fix slirp crash when exiting without having inited slirp
also fix misc bugs
This commit is contained in:
parent
1101ed773b
commit
91ff63a194
|
@ -1211,9 +1211,16 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
|
|||
}
|
||||
|
||||
u16 hdr = MB_Read16(0);
|
||||
if (hdr != 0x0000)
|
||||
hdr = ((hdr & 0xFF00) >> 8) | ((hdr & 0x00FF) << 8);
|
||||
if (hdr & 0x0003)
|
||||
{
|
||||
printf("WMI: special frame %04X\n", hdr);
|
||||
printf("WMI: special frame %04X len=%d\n", hdr, len);
|
||||
for (int i = 0; i < len-2; i++)
|
||||
{
|
||||
printf("%02X ", Mailbox[0]->Read());
|
||||
if ((i&0xF)==0xF) printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1252,11 +1259,18 @@ void DSi_NWifi::WMI_SendPacket(u16 len)
|
|||
memcpy(&LANBuffer[0], dstmac, 6); // destination MAC
|
||||
memcpy(&LANBuffer[6], srcmac, 6); // source MAC
|
||||
*(u16*)&LANBuffer[12] = ethertype; // type
|
||||
for (int i = 0; i < lan_len; i++)
|
||||
for (int i = 0; i < lan_len-14; i++)
|
||||
{
|
||||
LANBuffer[14+i] = Mailbox[0]->Read();
|
||||
}
|
||||
|
||||
for (int i = 0; i < lan_len; i++)
|
||||
{
|
||||
printf("%02X ", LANBuffer[i]);
|
||||
if ((i&0xF)==0xF) printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
Platform::LAN_SendPacket(LANBuffer, lan_len);
|
||||
}
|
||||
|
||||
|
@ -1373,6 +1387,7 @@ void DSi_NWifi::CheckRX()
|
|||
int rxlen = Platform::LAN_RecvPacket(LANBuffer);
|
||||
if (rxlen > 0)
|
||||
{
|
||||
printf("WMI packet recv %04X %04X %04X\n", *(u16*)&LANBuffer[0], *(u16*)&LANBuffer[2], *(u16*)&LANBuffer[4]);
|
||||
// check destination MAC
|
||||
if (*(u32*)&LANBuffer[0] != 0xFFFFFFFF || *(u16*)&LANBuffer[4] != 0xFFFF)
|
||||
{
|
||||
|
@ -1380,6 +1395,10 @@ void DSi_NWifi::CheckRX()
|
|||
return;
|
||||
}
|
||||
|
||||
// check source MAC, in case we get a packet we just sent out
|
||||
if (!memcmp(&LANBuffer[6], &EEPROM[0x00A], 6))
|
||||
return;
|
||||
|
||||
// packet is good
|
||||
|
||||
printf("WMI: receive packet %04X, len=%d\n", *(u16*)&LANBuffer[12], rxlen);
|
||||
|
|
|
@ -52,7 +52,7 @@ volatile int RXNum;
|
|||
|
||||
u32 IPv4ID;
|
||||
|
||||
Slirp* Ctx;
|
||||
Slirp* Ctx = nullptr;
|
||||
|
||||
const int FDListMax = 64;
|
||||
struct pollfd FDList[FDListMax];
|
||||
|
@ -164,6 +164,7 @@ void SlirpCbUnregisterPollFD(int fd, void* opaque)
|
|||
|
||||
void SlirpCbNotify(void* opaque)
|
||||
{
|
||||
printf("Slirp: notify???\n");
|
||||
}
|
||||
|
||||
SlirpCb cb =
|
||||
|
@ -205,7 +206,11 @@ bool Init()
|
|||
|
||||
void DeInit()
|
||||
{
|
||||
slirp_cleanup(Ctx);
|
||||
if (Ctx)
|
||||
{
|
||||
slirp_cleanup(Ctx);
|
||||
Ctx = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -411,6 +416,8 @@ void HandleDNSFrame(u8* data, int len)
|
|||
|
||||
int SendPacket(u8* data, int len)
|
||||
{
|
||||
if (!Ctx) return 0;
|
||||
|
||||
if (len > 2048)
|
||||
{
|
||||
printf("LAN_SendPacket: error: packet too long (%d)\n", len);
|
||||
|
@ -496,6 +503,8 @@ int SlirpCbGetREvents(int idx, void* opaque)
|
|||
|
||||
int RecvPacket(u8* data)
|
||||
{
|
||||
if (!Ctx) return 0;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (FDListSize > 0)
|
||||
|
|
Loading…
Reference in New Issue