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