From 64ec0478235b8de9403fa93b099e247ffb588932 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 6 Jul 2013 10:19:53 +0200 Subject: [PATCH] Introduce a non-portable management TLV for grand masters. When running as grand master, the attributes of the local clock are not known by the ptp4l program. Since these attributes may change over time, for example when losing signal from GPS satellites, we need to have a way to provide updated information at run time. This patch provides a new TLV intended for local IPC that contains the required settings. Signed-off-by: Richard Cochran --- tlv.c | 16 ++++++++++++++++ tlv.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/tlv.c b/tlv.c index b50c637..35a3aa0 100644 --- a/tlv.c +++ b/tlv.c @@ -60,6 +60,7 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len, struct timePropertiesDS *tp; struct portDS *p; struct time_status_np *tsn; + struct grandmaster_settings_np *gsn; struct mgmt_clock_description *cd; int extra_len = 0; uint8_t *buf; @@ -163,6 +164,14 @@ static int mgt_post_recv(struct management_tlv *m, uint16_t data_len, scaled_ns_n2h(&tsn->lastGmPhaseChange); tsn->gmPresent = ntohl(tsn->gmPresent); break; + case GRANDMASTER_SETTINGS_NP: + if (data_len != sizeof(struct grandmaster_settings_np)) + goto bad_length; + gsn = (struct grandmaster_settings_np *) m->data; + gsn->clockQuality.offsetScaledLogVariance = + ntohs(gsn->clockQuality.offsetScaledLogVariance); + gsn->utc_offset = ntohs(gsn->utc_offset); + break; } if (extra_len) { if (extra_len % 2) @@ -183,6 +192,7 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra) struct timePropertiesDS *tp; struct portDS *p; struct time_status_np *tsn; + struct grandmaster_settings_np *gsn; struct mgmt_clock_description *cd; switch (m->id) { case CLOCK_DESCRIPTION: @@ -236,6 +246,12 @@ static void mgt_pre_send(struct management_tlv *m, struct tlv_extra *extra) scaled_ns_h2n(&tsn->lastGmPhaseChange); tsn->gmPresent = htonl(tsn->gmPresent); break; + case GRANDMASTER_SETTINGS_NP: + gsn = (struct grandmaster_settings_np *) m->data; + gsn->clockQuality.offsetScaledLogVariance = + htons(gsn->clockQuality.offsetScaledLogVariance); + gsn->utc_offset = htons(gsn->utc_offset); + break; } } diff --git a/tlv.h b/tlv.h index 443bbdf..1cd8a39 100644 --- a/tlv.h +++ b/tlv.h @@ -78,6 +78,7 @@ enum management_action { #define TRANSPARENT_CLOCK_DEFAULT_DATA_SET 0x4000 #define PRIMARY_DOMAIN 0x4002 #define TIME_STATUS_NP 0xC000 +#define GRANDMASTER_SETTINGS_NP 0xC001 /* Port management ID values */ #define NULL_MANAGEMENT 0x0000 @@ -182,6 +183,13 @@ struct time_status_np { struct ClockIdentity gmIdentity; } PACKED; +struct grandmaster_settings_np { + struct ClockQuality clockQuality; + Integer16 utc_offset; + UInteger8 time_flags; + Enumeration8 time_source; +} PACKED; + enum clock_type { CLOCK_TYPE_ORDINARY = 0x8000, CLOCK_TYPE_BOUNDARY = 0x4000,