IOS HLE: Deduplicate request code in net/net_ssl

This commit is contained in:
Léo Lam 2017-01-15 11:47:27 +01:00
parent 84c8d0b66d
commit a04902086a
6 changed files with 349 additions and 494 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,7 +30,7 @@ public:
virtual ~CWII_IPC_HLE_Device_net_kd_request();
IPCCommandResult IOCtl(u32 _CommandAddress) override;
IPCCommandResult IOCtl(const IOSIOCtlRequest& request) override;
private:
enum
@ -86,35 +86,31 @@ public:
}
virtual ~CWII_IPC_HLE_Device_net_kd_time() {}
IPCCommandResult IOCtl(u32 _CommandAddress) override
IPCCommandResult IOCtl(const IOSIOCtlRequest& request) override
{
u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C);
u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
u32 result = 0;
s32 result = 0;
u32 common_result = 0;
// TODO Writes stuff to /shared2/nwc24/misc.bin
// u32 update_misc = 0;
switch (Parameter)
switch (request.request)
{
case IOCTL_NW24_GET_UNIVERSAL_TIME:
Memory::Write_U64(GetAdjustedUTC(), BufferOut + 4);
Memory::Write_U64(GetAdjustedUTC(), request.buffer_out + 4);
break;
case IOCTL_NW24_SET_UNIVERSAL_TIME:
SetAdjustedUTC(Memory::Read_U64(BufferIn));
// update_misc = Memory::Read_U32(BufferIn + 8);
SetAdjustedUTC(Memory::Read_U64(request.buffer_in));
// update_misc = Memory::Read_U32(request.buffer_in + 8);
break;
case IOCTL_NW24_SET_RTC_COUNTER:
rtc = Memory::Read_U32(BufferIn);
// update_misc = Memory::Read_U32(BufferIn + 4);
rtc = Memory::Read_U32(request.buffer_in);
// update_misc = Memory::Read_U32(request.buffer_in + 4);
break;
case IOCTL_NW24_GET_TIME_DIFF:
Memory::Write_U64(GetAdjustedUTC() - rtc, BufferOut + 4);
Memory::Write_U64(GetAdjustedUTC() - rtc, request.buffer_out + 4);
break;
case IOCTL_NW24_UNIMPLEMENTED:
@ -122,13 +118,13 @@ public:
break;
default:
ERROR_LOG(WII_IPC_NET, "%s - unknown IOCtl: %x", GetDeviceName().c_str(), Parameter);
ERROR_LOG(WII_IPC_NET, "%s - unknown IOCtl: %x", GetDeviceName().c_str(), request.request);
break;
}
// write return values
Memory::Write_U32(common_result, BufferOut);
Memory::Write_U32(result, _CommandAddress + 4);
Memory::Write_U32(common_result, request.buffer_out);
request.SetReturnValue(result);
return GetDefaultReply();
}
@ -207,8 +203,8 @@ public:
virtual ~CWII_IPC_HLE_Device_net_ip_top();
IPCCommandResult IOCtl(u32 _CommandAddress) override;
IPCCommandResult IOCtlV(u32 _CommandAddress) override;
IPCCommandResult IOCtl(const IOSIOCtlRequest& request) override;
IPCCommandResult IOCtlV(const IOSIOCtlVRequest& request) override;
void Update() override;
@ -227,7 +223,7 @@ public:
virtual ~CWII_IPC_HLE_Device_net_ncd_manage();
IPCCommandResult IOCtlV(u32 _CommandAddress) override;
IPCCommandResult IOCtlV(const IOSIOCtlVRequest& request) override;
private:
enum
@ -253,7 +249,7 @@ public:
virtual ~CWII_IPC_HLE_Device_net_wd_command();
IPCCommandResult IOCtlV(u32 CommandAddress) override;
IPCCommandResult IOCtlV(const IOSIOCtlVRequest& request) override;
private:
enum

View File

