Skip to content

Commit

Permalink
Misc Fixes 10 (#781)
Browse files Browse the repository at this point in the history
* libSceRazorCpu needed for gravity rush

* libSceCesCs needed for blue reflection

* clang format fix

* set scePadSetVibration to log debug

* initial sceNetCtl module implementation

* improved error codes in file system

* some intial work on netctl callbacks (helps a bit CUSA10135)

* misc

* improved callbacks handling in sceNetCtl

* small fixes

* added libSceRudp.sprx to lle modules

* draft work for npcallbacks
  • Loading branch information
georgemoralis authored Sep 11, 2024
1 parent 1c0dfc6 commit 0ebae4c
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp
src/core/libraries/network/net.cpp
src/core/libraries/network/netctl.cpp
src/core/libraries/network/netctl.h
src/core/libraries/network/net_ctl_obj.cpp
src/core/libraries/network/net_ctl_obj.h
src/core/libraries/network/net_ctl_codes.h
src/core/libraries/network/net.h
src/core/libraries/network/ssl.cpp
src/core/libraries/network/ssl.h
Expand Down
27 changes: 22 additions & 5 deletions src/core/libraries/kernel/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ int PS4_SYSV_ABI posix_close(int d) {
return -1;
}
return result;
return ORBIS_OK;
}

