ns: Added nsGetECommerceInterface. Added cmds: nsRequestLinkDevice, nsRequestSyncRights, nsRequestUnlinkDevice. Minor adjustments.

This commit is contained in:
yellows8 2020-02-28 14:36:10 -05:00
parent 7e07d1edf0
commit fdb6aa1f15
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 106 additions and 2 deletions

View File

@ -244,6 +244,10 @@ Service* nsGetServiceSession_GetterInterface(void);
/// Gets the Service object for IApplicationManagerInterface. /// Gets the Service object for IApplicationManagerInterface.
Service* nsGetServiceSession_ApplicationManagerInterface(void); 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. /// Gets the Service object for IFactoryResetInterface via the cmd for that.
/// Only available on [3.0.0+]. /// Only available on [3.0.0+].
Result nsGetFactoryResetInterface(Service* srv_out); 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 ///@name IFactoryResetInterface
///@{ ///@{

View File

@ -46,6 +46,13 @@ Service* nsGetServiceSession_ApplicationManagerInterface(void) {
return &g_nsAppManSrv; 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) { Result nsGetFactoryResetInterface(Service* srv_out) {
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
@ -251,10 +258,73 @@ static Result _nsCmdInU64OutAsyncResult(Service* srv, AsyncResult *a, u64 inval,
return rc; 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) { static Result _nsCheckNifm(void) {
return nifmIsAnyInternetRequestAccepted(nifmGetClientId()) ? 0 : MAKERESULT(16, 340); 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 // IFactoryResetInterface
Result nsResetToFactorySettings(void) { Result nsResetToFactorySettings(void) {