@ -75,72 +75,62 @@ int CWII_IPC_HLE_Device_net_ssl::GetSSLFreeID() const
return 0;
}
IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtl(u32 _CommandAddress)
IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtl(const IOSIOCtlRequest& request)
{
u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10);
u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C);
u32 Command = Memory::Read_U32(_CommandAddress + 0x0C);
INFO_LOG(WII_IPC_SSL, "%s unknown %i "
"(BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
GetDeviceName().c_str(), Command, BufferIn, BufferInSize, BufferOut, BufferOutSize);
Memory::Write_U32(0, _CommandAddress + 0x4);
request.Log(GetDeviceName(), LogTypes::WII_IPC_SSL, LogTypes::LINFO);
request.SetReturnValue(IPC_SUCCESS);
return GetDefaultReply();
}
IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(const IOSIOCtlVRequest& request)
{
SIOCtlVBuffer CommandBuffer(_CommandAddress);
u32 _BufferIn = 0, _BufferIn2 = 0, _BufferIn3 = 0;
u32 BufferIn = 0, BufferIn2 = 0, BufferIn3 = 0;
u32 BufferInSize = 0, BufferInSize2 = 0, BufferInSize3 = 0;
u32 BufferOut = 0, BufferOut2 = 0, BufferOut3 = 0;
u32 BufferOutSize = 0, BufferOutSize2 = 0, BufferOutSize3 = 0;
if (CommandBuffer.InBuffer.size() > 0)
if (request.in_vectors.size() > 0)
{
_BufferIn = CommandBuffer.InBuffer.at(0).m_Address;
BufferInSize = CommandBuffer.InBuffer.at(0).m_Size;
BufferIn = request.in_vectors.at(0).address;
BufferInSize = request.in_vectors.at(0).size;
}
if (CommandBuffer.InBuffer.size() > 1)
if (request.in_vectors.size() > 1)
{
_BufferIn2 = CommandBuffer.InBuffer.at(1).m_Address;
BufferInSize2 = CommandBuffer.InBuffer.at(1).m_Size;
BufferIn2 = request.in_vectors.at(1).address;
BufferInSize2 = request.in_vectors.at(1).size;
}
if (CommandBuffer.InBuffer.size() > 2)
if (request.in_vectors.size() > 2)
{
_BufferIn3 = CommandBuffer.InBuffer.at(2).m_Address;
BufferInSize3 = CommandBuffer.InBuffer.at(2).m_Size;
BufferIn3 = request.in_vectors.at(2).address;
BufferInSize3 = request.in_vectors.at(2).size;
}
if (CommandBuffer.PayloadBuffer.size() > 0)
if (request.io_vectors.size() > 0)
{
BufferOut = CommandBuffer.PayloadBuffer.at(0).m_Address;
BufferOutSize = CommandBuffer.PayloadBuffer.at(0).m_Size;
BufferOut = request.io_vectors.at(0).address;
BufferOutSize = request.io_vectors.at(0).size;
}
if (CommandBuffer.PayloadBuffer.size() > 1)
if (request.io_vectors.size() > 1)
{
BufferOut2 = CommandBuffer.PayloadBuffer.at(1).m_Address;
BufferOutSize2 = CommandBuffer.PayloadBuffer.at(1).m_Size;
BufferOut2 = request.io_vectors.at(1).address;
BufferOutSize2 = request.io_vectors.at(1).size;
}
if (CommandBuffer.PayloadBuffer.size() > 2)
if (request.io_vectors.size() > 2)
{
BufferOut3 = CommandBuffer.PayloadBuffer.at(2).m_Address;
BufferOutSize3 = CommandBuffer.PayloadBuffer.at(2).m_Size;
BufferOut3 = request.io_vectors.at(2).address;
BufferOutSize3 = request.io_vectors.at(2).size;
}
// I don't trust SSL to be deterministic, and this is never going to sync
// as such (as opposed to forwarding IPC results or whatever), so -
if (Core::g_want_determinism)
{
Memory::Write_U32(-1, _CommandAddress + 0x4);
request.SetReturnValue(-1);
return GetDefaultReply();
}
switch (CommandBuffer.Parameter)
switch (request.request)
{
case IOCTLV_NET_SSL_NEW:
{
@ -187,20 +177,20 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
mbedtls_ssl_set_hostname(&ssl->ctx, ssl->hostname.c_str());
ssl->active = true;
Memory::Write_U32(freeSSL, _BufferIn);
Memory::Write_U32(freeSSL, BufferIn);
}
else
{
_SSL_NEW_ERROR:
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_NEW (%d, %s) "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
verifyOption, hostname.c_str(), _BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, BufferOut, BufferOutSize, BufferOut2, BufferOutSize2,
verifyOption, hostname.c_str(), BufferIn, BufferInSize, BufferIn2, BufferInSize2,
BufferIn3, BufferInSize3, BufferOut, BufferOutSize, BufferOut2, BufferOutSize2,
BufferOut3, BufferOutSize3);
break;
}
@ -226,18 +216,18 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
ssl->active = false;
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SHUTDOWN "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SETROOTCA:
@ -246,8 +236,8 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
@ -264,19 +254,19 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
if (ret)
{
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCA = %d", ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
break;
}
@ -286,8 +276,8 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
@ -302,19 +292,19 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
{
mbedtls_x509_crt_free(&ssl->clicert);
mbedtls_pk_free(&ssl->pk);
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_own_cert(&ssl->config, &ssl->clicert, &ssl->pk);
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT = (%d, %d)", ret, pk_ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
@ -325,8 +315,8 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
@ -336,11 +326,11 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
mbedtls_pk_free(&ssl->pk);
mbedtls_ssl_conf_own_cert(&ssl->config, nullptr, nullptr);
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINCLIENTCERT invalid sslID = %d", sslID);
}
break;
@ -357,25 +347,25 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
if (ret)
{
mbedtls_x509_crt_free(&ssl->clicert);
Memory::Write_U32(SSL_ERR_FAILED, _BufferIn);
Memory::Write_U32(SSL_ERR_FAILED, BufferIn);
}
else
{
mbedtls_ssl_conf_ca_chain(&ssl->config, &ssl->cacert, nullptr);
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA = %d", ret);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETBUILTINROOTCA "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_CONNECT:
@ -388,18 +378,18 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
ssl->sockfd = Memory::Read_U32(BufferOut2);
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT socket = %d", ssl->sockfd);
mbedtls_ssl_set_bio(&ssl->ctx, &ssl->sockfd, mbedtls_net_send, mbedtls_net_recv, nullptr);
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_CONNECT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_DOHANDSHAKE:
@ -408,12 +398,12 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
if (SSLID_VALID(sslID))
{
WiiSockMan& sm = WiiSockMan::GetInstance();
sm.DoSock(_SSL[sslID].sockfd, _CommandAddress, IOCTLV_NET_SSL_DOHANDSHAKE);
sm.DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_DOHANDSHAKE);
return GetNoReply();
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
break;
}
@ -423,19 +413,19 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
if (SSLID_VALID(sslID))
{
WiiSockMan& sm = WiiSockMan::GetInstance();
sm.DoSock(_SSL[sslID].sockfd, _CommandAddress, IOCTLV_NET_SSL_WRITE);
sm.DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_WRITE);
return GetNoReply();
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_WRITE "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
INFO_LOG(WII_IPC_SSL, "%s", Memory::GetString(BufferOut2).c_str());
break;
}
@ -446,19 +436,19 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
if (SSLID_VALID(sslID))
{
WiiSockMan& sm = WiiSockMan::GetInstance();
sm.DoSock(_SSL[sslID].sockfd, _CommandAddress, IOCTLV_NET_SSL_READ);
sm.DoSock(_SSL[sslID].sockfd, request, IOCTLV_NET_SSL_READ);
return GetNoReply();
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_READ(%d)"
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
ret, _BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
ret, BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
break;
}
@ -467,18 +457,18 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
{
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
INFO_LOG(WII_IPC_SSL, "IOCTLV_NET_SSL_SETROOTCADEFAULT "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
break;
}
case IOCTLV_NET_SSL_SETCLIENTCERTDEFAULT:
@ -487,33 +477,25 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ssl::IOCtlV(u32 _CommandAddress)
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
_BufferIn, BufferInSize, _BufferIn2, BufferInSize2, _BufferIn3, BufferInSize3,
BufferOut, BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
BufferIn, BufferInSize, BufferIn2, BufferInSize2, BufferIn3, BufferInSize3, BufferOut,
BufferOutSize, BufferOut2, BufferOutSize2, BufferOut3, BufferOutSize3);
int sslID = Memory::Read_U32(BufferOut) - 1;
if (SSLID_VALID(sslID))
{
Memory::Write_U32(SSL_OK, _BufferIn);
Memory::Write_U32(SSL_OK, BufferIn);
}
else
{
Memory::Write_U32(SSL_ERR_ID, _BufferIn);
Memory::Write_U32(SSL_ERR_ID, BufferIn);
}
break;
}
default:
ERROR_LOG(WII_IPC_SSL, "%i "
"BufferIn: (%08x, %i), BufferIn2: (%08x, %i), "
"BufferIn3: (%08x, %i), BufferOut: (%08x, %i), "
"BufferOut2: (%08x, %i), BufferOut3: (%08x, %i)",
CommandBuffer.Parameter, _BufferIn, BufferInSize, _BufferIn2, BufferInSize2,
_BufferIn3, BufferInSize3, BufferOut, BufferOutSize, BufferOut2, BufferOutSize2,
BufferOut3, BufferOutSize3);
break;
request.DumpUnknown(GetDeviceName(), LogTypes::WII_IPC_SSL);
}
// SSL return codes are written to BufferIn
Memory::Write_U32(0, _CommandAddress + 4);
request.SetReturnValue(IPC_SUCCESS);
return GetDefaultReply();
}

