mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-16 04:24:45 -07:00
fmt
This commit is contained in:
@@ -38,7 +38,8 @@ static void nfc_scene_emulate_nfcv_widget_config(Nfc* nfc, bool data_received) {
|
|||||||
info_str = furi_string_alloc();
|
info_str = furi_string_alloc();
|
||||||
|
|
||||||
widget_add_icon_element(widget, 0, 3, &I_RFIDDolphinSend_97x61);
|
widget_add_icon_element(widget, 0, 3, &I_RFIDDolphinSend_97x61);
|
||||||
widget_add_string_element(widget, 89, 32, AlignCenter, AlignTop, FontPrimary, "Emulating NfcV");
|
widget_add_string_element(
|
||||||
|
widget, 89, 32, AlignCenter, AlignTop, FontPrimary, "Emulating NfcV");
|
||||||
if(strcmp(nfc->dev->dev_name, "")) {
|
if(strcmp(nfc->dev->dev_name, "")) {
|
||||||
furi_string_printf(info_str, "%s", nfc->dev->dev_name);
|
furi_string_printf(info_str, "%s", nfc->dev->dev_name);
|
||||||
} else {
|
} else {
|
||||||
@@ -97,7 +98,8 @@ bool nfc_scene_emulate_nfcv_on_event(void* context, SceneManagerEvent event) {
|
|||||||
}
|
}
|
||||||
if(strlen(nfcv_data->last_command) > 0) {
|
if(strlen(nfcv_data->last_command) > 0) {
|
||||||
/* use the last n bytes from the log so there's enough space for the new log entry */
|
/* use the last n bytes from the log so there's enough space for the new log entry */
|
||||||
size_t maxSize = NFC_SCENE_EMULATE_NFCV_LOG_SIZE_MAX - (strlen(nfcv_data->last_command) + 1);
|
size_t maxSize =
|
||||||
|
NFC_SCENE_EMULATE_NFCV_LOG_SIZE_MAX - (strlen(nfcv_data->last_command) + 1);
|
||||||
if(furi_string_size(nfc->text_box_store) >= maxSize) {
|
if(furi_string_size(nfc->text_box_store) >= maxSize) {
|
||||||
furi_string_right(nfc->text_box_store, (strlen(nfcv_data->last_command) + 1));
|
furi_string_right(nfc->text_box_store, (strlen(nfcv_data->last_command) + 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ 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 nfc_scene_nfc_data_info_get_key(uint8_t* data) {
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
|
|
||||||
for(uint32_t pos = 0; pos < 4; pos++) {
|
for(uint32_t pos = 0; pos < 4; pos++) {
|
||||||
@@ -25,8 +25,8 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
|||||||
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
||||||
NfcProtocol protocol = dev_data->protocol;
|
NfcProtocol protocol = dev_data->protocol;
|
||||||
uint8_t text_scroll_height = 0;
|
uint8_t text_scroll_height = 0;
|
||||||
if((protocol == NfcDeviceProtocolMifareDesfire) || (protocol == NfcDeviceProtocolMifareUl)
|
if((protocol == NfcDeviceProtocolMifareDesfire) || (protocol == NfcDeviceProtocolMifareUl) ||
|
||||||
|| (protocol == NfcDeviceProtocolNfcV)) {
|
(protocol == NfcDeviceProtocolNfcV)) {
|
||||||
widget_add_button_element(
|
widget_add_button_element(
|
||||||
widget, GuiButtonTypeRight, "More", nfc_scene_nfc_data_info_widget_callback, nfc);
|
widget, GuiButtonTypeRight, "More", nfc_scene_nfc_data_info_widget_callback, nfc);
|
||||||
text_scroll_height = 52;
|
text_scroll_height = 52;
|
||||||
@@ -55,26 +55,25 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
|||||||
} else if(protocol == NfcDeviceProtocolMifareDesfire) {
|
} else if(protocol == NfcDeviceProtocolMifareDesfire) {
|
||||||
furi_string_cat_printf(temp_str, "\e#MIFARE DESfire\n");
|
furi_string_cat_printf(temp_str, "\e#MIFARE DESfire\n");
|
||||||
} else if(protocol == NfcDeviceProtocolNfcV) {
|
} else if(protocol == NfcDeviceProtocolNfcV) {
|
||||||
switch (dev_data->nfcv_data.type)
|
switch(dev_data->nfcv_data.type) {
|
||||||
{
|
case NfcVTypePlain:
|
||||||
case NfcVTypePlain:
|
furi_string_cat_printf(temp_str, "\e#ISO15693\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693\n");
|
break;
|
||||||
break;
|
case NfcVTypeSlix:
|
||||||
case NfcVTypeSlix:
|
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX\n");
|
break;
|
||||||
break;
|
case NfcVTypeSlixS:
|
||||||
case NfcVTypeSlixS:
|
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX-S\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX-S\n");
|
break;
|
||||||
break;
|
case NfcVTypeSlixL:
|
||||||
case NfcVTypeSlixL:
|
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX-L\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX-L\n");
|
break;
|
||||||
break;
|
case NfcVTypeSlix2:
|
||||||
case NfcVTypeSlix2:
|
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX2\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 SLIX2\n");
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
furi_string_cat_printf(temp_str, "\e#Unknown ISO tag\n");
|
furi_string_cat_printf(temp_str, "\e#Unknown ISO tag\n");
|
||||||
@@ -83,20 +82,21 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
|||||||
// Set tag iso data
|
// Set tag iso data
|
||||||
if(protocol == NfcDeviceProtocolNfcV) {
|
if(protocol == NfcDeviceProtocolNfcV) {
|
||||||
NfcVData* nfcv_data = &nfc->dev->dev_data.nfcv_data;
|
NfcVData* nfcv_data = &nfc->dev->dev_data.nfcv_data;
|
||||||
|
|
||||||
furi_string_cat_printf(temp_str, "UID:\n");
|
furi_string_cat_printf(temp_str, "UID:\n");
|
||||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||||
}
|
}
|
||||||
furi_string_cat_printf(temp_str, "\n");
|
furi_string_cat_printf(temp_str, "\n");
|
||||||
|
|
||||||
furi_string_cat_printf(temp_str, "DSFID: %02X\n", nfcv_data->dsfid);
|
furi_string_cat_printf(temp_str, "DSFID: %02X\n", nfcv_data->dsfid);
|
||||||
furi_string_cat_printf(temp_str, "AFI: %02X\n", nfcv_data->afi);
|
furi_string_cat_printf(temp_str, "AFI: %02X\n", nfcv_data->afi);
|
||||||
furi_string_cat_printf(temp_str, "IC Ref: %02X\n", nfcv_data->ic_ref);
|
furi_string_cat_printf(temp_str, "IC Ref: %02X\n", nfcv_data->ic_ref);
|
||||||
furi_string_cat_printf(temp_str, "Blocks: %02X\n", nfcv_data->block_num);
|
furi_string_cat_printf(temp_str, "Blocks: %02X\n", nfcv_data->block_num);
|
||||||
furi_string_cat_printf(temp_str, "Blocksize: %02X\n", nfcv_data->block_size);
|
furi_string_cat_printf(temp_str, "Blocksize: %02X\n", nfcv_data->block_size);
|
||||||
|
|
||||||
furi_string_cat_printf(temp_str, "Data (%d byte)\n", nfcv_data->block_num * nfcv_data->block_size);
|
furi_string_cat_printf(
|
||||||
|
temp_str, "Data (%d byte)\n", nfcv_data->block_num * nfcv_data->block_size);
|
||||||
|
|
||||||
int maxBlocks = nfcv_data->block_num;
|
int maxBlocks = nfcv_data->block_num;
|
||||||
if(maxBlocks > 32) {
|
if(maxBlocks > 32) {
|
||||||
@@ -106,50 +106,92 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
|||||||
|
|
||||||
for(int block = 0; block < maxBlocks; block++) {
|
for(int block = 0; block < maxBlocks; block++) {
|
||||||
for(int pos = 0; pos < nfcv_data->block_size; pos++) {
|
for(int pos = 0; pos < nfcv_data->block_size; pos++) {
|
||||||
furi_string_cat_printf(temp_str, " %02X", nfcv_data->data[block * nfcv_data->block_size + pos]);
|
furi_string_cat_printf(
|
||||||
|
temp_str, " %02X", nfcv_data->data[block * nfcv_data->block_size + pos]);
|
||||||
}
|
}
|
||||||
furi_string_cat_printf(temp_str, "\n");
|
furi_string_cat_printf(temp_str, "\n");
|
||||||
}
|
}
|
||||||
furi_string_cat_printf(temp_str, "\n");
|
furi_string_cat_printf(temp_str, "\n");
|
||||||
|
|
||||||
switch (dev_data->nfcv_data.type)
|
switch(dev_data->nfcv_data.type) {
|
||||||
{
|
case NfcVTypePlain:
|
||||||
case NfcVTypePlain:
|
furi_string_cat_printf(temp_str, "Type: Plain\n");
|
||||||
furi_string_cat_printf(temp_str, "Type: Plain\n");
|
break;
|
||||||
break;
|
case NfcVTypeSlix:
|
||||||
case NfcVTypeSlix:
|
furi_string_cat_printf(temp_str, "Type: SLIX\n");
|
||||||
furi_string_cat_printf(temp_str, "Type: SLIX\n");
|
furi_string_cat_printf(temp_str, "Keys:\n");
|
||||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, " EAS %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
|
temp_str,
|
||||||
break;
|
" EAS %08lX\n",
|
||||||
case NfcVTypeSlixS:
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix.key_eas));
|
||||||
furi_string_cat_printf(temp_str, "Type: SLIX-S\n");
|
break;
|
||||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
case NfcVTypeSlixS:
|
||||||
furi_string_cat_printf(temp_str, " Read %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_read));
|
furi_string_cat_printf(temp_str, "Type: SLIX-S\n");
|
||||||
furi_string_cat_printf(temp_str, " Write %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_write));
|
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_s.key_privacy));
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, " Destroy %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_destroy));
|
temp_str,
|
||||||
furi_string_cat_printf(temp_str, " EAS %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_eas));
|
" Read %08lX\n",
|
||||||
break;
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_read));
|
||||||
case NfcVTypeSlixL:
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, "Type: SLIX-L\n");
|
temp_str,
|
||||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
" Write %08lX\n",
|
||||||
furi_string_cat_printf(temp_str, " Privacy %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_l.key_privacy));
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_write));
|
||||||
furi_string_cat_printf(temp_str, " Destroy %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_l.key_destroy));
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, " EAS %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_l.key_eas));
|
temp_str,
|
||||||
break;
|
" Privacy %08lX\n",
|
||||||
case NfcVTypeSlix2:
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_privacy));
|
||||||
furi_string_cat_printf(temp_str, "Type: SLIX2\n");
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, "Keys:\n");
|
temp_str,
|
||||||
furi_string_cat_printf(temp_str, " Read %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_read));
|
" Destroy %08lX\n",
|
||||||
furi_string_cat_printf(temp_str, " Write %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_write));
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_destroy));
|
||||||
furi_string_cat_printf(temp_str, " Privacy %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_privacy));
|
furi_string_cat_printf(
|
||||||
furi_string_cat_printf(temp_str, " Destroy %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_destroy));
|
temp_str,
|
||||||
furi_string_cat_printf(temp_str, " EAS %08lX\n", nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_eas));
|
" EAS %08lX\n",
|
||||||
break;
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_s.key_eas));
|
||||||
default:
|
break;
|
||||||
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
case NfcVTypeSlixL:
|
||||||
break;
|
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_l.key_privacy));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" Destroy %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_l.key_destroy));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" EAS %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix_l.key_eas));
|
||||||
|
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.slix2.key_read));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" Write %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_write));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" Privacy %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_privacy));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" Destroy %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_destroy));
|
||||||
|
furi_string_cat_printf(
|
||||||
|
temp_str,
|
||||||
|
" EAS %08lX\n",
|
||||||
|
nfc_scene_nfc_data_info_get_key(nfcv_data->sub_data.slix2.key_eas));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char iso_type = FURI_BIT(nfc_data->sak, 5) ? '4' : '3';
|
char iso_type = FURI_BIT(nfc_data->sak, 5) ? '4' : '3';
|
||||||
@@ -158,7 +200,8 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
|||||||
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
for(size_t i = 0; i < nfc_data->uid_len; i++) {
|
||||||
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]);
|
||||||
}
|
}
|
||||||
furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", nfc_data->atqa[1], nfc_data->atqa[0]);
|
furi_string_cat_printf(
|
||||||
|
temp_str, "\nATQA: %02X %02X ", nfc_data->atqa[1], nfc_data->atqa[0]);
|
||||||
furi_string_cat_printf(temp_str, " SAK: %02X", nfc_data->sak);
|
furi_string_cat_printf(temp_str, " SAK: %02X", nfc_data->sak);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,10 @@ void nfc_scene_nfcv_menu_on_enter(void* context) {
|
|||||||
Nfc* nfc = context;
|
Nfc* nfc = context;
|
||||||
Submenu* submenu = nfc->submenu;
|
Submenu* submenu = nfc->submenu;
|
||||||
|
|
||||||
submenu_add_item(
|
submenu_add_item(submenu, "Save", SubmenuIndexSave, nfc_scene_nfcv_menu_submenu_callback, nfc);
|
||||||
submenu, "Save", SubmenuIndexSave, nfc_scene_nfcv_menu_submenu_callback, nfc);
|
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_nfcv_menu_submenu_callback, nfc);
|
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_nfcv_menu_submenu_callback, nfc);
|
||||||
|
|
||||||
submenu_set_selected_item(
|
submenu_set_selected_item(
|
||||||
nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVMenu));
|
nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVMenu));
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ bool nfc_scene_nfcv_menu_on_event(void* context, SceneManagerEvent event) {
|
|||||||
DOLPHIN_DEED(DolphinDeedNfcEmulate);
|
DOLPHIN_DEED(DolphinDeedNfcEmulate);
|
||||||
}
|
}
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcVMenu, event.event);
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcVMenu, event.event);
|
||||||
|
|
||||||
} else if(event.type == SceneManagerEventTypeBack) {
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
|||||||
@@ -30,29 +30,36 @@ void nfc_scene_nfcv_unlock_set_state(Nfc* nfc, NfcSceneNfcVUnlockState state) {
|
|||||||
FuriHalNfcDevData* nfc_data = &(nfc->dev->dev_data.nfc_data);
|
FuriHalNfcDevData* nfc_data = &(nfc->dev->dev_data.nfc_data);
|
||||||
NfcVData* nfcv_data = &(nfc->dev->dev_data.nfcv_data);
|
NfcVData* nfcv_data = &(nfc->dev->dev_data.nfcv_data);
|
||||||
|
|
||||||
uint32_t curr_state =
|
uint32_t curr_state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVUnlock);
|
||||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVUnlock);
|
|
||||||
if(curr_state != state) {
|
if(curr_state != state) {
|
||||||
Popup* popup = nfc->popup;
|
Popup* popup = nfc->popup;
|
||||||
if(state == NfcSceneNfcVUnlockStateDetecting) {
|
if(state == NfcSceneNfcVUnlockStateDetecting) {
|
||||||
popup_reset(popup);
|
popup_reset(popup);
|
||||||
popup_set_text(
|
popup_set_text(popup, "Put Tonie On\nFlipper's Back", 97, 24, AlignCenter, AlignTop);
|
||||||
popup, "Put Tonie On\nFlipper's Back", 97, 24, AlignCenter, AlignTop);
|
|
||||||
popup_set_icon(popup, 0, 8, &I_NFC_manual_60x50);
|
popup_set_icon(popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
} else if(state == NfcSceneNfcVUnlockStateUnlocked) {
|
} else if(state == NfcSceneNfcVUnlockStateUnlocked) {
|
||||||
popup_reset(popup);
|
popup_reset(popup);
|
||||||
|
|
||||||
if(nfc_worker_get_state(nfc->worker) == NfcWorkerStateNfcVUnlockAndSave) {
|
if(nfc_worker_get_state(nfc->worker) == NfcWorkerStateNfcVUnlockAndSave) {
|
||||||
nfc_text_store_set(nfc, "SLIX_%02X%02X%02X%02X%02X%02X%02X%02X",
|
nfc_text_store_set(
|
||||||
nfc_data->uid[0], nfc_data->uid[1], nfc_data->uid[2], nfc_data->uid[3],
|
nfc,
|
||||||
nfc_data->uid[4], nfc_data->uid[5], nfc_data->uid[6], nfc_data->uid[7]);
|
"SLIX_%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
|
nfc_data->uid[0],
|
||||||
|
nfc_data->uid[1],
|
||||||
|
nfc_data->uid[2],
|
||||||
|
nfc_data->uid[3],
|
||||||
|
nfc_data->uid[4],
|
||||||
|
nfc_data->uid[5],
|
||||||
|
nfc_data->uid[6],
|
||||||
|
nfc_data->uid[7]);
|
||||||
|
|
||||||
nfc->dev->format = NfcDeviceSaveFormatNfcV;
|
nfc->dev->format = NfcDeviceSaveFormatNfcV;
|
||||||
|
|
||||||
if(nfc_device_save(nfc->dev, nfc->text_store)) {
|
if(nfc_device_save(nfc->dev, nfc->text_store)) {
|
||||||
popup_set_header(popup, "Successfully\nsaved", 94, 3, AlignCenter, AlignTop);
|
popup_set_header(popup, "Successfully\nsaved", 94, 3, AlignCenter, AlignTop);
|
||||||
} else {
|
} else {
|
||||||
popup_set_header(popup, "Unlocked but\nsave failed!", 94, 3, AlignCenter, AlignTop);
|
popup_set_header(
|
||||||
|
popup, "Unlocked but\nsave failed!", 94, 3, AlignCenter, AlignTop);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
popup_set_header(popup, "Successfully\nunlocked", 94, 3, AlignCenter, AlignTop);
|
popup_set_header(popup, "Successfully\nunlocked", 94, 3, AlignCenter, AlignTop);
|
||||||
@@ -82,13 +89,7 @@ void nfc_scene_nfcv_unlock_set_state(Nfc* nfc, NfcSceneNfcVUnlockState state) {
|
|||||||
} else if(state == NfcSceneNfcVUnlockStateNotSupportedCard) {
|
} else if(state == NfcSceneNfcVUnlockStateNotSupportedCard) {
|
||||||
popup_reset(popup);
|
popup_reset(popup);
|
||||||
popup_set_header(popup, "Wrong Type Of Card!", 64, 3, AlignCenter, AlignTop);
|
popup_set_header(popup, "Wrong Type Of Card!", 64, 3, AlignCenter, AlignTop);
|
||||||
popup_set_text(
|
popup_set_text(popup, nfcv_data->error, 4, 22, AlignLeft, AlignTop);
|
||||||
popup,
|
|
||||||
nfcv_data->error,
|
|
||||||
4,
|
|
||||||
22,
|
|
||||||
AlignLeft,
|
|
||||||
AlignTop);
|
|
||||||
popup_set_icon(popup, 73, 20, &I_DolphinCommon_56x48);
|
popup_set_icon(popup, 73, 20, &I_DolphinCommon_56x48);
|
||||||
}
|
}
|
||||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcVUnlock, state);
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcVUnlock, state);
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ void nfc_scene_nfcv_unlock_menu_on_enter(void* context) {
|
|||||||
Nfc* nfc = context;
|
Nfc* nfc = context;
|
||||||
Submenu* submenu = nfc->submenu;
|
Submenu* submenu = nfc->submenu;
|
||||||
|
|
||||||
uint32_t state =
|
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVUnlockMenu);
|
||||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcVUnlockMenu);
|
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
submenu,
|
submenu,
|
||||||
"Enter PWD Manually",
|
"Enter PWD Manually",
|
||||||
@@ -49,8 +48,7 @@ bool nfc_scene_nfcv_unlock_menu_on_event(void* context, SceneManagerEvent event)
|
|||||||
DOLPHIN_DEED(DolphinDeedNfcRead);
|
DOLPHIN_DEED(DolphinDeedNfcRead);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
scene_manager_set_scene_state(
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcVUnlockMenu, event.event);
|
||||||
nfc->scene_manager, NfcSceneNfcVUnlockMenu, event.event);
|
|
||||||
}
|
}
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,11 +6,9 @@
|
|||||||
|
|
||||||
#define TAG "DigitalSignal"
|
#define TAG "DigitalSignal"
|
||||||
|
|
||||||
|
#define F_TIM (64000000.0)
|
||||||
#define F_TIM (64000000.0)
|
#define T_TIM 1562 /* 15.625 ns *100 */
|
||||||
#define T_TIM 1562 /* 15.625 ns *100 */
|
#define T_TIM_DIV2 781 /* 15.625 ns / 2 *100 */
|
||||||
#define T_TIM_DIV2 781 /* 15.625 ns / 2 *100 */
|
|
||||||
|
|
||||||
|
|
||||||
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt) {
|
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt) {
|
||||||
DigitalSignal* signal = malloc(sizeof(DigitalSignal));
|
DigitalSignal* signal = malloc(sizeof(DigitalSignal));
|
||||||
@@ -21,7 +19,7 @@ DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt) {
|
|||||||
signal->reload_reg_buff = malloc(signal->edges_max_cnt * sizeof(uint32_t));
|
signal->reload_reg_buff = malloc(signal->edges_max_cnt * sizeof(uint32_t));
|
||||||
signal->reload_reg_entries = 0;
|
signal->reload_reg_entries = 0;
|
||||||
signal->reload_reg_remainder = 0;
|
signal->reload_reg_remainder = 0;
|
||||||
|
|
||||||
signal->dma_config_gpio.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
signal->dma_config_gpio.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
||||||
signal->dma_config_gpio.Mode = LL_DMA_MODE_CIRCULAR;
|
signal->dma_config_gpio.Mode = LL_DMA_MODE_CIRCULAR;
|
||||||
signal->dma_config_gpio.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
signal->dma_config_gpio.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||||
@@ -32,7 +30,7 @@ DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt) {
|
|||||||
signal->dma_config_gpio.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
|
signal->dma_config_gpio.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
|
||||||
signal->dma_config_gpio.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
signal->dma_config_gpio.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
||||||
|
|
||||||
signal->dma_config_timer.PeriphOrM2MSrcAddress = (uint32_t) &(TIM2->ARR);
|
signal->dma_config_timer.PeriphOrM2MSrcAddress = (uint32_t) & (TIM2->ARR);
|
||||||
signal->dma_config_timer.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
signal->dma_config_timer.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
||||||
signal->dma_config_timer.Mode = LL_DMA_MODE_NORMAL;
|
signal->dma_config_timer.Mode = LL_DMA_MODE_NORMAL;
|
||||||
signal->dma_config_timer.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
signal->dma_config_timer.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||||
@@ -135,7 +133,7 @@ void digital_signal_prepare(DigitalSignal* signal) {
|
|||||||
furi_assert(signal);
|
furi_assert(signal);
|
||||||
furi_assert(signal->gpio);
|
furi_assert(signal->gpio);
|
||||||
furi_assert(signal->gpio->pin);
|
furi_assert(signal->gpio->pin);
|
||||||
|
|
||||||
/* set up signal polarities */
|
/* set up signal polarities */
|
||||||
uint32_t bit_set = signal->gpio->pin;
|
uint32_t bit_set = signal->gpio->pin;
|
||||||
uint32_t bit_reset = signal->gpio->pin << 16;
|
uint32_t bit_reset = signal->gpio->pin << 16;
|
||||||
@@ -181,8 +179,8 @@ static bool digital_signal_setup_dma(DigitalSignal* signal) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t) signal->gpio_buff;
|
signal->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t)signal->gpio_buff;
|
||||||
signal->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t) &(signal->gpio->port->BSRR);
|
signal->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t) & (signal->gpio->port->BSRR);
|
||||||
signal->dma_config_timer.MemoryOrM2MDstAddress = (uint32_t)signal->reload_reg_buff;
|
signal->dma_config_timer.MemoryOrM2MDstAddress = (uint32_t)signal->reload_reg_buff;
|
||||||
signal->dma_config_timer.NbData = signal->reload_reg_entries;
|
signal->dma_config_timer.NbData = signal->reload_reg_entries;
|
||||||
|
|
||||||
@@ -198,7 +196,6 @@ static bool digital_signal_setup_dma(DigitalSignal* signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void digital_signal_setup_timer() {
|
static void digital_signal_setup_timer() {
|
||||||
|
|
||||||
digital_signal_stop_timer();
|
digital_signal_stop_timer();
|
||||||
|
|
||||||
LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP);
|
LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP);
|
||||||
@@ -256,7 +253,6 @@ void digital_sequence_alloc_sequence(DigitalSequence* sequence, uint32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) {
|
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) {
|
||||||
|
|
||||||
DigitalSequence* sequence = malloc(sizeof(DigitalSequence));
|
DigitalSequence* sequence = malloc(sizeof(DigitalSequence));
|
||||||
|
|
||||||
sequence->gpio = gpio;
|
sequence->gpio = gpio;
|
||||||
@@ -276,7 +272,10 @@ void digital_sequence_free(DigitalSequence* sequence) {
|
|||||||
free(sequence);
|
free(sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
void digital_sequence_set_signal(DigitalSequence* sequence, uint8_t signal_index, DigitalSignal* signal) {
|
void digital_sequence_set_signal(
|
||||||
|
DigitalSequence* sequence,
|
||||||
|
uint8_t signal_index,
|
||||||
|
DigitalSignal* signal) {
|
||||||
furi_assert(sequence);
|
furi_assert(sequence);
|
||||||
furi_assert(signal);
|
furi_assert(signal);
|
||||||
furi_assert(signal_index < sequence->signals_size);
|
furi_assert(signal_index < sequence->signals_size);
|
||||||
@@ -301,52 +300,48 @@ void digital_sequence_add(DigitalSequence* sequence, uint8_t signal_index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void digital_signal_update_dma(DigitalSignal* signal) {
|
void digital_signal_update_dma(DigitalSignal* signal) {
|
||||||
|
|
||||||
volatile uint32_t dma1_data[] = {
|
volatile uint32_t dma1_data[] = {
|
||||||
/* R6 */ (uint32_t)&(DMA1_Channel1->CCR),
|
/* R6 */ (uint32_t) & (DMA1_Channel1->CCR),
|
||||||
/* R7 */ DMA1_Channel1->CCR & ~DMA_CCR_EN,
|
/* R7 */ DMA1_Channel1->CCR & ~DMA_CCR_EN,
|
||||||
/* R8 */ 2,
|
/* R8 */ 2,
|
||||||
/* R9 */ (uint32_t)&(signal->gpio->port->BSRR),
|
/* R9 */ (uint32_t) & (signal->gpio->port->BSRR),
|
||||||
/* R10 */ (uint32_t)signal->gpio_buff,
|
/* R10 */ (uint32_t)signal->gpio_buff,
|
||||||
/* R11 */ DMA1_Channel1->CCR | DMA_CCR_EN };
|
/* R11 */ DMA1_Channel1->CCR | DMA_CCR_EN};
|
||||||
|
|
||||||
volatile uint32_t dma2_data[] = {
|
volatile uint32_t dma2_data[] = {
|
||||||
/* R0 */ (uint32_t)&(DMA1_Channel2->CCR),
|
/* R0 */ (uint32_t) & (DMA1_Channel2->CCR),
|
||||||
/* R1 */ DMA1_Channel2->CCR & ~DMA_CCR_EN,
|
/* R1 */ DMA1_Channel2->CCR & ~DMA_CCR_EN,
|
||||||
/* R2 */ (uint32_t)signal->reload_reg_entries,
|
/* R2 */ (uint32_t)signal->reload_reg_entries,
|
||||||
/* R3 */ (uint32_t)&(TIM2->ARR),
|
/* R3 */ (uint32_t) & (TIM2->ARR),
|
||||||
/* R4 */ (uint32_t)signal->reload_reg_buff,
|
/* R4 */ (uint32_t)signal->reload_reg_buff,
|
||||||
/* R5 */ DMA1_Channel2->CCR | DMA_CCR_EN };
|
/* R5 */ DMA1_Channel2->CCR | DMA_CCR_EN};
|
||||||
|
|
||||||
|
|
||||||
/* hurry when setting up next transfer */
|
/* hurry when setting up next transfer */
|
||||||
asm volatile("\t"
|
asm volatile("\t"
|
||||||
"MOV r6, %[data1]\n\t"
|
"MOV r6, %[data1]\n\t"
|
||||||
"MOV r7, %[data2]\n\t"
|
"MOV r7, %[data2]\n\t"
|
||||||
|
|
||||||
"PUSH {r0-r12}\n\t"
|
"PUSH {r0-r12}\n\t"
|
||||||
|
|
||||||
"LDM r7, {r0-r5}\n\t"
|
"LDM r7, {r0-r5}\n\t"
|
||||||
"LDM r6, {r6-r11}\n\t"
|
"LDM r6, {r6-r11}\n\t"
|
||||||
|
|
||||||
"loop:\n\t"
|
"loop:\n\t"
|
||||||
"LDR r12, [r0, #4]\n\t"
|
"LDR r12, [r0, #4]\n\t"
|
||||||
"CMP r12, #0\n\t"
|
"CMP r12, #0\n\t"
|
||||||
"BNE loop\n\t"
|
"BNE loop\n\t"
|
||||||
|
|
||||||
"STM r6, {r7-r10}\n\t" /* disable channel and set up new parameters */
|
"STM r6, {r7-r10}\n\t" /* disable channel and set up new parameters */
|
||||||
"STR r11, [r6, #0]\n\t" /* enable channel again */
|
"STR r11, [r6, #0]\n\t" /* enable channel again */
|
||||||
"STM r0, {r1-r4}\n\t" /* disable channel and set up new parameters */
|
"STM r0, {r1-r4}\n\t" /* disable channel and set up new parameters */
|
||||||
"STR r5, [r0, #0]\n\t" /* enable channel again */
|
"STR r5, [r0, #0]\n\t" /* enable channel again */
|
||||||
|
|
||||||
"POP {r0-r12}\n\t"
|
"POP {r0-r12}\n\t"
|
||||||
|
|
||||||
: /* no outputs*/
|
: /* no outputs*/
|
||||||
: /* inputs */
|
: /* inputs */
|
||||||
[data1] "r" (dma1_data),
|
[data1] "r"(dma1_data), [data2] "r"(dma2_data)
|
||||||
[data2] "r" (dma2_data)
|
: "r6", "r7");
|
||||||
: "r6", "r7" );
|
|
||||||
|
|
||||||
|
|
||||||
LL_DMA_ClearFlag_TC1(DMA1);
|
LL_DMA_ClearFlag_TC1(DMA1);
|
||||||
LL_DMA_ClearFlag_TC2(DMA1);
|
LL_DMA_ClearFlag_TC2(DMA1);
|
||||||
@@ -354,7 +349,7 @@ void digital_signal_update_dma(DigitalSignal* signal) {
|
|||||||
|
|
||||||
static bool digital_sequence_send_signal(DigitalSignal* signal) {
|
static bool digital_sequence_send_signal(DigitalSignal* signal) {
|
||||||
furi_assert(signal);
|
furi_assert(signal);
|
||||||
|
|
||||||
/* the first iteration has to set up the whole machinery */
|
/* the first iteration has to set up the whole machinery */
|
||||||
if(!LL_DMA_IsEnabledChannel(DMA1, LL_DMA_CHANNEL_1)) {
|
if(!LL_DMA_IsEnabledChannel(DMA1, LL_DMA_CHANNEL_1)) {
|
||||||
if(!digital_signal_setup_dma(signal)) {
|
if(!digital_signal_setup_dma(signal)) {
|
||||||
@@ -372,21 +367,20 @@ static bool digital_sequence_send_signal(DigitalSignal* signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DigitalSignal* digital_sequence_bake(DigitalSequence* sequence) {
|
DigitalSignal* digital_sequence_bake(DigitalSequence* sequence) {
|
||||||
|
|
||||||
uint32_t edges = 0;
|
uint32_t edges = 0;
|
||||||
|
|
||||||
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
||||||
uint8_t signal_index = sequence->sequence[pos];
|
uint8_t signal_index = sequence->sequence[pos];
|
||||||
DigitalSignal *sig = sequence->signals[signal_index];
|
DigitalSignal* sig = sequence->signals[signal_index];
|
||||||
|
|
||||||
edges += sig->edge_cnt;
|
edges += sig->edge_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
DigitalSignal* ret = digital_signal_alloc(edges);
|
DigitalSignal* ret = digital_signal_alloc(edges);
|
||||||
|
|
||||||
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
||||||
uint8_t signal_index = sequence->sequence[pos];
|
uint8_t signal_index = sequence->sequence[pos];
|
||||||
DigitalSignal *sig = sequence->signals[signal_index];
|
DigitalSignal* sig = sequence->signals[signal_index];
|
||||||
|
|
||||||
digital_signal_append(ret, sig);
|
digital_signal_append(ret, sig);
|
||||||
}
|
}
|
||||||
@@ -412,10 +406,14 @@ bool digital_sequence_send(DigitalSequence* sequence) {
|
|||||||
|
|
||||||
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
for(uint32_t pos = 0; pos < sequence->sequence_used; pos++) {
|
||||||
uint8_t signal_index = sequence->sequence[pos];
|
uint8_t signal_index = sequence->sequence[pos];
|
||||||
DigitalSignal *sig = sequence->signals[signal_index];
|
DigitalSignal* sig = sequence->signals[signal_index];
|
||||||
|
|
||||||
if(!sig) {
|
if(!sig) {
|
||||||
FURI_LOG_D(TAG, "digital_sequence_send: Signal at index %u, used at pos %lu is NULL, aborting", signal_index, pos);
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
"digital_sequence_send: Signal at index %u, used at pos %lu is NULL, aborting",
|
||||||
|
signal_index,
|
||||||
|
pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,10 +451,10 @@ bool digital_sequence_send(DigitalSequence* sequence) {
|
|||||||
|
|
||||||
digital_signal_stop_timer();
|
digital_signal_stop_timer();
|
||||||
digital_signal_stop_dma();
|
digital_signal_stop_dma();
|
||||||
|
|
||||||
/* undo previously prolonged edges */
|
/* undo previously prolonged edges */
|
||||||
for(uint32_t pos = 0; pos < sequence->signals_size; pos++) {
|
for(uint32_t pos = 0; pos < sequence->signals_size; pos++) {
|
||||||
DigitalSignal *sig = sequence->signals[pos];
|
DigitalSignal* sig = sequence->signals[pos];
|
||||||
|
|
||||||
if(sig && sequence->signals_prolonged[pos]) {
|
if(sig && sequence->signals_prolonged[pos]) {
|
||||||
sig->edge_timings[0]--;
|
sig->edge_timings[0]--;
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* helper for easier signal generation */
|
/* helper for easier signal generation */
|
||||||
#define DIGITAL_SIGNAL_MS(x) (x*100000000UL)
|
#define DIGITAL_SIGNAL_MS(x) (x * 100000000UL)
|
||||||
#define DIGITAL_SIGNAL_US(x) (x*100000UL)
|
#define DIGITAL_SIGNAL_US(x) (x * 100000UL)
|
||||||
#define DIGITAL_SIGNAL_NS(x) (x*100UL)
|
#define DIGITAL_SIGNAL_NS(x) (x * 100UL)
|
||||||
#define DIGITAL_SIGNAL_PS(x) (x/10UL)
|
#define DIGITAL_SIGNAL_PS(x) (x / 10UL)
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool start_level;
|
bool start_level;
|
||||||
@@ -44,7 +43,6 @@ typedef struct {
|
|||||||
const GpioPin* gpio;
|
const GpioPin* gpio;
|
||||||
} DigitalSequence;
|
} DigitalSequence;
|
||||||
|
|
||||||
|
|
||||||
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt);
|
DigitalSignal* digital_signal_alloc(uint32_t max_edges_cnt);
|
||||||
|
|
||||||
void digital_signal_free(DigitalSignal* signal);
|
void digital_signal_free(DigitalSignal* signal);
|
||||||
@@ -65,16 +63,16 @@ uint32_t digital_signal_get_edge(DigitalSignal* signal, uint32_t edge_num);
|
|||||||
|
|
||||||
void digital_signal_send(DigitalSignal* signal, const GpioPin* gpio);
|
void digital_signal_send(DigitalSignal* signal, const GpioPin* gpio);
|
||||||
|
|
||||||
|
|
||||||
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio);
|
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio);
|
||||||
void digital_sequence_free(DigitalSequence* sequence);
|
void digital_sequence_free(DigitalSequence* sequence);
|
||||||
void digital_sequence_set_signal(DigitalSequence* sequence, uint8_t signal_index, DigitalSignal* signal);
|
void digital_sequence_set_signal(
|
||||||
|
DigitalSequence* sequence,
|
||||||
|
uint8_t signal_index,
|
||||||
|
DigitalSignal* signal);
|
||||||
void digital_sequence_add(DigitalSequence* sequence, uint8_t signal_index);
|
void digital_sequence_add(DigitalSequence* sequence, uint8_t signal_index);
|
||||||
bool digital_sequence_send(DigitalSequence* sequence);
|
bool digital_sequence_send(DigitalSequence* sequence);
|
||||||
void digital_sequence_clear(DigitalSequence* sequence);
|
void digital_sequence_clear(DigitalSequence* sequence);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -656,7 +656,8 @@ static bool nfc_device_save_slix_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_write_comment_cstr(file, "SLIX specific data")) break;
|
if(!flipper_format_write_comment_cstr(file, "SLIX specific data")) break;
|
||||||
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas))) break;
|
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
|
break;
|
||||||
saved = true;
|
saved = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
@@ -667,10 +668,9 @@ bool nfc_device_load_slix_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
NfcVSlixData* data = &dev->dev_data.nfcv_data.sub_data.slix;
|
NfcVSlixData* data = &dev->dev_data.nfcv_data.sub_data.slix;
|
||||||
memset(data, 0, sizeof(NfcVData));
|
memset(data, 0, sizeof(NfcVData));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
parsed = true;
|
parsed = true;
|
||||||
@@ -685,11 +685,19 @@ static bool nfc_device_save_slix_s_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_write_comment_cstr(file, "SLIX-S specific data")) break;
|
if(!flipper_format_write_comment_cstr(file, "SLIX-S specific data")) break;
|
||||||
if(!flipper_format_write_hex(file, "Password Read", data->key_read, sizeof(data->key_read))) break;
|
if(!flipper_format_write_hex(file, "Password Read", data->key_read, sizeof(data->key_read)))
|
||||||
if(!flipper_format_write_hex(file, "Password Write", data->key_write, sizeof(data->key_write))) break;
|
break;
|
||||||
if(!flipper_format_write_hex(file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy))) break;
|
if(!flipper_format_write_hex(
|
||||||
if(!flipper_format_write_hex(file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy))) break;
|
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
||||||
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas))) break;
|
break;
|
||||||
|
if(!flipper_format_write_hex(
|
||||||
|
file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy)))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_hex(
|
||||||
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
|
break;
|
||||||
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
saved = true;
|
saved = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
@@ -701,10 +709,9 @@ bool nfc_device_load_slix_s_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
NfcVSlixSData* data = &dev->dev_data.nfcv_data.sub_data.slix_s;
|
NfcVSlixSData* data = &dev->dev_data.nfcv_data.sub_data.slix_s;
|
||||||
memset(data, 0, sizeof(NfcVData));
|
memset(data, 0, sizeof(NfcVData));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password Read", data->key_read, sizeof(data->key_read)))
|
||||||
file, "Password Read", data->key_read, sizeof(data->key_read)))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
||||||
@@ -715,8 +722,7 @@ bool nfc_device_load_slix_s_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
|
|
||||||
@@ -732,9 +738,14 @@ static bool nfc_device_save_slix_l_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_write_comment_cstr(file, "SLIX-L specific data")) break;
|
if(!flipper_format_write_comment_cstr(file, "SLIX-L specific data")) break;
|
||||||
if(!flipper_format_write_hex(file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy))) break;
|
if(!flipper_format_write_hex(
|
||||||
if(!flipper_format_write_hex(file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy))) break;
|
file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy)))
|
||||||
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas))) break;
|
break;
|
||||||
|
if(!flipper_format_write_hex(
|
||||||
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
|
break;
|
||||||
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
saved = true;
|
saved = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
@@ -746,7 +757,7 @@ bool nfc_device_load_slix_l_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
NfcVSlixLData* data = &dev->dev_data.nfcv_data.sub_data.slix_l;
|
NfcVSlixLData* data = &dev->dev_data.nfcv_data.sub_data.slix_l;
|
||||||
memset(data, 0, sizeof(NfcVData));
|
memset(data, 0, sizeof(NfcVData));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy)))
|
file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy)))
|
||||||
@@ -754,8 +765,7 @@ bool nfc_device_load_slix_l_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
|
|
||||||
@@ -771,11 +781,19 @@ static bool nfc_device_save_slix2_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_write_comment_cstr(file, "SLIX2 specific data")) break;
|
if(!flipper_format_write_comment_cstr(file, "SLIX2 specific data")) break;
|
||||||
if(!flipper_format_write_hex(file, "Password Read", data->key_read, sizeof(data->key_read))) break;
|
if(!flipper_format_write_hex(file, "Password Read", data->key_read, sizeof(data->key_read)))
|
||||||
if(!flipper_format_write_hex(file, "Password Write", data->key_write, sizeof(data->key_write))) break;
|
break;
|
||||||
if(!flipper_format_write_hex(file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy))) break;
|
if(!flipper_format_write_hex(
|
||||||
if(!flipper_format_write_hex(file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy))) break;
|
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
||||||
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas))) break;
|
break;
|
||||||
|
if(!flipper_format_write_hex(
|
||||||
|
file, "Password Privacy", data->key_privacy, sizeof(data->key_privacy)))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_hex(
|
||||||
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
|
break;
|
||||||
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_write_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
saved = true;
|
saved = true;
|
||||||
} while(false);
|
} while(false);
|
||||||
@@ -787,10 +805,9 @@ bool nfc_device_load_slix2_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
bool parsed = false;
|
bool parsed = false;
|
||||||
NfcVSlix2Data* data = &dev->dev_data.nfcv_data.sub_data.slix2;
|
NfcVSlix2Data* data = &dev->dev_data.nfcv_data.sub_data.slix2;
|
||||||
memset(data, 0, sizeof(NfcVData));
|
memset(data, 0, sizeof(NfcVData));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password Read", data->key_read, sizeof(data->key_read)))
|
||||||
file, "Password Read", data->key_read, sizeof(data->key_read)))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
file, "Password Write", data->key_write, sizeof(data->key_write)))
|
||||||
@@ -801,8 +818,7 @@ bool nfc_device_load_slix2_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(
|
||||||
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
file, "Password Destroy", data->key_destroy, sizeof(data->key_destroy)))
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_hex(
|
if(!flipper_format_read_hex(file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
||||||
file, "Password EAS", data->key_eas, sizeof(data->key_eas)))
|
|
||||||
break;
|
break;
|
||||||
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
if(!flipper_format_read_bool(file, "Privacy Mode", &data->privacy, 1)) break;
|
||||||
|
|
||||||
@@ -826,32 +842,39 @@ static bool nfc_device_save_nfcv_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
if(!flipper_format_write_hex(file, "AFI", &(data->afi), 1)) break;
|
if(!flipper_format_write_hex(file, "AFI", &(data->afi), 1)) break;
|
||||||
if(!flipper_format_write_hex(file, "IC Reference", &(data->ic_ref), 1)) break;
|
if(!flipper_format_write_hex(file, "IC Reference", &(data->ic_ref), 1)) break;
|
||||||
temp_uint32 = data->block_num;
|
temp_uint32 = data->block_num;
|
||||||
if(!flipper_format_write_comment_cstr(file, "Number of memory blocks, usually 0 to 256")) break;
|
if(!flipper_format_write_comment_cstr(file, "Number of memory blocks, usually 0 to 256"))
|
||||||
|
break;
|
||||||
if(!flipper_format_write_uint32(file, "Block Count", &temp_uint32, 1)) break;
|
if(!flipper_format_write_uint32(file, "Block Count", &temp_uint32, 1)) break;
|
||||||
if(!flipper_format_write_comment_cstr(file, "Size of a single memory block, usually 4")) break;
|
if(!flipper_format_write_comment_cstr(file, "Size of a single memory block, usually 4"))
|
||||||
|
break;
|
||||||
if(!flipper_format_write_hex(file, "Block Size", &(data->block_size), 1)) break;
|
if(!flipper_format_write_hex(file, "Block Size", &(data->block_size), 1)) break;
|
||||||
if(!flipper_format_write_hex(file, "Data Content", data->data, data->block_num * data->block_size)) break;
|
if(!flipper_format_write_hex(
|
||||||
if(!flipper_format_write_comment_cstr(file, "Subtype of this card (0 = ISO15693, 1 = SLIX, 2 = SLIX-S, 3 = SLIX-L, 4 = SLIX2)")) break;
|
file, "Data Content", data->data, data->block_num * data->block_size))
|
||||||
|
break;
|
||||||
|
if(!flipper_format_write_comment_cstr(
|
||||||
|
file,
|
||||||
|
"Subtype of this card (0 = ISO15693, 1 = SLIX, 2 = SLIX-S, 3 = SLIX-L, 4 = SLIX2)"))
|
||||||
|
break;
|
||||||
temp_uint8 = (uint8_t)data->type;
|
temp_uint8 = (uint8_t)data->type;
|
||||||
if(!flipper_format_write_hex(file, "Subtype", &temp_uint8, 1)) break;
|
if(!flipper_format_write_hex(file, "Subtype", &temp_uint8, 1)) break;
|
||||||
|
|
||||||
switch(data->type) {
|
switch(data->type) {
|
||||||
case NfcVTypePlain:
|
case NfcVTypePlain:
|
||||||
if(!flipper_format_write_comment_cstr(file, "End of ISO15693 parameters")) break;
|
if(!flipper_format_write_comment_cstr(file, "End of ISO15693 parameters")) break;
|
||||||
saved = true;
|
saved = true;
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlix:
|
case NfcVTypeSlix:
|
||||||
saved = nfc_device_save_slix_data(file, dev);
|
saved = nfc_device_save_slix_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlixS:
|
case NfcVTypeSlixS:
|
||||||
saved = nfc_device_save_slix_s_data(file, dev);
|
saved = nfc_device_save_slix_s_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlixL:
|
case NfcVTypeSlixL:
|
||||||
saved = nfc_device_save_slix_l_data(file, dev);
|
saved = nfc_device_save_slix_l_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlix2:
|
case NfcVTypeSlix2:
|
||||||
saved = nfc_device_save_slix2_data(file, dev);
|
saved = nfc_device_save_slix2_data(file, dev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
@@ -863,7 +886,7 @@ bool nfc_device_load_nfcv_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
NfcVData* data = &dev->dev_data.nfcv_data;
|
NfcVData* data = &dev->dev_data.nfcv_data;
|
||||||
|
|
||||||
memset(data, 0, sizeof(NfcVData));
|
memset(data, 0, sizeof(NfcVData));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
uint32_t temp_uint32 = 0;
|
uint32_t temp_uint32 = 0;
|
||||||
uint8_t temp_value = 0;
|
uint8_t temp_value = 0;
|
||||||
@@ -881,21 +904,21 @@ bool nfc_device_load_nfcv_data(FlipperFormat* file, NfcDevice* dev) {
|
|||||||
data->type = temp_value;
|
data->type = temp_value;
|
||||||
|
|
||||||
switch(data->type) {
|
switch(data->type) {
|
||||||
case NfcVTypePlain:
|
case NfcVTypePlain:
|
||||||
parsed = true;
|
parsed = true;
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlix:
|
case NfcVTypeSlix:
|
||||||
parsed = nfc_device_load_slix_data(file, dev);
|
parsed = nfc_device_load_slix_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlixS:
|
case NfcVTypeSlixS:
|
||||||
parsed = nfc_device_load_slix_s_data(file, dev);
|
parsed = nfc_device_load_slix_s_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlixL:
|
case NfcVTypeSlixL:
|
||||||
parsed = nfc_device_load_slix_l_data(file, dev);
|
parsed = nfc_device_load_slix_l_data(file, dev);
|
||||||
break;
|
break;
|
||||||
case NfcVTypeSlix2:
|
case NfcVTypeSlix2:
|
||||||
parsed = nfc_device_load_slix2_data(file, dev);
|
parsed = nfc_device_load_slix2_data(file, dev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
@@ -1325,14 +1348,12 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) {
|
|||||||
nfc_device_prepare_format_string(dev, temp_str);
|
nfc_device_prepare_format_string(dev, temp_str);
|
||||||
if(!flipper_format_write_string(file, "Device type", temp_str)) break;
|
if(!flipper_format_write_string(file, "Device type", temp_str)) break;
|
||||||
// Write UID
|
// Write UID
|
||||||
if(!flipper_format_write_comment_cstr(file, "UID is common for all formats"))
|
if(!flipper_format_write_comment_cstr(file, "UID is common for all formats")) break;
|
||||||
break;
|
|
||||||
if(!flipper_format_write_hex(file, "UID", data->uid, data->uid_len)) break;
|
if(!flipper_format_write_hex(file, "UID", data->uid, data->uid_len)) break;
|
||||||
|
|
||||||
if(dev->format != NfcDeviceSaveFormatNfcV) {
|
if(dev->format != NfcDeviceSaveFormatNfcV) {
|
||||||
// Write ATQA, SAK
|
// Write ATQA, SAK
|
||||||
if(!flipper_format_write_comment_cstr(file, "ISO14443 specific fields"))
|
if(!flipper_format_write_comment_cstr(file, "ISO14443 specific fields")) break;
|
||||||
break;
|
|
||||||
if(!flipper_format_write_hex(file, "ATQA", data->atqa, 2)) break;
|
if(!flipper_format_write_hex(file, "ATQA", data->atqa, 2)) break;
|
||||||
if(!flipper_format_write_hex(file, "SAK", &data->sak, 1)) break;
|
if(!flipper_format_write_hex(file, "SAK", &data->sak, 1)) break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
|
|
||||||
NfcVData* nfcv_data = &nfc_worker->dev_data->nfcv_data;
|
NfcVData* nfcv_data = &nfc_worker->dev_data->nfcv_data;
|
||||||
FuriHalNfcTxRxContext tx_rx = {};
|
FuriHalNfcTxRxContext tx_rx = {};
|
||||||
uint8_t *key_data = nfcv_data->sub_data.slix_l.key_privacy;
|
uint8_t* key_data = nfcv_data->sub_data.slix_l.key_privacy;
|
||||||
uint32_t key = 0;
|
uint32_t key = 0;
|
||||||
|
|
||||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||||
@@ -169,14 +169,14 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
|
|
||||||
furi_hal_nfc_sleep();
|
furi_hal_nfc_sleep();
|
||||||
|
|
||||||
|
while((nfc_worker->state == NfcWorkerStateNfcVUnlock) ||
|
||||||
while((nfc_worker->state == NfcWorkerStateNfcVUnlock) ||
|
(nfc_worker->state == NfcWorkerStateNfcVUnlockAndSave)) {
|
||||||
(nfc_worker->state == NfcWorkerStateNfcVUnlockAndSave)) {
|
|
||||||
|
|
||||||
furi_hal_nfc_exit_sleep();
|
furi_hal_nfc_exit_sleep();
|
||||||
furi_hal_nfc_ll_txrx_on();
|
furi_hal_nfc_ll_txrx_on();
|
||||||
furi_hal_nfc_ll_poll();
|
furi_hal_nfc_ll_poll();
|
||||||
if(furi_hal_nfc_ll_set_mode(FuriHalNfcModePollNfcv, FuriHalNfcBitrate26p48, FuriHalNfcBitrate26p48) != FuriHalNfcReturnOk) {
|
if(furi_hal_nfc_ll_set_mode(
|
||||||
|
FuriHalNfcModePollNfcv, FuriHalNfcBitrate26p48, FuriHalNfcBitrate26p48) !=
|
||||||
|
FuriHalNfcReturnOk) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCV_POLLER);
|
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCV_POLLER);
|
||||||
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
||||||
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCV);
|
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCV);
|
||||||
|
|
||||||
furi_hal_console_printf("Detect presence\r\n");
|
furi_hal_console_printf("Detect presence\r\n");
|
||||||
ReturnCode ret = slix_l_get_random(nfcv_data);
|
ReturnCode ret = slix_l_get_random(nfcv_data);
|
||||||
|
|
||||||
@@ -198,25 +198,26 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
/* chip is also visible, so no action required, just save */
|
/* chip is also visible, so no action required, just save */
|
||||||
if(nfc_worker->state == NfcWorkerStateNfcVUnlockAndSave) {
|
if(nfc_worker->state == NfcWorkerStateNfcVUnlockAndSave) {
|
||||||
NfcVReader reader = {};
|
NfcVReader reader = {};
|
||||||
|
|
||||||
if(!nfcv_read_card(&reader, &nfc_worker->dev_data->nfc_data, nfcv_data)) {
|
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_hal_console_printf(" => failed, wait for chip to disappear.\r\n");
|
||||||
snprintf(nfcv_data->error, sizeof(nfcv_data->error), "Read card\nfailed");
|
snprintf(nfcv_data->error, sizeof(nfcv_data->error), "Read card\nfailed");
|
||||||
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
|
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
|
||||||
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
|
furi_hal_console_printf(" => success, wait for chip to disappear.\r\n");
|
||||||
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(slix_l_get_random(NULL) == ERR_NONE) {
|
while(slix_l_get_random(NULL) == ERR_NONE) {
|
||||||
furi_delay_ms(100);
|
furi_delay_ms(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
furi_hal_console_printf(" => chip is already visible, wait for chip to disappear.\r\n");
|
furi_hal_console_printf(
|
||||||
|
" => chip is already visible, wait for chip to disappear.\r\n");
|
||||||
nfc_worker->callback(NfcWorkerEventAborted, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventAborted, nfc_worker->context);
|
||||||
while(slix_l_get_random(NULL) == ERR_NONE) {
|
while(slix_l_get_random(NULL) == ERR_NONE) {
|
||||||
furi_delay_ms(100);
|
furi_delay_ms(100);
|
||||||
@@ -232,7 +233,6 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
furi_hal_console_printf(" chip is invisible, unlocking\r\n");
|
furi_hal_console_printf(" chip is invisible, unlocking\r\n");
|
||||||
|
|
||||||
if(nfcv_data->auth_method == NfcVAuthMethodManual) {
|
if(nfcv_data->auth_method == NfcVAuthMethodManual) {
|
||||||
|
|
||||||
key |= key_data[0] << 24;
|
key |= key_data[0] << 24;
|
||||||
key |= key_data[1] << 16;
|
key |= key_data[1] << 16;
|
||||||
key |= key_data[2] << 8;
|
key |= key_data[2] << 8;
|
||||||
@@ -271,7 +271,8 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
if(ret != ERR_NONE) {
|
if(ret != ERR_NONE) {
|
||||||
/* unlock failed */
|
/* unlock failed */
|
||||||
furi_hal_console_printf(" => failed, wait for chip to disappear.\r\n");
|
furi_hal_console_printf(" => failed, wait for chip to disappear.\r\n");
|
||||||
snprintf(nfcv_data->error, sizeof(nfcv_data->error), "Passwords not\naccepted");
|
snprintf(
|
||||||
|
nfcv_data->error, sizeof(nfcv_data->error), "Passwords not\naccepted");
|
||||||
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventWrongCardDetected, nfc_worker->context);
|
||||||
|
|
||||||
/* reset chip */
|
/* reset chip */
|
||||||
@@ -299,8 +300,6 @@ void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
|
static bool nfc_worker_read_mf_ultralight(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
|
||||||
bool read_success = false;
|
bool read_success = false;
|
||||||
MfUltralightReader reader = {};
|
MfUltralightReader reader = {};
|
||||||
@@ -600,7 +599,7 @@ static bool nfc_worker_read_nfcb(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* t
|
|||||||
static bool nfc_worker_read_nfcv(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
|
static bool nfc_worker_read_nfcv(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
|
||||||
furi_assert(nfc_worker);
|
furi_assert(nfc_worker);
|
||||||
furi_assert(tx_rx);
|
furi_assert(tx_rx);
|
||||||
|
|
||||||
bool card_read = false;
|
bool card_read = false;
|
||||||
furi_hal_nfc_sleep();
|
furi_hal_nfc_sleep();
|
||||||
|
|
||||||
|
|||||||
@@ -96,4 +96,3 @@ void nfc_worker_start(
|
|||||||
void nfc_worker_stop(NfcWorker* nfc_worker);
|
void nfc_worker_stop(NfcWorker* nfc_worker);
|
||||||
void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker);
|
void nfc_worker_nfcv_unlock(NfcWorker* nfc_worker);
|
||||||
void nfc_worker_emulate_nfcv(NfcWorker* nfc_worker);
|
void nfc_worker_emulate_nfcv(NfcWorker* nfc_worker);
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
#define TAG "NfcA-trans-rx"
|
#define TAG "NfcA-trans-rx"
|
||||||
|
|
||||||
|
void nfca_trans_rx_init(NfcaTransRxState* state) {
|
||||||
void nfca_trans_rx_init(NfcaTransRxState *state) {
|
|
||||||
FURI_LOG_D(TAG, "Starting NfcA transparent rx");
|
FURI_LOG_D(TAG, "Starting NfcA transparent rx");
|
||||||
|
|
||||||
st25r3916ExecuteCommand(ST25R3916_CMD_STOP);
|
st25r3916ExecuteCommand(ST25R3916_CMD_STOP);
|
||||||
@@ -29,7 +28,7 @@ void nfca_trans_rx_init(NfcaTransRxState *state) {
|
|||||||
state->reader_signal = pulse_reader_alloc(&gpio_spi_r_miso, 512);
|
state->reader_signal = pulse_reader_alloc(&gpio_spi_r_miso, 512);
|
||||||
/* timebase shall be 1 ns */
|
/* timebase shall be 1 ns */
|
||||||
pulse_reader_set_timebase(state->reader_signal, PulseReaderUnitNanosecond);
|
pulse_reader_set_timebase(state->reader_signal, PulseReaderUnitNanosecond);
|
||||||
|
|
||||||
pulse_reader_start(state->reader_signal);
|
pulse_reader_start(state->reader_signal);
|
||||||
|
|
||||||
/* set start values */
|
/* set start values */
|
||||||
@@ -38,21 +37,20 @@ void nfca_trans_rx_init(NfcaTransRxState *state) {
|
|||||||
state->valid_frame = false;
|
state->valid_frame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfca_trans_rx_deinit(NfcaTransRxState *state) {
|
void nfca_trans_rx_deinit(NfcaTransRxState* state) {
|
||||||
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_nfc);
|
furi_hal_spi_bus_handle_init(&furi_hal_spi_bus_handle_nfc);
|
||||||
pulse_reader_free(state->reader_signal);
|
pulse_reader_free(state->reader_signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfca_trans_rx_pause(NfcaTransRxState *state) {
|
void nfca_trans_rx_pause(NfcaTransRxState* state) {
|
||||||
pulse_reader_stop(state->reader_signal);
|
pulse_reader_stop(state->reader_signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfca_trans_rx_continue(NfcaTransRxState *state) {
|
void nfca_trans_rx_continue(NfcaTransRxState* state) {
|
||||||
pulse_reader_start(state->reader_signal);
|
pulse_reader_start(state->reader_signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfca_bit_received(NfcaTransRxState *state, uint8_t bit) {
|
static void nfca_bit_received(NfcaTransRxState* state, uint8_t bit) {
|
||||||
|
|
||||||
/* According to ISO14443-3 short frames have 7 bits and standard 9 bits per byte,
|
/* According to ISO14443-3 short frames have 7 bits and standard 9 bits per byte,
|
||||||
where the 9th bit is odd parity. Data is transmitted LSB first. */
|
where the 9th bit is odd parity. Data is transmitted LSB first. */
|
||||||
uint32_t byte_num = (state->bits_received / 9);
|
uint32_t byte_num = (state->bits_received / 9);
|
||||||
@@ -75,10 +73,9 @@ static void nfca_bit_received(NfcaTransRxState *state, uint8_t bit) {
|
|||||||
state->bits_received++;
|
state->bits_received++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nfca_trans_rx_loop(NfcaTransRxState* state, uint32_t timeout_ms) {
|
||||||
bool nfca_trans_rx_loop(NfcaTransRxState *state, uint32_t timeout_ms) {
|
|
||||||
furi_assert(state);
|
furi_assert(state);
|
||||||
|
|
||||||
state->valid_frame = false;
|
state->valid_frame = false;
|
||||||
state->have_sof = false;
|
state->have_sof = false;
|
||||||
state->bits_received = 0;
|
state->bits_received = 0;
|
||||||
|
|||||||
@@ -10,30 +10,29 @@
|
|||||||
#include "nfc_util.h"
|
#include "nfc_util.h"
|
||||||
|
|
||||||
/* assume fc/128 */
|
/* assume fc/128 */
|
||||||
#define NFCA_FC (13560000.0f) /* MHz */
|
#define NFCA_FC (13560000.0f) /* MHz */
|
||||||
#define NFCA_FC_K ((uint32_t)(NFCA_FC/1000)) /* kHz */
|
#define NFCA_FC_K ((uint32_t)(NFCA_FC / 1000)) /* kHz */
|
||||||
#define NFCA_T1 (28.0f / NFCA_FC * 1000000000)
|
#define NFCA_T1 (28.0f / NFCA_FC * 1000000000)
|
||||||
#define NFCA_T1_MIN (24.0f / NFCA_FC * 1000000000)
|
#define NFCA_T1_MIN (24.0f / NFCA_FC * 1000000000)
|
||||||
#define NFCA_T1_MAX (41.0f / NFCA_FC * 1000000000)
|
#define NFCA_T1_MAX (41.0f / NFCA_FC * 1000000000)
|
||||||
#define NFCA_TX (64.0f / NFCA_FC * 1000000000) /* 4.7198 µs */
|
#define NFCA_TX (64.0f / NFCA_FC * 1000000000) /* 4.7198 µs */
|
||||||
#define NFCA_TX_MIN (0.90f * NFCA_TX)
|
#define NFCA_TX_MIN (0.90f * NFCA_TX)
|
||||||
#define NFCA_TX_MAX (1.10f * NFCA_TX)
|
#define NFCA_TX_MAX (1.10f * NFCA_TX)
|
||||||
#define NFCA_TB (128.0f / NFCA_FC * 1000000000) /* 9.4395 µs */
|
#define NFCA_TB (128.0f / NFCA_FC * 1000000000) /* 9.4395 µs */
|
||||||
#define NFCA_TB_MIN (0.80f * NFCA_TB)
|
#define NFCA_TB_MIN (0.80f * NFCA_TB)
|
||||||
#define NFCA_TB_MAX (1.20f * NFCA_TB)
|
#define NFCA_TB_MAX (1.20f * NFCA_TB)
|
||||||
|
|
||||||
#define IS_T1(x) ((x)>=NFCA_T1_MIN && (x)<=NFCA_T1_MAX)
|
#define IS_T1(x) ((x) >= NFCA_T1_MIN && (x) <= NFCA_T1_MAX)
|
||||||
#define IS_TX(x) ((x)>=NFCA_TX_MIN && (x)<=NFCA_TX_MAX)
|
#define IS_TX(x) ((x) >= NFCA_TX_MIN && (x) <= NFCA_TX_MAX)
|
||||||
#define IS_TB(x) ((x)>=NFCA_TB_MIN && (x)<=NFCA_TB_MAX)
|
#define IS_TB(x) ((x) >= NFCA_TB_MIN && (x) <= NFCA_TB_MAX)
|
||||||
#define IS_ZERO(x) ((x)>=-NFCA_T1_MIN/2 && (x)<=NFCA_T1_MIN/2)
|
#define IS_ZERO(x) ((x) >= -NFCA_T1_MIN / 2 && (x) <= NFCA_T1_MIN / 2)
|
||||||
|
|
||||||
#define DIGITAL_SIGNAL_UNIT_S (100000000000.0f)
|
#define DIGITAL_SIGNAL_UNIT_S (100000000000.0f)
|
||||||
#define DIGITAL_SIGNAL_UNIT_US (100000.0f)
|
#define DIGITAL_SIGNAL_UNIT_US (100000.0f)
|
||||||
|
|
||||||
#define NFCA_FRAME_LENGTH 32
|
#define NFCA_FRAME_LENGTH 32
|
||||||
#define NFCA_DEBUG_LENGTH 128
|
#define NFCA_DEBUG_LENGTH 128
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool have_sof;
|
bool have_sof;
|
||||||
bool valid_frame;
|
bool valid_frame;
|
||||||
@@ -43,12 +42,12 @@ typedef struct {
|
|||||||
uint32_t debug_buffer[NFCA_DEBUG_LENGTH];
|
uint32_t debug_buffer[NFCA_DEBUG_LENGTH];
|
||||||
size_t debug_pos;
|
size_t debug_pos;
|
||||||
uint32_t parity_bits;
|
uint32_t parity_bits;
|
||||||
PulseReader *reader_signal;
|
PulseReader* reader_signal;
|
||||||
} NfcaTransRxState;
|
} NfcaTransRxState;
|
||||||
|
|
||||||
bool nfca_trans_rx_loop(NfcaTransRxState *state, uint32_t timeout_ms);
|
bool nfca_trans_rx_loop(NfcaTransRxState* state, uint32_t timeout_ms);
|
||||||
void nfca_trans_rx_deinit(NfcaTransRxState *state);
|
void nfca_trans_rx_deinit(NfcaTransRxState* state);
|
||||||
void nfca_trans_rx_init(NfcaTransRxState *state);
|
void nfca_trans_rx_init(NfcaTransRxState* state);
|
||||||
|
|
||||||
void nfca_trans_rx_pause(NfcaTransRxState *state);
|
void nfca_trans_rx_pause(NfcaTransRxState* state);
|
||||||
void nfca_trans_rx_continue(NfcaTransRxState *state);
|
void nfca_trans_rx_continue(NfcaTransRxState* state);
|
||||||
@@ -22,8 +22,7 @@ ReturnCode nfcv_inventory(uint8_t* uid) {
|
|||||||
|
|
||||||
for(int tries = 0; tries < 5; tries++) {
|
for(int tries = 0; tries < 5; tries++) {
|
||||||
/* TODO: needs proper abstraction via fury_hal(_ll)_* */
|
/* TODO: needs proper abstraction via fury_hal(_ll)_* */
|
||||||
ret = rfalNfcvPollerInventory(
|
ret = rfalNfcvPollerInventory(RFAL_NFCV_NUM_SLOTS_1, 0, NULL, &res, &received);
|
||||||
RFAL_NFCV_NUM_SLOTS_1, 0, NULL, &res, &received);
|
|
||||||
|
|
||||||
if(ret == ERR_NONE) {
|
if(ret == ERR_NONE) {
|
||||||
break;
|
break;
|
||||||
@@ -39,10 +38,7 @@ ReturnCode nfcv_inventory(uint8_t* uid) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode nfcv_read_blocks(
|
ReturnCode nfcv_read_blocks(NfcVReader* reader, NfcVData* data) {
|
||||||
NfcVReader* reader,
|
|
||||||
NfcVData* data) {
|
|
||||||
|
|
||||||
UNUSED(reader);
|
UNUSED(reader);
|
||||||
|
|
||||||
uint16_t received = 0;
|
uint16_t received = 0;
|
||||||
@@ -53,8 +49,7 @@ ReturnCode nfcv_read_blocks(
|
|||||||
ReturnCode ret = ERR_NONE;
|
ReturnCode ret = ERR_NONE;
|
||||||
for(int tries = 0; tries < 5; tries++) {
|
for(int tries = 0; tries < 5; tries++) {
|
||||||
ret = rfalNfcvPollerReadSingleBlock(
|
ret = rfalNfcvPollerReadSingleBlock(
|
||||||
RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, block,
|
RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, block, rxBuf, sizeof(rxBuf), &received);
|
||||||
rxBuf, sizeof(rxBuf), &received);
|
|
||||||
|
|
||||||
if(ret == ERR_NONE) {
|
if(ret == ERR_NONE) {
|
||||||
break;
|
break;
|
||||||
@@ -65,9 +60,13 @@ ReturnCode nfcv_read_blocks(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
memcpy(&(data->data[block * data->block_size]), &rxBuf[1], data->block_size);
|
memcpy(&(data->data[block * data->block_size]), &rxBuf[1], data->block_size);
|
||||||
FURI_LOG_D(TAG, " %02X %02X %02X %02X",
|
FURI_LOG_D(
|
||||||
data->data[block * data->block_size + 0], data->data[block * data->block_size + 1],
|
TAG,
|
||||||
data->data[block * data->block_size + 2], data->data[block * data->block_size + 3]);
|
" %02X %02X %02X %02X",
|
||||||
|
data->data[block * data->block_size + 0],
|
||||||
|
data->data[block * data->block_size + 1],
|
||||||
|
data->data[block * data->block_size + 2],
|
||||||
|
data->data[block * data->block_size + 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERR_NONE;
|
return ERR_NONE;
|
||||||
@@ -102,10 +101,25 @@ ReturnCode nfcv_read_sysinfo(FuriHalNfcDevData* nfc_data, NfcVData* data) {
|
|||||||
data->block_num = rxBuf[12] + 1;
|
data->block_num = rxBuf[12] + 1;
|
||||||
data->block_size = rxBuf[13] + 1;
|
data->block_size = rxBuf[13] + 1;
|
||||||
data->ic_ref = rxBuf[14];
|
data->ic_ref = rxBuf[14];
|
||||||
FURI_LOG_D(TAG, " UID: %02X %02X %02X %02X %02X %02X %02X %02X",
|
FURI_LOG_D(
|
||||||
nfc_data->uid[0], nfc_data->uid[1], nfc_data->uid[2], nfc_data->uid[3],
|
TAG,
|
||||||
nfc_data->uid[4], nfc_data->uid[5], nfc_data->uid[6], nfc_data->uid[7]);
|
" UID: %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
FURI_LOG_D(TAG, " DSFID %d, AFI %d, Blocks %d, Size %d, IC Ref %d", data->dsfid, data->afi, data->block_num, data->block_size, data->ic_ref);
|
nfc_data->uid[0],
|
||||||
|
nfc_data->uid[1],
|
||||||
|
nfc_data->uid[2],
|
||||||
|
nfc_data->uid[3],
|
||||||
|
nfc_data->uid[4],
|
||||||
|
nfc_data->uid[5],
|
||||||
|
nfc_data->uid[6],
|
||||||
|
nfc_data->uid[7]);
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
" DSFID %d, AFI %d, Blocks %d, Size %d, IC Ref %d",
|
||||||
|
data->dsfid,
|
||||||
|
data->afi,
|
||||||
|
data->block_num,
|
||||||
|
data->block_size,
|
||||||
|
data->ic_ref);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
FURI_LOG_D(TAG, "Failed: %d", ret);
|
FURI_LOG_D(TAG, "Failed: %d", ret);
|
||||||
@@ -113,10 +127,7 @@ ReturnCode nfcv_read_sysinfo(FuriHalNfcDevData* nfc_data, NfcVData* data) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nfcv_read_card(
|
bool nfcv_read_card(NfcVReader* reader, FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data) {
|
||||||
NfcVReader* reader,
|
|
||||||
FuriHalNfcDevData* nfc_data,
|
|
||||||
NfcVData* nfcv_data) {
|
|
||||||
furi_assert(reader);
|
furi_assert(reader);
|
||||||
furi_assert(nfc_data);
|
furi_assert(nfc_data);
|
||||||
furi_assert(nfcv_data);
|
furi_assert(nfcv_data);
|
||||||
@@ -148,15 +159,13 @@ bool nfcv_read_card(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void nfcv_crc(uint8_t* data, uint32_t length) {
|
void nfcv_crc(uint8_t* data, uint32_t length) {
|
||||||
uint32_t reg = 0xFFFF;
|
uint32_t reg = 0xFFFF;
|
||||||
|
|
||||||
for (size_t i = 0; i < length; i++) {
|
for(size_t i = 0; i < length; i++) {
|
||||||
reg = reg ^ ((uint32_t)data[i]);
|
reg = reg ^ ((uint32_t)data[i]);
|
||||||
for (size_t j = 0; j < 8; j++) {
|
for(size_t j = 0; j < 8; j++) {
|
||||||
if (reg & 0x0001) {
|
if(reg & 0x0001) {
|
||||||
reg = (reg >> 1) ^ 0x8408;
|
reg = (reg >> 1) ^ 0x8408;
|
||||||
} else {
|
} else {
|
||||||
reg = (reg >> 1);
|
reg = (reg >> 1);
|
||||||
@@ -198,15 +207,18 @@ void nfcv_emu_alloc(NfcVData* data) {
|
|||||||
/* unmodulated 256/fc signal as building block */
|
/* unmodulated 256/fc signal as building block */
|
||||||
data->emulation.nfcv_resp_unmod_256 = digital_signal_alloc(4);
|
data->emulation.nfcv_resp_unmod_256 = digital_signal_alloc(4);
|
||||||
data->emulation.nfcv_resp_unmod_256->start_level = false;
|
data->emulation.nfcv_resp_unmod_256->start_level = false;
|
||||||
data->emulation.nfcv_resp_unmod_256->edge_timings[0] = (uint32_t)(NFCV_RESP_SUBC1_UNMOD_256 * DIGITAL_SIGNAL_UNIT_S);
|
data->emulation.nfcv_resp_unmod_256->edge_timings[0] =
|
||||||
|
(uint32_t)(NFCV_RESP_SUBC1_UNMOD_256 * DIGITAL_SIGNAL_UNIT_S);
|
||||||
data->emulation.nfcv_resp_unmod_256->edge_cnt = 1;
|
data->emulation.nfcv_resp_unmod_256->edge_cnt = 1;
|
||||||
}
|
}
|
||||||
if(!data->emulation.nfcv_resp_pulse_32) {
|
if(!data->emulation.nfcv_resp_pulse_32) {
|
||||||
/* modulated fc/32 pulse as building block */
|
/* modulated fc/32 pulse as building block */
|
||||||
data->emulation.nfcv_resp_pulse_32 = digital_signal_alloc(4);
|
data->emulation.nfcv_resp_pulse_32 = digital_signal_alloc(4);
|
||||||
data->emulation.nfcv_resp_pulse_32->start_level = true;
|
data->emulation.nfcv_resp_pulse_32->start_level = true;
|
||||||
data->emulation.nfcv_resp_pulse_32->edge_timings[0] = (uint32_t)(NFCV_RESP_SUBC1_PULSE_32 * DIGITAL_SIGNAL_UNIT_S);
|
data->emulation.nfcv_resp_pulse_32->edge_timings[0] =
|
||||||
data->emulation.nfcv_resp_pulse_32->edge_timings[1] = (uint32_t)(NFCV_RESP_SUBC1_PULSE_32 * DIGITAL_SIGNAL_UNIT_S);
|
(uint32_t)(NFCV_RESP_SUBC1_PULSE_32 * DIGITAL_SIGNAL_UNIT_S);
|
||||||
|
data->emulation.nfcv_resp_pulse_32->edge_timings[1] =
|
||||||
|
(uint32_t)(NFCV_RESP_SUBC1_PULSE_32 * DIGITAL_SIGNAL_UNIT_S);
|
||||||
data->emulation.nfcv_resp_pulse_32->edge_cnt = 2;
|
data->emulation.nfcv_resp_pulse_32->edge_cnt = 2;
|
||||||
}
|
}
|
||||||
if(!data->emulation.nfcv_resp_one) {
|
if(!data->emulation.nfcv_resp_one) {
|
||||||
@@ -214,14 +226,16 @@ void nfcv_emu_alloc(NfcVData* data) {
|
|||||||
data->emulation.nfcv_resp_one = digital_signal_alloc(24);
|
data->emulation.nfcv_resp_one = digital_signal_alloc(24);
|
||||||
digital_signal_append(data->emulation.nfcv_resp_one, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_one, data->emulation.nfcv_resp_unmod_256);
|
||||||
for(size_t i = 0; i < 8; i++) {
|
for(size_t i = 0; i < 8; i++) {
|
||||||
digital_signal_append(data->emulation.nfcv_resp_one, data->emulation.nfcv_resp_pulse_32);
|
digital_signal_append(
|
||||||
|
data->emulation.nfcv_resp_one, data->emulation.nfcv_resp_pulse_32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!data->emulation.nfcv_resp_zero) {
|
if(!data->emulation.nfcv_resp_zero) {
|
||||||
/* logical zero: 8 pulses fc/32 then 256/fc unmodulated */
|
/* logical zero: 8 pulses fc/32 then 256/fc unmodulated */
|
||||||
data->emulation.nfcv_resp_zero = digital_signal_alloc(24);
|
data->emulation.nfcv_resp_zero = digital_signal_alloc(24);
|
||||||
for(size_t i = 0; i < 8; i++) {
|
for(size_t i = 0; i < 8; i++) {
|
||||||
digital_signal_append(data->emulation.nfcv_resp_zero, data->emulation.nfcv_resp_pulse_32);
|
digital_signal_append(
|
||||||
|
data->emulation.nfcv_resp_zero, data->emulation.nfcv_resp_pulse_32);
|
||||||
}
|
}
|
||||||
digital_signal_append(data->emulation.nfcv_resp_zero, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_zero, data->emulation.nfcv_resp_unmod_256);
|
||||||
}
|
}
|
||||||
@@ -232,7 +246,8 @@ void nfcv_emu_alloc(NfcVData* data) {
|
|||||||
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_unmod_256);
|
||||||
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_unmod_256);
|
||||||
for(size_t i = 0; i < 24; i++) {
|
for(size_t i = 0; i < 24; i++) {
|
||||||
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_pulse_32);
|
digital_signal_append(
|
||||||
|
data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_pulse_32);
|
||||||
}
|
}
|
||||||
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_one);
|
digital_signal_append(data->emulation.nfcv_resp_sof, data->emulation.nfcv_resp_one);
|
||||||
}
|
}
|
||||||
@@ -241,7 +256,8 @@ void nfcv_emu_alloc(NfcVData* data) {
|
|||||||
data->emulation.nfcv_resp_eof = digital_signal_alloc(128);
|
data->emulation.nfcv_resp_eof = digital_signal_alloc(128);
|
||||||
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_zero);
|
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_zero);
|
||||||
for(size_t i = 0; i < 24; i++) {
|
for(size_t i = 0; i < 24; i++) {
|
||||||
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_pulse_32);
|
digital_signal_append(
|
||||||
|
data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_pulse_32);
|
||||||
}
|
}
|
||||||
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
||||||
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
||||||
@@ -250,13 +266,16 @@ void nfcv_emu_alloc(NfcVData* data) {
|
|||||||
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
digital_signal_append(data->emulation.nfcv_resp_eof, data->emulation.nfcv_resp_unmod_256);
|
||||||
}
|
}
|
||||||
|
|
||||||
digital_sequence_set_signal(data->emulation.nfcv_signal, NFCV_SIG_SOF, data->emulation.nfcv_resp_sof);
|
digital_sequence_set_signal(
|
||||||
digital_sequence_set_signal(data->emulation.nfcv_signal, NFCV_SIG_BIT0, data->emulation.nfcv_resp_zero);
|
data->emulation.nfcv_signal, NFCV_SIG_SOF, data->emulation.nfcv_resp_sof);
|
||||||
digital_sequence_set_signal(data->emulation.nfcv_signal, NFCV_SIG_BIT1, data->emulation.nfcv_resp_one);
|
digital_sequence_set_signal(
|
||||||
digital_sequence_set_signal(data->emulation.nfcv_signal, NFCV_SIG_EOF, data->emulation.nfcv_resp_eof);
|
data->emulation.nfcv_signal, NFCV_SIG_BIT0, data->emulation.nfcv_resp_zero);
|
||||||
|
digital_sequence_set_signal(
|
||||||
|
data->emulation.nfcv_signal, NFCV_SIG_BIT1, data->emulation.nfcv_resp_one);
|
||||||
|
digital_sequence_set_signal(
|
||||||
|
data->emulation.nfcv_signal, NFCV_SIG_EOF, data->emulation.nfcv_resp_eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void nfcv_emu_send_raw(NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
static void nfcv_emu_send_raw(NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
||||||
digital_sequence_clear(nfcv->emulation.nfcv_signal);
|
digital_sequence_clear(nfcv->emulation.nfcv_signal);
|
||||||
digital_sequence_add(nfcv->emulation.nfcv_signal, NFCV_SIG_SOF);
|
digital_sequence_add(nfcv->emulation.nfcv_signal, NFCV_SIG_SOF);
|
||||||
@@ -266,7 +285,9 @@ static void nfcv_emu_send_raw(NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
|||||||
uint32_t bit_pos = bit_total % 8;
|
uint32_t bit_pos = bit_total % 8;
|
||||||
uint8_t bit_val = 0x01 << bit_pos;
|
uint8_t bit_val = 0x01 << bit_pos;
|
||||||
|
|
||||||
digital_sequence_add(nfcv->emulation.nfcv_signal, (data[byte_pos] & bit_val) ? NFCV_SIG_BIT1 : NFCV_SIG_BIT0);
|
digital_sequence_add(
|
||||||
|
nfcv->emulation.nfcv_signal,
|
||||||
|
(data[byte_pos] & bit_val) ? NFCV_SIG_BIT1 : NFCV_SIG_BIT0);
|
||||||
}
|
}
|
||||||
|
|
||||||
digital_sequence_add(nfcv->emulation.nfcv_signal, NFCV_SIG_EOF);
|
digital_sequence_add(nfcv->emulation.nfcv_signal, NFCV_SIG_EOF);
|
||||||
@@ -277,8 +298,8 @@ static void nfcv_emu_send_raw(NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
|||||||
furi_hal_gpio_write(&gpio_spi_r_mosi, false);
|
furi_hal_gpio_write(&gpio_spi_r_mosi, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfcv_emu_send(FuriHalNfcTxRxContext* tx_rx, NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
static void
|
||||||
|
nfcv_emu_send(FuriHalNfcTxRxContext* tx_rx, NfcVData* nfcv, uint8_t* data, uint8_t length) {
|
||||||
nfcv_crc(data, length);
|
nfcv_crc(data, length);
|
||||||
nfcv_emu_send_raw(nfcv, data, length + 2);
|
nfcv_emu_send_raw(nfcv, data, length + 2);
|
||||||
if(tx_rx->sniff_tx) {
|
if(tx_rx->sniff_tx) {
|
||||||
@@ -286,22 +307,22 @@ static void nfcv_emu_send(FuriHalNfcTxRxContext* tx_rx, NfcVData* nfcv, uint8_t*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfcv_uidcpy(uint8_t *dst, uint8_t *src) {
|
static void nfcv_uidcpy(uint8_t* dst, uint8_t* src) {
|
||||||
for(int pos = 0; pos < 8; pos++) {
|
for(int pos = 0; pos < 8; pos++) {
|
||||||
dst[pos] = src[7-pos];
|
dst[pos] = src[7 - pos];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nfcv_uidcmp(uint8_t *dst, uint8_t *src) {
|
static int nfcv_uidcmp(uint8_t* dst, uint8_t* src) {
|
||||||
for(int pos = 0; pos < 8; pos++) {
|
for(int pos = 0; pos < 8; pos++) {
|
||||||
if(dst[pos] != src[7-pos]) {
|
if(dst[pos] != src[7 - pos]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t nfcv_read_be(uint8_t *data, uint32_t length) {
|
static uint32_t nfcv_read_be(uint8_t* data, uint32_t length) {
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
|
|
||||||
for(uint32_t pos = 0; pos < length; pos++) {
|
for(uint32_t pos = 0; pos < length; pos++) {
|
||||||
@@ -312,215 +333,261 @@ static uint32_t nfcv_read_be(uint8_t *data, uint32_t length) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfcv_emu_handle_packet(FuriHalNfcTxRxContext* tx_rx, FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data, uint8_t* payload, uint32_t payload_length) {
|
void nfcv_emu_handle_packet(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
FuriHalNfcDevData* nfc_data,
|
||||||
|
NfcVData* nfcv_data,
|
||||||
|
uint8_t* payload,
|
||||||
|
uint32_t payload_length) {
|
||||||
if(!payload_length) {
|
if(!payload_length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t flags = payload[0];
|
uint8_t flags = payload[0];
|
||||||
uint8_t command = payload[1];
|
uint8_t command = payload[1];
|
||||||
bool addressed = !(flags & RFAL_NFCV_REQ_FLAG_INVENTORY) && (flags & RFAL_NFCV_REQ_FLAG_ADDRESS);
|
bool addressed = !(flags & RFAL_NFCV_REQ_FLAG_INVENTORY) &&
|
||||||
|
(flags & RFAL_NFCV_REQ_FLAG_ADDRESS);
|
||||||
bool advanced = (command >= 0xA0);
|
bool advanced = (command >= 0xA0);
|
||||||
uint8_t address_offset = 2 + (advanced ? 1 : 0);
|
uint8_t address_offset = 2 + (advanced ? 1 : 0);
|
||||||
uint8_t payload_offset = address_offset + (addressed ? 8 : 0);
|
uint8_t payload_offset = address_offset + (addressed ? 8 : 0);
|
||||||
uint8_t *address = &payload[address_offset];
|
uint8_t* address = &payload[address_offset];
|
||||||
uint8_t response_buffer[32];
|
uint8_t response_buffer[32];
|
||||||
|
|
||||||
if(addressed && nfcv_uidcmp(address, nfc_data->uid)) {
|
if(addressed && nfcv_uidcmp(address, nfc_data->uid)) {
|
||||||
FURI_LOG_D(TAG, "addressed command 0x%02X, but not for us:", command);
|
FURI_LOG_D(TAG, "addressed command 0x%02X, but not for us:", command);
|
||||||
FURI_LOG_D(TAG, " dest: %02X%02X%02X%02X%02X%02X%02X%02X", address[7], address[6], address[5], address[4], address[3], address[2], address[1], address[0]);
|
FURI_LOG_D(
|
||||||
FURI_LOG_D(TAG, " our UID: %02X%02X%02X%02X%02X%02X%02X%02X", nfc_data->uid[0], nfc_data->uid[1], nfc_data->uid[2], nfc_data->uid[3], nfc_data->uid[4], nfc_data->uid[5], nfc_data->uid[6], nfc_data->uid[7]);
|
TAG,
|
||||||
|
" dest: %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
|
address[7],
|
||||||
|
address[6],
|
||||||
|
address[5],
|
||||||
|
address[4],
|
||||||
|
address[3],
|
||||||
|
address[2],
|
||||||
|
address[1],
|
||||||
|
address[0]);
|
||||||
|
FURI_LOG_D(
|
||||||
|
TAG,
|
||||||
|
" our UID: %02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
|
nfc_data->uid[0],
|
||||||
|
nfc_data->uid[1],
|
||||||
|
nfc_data->uid[2],
|
||||||
|
nfc_data->uid[3],
|
||||||
|
nfc_data->uid[4],
|
||||||
|
nfc_data->uid[5],
|
||||||
|
nfc_data->uid[6],
|
||||||
|
nfc_data->uid[7]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch(nfcv_data->type) {
|
switch(nfcv_data->type) {
|
||||||
case NfcVTypeSlixL:
|
case NfcVTypeSlixL:
|
||||||
if(nfcv_data->sub_data.slix_l.privacy &&
|
if(nfcv_data->sub_data.slix_l.privacy && command != ISO15693_CMD_NXP_GET_RANDOM_NUMBER &&
|
||||||
command != ISO15693_CMD_NXP_GET_RANDOM_NUMBER &&
|
command != ISO15693_CMD_NXP_SET_PASSWORD) {
|
||||||
command != ISO15693_CMD_NXP_SET_PASSWORD) {
|
snprintf(
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "command 0x%02X ignored, privacy mode", command);
|
nfcv_data->last_command,
|
||||||
FURI_LOG_D(TAG, "%s", nfcv_data->last_command);
|
sizeof(nfcv_data->last_command),
|
||||||
return;
|
"command 0x%02X ignored, privacy mode",
|
||||||
}
|
command);
|
||||||
break;
|
FURI_LOG_D(TAG, "%s", nfcv_data->last_command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unfortunately our response is quicker than the original NFC tag which causes frame misses */
|
/* unfortunately our response is quicker than the original NFC tag which causes frame misses */
|
||||||
furi_delay_us(270);
|
furi_delay_us(270);
|
||||||
|
|
||||||
switch(command) {
|
switch(command) {
|
||||||
case ISO15693_INVENTORY:
|
case ISO15693_INVENTORY: {
|
||||||
{
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
response_buffer[1] = nfcv_data->dsfid;
|
||||||
response_buffer[1] = nfcv_data->dsfid;
|
nfcv_uidcpy(&response_buffer[2], nfc_data->uid);
|
||||||
nfcv_uidcpy(&response_buffer[2], nfc_data->uid);
|
|
||||||
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 10);
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 10);
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "INVENTORY");
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "INVENTORY");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ISO15693_STAYQUIET:
|
case ISO15693_STAYQUIET: {
|
||||||
{
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "STAYQUIET");
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "STAYQUIET");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_LOCKBLOCK:
|
case ISO15693_LOCKBLOCK: {
|
||||||
{
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "LOCKBLOCK");
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "LOCKBLOCK");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_READ_MULTI_BLOCK:
|
case ISO15693_READ_MULTI_BLOCK: {
|
||||||
{
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "READ_MULTI_BLOCK");
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "READ_MULTI_BLOCK");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_WRITE_MULTI_BLOCK:
|
case ISO15693_WRITE_MULTI_BLOCK: {
|
||||||
{
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "WRITE_MULTI_BLOCK");
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "WRITE_MULTI_BLOCK");
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_SELECT:
|
case ISO15693_SELECT: {
|
||||||
{
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
||||||
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SELECT");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ISO15693_READBLOCK: {
|
||||||
|
uint8_t block = payload[payload_offset];
|
||||||
|
|
||||||
|
if(block >= nfcv_data->block_num) {
|
||||||
|
response_buffer[0] = ISO15693_ERROR_BLOCK_WRITE;
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SELECT");
|
} else {
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_READBLOCK:
|
|
||||||
{
|
|
||||||
uint8_t block = payload[payload_offset];
|
|
||||||
|
|
||||||
if(block >= nfcv_data->block_num) {
|
|
||||||
response_buffer[0] = ISO15693_ERROR_BLOCK_WRITE;
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
|
||||||
} else {
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
|
||||||
memcpy(&response_buffer[1], &nfcv_data->data[nfcv_data->block_size * block], nfcv_data->block_size);
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1 + nfcv_data->block_size);
|
|
||||||
}
|
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "READ BLOCK %d", block);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_WRITEBLOCK:
|
|
||||||
{
|
|
||||||
uint8_t block = payload[payload_offset];
|
|
||||||
uint8_t *data = &payload[payload_offset + 1];
|
|
||||||
|
|
||||||
if(block >= nfcv_data->block_num) {
|
|
||||||
response_buffer[0] = ISO15693_ERROR_BLOCK_WRITE;
|
|
||||||
} else {
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
|
||||||
memcpy(&nfcv_data->data[nfcv_data->block_size * block], &response_buffer[1], nfcv_data->block_size);
|
|
||||||
}
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "WRITE BLOCK %d <- %02X %02X %02X %02X", block, data[0], data[1], data[2], data[3]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_GET_SYSTEM_INFO:
|
|
||||||
{
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
|
||||||
response_buffer[1] = 0x0F;
|
|
||||||
nfcv_uidcpy(&response_buffer[2], nfc_data->uid);
|
|
||||||
response_buffer[10] = nfcv_data->dsfid; /* DSFID */
|
|
||||||
response_buffer[11] = nfcv_data->afi; /* AFI */
|
|
||||||
response_buffer[12] = nfcv_data->block_num - 1; /* number of blocks */
|
|
||||||
response_buffer[13] = nfcv_data->block_size - 1; /* block size */
|
|
||||||
response_buffer[14] = nfcv_data->ic_ref; /* IC reference */
|
|
||||||
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 15);
|
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SYSTEMINFO");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_CMD_NXP_GET_RANDOM_NUMBER:
|
|
||||||
{
|
|
||||||
nfcv_data->sub_data.slix_l.rand[0] = furi_hal_random_get();
|
|
||||||
nfcv_data->sub_data.slix_l.rand[1] = furi_hal_random_get();
|
|
||||||
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
response_buffer[1] = nfcv_data->sub_data.slix_l.rand[1];
|
memcpy(
|
||||||
response_buffer[2] = nfcv_data->sub_data.slix_l.rand[0];
|
&response_buffer[1],
|
||||||
|
&nfcv_data->data[nfcv_data->block_size * block],
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 3);
|
nfcv_data->block_size);
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command),
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1 + nfcv_data->block_size);
|
||||||
"GET_RANDOM_NUMBER -> 0x%02X%02X",
|
|
||||||
nfcv_data->sub_data.slix_l.rand[0],
|
|
||||||
nfcv_data->sub_data.slix_l.rand[1]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "READ BLOCK %d", block);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ISO15693_CMD_NXP_SET_PASSWORD:
|
case ISO15693_WRITEBLOCK: {
|
||||||
{
|
uint8_t block = payload[payload_offset];
|
||||||
uint8_t password_id = payload[payload_offset];
|
uint8_t* data = &payload[payload_offset + 1];
|
||||||
uint8_t *password_xored = &payload[payload_offset + 1];
|
|
||||||
uint8_t *rand = nfcv_data->sub_data.slix_l.rand;
|
|
||||||
uint8_t *password = NULL;
|
|
||||||
uint8_t password_rcv[4];
|
|
||||||
|
|
||||||
switch(password_id) {
|
if(block >= nfcv_data->block_num) {
|
||||||
case 4:
|
response_buffer[0] = ISO15693_ERROR_BLOCK_WRITE;
|
||||||
password = nfcv_data->sub_data.slix_l.key_privacy;
|
} else {
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
password = nfcv_data->sub_data.slix_l.key_destroy;
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
password = nfcv_data->sub_data.slix_l.key_eas;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int pos = 0; pos < 4; pos++) {
|
|
||||||
password_rcv[pos] = password_xored[3 - pos] ^ rand[pos % 2];
|
|
||||||
}
|
|
||||||
uint32_t pass_expect = nfcv_read_be(password, 4);
|
|
||||||
uint32_t pass_received = nfcv_read_be(password_rcv, 4);
|
|
||||||
|
|
||||||
/* if the password is all-zeroes, just accept any password*/
|
|
||||||
if(!pass_expect || pass_expect == pass_received) {
|
|
||||||
nfcv_data->sub_data.slix_l.privacy = false;
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SET_PASSWORD #%02X 0x%08lX OK", password_id, pass_received);
|
|
||||||
} else {
|
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SET_PASSWORD #%02X 0x%08lX/%08lX FAIL", password_id, pass_received, pass_expect);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case ISO15693_CMD_NXP_ENABLE_PRIVACY:
|
|
||||||
{
|
|
||||||
response_buffer[0] = ISO15693_NOERROR;
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
|
memcpy(
|
||||||
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
&nfcv_data->data[nfcv_data->block_size * block],
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "ISO15693_CMD_NXP_ENABLE_PRIVACY");
|
&response_buffer[1],
|
||||||
|
nfcv_data->block_size);
|
||||||
nfcv_data->sub_data.slix_l.privacy = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command,
|
||||||
|
sizeof(nfcv_data->last_command),
|
||||||
|
"WRITE BLOCK %d <- %02X %02X %02X %02X",
|
||||||
|
block,
|
||||||
|
data[0],
|
||||||
|
data[1],
|
||||||
|
data[2],
|
||||||
|
data[3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ISO15693_GET_SYSTEM_INFO: {
|
||||||
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
|
response_buffer[1] = 0x0F;
|
||||||
|
nfcv_uidcpy(&response_buffer[2], nfc_data->uid);
|
||||||
|
response_buffer[10] = nfcv_data->dsfid; /* DSFID */
|
||||||
|
response_buffer[11] = nfcv_data->afi; /* AFI */
|
||||||
|
response_buffer[12] = nfcv_data->block_num - 1; /* number of blocks */
|
||||||
|
response_buffer[13] = nfcv_data->block_size - 1; /* block size */
|
||||||
|
response_buffer[14] = nfcv_data->ic_ref; /* IC reference */
|
||||||
|
|
||||||
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 15);
|
||||||
|
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "SYSTEMINFO");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ISO15693_CMD_NXP_GET_RANDOM_NUMBER: {
|
||||||
|
nfcv_data->sub_data.slix_l.rand[0] = furi_hal_random_get();
|
||||||
|
nfcv_data->sub_data.slix_l.rand[1] = furi_hal_random_get();
|
||||||
|
|
||||||
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
|
response_buffer[1] = nfcv_data->sub_data.slix_l.rand[1];
|
||||||
|
response_buffer[2] = nfcv_data->sub_data.slix_l.rand[0];
|
||||||
|
|
||||||
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 3);
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command,
|
||||||
|
sizeof(nfcv_data->last_command),
|
||||||
|
"GET_RANDOM_NUMBER -> 0x%02X%02X",
|
||||||
|
nfcv_data->sub_data.slix_l.rand[0],
|
||||||
|
nfcv_data->sub_data.slix_l.rand[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ISO15693_CMD_NXP_SET_PASSWORD: {
|
||||||
|
uint8_t password_id = payload[payload_offset];
|
||||||
|
uint8_t* password_xored = &payload[payload_offset + 1];
|
||||||
|
uint8_t* rand = nfcv_data->sub_data.slix_l.rand;
|
||||||
|
uint8_t* password = NULL;
|
||||||
|
uint8_t password_rcv[4];
|
||||||
|
|
||||||
|
switch(password_id) {
|
||||||
|
case 4:
|
||||||
|
password = nfcv_data->sub_data.slix_l.key_privacy;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
password = nfcv_data->sub_data.slix_l.key_destroy;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
password = nfcv_data->sub_data.slix_l.key_eas;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(nfcv_data->last_command, sizeof(nfcv_data->last_command), "unsupported: %02X", command);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int pos = 0; pos < 4; pos++) {
|
||||||
|
password_rcv[pos] = password_xored[3 - pos] ^ rand[pos % 2];
|
||||||
|
}
|
||||||
|
uint32_t pass_expect = nfcv_read_be(password, 4);
|
||||||
|
uint32_t pass_received = nfcv_read_be(password_rcv, 4);
|
||||||
|
|
||||||
|
/* if the password is all-zeroes, just accept any password*/
|
||||||
|
if(!pass_expect || pass_expect == pass_received) {
|
||||||
|
nfcv_data->sub_data.slix_l.privacy = false;
|
||||||
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command,
|
||||||
|
sizeof(nfcv_data->last_command),
|
||||||
|
"SET_PASSWORD #%02X 0x%08lX OK",
|
||||||
|
password_id,
|
||||||
|
pass_received);
|
||||||
|
} else {
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command,
|
||||||
|
sizeof(nfcv_data->last_command),
|
||||||
|
"SET_PASSWORD #%02X 0x%08lX/%08lX FAIL",
|
||||||
|
password_id,
|
||||||
|
pass_received,
|
||||||
|
pass_expect);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ISO15693_CMD_NXP_ENABLE_PRIVACY: {
|
||||||
|
response_buffer[0] = ISO15693_NOERROR;
|
||||||
|
|
||||||
|
nfcv_emu_send(tx_rx, nfcv_data, response_buffer, 1);
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command,
|
||||||
|
sizeof(nfcv_data->last_command),
|
||||||
|
"ISO15693_CMD_NXP_ENABLE_PRIVACY");
|
||||||
|
|
||||||
|
nfcv_data->sub_data.slix_l.privacy = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
snprintf(
|
||||||
|
nfcv_data->last_command, sizeof(nfcv_data->last_command), "unsupported: %02X", command);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(nfcv_data->last_command) > 0) {
|
if(strlen(nfcv_data->last_command) > 0) {
|
||||||
FURI_LOG_D(TAG, "Received command %s", nfcv_data->last_command);
|
FURI_LOG_D(TAG, "Received command %s", nfcv_data->last_command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,30 +603,45 @@ void nfcv_emu_init(FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data) {
|
|||||||
furi_hal_spi_bus_handle_deinit(&furi_hal_spi_bus_handle_nfc);
|
furi_hal_spi_bus_handle_deinit(&furi_hal_spi_bus_handle_nfc);
|
||||||
|
|
||||||
FURI_LOG_D(TAG, "Starting NfcV emulation");
|
FURI_LOG_D(TAG, "Starting NfcV emulation");
|
||||||
FURI_LOG_D(TAG, " UID: %02X %02X %02X %02X %02X %02X %02X %02X",
|
FURI_LOG_D(
|
||||||
nfc_data->uid[0], nfc_data->uid[1], nfc_data->uid[2], nfc_data->uid[3],
|
TAG,
|
||||||
nfc_data->uid[4], nfc_data->uid[5], nfc_data->uid[6], nfc_data->uid[7]);
|
" UID: %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||||
|
nfc_data->uid[0],
|
||||||
|
nfc_data->uid[1],
|
||||||
|
nfc_data->uid[2],
|
||||||
|
nfc_data->uid[3],
|
||||||
|
nfc_data->uid[4],
|
||||||
|
nfc_data->uid[5],
|
||||||
|
nfc_data->uid[6],
|
||||||
|
nfc_data->uid[7]);
|
||||||
|
|
||||||
switch(nfcv_data->type) {
|
switch(nfcv_data->type) {
|
||||||
case NfcVTypeSlixL:
|
case NfcVTypeSlixL:
|
||||||
FURI_LOG_D(TAG, " Card type: SLIX-L");
|
FURI_LOG_D(TAG, " Card type: SLIX-L");
|
||||||
FURI_LOG_D(TAG, " Privacy pass: 0x%08lX", nfcv_read_be(nfcv_data->sub_data.slix_l.key_privacy, 4));
|
FURI_LOG_D(
|
||||||
FURI_LOG_D(TAG, " Destroy pass: 0x%08lX", nfcv_read_be(nfcv_data->sub_data.slix_l.key_destroy, 4));
|
TAG,
|
||||||
FURI_LOG_D(TAG, " EAS pass: 0x%08lX", nfcv_read_be(nfcv_data->sub_data.slix_l.key_eas, 4));
|
" Privacy pass: 0x%08lX",
|
||||||
FURI_LOG_D(TAG, " Privacy mode: %s", nfcv_data->sub_data.slix_l.privacy ? "ON" : "OFF");
|
nfcv_read_be(nfcv_data->sub_data.slix_l.key_privacy, 4));
|
||||||
break;
|
FURI_LOG_D(
|
||||||
case NfcVTypeSlixS:
|
TAG,
|
||||||
FURI_LOG_D(TAG, " Card type: SLIX-S");
|
" Destroy pass: 0x%08lX",
|
||||||
break;
|
nfcv_read_be(nfcv_data->sub_data.slix_l.key_destroy, 4));
|
||||||
case NfcVTypeSlix2:
|
FURI_LOG_D(
|
||||||
FURI_LOG_D(TAG, " Card type: SLIX2");
|
TAG, " EAS pass: 0x%08lX", nfcv_read_be(nfcv_data->sub_data.slix_l.key_eas, 4));
|
||||||
break;
|
FURI_LOG_D(TAG, " Privacy mode: %s", nfcv_data->sub_data.slix_l.privacy ? "ON" : "OFF");
|
||||||
case NfcVTypePlain:
|
break;
|
||||||
FURI_LOG_D(TAG, " Card type: Plain");
|
case NfcVTypeSlixS:
|
||||||
break;
|
FURI_LOG_D(TAG, " Card type: SLIX-S");
|
||||||
case NfcVTypeSlix:
|
break;
|
||||||
FURI_LOG_D(TAG, " Card type: SLIX-L");
|
case NfcVTypeSlix2:
|
||||||
break;
|
FURI_LOG_D(TAG, " Card type: SLIX2");
|
||||||
|
break;
|
||||||
|
case NfcVTypePlain:
|
||||||
|
FURI_LOG_D(TAG, " Card type: Plain");
|
||||||
|
break;
|
||||||
|
case NfcVTypeSlix:
|
||||||
|
FURI_LOG_D(TAG, " Card type: SLIX-L");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate a 512 edge buffer, more than enough */
|
/* allocate a 512 edge buffer, more than enough */
|
||||||
@@ -579,8 +661,11 @@ void nfcv_emu_deinit(NfcVData* nfcv_data) {
|
|||||||
pulse_reader_free(nfcv_data->emulation.reader_signal);
|
pulse_reader_free(nfcv_data->emulation.reader_signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nfcv_emu_loop(FuriHalNfcTxRxContext* tx_rx, FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data, uint32_t timeout_ms) {
|
bool nfcv_emu_loop(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
FuriHalNfcDevData* nfc_data,
|
||||||
|
NfcVData* nfcv_data,
|
||||||
|
uint32_t timeout_ms) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
uint32_t frame_state = NFCV_FRAME_STATE_SOF1;
|
uint32_t frame_state = NFCV_FRAME_STATE_SOF1;
|
||||||
uint32_t periods_previous = 0;
|
uint32_t periods_previous = 0;
|
||||||
@@ -592,8 +677,8 @@ bool nfcv_emu_loop(FuriHalNfcTxRxContext* tx_rx, FuriHalNfcDevData* nfc_data, Nf
|
|||||||
bool wait_for_pulse = false;
|
bool wait_for_pulse = false;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
uint32_t periods =
|
||||||
uint32_t periods = pulse_reader_receive(nfcv_data->emulation.reader_signal, timeout_ms * 1000);
|
pulse_reader_receive(nfcv_data->emulation.reader_signal, timeout_ms * 1000);
|
||||||
|
|
||||||
if(periods == PULSE_READER_NO_EDGE) {
|
if(periods == PULSE_READER_NO_EDGE) {
|
||||||
break;
|
break;
|
||||||
@@ -602,113 +687,137 @@ bool nfcv_emu_loop(FuriHalNfcTxRxContext* tx_rx, FuriHalNfcDevData* nfc_data, Nf
|
|||||||
if(wait_for_pulse) {
|
if(wait_for_pulse) {
|
||||||
wait_for_pulse = false;
|
wait_for_pulse = false;
|
||||||
if(periods != 1) {
|
if(periods != 1) {
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "SOF: Expected a single low pulse in state %lu, but got %lu", frame_state, periods);
|
snprintf(
|
||||||
|
reset_reason,
|
||||||
|
sizeof(reset_reason),
|
||||||
|
"SOF: Expected a single low pulse in state %lu, but got %lu",
|
||||||
|
frame_state,
|
||||||
|
periods);
|
||||||
frame_state = NFCV_FRAME_STATE_RESET;
|
frame_state = NFCV_FRAME_STATE_RESET;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(frame_state) {
|
switch(frame_state) {
|
||||||
case NFCV_FRAME_STATE_SOF1:
|
case NFCV_FRAME_STATE_SOF1:
|
||||||
if(periods == 1) {
|
if(periods == 1) {
|
||||||
frame_state = NFCV_FRAME_STATE_SOF2;
|
frame_state = NFCV_FRAME_STATE_SOF2;
|
||||||
} else {
|
} else {
|
||||||
frame_state = NFCV_FRAME_STATE_SOF1;
|
frame_state = NFCV_FRAME_STATE_SOF1;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case NFCV_FRAME_STATE_SOF2:
|
case NFCV_FRAME_STATE_SOF2:
|
||||||
/* waiting for the second low period, telling us about coding */
|
/* waiting for the second low period, telling us about coding */
|
||||||
if(periods == 6) {
|
if(periods == 6) {
|
||||||
frame_state = NFCV_FRAME_STATE_CODING_256;
|
frame_state = NFCV_FRAME_STATE_CODING_256;
|
||||||
periods_previous = 0;
|
|
||||||
wait_for_pulse = true;
|
|
||||||
} else if(periods == 4) {
|
|
||||||
frame_state = NFCV_FRAME_STATE_CODING_4;
|
|
||||||
periods_previous = 2;
|
|
||||||
wait_for_pulse = true;
|
|
||||||
} else {
|
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "SOF: Expected 4/6 periods, got %lu", periods);
|
|
||||||
frame_state = NFCV_FRAME_STATE_SOF1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NFCV_FRAME_STATE_CODING_256:
|
|
||||||
if(periods_previous > periods) {
|
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "1oo256: Missing %lu periods from previous symbol, got %lu", periods_previous, periods);
|
|
||||||
frame_state = NFCV_FRAME_STATE_RESET;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* previous symbol left us with some pulse periods */
|
|
||||||
periods -= periods_previous;
|
|
||||||
|
|
||||||
if(periods > 512) {
|
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "1oo256: %lu periods is too much", periods);
|
|
||||||
frame_state = NFCV_FRAME_STATE_RESET;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(periods == 2) {
|
|
||||||
frame_state = NFCV_FRAME_STATE_EOF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
periods_previous = 512 - (periods + 1);
|
|
||||||
byte_value = (periods - 1) / 2;
|
|
||||||
frame_payload[frame_pos++] = (uint8_t)byte_value;
|
|
||||||
|
|
||||||
wait_for_pulse = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NFCV_FRAME_STATE_CODING_4:
|
|
||||||
if(periods_previous > periods) {
|
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "1oo4: Missing %lu periods from previous symbol, got %lu", periods_previous, periods);
|
|
||||||
frame_state = NFCV_FRAME_STATE_RESET;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* previous symbol left us with some pulse periods */
|
|
||||||
periods -= periods_previous;
|
|
||||||
periods_previous = 0;
|
periods_previous = 0;
|
||||||
|
|
||||||
byte_value >>= 2;
|
|
||||||
bits_received += 2;
|
|
||||||
|
|
||||||
if(periods == 1) {
|
|
||||||
byte_value |= 0x00 << 6;
|
|
||||||
periods_previous = 6;
|
|
||||||
} else if(periods == 3) {
|
|
||||||
byte_value |= 0x01 << 6;
|
|
||||||
periods_previous = 4;
|
|
||||||
} else if(periods == 5) {
|
|
||||||
byte_value |= 0x02 << 6;
|
|
||||||
periods_previous = 2;
|
|
||||||
} else if(periods == 7) {
|
|
||||||
byte_value |= 0x03 << 6;
|
|
||||||
periods_previous = 0;
|
|
||||||
} else if(periods == 2) {
|
|
||||||
frame_state = NFCV_FRAME_STATE_EOF;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
snprintf(reset_reason, sizeof(reset_reason), "1oo4: Expected 1/3/5/7 low pulses, but got %lu", periods);
|
|
||||||
frame_state = NFCV_FRAME_STATE_RESET;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bits_received >= 8) {
|
|
||||||
frame_payload[frame_pos++] = (uint8_t)byte_value;
|
|
||||||
bits_received = 0;
|
|
||||||
}
|
|
||||||
wait_for_pulse = true;
|
wait_for_pulse = true;
|
||||||
|
} else if(periods == 4) {
|
||||||
|
frame_state = NFCV_FRAME_STATE_CODING_4;
|
||||||
|
periods_previous = 2;
|
||||||
|
wait_for_pulse = true;
|
||||||
|
} else {
|
||||||
|
snprintf(
|
||||||
|
reset_reason,
|
||||||
|
sizeof(reset_reason),
|
||||||
|
"SOF: Expected 4/6 periods, got %lu",
|
||||||
|
periods);
|
||||||
|
frame_state = NFCV_FRAME_STATE_SOF1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NFCV_FRAME_STATE_CODING_256:
|
||||||
|
if(periods_previous > periods) {
|
||||||
|
snprintf(
|
||||||
|
reset_reason,
|
||||||
|
sizeof(reset_reason),
|
||||||
|
"1oo256: Missing %lu periods from previous symbol, got %lu",
|
||||||
|
periods_previous,
|
||||||
|
periods);
|
||||||
|
frame_state = NFCV_FRAME_STATE_RESET;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
/* previous symbol left us with some pulse periods */
|
||||||
|
periods -= periods_previous;
|
||||||
|
|
||||||
|
if(periods > 512) {
|
||||||
|
snprintf(
|
||||||
|
reset_reason, sizeof(reset_reason), "1oo256: %lu periods is too much", periods);
|
||||||
|
frame_state = NFCV_FRAME_STATE_RESET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(periods == 2) {
|
||||||
|
frame_state = NFCV_FRAME_STATE_EOF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
periods_previous = 512 - (periods + 1);
|
||||||
|
byte_value = (periods - 1) / 2;
|
||||||
|
frame_payload[frame_pos++] = (uint8_t)byte_value;
|
||||||
|
|
||||||
|
wait_for_pulse = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NFCV_FRAME_STATE_CODING_4:
|
||||||
|
if(periods_previous > periods) {
|
||||||
|
snprintf(
|
||||||
|
reset_reason,
|
||||||
|
sizeof(reset_reason),
|
||||||
|
"1oo4: Missing %lu periods from previous symbol, got %lu",
|
||||||
|
periods_previous,
|
||||||
|
periods);
|
||||||
|
frame_state = NFCV_FRAME_STATE_RESET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* previous symbol left us with some pulse periods */
|
||||||
|
periods -= periods_previous;
|
||||||
|
periods_previous = 0;
|
||||||
|
|
||||||
|
byte_value >>= 2;
|
||||||
|
bits_received += 2;
|
||||||
|
|
||||||
|
if(periods == 1) {
|
||||||
|
byte_value |= 0x00 << 6;
|
||||||
|
periods_previous = 6;
|
||||||
|
} else if(periods == 3) {
|
||||||
|
byte_value |= 0x01 << 6;
|
||||||
|
periods_previous = 4;
|
||||||
|
} else if(periods == 5) {
|
||||||
|
byte_value |= 0x02 << 6;
|
||||||
|
periods_previous = 2;
|
||||||
|
} else if(periods == 7) {
|
||||||
|
byte_value |= 0x03 << 6;
|
||||||
|
periods_previous = 0;
|
||||||
|
} else if(periods == 2) {
|
||||||
|
frame_state = NFCV_FRAME_STATE_EOF;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
snprintf(
|
||||||
|
reset_reason,
|
||||||
|
sizeof(reset_reason),
|
||||||
|
"1oo4: Expected 1/3/5/7 low pulses, but got %lu",
|
||||||
|
periods);
|
||||||
|
frame_state = NFCV_FRAME_STATE_RESET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bits_received >= 8) {
|
||||||
|
frame_payload[frame_pos++] = (uint8_t)byte_value;
|
||||||
|
bits_received = 0;
|
||||||
|
}
|
||||||
|
wait_for_pulse = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* post-state-machine cleanup and reset */
|
/* post-state-machine cleanup and reset */
|
||||||
if(frame_state == NFCV_FRAME_STATE_RESET) {
|
if(frame_state == NFCV_FRAME_STATE_RESET) {
|
||||||
frame_state = NFCV_FRAME_STATE_SOF1;
|
frame_state = NFCV_FRAME_STATE_SOF1;
|
||||||
|
|
||||||
FURI_LOG_D(TAG, "Resetting state machine, reason: '%s'", reset_reason);
|
FURI_LOG_D(TAG, "Resetting state machine, reason: '%s'", reset_reason);
|
||||||
} else if(frame_state == NFCV_FRAME_STATE_EOF) {
|
} else if(frame_state == NFCV_FRAME_STATE_EOF) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,83 +8,77 @@
|
|||||||
#include "nfc_util.h"
|
#include "nfc_util.h"
|
||||||
#include <furi_hal_nfc.h>
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
|
#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 PULSE_DURATION_NS (128.0f * 1000000000.0f / NFCV_FC) /* ns */
|
||||||
|
|
||||||
|
#define DIGITAL_SIGNAL_UNIT_S (100000000000.0f)
|
||||||
|
#define DIGITAL_SIGNAL_UNIT_US (100000.0f)
|
||||||
|
|
||||||
#define NFCV_FC (13560000.0f) /* MHz */
|
#define NFCV_TOTAL_BLOCKS_MAX 256
|
||||||
#define NFCV_RESP_SUBC1_PULSE_32 (1.0f / (NFCV_FC/32) / 2.0f) /* 1.1799 µs */
|
#define NFCV_BLOCK_SIZE 4
|
||||||
#define NFCV_RESP_SUBC1_UNMOD_256 (256.0f / NFCV_FC) /* 18.8791 µs */
|
#define NFCV_MAX_DUMP_SIZE (NFCV_BLOCK_SIZE * NFCV_TOTAL_BLOCKS_MAX)
|
||||||
|
|
||||||
#define PULSE_DURATION_NS (128.0f * 1000000000.0f / NFCV_FC) /* ns */
|
#define NFCV_FRAME_STATE_SOF1 0
|
||||||
|
#define NFCV_FRAME_STATE_SOF2 1
|
||||||
|
#define NFCV_FRAME_STATE_CODING_4 2
|
||||||
|
#define NFCV_FRAME_STATE_CODING_256 3
|
||||||
|
#define NFCV_FRAME_STATE_EOF 4
|
||||||
|
#define NFCV_FRAME_STATE_RESET 5
|
||||||
|
|
||||||
#define DIGITAL_SIGNAL_UNIT_S (100000000000.0f)
|
#define NFCV_SIG_SOF 0
|
||||||
#define DIGITAL_SIGNAL_UNIT_US (100000.0f)
|
|
||||||
|
|
||||||
#define NFCV_TOTAL_BLOCKS_MAX 256
|
|
||||||
#define NFCV_BLOCK_SIZE 4
|
|
||||||
#define NFCV_MAX_DUMP_SIZE (NFCV_BLOCK_SIZE*NFCV_TOTAL_BLOCKS_MAX)
|
|
||||||
|
|
||||||
|
|
||||||
#define NFCV_FRAME_STATE_SOF1 0
|
|
||||||
#define NFCV_FRAME_STATE_SOF2 1
|
|
||||||
#define NFCV_FRAME_STATE_CODING_4 2
|
|
||||||
#define NFCV_FRAME_STATE_CODING_256 3
|
|
||||||
#define NFCV_FRAME_STATE_EOF 4
|
|
||||||
#define NFCV_FRAME_STATE_RESET 5
|
|
||||||
|
|
||||||
|
|
||||||
#define NFCV_SIG_SOF 0
|
|
||||||
#define NFCV_SIG_BIT0 1
|
#define NFCV_SIG_BIT0 1
|
||||||
#define NFCV_SIG_BIT1 2
|
#define NFCV_SIG_BIT1 2
|
||||||
#define NFCV_SIG_EOF 3
|
#define NFCV_SIG_EOF 3
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
#define ISO15693_INVENTORY 0x01
|
#define ISO15693_INVENTORY 0x01
|
||||||
#define ISO15693_STAYQUIET 0x02
|
#define ISO15693_STAYQUIET 0x02
|
||||||
#define ISO15693_READBLOCK 0x20
|
#define ISO15693_READBLOCK 0x20
|
||||||
#define ISO15693_WRITEBLOCK 0x21
|
#define ISO15693_WRITEBLOCK 0x21
|
||||||
#define ISO15693_LOCKBLOCK 0x22
|
#define ISO15693_LOCKBLOCK 0x22
|
||||||
#define ISO15693_READ_MULTI_BLOCK 0x23
|
#define ISO15693_READ_MULTI_BLOCK 0x23
|
||||||
#define ISO15693_WRITE_MULTI_BLOCK 0x24
|
#define ISO15693_WRITE_MULTI_BLOCK 0x24
|
||||||
#define ISO15693_SELECT 0x25
|
#define ISO15693_SELECT 0x25
|
||||||
#define ISO15693_RESET_TO_READY 0x26
|
#define ISO15693_RESET_TO_READY 0x26
|
||||||
#define ISO15693_WRITE_AFI 0x27
|
#define ISO15693_WRITE_AFI 0x27
|
||||||
#define ISO15693_LOCK_AFI 0x28
|
#define ISO15693_LOCK_AFI 0x28
|
||||||
#define ISO15693_WRITE_DSFID 0x29
|
#define ISO15693_WRITE_DSFID 0x29
|
||||||
#define ISO15693_LOCK_DSFID 0x2A
|
#define ISO15693_LOCK_DSFID 0x2A
|
||||||
#define ISO15693_GET_SYSTEM_INFO 0x2B
|
#define ISO15693_GET_SYSTEM_INFO 0x2B
|
||||||
#define ISO15693_READ_MULTI_SECSTATUS 0x2C
|
#define ISO15693_READ_MULTI_SECSTATUS 0x2C
|
||||||
|
|
||||||
// ISO15693 MANUFACTURER CODES
|
// ISO15693 MANUFACTURER CODES
|
||||||
#define ISO15693_MANUFACTURER_NXP 0x04
|
#define ISO15693_MANUFACTURER_NXP 0x04
|
||||||
|
|
||||||
// ISO15693-3 CUSTOM NXP COMMANDS
|
// ISO15693-3 CUSTOM NXP COMMANDS
|
||||||
#define ISO15693_CMD_NXP_SET_EAS 0xA2
|
#define ISO15693_CMD_NXP_SET_EAS 0xA2
|
||||||
#define ISO15693_CMD_NXP_RESET_EAS 0xA3
|
#define ISO15693_CMD_NXP_RESET_EAS 0xA3
|
||||||
#define ISO15693_CMD_NXP_LOCK_EAS 0xA4
|
#define ISO15693_CMD_NXP_LOCK_EAS 0xA4
|
||||||
#define ISO15693_CMD_NXP_EAS_ALARM 0xA5
|
#define ISO15693_CMD_NXP_EAS_ALARM 0xA5
|
||||||
#define ISO15693_CMD_NXP_PASSWORD_PROTECT_EAS_AFI 0xA6
|
#define ISO15693_CMD_NXP_PASSWORD_PROTECT_EAS_AFI 0xA6
|
||||||
#define ISO15693_CMD_NXP_WRITE_EAS_ID 0xA7
|
#define ISO15693_CMD_NXP_WRITE_EAS_ID 0xA7
|
||||||
#define ISO15693_CMD_NXP_INVENTORY_PAGE_READ 0xB0
|
#define ISO15693_CMD_NXP_INVENTORY_PAGE_READ 0xB0
|
||||||
#define ISO15693_CMD_NXP_INVENTORY_PAGE_READ_FAST 0xB1
|
#define ISO15693_CMD_NXP_INVENTORY_PAGE_READ_FAST 0xB1
|
||||||
#define ISO15693_CMD_NXP_GET_RANDOM_NUMBER 0xB2
|
#define ISO15693_CMD_NXP_GET_RANDOM_NUMBER 0xB2
|
||||||
#define ISO15693_CMD_NXP_SET_PASSWORD 0xB3
|
#define ISO15693_CMD_NXP_SET_PASSWORD 0xB3
|
||||||
#define ISO15693_CMD_NXP_WRITE_PASSWORD 0xB4
|
#define ISO15693_CMD_NXP_WRITE_PASSWORD 0xB4
|
||||||
#define ISO15693_CMD_NXP_DESTROY 0xB9
|
#define ISO15693_CMD_NXP_DESTROY 0xB9
|
||||||
#define ISO15693_CMD_NXP_ENABLE_PRIVACY 0xBA
|
#define ISO15693_CMD_NXP_ENABLE_PRIVACY 0xBA
|
||||||
|
|
||||||
// ISO15693 RESPONSE ERROR CODES
|
// ISO15693 RESPONSE ERROR CODES
|
||||||
#define ISO15693_NOERROR 0x00
|
#define ISO15693_NOERROR 0x00
|
||||||
#define ISO15693_ERROR_CMD_NOT_SUP 0x01 // Command not supported
|
#define ISO15693_ERROR_CMD_NOT_SUP 0x01 // Command not supported
|
||||||
#define ISO15693_ERROR_CMD_NOT_REC 0x02 // Command not recognized (eg. parameter error)
|
#define ISO15693_ERROR_CMD_NOT_REC 0x02 // Command not recognized (eg. parameter error)
|
||||||
#define ISO15693_ERROR_CMD_OPTION 0x03 // Command option not supported
|
#define ISO15693_ERROR_CMD_OPTION 0x03 // Command option not supported
|
||||||
#define ISO15693_ERROR_GENERIC 0x0F // No additional Info about this error
|
#define ISO15693_ERROR_GENERIC 0x0F // No additional Info about this error
|
||||||
#define ISO15693_ERROR_BLOCK_UNAVAILABLE 0x10
|
#define ISO15693_ERROR_BLOCK_UNAVAILABLE 0x10
|
||||||
#define ISO15693_ERROR_BLOCK_LOCKED_ALREADY 0x11 // cannot lock again
|
#define ISO15693_ERROR_BLOCK_LOCKED_ALREADY 0x11 // cannot lock again
|
||||||
#define ISO15693_ERROR_BLOCK_LOCKED 0x12 // cannot be changed
|
#define ISO15693_ERROR_BLOCK_LOCKED 0x12 // cannot be changed
|
||||||
#define ISO15693_ERROR_BLOCK_WRITE 0x13 // Writing was unsuccessful
|
#define ISO15693_ERROR_BLOCK_WRITE 0x13 // Writing was unsuccessful
|
||||||
#define ISO15693_ERROR_BLOCL_WRITELOCK 0x14 // Locking was unsuccessful
|
#define ISO15693_ERROR_BLOCL_WRITELOCK 0x14 // Locking was unsuccessful
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NfcVAuthMethodManual,
|
NfcVAuthMethodManual,
|
||||||
@@ -93,7 +87,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NfcVTypePlain = 0,
|
NfcVTypePlain = 0,
|
||||||
NfcVTypeSlix = 1,
|
NfcVTypeSlix = 1,
|
||||||
NfcVTypeSlixS = 2,
|
NfcVTypeSlixS = 2,
|
||||||
NfcVTypeSlixL = 3,
|
NfcVTypeSlixL = 3,
|
||||||
NfcVTypeSlix2 = 4,
|
NfcVTypeSlix2 = 4,
|
||||||
@@ -139,9 +133,8 @@ typedef union {
|
|||||||
NfcVSlixLData slix_l;
|
NfcVSlixLData slix_l;
|
||||||
} NfcVSubtypeData;
|
} NfcVSubtypeData;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PulseReader *reader_signal;
|
PulseReader* reader_signal;
|
||||||
DigitalSignal* nfcv_resp_pulse_32;
|
DigitalSignal* nfcv_resp_pulse_32;
|
||||||
DigitalSignal* nfcv_resp_unmod;
|
DigitalSignal* nfcv_resp_unmod;
|
||||||
DigitalSignal* nfcv_resp_one;
|
DigitalSignal* nfcv_resp_one;
|
||||||
@@ -179,11 +172,15 @@ typedef struct {
|
|||||||
int16_t blocks_read;
|
int16_t blocks_read;
|
||||||
} NfcVReader;
|
} NfcVReader;
|
||||||
|
|
||||||
ReturnCode nfcv_read_blocks(NfcVReader* reader, NfcVData* data);
|
ReturnCode nfcv_read_blocks(NfcVReader* reader, NfcVData* data);
|
||||||
ReturnCode nfcv_read_sysinfo(FuriHalNfcDevData* nfc_data, NfcVData* data);
|
ReturnCode nfcv_read_sysinfo(FuriHalNfcDevData* nfc_data, NfcVData* data);
|
||||||
ReturnCode nfcv_inventory(uint8_t* uid);
|
ReturnCode nfcv_inventory(uint8_t* uid);
|
||||||
bool nfcv_read_card(NfcVReader* reader, FuriHalNfcDevData* nfc_data, NfcVData* data);
|
bool nfcv_read_card(NfcVReader* reader, FuriHalNfcDevData* nfc_data, NfcVData* data);
|
||||||
|
|
||||||
void nfcv_emu_init(FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data);
|
void nfcv_emu_init(FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data);
|
||||||
void nfcv_emu_deinit(NfcVData* nfcv_data);
|
void nfcv_emu_deinit(NfcVData* nfcv_data);
|
||||||
bool nfcv_emu_loop(FuriHalNfcTxRxContext* tx_rx, FuriHalNfcDevData* nfc_data, NfcVData* nfcv_data, uint32_t timeout_ms);
|
bool nfcv_emu_loop(
|
||||||
|
FuriHalNfcTxRxContext* tx_rx,
|
||||||
|
FuriHalNfcDevData* nfc_data,
|
||||||
|
NfcVData* nfcv_data,
|
||||||
|
uint32_t timeout_ms);
|
||||||
|
|||||||
@@ -6,59 +6,49 @@
|
|||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include "furi_hal_nfc.h"
|
#include "furi_hal_nfc.h"
|
||||||
|
|
||||||
|
|
||||||
bool slix_check_card_type(FuriHalNfcDevData* nfc_data) {
|
bool slix_check_card_type(FuriHalNfcDevData* nfc_data) {
|
||||||
if((nfc_data->uid[0] == 0xE0)
|
if((nfc_data->uid[0] == 0xE0) && (nfc_data->uid[1] == 0x04) && (nfc_data->uid[2] == 0x01) &&
|
||||||
&& (nfc_data->uid[1] == 0x04)
|
(((nfc_data->uid[3] >> 4) & 3) == 2)) {
|
||||||
&& (nfc_data->uid[2] == 0x01)
|
|
||||||
&& (((nfc_data->uid[3] >> 4) & 3) == 2)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slix2_check_card_type(FuriHalNfcDevData* nfc_data) {
|
bool slix2_check_card_type(FuriHalNfcDevData* nfc_data) {
|
||||||
if((nfc_data->uid[0] == 0xE0)
|
if((nfc_data->uid[0] == 0xE0) && (nfc_data->uid[1] == 0x04) && (nfc_data->uid[2] == 0x01) &&
|
||||||
&& (nfc_data->uid[1] == 0x04)
|
(((nfc_data->uid[3] >> 4) & 3) == 1)) {
|
||||||
&& (nfc_data->uid[2] == 0x01)
|
|
||||||
&& (((nfc_data->uid[3] >> 4) & 3) == 1)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slix_s_check_card_type(FuriHalNfcDevData* nfc_data) {
|
bool slix_s_check_card_type(FuriHalNfcDevData* nfc_data) {
|
||||||
if((nfc_data->uid[0] == 0xE0)
|
if((nfc_data->uid[0] == 0xE0) && (nfc_data->uid[1] == 0x04) && (nfc_data->uid[2] == 0x02)) {
|
||||||
&& (nfc_data->uid[1] == 0x04)
|
|
||||||
&& (nfc_data->uid[2] == 0x02)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slix_l_check_card_type(FuriHalNfcDevData* nfc_data) {
|
bool slix_l_check_card_type(FuriHalNfcDevData* nfc_data) {
|
||||||
if((nfc_data->uid[0] == 0xE0)
|
if((nfc_data->uid[0] == 0xE0) && (nfc_data->uid[1] == 0x04) && (nfc_data->uid[2] == 0x03)) {
|
||||||
&& (nfc_data->uid[1] == 0x04)
|
|
||||||
&& (nfc_data->uid[2] == 0x03)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnCode slix_l_get_random(NfcVData* data) {
|
ReturnCode slix_l_get_random(NfcVData* data) {
|
||||||
uint16_t received = 0;
|
uint16_t received = 0;
|
||||||
uint8_t rxBuf[32];
|
uint8_t rxBuf[32];
|
||||||
|
|
||||||
ReturnCode ret = rfalNfcvPollerTransceiveReq(
|
ReturnCode ret = rfalNfcvPollerTransceiveReq(
|
||||||
ISO15693_CMD_NXP_GET_RANDOM_NUMBER,
|
ISO15693_CMD_NXP_GET_RANDOM_NUMBER,
|
||||||
RFAL_NFCV_REQ_FLAG_DEFAULT,
|
RFAL_NFCV_REQ_FLAG_DEFAULT,
|
||||||
ISO15693_MANUFACTURER_NXP,
|
ISO15693_MANUFACTURER_NXP,
|
||||||
NULL,
|
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
NULL,
|
||||||
rxBuf,
|
0,
|
||||||
sizeof(rxBuf),
|
rxBuf,
|
||||||
|
sizeof(rxBuf),
|
||||||
&received);
|
&received);
|
||||||
|
|
||||||
if(ret == ERR_NONE) {
|
if(ret == ERR_NONE) {
|
||||||
@@ -76,30 +66,29 @@ ReturnCode slix_l_get_random(NfcVData* data) {
|
|||||||
|
|
||||||
ReturnCode slix_l_unlock(NfcVData* data, uint32_t password_id) {
|
ReturnCode slix_l_unlock(NfcVData* data, uint32_t password_id) {
|
||||||
furi_assert(rand);
|
furi_assert(rand);
|
||||||
|
|
||||||
uint16_t received = 0;
|
uint16_t received = 0;
|
||||||
uint8_t rxBuf[32];
|
uint8_t rxBuf[32];
|
||||||
uint8_t cmd_set_pass[] = {
|
uint8_t cmd_set_pass[] = {
|
||||||
password_id,
|
password_id,
|
||||||
data->sub_data.slix_l.rand[1],
|
data->sub_data.slix_l.rand[1],
|
||||||
data->sub_data.slix_l.rand[0],
|
data->sub_data.slix_l.rand[0],
|
||||||
data->sub_data.slix_l.rand[1],
|
data->sub_data.slix_l.rand[1],
|
||||||
data->sub_data.slix_l.rand[0]
|
data->sub_data.slix_l.rand[0]};
|
||||||
};
|
uint8_t* password = NULL;
|
||||||
uint8_t *password = NULL;
|
|
||||||
|
|
||||||
switch(password_id) {
|
switch(password_id) {
|
||||||
case 4:
|
case 4:
|
||||||
password = data->sub_data.slix_l.key_privacy;
|
password = data->sub_data.slix_l.key_privacy;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
password = data->sub_data.slix_l.key_destroy;
|
password = data->sub_data.slix_l.key_destroy;
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
password = data->sub_data.slix_l.key_eas;
|
password = data->sub_data.slix_l.key_eas;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!password) {
|
if(!password) {
|
||||||
@@ -111,14 +100,14 @@ ReturnCode slix_l_unlock(NfcVData* data, uint32_t password_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode ret = rfalNfcvPollerTransceiveReq(
|
ReturnCode ret = rfalNfcvPollerTransceiveReq(
|
||||||
ISO15693_CMD_NXP_SET_PASSWORD,
|
ISO15693_CMD_NXP_SET_PASSWORD,
|
||||||
RFAL_NFCV_REQ_FLAG_DATA_RATE,
|
RFAL_NFCV_REQ_FLAG_DATA_RATE,
|
||||||
ISO15693_MANUFACTURER_NXP,
|
ISO15693_MANUFACTURER_NXP,
|
||||||
NULL,
|
NULL,
|
||||||
cmd_set_pass,
|
cmd_set_pass,
|
||||||
sizeof(cmd_set_pass),
|
sizeof(cmd_set_pass),
|
||||||
rxBuf,
|
rxBuf,
|
||||||
sizeof(rxBuf),
|
sizeof(rxBuf),
|
||||||
&received);
|
&received);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -5,10 +5,9 @@
|
|||||||
#include "nfc_util.h"
|
#include "nfc_util.h"
|
||||||
#include <furi_hal_nfc.h>
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
#define ISO15693_CMD_NXP_GET_RANDOM_NUMBER 0xB2
|
#define ISO15693_CMD_NXP_GET_RANDOM_NUMBER 0xB2
|
||||||
#define ISO15693_CMD_NXP_SET_PASSWORD 0xB3
|
#define ISO15693_CMD_NXP_SET_PASSWORD 0xB3
|
||||||
#define ISO15693_MANUFACTURER_NXP 0x04
|
#define ISO15693_MANUFACTURER_NXP 0x04
|
||||||
|
|
||||||
|
|
||||||
bool slix_check_card_type(FuriHalNfcDevData* nfc_data);
|
bool slix_check_card_type(FuriHalNfcDevData* nfc_data);
|
||||||
bool slix2_check_card_type(FuriHalNfcDevData* nfc_data);
|
bool slix2_check_card_type(FuriHalNfcDevData* nfc_data);
|
||||||
@@ -16,4 +15,3 @@ bool slix_s_check_card_type(FuriHalNfcDevData* nfc_data);
|
|||||||
bool slix_l_check_card_type(FuriHalNfcDevData* nfc_data);
|
bool slix_l_check_card_type(FuriHalNfcDevData* nfc_data);
|
||||||
ReturnCode slix_l_get_random(NfcVData* data);
|
ReturnCode slix_l_get_random(NfcVData* data);
|
||||||
ReturnCode slix_l_unlock(NfcVData* data, uint32_t password_id);
|
ReturnCode slix_l_unlock(NfcVData* data, uint32_t password_id);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "pulse_reader.h"
|
#include "pulse_reader.h"
|
||||||
|
|
||||||
|
|
||||||
#define GPIO_PIN_MAP(pin, prefix) \
|
#define GPIO_PIN_MAP(pin, prefix) \
|
||||||
(((pin) == (LL_GPIO_PIN_0)) ? prefix##0 : \
|
(((pin) == (LL_GPIO_PIN_0)) ? prefix##0 : \
|
||||||
((pin) == (LL_GPIO_PIN_1)) ? prefix##1 : \
|
((pin) == (LL_GPIO_PIN_1)) ? prefix##1 : \
|
||||||
@@ -26,10 +25,7 @@
|
|||||||
|
|
||||||
#define GET_DMAMUX_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_DMAMUX_REQ_GEN_EXTI_LINE)
|
#define GET_DMAMUX_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_DMAMUX_REQ_GEN_EXTI_LINE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size) {
|
PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size) {
|
||||||
|
|
||||||
PulseReader* signal = malloc(sizeof(PulseReader));
|
PulseReader* signal = malloc(sizeof(PulseReader));
|
||||||
signal->timer_buffer = malloc(size * sizeof(uint32_t));
|
signal->timer_buffer = malloc(size * sizeof(uint32_t));
|
||||||
signal->gpio_buffer = malloc(size * sizeof(uint32_t));
|
signal->gpio_buffer = malloc(size * sizeof(uint32_t));
|
||||||
@@ -43,23 +39,25 @@ PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size) {
|
|||||||
pulse_reader_set_bittime(signal, 1);
|
pulse_reader_set_bittime(signal, 1);
|
||||||
|
|
||||||
signal->dma_config_timer.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
signal->dma_config_timer.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||||
signal->dma_config_timer.PeriphOrM2MSrcAddress = (uint32_t) &(TIM2->CNT);
|
signal->dma_config_timer.PeriphOrM2MSrcAddress = (uint32_t) & (TIM2->CNT);
|
||||||
signal->dma_config_timer.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
signal->dma_config_timer.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||||
signal->dma_config_timer.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD;
|
signal->dma_config_timer.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD;
|
||||||
signal->dma_config_timer.MemoryOrM2MDstAddress = (uint32_t) signal->timer_buffer;
|
signal->dma_config_timer.MemoryOrM2MDstAddress = (uint32_t)signal->timer_buffer;
|
||||||
signal->dma_config_timer.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
signal->dma_config_timer.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||||
signal->dma_config_timer.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD;
|
signal->dma_config_timer.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD;
|
||||||
signal->dma_config_timer.Mode = LL_DMA_MODE_CIRCULAR;
|
signal->dma_config_timer.Mode = LL_DMA_MODE_CIRCULAR;
|
||||||
signal->dma_config_timer.PeriphRequest = LL_DMAMUX_REQ_GENERATOR0; /* executes LL_DMA_SetPeriphRequest */
|
signal->dma_config_timer.PeriphRequest =
|
||||||
|
LL_DMAMUX_REQ_GENERATOR0; /* executes LL_DMA_SetPeriphRequest */
|
||||||
signal->dma_config_timer.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
signal->dma_config_timer.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
||||||
|
|
||||||
signal->dma_config_gpio.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
signal->dma_config_gpio.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||||
signal->dma_config_gpio.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
signal->dma_config_gpio.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT;
|
||||||
signal->dma_config_gpio.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD;
|
signal->dma_config_gpio.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD;
|
||||||
signal->dma_config_gpio.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
signal->dma_config_gpio.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||||
signal->dma_config_gpio.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD;
|
signal->dma_config_gpio.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD;
|
||||||
signal->dma_config_gpio.Mode = LL_DMA_MODE_CIRCULAR;
|
signal->dma_config_gpio.Mode = LL_DMA_MODE_CIRCULAR;
|
||||||
signal->dma_config_gpio.PeriphRequest = LL_DMAMUX_REQ_GENERATOR0; /* executes LL_DMA_SetPeriphRequest */
|
signal->dma_config_gpio.PeriphRequest =
|
||||||
|
LL_DMAMUX_REQ_GENERATOR0; /* executes LL_DMA_SetPeriphRequest */
|
||||||
signal->dma_config_gpio.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
signal->dma_config_gpio.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
||||||
|
|
||||||
return signal;
|
return signal;
|
||||||
@@ -67,22 +65,22 @@ PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size) {
|
|||||||
|
|
||||||
void pulse_reader_set_timebase(PulseReader* signal, PulseReaderUnit unit) {
|
void pulse_reader_set_timebase(PulseReader* signal, PulseReaderUnit unit) {
|
||||||
switch(unit) {
|
switch(unit) {
|
||||||
case PulseReaderUnit64MHz:
|
case PulseReaderUnit64MHz:
|
||||||
signal->unit_multiplier = 1;
|
signal->unit_multiplier = 1;
|
||||||
signal->unit_divider = 1;
|
signal->unit_divider = 1;
|
||||||
break;
|
break;
|
||||||
case PulseReaderUnitPicosecond:
|
case PulseReaderUnitPicosecond:
|
||||||
signal->unit_multiplier = 15625;
|
signal->unit_multiplier = 15625;
|
||||||
signal->unit_divider = 1;
|
signal->unit_divider = 1;
|
||||||
break;
|
break;
|
||||||
case PulseReaderUnitNanosecond:
|
case PulseReaderUnitNanosecond:
|
||||||
signal->unit_multiplier = 15625;
|
signal->unit_multiplier = 15625;
|
||||||
signal->unit_divider = 1000;
|
signal->unit_divider = 1000;
|
||||||
break;
|
break;
|
||||||
case PulseReaderUnitMicrosecond:
|
case PulseReaderUnitMicrosecond:
|
||||||
signal->unit_multiplier = 15625;
|
signal->unit_multiplier = 15625;
|
||||||
signal->unit_divider = 1000000;
|
signal->unit_divider = 1000000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +102,7 @@ uint32_t pulse_reader_samples(PulseReader* signal) {
|
|||||||
|
|
||||||
void pulse_reader_stop(PulseReader* signal) {
|
void pulse_reader_stop(PulseReader* signal) {
|
||||||
LL_DMA_DisableChannel(DMA1, signal->dma_channel);
|
LL_DMA_DisableChannel(DMA1, signal->dma_channel);
|
||||||
LL_DMA_DisableChannel(DMA1, signal->dma_channel+1);
|
LL_DMA_DisableChannel(DMA1, signal->dma_channel + 1);
|
||||||
LL_DMAMUX_DisableRequestGen(NULL, LL_DMAMUX_REQ_GEN_0);
|
LL_DMAMUX_DisableRequestGen(NULL, LL_DMAMUX_REQ_GEN_0);
|
||||||
LL_TIM_DisableCounter(TIM2);
|
LL_TIM_DisableCounter(TIM2);
|
||||||
}
|
}
|
||||||
@@ -113,10 +111,10 @@ void pulse_reader_start(PulseReader* signal) {
|
|||||||
/* configure DMA to read from a timer peripheral */
|
/* configure DMA to read from a timer peripheral */
|
||||||
signal->dma_config_timer.NbData = signal->size;
|
signal->dma_config_timer.NbData = signal->size;
|
||||||
|
|
||||||
signal->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t) &(signal->gpio->port->IDR);
|
signal->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t) & (signal->gpio->port->IDR);
|
||||||
signal->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t) signal->gpio_buffer;
|
signal->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t)signal->gpio_buffer;
|
||||||
signal->dma_config_gpio.NbData = signal->size;
|
signal->dma_config_gpio.NbData = signal->size;
|
||||||
|
|
||||||
/* start counter */
|
/* start counter */
|
||||||
LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP);
|
LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP);
|
||||||
LL_TIM_SetClockDivision(TIM2, LL_TIM_CLOCKDIVISION_DIV1);
|
LL_TIM_SetClockDivision(TIM2, LL_TIM_CLOCKDIVISION_DIV1);
|
||||||
@@ -126,14 +124,16 @@ void pulse_reader_start(PulseReader* signal) {
|
|||||||
LL_TIM_EnableCounter(TIM2);
|
LL_TIM_EnableCounter(TIM2);
|
||||||
|
|
||||||
/* generator 0 gets fed by EXTI_LINEn */
|
/* generator 0 gets fed by EXTI_LINEn */
|
||||||
LL_DMAMUX_SetRequestSignalID(NULL, LL_DMAMUX_REQ_GEN_0, GET_DMAMUX_EXTI_LINE(signal->gpio->pin));
|
LL_DMAMUX_SetRequestSignalID(
|
||||||
|
NULL, LL_DMAMUX_REQ_GEN_0, GET_DMAMUX_EXTI_LINE(signal->gpio->pin));
|
||||||
/* trigger on rising edge of the interrupt */
|
/* trigger on rising edge of the interrupt */
|
||||||
LL_DMAMUX_SetRequestGenPolarity(NULL, LL_DMAMUX_REQ_GEN_0, LL_DMAMUX_REQ_GEN_POL_RISING);
|
LL_DMAMUX_SetRequestGenPolarity(NULL, LL_DMAMUX_REQ_GEN_0, LL_DMAMUX_REQ_GEN_POL_RISING);
|
||||||
/* now enable request generation again */
|
/* now enable request generation again */
|
||||||
LL_DMAMUX_EnableRequestGen(NULL, LL_DMAMUX_REQ_GEN_0);
|
LL_DMAMUX_EnableRequestGen(NULL, LL_DMAMUX_REQ_GEN_0);
|
||||||
|
|
||||||
/* we need the EXTI to be configured as interrupt generating line, but no ISR registered */
|
/* we need the EXTI to be configured as interrupt generating line, but no ISR registered */
|
||||||
furi_hal_gpio_init_ex(signal->gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedVeryHigh, GpioAltFnUnused);
|
furi_hal_gpio_init_ex(
|
||||||
|
signal->gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedVeryHigh, GpioAltFnUnused);
|
||||||
|
|
||||||
/* capture current timer */
|
/* capture current timer */
|
||||||
signal->pos = 0;
|
signal->pos = 0;
|
||||||
@@ -143,23 +143,22 @@ void pulse_reader_start(PulseReader* signal) {
|
|||||||
|
|
||||||
/* now set up DMA with these settings */
|
/* now set up DMA with these settings */
|
||||||
LL_DMA_Init(DMA1, signal->dma_channel, &signal->dma_config_timer);
|
LL_DMA_Init(DMA1, signal->dma_channel, &signal->dma_config_timer);
|
||||||
LL_DMA_Init(DMA1, signal->dma_channel+1, &signal->dma_config_gpio);
|
LL_DMA_Init(DMA1, signal->dma_channel + 1, &signal->dma_config_gpio);
|
||||||
LL_DMA_EnableChannel(DMA1, signal->dma_channel);
|
LL_DMA_EnableChannel(DMA1, signal->dma_channel);
|
||||||
LL_DMA_EnableChannel(DMA1, signal->dma_channel+1);
|
LL_DMA_EnableChannel(DMA1, signal->dma_channel + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us) {
|
uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us) {
|
||||||
|
|
||||||
uint32_t start_time = DWT->CYCCNT;
|
uint32_t start_time = DWT->CYCCNT;
|
||||||
uint32_t timeout_ticks = timeout_us * (F_TIM2/1000000);
|
uint32_t timeout_ticks = timeout_us * (F_TIM2 / 1000000);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* get the DMA's next write position by reading "remaining length" register */
|
/* get the DMA's next write position by reading "remaining length" register */
|
||||||
uint32_t dma_pos = signal->size - (uint32_t)LL_DMA_GetDataLength(DMA1, signal->dma_channel);
|
uint32_t dma_pos =
|
||||||
|
signal->size - (uint32_t)LL_DMA_GetDataLength(DMA1, signal->dma_channel);
|
||||||
|
|
||||||
/* the DMA has advanced in the ringbuffer */
|
/* the DMA has advanced in the ringbuffer */
|
||||||
if(dma_pos != signal->pos) {
|
if(dma_pos != signal->pos) {
|
||||||
|
|
||||||
uint32_t delta = signal->timer_buffer[signal->pos] - signal->timer_value;
|
uint32_t delta = signal->timer_buffer[signal->pos] - signal->timer_value;
|
||||||
uint32_t last_gpio_value = signal->gpio_value;
|
uint32_t last_gpio_value = signal->gpio_value;
|
||||||
|
|
||||||
@@ -174,12 +173,13 @@ uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us) {
|
|||||||
|
|
||||||
signal->pos++;
|
signal->pos++;
|
||||||
signal->pos %= signal->size;
|
signal->pos %= signal->size;
|
||||||
|
|
||||||
uint32_t delta_unit = 0;
|
uint32_t delta_unit = 0;
|
||||||
|
|
||||||
/* probably larger values, so choose a wider data type */
|
/* probably larger values, so choose a wider data type */
|
||||||
if(signal->unit_divider > 1) {
|
if(signal->unit_divider > 1) {
|
||||||
delta_unit = (uint32_t)((uint64_t)delta * (uint64_t)signal->unit_multiplier / signal->unit_divider);
|
delta_unit =
|
||||||
|
(uint32_t)((uint64_t)delta * (uint64_t)signal->unit_multiplier / signal->unit_divider);
|
||||||
} else {
|
} else {
|
||||||
delta_unit = delta * signal->unit_multiplier;
|
delta_unit = delta * signal->unit_multiplier;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PULSE_READER_NO_EDGE 0xFFFFFFFFUL
|
#define PULSE_READER_NO_EDGE 0xFFFFFFFFUL
|
||||||
#define PULSE_READER_LOST_EDGE 0xFFFFFFFEUL
|
#define PULSE_READER_LOST_EDGE 0xFFFFFFFEUL
|
||||||
#define F_TIM2 64000000UL
|
#define F_TIM2 64000000UL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unit of the edge durations to return
|
* unit of the edge durations to return
|
||||||
@@ -28,7 +28,6 @@ typedef enum {
|
|||||||
PulseReaderUnitMicrosecond,
|
PulseReaderUnitMicrosecond,
|
||||||
} PulseReaderUnit;
|
} PulseReaderUnit;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool start_level;
|
bool start_level;
|
||||||
uint32_t* timer_buffer;
|
uint32_t* timer_buffer;
|
||||||
@@ -47,7 +46,6 @@ typedef struct {
|
|||||||
LL_DMA_InitTypeDef dma_config_gpio;
|
LL_DMA_InitTypeDef dma_config_gpio;
|
||||||
} PulseReader;
|
} PulseReader;
|
||||||
|
|
||||||
|
|
||||||
/** Allocate a PulseReader object
|
/** Allocate a PulseReader object
|
||||||
*
|
*
|
||||||
* Allocates memory for a ringbuffer and initalizes the object
|
* Allocates memory for a ringbuffer and initalizes the object
|
||||||
@@ -57,7 +55,6 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size);
|
PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size);
|
||||||
|
|
||||||
|
|
||||||
/** Free a PulseReader object
|
/** Free a PulseReader object
|
||||||
*
|
*
|
||||||
* Frees all memory of the given object
|
* Frees all memory of the given object
|
||||||
@@ -66,7 +63,6 @@ PulseReader* pulse_reader_alloc(const GpioPin* gpio, uint32_t size);
|
|||||||
*/
|
*/
|
||||||
void pulse_reader_free(PulseReader* signal);
|
void pulse_reader_free(PulseReader* signal);
|
||||||
|
|
||||||
|
|
||||||
/** Start signal capturing
|
/** Start signal capturing
|
||||||
*
|
*
|
||||||
* Initializes DMA1, TIM2 and DMAMUX_REQ_GEN_0 to automatically capture timer values
|
* Initializes DMA1, TIM2 and DMAMUX_REQ_GEN_0 to automatically capture timer values
|
||||||
@@ -83,7 +79,6 @@ void pulse_reader_start(PulseReader* signal);
|
|||||||
*/
|
*/
|
||||||
void pulse_reader_stop(PulseReader* signal);
|
void pulse_reader_stop(PulseReader* signal);
|
||||||
|
|
||||||
|
|
||||||
/** Recevie a sample from ringbuffer
|
/** Recevie a sample from ringbuffer
|
||||||
*
|
*
|
||||||
* Waits for the specified time until a new edge gets detected.
|
* Waits for the specified time until a new edge gets detected.
|
||||||
@@ -98,7 +93,6 @@ void pulse_reader_stop(PulseReader* signal);
|
|||||||
*/
|
*/
|
||||||
uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us);
|
uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us);
|
||||||
|
|
||||||
|
|
||||||
/** Get available samples
|
/** Get available samples
|
||||||
*
|
*
|
||||||
* Get the number of available samples in the ringbuffer
|
* Get the number of available samples in the ringbuffer
|
||||||
@@ -109,7 +103,6 @@ uint32_t pulse_reader_receive(PulseReader* signal, int timeout_us);
|
|||||||
*/
|
*/
|
||||||
uint32_t pulse_reader_samples(PulseReader* signal);
|
uint32_t pulse_reader_samples(PulseReader* signal);
|
||||||
|
|
||||||
|
|
||||||
/** Set timebase
|
/** Set timebase
|
||||||
*
|
*
|
||||||
* Set the timebase to be used when returning pulse duration.
|
* Set the timebase to be used when returning pulse duration.
|
||||||
@@ -119,8 +112,6 @@ uint32_t pulse_reader_samples(PulseReader* signal);
|
|||||||
*/
|
*/
|
||||||
void pulse_reader_set_timebase(PulseReader* signal, PulseReaderUnit unit);
|
void pulse_reader_set_timebase(PulseReader* signal, PulseReaderUnit unit);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Set bit time
|
/** Set bit time
|
||||||
*
|
*
|
||||||
* Set the number of timebase units per bit.
|
* Set the number of timebase units per bit.
|
||||||
@@ -134,7 +125,6 @@ void pulse_reader_set_timebase(PulseReader* signal, PulseReaderUnit unit);
|
|||||||
*/
|
*/
|
||||||
void pulse_reader_set_bittime(PulseReader* signal, uint32_t bit_time);
|
void pulse_reader_set_bittime(PulseReader* signal, uint32_t bit_time);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user