Commit Graph

83 Commits

Author SHA1 Message Date
Philippe Teuwen 75e368da62 cli: hf mf econfig, hf mfu econfig (wip), fix dumphelp 2023-10-09 21:23:17 +02:00
Philippe Teuwen 2f4d84ed2c cli: clean enums 2023-10-08 21:17:57 +02:00
Philippe Teuwen deb6684c0d cli: enum for key type A/B, prepare hf mf auth args 2023-10-08 21:12:52 +02:00
Philippe Teuwen dcebc89654 cli: Command enum 2023-10-08 16:48:29 +02:00
Philippe Teuwen 1da470b8fe cli: hw settings btnpress 2023-10-08 14:20:09 +02:00
Philippe Teuwen 45deb30d4a cli: hw settings btnpress WIP 2023-10-08 13:55:18 +02:00
Philippe Teuwen a47e9b8b03 cli: remove unused TagSenseType list 2023-10-08 12:46:24 +02:00
Philippe Teuwen 18a1770c80 cli: hw settings animation/bleclearbonds, hw factory_reset and hw settings bleclearbonds with --force 2023-10-08 12:02:28 +02:00
Philippe Teuwen 3aa73a2def cli: metavar, simplify enums, replace tag types int by keywords 2023-10-07 23:54:13 +02:00
Philippe Teuwen 702dba0d93 Added button action to show battery level 2023-10-04 19:36:33 +02:00
Philippe Teuwen 0d2c3fae89 hw settings btnpress set: tolerate A/B/a/b for button 2023-10-04 18:53:55 +02:00
Philippe Teuwen 6915ee19a4 New DELETE_SLOT_TAG_NICK 2023-09-27 23:09:59 +02:00
Philippe Teuwen 372cfead0c style 2023-09-25 00:51:43 +02:00
Philippe Teuwen 313d772a99 hf14a_raw: use @expect_response and fix tests 2023-09-24 22:30:50 +02:00
Philippe Teuwen 1dc8891e1b Fix shadow mode not being preserved. Breaking change:
nfc_tag_mf1_write_mode_t has one new mode SHADOW_REQ.
Client can set SHADOW or SHADOW_REQ, internally it will be transformed to SHADOW_REQ.
When it's time to save data, if SHADOW_REQ, the fw will change it to SHADOW and still allow to save the data before acting as shadow.
Breaking: when client reads back MF1 write mode just after settings SHADOW and before saving config, it will receive SHADOW_REQ and must be ready to handle this new enum value.
2023-09-24 19:01:20 +02:00
Philippe Teuwen 941d42561a MF1_DETECT_SUPPORT: remove redundant data
cf https://github.com/RfidResearchGroup/ChameleonUltra/pull/147#issuecomment-1732338315
2023-09-24 01:49:26 +02:00
Philippe Teuwen f7db6d0fb3 hw 14a raw: closer to pm3 syntax, removed bit_frame,...
Now data length is always in bits
Option -o => -a and only needed to turn field on without select or data
Reorganize pcd_14a_reader_raw_cmd
Some more checks
2023-09-24 01:02:30 +02:00
Philippe Teuwen 7da58bbce8 new tag_specific_type_t enum, new slotConfig struct. FW will take care of existing slots. Disruptive changes: see below
Disruptive changes:
- tag types are 2-byte long with new values
- GET_SLOT_INFO returns 32 bytes as tag types are now 2-byte long
- "enable" is not common to one slot anymore but bound to the HF or LF part
- GET_ENABLED_SLOTS returns 16 bytes as we get "enabled_hf" and "enabled_lf" for each slot
- SET_SLOT_ENABLE needs 3 bytes slot_number|sense_type|enable as we need to specify to enable HF or LF
- slotConfig changed a lot but this is internal to the fw and its flash and a function does the format conversion on first boot after flash
  so slot data is preserved on fw upgrade, but if one downgrades to a previous version, data will be erased.
2023-09-23 21:34:15 +02:00
dxl 879b8e3459 Implemented hf 14a raw 2023-09-21 18:30:05 +08:00
Philippe Teuwen 14bffafb2a style 2023-09-20 01:26:47 +02:00
Philippe Teuwen 5a9d49ddb4 Remove unused MF1_DETECT_DARKSIDE, reallocate 2003 to MF1_STATIC_NESTED_ACQUIRE
MF1_DETECT_DARKSIDE was actually runnign the full attack, as there is no quick way to detect Darkside
So if you want to check for Darkside, just run directly MF1_DARKSIDE_ACQUIRE.
2023-09-19 16:03:20 +02:00
dxl 32b3e19279 Added support for StaticNested(FastDecrypt). 2023-09-19 18:24:30 +08:00
Philippe Teuwen 782905f202 fix Darkside 2023-09-18 22:44:15 +02:00
Philippe Teuwen 8499535aad Clarify protocol. Disruptive changes: see below
This huge commit tries to enhance several things related to the fw/cli protocol.
Generally, the idea is to be verbose, explicit and reuse conventions, in order to enhance code maintainability and understandability for the other contributors.

