Skip to contentSkip to conversation

smsutil: Change the range of time zone

PATCH In review Yang Gu 4 participants 8 messages Nov 30, 2010 – Dec 8, 2010

lore
Share & tools
lore

Yang Gu

author
#0 lore raw

PATCH 1/3 smsutil: Change the range of time zone

---
 src/smsutil.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
src/smsutil.c +9 -2
index b06e9bf..644e3e0 100644
@@ -51,6 +51,13 @@
 #define SMS_ADDR_FMT "%24[0-9A-F]"
 #define SMS_MSGID_FMT "%40[0-9A-F]"
 
+/*
+ * Time zone accounts for daylight saving time, and the two extreme time
+ * zones on earth are UTC-12 and UTC+14.
+ */
+#define MAX_TIMEZONE 56
+#define MIN_TIMEZONE -48
+
 static GSList *sms_assembly_add_fragment_backup(struct sms_assembly *assembly,
 					const struct sms *sms, time_t ts,
 					const struct sms_address *addr,
@@ -339,7 +346,7 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
 	if (in->second > 59)
 		return FALSE;
 
-	if ((in->timezone > 12*4-1) || (in->timezone < -(12*4-1)))
+	if ((in->timezone > MAX_TIMEZONE) || (in->timezone < MIN_TIMEZONE))
 		return FALSE;
 
 	pdu = pdu + *offset;
@@ -426,7 +433,7 @@ gboolean sms_decode_scts(const unsigned char *pdu, int len,
 	if (oct & 0x08)
 		out->timezone = out->timezone * -1;
 
-	if ((out->timezone > 12*4-1) || (out->timezone < -(12*4-1)))
+	if ((out->timezone > MAX_TIMEZONE) || (out->timezone < MIN_TIMEZONE))
 		return FALSE;
 
 	return TRUE;
Signature · 1 line
1.7.2.3
author
#1 lore raw

PATCH 2/3 Make timezone an optional field

---
 src/smsutil.c |   11 ++++++++++-
 src/smsutil.h |    1 +
 src/stkutil.c |   13 ++-----------
 3 files changed, 13 insertions(+), 12 deletions(-)
src/smsutil.c +10 -1
index 644e3e0..20af30a 100644
@@ -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;
 }
 
src/smsutil.h +1 -0
index 4b05313..4b6159f 100644
@@ -223,6 +223,7 @@ struct sms_scts {
 	guint8 hour;
 	guint8 minute;
 	guint8 second;
+	gboolean has_timezone;
 	gint8 timezone;
 };
 
src/stkutil.c +2 -11
index a211462..01a0021 100644
@@ -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) &&
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [PATCH 2/3] Make timezone an optional field

Hi Yang,

Quoted 6 lines · Yang Gu
---
 src/smsutil.c |   11 ++++++++++-
 src/smsutil.h |    1 +
 src/stkutil.c |   13 ++-----------
 3 files changed, 13 insertions(+), 12 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

author
#3 lore raw

PATCH 3/3 stk: Handle provide local info proactive command

In reply to Yang Gu
---
 src/stk.c |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)
src/stk.c +77 -0
index a4abb7d..08353f2 100644
@@ -26,6 +26,7 @@
 #define _GNU_SOURCE
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <stdint.h>
 
 #include <glib.h>
@@ -1995,6 +1996,77 @@ static gboolean handle_command_refresh(const struct stk_command *cmd,
 	return TRUE;
 }
 
