1 /*
2  * Copyright (c) 2017 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __SNTP_PKT_H
8 #define __SNTP_PKT_H
9 
10 #include <zephyr/types.h>
11 
12 #define SNTP_LI_MASK   0xC0
13 #define SNTP_VN_MASK   0x38
14 #define SNTP_MODE_MASK 0x07
15 
16 #define SNTP_LI_SHIFT   6
17 #define SNTP_VN_SHIFT   3
18 #define SNTP_MODE_SHIFT 0
19 
20 #define SNTP_GET_LI(x)    ((x & SNTP_LI_MASK) >> SNTP_LI_SHIFT)
21 #define SNTP_GET_VN(x)    ((x & SNTP_VN_MASK) >> SNTP_VN_SHIFT)
22 #define SNTP_GET_MODE(x)  ((x & SNTP_MODE_MASK) >> SNTP_MODE_SHIFT)
23 
24 #define SNTP_SET_LI(x, v)   (x = x | (v << SNTP_LI_SHIFT))
25 #define SNTP_SET_VN(x, v)   (x = x | (v << SNTP_VN_SHIFT))
26 #define SNTP_SET_MODE(x, v) (x = x | (v << SNTP_MODE_SHIFT))
27 
28 struct sntp_pkt {
29 	uint8_t lvm;		/* li, vn, and mode in big endian fashion */
30 	uint8_t stratum;
31 	uint8_t poll;
32 	uint8_t precision;
33 	uint32_t root_delay;
34 	uint32_t root_dispersion;
35 	uint32_t ref_id;
36 	uint32_t ref_tm_s;
37 	uint32_t ref_tm_f;
38 	uint32_t orig_tm_s;	/* Originate timestamp seconds */
39 	uint32_t orig_tm_f;	/* Originate timestamp seconds fraction */
40 	uint32_t rx_tm_s;		/* Receive timestamp seconds */
41 	uint32_t rx_tm_f;		/* Receive timestamp seconds fraction */
42 	uint32_t tx_tm_s;		/* Transmit timestamp seconds */
43 	uint32_t tx_tm_f;		/* Transmit timestamp seconds fraction */
44 } __packed;
45 
46 #endif
47