Skip to content

Commit 56412b9

Browse files
committed
[BREAKING] - Remove ignore list.
This removes the ignore list feature as it can be implemented by the application if desired. The scan will now ignore any device we are connected to already by checking for any connected client with the same peer address.
1 parent 6ac6241 commit 56412b9

File tree

5 files changed

+6
-61
lines changed

5 files changed

+6
-61
lines changed

examples/NimBLE_Client/NimBLE_Client.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ void setup (){
352352
NimBLEDevice::setPower(9); /** +9db */
353353
#endif
354354

355-
/** Optional: set any devices you don't want to get advertisments from */
356-
// NimBLEDevice::addIgnored(NimBLEAddress ("aa:bb:cc:dd:ee:ff"));
357-
358355
/** create new scan */
359356
NimBLEScan* pScan = NimBLEDevice::getScan();
360357

src/NimBLEClient.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
946946
NIMBLE_LOGD(LOG_TAG, "disconnect; reason=%d, %s", rc, NimBLEUtils::returnCodeToString(rc));
947947

948948
pClient->m_terminateFailCount = 0;
949-
NimBLEDevice::removeIgnored(pClient->m_peerAddress);
950-
951949
// Don't call the disconnect callback if we are waiting for a connection to complete and it fails
952950
if (rc != (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_ESTABLISHMENT) || pClient->m_config.asyncConnect) {
953951
pClient->m_pClientCallbacks->onDisconnect(pClient, rc);
@@ -985,10 +983,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
985983
break;
986984
}
987985
}
988-
989-
// In the case of a multi-connecting device we ignore this device when
990-
// scanning since we are already connected to it
991-
NimBLEDevice::addIgnored(pClient->m_peerAddress);
992986
} else {
993987
pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
994988
if (!pClient->m_config.asyncConnect) {

src/NimBLEDevice.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ bool NimBLEDevice::m_initialized{false};
9797
uint32_t NimBLEDevice::m_passkey{123456};
9898
bool NimBLEDevice::m_synced{false};
9999
ble_gap_event_listener NimBLEDevice::m_listener{};
100-
std::vector<NimBLEAddress> NimBLEDevice::m_ignoreList{};
101100
std::vector<NimBLEAddress> NimBLEDevice::m_whiteList{};
102101
uint8_t NimBLEDevice::m_ownAddrType{BLE_OWN_ADDR_PUBLIC};
103102

@@ -928,7 +927,6 @@ bool NimBLEDevice::deinit(bool clearAll) {
928927
deleteClient(clt);
929928
}
930929
# endif
931-
m_ignoreList.clear();
932930
}
933931

934932
return rc == 0;
@@ -1149,48 +1147,6 @@ bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool acc
11491147
return rc == 0;
11501148
}
11511149

1152-
/* -------------------------------------------------------------------------- */
1153-
/* IGNORE LIST */
1154-
/* -------------------------------------------------------------------------- */
1155-
1156-
/**
1157-
* @brief Check if the device address is on our ignore list.
1158-
* @param [in] address The address to look for.
1159-
* @return True if ignoring.
1160-
*/
1161-
bool NimBLEDevice::isIgnored(const NimBLEAddress& address) {
1162-
for (const auto& addr : m_ignoreList) {
1163-
if (addr == address) {
1164-
return true;
1165-
}
1166-
}
1167-
1168-
return false;
1169-
}
1170-
1171-
/**
1172-
* @brief Add a device to the ignore list.
1173-
* @param [in] address The address of the device we want to ignore.
1174-
*/
1175-
void NimBLEDevice::addIgnored(const NimBLEAddress& address) {
1176-
if (!isIgnored(address)) {
1177-
m_ignoreList.push_back(address);
1178-
}
1179-
}
1180-
1181-
/**
1182-
* @brief Remove a device from the ignore list.
1183-
* @param [in] address The address of the device we want to remove from the list.
1184-
*/
1185-
void NimBLEDevice::removeIgnored(const NimBLEAddress& address) {
1186-
for (auto it = m_ignoreList.begin(); it < m_ignoreList.end(); ++it) {
1187-
if (*it == address) {
1188-
m_ignoreList.erase(it);
1189-
std::vector<NimBLEAddress>(m_ignoreList).swap(m_ignoreList);
1190-
}
1191-
}
1192-
}
1193-
11941150
/* -------------------------------------------------------------------------- */
11951151
/* UTILITIES */
11961152
/* -------------------------------------------------------------------------- */

src/NimBLEDevice.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ class NimBLEDevice {
132132
static bool startSecurity(uint16_t connHandle);
133133
static bool setMTU(uint16_t mtu);
134134
static uint16_t getMTU();
135-
static bool isIgnored(const NimBLEAddress& address);
136-
static void addIgnored(const NimBLEAddress& address);
137-
static void removeIgnored(const NimBLEAddress& address);
138135
static void onReset(int reason);
139136
static void onSync(void);
140137
static void host_task(void* param);
@@ -189,7 +186,6 @@ class NimBLEDevice {
189186
private:
190187
static bool m_synced;
191188
static bool m_initialized;
192-
static std::vector<NimBLEAddress> m_ignoreList;
193189
static uint32_t m_passkey;
194190
static ble_gap_event_listener m_listener;
195191
static uint8_t m_ownAddrType;

src/NimBLEScan.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
6666
# endif
6767
NimBLEAddress advertisedAddress(disc.addr);
6868

69-
// stop processing if we don't want to see it or are already connected
70-
if (NimBLEDevice::isIgnored(advertisedAddress)) {
71-
NIMBLE_LOGI(LOG_TAG, "Ignoring device: address: %s", advertisedAddress.toString().c_str());
69+
# ifdef CONFIG_BT_NIMBLE_ROLE_CENTRAL
70+
// stop processing if already connected
71+
NimBLEClient* pClient = NimBLEDevice::getClientByPeerAddress(advertisedAddress);
72+
if (pClient != nullptr && pClient->isConnected()) {
73+
NIMBLE_LOGI(LOG_TAG, "Ignoring device: address: %s, already connected", advertisedAddress.toString().c_str());
7274
return 0;
7375
}
74-
76+
# endif
7577
NimBLEAdvertisedDevice* advertisedDevice = nullptr;
7678

7779
// If we've seen this device before get a pointer to it from the vector

0 commit comments

Comments
 (0)