Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

fix(ps4): resolve controller init 0x80960002 and TLS handshake send -78 on real hardware

Rafael Abud Ferreira219ca8525c08
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index 1e047c5..b110c95 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -26,7 +26,8 @@ body:
label: Platform
description: Platform where you run the application.
options:
- - PlayStation 5 (PPSA99810)
+ - PlayStation 4
+ - PlayStation 5
- Linux
- Other
validations:
@@ -41,7 +42,7 @@ body:
- type: input
id: firmware
attributes:
- label: PS5 firmware
+ label: PlayStation Firmware
placeholder: e.g. 4.03
validations:
required: true
diff --git a/.github/triage/test_triage.py b/.github/triage/test_triage.py
index 8f95c5c..31b211e 100644
--- a/.github/triage/test_triage.py
+++ b/.github/triage/test_triage.py
@@ -13,7 +13,7 @@ RULES = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
def form(what="", release="", firmware="", log=""):
def section(title, text):
return f"### {title}\n\n{text or '_No response_'}\n\n"
- return (section("What happened?", what) + section("App release", release) + section("PS5 firmware", firmware) +
+ return (section("What happened?", what) + section("App release", release) + section("PlayStation Firmware", firmware) +
section("Game(s) affected", "") + section("Network", "Wired") +
section("xcloud.log", f"```text\n{log}\n```" if log else ""))
@@ -68,6 +68,13 @@ class Triage(unittest.TestCase):
self.assertEqual(labels, ["fw: 13.60"])
self.assertIsNone(comment)
+ def test_legacy_ps5_firmware_label_recognized(self):
+ legacy_body = ("### What happened?\n\nSomething\n\n### App release\n\nv1.3.2\n\n"
+ "### PS5 firmware\n\n13.60\n\n### Game(s) affected\n\n_No response_\n\n"
+ "### Network\n\nWired\n\n### xcloud.log\n\n_No response_\n\n")
+ labels, _ = self.run_triage(legacy_body)
+ self.assertIn("fw: 13.60", labels)
+
def test_app_version_typed_as_firmware_is_ignored(self):
labels, _ = self.run_triage(form("x", "0.9.5", "0.9.5", LOG))
self.assertFalse(any(label.startswith("fw: ") for label in labels))
diff --git a/.github/triage/triage.py b/.github/triage/triage.py
index 628873f..f252f63 100644
--- a/.github/triage/triage.py
+++ b/.github/triage/triage.py
@@ -3,7 +3,7 @@
# Copyright (C) 2026 RafaelNGP
"""Triage of a new or edited issue, by rules (no AI, nothing to pay).
-Reads the bug form's fields (What happened?, App release, PS5 firmware,
+Reads the bug form's fields (What happened?, App release, PlayStation Firmware,
xcloud.log), matches rules.json's known problems, and then on the issue:
adds labels (never removes one), and writes or updates ONE comment (marked
with MARKER) in the reporter's language (English, Portuguese, or Spanish)
@@ -238,7 +238,7 @@ def is_unsupported_147(fields, release, title, body):
app_rel = field(fields, "app release")
if re.search(r"\bv?1\.4\.7\b", app_rel, re.I):
return True
- fw = field(fields, "ps5 firmware").strip().lower()
+ fw = field(fields, "playstation firmware", "ps5 firmware").strip().lower()
plat = field(fields, "platform").strip().lower()
if fw == "ps4" or plat == "ps4":
return True
@@ -259,7 +259,7 @@ def triage(issue, rules, latest):
if not fields: # not the form: all of it is "what happened"
parts["what"] = body
release = version_tuple(field(fields, "app release"))
- firmware = firmware_of(field(fields, "ps5 firmware"))
+ firmware = firmware_of(field(fields, "playstation firmware", "ps5 firmware"))
latest_t = version_tuple(latest) if latest else None
lang = detect_lang(title, parts["what"], log)
tr = STRINGS[lang]
diff --git a/ps4/compat/sys/socket.h b/ps4/compat/sys/socket.h
index 9406128..a5bf8ed 100644
--- a/ps4/compat/sys/socket.h
+++ b/ps4/compat/sys/socket.h
@@ -20,3 +20,17 @@ struct sockaddr_storage {
#ifndef SO_NBIO
#define SO_NBIO 0x1200
#endif
+
+#ifndef SO_NOSIGPIPE
+#define SO_NOSIGPIPE 0x0800
+#endif
+
+#undef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+
+#undef MSG_DONTWAIT
+#define MSG_DONTWAIT 0x0080
+
+#undef MSG_WAITALL
+#define MSG_WAITALL 0x0040
+
diff --git a/src/app/report.h b/src/app/report.h
index 5b66ef7..790dc26 100644
--- a/src/app/report.h
+++ b/src/app/report.h
@@ -16,10 +16,10 @@ struct Info {
std::string title; // the issue's title
std::string what; // what happened (the error shown, or the crash)
std::string release; // app version
- std::string firmware; // PS5 system software, when known
+ std::string firmware; // console system software, when known
std::string log; // logExcerpt()'s
std::string crash; // crash: SIGSEGV pc=eboot+0x... (from the marker)
- std::string platform; // platform name ("PlayStation 5 (PPSA99810)", "Linux", etc.)
+ std::string platform; // platform name ("PlayStation 4", "PlayStation 5", "Linux", etc.)
};
// The bug form's link, at most `maxLength` characters: the log is cut from
diff --git a/src/app/web_server_html.cpp b/src/app/web_server_html.cpp
index b7de86f..ba217c5 100644
--- a/src/app/web_server_html.cpp
+++ b/src/app/web_server_html.cpp
@@ -1849,7 +1849,7 @@ function copySanitizedReport() {
}).then(r => r.json()).then(data => {
btn.disabled = false;
if (data && data.excerpt) {
- const markdown = `### ${data.title || 'Relatório de Erro'}\n\n**Plataforma:** ${data.platform || 'PlayStation 5 (PPSA99810)'}\n**Versão:** v${data.release || ')html" XC_APP_VERSION R"html('}\n**Firmware:** ${data.firmware || 'N/A'}\n\n**O que aconteceu:**\n${what || 'Relatório enviado via WebUI'}\n\n\`\`\`\n${data.excerpt}\n\`\`\``;
+ const markdown = `### ${data.title || 'Relatório de Erro'}\n\n**Plataforma:** ${data.platform || 'PlayStation 5'}\n**Versão:** v${data.release || ')html" XC_APP_VERSION R"html('}\n**Firmware:** ${data.firmware || 'N/A'}\n\n**O que aconteceu:**\n${what || 'Relatório enviado via WebUI'}\n\n\`\`\`\n${data.excerpt}\n\`\`\``;
copyTextToClipboard(markdown).then(() => {
showToast('Relatório copiado para a área de transferência!');
}).catch(() => {
diff --git a/src/input/controller_ps4.cpp b/src/input/controller_ps4.cpp
index 782b384..bcc2d1e 100644
--- a/src/input/controller_ps4.cpp
+++ b/src/input/controller_ps4.cpp
@@ -87,8 +87,6 @@ struct Slot {
char name[64]{};
};
Slot g_slots[4];
-bool g_userServiceInit = false;
-bool g_padInit = false;
bool g_rumbleLogged = false;
inline float normStick(uint8_t v) {
@@ -241,15 +239,27 @@ bool init() {
XC_LOGE("scePadInit failed: 0x%08x", static_cast<unsigned>(rc));
return false;
}
+ SceUserServiceInitializeParams param{0x2FF};
+ rc = sceUserServiceInitialize(&param);
+ if (rc != 0 && rc != static_cast<int>(0x80960003)) {
+ XC_LOGW("sceUserServiceInitialize: 0x%08x", static_cast<unsigned>(rc));
+ }
int32_t uid = -1;
rc = sceUserServiceGetInitialUser(&uid);
- if (rc != 0) {
- SceUserServiceInitializeParams param{0};
- sceUserServiceInitialize(&param);
- rc = sceUserServiceGetInitialUser(&uid);
+ if (rc != 0 || uid < 0) {
+ SceUserServiceLoginUserIdList list{};
+ if (sceUserServiceGetLoginUserIdList(&list) == 0) {
+ for (int32_t u : list.userId) {
+ if (u > 0) {
+ uid = u;
+ rc = 0;
+ break;
+ }
+ }
+ }
}
if (rc != 0 || uid < 0) {
- XC_LOGE("sceUserServiceGetInitialUser failed: 0x%08x", static_cast<unsigned>(rc));
+ XC_LOGE("sceUserServiceGetInitialUser failed: 0x%08x (uid=%d)", static_cast<unsigned>(rc), uid);
return false;
}
openPad(0, uid);
diff --git a/src/net/http.cpp b/src/net/http.cpp
index 054f834..7eb3bc8 100644
--- a/src/net/http.cpp
+++ b/src/net/http.cpp
@@ -80,7 +80,7 @@ std::string lower(std::string s) {
int bioSend(void* ctx, const unsigned char* buf, size_t len) {
int fd = *static_cast<int*>(ctx);
int flags = 0;
-#ifdef MSG_NOSIGNAL
+#if defined(MSG_NOSIGNAL) && (MSG_NOSIGNAL != 0) && !defined(__PS4__)
flags = MSG_NOSIGNAL; // a connection the server dropped: an error, not SIGPIPE
#endif
ssize_t n = ::send(fd, buf, len, flags);
diff --git a/src/platform/platform.h b/src/platform/platform.h
index 880a212..1f0827f 100644
--- a/src/platform/platform.h
+++ b/src/platform/platform.h
@@ -95,7 +95,7 @@ bool restartApp();
// The console's system software ("13.00"); empty where unknown.
std::string firmwareVersion();
-// Platform description ("PlayStation 5 (PPSA99810)" or "Linux").
+// Platform description ("PlayStation 4", "PlayStation 5", "Linux", etc.).
std::string platformName();
bool readFile(const std::string& path, std::string& out);
diff --git a/src/platform/ps4/platform_ps4.cpp b/src/platform/ps4/platform_ps4.cpp
index f3ebabe..0904b9d 100644
--- a/src/platform/ps4/platform_ps4.cpp
+++ b/src/platform/ps4/platform_ps4.cpp
@@ -51,6 +51,25 @@ int sceSysmoduleLoadModule(uint32_t id);
int sceSysmoduleLoadModuleInternal(uint32_t id);
int sceRandomGetRandomNumber(void* buf, size_t size);
+static inline int getNetErrno(int ret) {
+ int* err = sceNetErrnoLoc();
+ if (err && *err > 0) {
+ return *err;
+ }
+ uint32_t uret = static_cast<uint32_t>(ret);
+ if ((uret & 0xFFFFFE00) == 0x80410000) {
+ return static_cast<int>(uret & 0xFF);
+ }
+ if (ret < 0 && ret > -256) {
+ return -ret;
+ }
+ return ret < 0 ? -ret : 0;
+}
+
+static inline int sanitizeNetFlags(int flags) {
+ return flags & 0xC3;
+}
+
int ioctl(int fd, unsigned long request, ...) {
void* arg = nullptr;
va_list ap;
@@ -68,7 +87,6 @@ int ioctl(int fd, unsigned long request, ...) {
static std::mutex s_sockMutex;
static std::unordered_map<int, uint16_t> s_boundPorts;
-static std::atomic<uint16_t> s_nextEphemeralPort{50100};
int socket(int domain, int type, int protocol) {
if (protocol == 17) {
@@ -77,7 +95,7 @@ int socket(int domain, int type, int protocol) {
int baseType = type & 0xF;
int s = sceNetSocket("", domain, baseType, protocol);
if (s < 0) {
- errno = (sceNetErrnoLoc && *sceNetErrnoLoc() > 0) ? *sceNetErrnoLoc() : -s;
+ errno = getNetErrno(s);
return -1;
}
if (type & 0x4000) { // SOCK_NONBLOCK
@@ -90,7 +108,7 @@ int socket(int domain, int type, int protocol) {
int bind(int fd, const struct sockaddr* addr, socklen_t len) {
if (!addr || len < sizeof(struct sockaddr_in)) {
int rc = sceNetBind(fd, addr, len);
- if (rc < 0) { errno = *sceNetErrnoLoc(); return -1; }
+ if (rc < 0) { errno = getNetErrno(rc); return -1; }
return rc;
}
const auto* raw = reinterpret_cast<const uint8_t*>(addr);
@@ -107,7 +125,7 @@ int bind(int fd, const struct sockaddr* addr, socklen_t len) {
// range (old 50100+) collides with ports the PS4 network stack reserves.
int rc = sceNetBind(fd, &boundAddr, sizeof(boundAddr));
if (rc < 0) {
- errno = *sceNetErrnoLoc();
+ errno = getNetErrno(rc);
return -1;
}
if (port != 0) {
@@ -159,10 +177,11 @@ int getsockname(int fd, struct sockaddr* addr, socklen_t* len) {
ssize_t sendto(int fd, const void* buf, size_t len, int flags,
const struct sockaddr* dest_addr, socklen_t addrlen) {
+ flags = sanitizeNetFlags(flags);
if (!dest_addr || addrlen < 2) {
int ret = sceNetSendto(fd, buf, len, flags, nullptr, 0);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
@@ -179,7 +198,7 @@ ssize_t sendto(int fd, const void* buf, size_t len, int flags,
int ret = sceNetSendto(fd, buf, len, flags, &fixedAddr, addrlen);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
@@ -187,10 +206,11 @@ ssize_t sendto(int fd, const void* buf, size_t len, int flags,
ssize_t recvfrom(int fd, void* buf, size_t len, int flags,
struct sockaddr* src_addr, socklen_t* addrlen) {
+ flags = sanitizeNetFlags(flags);
unsigned int slen = addrlen ? static_cast<unsigned int>(*addrlen) : 0;
int ret = sceNetRecvfrom(fd, buf, len, flags, src_addr, addrlen ? &slen : nullptr);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
if (addrlen) *addrlen = slen;
@@ -203,18 +223,18 @@ ssize_t recvfrom(int fd, void* buf, size_t len, int flags,
}
ssize_t send(int fd, const void* buf, size_t len, int flags) {
- int ret = sceNetSend(fd, buf, len, flags);
+ int ret = sceNetSend(fd, buf, len, sanitizeNetFlags(flags));
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
}
ssize_t recv(int fd, void* buf, size_t len, int flags) {
- int ret = sceNetRecv(fd, buf, len, flags);
+ int ret = sceNetRecv(fd, buf, len, sanitizeNetFlags(flags));
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
@@ -232,7 +252,7 @@ int connect(int fd, const struct sockaddr* addr, socklen_t len) {
}
int ret = sceNetConnect(fd, &fixedAddr, len);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
@@ -241,7 +261,7 @@ int connect(int fd, const struct sockaddr* addr, socklen_t len) {
int listen(int fd, int backlog) {
int ret = sceNetListen(fd, backlog);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return ret;
@@ -251,7 +271,7 @@ int accept(int fd, struct sockaddr* addr, socklen_t* addrlen) {
unsigned int slen = addrlen ? static_cast<unsigned int>(*addrlen) : 0;
int ret = sceNetAccept(fd, addr, addrlen ? &slen : nullptr);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
if (addrlen) *addrlen = slen;
@@ -261,7 +281,7 @@ int accept(int fd, struct sockaddr* addr, socklen_t* addrlen) {
int setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen) {
int ret = sceNetSetsockopt(fd, level, optname, optval, optlen);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
return 0;
@@ -271,7 +291,7 @@ int getsockopt(int fd, int level, int optname, void* optval, socklen_t* optlen)
unsigned int olen = optlen ? static_cast<unsigned int>(*optlen) : 0;
int ret = sceNetGetsockopt(fd, level, optname, optval, optlen ? &olen : nullptr);
if (ret < 0) {
- errno = sceNetErrnoLoc ? *sceNetErrnoLoc() : -ret;
+ errno = getNetErrno(ret);
return -1;
}
if (optlen) *optlen = olen;
@@ -712,7 +732,7 @@ std::string firmwareVersion() {
}
std::string platformName() {
- return "PlayStation 4 (BREW99810)";
+ return "PlayStation 4";
}
void makePrivate(const std::string&) {}
diff --git a/src/platform/ps5/platform_ps5.cpp b/src/platform/ps5/platform_ps5.cpp
index c4ecd49..6fe500a 100644
--- a/src/platform/ps5/platform_ps5.cpp
+++ b/src/platform/ps5/platform_ps5.cpp
@@ -242,7 +242,7 @@ std::string firmwareVersion() {
}
std::string platformName() {
- return "PlayStation 5 (PPSA99810)";
+ return "PlayStation 5";
}
// One user per app sandbox: nothing to hide the sign-in from.