From 6915ee19a4a9d97e2593d39baca328f3faf10031 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 27 Sep 2023 23:09:59 +0200 Subject: [PATCH] New DELETE_SLOT_TAG_NICK --- CHANGELOG.md | 1 + docs/protocol.md | 4 ++++ firmware/application/src/app_cmd.c | 20 ++++++++++++++++++++ firmware/application/src/data_cmd.h | 1 + software/script/chameleon_cli_unit.py | 16 ++++++++++++++++ software/script/chameleon_cmd.py | 14 ++++++++++++++ 6 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e85fc4bf..535f3ff4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Add PyInstaller support for CLI client (@augustozanellato) ## [v2.0.0][2023-09-26] + - Added `hw slot nick delete` and DELETE_SLOT_TAG_NICK (@doegox) - Changed APP_FW_VER now deduced from git tag vx.y.z (@doegox) - Changed initial button wakeup from 4 to 8 seconds (@aramova) - Added MIFARE Ultralight reading features (@FlUxIuS & @doegox) diff --git a/docs/protocol.md b/docs/protocol.md index fffc940e..8d333d9c 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -146,6 +146,10 @@ Notes: the returned string is the output of `git describe --abbrev=7 --dirty --a * Command: no data * Response: no data. Status is `STATUS_DEVICE_SUCCESS` or `STATUS_FLASH_WRITE_FAIL`. The device will reboot shortly after this command. * CLI: cf `hw factory_reset` +### 1021: DELETE_SLOT_TAG_NICK +* Command: 2 bytes. `slot_number|sense_type` with `slot_number` between 0 and 7 and `sense_type` according to `tag_sense_type_t` enum. +* Response: no data +* CLI: cf `hw slot nick delete` ### 1023: GET_ENABLED_SLOTS * Command: no data * Response: 16 bytes, 8*2 bool = `0x00` or `0x01`, 2 bytes for each slot from 0 to 7, as `enabled_hf|enabled_lf` diff --git a/firmware/application/src/app_cmd.c b/firmware/application/src/app_cmd.c index 5332c09c..23bd09db 100644 --- a/firmware/application/src/app_cmd.c +++ b/firmware/application/src/app_cmd.c @@ -792,6 +792,25 @@ static data_frame_tx_t *cmd_processor_get_slot_tag_nick(uint16_t cmd, uint16_t s return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, buffer[0], &buffer[1]); } +static data_frame_tx_t *cmd_processor_delete_slot_tag_nick(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { + if (length != 2) { + return data_frame_make(cmd, STATUS_PAR_ERR, 0, NULL); + } + uint8_t slot = data[0]; + uint8_t sense_type = data[1]; + fds_slot_record_map_t map_info; + + if (slot >= TAG_MAX_SLOT_NUM || (sense_type != TAG_SENSE_HF && sense_type != TAG_SENSE_LF)) { + return data_frame_make(cmd, STATUS_PAR_ERR, 0, NULL); + } + get_fds_map_by_slot_sense_type_for_nick(slot, sense_type, &map_info); + bool ret = fds_delete_sync(map_info.id, map_info.key); + if (!ret) { + return data_frame_make(cmd, STATUS_FLASH_WRITE_FAIL, 0, NULL); + } + return data_frame_make(cmd, STATUS_DEVICE_SUCCESS, 0, NULL); +} + static data_frame_tx_t *cmd_processor_mf1_get_emulator_config(uint16_t cmd, uint16_t status, uint16_t length, uint8_t *data) { uint8_t mf1_info[5] = {}; mf1_info[0] = nfc_tag_mf1_is_detection_enable(); @@ -965,6 +984,7 @@ static cmd_data_map_t m_data_cmd_map[] = { { DATA_CMD_GET_ACTIVE_SLOT, NULL, cmd_processor_get_active_slot, NULL }, { DATA_CMD_GET_SLOT_INFO, NULL, cmd_processor_get_slot_info, NULL }, { DATA_CMD_WIPE_FDS, NULL, cmd_processor_wipe_fds, NULL }, + { DATA_CMD_DELETE_SLOT_TAG_NICK, NULL, cmd_processor_delete_slot_tag_nick, 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 }, { DATA_CMD_GET_BATTERY_INFO, NULL, cmd_processor_get_battery_info, NULL }, diff --git a/firmware/application/src/data_cmd.h b/firmware/application/src/data_cmd.h index 267e09c4..b0ad7511 100644 --- a/firmware/application/src/data_cmd.h +++ b/firmware/application/src/data_cmd.h @@ -28,6 +28,7 @@ #define DATA_CMD_GET_ACTIVE_SLOT (1018) #define DATA_CMD_GET_SLOT_INFO (1019) #define DATA_CMD_WIPE_FDS (1020) +#define DATA_CMD_DELETE_SLOT_TAG_NICK (1021) #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 5e2b0d37..203850a6 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -1392,6 +1392,22 @@ def on_exec(self, args: argparse.Namespace): print(f' - Get tag nick name for slot {slot_num}: {res.decode(encoding="utf8")}') +@hw_slot_nick.command('delete', 'Delete tag nick name for slot') +class HWSlotNickGet(SlotIndexRequireUnit, SenseTypeRequireUnit): + def args_parser(self) -> ArgumentParserNoExit or None: + parser = ArgumentParserNoExit() + self.add_slot_args(parser) + self.add_sense_type_args(parser) + return parser + + # hw slot nick delete -s 1 -st 1 + def on_exec(self, args: argparse.Namespace): + slot_num = args.slot + sense_type = args.sense_type + res = self.cmd.delete_slot_tag_nick(slot_num, sense_type) + print(f' - Delete tag nick name for slot {slot_num}: {res.decode(encoding="utf8")}') + + @hw_slot.command('update', 'Update config & data to device flash') class HWSlotUpdate(DeviceRequiredUnit): def args_parser(self) -> ArgumentParserNoExit or None: diff --git a/software/script/chameleon_cmd.py b/software/script/chameleon_cmd.py index 0e79eceb..2e5812e4 100644 --- a/software/script/chameleon_cmd.py +++ b/software/script/chameleon_cmd.py @@ -37,6 +37,8 @@ DATA_CMD_WIPE_FDS = 1020 +DATA_CMD_DELETE_SLOT_TAG_NICK = 1021 + DATA_CMD_GET_ENABLED_SLOTS = 1023 DATA_CMD_DELETE_SLOT_SENSE_TYPE = 1024 @@ -912,6 +914,18 @@ def get_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType): data = struct.pack('!BB', SlotNumber.to_fw(slot), sense_type) return self.device.send_cmd_sync(DATA_CMD_GET_SLOT_TAG_NICK, data) + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) + def delete_slot_tag_nick(self, slot: SlotNumber, sense_type: TagSenseType): + """ + Delete the nick name of the slot + :param slot: Card slot number + :param sense_type: field type + :return: + """ + # SlotNumber() will raise error for us if slot not in slot range + data = struct.pack('!BB', SlotNumber.to_fw(slot), sense_type) + return self.device.send_cmd_sync(DATA_CMD_DELETE_SLOT_TAG_NICK, data) + @expect_response(chameleon_status.Device.STATUS_DEVICE_SUCCESS) def mf1_get_emulator_config(self): """