/*---------------------------------------------------------------------------*
  Project:  NitroSDK - MB - include
  File:     tmp_lib_stub.h

  Copyright 2003-2004 Nintendo.  All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., and are protected by Federal copyright law.  They may
  not be disclosed to third parties or copied or duplicated in any form,
  in whole or in part, without the prior written consent of Nintendo.

  $Log: tmp_lib_stub.h,v $
  Revision 1.13  2004/11/29 04:47:36  yosizaki
  allocate sendBuf. (avoid to share with SetMPData's buffer)

  Revision 1.12  2004/11/22 12:56:22  takano_makoto
  Deleted structure member for getting WM status bufffer.

  Revision 1.11  2004/11/10 07:43:13  takano_makoto
  Removed MBw function from processing on child in mb_gameinfo.c.

  Revision 1.10  2004/10/18 11:44:30  yosizaki
  add MB_StartParentEx, MB_EndEx.

  Revision 1.9  2004/10/05 09:45:29  terui
  Standardized the MAC address as the u8 type array

  Revision 1.8  2004/09/22 12:16:53  sato_masaki
  add function MBw_GetMaxEntry()

  Revision 1.7  2004/09/22 09:42:11  sato_masaki
  Merged with IPL_branch 1.5.2.2.
  (Added the function MBw_GetWLVersion that gets the WirelessLibrary version.)

  Revision 1.6  2004/09/17 11:35:06  sato_masaki
  add function MBw_IsStarted()

  Revision 1.5  2004/09/15 06:25:01  sato_masaki
  Changed the sections that had a dependency on the definitions of MB_COMM_P_SENDLEN and MB_COMM_C_SENDLEN into variables.

  Revision 1.4  2004/09/14 02:41:32  sato_masaki
  Added mpBusy to MBiParam

  Revision 1.2  2004/09/06 11:43:52  sato_masaki
  Added the MBw_GetGgidLo(), MBw_GetGgidHi(), and MBw_GetTgid() functions.

  Revision 1.1  2004/09/03 07:06:28  sato_masaki
  Divided up the files by device 


  $NoKeywords: $
 *---------------------------------------------------------------------------*/

#ifndef _TMP_LIB_STUB_H_
#define _TMP_LIB_STUB_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <nitro.h>
#include <nitro/wm.h>

/* maximum number of connections */
#define MB_NUM_PARENT_INFORMATIONS              16

#define MB_MAX_SEND_BUFFER_SIZE         (0x400)

/*
 *  selection of the multiboot parent / child.
 * (cannot execute if the child is not IPL)
 */
#define MB_MODE_PARENT                          1
#define MB_MODE_CHILD                           2

/*
 * definitions unique to the wm_lib 
 */

#define MB_CALLBACK_CHILD_CONNECTED             0
#define MB_CALLBACK_CHILD_DISCONNECTED          1
#define MB_CALLBACK_MP_PARENT_SENT              2
#define MB_CALLBACK_MP_PARENT_RECV              3
#define MB_CALLBACK_PARENT_FOUND                4
#define MB_CALLBACK_PARENT_NOT_FOUND            5
#define MB_CALLBACK_CONNECTED_TO_PARENT         6
#define MB_CALLBACK_DISCONNECTED                7
#define MB_CALLBACK_MP_CHILD_SENT               8
#define MB_CALLBACK_MP_CHILD_RECV               9
#define MB_CALLBACK_DISCONNECTED_FROM_PARENT    10
#define MB_CALLBACK_CONNECT_FAILED              11
#define MB_CALLBACK_DCF_CHILD_SENT              12
#define MB_CALLBACK_DCF_CHILD_SENT_ERR          13
#define MB_CALLBACK_DCF_CHILD_RECV              14
#define MB_CALLBACK_DISCONNECT_COMPLETE         15
#define MB_CALLBACK_DISCONNECT_FAILED           16
#define MB_CALLBACK_END_COMPLETE                17
#define MB_CALLBACK_MP_CHILD_SENT_ERR           18
#define MB_CALLBACK_MP_PARENT_SENT_ERR          19
#define MB_CALLBACK_MP_STARTED                  20
#define MB_CALLBACK_INIT_COMPLETE               21
#define MB_CALLBACK_END_MP_COMPLETE             22
#define MB_CALLBACK_SET_GAMEINFO_COMPLETE       23
#define MB_CALLBACK_SET_GAMEINFO_FAILED         24
#define MB_CALLBACK_MP_SEND_ENABLE              25
#define MB_CALLBACK_PARENT_STARTED              26
#define MB_CALLBACK_BEACON_LOST                 27
#define MB_CALLBACK_BEACON_SENT                 28
#define MB_CALLBACK_BEACON_RECV                 29
#define MB_CALLBACK_MP_SEND_DISABLE             30
#define MB_CALLBACK_DISASSOCIATE                31
#define MB_CALLBACK_REASSOCIATE                 32
#define MB_CALLBACK_AUTHENTICATE                33
#define MB_CALLBACK_SET_LIFETIME                34
#define MB_CALLBACK_DCF_STARTED                 35
#define MB_CALLBACK_DCF_SENT                    36
#define MB_CALLBACK_DCF_SENT_ERR                37
#define MB_CALLBACK_DCF_RECV                    38
#define MB_CALLBACK_DCF_END                     39
#define MB_CALLBACK_MPACK_IND                   40
#define MB_CALLBACK_MP_CHILD_SENT_TIMEOUT       41
#define MB_CALLBACK_SEND_QUEUE_FULL_ERR         42

#define MB_CALLBACK_API_ERROR                   255     // error with the return value of the API call 
#define MB_CALLBACK_ERROR                       256


/*
 *  individual parent device information received with the beacon. (Child Device manages this internally)
 */
