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 12372 2010-03-15 02:11:34Z hatamoto_minoru $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NWCM_H
17 #define NWCM_H
18
19 #include <nnet.h>
20 #include <nwcm.h>
21
22 /* 本当のwcmヘッダファイル */
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 /* このドライバで扱えるI/Fは1つだけ */
33
34 #define NWCM_VENDOR_NINTENDO 0x0000
35 #define NWCM_COMMON_CONF_VERSION 0x1100
36 #define NWCM_INS_CONF_VERSION 0x2100
37
38 /**
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), /* パラメータエラー */
45 NWCM_ERR_INIT = NWCM_ERROR_CODE(2), /* 初期状態のため実行不可 */
46 NWCM_ERR_FINISH = NWCM_ERROR_CODE(3), /* 終了状態のため実行不可 */
47 NWCM_ERR_CONFVER = NWCM_ERROR_CODE(4), /* 設定のバージョンエラー */
48 NWCM_ERR_STATE = NWCM_ERROR_CODE(5), /* ステートエラー */
49 NWCM_ERR_EXIST = NWCM_ERROR_CODE(6), /* 既に作成済み */
50 NWCM_ERR_NOMEM = NWCM_ERROR_CODE(7), /* メモリ不足 */
51 NWCM_ERR_TIMEOUT = NWCM_ERROR_CODE(8), /* タイムアウト */
52 NWCM_ERR_NONE = 0 /* 正常終了 */
53 };
54
55 /**
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 /**
65 * ステート
66 */
67 enum {
68 NWCM_STATE_INIT = 0, /* 初期状態 */
69 NWCM_STATE_WAIT_LINKUP, /* APとのアソシエーション待ち状態 */
70 NWCM_STATE_ACTIVE, /* 接続完了状態 */
71 NWCM_STATE_ABORT, /* アソシエーションキャンセル */
72 NWCM_STATE_MORIBUND /* 切断実行中 */
73 };
74
75 /*---------------------------------------------------------------------------*
76 * Types/Declarations
77 *---------------------------------------------------------------------------*/
78 #define NWCM_MAC_LEN 6
79
80 /**
81 * 無線ドライバが保持するプロトコル情報
82 */
83 typedef struct NWCMProtocolList {
84 u16 protocol; /* IP、ARPなど */
85 NNETInstance *upper_ins; /* 上位インスタンス */
86 NOSMessageQueueId mq_receive; /* 上記プロトコルを受信したときにパケットを入れるキュー */
87 } NWCMProtocolList;
88
89 /**
90 * モジュール全体で使用する設定
91 */
92 typedef struct NWCMCommonConfig {
93 u16 vendor; /* NWCM_VENDOR_NINTENDO */
94 u16 version; /* NWCM_COMMON_CONF_VERSION */
95
96 /*
97 パラメータなし
98 */
99
100 } NWCMCommonConfig;
101
102 /**
103 * WEPキー設定構造体
104 */
105 /* APとの認証モード */
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 暗号化モード種別 */
112 #define NWCM_WEPMODE_NONE WCM_WEPMODE_NONE /* 暗号化なし */
113 #define NWCM_WEPMODE_40 WCM_WEPMODE_40 /* RC4 ( 40 ビット ) 暗号化モード */
114 #define NWCM_WEPMODE_104 WCM_WEPMODE_104 /* RC4 ( 104 ビット ) 暗号化モード */
115 #define NWCM_WEPMODE_128 WCM_WEPMODE_128 /* RC4 ( 128 ビット ) 暗号化モード */
116 #define NWCM_SIZE_WEPKEY WCM_WEP_SIZE /* WEPキー長 */
117 typedef struct NWCMWepDesc {
118 u8 mode; /* WEP 暗号化モード ( WCM_WEPMODE_* ) */
119 u8 keyId; /*/ WEP キー ID ( 0 ~ 3 ) */
120 u8 key[NWCM_SIZE_WEPKEY]; /* WEP キーデータ列[ 20 * 4 バイト ] */
121 } NWCMWepDesc;
122
123 /**
124 * インスタンス固有設定
125 */
126 #define NWCM_BSSID_SIZE WCM_BSSID_SIZE /* BSSIDサイズ */
127 #define NWCM_ESSID_SIZE WCM_ESSID_SIZE /* ESSIDサイズ */
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 /**
139 * インスタンス
140 */
141 #define NWCM_PROTOCOL_NUM 8 /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */
142 #define NWCM_UPPER_NUM 2 /* 上位のレイヤ数 */
143 #define NWCM_MQ_NUM 16 /* 上位へ渡すキューのサイズ */
144 #define NWCM_MAX_SEND_LEN 1600
145 typedef struct NWCMMessage {
146 NOSMessageQueue mq; /* 上位用の受信キュー */
147 NOSMessage mqarray[NWCM_MQ_NUM]; /* 上位用の受信キュー実体 */
148 } NWCMMessage;
149
150 typedef struct NWCMInstance {
151 NNETInstance ins; /* 全レイヤ共通に持っているインスタンス情報 */
152
153 NWCMInstanceConfig config; /* インスタンス固有設定 */
154
155 NWCMProtocolList upper_protocol[NWCM_PROTOCOL_NUM]; /* 上位のプロトコルと送信するメッセージキュー */
156 s32 upper_protocol_count;
157
158 NWCMMessage upper_mq[NWCM_UPPER_NUM]; /* 上位用の受信キュー */
159
160 s32 upper_ins_count;
161
162 s32 state;
163
164 u8 macaddr[NWCM_MAC_LEN]; /* 自MACアドレス */
165
166 u8 sendBuf[NWCM_MAX_SEND_LEN]; /* 送信バッファ */
167
168 } NWCMInstance;
169
170 /*
171 WCMのインスタンスからNNETInstanceを取得する
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 NNETInstanceからWCMのインスタンスを取得する
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