Harald Welte | f5d6fee | 2016-01-13 22:29:10 +0100 | [diff] [blame] | 1 | #include <osmocom/core/msgb.h> |
Harald Welte | 84ec50f | 2016-12-24 10:16:00 +0100 | [diff] [blame] | 2 | #include "protocol/protocol.h" |
| 3 | #include "protocol/diagcmd.h" |
Harald Welte | f5d6fee | 2016-01-13 22:29:10 +0100 | [diff] [blame] | 4 | |
| 5 | int diag_push_subsys_hdr(struct msgb *msg, uint8_t subsys, uint8_t code) |
| 6 | { |
| 7 | struct diagpkt_subsys_hdr *ssh; |
| 8 | ssh = (struct diagpkt_subsys_hdr *) msgb_push(msg, sizeof(*ssh)); |
| 9 | ssh->command = DIAG_SUBSYS_CMD_F; |
| 10 | ssh->subsys_id = subsys; |
| 11 | ssh->subsys_cmd_code = code; |
| 12 | |
| 13 | return 0; |
| 14 | } |
Harald Welte | 2c36375 | 2016-12-24 00:19:55 +0100 | [diff] [blame] | 15 | |
| 16 | #include <sys/time.h> |
| 17 | #include <osmocom/gsm/gsm_utils.h> |
| 18 | |
| 19 | uint32_t diag_ts_to_fn(uint64_t ts) |
| 20 | { |
| 21 | return (ts/204800)%GSM_MAX_FN; |
| 22 | } |
| 23 | |
| 24 | uint32_t diag_ts_to_epoch(uint64_t qd_time) |
| 25 | { |
| 26 | double qd_ts; |
| 27 | |
| 28 | qd_ts = osmo_load64le(&qd_time); |
| 29 | qd_ts *= 1.25*256.0/1000.0; |
| 30 | |
| 31 | /* Sanity check on timestamp (year > 2011) */ |
| 32 | if (qd_ts < 1000000000) { |
| 33 | /* Use current time */ |
| 34 | int rv = -1; |
| 35 | struct timeval tv; |
| 36 | |
| 37 | rv = gettimeofday(&tv, NULL); |
| 38 | if (0 == rv) |
| 39 | return tv.tv_sec; |
| 40 | } else { |
| 41 | /* Adjust timestamp from GPS to UNIX */ |
| 42 | qd_ts += 315964800.0; |
| 43 | } |
| 44 | |
| 45 | return qd_ts; |
| 46 | } |