[FL-3640] NFC: Felica UID emulation (#3190)
* Added basic template of Felica listener * Raw nfc felica listener functions * Added functions to setup chip for felica listener * Cleanup function templates from unnecessary parts * Removed todo comment * Updated api versions * Adjusted chip config for felica * Set proper chip passive target mode for felica * Added felica function to unit tests * Update furi_hal_nfc_felica.c * Removed duplication Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
co-authored by
gornekich
parent
4b3e8aba29
commit
1c3cbec661
@@ -14,6 +14,8 @@ extern "C" {
|
||||
#define FELICA_FDT_POLL_FC (10000U)
|
||||
#define FELICA_POLL_POLL_MIN_US (1280U)
|
||||
|
||||
#define FELICA_FDT_LISTEN_FC (1172)
|
||||
|
||||
#define FELICA_SYSTEM_CODE_CODE (0xFFFFU)
|
||||
#define FELICA_TIME_SLOT_1 (0x00U)
|
||||
#define FELICA_TIME_SLOT_2 (0x01U)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "felica_listener_i.h"
|
||||
|
||||
#include "nfc/protocols/nfc_listener_base.h"
|
||||
|
||||
#define FELICA_LISTENER_MAX_BUFFER_SIZE (64)
|
||||
#define TAG "Felica"
|
||||
|
||||
FelicaListener* felica_listener_alloc(Nfc* nfc, FelicaData* data) {
|
||||
furi_assert(nfc);
|
||||
furi_assert(data);
|
||||
|
||||
FelicaListener* instance = malloc(sizeof(FelicaListener));
|
||||
instance->nfc = nfc;
|
||||
instance->data = data;
|
||||
instance->tx_buffer = bit_buffer_alloc(FELICA_LISTENER_MAX_BUFFER_SIZE);
|
||||
instance->rx_buffer = bit_buffer_alloc(FELICA_LISTENER_MAX_BUFFER_SIZE);
|
||||
|
||||
nfc_set_fdt_listen_fc(instance->nfc, FELICA_FDT_LISTEN_FC);
|
||||
|
||||
nfc_config(instance->nfc, NfcModeListener, NfcTechFelica);
|
||||
nfc_felica_listener_set_sensf_res_data(
|
||||
nfc, data->idm.data, sizeof(data->idm), data->pmm.data, sizeof(data->pmm));
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void felica_listener_free(FelicaListener* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->tx_buffer);
|
||||
|
||||
bit_buffer_free(instance->tx_buffer);
|
||||
bit_buffer_free(instance->rx_buffer);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void felica_listener_set_callback(
|
||||
FelicaListener* listener,
|
||||
NfcGenericCallback callback,
|
||||
void* context) {
|
||||
UNUSED(listener);
|
||||
UNUSED(callback);
|
||||
UNUSED(context);
|
||||
}
|
||||
|
||||
const FelicaData* felica_listener_get_data(const FelicaListener* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->data);
|
||||
|
||||
return instance->data;
|
||||
}
|
||||
|
||||
NfcCommand felica_listener_run(NfcGenericEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(event.protocol == NfcProtocolInvalid);
|
||||
furi_assert(event.event_data);
|
||||
|
||||
FelicaListener* instance = context;
|
||||
NfcEvent* nfc_event = event.event_data;
|
||||
NfcCommand command = NfcCommandContinue;
|
||||
|
||||
if(nfc_event->type == NfcEventTypeListenerActivated) {
|
||||
instance->state = Felica_ListenerStateActivated;
|
||||
FURI_LOG_D(TAG, "Activated");
|
||||
} else if(nfc_event->type == NfcEventTypeFieldOff) {
|
||||
instance->state = Felica_ListenerStateIdle;
|
||||
FURI_LOG_D(TAG, "Field Off");
|
||||
} else if(nfc_event->type == NfcEventTypeRxEnd) {
|
||||
FURI_LOG_D(TAG, "Rx Done");
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
const NfcListenerBase nfc_listener_felica = {
|
||||
.alloc = (NfcListenerAlloc)felica_listener_alloc,
|
||||
.free = (NfcListenerFree)felica_listener_free,
|
||||
.set_callback = (NfcListenerSetCallback)felica_listener_set_callback,
|
||||
.get_data = (NfcListenerGetData)felica_listener_get_data,
|
||||
.run = (NfcListenerRun)felica_listener_run,
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "felica.h"
|
||||
#include <lib/nfc/nfc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct FelicaListener FelicaListener;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <nfc/protocols/nfc_listener_base.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const NfcListenerBase nfc_listener_felica;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "felica_listener.h"
|
||||
|
||||
#include <nfc/protocols/nfc_generic_event.h>
|
||||
|
||||
typedef enum {
|
||||
Felica_ListenerStateIdle,
|
||||
Felica_ListenerStateActivated,
|
||||
} FelicaListenerState;
|
||||
|
||||
struct FelicaListener {
|
||||
Nfc* nfc;
|
||||
FelicaData* data;
|
||||
FelicaListenerState state;
|
||||
|
||||
BitBuffer* tx_buffer;
|
||||
BitBuffer* rx_buffer;
|
||||
|
||||
NfcGenericEvent generic_event;
|
||||
NfcGenericCallback callback;
|
||||
void* context;
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <nfc/protocols/mf_ultralight/mf_ultralight_listener_defs.h>
|
||||
#include <nfc/protocols/mf_classic/mf_classic_listener_defs.h>
|
||||
#include <nfc/protocols/slix/slix_listener_defs.h>
|
||||
#include <nfc/protocols/felica/felica_listener_defs.h>
|
||||
|
||||
const NfcListenerBase* nfc_listeners_api[NfcProtocolNum] = {
|
||||
[NfcProtocolIso14443_3a] = &nfc_listener_iso14443_3a,
|
||||
@@ -18,4 +19,5 @@ const NfcListenerBase* nfc_listeners_api[NfcProtocolNum] = {
|
||||
[NfcProtocolMfDesfire] = NULL,
|
||||
[NfcProtocolSlix] = &nfc_listener_slix,
|
||||
[NfcProtocolSt25tb] = NULL,
|
||||
[NfcProtocolFelica] = &nfc_listener_felica,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user