1 /*---------------------------------------------------------------------------*
2 Project: Wii Connect 24 API demos
3 File: Check.c
4
5 Copyright 2006 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 $Log: Check.c,v $
14 Revision 1.5 2007/01/31 09:10:20 hirose_kazuki
15 Rewrote error check sequence after NWC24OpenLib.
16
17 Revision 1.4 2006/11/01 01:50:59 hirose_kazuki
18 Removed NWC24_ERR_PROTECTED result from NWC24Check() sequence.
19
20 Revision 1.3 2006/10/26 08:06:40 hirose_kazuki
21 Fixed an easy mistake.
22
23 Revision 1.2 2006/10/26 02:52:49 hirose_kazuki
24 Added case handling for NWC24_ERR_FATAL on NWC24Check().
25
26 Revision 1.1 2006/10/23 04:13:03 hirose_kazuki
27 Initial check in.
28
29
30 *---------------------------------------------------------------------------*/
31 #include <revolution.h>
32
33 #include <revolution/nand.h>
34 #include <revolution/vf.h>
35 #include <revolution/mem.h>
36
37 #include <revolution/nwc24.h>
38
39 #include <stdio.h>
40
41 /*---------------------------------------------------------------------------*
42 WiiConnect24 status check sequence sample.
43 *---------------------------------------------------------------------------*/
44
45 /*---------------------------------------------------------------------------*/
46 // Error messages (tentative)
47
48 #define ERRORMSG_FATAL "Fatal error."
49 #define ERRORMSG_FILE "File access problem."
50 #define ERRORMSG_OLD_SYSTEM "System update required."
51 #define ERRORMSG_NOT_AVAILABLE "Service is not activated."
52 #define ERRORMSG_NETWORK "Network problem."
53 #define ERRORMSG_SERVER "Server problem."
54 #define ERRORMSG_SENDBOXFULL "Send box is full."
55
56
57 /*---------------------------------------------------------------------------*/
58 void PrintError( const char* errorMsg );
59
60 /*---------------------------------------------------------------------------*/
61 MEMHeapHandle HeapHndl;
62 MEMAllocator Allocator;
63
64 /*---------------------------------------------------------------------------*
65 Main
66 *---------------------------------------------------------------------------*/
main(void)67 int main(void)
68 {
69 NWC24Err err;
70 s32 result;
71 void* arenaLo;
72 void* arenaHi;
73 char* libWorkMem;
74
75 // Memory allocator initialization
76 arenaLo = OSGetMEM1ArenaLo();
77 arenaHi = OSGetMEM1ArenaHi();
78 HeapHndl = MEMCreateExpHeap(arenaLo, (u32)arenaHi - (u32)arenaLo);
79 OSSetMEM1ArenaLo(arenaHi);
80 MEMInitAllocatorForExpHeap(&Allocator, HeapHndl, 32);
81
82 result = NANDInit();
83 if ( result != NAND_RESULT_OK )
84 {
85 OSHalt("NANDInit() failed.\n");
86 }
87 VFInit();
88
89 OSReport("*******************************************************\n");
90 OSReport(" WiiConnect24 status check sequence sample\n");
91 OSReport("*******************************************************\n");
92
93 libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE);
94
95 openRetry:
96 /**********************************************
97 * Opens the library and check results *
98 **********************************************/
99 err = NWC24OpenLib(libWorkMem);
100 if ( err == NWC24_OK )
101 {
102 }
103 else if ( NWC24_ERR_IS_FATAL(err) )
104 {
105 /* Fatal errors [NWC24_ERR_FATAL, NWC24_ERR_INTERNAL_IPC] */
106 PrintError(ERRORMSG_FATAL);
107 goto end;
108 }
109 else if ( NWC24_ERR_IS_FILE(err) )
110 {
111 /* File access errors [NWC24_ERR_BROKEN, NWC24_ERR_FILE_*,
112 NWC24_ERR_INTERNAL_VF, NWC24_ERR_NAND_CORRUPT] */
113 PrintError(ERRORMSG_FILE);
114 goto end;
115 }
116 else if ( err == NWC24_ERR_OLD_SYSTEM )
117 {
118 /* Systemmenu version errors [NWC24_ERR_OLD_SYSTEM] */
119 PrintError(ERRORMSG_OLD_SYSTEM);
120 goto end;
121 }
122 else if ( NWC24_ERR_IS_RETRIABLE(err) )
123 {
124 /* Retriable errors [NWC24_ERR_MUTEX, NWC24_ERR_BUSY, NWC24_ERR_INPROGRESS] */
125 OSReport("NWC24OpenLib() -- Busy(%d). Retrying.\n", err);
126 OSSleepSeconds(2);
127 goto openRetry;
128 }
129 else
130 {
131 /* Other errors (because of programming error) */
132 OSReport("NWC24OpenLib() -- Programming error (%d).\n", err);
133 goto end;
134 }
135
136 /**********************************************
137 * Status check by NWC24Check() *
138 **********************************************/
139 err = NWC24Check(NWC24_USE_MESSAGES);
140 switch ( err )
141 {
142 case NWC24_OK:
143 break;
144 case NWC24_ERR_FATAL:
145 PrintError(ERRORMSG_FATAL);
146 goto closeLib;
147 case NWC24_ERR_DISABLED:
148 PrintError(ERRORMSG_NOT_AVAILABLE);
149 goto closeLib;
150 case NWC24_ERR_NETWORK:
151 PrintError(ERRORMSG_NETWORK);
152 goto closeLib;
153 case NWC24_ERR_SERVER:
154 PrintError(ERRORMSG_SERVER);
155 goto closeLib;
156 case NWC24_ERR_FULL:
157 PrintError(ERRORMSG_SENDBOXFULL);
158 goto closeLib;
159 default:
160 // Should not reach here.
161 break;
162 }
163
164 OSReport("All NWC24 status check passed.\n");
165
166 closeLib:
167 err = NWC24CloseLib();
168 if ( err != NWC24_OK )
169 {
170 OSReport("NWC24CloseLib(): Error %d\n", err);
171 OSHalt("Failed.\n");
172 }
173
174 end:
175 MEMFreeToAllocator(&Allocator, libWorkMem);
176
177 OSHalt("Program finished.\n");
178
179 return 0;
180 }
181
182 /*---------------------------------------------------------------------------*
183 Prints error message and 6-digits error code
184 *---------------------------------------------------------------------------*/
PrintError(const char * errorMsg)185 void PrintError( const char* errorMsg )
186 {
187 s32 errorCode;
188
189 errorCode = NWC24GetErrorCode();
190 OSReport("NWC24 status check failed. [%06d]\n", -errorCode);
191 OSReport("%s\n", errorMsg);
192
193 return;
194 }
195
196
197