Difference between revisions of "NIM Services"

From 3dbrew
Jump to navigation Jump to search
(Filling out nim:u service commands)
(Filling out nim:u types)
Line 292: Line 292:
  
 
=Types=
 
=Types=
==InstallationMode==
+
 
 +
==SystemUpdateProgress==
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Offset
 +
!  Length
 +
!  Description
 +
|-
 +
| 0x00
 +
| 0x01
 +
| [[#SystemUpdateState|System Update State]]
 +
|-
 +
| 0x01
 +
| 0x03
 +
| Padding
 +
|-
 +
| 0x04
 +
| 0x04
 +
| Last Operation Result Code
 +
|-
 +
| 0x08
 +
| 0x08
 +
| Current Title Downloaded Bytes
 +
|-
 +
| 0x10
 +
| 0x08
 +
| Current Title Total Bytes
 +
|-
 +
| 0x18
 +
| 0x08
 +
| Titles Downloaded
 +
|-
 +
| 0x20
 +
| 0x08
 +
| Titles Total
 +
|}
 +
 
 +
==SystemUpdateState==
 +
 
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 299: Line 338:
 
|-
 
|-
 
| 0
 
| 0
| Initial installation
+
| Not Initialized
 
|-
 
|-
 
| 1
 
| 1
| Unknown
+
| Starting System Update
 
|-
 
|-
 
| 2
 
| 2
| Unknown
+
| Fetching System Hash and Account Status
 
|-
 
|-
 
| 3
 
| 3
| Reinstallation
+
| Installing New Tickets
 +
|-
 +
| 4
 +
| Installing Titles
 +
|-
 +
| 5
 +
| Update Complete
 +
|-
 +
| 6
 +
| Failed - System Updates Disabled (Dev Units Only)
 +
|-
 +
| 7
 +
| ? (Only for background updates)
 +
|-
 +
| 8
 +
| ? (Only for background updates)
 +
|}
 +
 
 +
==TitleDownloadProgress==
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Offset
 +
!  Length
 +
!  Description
 +
|-
 +
| 0x00
 +
| 0x01
 +
| [[#TitleDownloadState|Title Download State]]
 +
|-
 +
| 0x01
 +
| 0x03
 +
| Padding
 +
|-
 +
| 0x04
 +
| 0x04
 +
| Last Operation Result Code
 +
|-
 +
| 0x08
 +
| 0x08
 +
| Downloaded Bytes
 +
|-
 +
| 0x10
 +
| 0x08
 +
| Total Bytes
 
|}
 
|}
==DownloadState==
+
 
 +
==TitleDownloadState==
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 317: Line 400:
 
|-
 
|-
 
| 0
 
| 0
| Not initialized
+
| Not Initialized
 
|-
 
|-
 
| 1
 
| 1
| Download initialized
+
| Starting Title Download
 
|-
 
|-
 
| 2
 
| 2
| Downloading, verifying and installing TMD
+
| Downloading and Installing TMD
 
|-
 
|-
 
| 3
 
| 3
| Initializing save data
+
| Committing TMD
 
|-
 
|-
 
| 4
 
| 4
| Downloading and installing contents
+
| Downloading and Installing Contents
 
|-
 
|-
 
| 5
 
| 5
| Waiting before calling [[AM:CommitImportPrograms]]
+
| Contents Installed
 
|-
 
|-
 
| 6
 
| 6
| Running [[AM:CommitImportPrograms]]
+
| [[AM:CommitImportPrograms|Committing Titles]]
 
|-
 
|-
 
| 7
 
| 7
| Title installation finished
+
| Finished
 
|-
 
|-
 
| 8
 
| 8
| Unknown error regarding title version
+
| ? (Unknown error regarding title version?)
 
|-
 
|-
 
| 9
 
| 9
| Creating the .ctx file (or error doing so)?
+
| ? (Creating the .ctx file (or error doing so)?)
 
|-
 
|-
 
| 10
 
| 10
| Irrecoverable error encountered
+
| Background Download Failed
 
|}
 
|}
==TitleConfig==
+
 
 +
==TitleDownloadConfig==
 +
 
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 356: Line 441:
 
!  Description
 
!  Description
 
|-
 
|-
| 0x0
+
| 0x00
| 0x8
+
| 0x08
 
| Title ID
 
| Title ID
 
|-
 
|-
| 0x8
+
| 0x08
| 0x4
+
| 0x04
 
| Title version
 
| Title version
 
|-
 
|-
| 0xC
+
| 0x0C
| 0x4
+
| 0x04
| Unknown (always 0)
+
| Unknown (always 0?)
 
|-
 
|-
 
| 0x10
 
