Index: gw/smsc/smsc_smpp.c
===================================================================
--- gw/smsc/smsc_smpp.c	(revision 36)
+++ gw/smsc/smsc_smpp.c	(working copy)
@@ -938,6 +938,9 @@
     else if (DLR_IS_FAIL(msg->sms.dlr_mask) && !DLR_IS_SUCCESS(msg->sms.dlr_mask))
         pdu->u.submit_sm.registered_delivery = 2;
 
+    if (DLR_ASK_INTERMEDIATE(msg->sms.dlr_mask))
+        pdu->u.submit_sm.registered_delivery += 16;
+
     /* set priority */
     if (msg->sms.priority >= 0 && msg->sms.priority <= 3)
         pdu->u.submit_sm.priority_flag = msg->sms.priority;
@@ -1269,7 +1272,7 @@
             /* first try sscanf way if thus failed then old way */
             ret = sscanf(octstr_get_cstr(respstr),
                          "id:%64[^s] sub:%d dlvrd:%d submit date:%12[0-9] done "
-                         "date:%12[0-9] stat:%10[^t^e] err:%3[0-9]",
+                         "date:%12[0-9] stat:%10[^t^e] err:%3[^t]",
                          id_cstr, &sub, &dlrvrd, sub_d_cstr, done_d_cstr,
                          stat_cstr, err_cstr);
             if (ret == 7) {
@@ -1448,7 +1451,7 @@
              *       only on bits 2-5 (some SMSC's send 0x44, and it's
              *       spec. conforme)
              */
-           if (pdu->u.data_sm.esm_class & (0x04|0x08)) {
+           if (pdu->u.data_sm.esm_class & (0x04|0x08|0x20)) {
                 debug("bb.sms.smpp",0,"SMPP[%s] handle_pdu, got DLR",
                       octstr_get_cstr(smpp->conn->id));
                 dlrmsg = handle_dlr(smpp, pdu->u.data_sm.source_addr, NULL, pdu->u.data_sm.message_payload,
@@ -1504,7 +1507,7 @@
              *       only on bits 2-5 (some SMSC's send 0x44, and it's
              *       spec. conforme)
              */
-            if (pdu->u.deliver_sm.esm_class & (0x04|0x08)) {
+            if (pdu->u.deliver_sm.esm_class & (0x04|0x08|0x20)) {
 
                 debug("bb.sms.smpp",0,"SMPP[%s] handle_pdu, got DLR",
                       octstr_get_cstr(smpp->conn->id));
Index: gw/smsbox.c
===================================================================
--- gw/smsbox.c	(revision 38)
+++ gw/smsbox.c	(working copy)
@@ -2225,9 +2225,9 @@
 	msg->sms.dlr_url = octstr_create("");
     }
 
-    if ( dlr_mask < -1 || dlr_mask > 31 ) { /* 00011111 */
-	returnerror = octstr_create("DLR-Mask field misformed, rejected");
-	goto field_error;
+    if ( dlr_mask < -1 || dlr_mask > 63 ) { /* 00111111 */
+    returnerror = octstr_create("DLR-Mask field misformed, rejected");
+    goto field_error;
     }
     msg->sms.dlr_mask = dlr_mask;
     
Index: gw/dlr.h
===================================================================
--- gw/dlr.h	(revision 36)
+++ gw/dlr.h	(working copy)
@@ -73,6 +73,7 @@
 #define	DLR_BUFFERED        0x04
 #define	DLR_SMSC_SUCCESS    0x08
 #define	DLR_SMSC_FAIL       0x10
+#define DLR_INTERMEDIATE    0x20
 
 #define DLR_IS_DEFINED(dlr)          (dlr != DLR_UNDEFINED)
 #define DLR_IS_ENABLED(dlr)          (DLR_IS_DEFINED(dlr) && (dlr & (DLR_SUCCESS | DLR_FAIL | DLR_BUFFERED | DLR_SMSC_SUCCESS | DLR_SMSC_FAIL)))
@@ -85,6 +86,7 @@
 #define DLR_IS_BUFFERED(dlr)         (DLR_IS_DEFINED(dlr) && (dlr & DLR_BUFFERED))
 #define DLR_IS_SMSC_SUCCESS(dlr)     (DLR_IS_DEFINED(dlr) && (dlr & DLR_SMSC_SUCCESS))
 #define DLR_IS_SMSC_FAIL(dlr)        (DLR_IS_DEFINED(dlr) && (dlr & DLR_SMSC_FAIL))
+#define DLR_ASK_INTERMEDIATE(dlr)    (DLR_IS_DEFINED(dlr) && (dlr & DLR_INTERMEDIATE))
 
 /* DLR initialization routine (abstracted) */
 void dlr_init(Cfg *cfg);
