From 7a86a01e3d8ede72aaf0f1e163ca31e8b91debe1 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 4 Oct 2020 22:26:58 +0200 Subject: [PATCH] fix(bondings): Bring API more in line with upstream --- epicardium/ble/ble_main.c | 8 ++++ epicardium/ble/bondings.c | 46 +++++++++++++++---- .../stack/ble-profiles/include/app/app_db.h | 22 +++++++++ 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/epicardium/ble/ble_main.c b/epicardium/ble/ble_main.c index a5522b4e7..35024f6aa 100644 --- a/epicardium/ble/ble_main.c +++ b/epicardium/ble/ble_main.c @@ -394,6 +394,7 @@ static void bleCccCback(attsCccEvt_t *pEvt) { /* store value in device database */ AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value); + AppDbNvmStoreCccTbl(dbHdl); } if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL) @@ -761,6 +762,10 @@ static void bleProcMsg(bleMsg_t *pMsg) case DM_SEC_PAIR_CMPL_IND: LOG_INFO("ble", "Secure pairing successful, auth: 0x%02X", pMsg->dm.pairCmpl.auth); + + DmSecGenerateEccKeyReq(); + AppDbNvmStoreBond(AppDbGetHdl((dmConnId_t) pMsg->hdr.param)); + pair_connId = DM_CONN_ID_NONE; trigger_event(BLE_EVENT_PAIRING_COMPLETE); /* After a successful pairing, bonding is disabled again. @@ -783,6 +788,9 @@ static void bleProcMsg(bleMsg_t *pMsg) pMsg->hdr.status); break; } + + DmSecGenerateEccKeyReq(); + pair_connId = DM_CONN_ID_NONE; trigger_event(BLE_EVENT_PAIRING_FAILED); break; diff --git a/epicardium/ble/bondings.c b/epicardium/ble/bondings.c index 910c8f26f..3620ba3a7 100644 --- a/epicardium/ble/bondings.c +++ b/epicardium/ble/bondings.c @@ -425,11 +425,6 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask) { ((appDbRec_t *) hdl)->valid = TRUE; ((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); } /*************************************************************************************************/ @@ -697,10 +692,6 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value) WSF_ASSERT(idx < APP_DB_NUM_CCCD); ((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); } /*************************************************************************************************/ @@ -878,4 +869,41 @@ void AppDbSetPeerRpao(appDbHdl_t hdl, bool_t 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"); + write_bond_to_file(pRec, filename); + } +} /* clang-format on */ diff --git a/lib/sdk/Libraries/BTLE/stack/ble-profiles/include/app/app_db.h b/lib/sdk/Libraries/BTLE/stack/ble-profiles/include/app/app_db.h index e72fb4cf8..a34b6d3bb 100644 --- a/lib/sdk/Libraries/BTLE/stack/ble-profiles/include/app/app_db.h +++ b/lib/sdk/Libraries/BTLE/stack/ble-profiles/include/app/app_db.h @@ -395,6 +395,28 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl); /*************************************************************************************************/ 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 */ -- GitLab