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