diff --git a/nx/include/switch/services/hidsys.h b/nx/include/switch/services/hidsys.h index 92318f19..280aa3cb 100644 --- a/nx/include/switch/services/hidsys.h +++ b/nx/include/switch/services/hidsys.h @@ -71,3 +71,9 @@ Result hidsysGetUniquePadIds(u64 *UniquePadIds, size_t count, size_t *total_entr */ Result hidsysSetNotificationLedPattern(const HidsysNotificationLedPattern *pattern, u64 UniquePadId); +/** + * @brief Gets the unique pad's serial number. + * @param UniquePadId UniquePadId for the controller. + * @param serial Pointer to output the serial to. (The buffer size needs to be at least 0x19 bytes) + */ +Result hidsysGetUniquePadSerialNumber(u64 UniquePadId, char *serial); diff --git a/nx/source/services/hidsys.c b/nx/source/services/hidsys.c index 754d73b2..ad8df5fe 100644 --- a/nx/source/services/hidsys.c +++ b/nx/source/services/hidsys.c @@ -300,3 +300,46 @@ Result hidsysSetNotificationLedPattern(const HidsysNotificationLedPattern *patte return rc; } +Result hidsysGetUniquePadSerialNumber(u64 UniquePadId, char *serial) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + IpcCommand c; + ipcInitialize(&c); + + if (serial) memset(serial, 0, 0x19); + + struct { + u64 magic; + u64 cmd_id; + u64 UniquePadId; + } *raw; + + raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 809; + raw->UniquePadId = UniquePadId; + + Result rc = serviceIpcDispatch(&g_hidsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + + struct { + u64 magic; + u64 result; + char serial[0x18]; + } *resp; + + serviceIpcParse(&g_hidsysSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && serial) + memcpy(serial, resp->serial, 0x18); + } + + return rc; +}