1 /*
2  * Copyright 2023 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 <cstdint>
20 #include <memory>
21 
22 #include "bta/include/bta_sec_api.h"
23 #include "stack/include/bt_hdr.h"
24 #include "stack/include/btm_sec_api_types.h"
25 
26 typedef struct {
27   RawAddress bd_addr;
28   bool accept;
29   uint8_t pin_len;
30   uint8_t p_pin[PIN_CODE_LEN];
31 } tBTA_DM_API_PIN_REPLY;
32 
33 typedef struct {
34   BT_HDR_RIGID hdr;
35   RawAddress bd_addr;
36   tBTM_IO_CAP io_cap;
37   tBTM_OOB_DATA oob_data;
38   tBTM_AUTH_REQ auth_req;
39 } tBTA_DM_CI_IO_REQ;
40 
41 typedef struct {
42   RawAddress bd_addr;
43   Octet16 c;
44   Octet16 r;
45   bool accept;
46 } tBTA_DM_CI_RMT_OOB;
47 
48 typedef struct {
49   tBTA_DM_SEC_CBACK* p_sec_cback;
50   tBTA_DM_SEC_CBACK* p_sec_sirk_cback;
51 /* Storage for pin code request parameters */
52   RawAddress pin_bd_addr;
53   DEV_CLASS pin_dev_class;
54   tBTA_DM_SEC_EVT pin_evt;
55   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of local device */
56   tBTM_IO_CAP rmt_io_caps;    /* IO Capabilities of remote device */
57   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
58   tBTM_AUTH_REQ rmt_auth_req;
59   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
60                        show this number to UI */
61   bool just_works;  /* true, if "Just Works" association model */
62 } tBTA_DM_SEC_CB;
63 
64 extern tBTA_DM_SEC_CB bta_dm_sec_cb;
65 
66 void bta_dm_sec_enable(tBTA_DM_SEC_CBACK* p_sec_cback);
67 void btm_sec_on_hw_on();
68 
69 void bta_dm_add_ble_device(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
70                            tBT_DEVICE_TYPE dev_type);
71 void bta_dm_add_blekey(const RawAddress& bd_addr, tBTA_LE_KEY_VALUE blekey,
72                        tBTM_LE_KEY_TYPE key_type);
73 void bta_dm_ble_config_local_privacy(bool privacy_enable);
74 void bta_dm_ble_confirm_reply(const RawAddress& bd_addr, bool accept);
75 void bta_dm_ble_passkey_reply(const RawAddress& bd_addr, bool accept,
76                               uint32_t passkey);
77 void bta_dm_ble_sirk_confirm_device_reply(const RawAddress& bd_addr,
78                                           bool accept);
79 void bta_dm_ble_sirk_sec_cb_register(tBTA_DM_SEC_CBACK* p_cback);
80 void bta_dm_bond(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type,
81                  tBT_TRANSPORT transport, tBT_DEVICE_TYPE device_type);
82 void bta_dm_bond_cancel(const RawAddress& bd_addr);
83 void bta_dm_remove_device(const RawAddress& bd_addr);
84 void bta_dm_ci_rmt_oob_act(std::unique_ptr<tBTA_DM_CI_RMT_OOB> msg);
85 void bta_dm_confirm(const RawAddress& bd_addr, bool accept);
86 void bta_dm_consolidate(const RawAddress& identity_addr, const RawAddress& rpa);
87 void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback);
88 void bta_dm_encrypt_cback(const RawAddress* bd_addr, tBT_TRANSPORT transport,
89                           void* /* p_ref_data */, tBTM_STATUS result);
90 void bta_dm_pin_reply(std::unique_ptr<tBTA_DM_API_PIN_REPLY> msg);
91 void bta_dm_set_encryption(const RawAddress& bd_addr, tBT_TRANSPORT transport,
92                            tBTA_DM_ENCRYPT_CBACK* p_callback,
93                            tBTM_BLE_SEC_ACT sec_act);
94 void btm_dm_sec_init();
95