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 #ifndef BT_TYPES_H 20 #define BT_TYPES_H 21 22 #include <stdbool.h> 23 #include <stdint.h> 24 25 #ifndef FALSE 26 #define FALSE false 27 #endif 28 29 #ifndef TRUE 30 #define TRUE true 31 #endif 32 33 #ifdef __arm 34 #define PACKED __packed 35 #define INLINE __inline 36 #else 37 #define PACKED 38 #define INLINE 39 #endif 40 41 /* READ WELL !! 42 * 43 * This section defines global events. These are events that cross layers. 44 * Any event that passes between layers MUST be one of these events. Tasks 45 * can use their own events internally, but a FUNDAMENTAL design issue is 46 * that global events MUST be one of these events defined below. 47 * 48 * The convention used is the the event name contains the layer that the 49 * event is going to. 50 */ 51 #define BT_EVT_MASK 0xFF00 52 #define BT_SUB_EVT_MASK 0x00FF 53 /* To Bluetooth Upper Layers */ 54 /************************************/ 55 /* L2CAP event */ 56 #define BT_EVT_TO_BTU_L2C_EVT 0x0900 57 /* HCI Event */ 58 #define BT_EVT_TO_BTU_HCI_EVT 0x1000 59 /* event from BR/EDR controller */ 60 #define BT_EVT_TO_BTU_HCI_BR_EDR_EVT (0x0000 | BT_EVT_TO_BTU_HCI_EVT) 61 /* event from local AMP 1 controller */ 62 #define BT_EVT_TO_BTU_HCI_AMP1_EVT (0x0001 | BT_EVT_TO_BTU_HCI_EVT) 63 /* event from local AMP 2 controller */ 64 #define BT_EVT_TO_BTU_HCI_AMP2_EVT (0x0002 | BT_EVT_TO_BTU_HCI_EVT) 65 /* event from local AMP 3 controller */ 66 #define BT_EVT_TO_BTU_HCI_AMP3_EVT (0x0003 | BT_EVT_TO_BTU_HCI_EVT) 67 68 /* ACL Data from HCI */ 69 #define BT_EVT_TO_BTU_HCI_ACL 0x1100 70 /* SCO Data from HCI */ 71 #define BT_EVT_TO_BTU_HCI_SCO 0x1200 72 /* HCI Transport Error */ 73 #define BT_EVT_TO_BTU_HCIT_ERR 0x1300 74 75 /* Serial Port Event */ 76 #define BT_EVT_TO_BTU_SP_EVT 0x1400 77 /* Serial Port Data */ 78 #define BT_EVT_TO_BTU_SP_DATA 0x1500 79 80 /* HCI command from upper layer */ 81 #define BT_EVT_TO_BTU_HCI_CMD 0x1600 82 83 /* L2CAP segment(s) transmitted */ 84 #define BT_EVT_TO_BTU_L2C_SEG_XMIT 0x1900 85 86 /* BlueStackTester event: incoming message from target */ 87 #define BT_EVT_PROXY_INCOMING_MSG 0x1A00 88 89 /* Insight BTSIM event */ 90 #define BT_EVT_BTSIM 0x1B00 91 /* Insight Script Engine event */ 92 #define BT_EVT_BTISE 0x1C00 93 94 /* To LM */ 95 /************************************/ 96 /* HCI Command */ 97 #define BT_EVT_TO_LM_HCI_CMD 0x2000 98 /* HCI ACL Data */ 99 #define BT_EVT_TO_LM_HCI_ACL 0x2100 100 /* HCI SCO Data */ 101 #define BT_EVT_TO_LM_HCI_SCO 0x2200 102 /* HCI Transport Error */ 103 #define BT_EVT_TO_LM_HCIT_ERR 0x2300 104 /* LC event */ 105 #define BT_EVT_TO_LM_LC_EVT 0x2400 106 /* LC Received LMP command frame */ 107 #define BT_EVT_TO_LM_LC_LMP 0x2500 108 /* LC Received ACL data */ 109 #define BT_EVT_TO_LM_LC_ACL 0x2600 110 /* LC Received SCO data (not used) */ 111 #define BT_EVT_TO_LM_LC_SCO 0x2700 112 /* LMP data transmit complete */ 113 #define BT_EVT_TO_LM_LC_ACL_TX 0x2800 114 /* LMP Command transmit complete */ 115 #define BT_EVT_TO_LM_LC_LMPC_TX 0x2900 116 /* Data to be locally loopbacked */ 117 #define BT_EVT_TO_LM_LOCAL_ACL_LB 0x2a00 118 /* HCI ACL Data ack (not used) */ 119 #define BT_EVT_TO_LM_HCI_ACL_ACK 0x2b00 120 /* LM Diagnostics commands */ 121 #define BT_EVT_TO_LM_DIAG 0x2c00 122 123 #define BT_EVT_TO_BTM_CMDS 0x2f00 124 #define BT_EVT_TO_BTM_PM_MDCHG_EVT (0x0001 | BT_EVT_TO_BTM_CMDS) 125 126 #define BT_EVT_TO_TCS_CMDS 0x3000 127 128 #define BT_EVT_TO_CTP_CMDS 0x3300 129 130 /* ftp events */ 131 #define BT_EVT_TO_FTP_SRVR_CMDS 0x3600 132 #define BT_EVT_TO_FTP_CLNT_CMDS 0x3700 133 134 /* SIM Access Profile events */ 135 #define BT_EVT_TO_BTU_SAP 0x3800 136 137 /* opp events */ 138 #define BT_EVT_TO_OPP_SRVR_CMDS 0x3900 139 #define BT_EVT_TO_OPP_CLNT_CMDS 0x3a00 140 141 /* for NFC */ 142 /************************************/ 143 /* NCI Command, Notification or Data*/ 144 #define BT_EVT_TO_NFC_NCI 0x4000 145 /* Initialization message */ 146 #define BT_EVT_TO_NFC_INIT 0x4100 147 /* Low power */ 148 #define BT_EVT_TO_NCI_LP 0x4200 149 /* Error notification to NFC Task */ 150 #define BT_EVT_TO_NFC_ERR 0x4300 151 152 /* events to NFCC simulation (NCI packets) */ 153 #define BT_EVT_TO_NFCCSIM_NCI 0x4a00 154 155 /* HCISU Events */ 156 157 #define BT_EVT_HCISU 0x5000 158 159 #define BT_EVT_TO_HCISU_RECONFIG_EVT (0x0001 | BT_EVT_HCISU) 160 #define BT_EVT_TO_HCISU_UPDATE_BAUDRATE_EVT (0x0002 | BT_EVT_HCISU) 161 #define BT_EVT_TO_HCISU_LP_ENABLE_EVT (0x0003 | BT_EVT_HCISU) 162 #define BT_EVT_TO_HCISU_LP_DISABLE_EVT (0x0004 | BT_EVT_HCISU) 163 #define BT_EVT_TO_HCISU_LP_APP_SLEEPING_EVT (0x0005 | BT_EVT_HCISU) 164 #define BT_EVT_TO_HCISU_LP_ALLOW_BT_SLEEP_EVT (0x0006 | BT_EVT_HCISU) 165 #define BT_EVT_TO_HCISU_LP_WAKEUP_HOST_EVT (0x0007 | BT_EVT_HCISU) 166 #define BT_EVT_TO_HCISU_LP_RCV_H4IBSS_EVT (0x0008 | BT_EVT_HCISU) 167 #define BT_EVT_TO_HCISU_H5_RESET_EVT (0x0009 | BT_EVT_HCISU) 168 #define BT_EVT_HCISU_START_QUICK_TIMER (0x000a | BT_EVT_HCISU) 169 170 #define BT_EVT_DATA_TO_AMP_1 0x5100 171 #define BT_EVT_DATA_TO_AMP_15 0x5f00 172 173 /* HSP Events */ 174 175 #define BT_EVT_BTU_HSP2 0x6000 176 177 #define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2) 178 179 /* BPP Events */ 180 #define BT_EVT_TO_BPP_PR_CMDS 0x6100 /* Printer Events */ 181 #define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */ 182 183 /* BIP Events */ 184 #define BT_EVT_TO_BIP_CMDS 0x6300 185 186 /* HCRP Events */ 187 188 #define BT_EVT_BTU_HCRP 0x7000 189 190 #define BT_EVT_TO_BTU_HCRP_EVT (0x0001 | BT_EVT_BTU_HCRP) 191 #define BT_EVT_TO_BTU_HCRPM_EVT (0x0002 | BT_EVT_BTU_HCRP) 192 193 #define BT_EVT_BTU_HFP 0x8000 194 #define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP) 195 196 #define BT_EVT_BTU_IPC_EVT 0x9000 197 #define BT_EVT_BTU_IPC_LOGMSG_EVT (0x0000 | BT_EVT_BTU_IPC_EVT) 198 #define BT_EVT_BTU_IPC_ACL_EVT (0x0001 | BT_EVT_BTU_IPC_EVT) 199 #define BT_EVT_BTU_IPC_BTU_EVT (0x0002 | BT_EVT_BTU_IPC_EVT) 200 #define BT_EVT_BTU_IPC_L2C_EVT (0x0003 | BT_EVT_BTU_IPC_EVT) 201 #define BT_EVT_BTU_IPC_L2C_MSG_EVT (0x0004 | BT_EVT_BTU_IPC_EVT) 202 #define BT_EVT_BTU_IPC_BTM_EVT (0x0005 | BT_EVT_BTU_IPC_EVT) 203 #define BT_EVT_BTU_IPC_AVDT_EVT (0x0006 | BT_EVT_BTU_IPC_EVT) 204 #define BT_EVT_BTU_IPC_SLIP_EVT (0x0007 | BT_EVT_BTU_IPC_EVT) 205 #define BT_EVT_BTU_IPC_MGMT_EVT (0x0008 | BT_EVT_BTU_IPC_EVT) 206 #define BT_EVT_BTU_IPC_BTTRC_EVT (0x0009 | BT_EVT_BTU_IPC_EVT) 207 #define BT_EVT_BTU_IPC_BURST_EVT (0x000A | BT_EVT_BTU_IPC_EVT) 208 209 /* BTIF Events */ 210 #define BT_EVT_BTIF 0xA000 211 #define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF) 212 213 /* Define the header of each buffer used in the Bluetooth stack. 214 */ 215 typedef struct { 216 uint16_t event; 217 uint16_t len; 218 uint16_t offset; 219 uint16_t layer_specific; 220 uint8_t data[]; 221 } BT_HDR; 222 223 #define BT_HDR_SIZE (sizeof(BT_HDR)) 224 225 #define BT_PSM_SDP 0x0001 226 #define BT_PSM_RFCOMM 0x0003 227 #define BT_PSM_TCS 0x0005 228 #define BT_PSM_CTP 0x0007 229 #define BT_PSM_BNEP 0x000F 230 #define BT_PSM_HIDC 0x0011 231 #define BT_PSM_HIDI 0x0013 232 #define BT_PSM_UPNP 0x0015 233 #define BT_PSM_AVCTP 0x0017 234 #define BT_PSM_AVDTP 0x0019 235 #define BT_PSM_AVCTP_13 0x001B /* Advanced Control - Browsing */ 236 #define BT_PSM_UDI_CP \ 237 0x001D /* Unrestricted Digital Information Profile C-Plane */ 238 #define BT_PSM_ATT 0x001F /* Attribute Protocol */ 239 240 /* These macros extract the HCI opcodes from a buffer 241 */ 242 #define HCI_GET_CMD_HDR_OPCODE(p) \ 243 (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \ 244 (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8))) 245 #define HCI_GET_CMD_HDR_PARAM_LEN(p) \ 246 (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 2)) 247 248 #define HCI_GET_EVT_HDR_OPCODE(p) \ 249 (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset)) 250 #define HCI_GET_EVT_HDR_PARAM_LEN(p) \ 251 (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 1)) 252 253 /******************************************************************************* 254 * Macros to get and put bytes to and from a stream (Little Endian format). 255 */ 256 #define UINT64_TO_BE_STREAM(p, u64) \ 257 { \ 258 *(p)++ = (uint8_t)((u64) >> 56); \ 259 *(p)++ = (uint8_t)((u64) >> 48); \ 260 *(p)++ = (uint8_t)((u64) >> 40); \ 261 *(p)++ = (uint8_t)((u64) >> 32); \ 262 *(p)++ = (uint8_t)((u64) >> 24); \ 263 *(p)++ = (uint8_t)((u64) >> 16); \ 264 *(p)++ = (uint8_t)((u64) >> 8); \ 265 *(p)++ = (uint8_t)(u64); \ 266 } 267 #define UINT32_TO_STREAM(p, u32) \ 268 { \ 269 *(p)++ = (uint8_t)(u32); \ 270 *(p)++ = (uint8_t)((u32) >> 8); \ 271 *(p)++ = (uint8_t)((u32) >> 16); \ 272 *(p)++ = (uint8_t)((u32) >> 24); \ 273 } 274 #define UINT24_TO_STREAM(p, u24) \ 275 { \ 276 *(p)++ = (uint8_t)(u24); \ 277 *(p)++ = (uint8_t)((u24) >> 8); \ 278 *(p)++ = (uint8_t)((u24) >> 16); \ 279 } 280 #define UINT16_TO_STREAM(p, u16) \ 281 { \ 282 *(p)++ = (uint8_t)(u16); \ 283 *(p)++ = (uint8_t)((u16) >> 8); \ 284 } 285 #define UINT8_TO_STREAM(p, u8) \ 286 { *(p)++ = (uint8_t)(u8); } 287 #define INT8_TO_STREAM(p, u8) \ 288 { *(p)++ = (int8_t)(u8); } 289 #define ARRAY32_TO_STREAM(p, a) \ 290 { \ 291 int ijk; \ 292 for (ijk = 0; ijk < 32; ijk++) *(p)++ = (uint8_t)(a)[31 - ijk]; \ 293 } 294 #define ARRAY16_TO_STREAM(p, a) \ 295 { \ 296 int ijk; \ 297 for (ijk = 0; ijk < 16; ijk++) *(p)++ = (uint8_t)(a)[15 - ijk]; \ 298 } 299 #define ARRAY8_TO_STREAM(p, a) \ 300 { \ 301 int ijk; \ 302 for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t)(a)[7 - ijk]; \ 303 } 304 #define LAP_TO_STREAM(p, a) \ 305 { \ 306 int ijk; \ 307 for (ijk = 0; ijk < LAP_LEN; ijk++) \ 308 *(p)++ = (uint8_t)(a)[LAP_LEN - 1 - ijk]; \ 309 } 310 #define DEVCLASS_TO_STREAM(p, a) \ 311 { \ 312 int ijk; \ 313 for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) \ 314 *(p)++ = (uint8_t)(a)[DEV_CLASS_LEN - 1 - ijk]; \ 315 } 316 #define ARRAY_TO_STREAM(p, a, len) \ 317 { \ 318 int ijk; \ 319 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \ 320 } 321 #define REVERSE_ARRAY_TO_STREAM(p, a, len) \ 322 { \ 323 int ijk; \ 324 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-1 - ijk]; \ 325 } 326 327 #define STREAM_TO_INT8(u8, p) \ 328 { \ 329 (u8) = (*((int8_t*)p)); \ 330 (p) += 1; \ 331 } 332 #define STREAM_TO_UINT8(u8, p) \ 333 { \ 334 (u8) = (uint8_t)(*(p)); \ 335 (p) += 1; \ 336 } 337 #define STREAM_TO_UINT16(u16, p) \ 338 { \ 339 (u16) = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \ 340 (p) += 2; \ 341 } 342 #define STREAM_TO_UINT24(u32, p) \ 343 { \ 344 (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \ 345 ((((uint32_t)(*((p) + 2)))) << 16)); \ 346 (p) += 3; \ 347 } 348 #define STREAM_TO_UINT32(u32, p) \ 349 { \ 350 (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \ 351 ((((uint32_t)(*((p) + 2)))) << 16) + \ 352 ((((uint32_t)(*((p) + 3)))) << 24)); \ 353 (p) += 4; \ 354 } 355 #define STREAM_TO_ARRAY32(a, p) \ 356 { \ 357 int ijk; \ 358 uint8_t* _pa = (uint8_t*)(a) + 31; \ 359 for (ijk = 0; ijk < 32; ijk++) *_pa-- = *(p)++; \ 360 } 361 #define STREAM_TO_ARRAY16(a, p) \ 362 { \ 363 int ijk; \ 364 uint8_t* _pa = (uint8_t*)(a) + 15; \ 365 for (ijk = 0; ijk < 16; ijk++) *_pa-- = *(p)++; \ 366 } 367 #define STREAM_TO_ARRAY8(a, p) \ 368 { \ 369 int ijk; \ 370 uint8_t* _pa = (uint8_t*)(a) + 7; \ 371 for (ijk = 0; ijk < 8; ijk++) *_pa-- = *(p)++; \ 372 } 373 #define STREAM_TO_DEVCLASS(a, p) \ 374 { \ 375 int ijk; \ 376 uint8_t* _pa = (uint8_t*)(a) + DEV_CLASS_LEN - 1; \ 377 for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *(p)++; \ 378 } 379 #define STREAM_TO_LAP(a, p) \ 380 { \ 381 int ijk; \ 382 uint8_t* plap = (uint8_t*)(a) + LAP_LEN - 1; \ 383 for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *(p)++; \ 384 } 385 #define STREAM_TO_ARRAY(a, p, len) \ 386 { \ 387 int ijk; \ 388 for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \ 389 } 390 #define REVERSE_STREAM_TO_ARRAY(a, p, len) \ 391 { \ 392 int ijk; \ 393 uint8_t* _pa = (uint8_t*)(a) + (len)-1; \ 394 for (ijk = 0; ijk < (len); ijk++) *_pa-- = *(p)++; \ 395 } 396 397 #define STREAM_SKIP_UINT8(p) \ 398 do { \ 399 (p) += 1; \ 400 } while (0) 401 #define STREAM_SKIP_UINT16(p) \ 402 do { \ 403 (p) += 2; \ 404 } while (0) 405 406 /******************************************************************************* 407 * Macros to get and put bytes to and from a field (Little Endian format). 408 * These are the same as to stream, except the pointer is not incremented. 409 */ 410 #define UINT32_TO_FIELD(p, u32) \ 411 { \ 412 *(uint8_t*)(p) = (uint8_t)(u32); \ 413 *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 8); \ 414 *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 16); \ 415 *((uint8_t*)(p) + 3) = (uint8_t)((u32) >> 24); \ 416 } 417 #define UINT24_TO_FIELD(p, u24) \ 418 { \ 419 *(uint8_t*)(p) = (uint8_t)(u24); \ 420 *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \ 421 *((uint8_t*)(p) + 2) = (uint8_t)((u24) >> 16); \ 422 } 423 #define UINT16_TO_FIELD(p, u16) \ 424 { \ 425 *(uint8_t*)(p) = (uint8_t)(u16); \ 426 *((uint8_t*)(p) + 1) = (uint8_t)((u16) >> 8); \ 427 } 428 #define UINT8_TO_FIELD(p, u8) \ 429 { *(uint8_t*)(p) = (uint8_t)(u8); } 430 431 /******************************************************************************* 432 * Macros to get and put bytes to and from a stream (Big Endian format) 433 */ 434 #define UINT32_TO_BE_STREAM(p, u32) \ 435 { \ 436 *(p)++ = (uint8_t)((u32) >> 24); \ 437 *(p)++ = (uint8_t)((u32) >> 16); \ 438 *(p)++ = (uint8_t)((u32) >> 8); \ 439 *(p)++ = (uint8_t)(u32); \ 440 } 441 #define UINT24_TO_BE_STREAM(p, u24) \ 442 { \ 443 *(p)++ = (uint8_t)((u24) >> 16); \ 444 *(p)++ = (uint8_t)((u24) >> 8); \ 445 *(p)++ = (uint8_t)(u24); \ 446 } 447 #define UINT16_TO_BE_STREAM(p, u16) \ 448 { \ 449 *(p)++ = (uint8_t)((u16) >> 8); \ 450 *(p)++ = (uint8_t)(u16); \ 451 } 452 #define UINT8_TO_BE_STREAM(p, u8) \ 453 { *(p)++ = (uint8_t)(u8); } 454 #define ARRAY_TO_BE_STREAM(p, a, len) \ 455 { \ 456 int ijk; \ 457 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \ 458 } 459 #define ARRAY_TO_BE_STREAM_REVERSE(p, a, len) \ 460 { \ 461 int ijk; \ 462 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-ijk - 1]; \ 463 } 464 465 #define BE_STREAM_TO_UINT8(u8, p) \ 466 { \ 467 (u8) = (uint8_t)(*(p)); \ 468 (p) += 1; \ 469 } 470 #define BE_STREAM_TO_UINT16(u16, p) \ 471 { \ 472 (u16) = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); \ 473 (p) += 2; \ 474 } 475 #define BE_STREAM_TO_UINT24(u32, p) \ 476 { \ 477 (u32) = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + \ 478 ((uint32_t)(*(p)) << 16)); \ 479 (p) += 3; \ 480 } 481 #define BE_STREAM_TO_UINT32(u32, p) \ 482 { \ 483 (u32) = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) + \ 484 ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); \ 485 (p) += 4; \ 486 } 487 #define BE_STREAM_TO_UINT64(u64, p) \ 488 { \ 489 (u64) = ((uint64_t)(*((p) + 7)) + ((uint64_t)(*((p) + 6)) << 8) + \ 490 ((uint64_t)(*((p) + 5)) << 16) + ((uint64_t)(*((p) + 4)) << 24) + \ 491 ((uint64_t)(*((p) + 3)) << 32) + ((uint64_t)(*((p) + 2)) << 40) + \ 492 ((uint64_t)(*((p) + 1)) << 48) + ((uint64_t)(*(p)) << 56)); \ 493 (p) += 8; \ 494 } 495 #define BE_STREAM_TO_ARRAY(p, a, len) \ 496 { \ 497 int ijk; \ 498 for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \ 499 } 500 501 /******************************************************************************* 502 * Macros to get and put bytes to and from a field (Big Endian format). 503 * These are the same as to stream, except the pointer is not incremented. 504 */ 505 #define UINT32_TO_BE_FIELD(p, u32) \ 506 { \ 507 *(uint8_t*)(p) = (uint8_t)((u32) >> 24); \ 508 *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 16); \ 509 *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 8); \ 510 *((uint8_t*)(p) + 3) = (uint8_t)(u32); \ 511 } 512 #define UINT24_TO_BE_FIELD(p, u24) \ 513 { \ 514 *(uint8_t*)(p) = (uint8_t)((u24) >> 16); \ 515 *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \ 516 *((uint8_t*)(p) + 2) = (uint8_t)(u24); \ 517 } 518 #define UINT16_TO_BE_FIELD(p, u16) \ 519 { \ 520 *(uint8_t*)(p) = (uint8_t)((u16) >> 8); \ 521 *((uint8_t*)(p) + 1) = (uint8_t)(u16); \ 522 } 523 #define UINT8_TO_BE_FIELD(p, u8) \ 524 { *(uint8_t*)(p) = (uint8_t)(u8); } 525 526 /* Common Bluetooth field definitions */ 527 #define BD_ADDR_LEN 6 /* Device address length */ 528 529 #ifdef __cplusplus 530 #include <hardware/bluetooth.h> 531 532 inline void BDADDR_TO_STREAM(uint8_t*& p, const RawAddress& a) { 533 for (int ijk = 0; ijk < BD_ADDR_LEN; ijk++) 534 *(p)++ = (uint8_t)(a.address)[BD_ADDR_LEN - 1 - ijk]; 535 } 536 537 inline void STREAM_TO_BDADDR(RawAddress& a, uint8_t*& p) { 538 uint8_t* pbda = (uint8_t*)(a.address) + BD_ADDR_LEN - 1; 539 for (int ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *(p)++; 540 } 541 542 #endif 543 544 #define AMP_KEY_TYPE_GAMP 0 545 #define AMP_KEY_TYPE_WIFI 1 546 #define AMP_KEY_TYPE_UWB 2 547 typedef uint8_t tAMP_KEY_TYPE; 548 549 #define BT_OCTET8_LEN 8 550 typedef uint8_t BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */ 551 552 #define LINK_KEY_LEN 16 553 typedef uint8_t LINK_KEY[LINK_KEY_LEN]; /* Link Key */ 554 555 #define AMP_LINK_KEY_LEN 32 556 typedef uint8_t 557 AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */ 558 559 #define BT_OCTET16_LEN 16 560 typedef uint8_t BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */ 561 562 #define PIN_CODE_LEN 16 563 typedef uint8_t PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */ 564 typedef uint8_t* PIN_CODE_PTR; /* Pointer to Pin Code */ 565 566 #define BT_OCTET32_LEN 32 567 typedef uint8_t BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */ 568 569 #define DEV_CLASS_LEN 3 570 typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ 571 typedef uint8_t* DEV_CLASS_PTR; /* Pointer to Device class */ 572 573 #define EXT_INQ_RESP_LEN 3 574 typedef uint8_t EXT_INQ_RESP[EXT_INQ_RESP_LEN]; /* Extended Inquiry Response */ 575 typedef uint8_t* EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */ 576 577 #define BD_NAME_LEN 248 578 typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */ 579 typedef uint8_t* BD_NAME_PTR; /* Pointer to Device name */ 580 581 #define BD_FEATURES_LEN 8 582 typedef uint8_t 583 BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */ 584 585 #define BT_EVENT_MASK_LEN 8 586 typedef uint8_t BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */ 587 588 #define LAP_LEN 3 589 typedef uint8_t LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ 590 typedef uint8_t INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */ 591 592 #define RAND_NUM_LEN 16 593 typedef uint8_t RAND_NUM[RAND_NUM_LEN]; 594 595 #define ACO_LEN 12 596 typedef uint8_t ACO[ACO_LEN]; /* Authenticated ciphering offset */ 597 598 #define COF_LEN 12 599 typedef uint8_t COF[COF_LEN]; /* ciphering offset number */ 600 601 typedef struct { 602 uint8_t qos_flags; /* TBD */ 603 uint8_t service_type; /* see below */ 604 uint32_t token_rate; /* bytes/second */ 605 uint32_t token_bucket_size; /* bytes */ 606 uint32_t peak_bandwidth; /* bytes/second */ 607 uint32_t latency; /* microseconds */ 608 uint32_t delay_variation; /* microseconds */ 609 } FLOW_SPEC; 610 611 /* Values for service_type */ 612 #define NO_TRAFFIC 0 613 #define BEST_EFFORT 1 614 #define GUARANTEED 2 615 616 /* Service class of the CoD */ 617 #define SERV_CLASS_NETWORKING (1 << 1) 618 #define SERV_CLASS_RENDERING (1 << 2) 619 #define SERV_CLASS_CAPTURING (1 << 3) 620 #define SERV_CLASS_OBJECT_TRANSFER (1 << 4) 621 #define SERV_CLASS_OBJECT_AUDIO (1 << 5) 622 #define SERV_CLASS_OBJECT_TELEPHONY (1 << 6) 623 #define SERV_CLASS_OBJECT_INFORMATION (1 << 7) 624 625 /* Second byte */ 626 #define SERV_CLASS_LIMITED_DISC_MODE (0x20) 627 628 /* Field size definitions. Note that byte lengths are rounded up. */ 629 #define ACCESS_CODE_BIT_LEN 72 630 #define ACCESS_CODE_BYTE_LEN 9 631 #define SHORTENED_ACCESS_CODE_BIT_LEN 68 632 633 typedef uint8_t ACCESS_CODE[ACCESS_CODE_BYTE_LEN]; 634 635 #define SYNTH_TX 1 /* want synth code to TRANSMIT at this freq */ 636 #define SYNTH_RX 2 /* want synth code to RECEIVE at this freq */ 637 638 #define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */ 639 640 #define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */ 641 642 /* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */ 643 #define MAX_UUID_SIZE 16 644 typedef struct { 645 #define LEN_UUID_16 2 646 #define LEN_UUID_32 4 647 #define LEN_UUID_128 16 648 649 uint16_t len; 650 651 union { 652 uint16_t uuid16; 653 uint32_t uuid32; 654 uint8_t uuid128[MAX_UUID_SIZE]; 655 } uu; 656 657 } tBT_UUID; 658 659 #define BT_EIR_FLAGS_TYPE 0x01 660 #define BT_EIR_MORE_16BITS_UUID_TYPE 0x02 661 #define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03 662 #define BT_EIR_MORE_32BITS_UUID_TYPE 0x04 663 #define BT_EIR_COMPLETE_32BITS_UUID_TYPE 0x05 664 #define BT_EIR_MORE_128BITS_UUID_TYPE 0x06 665 #define BT_EIR_COMPLETE_128BITS_UUID_TYPE 0x07 666 #define BT_EIR_SHORTENED_LOCAL_NAME_TYPE 0x08 667 #define BT_EIR_COMPLETE_LOCAL_NAME_TYPE 0x09 668 #define BT_EIR_TX_POWER_LEVEL_TYPE 0x0A 669 #define BT_EIR_OOB_BD_ADDR_TYPE 0x0C 670 #define BT_EIR_OOB_COD_TYPE 0x0D 671 #define BT_EIR_OOB_SSP_HASH_C_TYPE 0x0E 672 #define BT_EIR_OOB_SSP_RAND_R_TYPE 0x0F 673 #define BT_EIR_SERVICE_DATA_TYPE 0x16 674 #define BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE 0x16 675 #define BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE 0x20 676 #define BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE 0x21 677 #define BT_EIR_MANUFACTURER_SPECIFIC_TYPE 0xFF 678 679 #define BT_OOB_COD_SIZE 3 680 #define BT_OOB_HASH_C_SIZE 16 681 #define BT_OOB_RAND_R_SIZE 16 682 683 /* Broadcom proprietary UUIDs and reserved PSMs 684 * 685 * The lowest 4 bytes byte of the UUID or GUID depend on the feature. Typically, 686 * the value of those bytes will be the PSM or SCN. 687 */ 688 #define BRCM_PROPRIETARY_UUID_BASE \ 689 0xDA, 0x23, 0x41, 0x02, 0xA3, 0xBB, 0xC1, 0x71, 0xBA, 0x09, 0x6f, 0x21 690 #define BRCM_PROPRIETARY_GUID_BASE \ 691 0xda23, 0x4102, 0xa3, 0xbb, 0xc1, 0x71, 0xba, 0x09, 0x6f, 0x21 692 693 /* We will not allocate a PSM in the reserved range to 3rd party apps 694 */ 695 #define BRCM_RESERVED_PSM_START 0x5AE1 696 #define BRCM_RESERVED_PSM_END 0x5AFF 697 698 #define BRCM_UTILITY_SERVICE_PSM 0x5AE1 699 #define BRCM_MATCHER_PSM 0x5AE3 700 701 /* Connection statistics 702 */ 703 704 /* Structure to hold connection stats */ 705 #ifndef BT_CONN_STATS_DEFINED 706 #define BT_CONN_STATS_DEFINED 707 708 /* These bits are used in the bIsConnected field */ 709 #define BT_CONNECTED_USING_BREDR 1 710 #define BT_CONNECTED_USING_AMP 2 711 712 typedef struct { 713 uint32_t is_connected; 714 int32_t rssi; 715 uint32_t bytes_sent; 716 uint32_t bytes_rcvd; 717 uint32_t duration; 718 } tBT_CONN_STATS; 719 720 #endif 721 722 /***************************************************************************** 723 * Low Energy definitions 724 * 725 * Address types 726 */ 727 #define BLE_ADDR_PUBLIC 0x00 728 #define BLE_ADDR_RANDOM 0x01 729 #define BLE_ADDR_PUBLIC_ID 0x02 730 #define BLE_ADDR_RANDOM_ID 0x03 731 typedef uint8_t tBLE_ADDR_TYPE; 732 #define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC) 733 734 #define BT_TRANSPORT_INVALID 0 735 #define BT_TRANSPORT_BR_EDR 1 736 #define BT_TRANSPORT_LE 2 737 typedef uint8_t tBT_TRANSPORT; 738 739 #define PHY_LE_1M_MASK 1 740 #define PHY_LE_2M_MASK 2 741 #define PHY_LE_CODED_MASK 4 742 743 #define BLE_ADDR_IS_STATIC(x) (((x)[0] & 0xC0) == 0xC0) 744 745 #ifdef __cplusplus 746 struct tBLE_BD_ADDR { 747 tBLE_ADDR_TYPE type; 748 RawAddress bda; 749 }; 750 #endif 751 752 /* Device Types 753 */ 754 #define BT_DEVICE_TYPE_BREDR 0x01 755 #define BT_DEVICE_TYPE_BLE 0x02 756 #define BT_DEVICE_TYPE_DUMO 0x03 757 typedef uint8_t tBT_DEVICE_TYPE; 758 /*****************************************************************************/ 759 760 /* Define trace levels */ 761 #define BT_TRACE_LEVEL_NONE 0 /* No trace messages to be generated */ 762 #define BT_TRACE_LEVEL_ERROR 1 /* Error condition trace messages */ 763 #define BT_TRACE_LEVEL_WARNING 2 /* Warning condition trace messages */ 764 #define BT_TRACE_LEVEL_API 3 /* API traces */ 765 #define BT_TRACE_LEVEL_EVENT 4 /* Debug messages for events */ 766 #define BT_TRACE_LEVEL_DEBUG 5 /* Full debug messages */ 767 #define BT_TRACE_LEVEL_VERBOSE 6 /* Verbose debug messages */ 768 769 #define MAX_TRACE_LEVEL 6 770 771 /* Define New Trace Type Definition */ 772 /* TRACE_CTRL_TYPE 0x^^000000*/ 773 #define TRACE_CTRL_MASK 0xff000000 774 #define TRACE_GET_CTRL(x) ((((uint32_t)(x)) & TRACE_CTRL_MASK) >> 24) 775 776 #define TRACE_CTRL_GENERAL 0x00000000 777 #define TRACE_CTRL_STR_RESOURCE 0x01000000 778 #define TRACE_CTRL_SEQ_FLOW 0x02000000 779 #define TRACE_CTRL_MAX_NUM 3 780 781 /* LAYER SPECIFIC 0x00^^0000*/ 782 #define TRACE_LAYER_MASK 0x00ff0000 783 #define TRACE_GET_LAYER(x) ((((uint32_t)(x)) & TRACE_LAYER_MASK) >> 16) 784 785 #define TRACE_LAYER_NONE 0x00000000 786 #define TRACE_LAYER_USB 0x00010000 787 #define TRACE_LAYER_SERIAL 0x00020000 788 #define TRACE_LAYER_SOCKET 0x00030000 789 #define TRACE_LAYER_RS232 0x00040000 790 #define TRACE_LAYER_TRANS_MAX_NUM 5 791 #define TRACE_LAYER_TRANS_ALL 0x007f0000 792 #define TRACE_LAYER_LC 0x00050000 793 #define TRACE_LAYER_LM 0x00060000 794 #define TRACE_LAYER_HCI 0x00070000 795 #define TRACE_LAYER_L2CAP 0x00080000 796 #define TRACE_LAYER_RFCOMM 0x00090000 797 #define TRACE_LAYER_SDP 0x000a0000 798 #define TRACE_LAYER_TCS 0x000b0000 799 #define TRACE_LAYER_OBEX 0x000c0000 800 #define TRACE_LAYER_BTM 0x000d0000 801 #define TRACE_LAYER_ICP 0x00110000 802 #define TRACE_LAYER_HSP2 0x00120000 803 #define TRACE_LAYER_SPP 0x00130000 804 #define TRACE_LAYER_CTP 0x00140000 805 #define TRACE_LAYER_BPP 0x00150000 806 #define TRACE_LAYER_HCRP 0x00160000 807 #define TRACE_LAYER_FTP 0x00170000 808 #define TRACE_LAYER_OPP 0x00180000 809 #define TRACE_LAYER_BTU 0x00190000 810 #define TRACE_LAYER_GKI 0x001a0000 /* OBSOLETED */ 811 #define TRACE_LAYER_BNEP 0x001b0000 812 #define TRACE_LAYER_PAN 0x001c0000 813 #define TRACE_LAYER_HFP 0x001d0000 814 #define TRACE_LAYER_HID 0x001e0000 815 #define TRACE_LAYER_BIP 0x001f0000 816 #define TRACE_LAYER_AVP 0x00200000 817 #define TRACE_LAYER_A2DP 0x00210000 818 #define TRACE_LAYER_SAP 0x00220000 819 #define TRACE_LAYER_AMP 0x00230000 820 #define TRACE_LAYER_MCA 0x00240000 821 #define TRACE_LAYER_ATT 0x00250000 822 #define TRACE_LAYER_SMP 0x00260000 823 #define TRACE_LAYER_NFC 0x00270000 824 #define TRACE_LAYER_NCI 0x00280000 825 #define TRACE_LAYER_LLCP 0x00290000 826 #define TRACE_LAYER_NDEF 0x002a0000 827 #define TRACE_LAYER_RW 0x002b0000 828 #define TRACE_LAYER_CE 0x002c0000 829 #define TRACE_LAYER_P2P 0x002d0000 830 #define TRACE_LAYER_SNEP 0x002e0000 831 #define TRACE_LAYER_CHO 0x002f0000 832 #define TRACE_LAYER_NFA 0x00300000 833 834 #define TRACE_LAYER_MAX_NUM 0x0031 835 836 /* TRACE_ORIGINATOR 0x0000^^00*/ 837 #define TRACE_ORG_MASK 0x0000ff00 838 #define TRACE_GET_ORG(x) ((((uint32_t)(x)) & TRACE_ORG_MASK) >> 8) 839 840 #define TRACE_ORG_STACK 0x00000000 841 #define TRACE_ORG_HCI_TRANS 0x00000100 842 #define TRACE_ORG_PROTO_DISP 0x00000200 843 #define TRACE_ORG_RPC 0x00000300 844 #define TRACE_ORG_GKI 0x00000400 /* OBSOLETED */ 845 #define TRACE_ORG_APPL 0x00000500 846 #define TRACE_ORG_SCR_WRAPPER 0x00000600 847 #define TRACE_ORG_SCR_ENGINE 0x00000700 848 #define TRACE_ORG_USER_SCR 0x00000800 849 #define TRACE_ORG_TESTER 0x00000900 850 #define TRACE_ORG_MAX_NUM 10 /* 32-bit mask; must be < 32 */ 851 #define TRACE_LITE_ORG_MAX_NUM 6 852 #define TRACE_ORG_ALL 0x03ff 853 #define TRACE_ORG_RPC_TRANS 0x04 854 855 #define TRACE_ORG_REG 0x00000909 856 #define TRACE_ORG_REG_SUCCESS 0x0000090a 857 858 /* TRACE_TYPE 0x000000^^*/ 859 #define TRACE_TYPE_MASK 0x000000ff 860 #define TRACE_GET_TYPE(x) (((uint32_t)(x)) & TRACE_TYPE_MASK) 861 862 #define TRACE_TYPE_ERROR 0x00000000 863 #define TRACE_TYPE_WARNING 0x00000001 864 #define TRACE_TYPE_API 0x00000002 865 #define TRACE_TYPE_EVENT 0x00000003 866 #define TRACE_TYPE_DEBUG 0x00000004 867 #define TRACE_TYPE_STACK_ONLY_MAX TRACE_TYPE_DEBUG 868 #define TRACE_TYPE_TX 0x00000005 869 #define TRACE_TYPE_RX 0x00000006 870 #define TRACE_TYPE_DEBUG_ASSERT 0x00000007 871 #define TRACE_TYPE_GENERIC 0x00000008 872 #define TRACE_TYPE_REG 0x00000009 873 #define TRACE_TYPE_REG_SUCCESS 0x0000000a 874 #define TRACE_TYPE_CMD_TX 0x0000000b 875 #define TRACE_TYPE_EVT_TX 0x0000000c 876 #define TRACE_TYPE_ACL_TX 0x0000000d 877 #define TRACE_TYPE_CMD_RX 0x0000000e 878 #define TRACE_TYPE_EVT_RX 0x0000000f 879 #define TRACE_TYPE_ACL_RX 0x00000010 880 #define TRACE_TYPE_TARGET_TRACE 0x00000011 881 #define TRACE_TYPE_SCO_TX 0x00000012 882 #define TRACE_TYPE_SCO_RX 0x00000013 883 884 #define TRACE_TYPE_MAX_NUM 20 885 #define TRACE_TYPE_ALL 0xffff 886 887 /* Define color for script type */ 888 #define SCR_COLOR_DEFAULT 0 889 #define SCR_COLOR_TYPE_COMMENT 1 890 #define SCR_COLOR_TYPE_COMMAND 2 891 #define SCR_COLOR_TYPE_EVENT 3 892 #define SCR_COLOR_TYPE_SELECT 4 893 894 /* Define protocol trace flag values */ 895 #define SCR_PROTO_TRACE_HCI_SUMMARY 0x00000001 896 #define SCR_PROTO_TRACE_HCI_DATA 0x00000002 897 #define SCR_PROTO_TRACE_L2CAP 0x00000004 898 #define SCR_PROTO_TRACE_RFCOMM 0x00000008 899 #define SCR_PROTO_TRACE_SDP 0x00000010 900 #define SCR_PROTO_TRACE_TCS 0x00000020 901 #define SCR_PROTO_TRACE_OBEX 0x00000040 902 #define SCR_PROTO_TRACE_OAPP 0x00000080 /* OBEX Application Profile */ 903 #define SCR_PROTO_TRACE_AMP 0x00000100 904 #define SCR_PROTO_TRACE_BNEP 0x00000200 905 #define SCR_PROTO_TRACE_AVP 0x00000400 906 #define SCR_PROTO_TRACE_MCA 0x00000800 907 #define SCR_PROTO_TRACE_ATT 0x00001000 908 #define SCR_PROTO_TRACE_SMP 0x00002000 909 #define SCR_PROTO_TRACE_NCI 0x00004000 910 #define SCR_PROTO_TRACE_LLCP 0x00008000 911 #define SCR_PROTO_TRACE_NDEF 0x00010000 912 #define SCR_PROTO_TRACE_RW 0x00020000 913 #define SCR_PROTO_TRACE_CE 0x00040000 914 #define SCR_PROTO_TRACE_SNEP 0x00080000 915 #define SCR_PROTO_TRACE_CHO 0x00100000 916 #define SCR_PROTO_TRACE_ALL 0x001fffff 917 #define SCR_PROTO_TRACE_HCI_LOGGING_VSE \ 918 0x0800 /* Brcm vs event for logmsg and protocol traces */ 919 920 #define MAX_SCRIPT_TYPE 5 921 922 #define TCS_PSM_INTERCOM 5 923 #define TCS_PSM_CORDLESS 7 924 #define BT_PSM_BNEP 0x000F 925 /* Define PSMs HID uses */ 926 #define HID_PSM_CONTROL 0x0011 927 #define HID_PSM_INTERRUPT 0x0013 928 929 /* Define a function for logging */ 930 typedef void(BT_LOG_FUNC)(int trace_type, const char* fmt_str, ...); 931 932 #endif 933