58
58
#endif
59
59
60
60
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
61
- #include < platform/Linux/GlibTypeDeleter .h>
61
+ #include < platform/GLibTypeDeleter .h>
62
62
#include < platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
63
63
#endif
64
64
@@ -76,6 +76,23 @@ using namespace ::chip::app::Clusters::WiFiNetworkDiagnostics;
76
76
using namespace ::chip::DeviceLayer::NetworkCommissioning;
77
77
78
78
namespace chip {
79
+
80
+ #if CHIP_DEVICE_CONFIG_ENABLE_WPA
81
+
82
+ template <>
83
+ struct GAutoPtrDeleter <WpaFiW1Wpa_supplicant1BSS>
84
+ {
85
+ using deleter = GObjectDeleter;
86
+ };
87
+
88
+ template <>
89
+ struct GAutoPtrDeleter <WpaFiW1Wpa_supplicant1Network>
90
+ {
91
+ using deleter = GObjectDeleter;
92
+ };
93
+
94
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
95
+
79
96
namespace DeviceLayer {
80
97
81
98
ConnectivityManagerImpl ConnectivityManagerImpl::sInstance ;
@@ -1070,8 +1087,7 @@ ConnectivityManagerImpl::ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credent
1070
1087
void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback (GObject * source_object, GAsyncResult * res, gpointer user_data)
1071
1088
{
1072
1089
ConnectivityManagerImpl * this_ = reinterpret_cast <ConnectivityManagerImpl *>(user_data);
1073
- std::unique_ptr<GVariant, GVariantDeleter> attachRes;
1074
- std::unique_ptr<GError, GErrorDeleter> err;
1090
+ GAutoPtr<GError> err;
1075
1091
1076
1092
std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1077
1093
@@ -1159,7 +1175,7 @@ void ConnectivityManagerImpl::PostNetworkConnect()
1159
1175
CHIP_ERROR ConnectivityManagerImpl::CommitConfig ()
1160
1176
{
1161
1177
gboolean result;
1162
- std::unique_ptr <GError, GErrorDeleter > err;
1178
+ GAutoPtr <GError> err;
1163
1179
1164
1180
std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1165
1181
@@ -1290,7 +1306,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetWiFiVersion(WiFiVersionEnum & wiFiVersion
1290
1306
int32_t ConnectivityManagerImpl::GetDisconnectReason ()
1291
1307
{
1292
1308
std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1293
- std::unique_ptr <GError, GErrorDeleter > err;
1309
+ GAutoPtr <GError> err;
1294
1310
1295
1311
gint errorValue = wpa_fi_w1_wpa_supplicant1_interface_get_disconnect_reason (mWpaSupplicant .iface );
1296
1312
// wpa_supplicant DBus API: DisconnectReason: The most recent IEEE 802.11 reason code for disconnect. Negative value
@@ -1306,7 +1322,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetConfiguredNetwork(NetworkCommissioning::N
1306
1322
// with the proxy object.
1307
1323
1308
1324
std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1309
- std::unique_ptr <GError, GErrorDeleter > err;
1325
+ GAutoPtr <GError> err;
1310
1326
1311
1327
if (mWpaSupplicant .iface == nullptr )
1312
1328
{
@@ -1322,20 +1338,19 @@ CHIP_ERROR ConnectivityManagerImpl::GetConfiguredNetwork(NetworkCommissioning::N
1322
1338
return CHIP_ERROR_KEY_NOT_FOUND;
1323
1339
}
1324
1340
1325
- std::unique_ptr<WpaFiW1Wpa_supplicant1Network, GObjectDeleter> networkInfo (
1326
- wpa_fi_w1_wpa_supplicant1_network_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
1327
- kWpaSupplicantServiceName , networkPath, nullptr ,
1328
- &MakeUniquePointerReceiver (err).Get ()));
1341
+ GAutoPtr<WpaFiW1Wpa_supplicant1Network> networkInfo (wpa_fi_w1_wpa_supplicant1_network_proxy_new_for_bus_sync (
1342
+ G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName , networkPath, nullptr ,
1343
+ &MakeUniquePointerReceiver (err).Get ()));
1329
1344
if (networkInfo == nullptr )
1330
1345
{
1331
1346
return CHIP_ERROR_INTERNAL;
1332
1347
}
1333
1348
1334
1349
network.connected = wpa_fi_w1_wpa_supplicant1_network_get_enabled (networkInfo.get ());
1335
1350
GVariant * properties = wpa_fi_w1_wpa_supplicant1_network_get_properties (networkInfo.get ());
1336
- GVariant * ssid = g_variant_lookup_value (properties, " ssid" , nullptr );
1351
+ GAutoPtr< GVariant> ssid ( g_variant_lookup_value (properties, " ssid" , nullptr ) );
1337
1352
gsize length;
1338
- const gchar * ssidStr = g_variant_get_string (ssid, &length);
1353
+ const gchar * ssidStr = g_variant_get_string (ssid. get () , &length);
1339
1354
// TODO: wpa_supplicant will return ssid with quotes! We should have a better way to get the actual ssid in bytes.
1340
1355
gsize length_actual = length - 2 ;
1341
1356
VerifyOrReturnError (length_actual <= sizeof (network.networkID ), CHIP_ERROR_INTERNAL);
@@ -1350,7 +1365,7 @@ CHIP_ERROR ConnectivityManagerImpl::StopAutoScan()
1350
1365
std::lock_guard<std::mutex> lock (mWpaSupplicantMutex );
1351
1366
VerifyOrReturnError (mWpaSupplicant .iface != nullptr , CHIP_ERROR_INCORRECT_STATE);
1352
1367
1353
- std::unique_ptr <GError, GErrorDeleter > err;
1368
+ GAutoPtr <GError> err;
1354
1369
gboolean result;
1355
1370
1356
1371
ChipLogDetail (DeviceLayer, " wpa_supplicant: disabling auto scan" );
@@ -1407,6 +1422,7 @@ CHIP_ERROR ConnectivityManagerImpl::StartWiFiScan(ByteSpan ssid, WiFiDriver::Sca
1407
1422
}
1408
1423
1409
1424
namespace {
1425
+
1410
1426
// wpa_supplicant's scan results don't contains the channel infomation, so we need this lookup table for resolving the band and
1411
1427
// channel infomation.
1412
1428
std::pair<WiFiBand, uint16_t > GetBandAndChannelFromFrequency (uint32_t freq)
@@ -1505,6 +1521,7 @@ std::pair<WiFiBand, uint16_t> GetBandAndChannelFromFrequency(uint32_t freq)
1505
1521
}
1506
1522
return ret;
1507
1523
}
1524
+
1508
1525
} // namespace
1509
1526
1510
1527
bool ConnectivityManagerImpl::_GetBssInfo (const gchar * bssPath, NetworkCommissioning::WiFiScanResponse & result)
@@ -1514,8 +1531,8 @@ bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissi
1514
1531
// completed before this function returns. Also, no external callbacks are registered
1515
1532
// with the proxy object.
1516
1533
1517
- std::unique_ptr <GError, GErrorDeleter > err;
1518
- std::unique_ptr <WpaFiW1Wpa_supplicant1BSS, GObjectDeleter > bss (
1534
+ GAutoPtr <GError> err;
1535
+ GAutoPtr <WpaFiW1Wpa_supplicant1BSS> bss (
1519
1536
wpa_fi_w1_wpa_supplicant1_bss_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName ,
1520
1537
bssPath, nullptr , &MakeUniquePointerReceiver (err).Get ()));
1521
1538
@@ -1526,8 +1543,8 @@ bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissi
1526
1543
1527
1544
WpaFiW1Wpa_supplicant1BSSProxy * bssProxy = WPA_FI_W1_WPA_SUPPLICANT1_BSS_PROXY (bss.get ());
1528
1545
1529
- std::unique_ptr <GVariant, GVariantDeleter > ssid (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (bssProxy), " SSID" ));
1530
- std::unique_ptr <GVariant, GVariantDeleter > bssid (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (bssProxy), " BSSID" ));
1546
+ GAutoPtr <GVariant> ssid (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (bssProxy), " SSID" ));
1547
+ GAutoPtr <GVariant> bssid (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (bssProxy), " BSSID" ));
1531
1548
1532
1549
// Network scan is performed in the background, so the BSS
1533
1550
// may be gone when we try to get the properties.
@@ -1635,8 +1652,8 @@ bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissi
1635
1652
return res;
1636
1653
};
1637
1654
auto GetNetworkSecurityType = [IsNetworkWPAPSK, IsNetworkWPA2PSK](WpaFiW1Wpa_supplicant1BSSProxy * proxy) -> uint8_t {
1638
- std::unique_ptr <GVariant, GVariantDeleter > wpa (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), " WPA" ));
1639
- std::unique_ptr <GVariant, GVariantDeleter > rsn (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), " RSN" ));
1655
+ GAutoPtr <GVariant> wpa (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), " WPA" ));
1656
+ GAutoPtr <GVariant> rsn (g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), " RSN" ));
1640
1657
1641
1658
uint8_t res = IsNetworkWPAPSK (wpa.get ()) | IsNetworkWPA2PSK (rsn.get ());
1642
1659
if (res == 0 )
0 commit comments