/*---------------------------------------------------------------------------* Project: NWCM Library File: nwcm.h Copyright (C)2008 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. @version $Id: nwcm.h 16441 2010-05-20 00:57:11Z takiguchi_shinichi $ *--------------------------------------------------------------------------- */ #ifndef NWCM_H #define NWCM_H #include #ifdef __cplusplus extern "C" { #endif /*---------------------------------------------------------------------------* * WCM Temporary Definitions *---------------------------------------------------------------------------*/ // Types of Control Constants // Size of each type of data (bytes) #define WM_SIZE_BSSID 6 #define WM_SIZE_SSID 32 #define WCM_CAM_LIFETIME 80 // CAM lifetime (8s) #define WCM_BSSID_SIZE WM_SIZE_BSSID // BSS-ID size (6 bytes) #define WCM_ESSID_SIZE WM_SIZE_SSID // ESS-ID maximum size (32 bytes) #define WCM_OPTION_TEST_AUTH 0x00080000 #define WCM_OPTION_FILTER_AUTH 0x00040000 // WEP encryption mode type #define WCM_WEPMODE_NONE 0 // No encryption #define WCM_WEPMODE_40 1 // RC4 (40-bit) encryption mode #define WCM_WEPMODE_104 2 // RC4 (104-bit) encryption mode #define WCM_WEPMODE_128 3 // RC4 (128-bit) encryption mode // AP authentication modes #define WCM_OPTION_TEST_AUTH 0x00080000 #define WCM_OPTION_FILTER_AUTH 0x00040000 #define WCM_OPTION_MASK_AUTH (WCM_OPTION_TEST_AUTH | WCM_OPTION_FILTER_AUTH) #define WCM_OPTION_AUTH_OPENSYSTEM (WCM_OPTION_TEST_AUTH | 0x00000000) #define WCM_OPTION_AUTH_SHAREDKEY (WCM_OPTION_TEST_AUTH | 0x00040000) #define WM_SIZE_WEPKEY 80 #define WCM_WEP_SIZE WM_SIZE_WEPKEY // 80 bytes /*---------------------------------------------------------------------------* * Definitions *---------------------------------------------------------------------------*/ #define NWCM_DEVICE_1 0 /* Only 1 interface can be used with this driver */ #define NWCM_VENDOR_NINTENDO 0x0000 #define NWCM_COMMON_CONF_VERSION 0x1100 #define NWCM_INS_CONF_VERSION 0x2100 #define NWCM_MEM_BASE 0x00050000 #define NWCM_MEM_NAME(name) ((s32)(NWCM_MEM_BASE|(name))) enum { NWCM_MEM_INSTANCE = NWCM_MEM_NAME(1) }; #define WM_SIZE_USER_GAMEINFO 112 // Maximum user area size for GameInfo #define WM_SIZE_USERNAME 8 #define WM_SIZE_GAMENAME 16 typedef struct WMGameInfo { u16 magicNumber; // == 0x0001 u8 ver; // GameInfo Version 1 u8 platform; // DS: 0, Wii: 8 u32 ggid; u16 tgid; u8 userGameInfoLength; // Length of user area union { // (CS_Flag):1, (KS_Flag):1, multibootFlag:1, entryFlag:1 u8 gameNameCount_attribute; // Old name for compatibility purposes u8 attribute; }; u16 parentMaxSize; //Maximum parent send size u16 childMaxSize; //Maximum child 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; typedef struct WCMBssDesc { 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 union { u16 otherElementCount; u16 elementCount; }; // 64 union { WMGameInfo gameInfo; u16 elements[1]; }; } WCMBssDesc; /* Please see man pages for details */ enum { NWCM_STATE_INIT = 0, /*Initial state*/ NWCM_STATE_WAIT_LINKUP, /* Wait for association to AP*/ NWCM_STATE_ACTIVE, /*Connection completed state*/ NWCM_STATE_ABORT, /*Cancel association*/ NWCM_STATE_MORIBUND /*Disconnecting*/ }; /*---------------------------------------------------------------------------* * Types/Declarations *---------------------------------------------------------------------------*/ #define NWCM_MAC_LEN 6 /* Please see man pages for details */ typedef struct NWCMProtocolList { u16 protocol; /*IP, ARP, etc.*/ NNETInstance *upper_ins; /*Upper instance*/ NOSMessageQueueId mq_receive; /*Queue to insert packet when above protocol is received*/ } NWCMProtocolList; /* Please see man pages for details */ typedef struct NWCMCommonConfig { u16 vendor; /* NWCM_VENDOR_NINTENDO */ u16 version; /* NWCM_COMMON_CONF_VERSION */ /* No arguments */ } NWCMCommonConfig; /* Please see man pages for details */ #define NWCM_PROTOCOL_NUM 8 /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */ #define NWCM_UPPER_NUM 2 /*Number of upper layers*/ #define NWCM_MQ_NUM 16 /*Size of queue to pass to upper layers*/ #define NWCM_MAX_SEND_LEN 1600 typedef struct NWCMMessage { NOSMessageQueue mq; /*Receive queue for upper layers*/ NOSMessage mqarray[NWCM_MQ_NUM]; /*Receive queue instance for upper layers*/ } NWCMMessage; #define NWCM_VENDOR_NINTENDO 0x0000 #define NWCM_COMMON_CONF_VERSION 0x1100 #define NWCM_INS_CONF_VERSION 0x2100 /* Please see man pages for details */ #define NWCM_BSSID_SIZE WCM_BSSID_SIZE /* BSSID size */ #define NWCM_ESSID_SIZE WCM_ESSID_SIZE /* ESSID size */ /* AP authentication modes */ #define NWCM_OPTION_TEST_AUTH WCM_OPTION_TEST_AUTH #define NWCM_OPTION_FILTER_AUTH WCM_OPTION_FILTER_AUTH #define NWCM_OPTION_MASK_AUTH WCM_OPTION_MASK_AUTH #define NWCM_OPTION_AUTH_OPENSYSTEM WCM_OPTION_AUTH_OPENSYSTEM /* WEP encryption mode type */ #define NWCM_WEPMODE_NONE WCM_WEPMODE_NONE /* No encryption */ #define NWCM_WEPMODE_40 WCM_WEPMODE_40 /* RC4 (40-bit) encryption mode */ #define NWCM_WEPMODE_104 WCM_WEPMODE_104 /* RC4 (104-bit) encryption mode */ #define NWCM_WEPMODE_128 WCM_WEPMODE_128 /* RC4 (128-bit) encryption mode */ #define NWCM_SIZE_WEPKEY WCM_WEP_SIZE /* WEP key length */ typedef struct NWCMWepDesc { u8 mode; /* WEP encryption mode ( WCM_WEPMODE_* ) */ u8 keyId; /*/ WEP key ID (0 to 3) */ u8 key[NWCM_SIZE_WEPKEY]; /* WEP key data string [20 * 4 bytes] */ } NWCMWepDesc; typedef NWCMWepDesc WCMWepDesc; typedef struct NWCMInstanceConfig { u16 vendor; /* NWCM_VENDOR_NINTENDO */ u16 version; /* NWCM_INS_CONF_VERSION */ u8 bssId[NWCM_BSSID_SIZE]; NWCMWepDesc wepDesc; u8 essId[NWCM_ESSID_SIZE]; u32 auth_option; } NWCMInstanceConfig; typedef struct NWCMInstance { NNETInstance ins; /* Instance information common to all layers */ NWCMInstanceConfig config; /*Instance-specific settings*/ NWCMProtocolList upper_protocol[NWCM_PROTOCOL_NUM]; /*Upper protocol and message queue for sending*/ s32 upper_protocol_count; NWCMMessage upper_mq[NWCM_UPPER_NUM]; /*Receive queue for upper layers*/ s32 upper_ins_count; s32 state; u8 macaddr[NWCM_MAC_LEN]; /*Local MAC address*/ u8 sendBuf[NWCM_MAX_SEND_LEN]; /*Send buffer*/ } NWCMInstance; /* Get NNETInstance from WCM instance */ NN_INLINE NNETInstance *NWCM_GetNNETInstance(NWCMInstance *wcm_ins) { return (NNETInstance *)wcm_ins; } /* Get WCM instance from NNETInstance */ NN_INLINE NWCMInstance *NWCM_GetNWCMInstance(NNETInstance *ins) { return (NWCMInstance *)ins; } /*---------------------------------------------------------------------------* * Function Prototypes *---------------------------------------------------------------------------*/ /* nwcm_main.c */ s32 NWCM_Init(const NNETAllocator *allocator); s32 NWCM_Finish(void); s32 NWCM_SetCommonConfig(const NWCMCommonConfig *common_conf); s32 NWCM_SetInstanceConfig(NWCMInstance *wcm_ins, const NWCMInstanceConfig *ins_conf); s32 NWCM_StartupIns(NNETInstance *ins, s32 timeout); s32 NWCM_CleanupIns(NNETInstance *ins, s32 timeout); s32 NWCM_AbortIns(NNETInstance *ins); s32 NWCM_CreateIns(NWCMInstance **wcm_ins, u32 device_id); s32 NWCM_DestroyIns(NWCMInstance *wcm_ins); s32 NWCM_GetStateIns(NWCMInstance *wcm_ins); s32 NWCM_GetUpperAPI(NNETEthernetAPI *wcm_api, NWCMInstance *wcm_ins); s32 NWCM_SetUpper(NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 entry[]); s32 NWCM_ClearUpper(NNETInstance *ins, NNETInstance *upper_ins); s32 NWCM_GetMacAddr(NNETInstance *ins, u8 *macaddr); s32 NWCM_SetMulticastAddr(NNETInstance *ins, u8 *macaddr); s32 NWCM_ClearMulticastAddr(NNETInstance *ins, u8 *macaddr); s32 NWCM_Send(NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf); s32 NWCM_Receive(NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf); s32 NWCM_CancelReceive(NNETInstance *ins, u32 receive_id); #ifdef NDEBUG_ENABLE extern void NWCM_Dummy_Recv(const u8 *srcAddr, const u8 *dstAddr, const u8 *buf, s32 len); #endif /* nwcm_state.c */ extern void NWCM_ChangeStateIns(NWCMInstance *ins, s32 state); extern NWCMCommonConfig nwcmCommonConfig; extern NWCMInstance *wcmIns; extern NWCMInstanceConfig CU_nwcmInsConfig; #ifdef __cplusplus } #endif /* NWCM_H */ #endif