From 63e20a86293fbc45f2c1e82379b55361d18ea5a8 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Tue, 6 Feb 2024 03:55:08 +0000 Subject: [PATCH 01/12] Add proto extension to workspace recommendations. --- .vscode/extensions.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index ae6a4510..23e517bf 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,6 +9,7 @@ "ms-vscode-remote.vscode-remote-extensionpack", "coolbear.systemd-unit-file", "redhat.vscode-yaml", - "vadimcn.vscode-lldb" + "vadimcn.vscode-lldb", + "zxh404.vscode-proto3" ] } \ No newline at end of file From 20d92855d78a4316e4d83e97e70bd2038ebdf078 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Tue, 6 Feb 2024 04:04:44 +0000 Subject: [PATCH 02/12] Add API definitions. --- protocol/protos/NetRemoteService.proto | 1 + protocol/protos/NetRemoteWifi.proto | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/protocol/protos/NetRemoteService.proto b/protocol/protos/NetRemoteService.proto index 6b3f8faf..34fe04b4 100644 --- a/protocol/protos/NetRemoteService.proto +++ b/protocol/protos/NetRemoteService.proto @@ -12,4 +12,5 @@ service NetRemote rpc WifiAccessPointEnable (Microsoft.Net.Remote.Wifi.WifiAccessPointEnableRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointEnableResult); rpc WifiAccessPointDisable (Microsoft.Net.Remote.Wifi.WifiAccessPointDisableRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointDisableResult); rpc WifiAccessPointSetPhyType (Microsoft.Net.Remote.Wifi.WifiAccessPointSetPhyTypeRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointSetPhyTypeResult); + rpc WifiAccessPointSetFrequencyBands (Microsoft.Net.Remote.Wifi.WifiAccessPointSetFrequencyBandsRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointSetFrequencyBandsResult); } diff --git a/protocol/protos/NetRemoteWifi.proto b/protocol/protos/NetRemoteWifi.proto index 28913542..8983da92 100644 --- a/protocol/protos/NetRemoteWifi.proto +++ b/protocol/protos/NetRemoteWifi.proto @@ -74,3 +74,15 @@ message WifiAccessPointSetPhyTypeResult string AccessPointId = 1; WifiAccessPointOperationStatus Status = 2; } + +message WifiAccessPointSetFrequencyBandsRequest +{ + string AccessPointId = 1; + repeated Microsoft.Net.Wifi.Dot11FrequencyBand FrequencyBands = 2; +} + +message WifiAccessPointSetFrequencyBandsResult +{ + string AccessPointId = 1; + WifiAccessPointOperationStatus Status = 2; +} From a8ae722d0f965aad53690de2abbc14d8a89af7d9 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 04:04:53 +0000 Subject: [PATCH 03/12] Add IAccessPointController::SetFrequencyBands function. --- .../microsoft/net/wifi/IAccessPointController.hxx | 10 ++++++++++ src/linux/wifi/core/AccessPointControllerLinux.cxx | 7 +++++++ .../net/wifi/AccessPointControllerLinux.hxx | 13 ++++++++++++- .../unit/wifi/helpers/AccessPointControllerTest.cxx | 12 +++++++++++- .../net/wifi/test/AccessPointControllerTest.hxx | 11 +++++++++++ .../microsoft/net/wifi/test/AccessPointTest.hxx | 2 ++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx b/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx index cd2898e6..06ae9b67 100644 --- a/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx +++ b/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx @@ -72,6 +72,16 @@ struct IAccessPointController */ virtual bool SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol ieeeProtocol) = 0; + + /** + * @brief Set the frquency bands the access point should enable. + * + * @param frequencyBands The frequency bands to be set. + * @return true + * @return false + */ + virtual bool + SetFrquencyBands(std::vector frequencyBands) = 0; }; /** diff --git a/src/linux/wifi/core/AccessPointControllerLinux.cxx b/src/linux/wifi/core/AccessPointControllerLinux.cxx index 293c68c4..1a46ca78 100644 --- a/src/linux/wifi/core/AccessPointControllerLinux.cxx +++ b/src/linux/wifi/core/AccessPointControllerLinux.cxx @@ -200,6 +200,13 @@ AccessPointControllerLinux::SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol return isOk && m_hostapd.Reload(); } +bool +AccessPointControllerLinux::SetFrquencyBands([[maybe_unused]] std::vector frequencyBands) +{ + // TODO: + return false; +} + std::unique_ptr AccessPointControllerLinuxFactory::Create(std::string_view interfaceName) { diff --git a/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx b/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx index d34b6404..4bc3a69f 100644 --- a/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx +++ b/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx @@ -3,10 +3,11 @@ #define ACCESS_POINT_CONTROLLER_LINUX_HXX #include +#include #include -#include #include +#include namespace Microsoft::Net::Wifi { @@ -54,6 +55,16 @@ struct AccessPointControllerLinux : virtual bool SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol ieeeProtocol) override; + /** + * @brief Set the frquency bands the access point should enable. + * + * @param frequencyBands The frequency bands to be set. + * @return true + * @return false + */ + virtual bool + SetFrquencyBands(std::vector frequencyBands) override; + private: Wpa::Hostapd m_hostapd; }; diff --git a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx index 847ea421..6b0839fb 100644 --- a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx @@ -42,7 +42,7 @@ AccessPointControllerTest::GetCapabilities() } bool -AccessPointControllerTest::SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol ieeeProtocol) +AccessPointControllerTest::SetProtocol(Ieee80211Protocol ieeeProtocol) { if (AccessPoint == nullptr) { throw std::runtime_error("AccessPointControllerTest::SetIeeeProtocol called with null AccessPoint"); @@ -52,6 +52,16 @@ AccessPointControllerTest::SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol i return true; } +bool +AccessPointControllerTest::SetFrquencyBands(std::vector frequencyBands) +{ + if (AccessPoint == nullptr) { + throw std::runtime_error("AccessPointControllerTest::SetIeeeProtocol called with null AccessPoint"); + } + + AccessPoint->FrequencyBands = std::move(frequencyBands); +} + AccessPointControllerFactoryTest::AccessPointControllerFactoryTest(AccessPointTest *accessPoint) : AccessPoint(accessPoint) {} diff --git a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx index ae0c4062..404284d1 100644 --- a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx +++ b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx @@ -4,6 +4,7 @@ #include #include +#include #include @@ -64,6 +65,16 @@ struct AccessPointControllerTest final : */ virtual bool SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol ieeeProtocol) override; + + /** + * @brief Set the frquency bands the access point should enable. + * + * @param frequencyBands The frequency bands to be set. + * @return true + * @return false + */ + virtual bool + SetFrquencyBands(std::vector frequencyBands) override; }; /** diff --git a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx index 48da4d1a..c96e5568 100644 --- a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx +++ b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -24,6 +25,7 @@ struct AccessPointTest final : Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities Capabilities; bool IsEnabled{ false }; Microsoft::Net::Wifi::Ieee80211Protocol Protocol; + std::vector FrequencyBands; /** * @brief Construct a new AccessPointTest object with the given interface name and default capabilities. From 60c0a600bff105b055202867c3a1cd46109c2ce4 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 04:16:30 +0000 Subject: [PATCH 04/12] Add missing return statement. --- tests/unit/wifi/helpers/AccessPointControllerTest.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx index 6b0839fb..a55ed8e2 100644 --- a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx @@ -60,6 +60,7 @@ AccessPointControllerTest::SetFrquencyBands(std::vector } AccessPoint->FrequencyBands = std::move(frequencyBands); + return true; } AccessPointControllerFactoryTest::AccessPointControllerFactoryTest(AccessPointTest *accessPoint) : From 3e5bc3e11a8278f70cca62f0da82f85eaab5c041 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 04:37:21 +0000 Subject: [PATCH 05/12] Implement AccessPointControllerLinux::SetFrquencyBands. --- .../wifi/core/AccessPointControllerLinux.cxx | 68 +++++++++++++++++-- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/src/linux/wifi/core/AccessPointControllerLinux.cxx b/src/linux/wifi/core/AccessPointControllerLinux.cxx index 1a46ca78..bb7cade0 100644 --- a/src/linux/wifi/core/AccessPointControllerLinux.cxx +++ b/src/linux/wifi/core/AccessPointControllerLinux.cxx @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -10,6 +11,7 @@ #include #include #include +#include using namespace Microsoft::Net::Wifi; @@ -119,6 +121,21 @@ HostapdHwModeToPropertyValue(Wpa::HostapdHwMode hwMode) throw AccessPointControllerException(std::format("Invalid hostapd hw_mode value {}", magic_enum::enum_name(hwMode))); } } + +std::string_view +IeeeFrequencyBandToHostapdBand(Ieee80211FrequencyBand ieeeFrequencyBand) +{ + switch (ieeeFrequencyBand) { + case Ieee80211FrequencyBand::TwoPointFourGHz: + return Wpa::ProtocolHostapd::PropertySetBandValue2G; + case Ieee80211FrequencyBand::FiveGHz: + return Wpa::ProtocolHostapd::PropertySetBandValue5G; + case Ieee80211FrequencyBand::SixGHz: + return Wpa::ProtocolHostapd::PropertySetBandValue6G; + default: + throw AccessPointControllerException(std::format("Invalid ieee80211 frequency band value {}", magic_enum::enum_name(ieeeFrequencyBand))); + } +} } // namespace detail Ieee80211AccessPointCapabilities @@ -196,15 +213,56 @@ AccessPointControllerLinux::SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol throw AccessPointControllerException(std::format("Failed to set Ieee80211 protocol for interface {} ({})", GetInterfaceName(), ex.what())); } - // Reload hostapd conf file. - return isOk && m_hostapd.Reload(); + if (isOk) { + // Reload hostapd configuration. + isOk = m_hostapd.Reload(); + if (!isOk) { + LOGE << std::format("Failed to reload hostapd configuration for interface {}", GetInterfaceName()); + return false; + } + } + + return isOk; } bool -AccessPointControllerLinux::SetFrquencyBands([[maybe_unused]] std::vector frequencyBands) +AccessPointControllerLinux::SetFrquencyBands(std::vector frequencyBands) { - // TODO: - return false; + // Ensure at least one band is requested. + if (std::empty(frequencyBands)) { + LOGW << std::format("No frequency bands specified for interface {}", GetInterfaceName()); + return false; + } + + // Generate the argument for the hostapd "setband" command, which accepts a comma separated list of bands. + std::ostringstream setBandArgumentBuilder; + for (const auto& band : frequencyBands) { + setBandArgumentBuilder << detail::IeeeFrequencyBandToHostapdBand(band) << ','; + } + + std::string setBandArgumentAll = setBandArgumentBuilder.str(); + std::string_view setBandArgument(std::data(setBandArgumentAll), std::size(setBandArgumentAll) - 1); // Remove trailing comma + + bool isOk = false; + try { + // Set the hostapd "setband" property. + isOk = m_hostapd.SetProperty(Wpa::ProtocolHostapd::PropertyNameSetBand, setBandArgument); + if (!isOk) { + LOGE << std::format("Failed to set frequency bands for interface {}", GetInterfaceName()); + return false; + } + + // Reload hostapd configuration to pick up the changes. + isOk = m_hostapd.Reload(); + if (!isOk) { + LOGE << std::format("Failed to reload hostapd configuration for interface {}", GetInterfaceName()); + return false; + } + } catch (const Wpa::HostapdException& ex) { + throw AccessPointControllerException(std::format("Failed to set frequency bands for interface {} ({})", GetInterfaceName(), ex.what())); + } + + return true; } std::unique_ptr From e281233bb7424d010bc5136200a74858635bf34e Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 04:49:44 +0000 Subject: [PATCH 06/12] Implement WifiAccessPointSetFrequencyBands. --- src/common/service/NetRemoteService.cxx | 94 ++++++++++++++++++- .../microsoft/net/remote/NetRemoteService.hxx | 6 ++ .../net/wifi/IAccessPointController.hxx | 2 +- .../wifi/core/AccessPointControllerLinux.cxx | 2 +- .../net/wifi/AccessPointControllerLinux.hxx | 2 +- .../helpers/AccessPointControllerTest.cxx | 2 +- .../wifi/test/AccessPointControllerTest.hxx | 12 +-- 7 files changed, 107 insertions(+), 13 deletions(-) diff --git a/src/common/service/NetRemoteService.cxx b/src/common/service/NetRemoteService.cxx index ab6a7212..7632138f 100644 --- a/src/common/service/NetRemoteService.cxx +++ b/src/common/service/NetRemoteService.cxx @@ -572,8 +572,7 @@ NetRemoteService::WifiAccessPointSetPhyType([[maybe_unused]] ::grpc::ServerConte return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set PHY type for access point {}", request->accesspointid())); } } catch (const AccessPointControllerException& apce) { - LOGE << std::format("Failed to set Ieee80211 protocol for access point {} ({})", request->accesspointid(), apce.what()); - return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set PHY type for access point {}", request->accesspointid())); + return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set PHY type for access point {} ({})", request->accesspointid(), apce.what())); } status.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); @@ -583,8 +582,97 @@ NetRemoteService::WifiAccessPointSetPhyType([[maybe_unused]] ::grpc::ServerConte return grpc::Status::OK; } +using Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest; +using Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult; +using Microsoft::Net::Wifi::Dot11FrequencyBand; + +namespace detail +{ +std::vector +GetFrequencyBands(const WifiAccessPointSetFrequencyBandsRequest& request) +{ + const auto& frequencyBands = request.frequencybands(); + + std::vector bands(static_cast(std::size(frequencyBands))); + std::ranges::transform(frequencyBands, std::begin(bands), [](const auto& frequencyBand) { + return static_cast(frequencyBand); + }); + + return bands; +} + +Ieee80211FrequencyBand +NetRemoteFrequencyBandToIeee80211FrequencyBand(Dot11FrequencyBand dot11FrequencyBand) +{ + switch (dot11FrequencyBand) { + case Dot11FrequencyBand::Dot11FrequencyBand2_4GHz: + return Ieee80211FrequencyBand::TwoPointFourGHz; + case Dot11FrequencyBand::Dot11FrequencyBand5_0GHz: + return Ieee80211FrequencyBand::FiveGHz; + case Dot11FrequencyBand::Dot11FrequencyBand6_0GHz: + return Ieee80211FrequencyBand::SixGHz; + case Dot11FrequencyBand::Dot11FrequencyBandUnknown: + default: + return Ieee80211FrequencyBand::Unknown; + } +} +} // namespace detail + +bool +NetRemoteService::ValidateWifiSetFrequencyBandsRequest(const WifiAccessPointSetFrequencyBandsRequest* request, WifiAccessPointSetFrequencyBandsResult* result) +{ + const auto& frequencyBands = request->frequencybands(); + + if (std::empty(frequencyBands)) { + detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInvalidParameter, "No frequency band provided"); + return false; + } else if (std::ranges::find(frequencyBands, Dot11FrequencyBand::Dot11FrequencyBandUnknown) != std::cend(frequencyBands)) { + detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInvalidParameter, "Invalid frequency band provided"); + return false; + } + + return true; +} + +::grpc::Status +NetRemoteService::WifiAccessPointSetFrequencyBands([[maybe_unused]] ::grpc::ServerContext* context, const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* result) +{ + LOGD << std::format("Received WifiAccessPointSetFrequencyBands request for access point id {}", request->accesspointid()); + + if (!ValidateWifiSetFrequencyBandsRequest(request, result)) { + return grpc::Status::OK; + } + + // Create an AP controller for the requested AP. + auto accessPointController = detail::TryGetAccessPointController(request, result, m_accessPointManager); + if (accessPointController == nullptr) { + return grpc::Status::OK; + } + + const auto& frequencyBands = detail::GetFrequencyBands(*request); + std::vector ieeeFrequencyBands(static_cast(std::size(frequencyBands))); + std::ranges::transform(frequencyBands, std::begin(ieeeFrequencyBands), detail::NetRemoteFrequencyBandToIeee80211FrequencyBand); + + try { + const auto setBandsSucceeded = accessPointController->SetFrequencyBands(std::move(ieeeFrequencyBands)); + if (!setBandsSucceeded) { + return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to set frequency bands for access point {}", request->accesspointid())); + } + } catch (const AccessPointControllerException& apce) { + return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set frequency bands for access point {} ({})", request->accesspointid(), apce.what())); + } + + WifiAccessPointOperationStatus status{}; + status.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); + + result->set_accesspointid(request->accesspointid()); + *result->mutable_status() = std::move(status); + + return grpc::Status::OK; +} + bool -NetRemoteService::ValidateWifiAccessPointEnableRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus& status) +NetRemoteService::ValidateWifiAccessPointEnableRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, WifiAccessPointOperationStatus& status) { // Validate required arguments are present. Detailed argument validation is left to the implementation. diff --git a/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx b/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx index 39c04f6a..fe1e31e7 100644 --- a/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx +++ b/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx @@ -44,10 +44,16 @@ private: virtual ::grpc::Status WifiAccessPointSetPhyType(::grpc::ServerContext* context, const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetPhyTypeRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetPhyTypeResult* response) override; + virtual ::grpc::Status + WifiAccessPointSetFrequencyBands(::grpc::ServerContext* context, const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* response) override; + protected: bool ValidateWifiAccessPointEnableRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus& status); + bool + ValidateWifiSetFrequencyBandsRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* result); + private: std::shared_ptr m_accessPointManager; }; diff --git a/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx b/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx index 06ae9b67..f3e81b83 100644 --- a/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx +++ b/src/common/wifi/core/include/microsoft/net/wifi/IAccessPointController.hxx @@ -81,7 +81,7 @@ struct IAccessPointController * @return false */ virtual bool - SetFrquencyBands(std::vector frequencyBands) = 0; + SetFrequencyBands(std::vector frequencyBands) = 0; }; /** diff --git a/src/linux/wifi/core/AccessPointControllerLinux.cxx b/src/linux/wifi/core/AccessPointControllerLinux.cxx index bb7cade0..cdef5e58 100644 --- a/src/linux/wifi/core/AccessPointControllerLinux.cxx +++ b/src/linux/wifi/core/AccessPointControllerLinux.cxx @@ -226,7 +226,7 @@ AccessPointControllerLinux::SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol } bool -AccessPointControllerLinux::SetFrquencyBands(std::vector frequencyBands) +AccessPointControllerLinux::SetFrequencyBands(std::vector frequencyBands) { // Ensure at least one band is requested. if (std::empty(frequencyBands)) { diff --git a/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx b/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx index 4bc3a69f..ebf11169 100644 --- a/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx +++ b/src/linux/wifi/core/include/microsoft/net/wifi/AccessPointControllerLinux.hxx @@ -63,7 +63,7 @@ struct AccessPointControllerLinux : * @return false */ virtual bool - SetFrquencyBands(std::vector frequencyBands) override; + SetFrequencyBands(std::vector frequencyBands) override; private: Wpa::Hostapd m_hostapd; diff --git a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx index a55ed8e2..a3b08c7c 100644 --- a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx @@ -53,7 +53,7 @@ AccessPointControllerTest::SetProtocol(Ieee80211Protocol ieeeProtocol) } bool -AccessPointControllerTest::SetFrquencyBands(std::vector frequencyBands) +AccessPointControllerTest::SetFrequencyBands(std::vector frequencyBands) { if (AccessPoint == nullptr) { throw std::runtime_error("AccessPointControllerTest::SetIeeeProtocol called with null AccessPoint"); diff --git a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx index 404284d1..8ef57133 100644 --- a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx +++ b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx @@ -58,23 +58,23 @@ struct AccessPointControllerTest final : /** * @brief Set the Ieee80211 protocol of the access point. - * + * * @param ieeeProtocol The Ieee80211 protocol to be set * @return true * @return false - */ + */ virtual bool SetProtocol(Microsoft::Net::Wifi::Ieee80211Protocol ieeeProtocol) override; /** * @brief Set the frquency bands the access point should enable. - * + * * @param frequencyBands The frequency bands to be set. - * @return true - * @return false + * @return true + * @return false */ virtual bool - SetFrquencyBands(std::vector frequencyBands) override; + SetFrequencyBands(std::vector frequencyBands) override; }; /** From 736198f6f337a7994033b606d078656bd2d4da7a Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:18:58 +0000 Subject: [PATCH 07/12] Remove code from bad merge. --- tests/unit/TestNetRemoteServiceClient.cxx | 24 ----------------------- 1 file changed, 24 deletions(-) diff --git a/tests/unit/TestNetRemoteServiceClient.cxx b/tests/unit/TestNetRemoteServiceClient.cxx index 0eae3bd7..e07aaa9b 100644 --- a/tests/unit/TestNetRemoteServiceClient.cxx +++ b/tests/unit/TestNetRemoteServiceClient.cxx @@ -130,7 +130,6 @@ TEST_CASE("WifiAccessPointSetPhyType API", "[basic][rpc][client][remote]") using namespace Microsoft::Net::Wifi; using namespace Microsoft::Net::Wifi::Test; - constexpr auto SsidName{ "TestWifiAccessPointSetPhyType" }; constexpr auto InterfaceName{ "TestWifiAccessPointSetPhyType" }; auto apManagerTest = std::make_shared(); @@ -151,29 +150,6 @@ TEST_CASE("WifiAccessPointSetPhyType API", "[basic][rpc][client][remote]") auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); auto client = NetRemote::NewStub(channel); - Dot11AccessPointConfiguration apConfiguration{}; - apConfiguration.mutable_ssid()->set_name(SsidName); - apConfiguration.set_phytype(Dot11PhyType::Dot11PhyTypeA); - apConfiguration.set_authenticationalgorithm(Dot11AuthenticationAlgorithm::Dot11AuthenticationAlgorithmSharedKey); - apConfiguration.set_ciphersuite(Dot11CipherSuite::Dot11CipherSuiteCcmp256); - apConfiguration.mutable_bands()->Add(Dot11FrequencyBand::Dot11FrequencyBand2_4GHz); - apConfiguration.mutable_bands()->Add(Dot11FrequencyBand::Dot11FrequencyBand5_0GHz); - - WifiAccessPointEnableRequest request{}; - request.set_accesspointid(InterfaceName); - *request.mutable_configuration() = std::move(apConfiguration); - - WifiAccessPointEnableResult result{}; - grpc::ClientContext clientContext{}; - - auto status = client->WifiAccessPointEnable(&clientContext, request, &result); - REQUIRE(status.ok()); - REQUIRE(result.accesspointid() == request.accesspointid()); - REQUIRE(result.has_status()); - REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); - REQUIRE(result.status().message().empty()); - REQUIRE(result.status().has_details() == false); - SECTION("Can be called") { WifiAccessPointSetPhyTypeRequest setPhyTypeRequest{}; From 15d9c1e0769c51bd43fee6a5f7f73c52f4cdd455 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:19:48 +0000 Subject: [PATCH 08/12] Check caps prior to attempting to apply bands. --- src/common/service/NetRemoteService.cxx | 24 ++++++++++++++++++- .../helpers/AccessPointControllerTest.cxx | 11 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/common/service/NetRemoteService.cxx b/src/common/service/NetRemoteService.cxx index 7632138f..3aacd234 100644 --- a/src/common/service/NetRemoteService.cxx +++ b/src/common/service/NetRemoteService.cxx @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -634,11 +635,14 @@ NetRemoteService::ValidateWifiSetFrequencyBandsRequest(const WifiAccessPointSetF return true; } +using Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities; + ::grpc::Status NetRemoteService::WifiAccessPointSetFrequencyBands([[maybe_unused]] ::grpc::ServerContext* context, const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* result) { LOGD << std::format("Received WifiAccessPointSetFrequencyBands request for access point id {}", request->accesspointid()); + // Validate basic parameters in the request. if (!ValidateWifiSetFrequencyBandsRequest(request, result)) { return grpc::Status::OK; } @@ -649,19 +653,37 @@ NetRemoteService::WifiAccessPointSetFrequencyBands([[maybe_unused]] ::grpc::Serv return grpc::Status::OK; } + // Convert dot11 bands to ieee80211 bands. const auto& frequencyBands = detail::GetFrequencyBands(*request); std::vector ieeeFrequencyBands(static_cast(std::size(frequencyBands))); std::ranges::transform(frequencyBands, std::begin(ieeeFrequencyBands), detail::NetRemoteFrequencyBandToIeee80211FrequencyBand); + // Obtain capabilities of the access point. + Ieee80211AccessPointCapabilities accessPointCapabilities{}; + try { + accessPointCapabilities = accessPointController->GetCapabilities(); + } catch (const AccessPointControllerException& apce) { + return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to get capabilities for access point {} ({})", request->accesspointid(), apce.what())); + } + + // Check if requested bands are supported by the AP. + for (const auto& requestedFrequencyBand : ieeeFrequencyBands) { + if (std::ranges::find(accessPointCapabilities.FrequencyBands, requestedFrequencyBand) == std::cend(accessPointCapabilities.FrequencyBands)) { + return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Frequency band {} not supported by access point {}", magic_enum::enum_name(requestedFrequencyBand), request->accesspointid())); + } + } + + // Attempt to set the frequency bands. try { const auto setBandsSucceeded = accessPointController->SetFrequencyBands(std::move(ieeeFrequencyBands)); if (!setBandsSucceeded) { return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to set frequency bands for access point {}", request->accesspointid())); } } catch (const AccessPointControllerException& apce) { - return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set frequency bands for access point {} ({})", request->accesspointid(), apce.what())); + return detail::HandleFailure(request, result, WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to set frequency bands for access point {} ({})", request->accesspointid(), apce.what())); } + // Prepare result with success indication. WifiAccessPointOperationStatus status{}; status.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); diff --git a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx index a3b08c7c..5aa67c3c 100644 --- a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx @@ -1,8 +1,12 @@ +#include +#include #include +#include #include #include +#include using namespace Microsoft::Net::Wifi; using namespace Microsoft::Net::Wifi::Test; @@ -59,6 +63,13 @@ AccessPointControllerTest::SetFrequencyBands(std::vector throw std::runtime_error("AccessPointControllerTest::SetIeeeProtocol called with null AccessPoint"); } + for (const auto &frequencyBandToSet : frequencyBands) { + if (std::ranges::find(AccessPoint->Capabilities.FrequencyBands, frequencyBandToSet) == std::cend(AccessPoint->Capabilities.FrequencyBands)) { + LOGE << std::format("AccessPointControllerTest::SetFrequencyBands called with unsupported frequency band {}", magic_enum::enum_name(frequencyBandToSet)); + return false; + } + } + AccessPoint->FrequencyBands = std::move(frequencyBands); return true; } From 5625fc443c9de8b0202d5acc9156ff9582e68476 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:23:21 +0000 Subject: [PATCH 09/12] Return internal error from failed ap operations that don't throw. --- src/common/service/NetRemoteService.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/service/NetRemoteService.cxx b/src/common/service/NetRemoteService.cxx index 3aacd234..bec62167 100644 --- a/src/common/service/NetRemoteService.cxx +++ b/src/common/service/NetRemoteService.cxx @@ -564,7 +564,7 @@ NetRemoteService::WifiAccessPointSetPhyType([[maybe_unused]] ::grpc::ServerConte } } catch (const AccessPointControllerException& apce) { LOGE << std::format("Failed to get capabilities for access point {} ({})", request->accesspointid(), apce.what()); - return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to get capabilities for access point {}", request->accesspointid())); + return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to get capabilities for access point {}", request->accesspointid())); } // Set the Ieee80211 protocol. @@ -573,7 +573,7 @@ NetRemoteService::WifiAccessPointSetPhyType([[maybe_unused]] ::grpc::ServerConte return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set PHY type for access point {}", request->accesspointid())); } } catch (const AccessPointControllerException& apce) { - return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported, std::format("Failed to set PHY type for access point {} ({})", request->accesspointid(), apce.what())); + return handleFailure(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInternalError, std::format("Failed to set PHY type for access point {} ({})", request->accesspointid(), apce.what())); } status.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); From c50985b0df5d7c28489fa54569ad5bb0ff4760b8 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:23:36 +0000 Subject: [PATCH 10/12] Add tests. --- tests/unit/TestNetRemoteServiceClient.cxx | 147 +++++++++++++++++++++- 1 file changed, 146 insertions(+), 1 deletion(-) diff --git a/tests/unit/TestNetRemoteServiceClient.cxx b/tests/unit/TestNetRemoteServiceClient.cxx index e07aaa9b..34ac2340 100644 --- a/tests/unit/TestNetRemoteServiceClient.cxx +++ b/tests/unit/TestNetRemoteServiceClient.cxx @@ -19,6 +19,7 @@ namespace Microsoft::Net::Remote::Test { constexpr auto AllProtocols = magic_enum::enum_values(); +constexpr auto AllBands = magic_enum::enum_values(); } // namespace Microsoft::Net::Remote::Test using Microsoft::Net::Remote::Test::RemoteServiceAddressHttp; @@ -167,4 +168,148 @@ TEST_CASE("WifiAccessPointSetPhyType API", "[basic][rpc][client][remote]") REQUIRE(setPhyTypeResult.status().message().empty()); REQUIRE(setPhyTypeResult.status().has_details() == false); } -} \ No newline at end of file +} + +TEST_CASE("WifiAccessPointSetFrequencyBands API", "[basic][rpc][client][remote]") +{ + using namespace Microsoft::Net::Remote; + using namespace Microsoft::Net::Remote::Service; + using namespace Microsoft::Net::Remote::Test; + using namespace Microsoft::Net::Remote::Wifi; + using namespace Microsoft::Net::Wifi; + using namespace Microsoft::Net::Wifi::Test; + + constexpr auto InterfaceNameAllBands{ "TestWifiAccessPointSetFrequencyBandsAll" }; + constexpr auto InterfaceNameBand2_4{ "TestWifiAccessPointSetFrequencyBands2_4" }; + constexpr auto InterfaceNameBand5_0{ "TestWifiAccessPointSetFrequencyBands5_0" }; + constexpr auto InterfaceNameBand6_0{ "TestWifiAccessPointSetFrequencyBands6_0" }; + + auto apManagerTest = std::make_shared(); + + Ieee80211AccessPointCapabilities apCapabilitiesBandsAll{ + .FrequencyBands{ std::cbegin(AllBands), std::cend(AllBands) } + }; + Ieee80211AccessPointCapabilities apCapabilitiesBands2_4{ + .FrequencyBands{ Ieee80211FrequencyBand::TwoPointFourGHz } + }; + Ieee80211AccessPointCapabilities apCapabilitiesBands5_0{ + .FrequencyBands{ Ieee80211FrequencyBand::FiveGHz } + }; + Ieee80211AccessPointCapabilities apCapabilitiesBands6_0{ + .FrequencyBands{ Ieee80211FrequencyBand::SixGHz } + }; + + auto apTestBandsAll = std::make_shared(InterfaceNameAllBands, std::move(apCapabilitiesBandsAll)); + auto apTestBands2_4 = std::make_shared(InterfaceNameBand2_4, std::move(apCapabilitiesBands2_4)); + auto apTestBands5_0 = std::make_shared(InterfaceNameBand5_0, std::move(apCapabilitiesBands5_0)); + auto apTestBands6_0 = std::make_shared(InterfaceNameBand6_0, std::move(apCapabilitiesBands6_0)); + + apManagerTest->AddAccessPoint(apTestBandsAll); + apManagerTest->AddAccessPoint(apTestBands2_4); + apManagerTest->AddAccessPoint(apTestBands5_0); + apManagerTest->AddAccessPoint(apTestBands6_0); + + NetRemoteServerConfiguration Configuration{ + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = apManagerTest, + }; + + NetRemoteServer server{ Configuration }; + server.Run(); + + auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); + auto client = NetRemote::NewStub(channel); + + SECTION("Can be called") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameAllBands); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand2_4GHz); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand5_0GHz); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); + } + + SECTION("Empty frequency bands returns an error") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameAllBands); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInvalidParameter); + } + + SECTION("Invalid frequency band returns an error") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameAllBands); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBandUnknown); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInvalidParameter); + } + + SECTION("Invalid frequency band with other valid bands returns an error") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameAllBands); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBandUnknown); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand5_0GHz); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeInvalidParameter); + } + + SECTION("Unsupported frequency band returns an error") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameBand2_4); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand5_0GHz); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeOperationNotSupported); + } + + SECTION("Enabling multiple bands works") + { + WifiAccessPointSetFrequencyBandsRequest request{}; + request.set_accesspointid(InterfaceNameAllBands); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand2_4GHz); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand5_0GHz); + request.mutable_frequencybands()->Add(Dot11FrequencyBand::Dot11FrequencyBand6_0GHz); + + grpc::ClientContext clientContext{}; + WifiAccessPointSetFrequencyBandsResult result{}; + auto status = client->WifiAccessPointSetFrequencyBands(&clientContext, request, &result); + REQUIRE(status.ok()); + REQUIRE(result.accesspointid() == request.accesspointid()); + REQUIRE(result.has_status()); + REQUIRE(result.status().code() == WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded); + } +} From 99ba41b3e2095d5a5a0eed597018445ef3796675 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:46:06 +0000 Subject: [PATCH 11/12] Make validation helpers static. --- src/common/service/NetRemoteService.cxx | 2 ++ .../service/include/microsoft/net/remote/NetRemoteService.hxx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/service/NetRemoteService.cxx b/src/common/service/NetRemoteService.cxx index bec62167..c65acbe3 100644 --- a/src/common/service/NetRemoteService.cxx +++ b/src/common/service/NetRemoteService.cxx @@ -619,6 +619,7 @@ NetRemoteFrequencyBandToIeee80211FrequencyBand(Dot11FrequencyBand dot11Frequency } } // namespace detail +/* static */ bool NetRemoteService::ValidateWifiSetFrequencyBandsRequest(const WifiAccessPointSetFrequencyBandsRequest* request, WifiAccessPointSetFrequencyBandsResult* result) { @@ -693,6 +694,7 @@ NetRemoteService::WifiAccessPointSetFrequencyBands([[maybe_unused]] ::grpc::Serv return grpc::Status::OK; } +/* static */ bool NetRemoteService::ValidateWifiAccessPointEnableRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, WifiAccessPointOperationStatus& status) { diff --git a/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx b/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx index fe1e31e7..5b8fe8b3 100644 --- a/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx +++ b/src/common/service/include/microsoft/net/remote/NetRemoteService.hxx @@ -48,10 +48,10 @@ private: WifiAccessPointSetFrequencyBands(::grpc::ServerContext* context, const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* response) override; protected: - bool + static bool ValidateWifiAccessPointEnableRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus& status); - bool + static bool ValidateWifiSetFrequencyBandsRequest(const ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest* request, ::Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsResult* result); private: From 6769774a63c6542b7fe60ee61934f5d0374ec272 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 7 Feb 2024 17:49:11 +0000 Subject: [PATCH 12/12] Consistent naming. --- src/common/service/NetRemoteService.cxx | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/common/service/NetRemoteService.cxx b/src/common/service/NetRemoteService.cxx index c65acbe3..9a3c79fc 100644 --- a/src/common/service/NetRemoteService.cxx +++ b/src/common/service/NetRemoteService.cxx @@ -196,17 +196,31 @@ Dot11FrequencyBand IeeeDot11FrequencyBandToNetRemoteDot11FrequencyBand(Ieee80211FrequencyBand ieeeDot11FrequencyBand) { switch (ieeeDot11FrequencyBand) { - case Ieee80211FrequencyBand::Unknown: - return Dot11FrequencyBand::Dot11FrequencyBandUnknown; case Ieee80211FrequencyBand::TwoPointFourGHz: return Dot11FrequencyBand::Dot11FrequencyBandTwoPoint4GHz; case Ieee80211FrequencyBand::FiveGHz: return Dot11FrequencyBand::Dot11FrequencyBandFiveGHz; case Ieee80211FrequencyBand::SixGHz: return Dot11FrequencyBand::Dot11FrequencyBandSixGHz; + default: + return Dot11FrequencyBand::Dot11FrequencyBandUnknown; } +} - return Dot11FrequencyBand::Dot11FrequencyBandUnknown; +Ieee80211FrequencyBand +NetRemoteDot11FrequencyBandToIeee80211FrequencyBand(Dot11FrequencyBand dot11FrequencyBand) +{ + switch (dot11FrequencyBand) { + case Dot11FrequencyBand::Dot11FrequencyBand2_4GHz: + return Ieee80211FrequencyBand::TwoPointFourGHz; + case Dot11FrequencyBand::Dot11FrequencyBand5_0GHz: + return Ieee80211FrequencyBand::FiveGHz; + case Dot11FrequencyBand::Dot11FrequencyBand6_0GHz: + return Ieee80211FrequencyBand::SixGHz; + case Dot11FrequencyBand::Dot11FrequencyBandUnknown: + default: + return Ieee80211FrequencyBand::Unknown; + } } using Microsoft::Net::Wifi::Dot11AuthenticationAlgorithm; @@ -602,21 +616,7 @@ GetFrequencyBands(const WifiAccessPointSetFrequencyBandsRequest& request) return bands; } -Ieee80211FrequencyBand -NetRemoteFrequencyBandToIeee80211FrequencyBand(Dot11FrequencyBand dot11FrequencyBand) -{ - switch (dot11FrequencyBand) { - case Dot11FrequencyBand::Dot11FrequencyBand2_4GHz: - return Ieee80211FrequencyBand::TwoPointFourGHz; - case Dot11FrequencyBand::Dot11FrequencyBand5_0GHz: - return Ieee80211FrequencyBand::FiveGHz; - case Dot11FrequencyBand::Dot11FrequencyBand6_0GHz: - return Ieee80211FrequencyBand::SixGHz; - case Dot11FrequencyBand::Dot11FrequencyBandUnknown: - default: - return Ieee80211FrequencyBand::Unknown; - } -} + } // namespace detail /* static */ @@ -657,7 +657,7 @@ NetRemoteService::WifiAccessPointSetFrequencyBands([[maybe_unused]] ::grpc::Serv // Convert dot11 bands to ieee80211 bands. const auto& frequencyBands = detail::GetFrequencyBands(*request); std::vector ieeeFrequencyBands(static_cast(std::size(frequencyBands))); - std::ranges::transform(frequencyBands, std::begin(ieeeFrequencyBands), detail::NetRemoteFrequencyBandToIeee80211FrequencyBand); + std::ranges::transform(frequencyBands, std::begin(ieeeFrequencyBands), detail::NetRemoteDot11FrequencyBandToIeee80211FrequencyBand); // Obtain capabilities of the access point. Ieee80211AccessPointCapabilities accessPointCapabilities{};