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