From eda5774408758ce1ee3b9e3360cb75effd279f0c Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Mon, 27 Jul 2020 09:51:53 +0700 Subject: [PATCH] Added more stub for some unimplemented sceNetApctl* functions --- Core/HLE/sceNet.cpp | 425 ++++++++++++++++++++++++++++++++++++++++++-- Core/HLE/sceNet.h | 98 +++++++++- 2 files changed, 511 insertions(+), 12 deletions(-) diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 0df11e5c63..8851347ec4 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -48,6 +48,7 @@ static bool netInited; bool netInetInited; bool netApctlInited; +int netApctlStatus; u32 netDropRate = 0; u32 netDropDuration = 0; u32 netPoolAddr = 0; @@ -58,6 +59,8 @@ static struct SceNetMallocStat netMallocStat; static std::map apctlHandlers; +static struct SceNetApctlInfoInternal netApctlInfo; + static int InitLocalhostIP() { // find local IP addrinfo* localAddr; @@ -152,6 +155,7 @@ static void __UpdateApctlHandlers(int oldState, int newState, int flag, int erro for(std::map::iterator it = apctlHandlers.begin(); it != apctlHandlers.end(); ++it) { args[4] = it->second.argument; + // TODO: Need to make sure netApctlState is updated before calling the callback's mipscall so the game handler's subroutine can Get and make use the new state/info hleEnqueueCall(it->second.entryPoint, 5, args); } } @@ -195,6 +199,101 @@ void __NetDoState(PointerWrap &p) { } } +template std::string num2hex(I w, size_t hex_len) { + static const char* digits = "0123456789ABCDEF"; + std::string rc(hex_len, '0'); + for (size_t i = 0, j = (hex_len - 1) * 4; i < hex_len; ++i, j -= 4) + rc[i] = digits[(w >> j) & 0x0f]; + return rc; +} + +std::string error2str(u32 errorCode) { + std::string str = ""; + if (((errorCode >> 31) & 1) != 0) + str += "ERROR "; + if (((errorCode >> 30) & 1) != 0) + str += "CRITICAL "; + switch ((errorCode >> 16) & 0xfff) { + case 0x41: + str += "NET "; + break; + default: + str += "UNK"+num2hex(u16((errorCode >> 16) & 0xfff), 3)+" "; + } + switch ((errorCode >> 8) & 0xff) { + case 0x00: + str += "COMMON "; + break; + case 0x01: + str += "CORE "; + break; + case 0x02: + str += "INET "; + break; + case 0x03: + str += "POECLIENT "; + break; + case 0x04: + str += "RESOLVER "; + break; + case 0x05: + str += "DHCP "; + break; + case 0x06: + str += "ADHOC_AUTH "; + break; + case 0x07: + str += "ADHOC "; + break; + case 0x08: + str += "ADHOC_MATCHING "; + break; + case 0x09: + str += "NETCNF "; + break; + case 0x0a: + str += "APCTL "; + break; + case 0x0b: + str += "ADHOCCTL "; + break; + case 0x0c: + str += "UNKNOWN1 "; + break; + case 0x0d: + str += "WLAN "; + break; + case 0x0e: + str += "EAPOL "; + break; + case 0x0f: + str += "8021x "; + break; + case 0x10: + str += "WPA "; + break; + case 0x11: + str += "UNKNOWN2 "; + break; + case 0x12: + str += "TRANSFER "; + break; + case 0x13: + str += "ADHOC_DISCOVER "; + break; + case 0x14: + str += "ADHOC_DIALOG "; + break; + case 0x15: + str += "WISPR "; + break; + default: + str += "UNKNOWN"+num2hex(u8((errorCode >> 8) & 0xff))+" "; + } + str += num2hex(u8(errorCode & 0xff)); + return str; +} + static inline u32 AllocUser(u32 size, bool fromTop, const char *name) { u32 addr = userMemory.Alloc(size, fromTop, name); if (addr == -1) @@ -449,11 +548,38 @@ int sceNetInetTerm() { return 0; } -static int sceNetApctlInit() { +static int sceNetApctlInit(int stackSize, int initPriority) { ERROR_LOG(SCENET, "UNIMPL sceNetApctlInit()"); if (netApctlInited) return ERROR_NET_APCTL_ALREADY_INITIALIZED; + + memset(&netApctlInfo, 0, sizeof(netApctlInfo)); + // Set default values + truncate_cpy(netApctlInfo.name, sizeof(netApctlInfo.name), "Wifi"); + truncate_cpy(netApctlInfo.ssid, sizeof(netApctlInfo.ssid), "Wifi"); + memcpy(netApctlInfo.bssid, "\1\1\2\2\3\3", sizeof(netApctlInfo.bssid)); + netApctlInfo.ssidLength = 4; + netApctlInfo.strength = 99; + netApctlInfo.channel = g_Config.iWlanAdhocChannel; + if (netApctlInfo.channel == PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC) netApctlInfo.channel = defaultWlanChannel; + // Get Local IP Address + sockaddr_in sockAddr; + getLocalIp(&sockAddr); + char ipstr[INET_ADDRSTRLEN] = "127.0.0.1"; // default + inet_ntop(AF_INET, &sockAddr.sin_addr, ipstr, sizeof(ipstr)); + truncate_cpy(netApctlInfo.ip, sizeof(netApctlInfo.ip), ipstr); + // Change the last number to 1 to indicate a common dns server/internet gateway + ((u8*)&sockAddr.sin_addr.s_addr)[3] = 1; + inet_ntop(AF_INET, &sockAddr.sin_addr, ipstr, sizeof(ipstr)); + truncate_cpy(netApctlInfo.gateway, sizeof(netApctlInfo.gateway), ipstr); + truncate_cpy(netApctlInfo.primaryDns, sizeof(netApctlInfo.primaryDns), ipstr); + truncate_cpy(netApctlInfo.secondaryDns, sizeof(netApctlInfo.secondaryDns), "8.8.8.8"); + truncate_cpy(netApctlInfo.subNetMask, sizeof(netApctlInfo.subNetMask), "255.255.255.0"); + + // TODO: Create APctl fake-Thread + netApctlInited = true; + netApctlStatus = PSP_NET_APCTL_STATE_DISCONNECTED; return 0; } @@ -461,10 +587,96 @@ static int sceNetApctlInit() { int sceNetApctlTerm() { ERROR_LOG(SCENET, "UNIMPL sceNeApctlTerm()"); netApctlInited = false; + netApctlStatus = PSP_NET_APCTL_STATE_DISCONNECTED; return 0; } +static int sceNetApctlGetInfo(int code, u32 pInfoAddr) { + WARN_LOG(SCENET, "UNTESTED %s(%i, %08x)", __FUNCTION__, code, pInfoAddr); + + if (!netApctlInited) + return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss"); // Only have valid info after joining an AP and got an IP, right? + + if (!Memory::IsValidAddress(pInfoAddr)) + return hleLogError(SCENET, -1, "apctl invalid arg"); + + u8* info = Memory::GetPointer(pInfoAddr); // FIXME: Points to a union instead of a struct thus each field have the same address + + switch (code) { + case PSP_NET_APCTL_INFO_PROFILE_NAME: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.name); + DEBUG_LOG(SCENET, "ApctlInfo - ProfileName: %s", netApctlInfo.name); + break; + case PSP_NET_APCTL_INFO_BSSID: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.bssid); + DEBUG_LOG(SCENET, "ApctlInfo - BSSID: %s", mac2str((SceNetEtherAddr*)&netApctlInfo.bssid).c_str()); + break; + case PSP_NET_APCTL_INFO_SSID: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.ssid); + DEBUG_LOG(SCENET, "ApctlInfo - SSID: %s", netApctlInfo.ssid); + break; + case PSP_NET_APCTL_INFO_SSID_LENGTH: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.ssidLength); + break; + case PSP_NET_APCTL_INFO_SECURITY_TYPE: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.securityType); + break; + case PSP_NET_APCTL_INFO_STRENGTH: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.strength); + break; + case PSP_NET_APCTL_INFO_CHANNEL: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.channel); + break; + case PSP_NET_APCTL_INFO_POWER_SAVE: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.powerSave); + break; + case PSP_NET_APCTL_INFO_IP: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.ip); + DEBUG_LOG(SCENET, "ApctlInfo - IP: %s", netApctlInfo.ip); + break; + case PSP_NET_APCTL_INFO_SUBNETMASK: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.subNetMask); + DEBUG_LOG(SCENET, "ApctlInfo - SubNet Mask: %s", netApctlInfo.subNetMask); + break; + case PSP_NET_APCTL_INFO_GATEWAY: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.gateway); + DEBUG_LOG(SCENET, "ApctlInfo - Gateway IP: %s", netApctlInfo.gateway); + break; + case PSP_NET_APCTL_INFO_PRIMDNS: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.primaryDns); + DEBUG_LOG(SCENET, "ApctlInfo - Primary DNS: %s", netApctlInfo.primaryDns); + break; + case PSP_NET_APCTL_INFO_SECDNS: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.secondaryDns); + DEBUG_LOG(SCENET, "ApctlInfo - Secondary DNS: %s", netApctlInfo.secondaryDns); + break; + case PSP_NET_APCTL_INFO_USE_PROXY: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.useProxy); + break; + case PSP_NET_APCTL_INFO_PROXY_URL: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.proxyUrl); + DEBUG_LOG(SCENET, "ApctlInfo - Proxy URL: %s", netApctlInfo.proxyUrl); + break; + case PSP_NET_APCTL_INFO_PROXY_PORT: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.proxyPort); + break; + case PSP_NET_APCTL_INFO_8021_EAP_TYPE: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.eapType); + break; + case PSP_NET_APCTL_INFO_START_BROWSER: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.startBrowser); + break; + case PSP_NET_APCTL_INFO_WIFISP: + Memory::WriteStruct(pInfoAddr, &netApctlInfo.wifisp); + break; + default: + return hleLogError(SCENET, ERROR_NET_APCTL_INVALID_CODE, "apctl invalid code"); + } + + return hleLogSuccessI(SCENET, 0); +} + // TODO: How many handlers can the PSP actually have for Apctl? // TODO: Should we allow the same handler to be added more than once? static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) { @@ -615,20 +827,201 @@ static int sceNetInetConnect(int socket, u32 sockAddrInternetPtr, int addressLen return -1; } +static int sceNetApctlConnect(int connIndex) { + ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, connIndex); + + netApctlStatus = PSP_NET_APCTL_STATE_JOINING; + __UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_CONNECT_REQUEST, 0); + return 0; +} + static int sceNetApctlDisconnect() { ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); // Like its 'sister' function sceNetAdhocctlDisconnect, we need to alert Apctl handlers that a disconnect took place // or else games like Phantasy Star Portable 2 will hang at certain points (e.g. returning to the main menu after trying to connect to PSN). + netApctlStatus = PSP_NET_APCTL_STATE_DISCONNECTED; __UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_DISCONNECT_REQUEST, 0); return 0; } +static int sceNetApctlGetState(u32 pStateAddr) { + WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, pStateAddr); + + //if (!netApctlInited) return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss"); + + // Valid Arguments + if (Memory::IsValidAddress(pStateAddr)) { + // Return Thread Status + Memory::Write_U32(netApctlStatus, pStateAddr); + // Return Success + return hleLogSuccessI(SCENET, 0); + } + + return hleLogError(SCENET, -1, "apctl invalid arg"); +} + +static int sceNetApctlScanUser() { + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); + + // Scan probably only works when not in connected state, right? + if (netApctlStatus != PSP_NET_APCTL_STATE_DISCONNECTED) + return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected"); + + netApctlStatus = PSP_NET_APCTL_STATE_SCANNING; + __UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_SCAN_REQUEST, 0); + return 0; +} + +static int sceNetApctlGetBSSDescIDListUser(u32 sizeAddr, u32 bufAddr) { + WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, sizeAddr, bufAddr); + + const int userInfoSize = 8; + int entries = 1; + if (!Memory::IsValidAddress(sizeAddr)) + hleLogError(SCENET, -1, "apctl invalid arg"); + + int size = Memory::Read_U32(sizeAddr); + // Return size required + Memory::Write_U32(entries * userInfoSize, sizeAddr); + + if (bufAddr != 0 && Memory::IsValidAddress(sizeAddr)) { + int offset = 0; + for (int i = 0; i < entries; i++) { + // Check if enough space available to write the next structure + if (offset + userInfoSize > size) { + break; + } + + DEBUG_LOG(SCENET, "%s returning %d at %08x", __FUNCTION__, i, bufAddr + offset); + + // Pointer to next Network structure in list + Memory::Write_U32((i+1)*userInfoSize + bufAddr, bufAddr + offset); + offset += 4; + + // Entry ID + Memory::Write_U32(i, bufAddr + offset); + offset += 4; + } + // Fix the last Pointer + if (offset > 0) + Memory::Write_U32(0, bufAddr + offset - userInfoSize); + } + + return hleLogWarning(SCENET, 0, "untested"); +} + +static int sceNetApctlGetBSSDescEntryUser(int entryId, int infoId, u32 resultAddr) { + WARN_LOG(SCENET, "UNTESTED %s(%i, %i, %08x)", __FUNCTION__, entryId, infoId, resultAddr); + + if (!Memory::IsValidAddress(resultAddr)) + hleLogError(SCENET, -1, "apctl invalid arg"); + + switch (infoId) { + case PSP_NET_APCTL_DESC_IBSS: // IBSS, 6 bytes + Memory::WriteStruct(resultAddr, &netApctlInfo.bssid); + break; + case PSP_NET_APCTL_DESC_SSID_NAME: + // Return 32 bytes + Memory::WriteStruct(resultAddr, &netApctlInfo.ssid); + break; + case PSP_NET_APCTL_DESC_SSID_NAME_LENGTH: + // Return one 32-bit value + Memory::WriteStruct(resultAddr, &netApctlInfo.ssidLength); + break; + case PSP_NET_APCTL_DESC_SIGNAL_STRENGTH: + // Return 1 byte + Memory::WriteStruct(resultAddr, &netApctlInfo.strength); + break; + case PSP_NET_APCTL_DESC_SECURITY: + // Return one 32-bit value + Memory::WriteStruct(resultAddr, &netApctlInfo.securityType); + break; + default: + return hleLogError(SCENET, ERROR_NET_APCTL_INVALID_CODE, "unknown info id"); + } + + return hleLogWarning(SCENET, 0, "untested"); +} + +static int sceNetApctlScanSSID2() { + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); + + // Scan probably only works when not in connected state, right? + if (netApctlStatus != PSP_NET_APCTL_STATE_DISCONNECTED) + return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected"); + + netApctlStatus = PSP_NET_APCTL_STATE_SCANNING; + __UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_SCAN_REQUEST, 0); + return 0; +} + +static int sceNetApctlGetBSSDescIDList2(u32 Arg1, u32 Arg2, u32 Arg3, u32 Arg4) { + return hleLogError(SCENET, 0, "unimplemented"); +} + +static int sceNetApctlGetBSSDescEntry2(u32 Arg1, u32 Arg2, u32 Arg3, u32 Arg4) { + return hleLogError(SCENET, 0, "unimplemented"); +} + static int sceNetResolverInit() { ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); return 0; } +static int sceNetApctlAddInternalHandler(u32 handlerPtr, u32 handlerArg) { + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg); + // This seems to be a 2nd kind of handler + return sceNetApctlAddHandler(handlerPtr, handlerArg); +} + +static int sceNetApctlDelInternalHandler(u32 handlerID) { + ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, handlerID); + // This seems to be a 2nd kind of handler + return sceNetApctlDelHandler(handlerID); +} + +static int sceNetApctl_A7BB73DF(u32 handlerPtr, u32 handlerArg) { + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg); + // This seems to be a 3rd kind of handler + return sceNetApctlAddHandler(handlerPtr, handlerArg); +} + +static int sceNetApctl_6F5D2981(u32 handlerID) { + ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, handlerID); + // This seems to be a 3rd kind of handler + return sceNetApctlDelHandler(handlerID); +} + +static int sceNetApctl_lib2_69745F0A(int handlerId) { + return hleLogError(SCENET, 0, "unimplemented"); +} + +static int sceNetApctl_lib2_4C19731F(int code, u32 pInfoAddr) { + ERROR_LOG(SCENET, "UNIMPL %s(%i, %08x)", __FUNCTION__, code, pInfoAddr); + return sceNetApctlGetInfo(code, pInfoAddr); +} + +static int sceNetApctlScan() { + ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); + return sceNetApctlScanUser(); +} + +static int sceNetApctlGetBSSDescIDList(u32 sizeAddr, u32 bufAddr) { + ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, sizeAddr, bufAddr); + return sceNetApctlGetBSSDescIDListUser(sizeAddr, bufAddr); +} + +static int sceNetApctlGetBSSDescEntry(int entryId, int infoId, u32 resultAddr) { + ERROR_LOG(SCENET, "UNIMPL %s(%i, %i, %08x)", __FUNCTION__, entryId, infoId, resultAddr); + return sceNetApctlGetBSSDescEntryUser(entryId, infoId, resultAddr); +} + +static int sceNetApctl_lib2_C20A144C(int connIndex, u32 ps3MacAddressPtr) { + ERROR_LOG(SCENET, "UNIMPL %s(%i, %08x)", __FUNCTION__, connIndex, ps3MacAddressPtr); + return sceNetApctlConnect(connIndex); +} + static int sceNetUpnpInit(int unknown1,int unknown2) { @@ -734,20 +1127,30 @@ const HLEFunction sceNetInet[] = { }; const HLEFunction sceNetApctl[] = { - {0XCFB957C6, nullptr, "sceNetApctlConnect", '?', "" }, + {0XCFB957C6, &WrapI_I, "sceNetApctlConnect", 'i', "i" }, {0X24FE91A1, &WrapI_V, "sceNetApctlDisconnect", 'i', "" }, - {0X5DEAC81B, nullptr, "sceNetApctlGetState", '?', "" }, + {0X5DEAC81B, &WrapI_U, "sceNetApctlGetState", 'i', "x" }, {0X8ABADD51, &WrapU_UU, "sceNetApctlAddHandler", 'x', "xx" }, - {0XE2F91F9B, &WrapI_V, "sceNetApctlInit", 'i', "" }, + {0XE2F91F9B, &WrapI_II, "sceNetApctlInit", 'i', "ii" }, {0X5963991B, &WrapI_U, "sceNetApctlDelHandler", 'i', "x" }, {0XB3EDD0EC, &WrapI_V, "sceNetApctlTerm", 'i', "" }, - {0X2BEFDF23, nullptr, "sceNetApctlGetInfo", '?', "" }, - {0XA3E77E13, nullptr, "sceNetApctlScanSSID2", '?', "" }, - {0XE9B2E5E6, nullptr, "sceNetApctlScanUser", '?', "" }, - {0XF25A5006, nullptr, "sceNetApctlGetBSSDescIDList2", '?', "" }, - {0X2935C45B, nullptr, "sceNetApctlGetBSSDescEntry2", '?', "" }, - {0X04776994, nullptr, "sceNetApctlGetBSSDescEntryUser", '?', "" }, - {0X6BDDCB8C, nullptr, "sceNetApctlGetBSSDescIDListUser", '?', "" }, + {0X2BEFDF23, &WrapI_IU, "sceNetApctlGetInfo", 'i', "ix" }, + {0XA3E77E13, &WrapI_V, "sceNetApctlScanSSID2", 'i', "" }, + {0XE9B2E5E6, &WrapI_V, "sceNetApctlScanUser", 'i', "" }, + {0XF25A5006, &WrapI_UUUU, "sceNetApctlGetBSSDescIDList2", 'i', "xxxx" }, + {0X2935C45B, &WrapI_UUUU, "sceNetApctlGetBSSDescEntry2", 'i', "xxxx" }, + {0X04776994, &WrapI_IIU, "sceNetApctlGetBSSDescEntryUser", 'i', "iix" }, + {0X6BDDCB8C, &WrapI_UU, "sceNetApctlGetBSSDescIDListUser", 'i', "xx" }, + {0X7CFAB990, &WrapI_UU, "sceNetApctlAddInternalHandler", 'i', "xx" }, + {0XE11BAFAB, &WrapI_U, "sceNetApctlDelInternalHandler", 'i', "x" }, + {0XA7BB73DF, &WrapI_UU, "sceNetApctl_A7BB73DF", 'i', "xx" }, + {0X6F5D2981, &WrapI_U, "sceNetApctl_6F5D2981", 'i', "x" }, + {0X69745F0A, &WrapI_I, "sceNetApctl_lib2_69745F0A", 'i', "i" }, + {0X4C19731F, &WrapI_IU, "sceNetApctl_lib2_4C19731F", 'i', "ix" }, + {0XB3CF6849, &WrapI_V, "sceNetApctlScan", 'i', "" }, + {0X0C7FFA5C, &WrapI_UU, "sceNetApctlGetBSSDescIDList", 'i', "xx" }, + {0X96BEB231, &WrapI_IIU, "sceNetApctlGetBSSDescEntry", 'i', "iix" }, + {0XC20A144C, &WrapI_IU, "sceNetApctl_lib2_C20A144C", 'i', "ix" }, }; const HLEFunction sceWlanDrv[] = { diff --git a/Core/HLE/sceNet.h b/Core/HLE/sceNet.h index 84615a2427..d8514491f8 100644 --- a/Core/HLE/sceNet.h +++ b/Core/HLE/sceNet.h @@ -17,6 +17,7 @@ #pragma once +#include #include "Core/HLE/proAdhoc.h" // Option Names @@ -49,12 +50,74 @@ enum { ERROR_NET_RESOLVER_INVALID_HOST = 0x80410414, ERROR_NET_APCTL_ALREADY_INITIALIZED = 0x80410a01, + ERROR_NET_APCTL_INVALID_CODE = 0x80410a02, + ERROR_NET_APCTL_INVALID_IP = 0x80410a03, + ERROR_NET_APCTL_NOT_DISCONNECTED = 0x80410a04, + ERROR_NET_APCTL_NOT_IN_BSS = 0x80410a05, + ERROR_NET_APCTL_WLAN_SWITCH_OFF = 0x80410a06, + ERROR_NET_APCTL_WLAN_BEACON_LOST = 0x80410a07, + ERROR_NET_APCTL_WLAN_DISASSOCIATION = 0x80410a08, + ERROR_NET_APCTL_INVALID_ID = 0x80410a09, + ERROR_NET_APCTL_WLAN_SUSPENDED = 0x80410a0a, + ERROR_NET_APCTL_TIMEOUT = 0x80410a0b, }; enum { - PSP_NET_APCTL_EVENT_DISCONNECT_REQUEST = 5, + PSP_NET_APCTL_STATE_DISCONNECTED = 0, + PSP_NET_APCTL_STATE_SCANNING = 1, + PSP_NET_APCTL_STATE_JOINING = 2, + PSP_NET_APCTL_STATE_GETTING_IP = 3, + PSP_NET_APCTL_STATE_GOT_IP = 4, + PSP_NET_APCTL_STATE_EAP_AUTH = 5, + PSP_NET_APCTL_STATE_KEY_EXCHANGE = 6 }; +enum { + PSP_NET_APCTL_EVENT_CONNECT_REQUEST = 0, + PSP_NET_APCTL_EVENT_SCAN_REQUEST = 1, + PSP_NET_APCTL_EVENT_SCAN_COMPLETE = 2, + PSP_NET_APCTL_EVENT_ESTABLISHED = 3, + PSP_NET_APCTL_EVENT_GET_IP = 4, + PSP_NET_APCTL_EVENT_DISCONNECT_REQUEST = 5, + PSP_NET_APCTL_EVENT_ERROR = 6, + PSP_NET_APCTL_EVENT_INFO = 7, + PSP_NET_APCTL_EVENT_EAP_AUTH = 8, + PSP_NET_APCTL_EVENT_KEY_EXCHANGE = 9, + PSP_NET_APCTL_EVENT_RECONNECT = 10 +}; + +#define PSP_NET_APCTL_INFO_PROFILE_NAME 0 +#define PSP_NET_APCTL_INFO_BSSID 1 +#define PSP_NET_APCTL_INFO_SSID 2 +#define PSP_NET_APCTL_INFO_SSID_LENGTH 3 +#define PSP_NET_APCTL_INFO_SECURITY_TYPE 4 +#define PSP_NET_APCTL_INFO_STRENGTH 5 +#define PSP_NET_APCTL_INFO_CHANNEL 6 +#define PSP_NET_APCTL_INFO_POWER_SAVE 7 +#define PSP_NET_APCTL_INFO_IP 8 +#define PSP_NET_APCTL_INFO_SUBNETMASK 9 +#define PSP_NET_APCTL_INFO_GATEWAY 10 +#define PSP_NET_APCTL_INFO_PRIMDNS 11 +#define PSP_NET_APCTL_INFO_SECDNS 12 +#define PSP_NET_APCTL_INFO_USE_PROXY 13 +#define PSP_NET_APCTL_INFO_PROXY_URL 14 +#define PSP_NET_APCTL_INFO_PROXY_PORT 15 +#define PSP_NET_APCTL_INFO_8021_EAP_TYPE 16 +#define PSP_NET_APCTL_INFO_START_BROWSER 17 +#define PSP_NET_APCTL_INFO_WIFISP 18 + +#define PSP_NET_APCTL_INFO_SECURITY_TYPE_NONE 0 +#define PSP_NET_APCTL_INFO_SECURITY_TYPE_WEP 1 +#define PSP_NET_APCTL_INFO_SECURITY_TYPE_WPA 2 +#define PSP_NET_APCTL_INFO_SECURITY_TYPE_UNSUPPORTED 3 +#define PSP_NET_APCTL_INFO_SECURITY_TYPE_WPA_AES 4 + +#define PSP_NET_APCTL_DESC_IBSS 0 +#define PSP_NET_APCTL_DESC_SSID_NAME 1 +#define PSP_NET_APCTL_DESC_SSID_NAME_LENGTH 2 +#define PSP_NET_APCTL_DESC_SIGNAL_STRENGTH 4 +#define PSP_NET_APCTL_DESC_SECURITY 5 + #ifdef _MSC_VER #pragma pack(push,1) #endif @@ -85,10 +148,39 @@ typedef struct ProductStruct { // Similar to SceNetAdhocctlAdhocId ? s32_le unknown; // Unknown, set to 0 // Product Type ? char product[PRODUCT_CODE_LENGTH]; // Game ID (Example: ULUS10000) } PACK ProductStruct; + #ifdef _MSC_VER #pragma pack(pop) #endif +typedef void(*sceNetApctlHandler)(int oldState, int newState, int event, int error, void* pArg); + +#define APCTL_PROFILENAME_MAXLEN 64 +#define APCTL_SSID_MAXLEN 32 +#define APCTL_IPADDR_MAXLEN 16 +#define APCTL_URL_MAXLEN 128 +typedef struct SceNetApctlInfoInternal { // Using struct instead of union for internal use + char name[APCTL_PROFILENAME_MAXLEN]; + u8 bssid[ETHER_ADDR_LEN]; + char ssid[APCTL_SSID_MAXLEN]; + unsigned int ssidLength; // ssid string length (excluding null terminator) + unsigned int securityType; // a value of PSP_NET_APCTL_INFO_SECURITY_TYPE_NONE..PSP_NET_APCTL_INFO_SECURITY_TYPE_WPA? + u8 strength; // Signal strength in % + u8 channel; + u8 powerSave; // 1 on, 0 off + char ip[APCTL_IPADDR_MAXLEN]; // PSP's IP + char subNetMask[APCTL_IPADDR_MAXLEN]; + char gateway[APCTL_IPADDR_MAXLEN]; + char primaryDns[APCTL_IPADDR_MAXLEN]; + char secondaryDns[APCTL_IPADDR_MAXLEN]; + unsigned int useProxy; // 1 for proxy, 0 for no proxy + char proxyUrl[APCTL_URL_MAXLEN]; + unsigned short proxyPort; + unsigned int eapType; // 0 is none, 1 is EAP-MD5 + unsigned int startBrowser; // 1 = start browser + unsigned int wifisp; // 1 if connection is for Wifi service providers (WISP) for sharing internet connection +} SceNetApctlInfoInternal; + struct ApctlHandler { u32 entryPoint; u32 argument; @@ -98,6 +190,10 @@ class PointerWrap; extern bool netInetInited; extern bool netApctlInited; +extern int netApctlStatus; + +template std::string num2hex(I w, size_t hex_len = sizeof(I) << 1); +std::string error2str(u32 errorcode); void Register_sceNet(); void Register_sceWlanDrv();