Add switch PS5 ChiakiTarget config

This commit is contained in:
h0neybadger 2020-12-24 19:55:05 +01:00 committed by Florian Märkl
commit 7378b31bc1
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
7 changed files with 193 additions and 98 deletions

View file

@ -56,7 +56,7 @@ class MainApplication
// add_host local settings
std::string remote_display_name = "";
std::string remote_addr = "";
int remote_ps4_version = 8000000;
ChiakiTarget remote_ps_version = CHIAKI_TARGET_PS5_1;
bool BuildConfigurationMenu(brls::List *, Host * host = nullptr);
void BuildAddHostConfigurationMenu(brls::List *);

View file

@ -42,8 +42,6 @@ class Host
//video config
ChiakiVideoResolutionPreset video_resolution = CHIAKI_VIDEO_RESOLUTION_PRESET_720p;
ChiakiVideoFPSPreset video_fps = CHIAKI_VIDEO_FPS_PRESET_60;
// info from discovery manager
int device_discovery_protocol_version = 0;
std::string host_type;
// user info
std::string psn_online_id = "";
@ -55,11 +53,24 @@ class Host
std::function<void()> chiaki_regist_event_type_finished_failed = nullptr;
std::function<void()> chiaki_regist_event_type_finished_success = nullptr;
// internal state
bool discovered = false;
bool registered = false;
// rp_key_data is true when rp_key, rp_regist_key, rp_key_type
bool rp_key_data = false;
std::string host_name;
// sony's host_id == mac addr without colon
std::string host_id;
std::string host_addr;
std::string ap_ssid;
std::string ap_bssid;
std::string ap_key;
std::string ap_name;
std::string server_nickname;
ChiakiTarget target = CHIAKI_TARGET_PS4_UNKNOWN;
ChiakiDiscoveryHostState state = CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN;
// mac address = 48 bits
uint8_t server_mac[6] = {0};
char rp_regist_key[CHIAKI_SESSION_AUTH_SIZE] = {0};
@ -74,20 +85,8 @@ class Host
friend class DiscoveryManager;
friend class Settings;
public:
// internal state
ChiakiDiscoveryHostState state = CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN;
bool discovered = false;
bool registered = false;
// rp_key_data is true when rp_key, rp_regist_key, rp_key_type
bool rp_key_data = false;
std::string host_name;
int system_version = 0;
// sony's host_id == mac addr without colon
std::string host_id;
std::string host_addr;
Host(ChiakiLog * log, Settings * settings, std::string host_name);
~Host();
bool GetVideoResolution(int * ret_width, int * ret_height);
int Register(std::string pin);
int Wakeup();
int InitSession(IO *);
@ -96,19 +95,19 @@ class Host
void StartSession();
void SendFeedbackState(ChiakiControllerState*);
void RegistCB(ChiakiRegistEvent *);
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled)
{
this->chiaki_regist_event_type_finished_canceled = chiaki_regist_event_type_finished_canceled;
};
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed)
{
this->chiaki_regist_event_type_finished_failed = chiaki_regist_event_type_finished_failed;
};
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success)
{
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
};
bool GetVideoResolution(int * ret_width, int * ret_height);
std::string GetHostName();
std::string GetHostAddr();
ChiakiTarget GetChiakiTarget();
void SetChiakiTarget(ChiakiTarget target);
void SetHostAddr(std::string host_addr);
void SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled);
void SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed);
void SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success);
bool IsRegistered();
bool IsDiscovered();
bool IsReady();
bool HasRPkey();
};
#endif

View file