| 0x10
| 0x1
+
| 0x01
| Age rating for the HOME Menu parental controls
+
| Age Rating (for HOME Menu parental controls)
 
|-
 
|-
 
| 0x11
 
| 0x11
| 0x1
+
| 0x01
 
| [[Filesystem_services#MediaType|Media Type]]
 
| [[Filesystem_services#MediaType|Media Type]]
 
|-
 
|-
 
| 0x12
 
| 0x12
| 0x2
+
| 0x02
 
| Padding
 
| Padding
 
|-
 
|-
 
| 0x14
 
| 0x14
| 0x4
+
| 0x04
 
| Unknown (always 0?)
 
| Unknown (always 0?)
 
|}
 
|}
==TitleProgress==
+
 
 +
==BackgroundTitleDownloadConfig==
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Offset
 +
!  Length
 +
!  Description
 +
|-
 +
| 0x000
 +
| 0x018
 +
| [[#TitleDownloadConfig|Title Download Config]]
 +
|-
 +
| 0x018
 +
| 0x001
 +
| Unknown
 +
|-
 +
| 0x019
 +
| 0x001
 +
| Unknown
 +
|-
 +
| 0x01A
 +
| 0x006
 +
| Padding
 +
|-
 +
| 0x020
 +
| 0x008
 +
| Requester Title ID
 +
|-
 +
| 0x028
 +
| 0x090
 +
| Title Name (UTF-16)
 +
|-
 +
| 0x0B8
 +
| 0x002
 +
| Title Name Forced NUL Terminator (always 0)
 +
|-
 +
| 0x0BA
 +
| 0x048
 +
| Developer Name (UTF-16)
 +
|-
 +
| 0x102
 +
| 0x002
 +
| Developer Name Forced NUL Terminator (always 0)
 +
|}
 +
 
 +
==BackgroundTitleDownloadTaskInfo==
 +
 
 
{| class="wikitable" border="1"
 
{| class="wikitable" border="1"
 
|-
 
|-
Line 391: Line 523:
 
!  Description
 
!  Description
 
|-
 
|-
| 0x0
+
| 0x000
| 0x4
+
| 0x104
| [[#DownloadState|Download State]]
+
| [[#BackgroundTitleDownloadConfig|Background Title Download Config]]
 
|-
 
|-
| 0x4
+
| 0x104
| 0x4
+
| 0x004
| Last result code in NIM related to the installation
+
| Padding
 
|-
 
|-
| 0x8
+
| 0x108
| 0x8
+
| 0x018
| Amount of bytes that have been downloaded
+
| [[#TitleDownloadProgress|Title Download Progress]]
 +
|}
 +
 
 +
==AutoTitleDownloadTaskInfos==
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Offset
 +
!  Length
 +
!  Description
 +
|-
 +
| 0x000
 +
| 0x008
 +
| Task ID
 +
|-
 +
| 0x008
 +
| 0x008
 +
| Title ID
 +
|-
 +
| 0x010
 +
| 0x004
 +
| Title Version
 +
|-
 +
| 0x014
 +
| 0x014
 +
| Unknown
 
|-
 
|-
| 0x10
+
| 0x028
| 0x8
+
| 0x008
| Total bytes that need to be downloaded
+
| Required Storage Space
 +
|-
 +
| 0x030
 +
| 0x004
 +
| Last Operation Result code
 +
|-
 +
| 0x034
 +
| 0x004
 +
| Last Operation Customer Support Code
 +
|-
 +
| 0x038
 +
| 0x090
 +
| Title Name (UTF-16)
 +
|-
 +
| 0x0C8
 +
| 0x002
 +
| Title Name Forced NUL Terminator (always 0)
 +
|-
 +
| 0x0CA
 +
| 0x048
 +
| Developer Name (UTF-16)
 +
|-
 +
| 0x112
 +
| 0x002
 +
| Developer Name Forced NUL Terminator (always 0)
 +
|-
 +
| 0x114
 +
| 0x024
 +
| Unknown
 +
|}
 +
 
 +
==InstallationMode==
 +
 
 +
{| class="wikitable" border="1"
 +
|-
 +
!  Value
 +
!  Description
 +
|-
 +
| 0
 +
| Initial Installation
 +
|-
 +
| 1
 +
| Unknown
 +
|-
 +
| 2
 +
| Unknown
 +
|-
 +
| 3
 +
| Re-installation
 
|}
 
|}

Revision as of 04:18, 3 March 2023

NIM updater service "nim:u"

Command Header Description
0x00010000 StartNetworkUpdate
0x00020000 GetProgress
0x00030000 Cancel
0x00040000 CommitSystemTitles
0x00050000 GetBackgroundEventForMenu
0x00060000 GetBackgroundEventForNews
0x00070000 FormatSaveData
0x00080000 GetCustomerSupportCode
0x00090000 IsCommittableAllSystemTitles
0x000A0000 GetBackgroundProgress
0x000B0000 GetSavedHash
0x000C0082 UnregisterTask
0x000D0080 IsRegistered
0x000E0080 FindTaskInfo
0x000F0042 GetTaskInfos
0x00100000 DeleteUnmanagedContexts
0x00110000 UpdateAutoTitleDownloadTasksAsync
0x00120000 StartPendingAutoTitleDownloadTasksAsync
0x00130000 GetAsyncResult
0x00140000 CancelAsyncCall
0x00150000 IsPendingAutoTitleDownloadTasks
0x00160000 GetNumAutoTitleDownloadTasks
0x00170042 GetAutoTitleDownloadTaskInfos
0x00180080 CancelAutoTitleDownloadTask
0x00190002 SetAutoDbgDat
0x001A0002 GetAutoDbgDat
0x001B0042 SetDbgTasks
0x001C0042 GetDbgTasks
0x001D0000 DeleteDbgData
0x001E0042 SetTslXml
0x001F0000 GetTslXmlSize
0x00200042 GetTslXml
0x00210000 DeleteTslXml
0x00220042 SetDtlXml
0x00230000 GetDtlXmlSize
0x00240042 GetDtlXml
0x00250000 UpdateAccountStatus
0x00260180 StartTitleDownload
0x00270000 StopTitleDownload
0x00280000 GetTitleDownloadProgress
0x00290246 RegisterTask
0x002A0000 IsSystemUpdateAvailable
0x002B0000 ? (Response: 0 = 0x002B0040, 1 = Result Code)
0x002C0000 UpdateTickets
0x002D00C0 DownloadTitleSeedAsync
0x002E0000 DownloadMissingTitleSeedsAsync

NIM server service "nim:s"

Command Header Description
0x00010200 StartDownloadSimple
0x00020000 CancelDownload
0x00030000 GetProgress
0x00050082 UnregisterTask
0x00060080 IsTaskRegistered
0x000A0000 CheckSysupdateAvailableSOAP
0x000B0084 SetAttribute
0x0016020A ListTitles
0x00220080 AccountDeleteTitleETicketsSOAP. The SOAP request is sent only after the ticket for the specified titleID has been successfully deleted.
0x00290000 AccountCheckBalanceSOAP
0x002D0042 DownloadTickets
0x003C0002 RegisterSelf
0x003F0000 GetInitializeResult. Checks whether nim is properly initialized or not. If it is not, the result code returned is non-zero.
0x00420240 StartDownload
0x00550246 RegisterTask
0x00570082 ConnectNoTicketDownload

NIM server service "nim:aoc"

Command Header Description
0x00030042 SetApplicationId
0x00040042 SetTin
0x000902D0 ListContentSetsEx
0x00180000 GetBalance
0x001D0000 GetCustomerSupportCode
0x00210000 Initialize
0x00240282 CalculateContentsRequiredSize
0x00250000 RefreshServerTime

NIM service "nim:ndm"

kagiya server

The nim system module communicates with a server called kagiya (kagiya-ctr.cdn.nintendo.net or kagiya-dev-ctr.cdn.nintendo.net for development units). It provides the 9.6 crypto seed in binary form for any given title ID under (HTTPS) kagiya-ctr.cdn.nintendo.net/title/0x%16llx/ext_key?country=%s, where %16llx is the title ID and %s is a country code as used in the eShop.

New3DS

NIM module only uses CheckNew3DS for determining what heap sizes to use, in two functions. One is for the size of the 0x08000000 vmem heap, the other is probably for some buffer allocated on that heap. The New3DS version of these sizes are 0x1C000-bytes larger than the Old3DS sizes here.

HTTPS requests

Trusted RootCAs

During startup NIM-module creates two RootCertChains with HTTPC. Both of these only contain the same default cert with ID 0x3. The first RootCertChain is used with NetUpdateSOAP. Requests such as the "notifications.json" page don't use these RootCertChains(in this case just default certID 0xB is used).

SOAP

NetUpdateSOAP

There are exactly 3 types of network SOAP requests used with NetUpdateSOAP by NIM module, described below. This URL contained in NIM module itself is only used with GetSystemTitleHash. The other requests use an identical URL loaded from an ECommerceSOAP response instead.

See also here.

GetSystemUpdate

Returns the current sysupdate title-listing. This also contains the SystemTitleHash returned by GetSystemTitleHash.

GetSystemTitleHash

Returns the current SystemTitleHash for the current sysupdate title-listing.

GetSystemCommonETicket

Returns the Base64-encoded cetk for each specified TitleId entry.

This is only used when installing new titles. This means with CDN system-updates, tickets are never installed except when a title is being installed for the first time. For example, a system on the latest system-version that was only ever updated via CDN has the same NATIVE_FIRM ticket installed from the factory.

Sysupdate checking process

This section describes the process used when checking whether a sysupdate is required.

First the GetSystemTitleHash SOAP request is done. Then the SystemTitleHash in savedata hash.dat is compared with the received one. If they match and the SystemTitleHash flag is set to value 0x03, it will immediately return that no sysupdate is required. Otherwise it will start the GetSystemUpdate SOAP request handling.

The GetSystemUpdate SOAP request contains a titlelist of all NAND system-titles. For GetSystemUpdate response parsing, it compares each SOAP title_entry with the NAND system titlelist. If a SOAP titleID isn't found in the NAND titlelist, this means NAND is missing a new title and hence a sysupdate is required for installing that title. If a NAND title_entry-version is less than the SOAP title_entry-version, this means the title needs updated and hence a sysupdate is required.

At least one <TitleVersion> entry with valid data in the GetSystemUpdate response is required.

The titleIDs sent in the GetSystemUpdate SOAP request are decimal, while the titleIDs in the response are hex.

NIM System_SaveData

hash.dat

Offset Size Description
0x60 0x1 u8 flag used with the SystemTitleHash. 0x01 = latest sysupdate isn't installed as of last SOAP requests, 0x03 = latest sysupdate is installed as of last SOAP requests.
0x61 0x21 ASCII hex SystemTitleHash, including NUL-terminator. This is the latest SystemTitleHash which NIM module received from SOAP.

Types

SystemUpdateProgress

Offset Length Description
0x00 0x01 System Update State
0x01 0x03 Padding
0x04 0x04 Last Operation Result Code
0x08 0x08 Current Title Downloaded Bytes
0x10 0x08 Current Title Total Bytes
0x18 0x08 Titles Downloaded
0x20 0x08 Titles Total

SystemUpdateState

Value Description
0 Not Initialized
1 Starting System Update
2 Fetching System Hash and Account Status
3 Installing New Tickets
4 Installing Titles
5 Update Complete
6 Failed - System Updates Disabled (Dev Units Only)
7 ? (Only for background updates)
8 ? (Only for background updates)

TitleDownloadProgress

Offset Length Description
0x00 0x01 Title Download State
0x01 0x03 Padding
0x04 0x04 Last Operation Result Code
0x08 0x08 Downloaded Bytes
0x10 0x08 Total Bytes

TitleDownloadState

Value Description
0 Not Initialized
1 Starting Title Download
2 Downloading and Installing TMD
3 Committing TMD
4 Downloading and Installing Contents
5 Contents Installed
6 Committing Titles
7 Finished
8 ? (Unknown error regarding title version?)
9 ? (Creating the .ctx file (or error doing so)?)
10 Background Download Failed

TitleDownloadConfig

Offset Length Description
0x00 0x08 Title ID
0x08 0x04 Title version
0x0C 0x04 Unknown (always 0?)
0x10 0x01 Age Rating (for HOME Menu parental controls)
0x11 0x01 Media Type
0x12 0x02 Padding
0x14 0x04 Unknown (always 0?)

BackgroundTitleDownloadConfig

Offset Length Description
0x000 0x018 Title Download Config
0x018 0x001 Unknown
0x019 0x001 Unknown
0x01A 0x006 Padding
0x020 0x008 Requester Title ID
0x028 0x090 Title Name (UTF-16)
0x0B8 0x002 Title Name Forced NUL Terminator (always 0)
0x0BA 0x048 Developer Name (UTF-16)
0x102 0x002 Developer Name Forced NUL Terminator (always 0)

BackgroundTitleDownloadTaskInfo

Offset Length Description
0x000 0x104 Background Title Download Config
0x104 0x004 Padding
0x108 0x018 Title Download Progress

AutoTitleDownloadTaskInfos

Offset Length Description
0x000 0x008 Task ID
0x008 0x008 Title ID
0x010 0x004 Title Version
0x014 0x014 Unknown
0x028 0x008 Required Storage Space
0x030 0x004 Last Operation Result code
0x034 0x004 Last Operation Customer Support Code
0x038 0x090 Title Name (UTF-16)
0x0C8 0x002 Title Name Forced NUL Terminator (always 0)
0x0CA 0x048 Developer Name (UTF-16)
0x112 0x002 Developer Name Forced NUL Terminator (always 0)
0x114 0x024 Unknown

InstallationMode

Value Description
0 Initial Installation
1 Unknown
2 Unknown
3 Re-installation