The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | /****************************************************************************** |
| 20 | * |
| 21 | * Filename: bte_main.c |
| 22 | * |
| 23 | * Description: Contains BTE core stack initialization and shutdown code |
| 24 | * |
| 25 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | #include <assert.h> |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <hardware/bluetooth.h> |
Chris Manton | 1802329 | 2014-08-29 09:12:06 -0700 | [diff] [blame] | 30 | #include <pthread.h> |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 31 | #include <signal.h> |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 32 | #include <stdlib.h> |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 33 | #include <time.h> |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 34 | #include <utils/Log.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 36 | #include "alarm.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 37 | #include "bd.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | #include "bta_api.h" |
Matthew Xie | 66432dc | 2014-04-27 05:45:32 -0700 | [diff] [blame] | 39 | #include "bt_hci_bdroid.h" |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 40 | #include "bte.h" |
Chris Manton | 0eefef0 | 2014-09-08 15:01:39 -0700 | [diff] [blame] | 41 | #include "btif_common.h" |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 42 | #include "btu.h" |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 43 | #include "btsnoop.h" |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 44 | #include "bt_utils.h" |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 45 | #include "fixed_queue.h" |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 46 | #include "future.h" |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 47 | #include "gki.h" |
Chris Manton | 1802329 | 2014-08-29 09:12:06 -0700 | [diff] [blame] | 48 | #include "hash_functions.h" |
| 49 | #include "hash_map.h" |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 50 | #include "hci_layer.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 51 | #include "module.h" |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 52 | #include "osi.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 53 | #include "stack_config.h" |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 54 | #include "thread.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 55 | |
| 56 | /******************************************************************************* |
| 57 | ** Constants & Macros |
| 58 | *******************************************************************************/ |
| 59 | |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 60 | /* Run-time configuration file for BLE*/ |
| 61 | #ifndef BTE_BLE_STACK_CONF_FILE |
| 62 | #define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_stack.conf" |
| 63 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 65 | /****************************************************************************** |
| 66 | ** Variables |
| 67 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 68 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 69 | /******************************************************************************* |
| 70 | ** Static variables |
| 71 | *******************************************************************************/ |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 72 | static const hci_t *hci; |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 73 | static const hci_callbacks_t hci_callbacks; |
Zach Johnson | 7fa65f7 | 2014-08-29 18:20:48 -0700 | [diff] [blame] | 74 | // Lock to serialize shutdown requests from upper layer. |
| 75 | static pthread_mutex_t shutdown_lock; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 76 | |
| 77 | /******************************************************************************* |
| 78 | ** Static functions |
| 79 | *******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 80 | |
| 81 | /******************************************************************************* |
| 82 | ** Externs |
| 83 | *******************************************************************************/ |
Sharvil Nanavati | da0446b | 2014-08-29 18:28:19 -0700 | [diff] [blame] | 84 | void BTE_LoadStack(void); |
| 85 | void BTE_UnloadStack(void); |
| 86 | void scru_flip_bda (BD_ADDR dst, const BD_ADDR src); |
| 87 | void bte_load_conf(const char *p_path); |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 88 | extern void bte_load_ble_conf(const char *p_path); |
Sharvil Nanavati | da0446b | 2014-08-29 18:28:19 -0700 | [diff] [blame] | 89 | bt_bdaddr_t btif_local_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 90 | |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 91 | fixed_queue_t *btu_hci_msg_queue; |
| 92 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | /****************************************************************************** |
| 94 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 95 | ** Function bte_main_boot_entry |
| 96 | ** |
| 97 | ** Description BTE MAIN API - Entry point for BTE chip/stack initialization |
| 98 | ** |
| 99 | ** Returns None |
| 100 | ** |
| 101 | ******************************************************************************/ |
| 102 | void bte_main_boot_entry(void) |
| 103 | { |
| 104 | /* initialize OS */ |
| 105 | GKI_init(); |
| 106 | |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 107 | hci = hci_layer_get_interface(); |
| 108 | if (!hci) |
| 109 | ALOGE("%s could not get hci layer interface.", __func__); |
| 110 | |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 111 | btu_hci_msg_queue = fixed_queue_new(SIZE_MAX); |
| 112 | if (btu_hci_msg_queue == NULL) { |
| 113 | ALOGE("%s unable to allocate hci message queue.", __func__); |
| 114 | return; |
| 115 | } |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 116 | |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 117 | data_dispatcher_register_default(hci->upward_dispatcher, btu_hci_msg_queue); |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 118 | |
Prerepa Viswanadham | 4c94c5f | 2014-07-18 15:20:54 -0700 | [diff] [blame] | 119 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 120 | bte_load_ble_conf(BTE_BLE_STACK_CONF_FILE); |
| 121 | #endif |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 122 | module_init(get_module(STACK_CONFIG_MODULE)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | |
| 124 | #if (BTTRC_INCLUDED == TRUE) |
| 125 | /* Initialize trace feature */ |
| 126 | BTTRC_TraceInit(MAX_TRACE_RAM_SIZE, &BTE_TraceLogBuf[0], BTTRC_METHOD_RAM); |
| 127 | #endif |
Chris Manton | 6c25e79 | 2014-08-07 16:23:41 -0700 | [diff] [blame] | 128 | |
Zach Johnson | 7fa65f7 | 2014-08-29 18:20:48 -0700 | [diff] [blame] | 129 | pthread_mutex_init(&shutdown_lock, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /****************************************************************************** |
| 133 | ** |
| 134 | ** Function bte_main_shutdown |
| 135 | ** |
| 136 | ** Description BTE MAIN API - Shutdown code for BTE chip/stack |
| 137 | ** |
| 138 | ** Returns None |
| 139 | ** |
| 140 | ******************************************************************************/ |
| 141 | void bte_main_shutdown() |
| 142 | { |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 143 | data_dispatcher_register_default(hci_layer_get_interface()->upward_dispatcher, NULL); |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 144 | fixed_queue_free(btu_hci_msg_queue, NULL); |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 145 | |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 146 | btu_hci_msg_queue = NULL; |
Sharvil Nanavati | 14a559a | 2014-07-25 22:20:46 -0700 | [diff] [blame] | 147 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 148 | module_clean_up(get_module(STACK_CONFIG_MODULE)); |
| 149 | |
Zach Johnson | 7fa65f7 | 2014-08-29 18:20:48 -0700 | [diff] [blame] | 150 | pthread_mutex_destroy(&shutdown_lock); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 151 | GKI_shutdown(); |
| 152 | } |
| 153 | |
| 154 | /****************************************************************************** |
| 155 | ** |
| 156 | ** Function bte_main_enable |
| 157 | ** |
| 158 | ** Description BTE MAIN API - Creates all the BTE tasks. Should be called |
| 159 | ** part of the Bluetooth stack enable sequence |
| 160 | ** |
| 161 | ** Returns None |
| 162 | ** |
| 163 | ******************************************************************************/ |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 164 | void bte_main_enable() |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 165 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 166 | APPL_TRACE_DEBUG("%s", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 167 | |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 168 | // BTU_StartUp(); |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 169 | |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 170 | assert(hci->start_up_async(btif_local_bd_addr.address, &hci_callbacks)); |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 171 | module_start_up(get_module(BTSNOOP_MODULE)); |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /****************************************************************************** |
| 175 | ** |
| 176 | ** Function bte_main_disable |
| 177 | ** |
| 178 | ** Description BTE MAIN API - Destroys all the BTE tasks. Should be called |
| 179 | ** part of the Bluetooth stack disable sequence |
| 180 | ** |
| 181 | ** Returns None |
| 182 | ** |
| 183 | ******************************************************************************/ |
| 184 | void bte_main_disable(void) |
| 185 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 186 | APPL_TRACE_DEBUG("%s", __FUNCTION__); |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 187 | |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame^] | 188 | module_shut_down(get_module(BTSNOOP_MODULE)); |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 189 | if (hci) { |
| 190 | // Shutdown is not thread safe and must be protected. |
| 191 | pthread_mutex_lock(&shutdown_lock); |
| 192 | |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 193 | hci->shut_down(); |
| 194 | |
| 195 | pthread_mutex_unlock(&shutdown_lock); |
| 196 | } |
| 197 | |
Sharvil Nanavati | f79d286 | 2014-09-06 16:16:19 -0700 | [diff] [blame] | 198 | BTU_ShutDown(); |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /****************************************************************************** |
| 202 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 203 | ** Function bte_main_postload_cfg |
| 204 | ** |
| 205 | ** Description BTE MAIN API - Stack postload configuration |
| 206 | ** |
| 207 | ** Returns None |
| 208 | ** |
| 209 | ******************************************************************************/ |
| 210 | void bte_main_postload_cfg(void) |
| 211 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 212 | hci->do_postload(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE) |
| 216 | /****************************************************************************** |
| 217 | ** |
| 218 | ** Function bte_main_enable_lpm |
| 219 | ** |
| 220 | ** Description BTE MAIN API - Enable/Disable low power mode operation |
| 221 | ** |
| 222 | ** Returns None |
| 223 | ** |
| 224 | ******************************************************************************/ |
| 225 | void bte_main_enable_lpm(BOOLEAN enable) |
| 226 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 227 | hci->send_low_power_command(enable ? LPM_ENABLE : LPM_DISABLE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /****************************************************************************** |
| 231 | ** |
| 232 | ** Function bte_main_lpm_allow_bt_device_sleep |
| 233 | ** |
| 234 | ** Description BTE MAIN API - Allow BT controller goest to sleep |
| 235 | ** |
| 236 | ** Returns None |
| 237 | ** |
| 238 | ******************************************************************************/ |
| 239 | void bte_main_lpm_allow_bt_device_sleep() |
| 240 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 241 | hci->send_low_power_command(LPM_WAKE_DEASSERT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /****************************************************************************** |
| 245 | ** |
| 246 | ** Function bte_main_lpm_wake_bt_device |
| 247 | ** |
| 248 | ** Description BTE MAIN API - Wake BT controller up if it is in sleep mode |
| 249 | ** |
| 250 | ** Returns None |
| 251 | ** |
| 252 | ******************************************************************************/ |
| 253 | void bte_main_lpm_wake_bt_device() |
| 254 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 255 | hci->send_low_power_command(LPM_WAKE_ASSERT); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 256 | } |
| 257 | #endif // HCILP_INCLUDED |
| 258 | |
Matthew Xie | 66432dc | 2014-04-27 05:45:32 -0700 | [diff] [blame] | 259 | |
| 260 | /* NOTICE: |
| 261 | * Definitions for audio state structure, this type needs to match to |
| 262 | * the bt_vendor_op_audio_state_t type defined in bt_vendor_lib.h |
| 263 | */ |
| 264 | typedef struct { |
| 265 | UINT16 handle; |
| 266 | UINT16 peer_codec; |
| 267 | UINT16 state; |
| 268 | } bt_hc_audio_state_t; |
| 269 | |
| 270 | struct bt_audio_state_tag { |
| 271 | BT_HDR hdr; |
| 272 | bt_hc_audio_state_t audio; |
| 273 | }; |
| 274 | |
| 275 | /****************************************************************************** |
| 276 | ** |
| 277 | ** Function set_audio_state |
| 278 | ** |
| 279 | ** Description Sets audio state on controller state for SCO (PCM, WBS, FM) |
| 280 | ** |
| 281 | ** Parameters handle: codec related handle for SCO: sco cb idx, unused for |
| 282 | ** codec: BTA_AG_CODEC_MSBC, BTA_AG_CODEC_CSVD or FM codec |
| 283 | ** state: codec state, eg. BTA_AG_CO_AUD_STATE_SETUP |
| 284 | ** param: future extensions, e.g. call-in structure/event. |
| 285 | ** |
| 286 | ** Returns None |
| 287 | ** |
| 288 | ******************************************************************************/ |
| 289 | int set_audio_state(UINT16 handle, UINT16 codec, UINT8 state, void *param) |
| 290 | { |
| 291 | struct bt_audio_state_tag *p_msg; |
| 292 | int result = -1; |
| 293 | |
| 294 | APPL_TRACE_API("set_audio_state(handle: %d, codec: 0x%x, state: %d)", handle, |
| 295 | codec, state); |
| 296 | if (NULL != param) |
| 297 | APPL_TRACE_WARNING("set_audio_state() non-null param not supported"); |
| 298 | p_msg = (struct bt_audio_state_tag *)GKI_getbuf(sizeof(*p_msg)); |
| 299 | if (!p_msg) |
| 300 | return result; |
| 301 | p_msg->audio.handle = handle; |
| 302 | p_msg->audio.peer_codec = codec; |
| 303 | p_msg->audio.state = state; |
| 304 | |
| 305 | p_msg->hdr.event = MSG_CTRL_TO_HC_CMD | (MSG_SUB_EVT_MASK & BT_HC_AUDIO_STATE); |
| 306 | p_msg->hdr.len = sizeof(p_msg->audio); |
| 307 | p_msg->hdr.offset = 0; |
| 308 | /* layer_specific shall contain return path event! for BTA events! |
| 309 | * 0 means no return message is expected. */ |
| 310 | p_msg->hdr.layer_specific = 0; |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 311 | hci->transmit_downward(MSG_STACK_TO_HC_HCI_CMD, p_msg); |
Matthew Xie | 66432dc | 2014-04-27 05:45:32 -0700 | [diff] [blame] | 312 | return result; |
| 313 | } |
| 314 | |
| 315 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 316 | /****************************************************************************** |
| 317 | ** |
| 318 | ** Function bte_main_hci_send |
| 319 | ** |
| 320 | ** Description BTE MAIN API - This function is called by the upper stack to |
| 321 | ** send an HCI message. The function displays a protocol trace |
| 322 | ** message (if enabled), and then calls the 'transmit' function |
| 323 | ** associated with the currently selected HCI transport |
| 324 | ** |
| 325 | ** Returns None |
| 326 | ** |
| 327 | ******************************************************************************/ |
| 328 | void bte_main_hci_send (BT_HDR *p_msg, UINT16 event) |
| 329 | { |
| 330 | UINT16 sub_event = event & BT_SUB_EVT_MASK; /* local controller ID */ |
| 331 | |
| 332 | p_msg->event = event; |
| 333 | |
| 334 | |
| 335 | if((sub_event == LOCAL_BR_EDR_CONTROLLER_ID) || \ |
| 336 | (sub_event == LOCAL_BLE_CONTROLLER_ID)) |
| 337 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 338 | hci->transmit_downward(event, p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 339 | } |
| 340 | else |
| 341 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 342 | APPL_TRACE_ERROR("Invalid Controller ID. Discarding message."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 343 | GKI_freebuf(p_msg); |
| 344 | } |
| 345 | } |
| 346 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 347 | /***************************************************************************** |
| 348 | ** |
| 349 | ** libbt-hci Callback Functions |
| 350 | ** |
| 351 | *****************************************************************************/ |
| 352 | |
| 353 | /****************************************************************************** |
| 354 | ** |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 355 | ** Function hci_startup_cb |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | ** |
| 357 | ** Description HOST/CONTROLLER LIB CALLBACK API - This function is called |
| 358 | ** when the libbt-hci completed stack preload process |
| 359 | ** |
| 360 | ** Returns None |
| 361 | ** |
| 362 | ******************************************************************************/ |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 363 | static void hci_startup_cb(bool success) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 364 | { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 365 | APPL_TRACE_EVENT("HC preload_cb %d [1:SUCCESS 0:FAIL]", success); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 367 | if (success) { |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 368 | BTU_StartUp(); |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 369 | } else { |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 370 | ALOGE("%s hci startup failed", __func__); |
| 371 | // TODO(cmanton) Initiate shutdown sequence. |
YK Jeffrey Chao | 48ebe2c | 2013-04-24 11:38:06 -0700 | [diff] [blame] | 372 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 373 | } |
| 374 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 375 | /****************************************************************************** |
| 376 | ** |
| 377 | ** Function tx_result |
| 378 | ** |
| 379 | ** Description HOST/CONTROLLER LIB CALLBACK API - This function is called |
| 380 | ** from the libbt-hci once it has processed/sent the prior data |
| 381 | ** buffer which core stack passed to it through transmit_buf |
| 382 | ** call earlier. |
| 383 | ** |
| 384 | ** The core stack is responsible for releasing the data buffer |
| 385 | ** if it has been completedly processed. |
| 386 | ** |
| 387 | ** Bluedroid libbt-hci library uses 'transac' parameter to |
| 388 | ** pass data-path buffer/packet across bt_hci_lib interface |
| 389 | ** boundary. The 'p_buf' is not intended to be used here |
| 390 | ** but might point to data portion in data-path buffer. |
| 391 | ** |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 392 | ** Returns void |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 393 | ** |
| 394 | ******************************************************************************/ |
Chris Manton | 307381e | 2014-09-04 19:48:49 -0700 | [diff] [blame] | 395 | static void tx_result(void *p_buf, bool all_fragments_sent) { |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 396 | if (!all_fragments_sent) |
Chris Manton | 860a9af | 2014-08-27 10:30:47 -0700 | [diff] [blame] | 397 | fixed_queue_enqueue(btu_hci_msg_queue, p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 398 | else |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 399 | GKI_freebuf(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /***************************************************************************** |
| 403 | ** The libbt-hci Callback Functions Table |
| 404 | *****************************************************************************/ |
Zach Johnson | fbbd42b | 2014-08-15 17:00:17 -0700 | [diff] [blame] | 405 | static const hci_callbacks_t hci_callbacks = { |
Zach Johnson | 733a06e | 2014-09-08 18:31:39 -0700 | [diff] [blame] | 406 | hci_startup_cb, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 407 | tx_result |
| 408 | }; |