docs/protocol.md got heavily updated

Many commands have been renamed for consistency. you are invited to adapt your client for easier maintenance

Guidelines, also written in docs/protocol.md "New data payloads: guidelines for developers":
- Now protocol data exchanged over USB or BLE are defined in netdata.h as packed structs and values are stored in Network byte order (=Big Endian)
- Command-specific payloads are defined in their respective cmd_processor handler in app_cmd.c and chameleon_cmd.py
- Define C `struct` for cmd/resp data greater than a single byte, use and abuse of `struct.pack`/`struct.unpack` in Python. So one can understand the payload format at a simple glimpse.
- If single byte of data to return, still use a 1-byte `data`, not `status`.
- Use unambiguous types such as `uint16_t`, not `int` or `enum`. Cast explicitly `int` and `enum` to `uint_t` of proper size
- Use Network byte order for 16b and 32b integers
  - Macros `U16NTOHS`, `U32NTOHL` must be used on reception of a command payload.
  - Macros `U16HTONS`, `U32HTONL` must be used on creation of a response payload.
  - In Python, use the modifier `!` with all `struct.pack`/`struct.unpack`
- Concentrate payload parsing in the handlers, avoid further parsing in their callers. This is true for the firmware and the client.
- In cmd_processor handlers: don't reuse input `length`/`data` parameters for creating the response content
- Avoid hardcoding offsets, use `sizeof()`, `offsetof(struct, field)` in C and `struct.calcsize()` in Python
- Use the exact same command and fields names in firmware and in client, use function names matching the command names for their handlers unless there is a very good reason not to do so. This helps grepping around. Names must start with a letter, not a number, because some languages require it (e.g. `14a_scan` not possible in Python)
- Respect commands order in `m_data_cmd_map`, `data_cmd.h` and `chameleon_cmd.py` definitions
- Even if a command is not yet implemented in firmware or in client but a command number is allocated, add it to `data_cmd.h` and `chameleon_cmd.py` with some `FIXME: to be implemented` comment
- Validate data before using it, both when receiving command data in the firmware and when receiving response data in the client.
- Validate response status in client.

Disruptive changes:
- GET_DEVICE_CAPABILITIES: list of cmds in data are now really Big Endian
  Note: the initial attempt to use macros PP_HTONS were actually considering wrongly that the platform was Big Endian (BYTE_ORDER was actually undefined) while it is actually Little Endian.
- GET_APP_VERSION: response is now a tuple of bytes: major|minor (previously it was in reversed order as a single uint16_t in Little Endian)
- SET_SLOT_TAG_TYPE: tag_type now on 2 bytes, to prepare remapping of its enum
- SET_SLOT_DATA_DEFAULT: tag_type now on 2 bytes, to prepare remapping of its enum
- GET_SLOT_INFO: tag_type now on 2 bytes, to prepare remapping of its enum
- GET_DEVICE_CHIP_ID: now returns its 64b ID following Network byte order (previously, bytes were in the reverse order)
- GET_DEVICE_ADDRESS: now returns its 56b address following Network byte order (previously, bytes were in the reverse order). CLI does not reverse the response anymore so it displays the same value as before.
- MF1_GET_DETECTION_COUNT: now returns its 32b value following Network byte order (previously Little Endian)
- GET_GIT_VERSION response status is now STATUS_DEVICE_SUCCESS
- GET_DEVICE_MODEL response status is now STATUS_DEVICE_SUCCESS
- MF1_READ_EMU_BLOCK_DATA response status is now STATUS_DEVICE_SUCCESS
- GET_DEVICE_CAPABILITIES response status is now STATUS_DEVICE_SUCCESS
- HF14A_SCAN: entirely new response format, room for ATS and multiple tags
- MF1_DETECT_SUPPORT response status is now HF_TAG_OK and support is indicated as bool in 1 byte of data
- MF1_DETECT_PRNG response status is now HF_TAG_OK and prng_type is returned in 1 byte of data with a new enum mf1_prng_type_t == MifareClassicPrngType
- MF1_DETECT_DARKSIDE response status is now HF_TAG_OK and darkside_status is returned in 1 byte of data with a new enum mf1_darkside_status_t == MifareClassicDarksideStatus
- MF1_DARKSIDE_ACQUIRE response status is now HF_TAG_OK and darkside_status is returned in 1 byte of data. If OK, followed by 24 bytes as previously
- MF1_GET_ANTI_COLL_DATA: in case slot does not contain anticoll data, instead of STATUS_PAR_ERR, now it returns STATUS_DEVICE_SUCCESS with empty data
- MF1_SET_ANTI_COLL_DATA and MF1_GET_ANTI_COLL_DATA now use the same data format as HF14A_SCAN

