Add server and client onIdentity callback.

Adds a callback that is called when the identity address of the peer is resolved, this is useful for adding it to a whitelist.
This commit is contained in:
h2zero 2024-06-12 09:26:10 -06:00 committed by h2zero
parent 44daa3c687
commit aeb4334e98
4 changed files with 43 additions and 0 deletions

View file

@ -1189,6 +1189,19 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event *event, void *arg) {
break; break;
} //BLE_GAP_EVENT_ENC_CHANGE } //BLE_GAP_EVENT_ENC_CHANGE
case BLE_GAP_EVENT_IDENTITY_RESOLVED: {
NimBLEConnInfo peerInfo;
rc = ble_gap_conn_find(event->identity_resolved.conn_handle, &peerInfo.m_desc);
if (rc != 0) {
NIMBLE_LOGE(LOG_TAG, "Connection info not found");
rc = 0;
break;
}
pClient->m_pClientCallbacks->onIdentity(peerInfo);
break;
} // BLE_GAP_EVENT_IDENTITY_RESOLVED
case BLE_GAP_EVENT_MTU: { case BLE_GAP_EVENT_MTU: {
if(pClient->m_conn_id != event->mtu.conn_handle){ if(pClient->m_conn_id != event->mtu.conn_handle){
return 0; return 0;
@ -1326,6 +1339,10 @@ void NimBLEClientCallbacks::onAuthenticationComplete(const NimBLEConnInfo& connI
NIMBLE_LOGD("NimBLEClientCallbacks", "onAuthenticationComplete: default"); NIMBLE_LOGD("NimBLEClientCallbacks", "onAuthenticationComplete: default");
} }
void NimBLEClientCallbacks::onIdentity(const NimBLEConnInfo& connInfo){
NIMBLE_LOGD("NimBLEClientCallbacks", "onIdentity: default");
} // onIdentity
void NimBLEClientCallbacks::onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pin){ void NimBLEClientCallbacks::onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pin){
NIMBLE_LOGD("NimBLEClientCallbacks", "onConfirmPIN: default: true"); NIMBLE_LOGD("NimBLEClientCallbacks", "onConfirmPIN: default: true");
NimBLEDevice::injectConfirmPIN(connInfo, true); NimBLEDevice::injectConfirmPIN(connInfo, true);

View file

@ -164,6 +164,12 @@ public:
* @param [in] pin The pin to compare with the server. * @param [in] pin The pin to compare with the server.
*/ */
virtual void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pin); virtual void onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_t pin);
/**
* @brief Called when the peer identity address is resolved.
* @param [in] connInfo A reference to a NimBLEConnInfo instance with information
*/
virtual void onIdentity(const NimBLEConnInfo& connInfo);
}; };
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */ #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */

View file

@ -528,6 +528,16 @@ int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
return 0; return 0;
} // BLE_GAP_EVENT_ENC_CHANGE } // BLE_GAP_EVENT_ENC_CHANGE
case BLE_GAP_EVENT_IDENTITY_RESOLVED: {
rc = ble_gap_conn_find(event->identity_resolved.conn_handle, &peerInfo.m_desc);
if(rc != 0) {
return BLE_ATT_ERR_INVALID_HANDLE;
}
pServer->m_pServerCallbacks->onIdentity(peerInfo);
return 0;
} // BLE_GAP_EVENT_IDENTITY_RESOLVED
case BLE_GAP_EVENT_PASSKEY_ACTION: { case BLE_GAP_EVENT_PASSKEY_ACTION: {
struct ble_sm_io pkey = {0,0}; struct ble_sm_io pkey = {0,0};
@ -864,6 +874,10 @@ void NimBLEServerCallbacks::onConfirmPIN(const NimBLEConnInfo& connInfo, uint32_
NimBLEDevice::injectConfirmPIN(connInfo, true); NimBLEDevice::injectConfirmPIN(connInfo, true);
} // onConfirmPIN } // onConfirmPIN
void NimBLEServerCallbacks::onIdentity(const NimBLEConnInfo& connInfo){
NIMBLE_LOGD("NimBLEServerCallbacks", "onIdentity: default");
} // onIdentity
void NimBLEServerCallbacks::onAuthenticationComplete(const NimBLEConnInfo& connInfo){ void NimBLEServerCallbacks::onAuthenticationComplete(const NimBLEConnInfo& connInfo){
NIMBLE_LOGD("NimBLEServerCallbacks", "onAuthenticationComplete: default"); NIMBLE_LOGD("NimBLEServerCallbacks", "onAuthenticationComplete: default");
} // onAuthenticationComplete } // onAuthenticationComplete

View file

@ -173,6 +173,12 @@ public:
* about the peer connection parameters. * about the peer connection parameters.
*/ */
virtual void onAuthenticationComplete(const NimBLEConnInfo& connInfo); virtual void onAuthenticationComplete(const NimBLEConnInfo& connInfo);
/**
* @brief Called when the peer identity address is resolved.
* @param [in] connInfo A reference to a NimBLEConnInfo instance with information
*/
virtual void onIdentity(const NimBLEConnInfo& connInfo);
}; // NimBLEServerCallbacks }; // NimBLEServerCallbacks
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */ #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */