diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index 8ec2a64b..3b1828eb 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -408,6 +408,7 @@ void NimBLEClient::setConfig(NimBLEClient::Config config) { void NimBLEClient::setConnectPhy(uint8_t mask) { m_phyMask = mask; } // setConnectPhy +# endif /** * @brief Request a change to the PHY used for this peer connection. @@ -450,7 +451,6 @@ bool NimBLEClient::getPhy(uint8_t* txPhy, uint8_t* rxPhy) { return rc == 0; } // getPhy -# endif /** * @brief Set the connection parameters to use when connecting to a server. @@ -1141,7 +1141,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) { break; } // BLE_GAP_EVENT_IDENTITY_RESOLVED -# if CONFIG_BT_NIMBLE_EXT_ADV case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: { NimBLEConnInfo peerInfo; rc = ble_gap_conn_find(event->phy_updated.conn_handle, &peerInfo.m_desc); @@ -1152,7 +1151,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) { pClient->m_pClientCallbacks->onPhyUpdate(pClient, event->phy_updated.tx_phy, event->phy_updated.rx_phy); return 0; } // BLE_GAP_EVENT_PHY_UPDATE_COMPLETE -# endif case BLE_GAP_EVENT_MTU: { if (pClient->m_connHandle != event->mtu.conn_handle) { @@ -1298,10 +1296,9 @@ void NimBLEClientCallbacks::onMTUChange(NimBLEClient* pClient, uint16_t mtu) { NIMBLE_LOGD(CB_TAG, "onMTUChange: default"); } // onMTUChange -# if CONFIG_BT_NIMBLE_EXT_ADV void NimBLEClientCallbacks::onPhyUpdate(NimBLEClient* pClient, uint8_t txPhy, uint8_t rxPhy) { NIMBLE_LOGD(CB_TAG, "onPhyUpdate: default, txPhy: %d, rxPhy: %d", txPhy, rxPhy); } // onPhyUpdate -# endif +# #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */ diff --git a/src/NimBLEClient.h b/src/NimBLEClient.h index 79e51d98..f3a3bd8d 100644 --- a/src/NimBLEClient.h +++ b/src/NimBLEClient.h @@ -95,9 +95,9 @@ class NimBLEClient { # if CONFIG_BT_NIMBLE_EXT_ADV void setConnectPhy(uint8_t phyMask); +# endif bool updatePhy(uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions = 0); bool getPhy(uint8_t* txPhy, uint8_t* rxPhy); -# endif struct Config { uint8_t deleteCallbacks : 1; // Delete the callback object when the client is deleted. @@ -213,7 +213,6 @@ class NimBLEClientCallbacks { */ virtual void onMTUChange(NimBLEClient* pClient, uint16_t MTU); -# if CONFIG_BT_NIMBLE_EXT_ADV /** * @brief Called when the PHY update procedure is complete. * @param [in] pClient A pointer to the client whose PHY was updated. @@ -226,7 +225,6 @@ class NimBLEClientCallbacks { * * BLE_GAP_LE_PHY_CODED */ virtual void onPhyUpdate(NimBLEClient* pClient, uint8_t txPhy, uint8_t rxPhy); -# endif }; #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */ diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index e981decd..864dbcfe 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -737,7 +737,6 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) { /* STACK FUNCTIONS */ /* -------------------------------------------------------------------------- */ -# if CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_) /** * @brief Set the preferred default phy to use for connections. * @param [in] txPhyMask TX PHY. Can be mask of following: @@ -760,7 +759,6 @@ bool NimBLEDevice::setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask) { return rc == 0; } -# endif /** * @brief Host reset, we pass the message so we don't make calls until re-synced. diff --git a/src/NimBLEDevice.h b/src/NimBLEDevice.h index 5ec10c9f..b76388c1 100644 --- a/src/NimBLEDevice.h +++ b/src/NimBLEDevice.h @@ -102,12 +102,7 @@ class NimBLEDeviceCallbacks; # define NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS # endif -enum class NimBLETxPowerType { - All = 0, - Advertise = 1, - Scan = 2, - Connection = 3 -}; +enum class NimBLETxPowerType { All = 0, Advertise = 1, Scan = 2, Connection = 3 }; typedef int (*gap_event_handler)(ble_gap_event* event, void* arg); @@ -149,6 +144,7 @@ class NimBLEDevice { static void host_task(void* param); static int getPower(NimBLETxPowerType type = NimBLETxPowerType::All); static bool setPower(int8_t dbm, NimBLETxPowerType type = NimBLETxPowerType::All); + static bool setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask); # ifdef ESP_PLATFORM # ifndef CONFIG_IDF_TARGET_ESP32P4 @@ -157,10 +153,6 @@ class NimBLEDevice { # endif # endif -# if CONFIG_BT_NIMBLE_EXT_ADV - static bool setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask); -# endif - # if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER) static NimBLEScan* getScan(); # endif diff --git a/src/NimBLEServer.cpp b/src/NimBLEServer.cpp index 2980d9a4..2ba2aafc 100644 --- a/src/NimBLEServer.cpp +++ b/src/NimBLEServer.cpp @@ -544,7 +544,6 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) { break; } // BLE_GAP_EVENT_IDENTITY_RESOLVED -# if CONFIG_BT_NIMBLE_EXT_ADV case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: { rc = ble_gap_conn_find(event->phy_updated.conn_handle, &peerInfo.m_desc); if (rc != 0) { @@ -554,7 +553,6 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) { pServer->m_pServerCallbacks->onPhyUpdate(peerInfo, event->phy_updated.tx_phy, event->phy_updated.rx_phy); return 0; } // BLE_GAP_EVENT_PHY_UPDATE_COMPLETE -# endif case BLE_GAP_EVENT_PASSKEY_ACTION: { struct ble_sm_io pkey = {0, 0}; @@ -788,29 +786,6 @@ void NimBLEServer::resetGATT() { m_gattsStarted = false; } // resetGATT -# if CONFIG_BT_NIMBLE_EXT_ADV -/** - * @brief Start advertising. - * @param [in] instId The extended advertisement instance ID to start. - * @param [in] duration How long to advertise for in milliseconds, 0 = forever (default). - * @param [in] maxEvents Maximum number of advertisement events to send, 0 = no limit (default). - * @return True if advertising started successfully. - * @details Start the server advertising its existence. This is a convenience function and is equivalent to - * retrieving the advertising object and invoking start upon it. - */ -bool NimBLEServer::startAdvertising(uint8_t instId, int duration, int maxEvents) const { - return getAdvertising()->start(instId, duration, maxEvents); -} // startAdvertising - -/** - * @brief Convenience function to stop advertising a data set. - * @param [in] instId The extended advertisement instance ID to stop advertising. - * @return True if advertising stopped successfully. - */ -bool NimBLEServer::stopAdvertising(uint8_t instId) const { - return getAdvertising()->stop(instId); -} // stopAdvertising - /** * @brief Request an update to the PHY used for a peer connection. * @param [in] connHandle the connection handle to the update the PHY for. @@ -854,6 +829,30 @@ bool NimBLEServer::getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy) { return rc == 0; } // getPhy + +# if CONFIG_BT_NIMBLE_EXT_ADV +/** + * @brief Start advertising. + * @param [in] instId The extended advertisement instance ID to start. + * @param [in] duration How long to advertise for in milliseconds, 0 = forever (default). + * @param [in] maxEvents Maximum number of advertisement events to send, 0 = no limit (default). + * @return True if advertising started successfully. + * @details Start the server advertising its existence. This is a convenience function and is equivalent to + * retrieving the advertising object and invoking start upon it. + */ +bool NimBLEServer::startAdvertising(uint8_t instId, int duration, int maxEvents) const { + return getAdvertising()->start(instId, duration, maxEvents); +} // startAdvertising + +/** + * @brief Convenience function to stop advertising a data set. + * @param [in] instId The extended advertisement instance ID to stop advertising. + * @return True if advertising stopped successfully. + */ +bool NimBLEServer::stopAdvertising(uint8_t instId) const { + return getAdvertising()->stop(instId); +} // stopAdvertising + # endif # if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_) @@ -1016,10 +1015,8 @@ void NimBLEServerCallbacks::onConnParamsUpdate(NimBLEConnInfo& connInfo) { NIMBLE_LOGD("NimBLEServerCallbacks", "onConnParamsUpdate: default"); } // onConnParamsUpdate -# if CONFIG_BT_NIMBLE_EXT_ADV void NimBLEServerCallbacks::onPhyUpdate(NimBLEConnInfo& connInfo, uint8_t txPhy, uint8_t rxPhy) { NIMBLE_LOGD("NimBLEServerCallbacks", "onPhyUpdate: default, txPhy: %d, rxPhy: %d", txPhy, rxPhy); } // onPhyUpdate -# endif #endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */ diff --git a/src/NimBLEServer.h b/src/NimBLEServer.h index 4eb7962b..7d074ba1 100644 --- a/src/NimBLEServer.h +++ b/src/NimBLEServer.h @@ -79,6 +79,8 @@ class NimBLEServer { NimBLEConnInfo getPeerInfoByHandle(uint16_t connHandle) const; void advertiseOnDisconnect(bool enable); void setDataLen(uint16_t connHandle, uint16_t tx_octets) const; + bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions); + bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy); # if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) NimBLEClient* getClient(uint16_t connHandle); @@ -90,8 +92,6 @@ class NimBLEServer { NimBLEExtAdvertising* getAdvertising() const; bool startAdvertising(uint8_t instanceId, int duration = 0, int maxEvents = 0) const; bool stopAdvertising(uint8_t instanceId) const; - bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions); - bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy); # endif # if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_) @@ -203,7 +203,6 @@ class NimBLEServerCallbacks { */ virtual void onConnParamsUpdate(NimBLEConnInfo& connInfo); -# if CONFIG_BT_NIMBLE_EXT_ADV /** * @brief Called when the PHY update procedure is complete. * @param [in] connInfo A reference to a NimBLEConnInfo instance with information @@ -216,7 +215,6 @@ class NimBLEServerCallbacks { * * BLE_GAP_LE_PHY_CODED */ virtual void onPhyUpdate(NimBLEConnInfo& connInfo, uint8_t txPhy, uint8_t rxPhy); -# endif }; // NimBLEServerCallbacks #endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL