Skip to content

Commit

Permalink
Overhaul properties -> attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jul 27, 2024
1 parent 3e8a214 commit c8fd895
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 72 deletions.
2 changes: 1 addition & 1 deletion protocol/protos/NetRemoteService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +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 WifiAccessPointGetProperties (Microsoft.Net.Remote.Wifi.WifiAccessPointGetPropertiesRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointGetPropertiesResult);
rpc WifiAccessPointGetAttributes (Microsoft.Net.Remote.Wifi.WifiAccessPointGetAttributesRequest) returns (Microsoft.Net.Remote.Wifi.WifiAccessPointGetAttributesResult);
}
6 changes: 3 additions & 3 deletions protocol/protos/NetRemoteWifi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ message WifiAccessPointSetAuthenticationDot1xResult
WifiAccessPointOperationStatus Status = 2;
}

message WifiAccessPointGetPropertiesRequest
message WifiAccessPointGetAttributesRequest
{
string AccessPointId = 1;
}

message WifiAccessPointGetPropertiesResult
message WifiAccessPointGetAttributesResult
{
string AccessPointId = 1;
WifiAccessPointOperationStatus Status = 2;
repeated string Properties = 3;
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
10 changes: 5 additions & 5 deletions src/common/net/wifi/core/AccessPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

using namespace Microsoft::Net::Wifi;

AccessPoint::AccessPoint(std::string_view interfaceName, std::shared_ptr<IAccessPointControllerFactory> accessPointControllerFactory, AccessPointProperties properties, 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_properties(std::move(properties)),
m_attributes(std::move(attributes)),
m_macAddress(macAddress)
{}

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

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

std::unique_ptr<IAccessPointController>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ struct AccessPoint :
*
* @param interfaceName The network interface name representing the access point.
* @param accessPointControllerFactory The factory used to create controller objects.
* @param properties The static properties of the access point.
* @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, AccessPointProperties properties = {}, 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 @@ -46,12 +46,12 @@ struct AccessPoint :
GetMacAddress() const noexcept override;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

#include <microsoft/net/wifi/IAccessPointController.hxx>
#include <microsoft/net/wifi/Ieee80211.hxx>
Expand All @@ -12,11 +13,11 @@ namespace Microsoft::Net::Wifi
{

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

/**
Expand Down Expand Up @@ -61,12 +62,12 @@ struct IAccessPoint
GetMacAddress() const noexcept = 0;

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

/**
* @brief Create a new instance that can control the access point.
Expand Down Expand Up @@ -99,7 +100,7 @@ struct IAccessPointCreateArgs
IAccessPointCreateArgs&
operator=(IAccessPointCreateArgs&&) = delete;

AccessPointProperties Properties{};
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
19 changes: 8 additions & 11 deletions src/common/service/NetRemoteService.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <utility>
#include <vector>

#include <google/protobuf/repeated_ptr_field.h>
#include <google/protobuf/map.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/server_context.h>
#include <magic_enum.hpp>
Expand Down Expand Up @@ -422,11 +422,11 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1x([[maybe_unused]] grpc::S
}

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

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

Expand Down Expand Up @@ -1267,10 +1267,10 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1xImpl(std::string_view acc
return wifiOperationStatus;
}

using google::protobuf::RepeatedPtrField;
using google::protobuf::Map;

WifiAccessPointOperationStatus
NetRemoteService::WifiAccessPointGetPropertiesImpl(std::string_view accessPointId, RepeatedPtrField<std::string>& accessPointProperties)
NetRemoteService::WifiAccessPointGetAttributesImpl(std::string_view accessPointId, Dot11AccessPointAttributes& dot11AccessPointAttributes)
{
WifiAccessPointOperationStatus wifiOperationStatus{};

Expand All @@ -1283,13 +1283,10 @@ NetRemoteService::WifiAccessPointGetPropertiesImpl(std::string_view accessPointI
return wifiOperationStatus;
}

// Populate output argument with a copy of the access point properties.
// Populate output argument with a copy of the access point attributes.
{
auto properties = accessPoint->GetProperties();
accessPointProperties = {
std::make_move_iterator(std::begin(properties.Properties)),
std::make_move_iterator(std::end(properties.Properties)),
};
auto accessPointAttributes = accessPoint->GetAttributes();
dot11AccessPointAttributes = ToDot11AccessPointAttributes(accessPointAttributes);
}

wifiOperationStatus.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <string_view>

#include <google/protobuf/repeated_ptr_field.h>
#include <google/protobuf/map.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include <microsoft/net/NetworkManager.hxx>
Expand Down Expand Up @@ -157,7 +157,7 @@ private:
* @return ::grpc::Status
*/
::grpc::Status
WifiAccessPointGetProperties(grpc::ServerContext* context, const Microsoft::Net::Remote::Wifi::WifiAccessPointGetPropertiesRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointGetPropertiesResult* result) override;
WifiAccessPointGetAttributes(grpc::ServerContext* context, const Microsoft::Net::Remote::Wifi::WifiAccessPointGetAttributesRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointGetAttributesResult* result) override;

protected:
/**
Expand Down Expand Up @@ -317,14 +317,14 @@ protected:
WifiAccessPointSetAuthenticationDot1xImpl(std::string_view accessPointId, const Microsoft::Net::Wifi::Dot11AuthenticationDot1x& dot11AuthenticationDot1x, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

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

private:
std::shared_ptr<Microsoft::Net::NetworkManager> m_networkManager;
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, AccessPointProperties properties) :
AccessPoint(interfaceName, std::move(accessPointControllerFactory), std::move(properties)),
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), std::move(createArgs->Properties));
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,9 +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 properties The static properties of the access point.
* @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, AccessPointProperties properties = {});
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

0 comments on commit c8fd895

Please sign in to comment.