Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/3] Make timezone an optional field
Date: Tue, 30 Nov 2010 18:44:49 +0800	[thread overview]
Message-ID: <1291113890-24465-2-git-send-email-yang.gu@intel.com> (raw)
In-Reply-To: <1291113890-24465-1-git-send-email-yang.gu@intel.com>

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

---
 src/smsutil.c |   11 ++++++++++-
 src/smsutil.h |    1 +
 src/stkutil.c |   13 ++-----------
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index 644e3e0..20af30a 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -346,7 +346,8 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
 	if (in->second > 59)
 		return FALSE;
 
-	if ((in->timezone > MAX_TIMEZONE) || (in->timezone < MIN_TIMEZONE))
+	if ((in->timezone > MAX_TIMEZONE || in->timezone < MIN_TIMEZONE) &&
+			in->has_timezone == TRUE)
 		return FALSE;
 
 	pdu = pdu + *offset;
@@ -358,6 +359,11 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
 	pdu[4] = ((in->minute / 10) & 0x0f) | (((in->minute % 10) & 0x0f) << 4);
 	pdu[5] = ((in->second / 10) & 0x0f) | (((in->second % 10) & 0x0f) << 4);
 
+	if (in->has_timezone == FALSE) {
+		pdu[6] = 0xff;
+		goto out;
+	}
+
 	timezone = abs(in->timezone);
 
 	pdu[6] = ((timezone / 10) & 0x07) | (((timezone % 10) & 0x0f) << 4);
@@ -365,6 +371,7 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
 	if (in->timezone < 0)
 		pdu[6] |= 0x8;
 
+out:
 	*offset += 7;
 
 	return TRUE;
@@ -436,6 +443,8 @@ gboolean sms_decode_scts(const unsigned char *pdu, int len,
 	if ((out->timezone > MAX_TIMEZONE) || (out->timezone < MIN_TIMEZONE))
 		return FALSE;
 
+	out->has_timezone = TRUE;
+
 	return TRUE;
 }
 
diff --git a/src/smsutil.h b/src/smsutil.h
index 4b05313..4b6159f 100644
--- a/src/smsutil.h
+++ b/src/smsutil.h
@@ -223,6 +223,7 @@ struct sms_scts {
 	guint8 hour;
 	guint8 minute;
 	guint8 second;
+	gboolean has_timezone;
 	gint8 timezone;
 };
 
diff --git a/src/stkutil.c b/src/stkutil.c
index a211462..01a0021 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -4548,7 +4548,6 @@ static gboolean build_dataobj_datetime_timezone(struct stk_tlv_builder *tlv,
 						const void *data, gboolean cr)
 {
 	const struct sms_scts *scts = data;
-	struct sms_scts timestamp;
 	unsigned char value[7];
 	int offset = 0;
 	unsigned char tag = STK_DATA_OBJECT_TYPE_DATETIME_TIMEZONE;
@@ -4556,16 +4555,8 @@ static gboolean build_dataobj_datetime_timezone(struct stk_tlv_builder *tlv,
 	if (scts->month == 0 && scts->day == 0)
 		return TRUE;
 
-	/* Time zone information is optional */
-	if (scts->timezone == (gint8) 0xff) {
-		memcpy(&timestamp, scts, sizeof(timestamp));
-		timestamp.timezone = 0;
-		if (sms_encode_scts(&timestamp, value, &offset) != TRUE)
-			return FALSE;
-		value[6] = 0xff;
-	} else
-		if (sms_encode_scts(scts, value, &offset) != TRUE)
-			return FALSE;
+	if (sms_encode_scts(scts, value, &offset) != TRUE)
+		return FALSE;
 
 	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
 		stk_tlv_builder_append_bytes(tlv, value, 7) &&
-- 
1.7.2.3


  reply	other threads:[~2010-11-30 10:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-30 10:44 [PATCH 1/3] smsutil: Change the range of time zone Yang Gu
2010-11-30 10:44 ` Yang Gu [this message]
2010-12-08 14:05   ` [PATCH 2/3] Make timezone an optional field Denis Kenzior
2010-11-30 10:44 ` [PATCH 3/3] stk: Handle provide local info proactive command Yang Gu
2010-11-30 20:43   ` Jeevaka.Badrappan
2010-12-01  2:03     ` Gu, Yang
2010-12-08 14:05   ` Denis Kenzior
2010-12-07 13:39 ` [PATCH 1/3] smsutil: Change the range of time zone Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291113890-24465-2-git-send-email-yang.gu@intel.com \
    --to=yang.gu@intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox