From 42b4438b0c4ad42bb9c733f5e6569b73115704a6 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 3 Nov 2022 18:04:11 -0700 Subject: [PATCH] Remove unused functions from ConnectivityManagerImpl (#23475) --- examples/all-clusters-app/nxp/mw320/main.cpp | 6 +- .../Linux/ConnectivityManagerImpl.cpp | 109 ------------------ src/platform/Linux/ConnectivityManagerImpl.h | 1 - .../Tizen/ConnectivityManagerImpl.cpp | 5 - src/platform/Tizen/ConnectivityManagerImpl.h | 2 - .../android/ConnectivityManagerImpl.cpp | 9 -- .../android/ConnectivityManagerImpl.h | 2 - .../nxp/mw320/ConnectivityManagerImpl.cpp | 37 ------ .../nxp/mw320/ConnectivityManagerImpl.h | 1 - .../webos/ConnectivityManagerImpl.cpp | 109 ------------------ src/platform/webos/ConnectivityManagerImpl.h | 1 - 11 files changed, 5 insertions(+), 277 deletions(-) diff --git a/examples/all-clusters-app/nxp/mw320/main.cpp b/examples/all-clusters-app/nxp/mw320/main.cpp index d9517faccf0297..b48daf70826f4e 100644 --- a/examples/all-clusters-app/nxp/mw320/main.cpp +++ b/examples/all-clusters-app/nxp/mw320/main.cpp @@ -1272,7 +1272,11 @@ void ShellCLIMain(void * pvParameter) strcpy(def_psk, "nxp12345"); } PRINTF("Connecting to [%s, %s] \r\n", def_ssid, def_psk); - ConnectivityMgrImpl().ProvisionWiFiNetwork(def_ssid, def_psk); + + // TODO: ConnectivityMgrImpl is the platform implementation of ConnectivityMgr layer. + // Application should use the APIs defined src/include/platform to talk to the Matter + // platfrom layer, instead of calling into the functions defined in the platform implemenation. + // ConnectivityMgrImpl().ProvisionWiFiNetwork(def_ssid, def_psk); } // Run CHIP servers diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 449527de2ee611..ca7251d72a28cc 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -1064,115 +1064,6 @@ void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback(GObject * source_ } } -CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) -{ - CHIP_ERROR ret = CHIP_NO_ERROR; - GError * err = nullptr; - GVariant * args = nullptr; - GVariantBuilder builder; - gboolean result; - - // Clean up current network if exists - if (mWpaSupplicant.networkPath) - { - GError * error = nullptr; - - result = wpa_fi_w1_wpa_supplicant1_interface_call_remove_network_sync(mWpaSupplicant.iface, mWpaSupplicant.networkPath, - nullptr, &error); - - if (result) - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: removed network: %s", mWpaSupplicant.networkPath); - g_free(mWpaSupplicant.networkPath); - mWpaSupplicant.networkPath = nullptr; - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to stop AP mode with error: %s", - error ? error->message : "unknown error"); - ret = CHIP_ERROR_INTERNAL; - } - - if (error != nullptr) - g_error_free(error); - - SuccessOrExit(ret); - } - - g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); - g_variant_builder_add(&builder, "{sv}", "ssid", g_variant_new_string(ssid)); - g_variant_builder_add(&builder, "{sv}", "psk", g_variant_new_string(key)); - g_variant_builder_add(&builder, "{sv}", "key_mgmt", g_variant_new_string("WPA-PSK")); - args = g_variant_builder_end(&builder); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_add_network_sync(mWpaSupplicant.iface, args, &mWpaSupplicant.networkPath, - nullptr, &err); - - if (result) - { - GError * error = nullptr; - - ChipLogProgress(DeviceLayer, "wpa_supplicant: added network: SSID: %s: %s", ssid, mWpaSupplicant.networkPath); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_select_network_sync(mWpaSupplicant.iface, mWpaSupplicant.networkPath, - nullptr, &error); - if (result) - { - GError * gerror = nullptr; - - ChipLogProgress(DeviceLayer, "wpa_supplicant: connected to network: SSID: %s", ssid); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_save_config_sync(mWpaSupplicant.iface, nullptr, &gerror); - - if (result) - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: save config succeeded!"); - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to save config: %s", - gerror ? gerror->message : "unknown error"); - } - - if (gerror != nullptr) - g_error_free(gerror); - - PostNetworkConnect(); - - // Return success as long as the device is connected to the network - ret = CHIP_NO_ERROR; - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to connect to network: SSID: %s: %s", ssid, - error ? error->message : "unknown error"); - - ret = CHIP_ERROR_INTERNAL; - } - - if (error != nullptr) - g_error_free(error); - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to add network: %s: %s", ssid, err ? err->message : "unknown error"); - - if (mWpaSupplicant.networkPath) - { - g_object_unref(mWpaSupplicant.networkPath); - mWpaSupplicant.networkPath = nullptr; - } - - ret = CHIP_ERROR_INTERNAL; - } - -exit: - if (err != nullptr) - g_error_free(err); - - return ret; -} - void ConnectivityManagerImpl::PostNetworkConnect() { // Iterate on the network interface to see if we already have beed assigned addresses. diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index 020ba83c32361f..fe1591185af58e 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -121,7 +121,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, public: #if CHIP_DEVICE_CONFIG_ENABLE_WPA - CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); void SetNetworkStatusChangeCallback(NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) { diff --git a/src/platform/Tizen/ConnectivityManagerImpl.cpp b/src/platform/Tizen/ConnectivityManagerImpl.cpp index a539307ab45ac6..66ba3b9098f01a 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.cpp +++ b/src/platform/Tizen/ConnectivityManagerImpl.cpp @@ -220,11 +220,6 @@ void ConnectivityManagerImpl::DeactivateWiFiManager(::chip::System::Layer * aLay { WiFiMgr().Deactivate(); } - -CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) -{ - return WiFiMgr().Connect(ssid, key); -} #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI } // namespace DeviceLayer diff --git a/src/platform/Tizen/ConnectivityManagerImpl.h b/src/platform/Tizen/ConnectivityManagerImpl.h index 7d8e619a367380..4988d5c5b28fdf 100644 --- a/src/platform/Tizen/ConnectivityManagerImpl.h +++ b/src/platform/Tizen/ConnectivityManagerImpl.h @@ -85,8 +85,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, public: #if CHIP_DEVICE_CONFIG_ENABLE_WIFI - CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); - void StartWiFiManagement(void); void StopWiFiManagement(void); #endif diff --git a/src/platform/android/ConnectivityManagerImpl.cpp b/src/platform/android/ConnectivityManagerImpl.cpp index 0c3b94d3a01b1e..390cb5ebb751f9 100644 --- a/src/platform/android/ConnectivityManagerImpl.cpp +++ b/src/platform/android/ConnectivityManagerImpl.cpp @@ -214,14 +214,5 @@ void ConnectivityManagerImpl::DriveAPState(::chip::System::Layer * aLayer, void } #endif // CHIP_DEVICE_CONFIG_ENABLE_WPA -CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) -{ -#if CHIP_DEVICE_CONFIG_ENABLE_WPA - return CHIP_NO_ERROR; -#else - return CHIP_ERROR_NOT_IMPLEMENTED; -#endif -} - } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/android/ConnectivityManagerImpl.h b/src/platform/android/ConnectivityManagerImpl.h index 1d526a0dd09f73..64f46b7394cb3e 100644 --- a/src/platform/android/ConnectivityManagerImpl.h +++ b/src/platform/android/ConnectivityManagerImpl.h @@ -105,8 +105,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, friend class ConnectivityManager; public: - CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); - #if CHIP_DEVICE_CONFIG_ENABLE_WPA void StartWiFiManagement(); #endif diff --git a/src/platform/nxp/mw320/ConnectivityManagerImpl.cpp b/src/platform/nxp/mw320/ConnectivityManagerImpl.cpp index a91e6551b1e932..bf6986f8985ded 100644 --- a/src/platform/nxp/mw320/ConnectivityManagerImpl.cpp +++ b/src/platform/nxp/mw320/ConnectivityManagerImpl.cpp @@ -346,43 +346,6 @@ ConnectivityManagerImpl::ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credent return ret; } -CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) -{ - CHIP_ERROR ret = CHIP_NO_ERROR; - int ret_mcuXpresso; - char arg0[] = "wlan-add"; - char arg1[32]; - char arg2[] = "ssid"; - char arg3[32]; - char arg4[] = "wpa2"; - char arg5[64]; - char * argv[] = { &arg0[0], &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], NULL }; - int argc = (int) (sizeof(argv) / sizeof(argv[0])) - 1; - - sprintf((char *) arg1, "%s", ssid); - sprintf((char *) arg3, "%s", ssid); - sprintf((char *) arg5, "%s", key); - test_wlan_add(argc, &argv[0]); - ret_mcuXpresso = wlan_connect(argv[1]); - if (ret_mcuXpresso == WLAN_ERROR_STATE) - { - ChipLogProgress(DeviceLayer, "Error: connect manager not running"); - ret = CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY; - } - if (ret_mcuXpresso == -WM_E_INVAL) - { - ChipLogProgress(DeviceLayer, "Error: specify a network to connect"); - ret = CHIP_ERROR_INVALID_ARGUMENT; - } - else - { - ChipLogProgress(DeviceLayer, - "Connecting to network...\r\nUse 'wlan-stat' for " - "current connection status."); - } - return ret; -} - bool ConnectivityManagerImpl::_GetBssInfo(const uint8_t sid, NetworkCommissioning::WiFiScanResponse & result) { struct wlan_scan_result res; diff --git a/src/platform/nxp/mw320/ConnectivityManagerImpl.h b/src/platform/nxp/mw320/ConnectivityManagerImpl.h index 2d898f7321bdfb..fa1b2a89150a06 100644 --- a/src/platform/nxp/mw320/ConnectivityManagerImpl.h +++ b/src/platform/nxp/mw320/ConnectivityManagerImpl.h @@ -73,7 +73,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, friend class ConnectivityManager; public: - CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); void SetNetworkStatusChangeCallback(NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) { diff --git a/src/platform/webos/ConnectivityManagerImpl.cpp b/src/platform/webos/ConnectivityManagerImpl.cpp index 627fa14366ce1f..50fcb22fc3de53 100644 --- a/src/platform/webos/ConnectivityManagerImpl.cpp +++ b/src/platform/webos/ConnectivityManagerImpl.cpp @@ -1045,115 +1045,6 @@ void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback(GObject * source_ } } -CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) -{ - CHIP_ERROR ret = CHIP_NO_ERROR; - GError * err = nullptr; - GVariant * args = nullptr; - GVariantBuilder builder; - gboolean result; - - // Clean up current network if exists - if (mWpaSupplicant.networkPath) - { - GError * error = nullptr; - - result = wpa_fi_w1_wpa_supplicant1_interface_call_remove_network_sync(mWpaSupplicant.iface, mWpaSupplicant.networkPath, - nullptr, &error); - - if (result) - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: removed network: %s", mWpaSupplicant.networkPath); - g_free(mWpaSupplicant.networkPath); - mWpaSupplicant.networkPath = nullptr; - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to stop AP mode with error: %s", - error ? error->message : "unknown error"); - ret = CHIP_ERROR_INTERNAL; - } - - if (error != nullptr) - g_error_free(error); - - SuccessOrExit(ret); - } - - g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); - g_variant_builder_add(&builder, "{sv}", "ssid", g_variant_new_string(ssid)); - g_variant_builder_add(&builder, "{sv}", "psk", g_variant_new_string(key)); - g_variant_builder_add(&builder, "{sv}", "key_mgmt", g_variant_new_string("WPA-PSK")); - args = g_variant_builder_end(&builder); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_add_network_sync(mWpaSupplicant.iface, args, &mWpaSupplicant.networkPath, - nullptr, &err); - - if (result) - { - GError * error = nullptr; - - ChipLogProgress(DeviceLayer, "wpa_supplicant: added network: SSID: %s: %s", ssid, mWpaSupplicant.networkPath); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_select_network_sync(mWpaSupplicant.iface, mWpaSupplicant.networkPath, - nullptr, &error); - if (result) - { - GError * gerror = nullptr; - - ChipLogProgress(DeviceLayer, "wpa_supplicant: connected to network: SSID: %s", ssid); - - result = wpa_fi_w1_wpa_supplicant1_interface_call_save_config_sync(mWpaSupplicant.iface, nullptr, &gerror); - - if (result) - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: save config succeeded!"); - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to save config: %s", - gerror ? gerror->message : "unknown error"); - } - - if (gerror != nullptr) - g_error_free(gerror); - - PostNetworkConnect(); - - // Return success as long as the device is connected to the network - ret = CHIP_NO_ERROR; - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to connect to network: SSID: %s: %s", ssid, - error ? error->message : "unknown error"); - - ret = CHIP_ERROR_INTERNAL; - } - - if (error != nullptr) - g_error_free(error); - } - else - { - ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to add network: %s: %s", ssid, err ? err->message : "unknown error"); - - if (mWpaSupplicant.networkPath) - { - g_object_unref(mWpaSupplicant.networkPath); - mWpaSupplicant.networkPath = nullptr; - } - - ret = CHIP_ERROR_INTERNAL; - } - -exit: - if (err != nullptr) - g_error_free(err); - - return ret; -} - void ConnectivityManagerImpl::PostNetworkConnect() { // Iterate on the network interface to see if we already have beed assigned addresses. diff --git a/src/platform/webos/ConnectivityManagerImpl.h b/src/platform/webos/ConnectivityManagerImpl.h index 361ffab71684ff..d790ff667455da 100644 --- a/src/platform/webos/ConnectivityManagerImpl.h +++ b/src/platform/webos/ConnectivityManagerImpl.h @@ -121,7 +121,6 @@ class ConnectivityManagerImpl final : public ConnectivityManager, public: #if CHIP_DEVICE_CONFIG_ENABLE_WPA - CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); void SetNetworkStatusChangeCallback(NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) {