@@ -45,7 +45,6 @@ static NimBLEServerCallbacks defaultCallbacks;
4545 */
4646NimBLEServer::NimBLEServer ()
4747 : m_gattsStarted{false },
48- m_getPeerNameOnConnect{false },
4948 m_svcChanged{false },
5049 m_deleteCallbacks{false },
5150# if !CONFIG_BT_NIMBLE_EXT_ADV
@@ -257,15 +256,6 @@ void NimBLEServer::advertiseOnDisconnect(bool enable) {
257256} // advertiseOnDisconnect
258257# endif
259258
260- /* *
261- * @brief Set the server to automatically read the name from the connected peer before
262- * the onConnect callback is called and enables the override callback with name parameter.
263- * @param [in] enable Enable reading the connected peer name upon connection.
264- */
265- void NimBLEServer::getPeerNameOnConnect (bool enable) {
266- m_getPeerNameOnConnect = enable;
267- } // getPeerNameOnConnect
268-
269259/* *
270260 * @brief Return the number of connected clients.
271261 * @return The number of connected clients.
@@ -348,100 +338,6 @@ NimBLEConnInfo NimBLEServer::getPeerInfoByHandle(uint16_t connHandle) const {
348338 return peerInfo;
349339} // getPeerIDInfo
350340
351- /* *
352- * @brief Callback that is called after reading from the peer name characteristic.
353- * @details This will check the task pointer in the task data struct to determine
354- * the action to take once the name has been read. If there is a task waiting then
355- * it will be resumed, if not, the the RC value is checked to determine which callback
356- * should be called.
357- */
358- int NimBLEServer::peerNameCB (uint16_t connHandle, const ble_gatt_error* error, ble_gatt_attr* attr, void * arg) {
359- NimBLETaskData* pTaskData = (NimBLETaskData*)arg;
360- std::string* name = (std::string*)pTaskData->m_pBuf ;
361- int rc = error->status ;
362-
363- if (rc == 0 ) {
364- if (attr) {
365- name->append (OS_MBUF_DATA (attr->om , char *), OS_MBUF_PKTLEN (attr->om ));
366- return rc;
367- }
368- }
369-
370- if (rc == BLE_HS_EDONE) {
371- if (pTaskData->m_flags != -1 ) {
372- NimBLEServer* pServer = (NimBLEServer*)pTaskData->m_pInstance ;
373- NimBLEConnInfo peerInfo{};
374- ble_gap_conn_find (connHandle, &peerInfo.m_desc );
375-
376- // check the flag to indicate which callback should be called.
377- if (pTaskData->m_flags == NIMBLE_SERVER_GET_PEER_NAME_ON_CONNECT_CB) {
378- pServer->m_pServerCallbacks ->onConnect (pServer, peerInfo, *name);
379- } else if (pTaskData->m_flags == NIMBLE_SERVER_GET_PEER_NAME_ON_AUTH_CB) {
380- pServer->m_pServerCallbacks ->onAuthenticationComplete (peerInfo, *name);
381- }
382- }
383- } else {
384- NIMBLE_LOGE (LOG_TAG, " NimBLEServerPeerNameCB rc=%d; %s" , rc, NimBLEUtils::returnCodeToString (rc));
385- }
386-
387- if (pTaskData->m_flags == -1 ) {
388- NimBLEUtils::taskRelease (*pTaskData, rc);
389- } else {
390- // If the read was triggered for callback use then these were allocated.
391- delete name;
392- delete pTaskData;
393- }
394-
395- return rc;
396- }
397-
398- /* *
399- * @brief Implementation of the function that sends the read command.
400- */
401- std::string NimBLEServer::getPeerNameImpl (uint16_t connHandle, int cbType) const {
402- std::string* buf = new std::string{};
403- NimBLETaskData* pTaskData = new NimBLETaskData (const_cast <NimBLEServer*>(this ), cbType, buf);
404- ble_uuid16_t uuid{{BLE_UUID_TYPE_16}, BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME};
405- int rc = ble_gattc_read_by_uuid (connHandle, 1 , 0xffff , &uuid.u , NimBLEServer::peerNameCB, pTaskData);
406- if (rc != 0 ) {
407- NIMBLE_LOGE (LOG_TAG, " ble_gattc_read_by_uuid rc=%d, %s" , rc, NimBLEUtils::returnCodeToString (rc));
408- NimBLEConnInfo peerInfo{};
409- ble_gap_conn_find (connHandle, &peerInfo.m_desc );
410- if (cbType == NIMBLE_SERVER_GET_PEER_NAME_ON_CONNECT_CB) {
411- m_pServerCallbacks->onConnect (const_cast <NimBLEServer*>(this ), peerInfo, *buf);
412- } else if (cbType == NIMBLE_SERVER_GET_PEER_NAME_ON_AUTH_CB) {
413- m_pServerCallbacks->onAuthenticationComplete (peerInfo, *buf);
414- }
415- delete buf;
416- delete pTaskData;
417- } else if (cbType == -1 ) {
418- NimBLEUtils::taskWait (*pTaskData, BLE_NPL_TIME_FOREVER);
419- rc = pTaskData->m_flags ;
420- std::string name{*(std::string*)pTaskData->m_pBuf };
421- delete buf;
422- delete pTaskData;
423-
424- if (rc != 0 && rc != BLE_HS_EDONE) {
425- NIMBLE_LOGE (LOG_TAG, " getPeerName rc=%d %s" , rc, NimBLEUtils::returnCodeToString (rc));
426- }
427-
428- return name;
429- }
430- // TaskData and name buffer will be deleted in the callback.
431- return " " ;
432- }
433-
434- /* *
435- * @brief Get the name of the connected peer.
436- * @param connInfo A reference to a NimBLEConnInfo instance to read the name from.
437- * @returns A string containing the name.
438- * @note This is a blocking call and should NOT be called from any callbacks!
439- */
440- std::string NimBLEServer::getPeerName (const NimBLEConnInfo& connInfo) const {
441- std::string name = getPeerNameImpl (connInfo.getConnHandle ());
442- return name;
443- }
444-
445341/* *
446342 * @brief Gap event handler.
447343 */
@@ -473,11 +369,7 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
473369 }
474370 }
475371
476- if (pServer->m_getPeerNameOnConnect ) {
477- pServer->getPeerNameImpl (event->connect .conn_handle , NIMBLE_SERVER_GET_PEER_NAME_ON_CONNECT_CB);
478- } else {
479- pServer->m_pServerCallbacks ->onConnect (pServer, peerInfo);
480- }
372+ pServer->m_pServerCallbacks ->onConnect (pServer, peerInfo);
481373 }
482374
483375 break ;
@@ -632,12 +524,7 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
632524 return BLE_ATT_ERR_INVALID_HANDLE;
633525 }
634526
635- if (pServer->m_getPeerNameOnConnect ) {
636- pServer->getPeerNameImpl (event->enc_change .conn_handle , NIMBLE_SERVER_GET_PEER_NAME_ON_AUTH_CB);
637- } else {
638- pServer->m_pServerCallbacks ->onAuthenticationComplete (peerInfo);
639- }
640-
527+ pServer->m_pServerCallbacks ->onAuthenticationComplete (peerInfo);
641528 break ;
642529 } // BLE_GAP_EVENT_ENC_CHANGE
643530
@@ -1095,10 +982,6 @@ void NimBLEServerCallbacks::onConnect(NimBLEServer* pServer, NimBLEConnInfo& con
1095982 NIMBLE_LOGD (" NimBLEServerCallbacks" , " onConnect(): Default" );
1096983} // onConnect
1097984
1098- void NimBLEServerCallbacks::onConnect (NimBLEServer* pServer, NimBLEConnInfo& connInfo, std::string& name) {
1099- NIMBLE_LOGD (" NimBLEServerCallbacks" , " onConnect(): Default" );
1100- } // onConnect
1101-
1102985void NimBLEServerCallbacks::onDisconnect (NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) {
1103986 NIMBLE_LOGD (" NimBLEServerCallbacks" , " onDisconnect(): Default" );
1104987} // onDisconnect
@@ -1113,9 +996,9 @@ uint32_t NimBLEServerCallbacks::onPassKeyDisplay() {
1113996} // onPassKeyDisplay
1114997
1115998void NimBLEServerCallbacks::onConfirmPassKey (NimBLEConnInfo& connInfo, uint32_t pin) {
1116- NIMBLE_LOGD (" NimBLEServerCallbacks" , " onConfirmPIN : default: true" );
999+ NIMBLE_LOGD (" NimBLEServerCallbacks" , " onConfirmPasskey : default: true" );
11171000 NimBLEDevice::injectConfirmPasskey (connInfo, true );
1118- } // onConfirmPIN
1001+ } // onConfirmPasskey
11191002
11201003void NimBLEServerCallbacks::onIdentity (NimBLEConnInfo& connInfo) {
11211004 NIMBLE_LOGD (" NimBLEServerCallbacks" , " onIdentity: default" );
@@ -1125,10 +1008,6 @@ void NimBLEServerCallbacks::onAuthenticationComplete(NimBLEConnInfo& connInfo) {
11251008 NIMBLE_LOGD (" NimBLEServerCallbacks" , " onAuthenticationComplete: default" );
11261009} // onAuthenticationComplete
11271010
1128- void NimBLEServerCallbacks::onAuthenticationComplete (NimBLEConnInfo& connInfo, const std::string& name) {
1129- NIMBLE_LOGD (" NimBLEServerCallbacks" , " onAuthenticationComplete: default" );
1130- } // onAuthenticationComplete
1131-
11321011void NimBLEServerCallbacks::onConnParamsUpdate (NimBLEConnInfo& connInfo) {
11331012 NIMBLE_LOGD (" NimBLEServerCallbacks" , " onConnParamsUpdate: default" );
11341013} // onConnParamsUpdate
0 commit comments