/*---------------------------------------------------------------------------* Project: Wii Connect 24 API demos File: Check.c Copyright 2006 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: Check.c,v $ Revision 1.7 2008/04/28 09:50:52 hirose_kazuki Updated messsages again. Revision 1.6 2008/03/06 05:29:20 hirose_kazuki Updated messsages and sequences to match the latest guideline requirements. Revision 1.5 2007/01/31 09:10:20 hirose_kazuki Rewrote error check sequence after NWC24OpenLib. Revision 1.4 2006/11/01 01:50:59 hirose_kazuki Removed NWC24_ERR_PROTECTED result from NWC24Check() sequence. Revision 1.3 2006/10/26 08:06:40 hirose_kazuki Fixed an easy mistake. Revision 1.2 2006/10/26 02:52:49 hirose_kazuki Added case handling for NWC24_ERR_FATAL on NWC24Check(). Revision 1.1 2006/10/23 04:13:03 hirose_kazuki Initial check in. *---------------------------------------------------------------------------*/ #include #include #include #include #include #include /*---------------------------------------------------------------------------* WiiConnect24 status check sequence sample. *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ // Error messages /* ===================================================================== NOTE: Following messages might not be up-to-date. Please refer to "WiiConnect24 message list" for messages you should use in applications. ===================================================================== */ #define ERRORMSG_WC24_01 /* File errors */ \ "[ID:WC24_01] \n" \ "There is a problem with the Wii system memory,\n" \ "so WiiConnect24 cannot be used.\n" #define ERRORMSG_WC24_02 /* System update required */ \ "[ID:WC24_02] \n" \ "To use WiiConnect24, a system update is required.\n" \ "Refer to the Wii Operations Manual for details.\n" #define ERRORMSG_WC24_03 /* Other fatal errors */ \ "[ID:WC24_03] \n" \ "WiiConnect24 cannot be used because an error has occurred.\n" \ "Reset and try again.\n" #define ERRORMSG_WC24_04 /* WiiConnect24 is busy */ \ "[ID:WC24_04] \n" \ "WiiConnect24 is temporarily unavailable. Please try again later.\n" #define ERRORMSG_WC24_05 /* Setting is disabled */ \ "[ID:WC24_05] \n" \ "The WiiConnect24 setting is not turned on. Please check the\n" \ "settings under Wii Options. Refer to the Wii Operations Manual\n" \ "for details.\n" #define ERRORMSG_WC24_06 /* Network setting problem */ \ "[ID:WC24_06] \n" \ "An Internet connection cannot be established, so WiiConnect24\n" \ "cannot be used. Check the Internet settings and connection.\n" \ "Refer to the Wii Operations Manual for details.\n" #define ERRORMSG_WC24_07 /* Server problem */ \ "[ID:WC24_07] \n" \ "WiiConnect24 is temporarily unavailable. Please try again later.\n" #define ERRORMSG_WC24_08 /* Send-box full */ \ "[ID:WC24_08] \n" \ "WiiConnect24 is temporarily unavailable. Please try again later.\n" #define ERRORMSG_WC24_12 /* Prohibited by parental control */ \ "[ID:WC24_12] \n" \ "Use of network features has been restricted. Please check the\n" \ "settings for Parental Controls under Wii Options.\n" #define ERRORMSG_NAND_08 /* NAND memory corrupted */ \ "[ID:NAND_08] \n" \ "The Wii system memory has been damaged.\n" \ "Refer to the Wii Operations Manual for details.\n" /*---------------------------------------------------------------------------*/ void PrintError( const char* errorMsg ); /*---------------------------------------------------------------------------*/ MEMHeapHandle HeapHndl; MEMAllocator Allocator; /*---------------------------------------------------------------------------* Main *---------------------------------------------------------------------------*/ int main(void) { NWC24Err err; s32 result; void* arenaLo; void* arenaHi; char* libWorkMem; u32 retryCount; // Memory allocator initialization arenaLo = OSGetMEM1ArenaLo(); arenaHi = OSGetMEM1ArenaHi(); HeapHndl = MEMCreateExpHeap(arenaLo, (u32)arenaHi - (u32)arenaLo); OSSetMEM1ArenaLo(arenaHi); MEMInitAllocatorForExpHeap(&Allocator, HeapHndl, 32); result = NANDInit(); if ( result != NAND_RESULT_OK ) { OSHalt("NANDInit() failed.\n"); } VFInit(); OSReport("*******************************************************\n"); OSReport(" WiiConnect24 status check sequence sample\n"); OSReport("*******************************************************\n"); libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE); retryCount = 0; openRetry: /********************************************** * Opens the library and check results * **********************************************/ err = NWC24OpenLib(libWorkMem); if ( err == NWC24_OK ) { } else if ( err == NWC24_ERR_NAND_CORRUPT ) { /* NAND flash corrupted [NWC24_ERR_NAND_CORRUPT] */ PrintError(ERRORMSG_NAND_08); goto end; } else if ( NWC24_ERR_IS_FILE(err) ) { /* File access errors [NWC24_ERR_BROKEN, NWC24_ERR_FILE_*, NWC24_ERR_INTERNAL_VF] */ PrintError(ERRORMSG_WC24_01); goto end; } else if ( NWC24_ERR_IS_FATAL(err) ) { /* Fatal errors [NWC24_ERR_FATAL, NWC24_ERR_INTERNAL_IPC] */ PrintError(ERRORMSG_WC24_03); goto end; } else if ( err == NWC24_ERR_OLD_SYSTEM ) { /* Systemmenu version errors [NWC24_ERR_OLD_SYSTEM] */ PrintError(ERRORMSG_WC24_02); goto end; } else if ( NWC24_ERR_IS_RETRIABLE(err) ) { /* Retriable errors [NWC24_ERR_MUTEX, NWC24_ERR_BUSY, NWC24_ERR_INPROGRESS] */ if ( retryCount == 10 ) { PrintError(ERRORMSG_WC24_04); goto end; } OSReport("NWC24OpenLib() -- Busy(%d). Retrying.\n", err); OSSleepSeconds(2); ++retryCount; goto openRetry; } else { /* Other errors (because of programming error) */ OSReport("NWC24OpenLib() -- Programming error (%d).\n", err); goto end; } /********************************************** * Status check by NWC24Check() * **********************************************/ err = NWC24Check(NWC24_USE_MESSAGES); switch ( err ) { case NWC24_OK: break; case NWC24_ERR_FATAL: PrintError(ERRORMSG_WC24_03); goto closeLib; case NWC24_ERR_DISABLED: PrintError(ERRORMSG_WC24_05); goto closeLib; case NWC24_ERR_NETWORK: PrintError(ERRORMSG_WC24_06); goto closeLib; case NWC24_ERR_SERVER: PrintError(ERRORMSG_WC24_07); goto closeLib; case NWC24_ERR_FULL: PrintError(ERRORMSG_WC24_08); goto closeLib; case NWC24_ERR_PROTECTED: PrintError(ERRORMSG_WC24_12); goto closeLib; default: // Should not reach here. break; } OSReport("All NWC24 status check passed.\n"); closeLib: err = NWC24CloseLib(); if ( err != NWC24_OK ) { OSReport("NWC24CloseLib(): Error %d\n", err); OSHalt("Failed.\n"); } end: MEMFreeToAllocator(&Allocator, libWorkMem); OSHalt("\nProgram finished.\n"); return 0; } /*---------------------------------------------------------------------------* Prints error message and 6-digits error code *---------------------------------------------------------------------------*/ void PrintError( const char* errorMsg ) { s32 errorCode; errorCode = NWC24GetErrorCode(); OSReport("NWC24 status check failed. [%06d]\n", -errorCode); OSReport("Message: %s\n", errorMsg); return; }