core: ldn: Address review comments

This commit is contained in:
Narr the Reg 2022-08-08 12:49:48 -05:00
parent 12dc05032b
commit 8eb2c73381
4 changed files with 51 additions and 61 deletions

View File

@ -8,6 +8,7 @@
#include "core/internal_network/network.h" #include "core/internal_network/network.h"
#include "core/internal_network/network_interface.h" #include "core/internal_network/network_interface.h"
// This is defined by synchapi.h and conflicts with ServiceContext::CreateEvent
#undef CreateEvent #undef CreateEvent
namespace Service::LDN { namespace Service::LDN {
@ -168,7 +169,7 @@ void IUserLocalCommunicationService::GetNetworkInfo(Kernel::HLERequestContext& c
return; return;
} }
NetworkInfo networkInfo{}; NetworkInfo network_info{};
const auto rc = ResultSuccess; const auto rc = ResultSuccess;
if (rc.IsError()) { if (rc.IsError()) {
LOG_ERROR(Service_LDN, "NetworkInfo is not valid {}", rc.raw); LOG_ERROR(Service_LDN, "NetworkInfo is not valid {}", rc.raw);
@ -178,9 +179,9 @@ void IUserLocalCommunicationService::GetNetworkInfo(Kernel::HLERequestContext& c
} }
LOG_WARNING(Service_LDN, "(STUBBED) called, ssid='{}', nodes={}", LOG_WARNING(Service_LDN, "(STUBBED) called, ssid='{}', nodes={}",
networkInfo.common.ssid.GetStringValue(), networkInfo.ldn.node_count); network_info.common.ssid.GetStringValue(), network_info.ldn.node_count);
ctx.WriteBuffer<NetworkInfo>(networkInfo); ctx.WriteBuffer<NetworkInfo>(network_info);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(rc); rb.Push(rc);
} }
@ -267,8 +268,7 @@ void IUserLocalCommunicationService::GetNetworkInfoLatestUpdate(Kernel::HLEReque
} }
NetworkInfo info; NetworkInfo info;
std::vector<NodeLatestUpdate> latest_update{}; std::vector<NodeLatestUpdate> latest_update(node_buffer_count);
latest_update.resize(node_buffer_count);
const auto rc = ResultSuccess; const auto rc = ResultSuccess;
if (rc.IsError()) { if (rc.IsError()) {
@ -311,14 +311,13 @@ void IUserLocalCommunicationService::ScanImpl(Kernel::HLERequestContext& ctx, bo
} }
u16 count = 0; u16 count = 0;
std::vector<NetworkInfo> networks_info{}; std::vector<NetworkInfo> network_infos(network_info_size);
networks_info.resize(network_info_size);
LOG_WARNING(Service_LDN, LOG_WARNING(Service_LDN,
"(STUBBED) called, channel={}, filter_scan_flag={}, filter_network_type={}", "(STUBBED) called, channel={}, filter_scan_flag={}, filter_network_type={}",
channel, scan_filter.flag, scan_filter.network_type); channel, scan_filter.flag, scan_filter.network_type);
ctx.WriteBuffer(networks_info); ctx.WriteBuffer(network_infos);
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
@ -340,31 +339,39 @@ void IUserLocalCommunicationService::CloseAccessPoint(Kernel::HLERequestContext&
} }
void IUserLocalCommunicationService::CreateNetwork(Kernel::HLERequestContext& ctx) { void IUserLocalCommunicationService::CreateNetwork(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_LDN, "(STUBBED) called");
CreateNetworkImpl(ctx, false);
}
void IUserLocalCommunicationService::CreateNetworkPrivate(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_LDN, "(STUBBED) called");
CreateNetworkImpl(ctx, true);
}
void IUserLocalCommunicationService::CreateNetworkImpl(Kernel::HLERequestContext& ctx,
bool is_private) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
struct Parameters {
SecurityConfig security_config;
UserConfig user_config;
INSERT_PADDING_WORDS_NOINIT(1);
NetworkConfig network_config;
};
static_assert(sizeof(Parameters) == 0x98, "Parameters has incorrect size.");
const auto security_config{rp.PopRaw<SecurityConfig>()}; LOG_WARNING(Service_LDN, "(STUBBED) called");
[[maybe_unused]] const auto security_parameter{is_private ? rp.PopRaw<SecurityParameter>()
: SecurityParameter{}};
const auto user_config{rp.PopRaw<UserConfig>()};
rp.Pop<u32>(); // Padding
const auto network_Config{rp.PopRaw<NetworkConfig>()};
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
} }
void IUserLocalCommunicationService::CreateNetworkPrivate(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
struct Parameters {
SecurityConfig security_config;
SecurityParameter security_parameter;
UserConfig user_config;
NetworkConfig network_config;
};
static_assert(sizeof(Parameters) == 0xB8, "Parameters has incorrect size.");
const auto parameters{rp.PopRaw<Parameters>()};
LOG_WARNING(Service_LDN, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
void IUserLocalCommunicationService::DestroyNetwork(Kernel::HLERequestContext& ctx) { void IUserLocalCommunicationService::DestroyNetwork(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_LDN, "(STUBBED) called"); LOG_WARNING(Service_LDN, "(STUBBED) called");
@ -413,14 +420,18 @@ void IUserLocalCommunicationService::Connect(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_LDN, "(STUBBED) called"); LOG_WARNING(Service_LDN, "(STUBBED) called");
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
struct Parameters {
SecurityConfig security_config;
UserConfig user_config;
u32 local_communication_version;
u32 option;
};
static_assert(sizeof(Parameters) == 0x7C, "Parameters has incorrect size.");
[[maybe_unused]] const auto securityConfig{rp.PopRaw<SecurityConfig>()}; const auto parameters{rp.PopRaw<Parameters>()};
const auto user_config{rp.PopRaw<UserConfig>()};
const auto local_communication_version{rp.Pop<u32>()};
[[maybe_unused]] const auto option{rp.Pop<u32>()};
std::vector<u8> read_buffer = ctx.ReadBuffer(); const std::vector<u8> read_buffer = ctx.ReadBuffer();
NetworkInfo networkInfo{}; NetworkInfo network_info{};
if (read_buffer.size() != sizeof(NetworkInfo)) { if (read_buffer.size() != sizeof(NetworkInfo)) {
LOG_ERROR(Frontend, "NetworkInfo doesn't match read_buffer size!"); LOG_ERROR(Frontend, "NetworkInfo doesn't match read_buffer size!");
@ -429,7 +440,7 @@ void IUserLocalCommunicationService::Connect(Kernel::HLERequestContext& ctx) {
return; return;
} }
std::memcpy(&networkInfo, read_buffer.data(), read_buffer.size()); std::memcpy(&network_info, read_buffer.data(), read_buffer.size());
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
@ -445,9 +456,6 @@ void IUserLocalCommunicationService::Initialize(Kernel::HLERequestContext& ctx)
LOG_WARNING(Service_LDN, "(STUBBED) called"); LOG_WARNING(Service_LDN, "(STUBBED) called");
const auto rc = InitializeImpl(ctx); const auto rc = InitializeImpl(ctx);
if (rc.IsError()) {
LOG_ERROR(Service_LDN, "Network isn't initialized, rc={}", rc.raw);
}
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(rc); rb.Push(rc);
@ -466,9 +474,6 @@ void IUserLocalCommunicationService::Initialize2(Kernel::HLERequestContext& ctx)
LOG_WARNING(Service_LDN, "(STUBBED) called"); LOG_WARNING(Service_LDN, "(STUBBED) called");
const auto rc = InitializeImpl(ctx); const auto rc = InitializeImpl(ctx);
if (rc.IsError()) {
LOG_ERROR(Service_LDN, "Network isn't initialized, rc={}", rc.raw);
}
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(rc); rb.Push(rc);
@ -477,6 +482,7 @@ void IUserLocalCommunicationService::Initialize2(Kernel::HLERequestContext& ctx)
Result IUserLocalCommunicationService::InitializeImpl(Kernel::HLERequestContext& ctx) { Result IUserLocalCommunicationService::InitializeImpl(Kernel::HLERequestContext& ctx) {
const auto network_interface = Network::GetSelectedNetworkInterface(); const auto network_interface = Network::GetSelectedNetworkInterface();
if (!network_interface) { if (!network_interface) {
LOG_ERROR(Service_LDN, "No network interface is set");
return ResultAirplaneModeEnabled; return ResultAirplaneModeEnabled;
} }

View File

@ -54,7 +54,6 @@ public:
void CreateNetwork(Kernel::HLERequestContext& ctx); void CreateNetwork(Kernel::HLERequestContext& ctx);
void CreateNetworkPrivate(Kernel::HLERequestContext& ctx); void CreateNetworkPrivate(Kernel::HLERequestContext& ctx);
void CreateNetworkImpl(Kernel::HLERequestContext& ctx, bool is_private);
void DestroyNetwork(Kernel::HLERequestContext& ctx); void DestroyNetwork(Kernel::HLERequestContext& ctx);

View File

@ -1,6 +1,5 @@
// Copyright 2022 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// Licensed under GPLv2 or any later version // SPDX-License-Identifier: GPL-3.0-or-later
// Refer to the license.txt file included.
#pragma once #pragma once

View File

@ -1,6 +1,5 @@
// Copyright 2022 yuzu emulator team // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// Licensed under GPLv2 or any later version // SPDX-License-Identifier: GPL-3.0-or-later
// Refer to the license.txt file included.
#pragma once #pragma once
@ -32,14 +31,6 @@ enum class NodeStateChange : u8 {
DisconnectAndConnect, DisconnectAndConnect,
}; };
inline NodeStateChange operator|(NodeStateChange a, NodeStateChange b) {
return static_cast<NodeStateChange>(static_cast<u8>(a) | static_cast<u8>(b));
}
inline NodeStateChange operator|=(NodeStateChange& a, NodeStateChange b) {
return a = a | b;
}
enum class ScanFilterFlag : u32 { enum class ScanFilterFlag : u32 {
None = 0, None = 0,
LocalCommunicationId = 1 << 0, LocalCommunicationId = 1 << 0,
@ -135,10 +126,7 @@ struct SessionId {
u64 high; u64 high;
u64 low; u64 low;
public: bool operator==(const SessionId&) const = default;
bool operator==(const SessionId& b) const {
return (low == b.low) && (high == b.high);
}
}; };
static_assert(sizeof(SessionId) == 0x10, "SessionId is an invalid size"); static_assert(sizeof(SessionId) == 0x10, "SessionId is an invalid size");
@ -160,7 +148,6 @@ struct Ssid {
u8 length; u8 length;
std::array<char, SsidLengthMax + 1> raw; std::array<char, SsidLengthMax + 1> raw;
public:
std::string GetStringValue() const { std::string GetStringValue() const {
return std::string(raw.data(), length); return std::string(raw.data(), length);
} }
@ -173,7 +160,6 @@ struct Ipv4Address {
std::array<u8, 4> bytes; std::array<u8, 4> bytes;
}; };
public:
std::string GetStringValue() const { std::string GetStringValue() const {
return fmt::format("{}.{}.{}.{}", bytes[3], bytes[2], bytes[1], bytes[0]); return fmt::format("{}.{}.{}.{}", bytes[3], bytes[2], bytes[1], bytes[0]);
} }