Re: [PATCH] smsc_cimd2.c (was: Segmentation fault in latest CVS)

<[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi Stipe,

Thanks for pointing that out, this is the kind of punishment one gets for
using ancient outlooks... :-(

Anyway, here's the patch again.

-- 
Per Skaglund
Dialtone Oy
Tekniikantie 14, FIN-02150 Espoo, Finland
Tel. +358941743434, Mobile +358405198377


-----Original Message-----
From:	Stipe Tolj [SMTP:[email protected]]
Sent:	Tuesday, June 03, 2003 11:48 AM
To:	Per Skaglund
Cc:	[email protected]
Subject:	Re: [PATCH] smsc_cimd2.c (was: Segmentation fault in latest CVS)

Hi Per,

Per Skaglund schrieb:
>
> Hi again,
>
> This patch should solve these cimd2 problems reported earlier by Illimar
> Reinbusch. The octstr ts in cimd2_submit_msg() was never initialized if the
> socket had been closed, octstr_destroy() caused a segmentation fault.
>
> NOTE: This patch also contains the not yet committed misc. fixes for
> smsc_cimd2.c I submitted earlier. I belive at least Angel voted in favour
> of that patch (thanks), Stipe?

it seems the attachement is broken, I get only a file of size 0 bytes
:(

Can you please re-send the patch.

Stipe

[email protected]
-------------------------------------------------------------------
Wapme Systems AG

Vogelsanger Weg 80
40470 Düsseldorf

Tel: +49-211-74845-0
Fax: +49-211-74845-299

E-Mail: [email protected]
Internet: http://www.wapme-systems.de
-------------------------------------------------------------------
wapme.net - wherever you are
smsc_cimd2.diff (application/octet-stream, 5.4 KB)
Index: gateway/gw/smsc/smsc_cimd2.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_cimd2.c,v
retrieving revision 1.12
diff -u -r1.12 smsc_cimd2.c
--- gateway/gw/smsc/smsc_cimd2.c	27 May 2003 03:36:59 -0000	1.12
+++ gateway/gw/smsc/smsc_cimd2.c	2 Jun 2003 09:54:35 -0000
@@ -69,7 +69,7 @@
 
 
 /* Microseconds before giving up on a request */
-#define RESPONSE_TIMEOUT (10 * 1000000)
+#define RESPONSE_TIMEOUT (60 * 1000000)
 
 /* Textual names for the operation codes defined by the CIMD 2 spec. */
 /* If you make changes here, also change the operation table. */
@@ -1436,6 +1436,9 @@
 static void packet_set_send_sequence(struct packet *packet, PrivData *pdata)
 {
     gw_assert(pdata != NULL);
+    /* LOGIN packets always have sequence number 001 */
+    if (packet->operation == LOGIN)
+        pdata->send_seq = 1;
     /* Send sequence numbers are always odd, receiving are always even */
     gw_assert(pdata->send_seq % 2 == 1);
 
@@ -1535,7 +1538,7 @@
     text = packet_get_sms_parm(request, P_USER_DATA);
     if (text != NULL) {
         convert_cimd2_to_gsm(text,conn);
-        /*charset = charset_gsm;  This overrides what we got from the DCS */
+        charset_gsm_to_latin1(text);
     } else {
         /*
          * FIXME: If DCS indicates GSM charset, and we get it in binary,
@@ -1551,23 +1554,27 @@
      * lack them.  If they should not be discarded, then the code
      * handling sms messages should be reviewed.  -- RB */
     if (!destination || octstr_len(destination) == 0) {
-        info(0, "CIMD2: Got SMS without receiver, discarding.");
+        info(0, "CIMD2[%s]: Got SMS without receiver, discarding.",
+              octstr_get_cstr(conn->id));
         goto error;
     }
     if (!origin || octstr_len(origin) == 0) {
-        info(0, "CIMD2: Got SMS without sender, discarding.");
+        info(0, "CIMD2[%s]: Got SMS without sender, discarding.",
+              octstr_get_cstr(conn->id));
         goto error;
     }
 
-    if ((!text || octstr_len(text) == 0) && (!UDH || octstr_len(UDH) == 0)) {
-        info(0, "CIMD2: Got empty SMS, ignoring.");
+    if (!text && (!UDH || octstr_len(UDH) == 0)) {
+        info(0, "CIMD2[%s]: Got empty SMS, ignoring.",
+              octstr_get_cstr(conn->id));
         goto error;
     }
-
+    
     message = msg_create(sms);
     if (! dcs_to_fields(&message, DCS)) {
 	/* XXX Should reject this message ? */
-	debug("CIMD2", 0, "Invalid DCS");
+        debug("bb.sms.cimd2", 0, "CIMD2[%s]: Invalid DCS",
+              octstr_get_cstr(conn->id));
 	dcs_to_fields(&message, 0);
     }
     time(&message->sms.time);
@@ -1594,18 +1601,26 @@
     PrivData *pdata = conn->data;
     Msg *message = NULL;
 
-    /* TODO: Check if the sequence number of this request is what we
-     * expected. */
-
-    if (request->operation == DELIVER_STATUS_REPORT) {
-        message = cimd2_accept_delivery_report_message(request, conn);
-        if (message)
-            list_append(pdata->received, message);
-     }
-     else if (request->operation == DELIVER_MESSAGE) {
-         message = cimd2_accept_message(request,conn);
-         if (message)
-             list_append(pdata->received, message);
+    if ((request->seq == 254 && pdata->receive_seq == 0) ||
+            request->seq == pdata->receive_seq - 2) {
+        warning(0, "CIMD2[%s]: request had same sequence number as previous.",
+                octstr_get_cstr(conn->id));
+    }
+    else {
+        pdata->receive_seq = request->seq + 2;
+        if (pdata->receive_seq > 254)
+            pdata->receive_seq = 0;
+
+        if (request->operation == DELIVER_STATUS_REPORT) {
+            message = cimd2_accept_delivery_report_message(request, conn);
+            if (message)
+                list_append(pdata->received, message);
+        }
+        else if (request->operation == DELIVER_MESSAGE) {
+            message = cimd2_accept_message(request,conn);
+            if (message)
+                list_append(pdata->received, message);
+        }
     }
 
     cimd2_send_response(request, pdata);
@@ -1637,10 +1652,6 @@
     gw_assert(request != NULL);
     gw_assert(operation_can_send(request->operation));
 
-    debug("bb.sms.cimd2", 0, "CIMD2[%s]: sending <%s>",
-          octstr_get_cstr(conn->id),
-          octstr_get_cstr(request->data));
-
     if (pdata->socket < 0) {
         warning(0, "CIMD2[%s]: cimd2_request: socket not open.",
                 octstr_get_cstr(conn->id));
@@ -1651,6 +1662,10 @@
     packet_set_send_sequence(request, pdata);
     packet_set_checksum(request);
 
+    debug("bb.sms.cimd2", 0, "CIMD2[%s]: sending <%s>",
+          octstr_get_cstr(conn->id),
+          octstr_get_cstr(request->data));
+
     ret = octstr_write_to_socket(pdata->socket, request->data);
     if (ret < 0)
         goto io_error;
@@ -1669,7 +1684,7 @@
         octstr_dump(reply->data, 0);
         /* Correct sequence number if server says it was wrong,
          * but only if server's number is sane. */
-        if (reply->seq != request->seq && (reply->seq % 1) == 1) {
+        if (reply->seq != request->seq && (reply->seq % 2) == 1) {
             warning(0, "CIMD2[%s]: correcting sequence number from %ld to %ld.",
                     octstr_get_cstr(conn->id),
                     (long) pdata->send_seq, 
@@ -1867,7 +1882,7 @@
 {
     PrivData *pdata = conn->data;
     struct packet *packet;
-    Octstr *ts;
+    Octstr *ts = NULL;
     int ret;
 
     gw_assert(pdata != NULL);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.