aboutsummaryrefslogtreecommitdiff
path: root/src/DSi_NWifi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DSi_NWifi.cpp')
-rw-r--r--src/DSi_NWifi.cpp105
1 files changed, 54 insertions, 51 deletions
diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp
index 7f8be83..b07d7a7 100644
--- a/src/DSi_NWifi.cpp
+++ b/src/DSi_NWifi.cpp
@@ -24,6 +24,9 @@
#include "WifiAP.h"
#include "Platform.h"
+using Platform::Log;
+using Platform::LogLevel;
+
const u8 CIS0[256] =
{
@@ -161,7 +164,7 @@ void DSi_NWifi::Reset()
Mailbox[i].Clear();
u8* mac = SPI_Firmware::GetWifiMAC();
- printf("NWifi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
+ Log(LogLevel::Info, "NWifi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
u8 type = SPI_Firmware::GetNWifiVersion();
@@ -183,11 +186,11 @@ void DSi_NWifi::Reset()
ROMID = 0x2300006F;
ChipID = 0x0D000001;
HostIntAddr = 0x00520000;
- printf("NWifi: hardware is 3DS type, unchecked\n");
+ Log(LogLevel::Info, "NWifi: hardware is 3DS type, unchecked\n");
break;
default:
- printf("NWifi: unknown hardware type, assuming AR6002\n");
+ Log(LogLevel::Warn, "NWifi: unknown hardware type, assuming AR6002\n");
ROMID = 0x20000188;
ChipID = 0x02000001;
HostIntAddr = 0x00500400;
@@ -353,7 +356,7 @@ u8 DSi_NWifi::F0_Read(u32 addr)
return CIS1[addr & 0xFF];
}
- printf("NWIFI: unknown func0 read %05X\n", addr);
+ Log(LogLevel::Warn, "NWIFI: unknown func0 read %05X\n", addr);
return 0;
}
@@ -367,7 +370,7 @@ void DSi_NWifi::F0_Write(u32 addr, u8 val)
return;
}
- printf("NWIFI: unknown func0 write %05X %02X\n", addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown func0 write %05X %02X\n", addr, val);
}
@@ -480,7 +483,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
{
if (addr < 0x100)
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0xFF) HandleCommand();
UpdateIRQ_F1();
@@ -488,21 +491,21 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x200)
{
- if (Mailbox[1].IsFull()) printf("!!! NWIFI: MBOX1 FULL\n");
+ if (Mailbox[1].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX1 FULL\n");
Mailbox[1].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x300)
{
- if (Mailbox[2].IsFull()) printf("!!! NWIFI: MBOX2 FULL\n");
+ if (Mailbox[2].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX2 FULL\n");
Mailbox[2].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x400)
{
- if (Mailbox[3].IsFull()) printf("!!! NWIFI: MBOX3 FULL\n");
+ if (Mailbox[3].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX3 FULL\n");
Mailbox[3].Write(val);
UpdateIRQ_F1();
return;
@@ -543,7 +546,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x1000)
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0xFFF) HandleCommand();
UpdateIRQ_F1();
@@ -551,35 +554,35 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val)
}
else if (addr < 0x1800)
{
- if (Mailbox[1].IsFull()) printf("!!! NWIFI: MBOX1 FULL\n");
+ if (Mailbox[1].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX1 FULL\n");
Mailbox[1].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x2000)
{
- if (Mailbox[2].IsFull()) printf("!!! NWIFI: MBOX2 FULL\n");
+ if (Mailbox[2].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX2 FULL\n");
Mailbox[2].Write(val);
UpdateIRQ_F1();
return;
}
else if (addr < 0x2800)
{
- if (Mailbox[3].IsFull()) printf("!!! NWIFI: MBOX3 FULL\n");
+ if (Mailbox[3].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX3 FULL\n");
Mailbox[3].Write(val);
UpdateIRQ_F1();
return;
}
else
{
- if (Mailbox[0].IsFull()) printf("!!! NWIFI: MBOX0 FULL\n");
+ if (Mailbox[0].IsFull()) Log(LogLevel::Debug, "!!! NWIFI: MBOX0 FULL\n");
Mailbox[0].Write(val);
if (addr == 0x3FFF) HandleCommand(); // CHECKME
UpdateIRQ_F1();
return;
}
- printf("NWIFI: unknown func1 write %05X %02X\n", addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown func1 write %05X %02X\n", addr, val);
}
@@ -591,7 +594,7 @@ u8 DSi_NWifi::SDIO_Read(u32 func, u32 addr)
case 1: return F1_Read(addr);
}
- printf("NWIFI: unknown SDIO read %d %05X\n", func, addr);
+ Log(LogLevel::Warn, "NWIFI: unknown SDIO read %d %05X\n", func, addr);
return 0;
}
@@ -603,7 +606,7 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val)
case 1: return F1_Write(addr, val);
}
- printf("NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val);
+ Log(LogLevel::Warn, "NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val);
}
@@ -676,12 +679,12 @@ void DSi_NWifi::SendCMD(u8 cmd, u32 param)
return;
}
- printf("NWIFI: unknown CMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "NWIFI: unknown CMD %d %08X\n", cmd, param);
}
void DSi_NWifi::SendACMD(u8 cmd, u32 param)
{
- printf("NWIFI: unknown ACMD %d %08X\n", cmd, param);
+ Log(LogLevel::Warn, "NWIFI: unknown ACMD %d %08X\n", cmd, param);
}
void DSi_NWifi::ContinueTransfer()
@@ -772,7 +775,7 @@ void DSi_NWifi::BMI_Command()
{
case 0x01: // BMI_DONE
{
- printf("BMI_DONE\n");
+ Log(LogLevel::Debug, "BMI_DONE\n");
EEPROMReady = 1; // GROSS FUCKING HACK
u8 ready_msg[6] = {0x0A, 0x00, 0x08, 0x06, 0x16, 0x00};
SendWMIEvent(0, 0x0001, ready_msg, 6);
@@ -784,7 +787,7 @@ void DSi_NWifi::BMI_Command()
{
u32 addr = MB_Read32(0);
u32 len = MB_Read32(0);
- printf("BMI mem write %08X %08X\n", addr, len);
+ Log(LogLevel::Debug, "BMI mem write %08X %08X\n", addr, len);
for (u32 i = 0; i < len; i++)
{
@@ -800,7 +803,7 @@ void DSi_NWifi::BMI_Command()
u32 entry = MB_Read32(0);
u32 arg = MB_Read32(0);
- printf("BMI_EXECUTE %08X %08X\n", entry, arg);
+ Log(LogLevel::Debug, "BMI_EXECUTE %08X %08X\n", entry, arg);
}
return;
@@ -830,14 +833,14 @@ void DSi_NWifi::BMI_Command()
case 0x0D: // BMI_LZ_STREAM_START
{
u32 addr = MB_Read32(0);
- printf("BMI_LZ_STREAM_START %08X\n", addr);
+ Log(LogLevel::Debug, "BMI_LZ_STREAM_START %08X\n", addr);
}
return;
case 0x0E: // BMI_LZ_DATA
{
u32 len = MB_Read32(0);
- printf("BMI LZ write %08X\n", len);
+ Log(LogLevel::Debug, "BMI LZ write %08X\n", len);
//FILE* f = fopen("debug/wififirm.bin", "ab");
for (u32 i = 0; i < len; i++)
@@ -852,7 +855,7 @@ void DSi_NWifi::BMI_Command()
return;
default:
- printf("unknown BMI command %08X\n", cmd);
+ Log(LogLevel::Warn, "unknown BMI command %08X\n", cmd);
return;
}
}
@@ -871,7 +874,7 @@ void DSi_NWifi::HTC_Command()
{
u16 svc_id = MB_Read16(0);
u16 conn_flags = MB_Read16(0);
- printf("service connect %04X %04X %04X\n", svc_id, conn_flags, MB_Read16(0));
+ Log(LogLevel::Info, "service connect %04X %04X %04X\n", svc_id, conn_flags, MB_Read16(0));
u8 svc_resp[8];
// responses from hardware:
@@ -908,7 +911,7 @@ void DSi_NWifi::HTC_Command()
break;
default:
- printf("unknown HTC command %04X\n", cmd);
+ Log(LogLevel::Warn, "unknown HTC command %04X\n", cmd);
for (int i = 0; i < len; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -947,9 +950,9 @@ void DSi_NWifi::WMI_Command()
case 0x0003: // disconnect
{
if (ConnectionStatus != 1)
- printf("WMI: ?? trying to disconnect while not connected\n");
+ Log(LogLevel::Warn, "WMI: ?? trying to disconnect while not connected\n");
- printf("WMI: disconnect\n");
+ Log(LogLevel::Info, "WMI: disconnect\n");
ConnectionStatus = 0;
u8 reply[11];
@@ -985,12 +988,12 @@ void DSi_NWifi::WMI_Command()
u8 scantype = Mailbox[0].Read();
u8 nchannels = Mailbox[0].Read();
- printf("WMI: start scan, forceFG=%d, legacy=%d, scanTime=%d, interval=%d, scanType=%d, chan=%d\n",
+ Log(LogLevel::Debug, "WMI: start scan, forceFG=%d, legacy=%d, scanTime=%d, interval=%d, scanType=%d, chan=%d\n",
forcefg, legacy, scantime, forceinterval, scantype, nchannels);
if (ScanTimer > 0)
{
- printf("!! CHECKME: START SCAN BUT WAS ALREADY SCANNING (%d)\n", ScanTimer);
+ Log(LogLevel::Debug, "!! CHECKME: START SCAN BUT WAS ALREADY SCANNING (%d)\n", ScanTimer);
}
// checkme
@@ -1013,7 +1016,7 @@ void DSi_NWifi::WMI_Command()
Mailbox[0].Read();
u32 iemask = MB_Read32(0);
- printf("WMI: set BSS filter, filter=%02X, iemask=%08X\n", bssfilter, iemask);
+ Log(LogLevel::Debug, "WMI: set BSS filter, filter=%02X, iemask=%08X\n", bssfilter, iemask);
}
break;
@@ -1028,7 +1031,7 @@ void DSi_NWifi::WMI_Command()
ssid[i] = Mailbox[0].Read();
// TODO: store it somewhere
- printf("WMI: set probed SSID: id=%d, flags=%02X, len=%d, SSID=%s\n", id, flags, len, ssid);
+ Log(LogLevel::Debug, "WMI: set probed SSID: id=%d, flags=%02X, len=%d, SSID=%s\n", id, flags, len, ssid);
}
break;
@@ -1066,7 +1069,7 @@ void DSi_NWifi::WMI_Command()
channels[i] = MB_Read16(0);
// TODO: store it somewhere
- printf("WMI: set channel params: scan=%d, phymode=%d, len=%d, channels=", scan, phymode, len);
+ Log(LogLevel::Debug, "WMI: set channel params: scan=%d, phymode=%d, len=%d, channels=", scan, phymode, len);
for (int i = 0; i < len && i < 32; i++)
printf("%d,", channels[i]);
printf("\n");
@@ -1110,7 +1113,7 @@ void DSi_NWifi::WMI_Command()
break;
default:
- printf("WMI: unknown ext cmd 002E:%04X\n", extcmd);
+ Log(LogLevel::Warn, "WMI: unknown ext cmd 002E:%04X\n", extcmd);
break;
}
}
@@ -1161,7 +1164,7 @@ void DSi_NWifi::WMI_Command()
break;
default:
- printf("unknown WMI command %04X (header: %04X:%04X:%04X)\n", cmd, h0, len, h2);
+ Log(LogLevel::Warn, "unknown WMI command %04X (header: %04X:%04X:%04X)\n", cmd, h0, len, h2);
for (int i = 0; i < len-2; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -1210,12 +1213,12 @@ void DSi_NWifi::WMI_ConnectToNetwork()
(gCryptoType != 0x01) ||
(memcmp(bssid, WifiAP::APMac, 6)))
{
- printf("WMI_Connect: bad parameters\n");
+ Log(LogLevel::Error, "WMI_Connect: bad parameters\n");
// TODO: send disconnect??
return;
}
- printf("WMI: connecting to network %s\n", ssid);
+ Log(LogLevel::Info, "WMI: connecting to network %s\n", ssid);
u8 reply[20];
@@ -1240,7 +1243,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
{
if (ConnectionStatus != 1)
{
- printf("WMI: !! trying to send shit while not connected\n");
+ Log(LogLevel::Warn, "WMI: !! trying to send shit while not connected\n");
// TODO: report error??
return;
}
@@ -1255,7 +1258,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (type == 2) // data sync
{
- printf("WMI: data sync\n");
+ Log(LogLevel::Debug, "WMI: data sync\n");
/*Mailbox[8].Write(2); // eid
Mailbox[8].Write(0x00); // flags
@@ -1270,7 +1273,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (type)
{
- printf("WMI: special frame %04X len=%d\n", hdr, len);
+ Log(LogLevel::Debug, "WMI: special frame %04X len=%d\n", hdr, len);
for (int i = 0; i < len-2; i++)
{
printf("%02X ", Mailbox[0].Read());
@@ -1280,7 +1283,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
return;
}
- printf("WMI: send packet, hdr=%04X, len=%d\n", hdr, len);
+ Log(LogLevel::Debug, "WMI: send packet, hdr=%04X, len=%d\n", hdr, len);
u8 dstmac[6];
u8 srcmac[6];
@@ -1295,7 +1298,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (plen > len-16)
{
- printf("WMI: bad packet length %d > %d\n", plen, len-16);
+ Log(LogLevel::Error, "WMI: bad packet length %d > %d\n", plen, len-16);
return;
}
@@ -1304,7 +1307,7 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
if (h0 != 0x0003AAAA || h1 != 0x0000)
{
- printf("WMI: bad LLC/SLIP header\n");
+ Log(LogLevel::Error, "WMI: bad LLC/SLIP header\n");
return;
}
@@ -1334,7 +1337,7 @@ void DSi_NWifi::SendWMIEvent(u8 ep, u16 id, u8* data, u32 len)
{
if (!Mailbox[8].CanFit(6+len+2+8))
{
- printf("NWifi: !! not enough space in RX buffer for WMI event %04X\n", id);
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI event %04X\n", id);
return;
}
@@ -1367,7 +1370,7 @@ void DSi_NWifi::SendWMIAck(u8 ep)
{
if (!Mailbox[8].CanFit(6+12))
{
- printf("NWifi: !! not enough space in RX buffer for WMI ack (ep #%d)\n", ep);
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI ack (ep #%d)\n", ep);
return;
}
@@ -1400,7 +1403,7 @@ void DSi_NWifi::SendWMIBSSInfo(u8 type, u8* data, u32 len)
{
if (!Mailbox[8].CanFit(6+len+2+16))
{
- printf("NWifi: !! not enough space in RX buffer for WMI BSSINFO event\n");
+ Log(LogLevel::Error, "NWifi: !! not enough space in RX buffer for WMI BSSINFO event\n");
return;
}
@@ -1452,7 +1455,7 @@ void DSi_NWifi::CheckRX()
// packet is good
- printf("WMI: receive packet %04X, len=%d\n", *(u16*)&LANBuffer[12], rxlen);
+ Log(LogLevel::Debug, "WMI: receive packet %04X, len=%d\n", *(u16*)&LANBuffer[12], rxlen);
/*for (int i = 0; i < rxlen; i++)
{
@@ -1501,7 +1504,7 @@ void DSi_NWifi::CheckRX()
u32 DSi_NWifi::WindowRead(u32 addr)
{
- printf("NWifi: window read %08X\n", addr);
+ Log(LogLevel::Debug, "NWifi: window read %08X\n", addr);
if ((addr & 0xFFFF00) == HostIntAddr)
{
@@ -1540,7 +1543,7 @@ u32 DSi_NWifi::WindowRead(u32 addr)
void DSi_NWifi::WindowWrite(u32 addr, u32 val)
{
- printf("NWifi: window write %08X %08X\n", addr, val);
+ Log(LogLevel::Debug, "NWifi: window write %08X %08X\n", addr, val);
}
@@ -1567,7 +1570,7 @@ void DSi_NWifi::_MSTimer()
};
SendWMIBSSInfo(0x01, beacon, sizeof(beacon));
- printf("send beacon\n");
+ Log(LogLevel::Debug, "send beacon\n");
}
if (ScanTimer == 0)