From 8ae9b5e1a9679ef5204782d9c529be4d808ef888 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 26 Feb 2020 17:35:01 -0500 Subject: [PATCH 01/21] ns: Added nsGetFactoryResetInterface(). Added support for IFactoryResetInterface. Improved docs, etc. --- nx/include/switch/services/ns.h | 44 ++++++++++++++++++ nx/source/services/ns.c | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index b7123787..e21b7315 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -234,6 +234,50 @@ Service* nsGetServiceSession_GetterInterface(void); /// Gets the Service object for IApplicationManagerInterface. Service* nsGetServiceSession_ApplicationManagerInterface(void); +/// Gets the Service object for IFactoryResetInterface via the cmd for that. +Result nsGetFactoryResetInterface(Service* srv_out); + +///@} + +///@name IFactoryResetInterface +///@{ + +/** + * @brief ResetToFactorySettings + * @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + */ +Result nsResetToFactorySettings(void); + +/** + * @brief ResetToFactorySettingsWithoutUserSaveData + * @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + */ +Result nsResetToFactorySettingsWithoutUserSaveData(void); + +/** + * @brief ResetToFactorySettingsForRefurbishment + * @note Uses \ref nsGetFactoryResetInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + */ +Result nsResetToFactorySettingsForRefurbishment(void); + +/** + * @brief ResetToFactorySettingsWithPlatformRegion + * @note Only available on [9.1.0+]. + */ +Result nsResetToFactorySettingsWithPlatformRegion(void); + +/** + * @brief ResetToFactorySettingsWithPlatformRegionAuthentication + * @note Only available on [9.1.0+]. + */ +Result nsResetToFactorySettingsWithPlatformRegionAuthentication(void); + +///@} + +///@name IApplicationManagerInterface +///@{ + /** * @brief Gets an listing of \ref NsApplicationRecord. * @param[out] records Output array of \ref NsApplicationRecord. diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index eb9e3950..bbc430f1 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -46,6 +46,10 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) { return &g_nsAppManSrv; } +Result nsGetFactoryResetInterface(Service* srv_out) { + return _nsGetSession(&g_nsGetterSrv, srv_out, 7994); +} + static Result _nsGetSession(Service* srv, Service* srv_out, u32 cmd_id) { return serviceDispatch(srv, cmd_id, .out_num_objects = 1, @@ -234,6 +238,81 @@ static Result _nsCheckNifm(void) { return nifmIsAnyInternetRequestAccepted(nifmGetClientId()) ? 0 : MAKERESULT(16, 340); } +// IFactoryResetInterface + +Result nsResetToFactorySettings(void) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetFactoryResetInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 100); + + serviceClose(&srv); + return rc; +} + +Result nsResetToFactorySettingsWithoutUserSaveData(void) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetFactoryResetInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 101); + + serviceClose(&srv); + return rc; +} + +Result nsResetToFactorySettingsForRefurbishment(void) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetFactoryResetInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 102); + + serviceClose(&srv); + return rc; +} + +Result nsResetToFactorySettingsWithPlatformRegion(void) { + if (hosversionBefore(9,1,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetFactoryResetInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 103); + + serviceClose(&srv); + return rc; +} + +Result nsResetToFactorySettingsWithPlatformRegionAuthentication(void) { + if (hosversionBefore(9,1,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetFactoryResetInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 104); + + serviceClose(&srv); + return rc; +} + +// IApplicationManagerInterface + Result nsListApplicationRecord(NsApplicationRecord* records, s32 count, s32 entry_offset, s32* out_entrycount) { return serviceDispatchInOut(&g_nsAppManSrv, 0, entry_offset, *out_entrycount, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, From 424cd0fefedd5a2bcfaf974c386fd9fbc3da21f6 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 26 Feb 2020 22:38:13 -0500 Subject: [PATCH 02/21] ns: Check sysver in nsGetFactoryResetInterface, and added nsGetContentManagementInterface. Use IContentManagementInterface with the relevant cmds when needed. Added struct NsApplicationOccupiedSize. Added cmds: nsCalculateApplicationOccupiedSize, nsCheckSdCardMountStatus, nsCountApplicationContentMeta, nsIsAnyApplicationRunning. --- nx/include/switch/services/ns.h | 98 +++++++++++++++------ nx/source/services/ns.c | 148 ++++++++++++++++++++++++++------ 2 files changed, 197 insertions(+), 49 deletions(-) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index e21b7315..5cd13794 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -74,6 +74,11 @@ typedef struct { u8 icon[0x20000]; ///< JPEG } NsApplicationControlData; +/// ApplicationOccupiedSize +typedef struct { + u8 unk_x0[0x80]; ///< Unknown. +} NsApplicationOccupiedSize; + /// NsApplicationContentMetaStatus typedef struct { u8 meta_type; ///< \ref NcmContentMetaType @@ -235,8 +240,13 @@ Service* nsGetServiceSession_GetterInterface(void); Service* nsGetServiceSession_ApplicationManagerInterface(void); /// Gets the Service object for IFactoryResetInterface via the cmd for that. +/// Only available on [3.0.0+]. Result nsGetFactoryResetInterface(Service* srv_out); +/// Gets the Service object for IContentManagementInterface via the cmd for that. +/// Only available on [3.0.0+]. +Result nsGetContentManagementInterface(Service* srv_out); + ///@} ///@name IFactoryResetInterface @@ -381,20 +391,6 @@ Result nsCleanupSdCard(void); */ Result nsGetSdCardMountStatusChangedEvent(Event* out_event); -/** - * @brief Returns the total storage capacity (used + free) from content manager services. - * @param[in] storage_id \ref NcmStorageId. Must be ::NcmStorageId_SdCard. - * @param[out] size Pointer to output the total storage size to. - */ -Result nsGetTotalSpaceSize(NcmStorageId storage_id, s64 *size); - -/** - * @brief Returns the available storage capacity from content manager services. - * @param[in] storage_id \ref NcmStorageId. Must be ::NcmStorageId_SdCard. - * @param[out] size Pointer to output the free storage size to. - */ -Result nsGetFreeSpaceSize(NcmStorageId storage_id, s64 *size); - /** * @brief GetGameCardUpdateDetectionEvent * @note The Event must be closed by the user once finished with it. @@ -631,17 +627,6 @@ Result nsGetLastGameCardMountFailureResult(void); */ Result nsListApplicationIdOnGameCard(u64 *application_ids, s32 count, s32 *total_out); -/** - * @brief Gets an listing of \ref NsApplicationContentMetaStatus. - * @note Only available on [2.0.0+]. - * @param[in] application_id ApplicationId. - * @param[in] index Starting entry index. - * @param[out] list Output array of \ref NsApplicationContentMetaStatus. - * @param[in] count Size of the list array in entries. - * @param[out] out_entrycount Total output entries. - */ -Result nsListApplicationContentMetaStatus(u64 application_id, s32 index, NsApplicationContentMetaStatus* list, s32 count, s32* out_entrycount); - /** * @brief TouchApplication * @note Only available on [2.0.0+]. @@ -982,6 +967,69 @@ Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, Accoun ///@} +///@name IContentManagementInterface +///@{ + +/** + * @brief CalculateApplicationOccupiedSize + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @param[in] application_id ApplicationId. + * @param[out] out \ref NsApplicationOccupiedSize + */ +Result nsCalculateApplicationOccupiedSize(u64 application_id, NsApplicationOccupiedSize *out); + +/** + * @brief CheckSdCardMountStatus + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + */ +Result nsCheckSdCardMountStatus(void); + +/** + * @brief Returns the total storage capacity (used + free) from content manager services. + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @param[in] storage_id \ref NcmStorageId. Must be ::NcmStorageId_SdCard. + * @param[out] size Pointer to output the total storage size to. + */ +Result nsGetTotalSpaceSize(NcmStorageId storage_id, s64 *size); + +/** + * @brief Returns the available storage capacity from content manager services. + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @param[in] storage_id \ref NcmStorageId. Must be ::NcmStorageId_SdCard. + * @param[out] size Pointer to output the free storage size to. + */ +Result nsGetFreeSpaceSize(NcmStorageId storage_id, s64 *size); + +/** + * @brief CountApplicationContentMeta + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + * @param[in] application_id ApplicationId. + * @param[out] out Output count. + */ +Result nsCountApplicationContentMeta(u64 application_id, s32 *out); + +/** + * @brief Gets an listing of \ref NsApplicationContentMetaStatus. + * @note Uses \ref nsGetContentManagementInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + * @param[in] application_id ApplicationId. + * @param[in] index Starting entry index. + * @param[out] list Output array of \ref NsApplicationContentMetaStatus. + * @param[in] count Size of the list array in entries. + * @param[out] out_entrycount Total output entries. + */ +Result nsListApplicationContentMetaStatus(u64 application_id, s32 index, NsApplicationContentMetaStatus* list, s32 count, s32* out_entrycount); + +/** + * @brief IsAnyApplicationRunning + * @note Only available on [3.0.0+]. + * @param[out] out Output flag. + */ +Result nsIsAnyApplicationRunning(bool *out); + +///@} + ///@name IRequestServerStopper ///@{ diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index bbc430f1..4f8ec96b 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -47,9 +47,19 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) { } Result nsGetFactoryResetInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _nsGetSession(&g_nsGetterSrv, srv_out, 7994); } +Result nsGetContentManagementInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7998); +} + static Result _nsGetSession(Service* srv, Service* srv_out, u32 cmd_id) { return serviceDispatch(srv, cmd_id, .out_num_objects = 1, @@ -397,14 +407,6 @@ Result nsGetSdCardMountStatusChangedEvent(Event* out_event) { return _nsCmdGetEvent(&g_nsAppManSrv, out_event, false, 44); } -Result nsGetTotalSpaceSize(NcmStorageId storage_id, s64 *size) { - return _nsCmdInU64OutU64(&g_nsAppManSrv, storage_id, (u64*)size, 47); -} - -Result nsGetFreeSpaceSize(NcmStorageId storage_id, s64 *size) { - return _nsCmdInU64OutU64(&g_nsAppManSrv, storage_id, (u64*)size, 48); -} - Result nsGetGameCardUpdateDetectionEvent(Event* out_event) { return _nsCmdGetEvent(&g_nsAppManSrv, out_event, false, 52); } @@ -713,22 +715,6 @@ Result nsListApplicationIdOnGameCard(u64 *application_ids, s32 count, s32 *total ); } -Result nsListApplicationContentMetaStatus(u64 application_id, s32 index, NsApplicationContentMetaStatus* list, s32 count, s32* out_entrycount) { - if (hosversionBefore(2,0,0)) - return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - - const struct { - s32 index; - u32 pad; - u64 application_id; - } in = { index, 0, application_id }; - - return serviceDispatchInOut(&g_nsAppManSrv, 601, in, *out_entrycount, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { list, count*sizeof(NsApplicationContentMetaStatus) } }, - ); -} - Result nsTouchApplication(u64 application_id) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -1271,6 +1257,120 @@ Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, Accoun ); } +// IContentManagementInterface + +Result nsCalculateApplicationOccupiedSize(u64 application_id, NsApplicationOccupiedSize *out) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 11, application_id, *out); + + serviceClose(&srv); + return rc; +} + +Result nsCheckSdCardMountStatus(void) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 43); + + serviceClose(&srv); + return rc; +} + +Result nsGetTotalSpaceSize(NcmStorageId storage_id, s64 *size) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64OutU64(srv_ptr, storage_id, (u64*)size, 47); + + serviceClose(&srv); + return rc; +} + +Result nsGetFreeSpaceSize(NcmStorageId storage_id, s64 *size) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64OutU64(srv_ptr, storage_id, (u64*)size, 48); + + serviceClose(&srv); + return rc; +} + +Result nsCountApplicationContentMeta(u64 application_id, s32 *out) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 600, application_id, *out); + + serviceClose(&srv); + return rc; +} + +Result nsListApplicationContentMetaStatus(u64 application_id, s32 index, NsApplicationContentMetaStatus* list, s32 count, s32* out_entrycount) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetContentManagementInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + const struct { + s32 index; + u32 pad; + u64 application_id; + } in = { index, 0, application_id }; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 601, in, *out_entrycount, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { list, count*sizeof(NsApplicationContentMetaStatus) } }, + ); + + serviceClose(&srv); + return rc; +} + +Result nsIsAnyApplicationRunning(bool *out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetContentManagementInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoInOutBool(&srv, out, 607); + + serviceClose(&srv); + return rc; +} + // IRequestServerStopper void nsRequestServerStopperClose(NsRequestServerStopper *r) { From 3ff12e7337d7e2cda4eb1a6d9e7da7f0e4ca50c3 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 27 Feb 2020 20:52:14 -0500 Subject: [PATCH 03/21] ns: Added nsGetDownloadTaskInterface. Added NsDownloadTaskStatus. Added support for IDownloadTaskInterface. --- nx/include/switch/services/ns.h | 78 +++++++++++++++++ nx/source/services/ns.c | 150 ++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index 5cd13794..dd5ab686 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -221,6 +221,11 @@ typedef struct { u8 unk_x1a[0x6]; ///< Unknown. } NsApplicationRightsOnClient; +/// DownloadTaskStatus +typedef struct { + u8 unk_x0[0x20]; ///< Unknown. +} NsDownloadTaskStatus; + /// Default size for \ref nssuControlSetupCardUpdate / \ref nssuControlSetupCardUpdateViaSystemUpdater. This is the size used by qlaunch for SetupCardUpdate. #define NSSU_CARDUPDATE_TMEM_SIZE_DEFAULT 0x100000 @@ -243,6 +248,10 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void); /// Only available on [3.0.0+]. Result nsGetFactoryResetInterface(Service* srv_out); +/// Gets the Service object for IDownloadTaskInterface via the cmd for that. +/// Only available on [3.0.0+]. +Result nsGetDownloadTaskInterface(Service* srv_out); + /// Gets the Service object for IContentManagementInterface via the cmd for that. /// Only available on [3.0.0+]. Result nsGetContentManagementInterface(Service* srv_out); @@ -967,6 +976,75 @@ Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, Accoun ///@} +///@name IDownloadTaskInterface +///@{ + +/** + * @brief ClearTaskStatusList + * @note Uses \ref nsGetDownloadTaskInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + */ +Result nsClearTaskStatusList(void); + +/** + * @brief RequestDownloadTaskList + * @note Uses \ref nsGetDownloadTaskInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + */ +Result nsRequestDownloadTaskList(void); + +/** + * @brief RequestEnsureDownloadTask + * @note Uses \ref nsGetDownloadTaskInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + * @param[out] a \ref AsyncResult + */ +Result nsRequestEnsureDownloadTask(AsyncResult *a); + +/** + * @brief ListDownloadTaskStatus + * @note Uses \ref nsGetDownloadTaskInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + * @param[out] tasks Output array of \ref NsDownloadTaskStatus. + * @param[in] count Size of the tasks array in entries. A maximum of 0x100 tasks can be stored in state. + * @param[out] total_out Total output entries. + */ +Result nsListDownloadTaskStatus(NsDownloadTaskStatus* tasks, s32 count, s32 *total_out); + +/** + * @brief RequestDownloadTaskListData + * @note Uses \ref nsGetDownloadTaskInterface on [3.0.0+], otherwise IApplicationManagerInterface is used. + * @note Only available on [2.0.0+]. + * @param[out] a \ref AsyncValue + */ +Result nsRequestDownloadTaskListData(AsyncValue *a); + +/** + * @brief TryCommitCurrentApplicationDownloadTask + * @note Only available on [4.0.0+]. + */ +Result nsTryCommitCurrentApplicationDownloadTask(void); + +/** + * @brief EnableAutoCommit + * @note Only available on [4.0.0+]. + */ +Result nsEnableAutoCommit(void); + +/** + * @brief DisableAutoCommit + * @note Only available on [4.0.0+]. + */ +Result nsDisableAutoCommit(void); + +/** + * @brief TriggerDynamicCommitEvent + * @note Only available on [4.0.0+]. + */ +Result nsTriggerDynamicCommitEvent(void); + +///@} + ///@name IContentManagementInterface ///@{ diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 4f8ec96b..f0bba149 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -53,6 +53,13 @@ Result nsGetFactoryResetInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7994); } +Result nsGetDownloadTaskInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7997); +} + Result nsGetContentManagementInterface(Service* srv_out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -1257,6 +1264,149 @@ Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, Accoun ); } +// IDownloadTaskInterface + +Result nsClearTaskStatusList(void) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetDownloadTaskInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 701); + + serviceClose(&srv); + return rc; +} + +Result nsRequestDownloadTaskList(void) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetDownloadTaskInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, 702); + + serviceClose(&srv); + return rc; +} + +Result nsRequestEnsureDownloadTask(AsyncResult *a) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetDownloadTaskInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc =_nsCmdNoInOutAsyncResult(srv_ptr, a, 703); + + serviceClose(&srv); + return rc; +} + +Result nsListDownloadTaskStatus(NsDownloadTaskStatus* tasks, s32 count, s32 *total_out) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetDownloadTaskInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(srv_ptr, 704, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { tasks, count*sizeof(NsDownloadTaskStatus) } }, + ); + + + serviceClose(&srv); + return rc; +} + +Result nsRequestDownloadTaskListData(AsyncValue *a) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetDownloadTaskInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc =_nsCmdNoInOutAsyncValue(srv_ptr, a, 705); + + serviceClose(&srv); + return rc; +} + +Result nsTryCommitCurrentApplicationDownloadTask(void) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetDownloadTaskInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 706); + + serviceClose(&srv); + return rc; +} + +Result nsEnableAutoCommit(void) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetDownloadTaskInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 707); + + serviceClose(&srv); + return rc; +} + +Result nsDisableAutoCommit(void) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetDownloadTaskInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 708); + + serviceClose(&srv); + return rc; +} + +Result nsTriggerDynamicCommitEvent(void) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetDownloadTaskInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(&srv, 709); + + serviceClose(&srv); + return rc; +} + // IContentManagementInterface Result nsCalculateApplicationOccupiedSize(u64 application_id, NsApplicationOccupiedSize *out) { From 23852ad932347ca098de14136ff51a309ed500af Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 28 Feb 2020 17:59:31 +0100 Subject: [PATCH 04/21] add tc (#378) --- nx/include/switch.h | 1 + nx/include/switch/services/tc.h | 26 ++++++++++++++++++ nx/source/services/tc.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 nx/include/switch/services/tc.h create mode 100644 nx/source/services/tc.c diff --git a/nx/include/switch.h b/nx/include/switch.h index b51d25d5..eed43dc6 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -84,6 +84,7 @@ extern "C" { #include "switch/services/ns.h" #include "switch/services/ldr.h" #include "switch/services/ro.h" +#include "switch/services/tc.h" #include "switch/services/ts.h" #include "switch/services/pm.h" #include "switch/services/set.h" diff --git a/nx/include/switch/services/tc.h b/nx/include/switch/services/tc.h new file mode 100644 index 00000000..56be6c06 --- /dev/null +++ b/nx/include/switch/services/tc.h @@ -0,0 +1,26 @@ +/** + * @file tc.h + * @brief Temperature control (tc) service IPC wrapper. + * @author Behemoth + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../sf/service.h" + +/// Initialize tc. +Result tcInitialize(void); + +/// Exit tc. +void tcExit(void); + +/// Gets the Service for tc. +Service* tcGetServiceSession(void); + +Result tcEnableFanControl(void); +/// @warning Disabling your fan can damage your system. +Result tcDisableFanControl(void); +Result tcIsFanControlEnabled(bool *status); +/// Only available on [5.0.0+]. +Result tcGetSkinTemperatureMilliC(s32 *skinTemp); + diff --git a/nx/source/services/tc.c b/nx/source/services/tc.c new file mode 100644 index 00000000..dae85f88 --- /dev/null +++ b/nx/source/services/tc.c @@ -0,0 +1,47 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include +#include "service_guard.h" +#include "runtime/hosversion.h" +#include "services/tc.h" + +static Service g_tcSrv; + +NX_GENERATE_SERVICE_GUARD(tc); + +Result _tcInitialize(void) { + return smGetService(&g_tcSrv, "tc"); +} + +void _tcCleanup(void) { + serviceClose(&g_tcSrv); +} + +Service* tcGetServiceSession(void) { + return &g_tcSrv; +} + +static Result _tcNoInNoOut(u32 cmd_id) { + return serviceDispatch(&g_tcSrv, cmd_id); +} + +Result tcEnableFanControl(void) { + return _tcNoInNoOut(6); +} + +Result tcDisableFanControl(void) { + return _tcNoInNoOut(7); +} + +Result tcIsFanControlEnabled(bool *status) { + u8 tmp=0; + Result rc = serviceDispatchOut(&g_tcSrv, 8, tmp); + if (R_SUCCEEDED(rc) && status) *status = tmp & 1; + return rc; +} + +Result tcGetSkinTemperatureMilliC(s32 *skinTemp) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_tcSrv, 9, *skinTemp); +} From abc3522724c6cfb4dcd0bf8d6b4f540df829968c Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 28 Feb 2020 19:13:27 +0100 Subject: [PATCH 05/21] lbl: more commands (#377) --- nx/include/switch/services/lbl.h | 63 ++++++++++++++++++- nx/source/services/lbl.c | 101 +++++++++++++++++++++++++++++-- 2 files changed, 158 insertions(+), 6 deletions(-) diff --git a/nx/include/switch/services/lbl.h b/nx/include/switch/services/lbl.h index 6a6feff0..03bfb548 100644 --- a/nx/include/switch/services/lbl.h +++ b/nx/include/switch/services/lbl.h @@ -8,6 +8,13 @@ #include "../types.h" #include "../sf/service.h" +typedef enum { + LblBacklightSwitchStatus_Disabled = 0, + LblBacklightSwitchStatus_Enabled = 1, + LblBacklightSwitchStatus_Enabling = 2, + LblBacklightSwitchStatus_Disabling = 3, +} LblBacklightSwitchStatus; + /// Initialize lbl. Result lblInitialize(void); @@ -17,8 +24,8 @@ void lblExit(void); /// Gets the Service object for the actual lbl service session. Service* lblGetServiceSession(void); -Result lblSwitchBacklightOn(u64 fade_time); -Result lblSwitchBacklightOff(u64 fade_time); +Result lblSaveCurrentSetting(void); +Result lblLoadCurrentSetting(void); /** * @note The brightness goes from 0 to 1.0. @@ -26,6 +33,58 @@ Result lblSwitchBacklightOff(u64 fade_time); Result lblSetCurrentBrightnessSetting(float brightness); Result lblGetCurrentBrightnessSetting(float *out_value); +Result lblApplyCurrentBrightnessSettingToBacklight(void); +Result lblGetBrightnessSettingAppliedToBacklight(float *out_value); + +Result lblSwitchBacklightOn(u64 fade_time); +Result lblSwitchBacklightOff(u64 fade_time); +Result lblGetBacklightSwitchStatus(LblBacklightSwitchStatus *out_value); + +Result lblEnableDimming(void); +Result lblDisableDimming(void); +Result lblIsDimmingEnabled(bool *out_value); + Result lblEnableAutoBrightnessControl(void); Result lblDisableAutoBrightnessControl(void); Result lblIsAutoBrightnessControlEnabled(bool *out_value); + +Result lblSetAmbientLightSensorValue(float value); + +/** + * @note Used internally by \ref appletGetAmbientLightSensorValue and \ref appletGetCurrentIlluminanceEx. + */ +Result lblGetAmbientLightSensorValue(bool *over_limit, float *lux); + +/** + * @note Only available on [3.0.0+]. + * @note Used internally by \ref appletIsIlluminanceAvailable. + */ +Result lblIsAmbientLightSensorAvailable(bool *out_value); + +/** + * @note Only available on [3.0.0+]. + */ +Result lblSetCurrentBrightnessSettingForVrMode(float brightness); + +/** + * @note Only available on [3.0.0+]. + */ +Result lblGetCurrentBrightnessSettingForVrMode(float *out_value); + +/** + * @note Only available on [3.0.0+]. + * @note Used internally by \ref appletSetVrModeEnabled. + */ +Result lblEnableVrMode(void); + +/** + * @note Only available on [3.0.0+]. + * @note Used internally by \ref appletSetVrModeEnabled. + */ +Result lblDisableVrMode(void); + +/** + * @note Only available on [3.0.0+]. + * @note Used internally by \ref appletIsVrModeEnabled. + */ +Result lblIsVrModeEnabled(bool *out_value); diff --git a/nx/source/services/lbl.c b/nx/source/services/lbl.c index 5dbbd1b8..6e491692 100644 --- a/nx/source/services/lbl.c +++ b/nx/source/services/lbl.c @@ -1,6 +1,7 @@ #define NX_SERVICE_ASSUME_NON_DOMAIN #include "service_guard.h" #include "services/lbl.h" +#include "runtime/hosversion.h" static Service g_lblSrv; @@ -37,6 +38,38 @@ static Result _lblCmdNoInOutBool(bool *out, u32 cmd_id) { return rc; } +static Result _lblCmdNoInOutFloat(float *out, u32 cmd_id) { + return serviceDispatchOut(&g_lblSrv, cmd_id, *out); +} + +static Result _lblCmdInFloatNoOut(float in, u32 cmd_id) { + return serviceDispatchIn(&g_lblSrv, cmd_id, in); +} + +Result lblSaveCurrentSetting(void) { + return _lblCmdNoIO(0); +} + +Result lblLoadCurrentSetting(void) { + return _lblCmdNoIO(1); +} + +Result lblSetCurrentBrightnessSetting(float brightness) { + return _lblCmdInFloatNoOut(brightness, 2); +} + +Result lblGetCurrentBrightnessSetting(float *out_value) { + return _lblCmdNoInOutFloat(out_value, 3); +} + +Result lblApplyCurrentBrightnessSettingToBacklight(void) { + return _lblCmdNoIO(4); +} + +Result lblGetBrightnessSettingAppliedToBacklight(float *out_value) { + return _lblCmdNoInOutFloat(out_value, 5); +} + Result lblSwitchBacklightOn(u64 fade_time) { return _lblCmdInU64NoOut(fade_time, 6); } @@ -45,12 +78,20 @@ Result lblSwitchBacklightOff(u64 fade_time) { return _lblCmdInU64NoOut(fade_time, 7); } -Result lblSetCurrentBrightnessSetting(float brightness) { - return serviceDispatchIn(&g_lblSrv, 2, brightness); +Result lblGetBacklightSwitchStatus(LblBacklightSwitchStatus *out_value) { + return serviceDispatchOut(&g_lblSrv, 8, *out_value); } -Result lblGetCurrentBrightnessSetting(float *out_value) { - return serviceDispatchOut(&g_lblSrv, 3, *out_value); +Result lblEnableDimming(void) { + return _lblCmdNoIO(9); +} + +Result lblDisableDimming(void) { + return _lblCmdNoIO(10); +} + +Result lblIsDimmingEnabled(bool *out_value) { + return _lblCmdNoInOutBool(out_value, 11); } Result lblEnableAutoBrightnessControl(void) { @@ -64,3 +105,55 @@ Result lblDisableAutoBrightnessControl(void) { Result lblIsAutoBrightnessControlEnabled(bool *out_value){ return _lblCmdNoInOutBool(out_value, 14); } + +Result lblSetAmbientLightSensorValue(float value) { + return _lblCmdInFloatNoOut(value, 15); +} + +Result lblGetAmbientLightSensorValue(bool *over_limit, float *lux) { + struct { + u32 over_limit; + float lux; + } out; + + Result rc = serviceDispatchOut(&g_lblSrv, 16, out); + if (R_SUCCEEDED(rc)) { + if (over_limit) *over_limit = out.over_limit & 1; + if (lux) *lux = out.lux; + } + return rc; +} + +Result lblIsAmbientLightSensorAvailable(bool *out_value) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdNoInOutBool(out_value, 23); +} +Result lblSetCurrentBrightnessSettingForVrMode(float brightness) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdInFloatNoOut(brightness, 24); +} +Result lblGetCurrentBrightnessSettingForVrMode(float *out_value) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdNoInOutFloat(out_value, 25); +} + +Result lblEnableVrMode(void) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdNoIO(26); +} + +Result lblDisableVrMode(void) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdNoIO(27); +} + +Result lblIsVrModeEnabled(bool *out_value) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _lblCmdNoInOutBool(out_value, 28); +} From 7e07d1edf0a6601a0daa96f51c5ce346ebd30da2 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 28 Feb 2020 19:23:10 +0100 Subject: [PATCH 06/21] add fan service (#376) --- nx/include/switch.h | 1 + nx/include/switch/services/fan.h | 32 ++++++++++++++++++++++++++ nx/source/services/fan.c | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 nx/include/switch/services/fan.h create mode 100644 nx/source/services/fan.c diff --git a/nx/include/switch.h b/nx/include/switch.h index eed43dc6..5b06c4fd 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -64,6 +64,7 @@ extern "C" { #include "switch/services/bpc.h" #include "switch/services/pcv.h" #include "switch/services/clkrst.h" +#include "switch/services/fan.h" #include "switch/services/psm.h" #include "switch/services/spsm.h" //#include "switch/services/bsd.h" Use instead diff --git a/nx/include/switch/services/fan.h b/nx/include/switch/services/fan.h new file mode 100644 index 00000000..b77bf4b4 --- /dev/null +++ b/nx/include/switch/services/fan.h @@ -0,0 +1,32 @@ +/** + * @file fan.h + * @brief Fan service IPC wrapper. + * @author Behemoth + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../sf/service.h" + +typedef struct { + Service s; +} FanController; + +/// Initialize fan. +Result fanInitialize(void); + +/// Exit fan. +void fanExit(void); + +/// Gets the Service object for the actual fan service session. +Service* fanGetServiceSession(void); + +/// Opens IController session. +Result fanOpenController(FanController *out, u32 device_code); + +/// Close IController session. +void fanControllerClose(FanController *controller); + +/// @warning Disabling your fan can damage your system. +Result fanControllerSetRotationSpeedLevel(FanController *controller, float level); +Result fanControllerGetRotationSpeedLevel(FanController *controller, float *level); diff --git a/nx/source/services/fan.c b/nx/source/services/fan.c new file mode 100644 index 00000000..1a94d147 --- /dev/null +++ b/nx/source/services/fan.c @@ -0,0 +1,39 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" +#include "services/fan.h" +#include "runtime/hosversion.h" + +static Service g_fanSrv; + +NX_GENERATE_SERVICE_GUARD(fan); + +Result _fanInitialize(void) { + return smGetService(&g_fanSrv, "fan"); +} + +void _fanCleanup(void) { + serviceClose(&g_fanSrv); +} + +Result fanOpenController(FanController *out, u32 device_code) { + return serviceDispatchIn(&g_fanSrv, 0, device_code, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + +Service* fanGetServiceSession(void) { + return &g_fanSrv; +} + +void fanControllerClose(FanController *controller) { + serviceClose(&controller->s); +} + +Result fanControllerSetRotationSpeedLevel(FanController *controller, float level) { + return serviceDispatchIn(&controller->s, 0, level); +} + +Result fanControllerGetRotationSpeedLevel(FanController *controller, float *level) { + return serviceDispatchOut(&controller->s, 2, *level); +} From fdb6aa1f159b45d8823d9c9bf5a2539feb47103d Mon Sep 17 00:00:00 2001 From: yellows8 Date: Fri, 28 Feb 2020 14:36:10 -0500 Subject: [PATCH 07/21] ns: Added nsGetECommerceInterface. Added cmds: nsRequestLinkDevice, nsRequestSyncRights, nsRequestUnlinkDevice. Minor adjustments. --- nx/include/switch/services/ns.h | 34 +++++++++++++++ nx/source/services/ns.c | 74 ++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index dd5ab686..31fd597e 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -244,6 +244,10 @@ Service* nsGetServiceSession_GetterInterface(void); /// Gets the Service object for IApplicationManagerInterface. Service* nsGetServiceSession_ApplicationManagerInterface(void); +/// Gets the Service object for IECommerceInterface via the cmd for that. +/// Only available on [4.0.0+]. +Result nsGetECommerceInterface(Service* srv_out); + /// Gets the Service object for IFactoryResetInterface via the cmd for that. /// Only available on [3.0.0+]. Result nsGetFactoryResetInterface(Service* srv_out); @@ -258,6 +262,36 @@ Result nsGetContentManagementInterface(Service* srv_out); ///@} +///@name IECommerceInterface +///@{ + +/** + * @brief RequestLinkDevice + * @note \ref nifmInitialize must be used prior to this. Before using the cmd, this calls \ref nifmIsAnyInternetRequestAccepted with the output from \ref nifmGetClientId, an error is returned when that returns false. + * @note Only available on [4.0.0+]. + * @param[out] a \ref AsyncResult + * @param[in] uid \ref AccountUid + */ +Result nsRequestLinkDevice(AsyncResult *a, AccountUid uid); + +/** + * @brief RequestSyncRights + * @note Only available on [6.0.0+]. + * @param[out] a \ref AsyncResult + */ +Result nsRequestSyncRights(AsyncResult *a); + +/** + * @brief RequestUnlinkDevice + * @note \ref nifmInitialize must be used prior to this. Before using the cmd, this calls \ref nifmIsAnyInternetRequestAccepted with the output from \ref nifmGetClientId, an error is returned when that returns false. + * @note Only available on [6.0.0+]. + * @param[out] a \ref AsyncResult + * @param[in] uid \ref AccountUid + */ +Result nsRequestUnlinkDevice(AsyncResult *a, AccountUid uid); + +///@} + ///@name IFactoryResetInterface ///@{ diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index f0bba149..076e648f 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -46,6 +46,13 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) { return &g_nsAppManSrv; } +Result nsGetECommerceInterface(Service* srv_out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7992); +} + Result nsGetFactoryResetInterface(Service* srv_out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -251,10 +258,73 @@ static Result _nsCmdInU64OutAsyncResult(Service* srv, AsyncResult *a, u64 inval, return rc; } +static Result _nsCmdInUidOutAsyncResult(Service* srv, AsyncResult *a, AccountUid uid, u32 cmd_id) { + memset(a, 0, sizeof(*a)); + Handle event = INVALID_HANDLE; + Result rc = serviceDispatchIn(srv, cmd_id, uid, + .out_num_objects = 1, + .out_objects = &a->s, + .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, + .out_handles = &event, + ); + + if (R_SUCCEEDED(rc)) + eventLoadRemote(&a->event, event, false); + + return rc; +} + static Result _nsCheckNifm(void) { return nifmIsAnyInternetRequestAccepted(nifmGetClientId()) ? 0 : MAKERESULT(16, 340); } +// IECommerceInterface + +Result nsRequestLinkDevice(AsyncResult *a, AccountUid uid) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Result rc = _nsCheckNifm(); + if (R_FAILED(rc)) return rc; + + Service srv={0}; + rc = nsGetECommerceInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdInUidOutAsyncResult(&srv, a, uid, 0); + + serviceClose(&srv); + return rc; +} + +Result nsRequestSyncRights(AsyncResult *a) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Service srv={0}; + Result rc = nsGetECommerceInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoInOutAsyncResult(&srv, a, 3); + + serviceClose(&srv); + return rc; +} + +Result nsRequestUnlinkDevice(AsyncResult *a, AccountUid uid) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Result rc = _nsCheckNifm(); + if (R_FAILED(rc)) return rc; + + Service srv={0}; + rc = nsGetECommerceInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = _nsCmdInUidOutAsyncResult(&srv, a, uid, 4); + + serviceClose(&srv); + return rc; +} + // IFactoryResetInterface Result nsResetToFactorySettings(void) { @@ -1311,7 +1381,7 @@ Result nsRequestEnsureDownloadTask(AsyncResult *a) { else srv_ptr = &g_nsAppManSrv; - if (R_SUCCEEDED(rc)) rc =_nsCmdNoInOutAsyncResult(srv_ptr, a, 703); + if (R_SUCCEEDED(rc)) rc = _nsCmdNoInOutAsyncResult(srv_ptr, a, 703); serviceClose(&srv); return rc; @@ -1349,7 +1419,7 @@ Result nsRequestDownloadTaskListData(AsyncValue *a) { else srv_ptr = &g_nsAppManSrv; - if (R_SUCCEEDED(rc)) rc =_nsCmdNoInOutAsyncValue(srv_ptr, a, 705); + if (R_SUCCEEDED(rc)) rc = _nsCmdNoInOutAsyncValue(srv_ptr, a, 705); serviceClose(&srv); return rc; From 7822accc226db5302aff649b423bc4b4161df489 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Fri, 28 Feb 2020 20:08:08 -0500 Subject: [PATCH 08/21] ns: Added nsGetReadOnlyApplicationControlDataInterface. Use IReadOnlyApplicationControlDataInterface with nsGetApplicationControlData when needed. --- nx/include/switch/services/ns.h | 30 ++++++++++++------ nx/source/services/ns.c | 55 +++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index 31fd597e..11ca6784 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -244,6 +244,10 @@ Service* nsGetServiceSession_GetterInterface(void); /// Gets the Service object for IApplicationManagerInterface. Service* nsGetServiceSession_ApplicationManagerInterface(void); +/// Gets the Service object for IReadOnlyApplicationControlDataInterface via the cmd for that. +/// Only available on [5.1.0+]. +Result nsGetReadOnlyApplicationControlDataInterface(Service* srv_out); + /// Gets the Service object for IECommerceInterface via the cmd for that. /// Only available on [4.0.0+]. Result nsGetECommerceInterface(Service* srv_out); @@ -262,6 +266,22 @@ Result nsGetContentManagementInterface(Service* srv_out); ///@} +///@name IReadOnlyApplicationControlDataInterface +///@{ + +/** + * @brief Gets the \ref NsApplicationControlData for the specified application. + * @note Uses \ref nsGetReadOnlyApplicationControlDataInterface on [5.1.0+], otherwise IApplicationManagerInterface is used. + * @param[in] source Source, official sw uses ::NsApplicationControlSource_Storage. + * @param[in] application_id ApplicationId. + * @param[out] buffer \ref NsApplicationControlData + * @param[in] size Size of the buffer. + * @param[out] actual_size Actual output size. + */ +Result nsGetApplicationControlData(NsApplicationControlSource source, u64 application_id, NsApplicationControlData* buffer, size_t size, u64* actual_size); + +///@} + ///@name IECommerceInterface ///@{ @@ -560,16 +580,6 @@ Result nsUnregisterNetworkServiceAccount(AccountUid uid); */ Result nsUnregisterNetworkServiceAccountWithUserSaveDataDeletion(AccountUid uid); -/** - * @brief Gets the \ref NsApplicationControlData for the specified application. - * @param[in] source Source, official sw uses ::NsApplicationControlSource_Storage. - * @param[in] application_id ApplicationId. - * @param[out] buffer \ref NsApplicationControlData - * @param[in] size Size of the buffer. - * @param[out] actual_size Actual output size. - */ -Result nsGetApplicationControlData(NsApplicationControlSource source, u64 application_id, NsApplicationControlData* buffer, size_t size, u64* actual_size); - /** * @brief RequestDownloadApplicationControlData * @note \ref nifmInitialize must be used prior to this. Before using the cmd, this calls \ref nifmIsAnyInternetRequestAccepted with the output from \ref nifmGetClientId, an error is returned when that returns false. diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 076e648f..3a665891 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -46,6 +46,13 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) { return &g_nsAppManSrv; } +Result nsGetReadOnlyApplicationControlDataInterface(Service* srv_out) { + if (hosversionBefore(5,1,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7989); +} + Result nsGetECommerceInterface(Service* srv_out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -278,6 +285,37 @@ static Result _nsCheckNifm(void) { return nifmIsAnyInternetRequestAccepted(nifmGetClientId()) ? 0 : MAKERESULT(16, 340); } +// IReadOnlyApplicationControlDataInterface + +Result nsGetApplicationControlData(NsApplicationControlSource source, u64 application_id, NsApplicationControlData* buffer, size_t size, u64* actual_size) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + u32 cmd_id = 400; + if (hosversionAtLeast(5,1,0)) { + rc = nsGetReadOnlyApplicationControlDataInterface(&srv); + cmd_id = 0; + } + else + srv_ptr = &g_nsAppManSrv; + + const struct { + u8 source; + u8 pad[7]; + u64 application_id; + } in = { source, {0}, application_id }; + + u32 tmp=0; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, cmd_id, in, tmp, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { buffer, size } }, + ); + if (R_SUCCEEDED(rc) && actual_size) *actual_size = tmp; + + serviceClose(&srv); + return rc; +} + // IECommerceInterface Result nsRequestLinkDevice(AsyncResult *a, AccountUid uid) { @@ -611,23 +649,6 @@ Result nsUnregisterNetworkServiceAccountWithUserSaveDataDeletion(AccountUid uid) return _nsCmdInUidNoOut(&g_nsAppManSrv, uid, 221); } -Result nsGetApplicationControlData(NsApplicationControlSource source, u64 application_id, NsApplicationControlData* buffer, size_t size, u64* actual_size) { - const struct { - u8 source; - u8 pad[7]; - u64 application_id; - } in = { source, {0}, application_id }; - - u32 tmp=0; - - Result rc = serviceDispatchInOut(&g_nsAppManSrv, 400, in, tmp, - .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { buffer, size } }, - ); - if (R_SUCCEEDED(rc) && actual_size) *actual_size = tmp; - return rc; -} - Result nsRequestDownloadApplicationControlData(AsyncResult *a, u64 application_id) { Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; From 763b32060a48d74537bcd019ee03943b38c7ff92 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 29 Feb 2020 22:39:43 -0500 Subject: [PATCH 09/21] ns: Added nsGetApplicationDesiredLanguage. --- nx/include/switch/nacp.h | 1 + nx/include/switch/services/ns.h | 8 ++++++ nx/source/services/ns.c | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/nx/include/switch/nacp.h b/nx/include/switch/nacp.h index 4faffdc4..784581df 100644 --- a/nx/include/switch/nacp.h +++ b/nx/include/switch/nacp.h @@ -77,5 +77,6 @@ typedef struct { } NacpStruct; /// Get the NacpLanguageEntry from the input nacp corresponding to the current system language (this may fallback to other languages when needed). Output langentry is NULL if none found / content of entry is empty. +/// If you're using ns you may want to use \ref nsGetApplicationDesiredLanguage instead. Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry); diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index 11ca6784..26252f81 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -280,6 +280,14 @@ Result nsGetContentManagementInterface(Service* srv_out); */ Result nsGetApplicationControlData(NsApplicationControlSource source, u64 application_id, NsApplicationControlData* buffer, size_t size, u64* actual_size); +/** + * @brief GetApplicationDesiredLanguage. Selects a \ref NacpLanguageEntry to use from the specified \ref NacpStruct. + * @note Uses \ref nsGetReadOnlyApplicationControlDataInterface on [5.1.0+], otherwise IApplicationManagerInterface is used. + * @param[in] nacp \ref NacpStruct + * @param[out] langentry \ref NacpLanguageEntry + */ +Result nsGetApplicationDesiredLanguage(NacpStruct *nacp, NacpLanguageEntry **langentry); + ///@} ///@name IECommerceInterface diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 3a665891..7dd78433 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -316,6 +316,49 @@ Result nsGetApplicationControlData(NsApplicationControlSource source, u64 applic return rc; } +Result nsGetApplicationDesiredLanguage(NacpStruct *nacp, NacpLanguageEntry **langentry) { + if (nacp==NULL || langentry==NULL) + return MAKERESULT(Module_Libnx, LibnxError_BadInput); + + *langentry = NULL; + + NacpLanguageEntry *entry = NULL; + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + u32 cmd_id = 55; + if (hosversionAtLeast(5,1,0)) { + rc = nsGetReadOnlyApplicationControlDataInterface(&srv); + cmd_id = 1; + } + else + srv_ptr = &g_nsAppManSrv; + + u8 lang_bitmask=0, out=0; + + if (R_SUCCEEDED(rc)) { + for (u32 i=0; i<16; i++) { + entry = &nacp->lang[i]; + if (entry->name[0] || entry->author[0]) lang_bitmask |= BIT(i); + } + if (!lang_bitmask) { + *langentry = &nacp->lang[0]; + return 0; + } + } + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, cmd_id, lang_bitmask, out); + if (R_SUCCEEDED(rc)) { + if (out > 16) out = 0; + if (lang_bitmask & BIT(out)) + *langentry = &nacp->lang[out]; + else + rc = MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen); + } + + serviceClose(&srv); + return rc; +} + // IECommerceInterface Result nsRequestLinkDevice(AsyncResult *a, AccountUid uid) { From af2b4ab7c3d12dd9eba8fd41bbc95960103e75ba Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 1 Mar 2020 15:06:15 -0500 Subject: [PATCH 10/21] ns: Added nsGetApplicationManagerInterface(), and removed automatic IApplicationManagerInterface init on [3.0.0+]. Updated all IApplicationManagerInterface cmds to use service-session IApplicationManagerInterface on pre-3.0.0, otherwise nsGetApplicationManagerInterface() is used. Apps which use nsGetServiceSession_ApplicationManagerInterface must now use nsGetApplicationManagerInterface if running on [3.0.0+]. --- nx/include/switch/services/ns.h | 6 +- nx/source/services/ns.c | 577 +++++++++++++++++++++++++++----- 2 files changed, 495 insertions(+), 88 deletions(-) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index 26252f81..c9286547 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -241,7 +241,7 @@ void nsExit(void); /// Gets the Service object for the actual ns:* service session. Only initialized on [3.0.0+], on pre-3.0.0 see \ref nsGetServiceSession_ApplicationManagerInterface. Service* nsGetServiceSession_GetterInterface(void); -/// Gets the Service object for IApplicationManagerInterface. +/// Gets the Service object for IApplicationManagerInterface. Only initialized on pre-3.0.0, on [3.0.0+] use \ref nsGetApplicationManagerInterface. Service* nsGetServiceSession_ApplicationManagerInterface(void); /// Gets the Service object for IReadOnlyApplicationControlDataInterface via the cmd for that. @@ -256,6 +256,10 @@ Result nsGetECommerceInterface(Service* srv_out); /// Only available on [3.0.0+]. Result nsGetFactoryResetInterface(Service* srv_out); +/// Gets the Service object for IApplicationManagerInterface via the cmd for that. +/// Only available on [3.0.0+], on prior sysvers use \ref nsGetServiceSession_ApplicationManagerInterface. +Result nsGetApplicationManagerInterface(Service* srv_out); + /// Gets the Service object for IDownloadTaskInterface via the cmd for that. /// Only available on [3.0.0+]. Result nsGetDownloadTaskInterface(Service* srv_out); diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 7dd78433..d63f135d 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -26,16 +26,14 @@ Result _nsInitialize(void) { rc = smGetService(&g_nsGetterSrv, "ns:am2");//TODO: Support the other services?(Only useful when ns:am2 isn't accessible) if (R_FAILED(rc)) return rc; - rc = _nsGetSession(&g_nsGetterSrv, &g_nsAppManSrv, 7996); - return rc; } void _nsCleanup(void) { - serviceClose(&g_nsAppManSrv); - if(hosversionBefore(3,0,0)) return; - - serviceClose(&g_nsGetterSrv); + if(hosversionBefore(3,0,0)) + serviceClose(&g_nsAppManSrv); + else + serviceClose(&g_nsGetterSrv); } Service* nsGetServiceSession_GetterInterface(void) { @@ -67,6 +65,13 @@ Result nsGetFactoryResetInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7994); } +Result nsGetApplicationManagerInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7996); +} + Result nsGetDownloadTaskInterface(Service* srv_out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -101,6 +106,20 @@ static Result _nsCmdGetEvent(Service* srv, Event* out_event, bool autoclear, u32 return rc; } +static Result _nsManCmdGetEvent(Event* out_event, bool autoclear, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdGetEvent(srv_ptr, out_event, autoclear, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInHandle64NoOut(Service* srv, Handle handle, u64 inval, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, inval, .in_num_handles = 1, @@ -116,6 +135,20 @@ static Result _nsCmdNoIO(Service* srv, u32 cmd_id) { return serviceDispatch(srv, cmd_id); } +static Result _nsManCmdNoIO(u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoIO(srv_ptr, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInBool(Service* srv, bool inval, u32 cmd_id) { u8 in = inval!=0; @@ -126,6 +159,20 @@ static Result _nsCmdInU64(Service* srv, u64 inval, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, inval); } +static Result _nsManCmdInU64(u64 inval, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64(srv_ptr, inval, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInU64OutU64(Service* srv, u64 inval, u64 *out, u32 cmd_id) { return serviceDispatchInOut(srv, cmd_id, inval, *out); } @@ -141,6 +188,20 @@ static Result _nsCmdNoInOutBool(Service* srv, bool *out, u32 cmd_id) { return rc; } +static Result _nsManCmdNoInOutBool(bool *out, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdNoInOutBool(srv_ptr, out, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdNoInOutU64(Service* srv, u64 *out, u32 cmd_id) { return serviceDispatchOut(srv, cmd_id, *out); } @@ -155,6 +216,20 @@ static Result _nsCmdInU8U64NoOut(Service* srv, u8 in8, u64 in64, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, in); } +static Result _nsManCmdInU8U64NoOut(u8 in8, u64 in64, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU8U64NoOut(srv_ptr, in8, in64, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInU64OutStorageIdS64(Service* srv, u64 inval, NcmStorageId *storage_id, s64 *outval, u32 cmd_id) { struct { u8 storage_id; @@ -170,10 +245,38 @@ static Result _nsCmdInU64OutStorageIdS64(Service* srv, u64 inval, NcmStorageId * return rc; } +static Result _nsManCmdInU64OutStorageIdS64(u64 inval, NcmStorageId *storage_id, s64 *outval, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64OutStorageIdS64(srv_ptr, inval, storage_id, outval, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInUidNoOut(Service* srv, AccountUid uid, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, uid); } +static Result _nsManCmdInUidNoOut(AccountUid uid, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInUidNoOut(srv_ptr, uid, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdNoInOutSystemUpdateProgress(Service* srv, NsSystemUpdateProgress *out, u32 cmd_id) { return serviceDispatchOut(srv, cmd_id, *out); } @@ -249,6 +352,20 @@ static Result _nsCmdInU64OutAsyncValue(Service* srv, AsyncValue *a, u64 inval, u return rc; } +static Result _nsManCmdInU64OutAsyncValue(AsyncValue *a, u64 inval, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64OutAsyncValue(srv_ptr, a, inval, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInU64OutAsyncResult(Service* srv, AsyncResult *a, u64 inval, u32 cmd_id) { memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; @@ -265,6 +382,20 @@ static Result _nsCmdInU64OutAsyncResult(Service* srv, AsyncResult *a, u64 inval, return rc; } +static Result _nsManCmdInU64OutAsyncResult(AsyncResult *a, u64 inval, u32 cmd_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsCmdInU64OutAsyncResult(srv_ptr, a, inval, cmd_id); + + serviceClose(&srv); + return rc; +} + static Result _nsCmdInUidOutAsyncResult(Service* srv, AsyncResult *a, AccountUid uid, u32 cmd_id) { memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; @@ -482,18 +613,35 @@ Result nsResetToFactorySettingsWithPlatformRegionAuthentication(void) { // IApplicationManagerInterface Result nsListApplicationRecord(NsApplicationRecord* records, s32 count, s32 entry_offset, s32* out_entrycount) { - return serviceDispatchInOut(&g_nsAppManSrv, 0, entry_offset, *out_entrycount, + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 0, entry_offset, *out_entrycount, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { records, count*sizeof(NsApplicationRecord) } }, ); + + serviceClose(&srv); + return rc; } Result nsGetApplicationRecordUpdateSystemEvent(Event* out_event) { - return _nsCmdGetEvent(&g_nsAppManSrv, out_event, true, 2); + return _nsManCmdGetEvent(out_event, true, 2); } Result nsGetApplicationViewDeprecated(NsApplicationViewDeprecated *views, const u64 *application_ids, s32 count) { - return serviceDispatch(&g_nsAppManSrv, 3, + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatch(srv_ptr, 3, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -503,21 +651,31 @@ Result nsGetApplicationViewDeprecated(NsApplicationViewDeprecated *views, const { application_ids, count*sizeof(u64) }, }, ); + + serviceClose(&srv); + return rc; } Result nsDeleteApplicationEntity(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 4); + return _nsManCmdInU64(application_id, 4); } Result nsDeleteApplicationCompletely(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 5); + return _nsManCmdInU64(application_id, 5); } Result nsDeleteRedundantApplicationEntity(void) { - return _nsCmdNoIO(&g_nsAppManSrv, 7); + return _nsManCmdNoIO(7); } Result nsIsApplicationEntityMovable(u64 application_id, NcmStorageId storage_id, bool *out) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { u8 storage_id; u8 pad[7]; @@ -525,126 +683,153 @@ Result nsIsApplicationEntityMovable(u64 application_id, NcmStorageId storage_id, } in = { storage_id, {0}, application_id }; u8 tmp=0; - Result rc = serviceDispatchInOut(&g_nsAppManSrv, 8, in, tmp); + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 8, in, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + + serviceClose(&srv); return rc; } Result nsMoveApplicationEntity(u64 application_id, NcmStorageId storage_id) { - return _nsCmdInU8U64NoOut(&g_nsAppManSrv, storage_id, application_id, 9); + return _nsManCmdInU8U64NoOut(storage_id, application_id, 9); } Result nsRequestApplicationUpdateInfo(AsyncValue *a, u64 application_id) { Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncValue(&g_nsAppManSrv, a, application_id, 30); + return _nsManCmdInU64OutAsyncValue(a, application_id, 30); } Result nsCancelApplicationDownload(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 32); + return _nsManCmdInU64(application_id, 32); } Result nsResumeApplicationDownload(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 33); + return _nsManCmdInU64(application_id, 33); } Result nsCheckApplicationLaunchVersion(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 38); + return _nsManCmdInU64(application_id, 38); } Result nsCalculateApplicationDownloadRequiredSize(u64 application_id, NcmStorageId *storage_id, s64 *size) { - return _nsCmdInU64OutStorageIdS64(&g_nsAppManSrv, application_id, storage_id, size, 41); + return _nsManCmdInU64OutStorageIdS64(application_id, storage_id, size, 41); } Result nsCleanupSdCard(void) { - return _nsCmdNoIO(&g_nsAppManSrv, 42); + return _nsManCmdNoIO(42); } Result nsGetSdCardMountStatusChangedEvent(Event* out_event) { - return _nsCmdGetEvent(&g_nsAppManSrv, out_event, false, 44); + return _nsManCmdGetEvent(out_event, false, 44); } Result nsGetGameCardUpdateDetectionEvent(Event* out_event) { - return _nsCmdGetEvent(&g_nsAppManSrv, out_event, false, 52); + return _nsManCmdGetEvent(out_event, false, 52); } Result nsDisableApplicationAutoDelete(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 53); + return _nsManCmdInU64(application_id, 53); } Result nsEnableApplicationAutoDelete(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 54); + return _nsManCmdInU64(application_id, 54); } Result nsSetApplicationTerminateResult(u64 application_id, Result res) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { Result res; u32 pad; u64 application_id; } in = { res, 0, application_id }; - return serviceDispatchIn(&g_nsAppManSrv, 56, in); + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 56, in); + + serviceClose(&srv); + return rc; } Result nsClearApplicationTerminateResult(u64 application_id) { - return _nsCmdInU64(&g_nsAppManSrv, application_id, 57); + return _nsManCmdInU64(application_id, 57); } Result nsGetLastSdCardMountUnexpectedResult(void) { - return _nsCmdNoIO(&g_nsAppManSrv, 58); + return _nsManCmdNoIO(58); } Result nsGetRequestServerStopper(NsRequestServerStopper *r) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsGetSession(&g_nsAppManSrv, &r->s, 65); + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = _nsGetSession(srv_ptr, &r->s, 65); + + serviceClose(&srv); + return rc; } Result nsCancelApplicationApplyDelta(u64 application_id) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64(&g_nsAppManSrv, application_id, 67); + return _nsManCmdInU64(application_id, 67); } Result nsResumeApplicationApplyDelta(u64 application_id) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64(&g_nsAppManSrv, application_id, 68); + return _nsManCmdInU64(application_id, 68); } Result nsCalculateApplicationApplyDeltaRequiredSize(u64 application_id, NcmStorageId *storage_id, s64 *size) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64OutStorageIdS64(&g_nsAppManSrv, application_id, storage_id, size, 69); + return _nsManCmdInU64OutStorageIdS64(application_id, storage_id, size, 69); } Result nsResumeAll(void) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoIO(&g_nsAppManSrv, 70); + return _nsManCmdNoIO(70); } Result nsGetStorageSize(NcmStorageId storage_id, s64 *total_space_size, s64 *free_space_size) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + struct { s64 total_space_size; s64 free_space_size; } out; u8 tmp = storage_id; - Result rc = serviceDispatchInOut(&g_nsAppManSrv, 71, tmp, out); + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 71, tmp, out); if (R_SUCCEEDED(rc)) { if (total_space_size) *total_space_size = out.total_space_size; if (free_space_size) *free_space_size = out.free_space_size; } + + serviceClose(&srv); return rc; } @@ -655,51 +840,74 @@ Result nsRequestUpdateApplication2(AsyncResult *a, u64 application_id) { Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncResult(&g_nsAppManSrv, a, application_id, 85); + return _nsManCmdInU64OutAsyncResult(a, application_id, 85); } Result nsDeleteUserSaveDataAll(NsProgressMonitorForDeleteUserSaveDataAll *p, AccountUid uid) { - return serviceDispatchIn(&g_nsAppManSrv, 201, uid, + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 201, uid, .out_num_objects = 1, .out_objects = &p->s, ); + + serviceClose(&srv); + return rc; } Result nsDeleteUserSystemSaveData(AccountUid uid, u64 system_save_data_id) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { AccountUid uid; u64 system_save_data_id; } in = { uid, system_save_data_id }; - return serviceDispatchIn(&g_nsAppManSrv, 210, in); + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 210, in); + + serviceClose(&srv); + return rc; } Result nsDeleteSaveData(FsSaveDataSpaceId save_data_space_id, u64 save_data_id) { if (hosversionBefore(6,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU8U64NoOut(&g_nsAppManSrv, save_data_space_id, save_data_id, 211); + return _nsManCmdInU8U64NoOut(save_data_space_id, save_data_id, 211); } Result nsUnregisterNetworkServiceAccount(AccountUid uid) { - return _nsCmdInUidNoOut(&g_nsAppManSrv, uid, 220); + return _nsManCmdInUidNoOut(uid, 220); } Result nsUnregisterNetworkServiceAccountWithUserSaveDataDeletion(AccountUid uid) { if (hosversionBefore(6,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInUidNoOut(&g_nsAppManSrv, uid, 221); + return _nsManCmdInUidNoOut(uid, 221); } Result nsRequestDownloadApplicationControlData(AsyncResult *a, u64 application_id) { Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncResult(&g_nsAppManSrv, a, application_id, 402); + return _nsManCmdInU64OutAsyncResult(a, application_id, 402); } static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSource source, const u64 *application_ids, s32 count, TransferMemory *tmem, u32 cmd_id) { // [8.0.0+] + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u8 source; u8 pad[7]; @@ -708,7 +916,7 @@ static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSou memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, cmd_id, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, cmd_id, in, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { application_ids, count*sizeof(u64) } }, .in_num_handles = 1, @@ -721,6 +929,8 @@ static Result _nsListApplicationTitleIcon(AsyncValue *a, NsApplicationControlSou if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + + serviceClose(&srv); return rc; } @@ -759,7 +969,7 @@ Result nsRequestCheckGameCardRegistration(AsyncResult *a, u64 application_id) { Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncResult(&g_nsAppManSrv, a, application_id, 502); + return _nsManCmdInU64OutAsyncResult(a, application_id, 502); } Result nsRequestGameCardRegistrationGoldPoint(AsyncValue *a, AccountUid uid, u64 application_id) { @@ -769,6 +979,12 @@ Result nsRequestGameCardRegistrationGoldPoint(AsyncValue *a, AccountUid uid, u64 Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; + Service srv={0}, *srv_ptr = &srv; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { AccountUid uid; u64 application_id; @@ -776,7 +992,7 @@ Result nsRequestGameCardRegistrationGoldPoint(AsyncValue *a, AccountUid uid, u64 memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - rc = serviceDispatchIn(&g_nsAppManSrv, 503, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 503, in, .out_num_objects = 1, .out_objects = &a->s, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, @@ -786,6 +1002,7 @@ Result nsRequestGameCardRegistrationGoldPoint(AsyncValue *a, AccountUid uid, u64 if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + serviceClose(&srv); return rc; } @@ -796,6 +1013,12 @@ Result nsRequestRegisterGameCard(AsyncResult *a, AccountUid uid, u64 application Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; + Service srv={0}, *srv_ptr = &srv; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { s32 inval; u32 pad; @@ -805,7 +1028,7 @@ Result nsRequestRegisterGameCard(AsyncResult *a, AccountUid uid, u64 application memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - rc = serviceDispatchIn(&g_nsAppManSrv, 504, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 504, in, .out_num_objects = 1, .out_objects = &a->s, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, @@ -815,6 +1038,7 @@ Result nsRequestRegisterGameCard(AsyncResult *a, AccountUid uid, u64 application if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + serviceClose(&srv); return rc; } @@ -822,62 +1046,77 @@ Result nsGetGameCardMountFailureEvent(Event* out_event) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdGetEvent(&g_nsAppManSrv, out_event, false, 505); + return _nsManCmdGetEvent(out_event, false, 505); } Result nsIsGameCardInserted(bool *out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoInOutBool(&g_nsAppManSrv, out, 506); + return _nsManCmdNoInOutBool(out, 506); } Result nsEnsureGameCardAccess(void) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoIO(&g_nsAppManSrv, 507); + return _nsManCmdNoIO(507); } Result nsGetLastGameCardMountFailureResult(void) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoIO(&g_nsAppManSrv, 508); + return _nsManCmdNoIO(508); } Result nsListApplicationIdOnGameCard(u64 *application_ids, s32 count, s32 *total_out) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchOut(&g_nsAppManSrv, 509, *total_out, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 509, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { application_ids, count*sizeof(u64) } }, ); + + serviceClose(&srv); + return rc; } Result nsTouchApplication(u64 application_id) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64(&g_nsAppManSrv, application_id, 904); + return _nsManCmdInU64(application_id, 904); } Result nsIsApplicationUpdateRequested(u64 application_id, bool *flag, u32 *out) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + struct { u8 flag; u8 pad[3]; u32 out; } tmpout; - Result rc = serviceDispatchInOut(&g_nsAppManSrv, 906, application_id, tmpout); + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 906, application_id, tmpout); if (R_SUCCEEDED(rc)) { if (flag) *flag = tmpout.flag & 1; if (out) *out = tmpout.out; } + + serviceClose(&srv); return rc; } @@ -885,10 +1124,17 @@ Result nsWithdrawApplicationUpdateRequest(u64 application_id) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64(&g_nsAppManSrv, application_id, 907); + return _nsManCmdInU64(application_id, 907); } static Result _nsRequestVerifyApplicationDeprecated(NsProgressAsyncResult *a, u64 application_id, TransferMemory *tmem) { + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + const struct { u64 application_id; u64 size; @@ -896,7 +1142,7 @@ static Result _nsRequestVerifyApplicationDeprecated(NsProgressAsyncResult *a, u6 memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, 1000, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(srv_ptr, 1000, in, .in_num_handles = 1, .in_handles = { tmem->handle }, .out_num_objects = 1, @@ -907,10 +1153,15 @@ static Result _nsRequestVerifyApplicationDeprecated(NsProgressAsyncResult *a, u6 if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + + serviceClose(&srv); return rc; } static Result _nsRequestVerifyApplication(NsProgressAsyncResult *a, u64 application_id, u32 unk, TransferMemory *tmem) { // [5.0.0+] + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u32 unk; u32 pad; @@ -920,7 +1171,7 @@ static Result _nsRequestVerifyApplication(NsProgressAsyncResult *a, u64 applicat memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, 1003, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 1003, in, .in_num_handles = 1, .in_handles = { tmem->handle }, .out_num_objects = 1, @@ -931,6 +1182,8 @@ static Result _nsRequestVerifyApplication(NsProgressAsyncResult *a, u64 applicat if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + + serviceClose(&srv); return rc; } @@ -938,9 +1191,12 @@ Result nsRequestVerifyAddOnContentsRights(NsProgressAsyncResult *a, u64 applicat if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, 1002, application_id, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 1002, application_id, .out_num_objects = 1, .out_objects = &a->s, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, @@ -949,6 +1205,8 @@ Result nsRequestVerifyAddOnContentsRights(NsProgressAsyncResult *a, u64 applicat if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + + serviceClose(&srv); return rc; } @@ -972,9 +1230,18 @@ Result nsIsAnyApplicationEntityInstalled(u64 application_id, bool *out) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}, *srv_ptr = &srv; + Result rc=0; + if (hosversionAtLeast(3,0,0)) + rc = nsGetApplicationManagerInterface(&srv); + else + srv_ptr = &g_nsAppManSrv; + u8 tmp=0; - Result rc = serviceDispatchInOut(&g_nsAppManSrv, 1300, application_id, tmp); + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(srv_ptr, 1300, application_id, tmp); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + + serviceClose(&srv); return rc; } @@ -982,40 +1249,49 @@ Result nsCleanupUnavailableAddOnContents(u64 application_id, AccountUid uid) { if (hosversionBefore(6,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u64 application_id; AccountUid uid; } in = { application_id, uid }; - return serviceDispatchIn(&g_nsAppManSrv, 1309, in); + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 1309, in); + + serviceClose(&srv); + return rc; } Result nsFormatSdCard(void) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoIO(&g_nsAppManSrv, 1500); + return _nsManCmdNoIO(1500); } Result nsNeedsSystemUpdateToFormatSdCard(bool *out) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoInOutBool(&g_nsAppManSrv, out, 1501); + return _nsManCmdNoInOutBool(out, 1501); } Result nsGetLastSdCardFormatUnexpectedResult(void) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdNoIO(&g_nsAppManSrv, 1502); + return _nsManCmdNoIO(1502); } Result nsGetApplicationView(NsApplicationView *views, const u64 *application_ids, s32 count) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatch(&g_nsAppManSrv, 1701, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatch(&srv, 1701, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1025,23 +1301,35 @@ Result nsGetApplicationView(NsApplicationView *views, const u64 *application_ids { application_ids, count*sizeof(u64) }, }, ); + + serviceClose(&srv); + return rc; } Result nsGetApplicationViewDownloadErrorContext(u64 application_id, ErrorContext *context) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchIn(&g_nsAppManSrv, 1703, application_id, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 1703, application_id, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { context, sizeof(*context) } }, ); + + serviceClose(&srv); + return rc; } Result nsGetApplicationViewWithPromotionInfo(NsApplicationViewWithPromotionInfo *out, const u64 *application_ids, s32 count) { if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatch(&g_nsAppManSrv, 1704, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatch(&srv, 1704, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1051,6 +1339,9 @@ Result nsGetApplicationViewWithPromotionInfo(NsApplicationViewWithPromotionInfo { application_ids, count*sizeof(u64) }, }, ); + + serviceClose(&srv); + return rc; } Result nsRequestDownloadApplicationPrepurchasedRights(AsyncResult *a, u64 application_id) { @@ -1060,24 +1351,33 @@ Result nsRequestDownloadApplicationPrepurchasedRights(AsyncResult *a, u64 applic Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncResult(&g_nsAppManSrv, a, application_id, 1901); + return _nsManCmdInU64OutAsyncResult(a, application_id, 1901); } Result nsGetSystemDeliveryInfo(NsSystemDeliveryInfo *info) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatch(&g_nsAppManSrv, 2000, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatch(&srv, 2000, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { info, sizeof(*info) } }, ); + + serviceClose(&srv); + return rc; } Result nsSelectLatestSystemDeliveryInfo(const NsSystemDeliveryInfo *sys_list, s32 sys_count, const NsSystemDeliveryInfo *base_info, const NsApplicationDeliveryInfo *app_list, s32 app_count, s32 *index) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchOut(&g_nsAppManSrv, 2001, *index, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2001, *index, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1089,44 +1389,64 @@ Result nsSelectLatestSystemDeliveryInfo(const NsSystemDeliveryInfo *sys_list, s3 { app_list, app_count*sizeof(NsApplicationDeliveryInfo) }, }, ); + + serviceClose(&srv); + return rc; } Result nsVerifyDeliveryProtocolVersion(const NsSystemDeliveryInfo *info) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatch(&g_nsAppManSrv, 2002, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatch(&srv, 2002, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { info, sizeof(*info) } }, ); + + serviceClose(&srv); + return rc; } Result nsGetApplicationDeliveryInfo(NsApplicationDeliveryInfo *info, s32 count, u64 application_id, u32 attr, s32 *total_out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u32 attr; u32 pad; u64 application_id; } in = { attr, 0, application_id }; - return serviceDispatchInOut(&g_nsAppManSrv, 2003, in, *total_out, + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2003, in, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { info, count*sizeof(NsApplicationDeliveryInfo) } }, ); + + serviceClose(&srv); + return rc; } Result nsHasAllContentsToDeliver(const NsApplicationDeliveryInfo *info, s32 count, bool *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + u8 tmp=0; - Result rc = serviceDispatchOut(&g_nsAppManSrv, 2004, tmp, + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2004, tmp, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { info, count*sizeof(NsApplicationDeliveryInfo) } }, ); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + + serviceClose(&srv); return rc; } @@ -1134,7 +1454,10 @@ Result nsCompareApplicationDeliveryInfo(const NsApplicationDeliveryInfo *info0, if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchOut(&g_nsAppManSrv, 2005, out, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2005, out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1144,14 +1467,20 @@ Result nsCompareApplicationDeliveryInfo(const NsApplicationDeliveryInfo *info0, { info1, count1*sizeof(NsApplicationDeliveryInfo) }, }, ); + + serviceClose(&srv); + return rc; } Result nsCanDeliverApplication(const NsApplicationDeliveryInfo *info0, s32 count0, const NsApplicationDeliveryInfo *info1, s32 count1, bool *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + u8 tmp=0; - Result rc = serviceDispatchOut(&g_nsAppManSrv, 2006, tmp, + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2006, tmp, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1162,6 +1491,8 @@ Result nsCanDeliverApplication(const NsApplicationDeliveryInfo *info0, s32 count }, ); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + + serviceClose(&srv); return rc; } @@ -1169,7 +1500,10 @@ Result nsListContentMetaKeyToDeliverApplication(NcmContentMetaKey *meta, s32 met if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchInOut(&g_nsAppManSrv, 2007, meta_index, *total_out, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2007, meta_index, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1179,14 +1513,20 @@ Result nsListContentMetaKeyToDeliverApplication(NcmContentMetaKey *meta, s32 met { info, info_count*sizeof(NsApplicationDeliveryInfo) }, }, ); + + serviceClose(&srv); + return rc; } Result nsNeedsSystemUpdateToDeliverApplication(const NsApplicationDeliveryInfo *info, s32 count, const NsSystemDeliveryInfo *sys_info, bool *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + u8 tmp=0; - Result rc = serviceDispatchOut(&g_nsAppManSrv, 2008, tmp, + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2008, tmp, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1197,6 +1537,8 @@ Result nsNeedsSystemUpdateToDeliverApplication(const NsApplicationDeliveryInfo * }, ); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + + serviceClose(&srv); return rc; } @@ -1204,16 +1546,25 @@ Result nsEstimateRequiredSize(const NcmContentMetaKey *meta, s32 count, s64 *out if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchOut(&g_nsAppManSrv, 2009, *out, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2009, *out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { meta, count*sizeof(NcmContentMetaKey) } }, ); + + serviceClose(&srv); + return rc; } Result nsRequestReceiveApplication(AsyncResult *a, u32 addr, u16 port, u64 application_id, const NcmContentMetaKey *meta, s32 count, NcmStorageId storage_id) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u8 storage_id; u8 pad; @@ -1225,7 +1576,7 @@ Result nsRequestReceiveApplication(AsyncResult *a, u32 addr, u16 port, u64 appli memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, 2010, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 2010, in, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { meta, count*sizeof(NcmContentMetaKey) } }, .out_num_objects = 1, @@ -1237,6 +1588,7 @@ Result nsRequestReceiveApplication(AsyncResult *a, u32 addr, u16 port, u64 appli if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + serviceClose(&srv); return rc; } @@ -1244,20 +1596,29 @@ Result nsCommitReceiveApplication(u64 application_id) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _nsCmdInU64(&g_nsAppManSrv, application_id, 2011); + return _nsManCmdInU64(application_id, 2011); } Result nsGetReceiveApplicationProgress(u64 application_id, NsReceiveApplicationProgress *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchInOut(&g_nsAppManSrv, 2012, application_id, *out); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2012, application_id, *out); + + serviceClose(&srv); + return rc; } Result nsRequestSendApplication(AsyncResult *a, u32 addr, u16 port, u64 application_id, const NcmContentMetaKey *meta, s32 count) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u16 port; u16 pad2; @@ -1267,7 +1628,7 @@ Result nsRequestSendApplication(AsyncResult *a, u32 addr, u16 port, u64 applicat memset(a, 0, sizeof(*a)); Handle event = INVALID_HANDLE; - Result rc = serviceDispatchIn(&g_nsAppManSrv, 2013, in, + if (R_SUCCEEDED(rc)) rc = serviceDispatchIn(&srv, 2013, in, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { meta, count*sizeof(NcmContentMetaKey) } }, .out_num_objects = 1, @@ -1279,6 +1640,7 @@ Result nsRequestSendApplication(AsyncResult *a, u32 addr, u16 port, u64 applicat if (R_SUCCEEDED(rc)) eventLoadRemote(&a->event, event, false); + serviceClose(&srv); return rc; } @@ -1286,14 +1648,23 @@ Result nsGetSendApplicationProgress(u64 application_id, NsSendApplicationProgres if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchInOut(&g_nsAppManSrv, 2014, application_id, *out); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2014, application_id, *out); + + serviceClose(&srv); + return rc; } Result nsCompareSystemDeliveryInfo(const NsSystemDeliveryInfo *info0, const NsSystemDeliveryInfo *info1, s32 *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchOut(&g_nsAppManSrv, 2015, out, + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2015, out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1303,34 +1674,48 @@ Result nsCompareSystemDeliveryInfo(const NsSystemDeliveryInfo *info0, const NsSy { info1, sizeof(*info1) }, }, ); + + serviceClose(&srv); + return rc; } Result nsListNotCommittedContentMeta(NcmContentMetaKey *meta, s32 count, u64 application_id, s32 unk, s32 *total_out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { s32 unk; u32 pad; u64 application_id; } in = { unk, 0, application_id }; - return serviceDispatchInOut(&g_nsAppManSrv, 2016, in, *total_out, + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2016, in, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { meta, count*sizeof(NcmContentMetaKey) } }, ); + + serviceClose(&srv); + return rc; } Result nsGetApplicationDeliveryInfoHash(const NsApplicationDeliveryInfo *info, s32 count, u8 *out_hash) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + u8 tmp[0x20]; - Result rc = serviceDispatchOut(&g_nsAppManSrv, 2018, tmp, + if (R_SUCCEEDED(rc)) rc = serviceDispatchOut(&srv, 2018, tmp, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, .buffers = { { info, count*sizeof(NsApplicationDeliveryInfo) } }, ); if (R_SUCCEEDED(rc) && out_hash) memcpy(out_hash, tmp, sizeof(tmp)); + + serviceClose(&srv); return rc; } @@ -1338,13 +1723,22 @@ Result nsGetApplicationTerminateResult(u64 application_id, Result *res) { if (hosversionBefore(6,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return serviceDispatchInOut(&g_nsAppManSrv, 2100, application_id, *res); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2100, application_id, *res); + + serviceClose(&srv); + return rc; } Result nsGetApplicationRightsOnClient(NsApplicationRightsOnClient *rights, s32 count, u64 application_id, AccountUid uid, u32 flags, s32 *total_out) { if (hosversionBefore(6,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + const struct { u32 flags; u32 pad; @@ -1352,10 +1746,13 @@ Result nsGetApplicationRightsOnClient(NsApplicationRightsOnClient *rights, s32 c AccountUid uid; } in = { flags, 0, application_id, uid }; - return serviceDispatchInOut(&g_nsAppManSrv, 2050, in, *total_out, + if (R_SUCCEEDED(rc)) rc = serviceDispatchInOut(&srv, 2050, in, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, .buffers = { { rights, count*sizeof(NsApplicationRightsOnClient) } }, ); + + serviceClose(&srv); + return rc; } Result nsRequestNoDownloadRightsErrorResolution(AsyncValue *a, u64 application_id) { @@ -1365,7 +1762,7 @@ Result nsRequestNoDownloadRightsErrorResolution(AsyncValue *a, u64 application_i Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncValue(&g_nsAppManSrv, a, application_id, 2351); + return _nsManCmdInU64OutAsyncValue(a, application_id, 2351); } Result nsRequestResolveNoDownloadRightsError(AsyncValue *a, u64 application_id) { @@ -1375,16 +1772,19 @@ Result nsRequestResolveNoDownloadRightsError(AsyncValue *a, u64 application_id) Result rc = _nsCheckNifm(); if (R_FAILED(rc)) return rc; - return _nsCmdInU64OutAsyncValue(&g_nsAppManSrv, a, application_id, 2352); + return _nsManCmdInU64OutAsyncValue(a, application_id, 2352); } Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, AccountUid uid) { if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + Service srv={0}; + Result rc = nsGetApplicationManagerInterface(&srv); + // These are arrays, but official sw uses hard-coded value 1 for array-count. - return serviceDispatch(&g_nsAppManSrv, 2400, + if (R_SUCCEEDED(rc)) rc = serviceDispatch(&srv, 2400, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, SfBufferAttr_HipcMapAlias | SfBufferAttr_In, @@ -1396,6 +1796,9 @@ Result nsGetPromotionInfo(NsPromotionInfo *promotion, u64 application_id, Accoun { &uid, sizeof(AccountUid) }, }, ); + + serviceClose(&srv); + return rc; } // IDownloadTaskInterface From f589c952142d86d0784b3dd34f6b38b65ce307be Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 3 Mar 2020 14:47:22 -0500 Subject: [PATCH 11/21] ns: Added support for using the other services as fallback on [3.0.0+] when ns:am2 isn't available. --- nx/source/services/ns.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index d63f135d..45fb4b81 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -19,12 +19,15 @@ NX_GENERATE_SERVICE_GUARD(ns); Result _nsInitialize(void) { Result rc=0; + const char *servarray[5] = {"ns:ec", "ns:web", "ns:rid", "ns:rt", "ns:am2"}; // This is the order used used by official sw, however the below loop uses this in reverse since ns:am2 is last in the list. if(hosversionBefore(3,0,0)) return smGetService(&g_nsAppManSrv, "ns:am"); - rc = smGetService(&g_nsGetterSrv, "ns:am2");//TODO: Support the other services?(Only useful when ns:am2 isn't accessible) - if (R_FAILED(rc)) return rc; + for (s32 i=4; i>=0; i--) { + rc = smGetService(&g_nsGetterSrv, servarray[i]); + if (R_SUCCEEDED(rc)) break; + } return rc; } From c85dd5fe2fb07dd8c5e4c3145619e5127e9f73dc Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 3 Mar 2020 16:27:44 -0500 Subject: [PATCH 12/21] ns: Added nsGetDynamicRightsInterface, nsGetReadOnlyApplicationRecordInterface, nsGetApplicationVersionInterface, nsGetAccountProxyInterface, nsGetDocumentInterface. --- nx/include/switch/services/ns.h | 20 +++++++++++++++++++ nx/source/services/ns.c | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index c9286547..c4383481 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -244,18 +244,34 @@ Service* nsGetServiceSession_GetterInterface(void); /// Gets the Service object for IApplicationManagerInterface. Only initialized on pre-3.0.0, on [3.0.0+] use \ref nsGetApplicationManagerInterface. Service* nsGetServiceSession_ApplicationManagerInterface(void); +/// Gets the Service object for IDynamicRightsInterface via the cmd for that. +/// Only available on [6.0.0+]. +Result nsGetDynamicRightsInterface(Service* srv_out); + /// Gets the Service object for IReadOnlyApplicationControlDataInterface via the cmd for that. /// Only available on [5.1.0+]. Result nsGetReadOnlyApplicationControlDataInterface(Service* srv_out); +/// Gets the Service object for IReadOnlyApplicationRecordInterface via the cmd for that. +/// Only available on [5.0.0+]. +Result nsGetReadOnlyApplicationRecordInterface(Service* srv_out); + /// Gets the Service object for IECommerceInterface via the cmd for that. /// Only available on [4.0.0+]. Result nsGetECommerceInterface(Service* srv_out); +/// Gets the Service object for IApplicationVersionInterface via the cmd for that. +/// Only available on [4.0.0+]. +Result nsGetApplicationVersionInterface(Service* srv_out); + /// Gets the Service object for IFactoryResetInterface via the cmd for that. /// Only available on [3.0.0+]. Result nsGetFactoryResetInterface(Service* srv_out); +/// Gets the Service object for IAccountProxyInterface via the cmd for that. +/// Only available on [3.0.0+]. +Result nsGetAccountProxyInterface(Service* srv_out); + /// Gets the Service object for IApplicationManagerInterface via the cmd for that. /// Only available on [3.0.0+], on prior sysvers use \ref nsGetServiceSession_ApplicationManagerInterface. Result nsGetApplicationManagerInterface(Service* srv_out); @@ -268,6 +284,10 @@ Result nsGetDownloadTaskInterface(Service* srv_out); /// Only available on [3.0.0+]. Result nsGetContentManagementInterface(Service* srv_out); +/// Gets the Service object for IDocumentInterface via the cmd for that. +/// Only available on [3.0.0+]. +Result nsGetDocumentInterface(Service* srv_out); + ///@} ///@name IReadOnlyApplicationControlDataInterface diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 45fb4b81..cf55029e 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -47,6 +47,13 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) { return &g_nsAppManSrv; } +Result nsGetDynamicRightsInterface(Service* srv_out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7988); +} + Result nsGetReadOnlyApplicationControlDataInterface(Service* srv_out) { if (hosversionBefore(5,1,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -54,6 +61,13 @@ Result nsGetReadOnlyApplicationControlDataInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7989); } +Result nsGetReadOnlyApplicationRecordInterface(Service* srv_out) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7991); +} + Result nsGetECommerceInterface(Service* srv_out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -61,6 +75,13 @@ Result nsGetECommerceInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7992); } +Result nsGetApplicationVersionInterface(Service* srv_out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7993); +} + Result nsGetFactoryResetInterface(Service* srv_out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -68,6 +89,13 @@ Result nsGetFactoryResetInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7994); } +Result nsGetAccountProxyInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7995); +} + Result nsGetApplicationManagerInterface(Service* srv_out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -89,6 +117,13 @@ Result nsGetContentManagementInterface(Service* srv_out) { return _nsGetSession(&g_nsGetterSrv, srv_out, 7998); } +Result nsGetDocumentInterface(Service* srv_out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nsGetSession(&g_nsGetterSrv, srv_out, 7999); +} + static Result _nsGetSession(Service* srv, Service* srv_out, u32 cmd_id) { return serviceDispatch(srv, cmd_id, .out_num_objects = 1, From 44ec13169da0c76d174b730acef27501f0632f04 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 5 Mar 2020 10:39:29 -0500 Subject: [PATCH 13/21] pl: Removed unneeded plExit call from _plInitialize on errors, which is not needed with new-ipc. --- nx/source/services/pl.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/nx/source/services/pl.c b/nx/source/services/pl.c index b8f9187c..9e33e77b 100644 --- a/nx/source/services/pl.c +++ b/nx/source/services/pl.c @@ -29,8 +29,6 @@ Result _plInitialize(void) { } } - if (R_FAILED(rc)) plExit(); - return rc; } From 1b1620f7bbd03e1be3eefe24f2c3bba29fe55eb4 Mon Sep 17 00:00:00 2001 From: 3096 Date: Thu, 5 Mar 2020 22:49:46 -0800 Subject: [PATCH 14/21] apm: add apmGetPerformanceMode --- nx/include/switch/services/apm.h | 6 ++++++ nx/source/services/apm.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/nx/include/switch/services/apm.h b/nx/include/switch/services/apm.h index b1d44e34..2c792db9 100644 --- a/nx/include/switch/services/apm.h +++ b/nx/include/switch/services/apm.h @@ -33,6 +33,12 @@ Service* apmGetServiceSession(void); /// Gets the Service object for ISession. Service* apmGetServiceSession_Session(void); +/** + * @brief Gets the current ApmPerformanceMode. + * @param[out] out_performanceMode ApmPerformanceMode + */ +Result apmGetPerformanceMode(ApmPerformanceMode* out_performanceMode); + /** * @brief Sets the PerformanceConfiguration for the specified PerformanceMode. * @param[in] PerformanceMode \ref ApmPerformanceMode diff --git a/nx/source/services/apm.c b/nx/source/services/apm.c index 1eddb72e..02650b83 100644 --- a/nx/source/services/apm.c +++ b/nx/source/services/apm.c @@ -39,6 +39,10 @@ static Result _apmCmdGetSession(Service* srv, Service* srv_out, u32 cmd_id) { ); } +Result apmGetPerformanceMode(ApmPerformanceMode* out_performanceMode) { + return serviceDispatchOut(&g_apmSrv, 1, *out_performanceMode); +} + Result apmSetPerformanceConfiguration(ApmPerformanceMode PerformanceMode, u32 PerformanceConfiguration) { const struct { u32 PerformanceMode; From c3b0b63471ee5309ea5040ad98f21919022ac9c7 Mon Sep 17 00:00:00 2001 From: SciresM Date: Sat, 7 Mar 2020 03:40:02 -0800 Subject: [PATCH 15/21] fs: add IsSignedSystemPartitionOnSdCardValid (#381) --- nx/include/switch/services/fs.h | 2 ++ nx/source/services/fs.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 0da76c50..d570ce84 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -345,6 +345,8 @@ Result fsOpenDataStorageByDataId(FsStorage* out, u64 dataId, NcmStorageId storag Result fsOpenDeviceOperator(FsDeviceOperator* out); Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out); +Result fsIsSignedSystemPartitionOnSdCardValid(bool *out); + /// Retrieves the rights id corresponding to the content path. Only available on [2.0.0+]. Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index ba5bda71..ebeef80f 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -402,6 +402,13 @@ Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out) { return _fsCmdGetSession(&g_fsSrv, &out->s, 500); } +Result fsIsSignedSystemPartitionOnSdCardValid(bool *out) { + if (!hosversionBetween(4, 8)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _fsCmdNoInOutBool(&g_fsSrv, out, 640); +} + Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); From afbf2c6f718889312222a0dd52afc7d80a10693a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 7 Mar 2020 14:14:06 -0800 Subject: [PATCH 16/21] fs: be consistent about no stack temps in fsFs --- nx/source/services/fs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index ebeef80f..2613f3f2 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -629,9 +629,6 @@ Result fsFsQueryEntry(FsFileSystem* fs, void *out, size_t out_size, const void * if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - char send_path[FS_MAX_PATH] = {0}; - strncpy(send_path, path, sizeof(send_path)-1); - return _fsObjectDispatchIn(&fs->s, 15, query_id, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In, @@ -639,9 +636,9 @@ Result fsFsQueryEntry(FsFileSystem* fs, void *out, size_t out_size, const void * SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, }, .buffers = { - { send_path, sizeof(send_path) }, - { in, in_size }, - { out, out_size }, + { path, FS_MAX_PATH }, + { in, in_size }, + { out, out_size }, }, ); } @@ -655,7 +652,8 @@ Result fsFsIsValidSignedSystemPartitionOnSdCard(FsFileSystem* fs, bool *out) { return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); u8 tmp=0; - Result rc = fsFsQueryEntry(fs, &tmp, sizeof(tmp), NULL, 0, "/", FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard); + char send_path[FS_MAX_PATH] = "/"; + Result rc = fsFsQueryEntry(fs, &tmp, sizeof(tmp), NULL, 0, send_path, FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard); if (R_SUCCEEDED(rc) && out) *out = tmp & 1; return rc; } From bf8f6ae5f5a6c5e319e7e331a4eba49e4dbb447f Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 8 Mar 2020 17:42:25 -0400 Subject: [PATCH 17/21] ns: Use 'static ... const' with servarray. --- nx/source/services/ns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index cf55029e..c2716ecf 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -19,7 +19,7 @@ NX_GENERATE_SERVICE_GUARD(ns); Result _nsInitialize(void) { Result rc=0; - const char *servarray[5] = {"ns:ec", "ns:web", "ns:rid", "ns:rt", "ns:am2"}; // This is the order used used by official sw, however the below loop uses this in reverse since ns:am2 is last in the list. + static const char* const servarray[5] = {"ns:ec", "ns:web", "ns:rid", "ns:rt", "ns:am2"}; // This is the order used used by official sw, however the below loop uses this in reverse since ns:am2 is last in the list. if(hosversionBefore(3,0,0)) return smGetService(&g_nsAppManSrv, "ns:am"); From ccb79ff4b6a370f9d488609c8d8bfde18215ef13 Mon Sep 17 00:00:00 2001 From: fincs Date: Tue, 10 Mar 2020 00:07:04 +0100 Subject: [PATCH 18/21] NWindow: don't use bqDetachBuffer as it's unnecessary and in fact does nothing in the place it's called (reported by @Thog) --- nx/source/display/native_window.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/nx/source/display/native_window.c b/nx/source/display/native_window.c index 4703c97c..47081ced 100644 --- a/nx/source/display/native_window.c +++ b/nx/source/display/native_window.c @@ -324,13 +324,8 @@ Result nwindowReleaseBuffers(NWindow* nw) if (nw->cur_slot >= 0) rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); - else if (nw->is_connected && nw->slots_configured) { - for (u32 i = 0; i < 64; i ++) - if (nw->slots_configured & (1UL << i)) - bqDetachBuffer(&nw->bq, i); - + else if (nw->is_connected && nw->slots_configured) rc = _nwindowDisconnect(nw); - } mutexUnlock(&nw->mutex); return rc; From 7ce58f84e087da1088ea9296adae93099f33aee3 Mon Sep 17 00:00:00 2001 From: shchmue Date: Tue, 10 Mar 2020 09:35:11 -0600 Subject: [PATCH 19/21] Complete and correct all Settings calls (#383) --- nx/include/switch/services/fs.h | 5 + nx/include/switch/services/hid.h | 8 + nx/include/switch/services/set.h | 1126 ++++++++++++++++++++++++++++- nx/include/switch/services/time.h | 5 + nx/source/services/set.c | 678 ++++++++++++++++- 5 files changed, 1798 insertions(+), 24 deletions(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index d570ce84..b69b3246 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -123,6 +123,11 @@ typedef struct { u8 padding[7]; } FsTimeStampRaw; +/// This is nn::fssystem::ArchiveMacKey. Used by \ref setsysGetThemeKey and \ref setsysSetThemeKey. Does not appear to be in use elsewhere. +typedef struct { + u8 key[0x10]; +} FsArchiveMacKey; + /// Returned by fsFsGetEntryType. typedef enum { FsDirEntryType_Dir = 0, ///< Entry is a directory. diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index f926d6cd..71eb5ac3 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -381,6 +381,14 @@ typedef enum { NpadInterfaceType_Unknown4 = 4, ///< Unknown. } HidNpadInterfaceType; +/// XcdInterfaceType +typedef enum { + XcdInterfaceType_Bluetooth = BIT(0), + XcdInterfaceType_Uart = BIT(1), + XcdInterfaceType_Usb = BIT(2), + XcdInterfaceType_FieldSet = BIT(7), +} XcdInterfaceType; + /// touchPosition typedef struct touchPosition { u32 id; diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index e60a6911..004dfc6a 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -11,6 +11,7 @@ #include "../kernel/event.h" #include "../services/time.h" #include "../services/acc.h" +#include "../services/fs.h" #include "../sf/service.h" #define SET_MAX_NAME_SIZE 0x48 @@ -55,6 +56,39 @@ typedef enum { SetRegion_TWN = 6, ///< Taiwan } SetRegion; +/// ConnectionFlag +typedef enum { + SetSysConnectionFlag_ConnectAutomaticallyFlag = BIT(0), + SetSysConnectionFlag_Unknown = BIT(1), +} SetSysConnectionFlag; + +/// AccessPointSecurityType +typedef enum { + SetSysAccessPointSecurityType_None = 0, + SetSysAccessPointSecurityType_Shared = 1, + SetSysAccessPointSecurityType_Wpa = 2, + SetSysAccessPointSecurityType_Wpa2 = 3, +} SetSysAccessPointSecurityType; + +/// AccessPointSecurityStandard +typedef enum { + SetSysAccessPointSecurityStandard_None = 0, + SetSysAccessPointSecurityStandard_Wep = 1, + SetSysAccessPointSecurityStandard_Wpa = 2, +} SetSysAccessPointSecurityStandard; + +/// AutoSettings +typedef enum { + SetSysAutoSettings_AutoIp = BIT(0), + SetSysAutoSettings_AutoDns = BIT(1), +} SetSysAutoSettings; + +/// ProxyFlags +typedef enum { + SetSysProxyFlags_UseProxyFlag = BIT(0), + SetSysProxyFlags_ProxyAutoAuthenticateFlag = BIT(1), +} SetSysProxyFlags; + /// UserSelectorFlag typedef enum { SetSysUserSelectorFlag_SkipsIfSingleUser = BIT(0), @@ -81,6 +115,13 @@ typedef enum { SetSysFriendPresenceOverlayPermission_Friends = 3, } SetSysFriendPresenceOverlayPermission; +/// AudioDevice +typedef enum { + SetSysAudioDevice_Console = 0, + SetSysAudioDevice_Headphone = 1, + SetSysAudioDevice_Tv = 2, +} SetSysAudioDevice; + /// PrimaryAlbumStorage typedef enum { SetSysPrimaryAlbumStorage_Nand = 0, @@ -107,6 +148,24 @@ typedef enum { SetSysConsoleSleepPlan_Never = 5, } SetSysConsoleSleepPlan; +/// AudioOutputModeTarget +typedef enum { + SetSysAudioOutputModeTarget_Unknown0 = 0, + SetSysAudioOutputModeTarget_Unknown1 = 1, + SetSysAudioOutputModeTarget_Unknown2 = 2, + SetSysAudioOutputModeTarget_Unknown3 = 3, +} SetSysAudioOutputModeTarget; + +/// AudioOutputMode +typedef enum { + SetSysAudioOutputMode_Unknown1 = 1 ///< Default value. +} SetSysAudioOutputMode; + +/// ServiceDiscoveryControlSettings +typedef enum { + SetSysServiceDiscoveryControlSettings_IsChangeEnvironmentIdentifierDisabled = BIT(0), +} SetSysServiceDiscoveryControlSettings; + /// ErrorReportSharePermission typedef enum { SetSysErrorReportSharePermission_NotConfirmed = 0, @@ -139,6 +198,12 @@ typedef enum { SetChineseTraditionalInputMethod_Unknown2 = 2, } SetChineseTraditionalInputMethod; +/// PtmCycleCountReliability +typedef enum { + PtmCycleCountReliability_Default = 0, + PtmCycleCountReliability_Unk = 1, +} SetSysPtmCycleCountReliability; + /// PlatformRegion. Other values not listed here should be handled as "Unknown". typedef enum { SetSysPlatformRegion_Global = 1, @@ -151,11 +216,110 @@ typedef enum { SetSysTouchScreenMode_Standard = 1, ///< Standard, the default. } SetSysTouchScreenMode; +/// BlockType +typedef enum { + SetSysBlockType_Audio = 1, + SetSysBlockType_Video = 2, + SetSysBlockType_VendorSpecific = 3, + SetSysBlockType_Speaker = 4, +} SetSysBlockType; + +/// ControllerType +typedef enum { + SetSysControllerType_JoyConR = 1, + SetSysControllerType_JoyConL = 2, + SetSysControllerType_ProCon = 3, +} SetSysControllerType; + /// BatteryLot typedef struct { char lot[0x18]; ///< BatteryLot string. } SetBatteryLot; +/// NetworkSettings +typedef struct { + char name[0x40]; + Uuid uuid; + u32 connection_flags; ///< Bitmask with \ref SetSysConnectionFlag. + u32 wired_flag; + u32 connect_to_hidden_network; ///< Bitmask with UseStealthNetworkFlag. + char access_point_ssid[0x20]; + u32 access_point_ssid_len; + u32 access_point_security_type; ///< Bitmask with \ref SetSysAccessPointSecurityType. + u32 access_point_security_standard; ///< Bitmask with \ref SetSysAccessPointSecurityStandard. + char access_point_passphrase[0x40]; + u32 access_point_passphrase_len; + u32 auto_settings; ///< Bitmask with \ref SetSysAutoSettings. + u32 manual_ip_address; + u32 manual_subnet_mask; + u32 manual_gateway; + u32 primary_dns; + u32 secondary_dns; + u32 proxy_flags; ///< Bitmask with \ref SetSysProxyFlags. + char proxy_server[0x80]; + u16 proxy_port; + u16 padding1; + char proxy_autoauth_user[0x20]; + char proxy_autoauth_pass[0x20]; + u16 mtu; + u16 padding2; +} SetSysNetworkSettings; + +/// LcdBacklightBrightnessMapping +typedef struct { + float brightness_applied_to_backlight; + float ambient_light_sensor_value; + float unk_x8; +} SetSysLcdBacklightBrightnessMapping; + +/// BacklightSettings +typedef struct { + u32 auto_brightness_flags; + float screen_brightness; + SetSysLcdBacklightBrightnessMapping brightness_mapping; + float unk_x14; + float unk_x18; + float unk_x1C; + float unk_x20; + float unk_x24; +} SetSysBacklightSettings; + +/// BacklightSettingsEx +typedef struct { + u32 auto_brightness_flags; + float screen_brightness; + float current_brightness_for_vr_mode; + SetSysLcdBacklightBrightnessMapping brightness_mapping; + float unk_x18; + float unk_x1C; + float unk_x20; + float unk_x24; + float unk_x28; +} SetSysBacklightSettingsEx; + +/// BluetoothDevicesSettings +typedef struct { + u8 address[6]; ///< nn::bluetooth::Address + char name[0x20]; + u16 unk_x26; + u8 unk_x28; + Uuid uuid; + u8 unk_x39; + u16 unk_x3A; + u32 unk_x3C; + u16 unk_x40; + u16 unk_x42; + u16 unk_x44; + u8 unk_x46[0x80]; + u16 unk_xC6; + u8 unk_xC8; + u8 unk_xC9; + u16 unk_xCA; + u8 unk_xCC[8]; + u8 unk_xD4; + u8 unk_xD5[0x12B]; +} SetSysBluetoothDevicesSettings; + /// Structure returned by \ref setsysGetFirmwareVersion. typedef struct { u8 major; @@ -172,6 +336,11 @@ typedef struct { char display_title[0x80]; } SetSysFirmwareVersion; +/// Structure returned by \ref setsysGetFirmwareVersionDigest. +typedef struct { + char digest[0x40]; +} SetSysFirmwareVersionDigest; + /// UserSelectorSettings typedef struct { u32 flags; ///< Bitmask with \ref SetSysUserSelectorFlag. @@ -182,6 +351,11 @@ typedef struct { SetSysUserSelectorSettings settings; } SetSysAccountSettings; +typedef struct { + u32 unk_x0; ///< 0 for Console and Tv, 2 for Headphones. + u8 volume; ///< From 0-15. +} SetSysAudioVolume; + /// EulaVersion typedef struct { u32 version; @@ -226,6 +400,140 @@ typedef struct { float contrast; ///< Contrast. } SetSysTvSettings; +typedef struct { + u16 pixel_clock; ///< In 10 kHz units. + u8 horizontal_active_pixels_lsb; + u8 horizontal_blanking_pixels_lsb; + u8 horizontal_blanking_pixels_msb : 4; + u8 horizontal_active_pixels_msb : 4; + u8 vertical_active_lines_lsb; + u8 vertical_blanking_lines_lsb; + u8 vertical_blanking_lines_msb : 4; + u8 vertical_active_lines_msb : 4; + u8 horizontal_sync_offset_pixels_lsb; + u8 horizontal_sync_pulse_width_pixels_lsb; + u8 horizontal_sync_pulse_width_lines_lsb : 4; + u8 horizontal_sync_offset_lines_lsb : 4; + u8 vertical_sync_pulse_width_lines_msb : 2; + u8 vertical_sync_offset_lines_msb : 2; + u8 horizontal_sync_pulse_width_pixels_msb : 2; + u8 horizontal_sync_offset_pixels_msb : 2; + u8 horizontal_image_size_mm_lsb; + u8 vertical_image_size_mm_lsb; + u8 vertical_image_size_mm_msb : 4; + u8 horizontal_image_size_mm_msb : 4; + u8 horizontal_border_pixels; + u8 vertical_border_lines; + u8 features_bitmap_0 : 1; + u8 features_bitmap_1 : 1; + u8 features_bitmap_2 : 1; + u8 features_bitmap_34 : 2; + u8 features_bitmap_56 : 2; + u8 interlaced : 1; +} SetSysModeLine; + +typedef struct { + struct { + u8 size : 5; + SetSysBlockType block_type : 3; + struct { + u8 svd_index : 7; + u8 native_flag : 1; + } svd[0xC]; + } PACKED video; + struct { + u8 size : 5; + SetSysBlockType block_type : 3; + u8 channel_count : 3; + u8 format_code : 4; + u8 padding1 : 1; + u8 sampling_rates_bitmap; + u8 bitrate; + } PACKED audio; + struct { + u8 size : 5; + SetSysBlockType block_type : 3; + u8 ieee_registration_id[3]; + u16 source_physical_address; + u8 mode_bitmap; + u8 max_tmds_frequency; + u8 latency_bitmap; + } PACKED vendor_specific; + u8 padding[2]; +} SetSysDataBlock; + +/// Edid +typedef struct { + u8 pattern[8]; ///< Fixed pattern 00 FF FF FF FF FF FF 00. + u16 pnp_id; ///< Big-endian set of 3 5-bit values representing letters, 1 = A .. 26 = Z. + u16 product_code; + u32 serial_number; + u8 manufacture_week; + u8 manufacture_year; + u8 edid_version; + u8 edid_revision; + u8 video_input_parameters_bitmap; + u8 display_width; + u8 display_height; + u8 display_gamma; + u8 supported_features_bitmap; + struct { + u8 green_y_lsb : 2; + u8 green_x_lsb : 2; + u8 red_y_lsb : 2; + u8 red_x_lsb : 2; + u8 blue_lsb : 4; + u8 white_lsb : 4; + u8 red_x_msb; + u8 red_y_msb; + u8 green_x_msb; + u8 green_y_msb; + u8 blue_x_msb; + u8 blue_y_msb; + u8 white_x_msb; + u8 white_y_msb; + } chromaticity; + u8 timing_bitmap[3]; + struct { + u8 x_resolution; ///< Real value is (val + 31) * 8 pixels. + u8 vertical_frequency : 6; ///< Real value is val + 60 Hz. + u8 aspect_ratio : 2; ///< 0 = 16:10, 1 = 4:3, 2 = 5:4, 3 = 16:9. + } timing_info[8]; + SetSysModeLine timing_descriptor[2]; + struct { + u16 display_descriptor_zero; + u8 padding1; + u8 descriptor_type; + u8 padding2; + char name[0xD]; + } display_descriptor_name; + struct { + u16 display_descriptor_zero; + u8 padding1; + u8 descriptor_type; + u8 range_limit_offsets; + u8 vertical_field_rate_min; + u8 vertical_field_rate_max; + u8 horizontal_line_rate_min; + u8 horizontal_line_rate_max; + u8 pixel_clock_rate_max; ///< Rounded up to multiples of 10 MHz. + u8 extended_timing_info; + u8 padding[7]; + } display_descriptor_range_limits; + u8 extension_count; ///< Always 1. + u8 checksum; ///< Sum of all 128 bytes should equal 0 mod 256. + ///< Extended data. + u8 extension_tag; ///< Always 2 = CEA EDID timing extension. + u8 revision; + u8 dtd_start; + u8 native_dtd_count : 4; + u8 native_dtd_feature_bitmap : 4; + SetSysDataBlock data_block; + SetSysModeLine extended_timing_descriptor[5]; + u8 padding[5]; + u8 extended_checksum; ///< Sum of 128 extended bytes should equal 0 mod 256. +} SetSysEdid; + /// DataDeletionSettings typedef struct { u32 flags; ///< Bitmask with DataDeletionFlag. @@ -246,6 +554,122 @@ typedef struct { TimeSteadyClockTimePoint timestamp; ///< \ref TimeSteadyClockTimePoint timestamp. } SetSysInitialLaunchSettings; +/// PtmFuelGaugeParameter +typedef struct { + u16 rcomp0; + u16 tempc0; + u16 fullcap; + u16 fullcapnom; + u16 lavgempty; + u16 qresidual00; + u16 qresidual10; + u16 qresidual20; + u16 qresidual30; + u16 cycles; ///< Normally keeps the cycles reg. Unused and contains stack garbage. + u32 cycles_actual; ///< Keeps track of cycles. The fuel gauge cycles reg is reset if > 2.00 cycles and added here. +} SetSysPtmFuelGaugeParameter; + +/// Actually nn::util::Color4u8Type. +typedef struct { + u8 field[4]; +} SetSysColor4u8Type; + +/// NxControllerSettings +typedef struct { + u8 address[6]; ///< nn::bluetooth::Address + u8 type; ///< \ref SetSysControllerType. + char serial[0x10]; + SetSysColor4u8Type body_color; + SetSysColor4u8Type button_color; + u8 unk_x1F[8]; + u8 unk_x27; + u8 interface_type; ///< Bitmask with \ref XcdInterfaceType. +} SetSysNxControllerSettings; + +/// ConsoleSixAxisSensorAccelerationBias +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; +} SetSysConsoleSixAxisSensorAccelerationBias; + +/// ConsoleSixAxisSensorAngularVelocityBias +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; +} SetSysConsoleSixAxisSensorAngularVelocityBias; + +/// ConsoleSixAxisSensorAccelerationGain +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; + float unk_xC; + float unk_x10; + float unk_x14; + float unk_x18; + float unk_x1C; + float unk_x20; +} SetSysConsoleSixAxisSensorAccelerationGain; + +/// ConsoleSixAxisSensorAngularVelocityGain +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; + float unk_xC; + float unk_x10; + float unk_x14; + float unk_x18; + float unk_x1C; + float unk_x20; +} SetSysConsoleSixAxisSensorAngularVelocityGain; + +/// AllowedSslHosts +typedef struct { + u8 hosts[0x100]; +} SetSysAllowedSslHosts; + +/// HostFsMountPoint +typedef struct { + char mount[0x100]; +} SetSysHostFsMountPoint; + +/// BlePairingSettings +typedef struct { + u8 address[6]; ///< nn::bluetooth::Address + u16 unk_x6; + u16 unk_x8; + u8 unk_xA; + u8 unk_xB; + u8 unk_xC; + u8 unk_xD; + u8 unk_xE; + u8 unk_xF; + u8 padding[0x70]; +} SetSysBlePairingSettings; + +/// ConsoleSixAxisSensorAngularVelocityTimeBias +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; +} SetSysConsoleSixAxisSensorAngularVelocityTimeBias; + +/// ConsoleSixAxisSensorAngularAcceleration +typedef struct { + float unk_x0; + float unk_x4; + float unk_x8; + float unk_xC; + float unk_x10; + float unk_x14; + float unk_x18; + float unk_x1C; + float unk_x20; +} SetSysConsoleSixAxisSensorAngularAcceleration; + /// RebootlessSystemUpdateVersion. This is the content of the RebootlessSystemUpdateVersion SystemData, in the "/version" file. typedef struct { u32 version; @@ -253,6 +677,35 @@ typedef struct { char display_version[0x20]; } SetSysRebootlessSystemUpdateVersion; +/// AccountOnlineStorageSettings +typedef struct { + AccountUid uid; ///< \ref AccountUid + u32 unk_x10; + u32 unk_x14; +} SetSysAccountOnlineStorageSettings; + +/// AnalogStickUserCalibration +typedef struct { + u16 unk_x0; + u16 unk_x2; + u16 unk_x4; + u16 unk_x6; + u16 unk_x8; + u16 unk_xA; + u16 unk_xC; + u16 unk_xE; +} SetSysAnalogStickUserCalibration; + +/// ThemeId +typedef struct { + u64 theme_id[0x10]; +} SetSysThemeId; + +/// ThemeSettings +typedef struct { + u64 theme_settings; +} SetSysThemeSettings; + /// Output from \ref setsysGetHomeMenuScheme. This contains RGBA8 colors which correspond with the physical shell of the system. typedef struct { u32 main_color; ///< Main Color. @@ -310,10 +763,6 @@ typedef struct { u8 parameter[0x12]; } SetCalAnalogStickModelParameter; -typedef struct { - u8 battery_lot[0x18]; -} SetCalBatteryLot; - typedef struct { u8 bd_addr[0x6]; } SetCalBdAddress; @@ -444,12 +893,33 @@ Service* setsysGetServiceSession(void); */ Result setsysSetLanguageCode(u64 LanguageCode); +/** + * @brief SetNetworkSettings + * @param[in] settings Input array of \ref SetSysNetworkSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysSetNetworkSettings(const SetSysNetworkSettings *settings, s32 count); + +/** + * @brief GetNetworkSettings + * @param[out] total_out Total output entries. + * @param[out] versions Output array of \ref SetSysNetworkSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysGetNetworkSettings(s32 *total_out, SetSysNetworkSettings *settings, s32 count); + /** * @brief Gets the system firmware version. * @param[out] out Firmware version to populate. */ Result setsysGetFirmwareVersion(SetSysFirmwareVersion *out); +/** + * @brief GetFirmwareVersionDigest + * @param[out] out \ref SetSysFirmwareVersionDigest + */ +Result setsysGetFirmwareVersionDigest(SetSysFirmwareVersionDigest *out); + /** * @brief GetLockScreenFlag * @param[out] out Output flag. @@ -462,6 +932,57 @@ Result setsysGetLockScreenFlag(bool *out); */ Result setsysSetLockScreenFlag(bool flag); +/** + * @brief GetBacklightSettings + * @param[out] out \ref SetSysBacklightSettings + */ +Result setsysGetBacklightSettings(SetSysBacklightSettings *out); + +/** + * @brief SetBacklightSettings + * @param[in] settings \ref SetSysBacklightSettings + */ +Result setsysSetBacklightSettings(const SetSysBacklightSettings *settings); + +/** + * @brief SetBluetoothDevicesSettings + * @param[in] settings Input array of \ref SetSysBluetoothDevicesSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysSetBluetoothDevicesSettings(const SetSysBluetoothDevicesSettings *settings, s32 count); + +/** + * @brief GetBluetoothDevicesSettings + * @param[out] total_out Total output entries. + * @param[out] settings Output array of \ref SetSysBluetoothDevicesSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysGetBluetoothDevicesSettings(s32 *total_out, SetSysBluetoothDevicesSettings *settings, s32 count); + +/** + * @brief GetExternalSteadyClockSourceId + * @param[out] out \ref Uuid + */ +Result setsysGetExternalSteadyClockSourceId(Uuid *out); + +/** + * @brief SetExternalSteadyClockSourceId + * @param[in] uuid \ref Uuid + */ +Result setsysSetExternalSteadyClockSourceId(const Uuid *uuid); + +/** + * @brief GetUserSystemClockContext + * @param[out] out \ref TimeSystemClockContext + */ +Result setsysGetUserSystemClockContext(TimeSystemClockContext *out); + +/** + * @brief SetUserSystemClockContext + * @param[in] context \ref TimeSystemClockContext + */ +Result setsysSetUserSystemClockContext(const TimeSystemClockContext *context); + /** * @brief GetAccountSettings * @param[out] out \ref SetSysAccountSettings @@ -474,6 +995,20 @@ Result setsysGetAccountSettings(SetSysAccountSettings *out); */ Result setsysSetAccountSettings(SetSysAccountSettings settings); +/** + * @brief GetAudioVolume + * @param[in] device \ref SetSysAudioDevice + * @param[out] out \ref SetSysAudioVolume + */ +Result setsysGetAudioVolume(SetSysAudioDevice device, SetSysAudioVolume *out); + +/** + * @brief SetAudioVolume + * @param[in] device \ref SetSysAudioDevice + * @param[in] volume \ref SetSysAudioVolume + */ +Result setsysSetAudioVolume(SetSysAudioDevice device, const SetSysAudioVolume *volume); + /** * @brief GetEulaVersions * @param[out] total_out Total output entries. @@ -546,6 +1081,18 @@ Result setsysGetAccountNotificationSettings(s32 *total_out, SetSysAccountNotific */ Result setsysSetAccountNotificationSettings(const SetSysAccountNotificationSettings *settings, s32 count); +/** + * @brief GetVibrationMasterVolume + * @param[out] out Output volume. + */ +Result setsysGetVibrationMasterVolume(float *out); + +/** + * @brief SetVibrationMasterVolume + * @param[in] volume Input volume. + */ +Result setsysSetVibrationMasterVolume(float volume); + /** * @brief Gets the size of a settings item value. * @param name Name string. @@ -576,6 +1123,44 @@ Result setsysGetTvSettings(SetSysTvSettings *out); */ Result setsysSetTvSettings(const SetSysTvSettings *settings); +/** + * @brief GetEdid + * @param[out] out \ref SetSysEdid + */ +Result setsysGetEdid(SetSysEdid *out); + +/** + * @brief SetEdid + * @param[in] edid \ref SetSysEdid + */ +Result setsysSetEdid(const SetSysEdid *edid); + +/** + * @brief GetAudioOutputMode + * @param[in] target \ref SetSysAudioOutputModeTarget + * @param[out] out \ref SetSysAudioOutputMode + */ +Result setsysGetAudioOutputMode(SetSysAudioOutputModeTarget target, SetSysAudioOutputMode *out); + +/** + * @brief SetAudioOutputMode + * @param[in] target \ref SetSysAudioOutputModeTarget + * @param[in] mode \ref SetSysAudioOutputMode + */ +Result setsysSetAudioOutputMode(SetSysAudioOutputModeTarget target, SetSysAudioOutputMode mode); + +/** + * @brief IsForceMuteOnHeadphoneRemoved + * @param[out] out Output flag. + */ +Result setsysIsForceMuteOnHeadphoneRemoved(bool *out); + +/** + * @brief SetForceMuteOnHeadphoneRemoved + * @param[in] flag Input flag. + */ +Result setsysSetForceMuteOnHeadphoneRemoved(bool flag); + /** * @brief GetQuestFlag * @param[out] out Output flag. @@ -600,6 +1185,30 @@ Result setsysGetDataDeletionSettings(SetSysDataDeletionSettings *out); */ Result setsysSetDataDeletionSettings(const SetSysDataDeletionSettings *settings); +/** + * @brief GetInitialSystemAppletProgramId + * @param[out] out output ProgramId. + */ +Result setsysGetInitialSystemAppletProgramId(u64 *out); + +/** + * @brief GetOverlayDispProgramId + * @param[out] out output ProgramId. + */ +Result setsysGetOverlayDispProgramId(u64 *out); + +/** + * @brief GetDeviceTimeZoneLocationName + * @param[out] out \ref TimeLocationName + */ +Result setsysGetDeviceTimeZoneLocationName(TimeLocationName *out); + +/** + * @brief SetDeviceTimeZoneLocationName + * @param[in] name \ref TimeLocationName + */ +Result setsysSetDeviceTimeZoneLocationName(const TimeLocationName *name); + /** * @brief GetWirelessCertificationFileSize * @param[out] out_size Output size. @@ -620,6 +1229,18 @@ Result setsysGetWirelessCertificationFile(void* buffer, size_t size, u64 *out_si */ Result setsysSetRegionCode(SetRegion region); +/** + * @brief GetNetworkSystemClockContext + * @param[out] out \ref TimeSystemClockContext + */ +Result setsysGetNetworkSystemClockContext(TimeSystemClockContext *out); + +/** + * @brief SetNetworkSystemClockContext + * @param[in] context \ref TimeSystemClockContext + */ +Result setsysSetNetworkSystemClockContext(const TimeSystemClockContext *context); + /** * @brief IsUserSystemClockAutomaticCorrectionEnabled * @param[out] out Output flag. @@ -632,6 +1253,12 @@ Result setsysIsUserSystemClockAutomaticCorrectionEnabled(bool *out); */ Result setsysSetUserSystemClockAutomaticCorrectionEnabled(bool flag); +/** + * @brief GetDebugModeFlag + * @param[out] out Output flag. + */ +Result setsysGetDebugModeFlag(bool *out); + /** * @brief GetPrimaryAlbumStorage * @param[out] out \ref GetPrimaryAlbumStorage @@ -734,6 +1361,55 @@ Result setsysSetDeviceNickname(const char* nickname); */ Result setsysGetProductModel(s32 *out); +/** + * @brief GetLdnChannel + * @param[out] out Output LdnChannel. + */ +Result setsysGetLdnChannel(s32 *out); + +/** + * @brief SetLdnChannel + * @param[in] channel Input LdnChannel. + */ +Result setsysSetLdnChannel(s32 channel); + +/** + * @brief Gets an event that settings will signal on flag change. + * @param out_event Event to bind. Output event will have autoclear=false. + */ +Result setsysAcquireTelemetryDirtyFlagEventHandle(Event *out_event); + +/** + * @brief Gets the settings flags that have changed. + * @param flags_0 Pointer to populate with first 64 flags. + * @param flags_1 Pointer to populate with second 64 flags. + */ +Result setsysGetTelemetryDirtyFlags(u64 *flags_0, u64 *flags_1); + +/** + * @brief GetPtmBatteryLot + * @param[out] out \ref SetBatteryLot + */ +Result setsysGetPtmBatteryLot(SetBatteryLot *out); + +/** + * @brief SetPtmBatteryLot + * @param[in] lot \ref SetBatteryLot + */ +Result setsysSetPtmBatteryLot(const SetBatteryLot *lot); + +/** + * @brief GetPtmFuelGaugeParameter + * @param[out] out \ref SetSysPtmFuelGaugeParameter + */ +Result setsysGetPtmFuelGaugeParameter(SetSysPtmFuelGaugeParameter *out); + +/** + * @brief SetPtmFuelGaugeParameter + * @param[in] parameter \ref SetSysPtmFuelGaugeParameter + */ +Result setsysSetPtmFuelGaugeParameter(const SetSysPtmFuelGaugeParameter *parameter); + /** * @brief GetBluetoothEnableFlag * @param[out] out Output flag. @@ -752,11 +1428,23 @@ Result setsysSetBluetoothEnableFlag(bool flag); */ Result setsysGetMiiAuthorId(Uuid *out); +/** + * @brief SetShutdownRtcValue + * @param[in] value Input value. + */ +Result setsysSetShutdownRtcValue(u64 value); + +/** + * @brief GetShutdownRtcValue + * @param[out] out Output value. + */ +Result setsysGetShutdownRtcValue(u64 *out); + /** * @brief Gets an event that settings will signal on flag change. * @param out_event Event to bind. Output event will have autoclear=false. */ -Result setsysBindFatalDirtyFlagEvent(Event *out_event); +Result setsysAcquireFatalDirtyFlagEventHandle(Event *out_event); /** * @brief Gets the settings flags that have changed. @@ -779,6 +1467,21 @@ Result setsysGetAutoUpdateEnableFlag(bool *out); */ Result setsysSetAutoUpdateEnableFlag(bool flag); +/** + * @brief GetNxControllerSettings + * @param[out] total_out Total output entries. + * @param[out] settings Output array of \ref SetSysNxControllerSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysGetNxControllerSettings(s32 *total_out, SetSysNxControllerSettings *settings, s32 count); + +/** + * @brief SetNxControllerSettings + * @param[in] settings Input array of \ref SetSysNxControllerSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysSetNxControllerSettings(const SetSysNxControllerSettings *settings, s32 count); + /** * @brief GetBatteryPercentageFlag * @note Only available on [2.0.0+]. @@ -821,6 +1524,48 @@ Result setsysGetUsbFullKeyEnableFlag(bool *out); */ Result setsysSetUsbFullKeyEnableFlag(bool flag); +/** + * @brief SetExternalSteadyClockInternalOffset + * @note Only available on [3.0.0+]. + * @param[in] offset Input offset. + */ +Result setsysSetExternalSteadyClockInternalOffset(u64 offset); + +/** + * @brief GetExternalSteadyClockInternalOffset + * @note Only available on [3.0.0+]. + * @param[out] out Output offset. + */ +Result setsysGetExternalSteadyClockInternalOffset(u64 *out); + +/** + * @brief GetBacklightSettingsEx + * @note Only available on [3.0.0+]. + * @param[out] out \ref SetSysBacklightSettingsEx + */ +Result setsysGetBacklightSettingsEx(SetSysBacklightSettingsEx *out); + +/** + * @brief SetBacklightSettingsEx + * @note Only available on [3.0.0+]. + * @param[in] settings \ref SetSysBacklightSettingsEx + */ +Result setsysSetBacklightSettingsEx(const SetSysBacklightSettingsEx *settings); + +/** + * @brief GetHeadphoneVolumeWarningCount + * @note Only available on [3.0.0+]. + * @param[out] out Output count. + */ +Result setsysGetHeadphoneVolumeWarningCount(u32 *out); + +/** + * @brief SetHeadphoneVolumeWarningCount + * @note Only available on [3.0.0+]. + * @param[in] count Input count. + */ +Result setsysSetHeadphoneVolumeWarningCount(u32 count); + /** * @brief GetBluetoothAfhEnableFlag * @note Only available on [3.0.0+]. @@ -877,6 +1622,44 @@ Result setsysGetHeadphoneVolumeUpdateFlag(bool *out); */ Result setsysSetHeadphoneVolumeUpdateFlag(bool flag); +/** + * @brief NeedsToUpdateHeadphoneVolume + * @note Only available on [3.0.0+]. + * @param[out] a0 Output arg. + * @param[out] a1 Output arg. + * @param[out] a2 Output arg. + * @param[in] flag Input flag. + */ +Result setsysNeedsToUpdateHeadphoneVolume(u8 *a0, u8 *a1, u8 *a2, bool flag); + +/** + * @brief GetPushNotificationActivityModeOnSleep + * @note Only available on [3.0.0+]. + * @param[out] out Output mode. + */ +Result setsysGetPushNotificationActivityModeOnSleep(u32 *out); + +/** + * @brief SetPushNotificationActivityModeOnSleep + * @note Only available on [3.0.0+]. + * @param[in] mode Input mode. + */ +Result setsysSetPushNotificationActivityModeOnSleep(u32 mode); + +/** + * @brief GetServiceDiscoveryControlSettings + * @note Only available on [4.0.0+]. + * @param[out] out \ref ServiceDiscoveryControlSettings + */ +Result setsysGetServiceDiscoveryControlSettings(SetSysServiceDiscoveryControlSettings *out); + +/** + * @brief SetServiceDiscoveryControlSettings + * @note Only available on [4.0.0+]. + * @param[in] settings \ref ServiceDiscoveryControlSettings + */ +Result setsysSetServiceDiscoveryControlSettings(SetSysServiceDiscoveryControlSettings settings); + /** * @brief GetErrorReportSharePermission * @note Only available on [4.0.0+]. @@ -905,6 +1688,62 @@ Result setsysGetAppletLaunchFlags(u32 *out); */ Result setsysSetAppletLaunchFlags(u32 flags); +/** + * @brief GetConsoleSixAxisSensorAccelerationBias + * @note Only available on [4.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAccelerationBias + */ +Result setsysGetConsoleSixAxisSensorAccelerationBias(SetSysConsoleSixAxisSensorAccelerationBias *out); + +/** + * @brief SetConsoleSixAxisSensorAccelerationBias + * @note Only available on [4.0.0+]. + * @param[in] bias \ref SetSysConsoleSixAxisSensorAccelerationBias + */ +Result setsysSetConsoleSixAxisSensorAccelerationBias(const SetSysConsoleSixAxisSensorAccelerationBias *bias); + +/** + * @brief GetConsoleSixAxisSensorAngularVelocityBias + * @note Only available on [4.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAngularVelocityBias + */ +Result setsysGetConsoleSixAxisSensorAngularVelocityBias(SetSysConsoleSixAxisSensorAngularVelocityBias *out); + +/** + * @brief SetConsoleSixAxisSensorAngularVelocityBias + * @note Only available on [4.0.0+]. + * @param[in] bias \ref SetSysConsoleSixAxisSensorAngularVelocityBias + */ +Result setsysSetConsoleSixAxisSensorAngularVelocityBias(const SetSysConsoleSixAxisSensorAngularVelocityBias *bias); + +/** + * @brief GetConsoleSixAxisSensorAccelerationGain + * @note Only available on [4.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAccelerationGain + */ +Result setsysGetConsoleSixAxisSensorAccelerationGain(SetSysConsoleSixAxisSensorAccelerationGain *out); + +/** + * @brief SetConsoleSixAxisSensorAccelerationGain + * @note Only available on [4.0.0+]. + * @param[in] gain \ref SetSysConsoleSixAxisSensorAccelerationGain + */ +Result setsysSetConsoleSixAxisSensorAccelerationGain(const SetSysConsoleSixAxisSensorAccelerationGain *gain); + +/** + * @brief GetConsoleSixAxisSensorAngularVelocityGain + * @note Only available on [4.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAngularVelocityGain + */ +Result setsysGetConsoleSixAxisSensorAngularVelocityGain(SetSysConsoleSixAxisSensorAngularVelocityGain *out); + +/** + * @brief SetConsoleSixAxisSensorAngularVelocityGain + * @note Only available on [4.0.0+]. + * @param[in] gain \ref SetSysConsoleSixAxisSensorAngularVelocityGain + */ +Result setsysSetConsoleSixAxisSensorAngularVelocityGain(const SetSysConsoleSixAxisSensorAngularVelocityGain *gain); + /** * @brief GetKeyboardLayout * @note Only available on [4.0.0+]. @@ -919,6 +1758,29 @@ Result setsysGetKeyboardLayout(SetKeyboardLayout *out); */ Result setsysSetKeyboardLayout(SetKeyboardLayout layout); +/** + * @brief GetWebInspectorFlag + * @note Only available on [4.0.0+]. + * @param[out] out Output flag. + */ +Result setsysGetWebInspectorFlag(bool *out); + +/** + * @brief GetAllowedSslHosts + * @note Only available on [4.0.0+]. + * @param[out] total_out Total output entries. + * @param[out] out Output array of \ref SetSysAllowedSslHosts. + * @param[in] count Size of the hosts array in entries. + */ +Result setsysGetAllowedSslHosts(s32 *total_out, SetSysAllowedSslHosts *out, s32 count); + +/** + * @brief GetHostFsMountPoint + * @note Only available on [4.0.0+]. + * @param[out] out \ref SetSysHostFsMountPoint + */ +Result setsysGetHostFsMountPoint(SetSysHostFsMountPoint *out); + /** * @brief GetRequiresRunRepairTimeReviser * @note Only available on [5.0.0+]. @@ -926,6 +1788,58 @@ Result setsysSetKeyboardLayout(SetKeyboardLayout layout); */ Result setsysGetRequiresRunRepairTimeReviser(bool *out); +/** + * @brief SetRequiresRunRepairTimeReviser + * @note Only available on [5.0.0+]. + * @param[in] flag Input flag. + */ +Result setsysSetRequiresRunRepairTimeReviser(bool flag); + +/** + * @brief SetBlePairingSettings + * @note Only available on [5.0.0+]. + * @param[in] settings Input array of \ref SetSysBlePairingSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysSetBlePairingSettings(const SetSysBlePairingSettings *settings, s32 count); + +/** + * @brief GetBlePairingSettings + * @note Only available on [5.0.0+]. + * @param[out] total_out Total output entries. + * @param[out] settings Output array of \ref SetSysBlePairingSettings. + * @param[in] count Size of the hosts array in entries. + */ +Result setsysGetBlePairingSettings(s32 *total_out, SetSysBlePairingSettings *settings, s32 count); + +/** + * @brief GetConsoleSixAxisSensorAngularVelocityTimeBias + * @note Only available on [5.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAngularVelocityTimeBias + */ +Result setsysGetConsoleSixAxisSensorAngularVelocityTimeBias(SetSysConsoleSixAxisSensorAngularVelocityTimeBias *out); + +/** + * @brief SetConsoleSixAxisSensorAngularVelocityTimeBias + * @note Only available on [5.0.0+]. + * @param[in] bias \ref SetSysConsoleSixAxisSensorAngularVelocityTimeBias + */ +Result setsysSetConsoleSixAxisSensorAngularVelocityTimeBias(const SetSysConsoleSixAxisSensorAngularVelocityTimeBias *bias); + +/** + * @brief GetConsoleSixAxisSensorAngularAcceleration + * @note Only available on [5.0.0+]. + * @param[out] out \ref SetSysConsoleSixAxisSensorAngularAcceleration + */ +Result setsysGetConsoleSixAxisSensorAngularAcceleration(SetSysConsoleSixAxisSensorAngularAcceleration *out); + +/** + * @brief SetConsoleSixAxisSensorAngularAcceleration + * @note Only available on [5.0.0+]. + * @param[in] acceleration \ref SetSysConsoleSixAxisSensorAngularAcceleration + */ +Result setsysSetConsoleSixAxisSensorAngularAcceleration(const SetSysConsoleSixAxisSensorAngularAcceleration *acceleration); + /** * @brief GetRebootlessSystemUpdateVersion * @note Only available on [5.0.0+]. @@ -934,11 +1848,49 @@ Result setsysGetRequiresRunRepairTimeReviser(bool *out); Result setsysGetRebootlessSystemUpdateVersion(SetSysRebootlessSystemUpdateVersion *out); /** - * @brief SetRequiresRunRepairTimeReviser + * @brief GetDeviceTimeZoneLocationUpdatedTime * @note Only available on [5.0.0+]. - * @param[in] flag Input flag. + * @param[out] out \ref TimeSteadyClockTimePoint */ -Result setsysSetRequiresRunRepairTimeReviser(bool flag); +Result setsysGetDeviceTimeZoneLocationUpdatedTime(TimeSteadyClockTimePoint *out); + +/** + * @brief SetDeviceTimeZoneLocationUpdatedTime + * @note Only available on [5.0.0+]. + * @param[in] time_point \ref TimeSteadyClockTimePoint + */ +Result setsysSetDeviceTimeZoneLocationUpdatedTime(const TimeSteadyClockTimePoint *time_point); + +/** + * @brief GetUserSystemClockAutomaticCorrectionUpdatedTime + * @note Only available on [6.0.0+]. + * @param[out] out \ref TimeSteadyClockTimePoint + */ +Result setsysGetUserSystemClockAutomaticCorrectionUpdatedTime(TimeSteadyClockTimePoint *out); + +/** + * @brief SetUserSystemClockAutomaticCorrectionUpdatedTime + * @note Only available on [6.0.0+]. + * @param[in] time_point \ref TimeSteadyClockTimePoint + */ +Result setsysSetUserSystemClockAutomaticCorrectionUpdatedTime(const TimeSteadyClockTimePoint *time_point); + +/** + * @brief GetAccountOnlineStorageSettings + * @note Only available on [6.0.0+]. + * @param[out] total_out Total output entries. + * @param[out] settings Output array of \ref SetSysAccountOnlineStorageSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysGetAccountOnlineStorageSettings(s32 *total_out, SetSysAccountOnlineStorageSettings *settings, s32 count); + +/** + * @brief SetAccountOnlineStorageSettings + * @note Only available on [6.0.0+]. + * @param[in] settings Input array of \ref SetSysAccountOnlineStorageSettings. + * @param[in] count Size of the settings array in entries. + */ +Result setsysSetAccountOnlineStorageSettings(const SetSysAccountOnlineStorageSettings *settings, s32 count); /** * @brief GetPctlReadyFlag @@ -954,6 +1906,92 @@ Result setsysGetPctlReadyFlag(bool *out); */ Result setsysSetPctlReadyFlag(bool flag); +/** + * @brief GetAnalogStickUserCalibrationL + * @note Only available on [8.1.1+]. + * @param[out] out \ref SetSysAnalogStickUserCalibration + */ +Result setsysGetAnalogStickUserCalibrationL(SetSysAnalogStickUserCalibration *out); + +/** + * @brief SetAnalogStickUserCalibrationL + * @note Only available on [8.1.1+]. + * @param[in] calibration \ref SetSysAnalogStickUserCalibration + */ +Result setsysSetAnalogStickUserCalibrationL(const SetSysAnalogStickUserCalibration *calibration); + +/** + * @brief GetAnalogStickUserCalibrationR + * @note Only available on [8.1.1+]. + * @param[out] out \ref SetSysAnalogStickUserCalibration + */ +Result setsysGetAnalogStickUserCalibrationR(SetSysAnalogStickUserCalibration *out); + +/** + * @brief SetAnalogStickUserCalibrationR + * @note Only available on [8.1.1+]. + * @param[in] calibration \ref SetSysAnalogStickUserCalibration + */ +Result setsysSetAnalogStickUserCalibrationR(const SetSysAnalogStickUserCalibration *calibration); + +/** + * @brief GetPtmBatteryVersion + * @note Only available on [6.0.0+]. + * @param[out] out Output version. + */ +Result setsysGetPtmBatteryVersion(u8 *out); + +/** + * @brief SetPtmBatteryVersion + * @note Only available on [6.0.0+]. + * @param[in] version Input version. + */ +Result setsysSetPtmBatteryVersion(u8 version); + +/** + * @brief GetUsb30HostEnableFlag + * @note Only available on [6.0.0+]. + * @param[out] out Output flag. + */ +Result setsysGetUsb30HostEnableFlag(bool *out); + +/** + * @brief SetUsb30HostEnableFlag + * @note Only available on [6.0.0+]. + * @param[in] flag Input flag. + */ +Result setsysSetUsb30HostEnableFlag(bool flag); + +/** + * @brief GetUsb30DeviceEnableFlag + * @note Only available on [6.0.0+]. + * @param[out] out Output flag. + */ +Result setsysGetUsb30DeviceEnableFlag(bool *out); + +/** + * @brief SetUsb30DeviceEnableFlag + * @note Only available on [6.0.0+]. + * @param[in] flag Input flag. + */ +Result setsysSetUsb30DeviceEnableFlag(bool flag); + +/** + * @brief GetThemeId + * @note Only available on [7.0.0+]. + * @param[in] type Input theme id type. + * @param[out] out \ref SetSysThemeId + */ +Result setsysGetThemeId(s32 type, SetSysThemeId *out); + +/** + * @brief SetThemeId + * @note Only available on [7.0.0+]. + * @param[in] type Input theme id type. + * @param[in] theme_id \ref SetSysThemeId + */ +Result setsysSetThemeId(s32 type, const SetSysThemeId *theme_id); + /** * @brief GetChineseTraditionalInputMethod * @note Only available on [7.0.0+]. @@ -968,6 +2006,20 @@ Result setsysGetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod * */ Result setsysSetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod method); +/** + * @brief GetPtmCycleCountReliability + * @note Only available on [7.0.0+]. + * @param[out] out \ref SetSysPtmCycleCountReliability + */ +Result setsysGetPtmCycleCountReliability(SetSysPtmCycleCountReliability *out); + +/** + * @brief SetPtmCycleCountReliability + * @note Only available on [7.0.0+]. + * @param[in] reliability \ref SetSysPtmCycleCountReliability + */ +Result setsysSetPtmCycleCountReliability(SetSysPtmCycleCountReliability reliability); + /** * @brief Gets the \ref SetSysHomeMenuScheme. * @note Only available on [8.1.1+]. @@ -975,6 +2027,64 @@ Result setsysSetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod m */ Result setsysGetHomeMenuScheme(SetSysHomeMenuScheme *out); +/** + * @brief GetThemeSettings + * @note Only available on [7.0.0+]. + * @param[out] out \ref SetSysThemeSettings + */ +Result setsysGetThemeSettings(SetSysThemeSettings *out); + +/** + * @brief SetThemeSettings + * @note Only available on [7.0.0+]. + * @param[in] settings \ref SetSysThemeSettings + */ +Result setsysSetThemeSettings(const SetSysThemeSettings *settings); + +/** + * @brief GetThemeKey + * @note Only available on [7.0.0+]. + * @param[out] out \ref FsArchiveMacKey + */ +Result setsysGetThemeKey(FsArchiveMacKey *out); + +/** + * @brief SetThemeKey + * @note Only available on [7.0.0+]. + * @param[in] key \ref FsArchiveMacKey + */ +Result setsysSetThemeKey(const FsArchiveMacKey *key); + +/** + * @brief GetZoomFlag + * @note Only available on [8.0.0+]. + * @param[out] out Output flag. + */ +Result setsysGetZoomFlag(bool *out); + +/** + * @brief SetZoomFlag + * @note Only available on [8.0.0+]. + * @param[in] flag Input flag. + */ +Result setsysSetZoomFlag(bool flag); + +/** + * @brief Returns Terra platform type flag. + * @note On [9.0.0+], this is a wrapper for \ref setsysGetPlatFormRegion() == 2. + * @note Only available on [8.0.0+]. + * @param[out] out Output flag. + */ +Result setsysGetT(bool *out); + +/** + * @brief Sets Terra platform type flag. + * @note On [9.0.0+], this is a wrapper for \ref setsysSetPlatFormRegion(1 + (IsT & 1)). + * @note Only available on [8.0.0+]. + * @param[in] flag Input flag. + */ +Result setsysSetT(bool flag); + /** * @brief Gets the \ref SetSysPlatformRegion. * @note This is used internally by \ref appletGetSettingsPlatformRegion. diff --git a/nx/include/switch/services/time.h b/nx/include/switch/services/time.h index 756d2d68..9de42969 100644 --- a/nx/include/switch/services/time.h +++ b/nx/include/switch/services/time.h @@ -57,6 +57,11 @@ typedef struct { Uuid source_id; ///< An ID representing the clock source. } TimeSteadyClockTimePoint; +typedef struct { + s64 time_point; + TimeSteadyClockTimePoint steady_clock_time_point; +} TimeSystemClockContext; + /// Initialize time. Used automatically during app startup. Result timeInitialize(void); diff --git a/nx/source/services/set.c b/nx/source/services/set.c index 67d9dd92..8e7dbb07 100644 --- a/nx/source/services/set.c +++ b/nx/source/services/set.c @@ -114,6 +114,10 @@ static Result _setCmdInU64NoOut(Service* srv, u64 inval, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, inval); } +static Result _setCmdInUuidNoOut(Service* srv, const Uuid *inval, u32 cmd_id) { + return serviceDispatchIn(srv, cmd_id, *inval); +} + static Result setInitializeLanguageCodesCache(void) { if (g_setLanguageCodesInitialized) return 0; Result rc = 0; @@ -213,6 +217,20 @@ Result setsysSetLanguageCode(u64 LanguageCode) { return _setCmdInU64NoOut(&g_setsysSrv, LanguageCode, 0); } +Result setsysSetNetworkSettings(const SetSysNetworkSettings *settings, s32 count) { + return serviceDispatch(&g_setsysSrv, 1, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { settings, count*sizeof(SetSysNetworkSettings) } }, + ); +} + +Result setsysGetNetworkSettings(s32 *total_out, SetSysNetworkSettings *settings, s32 count) { + return serviceDispatchOut(&g_setsysSrv, 2, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { settings, count*sizeof(SetSysNetworkSettings) } }, + ); +} + static Result _setsysGetFirmwareVersionImpl(SetSysFirmwareVersion *out, u32 cmd_id) { return serviceDispatch(&g_setsysSrv, cmd_id, .buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_Out }, @@ -229,6 +247,10 @@ Result setsysGetFirmwareVersion(SetSysFirmwareVersion *out) { } } +Result setsysGetFirmwareVersionDigest(SetSysFirmwareVersionDigest *out) { + return serviceDispatchOut(&g_setsysSrv, 5, *out); +} + Result setsysGetLockScreenFlag(bool *out) { return _setCmdNoInOutBool(&g_setsysSrv, out, 7); } @@ -237,6 +259,44 @@ Result setsysSetLockScreenFlag(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 8); } +Result setsysGetBacklightSettings(SetSysBacklightSettings *out) { + return serviceDispatchOut(&g_setsysSrv, 9, *out); +} + +Result setsysSetBacklightSettings(const SetSysBacklightSettings *settings) { + return serviceDispatchIn(&g_setsysSrv, 10, *settings); +} + +Result setsysSetBluetoothDevicesSettings(const SetSysBluetoothDevicesSettings *settings, s32 count) { + return serviceDispatch(&g_setsysSrv, 11, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { settings, count*sizeof(SetSysBluetoothDevicesSettings) } }, + ); +} + +Result setsysGetBluetoothDevicesSettings(s32 *total_out, SetSysBluetoothDevicesSettings *settings, s32 count) { + return serviceDispatchOut(&g_setsysSrv, 12, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { settings, count*sizeof(SetSysBluetoothDevicesSettings) } }, + ); +} + +Result setsysGetExternalSteadyClockSourceId(Uuid *out) { + return _setCmdNoInOutUuid(&g_setsysSrv, out, 13); +} + +Result setsysSetExternalSteadyClockSourceId(const Uuid *uuid) { + return _setCmdInUuidNoOut(&g_setsysSrv, uuid, 14); +} + +Result setsysGetUserSystemClockContext(TimeSystemClockContext *out) { + return serviceDispatchOut(&g_setsysSrv, 15, *out); +} + +Result setsysSetUserSystemClockContext(const TimeSystemClockContext *context) { + return serviceDispatchIn(&g_setsysSrv, 16, *context); +} + Result setsysGetAccountSettings(SetSysAccountSettings *out) { return serviceDispatchOut(&g_setsysSrv, 17, *out); } @@ -245,6 +305,19 @@ Result setsysSetAccountSettings(SetSysAccountSettings settings) { return serviceDispatchIn(&g_setsysSrv, 18, settings); } +Result setsysGetAudioVolume(SetSysAudioDevice device, SetSysAudioVolume *out) { + return serviceDispatchInOut(&g_setsysSrv, 19, device, *out); +} + +Result setsysSetAudioVolume(SetSysAudioDevice device, const SetSysAudioVolume *volume) { + const struct { + SetSysAudioVolume volume; + u32 device; + } in = { *volume, device }; + + return serviceDispatchIn(&g_setsysSrv, 20, in); +} + Result setsysGetEulaVersions(s32 *total_out, SetSysEulaVersion *versions, s32 count) { return serviceDispatchOut(&g_setsysSrv, 21, *total_out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, @@ -308,6 +381,14 @@ Result setsysSetAccountNotificationSettings(const SetSysAccountNotificationSetti ); } +Result setsysGetVibrationMasterVolume(float *out) { + return serviceDispatchOut(&g_setsysSrv, 35, *out); +} + +Result setsysSetVibrationMasterVolume(float volume) { + return serviceDispatchIn(&g_setsysSrv, 36, volume); +} + Result setsysGetSettingsItemValueSize(const char *name, const char *item_key, u64 *size_out) { char send_name[SET_MAX_NAME_SIZE]; char send_item_key[SET_MAX_NAME_SIZE]; @@ -360,6 +441,44 @@ Result setsysSetTvSettings(const SetSysTvSettings *settings) { return serviceDispatchIn(&g_setsysSrv, 40, *settings); } +Result setsysGetEdid(SetSysEdid *out) { + return serviceDispatch(&g_setsysSrv, 41, + .buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_Out }, + .buffers = { { out, sizeof(*out) } }, + ); +} + +Result setsysSetEdid(const SetSysEdid *edid) { + return serviceDispatch(&g_setsysSrv, 42, + .buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_In }, + .buffers = { { edid, sizeof(*edid) } }, + ); +} + +Result setsysGetAudioOutputMode(SetSysAudioOutputModeTarget target, SetSysAudioOutputMode *out) { + u32 tmp=0; + Result rc = serviceDispatchInOut(&g_setsysSrv, 43, target, tmp); + if (R_SUCCEEDED(rc) && out) *out = tmp; + return rc; +} + +Result setsysSetAudioOutputMode(SetSysAudioOutputModeTarget target, SetSysAudioOutputMode mode) { + const struct { + u32 target; + u32 mode; + } in = { target, mode }; + + return serviceDispatchIn(&g_setsysSrv, 44, in); +} + +Result setsysIsForceMuteOnHeadphoneRemoved(bool *out) { + return _setCmdNoInOutBool(&g_setsysSrv, out, 45); +} + +Result setsysSetForceMuteOnHeadphoneRemoved(bool flag) { + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 46); +} + Result setsysGetQuestFlag(bool *out) { return _setCmdNoInOutBool(&g_setsysSrv, out, 47); } @@ -376,6 +495,22 @@ Result setsysSetDataDeletionSettings(const SetSysDataDeletionSettings *settings) return serviceDispatchIn(&g_setsysSrv, 50, *settings); } +Result setsysGetInitialSystemAppletProgramId(u64 *out) { + return _setCmdNoInOut64(&g_setsysSrv, out, 51); +} + +Result setsysGetOverlayDispProgramId(u64 *out) { + return _setCmdNoInOut64(&g_setsysSrv, out, 52); +} + +Result setsysGetDeviceTimeZoneLocationName(TimeLocationName *out) { + return serviceDispatchOut(&g_setsysSrv, 53, *out); +} + +Result setsysSetDeviceTimeZoneLocationName(const TimeLocationName *name) { + return serviceDispatchIn(&g_setsysSrv, 54, *name); +} + Result setsysGetWirelessCertificationFileSize(u64 *out_size) { return _setCmdNoInOut64(&g_setsysSrv, out_size, 55); } @@ -391,6 +526,14 @@ Result setsysSetRegionCode(SetRegion region) { return _setCmdInU32NoOut(&g_setsysSrv, region, 57); } +Result setsysGetNetworkSystemClockContext(TimeSystemClockContext *out) { + return serviceDispatchOut(&g_setsysSrv, 58, *out); +} + +Result setsysSetNetworkSystemClockContext(const TimeSystemClockContext *context) { + return serviceDispatchIn(&g_setsysSrv, 59, *context); +} + Result setsysIsUserSystemClockAutomaticCorrectionEnabled(bool *out) { return _setCmdNoInOutBool(&g_setsysSrv, out, 60); } @@ -399,6 +542,10 @@ Result setsysSetUserSystemClockAutomaticCorrectionEnabled(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 61); } +Result setsysGetDebugModeFlag(bool *out) { + return _setCmdNoInOutBool(&g_setsysSrv, out, 62); +} + Result setsysGetPrimaryAlbumStorage(SetSysPrimaryAlbumStorage *out) { u32 tmp=0; Result rc = _setCmdNoInOutU32(&g_setsysSrv, &tmp, 63); @@ -486,6 +633,46 @@ Result setsysGetProductModel(s32 *out) { return _setCmdNoInOutU32(&g_setsysSrv, (u32*)out, 79); } +Result setsysGetLdnChannel(s32 *out) { + return _setCmdNoInOutU32(&g_setsysSrv, (u32*)out, 80); +} + +Result setsysSetLdnChannel(s32 channel) { + return _setCmdInU32NoOut(&g_setsysSrv, (u32)channel, 81); +} + +Result setsysAcquireTelemetryDirtyFlagEventHandle(Event *out_event) { + return _setCmdGetEvent(&g_setsysSrv, out_event, false, 82); +} + +Result setsysGetTelemetryDirtyFlags(u64 *flags_0, u64 *flags_1) { + struct { + u64 flags_0; + u64 flags_1; + } out; + + Result rc = serviceDispatchOut(&g_setsysSrv, 83, out); + if (R_SUCCEEDED(rc) && flags_0) *flags_0 = out.flags_0; + if (R_SUCCEEDED(rc) && flags_1) *flags_1 = out.flags_1; + return rc; +} + +Result setsysGetPtmBatteryLot(SetBatteryLot *out) { + return serviceDispatchOut(&g_setsysSrv, 84, *out); +} + +Result setsysSetPtmBatteryLot(const SetBatteryLot *lot) { + return serviceDispatchIn(&g_setsysSrv, 85, *lot); +} + +Result setsysGetPtmFuelGaugeParameter(SetSysPtmFuelGaugeParameter *out) { + return serviceDispatchOut(&g_setsysSrv, 86, *out); +} + +Result setsysSetPtmFuelGaugeParameter(const SetSysPtmFuelGaugeParameter *parameter) { + return serviceDispatchIn(&g_setsysSrv, 87, *parameter); +} + Result setsysGetBluetoothEnableFlag(bool *out) { return _setCmdNoInOutBool(&g_setsysSrv, out, 88); } @@ -498,7 +685,15 @@ Result setsysGetMiiAuthorId(Uuid *out) { return _setCmdNoInOutUuid(&g_setsysSrv, out, 90); } -Result setsysBindFatalDirtyFlagEvent(Event *out_event) { +Result setsysSetShutdownRtcValue(u64 value) { + return _setCmdInU64NoOut(&g_setsysSrv, value, 91); +} + +Result setsysGetShutdownRtcValue(u64 *out) { + return _setCmdNoInOut64(&g_setsysSrv, out, 92); +} + +Result setsysAcquireFatalDirtyFlagEventHandle(Event *out_event) { return _setCmdGetEvent(&g_setsysSrv, out_event, false, 93); } @@ -528,6 +723,26 @@ Result setsysSetAutoUpdateEnableFlag(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 96); } +Result setsysGetNxControllerSettings(s32 *total_out, SetSysNxControllerSettings *settings, s32 count) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 97, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { settings, count*sizeof(SetSysNxControllerSettings) } }, + ); +} + +Result setsysSetNxControllerSettings(const SetSysNxControllerSettings *settings, s32 count) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatch(&g_setsysSrv, 98, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { settings, count*sizeof(SetSysNxControllerSettings) } }, + ); +} + Result setsysGetBatteryPercentageFlag(bool *out) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -570,6 +785,48 @@ Result setsysSetUsbFullKeyEnableFlag(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 104); } +Result setsysSetExternalSteadyClockInternalOffset(u64 offset) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU64NoOut(&g_setsysSrv, offset, 105); +} + +Result setsysGetExternalSteadyClockInternalOffset(u64 *out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOut64(&g_setsysSrv, out, 106); +} + +Result setsysGetBacklightSettingsEx(SetSysBacklightSettingsEx *out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 107, *out); +} + +Result setsysSetBacklightSettingsEx(const SetSysBacklightSettingsEx *settings) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 108, *settings); +} + +Result setsysGetHeadphoneVolumeWarningCount(u32 *out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutU32(&g_setsysSrv, out, 109); +} + +Result setsysSetHeadphoneVolumeWarningCount(u32 count) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU32NoOut(&g_setsysSrv, count, 110); +} + Result setsysGetBluetoothAfhEnableFlag(bool *out) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -626,6 +883,54 @@ Result setsysSetHeadphoneVolumeUpdateFlag(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 118); } +Result setsysNeedsToUpdateHeadphoneVolume(u8 *a0, u8 *a1, u8 *a2, bool flag) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + struct { + u8 a0; + u8 a1; + u8 a2; + } out; + + Result rc = serviceDispatchInOut(&g_setsysSrv, 119, flag, out); + if (R_SUCCEEDED(rc) && a0) *a0 = out.a0; + if (R_SUCCEEDED(rc) && a1) *a1 = out.a1; + if (R_SUCCEEDED(rc) && a2) *a2 = out.a2; + return rc; +} + +Result setsysGetPushNotificationActivityModeOnSleep(u32 *out) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutU32(&g_setsysSrv, out, 120); +} + +Result setsysSetPushNotificationActivityModeOnSleep(u32 mode) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU32NoOut(&g_setsysSrv, mode, 121); +} + +Result setsysGetServiceDiscoveryControlSettings(SetSysServiceDiscoveryControlSettings *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u32 tmp=0; + Result rc = _setCmdNoInOutU32(&g_setsysSrv, &tmp, 122); + if (R_SUCCEEDED(rc) && out) *out = tmp; + return rc; +} + +Result setsysSetServiceDiscoveryControlSettings(SetSysServiceDiscoveryControlSettings settings) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU32NoOut(&g_setsysSrv, settings, 123); +} + Result setsysGetErrorReportSharePermission(SetSysErrorReportSharePermission *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -657,6 +962,62 @@ Result setsysSetAppletLaunchFlags(u32 flags) { return _setCmdInU32NoOut(&g_setsysSrv, flags, 127); } +Result setsysGetConsoleSixAxisSensorAccelerationBias(SetSysConsoleSixAxisSensorAccelerationBias *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 128, *out); +} + +Result setsysSetConsoleSixAxisSensorAccelerationBias(const SetSysConsoleSixAxisSensorAccelerationBias *bias) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 129, *bias); +} + +Result setsysGetConsoleSixAxisSensorAngularVelocityBias(SetSysConsoleSixAxisSensorAngularVelocityBias *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 130, *out); +} + +Result setsysSetConsoleSixAxisSensorAngularVelocityBias(const SetSysConsoleSixAxisSensorAngularVelocityBias *bias) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 131, *bias); +} + +Result setsysGetConsoleSixAxisSensorAccelerationGain(SetSysConsoleSixAxisSensorAccelerationGain *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 132, *out); +} + +Result setsysSetConsoleSixAxisSensorAccelerationGain(const SetSysConsoleSixAxisSensorAccelerationGain *gain) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 133, *gain); +} + +Result setsysGetConsoleSixAxisSensorAngularVelocityGain(SetSysConsoleSixAxisSensorAngularVelocityGain *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 134, *out); +} + +Result setsysSetConsoleSixAxisSensorAngularVelocityGain(const SetSysConsoleSixAxisSensorAngularVelocityGain *gain) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 135, *gain); +} + Result setsysGetKeyboardLayout(SetKeyboardLayout *out) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -674,6 +1035,33 @@ Result setsysSetKeyboardLayout(SetKeyboardLayout layout) { return _setCmdInU32NoOut(&g_setsysSrv, layout, 137); } +Result setsysGetWebInspectorFlag(bool *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutBool(&g_setsysSrv, out, 138); +} + +Result setsysGetAllowedSslHosts(s32 *total_out, SetSysAllowedSslHosts *out, s32 count) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 139, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { out, count*sizeof(SetSysAllowedSslHosts) } }, + ); +} + +Result setsysGetHostFsMountPoint(SetSysHostFsMountPoint *out) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatch(&g_setsysSrv, 140, + .buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { out, sizeof(SetSysHostFsMountPoint) } }, + ); +} + Result setsysGetRequiresRunRepairTimeReviser(bool *out) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -681,6 +1069,61 @@ Result setsysGetRequiresRunRepairTimeReviser(bool *out) { return _setCmdNoInOutBool(&g_setsysSrv, out, 141); } +Result setsysSetRequiresRunRepairTimeReviser(bool flag) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 142); +} + +Result setsysSetBlePairingSettings(const SetSysBlePairingSettings *settings, s32 count) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatch(&g_setsysSrv, 143, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { settings, count*sizeof(SetSysBlePairingSettings) } }, + ); +} + +Result setsysGetBlePairingSettings(s32 *total_out, SetSysBlePairingSettings *settings, s32 count) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 144, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { settings, count*sizeof(SetSysBlePairingSettings) } }, + ); +} + +Result setsysGetConsoleSixAxisSensorAngularVelocityTimeBias(SetSysConsoleSixAxisSensorAngularVelocityTimeBias *out) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 145, *out); +} + +Result setsysSetConsoleSixAxisSensorAngularVelocityTimeBias(const SetSysConsoleSixAxisSensorAngularVelocityTimeBias *bias) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 146, *bias); +} + +Result setsysGetConsoleSixAxisSensorAngularAcceleration(SetSysConsoleSixAxisSensorAngularAcceleration *out) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 147, *out); +} + +Result setsysSetConsoleSixAxisSensorAngularAcceleration(const SetSysConsoleSixAxisSensorAngularAcceleration *acceleration) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 148, *acceleration); +} + Result setsysGetRebootlessSystemUpdateVersion(SetSysRebootlessSystemUpdateVersion *out) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -688,11 +1131,52 @@ Result setsysGetRebootlessSystemUpdateVersion(SetSysRebootlessSystemUpdateVersio return serviceDispatchOut(&g_setsysSrv, 149, *out); } -Result setsysSetRequiresRunRepairTimeReviser(bool flag) { +Result setsysGetDeviceTimeZoneLocationUpdatedTime(TimeSteadyClockTimePoint *out) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _setCmdInBoolNoOut(&g_setsysSrv, flag, 142); + return serviceDispatchOut(&g_setsysSrv, 150, *out); +} + +Result setsysSetDeviceTimeZoneLocationUpdatedTime(const TimeSteadyClockTimePoint *time_point) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 151, *time_point); +} + +Result setsysGetUserSystemClockAutomaticCorrectionUpdatedTime(TimeSteadyClockTimePoint *out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 152, *out); +} + +Result setsysSetUserSystemClockAutomaticCorrectionUpdatedTime(const TimeSteadyClockTimePoint *time_point) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 153, *time_point); +} + +Result setsysGetAccountOnlineStorageSettings(s32 *total_out, SetSysAccountOnlineStorageSettings *settings, s32 count) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 154, *total_out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { settings, count*sizeof(SetSysAccountOnlineStorageSettings) } }, + ); +} + +Result setsysSetAccountOnlineStorageSettings(const SetSysAccountOnlineStorageSettings *settings, s32 count) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatch(&g_setsysSrv, 155, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { settings, count*sizeof(SetSysAccountOnlineStorageSettings) } }, + ); } Result setsysGetPctlReadyFlag(bool *out) { @@ -709,6 +1193,95 @@ Result setsysSetPctlReadyFlag(bool flag) { return _setCmdInBoolNoOut(&g_setsysSrv, flag, 157); } +Result setsysGetAnalogStickUserCalibrationL(SetSysAnalogStickUserCalibration *out) { + if (hosversionBefore(8,1,1)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 158, *out); +} + +Result setsysSetAnalogStickUserCalibrationL(const SetSysAnalogStickUserCalibration *calibration) { + if (hosversionBefore(8,1,1)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 159, *calibration); +} + +Result setsysGetAnalogStickUserCalibrationR(SetSysAnalogStickUserCalibration *out) { + if (hosversionBefore(8,1,1)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 160, *out); +} + +Result setsysSetAnalogStickUserCalibrationR(const SetSysAnalogStickUserCalibration *calibration) { + if (hosversionBefore(8,1,1)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 161, *calibration); +} + +Result setsysGetPtmBatteryVersion(u8 *out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutU8(&g_setsysSrv, out, 162); +} + +Result setsysSetPtmBatteryVersion(u8 version) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU8NoOut(&g_setsysSrv, version, 163); +} + +Result setsysGetUsb30HostEnableFlag(bool *out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutBool(&g_setsysSrv, out, 164); +} + +Result setsysSetUsb30HostEnableFlag(bool flag) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 165); +} + +Result setsysGetUsb30DeviceEnableFlag(bool *out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutBool(&g_setsysSrv, out, 166); +} + +Result setsysSetUsb30DeviceEnableFlag(bool flag) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 167); +} + +Result setsysGetThemeId(s32 type, SetSysThemeId *out) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchInOut(&g_setsysSrv, 168, type, *out); +} + +Result setsysSetThemeId(s32 type, const SetSysThemeId *theme_id) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + const struct { + s32 type; + SetSysThemeId theme_id; + } in = { type, *theme_id }; + + return serviceDispatchIn(&g_setsysSrv, 169, in); +} + Result setsysGetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod *out) { if (hosversionBefore(7,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -726,6 +1299,23 @@ Result setsysSetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod m return _setCmdInU32NoOut(&g_setsysSrv, method, 171); } +Result setsysGetPtmCycleCountReliability(SetSysPtmCycleCountReliability *out) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u32 tmp=0; + Result rc = _setCmdNoInOutU32(&g_setsysSrv, &tmp, 172); + if (R_SUCCEEDED(rc) && out) *out = tmp; + return rc; +} + +Result setsysSetPtmCycleCountReliability(SetSysPtmCycleCountReliability reliability) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInU32NoOut(&g_setsysSrv, reliability, 173); +} + Result setsysGetHomeMenuScheme(SetSysHomeMenuScheme *out) { if (hosversionBefore(8,1,1)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -733,6 +1323,62 @@ Result setsysGetHomeMenuScheme(SetSysHomeMenuScheme *out) { return serviceDispatchOut(&g_setsysSrv, 174, *out); } +Result setsysGetThemeSettings(SetSysThemeSettings *out) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 175, *out); +} + +Result setsysSetThemeSettings(const SetSysThemeSettings *settings) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 176, *settings); +} + +Result setsysGetThemeKey(FsArchiveMacKey *out) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_setsysSrv, 177, *out); +} + +Result setsysSetThemeKey(const FsArchiveMacKey *key) { + if (hosversionBefore(7,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_setsysSrv, 178, *key); +} + +Result setsysGetZoomFlag(bool *out) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutBool(&g_setsysSrv, out, 179); +} + +Result setsysSetZoomFlag(bool flag) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 180); +} + +Result setsysGetT(bool *out) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdNoInOutBool(&g_setsysSrv, out, 181); +} + +Result setsysSetT(bool flag) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _setCmdInBoolNoOut(&g_setsysSrv, flag, 182); +} + Result setsysGetPlatformRegion(SetSysPlatformRegion *out) { if (hosversionBefore(9,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -782,58 +1428,58 @@ Result setsysSetTouchScreenMode(SetSysTouchScreenMode mode) { } Result setcalGetBdAddress(SetCalBdAddress *out) { - return serviceDispatchOut(&g_setsysSrv, 0, *out); + return serviceDispatchOut(&g_setcalSrv, 0, *out); } Result setcalGetConfigurationId1(SetCalConfigurationId1 *out) { - return serviceDispatchOut(&g_setsysSrv, 1, *out); + return serviceDispatchOut(&g_setcalSrv, 1, *out); } Result setcalGetAccelerometerOffset(SetCalAccelerometerOffset *out) { - return serviceDispatchOut(&g_setsysSrv, 2, *out); + return serviceDispatchOut(&g_setcalSrv, 2, *out); } Result setcalGetAccelerometerScale(SetCalAccelerometerScale *out) { - return serviceDispatchOut(&g_setsysSrv, 3, *out); + return serviceDispatchOut(&g_setcalSrv, 3, *out); } Result setcalGetGyroscopeOffset(SetCalAccelerometerOffset *out) { - return serviceDispatchOut(&g_setsysSrv, 4, *out); + return serviceDispatchOut(&g_setcalSrv, 4, *out); } Result setcalGetGyroscopeScale(SetCalGyroscopeScale *out) { - return serviceDispatchOut(&g_setsysSrv, 5, *out); + return serviceDispatchOut(&g_setcalSrv, 5, *out); } Result setcalGetWirelessLanMacAddress(SetCalMacAddress *out) { - return serviceDispatchOut(&g_setsysSrv, 6, *out); + return serviceDispatchOut(&g_setcalSrv, 6, *out); } Result setcalGetWirelessLanCountryCodeCount(s32 *out_count) { - return _setCmdNoInOutU32(&g_setsysSrv, (u32*)out_count, 7); + return _setCmdNoInOutU32(&g_setcalSrv, (u32*)out_count, 7); } Result setcalGetWirelessLanCountryCodes(s32 *total_out, SetCalCountryCode *codes, s32 count) { - return serviceDispatchOut(&g_setsysSrv, 8, *total_out, + return serviceDispatchOut(&g_setcalSrv, 8, *total_out, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out }, .buffers = { { codes, count*sizeof(SetCalCountryCode) } }, ); } Result setcalGetSerialNumber(SetCalSerialNumber *out) { - return serviceDispatchOut(&g_setsysSrv, 9, *out); + return serviceDispatchOut(&g_setcalSrv, 9, *out); } Result setcalSetInitialSystemAppletProgramId(u64 program_id) { - return _setCmdInU64NoOut(&g_setsysSrv, program_id, 10); + return _setCmdInU64NoOut(&g_setcalSrv, program_id, 10); } Result setcalSetOverlayDispProgramId(u64 program_id) { - return _setCmdInU64NoOut(&g_setsysSrv, program_id, 11); + return _setCmdInU64NoOut(&g_setcalSrv, program_id, 11); } Result setcalGetBatteryLot(SetBatteryLot *out) { - return serviceDispatchOut(&g_setsysSrv, 12, *out); + return serviceDispatchOut(&g_setcalSrv, 12, *out); } Result setcalGetEciDeviceCertificate(SetCalEccB233DeviceCertificate *out) { From 8421863c780a370f6c5cb3bfe553393e90f862da Mon Sep 17 00:00:00 2001 From: fincs Date: Tue, 10 Mar 2020 17:42:00 +0100 Subject: [PATCH 20/21] applet: appletSetFocusHandlingMode should only be used with Application --- nx/include/switch/services/applet.h | 4 ++++ nx/source/services/applet.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index ee02c6f0..2fc56b32 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -2468,6 +2468,10 @@ AppletOperationMode appletGetOperationMode(void); ApmPerformanceMode appletGetPerformanceMode(void); AppletFocusState appletGetFocusState(void); +/** + * @brief Sets the current \ref AppletFocusHandlingMode. + * @note Should only be called with AppletType_Application. + */ Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode); ///@} diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index e66ac5ba..f83ed9f0 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -541,6 +541,8 @@ Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode) { Result rc; bool invals[4]; + if (__nx_applet_type != AppletType_Application) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); if (mode >= AppletFocusHandlingMode_Max) return MAKERESULT(Module_Libnx, LibnxError_BadInput); From d7e6207708f2c976b7cbb3707e6a01d3e88083ab Mon Sep 17 00:00:00 2001 From: CTCaer Date: Wed, 11 Mar 2020 12:23:25 +0200 Subject: [PATCH 21/21] ts: Add temperature location comments Avert some confusion about the locations. HOS uses TMP451 IC's internal thermistor for PCB temp readings and external is connected to a thermistor to SoC's package temp pins, so SoC temp readings. --- nx/include/switch/services/ts.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/services/ts.h b/nx/include/switch/services/ts.h index cc85b0c8..81ce554e 100644 --- a/nx/include/switch/services/ts.h +++ b/nx/include/switch/services/ts.h @@ -10,8 +10,8 @@ /// Location typedef enum { - TsLocation_Internal = 0, ///< Internal - TsLocation_External = 1, ///< External + TsLocation_Internal = 0, ///< TMP451 Internal: PCB + TsLocation_External = 1, ///< TMP451 External: SoC } TsLocation; /// Initialize ts.