1 /****************************************************************************** 2 * 3 * Copyright 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 #ifndef BTM_API_TYPES_H 20 #define BTM_API_TYPES_H 21 22 #include "bt_target.h" 23 #include "device/include/esco_parameters.h" 24 #include "hcidefs.h" 25 #include "smp_api_types.h" 26 27 /* Maximum number of bytes allowed for vendor specific command parameters */ 28 #define BTM_MAX_VENDOR_SPECIFIC_LEN HCI_COMMAND_SIZE 29 30 /* BTM application return status codes */ 31 enum { 32 BTM_SUCCESS = 0, /* 0 Command succeeded */ 33 BTM_CMD_STARTED, /* 1 Command started OK. */ 34 BTM_BUSY, /* 2 Device busy with another command */ 35 BTM_NO_RESOURCES, /* 3 No resources to issue command */ 36 BTM_MODE_UNSUPPORTED, /* 4 Request for 1 or more unsupported modes */ 37 BTM_ILLEGAL_VALUE, /* 5 Illegal parameter value */ 38 BTM_WRONG_MODE, /* 6 Device in wrong mode for request */ 39 BTM_UNKNOWN_ADDR, /* 7 Unknown remote BD address */ 40 BTM_DEVICE_TIMEOUT, /* 8 Device timeout */ 41 BTM_BAD_VALUE_RET, /* 9 A bad value was received from HCI */ 42 BTM_ERR_PROCESSING, /* 10 Generic error */ 43 BTM_NOT_AUTHORIZED, /* 11 Authorization failed */ 44 BTM_DEV_RESET, /* 12 Device has been reset */ 45 BTM_CMD_STORED, /* 13 request is stored in control block */ 46 BTM_ILLEGAL_ACTION, /* 14 state machine gets illegal command */ 47 BTM_DELAY_CHECK, /* 15 delay the check on encryption */ 48 BTM_SCO_BAD_LENGTH, /* 16 Bad SCO over HCI data length */ 49 BTM_SUCCESS_NO_SECURITY, /* 17 security passed, no security set */ 50 BTM_FAILED_ON_SECURITY, /* 18 security failed */ 51 BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */ 52 BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be 53 supported */ 54 BTM_DEV_BLACKLISTED /* 21 The device is Blacklisted */ 55 }; 56 57 typedef uint8_t tBTM_STATUS; 58 59 /* Device name of peer (may be truncated to save space in BTM database) */ 60 typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1]; 61 62 /* Structure returned with Vendor Specific Command complete callback */ 63 typedef struct { 64 uint16_t opcode; 65 uint16_t param_len; 66 uint8_t* p_param_buf; 67 } tBTM_VSC_CMPL; 68 69 /************************************************** 70 * Device Control and General Callback Functions 71 **************************************************/ 72 /* Callback function for when device status changes. Appl must poll for 73 * what the new state is (BTM_IsDeviceUp). The event occurs whenever the stack 74 * has detected that the controller status has changed. This asynchronous event 75 * is enabled/disabled by calling BTM_RegisterForDeviceStatusNotif(). 76 */ 77 enum { BTM_DEV_STATUS_UP, BTM_DEV_STATUS_DOWN, BTM_DEV_STATUS_CMD_TOUT }; 78 79 typedef uint8_t tBTM_DEV_STATUS; 80 81 typedef void(tBTM_DEV_STATUS_CB)(tBTM_DEV_STATUS status); 82 83 /* Callback function for when a vendor specific event occurs. The length and 84 * array of returned parameter bytes are included. This asynchronous event 85 * is enabled/disabled by calling BTM_RegisterForVSEvents(). 86 */ 87 typedef void(tBTM_VS_EVT_CB)(uint8_t len, uint8_t* p); 88 89 /* General callback function for notifying an application that a synchronous 90 * BTM function is complete. The pointer contains the address of any returned 91 * data. 92 */ 93 typedef void(tBTM_CMPL_CB)(void* p1); 94 95 /* VSC callback function for notifying an application that a synchronous 96 * BTM function is complete. The pointer contains the address of any returned 97 * data. 98 */ 99 typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1); 100 101 /***************************************************************************** 102 * DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device 103 ****************************************************************************/ 104 /******************************* 105 * Device Discovery Constants 106 *******************************/ 107 /* Discoverable modes */ 108 #define BTM_NON_DISCOVERABLE 0 109 #define BTM_LIMITED_DISCOVERABLE 1 110 #define BTM_GENERAL_DISCOVERABLE 2 111 #define BTM_DISCOVERABLE_MASK \ 112 (BTM_LIMITED_DISCOVERABLE | BTM_GENERAL_DISCOVERABLE) 113 #define BTM_MAX_DISCOVERABLE BTM_GENERAL_DISCOVERABLE 114 /* high byte for BLE Discoverable modes */ 115 #define BTM_BLE_NON_DISCOVERABLE 0x0000 116 #define BTM_BLE_LIMITED_DISCOVERABLE 0x0100 117 #define BTM_BLE_GENERAL_DISCOVERABLE 0x0200 118 #define BTM_BLE_MAX_DISCOVERABLE BTM_BLE_GENERAL_DISCOVERABLE 119 #define BTM_BLE_DISCOVERABLE_MASK \ 120 (BTM_BLE_NON_DISCOVERABLE | BTM_BLE_LIMITED_DISCOVERABLE | \ 121 BTM_BLE_GENERAL_DISCOVERABLE) 122 123 /* Connectable modes */ 124 #define BTM_NON_CONNECTABLE 0 125 #define BTM_CONNECTABLE 1 126 #define BTM_CONNECTABLE_MASK (BTM_NON_CONNECTABLE | BTM_CONNECTABLE) 127 /* high byte for BLE Connectable modes */ 128 #define BTM_BLE_NON_CONNECTABLE 0x0000 129 #define BTM_BLE_CONNECTABLE 0x0100 130 #define BTM_BLE_MAX_CONNECTABLE BTM_BLE_CONNECTABLE 131 #define BTM_BLE_CONNECTABLE_MASK (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE) 132 133 /* Inquiry modes 134 * Note: These modes are associated with the inquiry active values (BTM_*ACTIVE) 135 */ 136 #define BTM_INQUIRY_NONE 0 137 #define BTM_GENERAL_INQUIRY 0x01 138 #define BTM_LIMITED_INQUIRY 0x02 139 #define BTM_BR_INQUIRY_MASK (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY) 140 141 /* high byte of inquiry mode for BLE inquiry mode */ 142 #define BTM_BLE_INQUIRY_NONE 0x00 143 #define BTM_BLE_GENERAL_INQUIRY 0x10 144 #define BTM_BLE_LIMITED_INQUIRY 0x20 145 #define BTM_BLE_INQUIRY_MASK (BTM_BLE_GENERAL_INQUIRY | BTM_BLE_LIMITED_INQUIRY) 146 147 /* BTM_IsInquiryActive return values (Bit Mask) 148 * Note: These bit masks are associated with the inquiry modes (BTM_*_INQUIRY) 149 */ 150 /* no inquiry in progress */ 151 #define BTM_INQUIRY_INACTIVE 0x0 152 /* a general inquiry is in progress */ 153 #define BTM_GENERAL_INQUIRY_ACTIVE BTM_GENERAL_INQUIRY 154 /* a limited inquiry is in progress */ 155 #define BTM_LIMITED_INQUIRY_ACTIVE BTM_LIMITED_INQUIRY 156 /* a periodic inquiry is active */ 157 #define BTM_PERIODIC_INQUIRY_ACTIVE 0x8 158 /* SSP is active, so inquiry is disallowed (work around for FW bug) */ 159 #define BTM_SSP_INQUIRY_ACTIVE 0x4 160 /* a general inquiry is in progress */ 161 #define BTM_LE_GENERAL_INQUIRY_ACTIVE BTM_BLE_GENERAL_INQUIRY 162 /* a limited inquiry is in progress */ 163 #define BTM_LE_LIMITED_INQUIRY_ACTIVE BTM_BLE_LIMITED_INQUIRY 164 165 /* inquiry activity mask */ 166 /* BR/EDR inquiry activity mask */ 167 #define BTM_BR_INQ_ACTIVE_MASK \ 168 (BTM_GENERAL_INQUIRY_ACTIVE | BTM_LIMITED_INQUIRY_ACTIVE | \ 169 BTM_PERIODIC_INQUIRY_ACTIVE) 170 /* LE scan activity mask */ 171 #define BTM_BLE_SCAN_ACTIVE_MASK 0xF0 172 /* LE inquiry activity mask*/ 173 #define BTM_BLE_INQ_ACTIVE_MASK \ 174 (BTM_LE_GENERAL_INQUIRY_ACTIVE | BTM_LE_LIMITED_INQUIRY_ACTIVE) 175 /* inquiry activity mask */ 176 #define BTM_INQUIRY_ACTIVE_MASK \ 177 (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) 178 179 /* Define scan types */ 180 #define BTM_SCAN_TYPE_STANDARD 0 181 #define BTM_SCAN_TYPE_INTERLACED 1 /* 1.2 devices only */ 182 183 /* Define inquiry results mode */ 184 #define BTM_INQ_RESULT_STANDARD 0 185 #define BTM_INQ_RESULT_WITH_RSSI 1 186 #define BTM_INQ_RESULT_EXTENDED 2 187 /* RSSI value not supplied (ignore it) */ 188 #define BTM_INQ_RES_IGNORE_RSSI 0x7f 189 190 /* Inquiry Filter Condition types (see tBTM_INQ_PARMS) */ 191 /* Inquiry Filtering is turned off */ 192 #define BTM_CLR_INQUIRY_FILTER 0 193 /* Filter on device class */ 194 #define BTM_FILTER_COND_DEVICE_CLASS HCI_FILTER_COND_DEVICE_CLASS 195 /* Filter on device addr */ 196 #define BTM_FILTER_COND_BD_ADDR HCI_FILTER_COND_BD_ADDR 197 198 /**************************** 199 * minor device class field 200 ****************************/ 201 202 /* 0x00 is used as unclassified for all minor device classes */ 203 #define BTM_COD_MINOR_UNCLASSIFIED 0x00 204 #define BTM_COD_MINOR_CONFM_HANDSFREE 0x08 205 #define BTM_COD_MINOR_CAR_AUDIO 0x20 206 207 /* minor device class field for Peripheral Major Class */ 208 /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */ 209 #define BTM_COD_MINOR_KEYBOARD 0x40 210 #define BTM_COD_MINOR_POINTING 0x80 211 /* Bits 2-5 OR'd with selection from bits 6-7 */ 212 /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ 213 #define BTM_COD_MINOR_JOYSTICK 0x04 214 #define BTM_COD_MINOR_GAMEPAD 0x08 215 #define BTM_COD_MINOR_REMOTE_CONTROL 0x0C 216 #define BTM_COD_MINOR_DIGITIZING_TABLET 0x14 217 #define BTM_COD_MINOR_CARD_READER 0x18 /* e.g. SIM card reader */ 218 #define BTM_COD_MINOR_DIGITAL_PAN 0x1C 219 220 /* minor device class field for Imaging Major Class */ 221 /* Bits 5-7 independently specify display, camera, scanner, or printer */ 222 #define BTM_COD_MINOR_DISPLAY 0x10 223 /* Bits 2-3 Reserved */ 224 /* #define BTM_COD_MINOR_UNCLASSIFIED 0x00 */ 225 226 /* minor device class field for Wearable Major Class */ 227 /* Bits 2-7 meaningful */ 228 #define BTM_COD_MINOR_WRIST_WATCH 0x04 229 #define BTM_COD_MINOR_GLASSES 0x14 230 231 /* minor device class field for Health Major Class */ 232 /* Bits 2-7 meaningful */ 233 #define BTM_COD_MINOR_BLOOD_MONITOR 0x04 234 #define BTM_COD_MINOR_THERMOMETER 0x08 235 #define BTM_COD_MINOR_WEIGHING_SCALE 0x0C 236 #define BTM_COD_MINOR_GLUCOSE_METER 0x10 237 #define BTM_COD_MINOR_PULSE_OXIMETER 0x14 238 #define BTM_COD_MINOR_HEART_PULSE_MONITOR 0x18 239 #define BTM_COD_MINOR_STEP_COUNTER 0x20 240 241 /*************************** 242 * major device class field 243 ***************************/ 244 #define BTM_COD_MAJOR_COMPUTER 0x01 245 #define BTM_COD_MAJOR_PHONE 0x02 246 #define BTM_COD_MAJOR_AUDIO 0x04 247 #define BTM_COD_MAJOR_PERIPHERAL 0x05 248 #define BTM_COD_MAJOR_IMAGING 0x06 249 #define BTM_COD_MAJOR_WEARABLE 0x07 250 #define BTM_COD_MAJOR_HEALTH 0x09 251 #define BTM_COD_MAJOR_UNCLASSIFIED 0x1F 252 253 /*************************** 254 * service class fields 255 ***************************/ 256 #define BTM_COD_SERVICE_LMTD_DISCOVER 0x0020 257 #define BTM_COD_SERVICE_POSITIONING 0x0100 258 #define BTM_COD_SERVICE_NETWORKING 0x0200 259 #define BTM_COD_SERVICE_RENDERING 0x0400 260 #define BTM_COD_SERVICE_CAPTURING 0x0800 261 #define BTM_COD_SERVICE_OBJ_TRANSFER 0x1000 262 #define BTM_COD_SERVICE_AUDIO 0x2000 263 #define BTM_COD_SERVICE_TELEPHONY 0x4000 264 #define BTM_COD_SERVICE_INFORMATION 0x8000 265 266 /* class of device field macros */ 267 #define BTM_COD_MINOR_CLASS(u8, pd) \ 268 { (u8) = (pd)[2] & 0xFC; } 269 #define BTM_COD_MAJOR_CLASS(u8, pd) \ 270 { (u8) = (pd)[1] & 0x1F; } 271 #define BTM_COD_SERVICE_CLASS(u16, pd) \ 272 { \ 273 (u16) = (pd)[0]; \ 274 (u16) <<= 8; \ 275 (u16) += (pd)[1] & 0xE0; \ 276 } 277 278 /* to set the fields (assumes that format type is always 0) */ 279 #define FIELDS_TO_COD(pd, mn, mj, sv) \ 280 { \ 281 (pd)[2] = mn; \ 282 (pd)[1] = (mj) + ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \ 283 (pd)[0] = (sv) >> 8; \ 284 } 285 286 /* the COD masks */ 287 #define BTM_COD_MINOR_CLASS_MASK 0xFC 288 #define BTM_COD_MAJOR_CLASS_MASK 0x1F 289 #define BTM_COD_SERVICE_CLASS_LO_B 0x00E0 290 #define BTM_COD_SERVICE_CLASS_MASK 0xFFE0 291 292 /* BTM service definitions 293 * Used for storing EIR data to bit mask 294 */ 295 enum { 296 BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER, 297 /* BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR, */ 298 /* BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP, */ 299 BTM_EIR_UUID_SERVCLASS_SERIAL_PORT, 300 BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP, 301 BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING, 302 BTM_EIR_UUID_SERVCLASS_IRMC_SYNC, 303 BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH, 304 BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER, 305 BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND, 306 BTM_EIR_UUID_SERVCLASS_HEADSET, 307 BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY, 308 BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE, 309 BTM_EIR_UUID_SERVCLASS_AUDIO_SINK, 310 BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET, 311 /* BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION, */ 312 BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL, 313 /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING, */ 314 BTM_EIR_UUID_SERVCLASS_INTERCOM, 315 BTM_EIR_UUID_SERVCLASS_FAX, 316 BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, 317 /* BTM_EIR_UUID_SERVCLASS_WAP, */ 318 /* BTM_EIR_UUID_SERVCLASS_WAP_CLIENT, */ 319 BTM_EIR_UUID_SERVCLASS_PANU, 320 BTM_EIR_UUID_SERVCLASS_NAP, 321 BTM_EIR_UUID_SERVCLASS_GN, 322 BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING, 323 /* BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING, */ 324 BTM_EIR_UUID_SERVCLASS_IMAGING, 325 BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER, 326 BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE, 327 BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS, 328 BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE, 329 BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE, 330 BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE, 331 /* BTM_EIR_UUID_SERVCLASS_REFLECTED_UI, */ 332 BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING, 333 BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS, 334 BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE, 335 BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT, 336 BTM_EIR_UUID_SERVCLASS_HCRP_PRINT, 337 BTM_EIR_UUID_SERVCLASS_HCRP_SCAN, 338 /* BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS, */ 339 /* BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW, */ 340 /* BTM_EIR_UUID_SERVCLASS_UDI_MT, */ 341 /* BTM_EIR_UUID_SERVCLASS_UDI_TA, */ 342 /* BTM_EIR_UUID_SERVCLASS_VCP, */ 343 BTM_EIR_UUID_SERVCLASS_SAP, 344 BTM_EIR_UUID_SERVCLASS_PBAP_PCE, 345 BTM_EIR_UUID_SERVCLASS_PBAP_PSE, 346 /* BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS, */ 347 /* BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS, */ 348 BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS, 349 BTM_EIR_UUID_SERVCLASS_HEADSET_HS, 350 BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION, 351 /* BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING, */ 352 /* BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER, */ 353 /* BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO, */ 354 /* BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY, */ 355 /* BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE, */ 356 /* BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE, */ 357 /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN, */ 358 /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP, */ 359 /* BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP, */ 360 BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE, 361 BTM_EIR_UUID_SERVCLASS_VIDEO_SINK, 362 /* BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION */ 363 /* BTM_EIR_UUID_SERVCLASS_HDP_PROFILE */ 364 BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS, 365 BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION, 366 BTM_EIR_UUID_SERVCLASS_HDP_SOURCE, 367 BTM_EIR_UUID_SERVCLASS_HDP_SINK, 368 BTM_EIR_MAX_SERVICES 369 }; 370 371 /* search result in EIR of inquiry database */ 372 #define BTM_EIR_FOUND 0 373 #define BTM_EIR_NOT_FOUND 1 374 #define BTM_EIR_UNKNOWN 2 375 376 typedef uint8_t tBTM_EIR_SEARCH_RESULT; 377 378 /* 0x01 */ 379 #define BTM_EIR_FLAGS_TYPE HCI_EIR_FLAGS_TYPE 380 /* 0x02 */ 381 #define BTM_EIR_MORE_16BITS_UUID_TYPE HCI_EIR_MORE_16BITS_UUID_TYPE 382 /* 0x03 */ 383 #define BTM_EIR_COMPLETE_16BITS_UUID_TYPE HCI_EIR_COMPLETE_16BITS_UUID_TYPE 384 /* 0x04 */ 385 #define BTM_EIR_MORE_32BITS_UUID_TYPE HCI_EIR_MORE_32BITS_UUID_TYPE 386 /* 0x05 */ 387 #define BTM_EIR_COMPLETE_32BITS_UUID_TYPE HCI_EIR_COMPLETE_32BITS_UUID_TYPE 388 /* 0x06 */ 389 #define BTM_EIR_MORE_128BITS_UUID_TYPE HCI_EIR_MORE_128BITS_UUID_TYPE 390 /* 0x07 */ 391 #define BTM_EIR_COMPLETE_128BITS_UUID_TYPE HCI_EIR_COMPLETE_128BITS_UUID_TYPE 392 /* 0x08 */ 393 #define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE HCI_EIR_SHORTENED_LOCAL_NAME_TYPE 394 /* 0x09 */ 395 #define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE HCI_EIR_COMPLETE_LOCAL_NAME_TYPE 396 /* 0x0A */ 397 #define BTM_EIR_TX_POWER_LEVEL_TYPE HCI_EIR_TX_POWER_LEVEL_TYPE 398 /* 0xFF */ 399 #define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE HCI_EIR_MANUFACTURER_SPECIFIC_TYPE 400 401 #define BTM_BLE_SEC_NONE 0 402 /* encrypt the link using current key */ 403 #define BTM_BLE_SEC_ENCRYPT 1 404 #define BTM_BLE_SEC_ENCRYPT_NO_MITM 2 405 #define BTM_BLE_SEC_ENCRYPT_MITM 3 406 typedef uint8_t tBTM_BLE_SEC_ACT; 407 408 /******************************************************************************* 409 * BTM Services MACROS handle array of uint32_t bits for more than 32 services 410 ******************************************************************************/ 411 /* Determine the number of uint32_t's necessary for services */ 412 #define BTM_EIR_ARRAY_BITS 32 /* Number of bits in each array element */ 413 #define BTM_EIR_SERVICE_ARRAY_SIZE \ 414 (((uint32_t)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \ 415 (((uint32_t)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0)) 416 417 /* MACRO to set the service bit mask in a bit stream */ 418 #define BTM_EIR_SET_SERVICE(p, service) \ 419 (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] |= \ 420 ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) 421 422 /* MACRO to clear the service bit mask in a bit stream */ 423 #define BTM_EIR_CLR_SERVICE(p, service) \ 424 (((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] &= \ 425 ~((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) 426 427 /* MACRO to check the service bit mask in a bit stream */ 428 #define BTM_EIR_HAS_SERVICE(p, service) \ 429 ((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_EIR_ARRAY_BITS)] & \ 430 ((uint32_t)1 << (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS))) >> \ 431 (((uint32_t)(service)) % BTM_EIR_ARRAY_BITS)) 432 433 /* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1) 434 */ 435 #define BTM_HCI_EIR_OFFSET (BT_HDR_SIZE + 4) 436 437 /*************************** 438 * Device Discovery Types 439 ***************************/ 440 /* Definitions of the parameters passed to BTM_StartInquiry. 441 */ 442 typedef struct /* contains the two device class condition fields */ 443 { 444 DEV_CLASS dev_class; 445 DEV_CLASS dev_class_mask; 446 } tBTM_COD_COND; 447 448 typedef union /* contains the inquiry filter condition */ 449 { 450 RawAddress bdaddr_cond; 451 tBTM_COD_COND cod_cond; 452 } tBTM_INQ_FILT_COND; 453 454 typedef struct /* contains the parameters passed to the inquiry functions */ 455 { 456 uint8_t mode; /* general or limited */ 457 uint8_t duration; /* duration of the inquiry (1.28 sec increments) */ 458 uint8_t max_resps; /* maximum number of responses to return */ 459 bool report_dup; /* report duplicated inquiry response with higher RSSI value 460 */ 461 uint8_t filter_cond_type; /* new devices, BD ADDR, COD, or No filtering */ 462 tBTM_INQ_FILT_COND filter_cond; /* filter value based on filter cond type */ 463 } tBTM_INQ_PARMS; 464 465 #define BTM_INQ_RESULT_BR 0x01 466 #define BTM_INQ_RESULT_BLE 0x02 467 468 constexpr uint8_t BLE_EVT_CONNECTABLE_BIT = 0; 469 constexpr uint8_t BLE_EVT_SCANNABLE_BIT = 1; 470 constexpr uint8_t BLE_EVT_DIRECTED_BIT = 2; 471 constexpr uint8_t BLE_EVT_SCAN_RESPONSE_BIT = 3; 472 constexpr uint8_t BLE_EVT_LEGACY_BIT = 4; 473 474 constexpr uint8_t PHY_LE_NO_PACKET = 0x00; 475 constexpr uint8_t PHY_LE_1M = 0x01; 476 constexpr uint8_t PHY_LE_2M = 0x02; 477 constexpr uint8_t PHY_LE_CODED = 0x04; 478 479 constexpr uint8_t NO_ADI_PRESENT = 0xFF; 480 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F; 481 482 /* These are the fields returned in each device's response to the inquiry. It 483 * is returned in the results callback if registered. 484 */ 485 typedef struct { 486 uint16_t clock_offset; 487 RawAddress remote_bd_addr; 488 DEV_CLASS dev_class; 489 uint8_t page_scan_rep_mode; 490 uint8_t page_scan_per_mode; 491 uint8_t page_scan_mode; 492 int8_t rssi; /* Set to BTM_INQ_RES_IGNORE_RSSI if not valid */ 493 uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE]; 494 bool eir_complete_list; 495 tBT_DEVICE_TYPE device_type; 496 uint8_t inq_result_type; 497 uint8_t ble_addr_type; 498 uint16_t ble_evt_type; 499 uint8_t ble_primary_phy; 500 uint8_t ble_secondary_phy; 501 uint8_t ble_advertising_sid; 502 int8_t ble_tx_power; 503 uint16_t ble_periodic_adv_int; 504 uint8_t flag; 505 } tBTM_INQ_RESULTS; 506 507 /* This is the inquiry response information held in its database by BTM, and 508 * available to applications via BTM_InqDbRead, BTM_InqDbFirst, and 509 * BTM_InqDbNext. 510 */ 511 typedef struct { 512 tBTM_INQ_RESULTS results; 513 514 bool appl_knows_rem_name; /* set by application if it knows the remote name of 515 the peer device. 516 This is later used by application to determine if 517 remote name request is 518 required to be done. Having the flag here avoid 519 duplicate store of inquiry results */ 520 uint16_t remote_name_len; 521 tBTM_BD_NAME remote_name; 522 uint8_t remote_name_state; 523 uint8_t remote_name_type; 524 525 } tBTM_INQ_INFO; 526 527 /* Structure returned with inquiry complete callback */ 528 typedef struct { 529 tBTM_STATUS status; 530 uint8_t num_resp; /* Number of results from the current inquiry */ 531 } tBTM_INQUIRY_CMPL; 532 533 /* Structure returned with remote name request */ 534 typedef struct { 535 uint16_t status; 536 RawAddress bd_addr; 537 uint16_t length; 538 BD_NAME remote_bd_name; 539 } tBTM_REMOTE_DEV_NAME; 540 541 typedef struct { 542 uint8_t pcm_intf_rate; /* PCM interface rate: 0: 128kbps, 1: 256 kbps; 543 2:512 bps; 3: 1024kbps; 4: 2048kbps */ 544 uint8_t frame_type; /* frame type: 0: short; 1: long */ 545 uint8_t sync_mode; /* sync mode: 0: slave; 1: master */ 546 uint8_t clock_mode; /* clock mode: 0: slave; 1: master */ 547 548 } tBTM_SCO_PCM_PARAM; 549 550 /**************************************** 551 * Device Discovery Callback Functions 552 ****************************************/ 553 /* Callback function for notifications when the BTM gets inquiry response. 554 * First param is inquiry results database, second is pointer of EIR. 555 */ 556 typedef void(tBTM_INQ_RESULTS_CB)(tBTM_INQ_RESULTS* p_inq_results, 557 uint8_t* p_eir, uint16_t eir_len); 558 559 /***************************************************************************** 560 * ACL CHANNEL MANAGEMENT 561 ****************************************************************************/ 562 /****************** 563 * ACL Constants 564 ******************/ 565 566 /* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */ 567 #define BTM_ROLE_MASTER HCI_ROLE_MASTER 568 #define BTM_ROLE_SLAVE HCI_ROLE_SLAVE 569 #define BTM_ROLE_UNDEFINED 0xff /* undefined value (error status) */ 570 571 /* ACL Packet Types */ 572 #define BTM_ACL_PKT_TYPES_MASK_DM1 HCI_PKT_TYPES_MASK_DM1 573 #define BTM_ACL_PKT_TYPES_MASK_DH1 HCI_PKT_TYPES_MASK_DH1 574 #define BTM_ACL_PKT_TYPES_MASK_DM3 HCI_PKT_TYPES_MASK_DM3 575 #define BTM_ACL_PKT_TYPES_MASK_DH3 HCI_PKT_TYPES_MASK_DH3 576 #define BTM_ACL_PKT_TYPES_MASK_DM5 HCI_PKT_TYPES_MASK_DM5 577 #define BTM_ACL_PKT_TYPES_MASK_DH5 HCI_PKT_TYPES_MASK_DH5 578 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1 579 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1 580 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3 581 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 HCI_PKT_TYPES_MASK_NO_3_DH3 582 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 HCI_PKT_TYPES_MASK_NO_2_DH5 583 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH5 HCI_PKT_TYPES_MASK_NO_3_DH5 584 585 /*************** 586 * ACL Types 587 ***************/ 588 589 /* Structure returned with Role Switch information (in tBTM_CMPL_CB callback 590 * function) in response to BTM_SwitchRole call. 591 */ 592 typedef struct { 593 uint8_t hci_status; /* HCI status returned with the event */ 594 uint8_t role; /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */ 595 RawAddress remote_bd_addr; /* Remote BD addr involved with the switch */ 596 } tBTM_ROLE_SWITCH_CMPL; 597 598 /* Structure returned with QoS information (in tBTM_CMPL_CB callback function) 599 * in response to BTM_SetQoS call. 600 */ 601 typedef struct { 602 FLOW_SPEC flow; 603 uint16_t handle; 604 uint8_t status; 605 } tBTM_QOS_SETUP_CMPL; 606 607 /* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function) 608 * in response to BTM_ReadRSSI call. 609 */ 610 typedef struct { 611 tBTM_STATUS status; 612 uint8_t hci_status; 613 int8_t rssi; 614 RawAddress rem_bda; 615 } tBTM_RSSI_RESULT; 616 617 /* Structure returned with read failed contact counter event 618 * (in tBTM_CMPL_CB callback function) in response to 619 * BTM_ReadFailedContactCounter call. 620 */ 621 typedef struct { 622 tBTM_STATUS status; 623 uint8_t hci_status; 624 uint16_t failed_contact_counter; 625 RawAddress rem_bda; 626 } tBTM_FAILED_CONTACT_COUNTER_RESULT; 627 628 /* Structure returned with read automatic flush timeout event 629 * (in tBTM_CMPL_CB callback function) in response to 630 * BTM_ReadAutomaticFlushTimeout call. 631 */ 632 typedef struct { 633 tBTM_STATUS status; 634 uint8_t hci_status; 635 uint16_t automatic_flush_timeout; 636 RawAddress rem_bda; 637 } tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT; 638 639 /* Structure returned with read current TX power event (in tBTM_CMPL_CB callback 640 * function) in response to BTM_ReadTxPower call. 641 */ 642 typedef struct { 643 tBTM_STATUS status; 644 uint8_t hci_status; 645 int8_t tx_power; 646 RawAddress rem_bda; 647 } tBTM_TX_POWER_RESULT; 648 649 /* Structure returned with read link quality event (in tBTM_CMPL_CB callback 650 * function) in response to BTM_ReadLinkQuality call. 651 */ 652 typedef struct { 653 tBTM_STATUS status; 654 uint8_t hci_status; 655 uint8_t link_quality; 656 RawAddress rem_bda; 657 } tBTM_LINK_QUALITY_RESULT; 658 659 /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB 660 * callback function) in response to BTM_ReadInquiryRspTxPower call. 661 */ 662 typedef struct { 663 tBTM_STATUS status; 664 uint8_t hci_status; 665 int8_t tx_power; 666 } tBTM_INQ_TXPWR_RESULT; 667 668 enum { 669 BTM_BL_CONN_EVT, 670 BTM_BL_DISCN_EVT, 671 BTM_BL_UPDATE_EVT, 672 BTM_BL_ROLE_CHG_EVT, 673 BTM_BL_COLLISION_EVT 674 }; 675 typedef uint8_t tBTM_BL_EVENT; 676 typedef uint16_t tBTM_BL_EVENT_MASK; 677 678 #define BTM_BL_UPDATE_MASK 0x0004 679 #define BTM_BL_ROLE_CHG_MASK 0x0008 680 681 /* Device features mask definitions */ 682 #define BTM_FEATURE_BYTES_PER_PAGE HCI_FEATURE_BYTES_PER_PAGE 683 #define BTM_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_MAX 684 685 /* the data type associated with BTM_BL_CONN_EVT */ 686 typedef struct { 687 tBTM_BL_EVENT event; /* The event reported. */ 688 const RawAddress* p_bda; /* The address of the newly connected device */ 689 DEV_CLASS_PTR p_dc; /* The device class */ 690 BD_NAME_PTR p_bdn; /* The device name */ 691 uint8_t* p_features; /* pointer to the remote device's features page[0] 692 (supported features page) */ 693 uint16_t handle; /* connection handle */ 694 tBT_TRANSPORT transport; /* link is LE or not */ 695 } tBTM_BL_CONN_DATA; 696 697 /* the data type associated with BTM_BL_DISCN_EVT */ 698 typedef struct { 699 tBTM_BL_EVENT event; /* The event reported. */ 700 const RawAddress* p_bda; /* The address of the disconnected device */ 701 uint16_t handle; /* disconnected connection handle */ 702 tBT_TRANSPORT transport; /* link is LE link or not */ 703 } tBTM_BL_DISCN_DATA; 704 705 /* Busy-Level shall have the inquiry_paging mask set when 706 * inquiry/paging is in progress, Else the number of ACL links */ 707 #define BTM_BL_INQUIRY_PAGING_MASK 0x10 708 #define BTM_BL_INQUIRY_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x1) 709 #define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2) 710 #define BTM_BL_INQUIRY_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x3) 711 #define BTM_BL_PAGING_STARTED (BTM_BL_INQUIRY_PAGING_MASK | 0x4) 712 #define BTM_BL_PAGING_COMPLETE (BTM_BL_INQUIRY_PAGING_MASK | 0x5) 713 /* the data type associated with BTM_BL_UPDATE_EVT */ 714 typedef struct { 715 tBTM_BL_EVENT event; /* The event reported. */ 716 uint8_t busy_level; /* when paging or inquiring, level is 10. 717 * Otherwise, the number of ACL links. */ 718 uint8_t busy_level_flags; /* Notifies actual inquiry/page activities */ 719 } tBTM_BL_UPDATE_DATA; 720 721 /* the data type associated with BTM_BL_ROLE_CHG_EVT */ 722 typedef struct { 723 tBTM_BL_EVENT event; /* The event reported. */ 724 const RawAddress* p_bda; /* The address of the peer connected device */ 725 uint8_t new_role; 726 uint8_t hci_status; /* HCI status returned with the event */ 727 } tBTM_BL_ROLE_CHG_DATA; 728 729 typedef union { 730 tBTM_BL_EVENT event; /* The event reported. */ 731 tBTM_BL_CONN_DATA conn; /* The data associated with BTM_BL_CONN_EVT */ 732 tBTM_BL_DISCN_DATA discn; /* The data associated with BTM_BL_DISCN_EVT */ 733 tBTM_BL_UPDATE_DATA update; /* The data associated with BTM_BL_UPDATE_EVT */ 734 tBTM_BL_ROLE_CHG_DATA 735 role_chg; /*The data associated with BTM_BL_ROLE_CHG_EVT */ 736 } tBTM_BL_EVENT_DATA; 737 738 /* Callback function for notifications when the BTM busy level 739 * changes. 740 */ 741 typedef void(tBTM_BL_CHANGE_CB)(tBTM_BL_EVENT_DATA* p_data); 742 743 /***************************************************************************** 744 * SCO CHANNEL MANAGEMENT 745 ****************************************************************************/ 746 /****************** 747 * SCO Constants 748 ******************/ 749 750 /* Define an invalid SCO index and an invalid HCI handle */ 751 #define BTM_INVALID_SCO_INDEX 0xFFFF 752 #define BTM_INVALID_HCI_HANDLE 0xFFFF 753 754 /* Define an invalid SCO disconnect reason */ 755 #define BTM_INVALID_SCO_DISC_REASON 0xFFFF 756 757 #define BTM_SCO_LINK_ONLY_MASK \ 758 (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3) 759 760 #define BTM_ESCO_LINK_ONLY_MASK \ 761 (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5) 762 763 /*************** 764 * SCO Types 765 ***************/ 766 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO 767 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO 768 typedef uint8_t tBTM_SCO_TYPE; 769 770 /******************* 771 * SCO Codec Types 772 *******************/ 773 // TODO(google) This should use common definitions 774 #define BTM_SCO_CODEC_NONE 0x0000 775 #define BTM_SCO_CODEC_CVSD 0x0001 776 #define BTM_SCO_CODEC_MSBC 0x0002 777 typedef uint16_t tBTM_SCO_CODEC_TYPE; 778 779 /******************* 780 * SCO Voice Settings 781 *******************/ 782 #define BTM_VOICE_SETTING_CVSD \ 783 ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \ 784 HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD)) 785 786 #define BTM_VOICE_SETTING_TRANS \ 787 ((uint16_t)(HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | \ 788 HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_TRANSPNT)) 789 790 /******************* 791 * SCO Data Status 792 *******************/ 793 typedef uint8_t tBTM_SCO_DATA_FLAG; 794 795 /*************************** 796 * SCO Callback Functions 797 ***************************/ 798 typedef void(tBTM_SCO_CB)(uint16_t sco_inx); 799 800 /*************** 801 * eSCO Types 802 ***************/ 803 /* tBTM_ESCO_CBACK event types */ 804 #define BTM_ESCO_CHG_EVT 1 805 #define BTM_ESCO_CONN_REQ_EVT 2 806 typedef uint8_t tBTM_ESCO_EVT; 807 808 /* Structure passed with SCO change command and events. 809 * Used by both Sync and Enhanced sync messaging 810 */ 811 typedef struct { 812 uint16_t max_latency_ms; 813 uint16_t packet_types; 814 uint8_t retransmission_effort; 815 } tBTM_CHG_ESCO_PARAMS; 816 817 /* Returned by BTM_ReadEScoLinkParms() */ 818 typedef struct { 819 uint16_t rx_pkt_len; 820 uint16_t tx_pkt_len; 821 RawAddress bd_addr; 822 uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */ 823 uint8_t tx_interval; 824 uint8_t retrans_window; 825 uint8_t air_mode; 826 } tBTM_ESCO_DATA; 827 828 typedef struct { 829 uint16_t sco_inx; 830 uint16_t rx_pkt_len; 831 uint16_t tx_pkt_len; 832 RawAddress bd_addr; 833 uint8_t hci_status; 834 uint8_t tx_interval; 835 uint8_t retrans_window; 836 } tBTM_CHG_ESCO_EVT_DATA; 837 838 typedef struct { 839 uint16_t sco_inx; 840 RawAddress bd_addr; 841 DEV_CLASS dev_class; 842 tBTM_SCO_TYPE link_type; 843 } tBTM_ESCO_CONN_REQ_EVT_DATA; 844 845 typedef union { 846 tBTM_CHG_ESCO_EVT_DATA chg_evt; 847 tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt; 848 } tBTM_ESCO_EVT_DATA; 849 850 /*************************** 851 * eSCO Callback Functions 852 ***************************/ 853 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data); 854 855 /***************************************************************************** 856 * SECURITY MANAGEMENT 857 ****************************************************************************/ 858 /******************************* 859 * Security Manager Constants 860 *******************************/ 861 862 /* Security Mode (BTM_SetSecurityMode) */ 863 #define BTM_SEC_MODE_UNDEFINED 0 864 #define BTM_SEC_MODE_NONE 1 865 #define BTM_SEC_MODE_SERVICE 2 866 #define BTM_SEC_MODE_LINK 3 867 #define BTM_SEC_MODE_SP 4 868 #define BTM_SEC_MODE_SP_DEBUG 5 869 #define BTM_SEC_MODE_SC 6 870 871 /* Security Service Levels [bit mask] (BTM_SetSecurityLevel) 872 * Encryption should not be used without authentication 873 */ 874 /* Nothing required */ 875 #define BTM_SEC_NONE 0x0000 876 /* Inbound call requires authorization */ 877 #define BTM_SEC_IN_AUTHORIZE 0x0001 878 /* Inbound call requires authentication */ 879 #define BTM_SEC_IN_AUTHENTICATE 0x0002 880 /* Inbound call requires encryption */ 881 #define BTM_SEC_IN_ENCRYPT 0x0004 882 /* Outbound call requires authorization */ 883 #define BTM_SEC_OUT_AUTHORIZE 0x0008 884 /* Outbound call requires authentication */ 885 #define BTM_SEC_OUT_AUTHENTICATE 0x0010 886 /* Outbound call requires encryption */ 887 #define BTM_SEC_OUT_ENCRYPT 0x0020 888 /* Secure Connections Only Mode */ 889 #define BTM_SEC_MODE4_LEVEL4 0x0040 890 /* Need to switch connection to be master */ 891 #define BTM_SEC_FORCE_MASTER 0x0100 892 /* Try to switch connection to be master */ 893 #define BTM_SEC_ATTEMPT_MASTER 0x0200 894 /* Need to switch connection to be master */ 895 #define BTM_SEC_FORCE_SLAVE 0x0400 896 /* Try to switch connection to be slave */ 897 #define BTM_SEC_ATTEMPT_SLAVE 0x0800 898 /* inbound Do man in the middle protection */ 899 #define BTM_SEC_IN_MITM 0x1000 900 /* outbound Do man in the middle protection */ 901 #define BTM_SEC_OUT_MITM 0x2000 902 /* enforce a minimum of 16 digit for sec mode 2 */ 903 #define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000 904 905 /* Security Flags [bit mask] (BTM_GetSecurityFlags) 906 */ 907 #define BTM_SEC_FLAG_AUTHORIZED 0x01 908 #define BTM_SEC_FLAG_AUTHENTICATED 0x02 909 #define BTM_SEC_FLAG_ENCRYPTED 0x04 910 #define BTM_SEC_FLAG_LKEY_KNOWN 0x10 911 #define BTM_SEC_FLAG_LKEY_AUTHED 0x20 912 913 /* Link Key types used to generate the new link key. 914 * returned in link key notification callback function 915 */ 916 #define BTM_LKEY_TYPE_COMBINATION HCI_LKEY_TYPE_COMBINATION 917 #define BTM_LKEY_TYPE_REMOTE_UNIT HCI_LKEY_TYPE_REMOTE_UNIT 918 #define BTM_LKEY_TYPE_UNAUTH_COMB HCI_LKEY_TYPE_UNAUTH_COMB 919 #define BTM_LKEY_TYPE_AUTH_COMB HCI_LKEY_TYPE_AUTH_COMB 920 #define BTM_LKEY_TYPE_CHANGED_COMB HCI_LKEY_TYPE_CHANGED_COMB 921 922 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256 923 #define BTM_LKEY_TYPE_AUTH_COMB_P_256 HCI_LKEY_TYPE_AUTH_COMB_P_256 924 925 /* "easy" requirements for LK derived from LTK */ 926 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20 927 #define BTM_LKEY_TYPE_IGNORE \ 928 0xff /* used when event is response from \ 929 hci return link keys request */ 930 931 typedef uint8_t tBTM_LINK_KEY_TYPE; 932 933 /* Protocol level security (BTM_SetSecurityLevel) */ 934 #define BTM_SEC_PROTO_RFCOMM 3 935 #define BTM_SEC_PROTO_BNEP 5 936 #define BTM_SEC_PROTO_HID 6 /* HID */ 937 #define BTM_SEC_PROTO_AVDT 7 938 939 /* Determine the number of uint32_t's necessary for security services */ 940 #define BTM_SEC_ARRAY_BITS 32 /* Number of bits in each array element */ 941 #define BTM_SEC_SERVICE_ARRAY_SIZE \ 942 (((uint32_t)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \ 943 (((uint32_t)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0)) 944 945 /* Security service definitions (BTM_SetSecurityLevel) 946 * Used for Authorization APIs 947 */ 948 #define BTM_SEC_SERVICE_SDP_SERVER 0 949 #define BTM_SEC_SERVICE_SERIAL_PORT 1 950 #define BTM_SEC_SERVICE_LAN_ACCESS 2 951 #define BTM_SEC_SERVICE_DUN 3 952 #define BTM_SEC_SERVICE_IRMC_SYNC 4 953 #define BTM_SEC_SERVICE_OBEX 6 954 #define BTM_SEC_SERVICE_OBEX_FTP 7 955 #define BTM_SEC_SERVICE_HEADSET 8 956 #define BTM_SEC_SERVICE_CORDLESS 9 957 #define BTM_SEC_SERVICE_INTERCOM 10 958 #define BTM_SEC_SERVICE_HEADSET_AG 12 959 #define BTM_SEC_SERVICE_BPP_JOB 22 960 #define BTM_SEC_SERVICE_BNEP_PANU 25 961 #define BTM_SEC_SERVICE_BNEP_GN 26 962 #define BTM_SEC_SERVICE_BNEP_NAP 27 963 #define BTM_SEC_SERVICE_HF_HANDSFREE 28 964 #define BTM_SEC_SERVICE_AG_HANDSFREE 29 965 966 #define BTM_SEC_SERVICE_HIDH_SEC_CTRL 32 967 #define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33 968 #define BTM_SEC_SERVICE_HIDH_INTR 34 969 #define BTM_SEC_SERVICE_BIP 35 970 #define BTM_SEC_SERVICE_AVDTP 37 971 #define BTM_SEC_SERVICE_AVDTP_NOSEC 38 972 #define BTM_SEC_SERVICE_AVCTP 39 973 #define BTM_SEC_SERVICE_SAP 40 974 #define BTM_SEC_SERVICE_PBAP 41 975 #define BTM_SEC_SERVICE_RFC_MUX 42 976 #define BTM_SEC_SERVICE_AVCTP_BROWSE 43 977 #define BTM_SEC_SERVICE_MAP 44 978 #define BTM_SEC_SERVICE_HDP_SNK 48 979 #define BTM_SEC_SERVICE_ATT 50 980 #define BTM_SEC_SERVICE_HIDD_SEC_CTRL 51 981 #define BTM_SEC_SERVICE_HIDD_NOSEC_CTRL 52 982 #define BTM_SEC_SERVICE_HIDD_INTR 53 983 #define BTM_SEC_SERVICE_HEARING_AID_LEFT 54 984 #define BTM_SEC_SERVICE_HEARING_AID_RIGHT 55 985 986 /* Update these as services are added */ 987 #define BTM_SEC_SERVICE_FIRST_EMPTY 56 988 989 #ifndef BTM_SEC_MAX_SERVICES 990 #define BTM_SEC_MAX_SERVICES 75 991 #endif 992 993 /******************************************************************************* 994 * Security Services MACROS handle array of uint32_t bits for more than 32 995 * trusted services 996 ******************************************************************************/ 997 998 /* MACRO to check the security service bit mask in a bit stream (Returns true or 999 * false) */ 1000 #define BTM_SEC_IS_SERVICE_TRUSTED(p, service) \ 1001 (((((uint32_t*)(p))[(((uint32_t)(service)) / BTM_SEC_ARRAY_BITS)]) & \ 1002 (uint32_t)(((uint32_t)1 << (((uint32_t)(service)) % BTM_SEC_ARRAY_BITS)))) \ 1003 ? true \ 1004 : false) 1005 1006 /* MACRO to copy two trusted device bitmask */ 1007 #define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst) \ 1008 { \ 1009 uint32_t trst; \ 1010 for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ 1011 ((uint32_t*)(p_dst))[trst] = ((uint32_t*)(p_src))[trst]; \ 1012 } 1013 1014 /* MACRO to clear two trusted device bitmask */ 1015 #define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst) \ 1016 { \ 1017 uint32_t trst; \ 1018 for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \ 1019 ((uint32_t*)(p_dst))[trst] = 0; \ 1020 } 1021 1022 #define BTM_SEC_TRUST_ALL 0xFFFFFFFF /* for each array element */ 1023 1024 /**************************************** 1025 * Security Manager Callback Functions 1026 ****************************************/ 1027 /* Authorize device for service. Parameters are 1028 * BD Address of remote 1029 * Device Class of remote 1030 * BD Name of remote 1031 * Service name 1032 * Service Id (NULL - unknown service or unused 1033 * [BTM_SEC_SERVICE_NAME_LEN set to 0]) 1034 * Is originator of the connection 1035 * Result of the operation 1036 */ 1037 typedef uint8_t(tBTM_AUTHORIZE_CALLBACK)( 1038 const RawAddress& bd_addr, DEV_CLASS dev_class, tBTM_BD_NAME bd_name, 1039 uint8_t* service_name, uint8_t service_id, bool is_originator); 1040 1041 /* Get PIN for the connection. Parameters are 1042 * BD Address of remote 1043 * Device Class of remote 1044 * BD Name of remote 1045 * Flag indicating the minimum pin code length to be 16 digits 1046 */ 1047 typedef uint8_t(tBTM_PIN_CALLBACK)(const RawAddress& bd_addr, 1048 DEV_CLASS dev_class, tBTM_BD_NAME bd_name, 1049 bool min_16_digit); 1050 1051 /* New Link Key for the connection. Parameters are 1052 * BD Address of remote 1053 * Link Key 1054 * Key Type: Combination, Local Unit, or Remote Unit 1055 */ 1056 typedef uint8_t(tBTM_LINK_KEY_CALLBACK)(const RawAddress& bd_addr, 1057 DEV_CLASS dev_class, 1058 tBTM_BD_NAME bd_name, 1059 const LinkKey& key, uint8_t key_type); 1060 1061 /* Remote Name Resolved. Parameters are 1062 * BD Address of remote 1063 * BD Name of remote 1064 */ 1065 typedef void(tBTM_RMT_NAME_CALLBACK)(const RawAddress& bd_addr, DEV_CLASS dc, 1066 tBTM_BD_NAME bd_name); 1067 1068 /* Authentication complete for the connection. Parameters are 1069 * BD Address of remote 1070 * Device Class of remote 1071 * BD Name of remote 1072 * 1073 */ 1074 typedef uint8_t(tBTM_AUTH_COMPLETE_CALLBACK)(const RawAddress& bd_addr, 1075 DEV_CLASS dev_class, 1076 tBTM_BD_NAME bd_name, int result); 1077 1078 enum { 1079 BTM_SP_IO_REQ_EVT, /* received IO_CAPABILITY_REQUEST event */ 1080 BTM_SP_IO_RSP_EVT, /* received IO_CAPABILITY_RESPONSE event */ 1081 BTM_SP_CFM_REQ_EVT, /* received USER_CONFIRMATION_REQUEST event */ 1082 BTM_SP_KEY_NOTIF_EVT, /* received USER_PASSKEY_NOTIFY event */ 1083 BTM_SP_KEY_REQ_EVT, /* received USER_PASSKEY_REQUEST event */ 1084 BTM_SP_KEYPRESS_EVT, /* received KEYPRESS_NOTIFY event */ 1085 BTM_SP_LOC_OOB_EVT, /* received result for READ_LOCAL_OOB_DATA command */ 1086 BTM_SP_RMT_OOB_EVT, /* received REMOTE_OOB_DATA_REQUEST event */ 1087 BTM_SP_COMPLT_EVT, /* received SIMPLE_PAIRING_COMPLETE event */ 1088 BTM_SP_UPGRADE_EVT /* check if the application wants to upgrade the link key 1089 */ 1090 }; 1091 typedef uint8_t tBTM_SP_EVT; 1092 1093 #define BTM_IO_CAP_OUT 0 /* DisplayOnly */ 1094 #define BTM_IO_CAP_IO 1 /* DisplayYesNo */ 1095 #define BTM_IO_CAP_IN 2 /* KeyboardOnly */ 1096 #define BTM_IO_CAP_NONE 3 /* NoInputNoOutput */ 1097 #define BTM_IO_CAP_KBDISP 4 /* Keyboard display */ 1098 #define BTM_IO_CAP_MAX 5 1099 #define BTM_IO_CAP_UNKNOWN 0xFF /* Unknown value */ 1100 1101 typedef uint8_t tBTM_IO_CAP; 1102 1103 #define BTM_MAX_PASSKEY_VAL (999999) 1104 1105 /* MITM Protection Not Required - Single Profile/non-bonding Numeric comparison 1106 * with automatic accept allowed */ 1107 #define BTM_AUTH_SP_NO 0 1108 /* MITM Protection Required - Single Profile/non-bonding. Use IO Capabilities to 1109 * determine authentication procedure */ 1110 #define BTM_AUTH_SP_YES 1 1111 /* MITM Protection Not Required - All Profiles/dedicated bonding Numeric 1112 * comparison with automatic accept allowed */ 1113 #define BTM_AUTH_AP_NO 2 1114 /* MITM Protection Required - All Profiles/dedicated bonding Use IO Capabilities 1115 * to determine authentication procedure */ 1116 #define BTM_AUTH_AP_YES 3 1117 /* MITM Protection Not Required - Single Profiles/general bonding Numeric 1118 * comparison with automatic accept allowed */ 1119 #define BTM_AUTH_SPGB_NO 4 1120 /* MITM Protection Required - Single Profiles/general bonding Use IO 1121 * Capabilities to determine authentication procedure */ 1122 #define BTM_AUTH_SPGB_YES 5 1123 1124 /* this bit is ORed with BTM_AUTH_SP_* when IO exchange for dedicated bonding */ 1125 #define BTM_AUTH_DD_BOND 2 1126 #define BTM_AUTH_BONDS 6 /* the general/dedicated bonding bits */ 1127 #define BTM_AUTH_YN_BIT 1 /* this is the Yes or No bit */ 1128 1129 #define BTM_BLE_INITIATOR_KEY_SIZE 15 1130 #define BTM_BLE_RESPONDER_KEY_SIZE 15 1131 #define BTM_BLE_MAX_KEY_SIZE 16 1132 1133 typedef uint8_t tBTM_AUTH_REQ; 1134 1135 enum { BTM_OOB_NONE, BTM_OOB_PRESENT, BTM_OOB_UNKNOWN }; 1136 typedef uint8_t tBTM_OOB_DATA; 1137 1138 /* data type for BTM_SP_IO_REQ_EVT */ 1139 typedef struct { 1140 RawAddress bd_addr; /* peer address */ 1141 tBTM_IO_CAP io_cap; /* local IO capabilities */ 1142 tBTM_OOB_DATA oob_data; /* OOB data present (locally) for the peer device */ 1143 tBTM_AUTH_REQ auth_req; /* Authentication required (for local device) */ 1144 bool is_orig; /* true, if local device initiated the SP process */ 1145 } tBTM_SP_IO_REQ; 1146 1147 /* data type for BTM_SP_IO_RSP_EVT */ 1148 typedef struct { 1149 RawAddress bd_addr; /* peer address */ 1150 tBTM_IO_CAP io_cap; /* peer IO capabilities */ 1151 tBTM_OOB_DATA 1152 oob_data; /* OOB data present at peer device for the local device */ 1153 tBTM_AUTH_REQ auth_req; /* Authentication required for peer device */ 1154 } tBTM_SP_IO_RSP; 1155 1156 /* data type for BTM_SP_CFM_REQ_EVT */ 1157 typedef struct { 1158 RawAddress bd_addr; /* peer address */ 1159 DEV_CLASS dev_class; /* peer CoD */ 1160 tBTM_BD_NAME bd_name; /* peer device name */ 1161 uint32_t num_val; /* the numeric value for comparison. If just_works, do not 1162 show this number to UI */ 1163 bool just_works; /* true, if "Just Works" association model */ 1164 tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */ 1165 tBTM_AUTH_REQ rmt_auth_req; /* Authentication required for peer device */ 1166 tBTM_IO_CAP loc_io_caps; /* IO Capabilities of the local device */ 1167 tBTM_IO_CAP rmt_io_caps; /* IO Capabilities of the remot device */ 1168 } tBTM_SP_CFM_REQ; 1169 1170 /* data type for BTM_SP_KEY_REQ_EVT */ 1171 typedef struct { 1172 RawAddress bd_addr; /* peer address */ 1173 DEV_CLASS dev_class; /* peer CoD */ 1174 tBTM_BD_NAME bd_name; /* peer device name */ 1175 } tBTM_SP_KEY_REQ; 1176 1177 /* data type for BTM_SP_KEY_NOTIF_EVT */ 1178 typedef struct { 1179 RawAddress bd_addr; /* peer address */ 1180 DEV_CLASS dev_class; /* peer CoD */ 1181 tBTM_BD_NAME bd_name; /* peer device name */ 1182 uint32_t passkey; /* passkey */ 1183 } tBTM_SP_KEY_NOTIF; 1184 1185 enum { 1186 BTM_SP_KEY_STARTED, /* 0 - passkey entry started */ 1187 BTM_SP_KEY_ENTERED, /* 1 - passkey digit entered */ 1188 BTM_SP_KEY_ERASED, /* 2 - passkey digit erased */ 1189 BTM_SP_KEY_CLEARED, /* 3 - passkey cleared */ 1190 BTM_SP_KEY_COMPLT, /* 4 - passkey entry completed */ 1191 BTM_SP_KEY_OUT_OF_RANGE /* 5 - out of range */ 1192 }; 1193 typedef uint8_t tBTM_SP_KEY_TYPE; 1194 1195 /* data type for BTM_SP_KEYPRESS_EVT */ 1196 typedef struct { 1197 RawAddress bd_addr; /* peer address */ 1198 tBTM_SP_KEY_TYPE notif_type; 1199 } tBTM_SP_KEYPRESS; 1200 1201 /* data type for BTM_SP_LOC_OOB_EVT */ 1202 typedef struct { 1203 tBTM_STATUS status; /* */ 1204 Octet16 c; /* Simple Pairing Hash C */ 1205 Octet16 r; /* Simple Pairing Randomnizer R */ 1206 } tBTM_SP_LOC_OOB; 1207 1208 /* data type for BTM_SP_RMT_OOB_EVT */ 1209 typedef struct { 1210 RawAddress bd_addr; /* peer address */ 1211 DEV_CLASS dev_class; /* peer CoD */ 1212 tBTM_BD_NAME bd_name; /* peer device name */ 1213 } tBTM_SP_RMT_OOB; 1214 1215 /* data type for BTM_SP_COMPLT_EVT */ 1216 typedef struct { 1217 RawAddress bd_addr; /* peer address */ 1218 DEV_CLASS dev_class; /* peer CoD */ 1219 tBTM_BD_NAME bd_name; /* peer device name */ 1220 tBTM_STATUS status; /* status of the simple pairing process */ 1221 } tBTM_SP_COMPLT; 1222 1223 /* data type for BTM_SP_UPGRADE_EVT */ 1224 typedef struct { 1225 RawAddress bd_addr; /* peer address */ 1226 bool upgrade; /* true, to upgrade the link key */ 1227 } tBTM_SP_UPGRADE; 1228 1229 typedef union { 1230 tBTM_SP_IO_REQ io_req; /* BTM_SP_IO_REQ_EVT */ 1231 tBTM_SP_IO_RSP io_rsp; /* BTM_SP_IO_RSP_EVT */ 1232 tBTM_SP_CFM_REQ cfm_req; /* BTM_SP_CFM_REQ_EVT */ 1233 tBTM_SP_KEY_NOTIF key_notif; /* BTM_SP_KEY_NOTIF_EVT */ 1234 tBTM_SP_KEY_REQ key_req; /* BTM_SP_KEY_REQ_EVT */ 1235 tBTM_SP_KEYPRESS key_press; /* BTM_SP_KEYPRESS_EVT */ 1236 tBTM_SP_LOC_OOB loc_oob; /* BTM_SP_LOC_OOB_EVT */ 1237 tBTM_SP_RMT_OOB rmt_oob; /* BTM_SP_RMT_OOB_EVT */ 1238 tBTM_SP_COMPLT complt; /* BTM_SP_COMPLT_EVT */ 1239 tBTM_SP_UPGRADE upgrade; /* BTM_SP_UPGRADE_EVT */ 1240 } tBTM_SP_EVT_DATA; 1241 1242 /* Simple Pairing Events. Called by the stack when Simple Pairing related 1243 * events occur. 1244 */ 1245 typedef uint8_t(tBTM_SP_CALLBACK)(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); 1246 1247 typedef void(tBTM_MKEY_CALLBACK)(const RawAddress& bd_addr, uint8_t status, 1248 uint8_t key_flag); 1249 1250 /* Encryption enabled/disabled complete: Optionally passed with 1251 * BTM_SetEncryption. 1252 * Parameters are 1253 * BD Address of remote 1254 * optional data passed in by BTM_SetEncryption 1255 * tBTM_STATUS - result of the operation 1256 */ 1257 typedef void(tBTM_SEC_CBACK)(const RawAddress* bd_addr, tBT_TRANSPORT trasnport, 1258 void* p_ref_data, tBTM_STATUS result); 1259 1260 /* Bond Cancel complete. Parameters are 1261 * Result of the cancel operation 1262 * 1263 */ 1264 typedef void(tBTM_BOND_CANCEL_CMPL_CALLBACK)(tBTM_STATUS result); 1265 1266 /* LE related event and data structure */ 1267 /* received IO_CAPABILITY_REQUEST event */ 1268 #define BTM_LE_IO_REQ_EVT SMP_IO_CAP_REQ_EVT 1269 /* security request event */ 1270 #define BTM_LE_SEC_REQUEST_EVT SMP_SEC_REQUEST_EVT 1271 /* received USER_PASSKEY_NOTIFY event */ 1272 #define BTM_LE_KEY_NOTIF_EVT SMP_PASSKEY_NOTIF_EVT 1273 /* received USER_PASSKEY_REQUEST event */ 1274 #define BTM_LE_KEY_REQ_EVT SMP_PASSKEY_REQ_EVT 1275 /* OOB data request event */ 1276 #define BTM_LE_OOB_REQ_EVT SMP_OOB_REQ_EVT 1277 /* Numeric Comparison request event */ 1278 #define BTM_LE_NC_REQ_EVT SMP_NC_REQ_EVT 1279 /* Peer keypress notification recd event */ 1280 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT 1281 /* SC OOB request event (both local and peer OOB data) can be expected in 1282 * response */ 1283 #define BTM_LE_SC_OOB_REQ_EVT SMP_SC_OOB_REQ_EVT 1284 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */ 1285 #define BTM_LE_SC_LOC_OOB_EVT SMP_SC_LOC_OOB_DATA_UP_EVT 1286 /* SMP over BR keys request event */ 1287 #define BTM_LE_BR_KEYS_REQ_EVT SMP_BR_KEYS_REQ_EVT 1288 /* SMP complete event */ 1289 #define BTM_LE_COMPLT_EVT SMP_COMPLT_EVT 1290 #define BTM_LE_LAST_FROM_SMP BTM_LE_BR_KEYS_REQ_EVT 1291 /* KEY update event */ 1292 #define BTM_LE_KEY_EVT (BTM_LE_LAST_FROM_SMP + 1) 1293 typedef uint8_t tBTM_LE_EVT; 1294 1295 #define BTM_LE_KEY_NONE 0 1296 /* encryption information of peer device */ 1297 #define BTM_LE_KEY_PENC SMP_SEC_KEY_TYPE_ENC 1298 /* identity key of the peer device */ 1299 #define BTM_LE_KEY_PID SMP_SEC_KEY_TYPE_ID 1300 /* peer SRK */ 1301 #define BTM_LE_KEY_PCSRK SMP_SEC_KEY_TYPE_CSRK 1302 #define BTM_LE_KEY_PLK SMP_SEC_KEY_TYPE_LK 1303 #define BTM_LE_KEY_LLK (SMP_SEC_KEY_TYPE_LK << 4) 1304 /* master role security information:div */ 1305 #define BTM_LE_KEY_LENC (SMP_SEC_KEY_TYPE_ENC << 4) 1306 /* master device ID key */ 1307 #define BTM_LE_KEY_LID (SMP_SEC_KEY_TYPE_ID << 4) 1308 /* local CSRK has been deliver to peer */ 1309 #define BTM_LE_KEY_LCSRK (SMP_SEC_KEY_TYPE_CSRK << 4) 1310 typedef uint8_t tBTM_LE_KEY_TYPE; 1311 1312 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND /* 0 */ 1313 #define BTM_LE_AUTH_REQ_BOND SMP_AUTH_BOND /* 1 << 0 */ 1314 #define BTM_LE_AUTH_REQ_MITM SMP_AUTH_YN_BIT /* 1 << 2 */ 1315 typedef uint8_t tBTM_LE_AUTH_REQ; 1316 #define BTM_LE_SC_SUPPORT_BIT SMP_SC_SUPPORT_BIT /* (1 << 3) */ 1317 #define BTM_LE_KP_SUPPORT_BIT SMP_KP_SUPPORT_BIT /* (1 << 4) */ 1318 #define BTM_LE_H7_SUPPORT_BIT SMP_H7_SUPPORT_BIT /* (1 << 5) */ 1319 1320 #define BTM_LE_AUTH_REQ_SC_ONLY SMP_AUTH_SC_ENC_ONLY /* 00101000 */ 1321 #define BTM_LE_AUTH_REQ_SC_BOND SMP_AUTH_SC_GB /* 00101001 */ 1322 #define BTM_LE_AUTH_REQ_SC_MITM SMP_AUTH_SC_MITM_NB /* 00101100 */ 1323 #define BTM_LE_AUTH_REQ_SC_MITM_BOND SMP_AUTH_SC_MITM_GB /* 00101101 */ 1324 #define BTM_LE_AUTH_REQ_MASK SMP_AUTH_MASK /* 0x3D */ 1325 1326 /* LE security level */ 1327 #define BTM_LE_SEC_NONE SMP_SEC_NONE 1328 #define BTM_LE_SEC_UNAUTHENTICATE SMP_SEC_UNAUTHENTICATE /* 1 */ 1329 #define BTM_LE_SEC_AUTHENTICATED SMP_SEC_AUTHENTICATED /* 4 */ 1330 typedef uint8_t tBTM_LE_SEC; 1331 1332 typedef struct { 1333 /* local IO capabilities */ 1334 tBTM_IO_CAP io_cap; 1335 /* OOB data present (locally) for the peer device */ 1336 uint8_t oob_data; 1337 /* Authentication request (for local device) containing bonding and MITM 1338 * info */ 1339 tBTM_LE_AUTH_REQ auth_req; 1340 uint8_t max_key_size; /* max encryption key size */ 1341 tBTM_LE_KEY_TYPE init_keys; /* keys to be distributed, bit mask */ 1342 tBTM_LE_KEY_TYPE resp_keys; /* keys to be distributed, bit mask */ 1343 } tBTM_LE_IO_REQ; 1344 1345 /* data type for tBTM_LE_COMPLT */ 1346 typedef struct { 1347 uint8_t reason; 1348 uint8_t sec_level; 1349 bool is_pair_cancel; 1350 bool smp_over_br; 1351 } tBTM_LE_COMPLT; 1352 1353 /* BLE encryption keys */ 1354 typedef struct { 1355 Octet16 ltk; 1356 BT_OCTET8 rand; 1357 uint16_t ediv; 1358 uint8_t sec_level; 1359 uint8_t key_size; 1360 } tBTM_LE_PENC_KEYS; 1361 1362 /* BLE CSRK keys */ 1363 typedef struct { 1364 uint32_t counter; 1365 Octet16 csrk; 1366 uint8_t sec_level; 1367 } tBTM_LE_PCSRK_KEYS; 1368 1369 /* BLE Encryption reproduction keys */ 1370 typedef struct { 1371 Octet16 ltk; 1372 uint16_t div; 1373 uint8_t key_size; 1374 uint8_t sec_level; 1375 } tBTM_LE_LENC_KEYS; 1376 1377 /* BLE SRK keys */ 1378 typedef struct { 1379 uint32_t counter; 1380 uint16_t div; 1381 uint8_t sec_level; 1382 Octet16 csrk; 1383 } tBTM_LE_LCSRK_KEYS; 1384 1385 typedef struct { 1386 Octet16 irk; 1387 tBLE_ADDR_TYPE identity_addr_type; 1388 RawAddress identity_addr; 1389 } tBTM_LE_PID_KEYS; 1390 1391 typedef union { 1392 tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ 1393 tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ 1394 tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ 1395 tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys 1396 * LTK = = d1(ER,DIV,0) */ 1397 tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ 1398 } tBTM_LE_KEY_VALUE; 1399 1400 typedef struct { 1401 tBTM_LE_KEY_TYPE key_type; 1402 tBTM_LE_KEY_VALUE* p_key_value; 1403 } tBTM_LE_KEY; 1404 1405 typedef union { 1406 tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT */ 1407 uint32_t key_notif; /* BTM_LE_KEY_NOTIF_EVT */ 1408 /* BTM_LE_NC_REQ_EVT */ 1409 /* no callback data for 1410 * BTM_LE_KEY_REQ_EVT 1411 * and BTM_LE_OOB_REQ_EVT */ 1412 tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT */ 1413 tSMP_OOB_DATA_TYPE req_oob_type; 1414 tBTM_LE_KEY key; 1415 } tBTM_LE_EVT_DATA; 1416 1417 /* Simple Pairing Events. Called by the stack when Simple Pairing related 1418 * events occur. 1419 */ 1420 typedef uint8_t(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, const RawAddress& bda, 1421 tBTM_LE_EVT_DATA* p_data); 1422 1423 #define BTM_BLE_KEY_TYPE_ID 1 1424 #define BTM_BLE_KEY_TYPE_ER 2 1425 #define BTM_BLE_KEY_TYPE_COUNTER 3 // tobe obsolete 1426 1427 typedef struct { 1428 Octet16 ir; 1429 Octet16 irk; 1430 Octet16 dhk; 1431 1432 } tBTM_BLE_LOCAL_ID_KEYS; 1433 1434 typedef union { 1435 tBTM_BLE_LOCAL_ID_KEYS id_keys; 1436 Octet16 er; 1437 } tBTM_BLE_LOCAL_KEYS; 1438 1439 /* New LE identity key for local device. 1440 */ 1441 typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type, 1442 tBTM_BLE_LOCAL_KEYS* p_key); 1443 1444 /*************************** 1445 * Security Manager Types 1446 ***************************/ 1447 /* Structure that applications use to register with BTM_SecRegister */ 1448 typedef struct { 1449 tBTM_AUTHORIZE_CALLBACK* p_authorize_callback; 1450 tBTM_PIN_CALLBACK* p_pin_callback; 1451 tBTM_LINK_KEY_CALLBACK* p_link_key_callback; 1452 tBTM_AUTH_COMPLETE_CALLBACK* p_auth_complete_callback; 1453 tBTM_BOND_CANCEL_CMPL_CALLBACK* p_bond_cancel_cmpl_callback; 1454 tBTM_SP_CALLBACK* p_sp_callback; 1455 tBTM_LE_CALLBACK* p_le_callback; 1456 tBTM_LE_KEY_CALLBACK* p_le_key_callback; 1457 } tBTM_APPL_INFO; 1458 1459 /* Callback function for when a link supervision timeout event occurs. 1460 * This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt(). 1461 */ 1462 typedef void(tBTM_LSTO_CBACK)(const RawAddress& remote_bda, uint16_t timeout); 1463 1464 /***************************************************************************** 1465 * POWER MANAGEMENT 1466 ****************************************************************************/ 1467 /**************************** 1468 * Power Manager Constants 1469 ****************************/ 1470 /* BTM Power manager status codes */ 1471 enum { 1472 BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE, 1473 BTM_PM_STS_HOLD = HCI_MODE_HOLD, 1474 BTM_PM_STS_SNIFF = HCI_MODE_SNIFF, 1475 BTM_PM_STS_PARK = HCI_MODE_PARK, 1476 BTM_PM_STS_SSR, /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */ 1477 BTM_PM_STS_PENDING, /* when waiting for status from controller */ 1478 BTM_PM_STS_ERROR /* when HCI command status returns error */ 1479 }; 1480 typedef uint8_t tBTM_PM_STATUS; 1481 1482 /* BTM Power manager modes */ 1483 enum { 1484 BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE, 1485 BTM_PM_MD_HOLD = BTM_PM_STS_HOLD, 1486 BTM_PM_MD_SNIFF = BTM_PM_STS_SNIFF, 1487 BTM_PM_MD_PARK = BTM_PM_STS_PARK, 1488 BTM_PM_MD_FORCE = 0x10 /* OR this to force ACL link to a certain mode */ 1489 }; 1490 typedef uint8_t tBTM_PM_MODE; 1491 1492 #define BTM_PM_SET_ONLY_ID 0x80 1493 1494 /* Operation codes */ 1495 /* The module wants to set the desired power mode */ 1496 #define BTM_PM_REG_SET 1 1497 /* The module wants to receive mode change event */ 1498 #define BTM_PM_REG_NOTIF 2 1499 /* The module does not want to involve with PM anymore */ 1500 #define BTM_PM_DEREG 4 1501 1502 /************************ 1503 * Power Manager Types 1504 ************************/ 1505 typedef struct { 1506 uint16_t max; 1507 uint16_t min; 1508 uint16_t attempt; 1509 uint16_t timeout; 1510 tBTM_PM_MODE mode; 1511 } tBTM_PM_PWR_MD; 1512 1513 /************************************* 1514 * Power Manager Callback Functions 1515 *************************************/ 1516 typedef void(tBTM_PM_STATUS_CBACK)(const RawAddress& p_bda, 1517 tBTM_PM_STATUS status, uint16_t value, 1518 uint8_t hci_status); 1519 1520 /************************ 1521 * Stored Linkkey Types 1522 ************************/ 1523 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS 4 1524 1525 typedef struct { 1526 uint8_t event; 1527 uint8_t status; 1528 uint16_t num_keys; 1529 1530 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE; 1531 1532 /* ACL link on, SCO link ongoing, sniff mode */ 1533 #define BTM_CONTRL_ACTIVE 1 1534 /* Scan state - paging/inquiry/trying to connect*/ 1535 #define BTM_CONTRL_SCAN 2 1536 /* Idle state - page scan, LE advt, inquiry scan */ 1537 #define BTM_CONTRL_IDLE 3 1538 1539 typedef uint8_t tBTM_CONTRL_STATE; 1540 1541 #endif // BTM_API_TYPES_H 1542