Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to enforce ISO15693 mode #3885

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,33 @@ NfcError nfc_iso15693_listener_tx_sof(Nfc* instance) {
return ret;
}

NfcError nfc_iso15693_detect_mode(Nfc* instance) {
furi_check(instance);

FuriHalNfcError error = furi_hal_nfc_iso15693_detect_mode();
NfcError ret = nfc_process_hal_error(error);

return ret;
}

NfcError nfc_iso15693_force_1outof4(Nfc* instance) {
furi_check(instance);

FuriHalNfcError error = furi_hal_nfc_iso15693_force_1outof4();
NfcError ret = nfc_process_hal_error(error);

return ret;
}

NfcError nfc_iso15693_force_1outof256(Nfc* instance) {
furi_check(instance);

FuriHalNfcError error = furi_hal_nfc_iso15693_force_1outof256();
NfcError ret = nfc_process_hal_error(error);

return ret;
}

NfcError nfc_felica_listener_set_sensf_res_data(
Nfc* instance,
const uint8_t* idm,
Expand Down
24 changes: 24 additions & 0 deletions lib/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,30 @@ NfcError nfc_felica_listener_set_sensf_res_data(
*/
NfcError nfc_iso15693_listener_tx_sof(Nfc* instance);

/**
* @brief Set ISO15693 parser mode to autodetect
*
* @param[in,out] instance pointer to the instance to be configured.
* @returns NfcErrorNone on success, any other error code on failure.
*/
NfcError nfc_iso15693_detect_mode(Nfc* instance);

/**
* @brief Set ISO15693 parser mode to 1OutOf4, disables autodetection
*
* @param[in,out] instance pointer to the instance to be configured.
* @return NfcErrorNone on success, any other error code on failure.
*/
NfcError nfc_iso15693_force_1outof4(Nfc* instance);

/**
* @brief Set ISO15693 parser mode to 1OutOf256, disables autodetection
*
* @param[in,out] instance pointer to the instance to be configured.
* @return NfcErrorNone on success, any other error code on failure.
*/
NfcError nfc_iso15693_force_1outof256(Nfc* instance);

#ifdef __cplusplus
}
#endif
18 changes: 18 additions & 0 deletions lib/nfc/nfc_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,24 @@ NfcError nfc_iso15693_listener_tx_sof(Nfc* instance) {
return NfcErrorNone;
}

NfcError nfc_iso15693_detect_mode(Nfc* instance) {
UNUSED(instance);

return NfcErrorNone;
}

NfcError nfc_iso15693_force_1outof4(Nfc* instance) {
UNUSED(instance);

return NfcErrorNone;
}

NfcError nfc_iso15693_force_1outof256(Nfc* instance) {
UNUSED(instance);

return NfcErrorNone;
}

NfcError nfc_felica_listener_set_sensf_res_data(
Nfc* instance,
const uint8_t* idm,
Expand Down
28 changes: 25 additions & 3 deletions lib/signal_reader/parsers/iso15693/iso15693_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef enum {
struct Iso15693Parser {
Iso15693ParserState state;
Iso15693ParserMode mode;
bool detect_mode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this detect_mode be moved to the Iso15693ParserMode enum?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, so you're proposing to add two new modes like Iso15693ParserModeForced1OutOf4 and Iso15693ParserModeForced1OutOf256 in place of the boolean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but there is a more important thing, which I've missed previously. Putting protocol specific functions into nfc.c / nfc.h layer it's not very good idea, because nfc layer was designed to be a generic protocol free. I had a quick conversation with original nfc stack designer and he agreed on that.
Also, we came up to the idea that we need to investigate this problem deeper and try to fix this in iso15 parser. Currently I'm investigating this issue and will be in touch with you on the results.


SignalReader* signal_reader;

Expand Down Expand Up @@ -62,6 +63,7 @@ typedef Iso15693ParserCommand (*Iso15693ParserStateHandler)(Iso15693Parser* inst

Iso15693Parser* iso15693_parser_alloc(const GpioPin* pin, size_t max_frame_size) {
Iso15693Parser* instance = malloc(sizeof(Iso15693Parser));
instance->detect_mode = true;
instance->parsed_frame = bit_buffer_alloc(max_frame_size);

instance->signal_reader = signal_reader_alloc(pin, ISO15693_PARSER_SIGNAL_READER_BUFF_SIZE);
Expand All @@ -86,7 +88,7 @@ void iso15693_parser_reset(Iso15693Parser* instance) {
furi_assert(instance);

instance->state = Iso15693ParserStateParseSoF;
instance->mode = Iso15693ParserMode1OutOf4;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf4;
memset(instance->bitstream_buff, 0x00, sizeof(instance->bitstream_buff));
instance->bitstream_idx = 0;

Expand Down Expand Up @@ -122,10 +124,10 @@ static void signal_reader_callback(SignalReaderEvent event, void* context) {

if(instance->state == Iso15693ParserStateParseSoF) {
if(event.data->data[0] == sof_1_out_of_4) {
instance->mode = Iso15693ParserMode1OutOf4;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf4;
instance->state = Iso15693ParserStateParseFrame;
} else if(event.data->data[0] == sof_1_out_of_256) {
instance->mode = Iso15693ParserMode1OutOf256;
if(instance->detect_mode) instance->mode = Iso15693ParserMode1OutOf256;
instance->state = Iso15693ParserStateParseFrame;
} else if(event.data->data[0] == eof_single) {
instance->eof_received = true;
Expand Down Expand Up @@ -298,3 +300,23 @@ void iso15693_parser_get_data(
bit_buffer_write_bytes(instance->parsed_frame, buff, buff_size);
*data_bits = bit_buffer_get_size(instance->parsed_frame);
}

void iso15693_parser_detect_mode(Iso15693Parser* instance) {
furi_assert(instance);

instance->detect_mode = true;
}

void iso15693_parser_force_1outof4(Iso15693Parser* instance) {
furi_assert(instance);

instance->detect_mode = false;
instance->mode = Iso15693ParserMode1OutOf4;
}

void iso15693_parser_force_1outof256(Iso15693Parser* instance) {
furi_assert(instance);

instance->detect_mode = false;
instance->mode = Iso15693ParserMode1OutOf256;
}
4 changes: 4 additions & 0 deletions lib/signal_reader/parsers/iso15693/iso15693_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void iso15693_parser_get_data(
size_t buff_size,
size_t* data_bits);

void iso15693_parser_detect_mode(Iso15693Parser* instance);
void iso15693_parser_force_1outof4(Iso15693Parser* instance);
void iso15693_parser_force_1outof256(Iso15693Parser* instance);

#ifdef __cplusplus
}
#endif
6 changes: 6 additions & 0 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,9 @@ Function,+,furi_hal_nfc_iso14443a_poller_trx_short_frame,FuriHalNfcError,FuriHal
Function,+,furi_hal_nfc_iso14443a_poller_tx_custom_parity,FuriHalNfcError,"const uint8_t*, size_t"
Function,+,furi_hal_nfc_iso14443a_rx_sdd_frame,FuriHalNfcError,"uint8_t*, size_t, size_t*"
Function,+,furi_hal_nfc_iso14443a_tx_sdd_frame,FuriHalNfcError,"const uint8_t*, size_t"
Function,+,furi_hal_nfc_iso15693_detect_mode,FuriHalNfcError,
Function,+,furi_hal_nfc_iso15693_force_1outof256,FuriHalNfcError,
Function,+,furi_hal_nfc_iso15693_force_1outof4,FuriHalNfcError,
Function,+,furi_hal_nfc_iso15693_listener_tx_sof,FuriHalNfcError,
Function,+,furi_hal_nfc_listener_enable_rx,FuriHalNfcError,
Function,+,furi_hal_nfc_listener_idle,FuriHalNfcError,
Expand Down Expand Up @@ -2804,6 +2807,9 @@ Function,+,nfc_iso14443a_listener_tx_custom_parity,NfcError,"Nfc*, const BitBuff
Function,+,nfc_iso14443a_poller_trx_custom_parity,NfcError,"Nfc*, const BitBuffer*, BitBuffer*, uint32_t"
Function,+,nfc_iso14443a_poller_trx_sdd_frame,NfcError,"Nfc*, const BitBuffer*, BitBuffer*, uint32_t"
Function,+,nfc_iso14443a_poller_trx_short_frame,NfcError,"Nfc*, NfcIso14443aShortFrame, BitBuffer*, uint32_t"
Function,+,nfc_iso15693_detect_mode,NfcError,Nfc*
Function,+,nfc_iso15693_force_1outof256,NfcError,Nfc*
Function,+,nfc_iso15693_force_1outof4,NfcError,Nfc*
Function,+,nfc_iso15693_listener_tx_sof,NfcError,Nfc*
Function,+,nfc_listener_alloc,NfcListener*,"Nfc*, NfcProtocol, const NfcDeviceData*"
Function,+,nfc_listener_free,void,NfcListener*
Expand Down
18 changes: 18 additions & 0 deletions targets/f7/furi_hal/furi_hal_nfc_iso15693.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,24 @@ FuriHalNfcError furi_hal_nfc_iso15693_listener_tx_sof(void) {
return FuriHalNfcErrorNone;
}

FuriHalNfcError furi_hal_nfc_iso15693_detect_mode(void) {
iso15693_parser_detect_mode(furi_hal_nfc_iso15693_listener->parser);

return FuriHalNfcErrorNone;
}

FuriHalNfcError furi_hal_nfc_iso15693_force_1outof4(void) {
iso15693_parser_force_1outof4(furi_hal_nfc_iso15693_listener->parser);

return FuriHalNfcErrorNone;
}

FuriHalNfcError furi_hal_nfc_iso15693_force_1outof256(void) {
iso15693_parser_force_1outof256(furi_hal_nfc_iso15693_listener->parser);

return FuriHalNfcErrorNone;
}

static FuriHalNfcError furi_hal_nfc_iso15693_listener_rx(
FuriHalSpiBusHandle* handle,
uint8_t* rx_data,
Expand Down
18 changes: 18 additions & 0 deletions targets/furi_hal_include/furi_hal_nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,24 @@ FuriHalNfcError furi_hal_nfc_iso14443a_listener_tx_custom_parity(
*/
FuriHalNfcError furi_hal_nfc_iso15693_listener_tx_sof(void);

/** Set ISO15693 parser mode to autodetect
*
* @return FuriHalNfcError
*/
FuriHalNfcError furi_hal_nfc_iso15693_detect_mode(void);

/** Set ISO15693 parser mode to 1OutOf4, disables autodetection
*
* @return FuriHalNfcError
*/
FuriHalNfcError furi_hal_nfc_iso15693_force_1outof4(void);

/** Set ISO15693 parser mode to 1OutOf256, disables autodetection
*
* @return FuriHalNfcError
*/
FuriHalNfcError furi_hal_nfc_iso15693_force_1outof256(void);

/**
* @brief Set FeliCa collision resolution parameters in listener mode.
*
Expand Down