1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "stack/include/btm_api_types.h"
20 #include "stack/include/btm_ble_api_types.h"
21 
22 namespace bluetooth {
23 namespace shim {
24 
25 /*******************************************************************************
26  *
27  * Function         BTM_StartInquiry
28  *
29  * Description      This function is called to start an inquiry.
30  *
31  * Parameters:      p_inqparms - pointer to the inquiry information
32  *                      mode - GENERAL or LIMITED inquiry
33  *                      duration - length in 1.28 sec intervals (If '0', the
34  *                                 inquiry is CANCELLED)
35  *                      max_resps - maximum amount of devices to search for
36  *                                  before ending the inquiry
37  *                      filter_cond_type - BTM_CLR_INQUIRY_FILTER,
38  *                                         BTM_FILTER_COND_DEVICE_CLASS, or
39  *                                         BTM_FILTER_COND_BD_ADDR
40  *                      filter_cond - value for the filter (based on
41  *                                                          filter_cond_type)
42  *
43  *                  p_results_cb  - Pointer to the callback routine which gets
44  *                                called upon receipt of an inquiry result. If
45  *                                this field is NULL, the application is not
46  *                                notified.
47  *
48  *                  p_cmpl_cb   - Pointer to the callback routine which gets
49  *                                called upon completion.  If this field is
50  *                                NULL, the application is not notified when
51  *                                completed.
52  * Returns          tBTM_STATUS
53  *                  BTM_CMD_STARTED if successfully initiated
54  *                  BTM_BUSY if already in progress
55  *                  BTM_ILLEGAL_VALUE if parameter(s) are out of range
56  *                  BTM_NO_RESOURCES if could not allocate resources to start
57  *                                   the command
58  *                  BTM_WRONG_MODE if the device is not up.
59  *
60  ******************************************************************************/
61 tBTM_STATUS BTM_StartInquiry(tBTM_INQ_PARMS* p_inqparms,
62                              tBTM_INQ_RESULTS_CB* p_results_cb,
63                              tBTM_CMPL_CB* p_cmpl_cb);
64 
65 /*******************************************************************************
66  *
67  * Function         BTM_SetDiscoverability
68  *
69  * Description      This function is called to set the device into or out of
70  *                  discoverable mode. Discoverable mode means inquiry
71  *                  scans are enabled.  If a value of '0' is entered for window
72  *                  or interval, the default values are used.
73  *
74  * Returns          BTM_SUCCESS if successful
75  *                  BTM_BUSY if a setting of the filter is already in progress
76  *                  BTM_NO_RESOURCES if couldn't get a memory pool buffer
77  *                  BTM_ILLEGAL_VALUE if a bad parameter was detected
78  *                  BTM_WRONG_MODE if the device is not up.
79  *
80  ******************************************************************************/
81 tBTM_STATUS BTM_SetDiscoverability(uint16_t inq_mode, uint16_t window,
82                                    uint16_t interval);
83 
84 /*******************************************************************************
85  *
86  * Function         BTM_SetInquiryScanType
87  *
88  * Description      This function is called to set the iquiry scan-type to
89  *                  standard or interlaced.
90  *
91  * Input Params:    BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED
92  *
93  * Returns          BTM_SUCCESS if successful
94  *                  BTM_MODE_UNSUPPORTED if not a 1.2 device
95  *                  BTM_WRONG_MODE if the device is not up.
96  *
97  ******************************************************************************/
98 tBTM_STATUS BTM_SetInquiryScanType(uint16_t scan_type);
99 
100 /*******************************************************************************
101  *
102  * Function         BTM_BleObserve
103  *
104  * Description      This procedure keep the device listening for advertising
105  *                  events from a broadcast device.
106  *
107  * Parameters       start: start or stop observe.
108  *
109  * Returns          void
110  *
111  ******************************************************************************/
112 tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration,
113                            tBTM_INQ_RESULTS_CB* p_results_cb,
114                            tBTM_CMPL_CB* p_cmpl_cb);
115 
116 /*******************************************************************************
117  *
118  * Function         BTM_SetPageScanType
119  *
120  * Description      This function is called to set the page scan-type to
121  *                  standard or interlaced.
122  *
123  * Input Params:    BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED
124  *
125  * Returns          BTM_SUCCESS if successful
126  *                  BTM_MODE_UNSUPPORTED if not a 1.2 device
127  *                  BTM_WRONG_MODE if the device is not up.
128  *
129  ******************************************************************************/
130 tBTM_STATUS BTM_SetPageScanType(uint16_t scan_type);
131 
132 /*******************************************************************************
133  *
134  * Function         BTM_SetInquiryMode
135  *
136  * Description      This function is called to set standard, with RSSI
137  *                  mode or extended of the inquiry for local device.
138  *
139  * Input Params:    BTM_INQ_RESULT_STANDARD, BTM_INQ_RESULT_WITH_RSSI or
140  *                  BTM_INQ_RESULT_EXTENDED
141  *
142  * Returns          BTM_SUCCESS if successful
143  *                  BTM_NO_RESOURCES if couldn't get a memory pool buffer
144  *                  BTM_ILLEGAL_VALUE if a bad parameter was detected
145  *                  BTM_WRONG_MODE if the device is not up.
146  *
147  ******************************************************************************/
148 tBTM_STATUS BTM_SetInquiryMode(uint8_t mode);
149 
150 /*******************************************************************************
151  *
152  * Function         BTM_ReadDiscoverability
153  *
154  * Description      This function is called to read the current discoverability
155  *                  mode of the device.
156  *
157  * Output Params:   p_window - current inquiry scan duration
158  *                  p_interval - current inquiry scan interval
159  *
160  * Returns          BTM_NON_DISCOVERABLE, BTM_LIMITED_DISCOVERABLE, or
161  *                  BTM_GENERAL_DISCOVERABLE
162  *
163  ******************************************************************************/
164 uint16_t BTM_ReadDiscoverability(uint16_t* p_window, uint16_t* p_interval);
165 
166 /*******************************************************************************
167  *
168  * Function         BTM_CancelPeriodicInquiry
169  *
170  * Description      This function cancels a periodic inquiry
171  *
172  * Returns
173  *                  BTM_NO_RESOURCES if could not allocate a message buffer
174  *                  BTM_SUCCESS - if cancelling the periodic inquiry
175  *                  BTM_WRONG_MODE if the device is not up.
176  *
177  ******************************************************************************/
178 tBTM_STATUS BTM_CancelPeriodicInquiry(void);
179 
180 /*******************************************************************************
181  *
182  * Function         BTM_SetConnectability
183  *
184  * Description      This function is called to set the device into or out of
185  *                  connectable mode. Discoverable mode means page scans are
186  *                  enabled.
187  *
188  * Returns          BTM_SUCCESS if successful
189  *                  BTM_ILLEGAL_VALUE if a bad parameter is detected
190  *                  BTM_NO_RESOURCES if could not allocate a message buffer
191  *                  BTM_WRONG_MODE if the device is not up.
192  *
193  ******************************************************************************/
194 tBTM_STATUS BTM_SetConnectability(uint16_t page_mode, uint16_t window,
195                                   uint16_t interval);
196 
197 /*******************************************************************************
198  *
199  * Function         BTM_ReadConnectability
200  *
201  * Description      This function is called to read the current discoverability
202  *                  mode of the device.
203  * Output Params    p_window - current page scan duration
204  *                  p_interval - current time between page scans
205  *
206  * Returns          BTM_NON_CONNECTABLE or BTM_CONNECTABLE
207  *
208  ******************************************************************************/
209 uint16_t BTM_ReadConnectability(uint16_t* p_window, uint16_t* p_interval);
210 
211 /*******************************************************************************
212  *
213  * Function         BTM_IsInquiryActive
214  *
215  * Description      Return a bit mask of the current inquiry state
216  *
217  * Returns          BTM_INQUIRY_INACTIVE if inactive (0)
218  *                  BTM_LIMITED_INQUIRY_ACTIVE if a limted inquiry is active
219  *                  BTM_GENERAL_INQUIRY_ACTIVE if a general inquiry is active
220  *                  BTM_PERIODIC_INQUIRY_ACTIVE if a periodic inquiry is active
221  *
222  ******************************************************************************/
223 uint16_t BTM_IsInquiryActive(void);
224 
225 /*******************************************************************************
226  *
227  * Function         BTM_CancelInquiry
228  *
229  * Description      This function cancels an inquiry if active
230  *
231  * Returns          BTM_SUCCESS if successful
232  *                  BTM_NO_RESOURCES if could not allocate a message buffer
233  *                  BTM_WRONG_MODE if the device is not up.
234  *
235  ******************************************************************************/
236 tBTM_STATUS BTM_CancelInquiry(void);
237 
238 /*******************************************************************************
239  *
240  * Function         BTM_ReadRemoteDeviceName
241  *
242  * Description      This function initiates a remote device HCI command to the
243  *                  controller and calls the callback when the process has
244  *                  completed.
245  *
246  * Input Params:    remote_bda      - device address of name to retrieve
247  *                  p_cb            - callback function called when
248  *                                    BTM_CMD_STARTED is returned.
249  *                                    A pointer to tBTM_REMOTE_DEV_NAME is
250  *                                    passed to the callback.
251  *
252  * Returns
253  *                  BTM_CMD_STARTED is returned if the request was successfully
254  *                                  sent to HCI.
255  *                  BTM_BUSY if already in progress
256  *                  BTM_UNKNOWN_ADDR if device address is bad
257  *                  BTM_NO_RESOURCES if resources could not be allocated to
258  *                                   start the command
259  *                  BTM_WRONG_MODE if the device is not up.
260  *
261  ******************************************************************************/
262 tBTM_STATUS BTM_ReadRemoteDeviceName(const RawAddress& remote_bda,
263                                      tBTM_CMPL_CB* p_cb,
264                                      tBT_TRANSPORT transport);
265 
266 /*******************************************************************************
267  *
268  * Function         BTM_CancelRemoteDeviceName
269  *
270  * Description      This function initiates the cancel request for the specified
271  *                  remote device.
272  *
273  * Input Params:    None
274  *
275  * Returns
276  *                  BTM_CMD_STARTED is returned if the request was successfully
277  *                                  sent to HCI.
278  *                  BTM_NO_RESOURCES if resources could not be allocated to
279  *                                   start the command
280  *                  BTM_WRONG_MODE if there is no active remote name request.
281  *
282  ******************************************************************************/
283 tBTM_STATUS BTM_CancelRemoteDeviceName(void);
284 
285 /*******************************************************************************
286  *
287  * Function         BTM_InqDbRead
288  *
289  * Description      This function looks through the inquiry database for a match
290  *                  based on Bluetooth Device Address. This is the application's
291  *                  interface to get the inquiry details of a specific BD
292  *                  address.
293  *
294  * Returns          pointer to entry, or NULL if not found
295  *
296  ******************************************************************************/
297 tBTM_INQ_INFO* BTM_InqDbRead(const RawAddress& p_bda);
298 
299 /*******************************************************************************
300  *
301  * Function         BTM_InqDbFirst
302  *
303  * Description      This function looks through the inquiry database for the
304  *                  first used entry, and returns that. This is used in
305  *                  conjunction with BTM_InqDbNext by applications as a way to
306  *                  walk through the inquiry database.
307  *
308  * Returns          pointer to first in-use entry, or NULL if DB is empty
309  *
310  ******************************************************************************/
311 tBTM_INQ_INFO* BTM_InqDbFirst(void);
312 
313 /*******************************************************************************
314  *
315  * Function         BTM_InqDbNext
316  *
317  * Description      This function looks through the inquiry database for the
318  *                  next used entry, and returns that.  If the input parameter
319  *                  is NULL, the first entry is returned.
320  *
321  * Returns          pointer to next in-use entry, or NULL if no more found.
322  *
323  ******************************************************************************/
324 tBTM_INQ_INFO* BTM_InqDbNext(tBTM_INQ_INFO* p_cur);
325 
326 /*******************************************************************************
327  *
328  * Function         BTM_ClearInqDb
329  *
330  * Description      This function is called to clear out a device or all devices
331  *                  from the inquiry database.
332  *
333  * Parameter        p_bda - (input) BD_ADDR ->  Address of device to clear
334  *                                              (NULL clears all entries)
335  *
336  * Returns          BTM_BUSY if an inquiry, get remote name, or event filter
337  *                          is active, otherwise BTM_SUCCESS
338  *
339  ******************************************************************************/
340 tBTM_STATUS BTM_ClearInqDb(const RawAddress* p_bda);
341 
342 /*******************************************************************************
343  *
344  * Function         BTM_WriteEIR
345  *
346  * Description      This function is called to write EIR data to controller.
347  *
348  * Parameters       p_buff - allocated HCI command buffer including extended
349  *                           inquriry response
350  *
351  * Returns          BTM_SUCCESS  - if successful
352  *                  BTM_MODE_UNSUPPORTED - if local device cannot support it
353  *
354  ******************************************************************************/
355 tBTM_STATUS BTM_WriteEIR(BT_HDR* p_buff);
356 
357 /*******************************************************************************
358  *
359  * Function         BTM_HasEirService
360  *
361  * Description      This function is called to know if UUID in bit map of UUID.
362  *
363  * Parameters       p_eir_uuid - bit map of UUID list
364  *                  uuid16 - UUID 16-bit
365  *
366  * Returns          true - if found
367  *                  false - if not found
368  *
369  ******************************************************************************/
370 bool BTM_HasEirService(const uint32_t* p_eir_uuid, uint16_t uuid16);
371 
372 /*******************************************************************************
373  *
374  * Function         BTM_HasInquiryEirService
375  *
376  * Description      Return if a UUID is in the bit map of a UUID list.
377  *
378  * Parameters       p_results - inquiry results
379  *                  uuid16 - UUID 16-bit
380  *
381  * Returns          BTM_EIR_FOUND - if found
382  *                  BTM_EIR_NOT_FOUND - if not found and it is a complete list
383  *                  BTM_EIR_UNKNOWN - if not found and it is not complete list
384  *
385  ******************************************************************************/
386 tBTM_EIR_SEARCH_RESULT BTM_HasInquiryEirService(tBTM_INQ_RESULTS* p_results,
387                                                 uint16_t uuid16);
388 
389 /*******************************************************************************
390  *
391  * Function         BTM_AddEirService
392  *
393  * Description      This function is called to add a service in the bit map UUID
394  *                  list.
395  *
396  * Parameters       p_eir_uuid - bit mask of UUID list for EIR
397  *                  uuid16 - UUID 16-bit
398  *
399  * Returns          None
400  *
401  ******************************************************************************/
402 void BTM_AddEirService(uint32_t* p_eir_uuid, uint16_t uuid16);
403 
404 /*******************************************************************************
405  *
406  * Function         BTM_RemoveEirService
407  *
408  * Description      This function is called to remove a service from the bit map
409  *                  UUID list.
410  *
411  * Parameters       p_eir_uuid - bit mask of UUID list for EIR
412  *                  uuid16 - UUID 16-bit
413  *
414  * Returns          None
415  *
416  ******************************************************************************/
417 void BTM_RemoveEirService(uint32_t* p_eir_uuid, uint16_t uuid16);
418 
419 /*******************************************************************************
420  *
421  * Function         BTM_GetEirSupportedServices
422  *
423  * Description      This function is called to get UUID list from bit map UUID
424  *                  list.
425  *
426  * Parameters       p_eir_uuid - bit mask of UUID list for EIR
427  *                  p - reference of current pointer of EIR
428  *                  max_num_uuid16 - max number of UUID can be written in EIR
429  *                  num_uuid16 - number of UUID have been written in EIR
430  *
431  * Returns          BTM_EIR_MORE_16BITS_UUID_TYPE, if it has more than max
432  *                  BTM_EIR_COMPLETE_16BITS_UUID_TYPE, otherwise
433  *
434  ******************************************************************************/
435 uint8_t BTM_GetEirSupportedServices(uint32_t* p_eir_uuid, uint8_t** p,
436                                     uint8_t max_num_uuid16,
437                                     uint8_t* p_num_uuid16);
438 
439 /*******************************************************************************
440  *
441  * Function         BTM_GetEirUuidList
442  *
443  * Description      This function parses EIR and returns UUID list.
444  *
445  * Parameters       p_eir - EIR
446  *                  eirl_len - EIR len
447  *                  uuid_size - Uuid::kNumBytes16, Uuid::kNumBytes32,
448  *                              Uuid::kNumBytes128
449  *                  p_num_uuid - return number of UUID in found list
450  *                  p_uuid_list - return UUID 16-bit list
451  *                  max_num_uuid - maximum number of UUID to be returned
452  *
453  * Returns          0 - if not found
454  *                  BTM_EIR_COMPLETE_16BITS_UUID_TYPE
455  *                  BTM_EIR_MORE_16BITS_UUID_TYPE
456  *                  BTM_EIR_COMPLETE_32BITS_UUID_TYPE
457  *                  BTM_EIR_MORE_32BITS_UUID_TYPE
458  *                  BTM_EIR_COMPLETE_128BITS_UUID_TYPE
459  *                  BTM_EIR_MORE_128BITS_UUID_TYPE
460  *
461  ******************************************************************************/
462 uint8_t BTM_GetEirUuidList(uint8_t* p_eir, size_t eir_len, uint8_t uuid_size,
463                            uint8_t* p_num_uuid, uint8_t* p_uuid_list,
464                            uint8_t max_num_uuid);
465 
466 /*******************************************************************************
467  *
468  * Function         BTM_SecAddBleDevice
469  *
470  * Description      Add/modify device.  This function will be normally called
471  *                  during host startup to restore all required information
472  *                  for a LE device stored in the NVRAM.
473  *
474  * Parameters:      bd_addr          - BD address of the peer
475  *                  bd_name          - Name of the peer device. NULL if unknown.
476  *                  dev_type         - Remote device's device type.
477  *                  addr_type        - LE device address type.
478  *
479  * Returns          true if added OK, else false
480  *
481  ******************************************************************************/
482 bool BTM_SecAddBleDevice(const RawAddress& bd_addr, BD_NAME bd_name,
483                          tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type);
484 
485 /*******************************************************************************
486  *
487  * Function         BTM_SecAddBleKey
488  *
489  * Description      Add/modify LE device information.  This function will be
490  *                  normally called during host startup to restore all required
491  *                  information stored in the NVRAM.
492  *
493  * Parameters:      bd_addr          - BD address of the peer
494  *                  p_le_key         - LE key values.
495  *                  key_type         - LE SMP key type.
496  *
497  * Returns          true if added OK, else false
498  *
499  ******************************************************************************/
500 bool BTM_SecAddBleKey(const RawAddress& bd_addr, tBTM_LE_KEY_VALUE* p_le_key,
501                       tBTM_LE_KEY_TYPE key_type);
502 
503 /*******************************************************************************
504  *
505  * Function         BTM_BleLoadLocalKeys
506  *
507  * Description      Local local identity key, encryption root or sign counter.
508  *
509  * Parameters:      key_type: type of key, can be BTM_BLE_KEY_TYPE_ID,
510  *                            BTM_BLE_KEY_TYPE_ER
511  *                            or BTM_BLE_KEY_TYPE_COUNTER.
512  *                  p_key: pointer to the key.
513  *
514  * Returns          non2.
515  *
516  ******************************************************************************/
517 void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key);
518 
519 /** Returns local device encryption root (ER) */
520 const Octet16& BTM_GetDeviceEncRoot();
521 
522 /** Returns local device identity root (IR) */
523 const Octet16& BTM_GetDeviceIDRoot();
524 
525 /** Return local device DHK. */
526 const Octet16& BTM_GetDeviceDHK();
527 
528 /*******************************************************************************
529  *
530  * Function         BTM_ReadConnectionAddr
531  *
532  * Description      Read the local device random address.
533  *
534  * Returns          void
535  *
536  ******************************************************************************/
537 void BTM_ReadConnectionAddr(const RawAddress& remote_bda,
538                             RawAddress& local_conn_addr,
539                             tBLE_ADDR_TYPE* p_addr_type);
540 
541 /*******************************************************************************
542  *
543  * Function         BTM_ReadRemoteConnectionAddr
544  *
545  * Description      Read the remote device address currently used.
546  *
547  * Returns          void
548  *
549  ******************************************************************************/
550 bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr,
551                                   RawAddress& conn_addr,
552                                   tBLE_ADDR_TYPE* p_addr_type);
553 
554 /*******************************************************************************
555  *
556  * Function         BTM_SecurityGrant
557  *
558  * Description      This function is called to grant security process.
559  *
560  * Parameters       bd_addr - peer device bd address.
561  *                  res     - result of the operation BTM_SUCCESS if success.
562  *                            Otherwise, BTM_REPEATED_ATTEMPTS is too many
563  *                            attempts.
564  *
565  * Returns          None
566  *
567  ******************************************************************************/
568 void BTM_SecurityGrant(const RawAddress& bd_addr, uint8_t res);
569 
570 /*******************************************************************************
571  *
572  * Function         BTM_LeOobDataReply
573  *
574  * Description      This function is called to provide the OOB data for
575  *                  SMP in response to BTM_LE_OOB_REQ_EVT
576  *
577  * Parameters:      bd_addr     - Address of the peer device
578  *                  res         - result of the operation SMP_SUCCESS if success
579  *                  p_data      - simple pairing Randomizer  C.
580  *
581  ******************************************************************************/
582 void BTM_BleOobDataReply(const RawAddress& bd_addr, uint8_t res, uint8_t len,
583                          uint8_t* p_data);
584 
585 /*******************************************************************************
586  *
587  * Function         BTM_BleSecureConnectionOobDataReply
588  *
589  * Description      This function is called to provide the OOB data for
590  *                  SMP in response to BTM_LE_OOB_REQ_EVT when secure connection
591  *                  data is available
592  *
593  * Parameters:      bd_addr     - Address of the peer device
594  *                  p_c         - pointer to Confirmation
595  *                  p_r         - pointer to Randomizer.
596  *
597  ******************************************************************************/
598 void BTM_BleSecureConnectionOobDataReply(const RawAddress& bd_addr,
599                                          uint8_t* p_c, uint8_t* p_r);
600 
601 /******************************************************************************
602  *
603  * Function         BTM_BleSetConnScanParams
604  *
605  * Description      Set scan parameters used in BLE connection request
606  *
607  * Parameters:      scan_interval    - scan interval
608  *                  scan_window      - scan window
609  *
610  * Returns          void
611  *
612  ******************************************************************************/
613 void BTM_BleSetConnScanParams(uint32_t scan_interval, uint32_t scan_window);
614 
615 /********************************************************
616  *
617  * Function         BTM_BleSetPrefConnParams
618  *
619  * Description      Set a peripheral's preferred connection parameters. When
620  *                  any of the value does not want to be updated while others
621  *                  do, use BTM_BLE_CONN_PARAM_UNDEF for the ones want to
622  *                  leave untouched.
623  *
624  * Parameters:      bd_addr          - BD address of the peripheral
625  *                  min_conn_int     - minimum preferred connection interval
626  *                  max_conn_int     - maximum preferred connection interval
627  *                  slave_latency    - preferred slave latency
628  *                  supervision_tout - preferred supervision timeout
629  *
630  * Returns          void
631  *
632  ******************************************************************************/
633 void BTM_BleSetPrefConnParams(const RawAddress& bd_addr, uint16_t min_conn_int,
634                               uint16_t max_conn_int, uint16_t slave_latency,
635                               uint16_t supervision_tout);
636 
637 /*******************************************************************************
638  *
639  * Function         BTM_ReadDevInfo
640  *
641  * Description      This function is called to read the device/address type
642  *                  of BD address.
643  *
644  * Parameter        remote_bda: remote device address
645  *                  p_dev_type: output parameter to read the device type.
646  *                  p_addr_type: output parameter to read the address type.
647  *
648  ******************************************************************************/
649 void BTM_ReadDevInfo(const RawAddress& remote_bda, tBT_DEVICE_TYPE* p_dev_type,
650                      tBLE_ADDR_TYPE* p_addr_type);
651 
652 /*******************************************************************************
653  *
654  * Function         BTM_ReadConnectedTransportAddress
655  *
656  * Description      This function is called to read the paired device/address
657  *                  type of other device paired corresponding to the BD_address
658  *
659  * Parameter        remote_bda: remote device address, carry out the transport
660  *                              address
661  *                  transport: active transport
662  *
663  * Return           true if an active link is identified; false otherwise
664  *
665  ******************************************************************************/
666 bool BTM_ReadConnectedTransportAddress(RawAddress* remote_bda,
667                                        tBT_TRANSPORT transport);
668 
669 /*******************************************************************************
670  *
671  * Function         BTM_BleReceiverTest
672  *
673  * Description      This function is called to start the LE Receiver test
674  *
675  * Parameter       rx_freq - Frequency Range
676  *               p_cmd_cmpl_cback - Command Complete callback
677  *
678  ******************************************************************************/
679 void BTM_BleReceiverTest(uint8_t rx_freq, tBTM_CMPL_CB* p_cmd_cmpl_cback);
680 
681 /*******************************************************************************
682  *
683  * Function         BTM_BleTransmitterTest
684  *
685  * Description      This function is called to start the LE Transmitter test
686  *
687  * Parameter       tx_freq - Frequency Range
688  *                       test_data_len - Length in bytes of payload data in each
689  *                                       packet
690  *                       packet_payload - Pattern to use in the payload
691  *                       p_cmd_cmpl_cback - Command Complete callback
692  *
693  ******************************************************************************/
694 void BTM_BleTransmitterTest(uint8_t tx_freq, uint8_t test_data_len,
695                             uint8_t packet_payload,
696                             tBTM_CMPL_CB* p_cmd_cmpl_cback);
697 
698 /*******************************************************************************
699  *
700  * Function         BTM_BleTestEnd
701  *
702  * Description     This function is called to stop the in-progress TX or RX test
703  *
704  * Parameter       p_cmd_cmpl_cback - Command complete callback
705  *
706  ******************************************************************************/
707 void BTM_BleTestEnd(tBTM_CMPL_CB* p_cmd_cmpl_cback);
708 
709 /*******************************************************************************
710  *
711  * Function         BTM_UseLeLink
712  *
713  * Description      Select the underlying physical link to use.
714  *
715  * Returns          true to use LE, false use BR/EDR.
716  *
717  ******************************************************************************/
718 bool BTM_UseLeLink(const RawAddress& bd_addr);
719 
720 /*******************************************************************************
721  *
722  * Function         BTM_SetBleDataLength
723  *
724  * Description      Set the maximum BLE transmission packet size
725  *
726  * Returns          BTM_SUCCESS if success; otherwise failed.
727  *
728  ******************************************************************************/
729 tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
730                                  uint16_t tx_pdu_length);
731 
732 /*******************************************************************************
733  *
734  * Function         BTM_BleReadPhy
735  *
736  * Description      To read the current PHYs for specified LE connection
737  *
738  *
739  * Returns          BTM_SUCCESS if success; otherwise failed.
740  *
741  ******************************************************************************/
742 void BTM_BleReadPhy(
743     const RawAddress& bd_addr,
744     base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb);
745 
746 /*******************************************************************************
747  *
748  * Function         BTM_BleSetPhy
749  *
750  * Description      To set PHY preferences for specified LE connection
751  *
752  *
753  * Returns          BTM_SUCCESS if success; otherwise failed.
754  *                  BTM_MODE_UNSUPPORTED if local controller doesn't support LE
755  *                  2M or LE Coded PHY,
756  *                  BTM_ILLEGAL_VALUE if specified remote doesn't support LE 2M
757  *                  or LE Coded PHY,
758  *                  BTM_WRONG_MODE if Device in wrong mode for request.
759  *
760  ******************************************************************************/
761 void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
762                    uint16_t phy_options);
763 
764 /*******************************************************************************
765  *
766  * Function         BTM_BleDataSignature
767  *
768  * Description      This function is called to sign the data using AES128 CMAC
769  *                  algorith.
770  *
771  * Parameter        bd_addr: target device the data to be signed for.
772  *                  p_text: singing data
773  *                  len: length of the signing data
774  *                  signature: output parameter where data signature is going to
775  *                             be stored.
776  *
777  * Returns          true if signing sucessul, otherwise false.
778  *
779  ******************************************************************************/
780 bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text,
781                           uint16_t len, BLE_SIGNATURE signature);
782 
783 /*******************************************************************************
784  *
785  * Function         BTM_BleVerifySignature
786  *
787  * Description      This function is called to verify the data signature
788  *
789  * Parameter        bd_addr: target device the data to be signed for.
790  *                  p_orig:  original data before signature.
791  *                  len: length of the signing data
792  *                  counter: counter used when doing data signing
793  *                  p_comp: signature to be compared against.
794 
795  * Returns          true if signature verified correctly; otherwise false.
796  *
797  ******************************************************************************/
798 bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig,
799                             uint16_t len, uint32_t counter, uint8_t* p_comp);
800 
801 /*******************************************************************************
802  *
803  * Function         BTM_GetLeSecurityState
804  *
805  * Description      This function is called to get security mode 1 flags and
806  *                  encryption key size for LE peer.
807  *
808  * Returns          bool    true if LE device is found, false otherwise.
809  *
810  ******************************************************************************/
811 bool BTM_GetLeSecurityState(const RawAddress& bd_addr,
812                             uint8_t* p_le_dev_sec_flags,
813                             uint8_t* p_le_key_size);
814 
815 /*******************************************************************************
816  *
817  * Function         BTM_BleSecurityProcedureIsRunning
818  *
819  * Description      This function indicates if LE security procedure is
820  *                  currently running with the peer.
821  *
822  * Returns          bool true if security procedure is running, false otherwise.
823  *
824  ******************************************************************************/
825 bool BTM_BleSecurityProcedureIsRunning(const RawAddress& bd_addr);
826 
827 /*******************************************************************************
828  *
829  * Function         BTM_BleGetSupportedKeySize
830  *
831  * Description      This function gets the maximum encryption key size in bytes
832  *                  the local device can suport.
833  *                  record.
834  *
835  * Returns          the key size or 0 if the size can't be retrieved.
836  *
837  ******************************************************************************/
838 uint8_t BTM_BleGetSupportedKeySize(const RawAddress& bd_addr);
839 
840 void BTM_LE_PF_local_name(tBTM_BLE_SCAN_COND_OP action,
841                           tBTM_BLE_PF_FILT_INDEX filt_index,
842                           std::vector<uint8_t> name, tBTM_BLE_PF_CFG_CBACK cb);
843 
844 void BTM_LE_PF_srvc_data(tBTM_BLE_SCAN_COND_OP action,
845                          tBTM_BLE_PF_FILT_INDEX filt_index);
846 
847 void BTM_LE_PF_manu_data(tBTM_BLE_SCAN_COND_OP action,
848                          tBTM_BLE_PF_FILT_INDEX filt_index, uint16_t company_id,
849                          uint16_t company_id_mask, std::vector<uint8_t> data,
850                          std::vector<uint8_t> data_mask,
851                          tBTM_BLE_PF_CFG_CBACK cb);
852 
853 void BTM_LE_PF_srvc_data_pattern(tBTM_BLE_SCAN_COND_OP action,
854                                  tBTM_BLE_PF_FILT_INDEX filt_index,
855                                  std::vector<uint8_t> data,
856                                  std::vector<uint8_t> data_mask,
857                                  tBTM_BLE_PF_CFG_CBACK cb);
858 
859 void BTM_LE_PF_addr_filter(tBTM_BLE_SCAN_COND_OP action,
860                            tBTM_BLE_PF_FILT_INDEX filt_index, tBLE_BD_ADDR addr,
861                            tBTM_BLE_PF_CFG_CBACK cb);
862 
863 void BTM_LE_PF_uuid_filter(tBTM_BLE_SCAN_COND_OP action,
864                            tBTM_BLE_PF_FILT_INDEX filt_index,
865                            tBTM_BLE_PF_COND_TYPE filter_type,
866                            const bluetooth::Uuid& uuid,
867                            tBTM_BLE_PF_LOGIC_TYPE cond_logic,
868                            const bluetooth::Uuid& uuid_mask,
869                            tBTM_BLE_PF_CFG_CBACK cb);
870 
871 void BTM_LE_PF_set(tBTM_BLE_PF_FILT_INDEX filt_index,
872                    std::vector<ApcfCommand> commands, tBTM_BLE_PF_CFG_CBACK cb);
873 void BTM_LE_PF_clear(tBTM_BLE_PF_FILT_INDEX filt_index,
874                      tBTM_BLE_PF_CFG_CBACK cb);
875 
876 /*******************************************************************************
877  *
878  * Function         BTM_BleAdvFilterParamSetup
879  *
880  * Description      This function is called to setup the adv data payload filter
881  *                  condition.
882  *
883  ******************************************************************************/
884 void BTM_BleAdvFilterParamSetup(
885     int action, tBTM_BLE_PF_FILT_INDEX filt_index,
886     std::unique_ptr<btgatt_filt_param_setup_t> p_filt_params,
887     tBTM_BLE_PF_PARAM_CB cb);
888 
889 /*******************************************************************************
890  *
891  * Function         BTM_BleUpdateAdvFilterPolicy
892  *
893  * Description      This function update the filter policy of advertiser.
894  *
895  * Parameter        adv_policy: advertising filter policy
896  *
897  * Return           void
898  ******************************************************************************/
899 void BTM_BleUpdateAdvFilterPolicy(tBTM_BLE_AFP adv_policy);
900 
901 /*******************************************************************************
902  *
903  * Function         BTM_BleEnableDisableFilterFeature
904  *
905  * Description      Enable or disable the APCF feature
906  *
907  * Parameters       enable - true - enables APCF, false - disables APCF
908  *
909  ******************************************************************************/
910 void BTM_BleEnableDisableFilterFeature(uint8_t enable,
911                                        tBTM_BLE_PF_STATUS_CBACK p_stat_cback);
912 
913 /*******************************************************************************
914  *
915  * Function          BTM_BleMaxMultiAdvInstanceCount
916  *
917  * Description      Returns the maximum number of multi adv instances supported
918  *                  by the controller.
919  *
920  * Returns          Max multi adv instance count
921  *
922  ******************************************************************************/
923 uint8_t BTM_BleMaxMultiAdvInstanceCount();
924 
925 /*******************************************************************************
926  *
927  * Function         BTM_DeviceReset
928  *
929  * Description      This function is called to reset the controller.  The
930  *                  Callback function if provided is called when startup of the
931  *                  device has completed.
932  *
933  * Returns          void
934  *
935  ******************************************************************************/
936 void BTM_DeviceReset(tBTM_CMPL_CB* p_cb);
937 
938 /*******************************************************************************
939  *
940  * Function         BTM_IsDeviceUp
941  *
942  * Description      This function is called to check if the device is up.
943  *
944  * Returns          true if device is up, else false
945  *
946  ******************************************************************************/
947 bool BTM_IsDeviceUp(void);
948 
949 /*******************************************************************************
950  *
951  * Function         BTM_SetLocalDeviceName
952  *
953  * Description      This function is called to set the local device name.
954  *
955  * Returns          BTM_CMD_STARTED if successful, otherwise an error
956  *
957  ******************************************************************************/
958 tBTM_STATUS BTM_SetLocalDeviceName(char* p_name);
959 
960 /*******************************************************************************
961  *
962  * Function         BTM_SetDeviceClass
963  *
964  * Description      This function is called to set the local device class
965  *
966  * Returns          BTM_SUCCESS if successful, otherwise an error
967  *
968  ******************************************************************************/
969 tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class);
970 
971 /*******************************************************************************
972  *
973  * Function         BTM_ReadLocalDeviceName
974  *
975  * Description      This function is called to read the local device name.
976  *
977  * Returns          status of the operation
978  *                  If success, BTM_SUCCESS is returned and p_name points stored
979  *                              local device name
980  *                  If BTM doesn't store local device name, BTM_NO_RESOURCES is
981  *                              is returned and p_name is set to NULL
982  *
983  ******************************************************************************/
984 tBTM_STATUS BTM_ReadLocalDeviceName(char** p_name);
985 
986 /*******************************************************************************
987  *
988  * Function         BTM_ReadLocalDeviceNameFromController
989  *
990  * Description      Get local device name from controller. Do not use cached
991  *                  name (used to get chip-id prior to btm reset complete).
992  *
993  * Returns          BTM_CMD_STARTED if successful, otherwise an error
994  *
995  ******************************************************************************/
996 tBTM_STATUS BTM_ReadLocalDeviceNameFromController(
997     tBTM_CMPL_CB* p_rln_cmpl_cback);
998 
999 /*******************************************************************************
1000  *
1001  * Function         BTM_ReadDeviceClass
1002  *
1003  * Description      This function is called to read the local device class
1004  *
1005  * Returns          pointer to the device class
1006  *
1007  ******************************************************************************/
1008 uint8_t* BTM_ReadDeviceClass(void);
1009 
1010 /*******************************************************************************
1011  *
1012  * Function         BTM_RegisterForDeviceStatusNotif
1013  *
1014  * Description      This function is called to register for device status
1015  *                  change notifications.
1016  *
1017  * Returns          pointer to previous caller's callback function or NULL if
1018  *                  first registration.
1019  *
1020  ******************************************************************************/
1021 tBTM_DEV_STATUS_CB* BTM_RegisterForDeviceStatusNotif(tBTM_DEV_STATUS_CB* p_cb);
1022 
1023 /*******************************************************************************
1024  *
1025  * Function         BTM_RegisterForVSEvents
1026  *
1027  * Description      This function is called to register/deregister for vendor
1028  *                  specific HCI events.
1029  *
1030  *                  If is_register=true, then the function will be registered;
1031  *                  otherwise the function will be deregistered.
1032  *
1033  * Returns          BTM_SUCCESS if successful,
1034  *                  BTM_BUSY if maximum number of callbacks have already been
1035  *                           registered.
1036  *
1037  ******************************************************************************/
1038 tBTM_STATUS BTM_RegisterForVSEvents(tBTM_VS_EVT_CB* p_cb, bool is_register);
1039 
1040 /*******************************************************************************
1041  *
1042  * Function         BTM_VendorSpecificCommand
1043  *
1044  * Description      Send a vendor specific HCI command to the controller.
1045  *
1046  ******************************************************************************/
1047 void BTM_VendorSpecificCommand(uint16_t opcode, uint8_t param_len,
1048                                uint8_t* p_param_buf, tBTM_VSC_CMPL_CB* p_cb);
1049 
1050 /*******************************************************************************
1051  *
1052  * Function         BTM_AllocateSCN
1053  *
1054  * Description      Look through the Server Channel Numbers for a free one to be
1055  *                  used with an RFCOMM connection.
1056  *
1057  * Returns          Allocated SCN number or 0 if none.
1058  *
1059  ******************************************************************************/
1060 uint8_t BTM_AllocateSCN(void);
1061 
1062 /*******************************************************************************
1063  *
1064  * Function         BTM_TryAllocateSCN
1065  *
1066  * Description      Try to allocate a fixed server channel
1067  *
1068  * Returns          Returns true if server channel was available
1069  *
1070  ******************************************************************************/
1071 bool BTM_TryAllocateSCN(uint8_t scn);
1072 
1073 /*******************************************************************************
1074  *
1075  * Function         BTM_FreeSCN
1076  *
1077  * Description      Free the specified SCN.
1078  *
1079  * Returns          true if successful, false if SCN is not in use or invalid
1080  *
1081  ******************************************************************************/
1082 bool BTM_FreeSCN(uint8_t scn);
1083 
1084 /*******************************************************************************
1085  *
1086  * Function         BTM_SetTraceLevel
1087  *
1088  * Description      This function sets the trace level for BTM.  If called with
1089  *                  a value of 0xFF, it simply returns the current trace level.
1090  *
1091  * Returns          The new or current trace level
1092  *
1093  ******************************************************************************/
1094 uint8_t BTM_SetTraceLevel(uint8_t new_level);
1095 
1096 /*******************************************************************************
1097  *
1098  * Function         BTM_WritePageTimeout
1099  *
1100  * Description      Send HCI Wite Page Timeout.
1101  *
1102  ******************************************************************************/
1103 void BTM_WritePageTimeout(uint16_t timeout);
1104 
1105 /*******************************************************************************
1106  *
1107  * Function         BTM_WriteVoiceSettings
1108  *
1109  * Description      Send HCI Write Voice Settings command.
1110  *                  See hcidefs.h for settings bitmask values.
1111  *
1112  ******************************************************************************/
1113 void BTM_WriteVoiceSettings(uint16_t settings);
1114 
1115 /*******************************************************************************
1116  *
1117  * Function         BTM_EnableTestMode
1118  *
1119  * Description      Send HCI the enable device under test command.
1120  *
1121  *                  Note: Controller can only be taken out of this mode by
1122  *                      resetting the controller.
1123  *
1124  * Returns
1125  *      BTM_SUCCESS         Command sent.
1126  *      BTM_NO_RESOURCES    If out of resources to send the command.
1127  *
1128  *
1129  ******************************************************************************/
1130 tBTM_STATUS BTM_EnableTestMode(void);
1131 
1132 /*******************************************************************************
1133  *
1134  * Function         BTM_ReadRemoteVersion
1135  *
1136  * Description      This function is called to read a remote device's version
1137  *
1138  * Returns          BTM_SUCCESS if successful, otherwise an error
1139  *
1140  ******************************************************************************/
1141 tBTM_STATUS BTM_ReadRemoteVersion(const RawAddress& addr, uint8_t* lmp_version,
1142                                   uint16_t* manufacturer,
1143                                   uint16_t* lmp_sub_version);
1144 
1145 /*******************************************************************************
1146  *
1147  * Function         BTM_ReadRemoteFeatures
1148  *
1149  * Description      This function is called to read a remote device's
1150  *                  supported features mask (features mask located at page 0)
1151  *
1152  *                  Note: The size of device features mask page is
1153  *                  BTM_FEATURE_BYTES_PER_PAGE bytes.
1154  *
1155  * Returns          pointer to the remote supported features mask
1156  *
1157  ******************************************************************************/
1158 uint8_t* BTM_ReadRemoteFeatures(const RawAddress& addr);
1159 
1160 /*****************************************************************************
1161  *  ACL CHANNEL MANAGEMENT FUNCTIONS
1162  ****************************************************************************/
1163 /*******************************************************************************
1164  *
1165  * Function         BTM_SetLinkPolicy
1166  *
1167  * Description      Create and send HCI "Write Policy Set" command
1168  *
1169  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
1170  *
1171  ******************************************************************************/
1172 tBTM_STATUS BTM_SetLinkPolicy(const RawAddress& remote_bda, uint16_t* settings);
1173 
1174 /*******************************************************************************
1175  *
1176  * Function         BTM_SetDefaultLinkPolicy
1177  *
1178  * Description      Set the default value for HCI "Write Policy Set" command
1179  *                  to use when an ACL link is created.
1180  *
1181  * Returns          void
1182  *
1183  ******************************************************************************/
1184 void BTM_SetDefaultLinkPolicy(uint16_t settings);
1185 
1186 /*******************************************************************************
1187  *
1188  * Function         BTM_SetDefaultLinkSuperTout
1189  *
1190  * Description      Set the default value for HCI "Write Link Supervision
1191  *                  Timeout" command to use when an ACL link is created.
1192  *
1193  * Returns          void
1194  *
1195  ******************************************************************************/
1196 void BTM_SetDefaultLinkSuperTout(uint16_t timeout);
1197 
1198 /*******************************************************************************
1199  *
1200  * Function         BTM_SetLinkSuperTout
1201  *
1202  * Description      Create and send HCI "Write Link Supervision Timeout" command
1203  *
1204  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
1205  *
1206  ******************************************************************************/
1207 tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda,
1208                                  uint16_t timeout);
1209 /*******************************************************************************
1210  *
1211  * Function         BTM_GetLinkSuperTout
1212  *
1213  * Description      Read the link supervision timeout value of the connection
1214  *
1215  * Returns          status of the operation
1216  *
1217  ******************************************************************************/
1218 tBTM_STATUS BTM_GetLinkSuperTout(const RawAddress& remote_bda,
1219                                  uint16_t* p_timeout);
1220 
1221 /*******************************************************************************
1222  *
1223  * Function         BTM_IsAclConnectionUp
1224  *
1225  * Description      This function is called to check if an ACL connection exists
1226  *                  to a specific remote BD Address.
1227  *
1228  * Returns          true if connection is up, else false.
1229  *
1230  ******************************************************************************/
1231 bool BTM_IsAclConnectionUp(const RawAddress& remote_bda,
1232                            tBT_TRANSPORT transport);
1233 
1234 /*******************************************************************************
1235  *
1236  * Function         BTM_GetRole
1237  *
1238  * Description      This function is called to get the role of the local device
1239  *                  for the ACL connection with the specified remote device
1240  *
1241  * Returns          BTM_SUCCESS if connection exists.
1242  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1243  *
1244  ******************************************************************************/
1245 tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role);
1246 
1247 /*******************************************************************************
1248  *
1249  * Function         BTM_SwitchRole
1250  *
1251  * Description      This function is called to switch role between master and
1252  *                  slave.  If role is already set it will do nothing.  If the
1253  *                  command was initiated, the callback function is called upon
1254  *                  completion.
1255  *
1256  * Returns          BTM_SUCCESS if already in specified role.
1257  *                  BTM_CMD_STARTED if command issued to controller.
1258  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
1259  *                                   the command
1260  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1261  *                  BTM_MODE_UNSUPPORTED if the local device does not support
1262  *                                       role switching
1263  *
1264  ******************************************************************************/
1265 tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role,
1266                            tBTM_CMPL_CB* p_cb);
1267 
1268 /*******************************************************************************
1269  *
1270  * Function         BTM_ReadRSSI
1271  *
1272  * Description      This function is called to read the link policy settings.
1273  *                  The address of link policy results are returned in the
1274  *                  callback. (tBTM_RSSI_RESULT)
1275  *
1276  * Returns          BTM_CMD_STARTED if command issued to controller.
1277  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
1278  *                                   the command
1279  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1280  *                  BTM_BUSY if command is already in progress
1281  *
1282  ******************************************************************************/
1283 tBTM_STATUS BTM_ReadRSSI(const RawAddress& remote_bda, tBTM_CMPL_CB* p_cb);
1284 
1285 /*******************************************************************************
1286  *
1287  * Function         BTM_ReadFailedContactCounter
1288  *
1289  * Description      This function is called to read the failed contact counter.
1290  *                  The result is returned in the callback.
1291  *                  (tBTM_FAILED_CONTACT_COUNTER_RESULT)
1292  *
1293  * Returns          BTM_CMD_STARTED if command issued to controller.
1294  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
1295  *                                   the command
1296  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1297  *                  BTM_BUSY if command is already in progress
1298  *
1299  ******************************************************************************/
1300 tBTM_STATUS BTM_ReadFailedContactCounter(const RawAddress& remote_bda,
1301                                          tBTM_CMPL_CB* p_cb);
1302 
1303 /*******************************************************************************
1304  *
1305  * Function         BTM_ReadAutomaticFlushTimeout
1306  *
1307  * Description      This function is called to read the automatic flush timeout.
1308  *                  The result is returned in the callback.
1309  *                  (tBTM_AUTOMATIC_FLUSH_TIMEOUT_RESULT)
1310  *
1311  * Returns          BTM_CMD_STARTED if command issued to controller.
1312  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
1313  *                                   the command
1314  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1315  *                  BTM_BUSY if command is already in progress
1316  *
1317  ******************************************************************************/
1318 tBTM_STATUS BTM_ReadAutomaticFlushTimeout(const RawAddress& remote_bda,
1319                                           tBTM_CMPL_CB* p_cb);
1320 
1321 /*******************************************************************************
1322  *
1323  * Function         BTM_ReadTxPower
1324  *
1325  * Description      This function is called to read the current connection
1326  *                  TX power of the connection. The TX power level results
1327  *                  are returned in the callback.
1328  *                  (tBTM_RSSI_RESULT)
1329  *
1330  * Returns          BTM_CMD_STARTED if command issued to controller.
1331  *                  BTM_NO_RESOURCES if memory couldn't be allocated to issue
1332  *                                   the command
1333  *                  BTM_UNKNOWN_ADDR if no active link with bd addr specified
1334  *                  BTM_BUSY if command is already in progress
1335  *
1336  ******************************************************************************/
1337 tBTM_STATUS BTM_ReadTxPower(const RawAddress& remote_bda,
1338                             tBT_TRANSPORT transport, tBTM_CMPL_CB* p_cb);
1339 
1340 /*******************************************************************************
1341  *
1342  * Function         BTM_RegBusyLevelNotif
1343  *
1344  * Description      This function is called to register a callback to receive
1345  *                  busy level change events.
1346  *
1347  * Returns          BTM_SUCCESS if successfully registered, otherwise error
1348  *
1349  ******************************************************************************/
1350 tBTM_STATUS BTM_RegBusyLevelNotif(tBTM_BL_CHANGE_CB* p_cb, uint8_t* p_level,
1351                                   tBTM_BL_EVENT_MASK evt_mask);
1352 
1353 /*******************************************************************************
1354  *
1355  * Function         BTM_GetNumAclLinks
1356  *
1357  * Description      This function is called to count the number of
1358  *                  ACL links that are active.
1359  *
1360  * Returns          uint16_t Number of active ACL links
1361  *
1362  ******************************************************************************/
1363 uint16_t BTM_GetNumAclLinks(void);
1364 
1365 /*****************************************************************************
1366  *  (e)SCO CHANNEL MANAGEMENT FUNCTIONS
1367  ****************************************************************************/
1368 /*******************************************************************************
1369  *
1370  * Function         BTM_CreateSco
1371  *
1372  * Description      This function is called to create an SCO connection. If the
1373  *                  "is_orig" flag is true, the connection will be originated,
1374  *                  otherwise BTM will wait for the other side to connect.
1375  *
1376  * Returns          BTM_UNKNOWN_ADDR if the ACL connection is not up
1377  *                  BTM_BUSY         if another SCO being set up to
1378  *                                   the same BD address
1379  *                  BTM_NO_RESOURCES if the max SCO limit has been reached
1380  *                  BTM_CMD_STARTED  if the connection establishment is started.
1381  *                                   In this case, "*p_sco_inx" is filled in
1382  *                                   with the sco index used for the connection.
1383  *
1384  ******************************************************************************/
1385 tBTM_STATUS BTM_CreateSco(const RawAddress* remote_bda, bool is_orig,
1386                           uint16_t pkt_types, uint16_t* p_sco_inx,
1387                           tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb);
1388 
1389 /*******************************************************************************
1390  *
1391  * Function         BTM_RemoveSco
1392  *
1393  * Description      This function is called to remove a specific SCO connection.
1394  *
1395  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
1396  *
1397  ******************************************************************************/
1398 tBTM_STATUS BTM_RemoveSco(uint16_t sco_inx);
1399 
1400 /*******************************************************************************
1401  *
1402  * Function         BTM_ReadScoBdAddr
1403  *
1404  * Description      This function is read the remote BD Address for a specific
1405  *                  SCO connection,
1406  *
1407  * Returns          pointer to BD address or NULL if not known
1408  *
1409  ******************************************************************************/
1410 const RawAddress* BTM_ReadScoBdAddr(uint16_t sco_inx);
1411 
1412 /*******************************************************************************
1413  *
1414  * Function         BTM_SetEScoMode
1415  *
1416  * Description      This function sets up the negotiated parameters for SCO or
1417  *                  eSCO, and sets as the default mode used for calls to
1418  *                  BTM_CreateSco.  It can be called only when there are no
1419  *                  active (e)SCO links.
1420  *
1421  * Returns          BTM_SUCCESS if the successful.
1422  *                  BTM_BUSY if there are one or more active (e)SCO links.
1423  *
1424  ******************************************************************************/
1425 tBTM_STATUS BTM_SetEScoMode(enh_esco_params_t* p_parms);
1426 
1427 /*******************************************************************************
1428  *
1429  * Function         BTM_RegForEScoEvts
1430  *
1431  * Description      This function registers a SCO event callback with the
1432  *                  specified instance.  It should be used to received
1433  *                  connection indication events and change of link parameter
1434  *                  events.
1435  *
1436  * Returns          BTM_SUCCESS if the successful.
1437  *                  BTM_ILLEGAL_VALUE if there is an illegal sco_inx
1438  *
1439  ******************************************************************************/
1440 tBTM_STATUS BTM_RegForEScoEvts(uint16_t sco_inx, tBTM_ESCO_CBACK* p_esco_cback);
1441 
1442 /*******************************************************************************
1443  *
1444  * Function         BTM_ChangeEScoLinkParms
1445  *
1446  * Description      This function requests renegotiation of the parameters on
1447  *                  the current eSCO Link.  If any of the changes are accepted
1448  *                  by the controllers, the BTM_ESCO_CHG_EVT event is sent in
1449  *                  the tBTM_ESCO_CBACK function with the current settings of
1450  *                  the link. The callback is registered through the call to
1451  *                  BTM_SetEScoMode.
1452  *
1453  *
1454  * Returns          BTM_CMD_STARTED if command is successfully initiated.
1455  *                  BTM_ILLEGAL_VALUE if no connection for specified sco_inx.
1456  *                  BTM_NO_RESOURCES - not enough resources to initiate command.
1457  *                  BTM_MODE_UNSUPPORTED if local controller does not support
1458  *                      1.2 specification.
1459  *
1460  ******************************************************************************/
1461 tBTM_STATUS BTM_ChangeEScoLinkParms(uint16_t sco_inx,
1462                                     tBTM_CHG_ESCO_PARAMS* p_parms);
1463 
1464 /*******************************************************************************
1465  *
1466  * Function         BTM_EScoConnRsp
1467  *
1468  * Description      This function is called upon receipt of an (e)SCO connection
1469  *                  request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject
1470  *                  the request. Parameters used to negotiate eSCO links.
1471  *                  If p_parms is NULL, then values set through BTM_SetEScoMode
1472  *                  are used.
1473  *                  If the link type of the incoming request is SCO, then only
1474  *                  the tx_bw, max_latency, content format, and packet_types are
1475  *                  valid.  The hci_status parameter should be
1476  *                  ([0x0] to accept, [0x0d..0x0f] to reject)
1477  *
1478  *
1479  * Returns          void
1480  *
1481  ******************************************************************************/
1482 void BTM_EScoConnRsp(uint16_t sco_inx, uint8_t hci_status,
1483                      enh_esco_params_t* p_parms);
1484 
1485 /*******************************************************************************
1486  *
1487  * Function         BTM_GetNumScoLinks
1488  *
1489  * Description      This function returns the number of active SCO links.
1490  *
1491  * Returns          uint8_t
1492  *
1493  ******************************************************************************/
1494 uint8_t BTM_GetNumScoLinks(void);
1495 
1496 /*****************************************************************************
1497  *  SECURITY MANAGEMENT FUNCTIONS
1498  ****************************************************************************/
1499 /*******************************************************************************
1500  *
1501  * Function         BTM_SecRegister
1502  *
1503  * Description      Application manager calls this function to register for
1504  *                  security services.  There can be one and only one
1505  *                  application saving link keys.  BTM allows only first
1506  *                  registration.
1507  *
1508  * Returns          true if registered OK, else false
1509  *
1510  ******************************************************************************/
1511 bool BTM_SecRegister(const tBTM_APPL_INFO* p_cb_info);
1512 
1513 /*******************************************************************************
1514  *
1515  * Function         BTM_SecAddRmtNameNotifyCallback
1516  *
1517  * Description      Profiles can register to be notified when name of the
1518  *                  remote device is resolved (up to
1519  *                  BTM_SEC_MAX_RMT_NAME_CALLBACKS).
1520  *
1521  * Returns          true if registered OK, else false
1522  *
1523  ******************************************************************************/
1524 bool BTM_SecAddRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback);
1525 
1526 /*******************************************************************************
1527  *
1528  * Function         BTM_SecDeleteRmtNameNotifyCallback
1529  *
1530  * Description      A profile can deregister notification when a new Link Key
1531  *                  is generated per connection.
1532  *
1533  * Returns          true if OK, else false
1534  *
1535  ******************************************************************************/
1536 bool BTM_SecDeleteRmtNameNotifyCallback(tBTM_RMT_NAME_CALLBACK* p_callback);
1537 
1538 /*******************************************************************************
1539  *
1540  * Function         BTM_GetSecurityFlags
1541  *
1542  * Description      Get security flags for the device
1543  *
1544  * Returns          bool    true or false is device found
1545  *
1546  ******************************************************************************/
1547 bool BTM_GetSecurityFlags(const RawAddress& bd_addr, uint8_t* p_sec_flags);
1548 
1549 /*******************************************************************************
1550  *
1551  * Function         BTM_GetSecurityFlagsByTransport
1552  *
1553  * Description      Get security flags for the device on a particular transport
1554  *
1555  * Parameters      bd_addr: BD address of remote device
1556  *                  p_sec_flags : Out parameter to be filled with security
1557  *                                flags for the connection
1558  *                  transport :  Physical transport of the connection
1559  *                               (BR/EDR or LE)
1560  *
1561  * Returns          bool    true or false is device found
1562  *
1563  ******************************************************************************/
1564 bool BTM_GetSecurityFlagsByTransport(const RawAddress& bd_addr,
1565                                      uint8_t* p_sec_flags,
1566                                      tBT_TRANSPORT transport);
1567 
1568 /*******************************************************************************
1569  *
1570  * Function         BTM_ReadTrustedMask
1571  *
1572  * Description      Get trusted mask for the device
1573  *
1574  * Returns          NULL, if the device record is not found.
1575  *                  otherwise, the trusted mask
1576  *
1577  ******************************************************************************/
1578 uint32_t* BTM_ReadTrustedMask(const RawAddress& bd_addr);
1579 
1580 /*******************************************************************************
1581  *
1582  * Function         BTM_SetPinType
1583  *
1584  * Description      Set PIN type for the device.
1585  *
1586  * Returns          void
1587  *
1588  ******************************************************************************/
1589 void BTM_SetPinType(uint8_t pin_type, PIN_CODE pin_code, uint8_t pin_code_len);
1590 
1591 /*******************************************************************************
1592  *
1593  * Function         BTM_SetPairableMode
1594  *
1595  * Description      Enable or disable pairing
1596  *
1597  * Parameters       allow_pairing - (true or false) whether or not the device
1598  *                      allows pairing.
1599  *                  connect_only_paired - (true or false) whether or not to
1600  *                      only allow paired devices to connect.
1601  *
1602  * Returns          void
1603  *
1604  ******************************************************************************/
1605 void BTM_SetPairableMode(bool allow_pairing, bool connect_only_paired);
1606 
1607 /*******************************************************************************
1608  *
1609  * Function         BTM_SetSecurityLevel
1610  *
1611  * Description      Register service security level with Security Manager.  Each
1612  *                  service must register its requirements regardless of the
1613  *                  security level that is used.  This API is called once for
1614  *                  originators and again for acceptors of connections.
1615  *
1616  * Returns          true if registered OK, else false
1617  *
1618  ******************************************************************************/
1619 bool BTM_SetSecurityLevel(bool is_originator, const char* p_name,
1620                           uint8_t service_id, uint16_t sec_level, uint16_t psm,
1621                           uint32_t mx_proto_id, uint32_t mx_chan_id);
1622 
1623 /*******************************************************************************
1624  *
1625  * Function         BTM_SetOutService
1626  *
1627  * Description      This function is called to set the service for
1628  *                  outgoing connection.
1629  *
1630  * Returns          void
1631  *
1632  ******************************************************************************/
1633 void BTM_SetOutService(const RawAddress& bd_addr, uint8_t service_id,
1634                        uint32_t mx_chan_id);
1635 
1636 /*******************************************************************************
1637  *
1638  * Function         BTM_SecClrService
1639  *
1640  * Description      Removes specified service record(s) from the security
1641  *                  database. All service records with the specified name are
1642  *                  removed. Typically used only by devices with limited RAM
1643  *                  so that it can reuse an old security service record.
1644  *
1645  * Returns          Number of records that were freed.
1646  *
1647  ******************************************************************************/
1648 uint8_t BTM_SecClrService(uint8_t service_id);
1649 
1650 /*******************************************************************************
1651  *
1652  * Function         BTM_SecAddDevice
1653  *
1654  * Description      Add/modify device.  This function will be normally called
1655  *                  during host startup to restore all required information
1656  *                  stored in the NVRAM.
1657  *                  dev_class, bd_name, link_key, and features are NULL if
1658  *                  unknown
1659  *
1660  * Returns          true if added OK, else false
1661  *
1662  ******************************************************************************/
1663 bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
1664                       BD_NAME bd_name, uint8_t* features,
1665                       uint32_t trusted_mask[], LinkKey* link_key,
1666                       uint8_t key_type, tBTM_IO_CAP io_cap, uint8_t pin_length);
1667 
1668 /** Free resources associated with the device associated with |bd_addr| address.
1669  *
1670  * *** WARNING ***
1671  * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function
1672  * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is
1673  * no longer valid!
1674  * *** WARNING ***
1675  *
1676  * Returns true if removed OK, false if not found or ACL link is active.
1677  */
1678 bool BTM_SecDeleteDevice(const RawAddress& bd_addr);
1679 
1680 /*******************************************************************************
1681  *
1682  * Function         BTM_SecClearSecurityFlags
1683  *
1684  * Description      Reset the security flags (mark as not-paired) for a given
1685  *                  remove device.
1686  *
1687  ******************************************************************************/
1688 void BTM_SecClearSecurityFlags(const RawAddress& bd_addr);
1689 
1690 /*******************************************************************************
1691  *
1692  * Function         BTM_SecGetDeviceLinkKeyType
1693  *
1694  * Description      This function is called to obtain link key type for the
1695  *                  device.
1696  *                  it returns BTM_SUCCESS if link key is available, or
1697  *                  BTM_UNKNOWN_ADDR if Security Manager does not know about
1698  *                  the device or device record does not contain link key info
1699  *
1700  * Returns          BTM_LKEY_TYPE_IGNORE if link key is unknown, link type
1701  *                  otherwise.
1702  *
1703  ******************************************************************************/
1704 tBTM_LINK_KEY_TYPE BTM_SecGetDeviceLinkKeyType(const RawAddress& bd_addr);
1705 
1706 /*******************************************************************************
1707  *
1708  * Function         BTM_PINCodeReply
1709  *
1710  * Description      This function is called after Security Manager submitted
1711  *                  PIN code request to the UI.
1712  *
1713  * Parameters:      bd_addr      - Address of the device for which PIN was
1714  *                                 requested
1715  *                  res          - result of the operation BTM_SUCCESS if
1716  *                                 success
1717  *                  pin_len      - length in bytes of the PIN Code
1718  *                  p_pin        - pointer to array with the PIN Code
1719  *                  trusted_mask - bitwise OR of trusted services
1720  *                                 (array of uint32_t)
1721  *
1722  * Returns          void
1723  *
1724  ******************************************************************************/
1725 void BTM_PINCodeReply(const RawAddress& bd_addr, uint8_t res, uint8_t pin_len,
1726                       uint8_t* p_pin, uint32_t trusted_mask[]);
1727 
1728 /*******************************************************************************
1729  *
1730  * Function         BTM_SecBond
1731  *
1732  * Description      Perform bonding by designated transport
1733  *
1734  * Parameters:      bd_addr      - Address of the device to bond
1735  *                  addr_type    - address type for LE transport
1736  *                  pin_len      - length in bytes of the PIN Code
1737  *                  p_pin        - pointer to array with the PIN Code
1738  *                  trusted_mask - bitwise OR of trusted services
1739  *                                 (array of uint32_t)
1740  *                  transport :  Physical transport to use for bonding
1741  *                               (BR/EDR or LE)
1742  *
1743  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
1744  *
1745  ******************************************************************************/
1746 tBTM_STATUS BTM_SecBond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
1747                         tBT_TRANSPORT transport, int device_type);
1748 
1749 /*******************************************************************************
1750  *
1751  * Function         BTM_SecBondCancel
1752  *
1753  * Description      This function is called to cancel ongoing bonding process
1754  *                  with peer device.
1755  *
1756  * Returns          BTM_CMD_STARTED if successfully initiated, otherwise error
1757  *
1758  ******************************************************************************/
1759 tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr);
1760 
1761 /*******************************************************************************
1762  *
1763  * Function         BTM_SetEncryption
1764  *
1765  * Description      This function is called to ensure that connection is
1766  *                  encrypted.  Should be called only on an open connection.
1767  *                  Typically only needed for connections that first want to
1768  *                  bring up unencrypted links, then later encrypt them.
1769  *
1770  * Parameters:      bd_addr       - Address of the peer device
1771  *                  transport     - Link transport
1772  *                  p_callback    - Pointer to callback function called if
1773  *                                  this function returns PENDING after required
1774  *                                  procedures are completed.  Can be set to
1775  *                                  NULL if status is not desired.
1776  *                  p_ref_data    - pointer to any data the caller wishes to
1777  *                                  receive in the callback function upon
1778  *                                  completion.
1779  *                                  can be set to NULL if not used.
1780  *                  sec_act       - LE security action, unused for BR/EDR
1781  *
1782  * Returns          BTM_SUCCESS   - already encrypted
1783  *                  BTM_PENDING   - command will be returned in the callback
1784  *                  BTM_WRONG_MODE- connection not up.
1785  *                  BTM_BUSY      - security procedures are currently active
1786  *                  BTM_MODE_UNSUPPORTED - if security manager not linked in.
1787  *
1788  ******************************************************************************/
1789 tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
1790                               tBT_TRANSPORT transport,
1791                               tBTM_SEC_CBACK* p_callback, void* p_ref_data,
1792                               tBTM_BLE_SEC_ACT sec_act);
1793 
1794 /*******************************************************************************
1795  *
1796  * Function         BTM_ConfirmReqReply
1797  *
1798  * Description      This function is called to confirm the numeric value for
1799  *                  Simple Pairing in response to BTM_SP_CFM_REQ_EVT
1800  *
1801  * Parameters:      res           - result of the operation BTM_SUCCESS if
1802  *                                  success
1803  *                  bd_addr       - Address of the peer device
1804  *
1805  ******************************************************************************/
1806 void BTM_ConfirmReqReply(tBTM_STATUS res, const RawAddress& bd_addr);
1807 
1808 /*******************************************************************************
1809  *
1810  * Function         BTM_PasskeyReqReply
1811  *
1812  * Description      This function is called to provide the passkey for
1813  *                  Simple Pairing in response to BTM_SP_KEY_REQ_EVT
1814  *
1815  * Parameters:      res           - result of the operation BTM_SUCCESS if
1816  *                                  success
1817  *                  bd_addr       - Address of the peer device
1818  *                  passkey       - numeric value in the range of
1819  *                                  0 - 999999(0xF423F).
1820  *
1821  ******************************************************************************/
1822 void BTM_PasskeyReqReply(tBTM_STATUS res, const RawAddress& bd_addr,
1823                          uint32_t passkey);
1824 
1825 /*******************************************************************************
1826  *
1827  * Function         BTM_SendKeypressNotif
1828  *
1829  * Description      This function is used during the passkey entry model
1830  *                  by a device with KeyboardOnly IO capabilities
1831  *                  (very likely to be a HID Device).
1832  *                  It is called by a HID Device to inform the remote device
1833  *                  when a key has been entered or erased.
1834  *
1835  * Parameters:      bd_addr - Address of the peer device
1836  *                  type - notification type
1837  *
1838  ******************************************************************************/
1839 void BTM_SendKeypressNotif(const RawAddress& bd_addr, tBTM_SP_KEY_TYPE type);
1840 
1841 /*******************************************************************************
1842  *
1843  * Function         BTM_IoCapRsp
1844  *
1845  * Description      This function is called in response to BTM_SP_IO_REQ_EVT
1846  *                  When the event data io_req.oob_data is set to
1847  *                  BTM_OOB_UNKNOWN by the tBTM_SP_CALLBACK implementation, this
1848  *                  function is called to provide the actual response
1849  *
1850  * Parameters:      bd_addr - Address of the peer device
1851  *                  io_cap  - The IO capability of local device.
1852  *                  oob     - BTM_OOB_NONE or BTM_OOB_PRESENT.
1853  *                  auth_req- MITM protection required or not.
1854  *
1855  ******************************************************************************/
1856 void BTM_IoCapRsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap,
1857                   tBTM_OOB_DATA oob, tBTM_AUTH_REQ auth_req);
1858 
1859 /*******************************************************************************
1860  *
1861  * Function         BTM_ReadLocalOobData
1862  *
1863  * Description      This function is called to read the local OOB data from
1864  *                  LM
1865  *
1866  ******************************************************************************/
1867 void BTM_ReadLocalOobData(void);
1868 
1869 /*******************************************************************************
1870  *
1871  * Function         BTM_RemoteOobDataReply
1872  *
1873  * Description      This function is called to provide the remote OOB data for
1874  *                  Simple Pairing in response to BTM_SP_RMT_OOB_EVT
1875  *
1876  * Parameters:      bd_addr     - Address of the peer device
1877  *                  c           - simple pairing Hash C.
1878  *                  r           - simple pairing Randomizer  C.
1879  *
1880  ******************************************************************************/
1881 void BTM_RemoteOobDataReply(tBTM_STATUS res, const RawAddress& bd_addr,
1882                             const Octet16& c, const Octet16& r);
1883 
1884 /*******************************************************************************
1885  *
1886  * Function         BTM_BothEndsSupportSecureConnections
1887  *
1888  * Description      This function is called to check if both the local device
1889  *                  and the peer device specified by bd_addr support BR/EDR
1890  *                  Secure Connections.
1891  *
1892  * Parameters:      bd_addr - address of the peer
1893  *
1894  * Returns          true if BR/EDR Secure Connections are supported by both
1895  *                  local and the remote device.
1896  *                  else false.
1897  *
1898  ******************************************************************************/
1899 bool BTM_BothEndsSupportSecureConnections(const RawAddress& bd_addr);
1900 
1901 /*******************************************************************************
1902  *
1903  * Function         BTM_PeerSupportsSecureConnections
1904  *
1905  * Description      This function is called to check if the peer supports
1906  *                  BR/EDR Secure Connections.
1907  *
1908  * Parameters:      bd_addr - address of the peer
1909  *
1910  * Returns          true if BR/EDR Secure Connections are supported by the peer,
1911  *                  else false.
1912  *
1913  ******************************************************************************/
1914 bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr);
1915 
1916 /*******************************************************************************
1917  *
1918  * Function         BTM_SecReadDevName
1919  *
1920  * Description      Looks for the device name in the security database for the
1921  *                  specified BD address.
1922  *
1923  * Returns          Pointer to the name or NULL
1924  *
1925  ******************************************************************************/
1926 char* BTM_SecReadDevName(const RawAddress& bd_addr);
1927 
1928 /*****************************************************************************
1929  *  POWER MANAGEMENT FUNCTIONS
1930  ****************************************************************************/
1931 /*******************************************************************************
1932  *
1933  * Function         BTM_PmRegister
1934  *
1935  * Description      register or deregister with power manager
1936  *
1937  * Returns          BTM_SUCCESS if successful,
1938  *                  BTM_NO_RESOURCES if no room to hold registration
1939  *                  BTM_ILLEGAL_VALUE
1940  *
1941  ******************************************************************************/
1942 tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id,
1943                            tBTM_PM_STATUS_CBACK* p_cb);
1944 
1945 /*******************************************************************************
1946  *
1947  * Function         BTM_SetPowerMode
1948  *
1949  * Description      store the mode in control block or
1950  *                  alter ACL connection behavior.
1951  *
1952  * Returns          BTM_SUCCESS if successful,
1953  *                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
1954  *
1955  ******************************************************************************/
1956 tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda,
1957                              const tBTM_PM_PWR_MD* p_mode);
1958 
1959 /*******************************************************************************
1960  *
1961  * Function         BTM_ReadPowerMode
1962  *
1963  * Description      This returns the current mode for a specific
1964  *                  ACL connection.
1965  *
1966  * Input Param      remote_bda - device address of desired ACL connection
1967  *
1968  * Output Param     p_mode - address where the current mode is copied into.
1969  *                          BTM_ACL_MODE_NORMAL
1970  *                          BTM_ACL_MODE_HOLD
1971  *                          BTM_ACL_MODE_SNIFF
1972  *                          BTM_ACL_MODE_PARK
1973  *                          (valid only if return code is BTM_SUCCESS)
1974  *
1975  * Returns          BTM_SUCCESS if successful,
1976  *                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
1977  *
1978  ******************************************************************************/
1979 tBTM_STATUS BTM_ReadPowerMode(const RawAddress& remote_bda,
1980                               tBTM_PM_MODE* p_mode);
1981 
1982 /*******************************************************************************
1983  *
1984  * Function         BTM_SetSsrParams
1985  *
1986  * Description      This sends the given SSR parameters for the given ACL
1987  *                  connection if it is in ACTIVE mode.
1988  *
1989  * Input Param      remote_bda - device address of desired ACL connection
1990  *                  max_lat    - maximum latency (in 0.625ms)(0-0xFFFE)
1991  *                  min_rmt_to - minimum remote timeout
1992  *                  min_loc_to - minimum local timeout
1993  *
1994  *
1995  * Returns          BTM_SUCCESS if the HCI command is issued successful,
1996  *                  BTM_UNKNOWN_ADDR if bd addr is not active or bad
1997  *                  BTM_CMD_STORED if the command is stored
1998  *
1999  ******************************************************************************/
2000 tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat,
2001                              uint16_t min_rmt_to, uint16_t min_loc_to);
2002 
2003 /*******************************************************************************
2004  *
2005  * Function         BTM_GetHCIConnHandle
2006  *
2007  * Description      This function is called to get the handle for an ACL
2008  *                  connection to a specific remote BD Address.
2009  *
2010  * Returns          the handle of the connection, or 0xFFFF if none.
2011  *
2012  ******************************************************************************/
2013 uint16_t BTM_GetHCIConnHandle(const RawAddress& remote_bda,
2014                               tBT_TRANSPORT transport);
2015 
2016 /*******************************************************************************
2017  *
2018  * Function         BTM_DeleteStoredLinkKey
2019  *
2020  * Description      This function is called to delete link key for the specified
2021  *                  device addresses from the NVRAM storage attached to the
2022  *                  Bluetooth controller.
2023  *
2024  * Parameters:      bd_addr      - Addresses of the devices
2025  *                  p_cb         - Call back function to be called to return
2026  *                                 the results
2027  *
2028  ******************************************************************************/
2029 tBTM_STATUS BTM_DeleteStoredLinkKey(const RawAddress* bd_addr,
2030                                     tBTM_CMPL_CB* p_cb);
2031 
2032 tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void);
2033 
2034 /**
2035  *
2036  * BLE API
2037  */
2038 
2039 /**
2040  * This function is called to set scan parameters. |cb| is called with operation
2041  * status
2042  **/
2043 void BTM_BleSetScanParams(uint32_t scan_interval, uint32_t scan_window,
2044                           tBLE_SCAN_MODE scan_type,
2045                           base::Callback<void(uint8_t)> cb);
2046 
2047 /*******************************************************************************
2048  *
2049  * Function         BTM_BleGetVendorCapabilities
2050  *
2051  * Description      This function reads local LE features
2052  *
2053  * Parameters       p_cmn_vsc_cb : Locala LE capability structure
2054  *
2055  * Returns          void
2056  *
2057  ******************************************************************************/
2058 void BTM_BleGetVendorCapabilities(tBTM_BLE_VSC_CB* p_cmn_vsc_cb);
2059 
2060 /*******************************************************************************
2061  *
2062  * Function         BTM_BleSetStorageConfig
2063  *
2064  * Description      This function is called to setup storage configuration and
2065  *                  setup callbacks.
2066  *
2067  * Parameters       uint8_t batch_scan_full_max -Batch scan full maximum
2068  *                  uint8_t batch_scan_trunc_max - Batch scan truncated value
2069  *maximum uint8_t batch_scan_notify_threshold - Threshold value cb - Setup
2070  *callback tBTM_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback -Threshold callback void
2071  **p_ref - Reference value
2072  *
2073  *
2074  ******************************************************************************/
2075 void BTM_BleSetStorageConfig(uint8_t batch_scan_full_max,
2076                              uint8_t batch_scan_trunc_max,
2077                              uint8_t batch_scan_notify_threshold,
2078                              base::Callback<void(uint8_t /* status */)> cb,
2079                              tBTM_BLE_SCAN_THRESHOLD_CBACK* p_thres_cback,
2080                              tBTM_BLE_REF_VALUE ref_value);
2081 
2082 /* This function is called to enable batch scan */
2083 void BTM_BleEnableBatchScan(tBTM_BLE_BATCH_SCAN_MODE scan_mode,
2084                             uint32_t scan_interval, uint32_t scan_window,
2085                             tBTM_BLE_DISCARD_RULE discard_rule,
2086                             tBLE_ADDR_TYPE addr_type,
2087                             base::Callback<void(uint8_t /* status */)> cb);
2088 
2089 /* This function is called to disable batch scanning */
2090 void BTM_BleDisableBatchScan(base::Callback<void(uint8_t /* status */)> cb);
2091 
2092 /* This function is called to read batch scan reports */
2093 void BTM_BleReadScanReports(tBLE_SCAN_MODE scan_mode,
2094                             tBTM_BLE_SCAN_REP_CBACK cb);
2095 
2096 /* This function is called to setup the callback for tracking */
2097 void BTM_BleTrackAdvertiser(tBTM_BLE_TRACK_ADV_CBACK* p_track_cback,
2098                             tBTM_BLE_REF_VALUE ref_value);
2099 
2100 /******************************************************************************
2101  *
2102  * Function         BTM_BleReadControllerFeatures
2103  *
2104  * Description      Reads BLE specific controller features
2105  *
2106  * Parameters:      tBTM_BLE_CTRL_FEATURES_CBACK : Callback to notify when
2107  *                  features are read
2108  *
2109  * Returns          void
2110  *
2111  ******************************************************************************/
2112 void BTM_BleReadControllerFeatures(tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback);
2113 
2114 /*******************************************************************************
2115  *
2116  * Function         BTM__BLEReadDiscoverability
2117  *
2118  * Description      This function is called to read the current LE
2119  *                  discoverability mode of the device.
2120  *
2121  * Returns          BTM_BLE_NON_DISCOVERABLE ,BTM_BLE_LIMITED_DISCOVERABLE or
2122  *                     BTM_BLE_GENRAL_DISCOVERABLE
2123  *
2124  ******************************************************************************/
2125 uint16_t BTM_BleReadDiscoverability();
2126 
2127 /*******************************************************************************
2128  *
2129  * Function         BTM__BLEReadConnectability
2130  *
2131  * Description      This function is called to read the current LE
2132  *                  connectibility mode of the device.
2133  *
2134  * Returns          BTM_BLE_NON_CONNECTABLE or BTM_BLE_CONNECTABLE
2135  *
2136  ******************************************************************************/
2137 uint16_t BTM_BleReadConnectability();
2138 
2139 /*******************************************************************************
2140  *
2141  * Function         BTM_BleConfigPrivacy
2142  *
2143  * Description      This function is called to enable or disable the privacy in
2144  *                  the local device.
2145  *
2146  * Parameters       enable: true to enable it; false to disable it.
2147  *
2148  * Returns          bool    privacy mode set success; otherwise failed.
2149  *
2150  ******************************************************************************/
2151 bool BTM_BleConfigPrivacy(bool enable);
2152 
2153 /*******************************************************************************
2154  *
2155  * Function         BTM_BleLocalPrivacyEnabled
2156  *
2157  * Description        Checks if local device supports private address
2158  *
2159  * Returns          Return true if local privacy is enabled else false
2160  *
2161  ******************************************************************************/
2162 bool BTM_BleLocalPrivacyEnabled(void);
2163 
2164 /**
2165  * This functions are called to configure the adv data payload filter condition
2166  */
2167 /*******************************************************************************
2168  *
2169  * Function         BTM_BleGetEnergyInfo
2170  *
2171  * Description      This function obtains the energy info
2172  *
2173  * Parameters       p_ener_cback - Callback pointer
2174  *
2175  * Returns          status
2176  *
2177  ******************************************************************************/
2178 tBTM_STATUS BTM_BleGetEnergyInfo(tBTM_BLE_ENERGY_INFO_CBACK* p_ener_cback);
2179 
2180 /**
2181  * Send remote name request to GD shim Name module
2182  */
2183 void SendRemoteNameRequest(const RawAddress& raw_address);
2184 
2185 tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr, uint16_t psm,
2186                                       bool is_originator, uint32_t mx_proto_id,
2187                                       uint32_t mx_chan_id,
2188                                       tBTM_SEC_CBACK* p_callback,
2189                                       void* p_ref_data);
2190 
2191 }  // namespace shim
2192 }  // namespace bluetooth
2193