Skip to content

Commit

Permalink
Merge pull request #116 from microsoft/isenabled
Browse files Browse the repository at this point in the history
Add way to check if an access point is enabled
  • Loading branch information
abeltrano authored Jan 20, 2024
2 parents 95c3999 + 979e11a commit 43b4f99
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 41 deletions.
15 changes: 15 additions & 0 deletions src/common/wifi/core/AccessPointControllerException.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include <microsoft/net/wifi/IAccessPointController.hxx>

using namespace Microsoft::Net::Wifi;

AccessPointControllerException::AccessPointControllerException(std::string_view what) :
m_what(what)
{
}

const char*
AccessPointControllerException::what() const noexcept
{
return m_what.c_str();
}
3 changes: 2 additions & 1 deletion src/common/wifi/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ target_sources(wifi-core
PRIVATE
AccessPoint.cxx
AccessPointController.cxx
AccessPointControllerException.cxx
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${WIFI_CORE_PUBLIC_INCLUDE}
FILES
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/AccessPoint.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/AccessPointCapabilities.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/AccessPointController.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/IAccessPoint.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/IAccessPointController.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/Ieee80211.hxx
${WIFI_CORE_PUBLIC_INCLUDE_PREFIX}/Ieee80211AccessPointCapabilities.hxx
)

