Skip to content

Commit

Permalink
Merge pull request #203 from microsoft/apenableaggregate
Browse files Browse the repository at this point in the history
Implement WifiAccessPointEnable
  • Loading branch information
abeltrano authored Mar 3, 2024
2 parents faba955 + 73179bd commit fcbc3a7
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 125 deletions.
248 changes: 155 additions & 93 deletions src/common/service/NetRemoteService.cxx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <grpcpp/support/status.h>
#include <microsoft/net/remote/protocol/NetRemoteService.grpc.pb.h>
#include <microsoft/net/remote/protocol/NetRemoteWifi.pb.h>
#include <microsoft/net/remote/protocol/WifiCore.pb.h>
#include <microsoft/net/wifi/AccessPointManager.hxx>
#include <microsoft/net/wifi/AccessPointOperationStatus.hxx>
#include <microsoft/net/wifi/IAccessPoint.hxx>
Expand Down Expand Up @@ -121,45 +122,57 @@ protected:
* @brief Attempt to obtain an IAccessPointController instance for the specified access point.
*
* @param accessPoint The access point to obtain a controller for.
* @param accessPointController
* @param accessPointController Optional configuration to apply to the access point prior to enablement.
* @return Microsoft::Net::Wifi::AccessPointOperationStatus
*/
static Microsoft::Net::Wifi::AccessPointOperationStatus
TryGetAccessPointController(const std::shared_ptr<Microsoft::Net::Wifi::IAccessPoint>& accessPoint, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController>& accessPointController);

/**
* @brief Enable an access point. This brings the access point online, making it available for use by clients.
*
* @param accessPointId The access point identifier.
* @param dot11AccessPointConfiguration (optional) The access point configuration to enforce prior to enablement.
* @param accessPointController The access point controller for the specified access point (optional).
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointEnableImpl(std::string_view accessPointId, const Microsoft::Net::Wifi::Dot11AccessPointConfiguration* dot11AccessPointConfiguration, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

/**
* @brief Set the active PHY type or protocol of the access point. The access point must be enabled. This will cause
* the access point to temporarily go offline while the change is being applied.
*
* @param accessPointId The access point identifier.
* @param dot11PhyType The new PHY type to set.
* @param accessPointController The access point controller for the specified access point (optional).
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointSetPhyTypeImpl(std::string_view accessPointId, Microsoft::Net::Wifi::Dot11PhyType dot11PhyType);
WifiAccessPointSetPhyTypeImpl(std::string_view accessPointId, Microsoft::Net::Wifi::Dot11PhyType dot11PhyType, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

/**
* @brief Set the active frequency bands of the access point. The access point must be enabled. This will cause the
* access point to temporarily go offline while the change is being applied.
*
* @param accessPointId The access point identifier.
* @param dot11FrequencyBands The new frequency bands to set.
* @param accessPointController The access point controller for the specified access point (optional).
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointSetFrequencyBandsImpl(std::string_view accessPointId, std::vector<Microsoft::Net::Wifi::Dot11FrequencyBand>& dot11FrequencyBands);
WifiAccessPointSetFrequencyBandsImpl(std::string_view accessPointId, std::vector<Microsoft::Net::Wifi::Dot11FrequencyBand>& dot11FrequencyBands, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

protected:
/**
* @brief Validate the basic input parameters for the WifiAccessPointEnable request.
*
* @param request The request to validate.
* @param status The status to populate with failure information.
* @return true
* @return false
* @brief Set the SSID of the access point.
*
* @param accessPointId The access point identifier.
* @param dot11Ssid The new SSID to set.
* @param accessPointController The access point controller for the specified access point (optional).
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
static bool
ValidateWifiAccessPointEnableRequest(const Microsoft::Net::Remote::Wifi::WifiAccessPointEnableRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus& status);
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointSetSsidImpl(std::string_view accessPointId, const Microsoft::Net::Wifi::Dot11Ssid& dot11Ssid, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

private:
std::shared_ptr<Microsoft::Net::Wifi::AccessPointManager> m_accessPointManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct IAccessPointController
* @return AccessPointOperationStatus
*/
virtual AccessPointOperationStatus
SetSssid(std::string_view ssid) noexcept = 0;
SetSsid(std::string_view ssid) noexcept = 0;
};

