DSWifi
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
Local multiplayer utilities.

Typedefs

typedef void(* WifiFromClientPacketHandler) (Wifi_MPPacketType, int, int, int)
 Handler of WiFI packets received on the host from a client.
 
typedef void(* WifiFromHostPacketHandler) (Wifi_MPPacketType, int, int)
 Handler of WiFI packets received on a client from the host.
 

Enumerations

enum  Wifi_MPPacketType {
  WIFI_MPTYPE_INVALID = -1 ,
  WIFI_MPTYPE_CMD = 0 ,
  WIFI_MPTYPE_REPLY = 1 ,
  WIFI_MPTYPE_DATA = 2
}
 Possible types of packets received by multiplayer handlers. More...
 

Functions

int Wifi_BeaconStart (const char *ssid, u32 game_id)
 Sends a beacon frame to the ARM7 to be used in multiplayer host mode.
 
void Wifi_MultiplayerAllowNewClients (bool allow)
 Allows or disallows new clients to connect to this console acting as host.
 
int Wifi_MultiplayerClientMode (size_t client_packet_size)
 Sets the WiFI hardware in mulitplayer client mode.
 
int Wifi_MultiplayerClientReplyTxFrame (const void *data, u16 datalen)
 Prepares a multiplayer client reply frame to be sent.
 
int Wifi_MultiplayerClientToHostDataTxFrame (const void *data, u16 datalen)
 Sends a data frame to the host.
 
void Wifi_MultiplayerFromClientSetPacketHandler (WifiFromClientPacketHandler func)
 Set a handler on a host console for packets received from clients.
 
void Wifi_MultiplayerFromHostSetPacketHandler (WifiFromHostPacketHandler func)
 Set a handler on a client console for packets received from the host.
 
u16 Wifi_MultiplayerGetClientMask (void)
 Returns a mask where each bit represents an connected client.
 
int Wifi_MultiplayerGetClients (int max_clients, Wifi_ConnectedClient *client_data)
 Get information of clients connected to a multiplayer host.
 
int Wifi_MultiplayerGetNumClients (void)
 Get the number of clients connected to this DS acting as a multiplayer host.
 
int Wifi_MultiplayerHostCmdTxFrame (const void *data, u16 datalen)
 Sends a multiplayer host frame.
 
int Wifi_MultiplayerHostMode (int max_clients, size_t host_packet_size, size_t client_packet_size)
 Sets the WiFI hardware in mulitplayer host mode.
 
void Wifi_MultiplayerHostName (const void *buffer, u8 len)
 Set the name and name length fields in beacon packets.
 
int Wifi_MultiplayerHostToClientDataTxFrame (int aid, const void *data, u16 datalen)
 Sends a data frame to the client with the specified association ID.
 
void Wifi_MultiplayerKickClientByAID (int association_id)
 Kick the client with the provided AID from the host.
 

Detailed Description

Typedef Documentation

◆ WifiFromClientPacketHandler

typedef void(* WifiFromClientPacketHandler) (Wifi_MPPacketType, int, int, int)

Handler of WiFI packets received on the host from a client.

The first argument is the packet type.

The second argument is the association ID of the client that sent this packet. The third argument is the packet address. It is only valid while the called function is executing. The fourth argument is packet length.

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

Only user data of packets can be read from this handler, not the IEEE 802.11 header.

◆ WifiFromHostPacketHandler

typedef void(* WifiFromHostPacketHandler) (Wifi_MPPacketType, int, int)

Handler of WiFI packets received on a client from the host.

The first argument is the packet type.

The second argument is the packet address. It is only valid while the called function is executing. The third argument is the packet length.

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

Only user data of packets can be read from this handler, not the IEEE 802.11 header.

Enumeration Type Documentation

◆ Wifi_MPPacketType

Possible types of packets received by multiplayer handlers.

Enumerator
WIFI_MPTYPE_INVALID 

Invalid packet type.

WIFI_MPTYPE_CMD 

Multiplayer CMD packet.

WIFI_MPTYPE_REPLY 

Multiplayer REPLY packet.

WIFI_MPTYPE_DATA 

Regular data packet.

Function Documentation

◆ Wifi_BeaconStart()

int Wifi_BeaconStart ( const char *  ssid,
u32  game_id 
)

Sends a beacon frame to the ARM7 to be used in multiplayer host mode.

This beacon frame announces that this console is acting as an access point (for example, to act as a host of a multiplayer group). Beacon frames are be sent periodically by the hardware, you only need to call this function once. If you call Wifi_SetChannel(), the beacon will start announcing the presence of the AP in the new channel.

