diff options
author | Dan Williams <dcbw@redhat.com> | 2011-09-19 13:42:00 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-09-19 13:42:00 -0500 |
commit | 8250dee13177a164d61e31fe8d60900f9d5c6797 (patch) | |
tree | f3ade392879c752ff63b81bff254ac69ee5f3c67 /libwmc/src/utils.c | |
parent | 46a5c77616a6fe22fa2a13a1f908b05a55e1ff31 (diff) |
libwmc: add more tests including for UML290 quirks
Diffstat (limited to 'libwmc/src/utils.c')
-rw-r--r-- | libwmc/src/utils.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libwmc/src/utils.c b/libwmc/src/utils.c index 71f8a461..99c13db7 100644 --- a/libwmc/src/utils.c +++ b/libwmc/src/utils.c @@ -128,14 +128,15 @@ hdlc_escape (const char *inbuf, src = inbuf; i = inbuf_len; while (i--) { - if ( *src == DIAG_CONTROL_CHAR - || *src == DIAG_ESC_CHAR - || (escape_all_ctrl && *src <= 0x20)) { + guint8 byte = (guint8) *src++; + + if ( byte == DIAG_CONTROL_CHAR + || byte == DIAG_ESC_CHAR + || (escape_all_ctrl && byte <= 0x20)) { *dst++ = DIAG_ESC_CHAR; - *dst++ = *src ^ DIAG_ESC_MASK; + *dst++ = byte ^ DIAG_ESC_MASK; } else - *dst++ = *src; - src++; + *dst++ = byte; } return (dst - outbuf); @@ -273,6 +274,9 @@ uml290_wmc_encapsulate (char *inbuf, * hdlc_decapsulate_buffer: * @inbuf: buffer in which to look for an HDLC frame * @inbuf_len: length of valid data in @inbuf + * @check_known_crc: if %TRUE, validate the CRC using @known_crc + * @known_crc: if @check_known_crc is %TRUE, compare the frame's CRC against + * @known_crc. @known_crc must be in Little Endian (LE) byte order. * @outbuf: buffer in which to put decapsulated data from the HDLC frame * @outbuf_len: max size of @outbuf * @out_decap_len: on success, size of the decapsulated data @@ -296,6 +300,8 @@ uml290_wmc_encapsulate (char *inbuf, gboolean hdlc_decapsulate_buffer (const char *inbuf, gsize inbuf_len, + gboolean check_known_crc, + guint16 known_crc, char *outbuf, gsize outbuf_len, gsize *out_decap_len, @@ -359,7 +365,7 @@ hdlc_decapsulate_buffer (const char *inbuf, } /* Check the CRC of the packet's data */ - crc = crc16 (outbuf, unesc_len - 2, 0); + crc = check_known_crc ? known_crc : crc16 (outbuf, unesc_len - 2, 0); pkt_crc = outbuf[unesc_len - 2] & 0xFF; pkt_crc |= (outbuf[unesc_len - 1] & 0xFF) << 8; if (crc != pkt_crc) { |