diff options
author | Dan Williams <dcbw@redhat.com> | 2010-02-22 10:52:59 -0800 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2010-02-22 10:52:59 -0800 |
commit | 0f9d4d2a1ac3414b25c71f736c5b1293e1595721 (patch) | |
tree | 4d7fb6885eab580005a5608cd44dbda1d757cb00 /libqcdm/tests/test-qcdm-com.c | |
parent | f5d1a9b40038c4c81b361a089b0753d149b3107c (diff) | |
download | ModemManager-0f9d4d2a1ac3414b25c71f736c5b1293e1595721.tar.gz |
qcdm: fix QCDM packet decapsulation
Rename and document the encapsulate/decapsulate functions, CRC-check
the incoming packet, and make callers aware of the difference in how
big the decapsulated packet is versus how many bytes they should
discard from the buffer (since the decapsulated packet is at least
3 bytes shorter than the incoming packet due to the CRC + framing).
Diffstat (limited to 'libqcdm/tests/test-qcdm-com.c')
-rw-r--r-- | libqcdm/tests/test-qcdm-com.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c index 5ea59f67b..d8380fd75 100644 --- a/libqcdm/tests/test-qcdm-com.c +++ b/libqcdm/tests/test-qcdm-com.c @@ -144,9 +144,8 @@ wait_reply (TestComData *d, char *buf, gsize len) struct timeval timeout = { 1, 0 }; char readbuf[1024]; ssize_t bytes_read; - char *p = &readbuf[0]; int total = 0, retries = 0; - gboolean escaping = FALSE; + gsize decap_len = 0; FD_ZERO (&in); FD_SET (d->fd, &in); @@ -156,7 +155,7 @@ wait_reply (TestComData *d, char *buf, gsize len) do { errno = 0; - bytes_read = read (d->fd, p, 1); + bytes_read = read (d->fd, &readbuf[total], 1); if ((bytes_read == 0) || (errno == EAGAIN)) { /* Haven't gotten the async control char yet */ if (retries > 20) @@ -167,20 +166,36 @@ wait_reply (TestComData *d, char *buf, gsize len) retries++; continue; } else if (bytes_read == 1) { - /* Check for the async control char */ - if (*p++ == DIAG_CONTROL_CHAR) - break; + gboolean more = FALSE, success; + gsize used = 0; + total++; + decap_len = 0; + print_buf ("<<<", readbuf, total); + success = dm_decapsulate_buffer (readbuf, total, buf, len, &decap_len, &used, &more); + + /* Discard used data */ + if (used > 0) { + total -= used; + memmove (readbuf, &readbuf[used], total); + } + + if (success && !more) { + /* Success; we have a packet */ + break; + } } else { /* Some error occurred */ return 0; } - } while (total <= sizeof (readbuf)); + } while (total < sizeof (readbuf)); - if (d->debug) + if (d->debug) { print_buf ("<<<", readbuf, total); + print_buf ("D<<", buf, decap_len); + } - return dm_unescape (readbuf, total, buf, len, &escaping); + return decap_len; } void |