Skip to content

Commit

Permalink
[Tizen] Implement ScanNetworks. (#27623)
Browse files Browse the repository at this point in the history
* [Tizen] Implement ScanNetworks

This pacth:
-> Implements ScanNetworks function.
-> Implements callback functions related to the ScanNetworks.
-> Implements Count and Next function.
-> Resolve race condition in ble-wifi commissioning.

Signed-off-by: Akash Kumar <[email protected]>

* Update src/platform/Tizen/WiFiManager.cpp

Co-authored-by: Arkadiusz Bokowy <[email protected]>

* Implement ScanNetworks

This pacth:
-> Implements ScanNetworks function.
-> Implements callback functions related to the ScanNetworks.
-> Implements Count and Next function.
-> Resolve race condition in ble-wifi commissioning.

Signed-off-by: Akash Kumar <[email protected]>

* Update error handling

Signed-off-by: Akash Kumar <[email protected]>

---------

Signed-off-by: Akash Kumar <[email protected]>
Co-authored-by: Justin Wood <[email protected]>
Co-authored-by: Arkadiusz Bokowy <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2023
1 parent ee014cb commit 0869e98
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ void BLEManagerImpl::OnChipDeviceScanned(void * device, const Ble::ChipBLEDevice

/* Set CHIP Connecting state */
mBLEScanConfig.mBleScanState = BleScanState::kConnecting;
chip::DeviceLayer::PlatformMgr().LockChipStack();
DeviceLayer::SystemLayer().StartTimer(kConnectTimeout, HandleConnectionTimeout, nullptr);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
mDeviceScanner->StopChipScan();

/* Initiate Connect */
Expand Down
27 changes: 27 additions & 0 deletions src/platform/Tizen/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ namespace chip {
namespace DeviceLayer {
namespace NetworkCommissioning {

template <typename T>
class TizenScanResponseIterator : public Iterator<T>
{
public:
TizenScanResponseIterator(std::vector<T> * apScanResponse) : mpScanResponse(apScanResponse) {}
size_t Count() override { return mpScanResponse != nullptr ? mpScanResponse->size() : 0; }
bool Next(T & item) override
{
if (mpScanResponse == nullptr || currentIterating >= mpScanResponse->size())
{
return false;
}
item = (*mpScanResponse)[currentIterating];
currentIterating++;
return true;
}
void Release() override
{ /* nothing to do, we don't hold the ownership of the vector, and users is not expected to hold the ownership in OnFinished for
scan. */
}

private:
size_t currentIterating = 0;
// Note: We cannot post a event in ScheduleLambda since std::vector is not trivial copyable.
std::vector<T> * mpScanResponse;
};

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
class TizenWiFiDriver final : public WiFiDriver
{
Expand Down
32 changes: 27 additions & 5 deletions src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,41 @@ void TizenWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callb

void TizenWiFiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callback)
{
ChipLogError(NetworkProvisioning, "Not implemented");
CHIP_ERROR err = DeviceLayer::Internal::WiFiMgr().StartWiFiScan(ssid, callback);
if (err != CHIP_NO_ERROR)
{
callback->OnFinished(Status::kUnknownError, CharSpan(), nullptr);
}
}

size_t TizenWiFiDriver::WiFiNetworkIterator::Count()
{
ChipLogError(NetworkProvisioning, "Not implemented");
return 0;
return driver->mStagingNetwork.ssidLen == 0 ? 0 : 1;
}

bool TizenWiFiDriver::WiFiNetworkIterator::Next(Network & item)
{
ChipLogError(NetworkProvisioning, "Not implemented");
return false;
if (exhausted || driver->mStagingNetwork.ssidLen == 0)
{
return false;
}
memcpy(item.networkID, driver->mStagingNetwork.ssid, driver->mStagingNetwork.ssidLen);
item.networkIDLen = driver->mStagingNetwork.ssidLen;
item.connected = false;
exhausted = true;

Network configuredNetwork;
CHIP_ERROR err = DeviceLayer::Internal::WiFiMgr().GetConfiguredNetwork(configuredNetwork);
if (err == CHIP_NO_ERROR)
{
if (DeviceLayer::Internal::WiFiMgr().IsWiFiStationConnected() && configuredNetwork.networkIDLen == item.networkIDLen &&
memcmp(configuredNetwork.networkID, item.networkID, item.networkIDLen) == 0)
{
item.connected = true;
}
}

return true;
}

#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand Down
Loading

0 comments on commit 0869e98

Please sign in to comment.