mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-02 04:39:59 -07:00
NFC: Refactor MIFARE Plus with NxpNativeCommand helper
This commit is contained in:
@@ -238,22 +238,12 @@ MfPlusError
|
||||
}
|
||||
|
||||
MfPlusError mf_plus_version_parse(MfPlusVersion* data, const BitBuffer* buf) {
|
||||
bool can_parse = bit_buffer_get_size_bytes(buf) == sizeof(MfPlusVersion);
|
||||
const bool can_parse = bit_buffer_get_size_bytes(buf) == sizeof(MfPlusVersion);
|
||||
|
||||
if(can_parse) {
|
||||
bit_buffer_write_bytes(buf, data, sizeof(MfPlusVersion));
|
||||
} else if(
|
||||
bit_buffer_get_size_bytes(buf) == 8 &&
|
||||
bit_buffer_get_byte(buf, 0) == MF_PLUS_STATUS_ADDITIONAL_FRAME) {
|
||||
// HACK(-nofl): There are supposed to be three parts to the GetVersion command,
|
||||
// with the second and third parts fetched by sending the AdditionalFrame
|
||||
// command. I don't know whether the entire MIFARE Plus line uses status as
|
||||
// the first byte, so let's just assume we only have the first part of
|
||||
// the response if it's size 8 and starts with the AF status. The second
|
||||
// part of the response is the same size and status byte, but so far
|
||||
// we're only reading one response.
|
||||
can_parse = true;
|
||||
bit_buffer_write_bytes_mid(buf, data, 1, bit_buffer_get_size_bytes(buf) - 1);
|
||||
} else {
|
||||
memset(data, 0, sizeof(MfPlusVersion));
|
||||
}
|
||||
|
||||
return can_parse ? MfPlusErrorNone : MfPlusErrorProtocol;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
#include "mf_plus.h"
|
||||
|
||||
#define MF_PLUS_FFF_PICC_PREFIX "PICC"
|
||||
#include <nfc/helpers/nxp_native_command.h>
|
||||
|
||||
#define MF_PLUS_STATUS_OPERATION_OK (0x90)
|
||||
#define MF_PLUS_STATUS_ADDITIONAL_FRAME (0xAF)
|
||||
#define MF_PLUS_FFF_PICC_PREFIX "PICC"
|
||||
|
||||
MfPlusError mf_plus_get_type_from_version(
|
||||
const Iso14443_4aData* iso14443_4a_data,
|
||||
|
||||
@@ -19,28 +19,36 @@ MfPlusError mf_plus_process_error(Iso14443_4aError error) {
|
||||
}
|
||||
}
|
||||
|
||||
MfPlusError mf_plus_poller_send_chunk(
|
||||
MfPlusError mf_plus_process_status_code(uint8_t status_code) {
|
||||
switch(status_code) {
|
||||
case NXP_NATIVE_COMMAND_STATUS_OPERATION_OK:
|
||||
return MfPlusErrorNone;
|
||||
default:
|
||||
return MfPlusErrorProtocol;
|
||||
}
|
||||
}
|
||||
|
||||
MfPlusError mf_plus_poller_send_chunks(
|
||||
MfPlusPoller* instance,
|
||||
const BitBuffer* tx_buffer,
|
||||
BitBuffer* rx_buffer) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->iso14443_4a_poller);
|
||||
furi_assert(instance->tx_buffer);
|
||||
furi_assert(instance->rx_buffer);
|
||||
furi_assert(tx_buffer);
|
||||
furi_assert(rx_buffer);
|
||||
|
||||
Iso14443_4aError iso14443_4a_error = iso14443_4a_poller_send_block(
|
||||
instance->iso14443_4a_poller, tx_buffer, instance->rx_buffer);
|
||||
MfPlusError error = mf_plus_process_error(iso14443_4a_error);
|
||||
NxpNativeCommandStatus status_code = NXP_NATIVE_COMMAND_STATUS_OPERATION_OK;
|
||||
Iso14443_4aError iso14443_4a_error = nxp_native_command_iso14443_4a_poller(
|
||||
instance->iso14443_4a_poller,
|
||||
&status_code,
|
||||
tx_buffer,
|
||||
rx_buffer,
|
||||
NxpNativeCommandModePlain,
|
||||
instance->tx_buffer,
|
||||
instance->rx_buffer);
|
||||
|
||||
if(error == MfPlusErrorNone) {
|
||||
bit_buffer_copy(rx_buffer, instance->rx_buffer);
|
||||
if(iso14443_4a_error != Iso14443_4aErrorNone) {
|
||||
return mf_plus_process_error(iso14443_4a_error);
|
||||
}
|
||||
|
||||
bit_buffer_reset(instance->tx_buffer);
|
||||
|
||||
return error;
|
||||
return mf_plus_process_status_code(status_code);
|
||||
}
|
||||
|
||||
MfPlusError mf_plus_poller_read_version(MfPlusPoller* instance, MfPlusVersion* data) {
|
||||
@@ -50,7 +58,7 @@ MfPlusError mf_plus_poller_read_version(MfPlusPoller* instance, MfPlusVersion* d
|
||||
bit_buffer_append_byte(instance->input_buffer, MF_PLUS_CMD_GET_VERSION);
|
||||
|
||||
MfPlusError error =
|
||||
mf_plus_poller_send_chunk(instance, instance->input_buffer, instance->result_buffer);
|
||||
mf_plus_poller_send_chunks(instance, instance->input_buffer, instance->result_buffer);
|
||||
if(error == MfPlusErrorNone) {
|
||||
error = mf_plus_version_parse(data, instance->result_buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user