> -----Original Message-----
> From: Erez Geva <erez.geva....@siemens.com>
> Sent: Wednesday, March 10, 2021 2:18 PM
> To: linuxptp-devel@lists.sourceforge.net
> Subject: [Linuxptp-devel] [PATCH 2/2] Fix Management Implementation-specific
> TLVs
> 
> Change Management Implementation-specific TLVs use to
>  little endian instead of using host order.
> 
> Although IEEE use network order, as most of us use little endian
>  hardware and to retain backward compatible with most of us,
>  we decide to use little endian.
> 
> Signed-off-by: Erez Geva <erez.geva....@siemens.com>

If we were worried, we could introduce new ops for this, but I think the 
fallout is low.

Thanks,
Jake

> ---
>  clock.c | 29 +++++++++++++--------
>  pmc.c   | 80 +++++++++++++++++++++++++++++++++------------------------
>  port.c  | 13 +++++++---
>  3 files changed, 74 insertions(+), 48 deletions(-)
> 
> diff --git a/clock.c b/clock.c
> index 5b3b4d0..90f3c77 100644
> --- a/clock.c
> +++ b/clock.c
> @@ -423,25 +423,33 @@ static int clock_management_fill_response(struct clock
> *c, struct port *p,
>               break;
>       case TLV_TIME_STATUS_NP:
>               tsn = (struct time_status_np *) tlv->data;
> -             tsn->master_offset = tmv_to_nanoseconds(c->master_offset);
> -             tsn->ingress_time = tmv_to_nanoseconds(c->ingress_ts);
> -             tsn->cumulativeScaledRateOffset =
> +             tsn->master_offset = htole64(tmv_to_nanoseconds(c-
> >master_offset));
> +             tsn->ingress_time = htole64(tmv_to_nanoseconds(c-
> >ingress_ts));
> +             tsn->cumulativeScaledRateOffset = htole32(
>                       (Integer32) (c->status.cumulativeScaledRateOffset +
> -                                   c->nrr * POW2_41 - POW2_41);
> -             tsn->scaledLastGmPhaseChange = c-
> >status.scaledLastGmPhaseChange;
> -             tsn->gmTimeBaseIndicator = c->status.gmTimeBaseIndicator;
> -             tsn->lastGmPhaseChange = c->status.lastGmPhaseChange;
> +                                   c->nrr * POW2_41 - POW2_41));
> +             tsn->scaledLastGmPhaseChange = htole32(c-
> >status.scaledLastGmPhaseChange);
> +             tsn->gmTimeBaseIndicator = htole16(c-
> >status.gmTimeBaseIndicator);
> +             tsn->lastGmPhaseChange.nanoseconds_msb =
> +                     htole16(c-
> >status.lastGmPhaseChange.nanoseconds_msb);
> +             tsn->lastGmPhaseChange.nanoseconds_lsb =
> +                     htole64(c->status.lastGmPhaseChange.nanoseconds_lsb);
> +             tsn->lastGmPhaseChange.fractional_nanoseconds =
> +                     htole16(c-
> >status.lastGmPhaseChange.fractional_nanoseconds);
>               if (cid_eq(&c->dad.pds.grandmasterIdentity, &c-
> >dds.clockIdentity))
>                       tsn->gmPresent = 0;
>               else
> -                     tsn->gmPresent = 1;
> +                     tsn->gmPresent = htole32(1);
>               tsn->gmIdentity = c->dad.pds.grandmasterIdentity;
>               datalen = sizeof(*tsn);
>               break;
>       case TLV_GRANDMASTER_SETTINGS_NP:
>               gsn = (struct grandmaster_settings_np *) tlv->data;
> -             gsn->clockQuality = c->dds.clockQuality;
> -             gsn->utc_offset = c->utc_offset;
> +             gsn->clockQuality.clockClass = c->dds.clockQuality.clockClass;
> +             gsn->clockQuality.clockAccuracy = c-
> >dds.clockQuality.clockAccuracy;
> +             gsn->clockQuality.offsetScaledLogVariance =
> +                     htole16(c->dds.clockQuality.offsetScaledLogVariance);
> +             gsn->utc_offset = htole16(c->utc_offset);
>               gsn->time_flags = c->time_flags;
>               gsn->time_source = c->time_source;
>               datalen = sizeof(*gsn);
> @@ -453,6 +461,7 @@ static int clock_management_fill_response(struct clock
> *c, struct port *p,
>               }
>               sen = (struct subscribe_events_np *)tlv->data;
>               clock_get_subscription(c, req, sen->bitmask, &sen->duration);
> +             sen->duration = htole16(sen->duration);
>               datalen = sizeof(*sen);
>               break;
>       case TLV_SYNCHRONIZATION_UNCERTAIN_NP:
> diff --git a/pmc.c b/pmc.c
> index 1e569b5..6d5d35c 100644
> --- a/pmc.c
> +++ b/pmc.c
> @@ -137,6 +137,17 @@ static void pmc_show_signaling(struct ptp_message
> *msg, FILE *fp)
>       fflush(fp);
>  }
> 
> +static inline uint64_t getStat(struct port_stats_np *pcp, bool rx, int index)
> +{
> +     uint64_t ret;
> +
> +     if (rx)
> +             ret = pcp->stats.rxMsgType[index];
> +     else
> +             ret = pcp->stats.txMsgType[index];
> +     return le64toh(ret);
> +}
> +
>  static void pmc_show(struct ptp_message *msg, FILE *fp)
>  {
>       struct grandmaster_settings_np *gsn;
> @@ -346,15 +357,15 @@ static void pmc_show(struct ptp_message *msg, FILE
> *fp)
>                       IFMT "lastGmPhaseChange          0x%04hx'%016" PRIx64
> ".%04hx"
>                       IFMT "gmPresent                  %s"
>                       IFMT "gmIdentity                 %s",
> -                     tsn->master_offset,
> -                     tsn->ingress_time,
> -                     (tsn->cumulativeScaledRateOffset + 0.0) / P41,
> -                     tsn->scaledLastGmPhaseChange,
> -                     tsn->gmTimeBaseIndicator,
> -                     tsn->lastGmPhaseChange.nanoseconds_msb,
> -                     tsn->lastGmPhaseChange.nanoseconds_lsb,
> -                     tsn->lastGmPhaseChange.fractional_nanoseconds,
> -                     tsn->gmPresent ? "true" : "false",
> +                     le64toh(tsn->master_offset),
> +                     le64toh(tsn->ingress_time),
> +                     (le32toh(tsn->cumulativeScaledRateOffset) + 0.0) / P41,
> +                     le32toh(tsn->scaledLastGmPhaseChange),
> +                     le16toh(tsn->gmTimeBaseIndicator),
> +                     le16toh(tsn->lastGmPhaseChange.nanoseconds_msb),
> +                     le64toh(tsn->lastGmPhaseChange.nanoseconds_lsb),
> +                     le16toh(tsn-
> >lastGmPhaseChange.fractional_nanoseconds),
> +                     le32toh(tsn->gmPresent) ? "true" : "false",
>                       cid2str(&tsn->gmIdentity));
>               break;
>       case TLV_GRANDMASTER_SETTINGS_NP:
> @@ -373,8 +384,8 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
>                       IFMT "timeSource              0x%02hhx",
>                       gsn->clockQuality.clockClass,
>                       gsn->clockQuality.clockAccuracy,
> -                     gsn->clockQuality.offsetScaledLogVariance,
> -                     gsn->utc_offset,
> +                     le16toh(gsn->clockQuality.offsetScaledLogVariance),
> +                     le16toh(gsn->utc_offset),
>                       gsn->time_flags & LEAP_61 ? 1 : 0,
>                       gsn->time_flags & LEAP_59 ? 1 : 0,
>                       gsn->time_flags & UTC_OFF_VALID ? 1 : 0,
> @@ -389,7 +400,7 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
>                       IFMT "duration          %hu"
>                       IFMT "NOTIFY_PORT_STATE %s"
>                       IFMT "NOTIFY_TIME_SYNC  %s",
> -                     sen->duration,
> +                     le16toh(sen->duration),
>                       event_bitmask_get(sen->bitmask, NOTIFY_PORT_STATE)
> ? "on" : "off",
>                       event_bitmask_get(sen->bitmask, NOTIFY_TIME_SYNC) ?
> "on" : "off");
>               break;
> @@ -426,11 +437,12 @@ static void pmc_show(struct ptp_message *msg, FILE
> *fp)
>               fprintf(fp, "PORT_DATA_SET_NP "
>                       IFMT "neighborPropDelayThresh %u"
>                       IFMT "asCapable               %d",
> -                     pnp->neighborPropDelayThresh,
> -                     pnp->asCapable ? 1 : 0);
> +                     le32toh(pnp->neighborPropDelayThresh),
> +                     le32toh(pnp->asCapable) ? 1 : 0);
>               break;
>       case TLV_PORT_PROPERTIES_NP:
>               ppn = (struct port_properties_np *) mgt->data;
> +             ppn->portIdentity.portNumber = le16toh(ppn-
> >portIdentity.portNumber);
>               if (ppn->port_state > PS_SLAVE) {
>                       ppn->port_state = 0;
>               }
> @@ -469,26 +481,26 @@ static void pmc_show(struct ptp_message *msg, FILE
> *fp)
>                       IFMT "tx_Signaling              %" PRIu64
>                       IFMT "tx_Management             %" PRIu64,
>                       pid2str(&pcp->portIdentity),
> -                     pcp->stats.rxMsgType[SYNC],
> -                     pcp->stats.rxMsgType[DELAY_REQ],
> -                     pcp->stats.rxMsgType[PDELAY_REQ],
> -                     pcp->stats.rxMsgType[PDELAY_RESP],
> -                     pcp->stats.rxMsgType[FOLLOW_UP],
> -                     pcp->stats.rxMsgType[DELAY_RESP],
> -                     pcp->stats.rxMsgType[PDELAY_RESP_FOLLOW_UP],
> -                     pcp->stats.rxMsgType[ANNOUNCE],
> -                     pcp->stats.rxMsgType[SIGNALING],
> -                     pcp->stats.rxMsgType[MANAGEMENT],
> -                     pcp->stats.txMsgType[SYNC],
> -                     pcp->stats.txMsgType[DELAY_REQ],
> -                     pcp->stats.txMsgType[PDELAY_REQ],
> -                     pcp->stats.txMsgType[PDELAY_RESP],
> -                     pcp->stats.txMsgType[FOLLOW_UP],
> -                     pcp->stats.txMsgType[DELAY_RESP],
> -                     pcp->stats.txMsgType[PDELAY_RESP_FOLLOW_UP],
> -                     pcp->stats.txMsgType[ANNOUNCE],
> -                     pcp->stats.txMsgType[SIGNALING],
> -                     pcp->stats.txMsgType[MANAGEMENT]);
> +                     getStat(pcp, true, SYNC),
> +                     getStat(pcp, true, DELAY_REQ),
> +                     getStat(pcp, true, PDELAY_REQ),
> +                     getStat(pcp, true, PDELAY_RESP),
> +                     getStat(pcp, true, FOLLOW_UP),
> +                     getStat(pcp, true, DELAY_RESP),
> +                     getStat(pcp, true, PDELAY_RESP_FOLLOW_UP),
> +                     getStat(pcp, true, ANNOUNCE),
> +                     getStat(pcp, true, SIGNALING),
> +                     getStat(pcp, true, MANAGEMENT),
> +                     getStat(pcp, false, SYNC),
> +                     getStat(pcp, false, DELAY_REQ),
> +                     getStat(pcp, false, PDELAY_REQ),
> +                     getStat(pcp, false, PDELAY_RESP),
> +                     getStat(pcp, false, FOLLOW_UP),
> +                     getStat(pcp, false, DELAY_RESP),
> +                     getStat(pcp, false, PDELAY_RESP_FOLLOW_UP),
> +                     getStat(pcp, false, ANNOUNCE),
> +                     getStat(pcp, false, SIGNALING),
> +                     getStat(pcp, false, MANAGEMENT));
>               break;
>       case TLV_LOG_ANNOUNCE_INTERVAL:
>               mtd = (struct management_tlv_datum *) mgt->data;
> diff --git a/port.c b/port.c
> index d405a2c..1286b9b 100644
> --- a/port.c
> +++ b/port.c
> @@ -806,6 +806,7 @@ static int port_management_fill_response(struct port
> *target,
>       uint16_t u16;
>       uint8_t *buf;
>       int datalen;
> +     int i;
> 
>       extra = tlv_extra_alloc();
>       if (!extra) {
> @@ -939,13 +940,14 @@ static int port_management_fill_response(struct port
> *target,
>               break;
>       case TLV_PORT_DATA_SET_NP:
>               pdsnp = (struct port_ds_np *) tlv->data;
> -             pdsnp->neighborPropDelayThresh = target-
> >neighborPropDelayThresh;
> -             pdsnp->asCapable = target->asCapable;
> +             pdsnp->neighborPropDelayThresh = htole32(target-
> >neighborPropDelayThresh);
> +             pdsnp->asCapable = htole32(target->asCapable);
>               datalen = sizeof(*pdsnp);
>               break;
>       case TLV_PORT_PROPERTIES_NP:
>               ppn = (struct port_properties_np *)tlv->data;
> -             ppn->portIdentity = target->portIdentity;
> +             ppn->portIdentity.clockIdentity = target-
> >portIdentity.clockIdentity;
> +             ppn->portIdentity.portNumber = htole16(target-
> >portIdentity.portNumber);
>               if (target->state == PS_GRAND_MASTER)
>                       ppn->port_state = PS_MASTER;
>               else
> @@ -958,7 +960,10 @@ static int port_management_fill_response(struct port
> *target,
>       case TLV_PORT_STATS_NP:
>               psn = (struct port_stats_np *)tlv->data;
>               psn->portIdentity = target->portIdentity;
> -             psn->stats = target->stats;
> +             for (i = 0 ; i < MAX_MESSAGE_TYPES; i++) {
> +                     psn->stats.rxMsgType[i] = htole64(target-
> >stats.rxMsgType[i]);
> +                     psn->stats.txMsgType[i] = htole64(target-
> >stats.txMsgType[i]);
> +             }
>               datalen = sizeof(*psn);
>               break;
>       default:
> --
> 2.20.1
> 
> 
> 
> _______________________________________________
> Linuxptp-devel mailing list
> Linuxptp-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to