Skip to content

Commit

Permalink
Remove unused functions from ConnectivityManagerImpl (#23475)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Oct 12, 2023
1 parent a0a825d commit 9294920
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 277 deletions.
6 changes: 5 additions & 1 deletion examples/all-clusters-app/nxp/mw320/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
109 changes: 0 additions & 109 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/platform/Linux/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 0 additions & 5 deletions src/platform/Tizen/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/platform/Tizen/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/platform/android/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/platform/android/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 0 additions & 37 deletions src/platform/nxp/mw320/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/platform/nxp/mw320/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
109 changes: 0 additions & 109 deletions src/platform/webos/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/platform/webos/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 9294920

Please sign in to comment.