mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Implement setsys GetDeviceNickname/SetDeviceNickname (#289)
* Implement setsys(Get/Set)DeviceNickname. Thanks to @shchmue & @thog for tips on the send/recv buffers!
This commit is contained in:
parent
8cf419802a
commit
133ffe92fd
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user