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