mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 05:53:12 -07:00
Finish PS5 Regist
This commit is contained in:
parent
20a7e9d123
commit
05812b7b7a
11 changed files with 122 additions and 51 deletions
|
@ -37,12 +37,13 @@ typedef struct chiaki_regist_info_t
|
|||
|
||||
typedef struct chiaki_registered_host_t
|
||||
{
|
||||
ChiakiTarget target;
|
||||
char ap_ssid[0x30];
|
||||
char ap_bssid[0x20];
|
||||
char ap_key[0x50];
|
||||
char ap_name[0x20];
|
||||
uint8_t ps4_mac[6];
|
||||
char ps4_nickname[0x20];
|
||||
uint8_t server_mac[6];
|
||||
char server_nickname[0x20];
|
||||
char rp_regist_key[CHIAKI_SESSION_AUTH_SIZE]; // must be completely filled (pad with \0)
|
||||
uint32_t rp_key_type;
|
||||
uint8_t rp_key[0x10];
|
||||
|
|
|
@ -633,20 +633,22 @@ static ChiakiErrorCode regist_parse_response_payload(ChiakiRegist *regist, Chiak
|
|||
}
|
||||
|
||||
memset(host, 0, sizeof(*host));
|
||||
host->target = regist->info.target;
|
||||
|
||||
bool mac_found = false;
|
||||
bool regist_key_found = false;
|
||||
bool key_found = false;
|
||||
bool ps5 = chiaki_target_is_ps5(regist->info.target);
|
||||
|
||||
for(ChiakiHttpHeader *header=headers; header; header=header->next)
|
||||
{
|
||||
#define COPY_STRING(name, key_str) \
|
||||
if(strcmp(header->key, key_str) == 0) \
|
||||
if(strcmp(header->key, (key_str)) == 0) \
|
||||
{ \
|
||||
size_t len = strlen(header->value); \
|
||||
if(len >= sizeof(host->name)) \
|
||||
{ \
|
||||
CHIAKI_LOGE(regist->log, "Regist value for " key_str " in response is too long"); \
|
||||
CHIAKI_LOGE(regist->log, "Regist value for %s in response is too long", (key_str)); \
|
||||
continue; \
|
||||
} \
|
||||
memcpy(host->name, header->value, len); \
|
||||
|
@ -657,10 +659,10 @@ static ChiakiErrorCode regist_parse_response_payload(ChiakiRegist *regist, Chiak
|
|||
COPY_STRING(ap_bssid, "AP-Bssid")
|
||||
COPY_STRING(ap_key, "AP-Key")
|
||||
COPY_STRING(ap_name, "AP-Name")
|
||||
COPY_STRING(ps4_nickname, "PS4-Nickname")
|
||||
COPY_STRING(server_nickname, ps5 ? "PS5-Nickname" : "PS4-Nickname")
|
||||
#undef COPY_STRING
|
||||
|
||||
if(strcmp(header->key, "PS4-RegistKey") == 0)
|
||||
if(strcmp(header->key, ps5 ? "PS5-RegistKey" : "PS4-RegistKey") == 0)
|
||||
{
|
||||
memset(host->rp_regist_key, 0, sizeof(host->rp_regist_key));
|
||||
size_t buf_size = sizeof(host->rp_regist_key);
|
||||
|
@ -693,14 +695,14 @@ static ChiakiErrorCode regist_parse_response_payload(ChiakiRegist *regist, Chiak
|
|||
key_found = true;
|
||||
}
|
||||
}
|
||||
else if(strcmp(header->key, "PS4-Mac") == 0)
|
||||
else if(strcmp(header->key, ps5 ? "PS5-Mac" : "PS4-Mac") == 0)
|
||||
{
|
||||
size_t buf_size = sizeof(host->ps4_mac);
|
||||
err = parse_hex((uint8_t *)host->ps4_mac, &buf_size, header->value, strlen(header->value));
|
||||
if(err != CHIAKI_ERR_SUCCESS || buf_size != sizeof(host->ps4_mac))
|
||||
size_t buf_size = sizeof(host->server_mac);
|
||||
err = parse_hex((uint8_t *)host->server_mac, &buf_size, header->value, strlen(header->value));
|
||||
if(err != CHIAKI_ERR_SUCCESS || buf_size != sizeof(host->server_mac))
|
||||
{
|
||||
CHIAKI_LOGE(regist->log, "Regist received invalid MAC Address in response");
|
||||
memset(host->ps4_mac, 0, sizeof(host->ps4_mac));
|
||||
memset(host->server_mac, 0, sizeof(host->server_mac));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#define SESSION_EXPECT_TIMEOUT_MS 5000
|
||||
|
||||
static void *session_thread_func(void *arg);
|
||||
static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget *target_out);
|
||||
static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, ChiakiTarget *target_out);
|
||||
|
||||
const char *chiaki_rp_application_reason_string(uint32_t reason)
|
||||
{
|
||||
|
@ -369,20 +369,20 @@ static void *session_thread_func(void *arg)
|
|||
CHIAKI_LOGI(session->log, "Starting session request");
|
||||
|
||||
ChiakiTarget server_target = session->connect_info.ps5 ? CHIAKI_TARGET_PS5_UNKNOWN : CHIAKI_TARGET_PS4_UNKNOWN;
|
||||
success = session_thread_request_session(session, &server_target);
|
||||
success = session_thread_request_session(session, &server_target) == CHIAKI_ERR_SUCCESS;
|
||||
|
||||
if(!success && chiaki_target_is_unknown(server_target))
|
||||
{
|
||||
CHIAKI_LOGI(session->log, "Attempting to re-request session with Server's RP-Version");
|
||||
session->target = server_target;
|
||||
success = session_thread_request_session(session, &server_target);
|
||||
success = session_thread_request_session(session, &server_target) == CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
if(!success && chiaki_target_is_unknown(server_target))
|
||||
{
|
||||
CHIAKI_LOGI(session->log, "Attempting to re-request session even harder with Server's RP-Version!!!");
|
||||
session->target = server_target;
|
||||
success = session_thread_request_session(session, NULL);
|
||||
success = session_thread_request_session(session, NULL) == CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
if(!success)
|
||||
|
@ -569,7 +569,7 @@ static void parse_session_response(SessionResponse *response, ChiakiHttpResponse
|
|||
/**
|
||||
* @param target_out if NULL, version mismatch means to fail the entire session, otherwise report the target here
|
||||
*/
|
||||
static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget *target_out)
|
||||
static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, ChiakiTarget *target_out)
|
||||
{
|
||||
chiaki_socket_t session_sock = CHIAKI_INVALID_SOCKET;
|
||||
for(struct addrinfo *ai=session->connect_info.host_addrinfos; ai; ai=ai->ai_next)
|
||||
|
@ -690,6 +690,12 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
}
|
||||
|
||||
const char *rp_version_str = chiaki_rp_version_string(session->target);
|
||||
if(!rp_version_str)
|
||||
{
|
||||
CHIAKI_LOGE(session->log, "Failed to get version for target, probably invalid target value");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return CHIAKI_ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
char buf[512];
|
||||
int request_len = snprintf(buf, sizeof(buf), session_request_fmt,
|
||||
|
@ -698,7 +704,7 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
{
|
||||
CHIAKI_SOCKET_CLOSE(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
return CHIAKI_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(session->log, "Sending session request");
|
||||
|
@ -710,7 +716,7 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
CHIAKI_LOGE(session->log, "Failed to send session request");
|
||||
CHIAKI_SOCKET_CLOSE(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
||||
size_t header_size;
|
||||
|
@ -731,7 +737,7 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
}
|
||||
CHIAKI_SOCKET_CLOSE(session_sock);
|
||||
return false;
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
||||
ChiakiHttpResponse http_response;
|
||||
|
@ -743,7 +749,7 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
CHIAKI_LOGE(session->log, "Failed to parse session request response");
|
||||
CHIAKI_SOCKET_CLOSE(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
||||
SessionResponse response;
|
||||
|
@ -802,7 +808,7 @@ static bool session_thread_request_session(ChiakiSession *session, ChiakiTarget
|
|||
|
||||
chiaki_http_response_fini(&http_response);
|
||||
CHIAKI_SOCKET_CLOSE(session_sock);
|
||||
return response.success;
|
||||
return response.success ? CHIAKI_ERR_SUCCESS : CHIAKI_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_goto_bed(ChiakiSession *session)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue