diff --git a/src/core/hle/kernel/shared_page.cpp b/src/core/hle/kernel/shared_page.cpp index 358397486..89f1641a3 100644 --- a/src/core/hle/kernel/shared_page.cpp +++ b/src/core/hle/kernel/shared_page.cpp @@ -136,10 +136,24 @@ void Handler::SetMacAddress(const MacAddress& addr) { std::memcpy(shared_page.wifi_macaddr, addr.data(), sizeof(MacAddress)); } +MacAddress Handler::GetMacAddress() { + MacAddress addr; + std::memcpy(addr.data(), shared_page.wifi_macaddr, sizeof(MacAddress)); + return addr; +} + void Handler::SetWifiLinkLevel(WifiLinkLevel level) { shared_page.wifi_link_level = static_cast(level); } +WifiLinkLevel Handler::GetWifiLinkLevel() { + return static_cast(shared_page.wifi_link_level); +} + +void Handler::SetWifiState(WifiState state) { + shared_page.wifi_state = static_cast(state); +} + void Handler::Set3DLed(u8 state) { shared_page.ledstate_3d = state; } diff --git a/src/core/hle/kernel/shared_page.h b/src/core/hle/kernel/shared_page.h index eebda7617..7c163bdd3 100644 --- a/src/core/hle/kernel/shared_page.h +++ b/src/core/hle/kernel/shared_page.h @@ -53,10 +53,20 @@ using MacAddress = std::array; constexpr MacAddress DefaultMac = {0x40, 0xF4, 0x07, 0x00, 0x00, 0x00}; enum class WifiLinkLevel : u8 { - OFF = 0, - POOR = 1, - GOOD = 2, - BEST = 3, + Off = 0, + Poor = 1, + Good = 2, + Best = 3, +}; + +enum class WifiState : u8 { + Invalid = 0, + Enabled = 1, + Internet = 2, + Local1 = 3, + Local2 = 4, + Local3 = 6, + Disabled = 7, }; struct SharedPageDef { @@ -70,7 +80,7 @@ struct SharedPageDef { DateTime date_time_1; // 40 u8 wifi_macaddr[6]; // 60 u8 wifi_link_level; // 66 - u8 wifi_unknown2; // 67 + u8 wifi_state; // 67 INSERT_PADDING_BYTES(0x80 - 0x68); // 68 float_le sliderstate_3d; // 80 u8 ledstate_3d; // 84 @@ -90,8 +100,14 @@ public: void SetMacAddress(const MacAddress&); + MacAddress GetMacAddress(); + void SetWifiLinkLevel(WifiLinkLevel); + WifiLinkLevel GetWifiLinkLevel(); + + void SetWifiState(WifiState); + void Set3DLed(u8); void Set3DSlider(float); diff --git a/src/core/hle/service/ac/ac.cpp b/src/core/hle/service/ac/ac.cpp index 8c148aa21..70483b62e 100644 --- a/src/core/hle/service/ac/ac.cpp +++ b/src/core/hle/service/ac/ac.cpp @@ -13,6 +13,7 @@ #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" @@ -37,76 +38,143 @@ void Module::Interface::CreateDefaultConfig(Kernel::HLERequestContext& ctx) { void Module::Interface::ConnectAsync(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - rp.Skip(2, false); // ProcessId descriptor + const u32 pid = rp.PopPID(); ac->connect_event = rp.PopObject(); rp.Skip(2, false); // Buffer descriptor - if (ac->connect_event) { - ac->connect_event->SetName("AC:connect_event"); - ac->connect_event->Signal(); - ac->ac_connected = true; - } + ac->Connect(pid); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); - LOG_WARNING(Service_AC, "(STUBBED) called"); + LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid); } void Module::Interface::GetConnectResult(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - rp.Skip(2, false); // ProcessId descriptor + [[maybe_unused]] const u32 pid = rp.PopPID(); + + 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(RESULT_SUCCESS); + + LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid); } void Module::Interface::CloseAsync(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - rp.Skip(2, false); // ProcessId descriptor + const u32 pid = rp.PopPID(); ac->close_event = rp.PopObject(); - 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; + ac->Disconnect(pid); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid); } void Module::Interface::GetCloseResult(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - rp.Skip(2, false); // ProcessId descriptor + [[maybe_unused]] const u32 pid = rp.PopPID(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(RESULT_SUCCESS); - - LOG_WARNING(Service_AC, "(STUBBED) called"); + rb.Push(ac->close_result); } void Module::Interface::GetWifiStatus(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - bool can_reach_internet = false; - std::shared_ptr socu_module = SOC::GetService(Core::System::GetInstance()); - if (socu_module) { - can_reach_internet = socu_module->GetDefaultInterfaceInfo().has_value(); + if (!ac->ac_connected) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ERROR_NOT_CONNECTED); + return; } IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); - rb.Push(static_cast(can_reach_internet ? (Settings::values.is_new_3ds - ? WifiStatus::STATUS_CONNECTED_N3DS - : WifiStatus::STATUS_CONNECTED_O3DS) - : WifiStatus::STATUS_DISCONNECTED)); + rb.Push(static_cast(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(); + const u32 pid = rp.PopPID(); + + if (!ac->ac_connected) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ERROR_NOT_CONNECTED); + 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->kernel.GetSharedPageHandler(); + SharedPage::MacAddress mac = shared_page.GetMacAddress(); + + APInfo info{ + .ssid_len = static_cast(std::strlen(citra_ap)), + .bssid = mac, + .padding = 0, + .signal_strength = good_signal_strength, + .link_level = static_cast(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 out_info(len); + std::memcpy(out_info.data(), &info, std::min(len, static_cast(sizeof(info)))); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + rb.Push(RESULT_SUCCESS); + 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(ERROR_NOT_CONNECTED); + return; + } + + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); + rb.Push(RESULT_SUCCESS); + rb.Push(static_cast(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(RESULT_SUCCESS); + rb.Push(static_cast(ac->ac_connected ? NetworkStatus::STATUS_INTERNET + : NetworkStatus::STATUS_DISCONNECTED)); + + LOG_WARNING(Service_AC, "(STUBBED) called"); } void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) { @@ -115,16 +183,28 @@ void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); - rb.Push(0); // Infra Priority, default 0 + rb.Push(static_cast(InfraPriority::PRIORITY_HIGH)); LOG_WARNING(Service_AC, "(STUBBED) called"); } +void Module::Interface::SetFromApplication(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx); + const u32 unknown = rp.Pop(); + auto config = rp.PopStaticBuffer(); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + rb.Push(RESULT_SUCCESS); + rb.PushStaticBuffer(config, 0); + + LOG_WARNING(Service_AC, "(STUBBED) called, unknown={}", unknown); +} + void Module::Interface::SetRequestEulaVersion(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - u32 major = rp.Pop(); - u32 minor = rp.Pop(); + const u32 major = rp.Pop(); + const u32 minor = rp.Pop(); const std::vector& ac_config = rp.PopStaticBuffer(); @@ -137,6 +217,19 @@ 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(); + + event->Signal(); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); + + LOG_WARNING(Service_AC, "(STUBBED) called"); +} + void Module::Interface::RegisterDisconnectEvent(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); rp.Skip(2, false); // ProcessId descriptor @@ -165,46 +258,133 @@ void Module::Interface::GetConnectingProxyEnable(Kernel::HLERequestContext& ctx) void Module::Interface::IsConnected(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - u32 unk = rp.Pop(); - u32 unk_descriptor = rp.Pop(); - u32 unk_param = rp.Pop(); + const u32 unk = rp.Pop(); + const u32 pid = rp.PopPID(); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); rb.Push(ac->ac_connected); - LOG_WARNING(Service_AC, "(STUBBED) called unk=0x{:08X} descriptor=0x{:08X} param=0x{:08X}", unk, - unk_descriptor, unk_param); + LOG_DEBUG(Service_AC, "(STUBBED) called unk=0x{:08X} pid={}", unk, pid); } void Module::Interface::SetClientVersion(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - u32 version = rp.Pop(); - rp.Skip(2, false); // ProcessId descriptor + const u32 version = rp.Pop(); + rp.PopPID(); - LOG_WARNING(Service_AC, "(STUBBED) called, version: 0x{:08X}", version); + LOG_DEBUG(Service_AC, "(STUBBED) called, version: 0x{:08X}", version); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); } +u32 Module::Interface::ConnectFromHLE() { + const u32 new_fake_pid = ++ac->current_fake_pid; + ac->Connect(new_fake_pid); + return new_fake_pid; +} + +void Module::Interface::DisconnectFromHLE(u32 fake_pid) { + ac->Disconnect(fake_pid); +} + +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 = 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 = RESULT_SUCCESS; + } else { + connect_result = ERROR_ALREADY_CONNECTED; + } +} + +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 = RESULT_SUCCESS; + } else { + close_result = ERROR_NOT_CONNECTED; + } + + 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 = kernel.GetSharedPageHandler(); + shared_page.SetWifiState(SharedPage::WifiState::Enabled); + shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Off); + } +} + +bool Module::CanAccessInternet() { + std::shared_ptr socu_module = SOC::GetService(Core::System::GetInstance()); + if (socu_module) { + return socu_module->GetDefaultInterfaceInfo().has_value(); + } + return false; +} + +Module::Module(Kernel::KernelSystem& kernel) : kernel(kernel) {} + Module::Interface::Interface(std::shared_ptr ac, const char* name, u32 max_session) : ServiceFramework(name, max_session), ac(std::move(ac)) {} void InstallInterfaces(Core::System& system) { auto& service_manager = system.ServiceManager(); - auto ac = std::make_shared(); + auto ac = std::make_shared(system.Kernel()); std::make_shared(ac)->InstallAsService(service_manager); std::make_shared(ac)->InstallAsService(service_manager); } +std::shared_ptr GetService(Core::System& system) { + return system.ServiceManager().GetService("ac:u"); +} + template void Module::serialize(Archive& ar, const unsigned int) { ar& ac_connected; 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; + ar& current_fake_pid; // default_config is never written to } diff --git a/src/core/hle/service/ac/ac.h b/src/core/hle/service/ac/ac.h index 38761150b..ab810a3a8 100644 --- a/src/core/hle/service/ac/ac.h +++ b/src/core/hle/service/ac/ac.h @@ -17,8 +17,11 @@ class Event; } namespace Service::AC { +class AC_U; class Module final { public: + explicit Module(Kernel::KernelSystem& kernel); + class Interface : public ServiceFramework { public: Interface(std::shared_ptr ac, const char* name, u32 max_session); @@ -55,6 +58,15 @@ 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: @@ -75,14 +87,40 @@ 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 connection type, 0 = none, 1 = Old3DS Internet, 2 = New3DS Internet. + * 2 : Output wifi status */ 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: @@ -94,6 +132,15 @@ 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: @@ -109,6 +156,17 @@ 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: @@ -145,17 +203,59 @@ public: */ void SetClientVersion(Kernel::HLERequestContext& ctx); + // Connects from a HLE handler instead of a real thread. + // Returns a fake PID number to be used with DisconnectFromHLE + u32 ConnectFromHLE(); + + // Disconnects from a HLE handler, a fake pid given by + // ConnectFromHLE must be provided. + void DisconnectFromHLE(u32 fake_pid); + protected: std::shared_ptr ac; }; protected: + static constexpr ResultCode ERROR_NOT_CONNECTED = + ResultCode(302, ErrorModule::AC, ErrorSummary::InvalidState, ErrorLevel::Usage); + + static constexpr ResultCode ERROR_ALREADY_CONNECTED = + ResultCode(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_O3DS = 1, - STATUS_CONNECTED_N3DS = 2, + STATUS_CONNECTED_SLOT1 = (1 << 0), + STATUS_CONNECTED_SLOT2 = (1 << 1), + STATUS_CONNECTED_SLOT3 = (1 << 2), }; + enum class InfraPriority { + PRIORITY_HIGH = 0, + PRIORITY_LOW = 1, + PRIORITY_NONE = 2, + }; + + struct APInfo { + u32 ssid_len; + std::array ssid; + std::array 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 data; }; @@ -167,13 +267,38 @@ protected: std::shared_ptr close_event; std::shared_ptr connect_event; std::shared_ptr disconnect_event; + Kernel::KernelSystem& kernel; + ResultCode connect_result = RESULT_SUCCESS; + ResultCode close_result = RESULT_SUCCESS; + std::set connected_pids; + u32 current_fake_pid = 0x80000000; + + void Connect(u32 pid); + + void Disconnect(u32 pid); + + bool CanAccessInternet(); private: template void serialize(Archive& ar, const unsigned int file_version); + + template + static void load_construct(Archive& ar, Module* t, const unsigned int file_version) { + ::new (t) Module(Core::Global()); + } + + template + void save_construct(Archive& ar, const unsigned int file_version) const {} + + friend class ::construct_access; friend class boost::serialization::access; }; void InstallInterfaces(Core::System& system); +std::shared_ptr GetService(Core::System& system); + } // namespace Service::AC + +BOOST_SERIALIZATION_CONSTRUCT(Service::AC::Module); diff --git a/src/core/hle/service/ac/ac_i.cpp b/src/core/hle/service/ac/ac_i.cpp index f7766b324..bbbfb4d4d 100644 --- a/src/core/hle/service/ac/ac_i.cpp +++ b/src/core/hle/service/ac/ac_i.cpp @@ -13,18 +13,20 @@ AC_I::AC_I(std::shared_ptr ac) : Module::Interface(std::move(ac), "ac:i" {0x0001, &AC_I::CreateDefaultConfig, "CreateDefaultConfig"}, {0x0004, &AC_I::ConnectAsync, "ConnectAsync"}, {0x0005, &AC_I::GetConnectResult, "GetConnectResult"}, - {0x0007, nullptr, "CancelConnectAsync"}, + {0x0007, &AC_I::CancelConnectAsync, "CancelConnectAsync"}, {0x0008, &AC_I::CloseAsync, "CloseAsync"}, {0x0009, &AC_I::GetCloseResult, "GetCloseResult"}, {0x000A, nullptr, "GetLastErrorCode"}, - {0x000C, nullptr, "GetStatus"}, + {0x000C, &AC_I::GetStatus, "GetStatus"}, {0x000D, &AC_I::GetWifiStatus, "GetWifiStatus"}, - {0x000E, nullptr, "GetCurrentAPInfo"}, + {0x000E, &AC_I::GetCurrentAPInfo, "GetCurrentAPInfo"}, + {0x000F, &AC_I::GetConnectingInfraPriority, "GetConnectingInfraPriority"}, {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"}, {0x0030, &AC_I::RegisterDisconnectEvent, "RegisterDisconnectEvent"}, {0x0036, &AC_I::GetConnectingProxyEnable, "GetConnectingProxyEnable"}, diff --git a/src/core/hle/service/ac/ac_u.cpp b/src/core/hle/service/ac/ac_u.cpp index 12506962c..bc2af0028 100644 --- a/src/core/hle/service/ac/ac_u.cpp +++ b/src/core/hle/service/ac/ac_u.cpp @@ -13,19 +13,22 @@ AC_U::AC_U(std::shared_ptr ac) : Module::Interface(std::move(ac), "ac:u" {0x0001, &AC_U::CreateDefaultConfig, "CreateDefaultConfig"}, {0x0004, &AC_U::ConnectAsync, "ConnectAsync"}, {0x0005, &AC_U::GetConnectResult, "GetConnectResult"}, - {0x0007, nullptr, "CancelConnectAsync"}, + {0x0007, &AC_U::CancelConnectAsync, "CancelConnectAsync"}, {0x0008, &AC_U::CloseAsync, "CloseAsync"}, {0x0009, &AC_U::GetCloseResult, "GetCloseResult"}, {0x000A, nullptr, "GetLastErrorCode"}, - {0x000C, nullptr, "GetStatus"}, + {0x000C, &AC_U::GetStatus, "GetStatus"}, {0x000D, &AC_U::GetWifiStatus, "GetWifiStatus"}, - {0x000E, nullptr, "GetCurrentAPInfo"}, + {0x000E, &AC_U::GetCurrentAPInfo, "GetCurrentAPInfo"}, + {0x000F, &AC_U::GetConnectingInfraPriority, "GetConnectingInfraPriority"}, {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"}, diff --git a/src/core/hle/service/ndm/ndm_u.cpp b/src/core/hle/service/ndm/ndm_u.cpp index 90d2b0b74..15465495a 100644 --- a/src/core/hle/service/ndm/ndm_u.cpp +++ b/src/core/hle/service/ndm/ndm_u.cpp @@ -5,6 +5,8 @@ #include "common/archives.h" #include "core/core.h" #include "core/hle/ipc_helpers.h" +#include "core/hle/service/ac/ac.h" +#include "core/hle/service/ac/ac_u.h" #include "core/hle/service/ndm/ndm_u.h" SERIALIZE_EXPORT_IMPL(Service::NDM::NDM_U) @@ -210,6 +212,30 @@ void NDM_U::ClearHalfAwakeMacFilter(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_NDM, "(STUBBED)"); } +void NDM_U::ACConnectCallback(std::uintptr_t user_data, int cycles_late) { + auto ac = Service::AC::GetService(Core::System::GetInstance()); + if (ac) { + ac_fake_pid = ac->ConnectFromHLE(); + } +} + +void NDM_U::PostInstallCallback() { + // TODO(PabloMK7) Figure out how and when NDM calls AC::ConnectAsync + // and figure out with which flags and timing. + + // TODO(PabloMK7) Enable back this code once this is handled properly, + // as currently it's causing issues in some games. + /* + Core::Timing& timing = Core::System::GetInstance().CoreTiming(); + + using namespace std::placeholders; + Core::TimingEventType* connect_event = timing.RegisterEvent( + "NDM_U::ConnectAC", std::bind(&NDM_U::ACConnectCallback, this, _1, _2)); + + timing.ScheduleEvent(nsToCycles(static_cast(500'000'000ULL)), connect_event, 0, 0); + */ +} + NDM_U::NDM_U() : ServiceFramework("ndm:u", 6) { static const FunctionInfo functions[] = { // clang-format off diff --git a/src/core/hle/service/ndm/ndm_u.h b/src/core/hle/service/ndm/ndm_u.h index aebc6fa8b..163a53ee1 100644 --- a/src/core/hle/service/ndm/ndm_u.h +++ b/src/core/hle/service/ndm/ndm_u.h @@ -222,6 +222,10 @@ private: */ void ClearHalfAwakeMacFilter(Kernel::HLERequestContext& ctx); + void ACConnectCallback(std::uintptr_t user_data, int cycles_late); + + void PostInstallCallback() override; + enum class Daemon : u32 { Cec = 0, Boss = 1, @@ -271,6 +275,7 @@ private: u32 scan_interval = DEFAULT_SCAN_INTERVAL; u32 retry_interval = DEFAULT_RETRY_INTERVAL; bool daemon_lock_enabled = false; + u32 ac_fake_pid = 0; template void serialize(Archive& ar, const unsigned int) { @@ -282,6 +287,7 @@ private: ar& scan_interval; ar& retry_interval; ar& daemon_lock_enabled; + ar& ac_fake_pid; } friend class boost::serialization::access; }; diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 60a1e445e..3da4fdcb5 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -575,6 +575,10 @@ void NWM_UDS::Shutdown(Kernel::HLERequestContext& ctx) { recv_buffer_memory.reset(); + SharedPage::Handler& shared_page = Core::System::GetInstance().Kernel().GetSharedPageHandler(); + shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Off); + shared_page.SetWifiState(SharedPage::WifiState::Enabled); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(RESULT_SUCCESS); LOG_DEBUG(Service_NWM, "called"); @@ -667,6 +671,10 @@ ResultVal> NWM_UDS::Initialize( channel_data.clear(); } + SharedPage::Handler& shared_page = Core::System::GetInstance().Kernel().GetSharedPageHandler(); + shared_page.SetWifiLinkLevel(SharedPage::WifiLinkLevel::Best); + shared_page.SetWifiState(SharedPage::WifiState::Local1); + return connection_status_event; } @@ -1506,7 +1514,6 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy } system.Kernel().GetSharedPageHandler().SetMacAddress(mac); - system.Kernel().GetSharedPageHandler().SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST); if (auto room_member = Network::GetRoomMember().lock()) { wifi_packet_received = room_member->BindOnWifiPacketReceived( diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 1e4c071f2..980e5dc94 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -218,6 +218,9 @@ void Init(Core::System& core) { if (!AttemptLLE(service_module) && service_module.init_function != nullptr) service_module.init_function(core); } + + SM::ServiceManager::RunHLEPostInstallCallbacks(core); + LOG_DEBUG(Service, "initialized OK"); } diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 0b4b3ec54..72b2705ea 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -70,6 +70,9 @@ public: /// Retrieves name of a function based on the header code. For IPC Recorder. std::string GetFunctionName(IPC::Header header) const; + /// Called after all the HLE handlers have been installed. + virtual void PostInstallCallback() {} + protected: /// Member-function pointer type of SyncRequest handlers. template diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 25ca1d248..d89623d5f 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -32,6 +32,15 @@ void ServiceManager::InstallInterfaces(Core::System& system) { system.ServiceManager().srv_interface = srv; } +void ServiceManager::RunHLEPostInstallCallbacks(Core::System& system) { + for (auto& it : system.ServiceManager().registered_services) { + auto hle_handler = it.second->GetServerPort()->hle_handler; + if (hle_handler) { + reinterpret_cast(hle_handler.get())->PostInstallCallback(); + } + } +} + ResultVal> ServiceManager::RegisterService( std::string name, unsigned int max_sessions) { diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 659e14afb..520d4631b 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -49,6 +49,8 @@ class ServiceManager { public: static void InstallInterfaces(Core::System& system); + static void RunHLEPostInstallCallbacks(Core::System& system); + explicit ServiceManager(Core::System& system); ResultVal> RegisterService(std::string name,