Skip to content

Commit 623db56

Browse files
[bouffalo lab] fix bl616 wifi scan operation with/without specified ssid (project-chip#38877)
* [bouffalo lab] fix bl616 wifi scan operation with/without specified ssid * Restyled by clang-format * check ssid length before * Verify SSID length prior to copying and correct pScanResult reference handling when SSID is specified. * Restyled by clang-format * remove +1 for mScanSSID * Restyled by clang-format --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 47b3a6a commit 623db56

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/platform/bouffalolab/BL616/NetworkCommissioningDriver.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,14 @@ void BLWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callba
205205
{
206206
if (callback != nullptr)
207207
{
208-
mpScanCallback = nullptr;
209-
if (0 == wifi_start_scan(ssid.data(), ssid.size()))
208+
mpScanCallback = nullptr;
209+
mScanSSIDlength = 0;
210+
211+
if (ssid.size() <= sizeof(mScanSSID) && 0 == wifi_start_scan(ssid.data(), ssid.size()))
210212
{
211-
mpScanCallback = callback;
213+
memcpy(mScanSSID, ssid.data(), ssid.size());
214+
mScanSSIDlength = ssid.size();
215+
mpScanCallback = callback;
212216
}
213217
else
214218
{
@@ -231,9 +235,30 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
231235
}
232236
else
233237
{
238+
wifi_mgmr_scan_item_t * pScanResult = NULL;
239+
uint32_t scanResultNum = 0;
240+
241+
if (mScanSSIDlength)
242+
{
243+
for (uint32_t i = 0; i < nums; i++)
244+
{
245+
if (mScanSSIDlength == pScanList[i].ssid_len && memcmp(pScanList[i].ssid, mScanSSID, mScanSSIDlength) == 0)
246+
{
247+
pScanResult = &pScanList[i];
248+
scanResultNum = 1;
249+
break;
250+
}
251+
}
252+
}
253+
else
254+
{
255+
pScanResult = pScanList;
256+
scanResultNum = nums;
257+
}
258+
259+
if (CHIP_NO_ERROR != DeviceLayer::SystemLayer().ScheduleLambda([scanResultNum, pScanResult, pScanList]() {
260+
BLScanResponseIterator iter(scanResultNum, pScanResult);
234261

235-
if (CHIP_NO_ERROR == DeviceLayer::SystemLayer().ScheduleLambda([nums, pScanList]() {
236-
BLScanResponseIterator iter(nums, pScanList);
237262
if (GetInstance().mpScanCallback)
238263
{
239264
GetInstance().mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), &iter);
@@ -243,6 +268,8 @@ void BLWiFiDriver::OnScanWiFiNetworkDone()
243268
{
244269
ChipLogError(DeviceLayer, "can't find the ScanCallback function");
245270
}
271+
272+
MemoryFree(pScanList);
246273
}))
247274
{
248275
MemoryFree(pScanList);

src/platform/bouffalolab/BL616/NetworkCommissioningDriver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class BLWiFiDriver final : public WiFiDriver
141141
ConnectCallback * mpConnectCallback;
142142
NetworkStatusChangeCallback * mpStatusChangeCallback = nullptr;
143143
int32_t mLastDisconnectedReason;
144+
145+
char mScanSSID[DeviceLayer::Internal::kMaxWiFiSSIDLength];
146+
int mScanSSIDlength;
144147
};
145148

146149
} // namespace NetworkCommissioning

0 commit comments

Comments
 (0)