+static void get_time(struct stk_response *rsp)
+{
+	time_t now;
+	struct tm *t;
+
+	time(&now);
+	t = localtime(&now);
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+
+	if (t->tm_year > 100)
+		rsp->provide_local_info.datetime.year = t->tm_year - 100;
+	else
+		rsp->provide_local_info.datetime.year = t->tm_year;
+
+	rsp->provide_local_info.datetime.month = t->tm_mon + 1;
+	rsp->provide_local_info.datetime.day = t->tm_mday;
+	rsp->provide_local_info.datetime.hour = t->tm_hour;
+	rsp->provide_local_info.datetime.minute = t->tm_min;
+	rsp->provide_local_info.datetime.second = t->tm_sec;
+	rsp->provide_local_info.datetime.timezone = t->tm_gmtoff / 900;
+	rsp->provide_local_info.datetime.has_timezone = TRUE;
+
+	return;
+}
+
+static void get_lang(struct stk_response *rsp, struct ofono_stk *stk)
+{
+	char *l;
+	char lang[3];
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+	l = getenv("LANG");
+	if (l == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		goto out;
+	}
+
+	memcpy(lang, l, 2);
+	lang[2] = '\0';
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+	rsp->provide_local_info.language = lang;
+
+out:
+	if (stk_respond(stk, rsp, stk_command_cb))
+		stk_command_cb(&failure, stk);
+}
+
+static gboolean handle_command_provide_local_info(const struct stk_command *cmd,
+				struct stk_response *rsp, struct ofono_stk *stk)
+{
+	switch (cmd->qualifier) {
+	case 3:
+		DBG("Date, time and time zone");
+		get_time(rsp);
+		return TRUE;
+
+	case 4:
+		DBG("Language setting");
+		get_lang(rsp, stk);
+		return FALSE;
+
+	default:
+		ofono_info("Unsupported Provide Local Info qualifier: %d",
+				cmd->qualifier);
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		return TRUE;
+	}
+}
+
 static void send_dtmf_cancel(struct ofono_stk *stk)
 {
 	struct ofono_voicecall *vc = NULL;
@@ -2427,6 +2499,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_PROVIDE_LOCAL_INFO:
+		respond = handle_command_provide_local_info(stk->pending_cmd,
+								&rsp, stk);
+		break;
+
 	case STK_COMMAND_TYPE_SEND_DTMF:
 		respond = handle_command_send_dtmf(stk->pending_cmd,
 							&rsp, stk);
Signature · 1 line
1.7.2.3
#4 lore raw

RE: [PATCH 3/3] stk: Handle provide local info proactive command

Hi Yang,

Quoted 13 lines
src/stk.c +11 -0
+static void get_time(struct stk_response *rsp) {
+	time_t now;
+	struct tm *t;
+
+	time(&now);
+	t = localtime(&now);
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+
+	if (t->tm_year > 100)
+		rsp->provide_local_info.datetime.year = 

t->tm_year - 100;

src/stk.c static gboolean handle_command_refresh(const struct stk_command *cmd, · line 2013

Quoted 3 lines
src/stk.c +3 -0
+	else
+		rsp->provide_local_info.datetime.year = t->tm_year;
+

Incase of error, localtime shall return a null pointer. I think its better to add the NULL check.

Regards,
Jeevaka

#5 lore raw

RE: [PATCH 3/3] stk: Handle provide local info proactive command

Hi Jeevaka,

Quoted 21 lines

-----Original Message-----
From: ofono-bounces(a)ofono.org [mailto:ofono-bounces(a)ofono.org] On Behalf Of Jeevaka.Badrappan(a)elektrobit.com
Sent: Wednesday, December 01, 2010 4:43 AM
To: ofono(a)ofono.org
Subject: RE: [PATCH 3/3] stk: Handle provide local info proactive command

Hi Yang,

Quoted 11 lines
src/stk.c +10 -0
+static void get_time(struct stk_response *rsp) {
+	time_t now;
+	struct tm *t;
+
+	time(&now);
+	t = localtime(&now);
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+
+	if (t->tm_year > 100)
Quoted 8 lines

src/stk.c static gboolean handle_command_refresh(const struct stk_command *cmd, · line 2013

Quoted 5 lines
(quoted diff) +1 -0
+		rsp->provide_local_info.datetime.year =

t->tm_year - 100;

src/stk.c +3 -0
+	else
+		rsp->provide_local_info.datetime.year = t->tm_year;
+

Incase of error, localtime shall return a null pointer. I think its better to add the NULL check.

Thanks for the comment. I have sent out the modified version.

Regards,
-Yang

#6 lore raw

Re: [PATCH 3/3] stk: Handle provide local info proactive command

In reply to Yang Gu

Hi Yang,

Quoted 4 lines · Yang Gu
---
 src/stk.c |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#7 lore raw
In reply to Yang Gu

Hi Yang,

Quoted 4 lines · Yang Gu
---
 src/smsutil.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis