(untested yet) code for sending and receiving packets via sockets
MAC randomization
This commit is contained in:
parent
e9a24b4d06
commit
01361f006e
|
@ -26,6 +26,8 @@ namespace Platform
|
|||
|
||||
bool MP_Init();
|
||||
void MP_DeInit();
|
||||
int MP_SendPacket(u8* data, int len, int rate);
|
||||
int MP_RecvPacket(u8* data, bool block, int* rate);
|
||||
|
||||
}
|
||||
|
||||
|
|
16
src/SPI.cpp
16
src/SPI.cpp
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "NDS.h"
|
||||
#include "SPI.h"
|
||||
|
||||
|
@ -138,6 +139,21 @@ void Reset()
|
|||
|
||||
*(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF);
|
||||
|
||||
// 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;
|
||||
|
||||
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");
|
||||
|
|
|
@ -48,6 +48,9 @@ namespace Platform
|
|||
|
||||
socket_t MPSocket;
|
||||
sockaddr_t MPSendAddr;
|
||||
u8 PacketBuffer[2048];
|
||||
|
||||
#define NIFI_VER 1
|
||||
|
||||
|
||||
bool MP_Init()
|
||||
|
@ -114,5 +117,73 @@ void MP_DeInit()
|
|||
#endif // __WXMSW__
|
||||
}
|
||||
|
||||
int MP_SendPacket(u8* data, int len, int rate)
|
||||
{
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
|
||||
if (len > 2048-8)
|
||||
{
|
||||
printf("MP_SendPacket: error: packet too long (%d)\n", len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI
|
||||
PacketBuffer[4] = NIFI_VER;
|
||||
PacketBuffer[5] = rate & 0xFF;
|
||||
*(u16*)&PacketBuffer[6] = htons(len);
|
||||
memcpy(&PacketBuffer[8], data, len);
|
||||
|
||||
return sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t));
|
||||
}
|
||||
|
||||
int MP_RecvPacket(u8* data, bool block, int* rate)
|
||||
{
|
||||
if (MPSocket < 0)
|
||||
return 0;
|
||||
|
||||
fd_set fd;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&fd);
|
||||
FD_SET(MPSocket, &fd);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
if (!select(1, &fd, 0, 0, &tv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
sockaddr_t fromAddr;
|
||||
socklen_t fromLen = sizeof(sockaddr_t);
|
||||
int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen);
|
||||
if (rlen < 8+24)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
rlen -= 8;
|
||||
|
||||
if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PacketBuffer[4] != NIFI_VER)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
rlen -= 8;
|
||||
if (ntohs(*(u16*)&PacketBuffer[6]) != rlen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(data, &PacketBuffer[8], rlen);
|
||||
if (rate) *rate = PacketBuffer[5];
|
||||
return rlen;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue