ieee1588_types.h 6.22 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 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

#include <stdint.h>


typedef enum {FALSE=0, TRUE} Boolean; /* FIXME really needed? */
typedef char 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;
/* Enumerations are unsigned, see 5.4.2, page 15 */
typedef uint16_t Enumeration16;
typedef uint8_t Enumeration8;
typedef uint8_t Enumeration4;
typedef uint8_t UInteger4;
typedef uint8_t Nibble;

27 28 29 30
#define PP_CLOCK_IDENTITY_LENGTH 8

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

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
typedef struct {
	uint32_t lsb;
	uint16_t msb;
} UInteger48;

typedef struct {
	uint32_t lsb;
	int32_t msb;
} Integer64;

typedef struct {
	Integer64 scaledNanoseconds;
} TimeInterval;

typedef struct  {
	UInteger48 secondsField;
	UInteger32 nanosecondsField;
} Timestamp;

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

55
typedef Octet ClockIdentity[PP_CLOCK_IDENTITY_LENGTH];
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

typedef struct {
	ClockIdentity clockIdentity;
	UInteger16 portNumber;
} PortIdentity;

typedef struct {
	Enumeration16 networkProtocol;
	UInteger16 adressLength;
	Octet* adressField;
} PortAdress;

typedef struct {
	UInteger8 clockClass;
	Enumeration8 clockAccuracy;
	UInteger16 offsetScaledLogVariance;
} ClockQuality;

typedef struct {
	Enumeration16 tlvType;
	UInteger16 lengthField;
	Octet* valueField;
} TLV;

typedef struct {
	UInteger8 lengthField;
	Octet* textField;
} PTPText;

typedef struct {
	UInteger16 faultRecordLength;
	Timestamp faultTime;
	Enumeration8 severityCode;
	PTPText faultName;
	PTPText faultValue;
	PTPText faultDescription;
} FaultRecord;


/* Common Message header (table 18, page 124) */
typedef struct {
 	Nibble transportSpecific;
 	Enumeration4 messageType;
 	UInteger4 versionPTP;
 	UInteger16 messageLength;
 	UInteger8 domainNumber;
 	Octet flagField[2];
 	Integer64 correctionfield;
	PortIdentity sourcePortIdentity;
 	UInteger16 sequenceId;
 	UInteger8 controlField;
 	Integer8 logMessageInterval;
} MsgHeader;

/* Announce Message (table 25, page 129) */
typedef struct {
	Timestamp originTimestamp;
	Integer16 currentUtcOffset;
	UInteger8 grandmasterPriority1;
	ClockQuality grandmasterClockQuality;
	UInteger8 grandmasterPriority2;
	ClockIdentity grandmasterIdentity;
	UInteger16 stepsRemoved;
	Enumeration8 timeSource;
} MsgAnnounce;

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

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

/* DelayResp Message (table 27, page 130) */
typedef struct {
	Timestamp preciseOriginTimestamp;
} MsgFollowUp;


/* DelayResp Message (table 28, page 130) */
typedef struct {
	Timestamp receiveTimestamp;
	PortIdentity requestingPortIdentity;
} MsgDelayResp;

/* PdelayReq Message (table 29, page 131) */
typedef struct {
	Timestamp originTimestamp;

} MsgPDelayReq;

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

/* PdelayRespFollowUp Message (table 31, page 132) */
typedef struct {
	Timestamp responseOriginTimestamp;
	PortIdentity requestingPortIdentity;
160
} MsgPDelayRespFollowUp;
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

/* Signaling Message (table 33, page 133) */
typedef struct {
	PortIdentity targetPortIdentity;
	char* tlv;
} MsgSignaling;

/* Management Message (table 37, page 137) */
typedef struct {
	PortIdentity targetPortIdentity;
	UInteger8 startingBoundaryHops;
	UInteger8 boundaryHops;
	Enumeration4 actionField;
	char* tlv;
} MsgManagement;

