Merge pull request #4425 from lioncash/ipc
IPC_HLE: Move NWC24Config and WiiNetConfig to their own source files
This commit is contained in:
commit
c77d4a765d
|
@ -135,6 +135,7 @@ set(SRCS ActionReplay.cpp
|
|||
HW/WiimoteReal/WiimoteReal.cpp
|
||||
HW/WiiSaveCrypted.cpp
|
||||
IPC_HLE/ICMPLin.cpp
|
||||
IPC_HLE/NWC24Config.cpp
|
||||
IPC_HLE/WII_IPC_HLE.cpp
|
||||
IPC_HLE/WII_IPC_HLE_Device_DI.cpp
|
||||
IPC_HLE/WII_IPC_HLE_Device_es.cpp
|
||||
|
@ -152,6 +153,7 @@ set(SRCS ActionReplay.cpp
|
|||
IPC_HLE/WII_IPC_HLE_Device_usb_ven.cpp
|
||||
IPC_HLE/WII_IPC_HLE_WiiMote.cpp
|
||||
IPC_HLE/WiiMote_HID_Attr.cpp
|
||||
IPC_HLE/WiiNetConfig.cpp
|
||||
PowerPC/MMU.cpp
|
||||
PowerPC/PowerPC.cpp
|
||||
PowerPC/PPCAnalyst.cpp
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
|
@ -22,6 +24,7 @@
|
|||
#include "Common/Logging/LogManager.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Common/Timer.h"
|
||||
|
@ -29,7 +32,6 @@
|
|||
#include "Core/Analytics.h"
|
||||
#include "Core/BootManager.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/DSPEmulator.h"
|
||||
#include "Core/Host.h"
|
||||
|
|
|
@ -168,6 +168,7 @@
|
|||
<ClCompile Include="HW\WII_IPC.cpp" />
|
||||
<ClCompile Include="HW\WiiSaveCrypted.cpp" />
|
||||
<ClCompile Include="IPC_HLE\ICMPWin.cpp" />
|
||||
<ClCompile Include="IPC_HLE\NWC24Config.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WiiMote_HID_Attr.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_DI.cpp" />
|
||||
|
@ -195,6 +196,7 @@
|
|||
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_usb_ven.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE_WiiMote.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WII_Socket.cpp" />
|
||||
<ClCompile Include="IPC_HLE\WiiNetConfig.cpp" />
|
||||
<ClCompile Include="MemTools.cpp" />
|
||||
<ClCompile Include="Movie.cpp" />
|
||||
<ClCompile Include="NetPlayClient.cpp" />
|
||||
|
@ -382,6 +384,7 @@
|
|||
<ClInclude Include="IPC_HLE\hci.h" />
|
||||
<ClInclude Include="IPC_HLE\ICMP.h" />
|
||||
<ClInclude Include="IPC_HLE\l2cap.h" />
|
||||
<ClInclude Include="IPC_HLE\NWC24Config.h" />
|
||||
<ClInclude Include="IPC_HLE\WiiMote_HID_Attr.h" />
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE.h" />
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device.h" />
|
||||
|
@ -402,6 +405,7 @@
|
|||
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_usb_ven.h" />
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE_WiiMote.h" />
|
||||
<ClInclude Include="IPC_HLE\WII_Socket.h" />
|
||||
<ClInclude Include="IPC_HLE\WiiNetConfig.h" />
|
||||
<ClInclude Include="MachineContext.h" />
|
||||
<ClInclude Include="MemTools.h" />
|
||||
<ClInclude Include="Movie.h" />
|
||||
|
|
|
@ -573,6 +573,9 @@
|
|||
<ClCompile Include="IPC_HLE\ICMPWin.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\NWC24Config.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_net.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClCompile>
|
||||
|
@ -582,6 +585,9 @@
|
|||
<ClCompile Include="IPC_HLE\WII_Socket.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\WiiNetConfig.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IPC_HLE\WII_IPC_HLE_Device_sdio_slot0.cpp">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\SDIO - SD Card</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1142,6 +1148,9 @@
|
|||
<ClInclude Include="IPC_HLE\ICMP.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\NWC24Config.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_net.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1151,6 +1160,9 @@
|
|||
<ClInclude Include="IPC_HLE\WII_Socket.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\WiiNetConfig.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="IPC_HLE\WII_IPC_HLE_Device_sdio_slot0.h">
|
||||
<Filter>IPC HLE %28IOS/Starlet%29\SDIO - SD Card</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/IPC_HLE/NWC24Config.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
|
||||
namespace NWC24
|
||||
{
|
||||
NWC24Config::NWC24Config()
|
||||
{
|
||||
m_path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_WC24CONF_DIR "/nwc24msg.cfg";
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
void NWC24Config::ReadConfig()
|
||||
{
|
||||
if (File::Exists(m_path))
|
||||
{
|
||||
if (!File::IOFile(m_path, "rb").ReadBytes(&m_data, sizeof(m_data)))
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
const s32 config_error = CheckNwc24Config();
|
||||
if (config_error)
|
||||
ERROR_LOG(WII_IPC_WC24, "There is an error in the config for for WC24: %d", config_error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void NWC24Config::WriteConfig() const
|
||||
{
|
||||
if (!File::Exists(m_path))
|
||||
{
|
||||
if (!File::CreateFullPath(File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_WC24CONF_DIR))
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Failed to create directory for WC24");
|
||||
}
|
||||
}
|
||||
|
||||
File::IOFile(m_path, "wb").WriteBytes(&m_data, sizeof(m_data));
|
||||
}
|
||||
|
||||
void NWC24Config::ResetConfig()
|
||||
{
|
||||
if (File::Exists(m_path))
|
||||
File::Delete(m_path);
|
||||
|
||||
constexpr const char* urls[5] = {
|
||||
"https://amw.wc24.wii.com/cgi-bin/account.cgi", "http://rcw.wc24.wii.com/cgi-bin/check.cgi",
|
||||
"http://mtw.wc24.wii.com/cgi-bin/receive.cgi", "http://mtw.wc24.wii.com/cgi-bin/delete.cgi",
|
||||
"http://mtw.wc24.wii.com/cgi-bin/send.cgi",
|
||||
};
|
||||
|
||||
memset(&m_data, 0, sizeof(m_data));
|
||||
|
||||
SetMagic(0x57634366);
|
||||
SetUnk(8);
|
||||
SetCreationStage(NWC24_IDCS_INITIAL);
|
||||
SetEnableBooting(0);
|
||||
SetEmail("@wii.com");
|
||||
|
||||
for (int i = 0; i < URL_COUNT; ++i)
|
||||
{
|
||||
strncpy(m_data.http_urls[i], urls[i], MAX_URL_LENGTH);
|
||||
}
|
||||
|
||||
SetChecksum(CalculateNwc24ConfigChecksum());
|
||||
|
||||
WriteConfig();
|
||||
}
|
||||
|
||||
u32 NWC24Config::CalculateNwc24ConfigChecksum() const
|
||||
{
|
||||
const u32* ptr = reinterpret_cast<const u32*>(&m_data);
|
||||
u32 sum = 0;
|
||||
|
||||
for (int i = 0; i < 0xFF; ++i)
|
||||
{
|
||||
sum += Common::swap32(*ptr++);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
s32 NWC24Config::CheckNwc24Config() const
|
||||
{
|
||||
// 'WcCf' magic
|
||||
if (Magic() != 0x57634366)
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Magic mismatch");
|
||||
return -14;
|
||||
}
|
||||
|
||||
const u32 checksum = CalculateNwc24ConfigChecksum();
|
||||
DEBUG_LOG(WII_IPC_WC24, "Checksum: %X", checksum);
|
||||
if (Checksum() != checksum)
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Checksum mismatch expected %X and got %X", checksum, Checksum());
|
||||
return -14;
|
||||
}
|
||||
|
||||
if (IdGen() > 0x1F)
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Id gen error");
|
||||
return -14;
|
||||
}
|
||||
|
||||
if (Unk() != 8)
|
||||
return -27;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 NWC24Config::Magic() const
|
||||
{
|
||||
return Common::swap32(m_data.magic);
|
||||
}
|
||||
|
||||
void NWC24Config::SetMagic(u32 magic)
|
||||
{
|
||||
m_data.magic = Common::swap32(magic);
|
||||
}
|
||||
|
||||
u32 NWC24Config::Unk() const
|
||||
{
|
||||
return Common::swap32(m_data.unk_04);
|
||||
}
|
||||
|
||||
void NWC24Config::SetUnk(u32 unk_04)
|
||||
{
|
||||
m_data.unk_04 = Common::swap32(unk_04);
|
||||
}
|
||||
|
||||
u32 NWC24Config::IdGen() const
|
||||
{
|
||||
return Common::swap32(m_data.id_generation);
|
||||
}
|
||||
|
||||
void NWC24Config::SetIdGen(u32 id_generation)
|
||||
{
|
||||
m_data.id_generation = Common::swap32(id_generation);
|
||||
}
|
||||
|
||||
void NWC24Config::IncrementIdGen()
|
||||
{
|
||||
u32 id_ctr = IdGen();
|
||||
id_ctr++;
|
||||
id_ctr &= 0x1F;
|
||||
|
||||
SetIdGen(id_ctr);
|
||||
}
|
||||
|
||||
u32 NWC24Config::Checksum() const
|
||||
{
|
||||
return Common::swap32(m_data.checksum);
|
||||
}
|
||||
|
||||
void NWC24Config::SetChecksum(u32 checksum)
|
||||
{
|
||||
m_data.checksum = Common::swap32(checksum);
|
||||
}
|
||||
|
||||
u32 NWC24Config::CreationStage() const
|
||||
{
|
||||
return Common::swap32(m_data.creation_stage);
|
||||
}
|
||||
|
||||
void NWC24Config::SetCreationStage(u32 creation_stage)
|
||||
{
|
||||
m_data.creation_stage = Common::swap32(creation_stage);
|
||||
}
|
||||
|
||||
u32 NWC24Config::EnableBooting() const
|
||||
{
|
||||
return Common::swap32(m_data.enable_booting);
|
||||
}
|
||||
|
||||
void NWC24Config::SetEnableBooting(u32 enable_booting)
|
||||
{
|
||||
m_data.enable_booting = Common::swap32(enable_booting);
|
||||
}
|
||||
|
||||
u64 NWC24Config::Id() const
|
||||
{
|
||||
return Common::swap64(m_data.nwc24_id);
|
||||
}
|
||||
|
||||
void NWC24Config::SetId(u64 nwc24_id)
|
||||
{
|
||||
m_data.nwc24_id = Common::swap64(nwc24_id);
|
||||
}
|
||||
|
||||
const char* NWC24Config::Email() const
|
||||
{
|
||||
return m_data.email;
|
||||
}
|
||||
|
||||
void NWC24Config::SetEmail(const char* email)
|
||||
{
|
||||
strncpy(m_data.email, email, MAX_EMAIL_LENGTH);
|
||||
m_data.email[MAX_EMAIL_LENGTH - 1] = '\0';
|
||||
}
|
||||
} // namespace NWC24
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace NWC24
|
||||
{
|
||||
enum ErrorCode : int
|
||||
{
|
||||
WC24_OK = 0,
|
||||
WC24_ERR_FATAL = -1,
|
||||
WC24_ERR_ID_NONEXISTANCE = -34,
|
||||
WC24_ERR_ID_GENERATED = -35,
|
||||
WC24_ERR_ID_REGISTERED = -36,
|
||||
WC24_ERR_ID_NOT_REGISTERED = -44,
|
||||
};
|
||||
|
||||
class NWC24Config final
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
NWC24_IDCS_INITIAL = 0,
|
||||
NWC24_IDCS_GENERATED = 1,
|
||||
NWC24_IDCS_REGISTERED = 2
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
URL_COUNT = 0x05,
|
||||
MAX_URL_LENGTH = 0x80,
|
||||
MAX_EMAIL_LENGTH = 0x40,
|
||||
MAX_PASSWORD_LENGTH = 0x20,
|
||||
};
|
||||
|
||||
NWC24Config();
|
||||
|
||||
void ReadConfig();
|
||||
void WriteConfig() const;
|
||||
void ResetConfig();
|
||||
|
||||
u32 CalculateNwc24ConfigChecksum() const;
|
||||
s32 CheckNwc24Config() const;
|
||||
|
||||
u32 Magic() const;
|
||||
void SetMagic(u32 magic);
|
||||
|
||||
u32 Unk() const;
|
||||
void SetUnk(u32 unk_04);
|
||||
|
||||
u32 IdGen() const;
|
||||
void SetIdGen(u32 id_generation);
|
||||
void IncrementIdGen();
|
||||
|
||||
u32 Checksum() const;
|
||||
void SetChecksum(u32 checksum);
|
||||
|
||||
u32 CreationStage() const;
|
||||
void SetCreationStage(u32 creation_stage);
|
||||
|
||||
u32 EnableBooting() const;
|
||||
void SetEnableBooting(u32 enable_booting);
|
||||
|
||||
u64 Id() const;
|
||||
void SetId(u64 nwc24_id);
|
||||
|
||||
const char* Email() const;
|
||||
void SetEmail(const char* email);
|
||||
|
||||
private:
|
||||
#pragma pack(push, 1)
|
||||
struct ConfigData final
|
||||
{
|
||||
u32 magic; // 'WcCf' 0x57634366
|
||||
u32 unk_04; // must be 8
|
||||
u64 nwc24_id;
|
||||
u32 id_generation;
|
||||
u32 creation_stage; // 0:not_generated; 1:generated; 2:registered
|
||||
char email[MAX_EMAIL_LENGTH];
|
||||
char paswd[MAX_PASSWORD_LENGTH];
|
||||
char mlchkid[0x24];
|
||||
char http_urls[URL_COUNT][MAX_URL_LENGTH];
|
||||
u8 reserved[0xDC];
|
||||
u32 enable_booting;
|
||||
u32 checksum;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::string m_path;
|
||||
ConfigData m_data;
|
||||
};
|
||||
} // namespace NWC24
|
|
@ -145,7 +145,7 @@ IPCCommandResult CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress)
|
|||
|
||||
case IOCTL_NWC24_REQUEST_GENERATED_USER_ID: // (Input: none, Output: 32 bytes)
|
||||
INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID");
|
||||
if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_INITIAL)
|
||||
if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_INITIAL)
|
||||
{
|
||||
std::string settings_Filename(
|
||||
Common::GetTitleDataPath(TITLEID_SYSMENU, Common::FROM_SESSION_ROOT) + WII_SETTING);
|
||||
|
@ -177,23 +177,23 @@ IPCCommandResult CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress)
|
|||
s32 ret = NWC24MakeUserID(&UserID, HollywoodID, id_ctr, hardware_model, area_code);
|
||||
config.SetId(UserID);
|
||||
config.IncrementIdGen();
|
||||
config.SetCreationStage(nwc24_config_t::NWC24_IDCS_GENERATED);
|
||||
config.SetCreationStage(NWC24::NWC24Config::NWC24_IDCS_GENERATED);
|
||||
config.WriteConfig();
|
||||
|
||||
Memory::Write_U32(ret, BufferOut);
|
||||
}
|
||||
else
|
||||
{
|
||||
Memory::Write_U32(WC24_ERR_FATAL, BufferOut);
|
||||
Memory::Write_U32(NWC24::WC24_ERR_FATAL, BufferOut);
|
||||
}
|
||||
}
|
||||
else if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_GENERATED)
|
||||
else if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_GENERATED)
|
||||
{
|
||||
Memory::Write_U32(WC24_ERR_ID_GENERATED, BufferOut);
|
||||
Memory::Write_U32(NWC24::WC24_ERR_ID_GENERATED, BufferOut);
|
||||
}
|
||||
else if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_REGISTERED)
|
||||
else if (config.CreationStage() == NWC24::NWC24Config::NWC24_IDCS_REGISTERED)
|
||||
{
|
||||
Memory::Write_U32(WC24_ERR_ID_REGISTERED, BufferOut);
|
||||
Memory::Write_U32(NWC24::WC24_ERR_ID_REGISTERED, BufferOut);
|
||||
}
|
||||
Memory::Write_U64(config.Id(), BufferOut + 4);
|
||||
Memory::Write_U32(config.CreationStage(), BufferOut + 0xC);
|
||||
|
@ -310,9 +310,9 @@ s32 CWII_IPC_HLE_Device_net_kd_request::NWC24MakeUserID(u64* nwc24_id, u32 holly
|
|||
*nwc24_id = mix_id;
|
||||
|
||||
if (mix_id > 9999999999999999ULL)
|
||||
return WC24_ERR_FATAL;
|
||||
return NWC24::WC24_ERR_FATAL;
|
||||
|
||||
return WC24_OK;
|
||||
return NWC24::WC24_OK;
|
||||
}
|
||||
|
||||
static void SaveMacAddress(u8* mac)
|
||||
|
@ -417,7 +417,7 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress)
|
|||
case IOCTLV_NCD_GETLINKSTATUS:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETLINKSTATUS");
|
||||
// Always connected
|
||||
Memory::Write_U32(netcfg_connection_t::LINK_WIRED,
|
||||
Memory::Write_U32(Net::ConnectionSettings::LINK_WIRED,
|
||||
CommandBuffer.PayloadBuffer.at(0).m_Address + 4);
|
||||
break;
|
||||
|
||||
|
|
|
@ -4,374 +4,20 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/Timer.h"
|
||||
|
||||
#include "Core/HW/EXI_DeviceIPL.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/IPC_HLE/NWC24Config.h"
|
||||
#include "Core/IPC_HLE/WII_IPC_HLE_Device.h"
|
||||
#include "Core/IPC_HLE/WiiNetConfig.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
// data layout of the network configuration file (/shared2/sys/net/02/config.dat)
|
||||
// needed for /dev/net/ncd/manage
|
||||
#pragma pack(push, 1)
|
||||
struct netcfg_proxy_t
|
||||
{
|
||||
u8 use_proxy;
|
||||
u8 use_proxy_userandpass;
|
||||
u8 padding_1[2];
|
||||
u8 proxy_name[255];
|
||||
u8 padding_2;
|
||||
u16 proxy_port; // 0-34463
|
||||
u8 proxy_username[32];
|
||||
u8 padding_3;
|
||||
u8 proxy_password[32];
|
||||
};
|
||||
|
||||
struct netcfg_connection_t
|
||||
{
|
||||
enum
|
||||
{
|
||||
WIRED_IF = 1, // 0: wifi 1: wired
|
||||
DNS_DHCP = 2, // 0: manual 1: DHCP
|
||||
IP_DHCP = 4, // 0: manual 1: DHCP
|
||||
USE_PROXY = 16,
|
||||
CONNECTION_TEST_OK = 32,
|
||||
CONNECTION_SELECTED = 128
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
OPEN = 0,
|
||||
WEP64 = 1,
|
||||
WEP128 = 2,
|
||||
WPA_TKIP = 4,
|
||||
WPA2_AES = 5,
|
||||
WPA_AES = 6
|
||||
};
|
||||
|
||||
enum status
|
||||
{
|
||||
LINK_BUSY = 1,
|
||||
LINK_NONE = 2,
|
||||
LINK_WIRED = 3,
|
||||
LINK_WIFI_DOWN = 4,
|
||||
LINK_WIFI_UP = 5
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PERM_NONE = 0,
|
||||
PERM_SEND_MAIL = 1,
|
||||
PERM_RECV_MAIL = 2,
|
||||
PERM_DOWNLOAD = 4,
|
||||
PERM_ALL = PERM_SEND_MAIL | PERM_RECV_MAIL | PERM_DOWNLOAD
|
||||
};
|
||||
|
||||
// settings common to both wired and wireless connections
|
||||
u8 flags;
|
||||
u8 padding_1[3];
|
||||
u8 ip[4];
|
||||
u8 netmask[4];
|
||||
u8 gateway[4];
|
||||
u8 dns1[4];
|
||||
u8 dns2[4];
|
||||
u8 padding_2[2];
|
||||
u16 mtu;
|
||||
u8 padding_3[8];
|
||||
netcfg_proxy_t proxy_settings;
|
||||
u8 padding_4;
|
||||
netcfg_proxy_t proxy_settings_copy;
|
||||
u8 padding_5[1297];
|
||||
|
||||
// wireless specific settings
|
||||
u8 ssid[32];
|
||||
u8 padding_6;
|
||||
u8 ssid_length; // length of ssid in bytes.
|
||||
u8 padding_7[3];
|
||||
u8 encryption;
|
||||
u8 padding_8[3];
|
||||
u8 key_length; // length of key in bytes. 0x00 for WEP64 and WEP128.
|
||||
u8 unknown; // 0x00 or 0x01 toggled with a WPA-PSK (TKIP) and with a WEP entered with hex instead
|
||||
// of ascii.
|
||||
u8 padding_9;
|
||||
u8 key[64]; // encryption key; for WEP, key is stored 4 times (20 bytes for WEP64 and 52 bytes
|
||||
// for WEP128) then padded with 0x00
|
||||
u8 padding_10[236];
|
||||
};
|
||||
|
||||
struct network_config_t
|
||||
{
|
||||
enum
|
||||
{
|
||||
IF_NONE,
|
||||
IF_WIFI,
|
||||
IF_WIRED
|
||||
};
|
||||
|
||||
u32 version;
|
||||
u8 connType;
|
||||
u8 linkTimeout;
|
||||
u8 nwc24Permission;
|
||||
u8 padding;
|
||||
|
||||
netcfg_connection_t connection[3];
|
||||
};
|
||||
|
||||
enum nwc24_err_t
|
||||
{
|
||||
WC24_OK = 0,
|
||||
WC24_ERR_FATAL = -1,
|
||||
WC24_ERR_ID_NONEXISTANCE = -34,
|
||||
WC24_ERR_ID_GENERATED = -35,
|
||||
WC24_ERR_ID_REGISTERED = -36,
|
||||
WC24_ERR_ID_NOT_REGISTERED = -44,
|
||||
};
|
||||
|
||||
struct nwc24_config_t
|
||||
{
|
||||
enum
|
||||
{
|
||||
NWC24_IDCS_INITIAL = 0,
|
||||
NWC24_IDCS_GENERATED = 1,
|
||||
NWC24_IDCS_REGISTERED = 2
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
URL_COUNT = 0x05,
|
||||
MAX_URL_LENGTH = 0x80,
|
||||
MAX_EMAIL_LENGTH = 0x40,
|
||||
MAX_PASSWORD_LENGTH = 0x20,
|
||||
};
|
||||
|
||||
u32 magic; /* 'WcCf' 0x57634366 */
|
||||
u32 _unk_04; /* must be 8 */
|
||||
u64 nwc24_id;
|
||||
u32 id_generation;
|
||||
u32 creation_stage; /* 0==not_generated;1==generated;2==registered; */
|
||||
char email[MAX_EMAIL_LENGTH];
|
||||
char paswd[MAX_PASSWORD_LENGTH];
|
||||
char mlchkid[0x24];
|
||||
char http_urls[URL_COUNT][MAX_URL_LENGTH];
|
||||
u8 reserved[0xDC];
|
||||
u32 enable_booting;
|
||||
u32 checksum;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class NWC24Config
|
||||
{
|
||||
private:
|
||||
std::string path;
|
||||
nwc24_config_t config;
|
||||
|
||||
public:
|
||||
NWC24Config()
|
||||
{
|
||||
path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_WC24CONF_DIR "/nwc24msg.cfg";
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
void ResetConfig()
|
||||
{
|
||||
if (File::Exists(path))
|
||||
File::Delete(path);
|
||||
|
||||
const char* urls[5] = {
|
||||
"https://amw.wc24.wii.com/cgi-bin/account.cgi",
|
||||
"http://rcw.wc24.wii.com/cgi-bin/check.cgi",
|
||||
"http://mtw.wc24.wii.com/cgi-bin/receive.cgi",
|
||||
"http://mtw.wc24.wii.com/cgi-bin/delete.cgi",
|
||||
"http://mtw.wc24.wii.com/cgi-bin/send.cgi",
|
||||
};
|
||||
|
||||
memset(&config, 0, sizeof(config));
|
||||
|
||||
SetMagic(0x57634366);
|
||||
SetUnk(8);
|
||||
SetCreationStage(nwc24_config_t::NWC24_IDCS_INITIAL);
|
||||
SetEnableBooting(0);
|
||||
SetEmail("@wii.com");
|
||||
|
||||
for (int i = 0; i < nwc24_config_t::URL_COUNT; ++i)
|
||||
{
|
||||
strncpy(config.http_urls[i], urls[i], nwc24_config_t::MAX_URL_LENGTH);
|
||||
}
|
||||
|
||||
SetChecksum(CalculateNwc24ConfigChecksum());
|
||||
|
||||
WriteConfig();
|
||||
}
|
||||
|
||||
void WriteConfig()
|
||||
{
|
||||
if (!File::Exists(path))
|
||||
{
|
||||
if (!File::CreateFullPath(File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_WC24CONF_DIR))
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Failed to create directory for WC24");
|
||||
}
|
||||
}
|
||||
|
||||
File::IOFile(path, "wb").WriteBytes((void*)&config, sizeof(config));
|
||||
}
|
||||
|
||||
void ReadConfig()
|
||||
{
|
||||
if (File::Exists(path))
|
||||
{
|
||||
if (!File::IOFile(path, "rb").ReadBytes((void*)&config, sizeof(config)))
|
||||
ResetConfig();
|
||||
else
|
||||
{
|
||||
s32 config_error = CheckNwc24Config();
|
||||
if (config_error)
|
||||
ERROR_LOG(WII_IPC_WC24, "There is an error in the config for for WC24: %d", config_error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
u32 CalculateNwc24ConfigChecksum()
|
||||
{
|
||||
u32* ptr = (u32*)&config;
|
||||
u32 sum = 0;
|
||||
for (int i = 0; i < 0xFF; ++i)
|
||||
{
|
||||
sum += Common::swap32(*ptr++);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
s32 CheckNwc24Config()
|
||||
{
|
||||
if (Magic() != 0x57634366) /* 'WcCf' magic */
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Magic mismatch");
|
||||
return -14;
|
||||
}
|
||||
u32 checksum = CalculateNwc24ConfigChecksum();
|
||||
DEBUG_LOG(WII_IPC_WC24, "Checksum: %X", checksum);
|
||||
if (Checksum() != checksum)
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Checksum mismatch expected %X and got %X", checksum, Checksum());
|
||||
return -14;
|
||||
}
|
||||
if (IdGen() > 0x1F)
|
||||
{
|
||||
ERROR_LOG(WII_IPC_WC24, "Id gen error");
|
||||
return -14;
|
||||
}
|
||||
if (Unk() != 8)
|
||||
return -27;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 Magic() const { return Common::swap32(config.magic); }
|
||||
void SetMagic(u32 magic) { config.magic = Common::swap32(magic); }
|
||||
u32 Unk() const { return Common::swap32(config._unk_04); }
|
||||
void SetUnk(u32 _unk_04) { config._unk_04 = Common::swap32(_unk_04); }
|
||||
u32 IdGen() const { return Common::swap32(config.id_generation); }
|
||||
void SetIdGen(u32 id_generation) { config.id_generation = Common::swap32(id_generation); }
|
||||
void IncrementIdGen()
|
||||
{
|
||||
u32 id_ctr = IdGen();
|
||||
id_ctr++;
|
||||
id_ctr &= 0x1F;
|
||||
SetIdGen(id_ctr);
|
||||
}
|
||||
|
||||
u32 Checksum() const { return Common::swap32(config.checksum); }
|
||||
void SetChecksum(u32 checksum) { config.checksum = Common::swap32(checksum); }
|
||||
u32 CreationStage() const { return Common::swap32(config.creation_stage); }
|
||||
void SetCreationStage(u32 creation_stage)
|
||||
{
|
||||
config.creation_stage = Common::swap32(creation_stage);
|
||||
}
|
||||
|
||||
u32 EnableBooting() const { return Common::swap32(config.enable_booting); }
|
||||
void SetEnableBooting(u32 enable_booting)
|
||||
{
|
||||
config.enable_booting = Common::swap32(enable_booting);
|
||||
}
|
||||
|
||||
u64 Id() const { return Common::swap64(config.nwc24_id); }
|
||||
void SetId(u64 nwc24_id) { config.nwc24_id = Common::swap64(nwc24_id); }
|
||||
const char* Email() const { return config.email; }
|
||||
void SetEmail(const char* email)
|
||||
{
|
||||
strncpy(config.email, email, nwc24_config_t::MAX_EMAIL_LENGTH);
|
||||
config.email[nwc24_config_t::MAX_EMAIL_LENGTH - 1] = '\0';
|
||||
}
|
||||
};
|
||||
|
||||
class WiiNetConfig
|
||||
{
|
||||
std::string path;
|
||||
network_config_t config;
|
||||
|
||||
public:
|
||||
WiiNetConfig()
|
||||
{
|
||||
path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR "/net/02/config.dat";
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
void ResetConfig()
|
||||
{
|
||||
if (File::Exists(path))
|
||||
File::Delete(path);
|
||||
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.connType = network_config_t::IF_WIRED;
|
||||
config.connection[0].flags = netcfg_connection_t::WIRED_IF | netcfg_connection_t::DNS_DHCP |
|
||||
netcfg_connection_t::IP_DHCP |
|
||||
netcfg_connection_t::CONNECTION_TEST_OK |
|
||||
netcfg_connection_t::CONNECTION_SELECTED;
|
||||
|
||||
WriteConfig();
|
||||
}
|
||||
|
||||
void WriteConfig()
|
||||
{
|
||||
if (!File::Exists(path))
|
||||
{
|
||||
if (!File::CreateFullPath(std::string(File::GetUserPath(D_SESSION_WIIROOT_IDX) +
|
||||
"/" WII_SYSCONF_DIR "/net/02/")))
|
||||
{
|
||||
ERROR_LOG(WII_IPC_NET, "Failed to create directory for network config file");
|
||||
}
|
||||
}
|
||||
|
||||
File::IOFile(path, "wb").WriteBytes((void*)&config, sizeof(config));
|
||||
}
|
||||
|
||||
void WriteToMem(const u32 address) { Memory::CopyToEmu(address, &config, sizeof(config)); }
|
||||
void ReadFromMem(const u32 address) { Memory::CopyFromEmu(&config, address, sizeof(config)); }
|
||||
void ReadConfig()
|
||||
{
|
||||
if (File::Exists(path))
|
||||
{
|
||||
if (!File::IOFile(path, "rb").ReadBytes((void*)&config, sizeof(config)))
|
||||
ResetConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// KD is the IOS module responsible for implementing WiiConnect24 functionality.
|
||||
// It can perform HTTPS downloads, send and receive mail via SMTP, and execute a
|
||||
|
@ -428,7 +74,7 @@ private:
|
|||
|
||||
s32 NWC24MakeUserID(u64* nwc24_id, u32 hollywood_id, u16 id_ctr, u8 hardware_model, u8 area_code);
|
||||
|
||||
NWC24Config config;
|
||||
NWC24::NWC24Config config;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -616,7 +262,7 @@ private:
|
|||
IOCTLV_NCD_GETWIRELESSMACADDRESS = 0x8, // NCDGetWirelessMacAddress
|
||||
};
|
||||
|
||||
WiiNetConfig config;
|
||||
Net::WiiNetConfig config;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/IPC_HLE/WiiNetConfig.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
namespace Net
|
||||
{
|
||||
WiiNetConfig::WiiNetConfig()
|
||||
{
|
||||
m_path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR "/net/02/config.dat";
|
||||
ReadConfig();
|
||||
}
|
||||
|
||||
void WiiNetConfig::ReadConfig()
|
||||
{
|
||||
if (File::Exists(m_path))
|
||||
{
|
||||
if (!File::IOFile(m_path, "rb").ReadBytes(&m_data, sizeof(m_data)))
|
||||
ResetConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void WiiNetConfig::WriteConfig() const
|
||||
{
|
||||
if (!File::Exists(m_path))
|
||||
{
|
||||
if (!File::CreateFullPath(File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR
|
||||
"/net/02/"))
|
||||
{
|
||||
ERROR_LOG(WII_IPC_NET, "Failed to create directory for network config file");
|
||||
}
|
||||
}
|
||||
|
||||
File::IOFile(m_path, "wb").WriteBytes(&m_data, sizeof(m_data));
|
||||
}
|
||||
|
||||
void WiiNetConfig::ResetConfig()
|
||||
{
|
||||
if (File::Exists(m_path))
|
||||
File::Delete(m_path);
|
||||
|
||||
memset(&m_data, 0, sizeof(m_data));
|
||||
m_data.connType = ConfigData::IF_WIRED;
|
||||
m_data.connection[0].flags =
|
||||
ConnectionSettings::WIRED_IF | ConnectionSettings::DNS_DHCP | ConnectionSettings::IP_DHCP |
|
||||
ConnectionSettings::CONNECTION_TEST_OK | ConnectionSettings::CONNECTION_SELECTED;
|
||||
|
||||
WriteConfig();
|
||||
}
|
||||
|
||||
void WiiNetConfig::WriteToMem(const u32 address) const
|
||||
{
|
||||
Memory::CopyToEmu(address, &m_data, sizeof(m_data));
|
||||
}
|
||||
|
||||
void WiiNetConfig::ReadFromMem(const u32 address)
|
||||
{
|
||||
Memory::CopyFromEmu(&m_data, address, sizeof(m_data));
|
||||
}
|
||||
} // namespace Net
|
|
@ -0,0 +1,137 @@
|
|||
// Copyright 2016 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace Net
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
struct ConnectionSettings final
|
||||
{
|
||||
struct ProxySettings final
|
||||
{
|
||||
u8 use_proxy;
|
||||
u8 use_proxy_userandpass;
|
||||
u8 padding_1[2];
|
||||
u8 proxy_name[255];
|
||||
u8 padding_2;
|
||||
u16 proxy_port; // 0-34463
|
||||
u8 proxy_username[32];
|
||||
u8 padding_3;
|
||||
u8 proxy_password[32];
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
WIRED_IF = 1, // 0: WiFi 1: Wired
|
||||
DNS_DHCP = 2, // 0: Manual 1: DHCP
|
||||
IP_DHCP = 4, // 0: Manual 1: DHCP
|
||||
USE_PROXY = 16,
|
||||
CONNECTION_TEST_OK = 32,
|
||||
CONNECTION_SELECTED = 128
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
OPEN = 0,
|
||||
WEP64 = 1,
|
||||
WEP128 = 2,
|
||||
WPA_TKIP = 4,
|
||||
WPA2_AES = 5,
|
||||
WPA_AES = 6
|
||||
};
|
||||
|
||||
enum Status
|
||||
{
|
||||
LINK_BUSY = 1,
|
||||
LINK_NONE = 2,
|
||||
LINK_WIRED = 3,
|
||||
LINK_WIFI_DOWN = 4,
|
||||
LINK_WIFI_UP = 5
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PERM_NONE = 0,
|
||||
PERM_SEND_MAIL = 1,
|
||||
PERM_RECV_MAIL = 2,
|
||||
PERM_DOWNLOAD = 4,
|
||||
PERM_ALL = PERM_SEND_MAIL | PERM_RECV_MAIL | PERM_DOWNLOAD
|
||||
};
|
||||
|
||||
// Settings common to both wired and wireless connections
|
||||
u8 flags;
|
||||
u8 padding_1[3];
|
||||
u8 ip[4];
|
||||
u8 netmask[4];
|
||||
u8 gateway[4];
|
||||
u8 dns1[4];
|
||||
u8 dns2[4];
|
||||
u8 padding_2[2];
|
||||
u16 mtu;
|
||||
u8 padding_3[8];
|
||||
ProxySettings proxy_settings;
|
||||
u8 padding_4;
|
||||
ProxySettings proxy_settings_copy;
|
||||
u8 padding_5[1297];
|
||||
|
||||
// Wireless specific settings
|
||||
u8 ssid[32];
|
||||
u8 padding_6;
|
||||
u8 ssid_length;
|
||||
u8 padding_7[3]; // Length of SSID in bytes.
|
||||
u8 encryption;
|
||||
u8 padding_8[3];
|
||||
u8 key_length; // Length of key in bytes. 0x00 for WEP64 and WEP128.
|
||||
u8 unknown; // 0x00 or 0x01 toggled with a WPA-PSK (TKIP) and with a WEP entered with hex
|
||||
// instead of ASCII.
|
||||
u8 padding_9;
|
||||
u8 key[64]; // Encryption key; for WEP, key is stored 4 times (20 bytes for WEP64 and 52 bytes
|
||||
// for WEP128) then padded with 0x00
|
||||
u8 padding_10[236];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class WiiNetConfig final
|
||||
{
|
||||
public:
|
||||
WiiNetConfig();
|
||||
|
||||
void ReadConfig();
|
||||
void WriteConfig() const;
|
||||
void ResetConfig();
|
||||
|
||||
void WriteToMem(u32 address) const;
|
||||
void ReadFromMem(u32 address);
|
||||
|
||||
private:
|
||||
// Data layout of the network configuration file (/shared2/sys/net/02/config.dat)
|
||||
// needed for /dev/net/ncd/manage
|
||||
#pragma pack(push, 1)
|
||||
struct ConfigData final
|
||||
{
|
||||
enum
|
||||
{
|
||||
IF_NONE,
|
||||
IF_WIFI,
|
||||
IF_WIRED
|
||||
};
|
||||
|
||||
u32 version;
|
||||
u8 connType;
|
||||
u8 linkTimeout;
|
||||
u8 nwc24Permission;
|
||||
u8 padding;
|
||||
|
||||
ConnectionSettings connection[3];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::string m_path;
|
||||
ConfigData m_data;
|
||||
};
|
||||
} // namespace Net
|
Loading…
Reference in New Issue