diff --git a/src/NimBLECharacteristic.cpp b/src/NimBLECharacteristic.cpp index d69fee8..73853a5 100644 --- a/src/NimBLECharacteristic.cpp +++ b/src/NimBLECharacteristic.cpp @@ -198,6 +198,15 @@ uint8_t* NimBLECharacteristic::getData() { } // getData +/** + * @brief Retrieve the the current data length of the characteristic. + * @return The length of the current characteristic data. + */ +size_t NimBLECharacteristic:: getDataLength() { + return m_value.getLength(); +} + + int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) @@ -637,4 +646,4 @@ void NimBLECharacteristicCallbacks::onStatus(NimBLECharacteristic* pCharacterist NIMBLE_LOGD("NimBLECharacteristicCallbacks", "onStatus: default"); } // onStatus -#endif /* CONFIG_BT_ENABLED */ \ No newline at end of file +#endif /* CONFIG_BT_ENABLED */ diff --git a/src/NimBLECharacteristic.h b/src/NimBLECharacteristic.h index 1787937..c31a882 100644 --- a/src/NimBLECharacteristic.h +++ b/src/NimBLECharacteristic.h @@ -97,6 +97,7 @@ public: NimBLEUUID getUUID(); std::string getValue(); uint8_t* getData(); + size_t getDataLength(); void indicate(); void notify(bool is_notification = true); @@ -191,4 +192,4 @@ public: virtual void onStatus(NimBLECharacteristic* pCharacteristic, Status s, int code); }; #endif /* CONFIG_BT_ENABLED */ -#endif /*MAIN_NIMBLECHARACTERISTIC_H_*/ \ No newline at end of file +#endif /*MAIN_NIMBLECHARACTERISTIC_H_*/ diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 078c89c..37c3690 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -443,7 +443,7 @@ void NimBLEDevice::stopAdvertising() { ble_hs_cfg.sm_mitm = 0; ble_hs_cfg.sm_sc = 1; ble_hs_cfg.sm_our_key_dist = 1; - ble_hs_cfg.sm_their_key_dist = 1; + ble_hs_cfg.sm_their_key_dist = 3; ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /*TODO: Implement handler for this*/ diff --git a/src/NimBLEServer.cpp b/src/NimBLEServer.cpp index acef95f..5e94b56 100644 --- a/src/NimBLEServer.cpp +++ b/src/NimBLEServer.cpp @@ -226,7 +226,8 @@ uint32_t NimBLEServer::getConnectedCount() { NIMBLE_LOGD(LOG_TAG, ">> handleGapEvent: %s", NimBLEUtils::gapEventToString(event->type)); int rc = 0; - + struct ble_gap_conn_desc desc; + switch(event->type) { case BLE_GAP_EVENT_CONNECT: { @@ -311,9 +312,25 @@ uint32_t NimBLEServer::getConnectedCount() { return 0; } // BLE_GAP_EVENT_CONN_UPDATE + case BLE_GAP_EVENT_REPEAT_PAIRING: { + /* We already have a bond with the peer, but it is attempting to + * establish a new secure link. This app sacrifices security for + * convenience: just throw away the old bond and accept the new link. + */ + + /* Delete the old bond. */ + rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); + assert(rc == 0); + ble_store_util_delete_peer(&desc.peer_id_addr); + + /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should + * continue with the pairing operation. + */ + return BLE_GAP_REPEAT_PAIRING_RETRY; + } // BLE_GAP_EVENT_REPEAT_PAIRING + case BLE_GAP_EVENT_ENC_CHANGE: { - struct ble_gap_conn_desc desc; - int rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc); + rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc); if(rc != 0) { return BLE_ATT_ERR_INVALID_HANDLE; }