For clients to detect Ultra/Lite with older firmwares, one can issue the GET_APP_VERSION and urge the user to flash his device if needed.
On older firmwares, it will return a status=b'\x00' and data=b'\x00\x01' while up-to-date firmwares will return status=STATUS_DEVICE_SUCCESS and data greater or equal to b'\x01\x00' (v1.0).

Other changes: cf CHANGELOG, and probably a few small changes I forgot about..

TODO:
- remap `tag_specific_type_t` enum to allow future tags (e.g. LF tags) without reshuffling enum and affecting users stored cards
- TEST!
2023-09-18 00:53:39 +02:00
Eremita Solitario 6d2eb1761f Solved bug that makes hf mf eread command crashes 2023-09-09 23:32:53 +02:00
Philippe Teuwen a793810f59 Merge pull request #132 from Foxushka/simplify-code
block_count can't be more than 0xFF, simplify code
2023-09-08 09:05:55 +02:00
Foxushka 1ac071e449 block_count can't be move than 0xFF, simplify code 2023-09-07 20:07:38 +03:00
Foxushka 6e4d861625 Update version in docstring 2023-09-07 19:41:57 +03:00
Foxushka dbf4599221 Update cmd_processor_get_settings 2023-09-07 19:40:50 +03:00
dxl b3e0afc555 Enable BLE pairing by setting and disable by default. 2023-09-07 20:04:24 +08:00
Foxushka 2e912285f5 Implement DATA_CMD_GET_MF1_ANTI_COLL_DATA and DATA_CMD_GET_SETTINGS 2023-09-06 23:36:43 +03:00
Foxushka 55a70fc2e5 Move to PP_HTONS 2023-09-06 22:55:26 +03:00
Foxushka 58d43a36c4 Merge branch 'main' into software-capabilities 2023-09-06 22:34:57 +03:00
Philippe Teuwen 76168621b4 style 2023-09-02 22:24:15 +02:00
Foxushka d22ff44342 DATA_CMD_GET_DEVICE_CAPABILITIES implementation 2023-08-28 09:12:48 +03:00
Philippe Teuwen bd3961077c CLI now takes into account Lite refusing to enter reader mode 2023-08-28 01:07:27 +02:00
dxl d76fbd440c Added commands related to BLE pairing binding. 2023-08-28 01:35:57 +08:00
Philippe Teuwen d5d955d2e9 pylance 2023-08-26 02:55:46 +02:00
Philippe Teuwen a596e98bf7 python style 2023-08-26 02:24:08 +02:00
Philippe Teuwen d08c8c4605 Close properly after factory reset, fix typo 2023-08-26 01:48:30 +02:00
Philippe Teuwen 05f25e830c More Chinese (auto) translation 2023-08-25 19:51:27 +02:00
Nemanja Nedeljkovic 1ff0be6ed8 Add long press command 2023-08-23 19:29:03 +02:00
Philippe Teuwen e43e668594 Remove tabs & spaces at end of lines 2023-08-23 00:18:31 +02:00
Augusto Zanellato 5f27cef975 Remove restrictions from slot delete 2023-08-22 23:30:33 +02:00
dxl 76643183ea Impl change the button function when click. 2023-08-22 19:58:33 +08:00
dxl 68a3e463f1 Add command to get battery information #38 2023-08-22 12:05:48 +08:00
Augusto Zanellato d33ae755c1 Add ability to delete sense type per slot 2023-08-21 16:38:11 +02:00
Philippe Teuwen 423d212cf7 add authors and changelog files and reminder in CI 2023-08-21 02:17:00 +02:00
Philippe Teuwen 136a7531f4 Merge pull request #66 from szymex73/cli-overhaul
CLI Overhaul
2023-08-21 00:09:02 +02:00
Philippe Teuwen 5e52180aec Mifare Classic emulator: fix asked by @Foxushka 2023-08-20 10:21:08 +02:00