Revert "Implement some missing/wrong AC functionality." (#5)

* Revert "Implement some missing/wrong AC functionality."

* Remove setting wifi level from nwm
This commit is contained in:
PabloMK7 2024-03-05 13:26:48 +01:00 committed by GitHub
parent cb75e1d637
commit f5316532e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 334 deletions

View File

@ -13,7 +13,6 @@
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/result.h"
#include "core/hle/service/ac/ac.h"
#include "core/hle/service/ac/ac_i.h"
@ -41,143 +40,76 @@ void Module::Interface::CreateDefaultConfig(Kernel::HLERequestContext& ctx) {
void Module::Interface::ConnectAsync(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 pid = rp.PopPID();
rp.Skip(2, false); // ProcessId descriptor
ac->connect_event = rp.PopObject<Kernel::Event>();
rp.Skip(2, false); // Buffer descriptor
ac->Connect(pid);
if (ac->connect_event) {
ac->connect_event->SetName("AC:connect_event");
ac->connect_event->Signal();
ac->ac_connected = true;
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::GetConnectResult(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
[[maybe_unused]] const u32 pid = rp.PopPID();
rp.Skip(2, false); // ProcessId descriptor
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ac->connect_result);
}
void Module::Interface::CancelConnectAsync(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 pid = rp.PopPID();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ac->ac_connected ? ErrorAlreadyConnected : ErrorNotConnected);
LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid);
rb.Push(ResultSuccess);
}
void Module::Interface::CloseAsync(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 pid = rp.PopPID();
rp.Skip(2, false); // ProcessId descriptor
ac->close_event = rp.PopObject<Kernel::Event>();
ac->Disconnect(pid);
if (ac->ac_connected && ac->disconnect_event) {
ac->disconnect_event->Signal();
}
if (ac->close_event) {
ac->close_event->SetName("AC:close_event");
ac->close_event->Signal();
}
ac->ac_connected = false;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid);
}
void Module::Interface::GetCloseResult(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
[[maybe_unused]] const u32 pid = rp.PopPID();
rp.Skip(2, false); // ProcessId descriptor
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ac->close_result);
rb.Push(ResultSuccess);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::GetWifiStatus(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
bool can_reach_internet = false;
if (!ac->ac_connected) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ErrorNotConnected);
return;
std::shared_ptr<SOC::SOC_U> socu_module = SOC::GetService(ac->system);
if (socu_module) {
can_reach_internet = socu_module->GetDefaultInterfaceInfo().has_value();
}
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u32>(static_cast<u32>(WifiStatus::STATUS_CONNECTED_SLOT1));
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::GetCurrentAPInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 len = rp.Pop<u32>();
const u32 pid = rp.PopPID();
if (!ac->ac_connected) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ErrorNotConnected);
return;
}
constexpr const char* citra_ap = "Citra_AP";
constexpr s16 good_signal_strength = 60;
constexpr u8 unknown1_value = 6;
constexpr u8 unknown2_value = 5;
constexpr u8 unknown3_value = 5;
constexpr u8 unknown4_value = 0;
SharedPage::Handler& shared_page = ac->system.Kernel().GetSharedPageHandler();
SharedPage::MacAddress mac = shared_page.GetMacAddress();
APInfo info{
.ssid_len = static_cast<u32>(std::strlen(citra_ap)),
.bssid = mac,
.padding = 0,
.signal_strength = good_signal_strength,
.link_level = static_cast<u8>(shared_page.GetWifiLinkLevel()),
.unknown1 = unknown1_value,
.unknown2 = unknown2_value,
.unknown3 = unknown3_value,
.unknown4 = unknown4_value,
};
std::strncpy(info.ssid.data(), citra_ap, info.ssid.size());
std::vector<u8> out_info(len);
std::memcpy(out_info.data(), &info, std::min(len, static_cast<u32>(sizeof(info))));
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(ResultSuccess);
rb.PushStaticBuffer(out_info, 0);
LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid);
}
void Module::Interface::GetConnectingInfraPriority(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
if (!ac->ac_connected) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ErrorNotConnected);
return;
}
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u32>(static_cast<u32>(InfraPriority::PRIORITY_HIGH));
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::GetStatus(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u32>(static_cast<u32>(ac->ac_connected ? NetworkStatus::STATUS_INTERNET
: NetworkStatus::STATUS_DISCONNECTED));
LOG_WARNING(Service_AC, "(STUBBED) called");
rb.Push<u32>(static_cast<u32>(can_reach_internet ? (Settings::values.is_new_3ds
? WifiStatus::STATUS_CONNECTED_N3DS
: WifiStatus::STATUS_CONNECTED_O3DS)
: WifiStatus::STATUS_DISCONNECTED));
}
void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) {
@ -186,28 +118,16 @@ void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u32>(static_cast<u32>(InfraPriority::PRIORITY_HIGH));
rb.Push<u32>(0); // Infra Priority, default 0
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::SetFromApplication(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 unknown = rp.Pop<u32>();
auto config = rp.PopStaticBuffer();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(ResultSuccess);
rb.PushStaticBuffer(config, 0);
LOG_WARNING(Service_AC, "(STUBBED) called, unknown={}", unknown);
}
void Module::Interface::SetRequestEulaVersion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 major = rp.Pop<u8>();
const u32 minor = rp.Pop<u8>();
u32 major = rp.Pop<u8>();
u32 minor = rp.Pop<u8>();
const std::vector<u8>& ac_config = rp.PopStaticBuffer();
@ -220,19 +140,6 @@ void Module::Interface::SetRequestEulaVersion(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_AC, "(STUBBED) called, major={}, minor={}", major, minor);
}
void Module::Interface::GetNZoneBeaconNotFoundEvent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.PopPID();
auto event = rp.PopObject<Kernel::Event>();
event->Signal();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
LOG_WARNING(Service_AC, "(STUBBED) called");
}
void Module::Interface::RegisterDisconnectEvent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(2, false); // ProcessId descriptor
@ -261,93 +168,30 @@ void Module::Interface::GetConnectingProxyEnable(Kernel::HLERequestContext& ctx)
void Module::Interface::IsConnected(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 unk = rp.Pop<u32>();
const u32 pid = rp.PopPID();
u32 unk = rp.Pop<u32>();
u32 unk_descriptor = rp.Pop<u32>();
u32 unk_param = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push(ac->ac_connected);
LOG_DEBUG(Service_AC, "(STUBBED) called unk=0x{:08X} pid={}", unk, pid);
LOG_WARNING(Service_AC, "(STUBBED) called unk=0x{:08X} descriptor=0x{:08X} param=0x{:08X}", unk,
unk_descriptor, unk_param);
}
void Module::Interface::SetClientVersion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 version = rp.Pop<u32>();
rp.PopPID();
u32 version = rp.Pop<u32>();
rp.Skip(2, false); // ProcessId descriptor
LOG_DEBUG(Service_AC, "(STUBBED) called, version: 0x{:08X}", version);
LOG_WARNING(Service_AC, "(STUBBED) called, version: 0x{:08X}", version);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void Module::Connect(u32 pid) {
if (connect_event) {
connect_event->SetName("AC:connect_event");
connect_event->Signal();
}
if (connected_pids.size() == 0) {
// TODO(PabloMK7) Publish to subscriber 0x300
ac_connected = true;
// TODO(PabloMK7) Move shared page modification to NWM once it is implemented.
SharedPage::Handler& shared_page = system.Kernel().GetSharedPageHandler();
const bool can_access_internet = CanAccessInternet();
if (can_access_internet) {
shared_page.SetWifiState(SharedPage::WifiState::Internet);
shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Best);
} else {
shared_page.SetWifiState(SharedPage::WifiState::Enabled);
shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Off);
}
}
if (connected_pids.find(pid) == connected_pids.end()) {
connected_pids.insert(pid);
connect_result = ResultSuccess;
} else {
connect_result = ErrorAlreadyConnected;
}
}
void Module::Disconnect(u32 pid) {
if (close_event) {
close_event->SetName("AC:close_event");
close_event->Signal();
}
if (connected_pids.find(pid) != connected_pids.end()) {
connected_pids.erase(pid);
close_result = ResultSuccess;
} else {
close_result = ErrorNotConnected;
}
if (connected_pids.size() == 0) {
ac_connected = false;
if (disconnect_event) {
disconnect_event->Signal();
}
// TODO(PabloMK7) Move shared page modification to NWM once it is implemented.
SharedPage::Handler& shared_page = system.Kernel().GetSharedPageHandler();
shared_page.SetWifiState(SharedPage::WifiState::Enabled);
shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Off);
}
}
bool Module::CanAccessInternet() {
std::shared_ptr<SOC::SOC_U> socu_module = SOC::GetService(system);
if (socu_module) {
return socu_module->GetDefaultInterfaceInfo().has_value();
}
return false;
}
Module::Interface::Interface(std::shared_ptr<Module> ac, const char* name, u32 max_session)
: ServiceFramework(name, max_session), ac(std::move(ac)) {}
@ -358,10 +202,6 @@ void InstallInterfaces(Core::System& system) {
std::make_shared<AC_U>(ac)->InstallAsService(service_manager);
}
std::shared_ptr<AC_U> GetService(Core::System& system) {
return system.ServiceManager().GetService<AC_U>("ac:u");
}
Module::Module(Core::System& system_) : system(system_) {}
template <class Archive>
@ -370,13 +210,6 @@ void Module::serialize(Archive& ar, const unsigned int) {
ar& close_event;
ar& connect_event;
ar& disconnect_event;
u32 connect_result_32 = connect_result.raw;
ar& connect_result_32;
connect_result.raw = connect_result_32;
u32 close_result_32 = close_result.raw;
ar& close_result_32;
close_result.raw = close_result_32;
ar& connected_pids;
// default_config is never written to
}
SERIALIZE_IMPL(Module)

