Skip to content

Commit 3e0e3e3

Browse files
committed
Make secure counter mutable, remove useless checks
1 parent c23bbca commit 3e0e3e3

File tree

6 files changed

+7
-43
lines changed

6 files changed

+7
-43
lines changed

src/NimBLEClient.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,27 +314,13 @@ bool NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes,
314314
* @return True on success.
315315
* @details This is a blocking function and should not be used in a callback.
316316
*/
317-
bool NimBLEClient::secureConnection(bool async) {
317+
bool NimBLEClient::secureConnection(bool async) const {
318318
NIMBLE_LOGD(LOG_TAG, ">> secureConnection()");
319319

320-
if (!NimBLEDevice::m_synced) {
321-
NIMBLE_LOGE(LOG_TAG, "Host reset, wait for sync.");
322-
return false;
323-
}
324-
325-
if (NimBLEDevice::isSecureInProgress()) {
326-
NIMBLE_LOGE(LOG_TAG, "Secure already in progress");
327-
return false;
328-
}
329-
330-
// Set the secure in progress flag to prevent a scan from starting while securing.
331-
NimBLEDevice::setSecureInProgress(true);
332-
333320
int rc = 0;
334321
if (async && !NimBLEDevice::startSecurity(m_connHandle, &rc)) {
335322
m_lastErr = rc;
336323
m_asyncSecureAttempt = 0;
337-
NimBLEDevice::setSecureInProgress(false);
338324
NIMBLE_LOGE(LOG_TAG, "secureConnection: failed to start rc=%d", rc);
339325
return false;
340326
}
@@ -1116,7 +1102,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
11161102
return 0;
11171103
}
11181104

1119-
NimBLEDevice::setSecureInProgress(false);
11201105
if (event->enc_change.status == 0 ||
11211106
event->enc_change.status == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING)) {
11221107
NimBLEConnInfo peerInfo;

src/NimBLEClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class NimBLEClient {
6464
bool setConnection(uint16_t connHandle);
6565
uint16_t getMTU() const;
6666
bool exchangeMTU();
67-
bool secureConnection(bool async = false);
67+
bool secureConnection(bool async = false) const;
6868
void setConnectTimeout(uint32_t timeout);
6969
bool setDataLen(uint16_t txOctets);
7070
bool discoverAttributes();
@@ -120,7 +120,7 @@ class NimBLEClient {
120120
bool m_deleteCallbacks;
121121
bool m_connEstablished;
122122
bool m_asyncConnect;
123-
uint8_t m_asyncSecureAttempt;
123+
mutable uint8_t m_asyncSecureAttempt;
124124
bool m_exchangeMTU;
125125
# if CONFIG_BT_NIMBLE_EXT_ADV
126126
uint8_t m_phyMask;

src/NimBLEDevice.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ uint8_t NimBLEDevice::m_ownAddrType{BLE_OWN_ADDR_PUBLIC};
103103

104104
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
105105
bool NimBLEDevice::m_connectionInProgress{false};
106-
bool NimBLEDevice::m_secureInProgress{false};
107106
# endif
108107

109108
# ifdef ESP_PLATFORM
@@ -1272,23 +1271,6 @@ bool NimBLEDevice::isConnectionInProgress() {
12721271
return m_connectionInProgress;
12731272
} // isConnectionInProgress
12741273

1275-
/**
1276-
* @brief Set the secure in progress flag.
1277-
* @param [in] inProgress The secure in progress flag.
1278-
* @details This is used to prevent a scan from starting while a secure is in progress.
1279-
*/
1280-
void NimBLEDevice::setSecureInProgress(bool inProgress) {
1281-
m_secureInProgress = inProgress;
1282-
} // setSecureInProgress
1283-
1284-
/**
1285-
* @brief Check if a secure is in progress.
1286-
* @return True if a secure is in progress.
1287-
*/
1288-
bool NimBLEDevice::isSecureInProgress() {
1289-
return m_secureInProgress;
1290-
} // isSecureInProgress
1291-
12921274
/**
12931275
* @brief Return a string representation of the address of this device.
12941276
* @return A string representation of this device address.

src/NimBLEDevice.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ class NimBLEDevice {
186186
static NimBLEAddress getBondedAddress(int index);
187187
static void setConnectionInProgress(bool inProgress);
188188
static bool isConnectionInProgress();
189-
static void setSecureInProgress(bool inProgress);
190-
static bool isSecureInProgress();
191189
# endif
192190

193191
private:
@@ -201,7 +199,6 @@ class NimBLEDevice {
201199

202200
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
203201
static bool m_connectionInProgress;
204-
static bool m_secureInProgress;
205202
# endif
206203

207204
# if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)

src/NimBLERemoteValueAttribute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const char* LOG_TAG = "NimBLERemoteValueAttribute";
1919
bool NimBLERemoteValueAttribute::writeValue(const uint8_t* data, size_t length, bool response) const {
2020
NIMBLE_LOGD(LOG_TAG, ">> writeValue()");
2121

22-
NimBLEClient* pClient = getClient();
22+
const NimBLEClient* pClient = getClient();
2323
int retryCount = 1;
2424
int rc = 0;
2525
uint16_t mtu = pClient->getMTU() - 3;
@@ -109,7 +109,7 @@ NimBLEAttValue NimBLERemoteValueAttribute::readValue(time_t* timestamp) const {
109109
NIMBLE_LOGD(LOG_TAG, ">> readValue()");
110110

111111
NimBLEAttValue value{};
112-
NimBLEClient* pClient = getClient();
112+
const NimBLEClient* pClient = getClient();
113113
int rc = 0;
114114
int retryCount = 1;
115115
NimBLETaskData taskData(const_cast<NimBLERemoteValueAttribute*>(this), 0, &value);

src/NimBLEScan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ bool NimBLEScan::isScanning() {
291291
bool NimBLEScan::start(uint32_t duration, bool is_continue) {
292292
NIMBLE_LOGD(LOG_TAG, ">> start: duration=%" PRIu32, duration);
293293

294-
if (NimBLEDevice::isConnectionInProgress() || NimBLEDevice::isSecureInProgress()) {
295-
NIMBLE_LOGE(LOG_TAG, "Connection/Secure in progress, cannot start scan");
294+
if (NimBLEDevice::isConnectionInProgress()) {
295+
NIMBLE_LOGE(LOG_TAG, "Connection in progress, cannot start scan");
296296
return false;
297297
}
298298

0 commit comments

Comments
 (0)