Skip to content

Commit

Permalink
renaming of slot into cloned when having cloned an ID/UID with a butt…
Browse files Browse the repository at this point in the history
…on, cf issue #166. Removed the goto
  • Loading branch information
doegox committed Oct 11, 2023
1 parent 4fe9e1e commit ea6576c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Added renaming of slot into "cloned" when having cloned an ID/UID with a button (@doegox)
- Fixed spurious LED in battery level, assigned battery level to long press B (@doegox)
- Changed `hw slot list` to display LF ID & HF anticol data, and names in the --short version too (@doegox)
- Added colors to CLI help (@doegox)
Expand Down
82 changes: 51 additions & 31 deletions firmware/application/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NRF_LOG_MODULE_REGISTER();
#include "tag_emulation.h"
#include "usb_main.h"
#include "rgb_marquee.h"

#include "tag_persistence.h"
#include "settings.h"

// Defining soft timers
Expand Down Expand Up @@ -596,14 +596,16 @@ static void offline_status_ok(void) {

// fast detect a 14a tag uid to sim
static void btn_fn_copy_ic_uid(void) {
bool lf_copy_succeeded = false;
bool hf_copy_succeeded = false;
uint8_t status;
uint8_t id_buffer[5] = { 0x00 };
// get 14a tag res buffer;
uint8_t slot_now = tag_emulation_get_slot();
tag_slot_specific_type_t tag_types;
tag_emulation_get_specific_types_by_slot(slot_now, &tag_types);

nfc_tag_14a_coll_res_entity_t *antres;
nfc_tag_14a_coll_res_entity_t *antres = NULL;

bool is_reader_mode_now = get_device_mode() == DEVICE_MODE_READER;
// first, we need switch to reader mode.
Expand All @@ -623,6 +625,7 @@ static void btn_fn_copy_ic_uid(void) {
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")
lf_copy_succeeded = true;
offline_status_ok();
} else {
NRF_LOG_INFO("No LF tag found");
Expand Down Expand Up @@ -658,42 +661,59 @@ static void btn_fn_copy_ic_uid(void) {

case TAG_TYPE_UNDEFINED:
// empty HF slot, nothing to do
goto exit;
break;

default:
NRF_LOG_ERROR("Unsupported HF tag type")
offline_status_error();
goto exit;
break;
}

if (!is_reader_mode_now) {
// finish HF reader initialization
pcd_14a_reader_reset();
pcd_14a_reader_antenna_on();
bsp_delay_ms(8);
if (antres != NULL) {
if (!is_reader_mode_now) {
// finish HF reader initialization
pcd_14a_reader_reset();
pcd_14a_reader_antenna_on();
bsp_delay_ms(8);
}
// select a tag
picc_14a_tag_t tag;

status = pcd_14a_reader_scan_auto(&tag);
if (status == HF_TAG_OK) {
// copy uid
antres->size = tag.uid_len;
memcpy(antres->uid, tag.uid, tag.uid_len);
// copy atqa
memcpy(antres->atqa, tag.atqa, 2);
// copy sak
antres->sak[0] = tag.sak;
// copy ats
antres->ats.length = tag.ats_len;
memcpy(antres->ats.data, tag.ats, tag.ats_len);
NRF_LOG_INFO("Offline HF uid copied")
hf_copy_succeeded = true;
offline_status_ok();
} else {
NRF_LOG_INFO("No HF tag found");
offline_status_error();
}
}
// select a tag
picc_14a_tag_t tag;

status = pcd_14a_reader_scan_auto(&tag);
if (status == HF_TAG_OK) {
// copy uid
antres->size = tag.uid_len;
memcpy(antres->uid, tag.uid, tag.uid_len);
// copy atqa
memcpy(antres->atqa, tag.atqa, 2);
// copy sak
antres->sak[0] = tag.sak;
// copy ats
antres->ats.length = tag.ats_len;
memcpy(antres->ats.data, tag.ats, tag.ats_len);
NRF_LOG_INFO("Offline HF uid copied")
offline_status_ok();
} else {
NRF_LOG_INFO("No HF tag found");
offline_status_error();
if (lf_copy_succeeded || hf_copy_succeeded) {
fds_slot_record_map_t map_info;
char *nick = "cloned";
uint8_t buffer[((((1+strlen(nick))-1)/4)+1)*4];
buffer[0] = strlen(nick);
memcpy(buffer + 1, nick, buffer[0]);
// ASSERT(sizeof(buffer) % 4 == 0);
if (lf_copy_succeeded) {
get_fds_map_by_slot_sense_type_for_nick(slot_now, TAG_SENSE_LF, &map_info);
fds_write_sync(map_info.id, map_info.key, sizeof(buffer) / 4, buffer);
}
if (hf_copy_succeeded) {
get_fds_map_by_slot_sense_type_for_nick(slot_now, TAG_SENSE_HF, &map_info);
fds_write_sync(map_info.id, map_info.key, sizeof(buffer) / 4, buffer);
}
}
exit:
// keep reader mode or exit reader mode.
if (!is_reader_mode_now) {
tag_mode_enter();
Expand Down

0 comments on commit ea6576c

Please sign in to comment.