size_t PS4_SYSV_ABI sceKernelWrite(int d, const void* buf, size_t nbytes) {
Expand Down Expand Up @@ -367,8 +366,17 @@ s64 PS4_SYSV_ABI sceKernelPread(int d, void* buf, size_t nbytes, s64 offset) {

int PS4_SYSV_ABI sceKernelFStat(int fd, OrbisKernelStat* sb) {
LOG_INFO(Kernel_Fs, "(PARTIAL) fd = {}", fd);
if (fd < 3) {
return ORBIS_KERNEL_ERROR_EPERM;
}
if (sb == nullptr) {
return ORBIS_KERNEL_ERROR_EFAULT;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF;
}
std::memset(sb, 0, sizeof(OrbisKernelStat));

if (file->is_directory) {
Expand Down Expand Up @@ -421,15 +429,24 @@ int PS4_SYSV_ABI sceKernelFtruncate(int fd, s64 length) {
}

static int GetDents(int fd, char* buf, int nbytes, s64* basep) {
// TODO error codes
ASSERT(buf != nullptr);
if (fd < 3) {
return ORBIS_KERNEL_ERROR_EBADF;
}

if (buf == nullptr) {
return ORBIS_KERNEL_ERROR_EFAULT;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);

if (file == nullptr) {
return ORBIS_KERNEL_ERROR_EBADF;
}
if (file->dirents_index == file->dirents.size()) {
return ORBIS_OK;
}

if (!file->is_directory || nbytes < 512 || file->dirents_index > file->dirents.size()) {
return ORBIS_KERNEL_ERROR_EINVAL;
}
const auto& entry = file->dirents.at(file->dirents_index++);
auto str = entry.name;
auto str_size = str.size() - 1;
Expand Down
28 changes: 28 additions & 0 deletions src/core/libraries/network/net_ctl_codes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

// error codes
constexpr int ORBIS_NET_CTL_ERROR_CALLBACK_MAX = 0x80412103;
constexpr int ORBIS_NET_CTL_ERROR_ID_NOT_FOUND = 0x80412104;
constexpr int ORBIS_NET_CTL_ERROR_INVALID_ID = 0x80412105;
constexpr int ORBIS_NET_CTL_ERROR_INVALID_ADDR = 0x80412107;
constexpr int ORBIS_NET_CTL_ERROR_NOT_CONNECTED = 0x80412108;
constexpr int ORBIS_NET_CTL_ERROR_NOT_AVAIL = 0x80412109;
constexpr int ORBIS_NET_CTL_ERROR_NETWORK_DISABLED = 0x8041210D;
constexpr int ORBIS_NET_CTL_ERROR_DISCONNECT_REQ = 0x8041210E;
constexpr int ORBIS_NET_CTL_ERROR_ETHERNET_PLUGOUT = 0x80412115;
constexpr int ORBIS_NET_CTL_ERROR_WIFI_DEAUTHED = 0x80412116;
constexpr int ORBIS_NET_CTL_ERROR_WIFI_BEACON_LOST = 0x80412117;

// state codes
constexpr int ORBIS_NET_CTL_STATE_DISCONNECTED = 0;
constexpr int ORBIS_NET_CTL_STATE_CONNECTING = 1;
constexpr int ORBIS_NET_CTL_STATE_IPOBTAINING = 2;
constexpr int ORBIS_NET_CTL_STATE_IPOBTAINED = 3;

// event type
constexpr int ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED = 1;
constexpr int ORBIS_SCE_NET_CTL_EVENT_TYPE_DISCONNECT_REQ_FINISHED = 2;
constexpr int ORBIS_NET_CTL_EVENT_TYPE_IPOBTAINED = 3;
74 changes: 74 additions & 0 deletions src/core/libraries/network/net_ctl_obj.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "net_ctl_codes.h"
#include "net_ctl_obj.h"

Libraries::NetCtl::NetCtlInternal::NetCtlInternal() {
callbacks.fill({nullptr, nullptr});
nptoolCallbacks.fill({nullptr, nullptr});
}

Libraries::NetCtl::NetCtlInternal::~NetCtlInternal() {}

s32 Libraries::NetCtl::NetCtlInternal::registerCallback(OrbisNetCtlCallback func, void* arg) {
std::unique_lock lock{m_mutex};

// Find the next available slot
int next_id = 0;
for (const auto& callback : callbacks) {
if (callback.func == nullptr) {
break;
}
next_id++;
}

if (next_id == 8) {
return ORBIS_NET_CTL_ERROR_CALLBACK_MAX;
}

callbacks[next_id].func = func;
callbacks[next_id].arg = arg;
return next_id;
}

s32 Libraries::NetCtl::NetCtlInternal::registerNpToolkitCallback(
OrbisNetCtlCallbackForNpToolkit func, void* arg) {

std::unique_lock lock{m_mutex};

// Find the next available slot
int next_id = 0;
for (const auto& callback : nptoolCallbacks) {
if (callback.func == nullptr) {
break;
}
next_id++;
}

if (next_id == 8) {
return ORBIS_NET_CTL_ERROR_CALLBACK_MAX;
}

nptoolCallbacks[next_id].func = func;
nptoolCallbacks[next_id].arg = arg;
return next_id;
}

void Libraries::NetCtl::NetCtlInternal::checkCallback() {
std::unique_lock lock{m_mutex};
for (auto& callback : callbacks) {
if (callback.func != nullptr) {
callback.func(ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, callback.arg);
}
}
}

void Libraries::NetCtl::NetCtlInternal::checkNpToolkitCallback() {
std::unique_lock lock{m_mutex};
for (auto& callback : nptoolCallbacks) {
if (callback.func != nullptr) {
callback.func(ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, callback.arg);
}
}
}
40 changes: 40 additions & 0 deletions src/core/libraries/network/net_ctl_obj.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <condition_variable>
#include <mutex>

#include "common/types.h"

namespace Libraries::NetCtl {

using OrbisNetCtlCallback = PS4_SYSV_ABI void (*)(int eventType, void* arg);
using OrbisNetCtlCallbackForNpToolkit = PS4_SYSV_ABI void (*)(int eventType, void* arg);

struct NetCtlCallback {
OrbisNetCtlCallback func;
void* arg;
};

struct NetCtlCallbackForNpToolkit {
OrbisNetCtlCallbackForNpToolkit func;
void* arg;
};

class NetCtlInternal {
public:
NetCtlInternal();
~NetCtlInternal();
s32 registerCallback(OrbisNetCtlCallback func, void* arg);
s32 registerNpToolkitCallback(OrbisNetCtlCallbackForNpToolkit func, void* arg);
void checkCallback();
void checkNpToolkitCallback();

public:
std::array<NetCtlCallback, 8> nptoolCallbacks;
std::array<NetCtlCallbackForNpToolkit, 8> callbacks;
std::mutex m_mutex;
};
} // namespace Libraries::NetCtl
56 changes: 45 additions & 11 deletions src/core/libraries/network/netctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
#include "core/libraries/network/net_ctl_codes.h"
#include "core/libraries/network/netctl.h"

namespace Libraries::NetCtl {
Expand Down Expand Up @@ -79,7 +81,8 @@ int PS4_SYSV_ABI sceNetCtlUnregisterCallbackV6() {
}

int PS4_SYSV_ABI sceNetCtlCheckCallback() {
LOG_TRACE(Lib_NetCtl, "(STUBBED) called");
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
netctl->checkCallback();
return ORBIS_OK;
}

Expand Down Expand Up @@ -143,7 +146,17 @@ int PS4_SYSV_ABI sceNetCtlGetIfStat() {
return ORBIS_OK;
}

int PS4_SYSV_ABI sceNetCtlGetInfo() {
int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info) {
switch (code) {
case ORBIS_NET_CTL_INFO_DEVICE:
info->device = 0;
break;
case ORBIS_NET_CTL_INFO_LINK:
info->link = 0; // disconnected
break;
default:
LOG_ERROR(Lib_NetCtl, "{} unsupported code", code);
}
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
return ORBIS_OK;
}
Expand Down Expand Up @@ -173,8 +186,9 @@ int PS4_SYSV_ABI sceNetCtlGetNetEvConfigInfoIpcInt() {
return ORBIS_OK;
}

int PS4_SYSV_ABI sceNetCtlGetResult() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlGetResult(int eventType, int* errorCode) {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called eventType = {} ", eventType);
*errorCode = 0;
return ORBIS_OK;
}

Expand Down Expand Up @@ -213,8 +227,8 @@ int PS4_SYSV_ABI sceNetCtlGetScanInfoForSsidScanIpcInt() {
return ORBIS_OK;
}

int PS4_SYSV_ABI sceNetCtlGetState() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlGetState(int* state) {
*state = ORBIS_NET_CTL_STATE_DISCONNECTED;
return ORBIS_OK;
}

Expand Down Expand Up @@ -248,8 +262,17 @@ int PS4_SYSV_ABI sceNetCtlIsBandwidthManagementEnabledIpcInt() {
return ORBIS_OK;
}

int PS4_SYSV_ABI sceNetCtlRegisterCallback() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlRegisterCallback(OrbisNetCtlCallback func, void* arg, int* cid) {
if (!func || !cid) {
return ORBIS_NET_CTL_ERROR_INVALID_ADDR;
}
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
s32 result = netctl->registerCallback(func, arg);
if (result < 0) {
return result;
} else {
*cid = result;
}
return ORBIS_OK;
}

Expand Down Expand Up @@ -319,7 +342,8 @@ int PS4_SYSV_ABI Func_D8DCB6973537A3DC() {
}

int PS4_SYSV_ABI sceNetCtlCheckCallbackForNpToolkit() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
netctl->checkNpToolkitCallback();
return ORBIS_OK;
}

Expand All @@ -328,8 +352,18 @@ int PS4_SYSV_ABI sceNetCtlClearEventForNpToolkit() {
return ORBIS_OK;
}

int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit() {
LOG_ERROR(Lib_NetCtl, "(STUBBED) called");
int PS4_SYSV_ABI sceNetCtlRegisterCallbackForNpToolkit(OrbisNetCtlCallbackForNpToolkit func,
void* arg, int* cid) {
if (!func || !cid) {
return ORBIS_NET_CTL_ERROR_INVALID_ADDR;
}
auto* netctl = Common::Singleton<Libraries::NetCtl::NetCtlInternal>::Instance();
s32 result = netctl->registerNpToolkitCallback(func, arg);
if (result < 0) {
return result;
} else {
*cid = result;
}
return ORBIS_OK;
}

Expand Down
Loading

0 comments on commit 0ebae4c

Please sign in to comment.