Beacon packets need to be sent regularly while in AP mode. When leaving AP mode, DSWifi will stop sending them automatically.

Note
You can call Wifi_SetChannel() and Wifi_MultiplayerAllowNewClients() before calling Wifi_BeaconStart(). The becaon will start with the pre-selected settings. You can also modify the settings if you wait for at least two or three frames of calling Wifi_BeaconStart().
Parameters
ssidSSID to use for the access point.
game_idA 32-bit game ID included in beacon frames. It is used to identify which access points belong to Nintendo DS devices acting as multiplayer hosts of a game. Official games use IDs of the form 0x0040yyyy (except for Nintendo Zone: 0x00000857).
Returns
0 on success, a negative value on error.

◆ Wifi_MultiplayerAllowNewClients()

void Wifi_MultiplayerAllowNewClients ( bool  allow)

Allows or disallows new clients to connect to this console acting as host.

By default, clients can connect to the host when in host mode. You should disable new connections once you have enough players connected to you, and you aren't expecting new connections.

Disabling new connections will kick all clients that are in the process of associating to this host but haven't finished the process.

Note
Give the ARM7 a frame or two for this call to have effect.
Parameters
allowIf true, allow new connections. If false, reject them.

◆ Wifi_MultiplayerClientMode()

int Wifi_MultiplayerClientMode ( size_t  client_packet_size)

Sets the WiFI hardware in mulitplayer client mode.

Use Wifi_LibraryModeReady() to check when the mode change is finished.

The size used in this function is only the size of the custom data sent by the application. The size of the headers is added internally by the library.

Parameters
client_packet_sizeSize of the user data sent in packets from the client to the host.
Returns
Returns 0 on success, -1 if the requested size is too big.

◆ Wifi_MultiplayerClientReplyTxFrame()

int Wifi_MultiplayerClientReplyTxFrame ( const void *  data,
u16  datalen 
)

Prepares a multiplayer client reply frame to be sent.

This frame will be sent to the host as soon as a CMD frame is received.

Hosts can use Wifi_MultiplayerFromClientSetPacketHandler() to register a packet handler for packets sent with Wifi_MultiplayerClientReplyTxFrame(). They will be received with type WIFI_MPTYPE_REPLY.

Note
If there is a pre-existing packet that hasn't been sent to the host yet, it will be replaced by the new one.
Parameters
dataPointer to the data to be sent.
datalenSize of the data in bytes. It can go up to the size defined when calling Wifi_MultiplayerHostMode() and Wifi_MultiplayerClientMode().
Returns
On success it returns 0, else it returns a negative value.

◆ Wifi_MultiplayerClientToHostDataTxFrame()

int Wifi_MultiplayerClientToHostDataTxFrame ( const void *  data,
u16  datalen 
)

Sends a data frame to the host.

This function sends an arbitrary data packet without waiting for any packet sent by the host.

Hosts can use Wifi_MultiplayerFromClientSetPacketHandler() to register a packet handler for packets sent with Wifi_MultiplayerClientToHostDataTxFrame(). They will be received with type WIFI_MPTYPE_DATA.

Parameters
dataPointer to the data to be sent.
datalenSize of the data in bytes.
Returns
On success it returns 0, else it returns a negative value.

◆ Wifi_MultiplayerFromClientSetPacketHandler()

void Wifi_MultiplayerFromClientSetPacketHandler ( WifiFromClientPacketHandler  func)

Set a handler on a host console for packets received from clients.

Parameters
funcPointer to packet handler (see WifiFromClientPacketHandler for info).

◆ Wifi_MultiplayerFromHostSetPacketHandler()

void Wifi_MultiplayerFromHostSetPacketHandler ( WifiFromHostPacketHandler  func)

Set a handler on a client console for packets received from the host.

Parameters
funcPointer to packet handler (see WifiFromHostPacketHandler for info).

◆ Wifi_MultiplayerGetClientMask()

u16 Wifi_MultiplayerGetClientMask ( void  )

Returns a mask where each bit represents an connected client.

Bit 0 is always set to 1 as it represents the host. Bits 1 to 15 represent all possible clients.

The bits are set to 1 when the client is authenticated and associated.

This function must be used while in multiplayer host mode.

Returns
The mask of players connected to this console acting as a host.

◆ Wifi_MultiplayerGetClients()

int Wifi_MultiplayerGetClients ( int  max_clients,
Wifi_ConnectedClient client_data 
)

