From 033b353128b88b39b9bff94671b3ad8553b151bb Mon Sep 17 00:00:00 2001 From: megazig Date: Tue, 18 Aug 2015 16:54:22 -0500 Subject: [PATCH 1/3] add key type 9 (NFC) for ps service --- libctru/include/3ds/services/ps.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libctru/include/3ds/services/ps.h b/libctru/include/3ds/services/ps.h index 29c9d95..52b7d65 100644 --- a/libctru/include/3ds/services/ps.h +++ b/libctru/include/3ds/services/ps.h @@ -17,10 +17,11 @@ typedef enum ps_KEYSLOT_31, ps_KEYSLOT_38, ps_KEYSLOT_32, - ps_KEYSLOT_39, + ps_KEYSLOT_39_DLP, ps_KEYSLOT_2E, ps_KEYSLOT_INVALID, - ps_KEYSLOT_36 + ps_KEYSLOT_36, + ps_KEYSLOT_39_NFC } ps_aes_keytypes; /* @@ -73,4 +74,4 @@ About: Gets a 32bit device id, it's used for some key slot inits device_id ptr to where the device id is written to */ -Result PS_GetDeviceId(u32* device_id); \ No newline at end of file +Result PS_GetDeviceId(u32* device_id); From 8e7606692ddcf690eb4e46b846063c35f57243ef Mon Sep 17 00:00:00 2001 From: megazig Date: Tue, 18 Aug 2015 16:55:50 -0500 Subject: [PATCH 2/3] move h_errno definition to soc_common add h_addr member to hostent structure implement gethostbyaddr --- libctru/include/netdb.h | 2 + libctru/source/services/soc/soc_common.c | 1 + .../source/services/soc/soc_gethostbyaddr.c | 72 +++++++++++++++++++ .../source/services/soc/soc_gethostbyname.c | 4 +- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 libctru/source/services/soc/soc_gethostbyaddr.c diff --git a/libctru/include/netdb.h b/libctru/include/netdb.h index b3fac81..dce8ffd 100644 --- a/libctru/include/netdb.h +++ b/libctru/include/netdb.h @@ -14,6 +14,7 @@ struct hostent { int h_addrtype; int h_length; char **h_addr_list; + char *h_addr; }; #ifdef __cplusplus @@ -22,6 +23,7 @@ extern "C" { extern int h_errno; struct hostent* gethostbyname(const char *name); + struct hostent* gethostbyaddr(const char *addr, socklen_t len, int type); void herror(const char *s); const char* hstrerror(int err); diff --git a/libctru/source/services/soc/soc_common.c b/libctru/source/services/soc/soc_common.c index a610919..d31d9b2 100644 --- a/libctru/source/services/soc/soc_common.c +++ b/libctru/source/services/soc/soc_common.c @@ -4,6 +4,7 @@ Handle SOCU_handle = 0; Handle socMemhandle = 0; +int h_errno = 0; //This is based on the array from libogc network_wii.c. static u8 _net_error_code_map[] = { diff --git a/libctru/source/services/soc/soc_gethostbyaddr.c b/libctru/source/services/soc/soc_gethostbyaddr.c new file mode 100644 index 0000000..d19e01b --- /dev/null +++ b/libctru/source/services/soc/soc_gethostbyaddr.c @@ -0,0 +1,72 @@ +#include "soc_common.h" +#include + +#define MAX_HOSTENT_RESULTS 16 +static struct hostent SOC_hostent; +static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1]; +static char *SOC_hostent_alias = NULL; + +struct hostent* gethostbyaddr(const char *addr, socklen_t len, int type) +{ + int ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + u32 saved_threadstorage[2]; + static u8 outbuf[0x1A88]; + + h_errno = 0; + + cmdbuf[0] = 0x000E00C2; + cmdbuf[1] = len; + cmdbuf[2] = type; + cmdbuf[3] = sizeof(outbuf); + cmdbuf[4] = (len << 14) | 0x1002; + cmdbuf[5] = (u32)addr; + + saved_threadstorage[0] = cmdbuf[0x100>>2]; + saved_threadstorage[1] = cmdbuf[0x104>>2]; + + cmdbuf[0x100>>2] = (sizeof(outbuf) << 14) | 2; + cmdbuf[0x104>>2] = (u32)outbuf; + + ret = svcSendSyncRequest(SOCU_handle); + if(ret != 0) { + h_errno = NO_RECOVERY; + return NULL; + } + + + cmdbuf[0x100>>2] = saved_threadstorage[0]; + cmdbuf[0x104>>2] = saved_threadstorage[1]; + + ret = (int)cmdbuf[1]; + if(ret == 0) + ret = _net_convert_error(cmdbuf[2]); + + if(ret < 0) { + /* TODO: set h_errno based on ret */ + h_errno = HOST_NOT_FOUND; + return NULL; + } + + u32 num_results, i; + memcpy(&num_results, (char*)outbuf+4, sizeof(num_results)); + if(num_results > MAX_HOSTENT_RESULTS) + num_results = MAX_HOSTENT_RESULTS; + + SOC_hostent.h_name = (char*)outbuf + 8; + SOC_hostent.h_aliases = &SOC_hostent_alias; + SOC_hostent.h_addrtype = AF_INET; + SOC_hostent.h_length = 4; + SOC_hostent.h_addr_list = SOC_hostent_results; + + SOC_hostent_alias = NULL; + + for(i = 0; i < num_results; ++i) + SOC_hostent_results[i] = (char*)outbuf + 0x1908 + i*0x10; + SOC_hostent_results[num_results] = NULL; + + SOC_hostent.h_addr = SOC_hostent.h_addr_list[0]; + + return &SOC_hostent; +} + diff --git a/libctru/source/services/soc/soc_gethostbyname.c b/libctru/source/services/soc/soc_gethostbyname.c index ed712db..2121c3b 100644 --- a/libctru/source/services/soc/soc_gethostbyname.c +++ b/libctru/source/services/soc/soc_gethostbyname.c @@ -6,8 +6,6 @@ static struct hostent SOC_hostent; static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1]; static char *SOC_hostent_alias = NULL; -int h_errno = 0; - struct hostent* gethostbyname(const char *name) { int ret = 0; @@ -66,5 +64,7 @@ struct hostent* gethostbyname(const char *name) SOC_hostent_results[i] = (char*)outbuf + 0x1908 + i*0x10; SOC_hostent_results[num_results] = NULL; + SOC_hostent.h_addr = SOC_hostent.h_addr_list[0]; + return &SOC_hostent; } From 9e597a7af998ebd075c55ce47114fc2d2189b264 Mon Sep 17 00:00:00 2001 From: megazig Date: Tue, 18 Aug 2015 17:15:21 -0500 Subject: [PATCH 3/3] update definition of gethostbyaddr --- libctru/include/netdb.h | 2 +- libctru/source/services/soc/soc_gethostbyaddr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libctru/include/netdb.h b/libctru/include/netdb.h index dce8ffd..4e42861 100644 --- a/libctru/include/netdb.h +++ b/libctru/include/netdb.h @@ -23,7 +23,7 @@ extern "C" { extern int h_errno; struct hostent* gethostbyname(const char *name); - struct hostent* gethostbyaddr(const char *addr, socklen_t len, int type); + struct hostent* gethostbyaddr(const void *addr, socklen_t len, int type); void herror(const char *s); const char* hstrerror(int err); diff --git a/libctru/source/services/soc/soc_gethostbyaddr.c b/libctru/source/services/soc/soc_gethostbyaddr.c index d19e01b..7e1a117 100644 --- a/libctru/source/services/soc/soc_gethostbyaddr.c +++ b/libctru/source/services/soc/soc_gethostbyaddr.c @@ -6,7 +6,7 @@ static struct hostent SOC_hostent; static char *SOC_hostent_results[MAX_HOSTENT_RESULTS+1]; static char *SOC_hostent_alias = NULL; -struct hostent* gethostbyaddr(const char *addr, socklen_t len, int type) +struct hostent* gethostbyaddr(const void *addr, socklen_t len, int type) { int ret = 0; u32 *cmdbuf = getThreadCommandBuffer();