Re: at2 - support for DLR?

Oded Arbel <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Michael Tung wrote:

> Alright, I guess that would give me a head start.
> Would appreciate it. Will try to get the rest of the code done.
> What do you mean by modifying the UDH? I'm not very
> familiar with that. I thought DLRs through GSM modems comes
> as an unsolicited message to the modem itself?
>  
>  
>  
>
>     ----- Original Message -----
>     *From:* Oded Arbel <mailto:[email protected]>
>     *To:* Michael Tung <mailto:[email protected]>
>     *Cc:* [email protected] <mailto:[email protected]>
>     *Sent:* Saturday, July 13, 2002 1:57 AM
>     *Subject:* Re: at2 - support for DLR?
>
>     Michael Tung wrote:
>
>>     Dear all,
>>      
>>     Has anyone implemented a working DLR support for at2?
>>     Or anyone who can point me in the right way to do it?
>>      
>
>     I have implemented partial DLR support (SMSC_SUCCESS/FAIL) for
>     AT2, and willing to share the code - it you are interested in it.
>     for acheiving better support you need to modify the UDH, which
>     shouldn't be too hard, but I've yet to do that - low priority.
>
Ok, it's not that simple as Andrea pointed out. it shouldn't be hard to do if UDH is already set, but what if UDH has not been set ? setting it will require some of the space reserved for the SM itself, and if the SM is too large after setting the UDH, what then ?

anyway - here is the simple patch attached.

-- 
Oded Arbel
m-Wise mobile solutions
smsc_at2.patch (text/plain, 2.9 KB)
--- kannel-dev/gateway/gw/smsc_at2.c	2002-06-06 17:09:24.000000000 +0000
+++ gateway/gw/smsc_at2.c	2002-07-15 12:53:27.000000000 +0000
@@ -1438,6 +1454,7 @@
     int ret = -1;
     char sc[3];
     int retries = RETRY_SEND;
+    Octstr* dlrmsgid = NULL; // message id for DLR
 
     if (octstr_len(privdata->my_number)) {
         octstr_destroy(msg->sms.sender);
@@ -1456,6 +1473,22 @@
         strcpy(sc, "00");
 
     if (msg_type(msg) == sms) {
+		/* experimental DLR for AT2 : */
+		// calculate DLR msg id
+		dlrmsgid = octstr_format("%ld%d",time(NULL), gw_rand());
+		
+		// remove DLR types we don't currently support
+		msg->sms.dlr_mask &= DLR_SMSC_FAIL | DLR_SMSC_SUCCESS;
+		
+		if (msg->sms.dlr_mask) // anything left ?
+			// create DLR
+			dlr_add(octstr_get_cstr(privdata->conn->id),
+			    octstr_get_cstr(dlrmsgid),
+				octstr_get_cstr(msg->sms.receiver),
+       	     octstr_get_cstr(msg->sms.service),
+	            octstr_get_cstr(msg->sms.dlr_url),
+	            msg->sms.dlr_mask);
+			/* end experimental DLR for AT2 */
         at2_pdu_encode(msg, &pdu[0], privdata);
 
         ret = -99;
@@ -1487,11 +1520,57 @@
             
             if (ret != 0) /* OK only */
                 continue;
+		/* experimental DLR for AT2 : */
+		/* gen DLR_SMSC_SUCCESS */
+		if (msg->sms.dlr_mask & DLR_SMSC_SUCCESS)
+		{
+			Octstr *reply;
+			Msg* dlrmsg;
+			
+			dlrmsg = dlr_find(octstr_get_cstr(privdata->conn->id), 
+				octstr_get_cstr(dlrmsgid),
+				octstr_get_cstr(msg->sms.receiver), /* destination */
+				DLR_SMSC_SUCCESS);
+			
+			if (dlrmsg != NULL)
+			{
+				reply = octstr_create("Success/");
+				octstr_insert(dlrmsg->sms.msgdata, reply, 0);
+				octstr_destroy(reply);			
+				bb_smscconn_receive(privdata->conn, dlrmsg);
+			}
+			else
+				error(0,"Got SMSC_ACK but couldnt find message");
+		}
+		/* end experimental DLR for AT2 */		
             counter_increase(privdata->conn->sent);
             bb_smscconn_sent(privdata->conn, msg);
         }
 
         if (ret != 0) {
+		/* experimental DLR for AT2 : */
+		/* gen DLR_SMSC_FAIL */
+		if (msg->sms.dlr_mask & DLR_SMSC_FAIL)
+		{
+			Octstr *reply;
+			Msg* dlrmsg;
+
+			dlrmsg = dlr_find(
+				octstr_get_cstr(privdata->conn->id),
+				octstr_get_cstr(dlrmsgid),
+				octstr_get_cstr(msg->sms.receiver), DLR_SMSC_FAIL);
+
+			if (dlrmsg != NULL)
+			{
+				reply = octstr_create("Success/");
+				octstr_insert(dlrmsg->sms.msgdata, reply, 0);
+				octstr_destroy(reply);			
+				bb_smscconn_receive(privdata->conn, dlrmsg);
+			}
+			else
+				error(0,"Got SMSC_NACK but couldnt find message");
+		}
+		/* end experimental DLR for AT2 */
             /*
              * no need to do counter_increase(privdata->conn->failed) here, 
              * since bb_smscconn_send_failed() will inc the counter on 
@@ -1500,6 +1579,7 @@
             bb_smscconn_send_failed(privdata->conn, msg, SMSCCONN_FAILED_MALFORMED);
         }
     }
+    O_DESTROY(dlrmsgid);
 }
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.