Get information of clients connected to a multiplayer host.

This function must be used while in multiplayer host mode.

This function expects you to pass an empty array of clients in client_data with a length of max_clients. It will check the current list of clients connected to this host and save them to the array, up to max_clients. It returns the actual number of clients saved to the struct.

Parameters
max_clientsMaximum number of clients that can be stored in client_data.
client_dataPointer to an array type Wifi_ConnectedClient that has a length of at least max_clients.
Returns
It returns the actual number of clients connected (up to a maximum of max_clients). On error, it returns a negative number.

◆ Wifi_MultiplayerGetNumClients()

int Wifi_MultiplayerGetNumClients ( void  )

Get the number of clients connected to this DS acting as a multiplayer host.

Clients are considered connected when they are authenticated and associated.

This function must be used while in multiplayer host mode.

Returns
The number of clients connected to this console acting as a host.

◆ Wifi_MultiplayerHostCmdTxFrame()

int Wifi_MultiplayerHostCmdTxFrame ( const void *  data,
u16  datalen 
)

Sends a multiplayer host frame.

This frame will be sent to all clients, and clients will reply automatically if they have prepared any reply frame.

Clients can use Wifi_MultiplayerFromHostSetPacketHandler() to register a packet handler for packets sent with Wifi_MultiplayerHostCmdTxFrame(). They will be received with type WIFI_MPTYPE_CMD.

Parameters
dataPointer to the data to be sent.
datalenSize of the data in bytes. It can go up to the size defined when calling Wifi_MultiplayerHostMode().
Returns
On success it returns 0, else it returns a negative value.

◆ Wifi_MultiplayerHostMode()

int Wifi_MultiplayerHostMode ( int  max_clients,
size_t  host_packet_size,
size_t  client_packet_size 
)

Sets the WiFI hardware in mulitplayer host mode.

While in host mode, call Wifi_BeaconStart() to start announcing that this DS is acting as an access point. This will allow other consoles to connect discover it and connect to it.

Use Wifi_LibraryModeReady() to check when the mode change is finished.

The sizes used in this function are only the size of the custom data sent by the application. The size of the headers is added internally by the library.

Parameters
max_clientsMaximum number of allowed clients connected to the console. The minimum is 1, the maximum is 15.
host_packet_sizeSize of the user data sent in packets from the host to the client.
client_packet_sizeSize of the user data sent in packets from the client to the host.
Returns
Returns 0 on success, -1 if the requested size is too big.

◆ Wifi_MultiplayerHostName()

void Wifi_MultiplayerHostName ( const void *  buffer,
u8  len 
)

Set the name and name length fields in beacon packets.

This information can be obtained from clients from the "name" and "name_len" fields of the "nintendo" struct in a Wifi_AccessPoint. DSWifi doesn't use this information in any way, so you are free to store any information you want here. Normally, a client would use this field to display the name of each DS that is in multiplayer host mode.

If you use this function to overwrite the default values of DSWifi, you need to do it before calling Wifi_BeaconStart().

This function will copy exactly DSWIFI_BEACON_NAME_SIZE bytes from "buffer". By default, DSWifi uses the player name stored in the DS firmware, so the format is UTF-16LE.

The "len" argument is copied directly to the beacon information, it isn't used by this function to determine how much data to copy.

Parameters
bufferSource buffer to be copied to the "name" field of the beacon packet. It must be DSWIFI_BEACON_NAME_SIZE bytes in size.
lenValue to be copied to the "name_len" field of the beacon packet.

◆ Wifi_MultiplayerHostToClientDataTxFrame()

int Wifi_MultiplayerHostToClientDataTxFrame ( int  aid,
const void *  data,
u16  datalen 
)

Sends a data frame to the client with the specified association ID.

This function sends an arbitrary data packet that doesn't trigger any response.

Clients can use Wifi_MultiplayerFromHostSetPacketHandler() to register a packet handler for packets sent with Wifi_MultiplayerHostToClientDataTxFrame(). They will be received with type WIFI_MPTYPE_DATA.

Parameters
aidAssociation ID of the client that will receive the packet.
dataPointer to the data to be sent.
datalenSize of the data in bytes.
Returns
On success it returns 0, else it returns a negative value.

◆ Wifi_MultiplayerKickClientByAID()

void Wifi_MultiplayerKickClientByAID ( int  association_id)

Kick the client with the provided AID from the host.

Parameters
association_idThe AID of the client to kick.