blob: d9d003fc8e9460265408b45ed0352a90e7a8a601 [file] [log] [blame]
Harald Welteccea8dd2016-12-24 10:27:55 +01001/*
2 * (C) 2013-2016 by Harald Welte <laforge@gnumonks.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
Harald Weltef5d6fee2016-01-13 22:29:10 +010019#include <osmocom/core/msgb.h>
Harald Welte84ec50f2016-12-24 10:16:00 +010020#include "protocol/protocol.h"
21#include "protocol/diagcmd.h"
Harald Weltef5d6fee2016-01-13 22:29:10 +010022
23int diag_push_subsys_hdr(struct msgb *msg, uint8_t subsys, uint8_t code)
24{
25 struct diagpkt_subsys_hdr *ssh;
26 ssh = (struct diagpkt_subsys_hdr *) msgb_push(msg, sizeof(*ssh));
27 ssh->command = DIAG_SUBSYS_CMD_F;
28 ssh->subsys_id = subsys;
29 ssh->subsys_cmd_code = code;
30
31 return 0;
32}
Harald Welte2c363752016-12-24 00:19:55 +010033
34#include <sys/time.h>
35#include <osmocom/gsm/gsm_utils.h>
36
37uint32_t diag_ts_to_fn(uint64_t ts)
38{
39 return (ts/204800)%GSM_MAX_FN;
40}
41
42uint32_t diag_ts_to_epoch(uint64_t qd_time)
43{
44 double qd_ts;
45
46 qd_ts = osmo_load64le(&qd_time);
47 qd_ts *= 1.25*256.0/1000.0;
48
49 /* Sanity check on timestamp (year > 2011) */
50 if (qd_ts < 1000000000) {
51 /* Use current time */
52 int rv = -1;
53 struct timeval tv;
54
55 rv = gettimeofday(&tv, NULL);
56 if (0 == rv)
57 return tv.tv_sec;
58 } else {
59 /* Adjust timestamp from GPS to UNIX */
60 qd_ts += 315964800.0;
61 }
62
63 return qd_ts;
64}