Skip to content

Commit

Permalink
cli: make status an enum. rename some status for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Oct 17, 2023
1 parent 2beb8f7 commit fa0754a
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 439 deletions.
10 changes: 5 additions & 5 deletions docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ E.g. LRC3(DATA) == LRC3(whole frame)

Each command and response have their own payload formats.

Standard response status is `STATUS_DEVICE_SUCCESS` for general commands, `HF_TAG_OK` for HF commands and `LF_TAG_OK` for LF commands.
Standard response status is `STATUS_SUCCESS` for general commands, `STATUS_HF_TAG_OK` for HF commands and `STATUS_LF_TAG_OK` for LF commands.
See [Guidelines](#new-data-payloads-guidelines-for-developers) for more info.

Beware, slots in protocol count from 0 to 7 (and from 1 to 8 in the CLI...).
Expand Down Expand Up @@ -144,7 +144,7 @@ Notes: the returned string is the output of `git describe --abbrev=7 --dirty --a
* CLI: cf `hw slot list`
### 1020: WIPE_FDS
* Command: no data
* Response: no data. Status is `STATUS_DEVICE_SUCCESS` or `STATUS_FLASH_WRITE_FAIL`. The device will reboot shortly after this command.
* Response: no data. Status is `STATUS_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.
Expand Down Expand Up @@ -226,7 +226,7 @@ Notes: wait about 5 seconds after wake-up, before querying the battery status, e
* CLI: cf `hf 14a scan`

Notes:
* remind that if no tag is present, status will be `HF_TAG_NO` and Response empty.
* remind that if no tag is present, status will be `STATUS_HF_TAG_NO` and Response empty.
* at the moment, the firmware supports only one tag, but get your client ready for more!
* `atslen` must not be confused with `ats[0]`==`TL`. So `atslen|ats` = `00` means no ATS while `0100` would be an empty ATS.
### 2001: MF1_DETECT_SUPPORT
Expand Down Expand Up @@ -269,7 +269,7 @@ Notes:
### 2007: MF1_AUTH_ONE_KEY_BLOCK
* Command: 8 bytes: `type|block|key[6]`. Key as 6 bytes. Type=0x60 for key A, 0x61 for key B.
* Response: no data
* Status will be `HF_TAG_OK` if auth succeeded, else `MF_ERR_AUTH`
* Status will be `STATUS_HF_TAG_OK` if auth succeeded, else `STATUS_MF_ERR_AUTH`
* CLI: cf `hf mf nested`
### 2008: MF1_READ_ONE_BLOCK
* Command: 8 bytes: `type|block|key[6]`. Key as 6 bytes. Type=0x60 for key A, 0x61 for key B.
Expand Down Expand Up @@ -397,7 +397,7 @@ Be verbose, explicit and reuse conventions, in order to enhance code maintainabi
- Avoid hardcoding offsets, use `sizeof()`, `offsetof(struct, field)` in C and `struct.calcsize()` in Python
- For complex bitfield structs, exceptionally you can use ctypes in Python. Beware ctypes.BigEndianStructure bitfield will be parsed in the firmware in the reverse order, from LSB to MSB.
### Guideline: Status
If single byte of data to return, still use a 1-byte `data`, not `status`. Standard response status is `STATUS_DEVICE_SUCCESS` for general commands, `HF_TAG_OK` for HF commands and `LF_TAG_OK` for LF commands. If the response status is different than those, the response data is empty. Response status are generic and cover things like tag disappearance or tag non-conformities with the ISO standard. If a command needs more specific response status, it is added in the first byte of the data, to avoid cluttering the 1-byte general status enum with command-specific statuses. See e.g. [MF1_DARKSIDE_ACQUIRE](#2004-mf1_darkside_acquire).
If single byte of data to return, still use a 1-byte `data`, not `status`. Standard response status is `STATUS_SUCCESS` for general commands, `STATUS_HF_TAG_OK` for HF commands and `STATUS_LF_TAG_OK` for LF commands. If the response status is different than those, the response data is empty. Response status are generic and cover things like tag disappearance or tag non-conformities with the ISO standard. If a command needs more specific response status, it is added in the first byte of the data, to avoid cluttering the 1-byte general status enum with command-specific statuses. See e.g. [MF1_DARKSIDE_ACQUIRE](#2004-mf1_darkside_acquire).
### Guideline: unambiguous types
- 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
Expand Down
148 changes: 74 additions & 74 deletions firmware/application/src/app_cmd.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions firmware/application/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static void btn_fn_copy_ic_uid(void) {
case TAG_TYPE_EM410X:
status = PcdScanEM410X(id_buffer);

if (status == LF_TAG_OK) {
if (status == STATUS_LF_TAG_OK) {
tag_data_buffer_t *buffer = get_buffer_by_tag_type(TAG_TYPE_EM410X);
memcpy(buffer->buffer, id_buffer, LF_EM410X_TAG_ID_SIZE);
tag_emulation_load_by_buffer(TAG_TYPE_EM410X, false);
Expand Down Expand Up @@ -680,7 +680,7 @@ static void btn_fn_copy_ic_uid(void) {

status = pcd_14a_reader_scan_auto(&tag);
pcd_14a_reader_antenna_off();
if (status == HF_TAG_OK) {
if (status == STATUS_HF_TAG_OK) {
// copy uid
antres->size = tag.uid_len;
memcpy(antres->uid, tag.uid, tag.uid_len);
Expand Down
24 changes: 12 additions & 12 deletions firmware/application/src/app_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
/////////////////////////////////////////////////////////////////////
// 14a status
/////////////////////////////////////////////////////////////////////
#define HF_TAG_OK (0x00) // IC card operation successful
#define HF_TAG_NO (0x01) // No IC card found
#define HF_ERR_STAT (0x02) // IC Card communication error
#define HF_ERR_CRC (0x03) // IC Card communication verification error
#define HF_COLLISION (0x04) // IC card conflict
#define HF_ERR_BCC (0x05) // IC card BCC error
#define MF_ERR_AUTH (0x06) // MF card verification failed
#define HF_ERR_PARITY (0x07) // IC card parity error
#define HF_ERR_ATS (0x08) // ATS should be present but card NAKed
#define STATUS_HF_TAG_OK (0x00) // IC card operation successful
#define STATUS_HF_TAG_NO (0x01) // No IC card found
#define STATUS_HF_ERR_STAT (0x02) // IC Card communication error
#define STATUS_HF_ERR_CRC (0x03) // IC Card communication verification error
#define STATUS_HF_COLLISION (0x04) // IC card conflict
#define STATUS_HF_ERR_BCC (0x05) // IC card BCC error
#define STATUS_MF_ERR_AUTH (0x06) // MF card verification failed
#define STATUS_HF_ERR_PARITY (0x07) // IC card parity error
#define STATUS_HF_ERR_ATS (0x08) // ATS should be present but card NAKed

/////////////////////////////////////////////////////////////////////
// lf status
/////////////////////////////////////////////////////////////////////
#define LF_TAG_OK (0x40) // Some of the low -frequency cards are successful!
#define EM410X_TAG_NO_FOUND (0x41) // Can't search for valid EM410X tags
#define STATUS_LF_TAG_OK (0x40) // Some of the low -frequency cards are successful!
#define STATUS_EM410X_TAG_NO_FOUND (0x41) // Can't search for valid EM410X tags


/////////////////////////////////////////////////////////////////////
Expand All @@ -28,7 +28,7 @@
#define STATUS_PAR_ERR (0x60) // The parameter errors transferred by the BLE instruction, or call the parameter error transmitted by certain functions
#define STATUS_DEVICE_MODE_ERROR (0x66) // The mode of the current device is wrong, and the corresponding API cannot be called
#define STATUS_INVALID_CMD (0x67) // Invalid instruction
#define STATUS_DEVICE_SUCCESS (0x68) // Device -related operations successfully executed
#define STATUS_SUCCESS (0x68) // Device -related operations successfully executed
#define STATUS_NOT_IMPLEMENTED (0x69) // Calling some unrealized operations, which belongs to the missed error of the developer
#define STATUS_FLASH_WRITE_FAIL (0x70) // Flash writing failed
#define STATUS_FLASH_READ_FAIL (0x71) // Flash read failed
Expand Down
Loading

0 comments on commit fa0754a

Please sign in to comment.