/**
Expand Down
34 changes: 20 additions & 14 deletions src/common/wifi/dot11/adapter/Ieee80211Dot11Adapters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,40 @@ FromDot11FrequencyBand(const Dot11FrequencyBand dot11FrequencyBand) noexcept

using Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest;

namespace detail
{
// protobuf encodes enums in repeated fields as 'int' instead of the enum type itself. So, the below is a simple
// function to convert the repeated field of int to the enum type.
constexpr auto toDot11FrequencyBand = [](const auto& frequencyBand) {
return static_cast<Dot11FrequencyBand>(frequencyBand);
};
} // details

std::vector<Dot11FrequencyBand>
ToDot11FrequencyBands(const WifiAccessPointSetFrequencyBandsRequest& request) noexcept
{
// protobuf encodes enums in repeated fields as 'int' instead of the enum type itself. So, the below is a simple
// function to convert the repeated field of int to the enum type.
constexpr auto toDot11FrequencyBand = [](const auto& frequencyBand) {
return static_cast<Dot11FrequencyBand>(frequencyBand);
};

std::vector<Dot11FrequencyBand> dot11FrequencyBands(static_cast<std::size_t>(std::size(request.frequencybands())));
std::ranges::transform(request.frequencybands(), std::begin(dot11FrequencyBands), toDot11FrequencyBand);
std::ranges::transform(request.frequencybands(), std::begin(dot11FrequencyBands), detail::toDot11FrequencyBand);

return dot11FrequencyBands;
// TODO: for some reason, std::ranges::to is not being found for clang. Once resolved, update to the following:
// return request.frequencybands() | std::views::transform(toDot11FrequencyBand) | std::ranges::to<std::vector>();
}

std::vector<Dot11FrequencyBand>
ToDot11FrequencyBands(const Dot11AccessPointConfiguration& dot11AccessPointConfiguration) noexcept
{
std::vector<Dot11FrequencyBand> dot11FrequencyBands(static_cast<std::size_t>(std::size(dot11AccessPointConfiguration.bands())));
std::ranges::transform(dot11AccessPointConfiguration.bands(), std::begin(dot11FrequencyBands), detail::toDot11FrequencyBand);

return dot11FrequencyBands;
}

std::vector<Ieee80211FrequencyBand>
FromDot11SetFrequencyBandsRequest(const WifiAccessPointSetFrequencyBandsRequest& request)
{
// protobuf encodes enums in repeated fields as 'int' instead of the enum type itself. So, the below is a simple
// function to convert the repeated field of int to the enum type.
constexpr auto toDot11FrequencyBand = [](const auto& frequencyBand) {
return static_cast<Dot11FrequencyBand>(frequencyBand);
};

std::vector<Ieee80211FrequencyBand> ieee80211FrequencyBands(static_cast<std::size_t>(std::size(request.frequencybands())));
std::ranges::transform(request.frequencybands() | std::views::transform(toDot11FrequencyBand), std::begin(ieee80211FrequencyBands), FromDot11FrequencyBand);
std::ranges::transform(request.frequencybands() | std::views::transform(detail::toDot11FrequencyBand), std::begin(ieee80211FrequencyBands), FromDot11FrequencyBand);

return ieee80211FrequencyBands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ ToDot11FrequencyBand(Microsoft::Net::Wifi::Ieee80211FrequencyBand ieee80211Frequ
std::vector<Microsoft::Net::Wifi::Dot11FrequencyBand>
ToDot11FrequencyBands(const Microsoft::Net::Remote::Wifi::WifiAccessPointSetFrequencyBandsRequest& request) noexcept;

/**
* @brief Obtain a vector of Dot11FrequencyBands from the specified Dot11AccessPointConfiguration.
*
* @param dot11AccessPointConfiguration The Dot11AccessPointConfiguration to extract the Dot11FrequencyBands from.
* @return std::vector<Microsoft::Net::Wifi::Dot11FrequencyBand>
*/
std::vector<Microsoft::Net::Wifi::Dot11FrequencyBand>
ToDot11FrequencyBands(const Microsoft::Net::Wifi::Dot11AccessPointConfiguration& dot11AccessPointConfiguration) noexcept;

/**
* @brief Convert the specified Dot11FrequencyBand to the equivalent IEEE 802.11 frequency band.
*
Expand Down
2 changes: 1 addition & 1 deletion src/linux/wifi/core/AccessPointControllerLinux.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ AccessPointControllerLinux::SetFrequencyBands(std::vector<Ieee80211FrequencyBand
}

AccessPointOperationStatus
AccessPointControllerLinux::SetSssid(std::string_view ssid) noexcept
AccessPointControllerLinux::SetSsid(std::string_view ssid) noexcept
{
AccessPointOperationStatus status{ GetInterfaceName() };
const AccessPointOperationStatusLogOnExit logStatusOnExit(&status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct AccessPointControllerLinux :
* @return AccessPointOperationStatus
*/
AccessPointOperationStatus
SetSssid(std::string_view ssid) noexcept override;
SetSsid(std::string_view ssid) noexcept override;

private:
Wpa::Hostapd m_hostapd;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/TestNetRemoteServiceClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ TEST_CASE("WifiAccessPointEnable API", "[basic][rpc][client][remote]")

auto apManagerTest = std::make_shared<AccessPointManagerTest>();
const Ieee80211AccessPointCapabilities apCapabilities{
.Protocols{ std::cbegin(AllProtocols), std::cend(AllProtocols) }
.Protocols{ std::cbegin(AllProtocols), std::cend(AllProtocols) },
.FrequencyBands{ std::cbegin(AllBands), std::cend(AllBands) }
};

auto apTest1 = std::make_shared<AccessPointTest>(InterfaceName1, apCapabilities);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/wifi/helpers/AccessPointControllerTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ AccessPointControllerTest::SetFrequencyBands(std::vector<Ieee80211FrequencyBand>
}

AccessPointOperationStatus
AccessPointControllerTest::SetSssid(std::string_view ssid) noexcept
AccessPointControllerTest::SetSsid(std::string_view ssid) noexcept
{
assert(AccessPoint != nullptr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct AccessPointControllerTest final :
* @return AccessPointOperationStatus
*/
AccessPointOperationStatus
SetSssid(std::string_view ssid) noexcept override;
SetSsid(std::string_view ssid) noexcept override;
};

/**
Expand Down

0 comments on commit fcbc3a7

Please sign in to comment.