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 /* gap events */
142 #define BT_EVT_TO_GAP_MSG 0x3b00
143 
144 /* for NFC                          */
145 /************************************/
146 /* NCI Command, Notification or Data*/
147 #define BT_EVT_TO_NFC_NCI 0x4000
148 /* Initialization message */
149 #define BT_EVT_TO_NFC_INIT 0x4100
150 /* Low power */
151 #define BT_EVT_TO_NCI_LP 0x4200
152 /* Error notification to NFC Task */
153 #define BT_EVT_TO_NFC_ERR 0x4300
154 
155 /* events to NFCC simulation (NCI packets) */
156 #define BT_EVT_TO_NFCCSIM_NCI 0x4a00
157 
158 /* HCISU Events */
159 
160 #define BT_EVT_HCISU 0x5000
161 
162 #define BT_EVT_TO_HCISU_RECONFIG_EVT (0x0001 | BT_EVT_HCISU)
163 #define BT_EVT_TO_HCISU_UPDATE_BAUDRATE_EVT (0x0002 | BT_EVT_HCISU)
164 #define BT_EVT_TO_HCISU_LP_ENABLE_EVT (0x0003 | BT_EVT_HCISU)
165 #define BT_EVT_TO_HCISU_LP_DISABLE_EVT (0x0004 | BT_EVT_HCISU)
166 #define BT_EVT_TO_HCISU_LP_APP_SLEEPING_EVT (0x0005 | BT_EVT_HCISU)
167 #define BT_EVT_TO_HCISU_LP_ALLOW_BT_SLEEP_EVT (0x0006 | BT_EVT_HCISU)
168 #define BT_EVT_TO_HCISU_LP_WAKEUP_HOST_EVT (0x0007 | BT_EVT_HCISU)
169 #define BT_EVT_TO_HCISU_LP_RCV_H4IBSS_EVT (0x0008 | BT_EVT_HCISU)
170 #define BT_EVT_TO_HCISU_H5_RESET_EVT (0x0009 | BT_EVT_HCISU)
171 #define BT_EVT_HCISU_START_QUICK_TIMER (0x000a | BT_EVT_HCISU)
172 
173 #define BT_EVT_DATA_TO_AMP_1 0x5100
174 #define BT_EVT_DATA_TO_AMP_15 0x5f00
175 
176 /* HSP Events */
177 
178 #define BT_EVT_BTU_HSP2 0x6000
179 
180 #define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2)
181 
182 /* BPP Events */
183 #define BT_EVT_TO_BPP_PR_CMDS 0x6100  /* Printer Events */
184 #define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */
185 
186 /* BIP Events */
187 #define BT_EVT_TO_BIP_CMDS 0x6300
188 
189 /* HCRP Events */
190 
191 #define BT_EVT_BTU_HCRP 0x7000
192 
193 #define BT_EVT_TO_BTU_HCRP_EVT (0x0001 | BT_EVT_BTU_HCRP)
194 #define BT_EVT_TO_BTU_HCRPM_EVT (0x0002 | BT_EVT_BTU_HCRP)
195 
196 #define BT_EVT_BTU_HFP 0x8000
197 #define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP)
198 
199 #define BT_EVT_BTU_IPC_EVT 0x9000
200 #define BT_EVT_BTU_IPC_LOGMSG_EVT (0x0000 | BT_EVT_BTU_IPC_EVT)
201 #define BT_EVT_BTU_IPC_ACL_EVT (0x0001 | BT_EVT_BTU_IPC_EVT)
202 #define BT_EVT_BTU_IPC_BTU_EVT (0x0002 | BT_EVT_BTU_IPC_EVT)
203 #define BT_EVT_BTU_IPC_L2C_EVT (0x0003 | BT_EVT_BTU_IPC_EVT)
204 #define BT_EVT_BTU_IPC_L2C_MSG_EVT (0x0004 | BT_EVT_BTU_IPC_EVT)
205 #define BT_EVT_BTU_IPC_BTM_EVT (0x0005 | BT_EVT_BTU_IPC_EVT)
206 #define BT_EVT_BTU_IPC_AVDT_EVT (0x0006 | BT_EVT_BTU_IPC_EVT)
207 #define BT_EVT_BTU_IPC_SLIP_EVT (0x0007 | BT_EVT_BTU_IPC_EVT)
208 #define BT_EVT_BTU_IPC_MGMT_EVT (0x0008 | BT_EVT_BTU_IPC_EVT)
209 #define BT_EVT_BTU_IPC_BTTRC_EVT (0x0009 | BT_EVT_BTU_IPC_EVT)
210 #define BT_EVT_BTU_IPC_BURST_EVT (0x000A | BT_EVT_BTU_IPC_EVT)
211 
212 /* BTIF Events */
213 #define BT_EVT_BTIF 0xA000
214 #define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF)
215 
216 /* Define the header of each buffer used in the Bluetooth stack.
217 */
218 typedef struct {
219   uint16_t event;
220   uint16_t len;
221   uint16_t offset;
222   uint16_t layer_specific;
223   uint8_t data[];
224 } BT_HDR;
225 
226 #define BT_HDR_SIZE (sizeof(BT_HDR))
227 
228 #define BT_PSM_SDP 0x0001
229 #define BT_PSM_RFCOMM 0x0003
230 #define BT_PSM_TCS 0x0005
231 #define BT_PSM_CTP 0x0007
232 #define BT_PSM_BNEP 0x000F
233 #define BT_PSM_HIDC 0x0011
234 #define BT_PSM_HIDI 0x0013
235 #define BT_PSM_UPNP 0x0015
236 #define BT_PSM_AVCTP 0x0017
237 #define BT_PSM_AVDTP 0x0019
238 #define BT_PSM_AVCTP_13 0x001B /* Advanced Control - Browsing */
239 #define BT_PSM_UDI_CP \
240   0x001D /* Unrestricted Digital Information Profile C-Plane  */
241 #define BT_PSM_ATT 0x001F /* Attribute Protocol  */
242 
243 /* These macros extract the HCI opcodes from a buffer
244 */
245 #define HCI_GET_CMD_HDR_OPCODE(p)                    \
246   (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \
247               (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8)))
248 #define HCI_GET_CMD_HDR_PARAM_LEN(p) \
249   (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 2))
250 
251 #define HCI_GET_EVT_HDR_OPCODE(p) \
252   (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset))
253 #define HCI_GET_EVT_HDR_PARAM_LEN(p) \
254   (uint8_t)(*((uint8_t*)((p) + 1) + (p)->offset + 1))
255 
256 /*******************************************************************************
257  * Macros to get and put bytes to and from a stream (Little Endian format).
258 */
259 #define UINT64_TO_BE_STREAM(p, u64)  \
260   {                                  \
261     *(p)++ = (uint8_t)((u64) >> 56); \
262     *(p)++ = (uint8_t)((u64) >> 48); \
263     *(p)++ = (uint8_t)((u64) >> 40); \
264     *(p)++ = (uint8_t)((u64) >> 32); \
265     *(p)++ = (uint8_t)((u64) >> 24); \
266     *(p)++ = (uint8_t)((u64) >> 16); \
267     *(p)++ = (uint8_t)((u64) >> 8);  \
268     *(p)++ = (uint8_t)(u64);         \
269   }
270 #define UINT32_TO_STREAM(p, u32)     \
271   {                                  \
272     *(p)++ = (uint8_t)(u32);         \
273     *(p)++ = (uint8_t)((u32) >> 8);  \
274     *(p)++ = (uint8_t)((u32) >> 16); \
275     *(p)++ = (uint8_t)((u32) >> 24); \
276   }
277 #define UINT24_TO_STREAM(p, u24)     \
278   {                                  \
279     *(p)++ = (uint8_t)(u24);         \
280     *(p)++ = (uint8_t)((u24) >> 8);  \
281     *(p)++ = (uint8_t)((u24) >> 16); \
282   }
283 #define UINT16_TO_STREAM(p, u16)    \
284   {                                 \
285     *(p)++ = (uint8_t)(u16);        \
286     *(p)++ = (uint8_t)((u16) >> 8); \
287   }
288 #define UINT8_TO_STREAM(p, u8) \
289   { *(p)++ = (uint8_t)(u8); }
290 #define INT8_TO_STREAM(p, u8) \
291   { *(p)++ = (int8_t)(u8); }
292 #define ARRAY32_TO_STREAM(p, a)                                     \
293   {                                                                 \
294     int ijk;                                                        \
295     for (ijk = 0; ijk < 32; ijk++) *(p)++ = (uint8_t)(a)[31 - ijk]; \
296   }
297 #define ARRAY16_TO_STREAM(p, a)                                     \
298   {                                                                 \
299     int ijk;                                                        \
300     for (ijk = 0; ijk < 16; ijk++) *(p)++ = (uint8_t)(a)[15 - ijk]; \
301   }
302 #define ARRAY8_TO_STREAM(p, a)                                    \
303   {                                                               \
304     int ijk;                                                      \
305     for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t)(a)[7 - ijk]; \
306   }
307 #define BDADDR_TO_STREAM(p, a)                      \
308   {                                                 \
309     int ijk;                                        \
310     for (ijk = 0; ijk < BD_ADDR_LEN; ijk++)         \
311       *(p)++ = (uint8_t)(a)[BD_ADDR_LEN - 1 - ijk]; \
312   }
313 #define LAP_TO_STREAM(p, a)                     \
314   {                                             \
315     int ijk;                                    \
316     for (ijk = 0; ijk < LAP_LEN; ijk++)         \
317       *(p)++ = (uint8_t)(a)[LAP_LEN - 1 - ijk]; \
318   }
319 #define DEVCLASS_TO_STREAM(p, a)                      \
320   {                                                   \
321     int ijk;                                          \
322     for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++)         \
323       *(p)++ = (uint8_t)(a)[DEV_CLASS_LEN - 1 - ijk]; \
324   }
325 #define ARRAY_TO_STREAM(p, a, len)                                \
326   {                                                               \
327     int ijk;                                                      \
328     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
329   }
330 #define REVERSE_ARRAY_TO_STREAM(p, a, len)                                  \
331   {                                                                         \
332     int ijk;                                                                \
333     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-1 - ijk]; \
334   }
335 
336 #define STREAM_TO_INT8(u8, p) \
337   {                           \
338     (u8) = (*((int8_t*)p));   \
339     (p) += 1;                 \
340   }
341 #define STREAM_TO_UINT8(u8, p) \
342   {                            \
343     (u8) = (uint8_t)(*(p));    \
344     (p) += 1;                  \
345   }
346 #define STREAM_TO_UINT16(u16, p)                                  \
347   {                                                               \
348     (u16) = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \
349     (p) += 2;                                                     \
350   }
351 #define STREAM_TO_UINT24(u32, p)                                      \
352   {                                                                   \
353     (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \
354              ((((uint32_t)(*((p) + 2)))) << 16));                     \
355     (p) += 3;                                                         \
356   }
357 #define STREAM_TO_UINT32(u32, p)                                      \
358   {                                                                   \
359     (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \
360              ((((uint32_t)(*((p) + 2)))) << 16) +                     \
361              ((((uint32_t)(*((p) + 3)))) << 24));                     \
362     (p) += 4;                                                         \
363   }
364 #define STREAM_TO_BDADDR(a, p)                                \
365   {                                                           \
366     int ijk;                                                  \
367     uint8_t* pbda = (uint8_t*)(a) + BD_ADDR_LEN - 1;          \
368     for (ijk = 0; ijk < BD_ADDR_LEN; ijk++) *pbda-- = *(p)++; \
369   }
370 #define STREAM_TO_ARRAY32(a, p)                     \
371   {                                                 \
372     int ijk;                                        \
373     uint8_t* _pa = (uint8_t*)(a) + 31;              \
374     for (ijk = 0; ijk < 32; ijk++) *_pa-- = *(p)++; \
375   }
376 #define STREAM_TO_ARRAY16(a, p)                     \
377   {                                                 \
378     int ijk;                                        \
379     uint8_t* _pa = (uint8_t*)(a) + 15;              \
380     for (ijk = 0; ijk < 16; ijk++) *_pa-- = *(p)++; \
381   }
382 #define STREAM_TO_ARRAY8(a, p)                     \
383   {                                                \
384     int ijk;                                       \
385     uint8_t* _pa = (uint8_t*)(a) + 7;              \
386     for (ijk = 0; ijk < 8; ijk++) *_pa-- = *(p)++; \
387   }
388 #define STREAM_TO_DEVCLASS(a, p)                               \
389   {                                                            \
390     int ijk;                                                   \
391     uint8_t* _pa = (uint8_t*)(a) + DEV_CLASS_LEN - 1;          \
392     for (ijk = 0; ijk < DEV_CLASS_LEN; ijk++) *_pa-- = *(p)++; \
393   }
394 #define STREAM_TO_LAP(a, p)                               \
395   {                                                       \
396     int ijk;                                              \
397     uint8_t* plap = (uint8_t*)(a) + LAP_LEN - 1;          \
398     for (ijk = 0; ijk < LAP_LEN; ijk++) *plap-- = *(p)++; \
399   }
400 #define STREAM_TO_ARRAY(a, p, len)                                   \
401   {                                                                  \
402     int ijk;                                                         \
403     for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \
404   }
405 #define REVERSE_STREAM_TO_ARRAY(a, p, len)             \
406   {                                                    \
407     int ijk;                                           \
408     uint8_t* _pa = (uint8_t*)(a) + (len)-1;            \
409     for (ijk = 0; ijk < (len); ijk++) *_pa-- = *(p)++; \
410   }
411 
412 #define STREAM_SKIP_UINT8(p) \
413   do {                       \
414     (p) += 1;                \
415   } while (0)
416 #define STREAM_SKIP_UINT16(p) \
417   do {                        \
418     (p) += 2;                 \
419   } while (0)
420 
421 /*******************************************************************************
422  * Macros to get and put bytes to and from a field (Little Endian format).
423  * These are the same as to stream, except the pointer is not incremented.
424 */
425 #define UINT32_TO_FIELD(p, u32)                    \
426   {                                                \
427     *(uint8_t*)(p) = (uint8_t)(u32);               \
428     *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 8);  \
429     *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 16); \
430     *((uint8_t*)(p) + 3) = (uint8_t)((u32) >> 24); \
431   }
432 #define UINT24_TO_FIELD(p, u24)                    \
433   {                                                \
434     *(uint8_t*)(p) = (uint8_t)(u24);               \
435     *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8);  \
436     *((uint8_t*)(p) + 2) = (uint8_t)((u24) >> 16); \
437   }
438 #define UINT16_TO_FIELD(p, u16)                   \
439   {                                               \
440     *(uint8_t*)(p) = (uint8_t)(u16);              \
441     *((uint8_t*)(p) + 1) = (uint8_t)((u16) >> 8); \
442   }
443 #define UINT8_TO_FIELD(p, u8) \
444   { *(uint8_t*)(p) = (uint8_t)(u8); }
445 
446 /*******************************************************************************
447  * Macros to get and put bytes to and from a stream (Big Endian format)
448 */
449 #define UINT32_TO_BE_STREAM(p, u32)  \
450   {                                  \
451     *(p)++ = (uint8_t)((u32) >> 24); \
452     *(p)++ = (uint8_t)((u32) >> 16); \
453     *(p)++ = (uint8_t)((u32) >> 8);  \
454     *(p)++ = (uint8_t)(u32);         \
455   }
456 #define UINT24_TO_BE_STREAM(p, u24)  \
457   {                                  \
458     *(p)++ = (uint8_t)((u24) >> 16); \
459     *(p)++ = (uint8_t)((u24) >> 8);  \
460     *(p)++ = (uint8_t)(u24);         \
461   }
462 #define UINT16_TO_BE_STREAM(p, u16) \
463   {                                 \
464     *(p)++ = (uint8_t)((u16) >> 8); \
465     *(p)++ = (uint8_t)(u16);        \
466   }
467 #define UINT8_TO_BE_STREAM(p, u8) \
468   { *(p)++ = (uint8_t)(u8); }
469 #define ARRAY_TO_BE_STREAM(p, a, len)                             \
470   {                                                               \
471     int ijk;                                                      \
472     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
473   }
474 #define ARRAY_TO_BE_STREAM_REVERSE(p, a, len)                               \
475   {                                                                         \
476     int ijk;                                                                \
477     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[(len)-ijk - 1]; \
478   }
479 
480 #define BE_STREAM_TO_UINT8(u8, p) \
481   {                               \
482     (u8) = (uint8_t)(*(p));       \
483     (p) += 1;                     \
484   }
485 #define BE_STREAM_TO_UINT16(u16, p)                                       \
486   {                                                                       \
487     (u16) = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); \
488     (p) += 2;                                                             \
489   }
490 #define BE_STREAM_TO_UINT24(u32, p)                                     \
491   {                                                                     \
492     (u32) = (((uint32_t)(*((p) + 2))) + ((uint32_t)(*((p) + 1)) << 8) + \
493              ((uint32_t)(*(p)) << 16));                                 \
494     (p) += 3;                                                           \
495   }
496 #define BE_STREAM_TO_UINT32(u32, p)                                      \
497   {                                                                      \
498     (u32) = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) +    \
499              ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); \
500     (p) += 4;                                                            \
501   }
502 #define BE_STREAM_TO_UINT64(u64, p)                                            \
503   {                                                                            \
504     (u64) = ((uint64_t)(*((p) + 7)) + ((uint64_t)(*((p) + 6)) << 8) +          \
505              ((uint64_t)(*((p) + 5)) << 16) + ((uint64_t)(*((p) + 4)) << 24) + \
506              ((uint64_t)(*((p) + 3)) << 32) + ((uint64_t)(*((p) + 2)) << 40) + \
507              ((uint64_t)(*((p) + 1)) << 48) + ((uint64_t)(*(p)) << 56));       \
508     (p) += 8;                                                                  \
509   }
510 #define BE_STREAM_TO_ARRAY(p, a, len)                                \
511   {                                                                  \
512     int ijk;                                                         \
513     for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \
514   }
515 
516 /*******************************************************************************
517  * Macros to get and put bytes to and from a field (Big Endian format).
518  * These are the same as to stream, except the pointer is not incremented.
519 */
520 #define UINT32_TO_BE_FIELD(p, u32)                 \
521   {                                                \
522     *(uint8_t*)(p) = (uint8_t)((u32) >> 24);       \
523     *((uint8_t*)(p) + 1) = (uint8_t)((u32) >> 16); \
524     *((uint8_t*)(p) + 2) = (uint8_t)((u32) >> 8);  \
525     *((uint8_t*)(p) + 3) = (uint8_t)(u32);         \
526   }
527 #define UINT24_TO_BE_FIELD(p, u24)                \
528   {                                               \
529     *(uint8_t*)(p) = (uint8_t)((u24) >> 16);      \
530     *((uint8_t*)(p) + 1) = (uint8_t)((u24) >> 8); \
531     *((uint8_t*)(p) + 2) = (uint8_t)(u24);        \
532   }
533 #define UINT16_TO_BE_FIELD(p, u16)          \
534   {                                         \
535     *(uint8_t*)(p) = (uint8_t)((u16) >> 8); \
536     *((uint8_t*)(p) + 1) = (uint8_t)(u16);  \
537   }
538 #define UINT8_TO_BE_FIELD(p, u8) \
539   { *(uint8_t*)(p) = (uint8_t)(u8); }
540 
541 /* Common Bluetooth field definitions */
542 #define BD_ADDR_LEN 6                 /* Device address length */
543 typedef uint8_t BD_ADDR[BD_ADDR_LEN]; /* Device address */
544 typedef uint8_t* BD_ADDR_PTR;         /* Pointer to Device Address */
545 
546 #define AMP_KEY_TYPE_GAMP 0
547 #define AMP_KEY_TYPE_WIFI 1
548 #define AMP_KEY_TYPE_UWB 2
549 typedef uint8_t tAMP_KEY_TYPE;
550 
551 #define BT_OCTET8_LEN 8
552 typedef uint8_t BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */
553 
554 #define LINK_KEY_LEN 16
555 typedef uint8_t LINK_KEY[LINK_KEY_LEN]; /* Link Key */
556 
557 #define AMP_LINK_KEY_LEN 32
558 typedef uint8_t
559     AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */
560 
561 #define BT_OCTET16_LEN 16
562 typedef uint8_t BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */
563 
564 #define PIN_CODE_LEN 16
565 typedef uint8_t PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */
566 typedef uint8_t* PIN_CODE_PTR;          /* Pointer to Pin Code */
567 
568 #define BT_OCTET32_LEN 32
569 typedef uint8_t BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */
570 
571 #define DEV_CLASS_LEN 3
572 typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */
573 typedef uint8_t* DEV_CLASS_PTR;           /* Pointer to Device class */
574 
575 #define EXT_INQ_RESP_LEN 3
576 typedef uint8_t EXT_INQ_RESP[EXT_INQ_RESP_LEN]; /* Extended Inquiry Response */
577 typedef uint8_t* EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */
578 
579 #define BD_NAME_LEN 248
580 typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */
581 typedef uint8_t* BD_NAME_PTR;             /* Pointer to Device name */
582 
583 #define BD_FEATURES_LEN 8
584 typedef uint8_t
585     BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */
586 
587 #define BT_EVENT_MASK_LEN 8
588 typedef uint8_t BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */
589 
590 #define LAP_LEN 3
591 typedef uint8_t LAP[LAP_LEN];     /* IAC as passed to Inquiry (LAP) */
592 typedef uint8_t INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */
593 
594 #define RAND_NUM_LEN 16
595 typedef uint8_t RAND_NUM[RAND_NUM_LEN];
596 
597 #define ACO_LEN 12
598 typedef uint8_t ACO[ACO_LEN]; /* Authenticated ciphering offset */
599 
600 #define COF_LEN 12
601 typedef uint8_t COF[COF_LEN]; /* ciphering offset number */
602 
603 typedef struct {
604   uint8_t qos_flags;          /* TBD */
605   uint8_t service_type;       /* see below */
606   uint32_t token_rate;        /* bytes/second */
607   uint32_t token_bucket_size; /* bytes */
608   uint32_t peak_bandwidth;    /* bytes/second */
609   uint32_t latency;           /* microseconds */
610   uint32_t delay_variation;   /* microseconds */
611 } FLOW_SPEC;
612 
613 /* Values for service_type */
614 #define NO_TRAFFIC 0
615 #define BEST_EFFORT 1
616 #define GUARANTEED 2
617 
618 /* Service class of the CoD */
619 #define SERV_CLASS_NETWORKING (1 << 1)
620 #define SERV_CLASS_RENDERING (1 << 2)
621 #define SERV_CLASS_CAPTURING (1 << 3)
622 #define SERV_CLASS_OBJECT_TRANSFER (1 << 4)
623 #define SERV_CLASS_OBJECT_AUDIO (1 << 5)
624 #define SERV_CLASS_OBJECT_TELEPHONY (1 << 6)
625 #define SERV_CLASS_OBJECT_INFORMATION (1 << 7)
626 
627 /* Second byte */
628 #define SERV_CLASS_LIMITED_DISC_MODE (0x20)
629 
630 /* Field size definitions. Note that byte lengths are rounded up. */
631 #define ACCESS_CODE_BIT_LEN 72
632 #define ACCESS_CODE_BYTE_LEN 9
633 #define SHORTENED_ACCESS_CODE_BIT_LEN 68
634 
635 typedef uint8_t ACCESS_CODE[ACCESS_CODE_BYTE_LEN];
636 
637 #define SYNTH_TX 1 /* want synth code to TRANSMIT at this freq */
638 #define SYNTH_RX 2 /* want synth code to RECEIVE at this freq */
639 
640 #define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */
641 
642 #define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */
643 
644 /* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */
645 #define MAX_UUID_SIZE 16
646 typedef struct {
647 #define LEN_UUID_16 2
648 #define LEN_UUID_32 4
649 #define LEN_UUID_128 16
650 
651   uint16_t len;
652 
653   union {
654     uint16_t uuid16;
655     uint32_t uuid32;
656     uint8_t uuid128[MAX_UUID_SIZE];
657   } uu;
658 
659 } tBT_UUID;
660 
661 #define BT_EIR_FLAGS_TYPE 0x01
662 #define BT_EIR_MORE_16BITS_UUID_TYPE 0x02
663 #define BT_EIR_COMPLETE_16BITS_UUID_TYPE 0x03
664 #define BT_EIR_MORE_32BITS_UUID_TYPE 0x04
665 #define BT_EIR_COMPLETE_32BITS_UUID_TYPE 0x05
666 #define BT_EIR_MORE_128BITS_UUID_TYPE 0x06
667 #define BT_EIR_COMPLETE_128BITS_UUID_TYPE 0x07
668 #define BT_EIR_SHORTENED_LOCAL_NAME_TYPE 0x08
669 #define BT_EIR_COMPLETE_LOCAL_NAME_TYPE 0x09
670 #define BT_EIR_TX_POWER_LEVEL_TYPE 0x0A
671 #define BT_EIR_OOB_BD_ADDR_TYPE 0x0C
672 #define BT_EIR_OOB_COD_TYPE 0x0D
673 #define BT_EIR_OOB_SSP_HASH_C_TYPE 0x0E
674 #define BT_EIR_OOB_SSP_RAND_R_TYPE 0x0F
675 #define BT_EIR_SERVICE_DATA_TYPE 0x16
676 #define BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE 0x16
677 #define BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE 0x20
678 #define BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE 0x21
679 #define BT_EIR_MANUFACTURER_SPECIFIC_TYPE 0xFF
680 
681 #define BT_OOB_COD_SIZE 3
682 #define BT_OOB_HASH_C_SIZE 16
683 #define BT_OOB_RAND_R_SIZE 16
684 
685 /* Broadcom proprietary UUIDs and reserved PSMs
686  *
687  * The lowest 4 bytes byte of the UUID or GUID depend on the feature. Typically,
688  * the value of those bytes will be the PSM or SCN.
689 */
690 #define BRCM_PROPRIETARY_UUID_BASE \
691   0xDA, 0x23, 0x41, 0x02, 0xA3, 0xBB, 0xC1, 0x71, 0xBA, 0x09, 0x6f, 0x21
692 #define BRCM_PROPRIETARY_GUID_BASE \
693   0xda23, 0x4102, 0xa3, 0xbb, 0xc1, 0x71, 0xba, 0x09, 0x6f, 0x21
694 
695 /* We will not allocate a PSM in the reserved range to 3rd party apps
696 */
697 #define BRCM_RESERVED_PSM_START 0x5AE1
698 #define BRCM_RESERVED_PSM_END 0x5AFF
699 
700 #define BRCM_UTILITY_SERVICE_PSM 0x5AE1
701 #define BRCM_MATCHER_PSM 0x5AE3
702 
703 /* Connection statistics
704 */
705 
706 /* Structure to hold connection stats */
707 #ifndef BT_CONN_STATS_DEFINED
708 #define BT_CONN_STATS_DEFINED
709 
710 /* These bits are used in the bIsConnected field */
711 #define BT_CONNECTED_USING_BREDR 1
712 #define BT_CONNECTED_USING_AMP 2
713 
714 typedef struct {
715   uint32_t is_connected;
716   int32_t rssi;
717   uint32_t bytes_sent;
718   uint32_t bytes_rcvd;
719   uint32_t duration;
720 } tBT_CONN_STATS;
721 
722 #endif
723 
724 /*****************************************************************************
725  *                          Low Energy definitions
726  *
727  * Address types
728 */
729 #define BLE_ADDR_PUBLIC 0x00
730 #define BLE_ADDR_RANDOM 0x01
731 #define BLE_ADDR_PUBLIC_ID 0x02
732 #define BLE_ADDR_RANDOM_ID 0x03
733 typedef uint8_t tBLE_ADDR_TYPE;
734 #define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC)
735 
736 #define BT_TRANSPORT_INVALID 0
737 #define BT_TRANSPORT_BR_EDR 1
738 #define BT_TRANSPORT_LE 2
739 typedef uint8_t tBT_TRANSPORT;
740 
741 #define PHY_LE_1M_MASK 1
742 #define PHY_LE_2M_MASK 2
743 #define PHY_LE_CODED_MASK 4
744 
745 #define BLE_ADDR_IS_STATIC(x) (((x)[0] & 0xC0) == 0xC0)
746 
747 typedef struct {
748   tBLE_ADDR_TYPE type;
749   BD_ADDR bda;
750 } tBLE_BD_ADDR;
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_GAP 0x000e0000
802 #define TRACE_LAYER_ICP 0x00110000
803 #define TRACE_LAYER_HSP2 0x00120000
804 #define TRACE_LAYER_SPP 0x00130000
805 #define TRACE_LAYER_CTP 0x00140000
806 #define TRACE_LAYER_BPP 0x00150000
807 #define TRACE_LAYER_HCRP 0x00160000
808 #define TRACE_LAYER_FTP 0x00170000
809 #define TRACE_LAYER_OPP 0x00180000
810 #define TRACE_LAYER_BTU 0x00190000
811 #define TRACE_LAYER_GKI 0x001a0000 /* OBSOLETED */
812 #define TRACE_LAYER_BNEP 0x001b0000
813 #define TRACE_LAYER_PAN 0x001c0000
814 #define TRACE_LAYER_HFP 0x001d0000
815 #define TRACE_LAYER_HID 0x001e0000
816 #define TRACE_LAYER_BIP 0x001f0000
817 #define TRACE_LAYER_AVP 0x00200000
818 #define TRACE_LAYER_A2DP 0x00210000
819 #define TRACE_LAYER_SAP 0x00220000
820 #define TRACE_LAYER_AMP 0x00230000
821 #define TRACE_LAYER_MCA 0x00240000
822 #define TRACE_LAYER_ATT 0x00250000
823 #define TRACE_LAYER_SMP 0x00260000
824 #define TRACE_LAYER_NFC 0x00270000
825 #define TRACE_LAYER_NCI 0x00280000
826 #define TRACE_LAYER_LLCP 0x00290000
827 #define TRACE_LAYER_NDEF 0x002a0000
828 #define TRACE_LAYER_RW 0x002b0000
829 #define TRACE_LAYER_CE 0x002c0000
830 #define TRACE_LAYER_P2P 0x002d0000
831 #define TRACE_LAYER_SNEP 0x002e0000
832 #define TRACE_LAYER_CHO 0x002f0000
833 #define TRACE_LAYER_NFA 0x00300000
834 
835 #define TRACE_LAYER_MAX_NUM 0x0031
836 
837 /* TRACE_ORIGINATOR                 0x0000^^00*/
838 #define TRACE_ORG_MASK 0x0000ff00
839 #define TRACE_GET_ORG(x) ((((uint32_t)(x)) & TRACE_ORG_MASK) >> 8)
840 
841 #define TRACE_ORG_STACK 0x00000000
842 #define TRACE_ORG_HCI_TRANS 0x00000100
843 #define TRACE_ORG_PROTO_DISP 0x00000200
844 #define TRACE_ORG_RPC 0x00000300
845 #define TRACE_ORG_GKI 0x00000400 /* OBSOLETED */
846 #define TRACE_ORG_APPL 0x00000500
847 #define TRACE_ORG_SCR_WRAPPER 0x00000600
848 #define TRACE_ORG_SCR_ENGINE 0x00000700
849 #define TRACE_ORG_USER_SCR 0x00000800
850 #define TRACE_ORG_TESTER 0x00000900
851 #define TRACE_ORG_MAX_NUM 10 /* 32-bit mask; must be < 32 */
852 #define TRACE_LITE_ORG_MAX_NUM 6
853 #define TRACE_ORG_ALL 0x03ff
854 #define TRACE_ORG_RPC_TRANS 0x04
855 
856 #define TRACE_ORG_REG 0x00000909
857 #define TRACE_ORG_REG_SUCCESS 0x0000090a
858 
859 /* TRACE_TYPE                       0x000000^^*/
860 #define TRACE_TYPE_MASK 0x000000ff
861 #define TRACE_GET_TYPE(x) (((uint32_t)(x)) & TRACE_TYPE_MASK)
862 
863 #define TRACE_TYPE_ERROR 0x00000000
864 #define TRACE_TYPE_WARNING 0x00000001
865 #define TRACE_TYPE_API 0x00000002
866 #define TRACE_TYPE_EVENT 0x00000003
867 #define TRACE_TYPE_DEBUG 0x00000004
868 #define TRACE_TYPE_STACK_ONLY_MAX TRACE_TYPE_DEBUG
869 #define TRACE_TYPE_TX 0x00000005
870 #define TRACE_TYPE_RX 0x00000006
871 #define TRACE_TYPE_DEBUG_ASSERT 0x00000007
872 #define TRACE_TYPE_GENERIC 0x00000008
873 #define TRACE_TYPE_REG 0x00000009
874 #define TRACE_TYPE_REG_SUCCESS 0x0000000a
875 #define TRACE_TYPE_CMD_TX 0x0000000b
876 #define TRACE_TYPE_EVT_TX 0x0000000c
877 #define TRACE_TYPE_ACL_TX 0x0000000d
878 #define TRACE_TYPE_CMD_RX 0x0000000e
879 #define TRACE_TYPE_EVT_RX 0x0000000f
880 #define TRACE_TYPE_ACL_RX 0x00000010
881 #define TRACE_TYPE_TARGET_TRACE 0x00000011
882 #define TRACE_TYPE_SCO_TX 0x00000012
883 #define TRACE_TYPE_SCO_RX 0x00000013
884 
885 #define TRACE_TYPE_MAX_NUM 20
886 #define TRACE_TYPE_ALL 0xffff
887 
888 /* Define color for script type */
889 #define SCR_COLOR_DEFAULT 0
890 #define SCR_COLOR_TYPE_COMMENT 1
891 #define SCR_COLOR_TYPE_COMMAND 2
892 #define SCR_COLOR_TYPE_EVENT 3
893 #define SCR_COLOR_TYPE_SELECT 4
894 
895 /* Define protocol trace flag values */
896 #define SCR_PROTO_TRACE_HCI_SUMMARY 0x00000001
897 #define SCR_PROTO_TRACE_HCI_DATA 0x00000002
898 #define SCR_PROTO_TRACE_L2CAP 0x00000004
899 #define SCR_PROTO_TRACE_RFCOMM 0x00000008
900 #define SCR_PROTO_TRACE_SDP 0x00000010
901 #define SCR_PROTO_TRACE_TCS 0x00000020
902 #define SCR_PROTO_TRACE_OBEX 0x00000040
903 #define SCR_PROTO_TRACE_OAPP 0x00000080 /* OBEX Application Profile */
904 #define SCR_PROTO_TRACE_AMP 0x00000100
905 #define SCR_PROTO_TRACE_BNEP 0x00000200
906 #define SCR_PROTO_TRACE_AVP 0x00000400
907 #define SCR_PROTO_TRACE_MCA 0x00000800
908 #define SCR_PROTO_TRACE_ATT 0x00001000
909 #define SCR_PROTO_TRACE_SMP 0x00002000
910 #define SCR_PROTO_TRACE_NCI 0x00004000
911 #define SCR_PROTO_TRACE_LLCP 0x00008000
912 #define SCR_PROTO_TRACE_NDEF 0x00010000
913 #define SCR_PROTO_TRACE_RW 0x00020000
914 #define SCR_PROTO_TRACE_CE 0x00040000
915 #define SCR_PROTO_TRACE_SNEP 0x00080000
916 #define SCR_PROTO_TRACE_CHO 0x00100000
917 #define SCR_PROTO_TRACE_ALL 0x001fffff
918 #define SCR_PROTO_TRACE_HCI_LOGGING_VSE \
919   0x0800 /* Brcm vs event for logmsg and protocol traces */
920 
921 #define MAX_SCRIPT_TYPE 5
922 
923 #define TCS_PSM_INTERCOM 5
924 #define TCS_PSM_CORDLESS 7
925 #define BT_PSM_BNEP 0x000F
926 /* Define PSMs HID uses */
927 #define HID_PSM_CONTROL 0x0011
928 #define HID_PSM_INTERRUPT 0x0013
929 
930 /* Define a function for logging */
931 typedef void(BT_LOG_FUNC)(int trace_type, const char* fmt_str, ...);
932 
933 /* bd addr length and type */
934 #ifndef BD_ADDR_LEN
935 #define BD_ADDR_LEN 6
936 typedef uint8_t BD_ADDR[BD_ADDR_LEN];
937 #endif
938 
939 // From bd.c
940 
941 /*****************************************************************************
942  *  Constants
943  ****************************************************************************/
944 
945 /* global constant for "any" bd addr */
946 static const BD_ADDR bd_addr_any = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
947 static const BD_ADDR bd_addr_null = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
948 
949 /*****************************************************************************
950  *  Functions
951  ****************************************************************************/
952 
953 /*******************************************************************************
954  *
955  * Function         bdcpy
956  *
957  * Description      Copy bd addr b to a.
958  *
959  *
960  * Returns          void
961  *
962  ******************************************************************************/
bdcpy(BD_ADDR a,const BD_ADDR b)963 static inline void bdcpy(BD_ADDR a, const BD_ADDR b) {
964   int i;
965 
966   for (i = BD_ADDR_LEN; i != 0; i--) {
967     *a++ = *b++;
968   }
969 }
970 
971 /*******************************************************************************
972  *
973  * Function         bdcmp
974  *
975  * Description      Compare bd addr b to a.
976  *
977  *
978  * Returns          Zero if b==a, nonzero otherwise (like memcmp).
979  *
980  ******************************************************************************/
bdcmp(const BD_ADDR a,const BD_ADDR b)981 static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) {
982   int i;
983 
984   for (i = BD_ADDR_LEN; i != 0; i--) {
985     if (*a++ != *b++) {
986       return -1;
987     }
988   }
989   return 0;
990 }
991 
992 /*******************************************************************************
993  *
994  * Function         bdcmpany
995  *
996  * Description      Compare bd addr to "any" bd addr.
997  *
998  *
999  * Returns          Zero if a equals bd_addr_any.
1000  *
1001  ******************************************************************************/
bdcmpany(const BD_ADDR a)1002 static inline int bdcmpany(const BD_ADDR a) { return bdcmp(a, bd_addr_any); }
1003 
1004 /*******************************************************************************
1005  *
1006  * Function         bdsetany
1007  *
1008  * Description      Set bd addr to "any" bd addr.
1009  *
1010  *
1011  * Returns          void
1012  *
1013  ******************************************************************************/
bdsetany(BD_ADDR a)1014 static inline void bdsetany(BD_ADDR a) { bdcpy(a, bd_addr_any); }
1015 #endif
1016