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