DSWifi
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
dswifi9.h File Reference

ARM9 header of DSWifi. More...

#include "dswifi_version.h"

Data Structures

struct  WIFI_ACCESSPOINT
 Structure that defines how to connect to an access point. More...
 

Macros

#define INIT_ONLY   false
 Initi library only, don't try to connect to AP. Used by Wifi_InitDefault().
 
#define WFC_CONNECT   true
 Init library and try to connect to firmware AP. Used by Wifi_InitDefault().
 

Typedefs

typedef struct WIFI_ACCESSPOINT Wifi_AccessPoint
 Structure that defines how to connect to an access point.
 
typedef void(* WifiPacketHandler) (int, int)
 Wifi Packet Handler function.
 
typedef void(* WifiSyncHandler) (void)
 Wifi Sync Handler function.
 

Enumerations

enum  WEPMODES {
  WEPMODE_NONE = 0 ,
  WEPMODE_40BIT = 1 ,
  WEPMODE_128BIT = 2
}
 Supported WEP modes. More...
 
enum  WIFI_ASSOCSTATUS {
  ASSOCSTATUS_DISCONNECTED ,
  ASSOCSTATUS_SEARCHING ,
  ASSOCSTATUS_AUTHENTICATING ,
  ASSOCSTATUS_ASSOCIATING ,
  ASSOCSTATUS_ACQUIRINGDHCP ,
  ASSOCSTATUS_ASSOCIATED ,
  ASSOCSTATUS_CANNOTCONNECT
}
 Returned by Wifi_AssocStatus() after calling Wifi_ConnectAPk. More...
 
enum  WIFI_RETURN {
  WIFI_RETURN_OK = 0 ,
  WIFI_RETURN_LOCKFAILED = 1 ,
  WIFI_RETURN_ERROR = 2 ,
  WIFI_RETURN_PARAMERROR = 3
}
 Error codes for Wifi_GetAPData() More...
 
enum  WIFI_STATS {
  WSTAT_RXQUEUEDPACKETS ,
  WSTAT_TXQUEUEDPACKETS ,
  WSTAT_RXQUEUEDBYTES ,
  WSTAT_TXQUEUEDBYTES ,
  WSTAT_RXQUEUEDLOST ,
  WSTAT_TXQUEUEDREJECTED ,
  WSTAT_RXPACKETS ,
  WSTAT_RXBYTES ,
  WSTAT_RXDATABYTES ,
  WSTAT_TXPACKETS ,
  WSTAT_TXBYTES ,
  WSTAT_TXDATABYTES ,
  WSTAT_ARM7_UPDATES ,
  WSTAT_DEBUG ,
  WSTAT_HW_1B0 ,
  WSTAT_HW_1B1 ,
  WSTAT_HW_1B2 ,
  WSTAT_HW_1B3 ,
  WSTAT_HW_1B4 ,
  WSTAT_HW_1B5 ,
  WSTAT_HW_1B6 ,
  WSTAT_HW_1B7 ,
  WSTAT_HW_1B8 ,
  WSTAT_HW_1B9 ,
  WSTAT_HW_1BA ,
  WSTAT_HW_1BB ,
  WSTAT_HW_1BC ,
  WSTAT_HW_1BD ,
  WSTAT_HW_1BE ,
  WSTAT_HW_1BF ,
  WSTAT_HW_1C0 ,
  WSTAT_HW_1C1 ,
  WSTAT_HW_1C4 ,
  WSTAT_HW_1C5 ,
  WSTAT_HW_1D0 ,
  WSTAT_HW_1D1 ,
  WSTAT_HW_1D2 ,
  WSTAT_HW_1D3 ,
  WSTAT_HW_1D4 ,
  WSTAT_HW_1D5 ,
  WSTAT_HW_1D6 ,
  WSTAT_HW_1D7 ,
  WSTAT_HW_1D8 ,
  WSTAT_HW_1D9 ,
  WSTAT_HW_1DA ,
  WSTAT_HW_1DB ,
  WSTAT_HW_1DC ,
  WSTAT_HW_1DD ,
  WSTAT_HW_1DE ,
  WSTAT_HW_1DF ,
  NUM_WIFI_STATS
}
 List of available WiFi statistics. More...
 
