Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WifiAccessPointGetAttributes API #326

Merged
merged 11 commits into from
Jul 27, 2024
1 change: 1 addition & 0 deletions protocol/protos/NetRemoteService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ service NetRemote
rpc WifiAccessPointSetSsid (Microsoft.Net.Remote.Wifi.WifiAccessPointSetSsidRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointSetSsidResult);
rpc WifiAccessPointSetNetworkBridge (Microsoft.Net.Remote.Wifi.WifiAccessPointSetNetworkBridgeRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointSetNetworkBridgeResult);
rpc WifiAccessPointSetAuthenticationDot1x (Microsoft.Net.Remote.Wifi.WifiAccessPointSetAuthenticationDot1xRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointSetAuthenticationDot1xResult);
rpc WifiAccessPointGetAttributes (Microsoft.Net.Remote.Wifi.WifiAccessPointGetAttributesRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointGetAttributesResult);
}
12 changes: 12 additions & 0 deletions protocol/protos/NetRemoteWifi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,15 @@ message WifiAccessPointSetAuthenticationDot1xResult
string AccessPointId = 1;
WifiAccessPointOperationStatus Status = 2;
}

message WifiAccessPointGetAttributesRequest
{
string AccessPointId = 1;
}

message WifiAccessPointGetAttributesResult
{
string AccessPointId = 1;
WifiAccessPointOperationStatus Status = 2;
Microsoft.Net.Wifi.Dot11AccessPointAttributes Attributes = 3;
}
5 changes: 5 additions & 0 deletions protocol/protos/WifiCore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ message Dot11AccessPointCapabilities
repeated Microsoft.Net.Wifi.Dot11AkmSuite AkmSuites = 5;
}

message Dot11AccessPointAttributes
{
map<string, string> Properties = 1;
}

enum Dot11AccessPointState
{
AccessPointStateUnknown = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/common/net/wifi/core/AccessPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

using namespace Microsoft::Net::Wifi;

AccessPoint::AccessPoint(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, std::optional<Ieee80211MacAddress> macAddress) :
AccessPoint::AccessPoint(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, AccessPointAttributes attributes, std::optional<Ieee80211MacAddress> macAddress) :
m_interfaceName(interfaceName),
m_accessPointControllerFactory(std::move(accessPointControllerFactory)),
m_attributes(std::move(attributes)),
m_macAddress(macAddress)
{}

Expand All @@ -29,6 +30,12 @@ AccessPoint::GetMacAddress() const noexcept
return m_macAddress.value_or(Ieee80211MacAddress{});
}

const AccessPointAttributes&
AccessPoint::GetAttributes() const noexcept
{
return m_attributes;
}

std::unique_ptr<IAccessPointController>
AccessPoint::CreateController()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ struct AccessPoint :
*
* @param interfaceName The network interface name representing the access point.
* @param accessPointControllerFactory The factory used to create controller objects.
* @param attributes The static attributes of the access point.
* @param macAddress The mac address of the access point.
*/
AccessPoint(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, std::optional<Ieee80211MacAddress> macAddress = std::nullopt);
AccessPoint(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, AccessPointAttributes attributes = {}, std::optional<Ieee80211MacAddress> macAddress = std::nullopt);

/**
* @brief Get the network interface name representing the access point.
Expand All @@ -43,6 +45,14 @@ struct AccessPoint :
Ieee80211MacAddress
GetMacAddress() const noexcept override;

/**
* @brief Get the static attributes of an access point.
*
* @return AccessPointAttributes&
*/
const AccessPointAttributes&
GetAttributes() const noexcept override;

/**
* @brief Create a controller object.
*
Expand All @@ -54,6 +64,7 @@ struct AccessPoint :
private:
const std::string m_interfaceName;
std::shared_ptr<IAccessPointControllerFactory> m_accessPointControllerFactory;
AccessPointAttributes m_attributes{};
std::optional<Ieee80211MacAddress> m_macAddress;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

#include <memory>
#include <string_view>
#include <unordered_map>

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

namespace Microsoft::Net::Wifi
{

/**
* @brief Container to hold static attributes about an access point.
*/
struct AccessPointAttributes
{
std::unordered_map<std::string, std::string> Properties{};
};

