1 // Copyright (C) 2014 The Android Open Source Project 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 #ifndef __BTC_BLE_STORAGE_H__ 15 #define __BTC_BLE_STORAGE_H__ 16 #include "stack/bt_types.h" 17 #include "common/bt_target.h" 18 #include "esp_gap_ble_api.h" 19 20 #if (SMP_INCLUDED == TRUE) 21 #define BTC_LE_LOCAL_KEY_IR (1<<0) 22 #define BTC_LE_LOCAL_KEY_IRK (1<<1) 23 #define BTC_LE_LOCAL_KEY_DHK (1<<2) 24 #define BTC_LE_LOCAL_KEY_ER (1<<3) 25 26 #define BTC_BLE_STORAGE_DEV_TYPE_STR "DevType" 27 #define BTC_BLE_STORAGE_ADDR_TYPE_STR "AddrType" 28 #define BTC_BLE_STORAGE_LINK_KEY_STR "LinkKey" 29 #define BTC_BLE_STORAGE_LE_KEY_PENC_STR "LE_KEY_PENC" 30 #define BTC_BLE_STORAGE_LE_KEY_PID_STR "LE_KEY_PID" 31 #define BTC_BLE_STORAGE_LE_KEY_PCSRK_STR "LE_KEY_PCSRK" 32 #define BTC_BLE_STORAGE_LE_KEY_LENC_STR "LE_KEY_LENC" 33 #define BTC_BLE_STORAGE_LE_KEY_LID_STR "LE_KEY_LID" 34 #define BTC_BLE_STORAGE_LE_KEY_LCSRK_STR "LE_KEY_LCSRK" 35 #define BTC_BLE_STORAGE_LE_AUTH_MODE_STR "AuthMode" 36 37 #define BTC_BLE_STORAGE_LOCAL_ADAPTER_STR "Adapter" 38 #define BTC_BLE_STORAGE_LE_LOCAL_KEY_IR_STR "LE_LOCAL_KEY_IR" 39 #define BTC_BLE_STORAGE_LE_LOCAL_KEY_IRK_STR "LE_LOCAL_KEY_IRK" 40 #define BTC_BLE_STORAGE_LE_LOCAL_KEY_DHK_STR "LE_LOCAL_KEY_DHK" 41 #define BTC_BLE_STORAGE_LE_LOCAL_KEY_ER_STR "LE_LOCAL_KEY_ER" 42 43 /************************************************************************************ 44 ** Local type definitions 45 ************************************************************************************/ 46 typedef struct 47 { 48 BT_OCTET16 sp_c; 49 BT_OCTET16 sp_r; 50 BD_ADDR oob_bdaddr; /* peer bdaddr*/ 51 } btc_dm_oob_cb_t; 52 53 54 void btc_storage_save(void); 55 56 bt_status_t btc_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr, char *key, uint8_t key_type, uint8_t key_length); 57 58 bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, char *key_value, int key_length); 59 60 bt_status_t btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr); 61 62 bool btc_storage_compare_address_key_value(bt_bdaddr_t *remote_bd_addr, uint8_t key_type, void *key_value, int key_length); 63 64 bt_status_t btc_storage_add_ble_local_key(char *key, uint8_t key_type, uint8_t key_length); 65 66 bt_status_t btc_storage_remove_ble_local_keys(void); 67 68 bt_status_t btc_storage_get_ble_local_key(uint8_t key_type, char *key_value, int key_len); 69 70 bt_status_t btc_storage_set_ble_dev_auth_mode(bt_bdaddr_t *remote_bd_addr, uint8_t auth_mode, bool flush); 71 72 bt_status_t btc_storage_get_ble_dev_auth_mode(bt_bdaddr_t *remote_bd_addr, int* auth_mode); 73 74 bt_status_t btc_storage_remove_ble_dev_auth_mode(bt_bdaddr_t *remote_bd_addr, bool flush); 75 76 bt_status_t btc_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr, int *addr_type); 77 78 bt_status_t btc_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr, uint8_t addr_type, bool flush); 79 80 bt_status_t btc_storage_remove_remote_addr_type(bt_bdaddr_t *remote_bd_addr, bool flush); 81 82 bt_status_t btc_storage_set_ble_dev_type(bt_bdaddr_t *bd_addr, bool flush); 83 84 bt_status_t btc_storage_remove_ble_dev_type(bt_bdaddr_t *remote_bd_addr, bool flush); 85 86 bt_status_t btc_storage_load_bonded_ble_devices(void); 87 88 bt_status_t btc_storage_get_bonded_ble_devices_list(esp_ble_bond_dev_t *bond_dev, int dev_num); 89 90 int btc_storage_get_num_ble_bond_devices(void); 91 #endif ///SMP_INCLUDED == TRUE 92 93 #define BTC_BLE_STORAGE_GATT_CL_SUPP_FEAT_STR "GATT_CL_SUPP_FEAT" 94 #define BTC_BLE_STORAGE_GATT_DB_HASH_STR "GATT_DB_HASH" 95 96 bt_status_t btc_storage_get_gatt_cl_supp_feat(bt_bdaddr_t *remote_bd_addr, uint8_t *value, int len); 97 98 bt_status_t btc_storage_set_gatt_cl_supp_feat(bt_bdaddr_t *remote_bd_addr, uint8_t *value, int len); 99 100 bt_status_t btc_storage_remove_gatt_cl_supp_feat(bt_bdaddr_t *remote_bd_addr); 101 102 bt_status_t btc_storage_get_gatt_db_hash(bt_bdaddr_t *remote_bd_addr, uint8_t *value, int len); 103 104 bt_status_t btc_storage_set_gatt_db_hash(bt_bdaddr_t *remote_bd_addr, uint8_t *value, int len); 105 106 bt_status_t btc_storage_remove_gatt_db_hash(bt_bdaddr_t *remote_bd_addr); 107 #endif ///__BTC_BLE_STORAGE_H__ 108