View File

@ -87,8 +87,8 @@ public:
virtual ~CWII_IPC_HLE_Device_net_ssl();
IPCCommandResult IOCtl(u32 _CommandAddress) override;
IPCCommandResult IOCtlV(u32 _CommandAddress) override;
IPCCommandResult IOCtl(const IOSIOCtlRequest& request) override;
IPCCommandResult IOCtlV(const IOSIOCtlVRequest& request) override;
int GetSSLFreeID() const;

View File

@ -187,28 +187,23 @@ void WiiSocket::Update(bool read, bool write, bool except)
{
s32 ReturnValue = 0;
bool forceNonBlock = false;
IPCCommandType ct = static_cast<IPCCommandType>(Memory::Read_U32(it->_CommandAddress));
IPCCommandType ct = it->request.command;
if (!it->is_ssl && ct == IPC_CMD_IOCTL)
{
u32 BufferIn = Memory::Read_U32(it->_CommandAddress + 0x10);
u32 BufferInSize = Memory::Read_U32(it->_CommandAddress + 0x14);
u32 BufferOut = Memory::Read_U32(it->_CommandAddress + 0x18);
u32 BufferOutSize = Memory::Read_U32(it->_CommandAddress + 0x1C);
IOSIOCtlRequest ioctl{it->request.address};
switch (it->net_type)
{
case IOCTL_SO_FCNTL:
{
u32 cmd = Memory::Read_U32(BufferIn + 4);
u32 arg = Memory::Read_U32(BufferIn + 8);
u32 cmd = Memory::Read_U32(ioctl.buffer_in + 4);
u32 arg = Memory::Read_U32(ioctl.buffer_in + 8);
ReturnValue = FCntl(cmd, arg);
break;
}
case IOCTL_SO_BIND:
{
// u32 has_addr = Memory::Read_U32(BufferIn + 0x04);
sockaddr_in local_name;
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(BufferIn + 0x08);
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(ioctl.buffer_in + 8);
WiiSockMan::Convert(*wii_name, local_name);
int ret = bind(fd, (sockaddr*)&local_name, sizeof(local_name));
@ -220,9 +215,8 @@ void WiiSocket::Update(bool read, bool write, bool except)
}
case IOCTL_SO_CONNECT:
{
// u32 has_addr = Memory::Read_U32(BufferIn + 0x04);
sockaddr_in local_name;
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(BufferIn + 0x08);
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(ioctl.buffer_in + 8);
WiiSockMan::Convert(*wii_name, local_name);
int ret = connect(fd, (sockaddr*)&local_name, sizeof(local_name));
@ -234,10 +228,10 @@ void WiiSocket::Update(bool read, bool write, bool except)
}
case IOCTL_SO_ACCEPT:
{
if (BufferOutSize > 0)
if (ioctl.buffer_out_size > 0)
{
sockaddr_in local_name;
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(BufferOut);
WiiSockAddrIn* wii_name = (WiiSockAddrIn*)Memory::GetPointer(ioctl.buffer_out);
WiiSockMan::Convert(*wii_name, local_name);
socklen_t addrlen = sizeof(sockaddr_in);
@ -254,10 +248,7 @@ void WiiSocket::Update(bool read, bool write, bool except)
WiiSockMan::GetInstance().AddSocket(ReturnValue);
INFO_LOG(WII_IPC_NET, "IOCTL_SO_ACCEPT "
"BufferIn: (%08x, %i), BufferOut: (%08x, %i)",
BufferIn, BufferInSize, BufferOut, BufferOutSize);
ioctl.Log("IOCTL_SO_ACCEPT", LogTypes::WII_IPC_NET);
break;
}
default:
@ -275,34 +266,34 @@ void WiiSocket::Update(bool read, bool write, bool except)
}
else if (ct == IPC_CMD_IOCTLV)
{
SIOCtlVBuffer CommandBuffer(it->_CommandAddress);
IOSIOCtlVRequest ioctlv{it->request.address};
u32 BufferIn = 0, BufferIn2 = 0;
u32 BufferInSize = 0, BufferInSize2 = 0;
u32 BufferOut = 0, BufferOut2 = 0;
u32 BufferOutSize = 0, BufferOutSize2 = 0;
if (CommandBuffer.InBuffer.size() > 0)
if (ioctlv.in_vectors.size() > 0)
{
BufferIn = CommandBuffer.InBuffer.at(0).m_Address;
BufferInSize = CommandBuffer.InBuffer.at(0).m_Size;
BufferIn = ioctlv.in_vectors.at(0).address;
BufferInSize = ioctlv.in_vectors.at(0).size;
}
if (CommandBuffer.PayloadBuffer.size() > 0)
if (ioctlv.io_vectors.size() > 0)
{
BufferOut = CommandBuffer.PayloadBuffer.at(0).m_Address;
BufferOutSize = CommandBuffer.PayloadBuffer.at(0).m_Size;
BufferOut = ioctlv.io_vectors.at(0).address;
BufferOutSize = ioctlv.io_vectors.at(0).size;
}
if (CommandBuffer.PayloadBuffer.size() > 1)
if (ioctlv.io_vectors.size() > 1)
{
BufferOut2 = CommandBuffer.PayloadBuffer.at(1).m_Address;
BufferOutSize2 = CommandBuffer.PayloadBuffer.at(1).m_Size;
BufferOut2 = ioctlv.io_vectors.at(1).address;
BufferOutSize2 = ioctlv.io_vectors.at(1).size;
}
if (CommandBuffer.InBuffer.size() > 1)
if (ioctlv.in_vectors.size() > 1)
{
BufferIn2 = CommandBuffer.InBuffer.at(1).m_Address;
BufferInSize2 = CommandBuffer.InBuffer.at(1).m_Size;
BufferIn2 = ioctlv.in_vectors.at(1).address;
BufferInSize2 = ioctlv.in_vectors.at(1).size;
}
if (it->is_ssl)
@ -576,8 +567,8 @@ void WiiSocket::Update(bool read, bool write, bool except)
"IOCTL(V) Sock: %08x ioctl/v: %d returned: %d nonBlock: %d forceNonBlock: %d", fd,
it->is_ssl ? (int)it->ssl_type : (int)it->net_type, ReturnValue, nonBlock,
forceNonBlock);
Memory::Write_U32(ReturnValue, it->_CommandAddress + 4);
WII_IPC_HLE_Interface::EnqueueReply(it->_CommandAddress);
it->request.SetReturnValue(ReturnValue);
WII_IPC_HLE_Interface::EnqueueReply(it->request);
it = pending_sockops.erase(it);
}
else
@ -587,16 +578,16 @@ void WiiSocket::Update(bool read, bool write, bool except)
}
}
void WiiSocket::DoSock(u32 _CommandAddress, NET_IOCTL type)
void WiiSocket::DoSock(IOSRequest request, NET_IOCTL type)
{
sockop so = {_CommandAddress, false};
sockop so = {request, false};
so.net_type = type;
pending_sockops.push_back(so);
}
void WiiSocket::DoSock(u32 _CommandAddress, SSL_IOCTL type)
void WiiSocket::DoSock(IOSRequest request, SSL_IOCTL type)
{
sockop so = {_CommandAddress, true};
sockop so = {request, true};
so.ssl_type = type;
pending_sockops.push_back(so);
}

