summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src/dswifi/inc/dswifi9.inc
blob: 08f29a007a5ce7022ef1a9e964bed4a0487e6782 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
(*
  $Id$
  ------------------------------------------------------------------------------
  DSWifi Project - Arm9 Library Header File (dswifi9.h)
  (C) 2005-2006 Stephen Stair - sgstair@akkit.org - http://www.akkit.org
  ****************************************************************************** 
  DSWifi Lib and test materials are licenced under the MIT open source licence:
  Copyright (c) 2005-2006 Stephen Stair
  
  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  of the Software, and to permit persons to whom the Software is furnished to do
  so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  ------------------------------------------------------------------------------

    
  Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  (http://www.freepascal.org)
   
  Copyright (C) 2006  Francesco Lombardi
  Check http://sourceforge.net/projects/libndsfpc for updates
   
  ------------------------------------------------------------------------------

  Comments:

*)


{$include dswifi_version.inc}

{$include sys/socket.inc}
{$include netinet/in.inc}
{$include netdb.inc}

{$ifdef NDS_INTERFACE}

const
  WIFIINIT_OPTION_USELED          = $0002;

  WIFIINIT_OPTION_USEHEAP_64      = $0000;
  WIFIINIT_OPTION_USEHEAP_128     = $1000;
  WIFIINIT_OPTION_USEHEAP_256     = $2000;
  WIFIINIT_OPTION_USEHEAP_512     = $3000;
  WIFIINIT_OPTION_USECUSTOMALLOC  = $4000;
  WIFIINIT_OPTION_HEAPMASK        = $F000;

  WFLAG_PACKET_DATA               = $0001;
  WFLAG_PACKET_MGT                = $0002;
  WFLAG_PACKET_BEACON             = $0004;
  WFLAG_PACKET_CTRL               = $0008;

  WFLAG_PACKET_ALL                = $FFFF;


  WFLAG_APDATA_ADHOC              = $0001;
  WFLAG_APDATA_WEP                = $0002;
  WFLAG_APDATA_WPA                = $0004;
  WFLAG_APDATA_COMPATIBLE         = $0008;
  WFLAG_APDATA_EXTCOMPATIBLE      = $0010;
  WFLAG_APDATA_SHORTPREAMBLE      = $0020;
  WFLAG_APDATA_ACTIVE             = $8000;

  WFC_CONNECT = true;
  INIT_ONLY = false;

type
  TWIFI_RETURN = (
    WIFI_RETURN_OK          =	0, 
    WIFI_RETURN_LOCKFAILED  = 1, 
    WIFI_RETURN_ERROR       =	2, 
    WIFI_RETURN_PARAMERROR  = 3  
  );

  TWIFI_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
  );

  TWIFI_MODE = (
    WIFIMODE_DISABLED,
    WIFIMODE_NORMAL,
    WIFIMODE_SCAN,
    WIFIMODE_ASSOCIATE,
    WIFIMODE_ASSOCIATED,
    WIFIMODE_DISASSOCIATE,
    WIFIMODE_CANNOTASSOCIATE
  );

  TWIFI_AUTHLEVEL = (
    WIFI_AUTHLEVEL_DISCONNECTED,
    WIFI_AUTHLEVEL_AUTHENTICATED,
    WIFI_AUTHLEVEL_ASSOCIATED,
    WIFI_AUTHLEVEL_DEASSOCIATED
  );

  TWIFIGETDATA = (
    WIFIGETDATA_MACADDRESS,			
    WIFIGETDATA_NUMWFCAPS,			
    MAX_WIFIGETDATA
  );


  TWEPMODES = (
    WEPMODE_NONE    = 0,
    WEPMODE_40BIT   = 1,
    WEPMODE_128BIT  = 2
  );
  

  TWIFI_ASSOCSTATUS = (
    ASSOCSTATUS_DISCONNECTED, 
    ASSOCSTATUS_SEARCHING, 
    ASSOCSTATUS_AUTHENTICATING, 
    ASSOCSTATUS_ASSOCIATING, 
    ASSOCSTATUS_ACQUIRINGDHCP, 
    ASSOCSTATUS_ASSOCIATED,	
    ASSOCSTATUS_CANNOTCONNECT 
  );

var
  ASSOCSTATUS_STRINGS: array [0..0] of pcchar; cvar; external;

