1 /******************************************************************************
3 * Copyright (c) 2014 The Android Open Source Project
4 * Copyright (C) 2009-2012 Broadcom Corporation
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ******************************************************************************/
24 #include <hardware/bluetooth.h>
31 #error "LOG_TAG not defined, please add in .c file prior to including bt_common.h"
34 #include "osi/include/log.h"
36 /*******************************************************************************
38 ********************************************************************************/
40 #define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR( \
41 "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
43 /* Calculate start of event enumeration; id is top 8 bits of event */
44 #define BTIF_SIG_START(id) ((id) << 8)
46 /* For upstream the MSB bit is always SET */
47 #define BTIF_SIG_CB_BIT (0x8000)
48 #define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT)
50 /* BTIF sub-systems */
56 #define BTIF_HF_CLIENT 5
58 extern bt_callbacks_t *bt_hal_cbacks;
60 #define HAL_CBACK(P_CB, P_CBACK, ...)\
61 if (P_CB && P_CB->P_CBACK) { \
62 BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \
63 P_CB->P_CBACK(__VA_ARGS__); \
66 ASSERTC(0, "Callback is NULL", 0); \
70 * BTIF events for requests that require context switch to btif task
75 BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
76 BTIF_CORE_STORAGE_NO_ACTION,
77 BTIF_CORE_STORAGE_ADAPTER_WRITE,
78 BTIF_CORE_STORAGE_ADAPTER_READ,
79 BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
80 BTIF_CORE_STORAGE_REMOTE_WRITE,
81 BTIF_CORE_STORAGE_REMOTE_READ,
82 BTIF_CORE_STORAGE_REMOTE_READ_ALL,
83 BTIF_CORE_STORAGE_READ_ALL,
84 BTIF_CORE_STORAGE_NOTIFY_STATUS,
87 BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
88 BTIF_DM_ENABLE_SERVICE,
89 BTIF_DM_DISABLE_SERVICE,
92 BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP),
95 BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV),
100 * BTIF events for callbacks that require context switch to btif task
101 * on upstream path - Typically these would be non-BTA events
102 * that are generated by the BTIF layer.
106 BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE),
109 BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
110 BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
111 BTIF_DM_CB_CREATE_BOND, /* Create bond */
112 BTIF_DM_CB_REMOVE_BOND, /*Remove bond */
113 BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */
114 BTIF_DM_CB_BOND_STATE_BONDING,
115 BTIF_DM_CB_LE_TX_TEST, /* BLE Tx Test command complete callback */
116 BTIF_DM_CB_LE_RX_TEST, /* BLE Rx Test command complete callback */
117 BTIF_DM_CB_LE_TEST_END, /* BLE Test mode end callback */
119 BTIF_HFP_CB_START = BTIF_SIG_CB_START(BTIF_HFP),
120 BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */
122 BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN),
123 BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */
125 BTIF_HF_CLIENT_CLIENT_CB_START = BTIF_SIG_CB_START(BTIF_HF_CLIENT),
126 BTIF_HF_CLIENT_CB_AUDIO_CONNECTING, /* AUDIO connect has been sent to BTA successfully */
129 /* Macro definitions for BD ADDR persistence */
132 * PROPERTY_BT_BDADDR_PATH
133 * The property key stores the storage location of Bluetooth Device Address
135 #ifndef PROPERTY_BT_BDADDR_PATH
136 #define PROPERTY_BT_BDADDR_PATH "ro.bt.bdaddr_path"
140 * PERSIST_BDADDR_PROPERTY
141 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH,
142 * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP.
144 #ifndef PERSIST_BDADDR_PROPERTY
145 #define PERSIST_BDADDR_PROPERTY "persist.service.bdroid.bdaddr"
149 * FACTORY_BT_BDADDR_PROPERTY
150 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH
151 * and there is no available persistent bdaddr available from
152 * PERSIST_BDADDR_PROPERTY use a factory set address
154 #ifndef FACTORY_BT_ADDR_PROPERTY
155 #define FACTORY_BT_ADDR_PROPERTY "ro.boot.btmacaddr"
158 #define FACTORY_BT_BDADDR_STORAGE_LEN 17
161 /*******************************************************************************
162 ** Type definitions for callback functions
163 ********************************************************************************/
165 typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
166 typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
169 /*******************************************************************************
170 ** Type definitions and return values
171 ********************************************************************************/
173 /* this type handles all btif context switches between BTU and HAL */
177 tBTIF_CBACK* p_cb; /* context switch callback */
179 /* parameters passed to callback */
180 UINT16 event; /* message event id */
181 char p_param[0]; /* parameter area needs to be last */
182 } tBTIF_CONTEXT_SWITCH_CBACK;
185 /*******************************************************************************
187 ********************************************************************************/
189 bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params,
190 int param_len, tBTIF_COPY_CBACK *p_copy_cback);
191 tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
192 bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
193 bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
194 int btif_is_enabled(void);
199 void btif_enable_bluetooth_evt(tBTA_STATUS status);
200 void btif_disable_bluetooth_evt(void);
201 void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props);
202 void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
203 uint32_t num_props, bt_property_t *p_props);
205 void btif_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
206 void btif_init_fail(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
208 #endif /* BTIF_COMMON_H */