/**
* @brief Represents a wireless access point.
*/
Expand Down Expand Up @@ -51,6 +61,14 @@ struct IAccessPoint
virtual Ieee80211MacAddress
GetMacAddress() const noexcept = 0;

/**
* @brief Get the static attributes of an access point.
*
* @return AccessPointAttributes&
*/
virtual const AccessPointAttributes&
GetAttributes() const noexcept = 0;

/**
* @brief Create a new instance that can control the access point.
*
Expand Down Expand Up @@ -81,6 +99,8 @@ struct IAccessPointCreateArgs

IAccessPointCreateArgs&
operator=(IAccessPointCreateArgs&&) = delete;

AccessPointAttributes Attributes{};
};

/**
Expand Down
32 changes: 29 additions & 3 deletions src/common/net/wifi/dot11/adapter/Ieee80211Dot11Adapters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,41 @@ FromDot11AuthenticationDot1x(const Dot11AuthenticationDot1x& Dot11Authentication
Dot11AuthenticationDot1x
ToDot11AuthenticationDot1x(const Ieee80211Authentication8021x& ieee8021xAuthentication) noexcept
{
Dot11AuthenticationDot1x Dot11AuthenticationDot1x{};
Dot11AuthenticationDot1x dot11AuthenticationDot1x{};

// Convert RADIUS configuration, if present.
if (ieee8021xAuthentication.Radius.has_value()) {
auto dot1xRadiusConfiguration = ToServiceDot1xRadiusConfiguration(ieee8021xAuthentication.Radius.value());
*Dot11AuthenticationDot1x.mutable_radius() = std::move(dot1xRadiusConfiguration);
*dot11AuthenticationDot1x.mutable_radius() = std::move(dot1xRadiusConfiguration);
}

return Dot11AuthenticationDot1x;
return dot11AuthenticationDot1x;
}

AccessPointAttributes
FromDot11AccessPointAttributes(const Dot11AccessPointAttributes& dot11AccessPointConfiguration) noexcept
{
AccessPointAttributes accessPointAttributes{};

accessPointAttributes.Properties = {
std::cbegin(dot11AccessPointConfiguration.properties()),
std::cend(dot11AccessPointConfiguration.properties()),
};

return accessPointAttributes;
}

Dot11AccessPointAttributes
ToDot11AccessPointAttributes(const AccessPointAttributes& accessPointAttributes) noexcept
{
Dot11AccessPointAttributes dot11AccessPointAttributes{};

*dot11AccessPointAttributes.mutable_properties() = {
std::make_move_iterator(std::begin(accessPointAttributes.Properties)),
std::make_move_iterator(std::end(accessPointAttributes.Properties)),
};

return dot11AccessPointAttributes;
}

} // namespace Microsoft::Net::Wifi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <microsoft/net/remote/protocol/Network8021x.pb.h>
#include <microsoft/net/remote/protocol/WifiCore.pb.h>
#include <microsoft/net/wifi/AccessPointOperationStatus.hxx>
#include <microsoft/net/wifi/IAccessPoint.hxx>
#include <microsoft/net/wifi/Ieee80211.hxx>
#include <microsoft/net/wifi/Ieee80211AccessPointCapabilities.hxx>
#include <microsoft/net/wifi/Ieee80211Authentication.hxx>
Expand Down Expand Up @@ -360,22 +361,40 @@ ToDot11AuthenticationData(const Ieee80211AuthenticationData& ieee80211Authentica

/**
* @brief Convert the specified Dot11AuthenticationDot1x to the equivalent IEEE 802.1x authentication.
*
*
* @param dot11AuthenticationDot1x The Dot11AuthenticationDot1x to convert.
* @return Ieee80211Authentication8021x
* @return Ieee80211Authentication8021x
*/
Ieee80211Authentication8021x
FromDot11AuthenticationDot1x(const Dot11AuthenticationDot1x& dot11AuthenticationDot1x) noexcept;

