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 /******************************************************************************
20  *
21  *  This file contains the Bluetooth Manager (BTM) API function external
22  *  definitions.
23  *
24  ******************************************************************************/
25 #ifndef BTM_API_H
26 #define BTM_API_H
27 
28 #include "common/bt_defs.h"
29 #include "common/bt_target.h"
30 #include "stack/hcidefs.h"
31 
32 #if SDP_INCLUDED == TRUE
33 #include "stack/sdp_api.h"
34 #endif
35 
36 #if SMP_INCLUDED == TRUE
37 #include "stack/smp_api.h"
38 #endif
39 /*****************************************************************************
40 **  DEVICE CONTROL and COMMON
41 *****************************************************************************/
42 /*****************************
43 **  Device Control Constants
44 ******************************/
45 /* Maximum number of bytes allowed for vendor specific command parameters */
46 #define BTM_MAX_VENDOR_SPECIFIC_LEN  HCI_COMMAND_SIZE
47 
48 /* BTM application return status codes */
49 enum {
50     BTM_SUCCESS = 0,                    /* 0  Command succeeded                 */
51     BTM_CMD_STARTED,                    /* 1  Command started OK.               */
52     BTM_BUSY,                           /* 2  Device busy with another command  */
53     BTM_NO_RESOURCES,                   /* 3  No resources to issue command     */
54     BTM_MODE_UNSUPPORTED,               /* 4  Request for 1 or more unsupported modes */
55     BTM_ILLEGAL_VALUE,                  /* 5  Illegal parameter value           */
56     BTM_WRONG_MODE,                     /* 6  Device in wrong mode for request  */
57     BTM_UNKNOWN_ADDR,                   /* 7  Unknown remote BD address         */
58     BTM_DEVICE_TIMEOUT,                 /* 8  Device timeout                    */
59     BTM_BAD_VALUE_RET,                  /* 9  A bad value was received from HCI */
60     BTM_ERR_PROCESSING,                 /* 10 Generic error                     */
61     BTM_NOT_AUTHORIZED,                 /* 11 Authorization failed              */
62     BTM_DEV_RESET,                      /* 12 Device has been reset             */
63     BTM_CMD_STORED,                     /* 13 request is stored in control block */
64     BTM_ILLEGAL_ACTION,                 /* 14 state machine gets illegal command */
65     BTM_DELAY_CHECK,                    /* 15 delay the check on encryption */
66     BTM_SCO_BAD_LENGTH,                 /* 16 Bad SCO over HCI data length */
67     BTM_SUCCESS_NO_SECURITY,            /* 17 security passed, no security set  */
68     BTM_FAILED_ON_SECURITY,             /* 18 security failed                   */
69     BTM_REPEATED_ATTEMPTS,              /* 19 repeated attempts for LE security requests */
70     BTM_MODE4_LEVEL4_NOT_SUPPORTED,     /* 20 Secure Connections Only Mode can't be supported */
71     BTM_PEER_LE_DATA_LEN_UNSUPPORTED,   /* 21 peer setting data length is unsupported*/
72     BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/
73     BTM_SET_PRIVACY_SUCCESS,            /* 23 enable/disable local privacy success */
74     BTM_SET_PRIVACY_FAIL,               /* 24 enable/disable local privacy failed*/
75     BTM_SET_STATIC_RAND_ADDR_FAIL,      /* 25 Command failed */
76     BTM_INVALID_STATIC_RAND_ADDR,       /* 26 invalid static rand addr */
77     BTM_SEC_DEV_REC_REMOVED,            /* 27 Device record relate to the bd_addr is removed */
78 };
79 
80 typedef uint8_t tBTM_STATUS;
81 
82 #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
83 typedef enum {
84     BTM_BR_ONE,                         /*0 First state or BR/EDR scan 1*/
85     BTM_BLE_ONE,                        /*1BLE scan 1*/
86     BTM_BR_TWO,                         /*2 BR/EDR scan 2*/
87     BTM_BLE_TWO,                        /*3 BLE scan 2*/
88     BTM_FINISH,                         /*4 End of Interleave Scan, or normal scan*/
89     BTM_NO_INTERLEAVING                 /*5 No Interleaving*/
90 } btm_inq_state;
91 #endif
92 
93 
94 
95 /*************************
96 **  Device Control Types
97 **************************/
98 #define BTM_DEVICE_ROLE_BR      0x01
99 #define BTM_DEVICE_ROLE_DUAL    0x02
100 #define BTM_MAX_DEVICE_ROLE     BTM_DEVICE_ROLE_DUAL
101 typedef UINT8 tBTM_DEVICE_ROLE;
102 
103 /* Device name of peer (may be truncated to save space in BTM database) */
104 typedef UINT8 tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1];
105 
106 /* Structure returned with local version information */
107 typedef struct {
108     UINT8       hci_version;
109     UINT16      hci_revision;
110     UINT8       lmp_version;
111     UINT16      manufacturer;
112     UINT16      lmp_subversion;
113 } tBTM_VERSION_INFO;
114 
115 /* Structure returned with Vendor Specific Command complete callback */
116 typedef struct {
117     UINT16  opcode;
118     UINT16  param_len;
119     UINT8   *p_param_buf;
120 } tBTM_VSC_CMPL;
121 
122 #define  BTM_VSC_CMPL_DATA_SIZE  (BTM_MAX_VENDOR_SPECIFIC_LEN + sizeof(tBTM_VSC_CMPL))
123 /**************************************************
124 **  Device Control and General Callback Functions
125 ***************************************************/
126 /* Callback function for when device status changes. Appl must poll for
127 ** what the new state is (BTM_IsDeviceUp). The event occurs whenever the stack
128 ** has detected that the controller status has changed. This asynchronous event
129 ** is enabled/disabled by calling BTM_RegisterForDeviceStatusNotif().
130 */
131 enum {
132     BTM_DEV_STATUS_UP,
133     BTM_DEV_STATUS_DOWN,
134     BTM_DEV_STATUS_CMD_TOUT
135 };
136 
137 typedef UINT8 tBTM_DEV_STATUS;
138 
139 typedef struct {
140     UINT16 rx_len;
141     UINT16 tx_len;
142 }tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS;
143 
144 typedef struct {
145     UINT16              min_conn_int;
146     UINT16              max_conn_int;
147     UINT16              conn_int;
148     UINT16              slave_latency;
149     UINT16              supervision_tout;
150 }tBTM_LE_UPDATE_CONN_PRAMS;
151 
152 typedef enum{
153     BTM_WHITELIST_REMOVE     = 0X00,
154     BTM_WHITELIST_ADD        = 0X01,
155     BTM_WHITELIST_CLEAR      = 0x02,
156 }tBTM_WL_OPERATION;
157 
158 
159 typedef void (tBTM_DEV_STATUS_CB) (tBTM_DEV_STATUS status);
160 
161 typedef void (tBTM_GET_DEV_NAME_CBACK) (UINT8 status, char *name);
162 
163 /* Callback function for when a vendor specific event occurs. The length and
164 ** array of returned parameter bytes are included. This asynchronous event
165 ** is enabled/disabled by calling BTM_RegisterForVSEvents().
166 */
167 typedef void (tBTM_VS_EVT_CB) (UINT8 len, UINT8 *p);
168 
169 
170 /* General callback function for notifying an application that a synchronous
171 ** BTM function is complete. The pointer contains the address of any returned data.
172 */
173 typedef void (tBTM_CMPL_CB) (void *p1);
174 
175 typedef void (tBTM_INQ_DIS_CB) (uint32_t num_dis);
176 
177 /* VSC callback function for notifying an application that a synchronous
178 ** BTM function is complete. The pointer contains the address of any returned data.
179 */
180 typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1);
181 
182 /* Callback for apps to check connection and inquiry filters.
183 ** Parameters are the BD Address of remote and the Dev Class of remote.
184 ** If the app returns none zero, the connection or inquiry result will be dropped.
185 */
186 typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc);
187 
188 typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params);
189 
190 typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
191 
192 typedef void (tBTM_SET_RAND_ADDR_CBACK) (UINT8 status);
193 
194 typedef void (tBTM_UPDATE_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration);
195 
196 typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);
197 
198 
199 /*****************************************************************************
200 **  DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
201 *****************************************************************************/
202 /*******************************
203 **  Device Discovery Constants
204 ********************************/
205 /* Discoverable modes */
206 #define BTM_NON_DISCOVERABLE        0
207 #define BTM_LIMITED_DISCOVERABLE    1
208 #define BTM_GENERAL_DISCOVERABLE    2
209 #define BTM_DISCOVERABLE_MASK       (BTM_LIMITED_DISCOVERABLE|BTM_GENERAL_DISCOVERABLE)
210 #define BTM_MAX_DISCOVERABLE        BTM_GENERAL_DISCOVERABLE
211 /* high byte for BLE Discoverable modes */
212 #define BTM_BLE_NON_DISCOVERABLE        0x0000
213 #define BTM_BLE_LIMITED_DISCOVERABLE    0x0100
214 #define BTM_BLE_GENERAL_DISCOVERABLE    0x0200
215 #define BTM_BLE_MAX_DISCOVERABLE        BTM_BLE_GENERAL_DISCOVERABLE
216 #define BTM_BLE_DISCOVERABLE_MASK       (BTM_BLE_NON_DISCOVERABLE|BTM_BLE_LIMITED_DISCOVERABLE|BTM_BLE_GENERAL_DISCOVERABLE)
217 
218 /* Connectable modes */
219 #define BTM_NON_CONNECTABLE         0
220 #define BTM_CONNECTABLE             1
221 #define BTM_CONNECTABLE_MASK        (BTM_NON_CONNECTABLE | BTM_CONNECTABLE)
222 /* high byte for BLE Connectable modes */
223 #define BTM_BLE_NON_CONNECTABLE      0x0000
224 #define BTM_BLE_CONNECTABLE          0x0100
225 #define BTM_BLE_MAX_CONNECTABLE      BTM_BLE_CONNECTABLE
226 #define BTM_BLE_CONNECTABLE_MASK    (BTM_BLE_NON_CONNECTABLE | BTM_BLE_CONNECTABLE)
227 
228 /* Inquiry modes
229  * Note: These modes are associated with the inquiry active values (BTM_*ACTIVE) */
230 #define BTM_INQUIRY_NONE            0
231 #define BTM_GENERAL_INQUIRY         0x01
232 #define BTM_LIMITED_INQUIRY         0x02
233 #define BTM_BR_INQUIRY_MASK         (BTM_GENERAL_INQUIRY | BTM_LIMITED_INQUIRY)
234 
235 /* high byte of inquiry mode for BLE inquiry mode */
236 #define BTM_BLE_INQUIRY_NONE         0x00
237 #define BTM_BLE_GENERAL_INQUIRY      0x10
238 #define BTM_BLE_LIMITED_INQUIRY      0x20
239 #define BTM_BLE_INQUIRY_MASK         (BTM_BLE_GENERAL_INQUIRY|BTM_BLE_LIMITED_INQUIRY)
240 
241 /* BTM_IsInquiryActive return values (Bit Mask)
242  * Note: These bit masks are associated with the inquiry modes (BTM_*_INQUIRY) */
243 #define BTM_INQUIRY_INACTIVE        0x0     /* no inquiry in progress */
244 #define BTM_GENERAL_INQUIRY_ACTIVE  BTM_GENERAL_INQUIRY     /* a general inquiry is in progress */
245 #define BTM_LIMITED_INQUIRY_ACTIVE  BTM_LIMITED_INQUIRY     /* a limited inquiry is in progress */
246 #define BTM_PERIODIC_INQUIRY_ACTIVE 0x8     /* a periodic inquiry is active */
247 #define BTM_SSP_INQUIRY_ACTIVE      0x4     /* SSP is active, so inquiry is disallowed (work around for FW bug) */
248 #define BTM_LE_GENERAL_INQUIRY_ACTIVE  BTM_BLE_GENERAL_INQUIRY     /* a general inquiry is in progress */
249 #define BTM_LE_LIMITED_INQUIRY_ACTIVE  BTM_BLE_LIMITED_INQUIRY      /* a limited inquiry is in progress */
250 
251 /* inquiry activity mask */
252 #define BTM_BR_INQ_ACTIVE_MASK        (BTM_GENERAL_INQUIRY_ACTIVE|BTM_LIMITED_INQUIRY_ACTIVE|BTM_PERIODIC_INQUIRY_ACTIVE) /* BR/EDR inquiry activity mask */
253 #define BTM_BLE_SCAN_ACTIVE_MASK      0x01F0     /* LE scan activity mask */
254 #define BTM_BLE_INQ_ACTIVE_MASK       (BTM_LE_GENERAL_INQUIRY_ACTIVE|BTM_LE_LIMITED_INQUIRY_ACTIVE) /* LE inquiry activity mask*/
255 #define BTM_INQUIRY_ACTIVE_MASK       (BTM_BR_INQ_ACTIVE_MASK | BTM_BLE_INQ_ACTIVE_MASK) /* inquiry activity mask */
256 
257 /* Define scan types */
258 #define BTM_SCAN_TYPE_STANDARD      0
259 #define BTM_SCAN_TYPE_INTERLACED    1       /* 1.2 devices only */
260 
261 /* Define inquiry results mode */
262 #define BTM_INQ_RESULT_STANDARD     0
263 #define BTM_INQ_RESULT_WITH_RSSI    1
264 #define BTM_INQ_RESULT_EXTENDED     2
265 
266 #define BTM_INQ_RES_IGNORE_RSSI     0x7f    /* RSSI value not supplied (ignore it) */
267 
268 /* Inquiry Filter Condition types (see tBTM_INQ_PARMS) */
269 #define BTM_CLR_INQUIRY_FILTER          0                   /* Inquiry Filtering is turned off */
270 #define BTM_FILTER_COND_DEVICE_CLASS    HCI_FILTER_COND_DEVICE_CLASS /* Filter on device class */
271 #define BTM_FILTER_COND_BD_ADDR         HCI_FILTER_COND_BD_ADDR /* Filter on device addr */
272 
273 /* State of the remote name retrieval during inquiry operations.
274 ** Used in the tBTM_INQ_INFO structure, and returned in the
275 ** BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext functions.
276 ** The name field is valid when the state returned is
277 ** BTM_INQ_RMT_NAME_DONE */
278 #define BTM_INQ_RMT_NAME_EMPTY      0
279 #define BTM_INQ_RMT_NAME_PENDING    1
280 #define BTM_INQ_RMT_NAME_DONE       2
281 #define BTM_INQ_RMT_NAME_FAILED     3
282 
283 /*********************************
284  *** Class of Device constants ***
285  *********************************/
286 #define BTM_FORMAT_TYPE_1   0x00
287 
288 /****************************
289 ** minor device class field
290 *****************************/
291 
292 /* 0x00 is used as unclassified for all minor device classes */
293 #define BTM_COD_MINOR_UNCLASSIFIED          0x00
294 
295 /* minor device class field for Computer Major Class */
296 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
297 #define BTM_COD_MINOR_DESKTOP_WORKSTATION   0x04
298 #define BTM_COD_MINOR_SERVER_COMPUTER       0x08
299 #define BTM_COD_MINOR_LAPTOP                0x0C
300 #define BTM_COD_MINOR_HANDHELD_PC_PDA       0x10    /* clam shell */
301 #define BTM_COD_MINOR_PALM_SIZE_PC_PDA      0x14
302 #define BTM_COD_MINOR_WEARABLE_COMPUTER     0x18    /* watch sized */
303 
304 /* minor device class field for Phone Major Class */
305 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
306 #define BTM_COD_MINOR_CELLULAR              0x04
307 #define BTM_COD_MINOR_CORDLESS              0x08
308 #define BTM_COD_MINOR_SMART_PHONE           0x0C
309 #define BTM_COD_MINOR_WIRED_MDM_V_GTWY      0x10 /* wired modem or voice gatway */
310 #define BTM_COD_MINOR_ISDN_ACCESS           0x14
311 
312 /* minor device class field for LAN Access Point Major Class */
313 /* Load Factor Field bit 5-7 */
314 #define BTM_COD_MINOR_FULLY_AVAILABLE       0x00
315 #define BTM_COD_MINOR_1_17_UTILIZED         0x20
316 #define BTM_COD_MINOR_17_33_UTILIZED        0x40
317 #define BTM_COD_MINOR_33_50_UTILIZED        0x60
318 #define BTM_COD_MINOR_50_67_UTILIZED        0x80
319 #define BTM_COD_MINOR_67_83_UTILIZED        0xA0
320 #define BTM_COD_MINOR_83_99_UTILIZED        0xC0
321 #define BTM_COD_MINOR_NO_SERVICE_AVAILABLE  0xE0
322 /* sub-Field bit 2-4 */
323 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
324 
325 /* minor device class field for Audio/Video Major Class */
326 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
327 #define BTM_COD_MINOR_CONFM_HEADSET         0x04
328 #define BTM_COD_MINOR_CONFM_HANDSFREE       0x08
329 #define BTM_COD_MINOR_MICROPHONE            0x10
330 #define BTM_COD_MINOR_LOUDSPEAKER           0x14
331 #define BTM_COD_MINOR_HEADPHONES            0x18
332 #define BTM_COD_MINOR_PORTABLE_AUDIO        0x1C
333 #define BTM_COD_MINOR_CAR_AUDIO             0x20
334 #define BTM_COD_MINOR_SET_TOP_BOX           0x24
335 #define BTM_COD_MINOR_HIFI_AUDIO            0x28
336 #define BTM_COD_MINOR_VCR                   0x2C
337 #define BTM_COD_MINOR_VIDEO_CAMERA          0x30
338 #define BTM_COD_MINOR_CAMCORDER             0x34
339 #define BTM_COD_MINOR_VIDEO_MONITOR         0x38
340 #define BTM_COD_MINOR_VIDDISP_LDSPKR        0x3C
341 #define BTM_COD_MINOR_VIDEO_CONFERENCING    0x40
342 #define BTM_COD_MINOR_GAMING_TOY            0x48
343 
344 /* minor device class field for Peripheral Major Class */
345 /* Bits 6-7 independently specify mouse, keyboard, or combo mouse/keyboard */
346 #define BTM_COD_MINOR_KEYBOARD              0x40
347 #define BTM_COD_MINOR_POINTING              0x80
348 #define BTM_COD_MINOR_COMBO                 0xC0
349 /* Bits 2-5 OR'd with selection from bits 6-7 */
350 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
351 #define BTM_COD_MINOR_JOYSTICK              0x04
352 #define BTM_COD_MINOR_GAMEPAD               0x08
353 #define BTM_COD_MINOR_REMOTE_CONTROL        0x0C
354 #define BTM_COD_MINOR_SENSING_DEVICE        0x10
355 #define BTM_COD_MINOR_DIGITIZING_TABLET     0x14
356 #define BTM_COD_MINOR_CARD_READER           0x18    /* e.g. SIM card reader */
357 #define BTM_COD_MINOR_DIGITAL_PAN           0x1C
358 #define BTM_COD_MINOR_HAND_SCANNER          0x20
359 #define BTM_COD_MINOR_HAND_GESTURAL_INPUT   0x24
360 
361 /* minor device class field for Imaging Major Class */
362 /* Bits 5-7 independently specify display, camera, scanner, or printer */
363 #define BTM_COD_MINOR_DISPLAY               0x10
364 #define BTM_COD_MINOR_CAMERA                0x20
365 #define BTM_COD_MINOR_SCANNER               0x40
366 #define BTM_COD_MINOR_PRINTER               0x80
367 /* Bits 2-3 Reserved */
368 /* #define BTM_COD_MINOR_UNCLASSIFIED       0x00    */
369 
370 /* minor device class field for Wearable Major Class */
371 /* Bits 2-7 meaningful    */
372 #define BTM_COD_MINOR_WRIST_WATCH           0x04
373 #define BTM_COD_MINOR_PAGER                 0x08
374 #define BTM_COD_MINOR_JACKET                0x0C
375 #define BTM_COD_MINOR_HELMET                0x10
376 #define BTM_COD_MINOR_GLASSES               0x14
377 
378 /* minor device class field for Toy Major Class */
379 /* Bits 2-7 meaningful    */
380 #define BTM_COD_MINOR_ROBOT                 0x04
381 #define BTM_COD_MINOR_VEHICLE               0x08
382 #define BTM_COD_MINOR_DOLL_ACTION_FIGURE    0x0C
383 #define BTM_COD_MINOR_CONTROLLER            0x10
384 #define BTM_COD_MINOR_GAME                  0x14
385 
386 /* minor device class field for Health Major Class */
387 /* Bits 2-7 meaningful    */
388 #define BTM_COD_MINOR_BLOOD_MONITOR         0x04
389 #define BTM_COD_MINOR_THERMOMETER           0x08
390 #define BTM_COD_MINOR_WEIGHING_SCALE        0x0C
391 #define BTM_COD_MINOR_GLUCOSE_METER         0x10
392 #define BTM_COD_MINOR_PULSE_OXIMETER        0x14
393 #define BTM_COD_MINOR_HEART_PULSE_MONITOR   0x18
394 #define BTM_COD_MINOR_HEALTH_DATA_DISPLAY   0x1C
395 #define BTM_COD_MINOR_STEP_COUNTER          0x20
396 #define BTM_COD_MINOR_BODY_COM_ANALYZER     0x24
397 #define BTM_COD_MINOR_PEAK_FLOW_MONITOR     0x28
398 #define BTM_COD_MINOR_MEDICATION_MONITOR    0x2C
399 #define BTM_COD_MINOR_KNEE_PROSTHESIS       0x30
400 #define BTM_COD_MINOR_ANKLE_PROSTHESIS      0x34
401 
402 
403 /***************************
404 ** major device class field
405 ****************************/
406 #define BTM_COD_MAJOR_MISCELLANEOUS         0x00
407 #define BTM_COD_MAJOR_COMPUTER              0x01
408 #define BTM_COD_MAJOR_PHONE                 0x02
409 #define BTM_COD_MAJOR_LAN_ACCESS_PT         0x03
410 #define BTM_COD_MAJOR_AUDIO                 0x04
411 #define BTM_COD_MAJOR_PERIPHERAL            0x05
412 #define BTM_COD_MAJOR_IMAGING               0x06
413 #define BTM_COD_MAJOR_WEARABLE              0x07
414 #define BTM_COD_MAJOR_TOY                   0x08
415 #define BTM_COD_MAJOR_HEALTH                0x09
416 #define BTM_COD_MAJOR_UNCLASSIFIED          0x1F
417 
418 /***************************
419 ** service class fields
420 ****************************/
421 #define BTM_COD_SERVICE_LMTD_DISCOVER       0x0020
422 #define BTM_COD_SERVICE_POSITIONING         0x0100
423 #define BTM_COD_SERVICE_NETWORKING          0x0200
424 #define BTM_COD_SERVICE_RENDERING           0x0400
425 #define BTM_COD_SERVICE_CAPTURING           0x0800
426 #define BTM_COD_SERVICE_OBJ_TRANSFER        0x1000
427 #define BTM_COD_SERVICE_AUDIO               0x2000
428 #define BTM_COD_SERVICE_TELEPHONY           0x4000
429 #define BTM_COD_SERVICE_INFORMATION         0x8000
430 
431 /* class of device field macros */
432 #define BTM_COD_FORMAT_TYPE(u8, pd)         {u8  = pd[2]&0x03;}
433 #define BTM_COD_MINOR_CLASS(u8, pd)         {u8  = pd[2]&0xFC;}
434 #define BTM_COD_MAJOR_CLASS(u8, pd)         {u8  = pd[1]&0x1F;}
435 #define BTM_COD_SERVICE_CLASS(u16, pd)      {u16 = pd[0]; u16<<=8; u16 += pd[1]&0xE0;}
436 
437 /* to set the fields (assumes that format type is always 0) */
438 #define FIELDS_TO_COD(pd, mn, mj, sv) {pd[2] = mn; pd[1] =              \
439                                        mj+ ((sv)&BTM_COD_SERVICE_CLASS_LO_B); \
440                                        pd[0] = (sv) >> 8;}
441 
442 /* the COD masks */
443 #define BTM_COD_FORMAT_TYPE_MASK      0x03
444 #define BTM_COD_MINOR_CLASS_MASK      0xFC
445 #define BTM_COD_MAJOR_CLASS_MASK      0x1F
446 #define BTM_COD_SERVICE_CLASS_LO_B    0x00E0
447 #define BTM_COD_SERVICE_CLASS_MASK    0xFFE0
448 
449 
450 /* BTM service definitions
451 ** Used for storing EIR data to bit mask
452 */
453 enum {
454     BTM_EIR_UUID_SERVCLASS_SERVICE_DISCOVERY_SERVER,
455     /*    BTM_EIR_UUID_SERVCLASS_BROWSE_GROUP_DESCRIPTOR,   */
456     /*    BTM_EIR_UUID_SERVCLASS_PUBLIC_BROWSE_GROUP,       */
457     BTM_EIR_UUID_SERVCLASS_SERIAL_PORT,
458     BTM_EIR_UUID_SERVCLASS_LAN_ACCESS_USING_PPP,
459     BTM_EIR_UUID_SERVCLASS_DIALUP_NETWORKING,
460     BTM_EIR_UUID_SERVCLASS_IRMC_SYNC,
461     BTM_EIR_UUID_SERVCLASS_OBEX_OBJECT_PUSH,
462     BTM_EIR_UUID_SERVCLASS_OBEX_FILE_TRANSFER,
463     BTM_EIR_UUID_SERVCLASS_IRMC_SYNC_COMMAND,
464     BTM_EIR_UUID_SERVCLASS_HEADSET,
465     BTM_EIR_UUID_SERVCLASS_CORDLESS_TELEPHONY,
466     BTM_EIR_UUID_SERVCLASS_AUDIO_SOURCE,
467     BTM_EIR_UUID_SERVCLASS_AUDIO_SINK,
468     BTM_EIR_UUID_SERVCLASS_AV_REM_CTRL_TARGET,
469     /*    BTM_EIR_UUID_SERVCLASS_ADV_AUDIO_DISTRIBUTION,    */
470     BTM_EIR_UUID_SERVCLASS_AV_REMOTE_CONTROL,
471     /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING,        */
472     BTM_EIR_UUID_SERVCLASS_INTERCOM,
473     BTM_EIR_UUID_SERVCLASS_FAX,
474     BTM_EIR_UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY,
475     /*    BTM_EIR_UUID_SERVCLASS_WAP,                       */
476     /*    BTM_EIR_UUID_SERVCLASS_WAP_CLIENT,                */
477     BTM_EIR_UUID_SERVCLASS_PANU,
478     BTM_EIR_UUID_SERVCLASS_NAP,
479     BTM_EIR_UUID_SERVCLASS_GN,
480     BTM_EIR_UUID_SERVCLASS_DIRECT_PRINTING,
481     /*    BTM_EIR_UUID_SERVCLASS_REFERENCE_PRINTING,        */
482     BTM_EIR_UUID_SERVCLASS_IMAGING,
483     BTM_EIR_UUID_SERVCLASS_IMAGING_RESPONDER,
484     BTM_EIR_UUID_SERVCLASS_IMAGING_AUTO_ARCHIVE,
485     BTM_EIR_UUID_SERVCLASS_IMAGING_REF_OBJECTS,
486     BTM_EIR_UUID_SERVCLASS_HF_HANDSFREE,
487     BTM_EIR_UUID_SERVCLASS_AG_HANDSFREE,
488     BTM_EIR_UUID_SERVCLASS_DIR_PRT_REF_OBJ_SERVICE,
489     /*    BTM_EIR_UUID_SERVCLASS_REFLECTED_UI,              */
490     BTM_EIR_UUID_SERVCLASS_BASIC_PRINTING,
491     BTM_EIR_UUID_SERVCLASS_PRINTING_STATUS,
492     BTM_EIR_UUID_SERVCLASS_HUMAN_INTERFACE,
493     BTM_EIR_UUID_SERVCLASS_CABLE_REPLACEMENT,
494     BTM_EIR_UUID_SERVCLASS_HCRP_PRINT,
495     BTM_EIR_UUID_SERVCLASS_HCRP_SCAN,
496     /*    BTM_EIR_UUID_SERVCLASS_COMMON_ISDN_ACCESS,        */
497     /*    BTM_EIR_UUID_SERVCLASS_VIDEO_CONFERENCING_GW,     */
498     /*    BTM_EIR_UUID_SERVCLASS_UDI_MT,                    */
499     /*    BTM_EIR_UUID_SERVCLASS_UDI_TA,                    */
500     /*    BTM_EIR_UUID_SERVCLASS_VCP,                       */
501     BTM_EIR_UUID_SERVCLASS_SAP,
502     BTM_EIR_UUID_SERVCLASS_PBAP_PCE,
503     BTM_EIR_UUID_SERVCLASS_PBAP_PSE,
504     /*    BTM_EIR_UUID_SERVCLASS_TE_PHONE_ACCESS,           */
505     /*    BTM_EIR_UUID_SERVCLASS_ME_PHONE_ACCESS,           */
506     BTM_EIR_UUID_SERVCLASS_PHONE_ACCESS,
507     BTM_EIR_UUID_SERVCLASS_HEADSET_HS,
508     BTM_EIR_UUID_SERVCLASS_PNP_INFORMATION,
509     /*    BTM_EIR_UUID_SERVCLASS_GENERIC_NETWORKING,        */
510     /*    BTM_EIR_UUID_SERVCLASS_GENERIC_FILETRANSFER,      */
511     /*    BTM_EIR_UUID_SERVCLASS_GENERIC_AUDIO,             */
512     /*    BTM_EIR_UUID_SERVCLASS_GENERIC_TELEPHONY,         */
513     /*    BTM_EIR_UUID_SERVCLASS_UPNP_SERVICE,              */
514     /*    BTM_EIR_UUID_SERVCLASS_UPNP_IP_SERVICE,           */
515     /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_PAN,          */
516     /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_LAP,          */
517     /*    BTM_EIR_UUID_SERVCLASS_ESDP_UPNP_IP_L2CAP,        */
518     BTM_EIR_UUID_SERVCLASS_VIDEO_SOURCE,
519     BTM_EIR_UUID_SERVCLASS_VIDEO_SINK,
520     /*    BTM_EIR_UUID_SERVCLASS_VIDEO_DISTRIBUTION         */
521     /*    BTM_EIR_UUID_SERVCLASS_HDP_PROFILE                */
522     BTM_EIR_UUID_SERVCLASS_MESSAGE_ACCESS,
523     BTM_EIR_UUID_SERVCLASS_MESSAGE_NOTIFICATION,
524     BTM_EIR_UUID_SERVCLASS_HDP_SOURCE,
525     BTM_EIR_UUID_SERVCLASS_HDP_SINK,
526     BTM_EIR_MAX_SERVICES
527 };
528 
529 /* search result in EIR of inquiry database */
530 #define BTM_EIR_FOUND           0
531 #define BTM_EIR_NOT_FOUND       1
532 #define BTM_EIR_UNKNOWN         2
533 
534 typedef UINT8 tBTM_EIR_SEARCH_RESULT;
535 
536 #define BTM_EIR_FLAGS_TYPE                  HCI_EIR_FLAGS_TYPE                  /* 0x01 */
537 #define BTM_EIR_MORE_16BITS_UUID_TYPE       HCI_EIR_MORE_16BITS_UUID_TYPE       /* 0x02 */
538 #define BTM_EIR_COMPLETE_16BITS_UUID_TYPE   HCI_EIR_COMPLETE_16BITS_UUID_TYPE   /* 0x03 */
539 #define BTM_EIR_MORE_32BITS_UUID_TYPE       HCI_EIR_MORE_32BITS_UUID_TYPE       /* 0x04 */
540 #define BTM_EIR_COMPLETE_32BITS_UUID_TYPE   HCI_EIR_COMPLETE_32BITS_UUID_TYPE   /* 0x05 */
541 #define BTM_EIR_MORE_128BITS_UUID_TYPE      HCI_EIR_MORE_128BITS_UUID_TYPE      /* 0x06 */
542 #define BTM_EIR_COMPLETE_128BITS_UUID_TYPE  HCI_EIR_COMPLETE_128BITS_UUID_TYPE  /* 0x07 */
543 #define BTM_EIR_SHORTENED_LOCAL_NAME_TYPE   HCI_EIR_SHORTENED_LOCAL_NAME_TYPE   /* 0x08 */
544 #define BTM_EIR_COMPLETE_LOCAL_NAME_TYPE    HCI_EIR_COMPLETE_LOCAL_NAME_TYPE    /* 0x09 */
545 #define BTM_EIR_TX_POWER_LEVEL_TYPE         HCI_EIR_TX_POWER_LEVEL_TYPE         /* 0x0A */
546 #define BTM_EIR_URL_TYPE                    HCI_EIR_URL_TYPE                    /* 0x24 */
547 #define BTM_EIR_MANUFACTURER_SPECIFIC_TYPE  HCI_EIR_MANUFACTURER_SPECIFIC_TYPE  /* 0xFF */
548 
549 #define BTM_EIR_TYPE_MAX_NUM                12                                  /* Max EIR types */
550 
551 /* the following EIR tags are defined to OOB, not regular EIR data */
552 #define BTM_EIR_OOB_BD_ADDR_TYPE            HCI_EIR_OOB_BD_ADDR_TYPE    /* 6 bytes */
553 #define BTM_EIR_OOB_COD_TYPE                HCI_EIR_OOB_COD_TYPE        /* 3 bytes */
554 #define BTM_EIR_OOB_SSP_HASH_C_TYPE         HCI_EIR_OOB_SSP_HASH_C_TYPE /* 16 bytes */
555 #define BTM_EIR_OOB_SSP_RAND_R_TYPE         HCI_EIR_OOB_SSP_RAND_R_TYPE /* 16 bytes */
556 
557 #define BTM_OOB_MANDATORY_SIZE      8   /* include 2 bytes length & 6 bytes bd_addr */
558 #define BTM_OOB_DATA_LEN_SIZE       2
559 #define BTM_OOB_BD_ADDR_SIZE        6
560 #define BTM_OOB_COD_SIZE            BT_OOB_COD_SIZE
561 #define BTM_OOB_HASH_C_SIZE         BT_OOB_HASH_C_SIZE
562 #define BTM_OOB_RAND_R_SIZE         BT_OOB_RAND_R_SIZE
563 
564 
565 #if BLE_INCLUDED == TRUE
566 #define BTM_BLE_SEC_NONE                0
567 #define BTM_BLE_SEC_ENCRYPT             1 /* encrypt the link using current key */
568 #define BTM_BLE_SEC_ENCRYPT_NO_MITM     2
569 #define BTM_BLE_SEC_ENCRYPT_MITM        3
570 typedef UINT8   tBTM_BLE_SEC_ACT;
571 #endif
572 /************************************************************************************************
573 ** BTM Services MACROS handle array of UINT32 bits for more than 32 services
574 *************************************************************************************************/
575 /* Determine the number of UINT32's necessary for services */
576 #define BTM_EIR_ARRAY_BITS          32          /* Number of bits in each array element */
577 #define BTM_EIR_SERVICE_ARRAY_SIZE  (((UINT32)BTM_EIR_MAX_SERVICES / BTM_EIR_ARRAY_BITS) + \
578                                     (((UINT32)BTM_EIR_MAX_SERVICES % BTM_EIR_ARRAY_BITS) ? 1 : 0))
579 
580 /* MACRO to set the service bit mask in a bit stream */
581 #define BTM_EIR_SET_SERVICE(p, service)  (((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] |=  \
582                                     ((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS)))
583 
584 
585 /* MACRO to clear the service bit mask in a bit stream */
586 #define BTM_EIR_CLR_SERVICE(p, service)  (((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] &=  \
587                                     ~((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS)))
588 
589 /* MACRO to check the service bit mask in a bit stream */
590 #define BTM_EIR_HAS_SERVICE(p, service)  ((((UINT32 *)(p))[(((UINT32)(service)) / BTM_EIR_ARRAY_BITS)] &  \
591                                     ((UINT32)1 << (((UINT32)(service)) % BTM_EIR_ARRAY_BITS))) >> (((UINT32)(service)) % BTM_EIR_ARRAY_BITS))
592 
593 /* start of EIR in HCI buffer, 4 bytes = HCI Command(2) + Length(1) + FEC_Req(1) */
594 #define BTM_HCI_EIR_OFFSET          (BT_HDR_SIZE + 4)
595 
596 /***************************
597 **  Device Discovery Types
598 ****************************/
599 /* Definitions of the parameters passed to BTM_StartInquiry and
600 ** BTM_SetPeriodicInquiryMode.
601 */
602 typedef struct {            /* contains the two device class condition fields */
603     DEV_CLASS       dev_class;
604     DEV_CLASS       dev_class_mask;
605 } tBTM_COD_COND;
606 
607 
608 typedef union {             /* contains the inquiry filter condition */
609     BD_ADDR         bdaddr_cond;
610     tBTM_COD_COND   cod_cond;
611 } tBTM_INQ_FILT_COND;
612 
613 
614 typedef struct {            /* contains the parameters passed to the inquiry functions */
615     UINT8   mode;                       /* general or limited */
616     UINT8   duration;                   /* duration of the inquiry (1.28 sec increments) */
617     UINT8   max_resps;                  /* maximum number of responses to return */
618     BOOLEAN report_dup;                 /* report duplicated inquiry response with higher RSSI value */
619     UINT8   filter_cond_type;           /* new devices, BD ADDR, COD, or No filtering */
620     tBTM_INQ_FILT_COND  filter_cond;    /* filter value based on filter cond type */
621 #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
622     UINT8   intl_duration[4];              /*duration array storing the interleave scan's time portions*/
623 #endif
624 } tBTM_INQ_PARMS;
625 
626 #define BTM_INQ_RESULT_BR       0x01
627 #define BTM_INQ_RESULT_BLE      0x02
628 
629 #if (BLE_INCLUDED == TRUE)
630 #define BTM_BLE_EVT_CONN_ADV        0x00
631 #define BTM_BLE_EVT_CONN_DIR_ADV    0x01
632 #define BTM_BLE_EVT_DISC_ADV        0x02
633 #define BTM_BLE_EVT_NON_CONN_ADV    0x03
634 #define BTM_BLE_EVT_SCAN_RSP        0x04
635 typedef UINT8 tBTM_BLE_EVT_TYPE;
636 #endif
637 
638 /* These are the fields returned in each device's response to the inquiry.  It
639 ** is returned in the results callback if registered.
640 */
641 typedef struct {
642     UINT16      clock_offset;
643     BD_ADDR     remote_bd_addr;
644     DEV_CLASS   dev_class;
645     UINT8       page_scan_rep_mode;
646     UINT8       page_scan_per_mode;
647     UINT8       page_scan_mode;
648     INT8        rssi;       /* Set to BTM_INQ_RES_IGNORE_RSSI if  not valid */
649     UINT32      eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
650     BOOLEAN     eir_complete_list;
651     tBT_DEVICE_TYPE         device_type;
652 #if (BLE_INCLUDED == TRUE)
653     UINT8       inq_result_type;
654     UINT8       ble_addr_type;
655     tBTM_BLE_EVT_TYPE       ble_evt_type;
656     UINT8                   flag;
657     UINT8       adv_data_len;
658     UINT8       scan_rsp_len;
659 #endif
660 } tBTM_INQ_RESULTS;
661 
662 
663 /* This is the inquiry response information held in its database by BTM, and available
664 ** to applications via BTM_InqDbRead, BTM_InqDbFirst, and BTM_InqDbNext.
665 */
666 typedef struct {
667     tBTM_INQ_RESULTS    results;
668 
669     BOOLEAN             appl_knows_rem_name;    /* set by application if it knows the remote name of the peer device.
670                                                    This is later used by application to determine if remote name request is
671                                                    required to be done. Having the flag here avoid duplicate store of inquiry results */
672 #if ( BLE_INCLUDED == TRUE)
673     UINT16          remote_name_len;
674     tBTM_BD_NAME    remote_name;
675     UINT8           remote_name_state;
676     UINT8           remote_name_type;
677 #endif
678 
679 } tBTM_INQ_INFO;
680 
681 
682 /* Structure returned with inquiry complete callback */
683 typedef struct {
684     tBTM_STATUS status;
685     UINT8       num_resp;       /* Number of results from the current inquiry */
686 } tBTM_INQUIRY_CMPL;
687 
688 /* Structure returned with remote name  request */
689 typedef struct {
690     UINT16      status;
691     BD_ADDR     bd_addr;
692     UINT16      length;
693     BD_NAME     remote_bd_name;
694 } tBTM_REMOTE_DEV_NAME;
695 
696 typedef struct {
697     UINT8   pcm_intf_rate;  /* PCM interface rate: 0: 128kbps, 1: 256 kbps;
698                                 2:512 bps; 3: 1024kbps; 4: 2048kbps */
699     UINT8   frame_type;     /* frame type: 0: short; 1: long */
700     UINT8   sync_mode;      /* sync mode: 0: slave; 1: master */
701     UINT8   clock_mode;     /* clock mode: 0: slave; 1: master */
702 
703 } tBTM_SCO_PCM_PARAM;
704 
705 /****************************************
706 **  Device Discovery Callback Functions
707 *****************************************/
708 /* Callback function for asynchronous notifications when the BTM inquiry DB
709 ** changes. First param is inquiry database, second is if added to or removed
710 ** from the inquiry database.
711 */
712 typedef void (tBTM_INQ_DB_CHANGE_CB) (void *p1, BOOLEAN is_new);
713 
714 /* Callback function for notifications when the BTM gets inquiry response.
715 ** First param is inquiry results database, second is pointer of EIR.
716 */
717 typedef void (tBTM_INQ_RESULTS_CB) (tBTM_INQ_RESULTS *p_inq_results, UINT8 *p_eir);
718 
719 /*****************************************************************************
720 **  ACL CHANNEL MANAGEMENT
721 *****************************************************************************/
722 /******************
723 **  ACL Constants
724 *******************/
725 
726 /* ACL modes */
727 #define BTM_ACL_MODE_NORMAL     HCI_MODE_ACTIVE
728 #define BTM_ACL_MODE_HOLD       HCI_MODE_HOLD
729 #define BTM_ACL_MODE_SNIFF      HCI_MODE_SNIFF
730 #define BTM_ACL_MODE_PARK       HCI_MODE_PARK
731 
732 /* Returned with structure in role switch callback (tBTM_ROLE_SWITCH_CMPL) */
733 #define BTM_ROLE_MASTER         HCI_ROLE_MASTER
734 #define BTM_ROLE_SLAVE          HCI_ROLE_SLAVE
735 #define BTM_ROLE_UNDEFINED      0xff     /* undefined value (error status) */
736 
737 /* ACL Packet Types */
738 #define BTM_ACL_PKT_TYPES_MASK_DM1      HCI_PKT_TYPES_MASK_DM1
739 #define BTM_ACL_PKT_TYPES_MASK_DH1      HCI_PKT_TYPES_MASK_DH1
740 #define BTM_ACL_PKT_TYPES_MASK_DM3      HCI_PKT_TYPES_MASK_DM3
741 #define BTM_ACL_PKT_TYPES_MASK_DH3      HCI_PKT_TYPES_MASK_DH3
742 #define BTM_ACL_PKT_TYPES_MASK_DM5      HCI_PKT_TYPES_MASK_DM5
743 #define BTM_ACL_PKT_TYPES_MASK_DH5      HCI_PKT_TYPES_MASK_DH5
744 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 HCI_PKT_TYPES_MASK_NO_2_DH1
745 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 HCI_PKT_TYPES_MASK_NO_3_DH1
746 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 HCI_PKT_TYPES_MASK_NO_2_DH3
747 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 HCI_PKT_TYPES_MASK_NO_3_DH3
748 #define BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 HCI_PKT_TYPES_MASK_NO_2_DH5
749 #define BTM_ACL_PKT_TYPES_MASK_NO_3_DH5 HCI_PKT_TYPES_MASK_NO_3_DH5
750 
751 /***************
752 **  ACL Types
753 ****************/
754 
755 /* Structure returned with Role Switch information (in tBTM_CMPL_CB callback function)
756 ** in response to BTM_SwitchRole call.
757 */
758 typedef struct {
759     UINT8   hci_status;     /* HCI status returned with the event */
760     UINT8   role;           /* BTM_ROLE_MASTER or BTM_ROLE_SLAVE */
761     BD_ADDR remote_bd_addr; /* Remote BD addr involved with the switch */
762 } tBTM_ROLE_SWITCH_CMPL;
763 
764 /* Structure returned with QoS information (in tBTM_CMPL_CB callback function)
765 ** in response to BTM_SetQoS call.
766 */
767 typedef struct {
768     FLOW_SPEC flow;
769     UINT16 handle;
770     UINT8 status;
771     BD_ADDR     rem_bda;
772 } tBTM_QOS_SETUP_CMPL;
773 
774 
775 /* Structure returned with read RSSI event (in tBTM_CMPL_CB callback function)
776 ** in response to BTM_ReadRSSI call.
777 */
778 typedef struct {
779     tBTM_STATUS status;
780     UINT8       hci_status;
781     INT8        rssi;
782     BD_ADDR     rem_bda;
783 } tBTM_RSSI_RESULTS;
784 
785 /* Structure returned with read current TX power event (in tBTM_CMPL_CB callback function)
786 ** in response to BTM_ReadTxPower call.
787 */
788 typedef struct {
789     tBTM_STATUS status;
790     UINT8       hci_status;
791     INT8        tx_power;
792     BD_ADDR     rem_bda;
793 } tBTM_TX_POWER_RESULTS;
794 
795 /* Structure returned with read link quality event (in tBTM_CMPL_CB callback function)
796 ** in response to BTM_ReadLinkQuality call.
797 */
798 typedef struct {
799     tBTM_STATUS status;
800     UINT8       hci_status;
801     UINT8       link_quality;
802     BD_ADDR     rem_bda;
803 } tBTM_LINK_QUALITY_RESULTS;
804 
805 /* Structure returned with set AFH channels event (in tBTM_CMPL_CB callback function)
806 ** in response to BTM_SetAfhChannels call.
807 */
808 typedef struct {
809     tBTM_STATUS status;
810     UINT8       hci_status;
811 } tBTM_SET_AFH_CHANNELS_RESULTS;
812 
813 /* Structure returned with set BLE channels event (in tBTM_CMPL_CB callback function)
814 ** in response to BTM_BleSetChannels call.
815 */
816 typedef struct {
817     tBTM_STATUS status;
818     UINT8       hci_status;
819 } tBTM_BLE_SET_CHANNELS_RESULTS;
820 
821 /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB callback function)
822 ** in response to BTM_ReadInquiryRspTxPower call.
823 */
824 typedef struct {
825     tBTM_STATUS status;
826     UINT8       hci_status;
827     INT8        tx_power;
828 } tBTM_INQ_TXPWR_RESULTS;
829 
830 
831 enum {
832     BTM_ACL_CONN_CMPL_EVT,
833     BTM_ACL_DISCONN_CMPL_EVT
834 };
835 typedef UINT8 tBTM_ACL_LINK_STAT_EVENT;
836 
837 typedef struct {
838     UINT8                   status;   /* The status of ACL connection complete */
839     UINT16                  handle;   /* The ACL connection handle */
840     BD_ADDR                 bd_addr;  /* Peer Bluetooth device address */
841 } tBTM_ACL_CONN_CMPL_DATA;
842 
843 typedef struct {
844     UINT8                   reason;   /* The reason for ACL disconnection complete */
845     UINT16                  handle;   /* The ACL connection handle */
846     BD_ADDR                 bd_addr;  /* Peer Bluetooth device address */
847 } tBTM_ACL_DISCONN_CMPL_DATA;
848 
849 typedef struct {
850     tBTM_ACL_LINK_STAT_EVENT       event;          /* The event reported */
851     union {
852         tBTM_ACL_CONN_CMPL_DATA     conn_cmpl;     /* The data associated with BTM_ACL_CONN_CMPL_EVT */
853         tBTM_ACL_DISCONN_CMPL_DATA  disconn_cmpl;  /* The data associated with BTM_ACL_DISCONN_CMPL_EVT */
854     } link_act;
855 } tBTM_ACL_LINK_STAT_EVENT_DATA;
856 
857 /* Callback function for reporting ACL link related events to upper
858 */
859 typedef void (tBTM_ACL_LINK_STAT_CB) (tBTM_ACL_LINK_STAT_EVENT_DATA *p_data);
860 
861 enum {
862     BTM_BL_CONN_EVT,
863     BTM_BL_DISCN_EVT,
864     BTM_BL_UPDATE_EVT,
865     BTM_BL_ROLE_CHG_EVT,
866     BTM_BL_COLLISION_EVT
867 };
868 typedef UINT8 tBTM_BL_EVENT;
869 typedef UINT16 tBTM_BL_EVENT_MASK;
870 
871 #define BTM_BL_CONN_MASK        0x0001
872 #define BTM_BL_DISCN_MASK       0x0002
873 #define BTM_BL_UPDATE_MASK      0x0004
874 #define BTM_BL_ROLE_CHG_MASK    0x0008
875 
876 /* Device features mask definitions */
877 #define BTM_FEATURE_BYTES_PER_PAGE  HCI_FEATURE_BYTES_PER_PAGE
878 #define BTM_EXT_FEATURES_PAGE_MAX   HCI_EXT_FEATURES_PAGE_MAX
879 
880 /* the data type associated with BTM_BL_CONN_EVT */
881 typedef struct {
882     tBTM_BL_EVENT   event;          /* The event reported. */
883     BD_ADDR_PTR     p_bda;          /* The address of the newly connected device */
884     DEV_CLASS_PTR   p_dc;           /* The device class */
885     BD_NAME_PTR     p_bdn;          /* The device name */
886     UINT8          *p_features;     /* pointer to the remote device's features page[0] (supported features page) */
887     BOOLEAN         sc_downgrade;   /* Secure connection downgrade state. */
888 #if BLE_INCLUDED == TRUE
889     UINT16          handle;         /* connection handle */
890     tBT_TRANSPORT   transport;      /* link is LE or not */
891 #endif
892 } tBTM_BL_CONN_DATA;
893 
894 /* the data type associated with BTM_BL_DISCN_EVT */
895 typedef struct {
896     tBTM_BL_EVENT   event;  /* The event reported. */
897     BD_ADDR_PTR     p_bda;  /* The address of the disconnected device */
898 #if BLE_INCLUDED == TRUE
899     UINT16          handle; /* disconnected connection handle */
900     tBT_TRANSPORT   transport; /* link is LE link or not */
901 #endif
902 } tBTM_BL_DISCN_DATA;
903 
904 /* Busy-Level shall have the inquiry_paging mask set when
905  * inquiry/paging is in progress, Else the number of ACL links */
906 #define BTM_BL_INQUIRY_PAGING_MASK 0x10
907 #define BTM_BL_INQUIRY_STARTED   (BTM_BL_INQUIRY_PAGING_MASK | 0x1)
908 #define BTM_BL_INQUIRY_CANCELLED (BTM_BL_INQUIRY_PAGING_MASK | 0x2)
909 #define BTM_BL_INQUIRY_COMPLETE  (BTM_BL_INQUIRY_PAGING_MASK | 0x3)
910 #define BTM_BL_PAGING_STARTED    (BTM_BL_INQUIRY_PAGING_MASK | 0x4)
911 #define BTM_BL_PAGING_COMPLETE   (BTM_BL_INQUIRY_PAGING_MASK | 0x5)
912 /* the data type associated with BTM_BL_UPDATE_EVT */
913 typedef struct {
914     tBTM_BL_EVENT   event;  /* The event reported. */
915     UINT8           busy_level;/* when paging or inquiring, level is 10.
916                                 * Otherwise, the number of ACL links. */
917     UINT8           busy_level_flags; /* Notifies actual inquiry/page activities */
918 } tBTM_BL_UPDATE_DATA;
919 
920 /* the data type associated with BTM_BL_ROLE_CHG_EVT */
921 typedef struct {
922     tBTM_BL_EVENT   event;      /* The event reported. */
923     BD_ADDR_PTR     p_bda;      /* The address of the peer connected device */
924     UINT8           new_role;
925     UINT8           hci_status; /* HCI status returned with the event */
926 } tBTM_BL_ROLE_CHG_DATA;
927 
928 typedef union {
929     tBTM_BL_EVENT           event;  /* The event reported. */
930     tBTM_BL_CONN_DATA       conn;   /* The data associated with BTM_BL_CONN_EVT */
931     tBTM_BL_DISCN_DATA      discn;  /* The data associated with BTM_BL_DISCN_EVT */
932     tBTM_BL_UPDATE_DATA     update; /* The data associated with BTM_BL_UPDATE_EVT */
933     tBTM_BL_ROLE_CHG_DATA   role_chg;/*The data associated with BTM_BL_ROLE_CHG_EVT */
934 } tBTM_BL_EVENT_DATA;
935 
936 /* Callback function for notifications when the BTM busy level
937 ** changes.
938 */
939 typedef void (tBTM_BL_CHANGE_CB) (tBTM_BL_EVENT_DATA *p_data);
940 
941 /***************************
942 **  ACL Callback Functions
943 ****************************/
944 /* Callback function for notifications when the BTM ACL connection DB
945 ** changes. First param is BD address, second is if added or removed.
946 ** Registered through BTM_AclRegisterForChanges call.
947 */
948 #if BLE_INCLUDED == TRUE
949 typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc,
950                                       BD_NAME p_bdn, UINT8 *features,
951                                       BOOLEAN is_new, UINT16 handle,
952                                       tBT_TRANSPORT transport);
953 #else
954 typedef void (tBTM_ACL_DB_CHANGE_CB) (BD_ADDR p_bda, DEV_CLASS p_dc,
955                                       BD_NAME p_bdn, UINT8 *features,
956                                       BOOLEAN is_new);
957 #endif
958 /*****************************************************************************
959 **  SCO CHANNEL MANAGEMENT
960 *****************************************************************************/
961 /******************
962 **  SCO Constants
963 *******************/
964 
965 /* Define an invalid SCO index and an invalid HCI handle */
966 #define BTM_INVALID_SCO_INDEX       0xFFFF
967 #define BTM_INVALID_HCI_HANDLE      0xFFFF
968 
969 /* Define an invalid SCO disconnect reason */
970 #define BTM_INVALID_SCO_DISC_REASON 0xFFFF
971 
972 /* Define first active SCO index */
973 #define BTM_FIRST_ACTIVE_SCO_INDEX  BTM_MAX_SCO_LINKS
974 
975 /* Define SCO packet types used in APIs */
976 #define BTM_SCO_PKT_TYPES_MASK_HV1  HCI_ESCO_PKT_TYPES_MASK_HV1
977 #define BTM_SCO_PKT_TYPES_MASK_HV2  HCI_ESCO_PKT_TYPES_MASK_HV2
978 #define BTM_SCO_PKT_TYPES_MASK_HV3  HCI_ESCO_PKT_TYPES_MASK_HV3
979 #define BTM_SCO_PKT_TYPES_MASK_EV3  HCI_ESCO_PKT_TYPES_MASK_EV3
980 #define BTM_SCO_PKT_TYPES_MASK_EV4  HCI_ESCO_PKT_TYPES_MASK_EV4
981 #define BTM_SCO_PKT_TYPES_MASK_EV5  HCI_ESCO_PKT_TYPES_MASK_EV5
982 #define BTM_SCO_PKT_TYPES_MASK_NO_2_EV3  HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3
983 #define BTM_SCO_PKT_TYPES_MASK_NO_3_EV3  HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3
984 #define BTM_SCO_PKT_TYPES_MASK_NO_2_EV5  HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5
985 #define BTM_SCO_PKT_TYPES_MASK_NO_3_EV5  HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5
986 
987 #define BTM_SCO_LINK_ONLY_MASK  (BTM_SCO_PKT_TYPES_MASK_HV1 | \
988                                  BTM_SCO_PKT_TYPES_MASK_HV2 | \
989                                  BTM_SCO_PKT_TYPES_MASK_HV3)
990 
991 #define BTM_ESCO_LINK_ONLY_MASK (BTM_SCO_PKT_TYPES_MASK_EV3 | \
992                                  BTM_SCO_PKT_TYPES_MASK_EV4 | \
993                                  BTM_SCO_PKT_TYPES_MASK_EV5)
994 
995 #define BTM_SCO_LINK_ALL_PKT_MASK   (BTM_SCO_LINK_ONLY_MASK     | \
996                                      BTM_ESCO_LINK_ONLY_MASK)
997 
998 #define BTM_VALID_SCO_ALL_PKT_TYPE HCI_VALID_SCO_ALL_PKT_TYPE
999 
1000 /* Passed in BTM_CreateSco if the packet type parameter should be ignored */
1001 #define BTM_IGNORE_SCO_PKT_TYPE     0
1002 
1003 /***************
1004 **  SCO Types
1005 ****************/
1006 #define BTM_LINK_TYPE_SCO           HCI_LINK_TYPE_SCO
1007 #define BTM_LINK_TYPE_ESCO          HCI_LINK_TYPE_ESCO
1008 typedef UINT8 tBTM_SCO_TYPE;
1009 
1010 
1011 /*******************
1012 ** SCO Routing Path
1013 ********************/
1014 #define BTM_SCO_ROUTE_PCM           (0) // HCI_BRCM_SCO_ROUTE_PCM
1015 #define BTM_SCO_ROUTE_HCI           (1) // HCI_BRCM_SCO_ROUTE_HCI
1016 typedef UINT8 tBTM_SCO_ROUTE_TYPE;
1017 
1018 
1019 /*******************
1020 ** SCO Codec Types
1021 ********************/
1022 // TODO(google) This should use common definitions
1023 // in hci/include/hci_audio.h
1024 #define BTM_SCO_CODEC_NONE          0x0000
1025 #define BTM_SCO_CODEC_CVSD          0x0001
1026 #define BTM_SCO_CODEC_MSBC          0x0002
1027 typedef UINT16 tBTM_SCO_CODEC_TYPE;
1028 
1029 
1030 
1031 /*******************
1032 ** SCO Air Mode Types
1033 ********************/
1034 #define BTM_SCO_AIR_MODE_U_LAW          0
1035 #define BTM_SCO_AIR_MODE_A_LAW          1
1036 #define BTM_SCO_AIR_MODE_CVSD           2
1037 #define BTM_SCO_AIR_MODE_TRANSPNT       3
1038 #define BTM_SCO_AIR_MODE_UNKNOWN        0xFF
1039 typedef UINT8 tBTM_SCO_AIR_MODE_TYPE;
1040 
1041 /*******************
1042 ** SCO Voice Settings
1043 ********************/
1044 #define BTM_VOICE_SETTING_CVSD  ((UINT16)  (HCI_INP_CODING_LINEAR          |   \
1045                                             HCI_INP_DATA_FMT_2S_COMPLEMENT |   \
1046                                             HCI_INP_SAMPLE_SIZE_16BIT      |   \
1047                                             HCI_AIR_CODING_FORMAT_CVSD))
1048 
1049 #define BTM_VOICE_SETTING_TRANS ((UINT16)  (HCI_INP_CODING_LINEAR          |   \
1050                                             HCI_INP_DATA_FMT_2S_COMPLEMENT |   \
1051                                             HCI_INP_SAMPLE_SIZE_8BIT      |   \
1052                                             HCI_AIR_CODING_FORMAT_TRANSPNT))
1053 
1054 /*******************
1055 ** SCO Data Status
1056 ********************/
1057 enum {
1058     BTM_SCO_DATA_CORRECT,
1059     BTM_SCO_DATA_PAR_ERR,
1060     BTM_SCO_DATA_NONE,
1061     BTM_SCO_DATA_PAR_LOST
1062 };
1063 typedef UINT8 tBTM_SCO_DATA_FLAG;
1064 
1065 /***************************
1066 **  SCO Callback Functions
1067 ****************************/
1068 typedef void (tBTM_SCO_CB) (UINT16 sco_inx);
1069 typedef void (tBTM_SCO_DATA_CB) (UINT16 sco_inx, BT_HDR *p_data, tBTM_SCO_DATA_FLAG status);
1070 
1071 /******************
1072 **  eSCO Constants
1073 *******************/
1074 #define BTM_64KBITS_RATE            0x00001f40  /* 64 kbits/sec data rate */
1075 
1076 /* Retransmission effort */
1077 #define BTM_ESCO_RETRANS_OFF        0
1078 #define BTM_ESCO_RETRANS_POWER      1
1079 #define BTM_ESCO_RETRANS_QUALITY    2
1080 #define BTM_ESCO_RETRANS_DONTCARE   0xff
1081 
1082 /* Max Latency Don't Care */
1083 #define BTM_ESCO_MAX_LAT_DONTCARE   0xffff
1084 
1085 /***************
1086 **  eSCO Types
1087 ****************/
1088 /* tBTM_ESCO_CBACK event types */
1089 #define BTM_ESCO_CHG_EVT        1
1090 #define BTM_ESCO_CONN_REQ_EVT   2
1091 typedef UINT8 tBTM_ESCO_EVT;
1092 
1093 /* Passed into BTM_SetEScoMode() */
1094 typedef struct {
1095     UINT32 tx_bw;
1096     UINT32 rx_bw;
1097     UINT16 max_latency;
1098     UINT16 voice_contfmt;  /* Voice Settings or Content Format */
1099     UINT16 packet_types;
1100     UINT8  retrans_effort;
1101 } tBTM_ESCO_PARAMS;
1102 
1103 typedef struct {
1104     UINT16 max_latency;
1105     UINT16 packet_types;
1106     UINT8  retrans_effort;
1107 } tBTM_CHG_ESCO_PARAMS;
1108 
1109 /* Returned by BTM_ReadEScoLinkParms() */
1110 typedef struct {
1111     UINT16  rx_pkt_len;
1112     UINT16  tx_pkt_len;
1113     BD_ADDR bd_addr;
1114     UINT8   link_type;  /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
1115     UINT8   tx_interval;
1116     UINT8   retrans_window;
1117     UINT8   air_mode;
1118 } tBTM_ESCO_DATA;
1119 
1120 typedef struct {
1121     UINT16  sco_inx;
1122     UINT16  rx_pkt_len;
1123     UINT16  tx_pkt_len;
1124     BD_ADDR bd_addr;
1125     UINT8   hci_status;
1126     UINT8   tx_interval;
1127     UINT8   retrans_window;
1128 } tBTM_CHG_ESCO_EVT_DATA;
1129 
1130 typedef struct {
1131     UINT16        sco_inx;
1132     BD_ADDR       bd_addr;
1133     DEV_CLASS     dev_class;
1134     tBTM_SCO_TYPE link_type;
1135 } tBTM_ESCO_CONN_REQ_EVT_DATA;
1136 
1137 typedef union {
1138     tBTM_CHG_ESCO_EVT_DATA      chg_evt;
1139     tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
1140 } tBTM_ESCO_EVT_DATA;
1141 
1142 /***************************
1143 **  eSCO Callback Functions
1144 ****************************/
1145 typedef void (tBTM_ESCO_CBACK) (tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA *p_data);
1146 
1147 
1148 /*****************************************************************************
1149 **  SECURITY MANAGEMENT
1150 *****************************************************************************/
1151 /*******************************
1152 **  Security Manager Constants
1153 ********************************/
1154 
1155 /* Security Mode (BTM_SetSecurityMode) */
1156 #define BTM_SEC_MODE_UNDEFINED      0
1157 #define BTM_SEC_MODE_NONE           1
1158 #define BTM_SEC_MODE_SERVICE        2
1159 #define BTM_SEC_MODE_LINK           3
1160 #define BTM_SEC_MODE_SP             4
1161 #define BTM_SEC_MODE_SP_DEBUG       5
1162 #define BTM_SEC_MODE_SC             6
1163 
1164 /* Maximum Number of BTM Security Modes */
1165 #define BTM_SEC_MODES_MAX           7
1166 
1167 /* Security Service Levels [bit mask] (BTM_SetSecurityLevel)
1168 ** Encryption should not be used without authentication
1169 */
1170 #define BTM_SEC_NONE               0x0000 /* Nothing required */
1171 #define BTM_SEC_IN_AUTHORIZE       0x0001 /* Inbound call requires authorization */
1172 #define BTM_SEC_IN_AUTHENTICATE    0x0002 /* Inbound call requires authentication */
1173 #define BTM_SEC_IN_ENCRYPT         0x0004 /* Inbound call requires encryption */
1174 #define BTM_SEC_OUT_AUTHORIZE      0x0008 /* Outbound call requires authorization */
1175 #define BTM_SEC_OUT_AUTHENTICATE   0x0010 /* Outbound call requires authentication */
1176 #define BTM_SEC_OUT_ENCRYPT        0x0020 /* Outbound call requires encryption */
1177 #define BTM_SEC_MODE4_LEVEL4       0x0040 /* Secure Connections Only Mode */
1178 #define BTM_SEC_FORCE_MASTER       0x0100 /* Need to switch connection to be master */
1179 #define BTM_SEC_ATTEMPT_MASTER     0x0200 /* Try to switch connection to be master */
1180 #define BTM_SEC_FORCE_SLAVE        0x0400 /* Need to switch connection to be master */
1181 #define BTM_SEC_ATTEMPT_SLAVE      0x0800 /* Try to switch connection to be slave */
1182 #define BTM_SEC_IN_MITM            0x1000 /* inbound Do man in the middle protection */
1183 #define BTM_SEC_OUT_MITM           0x2000 /* outbound Do man in the middle protection */
1184 #define BTM_SEC_IN_MIN_16_DIGIT_PIN 0x4000 /* enforce a minimum of 16 digit for sec mode 2 */
1185 
1186 /* Security Flags [bit mask] (BTM_GetSecurityFlags)
1187 */
1188 #define BTM_SEC_FLAG_AUTHORIZED     0x01
1189 #define BTM_SEC_FLAG_AUTHENTICATED  0x02
1190 #define BTM_SEC_FLAG_ENCRYPTED      0x04
1191 #define BTM_SEC_FLAG_LKEY_KNOWN     0x10
1192 #define BTM_SEC_FLAG_LKEY_AUTHED    0x20
1193 
1194 /* PIN types */
1195 #define BTM_PIN_TYPE_VARIABLE       HCI_PIN_TYPE_VARIABLE
1196 #define BTM_PIN_TYPE_FIXED          HCI_PIN_TYPE_FIXED
1197 
1198 /* Link Key types used to generate the new link key.
1199 ** returned in link key notification callback function
1200 */
1201 #define BTM_LKEY_TYPE_COMBINATION   HCI_LKEY_TYPE_COMBINATION
1202 #define BTM_LKEY_TYPE_LOCAL_UNIT    HCI_LKEY_TYPE_LOCAL_UNIT
1203 #define BTM_LKEY_TYPE_REMOTE_UNIT   HCI_LKEY_TYPE_REMOTE_UNIT
1204 #define BTM_LKEY_TYPE_DEBUG_COMB    HCI_LKEY_TYPE_DEBUG_COMB
1205 #define BTM_LKEY_TYPE_UNAUTH_COMB   HCI_LKEY_TYPE_UNAUTH_COMB
1206 #define BTM_LKEY_TYPE_AUTH_COMB     HCI_LKEY_TYPE_AUTH_COMB
1207 #define BTM_LKEY_TYPE_CHANGED_COMB  HCI_LKEY_TYPE_CHANGED_COMB
1208 
1209 #define BTM_LKEY_TYPE_UNAUTH_COMB_P_256 HCI_LKEY_TYPE_UNAUTH_COMB_P_256
1210 #define BTM_LKEY_TYPE_AUTH_COMB_P_256   HCI_LKEY_TYPE_AUTH_COMB_P_256
1211 
1212 #define BTM_LTK_DERIVED_LKEY_OFFSET 0x20    /* "easy" requirements for Link Key (LK) derived from Long Term Key */
1213 #define BTM_LKEY_TYPE_IGNORE        0xff    /* used when event is response from
1214                                                hci return link keys request */
1215 
1216 typedef UINT8 tBTM_LINK_KEY_TYPE;
1217 
1218 /* Protocol level security (BTM_SetSecurityLevel) */
1219 #define BTM_SEC_PROTO_L2CAP         0
1220 #define BTM_SEC_PROTO_SDP           1
1221 #define BTM_SEC_PROTO_TCS           2
1222 #define BTM_SEC_PROTO_RFCOMM        3
1223 #define BTM_SEC_PROTO_OBEX          4
1224 #define BTM_SEC_PROTO_BNEP          5
1225 #define BTM_SEC_PROTO_HID           6   /* HID      */
1226 #define BTM_SEC_PROTO_AVDT          7
1227 #define BTM_SEC_PROTO_MCA           8
1228 
1229 /* Determine the number of UINT32's necessary for security services */
1230 #define BTM_SEC_ARRAY_BITS          32          /* Number of bits in each array element */
1231 #define BTM_SEC_SERVICE_ARRAY_SIZE  (((UINT32)BTM_SEC_MAX_SERVICES / BTM_SEC_ARRAY_BITS) + \
1232                                     (((UINT32)BTM_SEC_MAX_SERVICES % BTM_SEC_ARRAY_BITS) ? 1 : 0))
1233 
1234 /* Security service definitions (BTM_SetSecurityLevel)
1235 ** Used for Authorization APIs
1236 */
1237 #define BTM_SEC_SERVICE_SDP_SERVER      0
1238 #define BTM_SEC_SERVICE_SERIAL_PORT     1
1239 #define BTM_SEC_SERVICE_LAN_ACCESS      2
1240 #define BTM_SEC_SERVICE_DUN             3
1241 #define BTM_SEC_SERVICE_IRMC_SYNC       4
1242 #define BTM_SEC_SERVICE_IRMC_SYNC_CMD   5
1243 #define BTM_SEC_SERVICE_OBEX            6
1244 #define BTM_SEC_SERVICE_OBEX_FTP        7
1245 #define BTM_SEC_SERVICE_HEADSET         8
1246 #define BTM_SEC_SERVICE_CORDLESS        9
1247 #define BTM_SEC_SERVICE_INTERCOM        10
1248 #define BTM_SEC_SERVICE_FAX             11
1249 #define BTM_SEC_SERVICE_HEADSET_AG      12
1250 #define BTM_SEC_SERVICE_PNP_INFO        13
1251 #define BTM_SEC_SERVICE_GEN_NET         14
1252 #define BTM_SEC_SERVICE_GEN_FILE        15
1253 #define BTM_SEC_SERVICE_GEN_AUDIO       16
1254 #define BTM_SEC_SERVICE_GEN_TEL         17
1255 #define BTM_SEC_SERVICE_CTP_DATA        18
1256 #define BTM_SEC_SERVICE_HCRP_CTRL       19
1257 #define BTM_SEC_SERVICE_HCRP_DATA       20
1258 #define BTM_SEC_SERVICE_HCRP_NOTIF      21
1259 #define BTM_SEC_SERVICE_BPP_JOB         22
1260 #define BTM_SEC_SERVICE_BPP_STATUS      23
1261 #define BTM_SEC_SERVICE_BPP_REF         24
1262 #define BTM_SEC_SERVICE_BNEP_PANU       25
1263 #define BTM_SEC_SERVICE_BNEP_GN         26
1264 #define BTM_SEC_SERVICE_BNEP_NAP        27
1265 #define BTM_SEC_SERVICE_HF_HANDSFREE    28
1266 #define BTM_SEC_SERVICE_AG_HANDSFREE    29
1267 #define BTM_SEC_SERVICE_TE_PHONE_ACCESS 30
1268 #define BTM_SEC_SERVICE_ME_PHONE_ACCESS 31
1269 
1270 #define BTM_SEC_SERVICE_HIDH_SEC_CTRL   32
1271 #define BTM_SEC_SERVICE_HIDH_NOSEC_CTRL 33
1272 #define BTM_SEC_SERVICE_HIDH_INTR       34
1273 #define BTM_SEC_SERVICE_BIP             35
1274 #define BTM_SEC_SERVICE_BIP_REF         36
1275 #define BTM_SEC_SERVICE_AVDTP           37
1276 #define BTM_SEC_SERVICE_AVDTP_NOSEC     38
1277 #define BTM_SEC_SERVICE_AVCTP           39
1278 #define BTM_SEC_SERVICE_SAP             40
1279 #define BTM_SEC_SERVICE_PBAP            41
1280 #define BTM_SEC_SERVICE_RFC_MUX         42
1281 #define BTM_SEC_SERVICE_AVCTP_BROWSE    43
1282 #define BTM_SEC_SERVICE_MAP             44
1283 #define BTM_SEC_SERVICE_MAP_NOTIF       45
1284 #define BTM_SEC_SERVICE_MCAP_CTRL       46
1285 #define BTM_SEC_SERVICE_MCAP_DATA       47
1286 #define BTM_SEC_SERVICE_HDP_SNK         48
1287 #define BTM_SEC_SERVICE_HDP_SRC         49
1288 #define BTM_SEC_SERVICE_ATT             50
1289 #define BTM_SEC_SERVICE_HIDD_SEC_CTRL   51
1290 #define BTM_SEC_SERVICE_HIDD_NOSEC_CTRL 52
1291 #define BTM_SEC_SERVICE_HIDD_INTR       53
1292 
1293 /* Update these as services are added */
1294 #define BTM_SEC_SERVICE_FIRST_EMPTY     54
1295 
1296 #ifndef BTM_SEC_MAX_SERVICES
1297 #define BTM_SEC_MAX_SERVICES            65
1298 #endif
1299 
1300 /************************************************************************************************
1301 ** Security Services MACROS handle array of UINT32 bits for more than 32 trusted services
1302 *************************************************************************************************/
1303 /* MACRO to set the security service bit mask in a bit stream */
1304 #define BTM_SEC_SET_SERVICE(p, service)  (((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)] |=  \
1305                                     ((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS)))
1306 
1307 
1308 /* MACRO to clear the security service bit mask in a bit stream */
1309 #define BTM_SEC_CLR_SERVICE(p, service)  (((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)] &=  \
1310                                     ~((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS)))
1311 
1312 /* MACRO to check the security service bit mask in a bit stream (Returns TRUE or FALSE) */
1313 #define BTM_SEC_IS_SERVICE_TRUSTED(p, service)    (((((UINT32 *)(p))[(((UINT32)(service)) / BTM_SEC_ARRAY_BITS)]) &   \
1314                                         (UINT32)(((UINT32)1 << (((UINT32)(service)) % BTM_SEC_ARRAY_BITS)))) ? TRUE : FALSE)
1315 
1316 /* MACRO to copy two trusted device bitmask */
1317 #define BTM_SEC_COPY_TRUSTED_DEVICE(p_src, p_dst)   {UINT32 trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \
1318                                                         ((UINT32 *)(p_dst))[trst] = ((UINT32 *)(p_src))[trst];}
1319 
1320 /* MACRO to clear two trusted device bitmask */
1321 #define BTM_SEC_CLR_TRUSTED_DEVICE(p_dst)   {UINT32 trst; for (trst = 0; trst < BTM_SEC_SERVICE_ARRAY_SIZE; trst++) \
1322                                                         ((UINT32 *)(p_dst))[trst] = 0;}
1323 
1324 /* Following bits can be provided by host in the trusted_mask array */
1325 /* 0..31 bits of mask[0] (Least Significant Word) */
1326 #define BTM_SEC_TRUST_SDP_SERVER        (1 << BTM_SEC_SERVICE_SDP_SERVER)
1327 #define BTM_SEC_TRUST_SERIAL_PORT       (1 << BTM_SEC_SERVICE_SERIAL_PORT)
1328 #define BTM_SEC_TRUST_LAN_ACCESS        (1 << BTM_SEC_SERVICE_LAN_ACCESS)
1329 #define BTM_SEC_TRUST_DUN               (1 << BTM_SEC_SERVICE_DUN)
1330 #define BTM_SEC_TRUST_IRMC_SYNC         (1 << BTM_SEC_SERVICE_IRMC_SYNC)
1331 #define BTM_SEC_TRUST_IRMC_SYNC_CMD     (1 << BTM_SEC_SERVICE_IRMC_SYNC_CMD)
1332 #define BTM_SEC_TRUST_OBEX              (1 << BTM_SEC_SERVICE_OBEX)
1333 #define BTM_SEC_TRUST_OBEX_FTP          (1 << BTM_SEC_SERVICE_OBEX_FTP)
1334 #define BTM_SEC_TRUST_HEADSET           (1 << BTM_SEC_SERVICE_HEADSET)
1335 #define BTM_SEC_TRUST_CORDLESS          (1 << BTM_SEC_SERVICE_CORDLESS)
1336 #define BTM_SEC_TRUST_INTERCOM          (1 << BTM_SEC_SERVICE_INTERCOM)
1337 #define BTM_SEC_TRUST_FAX               (1 << BTM_SEC_SERVICE_FAX)
1338 #define BTM_SEC_TRUST_HEADSET_AG        (1 << BTM_SEC_SERVICE_HEADSET_AG)
1339 #define BTM_SEC_TRUST_PNP_INFO          (1 << BTM_SEC_SERVICE_PNP_INFO)
1340 #define BTM_SEC_TRUST_GEN_NET           (1 << BTM_SEC_SERVICE_GEN_NET)
1341 #define BTM_SEC_TRUST_GEN_FILE          (1 << BTM_SEC_SERVICE_GEN_FILE)
1342 #define BTM_SEC_TRUST_GEN_AUDIO         (1 << BTM_SEC_SERVICE_GEN_AUDIO)
1343 #define BTM_SEC_TRUST_GEN_TEL           (1 << BTM_SEC_SERVICE_GEN_TEL)
1344 #define BTM_SEC_TRUST_CTP_DATA          (1 << BTM_SEC_SERVICE_CTP_DATA)
1345 #define BTM_SEC_TRUST_HCRP_CTRL         (1 << BTM_SEC_SERVICE_HCRP_CTRL)
1346 #define BTM_SEC_TRUST_HCRP_DATA         (1 << BTM_SEC_SERVICE_HCRP_DATA)
1347 #define BTM_SEC_TRUST_HCRP_NOTIF        (1 << BTM_SEC_SERVICE_HCRP_NOTIF)
1348 #define BTM_SEC_TRUST_BPP_JOB           (1 << BTM_SEC_SERVICE_JOB)
1349 #define BTM_SEC_TRUST_BPP_STATUS        (1 << BTM_SEC_SERVICE_STATUS)
1350 #define BTM_SEC_TRUST_BPP_REF           (1 << BTM_SEC_SERVICE_REF)
1351 #define BTM_SEC_TRUST_BNEP_PANU         (1 << BTM_SEC_SERVICE_BNEP_PANU)
1352 #define BTM_SEC_TRUST_BNEP_GN           (1 << BTM_SEC_SERVICE_BNEP_GN)
1353 #define BTM_SEC_TRUST_BNEP_NAP          (1 << BTM_SEC_SERVICE_BNEP_NAP)
1354 #define BTM_SEC_TRUST_HFP_HF            (1 << BTM_SEC_SERVICE_HF_HANDSFREE)
1355 #define BTM_SEC_TRUST_HFP_AG            (1 << BTM_SEC_SERVICE_AG_HANDSFREE)
1356 #define BTM_SEC_TRUST_TE_PHONE_ACCESS   (1 << BTM_SEC_SERVICE_TE_PHONE_ACCESS)
1357 #define BTM_SEC_TRUST_ME_PHONE_ACCESS   (1 << BTM_SEC_SERVICE_ME_PHONE_ACCESS)
1358 
1359 /* 0..31 bits of mask[1] (Most Significant Word) */
1360 #define BTM_SEC_TRUST_HIDH_CTRL         (1 << (BTM_SEC_SERVICE_HIDH_SEC_CTRL - 32))
1361 #define BTM_SEC_TRUST_HIDH_NOSEC_CTRL   (1 << (BTM_SEC_SERVICE_HIDH_NOSEC_CTRL - 32))
1362 #define BTM_SEC_TRUST_HIDH_INTR         (1 << (BTM_SEC_SERVICE_HIDH_INTR - 32))
1363 #define BTM_SEC_TRUST_BIP               (1 << (BTM_SEC_SERVICE_BIP - 32))
1364 #define BTM_SEC_TRUST_BIP_REF           (1 << (BTM_SEC_SERVICE_BIP_REF - 32))
1365 #define BTM_SEC_TRUST_AVDTP             (1 << (BTM_SEC_SERVICE_AVDTP - 32))
1366 #define BTM_SEC_TRUST_AVDTP_NOSEC       (1 << (BTM_SEC_SERVICE_AVDTP_NOSEC - 32))
1367 #define BTM_SEC_TRUST_AVCTP             (1 << (BTM_SEC_SERVICE_AVCTP - 32))
1368 #define BTM_SEC_TRUST_SAP               (1 << (BTM_SEC_SERVICE_SAP - 32))
1369 #define BTM_SEC_TRUST_PBAP              (1 << (BTM_SEC_SERVICE_PBAP - 32))
1370 #define BTM_SEC_TRUST_RFC_MUX           (1 << (BTM_SEC_SERVICE_RFC_MUX - 32))
1371 #define BTM_SEC_TRUST_AVCTP_BROWSE      (1 << (BTM_SEC_SERVICE_AVCTP_BROWSE - 32))
1372 #define BTM_SEC_TRUST_MAP               (1 << (BTM_SEC_SERVICE_MAP - 32))
1373 #define BTM_SEC_TRUST_MAP_NOTIF         (1 << (BTM_SEC_SERVICE_MAP_NOTIF - 32))
1374 #define BTM_SEC_TRUST_MCAP_CTRL         (1 << (BTM_SEC_SERVICE_MCAP_CTRL - 32))
1375 #define BTM_SEC_TRUST_MCAP_DATA         (1 << (BTM_SEC_SERVICE_MCAP_DATA - 32))
1376 #define BTM_SEC_TRUST_HDP_SNK           (1 << (BTM_SEC_SERVICE_HDP_SNK - 32))
1377 #define BTM_SEC_TRUST_HDP_SRC           (1 << (BTM_SEC_SERVICE_HDP_SRC - 32))
1378 
1379 #define BTM_SEC_TRUST_ALL               0xFFFFFFFF  /* for each array element */
1380 
1381 /****************************************
1382 **  Security Manager Callback Functions
1383 *****************************************/
1384 /* Authorize device for service.  Parameters are
1385 **              BD Address of remote
1386 **              Device Class of remote
1387 **              BD Name of remote
1388 **              Service name
1389 **              Service Id (NULL - unknown service or unused
1390 **                                 [BTM_SEC_SERVICE_NAME_LEN set to 0])
1391 **              Is originator of the connection
1392 **              Result of the operation
1393 */
1394 typedef UINT8 (tBTM_AUTHORIZE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class,
1395         tBTM_BD_NAME bd_name, UINT8 *service_name,
1396         UINT8 service_id, BOOLEAN is_originator);
1397 
1398 /* Get PIN for the connection.  Parameters are
1399 **              BD Address of remote
1400 **              Device Class of remote
1401 **              BD Name of remote
1402 **              Flag indicating the minimum pin code length to be 16 digits
1403 */
1404 typedef UINT8 (tBTM_PIN_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class,
1405                                    tBTM_BD_NAME bd_name, BOOLEAN min_16_digit);
1406 
1407 /* New Link Key for the connection.  Parameters are
1408 **              BD Address of remote
1409 **              Link Key
1410 **              Key Type: Combination, Local Unit, or Remote Unit
1411 */
1412 typedef UINT8 (tBTM_LINK_KEY_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class,
1413                                         tBTM_BD_NAME bd_name, UINT8 *key,
1414                                         UINT8 key_type, BOOLEAN sc_support);
1415 
1416 
1417 /* Remote Name Resolved.  Parameters are
1418 **              BD Address of remote
1419 **              BD Name of remote
1420 */
1421 typedef void (tBTM_RMT_NAME_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dc,
1422                                        tBTM_BD_NAME bd_name);
1423 
1424 
1425 /* Authentication complete for the connection.  Parameters are
1426 **              BD Address of remote
1427 **              Device Class of remote
1428 **              BD Name of remote
1429 **
1430 */
1431 typedef UINT8 (tBTM_AUTH_COMPLETE_CALLBACK) (BD_ADDR bd_addr, DEV_CLASS dev_class,
1432         tBTM_BD_NAME bd_name, int result);
1433 
1434 enum {
1435     BTM_SP_IO_REQ_EVT,      /* received IO_CAPABILITY_REQUEST event */
1436     BTM_SP_IO_RSP_EVT,      /* received IO_CAPABILITY_RESPONSE event */
1437     BTM_SP_CFM_REQ_EVT,     /* received USER_CONFIRMATION_REQUEST event */
1438     BTM_SP_KEY_NOTIF_EVT,   /* received USER_PASSKEY_NOTIFY event */
1439     BTM_SP_KEY_REQ_EVT,     /* received USER_PASSKEY_REQUEST event */
1440     BTM_SP_KEYPRESS_EVT,    /* received KEYPRESS_NOTIFY event */
1441     BTM_SP_LOC_OOB_EVT,     /* received result for READ_LOCAL_OOB_DATA command */
1442     BTM_SP_RMT_OOB_EVT,     /* received REMOTE_OOB_DATA_REQUEST event */
1443     BTM_SP_COMPLT_EVT,      /* received SIMPLE_PAIRING_COMPLETE event */
1444     BTM_SP_UPGRADE_EVT      /* check if the application wants to upgrade the link key */
1445 };
1446 typedef UINT8 tBTM_SP_EVT;
1447 
1448 /* relate to ESP_IO_CAP_xxx in esp_gap_ble_api.h */
1449 #define BTM_IO_CAP_OUT      0   /* DisplayOnly */
1450 #define BTM_IO_CAP_IO       1   /* DisplayYesNo */
1451 #define BTM_IO_CAP_IN       2   /* KeyboardOnly */
1452 #define BTM_IO_CAP_NONE     3   /* NoInputNoOutput */
1453 // #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
1454 #define BTM_IO_CAP_KBDISP   4   /* Keyboard display */
1455 #define BTM_IO_CAP_MAX      5
1456 // #else
1457 // #define BTM_IO_CAP_MAX      4
1458 // #endif
1459 
1460 typedef UINT8 tBTM_IO_CAP;
1461 
1462 #define BTM_MAX_PASSKEY_VAL (999999)
1463 #define BTM_MIN_PASSKEY_VAL (0)
1464 
1465 #define BTM_AUTH_SP_NO      0   /* MITM Protection Not Required - Single Profile/non-bonding
1466                                 Numeric comparison with automatic accept allowed */
1467 #define BTM_AUTH_SP_YES     1   /* MITM Protection Required - Single Profile/non-bonding
1468                                 Use IO Capabilities to determine authentication procedure */
1469 #define BTM_AUTH_AP_NO      2   /* MITM Protection Not Required - All Profiles/dedicated bonding
1470                                 Numeric comparison with automatic accept allowed */
1471 #define BTM_AUTH_AP_YES     3   /* MITM Protection Required - All Profiles/dedicated bonding
1472                                 Use IO Capabilities to determine authentication procedure */
1473 #define BTM_AUTH_SPGB_NO    4   /* MITM Protection Not Required - Single Profiles/general bonding
1474                                 Numeric comparison with automatic accept allowed */
1475 #define BTM_AUTH_SPGB_YES   5   /* MITM Protection Required - Single Profiles/general bonding
1476                                 Use IO Capabilities to determine authentication procedure */
1477 #define BTM_AUTH_DD_BOND    2   /* this bit is ORed to the BTM_AUTH_SP_* when IO exchange for dedicated bonding */
1478 #define BTM_AUTH_GB_BIT     4   /* the genernal bonding bit */
1479 #define BTM_AUTH_BONDS      6   /* the general/dedicated bonding bits  */
1480 #define BTM_AUTH_YN_BIT     1   /* this is the Yes or No bit  */
1481 
1482 #define BTM_BLE_ENC_KEY_MASK    (1 << 0)
1483 #define BTM_BLE_ID_KEY_MASK     (1 << 1)
1484 #define BTM_BLE_CSR_KEY_MASK    (1 << 2)
1485 #define BTM_BLE_LINK_KEY_MASK   (1 << 3)
1486 
1487 #define BTM_BLE_INITIATOR_KEY_SIZE 15
1488 #define BTM_BLE_RESPONDER_KEY_SIZE 15
1489 #define BTM_BLE_MAX_KEY_SIZE       16
1490 #define BTM_BLE_MIN_KEY_SIZE       7
1491 
1492 typedef UINT8 tBTM_AUTH_REQ;
1493 
1494 enum {
1495     BTM_OOB_NONE,
1496     BTM_OOB_PRESENT
1497 #if BTM_OOB_INCLUDED == TRUE
1498     , BTM_OOB_UNKNOWN
1499 #endif
1500 };
1501 typedef UINT8 tBTM_OOB_DATA;
1502 
1503 /* data type for BTM_SP_IO_REQ_EVT */
1504 typedef struct {
1505     BD_ADDR         bd_addr;        /* peer address */
1506     tBTM_IO_CAP     io_cap;         /* local IO capabilities */
1507     tBTM_OOB_DATA   oob_data;       /* OOB data present (locally) for the peer device */
1508     tBTM_AUTH_REQ   auth_req;       /* Authentication required (for local device) */
1509     BOOLEAN         is_orig;        /* TRUE, if local device initiated the SP process */
1510 } tBTM_SP_IO_REQ;
1511 
1512 /* data type for BTM_SP_IO_RSP_EVT */
1513 typedef struct {
1514     BD_ADDR         bd_addr;        /* peer address */
1515     tBTM_IO_CAP     io_cap;         /* peer IO capabilities */
1516     tBTM_OOB_DATA   oob_data;       /* OOB data present at peer device for the local device */
1517     tBTM_AUTH_REQ   auth_req;       /* Authentication required for peer device */
1518 } tBTM_SP_IO_RSP;
1519 
1520 /* data type for BTM_SP_CFM_REQ_EVT */
1521 typedef struct {
1522     BD_ADDR         bd_addr;        /* peer address */
1523     DEV_CLASS       dev_class;      /* peer CoD */
1524     tBTM_BD_NAME    bd_name;        /* peer device name */
1525     UINT32          num_val;        /* the numeric value for comparison. If just_works, do not show this number to UI */
1526     BOOLEAN         just_works;     /* TRUE, if "Just Works" association model */
1527     tBTM_AUTH_REQ   loc_auth_req;   /* Authentication required for local device */
1528     tBTM_AUTH_REQ   rmt_auth_req;   /* Authentication required for peer device */
1529     tBTM_IO_CAP     loc_io_caps;    /* IO Capabilities of the local device */
1530     tBTM_IO_CAP     rmt_io_caps;    /* IO Capabilities of the remot device */
1531 } tBTM_SP_CFM_REQ;
1532 
1533 /* data type for BTM_SP_KEY_REQ_EVT */
1534 typedef struct {
1535     BD_ADDR         bd_addr;        /* peer address */
1536     DEV_CLASS       dev_class;      /* peer CoD */
1537     tBTM_BD_NAME    bd_name;        /* peer device name */
1538 } tBTM_SP_KEY_REQ;
1539 
1540 /* data type for BTM_SP_KEY_NOTIF_EVT */
1541 typedef struct {
1542     BD_ADDR         bd_addr;        /* peer address */
1543     DEV_CLASS       dev_class;      /* peer CoD */
1544     tBTM_BD_NAME    bd_name;        /* peer device name */
1545     UINT32          passkey;        /* passkey */
1546 } tBTM_SP_KEY_NOTIF;
1547 
1548 enum {
1549     BTM_SP_KEY_STARTED,         /* 0 - passkey entry started */
1550     BTM_SP_KEY_ENTERED,         /* 1 - passkey digit entered */
1551     BTM_SP_KEY_ERASED,          /* 2 - passkey digit erased */
1552     BTM_SP_KEY_CLEARED,         /* 3 - passkey cleared */
1553     BTM_SP_KEY_COMPLT,          /* 4 - passkey entry completed */
1554     BTM_SP_KEY_OUT_OF_RANGE     /* 5 - out of range */
1555 };
1556 typedef UINT8   tBTM_SP_KEY_TYPE;
1557 
1558 /* data type for BTM_SP_KEYPRESS_EVT */
1559 typedef struct {
1560     BD_ADDR             bd_addr;        /* peer address */
1561     tBTM_SP_KEY_TYPE   notif_type;
1562 } tBTM_SP_KEYPRESS;
1563 
1564 /* data type for BTM_SP_LOC_OOB_EVT */
1565 typedef struct {
1566     tBTM_STATUS     status;         /* */
1567     BT_OCTET16      c;              /* Simple Pairing Hash C */
1568     BT_OCTET16      r;              /* Simple Pairing Randomnizer R */
1569 } tBTM_SP_LOC_OOB;
1570 
1571 /* data type for BTM_SP_RMT_OOB_EVT */
1572 typedef struct {
1573     BD_ADDR         bd_addr;        /* peer address */
1574     DEV_CLASS       dev_class;      /* peer CoD */
1575     tBTM_BD_NAME    bd_name;        /* peer device name */
1576 } tBTM_SP_RMT_OOB;
1577 
1578 
1579 /* data type for BTM_SP_COMPLT_EVT */
1580 typedef struct {
1581     BD_ADDR         bd_addr;        /* peer address */
1582     DEV_CLASS       dev_class;      /* peer CoD */
1583     tBTM_BD_NAME    bd_name;        /* peer device name */
1584     tBTM_STATUS     status;         /* status of the simple pairing process */
1585 } tBTM_SP_COMPLT;
1586 
1587 /* data type for BTM_SP_UPGRADE_EVT */
1588 typedef struct {
1589     BD_ADDR         bd_addr;        /* peer address */
1590     BOOLEAN         upgrade;        /* TRUE, to upgrade the link key */
1591 } tBTM_SP_UPGRADE;
1592 
1593 typedef union {
1594     tBTM_SP_IO_REQ      io_req;     /* BTM_SP_IO_REQ_EVT      */
1595     tBTM_SP_IO_RSP      io_rsp;     /* BTM_SP_IO_RSP_EVT      */
1596     tBTM_SP_CFM_REQ     cfm_req;    /* BTM_SP_CFM_REQ_EVT     */
1597     tBTM_SP_KEY_NOTIF   key_notif;  /* BTM_SP_KEY_NOTIF_EVT   */
1598     tBTM_SP_KEY_REQ     key_req;    /* BTM_SP_KEY_REQ_EVT     */
1599     tBTM_SP_KEYPRESS    key_press;  /* BTM_SP_KEYPRESS_EVT    */
1600     tBTM_SP_LOC_OOB     loc_oob;    /* BTM_SP_LOC_OOB_EVT     */
1601     tBTM_SP_RMT_OOB     rmt_oob;    /* BTM_SP_RMT_OOB_EVT     */
1602     tBTM_SP_COMPLT      complt;     /* BTM_SP_COMPLT_EVT      */
1603     tBTM_SP_UPGRADE     upgrade;    /* BTM_SP_UPGRADE_EVT      */
1604 } tBTM_SP_EVT_DATA;
1605 
1606 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1607 ** events occur.
1608 */
1609 typedef UINT8 (tBTM_SP_CALLBACK) (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data);
1610 
1611 
1612 typedef void (tBTM_MKEY_CALLBACK) (BD_ADDR bd_addr, UINT8 status, UINT8 key_flag) ;
1613 
1614 /* Encryption enabled/disabled complete: Optionally passed with BTM_SetEncryption.
1615 ** Parameters are
1616 **              BD Address of remote
1617 **              optional data passed in by BTM_SetEncryption
1618 **              tBTM_STATUS - result of the operation
1619 */
1620 typedef void (tBTM_SEC_CBACK) (BD_ADDR bd_addr, tBT_TRANSPORT transport,
1621                                void *p_ref_data, tBTM_STATUS result);
1622 
1623 /* Bond Cancel complete. Parameters are
1624 **              Result of the cancel operation
1625 **
1626 */
1627 typedef void (tBTM_BOND_CANCEL_CMPL_CALLBACK) (tBTM_STATUS result);
1628 
1629 /* LE related event and data structure
1630 */
1631 /* relate to ESP_LE_KEY_xxx in esp_gap_ble_api.h */
1632 #if (SMP_INCLUDED == TRUE)
1633 #define BTM_LE_IO_REQ_EVT       SMP_IO_CAP_REQ_EVT     /* received IO_CAPABILITY_REQUEST event */
1634 #define BTM_LE_SEC_REQUEST_EVT  SMP_SEC_REQUEST_EVT    /* security request event */
1635 #define BTM_LE_KEY_NOTIF_EVT    SMP_PASSKEY_NOTIF_EVT  /* received USER_PASSKEY_NOTIFY event */
1636 #define BTM_LE_KEY_REQ_EVT      SMP_PASSKEY_REQ_EVT    /* received USER_PASSKEY_REQUEST event */
1637 #define BTM_LE_OOB_REQ_EVT      SMP_OOB_REQ_EVT        /* OOB data request event */
1638 #define BTM_LE_NC_REQ_EVT       SMP_NC_REQ_EVT          /* Numeric Comparison request event */
1639 #define BTM_LE_PR_KEYPR_NOT_EVT SMP_PEER_KEYPR_NOT_EVT /* Peer keypress notification recd event */
1640 /* SC OOB request event (both local and peer OOB data) can be expected in response */
1641 #define BTM_LE_SC_OOB_REQ_EVT   SMP_SC_OOB_REQ_EVT
1642 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
1643 #define BTM_LE_SC_LOC_OOB_EVT   SMP_SC_LOC_OOB_DATA_UP_EVT
1644 #define BTM_LE_BR_KEYS_REQ_EVT  SMP_BR_KEYS_REQ_EVT     /* SMP over BR keys request event */
1645 #define BTM_LE_COMPLT_EVT       SMP_COMPLT_EVT         /* SMP complete event */
1646 #define BTM_LE_LAST_FROM_SMP    BTM_LE_BR_KEYS_REQ_EVT
1647 #define BTM_LE_KEY_EVT          BTM_LE_LAST_FROM_SMP + 1 /* KEY update event */
1648 #endif  ///SMP_INCLUDED == TRUE
1649 typedef UINT8 tBTM_LE_EVT;
1650 
1651 #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
1652 #define BTM_LE_KEY_NONE           0
1653 #define BTM_LE_KEY_PENC      SMP_SEC_KEY_TYPE_ENC        /* encryption information of peer device */
1654 #define BTM_LE_KEY_PID       SMP_SEC_KEY_TYPE_ID         /* identity key of the peer device */
1655 #define BTM_LE_KEY_PCSRK     SMP_SEC_KEY_TYPE_CSRK      /* peer SRK */
1656 #define BTM_LE_KEY_PLK       SMP_SEC_KEY_TYPE_LK
1657 #define BTM_LE_KEY_LLK       (SMP_SEC_KEY_TYPE_LK << 4)
1658 #define BTM_LE_KEY_LENC      (SMP_SEC_KEY_TYPE_ENC << 4)  /* master role security information:div */
1659 #define BTM_LE_KEY_LID       (SMP_SEC_KEY_TYPE_ID << 4)   /* master device ID key */
1660 #define BTM_LE_KEY_LCSRK     (SMP_SEC_KEY_TYPE_CSRK << 4) /* local CSRK has been deliver to peer */
1661 #endif  ///BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
1662 typedef UINT8 tBTM_LE_KEY_TYPE;
1663 
1664 /* relate to ESP_LE_AUTH_xxx in esp_gap_ble_api.h */
1665 #if (SMP_INCLUDED == TRUE)
1666 #define BTM_LE_AUTH_REQ_NO_BOND SMP_AUTH_NO_BOND   /* 0 */
1667 #define BTM_LE_AUTH_REQ_BOND    SMP_AUTH_GEN_BOND  /* 1 << 0 */
1668 #define BTM_LE_AUTH_REQ_MITM    SMP_AUTH_YN_BIT    /* 1 << 2 */
1669 #endif  ///SMP_INCLUDED == TRUE
1670 typedef UINT8 tBTM_LE_AUTH_REQ;
1671 #if (SMP_INCLUDED == TRUE)
1672 #define BTM_LE_SC_SUPPORT_BIT           SMP_SC_SUPPORT_BIT     /* (1 << 3) */
1673 #define BTM_LE_KP_SUPPORT_BIT           SMP_KP_SUPPORT_BIT     /* (1 << 4) */
1674 
1675 #define BTM_LE_AUTH_REQ_SC_ONLY         SMP_AUTH_SC_ENC_ONLY    /* 1 << 3 */
1676 #define BTM_LE_AUTH_REQ_SC_BOND         SMP_AUTH_SC_GB          /* 1001 */
1677 #define BTM_LE_AUTH_REQ_SC_MITM         SMP_AUTH_SC_MITM_NB     /* 1100 */
1678 #define BTM_LE_AUTH_REQ_SC_MITM_BOND    SMP_AUTH_SC_MITM_GB     /* 1101 */
1679 #define BTM_LE_AUTH_REQ_MASK            SMP_AUTH_MASK           /* 0x1D */
1680 
1681 /* LE security level */
1682 #define BTM_LE_SEC_NONE             SMP_SEC_NONE
1683 #define BTM_LE_SEC_UNAUTHENTICATE   SMP_SEC_UNAUTHENTICATE      /* 1 */
1684 #define BTM_LE_SEC_AUTHENTICATED    SMP_SEC_AUTHENTICATED       /* 4 */
1685 #endif  ///SMP_INCLUDED == TRUE
1686 typedef UINT8 tBTM_LE_SEC;
1687 
1688 
1689 typedef struct {
1690     tBTM_IO_CAP         io_cap;         /* local IO capabilities */
1691     UINT8               oob_data;       /* OOB data present (locally) for the peer device */
1692     tBTM_LE_AUTH_REQ    auth_req;       /* Authentication request (for local device) contain bonding and MITM info */
1693     UINT8               max_key_size;   /* max encryption key size */
1694     tBTM_LE_KEY_TYPE    init_keys;      /* keys to be distributed, bit mask */
1695     tBTM_LE_KEY_TYPE    resp_keys;      /* keys to be distributed, bit mask */
1696 } tBTM_LE_IO_REQ;
1697 
1698 #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
1699 /* data type for tBTM_LE_COMPLT */
1700 typedef struct {
1701     UINT8 reason;
1702     UINT8 sec_level;
1703     BOOLEAN is_pair_cancel;
1704     BOOLEAN smp_over_br;
1705     tSMP_AUTH_REQ auth_mode;
1706 } tBTM_LE_COMPLT;
1707 #endif
1708 
1709 /* BLE encryption keys */
1710 typedef struct {
1711     BT_OCTET16  ltk;
1712     BT_OCTET8   rand;
1713     UINT16      ediv;
1714     UINT8       sec_level;
1715     UINT8       key_size;
1716 } tBTM_LE_PENC_KEYS;
1717 
1718 /* BLE CSRK keys */
1719 typedef struct {
1720     UINT32          counter;
1721     BT_OCTET16      csrk;
1722     UINT8           sec_level;
1723 } tBTM_LE_PCSRK_KEYS;
1724 
1725 /* BLE Encryption reproduction keys */
1726 typedef struct {
1727     BT_OCTET16  ltk;
1728     UINT16      div;
1729     UINT8       key_size;
1730     UINT8       sec_level;
1731 } tBTM_LE_LENC_KEYS;
1732 
1733 /* BLE SRK keys */
1734 typedef struct {
1735     UINT32          counter;
1736     UINT16          div;
1737     UINT8           sec_level;
1738     BT_OCTET16      csrk;
1739 } tBTM_LE_LCSRK_KEYS;
1740 
1741 typedef struct {
1742     BT_OCTET16          irk;
1743     tBLE_ADDR_TYPE      addr_type;
1744     BD_ADDR             static_addr;
1745 } tBTM_LE_PID_KEYS;
1746 
1747 typedef union {
1748     tBTM_LE_PENC_KEYS   penc_key;       /* received peer encryption key */
1749     tBTM_LE_PCSRK_KEYS  pcsrk_key;      /* received peer device SRK */
1750     tBTM_LE_PID_KEYS    pid_key;        /* peer device ID key */
1751     tBTM_LE_LENC_KEYS   lenc_key;       /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
1752     tBTM_LE_LCSRK_KEYS   lcsrk_key;     /* local device CSRK = d1(ER,DIV,1)*/
1753 } tBTM_LE_KEY_VALUE;
1754 
1755 typedef struct {
1756     tBTM_LE_KEY_TYPE        key_type;
1757     tBTM_LE_KEY_VALUE       *p_key_value;
1758 } tBTM_LE_KEY;
1759 
1760 typedef union {
1761     tBTM_LE_IO_REQ      io_req;     /* BTM_LE_IO_REQ_EVT      */
1762     UINT32              key_notif;  /* BTM_LE_KEY_NOTIF_EVT   */
1763     /* BTM_LE_NC_REQ_EVT */
1764     /* no callback data for BTM_LE_KEY_REQ_EVT */
1765     /* and BTM_LE_OOB_REQ_EVT  */
1766 #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
1767     tBTM_LE_COMPLT      complt;     /* BTM_LE_COMPLT_EVT      */
1768     tSMP_OOB_DATA_TYPE  req_oob_type;
1769     tSMP_LOC_OOB_DATA   local_oob_data;
1770 #endif
1771     tBTM_LE_KEY         key;
1772 } tBTM_LE_EVT_DATA;
1773 
1774 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
1775 ** events occur.
1776 */
1777 typedef UINT8 (tBTM_LE_CALLBACK) (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data);
1778 
1779 #define BTM_BLE_KEY_TYPE_ID         1
1780 #define BTM_BLE_KEY_TYPE_ER         2
1781 #define BTM_BLE_KEY_TYPE_COUNTER    3  //tobe obsolete
1782 
1783 typedef struct {
1784     BT_OCTET16       ir;
1785     BT_OCTET16       irk;
1786     BT_OCTET16       dhk;
1787 
1788 } tBTM_BLE_LOCAL_ID_KEYS;
1789 
1790 typedef union {
1791     tBTM_BLE_LOCAL_ID_KEYS  id_keys;
1792     BT_OCTET16              er;
1793 } tBTM_BLE_LOCAL_KEYS;
1794 
1795 
1796 /* New LE identity key for local device.
1797 */
1798 typedef void (tBTM_LE_KEY_CALLBACK) (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key);
1799 
1800 
1801 /***************************
1802 **  Security Manager Types
1803 ****************************/
1804 /* Structure that applications use to register with BTM_SecRegister */
1805 typedef struct {
1806     tBTM_AUTHORIZE_CALLBACK     *p_authorize_callback;
1807     tBTM_PIN_CALLBACK           *p_pin_callback;
1808     tBTM_LINK_KEY_CALLBACK      *p_link_key_callback;
1809     tBTM_AUTH_COMPLETE_CALLBACK *p_auth_complete_callback;
1810     tBTM_BOND_CANCEL_CMPL_CALLBACK *p_bond_cancel_cmpl_callback;
1811     tBTM_SP_CALLBACK            *p_sp_callback;
1812 #if BLE_INCLUDED == TRUE
1813 #if SMP_INCLUDED == TRUE
1814     tBTM_LE_CALLBACK            *p_le_callback;
1815 #endif
1816     tBTM_LE_KEY_CALLBACK        *p_le_key_callback;
1817 #endif
1818 } tBTM_APPL_INFO;
1819 
1820 /* Callback function for when a link supervision timeout event occurs.
1821 ** This asynchronous event is enabled/disabled by calling BTM_RegForLstoEvt().
1822 */
1823 typedef void (tBTM_LSTO_CBACK) (BD_ADDR remote_bda, UINT16 timeout);
1824 
1825 /*****************************************************************************
1826 **  POWER MANAGEMENT
1827 *****************************************************************************/
1828 /****************************
1829 **  Power Manager Constants
1830 *****************************/
1831 /* BTM Power manager status codes */
1832 enum {
1833     BTM_PM_STS_ACTIVE = HCI_MODE_ACTIVE,
1834     BTM_PM_STS_HOLD   = HCI_MODE_HOLD,
1835     BTM_PM_STS_SNIFF  = HCI_MODE_SNIFF,
1836     BTM_PM_STS_PARK   = HCI_MODE_PARK,
1837     BTM_PM_STS_SSR,     /* report the SSR parameters in HCI_SNIFF_SUB_RATE_EVT */
1838     BTM_PM_STS_PENDING,   /* when waiting for status from controller */
1839     BTM_PM_STS_ERROR   /* when HCI command status returns error */
1840 };
1841 typedef UINT8 tBTM_PM_STATUS;
1842 
1843 /* BTM Power manager modes */
1844 enum {
1845     BTM_PM_MD_ACTIVE = BTM_PM_STS_ACTIVE,
1846     BTM_PM_MD_HOLD   = BTM_PM_STS_HOLD,
1847     BTM_PM_MD_SNIFF  = BTM_PM_STS_SNIFF,
1848     BTM_PM_MD_PARK   = BTM_PM_STS_PARK,
1849     BTM_PM_MD_FORCE  = 0x10 /* OR this to force ACL link to a certain mode */
1850 };
1851 typedef UINT8 tBTM_PM_MODE;
1852 
1853 #define BTM_PM_SET_ONLY_ID  0x80
1854 
1855 /* Operation codes */
1856 #define BTM_PM_REG_SET      1 /* The module wants to set the desired power mode */
1857 #define BTM_PM_REG_NOTIF    2 /* The module wants to receive mode change event */
1858 #define BTM_PM_DEREG        4 /* The module does not want to involve with PM anymore */
1859 
1860 /************************
1861 **  Power Manager Types
1862 *************************/
1863 typedef struct {
1864     UINT16          max;
1865     UINT16          min;
1866     UINT16          attempt;
1867     UINT16          timeout;
1868     tBTM_PM_MODE    mode;
1869 } tBTM_PM_PWR_MD;
1870 
1871 /*************************************
1872 **  Power Manager Callback Functions
1873 **************************************/
1874 typedef void (tBTM_PM_STATUS_CBACK) (BD_ADDR p_bda, tBTM_PM_STATUS status,
1875                                      UINT16 value, UINT8 hci_status);
1876 
1877 
1878 /************************
1879 **  Stored Linkkey Types
1880 *************************/
1881 #define BTM_CB_EVT_DELETE_STORED_LINK_KEYS  4
1882 
1883 typedef struct {
1884     UINT8          event;
1885     UINT8          status;
1886     UINT16         num_keys;
1887 
1888 } tBTM_DELETE_STORED_LINK_KEY_COMPLETE;
1889 
1890 /* MIP evnets, callbacks    */
1891 enum {
1892     BTM_MIP_MODE_CHG_EVT,
1893     BTM_MIP_DISCONNECT_EVT,
1894     BTM_MIP_PKTS_COMPL_EVT,
1895     BTM_MIP_RXDATA_EVT
1896 };
1897 typedef UINT8 tBTM_MIP_EVT;
1898 
1899 typedef struct {
1900     tBTM_MIP_EVT    event;
1901     BD_ADDR         bd_addr;
1902     UINT16          mip_id;
1903 } tBTM_MIP_MODE_CHANGE;
1904 
1905 typedef struct {
1906     tBTM_MIP_EVT    event;
1907     UINT16          mip_id;
1908     UINT8           disc_reason;
1909 } tBTM_MIP_CONN_TIMEOUT;
1910 
1911 #define BTM_MIP_MAX_RX_LEN  17
1912 
1913 typedef struct {
1914     tBTM_MIP_EVT    event;
1915     UINT16          mip_id;
1916     UINT8           rx_len;
1917     UINT8           rx_data[BTM_MIP_MAX_RX_LEN];
1918 } tBTM_MIP_RXDATA;
1919 
1920 typedef struct {
1921     tBTM_MIP_EVT    event;
1922     BD_ADDR         bd_addr;
1923     UINT8           data[11];       /* data[0] shows Vender-specific device type */
1924 } tBTM_MIP_EIR_HANDSHAKE;
1925 
1926 typedef struct {
1927     tBTM_MIP_EVT    event;
1928     UINT16          num_sent;       /* Number of packets completed at the controller */
1929 } tBTM_MIP_PKTS_COMPL;
1930 
1931 typedef union {
1932     tBTM_MIP_EVT            event;
1933     tBTM_MIP_MODE_CHANGE    mod_chg;
1934     tBTM_MIP_CONN_TIMEOUT   conn_tmo;
1935     tBTM_MIP_EIR_HANDSHAKE  eir;
1936     tBTM_MIP_PKTS_COMPL     completed;
1937     tBTM_MIP_RXDATA         rxdata;
1938 } tBTM_MIP_EVENT_DATA;
1939 
1940 /* MIP event callback function  */
1941 typedef void (tBTM_MIP_EVENTS_CB) (tBTM_MIP_EVT event, tBTM_MIP_EVENT_DATA data);
1942 
1943 /* MIP Device query callback function  */
1944 typedef BOOLEAN (tBTM_MIP_QUERY_CB) (BD_ADDR dev_addr, UINT8 *p_mode, LINK_KEY link_key);
1945 
1946 #define BTM_CONTRL_ACTIVE  1       /* ACL link on, SCO link ongoing, sniff mode */
1947 #define BTM_CONTRL_SCAN    2       /* Scan state - paging/inquiry/trying to connect*/
1948 #define BTM_CONTRL_IDLE    3       /* Idle state - page scan, LE advt, inquiry scan */
1949 
1950 typedef UINT8 tBTM_CONTRL_STATE;
1951 
1952 /*****************************************************************************
1953 **  EXTERNAL FUNCTION DECLARATIONS
1954 *****************************************************************************/
1955 
1956 #ifdef __cplusplus
1957 extern "C" {
1958 #endif
1959 
1960 /*****************************************************************************
1961 **  DEVICE CONTROL and COMMON FUNCTIONS
1962 *****************************************************************************/
1963 
1964 /*******************************************************************************
1965 **
1966 ** Function         BTM_DeviceReset
1967 **
1968 ** Description      This function is called to reset the controller.The Callback function
1969 **                  if provided is called when startup of the device has
1970 **                  completed.
1971 **
1972 ** Returns          void
1973 **
1974 *******************************************************************************/
1975 //extern
1976 void BTM_DeviceReset (tBTM_CMPL_CB *p_cb);
1977 
1978 
1979 /*******************************************************************************
1980 **
1981 ** Function         BTM_IsDeviceUp
1982 **
1983 ** Description      This function is called to check if the device is up.
1984 **
1985 ** Returns          TRUE if device is up, else FALSE
1986 **
1987 *******************************************************************************/
1988 //extern
1989 BOOLEAN BTM_IsDeviceUp (void);
1990 
1991 
1992 /*******************************************************************************
1993 **
1994 ** Function         BTM_SetLocalDeviceName
1995 **
1996 ** Description      This function is called to set the local device name.
1997 **
1998 ** Returns          BTM_CMD_STARTED if successful, otherwise an error
1999 **
2000 *******************************************************************************/
2001 //extern
2002 tBTM_STATUS BTM_SetLocalDeviceName (char *p_name);
2003 
2004 /*******************************************************************************
2005 **
2006 ** Function         BTM_SetDeviceClass
2007 **
2008 ** Description      This function is called to set the local device class
2009 **
2010 ** Returns          BTM_SUCCESS if successful, otherwise an error
2011 **
2012 *******************************************************************************/
2013 //extern
2014 tBTM_STATUS  BTM_SetDeviceClass (DEV_CLASS dev_class);
2015 
2016 
2017 /*******************************************************************************
2018 **
2019 ** Function         BTM_ReadLocalDeviceName
2020 **
2021 ** Description      This function is called to read the local device name.
2022 **
2023 ** Returns          status of the operation
2024 **                  If success, BTM_SUCCESS is returned and p_name points stored
2025 **                              local device name
2026 **                  If BTM doesn't store local device name, BTM_NO_RESOURCES is
2027 **                              is returned and p_name is set to NULL
2028 **
2029 *******************************************************************************/
2030 //extern
2031 tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name);
2032 
2033 /*******************************************************************************
2034 **
2035 ** Function         BTM_ReadLocalDeviceNameFromController
2036 **
2037 ** Description      Get local device name from controller. Do not use cached
2038 **                  name (used to get chip-id prior to btm reset complete).
2039 **
2040 ** Returns          BTM_CMD_STARTED if successful, otherwise an error
2041 **
2042 *******************************************************************************/
2043 //extern
2044 tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback);
2045 
2046 /*******************************************************************************
2047 **
2048 ** Function         BTM_ReadDeviceClass
2049 **
2050 ** Description      This function is called to read the local device class
2051 **
2052 ** Returns          pointer to the device class
2053 **
2054 *******************************************************************************/
2055 //extern
2056 UINT8 *BTM_ReadDeviceClass (void);
2057 
2058 
2059 /*******************************************************************************
2060 **
2061 ** Function         BTM_ReadLocalFeatures
2062 **
2063 ** Description      This function is called to read the local features
2064 **
2065 ** Returns          pointer to the local features string
2066 **
2067 *******************************************************************************/
2068 //extern
2069 UINT8 *BTM_ReadLocalFeatures (void);
2070 
2071 /*******************************************************************************
2072 **
2073 ** Function         BTM_RegisterForDeviceStatusNotif
2074 **
2075 ** Description      This function is called to register for device status
2076 **                  change notifications.
2077 **
2078 ** Returns          pointer to previous caller's callback function or NULL if first
2079 **                  registration.
2080 **
2081 *******************************************************************************/
2082 //extern
2083 tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb);
2084 
2085 
2086 /*******************************************************************************
2087 **
2088 ** Function         BTM_RegisterForVSEvents
2089 **
2090 ** Description      This function is called to register/deregister for vendor
2091 **                  specific HCI events.
2092 **
2093 **                  If is_register=TRUE, then the function will be registered;
2094 **                  if is_register=FALSE, then the function will be deregistered.
2095 **
2096 ** Returns          BTM_SUCCESS if successful,
2097 **                  BTM_BUSY if maximum number of callbacks have already been
2098 **                           registered.
2099 **
2100 *******************************************************************************/
2101 //extern
2102 tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register);
2103 
2104 
2105 /*******************************************************************************
2106 **
2107 ** Function         BTM_VendorSpecificCommand
2108 **
2109 ** Description      Send a vendor specific HCI command to the controller.
2110 **
2111 ** Returns
2112 **      BTM_SUCCESS         Command sent. Does not expect command complete
2113 **                              event. (command cmpl callback param is NULL)
2114 **      BTM_CMD_STARTED     Command sent. Waiting for command cmpl event.
2115 **      BTM_BUSY            Command not sent. Waiting for cmd cmpl event for
2116 **                              prior command.
2117 **
2118 *******************************************************************************/
2119 //extern
2120 tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode,
2121                                       UINT8 param_len,
2122                                       UINT8 *p_param_buf,
2123                                       tBTM_VSC_CMPL_CB *p_cb);
2124 
2125 
2126 /*******************************************************************************
2127 **
2128 ** Function         BTM_AllocateSCN
2129 **
2130 ** Description      Look through the Server Channel Numbers for a free one to be
2131 **                  used with an RFCOMM connection.
2132 **
2133 ** Returns          Allocated SCN number or 0 if none.
2134 **
2135 *******************************************************************************/
2136 //extern
2137 #if (CLASSIC_BT_INCLUDED == TRUE)
2138 UINT8 BTM_AllocateSCN(void);
2139 
2140 // btla-specific ++
2141 /*******************************************************************************
2142 **
2143 ** Function         BTM_TryAllocateSCN
2144 **
2145 ** Description      Try to allocate a fixed server channel
2146 **
2147 ** Returns          Returns TRUE if server channel was available
2148 **
2149 *******************************************************************************/
2150 //extern
2151 BOOLEAN BTM_TryAllocateSCN(UINT8 scn);
2152 // btla-specific --
2153 
2154 
2155 /*******************************************************************************
2156 **
2157 ** Function         BTM_FreeSCN
2158 **
2159 ** Description      Free the specified SCN.
2160 **
2161 ** Returns          TRUE if successful, FALSE if SCN is not in use or invalid
2162 **
2163 *******************************************************************************/
2164 //extern
2165 BOOLEAN BTM_FreeSCN(UINT8 scn);
2166 #endif  ///CLASSIC_BT_INCLUDED == TRUE
2167 
2168 
2169 /*******************************************************************************
2170 **
2171 ** Function         BTM_SetTraceLevel
2172 **
2173 ** Description      This function sets the trace level for BTM.  If called with
2174 **                  a value of 0xFF, it simply returns the current trace level.
2175 **
2176 ** Returns          The new or current trace level
2177 **
2178 *******************************************************************************/
2179 //extern
2180 UINT8 BTM_SetTraceLevel (UINT8 new_level);
2181 
2182 
2183 /*******************************************************************************
2184 **
2185 ** Function         BTM_WritePageTimeout
2186 **
2187 ** Description      Send HCI Wite Page Timeout.
2188 **
2189 ** Returns
2190 **      BTM_SUCCESS         Command sent.
2191 **      BTM_NO_RESOURCES    If out of resources to send the command.
2192 **
2193 *******************************************************************************/
2194 //extern
2195 tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout);
2196 
2197 /*******************************************************************************
2198 **
2199 ** Function         BTM_WriteVoiceSettings
2200 **
2201 ** Description      Send HCI Write Voice Settings command.
2202 **                  See stack/hcidefs.h for settings bitmask values.
2203 **
2204 ** Returns
2205 **      BTM_SUCCESS         Command sent.
2206 **      BTM_NO_RESOURCES     If out of resources to send the command.
2207 **
2208 **
2209 *******************************************************************************/
2210 //extern
2211 tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings);
2212 
2213 /*******************************************************************************
2214 **
2215 ** Function         BTM_EnableTestMode
2216 **
2217 ** Description      Send HCI the enable device under test command.
2218 **
2219 **                  Note: Controller can only be taken out of this mode by
2220 **                      resetting the controller.
2221 **
2222 ** Returns
2223 **      BTM_SUCCESS         Command sent.
2224 **      BTM_NO_RESOURCES    If out of resources to send the command.
2225 **
2226 **
2227 *******************************************************************************/
2228 //extern
2229 tBTM_STATUS BTM_EnableTestMode(void);
2230 
2231 
2232 /*****************************************************************************
2233 **  DEVICE DISCOVERY FUNCTIONS - Inquiry, Remote Name, Discovery, Class of Device
2234 *****************************************************************************/
2235 
2236 /*******************************************************************************
2237 **
2238 ** Function         BTM_SetDiscoverability
2239 **
2240 ** Description      This function is called to set the device into or out of
2241 **                  discoverable mode. Discoverable mode means inquiry
2242 **                  scans are enabled.  If a value of '0' is entered for window or
2243 **                  interval, the default values are used.
2244 **
2245 ** Returns          BTM_SUCCESS if successful
2246 **                  BTM_BUSY if a setting of the filter is already in progress
2247 **                  BTM_NO_RESOURCES if couldn't get a memory pool buffer
2248 **                  BTM_ILLEGAL_VALUE if a bad parameter was detected
2249 **                  BTM_WRONG_MODE if the device is not up.
2250 **
2251 *******************************************************************************/
2252 //extern
2253 tBTM_STATUS  BTM_SetDiscoverability (UINT16 inq_mode, UINT16 window,
2254                                      UINT16 interval);
2255 
2256 
2257 /*******************************************************************************
2258 **
2259 ** Function         BTM_ReadDiscoverability
2260 **
2261 ** Description      This function is called to read the current discoverability
2262 **                  mode of the device.
2263 **
2264 ** Output Params:   p_window - current inquiry scan duration
2265 **                  p_interval - current inquiry scan interval
2266 **
2267 ** Returns          BTM_NON_DISCOVERABLE, BTM_LIMITED_DISCOVERABLE, or
2268 **                  BTM_GENERAL_DISCOVERABLE
2269 **
2270 *******************************************************************************/
2271 //extern
2272 UINT16       BTM_ReadDiscoverability (UINT16 *p_window,
2273                                       UINT16 *p_interval);
2274 
2275 
2276 /*******************************************************************************
2277 **
2278 ** Function         BTM_SetPeriodicInquiryMode
2279 **
2280 ** Description      This function is called to set the device periodic inquiry mode.
2281 **                  If the duration is zero, the periodic inquiry mode is cancelled.
2282 **
2283 ** Parameters:      p_inqparms - pointer to the inquiry information
2284 **                      mode - GENERAL or LIMITED inquiry
2285 **                      duration - length in 1.28 sec intervals (If '0', the inquiry is CANCELLED)
2286 **                      max_resps - maximum amount of devices to search for before ending the inquiry
2287 **                      filter_cond_type - BTM_CLR_INQUIRY_FILTER, BTM_FILTER_COND_DEVICE_CLASS, or
2288 **                                         BTM_FILTER_COND_BD_ADDR
2289 **                      filter_cond - value for the filter (based on filter_cond_type)
2290 **
2291 **                  max_delay - maximum amount of time between successive inquiries
2292 **                  min_delay - minimum amount of time between successive inquiries
2293 **                  p_results_cb - callback returning pointer to results (tBTM_INQ_RESULTS)
2294 **
2295 ** Returns          BTM_CMD_STARTED if successfully started
2296 **                  BTM_ILLEGAL_VALUE if a bad parameter is detected
2297 **                  BTM_NO_RESOURCES if could not allocate a message buffer
2298 **                  BTM_SUCCESS - if cancelling the periodic inquiry
2299 **                  BTM_BUSY - if an inquiry is already active
2300 **                  BTM_WRONG_MODE if the device is not up.
2301 **
2302 *******************************************************************************/
2303 //extern
2304 tBTM_STATUS  BTM_SetPeriodicInquiryMode (tBTM_INQ_PARMS *p_inqparms,
2305         UINT16 max_delay, UINT16 min_delay,
2306         tBTM_INQ_RESULTS_CB *p_results_cb);
2307 
2308 
2309 /*******************************************************************************
2310 **
2311 ** Function         BTM_StartInquiry
2312 **
2313 ** Description      This function is called to start an inquiry.
2314 **
2315 ** Parameters:      p_inqparms - pointer to the inquiry information
2316 **                      mode - GENERAL or LIMITED inquiry
2317 **                      duration - length in 1.28 sec intervals (If '0', the inquiry is CANCELLED)
2318 **                      max_resps - maximum amount of devices to search for before ending the inquiry
2319 **                      filter_cond_type - BTM_CLR_INQUIRY_FILTER, BTM_FILTER_COND_DEVICE_CLASS, or
2320 **                                         BTM_FILTER_COND_BD_ADDR
2321 **                      filter_cond - value for the filter (based on filter_cond_type)
2322 **
2323 **                  p_results_cb   - Pointer to the callback routine which gets called
2324 **                                upon receipt of an inquiry result. If this field is
2325 **                                NULL, the application is not notified.
2326 **
2327 **                  p_cmpl_cb   - Pointer to the callback routine which gets called
2328 **                                upon completion.  If this field is NULL, the
2329 **                                application is not notified when completed.
2330 ** Returns          tBTM_STATUS
2331 **                  BTM_CMD_STARTED if successfully initiated
2332 **                  BTM_BUSY if already in progress
2333 **                  BTM_ILLEGAL_VALUE if parameter(s) are out of range
2334 **                  BTM_NO_RESOURCES if could not allocate resources to start the command
2335 **                  BTM_WRONG_MODE if the device is not up.
2336 **
2337 *******************************************************************************/
2338 //extern
2339 tBTM_STATUS  BTM_StartInquiry (tBTM_INQ_PARMS *p_inqparms,
2340                                tBTM_INQ_RESULTS_CB *p_results_cb,
2341                                tBTM_CMPL_CB *p_cmpl_cb);
2342 
2343 
2344 /*******************************************************************************
2345 **
2346 ** Function         BTM_IsInquiryActive
2347 **
2348 ** Description      This function returns a bit mask of the current inquiry state
2349 **
2350 ** Returns          BTM_INQUIRY_INACTIVE if inactive (0)
2351 **                  BTM_LIMITED_INQUIRY_ACTIVE if a limted inquiry is active
2352 **                  BTM_GENERAL_INQUIRY_ACTIVE if a general inquiry is active
2353 **                  BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active
2354 **
2355 *******************************************************************************/
2356 //extern
2357 UINT16 BTM_IsInquiryActive (void);
2358 
2359 
2360 /*******************************************************************************
2361 **
2362 ** Function         BTM_CancelInquiry
2363 **
2364 ** Description      This function cancels an inquiry if active
2365 **
2366 ** Returns          BTM_SUCCESS if successful
2367 **                  BTM_NO_RESOURCES if could not allocate a message buffer
2368 **                  BTM_WRONG_MODE if the device is not up.
2369 **
2370 *******************************************************************************/
2371 //extern
2372 tBTM_STATUS BTM_CancelInquiry(void);
2373 
2374 
2375 /*******************************************************************************
2376 **
2377 ** Function         BTM_CancelPeriodicInquiry
2378 **
2379 ** Description      This function cancels a periodic inquiry
2380 **
2381 ** Returns
2382 **                  BTM_NO_RESOURCES if could not allocate a message buffer
2383 **                  BTM_SUCCESS - if cancelling the periodic inquiry
2384 **                  BTM_WRONG_MODE if the device is not up.
2385 **
2386 *******************************************************************************/
2387 //extern
2388 tBTM_STATUS BTM_CancelPeriodicInquiry(void);
2389 
2390 
2391 /*******************************************************************************
2392 **
2393 ** Function         BTM_SetConnectability
2394 **
2395 ** Description      This function is called to set the device into or out of
2396 **                  connectable mode. Discoverable mode means page scans enabled.
2397 **
2398 ** Returns          BTM_SUCCESS if successful
2399 **                  BTM_ILLEGAL_VALUE if a bad parameter is detected
2400 **                  BTM_NO_RESOURCES if could not allocate a message buffer
2401 **                  BTM_WRONG_MODE if the device is not up.
2402 **
2403 *******************************************************************************/
2404 //extern
2405 tBTM_STATUS BTM_SetConnectability (UINT16 page_mode, UINT16 window,
2406                                    UINT16 interval);
2407 
2408 
2409 /*******************************************************************************
2410 **
2411 ** Function         BTM_ReadConnectability
2412 **
2413 ** Description      This function is called to read the current discoverability
2414 **                  mode of the device.
2415 ** Output Params    p_window - current page scan duration
2416 **                  p_interval - current time between page scans
2417 **
2418 ** Returns          BTM_NON_CONNECTABLE or BTM_CONNECTABLE
2419 **
2420 *******************************************************************************/
2421 //extern
2422 UINT16 BTM_ReadConnectability (UINT16 *p_window, UINT16 *p_interval);
2423 
2424 
2425 /*******************************************************************************
2426 **
2427 ** Function         BTM_SetInquiryMode
2428 **
2429 ** Description      This function is called to set standard, with RSSI
2430 **                  mode or extended of the inquiry for local device.
2431 **
2432 ** Input Params:    BTM_INQ_RESULT_STANDARD, BTM_INQ_RESULT_WITH_RSSI or
2433 **                  BTM_INQ_RESULT_EXTENDED
2434 **
2435 ** Returns          BTM_SUCCESS if successful
2436 **                  BTM_NO_RESOURCES if couldn't get a memory pool buffer
2437 **                  BTM_ILLEGAL_VALUE if a bad parameter was detected
2438 **                  BTM_WRONG_MODE if the device is not up.
2439 **
2440 *******************************************************************************/
2441 //extern
2442 tBTM_STATUS  BTM_SetInquiryMode (UINT8 mode);
2443 
2444 /*******************************************************************************
2445 **
2446 ** Function         BTM_SetInquiryScanType
2447 **
2448 ** Description      This function is called to set the iquiry scan-type to
2449 **                  standard or interlaced.
2450 **
2451 ** Input Params:    BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED
2452 **
2453 ** Returns          BTM_SUCCESS if successful
2454 **                  BTM_MODE_UNSUPPORTED if not a 1.2 device
2455 **                  BTM_WRONG_MODE if the device is not up.
2456 **
2457 *******************************************************************************/
2458 //extern
2459 tBTM_STATUS BTM_SetInquiryScanType (UINT16 scan_type);
2460 
2461 /*******************************************************************************
2462 **
2463 ** Function         BTM_SetPageScanType
2464 **
2465 ** Description      This function is called to set the page scan-type to
2466 **                  standard or interlaced.
2467 **
2468 ** Input Params:    BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED
2469 **
2470 ** Returns          BTM_SUCCESS if successful
2471 **                  BTM_MODE_UNSUPPORTED if not a 1.2 device
2472 **                  BTM_WRONG_MODE if the device is not up.
2473 **
2474 *******************************************************************************/
2475 
2476 //extern
2477 tBTM_STATUS BTM_SetPageScanType (UINT16 scan_type);
2478 
2479 /*******************************************************************************
2480 **
2481 ** Function         BTM_ReadRemoteDeviceName
2482 **
2483 ** Description      This function initiates a remote device HCI command to the
2484 **                  controller and calls the callback when the process has completed.
2485 **
2486 ** Input Params:    remote_bda      - device address of name to retrieve
2487 **                  p_cb            - callback function called when BTM_CMD_STARTED
2488 **                                    is returned.
2489 **                                    A pointer to tBTM_REMOTE_DEV_NAME is passed to the
2490 **                                    callback.
2491 **
2492 ** Returns
2493 **                  BTM_CMD_STARTED is returned if the request was successfully sent
2494 **                                  to HCI.
2495 **                  BTM_BUSY if already in progress
2496 **                  BTM_UNKNOWN_ADDR if device address is bad
2497 **                  BTM_NO_RESOURCES if could not allocate resources to start the command
2498 **                  BTM_WRONG_MODE if the device is not up.
2499 **
2500 *******************************************************************************/
2501 //extern
2502 tBTM_STATUS  BTM_ReadRemoteDeviceName (BD_ADDR remote_bda,
2503                                        tBTM_CMPL_CB *p_cb,
2504                                        tBT_TRANSPORT transport);
2505 
2506 
2507 /*******************************************************************************
2508 **
2509 ** Function         BTM_CancelRemoteDeviceName
2510 **
2511 ** Description      This function initiates the cancel request for the specified
2512 **                  remote device.
2513 **
2514 ** Input Params:    None
2515 **
2516 ** Returns
2517 **                  BTM_CMD_STARTED is returned if the request was successfully sent
2518 **                                  to HCI.
2519 **                  BTM_NO_RESOURCES if could not allocate resources to start the command
2520 **                  BTM_WRONG_MODE if there is not an active remote name request.
2521 **
2522 *******************************************************************************/
2523 //extern
2524 tBTM_STATUS  BTM_CancelRemoteDeviceName (void);
2525 
2526 /*******************************************************************************
2527 **
2528 ** Function         BTM_ReadRemoteVersion
2529 **
2530 ** Description      This function is called to read a remote device's version
2531 **
2532 ** Returns          BTM_SUCCESS if successful, otherwise an error
2533 **
2534 *******************************************************************************/
2535 //extern
2536 tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr,
2537                                    UINT8 *lmp_version,
2538                                    UINT16 *manufacturer,
2539                                    UINT16 *lmp_sub_version);
2540 
2541 /*******************************************************************************
2542 **
2543 ** Function         BTM_ReadRemoteFeatures
2544 **
2545 ** Description      This function is called to read a remote device's
2546 **                  supported features mask (features mask located at page 0)
2547 **
2548 **                  Note: The size of device features mask page is
2549 **                  BTM_FEATURE_BYTES_PER_PAGE bytes.
2550 **
2551 ** Returns          pointer to the remote supported features mask
2552 **
2553 *******************************************************************************/
2554 //extern
2555 UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr);
2556 
2557 /*******************************************************************************
2558 **
2559 ** Function         BTM_ReadRemoteExtendedFeatures
2560 **
2561 ** Description      This function is called to read a specific extended features
2562 **                  page of the remote device
2563 **
2564 **                  Note1: The size of device features mask page is
2565 **                  BTM_FEATURE_BYTES_PER_PAGE bytes.
2566 **                  Note2: The valid device features mask page number depends on
2567 **                  the remote device capabilities. It is expected to be in the
2568 **                  range [0 - BTM_EXT_FEATURES_PAGE_MAX].
2569 
2570 ** Returns          pointer to the remote extended features mask
2571 **                  or NULL if page_number is not valid
2572 **
2573 *******************************************************************************/
2574 //extern
2575 UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number);
2576 
2577 /*******************************************************************************
2578 **
2579 ** Function         BTM_ReadNumberRemoteFeaturesPages
2580 **
2581 ** Description      This function is called to retrieve the number of feature pages
2582 **                  read from the remote device
2583 **
2584 ** Returns          number of features pages read from the remote device
2585 **
2586 *******************************************************************************/
2587 //extern
2588 UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr);
2589 
2590 /*******************************************************************************
2591 **
2592 ** Function         BTM_ReadAllRemoteFeatures
2593 **
2594 ** Description      This function is called to read all features of the remote device
2595 **
2596 ** Returns          pointer to the byte[0] of the page[0] of the remote device
2597 **                  feature mask.
2598 **
2599 ** Note:            the function returns the pointer to the array of the size
2600 **                  BTM_FEATURE_BYTES_PER_PAGE * (BTM_EXT_FEATURES_PAGE_MAX + 1).
2601 **
2602 *******************************************************************************/
2603 //extern
2604 UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr);
2605 
2606 /*******************************************************************************
2607 **
2608 ** Function         BTM_InqDbRead
2609 **
2610 ** Description      This function looks through the inquiry database for a match
2611 **                  based on Bluetooth Device Address. This is the application's
2612 **                  interface to get the inquiry details of a specific BD address.
2613 **
2614 ** Returns          pointer to entry, or NULL if not found
2615 **
2616 *******************************************************************************/
2617 //extern
2618 tBTM_INQ_INFO *BTM_InqDbRead (BD_ADDR p_bda);
2619 
2620 
2621 /*******************************************************************************
2622 **
2623 ** Function         BTM_InqDbFirst
2624 **
2625 ** Description      This function looks through the inquiry database for the first
2626 **                  used entry, and returns that. This is used in conjunction with
2627 **                  BTM_InqDbNext by applications as a way to walk through the
2628 **                  inquiry database.
2629 **
2630 ** Returns          pointer to first in-use entry, or NULL if DB is empty
2631 **
2632 *******************************************************************************/
2633 //extern
2634 tBTM_INQ_INFO *BTM_InqDbFirst (void);
2635 
2636 
2637 /*******************************************************************************
2638 **
2639 ** Function         BTM_InqDbNext
2640 **
2641 ** Description      This function looks through the inquiry database for the next
2642 **                  used entry, and returns that.  If the input parameter is NULL,
2643 **                  the first entry is returned.
2644 **
2645 ** Returns          pointer to next in-use entry, or NULL if no more found.
2646 **
2647 *******************************************************************************/
2648 //extern
2649 tBTM_INQ_INFO *BTM_InqDbNext (tBTM_INQ_INFO *p_cur);
2650 
2651 
2652 /*******************************************************************************
2653 **
2654 ** Function         BTM_ClearInqDb
2655 **
2656 ** Description      This function is called to clear out a device or all devices
2657 **                  from the inquiry database.
2658 **
2659 ** Parameter        p_bda - (input) BD_ADDR ->  Address of device to clear
2660 **                                              (NULL clears all entries)
2661 **
2662 ** Returns          BTM_BUSY if an inquiry, get remote name, or event filter
2663 **                          is active, otherwise BTM_SUCCESS
2664 **
2665 *******************************************************************************/
2666 //extern
2667 tBTM_STATUS  BTM_ClearInqDb (BD_ADDR p_bda);
2668 
2669 /*******************************************************************************
2670 **
2671 ** Function         BTM_ReadInquiryRspTxPower
2672 **
2673 ** Description      This command will read the inquiry Transmit Power level used
2674 **                  to transmit the FHS and EIR data packets.
2675 **                  This can be used directly in the Tx Power Level EIR data type.
2676 **
2677 ** Returns          BTM_SUCCESS if successful
2678 **
2679 *******************************************************************************/
2680 //extern
2681 tBTM_STATUS BTM_ReadInquiryRspTxPower (tBTM_CMPL_CB *p_cb);
2682 
2683 #if SDP_INCLUDED == TRUE
2684 /*******************************************************************************
2685 **
2686 ** Function         BTM_StartDiscovery
2687 **
2688 ** Description      This function is called by an application (or profile)
2689 **                  when it wants to trigger an service discovery using the
2690 **                  BTM's discovery database.
2691 **
2692 ** Returns          tBTM_STATUS
2693 **                      BTM_CMD_STARTED if the discovery was initiated
2694 **                      BTM_BUSY if one is already in progress
2695 **                      BTM_UNKNOWN_ADDR if no addresses are in the INQ DB
2696 **                      BTM_ERR_PROCESSING if err initiating the command
2697 **
2698 *******************************************************************************/
2699 //extern
2700 tBTM_STATUS BTM_StartDiscovery (tBTM_CMPL_CB *p_cmpl_cb,
2701                                 BD_ADDR_PTR p_rem_addr);
2702 
2703 
2704 /*******************************************************************************
2705 **
2706 ** Function         BTM_FindAttribute
2707 **
2708 ** Description      This function is called by an application (or profile)
2709 **                  when it wants to see if an attribute exists in the BTM
2710 **                  discovery database.
2711 **
2712 ** Returns          Pointer to matching record, or NULL
2713 **
2714 *******************************************************************************/
2715 //extern
2716 tSDP_DISC_REC *BTM_FindAttribute (UINT16 attr_id,
2717                                   tSDP_DISC_REC *p_start_rec);
2718 
2719 
2720 /*******************************************************************************
2721 **
2722 ** Function         BTM_FindService
2723 **
2724 ** Description      This function is called by an application (or profile)
2725 **                  when it wants to see if a service exists in the BTM
2726 **                  discovery database.
2727 **
2728 ** Returns          Pointer to matching record, or NULL
2729 **
2730 *******************************************************************************/
2731 //extern
2732 tSDP_DISC_REC *BTM_FindService (UINT16 service_uuid,
2733                                 tSDP_DISC_REC *p_start_rec);
2734 
2735 
2736 /*******************************************************************************
2737 **
2738 ** Function         BTM_SetDiscoveryParams
2739 **
2740 ** Description      This function is called to set the BTM default discovery parameters.
2741 **                  These UUID and attribute filters are used during the call to
2742 **                  BTM_StartDiscovery.
2743 **
2744 ** Returns          void
2745 **
2746 *******************************************************************************/
2747 //extern
2748 void BTM_SetDiscoveryParams (UINT16 num_uuid, tSDP_UUID *p_uuid_list,
2749                              UINT16 num_attr, UINT16 *p_attr_list);
2750 #endif /*SDP_INCLUDED*/
2751 
2752 /*****************************************************************************
2753 **  ACL CHANNEL MANAGEMENT FUNCTIONS
2754 *****************************************************************************/
2755 /*******************************************************************************
2756 **
2757 ** Function         BTM_SetLinkPolicy
2758 **
2759 ** Description      Create and send HCI "Write Policy Set" command
2760 **
2761 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
2762 **
2763 *******************************************************************************/
2764 //extern
2765 tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda,
2766                                UINT16 *settings);
2767 
2768 /*******************************************************************************
2769 **
2770 ** Function         BTM_SetDefaultLinkPolicy
2771 **
2772 ** Description      Set the default value for HCI "Write Policy Set" command
2773 **                  to use when an ACL link is created.
2774 **
2775 ** Returns          void
2776 **
2777 *******************************************************************************/
2778 //extern
2779 void BTM_SetDefaultLinkPolicy (UINT16 settings);
2780 
2781 
2782 /*******************************************************************************
2783 **
2784 ** Function         BTM_SetDefaultLinkSuperTout
2785 **
2786 ** Description      Set the default value for HCI "Write Link Supervision Timeout"
2787 **                  command to use when an ACL link is created.
2788 **
2789 ** Returns          void
2790 **
2791 *******************************************************************************/
2792 //extern
2793 void BTM_SetDefaultLinkSuperTout (UINT16 timeout);
2794 
2795 
2796 /*******************************************************************************
2797 **
2798 ** Function         BTM_SetLinkSuperTout
2799 **
2800 ** Description      Create and send HCI "Write Link Supervision Timeout" command
2801 **
2802 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
2803 **
2804 *******************************************************************************/
2805 //extern
2806 tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda,
2807                                   UINT16 timeout);
2808 /*******************************************************************************
2809 **
2810 ** Function         BTM_GetLinkSuperTout
2811 **
2812 ** Description      Read the link supervision timeout value of the connection
2813 **
2814 ** Returns          status of the operation
2815 **
2816 *******************************************************************************/
2817 //extern
2818 tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda,
2819                                   UINT16 *p_timeout);
2820 
2821 /*******************************************************************************
2822 **
2823 ** Function         BTM_IsAclConnectionUp
2824 **
2825 ** Description      This function is called to check if an ACL connection exists
2826 **                  to a specific remote BD Address.
2827 **
2828 ** Returns          TRUE if connection is up, else FALSE.
2829 **
2830 *******************************************************************************/
2831 //extern
2832 BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport);
2833 
2834 
2835 /*******************************************************************************
2836 **
2837 ** Function         BTM_GetRole
2838 **
2839 ** Description      This function is called to get the role of the local device
2840 **                  for the ACL connection with the specified remote device
2841 **
2842 ** Returns          BTM_SUCCESS if connection exists.
2843 **                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
2844 **
2845 *******************************************************************************/
2846 //extern
2847 tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role);
2848 
2849 
2850 
2851 /*******************************************************************************
2852 **
2853 ** Function         BTM_SwitchRole
2854 **
2855 ** Description      This function is called to switch role between master and
2856 **                  slave.  If role is already set it will do nothing.  If the
2857 **                  command was initiated, the callback function is called upon
2858 **                  completion.
2859 **
2860 ** Returns          BTM_SUCCESS if already in specified role.
2861 **                  BTM_CMD_STARTED if command issued to controller.
2862 **                  BTM_NO_RESOURCES if couldn't allocate memory to issue command
2863 **                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
2864 **                  BTM_MODE_UNSUPPORTED if local device does not support role switching
2865 **
2866 *******************************************************************************/
2867 //extern
2868 tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr,
2869                             UINT8 new_role,
2870                             tBTM_CMPL_CB *p_cb);
2871 
2872 /*******************************************************************************
2873 **
2874 ** Function         BTM_ReadRSSI
2875 **
2876 ** Description      This function is called to read the RSSI for a particular transport.
2877 **                  The RSSI of results are returned in the callback.
2878 **                  (tBTM_RSSI_RESULTS)
2879 **
2880 ** Returns          BTM_CMD_STARTED if command issued to controller.
2881 **                  BTM_NO_RESOURCES if couldn't allocate memory to issue command
2882 **                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
2883 **                  BTM_BUSY if command is already in progress
2884 **
2885 *******************************************************************************/
2886 //extern
2887 tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb);
2888 
2889 
2890 /*******************************************************************************
2891 **
2892 ** Function         BTM_ReadTxPower
2893 **
2894 ** Description      This function is called to read the current connection
2895 **                  TX power of the connection. The TX power level results
2896 **                  are returned in the callback.
2897 **                  (tBTM_RSSI_RESULTS)
2898 **
2899 ** Returns          BTM_CMD_STARTED if command issued to controller.
2900 **                  BTM_NO_RESOURCES if couldn't allocate memory to issue command
2901 **                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
2902 **                  BTM_BUSY if command is already in progress
2903 **
2904 *******************************************************************************/
2905 //extern
2906 tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda,
2907                              tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb);
2908 
2909 tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb);
2910 
2911 void BTM_BleGetWhiteListSize(uint16_t *length);
2912 
2913 
2914 /*******************************************************************************
2915 **
2916 ** Function         BTM_ReadLinkQuality
2917 **
2918 ** Description      This function is called to read the link quality.
2919 **                  The value of the link quality is returned in the callback.
2920 **                  (tBTM_LINK_QUALITY_RESULTS)
2921 **
2922 ** Returns          BTM_CMD_STARTED if command issued to controller.
2923 **                  BTM_NO_RESOURCES if couldn't allocate memory to issue command
2924 **                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
2925 **                  BTM_BUSY if command is already in progress
2926 **
2927 *******************************************************************************/
2928 //extern
2929 tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb);
2930 
2931 /*******************************************************************************
2932 **
2933 ** Function         BTM_RegBusyLevelNotif
2934 **
2935 ** Description      This function is called to register a callback to receive
2936 **                  busy level change events.
2937 **
2938 ** Returns          BTM_SUCCESS if successfully registered, otherwise error
2939 **
2940 *******************************************************************************/
2941 //extern
2942 tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
2943                                    tBTM_BL_EVENT_MASK evt_mask);
2944 
2945 /*******************************************************************************
2946 **
2947 ** Function         BTM_RegAclLinkStatNotif
2948 **
2949 ** Description      This function is called to register a callback to receive
2950 **                  ACL link related events.
2951 **
2952 ** Returns          BTM_SUCCESS if successfully registered, otherwise error
2953 **
2954 *******************************************************************************/
2955 tBTM_STATUS BTM_RegAclLinkStatNotif(tBTM_ACL_LINK_STAT_CB *p_cb);
2956 
2957 /*******************************************************************************
2958 **
2959 ** Function         BTM_AclRegisterForChanges
2960 **
2961 ** Description      This function is called to register a callback to receive
2962 **                  ACL database change events, i.e. new connection or removed.
2963 **
2964 ** Returns          BTM_SUCCESS if successfully initiated, otherwise error
2965 **
2966 *******************************************************************************/
2967 //extern
2968 tBTM_STATUS BTM_AclRegisterForChanges (tBTM_ACL_DB_CHANGE_CB *p_cb);
2969 
2970 /*******************************************************************************
2971 **
2972 ** Function         BTM_GetNumAclLinks
2973 **
2974 ** Description      This function is called to count the number of
2975 **                  ACL links that are active.
2976 **
2977 ** Returns          UINT16  Number of active ACL links
2978 **
2979 *******************************************************************************/
2980 //extern
2981 UINT16 BTM_GetNumAclLinks (void);
2982 
2983 /*******************************************************************************
2984 **
2985 ** Function         BTM_SetQoS
2986 **
2987 ** Description      This function is called to setup QoS
2988 **
2989 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
2990 **
2991 *******************************************************************************/
2992 //extern
2993 tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC *p_flow,
2994                        tBTM_CMPL_CB *p_cb);
2995 
2996 
2997 /*****************************************************************************
2998 **  (e)SCO CHANNEL MANAGEMENT FUNCTIONS
2999 *****************************************************************************/
3000 /*******************************************************************************
3001 **
3002 ** Function         BTM_CreateSco
3003 **
3004 ** Description      This function is called to create an SCO connection. If the
3005 **                  "is_orig" flag is TRUE, the connection will be originated,
3006 **                  otherwise BTM will wait for the other side to connect.
3007 **
3008 ** Returns          BTM_UNKNOWN_ADDR if the ACL connection is not up
3009 **                  BTM_BUSY         if another SCO being set up to
3010 **                                   the same BD address
3011 **                  BTM_NO_RESOURCES if the max SCO limit has been reached
3012 **                  BTM_CMD_STARTED  if the connection establishment is started.
3013 **                                   In this case, "*p_sco_inx" is filled in
3014 **                                   with the sco index used for the connection.
3015 **
3016 *******************************************************************************/
3017 //extern
3018 tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, BOOLEAN is_orig,
3019                            UINT16 pkt_types, UINT16 *p_sco_inx,
3020                            tBTM_SCO_CB *p_conn_cb,
3021                            tBTM_SCO_CB *p_disc_cb);
3022 
3023 
3024 /*******************************************************************************
3025 **
3026 ** Function         BTM_RemoveSco
3027 **
3028 ** Description      This function is called to remove a specific SCO connection.
3029 **
3030 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
3031 **
3032 *******************************************************************************/
3033 //extern
3034 tBTM_STATUS BTM_RemoveSco (UINT16 sco_inx);
3035 
3036 
3037 /*******************************************************************************
3038 **
3039 ** Function         BTM_SetScoPacketTypes
3040 **
3041 ** Description      This function is called to set the packet types used for
3042 **                  a specific SCO connection,
3043 **
3044 ** Parameters       pkt_types - One or more of the following
3045 **                  BTM_SCO_PKT_TYPES_MASK_HV1
3046 **                  BTM_SCO_PKT_TYPES_MASK_HV2
3047 **                  BTM_SCO_PKT_TYPES_MASK_HV3
3048 **                  BTM_SCO_PKT_TYPES_MASK_EV3
3049 **                  BTM_SCO_PKT_TYPES_MASK_EV4
3050 **                  BTM_SCO_PKT_TYPES_MASK_EV5
3051 **
3052 **                  BTM_SCO_LINK_ALL_MASK   - enables all supported types
3053 **
3054 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
3055 **
3056 *******************************************************************************/
3057 //extern
3058 tBTM_STATUS BTM_SetScoPacketTypes (UINT16 sco_inx, UINT16 pkt_types);
3059 
3060 
3061 /*******************************************************************************
3062 **
3063 ** Function         BTM_ReadScoPacketTypes
3064 **
3065 ** Description      This function is read the packet types used for a specific
3066 **                  SCO connection.
3067 **
3068 ** Returns       One or more of the following (bitmask)
3069 **                  BTM_SCO_PKT_TYPES_MASK_HV1
3070 **                  BTM_SCO_PKT_TYPES_MASK_HV2
3071 **                  BTM_SCO_PKT_TYPES_MASK_HV3
3072 **                  BTM_SCO_PKT_TYPES_MASK_EV3
3073 **                  BTM_SCO_PKT_TYPES_MASK_EV4
3074 **                  BTM_SCO_PKT_TYPES_MASK_EV5
3075 **
3076 ** Returns          packet types supported for the connection
3077 **
3078 *******************************************************************************/
3079 //extern
3080 UINT16 BTM_ReadScoPacketTypes (UINT16 sco_inx);
3081 
3082 
3083 /*******************************************************************************
3084 **
3085 ** Function         BTM_ReadDeviceScoPacketTypes
3086 **
3087 ** Description      This function is read the SCO packet types that
3088 **                  the device supports.
3089 **
3090 ** Returns          packet types supported by the device.
3091 **
3092 *******************************************************************************/
3093 //extern
3094 UINT16 BTM_ReadDeviceScoPacketTypes (void);
3095 
3096 
3097 /*******************************************************************************
3098 **
3099 ** Function         BTM_ReadScoHandle
3100 **
3101 ** Description      This function is used to read the HCI handle used for a specific
3102 **                  SCO connection,
3103 **
3104 ** Returns          handle for the connection, or 0xFFFF if invalid SCO index.
3105 **
3106 *******************************************************************************/
3107 //extern
3108 UINT16 BTM_ReadScoHandle (UINT16 sco_inx);
3109 
3110 
3111 /*******************************************************************************
3112 **
3113 ** Function         BTM_ReadScoBdAddr
3114 **
3115 ** Description      This function is read the remote BD Address for a specific
3116 **                  SCO connection,
3117 **
3118 ** Returns          pointer to BD address or NULL if not known
3119 **
3120 *******************************************************************************/
3121 //extern
3122 UINT8 *BTM_ReadScoBdAddr (UINT16 sco_inx);
3123 
3124 
3125 /*******************************************************************************
3126 **
3127 ** Function         BTM_ReadScoDiscReason
3128 **
3129 ** Description      This function is returns the reason why an (e)SCO connection
3130 **                  has been removed. It contains the value until read, or until
3131 **                  another (e)SCO connection has disconnected.
3132 **
3133 ** Returns          HCI reason or BTM_INVALID_SCO_DISC_REASON if not set.
3134 **
3135 *******************************************************************************/
3136 //extern
3137 UINT16 BTM_ReadScoDiscReason (void);
3138 
3139 
3140 /*******************************************************************************
3141 **
3142 ** Function         BTM_SetEScoMode
3143 **
3144 ** Description      This function sets up the negotiated parameters for SCO or
3145 **                  eSCO, and sets as the default mode used for calls to
3146 **                  BTM_CreateSco.  It can be called only when there are no
3147 **                  active (e)SCO links.
3148 **
3149 ** Returns          BTM_SUCCESS if the successful.
3150 **                  BTM_BUSY if there are one or more active (e)SCO links.
3151 **
3152 *******************************************************************************/
3153 //extern
3154 tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode,
3155                              tBTM_ESCO_PARAMS *p_parms);
3156 
3157 /*******************************************************************************
3158 **
3159 ** Function         BTM_SetWBSCodec
3160 **
3161 ** Description      This function sends command to the controller to setup
3162 **                  WBS codec for the upcoming eSCO connection.
3163 **
3164 ** Returns          BTM_SUCCESS.
3165 **
3166 **
3167 *******************************************************************************/
3168 //extern
3169 tBTM_STATUS BTM_SetWBSCodec (tBTM_SCO_CODEC_TYPE codec_type);
3170 
3171 /*******************************************************************************
3172 **
3173 ** Function         BTM_RegForEScoEvts
3174 **
3175 ** Description      This function registers a SCO event callback with the
3176 **                  specified instance.  It should be used to received
3177 **                  connection indication events and change of link parameter
3178 **                  events.
3179 **
3180 ** Returns          BTM_SUCCESS if the successful.
3181 **                  BTM_ILLEGAL_VALUE if there is an illegal sco_inx
3182 **
3183 *******************************************************************************/
3184 //extern
3185 tBTM_STATUS BTM_RegForEScoEvts (UINT16 sco_inx,
3186                                 tBTM_ESCO_CBACK *p_esco_cback);
3187 
3188 /*******************************************************************************
3189 **
3190 ** Function         BTM_ReadEScoLinkParms
3191 **
3192 ** Description      This function returns the current eSCO link parameters for
3193 **                  the specified handle.  This can be called anytime a connection
3194 **                  is active, but is typically called after receiving the SCO
3195 **                  opened callback.
3196 **
3197 **                  Note: If called over a 1.1 controller, only the packet types
3198 **                        field has meaning.
3199 **                  Note: If the upper layer doesn't know the current sco index,
3200 **                  BTM_FIRST_ACTIVE_SCO_INDEX can be used as the first parameter to
3201 **                  find the first active SCO index
3202 **
3203 ** Returns          BTM_SUCCESS if returned data is valid connection.
3204 **                  BTM_ILLEGAL_VALUE if no connection for specified sco_inx.
3205 **                  BTM_MODE_UNSUPPORTED if local controller does not support
3206 **                      1.2 specification.
3207 **
3208 *******************************************************************************/
3209 //extern
3210 tBTM_STATUS BTM_ReadEScoLinkParms (UINT16 sco_inx,
3211                                    tBTM_ESCO_DATA *p_parms);
3212 
3213 /*******************************************************************************
3214 **
3215 ** Function         BTM_ChangeEScoLinkParms
3216 **
3217 ** Description      This function requests renegotiation of the parameters on
3218 **                  the current eSCO Link.  If any of the changes are accepted
3219 **                  by the controllers, the BTM_ESCO_CHG_EVT event is sent in
3220 **                  the tBTM_ESCO_CBACK function with the current settings of
3221 **                  the link. The callback is registered through the call to
3222 **                  BTM_SetEScoMode.
3223 **
3224 **
3225 ** Returns          BTM_CMD_STARTED if command is successfully initiated.
3226 **                  BTM_ILLEGAL_VALUE if no connection for specified sco_inx.
3227 **                  BTM_NO_RESOURCES - not enough resources to initiate command.
3228 **                  BTM_MODE_UNSUPPORTED if local controller does not support
3229 **                      1.2 specification.
3230 **
3231 *******************************************************************************/
3232 //extern
3233 tBTM_STATUS BTM_ChangeEScoLinkParms (UINT16 sco_inx,
3234                                      tBTM_CHG_ESCO_PARAMS *p_parms);
3235 
3236 /*******************************************************************************
3237 **
3238 ** Function         BTM_EScoConnRsp
3239 **
3240 ** Description      This function is called upon receipt of an (e)SCO connection
3241 **                  request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject
3242 **                  the request. Parameters used to negotiate eSCO links.
3243 **                  If p_parms is NULL, then values set through BTM_SetEScoMode
3244 **                  are used.
3245 **                  If the link type of the incoming request is SCO, then only
3246 **                  the tx_bw, max_latency, content format, and packet_types are
3247 **                  valid.  The hci_status parameter should be
3248 **                  ([0x0] to accept, [0x0d..0x0f] to reject)
3249 **
3250 **
3251 ** Returns          void
3252 **
3253 *******************************************************************************/
3254 //extern
3255 void BTM_EScoConnRsp (UINT16 sco_inx, UINT8 hci_status,
3256                       tBTM_ESCO_PARAMS *p_parms);
3257 
3258 /*******************************************************************************
3259 **
3260 ** Function         BTM_GetNumScoLinks
3261 **
3262 ** Description      This function returns the number of active SCO links.
3263 **
3264 ** Returns          UINT8
3265 **
3266 *******************************************************************************/
3267 //extern
3268 UINT8 BTM_GetNumScoLinks (void);
3269 
3270 /*****************************************************************************
3271 **  SECURITY MANAGEMENT FUNCTIONS
3272 *****************************************************************************/
3273 /*******************************************************************************
3274 **
3275 ** Function         BTM_SecRegister
3276 **
3277 ** Description      Application manager calls this function to register for
3278 **                  security services.  There can be one and only one application
3279 **                  saving link keys.  BTM allows only first registration.
3280 **
3281 ** Returns          TRUE if registered OK, else FALSE
3282 **
3283 *******************************************************************************/
3284 //extern
3285 BOOLEAN BTM_SecRegister (tBTM_APPL_INFO *p_cb_info);
3286 
3287 /*******************************************************************************
3288 **
3289 ** Function         BTM_SecRegisterLinkKeyNotificationCallback
3290 **
3291 ** Description      Profiles can register to be notified when a new Link Key
3292 **                  is generated per connection.
3293 **
3294 ** Returns          TRUE if registered OK, else FALSE
3295 **
3296 *******************************************************************************/
3297 //extern
3298 BOOLEAN BTM_SecRegisterLinkKeyNotificationCallback(
3299     tBTM_LINK_KEY_CALLBACK *p_callback);
3300 
3301 /*******************************************************************************
3302 **
3303 ** Function         BTM_SecAddRmtNameNotifyCallback
3304 **
3305 ** Description      Profiles can register to be notified when name of the
3306 **                  remote device is resolved (up to BTM_SEC_MAX_RMT_NAME_CALLBACKS).
3307 **
3308 ** Returns          TRUE if registered OK, else FALSE
3309 **
3310 *******************************************************************************/
3311 //extern
3312 BOOLEAN BTM_SecAddRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback);
3313 
3314 
3315 /*******************************************************************************
3316 **
3317 ** Function         BTM_SecDeleteRmtNameNotifyCallback
3318 **
3319 ** Description      A profile can deregister notification when a new Link Key
3320 **                  is generated per connection.
3321 **
3322 ** Returns          TRUE if OK, else FALSE
3323 **
3324 *******************************************************************************/
3325 //extern
3326 BOOLEAN BTM_SecDeleteRmtNameNotifyCallback (tBTM_RMT_NAME_CALLBACK *p_callback);
3327 
3328 /*******************************************************************************
3329 **
3330 ** Function         BTM_GetSecurityFlags
3331 **
3332 ** Description      Get security flags for the device
3333 **
3334 ** Returns          BOOLEAN TRUE or FALSE is device found
3335 **
3336 *******************************************************************************/
3337 //extern
3338 BOOLEAN BTM_GetSecurityFlags (BD_ADDR bd_addr, UINT8 *p_sec_flags);
3339 
3340 /*******************************************************************************
3341 **
3342 ** Function         BTM_GetSecurityFlagsByTransport
3343 **
3344 ** Description      Get security flags for the device on a particular transport
3345 **
3346 ** Parameters      bd_addr: BD address of remote device
3347 **                  p_sec_flags : Out parameter to be filled with security flags for the connection
3348 **                  transport :  Physical transport of the connection (BR/EDR or LE)
3349 **
3350 ** Returns          BOOLEAN TRUE or FALSE is device found
3351 **
3352 *******************************************************************************/
3353 //extern
3354 BOOLEAN BTM_GetSecurityFlagsByTransport (BD_ADDR bd_addr,
3355         UINT8 *p_sec_flags, tBT_TRANSPORT transport);
3356 
3357 /*******************************************************************************
3358 **
3359 ** Function         BTM_ReadTrustedMask
3360 **
3361 ** Description      Get trusted mask for the device
3362 **
3363 ** Returns          NULL, if the device record is not found.
3364 **                  otherwise, the trusted mask
3365 **
3366 *******************************************************************************/
3367 //extern
3368 UINT32 *BTM_ReadTrustedMask (BD_ADDR bd_addr);
3369 
3370 /*******************************************************************************
3371 **
3372 ** Function         BTM_SetPinType
3373 **
3374 ** Description      Set PIN type for the device.
3375 **
3376 ** Returns          void
3377 **
3378 *******************************************************************************/
3379 //extern
3380 void BTM_SetPinType (UINT8 pin_type, PIN_CODE pin_code, UINT8 pin_code_len);
3381 
3382 
3383 /*******************************************************************************
3384 **
3385 ** Function         BTM_SetPairableMode
3386 **
3387 ** Description      Enable or disable pairing
3388 **
3389 ** Parameters       allow_pairing - (TRUE or FALSE) whether or not the device
3390 **                      allows pairing.
3391 **                  connect_only_paired - (TRUE or FALSE) whether or not to
3392 **                      only allow paired devices to connect.
3393 **
3394 ** Returns          void
3395 **
3396 *******************************************************************************/
3397 //extern
3398 void BTM_SetPairableMode (BOOLEAN allow_pairing, BOOLEAN connect_only_paired);
3399 
3400 /*******************************************************************************
3401 **
3402 ** Function         BTM_SetSecureConnectionsOnly
3403 **
3404 ** Description      Enable or disable default treatment for Mode 4 Level 0 services
3405 **
3406 ** Parameter        secure_connections_only_mode - (TRUE or FALSE)
3407 **                  TRUE means that the device should treat Mode 4 Level 0 services as
3408 **                  services of other levels.
3409 **                  FALSE means that the device should provide default treatment for
3410 **                  Mode 4 Level 0 services.
3411 **
3412 ** Returns          void
3413 **
3414 *******************************************************************************/
3415 //extern
3416 void BTM_SetSecureConnectionsOnly (BOOLEAN secure_connections_only_mode);
3417 
3418 /*******************************************************************************
3419 **
3420 ** Function         BTM_SetSecurityLevel
3421 **
3422 ** Description      Register service security level with Security Manager.  Each
3423 **                  service must register its requirements regardless of the
3424 **                  security level that is used.  This API is called once for originators
3425 **                  nad again for acceptors of connections.
3426 **
3427 ** Returns          TRUE if registered OK, else FALSE
3428 **
3429 *******************************************************************************/
3430 //extern
3431 BOOLEAN BTM_SetSecurityLevel (BOOLEAN is_originator, const char *p_name,
3432                               UINT8 service_id, UINT16 sec_level,
3433                               UINT16 psm, UINT32 mx_proto_id,
3434                               UINT32 mx_chan_id);
3435 
3436 /*******************************************************************************
3437 **
3438 ** Function         BTM_SetOutService
3439 **
3440 ** Description      This function is called to set the service for
3441 **                  outgoing connection.
3442 **
3443 ** Returns          void
3444 **
3445 *******************************************************************************/
3446 //extern
3447 void BTM_SetOutService(BD_ADDR bd_addr, UINT8 service_id, UINT32 mx_chan_id);
3448 
3449 /*******************************************************************************
3450 **
3451 ** Function         BTM_SecClrService
3452 **
3453 ** Description      Removes specified service record(s) from the security database.
3454 **                  All service records with the specified name are removed.
3455 **                  Typically used only by devices with limited RAM so that it can
3456 **                  reuse an old security service record.
3457 **                          records (except SDP).
3458 **
3459 ** Returns          Number of records that were freed.
3460 **
3461 *******************************************************************************/
3462 //extern
3463 UINT8 BTM_SecClrService (UINT8 service_id);
3464 
3465 /*******************************************************************************
3466 **
3467 ** Function         BTM_SecAddDevice
3468 **
3469 ** Description      Add/modify device.  This function will be normally called
3470 **                  during host startup to restore all required information
3471 **                  stored in the NVRAM.
3472 **                  dev_class, bd_name, link_key, and features are NULL if unknown
3473 **
3474 ** Returns          TRUE if added OK, else FALSE
3475 **
3476 *******************************************************************************/
3477 //extern
3478 BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class,
3479                           BD_NAME bd_name, UINT8 *features,
3480                           UINT32 trusted_mask[], LINK_KEY link_key,
3481                           UINT8 key_type, tBTM_IO_CAP io_cap, UINT8 pin_length,
3482                           UINT8 sc_support);
3483 
3484 
3485 /*******************************************************************************
3486 **
3487 ** Function         BTM_SecDeleteDevice
3488 **
3489 ** Description      Free resources associated with the device.
3490 **
3491 ** Returns          TRUE if rmoved OK, FALSE if not found
3492 **
3493 *******************************************************************************/
3494 //extern
3495 BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport);
3496 
3497 /*******************************************************************************
3498 **
3499 ** Function         BTM_SecGetDeviceLinkKey
3500 **
3501 ** Description      This function is called to obtain link key for the device
3502 **                  it returns BTM_SUCCESS if link key is available, or
3503 **                  BTM_UNKNOWN_ADDR if Security Manager does not know about
3504 **                  the device or device record does not contain link key info
3505 **
3506 ** Returns          BTM_SUCCESS if successful, otherwise error code
3507 **
3508 *******************************************************************************/
3509 //extern
3510 tBTM_STATUS BTM_SecGetDeviceLinkKey (BD_ADDR bd_addr,
3511                                      LINK_KEY link_key);
3512 
3513 
3514 /*******************************************************************************
3515 **
3516 ** Function         BTM_SecGetDeviceLinkKeyType
3517 **
3518 ** Description      This function is called to obtain link key type for the
3519 **                  device.
3520 **                  it returns BTM_SUCCESS if link key is available, or
3521 **                  BTM_UNKNOWN_ADDR if Security Manager does not know about
3522 **                  the device or device record does not contain link key info
3523 **
3524 ** Returns          BTM_LKEY_TYPE_IGNORE if link key is unknown, link type
3525 **                  otherwise.
3526 **
3527 *******************************************************************************/
3528 //extern
3529 tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType (BD_ADDR bd_addr);
3530 
3531 
3532 /*******************************************************************************
3533 **
3534 ** Function         BTM_PINCodeReply
3535 **
3536 ** Description      This function is called after Security Manager submitted
3537 **                  PIN code request to the UI.
3538 **
3539 ** Parameters:      bd_addr      - Address of the device for which PIN was requested
3540 **                  res          - result of the operation BTM_SUCCESS if success
3541 **                  pin_len      - length in bytes of the PIN Code
3542 **                  p_pin        - pointer to array with the PIN Code
3543 **                  trusted_mask - bitwise OR of trusted services (array of UINT32)
3544 **
3545 ** Returns          void
3546 **
3547 *******************************************************************************/
3548 //extern
3549 void BTM_PINCodeReply (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len,
3550                        UINT8 *p_pin, UINT32 trusted_mask[]);
3551 
3552 
3553 /*******************************************************************************
3554 **
3555 ** Function         BTM_SecBond
3556 **
3557 ** Description      This function is called to perform bonding with peer device.
3558 **
3559 ** Parameters:      bd_addr      - Address of the device to bond
3560 **                  pin_len      - length in bytes of the PIN Code
3561 **                  p_pin        - pointer to array with the PIN Code
3562 **                  trusted_mask - bitwise OR of trusted services (array of UINT32)
3563 
3564 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
3565 **
3566 *******************************************************************************/
3567 //extern
3568 tBTM_STATUS BTM_SecBond (BD_ADDR bd_addr,
3569                          UINT8 pin_len, UINT8 *p_pin,
3570                          UINT32 trusted_mask[]);
3571 
3572 /*******************************************************************************
3573 **
3574 ** Function         BTM_SecBondByTransport
3575 **
3576 ** Description      This function is called to perform bonding by designated transport
3577 **
3578 ** Parameters:      bd_addr      - Address of the device to bond
3579 **                  pin_len      - length in bytes of the PIN Code
3580 **                  p_pin        - pointer to array with the PIN Code
3581 **                  trusted_mask - bitwise OR of trusted services (array of UINT32)
3582 **                  transport :  Physical transport to use for bonding (BR/EDR or LE)
3583 **
3584 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
3585 **
3586 *******************************************************************************/
3587 //extern
3588 tBTM_STATUS BTM_SecBondByTransport (BD_ADDR bd_addr,
3589                                     tBT_TRANSPORT transport,
3590                                     UINT8 pin_len, UINT8 *p_pin,
3591                                     UINT32 trusted_mask[]);
3592 
3593 /*******************************************************************************
3594 **
3595 ** Function         BTM_SecBondCancel
3596 **
3597 ** Description      This function is called to cancel ongoing bonding process
3598 **                  with peer device.
3599 **
3600 ** Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
3601 **
3602 *******************************************************************************/
3603 //extern
3604 tBTM_STATUS BTM_SecBondCancel (BD_ADDR bd_addr);
3605 
3606 /*******************************************************************************
3607 **
3608 ** Function         BTM_SetEncryption
3609 **
3610 ** Description      This function is called to ensure that connection is
3611 **                  encrypted.  Should be called only on an open connection.
3612 **                  Typically only needed for connections that first want to
3613 **                  bring up unencrypted links, then later encrypt them.
3614 **
3615 ** Parameters:      bd_addr       - Address of the peer device
3616 **                  p_callback    - Pointer to callback function called if
3617 **                                  this function returns PENDING after required
3618 **                                  procedures are completed.  Can be set to NULL
3619 **                                  if status is not desired.
3620 **                  p_ref_data    - pointer to any data the caller wishes to receive
3621 **                                  in the callback function upon completion.
3622 *                                   can be set to NULL if not used.
3623 **
3624 ** Returns          BTM_SUCCESS   - already encrypted
3625 **                  BTM_PENDING   - command will be returned in the callback
3626 **                  BTM_WRONG_MODE- connection not up.
3627 **                  BTM_BUSY      - security procedures are currently active
3628 **                  BTM_MODE_UNSUPPORTED - if security manager not linked in.
3629 **
3630 *******************************************************************************/
3631 //extern
3632 tBTM_STATUS BTM_SetEncryption (BD_ADDR bd_addr, tBT_TRANSPORT transport,
3633                                tBTM_SEC_CBACK *p_callback, void *p_ref_data);
3634 
3635 /*******************************************************************************
3636 **
3637 ** Function         BTM_ConfirmReqReply
3638 **
3639 ** Description      This function is called to confirm the numeric value for
3640 **                  Simple Pairing in response to BTM_SP_CFM_REQ_EVT
3641 **
3642 ** Parameters:      res           - result of the operation BTM_SUCCESS if success
3643 **                  bd_addr       - Address of the peer device
3644 **
3645 *******************************************************************************/
3646 //extern
3647 void BTM_ConfirmReqReply(tBTM_STATUS res, BD_ADDR bd_addr);
3648 
3649 /*******************************************************************************
3650 **
3651 ** Function         BTM_PasskeyReqReply
3652 **
3653 ** Description      This function is called to provide the passkey for
3654 **                  Simple Pairing in response to BTM_SP_KEY_REQ_EVT
3655 **
3656 ** Parameters:      res           - result of the operation BTM_SUCCESS if success
3657 **                  bd_addr       - Address of the peer device
3658 **                  passkey       - numeric value in the range of 0 - 999999(0xF423F).
3659 **
3660 *******************************************************************************/
3661 //extern
3662 void BTM_PasskeyReqReply(tBTM_STATUS res, BD_ADDR bd_addr, UINT32 passkey);
3663 
3664 /*******************************************************************************
3665 **
3666 ** Function         BTM_SendKeypressNotif
3667 **
3668 ** Description      This function is used during the passkey entry model
3669 **                  by a device with KeyboardOnly IO capabilities
3670 **                  (very likely to be a HID Device).
3671 **                  It is called by a HID Device to inform the remote device when
3672 **                  a key has been entered or erased.
3673 **
3674 ** Parameters:      bd_addr - Address of the peer device
3675 **                  type - notification type
3676 **
3677 *******************************************************************************/
3678 //extern
3679 void BTM_SendKeypressNotif(BD_ADDR bd_addr, tBTM_SP_KEY_TYPE type);
3680 
3681 /*******************************************************************************
3682 **
3683 ** Function         BTM_IoCapRsp
3684 **
3685 ** Description      This function is called in response to BTM_SP_IO_REQ_EVT
3686 **                  When the event data io_req.oob_data is set to BTM_OOB_UNKNOWN
3687 **                  by the tBTM_SP_CALLBACK implementation, this function is
3688 **                  called to provide the actual response
3689 **
3690 ** Parameters:      bd_addr - Address of the peer device
3691 **                  io_cap  - The IO capability of local device.
3692 **                  oob     - BTM_OOB_NONE or BTM_OOB_PRESENT.
3693 **                  auth_req- MITM protection required or not.
3694 **
3695 *******************************************************************************/
3696 //extern
3697 void BTM_IoCapRsp(BD_ADDR bd_addr, tBTM_IO_CAP io_cap,
3698                   tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req);
3699 
3700 /*******************************************************************************
3701 **
3702 ** Function         BTM_ReadLocalOobData
3703 **
3704 ** Description      This function is called to read the local OOB data from
3705 **                  LM
3706 **
3707 *******************************************************************************/
3708 //extern
3709 tBTM_STATUS BTM_ReadLocalOobData(void);
3710 
3711 /*******************************************************************************
3712 **
3713 ** Function         BTM_RemoteOobDataReply
3714 **
3715 ** Description      This function is called to provide the remote OOB data for
3716 **                  Simple Pairing in response to BTM_SP_RMT_OOB_EVT
3717 **
3718 ** Parameters:      bd_addr     - Address of the peer device
3719 **                  c           - simple pairing Hash C.
3720 **                  r           - simple pairing Randomizer  C.
3721 **
3722 *******************************************************************************/
3723 //extern
3724 void BTM_RemoteOobDataReply(tBTM_STATUS res, BD_ADDR bd_addr,
3725                             BT_OCTET16 c, BT_OCTET16 r);
3726 
3727 /*******************************************************************************
3728 **
3729 ** Function         BTM_BuildOobData
3730 **
3731 ** Description      This function is called to build the OOB data payload to
3732 **                  be sent over OOB (non-Bluetooth) link
3733 **
3734 ** Parameters:      p_data  - the location for OOB data
3735 **                  max_len - p_data size.
3736 **                  c       - simple pairing Hash C.
3737 **                  r       - simple pairing Randomizer  C.
3738 **                  name_len- 0, local device name would not be included.
3739 **                            otherwise, the local device name is included for
3740 **                            up to this specified length
3741 **
3742 ** Returns          Number of bytes in p_data.
3743 **
3744 *******************************************************************************/
3745 //extern
3746 UINT16 BTM_BuildOobData(UINT8 *p_data, UINT16 max_len, BT_OCTET16 c,
3747                         BT_OCTET16 r, UINT8 name_len);
3748 
3749 /*******************************************************************************
3750 **
3751 ** Function         BTM_BothEndsSupportSecureConnections
3752 **
3753 ** Description      This function is called to check if both the local device and the peer device
3754 **                   specified by bd_addr support BR/EDR Secure Connections.
3755 **
3756 ** Parameters:      bd_addr - address of the peer
3757 **
3758 ** Returns          TRUE if BR/EDR Secure Connections are supported by both local
3759 **                  and the remote device.
3760 **                  else FALSE.
3761 **
3762 *******************************************************************************/
3763 //extern
3764 BOOLEAN BTM_BothEndsSupportSecureConnections(BD_ADDR bd_addr);
3765 
3766 /*******************************************************************************
3767 **
3768 ** Function         BTM_PeerSupportsSecureConnections
3769 **
3770 ** Description      This function is called to check if the peer supports
3771 **                  BR/EDR Secure Connections.
3772 **
3773 ** Parameters:      bd_addr - address of the peer
3774 **
3775 ** Returns          TRUE if BR/EDR Secure Connections are supported by the peer,
3776 **                  else FALSE.
3777 **
3778 *******************************************************************************/
3779 //extern
3780 BOOLEAN BTM_PeerSupportsSecureConnections(BD_ADDR bd_addr);
3781 
3782 /*******************************************************************************
3783 **
3784 ** Function         BTM_ReadOobData
3785 **
3786 ** Description      This function is called to parse the OOB data payload
3787 **                  received over OOB (non-Bluetooth) link
3788 **
3789 ** Parameters:      p_data  - the location for OOB data
3790 **                  eir_tag - The associated EIR tag to read the data.
3791 **                  *p_len(output) - the length of the data with the given tag.
3792 **
3793 ** Returns          the beginning of the data with the given tag.
3794 **                  NULL, if the tag is not found.
3795 **
3796 *******************************************************************************/
3797 //extern
3798 UINT8 *BTM_ReadOobData(UINT8 *p_data, UINT8 eir_tag, UINT8 *p_len);
3799 
3800 /*******************************************************************************
3801 **
3802 ** Function         BTM_SecReadDevName
3803 **
3804 ** Description      Looks for the device name in the security database for the
3805 **                  specified BD address.
3806 **
3807 ** Returns          Pointer to the name or NULL
3808 **
3809 *******************************************************************************/
3810 //extern
3811 char *BTM_SecReadDevName (BD_ADDR bd_addr);
3812 
3813 /*******************************************************************************
3814 **
3815 ** Function         BTM_SecClearSecurityFlags
3816 **
3817 ** Description      Reset the security flags (mark as not-paired) for a given
3818 **                  remove device.
3819 **
3820 *******************************************************************************/
3821 extern void BTM_SecClearSecurityFlags (BD_ADDR bd_addr);
3822 
3823 
3824 
3825 /*****************************************************************************
3826 **  POWER MANAGEMENT FUNCTIONS
3827 *****************************************************************************/
3828 /*******************************************************************************
3829 **
3830 ** Function         BTM_PmRegister
3831 **
3832 ** Description      register or deregister with power manager
3833 **
3834 ** Returns          BTM_SUCCESS if successful,
3835 **                  BTM_NO_RESOURCES if no room to hold registration
3836 **                  BTM_ILLEGAL_VALUE
3837 **
3838 *******************************************************************************/
3839 //extern
3840 tBTM_STATUS BTM_PmRegister (UINT8 mask, UINT8 *p_pm_id,
3841                             tBTM_PM_STATUS_CBACK *p_cb);
3842 
3843 
3844 /*******************************************************************************
3845 **
3846 ** Function         BTM_SetPowerMode
3847 **
3848 ** Description      store the mode in control block or
3849 **                  alter ACL connection behavior.
3850 **
3851 ** Returns          BTM_SUCCESS if successful,
3852 **                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
3853 **
3854 *******************************************************************************/
3855 //extern
3856 tBTM_STATUS BTM_SetPowerMode (UINT8 pm_id, BD_ADDR remote_bda,
3857                               tBTM_PM_PWR_MD *p_mode);
3858 
3859 
3860 /*******************************************************************************
3861 **
3862 ** Function         BTM_ReadPowerMode
3863 **
3864 ** Description      This returns the current mode for a specific
3865 **                  ACL connection.
3866 **
3867 ** Input Param      remote_bda - device address of desired ACL connection
3868 **
3869 ** Output Param     p_mode - address where the current mode is copied into.
3870 **                          BTM_ACL_MODE_NORMAL
3871 **                          BTM_ACL_MODE_HOLD
3872 **                          BTM_ACL_MODE_SNIFF
3873 **                          BTM_ACL_MODE_PARK
3874 **                          (valid only if return code is BTM_SUCCESS)
3875 **
3876 ** Returns          BTM_SUCCESS if successful,
3877 **                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
3878 **
3879 *******************************************************************************/
3880 //extern
3881 tBTM_STATUS BTM_ReadPowerMode (BD_ADDR remote_bda,
3882                                tBTM_PM_MODE *p_mode);
3883 
3884 /*******************************************************************************
3885 **
3886 ** Function         BTM_SetSsrParams
3887 **
3888 ** Description      This sends the given SSR parameters for the given ACL
3889 **                  connection if it is in ACTIVE mode.
3890 **
3891 ** Input Param      remote_bda - device address of desired ACL connection
3892 **                  max_lat    - maximum latency (in 0.625ms)(0-0xFFFE)
3893 **                  min_rmt_to - minimum remote timeout
3894 **                  min_loc_to - minimum local timeout
3895 **
3896 **
3897 ** Returns          BTM_SUCCESS if the HCI command is issued successful,
3898 **                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
3899 **                  BTM_CMD_STORED if the command is stored
3900 **
3901 *******************************************************************************/
3902 //extern
3903 tBTM_STATUS BTM_SetSsrParams (BD_ADDR remote_bda, UINT16 max_lat,
3904                               UINT16 min_rmt_to, UINT16 min_loc_to);
3905 
3906 /*******************************************************************************
3907 **
3908 ** Function         BTM_GetHCIConnHandle
3909 **
3910 ** Description      This function is called to get the handle for an ACL connection
3911 **                  to a specific remote BD Address.
3912 **
3913 ** Returns          the handle of the connection, or 0xFFFF if none.
3914 **
3915 *******************************************************************************/
3916 //extern
3917 UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport);
3918 
3919 /*******************************************************************************
3920 **
3921 ** Function         BTM_DeleteStoredLinkKey
3922 **
3923 ** Description      This function is called to delete link key for the specified
3924 **                  device addresses from the NVRAM storage attached to the Bluetooth
3925 **                  controller.
3926 **
3927 ** Parameters:      bd_addr      - Addresses of the devices
3928 **                  p_cb         - Call back function to be called to return
3929 **                                 the results
3930 **
3931 *******************************************************************************/
3932 //extern
3933 tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb);
3934 
3935 /*******************************************************************************
3936 **
3937 ** Function         BTM_WriteEIR
3938 **
3939 ** Description      This function is called to write EIR data to controller.
3940 **
3941 ** Parameters       p_buff - allocated HCI command buffer including extended
3942 **                           inquriry response
3943 **                  fec_required - FEC is required or not
3944 **
3945 ** Returns          BTM_SUCCESS  - if successful
3946 **                  BTM_MODE_UNSUPPORTED - if local device cannot support it
3947 **
3948 *******************************************************************************/
3949 //extern
3950 tBTM_STATUS BTM_WriteEIR( BT_HDR *p_buff, BOOLEAN fec_required);
3951 
3952 /*******************************************************************************
3953 **
3954 ** Function         BTM_CheckEirData
3955 **
3956 ** Description      This function is called to get EIR data from significant part.
3957 **
3958 ** Parameters       p_eir - pointer of EIR significant part
3959 **                  type   - finding EIR data type
3960 **                  p_length - return the length of EIR data
3961 **
3962 ** Returns          pointer of EIR data
3963 **
3964 *******************************************************************************/
3965 //extern
3966 UINT8 *BTM_CheckEirData( UINT8 *p_eir, UINT8 type, UINT8 *p_length );
3967 
3968 /*******************************************************************************
3969 **
3970 ** Function         BTM_HasEirService
3971 **
3972 ** Description      This function is called to know if UUID in bit map of UUID.
3973 **
3974 ** Parameters       p_eir_uuid - bit map of UUID list
3975 **                  uuid16 - UUID 16-bit
3976 **
3977 ** Returns          TRUE - if found
3978 **                  FALSE - if not found
3979 **
3980 *******************************************************************************/
3981 //extern
3982 BOOLEAN BTM_HasEirService( UINT32 *p_eir_uuid, UINT16 uuid16 );
3983 
3984 /*******************************************************************************
3985 **
3986 ** Function         BTM_HasInquiryEirService
3987 **
3988 ** Description      This function is called to know if UUID in bit map of UUID list.
3989 **
3990 ** Parameters       p_results - inquiry results
3991 **                  uuid16 - UUID 16-bit
3992 **
3993 ** Returns          BTM_EIR_FOUND - if found
3994 **                  BTM_EIR_NOT_FOUND - if not found and it is complete list
3995 **                  BTM_EIR_UNKNOWN - if not found and it is not complete list
3996 **
3997 *******************************************************************************/
3998 //extern
3999 tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService( tBTM_INQ_RESULTS *p_results,
4000         UINT16 uuid16 );
4001 
4002 /*******************************************************************************
4003 **
4004 ** Function         BTM_AddEirService
4005 **
4006 ** Description      This function is called to add a service in bit map of UUID list.
4007 **
4008 ** Parameters       p_eir_uuid - bit mask of UUID list for EIR
4009 **                  uuid16 - UUID 16-bit
4010 **
4011 ** Returns          None
4012 **
4013 *******************************************************************************/
4014 //extern
4015 void BTM_AddEirService( UINT32 *p_eir_uuid, UINT16 uuid16 );
4016 
4017 /*******************************************************************************
4018 **
4019 ** Function         BTM_RemoveEirService
4020 **
4021 ** Description      This function is called to remove a service in bit map of UUID list.
4022 **
4023 ** Parameters       p_eir_uuid - bit mask of UUID list for EIR
4024 **                  uuid16 - UUID 16-bit
4025 **
4026 ** Returns          None
4027 **
4028 *******************************************************************************/
4029 //extern
4030 void BTM_RemoveEirService( UINT32 *p_eir_uuid, UINT16 uuid16 );
4031 
4032 /*******************************************************************************
4033 **
4034 ** Function         BTM_GetEirSupportedServices
4035 **
4036 ** Description      This function is called to get UUID list from bit map of UUID list.
4037 **
4038 ** Parameters       p_eir_uuid - bit mask of UUID list for EIR
4039 **                  p - reference of current pointer of EIR
4040 **                  max_num_uuid16 - max number of UUID can be written in EIR
4041 **                  num_uuid16 - number of UUID have been written in EIR
4042 **
4043 ** Returns          BTM_EIR_MORE_16BITS_UUID_TYPE, if it has more than max
4044 **                  BTM_EIR_COMPLETE_16BITS_UUID_TYPE, otherwise
4045 **
4046 *******************************************************************************/
4047 //extern
4048 UINT8 BTM_GetEirSupportedServices( UINT32 *p_eir_uuid,    UINT8 **p,
4049                                    UINT8  max_num_uuid16, UINT8 *p_num_uuid16);
4050 
4051 /*******************************************************************************
4052 **
4053 ** Function         BTM_GetEirUuidList
4054 **
4055 ** Description      This function parses EIR and returns UUID list.
4056 **
4057 ** Parameters       p_eir - EIR
4058 **                  uuid_size - LEN_UUID_16, LEN_UUID_32, LEN_UUID_128
4059 **                  p_num_uuid - return number of UUID in found list
4060 **                  p_uuid_list - return UUID 16-bit list
4061 **                  max_num_uuid - maximum number of UUID to be returned
4062 **
4063 ** Returns          0 - if not found
4064 **                  BTM_EIR_COMPLETE_16BITS_UUID_TYPE
4065 **                  BTM_EIR_MORE_16BITS_UUID_TYPE
4066 **                  BTM_EIR_COMPLETE_32BITS_UUID_TYPE
4067 **                  BTM_EIR_MORE_32BITS_UUID_TYPE
4068 **                  BTM_EIR_COMPLETE_128BITS_UUID_TYPE
4069 **                  BTM_EIR_MORE_128BITS_UUID_TYPE
4070 **
4071 *******************************************************************************/
4072 //extern
4073 UINT8 BTM_GetEirUuidList( UINT8 *p_eir, UINT8 uuid_size, UINT8 *p_num_uuid,
4074                           UINT8 *p_uuid_list, UINT8 max_num_uuid);
4075 
4076 /*****************************************************************************
4077 **  SCO OVER HCI
4078 *****************************************************************************/
4079 /*******************************************************************************
4080 **
4081 ** Function         BTM_ConfigScoPath
4082 **
4083 ** Description      This function enable/disable SCO over HCI and registers SCO
4084 **                  data callback if SCO over HCI is enabled.
4085 **
4086 ** Parameter        path: SCO or HCI
4087 **                  p_sco_data_cb: callback function or SCO data if path is set
4088 **                                 to transport.
4089 **                  p_pcm_param: pointer to the PCM interface parameter. If a NULL
4090 **                               pointer is used, PCM parameter maintained in
4091 **                               the control block will be used; otherwise update
4092 **                               control block value.
4093 **                  err_data_rpt: Lisbon feature to enable the erronous data report
4094 **                                or not.
4095 **
4096 ** Returns          BTM_SUCCESS if the successful.
4097 **                  BTM_NO_RESOURCES: no rsource to start the command.
4098 **                  BTM_ILLEGAL_VALUE: invalid callback function pointer.
4099 **                  BTM_CMD_STARTED :Command sent. Waiting for command cmpl event.
4100 **
4101 **
4102 *******************************************************************************/
4103 //extern
4104 tBTM_STATUS BTM_ConfigScoPath (tBTM_SCO_ROUTE_TYPE path,
4105                                tBTM_SCO_DATA_CB *p_sco_data_cb,
4106                                tBTM_SCO_PCM_PARAM *p_pcm_param,
4107                                BOOLEAN err_data_rpt);
4108 
4109 /*******************************************************************************
4110 **
4111 ** Function         BTM_WriteScoData
4112 **
4113 ** Description      This function write SCO data to a specified instance. The data
4114 **                  to be written p_buf needs to carry an offset of
4115 **                  HCI_SCO_PREAMBLE_SIZE bytes, and the data length can not
4116 **                  exceed BTM_SCO_DATA_SIZE_MAX bytes, whose default value is set
4117 **                  to 60 and is configurable. Data longer than the maximum bytes
4118 **                  will be truncated.
4119 **
4120 ** Returns          BTM_SUCCESS: data write is successful
4121 **                  BTM_ILLEGAL_VALUE: SCO data contains illegal offset value.
4122 **                  BTM_SCO_BAD_LENGTH: SCO data length exceeds the max SCO packet
4123 **                                      size.
4124 **                  BTM_NO_RESOURCES: no resources.
4125 **                  BTM_UNKNOWN_ADDR: unknown SCO connection handle, or SCO is not
4126 **                                    routed via HCI.
4127 **
4128 **
4129 *******************************************************************************/
4130 //extern
4131 tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf);
4132 
4133 /*******************************************************************************
4134 **
4135 ** Function         BTM_SetARCMode
4136 **
4137 ** Description      Send Audio Routing Control command.
4138 **
4139 ** Returns          void
4140 **
4141 *******************************************************************************/
4142 //extern
4143 void BTM_SetARCMode (UINT8 iface, UINT8 arc_mode, tBTM_VSC_CMPL_CB *p_arc_cb);
4144 
4145 
4146 /*******************************************************************************
4147 **
4148 ** Function         BTM_PCM2Setup_Write
4149 **
4150 ** Description      Send PCM2_Setup write command.
4151 **
4152 ** Returns          void
4153 **
4154 *******************************************************************************/
4155 //extern
4156 void BTM_PCM2Setup_Write (BOOLEAN clk_master, tBTM_VSC_CMPL_CB *p_arc_cb);
4157 
4158 
4159 /*******************************************************************************
4160 **
4161 ** Function         BTM_PM_ReadControllerState
4162 **
4163 ** Description      This function is called to obtain the controller state
4164 **
4165 ** Returns          Controller state (BTM_CONTRL_ACTIVE, BTM_CONTRL_SCAN, and BTM_CONTRL_IDLE)
4166 **
4167 *******************************************************************************/
4168 //extern
4169 tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void);
4170 
4171 /*******************************************************************************
4172 **
4173 ** Function         BTM_SetAfhChannels
4174 **
4175 ** Description      This function is called to set AFH channels
4176 **
4177 ** Returns          status of the operation
4178 **
4179 *******************************************************************************/
4180 tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_channels_cmpl_cback);
4181 
4182 /*******************************************************************************
4183 **
4184 ** Function         BTM_BleSetChannels
4185 **
4186 ** Description      This function is called to set BLE channels
4187 **
4188 ** Returns          status of the operation
4189 **
4190 *******************************************************************************/
4191 tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback);
4192 
4193 #ifdef __cplusplus
4194 }
4195 #endif
4196 
4197 #endif /* BTM_API_H */
4198