From 4a33b32f439264990694e54893886b4feeb36e05 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 9 Dec 2021 01:01:24 -0500 Subject: [PATCH] nfc: Added more cmds, etc. --- nx/include/switch/services/nfc.h | 4 +++ nx/source/services/nfc.c | 42 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/services/nfc.h b/nx/include/switch/services/nfc.h index f5725f66..9d20eb4a 100644 --- a/nx/include/switch/services/nfc.h +++ b/nx/include/switch/services/nfc.h @@ -155,3 +155,7 @@ Result nfpAttachAvailabilityChangeEvent(Event *out_event); /// This uses nfc:*. Result nfcIsNfcEnabled(bool *out); + +Result nfcSendCommandByPassThrough(const NfcDeviceHandle *handle, u64 timeout, const void* cmd_buf, size_t cmd_buf_size, void* reply_buf, size_t reply_buf_size, u64 *out_size); +Result nfcKeepPassThroughSession(const NfcDeviceHandle *handle); +Result nfcReleasePassThroughSession(const NfcDeviceHandle *handle); diff --git a/nx/source/services/nfc.c b/nx/source/services/nfc.c index 3ff9efd4..c8989b13 100644 --- a/nx/source/services/nfc.c +++ b/nx/source/services/nfc.c @@ -69,7 +69,7 @@ void _nfpCleanup(void) { NX_GENERATE_SERVICE_GUARD_PARAMS(nfc, (NfcServiceType service_type), (service_type)); Result _nfcInitialize(NfcServiceType service_type) { - Result rc=0; + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); g_nfcServiceType = service_type; switch (g_nfcServiceType) { @@ -347,3 +347,43 @@ Result nfpAttachAvailabilityChangeEvent(Event *out_event) { Result nfcIsNfcEnabled(bool *out) { return _nfcCmdNoInOutBool(&g_nfcInterface, out, hosversionBefore(4,0,0) ? 3 : 403); } + +Result nfcSendCommandByPassThrough(const NfcDeviceHandle *handle, u64 timeout, const void* cmd_buf, size_t cmd_buf_size, void* reply_buf, size_t reply_buf_size, u64 *out_size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + const struct { + NfcDeviceHandle handle; + u64 timeout; + } in = { *handle, timeout }; + + serviceAssumeDomain(&g_nfcInterface); + u32 tmp_out=0; + Result rc = serviceDispatchInOut(&g_nfcInterface, 1300, in, tmp_out, + .buffer_attrs = { + SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, + SfBufferAttr_HipcMapAlias | SfBufferAttr_In, + }, + .buffers = { + { reply_buf, reply_buf_size }, + { cmd_buf, cmd_buf_size }, + }, + ); + if (R_SUCCEEDED(rc) && out_size) *out_size = tmp_out; + return rc; +} + +Result nfcKeepPassThroughSession(const NfcDeviceHandle *handle) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nfcCmdInDevhandleNoOut(&g_nfcInterface, handle, 1301); +} + +Result nfcReleasePassThroughSession(const NfcDeviceHandle *handle) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _nfcCmdInDevhandleNoOut(&g_nfcInterface, handle, 1302); +} +