enum  WIFIGETDATA {
  WIFIGETDATA_MACADDRESS ,
  WIFIGETDATA_NUMWFCAPS ,
  MAX_WIFIGETDATA
}
 User code uses members of the WIFIGETDATA structure in calling Wifi_GetData to retreive miscellaneous odd information. More...
 

Functions

int Wifi_AssocStatus (void)
 Returns information about the status of connection to an AP.
 
void Wifi_AutoConnect (void)
 Connect to an Access Point specified by the WFC data in the firmware.
 
int Wifi_CheckInit (void)
 Verifies when the ARM7 has been successfully initialized.
 
int Wifi_ConnectAP (Wifi_AccessPoint *apdata, int wepmode, int wepkeyid, unsigned char *wepkey)
 Connect to an Access Point.
 
void Wifi_DisableWifi (void)
 Instructs the ARM7 to disengage wireless and stop receiving or transmitting.
 
int Wifi_DisconnectAP (void)
 Disassociate from the Access Point.
 
void Wifi_EnableWifi (void)
 Instructs the ARM7 to go into a basic "active" mode, not actually associated to an AP, but actively receiving and potentially transmitting.
 
int Wifi_FindMatchingAP (int numaps, Wifi_AccessPoint *apdata, Wifi_AccessPoint *match_dest)
 Determines whether various APs exist in the local area.
 
int Wifi_GetAPData (int apnum, Wifi_AccessPoint *apdata)
 Grabs data from internal structures for user code (always succeeds).
 
int Wifi_GetData (int datatype, int bufferlen, unsigned char *buffer)
 Retrieve an arbitrary or misc. piece of data from the WiFi hardware.
 
unsigned long Wifi_GetIP (void)
 It returns the current IP address of the DS.
 
struct in_addr Wifi_GetIPInfo (struct in_addr *pGateway, struct in_addr *pSnmask, struct in_addr *pDns1, struct in_addr *pDns2)
 Returns IP information.
 
int Wifi_GetNumAP (void)
 Returns the current number of APs that are known and tracked internally.
 
u32 Wifi_GetStats (int statnum)
 Retreive an element of the WiFi statistics gathered.
 
unsigned long Wifi_Init (int initflags)
 Initializes the WiFi library (ARM9 side) and the sgIP library.
 
bool Wifi_InitDefault (bool useFirmwareSettings)
 Initializes WiFi library.
 
void Wifi_RawSetPacketHandler (WifiPacketHandler wphfunc)
 Set a handler to process all raw incoming packets.
 
int Wifi_RawTxFrame (unsigned short datalen, unsigned short rate, unsigned short *data)
 Send a raw 802.11 frame at a specified rate.
 
int Wifi_RxRawReadPacket (long packetID, long readlength, unsigned short *data)
 Allows user code to read a packet from within the WifiPacketHandler function.
 
void Wifi_ScanMode (void)
 Instructs the ARM7 to periodically rotate through the channels to pick up and record information from beacons given off by APs.
 
void Wifi_SetChannel (int channel)
 If the WiFi system is not connected or connecting to an access point, instruct the chipset to change channel.
 
void Wifi_SetIP (unsigned long IPaddr, unsigned long gateway, unsigned long subnetmask, unsigned long dns1, unsigned long dns2)
 Set the DS's IP address and other IP configuration information.
 
void Wifi_SetPromiscuousMode (int enable)
 Allows the DS to enter or leave a "promsicuous" mode.
 
void Wifi_SetSyncHandler (WifiSyncHandler sh)
 Call this function to request notification of when the ARM7-side Wifi_Sync() function should be called.
 
void Wifi_Sync (void)
 Call this function when requested to sync by the ARM7 side of the WiFi lib.
 
void Wifi_Timer (int num_ms)
 This function should be called in a periodic interrupt.
 
