ieee1588_types.h 6.25 KB
Newer Older
1 2 3 4 5
/*
 * FIXME header
 * Structs defined in IEEE Std 1588-2008
 */

6 7
#ifndef __PPTP_IEEE_1588_TYPES_H__
#define __PPTP_IEEE_1588_TYPES_H__
8 9 10 11

#include <stdint.h>

typedef enum {FALSE=0, TRUE} Boolean; /* FIXME really needed? */
12 13 14 15 16 17 18
typedef uint8_t		Octet;
typedef int8_t		Integer8;
typedef int16_t		Integer16;
typedef int32_t		Integer32;
typedef uint8_t		UInteger8;
typedef uint16_t	UInteger16;
typedef uint32_t	UInteger32;
19
/* Enumerations are unsigned, see 5.4.2, page 15 */
20 21 22 23 24
typedef uint16_t	Enumeration16;
typedef uint8_t		Enumeration8;
typedef uint8_t		Enumeration4;
typedef uint8_t		UInteger4;
typedef uint8_t		Nibble;
25

26 27 28 29
#define PP_CLOCK_IDENTITY_LENGTH 8

/* FIXME: each struct must be aligned for lower memory usage */

30
typedef struct {
31 32
	uint32_t	lsb;
	uint16_t	msb;
33 34 35
} UInteger48;

typedef struct {
36 37
	uint32_t	lsb;
	int32_t		msb;
38 39 40
} Integer64;

typedef struct {
41
	Integer64	scaledNanoseconds;
42 43 44
} TimeInterval;

typedef struct  {
45 46
	UInteger48	secondsField;
	UInteger32	nanosecondsField;
47 48
} Timestamp;

Aurelio Colosimo's avatar
Aurelio Colosimo committed
49
typedef struct {
50 51
	Integer32	seconds;
	Integer32	nanoseconds;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
52 53
} TimeInternal;

54
typedef Octet		ClockIdentity[PP_CLOCK_IDENTITY_LENGTH];
55 56

typedef struct {
57 58
	ClockIdentity	clockIdentity;
	UInteger16	portNumber;
59 60 61
} PortIdentity;

typedef struct {
62 63 64
	Enumeration16	networkProtocol;
	UInteger16	adressLength;
	Octet		*adressField;
65 66 67
} PortAdress;

typedef struct {
68 69 70
	UInteger8	clockClass;
	Enumeration8	clockAccuracy;
	UInteger16	offsetScaledLogVariance;
71 72 73
} ClockQuality;

typedef struct {
74 75 76
	Enumeration16	tlvType;
	UInteger16	lengthField;
	Octet		*valueField;
77 78 79
} TLV;

typedef struct {
80 81
	UInteger8	lengthField;
	Octet		*textField;
82 83 84
} PTPText;

typedef struct {
85 86 87 88 89 90
	UInteger16	faultRecordLength;
	Timestamp	faultTime;
	Enumeration8	severityCode;
	PTPText		faultName;
	PTPText		faultValue;
	PTPText		faultDescription;
91 92 93 94 95
} FaultRecord;


/* Common Message header (table 18, page 124) */
typedef struct {
96 97 98 99 100 101 102 103 104 105 106
	Nibble		transportSpecific;
	Enumeration4	messageType;
	UInteger4	versionPTP;
	UInteger16	messageLength;
	UInteger8	domainNumber;
	Octet		flagField[2];
	Integer64	correctionfield;
	PortIdentity	sourcePortIdentity;
	UInteger16	sequenceId;
	UInteger8	controlField;
	Integer8	logMessageInterval;
107 108 109 110
} MsgHeader;

/* Announce Message (table 25, page 129) */
typedef struct {
111 112 113 114 115 116 117 118
	Timestamp	originTimestamp;
	Integer16	currentUtcOffset;
	UInteger8	grandmasterPriority1;
	ClockQuality	grandmasterClockQuality;
	UInteger8	grandmasterPriority2;
	ClockIdentity	grandmasterIdentity;
	UInteger16	stepsRemoved;
	Enumeration8	timeSource;
119 120 121 122 123 124 125 126 127
} MsgAnnounce;

/* Sync Message (table 26, page 129) */
typedef struct {
	Timestamp originTimestamp;
} MsgSync;

/* DelayReq Message (table 26, page 129) */
typedef struct {
128
	Timestamp	originTimestamp;
129 130 131 132
} MsgDelayReq;

/* DelayResp Message (table 27, page 130) */
typedef struct {
133
	Timestamp	preciseOriginTimestamp;
134 135 136 137 138
} MsgFollowUp;


/* DelayResp Message (table 28, page 130) */
typedef struct {
139 140
	Timestamp	receiveTimestamp;
	PortIdentity	requestingPortIdentity;
141 142 143 144
} MsgDelayResp;

/* PdelayReq Message (table 29, page 131) */
typedef struct {
145
	Timestamp	originTimestamp;
146 147 148 149 150

} MsgPDelayReq;

/* PdelayResp Message (table 30, page 131) */
typedef struct {
151 152
	Timestamp	requestReceiptTimestamp;
	PortIdentity	requestingPortIdentity;
153
} MsgPDelayResp;
154 155 156

/* PdelayRespFollowUp Message (table 31, page 132) */
typedef struct {
157 158
	Timestamp	responseOriginTimestamp;
	PortIdentity	requestingPortIdentity;
159
} MsgPDelayRespFollowUp;
160 161 162