{
var
  ASSOCSTATUS_STRINGS: array [TWIFI_ASSOCSTATUS] of string = (
    '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!
    'ASSOCSTATUS_CANNOTCONNECT'	// error in connecting...
  );
}

type

  WIFI_TXHEADER =  record
    enable_flags: cuint16;
    unknown: cuint16;
    countup: cuint16;
    beaconfreq: cuint16;
    tx_rate: cuint16;
    tx_length: cuint16;
  end;
  TWIFI_TXHEADER = WIFI_TXHEADER;
	PWIFI_TXHEADER = ^WIFI_TXHEADER;

  WIFI_RXHEADER =  record
    a: cuint16;
    b: cuint16;
    c: cuint16;
    d: cuint16;
    byteLength: cuint16;
    rssi_: cuint16;
  end;
  TWIFI_RXHEADER = WIFI_RXHEADER;
  PWIFI_RXHEADER = ^WIFI_RXHEADER;

  WIFI_ACCESSPOINT = packed record
    ssid: array [0..32] of cchar; 
    ssid_len: cchar; 
    bssid: array [0..5] of cuint8; 
    macaddr: array [0..5] of cuint8; 
    maxrate: cuint16; 
    timectr: cuint32; 
    rssi: cuint16; 
    flags: cuint16; 
    spinlock: cuint32; 
    channel: cuint8; 
    rssi_past: array [0..7] of cuint8; 
    base_rates: array [0..15] of cuint8; 
  end;
  TWIFI_ACCESSPOINT = WIFI_ACCESSPOINT;
  PWIFI_ACCESSPOINT = ^WIFI_ACCESSPOINT;

  WifiPacketHandler = procedure(packetID, packetlength: cint);

  WifiSyncHandler = procedure;


function Wifi_Init(initflags: cint): culong; cdecl; external;
function Wifi_CheckInit(): cint; cdecl; external;
procedure Wifi_DisableWifi(); cdecl; external;
procedure Wifi_EnableWifi(); cdecl; external;
procedure Wifi_SetPromiscuousMode(enable: cint); cdecl; external;
procedure Wifi_ScanMode(); cdecl; external;
procedure Wifi_SetChannel(channel: cint); cdecl; external;
function Wifi_GetNumAP(): cint; cdecl; external;
function Wifi_GetAPData(apnum: cint; apdata: PWifi_AccessPoint): cint; cdecl; external;
function Wifi_FindMatchingAP(numaps: cint; apdata: PWifi_AccessPoint; match_dest: PWifi_AccessPoint): cint; cdecl; external;
function Wifi_ConnectAP(apdata: PWifi_AccessPoint; wepmode, wepkeyid: cint; wepkey: pcuchar): cint; cdecl; external;
procedure Wifi_AutoConnect(); cdecl; external;
function Wifi_AssocStatus(): cint; cdecl; external;
function Wifi_DisconnectAP(): cint; cdecl; external;
procedure Wifi_Timer(num_ms: cint); cdecl; external;
function Wifi_GetIP(): cuint32; cdecl; external;
function Wifi_GetIPInfo(pGateway, pSnmask, pDns1, pDns2: pin_addr): cuint32; cdecl; external;
procedure Wifi_SetIP(IPaddr, gateway, subnetmask, dns1, dns2: u32); cdecl; external;
function Wifi_GetData(datatype, bufferlen: cint; buffer: pcuchar): cint; cdecl; external;
function Wifi_GetStats(statnum: cint): cuint32; cdecl; external;
function Wifi_RawTxFrame(datalen, rate: cuint16; data: pcuint16): cint; cdecl; external;
procedure Wifi_RawSetPacketHandler(wphfunc: WifiPacketHandler); cdecl; external;
function Wifi_RxRawReadPacket(packetID, readlength: cint32; data: pcuint16): cint; cdecl; external;
procedure Wifi_Update(); cdecl; external;
procedure Wifi_Sync(); cdecl; external;
procedure Wifi_SetSyncHandler(sh: WifiSyncHandler); cdecl; external;
//procedure Wifi_SetSyncHandler(sh: pointer); cdecl; external;
function Wifi_InitDefault(useWifiSettings: cbool): cbool; cdecl; external;
{$endif NDS_INTERFACE}