fixup net/ncd/manage
This commit is contained in:
parent
ac0883044e
commit
bad1c7e67a
|
@ -122,9 +122,6 @@
|
|||
#define GC_MEMCARDB "MemoryCardB"
|
||||
|
||||
#define WII_SETTING "setting.txt"
|
||||
#define WII_EUR_SETTING "setting-eur.txt"
|
||||
#define WII_USA_SETTING "setting-usa.txt"
|
||||
#define WII_JAP_SETTING "setting-jpn.txt"
|
||||
|
||||
#define GECKO_CODE_HANDLER "codehandler.bin"
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ it failed)
|
|||
|
||||
extern std::queue<std::pair<u32,std::string> > g_ReplyQueueLater;
|
||||
const u8 default_address[] = { 0x00, 0x17, 0xAB, 0x99, 0x99, 0x99 };
|
||||
int status = 3;
|
||||
|
||||
// **********************************************************************************
|
||||
// Handle /dev/net/kd/request requests
|
||||
CWII_IPC_HLE_Device_net_kd_request::CWII_IPC_HLE_Device_net_kd_request(u32 _DeviceID, const std::string& _rDeviceName)
|
||||
|
@ -193,76 +193,6 @@ bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress)
|
|||
CWII_IPC_HLE_Device_net_ncd_manage::CWII_IPC_HLE_Device_net_ncd_manage(u32 _DeviceID, const std::string& _rDeviceName)
|
||||
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
|
||||
{
|
||||
// store network configuration
|
||||
const std::string filename(File::GetUserPath(D_WIIUSER_IDX) + "shared2/sys/net/02/config.dat");
|
||||
|
||||
isSet = false;
|
||||
|
||||
File::IOFile file(filename, "rb");
|
||||
if (!file.ReadBytes(&m_Ifconfig, 1))
|
||||
{
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: Failed to load /shared2/sys/net/02/config.dat, using dummy configuration");
|
||||
|
||||
// wired connection on IP 192.168.1.1 using gateway 192.168.1.2
|
||||
memset(&m_Ifconfig, 0, sizeof(m_Ifconfig));
|
||||
m_Ifconfig.connType = 1;
|
||||
m_Ifconfig.linkTimeout = 7;
|
||||
m_Ifconfig.connection[0].flags = 167;
|
||||
m_Ifconfig.connection[0].ip[0] = 192;
|
||||
m_Ifconfig.connection[0].ip[1] = 168;
|
||||
m_Ifconfig.connection[0].ip[2] = 1;
|
||||
m_Ifconfig.connection[0].ip[3] = 150;
|
||||
m_Ifconfig.connection[0].netmask[0] = 255;
|
||||
m_Ifconfig.connection[0].netmask[1] = 255;
|
||||
m_Ifconfig.connection[0].netmask[2] = 255;
|
||||
m_Ifconfig.connection[0].netmask[3] = 0;
|
||||
m_Ifconfig.connection[0].gateway[0] = 192;
|
||||
m_Ifconfig.connection[0].gateway[1] = 168;
|
||||
m_Ifconfig.connection[0].gateway[2] = 1;
|
||||
m_Ifconfig.connection[0].gateway[3] = 1;
|
||||
m_Ifconfig.connection[0].dns1[0] = 8;
|
||||
m_Ifconfig.connection[0].dns1[1] = 8;
|
||||
m_Ifconfig.connection[0].dns1[2] = 8;
|
||||
m_Ifconfig.connection[0].dns1[3] = 8;
|
||||
m_Ifconfig.connection[1].flags = 167;
|
||||
m_Ifconfig.connection[1].ip[0] = 192;
|
||||
m_Ifconfig.connection[1].ip[1] = 168;
|
||||
m_Ifconfig.connection[1].ip[2] = 1;
|
||||
m_Ifconfig.connection[1].ip[3] = 150;
|
||||
m_Ifconfig.connection[1].netmask[0] = 255;
|
||||
m_Ifconfig.connection[1].netmask[1] = 255;
|
||||
m_Ifconfig.connection[1].netmask[2] = 255;
|
||||
m_Ifconfig.connection[1].netmask[3] = 0;
|
||||
m_Ifconfig.connection[1].gateway[0] = 192;
|
||||
m_Ifconfig.connection[1].gateway[1] = 168;
|
||||
m_Ifconfig.connection[1].gateway[2] = 1;
|
||||
m_Ifconfig.connection[1].gateway[3] = 1;
|
||||
m_Ifconfig.connection[1].dns1[0] = 8;
|
||||
m_Ifconfig.connection[1].dns1[1] = 8;
|
||||
m_Ifconfig.connection[1].dns1[2] = 8;
|
||||
m_Ifconfig.connection[1].dns1[3] = 8;
|
||||
m_Ifconfig.connection[2].flags = 167;
|
||||
m_Ifconfig.connection[2].ip[0] = 192;
|
||||
m_Ifconfig.connection[2].ip[1] = 168;
|
||||
m_Ifconfig.connection[2].ip[2] = 1;
|
||||
m_Ifconfig.connection[2].ip[3] = 150;
|
||||
m_Ifconfig.connection[2].netmask[0] = 255;
|
||||
m_Ifconfig.connection[2].netmask[1] = 255;
|
||||
m_Ifconfig.connection[2].netmask[2] = 255;
|
||||
m_Ifconfig.connection[2].netmask[3] = 0;
|
||||
m_Ifconfig.connection[2].gateway[0] = 192;
|
||||
m_Ifconfig.connection[2].gateway[1] = 168;
|
||||
m_Ifconfig.connection[2].gateway[2] = 1;
|
||||
m_Ifconfig.connection[2].gateway[3] = 1;
|
||||
m_Ifconfig.connection[2].dns1[0] = 8;
|
||||
m_Ifconfig.connection[2].dns1[1] = 8;
|
||||
m_Ifconfig.connection[2].dns1[2] = 8;
|
||||
m_Ifconfig.connection[2].dns1[3] = 8;
|
||||
|
||||
|
||||
File::IOFile outConfig(filename, "wb");
|
||||
outConfig.WriteBytes(&m_Ifconfig, sizeof(m_Ifconfig));
|
||||
}
|
||||
}
|
||||
|
||||
CWII_IPC_HLE_Device_net_ncd_manage::~CWII_IPC_HLE_Device_net_ncd_manage()
|
||||
|
@ -288,86 +218,59 @@ bool CWII_IPC_HLE_Device_net_ncd_manage::Close(u32 _CommandAddress, bool _bForce
|
|||
|
||||
bool CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress)
|
||||
{
|
||||
u32 ReturnValue = 0;
|
||||
u32 return_value = 0;
|
||||
u32 common_result = 0;
|
||||
u32 common_vector = 0;
|
||||
|
||||
SIOCtlVBuffer CommandBuffer(_CommandAddress);
|
||||
|
||||
switch (CommandBuffer.Parameter)
|
||||
{
|
||||
case IOCTLV_NCD_GETCONFIG: // 7004 out, 32 out
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETCONFIG");
|
||||
case IOCTLV_NCD_READCONFIG: // 7004 Out, 32 Out. 2nd, 3rd
|
||||
|
||||
if(CommandBuffer.Parameter == IOCTLV_NCD_READCONFIG)
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG");
|
||||
|
||||
// first out buffer gets filled with contents of /shared2/sys/net/02/config.dat
|
||||
// TODO: What's the second output buffer for?
|
||||
{
|
||||
|
||||
// fill output buffer, taking care of endianness, every day, every way
|
||||
u32 addr = CommandBuffer.PayloadBuffer.at(0).m_Address;
|
||||
u32 _BufferOut2 = CommandBuffer.PayloadBuffer.at(1).m_Address;
|
||||
|
||||
|
||||
Memory::WriteBigEData((const u8*)&m_Ifconfig, addr, 8);
|
||||
addr += 8;
|
||||
for (unsigned int i = 0; i < 3; i++)
|
||||
{
|
||||
netcfg_connection_t *conn = &m_Ifconfig.connection[i];
|
||||
|
||||
Memory::WriteBigEData((const u8*)conn, addr, 26);
|
||||
Memory::Write_U16(Common::swap16(conn->mtu), addr+26);
|
||||
Memory::WriteBigEData((const u8*)conn->padding_3, addr+28, 8);
|
||||
|
||||
Memory::WriteBigEData((const u8*)&conn->proxy_settings, addr+36, 260);
|
||||
Memory::Write_U16(Common::swap16(conn->proxy_settings.proxy_port), addr+296);
|
||||
Memory::WriteBigEData((const u8*)&conn->proxy_settings.proxy_username, addr+298, 65);
|
||||
Memory::Write_U8(conn->padding_4, addr+363);
|
||||
|
||||
Memory::WriteBigEData((const u8*)&conn->proxy_settings_copy, addr+364, 260);
|
||||
Memory::Write_U16(Common::swap16(conn->proxy_settings_copy.proxy_port), addr+624);
|
||||
Memory::WriteBigEData((const u8*)&conn->proxy_settings_copy.proxy_username, addr+626, 65);
|
||||
Memory::WriteBigEData((const u8*)conn->padding_5, addr+691, 1641);
|
||||
addr += sizeof(netcfg_connection_t);
|
||||
}
|
||||
Memory::Write_U32(0, _BufferOut2);
|
||||
Memory::Write_U32(0, _BufferOut2+4);
|
||||
ReturnValue = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case IOCTLV_NCD_SETCONFIG: // 7004 In, 32 Out. 4th
|
||||
/*if (param1[4] == 2)
|
||||
status = 3;
|
||||
if (param1[4] == 1)
|
||||
status = 5;
|
||||
if (param1[4] == 0)
|
||||
status = 2;*/
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_SETCONFIG");
|
||||
case IOCTLV_NCD_GETCONFIG:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETCONFIG");
|
||||
config.WriteToMem(CommandBuffer.PayloadBuffer.at(0).m_Address);
|
||||
common_vector = 1;
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_GETLINKSTATUS: // 32 Out. 5th
|
||||
{
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETLINKSTATUS");
|
||||
Memory::Write_U32(0x00000000, CommandBuffer.PayloadBuffer[0].m_Address);
|
||||
Memory::Write_U32(status, CommandBuffer.PayloadBuffer[0].m_Address+4);
|
||||
break;
|
||||
}
|
||||
case IOCTLV_NCD_SETCONFIG:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_SETCONFIG");
|
||||
config.ReadFromMem(CommandBuffer.InBuffer.at(0).m_Address);
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_GETWIRELESSMACADDRESS: // 32 Out, 6 Out. 1st
|
||||
{
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
|
||||
Memory::Write_U32(0, CommandBuffer.PayloadBuffer.at(0).m_Address);
|
||||
Memory::WriteBigEData(default_address, CommandBuffer.PayloadBuffer.at(1).m_Address, 6);
|
||||
break;
|
||||
}
|
||||
case IOCTLV_NCD_READCONFIG:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG");
|
||||
config.ReadConfig();
|
||||
config.WriteToMem(CommandBuffer.PayloadBuffer.at(0).m_Address);
|
||||
common_vector = 1;
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_WRITECONFIG:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG");
|
||||
config.ReadFromMem(CommandBuffer.InBuffer.at(0).m_Address);
|
||||
config.WriteConfig();
|
||||
break;
|
||||
|
||||
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,
|
||||
CommandBuffer.PayloadBuffer.at(0).m_Address + 4);
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_GETWIRELESSMACADDRESS:
|
||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
|
||||
Memory::WriteBigEData(default_address,
|
||||
CommandBuffer.PayloadBuffer.at(1).m_Address, sizeof(default_address));
|
||||
break;
|
||||
|
||||
default:
|
||||
WARN_LOG(WII_IPC_NET, "NET_NCD_MANAGE IOCtlV: %#x", CommandBuffer.Parameter);
|
||||
break;
|
||||
}
|
||||
|
||||
Memory::Write_U32(ReturnValue, _CommandAddress+4);
|
||||
Memory::Write_U32(common_result,
|
||||
CommandBuffer.PayloadBuffer.at(common_vector).m_Address);
|
||||
Memory::Write_U32(return_value, _CommandAddress + 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,19 +29,19 @@
|
|||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include "Timer.h"
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
// data layout of the network configuration file (/shared2/sys/net/02/config.dat)
|
||||
// needed for /dev/net/ncd/manage
|
||||
#pragma pack(1)
|
||||
#pragma pack(push, 1)
|
||||
struct netcfg_proxy_t
|
||||
{
|
||||
u8 use_proxy; // 0x00 -> no proxy; 0x01 -> proxy
|
||||
u8 use_proxy_userandpass; // 0x00 -> don't use username and password; 0x01 -> use username and password
|
||||
u8 use_proxy;
|
||||
u8 use_proxy_userandpass;
|
||||
u8 padding_1[2];
|
||||
u8 proxy_name[255];
|
||||
u8 padding_2;
|
||||
u16 proxy_port; // 0-34463
|
||||
u16 proxy_port; // 0-34463
|
||||
u8 proxy_username[32];
|
||||
u8 padding_3;
|
||||
u8 proxy_password[32];
|
||||
|
@ -49,68 +49,151 @@ struct netcfg_proxy_t
|
|||
|
||||
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
|
||||
{
|
||||
LINK_BUSY = 1,
|
||||
LINK_NONE,
|
||||
LINK_WIRED,
|
||||
LINK_WIFI_DOWN,
|
||||
LINK_WIFI_UP
|
||||
};
|
||||
|
||||
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; // Connection selected
|
||||
// | ?
|
||||
// | | Internet test passed
|
||||
// | | | Use Proxy (1 -> on; 0 -> off)
|
||||
// | | | |
|
||||
// 1 0 1 0 0 1 1 0
|
||||
// | | | |
|
||||
// | | | Interface (0 -> Internal wireless; 1 -> Wired LAN adapter)
|
||||
// | | DNS source (0 -> Manual; 1 -> DHCP)
|
||||
// | IP source (0 -> Manual; 1 -> DHCP)
|
||||
// ?
|
||||
|
||||
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; // 0 or 576-1500
|
||||
u16 mtu;
|
||||
u8 padding_3[8];
|
||||
|
||||
netcfg_proxy_t proxy_settings;
|
||||
u8 padding_4;
|
||||
|
||||
netcfg_proxy_t proxy_settings_copy; // seems to be a duplicate of proxy_settings
|
||||
netcfg_proxy_t proxy_settings_copy;
|
||||
u8 padding_5[1297];
|
||||
|
||||
// wireless specific settings
|
||||
u8 ssid[32]; // access Point name.
|
||||
|
||||
u8 ssid[32];
|
||||
u8 padding_6;
|
||||
u8 ssid_length; // length of ssid in bytes.
|
||||
u8 padding_7[2];
|
||||
|
||||
u8 padding_8;
|
||||
u8 encryption; // (probably) encryption. OPN: 0x00, WEP64: 0x01, WEP128: 0x02 WPA-PSK (TKIP): 0x04, WPA2-PSK (AES): 0x05, WPA-PSK (AES): 0x06
|
||||
u8 padding_9[2];
|
||||
|
||||
u8 padding_10;
|
||||
u8 key_length; // length of key in bytes. 0x00 for WEP64 and WEP128.
|
||||
u8 unknown; // 0x00 or 0x01 toogled with a WPA-PSK (TKIP) and with a WEP entered with hex instead of ascii.
|
||||
u8 padding_11;
|
||||
|
||||
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_12[236];
|
||||
u8 padding_10[236];
|
||||
};
|
||||
|
||||
struct network_config_t
|
||||
{
|
||||
enum
|
||||
{
|
||||
IF_NONE,
|
||||
IF_WIFI,
|
||||
IF_WIRED
|
||||
};
|
||||
|
||||
u32 version;
|
||||
u8 connType; // 0x01 if there's at least one valid connection to the Internet.
|
||||
u8 nwc24Permission; // 0x00
|
||||
u8 linkTimeout; // always 0x07?
|
||||
u8 padding; // 0x00
|
||||
u8 connType;
|
||||
u8 linkTimeout;
|
||||
u8 nwc24Permission;
|
||||
u8 padding;
|
||||
|
||||
netcfg_connection_t connection[3];
|
||||
};
|
||||
#pragma pack()
|
||||
#pragma pack(pop)
|
||||
|
||||
class WiiNetConfig
|
||||
{
|
||||
std::string path;
|
||||
network_config_t config;
|
||||
|
||||
public:
|
||||
WiiNetConfig()
|
||||
{
|
||||
path = File::GetUserPath(D_WIISYSCONF_IDX) + "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()
|
||||
{
|
||||
File::IOFile(path, "wb").WriteBytes((void*)&config, sizeof(config));
|
||||
}
|
||||
|
||||
void WriteToMem(const u32 address)
|
||||
{
|
||||
Memory::WriteBigEData((const u8 *)&config, address, sizeof(config));
|
||||
}
|
||||
|
||||
void ReadFromMem(const u32 address)
|
||||
{
|
||||
Memory::ReadBigEData((u8 *)&config, address, sizeof(config));
|
||||
}
|
||||
|
||||
void ReadConfig()
|
||||
{
|
||||
if (File::Exists(path))
|
||||
{
|
||||
if (!File::IOFile(path, "rb").ReadBytes((void *)&config, sizeof(config)))
|
||||
ResetConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetConfig();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -354,8 +437,8 @@ private:
|
|||
IOCTLV_NCD_GETLINKSTATUS = 0x7, // NCDGetLinkStatus
|
||||
IOCTLV_NCD_GETWIRELESSMACADDRESS = 0x8, // NCDGetWirelessMacAddress
|
||||
};
|
||||
bool isSet;
|
||||
network_config_t m_Ifconfig;
|
||||
|
||||
WiiNetConfig config;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
Loading…
Reference in New Issue