MFC emulation fixes (#3324)

* mf classic listener: fix write block
* nfc: go to idle state instead of sleep
* lib nfc: fix documentation
This commit is contained in:
gornekich 2023-12-29 07:24:20 +04:00 committed by GitHub
parent 895694c624
commit a7b60bf2a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 14 deletions

View file

@ -150,7 +150,7 @@ static int32_t nfc_worker_listener(void* context) {
} else if(command == NfcCommandReset) {
furi_hal_nfc_listener_enable_rx();
} else if(command == NfcCommandSleep) {
furi_hal_nfc_listener_sleep();
furi_hal_nfc_listener_idle();
}
}
}

View file

@ -18,8 +18,8 @@ typedef struct FelicaPoller FelicaPoller;
* @brief Enumeration of possible Felica poller event types.
*/
typedef enum {
FelicaPollerEventTypeError, /**< The card was activated by the poller. */
FelicaPollerEventTypeReady, /**< An error occured during activation procedure. */
FelicaPollerEventTypeError, /**< An error occured during activation procedure. */
FelicaPollerEventTypeReady, /**< The card was activated by the poller. */
} FelicaPollerEventType;
/**

View file

@ -18,8 +18,8 @@ typedef struct Iso14443_3aPoller Iso14443_3aPoller;
* @brief Enumeration of possible Iso14443_3a poller event types.
*/
typedef enum {
Iso14443_3aPollerEventTypeError, /**< The card was activated by the poller. */
Iso14443_3aPollerEventTypeReady, /**< An error occured during activation procedure. */
Iso14443_3aPollerEventTypeError, /**< An error occured during activation procedure. */
Iso14443_3aPollerEventTypeReady, /**< The card was activated by the poller. */
} Iso14443_3aPollerEventType;
/**

View file

@ -18,8 +18,8 @@ typedef struct Iso14443_3bPoller Iso14443_3bPoller;
* @brief Enumeration of possible Iso14443_3b poller event types.
*/
typedef enum {
Iso14443_3bPollerEventTypeError, /**< The card was activated by the poller. */
Iso14443_3bPollerEventTypeReady, /**< An error occured during activation procedure. */
Iso14443_3bPollerEventTypeError, /**< An error occured during activation procedure. */
Iso14443_3bPollerEventTypeReady, /**< The card was activated by the poller. */
} Iso14443_3bPollerEventType;
/**

View file

@ -17,8 +17,8 @@ typedef struct Iso14443_4aPoller Iso14443_4aPoller;
* @brief Enumeration of possible Iso14443_4a poller event types.
*/
typedef enum {
Iso14443_4aPollerEventTypeError, /**< The card was activated by the poller. */
Iso14443_4aPollerEventTypeReady, /**< An error occured during activation procedure. */
Iso14443_4aPollerEventTypeError, /**< An error occured during activation procedure. */
Iso14443_4aPollerEventTypeReady, /**< The card was activated by the poller. */
} Iso14443_4aPollerEventType;
/**

View file

@ -17,8 +17,8 @@ typedef struct Iso14443_4bPoller Iso14443_4bPoller;
* @brief Enumeration of possible Iso14443_4b poller event types.
*/
typedef enum {
Iso14443_4bPollerEventTypeError, /**< The card was activated by the poller. */
Iso14443_4bPollerEventTypeReady, /**< An error occured during activation procedure. */
Iso14443_4bPollerEventTypeError, /**< An error occured during activation procedure. */
Iso14443_4bPollerEventTypeReady, /**< The card was activated by the poller. */
} Iso14443_4bPollerEventType;
/**

View file

@ -17,8 +17,8 @@ typedef struct Iso15693_3Poller Iso15693_3Poller;
* @brief Enumeration of possible Iso15693_3 poller event types.
*/
typedef enum {
Iso15693_3PollerEventTypeError, /**< The card was activated by the poller. */
Iso15693_3PollerEventTypeReady, /**< An error occured during activation procedure. */
Iso15693_3PollerEventTypeError, /**< An error occured during activation procedure. */
Iso15693_3PollerEventTypeReady, /**< The card was activated by the poller. */
} Iso15693_3PollerEventType;
/**

View file

@ -33,6 +33,7 @@ static void mf_classic_listener_reset_state(MfClassicListener* instance) {
instance->state = MfClassicListenerStateIdle;
instance->cmd_in_progress = false;
instance->current_cmd_handler_idx = 0;
instance->write_block = 0;
instance->transfer_value = 0;
instance->transfer_valid = false;
instance->value_cmd = MfClassicValueCommandInvalid;
@ -240,11 +241,13 @@ static MfClassicListenerCommand mf_classic_listener_write_block_first_part_handl
uint8_t block_num = bit_buffer_get_byte(buff, 1);
if(block_num >= instance->total_block_num) break;
if(block_num == 0) break;
uint8_t sector_num = mf_classic_get_sector_by_block(block_num);
uint8_t auth_sector_num = mf_classic_get_sector_by_block(auth_ctx->block_num);
if(sector_num != auth_sector_num) break;
instance->write_block = block_num;
instance->cmd_in_progress = true;
instance->current_cmd_handler_idx++;
command = MfClassicListenerCommandAck;
@ -265,7 +268,7 @@ static MfClassicListenerCommand mf_classic_listener_write_block_second_part_hand
size_t buff_size = bit_buffer_get_size_bytes(buff);
if(buff_size != sizeof(MfClassicBlock)) break;
uint8_t block_num = auth_ctx->block_num;
uint8_t block_num = instance->write_block;
MfClassicKeyType key_type = auth_ctx->key_type;
MfClassicBlock block = instance->data->block[block_num];
@ -609,6 +612,7 @@ NfcCommand mf_classic_listener_run(NfcGenericEvent event, void* context) {
mf_classic_listener_send_short_frame(instance, nack);
mf_classic_listener_reset_state(instance);
command = NfcCommandSleep;
} else if(mfc_command == MfClassicListenerCommandSilent) {
command = NfcCommandReset;
} else if(mfc_command == MfClassicListenerCommandSleep) {

View file

@ -40,6 +40,9 @@ struct MfClassicListener {
Crypto1* crypto;
MfClassicAuthContext auth_context;
// Write block context
uint8_t write_block;
// Value operation data
int32_t transfer_value;
bool transfer_valid;