From ffe94421b2719ad20f032396350370ab5a7f9fd6 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Fri, 16 Feb 2018 18:38:28 -0700 Subject: [PATCH 1/5] UDS: Add non zero mac address to the shared page Apparently several games check the shared page mac address and wifi link level values, and will refuse to start UDS if they are not correct. This change gives a default value (in case you aren't connected to a network) and will read the value from Room if you are connected. --- src/core/hle/service/nwm/nwm_uds.cpp | 7 +++++++ src/core/hle/shared_page.cpp | 11 +++++++++++ src/core/hle/shared_page.h | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 43dbe59020..19bcf87e24 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -23,6 +23,7 @@ #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/hle/shared_page.h" #include "core/memory.h" #include "network/network.h" @@ -592,6 +593,12 @@ void NWM_UDS::InitializeWithVersion(Kernel::HLERequestContext& ctx) { node_info.push_back(current_node); } + if (auto room_member = Network::GetRoomMember().lock()) { + if (room_member->IsConnected()) { + SharedPage::SetMacAddress(static_cast(room_member->GetMacAddress())); + } + } + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); rb.Push(RESULT_SUCCESS); rb.PushCopyObjects(connection_status_event); diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp index eb9a874386..47e6369ef5 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/shared_page.cpp @@ -83,6 +83,17 @@ void Init() { update_time_event = CoreTiming::RegisterEvent("SharedPage::UpdateTimeCallback", UpdateTimeCallback); CoreTiming::ScheduleEvent(0, update_time_event); + + SetWifiLinkLevel(WifiLinkLevel::POOR); + SetMacAddress(DefaultMac); +} + +void SetMacAddress(const MacAddress& addr) { + std::memcpy(shared_page.wifi_macaddr, addr.data(), sizeof(MacAddress)); +} + +void SetWifiLinkLevel(WifiLinkLevel level) { + shared_page.wifi_link_level = static_cast(level); } } // namespace diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h index 864695ae14..181932c4b9 100644 --- a/src/core/hle/shared_page.h +++ b/src/core/hle/shared_page.h @@ -37,6 +37,17 @@ union BatteryState { BitField<2, 3, u8> charge_level; }; +using MacAddress = std::array; + +// Default MAC address in the nintendo 3ds range +constexpr MacAddress DefaultMac = { 0x40, 0xF4, 0x07, 0x00, 0x00, 0x00 }; + +enum class WifiLinkLevel : u8 { + POOR = 0, + GOOD = 1, + BEST = 2, +}; + struct SharedPageDef { // Most of these names are taken from the 3dbrew page linked above. u32_le date_time_counter; // 0 @@ -66,4 +77,8 @@ extern SharedPageDef shared_page; void Init(); +void SetMacAddress(const MacAddress&); + +void SetWifiLinkLevel(WifiLinkLevel); + } // namespace From 752cfcaaaeef6993fc9a58cde2c994e80d1f3c48 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sat, 17 Feb 2018 22:14:21 -0700 Subject: [PATCH 2/5] Move writing to shared page to the nwm init --- src/core/hle/service/nwm/nwm.cpp | 18 ++++++++++++++++++ src/core/hle/service/nwm/nwm_uds.cpp | 6 ------ src/core/hle/shared_page.cpp | 5 +---- src/core/hle/shared_page.h | 13 +++++++------ 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/core/hle/service/nwm/nwm.cpp b/src/core/hle/service/nwm/nwm.cpp index ce4c98bce9..9fc0537c04 100644 --- a/src/core/hle/service/nwm/nwm.cpp +++ b/src/core/hle/service/nwm/nwm.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "core/hle/service/nwm/nwm.h" #include "core/hle/service/nwm/nwm_cec.h" #include "core/hle/service/nwm/nwm_ext.h" @@ -10,6 +11,8 @@ #include "core/hle/service/nwm/nwm_soc.h" #include "core/hle/service/nwm/nwm_tst.h" #include "core/hle/service/nwm/nwm_uds.h" +#include "core/hle/shared_page.h" +#include "network/network.h" namespace Service { namespace NWM { @@ -21,6 +24,21 @@ void Init() { AddService(new NWM_SAP); AddService(new NWM_SOC); AddService(new NWM_TST); + + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dis(0, std::numeric_limits::max()); + auto mac = SharedPage::DefaultMac; + for (int i = 3; i < sizeof(SharedPage::MacAddress); ++i) { + mac[i] = static_cast(dis(gen)); + } + if (auto room_member = Network::GetRoomMember().lock()) { + if (room_member->IsConnected()) { + mac = static_cast(room_member->GetMacAddress()); + } + } + SharedPage::SetMacAddress(mac); + SharedPage::SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST); } void InstallInterfaces(SM::ServiceManager& service_manager) { diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 19bcf87e24..d120260d42 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -593,12 +593,6 @@ void NWM_UDS::InitializeWithVersion(Kernel::HLERequestContext& ctx) { node_info.push_back(current_node); } - if (auto room_member = Network::GetRoomMember().lock()) { - if (room_member->IsConnected()) { - SharedPage::SetMacAddress(static_cast(room_member->GetMacAddress())); - } - } - IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); rb.Push(RESULT_SUCCESS); rb.PushCopyObjects(connection_status_event); diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp index 47e6369ef5..0102d0f5ec 100644 --- a/src/core/hle/shared_page.cpp +++ b/src/core/hle/shared_page.cpp @@ -83,9 +83,6 @@ void Init() { update_time_event = CoreTiming::RegisterEvent("SharedPage::UpdateTimeCallback", UpdateTimeCallback); CoreTiming::ScheduleEvent(0, update_time_event); - - SetWifiLinkLevel(WifiLinkLevel::POOR); - SetMacAddress(DefaultMac); } void SetMacAddress(const MacAddress& addr) { @@ -96,4 +93,4 @@ void SetWifiLinkLevel(WifiLinkLevel level) { shared_page.wifi_link_level = static_cast(level); } -} // namespace +} // namespace SharedPage diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h index 181932c4b9..1e2fce6b7a 100644 --- a/src/core/hle/shared_page.h +++ b/src/core/hle/shared_page.h @@ -39,13 +39,14 @@ union BatteryState { using MacAddress = std::array; -// Default MAC address in the nintendo 3ds range -constexpr MacAddress DefaultMac = { 0x40, 0xF4, 0x07, 0x00, 0x00, 0x00 }; +// Default MAC address in the Nintendo 3DS range +constexpr MacAddress DefaultMac = {0x40, 0xF4, 0x07, 0x00, 0x00, 0x00}; enum class WifiLinkLevel : u8 { - POOR = 0, - GOOD = 1, - BEST = 2, + OFF = 0, + POOR = 1, + GOOD = 2, + BEST = 3, }; struct SharedPageDef { @@ -81,4 +82,4 @@ void SetMacAddress(const MacAddress&); void SetWifiLinkLevel(WifiLinkLevel); -} // namespace +} // namespace SharedPage From 1f87766b8673756973d02c90e05bd29fde77e466 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Thu, 22 Feb 2018 22:31:58 -0700 Subject: [PATCH 3/5] Change to use CryptoPP random and address review comments --- src/core/hle/service/nwm/nwm.cpp | 12 +++++------- src/core/hle/service/nwm/nwm_uds.cpp | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/core/hle/service/nwm/nwm.cpp b/src/core/hle/service/nwm/nwm.cpp index 9fc0537c04..f3f906d3a4 100644 --- a/src/core/hle/service/nwm/nwm.cpp +++ b/src/core/hle/service/nwm/nwm.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include +#include #include "core/hle/service/nwm/nwm.h" #include "core/hle/service/nwm/nwm_cec.h" #include "core/hle/service/nwm/nwm_ext.h" @@ -25,13 +25,11 @@ void Init() { AddService(new NWM_SOC); AddService(new NWM_TST); - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(0, std::numeric_limits::max()); + CryptoPP::AutoSeededRandomPool rng; auto mac = SharedPage::DefaultMac; - for (int i = 3; i < sizeof(SharedPage::MacAddress); ++i) { - mac[i] = static_cast(dis(gen)); - } + // Keep the Nintendo 3DS MAC header and randomly generate the last 3 bytes + rng.GenerateBlock(static_cast(mac.data() + 3), 3); + if (auto room_member = Network::GetRoomMember().lock()) { if (room_member->IsConnected()) { mac = static_cast(room_member->GetMacAddress()); diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index d120260d42..ecc2ed966d 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -23,7 +23,6 @@ #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/hle/shared_page.h" #include "core/memory.h" #include "network/network.h" @@ -555,8 +554,9 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { rb.Push(RESULT_SUCCESS); rb.PushMappedBuffer(out_buffer); - LOG_DEBUG(Service_NWM, "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X," - "unk1=0x%08X, unk2=0x%08X, offset=%zu", + LOG_DEBUG(Service_NWM, + "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X," + "unk1=0x%08X, unk2=0x%08X, offset=%zu", out_buffer_size, wlan_comm_id, id, unk1, unk2, cur_buffer_size); } From 878217372b5af21655ba59e3e4ec5686be3baeea Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sun, 4 Mar 2018 20:16:36 -0700 Subject: [PATCH 4/5] Remove useless static cast --- src/core/hle/service/nwm/nwm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/nwm/nwm.cpp b/src/core/hle/service/nwm/nwm.cpp index f3f906d3a4..8d63cb89f7 100644 --- a/src/core/hle/service/nwm/nwm.cpp +++ b/src/core/hle/service/nwm/nwm.cpp @@ -32,7 +32,7 @@ void Init() { if (auto room_member = Network::GetRoomMember().lock()) { if (room_member->IsConnected()) { - mac = static_cast(room_member->GetMacAddress()); + mac = room_member->GetMacAddress(); } } SharedPage::SetMacAddress(mac); From d26cf11399969b77e3082334e40723d92c42d009 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Sun, 4 Mar 2018 20:27:22 -0700 Subject: [PATCH 5/5] Fix clang format --- src/core/hle/service/nwm/nwm_uds.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index ecc2ed966d..43dbe59020 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -554,9 +554,8 @@ void NWM_UDS::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { rb.Push(RESULT_SUCCESS); rb.PushMappedBuffer(out_buffer); - LOG_DEBUG(Service_NWM, - "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X," - "unk1=0x%08X, unk2=0x%08X, offset=%zu", + LOG_DEBUG(Service_NWM, "called out_buffer_size=0x%08X, wlan_comm_id=0x%08X, id=0x%08X," + "unk1=0x%08X, unk2=0x%08X, offset=%zu", out_buffer_size, wlan_comm_id, id, unk1, unk2, cur_buffer_size); }