1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __BTC_DM_H__
16 #define __BTC_DM_H__
17 
18 #include "btc/btc_task.h"
19 #include "esp_bt_defs.h"
20 #include "bta/bta_api.h"
21 
22 typedef enum {
23     BTC_DM_SEC_ACT
24 } btc_dm_sec_act_t;
25 
26 /* btc_dm_args_t */
27 typedef union {
28     //BTC_DM_SEC_ACT
29     tBTA_DM_SEC sec;
30 } btc_dm_sec_args_t;
31 
32 typedef struct
33 {
34     bool                   is_penc_key_rcvd;
35     tBTM_LE_PENC_KEYS         penc_key;       /* received peer encryption key */
36     bool                   is_pcsrk_key_rcvd;
37     tBTM_LE_PCSRK_KEYS        pcsrk_key;       /* received peer device SRK */
38     bool                   is_pid_key_rcvd;
39     tBTM_LE_PID_KEYS          pid_key;        /* peer device ID key */
40     bool                   is_lenc_key_rcvd;
41     tBTM_LE_LENC_KEYS         lenc_key;       /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
42     bool                   is_lcsrk_key_rcvd;
43     tBTM_LE_LCSRK_KEYS        lcsrk_key;      /* local device CSRK = d1(ER,DIV,1)*/
44     bool                   is_lidk_key_rcvd;   /* local identity key received */
45 } btc_dm_ble_cb_t;
46 
47 typedef struct
48 {
49     bt_bdaddr_t            static_bdaddr;
50     BD_ADDR                bd_addr;
51     btc_dm_ble_cb_t        ble;
52 } btc_dm_pairing_cb_t;
53 
54 typedef struct
55 {
56     uint8_t                ir[BT_OCTET16_LEN];
57     uint8_t                irk[BT_OCTET16_LEN];
58     uint8_t                dhk[BT_OCTET16_LEN];
59 } btc_dm_local_key_id_t;
60 
61 typedef struct
62 {
63     bool                 is_er_rcvd;
64     uint8_t              er[BT_OCTET16_LEN];
65     bool                 is_id_keys_rcvd;
66     btc_dm_local_key_id_t  id_keys;  /* ID kyes */
67 } btc_dm_local_key_cb_t;
68 
69 typedef struct
70 {
71     tBTA_SERVICE_MASK btc_enabled_services;
72 #if (SMP_INCLUDED == TRUE)
73     btc_dm_pairing_cb_t pairing_cb;
74     btc_dm_local_key_cb_t ble_local_key_cb;
75 #endif
76 } btc_dm_cb_t;
77 
78 #if BTC_DYNAMIC_MEMORY == FALSE
79 extern btc_dm_cb_t btc_dm_cb;
80 #else
81 extern btc_dm_cb_t *btc_dm_cb_ptr;
82 #define btc_dm_cb (*btc_dm_cb_ptr)
83 #endif
84 
85 // void btc_dm_call_handler(btc_msg_t *msg);
86 void btc_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *data);
87 void btc_dm_sec_cb_handler(btc_msg_t *msg);
88 void btc_dm_sec_arg_deep_copy(btc_msg_t *msg, void *dst, void *src);
89 
90 bt_status_t btc_dm_enable_service(tBTA_SERVICE_ID service_id);
91 bt_status_t btc_dm_disable_service(tBTA_SERVICE_ID service_id);
92 
93 #if (SMP_INCLUDED == TRUE)
94 void btc_dm_load_ble_local_keys(void);
95 
96 void btc_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
97                                                             tBTA_BLE_LOCAL_ID_KEYS *p_id_keys);
98 #endif
99 
100 #endif /* __BTC_DM_H__ */
101