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