diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index d99c68fb27ef5..f336a42424784 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -286,6 +286,7 @@ set(pcsx2DEV9Sources DEV9/ATA/ATA_State.cpp DEV9/ATA/ATA_Transfer.cpp DEV9/ATA/HddCreate.cpp + DEV9/InternalServers/ARP_Logger.cpp DEV9/InternalServers/DHCP_Logger.cpp DEV9/InternalServers/DHCP_Server.cpp DEV9/InternalServers/DNS_Logger.cpp @@ -325,6 +326,7 @@ set(pcsx2DEV9Headers DEV9/ATA/ATA.h DEV9/ATA/HddCreate.h DEV9/DEV9.h + DEV9/InternalServers/ARP_Logger.h DEV9/InternalServers/DHCP_Logger.h DEV9/InternalServers/DHCP_Server.h DEV9/InternalServers/DNS_Logger.h diff --git a/pcsx2/DEV9/InternalServers/ARP_Logger.cpp b/pcsx2/DEV9/InternalServers/ARP_Logger.cpp new file mode 100644 index 0000000000000..df045585758d4 --- /dev/null +++ b/pcsx2/DEV9/InternalServers/ARP_Logger.cpp @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team +// SPDX-License-Identifier: GPL-3.0+ + +#include "ARP_Logger.h" +#include "DEV9/PacketReader/EthernetFrame.h" + +#include "common/Console.h" + +using namespace PacketReader; +using namespace PacketReader::ARP; + +namespace InternalServers +{ + void ARP_Logger::InspectRecv(Payload* payload) + { + ARP_Packet* arp = static_cast(payload); + LogPacket(arp); + } + + void ARP_Logger::InspectSend(Payload* payload) + { + ARP_Packet* arp = static_cast(payload); + LogPacket(arp); + } + + std::string ARP_Logger::ArrayToString(const std::unique_ptr& data, int length) + { + std::string str; + if (length != 0) + { + str.reserve(length * 4); + for (size_t i = 0; i < length; i++) + str += std::to_string(data[i]) + ":"; + + str.pop_back(); + } //else leave string empty + + return str; + } + + const char* ARP_Logger::HardwareTypeToString(u8 op) + { + switch (op) + { + case 1: + return "Ethernet"; + case 6: + return "IEEE 802"; + default: + return "Unknown"; + } + } + + const char* ARP_Logger::ProtocolToString(u16 protocol) + { + switch (protocol) + { + case static_cast(EtherType::IPv4): + return "IPv4"; + case static_cast(EtherType::ARP): + return "ARP"; + default: + return "Unknown"; + } + } + + const char* ARP_Logger::OperationToString(u16 op) + { + switch (op) + { + case 1: + return "Request"; + case 2: + return "Reply"; + default: + return "Unknown"; + } + } + + void ARP_Logger::LogPacket(ARP_Packet* arp) + { + Console.WriteLn("DEV9: ARP: Hardware Type %s (%i)", HardwareTypeToString(arp->hardwareType), arp->hardwareType); + Console.WriteLn("DEV9: ARP: Protocol %s (%i)", ProtocolToString(arp->protocol), arp->protocol); + Console.WriteLn("DEV9: ARP: Operation %s (%i)", OperationToString(arp->op), arp->op); + Console.WriteLn("DEV9: ARP: Hardware Length %i", arp->hardwareAddressLength); + Console.WriteLn("DEV9: ARP: Protocol Length %i", arp->protocolAddressLength); + Console.WriteLn("DEV9: ARP: Sender Hardware Address %s", ArrayToString(arp->senderHardwareAddress, arp->hardwareAddressLength).c_str()); + Console.WriteLn("DEV9: ARP: Sender Protocol Address %s", ArrayToString(arp->senderProtocolAddress, arp->protocolAddressLength).c_str()); + Console.WriteLn("DEV9: ARP: Target Hardware Address %s", ArrayToString(arp->targetHardwareAddress, arp->hardwareAddressLength).c_str()); + Console.WriteLn("DEV9: ARP: Target Protocol Address %s", ArrayToString(arp->targetProtocolAddress, arp->protocolAddressLength).c_str()); + } +} // namespace InternalServers diff --git a/pcsx2/DEV9/InternalServers/ARP_Logger.h b/pcsx2/DEV9/InternalServers/ARP_Logger.h new file mode 100644 index 0000000000000..5765f6e5afc79 --- /dev/null +++ b/pcsx2/DEV9/InternalServers/ARP_Logger.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team +// SPDX-License-Identifier: GPL-3.0+ + +#pragma once +#include "DEV9/PacketReader/Payload.h" +#include "DEV9/PacketReader/ARP/ARP_Packet.h" + +namespace InternalServers +{ + class ARP_Logger + { + public: + ARP_Logger(){}; + + //Expects a ARP_payload + void InspectRecv(PacketReader::Payload* payload); + //Expects a ARP_payload + void InspectSend(PacketReader::Payload* payload); + + private: + std::string ArrayToString(const std::unique_ptr& data, int length); + const char* HardwareTypeToString(u8 op); // Same as DHCP + const char* ProtocolToString(u16 protocol); + const char* OperationToString(u16 op); + void LogPacket(PacketReader::ARP::ARP_Packet* payload); + }; +} // namespace InternalServers diff --git a/pcsx2/DEV9/net.cpp b/pcsx2/DEV9/net.cpp index 6fc752ae84f6a..396f6d802ee86 100644 --- a/pcsx2/DEV9/net.cpp +++ b/pcsx2/DEV9/net.cpp @@ -17,6 +17,7 @@ #include "sockets.h" #include "PacketReader/EthernetFrame.h" +#include "PacketReader/ARP/ARP_Packet.h" #include "PacketReader/IP/IP_Packet.h" #include "PacketReader/IP/UDP/UDP_Packet.h" @@ -160,6 +161,7 @@ void TermNet() } using namespace PacketReader; +using namespace PacketReader::ARP; using namespace PacketReader::IP; using namespace PacketReader::IP::UDP; @@ -233,6 +235,13 @@ void NetAdapter::InspectSend(NetPacket* pkt) } } } + if (frame.protocol == static_cast(EtherType::ARP)) + { + Console.WriteLn("DEV9: ARP: Packet Sent"); + PayloadPtr* payload = static_cast(frame.GetPayload()); + ARP_Packet arppkt(payload->data, payload->GetLength()); + arpLogger.InspectSend(&arppkt); + } } } void NetAdapter::InspectRecv(NetPacket* pkt) @@ -265,6 +274,13 @@ void NetAdapter::InspectRecv(NetPacket* pkt) } } } + if (frame.protocol == static_cast(EtherType::ARP)) + { + Console.WriteLn("DEV9: ARP: Packet Received"); + PayloadPtr* payload = static_cast(frame.GetPayload()); + ARP_Packet arppkt(payload->data, payload->GetLength()); + arpLogger.InspectRecv(&arppkt); + } } } diff --git a/pcsx2/DEV9/net.h b/pcsx2/DEV9/net.h index a8b0c18320aa9..6f2c1e2e810ea 100644 --- a/pcsx2/DEV9/net.h +++ b/pcsx2/DEV9/net.h @@ -24,6 +24,7 @@ #include "PacketReader/MAC_Address.h" #include "PacketReader/IP/IP_Address.h" +#include "InternalServers/ARP_Logger.h" #include "InternalServers/DHCP_Logger.h" #include "InternalServers/DHCP_Server.h" #include "InternalServers/DNS_Logger.h" @@ -100,6 +101,7 @@ class NetAdapter bool dhcpOn = false; protected: + InternalServers::ARP_Logger arpLogger; InternalServers::DHCP_Logger dhcpLogger; InternalServers::DHCP_Server dhcpServer = InternalServers::DHCP_Server([&] { InternalSignalReceived(); }); InternalServers::DNS_Logger dnsLogger; diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 1d2efe083b393..170cab3bb31e3 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -170,6 +170,7 @@ + @@ -607,6 +608,7 @@ + diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index e72297d4b7e04..d7d7cd051087c 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -872,6 +872,9 @@ System\Ps2\DEV9 + + System\Ps2\DEV9\InternalServers + System\Ps2\DEV9\InternalServers @@ -1757,6 +1760,9 @@ System\Ps2\DEV9 + + System\Ps2\DEV9\InternalServers + System\Ps2\DEV9\InternalServers