Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen] Implement ScanNetworks. #27623

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,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