mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-14 00:37:21 +00:00
Merge branch 'ofw_dev' into dev
This commit is contained in:
commit
a7b2427007
18 changed files with 406 additions and 26 deletions
|
@ -455,4 +455,19 @@ NfcError nfc_iso15693_listener_tx_sof(Nfc* instance) {
|
|||
return NfcErrorNone;
|
||||
}
|
||||
|
||||
NfcError nfc_felica_listener_set_sensf_res_data(
|
||||
Nfc* instance,
|
||||
const uint8_t* idm,
|
||||
const uint8_t idm_len,
|
||||
const uint8_t* pmm,
|
||||
const uint8_t pmm_len) {
|
||||
furi_assert(instance);
|
||||
furi_assert(idm);
|
||||
furi_assert(pmm);
|
||||
furi_assert(idm_len == 8);
|
||||
furi_assert(pmm_len == 8);
|
||||
|
||||
return NfcErrorNone;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -67,8 +67,14 @@ static bool nfc_scene_saved_menu_on_event_felica(NfcApp* instance, uint32_t even
|
|||
return false;
|
||||
}
|
||||
|
||||
static void nfc_scene_emulate_on_enter_felica(NfcApp* instance) {
|
||||
const FelicaData* data = nfc_device_get_data(instance->nfc_device, NfcProtocolFelica);
|
||||
instance->listener = nfc_listener_alloc(instance->nfc, NfcProtocolFelica, data);
|
||||
nfc_listener_start(instance->listener, NULL, NULL);
|
||||
}
|
||||
|
||||
const NfcProtocolSupportBase nfc_protocol_support_felica = {
|
||||
.features = NfcProtocolFeatureNone,
|
||||
.features = NfcProtocolFeatureEmulateUid,
|
||||
|
||||
.scene_info =
|
||||
{
|
||||
|
@ -102,7 +108,7 @@ const NfcProtocolSupportBase nfc_protocol_support_felica = {
|
|||
},
|
||||
.scene_emulate =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_enter = nfc_scene_emulate_on_enter_felica,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -329,9 +329,23 @@ static void nfc_generate_mf_classic_uid(uint8_t* uid, uint8_t length) {
|
|||
static void
|
||||
nfc_generate_mf_classic_common(MfClassicData* data, uint8_t uid_len, MfClassicType type) {
|
||||
data->iso14443_3a_data->uid_len = uid_len;
|
||||
data->iso14443_3a_data->atqa[0] = 0x44;
|
||||
data->iso14443_3a_data->atqa[0] = 0x00;
|
||||
data->iso14443_3a_data->atqa[1] = 0x00;
|
||||
data->iso14443_3a_data->sak = 0x08;
|
||||
data->iso14443_3a_data->sak = 0x00;
|
||||
// Calculate the proper ATQA and SAK
|
||||
if(uid_len == 7) {
|
||||
data->iso14443_3a_data->atqa[0] |= 0x40;
|
||||
}
|
||||
if(type == MfClassicType1k) {
|
||||
data->iso14443_3a_data->atqa[0] |= 0x04;
|
||||
data->iso14443_3a_data->sak = 0x08;
|
||||
} else if(type == MfClassicType4k) {
|
||||
data->iso14443_3a_data->atqa[0] |= 0x02;
|
||||
data->iso14443_3a_data->sak = 0x18;
|
||||
} else if(type == MfClassicTypeMini) {
|
||||
data->iso14443_3a_data->atqa[0] |= 0x08;
|
||||
data->iso14443_3a_data->sak = 0x09;
|
||||
}
|
||||
data->type = type;
|
||||
}
|
||||
|
||||
|
@ -343,6 +357,11 @@ static void nfc_generate_mf_classic_sector_trailer(MfClassicData* data, uint8_t
|
|||
sec_tr->access_bits.data[2] = 0x80;
|
||||
sec_tr->access_bits.data[3] = 0x69; // Nice
|
||||
|
||||
for(int i = 0; i < 6; i++) {
|
||||
sec_tr->key_a.data[i] = 0xFF;
|
||||
sec_tr->key_b.data[i] = 0xFF;
|
||||
}
|
||||
|
||||
mf_classic_set_block_read(data, block, &data->block[block]);
|
||||
mf_classic_set_key_found(
|
||||
data, mf_classic_get_sector_by_block(block), MfClassicKeyTypeA, 0xFFFFFFFFFFFF);
|
||||
|
@ -396,41 +415,35 @@ static void nfc_generate_mf_classic(NfcDevice* nfc_device, uint8_t uid_len, MfCl
|
|||
|
||||
uint16_t block_num = mf_classic_get_total_block_num(type);
|
||||
if(type == MfClassicType4k) {
|
||||
// Set every block to 0xFF
|
||||
// Set every block to 0x00
|
||||
for(uint16_t i = 1; i < block_num; i++) {
|
||||
if(mf_classic_is_sector_trailer(i)) {
|
||||
nfc_generate_mf_classic_sector_trailer(mfc_data, i);
|
||||
} else {
|
||||
memset(&mfc_data->block[i].data, 0xFF, 16);
|
||||
memset(&mfc_data->block[i].data, 0x00, 16);
|
||||
}
|
||||
mf_classic_set_block_read(mfc_data, i, &mfc_data->block[i]);
|
||||
}
|
||||
// Set SAK to 18
|
||||
mfc_data->iso14443_3a_data->sak = 0x18;
|
||||
} else if(type == MfClassicType1k) {
|
||||
// Set every block to 0xFF
|
||||
// Set every block to 0x00
|
||||
for(uint16_t i = 1; i < block_num; i++) {
|
||||
if(mf_classic_is_sector_trailer(i)) {
|
||||
nfc_generate_mf_classic_sector_trailer(mfc_data, i);
|
||||
} else {
|
||||
memset(&mfc_data->block[i].data, 0xFF, 16);
|
||||
memset(&mfc_data->block[i].data, 0x00, 16);
|
||||
}
|
||||
mf_classic_set_block_read(mfc_data, i, &mfc_data->block[i]);
|
||||
}
|
||||
// Set SAK to 08
|
||||
mfc_data->iso14443_3a_data->sak = 0x08;
|
||||
} else if(type == MfClassicTypeMini) {
|
||||
// Set every block to 0xFF
|
||||
// Set every block to 0x00
|
||||
for(uint16_t i = 1; i < block_num; i++) {
|
||||
if(mf_classic_is_sector_trailer(i)) {
|
||||
nfc_generate_mf_classic_sector_trailer(mfc_data, i);
|
||||
} else {
|
||||
memset(&mfc_data->block[i].data, 0xFF, 16);
|
||||
memset(&mfc_data->block[i].data, 0x00, 16);
|
||||
}
|
||||
mf_classic_set_block_read(mfc_data, i, &mfc_data->block[i]);
|
||||
}
|
||||
// Set SAK to 09
|
||||
mfc_data->iso14443_3a_data->sak = 0x09;
|
||||
}
|
||||
|
||||
nfc_generate_mf_classic_block_0(
|
||||
|
|
|
@ -76,7 +76,7 @@ static const FuriHalNfcTech nfc_tech_table[NfcModeNum][NfcTechNum] = {
|
|||
[NfcTechIso14443a] = FuriHalNfcTechIso14443a,
|
||||
[NfcTechIso14443b] = FuriHalNfcTechInvalid,
|
||||
[NfcTechIso15693] = FuriHalNfcTechIso15693,
|
||||
[NfcTechFelica] = FuriHalNfcTechInvalid,
|
||||
[NfcTechFelica] = FuriHalNfcTechFelica,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -646,4 +646,20 @@ NfcError nfc_iso15693_listener_tx_sof(Nfc* instance) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
NfcError nfc_felica_listener_set_sensf_res_data(
|
||||
Nfc* instance,
|
||||
const uint8_t* idm,
|
||||
const uint8_t idm_len,
|
||||
const uint8_t* pmm,
|
||||
const uint8_t pmm_len) {
|
||||
furi_assert(instance);
|
||||
furi_assert(idm);
|
||||
furi_assert(pmm);
|
||||
|
||||
FuriHalNfcError error =
|
||||
furi_hal_nfc_felica_listener_set_sensf_res_data(idm, idm_len, pmm, pmm_len);
|
||||
instance->comm_state = NfcCommStateIdle;
|
||||
return nfc_process_hal_error(error);
|
||||
}
|
||||
|
||||
#endif // APP_UNIT_TESTS
|
||||
|
|
|
@ -351,6 +351,25 @@ NfcError nfc_iso14443a_listener_set_col_res_data(
|
|||
uint8_t* atqa,
|
||||
uint8_t sak);
|
||||
|
||||
/**
|
||||
* @brief Set FeliCa collision resolution parameters in listener mode.
|
||||
*
|
||||
* Configures the NFC hardware for automatic collision resolution.
|
||||
*
|
||||
* @param[in,out] instance pointer to the instance to be configured.
|
||||
* @param[in] idm pointer to a byte array containing the IDm.
|
||||
* @param[in] idm_len IDm length in bytes.
|
||||
* @param[in] pmm pointer to a byte array containing the PMm.
|
||||
* @param[in] pmm_len PMm length in bytes.
|
||||
* @returns NfcErrorNone on success, any other error code on failure.
|
||||
*/
|
||||
NfcError nfc_felica_listener_set_sensf_res_data(
|
||||
Nfc* instance,
|
||||
const uint8_t* idm,
|
||||
const uint8_t idm_len,
|
||||
const uint8_t* pmm,
|
||||
const uint8_t pmm_len);
|
||||
|
||||
/**
|
||||
* @brief Send ISO15693 Start of Frame pattern in listener mode
|
||||
*
|
||||
|
|
|
@ -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)
|
||||
|
|
79
lib/nfc/protocols/felica/felica_listener.c
Normal file
79
lib/nfc/protocols/felica/felica_listener.c
Normal file
|
@ -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,
|
||||
};
|
14
lib/nfc/protocols/felica/felica_listener.h
Normal file
14
lib/nfc/protocols/felica/felica_listener.h
Normal file
|
@ -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
|
13
lib/nfc/protocols/felica/felica_listener_defs.h
Normal file
13
lib/nfc/protocols/felica/felica_listener_defs.h
Normal file
|
@ -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
|
21
lib/nfc/protocols/felica/felica_listener_i.h
Normal file
21
lib/nfc/protocols/felica/felica_listener_i.h
Normal file
|
@ -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;
|
||||
};
|
|
@ -606,6 +606,7 @@ static bool mf_classic_is_allowed_access_sector_trailer(
|
|||
uint8_t* access_bits_arr = sec_tr->access_bits.data;
|
||||
uint8_t AC = ((access_bits_arr[1] >> 5) & 0x04) | ((access_bits_arr[2] >> 2) & 0x02) |
|
||||
((access_bits_arr[2] >> 7) & 0x01);
|
||||
FURI_LOG_T("NFC", "AC: %02X", AC);
|
||||
|
||||
switch(action) {
|
||||
case MfClassicActionKeyARead: {
|
||||
|
@ -615,20 +616,20 @@ static bool mf_classic_is_allowed_access_sector_trailer(
|
|||
case MfClassicActionKeyBWrite: {
|
||||
return (
|
||||
(key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x01)) ||
|
||||
(key_type == MfClassicKeyTypeB && (AC == 0x04 || AC == 0x03)));
|
||||
(key_type == MfClassicKeyTypeB &&
|
||||
(AC == 0x00 || AC == 0x04 || AC == 0x03 || AC == 0x01)));
|
||||
}
|
||||
case MfClassicActionKeyBRead: {
|
||||
return (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
|
||||
return (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x02 || AC == 0x01)) ||
|
||||
(key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x02 || AC == 0x01));
|
||||
}
|
||||
case MfClassicActionACRead: {
|
||||
return (
|
||||
(key_type == MfClassicKeyTypeA) ||
|
||||
(key_type == MfClassicKeyTypeB && !(AC == 0x00 || AC == 0x02 || AC == 0x01)));
|
||||
return ((key_type == MfClassicKeyTypeA) || (key_type == MfClassicKeyTypeB));
|
||||
}
|
||||
case MfClassicActionACWrite: {
|
||||
return (
|
||||
(key_type == MfClassicKeyTypeA && (AC == 0x01)) ||
|
||||
(key_type == MfClassicKeyTypeB && (AC == 0x03 || AC == 0x05)));
|
||||
(key_type == MfClassicKeyTypeB && (AC == 0x01 || AC == 0x03 || AC == 0x05)));
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -19,6 +19,8 @@ extern "C" {
|
|||
#define MF_CLASSIC_CMD_HALT_LSB (0x00)
|
||||
#define MF_CLASSIC_CMD_ACK (0x0A)
|
||||
#define MF_CLASSIC_CMD_NACK (0x00)
|
||||
#define MF_CLASSIC_CMD_NACK_TRANSFER_INVALID (0x04)
|
||||
#define MF_CLASSIC_CMD_NACK_TRANSFER_CRC_ERROR (0x01)
|
||||
|
||||
#define MF_CLASSIC_TOTAL_SECTORS_MAX (40)
|
||||
#define MF_CLASSIC_TOTAL_BLOCKS_MAX (256)
|
||||
|
|
|
@ -34,6 +34,7 @@ static void mf_classic_listener_reset_state(MfClassicListener* instance) {
|
|||
instance->cmd_in_progress = false;
|
||||
instance->current_cmd_handler_idx = 0;
|
||||
instance->transfer_value = 0;
|
||||
instance->transfer_valid = false;
|
||||
instance->value_cmd = MfClassicValueCommandInvalid;
|
||||
}
|
||||
|
||||
|
@ -154,7 +155,7 @@ static MfClassicListenerCommand
|
|||
uint32_t nt_num = nfc_util_bytes2num(instance->auth_context.nt.data, sizeof(MfClassicNt));
|
||||
uint32_t secret_poller = ar_num ^ crypto1_word(instance->crypto, 0, 0);
|
||||
if(secret_poller != prng_successor(nt_num, 64)) {
|
||||
FURI_LOG_D(
|
||||
FURI_LOG_T(
|
||||
TAG, "Wrong reader key: %08lX != %08lX", secret_poller, prng_successor(nt_num, 64));
|
||||
mf_classic_listener_reset_state(instance);
|
||||
break;
|
||||
|
@ -272,6 +273,17 @@ static MfClassicListenerCommand mf_classic_listener_write_block_second_part_hand
|
|||
|
||||
if(mf_classic_is_sector_trailer(block_num)) {
|
||||
MfClassicSectorTrailer* sec_tr = (MfClassicSectorTrailer*)█
|
||||
|
||||
// Check if any writing is allowed
|
||||
if(!mf_classic_is_allowed_access(
|
||||
instance->data, block_num, key_type, MfClassicActionKeyAWrite) &&
|
||||
!mf_classic_is_allowed_access(
|
||||
instance->data, block_num, key_type, MfClassicActionKeyBWrite) &&
|
||||
!mf_classic_is_allowed_access(
|
||||
instance->data, block_num, key_type, MfClassicActionACWrite)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(mf_classic_is_allowed_access(
|
||||
instance->data, block_num, key_type, MfClassicActionKeyAWrite)) {
|
||||
bit_buffer_write_bytes_mid(buff, sec_tr->key_a.data, 0, sizeof(MfClassicKey));
|
||||
|
@ -338,6 +350,7 @@ static MfClassicListenerCommand
|
|||
break;
|
||||
}
|
||||
|
||||
instance->transfer_valid = true;
|
||||
instance->cmd_in_progress = true;
|
||||
instance->current_cmd_handler_idx++;
|
||||
command = MfClassicListenerCommandAck;
|
||||
|
@ -382,6 +395,7 @@ static MfClassicListenerCommand
|
|||
}
|
||||
|
||||
instance->transfer_value += data;
|
||||
instance->transfer_valid = true;
|
||||
|
||||
instance->cmd_in_progress = true;
|
||||
instance->current_cmd_handler_idx++;
|
||||
|
@ -411,6 +425,7 @@ static MfClassicListenerCommand
|
|||
mf_classic_value_to_block(
|
||||
instance->transfer_value, block_num, &instance->data->block[block_num]);
|
||||
instance->transfer_value = 0;
|
||||
instance->transfer_valid = false;
|
||||
|
||||
command = MfClassicListenerCommandAck;
|
||||
} while(false);
|
||||
|
@ -581,7 +596,13 @@ NfcCommand mf_classic_listener_run(NfcGenericEvent event, void* context) {
|
|||
if(mfc_command == MfClassicListenerCommandAck) {
|
||||
mf_classic_listener_send_short_frame(instance, MF_CLASSIC_CMD_ACK);
|
||||
} else if(mfc_command == MfClassicListenerCommandNack) {
|
||||
mf_classic_listener_send_short_frame(instance, MF_CLASSIC_CMD_NACK);
|
||||
// Calculate nack based on the transfer buffer validity
|
||||
uint8_t nack = MF_CLASSIC_CMD_NACK;
|
||||
if(!instance->transfer_valid) {
|
||||
nack += MF_CLASSIC_CMD_NACK_TRANSFER_INVALID;
|
||||
}
|
||||
|
||||
mf_classic_listener_send_short_frame(instance, nack);
|
||||
} else if(mfc_command == MfClassicListenerCommandSilent) {
|
||||
command = NfcCommandReset;
|
||||
} else if(mfc_command == MfClassicListenerCommandSleep) {
|
||||
|
|
|
@ -42,6 +42,7 @@ struct MfClassicListener {
|
|||
|
||||
// Value operation data
|
||||
int32_t transfer_value;
|
||||
bool transfer_valid;
|
||||
MfClassicValueCommand value_cmd;
|
||||
|
||||
NfcGenericEvent generic_event;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -1317,6 +1317,7 @@ Function,+,furi_hal_nfc_abort,FuriHalNfcError,
|
|||
Function,+,furi_hal_nfc_acquire,FuriHalNfcError,
|
||||
Function,+,furi_hal_nfc_event_start,FuriHalNfcError,
|
||||
Function,+,furi_hal_nfc_event_stop,FuriHalNfcError,
|
||||
Function,+,furi_hal_nfc_felica_listener_set_sensf_res_data,FuriHalNfcError,"const uint8_t*, const uint8_t, const uint8_t*, const uint8_t"
|
||||
Function,+,furi_hal_nfc_field_detect_start,FuriHalNfcError,
|
||||
Function,+,furi_hal_nfc_field_detect_stop,FuriHalNfcError,
|
||||
Function,+,furi_hal_nfc_field_is_present,_Bool,
|
||||
|
@ -2355,6 +2356,7 @@ Function,+,nfc_dict_get_next_key,_Bool,"NfcDict*, uint8_t*, size_t"
|
|||
Function,+,nfc_dict_get_total_keys,uint32_t,NfcDict*
|
||||
Function,+,nfc_dict_is_key_present,_Bool,"NfcDict*, const uint8_t*, size_t"
|
||||
Function,+,nfc_dict_rewind,_Bool,NfcDict*
|
||||
Function,+,nfc_felica_listener_set_sensf_res_data,NfcError,"Nfc*, const uint8_t*, const uint8_t, const uint8_t*, const uint8_t"
|
||||
Function,+,nfc_free,void,Nfc*
|
||||
Function,+,nfc_iso14443a_listener_set_col_res_data,NfcError,"Nfc*, uint8_t*, uint8_t, uint8_t*, uint8_t"
|
||||
Function,+,nfc_iso14443a_listener_tx_custom_parity,NfcError,"Nfc*, const BitBuffer*"
|
||||
|
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "furi_hal_nfc_i.h"
|
||||
#include "furi_hal_nfc_tech_i.h"
|
||||
|
||||
// Prevent FDT timer from starting
|
||||
#define FURI_HAL_NFC_FELICA_LISTENER_FDT_COMP_FC (INT32_MAX)
|
||||
|
||||
static FuriHalNfcError furi_hal_nfc_felica_poller_init(FuriHalSpiBusHandle* handle) {
|
||||
// Enable Felica mode, AM modulation
|
||||
st25r3916_change_reg_bits(
|
||||
|
@ -50,6 +53,126 @@ static FuriHalNfcError furi_hal_nfc_felica_poller_deinit(FuriHalSpiBusHandle* ha
|
|||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
static FuriHalNfcError furi_hal_nfc_felica_listener_init(FuriHalSpiBusHandle* handle) {
|
||||
furi_assert(handle);
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_OP_CONTROL,
|
||||
ST25R3916_REG_OP_CONTROL_en | ST25R3916_REG_OP_CONTROL_rx_en |
|
||||
ST25R3916_REG_OP_CONTROL_en_fd_auto_efd);
|
||||
|
||||
// Enable Target Felica mode, AM modulation
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_MODE,
|
||||
ST25R3916_REG_MODE_targ_targ | ST25R3916_REG_MODE_om2 | ST25R3916_REG_MODE_tr_am);
|
||||
|
||||
st25r3916_change_reg_bits(
|
||||
handle,
|
||||
ST25R3916_REG_BIT_RATE,
|
||||
ST25R3916_REG_BIT_RATE_txrate_mask | ST25R3916_REG_BIT_RATE_rxrate_mask,
|
||||
ST25R3916_REG_BIT_RATE_txrate_212 | ST25R3916_REG_BIT_RATE_rxrate_212);
|
||||
|
||||
// Receive configuration
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_RX_CONF1,
|
||||
ST25R3916_REG_RX_CONF1_lp0 | ST25R3916_REG_RX_CONF1_hz_12_80khz);
|
||||
|
||||
// AGC enabled, ratio 3:1, squelch after TX
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_RX_CONF2,
|
||||
ST25R3916_REG_RX_CONF2_agc6_3 | ST25R3916_REG_RX_CONF2_agc_m |
|
||||
ST25R3916_REG_RX_CONF2_agc_en | ST25R3916_REG_RX_CONF2_sqm_dyn);
|
||||
// HF operation, full gain on AM and PM channels
|
||||
st25r3916_write_reg(handle, ST25R3916_REG_RX_CONF3, 0x00);
|
||||
// No gain reduction on AM and PM channels
|
||||
st25r3916_write_reg(handle, ST25R3916_REG_RX_CONF4, 0x00);
|
||||
// 10% ASK modulation
|
||||
st25r3916_write_reg(handle, ST25R3916_REG_TX_DRIVER, ST25R3916_REG_TX_DRIVER_am_mod_10percent);
|
||||
|
||||
// Correlator setup
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_CORR_CONF1,
|
||||
ST25R3916_REG_CORR_CONF1_corr_s6 | ST25R3916_REG_CORR_CONF1_corr_s4 |
|
||||
ST25R3916_REG_CORR_CONF1_corr_s2);
|
||||
|
||||
// Sleep mode disable, 424kHz mode off
|
||||
st25r3916_write_reg(handle, ST25R3916_REG_CORR_CONF2, 0x00);
|
||||
|
||||
st25r3916_write_reg(handle, ST25R3916_REG_MASK_RX_TIMER, 0x02);
|
||||
|
||||
st25r3916_direct_cmd(handle, ST25R3916_CMD_STOP);
|
||||
uint32_t interrupts =
|
||||
(ST25R3916_IRQ_MASK_FWL | ST25R3916_IRQ_MASK_TXE | ST25R3916_IRQ_MASK_RXS |
|
||||
ST25R3916_IRQ_MASK_RXE | ST25R3916_IRQ_MASK_PAR | ST25R3916_IRQ_MASK_CRC |
|
||||
ST25R3916_IRQ_MASK_ERR1 | ST25R3916_IRQ_MASK_ERR2 | ST25R3916_IRQ_MASK_NRE |
|
||||
ST25R3916_IRQ_MASK_EON | ST25R3916_IRQ_MASK_EOF | ST25R3916_IRQ_MASK_WU_A_X |
|
||||
ST25R3916_IRQ_MASK_WU_A);
|
||||
// Clear interrupts
|
||||
st25r3916_get_irq(handle);
|
||||
|
||||
st25r3916_write_reg(
|
||||
handle,
|
||||
ST25R3916_REG_PASSIVE_TARGET,
|
||||
ST25R3916_REG_PASSIVE_TARGET_d_106_ac_a | ST25R3916_REG_PASSIVE_TARGET_d_ac_ap2p |
|
||||
ST25R3916_REG_PASSIVE_TARGET_fdel_1);
|
||||
// Enable interrupts
|
||||
st25r3916_mask_irq(handle, ~interrupts);
|
||||
st25r3916_direct_cmd(handle, ST25R3916_CMD_GOTO_SENSE);
|
||||
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
static FuriHalNfcError furi_hal_nfc_felica_listener_deinit(FuriHalSpiBusHandle* handle) {
|
||||
UNUSED(handle);
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
static FuriHalNfcEvent furi_hal_nfc_felica_listener_wait_event(uint32_t timeout_ms) {
|
||||
UNUSED(timeout_ms);
|
||||
FuriHalNfcEvent event = furi_hal_nfc_wait_event_common(timeout_ms);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
FuriHalNfcError furi_hal_nfc_felica_listener_tx(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
const uint8_t* tx_data,
|
||||
size_t tx_bits) {
|
||||
UNUSED(handle);
|
||||
UNUSED(tx_data);
|
||||
UNUSED(tx_bits);
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
FuriHalNfcError furi_hal_nfc_felica_listener_sleep(FuriHalSpiBusHandle* handle) {
|
||||
UNUSED(handle);
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
FuriHalNfcError furi_hal_nfc_felica_listener_idle(FuriHalSpiBusHandle* handle) {
|
||||
UNUSED(handle);
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
FuriHalNfcError furi_hal_nfc_felica_listener_set_sensf_res_data(
|
||||
const uint8_t* idm,
|
||||
const uint8_t idm_len,
|
||||
const uint8_t* pmm,
|
||||
const uint8_t pmm_len) {
|
||||
FuriHalSpiBusHandle* handle = &furi_hal_spi_bus_handle_nfc;
|
||||
// Write PT Memory
|
||||
uint8_t pt_memory[19] = {};
|
||||
pt_memory[2] = 0x01;
|
||||
memcpy(pt_memory + 3, idm, idm_len);
|
||||
memcpy(pt_memory + 3 + idm_len, pmm, pmm_len);
|
||||
st25r3916_write_ptf_mem(handle, pt_memory, sizeof(pt_memory));
|
||||
return FuriHalNfcErrorNone;
|
||||
}
|
||||
|
||||
const FuriHalNfcTechBase furi_hal_nfc_felica = {
|
||||
.poller =
|
||||
{
|
||||
|
@ -65,5 +188,18 @@ const FuriHalNfcTechBase furi_hal_nfc_felica = {
|
|||
.rx = furi_hal_nfc_common_fifo_rx,
|
||||
},
|
||||
|
||||
.listener = {},
|
||||
.listener =
|
||||
{
|
||||
.compensation =
|
||||
{
|
||||
.fdt = FURI_HAL_NFC_FELICA_LISTENER_FDT_COMP_FC,
|
||||
},
|
||||
.init = furi_hal_nfc_felica_listener_init,
|
||||
.deinit = furi_hal_nfc_felica_listener_deinit,
|
||||
.wait_event = furi_hal_nfc_felica_listener_wait_event,
|
||||
.tx = furi_hal_nfc_felica_listener_tx,
|
||||
.rx = furi_hal_nfc_common_fifo_rx,
|
||||
.sleep = furi_hal_nfc_felica_listener_sleep,
|
||||
.idle = furi_hal_nfc_felica_listener_idle,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -452,6 +452,23 @@ FuriHalNfcError furi_hal_nfc_iso14443a_listener_tx_custom_parity(
|
|||
*/
|
||||
FuriHalNfcError furi_hal_nfc_iso15693_listener_tx_sof();
|
||||
|
||||
/**
|
||||
* @brief Set FeliCa collision resolution parameters in listener mode.
|
||||
*
|
||||
* Configures the NFC hardware for automatic collision resolution.
|
||||
*
|
||||
* @param[in] idm pointer to a byte array containing the IDm.
|
||||
* @param[in] idm_len IDm length in bytes.
|
||||
* @param[in] pmm pointer to a byte array containing the PMm.
|
||||
* @param[in] pmm_len PMm length in bytes.
|
||||
* @returns NfcErrorNone on success, any other error code on failure.
|
||||
*/
|
||||
FuriHalNfcError furi_hal_nfc_felica_listener_set_sensf_res_data(
|
||||
const uint8_t* idm,
|
||||
const uint8_t idm_len,
|
||||
const uint8_t* pmm,
|
||||
const uint8_t pmm_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue