Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (c) 2014 The Android Open Source Project
      4  *  Copyright (C) 2009-2012 Broadcom Corporation
      5  *
      6  *  Licensed under the Apache License, Version 2.0 (the "License");
      7  *  you may not use this file except in compliance with the License.
      8  *  You may obtain a copy of the License at:
      9  *
     10  *  http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  *  Unless required by applicable law or agreed to in writing, software
     13  *  distributed under the License is distributed on an "AS IS" BASIS,
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  *
     18  ******************************************************************************/
     19 
     20 #ifndef BTIF_COMMON_H
     21 #define BTIF_COMMON_H
     22 
     23 #include "data_types.h"
     24 #include "bt_types.h"
     25 #include "bta_api.h"
     26 
     27 #ifndef LOG_TAG
     28 #error "LOG_TAG not defined, please add in .c file prior to including bt_common.h"
     29 #endif
     30 
     31 #include <utils/Log.h>
     32 
     33 /*******************************************************************************
     34 **  Constants & Macros
     35 ********************************************************************************/
     36 
     37 #define ASSERTC(cond, msg, val) if (!(cond)) { ALOGE( \
     38     "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
     39 
     40 /* Calculate start of event enumeration; id is top 8 bits of event */
     41 #define BTIF_SIG_START(id)       ((id) << 8)
     42 
     43 /* For upstream the MSB bit is always SET */
     44 #define BTIF_SIG_CB_BIT   (0x8000)
     45 #define BTIF_SIG_CB_START(id)    (((id) << 8) | BTIF_SIG_CB_BIT)
     46 
     47 /* BTIF sub-systems */
     48 #define BTIF_CORE           0
     49 #define BTIF_DM             1
     50 #define BTIF_HFP            2
     51 #define BTIF_AV             3
     52 #define BTIF_PAN            4
     53 #define BTIF_HF_CLIENT      5
     54 
     55 extern bt_callbacks_t *bt_hal_cbacks;
     56 
     57 #define HAL_CBACK(P_CB, P_CBACK, ...)\
     58     if (P_CB && P_CB->P_CBACK) {            \
     59         BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \
     60         P_CB->P_CBACK(__VA_ARGS__);         \
     61     }                                       \
     62     else {                                  \
     63         ASSERTC(0, "Callback is NULL", 0);  \
     64     }
     65 
     66 /**
     67  * BTIF events for requests that require context switch to btif task
     68  * on downstreams path
     69  */
     70 enum
     71 {
     72     BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
     73     BTIF_CORE_STORAGE_NO_ACTION,
     74     BTIF_CORE_STORAGE_ADAPTER_WRITE,
     75     BTIF_CORE_STORAGE_ADAPTER_READ,
     76     BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
     77     BTIF_CORE_STORAGE_REMOTE_WRITE,
     78     BTIF_CORE_STORAGE_REMOTE_READ,
     79     BTIF_CORE_STORAGE_REMOTE_READ_ALL,
     80     BTIF_CORE_STORAGE_READ_ALL,
     81     BTIF_CORE_STORAGE_NOTIFY_STATUS,
     82     /* add here */
     83 
     84     BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
     85     BTIF_DM_ENABLE_SERVICE,
     86     BTIF_DM_DISABLE_SERVICE,
     87     /* add here */
     88 
     89     BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP),
     90     /* add here */
     91 
     92     BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV),
     93     /* add here */
     94 };
     95 
     96 /**
     97  * BTIF events for callbacks that require context switch to btif task
     98  * on upstream path - Typically these would be non-BTA events
     99  * that are generated by the BTIF layer.
    100  */
    101 enum
    102 {
    103     BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE),
    104     /* add here */
    105 
    106     BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
    107     BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
    108     BTIF_DM_CB_CREATE_BOND,   /* Create bond */
    109     BTIF_DM_CB_REMOVE_BOND,   /*Remove bond */
    110     BTIF_DM_CB_HID_REMOTE_NAME,   /* Remote name callback for HID device */
    111     BTIF_DM_CB_BOND_STATE_BONDING,
    112     BTIF_DM_CB_LE_TX_TEST,    /* BLE Tx Test command complete callback */
    113     BTIF_DM_CB_LE_RX_TEST,    /* BLE Rx Test command complete callback */
    114     BTIF_DM_CB_LE_TEST_END,   /* BLE Test mode end callback */
    115 
    116     BTIF_HFP_CB_START  = BTIF_SIG_CB_START(BTIF_HFP),
    117     BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */
    118 
    119     BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN),
    120     BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */
    121 
    122     BTIF_HF_CLIENT_CLIENT_CB_START  = BTIF_SIG_CB_START(BTIF_HF_CLIENT),
    123     BTIF_HF_CLIENT_CB_AUDIO_CONNECTING, /* AUDIO connect has been sent to BTA successfully */
    124 };
    125 
    126 /* Macro definitions for BD ADDR persistence */
    127 
    128 /**
    129  * PROPERTY_BT_BDADDR_PATH
    130  * The property key stores the storage location of Bluetooth Device Address
    131  */
    132 #ifndef PROPERTY_BT_BDADDR_PATH
    133 #define PROPERTY_BT_BDADDR_PATH         "ro.bt.bdaddr_path"
    134 #endif
    135 
    136 /**
    137  * PERSIST_BDADDR_PROPERTY
    138  * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH,
    139  * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP.
    140  */
    141 #ifndef PERSIST_BDADDR_PROPERTY
    142 #define PERSIST_BDADDR_PROPERTY         "persist.service.bdroid.bdaddr"
    143 #endif
    144 
    145 #define FACTORY_BT_BDADDR_STORAGE_LEN   17
    146 
    147 
    148 /*******************************************************************************
    149 **  Type definitions for callback functions
    150 ********************************************************************************/
    151 
    152 typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
    153 typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
    154 
    155 
    156 /*******************************************************************************
    157 **  Type definitions and return values
    158 ********************************************************************************/
    159 
    160 /* this type handles all btif context switches between BTU and HAL */
    161 typedef struct
    162 {
    163     BT_HDR               hdr;
    164     tBTIF_CBACK*         p_cb;    /* context switch callback */
    165 
    166     /* parameters passed to callback */
    167     UINT16               event;   /* message event id */
    168     char                 p_param[0]; /* parameter area needs to be last */
    169 } tBTIF_CONTEXT_SWITCH_CBACK;
    170 
    171 
    172 /*******************************************************************************
    173 **  Functions
    174 ********************************************************************************/
    175 
    176 bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params,
    177                                     int param_len, tBTIF_COPY_CBACK *p_copy_cback);
    178 tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
    179 bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
    180 bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
    181 int btif_is_enabled(void);
    182 
    183 /**
    184  * BTIF_Events
    185  */
    186 void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd);
    187 void btif_disable_bluetooth_evt(void);
    188 void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props);
    189 void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
    190                                    uint32_t num_props, bt_property_t *p_props);
    191 #endif /* BTIF_COMMON_H */
    192