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

NFC: FeliCa Protocol Expose Read Block API and Allow Specifying Service #4074

Open
wants to merge 3 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
6 changes: 3 additions & 3 deletions lib/nfc/protocols/felica/felica_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ NfcCommand felica_poller_state_handler_auth_internal(FelicaPoller* instance) {
blocks[1] = FELICA_BLOCK_INDEX_WCNT;
blocks[2] = FELICA_BLOCK_INDEX_MAC_A;
FelicaPollerReadCommandResponse* rx_resp;
error = felica_poller_read_blocks(instance, sizeof(blocks), blocks, &rx_resp);
error = felica_poller_read_blocks(instance, sizeof(blocks), blocks, FELICA_SERVICE_RO_ACCESS, &rx_resp);
if(error != FelicaErrorNone || rx_resp->SF1 != 0 || rx_resp->SF2 != 0) break;

if(felica_check_mac(
Expand Down Expand Up @@ -174,7 +174,7 @@ NfcCommand felica_poller_state_handler_auth_external(FelicaPoller* instance) {
if(error != FelicaErrorNone || tx_resp->SF1 != 0 || tx_resp->SF2 != 0) break;

FelicaPollerReadCommandResponse* rx_resp;
error = felica_poller_read_blocks(instance, 1, blocks, &rx_resp);
error = felica_poller_read_blocks(instance, 1, blocks, FELICA_SERVICE_RO_ACCESS, &rx_resp);
if(error != FelicaErrorNone || rx_resp->SF1 != 0 || rx_resp->SF2 != 0) break;

instance->data->data.fs.state.SF1 = 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ NfcCommand felica_poller_state_handler_read_blocks(FelicaPoller* instance) {
}

FelicaPollerReadCommandResponse* response;
FelicaError error = felica_poller_read_blocks(instance, block_count, block_list, &response);
FelicaError error = felica_poller_read_blocks(instance, block_count, block_list, FELICA_SERVICE_RO_ACCESS, &response);
if(error == FelicaErrorNone) {
block_count = (response->SF1 == 0) ? response->block_count : block_count;
uint8_t* data_ptr =
Expand Down
18 changes: 18 additions & 0 deletions lib/nfc/protocols/felica/felica_poller.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ typedef struct {
*/
FelicaError felica_poller_activate(FelicaPoller* instance, FelicaData* data);

/**
* @brief Performs felica read operation for blocks provided as parameters
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[in] block_count Amount of blocks involved in reading procedure
* @param[in] block_numbers Array with block indexes according to felica docs
* @param[in] service_code Service code for the read operation
* @param[out] response_ptr Pointer to the response structure
* @return FelicaErrorNone on success, an error code on failure.
*/
FelicaError felica_poller_read_blocks(
FelicaPoller* instance,
const uint8_t block_count,
const uint8_t* const block_numbers,
uint16_t service_code,
FelicaPollerReadCommandResponse** const response_ptr);


#ifdef __cplusplus
}
#endif
3 changes: 2 additions & 1 deletion lib/nfc/protocols/felica/felica_poller_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ FelicaError felica_poller_read_blocks(
FelicaPoller* instance,
const uint8_t block_count,
const uint8_t* const block_numbers,
uint16_t service_code,
FelicaPollerReadCommandResponse** const response_ptr) {
furi_assert(instance);
furi_assert(block_count <= 4);
Expand All @@ -143,7 +144,7 @@ FelicaError felica_poller_read_blocks(
felica_poller_prepare_tx_buffer(
instance,
FELICA_CMD_READ_WITHOUT_ENCRYPTION,
FELICA_SERVICE_RO_ACCESS,
service_code,
block_count,
block_numbers,
0,
Expand Down
14 changes: 0 additions & 14 deletions lib/nfc/protocols/felica/felica_poller_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ FelicaError felica_poller_polling(
const FelicaPollerPollingCommand* cmd,
FelicaPollerPollingResponse* resp);

/**
* @brief Performs felica read operation for blocks provided as parameters
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[in] block_count Amount of blocks involved in reading procedure
* @param[in] block_numbers Array with block indexes according to felica docs
* @param[out] response_ptr Pointer to the response structure
* @return FelicaErrorNone on success, an error code on failure.
*/
FelicaError felica_poller_read_blocks(
FelicaPoller* instance,
const uint8_t block_count,
const uint8_t* const block_numbers,
FelicaPollerReadCommandResponse** const response_ptr);

/**
* @brief Performs felica write operation with data provided as parameters
Expand Down
1 change: 1 addition & 0 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ Function,+,felica_get_uid,const uint8_t*,"const FelicaData*, size_t*"
Function,+,felica_is_equal,_Bool,"const FelicaData*, const FelicaData*"
Function,+,felica_load,_Bool,"FelicaData*, FlipperFormat*, uint32_t"
Function,+,felica_poller_activate,FelicaError,"FelicaPoller*, FelicaData*"
Function,+,felica_poller_read_blocks,FelicaError,"FelicaPoller*, const uint8_t, const uint8_t*, uint16_t, FelicaPollerReadCommandResponse**"
Function,+,felica_poller_sync_read,FelicaError,"Nfc*, FelicaData*, const FelicaCardKey*"
Function,+,felica_reset,void,FelicaData*
Function,+,felica_save,_Bool,"const FelicaData*, FlipperFormat*"
Expand Down