From 9656628583d58abdd67a2eb0f8280f7dbdc8e6de Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 18 Jun 2024 07:43:14 +0000 Subject: [PATCH] Restyled by clang-format --- examples/platform/linux/Options.h | 2 +- src/app/server/Server.cpp | 2 +- src/controller/AutoCommissioner.cpp | 4 +- src/controller/CHIPDeviceController.cpp | 15 +- .../CHIPDeviceControllerSystemState.h | 3 +- src/controller/SetUpCodePairer.h | 4 +- src/include/platform/CHIPDeviceConfig.h | 1 - src/include/platform/CHIPDeviceEvent.h | 2 +- src/include/platform/ConnectivityManager.h | 14 +- .../Linux/ConnectivityManagerImpl.cpp | 168 ++++++++---------- src/platform/Linux/ConnectivityManagerImpl.h | 42 ++--- src/transport/raw/WiFiPAF.cpp | 4 +- src/transport/raw/WiFiPAF.h | 24 ++- 13 files changed, 128 insertions(+), 157 deletions(-) diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index 163ae916353dda..7e3c154e2260d3 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -50,7 +50,7 @@ struct LinuxDeviceOptions bool mWiFi = false; bool mThread = false; #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - bool mWiFiPAF = false; + bool mWiFiPAF = false; #endif #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS uint16_t securedDevicePort = CHIP_PORT; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 9633da87e063ef..bc8627f21f37b1 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -220,7 +220,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) .SetListenPort(mOperationalServicePort) #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - , + , Transport::WiFiPAFListenParameters(DeviceLayer::ConnectivityMgr().GetWiFiPAF()) #endif ); diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index bc7ad342bcb99e..a7f7772a18681b 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -592,10 +592,10 @@ CHIP_ERROR AutoCommissioner::StartCommissioning(DeviceCommissioner * commissione mCommissioneeDeviceProxy = proxy; mNeedsNetworkSetup = (mCommissioneeDeviceProxy->GetSecureSession().Value()->AsSecureSession()->GetPeerAddress().GetTransportType() == - Transport::Type::kBle) + Transport::Type::kBle) #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF || (mCommissioneeDeviceProxy->GetSecureSession().Value()->AsSecureSession()->GetPeerAddress().GetTransportType() == - Transport::Type::kWiFiPAF) + Transport::Type::kWiFiPAF) #endif ; CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 1add5e05858f1f..8e48d3cda8c86f 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -70,7 +70,6 @@ #include #endif - #include #include #include @@ -818,7 +817,8 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF if (params.GetPeerAddress().GetTransportType() == Transport::Type::kWiFiPAF) { - if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != Transport::WiFiPAFBase::State::kConnected) { + if (DeviceLayer::ConnectivityMgr().GetWiFiPAF()->GetWiFiPAFState() != Transport::WiFiPAFBase::State::kConnected) + { ChipLogProgress(Controller, "WiFi-PAF: Subscribing the NAN-USD devices"); static constexpr useconds_t kWiFiStartCheckTimeUsec = WIFI_START_CHECK_TIME_USEC; static constexpr uint8_t kWiFiStartCheckAttempts = WIFI_START_CHECK_ATTEMPTS; @@ -834,15 +834,12 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re usleep(kWiFiStartCheckTimeUsec); } } - if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted()) { + if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted()) + { ChipLogError(NotSpecified, "Wi-Fi Management taking too long to start - device configuration will be reset."); } mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = params; - DeviceLayer::ConnectivityMgr().WiFiPAFConnect( - this, - OnWiFiPAFSubscribeComplete, - OnWiFiPAFSubscribeError - ); + DeviceLayer::ConnectivityMgr().WiFiPAFConnect(this, OnWiFiPAFSubscribeComplete, OnWiFiPAFSubscribeError); ExitNow(CHIP_NO_ERROR); } ChipLogProgress(Controller, "WiFi-PAF: Request to subscrib the NAN-USD device complete"); @@ -925,7 +922,7 @@ void DeviceCommissioner::OnWiFiPAFSubscribeComplete(void * appState) if (nullptr != device && device->GetDeviceTransportType() == Transport::Type::kWiFiPAF) { auto remoteId = device->GetDeviceId(); - auto params = self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF; + auto params = self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF; self->mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = RendezvousParameters(); self->ReleaseCommissioneeDevice(device); diff --git a/src/controller/CHIPDeviceControllerSystemState.h b/src/controller/CHIPDeviceControllerSystemState.h index d6dbec63a269a4..9ae6e377d76c4e 100644 --- a/src/controller/CHIPDeviceControllerSystemState.h +++ b/src/controller/CHIPDeviceControllerSystemState.h @@ -63,7 +63,6 @@ inline constexpr size_t kMaxDeviceTransportBlePendingPackets = 1; inline constexpr size_t kMaxDeviceTransportWiFiPAFPendingPackets = 1; #endif - #if INET_CONFIG_ENABLE_TCP_ENDPOINT inline constexpr size_t kMaxDeviceTransportTcpActiveConnectionCount = CHIP_CONFIG_MAX_ACTIVE_TCP_CONNECTIONS; @@ -106,7 +105,7 @@ struct DeviceControllerSystemStateParams Ble::BleLayer * bleLayer = nullptr; #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - Transport::WiFiPAFLayer *wifipaf_layer = nullptr; + Transport::WiFiPAFLayer * wifipaf_layer = nullptr; #endif Credentials::GroupDataProvider * groupDataProvider = nullptr; Crypto::SessionKeystore * sessionKeystore = nullptr; diff --git a/src/controller/SetUpCodePairer.h b/src/controller/SetUpCodePairer.h index 848fbfbb1400bc..fd9956e1fc0f8b 100644 --- a/src/controller/SetUpCodePairer.h +++ b/src/controller/SetUpCodePairer.h @@ -112,8 +112,8 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate CHIP_ERROR StartDiscoverOverSoftAP(SetupPayload & payload); CHIP_ERROR StopConnectOverSoftAP(); #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - CHIP_ERROR StartDiscoverOverWiFiPAF(SetupPayload & payload); - CHIP_ERROR StopConnectOverWiFiPAF(); + CHIP_ERROR StartDiscoverOverWiFiPAF(SetupPayload & payload); + CHIP_ERROR StopConnectOverWiFiPAF(); #endif // Returns whether we have kicked off a new connection attempt. diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 65e3d6ee83ad22..e7ad2dffe8ed39 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -434,7 +434,6 @@ #define CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF 0 #endif - // -------------------- WiFi AP Configuration -------------------- /** diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 611285fba4d4f3..8d18e742c70729 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -495,7 +495,7 @@ struct ChipDeviceEvent final BLE_CONNECTION_OBJECT ConId; } CHIPoBLENotifyConfirm; #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - struct + struct { chip::System::PacketBuffer * Data; } CHIPoWiFiPAFWriteReceived; diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index bb7be41a5b871c..80513bd1592ddc 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -179,12 +179,10 @@ class ConnectivityManager typedef void (*OnConnectionCompleteFunct)(void * appState); typedef void (*OnConnectionErrorFunct)(void * appState, CHIP_ERROR err); - CHIP_ERROR WiFiPAFConnect(void * appState, - OnConnectionCompleteFunct onSuccess, - OnConnectionErrorFunct onError); + CHIP_ERROR WiFiPAFConnect(void * appState, OnConnectionCompleteFunct onSuccess, OnConnectionErrorFunct onError); CHIP_ERROR WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf); - Transport::WiFiPAFBase * GetWiFiPAF(); - void SetWiFiPAF(Transport::WiFiPAFBase * pmWiFiPAF); + Transport::WiFiPAFBase * GetWiFiPAF(); + void SetWiFiPAF(Transport::WiFiPAFBase * pmWiFiPAF); #endif // WiFi AP methods @@ -428,10 +426,8 @@ inline CHIP_ERROR ConnectivityManager::SetWiFiPAFAdvertisingEnabled(bool val) return static_cast(this)->_SetWiFiPAFAdvertisingEnabled(val); } -inline CHIP_ERROR ConnectivityManager::WiFiPAFConnect( - void * appState, - OnConnectionCompleteFunct onSuccess, - OnConnectionErrorFunct onError) +inline CHIP_ERROR ConnectivityManager::WiFiPAFConnect(void * appState, OnConnectionCompleteFunct onSuccess, + OnConnectionErrorFunct onError) { return static_cast(this)->_WiFiPAFConnect(appState, onSuccess, onError); } diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 312557fdba07ba..76213b7c1b10ea 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -19,9 +19,9 @@ #include #include -#include #include #include +#include #include #include #include @@ -159,12 +159,12 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF switch (event->Type) { - case DeviceEventType::kCHIPoWiFiPAFWriteReceived: - ChipLogProgress(DeviceLayer, "WiFi-PAF: kCHIPoWiFiPAFWriteReceived"); - _GetWiFiPAF()->OnWiFiPAFMessageReceived(System::PacketBufferHandle::Adopt(event->CHIPoWiFiPAFWriteReceived.Data)); - break; + case DeviceEventType::kCHIPoWiFiPAFWriteReceived: + ChipLogProgress(DeviceLayer, "WiFi-PAF: kCHIPoWiFiPAFWriteReceived"); + _GetWiFiPAF()->OnWiFiPAFMessageReceived(System::PacketBufferHandle::Adopt(event->CHIPoWiFiPAFWriteReceived.Data)); + break; } -#endif //CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF } #if CHIP_DEVICE_CONFIG_ENABLE_WPA @@ -811,38 +811,38 @@ bool ConnectivityManagerImpl::IsWiFiManagementStarted() } #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -const char srv_name[]="_matterc._udp"; +const char srv_name[] = "_matterc._udp"; /* NAN-USD Service Protocol Type: ref: Table 58 of Wi-Fi Aware Specificaiton */ -#define MAX_PAF_PUBLISH_SSI_BUFLEN 128 -#define MAX_PAF_TX_SSI_BUFLEN 2048 -#define NAN_SRV_PROTO_MATTER 3 -#define NAM_PUBLISH_PERIOD 300u -#define NAN_PUBLISH_SSI_TAG "ssi=" +#define MAX_PAF_PUBLISH_SSI_BUFLEN 128 +#define MAX_PAF_TX_SSI_BUFLEN 2048 +#define NAN_SRV_PROTO_MATTER 3 +#define NAM_PUBLISH_PERIOD 300u +#define NAN_PUBLISH_SSI_TAG "ssi=" #pragma pack(push, 1) struct PAFPublishSSI { - uint8_t DevOpCode; - uint16_t DevInfo; - uint16_t ProductId; - uint16_t VendorId; + uint8_t DevOpCode; + uint16_t DevInfo; + uint16_t ProductId; + uint16_t VendorId; }; #pragma pack(pop) CHIP_ERROR ConnectivityManagerImpl::_SetWiFiPAFAdvertisingEnabled(bool val) { - CHIP_ERROR ret; + CHIP_ERROR ret; GAutoPtr err; gchar args[MAX_PAF_PUBLISH_SSI_BUFLEN]; gint publish_id; - snprintf(args, sizeof(args), "service_name=%s srv_proto_type=%u ttl=%u ", - srv_name, NAN_SRV_PROTO_MATTER, NAM_PUBLISH_PERIOD); + snprintf(args, sizeof(args), "service_name=%s srv_proto_type=%u ttl=%u ", srv_name, NAN_SRV_PROTO_MATTER, NAM_PUBLISH_PERIOD); struct PAFPublishSSI PafPublish_ssi; - VerifyOrReturnError((strlen(args) + strlen(NAN_PUBLISH_SSI_TAG) + (sizeof(struct PAFPublishSSI)*2) < MAX_PAF_PUBLISH_SSI_BUFLEN), + VerifyOrReturnError( + (strlen(args) + strlen(NAN_PUBLISH_SSI_TAG) + (sizeof(struct PAFPublishSSI) * 2) < MAX_PAF_PUBLISH_SSI_BUFLEN), CHIP_ERROR_BUFFER_TOO_SMALL); PafPublish_ssi.DevOpCode = 0; VerifyOrDie(DeviceLayer::GetCommissionableDataProvider()->GetSetupDiscriminator(PafPublish_ssi.DevInfo) == CHIP_NO_ERROR); @@ -855,23 +855,18 @@ CHIP_ERROR ConnectivityManagerImpl::_SetWiFiPAFAdvertisingEnabled(bool val) PafPublish_ssi.VendorId = 0; } strcat(args, NAN_PUBLISH_SSI_TAG); - ret = chip::Encoding::BytesToUppercaseHexString((uint8_t*)&PafPublish_ssi, sizeof(PafPublish_ssi), &args[strlen(args)], - MAX_PAF_PUBLISH_SSI_BUFLEN-strlen(args)); + ret = chip::Encoding::BytesToUppercaseHexString((uint8_t *) &PafPublish_ssi, sizeof(PafPublish_ssi), &args[strlen(args)], + MAX_PAF_PUBLISH_SSI_BUFLEN - strlen(args)); VerifyOrReturnError(ret == CHIP_NO_ERROR, ret); ChipLogProgress(DeviceLayer, "WiFi-PAF: SetWiFiPAFAdvertisingEnabled(%d)", val); - wpa_fi_w1_wpa_supplicant1_interface_call_nanpublish_sync(mWpaSupplicant.iface, - args, - &publish_id, - nullptr, - &err.GetReceiver()); + wpa_fi_w1_wpa_supplicant1_interface_call_nanpublish_sync(mWpaSupplicant.iface, args, &publish_id, nullptr, &err.GetReceiver()); ChipLogProgress(DeviceLayer, "WiFi-PAF: publish_id: %d ! ", publish_id); - g_signal_connect( - mWpaSupplicant.iface, "nan-receive", - G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * obj, ConnectivityManagerImpl * self) { - return self->OnNanReceive(obj); - }), - this); + g_signal_connect(mWpaSupplicant.iface, "nan-receive", + G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * obj, ConnectivityManagerImpl * self) { + return self->OnNanReceive(obj); + }), + this); return CHIP_NO_ERROR; } @@ -1320,9 +1315,9 @@ CHIP_ERROR ConnectivityManagerImpl::ConnectWiFiNetworkWithPDCAsync( /* NAN-USD Service Protocol Type: ref: Table 58 of Wi-Fi Aware Specificaiton */ -#define MAX_PAF_SUBSCRIBE_SSI_BUFLEN 128 -#define NAN_SRV_PROTO_MATTER 3 -#define NAM_SUBSCRIBE_PERIOD 30u +#define MAX_PAF_SUBSCRIBE_SSI_BUFLEN 128 +#define NAN_SRV_PROTO_MATTER 3 +#define NAM_SUBSCRIBE_PERIOD 30u void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * discov_info) { ChipLogProgress(Controller, "WiFi-PAF: OnDiscoveryResult, %d", success); @@ -1337,16 +1332,16 @@ void ConnectivityManagerImpl::OnDiscoveryResult(gboolean success, GVariant * dis size_t bufferLen; auto buffer = g_variant_get_fixed_array(dataValue.get(), &bufferLen, sizeof(uint8_t)); - if (((struct wpa_dbus_discov_info*)buffer)->subscribe_id == mpaf_info.subscribe_id) + if (((struct wpa_dbus_discov_info *) buffer)->subscribe_id == mpaf_info.subscribe_id) { return; } memcpy(&mpaf_info, buffer, sizeof(struct wpa_dbus_discov_info)); ChipLogProgress(DeviceLayer, "WiFi-PAF: subscribe_id: %u", mpaf_info.subscribe_id); ChipLogProgress(DeviceLayer, "WiFi-PAF: peer_publish_id: %u", mpaf_info.peer_publish_id); - ChipLogProgress(DeviceLayer, "WiFi-PAF: peer_addr: [%02x:%02x:%02x:%02x:%02x:%02x]", - mpaf_info.peer_addr[0], mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], - mpaf_info.peer_addr[3], mpaf_info.peer_addr[4], mpaf_info.peer_addr[5]); + ChipLogProgress(DeviceLayer, "WiFi-PAF: peer_addr: [%02x:%02x:%02x:%02x:%02x:%02x]", mpaf_info.peer_addr[0], + mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], mpaf_info.peer_addr[3], mpaf_info.peer_addr[4], + mpaf_info.peer_addr[5]); if (mOnPafSubscribeComplete != nullptr) { mOnPafSubscribeComplete(mAppState); @@ -1364,16 +1359,17 @@ void ConnectivityManagerImpl::OnNanReceive(GVariant * obj) return; } { - GAutoPtr dataValue(g_variant_lookup_value(obj, "nanrx_info", G_VARIANT_TYPE_BYTESTRING)); - size_t bufferLen; - auto buffer = g_variant_get_fixed_array(dataValue.get(), &bufferLen, sizeof(uint8_t)); + GAutoPtr dataValue(g_variant_lookup_value(obj, "nanrx_info", G_VARIANT_TYPE_BYTESTRING)); + size_t bufferLen; + auto buffer = g_variant_get_fixed_array(dataValue.get(), &bufferLen, sizeof(uint8_t)); - memcpy(&mpaf_nanrx_info, buffer, sizeof(struct wpa_dbus_nanrx_info)); - mpaf_info.subscribe_id = mpaf_nanrx_info.id; - mpaf_info.peer_publish_id = mpaf_nanrx_info.peer_id; - memcpy(mpaf_info.peer_addr, mpaf_nanrx_info.peer_addr, 6); + memcpy(&mpaf_nanrx_info, buffer, sizeof(struct wpa_dbus_nanrx_info)); + mpaf_info.subscribe_id = mpaf_nanrx_info.id; + mpaf_info.peer_publish_id = mpaf_nanrx_info.peer_id; + memcpy(mpaf_info.peer_addr, mpaf_nanrx_info.peer_addr, 6); } - if (mpaf_nanrx_info.ssi_len > 0) { + if (mpaf_nanrx_info.ssi_len > 0) + { GAutoPtr dataValue(g_variant_lookup_value(obj, "ssi", G_VARIANT_TYPE_BYTESTRING)); size_t bufferLen; System::PacketBufferHandle buf; @@ -1384,45 +1380,38 @@ void ConnectivityManagerImpl::OnNanReceive(GVariant * obj) // Post an event to the Chip queue to deliver the data into the Chip stack. { ChipDeviceEvent event; - event.Type = DeviceEventType::kCHIPoWiFiPAFWriteReceived; - event.CHIPoWiFiPAFWriteReceived.Data = std::move(buf).UnsafeRelease(); + event.Type = DeviceEventType::kCHIPoWiFiPAFWriteReceived; + event.CHIPoWiFiPAFWriteReceived.Data = std::move(buf).UnsafeRelease(); PlatformMgr().PostEventOrDie(&event); } - } else { + } + else + { ChipLogProgress(DeviceLayer, "WiFi-PAF: Skip, ssi length = %u", mpaf_nanrx_info.ssi_len); } return; } - -CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFConnect(void *appState, - OnConnectionCompleteFunct onSuccess, - OnConnectionErrorFunct onError) +CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFConnect(void * appState, OnConnectionCompleteFunct onSuccess, + OnConnectionErrorFunct onError) { ChipLogProgress(Controller, "WiFi-PAF: Try to subscribe the NAN-USD devices"); gchar args[MAX_PAF_SUBSCRIBE_SSI_BUFLEN]; - snprintf(args, sizeof(args), "service_name=%s srv_proto_type=%u ttl=%u ", - srv_name, NAN_SRV_PROTO_MATTER, NAM_SUBSCRIBE_PERIOD); + snprintf(args, sizeof(args), "service_name=%s srv_proto_type=%u ttl=%u ", srv_name, NAN_SRV_PROTO_MATTER, NAM_SUBSCRIBE_PERIOD); mAppState = appState; GAutoPtr err; - wpa_fi_w1_wpa_supplicant1_interface_call_nansubscribe(mWpaSupplicant.iface, - args, - nullptr, + wpa_fi_w1_wpa_supplicant1_interface_call_nansubscribe( + mWpaSupplicant.iface, args, nullptr, reinterpret_cast( - +[](GObject * sourceObject_, GAsyncResult * res_, ConnectivityManagerImpl * self) { - return ; - }), + +[](GObject * sourceObject_, GAsyncResult * res_, ConnectivityManagerImpl * self) { return; }), &err.GetReceiver()); mOnPafSubscribeComplete = onSuccess; - g_signal_connect( - mWpaSupplicant.iface, "discovery-result", - G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, gboolean success, GVariant * obj, ConnectivityManagerImpl * self) { - return self->OnDiscoveryResult(success, obj); - }), - this); - + g_signal_connect(mWpaSupplicant.iface, "discovery-result", + G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, gboolean success, GVariant * obj, + ConnectivityManagerImpl * self) { return self->OnDiscoveryResult(success, obj); }), + this); return CHIP_NO_ERROR; } @@ -1432,7 +1421,8 @@ CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFSend(System::PacketBufferHandle && m ChipLogProgress(Controller, "WiFi-PAF: sending PAF Follow-up packets, (%lu)", msgBuf->DataLength()); CHIP_ERROR ret = CHIP_NO_ERROR; - if (msgBuf.IsNull()) { + if (msgBuf.IsNull()) + { ChipLogError(Controller, "WiFi-PAF: Invalid Packet (%lu)", msgBuf->DataLength()); return CHIP_ERROR_INVALID_ARGUMENT; } @@ -1456,39 +1446,31 @@ CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFSend(System::PacketBufferHandle && m GAutoPtr err; gchar args[MAX_PAF_TX_SSI_BUFLEN]; - snprintf(args, sizeof(args), "handle=%u req_instance_id=%u address=%02x:%02x:%02x:%02x:%02x:%02x ssi=", - mpaf_info.subscribe_id, mpaf_info.peer_publish_id, - mpaf_info.peer_addr[0], mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], - mpaf_info.peer_addr[3], mpaf_info.peer_addr[4], mpaf_info.peer_addr[5]); + snprintf(args, sizeof(args), "handle=%u req_instance_id=%u address=%02x:%02x:%02x:%02x:%02x:%02x ssi=", mpaf_info.subscribe_id, + mpaf_info.peer_publish_id, mpaf_info.peer_addr[0], mpaf_info.peer_addr[1], mpaf_info.peer_addr[2], + mpaf_info.peer_addr[3], mpaf_info.peer_addr[4], mpaf_info.peer_addr[5]); - ChipLogProgress(Controller, "===> %s(), (%lu, %u)", __FUNCTION__, - (strlen(args) + msgBuf->DataLength()), - MAX_PAF_TX_SSI_BUFLEN) - VerifyOrReturnError((strlen(args) + msgBuf->DataLength() < MAX_PAF_TX_SSI_BUFLEN), - CHIP_ERROR_BUFFER_TOO_SMALL); + ChipLogProgress(Controller, "===> %s(), (%lu, %u)", __FUNCTION__, (strlen(args) + msgBuf->DataLength()), MAX_PAF_TX_SSI_BUFLEN) + VerifyOrReturnError((strlen(args) + msgBuf->DataLength() < MAX_PAF_TX_SSI_BUFLEN), CHIP_ERROR_BUFFER_TOO_SMALL); ret = chip::Encoding::BytesToUppercaseHexString(msgBuf->Start(), msgBuf->DataLength(), &args[strlen(args)], - MAX_PAF_TX_SSI_BUFLEN-strlen(args)); + MAX_PAF_TX_SSI_BUFLEN - strlen(args)); VerifyOrReturnError(ret == CHIP_NO_ERROR, ret); ChipLogProgress(DeviceLayer, "WiFi-PAF: ssi: [%s]", args); - wpa_fi_w1_wpa_supplicant1_interface_call_nantransmit_sync(mWpaSupplicant.iface, - args, - nullptr, - &err.GetReceiver()); + wpa_fi_w1_wpa_supplicant1_interface_call_nantransmit_sync(mWpaSupplicant.iface, args, nullptr, &err.GetReceiver()); - g_signal_connect( - mWpaSupplicant.iface, "nan-receive", - G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * obj, ConnectivityManagerImpl * self) { - return self->OnNanReceive(obj); - }), - this); + g_signal_connect(mWpaSupplicant.iface, "nan-receive", + G_CALLBACK(+[](WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * obj, ConnectivityManagerImpl * self) { + return self->OnNanReceive(obj); + }), + this); ChipLogProgress(Controller, "WiFi-PAF: Outbound message (%lu) done", msgBuf->DataLength()); return ret; } -#endif //CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback(GObject * sourceObject, GAsyncResult * res) { @@ -1734,7 +1716,7 @@ CHIP_ERROR ConnectivityManagerImpl::GetConfiguredNetwork(NetworkCommissioning::N const gchar * networkPath = wpa_fi_w1_wpa_supplicant1_interface_get_current_network(mWpaSupplicant.iface); // wpa_supplicant DBus API: if network path of current network is "/", means no networks is currently selected. - if ((networkPath==nullptr) || (strcmp(networkPath, "/") == 0)) + if ((networkPath == nullptr) || (strcmp(networkPath, "/") == 0)) { return CHIP_ERROR_KEY_NOT_FOUND; } diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index 54f29170d20d21..b128b90e34d5fd 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -141,15 +141,13 @@ class ConnectivityManagerImpl final : public ConnectivityManager, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * connectCallback); #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_PDC #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - CHIP_ERROR _WiFiPAFConnect(void * appState, - OnConnectionCompleteFunct onSuccess, - OnConnectionErrorFunct onError); + CHIP_ERROR _WiFiPAFConnect(void * appState, OnConnectionCompleteFunct onSuccess, OnConnectionErrorFunct onError); void OnDiscoveryResult(gboolean success, GVariant * obj); - void OnNanReceive(GVariant * obj); + void OnNanReceive(GVariant * obj); - CHIP_ERROR _WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf); - Transport::WiFiPAFBase * _GetWiFiPAF(); - void _SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF); + CHIP_ERROR _WiFiPAFSend(chip::System::PacketBufferHandle && msgBuf); + Transport::WiFiPAFBase * _GetWiFiPAF(); + void _SetWiFiPAF(Transport::WiFiPAFBase * pWiFiPAF); #endif void PostNetworkConnect(); @@ -230,23 +228,25 @@ class ConnectivityManagerImpl final : public ConnectivityManager, void _OnWpaInterfaceProxyReady(GObject * sourceObject, GAsyncResult * res); void _OnWpaBssProxyReady(GObject * sourceObject, GAsyncResult * res); #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF - struct wpa_dbus_discov_info { - uint32_t subscribe_id; - uint32_t peer_publish_id; - uint8_t peer_addr[6]; - }; - struct wpa_dbus_discov_info mpaf_info; - struct wpa_dbus_nanrx_info { - uint32_t id; - uint32_t peer_id; - uint8_t peer_addr[6]; - uint32_t ssi_len; - }; - struct wpa_dbus_nanrx_info mpaf_nanrx_info; + struct wpa_dbus_discov_info + { + uint32_t subscribe_id; + uint32_t peer_publish_id; + uint8_t peer_addr[6]; + }; + struct wpa_dbus_discov_info mpaf_info; + struct wpa_dbus_nanrx_info + { + uint32_t id; + uint32_t peer_id; + uint8_t peer_addr[6]; + uint32_t ssi_len; + }; + struct wpa_dbus_nanrx_info mpaf_nanrx_info; OnConnectionCompleteFunct mOnPafSubscribeComplete; Transport::WiFiPAFBase * pmWiFiPAF; - void * mAppState; + void * mAppState; CHIP_ERROR _SetWiFiPAFAdvertisingEnabled(bool val); #endif diff --git a/src/transport/raw/WiFiPAF.cpp b/src/transport/raw/WiFiPAF.cpp index 53729b7dce9ff7..4d0607b3b4e03d 100644 --- a/src/transport/raw/WiFiPAF.cpp +++ b/src/transport/raw/WiFiPAF.cpp @@ -22,13 +22,13 @@ * */ -//#include +// #include #include #include #include -#include #include +#include #include diff --git a/src/transport/raw/WiFiPAF.h b/src/transport/raw/WiFiPAF.h index 2f4e774e179173..7e49c09fe81b96 100644 --- a/src/transport/raw/WiFiPAF.h +++ b/src/transport/raw/WiFiPAF.h @@ -37,11 +37,10 @@ namespace Transport { class WiFiPAFLayer { public: - WiFiPAFLayer() = default; + WiFiPAFLayer() = default; }; class WiFiPAFListenParameters; - /** * Implements a transport using Wi-Fi-PAF */ @@ -58,7 +57,7 @@ class DLL_EXPORT WiFiPAFBase : public Base kInitialized = 1, /**< State after class is connected and ready. */ kConnected = 2, /**< Endpoint connected. */ }; - WiFiPAFBase()=default; + WiFiPAFBase() = default; WiFiPAFBase(System::PacketBufferHandle * packetBuffers, size_t packetBuffersSize) : mPendingPackets(packetBuffers), mPendingPacketsSize(packetBuffersSize) {} @@ -75,18 +74,18 @@ class DLL_EXPORT WiFiPAFBase : public Base { return (mState != State::kNotReady) && (address.GetTransportType() == Type::kWiFiPAF); } - void OnWiFiPAFMessageReceived(System::PacketBufferHandle && buffer); - void SetWiFiPAFState(State state) { mState = state; }; - State GetWiFiPAFState() { return mState; }; + void OnWiFiPAFMessageReceived(System::PacketBufferHandle && buffer); + void SetWiFiPAFState(State state) { mState = state; }; + State GetWiFiPAFState() { return mState; }; private: void ClearState(); - /** + /** * Sends the specified message once a connection has been established. * @param msg - what buffer to send once a connection has been established. */ CHIP_ERROR SendAfterConnect(System::PacketBufferHandle && msg); - State mState = State::kNotReady; + State mState = State::kNotReady; System::PacketBufferHandle * mPendingPackets; size_t mPendingPacketsSize; @@ -102,16 +101,15 @@ class WiFiPAF : public WiFiPAFBase System::PacketBufferHandle mPendingPackets[kPendingPacketSize]; }; - /** Defines parameters for setting up the Wi-Fi PAF transport */ class WiFiPAFListenParameters { public: - WiFiPAFListenParameters() = default; - explicit WiFiPAFListenParameters(WiFiPAFBase * layer) : mWiFiPAF(layer) {} -private: - WiFiPAFBase * mWiFiPAF; + WiFiPAFListenParameters() = default; + explicit WiFiPAFListenParameters(WiFiPAFBase * layer) : mWiFiPAF(layer) {} +private: + WiFiPAFBase * mWiFiPAF; }; } // namespace Transport