nfc: Add NTAG authentication event to emulation

This commit is contained in:
Yukai Li
2022-07-26 12:29:17 -06:00
parent 299ec9643e
commit 71035dc3ae
4 changed files with 20 additions and 1 deletions
+9
View File
@@ -447,6 +447,15 @@ void nfc_worker_emulate_mf_ultralight(NfcWorker* nfc_worker) {
mf_ul_prepare_emulation_response,
&emulator,
5000);
// Check if there was an auth attempt
if(emulator.auth_attempted) {
nfc_worker->event_data = &emulator.auth_attempt;
if(nfc_worker->callback) {
nfc_worker->callback(NfcWorkerEventPwdAuth, nfc_worker->context);
}
emulator.auth_attempted = false;
nfc_worker->event_data = NULL;
}
// Check if data was modified
if(emulator.data_changed) {
nfc_worker->dev_data->mf_ul_data = emulator.data;
+1 -1
View File
@@ -62,7 +62,7 @@ typedef enum {
// Mifare Ultralight events
NfcWorkerEventMfUltralightPassKey,
NfcWorkerEventPwdAuth,
} NfcWorkerEvent;
typedef bool (*NfcWorkerCallback)(NfcWorkerEvent event, void* context);
+8
View File
@@ -1246,6 +1246,7 @@ void mf_ul_prepare_emulation(MfUltralightEmulator* emulator, MfUltralightData* d
emulator->config = mf_ultralight_get_config_pages(&emulator->data);
emulator->page_num = emulator->data.data_size / 4;
emulator->data_changed = false;
memset(&emulator->auth_attempt, 0, sizeof(MfUltralightAuth));
mf_ul_reset_emulation(emulator, true);
}
@@ -1706,6 +1707,13 @@ bool mf_ul_prepare_emulation_response(
} else if(cmd == MF_UL_AUTH) {
if(emulator->supported_features & MfUltralightSupportAuth) {
if(buff_rx_len == (1 + 4) * 8) {
// Record password sent by PCD
memcpy(
emulator->auth_attempt.pwd.raw,
&buff_rx[1],
sizeof(emulator->auth_attempt.pwd.raw));
emulator->auth_attempted = true;
uint16_t scaled_authlim = mf_ultralight_calc_auth_count(&emulator->data);
if(scaled_authlim != 0 && emulator->data.curr_authlim >= scaled_authlim) {
if(emulator->data.curr_authlim != UINT16_MAX) {
+2
View File
@@ -185,6 +185,8 @@ typedef struct {
bool sector_select_cmd_started;
bool ntag_i2c_plus_sector3_lockout;
bool read_counter_incremented;
bool auth_attempted;
MfUltralightAuth auth_attempt;
} MfUltralightEmulator;
void mf_ul_reset(MfUltralightData* data);