1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WBT - include
3   File:     context.h
4 
5   Copyright 2006-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-11-04#$
14   $Rev: 9197 $
15   $Author: yosizaki $
16  *---------------------------------------------------------------------------*/
17 #ifndef	NITRO_WBT_CONTEXT_H_
18 #define	NITRO_WBT_CONTEXT_H_
19 
20 
21 /*===========================================================================*/
22 
23 #include <nitro/platform.h>
24 #include <nitro/misc.h>
25 #include <nitro/math/math.h>
26 #include <nitro/mi/memory.h>
27 #include <nitro/wbt.h>
28 
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 
35 /*---------------------------------------------------------------------------*/
36 /* Declarations */
37 
38 
39 /*****************************************************************************
40  * Wireless communication format
41  *****************************************************************************/
42 
43 /* REQ_SYNC command argument format structure */
44 typedef struct WBTPacketRequestSyncFormat
45 {
46     PLATFORM_LE16 peer_packet;
47     PLATFORM_LE16 own_packet;
48 }
49 PLATFORM_STRUCT_PADDING_FOOTER WBTPacketRequestSyncFormat;
50 
51 /* RES_SYNC command argument format structure */
52 typedef struct WBTPacketResponseSyncFormat
53 {
54     PLATFORM_LE16 block_total;
55     PLATFORM_LE16 peer_packet;
56     PLATFORM_LE16 own_packet;
57 }
58 PLATFORM_STRUCT_PADDING_FOOTER WBTPacketResponseSyncFormat;
59 
60 /* REQ_USERDATA command argument format structure */
61 typedef struct WBTPacketRequestUserDataFormat
62 {
63     PLATFORM_LE8 length;
64     PLATFORM_LE8 buffer[WBT_SIZE_USER_DATA];
65 }
66 WBTPacketRequestUserDataFormat;
67 
68 /* REQ_GETBLOCK_DONE command argument format structure */
69 typedef struct WBTPacketRequestGetBlockDoneFormat
70 {
71     PLATFORM_LE32 id;
72 }
73 WBTPacketRequestGetBlockDoneFormat;
74 
75 /* RES_GETBLOCK_DONE command argument format structure */
76 typedef struct WBTPacketResponseGetBlockDoneFormat
77 {
78     PLATFORM_LE32 id;
79 }
80 WBTPacketResponseGetBlockDoneFormat;
81 
82 /* REQ_GETBLOCK command argument format structure */
83 typedef struct WBTPacketRequestGetBlockFormat
84 {
85     PLATFORM_LE32 id;
86     PLATFORM_LE32 index;
87 }
88 WBTPacketRequestGetBlockFormat;
89 
90 /* RES_GETBLOCK command argument format structure */
91 typedef struct WBTPacketResponseGetBlockFormat
92 {
93     PLATFORM_LE32 id;
94     PLATFORM_LE32 index;
95 }
96 WBTPacketResponseGetBlockFormat;
97 
98 /* Packet header format structure */
99 typedef struct WBTPacketHeaderFormat
100 {
101     PLATFORM_LE8 command;
102     PLATFORM_LE16 bitmap;
103     PLATFORM_LE8 counter;
104 }
105 PLATFORM_STRUCT_PADDING_FOOTER WBTPacketHeaderFormat;
106 
107 /* Packet format structure */
108 typedef struct WBTPacketFormat
109 {
110     /* Packet header */
111     WBTPacketHeaderFormat header;
112     /* Existence of the next argument depends on the command */
113     union
114     {
115         u8      argument[10];
116         WBTPacketRequestSyncFormat req_sync;
117         WBTPacketResponseSyncFormat res_sync;
118         WBTPacketRequestUserDataFormat req_userdata;
119         WBTPacketRequestGetBlockDoneFormat req_getblock_done;
120         WBTPacketResponseGetBlockDoneFormat res_getblock_done;
121         WBTPacketRequestGetBlockFormat req_getblock;
122         WBTPacketResponseGetBlockFormat res_getblock;
123         u8      for_compiler[10];
124     } PLATFORM_STRUCT_PADDING_FOOTER /* unnamed */ ;
125     /* Existence of the next variable-length argument depends on the command */
126 }
127 PLATFORM_STRUCT_PADDING_FOOTER WBTPacketFormat;
128 
129 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketHeaderFormat) == 4);
130 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketRequestSyncFormat) == 4);
131 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketResponseSyncFormat) == 6);
132 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketRequestUserDataFormat) == 10);
133 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketRequestGetBlockDoneFormat) == 4);
134 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketResponseGetBlockDoneFormat) == 4);
135 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketRequestGetBlockFormat) == 8);
136 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketResponseGetBlockFormat) == 8);
137 PLATFORM_COMPILER_ASSERT(sizeof(WBTPacketFormat) == 14);
138 
139 
140 /*****************************************************************************
141  * Local Structures
142  *****************************************************************************/
143 
144 struct WBTContext;
145 struct WBTCommandList;
146 
147 /* Command callback prototype */
148 typedef void (*WBTEventCallback)(void*, WBTCommand*);
149 
150 /* Command list structure */
151 typedef struct WBTCommandList
152 {
153     struct WBTCommandList  *next;
154     WBTCommand              command;
155     WBTEventCallback        callback;
156 }
157 WBTCommandList;
158 
159 
160 /* Latest receipt status to be maintained for each AID by the parent */
161 typedef struct WBTRecvToken
162 {
163     u8      token_command;
164     u8      token_peer_cmd_counter;
165     u8      last_peer_cmd_counter;
166 
167     u8      dummy[1];
168 
169     /*
170      * These can only be replaced by WBT_CMD_REQ_GET_BLOCK* functions.
171      * Accessed when there is a response.
172      */
173     u32     token_block_id;
174     s32     token_block_seq_no;
175 }
176 WBTRecvToken;
177 
178 /* The different work variables to be maintained for each AID by the parent */
179 typedef struct WBTPacketBitmap
180 {
181     s32     length;
182     void   *buffer;
183     s32     count;
184     s32     total;
185     u32    *bitmap;
186     s32     current;
187 }
188 WBTPacketBitmap;
189 
190 /* Command management structure used by wbt_data.c */
191 typedef struct WBTContext
192 {
193     /* The processing command list and the available command pool */
194     WBTCommandList *command;
195     WBTCommandList *command_pool;
196 
197     /* Arbitrary user-defined value */
198     void               *userdata;
199     WBTEventCallback    callback;
200 
201     /*
202      * System callback buffer
203      * This is only used temporarily, but it is maintained in a context because it has 156 bytes.
204      */
205     WBTCommand system_cmd;
206 
207     /* The status of each AID */
208     struct
209     {
210         WBTRecvToken recv_token;
211         WBTPacketBitmap pkt_bmp;
212     }
213     peer_param[16];
214 
215     /* Own communication status */
216     int     my_aid;                    /* Own AID */
217     s16     peer_data_packet_size;     /* Size of peer packet data */
218     s16     my_data_packet_size;       /* Size of own packet data */
219     WBTBlockInfoList *list;            /* Registered data block list */
220     u8      my_command_counter;        /* User command issue counter */
221     u8      padding[3];
222     int     last_target_aid;
223 
224     /* Block number send history */
225     u32     last_block_id;
226     s32     last_seq_no_1;
227     s32     last_seq_no_2;
228 
229     /* Bitmap receiving the current request */
230     int     req_bitmap;
231 
232     /* GetBlockInfo bitmap */
233     u32     binfo_bitmap[16][MATH_ROUNDUP(sizeof(WBTBlockInfo), sizeof(u32)) / sizeof(u32)];
234 }
235 WBTContext;
236 
237 
238 /*---------------------------------------------------------------------------*/
239 /* Functions */
240 
241 /*---------------------------------------------------------------------------*
242   Name:         WBT_InitContext
243 
244   Description:  Initializes the WBT structure.
245 
246   Arguments:    work              The WBTContext structure.
247                 userdata         Arbitrary user-defined value.
248                 callback          The system callback.
249 
250   Returns:      None.
251  *---------------------------------------------------------------------------*/
252 void    WBT_InitContext(WBTContext *work, void *userdata, WBTEventCallback callback);
253 
254 /*---------------------------------------------------------------------------*
255   Name:         WBT_StartParent
256 
257   Description:  Starts the WBT as a parent.
258 
259   Arguments:    work              The WBTContext structure.
260                 own               Own MP send packet size.
261                 peer              Peer MP send packet size.
262 
263   Returns:      None.
264  *---------------------------------------------------------------------------*/
265 PLATFORM_ATTRIBUTE_INLINE
WBT_StartParent(WBTContext * work,int own,int peer)266 void    WBT_StartParent(WBTContext *work, int own, int peer)
267 {
268     SDK_MIN_ASSERT(own, WBT_PACKET_SIZE_MIN);
269     SDK_MIN_ASSERT(peer, WBT_PACKET_SIZE_MIN);
270     work->my_aid = 0;
271     work->my_data_packet_size = (s16)(own - WBT_PACKET_SIZE_MIN);
272     work->peer_data_packet_size = (s16)(peer - WBT_PACKET_SIZE_MIN);
273 }
274 
275 /*---------------------------------------------------------------------------*
276   Name:         WBT_StartChild
277 
278   Description:  Starts the WBT as a child.
279 
280   Arguments:    work              The WBTContext structure.
281                 aid               Own AID.
282 
283   Returns:      None.
284  *---------------------------------------------------------------------------*/
285 PLATFORM_ATTRIBUTE_INLINE
WBT_StartChild(WBTContext * work,int aid)286 void    WBT_StartChild(WBTContext *work, int aid)
287 {
288     work->my_data_packet_size = 0;
289     work->peer_data_packet_size = 0;
290     work->my_aid = aid;
291 }
292 
293 /*---------------------------------------------------------------------------*
294   Name:         WBT_ResetContext
295 
296   Description:  Reinitializes WBT.
297 
298   Arguments:    work              The WBTContext structure.
299                 callback          The system callback.
300 
301   Returns:      None.
302  *---------------------------------------------------------------------------*/
303 void    WBT_ResetContext(WBTContext *work, WBTEventCallback callback);
304 
305 /*---------------------------------------------------------------------------*
306   Name:         WBT_CallPacketSendHook
307 
308   Description:  Hook function for generating the send packet data.
309 
310   Arguments:    work              The WBTContext structure.
311                 buffer            The buffer to store the data.
312                 length            The buffer size.
313 
314   Returns:      The generated packet size.
315  *---------------------------------------------------------------------------*/
316 int     WBT_CallPacketSendHook(WBTContext *work, void *buffer, int length, BOOL is_parent);
317 
318 /*---------------------------------------------------------------------------*
319   Name:         WBT_CallPacketRecvHook
320 
321   Description:  Parses the receive packet data.
322 
323   Arguments:    work              The WBTContext structure.
324                 aid               The data sender's AID
325                 buffer            The received data buffer.
326                 length            Length of the received data.
327 
328   Returns:      None.
329  *---------------------------------------------------------------------------*/
330 void    WBT_CallPacketRecvHook(WBTContext *work, int aid, const void *buffer, int length);
331 
332 /*---------------------------------------------------------------------------*
333   Name:         WBT_GetUserData
334 
335   Description:  Gets the user-defined value associated with the context.
336 
337   Arguments:    work              The WBTContext structure.
338 
339   Returns:      Either the currently processing command or NULL.
340  *---------------------------------------------------------------------------*/
341 PLATFORM_ATTRIBUTE_INLINE
WBT_GetUserData(const WBTContext * work)342 void   *WBT_GetUserData(const WBTContext *work)
343 {
344     return work->userdata;
345 }
346 
347 /*---------------------------------------------------------------------------*
348   Name:         WBT_GetAid
349 
350   Description:  Gets the specified AID value.
351 
352   Arguments:    work              The WBTContext structure.
353 
354   Returns:      The set AID value.
355  *---------------------------------------------------------------------------*/
356 PLATFORM_ATTRIBUTE_INLINE
WBT_GetAid(const WBTContext * work)357 int WBT_GetAid(const WBTContext *work)
358 {
359     return work->my_aid;
360 }
361 
362 /*---------------------------------------------------------------------------*
363   Name:         WBT_GetOwnPacketLength
364 
365   Description:  Gets the current own send packet size.
366 
367   Arguments:    work              The WBTContext structure.
368 
369   Returns:      The current own send packet size.
370  *---------------------------------------------------------------------------*/
371 PLATFORM_ATTRIBUTE_INLINE
WBT_GetOwnPacketLength(const WBTContext * work)372 int WBT_GetOwnPacketLength(const WBTContext *work)
373 {
374     return work->my_data_packet_size;
375 }
376 
377 /*---------------------------------------------------------------------------*
378   Name:         WBT_GetPeerPacketLength
379 
380   Description:  Gets the current peer send packet size.
381 
382   Arguments:    work              The WBTContext structure.
383 
384   Returns:      The current peer send packet size.
385  *---------------------------------------------------------------------------*/
386 PLATFORM_ATTRIBUTE_INLINE
WBT_GetPeerPacketLength(const WBTContext * work)387 int WBT_GetPeerPacketLength(const WBTContext *work)
388 {
389     return work->peer_data_packet_size;
390 }
391 
392 /*---------------------------------------------------------------------------*
393   Name:         WBT_GetParentPacketLength
394 
395   Description:  Gets the current parent send packet size.
396 
397   Arguments:    work              The WBTContext structure.
398 
399   Returns:      The current parent send packet size.
400  *---------------------------------------------------------------------------*/
401 PLATFORM_ATTRIBUTE_INLINE
WBT_GetParentPacketLength(const WBTContext * work)402 int WBT_GetParentPacketLength(const WBTContext *work)
403 {
404     return (work->my_aid == 0) ? work->my_data_packet_size : work->peer_data_packet_size;
405 }
406 
407 /*---------------------------------------------------------------------------*
408   Name:         WBT_GetRegisteredCount
409 
410   Description:  Gets the total number of registered data blocks.
411 
412   Arguments:    work              The WBTContext structure.
413 
414   Returns:      The total number of registered data blocks.
415  *---------------------------------------------------------------------------*/
416 int     WBT_GetRegisteredCount(const WBTContext * work);
417 
418 /*---------------------------------------------------------------------------*
419   Name:         WBT_GetCurrentCommandList
420 
421   Description:  Gets the currently processing command.
422 
423   Arguments:    work              The WBTContext structure.
424 
425   Returns:      Either the currently processing command or NULL.
426  *---------------------------------------------------------------------------*/
427 PLATFORM_ATTRIBUTE_INLINE
WBT_GetCurrentCommandList(const WBTContext * work)428 WBTCommandList *WBT_GetCurrentCommandList(const WBTContext *work)
429 {
430     return work->command;
431 }
432 
433 /*---------------------------------------------------------------------------*
434   Name:         WBT_GetCurrentCommand
435 
436   Description:  Gets the currently processing command.
437 
438   Arguments:    work              The WBTContext structure.
439 
440   Returns:      Either the currently processing command or NULL.
441  *---------------------------------------------------------------------------*/
442 PLATFORM_ATTRIBUTE_INLINE
WBT_GetCurrentCommand(const WBTContext * work)443 WBTCommand *WBT_GetCurrentCommand(const WBTContext *work)
444 {
445     WBTCommandList *list = work->command;
446     return list ? &list->command : NULL;
447 }
448 
449 /*---------------------------------------------------------------------------*
450   Name:         WBT_GetBitmapLength
451 
452   Description:  Gets the bitmap buffer size needed for the block transfer control.
453 
454   Arguments:    work              The WBTContext structure.
455                 length            The maximum block size to be transferred.
456 
457   Returns:      Size of the necessary bitmap buffer
458  *---------------------------------------------------------------------------*/
459 int WBT_GetBitmapLength(const WBTContext *work, int length);
460 
461 /*---------------------------------------------------------------------------*
462   Name:         WBT_AddCommandPool
463 
464   Description:  Adds a new list to the command pool.
465 
466   Arguments:    work              The WBTContext structure.
467                 list              Array of command list structures.
468                 count             The number of array elements.
469 
470   Returns:      None.
471  *---------------------------------------------------------------------------*/
472 PLATFORM_ATTRIBUTE_INLINE
WBT_AddCommandPool(WBTContext * work,WBTCommandList * list,int count)473 void    WBT_AddCommandPool(WBTContext *work, WBTCommandList *list, int count)
474 {
475     while (--count >= 0)
476     {
477         list->next = work->command_pool;
478         work->command_pool = list++;
479     }
480 }
481 
482 /*---------------------------------------------------------------------------*
483   Name:         WBT_AllocCommandList
484 
485   Description:  Newly allocates one list from the command pool.
486 
487   Arguments:    work              The WBTContext structure.
488 
489   Returns:      Either the newly allocated command list or NULL.
490  *---------------------------------------------------------------------------*/
491 PLATFORM_ATTRIBUTE_INLINE
WBT_AllocCommandList(WBTContext * work)492 WBTCommandList *WBT_AllocCommandList(WBTContext *work)
493 {
494     WBTCommandList *list = work->command_pool;
495     if (list)
496     {
497         work->command_pool = list->next;
498         list->next = NULL;
499     }
500     return list;
501 }
502 
503 /*---------------------------------------------------------------------------*
504   Name:         WBT_SetPacketLength
505 
506   Description:  Changes the packet size.
507                 Can only be used with the parent.
508 
509   Arguments:    work              The WBTContext structure.
510                 own               Own MP send packet size.
511                 peer              Peer MP send packet size.
512 
513   Returns:      Returns TRUE if the setting succeeds.
514  *---------------------------------------------------------------------------*/
515 BOOL    WBT_SetPacketLength(WBTContext *work, int own, int peer);
516 
517 /*---------------------------------------------------------------------------*
518   Name:         WBT_CreateCommandSYNC
519 
520   Description:  Generates the "SYNC" command information.
521 
522   Arguments:    work              The WBTContext structure.
523                 list              The list prepared to stored command information.
524 
525   Returns:      None.
526  *---------------------------------------------------------------------------*/
527 PLATFORM_ATTRIBUTE_INLINE
WBT_CreateCommandSYNC(WBTContext * work,WBTCommandList * list)528 void WBT_CreateCommandSYNC(WBTContext *work, WBTCommandList *list)
529 {
530     (void)work;
531     list->command.command = WBT_CMD_REQ_SYNC;
532 }
533 
534 /*---------------------------------------------------------------------------*
535   Name:         WBT_CreateCommandINFO
536 
537   Description:  Sets the "INFO" command information to the list.
538 
539   Arguments:    work              The WBTContext structure.
540                 list              The list prepared to store command information.
541                 index: The index from the start of the registration list indicating the block information to obtain
542 
543                 buffer_table: A WBTBlockInfoTable of pointers that store the obtained block information.
544 
545 
546   Returns:      None.
547  *---------------------------------------------------------------------------*/
548 PLATFORM_ATTRIBUTE_INLINE
WBT_CreateCommandINFO(WBTContext * work,WBTCommandList * list,int index,const WBTBlockInfoTable * buffer_table)549 void WBT_CreateCommandINFO(WBTContext *work, WBTCommandList *list,
550                            int index, const WBTBlockInfoTable *buffer_table)
551 {
552     WBTGetBlockCallback *arg = &list->command.get;
553     arg->block_id = (u32)index;
554     arg->recv_data_size = sizeof(WBTBlockInfo);
555     {
556         int     i;
557         for (i = 0; i < 16; ++i)
558         {
559             arg->pkt_bmp_table.packet_bitmap[i] = work->binfo_bitmap[i];
560             arg->recv_buf_table.recv_buf[i] = (u8 *)buffer_table->block_info[i];
561         }
562     }
563     list->command.command = WBT_CMD_REQ_GET_BLOCKINFO;
564 }
565 
566 /*---------------------------------------------------------------------------*
567   Name:         WBT_CreateCommandGET
568 
569   Description:  Sets the "GET" command information to the list.
570 
571   Arguments:    work              The WBTContext structure.
572                 list              The list prepared to store command information.
573                 id                The block ID to be gotten.
574                 length            The length of the gotten block data.
575                 buffer_table: A WBTRecvBufTable of pointers that store the obtained block data.
576 
577                 bitmap_table: Table of buffers that manage the receive status necessary to control internal block transfers.
578 
579 
580   Returns:      None.
581  *---------------------------------------------------------------------------*/
582 PLATFORM_ATTRIBUTE_INLINE
WBT_CreateCommandGET(WBTContext * work,WBTCommandList * list,u32 id,u32 length,const WBTRecvBufTable * buffer_table,WBTPacketBitmapTable * bitmap_table)583 void WBT_CreateCommandGET(WBTContext *work, WBTCommandList * list,
584                           u32 id, u32 length,
585                           const WBTRecvBufTable *buffer_table,
586                           WBTPacketBitmapTable *bitmap_table)
587 {
588     WBTGetBlockCallback *arg = &list->command.get;
589     (void)work;
590     arg->block_id = id;
591     arg->recv_data_size = length;
592     arg->recv_buf_table = *buffer_table;
593     arg->pkt_bmp_table = *bitmap_table;
594     list->command.command = WBT_CMD_REQ_GET_BLOCK;
595 }
596 
597 /*---------------------------------------------------------------------------*
598   Name:         WBT_CreateCommandMSG
599 
600   Description:  Sets the "MSG" command information to the list.
601 
602   Arguments:    work              The WBTContext structure.
603                 list              The list prepared to store command information.
604                 buffer            The buffer where the send data was stored.
605                                   The buffer's content is only referenced within this function.
606                 length            The send data length.
607                                   Must be less than WBT_SIZE_USER_DATA.
608 
609   Returns:      None.
610  *---------------------------------------------------------------------------*/
611 PLATFORM_ATTRIBUTE_INLINE
WBT_CreateCommandMSG(WBTContext * work,WBTCommandList * list,const void * buffer,u32 length)612 void    WBT_CreateCommandMSG(WBTContext *work, WBTCommandList *list,
613                              const void *buffer, u32 length)
614 {
615     WBTRecvUserDataCallback *arg = &list->command.user_data;
616     (void)work;
617     SDK_MINMAX_ASSERT(length, 0, WBT_SIZE_USER_DATA);
618     arg->size = (u8)length;
619     MI_CpuCopy8(buffer, arg->data, length);
620     list->command.command = WBT_CMD_REQ_USER_DATA;
621 }
622 
623 /*---------------------------------------------------------------------------*
624   Name:         WBT_PostCommand
625 
626   Description:  Issues a command and adds it to the command queue.
627 
628   Arguments:    work              The WBTContext structure.
629                 list              The structure where the command information was stored.
630                                   Managed within the library until the command is completed.
631                 bitmap            The AID bitmap corresponding to the command issue.
632                 callback          Command completion callback. NULL if not needed.
633 
634   Returns:      None.
635  *---------------------------------------------------------------------------*/
636 void    WBT_PostCommand(WBTContext *work, WBTCommandList *list, u16 bitmap,
637                         WBTEventCallback callback);
638 
639 /*---------------------------------------------------------------------------*
640   Name:         WBT_PostCommandSYNC
641 
642   Description:  Issues the "SYNC" command information.
643 
644   Arguments:    context          The WBTContext structure.
645                 bitmap            The AID bitmap corresponding to the command issue.
646                 callback          Command completion callback. NULL if not needed.
647 
648   Returns:      TRUE if there is an available command list and the command issue succeeded.
649  *---------------------------------------------------------------------------*/
650 PLATFORM_ATTRIBUTE_INLINE
WBT_PostCommandSYNC(WBTContext * context,int bitmap,WBTEventCallback callback)651 BOOL    WBT_PostCommandSYNC(WBTContext *context, int bitmap, WBTEventCallback callback)
652 {
653     WBTCommandList *list = WBT_AllocCommandList(context);
654     if (list)
655     {
656         WBT_CreateCommandSYNC(context, list);
657         WBT_PostCommand(context, list, (u16)bitmap, callback);
658     }
659     return (list != NULL);
660 }
661 
662 /*---------------------------------------------------------------------------*
663   Name:         WBT_PostCommandINFO
664 
665   Description:  Issues the "INFO" command information.
666 
667   Arguments:    context          The WBTContext structure.
668                 bitmap            The AID bitmap corresponding to the command issue.
669                 callback          Command completion callback. NULL if not needed.
670                 index: The index from the start of the registration list indicating the block information to obtain
671 
672                 buffer_table: A WBTBlockInfoTable of pointers that store the obtained block information.
673 
674 
675   Returns:      TRUE if there is an available command list and the command issue succeeded.
676  *---------------------------------------------------------------------------*/
677 PLATFORM_ATTRIBUTE_INLINE
WBT_PostCommandINFO(WBTContext * context,int bitmap,WBTEventCallback callback,int index,const WBTBlockInfoTable * buffer_table)678 BOOL    WBT_PostCommandINFO(WBTContext *context, int bitmap, WBTEventCallback callback,
679                             int index, const WBTBlockInfoTable *buffer_table)
680 {
681     WBTCommandList *list = WBT_AllocCommandList(context);
682     if (list)
683     {
684         WBT_CreateCommandINFO(context, list, index, buffer_table);
685         WBT_PostCommand(context, list, (u16)bitmap, callback);
686     }
687     return (list != NULL);
688 }
689 
690 /*---------------------------------------------------------------------------*
691   Name:         WBT_PostCommandGET
692 
693   Description:  Issues the "GET" command information.
694 
695   Arguments:    context          The WBTContext structure.
696                 bitmap            The AID bitmap corresponding to the command issue.
697                 callback          Command completion callback. NULL if not needed.
698                 id                The block ID to be gotten.
699                 length            The length of the gotten block data.
700                 buffer_table: Table of WBTRecvBufTable pointers that store the obtained block data.
701 
702                 bitmap_table: Table of buffers that manage the receive status necessary to control internal block transfers.
703 
704 
705   Returns:      TRUE if there is an available command list and the command issue succeeded.
706  *---------------------------------------------------------------------------*/
707 PLATFORM_ATTRIBUTE_INLINE
WBT_PostCommandGET(WBTContext * context,int bitmap,WBTEventCallback callback,u32 id,u32 length,const WBTRecvBufTable * buffer_table,WBTPacketBitmapTable * bitmap_table)708 BOOL    WBT_PostCommandGET(WBTContext *context, int bitmap, WBTEventCallback callback,
709                            u32 id, u32 length, const WBTRecvBufTable *buffer_table,
710                            WBTPacketBitmapTable *bitmap_table)
711 {
712     WBTCommandList *list = WBT_AllocCommandList(context);
713     if (list)
714     {
715         WBT_CreateCommandGET(context, list, id, length, buffer_table, bitmap_table);
716         WBT_PostCommand(context, list, (u16)bitmap, callback);
717     }
718     return (list != NULL);
719 }
720 
721 /*---------------------------------------------------------------------------*
722   Name:         WBT_PostCommandMSG
723 
724   Description:  Issues the "MSG" command information.
725 
726   Arguments:    context          The WBTContext structure.
727                 bitmap            The AID bitmap corresponding to the command issue.
728                 callback          Command completion callback. NULL if not needed.
729                 buffer            The buffer where the send data was stored.
730                                   The buffer's content is only referenced within this function.
731                 length            The send data length.
732                                   Must be less than WBT_SIZE_USER_DATA.
733 
734   Returns:      TRUE if there is an available command list and the command issue succeeded.
735  *---------------------------------------------------------------------------*/
736 PLATFORM_ATTRIBUTE_INLINE
WBT_PostCommandMSG(WBTContext * context,int bitmap,WBTEventCallback callback,const void * buffer,u32 length)737 BOOL    WBT_PostCommandMSG(WBTContext *context, int bitmap, WBTEventCallback callback,
738                            const void *buffer, u32 length)
739 {
740     WBTCommandList *list = WBT_AllocCommandList(context);
741     if (list)
742     {
743         WBT_CreateCommandMSG(context, list, buffer, length);
744         WBT_PostCommand(context, list, (u16)bitmap, callback);
745     }
746     return (list != NULL);
747 }
748 
749 /*---------------------------------------------------------------------------*
750   Name:         WBT_CancelCommand
751 
752   Description:  Cancels the currently processing command.
753 
754   Arguments:    work              The WBTContext structure.
755                 bitmap            The peer that will cancel the command.
756 
757   Returns:      The bitmap that indicates the peer that will actually cancel the command.
758  *---------------------------------------------------------------------------*/
759 int     WBT_CancelCommand(WBTContext * work, int bitmap);
760 
761 /*---------------------------------------------------------------------------*
762   Name:         WBT_GetDownloadProgress
763 
764   Description:  Gets the block transfer progress status.
765 
766   Arguments:    work              The WBTContext structure.
767                 id                The receive block ID.
768                 aid               The recipient's AID.
769                 current           Where the received packets are stored.
770                 total             Where the total number of packets is stored.
771 
772   Returns:      None.
773                 Returns 0 for both current and total if there is not block transfer status.
774  *---------------------------------------------------------------------------*/
775 void    WBT_GetDownloadProgress(const WBTContext * work, u32 id, int aid, int *current, int *total);
776 
777 /*---------------------------------------------------------------------------*
778   Name:         WBT_RegisterBlockInfo
779 
780   Description:  Newly registers data blocks.
781 
782   Arguments:    work              The WBTContext structure.
783                 list              The list structure used for registration.
784                                   Used by the library until deallocated with Unregister.
785                 id                A unique ID associated with the data block.
786                 userinfo          User-defined information associated with the data block.
787                                   This pointer's target is only referenced within this function.
788                                   A NULL can be designated here if unnecessary.
789                 buffer            The buffer where the block data was stored.
790                                   When NULL is specified, the library will send a WBT_CMD_PREPARE_SEND_DATA callback notification as necessary.
791 
792                 length            The size of the block data.
793                                   This value must be correctly specified, even when NULL is specified for buffer.
794 
795 
796   Returns:      None.
797  *---------------------------------------------------------------------------*/
798 void    WBT_RegisterBlockInfo(WBTContext * work, WBTBlockInfoList *list, u32 id,
799                               const void *userinfo, const void *buffer, int length);
800 
801 /*---------------------------------------------------------------------------*
802   Name:         WBT_UnregisterBlockInfo
803 
804   Description:  Deallocates registered data blocks.
805 
806   Arguments:    work              The WBTContext structure.
807                 id                A unique ID associated with the data block to be deallocated.
808 
809   Returns:      Either the deallocated list structure or NULL.
810  *---------------------------------------------------------------------------*/
811 WBTBlockInfoList *WBT_UnregisterBlockInfo(WBTContext * work, u32 id);
812 
813 
814 /*===========================================================================*/
815 
816 #ifdef	__cplusplus
817 }          /* extern "C" */
818 #endif
819 
820 #endif /* NITRO_WBT_CONTEXT_H_ */
821 
822 /*---------------------------------------------------------------------------*
823 
824   $Log: context.h,v $
825   Revision 1.2  2007/08/22 05:22:32  yosizaki
826   Fixed dependencies.
827 
828   Revision 1.1  2007/04/10 08:20:14  yosizaki
829   Initial upload.
830 
831   $NoKeywords: $
832  *---------------------------------------------------------------------------*/
833