void Wifi_Update (void)
 Checks for new data from the ARM7 and initiates routing if data is available.
 

Detailed Description

ARM9 header of DSWifi.

Typedef Documentation

◆ Wifi_AccessPoint

Structure that defines how to connect to an access point.

If a field is not necessary for Wifi_ConnectAP it is marked as such. only 4 fields are absolutely required to be filled in correctly for the connection to work, they are: SSID, ssid_len, bssid, and channel. All others can be ignored (though flags should be set to 0).

◆ WifiPacketHandler

typedef void(* WifiPacketHandler) (int, int)

Wifi Packet Handler function.

The first parameter is the packetID. It is only valid while the called function is executing. The second parameter is packetlength.

Call Wifi_RxRawReadPacket() while in the packet handler function, to retreive the data to a local buffer.

◆ WifiSyncHandler

typedef void(* WifiSyncHandler) (void)

Wifi Sync Handler function.

Callback function that is called when the ARM7 needs to be told to synchronize with new fifo data. If this callback is used (see Wifi_SetSyncHandler()), it should send a message via the fifo to the ARM7, which will call Wifi_Sync() on ARM7.

Enumeration Type Documentation

◆ WEPMODES

enum WEPMODES

Supported WEP modes.

  • 64 bit (40 bit) WEP mode: 5 ASCII characters (or 10 hex numbers).
  • 128 bit (104 bit) WEP mode: 13 ASCII characters (or 26 hex numbers).
Enumerator
WEPMODE_NONE 

No WEP security is used.

WEPMODE_40BIT 

5 ASCII characters.

WEPMODE_128BIT 

13 ASCII characters.

◆ WIFI_ASSOCSTATUS

Returned by Wifi_AssocStatus() after calling Wifi_ConnectAPk.

Enumerator
ASSOCSTATUS_DISCONNECTED 

Not trying to connect.

ASSOCSTATUS_SEARCHING 

Data given does not completely specify an AP, looking for AP that matches the data.

ASSOCSTATUS_AUTHENTICATING 

Connecting...

ASSOCSTATUS_ASSOCIATING 

Connecting...

ASSOCSTATUS_ACQUIRINGDHCP 

Connected to AP, but getting IP data from DHCP.

ASSOCSTATUS_ASSOCIATED 

Connected! (COMPLETE if Wifi_ConnectAP was called to start)

ASSOCSTATUS_CANNOTCONNECT 

Error in connecting... (COMPLETE if Wifi_ConnectAP was called to start)

◆ WIFI_RETURN

Error codes for Wifi_GetAPData()

Enumerator
WIFI_RETURN_OK 

Everything went ok.

WIFI_RETURN_LOCKFAILED 

