NS services: Difference between revisions

 
(25 intermediate revisions by the same user not shown)
Line 406: Line 406:
These are "nn::ns::detail::IServiceGetterInterface".
These are "nn::ns::detail::IServiceGetterInterface".


These commands check a state field for a command-specific bit and returns an error if not set, this is likely a permissions check for service+command.
These commands check a state field for a command-specific bit and returns an error if not set, this is a permissions check for service+command.


[11.0.0+] ns:ro was added.
[11.0.0+] ns:ro was added.
Line 414: Line 414:
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
! Cmd || Name
! Cmd || Name || Permission bit
|-
| 7988 || [6.0.0+] [[#IDynamicRightsInterface|GetDynamicRightsInterface]] || 10
|-
| 7989 || [5.1.0+] [[#IReadOnlyApplicationControlDataInterface|GetReadOnlyApplicationControlDataInterface]] || 9
|-
| 7991 || [5.0.0+] [[#IReadOnlyApplicationRecordInterface|GetReadOnlyApplicationRecordInterface]] || 8
|-
| 7992 || [4.0.0+] [[#IECommerceInterface|GetECommerceInterface]] || 7
|-
| 7993 || [4.0.0+] [[#IApplicationVersionInterface|GetApplicationVersionInterface]] || 6
|-
| 7994 || [[#IFactoryResetInterface|GetFactoryResetInterface]] || 5
|-
| 7995 || [[#IAccountProxyInterface|GetAccountProxyInterface]] || 4
|-
| 7996 || [[#IApplicationManagerInterface|GetApplicationManagerInterface]] || 3
|-
|-
| 7988 || [6.0.0+] [[#IDynamicRightsInterface|GetDynamicRightsInterface]]
| 7997 || [[#IDownloadTaskInterface|GetDownloadTaskInterface]] || 1
|-
|-
| 7989 || [5.1.0+] [[#IReadOnlyApplicationControlDataInterface|GetReadOnlyApplicationControlDataInterface]]
| 7998 || [[#IContentManagementInterface|GetContentManagementInterface]] || 0
|-
|-
| 7991 || [5.0.0+] [[#IReadOnlyApplicationRecordInterface|GetReadOnlyApplicationRecordInterface]]
| 7999 || [[#IDocumentInterface|GetDocumentInterface]] || 2
|}
 
Permissions state field with each service:
 
{| class="wikitable" border="1"
|-
|-
| 7992 || [4.0.0+] [[#IECommerceInterface|GetECommerceInterface]]
! Service || Permissions
|-
|-
| 7993 || [4.0.0+] [[#IApplicationVersionInterface|GetApplicationVersionInterface]]
| ns:web || 0x304
|-
|-
| 7994 || [[#IFactoryResetInterface|GetFactoryResetInterface]]
| ns:ec || 0x83
|-
|-
| 7995 || [[#IAccountProxyInterface|GetAccountProxyInterface]]
| ns:sweb || 0x387
|-
|-
| 7996 || [[#IApplicationManagerInterface|GetApplicationManagerInterface]]
| ns:rid || 0x10
|-
|-
| 7997 || [[#IDownloadTaskInterface|GetDownloadTaskInterface]]
| ns:rt || 0x20
|-
|-
| 7998 || [[#IContentManagementInterface|GetContentManagementInterface]]
| ns:ro || 0x301
|-
|-
| 7999 || [[#IDocumentInterface|GetDocumentInterface]]
| ns:am2 || 0x7FF
|}
|}


Line 649: Line 670:
|-
|-
| 307 || TerminateOverlayApplet
| 307 || TerminateOverlayApplet
|-
| 308 || [S2]
|-
| 309 || [S2]
|-
|-
| 400 || [[#GetApplicationControlData]]
| 400 || [[#GetApplicationControlData]]
Line 667: Line 692:
|-
|-
| 408 || [8.0.0+] [[#ListApplicationIcon]]
| 408 || [8.0.0+] [[#ListApplicationIcon]]
|-
| 409 || [S2]
|-
| 410 || [S2]
|-
|-
| 411 || [19.0.0+]
| 411 || [19.0.0+]
Line 817: Line 846:
|-
|-
| 923 || [20.0.0+]
| 923 || [20.0.0+]
|-
| 924 || [S2]
|-
| 925 || [S2]
|-
| 926 || [S2]
|-
| 927 || [S2]
|-
|-
| 928 || [20.0.0+]
| 928 || [20.0.0+]
Line 1,132: Line 1,169:
| 3050 || [14.0.0+] ListAssignELicenseTaskResult
| 3050 || [14.0.0+] ListAssignELicenseTaskResult
|-
|-
| 3100 || [17.0.0+] GetSafeSystemVersionCheckInfo
| 3100 || [17.0.0+] [[#GetSafeSystemVersionCheckInfo|GetSafeSystemVersionCheckInfo]]
|-
|-
| 3101 || [17.0.0+] RequestUpdateSafeSystemVersionCheckInfo
| 3101 || [17.0.0+] [[#RequestUpdateSafeSystemVersionCheckInfo|RequestUpdateSafeSystemVersionCheckInfo]]
|-
|-
| 3102 || [17.0.0+] ResetSafeSystemVersionCheckInfo
| 3102 || [17.0.0+] [[#ResetSafeSystemVersionCheckInfo|ResetSafeSystemVersionCheckInfo]]
|-
|-
| 3104 || [18.0.0+] GetApplicationNintendoLogo
| 3104 || [18.0.0+] GetApplicationNintendoLogo
|-
|-
| 3105 || [18.0.0+] GetApplicationStartupMovie
| 3105 || [18.0.0+] GetApplicationStartupMovie
|-
| 3150 || [S2]
|-
|-
| 4000 || [20.0.0+]
| 4000 || [20.0.0+]
Line 1,393: Line 1,432:
==== GetRequestServerStopper ====
==== GetRequestServerStopper ====
No input, returns an output [[#IRequestServerStopper]].
No input, returns an output [[#IRequestServerStopper]].
This increfs a state ref-count, with decref being handled when the object is closed. This ref-count is checked by [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]] and related cmds.


==== CancelApplicationApplyDelta ====
==== CancelApplicationApplyDelta ====
Line 1,664: Line 1,705:
This determines the latest version (RequiredSystemVersion) from the input [[#ApplicationDeliveryInfo]] array (ApplicationDeliveryProtocolVersion and the HMAC are also validated), using value 0 if the array is empty.
This determines the latest version (RequiredSystemVersion) from the input [[#ApplicationDeliveryInfo]] array (ApplicationDeliveryProtocolVersion and the HMAC are also validated), using value 0 if the array is empty.


[20.0.0+] When the SystemDeliveryInfoPlatform from the type-0x15 [[#SystemDeliveryInfo]] buffer matches the [[System_Settings|sys-setting]], it then loops through the [[#ApplicationDeliveryInfo]] array again:
* [20.0.0+] The following code block now only runs when the SystemDeliveryInfoPlatform from the type-0x15 [[#SystemDeliveryInfo]] buffer matches the [[System_Settings|sys-setting]].
* A func is called with the [[#ApplicationDeliveryInfo]], returning error if this fails. This func essentially uses [[Shared_Database_services|pl:s]] GetFunctionBlackListSystemVersionToAuthorize with ApplicationFunctionAuthorizationId=0x5 and parses the output, using cached data if available.
** It then loops through the [[#ApplicationDeliveryInfo]] array again:
* tmp_version = out_u8 == 0 ? 0 : out_u32 + 0x10000;
** This uses functionality which essentially uses [[Shared_Database_services|pl:s]] GetFunctionBlackListSystemVersionToAuthorize with the [[#ApplicationDeliveryInfo]] ApplicationId and ApplicationFunctionAuthorizationId=0x5 then parses the output, using cached data if available. The error is returned on failure.
* Then the current latest-version value is updated with tmp_version, if tmp_version is higher.
** tmp_version = out_u8 == 0 ? 0 : out_u32 + 0x10000;
** Then the current latest-version value is updated with tmp_version, if tmp_version is higher.


If this version value is less than a state field, the state field value is used instead (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).
If this version value is less than a state field, the state field value is used instead (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).


Then this selects a [[#SystemDeliveryInfo]] with the latest version from the input array, where the minimum version is the previously mentioned value. The version must also be also be at least the version value from the type-0x15 [[#SystemDeliveryInfo]] buffer. This also does various validation, etc. The output s32 is an index in that array for the selected entry, -1 if none found.
Then this selects the [[#SystemDeliveryInfo]] with the latest version from the input array. The output s32 is an index in that array for the selected entry, -1 if none found.
 
During the above loop it first calls the [[#SystemDeliveryInfo]] validation func, returning the Result on failure. Then it runs additional validation, with the [[#SystemDeliveryInfo]] entry being ignored on failure:
* The above latest-version value must be at least the version value from the type-0x15 [[#SystemDeliveryInfo]] buffer and the [[#SystemDeliveryInfo]] array entry.
* When HasExFat is set in the type-0x15 [[#SystemDeliveryInfo]] buffer, it must be set in the [[#SystemDeliveryInfo]] array entry.
* FirmwareVariationId in the type-0x15 [[#SystemDeliveryInfo]] buffer must not be 0xFF.
* UpdatableFirmwareGroupId in the [[#SystemDeliveryInfo]] array entry must not be 0xFF. The value must be within bounds of the settings array ([[System_Settings|sys-settings]] <code>contents_delivery!updatable_firmware_group_string</code>).
* PlatformRegion in the [[#SystemDeliveryInfo]] array entry and the type-0x15 [[#SystemDeliveryInfo]] buffer must match.
* Lastly when the following is true, this indicates success: (settings_array[UpdatableFirmwareGroupId] >> {above FirmwareVariationId}) & 1.


==== VerifyDeliveryProtocolVersion ====
==== VerifyDeliveryProtocolVersion ====
Takes a type-0x15 input buffer containing a [[#SystemDeliveryInfo]], no output.
Takes a type-0x15 input buffer containing a [[#SystemDeliveryInfo]], no output.


This validates the [[#SystemDeliveryInfo]] HMAC and the protocol-version fields. Then an error is returned when SystemUpdateMetaVersion is less than a state field, otherwise 0 is returned (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).
This validates the [[#SystemDeliveryInfo]] HMAC and the protocol-version fields. Then an error is returned when SystemUpdateVersion is less than a state field, otherwise 0 is returned (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).


==== GetApplicationDeliveryInfo ====
==== GetApplicationDeliveryInfo ====
Line 1,685: Line 1,735:
An error is thrown if any bit is set in ApplicationDeliveryAttributeTag besides bit1, this must also be <=0x3. The output array-count must be at least 1: only 1 entry will be written to this array (hence on success total_out will also only be 1 on success).
An error is thrown if any bit is set in ApplicationDeliveryAttributeTag besides bit1, this must also be <=0x3. The output array-count must be at least 1: only 1 entry will be written to this array (hence on success total_out will also only be 1 on success).


An error is thrown if a state ref-count is zero.
[7.0.0+] An error is thrown if the state ref-count for [[#GetRequestServerStopper|RequestServerStopper]] is zero. [7.0.0-7.0.1] The func which checks this would also return success when a field prior to the previously mentioned field is 0 (checked before the ref-count).


An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.
An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.
Line 1,706: Line 1,756:
This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].
This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].


After validating the [[#ApplicationDeliveryInfo]], the output bool is set to u32 [[#ApplicationDeliveryInfo]]+0x1C & 0x10000002 != 0x2, then this returns 0.
After validating the [[#ApplicationDeliveryInfo]], the output bool is set to [[#ApplicationDeliveryInfo|ApplicationDeliveryAttributeTag]] & 0x10000002 != 0x2, then this returns 0.


==== CompareApplicationDeliveryInfo ====
==== CompareApplicationDeliveryInfo ====
Line 1,724: Line 1,774:
This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].
This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].


The second [[#ApplicationDeliveryInfo]] buffer is validated. An error is thrown when u32 [[#ApplicationDeliveryInfo]] (second buffer) +0x1C & 0x3 != 0x2, likewise when bit28 is clear in this field (bitmask 0x10000000).
The second [[#ApplicationDeliveryInfo]] buffer is validated. An error is thrown when [[#ApplicationDeliveryInfo|ApplicationDeliveryAttributeTag]] (second buffer) & 0x3 != 0x2, likewise when bit28 is clear in this field (bitmask 0x10000000).


The array-count for the first buffer must be <=1, otherwise an error is returned. If the array-count for the first buffer is 0, this will return 0 with the output bool set to 0. The first [[#ApplicationDeliveryInfo]] buffer is validated. An error is thrown when u32 [[#ApplicationDeliveryInfo]] (first buffer) +0x1C bit1 is clear or bit0 set. An error is thrown when u32 [[#ApplicationDeliveryInfo]] (second buffer) +0x1C bit1 is clear.
The array-count for the first buffer must be <=1, otherwise an error is returned. If the array-count for the first buffer is 0, this will return 0 with the output bool set to 0. The first [[#ApplicationDeliveryInfo]] buffer is validated. An error is thrown when [[#ApplicationDeliveryInfo|ApplicationDeliveryAttributeTag]] (first buffer) bit1 is clear or bit0 set. An error is thrown when [[#ApplicationDeliveryInfo|ApplicationDeliveryAttributeTag]] (second buffer) bit1 is clear.


When u32 [[#ApplicationDeliveryInfo]] (first or second buffer) +0x14 is higher than [[#ApplicationDeliveryInfo]] (second buffer) ApplicationVersion, this will return 0 with the output bool set to 0.
When [[#ApplicationDeliveryInfo|RequiredApplicationVersion]] (first or second buffer) is higher than [[#ApplicationDeliveryInfo|ApplicationVersion]] (second buffer), this will return 0 with the output bool set to 0.


When u32 [[#ApplicationDeliveryInfo]] (first buffer) +0x1C bit28 is set (bitmask 0x10000000):
When [[#ApplicationDeliveryInfo|ApplicationDeliveryAttributeTag]] (first buffer) bit28 is set (bitmask 0x10000000):
* When [[#ApplicationDeliveryInfo]] (first buffer) ApplicationVersion >= [[#ApplicationDeliveryInfo]] (second buffer) ApplicationVersion, write 0 to the output bool, otherwise write 1. Then return 0.
* When [[#ApplicationDeliveryInfo|ApplicationVersion]] (first buffer) >= [[#ApplicationDeliveryInfo|ApplicationVersion]] (second buffer), write 0 to the output bool, otherwise write 1. Then return 0.
Otherwise when the above bit28 is clear:
Otherwise when the above bit28 is clear:
* When [[#ApplicationDeliveryInfo]] (first buffer) ApplicationVersion > [[#ApplicationDeliveryInfo]] (second buffer) ApplicationVersion, write 0 to the output bool, otherwise write 1. Then return 0.
* When [[#ApplicationDeliveryInfo|ApplicationVersion]] (first buffer) > [[#ApplicationDeliveryInfo|ApplicationVersion]] (second buffer), write 0 to the output bool, otherwise write 1. Then return 0.


==== ListContentMetaKeyToDeliverApplication ====
==== ListContentMetaKeyToDeliverApplication ====
Line 1,754: Line 1,804:


This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].
This uses the same LocalContentShare check as [[#GetApplicationDeliveryInfo|GetApplicationDeliveryInfo]].
The [[#SystemDeliveryInfo]] is validated (validation for ApplicationDeliveryProtocolVersion is enabled).


The array-count must match 1.
The array-count must match 1.


After validation etc, this sets the output bool by comparing system-version fields in the [[#SystemDeliveryInfo]]/[[#ApplicationDeliveryInfo]] and with a state field (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).
The [[#ApplicationDeliveryInfo]] is validated (ApplicationDeliveryProtocolVersion/HMAC).


[20.0.0+] More validation was added.
This then runs functionality similar to [[#SelectLatestSystemDeliveryInfo]]:
* [20.0.0+] The following code block now only runs when the SystemDeliveryInfoPlatform from the input [[#SystemDeliveryInfo]] matches the [[System_Settings|sys-setting]].
* Uses the same functionality as [[#SelectLatestSystemDeliveryInfo]] for GetFunctionBlackListSystemVersionToAuthorize, returning the Result on failure.
* The output bool is set to: out_u8!=0 && out_u32 >= [[#SystemDeliveryInfo]] SystemUpdateVersion (only the upper 16bits are used from the SystemUpdateVersion).


[20.0.0+] Prior to comparing the system-version fields, this now runs additional functionality similar to [[#SelectLatestSystemDeliveryInfo]]:
Otherwise when the output bool is still false, this sets the output bool by comparing system-version fields in the [[#SystemDeliveryInfo]]/[[#ApplicationDeliveryInfo]] and with a state field (state field originates from [[System_Settings|system-setting]] <code>contents_delivery!required_system_version_to_deliver_application</code>).
* When the SystemDeliveryInfoPlatform from the input [[#SystemDeliveryInfo]] matches the [[System_Settings|sys-setting]], it does the following:
* Calls the same func as [[#SelectLatestSystemDeliveryInfo]] for GetFunctionBlackListSystemVersionToAuthorize, returning the Result on failure.
* The output bool is set to: out_u8!=0 && out_u32 >= [[#SystemDeliveryInfo]] SystemUpdateMetaVersion (only the upper 16bits are used from the SystemUpdateMetaVersion).


==== EstimateRequiredSize ====
==== EstimateRequiredSize ====
Line 1,782: Line 1,834:
HasApplicationRecord is called with the input [[NCM_services#ApplicationId|ApplicationId]], an error is returned if the record isn't found.
HasApplicationRecord is called with the input [[NCM_services#ApplicationId|ApplicationId]], an error is returned if the record isn't found.


This loops through the input [[NCM_services#ContentMetaKey|ContentMetaKey]] array, throwing an error if the [[NCM_services#ContentMetaType|ContentMetaType]] doesn't match Patch. The input array is copied into state which is used later by the thread for [[NIM_services|nim]] cmd53, max entries is 0x12.
This loops through the input [[NCM_services#ContentMetaKey|ContentMetaKey]] array, throwing an error if the [[NCM_services#ContentMetaType|ContentMetaType]] doesn't match Patch. The input array is copied into state which is used later by the thread for [[NIM_services|nim]] CreateLocalCommunicationReceiveApplicationTask, max entries is 0x12.


This does various setup then creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation. Then the thread does:
This does various setup then creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation. Then the thread does:
Line 1,788: Line 1,840:
* Calls a func which does:
* Calls a func which does:
** Throws an error if a state flag is set.
** Throws an error if a state flag is set.
** Uses [[NIM_services|nim]] cmd53, returning the Result on failure.
** Uses [[NIM_services|nim]] CreateLocalCommunicationReceiveApplicationTask, returning the Result on failure.
** Uses [[NIM_services|nim]] cmd56, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
** Uses [[NIM_services|nim]] RequestLocalCommunicationReceiveApplicationTaskRun, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
** Handles cleanup and returns.
** Handles cleanup and returns.
Line 1,819: Line 1,871:
An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.
An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.


Uses [[NIM_services|nim]] cmd67, throwing an error if no task is returned. Then [[NIM_services|nim]] cmd57 is used, returning the error from there on failure. Lastly, this writes the 0x10-bytes from output+8 from the latter cmd to the output [[#ReceiveApplicationProgress]], and returns 0.
Uses [[NIM_services|nim]] ListApplicationLocalCommunicationReceiveApplicationTask, throwing an error if no task is returned. Then [[NIM_services|nim]] GetLocalCommunicationReceiveApplicationTaskInfo is used, returning the error from there on failure. Lastly, this writes the 0x10-bytes from output+8 from the latter cmd to the output [[#ReceiveApplicationProgress]], and returns 0.


==== RequestSendApplication ====
==== RequestSendApplication ====
Line 1,830: Line 1,882:
An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.
An error is thrown if [[NIM_services|nim]] ListApplicationApplyDeltaTask returns a task.


The [[NCM_services#ContentMetaType|ContentMetaType]] in the ContentMetaKey must match Patch.
This does various setup and loops through the input ContentMetaKey array for initializing the array passed to the nim cmd during the async task. This loop does the following:
* Throws an error if the [[NCM_services#ContentMetaType|ContentMetaType]] in the ContentMetaKey doesn't match Patch.
* Calls a func with the ContentMetaKey and the ApplicationId, throwing an error if the output value is 0.
* Calls a func with the ContentMetaKey for getting the StorageId. This essentially loops through each valid ncm [[NCM_services|IContentMetaDatabase]] using cmd [[NCM_services|Has]] with the input ContentMetaKey, returning the relevant StorageId when found.
* The ContentMetaKey and the StorageId are copied into a tmp struct.
* if (ContentMetaType==Patch && StorageId==GameCard) { <call a func etc> }
* Copies the above tmp struct into the async task state array.


This does various setup and loops through the input ContentMetaKey array for initializing the array passed to the nim cmd during the async task. This then creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation. Then the thread does:
This then creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation. Then the thread does:


* Calls a func which does:
* Calls a func which does:
** Throws an error if a state flag is set.
** Throws an error if a state flag is set.
** Uses [[NIM_services|nim]] cmd60, returning the Result on failure.
** Uses [[NIM_services|nim]] CreateLocalCommunicationSendApplicationTask, returning the Result on failure.
** Uses [[NIM_services|nim]] cmd61, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
** Uses [[NIM_services|nim]] RequestLocalCommunicationSendApplicationTaskRun, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
** Handles cleanup and returns.
** Handles cleanup and returns.
Line 1,851: Line 1,909:
Takes an input [[NCM_services#ApplicationId|ApplicationId]], returns an output [[#SendApplicationProgress]].
Takes an input [[NCM_services#ApplicationId|ApplicationId]], returns an output [[#SendApplicationProgress]].


Same as [[#GetReceiveApplicationProgress]] except this is the Send version, and uses [[NIM_services|nim]] cmd68/cmd63 instead. The data copied to output is also swapped: u64 nim_out+0x8 is copied to out+0x8, and u64 nim_out+0x10 is copied to out+0x0.
Same as [[#GetReceiveApplicationProgress]] except this is the Send version, and uses [[NIM_services|nim]] ListApplicationLocalCommunicationSendApplicationTask/GetLocalCommunicationSendApplicationTaskInfo instead. The data copied to output is also swapped: u64 nim_out+0x8 is copied to out+0x8, and u64 nim_out+0x10 is copied to out+0x0.


==== CompareSystemDeliveryInfo ====
==== CompareSystemDeliveryInfo ====
Line 1,892: Line 1,950:
** Uses [[Shared_Database_services|pl:s]] RequestApplicationFunctionAuthorizationByApplicationId with the [[#ApplicationDeliveryInfo]] ApplicationId/ApplicationVersion and ApplicationFunctionAuthorizationId=0x5, handling the Result on failure.
** Uses [[Shared_Database_services|pl:s]] RequestApplicationFunctionAuthorizationByApplicationId with the [[#ApplicationDeliveryInfo]] ApplicationId/ApplicationVersion and ApplicationFunctionAuthorizationId=0x5, handling the Result on failure.
* When the platform fields from the input [[#SystemDeliveryInfo]]/[[#ApplicationDeliveryInfo]] match, write 1 to the output bool and return 0. Otherwise:
* When the platform fields from the input [[#SystemDeliveryInfo]]/[[#ApplicationDeliveryInfo]] match, write 1 to the output bool and return 0. Otherwise:
** When the [[#SystemDeliveryInfo]] SystemDeliveryInfoPlatform is 0x1 (Ounce): *output = [[#ApplicationDeliveryInfo]] ContentMetaPlatform == 0 && [[#ApplicationDeliveryInfo]] ProperProgramExists == 0;
** When the [[#SystemDeliveryInfo]] SystemDeliveryInfoPlatform is 0x1 (Ounce): *output = [[#ApplicationDeliveryInfo|ContentMetaPlatform]] == 0 && [[#ApplicationDeliveryInfo|ProperProgramExists]] == 0;
** When the [[#SystemDeliveryInfo]] SystemDeliveryInfoPlatform is 0x0 (NX): write 0 to the output bool and return 0.
** When the [[#SystemDeliveryInfo]] SystemDeliveryInfoPlatform is 0x0 (NX): write 0 to the output bool and return 0.
** Otherwise, Abort.
** Otherwise, Abort.
Line 2,251: Line 2,309:
|-
|-
| 92 || [5.0.0+] GetRunningApplicationProgramId
| 92 || [5.0.0+] GetRunningApplicationProgramId
|-
| 100 || [S2]
|-
| 101 || [S2]
|-
|-
| 2524 || [19.0.0+]  
| 2524 || [19.0.0+]  
|}
|}
==== Cmd100 ====
Takes a type-0x16 output buffer containing a 0x300-byte struct, an input u8, an u64. Returns two output u8s.
==== Cmd101 ====
Takes a type-0x16 output buffer containing a 0x300-byte struct, an input u8, an u64. Returns an output u8, an u8 [[Filesystem_services|ContentAttributes]], and a [[NCM_services#ProgramId|ProgramId]].
This is similar to Cmd2524. On [S2] this is used instead of Cmd2524.
==== Cmd2524 ====
Takes a type-0x16 output buffer containing a 0x300-byte struct, an input u8, an u64. Returns an output u8 [[Filesystem_services|ContentAttributes]] and a [[NCM_services#ProgramId|ProgramId]].
The user-process uses the output from this as the input for [[Filesystem_services|OpenFileSystemWithId]] (out-buffer is used as the [[Filesystem_services|FspPath]]).


=== IDownloadTaskInterface ===
=== IDownloadTaskInterface ===
Line 2,324: Line 2,399:
| 2 || [10.0.0+] IsDataCorruptedResult ||
| 2 || [10.0.0+] IsDataCorruptedResult ||
|-
|-
| 3 || [20.0.0+] ||
| 3 || [20.0.0+] [[#ListApplicationRecord|ListApplicationRecord]] ||
|}
|}


Line 2,657: Line 2,732:
| 1202 || [4.0.0+] [[#GetSafeSystemVersion]]
| 1202 || [4.0.0+] [[#GetSafeSystemVersion]]
|-
|-
| 3100 || [18.0.0+]  
| 3100 || [18.0.0+] [[#GetSafeSystemVersionCheckInfo|GetSafeSystemVersionCheckInfo]]
|-
|-
| 3101 || [18.0.0+]  
| 3101 || [18.0.0+] [[#RequestUpdateSafeSystemVersionCheckInfo|RequestUpdateSafeSystemVersionCheckInfo]]
|-
|-
| 3102 || [18.0.0+]  
| 3102 || [18.0.0+] [[#ResetSafeSystemVersionCheckInfo|ResetSafeSystemVersionCheckInfo]]
|}
|}


Line 2,667: Line 2,742:
No input, returns an output u8 bool flag.
No input, returns an output u8 bool flag.


Web-applets use this command to check if the system needs an update.
[S1] Web-applets use this command to check if the system needs an update.


== UpdateSafeSystemVersionForDebug ==
== UpdateSafeSystemVersionForDebug ==
Takes an input [[NCM_services#ApplicationId|ApplicationId]] and an u32 '''version'''.
Takes an input u32 '''version''' and an [[NCM_services#ApplicationId|ApplicationId]].


This command is not available for retail units. On a debug unit, if the [[System_Settings|system setting]] <code>vulnerability!enable_debug</code> is set, this mounts the system savegame [[Flash_Filesystem#System_Savegames|0x8000000000000049]] as "ns_ssversion:/", opens the file "ns_ssversion:/entry" and writes the supplied [[NCM_services#ApplicationId|ApplicationId]] and '''version''' in it.
This command is not available for retail units. On a debug unit, if the [[System_Settings|system setting]] <code>vulnerability!enable_debug</code> is set, this mounts the system savegame [[Flash_Filesystem#System_Savegames|0x8000000000000049]] as "ns_ssversion:/", opens the file "ns_ssversion:/entry" and writes the supplied [[NCM_services#ApplicationId|ApplicationId]] and '''version''' in it.
Line 2,680: Line 2,755:
== GetSafeSystemVersion ==
== GetSafeSystemVersion ==
No input, returns an output [[NCM_services#ContentMetaKey|ContentMetaKey]] with the cached contents of "ns_ssversion:/entry" ([[NCM_services#ApplicationId|ApplicationId]], u32 '''version''' and u32 '''policy''' from <code>vulnerability!needs_update_vulnerability_policy</code>).
No input, returns an output [[NCM_services#ContentMetaKey|ContentMetaKey]] with the cached contents of "ns_ssversion:/entry" ([[NCM_services#ApplicationId|ApplicationId]], u32 '''version''' and u32 '''policy''' from <code>vulnerability!needs_update_vulnerability_policy</code>).
== GetSafeSystemVersionCheckInfo ==
No input, returns 0x10-bytes of output.
[S2] Used by web-applets via ns:vm.
== RequestUpdateSafeSystemVersionCheckInfo ==
No input, returns an output Event handle and an [[#IAsyncResult|IAsyncResult]].
[S2] Used by web-applets via ns:vm.
The async task thread uses [[NIM_services|nim]] RequestCheckSafeSystemVersion, etc.
== ResetSafeSystemVersionCheckInfo ==
No input/output.
This throws an error if [[Settings_services|GetDebugModeFlag]] returns false.


= ns:su =
= ns:su =
Line 2,721: Line 2,813:
|-
|-
| 18 || [4.0.0+] [[#GetSendSystemUpdateProgress]]
| 18 || [4.0.0+] [[#GetSendSystemUpdateProgress]]
|-
| 19 || [S2]
|-
| 20 || [S2]
|}
|}


Line 2,795: Line 2,891:
This validates the [[#SystemDeliveryInfo]] and generates a [[NCM_services#ContentMetaKey|ContentMetaKey]] from that, and creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation.
This validates the [[#SystemDeliveryInfo]] and generates a [[NCM_services#ContentMetaKey|ContentMetaKey]] from that, and creates the [[#IAsyncResult]] + the async thread which handles the [[#IAsyncResult]] operation.


The above validation verifies that the HMAC and SystemDeliveryProtocolVersion are valid. The SystemUpdateMetaId ([20.0.0+] NewSystemUpdateMetaId, NewSystemUpdateMetaIdFlag ignored) must match the Id for the installed SystemUpdate as returned by [[NCM_services|ncm]].
The above validation verifies that the HMAC and SystemDeliveryProtocolVersion are valid. The OldSystemUpdateId ([20.0.0+] SystemUpdateId, SystemUpdateIdFlag ignored) must match the Id for the installed SystemUpdate as returned by [[NCM_services|ncm]].


Then the thread does:
Then the thread does:
Line 2,810: Line 2,906:


Same as [[#GetReceiveProgress]] except this uses nim ListLocalCommunicationSendSystemUpdateTask and GetLocalCommunicationSendSystemUpdateTaskInfo. The data copied to output is also swapped: u64 nim_out+0x8 is copied to out+0x8, and u64 nim_out+0x10 is copied to out+0x0.
Same as [[#GetReceiveProgress]] except this uses nim ListLocalCommunicationSendSystemUpdateTask and GetLocalCommunicationSendSystemUpdateTaskInfo. The data copied to output is also swapped: u64 nim_out+0x8 is copied to out+0x8, and u64 nim_out+0x10 is copied to out+0x0.
== Cmd19 ==
This is exclusive to S2.
No input/output.
== Cmd20 ==
This is exclusive to S2.
No input, returns an output u8.


== ISystemUpdateControl ==
== ISystemUpdateControl ==
Line 2,986: Line 3,092:
* Calls a func which does:
* Calls a func which does:
** Throws an error if [[NIM_services#ListSystemUpdateTask|ListSystemUpdateTask]] returns any task.
** Throws an error if [[NIM_services#ListSystemUpdateTask|ListSystemUpdateTask]] returns any task.
** Checks whether a sysupdate is actually required using the previously generated [[NCM_services#ContentMetaKey|ContentMetaKey]], throwing an error if not.
** Checks whether a sysupdate is actually required using the previously generated [[NCM_services#ContentMetaKey|ContentMetaKey]] (this func is also passed the below statefield as the last param), throwing an error if not.
*** [20.0.0+] The above check-sysupdate func was updated (which is also used elsewhere), flag handling during the loop was updated (which uses the last input param).
** Uses [[NIM_services|nim]] CreateLocalCommunicationReceiveSystemUpdateTask, returning the Result on failure.
** Uses [[NIM_services|nim]] CreateLocalCommunicationReceiveSystemUpdateTask, returning the Result on failure.
*** The input firmware_variation is from [[System_Settings|system-setting]] <code>ns.systemupdate!firmware_variation</code> or <code>ns.systemupdate!t_firmware_variation</code>, depending on the [[Settings_services|PlatformRegion]] (value 0xFF is used when the output setting-size is invalid).
*** The input firmware_variation is from [[System_Settings|system-setting]] <code>ns.systemupdate!firmware_variation</code> or <code>ns.systemupdate!t_firmware_variation</code>, depending on the [[Settings_services|PlatformRegion]] (value 0xFF is used when the output setting-size is invalid).
*** The input '''unk''' is set to: <code>unk = statefield == 0 ? 0x4 : 0xC</code> ([20.0.0+] uses statefield & 1 == 0). [20.0.0+] Additional data is now ORRed with unk afterwards: <code>unk |= ((statefield>>1) & 0x3) << 8;</code> (same statefield as before)
** Uses [[NIM_services|nim]] RequestLocalCommunicationReceiveSystemUpdateTaskRun, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
** Uses [[NIM_services|nim]] RequestLocalCommunicationReceiveSystemUpdateTaskRun, returning the Result on failure. Waits for the IAsyncResult operation from this to finish, then uses the Get cmd to get the output Result.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
*** When the Result from Get is an error, a func is called for filling in the [[#IAsyncResult|IAsyncResult]] ErrorContext with Type4.
Line 4,639: Line 4,747:
This is "nn::ns::SystemDeliveryInfo". This is a 0x100-byte struct.
This is "nn::ns::SystemDeliveryInfo". This is a 0x100-byte struct.


[20.0.0+] The used (New)SystemUpdateMetaId as selected by NewSystemUpdateMetaIdFlag must now match one of the Ids in [[System_Settings|system-setting]] <code>contents_delivery!acceptable_system_update_ids_string</code>.
Originally the SystemDeliveryInfo validation func verified that OldSystemUpdateId matched the installed SystemUpdate Id. [20.0.0+] The used (Old)SystemUpdateId as selected by SystemUpdateIdFlag must now match one of the Ids in [[System_Settings|system-setting]] <code>contents_delivery!acceptable_system_update_ids_string</code> (replaces the previously mentioned installed-SystemUpdate check).


{| class="wikitable" border="1"
{| class="wikitable" border="1"
Line 4,655: Line 4,763:
| 0x9 || 0x3 || Reserved.
| 0x9 || 0x3 || Reserved.
|-
|-
| 0xC || 0x4 || SystemUpdateMetaVersion.
| 0xC || 0x4 || SystemUpdateVersion.
|-
|-
| 0x10 || 0x8 || SystemUpdateMetaId. [20.0.0+] Always the NX Id: this is loaded from [[System_Settings|system-setting]] <code>contents_delivery!old_system_update_id</code>.
| 0x10 || 0x8 || OldSystemUpdateId. [20.0.0+] Always the NX Id: this is loaded from [[System_Settings|system-setting]] <code>contents_delivery!old_system_update_id</code>.
|-
|-
| 0x18 || 0x1 || FirmwareVariationId. Used by [[#RequestSendSystemUpdate]]. This is set to 0xC on S2.
| 0x18 || 0x1 || FirmwareVariationId. Used by [[#RequestSendSystemUpdate]]. Loaded from [[System_Settings|system-setting]] <code>ns.systemupdate!firmware_variation</code> or <code>ns.systemupdate!t_firmware_variation</code>, depending on the [[Settings_services|PlatformRegion]].
|-
|-
| 0x19 || 0x1 || UpdatableFirmwareGroupId. Unused by [[#RequestSendSystemUpdate]]/[[#RequestReceiveSystemUpdate]], besides HMAC validation. This is set to 0x8 on S2.
| 0x19 || 0x1 || UpdatableFirmwareGroupId. Unused by [[#RequestSendSystemUpdate]]/[[#RequestReceiveSystemUpdate]], besides HMAC validation. Loaded from [[System_Settings|system-setting]] <code>ns.systemupdate!updatable_firmware_group_id</code> or <code>ns.systemupdate!t_updatable_firmware_group_id</code>, depending on the [[Settings_services|PlatformRegion]].
|-
|-
| 0x1A || 0x1 || PlatformRegion (0x00 = Unknown, 0x01 = Global, 0x02 = China).
| 0x1A || 0x1 || PlatformRegion (0x00 = Unknown/Global, 0x01 = China).
|-
|-
| 0x1B || 0x1 || [20.0.0+] SystemDeliveryInfoPlatform. Loaded from [[System_Settings|system-setting]] <code>ns.systemupdate!system_delivery_info_platform</code>. Elsewhere this is compared against the sys-setting, etc.
| 0x1B || 0x1 || [20.0.0+] SystemDeliveryInfoPlatform. Loaded from [[System_Settings|system-setting]] <code>ns.systemupdate!system_delivery_info_platform</code>. Elsewhere this is compared against the sys-setting, etc.
|-
|-
| 0x1C || 0x1 || [20.0.0+] NewSystemUpdateMetaIdFlag. When non-zero, NewSystemUpdateMetaId is used instead of SystemUpdateMetaId. Always set to 0x1 by [[#GetSystemDeliveryInfo]] with [20.0.0+].
| 0x1C || 0x1 || [20.0.0+] SystemUpdateIdFlag. When non-zero, SystemUpdateId is used instead of OldSystemUpdateId. Always set to 0x1 by [[#GetSystemDeliveryInfo]] with [20.0.0+].
|-
|-
| 0x1D || 0x3 || Padding
| 0x1D || 0x3 || Padding
|-
|-
| 0x20 || 0x8 || [20.0.0+] NewSystemUpdateMetaId. See above. With [20.0.0+] [[#GetSystemDeliveryInfo]] now writes the Id here instead of SystemUpdateMetaId. On S2 this is set to the Ounce Id.
| 0x20 || 0x8 || [20.0.0+] SystemUpdateId. See above. With [20.0.0+] [[#GetSystemDeliveryInfo]] now writes the Id here instead of OldSystemUpdateId (for the installed SystemUpdate). On S2 this is set to the Ounce Id.
|-
|-
| 0x28 || 0xB8 || Unused by [[#RequestSendSystemUpdate]]/[[#RequestReceiveSystemUpdate]], besides HMAC validation.
| 0x28 || 0xB8 || Reserved
|-
|-
| 0xE0 || 0x20 || HMAC-SHA256 over the previous 0xE0-bytes.
| 0xE0 || 0x20 || HMAC-SHA256 over the previous 0xE0-bytes.