Skip to content

Commit b051279

Browse files
authored
WD/Wifi: Add Wifi control implementations (#247)
* Add WD implementation. * Add a few comments + Get rid of some magic numbers. * Add HW_RVL check. * Remove ISR calls in WD_Deinit() + Remove heap references + Pass wd_fd instead of WD_GetWork() in WD_Deinit(). * Add IE (Information Elements) operations. GetLength, GetIE (Get the data), GetNumberOfIEs. * Full rewrite IE operations. The way I interpreted IEs was wrong, which lead to the code being absolutely useless and broken (The last commit happened because of the lack of tests). * Return length instead of using a pointer. * Simplify if cases in WD_GetRadioLevel. * Use defined values for signal strength.
1 parent 792c749 commit b051279

3 files changed

Lines changed: 415 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ OGCOBJ := \
152152
console_font_8x16.o timesupp.o lock_supp.o usbgecko.o usbmouse.o \
153153
sbrk.o malloc_lock.o kprintf.o stm.o aes.o sha.o ios.o es.o isfs.o usb.o network_common.o \
154154
sdgecko_io.o sdgecko_buf.o gcsd.o argv.o network_wii.o wiisd.o conf.o usbstorage.o \
155-
texconv.o wiilaunch.o sys_report.o
155+
texconv.o wiilaunch.o wd.o sys_report.o
156156

157157
#---------------------------------------------------------------------------------
158158
MODOBJ := freqtab.o mixer.o modplay.o semitonetab.o gcmodplay.o

gc/ogc/wd.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*-----------------------------------------------------------------------
2+
3+
wd.h -- Wireless Driver Implementation.
4+
5+
Copyright:
6+
7+
- (C) 2025-2026 B. Abdelali (Abdelali221) (Author)
8+
- (C) 2008 Dolphin Emulator Project (For providing data structures)
9+
10+
This software is provided 'as-is', without any express or implied
11+
warranty. In no event will the authors be held liable for any
12+
damages arising from the use of this software.
13+
14+
Permission is granted to anyone to use this software for any
15+
purpose, including commercial applications, and to alter it and
16+
redistribute it freely, subject to the following restrictions:
17+
18+
1. The origin of this software must not be misrepresented; you
19+
must not claim that you wrote the original software. If you use
20+
this software in a product, an acknowledgment in the product
21+
documentation would be appreciated but is not required.
22+
23+
2. Altered source versions must be plainly marked as such, and
24+
must not be misrepresented as being the original software.
25+
26+
3. This notice may not be removed or altered from any source
27+
distribution.
28+
29+
-----------------------------------------------------------------------*/
30+
31+
#ifndef __WD_H_
32+
#define __WD_H_
33+
#include <gccore.h>
34+
35+
#define SSID_LENGTH 32
36+
#define BSSID_LENGTH 6
37+
38+
enum WDIOCTLV
39+
{
40+
IOCTLV_WD_INVALID = 0x1000,
41+
IOCTLV_WD_GET_MODE = 0x1001, // WD_GetMode
42+
IOCTLV_WD_SET_LINKSTATE = 0x1002, // WD_SetLinkState
43+
IOCTLV_WD_GET_LINKSTATE = 0x1003, // WD_GetLinkState
44+
IOCTLV_WD_SET_CONFIG = 0x1004, // WD_SetConfig
45+
IOCTLV_WD_GET_CONFIG = 0x1005, // WD_GetConfig
46+
IOCTLV_WD_CHANGE_BEACON = 0x1006, // WD_ChangeBeacon
47+
IOCTLV_WD_DISASSOC = 0x1007, // WD_DisAssoc
48+
IOCTLV_WD_MP_SEND_FRAME = 0x1008, // WD_MpSendFrame
49+
IOCTLV_WD_SEND_FRAME = 0x1009, // WD_SendFrame
50+
IOCTLV_WD_SCAN = 0x100a, // WD_Scan
51+
IOCTLV_WD_CALL_WL = 0x100c, // WD_CallWL
52+
IOCTLV_WD_MEASURE_CHANNEL = 0x100b, // WD_MeasureChannel
53+
IOCTLV_WD_GET_LASTERROR = 0x100d, // WD_GetLastError
54+
IOCTLV_WD_GET_INFO = 0x100e, // WD_GetInfo
55+
IOCTLV_WD_CHANGE_GAMEINFO = 0x100f, // WD_ChangeGameInfo
56+
IOCTLV_WD_CHANGE_VTSF = 0x1010, // WD_ChangeVTSF
57+
IOCTLV_WD_RECV_FRAME = 0x8000, // WD_ReceiveFrame
58+
IOCTLV_WD_RECV_NOTIFICATION = 0x8001 // WD_ReceiveNotification
59+
};
60+
61+
// Capability flags :
62+
63+
#define CAPAB_SECURED_FLAG 0x10
64+
65+
// Information Elements IDs :
66+
67+
#define IEID_SSID 0x0
68+
#define IEID_VENDORSPECIFIC 0xDD
69+
#define IEID_SECURITY 0x30
70+
71+
// Signal Strength :
72+
73+
#define WD_SIGNAL_STRONG 3
74+
#define WD_SIGNAL_NORMAL 2
75+
#define WD_SIGNAL_FAIR 1
76+
#define WD_SIGNAL_WEAK 0
77+
78+
// WD Modes :
79+
80+
enum MODES
81+
{
82+
Unintialized = 0,
83+
DSCommunications = 1,
84+
NA0 = 2,
85+
AOSSAPScan = 3,
86+
NA1 = 4,
87+
NA2 = 5,
88+
NA3 = 6
89+
};
90+
91+
// WD Information :
92+
93+
typedef struct WDInfo
94+
{
95+
u8 MAC[6];
96+
u16 EnableChannelsMask;
97+
u16 NTRallowedChannelsMask;
98+
u8 CountryCode[4];
99+
u8 channel;
100+
u8 initialized;
101+
u8 version[80];
102+
u8 unknown[48];
103+
} WDInfo;
104+
105+
// Scan parameters :
106+
107+
typedef struct ScanParameters
108+
{
109+
u16 ChannelBitmap;
110+
u16 MaxChannelTime;
111+
u8 BSSID[BSSID_LENGTH];
112+
u16 ScanType;
113+
114+
u16 SSIDLength;
115+
u8 SSID[SSID_LENGTH];
116+
u8 SSIDMatchMask[6];
117+
118+
} ScanParameters;
119+
120+
// BSS Descriptor :
121+
122+
typedef struct BSSDescriptor
123+
{
124+
u16 length;
125+
u16 RSSI;
126+
u8 BSSID[6];
127+
u16 SSIDLength;
128+
u8 SSID[32];
129+
u16 Capabilities;
130+
struct
131+
{
132+
u16 basic;
133+
u16 support;
134+
} rateSet;
135+
u16 beacon_period;
136+
u16 DTIM_period;
137+
u16 channel;
138+
u16 CF_period;
139+
u16 CF_max_duration;
140+
u16 IEs_length;
141+
} BSSDescriptor;
142+
143+
// Information Element Header :
144+
145+
typedef struct IE_hdr
146+
{
147+
u8 ID;
148+
u8 len;
149+
} IE_hdr;
150+
151+
// General Purpose :
152+
153+
s32 NCD_LockWirelessDriver();
154+
u32 NCD_UnlockWirelessDriver(s32 lockid);
155+
int WD_Init(u8 mode);
156+
void WD_Deinit();
157+
int WD_GetInfo(WDInfo* inf);
158+
159+
// AP Scan related :
160+
161+
u8 WD_GetRadioLevel(BSSDescriptor* Bss);
162+
int WD_Scan(ScanParameters *settings, u8* buff, u16 buffsize);
163+
int WD_ScanOnce(ScanParameters *settings, u8* buff, u16 buffsize);
164+
u8 WD_GetNumberOfIEs(BSSDescriptor* Bss);
165+
int WD_GetIELength(BSSDescriptor* Bss, u8 ID);
166+
int WD_GetIE(BSSDescriptor* Bss, u8 ID, u8* buff, u8 buffsize);
167+
void WD_SetDefaultScanParameters(ScanParameters* set);
168+
169+
#endif

0 commit comments

Comments
 (0)