1 /*---------------------------------------------------------------------------*
2 Project: NWCM Library
3 File: nwcm.h
4
5 Copyright (C) 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 @version $Id: nwcm.h 16441 2010-05-20 00:57:11Z takiguchi_shinichi $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NWCM_H
17 #define NWCM_H
18
19 #include <nnet.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /*---------------------------------------------------------------------------*
26 * WCM Temporary Definitions
27 *---------------------------------------------------------------------------*/
28 // 各種制御用定数
29 // 各種データサイズ(サイズの単位はバイト)
30 #define WM_SIZE_BSSID 6
31 #define WM_SIZE_SSID 32
32
33 #define WCM_CAM_LIFETIME 80 // CAM ライフタイム( 8 秒 )
34 #define WCM_BSSID_SIZE WM_SIZE_BSSID // BSS-ID のサイズ ( 6 バイト )
35 #define WCM_ESSID_SIZE WM_SIZE_SSID // ESS-ID の最大サイズ ( 32 バイト )
36
37 #define WCM_OPTION_TEST_AUTH 0x00080000
38 #define WCM_OPTION_FILTER_AUTH 0x00040000
39
40 // WEP 暗号化モード種別
41 #define WCM_WEPMODE_NONE 0 // 暗号化なし
42 #define WCM_WEPMODE_40 1 // RC4 ( 40 ビット ) 暗号化モード
43 #define WCM_WEPMODE_104 2 // RC4 ( 104 ビット ) 暗号化モード
44 #define WCM_WEPMODE_128 3 // RC4 ( 128 ビット ) 暗号化モード
45
46 // AP との認証モード
47 #define WCM_OPTION_TEST_AUTH 0x00080000
48 #define WCM_OPTION_FILTER_AUTH 0x00040000
49 #define WCM_OPTION_MASK_AUTH (WCM_OPTION_TEST_AUTH | WCM_OPTION_FILTER_AUTH)
50 #define WCM_OPTION_AUTH_OPENSYSTEM (WCM_OPTION_TEST_AUTH | 0x00000000)
51 #define WCM_OPTION_AUTH_SHAREDKEY (WCM_OPTION_TEST_AUTH | 0x00040000)
52
53 #define WM_SIZE_WEPKEY 80
54 #define WCM_WEP_SIZE WM_SIZE_WEPKEY // 80 バイト
55
56 /*---------------------------------------------------------------------------*
57 * Definitions
58 *---------------------------------------------------------------------------*/
59 #define NWCM_DEVICE_1 0 /* ���̃h���C�o�ň�����I/F��1���� */
60
61 #define NWCM_VENDOR_NINTENDO 0x0000
62 #define NWCM_COMMON_CONF_VERSION 0x1100
63 #define NWCM_INS_CONF_VERSION 0x2100
64
65 #define NWCM_MEM_BASE 0x00050000
66 #define NWCM_MEM_NAME(name) ((s32)(NWCM_MEM_BASE|(name)))
67 enum {
68 NWCM_MEM_INSTANCE = NWCM_MEM_NAME(1)
69 };
70
71
72 #define WM_SIZE_USER_GAMEINFO 112 // GameInfoのユーザー領域の最大サイズ
73 #define WM_SIZE_USERNAME 8
74 #define WM_SIZE_GAMENAME 16
75 typedef struct WMGameInfo
76 {
77 u16 magicNumber; // == 0x0001
78 u8 ver; // GameInfo Version 1
79 u8 platform; // DS: 0, Wii: 8
80 u32 ggid;
81 u16 tgid;
82 u8 userGameInfoLength; // ユーザー領域の長さ
83 union
84 {
85 // (CS_Flag):1, (KS_Flag):1, multibootFlag:1, entryFlag:1
86 u8 gameNameCount_attribute; // 互換のための旧名
87 u8 attribute;
88 };
89 u16 parentMaxSize; //親機最大送信サイズ
90 u16 childMaxSize; //子機最大送信サイズ
91 union
92 {
93 u16 userGameInfo[WM_SIZE_USER_GAMEINFO / sizeof(u16)]; // ユーザー領域(最大112バイト (暫定))
94 struct
95 {
96 u16 userName[WM_SIZE_USERNAME / sizeof(u16)]; // WM_SIZE_USERNAME -> 8
97 u16 gameName[WM_SIZE_GAMENAME / sizeof(u16)]; // WM_SIZE_GAMENAME -> 16
98 u16 padd1[44]; // pad -> 88
99 }
100 old_type; // 計 112バイト
101 };
102 }
103 WMGameInfo, WMgameInfo;
104
105
106
107 typedef struct WCMBssDesc
108 {
109 u16 length; // 2
110 u16 rssi; // 4
111 u8 bssid[WM_SIZE_BSSID]; // 10
112 u16 ssidLength; // 12
113 u8 ssid[WM_SIZE_SSID]; // 44
114 u16 capaInfo; // 46
115 struct
116 {
117 u16 basic; // 48
118 u16 support; // 50
119 }
120 rateSet;
121 u16 beaconPeriod; // 52
122 u16 dtimPeriod; // 54
123 u16 channel; // 56
124 u16 cfpPeriod; // 58
125 u16 cfpMaxDuration; // 60
126 u16 gameInfoLength; // 62
127 union
128 {
129 u16 otherElementCount;
130 u16 elementCount;
131 }; // 64
132 union
133 {
134 WMGameInfo gameInfo;
135 u16 elements[1];
136 };
137 } WCMBssDesc;
138
139
140
141 /**
142 * �X�e�[�g
143 */
144 enum {
145 NWCM_STATE_INIT = 0, /* ������ */
146 NWCM_STATE_WAIT_LINKUP, /* AP�Ƃ̃A�\�V�G�[�V�����҂���� */
147 NWCM_STATE_ACTIVE, /* �ڑ�������� */
148 NWCM_STATE_ABORT, /* �A�\�V�G�[�V�����L�����Z�� */
149 NWCM_STATE_MORIBUND /* �ؒf���s�� */
150 };
151
152 /*---------------------------------------------------------------------------*
153 * Types/Declarations
154 *---------------------------------------------------------------------------*/
155 #define NWCM_MAC_LEN 6
156
157 /**
158 * ����h���C�o���ێ�����v���g�R�����
159 */
160 typedef struct NWCMProtocolList {
161 u16 protocol; /* IP�AARP�Ȃ� */
162 NNETInstance *upper_ins; /* ��ʃC���X�^���X */
163 NOSMessageQueueId mq_receive; /* ��L�v���g�R������M�����Ƃ��Ƀp�P�b�g�����L���[ */
164 } NWCMProtocolList;
165
166 /**
167 * ���W���[���S�̂Ŏg�p����ݒ�
168 */
169 typedef struct NWCMCommonConfig {
170 u16 vendor; /* NWCM_VENDOR_NINTENDO */
171 u16 version; /* NWCM_COMMON_CONF_VERSION */
172
173 /*
174 �p�����[�^�Ȃ�
175 */
176
177 } NWCMCommonConfig;
178
179
180 /**
181 * �C���X�^���X
182 */
183 #define NWCM_PROTOCOL_NUM 8 /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */
184 #define NWCM_UPPER_NUM 2 /* ��ʂ̃��C���� */
185 #define NWCM_MQ_NUM 16 /* ��ʂ֓n���L���[�̃T�C�Y */
186 #define NWCM_MAX_SEND_LEN 1600
187 typedef struct NWCMMessage {
188 NOSMessageQueue mq; /* ��ʗp�̎�M�L���[ */
189 NOSMessage mqarray[NWCM_MQ_NUM]; /* ��ʗp�̎�M�L���[���� */
190 } NWCMMessage;
191
192 #define NWCM_VENDOR_NINTENDO 0x0000
193 #define NWCM_COMMON_CONF_VERSION 0x1100
194 #define NWCM_INS_CONF_VERSION 0x2100
195
196 /**
197 * インスタンス固有設定
198 */
199 #define NWCM_BSSID_SIZE WCM_BSSID_SIZE /* BSSIDサイズ */
200 #define NWCM_ESSID_SIZE WCM_ESSID_SIZE /* ESSIDサイズ */
201
202 /* APとの認証モード */
203 #define NWCM_OPTION_TEST_AUTH WCM_OPTION_TEST_AUTH
204 #define NWCM_OPTION_FILTER_AUTH WCM_OPTION_FILTER_AUTH
205 #define NWCM_OPTION_MASK_AUTH WCM_OPTION_MASK_AUTH
206 #define NWCM_OPTION_AUTH_OPENSYSTEM WCM_OPTION_AUTH_OPENSYSTEM
207
208
209 /* WEP 暗号化モード種別 */
210 #define NWCM_WEPMODE_NONE WCM_WEPMODE_NONE /* 暗号化なし */
211 #define NWCM_WEPMODE_40 WCM_WEPMODE_40 /* RC4 ( 40 ビット ) 暗号化モード */
212 #define NWCM_WEPMODE_104 WCM_WEPMODE_104 /* RC4 ( 104 ビット ) 暗号化モード */
213 #define NWCM_WEPMODE_128 WCM_WEPMODE_128 /* RC4 ( 128 ビット ) 暗号化モード */
214 #define NWCM_SIZE_WEPKEY WCM_WEP_SIZE /* WEPキー長 */
215 typedef struct NWCMWepDesc {
216 u8 mode; /* WEP 暗号化モード ( WCM_WEPMODE_* ) */
217 u8 keyId; /*/ WEP キー ID ( 0 ~ 3 ) */
218 u8 key[NWCM_SIZE_WEPKEY]; /* WEP キーデータ列[ 20 * 4 バイト ] */
219 } NWCMWepDesc;
220 typedef NWCMWepDesc WCMWepDesc;
221
222
223 typedef struct NWCMInstanceConfig {
224 u16 vendor; /* NWCM_VENDOR_NINTENDO */
225 u16 version; /* NWCM_INS_CONF_VERSION */
226
227 u8 bssId[NWCM_BSSID_SIZE];
228 NWCMWepDesc wepDesc;
229 u8 essId[NWCM_ESSID_SIZE];
230 u32 auth_option;
231 } NWCMInstanceConfig;
232
233
234 typedef struct NWCMInstance {
235 NNETInstance ins; /* �S���C�����ʂɎ����Ă���C���X�^���X��� */
236
237 NWCMInstanceConfig config; /* �C���X�^���X�ŗL�ݒ� */
238
239 NWCMProtocolList upper_protocol[NWCM_PROTOCOL_NUM]; /* ��ʂ̃v���g�R���Ƒ��M���郁�b�Z�[�W�L���[ */
240 s32 upper_protocol_count;
241
242 NWCMMessage upper_mq[NWCM_UPPER_NUM]; /* ��ʗp�̎�M�L���[ */
243
244 s32 upper_ins_count;
245
246 s32 state;
247
248 u8 macaddr[NWCM_MAC_LEN]; /* ��MAC�A�h���X */
249
250 u8 sendBuf[NWCM_MAX_SEND_LEN]; /* ���M�o�b�t�@ */
251
252 } NWCMInstance;
253
254
255
256
257 /*
258 WCM�̃C���X�^���X����NNETInstance���擾����
259 */
NWCM_GetNNETInstance(NWCMInstance * wcm_ins)260 NN_INLINE NNETInstance *NWCM_GetNNETInstance(NWCMInstance *wcm_ins)
261 {
262 return (NNETInstance *)wcm_ins;
263 }
264
265 /*
266 NNETInstance����WCM�̃C���X�^���X���擾����
267 */
NWCM_GetNWCMInstance(NNETInstance * ins)268 NN_INLINE NWCMInstance *NWCM_GetNWCMInstance(NNETInstance *ins)
269 {
270 return (NWCMInstance *)ins;
271 }
272
273 /*---------------------------------------------------------------------------*
274 * Function Prototypes
275 *---------------------------------------------------------------------------*/
276 /* nwcm_main.c */
277 s32 NWCM_Init(const NNETAllocator *allocator);
278 s32 NWCM_Finish(void);
279 s32 NWCM_SetCommonConfig(const NWCMCommonConfig *common_conf);
280 s32 NWCM_SetInstanceConfig(NWCMInstance *wcm_ins, const NWCMInstanceConfig *ins_conf);
281 s32 NWCM_StartupIns(NNETInstance *ins, s32 timeout);
282 s32 NWCM_CleanupIns(NNETInstance *ins, s32 timeout);
283 s32 NWCM_AbortIns(NNETInstance *ins);
284 s32 NWCM_CreateIns(NWCMInstance **wcm_ins, u32 device_id);
285 s32 NWCM_DestroyIns(NWCMInstance *wcm_ins);
286 s32 NWCM_GetStateIns(NWCMInstance *wcm_ins);
287 s32 NWCM_GetUpperAPI(NNETEthernetAPI *wcm_api, NWCMInstance *wcm_ins);
288 s32 NWCM_SetUpper(NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 entry[]);
289 s32 NWCM_ClearUpper(NNETInstance *ins, NNETInstance *upper_ins);
290 s32 NWCM_GetMacAddr(NNETInstance *ins, u8 *macaddr);
291 s32 NWCM_SetMulticastAddr(NNETInstance *ins, u8 *macaddr);
292 s32 NWCM_ClearMulticastAddr(NNETInstance *ins, u8 *macaddr);
293 s32 NWCM_Send(NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf);
294 s32 NWCM_Receive(NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf);
295 s32 NWCM_CancelReceive(NNETInstance *ins, u32 receive_id);
296
297 #ifdef NDEBUG_ENABLE
298 extern void NWCM_Dummy_Recv(const u8 *srcAddr, const u8 *dstAddr, const u8 *buf, s32 len);
299 #endif
300
301 /* nwcm_state.c */
302 extern void NWCM_ChangeStateIns(NWCMInstance *ins, s32 state);
303
304 extern NWCMCommonConfig nwcmCommonConfig;
305 extern NWCMInstance *wcmIns;
306 extern NWCMInstanceConfig CU_nwcmInsConfig;
307
308 #ifdef __cplusplus
309 }
310 #endif
311
312 /* NWCM_H */
313 #endif
314