[FL-2198], [FL-2161] NFC emulation refactoring (#968)
* rfal: add state changed callback * furi_hal_nfc: add NFC-A emulation API * nfc: add emulation logger, refactor scenes * elements: fix text_box element * gui: fix text box module * nfc: remove unnecessary buffers * nfc: introduce emulation callback concept * nfc: format sources * bt settings: fix incorrect scene switch * bt settings: format sources * Debug: fix x2d import for python 3 * Gui: rename method name widget_clear to widget_reset * nfc: add nfca emulation handler * nfc: add global custom events enum * nfc: UID emulation Data -> Log * furi_hal_nfc: fix incorrect timings * u2f, badusb: widget_clear() -> widget_reset() Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -545,10 +545,13 @@ typedef struct {
|
||||
typedef void (*rfalUpperLayerCallback)(void);
|
||||
|
||||
/*! Callback to be executed before a Transceive */
|
||||
typedef void (*rfalPreTxRxCallback)(void);
|
||||
typedef void (*rfalPreTxRxCallback)(void* context);
|
||||
|
||||
/*! Callback to be executed after a Transceive */
|
||||
typedef void (*rfalPostTxRxCallback)(void);
|
||||
typedef void (*rfalPostTxRxCallback)(void* context);
|
||||
|
||||
/** Callback to be executed on each RFAL state change */
|
||||
typedef void (*RfalStateChangedCallback)(void* context);
|
||||
|
||||
/*******************************************************************************/
|
||||
/* ISO14443A */
|
||||
@@ -819,6 +822,19 @@ void rfalSetPreTxRxCallback(rfalPreTxRxCallback pFunc);
|
||||
*/
|
||||
void rfalSetPostTxRxCallback(rfalPostTxRxCallback pFunc);
|
||||
|
||||
/** Set RFAL state changed callback
|
||||
*
|
||||
* @param cb RfalStateChangedCallback instance
|
||||
* @param ctx pointer to context
|
||||
*/
|
||||
void rfal_set_state_changed_callback(RfalStateChangedCallback callback);
|
||||
|
||||
/** Set callback context
|
||||
*
|
||||
* @param ctx pointer to context
|
||||
*/
|
||||
void rfal_set_callback_context(void* context);
|
||||
|
||||
/*!
|
||||
*****************************************************************************
|
||||
* \brief RFAL Deinitialize
|
||||
@@ -1480,6 +1496,15 @@ ReturnCode rfalTransceiveBlockingTxRx(
|
||||
uint32_t flags,
|
||||
uint32_t fwt);
|
||||
|
||||
ReturnCode rfalTransceiveBitsBlockingTx(
|
||||
uint8_t* txBuf,
|
||||
uint16_t txBufLen,
|
||||
uint8_t* rxBuf,
|
||||
uint16_t rxBufLen,
|
||||
uint16_t* actLen,
|
||||
uint32_t flags,
|
||||
uint32_t fwt);
|
||||
|
||||
/*****************************************************************************
|
||||
* Listen Mode *
|
||||
*****************************************************************************/
|
||||
|
@@ -130,6 +130,8 @@ typedef struct {
|
||||
typedef struct {
|
||||
rfalPreTxRxCallback preTxRx; /*!< RFAL's Pre TxRx callback */
|
||||
rfalPostTxRxCallback postTxRx; /*!< RFAL's Post TxRx callback */
|
||||
RfalStateChangedCallback state_changed_cb;
|
||||
void* ctx;
|
||||
} rfalCallbacks;
|
||||
|
||||
/*! Struct that holds counters to control the FIFO on Tx and Rx */
|
||||
@@ -595,6 +597,8 @@ ReturnCode rfalInitialize(void) {
|
||||
|
||||
gRFAL.callbacks.preTxRx = NULL;
|
||||
gRFAL.callbacks.postTxRx = NULL;
|
||||
gRFAL.callbacks.state_changed_cb = NULL;
|
||||
gRFAL.callbacks.ctx = NULL;
|
||||
|
||||
#if RFAL_FEATURE_NFCV
|
||||
/* Initialize NFC-V Data */
|
||||
@@ -669,6 +673,14 @@ void rfalSetPostTxRxCallback(rfalPostTxRxCallback pFunc) {
|
||||
gRFAL.callbacks.postTxRx = pFunc;
|
||||
}
|
||||
|
||||
void rfal_set_state_changed_callback(RfalStateChangedCallback callback) {
|
||||
gRFAL.callbacks.state_changed_cb = callback;
|
||||
}
|
||||
|
||||
void rfal_set_callback_context(void* context) {
|
||||
gRFAL.callbacks.ctx = context;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
ReturnCode rfalDeinitialize(void) {
|
||||
/* Deinitialize chip */
|
||||
@@ -1520,6 +1532,30 @@ ReturnCode rfalTransceiveBlockingTx(
|
||||
return rfalTransceiveRunBlockingTx();
|
||||
}
|
||||
|
||||
ReturnCode rfalTransceiveBitsBlockingTx(
|
||||
uint8_t* txBuf,
|
||||
uint16_t txBufLen,
|
||||
uint8_t* rxBuf,
|
||||
uint16_t rxBufLen,
|
||||
uint16_t* actLen,
|
||||
uint32_t flags,
|
||||
uint32_t fwt) {
|
||||
ReturnCode ret;
|
||||
rfalTransceiveContext ctx = {
|
||||
.rxBuf = rxBuf,
|
||||
.rxBufLen = rxBufLen,
|
||||
.rxRcvdLen = actLen,
|
||||
.txBuf = txBuf,
|
||||
.txBufLen = txBufLen,
|
||||
.flags = flags,
|
||||
.fwt = fwt,
|
||||
};
|
||||
|
||||
EXIT_ON_ERR(ret, rfalStartTransceive(&ctx));
|
||||
|
||||
return rfalTransceiveRunBlockingTx();
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
static ReturnCode rfalTransceiveRunBlockingTx(void) {
|
||||
ReturnCode ret;
|
||||
@@ -1797,7 +1833,7 @@ static void rfalCleanupTransceive(void) {
|
||||
/* Execute Post Transceive Callback */
|
||||
/*******************************************************************************/
|
||||
if(gRFAL.callbacks.postTxRx != NULL) {
|
||||
gRFAL.callbacks.postTxRx();
|
||||
gRFAL.callbacks.postTxRx(gRFAL.callbacks.ctx);
|
||||
}
|
||||
/*******************************************************************************/
|
||||
}
|
||||
@@ -1838,7 +1874,7 @@ static void rfalPrepareTransceive(void) {
|
||||
/* Execute Pre Transceive Callback */
|
||||
/*******************************************************************************/
|
||||
if(gRFAL.callbacks.preTxRx != NULL) {
|
||||
gRFAL.callbacks.preTxRx();
|
||||
gRFAL.callbacks.preTxRx(gRFAL.callbacks.ctx);
|
||||
}
|
||||
/*******************************************************************************/
|
||||
|
||||
@@ -4164,6 +4200,11 @@ ReturnCode rfalListenSetState(rfalLmState newSt) {
|
||||
|
||||
gRFAL.Lm.state = newState;
|
||||
|
||||
// Call callback on state change
|
||||
if(gRFAL.callbacks.state_changed_cb) {
|
||||
gRFAL.callbacks.state_changed_cb(gRFAL.callbacks.ctx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user