From 38b120c8617724ba97ac212c9e01d01c850abdc8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 3 Apr 2013 12:20:46 +0200 Subject: [PATCH] port-probe: don't assume the NULL bytes will be at the beginning of the response Also report as non-AT responses if the NUL bytes are embedded within a stream of bytes which doesn't start with NUL. This e.g. applies to CnS ports from Sierra modems, which show streams like: ~\0\245y\0}^T1_0_4_0BT R372 CNSZXD00000061 2011/05/12 15:25:25\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0T1_0_4_0AP R372 CNSZXD00000061 2011/05 /12 15:25:25\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 03\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0~~ \0Tb\0T1_0_4_0AP R372 CNSZXD --- src/mm-port-probe.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mm-port-probe.c b/src/mm-port-probe.c index 788c1045..6c36e6ba 100644 --- a/src/mm-port-probe.c +++ b/src/mm-port-probe.c @@ -597,15 +597,16 @@ static gboolean is_non_at_response (const guint8 *data, gsize len) { const gchar **iter; - size_t iter_len; - int i; + gsize iter_len; + gsize i; /* Some devices (observed on a ZTE branded "QUALCOMM INCORPORATED" model * "154") spew NULLs from some ports. */ - if ( (len >= sizeof (zerobuf)) - && (memcmp (data, zerobuf, sizeof (zerobuf)) == 0)) - return TRUE; + for (i = 0; (len >= sizeof (zerobuf)) && (i < len - sizeof (zerobuf)); i++) { + if (!memcmp (&data[i], zerobuf, sizeof (zerobuf))) + return TRUE; + } /* Check for a well-known non-AT response. There are some ports (eg many * Icera-based chipsets, Qualcomm Gobi devices before their firmware is