aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-01-18 15:26:12 -0600
committerDan Williams <dcbw@redhat.com>2012-01-18 15:26:12 -0600
commit5c561995aacdab2b29f8eabf38ad8703eec75cab (patch)
tree0fc65e9f005883587c5896d129616ca7254b0b36 /src
parentd51ff9ac07973701ee790f57c82a99cc25d92ab1 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/mm-generic-gsm.c8
-rw-r--r--src/mm-sms-utils.c6
-rw-r--r--src/mm-sms-utils.h1
-rw-r--r--src/tests/test-sms.c25
4 files changed, 25 insertions, 15 deletions
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 3afe4950..3a95a6b0 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -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);
diff --git a/src/mm-sms-utils.c b/src/mm-sms-utils.c
index fc493dc4..025a19dc 100644
--- a/src/mm-sms-utils.c
+++ b/src/mm-sms-utils.c
@@ -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
diff --git a/src/mm-sms-utils.h b/src/mm-sms-utils.h
index 8455df9a..5c1c026a 100644
--- a/src/mm-sms-utils.h
+++ b/src/mm-sms-utils.h
@@ -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 */
diff --git a/src/tests/test-sms.c b/src/tests/test-sms.c
index a6dda609..11118c06 100644
--- a/src/tests/test-sms.c
+++ b/src/tests/test-sms.c
@@ -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