Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 1/2] smsutil: sms_decode() allow to pass sms with unknown TPDU size
@ 2017-05-16 15:49 Alexander Couzens
  2017-05-16 15:49 ` [PATCH 2/2] qmimodem: receive & delete sms from NV storage on 'Powered' Alexander Couzens
  2017-05-16 17:49 ` [PATCH 1/2] smsutil: sms_decode() allow to pass sms with unknown TPDU size Denis Kenzior
  0 siblings, 2 replies; 5+ messages in thread
From: Alexander Couzens @ 2017-05-16 15:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2032 bytes --]

Certain modems (QMI based) only return a PDU length, but without
the length of the TPDU.
Without passing this information over ofono_sms_deliver_notify() down
to sms_decode(), sms_decode() will fail, as it try to interpret the
SC header as PDU header.
---

I'm not quite sure this is the best way to implement this.

a) adding a flag to ofono_sms_deliver_notify() would break the api
b) export sms_decode_address_field() which is part of smsutil.h would mean
   using this function only to get the length of TPDU and throw away the
   result (address), which is later called a second time.
c) add another function to cover this case is also bloated


 include/sms.h | 2 ++
 src/smsutil.c | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/sms.h b/include/sms.h
index e9260561..602042d2 100644
--- a/include/sms.h
+++ b/include/sms.h
@@ -60,6 +60,8 @@ struct ofono_sms_driver {
 				ofono_sms_bearer_set_cb_t, void *data);
 };
 
+/* unknown tpdu length, but contains a SC header */
+#define TPDU_UNKNOWN_WITH_SC -2
 void ofono_sms_deliver_notify(struct ofono_sms *sms, const unsigned char *pdu,
 				int len, int tpdu_len);
 void ofono_sms_status_notify(struct ofono_sms *sms, const unsigned char *pdu,
diff --git a/src/smsutil.c b/src/smsutil.c
index 24dcfaa7..d4b4a0d4 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -33,6 +33,7 @@
 #include <unistd.h>
 
 #include <glib.h>
+#include <ofono/sms.h>
 
 #include "util.h"
 #include "storage.h"
@@ -1545,7 +1546,12 @@ gboolean sms_decode(const unsigned char *pdu, int len, gboolean outgoing,
 
 	memset(out, 0, sizeof(*out));
 
-	if (tpdu_len < len) {
+	if (tpdu_len == TPDU_UNKNOWN_WITH_SC) {
+		/* unknown TPDU length but prefixed with SC */
+		sms_decode_address_field(pdu, len, &offset, TRUE,
+				&out->sc_addr);
+		tpdu_len = len - offset;
+	} else if (tpdu_len < len) {
 		if (!sms_decode_address_field(pdu, len, &offset,
 						TRUE, &out->sc_addr))
 			return FALSE;
-- 
2.13.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-16 23:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-16 15:49 [PATCH 1/2] smsutil: sms_decode() allow to pass sms with unknown TPDU size Alexander Couzens
2017-05-16 15:49 ` [PATCH 2/2] qmimodem: receive & delete sms from NV storage on 'Powered' Alexander Couzens
2017-05-16 18:06   ` Denis Kenzior
2017-05-16 17:49 ` [PATCH 1/2] smsutil: sms_decode() allow to pass sms with unknown TPDU size Denis Kenzior
2017-05-16 23:01   ` Alexander Couzens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox