Merge branch 'main' into implement-get-slot-data

This commit is contained in:
Dominik Szymański
2023-08-18 16:50:38 +02:00
5 changed files with 74 additions and 3 deletions
+19
View File
@@ -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);
@@ -596,6 +613,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 },
+2
View File
@@ -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)
//
// ******************************************************************
+2 -2
View File
@@ -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"),
@@ -178,9 +179,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
+12
View File
@@ -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):
+39 -1
View File
@@ -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
@@ -86,6 +90,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:
"""
@@ -280,6 +304,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):
"""
设置当前激活使用的卡槽