1 /*---------------------------------------------------------------------------*
2 Project: NWCM Library
3 File: nwcm.h
4 Copyright (C)2008 Nintendo All rights reserved.
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law. They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10 @version $Id: nwcm.h 12372 2010-03-15 02:11:34Z hatamoto_minoru $
11 *---------------------------------------------------------------------------
12
13
14 */
15
16 #ifndef NWCM_H
17 #define NWCM_H
18
19 #include <nnet.h>
20 #include <nwcm.h>
21
22 /* The real wcm header file */
23 #include <nitroWiFi/wcm.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /*---------------------------------------------------------------------------*
30 * Definitions
31 *---------------------------------------------------------------------------*/
32 #define NWCM_DEVICE_1 0 /* Only 1 interface can be used with this driver */
33
34 #define NWCM_VENDOR_NINTENDO 0x0000
35 #define NWCM_COMMON_CONF_VERSION 0x1100
36 #define NWCM_INS_CONF_VERSION 0x2100
37
38 /* Please see man pages for details
39
40 */
41 #define NWCM_ERROR_BASE 0xffff9000
42 #define NWCM_ERROR_CODE(code) ((s32)(NWCM_ERROR_BASE|(code)))
43 enum {
44 NWCM_ERR_PARAM = NWCM_ERROR_CODE(1), /* Parameter error */
45 NWCM_ERR_INIT = NWCM_ERROR_CODE(2), /* Cannot run because it is in initialized state */
46 NWCM_ERR_FINISH = NWCM_ERROR_CODE(3), /* Cannot run because it is in terminated state */
47 NWCM_ERR_CONFVER = NWCM_ERROR_CODE(4), /* Setting version error */
48 NWCM_ERR_STATE = NWCM_ERROR_CODE(5), /* State error */
49 NWCM_ERR_EXIST = NWCM_ERROR_CODE(6), /* Already created */
50 NWCM_ERR_NOMEM = NWCM_ERROR_CODE(7), /* Insufficient memory */
51 NWCM_ERR_TIMEOUT = NWCM_ERROR_CODE(8), /* timeout */
52 NWCM_ERR_NONE = 0 /* Normal end */
53 };
54
55 /* Please see man pages for details
56
57 */
58 #define NWCM_MEM_BASE 0x00050000
59 #define NWCM_MEM_NAME(name) ((s32)(NWCM_MEM_BASE|(name)))
60 enum {
61 NWCM_MEM_INSTANCE = NWCM_MEM_NAME(1)
62 };
63
64 /* Please see man pages for details
65
66 */
67 enum {
68 NWCM_STATE_INIT = 0, /* Initial state */
69 NWCM_STATE_WAIT_LINKUP, /* Wait for association to AP */
70 NWCM_STATE_ACTIVE, /* Connection completed state */
71 NWCM_STATE_ABORT, /* Cancel association */
72 NWCM_STATE_MORIBUND /* Disconnecting */
73 };
74
75 /*---------------------------------------------------------------------------*
76 * Types/Declarations
77 *---------------------------------------------------------------------------*/
78 #define NWCM_MAC_LEN 6
79
80 /* Please see man pages for details
81
82 */
83 typedef struct NWCMProtocolList {
84 u16 protocol; /* IP, ARP, etc. */
85 NNETInstance *upper_ins; /* Upper instance */
86 NOSMessageQueueId mq_receive; /* Queue to insert packet when above protocol is received */
87 } NWCMProtocolList;
88
89 /* Please see man pages for details
90
91 */
92 typedef struct NWCMCommonConfig {
93 u16 vendor; /* NWCM_VENDOR_NINTENDO */
94 u16 version; /* NWCM_COMMON_CONF_VERSION */
95
96 /*
97 No arguments
98 */
99
100 } NWCMCommonConfig;
101
102 /* Please see man pages for details
103
104 */
105 /* AP authentication modes */
106 #define NWCM_OPTION_TEST_AUTH WCM_OPTION_TEST_AUTH
107 #define NWCM_OPTION_FILTER_AUTH WCM_OPTION_FILTER_AUTH
108 #define NWCM_OPTION_MASK_AUTH WCM_OPTION_MASK_AUTH
109 #define NWCM_OPTION_AUTH_OPENSYSTEM WCM_OPTION_AUTH_OPENSYSTEM
110
111 /* WEP encryption mode type */
112 #define NWCM_WEPMODE_NONE WCM_WEPMODE_NONE /* No encryption */
113 #define NWCM_WEPMODE_40 WCM_WEPMODE_40 /* RC4 (40-bit) encryption mode */
114 #define NWCM_WEPMODE_104 WCM_WEPMODE_104 /* RC4 (104-bit) encryption mode */
115 #define NWCM_WEPMODE_128 WCM_WEPMODE_128 /* RC4 (128-bit) encryption mode */
116 #define NWCM_SIZE_WEPKEY WCM_WEP_SIZE /* WEP key length */
117 typedef struct NWCMWepDesc {
118 u8 mode; /* WEP encryption mode ( WCM_WEPMODE_* ) */
119 u8 keyId; /*/ WEP key ID (0 to 3) */
120 u8 key[NWCM_SIZE_WEPKEY]; /* WEP key data string [20 * 4 bytes] */
121 } NWCMWepDesc;
122
123 /* Please see man pages for details
124
125 */
126 #define NWCM_BSSID_SIZE WCM_BSSID_SIZE /* BSSID size */
127 #define NWCM_ESSID_SIZE WCM_ESSID_SIZE /* ESSID size */
128 typedef struct NWCMInstanceConfig {
129 u16 vendor; /* NWCM_VENDOR_NINTENDO */
130 u16 version; /* NWCM_INS_CONF_VERSION */
131
132 u8 bssId[NWCM_BSSID_SIZE];
133 NWCMWepDesc wepDesc;
134 u8 essId[NWCM_ESSID_SIZE];
135 u32 auth_option;
136 } NWCMInstanceConfig;
137
138 /* Please see man pages for details
139
140 */
141 #define NWCM_PROTOCOL_NUM 8 /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */
142 #define NWCM_UPPER_NUM 2 /* Number of upper layers */
143 #define NWCM_MQ_NUM 16 /* Size of queue to pass to upper layers */
144 #define NWCM_MAX_SEND_LEN 1600
145 typedef struct NWCMMessage {
146 NOSMessageQueue mq; /* Receive queue for upper layers */
147 NOSMessage mqarray[NWCM_MQ_NUM]; /* Receive queue instance for upper layers */
148 } NWCMMessage;
149
150 typedef struct NWCMInstance {
151 NNETInstance ins; /* Instance information common to all layers */
152
153 NWCMInstanceConfig config; /* Instance-specific settings */
154
155 NWCMProtocolList upper_protocol[NWCM_PROTOCOL_NUM]; /* Upper protocol and message queue for sending */
156 s32 upper_protocol_count;
157
158 NWCMMessage upper_mq[NWCM_UPPER_NUM]; /* Receive queue for upper layers */
159
160 s32 upper_ins_count;
161
162 s32 state;
163
164 u8 macaddr[NWCM_MAC_LEN]; /* Local MAC address */
165
166 u8 sendBuf[NWCM_MAX_SEND_LEN]; /* Send buffer */
167
168 } NWCMInstance;
169
170 /*
171 Get NNETInstance from WCM instance
172 */
NWCM_GetNNETInstance(NWCMInstance * wcm_ins)173 NN_INLINE NNETInstance *NWCM_GetNNETInstance(NWCMInstance *wcm_ins)
174 {
175 return (NNETInstance *)wcm_ins;
176 }
177
178 /*
179 Get WCM instance from NNETInstance
180 */
NWCM_GetNWCMInstance(NNETInstance * ins)181 NN_INLINE NWCMInstance *NWCM_GetNWCMInstance(NNETInstance *ins)
182 {
183 return (NWCMInstance *)ins;
184 }
185
186 /*---------------------------------------------------------------------------*
187 * Function Prototypes
188 *---------------------------------------------------------------------------*/
189 /* nwcm_main.c */
190 extern s32 NWCM_Init(const NNETAllocator *allocator);
191 extern s32 NWCM_Finish(void);
192 extern s32 NWCM_SetCommonConfig(const NWCMCommonConfig *common_conf);
193 extern s32 NWCM_SetInstanceConfig(NWCMInstance *wcm_ins, const NWCMInstanceConfig *ins_conf);
194 extern s32 NWCM_StartupIns(NNETInstance *ins, s32 timeout);
195 extern s32 NWCM_CleanupIns(NNETInstance *ins, s32 timeout);
196 extern s32 NWCM_AbortIns(NNETInstance *ins);
197 extern s32 NWCM_CreateIns(NWCMInstance **wcm_ins, u32 device_id);
198 extern s32 NWCM_DestroyIns(NWCMInstance *wcm_ins);
199 extern s32 NWCM_GetStateIns(NWCMInstance *wcm_ins);
200 extern s32 NWCM_GetUpperAPI(NNETEthernetAPI *wcm_api, NWCMInstance *wcm_ins);
201 extern s32 NWCM_SetUpper(NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 entry[]);
202 extern s32 NWCM_ClearUpper(NNETInstance *ins, NNETInstance *upper_ins);
203 extern s32 NWCM_GetMacAddr(NNETInstance *ins, u8 *macaddr);
204 extern s32 NWCM_SetMulticastAddr(NNETInstance *ins, u8 *macaddr);
205 extern s32 NWCM_ClearMulticastAddr(NNETInstance *ins, u8 *macaddr);
206 extern s32 NWCM_Send(NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf);
207 extern s32 NWCM_Receive(NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf);
208 extern s32 NWCM_CancelReceive(NNETInstance *ins, u32 receive_id);
209
210 #ifdef NDEBUG_ENABLE
211 extern void NWCM_Dummy_Recv(const u8 *srcAddr, const u8 *dstAddr, const u8 *buf, s32 len);
212 #endif
213
214 /* nwcm_state.c */
215 extern void NWCM_ChangeStateIns(NWCMInstance *ins, s32 state);
216
217 #ifdef __cplusplus
218 }
219 #endif
220
221 /* NWCM_H */
222 #endif
223