1 // Copyright (c) 2013- PPSSPP Project. 2 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, version 2.0 or later versions. 6 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License 2.0 for more details. 11 12 // A copy of the GPL 2.0 should have been included with the program. 13 // If not, see http://www.gnu.org/licenses/ 14 15 // Official git repository and contact information can be found at 16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. 17 18 #pragma once 19 20 #include <deque> 21 #include "Core/HLE/proAdhoc.h" 22 23 #ifdef _MSC_VER 24 #pragma pack(push,1) 25 #endif 26 typedef struct MatchingArgs { 27 u32_le data[6]; //ContextID, Opcode, bufAddr[ to MAC], OptLen, OptAddr[, EntryPoint] 28 } PACK MatchingArgs; 29 30 typedef struct SceNetAdhocDiscoverParam { 31 u32_le unknown1; // SleepMode? (ie. 0 on on Legend Of The Dragon, 1 on Dissidia 012) 32 char groupName[ADHOCCTL_GROUPNAME_LEN]; 33 u32_le unknown2; // size of something? (ie. 0x3c on Legend Of The Dragon, 0x14 on Dissidia 012) // Note: the param size is 0x14 may be it can contains extra data too? 34 u32_le result; // inited to 0? 35 } PACK SceNetAdhocDiscoverParam; 36 #ifdef _MSC_VER 37 #pragma pack(pop) 38 #endif 39 40 struct AdhocctlRequest { 41 u8 opcode; 42 SceNetAdhocctlGroupName group; 43 }; 44 45 struct AdhocSendTarget { 46 u32 ip; 47 u16 port; // original port 48 }; 49 50 struct AdhocSendTargets { 51 int length; 52 std::deque<AdhocSendTarget> peers; 53 bool isBroadcast; 54 }; 55 56 struct AdhocSocketRequest { 57 int type; 58 int id; // PDP/PTP socket id 59 void* buffer; 60 s32_le* length; 61 u32 timeout; 62 u64 startTime; 63 SceNetEtherAddr* remoteMAC; 64 u16_le* remotePort; 65 }; 66 67 enum AdhocSocketRequestType : int 68 { 69 PTP_CONNECT = 0, 70 PTP_ACCEPT = 1, 71 PTP_SEND = 2, 72 PTP_RECV = 3, 73 PTP_FLUSH = 4, 74 PDP_SEND = 5, 75 PDP_RECV = 6, 76 ADHOC_POLL_SOCKET = 7, 77 }; 78 79 enum AdhocDiscoverStatus : int 80 { 81 NET_ADHOC_DISCOVER_STATUS_NONE = 0, 82 NET_ADHOC_DISCOVER_STATUS_IN_PROGRESS = 1, 83 NET_ADHOC_DISCOVER_STATUS_COMPLETED = 2, 84 }; 85 86 enum AdhocDiscoverResult : int 87 { 88 NET_ADHOC_DISCOVER_RESULT_NO_PEER_FOUND = 0, // Initial value 89 NET_ADHOC_DISCOVER_RESULT_CANCELED = 1, // CANCELED or STOPPED? 90 NET_ADHOC_DISCOVER_RESULT_PEER_FOUND = 2, 91 NET_ADHOC_DISCOVER_RESULT_ABORTED = 3, // Internal Error occured? 92 }; 93 94 95 class PointerWrap; 96 97 void Register_sceNetAdhoc(); 98 99 u32_le __CreateHLELoop(u32_le* loopAddr, const char* sceFuncName, const char* hleFuncName, const char* tagName = NULL); 100 void __NetAdhocInit(); 101 void __NetAdhocShutdown(); 102 void __NetAdhocDoState(PointerWrap &p); 103 void __UpdateAdhocctlHandlers(u32 flags, u32 error); 104 void __UpdateMatchingHandler(MatchingArgs params); 105 106 // I have to call this from netdialog 107 int sceNetAdhocctlGetState(u32 ptrToStatus); 108 int sceNetAdhocctlCreate(const char * groupName); 109 int sceNetAdhocctlConnect(const char* groupName); 110 int sceNetAdhocctlJoin(u32 scanInfoAddr); 111 int sceNetAdhocctlScan(); 112 int sceNetAdhocctlGetScanInfo(u32 sizeAddr, u32 bufAddr); 113 114 int NetAdhocMatching_Term(); 115 int NetAdhocctl_Term(); 116 int NetAdhocctl_GetState(); 117 int NetAdhocctl_Create(const char* groupName); 118 int NetAdhoc_Term(); 119 120 // May need to use these from sceNet.cpp 121 extern bool netAdhocInited; 122 extern bool netAdhocctlInited; 123 extern bool networkInited; 124 extern bool netAdhocGameModeEntered; 125 extern int netAdhocEnterGameModeTimeout; 126 extern int adhocDefaultTimeout; //3000000 usec 127 extern int adhocDefaultDelay; //10000 128 extern int adhocExtraDelay; //20000 129 extern int adhocEventPollDelay; //100000; // Seems to be the same with PSP_ADHOCCTL_RECV_TIMEOUT 130 extern int adhocMatchingEventDelay; //30000 131 extern int adhocEventDelay; //1000000 132 extern std::recursive_mutex adhocEvtMtx; 133 extern int IsAdhocctlInCB; 134 135 extern u32 dummyThreadHackAddr; 136 extern u32_le dummyThreadCode[3]; 137 extern u32 matchingThreadHackAddr; 138 extern u32_le matchingThreadCode[3]; 139 140