1 /******************************************************************************
2  *
3  *  Copyright 2009-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef BTIF_DM_H
20 #define BTIF_DM_H
21 
22 #include "bta/include/bta_api.h"
23 #include "bte_appl.h"
24 #include "btif_uid.h"
25 
26 /*******************************************************************************
27  *  Functions
28  ******************************************************************************/
29 void btif_dm_init(uid_set_t* set);
30 void btif_dm_cleanup(void);
31 
32 /**
33  * BTIF callback to switch context from bte to btif
34  */
35 void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data);
36 
37 /**
38  * Notify BT disable being initiated. DM may chose to abort
39  * pending commands, like pairing
40  */
41 void btif_dm_on_disable(void);
42 
43 /**
44  * Callout for handling io_capabilities request
45  */
46 void btif_dm_proc_io_req(tBTM_AUTH_REQ* p_auth_req, bool is_orig);
47 /**
48  * Callout for handling io_capabilities response
49  */
50 void btif_dm_proc_io_rsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap,
51                          tBTM_OOB_DATA oob_data, tBTM_AUTH_REQ auth_req);
52 
53 /**
54  * Out-of-band functions
55  */
56 void btif_dm_set_oob_for_io_req(tBTM_OOB_DATA* p_oob_data);
57 void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
58                                    tBTM_OOB_DATA* p_oob_data,
59                                    tBTM_LE_AUTH_REQ* p_auth_req);
60 #ifdef BTIF_DM_OOB_TEST
61 void btif_dm_load_local_oob(void);
62 void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
63                           const Octet16& c, const Octet16& r);
64 bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c,
65                           Octet16* p_r);
66 void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport);
67 #endif /* BTIF_DM_OOB_TEST */
68 
69 /*callout for reading SMP properties from Text file*/
70 bool btif_dm_get_smp_config(tBTE_APPL_CFG* p_cfg);
71 
72 /* EIR functions */
73 void btif_dm_add_uuid_to_eir(uint16_t uuid16);
74 void btif_dm_remove_uuid_from_eir(uint16_t uuid16);
75 
76 typedef struct {
77   bool is_penc_key_rcvd;
78   tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */
79   bool is_pcsrk_key_rcvd;
80   tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */
81   bool is_pid_key_rcvd;
82   tBTM_LE_PID_KEYS pid_key; /* peer device ID key */
83   bool is_lenc_key_rcvd;
84   tBTM_LE_LENC_KEYS
85       lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
86   bool is_lcsrk_key_rcvd;
87   tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
88   bool is_lidk_key_rcvd;        /* local identity key received */
89 } btif_dm_ble_cb_t;
90 
91 #define BTIF_DM_LE_LOCAL_KEY_IR (1 << 0)
92 #define BTIF_DM_LE_LOCAL_KEY_IRK (1 << 1)
93 #define BTIF_DM_LE_LOCAL_KEY_DHK (1 << 2)
94 #define BTIF_DM_LE_LOCAL_KEY_ER (1 << 3)
95 
96 void btif_dm_load_ble_local_keys(void);
97 void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK* p_key_mask,
98                                 Octet16* p_er,
99                                 tBTA_BLE_LOCAL_ID_KEYS* p_id_keys);
100 void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr);
101 void btif_dm_remove_ble_bonding_keys(void);
102 void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ* p_ble_req, bool is_consent);
103 
104 void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
105                                           BD_NAME bd_name,
106                                           tBT_DEVICE_TYPE dev_type);
107 
108 #endif
109