typedef struct  ParentInfo
{
    union
    {
        WMBssDesc   parentInfo[1];
        u8          parentInfo_area[WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
    } ;
    /* anyhting other than mac and GameInfo will probably not be used at all */
    WMStartScanCallback scan_data;
    u8      reserved1[8];
} ParentInfo;


/* a set of functions used in the MB callback */
typedef void (*MBCallbackFunc)( u16 type, void *arg );


/*
 * the wm_lib parameters structure .
 * Since the bridging section of wm_lib - wm_tool was forcibly linked at one point,
 * there is a part of the way that the union is used that is not in compliance with ANSI-STRICT.
 * (this will be postponed, since we're only talking about how it's OK to replace this later)
 */
typedef struct
{
    /* parent parameter settings (used by parent) */
    union
    {
        WMParentParam   parentParam;
        u8              parentParam_area[WM_PARENT_PARAM_SIZE] ATTRIBUTE_ALIGN(32);
    } ;

	/* WM internal buffer passed to StartMP. (must not be used by SetMP) */
    u16             sendBuf[MB_MAX_SEND_BUFFER_SIZE/sizeof(u16)] ATTRIBUTE_ALIGN(32);

    /* buffer that gets the Parent Device information (used by the Child Device) */
    union
    {
        WMBssDesc       parentInfoBuf;
        u8              parentInfoBuf_area[WM_BSS_DESC_SIZE] ATTRIBUTE_ALIGN(32);
    } ;

    u16             p_sendlen;
    u16             p_recvlen;

    WMMpRecvBuf     *recvBuf;   /* receive  buffer */

    /* Parent Device  /  Child Device   callback */
    void    (*callback_ptr)(void *arg);

    u8              mpBusy;     /* MP busy flag */
    u8              mbIsStarted;
    u8              reserved0[10];

    u16             sendBufSize;        // the size of the send buffer 
    u16             recvBufSize;        // the size of the MP receive buffer 

    MBCallbackFunc  callback;           // callback for WM_lib
    const WMBssDesc *pInfo;             // the connection destination Parent Device information pointer ( used by the Child Device)
    u16             mode;               // MB_MODE_***
    u16             endReq;

    u16             mpStarted;          // the MP started flag 
    u16             child_bitmap;       // the condition of the Child Device connection

    /* continuous send -related */
    u16             contSend;           // the continuous send execution flag (1:continuous send , 0:communication in each 1 frame )
    u8              reserved1[2];

    // gameinfo -related
    u8              uname[WM_SIZE_USERNAME] ATTRIBUTE_ALIGN(4);
    u8              gname[WM_SIZE_GAMENAME] ATTRIBUTE_ALIGN(4);
    u16             currentTgid;        // the TGID of the connection destination Parent Device (checked by BeaconRecv.Ind)
    u8              reserved2[22];

    u16             userGameInfo[ (( WM_SIZE_USER_GAMEINFO + 32 ) & ~( 32 - 1 )) / sizeof(u16) ] ATTRIBUTE_ALIGN(32);
    
    /* data unique to the Child Device */
    struct
    {
        /*
		 * The number of discovered parent devices..
		 * initial value 0, ++ with StartScan success, 0 with StartConnect failure.
		 * No one is currently looking at this, but
		 * it will probably be convenient for the user if also placed in BeconRecvState.
         */
        u16         found_parent_count;
        /*
	 * the AID allocated to itself;
	 * initial value 0, n with StartConnect success.
	 * No one is currently looking at this..
         */
        u16         my_aid;

        BOOL        scanning_flag;
        BOOL        scan_channel_flag;
        int         last_found_parent_no;

        u8          reserved8[16];

        /* information array for 16 Parent Devices */
        ParentInfo  parent_info[MB_NUM_PARENT_INFORMATIONS];
    } ;

} MBiParam;


// ===============================================================================
// API function

/******************************************************************************/
/* this is a function that was cut out because it is dependent on wmDEMOlib */


/* get the total number of Parents that have been found */
//int   MBw_GetParentCount(void);

/* get the last parent found */
int MBw_GetLastFountParent(void);

/* get the Parent BSS */
WMBssDesc*  MBw_GetParentBssDesc(int parent);

/* get the maximum scan time */
//u16 MBw_GetMaxScanTime(void);
void MBw_SetMaxScanTime(u16 time);

/* configure the scan channel seek */
//void    MBw_SetScanChannelSeek(BOOL e);

/* get the BSS to scan */
//void    MBw_SetScanBss(const u8 *bss);

int MBw_SendMP(const void *buf, int len, int pollbmp);

void    MBw_SetupParentParameter(
    void (*callback)(u16, void*),
    u16 parent_size, u16 child_size);

void MBw_SetupChildParameter( void (*callback)(u16, void*) );

void MBw_SetupCommonParameter( void *send_buf, void *recv_buf );

int MBw_GetSendBufSize(void);

int MBw_GetRecvBufSize(void);

int MBw_CommConnectToParent(const WMBssDesc *bssDescp);

u32 MBw_GetGgid(void);

u16 MBw_GetGgidLo(void);

u16 MBw_GetGgidHi(void);

u16 MBw_GetTgid(void);

u8 MBw_GetAttribute(void);

int MBw_RestartScan(void);

int MBw_GetScanChannel(void);

u16 MBw_GetAid(void);

int MBw_GetParentSendlen(void);

int MBw_GetParentRecvlen(void);

BOOL MBw_IsStarted(void);

int MBi_CommEnd(void);

void MBi_CommParentCallback( u16 type, void *arg );
void MBi_CommChildCallback( u16 type, void *arg );

u8 MBw_GetMaxEntry( void );

#ifdef __cplusplus
}
#endif

#endif  /*  _TMP_LIB_STUB_H_    */
