From 1ccc55ef079014b5b81d90a33657d12e7041e358 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 1 Apr 2018 08:17:25 -0700 Subject: [PATCH] port: Add a method for constructing signaling messages. Signed-off-by: Richard Cochran --- makefile | 6 +++--- port_private.h | 4 ++++ port_signaling.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 port_signaling.c diff --git a/makefile b/makefile index a6e3eb5..5dc5fdc 100644 --- a/makefile +++ b/makefile @@ -25,9 +25,9 @@ LDLIBS = -lm -lrt $(EXTRA_LDFLAGS) PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o e2e_tc.o fault.o \ filter.o fsm.o hash.o linreg.o mave.o mmedian.o msg.o ntpshm.o nullf.o phc.o \ - pi.o port.o print.o ptp4l.o p2p_tc.o raw.o rtnl.o servo.o sk.o stats.o tc.o \ - telecom.o tlv.o transport.o tsproc.o udp.o udp6.o uds.o unicast_fsm.o util.o \ - version.o + pi.o port.o port_signaling.o print.o ptp4l.o p2p_tc.o raw.o rtnl.o servo.o \ + sk.o stats.o tc.o telecom.o tlv.o transport.o tsproc.o udp.o udp6.o uds.o \ + unicast_fsm.o util.o version.o OBJECTS = $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o pmc_common.o \ sysoff.o timemaster.o diff --git a/port_private.h b/port_private.h index e1adeb9..777de02 100644 --- a/port_private.h +++ b/port_private.h @@ -84,6 +84,7 @@ struct port { struct { UInteger16 announce; UInteger16 delayreq; + UInteger16 signaling; UInteger16 sync; } seqnum; tmv_t peer_delay; @@ -160,6 +161,9 @@ int port_set_delay_tmo(struct port *p); int port_set_qualification_tmo(struct port *p); void port_show_transition(struct port *p, enum port_state next, enum fsm_event event); +struct ptp_message *port_signaling_construct(struct port *p, + struct address *address, + struct PortIdentity *tpid); int port_tx_announce(struct port *p, struct address *dst); int port_tx_sync(struct port *p, struct address *dst); int process_announce(struct port *p, struct ptp_message *m); diff --git a/port_signaling.c b/port_signaling.c new file mode 100644 index 0000000..c8b46e9 --- /dev/null +++ b/port_signaling.c @@ -0,0 +1,46 @@ +/** + * @file port_signaling.c + * @brief Implements signaling messages + * @note Copyright (C) 2018 Richard Cochran + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA. + */ +#include "port_private.h" + +struct ptp_message *port_signaling_construct(struct port *p, + struct address *address, + struct PortIdentity *tpid) +{ + struct ptp_message *msg; + + msg = msg_allocate(); + if (!msg) { + return NULL; + } + msg->hwts.type = p->timestamping; + msg->header.tsmt = SIGNALING | p->transportSpecific; + msg->header.ver = PTP_VERSION; + msg->header.messageLength = sizeof(struct signaling_msg); + msg->header.domainNumber = clock_domain_number(p->clock); + msg->header.sourcePortIdentity = p->portIdentity; + msg->header.sequenceId = p->seqnum.signaling++; + msg->header.control = CTL_OTHER; + msg->header.logMessageInterval = 0x7F; + msg->signaling.targetPortIdentity = *tpid; + msg->header.flagField[0] |= UNICAST; + msg->address = *address; + + return msg; +}