Skip to content

Commit 86ea7e7

Browse files
committed
more clean up
1 parent acd4abe commit 86ea7e7

File tree

4 files changed

+48
-47
lines changed

4 files changed

+48
-47
lines changed

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@
4141
#define CFG_BLE_TX_POWER_LEVEL 0
4242
#define CFG_DEFAULT_NAME "Bluefruit52"
4343

44-
4544
#define CFG_BLE_TASK_STACKSIZE (512*3)
4645
#define CFG_SOC_TASK_STACKSIZE (200)
4746

48-
#define CFG_BOND_NFFS_DIR "/adafruit/bond"
49-
#define BOND_FILENAME CFG_BOND_NFFS_DIR "/%04x"
50-
#define BOND_FILENAME_LEN (sizeof(CFG_BOND_NFFS_DIR) + 10)
51-
5247
AdafruitBluefruit Bluefruit;
5348

5449
/*------------------------------------------------------------------*/
@@ -62,12 +57,6 @@ extern "C"
6257
void adafruit_ble_task(void* arg);
6358
void adafruit_soc_task(void* arg);
6459

65-
#if CFG_DEBUG >= 2
66-
#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
67-
#else
68-
#define printBondDir()
69-
#endif
70-
7160
/*------------------------------------------------------------------*/
7261
/* INTERNAL FUNCTION
7362
*------------------------------------------------------------------*/
@@ -1128,13 +1117,7 @@ bool AdafruitBluefruit::requestPairing(void)
11281117

11291118
void AdafruitBluefruit::clearBonds(void)
11301119
{
1131-
// Detele bonds dir
1132-
Nffs.remove(CFG_BOND_NFFS_DIR);
1133-
1134-
// Create an empty one
1135-
Nffs.mkdir_p(CFG_BOND_NFFS_DIR);
1136-
1137-
printBondDir();
1120+
bond_clear();
11381121
}
11391122

11401123
void AdafruitBluefruit::_bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key)

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ class AdafruitBluefruit
198198

199199
// Shared keys with bonded device, size = 80 bytes
200200
bond_data_t _bond_data;
201-
enum
202-
{
203-
BOND_FILE_DEVNAME_OFFSET = sizeof(_bond_data),
204-
BOND_FILE_CCCD_OFFSET = BOND_FILE_DEVNAME_OFFSET + CFG_MAX_DEVNAME_LEN
205-
};
206201

207202
private:
208203
/*------------- SoftDevice Configuration -------------*/

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,24 @@
3939
#include "bonding.h"
4040
#include "bluefruit.h"
4141

42+
#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)
43+
4244
#if CFG_DEBUG >= 2
43-
//#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
44-
#define printBondDir()
45+
#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
4546
#else
4647
#define printBondDir()
4748
#endif
4849

49-
#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)
50-
51-
5250
/*------------------------------------------------------------------*/
5351
/* Saving Bond Data to Nffs in following layout
5452
* - _bond_data 80 bytes
5553
* - Name 32 bytes
5654
* - CCCD variable
5755
*------------------------------------------------------------------*/
56+
57+
/*------------------------------------------------------------------*/
58+
/* Keys
59+
*------------------------------------------------------------------*/
5860
static void bond_save_keys_dfr(uint16_t conn_hdl, bond_data_t* bdata)
5961
{
6062
char filename[BOND_FILENAME_LEN];
@@ -105,6 +107,28 @@ void bond_save_keys(uint16_t conn_hdl, bond_data_t* bdata)
105107
ada_callback(buf, bond_save_keys_dfr, conn_hdl, buf);
106108
}
107109

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+
*------------------------------------------------------------------*/
108132
static void bond_save_cccd_dfr (uint16_t conn_hdl, uint16_t ediv)
109133
{
110134
uint16_t len=0;
@@ -141,23 +165,6 @@ void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv)
141165
ada_callback(NULL, bond_save_cccd_dfr, cond_hdl, ediv);
142166
}
143167

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-
}
161168

162169
bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv)
163170
{
@@ -207,3 +214,17 @@ bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv)
207214

208215
return loaded;
209216
}
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+
}

libraries/Bluefruit52Lib/src/utility/bonding.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ enum
5858

5959

6060
void bond_save_keys(uint16_t conn_hdl, bond_data_t* bdata);
61-
void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv);
62-
6361
bool bond_load_keys(uint16_t ediv, bond_data_t* bdata);
62+
63+
void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv);
6464
bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv);
6565

66+
void bond_clear(void);
67+
6668

6769
#endif /* BONDING_H_ */

0 commit comments

Comments
 (0)