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

Print access point capabilities in netremote-cli #118

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 73 additions & 3 deletions src/common/tools/cli/NetRemoteCliHandlerOperations.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#include <format>
#include <sstream>

#include <grpcpp/client_context.h>
#include <magic_enum.hpp>
Expand All @@ -17,6 +19,63 @@ NetRemoteCliHandlerOperations::NetRemoteCliHandlerOperations(std::shared_ptr<Net
{
}

namespace detail
{
/**
* @brief Generate a string representation of a AccessPointCapabilities object.
*
* @param accessPointCapabilities The object to generate a string representation of.
* @param indentationLevel The indentation level to use.
* @param indentation The number of spaces in each indentation level.
* @return std::string
*/
std::string
NetRemoteAccessPointCapabilitiesToString(const Microsoft::Net::Wifi::AccessPointCapabilities& accessPointCapabilities, std::size_t indentationLevel = 1, std::size_t indentation = 2)
{
const auto indent0 = std::string((indentationLevel + 0) * indentation, ' ');
const auto indent1 = std::string((indentationLevel + 1) * indentation, ' ');

std::stringstream ss;

ss << indent0
<< "Phy Types:";
for (const auto& phyType : accessPointCapabilities.phytypes()) {
ss << '\n'
<< indent1
<< magic_enum::enum_name(static_cast<Microsoft::Net::Wifi::Dot11PhyType>(phyType));
}

ss << '\n'
<< indent0
<< "Bands:";
for (const auto& band : accessPointCapabilities.bands()) {
ss << '\n'
<< indent1
<< magic_enum::enum_name(static_cast<Microsoft::Net::Wifi::RadioBand>(band));
}

ss << '\n'
<< indent0
<< "Authentication Algorithms:";
for (const auto& authenticationAlgorithm : accessPointCapabilities.authenticationalgorithms()) {
ss << '\n'
<< indent1
<< magic_enum::enum_name(static_cast<Microsoft::Net::Wifi::Dot11AuthenticationAlgorithm>(authenticationAlgorithm));
}

ss << '\n'
<< indent0
<< "Cipher Algorithms:";
for (const auto& ciperAlgorithm : accessPointCapabilities.encryptionalgorithms()) {
ss << '\n'
<< indent1
<< magic_enum::enum_name(static_cast<Microsoft::Net::Wifi::Dot11CipherAlgorithm>(ciperAlgorithm));
}

return ss.str();
}
} // namespace detail

void
NetRemoteCliHandlerOperations::WifiEnumerateAccessPoints()
{
Expand All @@ -30,11 +89,22 @@ NetRemoteCliHandlerOperations::WifiEnumerateAccessPoints()
return;
}

LOGI << std::format("{} access points discovered", result.accesspoints_size());
if (result.accesspoints().empty()) {
LOGI << "No access points found";
return;
}

std::size_t numAccessPoint = 1;
for (const auto& accessPoint : result.accesspoints()) {
LOGI << std::format(" - [{}]", accessPoint.accesspointid());
LOGI << std::format(" - {}", accessPoint.isenabled() ? "enabled" : "disabled");
std::stringstream ss;
ss << '[' << numAccessPoint++ << "] " << accessPoint.accesspointid();
if (!accessPoint.isenabled()) {
ss << " (disabled)";
}
ss << '\n'
<< detail::NetRemoteAccessPointCapabilitiesToString(accessPoint.capabilities())
<< '\n';
LOGI << ss.str();
}
}

Expand Down
Loading