1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MB - include
3   File:     mb_wm_base.h
4 
5   Copyright 2007-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   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef MB_WM_BASE_H_
19 #define MB_WM_BASE_H_
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include <nitro.h>
26 #include <nitro/wm.h>
27 
28 /* Maximum number of connections */
29 #define MB_NUM_PARENT_INFORMATIONS              16
30 
31 #define MB_MAX_SEND_BUFFER_SIZE         (0x400)
32 
33 /*
34  * Multiboot parent/child selection
35  * (Cannot be run for a non-IPL child)
36  */
37 #define MB_MODE_PARENT                          1
38 #define MB_MODE_CHILD                           2
39 
40 /*
41  * Definitions specific to wm_lib
42  */
43 
44 #define MB_CALLBACK_CHILD_CONNECTED             0
45 #define MB_CALLBACK_CHILD_DISCONNECTED          1
46 #define MB_CALLBACK_MP_PARENT_SENT              2
47 #define MB_CALLBACK_MP_PARENT_RECV              3
48 #define MB_CALLBACK_PARENT_FOUND                4
49 #define MB_CALLBACK_PARENT_NOT_FOUND            5
50 #define MB_CALLBACK_CONNECTED_TO_PARENT         6
51 #define MB_CALLBACK_DISCONNECTED                7
52 #define MB_CALLBACK_MP_CHILD_SENT               8
53 #define MB_CALLBACK_MP_CHILD_RECV               9
54 #define MB_CALLBACK_DISCONNECTED_FROM_PARENT    10
55 #define MB_CALLBACK_CONNECT_FAILED              11
56 #define MB_CALLBACK_DCF_CHILD_SENT              12
57 #define MB_CALLBACK_DCF_CHILD_SENT_ERR          13
58 #define MB_CALLBACK_DCF_CHILD_RECV              14
59 #define MB_CALLBACK_DISCONNECT_COMPLETE         15
60 #define MB_CALLBACK_DISCONNECT_FAILED           16
61 #define MB_CALLBACK_END_COMPLETE                17
62 #define MB_CALLBACK_MP_CHILD_SENT_ERR           18
63 #define MB_CALLBACK_MP_PARENT_SENT_ERR          19
64 #define MB_CALLBACK_MP_STARTED                  20
65 #define MB_CALLBACK_INIT_COMPLETE               21
66 #define MB_CALLBACK_END_MP_COMPLETE             22
67 #define MB_CALLBACK_SET_GAMEINFO_COMPLETE       23
68 #define MB_CALLBACK_SET_GAMEINFO_FAILED         24
69 #define MB_CALLBACK_MP_SEND_ENABLE              25
70 #define MB_CALLBACK_PARENT_STARTED              26
71 #define MB_CALLBACK_BEACON_LOST                 27
72 #define MB_CALLBACK_BEACON_SENT                 28
73 #define MB_CALLBACK_BEACON_RECV                 29
74 #define MB_CALLBACK_MP_SEND_DISABLE             30
75 #define MB_CALLBACK_DISASSOCIATE                31
76 #define MB_CALLBACK_REASSOCIATE                 32
77 #define MB_CALLBACK_AUTHENTICATE                33
78 #define MB_CALLBACK_SET_LIFETIME                34
79 #define MB_CALLBACK_DCF_STARTED                 35
80 #define MB_CALLBACK_DCF_SENT                    36
81 #define MB_CALLBACK_DCF_SENT_ERR                37
82 #define MB_CALLBACK_DCF_RECV                    38
83 #define MB_CALLBACK_DCF_END                     39
84 #define MB_CALLBACK_MPACK_IND                   40
85 #define MB_CALLBACK_MP_CHILD_SENT_TIMEOUT       41
86 #define MB_CALLBACK_SEND_QUEUE_FULL_ERR         42
87 
88 #define MB_CALLBACK_API_ERROR                   255     // Error on the value returned from an API call
89 #define MB_CALLBACK_ERROR                       256
90 
91 
92 /*
93  * Individual parent information received by a beacon (managed internally by the child)
94  */
95 typedef struct ParentInfo
96 {
97     union
98     {
99         WMBssDesc parentInfo[1];
100         u8      parentInfo_area[WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
101     };
102     /* Except for mac and GameInfo, probably not used at all */
103     WMStartScanCallback scan_data;
104     u8      reserved1[8];
105 }
106 ParentInfo;
107 
108 
109 /* Format of functions used for MB callbacks */
110 typedef void (*MBCallbackFunc) (u16 type, void *arg);
111 
112 
113 /*
114  * wm_lib parameter structure
115  * The part that bridges between wm_lib and wm_tool was temporarily forced to link, so some parts do not conform to ANSI-STRICT with respect to using unions
116  *
117  * (This may simply be replaced later so it has been postponed)
118  */
119 typedef struct
120 {
121     /* Parent information settings (used by the parent) */
122     union
123     {
124         WMParentParam parentParam;
125         u8      parentParam_area[WM_PARENT_PARAM_SIZE] ATTRIBUTE_ALIGN(32);
126     };
127 
128     /* WM internal buffer passed to StartMP (must not be used with SetMP) */
129     u16     sendBuf[MB_MAX_SEND_BUFFER_SIZE / sizeof(u16)] ATTRIBUTE_ALIGN(32);
130 
131     /* Buffer for getting parent information (used by the child) */
132     union
133     {
134         WMBssDesc parentInfoBuf;
135         u8      parentInfoBuf_area[WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
136     };
137 
138     u16     p_sendlen;
139     u16     p_recvlen;
140 
141     WMMpRecvBuf *recvBuf;              /* Receive buffer */
142 
143     /* Parent/child callback */
144     void    (*callback_ptr) (void *arg);
145 
146     u8      mpBusy;                    /* MP sending (busy) flag */
147     u8      mbIsStarted;
148     u8      reserved0[10];
149 
150     u16     sendBufSize;               // Size of send buffer
151     u16     recvBufSize;               // Size of MP receive buffer
152 
153     MBCallbackFunc callback;           // Callback for WM_lib
154     const WMBssDesc *pInfo;            // Pointer to information for the connected parent (used by the child)
155     u16     mode;                      // MB_MODE_***
156     u16     endReq;
157 
158     u16     mpStarted;                 // Flag indicating that MP has started
159     u16     child_bitmap;              // Child connection state
160 
161     /* Related to continuous sends */
162     u16     contSend;                  // Flag indicating execution of continuous transmission (1: Continuous transmission, 0: Per-frame communication)
163     u8      reserved1[2];
164 
165     // Related to gameinfo
166     u8      uname[WM_SIZE_USERNAME] ATTRIBUTE_ALIGN(4);
167     u8      gname[WM_SIZE_GAMENAME] ATTRIBUTE_ALIGN(4);
168     u16     currentTgid;               // TGID of the connected parent (checked with BeaconRecv.Ind)
169     u8      reserved2[22];
170 
171     u16     userGameInfo[((WM_SIZE_USER_GAMEINFO + 32) & ~(32 - 1)) /
172                          sizeof(u16)] ATTRIBUTE_ALIGN(32);
173 
174     /* Data unique to the child */
175     struct
176     {
177         /*
178          * The number of discovered parents.
179          * It initially has a value of 0, is incremented when StartScan succeeds, and is set to 0 when StartConnect fails.
180          * No one is currently looking at this, but it would probably be convenient for the user if it was included in BeconRecvState.
181          *
182          */
183         u16     found_parent_count;
184         /*
185          * AID assigned to self.
186          * It initially has a value of 0 and is set to n when StartConnect succeeds.
187          * No one is currently looking at this.
188          */
189         u16     my_aid;
190 
191         BOOL    scanning_flag;
192         BOOL    scan_channel_flag;
193         int     last_found_parent_no;
194 
195         u8      reserved8[16];
196 
197         /* Information array for 16 parent units */
198         ParentInfo parent_info[MB_NUM_PARENT_INFORMATIONS];
199     };
200 
201 }
202 MBiParam;
203 
204 
205 // ===============================================================================
206 // Functions
207 
208 /* Get the last parent to be found */
209 int     MBi_GetLastFountParent(void);
210 
211 /* Get the parent's BSS */
212 WMBssDesc *MBi_GetParentBssDesc(int parent);
213 
214 /* Set the maximum scan time */
215 void    MBi_SetMaxScanTime(u16 time);
216 
217 int     MBi_SendMP(const void *buf, int len, int pollbmp);
218 
219 int     MBi_GetSendBufSize(void);
220 
221 int     MBi_GetRecvBufSize(void);
222 
223 int     MBi_CommConnectToParent(const WMBssDesc *bssDescp);
224 
225 u32     MBi_GetGgid(void);
226 
227 u16     MBi_GetTgid(void);
228 
229 u8      MBi_GetAttribute(void);
230 
231 int     MBi_RestartScan(void);
232 
233 int     MBi_GetScanChannel(void);
234 
235 u16     MBi_GetAid(void);
236 
237 BOOL    MBi_IsStarted(void);
238 
239 int     MBi_CommEnd(void);
240 
241 void    MBi_CommParentCallback(u16 type, void *arg);
242 void    MBi_CommChildCallback(u16 type, void *arg);
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif /*  MB_WM_BASE_H_    */
249