mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
Rewrote offline uid copy to avoid 2 mode swaps
We also skip HF if we managed to clone a LF tag.
This commit is contained in:
@@ -507,41 +507,46 @@ static void btn_fn_copy_ic_uid(void) {
|
||||
uint8_t slot_now = tag_emulation_get_slot();
|
||||
tag_specific_type_t tag_type[2];
|
||||
tag_emulation_get_specific_type_by_slot(slot_now, tag_type);
|
||||
tag_data_buffer_t* buffer = get_buffer_by_tag_type(tag_type[0]);
|
||||
|
||||
nfc_tag_14a_coll_res_entity_t* antres;
|
||||
|
||||
if(tag_type[1] == TAG_TYPE_EM410X) {
|
||||
uint8_t status;
|
||||
|
||||
bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER;
|
||||
// first, we need switch to reader mode.
|
||||
if (!is_reader_mode_now) {
|
||||
// enter reader mode
|
||||
reader_mode_enter();
|
||||
bsp_delay_ms(8);
|
||||
NRF_LOG_INFO("Start reader mode to offline copy.")
|
||||
}
|
||||
|
||||
uint8_t id_buffer[5] = { 0x00 };
|
||||
status = PcdScanEM410X(id_buffer);
|
||||
|
||||
if(status == LF_TAG_OK) {
|
||||
tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X);
|
||||
memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE);
|
||||
tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false);
|
||||
|
||||
// keep reader mode or exit reader mode.
|
||||
offline_status_ok();
|
||||
} else {
|
||||
offline_status_error();
|
||||
}
|
||||
|
||||
if (!is_reader_mode_now) {
|
||||
tag_mode_enter();
|
||||
}
|
||||
bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER;
|
||||
// first, we need switch to reader mode.
|
||||
if (!is_reader_mode_now) {
|
||||
// enter reader mode
|
||||
reader_mode_enter();
|
||||
bsp_delay_ms(8);
|
||||
NRF_LOG_INFO("Start reader mode to offline copy.")
|
||||
}
|
||||
|
||||
switch(tag_type[1]) {
|
||||
case TAG_TYPE_EM410X:
|
||||
uint8_t status;
|
||||
uint8_t id_buffer[5] = { 0x00 };
|
||||
status = PcdScanEM410X(id_buffer);
|
||||
|
||||
if(status == LF_TAG_OK) {
|
||||
tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X);
|
||||
memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE);
|
||||
tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false);
|
||||
NRF_LOG_INFO("Offline LF uid copied")
|
||||
offline_status_ok();
|
||||
// no need to check for HF tag if we already cloned a LF tag
|
||||
goto exit;
|
||||
} else {
|
||||
NRF_LOG_INFO("No LF tag found");
|
||||
offline_status_error();
|
||||
}
|
||||
break;
|
||||
case TAG_TYPE_UNKNOWN:
|
||||
// empty LF slot, nothing to do, move on to HF
|
||||
break;
|
||||
default:
|
||||
NRF_LOG_ERROR("Unsupported LF tag type")
|
||||
offline_status_error();
|
||||
}
|
||||
|
||||
tag_data_buffer_t* buffer = get_buffer_by_tag_type(tag_type[0]);
|
||||
switch(tag_type[0]) {
|
||||
case TAG_TYPE_MIFARE_Mini:
|
||||
case TAG_TYPE_MIFARE_1024:
|
||||
@@ -560,24 +565,22 @@ static void btn_fn_copy_ic_uid(void) {
|
||||
break;
|
||||
}
|
||||
|
||||
case TAG_TYPE_UNKNOWN:
|
||||
// empty HF slot, nothing to do
|
||||
goto exit;
|
||||
|
||||
default:
|
||||
NRF_LOG_ERROR("Unsupported tag type")
|
||||
NRF_LOG_ERROR("Unsupported HF tag type")
|
||||
offline_status_error();
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER;
|
||||
// first, we need switch to reader mode.
|
||||
if (!is_reader_mode_now) {
|
||||
// enter reader mode
|
||||
reader_mode_enter();
|
||||
bsp_delay_ms(8);
|
||||
// finish HF reader initialization
|
||||
pcd_14a_reader_reset();
|
||||
pcd_14a_reader_antenna_on();
|
||||
bsp_delay_ms(8);
|
||||
NRF_LOG_INFO("Start reader mode to offline copy.")
|
||||
}
|
||||
|
||||
// select a tag
|
||||
picc_14a_tag_t tag;
|
||||
uint8_t status;
|
||||
@@ -590,13 +593,13 @@ static void btn_fn_copy_ic_uid(void) {
|
||||
memcpy(antres->atqa, tag.atqa, 2);
|
||||
// copy sak
|
||||
antres->sak[0] = tag.sak;
|
||||
NRF_LOG_INFO("Offline uid copied")
|
||||
NRF_LOG_INFO("Offline HF uid copied")
|
||||
offline_status_ok();
|
||||
} else {
|
||||
NRF_LOG_INFO("No tag found: %d", status);
|
||||
NRF_LOG_INFO("No HF tag found");
|
||||
offline_status_error();
|
||||
}
|
||||
|
||||
exit:
|
||||
// keep reader mode or exit reader mode.
|
||||
if (!is_reader_mode_now) {
|
||||
tag_mode_enter();
|
||||
|
||||
Reference in New Issue
Block a user