Skip to content

Commit

Permalink
feat: more descriptive return codes, sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaz committed Dec 25, 2023
1 parent 5353f19 commit d743eb6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/devices/astrostart_2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int astrostart_2000_decode(r_device *decoder, bitbuffer_t *bitbuffer)
uint8_t *bytes = bitbuffer->bb[0];

if (bytes[0] != (~bytes[1] & 0xff)) {
return DECODE_ABORT_EARLY;
return DECODE_FAIL_MIC;
}

button = bytes[0];
Expand All @@ -97,7 +97,7 @@ static int astrostart_2000_decode(r_device *decoder, bitbuffer_t *bitbuffer)
}

if (actual_checksum != expected_checksum) {
return DECODE_ABORT_EARLY;
return DECODE_FAIL_MIC;
}

// these are not bit flags
Expand Down
4 changes: 2 additions & 2 deletions src/devices/audiovox_car_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ static int audiovox_decode(r_device *decoder, bitbuffer_t *bitbuffer)
code = (bytes[2] << 8) | bytes[3];
button = (bytes[4] >> 3) & 0xf;

if (id == 0 || code == 0 || button == 0) {
return DECODE_ABORT_EARLY;
if (id == 0 || code == 0 || button == 0 || id == 0xffff || code == 0xffff) {
return DECODE_FAIL_SANITY;
}

/* clang-format off */
Expand Down
8 changes: 4 additions & 4 deletions src/devices/compustar_700r.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IIIII bbbbb xxx
- I: 20 bit remote ID
- B: 5 bit button flags
- x: 3 bit unknown (always set to 111)
- x: 3 bit unknown (always set to 000)
Format string:
Expand All @@ -57,14 +57,14 @@ static int compustar_700r_decode(r_device *decoder, bitbuffer_t *bitbuffer)
uint8_t *bytes = bitbuffer->bb[0];

if ((bytes[4] & 0x7) != 0x0) {
return DECODE_ABORT_EARLY;
return DECODE_FAIL_SANITY;
}

int id = bytes[0] << 12 | bytes[1] << 4 | bytes[2] >> 4;
int button = ~(bytes[2] << 1 | bytes[3] >> 7) & 0x1f;

if ((bytes[4] & 0x7) != 0x0 || button == 0 || id == 0) {
return DECODE_ABORT_EARLY;
if ((bytes[4] & 0x7) != 0x0 || button == 0 || id == 0 || id == 0xfffff) {
return DECODE_FAIL_SANITY;
}

// button flags
Expand Down

0 comments on commit d743eb6

Please sign in to comment.