/**
* @brief Convert the specified IEEE 802.1x authentication to the equivalent Dot11AuthenticationDot1x.
*
*
* @param ieee8021xAuthentication The IEEE 802.1x authentication to convert.
* @return Dot11AuthenticationDot1x
* @return Dot11AuthenticationDot1x
*/
Dot11AuthenticationDot1x
ToDot11AuthenticationDot1x(const Ieee80211Authentication8021x& ieee8021xAuthentication) noexcept;

/**
* @brief Convert the specified Dot11AccessPointAttributes to the equivalent neutral type access point attributes.
*
* @param dot11AccessPointConfiguration The Dot11AccessPointAttributes to convert.
* @return AccessPointAttributes
*/
AccessPointAttributes
FromDot11AccessPointAttributes(const Dot11AccessPointAttributes& dot11AccessPointConfiguration) noexcept;

/**
* @brief Convert the specified neutral type access point attributes to the equivalent Dot11AccessPointAttributes.
*
* @param accessPointAttributes The IEEE 802.11 access point configuration to convert.
* @return Dot11AccessPointAttributes
*/
Dot11AccessPointAttributes
ToDot11AccessPointAttributes(const AccessPointAttributes& accessPointAttributes) noexcept;

} // namespace Microsoft::Net::Wifi

#endif // IEEE_80211_DOT11_ADAPTERS_HXX
40 changes: 40 additions & 0 deletions src/common/service/NetRemoteService.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utility>
#include <vector>

#include <google/protobuf/map.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/server_context.h>
#include <magic_enum.hpp>
Expand Down Expand Up @@ -420,6 +421,18 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1x([[maybe_unused]] grpc::S
return grpc::Status::OK;
}

::grpc::Status
NetRemoteService::WifiAccessPointGetAttributes([[maybe_unused]] grpc::ServerContext* context, const WifiAccessPointGetAttributesRequest* request, WifiAccessPointGetAttributesResult* result)
{
const NetRemoteWifiApiTrace traceMe{ request->accesspointid(), result->mutable_status() };

auto wifiOperationStatus = WifiAccessPointGetAttributesImpl(request->accesspointid(), *result->mutable_attributes());
result->set_accesspointid(request->accesspointid());
*result->mutable_status() = std::move(wifiOperationStatus);

return grpc::Status::OK;
}

