1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 12:51:22 +04:00
Files
flipperzero-firmware/lib/nfc/protocols/felica/felica_poller.h

62 lines
1.8 KiB
C
Raw Normal View History

#pragma once
#include "felica.h"
#include <lib/nfc/nfc.h>
#include <nfc/nfc_poller.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief FelicaPoller opaque type definition.
*/
typedef struct FelicaPoller FelicaPoller;
/**
* @brief Enumeration of possible Felica poller event types.
*/
typedef enum {
FelicaPollerEventTypeError, /**< An error occured during activation procedure. */
[FL-3772] Felica poller (#3570) * New types for felica poller * New functions for felica data transmissions * Felica memory map extended with new fields * Init/deinit of mbedtls context added for felica encryption * Functions for session key and mac calculations added * Raw felica_poller implementation added * Removed MAC type parameter from check_mac function * Replaced all data fields needed for auth with context structure * Clean up felica_poller.c * Now RC block is filled with random numbers * New parameter for counting well-read blocks * Some cleanups * Felica file save and load logic added * Now we use card key from context for session key calculation * Copying card key to card block from auth context when both authentications succeeded, otherwise decrement blocks count by 1 * New felica poller event added * Moved some data structions to public namespace * FelicaAuthenticationContext struct moved to felica.h * Field type and name changed for better ones * Helper functions for felica_auth added to the app * New scene for felica card key input added * Logic for felica key input added * Auth context request processing added * Added block index definitions and replaced all index numbers with them * More macro defines * Replace nesting with do while block * New function for write operations mac calculation added * Replace nesting with do while block * Make functions static for now because they are used internally * Wrote some comments * Raw felica render implementation * New felica scenes * Adjusted felica dump rendering according design requirements * New felica scene added * Helper for switching scene during unlock added * Added warning scene and transfer to it * Moved unlock scene logic to separate files * Magic number changed * New felica render logic * Felica scenes adjusted according to design requirements * Felica poller cleanups * Some asserts added and some fixed * Replcaed asserts to checks in public api * Fixed pvs warnings in felica_poller * New event for felica_poller added for incomplete read actions * Handling of new poller event added * Update SConscript with felica files * Update api_symbols.csv with felica functions * Sync API versions Co-authored-by: あく <alleteam@gmail.com>
2024-04-10 12:51:36 +03:00
FelicaPollerEventTypeReady, /**< The card was activated and fully read by the poller. */
FelicaPollerEventTypeIncomplete, /**< The card was activated and partly read by the poller. */
FelicaPollerEventTypeRequestAuthContext, /**< Authentication context was requested by poller. */
} FelicaPollerEventType;
/**
* @brief Felica poller event data.
*/
typedef union {
FelicaError error; /**< Error code indicating card activation fail reason. */
[FL-3772] Felica poller (#3570) * New types for felica poller * New functions for felica data transmissions * Felica memory map extended with new fields * Init/deinit of mbedtls context added for felica encryption * Functions for session key and mac calculations added * Raw felica_poller implementation added * Removed MAC type parameter from check_mac function * Replaced all data fields needed for auth with context structure * Clean up felica_poller.c * Now RC block is filled with random numbers * New parameter for counting well-read blocks * Some cleanups * Felica file save and load logic added * Now we use card key from context for session key calculation * Copying card key to card block from auth context when both authentications succeeded, otherwise decrement blocks count by 1 * New felica poller event added * Moved some data structions to public namespace * FelicaAuthenticationContext struct moved to felica.h * Field type and name changed for better ones * Helper functions for felica_auth added to the app * New scene for felica card key input added * Logic for felica key input added * Auth context request processing added * Added block index definitions and replaced all index numbers with them * More macro defines * Replace nesting with do while block * New function for write operations mac calculation added * Replace nesting with do while block * Make functions static for now because they are used internally * Wrote some comments * Raw felica render implementation * New felica scenes * Adjusted felica dump rendering according design requirements * New felica scene added * Helper for switching scene during unlock added * Added warning scene and transfer to it * Moved unlock scene logic to separate files * Magic number changed * New felica render logic * Felica scenes adjusted according to design requirements * Felica poller cleanups * Some asserts added and some fixed * Replcaed asserts to checks in public api * Fixed pvs warnings in felica_poller * New event for felica_poller added for incomplete read actions * Handling of new poller event added * Update SConscript with felica files * Update api_symbols.csv with felica functions * Sync API versions Co-authored-by: あく <alleteam@gmail.com>
2024-04-10 12:51:36 +03:00
FelicaAuthenticationContext* auth_context; /**< Authentication context to be filled by user. */
} FelicaPollerEventData;
/**
* @brief FelicaPoller poller event structure.
*
* Upon emission of an event, an instance of this struct will be passed to the callback.
*/
typedef struct {
FelicaPollerEventType type; /**< Type of emmitted event. */
FelicaPollerEventData* data; /**< Pointer to event specific data. */
} FelicaPollerEvent;
/**
* @brief Perform collision resolution procedure.
*
* Must ONLY be used inside the callback function.
*
* Perfoms the collision resolution procedure as defined in FeliCa standars. The data
* field will be filled with Felica data on success.
*
* @param[in, out] instance pointer to the instance to be used in the transaction.
* @param[out] data pointer to the Felica data structure to be filled.
* @return FelicaErrorNone on success, an error code on failure.
*/
FelicaError felica_poller_activate(FelicaPoller* instance, FelicaData* data);
#ifdef __cplusplus
}
#endif