WiFi: The user no longer has to manually choose between using Ad-Hoc or Infrastructure modes. The code now automatically sends/receives packets to and from their proper places.
- This change obsoletes "CommonSettings.wifi.mode", which now does nothing. Ports that make use of this setting should remove it. - Also do a bunch of code refactoring and cleanup.
This commit is contained in:
parent
1e9aa08f54
commit
9d05935696
|
@ -89,9 +89,7 @@
|
||||||
{
|
{
|
||||||
if (theSelection == 0)
|
if (theSelection == 0)
|
||||||
{
|
{
|
||||||
//wifiHandler->SetFirmwareMACMode(FirmwareMACMode_ReadFromFirmware);
|
wifiHandler->SetFirmwareMACMode(FirmwareMACMode_ReadFromFirmware);
|
||||||
wifiHandler->SetMACModeForComm(WifiCommInterfaceID_AdHoc, WifiMACMode_ReadFromFirmware);
|
|
||||||
wifiHandler->SetMACModeForComm(WifiCommInterfaceID_Infrastructure, WifiMACMode_ReadFromFirmware);
|
|
||||||
}
|
}
|
||||||
else if ( (theSelection >= 1) && (theSelection <= 4) )
|
else if ( (theSelection >= 1) && (theSelection <= 4) )
|
||||||
{
|
{
|
||||||
|
@ -100,9 +98,7 @@
|
||||||
const uint8_t myMAC6 = (_myMACAddressValue >> 24) & 0x000000F0;
|
const uint8_t myMAC6 = (_myMACAddressValue >> 24) & 0x000000F0;
|
||||||
|
|
||||||
wifiHandler->SetUserMACValues(myMAC4, myMAC5, myMAC6 + theSelection);
|
wifiHandler->SetUserMACValues(myMAC4, myMAC5, myMAC6 + theSelection);
|
||||||
//wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual);
|
wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual);
|
||||||
wifiHandler->SetMACModeForComm(WifiCommInterfaceID_AdHoc, WifiMACMode_Manual);
|
|
||||||
wifiHandler->SetMACModeForComm(WifiCommInterfaceID_Infrastructure, WifiMACMode_Manual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addressSelection = theSelection;
|
addressSelection = theSelection;
|
||||||
|
|
|
@ -2273,11 +2273,9 @@ int _main()
|
||||||
hash &= 0x00FFFFFF;
|
hash &= 0x00FFFFFF;
|
||||||
|
|
||||||
wifiHandler->SetUserMACValues(hash >> 16, (hash >> 8) & 0xFF, hash & 0xFF);
|
wifiHandler->SetUserMACValues(hash >> 16, (hash >> 8) & 0xFF, hash & 0xFF);
|
||||||
wifiHandler->SetMACModeForComm(WifiCommInterfaceID_AdHoc, WifiMACMode_Manual);
|
wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual);
|
||||||
//wifiHandler->SetFirmwareMACMode(FirmwareMACMode_Manual);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wifiHandler->SetCommInterfaceID(CommonSettings.wifi.mode);
|
|
||||||
wifiHandler->SetBridgeDeviceIndex(CommonSettings.wifi.infraBridgeAdapter);
|
wifiHandler->SetBridgeDeviceIndex(CommonSettings.wifi.infraBridgeAdapter);
|
||||||
|
|
||||||
if (GetPrivateProfileBool("Wifi", "Enabled", false, IniName))
|
if (GetPrivateProfileBool("Wifi", "Enabled", false, IniName))
|
||||||
|
@ -6325,7 +6323,6 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
else
|
else
|
||||||
CommonSettings.wifi.mode = WifiCommInterfaceID_Infrastructure;
|
CommonSettings.wifi.mode = WifiCommInterfaceID_Infrastructure;
|
||||||
WritePrivateProfileInt("Wifi", "Mode", CommonSettings.wifi.mode, IniName);
|
WritePrivateProfileInt("Wifi", "Mode", CommonSettings.wifi.mode, IniName);
|
||||||
wifiHandler->SetCommInterfaceID(CommonSettings.wifi.mode);
|
|
||||||
|
|
||||||
cur = GetDlgItem(hDlg, IDC_BRIDGEADAPTER);
|
cur = GetDlgItem(hDlg, IDC_BRIDGEADAPTER);
|
||||||
CommonSettings.wifi.infraBridgeAdapter = ComboBox_GetCurSel(cur);
|
CommonSettings.wifi.infraBridgeAdapter = ComboBox_GetCurSel(cur);
|
||||||
|
|
1826
desmume/src/wifi.cpp
1826
desmume/src/wifi.cpp
File diff suppressed because it is too large
Load Diff
|
@ -820,11 +820,11 @@ enum WifiCommInterfaceID
|
||||||
WifiCommInterfaceID_Infrastructure = 1
|
WifiCommInterfaceID_Infrastructure = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WifiMACMode
|
enum FirmwareMACMode
|
||||||
{
|
{
|
||||||
WifiMACMode_Automatic = 0,
|
FirmwareMACMode_Automatic = 0,
|
||||||
WifiMACMode_Manual = 1,
|
FirmwareMACMode_Manual = 1,
|
||||||
WifiMACMode_ReadFromFirmware = 2
|
FirmwareMACMode_ReadFromFirmware = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef u16 IOREG_W_PADDING;
|
typedef u16 IOREG_W_PADDING;
|
||||||
|
@ -3242,41 +3242,14 @@ class WifiCommInterface
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
WifiCommInterfaceID _commInterfaceID;
|
WifiCommInterfaceID _commInterfaceID;
|
||||||
WifiEmulationLevel _emulationLevel;
|
|
||||||
u64 _usecCounter;
|
|
||||||
|
|
||||||
u8 *_workingTXBuffer;
|
|
||||||
u8 *_workingRXBuffer;
|
|
||||||
|
|
||||||
std::deque<RXQueuedPacket> _rxPacketQueue;
|
|
||||||
size_t _rxCurrentQueuedPacketPosition;
|
|
||||||
|
|
||||||
EAPStatus _softAPStatus;
|
|
||||||
u16 _softAPSequenceNumber;
|
|
||||||
|
|
||||||
FILE *_packetCaptureFile; // PCAP file to store the Ethernet packets.
|
|
||||||
|
|
||||||
RXQueuedPacket _GenerateSoftAPDeauthenticationFrame();
|
|
||||||
RXQueuedPacket _GenerateSoftAPBeaconFrame();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WifiCommInterface();
|
~WifiCommInterface();
|
||||||
virtual ~WifiCommInterface();
|
|
||||||
|
|
||||||
void PacketCaptureFileOpen();
|
|
||||||
void PacketCaptureFileClose();
|
|
||||||
void PacketCaptureFileWrite(const u8 *packet, u32 len, bool isReceived);
|
|
||||||
|
|
||||||
const u8* RXPacketFilter(const u8 *rxBuffer, const size_t rxBytes, RXPacketHeader &outRXHeader);
|
|
||||||
void RXWriteOneHalfword(u16 val);
|
|
||||||
|
|
||||||
void EmptyRXQueue();
|
|
||||||
|
|
||||||
virtual bool Start(WifiEmulationLevel emulationLevel) = 0;
|
virtual bool Start(WifiEmulationLevel emulationLevel) = 0;
|
||||||
virtual void Stop() = 0;
|
virtual void Stop() = 0;
|
||||||
virtual void SendPacket(const TXPacketHeader &txHeader, const u8 *packetData) = 0;
|
virtual size_t TXPacketSend(u8 *txTargetBuffer, size_t txLength) = 0;
|
||||||
virtual size_t RXPacketGet(u8 *rxTargetBuffer) = 0;
|
virtual size_t RXPacketGet(u8 *rxTargetBuffer, u16 sequenceNumber) = 0;
|
||||||
void Trigger();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AdhocCommInterface : public WifiCommInterface
|
class AdhocCommInterface : public WifiCommInterface
|
||||||
|
@ -3291,8 +3264,8 @@ public:
|
||||||
|
|
||||||
virtual bool Start(WifiEmulationLevel emulationLevel);
|
virtual bool Start(WifiEmulationLevel emulationLevel);
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual void SendPacket(const TXPacketHeader &txHeader, const u8 *packetData);
|
virtual size_t TXPacketSend(u8 *txTargetBuffer, size_t txLength);
|
||||||
virtual size_t RXPacketGet(u8 *rxTargetBuffer);
|
virtual size_t RXPacketGet(u8 *rxTargetBuffer, u16 sequenceNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SoftAPCommInterface : public WifiCommInterface
|
class SoftAPCommInterface : public WifiCommInterface
|
||||||
|
@ -3317,8 +3290,8 @@ public:
|
||||||
|
|
||||||
virtual bool Start(WifiEmulationLevel emulationLevel);
|
virtual bool Start(WifiEmulationLevel emulationLevel);
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
virtual void SendPacket(const TXPacketHeader &txHeader, const u8 *packetData);
|
virtual size_t TXPacketSend(u8 *txTargetBuffer, size_t txLength);
|
||||||
virtual size_t RXPacketGet(u8 *rxTargetBuffer);
|
virtual size_t RXPacketGet(u8 *rxTargetBuffer, u16 sequenceNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WifiHandler
|
class WifiHandler
|
||||||
|
@ -3332,22 +3305,44 @@ protected:
|
||||||
WifiEmulationLevel _selectedEmulationLevel;
|
WifiEmulationLevel _selectedEmulationLevel;
|
||||||
WifiEmulationLevel _currentEmulationLevel;
|
WifiEmulationLevel _currentEmulationLevel;
|
||||||
|
|
||||||
WifiCommInterfaceID _selectedCommID;
|
|
||||||
WifiCommInterfaceID _currentCommID;
|
|
||||||
WifiCommInterface *_currentCommInterface;
|
|
||||||
|
|
||||||
int _selectedBridgeDeviceIndex;
|
int _selectedBridgeDeviceIndex;
|
||||||
|
|
||||||
ClientPCapInterface *_pcap;
|
ClientPCapInterface *_pcap;
|
||||||
bool _isSocketsSupported;
|
bool _isSocketsSupported;
|
||||||
bool _didWarnWFCUser;
|
bool _didWarnWFCUser;
|
||||||
|
|
||||||
WifiMACMode _adhocMACMode;
|
FirmwareMACMode _firmwareMACMode;
|
||||||
WifiMACMode _infrastructureMACMode;
|
|
||||||
u32 _ip4Address;
|
|
||||||
u32 _uniqueMACValue;
|
|
||||||
u8 _userMAC[3];
|
u8 _userMAC[3];
|
||||||
|
|
||||||
|
u64 _usecCounter;
|
||||||
|
|
||||||
|
u8 *_workingTXBuffer;
|
||||||
|
u8 *_workingRXBuffer;
|
||||||
|
|
||||||
|
std::deque<RXQueuedPacket> _rxPacketQueue;
|
||||||
|
size_t _rxCurrentQueuedPacketPosition;
|
||||||
|
|
||||||
|
EAPStatus _softAPStatus;
|
||||||
|
u16 _softAPSequenceNumber;
|
||||||
|
|
||||||
|
FILE *_packetCaptureFile; // PCAP file to store the Ethernet packets.
|
||||||
|
|
||||||
|
void _RXEmptyQueue();
|
||||||
|
void _RXWriteOneHalfword(u16 val);
|
||||||
|
const u8* _RXPacketFilter(const u8 *rxBuffer, const size_t rxBytes, RXPacketHeader &outRXHeader);
|
||||||
|
|
||||||
|
void _PacketCaptureFileOpen();
|
||||||
|
void _PacketCaptureFileClose();
|
||||||
|
void _PacketCaptureFileWrite(const u8 *packet, u32 len, bool isReceived);
|
||||||
|
|
||||||
|
RXQueuedPacket _GenerateSoftAPDeauthenticationFrame();
|
||||||
|
RXQueuedPacket _GenerateSoftAPBeaconFrame();
|
||||||
|
RXQueuedPacket _GenerateSoftAPMgmtResponseFrame(WifiFrameManagementSubtype mgmtFrameSubtype);
|
||||||
|
RXQueuedPacket _GenerateSoftAPCtlACKFrame(const WifiDataFrameHeaderSTA2DS &inIEEE80211FrameHeader, const size_t sendPacketLength);
|
||||||
|
|
||||||
|
bool _SoftAPTrySendPacket(const TXPacketHeader &txHeader, const u8 *IEEE80211PacketData);
|
||||||
|
bool _AdhocTrySendPacket(const TXPacketHeader &txHeader, const u8 *IEEE80211PacketData);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WifiHandler();
|
WifiHandler();
|
||||||
~WifiHandler();
|
~WifiHandler();
|
||||||
|
@ -3362,10 +3357,6 @@ public:
|
||||||
WifiEmulationLevel GetCurrentEmulationLevel();
|
WifiEmulationLevel GetCurrentEmulationLevel();
|
||||||
void SetEmulationLevel(WifiEmulationLevel emulationLevel);
|
void SetEmulationLevel(WifiEmulationLevel emulationLevel);
|
||||||
|
|
||||||
WifiCommInterfaceID GetSelectedCommInterfaceID();
|
|
||||||
WifiCommInterfaceID GetCurrentCommInterfaceID();
|
|
||||||
void SetCommInterfaceID(WifiCommInterfaceID commID);
|
|
||||||
|
|
||||||
int GetBridgeDeviceList(std::vector<std::string> *deviceStringList);
|
int GetBridgeDeviceList(std::vector<std::string> *deviceStringList);
|
||||||
|
|
||||||
int GetSelectedBridgeDeviceIndex();
|
int GetSelectedBridgeDeviceIndex();
|
||||||
|
@ -3385,23 +3376,20 @@ public:
|
||||||
ClientPCapInterface* GetPCapInterface();
|
ClientPCapInterface* GetPCapInterface();
|
||||||
void SetPCapInterface(ClientPCapInterface *pcapInterface);
|
void SetPCapInterface(ClientPCapInterface *pcapInterface);
|
||||||
|
|
||||||
WifiMACMode GetMACModeForComm(WifiCommInterfaceID commID);
|
FirmwareMACMode GetFirmwareMACMode();
|
||||||
void SetMACModeForComm(WifiCommInterfaceID commID, WifiMACMode macMode);
|
void SetFirmwareMACMode(FirmwareMACMode macMode);
|
||||||
|
|
||||||
uint32_t GetIP4Address();
|
|
||||||
void SetIP4Address(u32 ip4Address);
|
|
||||||
|
|
||||||
uint32_t GetUniqueMACValue();
|
|
||||||
void SetUniqueMACValue(u32 uniqueValue);
|
|
||||||
|
|
||||||
void GetUserMACValues(u8 *outValue3, u8 *outValue4, u8 *outValue5);
|
void GetUserMACValues(u8 *outValue3, u8 *outValue4, u8 *outValue5);
|
||||||
void SetUserMACValues(u8 inValue3, u8 inValue4, u8 inValue5);
|
void SetUserMACValues(u8 inValue3, u8 inValue4, u8 inValue5);
|
||||||
|
|
||||||
void GenerateMACFromValues(u8 outMAC[6]);
|
void GenerateRandomMAC(u8 outMAC[6]);
|
||||||
void CopyMACFromUserValues(u8 outMAC[6]);
|
void CopyMACFromUserValues(u8 outMAC[6]);
|
||||||
|
|
||||||
void PrepareSaveStateWrite();
|
void PrepareSaveStateWrite();
|
||||||
void ParseSaveStateRead();
|
void ParseSaveStateRead();
|
||||||
|
|
||||||
|
static size_t ConvertDataFrame80211To8023(const u8 *inIEEE80211Frame, const size_t txLength, u8 *outIEEE8023Frame);
|
||||||
|
static size_t ConvertDataFrame8023To80211(const u8 *inIEEE8023Frame, const size_t txLength, u8 *outIEEE80211Frame);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* wifi data to be stored in firmware, when no firmware image was loaded */
|
/* wifi data to be stored in firmware, when no firmware image was loaded */
|
||||||
|
|
Loading…
Reference in New Issue