/* Signaling Message (table 33, page 133) */
typedef struct {
163 164
	PortIdentity	targetPortIdentity;
	char		*tlv;
165 166 167 168
} MsgSignaling;

/* Management Message (table 37, page 137) */
typedef struct {
169 170 171 172 173
	PortIdentity	targetPortIdentity;
	UInteger8	startingBoundaryHops;
	UInteger8	boundaryHops;
	Enumeration4	actionField;
	char		*tlv;
174 175
} MsgManagement;

Aurelio Colosimo's avatar
Aurelio Colosimo committed
176 177 178 179 180


/* Default Data Set */
typedef struct {
	/* Static */
181 182 183
	Boolean		twoStepFlag;
	ClockIdentity	clockIdentity;
	UInteger16	numberPorts;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
184
	/* Dynamic */
185
	ClockQuality	clockQuality;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
186
	/* Configurable */
187 188 189 190
	UInteger8	priority1;
	UInteger8	priority2;
	UInteger8	domainNumber;
	Boolean		slaveOnly;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
191 192 193 194 195
} DSDefault;

/* Current Data Set */
typedef struct {
	/* Dynamic */
196 197 198
	UInteger16	stepsRemoved;
	TimeInternal	offsetFromMaster;
	TimeInternal	meanPathDelay;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
199 200 201 202 203
} DSCurrent;

/* Parent Data Set */
typedef struct {
	/* Dynamic */
204 205 206 207 208 209 210 211
	PortIdentity	parentPortIdentity;
	Boolean		parentStats;
	UInteger16	observedParentOffsetScaledLogVariance;
	Integer32	observedParentClockPhaseChangeRate;
	ClockIdentity	grandmasterIdentity;
	ClockQuality	grandmasterClockQuality;
	UInteger8	grandmasterPriority1;
	UInteger8	grandmasterPriority2;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
212 213 214 215 216
} DSParent;

/* Port Data set */
typedef struct {
	/* Static */
217
	PortIdentity	portIdentity;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
218
	/* Dynamic */
219 220 221
	Enumeration8	portState;
	Integer8	logMinDelayReqInterval;
	TimeInternal	peerMeanPathDelay;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
222
	/* Configurable */
223 224 225 226 227 228
	Integer8	logAnnounceInterval;
	UInteger8	announceReceiptTimeout;
	Integer8	logSyncInterval;
	Enumeration8	delayMechanism;
	Integer8	logMinPdelayReqInterval;
	UInteger4	versionNumber;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
229 230 231 232 233
} DSPort;

/* Time Properties Data Set */
typedef struct {
	/* Dynamic */
234 235 236 237 238 239 240 241
	Integer16	currentUtcOffset;
	Boolean	currentUtcOffsetValid;
	Boolean	leap59;
	Boolean	leap61;
	Boolean	timeTraceable;
	Boolean	frequencyTraceable;
	Boolean	ptpTimescale;
	Enumeration8	timeSource;
Aurelio Colosimo's avatar
Aurelio Colosimo committed
242 243
} DSTimeProperties;

244 245
/* Enumeration States (table 8, page 73) */
enum pp_std_states {
246
	PPS_END_OF_TABLE	= 0,
247 248 249 250 251 252 253 254 255 256 257 258
	PPS_INITIALIZING,
	PPS_FAULTY,
	PPS_DISABLED,
	PPS_LISTENING,
	PPS_PRE_MASTER,
	PPS_MASTER,
	PPS_PASSIVE,
	PPS_UNCALIBRATED,
	PPS_SLAVE,
};

enum pp_std_messages {
259
	PPM_SYNC		= 0x0,
260 261 262
	PPM_DELAY_REQ,
	PPM_PDELAY_REQ,
	PPM_PDELAY_RESP,
263
	PPM_FOLLOW_UP		= 0x8,
264 265 266 267 268 269 270 271 272
	PPM_DELAY_RESP,
	PPM_PDELAY_RESP_FOLLOW_UP,
	PPM_ANNOUNCE,
	PPM_SIGNALING,
	PPM_MANAGEMENT,
};

/* Enumeration Domain Number (table 2, page 41) */
enum ENDomainNumber {
273
	DFLT_DOMAIN_NUMBER	= 0,
274 275 276 277 278 279 280
	ALT1_DOMAIN_NUMBER,
	ALT2_DOMAIN_NUMBER,
	ALT3_DOMAIN_NUMBER
};

/* Enumeration Network Protocol (table 3, page 46) */
enum ENNetworkProtocol {
281
	UDP_IPV4	= 1,
282 283 284 285 286 287 288 289
	UDP_IPV6,
	IEE_802_3,
	DeviceNet,
	ControlNet,
	PROFINET
};

/* Enumeration Time Source (table 7, page 57) */
290 291 292 293 294 295 296 297 298
enum ENTimeSource {
	ATOMIC_CLOCK		= 0x10,
	GPS			= 0x20,
	TERRESTRIAL_RADIO	= 0x30,
	PTP			= 0x40,
	NTP			= 0x50,
	HAND_SET		= 0x60,
	OTHER			= 0x90,
	INTERNAL_OSCILLATOR	= 0xA0
299 300 301 302
};

/* Enumeration Delay mechanism (table 9, page 74) */
enum ENDelayMechanism {
303 304 305
	E2E		= 1,
	P2P		= 2,
	DELAY_DISABLED	= 0xFE
306 307
};

308
#endif /* __PPTP_IEEE_1588_TYPES_H__ */