Moving reused adhoc function out of sceNet function to prevent getting extra SCENET log

This commit is contained in:
ANR2ME 2020-08-08 03:53:55 +07:00
parent ee3b822c0e
commit 8dec09703f
4 changed files with 110 additions and 92 deletions

View file

@ -917,9 +917,7 @@ static int sceNetApctlGetInfo(int code, u32 pInfoAddr) {
return hleLogSuccessI(SCENET, 0); return hleLogSuccessI(SCENET, 0);
} }
// TODO: How many handlers can the PSP actually have for Apctl? int NetApctl_AddHandler(u32 handlerPtr, u32 handlerArg) {
// TODO: Should we allow the same handler to be added more than once?
static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
bool foundHandler = false; bool foundHandler = false;
u32 retval = 0; u32 retval = 0;
struct ApctlHandler handler; struct ApctlHandler handler;
@ -931,41 +929,53 @@ static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
handler.entryPoint = handlerPtr; handler.entryPoint = handlerPtr;
handler.argument = handlerArg; handler.argument = handlerArg;
for(std::map<int, ApctlHandler>::iterator it = apctlHandlers.begin(); it != apctlHandlers.end(); it++) { for (std::map<int, ApctlHandler>::iterator it = apctlHandlers.begin(); it != apctlHandlers.end(); it++) {
if(it->second.entryPoint == handlerPtr) { if (it->second.entryPoint == handlerPtr) {
foundHandler = true; foundHandler = true;
break; break;
} }
} }
if(!foundHandler && Memory::IsValidAddress(handlerPtr)) { if (!foundHandler && Memory::IsValidAddress(handlerPtr)) {
if(apctlHandlers.size() >= MAX_APCTL_HANDLERS) { if (apctlHandlers.size() >= MAX_APCTL_HANDLERS) {
ERROR_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): Too many handlers", handlerPtr, handlerArg); ERROR_LOG(SCENET, "Failed to Add handler(%x, %x): Too many handlers", handlerPtr, handlerArg);
retval = ERROR_NET_ADHOCCTL_TOO_MANY_HANDLERS; // TODO: What's the proper error code for Apctl's TOO_MANY_HANDLERS? retval = ERROR_NET_ADHOCCTL_TOO_MANY_HANDLERS; // TODO: What's the proper error code for Apctl's TOO_MANY_HANDLERS?
return retval; return retval;
} }
apctlHandlers[retval] = handler; apctlHandlers[retval] = handler;
WARN_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): added handler %d", handlerPtr, handlerArg, retval); WARN_LOG(SCENET, "Added Apctl handler(%x, %x): %d", handlerPtr, handlerArg, retval);
} }
else { else {
ERROR_LOG(SCENET, "UNTESTED sceNetApctlAddHandler(%x, %x): Same handler already exists", handlerPtr, handlerArg); ERROR_LOG(SCENET, "Existing Apctl handler(%x, %x)", handlerPtr, handlerArg);
} }
// The id to return is the number of handlers currently registered // The id to return is the number of handlers currently registered
return retval; return retval;
} }
static int sceNetApctlDelHandler(u32 handlerID) { // TODO: How many handlers can the PSP actually have for Apctl?
if(apctlHandlers.find(handlerID) != apctlHandlers.end()) { // TODO: Should we allow the same handler to be added more than once?
static u32 sceNetApctlAddHandler(u32 handlerPtr, u32 handlerArg) {
INFO_LOG(SCENET, "%s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg);
return NetApctl_AddHandler(handlerPtr, handlerArg);
}
int NetApctl_DelHandler(u32 handlerID) {
if (apctlHandlers.find(handlerID) != apctlHandlers.end()) {
apctlHandlers.erase(handlerID); apctlHandlers.erase(handlerID);
WARN_LOG(SCENET, "UNTESTED sceNetapctlDelHandler(%d): deleted handler %d", handlerID, handlerID); WARN_LOG(SCENET, "Deleted Apctl handler: %d", handlerID);
} }
else { else {
ERROR_LOG(SCENET, "UNTESTED sceNetapctlDelHandler(%d): asked to delete invalid handler %d", handlerID, handlerID); ERROR_LOG(SCENET, "Invalid Apctl handler: %d", handlerID);
} }
return 0; return 0;
} }
static int sceNetApctlDelHandler(u32 handlerID) {
INFO_LOG(SCENET, "%s(%d)", __FUNCTION__, handlerID);
return NetApctl_DelHandler(handlerID);
}
static int sceNetInetInetAton(const char *hostname, u32 addrPtr) { static int sceNetInetInetAton(const char *hostname, u32 addrPtr) {
ERROR_LOG(SCENET, "UNIMPL sceNetInetInetAton(%s, %08x)", hostname, addrPtr); ERROR_LOG(SCENET, "UNIMPL sceNetInetInetAton(%s, %08x)", hostname, addrPtr);
return -1; return -1;
@ -1067,7 +1077,7 @@ static int sceNetInetConnect(int socket, u32 sockAddrInternetPtr, int addressLen
return -1; return -1;
} }
static int sceNetApctlConnect(int connIndex) { int sceNetApctlConnect(int connIndex) {
ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, connIndex); ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, connIndex);
// Is this connIndex is the index to the scanning's result data or sceNetApctlGetBSSDescIDListUser result? // Is this connIndex is the index to the scanning's result data or sceNetApctlGetBSSDescIDListUser result?
__UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_CONNECT_REQUEST, 0); __UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_CONNECT_REQUEST, 0);
@ -1083,15 +1093,17 @@ static int sceNetApctlDisconnect() {
return 0; return 0;
} }
static int sceNetApctlGetState(u32 pStateAddr) { int NetApctl_GetState() {
WARN_LOG(SCENET, "UNTESTED %s(%08x)", __FUNCTION__, pStateAddr); return netApctlState;
}
static int sceNetApctlGetState(u32 pStateAddr) {
//if (!netApctlInited) return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss"); //if (!netApctlInited) return hleLogError(SCENET, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss");
// Valid Arguments // Valid Arguments
if (Memory::IsValidAddress(pStateAddr)) { if (Memory::IsValidAddress(pStateAddr)) {
// Return Thread Status // Return Thread Status
Memory::Write_U32(netApctlState, pStateAddr); Memory::Write_U32(NetApctl_GetState(), pStateAddr);
// Return Success // Return Success
return hleLogSuccessI(SCENET, 0); return hleLogSuccessI(SCENET, 0);
} }
@ -1099,9 +1111,7 @@ static int sceNetApctlGetState(u32 pStateAddr) {
return hleLogError(SCENET, -1, "apctl invalid arg"); return hleLogError(SCENET, -1, "apctl invalid arg");
} }
static int sceNetApctlScanUser() { int NetApctl_ScanUser() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
// Scan probably only works when not in connected state, right? // Scan probably only works when not in connected state, right?
if (netApctlState != PSP_NET_APCTL_STATE_DISCONNECTED) if (netApctlState != PSP_NET_APCTL_STATE_DISCONNECTED)
return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected"); return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected");
@ -1110,6 +1120,11 @@ static int sceNetApctlScanUser() {
return 0; return 0;
} }
static int sceNetApctlScanUser() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
return NetApctl_ScanUser();
}
static int sceNetApctlGetBSSDescIDListUser(u32 sizeAddr, u32 bufAddr) { static int sceNetApctlGetBSSDescIDListUser(u32 sizeAddr, u32 bufAddr) {
WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, sizeAddr, bufAddr); WARN_LOG(SCENET, "UNTESTED %s(%08x, %08x)", __FUNCTION__, sizeAddr, bufAddr);
@ -1183,13 +1198,7 @@ static int sceNetApctlGetBSSDescEntryUser(int entryId, int infoId, u32 resultAdd
static int sceNetApctlScanSSID2() { static int sceNetApctlScanSSID2() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
return NetApctl_ScanUser();
// Scan probably only works when not in connected state, right?
if (netApctlState != PSP_NET_APCTL_STATE_DISCONNECTED)
return hleLogError(SCENET, ERROR_NET_APCTL_NOT_DISCONNECTED, "apctl not disconnected");
__UpdateApctlHandlers(0, 0, PSP_NET_APCTL_EVENT_SCAN_REQUEST, 0);
return 0;
} }
static int sceNetApctlGetBSSDescIDList2(u32 Arg1, u32 Arg2, u32 Arg3, u32 Arg4) { static int sceNetApctlGetBSSDescIDList2(u32 Arg1, u32 Arg2, u32 Arg3, u32 Arg4) {
@ -1209,13 +1218,13 @@ static int sceNetResolverInit()
static int sceNetApctlAddInternalHandler(u32 handlerPtr, u32 handlerArg) { static int sceNetApctlAddInternalHandler(u32 handlerPtr, u32 handlerArg) {
ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg); ERROR_LOG(SCENET, "UNIMPL %s(%08x, %08x)", __FUNCTION__, handlerPtr, handlerArg);
// This seems to be a 2nd kind of handler // This seems to be a 2nd kind of handler
return sceNetApctlAddHandler(handlerPtr, handlerArg); return NetApctl_AddHandler(handlerPtr, handlerArg);
} }
static int sceNetApctlDelInternalHandler(u32 handlerID) { static int sceNetApctlDelInternalHandler(u32 handlerID) {
ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, handlerID); ERROR_LOG(SCENET, "UNIMPL %s(%i)", __FUNCTION__, handlerID);
// This seems to be a 2nd kind of handler // This seems to be a 2nd kind of handler
return sceNetApctlDelHandler(handlerID); return NetApctl_DelHandler(handlerID);
} }
static int sceNetApctl_A7BB73DF(u32 handlerPtr, u32 handlerArg) { static int sceNetApctl_A7BB73DF(u32 handlerPtr, u32 handlerArg) {
@ -1241,7 +1250,7 @@ static int sceNetApctl_lib2_4C19731F(int code, u32 pInfoAddr) {
static int sceNetApctlScan() { static int sceNetApctlScan() {
ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__); ERROR_LOG(SCENET, "UNIMPL %s()", __FUNCTION__);
return sceNetApctlScanUser(); return NetApctl_ScanUser();
} }
static int sceNetApctlGetBSSDescIDList(u32 sizeAddr, u32 bufAddr) { static int sceNetApctlGetBSSDescIDList(u32 sizeAddr, u32 bufAddr) {

View file

@ -233,6 +233,9 @@ void __NetInit();
void __NetShutdown(); void __NetShutdown();
void __NetDoState(PointerWrap &p); void __NetDoState(PointerWrap &p);
int NetApctl_GetState();
int sceNetApctlConnect(int connIndex);
int sceNetInetPoll(void *fds, u32 nfds, int timeout); int sceNetInetPoll(void *fds, u32 nfds, int timeout);
int sceNetInetTerm(); int sceNetInetTerm();
int sceNetApctlTerm(); int sceNetApctlTerm();

View file

@ -274,23 +274,24 @@ static u32 sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
return 0; return 0;
} }
int NetAdhocctl_GetState() {
return threadStatus;
}
static int sceNetAdhocctlGetState(u32 ptrToStatus) { static int sceNetAdhocctlGetState(u32 ptrToStatus) {
// Library initialized
if (netAdhocctlInited) {
// Valid Arguments
if (Memory::IsValidAddress(ptrToStatus)) {
// Return Thread Status
Memory::Write_U32(threadStatus, ptrToStatus);
// Return Success
return 0;
}
// Invalid Arguments
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Library uninitialized // Library uninitialized
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; if (!netAdhocctlInited)
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
// Invalid Arguments
if (!Memory::IsValidAddress(ptrToStatus))
return ERROR_NET_ADHOCCTL_INVALID_ARG;
// Return Thread Status
Memory::Write_U32(NetAdhocctl_GetState(), ptrToStatus);
// Return Success
return hleLogSuccessVerboseI(SCENET, 0);
} }
/** /**
@ -1431,34 +1432,6 @@ static int sceNetAdhocctlGetNameByAddr(const char *mac, u32 nameAddr) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
} }
static int sceNetAdhocctlJoin(u32 scanInfoAddr) {
WARN_LOG(SCENET, "UNTESTED sceNetAdhocctlJoin(%08x) at %08x", scanInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
// Library initialized
if (netAdhocctlInited)
{
// Valid Argument
if (Memory::IsValidAddress(scanInfoAddr))
{
SceNetAdhocctlScanInfoEmu * sinfo = (SceNetAdhocctlScanInfoEmu *)Memory::GetPointer(scanInfoAddr);
//while (true) sleep_ms(1);
// We can ignore minor connection process differences here
// TODO: Adhoc Server may need to be changed to differentiate between Host/Create and Join, otherwise it can't support multiple Host using the same Group name, thus causing one of the Host to be confused being treated as Join.
return sceNetAdhocctlCreate((const char*)&sinfo->group_name);
}
// Invalid Argument
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Uninitialized Library
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) { int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
VERBOSE_LOG(SCENET, "sceNetAdhocctlGetPeerInfo(%s, %i, %08x) at %08x", mac2str((SceNetEtherAddr*)mac).c_str(), size, peerInfoAddr, currentMIPS->pc); VERBOSE_LOG(SCENET, "sceNetAdhocctlGetPeerInfo(%s, %i, %08x) at %08x", mac2str((SceNetEtherAddr*)mac).c_str(), size, peerInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) { if (!g_Config.bEnableWlan) {
@ -1528,20 +1501,8 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
} }
/** int NetAdhocctl_Create(const char* groupName) {
* Create and / or Join a Virtual Network of the specified Name const SceNetAdhocctlGroupName* groupNameStruct = (const SceNetAdhocctlGroupName*)groupName;
* @param group_name Virtual Network Name
* @return 0 on success or... ADHOCCTL_NOT_INITIALIZED, ADHOCCTL_INVALID_ARG, ADHOCCTL_BUSY
*/
int sceNetAdhocctlCreate(const char *groupName) {
char grpName[9] = { 0 };
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlCreate(%s) at %08x", grpName, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
const SceNetAdhocctlGroupName * groupNameStruct = (const SceNetAdhocctlGroupName *)groupName;
// Library initialized // Library initialized
if (netAdhocctlInited) { if (netAdhocctlInited) {
// Valid Argument // Valid Argument
@ -1578,7 +1539,7 @@ int sceNetAdhocctlCreate(const char *groupName) {
// Acquire Network Lock // Acquire Network Lock
// Send Packet // Send Packet
int iResult = send(metasocket, (const char *)&packet, sizeof(packet), 0); int iResult = send(metasocket, (const char*)&packet, sizeof(packet), 0);
if (iResult == SOCKET_ERROR) { if (iResult == SOCKET_ERROR) {
ERROR_LOG(SCENET, "Socket error (%i) when sending", errno); ERROR_LOG(SCENET, "Socket error (%i) when sending", errno);
//return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; // ERROR_NET_ADHOCCTL_DISCONNECTED; // ERROR_NET_ADHOCCTL_BUSY; //return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; // ERROR_NET_ADHOCCTL_DISCONNECTED; // ERROR_NET_ADHOCCTL_BUSY;
@ -1626,6 +1587,22 @@ int sceNetAdhocctlCreate(const char *groupName) {
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED; return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
} }
/**
* Create and / or Join a Virtual Network of the specified Name
* @param group_name Virtual Network Name
* @return 0 on success or... ADHOCCTL_NOT_INITIALIZED, ADHOCCTL_INVALID_ARG, ADHOCCTL_BUSY
*/
int sceNetAdhocctlCreate(const char *groupName) {
char grpName[9] = { 0 };
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlCreate(%s) at %08x", grpName, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
return NetAdhocctl_Create(groupName);
}
static int sceNetAdhocctlConnect(u32 ptrToGroupName) { static int sceNetAdhocctlConnect(u32 ptrToGroupName) {
if (Memory::IsValidAddress(ptrToGroupName)) { if (Memory::IsValidAddress(ptrToGroupName)) {
const char* groupName = Memory::GetCharPointer(ptrToGroupName); const char* groupName = Memory::GetCharPointer(ptrToGroupName);
@ -1633,12 +1610,40 @@ static int sceNetAdhocctlConnect(u32 ptrToGroupName) {
memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs memcpy(grpName, groupName, ADHOCCTL_GROUPNAME_LEN); // Copied to null-terminated var to prevent unexpected behaviour on Logs
INFO_LOG(SCENET, "sceNetAdhocctlConnect(groupName=%s) at %08x", grpName, currentMIPS->pc); INFO_LOG(SCENET, "sceNetAdhocctlConnect(groupName=%s) at %08x", grpName, currentMIPS->pc);
return sceNetAdhocctlCreate(groupName); return NetAdhocctl_Create(groupName);
} }
return ERROR_NET_ADHOC_INVALID_ARG; // ERROR_NET_ADHOC_INVALID_ADDR; return ERROR_NET_ADHOC_INVALID_ARG; // ERROR_NET_ADHOC_INVALID_ADDR;
} }
static int sceNetAdhocctlJoin(u32 scanInfoAddr) {
WARN_LOG(SCENET, "UNTESTED sceNetAdhocctlJoin(%08x) at %08x", scanInfoAddr, currentMIPS->pc);
if (!g_Config.bEnableWlan) {
return -1;
}
// Library initialized
if (netAdhocctlInited)
{
// Valid Argument
if (Memory::IsValidAddress(scanInfoAddr))
{
SceNetAdhocctlScanInfoEmu* sinfo = (SceNetAdhocctlScanInfoEmu*)Memory::GetPointer(scanInfoAddr);
//while (true) sleep_ms(1);
// We can ignore minor connection process differences here
// TODO: Adhoc Server may need to be changed to differentiate between Host/Create and Join, otherwise it can't support multiple Host using the same Group name, thus causing one of the Host to be confused being treated as Join.
return NetAdhocctl_Create((const char*)&sinfo->group_name);
}
// Invalid Argument
return ERROR_NET_ADHOCCTL_INVALID_ARG;
}
// Uninitialized Library
return ERROR_NET_ADHOCCTL_NOT_INITIALIZED;
}
// Connect to the Adhoc control game mode (as a Host) // Connect to the Adhoc control game mode (as a Host)
static int sceNetAdhocctlCreateEnterGameMode(const char *groupName, int unknown, int playerNum, u32 macsAddr, int timeout, int unknown2) { static int sceNetAdhocctlCreateEnterGameMode(const char *groupName, int unknown, int playerNum, u32 macsAddr, int timeout, int unknown2) {
char grpName[9] = { 0 }; char grpName[9] = { 0 };

View file

@ -62,4 +62,5 @@ extern u32_le matchingThreadCode[3];
int NetAdhocMatching_Term(); int NetAdhocMatching_Term();
int NetAdhocctl_Term(); int NetAdhocctl_Term();
int NetAdhocctl_GetState();
int NetAdhoc_Term(); int NetAdhoc_Term();