1 /* 2 * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __BTC_STORAGE_H__ 8 #define __BTC_STORAGE_H__ 9 10 #include <stdint.h> 11 #include "common/bt_defs.h" 12 #include "stack/bt_types.h" 13 #include "esp_gap_bt_api.h" 14 15 16 #define BTC_STORAGE_DEV_CLASS_STR "DevClass" 17 #define BTC_STORAGE_LINK_KEY_STR "LinkKey" /* same as the ble */ 18 #define BTC_STORAGE_LINK_KEY_TYPE_STR "LinkKeyType" 19 #define BTC_STORAGE_PIN_LENGTH_STR "PinLength" 20 #define BTC_STORAGE_SC_SUPPORT "SCSupport" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /******************************************************************************* 27 ** 28 ** Function btc_storage_add_bonded_device 29 ** 30 ** Description BTC storage API - Adds the newly bonded device to NVRAM 31 ** along with the link-key, Key type and Pin key length 32 ** 33 ** Returns BT_STATUS_SUCCESS if the store was successful, 34 ** BT_STATUS_FAIL otherwise 35 ** 36 *******************************************************************************/ 37 bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr, 38 LINK_KEY link_key, 39 uint8_t key_type, 40 uint8_t pin_length, 41 BOOLEAN sc_support); 42 43 /******************************************************************************* 44 ** 45 ** Function btc_storage_remove_bonded_device 46 ** 47 ** Description BTC storage API - Deletes the bonded device from NVRAM 48 ** 49 ** Returns BT_STATUS_SUCCESS if the deletion was successful, 50 ** BT_STATUS_FAIL otherwise 51 ** 52 *******************************************************************************/ 53 bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr); 54 55 /******************************************************************************* 56 ** 57 ** Function btc_storage_load_bonded_devices 58 ** 59 ** Description BTC storage API - Loads all the bonded devices from NVRAM 60 ** and adds to the BTA. 61 ** Additionally, this API also invokes the adaper_properties_cb 62 ** and remote_device_properties_cb for each of the bonded devices. 63 ** 64 ** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 65 ** 66 *******************************************************************************/ 67 bt_status_t btc_storage_load_bonded_devices(void); 68 69 /******************************************************************************* 70 ** 71 ** Function btc_storage_get_num_bt_bond_devices 72 ** 73 ** Description BTC storage API - get the num of the bonded device from NVRAM 74 ** 75 ** Returns the num of the bonded device 76 ** 77 *******************************************************************************/ 78 int btc_storage_get_num_bt_bond_devices(void); 79 80 /******************************************************************************* 81 ** 82 ** Function btc_storage_get_bonded_bt_devices_list 83 ** 84 ** Description BTC storage API - get the list of the bonded device from NVRAM 85 ** 86 ** Returns BT_STATUS_SUCCESS if get the list successful, 87 ** BT_STATUS_FAIL otherwise 88 ** 89 *******************************************************************************/ 90 bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *dev_num); 91 92 /******************************************************************************* 93 ** 94 ** Function btc_storage_get_num_all_bond_devices 95 ** 96 ** Description BTC storage API - get all the num of the bonded device from NVRAM 97 ** 98 ** Returns the num of the bonded device 99 ** 100 *******************************************************************************/ 101 int btc_storage_get_num_all_bond_devices(void); 102 103 /******************************************************************************* 104 ** 105 ** Function btc_storage_update_active_device 106 ** 107 ** Description BTC storage API - Once an ACL link is established and remote 108 ** bd_addr is already stored in NVRAM, update the config and update 109 ** the remote device to be the newest active device. The updates will 110 ** not be stored into NVRAM immediately. 111 ** 112 ** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 113 ** 114 *******************************************************************************/ 115 bool btc_storage_update_active_device(bt_bdaddr_t *remote_bd_addr); 116 117 #if (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE) 118 /******************************************************************************* 119 * 120 * Function btc_storage_add_hid_device_info 121 * 122 * Description BTC storage API - Adds the hid information of bonded hid 123 * devices-to NVRAM 124 * 125 * Returns BT_STATUS_SUCCESS if the store was successful, 126 * BT_STATUS_FAIL otherwise 127 * 128 ******************************************************************************/ 129 130 bt_status_t btc_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, uint16_t attr_mask, uint8_t sub_class, 131 uint8_t app_id, uint16_t vendor_id, uint16_t product_id, uint16_t version, 132 uint8_t ctry_code, uint16_t ssr_max_latency, uint16_t ssr_min_tout, 133 uint16_t dl_len, uint8_t *dsc_list); 134 135 /******************************************************************************* 136 * 137 * Function btc_storage_load_bonded_hid_info 138 * 139 * Description BTIF storage API - Loads hid info for all the bonded devices 140 * from NVRAM and adds those devices to the BTA_HH. 141 * 142 * Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 143 * 144 ******************************************************************************/ 145 bt_status_t btc_storage_load_bonded_hid_info(void); 146 147 /******************************************************************************* 148 * 149 * Function btc_storage_remove_hid_info 150 * 151 * Description BTC storage API - Deletes the bonded hid device info from 152 * NVRAM 153 * 154 * Returns BT_STATUS_SUCCESS if the deletion was successful, 155 * BT_STATUS_FAIL otherwise 156 * 157 ******************************************************************************/ 158 bt_status_t btc_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr); 159 #endif // (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE) 160 161 #if (defined BTC_HD_INCLUDED && BTC_HD_INCLUDED == TRUE) 162 /******************************************************************************* 163 * Function btc_storage_load_hidd 164 * 165 * Description Loads hidd bonded device and "plugs" it into hidd 166 * 167 * Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise 168 * 169 ******************************************************************************/ 170 bt_status_t btc_storage_load_hidd(void); 171 172 /******************************************************************************* 173 * 174 * Function btc_storage_set_hidd 175 * 176 * Description Stores hidd bonded device info in nvram. 177 * 178 * Returns BT_STATUS_SUCCESS 179 * 180 ******************************************************************************/ 181 bt_status_t btc_storage_set_hidd(bt_bdaddr_t *remote_bd_addr); 182 183 /******************************************************************************* 184 * 185 * Function btc_storage_remove_hidd 186 * 187 * Description Removes hidd bonded device info from nvram 188 * 189 * Returns BT_STATUS_SUCCESS 190 * 191 ******************************************************************************/ 192 bt_status_t btc_storage_remove_hidd(bt_bdaddr_t *remote_bd_addr); 193 #endif //(defined BTC_HD_INCLUDED && BTC_HD_INCLUDED == TRUE) 194 #endif /* BTC_STORAGE_H */ 195 #ifdef __cplusplus 196 } 197 #endif 198