From 6b1905a6c9b96132d23ac9d3b865df5ec5c7165c Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:14:16 -0700 Subject: [PATCH 1/8] Add "GET" command object. --- linux/wpa-controller/CMakeLists.txt | 4 +++ linux/wpa-controller/WpaCommandGet.cxx | 13 +++++++++ .../include/Wpa/WpaCommandGet.hxx | 29 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 linux/wpa-controller/WpaCommandGet.cxx create mode 100644 linux/wpa-controller/include/Wpa/WpaCommandGet.hxx diff --git a/linux/wpa-controller/CMakeLists.txt b/linux/wpa-controller/CMakeLists.txt index ef98ef05..43c323f3 100644 --- a/linux/wpa-controller/CMakeLists.txt +++ b/linux/wpa-controller/CMakeLists.txt @@ -10,6 +10,7 @@ target_sources(wpa-controller ${CMAKE_CURRENT_LIST_DIR}/ProtocolHostapd.cxx ${CMAKE_CURRENT_LIST_DIR}/ProtocolWpa.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCommand.cxx + ${CMAKE_CURRENT_LIST_DIR}/WpaCommandGet.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCommandStatus.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaController.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCore.cxx @@ -22,6 +23,7 @@ target_sources(wpa-controller ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/ProtocolHostapd.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/ProtocolWpa.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommand.hxx + ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandGet.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandStatus.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaController.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCore.hxx @@ -49,11 +51,13 @@ list(APPEND WPA_CONTROLLER_PUBLIC_HEADERS ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/ProtocolHostapd.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/IHostapd.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommand.hxx + ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandGet.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandStatus.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaController.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCore.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaKeyValuePair.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaResponse.hxx + ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaResponseGet.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaResponseParser.hxx ) diff --git a/linux/wpa-controller/WpaCommandGet.cxx b/linux/wpa-controller/WpaCommandGet.cxx new file mode 100644 index 00000000..21baacd7 --- /dev/null +++ b/linux/wpa-controller/WpaCommandGet.cxx @@ -0,0 +1,13 @@ + +#include +#include + +#include + +using namespace Wpa; + +WpaCommandGet::WpaCommandGet(std::string_view propertyName) : + WpaCommand(std::string(ProtocolWpa::CommandPayloadGet).append(std::format(" {}", propertyName))), + PropertyName(propertyName) +{ +} diff --git a/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx b/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx new file mode 100644 index 00000000..26d0b853 --- /dev/null +++ b/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx @@ -0,0 +1,29 @@ + +#ifndef WPA_COMMAND_GET_HXX +#define WPA_COMMAND_GET_HXX + +#include + +#include + +namespace Wpa +{ +/** + * @brief Representation of the "GET" command. + */ +struct WpaCommandGet : + public WpaCommand +{ + /** + * @brief Construct a new WpaCommandGet object for the specified property. + * + * @param propertyName The name of the property to retrieve. + */ + WpaCommandGet(std::string_view propertyName); + + std::string_view PropertyName; +}; + +} // namespace Wpa + +#endif // WPA_COMMAND_GET_HXX From 9d49a4c18e0dda20e6d728c05b56aefd5fb2d97d Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:30:47 -0700 Subject: [PATCH 2/8] Add "SET" command. --- linux/wpa-controller/CMakeLists.txt | 3 ++ linux/wpa-controller/WpaCommand.cxx | 5 +++ linux/wpa-controller/WpaCommandGet.cxx | 5 +-- linux/wpa-controller/WpaCommandSet.cxx | 15 +++++++++ linux/wpa-controller/WpaController.cxx | 2 +- .../wpa-controller/include/Wpa/WpaCommand.hxx | 15 ++++++--- .../include/Wpa/WpaCommandGet.hxx | 2 ++ .../include/Wpa/WpaCommandSet.hxx | 33 +++++++++++++++++++ 8 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 linux/wpa-controller/WpaCommandSet.cxx create mode 100644 linux/wpa-controller/include/Wpa/WpaCommandSet.hxx diff --git a/linux/wpa-controller/CMakeLists.txt b/linux/wpa-controller/CMakeLists.txt index 43c323f3..4dea5713 100644 --- a/linux/wpa-controller/CMakeLists.txt +++ b/linux/wpa-controller/CMakeLists.txt @@ -11,6 +11,7 @@ target_sources(wpa-controller ${CMAKE_CURRENT_LIST_DIR}/ProtocolWpa.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCommand.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCommandGet.cxx + ${CMAKE_CURRENT_LIST_DIR}/WpaCommandSet.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCommandStatus.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaController.cxx ${CMAKE_CURRENT_LIST_DIR}/WpaCore.cxx @@ -24,6 +25,7 @@ target_sources(wpa-controller ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/ProtocolWpa.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommand.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandGet.hxx + ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandSet.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandStatus.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaController.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCore.hxx @@ -52,6 +54,7 @@ list(APPEND WPA_CONTROLLER_PUBLIC_HEADERS ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/IHostapd.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommand.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandGet.hxx + ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandSet.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCommandStatus.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaController.hxx ${WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX}/WpaCore.hxx diff --git a/linux/wpa-controller/WpaCommand.cxx b/linux/wpa-controller/WpaCommand.cxx index c194a6fc..acde2363 100644 --- a/linux/wpa-controller/WpaCommand.cxx +++ b/linux/wpa-controller/WpaCommand.cxx @@ -3,6 +3,11 @@ using namespace Wpa; +void WpaCommand::SetPayload(std::string_view payload) +{ + Payload = payload; +} + std::shared_ptr WpaCommand::ParseResponse(std::string_view responsePayload) const { diff --git a/linux/wpa-controller/WpaCommandGet.cxx b/linux/wpa-controller/WpaCommandGet.cxx index 21baacd7..313f354f 100644 --- a/linux/wpa-controller/WpaCommandGet.cxx +++ b/linux/wpa-controller/WpaCommandGet.cxx @@ -1,13 +1,14 @@ #include -#include #include using namespace Wpa; WpaCommandGet::WpaCommandGet(std::string_view propertyName) : - WpaCommand(std::string(ProtocolWpa::CommandPayloadGet).append(std::format(" {}", propertyName))), + WpaCommand(), + PropertyPayload(std::format("{} {}", ProtocolWpa::CommandPayloadGet, propertyName)), PropertyName(propertyName) { + SetPayload(PropertyPayload); } diff --git a/linux/wpa-controller/WpaCommandSet.cxx b/linux/wpa-controller/WpaCommandSet.cxx new file mode 100644 index 00000000..b17fb887 --- /dev/null +++ b/linux/wpa-controller/WpaCommandSet.cxx @@ -0,0 +1,15 @@ + +#include + +#include +#include + +using namespace Wpa; + +WpaCommandSet::WpaCommandSet(std::string_view propertyName, std::string_view propertyValue) : + WpaCommand(), + PropertyPayload(std::format("{} {} {}", ProtocolWpa::CommandPayloadSet, propertyName, propertyValue)), + PropertyName(propertyName), + PropertyValue(propertyValue) +{ +} diff --git a/linux/wpa-controller/WpaController.cxx b/linux/wpa-controller/WpaController.cxx index b4200aa5..fe4ca9cc 100644 --- a/linux/wpa-controller/WpaController.cxx +++ b/linux/wpa-controller/WpaController.cxx @@ -87,7 +87,7 @@ WpaController::SendCommand(const WpaCommand& command) std::array responseBuffer; std::size_t responseSize = std::size(responseBuffer); - int ret = wpa_ctrl_request(controlSocket, std::data(command.Data), std::size(command.Data), std::data(responseBuffer), &responseSize, nullptr); + int ret = wpa_ctrl_request(controlSocket, std::data(command.Payload), std::size(command.Payload), std::data(responseBuffer), &responseSize, nullptr); switch (ret) { case 0: diff --git a/linux/wpa-controller/include/Wpa/WpaCommand.hxx b/linux/wpa-controller/include/Wpa/WpaCommand.hxx index 1b387c1e..703cc999 100644 --- a/linux/wpa-controller/include/Wpa/WpaCommand.hxx +++ b/linux/wpa-controller/include/Wpa/WpaCommand.hxx @@ -11,7 +11,7 @@ namespace Wpa { /** - * @brief Object to hold generic command data for a wpa_supplicant or hostapd + * @brief Object to hold generic command payload for a wpa_supplicant or hostapd * request. */ struct WpaCommand : @@ -20,11 +20,18 @@ struct WpaCommand : virtual ~WpaCommand() = default; constexpr WpaCommand() = default; - constexpr WpaCommand(std::string_view data) : - Data(data) + constexpr WpaCommand(std::string_view payload) : + Payload(payload) { } + /** + * @brief Set the payload of the command. + * + * @param payload The payload to assign. + */ + void SetPayload(std::string_view payload); + /** * @brief Parse the response payload into a WpaResponse object. * @@ -34,7 +41,7 @@ struct WpaCommand : std::shared_ptr ParseResponse(std::string_view responsePayload) const; - std::string Data; + std::string Payload; private: /** diff --git a/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx b/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx index 26d0b853..73843260 100644 --- a/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx +++ b/linux/wpa-controller/include/Wpa/WpaCommandGet.hxx @@ -3,6 +3,7 @@ #define WPA_COMMAND_GET_HXX #include +#include #include @@ -21,6 +22,7 @@ struct WpaCommandGet : */ WpaCommandGet(std::string_view propertyName); + std::string PropertyPayload; std::string_view PropertyName; }; diff --git a/linux/wpa-controller/include/Wpa/WpaCommandSet.hxx b/linux/wpa-controller/include/Wpa/WpaCommandSet.hxx new file mode 100644 index 00000000..90a288af --- /dev/null +++ b/linux/wpa-controller/include/Wpa/WpaCommandSet.hxx @@ -0,0 +1,33 @@ + +#ifndef WPA_COMMAND_SET_HXX +#define WPA_COMMAND_SET_HXX + +#include +#include + +#include + +namespace Wpa +{ +/** + * @brief Representation of the "SET" command. + */ +struct WpaCommandSet : + public WpaCommand +{ + /** + * @brief Construct a new WpaCommandSet object for the specified property. + * + * @param propertyName The name of the property to set. + * @param propertyValue The value to set the property to. + */ + WpaCommandSet(std::string_view propertyName, std::string_view propertyValue); + + std::string PropertyPayload; + std::string_view PropertyName; + std::string_view PropertyValue; +}; + +} // namespace Wpa + +#endif // WPA_COMMAND_SET_HXX From 164ec26747e246c169aa115a476beacc912eee50 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:42:57 -0700 Subject: [PATCH 3/8] Add GetProperty and SetProperty interface commands. --- linux/wpa-controller/Hostapd.cxx | 33 +++++++++++++++++++ linux/wpa-controller/include/Wpa/Hostapd.hxx | 20 +++++++++++ linux/wpa-controller/include/Wpa/IHostapd.hxx | 20 +++++++++++ 3 files changed, 73 insertions(+) diff --git a/linux/wpa-controller/Hostapd.cxx b/linux/wpa-controller/Hostapd.cxx index 7d228570..7b2771dc 100644 --- a/linux/wpa-controller/Hostapd.cxx +++ b/linux/wpa-controller/Hostapd.cxx @@ -6,6 +6,8 @@ #include #include +#include +#include #include #include @@ -48,6 +50,37 @@ HostapdStatus Hostapd::GetStatus() return response->Status; } +bool Hostapd::GetProperty(std::string_view propertyName, std::string& propertyValue) +{ + const WpaCommandGet getCommand(propertyName); + const auto response = m_controller.SendCommand(getCommand); + if (!response) + { + throw HostapdException("Failed to send hostapd 'get' command"); + } + // Check Failed() and not IsOk() since the response will indicate failure + // with "FAIL", otherwise, the payload is the property value (not "OK"). + else if (response->Failed()) + { + return false; + } + + propertyValue = response->Payload; + return true; +} + +bool Hostapd::SetProperty(std::string_view propertyName, std::string_view propertyValue) +{ + const WpaCommandSet setCommand(propertyName, propertyValue); + const auto response = m_controller.SendCommand(setCommand); + if (!response) + { + throw HostapdException("Failed to send hostapd 'set' command"); + } + + return response->IsOk(); +} + bool Hostapd::Enable() { static constexpr WpaCommand EnableCommand(ProtocolHostapd::CommandPayloadEnable); diff --git a/linux/wpa-controller/include/Wpa/Hostapd.hxx b/linux/wpa-controller/include/Wpa/Hostapd.hxx index aa56d5b3..04959fe8 100644 --- a/linux/wpa-controller/include/Wpa/Hostapd.hxx +++ b/linux/wpa-controller/include/Wpa/Hostapd.hxx @@ -42,6 +42,26 @@ struct Hostapd : */ HostapdStatus GetStatus() override; + /** + * @brief Get a property value for the interface. + * + * @param propertyName The name of the property to retrieve. + * @param propertyValue The string to store the property value in. + * @return true If the property value was obtained and its value is in 'propertyValue'. + * @return false If t he property value could not be obtained due to an error. + */ + bool GetProperty(std::string_view propertyName, std::string& propertyValue) override; + + /** + * @brief Set a property on the interface. + * + * @param propertyName The name of the property to set. + * @param propertyValue The value of the property to set. + * @return true The property was set successfully. + * @return false The property was not set successfully. + */ + bool SetProperty(std::string_view propertyName, std::string_view propertyValue) override; + /** * @brief Enables the interface for use. * diff --git a/linux/wpa-controller/include/Wpa/IHostapd.hxx b/linux/wpa-controller/include/Wpa/IHostapd.hxx index 0d11a278..337a6de4 100644 --- a/linux/wpa-controller/include/Wpa/IHostapd.hxx +++ b/linux/wpa-controller/include/Wpa/IHostapd.hxx @@ -42,6 +42,26 @@ struct IHostapd */ virtual HostapdStatus GetStatus() = 0; + /** + * @brief Get a property value for the interface. + * + * @param propertyName The name of the property to retrieve. + * @param propertyValue The string to store the property value in. + * @return true If the property value was obtained and its value is in 'propertyValue'. + * @return false If t he property value could not be obtained due to an error. + */ + virtual bool GetProperty(std::string_view propertyName, std::string& propertyValue) = 0; + + /** + * @brief Set a property on the interface. + * + * @param propertyName The name of the property to set. + * @param propertyValue The value of the property to set. + * @return true The property was set successfully. + * @return false The property was not set successfully. + */ + virtual bool SetProperty(std::string_view propertyName, std::string_view propertyValue) = 0; + /** * @brief Enables the interface for use. * From c9352e00fb0b6496e133ab8d7b360a20de2832c0 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:43:39 -0700 Subject: [PATCH 4/8] Regroup commands. --- linux/wpa-controller/include/Wpa/Hostapd.hxx | 54 +++++++++---------- linux/wpa-controller/include/Wpa/IHostapd.hxx | 54 +++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/linux/wpa-controller/include/Wpa/Hostapd.hxx b/linux/wpa-controller/include/Wpa/Hostapd.hxx index 04959fe8..36130c61 100644 --- a/linux/wpa-controller/include/Wpa/Hostapd.hxx +++ b/linux/wpa-controller/include/Wpa/Hostapd.hxx @@ -24,17 +24,41 @@ struct Hostapd : Hostapd(std::string_view interfaceName); /** - * @brief Get the name of the interface hostapd is managing. + * @brief Enables the interface for use. * - * @return std::string_view + * @return true + * @return false */ - std::string_view GetInterface() override; + bool Enable() override; + + /** + * @brief Disables the interface for use. + * + * @return true + * @return false + */ + bool Disable() override; + + /** + * @brief Terminates the process hosting the daemon. + * + * @return true + * @return false + */ + bool Terminate() override; /** * @brief Checks connectivity to the hostapd daemon. */ bool Ping() override; + /** + * @brief Get the name of the interface hostapd is managing. + * + * @return std::string_view + */ + std::string_view GetInterface() override; + /** * @brief Get the status for the interface. * @@ -62,30 +86,6 @@ struct Hostapd : */ bool SetProperty(std::string_view propertyName, std::string_view propertyValue) override; - /** - * @brief Enables the interface for use. - * - * @return true - * @return false - */ - bool Enable() override; - - /** - * @brief Disables the interface for use. - * - * @return true - * @return false - */ - bool Disable() override; - - /** - * @brief Terminates the process hosting the daemon. - * - * @return true - * @return false - */ - bool Terminate() override; - private: const std::string m_interface; WpaController m_controller; diff --git a/linux/wpa-controller/include/Wpa/IHostapd.hxx b/linux/wpa-controller/include/Wpa/IHostapd.hxx index 337a6de4..a45d2e64 100644 --- a/linux/wpa-controller/include/Wpa/IHostapd.hxx +++ b/linux/wpa-controller/include/Wpa/IHostapd.hxx @@ -24,17 +24,41 @@ struct IHostapd virtual ~IHostapd() = default; /** - * @brief Get the name of the interface hostapd is managing. + * @brief Enables the interface for use. * - * @return std::string_view + * @return true + * @return false */ - virtual std::string_view GetInterface() = 0; + virtual bool Enable() = 0; + + /** + * @brief Disables the interface for use. + * + * @return true + * @return false + */ + virtual bool Disable() = 0; + + /** + * @brief Terminates the process hosting the daemon. + * + * @return true + * @return false + */ + virtual bool Terminate() = 0; /** * @brief Checks connectivity to the hostapd daemon. */ virtual bool Ping() = 0; + /** + * @brief Get the name of the interface hostapd is managing. + * + * @return std::string_view + */ + virtual std::string_view GetInterface() = 0; + /** * @brief Get the status for the interface. * @@ -61,30 +85,6 @@ struct IHostapd * @return false The property was not set successfully. */ virtual bool SetProperty(std::string_view propertyName, std::string_view propertyValue) = 0; - - /** - * @brief Enables the interface for use. - * - * @return true - * @return false - */ - virtual bool Enable() = 0; - - /** - * @brief Disables the interface for use. - * - * @return true - * @return false - */ - virtual bool Disable() = 0; - - /** - * @brief Terminates the process hosting the daemon. - * - * @return true - * @return false - */ - virtual bool Terminate() = 0; }; /** From 6d50520c3d5eb02f11d6defe24a80a456483e6ab Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:45:49 -0700 Subject: [PATCH 5/8] Docs. --- linux/wpa-controller/include/Wpa/WpaCore.hxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux/wpa-controller/include/Wpa/WpaCore.hxx b/linux/wpa-controller/include/Wpa/WpaCore.hxx index 29809f9b..5001fe4c 100644 --- a/linux/wpa-controller/include/Wpa/WpaCore.hxx +++ b/linux/wpa-controller/include/Wpa/WpaCore.hxx @@ -6,6 +6,9 @@ namespace Wpa { +/** + * @brief The type of WPA daemon/service. + */ enum class WpaType { Hostapd, From 6c05d6e4b816ea0f1c0a39b2d19ca243951024f0 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 20:54:18 -0700 Subject: [PATCH 6/8] Add tests for GetProperty() command. --- .../include/Wpa/ProtocolHostapd.hxx | 6 +++ .../unit/linux/wpa-controller/TestHostapd.cxx | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx b/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx index 04f8704d..41fe9206 100644 --- a/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx +++ b/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx @@ -180,6 +180,12 @@ struct ProtocolHostapd : static constexpr auto ResponsePayloadStatusNoIr = "NO_IR"; static constexpr auto ResponsePayloadStatusUnknown = "UNKNOWN"; + // Property names for "GET" commands. + static constexpr auto PropertyNameVersion = "version"; + static constexpr auto PropertyNameTlsLibrary = "tls_library"; + // Note: this value must be updated if the version of hostapd changes. + static constexpr auto PropertyVersionValue = "2.10-hostap_2_10"; + // Response properties for the "STATUS" command. // Note: all properties must be terminated with the key-value delimeter (=). static constexpr auto ResponseStatusPropertyKeyState = "state="; diff --git a/tests/unit/linux/wpa-controller/TestHostapd.cxx b/tests/unit/linux/wpa-controller/TestHostapd.cxx index 8937daaa..aed3aa0b 100644 --- a/tests/unit/linux/wpa-controller/TestHostapd.cxx +++ b/tests/unit/linux/wpa-controller/TestHostapd.cxx @@ -96,6 +96,45 @@ TEST_CASE("Send command: GetStatus()", "[wpa][hostapd][client][remote]") } } +TEST_CASE("Send GetProperty() command", "[wpa][hostapd][client][remote]") +{ + using namespace Wpa; + + Hostapd hostapd(WpaDaemonManager::InterfaceNameDefault); + + SECTION("GetProperty() doesn't throw") + { + std::string whateverValue; + REQUIRE_NOTHROW(hostapd.GetProperty("whatever", whateverValue)); + } + + SECTION("GetProperty() returns false for invalid property") + { + std::string whateverValue; + REQUIRE_FALSE(hostapd.GetProperty("whatever", whateverValue)); + } + + SECTION("GetProperty() returns true for valid property") + { + std::string versionValue; + REQUIRE(hostapd.GetProperty(ProtocolHostapd::PropertyNameVersion, versionValue)); + } + + SECTION("GetProperty() returns true for valid property with non-empty value") + { + std::string versionValue; + REQUIRE(hostapd.GetProperty(ProtocolHostapd::PropertyNameVersion, versionValue)); + REQUIRE_FALSE(versionValue.empty()); + } + + SECTION("GetProperty() returns correct value for valid property") + { + std::string versionValue; + CHECK(hostapd.GetProperty(ProtocolHostapd::PropertyNameVersion, versionValue)); + REQUIRE(versionValue == ProtocolHostapd::PropertyVersionValue); + } +} + TEST_CASE("Send control commands: Enable(), Disable()", "[wpa][hostapd][client][remote]") { using namespace Wpa; From 372726777c9305a1772854194236abb64dc8e2b1 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 21:03:12 -0700 Subject: [PATCH 7/8] Fix bug not setting payload for "SET" command. --- linux/wpa-controller/WpaCommandSet.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/linux/wpa-controller/WpaCommandSet.cxx b/linux/wpa-controller/WpaCommandSet.cxx index b17fb887..c0eec674 100644 --- a/linux/wpa-controller/WpaCommandSet.cxx +++ b/linux/wpa-controller/WpaCommandSet.cxx @@ -12,4 +12,5 @@ WpaCommandSet::WpaCommandSet(std::string_view propertyName, std::string_view pro PropertyName(propertyName), PropertyValue(propertyValue) { + SetPayload(PropertyPayload); } From 4a764b525a516e02e724f62e1c8c49353e548346 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Wed, 22 Nov 2023 21:03:21 -0700 Subject: [PATCH 8/8] Add tests for SetProperty() command. --- .../include/Wpa/ProtocolHostapd.hxx | 7 ++++++ .../unit/linux/wpa-controller/TestHostapd.cxx | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx b/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx index 41fe9206..c9c2c493 100644 --- a/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx +++ b/linux/wpa-controller/include/Wpa/ProtocolHostapd.hxx @@ -186,6 +186,13 @@ struct ProtocolHostapd : // Note: this value must be updated if the version of hostapd changes. static constexpr auto PropertyVersionValue = "2.10-hostap_2_10"; + // Property names for "SET" commands. + static constexpr auto PropertyNameSetBand = "setband"; + static constexpr auto PropertySetBandValueAuto = "AUTO"; + static constexpr auto PropertySetBandValue2G = "2G"; + static constexpr auto PropertySetBandValue5G = "5G"; + static constexpr auto PropertySetBandValue6G = "6G"; + // Response properties for the "STATUS" command. // Note: all properties must be terminated with the key-value delimeter (=). static constexpr auto ResponseStatusPropertyKeyState = "state="; diff --git a/tests/unit/linux/wpa-controller/TestHostapd.cxx b/tests/unit/linux/wpa-controller/TestHostapd.cxx index aed3aa0b..49959aca 100644 --- a/tests/unit/linux/wpa-controller/TestHostapd.cxx +++ b/tests/unit/linux/wpa-controller/TestHostapd.cxx @@ -135,6 +135,30 @@ TEST_CASE("Send GetProperty() command", "[wpa][hostapd][client][remote]") } } +TEST_CASE("Send SetProperty() command", "[wpa][hostapd][client][remote]") +{ + using namespace Wpa; + + Hostapd hostapd(WpaDaemonManager::InterfaceNameDefault); + + SECTION("SetProperty() doesn't throw") + { + REQUIRE_NOTHROW(hostapd.SetProperty("whatever", "whatever")); + } + + SECTION("SetProperty() returns false for invalid property") + { + REQUIRE_FALSE(hostapd.SetProperty("whatever", "whatever")); + } + + SECTION("SetProperty() returns true for valid property") + { + REQUIRE(hostapd.SetProperty(ProtocolHostapd::PropertyNameSetBand, ProtocolHostapd::PropertySetBandValueAuto)); + } + + // TODO: validate that the property was actually set. Need to find a property whose value is retrievable. +} + TEST_CASE("Send control commands: Enable(), Disable()", "[wpa][hostapd][client][remote]") { using namespace Wpa;