Common: Namespace Network.h/.cpp

Necessary to avoid namespace clashes with IOS HLE's namespace name.
This commit is contained in:
Lioncash 2017-01-17 19:19:20 -05:00
parent 63011f1402
commit f1542c8e5a
5 changed files with 26 additions and 20 deletions

View File

@ -11,6 +11,8 @@
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/Timer.h" #include "Common/Timer.h"
namespace Common
{
void GenerateMacAddress(const MACConsumer type, u8* mac) void GenerateMacAddress(const MACConsumer type, u8* mac)
{ {
memset(mac, 0, MAC_ADDRESS_SIZE); memset(mac, 0, MAC_ADDRESS_SIZE);
@ -20,10 +22,10 @@ void GenerateMacAddress(const MACConsumer type, u8* mac)
switch (type) switch (type)
{ {
case BBA: case MACConsumer::BBA:
memcpy(mac, oui_bba, 3); memcpy(mac, oui_bba, 3);
break; break;
case IOS: case MACConsumer::IOS:
memcpy(mac, oui_ios, 3); memcpy(mac, oui_ios, 3);
break; break;
} }
@ -68,3 +70,4 @@ bool StringToMacAddress(const std::string& mac_string, u8* mac)
} }
return success; return success;
} }
} // namespace Common

View File

@ -8,10 +8,12 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
enum MACConsumer namespace Common
{ {
BBA = 0, enum class MACConsumer
IOS = 1 {
BBA,
IOS
}; };
enum enum
@ -22,3 +24,4 @@ enum
void GenerateMacAddress(const MACConsumer type, u8* mac); void GenerateMacAddress(const MACConsumer type, u8* mac);
std::string MacAddressToString(const u8* mac); std::string MacAddressToString(const u8* mac);
bool StringToMacAddress(const std::string& mac_string, u8* mac); bool StringToMacAddress(const std::string& mac_string, u8* mac);
} // namespace Common

View File

@ -31,16 +31,16 @@ 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; std::string& mac_addr_setting = SConfig::GetInstance().m_bba_mac;
u8 mac_addr[MAC_ADDRESS_SIZE] = {0}; u8 mac_addr[Common::MAC_ADDRESS_SIZE] = {0};
if (!StringToMacAddress(mac_addr_setting, mac_addr)) if (!Common::StringToMacAddress(mac_addr_setting, mac_addr))
{ {
GenerateMacAddress(BBA, mac_addr); Common::GenerateMacAddress(Common::MACConsumer::BBA, mac_addr);
mac_addr_setting = MacAddressToString(mac_addr); mac_addr_setting = Common::MacAddressToString(mac_addr);
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, MAC_ADDRESS_SIZE); memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, Common::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;

View File

@ -287,7 +287,7 @@ s32 CWII_IPC_HLE_Device_net_kd_request::NWC24MakeUserID(u64* nwc24_id, u32 holly
static void SaveMacAddress(u8* mac) static void SaveMacAddress(u8* mac)
{ {
SConfig::GetInstance().m_WirelessMac = MacAddressToString(mac); SConfig::GetInstance().m_WirelessMac = Common::MacAddressToString(mac);
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }
@ -300,18 +300,18 @@ static void GetMacAddress(u8* mac)
if (Core::g_want_determinism) if (Core::g_want_determinism)
wireless_mac = "12:34:56:78:9a:bc"; wireless_mac = "12:34:56:78:9a:bc";
if (!StringToMacAddress(wireless_mac, mac)) if (!Common::StringToMacAddress(wireless_mac, mac))
{ {
GenerateMacAddress(IOS, mac); Common::GenerateMacAddress(Common::MACConsumer::IOS, mac);
SaveMacAddress(mac); SaveMacAddress(mac);
if (!wireless_mac.empty()) if (!wireless_mac.empty())
{ {
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.",
MacAddressToString(mac).c_str()); Common::MacAddressToString(mac).c_str());
} }
} }
INFO_LOG(WII_IPC_NET, "Using MAC address: %s", MacAddressToString(mac).c_str()); INFO_LOG(WII_IPC_NET, "Using MAC address: %s", Common::MacAddressToString(mac).c_str());
} }
// ********************************************************************************** // **********************************************************************************
@ -374,7 +374,7 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(const IOSIOCtlVReque
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[MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); 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;
@ -448,7 +448,7 @@ IPCCommandResult CWII_IPC_HLE_Device_net_wd_command::IOCtlV(const IOSIOCtlVReque
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[MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); GetMacAddress(address);
memcpy(info->mac, address, sizeof(info->mac)); memcpy(info->mac, address, sizeof(info->mac));
} }
@ -1165,7 +1165,7 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtlV(const IOSIOCtlVRequest&
break; break;
case 0x1004: // mac address case 0x1004: // mac address
u8 address[MAC_ADDRESS_SIZE]; u8 address[Common::MAC_ADDRESS_SIZE];
GetMacAddress(address); GetMacAddress(address);
Memory::CopyToEmu(request.io_vectors[0].address, address, sizeof(address)); Memory::CopyToEmu(request.io_vectors[0].address, address, sizeof(address));
break; break;

View File

@ -470,7 +470,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305_real::LoadLinkKeys()
continue; continue;
btaddr_t address; btaddr_t address;
StringToMacAddress(pair.substr(0, index), address.data()); Common::StringToMacAddress(pair.substr(0, index), address.data());
std::reverse(address.begin(), address.end()); std::reverse(address.begin(), address.end());
const std::string& key_string = pair.substr(index + 1); const std::string& key_string = pair.substr(index + 1);
@ -495,7 +495,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305_real::SaveLinkKeys()
btaddr_t address; btaddr_t address;
// Reverse the address so that it is stored in the correct order in the config file // Reverse the address so that it is stored in the correct order in the config file
std::reverse_copy(entry.first.begin(), entry.first.end(), address.begin()); std::reverse_copy(entry.first.begin(), entry.first.end(), address.begin());
oss << MacAddressToString(address.data()); oss << Common::MacAddressToString(address.data());
oss << '='; oss << '=';
oss << std::hex; oss << std::hex;
for (const u16& data : entry.second) for (const u16& data : entry.second)