1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META http-equiv="Content-Style-Type" content="text/css">
6<TITLE>NWC24 Download API Introduction</TITLE>
7<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css">
8<LINK rel="stylesheet" type="text/css" href="../nwc24.css">
9</HEAD>
10<BODY>
11<H1>NWC24 Download API</H1>
12
13<H2>Introduction</H2>
14<P>
15Wii has a feature for synchronizing the automatic downloading of content from the server and saving to NAND memory while an application is running or while the console is in standby mode.<BR>With this function, applications can receive additional data without making the user wait.
16</P>
17
18<UL>
19<LI>The URL for the synchronized content must be pre-registered in the application.
20<LI>Wii automatically checks for updates to the content on the server at fixed intervals. (The interval is specified at the same time the URL is registered in the application.)
21<LI>If the content on the server has been updated, Wii automatically downloads and saves the content to its NAND flash.
22<LI>If the user does not start the application that registered the URL, automatic synchronization will be stopped.
23</UL>
24<P>
25</P>
26
27<H2><a name="idea">Overview</a></H2>
28
29<DL>
30	<DT>Download Task (Task)</DT>
31	<DD>
32		<P>
33		The download task refers to the collection of settings necessary for download reservation, such as the URL and check intervals for content updates.
34		</P>
35	</DD>
36	<DT>Download Task List (Task List)</DT>
37	<DD>
38		<P>
39		The download task list is a list of enabled download tasks.
40		</P>
41		<P>
42		A download task is enabled through registration to the download task list. The download task list is a file in NAND memory controlled through NWC24 functions.
43		</P>
44		<P>
45		Download tasks can be deleted from the task list automatically. (Details are described below.))
46		</P>
47	</DD>
48
49	<DT>Download Box</DT>
50	<DD>
51		<P>
52		The download box is the storage location of the downloaded data. There is one download box for each application.
53		</P>
54		<P>
55		An application must create a download box at initial startup and keep it in a usable state so that it is available for task registration. Create the download box in the application save area.
56		</P>
57	</DD>
58
59	<DT>Signature</DT>
60	<DD>
61		<P>
62		  WiiConnect24 automatically verifies the signature to ensure that the downloaded contents have not been falsified.<BR>To ensure security, contents acquired through HTTP must always have the correct signature.
63		</P>
64		<P>
65		  See also: <A href="sign.html">NWC24 Download Signatures</A>
66		</P>
67	</DD>
68
69</DL>
70
71
72<H2><a name="parameter">Download Task Configuration Items</a></H2>
73<P>
74The WiiConnect24 download feature is designed to avoid interference with the server, network, and applications running in the foreground. Therefore, users typically need to keep only certain parameters in mind, although detailed parameters settings are also possible.
75</P>
76
77<DL>
78
79
80<DT><a name="parameter_url">URL</a></DT>
81<DD>
82	<P>
83		Specifies the content acquisition source. Although the HTTP and HTTPS protocols are supported, the following restrictions are set to ensure security.
84	</P>
85	<DL>
86		<DT>a. When using HTTP</DT>
87		<DD>
88			<P>
89			  The signature verification functionality in WiiConnect24 must always be enabled.<BR>This restriction may be disabled through <A href="NWC24EnableDlLaxParameterChecking.html"><CODE>NWC24EnableDlLaxParameterChecking()</CODE></A> only for debugging.
90			</P>
91		</DD>
92		<DT>b. When using HTTPS</DT>
93		<DD>
94		  <P>The target server must have a server certificate that was issued by the Nintendo CA.</P>
95		</DD>
96	</DL>
97	<P>
98	  <A href="NWC24SetDlUrl.html"><CODE>NWC24SetDlUrl()</CODE></A>, <A href="NWC24GetDlUrl.html"><CODE>NWC24GetDlUrl()</CODE></A>
99	</P>
100</DD>
101
102<DT><a name="parameter_interval">Update Check Interval</a></DT>
103<DD>
104  <P>
105	WiiConnect24 queries the HTTP servers for content updates, using functions preset by HTTP. If the contents have been updated, they are downloaded. The interval for this update query is set in the update check interval.
106	</P>
107	<P>
108	Determining this value is extremely important. Setting a shorter update check interval allows users to acquire the updated contents sooner, but this also increases the server and network load. This value must therefore be determined with the scale of operation and the frequency of content update in mind. Since there is no way to change the update check interval later, the servers and network must be upgraded if they are inadequate. Therefore, be careful when choosing this value.
109	</P>
110	<P>
111	Keep in mind that the update check is not always performed as set by this value. Various factors may cause a delay in the operation.
112	</P>
113	<P>
114	  <A href="NWC24SetDlInterval.html"><CODE>NWC24SetDlInterval()</CODE></A>, <A href="NWC24GetDlInterval.html"><CODE>NWC24GetDlInterval()</CODE></A>
115	</P>
116</DD>
117
118<DT>Priority</DT>
119<DD><P>
120	When the update check timing overlaps with another, the task with the highest priority goes through. The update check for the remaining tasks is carried over to the next time (approximately two minutes later). (For more information on launch timing, see the <A href="../Scheduler/intro.html">NWC24 Scheduler Operation Functions</A>.
121	</P>
122	<P>
123	For this reason, if the update check interval is short, set the priority low so other tasks are given priority.<BR>There are restrictions that depend on the number of registered tasks and the update check interval. For details, see the <I>WiiConnect24 Programming Guidelines</I>.
124	</P>
125	<P>
126	Smaller values indicate higher priority.
127	</P>
128	<P>
129	  <A href="NWC24SetDlPriority.html"><CODE>NWC24SetDlPriority()</CODE></A>, <A href="NWC24GetDlPriority.html"><CODE>NWC24GetDlPriority()</CODE></A>
130	</P>
131</DD>
132
133<DT>Download Count</DT>
134<DD>
135	<P>
136	The download count is decremented each time a content update check is performed, and the task disappears once the count reaches zero. When a task disappears, the update check is no longer performed until the task is reregistered by the application.
137	</P>
138	<P>
139	The download count decrements by 1 when the update check is successful. In other words,
140	</P>
141	<UL>
142	<LI>you know if the Wii has connected to the server but there is no updated content, since the count decrements by 1 even if nothing was downloaded
143	<LI>If there is a network error or a server error and the process fails, the count will not change.
144	</UL>
145	<P>
146	  <A href="NWC24SetDlCount.html"><CODE>NWC24SetDlCount()</CODE></A>, <A href="NWC24GetDlCount.html"><CODE>NWC24GetDlCount()</CODE></A>
147	</P>
148</DD>
149
150<DT>File Name</DT>
151<DD>
152  <P>
153	Specifies the file name used to save to the download box. This item is effective when you want to keep past files. Directories other than the root directory may be specified as long as they are created first.
154	</P>
155	<P>
156	Normally there is no need to specify this.
157  </P>
158	<P>
159	  <A href="NWC24SetDlFilename.html"><CODE>NWC24SetDlFilename()</CODE></A>, <A href="NWC24GetDlFilename.html"><CODE>NWC24GetDlFilename()</CODE></A>
160	</P>
161</DD>
162
163<DT><a name="parameter_serverinterval">Server-side Update Interval</a></DT>
164<DD>
165	<P>
166	Specifies the update interval of the specified URL.
167	</P>
168	<P>
169	This setting will be used in a future upgrade. Currently, this value is not used, even if it is configured.
170	</P>
171	<P>
172	  <A href="NWC24SetDlServerInterval.html"><CODE>NWC24SetDlServerInterval()</CODE></A>, <A href="NWC24GetDlServerInterval.html"><CODE>NWC24GetDlServerInterval()</CODE></A>
173	</P>
174</DD>
175
176<DT>Retry Margin</DT>
177<DD>
178	<P>
179	If the Wii is turned off or a game application with WiiConnect24 operation prohibited is running, contents update check set by tasks is not performed. This may result in a substantial delay in the update check. The allowed margin of delay is set in the retry margin.<BR>When a delay beyond the allowed margin is detected, the next update check is performed at update check interval counting from the time of delay detection.
180	</P>
181	<P>
182	If WiiConnect24 cannot operate for a long period of time, multiple update checks are more likely to overlap once WiiConnect24 is operational again. This may also cause continuous download operations for an extended period of time, which may adversely affect other network operations.
183	</P>
184	<P>
185	In the following situations, set a smaller retry margin, as needed, so that other tasks have higher priority:
186	</P>
187	<UL>
188		<LI>When the update check interval is short</LI>
189		<LI>When the priority is high</LI>
190		<LI>When you want to avoid running an application immediately after startup, such as for a large download</LI>
191	</UL>
192	<P>
193	Since an appropriate value is automatically set by the library, this value typically does not need to be set. When changing the value, be sure you understand operations well enough to do so.
194	</P>
195	<P>
196	  <A href="NWC24SetDlRetryMargin.html"><CODE>NWC24SetDlRetryMargin()</CODE></A>, <A href="NWC24GetDlRetryMargin.html"><CODE>NWC24GetDlRetryMargin()</CODE></A>
197	</P>
198</DD>
199
200<DT>Flag</DT>
201<DD>
202	<P>
203	Various additional functions becomes usable through flags.
204	</P>
205	<P>
206	  <A href="NWC24SetDlFlags.html"><CODE>NWC24SetDlFlags()</CODE></A>, <A href="NWC24GetDlFlags.html"><CODE>NWC24GetDlFlags()</CODE></A>
207	</P>
208</DD>
209
210<DT>Application ID</DT>
211<DD>
212  <P>
213This is the ID of the application that registered the task. It is automatically set when a new task is created and cannot be changed. This is mainly used to restrict task access.
214  </P>
215	<P>
216When ID of the application that registered the task does not match ID of the application that read the task, the reading application cannot alter the task's contents. <BR>This does not apply if the task has <A href="NWC24SetDlFlags.html">group-writable settings</A> on. Also, this limit is not imposed on the same application in different regions.
217  </P>
218	<P>
219	  <A href="NWC24GetDlAppId.html"><CODE>NWC24GetDlAppId()</CODE></A>
220	</P>
221</DD>
222</DL>
223
224
225<H2><a name="parameter_application">Per-Application Setting Items</a></H2>
226<P>
227These are items that are set for each application that handles download tasks. Each task stores information for the application that registered it; this information is used for accessing the task.
228</P>
229
230<DL>
231
232<DT>Download Box</DT>
233<DD>
234  <P>
235The application must provide a VF archive that can store the contents retrieved by tasks that it registered.
236	</P>
237</DD>
238
239<DT><a name="">Public Keys and Shared Keys</a></DT>
240<DD>
241	<P>
242	Public keys are used to verify content signatures. Shared keys are used to decrypt encrypted content.
243  </P>
244	<P>
245	Although WiiConnect24 has public and shared keys in internal system regions that cannot be accessed, during normal use each application should separately provide a key. The key for the application can be set using <A href="NWC24GetDlAppId.html"><CODE>NWC24SetDlKeys()</CODE></A> and are stored in the Home directory.
246	</P>
247</DD>
248</DL>
249
250
251
252<H2>Flow of Download API Usage</H2>
253<H4>Download Task Registration</H4>
254
255<P>At each application startup, the following registration sequence is performed:</P>
256<OL>
257	<LI>Check for registered tasks
258	<LI>Create new task(s)
259	<LI>Update the remaining download count
260	<LI>(Re-)register tasks to the list
261</OL>
262
263<DL class="sequence">
264<DT>1. Check for Registered Tasks</DT>
265<DD>
266	<P>
267	Attempt to acquire tasks to check whether previously registered download tasks remain. If successful, go to 4. ((Re-)register tasks to the list.)
268	</P>
269	<P><A href="../Types/NWC24DlTask.html"><CODE>NWC24DlTask</CODE> Structure</A>, <A href="NWC24GetDlTask.html"><CODE>NWC24GetDlTask()</CODE></A>, <A href="NWC24GetDlTaskMine.html"><CODE>NWC24GetDlTaskMine()</CODE></A>, <A href="NWC24GetDlTaskByAppId.html"><CODE>NWC24GetDlTaskByAppId()</CODE></A></P>
270</DD>
271
272<DT>2. Create New Task(s)</DT>
273<DD>
274	<P>
275	Create and configure new download task(s). (See <a href="#parameter">Download Task Configuration Items</a> for the configuration items.) Usually, setting only the URL and the update check interval is sufficient.
276	</P>
277	<P>
278	There is no download box when the application starts up for the first time, so it must be created at that time. The size of downloadable files is limited by the available space in the download box. The application needs to determine the download box size, based on the size of the data it needs to handle. (Size restrictions follow the Wii Programming Guidelines.))
279	</P>
280	<P>
281	The download box is, in fact, an archive file handled by the VF library. The VF archive files for the download box have file permissions that allows view/update from other applications.
282	</P>
283	<P><A href="NWC24InitDlTask.html"><CODE>NWC24InitDlTask()</CODE></A>, <A href="NWC24CreateDlVf.html"><CODE>NWC24CreateDlVf()</CODE></A>, <A href="NWC24SetDlUrl.html"><CODE>NWC24SetDlUrl()</CODE></A>, <A href="NWC24SetDlInterval.html"><CODE>NWC24SetDlInterval()</CODE></A>, <A href="NWC24SetDlPriority.html"><CODE>NWC24SetDlPriority()</CODE></A>, ...</P>
284</DD>
285
286<DT>3. Update the Remaining Download Count</DT>
287<DD>
288	<P>Reset the remaining download count.</P>
289	<P>
290	The remaining download count is decremented each time a content update check is performed until the task disappears. Applications must reset the remaining download count to the original value at each startup. This is not the case for download tasks that need to be performed only once.
291	</P>
292	<P><A href="NWC24SetDlCount.html"><CODE>NWC24SetDlCount()</CODE></A></P>
293</DD>
294
295<DT>4. (Re-)register Tasks to the List</DT>
296<DD>
297	<P>
298	Register/re-register created or acquired tasks to the task list.
299	</P>
300	<P>
301	Use <A href="NWC24AddDlTask.html"><CODE>NWC24AddDlTask()</CODE></A> if the task was created in step 2, and <A href="NWC24AddDlTask.html"><CODE>NWC24UpdateDlTask()</CODE></A> if the task was successfully acquired in step 1. See the function reference for the differences between the two.
302	</P>
303</DD>
304</DL>
305
306<H4>Acquisition of Downloaded File</H4>
307<P>
308The download box is a VF library archive file. Use the <A href="../../vf/index.html" target="_top">VF API</a> to extract data.
309</P>
310
311<P>
312Get the archive file path name using <A href="NWC24GetDlVfPath.html"><CODE>NWC24GetDlVfPath()</CODE></A>. To get or delete downloaded files, the NWC24 library must be set in advance to a usable state by calling <CODE><A href="../Misc/NWC24OpenLib.html">NWC24OpenLib()</A></CODE>. There is no guarantee of operations if you manipulate VF archive files when the library is not open and in a usable state.
313</P>
314
315<H2>Precautions When Designing Content Reception</H2>
316
317<H3>How to Check Content Update from an Application</H3>
318<P>
319To avoid duplicate retrieval of the same content, WiiConnect24 uses the prescribed HTTP 1.1 method (If-Modified-Since header) for checking for updates on the server. The time of the most recent update to previously received content is stored in the task list. As a result, even if files in the download box are deleted, these update checks will work correctly.<BR>
320</P>
321<P>
322However, depending on the proxy server settings and other aspects of the user environment, there will be rare occasions when HTTP update checks will not work properly and duplicate content will be downloaded. Consequently, do not design a program such that it fails to operate if the same content is received. Consider this synchronizing feature using the update checks as a feature for limiting the server's transfer volume.
323</P>
324
325<P>
326We recommend that you embed sequence numbers in the content, and implement some process that ignores times, when the sequence number of received content is not larger than the number of the previously downloaded content.
327</P>
328
329
330<P>Example of use where embedded sequence numbers is recommended:</P>
331<UL>
332<LI>For delivery of items and other cases where obtained content is reflected in the Save Data<BR>If there is a process that deletes an existing file in the Download Box when new data arrives, so that the new data is reflected in the game, there will be cases where valuable items can be obtained multiple times.
333
334</UL>
335
336<P>Example of use where embedded sequence numbers is not necessary:</P>
337<UL>
338<LI>For delivery of ranking data and other such content that is downloaded for display purposes only
339</UL>
340
341
342<H3>Do Not Depend on Acquisition Timing</H3>
343<P>
344Various factors may cause a delay in the operation of downloading contents. Consequently, it is safest not to expect that new content will be downloaded at a specific time or to allow the user to see a date or time included in downloaded content.
345</P>
346
347
348<H3>Preparing for Empty Content</H3>
349<P>
350To halt the delivery of content, you can delete files from the server or prohibit access. However, this will also cause update inquiries to fail. Internally you will no longer be able to differentiate in error processing between scheduling that uses the final update time and positive errors.
351</P>
352<P>
353Therefore, we recommend that you define empty content that can be ignored by the application, containing only the control header used by the application, to halt delivery by delivering the empty content instead.
354</P>
355
356
357<H2>Notes for Developers</H2>
358
359<P>
360The settings and data of the download task are stored in the following locations:
361</P>
362
363<OL>
364<LI>The Save Data directory of each application (Public key, Secret key, Download Box)</LI>
365<LI>The WiiConnect24 system region (Items besides those of 1. that are accessed by special functions) </LI>
366</OL>
367
368<P>
369The NWC24 API maintains consistency, but certain operations performed during development can cause inconsistencies and result in states not anticipated by the developer. Be very careful when conducting operations like those described below.
370</P>
371
372<H3>Changing the Development Environment</H3>
373<P>
374Apart from the ID of the application that registered it, a download task internally stores the home directory path; these values are decided when the task is newly created. These values limit access and are used when accessing the download box.<BR>The download API assumes that each application has a different ID and home directory, so if the ID or home directory is changed during the development of an application, it may result in operations unintended by the developer.
375</P>
376
377<P>
378Specifically, cases such as the following require caution:
379</P>
380<UL>
381<LI>Switching the DVD library and CNT library while developing a NAND application</LI>
382<LI>Overwriting the GameCode in a <CODE>ddf</CODE> file</LI>
383</UL>
384
385<P>
386In situations like these, we recommend deleting all download tasks once.
387</P>
388
389<H3>Deleting Save Data</H3>
390<P>
391In the DEVKIT menu and the Wii Menu 2 and earlier versions, when the Save Data was deleted the download tasks remained behind but were referencing keys and Download Boxes that no longer existed.
392</P>
393
394<P>
395In Wii Menu 3 and later versions, the result and behavior of deleting is different from that of the DEVKIT menu. The specification has been changed so that when the Save Data is deleted, the registered download tasks are searched out and deleted at the same time.
396</P>
397
398<H2>Revision History</H2>
399<P>
4002007/11/12 Added text specific to the use of empty content.
401<BR> 2007/09/26 Added information on deleting saved data. <BR> 2007/07/24 Added notes on changing the development environment, etc. <BR> 2007/06/06 Added notes on designing receivable content.<BR> 2006/11/17 Initial version.fc<BR></P>
402
403<hr><p>CONFIDENTIAL</p></body>
404</HTML>