Skip to content
Snippets Groups Projects
Commit 93234db7 authored by schneider's avatar schneider
Browse files

fix(bondings): Bring API more in line with upstream

parent 6d7635d9
No related branches found
No related tags found
1 merge request!402New pairing database
...@@ -394,6 +394,7 @@ static void bleCccCback(attsCccEvt_t *pEvt) ...@@ -394,6 +394,7 @@ static void bleCccCback(attsCccEvt_t *pEvt)
{ {
/* store value in device database */ /* store value in device database */
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value); AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
AppDbNvmStoreCccTbl(dbHdl);
} }
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL) if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
...@@ -761,6 +762,9 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -761,6 +762,9 @@ static void bleProcMsg(bleMsg_t *pMsg)
case DM_SEC_PAIR_CMPL_IND: case DM_SEC_PAIR_CMPL_IND:
LOG_INFO("ble", "Secure pairing successful, auth: 0x%02X", LOG_INFO("ble", "Secure pairing successful, auth: 0x%02X",
pMsg->dm.pairCmpl.auth); pMsg->dm.pairCmpl.auth);
AppDbNvmStoreBond(AppDbGetHdl((dmConnId_t) pMsg->hdr.param));
pair_connId = DM_CONN_ID_NONE; pair_connId = DM_CONN_ID_NONE;
trigger_event(BLE_EVENT_PAIRING_COMPLETE); trigger_event(BLE_EVENT_PAIRING_COMPLETE);
/* After a successful pairing, bonding is disabled again. /* After a successful pairing, bonding is disabled again.
......
...@@ -182,6 +182,10 @@ static int read_tlv(int fd, uint32_t t, uint32_t l, void *v) ...@@ -182,6 +182,10 @@ static int read_tlv(int fd, uint32_t t, uint32_t l, void *v)
static int write_bond_to_file(appDbRec_t *r, char *filename) static int write_bond_to_file(appDbRec_t *r, char *filename)
{ {
if (!r->inUse) {
return -EINVAL;
}
int fd = epic_file_open(filename, "w"); int fd = epic_file_open(filename, "w");
int ret; int ret;
if (fd < 0) { if (fd < 0) {
...@@ -436,11 +440,6 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask) ...@@ -436,11 +440,6 @@ 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;
char filename[32];
record_to_filename((appDbRec_t *) hdl, filename, sizeof(filename));
/* Directory might exist already. Call will fail silently in that case. */
epic_file_mkdir("pairings");
write_bond_to_file((appDbRec_t *) hdl, filename);
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -708,10 +707,6 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value) ...@@ -708,10 +707,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;
char filename[32];
record_to_filename((appDbRec_t *) hdl, filename, sizeof(filename));
write_bond_to_file((appDbRec_t *) hdl, filename);
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -889,4 +884,49 @@ void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao) ...@@ -889,4 +884,49 @@ void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao)
{ {
((appDbRec_t *)hdl)->peerRpao = peerRpao; ((appDbRec_t *)hdl)->peerRpao = peerRpao;
} }
/*************************************************************************************************/
/*!
* \brief Store the client characteristic configuration table for a device record in NVM.
*
* \param hdl Database record handle.
*
* \return None.
*/
/*************************************************************************************************/
void AppDbNvmStoreCccTbl(appDbHdl_t hdl)
{
/* We take a short cut and simply write the whole file again. */
AppDbNvmStoreBond(hdl);
}
/*************************************************************************************************/
/*!
* \brief Store bonding information for device record in NVM.
*
* \param hdl Database record handle.
*
* \return None.
*/
/*************************************************************************************************/
void AppDbNvmStoreBond(appDbHdl_t hdl)
{
appDbRec_t *pRec = (appDbRec_t *) hdl;
if (pRec->inUse && pRec->valid) {
char filename[32];
record_to_filename(pRec, filename, sizeof(filename));
/* Directory might exist already. Call will fail silently in that case. */
epic_file_mkdir("pairings");
int ret = write_bond_to_file(pRec, filename);
if(ret < 0) {
LOG_WARN(
"bondings",
"Writing pairing '%s' failed: %d",
filename,
ret
);
}
}
}
/* clang-format on */ /* clang-format on */
...@@ -395,6 +395,28 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl); ...@@ -395,6 +395,28 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl);
/*************************************************************************************************/ /*************************************************************************************************/
void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao); void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t peerRpao);
/*************************************************************************************************/
/*!
* \brief Store the client characteristic configuration table for a device record in NVM.
*
* \param hdl Database record handle.
*
* \return None.
*/
/*************************************************************************************************/
void AppDbNvmStoreCccTbl(appDbHdl_t hdl);
/*************************************************************************************************/
/*!
* \brief Store bonding information for device record in NVM.
*
* \param hdl Database record handle.
*
* \return None.
*/
/*************************************************************************************************/
void AppDbNvmStoreBond(appDbHdl_t hdl);
/**@}*/ /**@}*/
/*! \} */ /*! APP_FRAMEWORK_DB_API */ /*! \} */ /*! APP_FRAMEWORK_DB_API */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment