1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WXC - include -
3   File:     common.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_COMMON_H_
19 #define	NITRO_WXC_COMMON_H_
20 
21 
22 #include <nitro.h>
23 
24 
25 /*****************************************************************************/
26 /* macro */
27 
28 /*
29  * Switches debug output (disabled by default)
30  * You can set this symbol to 0 (disabled) or 1 (enabled) from the command line.
31  * The WXC library must be rebuilt before the change takes effect.
32  */
33 #if !defined(WXC_DEBUG_OUTPUT)
34 #define     WXC_DEBUG_OUTPUT    0
35 #endif
36 
37 /* Planned to be deleted */
38 #define     WXC_PACKET_LOG      WXC_DEBUG_LOG
39 #define     WXC_DRIVER_LOG      WXC_DEBUG_LOG
40 
41 /* Compile legitimacy check (used inside library) */
42 #if defined(SDK_COMPILER_ASSERT)
43 #define SDK_STATIC_ASSERT  SDK_COMPILER_ASSERT
44 #else
45 #define SDK_STATIC_ASSERT(expr) \
46     extern void sdk_compiler_assert ## __LINE__ ( char is[(expr) ? +1 : -1] )
47 #endif
48 
49 
50 /*****************************************************************************/
51 /* Constants */
52 
53 typedef enum
54 {
55     /* Internal state obtainable by WXC_GetStatus function */
56     WXC_STATE_END,                     /* End process completed by WXC_End function */
57     WXC_STATE_ENDING,                  /* After WXC_End function and currently running end process */
58     WXC_STATE_READY,                   /* After WXC_Init function and before WXC_Start function */
59     WXC_STATE_ACTIVE,                  /* After WXC_Start function and wireless communication is enabled */
60 
61     /* Internal event notified to the system callback */
62     WXC_STATE_CONNECTED,               /* Child connected (only for Parent side. argument is WMStartParentCallback) */
63     WXC_STATE_EXCHANGE_DONE,           /* Data exchange completed (argument is the user specified receive buffer) */
64     WXC_STATE_BEACON_RECV              /* Received beacon (argument is the WXCBeaconFoundCallback function) */
65 }
66 WXCStateCode;
67 
68 /* Parent mode beacon setting */
69 #define WXC_BEACON_PERIOD            90 /* [ms] */
70 #define WXC_PARENT_BEACON_SEND_COUNT_OUT (900 / WXC_BEACON_PERIOD)
71 
72 /* Library MP data packet size */
73 #define WXC_PACKET_SIZE_MIN          20
74 #define WXC_PACKET_SIZE_MAX          WM_SIZE_MP_DATA_MAX
75 
76 /* GGID for shared chance encounter communications */
77 #define WXC_GGID_COMMON_BIT          0x80000000UL
78 #define WXC_GGID_COMMON_ANY          (u32)(WXC_GGID_COMMON_BIT | 0x00000000UL)
79 #define WXC_GGID_COMMON_PARENT       (u32)(WXC_GGID_COMMON_BIT | 0x00400120UL)
80 
81 
82 /*****************************************************************************/
83 /* Declaration */
84 
85 /* WXC library callback function prototype */
86 typedef void (*WXCCallback) (WXCStateCode stat, void *arg);
87 
88 /* User information per AID held by WXC (obtained with WXC_GetUserInfo()) */
89 typedef struct WXCUserInfo
90 {
91     u16     aid;
92     u8      macAddress[6];
93 }
94 WXCUserInfo;
95 
96 /* Structure used for handling MP data packet */
97 typedef struct WXCPacketInfo
98 {
99     /*
100      * The send buffer or receive buffer.
101      * When sending, the actual data is stored in this buffer and returned.
102      */
103     u8     *buffer;
104     /*
105      * The maximum size that can be sent or the receive data size.
106      * When sending, the actual data size sent is stored here and returned.
107      */
108     u16     length;
109     /*
110      * A bitmap of the currently connected AIDs.
111      * (A system can determine whether it is a parent or child from the presence of bit 0)
112      * When sending, the actual send target is stored here and returned.
113      */
114     u16     bitmap;
115 }
116 WXCPacketInfo;
117 
118 /* WXC_STATE_BEACON_RECV callback argument */
119 typedef struct WXCBeaconFoundCallback
120 {
121     /*
122      * TRUE is given if the format matches the specified protocol and FALSE is given otherwise.
123      * This member is set to TRUE and returned when connecting to this beacon's sender.
124      *
125      */
126     BOOL    matched;
127     /*
128      * The beacon detected this time
129      */
130     const WMBssDesc *bssdesc;
131 }
132 WXCBeaconFoundCallback;
133 
134 
135 /*****************************************************************************/
136 /* Functions */
137 
138 #ifdef  __cplusplus
139 extern "C" {
140 #endif
141 
142 
143 /*---------------------------------------------------------------------------*
144     WXC Utilities
145  *---------------------------------------------------------------------------*/
146 
147 
148 /*---------------------------------------------------------------------------*
149   Name:         WXC_DEBUG_LOG
150 
151   Description:  WXC library internal debug output function.
152                 This function is modified with SDK_WEAK_SYMBOL and normally is equivalent to OS_TPrintf processing.
153                 You can override this with a function of the same name in an application-specific debugging system, for example.
154 
155 
156 
157   Arguments:    format: Document format string representing the debug output content
158                 ...: Variable argument
159 
160   Returns:      None.
161  *---------------------------------------------------------------------------*/
162 #if (WXC_DEBUG_OUTPUT == 1)
163 void    WXC_DEBUG_LOG(const char *format, ...);
164 #else
165 #define     WXC_DEBUG_LOG(...) ((void)0)
166 #endif
167 
168 /*---------------------------------------------------------------------------*
169   Name:         WXC_GetWmApiName
170 
171   Description:  Gets WM function's name string.
172 
173   Arguments:    id: WMApiid enumeration value representing WM function type
174 
175   Returns:      WM function name string.
176  *---------------------------------------------------------------------------*/
177 const char *WXC_GetWmApiName(WMApiid id);
178 
179 /*---------------------------------------------------------------------------*
180   Name:         WXC_GetWmErrorName
181 
182   Description:  Gets WM error code's name string.
183 
184   Arguments:    err: WMErrCode enumeration value representing WM error code
185 
186   Returns:      WM error code name string.
187  *---------------------------------------------------------------------------*/
188 const char *WXC_GetWmErrorName(WMErrCode err);
189 
190 /*---------------------------------------------------------------------------*
191   Name:         WXC_CheckWmApiResult
192 
193   Description:  Determines the return value from a WM function call and sends details to debug output if it is an error.
194 
195 
196   Arguments:    id: WM function types
197                 err: Error code returned from the function
198 
199   Returns:      TRUE if the return value is legitimate. FALSE if not.
200  *---------------------------------------------------------------------------*/
201 BOOL    WXC_CheckWmApiResult(WMApiid id, WMErrCode err);
202 
203 /*---------------------------------------------------------------------------*
204   Name:         WXC_CheckWmCallbackResult
205 
206   Description:  Determines the return value from a WM callback and sends details to debug output if it is an error.
207 
208 
209   Arguments:    arg: Argument returned to WM function callback
210 
211   Returns:      TRUE if the resulting value is legitimate. FALSE if not
212  *---------------------------------------------------------------------------*/
213 BOOL    WXC_CheckWmCallbackResult(void *arg);
214 
215 /*---------------------------------------------------------------------------*
216   Name:         WXC_GetNextAllowedChannel
217 
218   Description:  Gets the next usable channel after the selected channel.
219                 Loops to the bottom channel after the top channel.
220                 Gets the bottom channel if 0 is selected.
221 
222   Arguments:    ch: Channel position this time (1-14 or 0)
223 
224   Returns:      Next usable channel (1-14).
225  *---------------------------------------------------------------------------*/
226 u16     WXC_GetNextAllowedChannel(int ch);
227 
228 /*---------------------------------------------------------------------------*
229   Name:         WXC_IsCommonGgid
230 
231   Description:  Determines whether or not the specified GGID is a shared chance encounter communication protocol GGID.
232 
233   Arguments:    gid: GGID to be determined
234 
235   Returns:      TRUE if it is a shared chance encounter communication protocol.
236  *---------------------------------------------------------------------------*/
237 SDK_INLINE
WXC_IsCommonGgid(u32 ggid)238 BOOL    WXC_IsCommonGgid(u32 ggid)
239 {
240     return ((ggid & WXC_GGID_COMMON_BIT) != 0);
241 }
242 
243 
244 #ifdef  __cplusplus
245 }       /* extern "C" */
246 #endif
247 
248 
249 #endif /* NITRO_WXC_COMMON_H_ */
250 
251 /*---------------------------------------------------------------------------*
252   End of file
253  *---------------------------------------------------------------------------*/
254