From 76fe7b6497c5283d1681cc9a7a0630d17ef73272 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Sun, 10 Jul 2022 23:17:46 +0400 Subject: [PATCH] NetworkCaptureLogger: Add GameCube BBA support --- Source/Core/Core/Config/MainSettings.cpp | 1 + Source/Core/Core/Config/MainSettings.h | 1 + Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp | 9 +++++++-- Source/Core/Core/NetworkCaptureLogger.cpp | 11 +++++++++++ Source/Core/Core/NetworkCaptureLogger.h | 6 ++++++ Source/Core/DolphinQt/Debugger/NetworkWidget.cpp | 10 ++++++++++ Source/Core/DolphinQt/Debugger/NetworkWidget.h | 1 + 7 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index c3161e924e..9ff3697c08 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -347,6 +347,7 @@ const Info MAIN_NETWORK_SSL_VERIFY_CERTIFICATES{ const Info MAIN_NETWORK_SSL_DUMP_ROOT_CA{{System::Main, "Network", "SSLDumpRootCA"}, false}; const Info MAIN_NETWORK_SSL_DUMP_PEER_CERT{{System::Main, "Network", "SSLDumpPeerCert"}, false}; +const Info MAIN_NETWORK_DUMP_BBA{{System::Main, "Network", "DumpBBA"}, false}; const Info MAIN_NETWORK_DUMP_AS_PCAP{{System::Main, "Network", "DumpAsPCAP"}, false}; // Default value based on: // - [RFC 1122] 4.2.3.5 TCP Connection Failures (at least 3 minutes) diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 4261eed960..7b52ad9ce4 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -206,6 +206,7 @@ extern const Info MAIN_NETWORK_SSL_DUMP_WRITE; extern const Info MAIN_NETWORK_SSL_VERIFY_CERTIFICATES; extern const Info MAIN_NETWORK_SSL_DUMP_ROOT_CA; extern const Info MAIN_NETWORK_SSL_DUMP_PEER_CERT; +extern const Info MAIN_NETWORK_DUMP_BBA; extern const Info MAIN_NETWORK_DUMP_AS_PCAP; extern const Info MAIN_NETWORK_TIMEOUT; diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp index 416b2c362d..fb99d616f1 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp @@ -8,6 +8,7 @@ #include #include +#include "Common/BitUtils.h" #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" @@ -17,6 +18,7 @@ #include "Core/CoreTiming.h" #include "Core/HW/EXI/EXI.h" #include "Core/HW/Memmap.h" +#include "Core/PowerPC/PowerPC.h" namespace ExpansionInterface { @@ -441,7 +443,10 @@ void CEXIETHERNET::DirectFIFOWrite(const u8* data, u32 size) void CEXIETHERNET::SendFromDirectFIFO() { - m_network_interface->SendFrame(tx_fifo.get(), *(u16*)&mBbaMem[BBA_TXFIFOCNT]); + const u8* frame = tx_fifo.get(); + const u16 size = Common::BitCastPtr(&mBbaMem[BBA_TXFIFOCNT]); + if (m_network_interface->SendFrame(frame, size)) + PowerPC::debug_interface.NetworkLogger()->LogBBA(frame, size); } void CEXIETHERNET::SendFromPacketBuffer() @@ -554,7 +559,7 @@ bool CEXIETHERNET::RecvHandlePacket() INFO_LOG_FMT(SP1, "{:x} {:x} {:x} {:x}", page_ptr(BBA_BP), page_ptr(BBA_RRP), page_ptr(BBA_RWP), page_ptr(BBA_RHBP)); #endif - + PowerPC::debug_interface.NetworkLogger()->LogBBA(mRecvBuffer.get(), mRecvBufferLength); write_ptr = &mBbaMem[page_ptr(BBA_RWP) << 8]; descriptor = (Descriptor*)write_ptr; diff --git a/Source/Core/Core/NetworkCaptureLogger.cpp b/Source/Core/Core/NetworkCaptureLogger.cpp index 064b5ed25b..2fd921686a 100644 --- a/Source/Core/Core/NetworkCaptureLogger.cpp +++ b/Source/Core/Core/NetworkCaptureLogger.cpp @@ -46,6 +46,10 @@ void DummyNetworkCaptureLogger::LogWrite(const void* data, std::size_t length, s { } +void DummyNetworkCaptureLogger::LogBBA(const void* data, std::size_t length) +{ +} + NetworkCaptureType DummyNetworkCaptureLogger::GetCaptureType() const { return NetworkCaptureType::None; @@ -115,6 +119,13 @@ void PCAPSSLCaptureLogger::LogWrite(const void* data, std::size_t length, s32 so Log(LogType::Write, data, length, socket, to); } +void PCAPSSLCaptureLogger::LogBBA(const void* data, std::size_t length) +{ + if (!Config::Get(Config::MAIN_NETWORK_DUMP_BBA)) + return; + m_file->AddPacket(static_cast(data), length); +} + void PCAPSSLCaptureLogger::Log(LogType log_type, const void* data, std::size_t length, s32 socket, sockaddr* other) { diff --git a/Source/Core/Core/NetworkCaptureLogger.h b/Source/Core/Core/NetworkCaptureLogger.h index d5067252d4..3e45446ac1 100644 --- a/Source/Core/Core/NetworkCaptureLogger.h +++ b/Source/Core/Core/NetworkCaptureLogger.h @@ -51,6 +51,8 @@ public: virtual void LogRead(const void* data, std::size_t length, s32 socket, sockaddr* from) = 0; virtual void LogWrite(const void* data, std::size_t length, s32 socket, sockaddr* to) = 0; + virtual void LogBBA(const void* data, std::size_t length) = 0; + virtual NetworkCaptureType GetCaptureType() const = 0; }; @@ -65,6 +67,8 @@ public: void LogRead(const void* data, std::size_t length, s32 socket, sockaddr* from) override; void LogWrite(const void* data, std::size_t length, s32 socket, sockaddr* to) override; + void LogBBA(const void* data, std::size_t length) override; + NetworkCaptureType GetCaptureType() const override; }; @@ -91,6 +95,8 @@ public: void LogRead(const void* data, std::size_t length, s32 socket, sockaddr* from) override; void LogWrite(const void* data, std::size_t length, s32 socket, sockaddr* to) override; + void LogBBA(const void* data, std::size_t length) override; + NetworkCaptureType GetCaptureType() const override; private: diff --git a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp index 96d25cc464..6439a061ba 100644 --- a/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/NetworkWidget.cpp @@ -223,6 +223,9 @@ void NetworkWidget::ConnectWidgets() connect(m_verify_certificates_checkbox, &QCheckBox::stateChanged, [](int state) { Config::SetBaseOrCurrent(Config::MAIN_NETWORK_SSL_VERIFY_CERTIFICATES, state == Qt::Checked); }); + connect(m_dump_bba_checkbox, &QCheckBox::stateChanged, [](int state) { + Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_BBA, state == Qt::Checked); + }); connect(m_open_dump_folder, &QPushButton::pressed, [] { const std::string location = File::GetUserPath(D_DUMPSSL_IDX); const QUrl url = QUrl::fromLocalFile(QString::fromStdString(location)); @@ -352,6 +355,7 @@ QGroupBox* NetworkWidget::CreateDumpOptionsGroup() // i18n: CA stands for certificate authority m_dump_root_ca_checkbox = new QCheckBox(tr("Dump root CA certificates")); m_dump_peer_cert_checkbox = new QCheckBox(tr("Dump peer certificates")); + m_dump_bba_checkbox = new QCheckBox(tr("Dump GameCube BBA traffic")); m_open_dump_folder = new QPushButton(tr("Open dump folder")); m_open_dump_folder->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -370,6 +374,7 @@ QGroupBox* NetworkWidget::CreateDumpOptionsGroup() dump_options_layout->addWidget(m_dump_ssl_write_checkbox); dump_options_layout->addWidget(m_dump_root_ca_checkbox); dump_options_layout->addWidget(m_dump_peer_cert_checkbox); + dump_options_layout->addWidget(m_dump_bba_checkbox); dump_options_layout->addWidget(m_open_dump_folder); dump_options_layout->setSpacing(1); @@ -414,23 +419,28 @@ void NetworkWidget::OnDumpFormatComboChanged(int index) case FormatComboId::BinarySSL: m_dump_ssl_read_checkbox->setChecked(true); m_dump_ssl_write_checkbox->setChecked(true); + m_dump_bba_checkbox->setChecked(false); break; case FormatComboId::BinarySSLRead: m_dump_ssl_read_checkbox->setChecked(true); m_dump_ssl_write_checkbox->setChecked(false); + m_dump_bba_checkbox->setChecked(false); break; case FormatComboId::BinarySSLWrite: m_dump_ssl_read_checkbox->setChecked(false); m_dump_ssl_write_checkbox->setChecked(true); + m_dump_bba_checkbox->setChecked(false); break; default: m_dump_ssl_read_checkbox->setChecked(false); m_dump_ssl_write_checkbox->setChecked(false); + m_dump_bba_checkbox->setChecked(false); break; } // Enable raw or decrypted SSL choices for PCAP const bool is_pcap = combo_id == FormatComboId::PCAP; m_dump_ssl_read_checkbox->setEnabled(is_pcap); m_dump_ssl_write_checkbox->setEnabled(is_pcap); + m_dump_bba_checkbox->setEnabled(is_pcap); Config::SetBaseOrCurrent(Config::MAIN_NETWORK_DUMP_AS_PCAP, is_pcap); } diff --git a/Source/Core/DolphinQt/Debugger/NetworkWidget.h b/Source/Core/DolphinQt/Debugger/NetworkWidget.h index f2ce77b615..eb235129bd 100644 --- a/Source/Core/DolphinQt/Debugger/NetworkWidget.h +++ b/Source/Core/DolphinQt/Debugger/NetworkWidget.h @@ -58,5 +58,6 @@ private: QCheckBox* m_dump_root_ca_checkbox; QCheckBox* m_dump_peer_cert_checkbox; QCheckBox* m_verify_certificates_checkbox; + QCheckBox* m_dump_bba_checkbox; QPushButton* m_open_dump_folder; };