From d33ae755c16793cec3b7b07771f0f53a4fc2c799 Mon Sep 17 00:00:00 2001 From: Augusto Zanellato Date: Mon, 21 Aug 2023 16:38:11 +0200 Subject: [PATCH] Add ability to delete sense type per slot --- firmware/application/src/app_cmd.c | 18 ++++++++++++++++++ firmware/application/src/data_cmd.h | 1 + software/script/chameleon_cli_unit.py | 17 +++++++++++++++++ software/script/chameleon_cmd.py | 16 ++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index c2da08d..3bb43eb 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -304,6 +304,23 @@ data_frame_tx_t* cmd_processor_set_slot_tag_type(uint16_t cmd, uint16_t status, return data_frame_make(cmd, status, 0, NULL); } +data_frame_tx_t* cmd_processor_delete_slot_sense_type(uint16_t cmd, uint16_t status, uint16_t length, uint8_t* data) { + status = STATUS_PAR_ERR; + if (length == 2 && data[0] < TAG_MAX_SLOT_NUM && (data[1] == TAG_SENSE_HF || data[1] == TAG_SENSE_LF)) { + uint8_t slot_num = data[0]; + uint8_t sense_type = data[1]; + uint8_t other_st_index = sense_type == TAG_SENSE_LF ? 0 : 1; + + tag_specific_type_t tag_types[2]; + tag_emulation_get_specific_type_by_slot(slot_num, tag_types); + if (tag_types[other_st_index] != TAG_TYPE_UNKNOWN) { + tag_emulation_delete_data(slot_num, sense_type); + status = STATUS_DEVICE_SUCCESS; + } + } + return data_frame_make(cmd, status, 0, NULL); +} + data_frame_tx_t* cmd_processor_set_slot_data_default(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { if (length == 2 && data[0] < TAG_MAX_SLOT_NUM && data[1] != TAG_TYPE_UNKNOWN) { uint8_t num_slot = data[0]; @@ -768,6 +785,7 @@ static cmd_data_map_t m_data_cmd_map[] = { { DATA_CMD_GET_SLOT_INFO, NULL, cmd_processor_get_slot_info, NULL }, { DATA_CMD_WIPE_FDS, NULL, cmd_processor_wipe_fds, NULL }, { DATA_CMD_GET_ENABLED_SLOTS, NULL, cmd_processor_get_enabled_slots, NULL }, + { DATA_CMD_DELETE_SLOT_SENSE_TYPE, NULL, cmd_processor_delete_slot_sense_type, NULL }, diff --git a/firmware/application/src/data_cmd.h b/firmware/application/src/data_cmd.h index a1bf6e7..72ed13f 100644 --- a/firmware/application/src/data_cmd.h +++ b/firmware/application/src/data_cmd.h @@ -29,6 +29,7 @@ #define DATA_CMD_GET_SLOT_INFO (1019) #define DATA_CMD_WIPE_FDS (1020) #define DATA_CMD_GET_ENABLED_SLOTS (1023) +#define DATA_CMD_DELETE_SLOT_SENSE_TYPE (1024) // // ****************************************************************** diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index 20cb3f2..d4f7808 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -1012,6 +1012,23 @@ class HWSlotTagType(TagTypeRequiredUnit, SlotIndexRequireUnit): print(f' - Set slot tag type success.') +@hw_slot.command('delete', 'Delete sense type data for slot') +class HWDeleteSlotSense(SlotIndexRequireUnit, SenseTypeRequireUnit): + def args_parser(self) -> ArgumentParserNoExit: + parser = ArgumentParserNoExit() + parser.description = "Delete sense type data for a specific slot. " \ + "The slot needs to have the other sense type correctly configured, " \ + "otherwise an error will be thrown." + self.add_slot_args(parser) + self.add_sense_type_args(parser) + return parser + + def on_exec(self, args: argparse.Namespace): + slot = args.slot + sense_type = args.sense_type + self.cmd.delete_slot_sense_type(slot, sense_type) + + @hw_slot.command('init', 'Set emulation tag data to default') class HWSlotDataDefault(TagTypeRequiredUnit, SlotIndexRequireUnit): diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index ecd2819..1f1cf3f 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -35,6 +35,7 @@ DATA_CMD_GET_SLOT_INFO = 1019 DATA_CMD_WIPE_FDS = 1020 DATA_CMD_GET_ENABLED_SLOTS = 1023 +DATA_CMD_DELETE_SLOT_SENSE_TYPE = 1024 DATA_CMD_SCAN_14A_TAG = 2000 DATA_CMD_MF1_SUPPORT_DETECT = 2001 @@ -432,6 +433,21 @@ class ChameleonCMD: data.append(tag_type) return self.device.send_cmd_sync(DATA_CMD_SET_SLOT_TAG_TYPE, 0x00, data) + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) + def delete_slot_sense_type(self, slot_index: SlotNumber, sense_type: TagSenseType): + """ + Delete a sense type for a specific slot. + Another sense type must be enabled for the same slot, + otherwise an error will be thrown. + :param slot_index: Slot index + :param sense_type: Sense type to disable + :return: + """ + return self.device.send_cmd_sync(DATA_CMD_DELETE_SLOT_SENSE_TYPE, 0x00, bytearray([ + SlotNumber.to_fw(slot_index), + sense_type, + ])) + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) def set_slot_data_default(self, slot_index: SlotNumber, tag_type: TagSpecificType): """