The spinlock attempt failed (it wasn't retried cause that could lock both cpus- retry again after a delay.

WIFI_RETURN_ERROR 

There was an error in attempting to complete the requested task.

WIFI_RETURN_PARAMERROR 

There was an error in the parameters passed to the function.

◆ WIFI_STATS

enum WIFI_STATS

List of available WiFi statistics.

Enumerator
WSTAT_RXQUEUEDPACKETS 

Number of packets queued into the RX FIFO.

WSTAT_TXQUEUEDPACKETS 

Number of packets queued into the TX FIFO.

WSTAT_RXQUEUEDBYTES 

Number of bytes queued into the RX FIFO.

WSTAT_TXQUEUEDBYTES 

Number of bytes queued into the TX FIFO.

WSTAT_RXQUEUEDLOST 

Number of packets lost due to space limitations in queuing.

WSTAT_TXQUEUEDREJECTED 

Number of packets rejected due to space limitations in queuing.

◆ WIFIGETDATA

User code uses members of the WIFIGETDATA structure in calling Wifi_GetData to retreive miscellaneous odd information.

Enumerator
WIFIGETDATA_MACADDRESS 

MACADDRESS: returns data in the buffer, requires at least 6 bytes.

WIFIGETDATA_NUMWFCAPS 

NUM WFC APS: returns number between 0 and 3, doesn't use buffer.

Function Documentation

◆ Wifi_AssocStatus()

int Wifi_AssocStatus ( void  )

Returns information about the status of connection to an AP.

Continue polling this function until you receive ASSOCSTATUS_CONNECTED or ASSOCSTATUS_CANNOTCONNECT.

Returns
A value from the WIFI_ASSOCSTATUS enum.

◆ Wifi_CheckInit()

int Wifi_CheckInit ( void  )

Verifies when the ARM7 has been successfully initialized.

Returns
1 if the ARM7 is ready for WiFi, 0 otherwise

◆ Wifi_ConnectAP()

int Wifi_ConnectAP ( Wifi_AccessPoint apdata,
int  wepmode,
int  wepkeyid,
unsigned char *  wepkey 
)

Connect to an Access Point.

Parameters
apdataBasic data on the AP.
wepmodeIndicates whether WEP is used, and what kind (WEPMODES).
wepkeyidIndicates which WEP key ID to use for transmitting.
wepkeyThe WEP key, to be used in all 4 key slots (should make this more flexible in the future).
Returns
0 for ok, -1 for error with input data.

◆ Wifi_DisconnectAP()

int Wifi_DisconnectAP ( void  )

Disassociate from the Access Point.

Returns
It returns 0 on success.

◆ Wifi_FindMatchingAP()

int Wifi_FindMatchingAP ( int  numaps,
Wifi_AccessPoint apdata,
Wifi_AccessPoint match_dest 
)

Determines whether various APs exist in the local area.

You provide a list of APs, and it will return the index of the first one in the list that can be found in the internal list of APs that are being tracked.

Parameters
numapsNumber of records in the list.
apdataPointer to an array of structures with information about the APs to find.
match_destOPTIONAL pointer to a record to receive the matching AP record.
Returns
-1 for none found, or a positive/zero integer index into the array

◆ Wifi_GetAPData()

int Wifi_GetAPData ( int  apnum,
Wifi_AccessPoint apdata 
)

Grabs data from internal structures for user code (always succeeds).

Parameters
apnumThe 0-based index of the access point record to fetch.
apdataPointer to the location to store the retrieved data.
Returns
WIFI_RETURN enumeration value.

◆ Wifi_GetData()

int Wifi_GetData ( int  datatype,
int  bufferlen,
unsigned char *  buffer 
)

Retrieve an arbitrary or misc. piece of data from the WiFi hardware.

See the WIFIGETDATA enum.

Parameters
datatypeElement from the WIFIGETDATA enum specifing what kind of data to get.
bufferlenLength of the buffer to copy data to (not always used)
bufferBuffer to copy element data to (not always used)
Returns
-1 for failure, the number of bytes written to the buffer, or the value requested if the buffer isn't used.

◆ Wifi_GetIP()

unsigned long Wifi_GetIP ( void  )

It returns the current IP address of the DS.

The IP may not be valid before connecting to an AP, or setting the IP manually.

Returns
The current IP address of the DS

◆ Wifi_GetIPInfo()

struct in_addr Wifi_GetIPInfo ( struct in_addr *  pGateway,
struct in_addr *  pSnmask,
struct in_addr *  pDns1,
struct in_addr *  pDns2 
)

Returns IP information.

The values may not be valid before connecting to an AP, or setting the IP manually.

Parameters
pGatewayPointer to receive the currently configured gateway IP.
pSnmaskPointer to receive the currently configured subnet mask.
pDns1Pointer to receive the currently configured primary DNS server IP.
pDns2Pointer to receive the currently configured secondary DNS server IP.
Returns
The current IP address of the DS

◆ Wifi_GetNumAP()

int Wifi_GetNumAP ( void  )

Returns the current number of APs that are known and tracked internally.

Returns
The number of APs.

◆ Wifi_GetStats()

u32 Wifi_GetStats ( int  statnum)

Retreive an element of the WiFi statistics gathered.

Parameters
statnumElement from the WIFI_STATS enum, indicating what statistic to return.
Returns
The requested stat, or 0 for failure.

◆ Wifi_Init()

unsigned long Wifi_Init ( int  initflags)

Initializes the WiFi library (ARM9 side) and the sgIP library.

Parameters
initflagsSet up some optional things, like controlling the LED blinking.
Returns
A 32bit value that must be passed to ARM7.

◆ Wifi_InitDefault()

bool Wifi_InitDefault ( bool  useFirmwareSettings)

Initializes WiFi library.

It initializes the WiFi hardware, sets up a FIFO handler to communicate with the ARM7 side of the library, and it sets up timer 3 to be used by the DSWifi.

Parameters
useFirmwareSettingsIf true, this function will initialize the hardware and try to connect to the Access Points stored in the firmware. If false, it will only initialize the library. You can use WFC_CONNECT and INIT_ONLY.
Returns
It returns true on success, false on failure.

◆ Wifi_RawSetPacketHandler()

void Wifi_RawSetPacketHandler ( WifiPacketHandler  wphfunc)

Set a handler to process all raw incoming packets.

Parameters
wphfuncPointer to packet handler (see WifiPacketHandler for info).

◆ Wifi_RawTxFrame()

int Wifi_RawTxFrame ( unsigned short  datalen,
unsigned short  rate,
unsigned short *  data 
)

Send a raw 802.11 frame at a specified rate.

Parameters
datalenThe length in bytes of the frame to send
rateThe rate to transmit at (Specified as mbits/10, 1mbit=0x000A, 2mbit=0x0014)
dataPointer to the data to send (should be halfword-aligned)
Returns
Nothing of interest.

◆ Wifi_RxRawReadPacket()

int Wifi_RxRawReadPacket ( long  packetID,
long  readlength,
unsigned short *  data 
)

Allows user code to read a packet from within the WifiPacketHandler function.

Parameters
packetIDA non-unique identifier which locates the packet specified in the internal buffer.
readlengthNumber of bytes to read. It actually reads ((number + 1) & ~1) bytes
dataLocation for the data to be read into
Returns
Number of bytes read.

◆ Wifi_SetChannel()

void Wifi_SetChannel ( int  channel)

If the WiFi system is not connected or connecting to an access point, instruct the chipset to change channel.

Parameters
channelThe channel to change to, in the range of 1-13.

◆ Wifi_SetIP()

void Wifi_SetIP ( unsigned long  IPaddr,
unsigned long  gateway,
unsigned long  subnetmask,
unsigned long  dns1,
unsigned long  dns2 
)

Set the DS's IP address and other IP configuration information.

Parameters
IPaddrThe new IP address. If this value is zero, the IP, the gateway, and the subnet mask will be allocated via DHCP.
gatewayThe new gateway (example: 192.168.1.1 is 0xC0A80101)
subnetmaskThe new subnet mask (example: 255.255.255.0 is 0xFFFFFF00)
dns1The new primary dns server (NOTE! if this value is zero AND the IPaddr value is zero, dns1 and dns2 will be allocated via DHCP).
dns2The new secondary dns server

◆ Wifi_SetPromiscuousMode()

void Wifi_SetPromiscuousMode ( int  enable)

Allows the DS to enter or leave a "promsicuous" mode.

In this mode all data that can be received is forwarded to the ARM9 for user processing. Best used with Wifi_RawSetPacketHandler, to allow user code to use the data (well, the lib won't use 'em, so they're just wasting CPU otherwise.)

Parameters
enable0 to disable promiscuous mode, nonzero to engage.

◆ Wifi_SetSyncHandler()

void Wifi_SetSyncHandler ( WifiSyncHandler  sh)

Call this function to request notification of when the ARM7-side Wifi_Sync() function should be called.

Parameters
shPointer to the function to be called for notification.

◆ Wifi_Timer()

void Wifi_Timer ( int  num_ms)

This function should be called in a periodic interrupt.

It serves as the basis for all updating in the sgIP library, all retransmits, timeouts, and etc are based on this function being called. It's not timing critical but it is rather essential.

Parameters
num_msThe number of milliseconds since the last time this function was called.