install(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include <exception>
#include <memory>
#include <string_view>
#include <string>

#include <microsoft/net/wifi/AccessPointCapabilities.hxx>
#include <microsoft/net/wifi/Ieee80211AccessPointCapabilities.hxx>

namespace Microsoft::Net::Wifi
{
Expand All @@ -16,7 +17,13 @@ namespace Microsoft::Net::Wifi
struct AccessPointControllerException :
public std::exception
{
using std::exception::exception;
AccessPointControllerException(std::string_view what);

virtual const char*
what() const noexcept override;

private:
std::string m_what;
};

/**
Expand All @@ -38,11 +45,20 @@ struct IAccessPointController
GetInterfaceName() const noexcept = 0;

/**
* @brief Get the capabilities of the access point.
* @brief Get whether the access point is enabled.
*
* @return AccessPointCapabilities
* @return true
* @return false
*/
virtual bool
GetIsEnabled() = 0;

/**
* @brief Get the capabilities of the access point.
*
* @return Ieee80211AccessPointCapabilities
*/
virtual AccessPointCapabilities2
virtual Ieee80211AccessPointCapabilities
GetCapabilities() = 0;
};

Expand All @@ -53,8 +69,8 @@ struct IAccessPointControllerFactory
{
/**
* @brief Create a new IAccessPointController object.
*
* @return std::unique_ptr<IAccessPointController>
*
* @return std::unique_ptr<IAccessPointController>
*/
virtual std::unique_ptr<IAccessPointController>
Create(std::string_view interfaceName) = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#ifndef IEEE_80211_ACCESS_POINT_CAPABILITIES_HXX
#define IEEE_80211_ACCESS_POINT_CAPABILITIES_HXX

#include <vector>

#include <microsoft/net/wifi/Ieee80211.hxx>

namespace Microsoft::Net::Wifi
{
/**
* @brief Describes the capabilities of an IEEE 802.11 access point.
*/
struct Ieee80211AccessPointCapabilities
{
std::vector<IeeeProtocol> Protocols;
std::vector<IeeeFrequencyBand> FrequencyBands;
std::vector<IeeeAuthenticationAlgorithm> AuthenticationAlgorithms;
std::vector<IeeeCipherSuite> EncryptionAlgorithms;
};
} // namespace Microsoft::Net::Wifi

#endif // IEEE_80211_ACCESS_POINT_CAPABILITIES_HXX
26 changes: 24 additions & 2 deletions src/linux/wifi/core/AccessPointControllerHostapd.cxx
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@

#include <format>

#include <microsoft/net/wifi/AccessPointControllerHostapd.hxx>
#include <plog/Log.h>
#include <Wpa/IHostapd.hxx>
#include <Wpa/ProtocolHostapd.hxx>
#include <Wpa/WpaCommandStatus.hxx>
#include <Wpa/WpaResponseStatus.hxx>

using namespace Microsoft::Net::Wifi;

AccessPointControllerHostapd::AccessPointControllerHostapd(std::string_view interfaceName) :
AccessPointController(interfaceName),
m_wpaController(interfaceName, Wpa::WpaType::Hostapd)
m_hostapd(interfaceName)
{
}

AccessPointCapabilities2
Ieee80211AccessPointCapabilities
AccessPointControllerHostapd::GetCapabilities()
{
// TODO: Implement this method.
return {};
}

bool
AccessPointControllerHostapd::GetIsEnabled()
{
bool isEnabled{ false };

try {
auto hostapdStatus = m_hostapd.GetStatus();
isEnabled = (hostapdStatus.State == Wpa::HostapdInterfaceState::Enabled);
} catch (const Wpa::HostapdException& ex) {
throw AccessPointControllerException(std::format("Failed to get status for interface {} ({})", GetInterfaceName(), ex.what()));
}

return isEnabled;
}

std::unique_ptr<IAccessPointController>
AccessPointControllerHostapdFactory::Create(std::string_view interfaceName)
{
Expand Down
2 changes: 2 additions & 0 deletions src/linux/wifi/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ target_sources(wifi-core-linux
)

target_link_libraries(wifi-core-linux
PRIVATE
plog::plog
PUBLIC
wifi-core
wpa-controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <string_view>

#include <Wpa/WpaController.hxx>
#include <Wpa/Hostapd.hxx>
#include <microsoft/net/wifi/AccessPointController.hxx>

namespace Microsoft::Net::Wifi
Expand All @@ -26,16 +26,25 @@ struct AccessPointControllerHostapd :
*/
AccessPointControllerHostapd(std::string_view interfaceName);

/**
* @brief Get whether the access point is enabled.
*
* @return true
* @return false
*/
virtual bool
GetIsEnabled() override;

/**
* @brief Get the Capabilities object
*
* @return AccessPointCapabilities2
* @return Ieee80211AccessPointCapabilities
*/
virtual AccessPointCapabilities2
virtual Ieee80211AccessPointCapabilities
GetCapabilities() override;

private:
Wpa::WpaController m_wpaController;
Wpa::Hostapd m_hostapd;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/linux/wpa-controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(WPA_CONTROLLER_PUBLIC_INCLUDE_PREFIX ${WPA_CONTROLLER_PUBLIC_INCLUDE}/${WPA_
target_sources(wpa-controller
PRIVATE
Hostapd.cxx
HostapdException.cxx
ProtocolHostapd.cxx
ProtocolWpa.cxx
WpaCommand.cxx
Expand Down
15 changes: 15 additions & 0 deletions src/linux/wpa-controller/HostapdException.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include <Wpa/IHostapd.hxx>

using namespace Wpa;

HostapdException::HostapdException(std::string_view message) :
m_message(message)
{
}

const char*
HostapdException::what() const noexcept
{
return m_message.c_str();
}
13 changes: 4 additions & 9 deletions src/linux/wpa-controller/include/Wpa/IHostapd.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,13 @@ struct IHostapd
* @brief Generic exception that may be thrown by any of the functions in
* IHostapd.
*/
struct HostapdException : std::exception
struct HostapdException :
public std::exception
{
HostapdException(std::string_view message) :
m_message(message)
{
}
HostapdException(std::string_view message);

const char*
what() const noexcept override
{
return m_message.c_str();
}
what() const noexcept override;

private:
const std::string m_message;
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/wifi/helpers/AccessPointControllerTest.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include <microsoft/net/wifi/test/AccessPointControllerTest.hxx>
#include <microsoft/net/wifi/test/AccessPointControllerTest.hxx>

using namespace Microsoft::Net::Wifi;
Expand All @@ -15,7 +14,13 @@ AccessPointControllerTest::GetInterfaceName() const noexcept
return InterfaceName;
}

AccessPointCapabilities2
bool
AccessPointControllerTest::GetIsEnabled()
{
return IsEnabled;
}

Ieee80211AccessPointCapabilities
AccessPointControllerTest::GetCapabilities()
{
return {}; // TODO: return something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ struct AccessPointControllerTest final :
virtual std::string_view
GetInterfaceName() const noexcept override;

virtual AccessPointCapabilities2
virtual bool
GetIsEnabled() override;

virtual Ieee80211AccessPointCapabilities
GetCapabilities() override;

std::string InterfaceName;
bool IsEnabled{ false };
};

struct AccessPointControllerFactoryTest final :
Expand Down

0 comments on commit 43b4f99

Please sign in to comment.