From 8be21732f268416e2b4744bea2272a38dd96c992 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Sat, 13 Jan 2018 11:33:37 -0600 Subject: [PATCH 1/5] Add ACU_GetLastErrorCode && ACU_GetLastDetailErrorCode --- libctru/include/3ds/services/ac.h | 12 ++++++++++++ libctru/source/services/ac.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index 7e2f573..290cfaa 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -36,3 +36,15 @@ Result ACU_GetSecurityMode(u32 *out); * @param out Pointer to output the current Wifi SSID length to. */ Result ACU_GetSSIDLength(u32 *out); + +/** + * @brief Gets the last error to occur during a connection. + * @param errorCode Pointer to output the error code to. + */ +Result ACU_GetLastErrorCode(u32* errorCode); + +/** + * @brief Gets the last detailed error to occur during a connection. + * @param errorCode Pointer to output the error code to. + */ +Result ACU_GetLastDetailErrorCode(u32* errorCode); diff --git a/libctru/source/services/ac.c b/libctru/source/services/ac.c index 38d71cc..7cb63c6 100644 --- a/libctru/source/services/ac.c +++ b/libctru/source/services/ac.c @@ -92,3 +92,31 @@ Result ACU_GetSSIDLength(u32 *out) return (Result)cmdbuf[1]; } + +Result ACU_GetLastErrorCode(u32* errorCode) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xA,0,0); // 0xA0000 + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + if(errorCode) *errorCode = cmdbuf[2]; + + return (Result)cmdbuf[1]; +} + +Result ACU_GetLastDetailErrorCode(u32* errorCode) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xB,0,0); // 0xB0000 + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + if(errorCode) *errorCode = cmdbuf[2]; + + return (Result)cmdbuf[1]; +} From 1b93b23feea51d07c877e123c75f8fe724b95583 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Mon, 19 Feb 2018 17:10:45 -0600 Subject: [PATCH 2/5] Add ACU_Proxy functions and minor changes - More descriptive/accurate docs - Use enum for security mode. --- libctru/include/3ds/services/ac.h | 62 ++++++++++++++++++---- libctru/source/services/ac.c | 88 ++++++++++++++++++++++++++++--- 2 files changed, 134 insertions(+), 16 deletions(-) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index 290cfaa..5013764 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -4,6 +4,18 @@ */ #pragma once +/// WiFi security modes. +typedef enum { + AC_OPEN = 0, ///< Open authentication. + AC_WEP_40BIT = 1, ///< WEP 40-bit authentication. + AC_WEP_104BIT = 2, ///< WEP 104-bit authentication. + AC_WEP_128BIT = 3, ///< WEP 128-bit authentication. + AC_WPA_TKIP = 4, ///< WPA TKIP authentication. + AC_WPA2_TKIP = 5, ///< WPA2 TKIP authentication. + AC_WPA_AES = 6, ///< WPA AES authentication. + AC_WPA2_AES = 7, ///< WPA2 AES authentication. +} acSecurityMode; + /// Initializes AC. Result acInit(void); @@ -14,29 +26,59 @@ void acExit(void); Result acWaitInternetConnection(void); /** - * @brief Gets the current Wifi status. - * @param out Pointer to output the current Wifi status to. (0 = not connected, 1 = O3DS Internet, 2 = N3DS Internet) + * @brief Gets the connected WiFi status. + * @param out Pointer to output the connected WiFi status to. (0 = not connected, 1 = O3DS Internet, 2 = N3DS Internet) */ -Result ACU_GetWifiStatus(u32 *out); +Result ACU_GetWiFiStatus(u32 *out); /** - * @brief Gets the current Wifi status. - * @param out Pointer to output the current Wifi status to. (1 = not connected, 3 = connected) + * @brief Gets the connected WiFi status. + * @param out Pointer to output the connected WiFi status to. (1 = not connected, 3 = connected) */ Result ACU_GetStatus(u32 *out); /** - * @brief Gets the current Wifi security mode. - * @param out Pointer to output the current Wifi security mode to. (0 = Open Authentication, 1 = WEP 40-bit, 2 = WEP 104-bit, 3 = WEP 128-bit, 4 = WPA TKIP, 5 = WPA2 TKIP, 6 = WPA AES, 7 = WPA2 AES) + * @brief Gets the connected WiFi security mode. + * @param mode Pointer to output the connected WiFi security mode to. (0 = Open Authentication, 1 = WEP 40-bit, 2 = WEP 104-bit, 3 = WEP 128-bit, 4 = WPA TKIP, 5 = WPA2 TKIP, 6 = WPA AES, 7 = WPA2 AES) */ -Result ACU_GetSecurityMode(u32 *out); +Result ACI_GetSecurityMode(acSecurityMode *mode); /** - * @brief Gets the current Wifi SSID length. - * @param out Pointer to output the current Wifi SSID length to. + * @brief Gets the connected WiFi SSID. + * @param SSID Pointer to output the connected WiFi SSID to. + */ +Result ACU_GetSSID(char *SSID); + +/** + * @brief Gets the connected WiFi SSID length. + * @param out Pointer to output the connected WiFi SSID length to. */ Result ACU_GetSSIDLength(u32 *out); +/** + * @brief Determines whether proxy is enabled for the connected network. + * @param enable Pointer to output the proxy status to. + */ +Result ACU_GetProxyEnable(bool *enable); + +/** + * @brief Gets the connected network's proxy port. + * @param out Pointer to output the proxy port to. + */ +Result ACU_GetProxyPort(u32 *out); + +/** + * @brief Gets the connected network's proxy username. + * @param username Pointer to output the proxy username to. + */ +Result ACU_GetProxyUserName(char *username); + +/** + * @brief Gets the connected network's proxy password. + * @param password Pointer to output the proxy password to. + */ +Result ACU_GetProxyPassword(char *password); + /** * @brief Gets the last error to occur during a connection. * @param errorCode Pointer to output the error code to. diff --git a/libctru/source/services/ac.c b/libctru/source/services/ac.c index 7cb63c6..a563997 100644 --- a/libctru/source/services/ac.c +++ b/libctru/source/services/ac.c @@ -42,7 +42,7 @@ Result ACU_GetWifiStatus(u32 *out) Result ret=0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0xD,0,0); // 0x000D0000 + cmdbuf[0] = IPC_MakeHeader(0xD,0,0); // 0xD0000 if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; @@ -56,7 +56,7 @@ Result ACU_GetStatus(u32 *out) Result ret=0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0x000C0000 + cmdbuf[0] = IPC_MakeHeader(0xC,0,0); // 0xC0000 if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; @@ -65,16 +65,32 @@ Result ACU_GetStatus(u32 *out) return (Result)cmdbuf[1]; } -Result ACU_GetSecurityMode(u32 *out) +Result ACI_GetSecurityMode(acSecurityMode *mode) { Result ret=0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0x33,0,0); // 0x00330000 + cmdbuf[0] = IPC_MakeHeader(0x33,0,0); // 0x330000 if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; - *out = cmdbuf[2]; + *mode = cmdbuf[2]; + + return (Result)cmdbuf[1]; +} + +Result ACU_GetSSID(char *SSID) +{ + Result ret=0; + u32 *cmdbuf = getThreadCommandBuffer(); + u32 *staticbufs = getThreadStaticBuffers(); + + cmdbuf[0] = IPC_MakeHeader(0x34,0,0); // 0x340000 + + staticbufs[0] = IPC_Desc_StaticBuffer(0x20, 0); + staticbufs[1] = (u32)SSID; + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; return (Result)cmdbuf[1]; } @@ -84,7 +100,7 @@ Result ACU_GetSSIDLength(u32 *out) Result ret=0; u32 *cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0x35,0,0); // 0x00350000 + cmdbuf[0] = IPC_MakeHeader(0x35,0,0); // 0x350000 if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; @@ -93,6 +109,66 @@ Result ACU_GetSSIDLength(u32 *out) return (Result)cmdbuf[1]; } +Result ACU_GetProxyEnable(bool *enable) +{ + Result ret=0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x36,0,0); // 0x360000 + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + *enable = cmdbuf[2] & 0xFF; + + return (Result)cmdbuf[1]; +} + +Result ACU_GetProxyPort(u32 *out) +{ + Result ret=0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x38,0,0); // 0x380000 + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + *out = cmdbuf[2]; + + return (Result)cmdbuf[1]; +} + +Result ACU_GetProxyUserName(char *username) +{ + Result ret=0; + u32 *cmdbuf = getThreadCommandBuffer(); + u32 *staticbufs = getThreadStaticBuffers(); + + cmdbuf[0] = IPC_MakeHeader(0x3A,0,0); // 0x3A0000 + + staticbufs[0] = IPC_Desc_StaticBuffer(0x20, 0); + staticbufs[1] = (u32)username; + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + return (Result)cmdbuf[1]; +} + +Result ACU_GetProxyPassword(char *password) +{ + Result ret=0; + u32 *cmdbuf = getThreadCommandBuffer(); + u32 *staticbufs = getThreadStaticBuffers(); + + cmdbuf[0] = IPC_MakeHeader(0x3B,0,0); // 0x3B0000 + + staticbufs[0] = IPC_Desc_StaticBuffer(0x20, 0); + staticbufs[1] = (u32)password; + + if(R_FAILED(ret = svcSendSyncRequest(acHandle)))return ret; + + return (Result)cmdbuf[1]; +} + Result ACU_GetLastErrorCode(u32* errorCode) { Result ret = 0; From 82019d2d78095e82ed31ca5f9fe16c84b4750351 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Mon, 19 Feb 2018 17:12:55 -0600 Subject: [PATCH 3/5] Revert function re-naming to avoid breaking programs --- libctru/include/3ds/services/ac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index 5013764..2816003 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -29,7 +29,7 @@ Result acWaitInternetConnection(void); * @brief Gets the connected WiFi status. * @param out Pointer to output the connected WiFi status to. (0 = not connected, 1 = O3DS Internet, 2 = N3DS Internet) */ -Result ACU_GetWiFiStatus(u32 *out); +Result ACU_GetWifiStatus(u32 *out); /** * @brief Gets the connected WiFi status. From fde27bce687d505d99b461d21572154013513a19 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Mon, 19 Feb 2018 17:31:31 -0600 Subject: [PATCH 4/5] Should be ACU_* --- libctru/include/3ds/services/ac.h | 2 +- libctru/source/services/ac.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index 2816003..0397e92 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -41,7 +41,7 @@ Result ACU_GetStatus(u32 *out); * @brief Gets the connected WiFi security mode. * @param mode Pointer to output the connected WiFi security mode to. (0 = Open Authentication, 1 = WEP 40-bit, 2 = WEP 104-bit, 3 = WEP 128-bit, 4 = WPA TKIP, 5 = WPA2 TKIP, 6 = WPA AES, 7 = WPA2 AES) */ -Result ACI_GetSecurityMode(acSecurityMode *mode); +Result ACU_GetSecurityMode(acSecurityMode *mode); /** * @brief Gets the connected WiFi SSID. diff --git a/libctru/source/services/ac.c b/libctru/source/services/ac.c index a563997..9267ad1 100644 --- a/libctru/source/services/ac.c +++ b/libctru/source/services/ac.c @@ -65,7 +65,7 @@ Result ACU_GetStatus(u32 *out) return (Result)cmdbuf[1]; } -Result ACI_GetSecurityMode(acSecurityMode *mode) +Result ACU_GetSecurityMode(acSecurityMode *mode) { Result ret=0; u32 *cmdbuf = getThreadCommandBuffer(); From bd1065fcf874c5c7eb5905f45f9e2943f67aee26 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Fri, 2 Mar 2018 15:02:57 -0600 Subject: [PATCH 5/5] Rename WiFi to Wifi --- libctru/include/3ds/services/ac.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index 0397e92..55b2310 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -4,7 +4,7 @@ */ #pragma once -/// WiFi security modes. +/// Wifi security modes. typedef enum { AC_OPEN = 0, ///< Open authentication. AC_WEP_40BIT = 1, ///< WEP 40-bit authentication. @@ -26,32 +26,32 @@ void acExit(void); Result acWaitInternetConnection(void); /** - * @brief Gets the connected WiFi status. - * @param out Pointer to output the connected WiFi status to. (0 = not connected, 1 = O3DS Internet, 2 = N3DS Internet) + * @brief Gets the connected Wifi status. + * @param out Pointer to output the connected Wifi status to. (0 = not connected, 1 = O3DS Internet, 2 = N3DS Internet) */ Result ACU_GetWifiStatus(u32 *out); /** - * @brief Gets the connected WiFi status. - * @param out Pointer to output the connected WiFi status to. (1 = not connected, 3 = connected) + * @brief Gets the connected Wifi status. + * @param out Pointer to output the connected Wifi status to. (1 = not connected, 3 = connected) */ Result ACU_GetStatus(u32 *out); /** - * @brief Gets the connected WiFi security mode. - * @param mode Pointer to output the connected WiFi security mode to. (0 = Open Authentication, 1 = WEP 40-bit, 2 = WEP 104-bit, 3 = WEP 128-bit, 4 = WPA TKIP, 5 = WPA2 TKIP, 6 = WPA AES, 7 = WPA2 AES) + * @brief Gets the connected Wifi security mode. + * @param mode Pointer to output the connected Wifi security mode to. (0 = Open Authentication, 1 = WEP 40-bit, 2 = WEP 104-bit, 3 = WEP 128-bit, 4 = WPA TKIP, 5 = WPA2 TKIP, 6 = WPA AES, 7 = WPA2 AES) */ Result ACU_GetSecurityMode(acSecurityMode *mode); /** - * @brief Gets the connected WiFi SSID. - * @param SSID Pointer to output the connected WiFi SSID to. + * @brief Gets the connected Wifi SSID. + * @param SSID Pointer to output the connected Wifi SSID to. */ Result ACU_GetSSID(char *SSID); /** - * @brief Gets the connected WiFi SSID length. - * @param out Pointer to output the connected WiFi SSID length to. + * @brief Gets the connected Wifi SSID length. + * @param out Pointer to output the connected Wifi SSID length to. */ Result ACU_GetSSIDLength(u32 *out);