OSDN Git Service

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