gsm: fix CMGS PDU mode length calculation
The first byte of the PDU is the SMSC length, but it's not the padded SMSC length. So we need to subtract the actual byte index of the start of the message from length of the PDU, and since the PDU creation function knows all about where the SMSC address stops and the message begins, just have it return that length instead of making the callers calculate it.
This commit is contained in:
@@ -4770,16 +4770,14 @@ sms_send (MMModemGsmSms *modem,
|
||||
|
||||
if (priv->sms_pdu_mode) {
|
||||
guint8 *pdu;
|
||||
guint pdulen = 0;
|
||||
guint smsclen = 0;
|
||||
guint pdulen = 0, msgstart = 0;
|
||||
char *hex;
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, validity, class, &pdulen, &info->error);
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, validity, class, &pdulen, &msgstart, &info->error);
|
||||
if (!pdu) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
smsclen = pdu[0];
|
||||
|
||||
hex = utils_bin2hexstr (pdu, pdulen);
|
||||
g_free (pdu);
|
||||
@@ -4793,7 +4791,7 @@ sms_send (MMModemGsmSms *modem,
|
||||
}
|
||||
|
||||
/* CMGS length is the size of the PDU without SMSC information */
|
||||
command = g_strdup_printf ("+CMGS=%d\r%s\x1a", pdulen - smsclen, hex);
|
||||
command = g_strdup_printf ("+CMGS=%d\r%s\x1a", pdulen - msgstart, hex);
|
||||
g_free (hex);
|
||||
} else
|
||||
command = g_strdup_printf ("+CMGS=\"%s\"\r%s\x1a", number, text);
|
||||
|
||||
@@ -600,6 +600,8 @@ validity_to_relative (guint validity)
|
||||
* suitable default
|
||||
* @class: unused
|
||||
* @out_pdulen: on success, the size of the returned PDU in bytes
|
||||
* @out_msgstart: on success, the byte index in the returned PDU where the
|
||||
* message starts (ie, skipping the SMSC length byte and address, if present)
|
||||
* @error: on error, filled with the error that occurred
|
||||
*
|
||||
* Constructs a single-part SMS message with the given details, preferring to
|
||||
@@ -615,6 +617,7 @@ sms_create_submit_pdu (const char *number,
|
||||
guint validity,
|
||||
guint class,
|
||||
guint *out_pdulen,
|
||||
guint *out_msgstart,
|
||||
GError **error)
|
||||
{
|
||||
guint8 *pdu;
|
||||
@@ -668,6 +671,9 @@ sms_create_submit_pdu (const char *number,
|
||||
pdu[offset++] = 0x00;
|
||||
}
|
||||
|
||||
if (out_msgstart)
|
||||
*out_msgstart = offset;
|
||||
|
||||
if (validity > 0)
|
||||
pdu[offset] = 1 << 4; /* TP-VP present; format RELATIVE */
|
||||
else
|
||||
|
||||
@@ -28,6 +28,7 @@ guint8 *sms_create_submit_pdu (const char *number,
|
||||
guint validity,
|
||||
guint class,
|
||||
guint *out_pdulen,
|
||||
guint *out_msgstart,
|
||||
GError **error);
|
||||
|
||||
/* For testcases only */
|
||||
|
||||
+15
-10
@@ -488,14 +488,15 @@ test_create_pdu_ucs2_with_smsc (void *f, gpointer d)
|
||||
0x04, 0x42, 0x04, 0x3A, 0x04, 0x30, 0x00, 0x21
|
||||
};
|
||||
guint8 *pdu;
|
||||
guint len = 0;
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &error);
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &msgstart, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pdu);
|
||||
g_assert_cmpint (len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
|
||||
g_assert_cmpint (msgstart, ==, 8);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -513,14 +514,15 @@ test_create_pdu_ucs2_no_smsc (void *f, gpointer d)
|
||||
0x21
|
||||
};
|
||||
guint8 *pdu;
|
||||
guint len = 0;
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &error);
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pdu);
|
||||
g_assert_cmpint (len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
|
||||
g_assert_cmpint (msgstart, ==, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -538,14 +540,15 @@ test_create_pdu_gsm_with_smsc (void *f, gpointer d)
|
||||
0x49, 0x5D, 0xC5, 0x52, 0x20, 0x08, 0x04, 0x02, 0x81, 0x00
|
||||
};
|
||||
guint8 *pdu;
|
||||
guint len = 0;
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &error);
|
||||
pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &msgstart, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pdu);
|
||||
g_assert_cmpint (len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
|
||||
g_assert_cmpint (msgstart, ==, 8);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -562,14 +565,15 @@ test_create_pdu_gsm_no_smsc (void *f, gpointer d)
|
||||
0x02, 0x81, 0x00
|
||||
};
|
||||
guint8 *pdu;
|
||||
guint len = 0;
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &error);
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pdu);
|
||||
g_assert_cmpint (len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
|
||||
g_assert_cmpint (msgstart, ==, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -584,7 +588,7 @@ test_create_pdu_gsm_3 (void *f, gpointer d)
|
||||
0x10
|
||||
};
|
||||
guint8 *pdu;
|
||||
guint len = 0;
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Tests that a 25-character message (where the last septet is packed into
|
||||
@@ -593,11 +597,12 @@ test_create_pdu_gsm_3 (void *f, gpointer d)
|
||||
* leave off the last octet.
|
||||
*/
|
||||
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &error);
|
||||
pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (pdu);
|
||||
g_assert_cmpint (len, ==, sizeof (expected));
|
||||
g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
|
||||
g_assert_cmpint (msgstart, ==, 1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user