2022-09-03 15:25:36 +03:00
|
|
|
#include "nfc_debug_log.h"
|
|
|
|
|
|
|
|
#include <storage/storage.h>
|
|
|
|
#include <stream/buffered_file_stream.h>
|
|
|
|
|
|
|
|
#define TAG "NfcDebugLog"
|
|
|
|
|
|
|
|
#define NFC_DEBUG_PCAP_FILENAME EXT_PATH("nfc/debug.txt")
|
|
|
|
|
|
|
|
struct NfcDebugLog {
|
|
|
|
Stream* file_stream;
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* data_str;
|
2022-09-03 15:25:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NfcDebugLog* nfc_debug_log_alloc() {
|
|
|
|
NfcDebugLog* instance = malloc(sizeof(NfcDebugLog));
|
|
|
|
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
instance->file_stream = buffered_file_stream_alloc(storage);
|
|
|
|
|
|
|
|
if(!buffered_file_stream_open(
|
|
|
|
instance->file_stream, NFC_DEBUG_PCAP_FILENAME, FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
|
|
|
buffered_file_stream_close(instance->file_stream);
|
|
|
|
stream_free(instance->file_stream);
|
|
|
|
instance->file_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!instance->file_stream) {
|
|
|
|
free(instance);
|
|
|
|
instance = NULL;
|
|
|
|
} else {
|
2022-10-05 18:15:23 +03:00
|
|
|
instance->data_str = furi_string_alloc();
|
2022-09-03 15:25:36 +03:00
|
|
|
}
|
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_debug_log_free(NfcDebugLog* instance) {
|
|
|
|
furi_assert(instance);
|
|
|
|
furi_assert(instance->file_stream);
|
|
|
|
furi_assert(instance->data_str);
|
|
|
|
|
|
|
|
buffered_file_stream_close(instance->file_stream);
|
|
|
|
stream_free(instance->file_stream);
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(instance->data_str);
|
2022-09-03 15:25:36 +03:00
|
|
|
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_debug_log_process_data(
|
|
|
|
NfcDebugLog* instance,
|
|
|
|
uint8_t* data,
|
|
|
|
uint16_t len,
|
|
|
|
bool reader_to_tag,
|
|
|
|
bool crc_dropped) {
|
|
|
|
furi_assert(instance);
|
|
|
|
furi_assert(instance->file_stream);
|
|
|
|
furi_assert(instance->data_str);
|
|
|
|
furi_assert(data);
|
|
|
|
UNUSED(crc_dropped);
|
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_printf(instance->data_str, "%lu %c:", furi_get_tick(), reader_to_tag ? 'R' : 'T');
|
2022-09-03 15:25:36 +03:00
|
|
|
uint16_t data_len = len;
|
|
|
|
for(size_t i = 0; i < data_len; i++) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_cat_printf(instance->data_str, " %02x", data[i]);
|
2022-09-03 15:25:36 +03:00
|
|
|
}
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_push_back(instance->data_str, '\n');
|
2022-09-03 15:25:36 +03:00
|
|
|
|
|
|
|
stream_write_string(instance->file_stream, instance->data_str);
|
|
|
|
}
|