Index: gw/smppbox.c
===================================================================
--- gw/smppbox.c	(revision 47)
+++ gw/smppbox.c	(working copy)
@@ -1748,7 +1748,7 @@
     Boxc *box = arg;
     SMPP_PDU *pdu;
     List *pdulist;
-    int dreport;
+    int dreport, errcode;
     Boxc *receiver_box;
     char id[UUID_STR_LEN + 1];
     Octstr *msgid;
@@ -1784,6 +1784,7 @@
 	    uuid_unparse(msg->ack.id, id);
 	    msgid = octstr_create(id);
 	    pdu = dict_get(box->msg_acks, msgid);
+	    errcode = SMPP_ESME_RMSGQFUL; /* in case we get ack_failed_tmp */
 	    if (pdu) {
 		switch (msg->ack.nack) {
 		case ack_buffered:
@@ -1791,17 +1792,19 @@
 			/* we can send the submit_sm_resp as-is */
 			break;
 		case ack_failed:
+			errcode = SMPP_ESME_RSUBMITFAIL;
+			/* no break */
 		case ack_failed_tmp:
 			switch (pdu->type) {
 			case submit_sm_resp:
 				octstr_destroy(pdu->u.submit_sm_resp.message_id);
 				pdu->u.submit_sm_resp.message_id = NULL;
-				pdu->u.submit_sm_resp.command_status = SMPP_ESME_RSUBMITFAIL;
+				pdu->u.submit_sm_resp.command_status = errcode;
 				break;
 			case data_sm_resp:
 				octstr_destroy(pdu->u.data_sm_resp.message_id);
 				pdu->u.data_sm_resp.message_id = NULL;
-				pdu->u.data_sm_resp.command_status = SMPP_ESME_RSUBMITFAIL;
+				pdu->u.data_sm_resp.command_status = errcode;
 				break;
 			default:
 				debug("smppbox", 0, "Getting failure ack on unexpected pdu: %i.", pdu->type);