View File

@ -17,7 +17,6 @@ class Event;
}
namespace Service::AC {
class AC_U;
class Module final {
public:
explicit Module(Core::System& system_);
@ -59,15 +58,6 @@ public:
*/
void GetConnectResult(Kernel::HLERequestContext& ctx);
/**
* AC::CancelConnectAsync service function
* Inputs:
* 1 : ProcessId Header
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void CancelConnectAsync(Kernel::HLERequestContext& ctx);
/**
* AC::CloseAsync service function
* Inputs:
@ -88,40 +78,14 @@ public:
*/
void GetCloseResult(Kernel::HLERequestContext& ctx);
/**
* AC::GetStatus service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output status
*/
void GetStatus(Kernel::HLERequestContext& ctx);
/**
* AC::GetWifiStatus service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output wifi status
* 2 : Output connection type, 0 = none, 1 = Old3DS Internet, 2 = New3DS Internet.
*/
void GetWifiStatus(Kernel::HLERequestContext& ctx);
/**
* AC::GetCurrentAPInfo service function
* Inputs:
* 1 : Size
* 2-3 : ProcessID
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void GetCurrentAPInfo(Kernel::HLERequestContext& ctx);
/**
* AC::GetConnectingInfraPriority service function
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : Output connecting priority
*/
void GetConnectingInfraPriority(Kernel::HLERequestContext& ctx);
/**
* AC::GetInfraPriority service function
* Inputs:
@ -133,15 +97,6 @@ public:
*/
void GetInfraPriority(Kernel::HLERequestContext& ctx);
/**
* AC::SetFromApplication service function
* Inputs:
* 1-2 : Input config
* Outputs:
* 1-2 : Output config
*/
void SetFromApplication(Kernel::HLERequestContext& ctx);
/**
* AC::SetRequestEulaVersion service function
* Inputs:
@ -157,17 +112,6 @@ public:
*/
void SetRequestEulaVersion(Kernel::HLERequestContext& ctx);
/**
* AC::GetNZoneBeaconNotFoundEvent service function
* Inputs:
* 1 : ProcessId Header
* 3 : Copy Handle Header
* 4 : Event handle, should be signaled when AC cannot find NZone
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void GetNZoneBeaconNotFoundEvent(Kernel::HLERequestContext& ctx);
/**
* AC::RegisterDisconnectEvent service function
* Inputs:
@ -209,46 +153,12 @@ public:
};
protected:
static constexpr Result ErrorNotConnected =
Result(302, ErrorModule::AC, ErrorSummary::InvalidState, ErrorLevel::Usage);
static constexpr Result ErrorAlreadyConnected =
Result(301, ErrorModule::AC, ErrorSummary::InvalidState, ErrorLevel::Usage);
enum class NetworkStatus {
STATUS_DISCONNECTED = 0,
STATUS_ENABLED = 1,
STATUS_LOCAL = 2,
STATUS_INTERNET = 3,
};
enum class WifiStatus {
STATUS_DISCONNECTED = 0,
STATUS_CONNECTED_SLOT1 = (1 << 0),
STATUS_CONNECTED_SLOT2 = (1 << 1),
STATUS_CONNECTED_SLOT3 = (1 << 2),
STATUS_CONNECTED_O3DS = 1,
STATUS_CONNECTED_N3DS = 2,
};
enum class InfraPriority {
PRIORITY_HIGH = 0,
PRIORITY_LOW = 1,
PRIORITY_NONE = 2,
};
struct APInfo {
u32 ssid_len;
std::array<char, 0x20> ssid;
std::array<u8, 0x6> bssid;
u16 padding;
s16 signal_strength;
u8 link_level;
u8 unknown1;
u8 unknown2;
u8 unknown3;
u16 unknown4;
};
static_assert(sizeof(APInfo) == 0x34, "Invalid APInfo size");
struct ACConfig {
std::array<u8, 0x200> data;
};
@ -260,15 +170,6 @@ protected:
std::shared_ptr<Kernel::Event> close_event;
std::shared_ptr<Kernel::Event> connect_event;
std::shared_ptr<Kernel::Event> disconnect_event;
Result connect_result = ResultSuccess;
Result close_result = ResultSuccess;
std::set<u32> connected_pids;
void Connect(u32 pid);
void Disconnect(u32 pid);
bool CanAccessInternet();
private:
Core::System& system;
@ -280,8 +181,6 @@ private:
void InstallInterfaces(Core::System& system);
std::shared_ptr<AC_U> GetService(Core::System& system);
} // namespace Service::AC
BOOST_CLASS_EXPORT_KEY(Service::AC::Module)

View File

@ -13,22 +13,19 @@ AC_I::AC_I(std::shared_ptr<Module> ac) : Module::Interface(std::move(ac), "ac:i"
{0x0001, &AC_I::CreateDefaultConfig, "CreateDefaultConfig"},
{0x0004, &AC_I::ConnectAsync, "ConnectAsync"},
{0x0005, &AC_I::GetConnectResult, "GetConnectResult"},
{0x0007, &AC_I::CancelConnectAsync, "CancelConnectAsync"},
{0x0007, nullptr, "CancelConnectAsync"},
{0x0008, &AC_I::CloseAsync, "CloseAsync"},
{0x0009, &AC_I::GetCloseResult, "GetCloseResult"},
{0x000A, nullptr, "GetLastErrorCode"},
{0x000C, &AC_I::GetStatus, "GetStatus"},
{0x000C, nullptr, "GetStatus"},
{0x000D, &AC_I::GetWifiStatus, "GetWifiStatus"},
{0x000E, &AC_I::GetCurrentAPInfo, "GetCurrentAPInfo"},
{0x000F, &AC_I::GetConnectingInfraPriority, "GetConnectingInfraPriority"},
{0x000E, nullptr, "GetCurrentAPInfo"},
{0x0010, nullptr, "GetCurrentNZoneInfo"},
{0x0011, nullptr, "GetNZoneApNumService"},
{0x001D, nullptr, "ScanAPs"},
{0x0024, nullptr, "AddDenyApType"},
{0x0027, &AC_I::GetInfraPriority, "GetInfraPriority"},
{0x002C, &AC_I::SetFromApplication, "SetFromApplication"},
{0x002D, &AC_I::SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x002F, &AC_I::GetNZoneBeaconNotFoundEvent, "GetNZoneBeaconNotFoundEvent"},
{0x0030, &AC_I::RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x0036, &AC_I::GetConnectingProxyEnable, "GetConnectingProxyEnable"},
{0x003C, nullptr, "GetAPSSIDList"},

View File

@ -13,22 +13,19 @@ AC_U::AC_U(std::shared_ptr<Module> ac) : Module::Interface(std::move(ac), "ac:u"
{0x0001, &AC_U::CreateDefaultConfig, "CreateDefaultConfig"},
{0x0004, &AC_U::ConnectAsync, "ConnectAsync"},
{0x0005, &AC_U::GetConnectResult, "GetConnectResult"},
{0x0007, &AC_U::CancelConnectAsync, "CancelConnectAsync"},
{0x0007, nullptr, "CancelConnectAsync"},
{0x0008, &AC_U::CloseAsync, "CloseAsync"},
{0x0009, &AC_U::GetCloseResult, "GetCloseResult"},
{0x000A, nullptr, "GetLastErrorCode"},
{0x000C, &AC_U::GetStatus, "GetStatus"},
{0x000C, nullptr, "GetStatus"},
{0x000D, &AC_U::GetWifiStatus, "GetWifiStatus"},
{0x000E, &AC_U::GetCurrentAPInfo, "GetCurrentAPInfo"},
{0x000F, &AC_U::GetConnectingInfraPriority, "GetConnectingInfraPriority"},
{0x000E, nullptr, "GetCurrentAPInfo"},
{0x0010, nullptr, "GetCurrentNZoneInfo"},
{0x0011, nullptr, "GetNZoneApNumService"},
{0x001D, nullptr, "ScanAPs"},
{0x0024, nullptr, "AddDenyApType"},
{0x0027, &AC_U::GetInfraPriority, "GetInfraPriority"},
{0x002C, &AC_U::SetFromApplication, "SetFromApplication"},
{0x002D, &AC_U::SetRequestEulaVersion, "SetRequestEulaVersion"},
{0x002F, &AC_U::GetNZoneBeaconNotFoundEvent, "GetNZoneBeaconNotFoundEvent"},
{0x0030, &AC_U::RegisterDisconnectEvent, "RegisterDisconnectEvent"},
{0x0036, &AC_U::GetConnectingProxyEnable, "GetConnectingProxyEnable"},
{0x003C, nullptr, "GetAPSSIDList"},

View File

@ -575,10 +575,6 @@ void NWM_UDS::Shutdown(Kernel::HLERequestContext& ctx) {
recv_buffer_memory.reset();
SharedPage::Handler& shared_page = system.Kernel().GetSharedPageHandler();
shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Off);
shared_page.SetWifiState(SharedPage::WifiState::Enabled);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
LOG_DEBUG(Service_NWM, "called");
@ -671,10 +667,6 @@ ResultVal<std::shared_ptr<Kernel::Event>> NWM_UDS::Initialize(
channel_data.clear();
}
SharedPage::Handler& shared_page = system.Kernel().GetSharedPageHandler();
shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Best);
shared_page.SetWifiState(SharedPage::WifiState::Local1);
return connection_status_event;
}