/*---------------------------------------------------------------------------*
  Project:  NitroSDK - WM - include
  File:     wm.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: wm.h,v $
  Revision 1.118  2004/11/10 13:02:51  takano_makoto
  Revised the include file

  Revision 1.117  2004/11/09 02:45:23  seiki_masashi
  Implemented a timeout caused by a Null response.
  Changed so that VAlarm process waits do not concurrently accumulate in the wireless process queue.

  Revision 1.116  2004/11/08 04:16:46  terui
  Added the linkLevel member to the MWStartScanExCallback structure.

  Revision 1.115  2004/11/04 12:14:28  terui
  Added a channel member to WMStartScanExCallback.

  Revision 1.114  2004/11/02 09:12:56  seiki_masashi
  Made changes to use the macro constant WM_DS_DATA_SIZE_252 for the switch.

  Revision 1.113  2004/11/02 07:28:42  terui
  Corrected comments

  Revision 1.112  2004/10/30 04:31:02  yasu
  comment out '#undef WM_ENABLE_TESTMODE'

  Revision 1.111  2004/10/27 04:29:57  ooe
  Changed the callback argument of StartScanEx.

  Revision 1.110  2004/10/26 08:23:39  ooe
  Added WM_StartScanEx. Defined WM_SIZE_SCAN_EX_BUF.

  Revision 1.109  2004/10/26 00:53:57  terui
  Newly added the WMDisconnectCallback structure.

  Revision 1.108  2004/10/22 09:31:58  seiki_masashi
  Added variable and APIID for Resume

  Revision 1.107  2004/10/22 01:54:42  seiki_masashi
  Expanded the maximum size for data sharing from 252 bytes to 508 bytes.

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

  Revision 1.105  2004/10/04 13:40:25  terui
  Standardized the game group ID as u32 type

  Revision 1.104  2004/10/04 11:43:54  terui
  Updated the WM_SIZE_MP_DATA_MAX definition

  Revision 1.103  2004/10/04 00:51:47  terui
  Changed WM_SIZE_MP_DATA_MAX from 510 to 508. (514-header(2)-footer(4))

  Revision 1.102  2004/10/03 07:52:54  ooe
  Merged with ipl_branch. Added support for ignoreFatalError flag and Flash error.

  Revision 1.101  2004/10/01 13:22:26  seiki_masashi
  Changed the calculation process of LinkLevel

  Revision 1.100  2004/10/01 04:11:23  terui
  Newly added the WM_ENABLE_TESTMODE switch. Default setting is undef.
  Added a feature that precalculates the wireless communication permitted channel when it is started

  Revision 1.99  2004/09/24 08:22:31  seiki_masashi
  fix comment

  Revision 1.98  2004/09/24 04:52:16  seiki_masashi
  Added WM_STATECODE_FIFO_ERROR
  Added reason to WMIndCallback

  Revision 1.97  2004/09/24 01:22:42  ooe
  Added errBitmap to WMMpRecvHeader (WL-2.05.00 and higher)

  Revision 1.96  2004/09/23 12:17:05  ooe
  Added AutoDisconnect.
  Also added the WMStatus member "curr.tgid" required for AutoDisconnect.

  Revision 1.95  2004/09/23 09:40:39  seiki_masashi
  Added a state field to WMDataSharingInfo

  Revision 1.94  2004/09/20 10:30:39  ooe
  Added WM_APIID_SET_BEACON_PERIOD.

  Revision 1.93  2004/09/17 06:36:40  seiki_masashi
  Added ssid and myAid fields to WMPortRecvCallback.

  Revision 1.92  2004/09/15 07:33:50  seiki_masashi
  Added WMStatus.mp_bufferEmptyFlag.

  Revision 1.91  2004/09/15 06:38:31  seiki_masashi
  Added WMStatus.mp_ping*.

  Revision 1.90  2004/09/15 05:40:27  ooe
  Added gameInfo and gameInfoLength
  in WMBeaconRecvIndCallback member.

  Revision 1.89  2004/09/13 04:22:06  seiki_masashi
  small fix.

  Revision 1.88  2004/09/13 04:09:16  seiki_masashi
  Added WM_SetMPFrequency.

  Revision 1.87  2004/09/10 12:04:37  seiki_masashi
  Hid key sharing send byte number in library.

  Revision 1.86  2004/09/09 12:39:45  seiki_masashi
  Added WM_HEADER_SIZE.

  Revision 1.85  2004/09/09 07:24:11  seiki_masashi
  Added WM_SetMPDataToPortEx.

  Revision 1.84  2004/09/09 02:00:57  terui
  Deleted unused Indication buffer.
  Changed part of APIID name.
  Added WM_STATE_READY (before WM_Enable) in internal state.

  Revision 1.83  2004/09/08 04:25:54  terui
  Changed WMApiid definitions. Added IDs for Enable, Disable, Idlize, and Stop.
  Changed padding size in WMArm9Buf.

  Revision 1.82  2004/09/03 04:36:41  seiki_masashi
  Added WM_ERRCODE_SEND_FAILED.
  Added WMStatus.mp_readyBitmap.

  Revision 1.81  2004/09/02 08:39:28  terui
  Added WM_SIZE_MP_DATA_MAX definition.

  Revision 1.80  2004/09/01 07:00:36  terui
  Added WM_STATE_MAX in WMState enum type.

  Revision 1.79  2004/08/31 09:26:07  seiki_masashi
  Added WMStatus.mp_setDataFlag, mp_sentDataFlag, and WM_ERRCODE_NO_DATA.

  Revision 1.78  2004/08/30 08:37:39  seiki_masashi
  Added WMStatus.mp_dataSettingFlag and mp_isPolledFlag.
  Added WM_ERRCODE_INVALID_POLLBITMAP.

  Revision 1.77  2004/08/30 01:58:59  seiki_masashi
  Consolidated WM_STATECODE_CHILD_CONNECTED in WM_STATECODE_CONNECTED.

  Revision 1.76  2004/08/30 00:53:51  terui
  Add definition about LinkLevel

  Revision 1.75  2004/08/27 08:17:18  terui
  Change pass to version_wl.h

  Revision 1.74  2004/08/27 06:46:33  seiki_masashi
  Added WMStatus.mp_newFrameFlag, mp_fixFreqMode and mp_defaultRetryCount.
  Added WMSendQueueData.retryCount.

  Revision 1.73  2004/08/26 09:42:35  ooe
  Added argument to BeaconRecv callback.

  Revision 1.72  2004/08/26 07:02:41  terui
  Include NITRO_WL_VERSION.

  Revision 1.71  2004/08/25 08:18:24  seiki_masashi
  Added status -> mp_minPollBmpMode and mp_singlePacketMode.

  Revision 1.70  2004/08/25 05:51:25  terui
  Rename parentRssi to lastRssi.

  Revision 1.69  2004/08/24 13:19:32  terui
  Added parentRssi member to WMStatus.

  Revision 1.68  2004/08/23 04:39:43  ooe
  Changed WM_StartConnect() specifications.

  Revision 1.67  2004/08/21 11:08:41  ooe
  Added support for WL-1.71.00.

  Revision 1.66  2004/08/21 06:56:01  ooe
  Created WMStartConnectReq type.

  Revision 1.65  2004/08/21 06:14:52  ooe
  Added ssid and ssidLength to WMStartParentCallback arguments.

  Revision 1.64  2004/08/20 04:29:17  terui
  Added WM_ERRCODE_OVER_MAX_ENTRY to error code.

  Revision 1.63  2004/08/19 16:24:19  miya
  switch GAMEINFO_TYPE

  Revision 1.62  2004/08/19 14:53:04  miya
  bug fix.

  Revision 1.61  2004/08/19 11:14:14  miya
  add GAMEINFO_VERSION

  Revision 1.60  2004/08/19 06:37:34  seiki_masashi
  Fixed DataSharingInfo structure for Key Sharing so that it matches 32-Byte align.

  Revision 1.59  2004/08/19 02:41:36  terui
  Added APIID form automatic disconnection by Entry availability.
  Added error code for when child is denied entry reception.

  Revision 1.58  2004/08/18 13:12:01  yosiokat
  Defined WM_GAMEINFO_TYPE_OLD.

  Revision 1.57  2004/08/18 09:01:38  miya
  modified WMGameInfo format

  Revision 1.56  2004/08/18 06:34:34  terui
  Added APIID for WM_SetEntry.
  Added allowedChannel member to WMStatus structure (padding and difference switching).

  Revision 1.55  2004/08/18 00:24:15  seiki_masashi
  Moved part of constant from wm_private.h.

  Revision 1.54  2004/08/17 12:50:45  seiki_masashi
  Changed send buffer so as to use the one specified by user program.
  Added status->maxReceiveSize.

  Revision 1.53  2004/08/16 06:50:50  ooe
  Added WMBeaconRecvIndCallback.

  Revision 1.52  2004/08/12 14:28:11  seiki_masashi
  Added WM_ERRCODE_FRAME_GAP.

  Revision 1.51  2004/08/11 04:26:45  seiki_masashi
  Added doubleMode field to WMDataSharingInfo.

  Revision 1.50  2004/08/11 00:19:42  terui
  Added reservation to port.

  Revision 1.49  2004/08/10 09:10:57  terui
  Extracted ARM9 dedicated function group definitions to wm_api.h.

  Revision 1.48  2004/08/10 04:12:13  seiki_masashi
  Added a macAddress field to WMPortRecvCallback for notifying connect and disconnect.

  Revision 1.47  2004/08/09 10:19:47  seiki_masashi
  Implemented exclusion control so that senqQueue will not be reset until sending is finished.

  Revision 1.46  2004/08/07 14:15:44  seiki_masashi
  Added a start process function for continuous WMSP_SendMaMP, SendMaKeyData.

  Revision 1.45  2004/08/07 10:19:46  seiki_masashi
  Save seq number of DataSet to WMDataSharingInfo.

  Revision 1.44  2004/08/07 08:45:49  seiki_masashi
  32-byte aligned DataSharing's send data.

  Revision 1.43  2004/08/07 07:04:40  seiki_masashi
  Changed WM_StepDataSharing argument.

  Revision 1.42  2004/08/07 04:06:44  seiki_masashi
  Added receivedBitmap field to WMDataSet.

  Revision 1.41  2004/08/07 02:55:56  terui
  Moved callback exclusion control flag to shared region.

  Revision 1.40  2004/08/07 01:22:47  seiki_masashi
  Added WMStatus.sendQueueMutex.

  Revision 1.39  2004/08/07 00:23:10  seiki_masashi
  Added dataSharing.

  Revision 1.38  2004/08/06 05:10:44  seiki_masashi
  small fix

  Revision 1.37  2004/08/05 11:59:16  ooe
  Support for more GetWirelessCounter items.

  Revision 1.36  2004/08/05 10:03:13  seiki_masashi
  Changed so that SetMPDataToPort() does not receive tmptt.

  Revision 1.35  2004/08/05 08:26:14  seiki_masashi
  Changes due to implementation of sendQueue.

  Revision 1.34  2004/08/04 06:57:03  seiki_masashi
  Added portSeqNo to WMStatus.

  Revision 1.33  2004/08/04 06:48:04  seiki_masashi
  Preparation for implementing send queue.
  WM_STATUS_BUF_SIZE from 512 to 2048.

  Revision 1.32  2004/08/04 06:21:33  ooe
  Added InitWirelessCounter and GetWirelessCounter.

  Revision 1.31  2004/08/04 02:29:39  seiki_masashi
  Added WMPortSendQueue structure definition.

  Revision 1.30  2004/08/04 01:44:30  seiki_masashi
  Preparation for introducing port.

  Revision 1.29  2004/08/03 12:22:28  ooe
  Support for WL TestMode command changes.

  Revision 1.28  2004/08/03 00:52:58  yosiokat
  Revised WM_SIZE_SYSTEM_GAMEINFO to "40". (for now)

  Revision 1.27  2004/08/02 06:29:15  terui
  Standardized WMbssDesc -> WMBssDesc.
  Standardized WMstatus -> WMStatus.

  Revision 1.26  2004/08/02 05:42:46  ooe
  small fix

  Revision 1.25  2004/08/02 05:34:49  ooe
  Added member for MPACK to the WMstartMPCallback structure.

  Revision 1.24  2004/08/02 02:52:32  terui
  Standardized structure names based on naming conventions.

  Revision 1.23  2004/07/31 09:03:41  sato_masaki
  Changed to 4-byte align when allocating the userGameInfo member in the WMgameInfo structure.

  Revision 1.22  2004/07/30 05:20:57  ooe
  Additional changes related to MeasureChannel.

  Revision 1.21  2004/07/29 12:11:00  ooe
  Added WM_MeasureChannel.

  Revision 1.20  2004/07/29 07:54:19  ikedae
  Added reasonCode for when disconnect.

  Revision 1.19  2004/07/29 07:38:46  miya
  modified callback table size

  Revision 1.18  2004/07/29 06:50:08  miya
  modified WMarm9Buf size

  Revision 1.17  2004/07/29 05:43:00  miya
  modified callback table size

  Revision 1.16  2004/07/29 04:21:38  miya
  add SetLifeTime function

  Revision 1.15  2004/07/28 07:35:20  terui
  Removed WM_EndConnect function definitions.

  Revision 1.14  2004/07/28 04:23:18  miya
  add functions about ggid and tgid

  Revision 1.13  2004/07/28 02:54:16  terui
  Revised structure padding.
  Added type names to enum.
  Changed WM_APIID_* to enum type.
  Moved WMState definition from wm_private.h.

  Revision 1.12  2004/07/27 07:32:24  yasu
  Add #pragma  warn_padding off

  Revision 1.11  2004/07/27 07:17:41  yasu
  Fix alignment 32 on WMpparam

  Revision 1.10  2004/07/20 01:24:34  terui
  Added STATECODE for indicate.
  Added callback vector storage variable for indicate.
  Added maximum connected children member to parent information.
  Removed scan_continue, scanning_ch members.
  Removed WM_getIndBuf function.
  Changed WM_SetGameInfo function specifications.
  Standardized functions to const if they take an argument with a pointer as src.

  Revision 1.9  2004/07/14 09:42:50  ooe
  Revisions due to StartScan argument changes

  Revision 1.8  2004/07/11 02:59:30  ooe
  Added WM_SetBeaconIndication()

  Revision 1.7  2004/07/10 12:52:39  miya
  Added beacon system

  Revision 1.6  2004/07/10 12:45:08  terui
  Modify comments.

  Revision 1.5  2004/07/10 09:30:30  ooe
  Added #define WM_APIID_VALARM_MP 23

  Revision 1.4  2004/07/08 09:50:35  terui
  Changes due to beginning of WM7 revision

  Revision 1.17  2004/07/06 08:04:27  Ooe
  Support for WL-1.56.00

  Revision 1.16  2004/07/06 05:49:05  Ooe
  Returned FIFO buffer size to 256 Bytes

  Revision 1.15  2004/07/06 02:08:24  Ooe
  Added WM_ATTR_FLAG_CS definition

  Revision 1.14  2004/07/06 01:51:28  Ooe
  Changed FIFO buffer size

  Revision 1.13  2004/07/05 13:01:47  Ooe
  Added ( ) to SYSTEM_BUF_SIZE

  Revision 1.12  2004/07/03 07:28:43  Ooe
  Changed definitions of size, etc

  Revision 1.11  2004/07/02 04:51:46  Miya
  Revised cache control size

  Revision 1.10  2004/06/29 06:50:27  Ooe
  Revised BssDesc structure

  Revision 1.9  2004/06/29 06:41:43  Miya
  As much as possible changed data size hard coding to macros.

  Revision 1.8  2004/06/25 06:18:27  Ooe
  Added argument (pollbmp) to WM_SetMPData()

  Revision 1.7  2004/06/25 02:15:27  Ooe
  Implemented WM_SetGameInfo() to fix corrupt DMA bug.

  Revision 1.6  2004/06/24 10:02:44  Ooe
  Added WM_SetGameInfo(),

  Revision 1.5  2004/06/21 06:39:42  Ooe
  (none)

  Revision 1.4  2004/06/19 05:56:58  Miya
  modified header file reference

  Revision 1.3  2004/06/19 04:03:08  miya
  ver. up Marionea-1.48.00

  Revision 1.2  2004/06/02 04:18:40  miya
  (none)

  Revision 1.1  2004/05/26 08:47:17  terui
  Additions due to embedding wireless

  $NoKeywords: $
 *---------------------------------------------------------------------------*/