Aurelio Colosimo's avatar
Aurelio Colosimo committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244


/* Default Data Set */
typedef struct {
	/* Static */
	Boolean twoStepFlag;
	ClockIdentity clockIdentity;
	UInteger16 numberPorts;
	/* Dynamic */
	ClockQuality clockQuality;
	/* Configurable */
	UInteger8 priority1;
	UInteger8 priority2;
	UInteger8 domainNumber;
	Boolean slaveOnly;
} DSDefault;

/* Current Data Set */
typedef struct {
	/* Dynamic */
	UInteger16 stepsRemoved;
	TimeInternal offsetFromMaster;
	TimeInternal meanPathDelay;
} DSCurrent;

/* Parent Data Set */
typedef struct {
	/* Dynamic */
	PortIdentity parentPortIdentity;
	Boolean parentStats;
	UInteger16 observedParentOffsetScaledLogVariance;
	Integer32 observedParentClockPhaseChangeRate;
	ClockIdentity grandmasterIdentity;
	ClockQuality grandmasterClockQuality;
	UInteger8 grandmasterPriority1;
	UInteger8 grandmasterPriority2;
} DSParent;

/* Port Data set */
typedef struct {
	/* Static */
	PortIdentity portIdentity;
	/* Dynamic */
	Enumeration8 portState;
	Integer8 logMinDelayReqInterval;
	TimeInternal peerMeanPathDelay;
	/* Configurable */
	Integer8 logAnnounceInterval;
	UInteger8 announceReceiptTimeout;
	Integer8 logSyncInterval;
	Enumeration8 delayMechanism;
	Integer8 logMinPdelayReqInterval;
	UInteger4 versionNumber;
} DSPort;

/* Time Properties Data Set */
typedef struct {
	/* Dynamic */
	Integer16 currentUtcOffset;
	Boolean currentUtcOffsetValid;
	Boolean leap59;
	Boolean leap61;
	Boolean timeTraceable;
	Boolean frequencyTraceable;
	Boolean ptpTimescale;
	Enumeration8 timeSource;
} DSTimeProperties;

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/* Enumeration States (table 8, page 73) */
enum pp_std_states {
	PPS_END_OF_TABLE = 0,
	PPS_INITIALIZING,
	PPS_FAULTY,
	PPS_DISABLED,
	PPS_LISTENING,
	PPS_PRE_MASTER,
	PPS_MASTER,
	PPS_PASSIVE,
	PPS_UNCALIBRATED,
	PPS_SLAVE,
};

enum pp_std_messages {
	PPM_SYNC = 0x0,
	PPM_DELAY_REQ,
	PPM_PDELAY_REQ,
	PPM_PDELAY_RESP,
	PPM_FOLLOW_UP = 0x8,
	PPM_DELAY_RESP,
	PPM_PDELAY_RESP_FOLLOW_UP,
	PPM_ANNOUNCE,
	PPM_SIGNALING,
	PPM_MANAGEMENT,
};

/* Enumeration Domain Number (table 2, page 41) */
enum ENDomainNumber {
	DFLT_DOMAIN_NUMBER = 0,
	ALT1_DOMAIN_NUMBER,
	ALT2_DOMAIN_NUMBER,
	ALT3_DOMAIN_NUMBER
};

/* Enumeration Network Protocol (table 3, page 46) */
enum ENNetworkProtocol {
	UDP_IPV4 = 1,
	UDP_IPV6,
	IEE_802_3,
	DeviceNet,
	ControlNet,
	PROFINET
};

/* Enumeration Time Source (table 7, page 57) */
enum ENTimeSource{
	ATOMIC_CLOCK = 0x10,
	GPS = 0x20,
	TERRESTRIAL_RADIO = 0x30,
	PTP = 0x40,
	NTP = 0x50,
	HAND_SET = 0x60,
	OTHER = 0x90,
	INTERNAL_OSCILLATOR = 0xA0
};

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

309
#endif /* __PPTP_IEEE_1588_TYPES_H__ */