mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
* Moved some structs and defs from poller to generic felica * Buffer size increased for transferring more data * Felica HAL Tx function implemented * Some structs and fields for listener * Raw listener implementation * Added new event for felica activation * Proper config fot listener added * Moved some structs from poller in order to use them in listener too * New function for calculating MAC * Listener data structures and function definitions * Private listener functions implementation added * Raw felica listener logic implementation added * Fix total sector count both for poller and listener * Defined type for write handlers * New logic for write operations added * Removed old commented code * Splitted read logic into several separate functions * New type added and some fields to instance * New logic of read command implemented * Defines added for response codes * Functions moved to private namespace * Function visibility changed and some cleanups * Update felica_listener.c, felica_listener_i.c, and felica_listener_i.h * Some type adjustments * Moved frame_exchange function to private namespace * Error handling added * Function to get data_ptr for write request added * Missing declaration added * Add processing of nfc errors * write_with_mac is a local variable now * Adjustments to MAC calculation logic * Values replaced with defines * Update nfc_transport.c with felica logic * Sync felica poller added for unit tests * Felica unit_tests and data dump added * Fixed proper reading of MAC_A block when it is 1st * Macro definitions for MC added * Function simplified * More defines * CRC check for incomming packets added * Readonly logic adjusted * Block write validation adjusted * New logic for ID block writing * Some cleanups * New logic of moving across the block list with different element length * Some cleanups * Adjusted requires_mac logic to cover all blocks needed * Cleanups and renaming * New block list validation logic * Block list logic iteration simplified * Some asserts and checks added * Replaced MC[2] checks with macros * Marked def values as unsigned * Removed old code * Removed commented function declarations * Changed protected block in felica test card dump and adjusted tests * Fixes after merge * Moved defines to header * Now we allocate memory for max possible response pack in any case * Some renaming and documentation * Bump api symbols * Set feature to emulate full for felica * Removed 'More' button and added MoreInfo feature which adds this button back * Types renamed * Removed unnecessary code * Reformat comments * Fixing missing signatures * Replaced crash with error log and return value * Format doxygen comments Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
121 lines
4.1 KiB
C
121 lines
4.1 KiB
C
#include <furi_hal_nfc_i.h>
|
|
|
|
FuriHalNfcEventInternal* furi_hal_nfc_event = NULL;
|
|
|
|
void furi_hal_nfc_event_init(void) {
|
|
furi_hal_nfc_event = malloc(sizeof(FuriHalNfcEventInternal));
|
|
}
|
|
|
|
FuriHalNfcError furi_hal_nfc_event_start(void) {
|
|
furi_check(furi_hal_nfc_event);
|
|
|
|
furi_hal_nfc_event->thread = furi_thread_get_current_id();
|
|
furi_thread_flags_clear(FURI_HAL_NFC_EVENT_INTERNAL_ALL);
|
|
|
|
return FuriHalNfcErrorNone;
|
|
}
|
|
|
|
FuriHalNfcError furi_hal_nfc_event_stop(void) {
|
|
furi_check(furi_hal_nfc_event);
|
|
|
|
furi_hal_nfc_event->thread = NULL;
|
|
|
|
return FuriHalNfcErrorNone;
|
|
}
|
|
|
|
void furi_hal_nfc_event_set(FuriHalNfcEventInternalType event) {
|
|
furi_check(furi_hal_nfc_event);
|
|
|
|
if(furi_hal_nfc_event->thread) {
|
|
furi_thread_flags_set(furi_hal_nfc_event->thread, event);
|
|
}
|
|
}
|
|
|
|
FuriHalNfcError furi_hal_nfc_abort(void) {
|
|
furi_hal_nfc_event_set(FuriHalNfcEventInternalTypeAbort);
|
|
return FuriHalNfcErrorNone;
|
|
}
|
|
|
|
FuriHalNfcEvent furi_hal_nfc_wait_event_common(uint32_t timeout_ms) {
|
|
furi_check(furi_hal_nfc_event);
|
|
furi_check(furi_hal_nfc_event->thread);
|
|
|
|
FuriHalNfcEvent event = 0;
|
|
uint32_t event_timeout = timeout_ms == FURI_HAL_NFC_EVENT_WAIT_FOREVER ? FuriWaitForever :
|
|
timeout_ms;
|
|
uint32_t event_flag =
|
|
furi_thread_flags_wait(FURI_HAL_NFC_EVENT_INTERNAL_ALL, FuriFlagWaitAny, event_timeout);
|
|
if(event_flag != (unsigned)FuriFlagErrorTimeout) {
|
|
if(event_flag & FuriHalNfcEventInternalTypeIrq) {
|
|
furi_thread_flags_clear(FuriHalNfcEventInternalTypeIrq);
|
|
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;
|
|
uint32_t irq = furi_hal_nfc_get_irq(handle);
|
|
if(irq & ST25R3916_IRQ_MASK_OSC) {
|
|
event |= FuriHalNfcEventOscOn;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_TXE) {
|
|
event |= FuriHalNfcEventTxEnd;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_RXS) {
|
|
event |= FuriHalNfcEventRxStart;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_RXE) {
|
|
event |= FuriHalNfcEventRxEnd;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_COL) {
|
|
event |= FuriHalNfcEventCollision;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_EON) {
|
|
event |= FuriHalNfcEventFieldOn;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_EOF) {
|
|
event |= FuriHalNfcEventFieldOff;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_WU_A) {
|
|
event |= FuriHalNfcEventListenerActive;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_WU_A_X) {
|
|
event |= FuriHalNfcEventListenerActive;
|
|
}
|
|
if(irq & ST25R3916_IRQ_MASK_WU_F) {
|
|
event |= FuriHalNfcEventListenerActive;
|
|
}
|
|
}
|
|
if(event_flag & FuriHalNfcEventInternalTypeTimerFwtExpired) {
|
|
event |= FuriHalNfcEventTimerFwtExpired;
|
|
furi_thread_flags_clear(FuriHalNfcEventInternalTypeTimerFwtExpired);
|
|
}
|
|
if(event_flag & FuriHalNfcEventInternalTypeTimerBlockTxExpired) {
|
|
event |= FuriHalNfcEventTimerBlockTxExpired;
|
|
furi_thread_flags_clear(FuriHalNfcEventInternalTypeTimerBlockTxExpired);
|
|
}
|
|
if(event_flag & FuriHalNfcEventInternalTypeAbort) {
|
|
event |= FuriHalNfcEventAbortRequest;
|
|
furi_thread_flags_clear(FuriHalNfcEventInternalTypeAbort);
|
|
}
|
|
} else {
|
|
event = FuriHalNfcEventTimeout;
|
|
}
|
|
|
|
return event;
|
|
}
|
|
|
|
bool furi_hal_nfc_event_wait_for_specific_irq(
|
|
FuriHalSpiBusHandle* handle,
|
|
uint32_t mask,
|
|
uint32_t timeout_ms) {
|
|
furi_check(furi_hal_nfc_event);
|
|
furi_check(furi_hal_nfc_event->thread);
|
|
|
|
bool irq_received = false;
|
|
uint32_t event_flag =
|
|
furi_thread_flags_wait(FuriHalNfcEventInternalTypeIrq, FuriFlagWaitAny, timeout_ms);
|
|
if(event_flag == FuriHalNfcEventInternalTypeIrq) {
|
|
uint32_t irq = furi_hal_nfc_get_irq(handle);
|
|
irq_received = ((irq & mask) == mask);
|
|
furi_thread_flags_clear(FuriHalNfcEventInternalTypeIrq);
|
|
}
|
|
|
|
return irq_received;
|
|
}
|