The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 1999-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 | * This file contains functions that handle BTM interface functions for the |
| 22 | * Bluetooth device including Rest, HCI buffer size and others |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stddef.h> |
| 30 | |
| 31 | #include "bt_types.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 32 | #include "bt_utils.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | #include "hcimsgs.h" |
| 34 | #include "btu.h" |
| 35 | #include "btm_int.h" |
| 36 | #include "l2c_int.h" |
| 37 | |
| 38 | #if BLE_INCLUDED == TRUE |
| 39 | #include "gatt_int.h" |
| 40 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 41 | #endif /* BLE_INCLUDED */ |
| 42 | |
| 43 | /* BTM_APP_DEV_INIT should be defined if additional controller initialization is |
| 44 | ** needed by the application to be performed after the HCI reset |
| 45 | */ |
| 46 | #ifdef BTM_APP_DEV_INIT |
| 47 | extern void BTM_APP_DEV_INIT(void); |
| 48 | #endif |
| 49 | |
| 50 | #ifdef BTA_PRM_CHECK_FW_VER |
| 51 | extern BOOLEAN BTA_PRM_CHECK_FW_VER(UINT8 *p); |
| 52 | #endif |
| 53 | |
| 54 | #ifndef TT_DEV_RESET_MASK |
| 55 | #define TT_DEV_RESET_MASK 0xff |
| 56 | #endif |
| 57 | |
| 58 | /********************************************************************************/ |
| 59 | /* L O C A L D A T A D E F I N I T I O N S */ |
| 60 | /********************************************************************************/ |
| 61 | |
| 62 | /* The default class of device. */ |
| 63 | #ifndef BTM_INIT_CLASS_OF_DEVICE |
| 64 | #define BTM_INIT_CLASS_OF_DEVICE "\x00\x1F\x00" |
| 65 | #endif |
| 66 | |
| 67 | #ifndef BTM_DEV_RESET_TIMEOUT |
| 68 | #define BTM_DEV_RESET_TIMEOUT 4 |
| 69 | #endif |
| 70 | |
| 71 | #define BTM_DEV_REPLY_TIMEOUT 2 /* 1 second expiration time is not good. Timer may start between 0 and 1 second. */ |
| 72 | /* if it starts at the very end of the 0 second, timer will expire really easily. */ |
| 73 | |
| 74 | #define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */ |
| 75 | |
| 76 | /* After Reset a timeout can be specified in the target.h for specific targets |
| 77 | * that may require additional time to reset |
| 78 | * otherwise no timeout is required |
| 79 | */ |
| 80 | #ifndef BTM_AFTER_RESET_TIMEOUT |
| 81 | #define BTM_AFTER_RESET_TIMEOUT 0 |
| 82 | #endif |
| 83 | |
| 84 | /* Internal baseband so the parameters such as local features, version etc. are known |
| 85 | so there is no need to issue HCI commands and wait for responses at BTM initialization */ |
| 86 | #ifndef BTM_INTERNAL_BB |
| 87 | #define BTM_INTERNAL_BB FALSE |
| 88 | #endif |
| 89 | |
| 90 | /* The local version information in the format specified in the HCI read local version |
| 91 | response message */ |
| 92 | #ifndef BTM_INTERNAL_LOCAL_VER |
| 93 | #define BTM_INTERNAL_LOCAL_VER {0x00, 0x01, 0x05, 0x81, 0x01, 0x30, 0x00, 0x40, 0x8D} |
| 94 | #endif |
| 95 | |
| 96 | /* The local features information in the format specified in the HCI read local features |
| 97 | response message */ |
| 98 | #ifndef BTM_INTERNAL_LOCAL_FEA |
| 99 | #define BTM_INTERNAL_LOCAL_FEA {0x00, 0xFF, 0xF9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 100 | #endif |
| 101 | |
| 102 | #ifndef BTM_SET_DEV_NAME_UPON_RESET |
| 103 | #define BTM_SET_DEV_NAME_UPON_RESET TRUE |
| 104 | #endif |
| 105 | |
| 106 | /* host SCO buffer size */ |
| 107 | #ifndef BTM_SCO_HOST_BUF_SIZE |
| 108 | #define BTM_SCO_HOST_BUF_SIZE 0xff |
| 109 | #endif |
| 110 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 111 | /********************************************************************************/ |
| 112 | /* L O C A L F U N C T I O N P R O T O T Y P E S */ |
| 113 | /********************************************************************************/ |
| 114 | static void btm_dev_reset (void); |
| 115 | static void btm_after_reset_hold_complete (void); |
| 116 | static void btm_continue_reset (void); |
| 117 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 118 | static void btm_get_local_ext_features (UINT8 page_number); |
| 119 | static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p_features); |
| 120 | static void btm_read_all_lmp_features_complete (UINT8 max_page_number); |
| 121 | static void btm_set_lmp_features_host_may_support (UINT8 max_page_number); |
| 122 | static void btm_get_local_features (void); |
| 123 | static void btm_issue_host_support_for_lmp_features (void); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 124 | static void btm_read_local_supported_cmds (UINT8 local_controller_id); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 125 | |
| 126 | #if BLE_INCLUDED == TRUE |
| 127 | static void btm_read_ble_local_supported_features (void); |
| 128 | #endif |
| 129 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 130 | /******************************************************************************* |
| 131 | ** |
| 132 | ** Function btm_dev_init |
| 133 | ** |
| 134 | ** Description This function is on the BTM startup |
| 135 | ** |
| 136 | ** Returns void |
| 137 | ** |
| 138 | *******************************************************************************/ |
| 139 | void btm_dev_init (void) |
| 140 | { |
| 141 | #if 0 /* cleared in btm_init; put back in if called from anywhere else! */ |
| 142 | memset (&btm_cb.devcb, 0, sizeof (tBTM_DEVCB)); |
| 143 | #endif |
| 144 | |
| 145 | /* Initialize nonzero defaults */ |
| 146 | #if (BTM_MAX_LOC_BD_NAME_LEN > 0) |
| 147 | memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 148 | #endif |
| 149 | |
| 150 | btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET; |
| 151 | btm_cb.devcb.rln_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLN; |
| 152 | btm_cb.devcb.rlinkp_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLNKP; |
| 153 | |
| 154 | btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 + |
| 155 | BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 + |
| 156 | BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5; |
| 157 | |
| 158 | btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1 + |
| 159 | BTM_SCO_PKT_TYPES_MASK_HV2 + |
| 160 | BTM_SCO_PKT_TYPES_MASK_HV3 + |
| 161 | BTM_SCO_PKT_TYPES_MASK_EV3 + |
| 162 | BTM_SCO_PKT_TYPES_MASK_EV4 + |
| 163 | BTM_SCO_PKT_TYPES_MASK_EV5; |
| 164 | |
| 165 | btm_cb.first_disabled_channel = 0xff; /* To allow disabling 0th channel alone */ |
| 166 | btm_cb.last_disabled_channel = 0xff; /* To allow disabling 0th channel alone */ |
| 167 | |
| 168 | #if (BTM_AUTOMATIC_HCI_RESET == TRUE) |
| 169 | |
| 170 | #if (BTM_FIRST_RESET_DELAY > 0) |
| 171 | btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT; |
| 172 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_FIRST_RESET_DELAY); |
| 173 | #else |
| 174 | btm_dev_reset(); |
| 175 | #endif |
| 176 | |
| 177 | #else |
| 178 | BTM_TRACE_EVENT0 ("BTM_AUTOMATIC_HCI_RESET is FALSE, so skip btm reset for now"); |
| 179 | #endif |
| 180 | |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /******************************************************************************* |
| 185 | ** |
| 186 | ** Function btm_db_reset |
| 187 | ** |
| 188 | ** Description This function is called by BTM_DeviceReset and clears out any |
| 189 | ** pending callbacks for inquiries, discoveries, other pending |
| 190 | ** functions that may be in progress. |
| 191 | ** |
| 192 | ** Returns void |
| 193 | ** |
| 194 | *******************************************************************************/ |
| 195 | static void btm_db_reset (void) |
| 196 | { |
| 197 | tBTM_CMPL_CB *p_cb; |
| 198 | tBTM_STATUS status = BTM_DEV_RESET; |
| 199 | |
| 200 | btm_inq_db_reset(); |
| 201 | |
| 202 | if (btm_cb.devcb.p_rln_cmpl_cb) |
| 203 | { |
| 204 | p_cb = btm_cb.devcb.p_rln_cmpl_cb; |
| 205 | btm_cb.devcb.p_rln_cmpl_cb = NULL; |
| 206 | |
| 207 | if (p_cb) |
| 208 | (*p_cb)((void *) NULL); |
| 209 | } |
| 210 | |
| 211 | if (btm_cb.devcb.p_rlinkp_cmpl_cb) |
| 212 | { |
| 213 | p_cb = btm_cb.devcb.p_rlinkp_cmpl_cb; |
| 214 | btm_cb.devcb.p_rlinkp_cmpl_cb = NULL; |
| 215 | |
| 216 | if (p_cb) |
| 217 | (*p_cb)((void *) &status); |
| 218 | } |
| 219 | |
| 220 | if (btm_cb.devcb.p_rssi_cmpl_cb) |
| 221 | { |
| 222 | p_cb = btm_cb.devcb.p_rssi_cmpl_cb; |
| 223 | btm_cb.devcb.p_rssi_cmpl_cb = NULL; |
| 224 | |
| 225 | if (p_cb) |
| 226 | (*p_cb)((tBTM_RSSI_RESULTS *) &status); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | |
| 231 | |
| 232 | /******************************************************************************* |
| 233 | ** |
| 234 | ** Function btm_dev_absent |
| 235 | ** |
| 236 | ** Description This function is called by when it is detected that the |
| 237 | ** device is not connected any more. |
| 238 | ** |
| 239 | ** Returns void |
| 240 | ** |
| 241 | *******************************************************************************/ |
| 242 | void btm_dev_absent (void) |
| 243 | { |
| 244 | btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT; |
| 245 | |
| 246 | btm_db_reset (); |
| 247 | btm_inq_db_reset(); |
| 248 | |
| 249 | /* If anyone wants device status notifications, give him one */ |
| 250 | btm_report_device_status (BTM_DEV_STATUS_DOWN); |
| 251 | |
| 252 | btu_stop_timer (&btm_cb.devcb.reset_timer); |
| 253 | } |
| 254 | |
| 255 | |
| 256 | /******************************************************************************* |
| 257 | ** |
| 258 | ** Function BTM_DeviceReset |
| 259 | ** |
| 260 | ** Description This function is called to reset the HCI. Callback function |
| 261 | ** if provided is called when startup of the device is |
| 262 | ** completed. |
| 263 | ** |
| 264 | ** Returns void |
| 265 | ** |
| 266 | *******************************************************************************/ |
| 267 | void BTM_DeviceReset (tBTM_CMPL_CB *p_cb) |
| 268 | { |
| 269 | tBTM_STATUS status; |
| 270 | |
| 271 | /* If device is already resetting, do not allow another */ |
| 272 | if ((!btm_cb.devcb.p_reset_cmpl_cb) || (btm_cb.devcb.p_reset_cmpl_cb == p_cb)) |
| 273 | { |
| 274 | /* Flush all ACL connections */ |
| 275 | btm_acl_device_down(); |
| 276 | |
| 277 | /* Clear the callback, so application would not hang on reset */ |
| 278 | btm_db_reset(); |
| 279 | |
| 280 | /* Save address of the completion routine, if provided */ |
| 281 | btm_cb.devcb.p_reset_cmpl_cb = p_cb; |
| 282 | |
| 283 | btm_dev_reset (); |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | /* pass an error to the bad callback, another one was already provided */ |
| 288 | if (p_cb) |
| 289 | { |
| 290 | status = BTM_ILLEGAL_VALUE; |
| 291 | p_cb (&status); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /******************************************************************************* |
| 298 | ** |
| 299 | ** Function BTM_IsDeviceUp |
| 300 | ** |
| 301 | ** Description This function is called to check if the device is up. |
| 302 | ** |
| 303 | ** Returns TRUE if device is up, else FALSE |
| 304 | ** |
| 305 | *******************************************************************************/ |
| 306 | BOOLEAN BTM_IsDeviceUp (void) |
| 307 | { |
| 308 | return ((BOOLEAN) (btm_cb.devcb.state == BTM_DEV_STATE_READY)); |
| 309 | } |
| 310 | |
| 311 | /******************************************************************************* |
| 312 | ** |
| 313 | ** Function BTM_SetAfhChannels |
| 314 | ** |
| 315 | ** Description This function is called disable channels |
| 316 | ** |
| 317 | ** Returns tBTM_STATUS |
| 318 | ** |
| 319 | *******************************************************************************/ |
| 320 | tBTM_STATUS BTM_SetAfhChannels (UINT8 first, UINT8 last) |
| 321 | { |
| 322 | BTM_TRACE_API4 ("BTM_SetAfhChannels first: %d (%d) last: %d (%d)", |
| 323 | first, btm_cb.first_disabled_channel, last, |
| 324 | btm_cb.last_disabled_channel); |
| 325 | |
| 326 | /* Make sure the local device supports the feature before sending */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 327 | if ((!HCI_LMP_AFH_CAP_MASTR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && |
| 328 | (!HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && |
| 329 | (!HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 330 | return (BTM_MODE_UNSUPPORTED); |
| 331 | |
| 332 | if (!BTM_IsDeviceUp()) |
| 333 | return (BTM_WRONG_MODE); |
| 334 | |
| 335 | if ((btm_cb.first_disabled_channel != first) |
| 336 | || (btm_cb.last_disabled_channel != last)) |
| 337 | { |
| 338 | if (btsnd_hcic_set_afh_channels (first, last)) |
| 339 | { |
| 340 | btm_cb.first_disabled_channel = first; |
| 341 | btm_cb.last_disabled_channel = last; |
| 342 | } |
| 343 | else |
| 344 | return (BTM_NO_RESOURCES); |
| 345 | } |
| 346 | return (BTM_SUCCESS); |
| 347 | } |
| 348 | |
| 349 | /******************************************************************************* |
| 350 | ** |
| 351 | ** Function BTM_SetAfhChannelAssessment |
| 352 | ** |
| 353 | ** Description This function is called to set the channel assessment mode on or off |
| 354 | ** |
| 355 | ** Returns none |
| 356 | ** |
| 357 | *******************************************************************************/ |
| 358 | tBTM_STATUS BTM_SetAfhChannelAssessment (BOOLEAN enable_or_disable) |
| 359 | { |
| 360 | /* whatever app wants if device is not 1.2 scan type should be STANDARD */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 361 | if (!HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 362 | return (BTM_MODE_UNSUPPORTED); |
| 363 | |
| 364 | if (!btsnd_hcic_write_afh_channel_assessment_mode (enable_or_disable)) |
| 365 | return (BTM_NO_RESOURCES); |
| 366 | |
| 367 | return (BTM_SUCCESS); |
| 368 | } |
| 369 | |
| 370 | /******************************************************************************* |
| 371 | ** |
| 372 | ** Function BTM_ContinueReset |
| 373 | ** |
| 374 | ** Description This function is called by the application to continue |
| 375 | ** initialization after the application has completed its |
| 376 | ** vendor specific sequence. It is only used when |
| 377 | ** BTM_APP_DEV_INIT is defined in target.h. |
| 378 | ** |
| 379 | ** Returns void |
| 380 | ** |
| 381 | *******************************************************************************/ |
| 382 | void BTM_ContinueReset (void) |
| 383 | { |
| 384 | #ifdef BTM_APP_DEV_INIT |
| 385 | btm_continue_reset(); |
| 386 | #endif |
| 387 | } |
| 388 | |
| 389 | /******************************************************************************* |
| 390 | ** |
| 391 | ** Function btm_dev_reset |
| 392 | ** |
| 393 | ** Description Local function called to send a reset command |
| 394 | ** |
| 395 | ** Returns void |
| 396 | ** |
| 397 | *******************************************************************************/ |
| 398 | static void btm_dev_reset (void) |
| 399 | { |
| 400 | btm_cb.devcb.state = BTM_DEV_STATE_WAIT_RESET_CMPLT; |
| 401 | |
| 402 | /* flush out the command complete queue and command transmit queue */ |
| 403 | btu_hcif_flush_cmd_queue(); |
| 404 | |
| 405 | /* Start reset timer. When timer expires we will send first command */ |
| 406 | /* from the setup sequence */ |
| 407 | |
| 408 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, |
| 409 | BTM_DEV_RESET_TIMEOUT); |
| 410 | btsnd_hcic_reset (LOCAL_BR_EDR_CONTROLLER_ID); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /******************************************************************************* |
| 415 | ** |
| 416 | ** Function btm_get_hci_buf_size |
| 417 | ** |
| 418 | ** Description Local function called to send a read buffer size command |
| 419 | ** |
| 420 | ** Returns void |
| 421 | ** |
| 422 | *******************************************************************************/ |
| 423 | void btm_get_hci_buf_size (void) |
| 424 | { |
| 425 | |
| 426 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 427 | |
| 428 | /* Send a Read Buffer Size message to the Host Controller. */ |
| 429 | btsnd_hcic_read_buffer_size (); |
| 430 | |
| 431 | } |
| 432 | #if BLE_INCLUDED == TRUE |
| 433 | /******************************************************************************* |
| 434 | ** |
| 435 | ** Function btm_read_ble_wl_size |
| 436 | ** |
| 437 | ** Description Local function called to send a read BLE buffer size command |
| 438 | ** |
| 439 | ** Returns void |
| 440 | ** |
| 441 | *******************************************************************************/ |
| 442 | void btm_read_ble_wl_size(void) |
| 443 | { |
| 444 | BTM_TRACE_DEBUG0("btm_read_ble_wl_size "); |
| 445 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 446 | |
| 447 | /* Send a Read Buffer Size message to the Host Controller. */ |
| 448 | btsnd_hcic_ble_read_white_list_size(); |
| 449 | } |
| 450 | /******************************************************************************* |
| 451 | ** |
| 452 | ** Function btm_get_ble_buffer_size |
| 453 | ** |
| 454 | ** Description Local function called to send a read BLE buffer size command |
| 455 | ** |
| 456 | ** Returns void |
| 457 | ** |
| 458 | *******************************************************************************/ |
| 459 | void btm_get_ble_buffer_size(void) |
| 460 | { |
| 461 | BTM_TRACE_DEBUG0("btm_get_ble_buffer_size "); |
| 462 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 463 | |
| 464 | /* Send a Read Buffer Size message to the Host Controller. */ |
| 465 | btsnd_hcic_ble_read_buffer_size (); |
| 466 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 467 | |
| 468 | /******************************************************************************* |
| 469 | ** |
| 470 | ** Function btm_read_ble_local_supported_features |
| 471 | ** |
| 472 | ** Description Local function called to send a read BLE local supported |
| 473 | ** features command |
| 474 | ** |
| 475 | ** Returns void |
| 476 | ** |
| 477 | *******************************************************************************/ |
| 478 | static void btm_read_ble_local_supported_features(void) |
| 479 | { |
| 480 | BTM_TRACE_DEBUG0("btm_read_ble_local_supported_features "); |
| 481 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 482 | |
| 483 | /* Send a Read Local Supported Features message to the Host Controller. */ |
| 484 | btsnd_hcic_ble_read_local_spt_feat (); |
| 485 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 486 | #endif |
| 487 | /******************************************************************************* |
| 488 | ** |
| 489 | ** Function btm_get_local_version |
| 490 | ** |
| 491 | ** Description Local function called to send a read local version to controller |
| 492 | ** |
| 493 | ** Returns void |
| 494 | ** |
| 495 | *******************************************************************************/ |
| 496 | void btm_get_local_version (void) |
| 497 | { |
| 498 | |
| 499 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 500 | |
| 501 | /* Send a Read Local Version message to the Host Controller. */ |
| 502 | btsnd_hcic_read_local_ver (LOCAL_BR_EDR_CONTROLLER_ID); |
| 503 | btsnd_hcic_read_bd_addr (); |
| 504 | |
| 505 | #if BTM_PWR_MGR_INCLUDED == TRUE |
| 506 | btm_pm_reset(); |
| 507 | #endif |
| 508 | |
| 509 | } |
| 510 | |
| 511 | /******************************************************************************* |
| 512 | ** |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 513 | ** Function btm_read_local_supported_cmds |
| 514 | ** |
| 515 | ** Description Local function called to send a read local supported commands |
| 516 | ** |
| 517 | ** Returns void |
| 518 | ** |
| 519 | *******************************************************************************/ |
| 520 | static void btm_read_local_supported_cmds (UINT8 local_controller_id) |
| 521 | { |
| 522 | BTM_TRACE_DEBUG0("Start reading local supported commands"); |
| 523 | |
| 524 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 525 | |
| 526 | btsnd_hcic_read_local_supported_cmds(local_controller_id); |
| 527 | } |
| 528 | |
| 529 | /******************************************************************************* |
| 530 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 531 | ** Function btm_get_local_features |
| 532 | ** |
| 533 | ** Description Local function called to send a read local features |
| 534 | ** |
| 535 | ** Returns void |
| 536 | ** |
| 537 | *******************************************************************************/ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 538 | static void btm_get_local_features (void) |
| 539 | { |
| 540 | /* If this BT controller supports Read Extended Feature */ |
| 541 | if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0) |
| 542 | { |
| 543 | btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_0); |
| 544 | } |
| 545 | /* else, if this is a very old BT controller */ |
| 546 | else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 547 | { |
| 548 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 549 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 550 | /* Just read the basic features (legacy HCI command) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 551 | btsnd_hcic_read_local_features (); |
| 552 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /******************************************************************************* |
| 556 | ** |
| 557 | ** Function btm_get_local_ext_features |
| 558 | ** |
| 559 | ** Description Local function called to send a read local extended features |
| 560 | ** |
| 561 | ** Returns void |
| 562 | ** |
| 563 | *******************************************************************************/ |
| 564 | static void btm_get_local_ext_features (UINT8 page_number) |
| 565 | { |
| 566 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 567 | |
| 568 | btsnd_hcic_read_local_ext_features(page_number); |
| 569 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 570 | |
| 571 | /******************************************************************************* |
| 572 | ** |
| 573 | ** Function btm_dev_timeout |
| 574 | ** |
| 575 | ** Description This function is called when a timer list entry expires. |
| 576 | ** |
| 577 | ** Returns void |
| 578 | ** |
| 579 | *******************************************************************************/ |
| 580 | void btm_dev_timeout (TIMER_LIST_ENT *p_tle) |
| 581 | { |
| 582 | TIMER_PARAM_TYPE timer_type = (TIMER_PARAM_TYPE)p_tle->param; |
| 583 | |
| 584 | if ((timer_type & TT_DEV_RESET_MASK) == TT_DEV_RESET) |
| 585 | { |
| 586 | /* Call device reset as long as there is timeout*/ |
| 587 | btm_dev_reset(); |
| 588 | } |
| 589 | else if (timer_type == (TIMER_PARAM_TYPE)TT_DEV_RLN) |
| 590 | { |
| 591 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb; |
| 592 | |
| 593 | btm_cb.devcb.p_rln_cmpl_cb = NULL; |
| 594 | |
| 595 | if (p_cb) |
| 596 | (*p_cb)((void *) NULL); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /******************************************************************************* |
| 601 | ** |
| 602 | ** Function btm_reset_complete |
| 603 | ** |
| 604 | ** Description This function is called when command complete for HCI_Reset |
| 605 | ** is received. It does not make sense to send next command |
| 606 | ** because device is resetting after command complete is |
| 607 | ** received. Just start timer and set required state. |
| 608 | ** |
| 609 | ** Returns void |
| 610 | ** |
| 611 | *******************************************************************************/ |
| 612 | void btm_reset_complete (void) |
| 613 | { |
| 614 | int devinx; |
| 615 | |
| 616 | BTM_TRACE_EVENT0 ("btm_reset_complete"); |
| 617 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 618 | /* Handle if btm initiated the reset */ |
| 619 | if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT) |
| 620 | { |
| 621 | /* Tell L2CAP that all connections are gone */ |
| 622 | l2cu_device_reset (); |
| 623 | |
| 624 | /* Clear current security state */ |
| 625 | for (devinx = 0; devinx < BTM_SEC_MAX_DEVICE_RECORDS; devinx++) |
| 626 | { |
| 627 | btm_cb.sec_dev_rec[devinx].sec_state = BTM_SEC_STATE_IDLE; |
| 628 | } |
| 629 | |
| 630 | /* After the reset controller should restore all parameters to defaults. */ |
| 631 | btm_cb.btm_inq_vars.inq_counter = 1; |
| 632 | btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW; |
| 633 | btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL; |
| 634 | btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE; |
| 635 | |
| 636 | btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW; |
| 637 | btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL; |
| 638 | btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE; |
| 639 | |
| 640 | #if (BTM_AFTER_RESET_TIMEOUT > 0) |
| 641 | btu_start_timer (&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL, |
| 642 | BTM_AFTER_RESET_TIMEOUT); |
| 643 | #else |
| 644 | btm_cb.devcb.state = BTM_DEV_STATE_WAIT_AFTER_RESET; |
| 645 | btm_after_reset_hold_complete(); |
| 646 | #endif |
| 647 | |
| 648 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 649 | btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE; |
| 650 | btm_cb.ble_ctr_cb.bg_dev_num = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 651 | btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE; |
| 652 | btm_cb.ble_ctr_cb.p_select_cback = NULL; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 653 | memset(&btm_cb.ble_ctr_cb.bg_dev_list, 0, (sizeof(tBTM_LE_BG_CONN_DEV)*BTM_BLE_MAX_BG_CONN_DEV_NUM)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 654 | gatt_reset_bgdev_list(); |
| 655 | #endif |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | /******************************************************************************* |
| 660 | ** |
| 661 | ** Function btm_continue_reset |
| 662 | ** |
| 663 | ** Description This function is called when wait period expired after |
| 664 | ** device reset or called by the application to continue |
| 665 | ** initialization after the application has completed its |
| 666 | ** vendor specific sequence. |
| 667 | ** |
| 668 | ** Returns void |
| 669 | ** |
| 670 | *******************************************************************************/ |
| 671 | void btm_continue_reset (void) |
| 672 | { |
| 673 | |
| 674 | /* Reinitialize the default class of device */ |
| 675 | #if BTM_INTERNAL_BB == TRUE |
| 676 | btsnd_hcic_read_bd_addr (); |
| 677 | #if BTM_PWR_MGR_INCLUDED == TRUE |
| 678 | btm_pm_reset(); |
| 679 | #endif |
| 680 | #endif |
| 681 | |
| 682 | btm_get_hci_buf_size (); |
| 683 | |
| 684 | /* default device class */ |
| 685 | BTM_SetDeviceClass((UINT8 *) BTM_INIT_CLASS_OF_DEVICE); |
| 686 | |
| 687 | #if (BTM_MAX_LOC_BD_NAME_LEN > 0) && (BTM_SET_DEV_NAME_UPON_RESET == TRUE) |
| 688 | BTM_SetLocalDeviceName(btm_cb.cfg.bd_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 689 | #endif |
| 690 | |
| 691 | BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len); |
| 692 | } |
| 693 | |
| 694 | /******************************************************************************* |
| 695 | ** |
| 696 | ** Function btm_after_reset_hold_complete |
| 697 | ** |
| 698 | ** Description This function is called when wait period expired after |
| 699 | ** device reset. Continue intitialization |
| 700 | ** |
| 701 | ** Returns void |
| 702 | ** |
| 703 | *******************************************************************************/ |
| 704 | void btm_after_reset_hold_complete (void) |
| 705 | { |
| 706 | #ifdef BTM_APP_DEV_INIT |
| 707 | btu_stop_timer(&btm_cb.devcb.reset_timer); |
| 708 | BTM_APP_DEV_INIT(); |
| 709 | #else |
| 710 | btm_continue_reset(); |
| 711 | #endif |
| 712 | } |
| 713 | |
| 714 | |
| 715 | /******************************************************************************* |
| 716 | ** |
| 717 | ** Function btm_read_hci_buf_size_complete |
| 718 | ** |
| 719 | ** Description This function is called when command complete for |
| 720 | ** get HCI buffer size is received. Start timer and send |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 721 | ** read local features request |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 722 | ** |
| 723 | ** Returns void |
| 724 | ** |
| 725 | *******************************************************************************/ |
| 726 | void btm_read_hci_buf_size_complete (UINT8 *p, UINT16 evt_len) |
| 727 | { |
| 728 | UINT8 status; |
| 729 | UINT8 lm_sco_buf_size; |
| 730 | UINT16 lm_num_acl_bufs; |
| 731 | UINT16 lm_num_sco_bufs; |
| 732 | UINT16 acl_buf_size; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 733 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 734 | |
| 735 | STREAM_TO_UINT8 (status, p); |
| 736 | if (status == HCI_SUCCESS) |
| 737 | { |
| 738 | STREAM_TO_UINT16 (btu_cb.hcit_acl_data_size, p); |
| 739 | STREAM_TO_UINT8 (lm_sco_buf_size, p); |
| 740 | STREAM_TO_UINT16 (lm_num_acl_bufs, p); |
| 741 | STREAM_TO_UINT16 (lm_num_sco_bufs, p); |
| 742 | |
| 743 | btu_cb.hcit_acl_pkt_size = btu_cb.hcit_acl_data_size + HCI_DATA_PREAMBLE_SIZE; |
| 744 | |
| 745 | l2c_link_processs_num_bufs (lm_num_acl_bufs); |
| 746 | |
| 747 | #if BTM_ACL_BUF_SIZE > 0 |
| 748 | acl_buf_size = (BTM_ACL_BUF_SIZE < L2CAP_MTU_SIZE) ? BTM_ACL_BUF_SIZE : L2CAP_MTU_SIZE; |
| 749 | #else |
| 750 | acl_buf_size = L2CAP_MTU_SIZE; |
| 751 | #endif |
| 752 | /* Tell the controller what our buffer sizes are. ?? Need SCO info */ |
| 753 | btsnd_hcic_set_host_buf_size (acl_buf_size, BTM_SCO_HOST_BUF_SIZE, L2CAP_HOST_FC_ACL_BUFS, 10); |
| 754 | |
| 755 | #if L2CAP_HOST_FLOW_CTRL == TRUE |
| 756 | btsnd_hcic_set_host_flow_ctrl (HCI_HOST_FLOW_CTRL_ACL_ON); |
| 757 | #endif |
| 758 | } |
| 759 | |
| 760 | /* Set the device into connectable and/or discoverable mode (if configured to do so) */ |
| 761 | #if BTM_IS_CONNECTABLE == TRUE |
| 762 | (void) BTM_SetConnectability (BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW, BTM_DEFAULT_CONN_INTERVAL); |
| 763 | #endif |
| 764 | |
| 765 | #if BTM_IS_DISCOVERABLE == TRUE |
| 766 | (void) BTM_SetDiscoverability (BTM_DEFAULT_DISC_MODE, BTM_DEFAULT_DISC_WINDOW, BTM_DEFAULT_DISC_INTERVAL); |
| 767 | #endif |
| 768 | |
| 769 | #if BTM_INTERNAL_BB == TRUE |
| 770 | { |
| 771 | UINT8 buf[9] = BTM_INTERNAL_LOCAL_VER; |
| 772 | btm_read_local_version_complete( buf, 9 ); |
| 773 | } |
| 774 | #else |
| 775 | btm_get_local_version (); |
| 776 | #endif |
| 777 | } |
| 778 | |
| 779 | #if (BLE_INCLUDED == TRUE) |
| 780 | /******************************************************************************* |
| 781 | ** |
| 782 | ** Function btm_read_ble_buf_size_complete |
| 783 | ** |
| 784 | ** Description This function is called when command complete for |
| 785 | ** get HCI buffer size is received. Start timer and send |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 786 | ** read local supported features request |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 787 | ** |
| 788 | ** Returns void |
| 789 | ** |
| 790 | *******************************************************************************/ |
| 791 | void btm_read_ble_buf_size_complete (UINT8 *p, UINT16 evt_len) |
| 792 | { |
| 793 | UINT8 status; |
| 794 | UINT16 lm_num_le_bufs; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 795 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 796 | |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 797 | BTM_TRACE_DEBUG0("btm_read_ble_buf_size_complete "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 798 | STREAM_TO_UINT8 (status, p); |
| 799 | if (status == HCI_SUCCESS) |
| 800 | { |
| 801 | STREAM_TO_UINT16 (btu_cb.hcit_ble_acl_data_size, p); |
| 802 | STREAM_TO_UINT8 (lm_num_le_bufs, p); |
| 803 | |
Andre Eisenbach | 0082e02 | 2013-04-03 13:56:05 -0700 | [diff] [blame] | 804 | if (btu_cb.hcit_ble_acl_data_size == 0) |
| 805 | btu_cb.hcit_ble_acl_data_size = btu_cb.hcit_acl_data_size; |
| 806 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 807 | btu_cb.hcit_ble_acl_pkt_size = btu_cb.hcit_ble_acl_data_size + HCI_DATA_PREAMBLE_SIZE; |
| 808 | |
| 809 | l2c_link_processs_ble_num_bufs (lm_num_le_bufs); |
| 810 | } |
| 811 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 812 | btm_read_ble_local_supported_features(); |
| 813 | } |
| 814 | |
| 815 | /******************************************************************************* |
| 816 | ** |
| 817 | ** Function btm_read_ble_local_supported_features_complete |
| 818 | ** |
| 819 | ** Description This function is called when command complete for |
| 820 | ** Read LE Local Supported Features is received. Start timer and send |
| 821 | ** read LMP local features request |
| 822 | ** |
| 823 | ** Returns void |
| 824 | ** |
| 825 | *******************************************************************************/ |
| 826 | void btm_read_ble_local_supported_features_complete (UINT8 *p, UINT16 evt_len) |
| 827 | { |
| 828 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 829 | UNUSED(evt_len); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 830 | |
| 831 | BTM_TRACE_DEBUG0("btm_read_ble_local_supported_features_complete "); |
| 832 | |
| 833 | btu_stop_timer (&btm_cb.devcb.reset_timer); |
| 834 | |
| 835 | STREAM_TO_UINT8 (status, p); |
| 836 | if (status == HCI_SUCCESS) |
| 837 | { |
| 838 | STREAM_TO_ARRAY(&btm_cb.devcb.local_le_features, p, HCI_FEATURE_BYTES_PER_PAGE); |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | BTM_TRACE_WARNING1 ("btm_read_ble_local_supported_features_complete status = %d", status); |
| 843 | } |
| 844 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 845 | #if BTM_INTERNAL_BB == TRUE |
| 846 | { |
| 847 | UINT8 buf[9] = BTM_INTERNAL_LOCAL_FEA; |
| 848 | btm_read_local_features_complete( buf, 9 ); |
| 849 | } |
| 850 | #else |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 851 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 852 | /* get local feature if BRCM specific feature is not included */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 853 | btm_reset_ctrlr_complete(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 854 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 855 | |
| 856 | } |
| 857 | |
| 858 | /******************************************************************************* |
| 859 | ** |
| 860 | ** Function btm_read_white_list_size_complete |
| 861 | ** |
| 862 | ** Description This function read the current white list size. |
| 863 | *******************************************************************************/ |
| 864 | void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len) |
| 865 | { |
| 866 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 867 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 868 | |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 869 | BTM_TRACE_DEBUG0("btm_read_white_list_size_complete "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 870 | STREAM_TO_UINT8 (status, p); |
| 871 | |
| 872 | if (status == HCI_SUCCESS) |
| 873 | { |
| 874 | STREAM_TO_UINT8(btm_cb.ble_ctr_cb.max_filter_entries, p); |
| 875 | btm_cb.ble_ctr_cb.num_empty_filter = btm_cb.ble_ctr_cb.max_filter_entries; |
| 876 | } |
| 877 | |
| 878 | btm_get_ble_buffer_size(); |
| 879 | } |
| 880 | |
| 881 | #endif |
| 882 | /******************************************************************************* |
| 883 | ** |
| 884 | ** Function btm_read_local_version_complete |
| 885 | ** |
| 886 | ** Description This function is called when local BD Addr read complete |
| 887 | ** message is received from the HCI. |
| 888 | ** |
| 889 | ** Returns void |
| 890 | ** |
| 891 | *******************************************************************************/ |
| 892 | void btm_read_local_version_complete (UINT8 *p, UINT16 evt_len) |
| 893 | { |
| 894 | tBTM_VERSION_INFO *p_vi = &btm_cb.devcb.local_version; |
| 895 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 896 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 897 | |
| 898 | #ifdef BTA_PRM_CHECK_FW_VER |
| 899 | if(BTA_PRM_CHECK_FW_VER(p)) |
| 900 | return; |
| 901 | #endif |
| 902 | |
| 903 | STREAM_TO_UINT8 (status, p); |
| 904 | if (status == HCI_SUCCESS) |
| 905 | { |
| 906 | |
| 907 | STREAM_TO_UINT8 (p_vi->hci_version, p); |
| 908 | STREAM_TO_UINT16 (p_vi->hci_revision, p); |
| 909 | STREAM_TO_UINT8 (p_vi->lmp_version, p); |
| 910 | STREAM_TO_UINT16 (p_vi->manufacturer, p); |
| 911 | STREAM_TO_UINT16 (p_vi->lmp_subversion, p); |
| 912 | } |
| 913 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 914 | if (p_vi->hci_version >= HCI_PROTO_VERSION_1_2) |
| 915 | { |
| 916 | btm_read_local_supported_cmds(LOCAL_BR_EDR_CONTROLLER_ID); |
| 917 | } |
| 918 | else |
| 919 | { |
| 920 | btm_get_local_features (); |
| 921 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 924 | /******************************************************************************* |
| 925 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 926 | ** Function btm_decode_ext_features_page |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 927 | ** |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 928 | ** Description This function is decodes a features page. |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 929 | ** |
| 930 | ** Returns void |
| 931 | ** |
| 932 | *******************************************************************************/ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 933 | static void btm_decode_ext_features_page (UINT8 page_number, const UINT8 *p_features) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 934 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 935 | UINT8 last; |
| 936 | UINT8 first; |
| 937 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 938 | BTM_TRACE_DEBUG1 ("btm_decode_ext_features_page page: %d", page_number); |
| 939 | switch (page_number) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 940 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 941 | /* Extended (Legacy) Page 0 */ |
| 942 | case HCI_EXT_FEATURES_PAGE_0: |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 943 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 944 | /* Create ACL supported packet types mask */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 945 | btm_cb.btm_acl_pkt_types_supported = (BTM_ACL_PKT_TYPES_MASK_DH1 + |
| 946 | BTM_ACL_PKT_TYPES_MASK_DM1); |
| 947 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 948 | if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 949 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH3 + |
| 950 | BTM_ACL_PKT_TYPES_MASK_DM3); |
| 951 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 952 | if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 953 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH5 + |
| 954 | BTM_ACL_PKT_TYPES_MASK_DM5); |
| 955 | |
| 956 | /* _NO_X_DXX masks are reserved before ver 2.0. |
| 957 | Set them only for later versions of controller */ |
| 958 | if (btm_cb.devcb.local_version.hci_version >= HCI_PROTO_VERSION_2_0) |
| 959 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 960 | /* Add in EDR related ACL types */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 961 | if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 962 | { |
| 963 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + |
| 964 | BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + |
| 965 | BTM_ACL_PKT_TYPES_MASK_NO_2_DH5); |
| 966 | } |
| 967 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 968 | if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 969 | { |
| 970 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + |
| 971 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 + |
| 972 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
| 973 | } |
| 974 | |
| 975 | /* Check to see if 3 and 5 slot packets are available */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 976 | if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) || |
| 977 | HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 978 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 979 | if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 980 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + |
| 981 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH3); |
| 982 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 983 | if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 984 | btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + |
| 985 | BTM_ACL_PKT_TYPES_MASK_NO_3_DH5); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | BTM_TRACE_DEBUG1("Local supported ACL packet types: 0x%04x", |
| 990 | btm_cb.btm_acl_pkt_types_supported); |
| 991 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 992 | /* Create (e)SCO supported packet types mask */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 993 | btm_cb.btm_sco_pkt_types_supported = 0; |
| 994 | #if BTM_SCO_INCLUDED == TRUE |
| 995 | btm_cb.sco_cb.esco_supported = FALSE; |
| 996 | #endif |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 997 | if (HCI_SCO_LINK_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 998 | { |
| 999 | btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1; |
| 1000 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1001 | if (HCI_HV2_PACKETS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1002 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2; |
| 1003 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1004 | if (HCI_HV3_PACKETS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1005 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3; |
| 1006 | } |
| 1007 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1008 | if (HCI_ESCO_EV3_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1009 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3; |
| 1010 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1011 | if (HCI_ESCO_EV4_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1012 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4; |
| 1013 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1014 | if (HCI_ESCO_EV5_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1015 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5; |
| 1016 | #if BTM_SCO_INCLUDED == TRUE |
| 1017 | if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) |
| 1018 | { |
| 1019 | btm_cb.sco_cb.esco_supported = TRUE; |
| 1020 | |
| 1021 | /* Add in EDR related eSCO types */ |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1022 | if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1023 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1024 | if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1025 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_2_EV5; |
| 1026 | } |
| 1027 | else |
| 1028 | { |
| 1029 | btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 + |
| 1030 | BTM_SCO_PKT_TYPES_MASK_NO_2_EV5); |
| 1031 | } |
| 1032 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1033 | if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1034 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1035 | if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1036 | btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_3_EV5; |
| 1037 | } |
| 1038 | else |
| 1039 | { |
| 1040 | btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 + |
| 1041 | BTM_SCO_PKT_TYPES_MASK_NO_3_EV5); |
| 1042 | } |
| 1043 | } |
| 1044 | #endif |
| 1045 | |
| 1046 | BTM_TRACE_DEBUG1("Local supported SCO packet types: 0x%04x", |
| 1047 | btm_cb.btm_sco_pkt_types_supported); |
| 1048 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1049 | /* Create Default Policy Settings */ |
| 1050 | if (HCI_SWITCH_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1051 | btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1052 | else |
| 1053 | btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1054 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1055 | if (HCI_HOLD_MODE_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1056 | btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE; |
| 1057 | else |
| 1058 | btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE; |
| 1059 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1060 | if (HCI_SNIFF_MODE_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1061 | btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE; |
| 1062 | else |
| 1063 | btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE; |
| 1064 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1065 | if (HCI_PARK_MODE_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1066 | btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE; |
| 1067 | else |
| 1068 | btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE; |
| 1069 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1070 | btm_sec_dev_reset (); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1071 | #if ((BTM_EIR_SERVER_INCLUDED == TRUE)||(BTM_EIR_CLIENT_INCLUDED == TRUE)) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1072 | if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1073 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1074 | if (HCI_EXT_INQ_RSP_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1075 | BTM_SetInquiryMode (BTM_INQ_RESULT_EXTENDED); |
| 1076 | else |
| 1077 | BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI); |
| 1078 | } |
| 1079 | #else |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1080 | if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1081 | BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI); |
| 1082 | #endif |
| 1083 | #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1084 | if( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1085 | l2cu_set_non_flushable_pbf(TRUE); |
| 1086 | else |
| 1087 | l2cu_set_non_flushable_pbf(FALSE); |
| 1088 | #endif |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1089 | BTM_SetPageScanType (BTM_DEFAULT_SCAN_TYPE); |
| 1090 | BTM_SetInquiryScanType (BTM_DEFAULT_SCAN_TYPE); |
| 1091 | |
| 1092 | break; |
| 1093 | |
| 1094 | /* Extended Page 1 */ |
| 1095 | case HCI_EXT_FEATURES_PAGE_1: |
| 1096 | /* Nothing to do for page 1 */ |
| 1097 | break; |
| 1098 | |
| 1099 | /* Extended Page 2 */ |
| 1100 | case HCI_EXT_FEATURES_PAGE_2: |
| 1101 | /* Nothing to do for page 2 */ |
| 1102 | break; |
| 1103 | |
| 1104 | default: |
| 1105 | BTM_TRACE_ERROR1("btm_decode_ext_features_page page=%d unknown", page_number); |
| 1106 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1107 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /******************************************************************************* |
| 1111 | ** |
| 1112 | ** Function btm_reset_ctrlr_complete |
| 1113 | ** |
| 1114 | ** Description This is the last step of BR/EDR controller startup sequence. |
| 1115 | ** |
| 1116 | ** Returns void |
| 1117 | ** |
| 1118 | *******************************************************************************/ |
| 1119 | void btm_reset_ctrlr_complete () |
| 1120 | { |
| 1121 | tBTM_DEVCB *p_devcb = &btm_cb.devcb; |
| 1122 | tBTM_CMPL_CB *p_cb = p_devcb->p_reset_cmpl_cb; |
| 1123 | BOOLEAN found = FALSE; |
| 1124 | UINT8 i, j, max_page_number; |
| 1125 | |
| 1126 | btu_stop_timer (&btm_cb.devcb.reset_timer); |
| 1127 | |
| 1128 | /* find the highest feature page number which contains non-zero bits */ |
Mike J. Chen | 9603e2e | 2014-01-31 15:14:08 -0800 | [diff] [blame] | 1129 | for (i = HCI_EXT_FEATURES_PAGE_MAX; ; i--) |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1130 | { |
| 1131 | for (j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++) |
| 1132 | { |
| 1133 | if (p_devcb->local_lmp_features[i][j] != 0) |
| 1134 | { |
| 1135 | found = TRUE; |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | if (found || !i) |
| 1140 | { |
| 1141 | break; |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | if (!found) |
| 1146 | BTM_TRACE_WARNING0 ("btm_reset_ctrlr_complete: NONE of local controller features is set"); |
| 1147 | |
| 1148 | max_page_number = i; |
| 1149 | |
| 1150 | BTM_TRACE_DEBUG1 ("btm_reset_ctrlr_complete: max_page_number: %d", max_page_number); |
| 1151 | |
| 1152 | /* |
| 1153 | * Set State to Ready (needs to be done before btm_decode_ext_features_page |
| 1154 | * to allow it to send some HCI configuration commands) |
| 1155 | */ |
| 1156 | p_devcb->state = BTM_DEV_STATE_READY; |
| 1157 | |
| 1158 | /* For every received/saved feature page */ |
| 1159 | for (i = 0; i <= max_page_number; i++) |
| 1160 | { |
| 1161 | /* Decode the saved Feature Page */ |
| 1162 | btm_decode_ext_features_page(i, p_devcb->local_lmp_features[i]); |
| 1163 | } |
| 1164 | |
| 1165 | /* If there was a callback address for reset complete, reset it */ |
| 1166 | p_devcb->p_reset_cmpl_cb = NULL; |
| 1167 | |
| 1168 | /* If anyone wants device status notifications, give him one */ |
| 1169 | btm_report_device_status(BTM_DEV_STATUS_UP); |
| 1170 | |
| 1171 | /* Reset sequence is complete. If this was an application originated */ |
| 1172 | /* reset, tell him its done. */ |
| 1173 | if (p_cb) |
| 1174 | (*p_cb)((void *) NULL); |
| 1175 | } |
| 1176 | |
| 1177 | /******************************************************************************* |
| 1178 | ** |
| 1179 | ** Function btm_issue_host_support_for_lmp_features |
| 1180 | ** |
| 1181 | ** Description This function: |
| 1182 | ** - issues commands to set host supported LMP features (one at |
| 1183 | ** a time); |
| 1184 | ** - after this is done it issues command to re-read LMP features |
| 1185 | ** page 1; |
| 1186 | ** - after this is done it calls the last step of BR/EDR |
| 1187 | ** controller startup sequence. |
| 1188 | ** |
| 1189 | ** Returns void |
| 1190 | ** |
| 1191 | *******************************************************************************/ |
| 1192 | static void btm_issue_host_support_for_lmp_features (void) |
| 1193 | { |
| 1194 | BTM_TRACE_DEBUG1("btm_issue_host_support_for_lmp_features lmp_features_host_may_support: 0x%02x", btm_cb.devcb.lmp_features_host_may_support); |
| 1195 | |
| 1196 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SSP) |
| 1197 | { |
| 1198 | btsnd_hcic_write_simple_pairing_mode(HCI_SP_MODE_ENABLED); |
| 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | #if (BLE_INCLUDED == TRUE) |
| 1203 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_LE) |
| 1204 | { |
| 1205 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SIMULT_BR_LE) |
| 1206 | { |
| 1207 | /* At the moment the host can't work simultaneously with BR/EDR and LE */ |
| 1208 | btsnd_hcic_ble_write_host_supported(BTM_BLE_HOST_SUPPORT, 0); |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | btsnd_hcic_ble_write_host_supported(BTM_BLE_HOST_SUPPORT, 0); |
| 1213 | } |
| 1214 | return; |
| 1215 | } |
| 1216 | #endif |
| 1217 | |
| 1218 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_RE_READ_1ST_PAGE) |
| 1219 | { |
| 1220 | btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_1); |
| 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | if (!btm_cb.devcb.lmp_features_host_may_support) |
| 1225 | { |
| 1226 | #if BLE_INCLUDED == TRUE |
| 1227 | if (HCI_LE_HOST_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_1])) |
| 1228 | { |
| 1229 | btm_read_ble_wl_size(); |
| 1230 | } |
Matthew Xie | fc4b2f1 | 2013-05-06 20:51:02 -0700 | [diff] [blame] | 1231 | else |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1232 | #elif BTM_INTERNAL_BB == TRUE |
| 1233 | { |
| 1234 | UINT8 buf[9] = BTM_INTERNAL_LOCAL_FEA; |
| 1235 | btm_read_local_features_complete( buf, 9 ); |
| 1236 | } |
| 1237 | #endif |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1238 | { |
| 1239 | btm_reset_ctrlr_complete(); |
| 1240 | } |
| 1241 | return; |
| 1242 | } |
| 1243 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1244 | BTM_TRACE_ERROR2("%s lmp_features_host_may_support: 0x%02x. This is unexpected.",__FUNCTION__, |
| 1245 | btm_cb.devcb.lmp_features_host_may_support); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /******************************************************************************* |
| 1249 | ** |
| 1250 | ** Function btm_set_lmp_features_host_may_support |
| 1251 | ** |
| 1252 | ** Description This function is called after all LMP features provided by |
| 1253 | ** controller are read. It sets the mask that indicates LMP |
| 1254 | ** features the host may support based on LMP features supported |
| 1255 | ** by controller. |
| 1256 | ** Example: |
| 1257 | ** Host may set SSP (host support) bit only if SSP (controller |
| 1258 | ** support) bit is set by controller. |
| 1259 | ** |
| 1260 | ** Returns void |
| 1261 | ** |
| 1262 | *******************************************************************************/ |
| 1263 | static void btm_set_lmp_features_host_may_support (UINT8 max_page_number) |
| 1264 | { |
| 1265 | btm_cb.devcb.lmp_features_host_may_support = 0; |
| 1266 | |
| 1267 | /* LMP page 0 is always read */ |
| 1268 | if (HCI_SIMPLE_PAIRING_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 1269 | { |
| 1270 | /* host may support SSP */ |
| 1271 | btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_SSP; |
| 1272 | } |
| 1273 | |
| 1274 | #if (BLE_INCLUDED == TRUE) |
| 1275 | if (HCI_LE_SPT_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 1276 | { |
| 1277 | /* host may support LE */ |
| 1278 | btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_LE; |
| 1279 | |
| 1280 | if (HCI_SIMUL_LE_BREDR_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) |
| 1281 | { |
| 1282 | /* host may support BR/EDR and LE simultaneously */ |
| 1283 | btm_cb.devcb.lmp_features_host_may_support |= BTM_HOST_MAY_SUPP_SIMULT_BR_LE; |
| 1284 | } |
| 1285 | } |
| 1286 | #endif |
| 1287 | |
| 1288 | if (max_page_number >= HCI_EXT_FEATURES_PAGE_1) |
| 1289 | { |
| 1290 | /* nothing yet for HCI_EXT_FEATURES_PAGE_1 */ |
| 1291 | } |
| 1292 | |
| 1293 | if (max_page_number >= HCI_EXT_FEATURES_PAGE_1) |
| 1294 | { |
| 1295 | /* nothing yet for HCI_EXT_FEATURES_PAGE_2 */ |
| 1296 | } |
| 1297 | |
| 1298 | if (btm_cb.devcb.lmp_features_host_may_support) |
| 1299 | btm_cb.devcb.lmp_features_host_may_support |= BTM_RE_READ_1ST_PAGE; |
| 1300 | } |
| 1301 | |
| 1302 | /******************************************************************************* |
| 1303 | ** |
| 1304 | ** Function btm_read_all_lmp_features_complete |
| 1305 | ** |
| 1306 | ** Description This function is called after all LMP features provided by |
| 1307 | ** controller are read. |
| 1308 | ** It works with controller supported LMP features which host |
| 1309 | ** may support too. |
| 1310 | ** |
| 1311 | ** Returns void |
| 1312 | ** |
| 1313 | *******************************************************************************/ |
| 1314 | static void btm_read_all_lmp_features_complete (UINT8 max_page_number) |
| 1315 | { |
| 1316 | btm_set_lmp_features_host_may_support(max_page_number); |
| 1317 | |
| 1318 | btm_issue_host_support_for_lmp_features(); |
| 1319 | } |
| 1320 | |
| 1321 | /******************************************************************************* |
| 1322 | ** |
| 1323 | ** Function btm_read_local_features_complete |
| 1324 | ** |
| 1325 | ** Description This function is called when local supported features read |
| 1326 | ** is complete. |
| 1327 | ** |
| 1328 | ** Returns void |
| 1329 | ** |
| 1330 | *******************************************************************************/ |
| 1331 | void btm_read_local_features_complete (UINT8 *p, UINT16 evt_len) |
| 1332 | { |
| 1333 | tBTM_DEVCB *p_devcb = &btm_cb.devcb; |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1334 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1335 | UNUSED(evt_len); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1336 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1337 | btu_stop_timer (&p_devcb->reset_timer); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1338 | |
| 1339 | STREAM_TO_UINT8 (status, p); |
| 1340 | if (status == HCI_SUCCESS) |
| 1341 | { |
| 1342 | /* Save the Feature Page 0 */ |
| 1343 | STREAM_TO_ARRAY(p_devcb->local_lmp_features[0], |
| 1344 | p, HCI_FEATURE_BYTES_PER_PAGE); |
| 1345 | |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1346 | if ((HCI_LMP_EXTENDED_SUPPORTED(p_devcb->local_lmp_features[HCI_EXT_FEATURES_PAGE_0])) && |
| 1347 | (HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(p_devcb->supported_cmds))) |
| 1348 | { |
| 1349 | /* if local controller has extended features and supports |
| 1350 | **HCI_Read_Local_Extended_Features command, |
| 1351 | ** then start reading these feature starting with extended features page 1 */ |
| 1352 | BTM_TRACE_DEBUG0 ("Start reading local extended features"); |
| 1353 | btm_get_local_ext_features(HCI_EXT_FEATURES_PAGE_1); |
| 1354 | } |
| 1355 | else |
| 1356 | { |
| 1357 | btm_read_all_lmp_features_complete (HCI_EXT_FEATURES_PAGE_0); |
| 1358 | } |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /******************************************************************************* |
| 1363 | ** |
| 1364 | ** Function btm_read_local_ext_features_complete |
| 1365 | ** |
| 1366 | ** Description This function is called when read local extended features |
| 1367 | ** command complete message is received from the HCI. |
| 1368 | ** |
| 1369 | ** Returns void |
| 1370 | ** |
| 1371 | *******************************************************************************/ |
| 1372 | void btm_read_local_ext_features_complete (UINT8 *p, UINT16 evt_len) |
| 1373 | { |
| 1374 | tBTM_DEVCB *p_devcb = &btm_cb.devcb; |
| 1375 | tBTM_CMPL_CB *p_cb = p_devcb->p_reset_cmpl_cb; |
| 1376 | UINT8 status; |
| 1377 | UINT8 page_number; |
| 1378 | UINT8 page_number_max; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1379 | UNUSED(evt_len); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1380 | |
| 1381 | btu_stop_timer (&btm_cb.devcb.reset_timer); |
| 1382 | |
| 1383 | STREAM_TO_UINT8 (status, p); |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1384 | |
| 1385 | if (status != HCI_SUCCESS) |
| 1386 | { |
| 1387 | BTM_TRACE_WARNING1("btm_read_local_ext_features_complete status = 0x%02X", status); |
| 1388 | btm_read_all_lmp_features_complete (HCI_EXT_FEATURES_PAGE_0); |
| 1389 | return; |
| 1390 | } |
| 1391 | |
| 1392 | /* Extract Page number */ |
| 1393 | STREAM_TO_UINT8 (page_number, p); |
| 1394 | |
| 1395 | /* Extract Page number Max */ |
| 1396 | STREAM_TO_UINT8 (page_number_max, p); |
| 1397 | |
| 1398 | if (page_number > HCI_EXT_FEATURES_PAGE_MAX) |
| 1399 | { |
| 1400 | BTM_TRACE_ERROR1("btm_read_local_ext_features_complete page=%d unknown", |
| 1401 | page_number); |
| 1402 | return; |
| 1403 | } |
| 1404 | |
| 1405 | /* Save the extended features Page received */ |
| 1406 | STREAM_TO_ARRAY(btm_cb.devcb.local_lmp_features[page_number], |
| 1407 | p, HCI_FEATURE_BYTES_PER_PAGE); |
| 1408 | |
| 1409 | /* If this is re-read of the 1-st extended page after host supported LMP features are set */ |
| 1410 | if ((page_number == HCI_EXT_FEATURES_PAGE_1) && |
| 1411 | (btm_cb.devcb.lmp_features_host_may_support == BTM_RE_READ_1ST_PAGE)) |
| 1412 | { |
| 1413 | btm_cb.devcb.lmp_features_host_may_support &= ~BTM_RE_READ_1ST_PAGE; |
| 1414 | btm_issue_host_support_for_lmp_features(); |
| 1415 | return; |
| 1416 | } |
| 1417 | |
| 1418 | /* If this is the last page supported by the local BT controller OR */ |
| 1419 | /* if this is the last page supported by the Host */ |
| 1420 | if ((page_number == page_number_max) || |
| 1421 | (page_number == HCI_EXT_FEATURES_PAGE_MAX)) |
| 1422 | { |
| 1423 | BTM_TRACE_DEBUG1("BTM reached last extended features page (%d)", page_number); |
| 1424 | btm_read_all_lmp_features_complete(page_number); |
| 1425 | } |
| 1426 | /* Else (another page must be read) */ |
| 1427 | else |
| 1428 | { |
| 1429 | /* Read the next features page */ |
| 1430 | page_number++; |
| 1431 | BTM_TRACE_DEBUG1("BTM reads next extended features page (%d)", page_number); |
| 1432 | btm_get_local_ext_features(page_number); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | /******************************************************************************* |
| 1437 | ** |
| 1438 | ** Function btm_read_local_supported_cmds_complete |
| 1439 | ** |
| 1440 | ** Description This function is called when local supported commands read |
| 1441 | ** is complete. |
| 1442 | ** |
| 1443 | ** Returns void |
| 1444 | ** |
| 1445 | *******************************************************************************/ |
| 1446 | void btm_read_local_supported_cmds_complete (UINT8 *p) |
| 1447 | { |
| 1448 | tBTM_DEVCB *p_devcb = &btm_cb.devcb; |
| 1449 | UINT8 status; |
| 1450 | |
| 1451 | btu_stop_timer (&(p_devcb->reset_timer)); |
| 1452 | |
| 1453 | STREAM_TO_UINT8 (status, p); |
| 1454 | BTM_TRACE_DEBUG1("btm_read_local_supported_cmds_complete status (0x%02x)", status); |
| 1455 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1456 | if (status == HCI_SUCCESS) |
| 1457 | { |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1458 | /* Save the supported commands bit mask */ |
| 1459 | STREAM_TO_ARRAY(p_devcb->supported_cmds, p, HCI_NUM_SUPP_COMMANDS_BYTES); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1460 | } |
Ganesh Ganapathi Batta | 9d140a9 | 2013-04-11 16:13:14 -0700 | [diff] [blame] | 1461 | |
| 1462 | btm_get_local_features(); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | /******************************************************************************* |
| 1466 | ** |
| 1467 | ** Function btm_write_simple_paring_mode_complete |
| 1468 | ** |
| 1469 | ** Description This function is called when the command complete message |
| 1470 | ** is received from the HCI for the write simple pairing mode |
| 1471 | ** command. |
| 1472 | ** |
| 1473 | ** Returns void |
| 1474 | ** |
| 1475 | *******************************************************************************/ |
| 1476 | void btm_write_simple_paring_mode_complete (UINT8 *p) |
| 1477 | { |
| 1478 | UINT8 status; |
| 1479 | |
| 1480 | STREAM_TO_UINT8 (status, p); |
| 1481 | |
| 1482 | if (status != HCI_SUCCESS) |
| 1483 | { |
| 1484 | BTM_TRACE_WARNING1("btm_write_simple_paring_mode_complete status: 0x%02x", status); |
| 1485 | } |
| 1486 | |
| 1487 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SSP) |
| 1488 | { |
| 1489 | btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_SSP; |
| 1490 | btm_issue_host_support_for_lmp_features(); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | /******************************************************************************* |
| 1495 | ** |
| 1496 | ** Function btm_write_le_host_supported_complete |
| 1497 | ** |
| 1498 | ** Description This function is called when the command complete message |
| 1499 | ** is received from the HCI for the write LE host supported |
| 1500 | ** command. |
| 1501 | ** |
| 1502 | ** Returns void |
| 1503 | ** |
| 1504 | *******************************************************************************/ |
| 1505 | void btm_write_le_host_supported_complete (UINT8 *p) |
| 1506 | { |
| 1507 | UINT8 status; |
| 1508 | |
| 1509 | STREAM_TO_UINT8 (status, p); |
| 1510 | |
| 1511 | if (status != HCI_SUCCESS) |
| 1512 | { |
| 1513 | BTM_TRACE_WARNING1("btm_write_le_host_supported_complete status: 0x%02x", status); |
| 1514 | } |
| 1515 | |
| 1516 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_LE) |
| 1517 | { |
| 1518 | btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_LE; |
| 1519 | if (btm_cb.devcb.lmp_features_host_may_support & BTM_HOST_MAY_SUPP_SIMULT_BR_LE) |
| 1520 | { |
| 1521 | btm_cb.devcb.lmp_features_host_may_support &= ~BTM_HOST_MAY_SUPP_SIMULT_BR_LE; |
| 1522 | } |
| 1523 | btm_issue_host_support_for_lmp_features(); |
| 1524 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /******************************************************************************* |
| 1528 | ** |
| 1529 | ** Function btm_get_voice_coding_support |
| 1530 | ** |
| 1531 | ** Description This function is provides a way to get the voice coding schemes |
| 1532 | ** supported the device. |
| 1533 | ** |
| 1534 | ** Returns A bit mask - Bit 0 if set indicates CVSD support |
| 1535 | ** Bit 1 if set indicates PCM A-law support |
| 1536 | ** Bit 2 if set indicates PCM Mu-law support |
| 1537 | ** |
| 1538 | *******************************************************************************/ |
| 1539 | |
| 1540 | UINT8 btm_get_voice_coding_support( void ) |
| 1541 | { |
| 1542 | UINT8 code = 0; |
| 1543 | |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1544 | if( HCI_LMP_CVSD_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x01 ; |
| 1545 | if( HCI_LMP_A_LAW_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x02 ; |
| 1546 | if( HCI_LMP_U_LAW_SUPPORTED(btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]) ) code |= 0x04 ; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1547 | |
| 1548 | return code ; |
| 1549 | } |
| 1550 | |
| 1551 | /******************************************************************************* |
| 1552 | ** |
| 1553 | ** Function BTM_SetLocalDeviceName |
| 1554 | ** |
| 1555 | ** Description This function is called to set the local device name. |
| 1556 | ** |
| 1557 | ** Returns status of the operation |
| 1558 | ** |
| 1559 | *******************************************************************************/ |
| 1560 | tBTM_STATUS BTM_SetLocalDeviceName (char *p_name) |
| 1561 | { |
| 1562 | UINT8 *p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1563 | |
| 1564 | if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN)) |
| 1565 | return (BTM_ILLEGAL_VALUE); |
| 1566 | |
| 1567 | if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT || |
| 1568 | btm_cb.devcb.state == BTM_DEV_STATE_WAIT_AFTER_RESET) |
| 1569 | return (BTM_DEV_RESET); |
| 1570 | |
| 1571 | #if BTM_MAX_LOC_BD_NAME_LEN > 0 |
| 1572 | /* Save the device name if local storage is enabled */ |
| 1573 | p = (UINT8 *)btm_cb.cfg.bd_name; |
| 1574 | if (p != (UINT8 *)p_name) |
| 1575 | { |
| 1576 | BCM_STRNCPY_S(btm_cb.cfg.bd_name, sizeof(btm_cb.cfg.bd_name), p_name, BTM_MAX_LOC_BD_NAME_LEN); |
| 1577 | btm_cb.cfg.bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0'; |
| 1578 | } |
| 1579 | #else |
| 1580 | p = (UINT8 *)p_name; |
| 1581 | #endif |
| 1582 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1583 | if (btsnd_hcic_change_name(p)) |
| 1584 | return (BTM_CMD_STARTED); |
| 1585 | else |
| 1586 | return (BTM_NO_RESOURCES); |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | /******************************************************************************* |
| 1592 | ** |
| 1593 | ** Function BTM_ReadLocalDeviceName |
| 1594 | ** |
| 1595 | ** Description This function is called to read the local device name. |
| 1596 | ** |
| 1597 | ** Returns status of the operation |
| 1598 | ** If success, BTM_SUCCESS is returned and p_name points stored |
| 1599 | ** local device name |
| 1600 | ** If BTM doesn't store local device name, BTM_NO_RESOURCES is |
| 1601 | ** is returned and p_name is set to NULL |
| 1602 | ** |
| 1603 | *******************************************************************************/ |
| 1604 | tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name) |
| 1605 | { |
| 1606 | #if BTM_MAX_LOC_BD_NAME_LEN > 0 |
| 1607 | *p_name = btm_cb.cfg.bd_name; |
| 1608 | return(BTM_SUCCESS); |
| 1609 | #else |
| 1610 | *p_name = NULL; |
| 1611 | return(BTM_NO_RESOURCES); |
| 1612 | #endif |
| 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | /******************************************************************************* |
| 1617 | ** |
| 1618 | ** Function BTM_ReadLocalDeviceNameFromController |
| 1619 | ** |
| 1620 | ** Description Get local device name from controller. Do not use cached |
| 1621 | ** name (used to get chip-id prior to btm reset complete). |
| 1622 | ** |
| 1623 | ** Returns BTM_CMD_STARTED if successful, otherwise an error |
| 1624 | ** |
| 1625 | *******************************************************************************/ |
| 1626 | tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback) |
| 1627 | { |
| 1628 | /* Check if rln already in progress */ |
| 1629 | if (btm_cb.devcb.p_rln_cmpl_cb) |
| 1630 | return(BTM_NO_RESOURCES); |
| 1631 | |
| 1632 | /* Save callback */ |
| 1633 | btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback; |
| 1634 | |
| 1635 | btsnd_hcic_read_name(); |
| 1636 | btu_start_timer (&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT); |
| 1637 | |
| 1638 | return BTM_CMD_STARTED; |
| 1639 | } |
| 1640 | |
| 1641 | /******************************************************************************* |
| 1642 | ** |
| 1643 | ** Function btm_read_local_name_complete |
| 1644 | ** |
| 1645 | ** Description This function is called when local name read complete. |
| 1646 | ** message is received from the HCI. |
| 1647 | ** |
| 1648 | ** Returns void |
| 1649 | ** |
| 1650 | *******************************************************************************/ |
| 1651 | void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len) |
| 1652 | { |
| 1653 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb; |
| 1654 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1655 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1656 | |
| 1657 | btu_stop_timer (&btm_cb.devcb.rln_timer); |
| 1658 | |
| 1659 | /* If there was a callback address for read local name, call it */ |
| 1660 | btm_cb.devcb.p_rln_cmpl_cb = NULL; |
| 1661 | |
| 1662 | if (p_cb) |
| 1663 | { |
| 1664 | STREAM_TO_UINT8 (status, p); |
| 1665 | |
| 1666 | if (status == HCI_SUCCESS) |
| 1667 | (*p_cb)(p); |
| 1668 | else |
| 1669 | (*p_cb)(NULL); |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | |
| 1674 | /******************************************************************************* |
| 1675 | ** |
| 1676 | ** Function BTM_GetLocalDeviceAddr |
| 1677 | ** |
| 1678 | ** Description This function is called to read the local device address |
| 1679 | ** |
| 1680 | ** Returns void |
| 1681 | ** the local device address is copied into bd_addr |
| 1682 | ** |
| 1683 | *******************************************************************************/ |
| 1684 | void BTM_GetLocalDeviceAddr (BD_ADDR bd_addr) |
| 1685 | { |
| 1686 | memcpy (bd_addr, btm_cb.devcb.local_addr, BD_ADDR_LEN); |
| 1687 | } |
| 1688 | |
| 1689 | /******************************************************************************* |
| 1690 | ** |
| 1691 | ** Function BTM_ReadLocalDeviceAddr |
| 1692 | ** |
| 1693 | ** Description This function is called to read the local device address |
| 1694 | ** |
| 1695 | ** Returns status of the operation |
| 1696 | ** |
| 1697 | *******************************************************************************/ |
| 1698 | tBTM_STATUS BTM_ReadLocalDeviceAddr (tBTM_CMPL_CB *p_cb) |
| 1699 | { |
| 1700 | if(p_cb) |
| 1701 | (*p_cb)(btm_cb.devcb.local_addr); |
| 1702 | |
| 1703 | return (BTM_SUCCESS); |
| 1704 | } |
| 1705 | |
| 1706 | |
| 1707 | /******************************************************************************* |
| 1708 | ** |
| 1709 | ** Function btm_read_local_addr_complete |
| 1710 | ** |
| 1711 | ** Description This function is called when local BD Addr read complete |
| 1712 | ** message is received from the HCI. |
| 1713 | ** |
| 1714 | ** Returns void |
| 1715 | ** |
| 1716 | *******************************************************************************/ |
| 1717 | void btm_read_local_addr_complete (UINT8 *p, UINT16 evt_len) |
| 1718 | { |
| 1719 | UINT8 status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1720 | UNUSED(evt_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1721 | |
| 1722 | STREAM_TO_UINT8 (status, p); |
| 1723 | |
| 1724 | if (status == HCI_SUCCESS) |
| 1725 | { |
| 1726 | STREAM_TO_BDADDR (btm_cb.devcb.local_addr, p); |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | |
| 1731 | /******************************************************************************* |
| 1732 | ** |
| 1733 | ** Function BTM_ReadLocalVersion |
| 1734 | ** |
| 1735 | ** Description This function is called to read the local device version |
| 1736 | ** |
| 1737 | ** Returns status of the operation |
| 1738 | ** |
| 1739 | *******************************************************************************/ |
| 1740 | tBTM_STATUS BTM_ReadLocalVersion (tBTM_VERSION_INFO *p_vers) |
| 1741 | { |
| 1742 | /* Make sure the device has retrieved the info (not being reset) */ |
| 1743 | if (btm_cb.devcb.state < BTM_DEV_STATE_READY) |
| 1744 | return (BTM_DEV_RESET); |
| 1745 | |
| 1746 | *p_vers = btm_cb.devcb.local_version; |
| 1747 | |
| 1748 | return (BTM_SUCCESS); |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | /******************************************************************************* |
| 1755 | ** |
| 1756 | ** Function BTM_SetDeviceClass |
| 1757 | ** |
| 1758 | ** Description This function is called to set the local device class |
| 1759 | ** |
| 1760 | ** Returns status of the operation |
| 1761 | ** |
| 1762 | *******************************************************************************/ |
| 1763 | tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class) |
| 1764 | { |
| 1765 | if(!memcmp (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN)) |
| 1766 | return(BTM_SUCCESS); |
| 1767 | |
| 1768 | memcpy (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN); |
| 1769 | |
| 1770 | if (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT || |
| 1771 | btm_cb.devcb.state == BTM_DEV_STATE_WAIT_AFTER_RESET) |
| 1772 | return (BTM_DEV_RESET); |
| 1773 | |
| 1774 | if (!btsnd_hcic_write_dev_class (dev_class)) |
| 1775 | return (BTM_NO_RESOURCES); |
| 1776 | |
| 1777 | return (BTM_SUCCESS); |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | /******************************************************************************* |
| 1782 | ** |
| 1783 | ** Function BTM_ReadDeviceClass |
| 1784 | ** |
| 1785 | ** Description This function is called to read the local device class |
| 1786 | ** |
| 1787 | ** Returns pointer to the device class |
| 1788 | ** |
| 1789 | *******************************************************************************/ |
| 1790 | UINT8 *BTM_ReadDeviceClass (void) |
| 1791 | { |
| 1792 | return ((UINT8 *)btm_cb.devcb.dev_class); |
| 1793 | } |
| 1794 | |
| 1795 | |
| 1796 | /******************************************************************************* |
| 1797 | ** |
| 1798 | ** Function BTM_ReadLocalFeatures |
| 1799 | ** |
| 1800 | ** Description This function is called to read the local features |
| 1801 | ** |
| 1802 | ** Returns pointer to the local features string |
| 1803 | ** |
| 1804 | *******************************************************************************/ |
| 1805 | UINT8 *BTM_ReadLocalFeatures (void) |
| 1806 | { |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 1807 | return (btm_cb.devcb.local_lmp_features[HCI_EXT_FEATURES_PAGE_0]); |
| 1808 | } |
| 1809 | |
| 1810 | /******************************************************************************* |
| 1811 | ** |
| 1812 | ** Function BTM_ReadLocalExtendedFeatures |
| 1813 | ** |
| 1814 | ** Description This function is called to read the local extended features |
| 1815 | ** |
| 1816 | ** Returns pointer to the local extended features mask or NULL if bad |
| 1817 | ** page |
| 1818 | ** |
| 1819 | *******************************************************************************/ |
| 1820 | UINT8 *BTM_ReadLocalExtendedFeatures (UINT8 page_number) |
| 1821 | { |
| 1822 | if (page_number <= HCI_EXT_FEATURES_PAGE_MAX) |
| 1823 | return (btm_cb.devcb.local_lmp_features[page_number]); |
| 1824 | |
| 1825 | BTM_TRACE_ERROR1("Warning: BTM_ReadLocalExtendedFeatures page %d unknown", |
| 1826 | page_number); |
| 1827 | return NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | /******************************************************************************* |
| 1831 | ** |
| 1832 | ** Function BTM_ReadBrcmFeatures |
| 1833 | ** |
| 1834 | ** Description This function is called to read the Broadcom specific features |
| 1835 | ** |
| 1836 | ** Returns pointer to the Broadcom features string |
| 1837 | ** |
| 1838 | *******************************************************************************/ |
| 1839 | UINT8 *BTM_ReadBrcmFeatures (void) |
| 1840 | { |
| 1841 | return (btm_cb.devcb.brcm_features); |
| 1842 | } |
| 1843 | |
| 1844 | /******************************************************************************* |
| 1845 | ** |
| 1846 | ** Function BTM_RegisterForDeviceStatusNotif |
| 1847 | ** |
| 1848 | ** Description This function is called to register for device status |
| 1849 | ** change notifications. |
| 1850 | ** |
| 1851 | ** If one registration is already there calling function should |
| 1852 | ** save the pointer to the function that is return and |
| 1853 | ** call it when processing of the event is complete |
| 1854 | ** |
| 1855 | ** Returns status of the operation |
| 1856 | ** |
| 1857 | *******************************************************************************/ |
| 1858 | tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb) |
| 1859 | { |
| 1860 | tBTM_DEV_STATUS_CB *p_prev = btm_cb.devcb.p_dev_status_cb; |
| 1861 | |
| 1862 | btm_cb.devcb.p_dev_status_cb = p_cb; |
| 1863 | return (p_prev); |
| 1864 | } |
| 1865 | |
| 1866 | /******************************************************************************* |
| 1867 | ** |
| 1868 | ** Function BTM_VendorSpecificCommand |
| 1869 | ** |
| 1870 | ** Description Send a vendor specific HCI command to the controller. |
| 1871 | ** |
| 1872 | ** Returns |
| 1873 | ** BTM_SUCCESS Command sent. Does not expect command complete |
| 1874 | ** event. (command cmpl callback param is NULL) |
| 1875 | ** BTM_CMD_STARTED Command sent. Waiting for command cmpl event. |
| 1876 | ** |
| 1877 | ** Notes |
| 1878 | ** Opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC. |
| 1879 | ** |
| 1880 | *******************************************************************************/ |
| 1881 | tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len, |
| 1882 | UINT8 *p_param_buf, tBTM_VSC_CMPL_CB *p_cb) |
| 1883 | { |
| 1884 | void *p_buf; |
| 1885 | |
| 1886 | BTM_TRACE_EVENT2 ("BTM: BTM_VendorSpecificCommand: Opcode: 0x%04X, ParamLen: %i.", |
| 1887 | opcode, param_len); |
| 1888 | |
| 1889 | /* Allocate a buffer to hold HCI command plus the callback function */ |
| 1890 | if ((p_buf = GKI_getbuf((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) + |
| 1891 | param_len + HCIC_PREAMBLE_SIZE))) != NULL) |
| 1892 | { |
| 1893 | /* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */ |
| 1894 | btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb); |
| 1895 | |
| 1896 | /* Return value */ |
| 1897 | if (p_cb != NULL) |
| 1898 | return (BTM_CMD_STARTED); |
| 1899 | else |
| 1900 | return (BTM_SUCCESS); |
| 1901 | } |
| 1902 | else |
| 1903 | return (BTM_NO_RESOURCES); |
| 1904 | |
| 1905 | } |
| 1906 | |
| 1907 | |
| 1908 | /******************************************************************************* |
| 1909 | ** |
| 1910 | ** Function btm_vsc_complete |
| 1911 | ** |
| 1912 | ** Description This function is called when local HCI Vendor Specific |
| 1913 | ** Command complete message is received from the HCI. |
| 1914 | ** |
| 1915 | ** Returns void |
| 1916 | ** |
| 1917 | *******************************************************************************/ |
| 1918 | void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, |
| 1919 | tBTM_CMPL_CB *p_vsc_cplt_cback) |
| 1920 | { |
| 1921 | tBTM_VSC_CMPL vcs_cplt_params; |
| 1922 | |
| 1923 | /* If there was a callback address for vcs complete, call it */ |
| 1924 | if (p_vsc_cplt_cback) |
| 1925 | { |
| 1926 | /* Pass paramters to the callback function */ |
| 1927 | vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */ |
| 1928 | vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */ |
| 1929 | vcs_cplt_params.p_param_buf = p; |
| 1930 | (*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */ |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | /******************************************************************************* |
| 1935 | ** |
| 1936 | ** Function BTM_RegisterForVSEvents |
| 1937 | ** |
| 1938 | ** Description This function is called to register/deregister for vendor |
| 1939 | ** specific HCI events. |
| 1940 | ** |
| 1941 | ** If is_register=TRUE, then the function will be registered; |
| 1942 | ** if is_register=FALSE, then the function will be deregistered. |
| 1943 | ** |
| 1944 | ** Returns BTM_SUCCESS if successful, |
| 1945 | ** BTM_BUSY if maximum number of callbacks have already been |
| 1946 | ** registered. |
| 1947 | ** |
| 1948 | *******************************************************************************/ |
| 1949 | tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register) |
| 1950 | { |
| 1951 | tBTM_STATUS retval = BTM_SUCCESS; |
| 1952 | UINT8 i, free_idx = BTM_MAX_VSE_CALLBACKS; |
| 1953 | |
| 1954 | /* See if callback is already registered */ |
| 1955 | for (i=0; i<BTM_MAX_VSE_CALLBACKS; i++) |
| 1956 | { |
| 1957 | if (btm_cb.devcb.p_vend_spec_cb[i] == NULL) |
| 1958 | { |
| 1959 | /* Found a free slot. Store index */ |
| 1960 | free_idx = i; |
| 1961 | } |
| 1962 | else if (btm_cb.devcb.p_vend_spec_cb[i] == p_cb) |
| 1963 | { |
| 1964 | /* Found callback in lookup table. If deregistering, clear the entry. */ |
| 1965 | if (is_register == FALSE) |
| 1966 | { |
| 1967 | btm_cb.devcb.p_vend_spec_cb[i] = NULL; |
| 1968 | BTM_TRACE_EVENT0("BTM Deregister For VSEvents is successfully"); |
| 1969 | } |
| 1970 | return (BTM_SUCCESS); |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | /* Didn't find callback. Add callback to free slot if registering */ |
| 1975 | if (is_register) |
| 1976 | { |
| 1977 | if (free_idx < BTM_MAX_VSE_CALLBACKS) |
| 1978 | { |
| 1979 | btm_cb.devcb.p_vend_spec_cb[free_idx] = p_cb; |
| 1980 | BTM_TRACE_EVENT0("BTM Register For VSEvents is successfully"); |
| 1981 | } |
| 1982 | else |
| 1983 | { |
| 1984 | /* No free entries available */ |
| 1985 | BTM_TRACE_ERROR0 ("BTM_RegisterForVSEvents: too many callbacks registered"); |
| 1986 | |
| 1987 | retval = BTM_NO_RESOURCES; |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | return (retval); |
| 1992 | } |
| 1993 | |
| 1994 | /******************************************************************************* |
| 1995 | ** |
| 1996 | ** Function btm_vendor_specific_evt |
| 1997 | ** |
| 1998 | ** Description Process event HCI_VENDOR_SPECIFIC_EVT |
| 1999 | ** |
| 2000 | ** Note: Some controllers do not send command complete, so |
| 2001 | ** the callback and busy flag are cleared here also. |
| 2002 | ** |
| 2003 | ** Returns void |
| 2004 | ** |
| 2005 | *******************************************************************************/ |
| 2006 | void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len) |
| 2007 | { |
| 2008 | UINT8 i; |
| 2009 | |
| 2010 | BTM_TRACE_DEBUG0 ("BTM Event: Vendor Specific event from controller"); |
| 2011 | |
| 2012 | for (i=0; i<BTM_MAX_VSE_CALLBACKS; i++) |
| 2013 | { |
| 2014 | if (btm_cb.devcb.p_vend_spec_cb[i]) |
| 2015 | (*btm_cb.devcb.p_vend_spec_cb[i])(evt_len, p); |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | /******************************************************************************* |
| 2021 | ** |
| 2022 | ** Function BTM_WritePageTimeout |
| 2023 | ** |
| 2024 | ** Description Send HCI Write Page Timeout. |
| 2025 | ** |
| 2026 | ** Returns |
| 2027 | ** BTM_SUCCESS Command sent. |
| 2028 | ** BTM_NO_RESOURCES If out of resources to send the command. |
| 2029 | ** |
| 2030 | ** |
| 2031 | *******************************************************************************/ |
| 2032 | tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout) |
| 2033 | { |
| 2034 | BTM_TRACE_EVENT1 ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout); |
| 2035 | |
| 2036 | /* Send the HCI command */ |
| 2037 | if (btsnd_hcic_write_page_tout (timeout)) |
| 2038 | return (BTM_SUCCESS); |
| 2039 | else |
| 2040 | return (BTM_NO_RESOURCES); |
| 2041 | } |
| 2042 | |
| 2043 | /******************************************************************************* |
| 2044 | ** |
| 2045 | ** Function BTM_WriteVoiceSettings |
| 2046 | ** |
| 2047 | ** Description Send HCI Write Voice Settings command. |
| 2048 | ** See hcidefs.h for settings bitmask values. |
| 2049 | ** |
| 2050 | ** Returns |
| 2051 | ** BTM_SUCCESS Command sent. |
| 2052 | ** BTM_NO_RESOURCES If out of resources to send the command. |
| 2053 | ** |
| 2054 | ** |
| 2055 | *******************************************************************************/ |
| 2056 | tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings) |
| 2057 | { |
| 2058 | BTM_TRACE_EVENT1 ("BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.", settings); |
| 2059 | |
| 2060 | /* Send the HCI command */ |
| 2061 | if (btsnd_hcic_write_voice_settings ((UINT16)(settings & 0x03ff))) |
| 2062 | return (BTM_SUCCESS); |
| 2063 | |
| 2064 | return (BTM_NO_RESOURCES); |
| 2065 | } |
| 2066 | |
| 2067 | /******************************************************************************* |
| 2068 | ** |
| 2069 | ** Function BTM_EnableTestMode |
| 2070 | ** |
| 2071 | ** Description Send HCI the enable device under test command. |
| 2072 | ** |
| 2073 | ** Note: Controller can only be taken out of this mode by |
| 2074 | ** resetting the controller. |
| 2075 | ** |
| 2076 | ** Returns |
| 2077 | ** BTM_SUCCESS Command sent. |
| 2078 | ** BTM_NO_RESOURCES If out of resources to send the command. |
| 2079 | ** |
| 2080 | ** |
| 2081 | *******************************************************************************/ |
| 2082 | tBTM_STATUS BTM_EnableTestMode(void) |
| 2083 | { |
| 2084 | UINT8 cond; |
| 2085 | |
| 2086 | BTM_TRACE_EVENT0 ("BTM: BTM_EnableTestMode"); |
| 2087 | |
| 2088 | /* set auto accept connection as this is needed during test mode */ |
| 2089 | /* Allocate a buffer to hold HCI command */ |
| 2090 | cond = HCI_DO_AUTO_ACCEPT_CONNECT; |
| 2091 | if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP, |
| 2092 | HCI_FILTER_COND_NEW_DEVICE, |
| 2093 | &cond, sizeof(cond))) |
| 2094 | { |
| 2095 | return (BTM_NO_RESOURCES); |
| 2096 | } |
| 2097 | |
| 2098 | /* put device to connectable mode */ |
| 2099 | if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW, |
| 2100 | BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS) |
| 2101 | { |
| 2102 | return BTM_NO_RESOURCES; |
| 2103 | } |
| 2104 | |
| 2105 | /* put device to discoverable mode */ |
| 2106 | if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW, |
| 2107 | BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS) |
| 2108 | { |
| 2109 | return BTM_NO_RESOURCES; |
| 2110 | } |
| 2111 | |
| 2112 | /* mask off all of event from controller */ |
| 2113 | if (!btsnd_hcic_set_event_mask(LOCAL_BR_EDR_CONTROLLER_ID, |
| 2114 | (UINT8 *)"\x00\x00\x00\x00\x00\x00\x00\x00")) |
| 2115 | { |
| 2116 | return BTM_NO_RESOURCES; |
| 2117 | } |
| 2118 | |
| 2119 | /* Send the HCI command */ |
| 2120 | if (btsnd_hcic_enable_test_mode ()) |
| 2121 | return (BTM_SUCCESS); |
| 2122 | else |
| 2123 | return (BTM_NO_RESOURCES); |
| 2124 | } |
| 2125 | |
| 2126 | /******************************************************************************* |
| 2127 | ** |
| 2128 | ** Function btm_get_hci_version |
| 2129 | ** |
| 2130 | ** Description Local function called to retrieve the current HCI version |
| 2131 | ** |
| 2132 | ** Returns Bluetooth HCI Version returned by the controller |
| 2133 | ** |
| 2134 | *******************************************************************************/ |
| 2135 | UINT8 btm_get_hci_version (void) |
| 2136 | { |
| 2137 | return (btm_cb.devcb.local_version.hci_version); |
| 2138 | } |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | /******************************************************************************* |
| 2143 | ** |
| 2144 | ** Function BTM_ReadStoredLinkKey |
| 2145 | ** |
| 2146 | ** Description This function is called to obtain link key for the specified |
| 2147 | ** device from the NVRAM storage attached to the Bluetooth |
| 2148 | ** controller. |
| 2149 | ** |
| 2150 | ** Parameters: bd_addr - Address of the device |
| 2151 | ** p_cb - Call back function to be called to return |
| 2152 | ** the results |
| 2153 | ** |
| 2154 | *******************************************************************************/ |
| 2155 | tBTM_STATUS BTM_ReadStoredLinkKey (BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb) |
| 2156 | { |
| 2157 | BD_ADDR local_bd_addr; |
| 2158 | BOOLEAN read_all_flag = FALSE; |
| 2159 | |
| 2160 | /* Check if the previous command is completed */ |
| 2161 | if (btm_cb.devcb.p_stored_link_key_cmpl_cb) |
| 2162 | return (BTM_BUSY); |
| 2163 | |
| 2164 | if (!bd_addr) |
| 2165 | { |
| 2166 | /* This is to read all the link keys */ |
| 2167 | read_all_flag = TRUE; |
| 2168 | |
| 2169 | /* We don't care the BD address. Just pass a non zero pointer */ |
| 2170 | bd_addr = local_bd_addr; |
| 2171 | } |
| 2172 | |
| 2173 | BTM_TRACE_EVENT1 ("BTM: BTM_ReadStoredLinkKey: Read_All: %s", |
| 2174 | read_all_flag ? "TRUE" : "FALSE"); |
| 2175 | |
| 2176 | /* Send the HCI command */ |
| 2177 | btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb; |
| 2178 | if (btsnd_hcic_read_stored_key (bd_addr, read_all_flag)) |
| 2179 | return (BTM_SUCCESS); |
| 2180 | else |
| 2181 | return (BTM_NO_RESOURCES); |
| 2182 | |
| 2183 | } |
| 2184 | |
| 2185 | |
| 2186 | /******************************************************************************* |
| 2187 | ** |
| 2188 | ** Function BTM_WriteStoredLinkKey |
| 2189 | ** |
| 2190 | ** Description This function is called to write link keys for the specified |
| 2191 | ** device addresses to the NVRAM storage attached to the Bluetooth |
| 2192 | ** controller. |
| 2193 | ** |
| 2194 | ** Parameters: num_keys - Number of link keys |
| 2195 | ** bd_addr - Addresses of the devices |
| 2196 | ** link_key - Link Keys to be stored |
| 2197 | ** p_cb - Call back function to be called to return |
| 2198 | ** the results |
| 2199 | ** |
| 2200 | *******************************************************************************/ |
| 2201 | tBTM_STATUS BTM_WriteStoredLinkKey (UINT8 num_keys, |
| 2202 | BD_ADDR *bd_addr, |
| 2203 | LINK_KEY *link_key, |
| 2204 | tBTM_CMPL_CB *p_cb) |
| 2205 | { |
| 2206 | /* Check if the previous command is completed */ |
| 2207 | if (btm_cb.devcb.p_stored_link_key_cmpl_cb) |
| 2208 | return (BTM_BUSY); |
| 2209 | |
| 2210 | BTM_TRACE_EVENT1 ("BTM: BTM_WriteStoredLinkKey: num_keys: %d", num_keys); |
| 2211 | |
| 2212 | /* Check the maximum number of link keys */ |
| 2213 | if(num_keys > HCI_MAX_NUM_OF_LINK_KEYS_PER_CMMD) |
| 2214 | num_keys = HCI_MAX_NUM_OF_LINK_KEYS_PER_CMMD; |
| 2215 | |
| 2216 | /* Send the HCI command */ |
| 2217 | btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb; |
| 2218 | if (btsnd_hcic_write_stored_key (num_keys, bd_addr, link_key)) |
| 2219 | return (BTM_SUCCESS); |
| 2220 | else |
| 2221 | return (BTM_NO_RESOURCES); |
| 2222 | |
| 2223 | } |
| 2224 | |
| 2225 | |
| 2226 | /******************************************************************************* |
| 2227 | ** |
| 2228 | ** Function BTM_DeleteStoredLinkKey |
| 2229 | ** |
| 2230 | ** Description This function is called to delete link key for the specified |
| 2231 | ** device addresses from the NVRAM storage attached to the Bluetooth |
| 2232 | ** controller. |
| 2233 | ** |
| 2234 | ** Parameters: bd_addr - Addresses of the devices |
| 2235 | ** p_cb - Call back function to be called to return |
| 2236 | ** the results |
| 2237 | ** |
| 2238 | *******************************************************************************/ |
| 2239 | tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb) |
| 2240 | { |
| 2241 | BD_ADDR local_bd_addr; |
| 2242 | BOOLEAN delete_all_flag = FALSE; |
| 2243 | |
| 2244 | /* Check if the previous command is completed */ |
| 2245 | if (btm_cb.devcb.p_stored_link_key_cmpl_cb) |
| 2246 | return (BTM_BUSY); |
| 2247 | |
| 2248 | if (!bd_addr) |
| 2249 | { |
| 2250 | /* This is to delete all link keys */ |
| 2251 | delete_all_flag = TRUE; |
| 2252 | |
| 2253 | /* We don't care the BD address. Just pass a non zero pointer */ |
| 2254 | bd_addr = local_bd_addr; |
| 2255 | } |
| 2256 | |
| 2257 | BTM_TRACE_EVENT1 ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s", |
| 2258 | delete_all_flag ? "TRUE" : "FALSE"); |
| 2259 | |
| 2260 | /* Send the HCI command */ |
| 2261 | btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb; |
| 2262 | if (!btsnd_hcic_delete_stored_key (bd_addr, delete_all_flag)) |
| 2263 | { |
| 2264 | return (BTM_NO_RESOURCES); |
| 2265 | } |
| 2266 | else |
| 2267 | return (BTM_SUCCESS); |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | /******************************************************************************* |
| 2272 | ** |
| 2273 | ** Function btm_read_stored_link_key_complete |
| 2274 | ** |
| 2275 | ** Description This function is called when the command complete message |
| 2276 | ** is received from the HCI for the read stored link key command. |
| 2277 | ** |
| 2278 | ** Returns void |
| 2279 | ** |
| 2280 | *******************************************************************************/ |
| 2281 | void btm_read_stored_link_key_complete (UINT8 *p) |
| 2282 | { |
| 2283 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; |
| 2284 | tBTM_READ_STORED_LINK_KEY_COMPLETE result; |
| 2285 | |
| 2286 | /* If there was a callback registered for read stored link key, call it */ |
| 2287 | btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL; |
| 2288 | |
| 2289 | if (p_cb) |
| 2290 | { |
| 2291 | /* Set the call back event to indicate command complete */ |
| 2292 | result.event = BTM_CB_EVT_READ_STORED_LINK_KEYS; |
| 2293 | |
| 2294 | /* Extract the result fields from the HCI event if status is success */ |
| 2295 | STREAM_TO_UINT8 (result.status, p); |
| 2296 | if (result.status == HCI_SUCCESS) |
| 2297 | { |
| 2298 | STREAM_TO_UINT16 (result.max_keys, p); |
| 2299 | STREAM_TO_UINT16 (result.read_keys, p); |
| 2300 | } |
| 2301 | else |
| 2302 | { |
| 2303 | BTM_TRACE_WARNING1("Read stored link key status %d", result.status); |
| 2304 | result.max_keys = 0; |
| 2305 | result.read_keys = 0; |
| 2306 | } |
| 2307 | /* Call the call back and pass the result */ |
| 2308 | (*p_cb)(&result); |
| 2309 | } |
| 2310 | } |
| 2311 | |
| 2312 | |
| 2313 | /******************************************************************************* |
| 2314 | ** |
| 2315 | ** Function btm_write_stored_link_key_complete |
| 2316 | ** |
| 2317 | ** Description This function is called when the command complete message |
| 2318 | ** is received from the HCI for the write stored link key command. |
| 2319 | ** |
| 2320 | ** Returns void |
| 2321 | ** |
| 2322 | *******************************************************************************/ |
| 2323 | void btm_write_stored_link_key_complete (UINT8 *p) |
| 2324 | { |
| 2325 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; |
| 2326 | tBTM_WRITE_STORED_LINK_KEY_COMPLETE result; |
| 2327 | |
| 2328 | /* If there was a callback registered for read stored link key, call it */ |
| 2329 | btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL; |
| 2330 | |
| 2331 | if (p_cb) |
| 2332 | { |
| 2333 | /* Set the call back event to indicate command complete */ |
| 2334 | result.event = BTM_CB_EVT_WRITE_STORED_LINK_KEYS; |
| 2335 | |
| 2336 | /* Extract the result fields from the HCI event */ |
| 2337 | STREAM_TO_UINT8 (result.status, p); |
| 2338 | STREAM_TO_UINT8 (result.num_keys, p); |
| 2339 | |
| 2340 | /* Call the call back and pass the result */ |
| 2341 | (*p_cb)(&result); |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | |
| 2346 | /******************************************************************************* |
| 2347 | ** |
| 2348 | ** Function btm_delete_stored_link_key_complete |
| 2349 | ** |
| 2350 | ** Description This function is called when the command complete message |
| 2351 | ** is received from the HCI for the delete stored link key command. |
| 2352 | ** |
| 2353 | ** Returns void |
| 2354 | ** |
| 2355 | *******************************************************************************/ |
| 2356 | void btm_delete_stored_link_key_complete (UINT8 *p) |
| 2357 | { |
| 2358 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; |
| 2359 | tBTM_DELETE_STORED_LINK_KEY_COMPLETE result; |
| 2360 | |
| 2361 | /* If there was a callback registered for read stored link key, call it */ |
| 2362 | btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL; |
| 2363 | |
| 2364 | if (p_cb) |
| 2365 | { |
| 2366 | /* Set the call back event to indicate command complete */ |
| 2367 | result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS; |
| 2368 | |
| 2369 | /* Extract the result fields from the HCI event */ |
| 2370 | STREAM_TO_UINT8 (result.status, p); |
| 2371 | STREAM_TO_UINT16 (result.num_keys, p); |
| 2372 | |
| 2373 | /* Call the call back and pass the result */ |
| 2374 | (*p_cb)(&result); |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | |
| 2379 | /******************************************************************************* |
| 2380 | ** |
| 2381 | ** Function btm_return_link_keys_evt |
| 2382 | ** |
| 2383 | ** Description This function is called when the return link keys event |
| 2384 | ** is received from the HCI for the read stored link key command. |
| 2385 | ** |
| 2386 | ** Returns void |
| 2387 | ** |
| 2388 | *******************************************************************************/ |
| 2389 | void btm_return_link_keys_evt (tBTM_RETURN_LINK_KEYS_EVT *result) |
| 2390 | { |
| 2391 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb; |
| 2392 | UINT8 i, *p, *p1; |
| 2393 | UINT8 bd_addr[BD_ADDR_LEN]; |
| 2394 | UINT8 link_key[LINK_KEY_LEN]; |
| 2395 | |
| 2396 | /* Call the call back to pass the link keys to application */ |
| 2397 | if (p_cb) |
| 2398 | { |
| 2399 | /* Change the BD addr and Link key in to big endian order */ |
| 2400 | p = (UINT8 *)(result + 1); |
| 2401 | for (i=0; i<result->num_keys; i++) |
| 2402 | { |
| 2403 | /* Initialize the backup pointer */ |
| 2404 | p1 = p; |
| 2405 | |
| 2406 | /* Extract the BD Addr and Link Key */ |
| 2407 | REVERSE_STREAM_TO_ARRAY(bd_addr, p1, BD_ADDR_LEN); |
| 2408 | REVERSE_STREAM_TO_ARRAY(link_key, p1, LINK_KEY_LEN); |
| 2409 | |
| 2410 | /* Write the BD Addr and Link Key back in big endian format */ |
| 2411 | ARRAY_TO_STREAM(p, bd_addr, BD_ADDR_LEN); |
| 2412 | ARRAY_TO_STREAM(p, link_key, LINK_KEY_LEN); |
| 2413 | } |
| 2414 | |
| 2415 | (*p_cb)(result); |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | |
| 2421 | /******************************************************************************* |
| 2422 | ** |
| 2423 | ** Function btm_report_device_status |
| 2424 | ** |
| 2425 | ** Description This function is called when there is a change in the device |
| 2426 | ** status. This function will report the new device status to |
| 2427 | ** the application |
| 2428 | ** |
| 2429 | ** Returns void |
| 2430 | ** |
| 2431 | *******************************************************************************/ |
| 2432 | void btm_report_device_status (tBTM_DEV_STATUS status) |
| 2433 | { |
| 2434 | tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb; |
| 2435 | |
| 2436 | /* Call the call back to pass the device status to application */ |
| 2437 | if (p_cb) |
| 2438 | (*p_cb)(status); |
| 2439 | } |
| 2440 | |
| 2441 | |