nfcv code review fixes

This commit is contained in:
Tiernan Messmer 2023-05-31 23:28:46 +10:00 committed by MX
parent 87aca2874f
commit b18bf3eddb
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83
4 changed files with 39 additions and 52 deletions

View file

@ -7,17 +7,6 @@ void nfc_scene_nfc_data_info_widget_callback(GuiButtonType result, InputType typ
}
}
uint32_t nfc_scene_nfc_data_info_get_key(uint8_t* data) {
uint32_t value = 0;
for(uint32_t pos = 0; pos < 4; pos++) {
value <<= 8;
value |= data[pos];
}
return value;
}
void nfc_scene_nfc_data_info_on_enter(void* context) {
Nfc* nfc = context;
Widget* widget = nfc->widget;
@ -129,72 +118,72 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
furi_string_cat_printf(temp_str, "Keys:\n");
furi_string_cat_printf(
temp_str,
" EAS %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
" EAS %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
break;
case NfcVTypeSlixS:
furi_string_cat_printf(temp_str, "Type: SLIX-S\n");
furi_string_cat_printf(temp_str, "Keys:\n");
furi_string_cat_printf(
temp_str,
" Read %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_read));
" Read %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_read, 4));
furi_string_cat_printf(
temp_str,
" Write %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_write));
" Write %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_write, 4));
furi_string_cat_printf(
temp_str,
" Privacy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_privacy));
" Privacy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
furi_string_cat_printf(
temp_str,
" Destroy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_destroy));
" Destroy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
furi_string_cat_printf(
temp_str,
" EAS %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
" EAS %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
break;
case NfcVTypeSlixL:
furi_string_cat_printf(temp_str, "Type: SLIX-L\n");
furi_string_cat_printf(temp_str, "Keys:\n");
furi_string_cat_printf(
temp_str,
" Privacy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_privacy));
" Privacy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
furi_string_cat_printf(
temp_str,
" Destroy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_destroy));
" Destroy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
furi_string_cat_printf(
temp_str,
" EAS %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
" EAS %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
break;
case NfcVTypeSlix2:
furi_string_cat_printf(temp_str, "Type: SLIX2\n");
furi_string_cat_printf(temp_str, "Keys:\n");
furi_string_cat_printf(
temp_str,
" Read %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_read));
" Read %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_read, 4));
furi_string_cat_printf(
temp_str,
" Write %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_write));
" Write %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_write, 4));
furi_string_cat_printf(
temp_str,
" Privacy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_privacy));
" Privacy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_privacy, 4));
furi_string_cat_printf(
temp_str,
" Destroy %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_destroy));
" Destroy %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_destroy, 4));
furi_string_cat_printf(
temp_str,
" EAS %08lX\n",
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
" EAS %08llX\n",
nfc_util_bytes2num(nfcv_data->sub_data.slix.key_eas, 4));
break;
default:
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");

View file

@ -8,7 +8,6 @@ enum {
};
bool nfc_scene_nfcv_emulate_worker_callback(NfcWorkerEvent event, void* context) {
UNUSED(event);
furi_assert(context);
Nfc* nfc = context;

View file

@ -248,13 +248,13 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCV);
furi_hal_console_printf("Detect presence\r\n");
FURI_LOG_D(TAG, "Detect presence");
ReturnCode ret = slix_get_random(nfcv_data);
if(ret == ERR_NONE) {
/* there is some chip, responding with a RAND */
nfc_worker->dev_data->protocol = NfcDeviceProtocolNfcV;
furi_hal_console_printf(" Chip detected. In privacy?\r\n");
FURI_LOG_D(TAG, " Chip detected. In privacy?");
ret = nfcv_inventory(NULL);
if(ret == ERR_NONE) {
@ -263,15 +263,15 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
NfcVReader reader = {};
if(!nfcv_read_card(&reader, &nfc_worker->dev_data->nfc_data, nfcv_data)) {
furi_hal_console_printf(" => failed, wait for chip to disappear.\r\n");
FURI_LOG_D(TAG, " => failed, wait for chip to disappear.");
snprintf(nfcv_data->error, sizeof(nfcv_data->error), "Read card\nfailed");
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);
} else {
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
FURI_LOG_D(TAG, " => success, wait for chip to disappear.");
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
}
} else {
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
FURI_LOG_D(TAG, " => success, wait for chip to disappear.");
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
}
@ -279,8 +279,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
furi_delay_ms(100);
}
furi_hal_console_printf(
" => chip is already visible, wait for chip to disappear.\r\n");
FURI_LOG_D(TAG, " => chip is already visible, wait for chip to disappear.\r\n");
nfc_worker->callback(NfcWorkerEventAborted, nfc_worker->context);
while(slix_get_random(NULL) == ERR_NONE) {
furi_delay_ms(100);
@ -293,7 +292,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
} else {
/* chip is invisible, try to unlock */
furi_hal_console_printf(" chip is invisible, unlocking\r\n");
FURI_LOG_D(TAG, " chip is invisible, unlocking");
if(nfcv_data->auth_method == NfcVAuthMethodManual) {
key |= key_data[0] << 24;
@ -312,7 +311,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
if(ret != ERR_NONE) {
/* main key failed, trying second one */
furi_hal_console_printf(" trying second key after resetting\r\n");
FURI_LOG_D(TAG, " trying second key after resetting");
/* reset chip */
furi_hal_nfc_ll_txrx_off();
@ -320,7 +319,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
furi_hal_nfc_ll_txrx_on();
if(slix_get_random(nfcv_data) != ERR_NONE) {
furi_hal_console_printf(" reset failed\r\n");
FURI_LOG_D(TAG, " reset failed");
}
key = 0x0F0F0F0F;
@ -333,7 +332,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
}
if(ret != ERR_NONE) {
/* unlock failed */
furi_hal_console_printf(" => failed, wait for chip to disappear.\r\n");
FURI_LOG_D(TAG, " => failed, wait for chip to disappear.");
snprintf(
nfcv_data->error, sizeof(nfcv_data->error), "Passwords not\naccepted");
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);

View file

@ -15,7 +15,7 @@ extern "C" {
/* true: modulating releases load, false: modulating adds load resistor to field coil */
#define NFCV_LOAD_MODULATION_POLARITY (false)
#define NFCV_FC (13560000.0f / 0.9998f) /* MHz */
#define NFCV_FC (13560000.0f) /* MHz */
#define NFCV_RESP_SUBC1_PULSE_32 (1.0f / (NFCV_FC / 32) / 2.0f) /* 1.1799 µs */
#define NFCV_RESP_SUBC1_UNMOD_256 (256.0f / NFCV_FC) /* 18.8791 µs */
#define NFCV_PULSE_DURATION_NS (128.0f * 1000000000.0f / NFCV_FC)