mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Add Discovery and Wakeup for PS5
This commit is contained in:
parent
65add80ec6
commit
8904c86a6d
9 changed files with 42 additions and 19 deletions
|
@ -21,8 +21,10 @@ typedef unsigned short sa_family_t;
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CHIAKI_DISCOVERY_PORT 987
|
||||
#define CHIAKI_DISCOVERY_PROTOCOL_VERSION "00020020"
|
||||
#define CHIAKI_DISCOVERY_PORT_PS4 987
|
||||
#define CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS4 "00020020"
|
||||
#define CHIAKI_DISCOVERY_PORT_PS5 9302
|
||||
#define CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS5 "00030010"
|
||||
|
||||
typedef enum chiaki_discovery_cmd_t
|
||||
{
|
||||
|
@ -101,7 +103,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_stop(ChiakiDiscoveryThread
|
|||
* Convenience function to send a wakeup packet
|
||||
* @param discovery Discovery to send the packet on. May be NULL, in which case a new temporary Discovery will be created
|
||||
*/
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDiscovery *discovery, const char *host, uint64_t user_credential);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDiscovery *discovery, const char *host, uint64_t user_credential, bool ps5);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,12 +34,13 @@ const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state)
|
|||
|
||||
CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, ChiakiDiscoveryPacket *packet)
|
||||
{
|
||||
const char *version_str = packet->protocol_version ? packet->protocol_version : CHIAKI_DISCOVERY_PROTOCOL_VERSION;
|
||||
if(!packet->protocol_version)
|
||||
return -1;
|
||||
switch(packet->cmd)
|
||||
{
|
||||
case CHIAKI_DISCOVERY_CMD_SRCH:
|
||||
return snprintf(buf, buf_size, "SRCH * HTTP/1.1\ndevice-discovery-protocol-version:%s\n",
|
||||
version_str);
|
||||
packet->protocol_version);
|
||||
case CHIAKI_DISCOVERY_CMD_WAKEUP:
|
||||
return snprintf(buf, buf_size,
|
||||
"WAKEUP * HTTP/1.1\n"
|
||||
|
@ -49,7 +50,7 @@ CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, Chiaki
|
|||
"app-type:r\n"
|
||||
"user-credential:%llu\n"
|
||||
"device-discovery-protocol-version:%s\n",
|
||||
(unsigned long long)packet->user_credential, version_str);
|
||||
(unsigned long long)packet->user_credential, packet->protocol_version);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
@ -179,6 +180,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_send(ChiakiDiscovery *discovery,
|
|||
if((size_t)len >= sizeof(buf))
|
||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||
|
||||
CHIAKI_LOGV(discovery->log, "Discovery sending:");
|
||||
chiaki_log_hexdump(discovery->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, (size_t)len + 1);
|
||||
int rc = sendto_broadcast(discovery->log, discovery->socket, buf, (size_t)len + 1, 0, addr, addr_size);
|
||||
if(rc < 0)
|
||||
{
|
||||
|
@ -280,7 +283,7 @@ static void *discovery_thread_func(void *user)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDiscovery *discovery, const char *host, uint64_t user_credential)
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDiscovery *discovery, const char *host, uint64_t user_credential, bool ps5)
|
||||
{
|
||||
struct addrinfo *addrinfos;
|
||||
int r = getaddrinfo(host, NULL, NULL, &addrinfos); // TODO: this blocks, use something else
|
||||
|
@ -311,10 +314,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDisc
|
|||
return CHIAKI_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
((struct sockaddr_in *)&addr)->sin_port = htons(CHIAKI_DISCOVERY_PORT);
|
||||
((struct sockaddr_in *)&addr)->sin_port = htons(ps5 ? CHIAKI_DISCOVERY_PORT_PS5 : CHIAKI_DISCOVERY_PORT_PS4);
|
||||
|
||||
ChiakiDiscoveryPacket packet = { 0 };
|
||||
packet.cmd = CHIAKI_DISCOVERY_CMD_WAKEUP;
|
||||
packet.protocol_version = ps5 ? CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS5 : CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS4;
|
||||
packet.user_credential = user_credential;
|
||||
|
||||
ChiakiErrorCode err;
|
||||
|
|
|
@ -135,9 +135,27 @@ static void discovery_service_ping(ChiakiDiscoveryService *service)
|
|||
CHIAKI_LOGV(service->log, "Discovery Service sending ping");
|
||||
ChiakiDiscoveryPacket packet = { 0 };
|
||||
packet.cmd = CHIAKI_DISCOVERY_CMD_SRCH;
|
||||
packet.protocol_version = CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS4;
|
||||
if(service->options.send_addr->sa_family == AF_INET)
|
||||
((struct sockaddr_in *)service->options.send_addr)->sin_port = htons(CHIAKI_DISCOVERY_PORT_PS4);
|
||||
else if(service->options.send_addr->sa_family == AF_INET6)
|
||||
((struct sockaddr_in6 *)service->options.send_addr)->sin6_port = htons(CHIAKI_DISCOVERY_PORT_PS4);
|
||||
else
|
||||
{
|
||||
CHIAKI_LOGE(service->log, "Discovery Service send_addr has unknown sa_family");
|
||||
return;
|
||||
}
|
||||
err = chiaki_discovery_send(&service->discovery, &packet, service->options.send_addr, service->options.send_addr_size);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
CHIAKI_LOGE(service->log, "Discovery Service failed to send ping");
|
||||
CHIAKI_LOGE(service->log, "Discovery Service failed to send ping for PS4");
|
||||
packet.protocol_version = CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS5;
|
||||
if(service->options.send_addr->sa_family == AF_INET)
|
||||
((struct sockaddr_in *)service->options.send_addr)->sin_port = htons(CHIAKI_DISCOVERY_PORT_PS5);
|
||||
else // if(service->options.send_addr->sa_family == AF_INET6)
|
||||
((struct sockaddr_in6 *)service->options.send_addr)->sin6_port = htons(CHIAKI_DISCOVERY_PORT_PS5);
|
||||
err = chiaki_discovery_send(&service->discovery, &packet, service->options.send_addr, service->options.send_addr_size);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
CHIAKI_LOGE(service->log, "Discovery Service failed to send ping for PS5");
|
||||
}
|
||||
|
||||
static void discovery_service_drop_old_hosts(ChiakiDiscoveryService *service)
|
||||
|
@ -264,4 +282,4 @@ static void discovery_service_report_state(ChiakiDiscoveryService *service)
|
|||
// service->state_mutex must be locked
|
||||
if(service->options.cb)
|
||||
service->options.cb(service->hosts, service->hosts_count, service->options.cb_user);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue