1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WXC - include -
3 File: driver.h
4
5 Copyright 2005-2009 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-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_WXC_DRIVER_H_
19 #define NITRO_WXC_DRIVER_H_
20
21 #include <nitro.h>
22
23
24 /*****************************************************************************/
25 /* Constants */
26
27 /* Basic wireless setting */
28 #define WXC_DEFAULT_PORT 4
29 #define WXC_DEFAULT_PORT_PRIO 2
30
31 /* Beacon interval was previously 150 (ms), but now 90 (ms) + 20 (ms) */
32 #define WXC_SCAN_TIME_MAX (WXC_BEACON_PERIOD + 20)
33
34 #define WXC_MAX_RATIO 100
35
36 /* Event callback type from the wireless driver */
37 typedef enum
38 {
39 /* End wireless communication (argument is always NULL) */
40 WXC_DRIVER_EVENT_STATE_END,
41 /* Transition to STOP state completed (argument is always NULL) */
42 WXC_DRIVER_EVENT_STATE_IDLE,
43 /* Transition to IDLE state completed (argument is always NULL) */
44 WXC_DRIVER_EVENT_STATE_STOP,
45 /* Transition to MP_PARENT state completed (argument is always NULL) */
46 WXC_DRIVER_EVENT_STATE_PARENT,
47 /* Transition to MP_CHILD state completed (argument is always NULL) */
48 WXC_DRIVER_EVENT_STATE_CHILD,
49 /* Beacon update timing (argument is WMParentParam pointer) */
50 WXC_DRIVER_EVENT_BEACON_SEND,
51 /* Beacon detection timing (argument is WMBssDesc pointer) */
52 WXC_DRIVER_EVENT_BEACON_RECV,
53 /* Send MP packet (argument is WXCPacketInfo pointer) */
54 WXC_DRIVER_EVENT_DATA_SEND,
55 /* Receive MP packet (argument is the const WXCPacketInfo pointer) */
56 WXC_DRIVER_EVENT_DATA_RECV,
57 /* Pre-connection notification (the argument is the WMBssDesc pointer) */
58 WXC_DRIVER_EVENT_CONNECTING,
59 /* Detect connection (argument) */
60 WXC_DRIVER_EVENT_CONNECTED,
61 /* Detect disconnection (argument is WMStartParentCallback pointer) */
62 WXC_DRIVER_EVENT_DISCONNECTED,
63
64 WXC_DRIVER_EVENT_MAX
65 }
66 WXCDriverEvent;
67
68 /* Driver internal state */
69 typedef enum WXCDriverState
70 {
71 WXC_DRIVER_STATE_END, /* Before initialization (driver = NULL) */
72 WXC_DRIVER_STATE_BUSY, /* State in transition */
73 WXC_DRIVER_STATE_STOP, /* Stable in STOP state */
74 WXC_DRIVER_STATE_IDLE, /* Stable in IDLE state */
75 WXC_DRIVER_STATE_PARENT, /* Stable in MP_PARENT state */
76 WXC_DRIVER_STATE_CHILD, /* Stable in MP_CHILD state */
77 WXC_DRIVER_STATE_ERROR /* Error without automatic recovery */
78 }
79 WXCDriverState;
80
81
82 /*****************************************************************************/
83 /* Declaration */
84
85 /*---------------------------------------------------------------------------*
86 Name: WXCDriverEventFunc
87
88 Description: Event callback prototype from the wireless driver.
89
90 Arguments: event: Notified event
91 arg: Function assigned to each event
92
93 Returns: u32 event result value assigned to each event.
94 *---------------------------------------------------------------------------*/
95 typedef u32 (*WXCDriverEventFunc) (WXCDriverEvent event, void *arg);
96
97
98 /* Wireless driver structure inside WXC library */
99 typedef struct WXCDriverWork
100 {
101
102 /* WM internal work */
103 u8 wm_work[WM_SYSTEM_BUF_SIZE] ATTRIBUTE_ALIGN(32);
104 u8 mp_send_work[WM_SIZE_MP_PARENT_SEND_BUFFER(WM_SIZE_MP_DATA_MAX, FALSE)]
105 ATTRIBUTE_ALIGN(32);
106 u8
107 mp_recv_work[WM_SIZE_MP_PARENT_RECEIVE_BUFFER(WM_SIZE_MP_DATA_MAX, WM_NUM_MAX_CHILD, FALSE)]
108 ATTRIBUTE_ALIGN(32);
109 u8 current_send_buf[WM_SIZE_MP_DATA_MAX] ATTRIBUTE_ALIGN(32);
110 u16 wm_dma; /* WM DMA channel */
111 u16 current_channel; /* Current channel (Measure/Start) */
112 u16 own_aid; /* This system's AID */
113 u16 peer_bitmap; /* Bitmap of connection peers */
114 u16 send_size_max; /* MP send size */
115 u16 recv_size_max; /* MP send size */
116 BOOL send_busy; /* Waiting for previous MP to complete */
117
118 /* State transition information */
119 WXCDriverState state;
120 WXCDriverState target;
121 WXCDriverEventFunc callback;
122
123 /* Parent device control information */
124 WMParentParam *parent_param;
125 BOOL need_measure_channel;
126 int measure_ratio_min;
127
128 /* Child device control information */
129 int scan_found_num;
130 u8 padding1[20];
131 WMBssDesc target_bss[1] ATTRIBUTE_ALIGN(32);
132 u8 scan_buf[WM_SIZE_SCAN_EX_BUF] ATTRIBUTE_ALIGN(32);
133 WMScanExParam scan_param[1] ATTRIBUTE_ALIGN(32);
134 u8 ssid[24];
135 u8 padding2[4];
136
137 }
138 WXCDriverWork;
139
140
141 /*****************************************************************************/
142 /* Functions */
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147
148
149 /*---------------------------------------------------------------------------*
150 Name: WXC_InitDriver
151
152 Description: Initializes wireless and starts the transition to IDLE.
153
154 Arguments: driver: Used as an internal work memory buffer
155 Pointer to WXCDriverWork structure
156 This must be 32-byte aligned.
157 pp: Parent parameters
158 func: Event notification callback
159 dma: DMA channel assigned to wireless
160
161 Returns: None.
162 *---------------------------------------------------------------------------*/
163 void WXC_InitDriver(WXCDriverWork * driver, WMParentParam *pp, WXCDriverEventFunc func, u32 dma);
164
165 /*---------------------------------------------------------------------------*
166 Name: WXC_SetDriverTarget
167
168 Description: Starts transition of a special status to the target.
169
170 Arguments: driver: WXCDriverWork structure
171 target: State of the transition target
172
173 Returns: None.
174 *---------------------------------------------------------------------------*/
175 void WXC_SetDriverTarget(WXCDriverWork * driver, WXCDriverState target);
176
177 /*---------------------------------------------------------------------------*
178 Name: WXC_GetDriverState
179
180 Description: Gets the current transition state.
181
182 Arguments: None.
183
184 Returns: The current transition state.
185 *---------------------------------------------------------------------------*/
WXC_GetDriverState(const WXCDriverWork * driver)186 static inline WXCDriverState WXC_GetDriverState(const WXCDriverWork * driver)
187 {
188 return driver->state;
189 }
190
191 /*---------------------------------------------------------------------------*
192 Name: WXC_SetDriverSsid
193
194 Description: Configures the SSID at connection.
195
196 Arguments: driver: WXCDriverWork structure
197 buffer: SSID data to configure
198 length: SSID data length
199 Must be less than WM_SIZE_CHILD_SSID.
200
201 Returns: None.
202 *---------------------------------------------------------------------------*/
203 void WXC_SetDriverSsid(WXCDriverWork * driver, const void *buffer, u32 length);
204
205 /*---------------------------------------------------------------------------*
206 Name: WXC_GetDriverTarget
207
208 Description: Gets the target current transition target state.
209
210 Arguments: None.
211
212 Returns: Current target transition target state.
213 *---------------------------------------------------------------------------*/
WXC_GetDriverTarget(const WXCDriverWork * driver)214 static inline WXCDriverState WXC_GetDriverTarget(const WXCDriverWork * driver)
215 {
216 return driver->target;
217 }
218
219 /*---------------------------------------------------------------------------*
220 Name: WXCi_IsParentMode
221
222 Description: Determines whether the current wireless state is parent.
223 Only valid in the WXC_STATE_ACTIVE state.
224
225 Arguments: None.
226
227 Returns: If the wireless status is parent mode, TRUE. If it's child mode, FALSE.
228 *---------------------------------------------------------------------------*/
WXCi_IsParentMode(const WXCDriverWork * driver)229 static inline BOOL WXCi_IsParentMode(const WXCDriverWork * driver)
230 {
231 return (driver->state == WXC_DRIVER_STATE_PARENT);
232 }
233
234 /*---------------------------------------------------------------------------*
235 Name: WXCi_GetParentBssDesc
236
237 Description: Gets the WMBssDesc structure for the connection target (valid only when child).
238
239 Arguments: None.
240
241 Returns: Connection target's WMBssDesc structure.
242 *---------------------------------------------------------------------------*/
WXCi_GetParentBssDesc(const WXCDriverWork * driver)243 static inline const WMBssDesc *WXCi_GetParentBssDesc(const WXCDriverWork * driver)
244 {
245 return driver->target_bss;
246 }
247
248 /*---------------------------------------------------------------------------*
249 Name: WXCi_Stop
250
251 Description: Start transition of wireless state to STOP.
252
253 Arguments: None.
254
255 Returns: None.
256 *---------------------------------------------------------------------------*/
WXCi_Stop(WXCDriverWork * driver)257 static inline void WXCi_Stop(WXCDriverWork * driver)
258 {
259 WXC_SetDriverTarget(driver, WXC_DRIVER_STATE_STOP);
260 }
261
262 /*---------------------------------------------------------------------------*
263 Name: WXCi_StartParent
264
265 Description: Starts transition of wireless state from IDLE to MP_PARENT.
266
267 Arguments: None.
268
269 Returns: None.
270 *---------------------------------------------------------------------------*/
WXCi_StartParent(WXCDriverWork * driver)271 static inline void WXCi_StartParent(WXCDriverWork * driver)
272 {
273 WXC_SetDriverTarget(driver, WXC_DRIVER_STATE_PARENT);
274 }
275
276 /*---------------------------------------------------------------------------*
277 Name: WXCi_StartChild
278
279 Description: Starts transition of wireless state from IDLE to MP_CHILD.
280
281 Arguments: None.
282
283 Returns: None.
284 *---------------------------------------------------------------------------*/
WXCi_StartChild(WXCDriverWork * driver)285 static inline void WXCi_StartChild(WXCDriverWork * driver)
286 {
287 WXC_SetDriverTarget(driver, WXC_DRIVER_STATE_CHILD);
288 }
289
290 /*---------------------------------------------------------------------------*
291 Name: WXCi_Reset
292
293 Description: Resets wireless state and start transition to IDLE.
294
295 Arguments: None.
296
297 Returns: None.
298 *---------------------------------------------------------------------------*/
WXCi_Reset(WXCDriverWork * driver)299 static inline void WXCi_Reset(WXCDriverWork * driver)
300 {
301 WXC_SetDriverTarget(driver, WXC_DRIVER_STATE_IDLE);
302 }
303
304 /*---------------------------------------------------------------------------*
305 Name: WXCi_End
306
307 Description: Ends wireless communication.
308
309 Arguments: None.
310
311 Returns: None.
312 *---------------------------------------------------------------------------*/
WXCi_End(WXCDriverWork * driver)313 static inline void WXCi_End(WXCDriverWork * driver)
314 {
315 WXC_SetDriverTarget(driver, WXC_DRIVER_STATE_END);
316 }
317
318
319 /*===========================================================================*/
320
321 #ifdef __cplusplus
322 } /* extern "C" */
323 #endif
324
325
326 #endif /* NITRO_WXC_DRIVER_H_ */
327
328 /*---------------------------------------------------------------------------*
329 End of file
330 *---------------------------------------------------------------------------*/
331