mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 13:09:39 -07:00
Fix switch PS5 discovery & wakeup PORT
This commit is contained in:
parent
05b22e15f1
commit
ad9b0f3d19
6 changed files with 132 additions and 134 deletions
|
@ -6,8 +6,8 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include <chiaki/discoveryservice.h>
|
#include <chiaki/discoveryservice.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
@ -17,14 +17,15 @@ static void Discovery(ChiakiDiscoveryHost*, void*);
|
||||||
class DiscoveryManager
|
class DiscoveryManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Settings * settings;
|
Settings * settings = nullptr;
|
||||||
ChiakiLog * log;
|
ChiakiLog * log = nullptr;
|
||||||
ChiakiDiscoveryService service;
|
ChiakiDiscoveryService service;
|
||||||
ChiakiDiscovery discovery;
|
ChiakiDiscovery discovery;
|
||||||
struct sockaddr * host_addr;
|
struct sockaddr * host_addr = nullptr;
|
||||||
size_t host_addr_len;
|
size_t host_addr_len = 0;
|
||||||
uint32_t GetIPv4BroadcastAddr();
|
uint32_t GetIPv4BroadcastAddr();
|
||||||
bool service_enable;
|
bool service_enable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef enum hoststate
|
typedef enum hoststate
|
||||||
{
|
{
|
||||||
|
@ -34,7 +35,7 @@ class DiscoveryManager
|
||||||
SHUTDOWN,
|
SHUTDOWN,
|
||||||
} HostState;
|
} HostState;
|
||||||
|
|
||||||
DiscoveryManager(Settings *settings);
|
DiscoveryManager();
|
||||||
~DiscoveryManager();
|
~DiscoveryManager();
|
||||||
void SetService(bool);
|
void SetService(bool);
|
||||||
int Send();
|
int Send();
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
#ifndef CHIAKI_HOST_H
|
#ifndef CHIAKI_HOST_H
|
||||||
#define CHIAKI_HOST_H
|
#define CHIAKI_HOST_H
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include <chiaki/regist.h>
|
|
||||||
#include <chiaki/discovery.h>
|
|
||||||
#include <chiaki/opusdecoder.h>
|
|
||||||
#include <chiaki/controller.h>
|
#include <chiaki/controller.h>
|
||||||
|
#include <chiaki/discovery.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
#include <chiaki/opusdecoder.h>
|
||||||
|
#include <chiaki/regist.h>
|
||||||
|
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
@ -82,10 +82,11 @@ class Host
|
||||||
ChiakiOpusDecoder opus_decoder;
|
ChiakiOpusDecoder opus_decoder;
|
||||||
ChiakiConnectVideoProfile video_profile;
|
ChiakiConnectVideoProfile video_profile;
|
||||||
ChiakiControllerState keyboard_state;
|
ChiakiControllerState keyboard_state;
|
||||||
friend class DiscoveryManager;
|
|
||||||
friend class Settings;
|
friend class Settings;
|
||||||
|
friend class DiscoveryManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Host(ChiakiLog * log, Settings * settings, std::string host_name);
|
Host(std::string host_name);
|
||||||
~Host();
|
~Host();
|
||||||
int Register(std::string pin);
|
int Register(std::string pin);
|
||||||
int Wakeup();
|
int Wakeup();
|
||||||
|
@ -108,6 +109,7 @@ class Host
|
||||||
bool IsDiscovered();
|
bool IsDiscovered();
|
||||||
bool IsReady();
|
bool IsReady();
|
||||||
bool HasRPkey();
|
bool HasRPkey();
|
||||||
|
bool IsPS5();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#include <discoverymanager.h>
|
#include <discoverymanager.h>
|
||||||
|
|
||||||
|
@ -25,10 +25,9 @@ static void Discovery(ChiakiDiscoveryHost * discovered_hosts, size_t hosts_count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiscoveryManager::DiscoveryManager()
|
||||||
DiscoveryManager::DiscoveryManager(Settings *settings)
|
|
||||||
: settings(settings), host_addr(nullptr), host_addr_len(0)
|
|
||||||
{
|
{
|
||||||
|
this->settings = Settings::GetInstance();
|
||||||
this->log = this->settings->GetLogger();
|
this->log = this->settings->GetLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +112,6 @@ int DiscoveryManager::Send(struct sockaddr *host_addr, size_t host_addr_len)
|
||||||
CHIAKI_LOGE(log, "Null sockaddr");
|
CHIAKI_LOGE(log, "Null sockaddr");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
((struct sockaddr_in *)host_addr)->sin_port = htons(CHIAKI_DISCOVERY_PORT);
|
|
||||||
|
|
||||||
ChiakiDiscoveryPacket packet;
|
ChiakiDiscoveryPacket packet;
|
||||||
memset(&packet, 0, sizeof(packet));
|
memset(&packet, 0, sizeof(packet));
|
||||||
packet.cmd = CHIAKI_DISCOVERY_CMD_SRCH;
|
packet.cmd = CHIAKI_DISCOVERY_CMD_SRCH;
|
||||||
|
@ -165,7 +162,6 @@ int DiscoveryManager::Send()
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = GetIPv4BroadcastAddr();
|
addr.sin_addr.s_addr = GetIPv4BroadcastAddr();
|
||||||
addr.sin_port = htons(CHIAKI_DISCOVERY_PORT);
|
|
||||||
|
|
||||||
this->host_addr_len = sizeof(sockaddr_in);
|
this->host_addr_len = sizeof(sockaddr_in);
|
||||||
this->host_addr = (struct sockaddr *)malloc(host_addr_len);
|
this->host_addr = (struct sockaddr *)malloc(host_addr_len);
|
||||||
|
@ -174,7 +170,6 @@ int DiscoveryManager::Send()
|
||||||
return DiscoveryManager::Send(this->host_addr, this->host_addr_len);
|
return DiscoveryManager::Send(this->host_addr, this->host_addr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DiscoveryManager::DiscoveryCB(ChiakiDiscoveryHost * discovered_host)
|
void DiscoveryManager::DiscoveryCB(ChiakiDiscoveryHost * discovered_host)
|
||||||
{
|
{
|
||||||
// the user ptr is passed as
|
// the user ptr is passed as
|
||||||
|
@ -230,4 +225,3 @@ void DiscoveryManager::DiscoveryCB(ChiakiDiscoveryHost * discovered_host)
|
||||||
|
|
||||||
CHIAKI_LOGI(this->log, "--");
|
CHIAKI_LOGI(this->log, "--");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||||
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include <chiaki/base64.h>
|
#include <chiaki/base64.h>
|
||||||
|
|
||||||
#include "io.h"
|
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
static void InitAudioCB(unsigned int channels, unsigned int rate, void * user)
|
static void InitAudioCB(unsigned int channels, unsigned int rate, void * user)
|
||||||
{
|
{
|
||||||
|
@ -39,9 +37,11 @@ static void RegistEventCB(ChiakiRegistEvent * event, void * user)
|
||||||
host->RegistCB(event);
|
host->RegistCB(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
Host::Host(ChiakiLog * log, Settings * settings, std::string host_name)
|
Host::Host(std::string host_name)
|
||||||
: log(log), settings(settings), host_name(host_name)
|
: host_name(host_name)
|
||||||
{
|
{
|
||||||
|
this->settings = Settings::GetInstance();
|
||||||
|
this->log = settings->GetLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
Host::~Host()
|
Host::~Host()
|
||||||
|
@ -62,7 +62,9 @@ int Host::Wakeup()
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t credential = (uint64_t)strtoull(this->rp_regist_key, NULL, 16);
|
uint64_t credential = (uint64_t)strtoull(this->rp_regist_key, NULL, 16);
|
||||||
ChiakiErrorCode ret = chiaki_discovery_wakeup(this->log, NULL, host_addr.c_str(), credential);
|
ChiakiErrorCode ret = chiaki_discovery_wakeup(this->log, NULL,
|
||||||
|
host_addr.c_str(), credential, this->IsPS5());
|
||||||
|
|
||||||
if(ret == CHIAKI_ERR_SUCCESS)
|
if(ret == CHIAKI_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
//FIXME
|
//FIXME
|
||||||
|
@ -119,7 +121,7 @@ int Host::Register(std::string pin)
|
||||||
this->regist_info.host = this->host_addr.c_str();
|
this->regist_info.host = this->host_addr.c_str();
|
||||||
this->regist_info.broadcast = false;
|
this->regist_info.broadcast = false;
|
||||||
|
|
||||||
if(this->system_version >= 7000000)
|
if(this->target >= CHIAKI_TARGET_PS4_9)
|
||||||
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN AccountID `%s` pin `%s`",
|
CHIAKI_LOGI(this->log, "Registering to host `%s` `%s` with PSN AccountID `%s` pin `%s`",
|
||||||
this->host_name.c_str(), this->host_addr.c_str(), account_id.c_str(), pin.c_str());
|
this->host_name.c_str(), this->host_addr.c_str(), account_id.c_str(), pin.c_str());
|
||||||
else
|
else
|
||||||
|
@ -142,10 +144,7 @@ int Host::InitSession(IO * user)
|
||||||
chiaki_connect_info.host = this->host_addr.c_str();
|
chiaki_connect_info.host = this->host_addr.c_str();
|
||||||
chiaki_connect_info.video_profile = this->video_profile;
|
chiaki_connect_info.video_profile = this->video_profile;
|
||||||
|
|
||||||
if(this->target >= CHIAKI_TARGET_PS5_UNKNOWN)
|
chiaki_connect_info.ps5 = this->IsPS5();
|
||||||
chiaki_connect_info.ps5 = true;
|
|
||||||
else
|
|
||||||
chiaki_connect_info.ps5 = false;
|
|
||||||
|
|
||||||
memcpy(chiaki_connect_info.regist_key, this->rp_regist_key, sizeof(chiaki_connect_info.regist_key));
|
memcpy(chiaki_connect_info.regist_key, this->rp_regist_key, sizeof(chiaki_connect_info.regist_key));
|
||||||
memcpy(chiaki_connect_info.morning, this->rp_key, sizeof(chiaki_connect_info.morning));
|
memcpy(chiaki_connect_info.morning, this->rp_key, sizeof(chiaki_connect_info.morning));
|
||||||
|
@ -336,3 +335,11 @@ bool Host::HasRPkey()
|
||||||
{
|
{
|
||||||
return this->rp_key_data;
|
return this->rp_key_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host::IsPS5()
|
||||||
|
{
|
||||||
|
if(this->target >= CHIAKI_TARGET_PS5_UNKNOWN)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL
|
||||||
|
|
||||||
// chiaki modules
|
// chiaki modules
|
||||||
#include <chiaki/log.h>
|
|
||||||
#include <chiaki/discovery.h>
|
#include <chiaki/discovery.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
// discover and wakeup ps4 host
|
// discover and wakeup ps4 host
|
||||||
// from local network
|
// from local network
|
||||||
#include "discoverymanager.h"
|
#include "discoverymanager.h"
|
||||||
#include "settings.h"
|
|
||||||
#include "io.h"
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include "io.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
@ -129,13 +129,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
// build sdl OpenGl and AV decoders graphical interface
|
// build sdl OpenGl and AV decoders graphical interface
|
||||||
IO io = IO(log); // open Input Output class
|
IO io = IO(log); // open Input Output class
|
||||||
|
DiscoveryManager discoverymanager = DiscoveryManager();
|
||||||
// create host objects form config file
|
|
||||||
CHIAKI_LOGI(log, "Read chiaki settings file");
|
|
||||||
// FIXME use GUI for config
|
|
||||||
Host * host = nullptr;
|
|
||||||
|
|
||||||
DiscoveryManager discoverymanager = DiscoveryManager(settings);
|
|
||||||
MainApplication app = MainApplication(&discoverymanager, &io);
|
MainApplication app = MainApplication(&discoverymanager, &io);
|
||||||
app.Load();
|
app.Load();
|
||||||
|
|
||||||
|
@ -143,4 +137,3 @@ int main(int argc, char* argv[])
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ Settings::Settings()
|
||||||
#else
|
#else
|
||||||
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
chiaki_log_init(&this->log, CHIAKI_LOG_ALL ^ CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
|
||||||
#endif
|
#endif
|
||||||
CHIAKI_LOGI(&this->log, "Read chiaki settings file %s", this->filename);
|
|
||||||
this->ParseFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::ConfigurationItem Settings::ParseLine(std::string * line, std::string * value)
|
Settings::ConfigurationItem Settings::ParseLine(std::string * line, std::string * value)
|
||||||
|
@ -43,7 +41,10 @@ Settings * Settings::instance = nullptr;
|
||||||
Settings * Settings::GetInstance()
|
Settings * Settings::GetInstance()
|
||||||
{
|
{
|
||||||
if(instance == nullptr)
|
if(instance == nullptr)
|
||||||
|
{
|
||||||
instance = new Settings;
|
instance = new Settings;
|
||||||
|
instance->ParseFile();
|
||||||
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ Host * Settings::GetOrCreateHost(std::string * host_name)
|
||||||
if(this->hosts.find(*host_name) == hosts.end())
|
if(this->hosts.find(*host_name) == hosts.end())
|
||||||
{
|
{
|
||||||
// create host if udefined
|
// create host if udefined
|
||||||
Host h = Host(&this->log, this, *host_name);
|
Host h = Host(*host_name);
|
||||||
this->hosts.emplace(*host_name, h);
|
this->hosts.emplace(*host_name, h);
|
||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue