1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 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 16 #ifndef __WM_BT_STORAGE_H__ 17 #define __WM_BT_STORAGE_H__ 18 19 #include <string.h> 20 #include <stdio.h> 21 #include <stdbool.h> 22 #include <assert.h> 23 24 #define BTIF_CFG_TYPE_INVALID 0 25 #define BTIF_CFG_TYPE_STR 1 26 #define BTIF_CFG_TYPE_INT (1 << 1) 27 #define BTIF_CFG_TYPE_BIN (1 << 2) 28 #define BTIF_CFG_TYPE_VOLATILE (1 << 15) 29 30 typedef enum { 31 NV_LOCAL = 0, 32 NV_LOCAL_ADAPTER, 33 NV_LOCAL_ADAPTER_ADDRESS, 34 NV_LOCAL_ADAPTER_NAME, 35 NV_LOCAL_ADAPTER_CLASS, 36 NV_LOCAL_ADAPTER_IO_CAP, 37 NV_LOCAL_ADAPTER_DISCOVERABLE, 38 NV_LOCAL_ADAPTER_CONNECTABLE, 39 NV_LOCAL_ADAPTER_DISCOVERY_TIMEOUT, 40 NV_LOCAL_ADAPTER_AUTH_REQ, 41 NV_LOCAL_ADAPTER_MODE, 42 NV_LOCAL_ADAPTER_BLE_AUTH_REQ, 43 NV_LOCAL_ADAPTER_BLE_IR, 44 NV_LOCAL_ADAPTER_BLE_IRK, 45 NV_LOCAL_ADAPTER_BLE_DHK, 46 NV_LOCAL_ADAPTER_BLE_ER, 47 NV_LOCAL_ADAPTER_MAX_TAG, 48 NV_REMOTE, 49 NV_REMOTE_ADDRESS, 50 NV_REMOTE_NAME, 51 NV_REMOTE_CLASS, 52 NV_REMOTE_SERVICE, 53 NV_REMOTE_LINK_KEY, 54 NV_REMOTE_KEY_TYPE, 55 NV_REMOTE_IO_CAP, 56 NV_REMOTE_PIN_LENGTH, 57 NV_REMOTE_DEVICE_TYPE, 58 NV_REMOTE_BLE_ADDRESS_TYPE, 59 NV_REMOTE_BLE_KEY_PENC, 60 NV_REMOTE_BLE_KEY_LENC, 61 NV_REMOTE_BLE_KEY_PID, 62 NV_REMOTE_BLE_KEY_LID, 63 NV_REMOTE_BLE_KEY_PCSRK, 64 NV_REMOTE_BLE_KEY_LCSRK, 65 NV_REMOTE_RECONNECT, 66 NV_REMOTE_MANU, 67 NV_REMOTE_LMPVER, 68 NV_REMOTE_LMPSUBVER, 69 NV_REMOTE_MAX_TAG 70 } nv_tag_t; 71 72 /* Adapter valid bit mask */ 73 #define NV_LOCAL_TAG 0 74 #define NV_REMOTE_TAG 1 75 76 #define ADAPTER_BD_ADDRESS_VALID_BIT (1<<0) 77 #define ADAPTER_NAME_VALID_BIT (1<<1) 78 #define ADAPTER_CLASS_VALID_BIT (1<<2) 79 #define ADAPTER_IOCAP_VALID_BIT (1<<3) 80 #define ADAPTER_DISCOVER_VALID_BIT (1<<4) 81 #define ADAPTER_CONNECT_VALID_BIT (1<<5) 82 #define ADAPTER_BT_AUTH_REQ_VALID_BIT (1<<6) 83 #define ADAPTER_BLE_WORK_MODE_VALID_BIT (1<<7) 84 #define ADAPTER_BLE_AUTH_REQ_VALID_BIT (1<<8) 85 #define ADAPTER_BLE_IR_VALID_BIT (1<<9) 86 #define ADAPTER_BLE_IRK_VALID_BIT (1<<10) 87 #define ADAPTER_BLE_DHK_VALID_BIT (1<<11) 88 #define ADAPTER_BLE_ER_VALID_BIT (1<<12) 89 90 /* BT device valid bit mask */ 91 #define DEVICE_BD_ADDRESS_VALID_BIT (1<<0) 92 #define DEVICE_NAME_VALID_BIT (1<<1) 93 #define DEVICE_CLASS_VALID_BIT (1<<2) 94 #define DEVICE_SERVICE_VALID_BIT (1<<3) 95 #define DEVICE_LINK_KEY_VALID_BIT (1<<4) 96 #define DEVICE_KEY_TYPE_VALID_BIT (1<<5) 97 #define DEVICE_IOCAP_VALID_BIT (1<<6) 98 #define DEVICE_PIN_LENGTH_VALID_BIT (1<<7) 99 #define DEVICE_TYPE_VALID_BIT (1<<8) 100 #define DEVICE_RECONNECT_VALID_BIT (1<<9) 101 #define DEVICE_BLE_ADDR_TYPE_VALID_BIT (1<<10) 102 #define DEVICE_BLE_KEY_PENC_VALID_BIT (1<<11) 103 #define DEVICE_BLE_KEY_LENC_VALID_BIT (1<<12) 104 #define DEVICE_BLE_KEY_PID_VALID_BIT (1<<13) 105 #define DEVICE_BLE_KEY_LID_VALID_BIT (1<<14) 106 #define DEVICE_BLE_KEY_PCSRK_VALID_BIT (1<<15) 107 #define DEVICE_BLE_KEY_LCSRK_VALID_BIT (1<<16) 108 #define DEVICE_RMT_MANU_VALID_BIT (1<<17) 109 #define DEVICE_RMT_LMP_VERSION_VALID_BIT (1<<18) 110 #define DEVICE_RMT_LMP_SUB_VERSION_VALID_BIT (1<<19) 111 112 extern int btif_wm_config_get_remote_device(int index, void *ptr, int from_flash); 113 114 extern int btif_config_get_int(const char *section, const char *key, const char *name, int *value); 115 extern int btif_config_set_int(const char *section, const char *key, const char *name, int value); 116 extern int btif_config_get_str(const char *section, const char *key, const char *name, char *value, 117 int *bytes); 118 extern int btif_config_set_str(const char *section, const char *key, const char *name, 119 const char *value); 120 121 extern int btif_config_get(const char *section, const char *key, const char *name, char *value, 122 int *bytes, int *type); 123 extern int btif_config_set(const char *section, const char *key, const char *name, 124 const char *value, int bytes, int type); 125 126 extern int btif_config_remove(const char *section, const char *key, const char *name); 127 extern int btif_config_filter_remove(const char *section, const char *filter[], int filter_count, 128 int max_allowed); 129 extern int btif_config_exist(const char *section, const char *key, const char *name); 130 extern int btif_config_flush(int force); 131 extern int btif_config_save(void); 132 extern void btif_clear_remote_all(void); 133 extern int btif_wm_config_update_remote_device(const char *key); 134 135 extern int btif_config_store_peer_sec(int idx, void *addr, uint8_t *payload, int length); 136 extern int btif_config_store_our_sec(int idx, void *addr, uint8_t *payload, int length); 137 extern int btif_config_store_cccd(int idx, void *addr, int count, void *payload, int length); 138 extern int btif_config_delete_our_sec(int idx); 139 extern int btif_config_delete_peer_sec(int idx); 140 extern int btif_config_delete_cccd(int idx); 141 extern int btif_config_get_sec_index(void *addr, uint8_t *found); 142 extern int btif_config_store_our_sec(int idx, void *addr, uint8_t *payload, int length); 143 extern uint32_t btif_config_get_sec_cccd_item(int idx, void *addr, void *our_sec, int our_sec_size, 144 void *peer_sec, int peer_sec_size, void *cccd_info, int cccd_info_size); 145 extern int btif_config_store_key_map(const uint8_t *map_info, int length, bool force_flush); 146 extern int btif_config_load_key_map(uint8_t *map_info, int length); 147 extern int btif_config_delete_all(void); 148 149 #endif