libnx  v4.8.0
ncm_types.h
Go to the documentation of this file.
1 /**
2  * @file ncm_types.h
3  * @brief Content Manager (ncm) service types (see ncm.h for the rest).
4  * @author Adubbz, zhuowei, and yellows8
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 #include "../crypto/sha256.h"
10 
11 /// StorageId
12 typedef enum {
13  NcmStorageId_None = 0, ///< None
14  NcmStorageId_Host = 1, ///< Host
15  NcmStorageId_GameCard = 2, ///< GameCard
16  NcmStorageId_BuiltInSystem = 3, ///< BuiltInSystem
17  NcmStorageId_BuiltInUser = 4, ///< BuiltInUser
18  NcmStorageId_SdCard = 5, ///< SdCard
19  NcmStorageId_Any = 6, ///< Any
20 } NcmStorageId;
21 
22 /// ContentType
23 typedef enum {
24  NcmContentType_Meta = 0, ///< Meta
25  NcmContentType_Program = 1, ///< Program
26  NcmContentType_Data = 2, ///< Data
27  NcmContentType_Control = 3, ///< Control
28  NcmContentType_HtmlDocument = 4, ///< HtmlDocument
29  NcmContentType_LegalInformation = 5, ///< LegalInformation
30  NcmContentType_DeltaFragment = 6, ///< DeltaFragment
32 
33 /// ContentMetaType
34 typedef enum {
35  NcmContentMetaType_Unknown = 0x0, ///< Unknown
36  NcmContentMetaType_SystemProgram = 0x1, ///< SystemProgram
37  NcmContentMetaType_SystemData = 0x2, ///< SystemData
38  NcmContentMetaType_SystemUpdate = 0x3, ///< SystemUpdate
39  NcmContentMetaType_BootImagePackage = 0x4, ///< BootImagePackage
40  NcmContentMetaType_BootImagePackageSafe = 0x5, ///< BootImagePackageSafe
41  NcmContentMetaType_Application = 0x80, ///< Application
42  NcmContentMetaType_Patch = 0x81, ///< Patch
43  NcmContentMetaType_AddOnContent = 0x82, ///< AddOnContent
44  NcmContentMetaType_Delta = 0x83, ///< Delta
45  NcmContentMetaType_DataPatch = 0x84, ///< DataPatch
47 
48 /// ContentMetaAttribute
49 typedef enum {
51  NcmContentMetaAttribute_IncludesExFatDriver = BIT(0), ///< IncludesExFatDriver
55 
56 /// ContentInstallType
57 typedef enum {
59  NcmContentInstallType_FragmentOnly = 1, ///< FragmentOnly
62 
63 /// ContentMetaPlatform
64 typedef enum {
67 
68 /// ContentId
69 typedef struct {
70  u8 c[0x10]; ///< Id
71 } NcmContentId;
72 
73 /// PlaceHolderId
74 typedef struct {
75  Uuid uuid; ///< UUID
77 
78 /// ContentMetaKey
79 typedef struct {
80  u64 id; ///< Id.
81  u32 version; ///< Version.
82  u8 type; ///< \ref NcmContentMetaType
83  u8 install_type; ///< \ref NcmContentInstallType
84  u8 padding[2]; ///< Padding.
86 
87 /// ApplicationContentMetaKey
88 typedef struct {
89  NcmContentMetaKey key; ///< \ref NcmContentMetaKey
90  u64 application_id; ///< ApplicationId.
92 
93 /// ContentInfo
94 typedef struct {
95  NcmContentId content_id; ///< \ref NcmContentId
96  u32 size_low; ///< Content size (low).
97  u8 size_high; ///< Content size (high).
98  u8 attr; ///< Content attributes.
99  u8 content_type; ///< \ref NcmContentType.
100  u8 id_offset; ///< Offset of this content. Unused by most applications.
102 
103 /// PackagedContentInfo
104 typedef struct {
105  u8 hash[SHA256_HASH_SIZE];
106  NcmContentInfo info;
108 
109 /// ContentMetaInfo
110 typedef struct {
111  u64 id; ///< Id.
112  u32 version; ///< Version.
113  u8 type; ///< \ref NcmContentMetaType
114  u8 attr; ///< \ref NcmContentMetaAttribute
115  u8 padding[2]; ///< Padding.
117 
118 /// ContentMetaHeader
119 typedef struct {
120  u16 extended_header_size; ///< Size of optional struct that comes after this one.
121  u16 content_count; ///< Number of NcmContentInfos after the extra bytes.
122  u16 content_meta_count; ///< Number of NcmContentMetaInfos that come after the NcmContentInfos.
123  u8 attributes; ///< Usually None (0).
124  u8 storage_id; ///< Usually None (0).
126 
127 /// ApplicationMetaExtendedHeader
128 typedef struct {
129  u64 patch_id; ///< PatchId of this application's patch.
130  u32 required_system_version; ///< Firmware version required by this application.
131  u32 required_application_version; ///< [9.0.0+] Owner application version required by this application. Previously padding.
133 
134 /// PatchMetaExtendedHeader
135 typedef struct {
136  u64 application_id; ///< ApplicationId of this patch's corresponding application.
137  u32 required_system_version; ///< Firmware version required by this patch.
138  u32 extended_data_size; ///< Size of the extended data following the NcmContentInfos.
139  u8 reserved[0x8]; ///< Unused.
141 
142 /// AddOnContentMetaExtendedHeader [15.0.0+]
143 typedef struct {
144  u64 application_id; ///< ApplicationId of this add-on-content's corresponding application.
145  u32 required_application_version; ///< Version of the application required by this add-on-content.
146  u8 content_accessibilities; ///< Content accessibilities.
147  u8 padding[3]; ///< Padding.
148  u64 data_patch_id; ///< DataPatchId of this add-on-content's corresponding data patch.
150 
151 /// LegacyAddOnContentMetaExtendedHeader [1.0.0-14.1.2]
152 typedef struct {
153  u64 application_id; ///< ApplicationId of this add-on-content's corresponding application.
154  u32 required_application_version; ///< Version of the application required by this add-on-content.
155  u32 padding; ///< Padding.
157 
158 /// DataPatchMetaExtendedHeader
159 typedef struct {
160  u64 data_id; ///< DataId of this data patch's corresponding add-on-content.
161  u64 application_id; ///< ApplicationId of this data patch's add-on-content's corresponding application.
162  u32 required_application_version; ///< Version of the application required by this data patch.
163  u32 extended_data_size; ///< Size of the extended data following the NcmContentInfos.
164  u64 padding; ///< Padding.
166 
167 /// SystemUpdateMetaExtendedHeader
168 typedef struct {
169  u32 extended_data_size; ///< Size of the extended data after NcmContentInfos and NcmContentMetaInfos.
171 
172 /// ProgramLocation
173 typedef struct {
174  u64 program_id; ///< ProgramId
175  u8 storageID; ///< \ref NcmStorageId
176  u8 pad[7]; ///< Padding
178 
179 /**
180  * @brief Retrieves the content size from a \ref NcmContentInfo struct.
181  * @param[in] info Pointer to \ref NcmContentInfo struct.
182  * @param[out] out Output size.
183  */
185  *out = ((u64)info->size_high << 32) | info->size_low;
186 }
187 
188 /**
189  * @brief Updates the content size from a \ref NcmContentInfo struct.
190  * @param[in] size Input size.
191  * @param[out] out Pointer to \ref NcmContentInfo struct.
192  */
194  info->size_low = size & 0xFFFFFFFF;
195  info->size_high = (u8)(size >> 32);
196 }
static void ncmContentInfoSizeToU64(const NcmContentInfo *info, u64 *out)
Retrieves the content size from a NcmContentInfo struct.
Definition: ncm_types.h:184
static void ncmU64ToContentInfoSize(const u64 size, NcmContentInfo *info)
Updates the content size from a NcmContentInfo struct.
Definition: ncm_types.h:193
NcmStorageId
StorageId.
Definition: ncm_types.h:12
@ NcmStorageId_None
None.
Definition: ncm_types.h:13
@ NcmStorageId_Any
Any.
Definition: ncm_types.h:19
@ NcmStorageId_BuiltInUser
BuiltInUser.
Definition: ncm_types.h:17
@ NcmStorageId_Host
Host.
Definition: ncm_types.h:14
@ NcmStorageId_SdCard
SdCard.
Definition: ncm_types.h:18
@ NcmStorageId_BuiltInSystem
BuiltInSystem.
Definition: ncm_types.h:16
@ NcmStorageId_GameCard
GameCard.
Definition: ncm_types.h:15
NcmContentInstallType
ContentInstallType.
Definition: ncm_types.h:57
@ NcmContentInstallType_Unknown
Unknown.
Definition: ncm_types.h:60
@ NcmContentInstallType_Full
Full.
Definition: ncm_types.h:58
@ NcmContentInstallType_FragmentOnly
FragmentOnly.
Definition: ncm_types.h:59
NcmContentMetaAttribute
ContentMetaAttribute.
Definition: ncm_types.h:49
@ NcmContentMetaAttribute_Compacted
Compacted.
Definition: ncm_types.h:53
@ NcmContentMetaAttribute_Rebootless
Rebootless.
Definition: ncm_types.h:52
@ NcmContentMetaAttribute_None
None.
Definition: ncm_types.h:50
@ NcmContentMetaAttribute_IncludesExFatDriver
IncludesExFatDriver.
Definition: ncm_types.h:51
NcmContentMetaType
ContentMetaType.
Definition: ncm_types.h:34
@ NcmContentMetaType_AddOnContent
AddOnContent.
Definition: ncm_types.h:43
@ NcmContentMetaType_BootImagePackageSafe
BootImagePackageSafe.
Definition: ncm_types.h:40
@ NcmContentMetaType_SystemData
SystemData.
Definition: ncm_types.h:37
@ NcmContentMetaType_Application
Application.
Definition: ncm_types.h:41
@ NcmContentMetaType_Delta
Delta.
Definition: ncm_types.h:44
@ NcmContentMetaType_SystemProgram
SystemProgram.
Definition: ncm_types.h:36
@ NcmContentMetaType_SystemUpdate
SystemUpdate.
Definition: ncm_types.h:38
@ NcmContentMetaType_Patch
Patch.
Definition: ncm_types.h:42
@ NcmContentMetaType_BootImagePackage
BootImagePackage.
Definition: ncm_types.h:39
@ NcmContentMetaType_Unknown
Unknown.
Definition: ncm_types.h:35
@ NcmContentMetaType_DataPatch
DataPatch.
Definition: ncm_types.h:45
NcmContentMetaPlatform
ContentMetaPlatform.
Definition: ncm_types.h:64
@ NcmContentMetaPlatform_Nx
Nx.
Definition: ncm_types.h:65
NcmContentType
ContentType.
Definition: ncm_types.h:23
@ NcmContentType_Program
Program.
Definition: ncm_types.h:25
@ NcmContentType_LegalInformation
LegalInformation.
Definition: ncm_types.h:29
@ NcmContentType_Control
Control.
Definition: ncm_types.h:27
@ NcmContentType_Meta
Meta.
Definition: ncm_types.h:24
@ NcmContentType_Data
Data.
Definition: ncm_types.h:26
@ NcmContentType_HtmlDocument
HtmlDocument.
Definition: ncm_types.h:28
@ NcmContentType_DeltaFragment
DeltaFragment.
Definition: ncm_types.h:30
AddOnContentMetaExtendedHeader [15.0.0+].
Definition: ncm_types.h:143
u64 application_id
ApplicationId of this add-on-content's corresponding application.
Definition: ncm_types.h:144
u32 required_application_version
Version of the application required by this add-on-content.
Definition: ncm_types.h:145
u64 data_patch_id
DataPatchId of this add-on-content's corresponding data patch.
Definition: ncm_types.h:148
u8 content_accessibilities
Content accessibilities.
Definition: ncm_types.h:146
ApplicationContentMetaKey.
Definition: ncm_types.h:88
u64 application_id
ApplicationId.
Definition: ncm_types.h:90
NcmContentMetaKey key
NcmContentMetaKey
Definition: ncm_types.h:89
ApplicationMetaExtendedHeader.
Definition: ncm_types.h:128
u32 required_application_version
[9.0.0+] Owner application version required by this application. Previously padding.
Definition: ncm_types.h:131
u32 required_system_version
Firmware version required by this application.
Definition: ncm_types.h:130
u64 patch_id
PatchId of this application's patch.
Definition: ncm_types.h:129
ContentId.
Definition: ncm_types.h:69
ContentInfo.
Definition: ncm_types.h:94
u8 content_type
NcmContentType.
Definition: ncm_types.h:99
u8 attr
Content attributes.
Definition: ncm_types.h:98
u8 size_high
Content size (high).
Definition: ncm_types.h:97
u32 size_low
Content size (low).
Definition: ncm_types.h:96
u8 id_offset
Offset of this content. Unused by most applications.
Definition: ncm_types.h:100
NcmContentId content_id
NcmContentId
Definition: ncm_types.h:95
ContentMetaHeader.
Definition: ncm_types.h:119
u8 attributes
Usually None (0).
Definition: ncm_types.h:123
u16 content_count
Number of NcmContentInfos after the extra bytes.
Definition: ncm_types.h:121
u16 content_meta_count
Number of NcmContentMetaInfos that come after the NcmContentInfos.
Definition: ncm_types.h:122
u16 extended_header_size
Size of optional struct that comes after this one.
Definition: ncm_types.h:120
u8 storage_id
Usually None (0).
Definition: ncm_types.h:124
ContentMetaInfo.
Definition: ncm_types.h:110
u64 id
Id.
Definition: ncm_types.h:111
u8 type
NcmContentMetaType
Definition: ncm_types.h:113
u32 version
Version.
Definition: ncm_types.h:112
u8 attr
NcmContentMetaAttribute
Definition: ncm_types.h:114
ContentMetaKey.
Definition: ncm_types.h:79
u8 install_type
NcmContentInstallType
Definition: ncm_types.h:83
u64 id
Id.
Definition: ncm_types.h:80
u8 type
NcmContentMetaType
Definition: ncm_types.h:82
u32 version
Version.
Definition: ncm_types.h:81
DataPatchMetaExtendedHeader.
Definition: ncm_types.h:159
u64 application_id
ApplicationId of this data patch's add-on-content's corresponding application.
Definition: ncm_types.h:161
u64 data_id
DataId of this data patch's corresponding add-on-content.
Definition: ncm_types.h:160
u64 padding
Padding.
Definition: ncm_types.h:164
u32 required_application_version
Version of the application required by this data patch.
Definition: ncm_types.h:162
u32 extended_data_size
Size of the extended data following the NcmContentInfos.
Definition: ncm_types.h:163
LegacyAddOnContentMetaExtendedHeader [1.0.0-14.1.2].
Definition: ncm_types.h:152
u64 application_id
ApplicationId of this add-on-content's corresponding application.
Definition: ncm_types.h:153
u32 required_application_version
Version of the application required by this add-on-content.
Definition: ncm_types.h:154
u32 padding
Padding.
Definition: ncm_types.h:155
PackagedContentInfo.
Definition: ncm_types.h:104
PatchMetaExtendedHeader.
Definition: ncm_types.h:135
u32 required_system_version
Firmware version required by this patch.
Definition: ncm_types.h:137
u64 application_id
ApplicationId of this patch's corresponding application.
Definition: ncm_types.h:136
u32 extended_data_size
Size of the extended data following the NcmContentInfos.
Definition: ncm_types.h:138
PlaceHolderId.
Definition: ncm_types.h:74
Uuid uuid
UUID.
Definition: ncm_types.h:75
ProgramLocation.
Definition: ncm_types.h:173
u8 storageID
NcmStorageId
Definition: ncm_types.h:175
u64 program_id
ProgramId.
Definition: ncm_types.h:174
SystemUpdateMetaExtendedHeader.
Definition: ncm_types.h:168
u32 extended_data_size
Size of the extended data after NcmContentInfos and NcmContentMetaInfos.
Definition: ncm_types.h:169
Definition: types.h:48
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:54
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition: types.h:92
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21