mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
* SimpleArray attached to FelicaData * tx rx done. response parsing done (in log) * dynamic vector as buffer. rendering begin * On screen render for directory tree * flags in render to indicate is_public_readable * beautify render flags * format * offload dynamic vector into individual files * saving. exposed dir tree writing for double use * save: additional formatting * save: clean up and some additional notes * load done * delete unnecessary debug log * Load: safer way to handle backward compatibility `parsed` being true is only contingent on whether the header (device type, UID, etc) are correctly read. The detailed data can be absent if saved from previous versions. Side effects: 1. The data format version number must not increment. 2. Newer sections of dumps must be appended in the end of the file. * format * handle block reading according to IC type Old version was aimed for FeliCa Lite dumping, which doesn't apply to FeliCa standard. Thus they need to be diverged in the poller run workflow. * read block content works. rendering begin * Render Refactor: dir & dump view from submenu * Render: show IC type name * IC parsing function cleanup * Revert "IC parsing function cleanup" This reverts commit ee3f7bf125b54b10d238b0aeb657ba15f27f93ba. * Load: Standard dump. Fully backward compatible * format * sync API version * format saved file * delete unused variable * clean ups * IC type addition * correction * beautify attribute parsing * correction * Lite save: delete extra line * correction: FeliCa link in Lite-S mode * format * Save: simplify printing * update IC type parsing * conform to api standard: const resp ptr to ptr also slightly faster and more readable block dump loop * disambiguate workflow type vs ic type It was too confusing to have the ic name string telling you one thing and ic_type enum saying the other. Might as well use better naming to indicate the use case for the two things * beautify on device render * reject dynamic_vector, embrace m-array * lint * use full variable name * partial fix: poller context's data proper init * edit unit test dump IC code and a small bug fix for the Lite auth workflow * unit test felica dump PMm correction * Fixes for static analysis warnings --------- Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: hedger <hedger@users.noreply.github.com>
74 lines
2.4 KiB
C
74 lines
2.4 KiB
C
#include "felica_poller_sync.h"
|
|
|
|
#include "felica_poller_i.h"
|
|
#include <nfc/nfc_poller.h>
|
|
|
|
#include <furi/furi.h>
|
|
|
|
#define FELICA_POLLER_FLAG_COMMAND_COMPLETE (1UL << 0)
|
|
|
|
typedef struct {
|
|
FelicaAuthenticationContext auth_ctx;
|
|
FuriThreadId thread_id;
|
|
FelicaError error;
|
|
FelicaPollerContextData data;
|
|
} FelicaPollerContext;
|
|
|
|
NfcCommand felica_poller_read_callback(NfcGenericEvent event, void* context) {
|
|
furi_assert(context);
|
|
furi_assert(event.event_data);
|
|
furi_assert(event.instance);
|
|
furi_assert(event.protocol == NfcProtocolFelica);
|
|
|
|
FelicaPollerContext* poller_context = context;
|
|
FelicaPoller* felica_poller = event.instance;
|
|
|
|
FelicaPollerEvent* felica_event = event.event_data;
|
|
|
|
if(felica_event->type == FelicaPollerEventTypeReady ||
|
|
felica_event->type == FelicaPollerEventTypeIncomplete) {
|
|
felica_copy(poller_context->data.data, felica_poller->data);
|
|
} else if(felica_event->type == FelicaPollerEventTypeRequestAuthContext) {
|
|
felica_event->data->auth_context->skip_auth = poller_context->auth_ctx.skip_auth;
|
|
memcpy(
|
|
felica_event->data->auth_context->card_key.data,
|
|
poller_context->auth_ctx.card_key.data,
|
|
FELICA_DATA_BLOCK_SIZE);
|
|
}
|
|
|
|
furi_thread_flags_set(poller_context->thread_id, FELICA_POLLER_FLAG_COMMAND_COMPLETE);
|
|
|
|
return NfcCommandStop;
|
|
}
|
|
|
|
FelicaError felica_poller_sync_read(Nfc* nfc, FelicaData* data, const FelicaCardKey* card_key) {
|
|
furi_check(nfc);
|
|
furi_check(data);
|
|
|
|
FelicaPollerContext poller_context = {};
|
|
if(card_key == NULL) {
|
|
poller_context.auth_ctx.skip_auth = true;
|
|
} else {
|
|
poller_context.auth_ctx.skip_auth = false;
|
|
memcpy(poller_context.auth_ctx.card_key.data, card_key->data, FELICA_DATA_BLOCK_SIZE);
|
|
}
|
|
|
|
poller_context.thread_id = furi_thread_get_current_id();
|
|
poller_context.data.data = felica_alloc();
|
|
NfcPoller* poller = nfc_poller_alloc(nfc, NfcProtocolFelica);
|
|
nfc_poller_start(poller, felica_poller_read_callback, &poller_context);
|
|
furi_thread_flags_wait(FELICA_POLLER_FLAG_COMMAND_COMPLETE, FuriFlagWaitAny, FuriWaitForever);
|
|
furi_thread_flags_clear(FELICA_POLLER_FLAG_COMMAND_COMPLETE);
|
|
|
|
nfc_poller_stop(poller);
|
|
nfc_poller_free(poller);
|
|
|
|
if(poller_context.error == FelicaErrorNone) {
|
|
felica_copy(data, poller_context.data.data);
|
|
}
|
|
|
|
felica_free(poller_context.data.data);
|
|
|
|
return poller_context.error;
|
|
}
|