From deb7518153f7bb3868dd713657373bc5040740e6 Mon Sep 17 00:00:00 2001 From: Lectem Date: Wed, 9 Sep 2015 16:44:02 -0400 Subject: [PATCH] Use IPC helpers for soc --- libctru/source/services/soc/soc_accept.c | 18 +++++++++-------- libctru/source/services/soc/soc_bind.c | 7 ++++--- libctru/source/services/soc/soc_connect.c | 7 ++++--- libctru/source/services/soc/soc_fcntl.c | 5 +++-- .../source/services/soc/soc_gethostbyname.c | 17 ++++++++-------- libctru/source/services/soc/soc_gethostid.c | 3 ++- libctru/source/services/soc/soc_getpeername.c | 18 +++++++++-------- libctru/source/services/soc/soc_getsockname.c | 18 +++++++++-------- libctru/source/services/soc/soc_getsockopt.c | 18 +++++++++-------- libctru/source/services/soc/soc_init.c | 13 ++++++------ libctru/source/services/soc/soc_listen.c | 5 +++-- libctru/source/services/soc/soc_poll.c | 20 ++++++++++--------- libctru/source/services/soc/soc_recvfrom.c | 20 ++++++++++--------- libctru/source/services/soc/soc_sendto.c | 17 ++++++++-------- libctru/source/services/soc/soc_setsockopt.c | 7 ++++--- libctru/source/services/soc/soc_shutdown.c | 5 +++-- libctru/source/services/soc/soc_sockatmark.c | 5 +++-- libctru/source/services/soc/soc_socket.c | 5 +++-- 18 files changed, 116 insertions(+), 92 deletions(-) diff --git a/libctru/source/services/soc/soc_accept.c b/libctru/source/services/soc/soc_accept.c index 71ce790..a5a39e3 100644 --- a/libctru/source/services/soc/soc_accept.c +++ b/libctru/source/services/soc/soc_accept.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { @@ -36,16 +37,17 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) memset(tmpaddr, 0, 0x1c); - cmdbuf[0] = 0x00040082; + cmdbuf[0] = IPC_MakeHeader(0x4,2,2); // 0x40082 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)tmp_addrlen; - cmdbuf[3] = 0x20; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (tmp_addrlen<<14) | 2; - cmdbuf[0x104>>2] = (u32)tmpaddr; + staticbufs[0] = IPC_Desc_StaticBuffer(tmp_addrlen,0); + staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -54,8 +56,8 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return ret; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_bind.c b/libctru/source/services/soc/soc_bind.c index 610cdf6..b452992 100644 --- a/libctru/source/services/soc/soc_bind.c +++ b/libctru/source/services/soc/soc_bind.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { @@ -31,11 +32,11 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) tmpaddr[1] = addr->sa_family; memcpy(&tmpaddr[2], &addr->sa_data, tmp_addrlen-2); - cmdbuf[0] = 0x00050084; + cmdbuf[0] = IPC_MakeHeader(0x5,2,4); // 0x50084 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)tmp_addrlen; - cmdbuf[3] = 0x20; - cmdbuf[5] = (((u32)tmp_addrlen)<<14) | 2; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); + cmdbuf[5] = IPC_Desc_StaticBuffer(tmp_addrlen,0); cmdbuf[6] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); diff --git a/libctru/source/services/soc/soc_connect.c b/libctru/source/services/soc/soc_connect.c index 4cab7cc..5778858 100644 --- a/libctru/source/services/soc/soc_connect.c +++ b/libctru/source/services/soc/soc_connect.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { @@ -31,11 +32,11 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) tmpaddr[1] = addr->sa_family; memcpy(&tmpaddr[2], &addr->sa_data, tmp_addrlen-2); - cmdbuf[0] = 0x00060084; + cmdbuf[0] = IPC_MakeHeader(0x6,2,4); // 0x60084 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)addrlen; - cmdbuf[3] = 0x20; - cmdbuf[5] = (((u32)tmp_addrlen)<<14) | 2; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); + cmdbuf[5] = IPC_Desc_StaticBuffer(tmp_addrlen,0); cmdbuf[6] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); diff --git a/libctru/source/services/soc/soc_fcntl.c b/libctru/source/services/soc/soc_fcntl.c index f14a0e0..824fea0 100644 --- a/libctru/source/services/soc/soc_fcntl.c +++ b/libctru/source/services/soc/soc_fcntl.c @@ -2,6 +2,7 @@ #include #include #include +#include <3ds/ipc.h> #define O_NONBLOCK_3DS 0x4 @@ -63,11 +64,11 @@ int fcntl(int sockfd, int cmd, ...) arg = to_3ds(arg); } - cmdbuf[0] = 0x001300C2; + cmdbuf[0] = IPC_MakeHeader(0x13,3,2); // 0x1300C2 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)cmd; cmdbuf[3] = (u32)arg; - cmdbuf[4] = 0x20; + cmdbuf[4] = IPC_Desc_CurProcessHandle(); ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_gethostbyname.c b/libctru/source/services/soc/soc_gethostbyname.c index 2121c3b..50c44aa 100644 --- a/libctru/source/services/soc/soc_gethostbyname.c +++ b/libctru/source/services/soc/soc_gethostbyname.c @@ -1,5 +1,6 @@ #include "soc_common.h" #include +#include <3ds/ipc.h> #define MAX_HOSTENT_RESULTS 16 static struct hostent SOC_hostent; @@ -15,17 +16,18 @@ struct hostent* gethostbyname(const char *name) h_errno = 0; - cmdbuf[0] = 0x000D0082; + cmdbuf[0] = IPC_MakeHeader(0xD,2,2); // 0xD0082 cmdbuf[1] = strlen(name)+1; cmdbuf[2] = sizeof(outbuf); cmdbuf[3] = ((strlen(name)+1) << 14) | 0xC02; cmdbuf[4] = (u32)name; - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (sizeof(outbuf) << 14) | 2; - cmdbuf[0x104>>2] = (u32)outbuf; + staticbufs[0] = IPC_Desc_StaticBuffer(sizeof(outbuf),0); + staticbufs[1] = (u32)outbuf; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -33,9 +35,8 @@ struct hostent* gethostbyname(const char *name) return NULL; } - - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_gethostid.c b/libctru/source/services/soc/soc_gethostid.c index 7a254aa..ba4fe4f 100644 --- a/libctru/source/services/soc/soc_gethostid.c +++ b/libctru/source/services/soc/soc_gethostid.c @@ -1,12 +1,13 @@ #include "soc_common.h" #include +#include <3ds/ipc.h> long gethostid(void) { int ret = 0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = 0x00160000; + cmdbuf[0] = IPC_MakeHeader(0x16,0,0); // 0x160000 ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_getpeername.c b/libctru/source/services/soc/soc_getpeername.c index 977b14b..b0aedab 100644 --- a/libctru/source/services/soc/soc_getpeername.c +++ b/libctru/source/services/soc/soc_getpeername.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { @@ -15,16 +16,17 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return -1; } - cmdbuf[0] = 0x00180082; + cmdbuf[0] = IPC_MakeHeader(0x18,2,2); // 0x180082 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = 0x1c; - cmdbuf[3] = 0x20; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (0x1c<<14) | 2; - cmdbuf[0x104>>2] = (u32)tmpaddr; + staticbufs[0] = IPC_Desc_StaticBuffer(0x1c,0); + staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -32,8 +34,8 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return ret; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_getsockname.c b/libctru/source/services/soc/soc_getsockname.c index 2fd16b3..9b9f0c3 100644 --- a/libctru/source/services/soc/soc_getsockname.c +++ b/libctru/source/services/soc/soc_getsockname.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { @@ -15,16 +16,17 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return -1; } - cmdbuf[0] = 0x00170082; + cmdbuf[0] = IPC_MakeHeader(0x17,2,2); // 0x170082 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = 0x1c; - cmdbuf[3] = 0x20; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (0x1c<<14) | 2; - cmdbuf[0x104>>2] = (u32)tmpaddr; + staticbufs[0] = IPC_Desc_StaticBuffer(0x1c,0); + staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -32,8 +34,8 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) return ret; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_getsockopt.c b/libctru/source/services/soc/soc_getsockopt.c index 8b48994..52d0f6e 100644 --- a/libctru/source/services/soc/soc_getsockopt.c +++ b/libctru/source/services/soc/soc_getsockopt.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen) { @@ -14,18 +15,19 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl return -1; } - cmdbuf[0] = 0x00110102; + cmdbuf[0] = IPC_MakeHeader(0x11,4,2); // 0x110102 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)level; cmdbuf[3] = (u32)optname; cmdbuf[4] = (u32)*optlen; - cmdbuf[5] = 0x20; + cmdbuf[5] = IPC_Desc_CurProcessHandle(); - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = ((*optlen)<<14) | 2; - cmdbuf[0x104>>2] = (u32)optval; + staticbufs[0] = IPC_Desc_StaticBuffer(*optlen,0); + staticbufs[1] = (u32)optval; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -33,8 +35,8 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl return ret; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_init.c b/libctru/source/services/soc/soc_init.c index 3b84b65..e6263d7 100644 --- a/libctru/source/services/soc/soc_init.c +++ b/libctru/source/services/soc/soc_init.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> static int soc_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode); static int soc_close(struct _reent *r, int fd); @@ -43,10 +44,10 @@ static Result socu_cmd1(Handle memhandle, u32 memsize) Result ret = 0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = 0x00010044; + cmdbuf[0] = IPC_MakeHeader(0x1,1,4); // 0x10044 cmdbuf[1] = memsize; - cmdbuf[2] = 0x20; - cmdbuf[4] = 0; + cmdbuf[2] = IPC_Desc_CurProcessHandle(); + cmdbuf[4] = IPC_Desc_SharedHandles(1); cmdbuf[5] = memhandle; ret = svcSendSyncRequest(SOCU_handle); @@ -111,7 +112,7 @@ Result SOC_Shutdown(void) svcCloseHandle(socMemhandle); socMemhandle = 0; - cmdbuf[0] = 0x00190000; + cmdbuf[0] = IPC_MakeHeader(0x19,0,0); // 0x190000 ret = svcSendSyncRequest(SOCU_handle); @@ -146,9 +147,9 @@ soc_close(struct _reent *r, int ret = 0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = 0x000B0042; + cmdbuf[0] = IPC_MakeHeader(0xB,1,2); // 0xB0042 cmdbuf[1] = (u32)sockfd; - cmdbuf[2] = 0x20; + cmdbuf[2] = IPC_Desc_CurProcessHandle(); ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_listen.c b/libctru/source/services/soc/soc_listen.c index 53257d2..542fa02 100644 --- a/libctru/source/services/soc/soc_listen.c +++ b/libctru/source/services/soc/soc_listen.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int listen(int sockfd, int max_connections) { @@ -13,10 +14,10 @@ int listen(int sockfd, int max_connections) return -1; } - cmdbuf[0] = 0x00030082; + cmdbuf[0] = IPC_MakeHeader(0x3,2,2); // 0x30082 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)max_connections; - cmdbuf[3] = 0x20; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_poll.c b/libctru/source/services/soc/soc_poll.c index 324612c..2d6f3bc 100644 --- a/libctru/source/services/soc/soc_poll.c +++ b/libctru/source/services/soc/soc_poll.c @@ -3,6 +3,7 @@ #include #include #include +#include <3ds/ipc.h> int poll(struct pollfd *fds, nfds_t nfds, int timeout) { @@ -35,18 +36,19 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) tmp_fds[i].revents = 0; } - cmdbuf[0] = 0x00140084; + cmdbuf[0] = IPC_MakeHeader(0x14,2,4); // 0x140084 cmdbuf[1] = (u32)nfds; cmdbuf[2] = (u32)timeout; - cmdbuf[3] = 0x20; - cmdbuf[5] = (size<<14) | 0x2802; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); + cmdbuf[5] = IPC_Desc_StaticBuffer(size,10); cmdbuf[6] = (u32)tmp_fds; - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (size<<14) | 2; - cmdbuf[0x104>>2] = (u32)tmp_fds; + staticbufs[0] = IPC_Desc_StaticBuffer(size,0); + staticbufs[1] = (u32)tmp_fds; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -55,8 +57,8 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) return ret; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_recvfrom.c b/libctru/source/services/soc/soc_recvfrom.c index f9b206a..03365f4 100644 --- a/libctru/source/services/soc/soc_recvfrom.c +++ b/libctru/source/services/soc/soc_recvfrom.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> ssize_t socuipc_cmd7(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) { @@ -15,20 +16,21 @@ ssize_t socuipc_cmd7(int sockfd, void *buf, size_t len, int flags, struct sockad if(src_addr) tmp_addrlen = 0x1c; - cmdbuf[0] = 0x00070104; + cmdbuf[0] = IPC_MakeHeader(0x7,4,4); // 0x70104 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)len; cmdbuf[3] = (u32)flags; cmdbuf[4] = (u32)tmp_addrlen; - cmdbuf[5] = 0x20; - cmdbuf[7] = (((u32)len)<<4) | 12; + cmdbuf[5] = IPC_Desc_CurProcessHandle(); + cmdbuf[7] = IPC_Desc_Buffer(len,IPC_BUFFER_W); cmdbuf[8] = (u32)buf; - saved_threadstorage[0] = cmdbuf[0x100>>2]; - saved_threadstorage[1] = cmdbuf[0x104>>2]; + u32 * staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0] = staticbufs[0]; + saved_threadstorage[1] = staticbufs[1]; - cmdbuf[0x100>>2] = (tmp_addrlen<<14) | 2; - cmdbuf[0x104>>2] = (u32)tmpaddr; + staticbufs[0] = IPC_Desc_StaticBuffer(tmp_addrlen,0); + staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { @@ -36,8 +38,8 @@ ssize_t socuipc_cmd7(int sockfd, void *buf, size_t len, int flags, struct sockad return -1; } - cmdbuf[0x100>>2] = saved_threadstorage[0]; - cmdbuf[0x104>>2] = saved_threadstorage[1]; + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; ret = (int)cmdbuf[1]; if(ret == 0) diff --git a/libctru/source/services/soc/soc_sendto.c b/libctru/source/services/soc/soc_sendto.c index 4b84749..5c0f3a5 100644 --- a/libctru/source/services/soc/soc_sendto.c +++ b/libctru/source/services/soc/soc_sendto.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> ssize_t socuipc_cmd9(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) { @@ -27,15 +28,15 @@ ssize_t socuipc_cmd9(int sockfd, const void *buf, size_t len, int flags, const s memcpy(&tmpaddr[2], &dest_addr->sa_data, tmp_addrlen-2); } - cmdbuf[0] = 0x00090106; + cmdbuf[0] = IPC_MakeHeader(0x9,4,6); // 0x90106 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)len; cmdbuf[3] = (u32)flags; cmdbuf[4] = (u32)tmp_addrlen; - cmdbuf[5] = 0x20; - cmdbuf[7] = (tmp_addrlen<<14) | 0x402; + cmdbuf[5] = IPC_Desc_CurProcessHandle(); + cmdbuf[7] = IPC_Desc_StaticBuffer(tmp_addrlen,1); cmdbuf[8] = (u32)tmpaddr; - cmdbuf[9] = (((u32)len)<<4) | 10; + cmdbuf[9] = IPC_Desc_Buffer(len,IPC_BUFFER_R); cmdbuf[10] = (u32)buf; ret = svcSendSyncRequest(SOCU_handle); @@ -81,15 +82,15 @@ ssize_t socuipc_cmda(int sockfd, const void *buf, size_t len, int flags, const s memcpy(&tmpaddr[2], &dest_addr->sa_data, tmp_addrlen-2); } - cmdbuf[0] = 0x000A0106; + cmdbuf[0] = IPC_MakeHeader(0xA,4,6); // 0xA0106 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)len; cmdbuf[3] = (u32)flags; cmdbuf[4] = (u32)tmp_addrlen; - cmdbuf[5] = 0x20; - cmdbuf[7] = (((u32)len)<<14) | 0x802; + cmdbuf[5] = IPC_Desc_CurProcessHandle(); + cmdbuf[7] = IPC_Desc_StaticBuffer(len,2); cmdbuf[8] = (u32)buf; - cmdbuf[9] = (tmp_addrlen<<14) | 0x402; + cmdbuf[9] = IPC_Desc_StaticBuffer(tmp_addrlen,1); cmdbuf[10] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); diff --git a/libctru/source/services/soc/soc_setsockopt.c b/libctru/source/services/soc/soc_setsockopt.c index 600d8cf..b2386d2 100644 --- a/libctru/source/services/soc/soc_setsockopt.c +++ b/libctru/source/services/soc/soc_setsockopt.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen) { @@ -13,13 +14,13 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t return -1; } - cmdbuf[0] = 0x00120104; + cmdbuf[0] = IPC_MakeHeader(0x12,4,4); // 0x120104 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)level; cmdbuf[3] = (u32)optname; cmdbuf[4] = (u32)optlen; - cmdbuf[5] = 0x20; - cmdbuf[7] = (optlen<<14) | 0x2402; + cmdbuf[5] = IPC_Desc_CurProcessHandle(); + cmdbuf[7] = IPC_Desc_StaticBuffer(optlen,9); cmdbuf[8] = (u32)optval; ret = svcSendSyncRequest(SOCU_handle); diff --git a/libctru/source/services/soc/soc_shutdown.c b/libctru/source/services/soc/soc_shutdown.c index 89b2db6..0af20a8 100644 --- a/libctru/source/services/soc/soc_shutdown.c +++ b/libctru/source/services/soc/soc_shutdown.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int shutdown(int sockfd, int shutdown_type) { @@ -13,10 +14,10 @@ int shutdown(int sockfd, int shutdown_type) return -1; } - cmdbuf[0] = 0x000C0082; + cmdbuf[0] = IPC_MakeHeader(0xC,2,2); // 0xC0082 cmdbuf[1] = (u32)sockfd; cmdbuf[2] = (u32)shutdown_type; - cmdbuf[3] = 0x20; + cmdbuf[3] = IPC_Desc_CurProcessHandle(); ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_sockatmark.c b/libctru/source/services/soc/soc_sockatmark.c index f774389..ea44543 100644 --- a/libctru/source/services/soc/soc_sockatmark.c +++ b/libctru/source/services/soc/soc_sockatmark.c @@ -1,6 +1,7 @@ #include "soc_common.h" #include #include +#include <3ds/ipc.h> int sockatmark(int sockfd) { @@ -13,9 +14,9 @@ int sockatmark(int sockfd) return -1; } - cmdbuf[0] = 0x00150042; + cmdbuf[0] = IPC_MakeHeader(0x15,1,2); // 0x150042 cmdbuf[1] = (u32)sockfd; - cmdbuf[2] = 0x20; + cmdbuf[2] = IPC_Desc_CurProcessHandle(); ret = svcSendSyncRequest(SOCU_handle); if(ret != 0) { diff --git a/libctru/source/services/soc/soc_socket.c b/libctru/source/services/soc/soc_socket.c index bf02700..53b7aa2 100644 --- a/libctru/source/services/soc/soc_socket.c +++ b/libctru/source/services/soc/soc_socket.c @@ -2,6 +2,7 @@ #include #include #include +#include <3ds/ipc.h> int socket(int domain, int type, int protocol) { @@ -10,11 +11,11 @@ int socket(int domain, int type, int protocol) __handle *handle; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = 0x000200C2; + cmdbuf[0] = IPC_MakeHeader(0x2,3,2); // 0x200C2 cmdbuf[1] = domain; cmdbuf[2] = type; cmdbuf[3] = protocol; - cmdbuf[4] = 0x20; + cmdbuf[4] = IPC_Desc_CurProcessHandle(); dev = FindDevice("soc:"); if(dev < 0) {