blob: da0baac406e5f3398b39fa5621ca5db9638abf1d [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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
Chris Manton83e2c342014-09-29 21:37:44 -070022#include <stdbool.h>
Myles Watson911d1ae2016-11-28 16:44:40 -080023#include <stdint.h>
Chris Manton83e2c342014-09-29 21:37:44 -070024
25#ifndef FALSE
Myles Watson911d1ae2016-11-28 16:44:40 -080026#define FALSE false
Chris Manton83e2c342014-09-29 21:37:44 -070027#endif
28
29#ifndef TRUE
Myles Watson911d1ae2016-11-28 16:44:40 -080030#define TRUE true
Chris Manton83e2c342014-09-29 21:37:44 -070031#endif
32
Chris Manton83e2c342014-09-29 21:37:44 -070033#ifdef __arm
Myles Watson911d1ae2016-11-28 16:44:40 -080034#define PACKED __packed
35#define INLINE __inline
Chris Manton83e2c342014-09-29 21:37:44 -070036#else
Myles Watson911d1ae2016-11-28 16:44:40 -080037#define PACKED
38#define INLINE
Chris Manton83e2c342014-09-29 21:37:44 -070039#endif
40
The Android Open Source Project5738f832012-12-12 16:00:35 -080041/* READ WELL !!
Myles Watsonee96a3c2016-11-23 14:49:54 -080042 *
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.
The Android Open Source Project5738f832012-12-12 16:00:35 -080050*/
Myles Watson911d1ae2016-11-28 16:44:40 -080051#define BT_EVT_MASK 0xFF00
52#define BT_SUB_EVT_MASK 0x00FF
Myles Watson9ca07092016-11-28 16:41:53 -080053/* To Bluetooth Upper Layers */
54/************************************/
55/* L2CAP event */
Myles Watson911d1ae2016-11-28 16:44:40 -080056#define BT_EVT_TO_BTU_L2C_EVT 0x0900
Myles Watson9ca07092016-11-28 16:41:53 -080057/* HCI Event */
Myles Watson911d1ae2016-11-28 16:44:40 -080058#define BT_EVT_TO_BTU_HCI_EVT 0x1000
Myles Watson9ca07092016-11-28 16:41:53 -080059/* 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 */
Myles Watson911d1ae2016-11-28 16:44:40 -080062#define BT_EVT_TO_BTU_HCI_AMP1_EVT (0x0001 | BT_EVT_TO_BTU_HCI_EVT)
Myles Watson9ca07092016-11-28 16:41:53 -080063/* event from local AMP 2 controller */
Myles Watson911d1ae2016-11-28 16:44:40 -080064#define BT_EVT_TO_BTU_HCI_AMP2_EVT (0x0002 | BT_EVT_TO_BTU_HCI_EVT)
Myles Watson9ca07092016-11-28 16:41:53 -080065/* event from local AMP 3 controller */
Myles Watson911d1ae2016-11-28 16:44:40 -080066#define BT_EVT_TO_BTU_HCI_AMP3_EVT (0x0003 | BT_EVT_TO_BTU_HCI_EVT)
The Android Open Source Project5738f832012-12-12 16:00:35 -080067
Myles Watson9ca07092016-11-28 16:41:53 -080068/* ACL Data from HCI */
Myles Watson911d1ae2016-11-28 16:44:40 -080069#define BT_EVT_TO_BTU_HCI_ACL 0x1100
Myles Watson9ca07092016-11-28 16:41:53 -080070/* SCO Data from HCI */
Myles Watson911d1ae2016-11-28 16:44:40 -080071#define BT_EVT_TO_BTU_HCI_SCO 0x1200
Myles Watson9ca07092016-11-28 16:41:53 -080072/* HCI Transport Error */
Myles Watson911d1ae2016-11-28 16:44:40 -080073#define BT_EVT_TO_BTU_HCIT_ERR 0x1300
The Android Open Source Project5738f832012-12-12 16:00:35 -080074
Myles Watson9ca07092016-11-28 16:41:53 -080075/* Serial Port Event */
Myles Watson911d1ae2016-11-28 16:44:40 -080076#define BT_EVT_TO_BTU_SP_EVT 0x1400
Myles Watson9ca07092016-11-28 16:41:53 -080077/* Serial Port Data */
Myles Watson911d1ae2016-11-28 16:44:40 -080078#define BT_EVT_TO_BTU_SP_DATA 0x1500
The Android Open Source Project5738f832012-12-12 16:00:35 -080079
Myles Watson9ca07092016-11-28 16:41:53 -080080/* HCI command from upper layer */
Myles Watson911d1ae2016-11-28 16:44:40 -080081#define BT_EVT_TO_BTU_HCI_CMD 0x1600
The Android Open Source Project5738f832012-12-12 16:00:35 -080082
Myles Watson9ca07092016-11-28 16:41:53 -080083/* L2CAP segment(s) transmitted */
Myles Watson911d1ae2016-11-28 16:44:40 -080084#define BT_EVT_TO_BTU_L2C_SEG_XMIT 0x1900
The Android Open Source Project5738f832012-12-12 16:00:35 -080085
Myles Watson9ca07092016-11-28 16:41:53 -080086/* BlueStackTester event: incoming message from target */
Myles Watson911d1ae2016-11-28 16:44:40 -080087#define BT_EVT_PROXY_INCOMING_MSG 0x1A00
The Android Open Source Project5738f832012-12-12 16:00:35 -080088
Myles Watson9ca07092016-11-28 16:41:53 -080089/* Insight BTSIM event */
Myles Watson911d1ae2016-11-28 16:44:40 -080090#define BT_EVT_BTSIM 0x1B00
Myles Watson9ca07092016-11-28 16:41:53 -080091/* Insight Script Engine event */
Myles Watson911d1ae2016-11-28 16:44:40 -080092#define BT_EVT_BTISE 0x1C00
The Android Open Source Project5738f832012-12-12 16:00:35 -080093
Myles Watson9ca07092016-11-28 16:41:53 -080094/* To LM */
95/************************************/
96/* HCI Command */
Myles Watson911d1ae2016-11-28 16:44:40 -080097#define BT_EVT_TO_LM_HCI_CMD 0x2000
Myles Watson9ca07092016-11-28 16:41:53 -080098/* HCI ACL Data */
Myles Watson911d1ae2016-11-28 16:44:40 -080099#define BT_EVT_TO_LM_HCI_ACL 0x2100
Myles Watson9ca07092016-11-28 16:41:53 -0800100/* HCI SCO Data */
Myles Watson911d1ae2016-11-28 16:44:40 -0800101#define BT_EVT_TO_LM_HCI_SCO 0x2200
Myles Watson9ca07092016-11-28 16:41:53 -0800102/* HCI Transport Error */
Myles Watson911d1ae2016-11-28 16:44:40 -0800103#define BT_EVT_TO_LM_HCIT_ERR 0x2300
Myles Watson9ca07092016-11-28 16:41:53 -0800104/* LC event */
Myles Watson911d1ae2016-11-28 16:44:40 -0800105#define BT_EVT_TO_LM_LC_EVT 0x2400
Myles Watson9ca07092016-11-28 16:41:53 -0800106/* LC Received LMP command frame */
Myles Watson911d1ae2016-11-28 16:44:40 -0800107#define BT_EVT_TO_LM_LC_LMP 0x2500
Myles Watson9ca07092016-11-28 16:41:53 -0800108/* LC Received ACL data */
Myles Watson911d1ae2016-11-28 16:44:40 -0800109#define BT_EVT_TO_LM_LC_ACL 0x2600
Myles Watson9ca07092016-11-28 16:41:53 -0800110/* LC Received SCO data (not used) */
Myles Watson911d1ae2016-11-28 16:44:40 -0800111#define BT_EVT_TO_LM_LC_SCO 0x2700
Myles Watson9ca07092016-11-28 16:41:53 -0800112/* LMP data transmit complete */
Myles Watson911d1ae2016-11-28 16:44:40 -0800113#define BT_EVT_TO_LM_LC_ACL_TX 0x2800
Myles Watson9ca07092016-11-28 16:41:53 -0800114/* LMP Command transmit complete */
Myles Watson911d1ae2016-11-28 16:44:40 -0800115#define BT_EVT_TO_LM_LC_LMPC_TX 0x2900
Myles Watson9ca07092016-11-28 16:41:53 -0800116/* Data to be locally loopbacked */
Myles Watson911d1ae2016-11-28 16:44:40 -0800117#define BT_EVT_TO_LM_LOCAL_ACL_LB 0x2a00
Myles Watson9ca07092016-11-28 16:41:53 -0800118/* HCI ACL Data ack (not used) */
Myles Watson911d1ae2016-11-28 16:44:40 -0800119#define BT_EVT_TO_LM_HCI_ACL_ACK 0x2b00
Myles Watson9ca07092016-11-28 16:41:53 -0800120/* LM Diagnostics commands */
Myles Watson911d1ae2016-11-28 16:44:40 -0800121#define BT_EVT_TO_LM_DIAG 0x2c00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800122
Myles Watson911d1ae2016-11-28 16:44:40 -0800123#define BT_EVT_TO_BTM_CMDS 0x2f00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800124#define BT_EVT_TO_BTM_PM_MDCHG_EVT (0x0001 | BT_EVT_TO_BTM_CMDS)
125
Myles Watson911d1ae2016-11-28 16:44:40 -0800126#define BT_EVT_TO_TCS_CMDS 0x3000
The Android Open Source Project5738f832012-12-12 16:00:35 -0800127
Myles Watson911d1ae2016-11-28 16:44:40 -0800128#define BT_EVT_TO_CTP_CMDS 0x3300
The Android Open Source Project5738f832012-12-12 16:00:35 -0800129
The Android Open Source Project5738f832012-12-12 16:00:35 -0800130/* ftp events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800131#define BT_EVT_TO_FTP_SRVR_CMDS 0x3600
132#define BT_EVT_TO_FTP_CLNT_CMDS 0x3700
The Android Open Source Project5738f832012-12-12 16:00:35 -0800133
Myles Watson9ca07092016-11-28 16:41:53 -0800134/* SIM Access Profile events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800135#define BT_EVT_TO_BTU_SAP 0x3800
The Android Open Source Project5738f832012-12-12 16:00:35 -0800136
137/* opp events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800138#define BT_EVT_TO_OPP_SRVR_CMDS 0x3900
139#define BT_EVT_TO_OPP_CLNT_CMDS 0x3a00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800140
141/* gap events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800142#define BT_EVT_TO_GAP_MSG 0x3b00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800143
The Android Open Source Project5738f832012-12-12 16:00:35 -0800144/* for NFC */
Myles Watson9ca07092016-11-28 16:41:53 -0800145/************************************/
146/* NCI Command, Notification or Data*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800147#define BT_EVT_TO_NFC_NCI 0x4000
Myles Watson9ca07092016-11-28 16:41:53 -0800148/* Initialization message */
Myles Watson911d1ae2016-11-28 16:44:40 -0800149#define BT_EVT_TO_NFC_INIT 0x4100
Myles Watson9ca07092016-11-28 16:41:53 -0800150/* Low power */
Myles Watson911d1ae2016-11-28 16:44:40 -0800151#define BT_EVT_TO_NCI_LP 0x4200
Myles Watson9ca07092016-11-28 16:41:53 -0800152/* Error notification to NFC Task */
Myles Watson911d1ae2016-11-28 16:44:40 -0800153#define BT_EVT_TO_NFC_ERR 0x4300
The Android Open Source Project5738f832012-12-12 16:00:35 -0800154
Myles Watson9ca07092016-11-28 16:41:53 -0800155/* events to NFCC simulation (NCI packets) */
Myles Watson911d1ae2016-11-28 16:44:40 -0800156#define BT_EVT_TO_NFCCSIM_NCI 0x4a00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800157
158/* HCISU Events */
159
Myles Watson911d1ae2016-11-28 16:44:40 -0800160#define BT_EVT_HCISU 0x5000
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161
Myles Watson911d1ae2016-11-28 16:44:40 -0800162#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)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800172
Myles Watson911d1ae2016-11-28 16:44:40 -0800173#define BT_EVT_DATA_TO_AMP_1 0x5100
174#define BT_EVT_DATA_TO_AMP_15 0x5f00
The Android Open Source Project5738f832012-12-12 16:00:35 -0800175
176/* HSP Events */
177
Myles Watson911d1ae2016-11-28 16:44:40 -0800178#define BT_EVT_BTU_HSP2 0x6000
The Android Open Source Project5738f832012-12-12 16:00:35 -0800179
Myles Watson911d1ae2016-11-28 16:44:40 -0800180#define BT_EVT_TO_BTU_HSP2_EVT (0x0001 | BT_EVT_BTU_HSP2)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800181
182/* BPP Events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800183#define BT_EVT_TO_BPP_PR_CMDS 0x6100 /* Printer Events */
184#define BT_EVT_TO_BPP_SND_CMDS 0x6200 /* BPP Sender Events */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800185
186/* BIP Events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800187#define BT_EVT_TO_BIP_CMDS 0x6300
The Android Open Source Project5738f832012-12-12 16:00:35 -0800188
189/* HCRP Events */
190
Myles Watson911d1ae2016-11-28 16:44:40 -0800191#define BT_EVT_BTU_HCRP 0x7000
The Android Open Source Project5738f832012-12-12 16:00:35 -0800192
Myles Watson911d1ae2016-11-28 16:44:40 -0800193#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)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800195
Myles Watson911d1ae2016-11-28 16:44:40 -0800196#define BT_EVT_BTU_HFP 0x8000
197#define BT_EVT_TO_BTU_HFP_EVT (0x0001 | BT_EVT_BTU_HFP)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198
Myles Watson911d1ae2016-11-28 16:44:40 -0800199#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)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204#define BT_EVT_BTU_IPC_L2C_MSG_EVT (0x0004 | BT_EVT_BTU_IPC_EVT)
Myles Watson911d1ae2016-11-28 16:44:40 -0800205#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)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211
212/* BTIF Events */
Myles Watson911d1ae2016-11-28 16:44:40 -0800213#define BT_EVT_BTIF 0xA000
214#define BT_EVT_CONTEXT_SWITCH_EVT (0x0001 | BT_EVT_BTIF)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800215
The Android Open Source Project5738f832012-12-12 16:00:35 -0800216/* Define the header of each buffer used in the Bluetooth stack.
217*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800218typedef struct {
219 uint16_t event;
220 uint16_t len;
221 uint16_t offset;
222 uint16_t layer_specific;
223 uint8_t data[];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800224} BT_HDR;
225
Myles Watson911d1ae2016-11-28 16:44:40 -0800226#define BT_HDR_SIZE (sizeof(BT_HDR))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800227
Myles Watson911d1ae2016-11-28 16:44:40 -0800228#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 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800242
The Android Open Source Project5738f832012-12-12 16:00:35 -0800243/* These macros extract the HCI opcodes from a buffer
244*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800245#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))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250
Myles Watson911d1ae2016-11-28 16:44:40 -0800251#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))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800255
Myles Watsonee96a3c2016-11-23 14:49:54 -0800256/*******************************************************************************
257 * Macros to get and put bytes to and from a stream (Little Endian format).
The Android Open Source Project5738f832012-12-12 16:00:35 -0800258*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800259#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 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800335
Jakub Pawlowski9e300562016-12-07 10:54:44 -0800336#define STREAM_TO_INT8(u8, p) \
337 { \
338 (u8) = (*((int8_t*)p)); \
339 (p) += 1; \
340 }
Myles Watson911d1ae2016-11-28 16:44:40 -0800341#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 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800411
Myles Watson911d1ae2016-11-28 16:44:40 -0800412#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)
Zach Johnsone81e99f2014-08-15 16:46:59 -0700420
Myles Watsonee96a3c2016-11-23 14:49:54 -0800421/*******************************************************************************
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.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800424*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800425#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); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800445
Myles Watsonee96a3c2016-11-23 14:49:54 -0800446/*******************************************************************************
447 * Macros to get and put bytes to and from a stream (Big Endian format)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800448*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800449#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 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800479
Myles Watson911d1ae2016-11-28 16:44:40 -0800480#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 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800515
Myles Watsonee96a3c2016-11-23 14:49:54 -0800516/*******************************************************************************
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.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800519*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800520#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); }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800540
541/* Common Bluetooth field definitions */
Myles Watson911d1ae2016-11-28 16:44:40 -0800542#define BD_ADDR_LEN 6 /* Device address length */
543typedef uint8_t BD_ADDR[BD_ADDR_LEN]; /* Device address */
544typedef uint8_t* BD_ADDR_PTR; /* Pointer to Device Address */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800545
Myles Watson911d1ae2016-11-28 16:44:40 -0800546#define AMP_KEY_TYPE_GAMP 0
547#define AMP_KEY_TYPE_WIFI 1
548#define AMP_KEY_TYPE_UWB 2
Marie Janssend19e0782016-07-15 12:48:27 -0700549typedef uint8_t tAMP_KEY_TYPE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800550
Myles Watson911d1ae2016-11-28 16:44:40 -0800551#define BT_OCTET8_LEN 8
552typedef uint8_t BT_OCTET8[BT_OCTET8_LEN]; /* octet array: size 16 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800553
Myles Watson911d1ae2016-11-28 16:44:40 -0800554#define LINK_KEY_LEN 16
555typedef uint8_t LINK_KEY[LINK_KEY_LEN]; /* Link Key */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800556
Myles Watson911d1ae2016-11-28 16:44:40 -0800557#define AMP_LINK_KEY_LEN 32
558typedef uint8_t
559 AMP_LINK_KEY[AMP_LINK_KEY_LEN]; /* Dedicated AMP and GAMP Link Keys */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800560
Myles Watson911d1ae2016-11-28 16:44:40 -0800561#define BT_OCTET16_LEN 16
562typedef uint8_t BT_OCTET16[BT_OCTET16_LEN]; /* octet array: size 16 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800563
Myles Watson911d1ae2016-11-28 16:44:40 -0800564#define PIN_CODE_LEN 16
565typedef uint8_t PIN_CODE[PIN_CODE_LEN]; /* Pin Code (upto 128 bits) MSB is 0 */
566typedef uint8_t* PIN_CODE_PTR; /* Pointer to Pin Code */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800567
Myles Watson911d1ae2016-11-28 16:44:40 -0800568#define BT_OCTET32_LEN 32
569typedef uint8_t BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */
Satya Calloji444a8da2015-03-06 10:38:22 -0800570
Myles Watson911d1ae2016-11-28 16:44:40 -0800571#define DEV_CLASS_LEN 3
572typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */
573typedef uint8_t* DEV_CLASS_PTR; /* Pointer to Device class */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800574
Myles Watson911d1ae2016-11-28 16:44:40 -0800575#define EXT_INQ_RESP_LEN 3
576typedef uint8_t EXT_INQ_RESP[EXT_INQ_RESP_LEN]; /* Extended Inquiry Response */
577typedef uint8_t* EXT_INQ_RESP_PTR; /* Pointer to Extended Inquiry Response */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800578
Myles Watson911d1ae2016-11-28 16:44:40 -0800579#define BD_NAME_LEN 248
580typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */
581typedef uint8_t* BD_NAME_PTR; /* Pointer to Device name */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800582
583#define BD_FEATURES_LEN 8
Myles Watson911d1ae2016-11-28 16:44:40 -0800584typedef uint8_t
585 BD_FEATURES[BD_FEATURES_LEN]; /* LMP features supported by device */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800586
Myles Watson911d1ae2016-11-28 16:44:40 -0800587#define BT_EVENT_MASK_LEN 8
588typedef uint8_t BT_EVENT_MASK[BT_EVENT_MASK_LEN]; /* Event Mask */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800589
Myles Watson911d1ae2016-11-28 16:44:40 -0800590#define LAP_LEN 3
591typedef uint8_t LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */
592typedef uint8_t INQ_LAP[LAP_LEN]; /* IAC as passed to Inquiry (LAP) */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800593
Myles Watson911d1ae2016-11-28 16:44:40 -0800594#define RAND_NUM_LEN 16
Marie Janssend19e0782016-07-15 12:48:27 -0700595typedef uint8_t RAND_NUM[RAND_NUM_LEN];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800596
Myles Watson911d1ae2016-11-28 16:44:40 -0800597#define ACO_LEN 12
598typedef uint8_t ACO[ACO_LEN]; /* Authenticated ciphering offset */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800599
Myles Watson911d1ae2016-11-28 16:44:40 -0800600#define COF_LEN 12
601typedef uint8_t COF[COF_LEN]; /* ciphering offset number */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800602
603typedef struct {
Myles Watson911d1ae2016-11-28 16:44:40 -0800604 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 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800611} FLOW_SPEC;
612
613/* Values for service_type */
Myles Watson911d1ae2016-11-28 16:44:40 -0800614#define NO_TRAFFIC 0
615#define BEST_EFFORT 1
616#define GUARANTEED 2
The Android Open Source Project5738f832012-12-12 16:00:35 -0800617
618/* Service class of the CoD */
Myles Watson911d1ae2016-11-28 16:44:40 -0800619#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)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800626
627/* Second byte */
Myles Watson911d1ae2016-11-28 16:44:40 -0800628#define SERV_CLASS_LIMITED_DISC_MODE (0x20)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800629
630/* Field size definitions. Note that byte lengths are rounded up. */
Myles Watson911d1ae2016-11-28 16:44:40 -0800631#define ACCESS_CODE_BIT_LEN 72
632#define ACCESS_CODE_BYTE_LEN 9
633#define SHORTENED_ACCESS_CODE_BIT_LEN 68
The Android Open Source Project5738f832012-12-12 16:00:35 -0800634
Marie Janssend19e0782016-07-15 12:48:27 -0700635typedef uint8_t ACCESS_CODE[ACCESS_CODE_BYTE_LEN];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800636
Myles Watson911d1ae2016-11-28 16:44:40 -0800637#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 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800639
Myles Watson911d1ae2016-11-28 16:44:40 -0800640#define SYNC_REPS 1 /* repeats of sync word transmitted to start of burst */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800641
Myles Watson911d1ae2016-11-28 16:44:40 -0800642#define BT_1SEC_TIMEOUT_MS (1 * 1000) /* 1 second */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800643
644/* Maximum UUID size - 16 bytes, and structure to hold any type of UUID. */
Myles Watson911d1ae2016-11-28 16:44:40 -0800645#define MAX_UUID_SIZE 16
646typedef struct {
647#define LEN_UUID_16 2
648#define LEN_UUID_32 4
649#define LEN_UUID_128 16
The Android Open Source Project5738f832012-12-12 16:00:35 -0800650
Myles Watson911d1ae2016-11-28 16:44:40 -0800651 uint16_t len;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800652
Myles Watson911d1ae2016-11-28 16:44:40 -0800653 union {
654 uint16_t uuid16;
655 uint32_t uuid32;
656 uint8_t uuid128[MAX_UUID_SIZE];
657 } uu;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800658
659} tBT_UUID;
660
Myles Watson911d1ae2016-11-28 16:44:40 -0800661#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800680
Myles Watson911d1ae2016-11-28 16:44:40 -0800681#define BT_OOB_COD_SIZE 3
682#define BT_OOB_HASH_C_SIZE 16
683#define BT_OOB_RAND_R_SIZE 16
The Android Open Source Project5738f832012-12-12 16:00:35 -0800684
685/* Broadcom proprietary UUIDs and reserved PSMs
Myles Watsonee96a3c2016-11-23 14:49:54 -0800686 *
Myles Watson9ca07092016-11-28 16:41:53 -0800687 * 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.
The Android Open Source Project5738f832012-12-12 16:00:35 -0800689*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800690#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800694
695/* We will not allocate a PSM in the reserved range to 3rd party apps
696*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800697#define BRCM_RESERVED_PSM_START 0x5AE1
698#define BRCM_RESERVED_PSM_END 0x5AFF
The Android Open Source Project5738f832012-12-12 16:00:35 -0800699
Myles Watson911d1ae2016-11-28 16:44:40 -0800700#define BRCM_UTILITY_SERVICE_PSM 0x5AE1
701#define BRCM_MATCHER_PSM 0x5AE3
The Android Open Source Project5738f832012-12-12 16:00:35 -0800702
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 */
Myles Watson911d1ae2016-11-28 16:44:40 -0800711#define BT_CONNECTED_USING_BREDR 1
712#define BT_CONNECTED_USING_AMP 2
The Android Open Source Project5738f832012-12-12 16:00:35 -0800713
Myles Watson911d1ae2016-11-28 16:44:40 -0800714typedef struct {
715 uint32_t is_connected;
716 int32_t rssi;
717 uint32_t bytes_sent;
718 uint32_t bytes_rcvd;
719 uint32_t duration;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800720} tBT_CONN_STATS;
721
722#endif
723
The Android Open Source Project5738f832012-12-12 16:00:35 -0800724/*****************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800725 * Low Energy definitions
726 *
727 * Address types
The Android Open Source Project5738f832012-12-12 16:00:35 -0800728*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800729#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
Marie Janssend19e0782016-07-15 12:48:27 -0700733typedef uint8_t tBLE_ADDR_TYPE;
Myles Watson911d1ae2016-11-28 16:44:40 -0800734#define BLE_ADDR_TYPE_MASK (BLE_ADDR_RANDOM | BLE_ADDR_PUBLIC)
Satya Calloji444a8da2015-03-06 10:38:22 -0800735
Myles Watson911d1ae2016-11-28 16:44:40 -0800736#define BT_TRANSPORT_INVALID 0
737#define BT_TRANSPORT_BR_EDR 1
738#define BT_TRANSPORT_LE 2
Marie Janssend19e0782016-07-15 12:48:27 -0700739typedef uint8_t tBT_TRANSPORT;
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -0700740
Jakub Pawlowski96fb2732017-03-24 17:52:02 -0700741#define PHY_LE_1M_MASK 1
742#define PHY_LE_2M_MASK 2
743#define PHY_LE_CODED_MASK 4
744
Myles Watson911d1ae2016-11-28 16:44:40 -0800745#define BLE_ADDR_IS_STATIC(x) (((x)[0] & 0xC0) == 0xC0)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800746
Myles Watson911d1ae2016-11-28 16:44:40 -0800747typedef struct {
748 tBLE_ADDR_TYPE type;
749 BD_ADDR bda;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800750} tBLE_BD_ADDR;
751
752/* Device Types
753*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800754#define BT_DEVICE_TYPE_BREDR 0x01
755#define BT_DEVICE_TYPE_BLE 0x02
756#define BT_DEVICE_TYPE_DUMO 0x03
Marie Janssend19e0782016-07-15 12:48:27 -0700757typedef uint8_t tBT_DEVICE_TYPE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800758/*****************************************************************************/
759
The Android Open Source Project5738f832012-12-12 16:00:35 -0800760/* Define trace levels */
Myles Watson911d1ae2016-11-28 16:44:40 -0800761#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 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800768
Myles Watson911d1ae2016-11-28 16:44:40 -0800769#define MAX_TRACE_LEVEL 6
The Android Open Source Project5738f832012-12-12 16:00:35 -0800770
771/* Define New Trace Type Definition */
772/* TRACE_CTRL_TYPE 0x^^000000*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800773#define TRACE_CTRL_MASK 0xff000000
774#define TRACE_GET_CTRL(x) ((((uint32_t)(x)) & TRACE_CTRL_MASK) >> 24)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800775
Myles Watson911d1ae2016-11-28 16:44:40 -0800776#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800780
781/* LAYER SPECIFIC 0x00^^0000*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800782#define TRACE_LAYER_MASK 0x00ff0000
783#define TRACE_GET_LAYER(x) ((((uint32_t)(x)) & TRACE_LAYER_MASK) >> 16)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800784
Myles Watson911d1ae2016-11-28 16:44:40 -0800785#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800834
Myles Watson911d1ae2016-11-28 16:44:40 -0800835#define TRACE_LAYER_MAX_NUM 0x0031
The Android Open Source Project5738f832012-12-12 16:00:35 -0800836
837/* TRACE_ORIGINATOR 0x0000^^00*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800838#define TRACE_ORG_MASK 0x0000ff00
839#define TRACE_GET_ORG(x) ((((uint32_t)(x)) & TRACE_ORG_MASK) >> 8)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800840
Myles Watson911d1ae2016-11-28 16:44:40 -0800841#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800855
Myles Watson911d1ae2016-11-28 16:44:40 -0800856#define TRACE_ORG_REG 0x00000909
857#define TRACE_ORG_REG_SUCCESS 0x0000090a
The Android Open Source Project5738f832012-12-12 16:00:35 -0800858
859/* TRACE_TYPE 0x000000^^*/
Myles Watson911d1ae2016-11-28 16:44:40 -0800860#define TRACE_TYPE_MASK 0x000000ff
861#define TRACE_GET_TYPE(x) (((uint32_t)(x)) & TRACE_TYPE_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800862
Myles Watson911d1ae2016-11-28 16:44:40 -0800863#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800884
Myles Watson911d1ae2016-11-28 16:44:40 -0800885#define TRACE_TYPE_MAX_NUM 20
886#define TRACE_TYPE_ALL 0xffff
The Android Open Source Project5738f832012-12-12 16:00:35 -0800887
888/* Define color for script type */
Myles Watson911d1ae2016-11-28 16:44:40 -0800889#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
The Android Open Source Project5738f832012-12-12 16:00:35 -0800894
895/* Define protocol trace flag values */
896#define SCR_PROTO_TRACE_HCI_SUMMARY 0x00000001
Myles Watson911d1ae2016-11-28 16:44:40 -0800897#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 */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800920
Myles Watson911d1ae2016-11-28 16:44:40 -0800921#define MAX_SCRIPT_TYPE 5
The Android Open Source Project5738f832012-12-12 16:00:35 -0800922
Myles Watson911d1ae2016-11-28 16:44:40 -0800923#define TCS_PSM_INTERCOM 5
924#define TCS_PSM_CORDLESS 7
925#define BT_PSM_BNEP 0x000F
The Android Open Source Project5738f832012-12-12 16:00:35 -0800926/* Define PSMs HID uses */
Myles Watson911d1ae2016-11-28 16:44:40 -0800927#define HID_PSM_CONTROL 0x0011
928#define HID_PSM_INTERRUPT 0x0013
The Android Open Source Project5738f832012-12-12 16:00:35 -0800929
930/* Define a function for logging */
Myles Watson911d1ae2016-11-28 16:44:40 -0800931typedef void(BT_LOG_FUNC)(int trace_type, const char* fmt_str, ...);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800932
Chris Manton794f3b52014-10-01 09:14:06 -0700933/* bd addr length and type */
934#ifndef BD_ADDR_LEN
Myles Watson911d1ae2016-11-28 16:44:40 -0800935#define BD_ADDR_LEN 6
Chris Manton794f3b52014-10-01 09:14:06 -0700936typedef uint8_t BD_ADDR[BD_ADDR_LEN];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800937#endif
938
Chris Manton794f3b52014-10-01 09:14:06 -0700939// From bd.c
940
941/*****************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800942 * Constants
943 ****************************************************************************/
Chris Manton794f3b52014-10-01 09:14:06 -0700944
945/* global constant for "any" bd addr */
946static const BD_ADDR bd_addr_any = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Myles Watson911d1ae2016-11-28 16:44:40 -0800947static const BD_ADDR bd_addr_null = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Chris Manton794f3b52014-10-01 09:14:06 -0700948
949/*****************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800950 * Functions
951 ****************************************************************************/
Chris Manton794f3b52014-10-01 09:14:06 -0700952
953/*******************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800954 *
955 * Function bdcpy
956 *
957 * Description Copy bd addr b to a.
958 *
959 *
960 * Returns void
961 *
962 ******************************************************************************/
Myles Watson911d1ae2016-11-28 16:44:40 -0800963static inline void bdcpy(BD_ADDR a, const BD_ADDR b) {
964 int i;
Chris Manton794f3b52014-10-01 09:14:06 -0700965
Myles Watson911d1ae2016-11-28 16:44:40 -0800966 for (i = BD_ADDR_LEN; i != 0; i--) {
967 *a++ = *b++;
968 }
Chris Manton794f3b52014-10-01 09:14:06 -0700969}
970
971/*******************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800972 *
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 ******************************************************************************/
Myles Watson911d1ae2016-11-28 16:44:40 -0800981static inline int bdcmp(const BD_ADDR a, const BD_ADDR b) {
982 int i;
Chris Manton794f3b52014-10-01 09:14:06 -0700983
Myles Watson911d1ae2016-11-28 16:44:40 -0800984 for (i = BD_ADDR_LEN; i != 0; i--) {
985 if (*a++ != *b++) {
986 return -1;
Chris Manton794f3b52014-10-01 09:14:06 -0700987 }
Myles Watson911d1ae2016-11-28 16:44:40 -0800988 }
989 return 0;
Chris Manton794f3b52014-10-01 09:14:06 -0700990}
991
992/*******************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -0800993 *
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 ******************************************************************************/
Myles Watson911d1ae2016-11-28 16:44:40 -08001002static inline int bdcmpany(const BD_ADDR a) { return bdcmp(a, bd_addr_any); }
Chris Manton794f3b52014-10-01 09:14:06 -07001003
1004/*******************************************************************************
Myles Watsonee96a3c2016-11-23 14:49:54 -08001005 *
1006 * Function bdsetany
1007 *
1008 * Description Set bd addr to "any" bd addr.
1009 *
1010 *
1011 * Returns void
1012 *
1013 ******************************************************************************/
Myles Watson911d1ae2016-11-28 16:44:40 -08001014static inline void bdsetany(BD_ADDR a) { bdcpy(a, bd_addr_any); }
Chris Manton794f3b52014-10-01 09:14:06 -07001015#endif