mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Fix MAC address reading on Windows.
This commit is contained in:
parent
c7b8c75d38
commit
57f2eda130
@ -13,6 +13,7 @@ set(SRCS BreakPoints.cpp
|
|||||||
Misc.cpp
|
Misc.cpp
|
||||||
MsgHandler.cpp
|
MsgHandler.cpp
|
||||||
NandPaths.cpp
|
NandPaths.cpp
|
||||||
|
Network.cpp
|
||||||
SettingsHandler.cpp
|
SettingsHandler.cpp
|
||||||
SDCardUtil.cpp
|
SDCardUtil.cpp
|
||||||
StringUtil.cpp
|
StringUtil.cpp
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
<ClInclude Include="MemoryUtil.h" />
|
<ClInclude Include="MemoryUtil.h" />
|
||||||
<ClInclude Include="MsgHandler.h" />
|
<ClInclude Include="MsgHandler.h" />
|
||||||
<ClInclude Include="NandPaths.h" />
|
<ClInclude Include="NandPaths.h" />
|
||||||
|
<ClInclude Include="Network.h" />
|
||||||
<ClInclude Include="SDCardUtil.h" />
|
<ClInclude Include="SDCardUtil.h" />
|
||||||
<ClInclude Include="SettingsHandler.h" />
|
<ClInclude Include="SettingsHandler.h" />
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
@ -109,6 +110,7 @@
|
|||||||
<ClCompile Include="Misc.cpp" />
|
<ClCompile Include="Misc.cpp" />
|
||||||
<ClCompile Include="MsgHandler.cpp" />
|
<ClCompile Include="MsgHandler.cpp" />
|
||||||
<ClCompile Include="NandPaths.cpp" />
|
<ClCompile Include="NandPaths.cpp" />
|
||||||
|
<ClCompile Include="Network.cpp" />
|
||||||
<ClCompile Include="SDCardUtil.cpp" />
|
<ClCompile Include="SDCardUtil.cpp" />
|
||||||
<ClCompile Include="SettingsHandler.cpp" />
|
<ClCompile Include="SettingsHandler.cpp" />
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
<ClInclude Include="MemoryUtil.h" />
|
<ClInclude Include="MemoryUtil.h" />
|
||||||
<ClInclude Include="MsgHandler.h" />
|
<ClInclude Include="MsgHandler.h" />
|
||||||
<ClInclude Include="NandPaths.h" />
|
<ClInclude Include="NandPaths.h" />
|
||||||
|
<ClInclude Include="Network.h" />
|
||||||
<ClInclude Include="SDCardUtil.h" />
|
<ClInclude Include="SDCardUtil.h" />
|
||||||
<ClInclude Include="SettingsHandler.h" />
|
<ClInclude Include="SettingsHandler.h" />
|
||||||
<ClInclude Include="StdConditionVariable.h" />
|
<ClInclude Include="StdConditionVariable.h" />
|
||||||
@ -77,6 +78,7 @@
|
|||||||
<ClCompile Include="Misc.cpp" />
|
<ClCompile Include="Misc.cpp" />
|
||||||
<ClCompile Include="MsgHandler.cpp" />
|
<ClCompile Include="MsgHandler.cpp" />
|
||||||
<ClCompile Include="NandPaths.cpp" />
|
<ClCompile Include="NandPaths.cpp" />
|
||||||
|
<ClCompile Include="Network.cpp" />
|
||||||
<ClCompile Include="SDCardUtil.cpp" />
|
<ClCompile Include="SDCardUtil.cpp" />
|
||||||
<ClCompile Include="SettingsHandler.cpp" />
|
<ClCompile Include="SettingsHandler.cpp" />
|
||||||
<ClCompile Include="StringUtil.cpp" />
|
<ClCompile Include="StringUtil.cpp" />
|
||||||
|
70
Source/Core/Common/Network.cpp
Normal file
70
Source/Core/Common/Network.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Copyright 2013 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
#include "Common/Network.h"
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
|
void GenerateMacAddress(const MACConsumer type, u8* mac)
|
||||||
|
{
|
||||||
|
memset(mac, 0, MAC_ADDRESS_SIZE);
|
||||||
|
|
||||||
|
u8 const oui_bba[] = { 0x00, 0x09, 0xbf };
|
||||||
|
u8 const oui_ios[] = { 0x00, 0x17, 0xab };
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case BBA:
|
||||||
|
memcpy(mac, oui_bba, 3);
|
||||||
|
break;
|
||||||
|
case IOS:
|
||||||
|
memcpy(mac, oui_ios, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
srand((unsigned int)time(nullptr));
|
||||||
|
|
||||||
|
u8 id[3] =
|
||||||
|
{
|
||||||
|
(u8)rand(),
|
||||||
|
(u8)rand(),
|
||||||
|
(u8)rand()
|
||||||
|
};
|
||||||
|
|
||||||
|
memcpy(&mac[3], id, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MacAddressToString(const u8* mac)
|
||||||
|
{
|
||||||
|
return StringFromFormat("%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
|
mac[0], mac[1], mac[2],
|
||||||
|
mac[3], mac[4], mac[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StringToMacAddress(const std::string& mac_string, u8* mac)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
if (!mac_string.empty())
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
memset(mac, 0, MAC_ADDRESS_SIZE);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < mac_string.size() && x < (MAC_ADDRESS_SIZE*2); ++i)
|
||||||
|
{
|
||||||
|
char c = tolower(mac_string.at(i));
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
{
|
||||||
|
mac[x / 2] |= (c - '0') << ((x & 1) ? 0 : 4); ++x;
|
||||||
|
}
|
||||||
|
else if (c >= 'a' && c <= 'f')
|
||||||
|
{
|
||||||
|
mac[x / 2] |= (c - 'a' + 10) << ((x & 1) ? 0 : 4); ++x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
success = x / 2 == MAC_ADDRESS_SIZE;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
24
Source/Core/Common/Network.h
Normal file
24
Source/Core/Common/Network.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2013 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
enum MACConsumer
|
||||||
|
{
|
||||||
|
BBA = 0,
|
||||||
|
IOS = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MAC_ADDRESS_SIZE = 6
|
||||||
|
};
|
||||||
|
|
||||||
|
void GenerateMacAddress(const MACConsumer type, u8* mac);
|
||||||
|
std::string MacAddressToString(const u8* mac);
|
||||||
|
bool StringToMacAddress(const std::string& mac_string, u8* mac);
|
@ -2,8 +2,7 @@
|
|||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/Network.h"
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/HW/EXI_Device.h"
|
#include "Core/HW/EXI_Device.h"
|
||||||
#include "Core/HW/EXI_DeviceEthernet.h"
|
#include "Core/HW/EXI_DeviceEthernet.h"
|
||||||
@ -14,43 +13,6 @@
|
|||||||
// being compiled for a little endian host.
|
// being compiled for a little endian host.
|
||||||
|
|
||||||
|
|
||||||
// TODO move this code into Common or something, for IOS to use
|
|
||||||
|
|
||||||
enum MACConsumer
|
|
||||||
{
|
|
||||||
BBA,
|
|
||||||
IOS
|
|
||||||
};
|
|
||||||
|
|
||||||
void GenerateMAC(MACConsumer type, u8 (&mac)[6])
|
|
||||||
{
|
|
||||||
memset(mac, 0, 6);
|
|
||||||
|
|
||||||
u8 const oui_bba[] = { 0x00, 0x09, 0xbf };
|
|
||||||
u8 const oui_ios[] = { 0x00, 0x17, 0xab };
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case BBA:
|
|
||||||
memcpy(mac, oui_bba, 3);
|
|
||||||
break;
|
|
||||||
case IOS:
|
|
||||||
memcpy(mac, oui_ios, 3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
srand((unsigned int)time(nullptr));
|
|
||||||
|
|
||||||
u8 id[3] =
|
|
||||||
{
|
|
||||||
(u8)rand(),
|
|
||||||
(u8)rand(),
|
|
||||||
(u8)rand()
|
|
||||||
};
|
|
||||||
|
|
||||||
memcpy(&mac[3], id, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
CEXIETHERNET::CEXIETHERNET()
|
CEXIETHERNET::CEXIETHERNET()
|
||||||
{
|
{
|
||||||
tx_fifo = new u8[1518];
|
tx_fifo = new u8[1518];
|
||||||
@ -63,49 +25,18 @@ CEXIETHERNET::CEXIETHERNET()
|
|||||||
|
|
||||||
// Parse MAC address from config, and generate a new one if it doesn't
|
// Parse MAC address from config, and generate a new one if it doesn't
|
||||||
// exist or can't be parsed.
|
// exist or can't be parsed.
|
||||||
|
std::string &mac_addr_setting = SConfig::GetInstance().m_bba_mac;
|
||||||
|
u8 mac_addr[MAC_ADDRESS_SIZE] = { 0 };
|
||||||
|
|
||||||
auto &mac_addr_setting = SConfig::GetInstance().m_bba_mac;
|
if (!StringToMacAddress(mac_addr_setting, mac_addr))
|
||||||
bool mac_addr_valid = false;
|
|
||||||
u8 mac_addr[6] = { 0 };
|
|
||||||
|
|
||||||
if (!mac_addr_setting.empty())
|
|
||||||
{
|
{
|
||||||
int x = 0;
|
GenerateMacAddress(BBA, mac_addr);
|
||||||
|
mac_addr_setting = MacAddressToString(mac_addr);
|
||||||
for (size_t i = 0; i < mac_addr_setting.size() && x < 12; i++)
|
|
||||||
{
|
|
||||||
char c = mac_addr_setting.at(i);
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
{
|
|
||||||
mac_addr[x / 2] |= (c - '0') << ((x & 1) ? 0 : 4); x++;
|
|
||||||
}
|
|
||||||
else if (c >= 'A' && c <= 'F')
|
|
||||||
{
|
|
||||||
mac_addr[x / 2] |= (c - 'A' + 10) << ((x & 1) ? 0 : 4); x++;
|
|
||||||
}
|
|
||||||
else if (c >= 'a' && c <= 'f')
|
|
||||||
{
|
|
||||||
mac_addr[x / 2] |= (c - 'a' + 10) << ((x & 1) ? 0 : 4); x++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x / 2 == 6)
|
|
||||||
{
|
|
||||||
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, 6);
|
|
||||||
mac_addr_valid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mac_addr_valid)
|
|
||||||
{
|
|
||||||
GenerateMAC(BBA, mac_addr);
|
|
||||||
|
|
||||||
mac_addr_setting = ArrayToString(mac_addr, 6, 10, false);
|
|
||||||
SConfig::GetInstance().SaveSettings();
|
SConfig::GetInstance().SaveSettings();
|
||||||
|
|
||||||
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, MAC_ADDRESS_SIZE);
|
||||||
|
|
||||||
// HACK: .. fully established 100BASE-T link
|
// HACK: .. fully established 100BASE-T link
|
||||||
mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;
|
mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/NandPaths.h"
|
#include "Common/NandPaths.h"
|
||||||
|
#include "Common/Network.h"
|
||||||
#include "Common/SettingsHandler.h"
|
#include "Common/SettingsHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
@ -305,55 +306,28 @@ s32 CWII_IPC_HLE_Device_net_kd_request::NWC24MakeUserID(u64* nwc24_id, u32 holly
|
|||||||
return WC24_OK;
|
return WC24_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MacAddressToString(u8* mac)
|
|
||||||
{
|
|
||||||
return StringFromFormat("%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 ":"
|
|
||||||
"%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8,
|
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SaveMacAddress(u8* mac)
|
void SaveMacAddress(u8* mac)
|
||||||
{
|
{
|
||||||
SConfig::GetInstance().m_WirelessMac = MacAddressToString(mac);
|
SConfig::GetInstance().m_WirelessMac = MacAddressToString(mac);
|
||||||
SConfig::GetInstance().SaveSettings();
|
SConfig::GetInstance().SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateMacAddress(u8* mac)
|
|
||||||
{
|
|
||||||
mac[0] = 0x00;
|
|
||||||
mac[1] = 0x17;
|
|
||||||
mac[2] = 0xAB;
|
|
||||||
mac[3] = rand() & 0xFF;
|
|
||||||
mac[4] = rand() & 0xFF;
|
|
||||||
mac[5] = rand() & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetMacAddress(u8* mac)
|
void GetMacAddress(u8* mac)
|
||||||
{
|
{
|
||||||
|
// Parse MAC address from config, and generate a new one if it doesn't
|
||||||
|
// exist or can't be parsed.
|
||||||
std::string wireless_mac = SConfig::GetInstance().m_WirelessMac;
|
std::string wireless_mac = SConfig::GetInstance().m_WirelessMac;
|
||||||
|
if (!StringToMacAddress(wireless_mac, mac))
|
||||||
|
{
|
||||||
|
GenerateMacAddress(IOS, mac);
|
||||||
|
SaveMacAddress(mac);
|
||||||
if (!wireless_mac.empty())
|
if (!wireless_mac.empty())
|
||||||
{
|
{
|
||||||
memset(mac, 0, 6);
|
|
||||||
if ((sscanf(wireless_mac.c_str(),
|
|
||||||
" %" SCNx8 ":%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":%" SCNx8 ":%" SCNx8 " ",
|
|
||||||
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6) &&
|
|
||||||
(sscanf(wireless_mac.c_str(),
|
|
||||||
" %" SCNx8 "-%" SCNx8 "-%" SCNx8 "-%" SCNx8 "-%" SCNx8 "-%" SCNx8 " ",
|
|
||||||
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) != 6))
|
|
||||||
{
|
|
||||||
// Unable to parse the MAC address, generate a new one instead.
|
|
||||||
GenerateMacAddress(mac);
|
|
||||||
SaveMacAddress(mac);
|
|
||||||
ERROR_LOG(WII_IPC_NET, "The MAC provided (%s) is invalid. We have "\
|
ERROR_LOG(WII_IPC_NET, "The MAC provided (%s) is invalid. We have "\
|
||||||
"generated another one for you.",
|
"generated another one for you.",
|
||||||
wireless_mac.c_str());
|
MacAddressToString(mac).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
GenerateMacAddress(mac);
|
|
||||||
SaveMacAddress(mac);
|
|
||||||
}
|
|
||||||
INFO_LOG(WII_IPC_NET, "Using MAC address: %s", MacAddressToString(mac).c_str());
|
INFO_LOG(WII_IPC_NET, "Using MAC address: %s", MacAddressToString(mac).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +409,7 @@ bool CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress)
|
|||||||
case IOCTLV_NCD_GETWIRELESSMACADDRESS:
|
case IOCTLV_NCD_GETWIRELESSMACADDRESS:
|
||||||
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
|
INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
|
||||||
|
|
||||||
u8 address[6];
|
u8 address[MAC_ADDRESS_SIZE];
|
||||||
GetMacAddress(address);
|
GetMacAddress(address);
|
||||||
Memory::WriteBigEData(address,
|
Memory::WriteBigEData(address,
|
||||||
CommandBuffer.PayloadBuffer.at(1).m_Address,
|
CommandBuffer.PayloadBuffer.at(1).m_Address,
|
||||||
@ -532,7 +506,7 @@ bool CWII_IPC_HLE_Device_net_wd_command::IOCtlV(u32 CommandAddress)
|
|||||||
memcpy(info->country, "US", 2);
|
memcpy(info->country, "US", 2);
|
||||||
info->ntr_allowed_channels = Common::swap16(0xfffe);
|
info->ntr_allowed_channels = Common::swap16(0xfffe);
|
||||||
|
|
||||||
u8 address[6];
|
u8 address[MAC_ADDRESS_SIZE];
|
||||||
GetMacAddress(address);
|
GetMacAddress(address);
|
||||||
memcpy(info->mac, address, sizeof(info->mac));
|
memcpy(info->mac, address, sizeof(info->mac));
|
||||||
}
|
}
|
||||||
@ -1238,7 +1212,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress)
|
|||||||
Memory::Write_U32(0, _BufferOut);
|
Memory::Write_U32(0, _BufferOut);
|
||||||
break;
|
break;
|
||||||
case 0x1004: // mac address
|
case 0x1004: // mac address
|
||||||
u8 address[6];
|
u8 address[MAC_ADDRESS_SIZE];
|
||||||
GetMacAddress(address);
|
GetMacAddress(address);
|
||||||
Memory::WriteBigEData(address, _BufferOut, sizeof(address));
|
Memory::WriteBigEData(address, _BufferOut, sizeof(address));
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user