diff options
-rw-r--r-- | src/libui_sdl/DlgWifiSettings.cpp | 24 | ||||
-rw-r--r-- | src/libui_sdl/LAN_PCap.cpp | 2 | ||||
-rw-r--r-- | src/libui_sdl/LAN_Socket.cpp | 81 |
3 files changed, 46 insertions, 61 deletions
diff --git a/src/libui_sdl/DlgWifiSettings.cpp b/src/libui_sdl/DlgWifiSettings.cpp index 4874c98..af27463 100644 --- a/src/libui_sdl/DlgWifiSettings.cpp +++ b/src/libui_sdl/DlgWifiSettings.cpp @@ -25,7 +25,8 @@ #include "../types.h" #include "../Config.h" -#include "LAN.h" +#include "LAN_Socket.h" +#include "LAN_PCap.h" #include "DlgWifiSettings.h" @@ -38,6 +39,8 @@ namespace DlgWifiSettings bool opened; uiWindow* win; +bool haspcap; + uiCheckbox* cbBindAnyAddr; uiCombobox* cmAdapterList; @@ -52,10 +55,10 @@ uiLabel* lbAdapterDNS1; void UpdateAdapterInfo() { int sel = uiComboboxSelected(cmAdapterList); - if (sel < 0 || sel >= LAN::NumAdapters) return; - if (LAN::NumAdapters < 1) return; + if (sel < 0 || sel >= LAN_PCap::NumAdapters) return; + if (LAN_PCap::NumAdapters < 1) return; - LAN::AdapterData* adapter = &LAN::Adapters[sel]; + LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[sel]; char tmp[64]; sprintf(tmp, "MAC: %02X:%02X:%02X:%02X:%02X:%02X", @@ -102,14 +105,14 @@ void OnOk(uiButton* btn, void* blarg) Config::DirectLAN = uiCheckboxChecked(cbDirectLAN); int sel = uiComboboxSelected(cmAdapterList); - if (sel < 0 || sel >= LAN::NumAdapters) sel = 0; - if (LAN::NumAdapters < 1) + if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; + if (LAN_PCap::NumAdapters < 1) { Config::LANDevice[0] = '\0'; } else { - strncpy(Config::LANDevice, LAN::Adapters[sel].DeviceName, 127); + strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); Config::LANDevice[127] = '\0'; } @@ -129,7 +132,8 @@ void Open() return; } - LAN::Init(); + LAN_Socket::Init(); + haspcap = LAN_PCap::Init(); opened = true; win = uiNewWindow("Wifi settings - melonDS", 400, 100, 0, 0, 0); @@ -202,9 +206,9 @@ void Open() uiCheckboxSetChecked(cbBindAnyAddr, Config::SocketBindAnyAddr); int sel = 0; - for (int i = 0; i < LAN::NumAdapters; i++) + for (int i = 0; i < LAN_PCap::NumAdapters; i++) { - LAN::AdapterData* adapter = &LAN::Adapters[i]; + LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[i]; uiComboboxAppend(cmAdapterList, adapter->FriendlyName); diff --git a/src/libui_sdl/LAN_PCap.cpp b/src/libui_sdl/LAN_PCap.cpp index 9928ce9..ca3e03a 100644 --- a/src/libui_sdl/LAN_PCap.cpp +++ b/src/libui_sdl/LAN_PCap.cpp @@ -303,7 +303,7 @@ void DeInit() void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data) { - while (PCapRXNum > 0); + while (RXNum > 0); if (header->len > 2048-64) return; diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp index fdb7421..71a38c5 100644 --- a/src/libui_sdl/LAN_Socket.cpp +++ b/src/libui_sdl/LAN_Socket.cpp @@ -96,13 +96,13 @@ void DeInit() // } -bool HandleIncomingIPFrame(u8* data, int len) +/*bool HandleIncomingIPFrame(u8* data, int len) { const u32 serverip = 0x0A404001; const u32 clientip = 0x0A404010; - if (memcmp(&data[0x1E], PCapAdapterData->IP_v4, 4)) - return false; + //if (memcmp(&data[0x1E], PCapAdapterData->IP_v4, 4)) + // return false; u8 protocol = data[0x17]; @@ -193,9 +193,9 @@ bool HandleIncomingIPFrame(u8* data, int len) } return false; -} +}*/ -void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data) +/*void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data) { while (PCapRXNum > 0); @@ -215,8 +215,8 @@ void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* d PCapRXNum = 0; } } -} -u32 zarp=0; +}*/ + bool HandleDHCPFrame(u8* data, int len) { const u32 serverip = 0x0A404001; @@ -225,7 +225,7 @@ bool HandleDHCPFrame(u8* data, int len) u8 type = 0xFF; u32 transid = *(u32*)&data[0x2E]; -zarp=transid; + u8* options = &data[0x11A]; for (;;) { @@ -322,7 +322,7 @@ zarp=transid; *out++ = 54; *out++ = 4; *(u32*)out = htonl(serverip); out += 4; // DHCP server - u8 numdns = 0; + /*u8 numdns = 0; for (int i = 0; i < 8; i++) { if (*(u32*)&PCapAdapterData->DNS[i][0] != 0) @@ -336,7 +336,9 @@ zarp=transid; { *(u32*)out = dnsip; out += 4; } - } + }*/ + *out++ = 6; *out++ = 4; + *(u32*)out = htonl(0x08080808); out += 4; // DNS (hax) *out++ = 0xFF; memset(out, 0, 20); out += 20; @@ -378,13 +380,9 @@ zarp=transid; // that being said, this will only happen during DHCP setup, so probably // not a big deal - PCapPacketLen = framelen; - memcpy(PCapPacketBuffer, resp, PCapPacketLen); - PCapRXNum = 1; - - // DEBUG!! - //pcap_sendpacket(PCapAdapter, data, len); - //pcap_sendpacket(PCapAdapter, resp, framelen); + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; return true; } @@ -397,9 +395,6 @@ bool HandleIPFrame(u8* data, int len) const u32 serverip = 0x0A404001; const u32 clientip = 0x0A404010; - // debug - //pcap_sendpacket(PCapAdapter, data, len); - u8 protocol = data[0x17]; // any kind of IPv4 frame that isn't DHCP @@ -410,10 +405,10 @@ bool HandleIPFrame(u8* data, int len) // destination MAC set to host MAC // source MAC set to melonRouter MAC - memcpy(&data[0], &PCapAdapterData->DHCP_MAC[0], 6); - memcpy(&data[6], &PCapAdapterData->MAC[0], 6); + //memcpy(&data[0], &PCapAdapterData->DHCP_MAC[0], 6); + //memcpy(&data[6], &PCapAdapterData->MAC[0], 6); - *(u32*)&data[0x1A] = *(u32*)&PCapAdapterData->IP_v4[0]; + //*(u32*)&data[0x1A] = *(u32*)&PCapAdapterData->IP_v4[0]; u8* ipheader = &data[0xE]; u8* protoheader = &data[0x22]; @@ -600,13 +595,9 @@ bool HandleARPFrame(u8* data, int len) // that being said, this will only happen during DHCP setup, so probably // not a big deal - PCapPacketLen = framelen; - memcpy(PCapPacketBuffer, resp, PCapPacketLen); - PCapRXNum = 1; - - // also broadcast them to the network - pcap_sendpacket(PCapAdapter, data, len); - pcap_sendpacket(PCapAdapter, resp, framelen); + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; return true; } @@ -632,12 +623,12 @@ bool HandlePacket(u8* data, int len) } } - printf("LANMAGIC: IP frame, doing NAT\n"); + printf("LANMAGIC: IP packet\n"); return HandleIPFrame(data, len); } else if (ethertype == 0x0806) // ARP { - printf("LANMAGIC: ARP\n"); + printf("LANMAGIC: ARP packet\n"); return HandleARPFrame(data, len); } @@ -646,40 +637,30 @@ bool HandlePacket(u8* data, int len) int SendPacket(u8* data, int len) { - if (PCapAdapter == NULL) - return 0; - if (len > 2048) { printf("LAN_SendPacket: error: packet too long (%d)\n", len); return 0; } - if (!Config::DirectLAN) - { - if (HandlePacket(data, len)) - return len; - } + // TODO: blarg + if (HandlePacket(data, len)) + return len; - pcap_sendpacket(PCapAdapter, data, len); - // TODO: check success return len; } int RecvPacket(u8* data) { - if (PCapAdapter == NULL) - return 0; - int ret = 0; - if (PCapRXNum > 0) + if (RXNum > 0) { - memcpy(data, PCapPacketBuffer, PCapPacketLen); - ret = PCapPacketLen; - PCapRXNum = 0; + memcpy(data, PacketBuffer, PacketLen); + ret = PacketLen; + RXNum = 0; } - pcap_dispatch(PCapAdapter, 1, RXCallback, NULL); + // TODO: check sockets return ret; } |