libwmc: add more tests including for UML290 quirks

This commit is contained in:
Dan Williams
2011-09-19 13:42:00 -05:00
parent 46a5c77616
commit 8250dee131
7 changed files with 186 additions and 9 deletions
+13 -7
View File
@@ -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) {