Skip to content

Commit

Permalink
asr: Add support for second Initiate request
Browse files Browse the repository at this point in the history
First observed in iBridgeOS 9.0. The first Initiate ASR packet (checksum_chunks = false)
requests 64 bytes of the IPSW at offset 0, after which another Initiate follows requesting
a switch to (checksum_chunks = true) and additional OOBData.
  • Loading branch information
fbrandstetter authored and nikias committed Sep 20, 2024
1 parent a31eb2b commit 4c7a6e5
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions src/asr.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,13 @@ void asr_free(asr_client_t asr)
}
}

int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
int asr_send_validation_packet_info(asr_client_t asr, uint64_t ipsw_size)
{
uint64_t length = 0;
char* command = NULL;
plist_t node = NULL;
plist_t packet = NULL;
plist_t packet_info = NULL;
plist_t payload_info = NULL;
int attempts = 0;

length = ipsw_file_size(file);

payload_info = plist_new_dict();
plist_t payload_info = plist_new_dict();
plist_dict_set_item(payload_info, "Port", plist_new_uint(1));
plist_dict_set_item(payload_info, "Size", plist_new_uint(length));
plist_dict_set_item(payload_info, "Size", plist_new_uint(ipsw_size));

packet_info = plist_new_dict();
plist_t packet_info = plist_new_dict();
if (asr->checksum_chunks) {
plist_dict_set_item(packet_info, "Checksum Chunk Size", plist_new_uint(ASR_CHECKSUM_CHUNK_SIZE));
}
Expand All @@ -230,12 +220,32 @@ int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
plist_dict_set_item(packet_info, "Version", plist_new_uint(ASR_VERSION));

if (asr_send(asr, packet_info)) {
error("ERROR: Unable to sent packet information to ASR\n");
plist_free(packet_info);
return -1;
}
plist_free(packet_info);

return 0;
}

int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
{
uint64_t length = 0;
char* command = NULL;
plist_t node = NULL;
plist_t packet = NULL;
plist_t packet_info = NULL;
plist_t payload_info = NULL;
int attempts = 0;

length = ipsw_file_size(file);

// Expected by device after every initiate
if (asr_send_validation_packet_info(asr, length) < 0) {
error("ERROR: Unable to send validation packet info to ASR\n");
return -1;
}

while (1) {
if (asr_receive(asr, &packet) < 0) {
error("ERROR: Unable to receive validation packet\n");
Expand All @@ -260,6 +270,25 @@ int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
}
plist_get_string_val(node, &command);

// Added for iBridgeOS 9.0 - second initiate request to change to checksum chunks
if (!strcmp(command, "Initiate")) {
// This might switch on the second Initiate
node = plist_dict_get_item(packet, "Checksum Chunks");
if (node && (plist_get_node_type(node) == PLIST_BOOLEAN)) {
plist_get_bool_val(node, &(asr->checksum_chunks));
}
plist_free(packet);

// Expected by device after every initiate
if (asr_send_validation_packet_info(asr, length) < 0) {
error("ERROR: Unable to send validation packet info to ASR\n");
return -1;
}

// A OOBData request should follow
continue;
}

if (!strcmp(command, "OOBData")) {
int ret = asr_handle_oob_data_request(asr, packet, file);
plist_free(packet);
Expand Down

0 comments on commit 4c7a6e5

Please sign in to comment.