Commit e86c7b6e authored by schneider's avatar schneider

refact(ble): Simplify bonding storage

parent 7e8f17f0
...@@ -95,12 +95,6 @@ static appDb_t appDb; ...@@ -95,12 +95,6 @@ static appDb_t appDb;
/*! When all records are allocated use this index to determine which to overwrite */ /*! When all records are allocated use this index to determine which to overwrite */
static appDbRec_t *pAppDbNewRec = appDb.rec; static appDbRec_t *pAppDbNewRec = appDb.rec;
/* Timer to delay writing to persistent storage until a burst of store() calls has finished */
static TimerHandle_t store_timer;
static StaticTimer_t store_timer_buffer;
static void store_callback();
#define STORE_DELAY pdMS_TO_TICKS(5000)
/*************************************************************************************************/ /*************************************************************************************************/
/*! /*!
* \brief Initialize the device database. * \brief Initialize the device database.
...@@ -117,32 +111,12 @@ void AppDbInit(void) ...@@ -117,32 +111,12 @@ void AppDbInit(void)
memset(&appDb, 0, sizeof(appDb)); memset(&appDb, 0, sizeof(appDb));
} }
epic_file_close(fd); epic_file_close(fd);
}
store_timer = xTimerCreateStatic(
"appdb_store_timer",
STORE_DELAY,
pdFALSE,
NULL,
store_callback,
&store_timer_buffer
);
}
/* TODO this should actually put tasks into a queue. On the other end of the queue */
/* a worker task can read tasks off the queue and execute them */
static void store(void)
{
LOG_INFO("appDb", "store() called, resetting timer");
if (xTimerReset(store_timer, 10) != pdPASS) { /* (Re)start the timer */
/* Store timer could not be reset, write to persistent storage anyway */
store_callback();
} }
} }
static void store_callback() static void AppDbStore(void)
{ {
LOG_INFO("appDb", "STORE_DELAY passed, writing to persistent storage"); LOG_INFO("appDb", "writing to persistent storage");
int fd = epic_file_open("pairings.bin", "w"); int fd = epic_file_open("pairings.bin", "w");
if(fd >= 0) { if(fd >= 0) {
...@@ -198,7 +172,6 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr) ...@@ -198,7 +172,6 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
pRec->peerAddedToRl = FALSE; pRec->peerAddedToRl = FALSE;
pRec->peerRpao = FALSE; pRec->peerRpao = FALSE;
store();
return (appDbHdl_t) pRec; return (appDbHdl_t) pRec;
} }
...@@ -263,7 +236,6 @@ appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl) ...@@ -263,7 +236,6 @@ appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl)
void AppDbDeleteRecord(appDbHdl_t hdl) void AppDbDeleteRecord(appDbHdl_t hdl)
{ {
((appDbRec_t *) hdl)->inUse = FALSE; ((appDbRec_t *) hdl)->inUse = FALSE;
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -281,7 +253,7 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask) ...@@ -281,7 +253,7 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask)
{ {
((appDbRec_t *) hdl)->valid = TRUE; ((appDbRec_t *) hdl)->valid = TRUE;
((appDbRec_t *) hdl)->keyValidMask = keyMask; ((appDbRec_t *) hdl)->keyValidMask = keyMask;
store(); AppDbStore();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -371,7 +343,6 @@ void AppDbDeleteAllRecords(void) ...@@ -371,7 +343,6 @@ void AppDbDeleteAllRecords(void)
{ {
pRec->inUse = FALSE; pRec->inUse = FALSE;
} }
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -518,7 +489,6 @@ void AppDbSetKey(appDbHdl_t hdl, dmSecKeyIndEvt_t *pKey) ...@@ -518,7 +489,6 @@ void AppDbSetKey(appDbHdl_t hdl, dmSecKeyIndEvt_t *pKey)
default: default:
break; break;
} }
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -551,7 +521,6 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value) ...@@ -551,7 +521,6 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value)
WSF_ASSERT(idx < APP_DB_NUM_CCCD); WSF_ASSERT(idx < APP_DB_NUM_CCCD);
((appDbRec_t *) hdl)->cccTbl[idx] = value; ((appDbRec_t *) hdl)->cccTbl[idx] = value;
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -581,7 +550,6 @@ uint8_t AppDbGetDiscStatus(appDbHdl_t hdl) ...@@ -581,7 +550,6 @@ uint8_t AppDbGetDiscStatus(appDbHdl_t hdl)
void AppDbSetDiscStatus(appDbHdl_t hdl, uint8_t status) void AppDbSetDiscStatus(appDbHdl_t hdl, uint8_t status)
{ {
((appDbRec_t *) hdl)->discStatus = status; ((appDbRec_t *) hdl)->discStatus = status;
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -611,7 +579,6 @@ uint16_t *AppDbGetHdlList(appDbHdl_t hdl) ...@@ -611,7 +579,6 @@ uint16_t *AppDbGetHdlList(appDbHdl_t hdl)
void AppDbSetHdlList(appDbHdl_t hdl, uint16_t *pHdlList) void AppDbSetHdlList(appDbHdl_t hdl, uint16_t *pHdlList)
{ {
memcpy(((appDbRec_t *) hdl)->hdlList, pHdlList, sizeof(((appDbRec_t *) hdl)->hdlList)); memcpy(((appDbRec_t *) hdl)->hdlList, pHdlList, sizeof(((appDbRec_t *) hdl)->hdlList));
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -654,7 +621,6 @@ void AppDbSetDevName(uint8_t len, char *pStr) ...@@ -654,7 +621,6 @@ void AppDbSetDevName(uint8_t len, char *pStr)
len = (len <= sizeof(appDb.devName)) ? len : sizeof(appDb.devName); len = (len <= sizeof(appDb.devName)) ? len : sizeof(appDb.devName);
memcpy(appDb.devName, pStr, len); memcpy(appDb.devName, pStr, len);
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -684,7 +650,6 @@ bool_t AppDbGetPeerAddrRes(appDbHdl_t hdl) ...@@ -684,7 +650,6 @@ bool_t AppDbGetPeerAddrRes(appDbHdl_t hdl)
void AppDbSetPeerAddrRes(appDbHdl_t hdl, uint8_t addrRes) void AppDbSetPeerAddrRes(appDbHdl_t hdl, uint8_t addrRes)
{ {
((appDbRec_t *)hdl)->peerAddrRes = addrRes; ((appDbRec_t *)hdl)->peerAddrRes = addrRes;
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -715,7 +680,6 @@ void AppDbSetPeerSignCounter(appDbHdl_t hdl, uint32_t signCounter) ...@@ -715,7 +680,6 @@ void AppDbSetPeerSignCounter(appDbHdl_t hdl, uint32_t signCounter)
{ {
if(((appDbRec_t *)hdl)->peerSignCounter != signCounter) { if(((appDbRec_t *)hdl)->peerSignCounter != signCounter) {
((appDbRec_t *)hdl)->peerSignCounter = signCounter; ((appDbRec_t *)hdl)->peerSignCounter = signCounter;
store();
} }
} }
...@@ -746,7 +710,6 @@ bool_t AppDbGetPeerAddedToRl(appDbHdl_t hdl) ...@@ -746,7 +710,6 @@ bool_t AppDbGetPeerAddedToRl(appDbHdl_t hdl)
void AppDbSetPeerAddedToRl(appDbHdl_t hdl, bool_t peerAddedToRl) void AppDbSetPeerAddedToRl(appDbHdl_t hdl, bool_t peerAddedToRl)
{ {
((appDbRec_t *)hdl)->peerAddedToRl = peerAddedToRl; ((appDbRec_t *)hdl)->peerAddedToRl = peerAddedToRl;
store();
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -776,6 +739,5 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl) ...@@ -776,6 +739,5 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl)
void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao) void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao)
{ {
((appDbRec_t *)hdl)->peerRpao = peerRpao; ((appDbRec_t *)hdl)->peerRpao = peerRpao;
store();
} }
/* clang-format on */ /* clang-format on */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment