mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 13:09:49 +04:00
* Moved some structs and defs from poller to generic felica * Buffer size increased for transferring more data * Felica HAL Tx function implemented * Some structs and fields for listener * Raw listener implementation * Added new event for felica activation * Proper config fot listener added * Moved some structs from poller in order to use them in listener too * New function for calculating MAC * Listener data structures and function definitions * Private listener functions implementation added * Raw felica listener logic implementation added * Fix total sector count both for poller and listener * Defined type for write handlers * New logic for write operations added * Removed old commented code * Splitted read logic into several separate functions * New type added and some fields to instance * New logic of read command implemented * Defines added for response codes * Functions moved to private namespace * Function visibility changed and some cleanups * Update felica_listener.c, felica_listener_i.c, and felica_listener_i.h * Some type adjustments * Moved frame_exchange function to private namespace * Error handling added * Function to get data_ptr for write request added * Missing declaration added * Add processing of nfc errors * write_with_mac is a local variable now * Adjustments to MAC calculation logic * Values replaced with defines * Update nfc_transport.c with felica logic * Sync felica poller added for unit tests * Felica unit_tests and data dump added * Fixed proper reading of MAC_A block when it is 1st * Macro definitions for MC added * Function simplified * More defines * CRC check for incomming packets added * Readonly logic adjusted * Block write validation adjusted * New logic for ID block writing * Some cleanups * New logic of moving across the block list with different element length * Some cleanups * Adjusted requires_mac logic to cover all blocks needed * Cleanups and renaming * New block list validation logic * Block list logic iteration simplified * Some asserts and checks added * Replaced MC[2] checks with macros * Marked def values as unsigned * Removed old code * Removed commented function declarations * Changed protected block in felica test card dump and adjusted tests * Fixes after merge * Moved defines to header * Now we allocate memory for max possible response pack in any case * Some renaming and documentation * Bump api symbols * Set feature to emulate full for felica * Removed 'More' button and added MoreInfo feature which adds this button back * Types renamed * Removed unnecessary code * Reformat comments * Fixing missing signatures * Replaced crash with error log and return value * Format doxygen comments Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
126 lines
3.8 KiB
C
126 lines
3.8 KiB
C
#pragma once
|
|
|
|
#include "felica_poller.h"
|
|
#include <toolbox/bit_buffer.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define FELICA_POLLER_MAX_BUFFER_SIZE (256U)
|
|
|
|
#define FELICA_POLLER_POLLING_FWT (200000U)
|
|
|
|
#define FELICA_POLLER_CMD_POLLING_REQ_CODE (0x00U)
|
|
#define FELICA_POLLER_CMD_POLLING_RESP_CODE (0x01U)
|
|
|
|
typedef enum {
|
|
FelicaPollerStateIdle,
|
|
FelicaPollerStateActivated,
|
|
FelicaPollerStateAuthenticateInternal,
|
|
FelicaPollerStateAuthenticateExternal,
|
|
FelicaPollerStateReadBlocks,
|
|
FelicaPollerStateReadSuccess,
|
|
FelicaPollerStateReadFailed,
|
|
|
|
FelicaPollerStateNum
|
|
} FelicaPollerState;
|
|
|
|
struct FelicaPoller {
|
|
Nfc* nfc;
|
|
FelicaPollerState state;
|
|
FelicaAuthentication auth;
|
|
|
|
FelicaData* data;
|
|
BitBuffer* tx_buffer;
|
|
BitBuffer* rx_buffer;
|
|
|
|
NfcGenericEvent general_event;
|
|
FelicaPollerEvent felica_event;
|
|
FelicaPollerEventData felica_event_data;
|
|
NfcGenericCallback callback;
|
|
uint8_t block_index;
|
|
void* context;
|
|
};
|
|
|
|
typedef struct {
|
|
uint16_t system_code;
|
|
uint8_t request_code;
|
|
uint8_t time_slot;
|
|
} FelicaPollerPollingCommand;
|
|
|
|
typedef struct {
|
|
FelicaIDm idm;
|
|
FelicaPMm pmm;
|
|
uint8_t request_data[2];
|
|
} FelicaPollerPollingResponse;
|
|
|
|
const FelicaData* felica_poller_get_data(FelicaPoller* instance);
|
|
|
|
/**
|
|
* @brief Performs felica polling operation as part of the activation process
|
|
*
|
|
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
|
* @param[in] cmd Pointer to polling command structure
|
|
* @param[out] resp Pointer to the response structure
|
|
* @return FelicaErrorNone on success, an error code on failure
|
|
*/
|
|
FelicaError felica_poller_polling(
|
|
FelicaPoller* instance,
|
|
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
|
|
*
|
|
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
|
* @param[in] block_count Amount of blocks involved in writing procedure
|
|
* @param[in] block_numbers Array with block indexes according to felica docs
|
|
* @param[in] data Data of blocks provided in block_numbers
|
|
* @param[out] response_ptr Pointer to the response structure
|
|
* @return FelicaErrorNone on success, an error code on failure.
|
|
*/
|
|
FelicaError felica_poller_write_blocks(
|
|
const FelicaPoller* instance,
|
|
const uint8_t block_count,
|
|
const uint8_t* const block_numbers,
|
|
const uint8_t* data,
|
|
FelicaPollerWriteCommandResponse** const response_ptr);
|
|
|
|
/**
|
|
* @brief Perform frame exchange procedure.
|
|
*
|
|
* Prepares data for sending by adding crc, after that performs
|
|
* low level calls to send package data to the card
|
|
*
|
|
* @param[in, out] instance pointer to the instance to be used in the transaction.
|
|
* @param[in] tx_buffer pointer to the buffer with data to be transmitted
|
|
* @param[out] rx_buffer pointer to the buffer with received data from card
|
|
* @param[in] fwt timeout window
|
|
* @return FelicaErrorNone on success, an error code on failure.
|
|
*/
|
|
FelicaError felica_poller_frame_exchange(
|
|
const FelicaPoller* instance,
|
|
const BitBuffer* tx_buffer,
|
|
BitBuffer* rx_buffer,
|
|
uint32_t fwt);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|