libctru  v2.4.1
nim.h
Go to the documentation of this file.
1 /**
2  * @file nim.h
3  * @brief NIM (network installation management) service.
4  *
5  * This service is used to download and install titles from Nintendo's CDN.
6  *
7  * We differentiate between two different kinds of downloads:
8  *
9  * - "active" downloads, which are downloads started with @ref NIMS_StartDownload or @ref NIMS_StartDownloadSimple. The process must keep polling the current status using @ref NIMS_GetProgress.
10  * - "tasks", which are downloads started with @ref NIMS_RegisterTask. These are only processed in sleep mode.
11  */
12 #pragma once
13 
14 // FS_MediaType
15 #include <3ds/services/fs.h>
16 
17 /// Mode that NIM downloads/installs a title with.
18 typedef enum
19 {
20  IM_DEFAULT = 0, ///< Initial installation
21  IM_UNKNOWN1, ///< Unknown
22  IM_UNKNOWN2, ///< Unknown
23  IM_REINSTALL, ///< Reinstall currently installed title; use this if the title is already installed (including updates)
25 
26 /// Current state of a NIM download/installation.
27 typedef enum
28 {
29  DS_NOT_INITIALIZED = 0, ///< Download not yet initialized
30  DS_INITIALIZED, ///< Download initialized
31  DS_DOWNLOAD_TMD, ///< Downloading and installing TMD
32  DS_PREPARE_SAVE_DATA, ///< Initializing save data
33  DS_DOWNLOAD_CONTENTS, ///< Downloading and installing contents
34  DS_WAIT_COMMIT, ///< Waiting before calling AM_CommitImportTitles
35  DS_COMMITTING, ///< Running AM_CommitImportTitles
36  DS_FINISHED, ///< Title installation finished
37  DS_VERSION_ERROR, ///< (unknown error regarding title version)
38  DS_CREATE_CONTEXT, ///< Creating the .ctx file?
39  DS_CANNOT_RECOVER, ///< Irrecoverable error encountered (e.g. out of space)
40  DS_INVALID, ///< Invalid state
42 
43 /// Input configuration for NIM download/installation tasks.
44 typedef struct
45 {
46  u64 titleId; ///< Title ID
47  u32 version; ///< Title version
48  u32 unknown_0; ///< Always 0
49  u8 ratingAge; ///< Age for the HOME Menu parental controls
50  u8 mediaType; ///< Media type, see @ref FS_MediaType enum
51  u8 padding[2]; ///< Padding
52  u32 unknown_1; ///< Unknown input, seems to be always 0
54 
55 /// Output struct for NIM downloads/installations in progress.
56 typedef struct
57 {
58  u32 state; ///< State, see NIM_DownloadState enum
59  Result lastResult; ///< Last result code in NIM
60  u64 downloadedSize; ///< Amount of bytes that have been downloaded
61  u64 totalSize; ///< Amount of bytes that need to be downloaded in total
63 
64 /**
65  * @brief Initializes nim:s. This uses networking and is blocking.
66  * @param buffer A buffer for internal use. It must be at least 0x20000 bytes long.
67  * @param buffer_len Length of the passed buffer.
68  */
69 Result nimsInit(void *buffer, size_t buffer_len);
70 
71 /**
72  * @brief Initializes nim:s with the given TIN. This uses networking and is blocking.
73  * @param buffer A buffer for internal use. It must be at least 0x20000 bytes long.
74  * @param buffer_len Length of the passed buffer.
75  * @param TIN The TIN to initialize nim:s with. If you do not know what a TIN is or why you would want to change it, use @ref nimsInit instead.
76  */
77 Result nimsInitWithTIN(void *buffer, size_t buffer_len, const char *TIN);
78 
79 /// Exits nim:s.
80 void nimsExit(void);
81 
82 /// Gets the current nim:s session handle.
84 
85 /**
86  * @brief Sets an attribute.
87  * @param attr Name of the attribute.
88  * @param val Value of the attribute.
89  */
90 Result NIMS_SetAttribute(const char *attr, const char *val);
91 
92 /**
93  * @brief Checks if nim wants a system update.
94  * @param want_update Set to true if a system update is required. Can be NULL.
95  */
96 Result NIMS_WantUpdate(bool *want_update);
97 
98 /**
99  * @brief Makes a TitleConfig struct for use with @ref NIMS_RegisterTask, @ref NIMS_StartDownload or @ref NIMS_StartDownloadSimple.
100  * @param cfg Struct to initialize.
101  * @param titleId Title ID to download and install.
102  * @param version Version of the title to download and install.
103  * @param ratingAge Age for which the title is aged; used by parental controls in HOME Menu.
104  * @param mediaType Media type of the title to download and install.
105  */
106 void NIMS_MakeTitleConfig(NIM_TitleConfig *cfg, u64 titleId, u32 version, u8 ratingAge, FS_MediaType mediaType);
107 
108 /**
109  * @brief Registers a background download task with NIM. These are processed in sleep mode only.
110  * @param cfg Title config to use. See @ref NIMS_MakeTitleConfig.
111  * @param name Name of the title in UTF-8. Will be displayed on the HOME Menu. Maximum 73 characters.
112  * @param maker Name of the maker/publisher in UTF-8. Will be displayed on the HOME Menu. Maximum 37 characters.
113  */
114 Result NIMS_RegisterTask(const NIM_TitleConfig *cfg, const char *name, const char *maker);
115 
116 /**
117  * @brief Checks whether a background download task for the given title is registered with NIM.
118  * @param titleId Title ID to check for.
119  * @param registered Whether there is a background download task registered.
120  */
121 Result NIMS_IsTaskRegistered(u64 titleId, bool *registered);
122 
123 /**
124  * @brief Unregisters a background download task.
125  * @param titleId Title ID whose background download task to cancel.
126  */
128 
129 /**
130  * @brief Starts an active download with NIM. Progress can be checked with @ref NIMS_GetProcess. Do not exit the process while a download is in progress without calling @ref NIMS_CancelDownload.
131  * @param cfg Title config to use. See @ref NIMS_MakeTitleConfig.
132  * @param mode The installation mode to use. See @ref NIM_InstallationMode.
133  */
135 
136 /**
137  * @brief Starts an active download with NIM with default installation mode; cannot reinstall titles. Progress can be checked with @ref NIMS_GetProcess. Do not exit the process while a download is in progress without calling @ref NIMS_CancelDownload.
138  * @param cfg Title config to use. See @ref NIMS_MakeTitleConfig.
139  */
141 
142 /**
143  * @brief Checks the status of the current active download.
144  * @param tp Title progress struct to write to. See @ref NIM_TitleProgress.
145  */
147 
148 /**
149  * @brief Cancels the current active download with NIM.
150  */
Filesystem Services.
FS_MediaType
Media types.
Definition: fs.h:35
Result NIMS_GetProgress(NIM_TitleProgress *tp)
Checks the status of the current active download.
Result NIMS_UnregisterTask(u64 titleId)
Unregisters a background download task.
Result nimsInitWithTIN(void *buffer, size_t buffer_len, const char *TIN)
Initializes nim:s with the given TIN.
Result NIMS_SetAttribute(const char *attr, const char *val)
Sets an attribute.
Result NIMS_StartDownloadSimple(const NIM_TitleConfig *cfg)
Starts an active download with NIM with default installation mode; cannot reinstall titles.
Result NIMS_IsTaskRegistered(u64 titleId, bool *registered)
Checks whether a background download task for the given title is registered with NIM.
Result NIMS_RegisterTask(const NIM_TitleConfig *cfg, const char *name, const char *maker)
Registers a background download task with NIM.
Result NIMS_StartDownload(const NIM_TitleConfig *cfg, NIM_InstallationMode mode)
Starts an active download with NIM.
void NIMS_MakeTitleConfig(NIM_TitleConfig *cfg, u64 titleId, u32 version, u8 ratingAge, FS_MediaType mediaType)
Makes a TitleConfig struct for use with NIMS_RegisterTask, NIMS_StartDownload or NIMS_StartDownloadSi...
Result nimsInit(void *buffer, size_t buffer_len)
Initializes nim:s.
void nimsExit(void)
Exits nim:s.
Result NIMS_CancelDownload(void)
Cancels the current active download with NIM.
Handle * nimsGetSessionHandle(void)
Gets the current nim:s session handle.
Result NIMS_WantUpdate(bool *want_update)
Checks if nim wants a system update.
NIM_InstallationMode
Mode that NIM downloads/installs a title with.
Definition: nim.h:19
@ IM_UNKNOWN1
Unknown.
Definition: nim.h:21
@ IM_REINSTALL
Reinstall currently installed title; use this if the title is already installed (including updates)
Definition: nim.h:23
@ IM_DEFAULT
Initial installation.
Definition: nim.h:20
@ IM_UNKNOWN2
Unknown.
Definition: nim.h:22
NIM_DownloadState
Current state of a NIM download/installation.
Definition: nim.h:28
@ DS_CANNOT_RECOVER
Irrecoverable error encountered (e.g. out of space)
Definition: nim.h:39
@ DS_CREATE_CONTEXT
Creating the .ctx file?
Definition: nim.h:38
@ DS_COMMITTING
Running AM_CommitImportTitles.
Definition: nim.h:35
@ DS_DOWNLOAD_CONTENTS
Downloading and installing contents.
Definition: nim.h:33
@ DS_INVALID
Invalid state.
Definition: nim.h:40
@ DS_DOWNLOAD_TMD
Downloading and installing TMD.
Definition: nim.h:31
@ DS_PREPARE_SAVE_DATA
Initializing save data.
Definition: nim.h:32
@ DS_VERSION_ERROR
(unknown error regarding title version)
Definition: nim.h:37
@ DS_NOT_INITIALIZED
Download not yet initialized.
Definition: nim.h:29
@ DS_FINISHED
Title installation finished.
Definition: nim.h:36
@ DS_WAIT_COMMIT
Waiting before calling AM_CommitImportTitles.
Definition: nim.h:34
@ DS_INITIALIZED
Download initialized.
Definition: nim.h:30
Input configuration for NIM download/installation tasks.
Definition: nim.h:45
u32 unknown_1
Unknown input, seems to be always 0.
Definition: nim.h:52
u32 version
Title version.
Definition: nim.h:47
u8 mediaType
Media type, see FS_MediaType enum.
Definition: nim.h:50
u64 titleId
Title ID.
Definition: nim.h:46
u8 ratingAge
Age for the HOME Menu parental controls.
Definition: nim.h:49
u32 unknown_0
Always 0.
Definition: nim.h:48
Output struct for NIM downloads/installations in progress.
Definition: nim.h:57
u32 state
State, see NIM_DownloadState enum.
Definition: nim.h:58
u64 downloadedSize
Amount of bytes that have been downloaded.
Definition: nim.h:60
u64 totalSize
Amount of bytes that need to be downloaded in total.
Definition: nim.h:61
Result lastResult
Last result code in NIM.
Definition: nim.h:59
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
u32 Handle
Resource handle.
Definition: types.h:41
s32 Result
Function result.
Definition: types.h:42
uint32_t u32
32-bit unsigned integer
Definition: types.h:23