|
39 | 39 | #include "bonding.h" |
40 | 40 | #include "bluefruit.h" |
41 | 41 |
|
| 42 | +#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS) |
| 43 | + |
42 | 44 | #if CFG_DEBUG >= 2 |
43 | | -//#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR) |
44 | | -#define printBondDir() |
| 45 | +#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR) |
45 | 46 | #else |
46 | 47 | #define printBondDir() |
47 | 48 | #endif |
48 | 49 |
|
49 | | -#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS) |
50 | | - |
51 | | - |
52 | 50 | /*------------------------------------------------------------------*/ |
53 | 51 | /* Saving Bond Data to Nffs in following layout |
54 | 52 | * - _bond_data 80 bytes |
55 | 53 | * - Name 32 bytes |
56 | 54 | * - CCCD variable |
57 | 55 | *------------------------------------------------------------------*/ |
| 56 | + |
| 57 | +/*------------------------------------------------------------------*/ |
| 58 | +/* Keys |
| 59 | + *------------------------------------------------------------------*/ |
58 | 60 | static void bond_save_keys_dfr(uint16_t conn_hdl, bond_data_t* bdata) |
59 | 61 | { |
60 | 62 | char filename[BOND_FILENAME_LEN]; |
@@ -105,6 +107,28 @@ void bond_save_keys(uint16_t conn_hdl, bond_data_t* bdata) |
105 | 107 | ada_callback(buf, bond_save_keys_dfr, conn_hdl, buf); |
106 | 108 | } |
107 | 109 |
|
| 110 | +bool bond_load_keys(uint16_t ediv, bond_data_t* bdata) |
| 111 | +{ |
| 112 | + char filename[BOND_FILENAME_LEN]; |
| 113 | + sprintf(filename, BOND_FILENAME, ediv); |
| 114 | + |
| 115 | + bool result = (Nffs.readFile(filename, bdata, sizeof(bond_data_t)) > 0); |
| 116 | + |
| 117 | + if ( result ) |
| 118 | + { |
| 119 | + LOG_LV2("BOND", "Load Keys from file %s", filename); |
| 120 | + }else |
| 121 | + { |
| 122 | + LOG_LV1("BOND", "Keys not found"); |
| 123 | + } |
| 124 | + |
| 125 | + return result; |
| 126 | +} |
| 127 | + |
| 128 | + |
| 129 | +/*------------------------------------------------------------------*/ |
| 130 | +/* CCCD |
| 131 | + *------------------------------------------------------------------*/ |
108 | 132 | static void bond_save_cccd_dfr (uint16_t conn_hdl, uint16_t ediv) |
109 | 133 | { |
110 | 134 | uint16_t len=0; |
@@ -141,23 +165,6 @@ void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv) |
141 | 165 | ada_callback(NULL, bond_save_cccd_dfr, cond_hdl, ediv); |
142 | 166 | } |
143 | 167 |
|
144 | | -bool bond_load_keys(uint16_t ediv, bond_data_t* bdata) |
145 | | -{ |
146 | | - char filename[BOND_FILENAME_LEN]; |
147 | | - sprintf(filename, BOND_FILENAME, ediv); |
148 | | - |
149 | | - bool result = (Nffs.readFile(filename, bdata, sizeof(bond_data_t)) > 0); |
150 | | - |
151 | | - if ( result ) |
152 | | - { |
153 | | - LOG_LV2("BOND", "Load Keys from file %s", filename); |
154 | | - }else |
155 | | - { |
156 | | - LOG_LV1("BOND", "Keys not found"); |
157 | | - } |
158 | | - |
159 | | - return result; |
160 | | -} |
161 | 168 |
|
162 | 169 | bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv) |
163 | 170 | { |
@@ -207,3 +214,17 @@ bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv) |
207 | 214 |
|
208 | 215 | return loaded; |
209 | 216 | } |
| 217 | + |
| 218 | +/*------------------------------------------------------------------*/ |
| 219 | +/* DELETE |
| 220 | + *------------------------------------------------------------------*/ |
| 221 | +void bond_clear(void) |
| 222 | +{ |
| 223 | + // Detele bonds dir |
| 224 | + Nffs.remove(CFG_BOND_NFFS_DIR); |
| 225 | + |
| 226 | + // Create an empty one |
| 227 | + Nffs.mkdir_p(CFG_BOND_NFFS_DIR); |
| 228 | + |
| 229 | + printBondDir(); |
| 230 | +} |
0 commit comments