Merge pull request #7107 from lioncash/mac
Common/Network: Get rid of out parameters for MAC address utilities
This commit is contained in:
9 files changed
+88
-60
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include "Core/HW/EXI/EXI_DeviceEthernet.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
@@ -33,16 +34,17 @@ CEXIETHERNET::CEXIETHERNET()
|
||||
// Parse MAC address from config, and generate a new one if it doesn't
|
||||
// exist or can't be parsed.
|
||||
std::string& mac_addr_setting = SConfig::GetInstance().m_bba_mac;
|
||||
u8 mac_addr[Common::MAC_ADDRESS_SIZE] = {0};
|
||||
std::optional<Common::MACAddress> mac_addr = Common::StringToMacAddress(mac_addr_setting);
|
||||
|
||||
if (!Common::StringToMacAddress(mac_addr_setting, mac_addr))
|
||||
if (!mac_addr)
|
||||
{
|
||||
Common::GenerateMacAddress(Common::MACConsumer::BBA, mac_addr);
|
||||
mac_addr_setting = Common::MacAddressToString(mac_addr);
|
||||
mac_addr = Common::GenerateMacAddress(Common::MACConsumer::BBA);
|
||||
mac_addr_setting = Common::MacAddressToString(mac_addr.value());
|
||||
SConfig::GetInstance().SaveSettings();
|
||||
}
|
||||
|
||||
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, Common::MAC_ADDRESS_SIZE);
|
||||
const auto& mac = mac_addr.value();
|
||||
memcpy(&mBbaMem[BBA_NAFR_PAR0], mac.data(), mac.size());
|
||||
|
||||
// HACK: .. fully established 100BASE-T link
|
||||
mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;
|
||||
|
||||
@@ -878,10 +878,11 @@ IPCCommandResult NetIPTop::HandleGetInterfaceOptRequest(const IOCtlVRequest& req
|
||||
break;
|
||||
|
||||
case 0x1004: // mac address
|
||||
u8 address[Common::MAC_ADDRESS_SIZE];
|
||||
IOS::Net::GetMACAddress(address);
|
||||
Memory::CopyToEmu(request.io_vectors[0].address, address, sizeof(address));
|
||||
{
|
||||
const Common::MACAddress address = IOS::Net::GetMACAddress();
|
||||
Memory::CopyToEmu(request.io_vectors[0].address, address.data(), address.size());
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x1005: // link state
|
||||
Memory::Write_U32(1, request.io_vectors[0].address);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Core/IOS/Network/MACUtils.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@@ -15,13 +16,13 @@
|
||||
|
||||
namespace IOS::Net
|
||||
{
|
||||
static void SaveMACAddress(const u8* mac)
|
||||
static void SaveMACAddress(const Common::MACAddress& mac)
|
||||
{
|
||||
SConfig::GetInstance().m_WirelessMac = Common::MacAddressToString(mac);
|
||||
SConfig::GetInstance().SaveSettings();
|
||||
}
|
||||
|
||||
void GetMACAddress(u8* mac)
|
||||
Common::MACAddress GetMACAddress()
|
||||
{
|
||||
// Parse MAC address from config, and generate a new one if it doesn't
|
||||
// exist or can't be parsed.
|
||||
@@ -30,19 +31,22 @@ void GetMACAddress(u8* mac)
|
||||
if (Core::WantsDeterminism())
|
||||
wireless_mac = "12:34:56:78:9a:bc";
|
||||
|
||||
if (!Common::StringToMacAddress(wireless_mac, mac))
|
||||
std::optional<Common::MACAddress> mac = Common::StringToMacAddress(wireless_mac);
|
||||
|
||||
if (!mac)
|
||||
{
|
||||
Common::GenerateMacAddress(Common::MACConsumer::IOS, mac);
|
||||
SaveMACAddress(mac);
|
||||
mac = Common::GenerateMacAddress(Common::MACConsumer::IOS);
|
||||
SaveMACAddress(mac.value());
|
||||
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());
|
||||
Common::MacAddressToString(mac.value()).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
INFO_LOG(IOS_NET, "Using MAC address: %s", Common::MacAddressToString(mac).c_str());
|
||||
INFO_LOG(IOS_NET, "Using MAC address: %s", Common::MacAddressToString(mac.value()).c_str());
|
||||
return mac.value();
|
||||
}
|
||||
} // namespace IOS::Net
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Network.h"
|
||||
|
||||
namespace IOS::Net
|
||||
{
|
||||
void GetMACAddress(u8* mac);
|
||||
Common::MACAddress GetMACAddress();
|
||||
} // namespace IOS::Net
|
||||
@@ -65,12 +65,13 @@ IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_GETWIRELESSMACADDRESS:
|
||||
{
|
||||
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS");
|
||||
|
||||
u8 address[Common::MAC_ADDRESS_SIZE];
|
||||
IOS::Net::GetMACAddress(address);
|
||||
Memory::CopyToEmu(request.io_vectors.at(1).address, address, sizeof(address));
|
||||
const Common::MACAddress address = IOS::Net::GetMACAddress();
|
||||
Memory::CopyToEmu(request.io_vectors.at(1).address, address.data(), address.size());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
INFO_LOG(IOS_NET, "NET_NCD_MANAGE IOCtlV: %#x", request.request);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Core/IOS/Network/WD/Command.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
@@ -65,9 +66,8 @@ IPCCommandResult NetWDCommand::IOCtlV(const IOCtlVRequest& request)
|
||||
memcpy(info->country, "US", 2);
|
||||
info->ntr_allowed_channels = Common::swap16(0xfffe);
|
||||
|
||||
u8 address[Common::MAC_ADDRESS_SIZE];
|
||||
IOS::Net::GetMACAddress(address);
|
||||
memcpy(info->mac, address, sizeof(info->mac));
|
||||
const Common::MACAddress address = IOS::Net::GetMACAddress();
|
||||
std::copy(address.begin(), address.end(), info->mac);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -518,9 +518,17 @@ void BluetoothReal::LoadLinkKeys()
|
||||
if (index == std::string::npos)
|
||||
continue;
|
||||
|
||||
bdaddr_t address;
|
||||
Common::StringToMacAddress(pair.substr(0, index), address.data());
|
||||
std::reverse(address.begin(), address.end());
|
||||
const std::string address_string = pair.substr(0, index);
|
||||
std::optional<bdaddr_t> address = Common::StringToMacAddress(address_string);
|
||||
if (!address)
|
||||
{
|
||||
ERROR_LOG(IOS_WIIMOTE, "Malformed MAC address (%s). Skipping loading of current link key.",
|
||||
address_string.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& mac = address.value();
|
||||
std::reverse(mac.begin(), mac.end());
|
||||
|
||||
const std::string& key_string = pair.substr(index + 1);
|
||||
linkkey_t key{};
|
||||
@@ -532,7 +540,7 @@ void BluetoothReal::LoadLinkKeys()
|
||||
key[pos++] = value;
|
||||
}
|
||||
|
||||
m_link_keys[address] = key;
|
||||
m_link_keys[mac] = key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,7 +552,7 @@ void BluetoothReal::SaveLinkKeys()
|
||||
bdaddr_t address;
|
||||
// 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());
|
||||
oss << Common::MacAddressToString(address.data());
|
||||
oss << Common::MacAddressToString(address);
|
||||
oss << '=';
|
||||
oss << std::hex;
|
||||
for (const u16& data : entry.second)
|
||||
|
||||
Reference in new issue
Block a user