View File

@ -172,7 +172,7 @@ class WiiSocket
{
struct sockop
{
u32 _CommandAddress;
IOSRequest request;
bool is_ssl;
union
{
@ -191,8 +191,8 @@ private:
s32 CloseFd();
s32 FCntl(u32 cmd, u32 arg);
void DoSock(u32 _CommandAddress, NET_IOCTL type);
void DoSock(u32 _CommandAddress, SSL_IOCTL type);
void DoSock(IOSRequest request, NET_IOCTL type);
void DoSock(IOSRequest request, SSL_IOCTL type);
void Update(bool read, bool write, bool except);
bool IsValid() const { return fd >= 0; }
public:
@ -223,19 +223,19 @@ public:
void SetLastNetError(s32 error) { errno_last = error; }
void Clean() { WiiSockets.clear(); }
template <typename T>
void DoSock(s32 sock, u32 CommandAddress, T type)
void DoSock(s32 sock, const IOSRequest& request, T type)
{
auto socket_entry = WiiSockets.find(sock);
if (socket_entry == WiiSockets.end())
{
ERROR_LOG(WII_IPC_NET, "DoSock: Error, fd not found (%08x, %08X, %08X)", sock, CommandAddress,
type);
Memory::Write_U32(-SO_EBADF, CommandAddress + 4);
WII_IPC_HLE_Interface::EnqueueReply(CommandAddress);
ERROR_LOG(WII_IPC_NET, "DoSock: Error, fd not found (%08x, %08X, %08X)", sock,
request.address, type);
request.SetReturnValue(-SO_EBADF);
WII_IPC_HLE_Interface::EnqueueReply(request);
}
else
{
socket_entry->second.DoSock(CommandAddress, type);
socket_entry->second.DoSock(request, type);
}
}