more clean up
This commit is contained in:
1 parent
acd4abec1d
commit
86ea7e7ae5
4 files changed
+48
-47
No files matched your search
@@ -41,14 +41,9 @@
|
||||
#define CFG_BLE_TX_POWER_LEVEL 0
|
||||
#define CFG_DEFAULT_NAME "Bluefruit52"
|
||||
|
||||
|
||||
#define CFG_BLE_TASK_STACKSIZE (512*3)
|
||||
#define CFG_SOC_TASK_STACKSIZE (200)
|
||||
|
||||
#define CFG_BOND_NFFS_DIR "/adafruit/bond"
|
||||
#define BOND_FILENAME CFG_BOND_NFFS_DIR "/%04x"
|
||||
#define BOND_FILENAME_LEN (sizeof(CFG_BOND_NFFS_DIR) + 10)
|
||||
|
||||
AdafruitBluefruit Bluefruit;
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@@ -62,12 +57,6 @@ extern "C"
|
||||
void adafruit_ble_task(void* arg);
|
||||
void adafruit_soc_task(void* arg);
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
|
||||
#else
|
||||
#define printBondDir()
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL FUNCTION
|
||||
*------------------------------------------------------------------*/
|
||||
@@ -1128,13 +1117,7 @@ bool AdafruitBluefruit::requestPairing(void)
|
||||
|
||||
void AdafruitBluefruit::clearBonds(void)
|
||||
{
|
||||
// Detele bonds dir
|
||||
Nffs.remove(CFG_BOND_NFFS_DIR);
|
||||
|
||||
// Create an empty one
|
||||
Nffs.mkdir_p(CFG_BOND_NFFS_DIR);
|
||||
|
||||
printBondDir();
|
||||
bond_clear();
|
||||
}
|
||||
|
||||
void AdafruitBluefruit::_bledfu_get_bond_data(ble_gap_addr_t* addr, ble_gap_irk_t* irk, ble_gap_enc_key_t* enc_key)
|
||||
|
||||
@@ -198,11 +198,6 @@ class AdafruitBluefruit
|
||||
|
||||
// Shared keys with bonded device, size = 80 bytes
|
||||
bond_data_t _bond_data;
|
||||
enum
|
||||
{
|
||||
BOND_FILE_DEVNAME_OFFSET = sizeof(_bond_data),
|
||||
BOND_FILE_CCCD_OFFSET = BOND_FILE_DEVNAME_OFFSET + CFG_MAX_DEVNAME_LEN
|
||||
};
|
||||
|
||||
private:
|
||||
/*------------- SoftDevice Configuration -------------*/
|
||||
|
||||
@@ -39,22 +39,24 @@
|
||||
#include "bonding.h"
|
||||
#include "bluefruit.h"
|
||||
|
||||
#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)
|
||||
|
||||
#if CFG_DEBUG >= 2
|
||||
//#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
|
||||
#define printBondDir()
|
||||
#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
|
||||
#else
|
||||
#define printBondDir()
|
||||
#endif
|
||||
|
||||
#define SVC_CONTEXT_FLAG (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Saving Bond Data to Nffs in following layout
|
||||
* - _bond_data 80 bytes
|
||||
* - Name 32 bytes
|
||||
* - CCCD variable
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Keys
|
||||
*------------------------------------------------------------------*/
|
||||
static void bond_save_keys_dfr(uint16_t conn_hdl, bond_data_t* bdata)
|
||||
{
|
||||
char filename[BOND_FILENAME_LEN];
|
||||
@@ -105,6 +107,28 @@ void bond_save_keys(uint16_t conn_hdl, bond_data_t* bdata)
|
||||
ada_callback(buf, bond_save_keys_dfr, conn_hdl, buf);
|
||||
}
|
||||
|
||||
bool bond_load_keys(uint16_t ediv, bond_data_t* bdata)
|
||||
{
|
||||
char filename[BOND_FILENAME_LEN];
|
||||
sprintf(filename, BOND_FILENAME, ediv);
|
||||
|
||||
bool result = (Nffs.readFile(filename, bdata, sizeof(bond_data_t)) > 0);
|
||||
|
||||
if ( result )
|
||||
{
|
||||
LOG_LV2("BOND", "Load Keys from file %s", filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1("BOND", "Keys not found");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* CCCD
|
||||
*------------------------------------------------------------------*/
|
||||
static void bond_save_cccd_dfr (uint16_t conn_hdl, uint16_t ediv)
|
||||
{
|
||||
uint16_t len=0;
|
||||
@@ -141,23 +165,6 @@ void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv)
|
||||
ada_callback(NULL, bond_save_cccd_dfr, cond_hdl, ediv);
|
||||
}
|
||||
|
||||
bool bond_load_keys(uint16_t ediv, bond_data_t* bdata)
|
||||
{
|
||||
char filename[BOND_FILENAME_LEN];
|
||||
sprintf(filename, BOND_FILENAME, ediv);
|
||||
|
||||
bool result = (Nffs.readFile(filename, bdata, sizeof(bond_data_t)) > 0);
|
||||
|
||||
if ( result )
|
||||
{
|
||||
LOG_LV2("BOND", "Load Keys from file %s", filename);
|
||||
}else
|
||||
{
|
||||
LOG_LV1("BOND", "Keys not found");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv)
|
||||
{
|
||||
@@ -207,3 +214,17 @@ bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv)
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* DELETE
|
||||
*------------------------------------------------------------------*/
|
||||
void bond_clear(void)
|
||||
{
|
||||
// Detele bonds dir
|
||||
Nffs.remove(CFG_BOND_NFFS_DIR);
|
||||
|
||||
// Create an empty one
|
||||
Nffs.mkdir_p(CFG_BOND_NFFS_DIR);
|
||||
|
||||
printBondDir();
|
||||
}
|
||||
@@ -58,10 +58,12 @@ enum
|
||||
|
||||
|
||||
void bond_save_keys(uint16_t conn_hdl, bond_data_t* bdata);
|
||||
void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv);
|
||||
|
||||
bool bond_load_keys(uint16_t ediv, bond_data_t* bdata);
|
||||
|
||||
void bond_save_cccd(uint16_t cond_hdl, uint16_t ediv);
|
||||
bool bond_load_cccd(uint16_t cond_hdl, uint16_t ediv);
|
||||
|
||||
void bond_clear(void);
|
||||
|
||||
|
||||
#endif /* BONDING_H_ */
|
||||
Reference in new issue
Block a user