From 0052b8cbb02949fee36c3aa03211d39665226de0 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Tue, 12 Dec 2017 00:40:06 -0600 Subject: [PATCH] Use ac:i instead of config blocks for wifi info --- include/services/ac.h | 14 ++++--- include/wifi.h | 70 ------------------------------- source/main.c | 63 ++++++++++------------------ source/services/ac.c | 98 +++++++++++++++++++++++++++---------------- source/wifi.c | 25 ----------- 5 files changed, 94 insertions(+), 176 deletions(-) delete mode 100644 include/wifi.h delete mode 100644 source/wifi.c diff --git a/include/services/ac.h b/include/services/ac.h index 3fecbc7..19e58f5 100644 --- a/include/services/ac.h +++ b/include/services/ac.h @@ -3,10 +3,12 @@ #include <3ds.h> -Result acGetServiceHandle(void); -Result acCloseServiceHandle(void); -Result ACU_GetConnectingSecurityMode(u32 * out); -Result ACU_GetConnectingSsid(u32 * out); -Result ACU_GetConnectingSsidLength(u32 * out); +Result aciInit(void); +Result aciExit(void); +Result ACI_LoadWiFiSlot(u8 slot); +Result ACI_GetSSID(char * ssid); +Result ACI_GetPassphrase(char * passphrase); +Result ACI_GetSSIDLength(u8 * length); +Result ACI_GetSecurityMode(u8 * securityMode); -#endif \ No newline at end of file +#endif diff --git a/include/wifi.h b/include/wifi.h deleted file mode 100644 index 468ae94..0000000 --- a/include/wifi.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef WIFI_H -#define WIFI_H - -#include <3ds.h> - -/* - Wifi Slot Structure constructed using the info provided here https://www.3dbrew.org/wiki/Config_Savegame#WiFi_Slot_Structure -*/ - -#define CFG_WIFI_BLKID (u32) 0x00080000 // Configuration blocks BlkID for WiFi configuration slots -#define CFG_WIFI_SLOT_SIZE (u32) 0xC00 // Blk size 0xC - -typedef struct -{ - bool set; // Was the network was set or not? - bool use; // Use this network strucutre to connect? - bool isFirst; // If this structure is the first (0) or the second (1) in the larger WiFi slot structure? - u8 padding1; - - char SSID[0x20]; // SSID of the network, without a trailing nullbyte. - u8 SSID_length; // Length of the SSID. - u8 AP_crypto_key_type; - u16 padding2; - - char passphrase[0x40]; // Plaintext of the passphrase of the network, without a trailing nullbyte. - u8 PBKDF2_passphrase[0x20]; // PBKDF2 of the passphrase and SSID (http://jorisvr.nl/wpapsk.html). -} networkStructure; // This is apparently used twice in the actual wifi slot structure (?) // 0xAC - -typedef struct -{ - bool set; // Was the network was set or not? - u16 checksum; // CRC-16 checksum of the next 0x410 bytes. - - networkStructure network; // First network structure. Only set if the network was set "normally", or was the last to be set using WPS during the session. Size 0x88 - u8 padding1[0x20]; - - networkStructure network_WPS; // Second network structure. Only set if the network was set using WPS, otherwise 0-filled. - u8 padding2[0x20C]; - - bool auto_obtain_ip_addr; // Automatically get the IP address (use DHCP) or not, defaults to 1. - bool auto_obtain_DNS; // Automatically get the DNS or not, defaults to 1 - u16 padding3; - - u8 ip_addr[0x4]; // IP address, to use if (auto_obtain_ip_addr) is false. - u8 gateway_addr[0x4]; // IP address of the gateway, to use if (auto_obtain_ip_addr) is false. - u8 subnet_mask[0x4]; // Subnetwork mask, to use if (auto_obtain_ip_addr) is false. - u8 primary_DNS[0x4]; // IP address of the primary DNS , to use if (auto_obtain_ip_addr) is false. - u8 secondary_DNS[0x4]; // IP address of the secondary DNS, to use if (auto_obtain_ip_addr) is false. - - u8 lastSet[0x4]; // Always 0x01050000 ? Only set if the network was the last to be set during the session. - u8 ip_to_use[0x4]; // IP address to use. Only set if the network was the last to be set during the session. - u8 mac_addr[0x6]; // MAC address of the AP. Only set if the network was the last to be set during the session. - u8 channel; // Channel. Only set if the network was the last to be set during the session. - u8 padding4; // Only set if the network was the last to be set during the session. - - bool use_proxy; // Use a proxy or not, defaults to 0. - bool basic_authentication; // Use a basic authentication for the proxy, defaults to 0. - u16 port_number; // Port to use for the proxy, defaults to 1. - char proxy_addr[0x30]; // URL/address of the proxy, including a trailing nullbyte. - u8 padding5[0x34]; - char proxy_username[0x20]; // Username to use for basic authentication, including a trailing nullbyte. - char proxy_password[0x20]; // Password to use for basic authentication, including a trailing nullbyte. - u16 padding6; - u16 MTU_value; // MTU value, defaults to 1400 and ranges between 576 and 1500, inclusive. - u8 padding8[0x7EC]; -} wifiSlotStructure; - -char * getSecurityMode(); - -#endif \ No newline at end of file diff --git a/source/main.c b/source/main.c index d901fb0..bc79c99 100644 --- a/source/main.c +++ b/source/main.c @@ -15,7 +15,6 @@ #include "storage.h" #include "system.h" #include "utils.h" -#include "wifi.h" #define SDK(a, b, c, d) ((a<<24) | (b<<16) | (c<<8) | d) @@ -30,7 +29,7 @@ void initServices() amAppInit(); aptInit(); hidInit(); - acGetServiceHandle(); + aciInit(); actInit(); socInit((u32*)memalign(0x1000, 0x10000), 0x10000); @@ -56,7 +55,7 @@ void termServices() hidExit(); aptExit(); acExit(); - acCloseServiceHandle(); + aciExit(); amExit(); mcuExit(); ptmuExit(); @@ -80,7 +79,6 @@ int main(int argc, char *argv[]) u8 batteryPercent = 0, batteryVolt = 0, volume = 0, mcuFwMajor = 0, mcuFwMinor = 0; bool isConnected = false; char sdFreeSize[16], sdTotalSize[16], ctrFreeSize[16], ctrTotalSize[16], country[0x3], name[0x16], nnid[0x11], timeZone[0x41]; - wifiSlotStructure slotData; AccountDataBlock accountDataBlock; MiiData miiData; @@ -129,52 +127,37 @@ int main(int argc, char *argv[]) //------------------------------WIFI Info------------------------------// //=====================================================================// - if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 0, (u8*)&slotData))) && (slotData.set)) + if (R_SUCCEEDED(ACI_LoadWiFiSlot(0))) { - if (slotData.network.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 1 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 1 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network.passphrase); - } - else if (slotData.network_WPS.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 1 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 1 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.passphrase); - } + char ssid[0x20], passphrase[0x40]; - printf("\x1b[32;1m*\x1b[0m WiFi 1 mac address: \x1b[32;1m%02X:%02X:%02X:%02X:%02X:%02X\x1b[0m\n\n", slotData.mac_addr[0], slotData.mac_addr[1], slotData.mac_addr[2], slotData.mac_addr[3], slotData.mac_addr[4], slotData.mac_addr[5]); + if (R_SUCCEEDED(ACI_GetSSID(ssid))) + printf("\x1b[32;1m*\x1b[0m WiFi 1 SSID: \x1b[32;1m%s\x1b[0m\n", ssid); + + if (R_SUCCEEDED(ACI_GetPassphrase(passphrase))) + printf("\x1b[32;1m*\x1b[0m WiFi 1 pass: \x1b[32;1m%s\x1b[0m\n\n", passphrase); } - if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 1, (u8*)&slotData))) && (slotData.set)) + if (R_SUCCEEDED(ACI_LoadWiFiSlot(1))) { - if (slotData.network.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 2 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 2 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network.passphrase); - } - else if (slotData.network_WPS.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 2 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 2 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.passphrase); - } + char ssid[0x20], passphrase[0x40]; - printf("\x1b[32;1m*\x1b[0m WiFi 2 mac address: \x1b[32;1m%02X:%02X:%02X:%02X:%02X:%02X\x1b[0m\n\n", slotData.mac_addr[0], slotData.mac_addr[1], slotData.mac_addr[2], slotData.mac_addr[3], slotData.mac_addr[4], slotData.mac_addr[5]); + if (R_SUCCEEDED(ACI_GetSSID(ssid))) + printf("\x1b[32;1m*\x1b[0m WiFi 2 SSID: \x1b[32;1m%s\x1b[0m\n", ssid); + + if (R_SUCCEEDED(ACI_GetPassphrase(passphrase))) + printf("\x1b[32;1m*\x1b[0m WiFi 2 pass: \x1b[32;1m%s\x1b[0m\n\n", passphrase); } - if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 2, (u8*)&slotData))) && (slotData.set)) + if (R_SUCCEEDED(ACI_LoadWiFiSlot(2))) { - if (slotData.network.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 3 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 3 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network.passphrase); - } - else if (slotData.network_WPS.use) - { - printf("\x1b[32;1m*\x1b[0m WiFi 3 SSID: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.SSID); - printf("\x1b[32;1m*\x1b[0m WiFi 3 pass: \x1b[32;1m%s\x1b[0m\n", slotData.network_WPS.passphrase); - } + char ssid[0x20], passphrase[0x40]; - printf("\x1b[32;1m*\x1b[0m WiFi 3 mac address: \x1b[32;1m%02X:%02X:%02X:%02X:%02X:%02X\x1b[0m\n\n", slotData.mac_addr[0], slotData.mac_addr[1], slotData.mac_addr[2], slotData.mac_addr[3], slotData.mac_addr[4], slotData.mac_addr[5]); + if (R_SUCCEEDED(ACI_GetSSID(ssid))) + printf("\x1b[32;1m*\x1b[0m WiFi 3 SSID: \x1b[32;1m%s\x1b[0m\n", ssid); + + if (R_SUCCEEDED(ACI_GetPassphrase(passphrase))) + printf("\x1b[32;1m*\x1b[0m WiFi 3 pass: \x1b[32;1m%s\x1b[0m\n\n", passphrase); } printf("\x1b[32;1m> Press any key to exit =)\x1b[0m"); diff --git a/source/services/ac.c b/source/services/ac.c index f9f328b..fe6a336 100644 --- a/source/services/ac.c +++ b/source/services/ac.c @@ -2,57 +2,85 @@ static Handle acHandle; -Result acGetServiceHandle(void) +Result aciInit(void) { - return srvGetServiceHandle(&acHandle, "ac:u"); + return srvGetServiceHandle(&acHandle, "ac:i"); } -Result acCloseServiceHandle(void) +Result aciExit(void) { return svcCloseHandle(acHandle); } -Result ACU_GetConnectingSecurityMode(u32 * out) +Result ACI_LoadWiFiSlot(u8 slot) { + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = 0x04010040; + cmdbuf[1] = (u32)slot; + Result ret = 0; - u32 * cmdbuf = getThreadCommandBuffer(); - - cmdbuf[0] = IPC_MakeHeader(0x33, 0, 0); // 0x00330000 - - if (R_FAILED(ret = svcSendSyncRequest(acHandle))) - return ret; - - *out = cmdbuf[2]; - - return cmdbuf[1]; + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + ret = cmdbuf[1]; + return ret; } -Result ACU_GetConnectingSsid(u32 * out) +Result ACI_GetSSID(char * ssid) { + u32* cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = 0x040F0000; + + u32* staticbufs = getThreadStaticBuffers(); + + staticbufs[0] = IPC_Desc_StaticBuffer(0x20, 0); //SSID length is 0x20 + staticbufs[1] = (u32)ssid; + Result ret = 0; - u32 * cmdbuf = getThreadCommandBuffer(); - - cmdbuf[0] = IPC_MakeHeader(0x34, 0, 0); // 0x00340000 - - if (R_FAILED(ret = svcSendSyncRequest(acHandle))) - return ret; - - *out = cmdbuf[2]; - - return cmdbuf[1]; + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + ret = cmdbuf[1]; + return ret; } -Result ACU_GetConnectingSsidLength(u32 * out) +Result ACI_GetPassphrase(char * passphrase) { + u32* cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = 0x04150000; + + u32* staticbufs = getThreadStaticBuffers(); + + staticbufs[0] = IPC_Desc_StaticBuffer(0x40, 0); //passphrase length is 0x40 + staticbufs[1] = (u32)passphrase; + Result ret = 0; - u32 * cmdbuf = getThreadCommandBuffer(); + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + ret = cmdbuf[1]; + return ret; +} - cmdbuf[0] = IPC_MakeHeader(0x35, 0, 0); // 0x00350000 +Result ACI_GetSSIDLength(u8 * length) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = 0x04110000; + + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + ret = cmdbuf[1]; + *length = (u8)cmdbuf[2]; + return ret; +} - if (R_FAILED(ret = svcSendSyncRequest(acHandle))) - return ret; - - *out = cmdbuf[2]; - - return cmdbuf[1]; -} \ No newline at end of file +Result ACI_GetSecurityMode(u8 * securityMode) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = 0x04130000; + + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + ret = cmdbuf[1]; + *securityMode = (u8)cmdbuf[2]; + return ret; +} diff --git a/source/wifi.c b/source/wifi.c deleted file mode 100644 index d780780..0000000 --- a/source/wifi.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "ac.h" -#include "wifi.h" - -char * getSecurityMode() -{ - u32 securityMode = 0; - - if (R_FAILED(ACU_GetConnectingSecurityMode(&securityMode))) - securityMode = 8; - - static char * securityString[] = - { - "Open authentication", - "WEP 40-bit", - "WEP 104-bit", - "WEP 128-bit", - "WPA TKIP", - "WPA2 TKIP", - "WPA AES", - "WPA2 AES", - "Unknown" - }; - - return securityString[securityMode]; -} \ No newline at end of file