Skip to content

Commit 4145e95

Browse files
fbrandstetternikias
authored andcommitted
asr: Add support for second Initiate request
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.
1 parent a31eb2b commit 4145e95

1 file changed

Lines changed: 43 additions & 16 deletions

File tree

src/asr.c

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,12 @@ void asr_free(asr_client_t asr)
202202
}
203203
}
204204

205-
int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
206-
{
207-
uint64_t length = 0;
208-
char* command = NULL;
209-
plist_t node = NULL;
210-
plist_t packet = NULL;
211-
plist_t packet_info = NULL;
212-
plist_t payload_info = NULL;
213-
int attempts = 0;
214-
215-
length = ipsw_file_size(file);
216-
217-
payload_info = plist_new_dict();
205+
int asr_send_validation_packet_info(asr_client_t asr, uint64_t ipsw_size) {
206+
plist_t payload_info = plist_new_dict();
218207
plist_dict_set_item(payload_info, "Port", plist_new_uint(1));
219-
plist_dict_set_item(payload_info, "Size", plist_new_uint(length));
208+
plist_dict_set_item(payload_info, "Size", plist_new_uint(ipsw_size));
220209

221-
packet_info = plist_new_dict();
210+
plist_t packet_info = plist_new_dict();
222211
if (asr->checksum_chunks) {
223212
plist_dict_set_item(packet_info, "Checksum Chunk Size", plist_new_uint(ASR_CHECKSUM_CHUNK_SIZE));
224213
}
@@ -230,11 +219,30 @@ int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
230219
plist_dict_set_item(packet_info, "Version", plist_new_uint(ASR_VERSION));
231220

232221
if (asr_send(asr, packet_info)) {
233-
error("ERROR: Unable to sent packet information to ASR\n");
234222
plist_free(packet_info);
235223
return -1;
236224
}
237225
plist_free(packet_info);
226+
plist_free(payload_info);
227+
228+
return 0;
229+
}
230+
231+
int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
232+
{
233+
uint64_t length = 0;
234+
char* command = NULL;
235+
plist_t node = NULL;
236+
plist_t packet = NULL;
237+
int attempts = 0;
238+
239+
length = ipsw_file_size(file);
240+
241+
// Expected by device after every initiate
242+
if (asr_send_validation_packet_info(asr, length) < 0) {
243+
error("ERROR: Unable to send validation packet info to ASR\n");
244+
return -1;
245+
}
238246

239247
while (1) {
240248
if (asr_receive(asr, &packet) < 0) {
@@ -260,6 +268,25 @@ int asr_perform_validation(asr_client_t asr, ipsw_file_handle_t file)
260268
}
261269
plist_get_string_val(node, &command);
262270

271+
// Added for iBridgeOS 9.0 - second initiate request to change to checksum chunks
272+
if (!strcmp(command, "Initiate")) {
273+
// This might switch on the second Initiate
274+
node = plist_dict_get_item(packet, "Checksum Chunks");
275+
if (node && (plist_get_node_type(node) == PLIST_BOOLEAN)) {
276+
plist_get_bool_val(node, &(asr->checksum_chunks));
277+
}
278+
plist_free(packet);
279+
280+
// Expected by device after every Initiate
281+
if (asr_send_validation_packet_info(asr, length) < 0) {
282+
error("ERROR: Unable to send validation packet info to ASR\n");
283+
return -1;
284+
}
285+
286+
// A OOBData request should follow
287+
continue;
288+
}
289+
263290
if (!strcmp(command, "OOBData")) {
264291
int ret = asr_handle_oob_data_request(asr, packet, file);
265292
plist_free(packet);

0 commit comments

Comments
 (0)