AccessPointOperationStatus
NetRemoteService::TryGetAccessPoint(std::string_view accessPointId, std::shared_ptr<IAccessPoint>& accessPoint)
{
Expand Down Expand Up @@ -1253,3 +1266,30 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1xImpl(std::string_view acc

return wifiOperationStatus;
}

using google::protobuf::Map;

WifiAccessPointOperationStatus
NetRemoteService::WifiAccessPointGetAttributesImpl(std::string_view accessPointId, Dot11AccessPointAttributes& dot11AccessPointAttributes)
{
WifiAccessPointOperationStatus wifiOperationStatus{};

// Obtain the access point specified in the request.
std::shared_ptr<IAccessPoint> accessPoint{};
auto operationStatus = TryGetAccessPoint(accessPointId, accessPoint);
if (!operationStatus.Succeeded()) {
wifiOperationStatus.set_code(ToDot11AccessPointOperationStatusCode(operationStatus.Code));
wifiOperationStatus.set_message(std::format("Failed to get access point {} - {}", accessPointId, operationStatus.ToString()));
return wifiOperationStatus;
}

// Populate output argument with a copy of the access point attributes.
{
auto accessPointAttributes = accessPoint->GetAttributes();
dot11AccessPointAttributes = ToDot11AccessPointAttributes(accessPointAttributes);
}

wifiOperationStatus.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded);

return wifiOperationStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#define NET_REMOTE_SERVICE_HXX

#include <memory>
#include <string>
#include <string_view>

#include <google/protobuf/map.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include <microsoft/net/NetworkManager.hxx>
Expand Down Expand Up @@ -146,6 +148,17 @@ private:
grpc::Status
WifiAccessPointSetAuthenticationDot1x(grpc::ServerContext* context, const Microsoft::Net::Remote::Wifi::WifiAccessPointSetAuthenticationDot1xRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointSetAuthenticationDot1xResult* result) override;

/**
* @brief Get the properties of the specified access point.
*
* @param context
* @param request
* @param result
* @return ::grpc::Status
*/
::grpc::Status
WifiAccessPointGetAttributes(grpc::ServerContext* context, const Microsoft::Net::Remote::Wifi::WifiAccessPointGetAttributesRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointGetAttributesResult* result) override;

protected:
/**
* @brief Attempt to obtain an IAccessPoint instance for the specified access point identifier.
Expand Down Expand Up @@ -294,15 +307,25 @@ protected:

/**
* @brief Set the IEEE 802.1x configuration for the access point.
*
*
* @param accessPointId The access point identifier.
* @param dot11AuthenticationDot1x The new IEEE 802.1x configuration to set.
* @param accessPointController The access point controller for the specified access point (optional).
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointSetAuthenticationDot1xImpl(std::string_view accessPointId, const Microsoft::Net::Wifi::Dot11AuthenticationDot1x& dot11AuthenticationDot1x, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

/**
* @brief Get the sttaic attributes of the specified access point.
*
* @param accessPointId The access point identifier.
* @param dot11AccessPointAttributes Output variable to receive the access point attributes.
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointGetAttributesImpl(std::string_view accessPointId, Microsoft::Net::Wifi::Dot11AccessPointAttributes& dot11AccessPointAttributes);

private:
std::shared_ptr<Microsoft::Net::NetworkManager> m_networkManager;
std::shared_ptr<Microsoft::Net::Wifi::AccessPointManager> m_accessPointManager;
Expand Down
6 changes: 3 additions & 3 deletions src/linux/net/wifi/core/AccessPointLinux.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ using Microsoft::Net::Netlink::Nl80211::Nl80211Interface;

using namespace Microsoft::Net::Wifi;

AccessPointLinux::AccessPointLinux(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, Nl80211Interface nl80211Interface) :
AccessPoint(interfaceName, std::move(accessPointControllerFactory)),
AccessPointLinux::AccessPointLinux(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, Nl80211Interface nl80211Interface, AccessPointAttributes attributes) :
AccessPoint(interfaceName, std::move(accessPointControllerFactory), std::move(attributes)),
m_nl80211Interface{ std::move(nl80211Interface) }
{
}
Expand All @@ -42,7 +42,7 @@ AccessPointFactoryLinux::Create(std::string_view interfaceName, std::unique_ptr<
throw std::runtime_error("invalid arguments passed to AccessPointFactoryLinux::Create; this is a bug!");
}

return std::make_shared<AccessPointLinux>(interfaceName, GetControllerFactory(), std::move(createArgsLinux->Interface));
return std::make_shared<AccessPointLinux>(interfaceName, GetControllerFactory(), std::move(createArgsLinux->Interface), std::move(createArgs->Attributes));
}

AccessPointCreateArgsLinux::AccessPointCreateArgsLinux(Nl80211Interface nl80211Interface) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ struct AccessPointLinux :
* @param interfaceName The name of the interface.
* @param accessPointControllerFactory The access point controller factory to use for creating access point.
* @param nl80211Interface The nl80211 interface object.
* @param attributes The static attributes of the access point.
*/
AccessPointLinux(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, Microsoft::Net::Netlink::Nl80211::Nl80211Interface nl80211Interface);
AccessPointLinux(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, Microsoft::Net::Netlink::Nl80211::Nl80211Interface nl80211Interface, AccessPointAttributes attributes = {});

/**
* @brief Get the mac address of the access point.
Expand Down
Loading