1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WFS - include
3   File:     client.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:: 2009-02-06#$
14   $Rev: 9985 $
15   $Author: yosizaki $
16  *---------------------------------------------------------------------------*/
17 #ifndef	NITRO_WFS_CLIENT_H_
18 #define	NITRO_WFS_CLIENT_H_
19 
20 
21 #include <nitro/wfs/format.h>
22 
23 
24 #ifdef __cplusplus
25 extern  "C"
26 {
27 #endif
28 
29 
30 /*---------------------------------------------------------------------------*/
31 /* Constants */
32 
33 /* The maximum file size (set at 4 MB) the child device can receive */
34 #define	WFS_FILE_SIZE_MAX	(4 * 1024 * 1024)
35 
36 
37 /*---------------------------------------------------------------------------*/
38 /* Declarations */
39 
40 /* ROM read request completion callback */
41 struct WFSClientContext;
42 typedef void (*WFSRequestClientReadDoneCallback)(struct WFSClientContext *context, BOOL succeeded, void *arg);
43 
44 /* WBT client context structure */
45 typedef struct WFSClientContext
46 {
47     /* Basic settings */
48     void                   *userdata;
49     WFSEventCallback        callback;
50     MIAllocator            *allocator;
51     u32                     fat_ready:1;
52     u32                     flags:31;
53     /* WBT management */
54     WBTContext              wbt[1];
55     WBTCommandList          wbt_list[2];
56     WBTRecvBufTable         recv_buf_table;
57     WBTPacketBitmapTable    recv_buf_packet_bmp_table;
58     WBTBlockInfoTable       block_info_table;
59     WBTBlockInfo            block_info[16];
60     /* Receive bit set management */
61     u32                    *recv_pkt_bmp_buf;
62     u32                     max_file_size;
63     /* FAT management */
64     WFSTableFormat          table[1];
65     /* Request management */
66     u32                     block_id;
67     CARDRomRegion           request_region;
68     void                   *request_buffer;
69     WFSRequestClientReadDoneCallback request_callback;
70     void                   *request_argument;
71     void (*unmount_callback)(struct WFSClientContext*);
72     u8                      padding[8];
73 }
74 WFSClientContext;
75 
76 
77 /*---------------------------------------------------------------------------*/
78 /* Functions */
79 
80 /*---------------------------------------------------------------------------*
81   Name:         WFS_InitClient
82 
83   Description:  Initializes the WFS client context.
84 
85   Arguments:    context          The WFSClientContext structure.
86                 userdata:         Any user-defined value associated with the context.
87                 callback:         The system event notification callback.
88                                  Specify NULL if not needed.
89                 allocator:        The allocator used internally.
90 
91   Returns:      None.
92  *---------------------------------------------------------------------------*/
93 void WFS_InitClient(WFSClientContext *context,
94                     void *userdata, WFSEventCallback callback,
95                     MIAllocator *allocator);
96 
97 /*---------------------------------------------------------------------------*
98   Name:         WFS_StartClient
99 
100   Description:  Starts the WFS client context communication.
101 
102   Arguments:    context          The WFSClientContext structure.
103                 peer             The device's connection information.
104 
105   Returns:      None.
106  *---------------------------------------------------------------------------*/
107 void WFS_StartClient(WFSClientContext *context, const WFSPeerInfo *peer);
108 
109 /*---------------------------------------------------------------------------*
110   Name:         WFS_EndClient
111 
112   Description:  Deallocates the WFS client context.
113 
114   Arguments:    context          The WFSClientContext structure.
115 
116   Returns:      None.
117  *---------------------------------------------------------------------------*/
118 void WFS_EndClient(WFSClientContext *context);
119 
120 /*---------------------------------------------------------------------------*
121   Name:         WFS_CallClientConnectHook
122 
123   Description:  Connection notification on the client side.
124 
125   Arguments:    context          The WFSClientContext structure.
126                 peer:             Information for the connected client.
127 
128   Returns:      None.
129  *---------------------------------------------------------------------------*/
130 void WFS_CallClientConnectHook(WFSClientContext *context, const WFSPeerInfo *peer);
131 
132 /*---------------------------------------------------------------------------*
133   Name:         WFS_CallClientDisconnectHook
134 
135   Description:  Disconnect notification on the client side.
136 
137   Arguments:    context          The WFSClientContext structure.
138                 peer:             Information for the disconnected client.
139 
140   Returns:      None.
141  *---------------------------------------------------------------------------*/
142 void WFS_CallClientDisconnectHook(WFSClientContext *context, const WFSPeerInfo *peer);
143 
144 /*---------------------------------------------------------------------------*
145   Name:         WFS_CallClientPacketSendHook
146 
147   Description:  Notification of timing when it is possible to send packets on the client side.
148 
149   Arguments:    context          The WFSClientContext structure.
150                 packet:           Send packet settings.
151 
152   Returns:      The actual packet size.
153  *---------------------------------------------------------------------------*/
154 void WFS_CallClientPacketSendHook(WFSClientContext *context, WFSPacketBuffer *packet);
155 
156 /*---------------------------------------------------------------------------*
157   Name:         WFS_CallClientPacketRecvHook
158 
159   Description:  Notification of timing when it is possible to receive packets on the client side.
160 
161   Arguments:    context          The WFSClientContext structure.
162                 packet:           Sender packet information.
163 
164   Returns:      The actual packet size.
165  *---------------------------------------------------------------------------*/
166 void WFS_CallClientPacketRecvHook(WFSClientContext *context, const WFSPacketBuffer *packet);
167 
168 /*---------------------------------------------------------------------------*
169   Name:         WFS_IsClientReady
170 
171   Description:  Determine whether client-side preparations have completed.
172                 Returns TRUE after a WFS_EVENT_CLIENT_READY notification.
173 
174   Arguments:    context          The WFSClientContext structure.
175 
176   Returns:      TRUE if client-side preparations are complete.
177  *---------------------------------------------------------------------------*/
178 PLATFORM_ATTRIBUTE_INLINE
WFS_IsClientReady(const WFSClientContext * context)179 BOOL WFS_IsClientReady(const WFSClientContext *context)
180 {
181     return context->fat_ready ? TRUE : FALSE;
182 }
183 
184 /*---------------------------------------------------------------------------*
185   Name:         WFS_GetTableFormat
186 
187   Description:  Gets the ROM file table received from the server.
188                 Only gets a valid value after a WFS_EVENT_CLIENT_READY notification.
189 
190   Arguments:    context          The WFSClientContext structure.
191 
192   Returns:      Either the ROM file table or NULL.
193  *---------------------------------------------------------------------------*/
194 PLATFORM_ATTRIBUTE_INLINE
WFS_GetTableFormat(const WFSClientContext * context)195 const WFSTableFormat *WFS_GetTableFormat(const WFSClientContext *context)
196 {
197     return WFS_IsClientReady(context) ? context->table : NULL;
198 }
199 
200 /*---------------------------------------------------------------------------*
201   Name:         WFS_RequestClientRead
202 
203   Description:  Begins a ROM image read request from the server.
204 
205   Arguments:    context          The WFSClientContext structure.
206                 buffer           Memory where the read data will be stored.
207                 offset           Starting position for the device read.
208                 length           The read size.
209                 callback         Read completion callback
210                                  NULL if not necessary.
211                 arg              Argument passed to the read completion callback
212   Returns:      None.
213  *---------------------------------------------------------------------------*/
214 void WFS_RequestClientRead(WFSClientContext *context, void *buffer, u32 offset,
215                            u32 length, WFSRequestClientReadDoneCallback callback,
216                            void *arg);
217 
218 /*---------------------------------------------------------------------------*
219   Name:         WFS_GetClientReadProgress
220 
221   Description:  Gets the progress of the ROM image read request.
222 
223   Arguments:    context          The WFSClientContext structure.
224                 current          Variable that gets the number of received packets.
225                 total            Variable that gets the total expected number of packets.
226 
227   Returns:      None.
228  *---------------------------------------------------------------------------*/
229 void WFS_GetClientReadProgress(WFSClientContext *context, int *current, int *total);
230 
231 /*---------------------------------------------------------------------------*
232   Name:         WFS_ReplaceRomArchive
233 
234   Description:  Mount the WFS ROM file table on the "rom" archive.
235 
236   Arguments:    context          The WFSClientContext structure.
237 
238   Returns:      None.
239  *---------------------------------------------------------------------------*/
240 void WFS_ReplaceRomArchive(WFSClientContext *context);
241 
242 
243 /*---------------------------------------------------------------------------*/
244 
245 
246 #ifdef __cplusplus
247 } /* extern "C" */
248 #endif
249 
250 
251 #endif /* NITRO_WFS_CLIENT_H_ */
252 /*---------------------------------------------------------------------------*
253   $Log: client.h,v $
254   Revision 1.3  2007/08/22 05:22:32  yosizaki
255   Fixed dependencies.
256 
257   Revision 1.2  2007/06/11 09:02:30  yosizaki
258   Added some functions.
259 
260   Revision 1.1  2007/04/13 04:14:18  yosizaki
261   Initial upload.
262 
263   $NoKeywords: $
264  *---------------------------------------------------------------------------*/
265