Merge pull request #3444 from jroweboy/fix-multiplayer

UDS: Add non zero mac address to the shared page
This commit is contained in:
James Rowe 2018-03-04 20:40:37 -07:00 committed by GitHub
commit ce725f24ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cryptopp/osrng.h>
#include "core/hle/service/nwm/nwm.h" #include "core/hle/service/nwm/nwm.h"
#include "core/hle/service/nwm/nwm_cec.h" #include "core/hle/service/nwm/nwm_cec.h"
#include "core/hle/service/nwm/nwm_ext.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_soc.h"
#include "core/hle/service/nwm/nwm_tst.h" #include "core/hle/service/nwm/nwm_tst.h"
#include "core/hle/service/nwm/nwm_uds.h" #include "core/hle/service/nwm/nwm_uds.h"
#include "core/hle/shared_page.h"
#include "network/network.h"
namespace Service { namespace Service {
namespace NWM { namespace NWM {
@ -21,6 +24,19 @@ void Init() {
AddService(new NWM_SAP); AddService(new NWM_SAP);
AddService(new NWM_SOC); AddService(new NWM_SOC);
AddService(new NWM_TST); AddService(new NWM_TST);
CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac;
// Keep the Nintendo 3DS MAC header and randomly generate the last 3 bytes
rng.GenerateBlock(static_cast<CryptoPP::byte*>(mac.data() + 3), 3);
if (auto room_member = Network::GetRoomMember().lock()) {
if (room_member->IsConnected()) {
mac = room_member->GetMacAddress();
}
}
SharedPage::SetMacAddress(mac);
SharedPage::SetWifiLinkLevel(SharedPage::WifiLinkLevel::BEST);
} }
void InstallInterfaces(SM::ServiceManager& service_manager) { void InstallInterfaces(SM::ServiceManager& service_manager) {

View File

@ -85,4 +85,12 @@ void Init() {
CoreTiming::ScheduleEvent(0, update_time_event); CoreTiming::ScheduleEvent(0, update_time_event);
} }
} // namespace 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<u8>(level);
}
} // namespace SharedPage

View File

@ -37,6 +37,18 @@ union BatteryState {
BitField<2, 3, u8> charge_level; BitField<2, 3, u8> charge_level;
}; };
using MacAddress = std::array<u8, 6>;
// Default MAC address in the Nintendo 3DS range
constexpr MacAddress DefaultMac = {0x40, 0xF4, 0x07, 0x00, 0x00, 0x00};
enum class WifiLinkLevel : u8 {
OFF = 0,
POOR = 1,
GOOD = 2,
BEST = 3,
};
struct SharedPageDef { struct SharedPageDef {
// Most of these names are taken from the 3dbrew page linked above. // Most of these names are taken from the 3dbrew page linked above.
u32_le date_time_counter; // 0 u32_le date_time_counter; // 0
@ -66,4 +78,8 @@ extern SharedPageDef shared_page;
void Init(); void Init();
} // namespace void SetMacAddress(const MacAddress&);
void SetWifiLinkLevel(WifiLinkLevel);
} // namespace SharedPage