From 5682608df76b614cadff6061cff35dcf100b944b Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 13:01:21 -0500 Subject: Services/APT: Use boost::optional for the APT parameter structure. --- src/core/hle/service/apt/apt.cpp | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index df4b5cc3f..e4068926a 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "common/common_paths.h" #include "common/file_util.h" #include "common/logging/log.h" @@ -44,7 +45,7 @@ static u8 unknown_ns_state_field; static ScreencapPostPermission screen_capture_post_permission; /// Parameter data to be returned in the next call to Glance/ReceiveParameter -static MessageParameter next_parameter; +static boost::optional next_parameter; void SendParameter(const MessageParameter& parameter) { next_parameter = parameter; @@ -227,18 +228,20 @@ void ReceiveParameter(Service::Interface* self) { buffer_size, static_buff_size); IPC::RequestBuilder rb = rp.MakeBuilder(4, 4); + rb.Push(RESULT_SUCCESS); // No error - rb.Push(next_parameter.sender_id); - rb.Push(next_parameter.signal); // Signal type - ASSERT_MSG(next_parameter.buffer.size() <= buffer_size, "Input static buffer is too small !"); - rb.Push(static_cast(next_parameter.buffer.size())); // Parameter buffer size + rb.Push(next_parameter->sender_id); + rb.Push(next_parameter->signal); // Signal type + ASSERT_MSG(next_parameter->buffer.size() <= buffer_size, "Input static buffer is too small !"); + rb.Push(static_cast(next_parameter->buffer.size())); // Parameter buffer size - rb.PushMoveHandles((next_parameter.object != nullptr) - ? Kernel::g_handle_table.Create(next_parameter.object).Unwrap() + rb.PushMoveHandles((next_parameter->object != nullptr) + ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter.buffer.size()), 0); - Memory::WriteBlock(buffer, next_parameter.buffer.data(), next_parameter.buffer.size()); + rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + + Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); LOG_WARNING(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } @@ -258,17 +261,18 @@ void GlanceParameter(Service::Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(4, 4); rb.Push(RESULT_SUCCESS); // No error - rb.Push(next_parameter.sender_id); - rb.Push(next_parameter.signal); // Signal type - ASSERT_MSG(next_parameter.buffer.size() <= buffer_size, "Input static buffer is too small !"); - rb.Push(static_cast(next_parameter.buffer.size())); // Parameter buffer size + rb.Push(next_parameter->sender_id); + rb.Push(next_parameter->signal); // Signal type + ASSERT_MSG(next_parameter->buffer.size() <= buffer_size, "Input static buffer is too small !"); + rb.Push(static_cast(next_parameter->buffer.size())); // Parameter buffer size - rb.PushCopyHandles((next_parameter.object != nullptr) - ? Kernel::g_handle_table.Create(next_parameter.object).Unwrap() + rb.PushMoveHandles((next_parameter->object != nullptr) + ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter.buffer.size()), 0); - Memory::WriteBlock(buffer, next_parameter.buffer.data(), next_parameter.buffer.size()); + rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + + Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); LOG_WARNING(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } @@ -800,8 +804,10 @@ void Init() { notification_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Notification"); parameter_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Start"); - next_parameter.signal = static_cast(SignalType::Wakeup); - next_parameter.destination_id = 0x300; + // Initialize the parameter to wake up the application. + next_parameter.emplace(); + next_parameter->signal = static_cast(SignalType::Wakeup); + next_parameter->destination_id = static_cast(AppletId::Application); } void Shutdown() { @@ -812,7 +818,7 @@ void Shutdown() { notification_event = nullptr; parameter_event = nullptr; - next_parameter.object = nullptr; + next_parameter = boost::none; HLE::Applets::Shutdown(); } -- cgit v1.2.3 From 2dc720c355dad55a607c1f993fc823cc198bed08 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 13:02:40 -0500 Subject: Services/APT: Use the right error codes in ReceiveParameter and GlanceParameter when the parameter doesn't exist. --- src/core/hle/service/apt/apt.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index e4068926a..b5748693f 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -227,6 +227,20 @@ void ReceiveParameter(Service::Interface* self) { "buffer_size is bigger than the size in the buffer descriptor (0x%08X > 0x%08zX)", buffer_size, static_buff_size); + if (!next_parameter) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::NoData, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } + + if (next_parameter->destination_id != app_id) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::Applet, ErrorSummary::NotFound, + ErrorLevel::Status)); + return; + } + IPC::RequestBuilder rb = rp.MakeBuilder(4, 4); rb.Push(RESULT_SUCCESS); // No error @@ -259,6 +273,20 @@ void GlanceParameter(Service::Interface* self) { "buffer_size is bigger than the size in the buffer descriptor (0x%08X > 0x%08zX)", buffer_size, static_buff_size); + if (!next_parameter) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::NoData, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } + + if (next_parameter->destination_id != app_id) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::Applet, ErrorSummary::NotFound, + ErrorLevel::Status)); + return; + } + IPC::RequestBuilder rb = rp.MakeBuilder(4, 4); rb.Push(RESULT_SUCCESS); // No error rb.Push(next_parameter->sender_id); -- cgit v1.2.3 From e403638d9b2cbd7f7dbacd14c3c4bf9863bf7b34 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 13:03:28 -0500 Subject: Services/APT: Properly clear the apt parameter after a successful ReceiveParameter call. --- src/core/hle/service/apt/apt.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index b5748693f..b6c013d43 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -257,7 +257,9 @@ void ReceiveParameter(Service::Interface* self) { Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); - LOG_WARNING(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); + // Clear the parameter + next_parameter = boost::none; + LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } void GlanceParameter(Service::Interface* self) { @@ -302,7 +304,11 @@ void GlanceParameter(Service::Interface* self) { Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); - LOG_WARNING(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); + // Note: The NS module always clears the DSPSleep and DSPWakeup signals even in GlanceParameter. + if (next_parameter->signal == static_cast(SignalType::DspSleep) || + next_parameter->signal == static_cast(SignalType::DspWakeup)) + next_parameter = boost::none; + LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } void CancelParameter(Service::Interface* self) { -- cgit v1.2.3 From a9bc417f5948dc63f182d31e4ba271aa23efe84d Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 13:09:45 -0500 Subject: Services/APT: Reset the APT parameter inside CancelParameter if the conditions are met. --- src/core/hle/service/apt/apt.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index b6c013d43..9cfb7f71e 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -314,17 +314,34 @@ void GlanceParameter(Service::Interface* self) { void CancelParameter(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0xF, 4, 0); // 0xF0100 - u32 check_sender = rp.Pop(); + bool check_sender = rp.Pop(); u32 sender_appid = rp.Pop(); - u32 check_receiver = rp.Pop(); + bool check_receiver = rp.Pop(); u32 receiver_appid = rp.Pop(); + + bool cancellation_success = true; + + if (!next_parameter) { + cancellation_success = false; + } else { + if (check_sender && next_parameter->sender_id != sender_appid) + cancellation_success = false; + + if (check_receiver && next_parameter->destination_id != receiver_appid) + cancellation_success = false; + } + + if (cancellation_success) + next_parameter = boost::none; + IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); + rb.Push(RESULT_SUCCESS); // No error - rb.Push(true); // Set to Success + rb.Push(cancellation_success); - LOG_WARNING(Service_APT, "(STUBBED) called check_sender=0x%08X, sender_appid=0x%08X, " - "check_receiver=0x%08X, receiver_appid=0x%08X", - check_sender, sender_appid, check_receiver, receiver_appid); + LOG_DEBUG(Service_APT, "called check_sender=%u, sender_appid=0x%08X, " + "check_receiver=%u, receiver_appid=0x%08X", + check_sender, sender_appid, check_receiver, receiver_appid); } void PrepareToStartApplication(Service::Interface* self) { -- cgit v1.2.3 From 68596a706860f37de876ca070f9de6e664df0d05 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 13:19:55 -0500 Subject: Services/APT: Return the proper error code when calling SendParameter with an outstanding parameter already in memory. --- src/core/hle/service/apt/apt.cpp | 15 +++++++++++---- src/core/hle/service/apt/apt.h | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 9cfb7f71e..987fb0992 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -192,6 +192,13 @@ void SendParameter(Service::Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + // A new parameter can not be sent if the previous one hasn't been consumed yet + if (next_parameter) { + rb.Push(ResultCode(ErrCodes::ParameterPresent, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } + if (dest_applet == nullptr) { LOG_ERROR(Service_APT, "Unknown applet id=0x%08X", dst_app_id); rb.Push(-1); // TODO(Subv): Find the right error code @@ -208,10 +215,10 @@ void SendParameter(Service::Interface* self) { rb.Push(dest_applet->ReceiveParameter(param)); - LOG_WARNING(Service_APT, - "(STUBBED) called src_app_id=0x%08X, dst_app_id=0x%08X, signal_type=0x%08X," - "buffer_size=0x%08X, handle=0x%08X, size=0x%08zX, in_param_buffer_ptr=0x%08X", - src_app_id, dst_app_id, signal_type, buffer_size, handle, size, buffer); + LOG_DEBUG(Service_APT, + "called src_app_id=0x%08X, dst_app_id=0x%08X, signal_type=0x%08X," + "buffer_size=0x%08X, handle=0x%08X, size=0x%08zX, in_param_buffer_ptr=0x%08X", + src_app_id, dst_app_id, signal_type, buffer_size, handle, size, buffer); } void ReceiveParameter(Service::Interface* self) { diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h index ee80926d2..106754853 100644 --- a/src/core/hle/service/apt/apt.h +++ b/src/core/hle/service/apt/apt.h @@ -116,6 +116,12 @@ enum class ScreencapPostPermission : u32 { DisableScreenshotPostingToMiiverse = 3 }; +namespace ErrCodes { +enum { + ParameterPresent = 2, +}; +} + /// Send a parameter to the currently-running application, which will read it via ReceiveParameter void SendParameter(const MessageParameter& parameter); -- cgit v1.2.3 From e59ab7c1d695e3eb303c5dd37cd0fde814657f53 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 15:03:06 -0500 Subject: Service/APT: Log Send/Cancel/Receive/GlanceParameter calls even if they return an error. --- src/core/hle/service/apt/apt.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 987fb0992..aad23e900 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -190,6 +190,11 @@ void SendParameter(Service::Interface* self) { std::shared_ptr dest_applet = HLE::Applets::Applet::Get(static_cast(dst_app_id)); + LOG_DEBUG(Service_APT, + "called src_app_id=0x%08X, dst_app_id=0x%08X, signal_type=0x%08X," + "buffer_size=0x%08X, handle=0x%08X, size=0x%08zX, in_param_buffer_ptr=0x%08X", + src_app_id, dst_app_id, signal_type, buffer_size, handle, size, buffer); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); // A new parameter can not be sent if the previous one hasn't been consumed yet @@ -214,11 +219,6 @@ void SendParameter(Service::Interface* self) { Memory::ReadBlock(buffer, param.buffer.data(), param.buffer.size()); rb.Push(dest_applet->ReceiveParameter(param)); - - LOG_DEBUG(Service_APT, - "called src_app_id=0x%08X, dst_app_id=0x%08X, signal_type=0x%08X," - "buffer_size=0x%08X, handle=0x%08X, size=0x%08zX, in_param_buffer_ptr=0x%08X", - src_app_id, dst_app_id, signal_type, buffer_size, handle, size, buffer); } void ReceiveParameter(Service::Interface* self) { @@ -234,6 +234,8 @@ void ReceiveParameter(Service::Interface* self) { "buffer_size is bigger than the size in the buffer descriptor (0x%08X > 0x%08zX)", buffer_size, static_buff_size); + LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); + if (!next_parameter) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultCode(ErrorDescription::NoData, ErrorModule::Applet, @@ -266,7 +268,6 @@ void ReceiveParameter(Service::Interface* self) { // Clear the parameter next_parameter = boost::none; - LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } void GlanceParameter(Service::Interface* self) { @@ -282,6 +283,8 @@ void GlanceParameter(Service::Interface* self) { "buffer_size is bigger than the size in the buffer descriptor (0x%08X > 0x%08zX)", buffer_size, static_buff_size); + LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); + if (!next_parameter) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); rb.Push(ResultCode(ErrorDescription::NoData, ErrorModule::Applet, @@ -315,7 +318,6 @@ void GlanceParameter(Service::Interface* self) { if (next_parameter->signal == static_cast(SignalType::DspSleep) || next_parameter->signal == static_cast(SignalType::DspWakeup)) next_parameter = boost::none; - LOG_DEBUG(Service_APT, "called app_id=0x%08X, buffer_size=0x%08zX", app_id, buffer_size); } void CancelParameter(Service::Interface* self) { -- cgit v1.2.3 From 5c631ec9c50482e8b34d0a6f3496b5beb1648230 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 1 Aug 2017 20:00:40 -0400 Subject: telemetry: Add field for RequiresSharedFont. --- src/core/hle/service/apt/apt.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 4e6b7b6f5..0109fa2b2 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -75,6 +75,10 @@ void Initialize(Service::Interface* self) { void GetSharedFont(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x44, 0, 0); // 0x00440000 IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); + + // Log in telemetry if the game uses the shared font + Core::Telemetry().AddField(Telemetry::FieldType::Session, "RequiresSharedFont", true); + if (!shared_font_loaded) { LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds"); rb.Push(-1); // TODO: Find the right error code -- cgit v1.2.3 From 73fba0de46aef0b18ef0ef5221cc23a60be4cb6c Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 22 Jul 2017 12:33:03 -0500 Subject: Services/APT: Use an array to hold data about the 4 possible concurrent applet types (Application, Library, HomeMenu, System). This gives each applet type its own set of events as per the real NS module. --- src/core/hle/service/apt/apt.cpp | 233 +++++++++++++++++++++++++++++++++------ src/core/hle/service/apt/apt.h | 6 +- 2 files changed, 204 insertions(+), 35 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 0109fa2b2..9cfa9efde 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -34,8 +34,6 @@ static bool shared_font_loaded = false; static bool shared_font_relocated = false; static Kernel::SharedPtr lock; -static Kernel::SharedPtr notification_event; ///< APT notification event -static Kernel::SharedPtr parameter_event; ///< APT parameter event static u32 cpu_percent; ///< CPU time available to the running application @@ -44,32 +42,164 @@ static u8 unknown_ns_state_field; static ScreencapPostPermission screen_capture_post_permission; -/// Parameter data to be returned in the next call to Glance/ReceiveParameter +/// Parameter data to be returned in the next call to Glance/ReceiveParameter. +/// TODO(Subv): Use std::optional once we migrate to C++17. static boost::optional next_parameter; +enum class AppletPos { Application = 0, Library = 1, System = 2, SysLibrary = 3, Resident = 4 }; + +static constexpr size_t NumAppletSlot = 4; + +enum class AppletSlot : u8 { + Application, + SystemApplet, + HomeMenu, + LibraryApplet, + + // An invalid tag + Error, +}; + +struct AppletSlotData { + AppletId applet_id; + AppletSlot slot; + bool registered; + u32 attributes; + Kernel::SharedPtr notification_event; + Kernel::SharedPtr parameter_event; +}; + +// Holds data about the concurrently running applets in the system. +static std::array applet_slots = {}; + +union AppletAttributes { + u32 raw; + + BitField<0, 3, u32> applet_pos; + + AppletAttributes(u32 attributes) : raw(attributes) {} +}; + +// Helper function to extract the AppletPos from the lower bits of the applet attributes +static u32 GetAppletPos(AppletAttributes attributes) { + return attributes.applet_pos; +} + +// This overload returns nullptr if no applet with the specified id has been started. +static AppletSlotData* GetAppletSlotData(AppletId id) { + auto GetSlot = [](AppletSlot slot) -> AppletSlotData* { + return &applet_slots[static_cast(slot)]; + }; + + if (id == AppletId::Application) { + auto* slot = GetSlot(AppletSlot::Application); + if (slot->applet_id != AppletId::None) + return slot; + + return nullptr; + } + + if (id == AppletId::AnySystemApplet) { + auto* system_slot = GetSlot(AppletSlot::SystemApplet); + if (system_slot->applet_id != AppletId::None) + return system_slot; + + // The Home Menu is also a system applet, but it lives in its own slot to be able to run + // concurrently with other system applets. + auto* home_slot = GetSlot(AppletSlot::HomeMenu); + if (home_slot->applet_id != AppletId::None) + return home_slot; + + return nullptr; + } + + if (id == AppletId::AnyLibraryApplet || id == AppletId::AnySysLibraryApplet) { + auto* slot = GetSlot(AppletSlot::LibraryApplet); + if (slot->applet_id == AppletId::None) + return nullptr; + + u32 applet_pos = GetAppletPos(slot->attributes); + + if (id == AppletId::AnyLibraryApplet && applet_pos == static_cast(AppletPos::Library)) + return slot; + + if (id == AppletId::AnySysLibraryApplet && + applet_pos == static_cast(AppletPos::SysLibrary)) + return slot; + + return nullptr; + } + + if (id == AppletId::HomeMenu || id == AppletId::AlternateMenu) { + auto* slot = GetSlot(AppletSlot::HomeMenu); + if (slot->applet_id != AppletId::None) + return slot; + + return nullptr; + } + + for (auto& slot : applet_slots) { + if (slot.applet_id == id) + return &slot; + } + + return nullptr; +} + +static AppletSlotData* GetAppletSlotData(u32 attributes) { + // Mapping from AppletPos to AppletSlot + static constexpr std::array applet_position_slots = { + AppletSlot::Application, AppletSlot::LibraryApplet, AppletSlot::SystemApplet, + AppletSlot::LibraryApplet, AppletSlot::Error, AppletSlot::LibraryApplet}; + + u32 applet_pos = GetAppletPos(attributes); + if (applet_pos >= applet_position_slots.size()) + return nullptr; + + AppletSlot slot = applet_position_slots[applet_pos]; + + if (slot == AppletSlot::Error) + return nullptr; + + return &applet_slots[static_cast(slot)]; +} + void SendParameter(const MessageParameter& parameter) { next_parameter = parameter; - // Signal the event to let the application know that a new parameter is ready to be read - parameter_event->Signal(); + // Signal the event to let the receiver know that a new parameter is ready to be read + auto* const slot_data = GetAppletSlotData(static_cast(parameter.destination_id)); + ASSERT(slot_data); + + slot_data->parameter_event->Signal(); } void Initialize(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x2, 2, 0); // 0x20080 u32 app_id = rp.Pop(); - u32 flags = rp.Pop(); - IPC::RequestBuilder rb = rp.MakeBuilder(1, 3); - rb.Push(RESULT_SUCCESS); - rb.PushCopyHandles(Kernel::g_handle_table.Create(notification_event).Unwrap(), - Kernel::g_handle_table.Create(parameter_event).Unwrap()); + u32 attributes = rp.Pop(); + + LOG_DEBUG(Service_APT, "called app_id=0x%08X, attributes=0x%08X", app_id, attributes); + + auto* const slot_data = GetAppletSlotData(attributes); + + // Note: The real NS service does not check if the attributes value is valid before accessing + // the data in the array + ASSERT_MSG(slot_data, "Invalid application attributes"); - // TODO(bunnei): Check if these events are cleared every time Initialize is called. - notification_event->Clear(); - parameter_event->Clear(); + if (slot_data->registered) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(ResultCode(ErrorDescription::AlreadyExists, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } - ASSERT_MSG((nullptr != lock), "Cannot initialize without lock"); - lock->Release(); + slot_data->applet_id = static_cast(app_id); + slot_data->attributes = attributes; - LOG_DEBUG(Service_APT, "called app_id=0x%08X, flags=0x%08X", app_id, flags); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 3); + rb.Push(RESULT_SUCCESS); + rb.PushCopyHandles(Kernel::g_handle_table.Create(slot_data->notification_event).Unwrap(), + Kernel::g_handle_table.Create(slot_data->parameter_event).Unwrap()); } void GetSharedFont(Service::Interface* self) { @@ -120,7 +250,12 @@ void GetLockHandle(Service::Interface* self) { // this will cause the app to wait until parameter_event is signaled. u32 applet_attributes = rp.Pop(); IPC::RequestBuilder rb = rp.MakeBuilder(3, 2); - rb.Push(RESULT_SUCCESS); // No error + rb.Push(RESULT_SUCCESS); // No error + + // TODO(Subv): The output attributes should have an AppletPos of either Library or System | + // Library (depending on the type of the last launched applet) if the input attributes' + // AppletPos has the Library bit set. + rb.Push(applet_attributes); // Applet Attributes, this value is passed to Enable. rb.Push(0); // Least significant bit = power button state Kernel::Handle handle_copy = Kernel::g_handle_table.Create(lock).Unwrap(); @@ -133,10 +268,22 @@ void GetLockHandle(Service::Interface* self) { void Enable(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x3, 1, 0); // 0x30040 u32 attributes = rp.Pop(); + + LOG_DEBUG(Service_APT, "called attributes=0x%08X", attributes); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(RESULT_SUCCESS); // No error - parameter_event->Signal(); // Let the application know that it has been started - LOG_WARNING(Service_APT, "(STUBBED) called attributes=0x%08X", attributes); + + auto* const slot_data = GetAppletSlotData(attributes); + + if (!slot_data) { + rb.Push(ResultCode(ErrCodes::InvalidAppletSlot, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } + + slot_data->registered = true; + + rb.Push(RESULT_SUCCESS); } void GetAppletManInfo(Service::Interface* self) { @@ -154,22 +301,27 @@ void GetAppletManInfo(Service::Interface* self) { void IsRegistered(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x9, 1, 0); // 0x90040 - u32 app_id = rp.Pop(); + AppletId app_id = static_cast(rp.Pop()); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); rb.Push(RESULT_SUCCESS); // No error - // TODO(Subv): An application is considered "registered" if it has already called APT::Enable - // handle this properly once we implement multiprocess support. - bool is_registered = false; // Set to not registered by default + auto* const slot_data = GetAppletSlotData(app_id); + + // Check if an LLE applet was registered first, then fallback to HLE applets + bool is_registered = slot_data && slot_data->registered; - if (app_id == static_cast(AppletId::AnyLibraryApplet)) { - is_registered = HLE::Applets::IsLibraryAppletRunning(); - } else if (auto applet = HLE::Applets::Applet::Get(static_cast(app_id))) { - is_registered = true; // Set to registered + if (!is_registered) { + if (app_id == AppletId::AnyLibraryApplet) { + is_registered = HLE::Applets::IsLibraryAppletRunning(); + } else if (auto applet = HLE::Applets::Applet::Get(app_id)) { + // The applet exists, set it as registered. + is_registered = true; + } } + rb.Push(is_registered); - LOG_WARNING(Service_APT, "(STUBBED) called app_id=0x%08X", app_id); + LOG_DEBUG(Service_APT, "called app_id=0x%08X", static_cast(app_id)); } void InquireNotification(Service::Interface* self) { @@ -864,14 +1016,23 @@ void Init() { screen_capture_post_permission = ScreencapPostPermission::CleanThePermission; // TODO(JamePeng): verify the initial value - // TODO(bunnei): Check if these are created in Initialize or on APT process startup. - notification_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Notification"); - parameter_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT_U:Start"); + for (size_t slot = 0; slot < applet_slots.size(); ++slot) { + auto& slot_data = applet_slots[slot]; + slot_data.slot = static_cast(slot); + slot_data.applet_id = AppletId::None; + slot_data.attributes = 0; + slot_data.registered = false; + slot_data.notification_event = + Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Notification"); + slot_data.parameter_event = + Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Parameter"); + } // Initialize the parameter to wake up the application. next_parameter.emplace(); next_parameter->signal = static_cast(SignalType::Wakeup); next_parameter->destination_id = static_cast(AppletId::Application); + applet_slots[static_cast(AppletSlot::Application)].parameter_event->Signal(); } void Shutdown() { @@ -879,8 +1040,12 @@ void Shutdown() { shared_font_loaded = false; shared_font_relocated = false; lock = nullptr; - notification_event = nullptr; - parameter_event = nullptr; + + for (auto& slot : applet_slots) { + slot.registered = false; + slot.notification_event = nullptr; + slot.parameter_event = nullptr; + } next_parameter = boost::none; diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h index 106754853..96b28b438 100644 --- a/src/core/hle/service/apt/apt.h +++ b/src/core/hle/service/apt/apt.h @@ -72,6 +72,8 @@ enum class SignalType : u32 { /// App Id's used by APT functions enum class AppletId : u32 { + None = 0, + AnySystemApplet = 0x100, HomeMenu = 0x101, AlternateMenu = 0x103, Camera = 0x110, @@ -83,6 +85,7 @@ enum class AppletId : u32 { Miiverse = 0x117, MiiversePost = 0x118, AmiiboSettings = 0x119, + AnySysLibraryApplet = 0x200, SoftwareKeyboard1 = 0x201, Ed1 = 0x202, PnoteApp = 0x204, @@ -119,8 +122,9 @@ enum class ScreencapPostPermission : u32 { namespace ErrCodes { enum { ParameterPresent = 2, + InvalidAppletSlot = 4, }; -} +} // namespace ErrCodes /// Send a parameter to the currently-running application, which will read it via ReceiveParameter void SendParameter(const MessageParameter& parameter); -- cgit v1.2.3 From 177e8ce655953e22b5304070694f2d2d6e65dda9 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 7 Aug 2017 16:09:55 -0500 Subject: Services/APT: Use the AppletAttributes union directly when dealing with applet attrs. --- src/core/hle/service/apt/apt.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 9cfa9efde..58d94768c 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -60,11 +60,20 @@ enum class AppletSlot : u8 { Error, }; +union AppletAttributes { + u32 raw; + + BitField<0, 3, u32> applet_pos; + + AppletAttributes() : raw(0) {} + AppletAttributes(u32 attributes) : raw(attributes) {} +}; + struct AppletSlotData { AppletId applet_id; AppletSlot slot; bool registered; - u32 attributes; + AppletAttributes attributes; Kernel::SharedPtr notification_event; Kernel::SharedPtr parameter_event; }; @@ -72,19 +81,6 @@ struct AppletSlotData { // Holds data about the concurrently running applets in the system. static std::array applet_slots = {}; -union AppletAttributes { - u32 raw; - - BitField<0, 3, u32> applet_pos; - - AppletAttributes(u32 attributes) : raw(attributes) {} -}; - -// Helper function to extract the AppletPos from the lower bits of the applet attributes -static u32 GetAppletPos(AppletAttributes attributes) { - return attributes.applet_pos; -} - // This overload returns nullptr if no applet with the specified id has been started. static AppletSlotData* GetAppletSlotData(AppletId id) { auto GetSlot = [](AppletSlot slot) -> AppletSlotData* { @@ -118,7 +114,7 @@ static AppletSlotData* GetAppletSlotData(AppletId id) { if (slot->applet_id == AppletId::None) return nullptr; - u32 applet_pos = GetAppletPos(slot->attributes); + u32 applet_pos = slot->attributes.applet_pos; if (id == AppletId::AnyLibraryApplet && applet_pos == static_cast(AppletPos::Library)) return slot; @@ -146,13 +142,13 @@ static AppletSlotData* GetAppletSlotData(AppletId id) { return nullptr; } -static AppletSlotData* GetAppletSlotData(u32 attributes) { +static AppletSlotData* GetAppletSlotData(AppletAttributes attributes) { // Mapping from AppletPos to AppletSlot static constexpr std::array applet_position_slots = { AppletSlot::Application, AppletSlot::LibraryApplet, AppletSlot::SystemApplet, AppletSlot::LibraryApplet, AppletSlot::Error, AppletSlot::LibraryApplet}; - u32 applet_pos = GetAppletPos(attributes); + u32 applet_pos = attributes.applet_pos; if (applet_pos >= applet_position_slots.size()) return nullptr; @@ -194,7 +190,7 @@ void Initialize(Service::Interface* self) { } slot_data->applet_id = static_cast(app_id); - slot_data->attributes = attributes; + slot_data->attributes.raw = attributes; IPC::RequestBuilder rb = rp.MakeBuilder(1, 3); rb.Push(RESULT_SUCCESS); @@ -1020,7 +1016,7 @@ void Init() { auto& slot_data = applet_slots[slot]; slot_data.slot = static_cast(slot); slot_data.applet_id = AppletId::None; - slot_data.attributes = 0; + slot_data.attributes.raw = 0; slot_data.registered = false; slot_data.notification_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Notification"); -- cgit v1.2.3 From 1a44949ef75016fa48f9daa0cf3c973ef7d3978c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 8 Aug 2017 17:50:09 +1000 Subject: Update cryptopp --- src/core/hle/service/cfg/cfg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 6624f1711..3dbeb27cc 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -681,7 +681,7 @@ void GenerateConsoleUniqueId(u32& random_number, u64& console_id) { CryptoPP::AutoSeededRandomPool rng; random_number = rng.GenerateWord32(0, 0xFFFF); u64_le local_friend_code_seed; - rng.GenerateBlock(reinterpret_cast(&local_friend_code_seed), + rng.GenerateBlock(reinterpret_cast(&local_friend_code_seed), sizeof(local_friend_code_seed)); console_id = (local_friend_code_seed & 0x3FFFFFFFF) | (static_cast(random_number) << 48); } -- cgit v1.2.3 From a6273dd56a4a7066ef27fa186e1046db677ff578 Mon Sep 17 00:00:00 2001 From: mailwl Date: Wed, 9 Aug 2017 12:00:54 +0300 Subject: Service/dlp: Update function tables according 3dbrew --- src/core/hle/service/dlp/dlp_clnt.cpp | 21 ++++++++++++++++++++- src/core/hle/service/dlp/dlp_fkcl.cpp | 18 +++++++++++++++++- src/core/hle/service/dlp/dlp_srvr.cpp | 9 +++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/dlp/dlp_clnt.cpp b/src/core/hle/service/dlp/dlp_clnt.cpp index 56f934b3f..6f2bf2061 100644 --- a/src/core/hle/service/dlp/dlp_clnt.cpp +++ b/src/core/hle/service/dlp/dlp_clnt.cpp @@ -8,7 +8,26 @@ namespace Service { namespace DLP { const Interface::FunctionInfo FunctionTable[] = { - {0x000100C3, nullptr, "Initialize"}, {0x00110000, nullptr, "GetWirelessRebootPassphrase"}, + {0x000100C3, nullptr, "Initialize"}, + {0x00020000, nullptr, "Finalize"}, + {0x00030000, nullptr, "GetEventDesc"}, + {0x00040000, nullptr, "GetChannel"}, + {0x00050180, nullptr, "StartScan"}, + {0x00060000, nullptr, "StopScan"}, + {0x00070080, nullptr, "GetServerInfo"}, + {0x00080100, nullptr, "GetTitleInfo"}, + {0x00090040, nullptr, "GetTitleInfoInOrder"}, + {0x000A0080, nullptr, "DeleteScanInfo"}, + {0x000B0100, nullptr, "PrepareForSystemDownload"}, + {0x000C0000, nullptr, "StartSystemDownload"}, + {0x000D0100, nullptr, "StartTitleDownload"}, + {0x000E0000, nullptr, "GetMyStatus"}, + {0x000F0040, nullptr, "GetConnectingNodes"}, + {0x00100040, nullptr, "GetNodeInfo"}, + {0x00110000, nullptr, "GetWirelessRebootPassphrase"}, + {0x00120000, nullptr, "StopSession"}, + {0x00130100, nullptr, "GetCupVersion"}, + {0x00140100, nullptr, "GetDupAvailability"}, }; DLP_CLNT_Interface::DLP_CLNT_Interface() { diff --git a/src/core/hle/service/dlp/dlp_fkcl.cpp b/src/core/hle/service/dlp/dlp_fkcl.cpp index 29b9d52e0..fe6be7d32 100644 --- a/src/core/hle/service/dlp/dlp_fkcl.cpp +++ b/src/core/hle/service/dlp/dlp_fkcl.cpp @@ -8,7 +8,23 @@ namespace Service { namespace DLP { const Interface::FunctionInfo FunctionTable[] = { - {0x00010083, nullptr, "Initialize"}, {0x000F0000, nullptr, "GetWirelessRebootPassphrase"}, + {0x00010083, nullptr, "Initialize"}, + {0x00020000, nullptr, "Finalize"}, + {0x00030000, nullptr, "GetEventDesc"}, + {0x00040000, nullptr, "GetChannels"}, + {0x00050180, nullptr, "StartScan"}, + {0x00060000, nullptr, "StopScan"}, + {0x00070080, nullptr, "GetServerInfo"}, + {0x00080100, nullptr, "GetTitleInfo"}, + {0x00090040, nullptr, "GetTitleInfoInOrder"}, + {0x000A0080, nullptr, "DeleteScanInfo"}, + {0x000B0100, nullptr, "StartFakeSession"}, + {0x000C0000, nullptr, "GetMyStatus"}, + {0x000D0040, nullptr, "GetConnectingNodes"}, + {0x000E0040, nullptr, "GetNodeInfo"}, + {0x000F0000, nullptr, "GetWirelessRebootPassphrase"}, + {0x00100000, nullptr, "StopSession"}, + {0x00110203, nullptr, "Initialize2"}, }; DLP_FKCL_Interface::DLP_FKCL_Interface() { diff --git a/src/core/hle/service/dlp/dlp_srvr.cpp b/src/core/hle/service/dlp/dlp_srvr.cpp index 32cfa2c44..1bcea43d3 100644 --- a/src/core/hle/service/dlp/dlp_srvr.cpp +++ b/src/core/hle/service/dlp/dlp_srvr.cpp @@ -11,7 +11,7 @@ namespace Service { namespace DLP { -static void unk_0x000E0040(Interface* self) { +static void IsChild(Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); cmd_buff[1] = RESULT_SUCCESS.raw; @@ -24,14 +24,19 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00010183, nullptr, "Initialize"}, {0x00020000, nullptr, "Finalize"}, {0x00030000, nullptr, "GetServerState"}, + {0x00040000, nullptr, "GetEventDescription"}, {0x00050080, nullptr, "StartAccepting"}, + {0x00060000, nullptr, "EndAccepting"}, {0x00070000, nullptr, "StartDistribution"}, {0x000800C0, nullptr, "SendWirelessRebootPassphrase"}, {0x00090040, nullptr, "AcceptClient"}, + {0x000A0040, nullptr, "DisconnectClient"}, {0x000B0042, nullptr, "GetConnectingClients"}, {0x000C0040, nullptr, "GetClientInfo"}, {0x000D0040, nullptr, "GetClientState"}, - {0x000E0040, unk_0x000E0040, "unk_0x000E0040"}, + {0x000E0040, IsChild, "IsChild"}, + {0x000F0303, nullptr, "InitializeWithName"}, + {0x00100000, nullptr, "GetDupNoticeNeed"}, }; DLP_SRVR_Interface::DLP_SRVR_Interface() { -- cgit v1.2.3 From 599de29ea345bbeee300bec4bd6c3ab31288268d Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 9 Aug 2017 06:59:13 +0300 Subject: HID: zero unused PadState bits --- src/core/hle/service/hid/hid.h | 2 +- src/core/hle/service/ir/ir_rst.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 1ef972e70..ef25926b5 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -24,7 +24,7 @@ namespace HID { */ struct PadState { union { - u32 hex; + u32 hex{}; BitField<0, 1, u32> a; BitField<1, 1, u32> b; diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp index 837413f93..0912d5756 100644 --- a/src/core/hle/service/ir/ir_rst.cpp +++ b/src/core/hle/service/ir/ir_rst.cpp @@ -18,7 +18,7 @@ namespace Service { namespace IR { union PadState { - u32_le hex; + u32_le hex{}; BitField<14, 1, u32_le> zl; BitField<15, 1, u32_le> zr; -- cgit v1.2.3 From 867eabd6b7effc8ba6c21d7fcbd0480b14f81ad0 Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 6 Aug 2017 22:54:19 +0300 Subject: HID: use MotionDevice for Accelerometer and Gyroscope --- src/core/hle/service/hid/hid.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 2014b8461..a13b72e88 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -7,6 +7,7 @@ #include #include #include "common/logging/log.h" +#include "core/core.h" #include "core/core_timing.h" #include "core/frontend/emu_window.h" #include "core/frontend/input.h" @@ -50,10 +51,14 @@ constexpr u64 pad_update_ticks = BASE_CLOCK_RATE_ARM11 / 234; constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE_ARM11 / 104; constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101; +constexpr float accelerometer_coef = 512.0f; // measured from hw test result +constexpr float gyroscope_coef = 14.375f; // got from hwtest GetGyroscopeLowRawToDpsCoefficient call + static std::atomic is_device_reload_pending; static std::array, Settings::NativeButton::NUM_BUTTONS_HID> buttons; static std::unique_ptr circle_pad; +static std::unique_ptr motion_device; DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) { // 30 degree and 60 degree are angular thresholds for directions @@ -90,6 +95,7 @@ static void LoadInputDevices() { buttons.begin(), Input::CreateDevice); circle_pad = Input::CreateDevice( Settings::values.analogs[Settings::NativeAnalog::CirclePad]); + motion_device = Input::CreateDevice(Settings::values.motion_device); } static void UnloadInputDevices() { @@ -97,6 +103,7 @@ static void UnloadInputDevices() { button.reset(); } circle_pad.reset(); + motion_device.reset(); } static void UpdatePadCallback(u64 userdata, int cycles_late) { @@ -193,10 +200,19 @@ static void UpdateAccelerometerCallback(u64 userdata, int cycles_late) { mem->accelerometer.index = next_accelerometer_index; next_accelerometer_index = (next_accelerometer_index + 1) % mem->accelerometer.entries.size(); + Math::Vec3 accel; + std::tie(accel, std::ignore) = motion_device->GetStatus(); + accel *= accelerometer_coef; + // TODO(wwylele): do a time stretch as it in UpdateGyroscopeCallback + // The time stretch formula should be like + // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity + AccelerometerDataEntry& accelerometer_entry = mem->accelerometer.entries[mem->accelerometer.index]; - std::tie(accelerometer_entry.x, accelerometer_entry.y, accelerometer_entry.z) = - VideoCore::g_emu_window->GetAccelerometerState(); + + accelerometer_entry.x = static_cast(accel.x); + accelerometer_entry.y = static_cast(accel.y); + accelerometer_entry.z = static_cast(accel.z); // Make up "raw" entry // TODO(wwylele): @@ -227,8 +243,14 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) { next_gyroscope_index = (next_gyroscope_index + 1) % mem->gyroscope.entries.size(); GyroscopeDataEntry& gyroscope_entry = mem->gyroscope.entries[mem->gyroscope.index]; - std::tie(gyroscope_entry.x, gyroscope_entry.y, gyroscope_entry.z) = - VideoCore::g_emu_window->GetGyroscopeState(); + + Math::Vec3 gyro; + std::tie(std::ignore, gyro) = motion_device->GetStatus(); + float stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); + gyro *= gyroscope_coef * stretch; + gyroscope_entry.x = static_cast(gyro.x); + gyroscope_entry.y = static_cast(gyro.y); + gyroscope_entry.z = static_cast(gyro.z); // Make up "raw" entry mem->gyroscope.raw_entry.x = gyroscope_entry.x; @@ -326,7 +348,7 @@ void GetGyroscopeLowRawToDpsCoefficient(Service::Interface* self) { cmd_buff[1] = RESULT_SUCCESS.raw; - f32 coef = VideoCore::g_emu_window->GetGyroscopeRawToDpsCoefficient(); + f32 coef = gyroscope_coef; memcpy(&cmd_buff[2], &coef, 4); } -- cgit v1.2.3 From b67c2dc82cff794fc1989e103daa96f5ff5f12be Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 15 Aug 2017 10:16:50 +0100 Subject: dsp_dsp: Remove size assertion in LoadComponent --- src/core/hle/service/dsp_dsp.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 7d746054f..42f8950f9 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -147,9 +147,10 @@ static void LoadComponent(Service::Interface* self) { LOG_INFO(Service_DSP, "Firmware hash: %#" PRIx64, Common::ComputeHash64(component_data.data(), component_data.size())); // Some versions of the firmware have the location of DSP structures listed here. - ASSERT(size > 0x37C); - LOG_INFO(Service_DSP, "Structures hash: %#" PRIx64, - Common::ComputeHash64(component_data.data() + 0x340, 60)); + if (size > 0x37C) { + LOG_INFO(Service_DSP, "Structures hash: %#" PRIx64, + Common::ComputeHash64(component_data.data() + 0x340, 60)); + } LOG_WARNING(Service_DSP, "(STUBBED) called size=0x%X, prog_mask=0x%08X, data_mask=0x%08X, buffer=0x%08X", -- cgit v1.2.3 From 54c0c8adee90d374e954e742d6d03279ef2e7ed7 Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 20 Aug 2017 08:37:48 +0300 Subject: HID: fix a comment and a warning --- src/core/hle/service/hid/hid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index a13b72e88..31f34a7ae 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -203,7 +203,7 @@ static void UpdateAccelerometerCallback(u64 userdata, int cycles_late) { Math::Vec3 accel; std::tie(accel, std::ignore) = motion_device->GetStatus(); accel *= accelerometer_coef; - // TODO(wwylele): do a time stretch as it in UpdateGyroscopeCallback + // TODO(wwylele): do a time stretch like the one in UpdateGyroscopeCallback // The time stretch formula should be like // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity @@ -246,7 +246,7 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) { Math::Vec3 gyro; std::tie(std::ignore, gyro) = motion_device->GetStatus(); - float stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); + double stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); gyro *= gyroscope_coef * stretch; gyroscope_entry.x = static_cast(gyro.x); gyroscope_entry.y = static_cast(gyro.y); -- cgit v1.2.3 From c84e60b4700778db236d3177714a076c515f9ce7 Mon Sep 17 00:00:00 2001 From: wwylele Date: Tue, 8 Aug 2017 21:34:17 +0300 Subject: HID: use TouchDevice for touch pad --- src/core/hle/service/hid/hid.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 31f34a7ae..aa5d821f9 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -7,9 +7,9 @@ #include #include #include "common/logging/log.h" +#include "core/3ds.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/frontend/emu_window.h" #include "core/frontend/input.h" #include "core/hle/ipc.h" #include "core/hle/kernel/event.h" @@ -19,7 +19,6 @@ #include "core/hle/service/hid/hid_spvr.h" #include "core/hle/service/hid/hid_user.h" #include "core/hle/service/service.h" -#include "video_core/video_core.h" namespace Service { namespace HID { @@ -59,6 +58,7 @@ static std::array, Settings::NativeButton:: buttons; static std::unique_ptr circle_pad; static std::unique_ptr motion_device; +static std::unique_ptr touch_device; DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) { // 30 degree and 60 degree are angular thresholds for directions @@ -96,6 +96,7 @@ static void LoadInputDevices() { circle_pad = Input::CreateDevice( Settings::values.analogs[Settings::NativeAnalog::CirclePad]); motion_device = Input::CreateDevice(Settings::values.motion_device); + touch_device = Input::CreateDevice(Settings::values.touch_device); } static void UnloadInputDevices() { @@ -104,6 +105,7 @@ static void UnloadInputDevices() { } circle_pad.reset(); motion_device.reset(); + touch_device.reset(); } static void UpdatePadCallback(u64 userdata, int cycles_late) { @@ -172,8 +174,10 @@ static void UpdatePadCallback(u64 userdata, int cycles_late) { // Get the current touch entry TouchDataEntry& touch_entry = mem->touch.entries[mem->touch.index]; bool pressed = false; - - std::tie(touch_entry.x, touch_entry.y, pressed) = VideoCore::g_emu_window->GetTouchState(); + float x, y; + std::tie(x, y, pressed) = touch_device->GetStatus(); + touch_entry.x = static_cast(x * Core::kScreenBottomWidth); + touch_entry.y = static_cast(y * Core::kScreenBottomHeight); touch_entry.valid.Assign(pressed ? 1 : 0); // TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which -- cgit v1.2.3 From 54411bef4eb16af0822820205a923690ea7e822a Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 17 Jul 2017 09:25:58 -0500 Subject: Services/UDS: Add functions to generate 802.11 auth and assoc response frames. --- src/core/hle/service/nwm/nwm_uds.h | 12 +++++ src/core/hle/service/nwm/uds_beacon.h | 11 ---- src/core/hle/service/nwm/uds_connection.cpp | 79 +++++++++++++++++++++++++++++ src/core/hle/service/nwm/uds_connection.h | 51 +++++++++++++++++++ 4 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 src/core/hle/service/nwm/uds_connection.cpp create mode 100644 src/core/hle/service/nwm/uds_connection.h (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 141f49f9c..f1caaf974 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h @@ -42,6 +42,7 @@ using NodeList = std::vector; enum class NetworkStatus { NotConnected = 3, ConnectedAsHost = 6, + Connecting = 7, ConnectedAsClient = 9, ConnectedAsSpectator = 10, }; @@ -85,6 +86,17 @@ static_assert(offsetof(NetworkInfo, oui_value) == 0xC, "oui_value is at the wron static_assert(offsetof(NetworkInfo, wlan_comm_id) == 0x10, "wlancommid is at the wrong offset."); static_assert(sizeof(NetworkInfo) == 0x108, "NetworkInfo has incorrect size."); +/// Additional block tag ids in the Beacon and Association Response frames +enum class TagId : u8 { + SSID = 0, + SupportedRates = 1, + DSParameterSet = 2, + TrafficIndicationMap = 5, + CountryInformation = 7, + ERPInformation = 42, + VendorSpecific = 221 +}; + class NWM_UDS final : public Interface { public: NWM_UDS(); diff --git a/src/core/hle/service/nwm/uds_beacon.h b/src/core/hle/service/nwm/uds_beacon.h index caacf4c6f..c726b04d9 100644 --- a/src/core/hle/service/nwm/uds_beacon.h +++ b/src/core/hle/service/nwm/uds_beacon.h @@ -17,17 +17,6 @@ namespace NWM { using MacAddress = std::array; constexpr std::array NintendoOUI = {0x00, 0x1F, 0x32}; -/// Additional block tag ids in the Beacon frames -enum class TagId : u8 { - SSID = 0, - SupportedRates = 1, - DSParameterSet = 2, - TrafficIndicationMap = 5, - CountryInformation = 7, - ERPInformation = 42, - VendorSpecific = 221 -}; - /** * Internal vendor-specific tag ids as stored inside * VendorSpecific blocks in the Beacon frames. diff --git a/src/core/hle/service/nwm/uds_connection.cpp b/src/core/hle/service/nwm/uds_connection.cpp new file mode 100644 index 000000000..c8a76ec2a --- /dev/null +++ b/src/core/hle/service/nwm/uds_connection.cpp @@ -0,0 +1,79 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/nwm/nwm_uds.h" +#include "core/hle/service/nwm/uds_connection.h" +#include "fmt/format.h" + +namespace Service { +namespace NWM { + +// Note: These values were taken from a packet capture of an o3DS XL +// broadcasting a Super Smash Bros. 4 lobby. +constexpr u16 DefaultExtraCapabilities = 0x0431; + +std::vector GenerateAuthenticationFrame(AuthenticationSeq seq) { + AuthenticationFrame frame{}; + frame.auth_seq = static_cast(seq); + + std::vector data(sizeof(frame)); + std::memcpy(data.data(), &frame, sizeof(frame)); + + return data; +} + +AuthenticationSeq GetAuthenticationSeqNumber(const std::vector& body) { + AuthenticationFrame frame; + std::memcpy(&frame, body.data(), sizeof(frame)); + + return static_cast(frame.auth_seq); +} + +/** + * Generates an SSID tag of an 802.11 Beacon frame with an 8-byte character representation of the + * specified network id as the SSID value. + * @param network_id The network id to use. + * @returns A buffer with the SSID tag. + */ +static std::vector GenerateSSIDTag(u32 network_id) { + constexpr u8 SSIDSize = 8; + + struct { + u8 id = static_cast(TagId::SSID); + u8 size = SSIDSize; + } tag_header; + + std::vector buffer(sizeof(tag_header) + SSIDSize); + + std::memcpy(buffer.data(), &tag_header, sizeof(tag_header)); + + std::string network_name = fmt::format("{0:08X}", network_id); + + std::memcpy(buffer.data() + sizeof(tag_header), network_name.c_str(), SSIDSize); + + return buffer; +} + +std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id) { + AssociationResponseFrame frame{}; + frame.capabilities = DefaultExtraCapabilities; + frame.status_code = static_cast(status); + // The association id is ORed with this magic value (0xC000) + constexpr u16 AssociationIdMagic = 0xC000; + frame.assoc_id = association_id | AssociationIdMagic; + + std::vector data(sizeof(frame)); + std::memcpy(data.data(), &frame, sizeof(frame)); + + auto ssid_tag = GenerateSSIDTag(network_id); + data.insert(data.end(), ssid_tag.begin(), ssid_tag.end()); + + // TODO(Subv): Add the SupportedRates tag. + // TODO(Subv): Add the DSParameterSet tag. + // TODO(Subv): Add the ERPInformation tag. + return data; +} + +} // namespace NWM +} // namespace Service diff --git a/src/core/hle/service/nwm/uds_connection.h b/src/core/hle/service/nwm/uds_connection.h new file mode 100644 index 000000000..73f55a4fd --- /dev/null +++ b/src/core/hle/service/nwm/uds_connection.h @@ -0,0 +1,51 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include "common/common_types.h" +#include "common/swap.h" +#include "core/hle/service/service.h" + +namespace Service { +namespace NWM { + +/// Sequence number of the 802.11 authentication frames. +enum class AuthenticationSeq : u16 { SEQ1 = 1, SEQ2 = 2 }; + +enum class AuthAlgorithm : u16 { OpenSystem = 0 }; + +enum class AuthStatus : u16 { Successful = 0 }; + +enum class AssocStatus : u16 { Successful = 0 }; + +struct AuthenticationFrame { + u16_le auth_algorithm = static_cast(AuthAlgorithm::OpenSystem); + u16_le auth_seq; + u16_le status_code = static_cast(AuthStatus::Successful); +}; + +static_assert(sizeof(AuthenticationFrame) == 6, "AuthenticationFrame has wrong size"); + +struct AssociationResponseFrame { + u16_le capabilities; + u16_le status_code; + u16_le assoc_id; +}; + +static_assert(sizeof(AssociationResponseFrame) == 6, "AssociationResponseFrame has wrong size"); + +/// Generates an 802.11 authentication frame, starting at the frame body. +std::vector GenerateAuthenticationFrame(AuthenticationSeq seq); + +/// Returns the sequence number from the body of an Authentication frame. +AuthenticationSeq GetAuthenticationSeqNumber(const std::vector& body); + +/// Generates an 802.11 association response frame with the specified status, association id and +/// network id, starting at the frame body. +std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id); + +} // namespace NWM +} // namespace Service -- cgit v1.2.3 From 2e9f544ecc9a01ff59859b43d65c61a2838e7c34 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 17 Jul 2017 09:39:12 -0500 Subject: Services/UDS: Store the received beacon frames until RecvBeaconBroadcastData is called, up to 15 beacons at the same time, removing any older beacon frames when the limit is exceeded. --- src/core/hle/service/nwm/nwm_uds.cpp | 65 ++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 6dbdff044..8fdf160ff 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include "common/common_types.h" @@ -15,8 +16,10 @@ #include "core/hle/result.h" #include "core/hle/service/nwm/nwm_uds.h" #include "core/hle/service/nwm/uds_beacon.h" +#include "core/hle/service/nwm/uds_connection.h" #include "core/hle/service/nwm/uds_data.h" #include "core/memory.h" +#include "network/network.h" namespace Service { namespace NWM { @@ -51,6 +54,52 @@ static NetworkInfo network_info; // Event that will generate and send the 802.11 beacon frames. static int beacon_broadcast_event; +// Mutex to synchronize access to the list of received beacons between the emulation thread and the +// network thread. +static std::mutex beacon_mutex; + +// Number of beacons to store before we start dropping the old ones. +// TODO(Subv): Find a more accurate value for this limit. +constexpr size_t MaxBeaconFrames = 15; + +// List of the last beacons received from the network. +static std::deque received_beacons; + +/** + * Returns a list of received 802.11 beacon frames from the specified sender since the last call. + */ +std::deque GetReceivedBeacons(const MacAddress& sender) { + std::lock_guard lock(beacon_mutex); + // TODO(Subv): Filter by sender. + return std::move(received_beacons); +} + +/// Sends a WifiPacket to the room we're currently connected to. +void SendPacket(Network::WifiPacket& packet) { + // TODO(Subv): Implement. +} + +// Inserts the received beacon frame in the beacon queue and removes any older beacons if the size +// limit is exceeded. +void HandleBeaconFrame(const Network::WifiPacket& packet) { + std::lock_guard lock(beacon_mutex); + + received_beacons.emplace_back(packet); + + // Discard old beacons if the buffer is full. + if (received_beacons.size() > MaxBeaconFrames) + received_beacons.pop_front(); +} + +/// Callback to parse and handle a received wifi packet. +void OnWifiPacketReceived(const Network::WifiPacket& packet) { + switch (packet.type) { + case Network::WifiPacket::PacketType::Beacon: + HandleBeaconFrame(packet); + break; + } +} + /** * NWM_UDS::Shutdown service function * Inputs: @@ -111,8 +160,7 @@ static void RecvBeaconBroadcastData(Interface* self) { u32 total_size = sizeof(BeaconDataReplyHeader); // Retrieve all beacon frames that were received from the desired mac address. - std::deque beacons = - GetReceivedPackets(WifiPacket::PacketType::Beacon, mac_address); + auto beacons = GetReceivedBeacons(mac_address); BeaconDataReplyHeader data_reply_header{}; data_reply_header.total_entries = beacons.size(); @@ -193,6 +241,9 @@ static void InitializeWithVersion(Interface* self) { rb.Push(RESULT_SUCCESS); rb.PushCopyHandles(Kernel::g_handle_table.Create(connection_status_event).Unwrap()); + // TODO(Subv): Connect the OnWifiPacketReceived function to the wifi packet received callback of + // the room we're currently in. + LOG_DEBUG(Service_NWM, "called sharedmem_size=0x%08X, version=0x%08X, sharedmem_handle=0x%08X", sharedmem_size, version, sharedmem_handle); } @@ -610,9 +661,17 @@ static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { if (connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) return; - // TODO(Subv): Actually send the beacon. std::vector frame = GenerateBeaconFrame(network_info, node_info); + using Network::WifiPacket; + WifiPacket packet; + packet.type = WifiPacket::PacketType::Beacon; + packet.data = std::move(frame); + packet.destination_address = Network::BroadcastMac; + packet.channel = network_channel; + + SendPacket(packet); + // Start broadcasting the network, send a beacon frame every 102.4ms. CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late, beacon_broadcast_event, 0); -- cgit v1.2.3 From d088dbfbe1064bb5212e83c50e71e4b2ea5b00cd Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 17 Jul 2017 09:51:03 -0500 Subject: Services/UDS: Handle the connection sequence packets. There is currently no stage tracking, a client is considered "Connected" when it receives the EAPoL Logoff packet from the server, this is not yet implemented. --- src/core/hle/service/nwm/nwm_uds.cpp | 100 +++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 17 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 8fdf160ff..893bbb1e7 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -91,12 +91,95 @@ void HandleBeaconFrame(const Network::WifiPacket& packet) { received_beacons.pop_front(); } +/* + * Returns an available index in the nodes array for the + * currently-hosted UDS network. + */ +static u16 GetNextAvailableNodeId() { + ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost), + "Can not accept clients if we're not hosting a network"); + + for (u16 index = 0; index < connection_status.max_nodes; ++index) { + if ((connection_status.node_bitmask & (1 << index)) == 0) + return index; + } + + // Any connection attempts to an already full network should have been refused. + ASSERT_MSG(false, "No available connection slots in the network"); +} + +/* + * Start a connection sequence with an UDS server. The sequence starts by sending an 802.11 + * authentication frame with SEQ1. + */ +void StartConnectionSequence(const MacAddress& server) { + ASSERT(connection_status.status == static_cast(NetworkStatus::NotConnected)); + + // TODO(Subv): Handle timeout. + + // Send an authentication frame with SEQ1 + using Network::WifiPacket; + WifiPacket auth_request; + auth_request.channel = network_channel; + auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ1); + auth_request.destination_address = server; + auth_request.type = WifiPacket::PacketType::Authentication; + + SendPacket(auth_request); +} + +/// Sends an Association Response frame to the specified mac address +void SendAssociationResponseFrame(const MacAddress& address) { + ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)); + + using Network::WifiPacket; + WifiPacket assoc_response; + assoc_response.channel = network_channel; + // TODO(Subv): This will cause multiple clients to end up with the same association id, but + // we're not using that for anything. + u16 association_id = 1; + assoc_response.data = GenerateAssocResponseFrame(AssocStatus::Successful, association_id, + network_info.network_id); + assoc_response.destination_address = address; + assoc_response.type = WifiPacket::PacketType::AssociationResponse; + + SendPacket(assoc_response); +} + +/* + * Handles the authentication request frame and sends the authentication response and association + * response frames. Once an Authentication frame with SEQ1 is received by the server, it responds + * with an Authentication frame containing SEQ2, and immediately sends an Association response frame + * containing the details of the access point and the assigned association id for the new client. + */ +void HandleAuthenticationFrame(const Network::WifiPacket& packet) { + // Only the SEQ1 auth frame is handled here, the SEQ2 frame doesn't need any special behavior + if (GetAuthenticationSeqNumber(packet.data) == AuthenticationSeq::SEQ1) { + ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)); + + // Respond with an authentication response frame with SEQ2 + using Network::WifiPacket; + WifiPacket auth_request; + auth_request.channel = network_channel; + auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ2); + auth_request.destination_address = packet.transmitter_address; + auth_request.type = WifiPacket::PacketType::Authentication; + + SendPacket(auth_request); + + SendAssociationResponseFrame(packet.transmitter_address); + } +} + /// Callback to parse and handle a received wifi packet. void OnWifiPacketReceived(const Network::WifiPacket& packet) { switch (packet.type) { case Network::WifiPacket::PacketType::Beacon: HandleBeaconFrame(packet); break; + case Network::WifiPacket::PacketType::Authentication: + HandleAuthenticationFrame(packet); + break; } } @@ -677,23 +760,6 @@ static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { beacon_broadcast_event, 0); } -/* - * Returns an available index in the nodes array for the - * currently-hosted UDS network. - */ -static u32 GetNextAvailableNodeId() { - ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost), - "Can not accept clients if we're not hosting a network"); - - for (unsigned index = 0; index < connection_status.max_nodes; ++index) { - if ((connection_status.node_bitmask & (1 << index)) == 0) - return index; - } - - // Any connection attempts to an already full network should have been refused. - ASSERT_MSG(false, "No available connection slots in the network"); -} - /* * Called when a client connects to an UDS network we're hosting, * updates the connection status and signals the update event. -- cgit v1.2.3 From f64cd87604b7a760e2832c76938d83ec6a284b22 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 17 Jul 2017 09:51:40 -0500 Subject: Services/UDS: Remove an old duplicated declaration of WifiPacket. --- src/core/hle/service/nwm/uds_beacon.cpp | 3 --- src/core/hle/service/nwm/uds_beacon.h | 19 ------------------- 2 files changed, 22 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/uds_beacon.cpp b/src/core/hle/service/nwm/uds_beacon.cpp index 6332b404c..552eaf65e 100644 --- a/src/core/hle/service/nwm/uds_beacon.cpp +++ b/src/core/hle/service/nwm/uds_beacon.cpp @@ -325,8 +325,5 @@ std::vector GenerateBeaconFrame(const NetworkInfo& network_info, const NodeL return buffer; } -std::deque GetReceivedPackets(WifiPacket::PacketType type, const MacAddress& sender) { - return {}; -} } // namespace NWM } // namespace Service diff --git a/src/core/hle/service/nwm/uds_beacon.h b/src/core/hle/service/nwm/uds_beacon.h index c726b04d9..50cc76da2 100644 --- a/src/core/hle/service/nwm/uds_beacon.h +++ b/src/core/hle/service/nwm/uds_beacon.h @@ -124,20 +124,6 @@ struct BeaconData { static_assert(sizeof(BeaconData) == 0x12, "BeaconData has incorrect size."); -/// Information about a received WiFi packet. -/// Acts as our own 802.11 header. -struct WifiPacket { - enum class PacketType { Beacon, Data }; - - PacketType type; ///< The type of 802.11 frame, Beacon / Data. - - /// Raw 802.11 frame data, starting at the management frame header for management frames. - std::vector data; - MacAddress transmitter_address; ///< Mac address of the transmitter. - MacAddress destination_address; ///< Mac address of the receiver. - u8 channel; ///< WiFi channel where this frame was transmitted. -}; - /** * Decrypts the beacon data buffer for the network described by `network_info`. */ @@ -150,10 +136,5 @@ void DecryptBeaconData(const NetworkInfo& network_info, std::vector& buffer) */ std::vector GenerateBeaconFrame(const NetworkInfo& network_info, const NodeList& nodes); -/** - * Returns a list of received 802.11 frames from the specified sender - * matching the type since the last call. - */ -std::deque GetReceivedPackets(WifiPacket::PacketType type, const MacAddress& sender); } // namespace NWM } // namespace Service -- cgit v1.2.3 From 59a9aaf388b71444116a42fe97a969947230908e Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 2 Aug 2017 22:56:44 +0300 Subject: APT: load different shared font depending on the region --- src/core/hle/service/apt/apt.cpp | 286 +++++++++++++++++++++------------------ src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/cfg/cfg.h | 2 + 3 files changed, 155 insertions(+), 135 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 58d94768c..8c0ba73f2 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -19,6 +19,7 @@ #include "core/hle/service/apt/apt_s.h" #include "core/hle/service/apt/apt_u.h" #include "core/hle/service/apt/bcfnt/bcfnt.h" +#include "core/hle/service/cfg/cfg.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/ptm/ptm.h" #include "core/hle/service/service.h" @@ -198,6 +199,143 @@ void Initialize(Service::Interface* self) { Kernel::g_handle_table.Create(slot_data->parameter_event).Unwrap()); } +static u32 DecompressLZ11(const u8* in, u8* out) { + u32_le decompressed_size; + memcpy(&decompressed_size, in, sizeof(u32)); + in += 4; + + u8 type = decompressed_size & 0xFF; + ASSERT(type == 0x11); + decompressed_size >>= 8; + + u32 current_out_size = 0; + u8 flags = 0, mask = 1; + while (current_out_size < decompressed_size) { + if (mask == 1) { + flags = *(in++); + mask = 0x80; + } else { + mask >>= 1; + } + + if (flags & mask) { + u8 byte1 = *(in++); + u32 length = byte1 >> 4; + u32 offset; + if (length == 0) { + u8 byte2 = *(in++); + u8 byte3 = *(in++); + length = (((byte1 & 0x0F) << 4) | (byte2 >> 4)) + 0x11; + offset = (((byte2 & 0x0F) << 8) | byte3) + 0x1; + } else if (length == 1) { + u8 byte2 = *(in++); + u8 byte3 = *(in++); + u8 byte4 = *(in++); + length = (((byte1 & 0x0F) << 12) | (byte2 << 4) | (byte3 >> 4)) + 0x111; + offset = (((byte3 & 0x0F) << 8) | byte4) + 0x1; + } else { + u8 byte2 = *(in++); + length = (byte1 >> 4) + 0x1; + offset = (((byte1 & 0x0F) << 8) | byte2) + 0x1; + } + + for (u32 i = 0; i < length; i++) { + *out = *(out - offset); + ++out; + } + + current_out_size += length; + } else { + *(out++) = *(in++); + current_out_size++; + } + } + return decompressed_size; +} + +static bool LoadSharedFont() { + u8 font_region_code; + switch (CFG::GetRegionValue()) { + case 4: // CHN + font_region_code = 2; + break; + case 5: // KOR + font_region_code = 3; + break; + case 6: // TWN + font_region_code = 4; + break; + default: // JPN/EUR/USA + font_region_code = 1; + break; + } + + const u64_le shared_font_archive_id_low = 0x0004009b00014002 | ((font_region_code - 1) << 8); + const u64_le shared_font_archive_id_high = 0x00000001ffffff00; + std::vector shared_font_archive_id(16); + std::memcpy(&shared_font_archive_id[0], &shared_font_archive_id_low, sizeof(u64)); + std::memcpy(&shared_font_archive_id[8], &shared_font_archive_id_high, sizeof(u64)); + FileSys::Path archive_path(shared_font_archive_id); + auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::NCCH, archive_path); + if (archive_result.Failed()) + return false; + + std::vector romfs_path(20, 0); // 20-byte all zero path for opening RomFS + FileSys::Path file_path(romfs_path); + FileSys::Mode open_mode = {}; + open_mode.read_flag.Assign(1); + auto file_result = Service::FS::OpenFileFromArchive(*archive_result, file_path, open_mode); + if (file_result.Failed()) + return false; + + auto romfs = std::move(file_result).Unwrap(); + std::vector romfs_buffer(romfs->backend->GetSize()); + romfs->backend->Read(0, romfs_buffer.size(), romfs_buffer.data()); + romfs->backend->Close(); + + const char16_t* file_name[4] = {u"cbf_std.bcfnt.lz", u"cbf_zh-Hans-CN.bcfnt.lz", + u"cbf_ko-Hang-KR.bcfnt.lz", u"cbf_zh-Hant-TW.bcfnt.lz"}; + const u8* font_file = + RomFS::GetFilePointer(romfs_buffer.data(), {file_name[font_region_code - 1]}); + if (font_file == nullptr) + return false; + + struct { + u32_le status; + u32_le region; + u32_le decompressed_size; + INSERT_PADDING_WORDS(0x1D); + } shared_font_header{}; + static_assert(sizeof(shared_font_header) == 0x80, "shared_font_header has incorrect size"); + + shared_font_header.status = 2; // successfully loaded + shared_font_header.region = font_region_code; + shared_font_header.decompressed_size = + DecompressLZ11(font_file, shared_font_mem->GetPointer(0x80)); + std::memcpy(shared_font_mem->GetPointer(), &shared_font_header, sizeof(shared_font_header)); + *shared_font_mem->GetPointer(0x83) = 'U'; // Change the magic from "CFNT" to "CFNU" + + return true; +} + +static bool LoadLegacySharedFont() { + // This is the legacy method to load shared font. + // The expected format is a decrypted, uncompressed BCFNT file with the 0x80 byte header + // generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided + // a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file + // "shared_font.bin" in the Citra "sysdata" directory. + std::string filepath = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT; + + FileUtil::CreateFullPath(filepath); // Create path if not already created + FileUtil::IOFile file(filepath, "rb"); + if (file.IsOpen()) { + file.ReadBytes(shared_font_mem->GetPointer(), file.GetSize()); + return true; + } + + return false; +} + void GetSharedFont(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x44, 0, 0); // 0x00440000 IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); @@ -206,11 +344,20 @@ void GetSharedFont(Service::Interface* self) { Core::Telemetry().AddField(Telemetry::FieldType::Session, "RequiresSharedFont", true); if (!shared_font_loaded) { - LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds"); - rb.Push(-1); // TODO: Find the right error code - rb.Skip(1 + 2, true); - Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSharedFont); - return; + // On real 3DS, font loading happens on booting. However, we load it on demand to coordinate + // with CFG region auto configuration, which happens later than APT initialization. + if (LoadSharedFont()) { + shared_font_loaded = true; + } else if (LoadLegacySharedFont()) { + LOG_WARNING(Service_APT, "Loaded shared font by legacy method"); + shared_font_loaded = true; + } else { + LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds"); + rb.Push(-1); // TODO: Find the right error code + rb.Skip(1 + 2, true); + Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSharedFont); + return; + } } // The shared font has to be relocated to the new address before being passed to the @@ -863,125 +1010,6 @@ void CheckNew3DS(Service::Interface* self) { LOG_WARNING(Service_APT, "(STUBBED) called"); } -static u32 DecompressLZ11(const u8* in, u8* out) { - u32_le decompressed_size; - memcpy(&decompressed_size, in, sizeof(u32)); - in += 4; - - u8 type = decompressed_size & 0xFF; - ASSERT(type == 0x11); - decompressed_size >>= 8; - - u32 current_out_size = 0; - u8 flags = 0, mask = 1; - while (current_out_size < decompressed_size) { - if (mask == 1) { - flags = *(in++); - mask = 0x80; - } else { - mask >>= 1; - } - - if (flags & mask) { - u8 byte1 = *(in++); - u32 length = byte1 >> 4; - u32 offset; - if (length == 0) { - u8 byte2 = *(in++); - u8 byte3 = *(in++); - length = (((byte1 & 0x0F) << 4) | (byte2 >> 4)) + 0x11; - offset = (((byte2 & 0x0F) << 8) | byte3) + 0x1; - } else if (length == 1) { - u8 byte2 = *(in++); - u8 byte3 = *(in++); - u8 byte4 = *(in++); - length = (((byte1 & 0x0F) << 12) | (byte2 << 4) | (byte3 >> 4)) + 0x111; - offset = (((byte3 & 0x0F) << 8) | byte4) + 0x1; - } else { - u8 byte2 = *(in++); - length = (byte1 >> 4) + 0x1; - offset = (((byte1 & 0x0F) << 8) | byte2) + 0x1; - } - - for (u32 i = 0; i < length; i++) { - *out = *(out - offset); - ++out; - } - - current_out_size += length; - } else { - *(out++) = *(in++); - current_out_size++; - } - } - return decompressed_size; -} - -static bool LoadSharedFont() { - // TODO (wwylele): load different font archive for region CHN/KOR/TWN - const u64_le shared_font_archive_id_low = 0x0004009b00014002; - const u64_le shared_font_archive_id_high = 0x00000001ffffff00; - std::vector shared_font_archive_id(16); - std::memcpy(&shared_font_archive_id[0], &shared_font_archive_id_low, sizeof(u64)); - std::memcpy(&shared_font_archive_id[8], &shared_font_archive_id_high, sizeof(u64)); - FileSys::Path archive_path(shared_font_archive_id); - auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::NCCH, archive_path); - if (archive_result.Failed()) - return false; - - std::vector romfs_path(20, 0); // 20-byte all zero path for opening RomFS - FileSys::Path file_path(romfs_path); - FileSys::Mode open_mode = {}; - open_mode.read_flag.Assign(1); - auto file_result = Service::FS::OpenFileFromArchive(*archive_result, file_path, open_mode); - if (file_result.Failed()) - return false; - - auto romfs = std::move(file_result).Unwrap(); - std::vector romfs_buffer(romfs->backend->GetSize()); - romfs->backend->Read(0, romfs_buffer.size(), romfs_buffer.data()); - romfs->backend->Close(); - - const u8* font_file = RomFS::GetFilePointer(romfs_buffer.data(), {u"cbf_std.bcfnt.lz"}); - if (font_file == nullptr) - return false; - - struct { - u32_le status; - u32_le region; - u32_le decompressed_size; - INSERT_PADDING_WORDS(0x1D); - } shared_font_header{}; - static_assert(sizeof(shared_font_header) == 0x80, "shared_font_header has incorrect size"); - - shared_font_header.status = 2; // successfully loaded - shared_font_header.region = 1; // region JPN/EUR/USA - shared_font_header.decompressed_size = - DecompressLZ11(font_file, shared_font_mem->GetPointer(0x80)); - std::memcpy(shared_font_mem->GetPointer(), &shared_font_header, sizeof(shared_font_header)); - *shared_font_mem->GetPointer(0x83) = 'U'; // Change the magic from "CFNT" to "CFNU" - - return true; -} - -static bool LoadLegacySharedFont() { - // This is the legacy method to load shared font. - // The expected format is a decrypted, uncompressed BCFNT file with the 0x80 byte header - // generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided - // a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file - // "shared_font.bin" in the Citra "sysdata" directory. - std::string filepath = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT; - - FileUtil::CreateFullPath(filepath); // Create path if not already created - FileUtil::IOFile file(filepath, "rb"); - if (file.IsOpen()) { - file.ReadBytes(shared_font_mem->GetPointer(), file.GetSize()); - return true; - } - - return false; -} - void Init() { AddService(new APT_A_Interface); AddService(new APT_S_Interface); @@ -995,16 +1023,6 @@ void Init() { MemoryPermission::ReadWrite, MemoryPermission::Read, 0, Kernel::MemoryRegion::SYSTEM, "APT:SharedFont"); - if (LoadSharedFont()) { - shared_font_loaded = true; - } else if (LoadLegacySharedFont()) { - LOG_WARNING(Service_APT, "Loaded shared font by legacy method"); - shared_font_loaded = true; - } else { - LOG_WARNING(Service_APT, "Unable to load shared font"); - shared_font_loaded = false; - } - lock = Kernel::Mutex::Create(false, "APT_U:Lock"); cpu_percent = 0; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 3dbeb27cc..f26a1f65f 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -168,7 +168,7 @@ void GetCountryCodeID(Service::Interface* self) { cmd_buff[2] = country_code_id; } -static u32 GetRegionValue() { +u32 GetRegionValue() { if (Settings::values.region_value == Settings::REGION_VALUE_AUTO_SELECT) return preferred_region_code; diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 1659ebf32..282b6936b 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -101,6 +101,8 @@ void GetCountryCodeString(Service::Interface* self); */ void GetCountryCodeID(Service::Interface* self); +u32 GetRegionValue(); + /** * CFG::SecureInfoGetRegion service function * Inputs: -- cgit v1.2.3 From 3d86e3afc4b03037fb1ac8c0b637312a5d0e17f8 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 28 Aug 2017 20:26:07 -0500 Subject: Services/NS: Port ns:s to the new service framework. --- src/core/hle/service/ns/ns.cpp | 16 ++++++++++++++++ src/core/hle/service/ns/ns.h | 16 ++++++++++++++++ src/core/hle/service/ns/ns_s.cpp | 34 ++++++++++++++++++++++++++++++++++ src/core/hle/service/ns/ns_s.h | 21 +++++++++++++++++++++ src/core/hle/service/ns_s.cpp | 33 --------------------------------- src/core/hle/service/ns_s.h | 22 ---------------------- src/core/hle/service/service.cpp | 5 +++-- 7 files changed, 90 insertions(+), 57 deletions(-) create mode 100644 src/core/hle/service/ns/ns.cpp create mode 100644 src/core/hle/service/ns/ns.h create mode 100644 src/core/hle/service/ns/ns_s.cpp create mode 100644 src/core/hle/service/ns/ns_s.h delete mode 100644 src/core/hle/service/ns_s.cpp delete mode 100644 src/core/hle/service/ns_s.h (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp new file mode 100644 index 000000000..9e19c38bf --- /dev/null +++ b/src/core/hle/service/ns/ns.cpp @@ -0,0 +1,16 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/ns/ns.h" +#include "core/hle/service/ns/ns_s.h" + +namespace Service { +namespace NS { + +void InstallInterfaces(SM::ServiceManager& service_manager) { + std::make_shared()->InstallAsService(service_manager); +} + +} // namespace NS +} // namespace Service diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h new file mode 100644 index 000000000..c3d67d98c --- /dev/null +++ b/src/core/hle/service/ns/ns.h @@ -0,0 +1,16 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service { +namespace NS { + +/// Registers all NS services with the specified service manager. +void InstallInterfaces(SM::ServiceManager& service_manager); + +} // namespace NS +} // namespace Service diff --git a/src/core/hle/service/ns/ns_s.cpp b/src/core/hle/service/ns/ns_s.cpp new file mode 100644 index 000000000..d952888dc --- /dev/null +++ b/src/core/hle/service/ns/ns_s.cpp @@ -0,0 +1,34 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/hle/service/ns/ns_s.h" + +namespace Service { +namespace NS { + +NS_S::NS_S() : ServiceFramework("ns:s", 2) { + static const FunctionInfo functions[] = { + {0x000100C0, nullptr, "LaunchFIRM"}, + {0x000200C0, nullptr, "LaunchTitle"}, + {0x00030000, nullptr, "TerminateApplication"}, + {0x00040040, nullptr, "TerminateProcess"}, + {0x000500C0, nullptr, "LaunchApplicationFIRM"}, + {0x00060042, nullptr, "SetFIRMParams4A0"}, + {0x00070042, nullptr, "CardUpdateInitialize"}, + {0x00080000, nullptr, "CardUpdateShutdown"}, + {0x000D0140, nullptr, "SetTWLBannerHMAC"}, + {0x000E0000, nullptr, "ShutdownAsync"}, + {0x00100180, nullptr, "RebootSystem"}, + {0x00110100, nullptr, "TerminateTitle"}, + {0x001200C0, nullptr, "SetApplicationCpuTimeLimit"}, + {0x00150140, nullptr, "LaunchApplication"}, + {0x00160000, nullptr, "RebootSystemClean"}, + }; + RegisterHandlers(functions); +} + +NS_S::~NS_S() = default; + +} // namespace NS +} // namespace Service diff --git a/src/core/hle/service/ns/ns_s.h b/src/core/hle/service/ns/ns_s.h new file mode 100644 index 000000000..660ae453f --- /dev/null +++ b/src/core/hle/service/ns/ns_s.h @@ -0,0 +1,21 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/hle/kernel/kernel.h" +#include "core/hle/service/service.h" + +namespace Service { +namespace NS { + +/// Interface to "ns:s" service +class NS_S final : public ServiceFramework { +public: + NS_S(); + ~NS_S(); +}; + +} // namespace NS +} // namespace Service diff --git a/src/core/hle/service/ns_s.cpp b/src/core/hle/service/ns_s.cpp deleted file mode 100644 index 215c9aacc..000000000 --- a/src/core/hle/service/ns_s.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "core/hle/service/ns_s.h" - -namespace Service { -namespace NS { - -const Interface::FunctionInfo FunctionTable[] = { - {0x000100C0, nullptr, "LaunchFIRM"}, - {0x000200C0, nullptr, "LaunchTitle"}, - {0x00030000, nullptr, "TerminateApplication"}, - {0x00040040, nullptr, "TerminateProcess"}, - {0x000500C0, nullptr, "LaunchApplicationFIRM"}, - {0x00060042, nullptr, "SetFIRMParams4A0"}, - {0x00070042, nullptr, "CardUpdateInitialize"}, - {0x00080000, nullptr, "CardUpdateShutdown"}, - {0x000D0140, nullptr, "SetTWLBannerHMAC"}, - {0x000E0000, nullptr, "ShutdownAsync"}, - {0x00100180, nullptr, "RebootSystem"}, - {0x00110100, nullptr, "TerminateTitle"}, - {0x001200C0, nullptr, "SetApplicationCpuTimeLimit"}, - {0x00150140, nullptr, "LaunchApplication"}, - {0x00160000, nullptr, "RebootSystemClean"}, -}; - -NS_S::NS_S() { - Register(FunctionTable); -} - -} // namespace NS -} // namespace Service diff --git a/src/core/hle/service/ns_s.h b/src/core/hle/service/ns_s.h deleted file mode 100644 index 90288a521..000000000 --- a/src/core/hle/service/ns_s.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "core/hle/service/service.h" - -namespace Service { -namespace NS { - -class NS_S final : public Interface { -public: - NS_S(); - - std::string GetPortName() const override { - return "ns:s"; - } -}; - -} // namespace NS -} // namespace Service diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index aad950e50..f267aad74 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp @@ -38,7 +38,7 @@ #include "core/hle/service/news/news.h" #include "core/hle/service/nfc/nfc.h" #include "core/hle/service/nim/nim.h" -#include "core/hle/service/ns_s.h" +#include "core/hle/service/ns/ns.h" #include "core/hle/service/nwm/nwm.h" #include "core/hle/service/pm_app.h" #include "core/hle/service/ptm/ptm.h" @@ -215,6 +215,8 @@ void Init() { SM::g_service_manager = std::make_shared(); SM::ServiceManager::InstallInterfaces(SM::g_service_manager); + NS::InstallInterfaces(*SM::g_service_manager); + AddNamedPort(new ERR::ERR_F); FS::ArchiveInit(); @@ -246,7 +248,6 @@ void Init() { AddService(new HTTP::HTTP_C); AddService(new LDR::LDR_RO); AddService(new MIC::MIC_U); - AddService(new NS::NS_S); AddService(new PM::PM_APP); AddService(new SOC::SOC_U); AddService(new SSL::SSL_C); -- cgit v1.2.3 From 0b33e36292ca44151da32c7866e4c4394add564b Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 24 Sep 2017 00:12:58 -0500 Subject: HLE/SRV: Implemented RegisterService. Now system modules can do more than just crash immediately on startup. --- src/core/hle/service/sm/sm.cpp | 4 ++++ src/core/hle/service/sm/sm.h | 3 +++ src/core/hle/service/sm/srv.cpp | 26 +++++++++++++++++++++++++- src/core/hle/service/sm/srv.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index 5e7fc68f9..854ab9a05 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -36,6 +36,10 @@ ResultVal> ServiceManager::RegisterService std::string name, unsigned int max_sessions) { CASCADE_CODE(ValidateServiceName(name)); + + if (registered_services.find(name) != registered_services.end()) + return ERR_ALREADY_REGISTERED; + Kernel::SharedPtr server_port; Kernel::SharedPtr client_port; std::tie(server_port, client_port) = Kernel::ServerPort::CreatePortPair(max_sessions, name); diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index 8f0dbf2db..9f60a7965 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h @@ -32,6 +32,9 @@ constexpr ResultCode ERR_ACCESS_DENIED(6, ErrorModule::SRV, ErrorSummary::Invali ErrorLevel::Permanent); // 0xD8E06406 constexpr ResultCode ERR_NAME_CONTAINS_NUL(7, ErrorModule::SRV, ErrorSummary::WrongArgument, ErrorLevel::Permanent); // 0xD9006407 +constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorDescription::AlreadyExists, ErrorModule::OS, + ErrorSummary::WrongArgument, + ErrorLevel::Permanent); // 0xD9001BFC class ServiceManager { public: diff --git a/src/core/hle/service/sm/srv.cpp b/src/core/hle/service/sm/srv.cpp index 352941e69..5c955cf54 100644 --- a/src/core/hle/service/sm/srv.cpp +++ b/src/core/hle/service/sm/srv.cpp @@ -13,6 +13,7 @@ #include "core/hle/kernel/errors.h" #include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/semaphore.h" +#include "core/hle/kernel/server_port.h" #include "core/hle/kernel/server_session.h" #include "core/hle/service/sm/sm.h" #include "core/hle/service/sm/srv.h" @@ -184,12 +185,35 @@ void SRV::PublishToSubscriber(Kernel::HLERequestContext& ctx) { flags); } +void SRV::RegisterService(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x3, 4, 0); + + auto name_buf = rp.PopRaw>(); + size_t name_len = rp.Pop(); + u32 max_sessions = rp.Pop(); + + std::string name(name_buf.data(), std::min(name_len, name_buf.size())); + + auto port = service_manager->RegisterService(name, max_sessions); + + if (port.Failed()) { + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(port.Code()); + LOG_ERROR(Service_SRV, "called service=%s -> error 0x%08X", name.c_str(), port.Code().raw); + return; + } + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + rb.Push(RESULT_SUCCESS); + rb.PushObjects(port.Unwrap()); +} + SRV::SRV(std::shared_ptr service_manager) : ServiceFramework("srv:", 4), service_manager(std::move(service_manager)) { static const FunctionInfo functions[] = { {0x00010002, &SRV::RegisterClient, "RegisterClient"}, {0x00020000, &SRV::EnableNotification, "EnableNotification"}, - {0x00030100, nullptr, "RegisterService"}, + {0x00030100, &SRV::RegisterService, "RegisterService"}, {0x000400C0, nullptr, "UnregisterService"}, {0x00050100, &SRV::GetServiceHandle, "GetServiceHandle"}, {0x000600C2, nullptr, "RegisterPort"}, diff --git a/src/core/hle/service/sm/srv.h b/src/core/hle/service/sm/srv.h index 75cca5184..aad839563 100644 --- a/src/core/hle/service/sm/srv.h +++ b/src/core/hle/service/sm/srv.h @@ -28,6 +28,7 @@ private: void Subscribe(Kernel::HLERequestContext& ctx); void Unsubscribe(Kernel::HLERequestContext& ctx); void PublishToSubscriber(Kernel::HLERequestContext& ctx); + void RegisterService(Kernel::HLERequestContext& ctx); std::shared_ptr service_manager; Kernel::SharedPtr notification_semaphore; -- cgit v1.2.3 From b57d58c0dc94857d28a3ef197d9656f0fbad8e08 Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 23 Sep 2017 13:59:07 -0500 Subject: HLE/APT: Prepare the APT Wakeup parameter when the game calls Initialize We need to know what is being run so we can set the APT parameter destination AppId correctly. Delaying the preparation of the parameter until we know which AppId is running lets us support booting both the Home Menu and normal game Applications. --- src/core/hle/service/apt/apt.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 8c0ba73f2..ea964bab1 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -65,6 +65,7 @@ union AppletAttributes { u32 raw; BitField<0, 3, u32> applet_pos; + BitField<29, 1, u32> is_home_menu; AppletAttributes() : raw(0) {} AppletAttributes(u32 attributes) : raw(attributes) {} @@ -158,6 +159,11 @@ static AppletSlotData* GetAppletSlotData(AppletAttributes attributes) { if (slot == AppletSlot::Error) return nullptr; + // The Home Menu is a system applet, however, it has its own applet slot so that it can run + // concurrently with other system applets. + if (slot == AppletSlot::SystemApplet && attributes.is_home_menu) + return &applet_slots[static_cast(AppletSlot::HomeMenu)]; + return &applet_slots[static_cast(slot)]; } @@ -197,6 +203,19 @@ void Initialize(Service::Interface* self) { rb.Push(RESULT_SUCCESS); rb.PushCopyHandles(Kernel::g_handle_table.Create(slot_data->notification_event).Unwrap(), Kernel::g_handle_table.Create(slot_data->parameter_event).Unwrap()); + + if (slot_data->applet_id == AppletId::Application || + slot_data->applet_id == AppletId::HomeMenu) { + // Initialize the APT parameter to wake up the application. + next_parameter.emplace(); + next_parameter->signal = static_cast(SignalType::Wakeup); + next_parameter->sender_id = static_cast(AppletId::None); + next_parameter->destination_id = app_id; + // Not signaling the parameter event will cause the application (or Home Menu) to hang + // during startup. In the real console, it is usually the Kernel and Home Menu who cause NS + // to signal the HomeMenu and Application parameter events, respectively. + slot_data->parameter_event->Signal(); + } } static u32 DecompressLZ11(const u8* in, u8* out) { @@ -1041,12 +1060,6 @@ void Init() { slot_data.parameter_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "APT:Parameter"); } - - // Initialize the parameter to wake up the application. - next_parameter.emplace(); - next_parameter->signal = static_cast(SignalType::Wakeup); - next_parameter->destination_id = static_cast(AppletId::Application); - applet_slots[static_cast(AppletSlot::Application)].parameter_event->Signal(); } void Shutdown() { -- cgit v1.2.3 From 7096f01c14ff76aefd829ae449a8ab5d474eacf7 Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 23 Sep 2017 14:01:04 -0500 Subject: HLE/APT: Always return an error from PrepareToStartNewestHomeMenu so that the Home Menu doesn't try to reboot the system. As per 3dbrew: "During Home Menu start-up it uses APT:PrepareToStartNewestHomeMenu. If that doesn't return an error(normally NS returns 0xC8A0CFFC for that), Home Menu starts a hardware reboot with APT:StartNewestHomeMenu etc. " --- src/core/hle/service/apt/apt.cpp | 14 ++++++++++++++ src/core/hle/service/apt/apt.h | 10 ++++++++++ src/core/hle/service/apt/apt_s.cpp | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index ea964bab1..490c14605 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -776,6 +776,20 @@ void PrepareToStartLibraryApplet(Service::Interface* self) { LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); } +void PrepareToStartNewestHomeMenu(Service::Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1A, 0, 0); // 0x1A0000 + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + + // TODO(Subv): This command can only be called by a System Applet (return 0xC8A0CC04 otherwise). + + // This command must return an error when called, otherwise the Home Menu will try to reboot the + // system. + rb.Push(ResultCode(ErrorDescription::AlreadyExists, ErrorModule::Applet, + ErrorSummary::InvalidState, ErrorLevel::Status)); + + LOG_DEBUG(Service_APT, "called"); +} + void PreloadLibraryApplet(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x16, 1, 0); // 0x160040 AppletId applet_id = static_cast(rp.Pop()); diff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.h index 96b28b438..7b79e1f3e 100644 --- a/src/core/hle/service/apt/apt.h +++ b/src/core/hle/service/apt/apt.h @@ -419,6 +419,16 @@ void GetAppCpuTimeLimit(Service::Interface* self); */ void PrepareToStartLibraryApplet(Service::Interface* self); +/** + * APT::PrepareToStartNewestHomeMenu service function + * Inputs: + * 0 : Command header [0x001A0000] + * Outputs: + * 0 : Return header + * 1 : Result of function + */ +void PrepareToStartNewestHomeMenu(Service::Interface* self); + /** * APT::PreloadLibraryApplet service function * Inputs: diff --git a/src/core/hle/service/apt/apt_s.cpp b/src/core/hle/service/apt/apt_s.cpp index ec5668d05..fe1d21fff 100644 --- a/src/core/hle/service/apt/apt_s.cpp +++ b/src/core/hle/service/apt/apt_s.cpp @@ -17,7 +17,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00060040, GetAppletInfo, "GetAppletInfo"}, {0x00070000, nullptr, "GetLastSignaledAppletId"}, {0x00080000, nullptr, "CountRegisteredApplet"}, - {0x00090040, nullptr, "IsRegistered"}, + {0x00090040, IsRegistered, "IsRegistered"}, {0x000A0040, nullptr, "GetAttribute"}, {0x000B0040, InquireNotification, "InquireNotification"}, {0x000C0104, nullptr, "SendParameter"}, @@ -34,7 +34,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00170040, nullptr, "FinishPreloadingLibraryApplet"}, {0x00180040, PrepareToStartLibraryApplet, "PrepareToStartLibraryApplet"}, {0x00190040, nullptr, "PrepareToStartSystemApplet"}, - {0x001A0000, nullptr, "PrepareToStartNewestHomeMenu"}, + {0x001A0000, PrepareToStartNewestHomeMenu, "PrepareToStartNewestHomeMenu"}, {0x001B00C4, nullptr, "StartApplication"}, {0x001C0000, nullptr, "WakeupApplication"}, {0x001D0000, nullptr, "CancelApplication"}, -- cgit v1.2.3 From d673d508dd1ca463dc72ff68b5582ee56d62f142 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Mon, 25 Sep 2017 08:16:27 +0200 Subject: Services/UDS: Added a function to send EAPoL-Start packets (#2920) * Services/UDS: Added a function to generate the EAPoL-Start packet body. * Services/UDS: Added filter for beacons. * Services/UDS: Lock a mutex when accessing connection_status from both the emulation and network thread. * Services/UDS: Handle the Association Response frame and respond with the EAPoL-Start frame. * fixup: make use of current_node, changed received_beacons into a list, mutex and assert corrections * fixup: fix damn clang-format --- src/core/hle/service/nwm/nwm_uds.cpp | 275 +++++++++++++++++++--------- src/core/hle/service/nwm/uds_connection.cpp | 9 + src/core/hle/service/nwm/uds_connection.h | 5 + src/core/hle/service/nwm/uds_data.cpp | 21 +++ src/core/hle/service/nwm/uds_data.h | 28 +++ 5 files changed, 250 insertions(+), 88 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 893bbb1e7..4e2af9ae6 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -2,8 +2,10 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include +#include #include #include #include @@ -37,9 +39,12 @@ static ConnectionStatus connection_status{}; /* Node information about the current network. * The amount of elements in this vector is always the maximum number * of nodes specified in the network configuration. - * The first node is always the host, so this always contains at least 1 entry. + * The first node is always the host. */ -static NodeList node_info(1); +static NodeList node_info; + +// Node information about our own system. +static NodeInfo current_node; // Mapping of bind node ids to their respective events. static std::unordered_map> bind_node_events; @@ -54,6 +59,10 @@ static NetworkInfo network_info; // Event that will generate and send the 802.11 beacon frames. static int beacon_broadcast_event; +// Mutex to synchronize access to the connection status between the emulation thread and the +// network thread. +static std::mutex connection_status_mutex; + // Mutex to synchronize access to the list of received beacons between the emulation thread and the // network thread. static std::mutex beacon_mutex; @@ -63,14 +72,26 @@ static std::mutex beacon_mutex; constexpr size_t MaxBeaconFrames = 15; // List of the last beacons received from the network. -static std::deque received_beacons; +static std::list received_beacons; /** * Returns a list of received 802.11 beacon frames from the specified sender since the last call. */ -std::deque GetReceivedBeacons(const MacAddress& sender) { +std::list GetReceivedBeacons(const MacAddress& sender) { std::lock_guard lock(beacon_mutex); - // TODO(Subv): Filter by sender. + if (sender != Network::BroadcastMac) { + std::list filtered_list; + const auto beacon = std::find_if(received_beacons.begin(), received_beacons.end(), + [&sender](const Network::WifiPacket& packet) { + return packet.transmitter_address == sender; + }); + if (beacon != received_beacons.end()) { + filtered_list.push_back(*beacon); + // TODO(B3N30): Check if the complete deque is cleared or just the fetched entries + received_beacons.erase(beacon); + } + return filtered_list; + } return std::move(received_beacons); } @@ -83,6 +104,15 @@ void SendPacket(Network::WifiPacket& packet) { // limit is exceeded. void HandleBeaconFrame(const Network::WifiPacket& packet) { std::lock_guard lock(beacon_mutex); + const auto unique_beacon = + std::find_if(received_beacons.begin(), received_beacons.end(), + [&packet](const Network::WifiPacket& new_packet) { + return new_packet.transmitter_address == packet.transmitter_address; + }); + if (unique_beacon != received_beacons.end()) { + // We already have a beacon from the same mac in the deque, remove the old one; + received_beacons.erase(unique_beacon); + } received_beacons.emplace_back(packet); @@ -91,14 +121,33 @@ void HandleBeaconFrame(const Network::WifiPacket& packet) { received_beacons.pop_front(); } +void HandleAssociationResponseFrame(const Network::WifiPacket& packet) { + auto assoc_result = GetAssociationResult(packet.data); + + ASSERT_MSG(std::get(assoc_result) == AssocStatus::Successful, + "Could not join network"); + { + std::lock_guard lock(connection_status_mutex); + ASSERT(connection_status.status == static_cast(NetworkStatus::Connecting)); + } + + // Send the EAPoL-Start packet to the server. + using Network::WifiPacket; + WifiPacket eapol_start; + eapol_start.channel = network_channel; + eapol_start.data = GenerateEAPoLStartFrame(std::get(assoc_result), current_node); + // TODO(B3N30): Encrypt the packet. + eapol_start.destination_address = packet.transmitter_address; + eapol_start.type = WifiPacket::PacketType::Data; + + SendPacket(eapol_start); +} + /* * Returns an available index in the nodes array for the * currently-hosted UDS network. */ static u16 GetNextAvailableNodeId() { - ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost), - "Can not accept clients if we're not hosting a network"); - for (u16 index = 0; index < connection_status.max_nodes; ++index) { if ((connection_status.node_bitmask & (1 << index)) == 0) return index; @@ -113,35 +162,46 @@ static u16 GetNextAvailableNodeId() { * authentication frame with SEQ1. */ void StartConnectionSequence(const MacAddress& server) { - ASSERT(connection_status.status == static_cast(NetworkStatus::NotConnected)); - - // TODO(Subv): Handle timeout. - - // Send an authentication frame with SEQ1 using Network::WifiPacket; WifiPacket auth_request; - auth_request.channel = network_channel; - auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ1); - auth_request.destination_address = server; - auth_request.type = WifiPacket::PacketType::Authentication; + { + std::lock_guard lock(connection_status_mutex); + ASSERT(connection_status.status == static_cast(NetworkStatus::NotConnected)); + + // TODO(Subv): Handle timeout. + + // Send an authentication frame with SEQ1 + auth_request.channel = network_channel; + auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ1); + auth_request.destination_address = server; + auth_request.type = WifiPacket::PacketType::Authentication; + } SendPacket(auth_request); } /// Sends an Association Response frame to the specified mac address void SendAssociationResponseFrame(const MacAddress& address) { - ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)); - using Network::WifiPacket; WifiPacket assoc_response; - assoc_response.channel = network_channel; - // TODO(Subv): This will cause multiple clients to end up with the same association id, but - // we're not using that for anything. - u16 association_id = 1; - assoc_response.data = GenerateAssocResponseFrame(AssocStatus::Successful, association_id, - network_info.network_id); - assoc_response.destination_address = address; - assoc_response.type = WifiPacket::PacketType::AssociationResponse; + + { + std::lock_guard lock(connection_status_mutex); + if (connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { + LOG_ERROR(Service_NWM, "Connection sequence aborted, because connection status is %u", + connection_status.status); + return; + } + + assoc_response.channel = network_channel; + // TODO(Subv): This will cause multiple clients to end up with the same association id, but + // we're not using that for anything. + u16 association_id = 1; + assoc_response.data = GenerateAssocResponseFrame(AssocStatus::Successful, association_id, + network_info.network_id); + assoc_response.destination_address = address; + assoc_response.type = WifiPacket::PacketType::AssociationResponse; + } SendPacket(assoc_response); } @@ -155,16 +215,23 @@ void SendAssociationResponseFrame(const MacAddress& address) { void HandleAuthenticationFrame(const Network::WifiPacket& packet) { // Only the SEQ1 auth frame is handled here, the SEQ2 frame doesn't need any special behavior if (GetAuthenticationSeqNumber(packet.data) == AuthenticationSeq::SEQ1) { - ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost)); - - // Respond with an authentication response frame with SEQ2 using Network::WifiPacket; WifiPacket auth_request; - auth_request.channel = network_channel; - auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ2); - auth_request.destination_address = packet.transmitter_address; - auth_request.type = WifiPacket::PacketType::Authentication; - + { + std::lock_guard lock(connection_status_mutex); + if (connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { + LOG_ERROR(Service_NWM, + "Connection sequence aborted, because connection status is %u", + connection_status.status); + return; + } + + // Respond with an authentication response frame with SEQ2 + auth_request.channel = network_channel; + auth_request.data = GenerateAuthenticationFrame(AuthenticationSeq::SEQ2); + auth_request.destination_address = packet.transmitter_address; + auth_request.type = WifiPacket::PacketType::Authentication; + } SendPacket(auth_request); SendAssociationResponseFrame(packet.transmitter_address); @@ -180,6 +247,9 @@ void OnWifiPacketReceived(const Network::WifiPacket& packet) { case Network::WifiPacket::PacketType::Authentication: HandleAuthenticationFrame(packet); break; + case Network::WifiPacket::PacketType::AssociationResponse: + HandleAssociationResponseFrame(packet); + break; } } @@ -305,7 +375,7 @@ static void InitializeWithVersion(Interface* self) { u32 sharedmem_size = rp.Pop(); // Update the node information with the data the game gave us. - rp.PopRaw(node_info[0]); + rp.PopRaw(current_node); u16 version = rp.Pop(); @@ -315,10 +385,14 @@ static void InitializeWithVersion(Interface* self) { ASSERT_MSG(recv_buffer_memory->size == sharedmem_size, "Invalid shared memory size."); - // Reset the connection status, it contains all zeros after initialization, - // except for the actual status value. - connection_status = {}; - connection_status.status = static_cast(NetworkStatus::NotConnected); + { + std::lock_guard lock(connection_status_mutex); + + // Reset the connection status, it contains all zeros after initialization, + // except for the actual status value. + connection_status = {}; + connection_status.status = static_cast(NetworkStatus::NotConnected); + } IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); rb.Push(RESULT_SUCCESS); @@ -348,12 +422,16 @@ static void GetConnectionStatus(Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(13, 0); rb.Push(RESULT_SUCCESS); - rb.PushRaw(connection_status); - - // Reset the bitmask of changed nodes after each call to this - // function to prevent falsely informing games of outstanding - // changes in subsequent calls. - connection_status.changed_nodes = 0; + { + std::lock_guard lock(connection_status_mutex); + rb.PushRaw(connection_status); + + // Reset the bitmask of changed nodes after each call to this + // function to prevent falsely informing games of outstanding + // changes in subsequent calls. + // TODO(Subv): Find exactly where the NWM module resets this value. + connection_status.changed_nodes = 0; + } LOG_DEBUG(Service_NWM, "called"); } @@ -434,31 +512,36 @@ static void BeginHostingNetwork(Interface* self) { // The real UDS module throws a fatal error if this assert fails. ASSERT_MSG(network_info.max_nodes > 1, "Trying to host a network of only one member."); - connection_status.status = static_cast(NetworkStatus::ConnectedAsHost); - - // Ensure the application data size is less than the maximum value. - ASSERT_MSG(network_info.application_data_size <= ApplicationDataSize, "Data size is too big."); - - // Set up basic information for this network. - network_info.oui_value = NintendoOUI; - network_info.oui_type = static_cast(NintendoTagId::NetworkInfo); - - connection_status.max_nodes = network_info.max_nodes; - - // Resize the nodes list to hold max_nodes. - node_info.resize(network_info.max_nodes); - - // There's currently only one node in the network (the host). - connection_status.total_nodes = 1; - network_info.total_nodes = 1; - // The host is always the first node - connection_status.network_node_id = 1; - node_info[0].network_node_id = 1; - connection_status.nodes[0] = connection_status.network_node_id; - // Set the bit 0 in the nodes bitmask to indicate that node 1 is already taken. - connection_status.node_bitmask |= 1; - // Notify the application that the first node was set. - connection_status.changed_nodes |= 1; + { + std::lock_guard lock(connection_status_mutex); + connection_status.status = static_cast(NetworkStatus::ConnectedAsHost); + + // Ensure the application data size is less than the maximum value. + ASSERT_MSG(network_info.application_data_size <= ApplicationDataSize, + "Data size is too big."); + + // Set up basic information for this network. + network_info.oui_value = NintendoOUI; + network_info.oui_type = static_cast(NintendoTagId::NetworkInfo); + + connection_status.max_nodes = network_info.max_nodes; + + // Resize the nodes list to hold max_nodes. + node_info.resize(network_info.max_nodes); + + // There's currently only one node in the network (the host). + connection_status.total_nodes = 1; + network_info.total_nodes = 1; + // The host is always the first node + connection_status.network_node_id = 1; + current_node.network_node_id = 1; + connection_status.nodes[0] = connection_status.network_node_id; + // Set the bit 0 in the nodes bitmask to indicate that node 1 is already taken. + connection_status.node_bitmask |= 1; + // Notify the application that the first node was set. + connection_status.changed_nodes |= 1; + node_info[0] = current_node; + } // If the game has a preferred channel, use that instead. if (network_info.channel != 0) @@ -495,9 +578,13 @@ static void DestroyNetwork(Interface* self) { // Unschedule the beacon broadcast event. CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); - // TODO(Subv): Check if connection_status is indeed reset after this call. - connection_status = {}; - connection_status.status = static_cast(NetworkStatus::NotConnected); + { + std::lock_guard lock(connection_status_mutex); + + // TODO(Subv): Check if connection_status is indeed reset after this call. + connection_status = {}; + connection_status.status = static_cast(NetworkStatus::NotConnected); + } connection_status_event->Signal(); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -540,17 +627,24 @@ static void SendTo(Interface* self) { IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - if (connection_status.status != static_cast(NetworkStatus::ConnectedAsClient) && - connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { - rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, - ErrorSummary::InvalidState, ErrorLevel::Status)); - return; - } + u16 network_node_id; - if (dest_node_id == connection_status.network_node_id) { - rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::UDS, - ErrorSummary::WrongArgument, ErrorLevel::Status)); - return; + { + std::lock_guard lock(connection_status_mutex); + if (connection_status.status != static_cast(NetworkStatus::ConnectedAsClient) && + connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { + rb.Push(ResultCode(ErrorDescription::NotAuthorized, ErrorModule::UDS, + ErrorSummary::InvalidState, ErrorLevel::Status)); + return; + } + + if (dest_node_id == connection_status.network_node_id) { + rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::UDS, + ErrorSummary::WrongArgument, ErrorLevel::Status)); + return; + } + + network_node_id = connection_status.network_node_id; } // TODO(Subv): Do something with the flags. @@ -567,8 +661,8 @@ static void SendTo(Interface* self) { // TODO(Subv): Increment the sequence number after each sent packet. u16 sequence_number = 0; - std::vector data_payload = GenerateDataPayload( - data, data_channel, dest_node_id, connection_status.network_node_id, sequence_number); + std::vector data_payload = + GenerateDataPayload(data, data_channel, dest_node_id, network_node_id, sequence_number); // TODO(Subv): Retrieve the MAC address of the dest_node_id and our own to encrypt // and encapsulate the payload. @@ -595,6 +689,7 @@ static void GetChannel(Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1A, 0, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); + std::lock_guard lock(connection_status_mutex); bool is_connected = connection_status.status != static_cast(NetworkStatus::NotConnected); u8 channel = is_connected ? network_channel : 0; @@ -766,6 +861,7 @@ static void BeaconBroadcastCallback(u64 userdata, int cycles_late) { * @param network_node_id Network Node Id of the connecting client. */ void OnClientConnected(u16 network_node_id) { + std::lock_guard lock(connection_status_mutex); ASSERT_MSG(connection_status.status == static_cast(NetworkStatus::ConnectedAsHost), "Can not accept clients if we're not hosting a network"); ASSERT_MSG(connection_status.total_nodes < connection_status.max_nodes, @@ -827,8 +923,11 @@ NWM_UDS::~NWM_UDS() { connection_status_event = nullptr; recv_buffer_memory = nullptr; - connection_status = {}; - connection_status.status = static_cast(NetworkStatus::NotConnected); + { + std::lock_guard lock(connection_status_mutex); + connection_status = {}; + connection_status.status = static_cast(NetworkStatus::NotConnected); + } CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0); } diff --git a/src/core/hle/service/nwm/uds_connection.cpp b/src/core/hle/service/nwm/uds_connection.cpp index c8a76ec2a..c74f51253 100644 --- a/src/core/hle/service/nwm/uds_connection.cpp +++ b/src/core/hle/service/nwm/uds_connection.cpp @@ -75,5 +75,14 @@ std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_i return data; } +std::tuple GetAssociationResult(const std::vector& body) { + AssociationResponseFrame frame; + memcpy(&frame, body.data(), sizeof(frame)); + + constexpr u16 AssociationIdMask = 0x3FFF; + return std::make_tuple(static_cast(frame.status_code), + frame.assoc_id & AssociationIdMask); +} + } // namespace NWM } // namespace Service diff --git a/src/core/hle/service/nwm/uds_connection.h b/src/core/hle/service/nwm/uds_connection.h index 73f55a4fd..a664f8471 100644 --- a/src/core/hle/service/nwm/uds_connection.h +++ b/src/core/hle/service/nwm/uds_connection.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" #include "common/swap.h" @@ -47,5 +48,9 @@ AuthenticationSeq GetAuthenticationSeqNumber(const std::vector& body); /// network id, starting at the frame body. std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_id, u32 network_id); +/// Returns a tuple of (association status, association id) from the body of an AssociationResponse +/// frame. +std::tuple GetAssociationResult(const std::vector& body); + } // namespace NWM } // namespace Service diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 8c6742dba..0fd9b8b8c 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -274,5 +274,26 @@ std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 return buffer; } +std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node_info) { + EAPoLStartPacket eapol_start{}; + eapol_start.association_id = association_id; + eapol_start.friend_code_seed = node_info.friend_code_seed; + + for (int i = 0; i < node_info.username.size(); ++i) + eapol_start.username[i] = node_info.username[i]; + + // Note: The network_node_id and unknown bytes seem to be uninitialized in the NWM module. + // TODO(B3N30): The last 8 bytes seem to have a fixed value of 07 88 15 00 04 e9 13 00 in + // EAPoL-Start packets from different 3DSs to the same host during a Super Smash Bros. 4 game. + // Find out what that means. + + std::vector eapol_buffer(sizeof(EAPoLStartPacket)); + std::memcpy(eapol_buffer.data(), &eapol_start, sizeof(eapol_start)); + + std::vector buffer = GenerateLLCHeader(EtherType::EAPoL); + buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end()); + return buffer; +} + } // namespace NWM } // namespace Service diff --git a/src/core/hle/service/nwm/uds_data.h b/src/core/hle/service/nwm/uds_data.h index a23520a41..76e8f546b 100644 --- a/src/core/hle/service/nwm/uds_data.h +++ b/src/core/hle/service/nwm/uds_data.h @@ -67,6 +67,27 @@ struct DataFrameCryptoCTR { static_assert(sizeof(DataFrameCryptoCTR) == 16, "DataFrameCryptoCTR has the wrong size"); +constexpr u16 EAPoLStartMagic = 0x201; + +/* + * Nintendo EAPoLStartPacket, is used to initaliaze a connection between client and host + */ +struct EAPoLStartPacket { + u16_be magic = EAPoLStartMagic; + u16_be association_id; + // This value is hardcoded to 1 in the NWM module. + u16_be unknown = 1; + INSERT_PADDING_BYTES(2); + + u64_be friend_code_seed; + std::array username; + INSERT_PADDING_BYTES(4); + u16_be network_node_id; + INSERT_PADDING_BYTES(6); +}; + +static_assert(sizeof(EAPoLStartPacket) == 0x30, "EAPoLStartPacket has the wrong size"); + /** * Generates an unencrypted 802.11 data payload. * @returns The generated frame payload. @@ -74,5 +95,12 @@ static_assert(sizeof(DataFrameCryptoCTR) == 16, "DataFrameCryptoCTR has the wron std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number); +/* + * Generates an unencrypted 802.11 data frame body with the EAPoL-Start format for UDS + * communication. + * @returns The generated frame body. + */ +std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node_info); + } // namespace NWM } // namespace Service -- cgit v1.2.3 From 774e7deae8655a6f09530770c56ae2e75d55309b Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 23 Sep 2017 20:32:18 -0500 Subject: HLE/Archives: Allow multiple loaded applications to access their SelfNCCH archive independently. The loaders now register each loaded ROM with the SelfNCCH factory, which keeps the data around for the duration of the emulation session. When opening the SelfNCCH archive, the factory queries the current program's programid and uses that as a key to the map that contains the NCCHData structure (RomFS, Icon, Banner, etc). 3dsx files do not have a programid and will use a default of 0 for this value, thus, only 1 3dsx file with RomFS is loadable at the same time. --- src/core/hle/service/fs/archive.cpp | 18 +++++++++++++++++- src/core/hle/service/fs/archive.h | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 033fbc9aa..4ccb3cd32 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -20,6 +20,7 @@ #include "core/file_sys/archive_savedata.h" #include "core/file_sys/archive_sdmc.h" #include "core/file_sys/archive_sdmcwriteonly.h" +#include "core/file_sys/archive_selfncch.h" #include "core/file_sys/archive_systemsavedata.h" #include "core/file_sys/directory_backend.h" #include "core/file_sys/errors.h" @@ -48,7 +49,7 @@ struct hash { return std::hash()(static_cast(id_code)); } }; -} +} // namespace std static constexpr Kernel::Handle INVALID_HANDLE{}; @@ -564,6 +565,21 @@ void RegisterArchiveTypes() { auto systemsavedata_factory = std::make_unique(nand_directory); RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData); + + auto selfncch_factory = std::make_unique(); + RegisterArchiveType(std::move(selfncch_factory), ArchiveIdCode::SelfNCCH); +} + +void RegisterSelfNCCH(Loader::AppLoader& app_loader) { + auto itr = id_code_map.find(ArchiveIdCode::SelfNCCH); + if (itr == id_code_map.end()) { + LOG_ERROR(Service_FS, + "Could not register a new NCCH because the SelfNCCH archive hasn't been created"); + return; + } + + auto* factory = static_cast(itr->second.get()); + factory->Register(app_loader); } void UnregisterArchiveTypes() { diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 3a3371c88..e3c8fc2ef 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -21,6 +21,10 @@ static constexpr char SYSTEM_ID[]{"00000000000000000000000000000000"}; /// The scrambled SD card CID, also known as ID1 static constexpr char SDCARD_ID[]{"00000000000000000000000000000000"}; +namespace Loader { +class AppLoader; +} + namespace Service { namespace FS { @@ -259,6 +263,9 @@ void ArchiveInit(); /// Shutdown archives void ArchiveShutdown(); +/// Registers a new NCCH file with the SelfNCCH archive factory +void RegisterSelfNCCH(Loader::AppLoader& app_loader); + /// Register all archive types void RegisterArchiveTypes(); -- cgit v1.2.3 From e27ae046960e20144892cf8252d8a672a48b0123 Mon Sep 17 00:00:00 2001 From: Subv Date: Sun, 24 Sep 2017 19:09:13 -0500 Subject: HLE/APT: Always set up the APT parameter when starting a library applet. Only use the HLE interface if an HLE applet with the desired id was started. This commit reorganizes the APT code surrounding parameter creation and delivery to make it easier to support LLE applets in the future. As future work, the HLE applet interface can be reworked to utilize the same facilities as the LLE interface. --- src/core/hle/service/apt/apt.cpp | 73 +++++++++++++++++++++++--------------- src/core/hle/service/apt/apt_s.cpp | 4 +-- 2 files changed, 47 insertions(+), 30 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 8c0ba73f2..c36775473 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -165,7 +165,11 @@ void SendParameter(const MessageParameter& parameter) { next_parameter = parameter; // Signal the event to let the receiver know that a new parameter is ready to be read auto* const slot_data = GetAppletSlotData(static_cast(parameter.destination_id)); - ASSERT(slot_data); + if (slot_data == nullptr) { + LOG_DEBUG(Service_APT, "No applet was registered with the id %03X", + parameter.destination_id); + return; + } slot_data->parameter_event->Signal(); } @@ -486,9 +490,6 @@ void SendParameter(Service::Interface* self) { size_t size; VAddr buffer = rp.PopStaticBuffer(&size); - std::shared_ptr dest_applet = - HLE::Applets::Applet::Get(static_cast(dst_app_id)); - LOG_DEBUG(Service_APT, "called src_app_id=0x%08X, dst_app_id=0x%08X, signal_type=0x%08X," "buffer_size=0x%08X, handle=0x%08X, size=0x%08zX, in_param_buffer_ptr=0x%08X", @@ -503,12 +504,6 @@ void SendParameter(Service::Interface* self) { return; } - if (dest_applet == nullptr) { - LOG_ERROR(Service_APT, "Unknown applet id=0x%08X", dst_app_id); - rb.Push(-1); // TODO(Subv): Find the right error code - return; - } - MessageParameter param; param.destination_id = dst_app_id; param.sender_id = src_app_id; @@ -517,7 +512,14 @@ void SendParameter(Service::Interface* self) { param.buffer.resize(buffer_size); Memory::ReadBlock(buffer, param.buffer.data(), param.buffer.size()); - rb.Push(dest_applet->ReceiveParameter(param)); + SendParameter(param); + + // If the applet is running in HLE mode, use the HLE interface to communicate with it. + if (auto dest_applet = HLE::Applets::Applet::Get(static_cast(dst_app_id))) { + rb.Push(dest_applet->ReceiveParameter(param)); + } else { + rb.Push(RESULT_SUCCESS); + } } void ReceiveParameter(Service::Interface* self) { @@ -746,7 +748,12 @@ void PrepareToStartLibraryApplet(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x18, 1, 0); // 0x180040 AppletId applet_id = static_cast(rp.Pop()); + LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + + // TODO(Subv): Launch the requested applet application. + auto applet = HLE::Applets::Applet::Get(applet_id); if (applet) { LOG_WARNING(Service_APT, "applet has already been started id=%08X", applet_id); @@ -754,14 +761,18 @@ void PrepareToStartLibraryApplet(Service::Interface* self) { } else { rb.Push(HLE::Applets::Applet::Create(applet_id)); } - LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); } void PreloadLibraryApplet(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x16, 1, 0); // 0x160040 AppletId applet_id = static_cast(rp.Pop()); + LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + + // TODO(Subv): Launch the requested applet application. + auto applet = HLE::Applets::Applet::Get(applet_id); if (applet) { LOG_WARNING(Service_APT, "applet has already been started id=%08X", applet_id); @@ -769,34 +780,40 @@ void PreloadLibraryApplet(Service::Interface* self) { } else { rb.Push(HLE::Applets::Applet::Create(applet_id)); } - LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); } void StartLibraryApplet(Service::Interface* self) { IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x1E, 2, 4); // 0x1E0084 AppletId applet_id = static_cast(rp.Pop()); - std::shared_ptr applet = HLE::Applets::Applet::Get(applet_id); - - LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); - - if (applet == nullptr) { - LOG_ERROR(Service_APT, "unknown applet id=%08X", applet_id); - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0, false); - rb.Push(-1); // TODO(Subv): Find the right error code - return; - } size_t buffer_size = rp.Pop(); Kernel::Handle handle = rp.PopHandle(); VAddr buffer_addr = rp.PopStaticBuffer(); - AppletStartupParameter parameter; - parameter.object = Kernel::g_handle_table.GetGeneric(handle); - parameter.buffer.resize(buffer_size); - Memory::ReadBlock(buffer_addr, parameter.buffer.data(), parameter.buffer.size()); + LOG_DEBUG(Service_APT, "called applet_id=%08X", applet_id); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(applet->Start(parameter)); + + // Send the Wakeup signal to the applet + MessageParameter param; + param.destination_id = static_cast(applet_id); + param.sender_id = static_cast(AppletId::Application); + param.object = Kernel::g_handle_table.GetGeneric(handle); + param.signal = static_cast(SignalType::Wakeup); + param.buffer.resize(buffer_size); + Memory::ReadBlock(buffer_addr, param.buffer.data(), param.buffer.size()); + SendParameter(param); + + // In case the applet is being HLEd, attempt to communicate with it. + if (auto applet = HLE::Applets::Applet::Get(applet_id)) { + AppletStartupParameter parameter; + parameter.object = Kernel::g_handle_table.GetGeneric(handle); + parameter.buffer.resize(buffer_size); + Memory::ReadBlock(buffer_addr, parameter.buffer.data(), parameter.buffer.size()); + rb.Push(applet->Start(parameter)); + } else { + rb.Push(RESULT_SUCCESS); + } } void CancelLibraryApplet(Service::Interface* self) { diff --git a/src/core/hle/service/apt/apt_s.cpp b/src/core/hle/service/apt/apt_s.cpp index ec5668d05..cf74c2a36 100644 --- a/src/core/hle/service/apt/apt_s.cpp +++ b/src/core/hle/service/apt/apt_s.cpp @@ -20,7 +20,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00090040, nullptr, "IsRegistered"}, {0x000A0040, nullptr, "GetAttribute"}, {0x000B0040, InquireNotification, "InquireNotification"}, - {0x000C0104, nullptr, "SendParameter"}, + {0x000C0104, SendParameter, "SendParameter"}, {0x000D0080, ReceiveParameter, "ReceiveParameter"}, {0x000E0080, GlanceParameter, "GlanceParameter"}, {0x000F0100, nullptr, "CancelParameter"}, @@ -38,7 +38,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x001B00C4, nullptr, "StartApplication"}, {0x001C0000, nullptr, "WakeupApplication"}, {0x001D0000, nullptr, "CancelApplication"}, - {0x001E0084, nullptr, "StartLibraryApplet"}, + {0x001E0084, StartLibraryApplet, "StartLibraryApplet"}, {0x001F0084, nullptr, "StartSystemApplet"}, {0x00200044, nullptr, "StartNewestHomeMenu"}, {0x00210000, nullptr, "OrderToCloseApplication"}, -- cgit v1.2.3 From a13ab958cbba75bc9abd1ca50f3030a10a75784e Mon Sep 17 00:00:00 2001 From: Huw Pascoe Date: Wed, 27 Sep 2017 00:26:09 +0100 Subject: Fixed type conversion ambiguity --- src/core/hle/service/apt/apt.cpp | 4 ++-- src/core/hle/service/cam/cam.cpp | 2 +- src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/fs/archive.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 2 +- src/core/hle/service/ldr_ro/cro_helper.h | 6 ++++-- src/core/hle/service/nwm/nwm_uds.cpp | 10 +++++----- src/core/hle/service/nwm/uds_beacon.cpp | 4 ++-- src/core/hle/service/nwm/uds_data.cpp | 8 ++++---- 9 files changed, 21 insertions(+), 19 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 8c0ba73f2..4c6156345 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -561,7 +561,7 @@ void ReceiveParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); @@ -609,7 +609,7 @@ void GlanceParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index c9f9e9d95..8172edae8 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -177,7 +177,7 @@ void CompletionEventCallBack(u64 port_id, int) { LOG_ERROR(Service_CAM, "The destination size (%u) doesn't match the source (%zu)!", port.dest_size, buffer_size); } - Memory::WriteBlock(port.dest, buffer.data(), std::min(port.dest_size, buffer_size)); + Memory::WriteBlock(port.dest, buffer.data(), std::min(port.dest_size, buffer_size)); } port.is_receiving = false; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index f26a1f65f..f78c25fb2 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -141,7 +141,7 @@ void GetCountryCodeString(Service::Interface* self) { void GetCountryCodeID(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); - u16 country_code = cmd_buff[1]; + u16 country_code = static_cast(cmd_buff[1]); u16 country_code_id = 0; // The following algorithm will fail if the first country code isn't 0. diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 4ccb3cd32..4ee7df73c 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -217,7 +217,7 @@ void Directory::HandleSyncRequest(Kernel::SharedPtr serve LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count); // Number of entries actually read - u32 read = backend->Read(entries.size(), entries.data()); + u32 read = backend->Read(static_cast(entries.size()), entries.data()); cmd_buff[2] = read; Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry)); break; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index aa5d821f9..379fbd71c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -251,7 +251,7 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) { Math::Vec3 gyro; std::tie(std::ignore, gyro) = motion_device->GetStatus(); double stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); - gyro *= gyroscope_coef * stretch; + gyro *= gyroscope_coef * static_cast(stretch); gyroscope_entry.x = static_cast(gyro.x); gyroscope_entry.y = static_cast(gyro.y); gyroscope_entry.z = static_cast(gyro.z); diff --git a/src/core/hle/service/ldr_ro/cro_helper.h b/src/core/hle/service/ldr_ro/cro_helper.h index 3bc10dbdc..57b4fb6df 100644 --- a/src/core/hle/service/ldr_ro/cro_helper.h +++ b/src/core/hle/service/ldr_ro/cro_helper.h @@ -413,7 +413,8 @@ private: */ template void GetEntry(std::size_t index, T& data) const { - Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast(index * sizeof(T)), + &data, sizeof(T)); } /** @@ -425,7 +426,8 @@ private: */ template void SetEntry(std::size_t index, const T& data) { - Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast(index * sizeof(T)), + &data, sizeof(T)); } /** diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 4e2af9ae6..8ef0cda09 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -316,7 +316,7 @@ static void RecvBeaconBroadcastData(Interface* self) { auto beacons = GetReceivedBeacons(mac_address); BeaconDataReplyHeader data_reply_header{}; - data_reply_header.total_entries = beacons.size(); + data_reply_header.total_entries = static_cast(beacons.size()); data_reply_header.max_output_size = out_buffer_size; Memory::WriteBlock(current_buffer_pos, &data_reply_header, sizeof(BeaconDataReplyHeader)); @@ -326,8 +326,8 @@ static void RecvBeaconBroadcastData(Interface* self) { for (const auto& beacon : beacons) { BeaconEntryHeader entry{}; // TODO(Subv): Figure out what this size is used for. - entry.unk_size = sizeof(BeaconEntryHeader) + beacon.data.size(); - entry.total_size = sizeof(BeaconEntryHeader) + beacon.data.size(); + entry.unk_size = static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); + entry.total_size = static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); entry.wifi_channel = beacon.channel; entry.header_size = sizeof(BeaconEntryHeader); entry.mac_address = beacon.transmitter_address; @@ -338,9 +338,9 @@ static void RecvBeaconBroadcastData(Interface* self) { current_buffer_pos += sizeof(BeaconEntryHeader); Memory::WriteBlock(current_buffer_pos, beacon.data.data(), beacon.data.size()); - current_buffer_pos += beacon.data.size(); + current_buffer_pos += static_cast(beacon.data.size()); - total_size += sizeof(BeaconEntryHeader) + beacon.data.size(); + total_size += static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); } // Update the total size in the structure and write it to the buffer again. diff --git a/src/core/hle/service/nwm/uds_beacon.cpp b/src/core/hle/service/nwm/uds_beacon.cpp index 552eaf65e..73a80d940 100644 --- a/src/core/hle/service/nwm/uds_beacon.cpp +++ b/src/core/hle/service/nwm/uds_beacon.cpp @@ -243,7 +243,7 @@ std::vector GenerateNintendoFirstEncryptedDataTag(const NetworkInfo& network EncryptedDataTag tag{}; tag.header.tag_id = static_cast(TagId::VendorSpecific); - tag.header.length = sizeof(tag) - sizeof(TagHeader) + payload_size; + tag.header.length = static_cast(sizeof(tag) - sizeof(TagHeader) + payload_size); tag.oui_type = static_cast(NintendoTagId::EncryptedData0); tag.oui = NintendoOUI; @@ -279,7 +279,7 @@ std::vector GenerateNintendoSecondEncryptedDataTag(const NetworkInfo& networ EncryptedDataTag tag{}; tag.header.tag_id = static_cast(TagId::VendorSpecific); - tag.header.length = tag_length; + tag.header.length = static_cast(tag_length); tag.oui_type = static_cast(NintendoTagId::EncryptedData1); tag.oui = NintendoOUI; diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 0fd9b8b8c..3ef2a84b6 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -197,7 +197,7 @@ static std::vector DecryptDataFrame(const std::vector& encrypted_payload df.ChannelMessageEnd(CryptoPP::DEFAULT_CHANNEL); df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector pdata(size); df.Get(pdata.data(), size); @@ -251,7 +251,7 @@ static std::vector EncryptDataFrame(const std::vector& payload, df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector cipher(size); df.Get(cipher.data(), size); @@ -266,8 +266,8 @@ static std::vector EncryptDataFrame(const std::vector& payload, std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number) { std::vector buffer = GenerateLLCHeader(EtherType::SecureData); - std::vector securedata_header = - GenerateSecureDataHeader(data.size(), channel, dest_node, src_node, sequence_number); + std::vector securedata_header = GenerateSecureDataHeader( + static_cast(data.size()), channel, dest_node, src_node, sequence_number); buffer.insert(buffer.end(), securedata_header.begin(), securedata_header.end()); buffer.insert(buffer.end(), data.begin(), data.end()); -- cgit v1.2.3 From afb1012bcd7e7aea2428aadb195b04ef72fcf861 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Sat, 30 Sep 2017 18:18:45 +0200 Subject: Services/UDS: Handle the rest of the connection sequence. (#2963) Services/UDS: Handle the rest of the connection sequence. --- src/core/hle/service/nwm/nwm_uds.cpp | 121 ++++++++++++++++++++++++++++++---- src/core/hle/service/nwm/uds_data.cpp | 80 +++++++++++++++++++++- src/core/hle/service/nwm/uds_data.h | 68 +++++++++++++++++-- 3 files changed, 250 insertions(+), 19 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 8ef0cda09..0aa63cc1e 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -15,6 +15,7 @@ #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/event.h" #include "core/hle/kernel/shared_memory.h" +#include "core/hle/lock.h" #include "core/hle/result.h" #include "core/hle/service/nwm/nwm_uds.h" #include "core/hle/service/nwm/uds_beacon.h" @@ -100,6 +101,20 @@ void SendPacket(Network::WifiPacket& packet) { // TODO(Subv): Implement. } +/* + * Returns an available index in the nodes array for the + * currently-hosted UDS network. + */ +static u16 GetNextAvailableNodeId() { + for (u16 index = 0; index < connection_status.max_nodes; ++index) { + if ((connection_status.node_bitmask & (1 << index)) == 0) + return index; + } + + // Any connection attempts to an already full network should have been refused. + ASSERT_MSG(false, "No available connection slots in the network"); +} + // Inserts the received beacon frame in the beacon queue and removes any older beacons if the size // limit is exceeded. void HandleBeaconFrame(const Network::WifiPacket& packet) { @@ -143,18 +158,88 @@ void HandleAssociationResponseFrame(const Network::WifiPacket& packet) { SendPacket(eapol_start); } -/* - * Returns an available index in the nodes array for the - * currently-hosted UDS network. - */ -static u16 GetNextAvailableNodeId() { - for (u16 index = 0; index < connection_status.max_nodes; ++index) { - if ((connection_status.node_bitmask & (1 << index)) == 0) - return index; - } +static void HandleEAPoLPacket(const Network::WifiPacket& packet) { + std::lock_guard lock(connection_status_mutex); - // Any connection attempts to an already full network should have been refused. - ASSERT_MSG(false, "No available connection slots in the network"); + if (GetEAPoLFrameType(packet.data) == EAPoLStartMagic) { + if (connection_status.status != static_cast(NetworkStatus::ConnectedAsHost)) { + LOG_DEBUG(Service_NWM, "Connection sequence aborted, because connection status is %u", + connection_status.status); + return; + } + + auto node = DeserializeNodeInfoFromFrame(packet.data); + + if (connection_status.max_nodes == connection_status.total_nodes) { + // Reject connection attempt + LOG_ERROR(Service_NWM, "Reached maximum nodes, but reject packet wasn't sent."); + // TODO(B3N30): Figure out what packet is sent here + return; + } + + // Get an unused network node id + u16 node_id = GetNextAvailableNodeId(); + node.network_node_id = node_id + 1; + + connection_status.node_bitmask |= 1 << node_id; + connection_status.changed_nodes |= 1 << node_id; + connection_status.nodes[node_id] = node.network_node_id; + connection_status.total_nodes++; + + u8 current_nodes = network_info.total_nodes; + node_info[current_nodes] = node; + + network_info.total_nodes++; + + // Send the EAPoL-Logoff packet. + using Network::WifiPacket; + WifiPacket eapol_logoff; + eapol_logoff.channel = network_channel; + eapol_logoff.data = + GenerateEAPoLLogoffFrame(packet.transmitter_address, node.network_node_id, node_info, + network_info.max_nodes, network_info.total_nodes); + // TODO(Subv): Encrypt the packet. + eapol_logoff.destination_address = packet.transmitter_address; + eapol_logoff.type = WifiPacket::PacketType::Data; + + SendPacket(eapol_logoff); + // TODO(B3N30): Broadcast updated node list + // The 3ds does this presumably to support spectators. + std::lock_guard lock(HLE::g_hle_lock); + connection_status_event->Signal(); + } else { + if (connection_status.status != static_cast(NetworkStatus::NotConnected)) { + LOG_DEBUG(Service_NWM, "Connection sequence aborted, because connection status is %u", + connection_status.status); + return; + } + auto logoff = ParseEAPoLLogoffFrame(packet.data); + + network_info.total_nodes = logoff.connected_nodes; + network_info.max_nodes = logoff.max_nodes; + + connection_status.network_node_id = logoff.assigned_node_id; + connection_status.total_nodes = logoff.connected_nodes; + connection_status.max_nodes = logoff.max_nodes; + + node_info.clear(); + node_info.reserve(network_info.max_nodes); + for (size_t index = 0; index < logoff.connected_nodes; ++index) { + connection_status.node_bitmask |= 1 << index; + connection_status.changed_nodes |= 1 << index; + connection_status.nodes[index] = logoff.nodes[index].network_node_id; + + node_info.emplace_back(DeserializeNodeInfo(logoff.nodes[index])); + } + + // We're now connected, signal the application + connection_status.status = static_cast(NetworkStatus::ConnectedAsClient); + // Some games require ConnectToNetwork to block, for now it doesn't + // If blocking is implemented this lock needs to be changed, + // otherwise it might cause deadlocks + std::lock_guard lock(HLE::g_hle_lock); + connection_status_event->Signal(); + } } /* @@ -238,6 +323,17 @@ void HandleAuthenticationFrame(const Network::WifiPacket& packet) { } } +static void HandleDataFrame(const Network::WifiPacket& packet) { + switch (GetFrameEtherType(packet.data)) { + case EtherType::EAPoL: + HandleEAPoLPacket(packet); + break; + case EtherType::SecureData: + // TODO(B3N30): Handle SecureData packets + break; + } +} + /// Callback to parse and handle a received wifi packet. void OnWifiPacketReceived(const Network::WifiPacket& packet) { switch (packet.type) { @@ -250,6 +346,9 @@ void OnWifiPacketReceived(const Network::WifiPacket& packet) { case Network::WifiPacket::PacketType::AssociationResponse: HandleAssociationResponseFrame(packet); break; + case Network::WifiPacket::PacketType::Data: + HandleDataFrame(packet); + break; } } diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 3ef2a84b6..4b389710f 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -277,10 +278,10 @@ std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node_info) { EAPoLStartPacket eapol_start{}; eapol_start.association_id = association_id; - eapol_start.friend_code_seed = node_info.friend_code_seed; + eapol_start.node.friend_code_seed = node_info.friend_code_seed; - for (int i = 0; i < node_info.username.size(); ++i) - eapol_start.username[i] = node_info.username[i]; + std::copy(node_info.username.begin(), node_info.username.end(), + eapol_start.node.username.begin()); // Note: The network_node_id and unknown bytes seem to be uninitialized in the NWM module. // TODO(B3N30): The last 8 bytes seem to have a fixed value of 07 88 15 00 04 e9 13 00 in @@ -295,5 +296,78 @@ std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node return buffer; } +EtherType GetFrameEtherType(const std::vector& frame) { + LLCHeader header; + std::memcpy(&header, frame.data(), sizeof(header)); + + u16 ethertype = header.protocol; + return static_cast(ethertype); +} + +u16 GetEAPoLFrameType(const std::vector& frame) { + // Ignore the LLC header + u16_be eapol_type; + std::memcpy(&eapol_type, frame.data() + sizeof(LLCHeader), sizeof(eapol_type)); + return eapol_type; +} + +NodeInfo DeserializeNodeInfoFromFrame(const std::vector& frame) { + EAPoLStartPacket eapol_start; + + // Skip the LLC header + std::memcpy(&eapol_start, frame.data() + sizeof(LLCHeader), sizeof(eapol_start)); + + NodeInfo node{}; + node.friend_code_seed = eapol_start.node.friend_code_seed; + + std::copy(eapol_start.node.username.begin(), eapol_start.node.username.end(), + node.username.begin()); + + return node; +} + +NodeInfo DeserializeNodeInfo(const EAPoLNodeInfo& node) { + NodeInfo node_info{}; + node_info.friend_code_seed = node.friend_code_seed; + node_info.network_node_id = node.network_node_id; + + std::copy(node.username.begin(), node.username.end(), node_info.username.begin()); + + return node_info; +} + +std::vector GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 network_node_id, + const NodeList& nodes, u8 max_nodes, u8 total_nodes) { + EAPoLLogoffPacket eapol_logoff{}; + eapol_logoff.assigned_node_id = network_node_id; + eapol_logoff.connected_nodes = total_nodes; + eapol_logoff.max_nodes = max_nodes; + + for (size_t index = 0; index < total_nodes; ++index) { + const auto& node_info = nodes[index]; + auto& node = eapol_logoff.nodes[index]; + + node.friend_code_seed = node_info.friend_code_seed; + node.network_node_id = node_info.network_node_id; + + std::copy(node_info.username.begin(), node_info.username.end(), node.username.begin()); + } + + std::vector eapol_buffer(sizeof(EAPoLLogoffPacket)); + std::memcpy(eapol_buffer.data(), &eapol_logoff, sizeof(eapol_logoff)); + + std::vector buffer = GenerateLLCHeader(EtherType::EAPoL); + buffer.insert(buffer.end(), eapol_buffer.begin(), eapol_buffer.end()); + return buffer; +} + +EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector& frame) { + EAPoLLogoffPacket eapol_logoff; + + // Skip the LLC header + std::memcpy(&eapol_logoff, frame.data() + sizeof(LLCHeader), sizeof(eapol_logoff)); + return eapol_logoff; +} + } // namespace NWM } // namespace Service diff --git a/src/core/hle/service/nwm/uds_data.h b/src/core/hle/service/nwm/uds_data.h index 76e8f546b..76bccb1bf 100644 --- a/src/core/hle/service/nwm/uds_data.h +++ b/src/core/hle/service/nwm/uds_data.h @@ -8,6 +8,7 @@ #include #include "common/common_types.h" #include "common/swap.h" +#include "core/hle/service/nwm/uds_beacon.h" #include "core/hle/service/service.h" namespace Service { @@ -67,6 +68,16 @@ struct DataFrameCryptoCTR { static_assert(sizeof(DataFrameCryptoCTR) == 16, "DataFrameCryptoCTR has the wrong size"); +struct EAPoLNodeInfo { + u64_be friend_code_seed; + std::array username; + INSERT_PADDING_BYTES(4); + u16_be network_node_id; + INSERT_PADDING_BYTES(6); +}; + +static_assert(sizeof(EAPoLNodeInfo) == 0x28, "EAPoLNodeInfo has the wrong size"); + constexpr u16 EAPoLStartMagic = 0x201; /* @@ -78,15 +89,27 @@ struct EAPoLStartPacket { // This value is hardcoded to 1 in the NWM module. u16_be unknown = 1; INSERT_PADDING_BYTES(2); + EAPoLNodeInfo node; +}; - u64_be friend_code_seed; - std::array username; - INSERT_PADDING_BYTES(4); - u16_be network_node_id; +static_assert(sizeof(EAPoLStartPacket) == 0x30, "EAPoLStartPacket has the wrong size"); + +constexpr u16 EAPoLLogoffMagic = 0x202; + +struct EAPoLLogoffPacket { + u16_be magic = EAPoLLogoffMagic; + INSERT_PADDING_BYTES(2); + u16_be assigned_node_id; + MacAddress client_mac_address; INSERT_PADDING_BYTES(6); + u8 connected_nodes; + u8 max_nodes; + INSERT_PADDING_BYTES(4); + + std::array nodes; }; -static_assert(sizeof(EAPoLStartPacket) == 0x30, "EAPoLStartPacket has the wrong size"); +static_assert(sizeof(EAPoLLogoffPacket) == 0x298, "EAPoLLogoffPacket has the wrong size"); /** * Generates an unencrypted 802.11 data payload. @@ -102,5 +125,40 @@ std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 */ std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node_info); +/* + * Returns the EtherType of the specified 802.11 frame. + */ +EtherType GetFrameEtherType(const std::vector& frame); + +/* + * Returns the EAPoL type (Start / Logoff) of the specified 802.11 frame. + * Note: The frame *must* be an EAPoL frame. + */ +u16 GetEAPoLFrameType(const std::vector& frame); + +/* + * Returns a deserialized NodeInfo structure from the information inside an EAPoL-Start packet + * encapsulated in an 802.11 data frame. + */ +NodeInfo DeserializeNodeInfoFromFrame(const std::vector& frame); + +/* + * Returns a NodeInfo constructed from the data in the specified EAPoLNodeInfo. + */ +NodeInfo DeserializeNodeInfo(const EAPoLNodeInfo& node); + +/* + * Generates an unencrypted 802.11 data frame body with the EAPoL-Logoff format for UDS + * communication. + * @returns The generated frame body. + */ +std::vector GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 network_node_id, + const NodeList& nodes, u8 max_nodes, u8 total_nodes); + +/* + * Returns a EAPoLLogoffPacket representing the specified 802.11-encapsulated data frame. + */ +EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector& frame); + } // namespace NWM } // namespace Service -- cgit v1.2.3 From 5bae5a48b90cc9f6c847040e6f486296ed135017 Mon Sep 17 00:00:00 2001 From: Subv Date: Sat, 30 Sep 2017 13:19:58 -0500 Subject: Services/NIM: Implement CheckForSysUpdateEvent. Implementation verified by reverse engineering. This lets the Home Menu boot without crashing on startup. --- src/core/hle/service/nim/nim.cpp | 18 +++++++++++++++++- src/core/hle/service/nim/nim.h | 11 +++++++++++ src/core/hle/service/nim/nim_u.cpp | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp index d5624fe54..b10d5852b 100644 --- a/src/core/hle/service/nim/nim.cpp +++ b/src/core/hle/service/nim/nim.cpp @@ -5,6 +5,8 @@ #include "common/common_types.h" #include "common/logging/log.h" #include "core/hle/ipc.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/kernel/event.h" #include "core/hle/service/nim/nim.h" #include "core/hle/service/nim/nim_aoc.h" #include "core/hle/service/nim/nim_s.h" @@ -14,6 +16,16 @@ namespace Service { namespace NIM { +static Kernel::SharedPtr nim_system_update_event; + +void CheckForSysUpdateEvent(Service::Interface* self) { + IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x5, 0, 0); // 0x50000 + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + rb.Push(RESULT_SUCCESS); + rb.PushCopyHandles(Kernel::g_handle_table.Create(nim_system_update_event).Unwrap()); + LOG_TRACE(Service_NIM, "called"); +} + void CheckSysUpdateAvailable(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -29,9 +41,13 @@ void Init() { AddService(new NIM_AOC_Interface); AddService(new NIM_S_Interface); AddService(new NIM_U_Interface); + + nim_system_update_event = Kernel::Event::Create(ResetType::OneShot, "NIM System Update Event"); } -void Shutdown() {} +void Shutdown() { + nim_system_update_event = nullptr; +} } // namespace NIM diff --git a/src/core/hle/service/nim/nim.h b/src/core/hle/service/nim/nim.h index c3106f18b..dbf605e5a 100644 --- a/src/core/hle/service/nim/nim.h +++ b/src/core/hle/service/nim/nim.h @@ -10,6 +10,17 @@ class Interface; namespace NIM { +/** + * NIM::CheckForSysUpdateEvent service function + * Inputs: + * 1 : None + * Outputs: + * 1 : Result of function, 0 on success, otherwise error code + * 2 : Copy handle descriptor + * 3 : System Update event handle + */ +void CheckForSysUpdateEvent(Service::Interface* self); + /** * NIM::CheckSysUpdateAvailable service function * Inputs: diff --git a/src/core/hle/service/nim/nim_u.cpp b/src/core/hle/service/nim/nim_u.cpp index 7664bad60..569660278 100644 --- a/src/core/hle/service/nim/nim_u.cpp +++ b/src/core/hle/service/nim/nim_u.cpp @@ -12,7 +12,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x00010000, nullptr, "StartSysUpdate"}, {0x00020000, nullptr, "GetUpdateDownloadProgress"}, {0x00040000, nullptr, "FinishTitlesInstall"}, - {0x00050000, nullptr, "CheckForSysUpdateEvent"}, + {0x00050000, CheckForSysUpdateEvent, "CheckForSysUpdateEvent"}, {0x00090000, CheckSysUpdateAvailable, "CheckSysUpdateAvailable"}, {0x000A0000, nullptr, "GetState"}, {0x000B0000, nullptr, "GetSystemTitleHash"}, -- cgit v1.2.3 From 83e5f639e626bcbd41fe86566a6d15d2d473536d Mon Sep 17 00:00:00 2001 From: Dragios Date: Mon, 9 Oct 2017 09:10:48 +0800 Subject: Change command header in nwm::UDS Initialize function --- src/core/hle/service/nwm/nwm_uds.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 0aa63cc1e..87a6b0eca 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -975,7 +975,7 @@ void OnClientConnected(u16 network_node_id) { } const Interface::FunctionInfo FunctionTable[] = { - {0x00010442, nullptr, "Initialize (deprecated)"}, + {0x000102C2, nullptr, "Initialize (deprecated)"}, {0x00020000, nullptr, "Scrap"}, {0x00030000, Shutdown, "Shutdown"}, {0x00040402, nullptr, "CreateNetwork (deprecated)"}, -- cgit v1.2.3