Commit Graph

58 Commits

Author SHA1 Message Date
Philippe Teuwen 9497ff7eab Add timeout parameter to hw raw 2023-09-18 23:20:18 +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
jimmytai 0db0d852cb sdk docs 2023-09-13 07:45:43 +08:00
Thomas Burnham 5f36600cda Update nomenclature technical_whitepaper.md
Simulation and emulation used within same document while having no distinctive technical differentiating usage, propose changing all instances to Emulate/Emulation
2023-09-12 17:47:50 -04:00
Philippe Teuwen 00a0019ef3 protocol note on LRC computations 2023-09-10 12:47:26 +02:00
Philippe Teuwen 0dc83b4f5b troubleshooting 2023-09-08 09:57:22 +02:00
Philippe Teuwen bc874f68ef doc 2023-09-07 08:44:03 +02:00
Wilson 2e38664792 Add MTools Lite link and quickstart documents. 2023-09-07 11:20:33 +08:00
mitmarcus ea67c5cec5 Update README.md 2023-09-05 14:21:48 +03:00
mitmarcus 7fe61d995b Update README.md
groupped documentation to be more readable
2023-09-05 14:09:33 +03:00
Philippe Teuwen e0556857f2 Merge pull request #124 from mitmarcus/patch-4
Update modding.md
2023-09-05 10:35:59 +02:00
mitmarcus a3cf711cac Update modding.md
found 1 more project
2023-09-05 11:26:09 +03:00
mitmarcus 476775a701 Update troubleshooting.md
reminding people to turn on location setting in android
2023-09-05 10:51:02 +03:00
Philippe Teuwen 5a9ca62d2a doc 2023-09-04 23:16:19 +02:00
Philippe Teuwen d928ab2285 docs 2023-09-03 15:41:26 +02:00
Philippe Teuwen 7506e64bc8 Mods 2023-09-01 20:17:36 +02:00
Philippe Teuwen f54879b364 Merge pull request #120 from mitmarcus/patch-2
Update chameleonultragui.md
2023-09-01 12:27:55 +02:00
Philippe Teuwen 65845fd7f5 Update docs/firmware.md 2023-09-01 12:24:19 +02:00
mitmarcus 5e1a502005 Update chameleonultragui.md
based on cyber.vi.king's and gametec_live's comment on this
2023-09-01 13:01:03 +03:00
mitmarcus 4fcc2f565e Update firmware.md 2023-09-01 12:45:42 +03:00
mitmarcus 93141e3e6c Update firmware.md
explanation on write modes provided by GameTec_live
2023-09-01 12:28:38 +03:00
jimmytai 80a7054c7c Docs: protocol 2023-08-30 23:08:16 +08:00
Foxushka 327e6c06e5 Fix links and correct OS namings 2023-08-30 13:40:14 +00:00
Andrea Draghetti d57a24073b Update quickstart.md 2023-08-30 11:48:29 +02:00
Philippe Teuwen a41322efae Merge pull request #109 from digitalcardboard/patch-1
Update cli.md
2023-08-30 10:18:50 +02:00
Philippe Teuwen f80e7fe14e doc ble 2023-08-29 13:09:24 +02:00
Jason Navarrete 81f6dd2473 Update cli.md
Installing ninja fails without updating keys.
2023-08-28 21:33:36 -07:00
Philippe Teuwen c0876aa11b noconfirm 2023-08-27 13:56:23 +02:00
Philippe Teuwen c56a7cc8bf troubleshooting 2023-08-27 13:53:03 +02:00
Uli Heilmeier c2f29de9b0 docs: add links for MTools 2023-08-26 15:13:31 +02:00
Philippe Teuwen 94164093b0 cli doc fix by @GameTec-live 2023-08-26 12:29:05 +02:00
Philippe Teuwen 5c36004e9c doc 2023-08-26 00:16:43 +02:00
Philippe Teuwen 86067576d8 doc 2023-08-25 23:51:51 +02:00
Philippe Teuwen 249cadc736 reorg doc 2023-08-25 23:41:25 +02:00
Philippe Teuwen 6d096df88b readme 2023-08-25 22:55:05 +02:00
Philippe Teuwen 591b03e1b3 emojis 2023-08-25 22:37:44 +02:00
Philippe Teuwen c6030c8fdf Remove command ID, there is no 1-1 mapping between cli commands and fw commands and it's more a concern for devs than uers 2023-08-25 22:25:57 +02:00
Philippe Teuwen 1a4fcdda01 doc 2023-08-25 22:16:07 +02:00
GameTec_live 6d4dee4247 Merge branch 'users-guide' of https://github.com/GameTec-live/ChameleonUltra into users-guide 2023-08-25 21:17:38 +02:00
GameTec_live 0d9ad25765 cli 2023-08-25 21:17:21 +02:00
GameTec-live 1adbc915ce Update docs/firmware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 20:07:59 +02:00
GameTec_live 62392a671c moved dev, added ideas for fw section 2023-08-25 19:21:31 +02:00
GameTec_live bf3b93622d fix z height 2023-08-25 18:55:35 +02:00
GameTec_live 7c5eb55fdf remove floating ´ 2023-08-25 18:51:50 +02:00
GameTec-live ef300fbbfe Update docs/hardware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:51:04 +02:00
GameTec-live 4731d04c3f Update docs/home.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:50:40 +02:00
GameTec-live e063c99b71 Update docs/hardware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:50:17 +02:00
GameTec-live f783f3a35b Update docs/hardware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:49:38 +02:00
GameTec-live 1e6a153c7e Update docs/hardware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:48:09 +02:00
GameTec-live 34d6d79306 Update docs/hardware.md
Co-authored-by: Philippe Teuwen <phil-github@teuwen.org>
2023-08-25 18:47:34 +02:00