1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WM - include
3   File:     nwm.h
4 
5   Copyright 2007-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2008-11-19#$
14   $Rev: 9345 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef LIBRARIES_NWM_ARM9_NWM_H__
19 #define LIBRARIES_NWM_ARM9_NWM_H__
20 
21 #ifdef  __cplusplus
22 extern "C" {
23 #endif
24 
25 /*===========================================================================*/
26 
27 #include <twl.h>
28 #include <nitro/wm.h>
29 
30 /*---------------------------------------------------------------------------*
31     Constant Definitions
32  *---------------------------------------------------------------------------*/
33 
34 #define NWM_NUM_MAX_AP_AID              2007   // The maximum value possible for the AssociationID provided by the wireless router
35 
36 #define NWM_SIZE_SSID                     32
37 #define NWM_SIZE_MACADDR                   6
38 #define NWM_SIZE_BSSID                    NWM_SIZE_MACADDR
39 
40 #define NWM_SIZE_WEP_40BIT                 5
41 #define NWM_SIZE_WEP_104BIT               13
42 #define NWM_SIZE_WEP_128BIT               16
43 
44 #define NWM_SIZE_WEP                      20   // for preserving WM (DS connection settings) compatibility
45 
46 #define NWM_WEPMODE_OPEN                   WM_WEPMODE_NO
47 #define NWM_WEPMODE_40BIT                  WM_WEPMODE_40BIT
48 #define NWM_WEPMODE_104BIT                 WM_WEPMODE_104BIT
49 #define NWM_WEPMODE_128BIT                 WM_WEPMODE_128BIT
50 
51 #define NWM_WPAMODE_WPA_TKIP               (WM_WEPMODE_128BIT + 1)
52 #define NWM_WPAMODE_WPA2_TKIP              (WM_WEPMODE_128BIT + 2)
53 #define NWM_WPAMODE_WPA_AES                (WM_WEPMODE_128BIT + 3)
54 #define NWM_WPAMODE_WPA2_AES               (WM_WEPMODE_128BIT + 4)
55 
56 
57 #define NWM_BSS_DESC_SIZE                 64   // Size of the buffer transferred with the NWM_StartScan function to store parent information
58 #define NWM_BSS_DESC_SIZE_MAX            512
59 #define NWM_FRAME_SIZE_MAX              1522   // Maximum data frame size: 1500(MTU) + 22(802.3 header)
60 #define NWM_SCAN_NODE_MAX                 32   // Maximum number of parent devices that can be found by a single Scan
61 #define NWM_SIZE_SCANBUF_MAX           65535   // Maximum buffer size
62 
63 #define NWM_SYSTEM_BUF_SIZE           (0x00003000)
64 
65 // bitmask for capability information
66 #define NWM_CAPABILITY_ESS_MASK         0x0001
67 #define NWM_CAPABILITY_ADHOC_MASK       0x0002
68 #define NWM_CAPABILITY_CP_POLLABLE_MASK 0x0004
69 #define NWM_CAPABILITY_CP_POLL_REQ_MASK 0x0008
70 #define NWM_CAPABILITY_PRIVACY_MASK     0x0010
71 #define NWM_CAPABILITY_SPREAMBLE_MASK   0x0020
72 #define NWM_CAPABILITY_PBCC_MASK        0x0040
73 #define NWM_CAPABILITY_CH_AGILITY_MASK  0x0800
74 #define NWM_CAPABILITY_SPECTRUM_MASK    0x0100
75 #define NWM_CAPABILITY_QOS_MASK         0x0200
76 #define NWM_CAPABILITY_SSLOTTIME_MASK   0x0400
77 #define NWM_CAPABILITY_APSD_MASK        0x0800
78 
79 
80 #define NWM_SCANTYPE_PASSIVE    0
81 #define NWM_SCANTYPE_ACTIVE     1
82 
83 #define NWM_DEFAULT_PASSIVE_SCAN_PERIOD 105 /* Note that the default NWM values are larger than the default WM values */
84 #define NWM_DEFAULT_ACTIVE_SCAN_PERIOD   30 /* Note that NWM uses different default values for active and passive scans */
85 
86 #define NWM_RATESET_1_0M                0x0001
87 #define NWM_RATESET_2_0M                0x0002
88 #define NWM_RATESET_5_5M                0x0004
89 #define NWM_RATESET_6_0M                0x0008
90 #define NWM_RATESET_9_0M                0x0010
91 #define NWM_RATESET_11_0M               0x0020
92 #define NWM_RATESET_12_0M               0x0040
93 #define NWM_RATESET_18_0M               0x0080
94 #define NWM_RATESET_24_0M               0x0100
95 #define NWM_RATESET_36_0M               0x0200
96 #define NWM_RATESET_48_0M               0x0400
97 #define NWM_RATESET_54_0M               0x0800
98 #define NWM_RATESET_11B_MASK            ( NWM_RATESET_1_0M | NWM_RATESET_2_0M | NWM_RATESET_5_5M | NWM_RATESET_11_0M )
99 #define NWM_RATESET_11G_MASK            ( NWM_RATESET_1_0M | NWM_RATESET_2_0M | NWM_RATESET_5_5M | NWM_RATESET_11_0M     \
100                                         | NWM_RATESET_6_0M | NWM_RATESET_9_0M | NWM_RATESET_12_0M | NWM_RATESET_18_0M    \
101                                         | NWM_RATESET_24_0M | NWM_RATESET_36_0M | NWM_RATESET_48_0M | NWM_RATESET_54_0M )
102 
103 #define NWM_WPA_PSK_LENGTH               32
104 #define NWM_WPA_PASSPHRASE_LENGTH_MAX    64
105 
106 
107 /* Link levels */
108 #define NWM_RSSI_INFRA_LINK_LEVEL_1  12
109 #define NWM_RSSI_INFRA_LINK_LEVEL_2  17
110 #define NWM_RSSI_INFRA_LINK_LEVEL_3  22
111 
112 #define NWM_RSSI_ADHOC_LINK_LEVEL_1  12 /* [TODO] TBD */
113 #define NWM_RSSI_ADHOC_LINK_LEVEL_2  17 /* [TODO] TBD */
114 #define NWM_RSSI_ADHOC_LINK_LEVEL_3  22 /* [TODO] TBD */
115 
116 /*---------------------------------------------------------------------------*
117     Macro Definitions
118  *---------------------------------------------------------------------------*/
119 
120 
121 // ID for each API
122 typedef enum NWMApiid
123 {
124     NWM_APIID_INIT = 0,                 // NWM_Init()
125     NWM_APIID_RESET,                    // NWM_Reset()
126     NWM_APIID_END,                      // NWM_End()
127 
128     NWM_APIID_LOAD_DEVICE,              // NWM_LoadDevice()
129     NWM_APIID_UNLOAD_DEVICE,            // NWM_UnloadDevice()
130     NWM_APIID_OPEN,                     // NWM_Open()
131     NWM_APIID_CLOSE,                    // NWM_Close()
132 
133     NWM_APIID_START_SCAN,               // NWM_StartScan()
134     NWM_APIID_CONNECT,                  // NWM_Connect()
135     NWM_APIID_DISCONNECT,               // NWM_Disconnect()
136     NWM_APIID_SET_RECEIVING_BUF,        // NWM_SetReceivingFrameBuffer()
137     NWM_APIID_SEND_FRAME,               // NWM_SendFrame()
138     NWM_APIID_UNSET_RECEIVING_BUF,      // NWM_UnsetReceivingFrameBuffer()
139     NWM_APIID_SET_WEPKEY,               // NWM_SetWEPKey()
140     NWM_APIID_SET_PS_MODE,              // NWM_SetPowerSaveMode()
141 
142     NWM_APIID_SET_WPA_KEY,              //
143     NWM_APIID_SET_WPA_PARAMS,           //
144 
145     NWM_APIID_CREATE_QOS,               //
146     NWM_APIID_SET_WPA_PSK,              // NWM_SetWPAPSK()
147     NWM_APIID_INSTALL_FIRMWARE,         // NWMi_InstallFirmware()
148     NWM_APIID_ASYNC_KIND_MAX,           //  : Type of asynchronous process
149 
150     NWM_APIID_INDICATION = 128,         //  : For indication callback
151 
152     NWM_APIID_UNKNOWN = 255             //  : Value returned from ARM7 at unknown command number
153 }
154 NWMApiid;
155 
156 
157 // API result codes
158 typedef enum NWMRetCode
159 {
160     NWM_RETCODE_SUCCESS         =  0,
161     NWM_RETCODE_FAILED          =  1,
162     NWM_RETCODE_OPERATING       =  2,
163     NWM_RETCODE_ILLEGAL_STATE   =  3,
164     NWM_RETCODE_NWM_DISABLE     =  4,
165     NWM_RETCODE_INVALID_PARAM   =  5,
166     NWM_RETCODE_FIFO_ERROR      =  6,
167     NWM_RETCODE_FATAL_ERROR     =  7,   // Error that the software cannot handle
168     NWM_RETCODE_NETBUF_ERROR    =  8,
169     NWM_RETCODE_WMI_ERROR       =  9,
170     NWM_RETCODE_SDIO_ERROR      = 10,
171     NWM_RETCODE_RECV_IND        = 11,
172     NWM_RETCODE_INDICATION      = 12,   // internal use only
173 
174     NWM_RETCODE_MAX
175 } NWMRetCode;
176 
177 // NWM state codes
178 typedef enum NWMState
179 {
180     NWM_STATE_NONE            = 0x0000,
181     NWM_STATE_INITIALIZED     = 0x0001,    // INITIALIZED state
182     NWM_STATE_LOADED          = 0x0002,    // LOADED state
183     NWM_STATE_DISCONNECTED    = 0x0003,    // DISCONNECTED state
184     NWM_STATE_INFRA_CONNECTED = 0x0004,    // CONNECTED STA (infrastructure) state
185     NWM_STATE_ADHOC_CONNECTED = 0x0005     // CONNECTED STA (ad hoc) state
186 }
187 NWMState;
188 
189 typedef enum NWMReasonCode
190 {
191     NWM_REASON_API_SUCCESS          = 0,
192 
193     /* for infra mode */
194     NWM_REASON_NO_NETWORK_AVAIL     = 1,
195     NWM_REASON_LOST_LINK            = 2,
196     NWM_REASON_DISCONNECT_CMD       = 3,
197     NWM_REASON_BSS_DISCONNECTED     = 4,
198     NWM_REASON_AUTH_FAILED          = 5,
199     NWM_REASON_ASSOC_FAILED         = 6,
200     NWM_REASON_NO_RESOURCES_AVAIL   = 7,
201     NWM_REASON_CSERV_DISCONNECT     = 8,
202     NWM_REASON_INVAILD_PROFILE      = 9,
203 
204     NWM_REASON_WEP_KEY_ERROR        =10,
205 
206     /* for WPA supplicant */
207     NWM_REASON_WPA_KEY_ERROR        =11,
208     NWM_REASON_TKIP_MIC_ERROR       =12,
209 
210     /* for Wireless QoS (802.11e) */
211     NWM_REASON_NO_QOS_RESOURCES_AVAIL   = 13,
212 
213     NWM_REASON_UNKNOWN
214 
215 } NWMReasonCode;
216 
217 typedef enum NWMAuthMode
218 {
219   NWM_AUTHMODE_OPEN,    /* dot11 authentication */
220   NWM_AUTHMODE_SHARED,  /* dot11 authentication */
221   NWM_AUTHMODE_WPA_PSK_TKIP         = NWM_WPAMODE_WPA_TKIP,   /* Be careful to keep this from overlapping with WCM_WEPMODE_* */
222   NWM_AUTHMODE_WPA2_PSK_TKIP        = NWM_WPAMODE_WPA2_TKIP,
223   NWM_AUTHMODE_WPA_PSK_AES          = NWM_WPAMODE_WPA_AES,
224   NWM_AUTHMODE_WPA2_PSK_AES         = NWM_WPAMODE_WPA2_AES
225 }
226 NWMAuthMode, NWMauthMode;
227 
228 
229 // Element ID of Information Elements
230 typedef enum NWMElementID {
231   NWM_ELEMENTID_SSID               = 0,
232   NWM_ELEMENTID_SUPPORTED_RATES    = 1,
233   NWM_ELEMENTID_FH_PARAMETER_SET   = 2,
234   NWM_ELEMENTID_DS_PARAMETER_SET   = 3,
235   NWM_ELEMENTID_CF_PARAMETER_SET   = 4,
236   NWM_ELEMENTID_TIM                = 5,
237   NWM_ELEMENTID_IBSS_PARAMETER_SET = 6,
238   NWM_ELEMENTID_COUNTRY            = 7,
239   NWM_ELEMENTID_HP_PARAMETERS      = 8,
240   NWM_ELEMENTID_HP_TABLE           = 9,
241   NWM_ELEMENTID_REQUEST            = 10,
242   NWM_ELEMENTID_QBSS_LOAD          = 11,
243   NWM_ELEMENTID_EDCA_PARAMETER_SET = 12,
244   NWM_ELEMENTID_TSPEC              = 13,
245   NWM_ELEMENTID_TRAFFIC_CLASS      = 14,
246   NWM_ELEMENTID_SCHEDULE           = 15,
247   NWM_ELEMENTID_CHALLENGE_TEXT     = 16,
248 
249   NWM_ELEMENTID_POWER_CONSTRAINT   = 32,
250   NWM_ELEMENTID_POWER_CAPABILITY   = 33,
251   NWM_ELEMENTID_TPC_REQUEST        = 34,
252   NWM_ELEMENTID_TPC_REPORT         = 35,
253   NWM_ELEMENTID_SUPPORTED_CHANNELS = 36,
254   NWM_ELEMENTID_CH_SWITCH_ANNOUNCE = 37,
255   NWM_ELEMENTID_MEASURE_REQUEST    = 38,
256   NWM_ELEMENTID_MEASURE_REPORT     = 39,
257   NWM_ELEMENTID_QUIET              = 40,
258   NWM_ELEMENTID_IBSS_DFS           = 41,
259   NWM_ELEMENTID_ERP_INFORMATION    = 42,
260   NWM_ELEMENTID_TS_DELAY           = 43,
261   NWM_ELEMENTID_TCLASS_PROCESSING  = 44,
262   NWM_ELEMENTID_HT_CAPABILITY      = 45,
263   NWM_ELEMENTID_QOS_CAPABILITY     = 46,
264   NWM_ELEMENTID_RSN                = 48,
265   NWM_ELEMENTID_EX_SUPPORTED_RATES = 50,
266   NWM_ELEMENTID_HT_INFORMATION     = 61,
267 
268   NWM_ELEMENTID_VENDOR             = 221,
269   NWM_ELEMENTID_NINTENDO           = 221
270 }
271 NWMElementID;
272 
273 typedef enum NWMPowerMode {
274   NWM_POWERMODE_ACTIVE,
275   NWM_POWERMODE_STANDARD,
276   NWM_POWERMODE_UAPSD
277 } NWMPowerMode;
278 
279 typedef enum NWMAccessCategory {
280   NWM_AC_BE,          /* best effort */
281   NWM_AC_BK,          /* background */
282   NWM_AC_VI,          /* video */
283   NWM_AC_VO,          /* voice */
284   NWM_AC_NUM
285 } NWMAccessCategory;
286 
287 typedef enum NWMNwType
288 {
289   NWM_NWTYPE_INFRA,
290   NWM_NWTYPE_ADHOC,
291   NWM_NWTYPE_WPS,
292   NWM_NWTYPE_NUM
293 } NWMNwType;
294 
295 typedef enum NWMFramePort
296 {
297     NWM_PORT_IPV4_ARP, /* for TCP/IP */
298     NWM_PORT_EAPOL,    /* for WPA supplicant */
299     NWM_PORT_OTHERS,
300     NWM_PORT_NUM
301 } NWMFramePort, NWMframePort;
302 
303 typedef void (*NWMCallbackFunc) (void *arg);     // Callback type for the NWM API
304 
305 /*---------------------------------------------------------------------------*
306     Structure Definitions
307  *---------------------------------------------------------------------------*/
308 
309 typedef struct NWMBssDesc
310 {
311     u16     length;                    // 2
312     s16     rssi;                      // 4
313     u8      bssid[NWM_SIZE_BSSID];     // 10
314     u16     ssidLength;                // 12
315     u8      ssid[NWM_SIZE_SSID];       // 44
316     u16     capaInfo;                  // 46
317     struct
318     {
319         u16     basic;                 // 48
320         u16     support;               // 50
321     }
322     rateSet;
323     u16     beaconPeriod;              // 52
324     u16     dtimPeriod;                // 54
325     u16     channel;                   // 56
326     u16     cfpPeriod;                 // 58
327     u16     cfpMaxDuration;            // 60
328     u16     reserved;                  // 62 just for compatibility with WM (must be 0)
329     u16     elementCount;              // 64
330     u16     elements[1];
331 } NWMBssDesc, NWMbssDesc;
332 
333 
334 typedef struct NWMInfoElements
335 {
336   u8  id;
337   u8  length;
338   u16 element[1];
339 }
340 NWMInfoElements;
341 
342 
343 //---------------------------------------
344 // NWM Scan parameter structure
345 typedef struct NWMScanParam
346 {
347     NWMBssDesc *scanBuf;                   // Buffer that stores parent information
348     u16         scanBufSize;               // Size of scanBuf
349     u16         channelList;               // List of channels (more than one can be specified) to scan
350     u16         channelDwellTime;          // Per-channel scan time (in ms)
351     u16         scanType;                  // passive or active
352     u8          bssid[NWM_SIZE_BSSID];     // MAC address to scan for (all parent devices will be targeted if this is 0xff)
353     u16         ssidLength;                // Length of the SSID to scan for (all nodes will be targeted if this is 0)
354     u8          ssid[NWM_SIZE_SSID];       // SSID to scan for
355     u16         rsv[6];
356 } NWMScanParam, NWMscanParam;
357 
358 // NWM Scan parameter structure
359 typedef struct NWMScanExParam
360 {
361     NWMBssDesc *scanBuf;                   // Buffer that stores parent information
362     u16         scanBufSize;               // Size of scanBuf
363     u16         channelList;               // List of channels (more than one can be specified) to scan
364     u16         channelDwellTime;          // Per-channel scan time (in ms)
365     u16         scanType;                  // passive or active
366     u8          bssid[NWM_SIZE_BSSID];     // MAC address to scan for (all parent devices will be targeted if this is 0xff)
367     u16         ssidLength;                // Length of the SSID to scan for (all nodes will be targeted if this is 0)
368     u8          ssid[NWM_SIZE_SSID];       // SSID to scan for
369     u16         ssidMatchLength;           // Matching length of the SSID to scan for
370     u16         rsv[5];
371 } NWMScanExParam, NWMscanExParam;
372 
373 
374 //---------------------------------------
375 // NWM  WPA parameter structure
376 
377 typedef struct NWMWpaParam {
378     u16   auth;     // NWMAuthMode (can use PSK only)
379     u8    psk[NWM_WPA_PSK_LENGTH];
380 } NWMWpaParam;
381 
382 // Buffer structure for receiving frames
383 typedef struct NWMRecvFrameHdr
384 {
385   u8   da[NWM_SIZE_MACADDR];
386   u8   sa[NWM_SIZE_MACADDR];
387   u8   pid[2];
388   u8   frame[2];
389 } NWMRecvFrameHdr;
390 
391 //==========================================================================================
392 
393 // Normal callback arguments
394 typedef struct NWMCallback
395 {
396     u16     apiid;
397     u16     retcode;
398 
399 } NWMCallback;
400 
401 // Callback arguments for the NWM_StartScan function
402 typedef struct NWMStartScanCallback
403 {
404     u16     apiid;
405     u16     retcode;
406     u32     channelList;               // Scanned channel list, regardless of whether found or not.
407     u8      reserved[2];               // padding
408     u16     bssDescCount;              // Number of parents that were found
409     u32     allBssDescSize;
410     NWMBssDesc *bssDesc[NWM_SCAN_NODE_MAX];  // Beginning address of the parent information
411     u16     linkLevel[NWM_SCAN_NODE_MAX];   // Reception signal strength
412 
413 } NWMStartScanCallback, NWMstartScanCallback;
414 
415 // Callback arguments for the NWM_Connect function
416 typedef struct NWMConnectCallback
417 {
418     u16     apiid;
419     u16     retcode;
420     u16     channel;
421     u8      bssid[NWM_SIZE_BSSID];
422     s8      rssi;
423     u8      padding;
424     u16     aid;                       // Only when CONNECTED. AID assigned to self
425     u16     reason;                    // reason when disconnecting. This is defined in NWMReasonCode.
426     u16     listenInterval;
427     u8      networkType;
428     u8      beaconIeLen;
429     u8      assocReqLen;
430     u8      assocRespLen;
431     u8      assocInfo[2]; /* this field consists of beaconIe, assocReq, assocResp */
432 } NWMConnectCallback, NWMconnectCallback;
433 
434 // Callback arguments for the NWM_Disconnect function
435 typedef struct NWMDisconnectCallback
436 {
437     u16   apiid;
438     u16   retcode;
439     u16   reason;
440     u16   rsv;
441 } NWMDisconnectCallback, NWMdisconnectCallback;
442 
443 // Callback arguments for the NWM_SendFrame function
444 typedef struct NWMSendFrameCallback
445 {
446     u16     apiid;
447     u16     retcode;
448     NWMCallbackFunc callback;
449 } NWMSendFrameCallback;
450 
451 // Callback arguments for the NWM_SetReceivingFrameBuffer function
452 typedef struct NWMReceivingFrameCallback
453 {
454   u16   apiid;
455   u16   retcode;
456   u16   port;
457   u16   rssi;
458   u32   length;
459   NWMRecvFrameHdr *recvBuf;
460 
461 } NWMReceivingFrameCallback;
462 
463 
464 /*===========================================================================
465   NWM APIs
466   ===========================================================================*/
467 
468 /*---------------------------------------------------------------------------*
469   Name:         NWM_Init
470 
471   Description:  Initializes the NWM library.
472                 Synchronous function that only initializes ARM9.
473 
474   Arguments:    sysBuf: Pointer to a buffer allocated by the caller.
475 
476                 bufSize: Size of the buffer allocated by the caller.
477 
478                 dmaNo: DMA number for the NWM library to use.
479 
480   Returns:      NWMRetCode: Returns the processing result.
481  *---------------------------------------------------------------------------*/
482 NWMRetCode NWM_Init(void* sysBuf, u32 bufSize, u8 dmaNo);
483 
484 /*---------------------------------------------------------------------------*
485   Name:         NWM_Reset
486 
487   Description:  Restarts the TWL wireless driver and resets the TWL wireless module.
488 
489   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
490 
491   Returns:      NWMRetCode: Returns the processing result.
492                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
493 
494  *---------------------------------------------------------------------------*/
495 NWMRetCode NWM_Reset(NWMCallbackFunc callback);
496 
497 /*---------------------------------------------------------------------------*
498   Name:         NWM_LoadDevice
499 
500   Description:  Starts the TWL wireless module.
501                 There will be an internal state transition from NWM_STATE_INITIALIZED to NWM_STATE_LOADED.
502 
503 
504   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
505 
506   Returns:      NWMRetCode: Returns the processing result.
507                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
508 
509  *---------------------------------------------------------------------------*/
510 NWMRetCode NWM_LoadDevice(NWMCallbackFunc callback);
511 
512 /*---------------------------------------------------------------------------*
513   Name:         NWM_UnloadDevice
514 
515   Description:  Shuts down the TWL wireless module.
516                 There will be an internal state transition from NWM_STATE_LOADED to NWM_STATE_INITIALIZED.
517 
518 
519   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
520 
521   Returns:      NWMRetCode: Returns the processing result.
522                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
523 
524  *---------------------------------------------------------------------------*/
525 NWMRetCode NWM_UnloadDevice(NWMCallbackFunc callback);
526 
527 /*---------------------------------------------------------------------------*
528   Name:         NWM_Open
529 
530   Description:  Allows use of TWL wireless functionality.
531                 There will be an internal state transition from NWM_STATE_LOADED to NWM_STATE_DISCONNECTED.
532 
533 
534   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
535 
536   Returns:      NWMRetCode: Returns the processing result.
537                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
538 
539  *---------------------------------------------------------------------------*/
540 NWMRetCode NWM_Open(NWMCallbackFunc callback);
541 
542 /*---------------------------------------------------------------------------*
543   Name:         NWM_Close
544 
545   Description:  Disables TWL wireless functionality.
546                 There will be an internal state transition from NWM_STATE_DISCONNECTED to NWM_STATE_LOADED.
547 
548 
549   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
550 
551   Returns:      NWMRetCode: Returns the processing result.
552                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
553 
554  *---------------------------------------------------------------------------*/
555 NWMRetCode NWM_Close(NWMCallbackFunc callback);
556 
557 /*---------------------------------------------------------------------------*
558   Name:         NWM_End
559 
560   Description:  Shuts down the NWM library.
561                 This is a synchronous function that only shuts down processing on the ARM9.
562 
563   Arguments:    None.
564 
565   Returns:      NWMRetCode: Returns the processing result.
566  *---------------------------------------------------------------------------*/
567 NWMRetCode NWM_End(void);
568 
569 /*---------------------------------------------------------------------------*
570   Name:         NWM_StartScan
571 
572   Description:  Starts scanning for an AP.
573                 A single function call can get parent information for multiple devices.
574                 There are no state transitions during or after a scan.
575 
576   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
577                                 Arguments will be returned as a NWMStartScanCallback structure.
578                 param: Pointer to a structure that shows information on scan settings.
579                                 The ARM7 directly writes scan result information from param to scanBuf, so it must match the cache line.
580                                 See the NWMScanParam structure for individual parameters.
581 
582 
583   Returns:      NWMRetCode: Returns the processing result.
584                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
585 
586  *---------------------------------------------------------------------------*/
587 NWMRetCode NWM_StartScan(NWMCallbackFunc callback, const NWMScanParam *param);
588 
589 /*---------------------------------------------------------------------------*
590   Name:         NWM_StartScanEx
591 
592   Description:  Starts scanning for an AP.
593                 A single function call can get parent information for multiple devices.
594                 There are no state transitions during or after a scan.
595                 You can run a partial SSID match on the scan results.
596 
597   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
598                                 Arguments will be returned as a NWMStartScanCallback structure.
599                 param: Pointer to a structure that shows information on scan settings.
600                                 Compare the target SSID with the scan results from the wireless module only for the length specified by ssidMatchLength, then write out only the relevant scan results.
601                                 The ARM7 directly writes scan result information from param to scanBuf, so it must match the cache line.
602                                 See the NWMScanExParam structure for individual parameters.
603 
604 
605 
606 
607   Returns:      NWMRetCode: Returns the processing result.
608                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
609 
610  *---------------------------------------------------------------------------*/
611 NWMRetCode NWM_StartScanEx(NWMCallbackFunc callback, const NWMScanExParam *param);
612 
613 /*---------------------------------------------------------------------------*
614   Name:         NWM_Connect
615 
616   Description:  Connects to an AP. This cannot connect to DS parent devices.
617 
618   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
619                                 Arguments will be returned as a NWMConnectCallback structure.
620                 nwType: Takes the value defined by NWMNwType.
621                                 In general, use NWM_NWTYPE_INFRA.
622                 pBdesc: Information on the AP to connect to.
623                                 Specifies the structure obtained with NWM_StartScan.
624                                 Instances of this structure are forcibly stored in the cache.
625                                 See the NWMBssDesc structure for individual parameters.
626 
627   Returns:      NWMRetCode: Returns the processing result.
628                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
629 
630  *---------------------------------------------------------------------------*/
631 NWMRetCode NWM_Connect(NWMCallbackFunc callback, u8 nwType, const NWMBssDesc *pBdesc);
632 
633 /*---------------------------------------------------------------------------*
634   Name:         NWM_Disconnect
635 
636   Description:  Disconnects from an access point.
637 
638   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
639                                 Arguments will be returned as a NWMDisconnectCallback structure.
640 
641   Returns:      NWMRetCode: Returns the processing result.
642                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
643 
644  *---------------------------------------------------------------------------*/
645 NWMRetCode NWM_Disconnect(NWMCallbackFunc callback);
646 
647 /*---------------------------------------------------------------------------*
648   Name:         NWM_SetWEPKey
649 
650   Description:  Configures the WEP encryption mode and key.
651                 You must configure these before calling the NWM_Connect function.
652 
653   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
654                 wepmode     -   NWM_WEPMODE_OPEN  : No encryption feature.
655                                 NWM_WEPMODE_40BIT : RC4 (40bit) encryption mode.
656                                 NWM_WEPMODE_104BIT: RC4 (104bit) encryption mode.
657                                 NWM_WEPMODE_128BIT: RC4 (128bit) encryption mode.
658                 wepkeyid    -   Selects which of the 4 specified wepkeys to use for sending data.
659                                 Specify using 0-3.
660                 wepkey      -   Pointer to the encryption key data (80 bytes).
661                                 Key data consists of 4 pieces of data, each 20 bytes long.
662                                 Of each 20 bytes,
663                                  5 bytes in 40-bit mode
664                                 13 bytes in 104-bit mode
665                                 16 bytes in 128-bit mode
666                                 are used.
667                                 The data entity is forcibly stored in cache.
668                 authMode    -   Authentication mode when connecting.
669                                 NWM_AUTHMODE_OPEN  : Open authentication
670                                 NWM_AUTHMODE_SHARED: Shared key authentication
671 
672   Returns:      NWMRetCode: Returns the processing result.
673                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
674 
675  *---------------------------------------------------------------------------*/
676 NWMRetCode NWM_SetWEPKey(NWMCallbackFunc callback, u16 wepmode, u16 wepkeyid, const u8 *wepkey, u16 authMode);
677 
678 /*---------------------------------------------------------------------------*
679   Name:         NWM_Passphrase2PSK
680 
681   Description:  Calculates the PSK from a WPA passphrase. Synchronous function.
682 
683   Arguments:    passphrase: Pointer to a buffer with the WPA passphrase.
684                                  This has a maximum size of 63 bytes.
685                 ssid: Pointer to a buffer with the SSID of the access point to connect to
686                 ssidlen: SSID size of the access point to connect to
687                 psk: Pointer to the buffer that will store the calculated PSK.
688                                  This is fixed to 32 bytes.
689 
690   Returns:      None.
691  *---------------------------------------------------------------------------*/
692 void NWM_Passphrase2PSK(const u8 passphrase[NWM_WPA_PASSPHRASE_LENGTH_MAX], const u8 *ssid, u8 ssidlen, u8 psk[NWM_WPA_PSK_LENGTH]);
693 
694 /*---------------------------------------------------------------------------*
695   Name:         NWM_SetWPAPSK
696 
697   Description:  Configures the WPA encryption mode and key.
698                 You must configure these before calling the NWM_Connect function.
699 
700   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
701                 param: Pointer to a structure that shows information on WPA settings.
702                                 See the NWMWpaParam structure for individual parameters.
703 
704   Returns:      NWMRetCode: Returns the processing result.
705                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
706 
707  *---------------------------------------------------------------------------*/
708 NWMRetCode NWM_SetWPAPSK(NWMCallbackFunc callback, NWMWpaParam *param);
709 
710 /*---------------------------------------------------------------------------*
711   Name:         NWM_SetReceivingFrameBuffer
712 
713   Description:  Configures the receive buffer.
714 
715   Arguments:    callback: The callback function that is invoked when asynchronous processing finishes and when data is sent.
716 
717                                 Arguments will be returned as a NWMReceivingFrameCallback structure.
718                                 This entails NWM_RETCODE_RECV_IND when sending data.
719 
720                 recvBuf     -   Pointer to the data receive buffer.
721                                 Pay attention to the cache because the ARM7 writes data out directly.
722                 recvBufSize -   Size of data receive buffer.
723                                 The receive buffer count is an integer quotient of this size divided by 1536 (0x600) bytes. (Anything below the decimal point will be rounded off.)
724                                 To avoid losing received data, allocate at least 3072 (0xC00) bytes.
725                 protocol: Specifies which protocol the receive buffer is for.
726                                 NWM_PORT_IPV4_ARP: IPv4 TCP/IP data and ARP data
727                                                    (You should normally use this.)
728                                 NWM_PORT_EAPOL   : EAPOL data (for WPS)
729                                 NWM_PORT_OTHERS  : Other protocols
730 
731   Returns:      NWMRetCode: Returns the processing result.
732                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
733 
734  *---------------------------------------------------------------------------*/
735 NWMRetCode NWM_SetReceivingFrameBuffer(NWMCallbackFunc callback, u8* recvBuf, u16 recvBufSize, u16 protocol);
736 
737 /*---------------------------------------------------------------------------*
738   Name:         NWM_SendFrame
739 
740   Description:  Sets the data for the wireless module to send.
741                 Note that this does not guarantee that the transmission has completed.
742 
743   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
744                                 Arguments will be returned as a NWMSendFrameCallback structure.
745                 destAddr: Pointer to a buffer with the BSSID to send to.
746                 sendFrame: Pointer to the data to send.
747                                 Note that instances of the data to send will be forced to be stored in the cache.
748 
749                 sendFrameSize: The size of the data to send.
750 
751   Returns:      NWMRetCode: Returns the processing result.
752                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
753 
754  *---------------------------------------------------------------------------*/
755 NWMRetCode NWM_SendFrame(NWMCallbackFunc callback, const u8 *destAddr,
756                          const u16 *sendFrame, u16 sendFrameSize);
757 
758 /*---------------------------------------------------------------------------*
759   Name:         NWM_UnsetReceivingFrameBuffer
760 
761   Description:  Releases the receive buffer.
762 
763   Arguments:    callback: The callback function that is invoked when asynchronous processing finishes and when data is sent.
764 
765 
766                 protocol: Specifies which protocol the receive buffer is for.
767                                 NWM_PORT_IPV4_ARP: IPv4 TCP/IP data and ARP data
768                                                    (You should normally use this.)
769                                 NWM_PORT_EAPOL   : EAPOL data (for WPS)
770                                 NWM_PORT_OTHERS  : Other protocols
771 
772   Returns:      NWMRetCode: Returns the processing result.
773                                 Returns NWM_RETCODE_OPERATING if asynchronous processing started successfully. Afterwards, asynchronous processing results will be passed to the callback.
774 
775  *---------------------------------------------------------------------------*/
776 NWMRetCode NWM_UnsetReceivingFrameBuffer(NWMCallbackFunc callback, u16 protocol);
777 
778 /*---------------------------------------------------------------------------*
779   Name:         NWM_SetPowerSaveMode
780 
781   Description:  Changes the power-save mode.
782 
783   Arguments:    callback    -   Callback function that is called when the asynchronous process completes.
784                 powerSave - Specifies the power-save mode.
785                                 NWM_POWERMODE_ACTIVE  : Power-save mode off
786                                 NWM_POWERMODE_STANDARD: Standard 802.11 power-save mode
787                                 NWM_POWERMODE_UAPSD   : Enhanced power-save mode established in 802.11e
788                                                         (Unscheduled Automatic Power Save Delivery)
789 
790   Returns:      NWMRetCode: Returns the processing result.
791                                 Returns WM_ERRCODE_OPERATING if asynchronous processing started successfully. Afterwards, the asynchronous processing results will be passed to the callback.
792 
793  *---------------------------------------------------------------------------*/
794 NWMRetCode NWM_SetPowerSaveMode(NWMCallbackFunc callback, NWMPowerMode powerSave);
795 
796 /*---------------------------------------------------------------------------*
797   Name:         NWM_GetMacAddress
798 
799   Description:  Gets the MAC address for this device from the TWL wireless module.
800                 Synchronous function.
801 
802   Arguments:    macAddr: Pointer to a buffer to store this device's MAC address.
803 
804   Returns:      NWMRetCode: Returns the processing result.
805  *---------------------------------------------------------------------------*/
806 NWMRetCode NWM_GetMacAddress(u8* macAddr);
807 
808 /*---------------------------------------------------------------------------*
809   Name:         NWM_GetBssDesc
810 
811   Description:  Gets BSS data from the buffer with scan results from NWM_StartScan.
812                 Synchronous function.
813 
814   Arguments:    bssbuf: Pointer to the buffer with scan results
815                 bsssize: Size of the buffer with scan results
816                 index: Index to the BSS data to get
817 
818   Returns:      NWMBssDesc: Returns the BSS data at index.
819                                  Returns NULL if it could not be obtained.
820  *---------------------------------------------------------------------------*/
821 NWMBssDesc* NWM_GetBssDesc(void* bssbuf, u32 bsssize, int index);
822 
823 /*---------------------------------------------------------------------------*
824   Name:         NWM_GetAllowedChannel
825 
826   Description:  Gets the channel that was permitted to use for the communication. Synchronous function.
827                 Call this from a state after NWM_STATE_DISCONNECTED (after NWM_Open has completed).
828 
829   Arguments:    None.
830 
831   Returns:      u16 -   Returns the bit field of the permitted channel.
832                         The least significant bit indicates channel 1, and the most significant bit indicates channel 16.
833                         If a channel's corresponding bit is set to 1, it is usable; otherwise, its use is prohibited.
834                         Typically, a value is returned with several of the bits corresponding to channels 1-13 set to 1.
835                         If 0x0000 is returned, no channels can be used and wireless features are therefore prohibited.
836                         Also, in case the function failed, such as when it is not yet initialized, 0x8000 is returned.
837 
838  *---------------------------------------------------------------------------*/
839 u16 NWM_GetAllowedChannel(void);
840 
841 /*---------------------------------------------------------------------------*
842   Name:         NWM_CalcLinkLevel
843 
844   Description:  Calculates the link level from the threshold defined in nwm_common_private.h.
845 
846   Arguments:    s16: The RSSI value received from the Atheros driver
847 
848   Returns:      u16: A link level similar to the WM library's
849  *---------------------------------------------------------------------------*/
850 u16 NWM_CalcLinkLevel(s16 rssi);
851 
852 /*---------------------------------------------------------------------------*
853   Name:         NWM_GetDispersionScanPeriod
854 
855   Description:  Gets the time limit that should be set when searching for an AP or DS parent device as an STA.
856 
857   Arguments:    u16 scanType: The scan type: NWM_SCANTYPE_PASSIVE or NWM_SCANTYPE_ACTIVE
858 
859   Returns:      u16 -   Search limit time that should be set (ms).
860  *---------------------------------------------------------------------------*/
861 u16 NWM_GetDispersionScanPeriod(u16 scanType);
862 
863 /*---------------------------------------------------------------------------*
864   Name:         NWM_GetState
865 
866   Description:  Gets the NWM state.
867 
868   Arguments:    None.
869 
870   Returns:      u16: The NWM state. This will be indicate by the NWMState enumerated type.
871  *---------------------------------------------------------------------------*/
872 u16 NWM_GetState(void);
873 
874 /*---------------------------------------------------------------------------*
875   Name:         NWM_GetInfoElements
876 
877   Description:  Gets the specified information element (IE) from BSS data.
878 
879   Arguments:    bssDesc: The BSS data to get.
880                 elementID: The ElementID of an information element, established in 802.11.
881 
882   Returns:      NWMInfoElements: Returns a pointer to the specified information element if it exists.
883                                       Returns NULL if it could not be obtained.
884 
885  *---------------------------------------------------------------------------*/
886 NWMInfoElements* NWM_GetInfoElements(NWMBssDesc *bssDesc, u8 elementID);
887 
888 /*---------------------------------------------------------------------------*
889   Name:         NWM_GetVenderInfoElements
890 
891   Description:  Gets the specified  vendor information element (IE) from BSS data.
892                 This is used to get information elements for WPA and so on.
893 
894   Arguments:    bssDesc: The BSS data to get.
895                 elementID: The ElementID of an information element, established in 802.11.
896                                       This must be specified as NWM_ELEMENTID_VENDOR.
897                 ouiType: An array of the OUI (3 bytes) and Type (1 byte).
898                                       For WPA, this is 0x00 0x50 0xf2 0x01.
899 
900   Returns:      NWMInfoElements: Returns a pointer to the specified vendor information element if it exists.
901                                       Returns NULL if it could not be obtained.
902 
903  *---------------------------------------------------------------------------*/
904 NWMInfoElements* NWM_GetVenderInfoElements(NWMBssDesc *bssDesc, u8 elementID, const u8 ouiType[4]);
905 
906 
907 #ifdef  __cplusplus
908 }       /* extern "C" */
909 #endif
910 
911 #endif /* LIBRARIES_NWM_ARM9_NWM_H__ */
912 
913 /*---------------------------------------------------------------------------*
914   End of file
915  *---------------------------------------------------------------------------*/
916