#ifndef NITRO_WM_COMMON_WM_H_
#define NITRO_WM_COMMON_WM_H_

#ifdef __cplusplus
extern "C" {
#endif

/*===========================================================================*/

#include <nitro/types.h>
#include <nitro/os.h>
#include <nitro_wl/common/version_wl.h>


/*---------------------------------------------------------------------------*
    Constant definition
 *---------------------------------------------------------------------------*/

#undef WM_GAMEINFO_TYPE_OLD        // Switch for using WMGameInfo with the condition before it was changed (userGameInfo is 64 bytes).

// TEST mode enable switch
//#define WM_ENABLE_TESTMODE

// Compile switch that precalculates the usable channels.
#if ( SDK_VERSION_WL >= 15600 )
#ifdef  SDK_TEG
    #undef  WM_PRECALC_ALLOWEDCHANNEL
#else
    #define WM_PRECALC_ALLOWEDCHANNEL
#endif
#else
    #undef  WM_PRECALC_ALLOWEDCHANNEL
#endif


// WM API related ===========================================================================

// ID for each API
typedef enum WMApiid
{
    WM_APIID_INITIALIZE = 0 ,       //  0 : WM_Initialize()
    WM_APIID_RESET ,                //  1 : WM_Reset()
    WM_APIID_END ,                  //  2 : WM_End()

    WM_APIID_ENABLE ,               //  3 : WM_Enable()
    WM_APIID_DISABLE ,              //  4 : WM_Disable()
    WM_APIID_POWER_ON ,             //  5 : WM_PowerOn()
    WM_APIID_POWER_OFF ,            //  6 : WM_PowerOff()

    WM_APIID_SET_P_PARAM ,          //  7 : WM_SetParentParameter()
    WM_APIID_START_PARENT ,         //  8 : WM_StartParent()
    WM_APIID_END_PARENT ,           //  9 : WM_EndParent()
    WM_APIID_START_SCAN ,           // 10 : WM_StartScan()
    WM_APIID_END_SCAN ,             // 11 : WM_EndScan()
    WM_APIID_START_CONNECT ,        // 12 : WM_StartConnect()
    WM_APIID_DISCONNECT ,           // 13 : WM_Disconnect()
    WM_APIID_START_MP ,             // 14 : WM_StartMP()
    WM_APIID_SET_MP_DATA ,          // 15 : WM_SetMPData()
    WM_APIID_END_MP ,               // 16 : WM_EndMP()
    WM_APIID_START_DCF ,            // 17 : WM_StartDCF()
    WM_APIID_SET_DCF_DATA ,         // 18 : WM_SetDCFData()
    WM_APIID_END_DCF ,              // 19 : WM_EndDCF()
    WM_APIID_SET_WEPKEY ,           // 20 : WM_SetWEPKey()
    WM_APIID_START_KS ,             // 21 : WM_StartKeySharing() Kept for the downward compatibility
    WM_APIID_END_KS ,               // 22 : WM_EndKeySharing()   Kept for the downward compatibility
    WM_APIID_GET_KEYSET ,           // 23 : WM_GetKeySet()
    WM_APIID_SET_GAMEINFO ,         // 24 : WM_SetGameInfo()
    WM_APIID_SET_BEACON_IND ,       // 25 : WM_SetBeaconIndication()
    WM_APIID_START_TESTMODE ,       // 26 : WM_StartTestMode()
    WM_APIID_STOP_TESTMODE ,        // 27 : WM_StopTestMode()
    WM_APIID_VALARM_MP ,            // 28 : For starting up MP from VAlarm in ARM7 (special)
    WM_APIID_SET_LIFETIME ,         // 29 : WM_SetLifeTime()
    WM_APIID_MEASURE_CHANNEL ,      // 30 : WM_MeasureChannel()
    WM_APIID_INIT_W_COUNTER ,       // 31 : WM_InitWirelessCounter()
    WM_APIID_GET_W_COUNTER ,        // 32 : WM_GetWirelessCounter()
    WM_APIID_SET_ENTRY ,            // 33 : WM_SetEntry()
    WM_APIID_AUTO_DEAUTH ,          // 34 : For starting up automatic disconnection from indicate in ARM7. (special)
    WM_APIID_SET_MP_FREQ ,          // 35 : WM_SetMPFrequency()
    WM_APIID_SET_BEACON_PERIOD,     // 36 : WM_SetBeaconPeriod()
    WM_APIID_AUTO_DISCONNECT ,      // 37 : For starting up automatic disconnection from indicate in ARM7. (special)
    WM_APIID_START_SCAN_EX ,        // 38 : WM_StartScanEx()

    WM_APIID_KICK_MP_PARENT ,       // 39 : For starting up MP (ARM7 internal use)
    WM_APIID_KICK_MP_CHILD ,        // 40 : For starting up MP (ARM7 internal use)
    WM_APIID_KICK_MP_RESUME ,       // 41 : For starting up MP (ARM7 internal use)

    WM_APIID_ASYNC_KIND_MAX ,       // 42 : Type of asynchronous process

    WM_APIID_INDICATION     = 128 , // 128 : For indication callback
    WM_APIID_PORT_SEND ,            // 129 : Data send notification to port
    WM_APIID_PORT_RECV ,            // 130 : Data receive notification to port
    WM_APIID_READ_STATUS ,          // 131 : WM_ReadStatus()

    WM_APIID_UNKNOWN        = 255   // 255 : Value returned from ARM7 at unknown command number

} WMApiid;

// WEP mode
#define WM_WEPMODE_NO           0
#define WM_WEPMODE_40BIT        1
#define WM_WEPMODE_104BIT       2
#define WM_WEPMODE_128BIT       3
#define WM_WEPMODE_232BIT       4

// Maximum number of children that can connect in one BSS
#define WM_NUM_MAX_CHILD 15

// Number of ports
#define WM_NUM_OF_PORT          16      // Number of ports
#define WM_NUM_OF_SEQ_PORT      8       // Number of ports that do sequential processing
typedef enum WMPort
{
    // Group of ports that do not do sequential control
    WM_PORT_RAWDATA     = 0 ,   // Port for downward compatibility
    WM_PORT_BT          = 1 ,   // Port for block transfer
    WM_PORT_RESERVE_02  = 2 ,   // Reserved
    WM_PORT_RESERVE_03  = 3 ,   // Reserved

    // Group of ports that do sequential control
    WM_PORT_KS = 8 ,            // KeySharing port ( port number (WM_NUM_OF_PORT - WM_NUM_OF_SEQ_PORT) )
    WM_PORT_RESERVE_11  = 9 ,   // Reserved
    WM_PORT_RESERVE_12  = 10 ,  // Reserved
    WM_PORT_RESERVE_13  = 11    // Reserved

} WMPort;

// Send queue related
#define WM_SEND_QUEUE_NUM       64      // Total 64 level queue list
#define WM_SEND_QUEUE_END       ((u16)0xffff) // Value that indicates tail
#define WM_PRIORITY_LEVEL       4       // 4 priority levels
typedef enum WMPriorityLevel
{
    WM_PRIORITY_URGENT = 0,
    WM_PRIORITY_HIGH,
    WM_PRIORITY_NORMAL,
    WM_PRIORITY_LOW

} WMPriorityLevel;

// Send interval
#define WM_MP_FREQ_CONT         16      // Send frequency that becomes continuous send
#define WM_MP_COUNT_LIMIT       256     // Upper limit of the counter for the number of sends remaining.

// Size of each type of data (bytes)
#define WM_SIZE_BSSID           6
#define WM_SIZE_SSID            32

#define WM_SIZE_GAMEINFO        128     // Maximum size

#define WM_SIZE_SCAN_EX_BUF     1024    // Buffer size for StartScanEx

#ifdef WM_GAMEINFO_TYPE_OLD

#define WM_SIZE_SYSTEM_GAMEINFO 40      // Size up to userGameInfoLength
#define WM_SIZE_USER_GAMEINFO   64      // Maximum size of GameInfo user area

#else

#define WM_GAMEINFO_VERSION_NUM 1
#define WM_SIZE_SYSTEM_GAMEINFO 16      // size up to userGameInfoLength
#define WM_SIZE_USER_GAMEINFO   112      // Maximum user area size for GameInfo

#endif

#define WM_SIZE_SCAN_PARAM      32

#define WM_PARENT_PARAM_SIZE    64
#define WM_SIZE_USERNAME        8
#define WM_SIZE_GAMENAME        16
#define WM_SIZE_GGID            4

#define WM_SIZE_WL_VERSION      8
#define WM_SIZE_BBP_VERSION     4
#define WM_SIZE_MACADDR         6
#define WM_SIZE_WEPKEY          80

#define WM_SIZE_CHILD_SSID      24

#if ( SDK_VERSION_WL >= 21100 )
#define WM_SIZE_MP_DATA_MAX     512
#else
#define WM_SIZE_MP_DATA_MAX     508
#endif

// number of bytes needed between packets when parent puts multiple packets in one MP transmission
#define WM_SIZE_MP_PARENT_PADDING   (WM_HEADER_SIZE + WM_HEADER_PARENT_MAX_SIZE)
// number of bytes needed between packets when child puts multiple packets in one MP transmission
#define WM_SIZE_MP_CHILD_PADDING    (WM_HEADER_SIZE + WM_HEADER_CHILD_MAX_SIZE)

#define WM_SIZE_DS_PARENT_HEADER    4
#define WM_SIZE_KS_PARENT_DATA  (2*16+WM_SIZE_DS_PARENT_HEADER)
#define WM_SIZE_KS_CHILD_DATA   2

// Attribute flags

#define WM_ATTR_ENTRY_SHIFT     0
#define WM_ATTR_MB_SHIFT        1
#define WM_ATTR_KS_SHIFT        2
#define WM_ATTR_CS_SHIFT        3

#define WM_ATTR_FLAG_ENTRY      (1 << WM_ATTR_ENTRY_SHIFT)
#define WM_ATTR_FLAG_MB         (1 << WM_ATTR_MB_SHIFT)
#define WM_ATTR_FLAG_KS         (1 << WM_ATTR_KS_SHIFT)
#define WM_ATTR_FLAG_CS         (1 << WM_ATTR_CS_SHIFT)

// For callback exclusive control
#define WM_EXCEPTION_CB_MASK    0x0001

// wmHeader
#define WM_HEADER_SIZE          2 // number of bytes of shared parent/child wmHeader

//#define WM_HEADER_MP        0x0001
#define WM_HEADER_KS        0x4000
#define WM_HEADER_VSYNC     0x8000

// packetHeader
#define WM_HEADER_PARENT_MAX_SIZE   4   // maximum number of bytes that can be added as header (excluding the 2 bytes of wmHeader)
                                        // At present there are cases where Sequence Number and Destination Bitmap are added.

#define WM_HEADER_CHILD_MAX_SIZE    2   // maximum number of bytes that can be added as header (excluding the 2 bytes of wmHeader)
                                        // At present there are cases where Sequence Number is added.

#define WM_HEADER_PORT_MASK     0x0f00
#define WM_HEADER_PORT_SHIFT    8
#define WM_HEADER_SEQ_FLAG      0x0800
#define WM_HEADER_DEST_BITMAP   0x1000
#define WM_HEADER_LENGTH_MASK   0x00ff
#define WM_HEADER_LENGTH_SCALE  2

#define WM_SEQ_PORT_FLAG        0x0008
#define WM_SEQ_PORT_MASK        0x0007

// packetHeader Seq No Field ( second byte)
#define WM_HEADER_SEQ_RETRY     0x8000
#define WM_HEADER_SEQ_NUM_MASK  0x7fff


// API result codes
typedef enum WMErrCode
{
    WM_ERRCODE_SUCCESS          = 0 ,
    WM_ERRCODE_FAILED           = 1 ,
    WM_ERRCODE_OPERATING        = 2 ,
    WM_ERRCODE_ILLEGAL_STATE    = 3 ,
    WM_ERRCODE_WM_DISABLE       = 4 ,
    WM_ERRCODE_NO_KEYSET        = 5 ,
    WM_ERRCODE_NO_DATASET       = 5 , // Same value as NO_KEYSET
    WM_ERRCODE_INVALID_PARAM    = 6 ,
    WM_ERRCODE_NO_CHILD         = 7 ,
    WM_ERRCODE_FIFO_ERROR       = 8 ,
    WM_ERRCODE_TIMEOUT          = 9 ,
    WM_ERRCODE_SEND_QUEUE_FULL  = 10 ,
    WM_ERRCODE_NO_ENTRY         = 11 ,
    WM_ERRCODE_OVER_MAX_ENTRY   = 12 ,
    WM_ERRCODE_INVALID_POLLBITMAP = 13 ,
    WM_ERRCODE_NO_DATA          = 14 ,
    WM_ERRCODE_SEND_FAILED      = 15 ,

    WM_ERRCODE_DCF_TEST ,               // For debugging
    WM_ERRCODE_WL_INVALID_PARAM ,       // For debugging (can delete)
    WM_ERRCODE_WL_LENGTH_ERR ,          // For debugging (can delete)

    WM_ERRCODE_FLASH_ERROR ,            // WL flash parameter error (freezes because it is fatal)
    WM_ERRCODE_MAX

} WMErrCode;

// State codes returned by the API's callback
typedef enum WMStateCode
{
    WM_STATECODE_PARENT_START   = 0 ,   // For StartParent. Started parent operation
    WM_STATECODE_BEACON_SENT    = 2 ,   // For StartParent. Beacon send completed

    WM_STATECODE_SCAN_START     = 3 ,   // For StartScan. Started Scan operation
    WM_STATECODE_PARENT_NOT_FOUND = 4 , // For StartScan. Cannot find parent
    WM_STATECODE_PARENT_FOUND   = 5 ,   // For StartScan. Found parent

    WM_STATECODE_CONNECT_START  = 6 ,   // For StartConnect. Started connect process
    WM_STATECODE_BEACON_LOST    = 8 ,   // For StartConnect. Lost parent's beacon

    WM_STATECODE_CONNECTED      = 7 ,   // For StartParent and StartConnect. Connection complete
    WM_STATECODE_CHILD_CONNECTED = 7 ,  // same value as WM_STATECODE_CONNECTED
    WM_STATECODE_DISCONNECTED   = 9 ,   // For StartParent and StartConnect. Disconnect notification

    WM_STATECODE_MP_START       = 10 ,  // For StartMP. Started MP communication mode.
    WM_STATECODE_MPEND_IND      = 11 ,  // For StartMP. Parent MP sequence complete (receive)
    WM_STATECODE_MP_IND         = 12 ,  // For StartMP. Child MP receive
    WM_STATECODE_MPACK_IND      = 13 ,  // For StartMP. Child MPACK receive

    WM_STATECODE_DCF_START      = 14 ,  // For StartDCF. Started DCF communication mode.
    WM_STATECODE_DCF_IND        = 15 ,  // For StartDCF. Received DCF data

    WM_STATECODE_BEACON_RECV    = 16 ,  // Indicate beacon receive
    WM_STATECODE_DISASSOCIATE   = 17 ,  // Indicate connection disconnect
    WM_STATECODE_REASSOCIATE    = 18 ,  // Indicate reconnect
    WM_STATECODE_AUTHENTICATE   = 19 ,  // Indicate authenticate

    WM_STATECODE_PORT_SEND      = 20 ,  // Send data to port
    WM_STATECODE_PORT_RECV      = 21 ,  // Receive data from port

    WM_STATECODE_FIFO_ERROR     = 22 ,  // FIFO error occurrence notification in ARM7

    WM_STATECODE_MAX            = 23

} WMStateCode;

// WM state code
typedef enum WMState
{
    WM_STATE_READY = 0 ,                // READY state (before Init, LED normal lighting state)
    WM_STATE_STOP ,                     // STOP state (Before Initialize, LED blinking state)
    WM_STATE_IDLE ,                     // IDLE state (After Initialize. After Reset, etc)
    WM_STATE_CLASS1 ,                   // CLASS1 state
    WM_STATE_TESTMODE ,                 // TESTMODE(for applying)
    WM_STATE_SCAN ,                     // During StartScan
    WM_STATE_CONNECT ,                  // During StartConnect
    WM_STATE_PARENT ,                   // During StartParent
    WM_STATE_CHILD ,                    // Child after connect complete
    WM_STATE_MP_PARENT ,                // Parent after StartMP
    WM_STATE_MP_CHILD ,                 // Child after StartMP
    WM_STATE_DCF_CHILD ,                // Child after StartDCF
    WM_STATE_MAX

} WMState;

// link strength
typedef enum WMLinkLevel
{
    WM_LINK_LEVEL_0 = 0 ,
    WM_LINK_LEVEL_1 ,
    WM_LINK_LEVEL_2 ,
    WM_LINK_LEVEL_3 ,
    WM_LINK_LEVEL_MAX

} WMLinkLevel;

// Data Sharing internal state
typedef enum WMDataSharingState
{
    WM_DS_STATE_READY = 0 ,             // Before WM_StartDataSharing
    WM_DS_STATE_START ,                 // During WM_StartDataSharing
    WM_DS_STATE_PAUSING ,               // While changing to the pause state
    WM_DS_STATE_PAUSED ,                // Immediately after WM_StartDataSharing or during pause
    WM_DS_STATE_RETRY_SEND ,            // Resend required because of SEND_QUEUE_FULL
    WM_DS_STATE_ERROR                   // Error generated
} WMDataSharingState;

// WM API callback type
typedef void (*WMcallbackFunc)( void *arg );        // WM API callback type
typedef void (*WMCallbackFunc)( void* arg );        // WM API callback type

// Buffer size =======================================================================

// ----------------------
// | WM9 variable       | 1536
// |--------------------|
// | WM7 variable       | 256
// |--------------------|
// | WM status          | 2560
// |--------------------|
// | Indication buffer  | 256     // -> To size 0 (to be deleted) 2004/09/08 terui
// |--------------------|
// | FIFO buf (9 -> 7)  | 256
// |--------------------|
// | FIFO buf (9 <- 7)  | 256
// ----------------------

// Size of the buffer used with WM -------------------

//#define WM_DS_DATA_SIZE_252

#ifdef WM_DS_DATA_SIZE_252      // When it is OK to set 252 for WM_DS_DATA_SIZE
#define WM_ARM9WM_BUF_SIZE      1536                // Size of the WM variable area on ARM9
#else                           // When WM_DS_DATA_SIZE is 508 (default)
#define WM_ARM9WM_BUF_SIZE      2560                // Size of the WM variable area on ARM9
#endif

#define WM_ARM7WM_BUF_SIZE      256                 // Size of the WM variable area on ARM7
#define WM_STATUS_BUF_SIZE      2560                // Size of the WM status area
//#define WM_INDBUF_SIZE          256                 // Size of the Indication buffer
#define WM_INDBUF_SIZE          0       // -> To size 0 (to be deleted) 2004/09/08 terui
#define WM_FIFO_BUF_SIZE        256                 // Size of the FIFO command buffer between ARM9 and ARM7

// Size of the buffer allocated by the user-------------
//   Size of all buffers used by the WM system 2560 + 256 + 2560 + 256 + 256 + 256 = 0x1400 (note that this is FIFO_BIF * 2)
#define WM_SYSTEM_BUF_SIZE      (WM_ARM9WM_BUF_SIZE + WM_ARM7WM_BUF_SIZE + WM_STATUS_BUF_SIZE + WM_INDBUF_SIZE + WM_FIFO_BUF_SIZE + WM_FIFO_BUF_SIZE)
#define WM_BSS_DESC_SIZE        192                 // Size of the buffer for storing parent information passed by WM_StartScan()

#define WM_DCF_MAX_SIZE         1508                // Maximum size that can be received with DCF
#define WM_KEYSET_SIZE          36                  // Size of KeySet
#define WM_KEYDATA_SIZE         2                   // Size of KeyData

#define WM_DS_HEADER_SIZE       4

#ifdef WM_DS_DATA_SIZE_252      // When it is OK to set 252 for WM_DS_DATA_SIZE
#define WM_DS_DATA_SIZE         252
#else                           // When WM_DS_DATA_SIZE is 508 (default)
#define WM_DS_DATA_SIZE         508                 // Maximum data size of one WMDataSet (512-4)
                                                    // WM_DS_DATA_SIZE+WM_DS_HEADER_SIZE needs to be the multiples of 32
#endif

#define WM_DS_DATASET_NUM       4                   // How many WMDataSet to be kept in WMDataSetBuf (fixed value)
#define WM_DS_INFO_SIZE         (sizeof(WMDataSharingInfo))   // Buffer size for DataSharing

#define WM_SCAN_EX_PARENT_MAX   16                  // Maximum number of parent that can be found with one ScanEx

/*---------------------------------------------------------------------------*
    Structure definition
 *---------------------------------------------------------------------------*/

// Buffer structure =======================================================================

// Key set structure
typedef struct WMKeySet
{
    u16 seqNum;             // Key set's sequential number
    u16 rsv;
    u16 key[16];            // Key data

} WMKeySet , WMkeySet;

// Ring buffer for holding key set
typedef struct WMKeySetBuf
{
    u16         next_ks;        // ks number that should be read next
    u16         left_num;       // Number of remaining ks that have not been acquired
    WMKeySet    ks[4];

} WMKeySetBuf , WMkeySetBuf;

// Data set structure
typedef struct WMDataSet
{
//    u16 seqNum;                 // Data set's sequential number
    u16 aidBitmap;
    u16 receivedBitmap;              // Bit map of receive status
    u16 data[WM_DS_DATA_SIZE/sizeof(u16)];  // Shared data

} WMDataSet;

// DataSharing information structure
typedef struct WMDataSharingInfo
{
    WMDataSet   ds[WM_DS_DATASET_NUM];
    u16 seqNum[WM_DS_DATASET_NUM]; // Sequential Number
    u16 writeIndex; // Next Index to write
    u16 sendIndex;  // Index currently being sent
    u16 readIndex;  // Next Index to read
    u16 aidBitmap;  // bitmap of data sharing group (including self)
    u16 dataLength; // Amount of data shared around one machine
    u16 stationNumber; // Number of machines sharing data (number of bits set in aidBitmap)
    u16 dataSetLength; // dataLength * stationNumber
    u16 port;       // Port being used (port number = at least 8)
    u16 doubleMode; // In mode for alternately sending/receiving each frame?
    u16 currentSeqNum; // The last DataSet SeqNum that was read
    u16 state;      // Current DataSharing state (WMDataSharingState)
    u16 reserved[1]; // for 32Byte Alignment
} WMDataSharingInfo;

//---------------------------------------
// Parent/Child shared MP port send queue structure
typedef struct
{
    u16     next;
    u16     port;
    u16     destBitmap;
    u16     size;
    u16     seqNo;
    u16     retryCount;
    const u16*  data;
    WMCallbackFunc callback;
    void*   arg;
} WMPortSendQueueData;

typedef struct
{
    u16     head;
    u16     tail;
} WMPortSendQueue;

//---------------------------------------
// Child MP receive buffer structure
typedef struct WMMpRecvBuf
{
    u16         rsv1[3];
    u16         length;

    u16         rsv2[1];
    u16         ackTimeStamp;
    u16         timeStamp;
    u16         rate_rssi;
    u16         rsv3[2];

    u16         rsv4[2];
    u8          destAdrs[6];
    u8          srcAdrs[6];
    u16         rsv5[3];
    u16         seqCtrl;

    u16         txop;
    u16         bitmap;
    u16         wmHeader;
    u16         data[2];

} WMMpRecvBuf , WMmpRecvBuf;

//---------------------------------------
// Parent MP receive buffer structure
typedef struct WMMpRecvData
{
    u16         length;
    u16         rate_rssi;
    u16         aid;
    u16         noResponse;
    u16         wmHeader;
    u16         cdata[1];

} WMMpRecvData , WMmpRecvData;

typedef struct WMMpRecvHeader
{
    u16             bitmap;
#if SDK_VERSION_WL >= 20500
    u16             errBitmap;
#endif
    u16             count;
    u16             length;
    u16             txCount;
    WMMpRecvData    data[1];

} WMMpRecvHeader , WMmpRecvHeader;

//---------------------------------------
// Child DCF receive buffer structure
typedef struct WMDcfRecvBuf
{
    u16         frameID;
    u16         rsv1[2];
    u16         length;

    u16         rsv2[3];
    u16         rate_rssi;
    u16         rsv3[4];
    u8          destAdrs[6];
    u8          srcAdrs[6];
    u16         rsv4[4];

    u16         data[2];

} WMDcfRecvBuf , WMdcfRecvBuf;

//---------------------------------------
// WM parent parameter structure
typedef struct WMParentParam
{
    u16 *userGameInfo;                          // Pointer to data to set in user area
    u16 userGameInfoLength;                     // Length of user area
    u16 padding;

    u32 ggid;
    u16 tgid;                                   // Temporary GameID(generated each time a user becomes a parent)
    u16 entryFlag;                              // 1: Connect possible, 0: Connect not possible
    u16 maxEntry;                               // Number of children that can connect
    u16 multiBootFlag;                          // 1: Multiboot possible, 0: Multiboot not possible
    u16 KS_Flag;                                // 1: KeySharing, 0: Not KeySharing
    u16 CS_Flag;                                // 1: Continuous send, 0: Send one frame at a time
    u16 beaconPeriod;                           // Beacon interval (ms)
#ifdef WM_GAMEINFO_TYPE_OLD
    u16 userName[WM_SIZE_USERNAME/sizeof(u16)]; // User name character string
    u16 gameName[WM_SIZE_GAMENAME/sizeof(u16)]; // Game name character string
#else
    u16 rsv1[WM_SIZE_USERNAME/sizeof(u16)];    //
    u16 rsv2[WM_SIZE_GAMENAME/sizeof(u16)];    //
#endif
    u16 channel;                                // Channel
    u16 parentMaxSize;                          // Parent maximum send size
    u16 childMaxSize;                           // Child maximum send size

    u16 rsv[4];                                 // For 32-byte alignment

} WMParentParam , WMpparam;

//---------------------------------------
// WM GameInfo Structure

#ifdef WM_GAMEINFO_TYPE_OLD

typedef struct WMGameInfo
{
    u16 ggid[WM_SIZE_GGID/sizeof(u16)];
    u16 tgid;
    u16 userName[WM_SIZE_USERNAME/sizeof(u16)];
    u16 gameNameCount_attribute;                    // CS_Flag, KS_Flag, multibootFlag, entryFlag
    u16 gameName[WM_SIZE_GAMENAME/sizeof(u16)];
    u16 parentMaxSize;                              // Parent maximum send size
    u16 childMaxSize;                               // Child maximum send size
    u16 userGameInfoLength;                         // Length of user area
    u16 reserved1;
    u16 userGameInfo[WM_SIZE_USER_GAMEINFO/sizeof(u16)];    // User area (maximum 64 bytes (provisional))
    u16 reserved2[12];                               // Reserved(gameInfo is total MAX128Byte)

} WMGameInfo , WMgameInfo;

#else

typedef struct WMGameInfo
{
  u16 version;
  u16 padd0;
//  u16 ggid[WM_SIZE_GGID/sizeof(u16)];
  u32 ggid;
  u16 tgid;
  u8 userGameInfoLength;                         // Length of user area
  u8 gameNameCount_attribute;                    // CS_Flag, KS_Flag, multibootFlag, entryFlag
  //  u16 attribute; //CS_Flag,KS_Flag,multibootFlag,entryFlag
  u16 parentMaxSize;           //Parent maximum send size
  u16 childMaxSize;            //Child maximum send size
  union {
    u16 userGameInfo[WM_SIZE_USER_GAMEINFO/sizeof(u16)];    // User region (Maximum: 112 bytes (provisional))
    struct {
      u16 userName[WM_SIZE_USERNAME/sizeof(u16)];      // WM_SIZE_USERNAME -> 8
      u16 gameName[WM_SIZE_GAMENAME/sizeof(u16)];      // WM_SIZE_GAMENAME -> 16
      u16 padd1[44];                                    // pad -> 88
    } old_type;                                       // Total: 112 bytes
  };
} WMGameInfo , WMgameInfo;

#endif /* WM_GAMEINFO_TYPE_OLD */

//---------------------------------------
// BSSDescription. Parent information structure (Acquired with Scan. Used for Connect specification)
#if SDK_VERSION_WL < 17100
typedef struct WMBssDesc
{
    u16         length;                             // 2
    u16         rssi;                               // 4
    u8          bssid[ WM_SIZE_BSSID ];             // 10
    u16         ssidLength;                         // 12
    u8          ssid[WM_SIZE_SSID];                 // 44
    u16         capaInfo;                           // 46
    struct
    {
        u16     basic;                              // 48
        u16     support;                            // 50
    } rateSet;
    u16         beaconPeriod;                       // 52
    u16         dtimPeriod;                         // 54
    u16         channel;                            // 56
    u16         cfpPeriod;                          // 58
    u16         cfpMaxDuration;                     // 60
    u16         gameInfoLength;                     // 62
    WMGameInfo  gameInfo;                           // 190
    u16         rsv;                                // 192

} WMBssDesc , WMbssDesc;
#else
typedef struct WMBssDesc
{
    u16         length;                             // 2
    u16         rssi;                               // 4
    u8          bssid[ WM_SIZE_BSSID ];             // 10
    u16         ssidLength;                         // 12
    u8          ssid[WM_SIZE_SSID];                 // 44
    u16         capaInfo;                           // 46
    struct
    {
        u16     basic;                              // 48
        u16     support;                            // 50
    } rateSet;
    u16         beaconPeriod;                       // 52
    u16         dtimPeriod;                         // 54
    u16         channel;                            // 56
    u16         cfpPeriod;                          // 58
    u16         cfpMaxDuration;                     // 60
    u16         gameInfoLength;                     // 62
    u16         rsv;                                // 64
    WMGameInfo  gameInfo;                           // 192

} WMBssDesc , WMbssDesc;
#endif

//---------------------------------------
// WM Scan parameter Structure
typedef struct WMScanParam
{
    WMBssDesc   *scanBuf;               // Buffer that holds parent information
    u16         channel;                // Scan channel
    u16         maxChannelTime;         // Maximum Scan time
    u8          bssid[ WM_SIZE_BSSID ]; // MacAddress of Scan target parent (all parents become target if 0xff)
    u16         rsv[9];

} WMScanParam , WMscanParam;

//---------------------------------------
// WM status buffer structure (ARM7 will rewrite. ARM9 can only read.)
//   Currently 2096 Bytes
typedef struct WMStatus
{
    // Status information (4Byte)
    u16             state;                  // WM status information
    u16             BusyApiid;              // Busy APIID

    // Flag (36Byte) 40
    BOOL            apiBusy;                // API busy flag (according to FIFO, API issue prohibit flag)
    BOOL            scan_continue;          // Scan continue flag (As of 07/19/2004 not used)
    BOOL            resume_flag;            // Resume execution flag
    BOOL            mp_flag;                // MP running flag
    BOOL            dcf_flag;               // DCF running flag
    BOOL            ks_flag;                // KeySharing running flag
//    BOOL            mp_sendFlag;            // Waiting for MP send flag
    u8              reserved_a[4];          // for padding 4byte align
    BOOL            dcf_sendFlag;           // Waiting for DCF send flag
    BOOL            VSyncFlag;              // VBlank sync OK flag

    // Version information (16Byte) 56
    u8              wlVersion[WM_SIZE_WL_VERSION];                  // WL version
    u16             macVersion;                                     // MAC version
    u16             rfVersion;                                      // RF version
    u16             bbpVersion[WM_SIZE_BBP_VERSION/sizeof(u16)];    // BBP version

    // MP related (26+48+4Byte) 154
//    u16             *mp_sendData;           // MP send data pointer
//    u16             mp_sendSize;            // MP send data size
//    u16             mp_pollbmp;             // MP user specification PollBitmap
//    u16             mp_tmptt;               // MP send time TMPTT specification (if 0)
    u16             mp_vsyncOrderedFlag;    // Whether the next MP will be performed synchronized with vsync
    u16             mp_vsyncFlag;           // How may MP per picture frame?
    u16             mp_freq;                // How may MP per picture frame?
    u16             mp_count;               // How many more MP for the current picture frame?
//    u16             mp_contSend;            // MP continuous send flag
//    u8              reserved_b[2];          // for padding 4byte align
    u16             mp_prevPollBitmap;      // PollBitmap in MP immediately before
    u16             mp_prevWmHeader;        // wmHeader in MP immediately before
    u16             mp_recvBufSel;          // MP receive buffer selection flag
//    u16             mp_recvBufClear;        // Flag that shows that MP receive buffer is cleared.
    u16             mp_recvBufSize;         // Size of the MP receive buffer
    WMMpRecvBuf     *mp_recvBuf[2];         // Pointer to the MP receive buffer
    u32             *mp_sendBuf;            // Pointer to the MP send buffer
    u16             mp_sendBufSize;         // Size of the MP send buffer
//    u8              reserved_c[2];          // for padding 4byte align
//    u16             mp_port;

    u16             mp_ackTime;             // MPACK estimated time of arrival
    OSAlarm         mp_ackAlarm;            // Alarm for detecting MPACK timeout (44 bytes)
    u16             mp_waitAckFlag;         // Waiting for MPACK
//    u8              reserved0[2];           // for padding 4byte align

    u16             mp_readyBitmap;         // child bitmap with MP preparations complete (for parent)

//    u8              reserved_e[2];

    u16             mp_newFrameFlag;        // flag that becomes TRUE when a new picture frame comes
    u16             mp_setDataFlag;         // flag with reply data set complete (for child)
    u16             mp_sentDataFlag;        // flag with reply data sent (for child)
    u16             mp_bufferEmptyFlag;     // buffer empty flag for reply data (for child)
    u16             mp_isPolledFlag;        // Was previous MP polled by itself? (for child)

    u16             mp_minPollBmpMode;      // mode that minimizes to fit the send target of the packet that sends PollBitmap
    u16             mp_singlePacketMode;    // mode that only sends 1 packet in 1 MP
    u16             mp_fixFreqMode;         // mode that prohibits increase of MP communication by retry
    u16             mp_defaultRetryCount;   // default number of retries for communication on a port that does not do Seq control

    u16             mp_pingFlag;            // flag that is enabled at the timing that ping is hit
    u16             mp_pingCounter;         // counter of number of frames remaining until ping

    // DCF related (26Byte) 184
    u8              dcf_destAdr[ WM_SIZE_MACADDR ]; // DCF send destination MAC address
    u16             *dcf_sendData;          // DCF send data pointer
    u16             dcf_sendSize;           // DCF send data size
    u16             dcf_recvBufSel;         // DCF receive buffer select flag
    WMDcfRecvBuf    *dcf_recvBuf[2];        // DCF receive buffer pointer
    u16             dcf_recvBufSize;        // DCF receive buffer size

//  u8              reserved1[2];           // for padding 4byte align
    u16             curr_tgid;              // TGID of the parent that is currently connected (used with BeaconRecv.Ind)

    // KeySharing related (36 + 4 + 2 + 2Byte)
//    WMKeySet        keySet_forSend;         // Key set that is waiting for send
//    WMKeySetBuf     *ksBuf;                 // Buffer for holding KeySet
//    u16             parentKeyData;          // Parent key data buffer

    // RSSI related (4Byte) 206
    u16             linkLevel;
    u16             minRssi;
    u16             rssiCounter;

    u8              reserved_d[10];
    u16             VSyncBitmap;            // Bitmap of children that have acquired V-Blank sync
    u16             valarm_queuedFlag;      // V-Alarm processes have accumulated in the run queue.

    // V-Blank sync related (14Byte) 218
    u32             v_tsf;                  // For V-Blank sync. V_TSF value
    u32             v_tsf_bak;              // For V-Blank sync. Last acquired V_TSF value
    u32             v_remain;               // For V-Blank sync. Remaining adjustment
    u16             valarm_counter;         // For V-Alarm interrupt generation counter

    // Read wait flag (2Byte) 220
//    u16             indbuf_read_wait;       // Flag for waiting for reading indication buffer

//    u8              reserve_f[2];
    u16             mp_ignoreFatalError;    // Whether to ignore FatalError


    // Status of the self (8Byte) 228
    u8              MacAddress[ WM_SIZE_MACADDR ];
    u16             mode;                   // Parent: WL_CMDLABEL_MODE_PARENT, Child: WL_CMDLABEL_MODE_CHILD

    // Information to be used when it is parent (64 + 90 + 2 = 156Byte) 384
    WMParentParam   pparam;                 // Parent parameter
    u8              childMacAddress[ WM_NUM_MAX_CHILD ][ WM_SIZE_MACADDR ];
    u16             child_bitmap;           // Connection status of child (used as poll bitmap)

    // Information to be used when it is a child (14Byte) 398
    WMBssDesc       *pInfoBuf;              // Pointer to the buffer that is used for storing information regarding the parent that was scanned. (given as an argument ARM9API)
    u16             aid;                    // Current AID
//    u16             parentMacAddress[WM_SIZE_MACADDR/sizeof(u16)];  // MAcAddress of the parent that is being connected (processed)
    u8              parentMacAddress[ WM_SIZE_MACADDR ];
    u16             scan_channel;           // Channel that is currently scanned

    // information used by both parent and child (4Byte) 402
    u16             maxSendSize;            // sendable size with current connection
    u16             maxReceiveSize;         // maximum receive size with current connection

    // WEP related (86Byte) 488
    u16             wepMode;                // WEP mode (how many bits is WEP?)
//    u8              reserved2[2];           // for padding 4byte align
    BOOL            wep_flag;               // Indicates whether other party is requesting WEP
    u16             wepKey[WM_SIZE_WEPKEY/sizeof(u16)]; // WEP key (20Byte * 4)

    // Other (4Byte) 492
    u16             rate;                   // Utilization rate(WL_CMDLABEL_RATE_AUTO, 1M, 2M)
    u16             preamble;               // Long:0, Short:1

    // Various parameters (Planning that user will not be allowed to touch this) (4Byte) 496
    u16             tmptt;
    u16             retryLimit;

    // Enabled channels (2Byte) 498
    u16             enableChannel;

    // usable channels (2Byte) 500
    u16             allowedChannel;

    // port related ( 1316+256+20+4Byte ) 1816+256+20+4
    u16             portSeqNo[ WM_NUM_MAX_CHILD+1 ][ WM_NUM_OF_SEQ_PORT ];  // 16*8*2=256Byte

    WMPortSendQueueData sendQueueData[ WM_SEND_QUEUE_NUM ];          // 24*64=1536Byte
    WMPortSendQueue sendQueueFreeList;                                  // 4Byte
    WMPortSendQueue sendQueue[ WM_PRIORITY_LEVEL ];                     // 16Byte
    WMPortSendQueue readyQueue[ WM_PRIORITY_LEVEL ];                    // 16Byte
    OSMutex         sendQueueMutex; // 20 byte
    BOOL            sendQueueInUse;            // MP send wait flag

    // Null Ack timeout ( 128 + 8 Byte )
    OSTick          mp_lastRecvTick[ 1 + WM_NUM_MAX_CHILD ];
    OSTick          mp_lifeTimeTick;
} WMStatus , WMstatus;

//---------------------------------------
// Buffer structure for WM ARM7 side variable area
typedef struct WMArm7Buf
{
    WMStatus    *status;        // WM status buffer
//    u32         *indbuf;        // Indication buffer pointer
    u8          reserved_a[4];
    u32         *fifo7to9;      // Buffer pointer for FIFO(ARM7->9)
//    BOOL        *fifoFlag;      // ARM7->ARM9 FIFO send permission flag
    u8          reserved_b[4];

    WMBssDesc   connectPInfo;   // Connection target parent information (190byte)
    OSVAlarm    VAlarm;         // V-Alarm Structure

} WMArm7Buf , WMarm7Buf;

//---------------------------------------
// Number of CallbackTable elements
#define WM_NUM_OF_CALLBACK      ( WM_APIID_ASYNC_KIND_MAX - 2 )
// padding size for 32-byte aligning keySharingInfo member
#define WM_ARM9BUF_32_ALIGN_PADDING_SIZE    ( ( 8 - ( ( WM_NUM_OF_CALLBACK + 7 ) % 8 ) ) * 4 )
// Buffer structure for WM ARM9 side variable area
typedef struct WMArm9Buf
{
    // Pointer types (20Byte)
    WMArm7Buf       *WM7;           // ARM7 side WM variable area ( no access from ARM9)
    WMStatus        *status;        // WM status buffer (read only from ARM9)
    u32             *indbuf;        // Indication buffer
    u32             *fifo9to7;      // Buffer for FIFO(ARM9->7)
    u32             *fifo7to9;      // Buffer for FIFO(ARM7->9)

    // Callback related (276Byte)
    WMCallbackFunc  CallbackTable[ WM_NUM_OF_CALLBACK ];    // Callback table (36*4 = 144Byte)
    WMCallbackFunc  indCallback;

    WMCallbackFunc  portCallbackTable[ WM_NUM_OF_PORT ];                // 16*4 = 64Byte
    void*           portCallbackArgument[ WM_NUM_OF_PORT ];             // 16*4 = 64Byte

    // KeySharing
    u8              reserved1[WM_ARM9BUF_32_ALIGN_PADDING_SIZE];    // for padding 32byte align
    BOOL            ksFlag;
    /* 32-byte alignment is necessary here */
    WMDataSharingInfo keySharingInfo; // 1024+32Byte

    // other (8Byte)
//    BOOL            fifoFlag;       // ARM7->ARM9 FIFO send permission flag
    u16             dmaNo;          // DMA number that WM uses
    u8              reserved2[2];   // for padding 4byte align
  /* 288+1024+32+4+20 Byte */
} WMArm9Buf , WMarm9Buf;

//==========================================================================================

// API arguments
typedef struct WMStartScanReq
{
    u16         apiid;
    u16         channel;
    WMBssDesc   *scanBuf;
    u16         maxChannelTime;
    u8          bssid[ WM_SIZE_BSSID ];

} WMStartScanReq , WMstartScanReq;

typedef struct WMStartConnectReq
{
    u16         apiid;
    u16         reserved;
    WMBssDesc   *pInfo;
    u8          ssid[WM_SIZE_CHILD_SSID];

} WMStartConnectReq , WMstartConnectReq;

typedef struct WMMeasureChannelReq
{
    u16 apiid;
    u16 ccaMode;
    u16 edThreshold;
    u16 channel;
    u16 measureTime;

} WMMeasureChannelReq , WMmeasureChannelReq;

typedef struct WMStartTestModeReq
{
    u16 apiid;
    u16 control;
    u16 signal;
    u16 rate;
    u16 channel;
} WMStartTestModeReq , WMstartTestModeReq;

//==========================================================================================

// Normal callback arguments
typedef struct WMCallback
{
    u16 apiid;
    u16 errcode;
    u16 wlCmdID;
    u16 wlResult;

} WMCallback;

// WM_StartParent() callback arguments
typedef struct WMStartParentCallback
{
    u16 apiid;
    u16 errcode;
    u16 wlCmdID;
    u16 wlResult;
    u16 state;          // CHILD_CONNECTED, DISCONNECTED, PARENT_START
    u8  macAddress[ WM_SIZE_MACADDR ];  // MAC address of each child that was connected
    u16 aid;
    u16 reason;         // Disconnect reasonCode
    u8  ssid[WM_SIZE_CHILD_SSID];   // SSID (child information)

} WMStartParentCallback , WMstartParentCallback;

// WM_StartScan() callback arguments
typedef struct WMStartScanCallback
{
    u16  apiid;
    u16  errcode;
    u16  wlCmdID;
    u16  wlResult;
    u16  state;         // FIND_PARENT, PARENT_NOT_FOUND, SCAN_START
    u8   macAddress[ WM_SIZE_MACADDR ]; // MAC address of the parent that was found
    u16  channel;
    u16  linkLevel;
    u16  ssidLength;
    u16  ssid[WM_SIZE_SSID/sizeof(u16)];
    u16  gameInfoLength;
    WMGameInfo gameInfo;

} WMStartScanCallback , WMstartScanCallback;

// Argument of WM_StartScanEx() callback
typedef struct WMStartScanExCallback
{
    u16         apiid;
    u16         errcode;
    u16         wlCmdID;
    u16         wlResult;
    u16         state;          // SCAN_START, PARENT_NOT_FOUND, PARENT_FOUND
    u16         channel;        // Scanned channels, regardless of whether found or not.
    u8          reserved[2];    // padding
    u16         bssDescCount;                       // Number of parents that were found
    WMBssDesc   *bssDesc[WM_SCAN_EX_PARENT_MAX];    // Beginning address of the parent information
    u16         linkLevel[WM_SCAN_EX_PARENT_MAX];   // Reception signal strength

} WMStartScanExCallback , WMstartScanExCallback;

// Argument of WM_StartConnect() callback
typedef struct WMStartConnectCallback
{
    u16 apiid;
    u16 errcode;    // PARENT_NOT_FOUND(timeout)
    u16 wlCmdID;
    u16 wlResult;
    u16 state;      // SCAN_START, CONNECTED,
    u16 aid;        // Only when CONNECTED. AID assigned to self
    u16 reason;     // Disconnect-time reasonCode

} WMStartConnectCallback , WMstartConnectCallback;

// Callback of WM_Disconnect() and WM_DisconnectChildren
typedef struct WMDisconnectCallback
{
    u16 apiid;
    u16 errcode;
    u16 wlCmdID;
    u16 wlResult;
    u16 tryBitmap;
    u16 disconnectedBitmap;
} WMDisconnectCallback;

// Argument of WM_StartMP() callback
typedef struct WMStartMPCallback
{
    u16         apiid;
    u16         errcode;
    u16         state;
    u8          reserved[2];    // for padding 4byte align
    WMMpRecvBuf *recvBuf;       // Receive buffer

    // The following only used for MPACK.Ind
    u16 timeStamp;
    u16 rate_rssi;
    u8  destAdrs[6];
    u8  srcAdrs[6];
    u16 seqNum;
    u16 tmptt;
    u16 pollbmp;
    u16 reserved2;
} WMStartMPCallback , WMstartMPCallback;

// WM_StartDCF() callback arguments
typedef struct WMStartDCFCallback
{
    u16             apiid;
    u16             errcode;
    u16             state;
    u8              reserved[2];    // for padding 4byte align
    WMDcfRecvBuf    *recvBuf;       // Receive buffer

} WMStartDCFCallback , WMstartDCFCallback;

// WM_MeasureChannel() callback arguments
typedef struct WMMeasureChannelCallback
{
    u16 apiid;
    u16 errcode;
    u16 wlCmdID;
    u16 wlResult;
    u16 channel;
    u16 ccaBusyRatio;
} WMMeasureChannelCallback , WMmeasureChannelCallback;

// WM_GetWirelessCounter() callback arguments
typedef struct WMGetWirelessCounterCallback
{
    u16 apiid;
    u16 errcode;
    u16 wlCmdID;
    u16 wlResult;
    u32 TX_Success;             // Number of successful sends
    u32 TX_Failed;              // Number of failed sends
    u32 TX_Retry;               // Number of retries
    u32 TX_AckError;            // Number of times desired ACK frame could not be received
    u32 TX_Unicast;             // Number of successfully sent Unicast addressed frames
    u32 TX_Multicast;           // Number of successfully sent Multicast addressed frames
    u32 TX_WEP;                 // Number of successfully sent encrypted frames
    u32 TX_Beacon;              // Number of successfully sent Beacon frames
    u32 RX_RTS;                 // Number of RTS receipt / CTS responses
    u32 RX_Fragment;            // Number of times fragmented frames received
    u32 RX_Unicast;             // Number of times Unicast addressed frames received
    u32 RX_Multicast;           // Number of times Multicast addressed frames received
    u32 RX_WEP;                 //Number of times received encrypted frames that were successfully decrypted
    u32 RX_Beacon;              // Number of times a Beacon frame was received
    u32 RX_FCSError;            // Number of times an FCS error occurred
    u32 RX_DuplicateError;      // Number of times a duplicate error occurred
    u32 RX_MPDuplicateError;    // Number of times an MP frame duplicate error occurred
    u32 RX_ICVError;            // Number of times an ICV error occurred
    u32 RX_FrameCtrlError;      // Number of times received frames that have illegal FrameCtrl
    u32 RX_LengthError;         // Number of times received frames that are longer or shorter that the prescribed length
    u32 RX_PLCPError;           // Number of times that PLCP CRC error occurred
    u32 RX_BufferOverflowError; // Number of times the receive buffer overflowed
    u32 RX_PathError;           // Number of times receive block internal errors occurred
    u32 RX_RateError;           // Number of times received frames that have an illegal receive rate
    u32 RX_FCSOK;               // Number of times received frames that have proper FCS
    u32 TX_MP;                  // Number of times MP frame sent
    u32 TX_KeyData;             // Number of times MP-KeyData frames sent
    u32 TX_NullKey;             // Number of times MP-NullKey frames sent
    u32 RX_MP;                  // Number of times proper MP frames received
    u32 RX_MPACK;               // Number of times proper MPACK frames received
    u32 MPKeyResponseError[15]; // Number of times proper response not made to Key request
} WMGetWirelessCounterCallback , WMgetWirelessCounterCallback;

// Indication callback arguments
typedef struct WMIndCallback
{
    u16     apiid;
    u16     errcode;
    u16     state;
    u16     reason;

} WMIndCallback , WMindCallback;

// MP port communication send callback arguments
typedef struct WMPortSendCallback
{
    u16     apiid;
    u16     errcode;
    u16     wlCmdID;
    u16     wlResult;
    u16     state;
    u16     port;
    u16     restBitmap;
    u16     size;
    const u16*  data;
    WMCallbackFunc callback;
    void*   arg;
    u16     seqNo;  // seqNo
    u16     rsv;

} WMPortSendCallback;

// MP port communication receive callback arguments
typedef struct WMPortRecvCallback
{
    u16     apiid;
    u16     errcode;
    u16     state;
    u16     port;   // Port number
    WMMpRecvBuf *recvBuf;       // receive buffer. // For compatibility with WMStartMPCallback
    u16*    data;   // Receive data (in the case of receive data addressed to port, reference this)
    u16     length; // Receive data length
    u16     aid;    // Send source AID
    u8      macAddress[ WM_SIZE_MACADDR ];
    u16     seqNo;  // seqNo
    void*   arg;    // Argument passed to callback (append on WM9 side)
    u16     myAid;  // my AID
    u16     rsv;
    u8      ssid[WM_SIZE_CHILD_SSID]; // SSID (child information)

} WMPortRecvCallback;

// BeaconRecv.Ind callback arguments
typedef struct WMBeaconRecvIndCallback
{
    u16         apiid;
    u16         errcode;
    u16         state;
    u16         tgid;
    u16         wmstate;
    u16         gameInfoLength;
    WMGameInfo  gameInfo;
}WMBeaconRecvIndCallback;


/*===========================================================================*/

#ifdef  __cplusplus
}       /* extern "C" */
#endif

#endif  /* NITRO_WM_COMMON_WM_H_ */

/*---------------------------------------------------------------------------*
  End of file
 *---------------------------------------------------------------------------*/
