[PATCH 5/6] sms: Fix support of negative timezone offsets in gsm340_gen_scts().

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Daniel Willmann dwillmann at sysmocom.de
Wed Mar 26 16:57:40 UTC 2014


Dear Alexander,

On Fri, 2014-03-07 at 21:24, Alexander Chemeris wrote:
> -- 
> Regards,
> Alexander Chemeris.
> CEO, Fairwaves, Inc. / ООО УмРадио
> https://fairwaves.co

> From 44600bbe8d0de88b7fbb2530e12b9122bf6e52df Mon Sep 17 00:00:00 2001
> From: Alexander Chemeris <Alexander.Chemeris at gmail.com>
> Date: Fri, 7 Mar 2014 21:02:46 +0100
> Subject: [PATCH 5/6] sms: Fix support of negative timezone offsets in
>  gsm340_gen_scts().
> 
> ---
>  src/gsm/gsm0411_utils.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gsm/gsm0411_utils.c b/src/gsm/gsm0411_utils.c
> index 6272ba3..e884eca 100644
> --- a/src/gsm/gsm0411_utils.c
> +++ b/src/gsm/gsm0411_utils.c
> @@ -85,7 +85,10 @@ void gsm340_gen_scts(uint8_t *scts, time_t time)
>  	*scts++ = gsm411_bcdify(tm->tm_min);
>  	*scts++ = gsm411_bcdify(tm->tm_sec);
>  #ifdef HAVE_TM_GMTOFF_IN_TM
> -	*scts++ = gsm411_bcdify(tm->tm_gmtoff/(60*15));
> +	if (tm->tm_gmtoff >= 0)
> +		*scts++ = gsm411_bcdify(tm->tm_gmtoff/(60*15));
> +	else
> +		*scts++ = gsm411_bcdify(-tm->tm_gmtoff/(60*15)) | 0x80;
>  #else
>  #warning find a portable way to obtain timezone offset
>  	*scts++ = 0;
> -- 
> 1.7.9.5

after looking through the code and thinking about mktime/timegm some
more I noticed that we actually want to used localtime() instead of
gmtime() in this function. gmtime will always set tm_gmtoff zero (as it
converts it into UTC).

This function could be written without any use of tm_gmtoff by using
both localtime and gmtime, converting these results back to time_t with
mktime and calculating the difference.

I'll send a patch in a an extra mail.


Regards,
Daniel

-- 
- Daniel Willmann <dwillmann at sysmocom.de>       http://www.sysmocom.de/
=======================================================================
* sysmocom - systems for mobile communications GmbH
* Schivelbeiner Str. 5
* 10439 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte




More information about the OpenBSC mailing list