diff --git a/src/platform/Tizen/WiFiManager.cpp b/src/platform/Tizen/WiFiManager.cpp index b13657e0d66c03..cc0369120b11b0 100644 --- a/src/platform/Tizen/WiFiManager.cpp +++ b/src/platform/Tizen/WiFiManager.cpp @@ -344,29 +344,42 @@ void WiFiManager::_ScanToConnectFinishedCb(wifi_manager_error_e wifiErr, void * } } -void WiFiManager::_ScanFinishedCb(wifi_manager_error_e wifiErr, void * userData) +void WiFiManager::_UpdateScanCallback(void * scanCbData) { - if (wifiErr == WIFI_MANAGER_ERROR_NONE) - { - std::vector networkScanned; - int err = wifi_manager_foreach_found_specific_ap(sInstance.mWiFiManagerHandle, _FoundAPOnScanCb, &networkScanned); - - VerifyOrReturn(err == WIFI_MANAGER_ERROR_NONE, - ChipLogError(DeviceLayer, "FAIL: get scan list [%s]", get_error_message(err))); + auto networkScanned = static_cast *>(scanCbData); - chip::DeviceLayer::PlatformMgr().LockChipStack(); - if (sInstance.mpScanCallback != nullptr) - { - TizenScanResponseIterator iter(&networkScanned); - sInstance.mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), &iter); - sInstance.mpScanCallback = nullptr; - } - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - } - else + chip::DeviceLayer::PlatformMgr().LockChipStack(); + if (sInstance.mpScanCallback != nullptr) { - ChipLogError(DeviceLayer, "FAIL: scan WiFi [%s]", get_error_message(wifiErr)); + TizenScanResponseIterator iter(networkScanned); + sInstance.mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), &iter); + sInstance.mpScanCallback = nullptr; } + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); +} + +void WiFiManager::_SpecificScanFinishedCb(wifi_manager_error_e wifiErr, void * userData) +{ + VerifyOrReturn(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogError(DeviceLayer, "FAIL: scan WiFi [%s]", get_error_message(wifiErr))); + + std::vector networkScanned; + int err = wifi_manager_foreach_found_specific_ap(sInstance.mWiFiManagerHandle, _FoundAPOnScanCb, &networkScanned); + + VerifyOrReturn(err == WIFI_MANAGER_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: get scan list [%s]", get_error_message(err))); + _UpdateScanCallback(&networkScanned); +} + +void WiFiManager::_FullScanFinishedCb(wifi_manager_error_e wifiErr, void * userData) +{ + VerifyOrReturn(wifiErr == WIFI_MANAGER_ERROR_NONE, + ChipLogError(DeviceLayer, "FAIL: scan WiFi [%s]", get_error_message(wifiErr))); + + std::vector networkScanned; + int err = wifi_manager_foreach_found_ap(sInstance.mWiFiManagerHandle, _FoundAPOnScanCb, &networkScanned); + + VerifyOrReturn(err == WIFI_MANAGER_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: get scan list [%s]", get_error_message(err))); + _UpdateScanCallback(&networkScanned); } bool WiFiManager::_FoundAPOnScanCb(wifi_manager_ap_h ap, void * userData) @@ -577,15 +590,26 @@ CHIP_ERROR WiFiManager::_WiFiScanToConnect(gpointer userData) return CHIP_NO_ERROR; } -CHIP_ERROR WiFiManager::_WiFiScan(gpointer userData) +CHIP_ERROR WiFiManager::_WiFiSpecificScan(gpointer userData) { - int wifiErr; + int wifiErr = + wifi_manager_scan_specific_ap(sInstance.mWiFiManagerHandle, sInstance.mInterestedSSID, _SpecificScanFinishedCb, nullptr); - wifiErr = wifi_manager_scan_specific_ap(sInstance.mWiFiManagerHandle, sInstance.mInterestedSSID, _ScanFinishedCb, nullptr); VerifyOrReturnError(wifiErr == WIFI_MANAGER_ERROR_NONE, CHIP_ERROR_INTERNAL, ChipLogError(DeviceLayer, "FAIL: request WiFi scan [%s]", get_error_message(wifiErr))); - ChipLogProgress(DeviceLayer, "WiFi scan is requested"); + ChipLogProgress(DeviceLayer, "WiFi specific scan is requested"); + return CHIP_NO_ERROR; +} + +CHIP_ERROR WiFiManager::_WiFiFullScan(gpointer userData) +{ + int wifiErr = wifi_manager_scan(sInstance.mWiFiManagerHandle, _FullScanFinishedCb, nullptr); + + VerifyOrReturnError(wifiErr == WIFI_MANAGER_ERROR_NONE, CHIP_ERROR_INTERNAL, + ChipLogError(DeviceLayer, "FAIL: request WiFi scan [%s]", get_error_message(wifiErr))); + + ChipLogProgress(DeviceLayer, "WiFi full scan is requested"); return CHIP_NO_ERROR; } @@ -919,19 +943,25 @@ CHIP_ERROR WiFiManager::StartWiFiScan(ByteSpan ssid, DeviceLayer::NetworkCommiss int wifiErr = WIFI_MANAGER_ERROR_NONE; bool isWiFiActivated = false; - memcpy(sInstance.mInterestedSSID, ssid.data(), ssid.size()); - sInstance.mInterestedSSID[ssid.size()] = '\0'; - wifiErr = wifi_manager_is_activated(sInstance.mWiFiManagerHandle, &isWiFiActivated); VerifyOrExit(wifiErr == WIFI_MANAGER_ERROR_NONE, err = CHIP_ERROR_INCORRECT_STATE; ChipLogError(DeviceLayer, "FAIL: check whether WiFi is activated [%s]", get_error_message(wifiErr))); VerifyOrExit(isWiFiActivated == true, ChipLogProgress(DeviceLayer, "WiFi is deactivated")); - sInstance.mpScanCallback = callback; - err = PlatformMgrImpl().GLibMatterContextInvokeSync(_WiFiScan, static_cast(nullptr)); - SuccessOrExit(err); + if (ssid.size() > 0) + { + memcpy(sInstance.mInterestedSSID, ssid.data(), ssid.size()); + sInstance.mInterestedSSID[ssid.size()] = '\0'; + err = PlatformMgrImpl().GLibMatterContextInvokeSync(_WiFiSpecificScan, static_cast(nullptr)); + } + else + { + err = PlatformMgrImpl().GLibMatterContextInvokeSync(_WiFiFullScan, static_cast(nullptr)); + } + + SuccessOrExit(err); exit: return err; } diff --git a/src/platform/Tizen/WiFiManager.h b/src/platform/Tizen/WiFiManager.h index b9b21bb6ab761a..8e24b6636763c3 100644 --- a/src/platform/Tizen/WiFiManager.h +++ b/src/platform/Tizen/WiFiManager.h @@ -70,16 +70,19 @@ class WiFiManager static void _ActivateCb(wifi_manager_error_e wifiErr, void * userData); static void _DeactivateCb(wifi_manager_error_e wifiErr, void * userData); static void _ScanToConnectFinishedCb(wifi_manager_error_e wifiErr, void * userData); - static void _ScanFinishedCb(wifi_manager_error_e wifiErr, void * userData); + static void _SpecificScanFinishedCb(wifi_manager_error_e wifiErr, void * userData); + static void _FullScanFinishedCb(wifi_manager_error_e wifiErr, void * userData); static bool _FoundAPOnScanCb(wifi_manager_ap_h ap, void * userData); static bool _FoundAPCb(wifi_manager_ap_h ap, void * userData); static void _ConnectedCb(wifi_manager_error_e wifiErr, void * userData); static bool _ConfigListCb(const wifi_manager_config_h config, void * userData); + static void _UpdateScanCallback(void * scanCbData); static CHIP_ERROR _WiFiInitialize(gpointer userData); static CHIP_ERROR _WiFiActivate(gpointer userData); static CHIP_ERROR _WiFiDeactivate(gpointer userData); - static CHIP_ERROR _WiFiScan(gpointer userData); + static CHIP_ERROR _WiFiSpecificScan(gpointer userData); + static CHIP_ERROR _WiFiFullScan(gpointer userData); static CHIP_ERROR _WiFiScanToConnect(gpointer userData); static CHIP_ERROR _WiFiConnect(wifi_manager_ap_h ap);