diff options
author | Arisotura <thetotalworm@gmail.com> | 2020-08-24 19:19:41 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2020-08-24 19:19:41 +0200 |
commit | abccc44eecb943720993c5d3e89234f435770aee (patch) | |
tree | ab111d1b32b2276a56f723415b2733a8a0b29ea4 /src | |
parent | c29e6303140af7aa7744d4bc4650399e286a3ac1 (diff) |
make MAC randomization optional
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.cpp | 2 | ||||
-rw-r--r-- | src/Config.h | 2 | ||||
-rw-r--r-- | src/SPI.cpp | 25 | ||||
-rw-r--r-- | src/frontend/qt_sdl/WifiSettingsDialog.cpp | 59 | ||||
-rw-r--r-- | src/frontend/qt_sdl/WifiSettingsDialog.h | 7 | ||||
-rw-r--r-- | src/frontend/qt_sdl/WifiSettingsDialog.ui | 12 | ||||
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 7 |
7 files changed, 77 insertions, 37 deletions
diff --git a/src/Config.cpp b/src/Config.cpp index d198093..2a98935 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -56,6 +56,8 @@ ConfigEntry ConfigFile[] = {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"RandomizeMAC", 0, &RandomizeMAC, 0, NULL, 0}, + #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index 5916b4a..a0f09dc 100644 --- a/src/Config.h +++ b/src/Config.h @@ -51,6 +51,8 @@ extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +extern int RandomizeMAC; + #ifdef JIT_ENABLED extern int JIT_Enable; extern int JIT_MaxBlockSize; diff --git a/src/SPI.cpp b/src/SPI.cpp index 1c88b58..2ba5e66 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -179,24 +179,25 @@ void Reset() //Firmware[userdata+0x64] &= 0xBF; *(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF); + + if (Config::RandomizeMAC) + { + // replace MAC address with random address + Firmware[0x36] = 0x00; + Firmware[0x37] = 0x09; + Firmware[0x38] = 0xBF; + Firmware[0x39] = rand()&0xFF; + Firmware[0x3A] = rand()&0xFF; + Firmware[0x3B] = rand()&0xFF; + + *(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); + } } -#if 0 - // replace MAC address with random address - // TODO: make optional? - Firmware[0x36] = 0x00; - Firmware[0x37] = 0x09; - Firmware[0x38] = 0xBF; - Firmware[0x39] = rand()&0xFF; - Firmware[0x3A] = rand()&0xFF; - Firmware[0x3B] = rand()&0xFF; -#endif printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", Firmware[0x36], Firmware[0x37], Firmware[0x38], Firmware[0x39], Firmware[0x3A], Firmware[0x3B]); - //*(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); - // verify shit printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD"); printf("FW: AP1 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FA00&FirmwareMask, 0xFE, 0x7FAFE&FirmwareMask)?"GOOD":"BAD"); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.cpp b/src/frontend/qt_sdl/WifiSettingsDialog.cpp index 457a78d..67297ad 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.cpp +++ b/src/frontend/qt_sdl/WifiSettingsDialog.cpp @@ -17,7 +17,7 @@ */ #include <stdio.h> -#include <QFileDialog> +#include <QMessageBox> #include "types.h" #include "Platform.h" @@ -41,6 +41,10 @@ WifiSettingsDialog* WifiSettingsDialog::currentDlg = nullptr; +bool WifiSettingsDialog::needsReset = false; + +extern bool RunningSomething; + WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::WifiSettingsDialog) { @@ -53,6 +57,7 @@ WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(ne ui->cbDirectMode->setText("Direct mode (requires " PCAP_NAME " and ethernet connection)"); ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr != 0); + ui->cbRandomizeMAC->setChecked(Config::RandomizeMAC != 0); int sel = 0; for (int i = 0; i < LAN_PCap::NumAdapters; i++) @@ -77,33 +82,49 @@ WifiSettingsDialog::~WifiSettingsDialog() delete ui; } -void WifiSettingsDialog::on_WifiSettingsDialog_accepted() +void WifiSettingsDialog::done(int r) { - Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; - Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0; + needsReset = false; - int sel = ui->cbxDirectAdapter->currentIndex(); - if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; - if (LAN_PCap::NumAdapters < 1) - { - Config::LANDevice[0] = '\0'; - } - else + if (r == QDialog::Accepted) { - strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); - Config::LANDevice[127] = '\0'; + int randommac = ui->cbRandomizeMAC->isChecked() ? 1:0; + + if (randommac != Config::RandomizeMAC) + { + if (RunningSomething + && QMessageBox::warning(this, "Reset necessary to apply changes", + "The emulation will be reset for the changes to take place.", + QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) + return; + } + + Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; + Config::RandomizeMAC = randommac; + Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0; + + int sel = ui->cbxDirectAdapter->currentIndex(); + if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; + if (LAN_PCap::NumAdapters < 1) + { + Config::LANDevice[0] = '\0'; + } + else + { + strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); + Config::LANDevice[127] = '\0'; + } + + Config::Save(); + + needsReset = true; } - Config::Save(); + QDialog::done(r); closeDlg(); } -void WifiSettingsDialog::on_WifiSettingsDialog_rejected() -{ - closeDlg(); -} - void WifiSettingsDialog::on_cbDirectMode_stateChanged(int state) { updateAdapterControls(); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.h b/src/frontend/qt_sdl/WifiSettingsDialog.h index f8aad1b..6c1f863 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.h +++ b/src/frontend/qt_sdl/WifiSettingsDialog.h @@ -42,7 +42,7 @@ public: } currentDlg = new WifiSettingsDialog(parent); - currentDlg->show(); + currentDlg->open(); return currentDlg; } static void closeDlg() @@ -50,9 +50,10 @@ public: currentDlg = nullptr; } + static bool needsReset; + private slots: - void on_WifiSettingsDialog_accepted(); - void on_WifiSettingsDialog_rejected(); + void done(int r); void on_cbDirectMode_stateChanged(int state); void on_cbxDirectAdapter_currentIndexChanged(int sel); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.ui b/src/frontend/qt_sdl/WifiSettingsDialog.ui index bfee1fd..6668d88 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.ui +++ b/src/frontend/qt_sdl/WifiSettingsDialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>479</width> - <height>217</height> + <height>240</height> </rect> </property> <property name="sizePolicy"> @@ -39,6 +39,16 @@ </property> </widget> </item> + <item row="1" column="0"> + <widget class="QCheckBox" name="cbRandomizeMAC"> + <property name="whatsThis"> + <string><html><head/><body><p>Randomizes the console's MAC address upon reset. Required for local multiplayer if each melonDS instance uses the same firmware file.</p></body></html></string> + </property> + <property name="text"> + <string>Randomize MAC address</string> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index f91f879..0228399 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1747,14 +1747,14 @@ void MainWindow::onAudioSettingsFinished(int res) void MainWindow::onOpenWifiSettings() { + emuThread->emuPause(); + WifiSettingsDialog* dlg = WifiSettingsDialog::openDlg(this); connect(dlg, &WifiSettingsDialog::finished, this, &MainWindow::onWifiSettingsFinished); } void MainWindow::onWifiSettingsFinished(int res) { - emuThread->emuPause(); - if (Wifi::MPInited) { Platform::MP_DeInit(); @@ -1764,6 +1764,9 @@ void MainWindow::onWifiSettingsFinished(int res) Platform::LAN_DeInit(); Platform::LAN_Init(); + if (WifiSettingsDialog::needsReset) + onReset(); + emuThread->emuUnpause(); } |