mirror of git://git.sysmocom.de/ofono
smsutil: Make timezone an optional field
This commit is contained in:
parent
7784c5ed62
commit
f6b037661b
|
@ -351,7 +351,8 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
|
||||||
if (in->second > 59)
|
if (in->second > 59)
|
||||||
return FALSE;
|
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;
|
return FALSE;
|
||||||
|
|
||||||
pdu = pdu + *offset;
|
pdu = pdu + *offset;
|
||||||
|
@ -363,6 +364,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[4] = ((in->minute / 10) & 0x0f) | (((in->minute % 10) & 0x0f) << 4);
|
||||||
pdu[5] = ((in->second / 10) & 0x0f) | (((in->second % 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);
|
timezone = abs(in->timezone);
|
||||||
|
|
||||||
pdu[6] = ((timezone / 10) & 0x07) | (((timezone % 10) & 0x0f) << 4);
|
pdu[6] = ((timezone / 10) & 0x07) | (((timezone % 10) & 0x0f) << 4);
|
||||||
|
@ -370,6 +376,7 @@ gboolean sms_encode_scts(const struct sms_scts *in, unsigned char *pdu,
|
||||||
if (in->timezone < 0)
|
if (in->timezone < 0)
|
||||||
pdu[6] |= 0x8;
|
pdu[6] |= 0x8;
|
||||||
|
|
||||||
|
out:
|
||||||
*offset += 7;
|
*offset += 7;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -441,6 +448,8 @@ gboolean sms_decode_scts(const unsigned char *pdu, int len,
|
||||||
if ((out->timezone > MAX_TIMEZONE) || (out->timezone < MIN_TIMEZONE))
|
if ((out->timezone > MAX_TIMEZONE) || (out->timezone < MIN_TIMEZONE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
out->has_timezone = TRUE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,7 @@ struct sms_scts {
|
||||||
guint8 hour;
|
guint8 hour;
|
||||||
guint8 minute;
|
guint8 minute;
|
||||||
guint8 second;
|
guint8 second;
|
||||||
|
gboolean has_timezone;
|
||||||
gint8 timezone;
|
gint8 timezone;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4548,7 +4548,6 @@ static gboolean build_dataobj_datetime_timezone(struct stk_tlv_builder *tlv,
|
||||||
const void *data, gboolean cr)
|
const void *data, gboolean cr)
|
||||||
{
|
{
|
||||||
const struct sms_scts *scts = data;
|
const struct sms_scts *scts = data;
|
||||||
struct sms_scts timestamp;
|
|
||||||
unsigned char value[7];
|
unsigned char value[7];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
unsigned char tag = STK_DATA_OBJECT_TYPE_DATETIME_TIMEZONE;
|
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)
|
if (scts->month == 0 && scts->day == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* Time zone information is optional */
|
if (sms_encode_scts(scts, value, &offset) != TRUE)
|
||||||
if (scts->timezone == (gint8) 0xff) {
|
return FALSE;
|
||||||
memcpy(×tamp, scts, sizeof(timestamp));
|
|
||||||
timestamp.timezone = 0;
|
|
||||||
if (sms_encode_scts(×tamp, value, &offset) != TRUE)
|
|
||||||
return FALSE;
|
|
||||||
value[6] = 0xff;
|
|
||||||
} else
|
|
||||||
if (sms_encode_scts(scts, value, &offset) != TRUE)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
|
return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
|
||||||
stk_tlv_builder_append_bytes(tlv, value, 7) &&
|
stk_tlv_builder_append_bytes(tlv, value, 7) &&
|
||||||
|
|
Loading…
Reference in New Issue