@ -36,6 +36,7 @@ class Settings
RP_REGIST_KEY,
VIDEO_RESOLUTION,
VIDEO_FPS,
TARGET,
} ConfigurationItem;
// dummy parser implementation
@ -51,6 +52,7 @@ class Settings
{ RP_REGIST_KEY, std::regex("^\\s*rp_regist_key\\s*=\\s*\"?([\\w/=+]+)\"?") },
{ VIDEO_RESOLUTION, std::regex("^\\s*video_resolution\\s*=\\s*\"?(1080p|720p|540p|360p)\"?") },
{ VIDEO_FPS, std::regex("^\\s*video_fps\\s*=\\s*\"?(60|30)\"?") },
{ TARGET, std::regex("^\\s*target\\s*=\\s*\"?(\\d+)\"?") },
};
ConfigurationItem ParseLine(std::string * line, std::string * value);
@ -75,6 +77,8 @@ class Settings
void SetVideoFPS(Host * host, ChiakiVideoFPSPreset value);
void SetVideoResolution(Host * host, std::string value);
void SetVideoFPS(Host * host, std::string value);
bool SetChiakiTarget(Host * host, ChiakiTarget target);
bool SetChiakiTarget(Host * host, std::string value);
std::string GetHostAddr(Host * host);
std::string GetHostName(Host * host);
bool SetHostRPKeyType(Host * host, std::string value);
@ -83,6 +87,7 @@ class Settings
std::string GetHostRPRegistKey(Host * host);
bool SetHostRPKey(Host * host, std::string rp_key_b64);
bool SetHostRPRegistKey(Host * host, std::string rp_regist_key_b64);
ChiakiTarget GetChiakiTarget(Host * host);
void ParseFile();
int WriteFile();
};

View file

@ -186,29 +186,19 @@ void DiscoveryManager::DiscoveryCB(ChiakiDiscoveryHost * discovered_host)
CHIAKI_LOGI(this->log, "--");
CHIAKI_LOGI(this->log, "Discovered Host:");
CHIAKI_LOGI(this->log, "State: %s", chiaki_discovery_host_state_string(discovered_host->state));
/*
host attr
uint32_t host_addr;
int system_version;
int device_discovery_protocol_version;
std::string host_name;
std::string host_type;
std::string host_id;
*/
host->state = discovered_host->state;
// add host ptr to list
if(discovered_host->system_version)
if(discovered_host->system_version && discovered_host->device_discovery_protocol_version)
{
// example: 07020001
host->system_version = atoi(discovered_host->system_version);
CHIAKI_LOGI(this->log, "System Version: %s", discovered_host->system_version);
}
ChiakiTarget target = chiaki_discovery_host_system_version_target(discovered_host);
host->SetChiakiTarget(target);
if(discovered_host->device_discovery_protocol_version)
{
host->device_discovery_protocol_version = atoi(discovered_host->device_discovery_protocol_version);
CHIAKI_LOGI(this->log, "System Version: %s", discovered_host->system_version);
CHIAKI_LOGI(this->log, "Device Discovery Protocol Version: %s", discovered_host->device_discovery_protocol_version);
CHIAKI_LOGI(this->log, "PlayStation ChiakiTarget Version: %d", target);
}
if(discovered_host->host_request_port)

View file

