|
|
@@ -399,7 +399,74 @@ NfcCommand passy_reader_state_machine(Passy* passy, PassyReader* passy_reader) {
|
|
|
body_offset += sizeof(chunk);
|
|
|
} while(body_offset < body_size);
|
|
|
passy_log_bitbuffer(TAG, "DG1", passy_reader->DG1);
|
|
|
+ } else if(passy->read_type == PassyReadDG7) {
|
|
|
+ ret = passy_reader_select_file(passy_reader, 0x0107);
|
|
|
+ if(ret != NfcCommandContinue) {
|
|
|
+ view_dispatcher_send_custom_event(
|
|
|
+ passy->view_dispatcher, PassyCustomEventReaderError);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ uint8_t header[100];
|
|
|
+ ret = passy_reader_read_binary(passy_reader, 0x00, sizeof(header), header);
|
|
|
+ if(ret != NfcCommandContinue) {
|
|
|
+ view_dispatcher_send_custom_event(
|
|
|
+ passy->view_dispatcher, PassyCustomEventReaderError);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ view_dispatcher_send_custom_event(
|
|
|
+ passy->view_dispatcher, PassyCustomEventReaderReading);
|
|
|
+
|
|
|
+ size_t body_size = asn1_length(header + 1);
|
|
|
+ FURI_LOG_I(TAG, "DG7 length: %d", body_size);
|
|
|
+
|
|
|
+ void* jpeg2k = memmem(header, sizeof(header), jpeg2k_header, sizeof(jpeg2k_header));
|
|
|
+ void* jpeg2k_cs =
|
|
|
+ memmem(header, sizeof(header), jpeg2k_cs_header, sizeof(jpeg2k_cs_header));
|
|
|
+
|
|
|
+ FuriString* path = furi_string_alloc();
|
|
|
+ uint8_t start = 0;
|
|
|
+
|
|
|
+ if(jpeg2k) {
|
|
|
+ furi_string_printf(path, "%s/%s%s", STORAGE_APP_DATA_PATH_PREFIX, "DG7", ".jp2");
|
|
|
+ start = (uint8_t*)jpeg2k - header;
|
|
|
+ } else if(jpeg2k_cs) {
|
|
|
+ furi_string_printf(path, "%s/%s%s", STORAGE_APP_DATA_PATH_PREFIX, "DG7", ".jpc");
|
|
|
+ start = (uint8_t*)jpeg2k_cs - header;
|
|
|
+ } else {
|
|
|
+ furi_string_printf(path, "%s/%s%s", STORAGE_APP_DATA_PATH_PREFIX, "DG7", ".bin");
|
|
|
+ start = 0;
|
|
|
+ passy_log_buffer(TAG, "header", header, sizeof(header));
|
|
|
+ }
|
|
|
+ FURI_LOG_I(TAG, "Writing offset %d to %s", start, furi_string_get_cstr(path));
|
|
|
+
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
+ Stream* stream = file_stream_alloc(storage);
|
|
|
+ file_stream_open(stream, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_ALWAYS);
|
|
|
+
|
|
|
+ uint8_t chunk[PASSY_READER_DG2_CHUNK_SIZE];
|
|
|
+ passy->offset = start;
|
|
|
+ passy->bytes_total = body_size;
|
|
|
+ do {
|
|
|
+ memset(chunk, 0, sizeof(chunk));
|
|
|
+ uint8_t Le = MIN(sizeof(chunk), (size_t)(body_size - passy->offset));
|
|
|
+
|
|
|
+ ret = passy_reader_read_binary(passy_reader, passy->offset, Le, chunk);
|
|
|
+ if(ret != NfcCommandContinue) {
|
|
|
+ view_dispatcher_send_custom_event(
|
|
|
+ passy->view_dispatcher, PassyCustomEventReaderError);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ passy->offset += sizeof(chunk);
|
|
|
+ // passy_log_buffer(TAG, "chunk", chunk, sizeof(chunk));
|
|
|
+ stream_write(stream, chunk, Le);
|
|
|
+ view_dispatcher_send_custom_event(
|
|
|
+ passy->view_dispatcher, PassyCustomEventReaderReading);
|
|
|
+ } while(passy->offset < body_size);
|
|
|
|
|
|
+ file_stream_close(stream);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+ furi_string_free(path);
|
|
|
} else if(passy->read_type == PassyReadDG2) {
|
|
|
ret = passy_reader_select_file(passy_reader, 0x0102);
|
|
|
if(ret != NfcCommandContinue) {
|