Skip to content

Commit 23a8a6d

Browse files
committed
Allow PHY updates without enabling extended advertising.
1 parent 8484206 commit 23a8a6d

File tree

6 files changed

+31
-51
lines changed

6 files changed

+31
-51
lines changed

src/NimBLEClient.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ void NimBLEClient::setConfig(NimBLEClient::Config config) {
408408
void NimBLEClient::setConnectPhy(uint8_t mask) {
409409
m_phyMask = mask;
410410
} // setConnectPhy
411+
# endif
411412

412413
/**
413414
* @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) {
450451

451452
return rc == 0;
452453
} // getPhy
453-
# endif
454454

455455
/**
456456
* @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) {
11411141
break;
11421142
} // BLE_GAP_EVENT_IDENTITY_RESOLVED
11431143

1144-
# if CONFIG_BT_NIMBLE_EXT_ADV
11451144
case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: {
11461145
NimBLEConnInfo peerInfo;
11471146
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) {
11521151
pClient->m_pClientCallbacks->onPhyUpdate(pClient, event->phy_updated.tx_phy, event->phy_updated.rx_phy);
11531152
return 0;
11541153
} // BLE_GAP_EVENT_PHY_UPDATE_COMPLETE
1155-
# endif
11561154

11571155
case BLE_GAP_EVENT_MTU: {
11581156
if (pClient->m_connHandle != event->mtu.conn_handle) {
@@ -1298,10 +1296,9 @@ void NimBLEClientCallbacks::onMTUChange(NimBLEClient* pClient, uint16_t mtu) {
12981296
NIMBLE_LOGD(CB_TAG, "onMTUChange: default");
12991297
} // onMTUChange
13001298

1301-
# if CONFIG_BT_NIMBLE_EXT_ADV
13021299
void NimBLEClientCallbacks::onPhyUpdate(NimBLEClient* pClient, uint8_t txPhy, uint8_t rxPhy) {
13031300
NIMBLE_LOGD(CB_TAG, "onPhyUpdate: default, txPhy: %d, rxPhy: %d", txPhy, rxPhy);
13041301
} // onPhyUpdate
1305-
# endif
1302+
#
13061303

13071304
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */

src/NimBLEClient.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class NimBLEClient {
9595

9696
# if CONFIG_BT_NIMBLE_EXT_ADV
9797
void setConnectPhy(uint8_t phyMask);
98+
# endif
9899
bool updatePhy(uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions = 0);
99100
bool getPhy(uint8_t* txPhy, uint8_t* rxPhy);
100-
# endif
101101

102102
struct Config {
103103
uint8_t deleteCallbacks : 1; // Delete the callback object when the client is deleted.
@@ -213,7 +213,6 @@ class NimBLEClientCallbacks {
213213
*/
214214
virtual void onMTUChange(NimBLEClient* pClient, uint16_t MTU);
215215

216-
# if CONFIG_BT_NIMBLE_EXT_ADV
217216
/**
218217
* @brief Called when the PHY update procedure is complete.
219218
* @param [in] pClient A pointer to the client whose PHY was updated.
@@ -226,7 +225,6 @@ class NimBLEClientCallbacks {
226225
* * BLE_GAP_LE_PHY_CODED
227226
*/
228227
virtual void onPhyUpdate(NimBLEClient* pClient, uint8_t txPhy, uint8_t rxPhy);
229-
# endif
230228
};
231229

232230
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */

src/NimBLEDevice.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
737737
/* STACK FUNCTIONS */
738738
/* -------------------------------------------------------------------------- */
739739

740-
# if CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
741740
/**
742741
* @brief Set the preferred default phy to use for connections.
743742
* @param [in] txPhyMask TX PHY. Can be mask of following:
@@ -760,7 +759,6 @@ bool NimBLEDevice::setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask) {
760759

761760
return rc == 0;
762761
}
763-
# endif
764762

765763
/**
766764
* @brief Host reset, we pass the message so we don't make calls until re-synced.

src/NimBLEDevice.h

+2-10
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ class NimBLEDeviceCallbacks;
102102
# define NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS
103103
# endif
104104

105-
enum class NimBLETxPowerType {
106-
All = 0,
107-
Advertise = 1,
108-
Scan = 2,
109-
Connection = 3
110-
};
105+
enum class NimBLETxPowerType { All = 0, Advertise = 1, Scan = 2, Connection = 3 };
111106

112107
typedef int (*gap_event_handler)(ble_gap_event* event, void* arg);
113108

@@ -149,6 +144,7 @@ class NimBLEDevice {
149144
static void host_task(void* param);
150145
static int getPower(NimBLETxPowerType type = NimBLETxPowerType::All);
151146
static bool setPower(int8_t dbm, NimBLETxPowerType type = NimBLETxPowerType::All);
147+
static bool setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask);
152148

153149
# ifdef ESP_PLATFORM
154150
# ifndef CONFIG_IDF_TARGET_ESP32P4
@@ -157,10 +153,6 @@ class NimBLEDevice {
157153
# endif
158154
# endif
159155

160-
# if CONFIG_BT_NIMBLE_EXT_ADV
161-
static bool setDefaultPhy(uint8_t txPhyMask, uint8_t rxPhyMask);
162-
# endif
163-
164156
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
165157
static NimBLEScan* getScan();
166158
# endif

src/NimBLEServer.cpp

+24-27
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
544544
break;
545545
} // BLE_GAP_EVENT_IDENTITY_RESOLVED
546546

547-
# if CONFIG_BT_NIMBLE_EXT_ADV
548547
case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: {
549548
rc = ble_gap_conn_find(event->phy_updated.conn_handle, &peerInfo.m_desc);
550549
if (rc != 0) {
@@ -554,7 +553,6 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
554553
pServer->m_pServerCallbacks->onPhyUpdate(peerInfo, event->phy_updated.tx_phy, event->phy_updated.rx_phy);
555554
return 0;
556555
} // BLE_GAP_EVENT_PHY_UPDATE_COMPLETE
557-
# endif
558556

559557
case BLE_GAP_EVENT_PASSKEY_ACTION: {
560558
struct ble_sm_io pkey = {0, 0};
@@ -788,29 +786,6 @@ void NimBLEServer::resetGATT() {
788786
m_gattsStarted = false;
789787
} // resetGATT
790788

791-
# if CONFIG_BT_NIMBLE_EXT_ADV
792-
/**
793-
* @brief Start advertising.
794-
* @param [in] instId The extended advertisement instance ID to start.
795-
* @param [in] duration How long to advertise for in milliseconds, 0 = forever (default).
796-
* @param [in] maxEvents Maximum number of advertisement events to send, 0 = no limit (default).
797-
* @return True if advertising started successfully.
798-
* @details Start the server advertising its existence. This is a convenience function and is equivalent to
799-
* retrieving the advertising object and invoking start upon it.
800-
*/
801-
bool NimBLEServer::startAdvertising(uint8_t instId, int duration, int maxEvents) const {
802-
return getAdvertising()->start(instId, duration, maxEvents);
803-
} // startAdvertising
804-
805-
/**
806-
* @brief Convenience function to stop advertising a data set.
807-
* @param [in] instId The extended advertisement instance ID to stop advertising.
808-
* @return True if advertising stopped successfully.
809-
*/
810-
bool NimBLEServer::stopAdvertising(uint8_t instId) const {
811-
return getAdvertising()->stop(instId);
812-
} // stopAdvertising
813-
814789
/**
815790
* @brief Request an update to the PHY used for a peer connection.
816791
* @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) {
854829

855830
return rc == 0;
856831
} // getPhy
832+
833+
# if CONFIG_BT_NIMBLE_EXT_ADV
834+
/**
835+
* @brief Start advertising.
836+
* @param [in] instId The extended advertisement instance ID to start.
837+
* @param [in] duration How long to advertise for in milliseconds, 0 = forever (default).
838+
* @param [in] maxEvents Maximum number of advertisement events to send, 0 = no limit (default).
839+
* @return True if advertising started successfully.
840+
* @details Start the server advertising its existence. This is a convenience function and is equivalent to
841+
* retrieving the advertising object and invoking start upon it.
842+
*/
843+
bool NimBLEServer::startAdvertising(uint8_t instId, int duration, int maxEvents) const {
844+
return getAdvertising()->start(instId, duration, maxEvents);
845+
} // startAdvertising
846+
847+
/**
848+
* @brief Convenience function to stop advertising a data set.
849+
* @param [in] instId The extended advertisement instance ID to stop advertising.
850+
* @return True if advertising stopped successfully.
851+
*/
852+
bool NimBLEServer::stopAdvertising(uint8_t instId) const {
853+
return getAdvertising()->stop(instId);
854+
} // stopAdvertising
855+
857856
# endif
858857

859858
# if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
@@ -1016,10 +1015,8 @@ void NimBLEServerCallbacks::onConnParamsUpdate(NimBLEConnInfo& connInfo) {
10161015
NIMBLE_LOGD("NimBLEServerCallbacks", "onConnParamsUpdate: default");
10171016
} // onConnParamsUpdate
10181017

1019-
# if CONFIG_BT_NIMBLE_EXT_ADV
10201018
void NimBLEServerCallbacks::onPhyUpdate(NimBLEConnInfo& connInfo, uint8_t txPhy, uint8_t rxPhy) {
10211019
NIMBLE_LOGD("NimBLEServerCallbacks", "onPhyUpdate: default, txPhy: %d, rxPhy: %d", txPhy, rxPhy);
10221020
} // onPhyUpdate
1023-
# endif
10241021

10251022
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */

src/NimBLEServer.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class NimBLEServer {
7979
NimBLEConnInfo getPeerInfoByHandle(uint16_t connHandle) const;
8080
void advertiseOnDisconnect(bool enable);
8181
void setDataLen(uint16_t connHandle, uint16_t tx_octets) const;
82+
bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions);
83+
bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy);
8284

8385
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
8486
NimBLEClient* getClient(uint16_t connHandle);
@@ -90,8 +92,6 @@ class NimBLEServer {
9092
NimBLEExtAdvertising* getAdvertising() const;
9193
bool startAdvertising(uint8_t instanceId, int duration = 0, int maxEvents = 0) const;
9294
bool stopAdvertising(uint8_t instanceId) const;
93-
bool updatePhy(uint16_t connHandle, uint8_t txPhysMask, uint8_t rxPhysMask, uint16_t phyOptions);
94-
bool getPhy(uint16_t connHandle, uint8_t* txPhy, uint8_t* rxPhy);
9595
# endif
9696

9797
# if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
@@ -203,7 +203,6 @@ class NimBLEServerCallbacks {
203203
*/
204204
virtual void onConnParamsUpdate(NimBLEConnInfo& connInfo);
205205

206-
# if CONFIG_BT_NIMBLE_EXT_ADV
207206
/**
208207
* @brief Called when the PHY update procedure is complete.
209208
* @param [in] connInfo A reference to a NimBLEConnInfo instance with information
@@ -216,7 +215,6 @@ class NimBLEServerCallbacks {
216215
* * BLE_GAP_LE_PHY_CODED
217216
*/
218217
virtual void onPhyUpdate(NimBLEConnInfo& connInfo, uint8_t txPhy, uint8_t rxPhy);
219-
# endif
220218
}; // NimBLEServerCallbacks
221219

222220
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL

0 commit comments

Comments
 (0)