Commit Graph

79 Commits

Author SHA1 Message Date
Philippe Teuwen 14bffafb2a style 2023-09-20 01:26:47 +02:00
dxl 32b3e19279 Added support for StaticNested(FastDecrypt). 2023-09-19 18:24:30 +08:00
Augusto Zanellato 09eb0d19f4 Automatically send RATS to 14443-4a tags 2023-09-19 00:32:52 +02:00
Philippe Teuwen 9497ff7eab Add timeout parameter to hw raw 2023-09-18 23:20:18 +02: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
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 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
dxl d76fbd440c Added commands related to BLE pairing binding. 2023-08-28 01:35:57 +08:00
Philippe Teuwen 04741bdc2a autopep8 2023-08-26 12:06:15 +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
Benjamin DELPY 3bf25f1766 Fix multiple Chameleon connected on WSL1
Avoid

```
Chameleon Connect fail: [Errno 2] could not open port /dev/ttyS15
/dev/ttyS39: [Errno 2] No such file or directory: '/dev/ttyS15\r\n/dev/ttyS39'
```

By only returning the first COM port with `VID_6868&PID_8686`
2023-08-26 00:31:44 +02:00
Philippe Teuwen 05f25e830c More Chinese (auto) translation 2023-08-25 19:51:27 +02:00
Philippe Teuwen 1ebeb9b461 fix btnpress info dump 2023-08-24 10:44:19 +02:00
Nemanja Nedeljkovic a01158f323 Remove parameter from --long 2023-08-24 08:50:55 +02:00
Nemanja Nedeljkovic 6e9582f4f2 Fix bug 2023-08-23 19:32:49 +02:00
Nemanja Nedeljkovic 1ff0be6ed8 Add long press command 2023-08-23 19:29:03 +02:00
Philippe Teuwen dbda8b92fb Merge pull request #73 from m-kozlowski/wsl-autodetect
Add port auto detection on WSL1
2023-08-23 01:03: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 ed4a84ccc6 Merge branch 'main' of https://github.com/RfidResearchGroup/ChameleonUltra 2023-08-22 20:01:32 +08:00
dxl 76643183ea Impl change the button function when click. 2023-08-22 19:58:33 +08:00
mkozlowski 961b8a58f3 Faster COM port detection 2023-08-22 11:37:12 +02:00
Sgnusov d17c63f298 Fix setting slot nick 2023-08-22 09:34:24 +00:00
mkozlowski aa3d3e40b4 Fallback to default path when powershell.exe is not found in PATH 2023-08-22 11:23:50 +02:00
mkozlowski 9922dc5b50 Fallback to default path when powershell.exe is not found in PATH 2023-08-22 11:22:59 +02:00
dxl 68a3e463f1 Add command to get battery information #38 2023-08-22 12:05:48 +08:00
mkozlowski 6e411dc50c WSL2 doesn't need special handling 2023-08-21 21:33:17 +02:00
mkozlowski 2f0d4edb04 Add com port auto detection on WSL1 2023-08-21 19:57:03 +02:00
Augusto Zanellato d33ae755c1 Add ability to delete sense type per slot 2023-08-21 16:38:11 +02:00
Szymon Borecki 895b0ced12 Merge remote-tracking branch 'origin/main' into cli-overhaul 2023-08-20 01:25:24 +02:00
Philippe Teuwen 8879460e10 Merge branch 'main' into hw-slot-info 2023-08-20 00:11:42 +02:00
Philippe Teuwen 12de4c0e0e Merge pull request #56 from domints/implement-get-slot-data
Implement get slot data
2023-08-20 00:07:46 +02:00
Foxushka 151f412490 Implement new Mifare Classic emulator configuration commands, improve CLI
Slot

Won't work like this

More randomness on nested auth (for hardnested recovery) and change default GCC location

Nobody will have GCC in this default location, /usr/bin/ will target way more users

Get enabled slots command

hw slot list show disabled slots

Improve python code quality

Show Mifare Classic emulator settings in hw slot list

Implement hf mf settings to change Mifare Classic emulator settings

Update
2023-08-19 20:59:39 +03:00
Szymon Borecki dddc6f1a10 Merge remote-tracking branch 'origin/main' into cli-overhaul 2023-08-19 14:19:40 +02:00
Szymon Borecki f6e22328bb Add working argument completion 2023-08-19 13:44:15 +02:00
Philippe Teuwen 22747138e7 Merge branch 'main' into bugfix/cli-offset 2023-08-19 01:18:42 +02:00
Philippe Teuwen 9db1671be5 Merge pull request #63 from augustozanellato/factory_reset
Add factory reset command
2023-08-19 00:46:39 +02:00
Philippe Teuwen 3bfc52432a change slot nicknames encoding: gbk -> utf8 2023-08-19 00:14:19 +02:00
Augusto Zanellato 7b76aefd5e ACK command and use delayed reset 2023-08-18 22:35:39 +02:00
Augusto Zanellato 4ab131d10a Implement wipe fds command used to factory reset 2023-08-18 22:13:06 +02:00
Dominik Szymański 813b12bd37 Implement Mifare Classic emulator slot read 2023-08-18 19:39:05 +02:00
Philippe Teuwen 828d88c273 Several changes on TagSenseType, TagSpecificType and SlotNumber:
* SlotNumber values range from 1 to 8 rather than from 0 to 7
  this allows more straightforward usage as ppl can use equivalently SLOT_1 or 1.
* SlotNumber.fix -> .to_fw, and add .from_fw
* removed unnecessary SLOT_NO
* More straightforward use of enums, no need for .value, .__members__, name.replace() etc
* Unify usage between TagSenseType and TagSpecificType
* Add str representations for TagSenseType
* Fixed TagSpecificType related help (e.g. in hw slot type -h)
* Removed some redundant error raise
* Note: iterations can be done with `for slot in chameleon_cmd.SlotNumber:`
2023-08-18 18:03:02 +02:00
Dominik Szymański 278deda0c6 Merge branch 'main' into implement-get-slot-data 2023-08-18 16:50:38 +02:00
Philippe Teuwen 698c9b8ea5 Merge branch 'main' into bugfix/cli-offset 2023-08-18 16:02:55 +02:00
Foxushka 913c1540e3 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
2023-08-17 22:40:04 +03:00