| File: | Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp |
| Location: | line 911, column 33 |
| Description: | Call to 'malloc' has an allocation size of 0 bytes |
| 1 | // Copyright 2013 Dolphin Emulator Project | |||
| 2 | // Licensed under GPLv2 | |||
| 3 | // Refer to the license.txt file included. | |||
| 4 | ||||
| 5 | #include "WII_IPC_HLE_Device_es.h" | |||
| 6 | #include "WII_IPC_HLE_Device_net.h" | |||
| 7 | #include "../ConfigManager.h" | |||
| 8 | #include "FileUtil.h" | |||
| 9 | #include <stdio.h> | |||
| 10 | #include <string> | |||
| 11 | #include "ICMP.h" | |||
| 12 | #include "CommonPaths.h" | |||
| 13 | #include "SettingsHandler.h" | |||
| 14 | #include "ec_wii.h" | |||
| 15 | #include "WII_Socket.h" | |||
| 16 | ||||
| 17 | #ifdef _WIN32 | |||
| 18 | #include <ws2tcpip.h> | |||
| 19 | #include <iphlpapi.h> | |||
| 20 | #include <iphlpapi.h> | |||
| 21 | ||||
| 22 | #include "fakepoll.h" | |||
| 23 | #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) | |||
| 24 | #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) | |||
| 25 | ||||
| 26 | #elif defined(__linux__1) or defined(__APPLE__) | |||
| 27 | #include <netdb.h> | |||
| 28 | #include <arpa/inet.h> | |||
| 29 | #include <sys/types.h> | |||
| 30 | #include <sys/socket.h> | |||
| 31 | #include <sys/ioctl.h> | |||
| 32 | #include <netinet/in.h> | |||
| 33 | #include <net/if.h> | |||
| 34 | #include <errno(*__errno_location ()).h> | |||
| 35 | #include <poll.h> | |||
| 36 | #include <string.h> | |||
| 37 | ||||
| 38 | typedef struct pollfd pollfd_t; | |||
| 39 | #else | |||
| 40 | #include <sys/types.h> | |||
| 41 | #include <sys/socket.h> | |||
| 42 | #include <netinet/in.h> | |||
| 43 | #include <errno(*__errno_location ()).h> | |||
| 44 | #endif | |||
| 45 | ||||
| 46 | extern std::queue<std::pair<u32,std::string> > g_ReplyQueueLater; | |||
| 47 | const u8 default_address[] = { 0x00, 0x17, 0xAB, 0x99, 0x99, 0x99 }; | |||
| 48 | ||||
| 49 | // ********************************************************************************** | |||
| 50 | // Handle /dev/net/kd/request requests | |||
| 51 | CWII_IPC_HLE_Device_net_kd_request::CWII_IPC_HLE_Device_net_kd_request(u32 _DeviceID, const std::string& _rDeviceName) | |||
| 52 | : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) | |||
| 53 | { | |||
| 54 | } | |||
| 55 | ||||
| 56 | CWII_IPC_HLE_Device_net_kd_request::~CWII_IPC_HLE_Device_net_kd_request() | |||
| 57 | { | |||
| 58 | WiiSockMan::getInstance().clean(); | |||
| 59 | } | |||
| 60 | ||||
| 61 | bool CWII_IPC_HLE_Device_net_kd_request::Open(u32 _CommandAddress, u32 _Mode) | |||
| 62 | { | |||
| 63 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: Open")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 63, "NET_KD_REQ: Open"); } } while (0); | |||
| 64 | Memory::Write_U32(GetDeviceID(), _CommandAddress + 4); | |||
| 65 | m_Active = true; | |||
| 66 | return true; | |||
| 67 | } | |||
| 68 | ||||
| 69 | bool CWII_IPC_HLE_Device_net_kd_request::Close(u32 _CommandAddress, bool _bForce) | |||
| 70 | { | |||
| 71 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: Close")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 71, "NET_KD_REQ: Close"); } } while (0); | |||
| 72 | if (!_bForce) | |||
| 73 | Memory::Write_U32(0, _CommandAddress + 4); | |||
| 74 | m_Active = false; | |||
| 75 | return true; | |||
| 76 | } | |||
| 77 | ||||
| 78 | bool CWII_IPC_HLE_Device_net_kd_request::IOCtl(u32 _CommandAddress) | |||
| 79 | { | |||
| 80 | u32 Parameter = Memory::Read_U32(_CommandAddress + 0xC); | |||
| 81 | u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); | |||
| 82 | u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); | |||
| 83 | u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); | |||
| 84 | u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); | |||
| 85 | ||||
| 86 | u32 ReturnValue = 0; | |||
| 87 | switch (Parameter) | |||
| 88 | { | |||
| 89 | case IOCTL_NWC24_SUSPEND_SCHEDULAR: | |||
| 90 | // NWC24iResumeForCloseLib from NWC24SuspendScheduler (Input: none, Output: 32 bytes) | |||
| 91 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULAR - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 91, "NET_KD_REQ: IOCTL_NWC24_SUSPEND_SCHEDULAR - NI"); } } while (0); | |||
| 92 | Memory::Write_U32(0, BufferOut); // no error | |||
| 93 | break; | |||
| 94 | ||||
| 95 | case IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULAR: // NWC24iResumeForCloseLib | |||
| 96 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULAR - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 96, "NET_KD_REQ: IOCTL_NWC24_EXEC_TRY_SUSPEND_SCHEDULAR - NI" ); } } while (0); | |||
| 97 | break; | |||
| 98 | ||||
| 99 | case IOCTL_NWC24_EXEC_RESUME_SCHEDULAR : // NWC24iResumeForCloseLib | |||
| 100 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULAR - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 100, "NET_KD_REQ: IOCTL_NWC24_EXEC_RESUME_SCHEDULAR - NI"); } } while (0); | |||
| 101 | Memory::Write_U32(0, BufferOut); // no error | |||
| 102 | break; | |||
| 103 | ||||
| 104 | case IOCTL_NWC24_STARTUP_SOCKET: // NWC24iStartupSocket | |||
| 105 | Memory::Write_U32(0, BufferOut); | |||
| 106 | Memory::Write_U32(0, BufferOut+4); | |||
| 107 | ReturnValue = 0; | |||
| 108 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_STARTUP_SOCKET - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 108, "NET_KD_REQ: IOCTL_NWC24_STARTUP_SOCKET - NI"); } } while (0); | |||
| 109 | break; | |||
| 110 | case IOCTL_NWC24_CLEANUP_SOCKET: | |||
| 111 | Memory::Memset(BufferOut, 0, BufferOutSize); | |||
| 112 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_CLEANUP_SOCKET - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 112, "NET_KD_REQ: IOCTL_NWC24_CLEANUP_SOCKET - NI"); } } while (0); | |||
| 113 | break; | |||
| 114 | case IOCTL_NWC24_LOCK_SOCKET: // WiiMenu | |||
| 115 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_LOCK_SOCKET - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 115, "NET_KD_REQ: IOCTL_NWC24_LOCK_SOCKET - NI"); } } while (0); | |||
| 116 | break; | |||
| 117 | ||||
| 118 | case IOCTL_NWC24_UNLOCK_SOCKET: | |||
| 119 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_UNLOCK_SOCKET - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 119, "NET_KD_REQ: IOCTL_NWC24_UNLOCK_SOCKET - NI"); } } while (0); | |||
| 120 | break; | |||
| 121 | ||||
| 122 | case IOCTL_NWC24_REQUEST_REGISTER_USER_ID: | |||
| 123 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 123, "NET_KD_REQ: IOCTL_NWC24_REQUEST_REGISTER_USER_ID"); } } while (0); | |||
| 124 | Memory::Write_U32(0, BufferOut); | |||
| 125 | Memory::Write_U32(0, BufferOut+4); | |||
| 126 | break; | |||
| 127 | ||||
| 128 | case IOCTL_NWC24_REQUEST_GENERATED_USER_ID: // (Input: none, Output: 32 bytes) | |||
| 129 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 129, "NET_KD_REQ: IOCTL_NWC24_REQUEST_GENERATED_USER_ID"); } } while (0); | |||
| 130 | if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_INITIAL) | |||
| 131 | { | |||
| 132 | std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU0x0000000100000002ull) + WII_SETTING"setting.txt"); | |||
| 133 | SettingsHandler gen; | |||
| 134 | std::string area, model; | |||
| 135 | bool _GotSettings = false; | |||
| 136 | ||||
| 137 | if (File::Exists(settings_Filename)) | |||
| 138 | { | |||
| 139 | File::IOFile settingsFileHandle(settings_Filename, "rb"); | |||
| 140 | if (settingsFileHandle.ReadBytes((void*)gen.GetData(), SettingsHandler::SETTINGS_SIZE)) | |||
| 141 | { | |||
| 142 | gen.Decrypt(); | |||
| 143 | area = gen.GetValue("AREA"); | |||
| 144 | model = gen.GetValue("MODEL"); | |||
| 145 | _GotSettings = true; | |||
| 146 | } | |||
| 147 | ||||
| 148 | } | |||
| 149 | if (_GotSettings) | |||
| 150 | { | |||
| 151 | u8 area_code = GetAreaCode(area.c_str()); | |||
| 152 | u8 id_ctr = config.IdGen(); | |||
| 153 | u8 hardware_model = GetHardwareModel(model.c_str()); | |||
| 154 | ||||
| 155 | EcWii &ec = EcWii::GetInstance(); | |||
| 156 | u32 HollywoodID = ec.getNgId(); | |||
| 157 | u64 UserID = 0; | |||
| 158 | ||||
| 159 | s32 ret = NWC24MakeUserID(&UserID, HollywoodID, id_ctr, hardware_model, area_code); | |||
| 160 | config.SetId(UserID); | |||
| 161 | config.IncrementIdGen(); | |||
| 162 | config.SetCreationStage(nwc24_config_t::NWC24_IDCS_GENERATED); | |||
| 163 | config.WriteConfig(); | |||
| 164 | ||||
| 165 | Memory::Write_U32(ret, BufferOut); | |||
| 166 | } | |||
| 167 | else | |||
| 168 | { | |||
| 169 | Memory::Write_U32(WC24_ERR_FATAL, BufferOut); | |||
| 170 | } | |||
| 171 | ||||
| 172 | } | |||
| 173 | else if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_GENERATED) | |||
| 174 | { | |||
| 175 | Memory::Write_U32(WC24_ERR_ID_GENERATED, BufferOut); | |||
| 176 | } | |||
| 177 | else if (config.CreationStage() == nwc24_config_t::NWC24_IDCS_REGISTERED) | |||
| 178 | { | |||
| 179 | Memory::Write_U32(WC24_ERR_ID_REGISTERED, BufferOut); | |||
| 180 | } | |||
| 181 | Memory::Write_U64(config.Id(), BufferOut + 4); | |||
| 182 | Memory::Write_U32(config.CreationStage(), BufferOut + 0xC); | |||
| 183 | break; | |||
| 184 | case IOCTL_NWC24_GET_SCHEDULAR_STAT: | |||
| 185 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULAR_STAT - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 185, "NET_KD_REQ: IOCTL_NWC24_GET_SCHEDULAR_STAT - NI"); } } while (0); | |||
| 186 | break; | |||
| 187 | ||||
| 188 | case IOCTL_NWC24_SAVE_MAIL_NOW: | |||
| 189 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_SAVE_MAIL_NOW - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 189, "NET_KD_REQ: IOCTL_NWC24_SAVE_MAIL_NOW - NI"); } } while (0); | |||
| 190 | break; | |||
| 191 | ||||
| 192 | case IOCTL_NWC24_REQUEST_SHUTDOWN: | |||
| 193 | // if ya set the IOS version to a very high value this happens ... | |||
| 194 | INFO_LOG(WII_IPC_WC24, "NET_KD_REQ: IOCTL_NWC24_REQUEST_SHUTDOWN - NI")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 194, "NET_KD_REQ: IOCTL_NWC24_REQUEST_SHUTDOWN - NI"); } } while (0); | |||
| 195 | break; | |||
| 196 | ||||
| 197 | default: | |||
| 198 | INFO_LOG(WII_IPC_WC24, "/dev/net/kd/request::IOCtl request 0x%x (BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 199, "/dev/net/kd/request::IOCtl request 0x%x (BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , Parameter, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 199 | Parameter, BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_WC24, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 199, "/dev/net/kd/request::IOCtl request 0x%x (BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , Parameter, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0); | |||
| 200 | break; | |||
| 201 | } | |||
| 202 | ||||
| 203 | Memory::Write_U32(ReturnValue, _CommandAddress + 4); | |||
| 204 | return true; | |||
| 205 | } | |||
| 206 | ||||
| 207 | ||||
| 208 | u8 CWII_IPC_HLE_Device_net_kd_request::GetAreaCode( const char * area ) | |||
| 209 | { | |||
| 210 | u32 i; | |||
| 211 | u8 regions_[] = {0,1,2,2,1,3,3,4,5,5,1,2,6,7}; | |||
| 212 | const char* regions[] = {"JPN", "USA", "EUR", "AUS", "BRA", "TWN", "ROC", "KOR", "HKG", "ASI", "LTN", "SAF", "CHN", ""}; | |||
| 213 | for (i=0; i<sizeof(regions)/sizeof(*regions); i++) | |||
| 214 | { | |||
| 215 | if (!strncmp(regions[i], area, 4)) | |||
| 216 | { | |||
| 217 | return regions_[i]; | |||
| 218 | } | |||
| 219 | } | |||
| 220 | ||||
| 221 | return 7; | |||
| 222 | } | |||
| 223 | ||||
| 224 | u8 CWII_IPC_HLE_Device_net_kd_request::GetHardwareModel(const char * model) | |||
| 225 | { | |||
| 226 | u8 mdl; | |||
| 227 | if (!strncmp(model, "RVL", 4)) | |||
| 228 | { | |||
| 229 | mdl = MODEL_RVL; | |||
| 230 | }else if (!strncmp(model, "RVT", 4)) | |||
| 231 | { | |||
| 232 | mdl = MODEL_RVT; | |||
| 233 | }else if (!strncmp(model, "RVV", 4)) | |||
| 234 | { | |||
| 235 | mdl = MODEL_RVV; | |||
| 236 | }else if (!strncmp(model, "RVD", 4)) | |||
| 237 | { | |||
| 238 | mdl = MODEL_RVD; | |||
| 239 | }else | |||
| 240 | { | |||
| 241 | mdl = MODEL_ELSE; | |||
| 242 | } | |||
| 243 | return mdl; | |||
| 244 | } | |||
| 245 | ||||
| 246 | static inline u8 u64_get_byte(u64 value, u8 shift) | |||
| 247 | { | |||
| 248 | return (u8)(value >> (shift*8)); | |||
| 249 | } | |||
| 250 | ||||
| 251 | static inline u64 u64_insert_byte(u64 value, u8 shift, u8 byte) | |||
| 252 | { | |||
| 253 | u64 mask = 0x00000000000000FFULL << (shift*8); | |||
| 254 | u64 inst = (u64)byte << (shift*8); | |||
| 255 | return (value & ~mask) | inst; | |||
| 256 | } | |||
| 257 | ||||
| 258 | s32 CWII_IPC_HLE_Device_net_kd_request::NWC24MakeUserID(u64* nwc24_id, u32 hollywood_id, u16 id_ctr, u8 hardware_model, u8 area_code) | |||
| 259 | { | |||
| 260 | const u8 table2[8] = {0x1, 0x5, 0x0, 0x4, 0x2, 0x3, 0x6, 0x7}; | |||
| 261 | const u8 table1[16] = {0x4, 0xB, 0x7, 0x9, 0xF, 0x1, 0xD, 0x3, 0xC, 0x2, 0x6, 0xE, 0x8, 0x0, 0xA, 0x5}; | |||
| 262 | ||||
| 263 | u64 mix_id = ((u64)area_code<<50) | ((u64)hardware_model<<47) | ((u64)hollywood_id<<15) | ((u64)id_ctr<<10); | |||
| 264 | u64 mix_id_copy1 = mix_id; | |||
| 265 | ||||
| 266 | int ctr = 0; | |||
| 267 | for (ctr = 0; ctr <= 42; ctr++) | |||
| 268 | { | |||
| 269 | u64 value = mix_id >> (52-ctr); | |||
| 270 | if (value & 1) | |||
| 271 | { | |||
| 272 | value = 0x0000000000000635ULL << (42-ctr); | |||
| 273 | mix_id ^= value; | |||
| 274 | } | |||
| 275 | } | |||
| 276 | ||||
| 277 | mix_id = (mix_id_copy1 | (mix_id & 0xFFFFFFFFUL)) ^ 0x0000B3B3B3B3B3B3ULL; | |||
| 278 | mix_id = (mix_id >> 10) | ((mix_id & 0x3FF) << (11+32)); | |||
| 279 | ||||
| 280 | for (ctr = 0; ctr <= 5; ctr++) | |||
| 281 | { | |||
| 282 | u8 ret = u64_get_byte(mix_id, ctr); | |||
| 283 | u8 foobar = ((table1[(ret>>4)&0xF])<<4) | (table1[ret&0xF]); | |||
| 284 | mix_id = u64_insert_byte(mix_id, ctr, foobar & 0xff); | |||
| 285 | } | |||
| 286 | u64 mix_id_copy2 = mix_id; | |||
| 287 | ||||
| 288 | for (ctr = 0; ctr <= 5; ctr++) | |||
| 289 | { | |||
| 290 | u8 ret = u64_get_byte(mix_id_copy2, ctr); | |||
| 291 | mix_id = u64_insert_byte(mix_id, table2[ctr], ret); | |||
| 292 | } | |||
| 293 | ||||
| 294 | mix_id &= 0x001FFFFFFFFFFFFFULL; | |||
| 295 | mix_id = (mix_id << 1) | ((mix_id >> 52) & 1); | |||
| 296 | ||||
| 297 | mix_id ^= 0x00005E5E5E5E5E5EULL; | |||
| 298 | mix_id &= 0x001FFFFFFFFFFFFFULL; | |||
| 299 | ||||
| 300 | *nwc24_id = mix_id; | |||
| 301 | ||||
| 302 | if (mix_id > 9999999999999999ULL) | |||
| 303 | return WC24_ERR_FATAL; | |||
| 304 | ||||
| 305 | return WC24_OK; | |||
| 306 | } | |||
| 307 | ||||
| 308 | // ********************************************************************************** | |||
| 309 | // Handle /dev/net/ncd/manage requests | |||
| 310 | CWII_IPC_HLE_Device_net_ncd_manage::CWII_IPC_HLE_Device_net_ncd_manage(u32 _DeviceID, const std::string& _rDeviceName) | |||
| 311 | : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) | |||
| 312 | { | |||
| 313 | } | |||
| 314 | ||||
| 315 | CWII_IPC_HLE_Device_net_ncd_manage::~CWII_IPC_HLE_Device_net_ncd_manage() | |||
| 316 | { | |||
| 317 | } | |||
| 318 | ||||
| 319 | bool CWII_IPC_HLE_Device_net_ncd_manage::Open(u32 _CommandAddress, u32 _Mode) | |||
| 320 | { | |||
| 321 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: Open")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 321, "NET_NCD_MANAGE: Open"); } } while (0); | |||
| 322 | Memory::Write_U32(GetDeviceID(), _CommandAddress+4); | |||
| 323 | m_Active = true; | |||
| 324 | return true; | |||
| 325 | } | |||
| 326 | ||||
| 327 | bool CWII_IPC_HLE_Device_net_ncd_manage::Close(u32 _CommandAddress, bool _bForce) | |||
| 328 | { | |||
| 329 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: Close")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 329, "NET_NCD_MANAGE: Close"); } } while (0); | |||
| 330 | if (!_bForce) | |||
| 331 | Memory::Write_U32(0, _CommandAddress + 4); | |||
| 332 | m_Active = false; | |||
| 333 | return true; | |||
| 334 | } | |||
| 335 | ||||
| 336 | bool CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress) | |||
| 337 | { | |||
| 338 | u32 return_value = 0; | |||
| 339 | u32 common_result = 0; | |||
| 340 | u32 common_vector = 0; | |||
| 341 | ||||
| 342 | SIOCtlVBuffer CommandBuffer(_CommandAddress); | |||
| 343 | ||||
| 344 | switch (CommandBuffer.Parameter) | |||
| 345 | { | |||
| 346 | case IOCTLV_NCD_LOCKWIRELESSDRIVER: | |||
| 347 | break; | |||
| 348 | case IOCTLV_NCD_UNLOCKWIRELESSDRIVER: | |||
| 349 | //Memory::Read_U32(CommandBuffer.InBuffer.at(0).m_Address); | |||
| 350 | break; | |||
| 351 | ||||
| 352 | case IOCTLV_NCD_GETCONFIG: | |||
| 353 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETCONFIG")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 353, "NET_NCD_MANAGE: IOCTLV_NCD_GETCONFIG"); } } while (0); | |||
| 354 | config.WriteToMem(CommandBuffer.PayloadBuffer.at(0).m_Address); | |||
| 355 | common_vector = 1; | |||
| 356 | break; | |||
| 357 | ||||
| 358 | case IOCTLV_NCD_SETCONFIG: | |||
| 359 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_SETCONFIG")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 359, "NET_NCD_MANAGE: IOCTLV_NCD_SETCONFIG"); } } while (0); | |||
| 360 | config.ReadFromMem(CommandBuffer.InBuffer.at(0).m_Address); | |||
| 361 | break; | |||
| 362 | ||||
| 363 | case IOCTLV_NCD_READCONFIG: | |||
| 364 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 364, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG"); } } while (0 ); | |||
| 365 | config.ReadConfig(); | |||
| 366 | config.WriteToMem(CommandBuffer.PayloadBuffer.at(0).m_Address); | |||
| 367 | common_vector = 1; | |||
| 368 | break; | |||
| 369 | ||||
| 370 | case IOCTLV_NCD_WRITECONFIG: | |||
| 371 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 371, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG"); } } while ( 0); | |||
| 372 | config.ReadFromMem(CommandBuffer.InBuffer.at(0).m_Address); | |||
| 373 | config.WriteConfig(); | |||
| 374 | break; | |||
| 375 | ||||
| 376 | case IOCTLV_NCD_GETLINKSTATUS: | |||
| 377 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETLINKSTATUS")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 377, "NET_NCD_MANAGE: IOCTLV_NCD_GETLINKSTATUS"); } } while (0); | |||
| 378 | // Always connected | |||
| 379 | Memory::Write_U32(netcfg_connection_t::LINK_WIRED, | |||
| 380 | CommandBuffer.PayloadBuffer.at(0).m_Address + 4); | |||
| 381 | break; | |||
| 382 | ||||
| 383 | case IOCTLV_NCD_GETWIRELESSMACADDRESS: | |||
| 384 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 384, "NET_NCD_MANAGE: IOCTLV_NCD_GETWIRELESSMACADDRESS"); } } while (0); | |||
| 385 | ||||
| 386 | if (!SConfig::GetInstance().m_WirelessMac.empty()) | |||
| 387 | { | |||
| 388 | int x = 0; | |||
| 389 | int tmpaddress[6]; | |||
| 390 | for (unsigned int i = 0; i < SConfig::GetInstance().m_WirelessMac.length() && x < 6; i++) | |||
| 391 | { | |||
| 392 | if (SConfig::GetInstance().m_WirelessMac[i] == ':' || SConfig::GetInstance().m_WirelessMac[i] == '-') | |||
| 393 | continue; | |||
| 394 | ||||
| 395 | std::stringstream ss; | |||
| 396 | ss << std::hex << SConfig::GetInstance().m_WirelessMac[i]; | |||
| 397 | if (SConfig::GetInstance().m_WirelessMac[i+1] != ':' && SConfig::GetInstance().m_WirelessMac[i+1] != '-') | |||
| 398 | { | |||
| 399 | ss << std::hex << SConfig::GetInstance().m_WirelessMac[i+1]; | |||
| 400 | i++; | |||
| 401 | } | |||
| 402 | ss >> tmpaddress[x]; | |||
| 403 | x++; | |||
| 404 | } | |||
| 405 | u8 address[6]; | |||
| 406 | for (int i = 0; i < 6;i++) | |||
| 407 | address[i] = tmpaddress[i]; | |||
| 408 | Memory::WriteBigEData(address, CommandBuffer.PayloadBuffer.at(1).m_Address, 4); | |||
| 409 | break; | |||
| 410 | } | |||
| 411 | ||||
| 412 | Memory::WriteBigEData(default_address, | |||
| 413 | CommandBuffer.PayloadBuffer.at(1).m_Address, sizeof(default_address)); | |||
| 414 | break; | |||
| 415 | ||||
| 416 | default: | |||
| 417 | INFO_LOG(WII_IPC_NET, "NET_NCD_MANAGE IOCtlV: %#x", CommandBuffer.Parameter)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 417, "NET_NCD_MANAGE IOCtlV: %#x", CommandBuffer.Parameter) ; } } while (0); | |||
| 418 | break; | |||
| 419 | } | |||
| 420 | ||||
| 421 | Memory::Write_U32(common_result, | |||
| 422 | CommandBuffer.PayloadBuffer.at(common_vector).m_Address); | |||
| 423 | if (common_vector == 1) | |||
| 424 | { | |||
| 425 | Memory::Write_U32(common_result, | |||
| 426 | CommandBuffer.PayloadBuffer.at(common_vector).m_Address + 4); | |||
| 427 | } | |||
| 428 | Memory::Write_U32(return_value, _CommandAddress + 4); | |||
| 429 | return true; | |||
| 430 | } | |||
| 431 | ||||
| 432 | // ********************************************************************************** | |||
| 433 | // Handle /dev/net/wd/command requests | |||
| 434 | CWII_IPC_HLE_Device_net_wd_command::CWII_IPC_HLE_Device_net_wd_command(u32 DeviceID, const std::string& DeviceName) | |||
| 435 | : IWII_IPC_HLE_Device(DeviceID, DeviceName) | |||
| 436 | { | |||
| 437 | } | |||
| 438 | ||||
| 439 | CWII_IPC_HLE_Device_net_wd_command::~CWII_IPC_HLE_Device_net_wd_command() | |||
| 440 | { | |||
| 441 | } | |||
| 442 | ||||
| 443 | bool CWII_IPC_HLE_Device_net_wd_command::Open(u32 CommandAddress, u32 Mode) | |||
| 444 | { | |||
| 445 | INFO_LOG(WII_IPC_NET, "NET_WD_COMMAND: Open")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 445, "NET_WD_COMMAND: Open"); } } while (0); | |||
| 446 | Memory::Write_U32(GetDeviceID(), CommandAddress + 4); | |||
| 447 | m_Active = true; | |||
| 448 | return true; | |||
| 449 | } | |||
| 450 | ||||
| 451 | bool CWII_IPC_HLE_Device_net_wd_command::Close(u32 CommandAddress, bool Force) | |||
| 452 | { | |||
| 453 | INFO_LOG(WII_IPC_NET, "NET_WD_COMMAND: Close")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 453, "NET_WD_COMMAND: Close"); } } while (0); | |||
| 454 | if (!Force) | |||
| 455 | Memory::Write_U32(0, CommandAddress + 4); | |||
| 456 | m_Active = false; | |||
| 457 | return true; | |||
| 458 | } | |||
| 459 | ||||
| 460 | // This is just for debugging / playing around. | |||
| 461 | // There really is no reason to implement wd unless we can bend it such that | |||
| 462 | // we can talk to the DS. | |||
| 463 | #include "StringUtil.h" | |||
| 464 | bool CWII_IPC_HLE_Device_net_wd_command::IOCtlV(u32 CommandAddress) | |||
| 465 | { | |||
| 466 | u32 return_value = 0; | |||
| 467 | ||||
| 468 | SIOCtlVBuffer CommandBuffer(CommandAddress); | |||
| 469 | ||||
| 470 | switch (CommandBuffer.Parameter) | |||
| 471 | { | |||
| 472 | case IOCTLV_WD_SCAN: | |||
| 473 | { | |||
| 474 | // Gives parameters detailing type of scan and what to match | |||
| 475 | // XXX - unused | |||
| 476 | // ScanInfo *scan = (ScanInfo *)Memory::GetPointer(CommandBuffer.InBuffer.at(0).m_Address); | |||
| 477 | ||||
| 478 | u16 *results = (u16 *)Memory::GetPointer(CommandBuffer.PayloadBuffer.at(0).m_Address); | |||
| 479 | // first u16 indicates number of BSSInfo following | |||
| 480 | results[0] = Common::swap16(1); | |||
| 481 | ||||
| 482 | BSSInfo *bss = (BSSInfo *)&results[1]; | |||
| 483 | memset(bss, 0, sizeof(BSSInfo)); | |||
| 484 | ||||
| 485 | bss->length = Common::swap16(sizeof(BSSInfo)); | |||
| 486 | bss->rssi = Common::swap16(0xffff); | |||
| 487 | ||||
| 488 | for (int i = 0; i < BSSID_SIZE; ++i) | |||
| 489 | bss->bssid[i] = i; | |||
| 490 | ||||
| 491 | const char *ssid = "dolphin-emu"; | |||
| 492 | strcpy((char *)bss->ssid, ssid); | |||
| 493 | bss->ssid_length = Common::swap16((u16)strlen(ssid)); | |||
| 494 | ||||
| 495 | bss->channel = Common::swap16(2); | |||
| 496 | } | |||
| 497 | break; | |||
| 498 | ||||
| 499 | case IOCTLV_WD_GET_INFO: | |||
| 500 | { | |||
| 501 | Info *info = (Info *)Memory::GetPointer(CommandBuffer.PayloadBuffer.at(0).m_Address); | |||
| 502 | memset(info, 0, sizeof(Info)); | |||
| 503 | // Probably used to disallow certain channels? | |||
| 504 | memcpy(info->country, "US", 2); | |||
| 505 | info->ntr_allowed_channels = Common::swap16(0xfffe); | |||
| 506 | memcpy(info->mac, default_address, 6); | |||
| 507 | } | |||
| 508 | break; | |||
| 509 | ||||
| 510 | case IOCTLV_WD_GET_MODE: | |||
| 511 | case IOCTLV_WD_SET_LINKSTATE: | |||
| 512 | case IOCTLV_WD_GET_LINKSTATE: | |||
| 513 | case IOCTLV_WD_SET_CONFIG: | |||
| 514 | case IOCTLV_WD_GET_CONFIG: | |||
| 515 | case IOCTLV_WD_CHANGE_BEACON: | |||
| 516 | case IOCTLV_WD_DISASSOC: | |||
| 517 | case IOCTLV_WD_MP_SEND_FRAME: | |||
| 518 | case IOCTLV_WD_SEND_FRAME: | |||
| 519 | case IOCTLV_WD_CALL_WL: | |||
| 520 | case IOCTLV_WD_MEASURE_CHANNEL: | |||
| 521 | case IOCTLV_WD_GET_LASTERROR: | |||
| 522 | case IOCTLV_WD_CHANGE_GAMEINFO: | |||
| 523 | case IOCTLV_WD_CHANGE_VTSF: | |||
| 524 | case IOCTLV_WD_RECV_FRAME: | |||
| 525 | case IOCTLV_WD_RECV_NOTIFICATION: | |||
| 526 | default: | |||
| 527 | INFO_LOG(WII_IPC_NET, "NET_WD_COMMAND IOCtlV %#x in %i out %i",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 528, "NET_WD_COMMAND IOCtlV %#x in %i out %i", CommandBuffer .Parameter, CommandBuffer.NumberInBuffer, CommandBuffer.NumberPayloadBuffer ); } } while (0) | |||
| 528 | CommandBuffer.Parameter, CommandBuffer.NumberInBuffer, CommandBuffer.NumberPayloadBuffer)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 528, "NET_WD_COMMAND IOCtlV %#x in %i out %i", CommandBuffer .Parameter, CommandBuffer.NumberInBuffer, CommandBuffer.NumberPayloadBuffer ); } } while (0); | |||
| 529 | for (u32 i = 0; i < CommandBuffer.NumberInBuffer; ++i) | |||
| 530 | { | |||
| 531 | INFO_LOG(WII_IPC_NET, "in %i addr %x size %i", i,do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 532, "in %i addr %x size %i", i, CommandBuffer.InBuffer.at( i).m_Address, CommandBuffer.InBuffer.at(i).m_Size); } } while (0) | |||
| 532 | CommandBuffer.InBuffer.at(i).m_Address, CommandBuffer.InBuffer.at(i).m_Size)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 532, "in %i addr %x size %i", i, CommandBuffer.InBuffer.at( i).m_Address, CommandBuffer.InBuffer.at(i).m_Size); } } while (0); | |||
| 533 | INFO_LOG(WII_IPC_NET, "%s",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 537, "%s", ArrayToString( Memory::GetPointer(CommandBuffer. InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size ).c_str()); } } while (0) | |||
| 534 | ArrayToString(do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 537, "%s", ArrayToString( Memory::GetPointer(CommandBuffer. InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size ).c_str()); } } while (0) | |||
| 535 | Memory::GetPointer(CommandBuffer.InBuffer.at(i).m_Address),do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 537, "%s", ArrayToString( Memory::GetPointer(CommandBuffer. InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size ).c_str()); } } while (0) | |||
| 536 | CommandBuffer.InBuffer.at(i).m_Size).c_str()do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 537, "%s", ArrayToString( Memory::GetPointer(CommandBuffer. InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size ).c_str()); } } while (0) | |||
| 537 | )do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 537, "%s", ArrayToString( Memory::GetPointer(CommandBuffer. InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size ).c_str()); } } while (0); | |||
| 538 | } | |||
| 539 | for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; ++i) | |||
| 540 | { | |||
| 541 | INFO_LOG(WII_IPC_NET, "out %i addr %x size %i", i,do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 542, "out %i addr %x size %i", i, CommandBuffer.PayloadBuffer .at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size); } } while (0) | |||
| 542 | CommandBuffer.PayloadBuffer.at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 542, "out %i addr %x size %i", i, CommandBuffer.PayloadBuffer .at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size); } } while (0); | |||
| 543 | } | |||
| 544 | break; | |||
| 545 | } | |||
| 546 | ||||
| 547 | Memory::Write_U32(return_value, CommandAddress + 4); | |||
| 548 | return true; | |||
| 549 | } | |||
| 550 | ||||
| 551 | // ********************************************************************************** | |||
| 552 | // Handle /dev/net/ip/top requests | |||
| 553 | CWII_IPC_HLE_Device_net_ip_top::CWII_IPC_HLE_Device_net_ip_top(u32 _DeviceID, const std::string& _rDeviceName) | |||
| 554 | : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) | |||
| 555 | { | |||
| 556 | #ifdef _WIN32 | |||
| 557 | int ret = WSAStartup(MAKEWORD(2,2), &InitData); | |||
| 558 | INFO_LOG(WII_IPC_NET, "WSAStartup: %d", ret)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 558, "WSAStartup: %d", ret); } } while (0); | |||
| 559 | #endif | |||
| 560 | } | |||
| 561 | ||||
| 562 | CWII_IPC_HLE_Device_net_ip_top::~CWII_IPC_HLE_Device_net_ip_top() | |||
| 563 | { | |||
| 564 | #ifdef _WIN32 | |||
| 565 | WSACleanup(); | |||
| 566 | #endif | |||
| 567 | } | |||
| 568 | ||||
| 569 | bool CWII_IPC_HLE_Device_net_ip_top::Open(u32 _CommandAddress, u32 _Mode) | |||
| 570 | { | |||
| 571 | INFO_LOG(WII_IPC_NET, "NET_IP_TOP: Open")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 571, "NET_IP_TOP: Open"); } } while (0); | |||
| 572 | Memory::Write_U32(GetDeviceID(), _CommandAddress+4); | |||
| 573 | m_Active = true; | |||
| 574 | return true; | |||
| 575 | } | |||
| 576 | ||||
| 577 | bool CWII_IPC_HLE_Device_net_ip_top::Close(u32 _CommandAddress, bool _bForce) | |||
| 578 | { | |||
| 579 | INFO_LOG(WII_IPC_NET, "NET_IP_TOP: Close")do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 579, "NET_IP_TOP: Close"); } } while (0); | |||
| 580 | if (!_bForce) | |||
| 581 | Memory::Write_U32(0, _CommandAddress + 4); | |||
| 582 | m_Active = false; | |||
| 583 | return true; | |||
| 584 | } | |||
| 585 | ||||
| 586 | static int inet_pton(const char *src, unsigned char *dst) | |||
| 587 | { | |||
| 588 | int saw_digit, octets; | |||
| 589 | char ch; | |||
| 590 | unsigned char tmp[4], *tp; | |||
| 591 | ||||
| 592 | saw_digit = 0; | |||
| 593 | octets = 0; | |||
| 594 | *(tp = tmp) = 0; | |||
| 595 | while ((ch = *src++) != '\0') { | |||
| 596 | if (ch >= '0' && ch <= '9') { | |||
| 597 | unsigned int newt = (*tp * 10) + (ch - '0'); | |||
| 598 | ||||
| 599 | if (newt > 255) | |||
| 600 | return (0); | |||
| 601 | *tp = newt; | |||
| 602 | if (! saw_digit) { | |||
| 603 | if (++octets > 4) | |||
| 604 | return (0); | |||
| 605 | saw_digit = 1; | |||
| 606 | } | |||
| 607 | } else if (ch == '.' && saw_digit) { | |||
| 608 | if (octets == 4) | |||
| 609 | return (0); | |||
| 610 | *++tp = 0; | |||
| 611 | saw_digit = 0; | |||
| 612 | } else | |||
| 613 | return (0); | |||
| 614 | } | |||
| 615 | if (octets < 4) | |||
| 616 | return (0); | |||
| 617 | memcpy(dst, tmp, 4); | |||
| 618 | return (1); | |||
| 619 | } | |||
| 620 | ||||
| 621 | // Maps SOCKOPT level from native to Wii | |||
| 622 | static unsigned int opt_level_mapping[][2] = { | |||
| 623 | { SOL_SOCKET1, 0xFFFF } | |||
| 624 | }; | |||
| 625 | ||||
| 626 | // Maps SOCKOPT optname from native to Wii | |||
| 627 | static unsigned int opt_name_mapping[][2] = { | |||
| 628 | { SO_REUSEADDR2, 0x4 }, | |||
| 629 | { SO_SNDBUF7, 0x1001 }, | |||
| 630 | { SO_RCVBUF8, 0x1002 }, | |||
| 631 | { SO_ERROR4, 0x1009 } | |||
| 632 | }; | |||
| 633 | ||||
| 634 | bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) | |||
| 635 | { | |||
| 636 | u32 Command = Memory::Read_U32(_CommandAddress + 0x0C); | |||
| 637 | u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); | |||
| 638 | u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); | |||
| 639 | u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); | |||
| 640 | u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); | |||
| 641 | ||||
| 642 | u32 ReturnValue = 0; | |||
| 643 | switch (Command) | |||
| ||||
| 644 | { | |||
| 645 | case IOCTL_SO_STARTUP: | |||
| 646 | { | |||
| 647 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_STARTUP "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 649, "IOCTL_SO_STARTUP " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 648 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 649, "IOCTL_SO_STARTUP " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 649 | BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 649, "IOCTL_SO_STARTUP " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0); | |||
| 650 | break; | |||
| 651 | } | |||
| 652 | case IOCTL_SO_SOCKET: | |||
| 653 | { | |||
| 654 | u32 af = Memory::Read_U32(BufferIn); | |||
| 655 | u32 type = Memory::Read_U32(BufferIn + 0x04); | |||
| 656 | u32 prot = Memory::Read_U32(BufferIn + 0x08); | |||
| 657 | ||||
| 658 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 659 | ReturnValue = sm.newSocket(af, type, prot); | |||
| 660 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_SOCKET "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 662, "IOCTL_SO_SOCKET " "Socket: %08x (%d,%d,%d), BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, af, type, prot, BufferIn, BufferInSize, BufferOut , BufferOutSize); } } while (0) | |||
| 661 | "Socket: %08x (%d,%d,%d), BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 662, "IOCTL_SO_SOCKET " "Socket: %08x (%d,%d,%d), BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, af, type, prot, BufferIn, BufferInSize, BufferOut , BufferOutSize); } } while (0) | |||
| 662 | ReturnValue, af, type, prot, BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 662, "IOCTL_SO_SOCKET " "Socket: %08x (%d,%d,%d), BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, af, type, prot, BufferIn, BufferInSize, BufferOut , BufferOutSize); } } while (0); | |||
| 663 | break; | |||
| 664 | } | |||
| 665 | case IOCTL_SO_ICMPSOCKET: | |||
| 666 | { | |||
| 667 | u32 pf = Memory::Read_U32(BufferIn); | |||
| 668 | ||||
| 669 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 670 | ReturnValue = sm.newSocket(pf, SOCK_RAWSOCK_RAW, IPPROTO_ICMPIPPROTO_ICMP); | |||
| 671 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_ICMPSOCKET(%x) %d", pf, ReturnValue)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 671, "IOCTL_SO_ICMPSOCKET(%x) %d", pf, ReturnValue); } } while (0); | |||
| 672 | break; | |||
| 673 | } | |||
| 674 | case IOCTL_SO_CLOSE: | |||
| 675 | case IOCTL_SO_ICMPCLOSE: | |||
| 676 | { | |||
| 677 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 678 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 679 | ReturnValue = sm.delSocket(fd); | |||
| 680 | DEBUG_LOG(WII_IPC_NET, "%s(%x) %x",do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 682, "%s(%x) %x", Command == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE", fd, ReturnValue); } } while (0) | |||
| 681 | Command == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE",do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 682, "%s(%x) %x", Command == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE", fd, ReturnValue); } } while (0) | |||
| 682 | fd, ReturnValue)do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 682, "%s(%x) %x", Command == IOCTL_SO_ICMPCLOSE ? "IOCTL_SO_ICMPCLOSE" : "IOCTL_SO_CLOSE", fd, ReturnValue); } } while (0); | |||
| 683 | break; | |||
| 684 | } | |||
| 685 | case IOCTL_SO_ACCEPT: | |||
| 686 | case IOCTL_SO_BIND: | |||
| 687 | case IOCTL_SO_CONNECT: | |||
| 688 | case IOCTL_SO_FCNTL: | |||
| 689 | { | |||
| 690 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 691 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 692 | sm.doSock(fd, _CommandAddress, (NET_IOCTL)Command); | |||
| 693 | return false; | |||
| 694 | break; | |||
| 695 | } | |||
| 696 | ///////////////////////////////////////////////////////////// | |||
| 697 | // TODO: Tidy all below // | |||
| 698 | ///////////////////////////////////////////////////////////// | |||
| 699 | case IOCTL_SO_SHUTDOWN: | |||
| 700 | { | |||
| 701 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_SHUTDOWN "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 703, "IOCTL_SO_SHUTDOWN " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 702 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 703, "IOCTL_SO_SHUTDOWN " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 703 | BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 703, "IOCTL_SO_SHUTDOWN " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0); | |||
| 704 | ||||
| 705 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 706 | u32 how = Memory::Read_U32(BufferIn+4); | |||
| 707 | int ret = shutdown(fd, how); | |||
| 708 | ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_SHUTDOWN", false); | |||
| 709 | break; | |||
| 710 | } | |||
| 711 | case IOCTL_SO_LISTEN: | |||
| 712 | { | |||
| 713 | ||||
| 714 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 715 | u32 BACKLOG = Memory::Read_U32(BufferIn + 0x04); | |||
| 716 | u32 ret = listen(fd, BACKLOG); | |||
| 717 | ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_LISTEN", false); | |||
| 718 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_LISTEN = %d "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 720, "IOCTL_SO_LISTEN = %d " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 719 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 720, "IOCTL_SO_LISTEN = %d " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 720 | ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 720, "IOCTL_SO_LISTEN = %d " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , ReturnValue, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0); | |||
| 721 | break; | |||
| 722 | } | |||
| 723 | case IOCTL_SO_GETSOCKOPT: | |||
| 724 | { | |||
| 725 | u32 fd = Memory::Read_U32(BufferOut); | |||
| 726 | u32 level = Memory::Read_U32(BufferOut + 4); | |||
| 727 | u32 optname = Memory::Read_U32(BufferOut + 8); | |||
| 728 | ||||
| 729 | INFO_LOG(WII_IPC_NET,"IOCTL_SO_GETSOCKOPT(%08x, %08x, %08x)"do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 732, "IOCTL_SO_GETSOCKOPT(%08x, %08x, %08x)" "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, level, optname, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 730 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 732, "IOCTL_SO_GETSOCKOPT(%08x, %08x, %08x)" "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, level, optname, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 731 | fd, level, optname,do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 732, "IOCTL_SO_GETSOCKOPT(%08x, %08x, %08x)" "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, level, optname, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0) | |||
| 732 | BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 732, "IOCTL_SO_GETSOCKOPT(%08x, %08x, %08x)" "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, level, optname, BufferIn, BufferInSize, BufferOut, BufferOutSize ); } } while (0); | |||
| 733 | ||||
| 734 | // Do the level/optname translation | |||
| 735 | int nat_level = -1, nat_optname = -1; | |||
| 736 | ||||
| 737 | for (unsigned int i = 0; i < sizeof (opt_level_mapping) / sizeof (opt_level_mapping[0]); ++i) | |||
| 738 | if (level == opt_level_mapping[i][1]) | |||
| 739 | nat_level = opt_level_mapping[i][0]; | |||
| 740 | ||||
| 741 | for (unsigned int i = 0; i < sizeof (opt_name_mapping) / sizeof (opt_name_mapping[0]); ++i) | |||
| 742 | if (optname == opt_name_mapping[i][1]) | |||
| 743 | nat_optname = opt_name_mapping[i][0]; | |||
| 744 | ||||
| 745 | u8 optval[20]; | |||
| 746 | u32 optlen = 4; | |||
| 747 | ||||
| 748 | int ret = getsockopt (fd, nat_level, nat_optname, (char *) &optval, (socklen_t*)&optlen); | |||
| 749 | ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_GETSOCKOPT", false); | |||
| 750 | ||||
| 751 | ||||
| 752 | Memory::Write_U32(optlen, BufferOut + 0xC); | |||
| 753 | Memory::WriteBigEData((u8 *) optval, BufferOut + 0x10, optlen); | |||
| 754 | ||||
| 755 | if (optname == SO_ERROR4) | |||
| 756 | { | |||
| 757 | s32 last_error = WiiSockMan::getInstance().getLastNetError(); | |||
| 758 | ||||
| 759 | Memory::Write_U32(sizeof(s32), BufferOut + 0xC); | |||
| 760 | Memory::Write_U32(last_error, BufferOut + 0x10); | |||
| 761 | } | |||
| 762 | break; | |||
| 763 | } | |||
| 764 | ||||
| 765 | case IOCTL_SO_SETSOCKOPT: | |||
| 766 | { | |||
| 767 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 768 | u32 level = Memory::Read_U32(BufferIn + 4); | |||
| 769 | u32 optname = Memory::Read_U32(BufferIn + 8); | |||
| 770 | u32 optlen = Memory::Read_U32(BufferIn + 0xc); | |||
| 771 | u8 optval[20]; | |||
| 772 | Memory::ReadBigEData(optval, BufferIn + 0x10, optlen); | |||
| 773 | ||||
| 774 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 777, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" , fd, level, optname, optlen, BufferIn, BufferInSize, BufferOut , BufferOutSize, optval[0], optval[1], optval[2], optval[3], optval [4], optval[5], optval[6], optval[7], optval[8], optval[9], optval [10], optval[11], optval[12], optval[13], optval[14], optval[ 15], optval[16], optval[17], optval[18], optval[19]); } } while (0) | |||
| 775 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)"do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 777, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" , fd, level, optname, optlen, BufferIn, BufferInSize, BufferOut , BufferOutSize, optval[0], optval[1], optval[2], optval[3], optval [4], optval[5], optval[6], optval[7], optval[8], optval[9], optval [10], optval[11], optval[12], optval[13], optval[14], optval[ 15], optval[16], optval[17], optval[18], optval[19]); } } while (0) | |||
| 776 | "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 777, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" , fd, level, optname, optlen, BufferIn, BufferInSize, BufferOut , BufferOutSize, optval[0], optval[1], optval[2], optval[3], optval [4], optval[5], optval[6], optval[7], optval[8], optval[9], optval [10], optval[11], optval[12], optval[13], optval[14], optval[ 15], optval[16], optval[17], optval[18], optval[19]); } } while (0) | |||
| 777 | fd, level, optname, optlen, BufferIn, BufferInSize, BufferOut, BufferOutSize, optval[0], optval[1], optval[2], optval[3], optval[4], optval[5], optval[6], optval[7], optval[8], optval[9], optval[10], optval[11], optval[12], optval[13], optval[14], optval[15], optval[16], optval[17], optval[18], optval[19])do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 777, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" , fd, level, optname, optlen, BufferIn, BufferInSize, BufferOut , BufferOutSize, optval[0], optval[1], optval[2], optval[3], optval [4], optval[5], optval[6], optval[7], optval[8], optval[9], optval [10], optval[11], optval[12], optval[13], optval[14], optval[ 15], optval[16], optval[17], optval[18], optval[19]); } } while (0); | |||
| 778 | ||||
| 779 | //TODO: bug booto about this, 0x2005 most likely timeout related, default value on wii is , 0x2001 is most likely tcpnodelay | |||
| 780 | if (level == 6 && (optname == 0x2005 || optname == 0x2001)){ | |||
| 781 | ReturnValue = 0; | |||
| 782 | break; | |||
| 783 | } | |||
| 784 | ||||
| 785 | // Do the level/optname translation | |||
| 786 | int nat_level = -1, nat_optname = -1; | |||
| 787 | ||||
| 788 | for (unsigned int i = 0; i < sizeof (opt_level_mapping) / sizeof (opt_level_mapping[0]); ++i) | |||
| 789 | if (level == opt_level_mapping[i][1]) | |||
| 790 | nat_level = opt_level_mapping[i][0]; | |||
| 791 | ||||
| 792 | for (unsigned int i = 0; i < sizeof (opt_name_mapping) / sizeof (opt_name_mapping[0]); ++i) | |||
| 793 | if (optname == opt_name_mapping[i][1]) | |||
| 794 | nat_optname = opt_name_mapping[i][0]; | |||
| 795 | ||||
| 796 | if (nat_level == -1 || nat_optname == -1) | |||
| 797 | { | |||
| 798 | INFO_LOG(WII_IPC_NET, "SO_SETSOCKOPT: unknown level %d or optname %d", level, optname)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 798, "SO_SETSOCKOPT: unknown level %d or optname %d", level , optname); } } while (0); | |||
| 799 | ||||
| 800 | // Default to the given level/optname. They match on Windows... | |||
| 801 | nat_level = level; | |||
| 802 | nat_optname = optname; | |||
| 803 | } | |||
| 804 | ||||
| 805 | int ret = setsockopt(fd, nat_level, nat_optname, (char*)optval, optlen); | |||
| 806 | ReturnValue = WiiSockMan::getNetErrorCode(ret, "SO_SETSOCKOPT", false); | |||
| 807 | break; | |||
| 808 | } | |||
| 809 | case IOCTL_SO_GETSOCKNAME: | |||
| 810 | { | |||
| 811 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 812 | ||||
| 813 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETSOCKNAME "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 815, "IOCTL_SO_GETSOCKNAME " "Socket: %08X, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 814 | "Socket: %08X, BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 815, "IOCTL_SO_GETSOCKNAME " "Socket: %08X, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 815 | fd, BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 815, "IOCTL_SO_GETSOCKNAME " "Socket: %08X, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , fd, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0); | |||
| 816 | ||||
| 817 | sockaddr sa; | |||
| 818 | socklen_t sa_len; | |||
| 819 | sa_len = sizeof(sa); | |||
| 820 | int ret = getsockname(fd, &sa, &sa_len); | |||
| 821 | ||||
| 822 | Memory::Write_U8(BufferOutSize, BufferOut); | |||
| 823 | Memory::Write_U8(sa.sa_family & 0xFF, BufferOut + 1); | |||
| 824 | Memory::WriteBigEData((u8*)&sa.sa_data, BufferOut + 2, BufferOutSize - 2); | |||
| 825 | ReturnValue = ret; | |||
| 826 | break; | |||
| 827 | } | |||
| 828 | case IOCTL_SO_GETPEERNAME: | |||
| 829 | { | |||
| 830 | u32 fd = Memory::Read_U32(BufferIn); | |||
| 831 | ||||
| 832 | sockaddr sa; | |||
| 833 | socklen_t sa_len; | |||
| 834 | sa_len = sizeof(sa); | |||
| 835 | ||||
| 836 | int ret = getpeername(fd, &sa, &sa_len); | |||
| 837 | ||||
| 838 | Memory::Write_U8(BufferOutSize, BufferOut); | |||
| 839 | Memory::Write_U8(AF_INET2, BufferOut + 1); | |||
| 840 | Memory::WriteBigEData((u8*)&sa.sa_data, BufferOut + 2, BufferOutSize - 2); | |||
| 841 | ||||
| 842 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETPEERNAME(%x)", fd)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 842, "IOCTL_SO_GETPEERNAME(%x)", fd); } } while (0); | |||
| 843 | ||||
| 844 | ReturnValue = ret; | |||
| 845 | break; | |||
| 846 | } | |||
| 847 | ||||
| 848 | case IOCTL_SO_GETHOSTID: | |||
| 849 | { | |||
| 850 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETHOSTID "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 852, "IOCTL_SO_GETHOSTID " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 851 | "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 852, "IOCTL_SO_GETHOSTID " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 852 | BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 852, "IOCTL_SO_GETHOSTID " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0); | |||
| 853 | ReturnValue = 192 << 24 | 168 << 16 | 1 << 8 | 150; | |||
| 854 | break; | |||
| 855 | } | |||
| 856 | ||||
| 857 | case IOCTL_SO_INETATON: | |||
| 858 | { | |||
| 859 | struct hostent *remoteHost = gethostbyname((char*)Memory::GetPointer(BufferIn)); | |||
| 860 | ||||
| 861 | Memory::Write_U32(Common::swap32(*(u32 *)remoteHost->h_addr_list[0]), BufferOut); | |||
| 862 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 864, "IOCTL_SO_INETATON = %d " "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X" ,remoteHost->h_addr_list[0] == 0 ? -1 : 0, (char*)Memory:: GetPointer(BufferIn), BufferIn, BufferInSize, BufferOut, BufferOutSize , Common::swap32(*(u32 *)remoteHost->h_addr_list[0])); } } while (0) | |||
| 863 | "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X",remoteHost->h_addr_list[0] == 0 ? -1 : 0,do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 864, "IOCTL_SO_INETATON = %d " "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X" ,remoteHost->h_addr_list[0] == 0 ? -1 : 0, (char*)Memory:: GetPointer(BufferIn), BufferIn, BufferInSize, BufferOut, BufferOutSize , Common::swap32(*(u32 *)remoteHost->h_addr_list[0])); } } while (0) | |||
| 864 | (char*)Memory::GetPointer(BufferIn), BufferIn, BufferInSize, BufferOut, BufferOutSize, Common::swap32(*(u32 *)remoteHost->h_addr_list[0]))do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 864, "IOCTL_SO_INETATON = %d " "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X" ,remoteHost->h_addr_list[0] == 0 ? -1 : 0, (char*)Memory:: GetPointer(BufferIn), BufferIn, BufferInSize, BufferOut, BufferOutSize , Common::swap32(*(u32 *)remoteHost->h_addr_list[0])); } } while (0); | |||
| 865 | ReturnValue = remoteHost->h_addr_list[0] == 0 ? 0 : 1; | |||
| 866 | break; | |||
| 867 | } | |||
| 868 | ||||
| 869 | case IOCTL_SO_INETPTON: | |||
| 870 | { | |||
| 871 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETPTON "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 872, "IOCTL_SO_INETPTON " "(Translating: %s)", Memory::GetPointer (BufferIn)); } } while (0) | |||
| 872 | "(Translating: %s)", Memory::GetPointer(BufferIn))do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 872, "IOCTL_SO_INETPTON " "(Translating: %s)", Memory::GetPointer (BufferIn)); } } while (0); | |||
| 873 | ReturnValue = inet_pton((char*)Memory::GetPointer(BufferIn), Memory::GetPointer(BufferOut+4)); | |||
| 874 | break; | |||
| 875 | } | |||
| 876 | ||||
| 877 | case IOCTL_SO_INETNTOP: | |||
| 878 | { | |||
| 879 | //u32 af = Memory::Read_U32(BufferIn); | |||
| 880 | //u32 validAddress = Memory::Read_U32(BufferIn + 4); | |||
| 881 | //u32 src = Memory::Read_U32(BufferIn + 8); | |||
| 882 | char ip_s[16]; | |||
| 883 | sprintf(ip_s, "%i.%i.%i.%i", | |||
| 884 | Memory::Read_U8(BufferIn + 8), | |||
| 885 | Memory::Read_U8(BufferIn + 8 + 1), | |||
| 886 | Memory::Read_U8(BufferIn + 8 + 2), | |||
| 887 | Memory::Read_U8(BufferIn + 8 + 3) | |||
| 888 | ); | |||
| 889 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETNTOP %s", ip_s)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 889, "IOCTL_SO_INETNTOP %s", ip_s); } } while (0); | |||
| 890 | memset(Memory::GetPointer(BufferOut), 0, BufferOutSize); | |||
| 891 | memcpy(Memory::GetPointer(BufferOut), ip_s, strlen(ip_s)); | |||
| 892 | break; | |||
| 893 | } | |||
| 894 | ||||
| 895 | case IOCTL_SO_POLL: | |||
| 896 | { | |||
| 897 | // Map Wii/native poll events types | |||
| 898 | unsigned int mapping[][2] = { | |||
| 899 | { POLLIN0x001, 0x0001 }, | |||
| 900 | { POLLOUT0x004, 0x0008 }, | |||
| 901 | { POLLHUP0x010, 0x0040 }, | |||
| 902 | }; | |||
| 903 | ||||
| 904 | u32 unknown = Memory::Read_U32(BufferIn); | |||
| 905 | u32 timeout = Memory::Read_U32(BufferIn + 4); | |||
| 906 | ||||
| 907 | int nfds = BufferOutSize / 0xc; | |||
| 908 | if (nfds == 0) | |||
| 909 | ERROR_LOG(WII_IPC_NET, "Hidden POLL")do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 909, "Hidden POLL"); } } while (0); | |||
| 910 | ||||
| 911 | pollfd_t* ufds = (pollfd_t *)malloc(sizeof(pollfd_t) * nfds); | |||
| ||||
| 912 | if (ufds == NULL__null) | |||
| 913 | { | |||
| 914 | ReturnValue = -1; | |||
| 915 | break; | |||
| 916 | } | |||
| 917 | ||||
| 918 | for (int i = 0; i < nfds; i++) | |||
| 919 | { | |||
| 920 | ufds[i].fd = Memory::Read_U32(BufferOut + 0xc*i); //fd | |||
| 921 | int events = Memory::Read_U32(BufferOut + 0xc*i + 4); //events | |||
| 922 | ufds[i].revents = Memory::Read_U32(BufferOut + 0xc*i + 8); //revents | |||
| 923 | ||||
| 924 | // Translate Wii to native events | |||
| 925 | int unhandled_events = events; | |||
| 926 | ufds[i].events = 0; | |||
| 927 | for (unsigned int j = 0; j < sizeof (mapping) / sizeof (mapping[0]); ++j) | |||
| 928 | { | |||
| 929 | if (events & mapping[j][1]) | |||
| 930 | ufds[i].events |= mapping[j][0]; | |||
| 931 | unhandled_events &= ~mapping[j][1]; | |||
| 932 | } | |||
| 933 | ||||
| 934 | DEBUG_LOG(WII_IPC_NET, "IOCTL_SO_POLL(%d) "do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 938, "IOCTL_SO_POLL(%d) " "Sock: %08x, Unknown: %08x, Events: %08x, " "NativeEvents: %08x", i, ufds[i].fd, unknown, events, ufds[i ].events); } } while (0) | |||
| 935 | "Sock: %08x, Unknown: %08x, Events: %08x, "do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 938, "IOCTL_SO_POLL(%d) " "Sock: %08x, Unknown: %08x, Events: %08x, " "NativeEvents: %08x", i, ufds[i].fd, unknown, events, ufds[i ].events); } } while (0) | |||
| 936 | "NativeEvents: %08x",do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 938, "IOCTL_SO_POLL(%d) " "Sock: %08x, Unknown: %08x, Events: %08x, " "NativeEvents: %08x", i, ufds[i].fd, unknown, events, ufds[i ].events); } } while (0) | |||
| 937 | i, ufds[i].fd, unknown, events, ufds[i].eventsdo { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 938, "IOCTL_SO_POLL(%d) " "Sock: %08x, Unknown: %08x, Events: %08x, " "NativeEvents: %08x", i, ufds[i].fd, unknown, events, ufds[i ].events); } } while (0) | |||
| 938 | )do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 938, "IOCTL_SO_POLL(%d) " "Sock: %08x, Unknown: %08x, Events: %08x, " "NativeEvents: %08x", i, ufds[i].fd, unknown, events, ufds[i ].events); } } while (0); | |||
| 939 | ||||
| 940 | if (unhandled_events) | |||
| 941 | ERROR_LOG(WII_IPC_NET, "SO_POLL: unhandled Wii event types: %04x", unhandled_events)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 941, "SO_POLL: unhandled Wii event types: %04x", unhandled_events ); } } while (0); | |||
| 942 | } | |||
| 943 | ||||
| 944 | int ret = poll(ufds, nfds, timeout); | |||
| 945 | ret = WiiSockMan::getNetErrorCode(ret, "SO_POLL", false); | |||
| 946 | ||||
| 947 | for (int i = 0; i<nfds; i++) | |||
| 948 | { | |||
| 949 | ||||
| 950 | // Translate native to Wii events | |||
| 951 | int revents = 0; | |||
| 952 | for (unsigned int j = 0; j < sizeof (mapping) / sizeof (mapping[0]); ++j) | |||
| 953 | { | |||
| 954 | if (ufds[i].revents & mapping[j][0]) | |||
| 955 | revents |= mapping[j][1]; | |||
| 956 | } | |||
| 957 | ||||
| 958 | // No need to change fd or events as they are input only. | |||
| 959 | //Memory::Write_U32(ufds[i].fd, BufferOut + 0xc*i); //fd | |||
| 960 | //Memory::Write_U32(events, BufferOut + 0xc*i + 4); //events | |||
| 961 | Memory::Write_U32(revents, BufferOut + 0xc*i + 8); //revents | |||
| 962 | ||||
| 963 | DEBUG_LOG(WII_IPC_NET, "IOCTL_SO_POLL socket %d revents %08X events %08X", i, revents, ufds[i].events)do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 963, "IOCTL_SO_POLL socket %d revents %08X events %08X", i, revents, ufds[i].events); } } while (0); | |||
| 964 | } | |||
| 965 | free(ufds); | |||
| 966 | ||||
| 967 | ReturnValue = ret; | |||
| 968 | break; | |||
| 969 | } | |||
| 970 | ||||
| 971 | case IOCTL_SO_GETHOSTBYNAME: | |||
| 972 | { | |||
| 973 | hostent *remoteHost = gethostbyname((char*)Memory::GetPointer(BufferIn)); | |||
| 974 | ||||
| 975 | INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETHOSTBYNAME "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 977, "IOCTL_SO_GETHOSTBYNAME " "Address: %s, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , (char*)Memory::GetPointer(BufferIn), BufferIn, BufferInSize , BufferOut, BufferOutSize); } } while (0) | |||
| 976 | "Address: %s, BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 977, "IOCTL_SO_GETHOSTBYNAME " "Address: %s, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , (char*)Memory::GetPointer(BufferIn), BufferIn, BufferInSize , BufferOut, BufferOutSize); } } while (0) | |||
| 977 | (char*)Memory::GetPointer(BufferIn), BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 977, "IOCTL_SO_GETHOSTBYNAME " "Address: %s, BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , (char*)Memory::GetPointer(BufferIn), BufferIn, BufferInSize , BufferOut, BufferOutSize); } } while (0); | |||
| 978 | ||||
| 979 | if (remoteHost) | |||
| 980 | { | |||
| 981 | for (int i = 0; remoteHost->h_aliases[i]; ++i) | |||
| 982 | { | |||
| 983 | INFO_LOG(WII_IPC_NET, "alias%i:%s", i, remoteHost->h_aliases[i])do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 983, "alias%i:%s", i, remoteHost->h_aliases[i]); } } while (0); | |||
| 984 | } | |||
| 985 | ||||
| 986 | for (int i = 0; remoteHost->h_addr_list[i]; ++i) | |||
| 987 | { | |||
| 988 | u32 ip = Common::swap32(*(u32*)(remoteHost->h_addr_list[i])); | |||
| 989 | char ip_s[16]; | |||
| 990 | sprintf(ip_s, "%i.%i.%i.%i", | |||
| 991 | ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); | |||
| 992 | DEBUG_LOG(WII_IPC_NET, "addr%i:%s", i, ip_s)do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 992, "addr%i:%s", i, ip_s); } } while (0); | |||
| 993 | } | |||
| 994 | ||||
| 995 | Memory::Memset(BufferOut, 0, BufferOutSize); | |||
| 996 | u32 wii_addr = BufferOut + 4 * 3 + 2 * 2; | |||
| 997 | ||||
| 998 | u32 name_length = (u32)strlen(remoteHost->h_name) + 1; | |||
| 999 | Memory::WriteBigEData((const u8 *)remoteHost->h_name, wii_addr, name_length); | |||
| 1000 | Memory::Write_U32(wii_addr, BufferOut); | |||
| 1001 | wii_addr += (name_length + 4) & ~3; | |||
| 1002 | ||||
| 1003 | // aliases - empty | |||
| 1004 | Memory::Write_U32(wii_addr, BufferOut + 4); | |||
| 1005 | Memory::Write_U32(wii_addr + sizeof(u32), wii_addr); | |||
| 1006 | wii_addr += sizeof(u32); | |||
| 1007 | Memory::Write_U32((u32)NULL__null, wii_addr); | |||
| 1008 | wii_addr += sizeof(u32); | |||
| 1009 | ||||
| 1010 | // hardcode to ipv4 | |||
| 1011 | _dbg_assert_msg_(WII_IPC_NET,{} | |||
| 1012 | remoteHost->h_addrtype == AF_INET && remoteHost->h_length == sizeof(u32),{} | |||
| 1013 | "returned host info is not IPv4"){}; | |||
| 1014 | Memory::Write_U16(AF_INET2, BufferOut + 8); | |||
| 1015 | Memory::Write_U16(sizeof(u32), BufferOut + 10); | |||
| 1016 | ||||
| 1017 | // addrlist - probably only really need to return 1 anyways... | |||
| 1018 | Memory::Write_U32(wii_addr, BufferOut + 12); | |||
| 1019 | u32 num_addr = 0; | |||
| 1020 | while (remoteHost->h_addr_list[num_addr]) | |||
| 1021 | num_addr++; | |||
| 1022 | for (u32 i = 0; i < num_addr; ++i) | |||
| 1023 | { | |||
| 1024 | Memory::Write_U32(wii_addr + sizeof(u32) * (num_addr + 1), wii_addr); | |||
| 1025 | wii_addr += sizeof(u32); | |||
| 1026 | } | |||
| 1027 | // NULL terminated list | |||
| 1028 | Memory::Write_U32((u32)NULL__null, wii_addr); | |||
| 1029 | wii_addr += sizeof(u32); | |||
| 1030 | // The actual IPs | |||
| 1031 | for (int i = 0; remoteHost->h_addr_list[i]; i++) | |||
| 1032 | { | |||
| 1033 | Memory::Write_U32_Swap(*(u32*)(remoteHost->h_addr_list[i]), wii_addr); | |||
| 1034 | wii_addr += sizeof(u32); | |||
| 1035 | } | |||
| 1036 | ||||
| 1037 | //ERROR_LOG(WII_IPC_NET, "\n%s", | |||
| 1038 | // ArrayToString(Memory::GetPointer(BufferOut), BufferOutSize, 16).c_str()); | |||
| 1039 | ReturnValue = 0; | |||
| 1040 | } | |||
| 1041 | else | |||
| 1042 | { | |||
| 1043 | ReturnValue = -1; | |||
| 1044 | } | |||
| 1045 | ||||
| 1046 | break; | |||
| 1047 | } | |||
| 1048 | ||||
| 1049 | case IOCTL_SO_ICMPCANCEL: | |||
| 1050 | ERROR_LOG(WII_IPC_NET, "IOCTL_SO_ICMPCANCEL")do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1050, "IOCTL_SO_ICMPCANCEL"); } } while (0); | |||
| 1051 | goto default_; | |||
| 1052 | default: | |||
| 1053 | INFO_LOG(WII_IPC_NET,"0x%x "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1055, "0x%x " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , Command, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 1054 | "BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1055, "0x%x " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , Command, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0) | |||
| 1055 | Command, BufferIn, BufferInSize, BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1055, "0x%x " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , Command, BufferIn, BufferInSize, BufferOut, BufferOutSize); } } while (0); | |||
| 1056 | default_: | |||
| 1057 | if (BufferInSize) | |||
| 1058 | { | |||
| 1059 | ERROR_LOG(WII_IPC_NET, "in addr %x size %x", BufferIn, BufferInSize)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1059, "in addr %x size %x", BufferIn, BufferInSize); } } while (0); | |||
| 1060 | ERROR_LOG(WII_IPC_NET, "\n%s",do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1062, "\n%s", ArrayToString(Memory::GetPointer(BufferIn), BufferInSize , 4).c_str()); } } while (0) | |||
| 1061 | ArrayToString(Memory::GetPointer(BufferIn), BufferInSize, 4).c_str()do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1062, "\n%s", ArrayToString(Memory::GetPointer(BufferIn), BufferInSize , 4).c_str()); } } while (0) | |||
| 1062 | )do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1062, "\n%s", ArrayToString(Memory::GetPointer(BufferIn), BufferInSize , 4).c_str()); } } while (0); | |||
| 1063 | } | |||
| 1064 | ||||
| 1065 | if (BufferOutSize) | |||
| 1066 | { | |||
| 1067 | ERROR_LOG(WII_IPC_NET, "out addr %x size %x", BufferOut, BufferOutSize)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1067, "out addr %x size %x", BufferOut, BufferOutSize); } } while (0); | |||
| 1068 | } | |||
| 1069 | break; | |||
| 1070 | } | |||
| 1071 | ||||
| 1072 | Memory::Write_U32(ReturnValue, _CommandAddress + 0x4); | |||
| 1073 | ||||
| 1074 | return true; | |||
| 1075 | } | |||
| 1076 | ||||
| 1077 | ||||
| 1078 | bool CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress) | |||
| 1079 | { | |||
| 1080 | SIOCtlVBuffer CommandBuffer(CommandAddress); | |||
| 1081 | ||||
| 1082 | s32 ReturnValue = 0; | |||
| 1083 | ||||
| 1084 | ||||
| 1085 | u32 _BufferIn = 0, _BufferIn2 = 0, _BufferIn3 = 0; | |||
| 1086 | u32 BufferInSize = 0, BufferInSize2 = 0, BufferInSize3 = 0; | |||
| 1087 | ||||
| 1088 | u32 _BufferOut = 0, _BufferOut2 = 0; | |||
| 1089 | u32 BufferOutSize = 0; | |||
| 1090 | ||||
| 1091 | if (CommandBuffer.InBuffer.size() > 0) | |||
| 1092 | { | |||
| 1093 | _BufferIn = CommandBuffer.InBuffer.at(0).m_Address; | |||
| 1094 | BufferInSize = CommandBuffer.InBuffer.at(0).m_Size; | |||
| 1095 | } | |||
| 1096 | if (CommandBuffer.InBuffer.size() > 1) | |||
| 1097 | { | |||
| 1098 | _BufferIn2 = CommandBuffer.InBuffer.at(1).m_Address; | |||
| 1099 | BufferInSize2 = CommandBuffer.InBuffer.at(1).m_Size; | |||
| 1100 | } | |||
| 1101 | if (CommandBuffer.InBuffer.size() > 2) | |||
| 1102 | { | |||
| 1103 | _BufferIn3 = CommandBuffer.InBuffer.at(2).m_Address; | |||
| 1104 | BufferInSize3 = CommandBuffer.InBuffer.at(2).m_Size; | |||
| 1105 | } | |||
| 1106 | ||||
| 1107 | if (CommandBuffer.PayloadBuffer.size() > 0) | |||
| 1108 | { | |||
| 1109 | _BufferOut = CommandBuffer.PayloadBuffer.at(0).m_Address; | |||
| 1110 | BufferOutSize = CommandBuffer.PayloadBuffer.at(0).m_Size; | |||
| 1111 | } | |||
| 1112 | if (CommandBuffer.PayloadBuffer.size() > 1) | |||
| 1113 | { | |||
| 1114 | _BufferOut2 = CommandBuffer.PayloadBuffer.at(1).m_Address; | |||
| 1115 | } | |||
| 1116 | ||||
| 1117 | u32 param = 0, param2 = 0, param3, param4, param5 = 0; | |||
| 1118 | ||||
| 1119 | switch (CommandBuffer.Parameter) | |||
| 1120 | { | |||
| 1121 | case IOCTLV_SO_GETINTERFACEOPT: | |||
| 1122 | { | |||
| 1123 | param = Memory::Read_U32(_BufferIn); | |||
| 1124 | param2 = Memory::Read_U32(_BufferIn+4); | |||
| 1125 | param3 = Memory::Read_U32(_BufferOut); | |||
| 1126 | param4 = Memory::Read_U32(_BufferOut2); | |||
| 1127 | if (BufferOutSize >= 8) | |||
| 1128 | { | |||
| 1129 | param5 = Memory::Read_U32(_BufferOut+4); | |||
| 1130 | } | |||
| 1131 | ||||
| 1132 | INFO_LOG(WII_IPC_NET,"IOCTLV_SO_GETINTERFACEOPT(%08X, %08X, %X, %X, %X) "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1135, "IOCTLV_SO_GETINTERFACEOPT(%08X, %08X, %X, %X, %X) " "BufferIn: (%08x, %i), BufferIn2: (%08x, %i) " , param, param2, param3, param4, param5, _BufferIn, BufferInSize , _BufferIn2, BufferInSize2); } } while (0) | |||
| 1133 | "BufferIn: (%08x, %i), BufferIn2: (%08x, %i) ",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1135, "IOCTLV_SO_GETINTERFACEOPT(%08X, %08X, %X, %X, %X) " "BufferIn: (%08x, %i), BufferIn2: (%08x, %i) " , param, param2, param3, param4, param5, _BufferIn, BufferInSize , _BufferIn2, BufferInSize2); } } while (0) | |||
| 1134 | param, param2, param3, param4, param5,do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1135, "IOCTLV_SO_GETINTERFACEOPT(%08X, %08X, %X, %X, %X) " "BufferIn: (%08x, %i), BufferIn2: (%08x, %i) " , param, param2, param3, param4, param5, _BufferIn, BufferInSize , _BufferIn2, BufferInSize2); } } while (0) | |||
| 1135 | _BufferIn, BufferInSize, _BufferIn2, BufferInSize2)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1135, "IOCTLV_SO_GETINTERFACEOPT(%08X, %08X, %X, %X, %X) " "BufferIn: (%08x, %i), BufferIn2: (%08x, %i) " , param, param2, param3, param4, param5, _BufferIn, BufferInSize , _BufferIn2, BufferInSize2); } } while (0); | |||
| 1136 | ||||
| 1137 | switch (param2) | |||
| 1138 | { | |||
| 1139 | case 0xb003: // dns server table | |||
| 1140 | { | |||
| 1141 | u32 address = 0; | |||
| 1142 | #ifdef _WIN32 | |||
| 1143 | PIP_ADAPTER_ADDRESSES AdapterAddresses = NULL__null; | |||
| 1144 | ULONG OutBufferLength = 0; | |||
| 1145 | ULONG RetVal = 0, i; | |||
| 1146 | for (i = 0; i < 5; i++) | |||
| 1147 | { | |||
| 1148 | RetVal = GetAdaptersAddresses( | |||
| 1149 | AF_INET2, | |||
| 1150 | 0, | |||
| 1151 | NULL__null, | |||
| 1152 | AdapterAddresses, | |||
| 1153 | &OutBufferLength); | |||
| 1154 | ||||
| 1155 | if (RetVal != ERROR_BUFFER_OVERFLOW) { | |||
| 1156 | break; | |||
| 1157 | } | |||
| 1158 | ||||
| 1159 | if (AdapterAddresses != NULL__null) { | |||
| 1160 | FREE(AdapterAddresses); | |||
| 1161 | } | |||
| 1162 | ||||
| 1163 | AdapterAddresses = (PIP_ADAPTER_ADDRESSES)MALLOC(OutBufferLength); | |||
| 1164 | if (AdapterAddresses == NULL__null) { | |||
| 1165 | RetVal = GetLastError(); | |||
| 1166 | break; | |||
| 1167 | } | |||
| 1168 | } | |||
| 1169 | if (RetVal == NO_ERROR) | |||
| 1170 | { | |||
| 1171 | unsigned long dwBestIfIndex = 0; | |||
| 1172 | IPAddr dwDestAddr = (IPAddr)0x08080808; | |||
| 1173 | // If successful, output some information from the data we received | |||
| 1174 | PIP_ADAPTER_ADDRESSES AdapterList = AdapterAddresses; | |||
| 1175 | if (GetBestInterface(dwDestAddr,&dwBestIfIndex) == NO_ERROR) | |||
| 1176 | { | |||
| 1177 | while (AdapterList) | |||
| 1178 | { | |||
| 1179 | if (AdapterList->IfIndex == dwBestIfIndex && | |||
| 1180 | AdapterList->FirstDnsServerAddress && | |||
| 1181 | AdapterList->OperStatus == IfOperStatusUp) | |||
| 1182 | { | |||
| 1183 | INFO_LOG(WII_IPC_NET, "Name of valid interface: %S", AdapterList->FriendlyName)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1183, "Name of valid interface: %S", AdapterList->FriendlyName ); } } while (0); | |||
| 1184 | INFO_LOG(WII_IPC_NET, "DNS: %u.%u.%u.%u",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1188, "DNS: %u.%u.%u.%u", (unsigned char)AdapterList->FirstDnsServerAddress ->Address.lpSockaddr->sa_data[2], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [3], (unsigned char)AdapterList->FirstDnsServerAddress-> Address.lpSockaddr->sa_data[4], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [5]); } } while (0) | |||
| 1185 | (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2],do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1188, "DNS: %u.%u.%u.%u", (unsigned char)AdapterList->FirstDnsServerAddress ->Address.lpSockaddr->sa_data[2], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [3], (unsigned char)AdapterList->FirstDnsServerAddress-> Address.lpSockaddr->sa_data[4], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [5]); } } while (0) | |||
| 1186 | (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[3],do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1188, "DNS: %u.%u.%u.%u", (unsigned char)AdapterList->FirstDnsServerAddress ->Address.lpSockaddr->sa_data[2], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [3], (unsigned char)AdapterList->FirstDnsServerAddress-> Address.lpSockaddr->sa_data[4], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [5]); } } while (0) | |||
| 1187 | (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[4],do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1188, "DNS: %u.%u.%u.%u", (unsigned char)AdapterList->FirstDnsServerAddress ->Address.lpSockaddr->sa_data[2], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [3], (unsigned char)AdapterList->FirstDnsServerAddress-> Address.lpSockaddr->sa_data[4], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [5]); } } while (0) | |||
| 1188 | (unsigned char)AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[5])do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1188, "DNS: %u.%u.%u.%u", (unsigned char)AdapterList->FirstDnsServerAddress ->Address.lpSockaddr->sa_data[2], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [3], (unsigned char)AdapterList->FirstDnsServerAddress-> Address.lpSockaddr->sa_data[4], (unsigned char)AdapterList ->FirstDnsServerAddress->Address.lpSockaddr->sa_data [5]); } } while (0); | |||
| 1189 | address = Common::swap32(*(u32*)(&AdapterList->FirstDnsServerAddress->Address.lpSockaddr->sa_data[2])); | |||
| 1190 | break; | |||
| 1191 | } | |||
| 1192 | AdapterList = AdapterList->Next; | |||
| 1193 | } | |||
| 1194 | } | |||
| 1195 | } | |||
| 1196 | if (AdapterAddresses != NULL__null) { | |||
| 1197 | FREE(AdapterAddresses); | |||
| 1198 | } | |||
| 1199 | #endif | |||
| 1200 | if (address == 0) | |||
| 1201 | address = 0x08080808; | |||
| 1202 | ||||
| 1203 | Memory::Write_U32(address, _BufferOut); | |||
| 1204 | Memory::Write_U32(0x08080404, _BufferOut+4); | |||
| 1205 | break; | |||
| 1206 | } | |||
| 1207 | case 0x1003: // error | |||
| 1208 | Memory::Write_U32(0, _BufferOut); | |||
| 1209 | break; | |||
| 1210 | case 0x1004: // mac address | |||
| 1211 | Memory::WriteBigEData(default_address, _BufferOut, 6); | |||
| 1212 | break; | |||
| 1213 | case 0x1005: // link state | |||
| 1214 | Memory::Write_U32(1, _BufferOut); | |||
| 1215 | break; | |||
| 1216 | case 0x4002: // ip addr number | |||
| 1217 | Memory::Write_U32(1, _BufferOut); | |||
| 1218 | break; | |||
| 1219 | case 0x4003: // ip addr table | |||
| 1220 | Memory::Write_U32(0xC, _BufferOut2); | |||
| 1221 | Memory::Write_U32(10 << 24 | 1 << 8 | 30, _BufferOut); | |||
| 1222 | Memory::Write_U32(255 << 24 | 255 << 16 | 255 << 8 | 0, _BufferOut+4); | |||
| 1223 | Memory::Write_U32(10 << 24 | 0 << 16 | 255 << 8 | 255, _BufferOut+8); | |||
| 1224 | break; | |||
| 1225 | default: | |||
| 1226 | ERROR_LOG(WII_IPC_NET, "Unknown param2: %08X", param2)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1226, "Unknown param2: %08X", param2); } } while (0); | |||
| 1227 | break; | |||
| 1228 | } | |||
| 1229 | break; | |||
| 1230 | } | |||
| 1231 | case IOCTLV_SO_SENDTO: | |||
| 1232 | { | |||
| 1233 | u32 fd = Memory::Read_U32(_BufferIn2); | |||
| 1234 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 1235 | sm.doSock(fd, CommandAddress, IOCTLV_SO_SENDTO); | |||
| 1236 | return false; | |||
| 1237 | break; | |||
| 1238 | } | |||
| 1239 | case IOCTLV_SO_RECVFROM: | |||
| 1240 | { | |||
| 1241 | u32 fd = Memory::Read_U32(_BufferIn); | |||
| 1242 | WiiSockMan &sm = WiiSockMan::getInstance(); | |||
| 1243 | sm.doSock(fd, CommandAddress, IOCTLV_SO_RECVFROM); | |||
| 1244 | return false; | |||
| 1245 | break; | |||
| 1246 | } | |||
| 1247 | case IOCTLV_SO_GETADDRINFO: | |||
| 1248 | { | |||
| 1249 | struct addrinfo hints; | |||
| 1250 | struct addrinfo *result = NULL__null; | |||
| 1251 | ||||
| 1252 | if (BufferInSize3) | |||
| 1253 | { | |||
| 1254 | hints.ai_flags = Memory::Read_U32(_BufferIn3); | |||
| 1255 | hints.ai_family = Memory::Read_U32(_BufferIn3 + 0x4); | |||
| 1256 | hints.ai_socktype = Memory::Read_U32(_BufferIn3 + 0x8); | |||
| 1257 | hints.ai_protocol = Memory::Read_U32(_BufferIn3 + 0xC); | |||
| 1258 | hints.ai_addrlen = Memory::Read_U32(_BufferIn3 + 0x10); | |||
| 1259 | hints.ai_canonname = NULL__null; | |||
| 1260 | hints.ai_addr = NULL__null; | |||
| 1261 | hints.ai_next = NULL__null; | |||
| 1262 | } | |||
| 1263 | ||||
| 1264 | char* pNodeName = NULL__null; | |||
| 1265 | if (BufferInSize > 0) | |||
| 1266 | pNodeName = (char*)Memory::GetPointer(_BufferIn); | |||
| 1267 | ||||
| 1268 | char* pServiceName = NULL__null; | |||
| 1269 | if (BufferInSize2 > 0) | |||
| 1270 | pServiceName = (char*)Memory::GetPointer(_BufferIn2); | |||
| 1271 | ||||
| 1272 | int ret = getaddrinfo(pNodeName, pServiceName, BufferInSize3 ? &hints : NULL__null, &result); | |||
| 1273 | u32 addr = _BufferOut; | |||
| 1274 | u32 sockoffset = addr + 0x460; | |||
| 1275 | if (ret == 0) | |||
| 1276 | { | |||
| 1277 | while (result != NULL__null) | |||
| 1278 | { | |||
| 1279 | Memory::Write_U32(result->ai_flags, addr); | |||
| 1280 | Memory::Write_U32(result->ai_family, addr + 0x04); | |||
| 1281 | Memory::Write_U32(result->ai_socktype, addr + 0x08); | |||
| 1282 | Memory::Write_U32(result->ai_protocol, addr + 0x0C); | |||
| 1283 | Memory::Write_U32((u32)result->ai_addrlen, addr + 0x10); | |||
| 1284 | // what to do? where to put? the buffer of 0x834 doesn't allow space for this | |||
| 1285 | Memory::Write_U32(/*result->ai_cannonname*/ 0, addr + 0x14); | |||
| 1286 | ||||
| 1287 | if (result->ai_addr) | |||
| 1288 | { | |||
| 1289 | Memory::Write_U32(sockoffset, addr + 0x18); | |||
| 1290 | Memory::Write_U16(((result->ai_addr->sa_family & 0xFF) << 8) | (result->ai_addrlen & 0xFF), sockoffset); | |||
| 1291 | Memory::WriteBigEData((u8*)result->ai_addr->sa_data, sockoffset + 0x2, sizeof(result->ai_addr->sa_data)); | |||
| 1292 | sockoffset += 0x1C; | |||
| 1293 | } | |||
| 1294 | else | |||
| 1295 | { | |||
| 1296 | Memory::Write_U32(0, addr + 0x18); | |||
| 1297 | } | |||
| 1298 | ||||
| 1299 | if (result->ai_next) | |||
| 1300 | { | |||
| 1301 | Memory::Write_U32(addr + sizeof(addrinfo), addr + 0x1C); | |||
| 1302 | } | |||
| 1303 | else | |||
| 1304 | { | |||
| 1305 | Memory::Write_U32(0, addr + 0x1C); | |||
| 1306 | } | |||
| 1307 | ||||
| 1308 | addr += sizeof(addrinfo); | |||
| 1309 | result = result->ai_next; | |||
| 1310 | } | |||
| 1311 | } | |||
| 1312 | else | |||
| 1313 | { | |||
| 1314 | // Host not found | |||
| 1315 | ret = -305; | |||
| 1316 | } | |||
| 1317 | ||||
| 1318 | INFO_LOG(WII_IPC_NET, "IOCTLV_SO_GETADDRINFO "do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1320, "IOCTLV_SO_GETADDRINFO " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , _BufferIn, BufferInSize, _BufferOut, BufferOutSize); } } while (0) | |||
| 1319 | "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1320, "IOCTLV_SO_GETADDRINFO " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , _BufferIn, BufferInSize, _BufferOut, BufferOutSize); } } while (0) | |||
| 1320 | _BufferIn, BufferInSize, _BufferOut, BufferOutSize)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1320, "IOCTLV_SO_GETADDRINFO " "(BufferIn: (%08x, %i), BufferOut: (%08x, %i)" , _BufferIn, BufferInSize, _BufferOut, BufferOutSize); } } while (0); | |||
| 1321 | INFO_LOG(WII_IPC_NET, "IOCTLV_SO_GETADDRINFO: %s", Memory::GetPointer(_BufferIn))do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1321, "IOCTLV_SO_GETADDRINFO: %s", Memory::GetPointer(_BufferIn )); } } while (0); | |||
| 1322 | ReturnValue = ret; | |||
| 1323 | break; | |||
| 1324 | } | |||
| 1325 | case IOCTLV_SO_ICMPPING: | |||
| 1326 | { | |||
| 1327 | struct | |||
| 1328 | { | |||
| 1329 | u8 length; | |||
| 1330 | u8 addr_family; | |||
| 1331 | u16 icmp_id; | |||
| 1332 | u32 ip; | |||
| 1333 | } ip_info; | |||
| 1334 | ||||
| 1335 | u32 fd = Memory::Read_U32(_BufferIn); | |||
| 1336 | u32 num_ip = Memory::Read_U32(_BufferIn + 4); | |||
| 1337 | u64 timeout = Memory::Read_U64(_BufferIn + 8); | |||
| 1338 | ||||
| 1339 | if (num_ip != 1) | |||
| 1340 | { | |||
| 1341 | INFO_LOG(WII_IPC_NET, "IOCTLV_SO_ICMPPING %i IPs", num_ip)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1341, "IOCTLV_SO_ICMPPING %i IPs", num_ip); } } while (0); | |||
| 1342 | } | |||
| 1343 | ||||
| 1344 | ip_info.length = Memory::Read_U8(_BufferIn + 16); | |||
| 1345 | ip_info.addr_family = Memory::Read_U8(_BufferIn + 17); | |||
| 1346 | ip_info.icmp_id = Memory::Read_U16(_BufferIn + 18); | |||
| 1347 | ip_info.ip = Memory::Read_U32(_BufferIn + 20); | |||
| 1348 | ||||
| 1349 | if (ip_info.length != 8 || ip_info.addr_family != AF_INET2) | |||
| 1350 | { | |||
| 1351 | INFO_LOG(WII_IPC_NET, "IOCTLV_SO_ICMPPING strange IPInfo:\n"do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1353, "IOCTLV_SO_ICMPPING strange IPInfo:\n" "length %x addr_family %x" , ip_info.length, ip_info.addr_family); } } while (0) | |||
| 1352 | "length %x addr_family %x",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1353, "IOCTLV_SO_ICMPPING strange IPInfo:\n" "length %x addr_family %x" , ip_info.length, ip_info.addr_family); } } while (0) | |||
| 1353 | ip_info.length, ip_info.addr_family)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1353, "IOCTLV_SO_ICMPPING strange IPInfo:\n" "length %x addr_family %x" , ip_info.length, ip_info.addr_family); } } while (0); | |||
| 1354 | } | |||
| 1355 | ||||
| 1356 | DEBUG_LOG(WII_IPC_NET, "IOCTLV_SO_ICMPPING %x", ip_info.ip)do { { if (LogTypes::LDEBUG <= 3) GenericLog(LogTypes::LDEBUG , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1356, "IOCTLV_SO_ICMPPING %x", ip_info.ip); } } while (0); | |||
| 1357 | ||||
| 1358 | sockaddr_in addr; | |||
| 1359 | addr.sin_family = AF_INET2; | |||
| 1360 | addr.sin_addr.s_addr = Common::swap32(ip_info.ip); | |||
| 1361 | memset(addr.sin_zero, 0, 8); | |||
| 1362 | ||||
| 1363 | u8 data[0x20]; | |||
| 1364 | memset(data, 0, sizeof(data)); | |||
| 1365 | s32 icmp_length = sizeof(data); | |||
| 1366 | ||||
| 1367 | if (BufferInSize2 == sizeof(data)) | |||
| 1368 | memcpy(data, Memory::GetPointer(_BufferIn2), BufferInSize2); | |||
| 1369 | else | |||
| 1370 | { | |||
| 1371 | // TODO sequence number is incremented either statically, by | |||
| 1372 | // port, or by socket. Doesn't seem to matter, so we just leave | |||
| 1373 | // it 0 | |||
| 1374 | ((u16 *)data)[0] = Common::swap16(ip_info.icmp_id); | |||
| 1375 | icmp_length = 22; | |||
| 1376 | } | |||
| 1377 | ||||
| 1378 | int ret = icmp_echo_req(fd, &addr, data, icmp_length); | |||
| 1379 | if (ret == icmp_length) | |||
| 1380 | { | |||
| 1381 | ret = icmp_echo_rep(fd, &addr, (u32)timeout, icmp_length); | |||
| 1382 | } | |||
| 1383 | ||||
| 1384 | // TODO proper error codes | |||
| 1385 | ReturnValue = 0; | |||
| 1386 | break; | |||
| 1387 | } | |||
| 1388 | default: | |||
| 1389 | INFO_LOG(WII_IPC_NET,"0x%x (BufferIn: (%08x, %i), BufferIn2: (%08x, %i)",do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1390, "0x%x (BufferIn: (%08x, %i), BufferIn2: (%08x, %i)", CommandBuffer .Parameter, _BufferIn, BufferInSize, _BufferIn2, BufferInSize2 ); } } while (0) | |||
| 1390 | CommandBuffer.Parameter, _BufferIn, BufferInSize, _BufferIn2, BufferInSize2)do { { if (LogTypes::LINFO <= 3) GenericLog(LogTypes::LINFO , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1390, "0x%x (BufferIn: (%08x, %i), BufferIn2: (%08x, %i)", CommandBuffer .Parameter, _BufferIn, BufferInSize, _BufferIn2, BufferInSize2 ); } } while (0); | |||
| 1391 | for (u32 i = 0; i < CommandBuffer.NumberInBuffer; ++i) | |||
| 1392 | { | |||
| 1393 | ERROR_LOG(WII_IPC_NET, "in %i addr %x size %x", i,do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1394, "in %i addr %x size %x", i, CommandBuffer.InBuffer.at (i).m_Address, CommandBuffer.InBuffer.at(i).m_Size); } } while (0) | |||
| 1394 | CommandBuffer.InBuffer.at(i).m_Address, CommandBuffer.InBuffer.at(i).m_Size)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1394, "in %i addr %x size %x", i, CommandBuffer.InBuffer.at (i).m_Address, CommandBuffer.InBuffer.at(i).m_Size); } } while (0); | |||
| 1395 | ERROR_LOG(WII_IPC_NET, "\n%s",do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1399, "\n%s", ArrayToString( Memory::GetPointer(CommandBuffer .InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size , 4).c_str()); } } while (0) | |||
| 1396 | ArrayToString(do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1399, "\n%s", ArrayToString( Memory::GetPointer(CommandBuffer .InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size , 4).c_str()); } } while (0) | |||
| 1397 | Memory::GetPointer(CommandBuffer.InBuffer.at(i).m_Address),do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1399, "\n%s", ArrayToString( Memory::GetPointer(CommandBuffer .InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size , 4).c_str()); } } while (0) | |||
| 1398 | CommandBuffer.InBuffer.at(i).m_Size, 4).c_str()do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1399, "\n%s", ArrayToString( Memory::GetPointer(CommandBuffer .InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size , 4).c_str()); } } while (0) | |||
| 1399 | )do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1399, "\n%s", ArrayToString( Memory::GetPointer(CommandBuffer .InBuffer.at(i).m_Address), CommandBuffer.InBuffer.at(i).m_Size , 4).c_str()); } } while (0); | |||
| 1400 | } | |||
| 1401 | for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; ++i) | |||
| 1402 | { | |||
| 1403 | ERROR_LOG(WII_IPC_NET, "out %i addr %x size %x", i,do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1404, "out %i addr %x size %x", i, CommandBuffer.PayloadBuffer .at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size); } } while (0) | |||
| 1404 | CommandBuffer.PayloadBuffer.at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size)do { { if (LogTypes::LERROR <= 3) GenericLog(LogTypes::LERROR , LogTypes::WII_IPC_NET, "/home/anal/dolphin-emu/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp" , 1404, "out %i addr %x size %x", i, CommandBuffer.PayloadBuffer .at(i).m_Address, CommandBuffer.PayloadBuffer.at(i).m_Size); } } while (0); | |||
| 1405 | } | |||
| 1406 | break; | |||
| 1407 | } | |||
| 1408 | ||||
| 1409 | Memory::Write_U32(ReturnValue, CommandAddress + 4); | |||
| 1410 | return true; | |||
| 1411 | } | |||
| 1412 | u32 CWII_IPC_HLE_Device_net_ip_top::Update() | |||
| 1413 | { | |||
| 1414 | WiiSockMan::getInstance().Update(); | |||
| 1415 | return 0; | |||
| 1416 | } |