@@ -147,7 +147,8 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
147
147
}
148
148
149
149
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
150
- bool ConnectivityManagerImpl::mAssociattionStarted = false ;
150
+
151
+ bool ConnectivityManagerImpl::mAssociationStarted = false ;
151
152
BitFlags<Internal::GenericConnectivityManagerImpl_WiFi<ConnectivityManagerImpl>::ConnectivityFlags>
152
153
ConnectivityManagerImpl::mConnectivityFlag ;
153
154
struct GDBusWpaSupplicant ConnectivityManagerImpl::mWpaSupplicant ;
@@ -157,6 +158,7 @@ ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMod
157
158
{
158
159
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled )
159
160
{
161
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
160
162
mWiFiStationMode = (mWpaSupplicant .iface != nullptr ) ? kWiFiStationMode_Enabled : kWiFiStationMode_Disabled ;
161
163
}
162
164
@@ -397,7 +399,7 @@ void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Inte
397
399
{
398
400
if (g_strcmp0 (value_str, " \' associating\' " ) == 0 )
399
401
{
400
- mAssociattionStarted = true ;
402
+ mAssociationStarted = true ;
401
403
}
402
404
else if (g_strcmp0 (value_str, " \' disconnected\' " ) == 0 )
403
405
{
@@ -409,7 +411,7 @@ void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Inte
409
411
delegate->OnConnectionStatusChanged (static_cast <uint8_t >(ConnectionStatusEnum::kConnected ));
410
412
}
411
413
412
- if (mAssociattionStarted )
414
+ if (mAssociationStarted )
413
415
{
414
416
uint8_t associationFailureCause = static_cast <uint8_t >(AssociationFailureCauseEnum::kUnknown );
415
417
uint16_t status = WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -447,7 +449,7 @@ void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Inte
447
449
448
450
DeviceLayer::SystemLayer ().ScheduleLambda ([]() { ConnectivityMgrImpl ().UpdateNetworkStatus (); });
449
451
450
- mAssociattionStarted = false ;
452
+ mAssociationStarted = false ;
451
453
}
452
454
else if (g_strcmp0 (value_str, " \' associated\' " ) == 0 )
453
455
{
@@ -460,7 +462,7 @@ void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Inte
460
462
}
461
463
else if (g_strcmp0 (value_str, " \' completed\' " ) == 0 )
462
464
{
463
- if (mAssociattionStarted )
465
+ if (mAssociationStarted )
464
466
{
465
467
DeviceLayer::SystemLayer ().ScheduleLambda ([]() {
466
468
if (mpConnectCallback != nullptr )
@@ -471,7 +473,7 @@ void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Inte
471
473
ConnectivityMgrImpl ().PostNetworkConnect ();
472
474
});
473
475
}
474
- mAssociattionStarted = false ;
476
+ mAssociationStarted = false ;
475
477
}
476
478
}
477
479
@@ -723,14 +725,10 @@ void ConnectivityManagerImpl::_OnWpaProxyReady(GObject * source_object, GAsyncRe
723
725
724
726
void ConnectivityManagerImpl::StartWiFiManagement ()
725
727
{
728
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
729
+
726
730
mConnectivityFlag .ClearAll ();
727
- mWpaSupplicant .state = GDBusWpaSupplicant::INIT;
728
- mWpaSupplicant .scanState = GDBusWpaSupplicant::WIFI_SCANNING_IDLE;
729
- mWpaSupplicant .proxy = nullptr ;
730
- mWpaSupplicant .iface = nullptr ;
731
- mWpaSupplicant .bss = nullptr ;
732
- mWpaSupplicant .interfacePath = nullptr ;
733
- mWpaSupplicant .networkPath = nullptr ;
731
+ mWpaSupplicant = GDBusWpaSupplicant{};
734
732
735
733
ChipLogProgress (DeviceLayer, " wpa_supplicant: Start WiFi management" );
736
734
@@ -752,6 +750,8 @@ void ConnectivityManagerImpl::DriveAPState()
752
750
CHIP_ERROR err = CHIP_NO_ERROR;
753
751
WiFiAPState targetState;
754
752
753
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
754
+
755
755
// If the AP interface is not under application control...
756
756
if (mWiFiAPMode != kWiFiAPMode_ApplicationControlled )
757
757
{
@@ -867,6 +867,8 @@ CHIP_ERROR ConnectivityManagerImpl::ConfigureWiFiAP()
867
867
uint16_t discriminator = 0 ;
868
868
char ssid[32 ];
869
869
870
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
871
+
870
872
channel = ConnectivityUtils::MapChannelToFrequency (kWiFi_BAND_2_4_GHZ , CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL);
871
873
872
874
if (GetCommissionableDataProvider ()->GetSetupDiscriminator (discriminator) != CHIP_NO_ERROR)
@@ -961,8 +963,11 @@ ConnectivityManagerImpl::ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credent
961
963
char ssidStr[kMaxWiFiSSIDLength + 1u ] = { 0 };
962
964
char keyStr[kMaxWiFiKeyLength + 1u ] = { 0 };
963
965
966
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
967
+
964
968
VerifyOrReturnError (ssid.size () <= kMaxWiFiSSIDLength , CHIP_ERROR_INVALID_ARGUMENT);
965
969
VerifyOrReturnError (credentials.size () <= kMaxWiFiKeyLength , CHIP_ERROR_INVALID_ARGUMENT);
970
+ VerifyOrReturnError (mWpaSupplicant .iface != nullptr , CHIP_ERROR_INCORRECT_STATE);
966
971
967
972
// There is another ongoing connect request, reject the new one.
968
973
VerifyOrReturnError (mpConnectCallback == nullptr , CHIP_ERROR_INCORRECT_STATE);
@@ -1046,6 +1051,9 @@ void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback(GObject * source_
1046
1051
ConnectivityManagerImpl * this_ = reinterpret_cast <ConnectivityManagerImpl *>(user_data);
1047
1052
std::unique_ptr<GVariant, GVariantDeleter> attachRes;
1048
1053
std::unique_ptr<GError, GErrorDeleter> err;
1054
+
1055
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1056
+
1049
1057
{
1050
1058
gboolean result = wpa_fi_w1_wpa_supplicant1_interface_call_select_network_finish (mWpaSupplicant .iface , res,
1051
1059
&MakeUniquePointerReceiver (err).Get ());
@@ -1132,7 +1140,15 @@ CHIP_ERROR ConnectivityManagerImpl::CommitConfig()
1132
1140
gboolean result;
1133
1141
std::unique_ptr<GError, GErrorDeleter> err;
1134
1142
1135
- ChipLogProgress (DeviceLayer, " wpa_supplicant: connected to network" );
1143
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1144
+
1145
+ if (mWpaSupplicant .state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
1146
+ {
1147
+ ChipLogError (DeviceLayer, " wpa_supplicant: CommitConfig: interface proxy not connected" );
1148
+ return CHIP_ERROR_INCORRECT_STATE;
1149
+ }
1150
+
1151
+ ChipLogProgress (DeviceLayer, " wpa_supplicant: save config" );
1136
1152
1137
1153
result = wpa_fi_w1_wpa_supplicant1_interface_call_save_config_sync (mWpaSupplicant .iface , nullptr ,
1138
1154
&MakeUniquePointerReceiver (err).Get ());
@@ -1196,7 +1212,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(SecurityTypeEnum & secur
1196
1212
1197
1213
if (mWpaSupplicant .state != GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED)
1198
1214
{
1199
- ChipLogError (DeviceLayer, " wpa_supplicant: _GetWiFiSecurityType : interface proxy not connected" );
1215
+ ChipLogError (DeviceLayer, " wpa_supplicant: GetWiFiSecurityType : interface proxy not connected" );
1200
1216
return CHIP_ERROR_INCORRECT_STATE;
1201
1217
}
1202
1218
@@ -1605,6 +1621,8 @@ bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissi
1605
1621
1606
1622
void ConnectivityManagerImpl::_OnWpaInterfaceScanDone (GObject * source_object, GAsyncResult * res, gpointer user_data)
1607
1623
{
1624
+ std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1625
+
1608
1626
ChipLogProgress (DeviceLayer, " wpa_supplicant: network scan done" );
1609
1627
gchar ** bsss = wpa_fi_w1_wpa_supplicant1_interface_dup_bsss (mWpaSupplicant .iface );
1610
1628
gchar ** oldBsss = bsss;
0 commit comments