From 133ffe92fdeb2e36fbd8be867daf5cd3ae5e2cc4 Mon Sep 17 00:00:00 2001 From: thedax Date: Tue, 4 Jun 2019 10:22:51 -0400 Subject: [PATCH] Implement setsys GetDeviceNickname/SetDeviceNickname (#289) * Implement setsys(Get/Set)DeviceNickname. Thanks to @shchmue & @thog for tips on the send/recv buffers! --- nx/include/switch/services/set.h | 13 ++++++ nx/source/services/set.c | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 1f8b41ee..57b9a2b4 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -11,6 +11,7 @@ #include "../kernel/event.h" #define SET_MAX_NAME_SIZE 0x48 +#define SET_MAX_NICKNAME_SIZE 0x80 typedef enum { ColorSetId_Light=0, @@ -175,3 +176,15 @@ Result setsysBindFatalDirtyFlagEvent(Event *out); * @param flags_1 Pointer to populate with second 64 flags. */ Result setsysGetFatalDirtyFlags(u64 *flags_0, u64 *flags_1); + +/** + * @brief Gets the system's nickname. + * @param nickname Pointer to output the nickname to. (The buffer size needs to be at least 0x80 bytes) + */ +Result setsysGetDeviceNickname(char* nickname); + +/** + * @brief Sets the system's nickname. + * @param nickname Pointer to read the nickname from. + */ +Result setsysSetDeviceNickname(const char* nickname); diff --git a/nx/source/services/set.c b/nx/source/services/set.c index 0772dac5..ad45633e 100644 --- a/nx/source/services/set.c +++ b/nx/source/services/set.c @@ -686,3 +686,71 @@ Result setsysGetFatalDirtyFlags(u64 *flags_0, u64 *flags_1) { return rc; } + +Result setsysGetDeviceNickname(char* nickname) { + IpcCommand c; + ipcInitialize(&c); + + ipcAddRecvBuffer(&c, nickname, SET_MAX_NICKNAME_SIZE, BufferType_Normal); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 77; + + Result rc = serviceIpcDispatch(&g_setsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result setsysSetDeviceNickname(const char* nickname) { + char send_nickname[SET_MAX_NICKNAME_SIZE] = {0}; + strncpy(send_nickname, nickname, SET_MAX_NICKNAME_SIZE-1); + + IpcCommand c; + ipcInitialize(&c); + ipcAddSendBuffer(&c, send_nickname, SET_MAX_NICKNAME_SIZE, 0); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 78; + + Result rc = serviceIpcDispatch(&g_setsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +}