Skip to content

Commit

Permalink
Fix byte-stuffing issues (#32)
Browse files Browse the repository at this point in the history
This commit fixes two issues related to byte stuffing in SHDLC

1) Decoding SHDLC messages fail when the CRC byte is stuffed.
   This issue was reported upstream, along with a fix. Many thanks.

2) Missing break; in case statement causing an unwanted fall-through.
   Stuffing bytes causes the buffer to not only add the stuffing
   marker and the stuffed byte, but also the original unstuffed byte.
   This means that the data is both too long and corrupt, likely
   causing the sensor to ignore the request.
  • Loading branch information
abrauchli authored Apr 3, 2019
1 parent d6eaad5 commit a668532
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion embedded-uart-common/sensirion_shdlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static u16 sensirion_shdlc_stuff_data(u8 data_len, const u8 *data,
*(stuffed_data++) = 0x7d;
*(stuffed_data++) = c ^ (1 << 5);
output_data_len += 2;
break;
default:
*(stuffed_data++) = c;
output_data_len += 1;
Expand Down Expand Up @@ -185,7 +186,7 @@ s16 sensirion_shdlc_rx(u8 max_data_len, struct sensirion_shdlc_rx_header *rxh,

crc = rx_frame[i++];
if (sensirion_shdlc_check_unstuff(crc)) {
crc = sensirion_shdlc_unstuff_byte(rx_frame[++i]);
crc = sensirion_shdlc_unstuff_byte(rx_frame[i++]);
if (i >= len)
return SENSIRION_SHDLC_ERR_MISSING_STOP;
}
Expand Down

0 comments on commit a668532

Please sign in to comment.