r2724 - trunk/src/target/gsm/src/libgsmd

laforge at sita.openmoko.org laforge at sita.openmoko.org
Fri Aug 17 10:31:52 CEST 2007


Author: laforge
Date: 2007-08-17 10:31:49 +0200 (Fri, 17 Aug 2007)
New Revision: 2724

Modified:
   trunk/src/target/gsm/src/libgsmd/libgsmd.c
Log:
From: Andrzej Zaborowski <balrog at zabor.org>
Date: Tue, 31 Jul 2007 22:28:28 +0200
Subject: [PATCH] Correctly split long usock reads into packets.

This is a patch for an unrelated to the above discussion timing issue in
libgsmd. In particular, when the modem responds fast enough, gsmd generates
usock packets fast enough for libgsmd to read multiple packets in a single read
and concatenate them thus discarding all packets but first. This happens on
Neo1973 when requesting for example the list of preferred operators or all
operators or, sometimes, list of short messages.


Modified: trunk/src/target/gsm/src/libgsmd/libgsmd.c
===================================================================
--- trunk/src/target/gsm/src/libgsmd/libgsmd.c	2007-08-17 08:31:21 UTC (rev 2723)
+++ trunk/src/target/gsm/src/libgsmd/libgsmd.c	2007-08-17 08:31:49 UTC (rev 2724)
@@ -88,26 +88,32 @@
 /* handle a packet that was received on the gsmd socket */
 int lgsm_handle_packet(struct lgsm_handle *lh, char *buf, int len)
 {
-	struct gsmd_msg_hdr *gmh = (struct gsmd_msg_hdr *)buf;
+	struct gsmd_msg_hdr *gmh;
 	lgsm_msg_handler *handler; 
-	
-	if (len < sizeof(*gmh))
-		return -EINVAL;
-	
-	if (len - sizeof(*gmh) < gmh->len)
-		return -EINVAL;
-	
-	if (gmh->msg_type >= __NUM_GSMD_MSGS)
-		return -EINVAL;
-	
-	handler = lh->handler[gmh->msg_type];
-	
-	if (handler)
-		return handler(lh, gmh);
-	else {
-		fprintf(stderr, "unable to handle packet type=%u\n", gmh->msg_type);
-		return 0;
+	int rc = 0;
+
+	while (len) {
+		if (len < sizeof(*gmh))
+			return -EINVAL;
+		gmh = (struct gsmd_msg_hdr *) buf;
+
+		if (len - sizeof(*gmh) < gmh->len)
+			return -EINVAL;
+		len -= sizeof(*gmh) + gmh->len;
+		buf += sizeof(*gmh) + gmh->len;
+
+		if (gmh->msg_type >= __NUM_GSMD_MSGS)
+			return -EINVAL;
+
+		handler = lh->handler[gmh->msg_type];
+
+		if (handler)
+			rc |= handler(lh, gmh);
+		else
+			fprintf(stderr, "unable to handle packet type=%u\n",
+					gmh->msg_type);
 	}
+	return rc;
 }
 
 int lgsm_register_handler(struct lgsm_handle *lh, int type, lgsm_msg_handler *handler)





More information about the commitlog mailing list