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