
project hardware/ril/
diff --git a/muxgsm-ril/atchannel.c b/muxgsm-ril/atchannel.c
index 6094e74..59fe222 100644
--- a/muxgsm-ril/atchannel.c
+++ b/muxgsm-ril/atchannel.c
@@ -628,9 +628,24 @@ static int handleControl (unsigned char *frame, int length)
     return 0;
 }
 
+int convertHexStringtoI(char c)
+{
+    if (c >= 'A' && c<='F') {
+        return c -'A' + 10;
+    }
+    else if (c >= 'a' && c<= 'f') {
+        return c - 'a' + 10;
+    }
+    else if (c >= '0' && c <= '9') {
+        return c - '0';
+    }
+    return -1;
+}
 
 static int handleCommand (int channel, char *buf)
 {
+    int pduDataLength = 0;
+    int pduSMSCLength = 0;
     do {
         /* Isolate the line
          */
@@ -656,7 +671,9 @@ static int handleCommand (int channel, char *buf)
             LOGD("MUX SMS: hasCRLF=%d, text len=%d, sms len=%d",
                  hasCRLF, strlen(smsText), s_chanData[channel].lenSMS);
 
-            if (strlen(smsText) >= s_chanData[channel].lenSMS) {
+            pduSMSCLength = convertHexStringtoI(smsText[0]) * 16 + convertHexStringtoI(smsText[1]) + 1;
+            pduDataLength = strlen(smsText) - pduSMSCLength * 2;
+            if (pduDataLength >= s_chanData[channel].lenSMS) {
                 if (s_unsolHandler)
                     s_unsolHandler (channel, s_chanData[channel].cmdSMS, smsText);
                 free(s_chanData[channel].cmdSMS);
