From 913c1540e32250f6505dbe6f98c95b20797800eb Mon Sep 17 00:00:00 2001 From: Foxushka <135865149+Foxushka@users.noreply.github.com> Date: Thu, 17 Aug 2023 21:48:49 +0300 Subject: [PATCH] Implement "hw slot info" to show which tag type loaded into all slots As suggested by @augustozanellato Fix input text disapperance in some cases Show selected slot Space --- firmware/application/src/app_cmd.c | 19 +++++++++++++ firmware/application/src/data_cmd.h | 2 ++ software/script/chameleon_cli_main.py | 4 +-- software/script/chameleon_cli_unit.py | 12 ++++++++ software/script/chameleon_cmd.py | 40 ++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index 1ab2e93..99c7d01 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -340,6 +340,23 @@ data_frame_tx_t* cmd_processor_slot_data_config_save(uint16_t cmd, uint16_t stat return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, 0, NULL); } +data_frame_tx_t* cmd_processor_get_activated_slot(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { + uint8_t slot = tag_emulation_get_slot(); + return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, 1, &slot); +} + +data_frame_tx_t* cmd_processor_get_slot_info(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { + uint8_t slot_info[16] = {}; + tag_specific_type_t tag_type[2]; + for (uint8_t slot = 0; slot < 8; slot++) { + tag_emulation_get_specific_type_by_slot(slot, tag_type); + slot_info[slot * 2] = tag_type[0]; + slot_info[slot * 2 + 1] = tag_type[1]; + } + + return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, 16, slot_info); +} + data_frame_tx_t* cmd_processor_set_em410x_emu_id(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { if (length == LF_EM410X_TAG_ID_SIZE) { tag_data_buffer_t* buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X); @@ -588,6 +605,8 @@ static cmd_data_map_t m_data_cmd_map[] = { { DATA_CMD_SET_SLOT_DATA_DEFAULT, NULL, cmd_processor_set_slot_data_default, NULL }, { DATA_CMD_SET_SLOT_ENABLE, NULL, cmd_processor_set_slot_enable, NULL }, { DATA_CMD_SLOT_DATA_CONFIG_SAVE, NULL, cmd_processor_slot_data_config_save, NULL }, + { DATA_CMD_GET_ACTIVE_SLOT, NULL, cmd_processor_get_activated_slot, NULL }, + { DATA_CMD_GET_SLOT_INFO, NULL, cmd_processor_get_slot_info, NULL }, { DATA_CMD_SET_EM410X_EMU_ID, NULL, cmd_processor_set_em410x_emu_id, NULL }, diff --git a/firmware/application/src/data_cmd.h b/firmware/application/src/data_cmd.h index e906e6e..32803cf 100644 --- a/firmware/application/src/data_cmd.h +++ b/firmware/application/src/data_cmd.h @@ -25,6 +25,8 @@ #define DATA_CMD_SET_ANIMATION_MODE (1015) #define DATA_CMD_GET_ANIMATION_MODE (1016) #define DATA_CMD_GET_GIT_VERSION (1017) +#define DATA_CMD_GET_ACTIVE_SLOT (1018) +#define DATA_CMD_GET_SLOT_INFO (1019) // // ****************************************************************** diff --git a/software/script/chameleon_cli_main.py b/software/script/chameleon_cli_main.py index cfb39b1..5241e90 100755 --- a/software/script/chameleon_cli_main.py +++ b/software/script/chameleon_cli_main.py @@ -73,6 +73,7 @@ class ChameleonCLI: 'help': "Device mode get/set" }, 'slot': { + 'info': new_uint(chameleon_cli_unit.HWSlotInfo, "Get information about slots"), 'change': new_uint(chameleon_cli_unit.HWSlotSet, "Set emulation tag slot activated."), 'type': new_uint(chameleon_cli_unit.HWSlotTagType, "Set emulation tag type"), 'init': new_uint(chameleon_cli_unit.HWSlotDataDefault, "Set emulation tag data to default"), @@ -174,9 +175,8 @@ class ChameleonCLI: while True: # wait user input status = f"{colorama.Fore.GREEN}USB" if self.device_com.isOpen() else f"{colorama.Fore.RED}Offline" - print(f"[{status}{colorama.Style.RESET_ALL}] chameleon --> ", end="") try: - cmd_str = input().strip() + cmd_str = input(f"[{status}{colorama.Style.RESET_ALL}] chameleon --> ").strip() except EOFError: print("") closing = True diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index cfad334..15f056d 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -818,6 +818,18 @@ class SenseTypeRequireUint(DeviceRequiredUnit): help="Sense type", metavar="number", choices=slot_choices) return parser +class HWSlotInfo(DeviceRequiredUnit): + def args_parser(self) -> ArgumentParserNoExit or None: + return + + # hw slot info + def on_exec(self, args: argparse.Namespace): + data = self.cmd_positive.get_slot_info().data + selected = self.cmd_positive.get_active_slot().data[0] + for slot in range(8): + print(f' - Slot {slot + 1} data{" (active)" if slot == selected else ""}:') + print(f' HF: {chameleon_cmd.TagSpecificType(data[slot * 2])}') + print(f' LF: {chameleon_cmd.TagSpecificType(data[slot * 2 + 1])}') class HWSlotSet(SlotIndexRequireUint): diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index d046bad..391f605 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -19,13 +19,17 @@ DATA_CMD_SLOT_DATA_CONFIG_SAVE = 1009 DATA_CMD_ENTER_BOOTLOADER = 1010 DATA_CMD_GET_DEVICE_CHIP_ID = 1011 DATA_CMD_GET_DEVICE_ADDRESS = 1012 -DATA_CMD_GET_GIT_VERSION = 1017 DATA_CMD_SAVE_SETTINGS = 1013 DATA_CMD_RESET_SETTINGS = 1014 DATA_CMD_SET_ANIMATION_MODE = 1015 DATA_CMD_GET_ANIMATION_MODE = 1016 +DATA_CMD_GET_GIT_VERSION = 1017 + +DATA_CMD_GET_ACTIVE_SLOT = 1018 +DATA_CMD_GET_SLOT_INFO = 1019 + DATA_CMD_SCAN_14A_TAG = 2000 DATA_CMD_MF1_SUPPORT_DETECT = 2001 DATA_CMD_MF1_NT_LEVEL_DETECT = 2002 @@ -82,6 +86,26 @@ class TagSpecificType(enum.IntEnum): enum_list.remove(TagSpecificType.TAG_TYPE_UNKNOWN) return enum_list + def __str__(self): + if self.value == TagSpecificType.TAG_TYPE_EM410X: + return "EM410X" + elif self.value == TagSpecificType.TAG_TYPE_MIFARE_Mini: + return "Mifare Mini" + elif self.value == TagSpecificType.TAG_TYPE_MIFARE_1024: + return "Mifare Classic 1k" + elif self.value == TagSpecificType.TAG_TYPE_MIFARE_2048: + return "Mifare Classic 2k" + elif self.value == TagSpecificType.TAG_TYPE_MIFARE_4096: + return "Mifare Classic 4k" + elif self.value == TagSpecificType.TAG_TYPE_NTAG_213: + return "NTAG 213" + elif self.value == TagSpecificType.TAG_TYPE_NTAG_215: + return "NTAG 215" + elif self.value == TagSpecificType.TAG_TYPE_NTAG_216: + return "NTAG 216" + return "Unknown" + + class BaseChameleonCMD: """ @@ -276,6 +300,20 @@ class BaseChameleonCMD: data.extend(key) return self.device.send_cmd_sync(DATA_CMD_WRITE_EM410X_TO_T5577, 0x00, data) + def get_slot_info(self): + """ + Get slots info + :return: + """ + return self.device.send_cmd_sync(DATA_CMD_GET_SLOT_INFO, 0x00, None) + + def get_active_slot(self): + """ + Get selected slot + :return: + """ + return self.device.send_cmd_sync(DATA_CMD_GET_ACTIVE_SLOT, 0x00, None) + def set_slot_activated(self, slot_index): """ 设置当前激活使用的卡槽