@ -53,13 +53,15 @@ void HostInterface::Register(IO * io, Host * host, Settings * settings, std::fun
// user must provide psn id for registration
std::string account_id = settings->GetPSNAccountID(host);
std::string online_id = settings->GetPSNOnlineID(host);
if(host->system_version >= 7000000 && account_id.length() <= 0)
ChiakiTarget target = host->GetChiakiTarget();
if(target >= CHIAKI_TARGET_PS4_9 && account_id.length() <= 0)
{
// PS4 firmware > 7.0
DIALOG(upaid, "Undefined PSN Account ID (Please configure a valid psn_account_id)");
return;
}
else if( host->system_version < 7000000 && host->system_version > 0 && online_id.length() <= 0)
else if(target < CHIAKI_TARGET_PS4_9 && online_id.length() <= 0)
{
// use oline ID for ps4 < 7.0
DIALOG(upoid, "Undefined PSN Online ID (Please configure a valid psn_online_id)");
@ -141,7 +143,7 @@ void HostInterface::Register()
void HostInterface::Wakeup(brls::View * view)
{
if(!this->host->rp_key_data)
if(!this->host->HasRPkey())
{
// the host is not registered yet
DIALOG(prypf, "Please register your PlayStation first");
@ -163,7 +165,7 @@ void HostInterface::Wakeup(brls::View * view)
void HostInterface::Connect(brls::View * view)
{
// check that all requirements are met
if(!this->host->discovered && !this->host->rp_key_data)
if(!this->host->IsDiscovered() && !this->host->HasRPkey())
{
// at this point the host must be discovered or registered manually
// to validate the system_version accuracy
@ -171,14 +173,14 @@ void HostInterface::Connect(brls::View * view)
}
// ignore state for remote hosts
if(this->host->discovered && this->host->state != CHIAKI_DISCOVERY_HOST_STATE_READY)
if(this->host->IsDiscovered() && this->host->IsReady())
{
// host in standby mode
DIALOG(ptoyp, "Please turn on your PlayStation");
return;
}
if(!this->host->rp_key_data)
if(!this->host->HasRPkey())
{
this->Register();
}
@ -309,14 +311,14 @@ bool MainApplication::Load()
{
// add host to the gui only if the host is registered or discovered
if(this->host_menuitems.find(&it->second) == this->host_menuitems.end()
&& (it->second.rp_key_data == true || it->second.discovered == true))
&& (it->second.HasRPkey() == true || it->second.IsDiscovered() == true))
{
brls::List* new_host = new brls::List();
this->host_menuitems[&it->second] = new_host;
// create host if udefined
HostInterface host_menu = HostInterface(new_host, this->io, &it->second, this->settings);
BuildConfigurationMenu(new_host, &it->second);
this->rootFrame->addTab(it->second.host_name.c_str(), new_host);
this->rootFrame->addTab(it->second.GetHostName().c_str(), new_host);
}
}
}
@ -325,6 +327,26 @@ bool MainApplication::Load()
bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
{
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
brls::ListItem* psn_account_id = new brls::ListItem("PSN Account ID", "PS5 or PS4 v7.0 and greater (base64 account_id)");
psn_account_id->setValue(psn_account_id_string.c_str());
auto psn_account_id_cb = [this, host, psn_account_id](brls::View * view)
{
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
if(input)
{
// update gui
psn_account_id->setValue(account_id);
// push in setting
this->settings->SetPSNAccountID(host, account_id);
// write on disk
this->settings->WriteFile();
}
};
psn_account_id->getClickEvent()->subscribe(psn_account_id_cb);
ls->addView(psn_account_id);
std::string psn_online_id_string = this->settings->GetPSNOnlineID(host);
brls::ListItem* psn_online_id = new brls::ListItem("PSN Online ID");
psn_online_id->setValue(psn_online_id_string.c_str());
@ -345,26 +367,6 @@ bool MainApplication::BuildConfigurationMenu(brls::List * ls, Host * host)
psn_online_id->getClickEvent()->subscribe(psn_online_id_cb);
ls->addView(psn_online_id);
std::string psn_account_id_string = this->settings->GetPSNAccountID(host);
brls::ListItem* psn_account_id = new brls::ListItem("PSN Account ID", "v7.0 and greater");
psn_account_id->setValue(psn_account_id_string.c_str());
auto psn_account_id_cb = [this, host, psn_account_id](brls::View * view)
{
char account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2] = {0};
bool input = this->io->ReadUserKeyboard(account_id, sizeof(account_id));
if(input)
{
// update gui
psn_account_id->setValue(account_id);
// push in setting
this->settings->SetPSNAccountID(host, account_id);
// write on disk
this->settings->WriteFile();
}
};
psn_account_id->getClickEvent()->subscribe(psn_account_id_cb);
ls->addView(psn_account_id);
int value;
ChiakiVideoResolutionPreset resolution_preset = this->settings->GetVideoResolution(host);
switch(resolution_preset)
@ -517,25 +519,32 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
// brls::ListItem* port = new brls::ListItem("Remote session port", "tcp/udp 9295");
// brls::ListItem* port = new brls::ListItem("Remote stream port", "udp 9296");
// brls::ListItem* port = new brls::ListItem("Remote Senkusha port", "udp 9297");
brls::SelectListItem* ps4_version = new brls::SelectListItem("PS4 Version",
{ "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
auto ps4_version_cb = [this, ps4_version](int result)
brls::SelectListItem* ps_version = new brls::SelectListItem("PlayStation Version",
{ "PS5", "PS4 > 8", "7 < PS4 < 8", "PS4 < 7"});
auto ps_version_cb = [this, ps_version](int result)
{
switch(result)
{
case 0:
this->remote_ps4_version = 8000000;
// ps5 v1
this->remote_ps_version = CHIAKI_TARGET_PS5_1;
break;
case 1:
this->remote_ps4_version = 7000000;
// ps4 v8
this->remote_ps_version = CHIAKI_TARGET_PS4_10;
break;
case 2:
this->remote_ps4_version = 6000000;
// ps4 v7
this->remote_ps_version = CHIAKI_TARGET_PS4_9;
break;
case 3:
// ps4 v6
this->remote_ps_version = CHIAKI_TARGET_PS4_8;
break;
}
};
ps4_version->getValueSelectedEvent()->subscribe(ps4_version_cb);
add_host->addView(ps4_version);
ps_version->getValueSelectedEvent()->subscribe(ps_version_cb);
add_host->addView(ps_version);
brls::ListItem* register_host = new brls::ListItem("Register");
auto register_host_cb = [this](brls::View * view)
@ -553,9 +562,9 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
err = true;
}
if(this->remote_ps4_version < 0)
if(this->remote_ps_version < 0)
{
brls::Application::notify("No PS4 Version provided");
brls::Application::notify("No PlayStation Version provided");
err = true;
}
@ -563,8 +572,8 @@ void MainApplication::BuildAddHostConfigurationMenu(brls::List * add_host)
return;
Host * host = this->settings->GetOrCreateHost(&this->remote_display_name);
host->host_addr = this->remote_addr;
host->system_version = this->remote_ps4_version;
host->SetHostAddr(this->remote_addr);
host->SetChiakiTarget(this->remote_ps_version);
HostInterface::Register(this->io, host, this->settings);
};

View file

@ -74,14 +74,13 @@ int Host::Register(std::string pin)
{
// use pin and accont_id to negociate secrets for session
//
// convert psn_account_id into uint8_t[CHIAKI_PSN_ACCOUNT_ID_SIZE]
// CHIAKI_PSN_ACCOUNT_ID_SIZE == 8
std::string account_id = this->settings->GetPSNAccountID(this);
std::string online_id = this->settings->GetPSNOnlineID(this);
size_t account_id_size = sizeof(uint8_t[CHIAKI_PSN_ACCOUNT_ID_SIZE]);
// PS4 firmware > 7.0
if(this->system_version >= 7000000)
regist_info.target = this->target;
if(this->target >= CHIAKI_TARGET_PS4_9)
{
// use AccountID for ps4 > 7.0
if(account_id.length() > 0)
@ -95,12 +94,8 @@ int Host::Register(std::string pin)
CHIAKI_LOGE(this->log, "Undefined PSN Account ID (Please configure a valid psn_account_id)");
return HOST_REGISTER_ERROR_SETTING_PSNACCOUNTID;
}
if(this->system_version >= 8000000)
regist_info.target = CHIAKI_TARGET_PS4_10;
else
regist_info.target = CHIAKI_TARGET_PS4_9;
}
else if( this->system_version < 7000000 && this->system_version > 0)
else if(this->target > CHIAKI_TARGET_PS4_UNKNOWN)
{
// use oline ID for ps4 < 7.0
if(online_id.length() > 0)
@ -113,7 +108,6 @@ int Host::Register(std::string pin)
CHIAKI_LOGE(this->log, "Undefined PSN Online ID (Please configure a valid psn_online_id)");
return HOST_REGISTER_ERROR_SETTING_PSNONLINEID;
}
regist_info.target = CHIAKI_TARGET_PS4_8;
}
else
{
@ -147,6 +141,12 @@ int Host::InitSession(IO * user)
chiaki_connect_info.host = this->host_addr.c_str();
chiaki_connect_info.video_profile = this->video_profile;
if(this->target >= CHIAKI_TARGET_PS5_UNKNOWN)
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.morning, this->rp_key, sizeof(chiaki_connect_info.morning));
// set keybord state to 0
@ -277,3 +277,62 @@ bool Host::GetVideoResolution(int * ret_width, int * ret_height)
return true;
}
std::string Host::GetHostName()
{
return this->host_name;
}
std::string Host::GetHostAddr()
{
return this->host_addr;
}
ChiakiTarget Host::GetChiakiTarget()
{
return this->target;
}
void Host::SetChiakiTarget(ChiakiTarget target)
{
this->target = target;
}
void Host::SetHostAddr(std::string host_addr)
{
this->host_addr = host_addr;
}
void Host::SetRegistEventTypeFinishedCanceled(std::function<void()> chiaki_regist_event_type_finished_canceled)
{
this->chiaki_regist_event_type_finished_canceled = chiaki_regist_event_type_finished_canceled;
}
void Host::SetRegistEventTypeFinishedFailed(std::function<void()> chiaki_regist_event_type_finished_failed)
{
this->chiaki_regist_event_type_finished_failed = chiaki_regist_event_type_finished_failed;
}
void Host::SetRegistEventTypeFinishedSuccess(std::function<void()> chiaki_regist_event_type_finished_success)
{
this->chiaki_regist_event_type_finished_success = chiaki_regist_event_type_finished_success;
}
bool Host::IsRegistered()
{
return this->registered;
}
bool Host::IsDiscovered()
{
return this->discovered;
}
bool Host::IsReady()
{
return this->state == CHIAKI_DISCOVERY_HOST_STATE_READY;
}
bool Host::HasRPkey()
{
return this->rp_key_data;
}

View file

@ -262,7 +262,7 @@ void Settings::SetCPUOverclock(Host * host, std::string value)
std::string Settings::GetHostAddr(Host * host)
{
if(host != nullptr)
return host->host_addr;
return host->GetHostAddr();
else
CHIAKI_LOGE(this->log, "Cannot GetHostAddr from nullptr host");
return "";
@ -271,7 +271,7 @@ std::string Settings::GetHostAddr(Host * host)
std::string Settings::GetHostName(Host * host)
{
if(host != nullptr)
return host->host_name;
return host->GetHostName();
else
CHIAKI_LOGE(this->log, "Cannot GetHostName from nullptr host");
return "";
@ -386,6 +386,31 @@ bool Settings::SetHostRPRegistKey(Host * host, std::string rp_regist_key_b64)
return false;
}
ChiakiTarget Settings::GetChiakiTarget(Host * host)
{
return host->GetChiakiTarget();
}
bool Settings::SetChiakiTarget(Host * host, ChiakiTarget target)
{
if(host != nullptr)
{
host->SetChiakiTarget(target);
return true;
}
else
{
CHIAKI_LOGE(this->log, "Cannot SetChiakiTarget from nullptr host");
return false;
}
}
bool Settings::SetChiakiTarget(Host * host, std::string value)
{
// TODO Check possible target values
return this->SetChiakiTarget(host, static_cast<ChiakiTarget>(std::atoi(value.c_str())));
}
void Settings::ParseFile()
{
CHIAKI_LOGI(this->log, "Parse config file %s", this->filename);
@ -456,6 +481,11 @@ void Settings::ParseFile()
case VIDEO_FPS:
this->SetVideoFPS(current_host, value);
break;
case TARGET:
CHIAKI_LOGV(this->log, "TARGET %s", value.c_str());
if(current_host != nullptr)
this->SetChiakiTarget(current_host, value);
break;
} // ci switch
if(rp_key_b && rp_regist_key_b && rp_key_type_b)
// the current host contains rp key data
@ -509,8 +539,10 @@ int Settings::WriteFile()
CHIAKI_LOGD(this->log, "Write Host config file %s", it->first.c_str());
config_file << "[" << it->first << "]\n"
<< "host_addr = \"" << it->second.host_addr << "\"\n";
<< "host_addr = \"" << it->second.GetHostAddr() << "\"\n"
<< "target = " << it->second.GetChiakiTarget() << "\"\n";
config_file << "target = \"" << it->second.psn_account_id << "\"\n";
if(it->second.video_resolution)
config_file << "video_resolution = \""
<< this->ResolutionPresetToString(this->GetVideoResolution(&it->second))
@ -535,7 +567,8 @@ int Settings::WriteFile()
config_file << "rp_key = \"" << this->GetHostRPKey(&it->second) << "\"\n"
<< "rp_regist_key = \"" << this->GetHostRPRegistKey(&it->second) << "\"\n"
<< "rp_key_type = " << rp_key_type << "\n";
} //
}
config_file << "\n";
} // for host
} // is_open