IOS: Move network MAC utilities to their own source files

All three implementations within Net.cpp currently rely on these
functions.
This commit is contained in:
Lioncash 2017-02-15 12:22:34 -05:00
parent 6f272b3a4c
commit 245de3fa4f
6 changed files with 81 additions and 36 deletions

View File

@ -148,8 +148,9 @@ set(SRCS ActionReplay.cpp
IOS/FS/FS.cpp IOS/FS/FS.cpp
IOS/Network/Config.cpp IOS/Network/Config.cpp
IOS/Network/ICMPLin.cpp IOS/Network/ICMPLin.cpp
IOS/Network/Socket.cpp IOS/Network/MACUtils.cpp
IOS/Network/Net.cpp IOS/Network/Net.cpp
IOS/Network/Socket.cpp
IOS/Network/SSL.cpp IOS/Network/SSL.cpp
IOS/Network/KD/NetKDRequest.cpp IOS/Network/KD/NetKDRequest.cpp
IOS/Network/KD/NetKDTime.cpp IOS/Network/KD/NetKDTime.cpp

View File

@ -180,8 +180,9 @@
<ClCompile Include="IOS\FS\FS.cpp" /> <ClCompile Include="IOS\FS\FS.cpp" />
<ClCompile Include="IOS\Network\Config.cpp" /> <ClCompile Include="IOS\Network\Config.cpp" />
<ClCompile Include="IOS\Network\ICMPLin.cpp" /> <ClCompile Include="IOS\Network\ICMPLin.cpp" />
<ClCompile Include="IOS\Network\Socket.cpp" /> <ClCompile Include="IOS\Network\MACUtils.cpp" />
<ClCompile Include="IOS\Network\Net.cpp" /> <ClCompile Include="IOS\Network\Net.cpp" />
<ClCompile Include="IOS\Network\Socket.cpp" />
<ClCompile Include="IOS\Network\SSL.cpp" /> <ClCompile Include="IOS\Network\SSL.cpp" />
<ClCompile Include="IOS\Network\KD\NetKDRequest.cpp" /> <ClCompile Include="IOS\Network\KD\NetKDRequest.cpp" />
<ClCompile Include="IOS\Network\KD\NetKDTime.cpp" /> <ClCompile Include="IOS\Network\KD\NetKDTime.cpp" />
@ -420,8 +421,9 @@
<ClInclude Include="IOS\Network\Config.h" /> <ClInclude Include="IOS\Network\Config.h" />
<ClInclude Include="IOS\Network\ICMPLin.h" /> <ClInclude Include="IOS\Network\ICMPLin.h" />
<ClInclude Include="IOS\Network\ICMP.h" /> <ClInclude Include="IOS\Network\ICMP.h" />
<ClInclude Include="IOS\Network\Socket.h" /> <ClInclude Include="IOS\Network\MACUtils.h" />
<ClInclude Include="IOS\Network\Net.h" /> <ClInclude Include="IOS\Network\Net.h" />
<ClInclude Include="IOS\Network\Socket.h" />
<ClInclude Include="IOS\Network\SSL.h" /> <ClInclude Include="IOS\Network\SSL.h" />
<ClInclude Include="IOS\Network\KD\NetKDRequest.h" /> <ClInclude Include="IOS\Network\KD\NetKDRequest.h" />
<ClInclude Include="IOS\Network\KD\NetKDTime.h" /> <ClInclude Include="IOS\Network\KD\NetKDTime.h" />

View File

@ -758,6 +758,9 @@
<ClCompile Include="IOS\MIOS.cpp"> <ClCompile Include="IOS\MIOS.cpp">
<Filter>IOS</Filter> <Filter>IOS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="IOS\Network\MACUtils.cpp">
<Filter>IOS\Network</Filter>
</ClCompile>
<ClCompile Include="IOS\Network\Net.cpp"> <ClCompile Include="IOS\Network\Net.cpp">
<Filter>IOS\Network</Filter> <Filter>IOS\Network</Filter>
</ClCompile> </ClCompile>
@ -1353,6 +1356,9 @@
<ClInclude Include="IOS\Network\ICMPLin.h"> <ClInclude Include="IOS\Network\ICMPLin.h">
<Filter>IOS\Network</Filter> <Filter>IOS\Network</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="IOS\Network\MACUtils.h">
<Filter>IOS\Network</Filter>
</ClInclude>
<ClInclude Include="IOS\Network\Net.h"> <ClInclude Include="IOS\Network\Net.h">
<Filter>IOS\Network</Filter> <Filter>IOS\Network</Filter>
</ClInclude> </ClInclude>

View File

@ -0,0 +1,50 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Core/IOS/Network/MACUtils.h"
#include <string>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Network.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
namespace IOS
{
namespace Net
{
static void SaveMACAddress(const u8* mac)
{
SConfig::GetInstance().m_WirelessMac = Common::MacAddressToString(mac);
SConfig::GetInstance().SaveSettings();
}
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;
if (Core::g_want_determinism)
wireless_mac = "12:34:56:78:9a:bc";
if (!Common::StringToMacAddress(wireless_mac, mac))
{
Common::GenerateMacAddress(Common::MACConsumer::IOS, mac);
SaveMACAddress(mac);
if (!wireless_mac.empty())
{
ERROR_LOG(IOS_NET, "The MAC provided (%s) is invalid. We have "
"generated another one for you.",
Common::MacAddressToString(mac).c_str());
}
}
INFO_LOG(IOS_NET, "Using MAC address: %s", Common::MacAddressToString(mac).c_str());
}
} // namespace Net
} // namespace IOS

View File

@ -0,0 +1,15 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include "Common/CommonTypes.h"
namespace IOS
{
namespace Net
{
void GetMACAddress(u8* mac);
} // namespace Net
} // namespace IOS

View File

@ -24,10 +24,10 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/Network.h" #include "Common/Network.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/IOS/Network/ICMP.h" #include "Core/IOS/Network/ICMP.h"
#include "Core/IOS/Network/MACUtils.h"
#include "Core/IOS/Network/Socket.h" #include "Core/IOS/Network/Socket.h"
#ifdef _WIN32 #ifdef _WIN32
@ -62,35 +62,6 @@ namespace HLE
{ {
namespace Device namespace Device
{ {
static void SaveMacAddress(u8* mac)
{
SConfig::GetInstance().m_WirelessMac = Common::MacAddressToString(mac);
SConfig::GetInstance().SaveSettings();
}
static 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;
if (Core::g_want_determinism)
wireless_mac = "12:34:56:78:9a:bc";
if (!Common::StringToMacAddress(wireless_mac, mac))
{
Common::GenerateMacAddress(Common::MACConsumer::IOS, mac);
SaveMacAddress(mac);
if (!wireless_mac.empty())
{
ERROR_LOG(IOS_NET, "The MAC provided (%s) is invalid. We have "
"generated another one for you.",
Common::MacAddressToString(mac).c_str());
}
}
INFO_LOG(IOS_NET, "Using MAC address: %s", Common::MacAddressToString(mac).c_str());
}
// ********************************************************************************** // **********************************************************************************
// Handle /dev/net/ncd/manage requests // Handle /dev/net/ncd/manage requests
NetNCDManage::NetNCDManage(u32 device_id, const std::string& device_name) NetNCDManage::NetNCDManage(u32 device_id, const std::string& device_name)
@ -146,7 +117,7 @@ IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS"); INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
u8 address[Common::MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); IOS::Net::GetMACAddress(address);
Memory::CopyToEmu(request.io_vectors.at(1).address, address, sizeof(address)); Memory::CopyToEmu(request.io_vectors.at(1).address, address, sizeof(address));
break; break;
@ -215,7 +186,7 @@ IPCCommandResult NetWDCommand::IOCtlV(const IOCtlVRequest& request)
info->ntr_allowed_channels = Common::swap16(0xfffe); info->ntr_allowed_channels = Common::swap16(0xfffe);
u8 address[Common::MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); IOS::Net::GetMACAddress(address);
memcpy(info->mac, address, sizeof(info->mac)); memcpy(info->mac, address, sizeof(info->mac));
} }
break; break;
@ -930,7 +901,7 @@ IPCCommandResult NetIPTop::IOCtlV(const IOCtlVRequest& request)
case 0x1004: // mac address case 0x1004: // mac address
u8 address[Common::MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); IOS::Net::GetMACAddress(address);
Memory::CopyToEmu(request.io_vectors[0].address, address, sizeof(address)); Memory::CopyToEmu(request.io_vectors[0].address, address, sizeof(address));
break; break;