summaryrefslogtreecommitdiff
path: root/daemons/gptp/common
diff options
context:
space:
mode:
Diffstat (limited to 'daemons/gptp/common')
-rw-r--r--daemons/gptp/common/ap_message.cpp116
-rw-r--r--daemons/gptp/common/avbap_message.hpp110
-rw-r--r--daemons/gptp/common/avbts_clock.hpp671
-rw-r--r--daemons/gptp/common/avbts_message.hpp1267
-rw-r--r--daemons/gptp/common/avbts_oscondition.hpp123
-rw-r--r--daemons/gptp/common/avbts_osipc.hpp140
-rw-r--r--daemons/gptp/common/avbts_oslock.hpp112
-rw-r--r--daemons/gptp/common/avbts_osnet.cpp38
-rw-r--r--daemons/gptp/common/avbts_osnet.hpp396
-rw-r--r--daemons/gptp/common/avbts_osthread.hpp96
-rw-r--r--daemons/gptp/common/avbts_ostimer.hpp78
-rw-r--r--daemons/gptp/common/avbts_ostimerq.hpp104
-rw-r--r--daemons/gptp/common/avbts_persist.hpp105
-rw-r--r--daemons/gptp/common/common_port.cpp762
-rw-r--r--daemons/gptp/common/common_port.hpp1534
-rw-r--r--daemons/gptp/common/common_tstamper.hpp162
-rw-r--r--daemons/gptp/common/ether_port.cpp881
-rw-r--r--daemons/gptp/common/ether_port.hpp598
-rw-r--r--daemons/gptp/common/ether_tstamper.hpp73
-rw-r--r--daemons/gptp/common/gptp_cfg.cpp335
-rw-r--r--daemons/gptp/common/gptp_cfg.hpp180
-rw-r--r--daemons/gptp/common/gptp_log.cpp113
-rw-r--r--daemons/gptp/common/gptp_log.hpp117
-rw-r--r--daemons/gptp/common/ieee1588.hpp455
-rw-r--r--daemons/gptp/common/ieee1588clock.cpp500
-rw-r--r--daemons/gptp/common/ini.c176
-rw-r--r--daemons/gptp/common/ini.h72
-rw-r--r--daemons/gptp/common/ipcdef.hpp120
-rw-r--r--daemons/gptp/common/ptp_message.cpp2018
-rw-r--r--daemons/gptp/common/ptptypes.hpp68
-rw-r--r--daemons/gptp/common/wireless_port.cpp242
-rw-r--r--daemons/gptp/common/wireless_port.hpp179
-rw-r--r--daemons/gptp/common/wireless_tstamper.cpp127
-rw-r--r--daemons/gptp/common/wireless_tstamper.hpp221
34 files changed, 0 insertions, 12289 deletions
diff --git a/daemons/gptp/common/ap_message.cpp b/daemons/gptp/common/ap_message.cpp
deleted file mode 100644
index df121838..00000000
--- a/daemons/gptp/common/ap_message.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2012-2016, Harman International Industries, Incorporated
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*************************************************************************************************************/
-
-#include <ieee1588.hpp>
-#include <avbts_clock.hpp>
-#include <avbap_message.hpp>
-#include <ether_port.hpp>
-#include <avbts_ostimer.hpp>
-#include <gptp_log.hpp>
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-// Octet based data 2 buffer macros
-#define OCT_D2BMEMCP(d, s) memcpy(d, s, sizeof(s)); d += sizeof(s);
-#define OCT_D2BBUFCP(d, s, len) memcpy(d, s, len); d += len;
-#define OCT_D2BHTONB(d, s) *(U8 *)(d) = s; d += sizeof(s);
-#define OCT_D2BHTONS(d, s) *(U16 *)(d) = PLAT_htons(s); d += sizeof(s);
-#define OCT_D2BHTONL(d, s) *(U32 *)(d) = PLAT_htonl(s); d += sizeof(s);
-
-// Bit based data 2 buffer macros
-#define BIT_D2BHTONB(d, s, shf) *(uint8_t *)(d) |= s << shf;
-#define BIT_D2BHTONS(d, s, shf) *(uint16_t *)(d) |= PLAT_htons((uint16_t)(s << shf));
-#define BIT_D2BHTONL(d, s, shf) *(uint32_t *)(d) |= PLAT_htonl((uint32_t)(s << shf));
-
-
-APMessageTestStatus::APMessageTestStatus()
-{
-}
-
-APMessageTestStatus::~APMessageTestStatus()
-{
-}
-
-APMessageTestStatus::APMessageTestStatus( EtherPort *port )
-{
-}
-
-void APMessageTestStatus::sendPort( EtherPort * port )
-{
- static uint16_t sequenceId = 0;
-
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- uint16_t tmp16;
- uint32_t tmp32;
- uint64_t tmp64;
-
- memset(buf_t, 0, 256);
-
- // Create packet in buf
- messageLength = AP_TEST_STATUS_LENGTH;
-
- BIT_D2BHTONB(buf_ptr + AP_TEST_STATUS_AVTP_SUBTYPE(AP_TEST_STATUS_OFFSET), 0xfb, 0);
- BIT_D2BHTONB(buf_ptr + AP_TEST_STATUS_AVTP_VERSION_CONTROL(AP_TEST_STATUS_OFFSET), 0x1, 0);
- BIT_D2BHTONS(buf_ptr + AP_TEST_STATUS_AVTP_STATUS_LENGTH(AP_TEST_STATUS_OFFSET), 148, 0);
-
- port->getLocalAddr()->toOctetArray(buf_ptr + AP_TEST_STATUS_TARGET_ENTITY_ID(AP_TEST_STATUS_OFFSET));
-
- tmp16 = PLAT_htons(sequenceId++);
- memcpy(buf_ptr + AP_TEST_STATUS_SEQUENCE_ID(AP_TEST_STATUS_OFFSET), &tmp16, sizeof(tmp16));
-
- BIT_D2BHTONS(buf_ptr + AP_TEST_STATUS_COMMAND_TYPE(AP_TEST_STATUS_OFFSET), 1, 15);
- BIT_D2BHTONS(buf_ptr + AP_TEST_STATUS_COMMAND_TYPE(AP_TEST_STATUS_OFFSET), 0x29, 0);
-
- tmp16 = PLAT_htons(0x09);
- memcpy(buf_ptr + AP_TEST_STATUS_DESCRIPTOR_TYPE(AP_TEST_STATUS_OFFSET), &tmp16, sizeof(tmp16));
- tmp16 = PLAT_htons(0x00);
- memcpy(buf_ptr + AP_TEST_STATUS_DESCRIPTOR_INDEX(AP_TEST_STATUS_OFFSET), &tmp16, sizeof(tmp16));
-
- tmp32 = PLAT_htonl(0x07000023);
- memcpy(buf_ptr + AP_TEST_STATUS_COUNTERS_VALID(AP_TEST_STATUS_OFFSET), &tmp32, sizeof(tmp32));
-
- tmp32 = PLAT_htonl(port->getLinkUpCount());
- memcpy(buf_ptr + AP_TEST_STATUS_COUNTER_LINKUP(AP_TEST_STATUS_OFFSET), &tmp32, sizeof(tmp32));
-
- tmp32 = PLAT_htonl(port->getLinkDownCount());
- memcpy(buf_ptr + AP_TEST_STATUS_COUNTER_LINKDOWN(AP_TEST_STATUS_OFFSET), &tmp32, sizeof(tmp32));
-
- Timestamp system_time;
- Timestamp device_time;
- uint32_t local_clock, nominal_clock_rate;
- port->getDeviceTime(system_time, device_time, local_clock, nominal_clock_rate);
- tmp64 = PLAT_htonll(TIMESTAMP_TO_NS(system_time));
- memcpy(buf_ptr + AP_TEST_STATUS_MESSAGE_TIMESTAMP(AP_TEST_STATUS_OFFSET), &tmp64, sizeof(tmp64));
-
- BIT_D2BHTONB(buf_ptr + AP_TEST_STATUS_STATION_STATE(AP_TEST_STATUS_OFFSET), (uint8_t)port->getStationState(), 0);
-
- port->sendGeneralPort(AVTP_ETHERTYPE, buf_t, messageLength, MCAST_TEST_STATUS, NULL);
-
- return;
-}
-
diff --git a/daemons/gptp/common/avbap_message.hpp b/daemons/gptp/common/avbap_message.hpp
deleted file mode 100644
index 4c66f758..00000000
--- a/daemons/gptp/common/avbap_message.hpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2012-2016, Harman International Industries, Incorporated
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*************************************************************************************************************/
-
-#ifndef AVBAP_MESSAGE_HPP
-#define AVBAP_MESSAGE_HPP
-
-#include <stdint.h>
-#include <avbts_osnet.hpp>
-#include <ieee1588.hpp>
-
-#include <list>
-#include <algorithm>
-#include <avbts_message.hpp>
-
-/** @file **/
-
-#define AP_TEST_STATUS_OFFSET 0 /*!< AP Test Status offset */
-#define AP_TEST_STATUS_LENGTH 160 /*!< AP Test Status length in byte */
-#define AP_TEST_STATUS_AVTP_SUBTYPE(x) x /*!< AVTP Subtype */
-#define AP_TEST_STATUS_AVTP_VERSION_CONTROL(x) x + 1 /*!< Version and control fields */
-#define AP_TEST_STATUS_AVTP_STATUS_LENGTH(x) x + 2 /*!< Status and content length */
-#define AP_TEST_STATUS_TARGET_ENTITY_ID(x) x + 4 /*!< Target entity ID */
-#define AP_TEST_STATUS_CONTROLLER_ENTITY_ID(x) x + 12 /*!< Controller entity ID */
-#define AP_TEST_STATUS_SEQUENCE_ID(x) x + 20 /*!< Sequence ID */
-#define AP_TEST_STATUS_COMMAND_TYPE(x) x + 22 /*!< Command type */
-#define AP_TEST_STATUS_DESCRIPTOR_TYPE(x) x + 24 /*!< Descriptor Type */
-#define AP_TEST_STATUS_DESCRIPTOR_INDEX(x) x + 26 /*!< Descriptor Index */
-#define AP_TEST_STATUS_COUNTERS_VALID(x) x + 28 /*!< Counters valid */
-#define AP_TEST_STATUS_COUNTER_LINKUP(x) x + 32 /*!< Counter Link Up */
-#define AP_TEST_STATUS_COUNTER_LINKDOWN(x) x + 36 /*!< Counter Link Down */
-#define AP_TEST_STATUS_COUNTER_FRAMES_TX(x) x + 40 /*!< Counter Frames TX */
-#define AP_TEST_STATUS_COUNTER_FRAMES_RX(x) x + 44 /*!< Counter Frames RX */
-#define AP_TEST_STATUS_COUNTER_FRAMES_RX_CRC_ERROR(x) x + 48 /*!< Counter Frames RX CRC Error */
-#define AP_TEST_STATUS_COUNTER_GM_CHANGED(x) x + 52 /*!< Counter GM Changed */
-#define AP_TEST_STATUS_COUNTER_RESERVED(x) x + 56 /*!< Reserved counters */
-#define AP_TEST_STATUS_MESSAGE_TIMESTAMP(x) x + 128 /*!< Message timestamp */
-#define AP_TEST_STATUS_STATION_STATE(x) x + 136 /*!< Station state */
-#define AP_TEST_STATUS_STATION_STATE_SPECIFIC_DATA(x) x + 137 /*!< Station state specific data */
-#define AP_TEST_STATUS_COUNTER_27(x) x + 140 /*!< Counter 27 */
-#define AP_TEST_STATUS_COUNTER_28(x) x + 144 /*!< Counter 28 */
-#define AP_TEST_STATUS_COUNTER_29(x) x + 148 /*!< Counter 29 */
-#define AP_TEST_STATUS_COUNTER_30(x) x + 152 /*!< Counter 30 */
-#define AP_TEST_STATUS_COUNTER_31(x) x + 156 /*!< Counter 31 */
-
-
-/**
- * @brief Automotive Profile Test Status Station State
- */
-typedef enum {
- STATION_STATE_RESERVED,
- STATION_STATE_ETHERNET_READY,
- STATION_STATE_AVB_SYNC,
- STATION_STATE_AVB_MEDIA_READY,
-} StationState_t;
-
-
-/**
- * @brief Provides a class for building the ANvu Automotive
- * Profile Test Status message
- */
-class APMessageTestStatus {
- private:
- uint16_t messageLength; /*!< message length */
-
- APMessageTestStatus();
- public:
- /**
- * @brief Default constructor. Creates APMessageTestStatus
- * @param port EtherPort
- */
- APMessageTestStatus( EtherPort *port );
-
- /**
- * @brief Destroys APMessageTestStatus interface
- */
- ~APMessageTestStatus();
-
- /**
- * @brief Assembles APMessageTestStatus message on the
- * EtherPort payload
- * @param port EtherPort where the message will be assembled
- * @return void
- */
- void sendPort( EtherPort *port );
-};
-
-
-#endif
diff --git a/daemons/gptp/common/avbts_clock.hpp b/daemons/gptp/common/avbts_clock.hpp
deleted file mode 100644
index 22a72464..00000000
--- a/daemons/gptp/common/avbts_clock.hpp
+++ /dev/null
@@ -1,671 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_CLOCK_HPP
-#define AVBTS_CLOCK_HPP
-
-#include <stdint.h>
-#include <ieee1588.hpp>
-#include <common_port.hpp>
-#include <avbts_ostimerq.hpp>
-#include <avbts_osipc.hpp>
-
-/**@file*/
-
-#define EVENT_TIMER_GRANULARITY 5000000 /*!< Event timer granularity*/
-
-/* These 4 macros are used only when Syntonize mode is enabled */
-#define INTEGRAL 0.0003 /*!< PI controller integral factor*/
-#define PROPORTIONAL 1.0 /*!< PI controller proportional factor*/
-#define UPPER_FREQ_LIMIT 250.0 /*!< Upper frequency limit */
-#define LOWER_FREQ_LIMIT -250.0 /*!< Lower frequency limit */
-
-#define UPPER_LIMIT_PPM 250
-#define LOWER_LIMIT_PPM -250
-#define PPM_OFFSET_TO_RATIO(ppm) ((ppm) / ((FrequencyRatio)US_PER_SEC) + 1)
-
-/* This is the threshold in ns for which frequency adjustments will be made */
-#define PHASE_ERROR_THRESHOLD (1000000000)
-
-/* This is the maximum count of phase error, outside of the threshold before
- adjustment is performed */
-#define PHASE_ERROR_MAX_COUNT (6)
-
-/* Value returned by calcMasterLocalClockRateDifference() to indicate
- detection of negative time jump in follow_up message */
-#define NEGATIVE_TIME_JUMP 0.0
-
-/**
- * @brief Provides the clock quality abstraction.
- * Represents the quality of the clock
- * Defined at IEEE 802.1AS-2011
- * Clause 6.3.3.8
- */
-struct ClockQuality {
- unsigned char cq_class; /*!< Clock Class - Clause 8.6.2.2
- Denotes the tracebility of the synchronized time
- distributed by a clock master when it is grandmaster. */
- unsigned char clockAccuracy; /*!< Clock Accuracy - clause 8.6.2.3.
- Indicates the expected time accuracy of
- a clock master.*/
- int16_t offsetScaledLogVariance; /*!< ::Offset Scaled log variance - Clause 8.6.2.4.
- Is the scaled, offset representation
- of an estimate of the PTP variance. The
- PTP variance characterizes the
- precision and frequency stability of the clock
- master. The PTP variance is the square of
- PTPDEV (See B.1.3.2). */
-};
-
-/**
- * @brief Provides the 1588 clock interface
- */
-class IEEE1588Clock {
-private:
- ClockIdentity clock_identity;
- ClockQuality clock_quality;
- unsigned char priority1;
- unsigned char priority2;
- bool initializable;
- bool is_boundary_clock;
- bool two_step_clock;
- unsigned char domain_number;
- uint16_t number_ports;
- uint16_t number_foreign_records;
- bool slave_only;
- int16_t current_utc_offset;
- bool leap_59;
- bool leap_61;
- uint16_t epoch_number;
- uint16_t steps_removed;
- int64_t offset_from_master;
- Timestamp one_way_delay;
- PortIdentity parent_identity;
- ClockIdentity grandmaster_clock_identity;
- ClockQuality grandmaster_clock_quality;
- unsigned char grandmaster_priority1;
- unsigned char grandmaster_priority2;
- bool grandmaster_is_boundary_clock;
- uint8_t time_source;
-
- ClockIdentity LastEBestIdentity;
- bool _syntonize;
- bool _new_syntonization_set_point;
- float _ppm;
- int _phase_error_violation;
-
- CommonPort *port_list[MAX_PORTS];
-
- static Timestamp start_time;
- Timestamp last_sync_time;
-
- bool _master_local_freq_offset_init;
- Timestamp _prev_master_time;
- Timestamp _prev_sync_time;
-
- bool _local_system_freq_offset_init;
- Timestamp _prev_local_time;
- Timestamp _prev_system_time;
-
- OS_IPC *ipc;
-
- OSTimerQueue *timerq;
-
- bool forceOrdinarySlave;
- FrequencyRatio _master_local_freq_offset;
- FrequencyRatio _local_system_freq_offset;
-
- /**
- * @brief fup info stores information of the last time
- * the base time has changed. When that happens
- * the information from fup_status is copied over
- * fup_info. The follow-up sendPort method is
- * supposed to get the information from fup_info
- * prior to sending a message out.
- */
- FollowUpTLV *fup_info;
-
- /**
- * @brief fup status has the instantaneous info
- */
- FollowUpTLV *fup_status;
-
- OSLock *timerq_lock;
-
-public:
-
- /**
- * @brief Add a new event to the timer queue
- * @param target EtherPort target
- * @param e Event to be added
- * @param time_ns Time in nanoseconds
- */
- void addEventTimer
- ( CommonPort *target, Event e,
- unsigned long long time_ns );
-
- /**
- * @brief Deletes an event from the timer queue
- * @param target Target port to remove the event from
- * @param e Event to be removed
- * @return void
- */
- void deleteEventTimer( CommonPort *target, Event e );
-
- /**
- * @brief Instantiates a IEEE 1588 Clock
- * @param forceOrdinarySlave Forces it to be an ordinary slave
- * @param syntonize if TRUE, clock will syntonize to the master clock
- * @param priority1 It is used in the execution of BCMA. See IEEE 802.1AS-2011 Clause 10.3
- * @param timerq_factory [in] Provides a factory object for creating timer queues (managing events)
- * @param ipc [in] Inter process communication object
- * @param lock_factory [in] Provides a factory object for creating locking a locking mechanism
- */
- IEEE1588Clock
- (bool forceOrdinarySlave, bool syntonize, uint8_t priority1,
- OSTimerQueueFactory * timerq_factory, OS_IPC * ipc,
- OSLockFactory *lock_factory );
-
- /*
- * Destroys the IEEE 1588 clock entity
- */
- ~IEEE1588Clock(void);
-
- /**
- * @brief Updates the frequencyRatio information
- * @param buf [out] Stores the serialized clock quality state
- * @param count [inout] Provides the size of buffer. Its decremented internally
- * @return TRUE in case of success, FALSE when the count should be updated with the right size.
- */
- bool serializeState( void *buf, long *count );
-
- /**
- * @brief Restores the frequencyRatio with the serialized input buffer data
- * @param buf [in] serialized frequencyRatio information
- * @param count [inout] Size of buffer. It is incremented internally
- * @return TRUE in case of success, FALSE otherwise.
- */
- bool restoreSerializedState( void *buf, long *count );
-
- /**
- * @brief Gets the current time from system clock
- * @return System time
- */
- Timestamp getTime(void);
-
- /**
- * @brief Gets the timestamp from hardware (Deprecated)
- * @return Hardware timestamp
- */
- Timestamp getPreciseTime(void);
-
- /**
- * @brief Compares the 1588 Clock to the grandmaster clock
- * @param msg [in] PTP announce message
- * @return TRUE if the 1588 clock
- */
- bool isBetterThan(PTPMessageAnnounce * msg);
-
- /**
- * @brief Gets the Last Best clock identity
- * @return clock identity
- */
- ClockIdentity getLastEBestIdentity( void ) {
- return LastEBestIdentity;
- }
-
- /**
- * @brief Sets the last Best clock identity
- * @param id ClockIdentity object to be set
- * @return void
- */
- void setLastEBestIdentity( ClockIdentity id ) {
- LastEBestIdentity = id;
- return;
- }
-
- /**
- * @brief Sets clock identity by id
- * @param id [id] Clock identity (as an octet array)
- * @return void
- */
- void setClockIdentity(char *id) {
- clock_identity.set((uint8_t *) id);
- }
-
- /**
- * @brief Set clock id based on the link layer address. Clock id is 8 octets
- * long whereas link layer address is 6 octets long and it is turned into a
- * clock identity as per the 802.1AS standard described in clause 8.5.2.2
- * @param addr Link layer address
- * @return void
- */
- void setClockIdentity(LinkLayerAddress * addr) {
- clock_identity.set(addr);
- }
-
- /**
- * @brief Gets the domain number
- * @return domain number
- */
- unsigned char getDomain(void) {
- return domain_number;
- }
-
- /**
- * @brief Gets grandmaster clock ID
- * @return GM clock ID
- */
- ClockIdentity getGrandmasterClockIdentity(void) {
- return grandmaster_clock_identity;
- }
-
- /**
- * @brief Sets a new GM clock ID
- * @param id New id
- * @return void
- */
- void setGrandmasterClockIdentity(ClockIdentity id) {
- if (id != grandmaster_clock_identity) {
- GPTP_LOG_STATUS("New Grandmaster \"%s\" (previous \"%s\")", id.getIdentityString().c_str(), grandmaster_clock_identity.getIdentityString().c_str());
- grandmaster_clock_identity = id;
- }
- }
-
- /**
- * @brief Gets grandmaster clock quality object
- * @return Clock quality
- */
- ClockQuality getGrandmasterClockQuality(void) {
- return grandmaster_clock_quality;
- }
-
- /**
- * @brief Sets grandmaster clock quality
- * @param clock_quality ClockQuality object to be set
- * @return void
- */
- void setGrandmasterClockQuality( ClockQuality clock_quality ) {
- grandmaster_clock_quality = clock_quality;
- }
-
- /**
- * @brief Gets the IEEE 1588 Clock quality
- * @return ClockQuality
- */
- ClockQuality getClockQuality(void) {
- return clock_quality;
- }
-
- /**
- * @brief Gets grandmaster priority1 attribute (IEEE 802.1AS-2011 Clause 10.5.3.2.2)
- * @return Grandmaster priority1
- */
- unsigned char getGrandmasterPriority1(void) {
- return grandmaster_priority1;
- }
-
- /**
- * @brief Gets grandmaster priotity2 attribute (IEEE 802.1AS-2011 Clause 10.5.3.2.4)
- * @return Grandmaster priority2
- */
- unsigned char getGrandmasterPriority2(void) {
- return grandmaster_priority2;
- }
-
- /**
- * @brief Sets grandmaster's priority1 attribute (IEEE 802.1AS-2011 Clause 10.5.3.2.2)
- * @param priority1 value to be set
- * @return void
- */
- void setGrandmasterPriority1( unsigned char priority1 ) {
- grandmaster_priority1 = priority1;
- }
-
- /**
- * @brief Sets grandmaster's priority2 attribute (IEEE 802.1AS-2011 Clause 10.5.3.2.4)
- * @param priority2 Value to be set
- * @return void
- */
- void setGrandmasterPriority2( unsigned char priority2 ) {
- grandmaster_priority2 = priority2;
- }
-
- /**
- * @brief Gets master steps removed (IEEE 802.1AS-2011 Clause 10.3.3)
- * @return steps removed value
- */
- uint16_t getMasterStepsRemoved(void) {
- return steps_removed;
- }
-
- /**
- * @brief Gets the currentUtcOffset attribute (IEEE 802.1AS-2011 Clause 10.3.8.9)
- * @return currentUtcOffset
- */
- uint16_t getCurrentUtcOffset(void) {
- return current_utc_offset;
- }
-
- /**
- * @brief Gets the TimeSource attribute (IEEE 802.1AS-2011 clause 10.3.8.10)
- * @return TimeSource
- */
- uint8_t getTimeSource(void) {
- return time_source;
- }
-
- /**
- * @brief Gets IEEE1588Clock priority1 value (IEEE 802.1AS-2011 Clause 8.6.2.1)
- * @return Priority1 value
- */
- unsigned char getPriority1(void) {
- return priority1;
- }
-
- /**
- * @brief Gets IEEE1588Clock priority2 attribute (IEEE 802.1AS-2011 Clause 8.6.2.5)
- * @return Priority2 value
- */
- unsigned char getPriority2(void) {
- return priority2;
- }
-
- /**
- * @brief Gets nextPortId value
- * @return The remaining value from the division of current number of ports by
- * (maximum number of ports + 1) + 1
- */
- uint16_t getNextPortId(void) {
- return (number_ports++ % (MAX_PORTS + 1)) + 1;
- }
-
- /**
- * @brief Sets the follow up info internal object. The fup_info object contains
- * the last updated information when the frequency or phase have changed
- * @param fup Pointer to the FolloUpTLV object.
- * @return void
- */
- void setFUPInfo(FollowUpTLV *fup)
- {
- fup_info = fup;
- }
-
- /**
- * @brief Gets the fup_info pointer
- * @return fup_info pointer
- */
- FollowUpTLV *getFUPInfo(void)
- {
- return fup_info;
- }
-
- /**
- * @brief Sets the follow up status internal object. The fup_status object contains
- * information about the current frequency/phase aqcuired through the received
- * follow up messages
- * @param fup Pointer to the FollowUpTLV object
- * @return void
- */
- void setFUPStatus(FollowUpTLV *fup)
- {
- fup_status = fup;
- }
-
- /**
- * @brief Gets the fup_status pointer
- * @return fup_status pointer
- */
- FollowUpTLV *getFUPStatus(void)
- {
- return fup_status;
- }
-
- /**
- * @brief Updates the follow up info internal object with the current clock source time
- * status values. This method should be called whenever the clockSource entity time
- * base changes (IEEE 802.1AS-2011 Clause 9.2)
- * @return void
- */
- void updateFUPInfo(void)
- {
- fup_info->incrementGMTimeBaseIndicator();
- fup_info->setScaledLastGmFreqChange(fup_status->getScaledLastGmFreqChange());
- fup_info->setScaledLastGmPhaseChange(fup_status->getScaledLastGmPhaseChange());
- }
-
- /**
- * @brief Registers a new IEEE1588 port
- * @param port [in] IEEE1588port instance
- * @param index Port's index
- * @return void
- */
- void registerPort( CommonPort *port, uint16_t index )
- {
- if (index < MAX_PORTS) {
- port_list[index - 1] = port;
- }
- ++number_ports;
- }
-
- /**
- * @brief Gets the current port list instance
- * @param count [out] Number of ports
- * @param ports [out] Pointer to the port list
- * @return
- */
- void getPortList(int &count, CommonPort ** &ports) {
- ports = this->port_list;
- count = number_ports;
- return;
- }
-
- /**
- * @brief Gets current system time
- * @return Instance of a Timestamp object
- */
- static Timestamp getSystemTime(void);
-
- /**
- * @brief Adds an event to the timer queue using a lock
- * @param target EtherPort target
- * @param e Event to be added
- * @param time_ns event time in nanoseconds
- * @return void
- */
- void addEventTimerLocked
- ( CommonPort *target, Event e, unsigned long long time_ns );
-
- /**
- * @brief Deletes and event from the timer queue using a lock
- * @param target Target port to remove the event from
- * @param e Event to be deleted
- * @return
- */
- void deleteEventTimerLocked( CommonPort *target, Event e );
-
- /**
- * @brief Calculates the master to local clock rate difference
- * @param master_time Master time
- * @param sync_time Local time
- * @return The offset in ppt (parts per trillion)
- */
- FrequencyRatio calcMasterLocalClockRateDifference
- ( Timestamp master_time, Timestamp sync_time );
-
- /**
- * @brief Calculates the local to system clock rate difference
- * @param local_time Local time
- * @param system_time System time
- * @return The offset in ppt (parts per trillion)
- */
- FrequencyRatio calcLocalSystemClockRateDifference
- ( Timestamp local_time, Timestamp system_time );
-
- /**
- * @brief Sets the master offset, sintonyze and adjusts the frequency offset
- * @param master_local_offset Master to local phase offset
- * @param local_time Local time
- * @param master_local_freq_offset Master to local frequency offset
- * @param local_system_offset Local time to system time phase offset
- * @param system_time System time
- * @param local_system_freq_offset Local to system frequency offset
- * @param sync_count Sync messages count
- * @param pdelay_count PDelay messages count
- * @param port_state PortState instance
- * @param asCapable asCapable flag
- */
- void setMasterOffset
- ( CommonPort *port, int64_t master_local_offset,
- Timestamp local_time, FrequencyRatio master_local_freq_offset,
- int64_t local_system_offset, Timestamp system_time,
- FrequencyRatio local_system_freq_offset, unsigned sync_count,
- unsigned pdelay_count, PortState port_state, bool asCapable );
-
- /**
- * @brief Get local:system frequency ratio
- * @return clock ratio
- */
- FrequencyRatio getLocalSystemFreqOffset()
- {
- return _local_system_freq_offset;
- }
-
- /**
- * @brief Get the IEEE1588Clock identity value
- * @return clock identity
- */
- ClockIdentity getClockIdentity() {
- return clock_identity;
- }
-
- /**
- * @brief Sets a flag that will allow syntonization during setMasterOffset calls
- * @return void
- */
- void newSyntonizationSetPoint() {
- _new_syntonization_set_point = true;
- }
-
- /**
- * @brief Restart PDelays on all ports
- * @return void
- */
- void restartPDelayAll() {
- int number_ports, i, j = 0;
- CommonPort **ports;
-
- getPortList( number_ports, ports );
-
- for( i = 0; i < number_ports; ++i ) {
- while( ports[j] == NULL ) ++j;
- ports[j]->restartPDelay();
- }
- }
-
- /**
- * @brief Gets all TX locks
- * @return void
- */
- int getTxLockAll() {
- int number_ports, i, j = 0;
- CommonPort **ports;
-
- getPortList( number_ports, ports );
-
- for( i = 0; i < number_ports; ++i ) {
- while( ports[j] == NULL ) ++j;
- if( ports[j]->getTxLock() == false ) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * @brief Release all TX locks
- * @return void
- */
- int putTxLockAll() {
- int number_ports, i, j = 0;
- CommonPort **ports;
-
- getPortList( number_ports, ports );
-
- for( i = 0; i < number_ports; ++i ) {
- while( ports[j] == NULL ) ++j;
- if( ports[j]->putTxLock() == false ) {
- return false;
- }
- }
-
- return true;
- }
-
-
- /**
- * @brief Declares a friend instance of tick_handler method
- * @param sig Signal
- * @return void
- */
- friend void tick_handler(int sig);
-
- /**
- * @brief Gets the timer queue lock
- * @return OSLockResult structure
- */
- OSLockResult getTimerQLock() {
- return timerq_lock->lock();
- }
-
- /**
- * @brief Releases the timer queue lock
- * @return OSLockResult structure
- */
- OSLockResult putTimerQLock() {
- return timerq_lock->unlock();
- }
-
- /**
- * @brief Gets a pointer to the timer queue lock object
- * @return OSLock instance
- */
- OSLock *timerQLock() {
- return timerq_lock;
- }
-};
-
-void tick_handler(int sig);
-
-#endif
diff --git a/daemons/gptp/common/avbts_message.hpp b/daemons/gptp/common/avbts_message.hpp
deleted file mode 100644
index f5ccd9a1..00000000
--- a/daemons/gptp/common/avbts_message.hpp
+++ /dev/null
@@ -1,1267 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_MESSAGE_HPP
-#define AVBTS_MESSAGE_HPP
-
-#include <stdint.h>
-#include <avbts_osnet.hpp>
-#include <ieee1588.hpp>
-
-#include <list>
-#include <algorithm>
-
-/** @file **/
-
-#define PTP_CODE_STRING_LENGTH 4 /*!< PTP code string length in bytes */
-#define PTP_SUBDOMAIN_NAME_LENGTH 16 /*!< PTP subdomain name lenght in bytes */
-#define PTP_FLAGS_LENGTH 2 /*!< PTP flags length in bytes */
-
-#define GPTP_VERSION 2 /*!< GPTP version */
-#define PTP_NETWORK_VERSION 1 /*!< PTP Network version */
-
-#define PTP_ETHER 1 /*!< @todo Not used */
-#define PTP_DEFAULT 255 /*!< @todo Not used */
-
-#define PTP_COMMON_HDR_OFFSET 0 /*!< PTP common header offset */
-#define PTP_COMMON_HDR_LENGTH 34 /*!< PTP common header length in bytes */
-#define PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(x) x /*!< Gets the message type offset on PTP header */
-#define PTP_COMMON_HDR_PTP_VERSION(x) x+1 /*!< Gets the ptp version offset on PTP header */
-#define PTP_COMMON_HDR_MSG_LENGTH(x) x+2 /*!< Gets the message length offset on PTP header */
-#define PTP_COMMON_HDR_DOMAIN_NUMBER(x) x+4 /*!< Gets the domain number offset on PTP header */
-#define PTP_COMMON_HDR_FLAGS(x) x+6 /*!< Gets the flags offset on PTP header */
-#define PTP_COMMON_HDR_CORRECTION(x) x+8 /*!< Gets the correction field offset on PTP header */
-#define PTP_COMMON_HDR_SOURCE_CLOCK_ID(x) x+20 /*!< Gets the source clock id offset on PTP header */
-#define PTP_COMMON_HDR_SOURCE_PORT_ID(x) x+28 /*!< Gets the source port id offset on PTP header */
-#define PTP_COMMON_HDR_SEQUENCE_ID(x) x+30 /*!< Gets the sequence id offset on PTP header */
-#define PTP_COMMON_HDR_CONTROL(x) x+32 /*!< Gets the control offset on PTP header */
-#define PTP_COMMON_HDR_LOG_MSG_INTRVL(x) x+33 /*!< Gets the log message interval offset on PTP header */
-
-#define PTP_ANNOUNCE_OFFSET 34 /*!< PTP announce offset */
-#define PTP_ANNOUNCE_LENGTH 30 /*!< PTP announce length in bytes */
-#define PTP_ANNOUNCE_CURRENT_UTC_OFFSET(x) x+10 /*!< Gets PTP announce current UTC offset */
-#define PTP_ANNOUNCE_GRANDMASTER_PRIORITY1(x) x+13 /*!< Gets Grandmaster priority1 offset on announce fields */
-#define PTP_ANNOUNCE_GRANDMASTER_CLOCK_QUALITY(x) x+14 /*!< Gets Grandmaster clock quality offset on announce fields */
-#define PTP_ANNOUNCE_GRANDMASTER_PRIORITY2(x) x+18 /*!< Gets Grandmasdter priority2 offset on announce fields*/
-#define PTP_ANNOUNCE_GRANDMASTER_IDENTITY(x) x+19 /*!< Gets Grandmaster identity offset on announce fields*/
-#define PTP_ANNOUNCE_STEPS_REMOVED(x) x+27 /*!< Gets steps removed offset on announce fields*/
-#define PTP_ANNOUNCE_TIME_SOURCE(x) x+29 /*!< Gets time source offset on announce fields*/
-
-#define PTP_SYNC_OFFSET 34 /*!< PTP SYNC base offset */
-#define PTP_SYNC_LENGTH 10 /*!< PTP SYNC length in bytes */
-#define PTP_SYNC_SEC_MS(x) x /*!< PTP SYNC seconds MSB offset */
-#define PTP_SYNC_SEC_LS(x) x+2 /*!< PTP SYNC seconds LSB offset */
-#define PTP_SYNC_NSEC(x) x+6 /*!< PTP SYNC nanoseconds offset */
-
-#define PTP_FOLLOWUP_OFFSET 34 /*!< PTP FOLLOWUP base offset */
-#define PTP_FOLLOWUP_LENGTH 10 /*!< PTP FOLLOWUP length in bytes */
-#define PTP_FOLLOWUP_SEC_MS(x) x /*!< Gets the followup seconds MSB offset */
-#define PTP_FOLLOWUP_SEC_LS(x) x+2 /*!< Gets the followup seconds LSB offset */
-#define PTP_FOLLOWUP_NSEC(x) x+6 /*!< Gets tne followup nanoseconds offset */
-
-#define PTP_PDELAY_REQ_OFFSET 34 /*!< PTP PDELAY REQUEST base offset */
-#define PTP_PDELAY_REQ_LENGTH 20 /*!< PTP PDELAY REQUEST length in bytes */
-#define PTP_PDELAY_REQ_SEC_MS(x) x /*!< Gets the pdelay request seconds MSB offset */
-#define PTP_PDELAY_REQ_SEC_LS(x) x+2 /*!< Gets the pdelay request seconds LSB offset */
-#define PTP_PDELAY_REQ_NSEC(x) x+6 /*!< Gets the pdelay request nanoseconds offset */
-
-#define PTP_PDELAY_RESP_OFFSET 34 /*!< PDELAY RESPONSE base offset */
-#define PTP_PDELAY_RESP_LENGTH 20 /*!< PDELAY RESPONSE length in bytes */
-#define PTP_PDELAY_RESP_SEC_MS(x) x /*!< Gets the pdelay response seconds MSB offset */
-#define PTP_PDELAY_RESP_SEC_LS(x) x+2 /*!< Gets the pdelay response seconds LSB offset */
-#define PTP_PDELAY_RESP_NSEC(x) x+6 /*!< Gets the pdelay nanoseconds offset */
-#define PTP_PDELAY_RESP_REQ_CLOCK_ID(x) x+10 /*!< Gets the pdelay response request clock id offset */
-#define PTP_PDELAY_RESP_REQ_PORT_ID(x) x+18 /*!< Gets the pdelay response request port id offset */
-
-#define PTP_PDELAY_FOLLOWUP_OFFSET 34 /*!< PTP PDELAY FOLLOWUP base offset*/
-#define PTP_PDELAY_FOLLOWUP_LENGTH 20 /*!< PTP PDELAY FOLLOWUP length in bytes */
-#define PTP_PDELAY_FOLLOWUP_SEC_MS(x) x /*!< Gets the pdelay followup seconds MSB offset*/
-#define PTP_PDELAY_FOLLOWUP_SEC_LS(x) x+2 /*!< Gets the pdelay followup seconds LSB offset*/
-#define PTP_PDELAY_FOLLOWUP_NSEC(x) x+6 /*!< Gets the pdelay followup nanoseconds offset*/
-#define PTP_PDELAY_FOLLOWUP_REQ_CLOCK_ID(x) x+10 /*!< Gets the pdelay followup request clock id offset*/
-#define PTP_PDELAY_FOLLOWUP_REQ_PORT_ID(x) x+18 /*!< Gets the pdelay followup request port id offset*/
-
-#define PTP_SIGNALLING_OFFSET 34 /*!< PTP signalling offset */
-#define PTP_SIGNALLING_LENGTH 10 /*!< PTP signalling length in bytes */
-#define PTP_SIGNALLING_TARGET_PORT_IDENTITY(x) x /*!< PTP signalling Tareget Port Identity */
-
-#define PTP_LI_61_BYTE 1 /*!< PTP_LI_61(leap61) byte offset on flags field */
-#define PTP_LI_61_BIT 0 /*!< PTP_LI_61(leap61) bit offset on PTP_LI_61 byte*/
-#define PTP_LI_59_BYTE 1 /*!< PTP_LI_59(leap59) byte offset on flags field*/
-#define PTP_LI_59_BIT 1 /*!< PTP_LI_59(leap59) bit offset on PTP_LI_59 byte*/
-#define PTP_ASSIST_BYTE 0 /*!< PTP_ASSIST(two step flag) byte offset on flags field*/
-#define PTP_ASSIST_BIT 1 /*!< PTP_ASSIST(two step flag) bit on PTP_ASSIST byte*/
-#define PTP_PTPTIMESCALE_BYTE 1 /*!< PTPTIMESCALE byte offset on flags field*/
-#define PTP_PTPTIMESCALE_BIT 3 /*!< PTPTIMESCAPE bit offset on PTPTIMESCALE byte*/
-
-#define TX_TIMEOUT_BASE 1000 /*!< Timeout base in microseconds */
-#define TX_TIMEOUT_ITER 6 /*!< Number of timeout iteractions for sending/receiving messages*/
-
-/**
- * @brief Enumeration message type. IEEE 1588-2008 Clause 13.3.2.2
- */
-enum MessageType {
- SYNC_MESSAGE = 0,
- DELAY_REQ_MESSAGE = 1,
- PATH_DELAY_REQ_MESSAGE = 2,
- PATH_DELAY_RESP_MESSAGE = 3,
- FOLLOWUP_MESSAGE = 8,
- DELAY_RESP_MESSAGE = 9,
- PATH_DELAY_FOLLOWUP_MESSAGE = 0xA,
- ANNOUNCE_MESSAGE = 0xB,
- SIGNALLING_MESSAGE = 0xC,
- MANAGEMENT_MESSAGE = 0xD,
-};
-
-/**
- * @brief Enumeration legacy message type
- */
-enum LegacyMessageType {
- SYNC,
- DELAY_REQ,
- FOLLOWUP,
- DELAY_RESP,
- MANAGEMENT,
- MESSAGE_OTHER
-};
-
-/**
- * @brief Enumeration multicast type.
- */
-enum MulticastType {
- MCAST_NONE,
- MCAST_PDELAY,
- MCAST_TEST_STATUS,
- MCAST_OTHER
-};
-
-class PTPMessageId {
- MessageType _messageType;
- uint16_t _sequenceId;
-public:
- PTPMessageId() { };
- PTPMessageId(MessageType messageType, uint16_t sequenceId) :
- _messageType(messageType),_sequenceId(sequenceId) { }
- PTPMessageId(const PTPMessageId& a) {
- _messageType = a._messageType;
- _sequenceId = a._sequenceId;
- }
-
- MessageType getMessageType(void) {
- return _messageType;
- }
- void setMessageType(MessageType messageType) {
- _messageType = messageType;
- }
-
- uint16_t getSequenceId(void) {
- return _sequenceId;
- }
- void setSequenceId(uint16_t sequenceId) {
- _sequenceId = sequenceId;
- }
-
- bool operator!=(const PTPMessageId & cmp) const {
- return
- this->_sequenceId != cmp._sequenceId ||
- this->_messageType != cmp._messageType ? true : false;
- }
- bool operator==(const PTPMessageId & cmp)const {
- return
- this->_sequenceId == cmp._sequenceId &&
- this->_messageType == cmp._messageType ? true : false;
- }
-};
-
-/**
- * @brief Builds PTP message from buffer
- * @param buf [in] byte buffer containing PTP message
- * @param size [in] length of buffer in bytes
- * @param remote [in] address from where message was received
- * @param port [in] port object that message was recieved on
- * @return PTP message object
- */
-PTPMessageCommon *buildPTPMessage
-( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-
-/**
- * @brief Provides the PTPMessage common interface used during building of
- * PTP messages.
- */
-class PTPMessageCommon {
-protected:
- unsigned char versionPTP; /*!< PTP version */
- uint16_t versionNetwork; /*!< Network version */
- MessageType messageType; /*!< MessageType to be built */
-
- PortIdentity *sourcePortIdentity; /*!< PortIdentity from source*/
-
- uint16_t sequenceId; /*!< PTP message sequence ID*/
- LegacyMessageType control; /*!< Control message type of LegacyMessageType */
- unsigned char flags[2]; /*!< PTP flags field */
-
- uint16_t messageLength; /*!< PTP message length */
- char logMeanMessageInterval; /*!< LogMessageInterval (IEEE 1588-2008 table 24)*/
- long long correctionField; /*!< Correction Field (IEEE 1588-2008 table 21) */
- unsigned char domainNumber; /*!< PTP domain number */
-
- Timestamp _timestamp; /*!< PTP message timestamp */
- unsigned _timestamp_counter_value; /*!< PTP timestamp counter value */
- bool _gc; /*!< Garbage collection flag */
-
- /**
- * @brief Default constructor
- */
- PTPMessageCommon(void) { };
- public:
- /**
- * @brief Creates the PTPMessageCommon interface
- * @param port EtherPort where the message interface is
- * connected to.
- */
- PTPMessageCommon( CommonPort *port );
- /**
- * @brief Destroys PTPMessageCommon interface
- */
- virtual ~PTPMessageCommon(void);
-
- /**
- * @brief Gets a pointer to the flags field within the PTP message.
- * @return Pointer to the flags field
- */
- unsigned char *getFlags(void) {
- return flags;
- }
-
- /**
- * @brief Gets the sequenceId value within a ptp message
- * @return Sequence ID value
- */
- uint16_t getSequenceId(void) {
- return sequenceId;
- }
- /**
- * @brief Sets the sequence ID value to the PTP message.
- * @param seq Sequence id value to be set.
- * @return void
- */
- void setSequenceId(uint16_t seq) {
- sequenceId = seq;
- }
-
- /**
- * @brief Gets the MessageType field within the PTP message.
- * @return MessageType
- */
- MessageType getMessageType(void) {
- return messageType;
- }
-
- /**
- * @brief Check if message type is event
- * @return true if an event message
- */
- bool isEvent( void )
- {
- return (( messageType >> 3) & 0x1 ) == 0;
- }
-
- /**
- * @brief Get TX timestamp
- * @param port used to send message
- * @param link_speed link speed of message
- */
- bool getTxTimestamp( EtherPort *port, uint32_t link_speed );
-
- /**
- * @brief Gets the MessageID of the PTP message.
- * @return MessageId
- */
- PTPMessageId getMessageId(void) {
- return PTPMessageId(messageType, sequenceId);
- }
- /**
- * @brief Gets the correctionField value in a Little-Endian format.
- * @return correctionField
- * @todo Little endian format could be removed by adding endianess discovery on
- * compile/run time.
- */
- long long getCorrectionField(void) {
- return correctionField;
- }
- /**
- * @brief Sets the correction field. It expects the host format.
- * @param correctionAmount
- * @return void
- * @todo Little endian format could be removed by adding endianess discovery on
- * compile/run time.
- */
- void setCorrectionField(long long correctionAmount) {
- correctionField = correctionAmount;
- }
-
- /**
- * @brief Gets PortIdentity field
- * @param identity [out] Source port identity
- * @return void
- */
- void getPortIdentity(PortIdentity * identity);
- /**
- * @brief Sets PortIdentity value
- * @param identity [in] Source port identity value to be set.
- * @return void
- */
- void setPortIdentity(PortIdentity * identity);
-
- /**
- * @brief Gets the current Timestamp value from the PTP message
- * @return Current Timestamp value
- */
- Timestamp getTimestamp(void) {
- return _timestamp;
- }
- /**
- * @brief Gets the timestamp counter value set during the RX timestamp method.
- * @return timestamp counter value
- */
- uint32_t getTimestampCounterValue(void) {
- return _timestamp_counter_value;;
- }
- /**
- * @brief Sets the timestamp value
- * @param timestamp [in] Reference to Timestamp value
- * @return void
- */
- void setTimestamp(Timestamp & timestamp) {
- _timestamp = timestamp;
- }
-
- /**
- * @brief Gets the garbage collection status
- * @return TRUE when it needs to be clean. FALSE otherwise.
- */
- bool garbage() {
- return _gc;
- }
-
- /**
- * @brief Determine whether the message was sent by given communication technology, uuid, and
- * port id fields
- * @param portIdentity PortIdentity value
- * @return TRUE if sender equals to internal PTPCommon values, FALSE otherwise.
- */
- bool isSenderEqual(PortIdentity portIdentity);
-
- /**
- * @brief Generic interface for processing PTP message
- * @param port CommonPort object
- * @return void
- */
- virtual void processMessage( CommonPort *port );
-
- /**
- * @brief Builds PTP common header
- * @param buf [out] PTP message
- * @return void
- */
- void buildCommonHeader(uint8_t * buf);
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/*Exact fit. No padding*/
-#pragma pack(push,1)
-
-#define PATH_TRACE_TLV_TYPE 0x8 /*!< This is the value that indicates the
- TLV is a path trace TLV, as specified in
- 16.2.7.1 and Table 34 of IEEE Std
- 1588-2008. The value is specified there
- as PATH_TRACE, whose value is 0x8. */
-
-/**
- * @brief Provides the PathTraceTLV interface
- * The fields of the path TLV shall be as specified in Table 10-8 and in
- * 10.5.4.3.2 through 10.5.4.3.9 from IEEE 802.1AS. This TLV,
- * and its use, are defined in IEEE Std 1588-2008 (see 16.2 and Table 34 of IEEE Std 1588-2008).
- */
-class PathTraceTLV {
- private:
- uint16_t tlvType;
- typedef std::list<ClockIdentity> IdentityList;
- IdentityList identityList;
- public:
- /**
- * @brief Creates the PathTraceTLV interface.
- * Sets tlvType to PATH_TRACE_TLV_TYPE using network byte order
- */
- PathTraceTLV() {
- tlvType = PLAT_htons(PATH_TRACE_TLV_TYPE);
- }
- /**
- * @brief Parses ClockIdentity from message buffer
- * @param buffer [in] Message buffer. It should be at least ::PTP_CLOCK_IDENTITY_LENGTH bytes long.
- * @param size [in] Buffer size. Should be the length of the data pointed to by the buffer argument.
- * @return void
- */
- void parseClockIdentity(uint8_t *buffer, int size) {
- int length = PLAT_ntohs(*(uint16_t*)buffer);
-
- buffer += sizeof(uint16_t);
- size -= sizeof(uint16_t);
-
- if((unsigned)size < (unsigned)length) {
- length = size;
- }
- length /= PTP_CLOCK_IDENTITY_LENGTH;
-
- for(; length > 0; --length) {
- ClockIdentity add;
- add.set(buffer);
- identityList.push_back(add);
- buffer += PTP_CLOCK_IDENTITY_LENGTH;
- }
- }
-
- /**
- * @brief Appends new ClockIdentity to internal ClockIdentity list
- * @param id ClockIdentity to be appended
- * @return void
- */
- void appendClockIdentity(ClockIdentity * id) {
- identityList.push_back(*id);
- }
-
- /**
- * @brief Gets TLV value in a byte string format
- * @param byte_str [out] Output byte string
- * @return void
- */
- void toByteString(uint8_t * byte_str) {
- IdentityList::iterator iter;
- *((uint16_t *)byte_str) = tlvType; // tlvType already in network byte order
- byte_str += sizeof(tlvType);
- *((uint16_t *)byte_str) = PLAT_htons
- ((uint16_t)identityList.size()*PTP_CLOCK_IDENTITY_LENGTH);
- byte_str += sizeof(uint16_t);
- for
- (iter = identityList.begin();
- iter != identityList.end(); ++iter) {
- iter->getIdentityString(byte_str);
- byte_str += PTP_CLOCK_IDENTITY_LENGTH;
- }
- }
-
- /**
- * @brief Looks for a specific ClockIdentity on the current TLV
- * @param id [in] Desired ClockIdentity
- * @return TRUE if it has found it, FALSE otherwise.
- */
- bool has(ClockIdentity *id) {
- return std::find
- (identityList.begin(), identityList.end(), *id) !=
- identityList.end();
- }
-
- /**
- * @brief Gets the total length of TLV.
- * Total length of TLV is length of type field (UINT16) + length of 'length'
- * field (UINT16) + length of
- * identities (each PTP_CLOCK_IDENTITY_LENGTH) in the path
- * @return Total length
- */
- int length() {
- return (int)(2*sizeof(uint16_t) + PTP_CLOCK_IDENTITY_LENGTH*identityList.size());
- }
-};
-
-/* back to whatever the previous packing mode was */
-#pragma pack(pop)
-
-/**
- * @brief Provides the PTPMessageAnnounce interface
- * The PTPMessageAnnounce class is used to create
- * announce messages on the 802.1AS format when building
- * the ptp messages.
- */
-class PTPMessageAnnounce:public PTPMessageCommon {
- private:
- uint8_t grandmasterIdentity[PTP_CLOCK_IDENTITY_LENGTH];
- ClockQuality *grandmasterClockQuality;
-
- PathTraceTLV tlv;
-
- uint16_t currentUtcOffset;
- unsigned char grandmasterPriority1;
- unsigned char grandmasterPriority2;
- ClockQuality *clockQuality;
- uint16_t stepsRemoved;
- unsigned char timeSource;
-
- PTPMessageAnnounce(void);
- public:
- /**
- * @brief Creates the PTPMessageAnnounce interface
- */
- PTPMessageAnnounce( CommonPort * port );
-
- /**
- * @brief Destroys the PTPMessageAnnounce interface
- */
- ~PTPMessageAnnounce();
-
- /**
- * @brief Compare gramdmaster's capabilities comming on the
- * announce messages against the current grandmaster capabilities.
- * @param msg [in] PTPMessageAnnounce to be compared
- * @return TRUE if it is better. FALSE otherwise.
- */
- bool isBetterThan(PTPMessageAnnounce * msg);
-
- /**
- * @brief Gets grandmaster's priority1 value
- * @return Grandmaster priority1
- */
- unsigned char getGrandmasterPriority1(void) {
- return grandmasterPriority1;
- }
-
- /**
- * @brief Gets grandmaster's priority2 value
- * @return Grandmaster priority2
- */
- unsigned char getGrandmasterPriority2(void) {
- return grandmasterPriority2;
- }
-
- /**
- * @brief Gets grandmaster clock quality
- * @return Pointer to a ClockQuality object.
- */
- ClockQuality *getGrandmasterClockQuality(void) {
- return grandmasterClockQuality;
- }
-
- /**
- * @brief Gets the steps removed value. See IEEE 802.1AS-2011 Clause 10.3.3
- * @return steps removed value
- */
- uint16_t getStepsRemoved(void) {
- return stepsRemoved;
- }
-
- /**
- * @brief Gets grandmaster identity value
- * @param identity [out] Grandmaster identity
- * @return void
- */
- void getGrandmasterIdentity(char *identity) {
- memcpy(identity, grandmasterIdentity, PTP_CLOCK_IDENTITY_LENGTH);
- }
-
- /**
- * @brief Gets grandmaster's clockIdentity value
- * @return Grandmaster ClockIdentity
- */
- ClockIdentity getGrandmasterClockIdentity() {
- ClockIdentity ret;
- ret.set( grandmasterIdentity );
- return ret;
- }
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Assembles PTPMessageAnnounce message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( CommonPort *port, PortIdentity *destIdentity);
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/**
- * @brief Provides a class for building the PTP Sync message
- */
-class PTPMessageSync : public PTPMessageCommon {
- private:
- Timestamp originTimestamp;
-
- PTPMessageSync();
- public:
- /**
- * @brief Default constructor. Creates PTPMessageSync
- * @param port EtherPort
- */
- PTPMessageSync( EtherPort *port );
-
- /**
- * @brief Destroys PTPMessageSync interface
- */
- ~PTPMessageSync();
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Gets origin timestamp value
- * @return Origin Timestamp
- */
- Timestamp getOriginTimestamp(void) {
- return originTimestamp;
- }
-
- /**
- * @brief Assembles PTPMessageSync message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- (EtherPort *port, PortIdentity *destIdentity );
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/* Exact fit. No padding*/
-#pragma pack(push,1)
-
-/**
- * @brief Provides a scaledNs interface
- * The scaledNs type represents signed values of time and time interval in units of 2e-16 ns.
- */
-class scaledNs {
- private:
- int32_t ms;
- uint64_t ls;
- public:
- /**
- * @brief Builds scaledNs interface
- */
- scaledNs() {
- ms = 0;
- ls = 0;
- }
-
- /**
- * @brief Gets scaledNs in a byte string format
- * @param byte_str [out] scaledNs value
- * @return void
- */
- void toByteString(uint8_t * byte_str) {
- memcpy(byte_str, this, sizeof(*this));
- }
-
- /**
- * @brief Overloads the operator = for this class
- * @param other Value to be attributed to this object's instance.
- * @return Reference to scaledNs object
- */
- scaledNs& operator=(const scaledNs& other)
- {
- this->ms = other.ms;
- this->ls = other.ls;
-
- return *this;
- }
-
- /**
- * @brief Set the lowest 64bits from the scaledNs object
- * @param lsb Value to be set
- * @return void
- */
- void setLSB(uint64_t lsb)
- {
- this->ls = lsb;
- }
-
- /**
- * @brief Set the highest 32bits of the scaledNs object
- * @param msb 32-bit signed integer to be set
- * @return void
- */
- void setMSB(int32_t msb)
- {
- this->ms = msb;
- }
-};
-
-/**
- * @brief Provides a follow-up TLV interface back to the previous packing mode
- */
-class FollowUpTLV {
- private:
- uint16_t tlvType;
- uint16_t lengthField;
- uint8_t organizationId[3];
- uint8_t organizationSubType_ms;
- uint16_t organizationSubType_ls;
- int32_t cumulativeScaledRateOffset;
- uint16_t gmTimeBaseIndicator;
- scaledNs scaledLastGmPhaseChange;
- int32_t scaledLastGmFreqChange;
- public:
- /**
- * @brief Builds the FollowUpTLV interface
- */
- FollowUpTLV() {
- tlvType = PLAT_htons(0x3);
- lengthField = PLAT_htons(28);
- organizationId[0] = '\x00';
- organizationId[1] = '\x80';
- organizationId[2] = '\xC2';
- organizationSubType_ms = 0;
- organizationSubType_ls = PLAT_htons(1);
- cumulativeScaledRateOffset = PLAT_htonl(0);
- gmTimeBaseIndicator = 0;
- scaledLastGmFreqChange = PLAT_htonl(0);
- }
-
- /**
- * @brief Gets FollowUpTLV information in a byte string format
- * @param byte_str [out] FollowUpTLV values
- */
- void toByteString(uint8_t * byte_str) {
- memcpy(byte_str, this, sizeof(*this));
- }
-
- /**
- * @brief Gets the cummulative scaledRateOffset
- * @return 32 bit signed value with the rate offset information.
- */
- int32_t getRateOffset() {
- return cumulativeScaledRateOffset;
- }
-
- /**
- * @brief Gets the gmTimeBaseIndicator
- * @return 16 bit unsigned value of the gmTimeBaseIndicator
- * information
- */
- uint16_t getGmTimeBaseIndicator() {
- return gmTimeBaseIndicator;
- }
-
- /**
- * @brief Updates the scaledLastGmFreqChanged private member
- * @param val Value to be set
- * @return void
- */
- void setScaledLastGmFreqChange(int32_t val)
- {
- scaledLastGmFreqChange = PLAT_htonl(val);
- }
-
- /**
- * @brief Gets the current scaledLastGmFreqChanged value
- * @return scaledLastGmFreqChange
- */
- int32_t getScaledLastGmFreqChange(void)
- {
- return scaledLastGmFreqChange;
- }
-
- /**
- * @brief Sets the gmTimeBaseIndicator private member
- * @param tbi Value to be set
- * @return void
- */
- void setGMTimeBaseIndicator(uint16_t tbi)
- {
- gmTimeBaseIndicator = tbi;
- }
-
- /**
- * @brief Incremets the Time Base Indicator member
- * @return void
- */
- void incrementGMTimeBaseIndicator(void)
- {
- ++gmTimeBaseIndicator;
- }
-
- /**
- * @brief Gets the current gmTimeBaseIndicator value
- * @return gmTimeBaseIndicator
- */
- uint16_t getGMTimeBaseIndicator(void)
- {
- return gmTimeBaseIndicator;
- }
-
- /**
- * @brief Sets the scaledLastGmPhaseChange private member
- * @param pc Value to be set
- * @return void
- */
- void setScaledLastGmPhaseChange(scaledNs pc)
- {
- scaledLastGmPhaseChange = pc;
- }
-
- /**
- * @brief Gets the scaledLastGmPhaseChange private member value
- * @return scaledLastGmPhaseChange value
- */
- scaledNs getScaledLastGmPhaseChange(void)
- {
- return scaledLastGmPhaseChange;
- }
-};
-
-/* back to whatever the previous packing mode was */
-#pragma pack(pop)
-
-/**
- * @brief Provides a class for a class for building a PTP follow up message
- */
-class PTPMessageFollowUp:public PTPMessageCommon {
-private:
- Timestamp preciseOriginTimestamp;
-
- FollowUpTLV tlv;
-
- PTPMessageFollowUp(void) { }
-public:
- /**
- * @brief Builds the PTPMessageFollowUP object
- */
- PTPMessageFollowUp( CommonPort *port );
-
- /**
- * @brief write followup message into buffer
- * @param port [in] associated CommonPort object
- * @param buf_ptr [out] buffer to write data to
- * @return number of bytes written to buffer
- */
- size_t buildMessage(CommonPort *port, uint8_t *buf_ptr);
-
- /**
- * @brief Assembles PTPMessageFollowUp message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( EtherPort *port, PortIdentity *destIdentity );
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Processes PTP messages
- * @param port [in] CommonPort
- * @param receipt [in] local time message was received
- * @param delay
- * @return void
- */
- void processMessage( CommonPort *port, Timestamp receipt );
-
- /**
- * @brief Gets the precise origin timestamp value
- * @return preciseOriginTimestamp value
- */
- Timestamp getPreciseOriginTimestamp(void) {
- return preciseOriginTimestamp;
- }
-
- /**
- * @brief Sets the precis origin timestamp value
- * @param timestamp Timestamp to be set
- * @return void
- */
- void setPreciseOriginTimestamp(Timestamp & timestamp) {
- preciseOriginTimestamp = timestamp;
- }
-
- /**
- * @brief Sets the clock source time interface (802.1AS 9.2)
- * @param fup Follow up message
- * @return void
- */
- void setClockSourceTime(FollowUpTLV *fup)
- {
- tlv.setGMTimeBaseIndicator(fup->getGMTimeBaseIndicator());
- tlv.setScaledLastGmFreqChange(fup->getScaledLastGmFreqChange());
- tlv.setScaledLastGmPhaseChange(fup->getScaledLastGmPhaseChange());
- }
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/**
- * @brief Provides a class for building the PTP Path Delay Request message
- */
-class PTPMessagePathDelayReq : public PTPMessageCommon {
- private:
- Timestamp originTimestamp;
-
- PTPMessagePathDelayReq() {
- return;
- }
- public:
- /**
- * @brief Destroys the PTPMessagePathDelayReq object
- */
- ~PTPMessagePathDelayReq() {
- }
-
- /**
- * @brief Builds the PTPMessagePathDelayReq message
- */
- PTPMessagePathDelayReq( EtherPort *port );
-
- /**
- * @brief Assembles PTPMessagePathDelayReq message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( EtherPort *port, PortIdentity *destIdentity );
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Gets origin timestamp value
- * @return Origin Timestamp
- */
- Timestamp getOriginTimestamp(void) {
- return originTimestamp;
- }
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/**
- * @brief Provides a class for building the PTP Path Delay Response message.
- */
-class PTPMessagePathDelayResp:public PTPMessageCommon {
-private:
- PortIdentity * requestingPortIdentity;
- Timestamp requestReceiptTimestamp;
-
- PTPMessagePathDelayResp(void) {
- }
-public:
- /**
- * @brief Destroys the PTPMessagePathDelayResp object
- */
- ~PTPMessagePathDelayResp();
- /**
- * @brief Builds the PTPMessagePathDelayResp object
- */
- PTPMessagePathDelayResp( EtherPort *port );
-
- /**
- * @brief Assembles PTPMessagePathDelayResp message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( EtherPort *port, PortIdentity *destIdentity );
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Sets the request receipt timestamp
- * @param timestamp Timestamp to be set
- * @return void
- */
- void setRequestReceiptTimestamp(Timestamp timestamp) {
- requestReceiptTimestamp = timestamp;
- }
-
- /**
- * @brief Sets requesting port identity
- * @param identity [in] PortIdentity to be set
- * @return void
- */
- void setRequestingPortIdentity(PortIdentity * identity);
- /**
- * @brief Gets requesting port identity
- * @param identity [out] Requested PortIdentity
- * @return void
- */
- void getRequestingPortIdentity(PortIdentity * identity);
-
- /**
- * @brief Gets the request receipt timestamp
- * @return requestReceiptTimestamp
- */
- Timestamp getRequestReceiptTimestamp(void) {
- return requestReceiptTimestamp;
- }
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/**
- * @brief Provides a class for building the PTP Path Delay Response follow up message.
- */
-class PTPMessagePathDelayRespFollowUp:public PTPMessageCommon {
- private:
- Timestamp responseOriginTimestamp;
- PortIdentity *requestingPortIdentity;
-
- PTPMessagePathDelayRespFollowUp(void) { }
-
-public:
- /**
- * @brief Builds the PTPMessagePathDelayRespFollowUp object
- */
- PTPMessagePathDelayRespFollowUp( EtherPort *port );
-
- /**
- * @brief Destroys the PTPMessagePathDelayRespFollowUp object
- */
- ~PTPMessagePathDelayRespFollowUp();
-
- /**
- * @brief Assembles PTPMessageRespFollowUp message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( EtherPort *port, PortIdentity *destIdentity );
-
- void processMessage( CommonPort *port );
-
- /**
- * @brief Sets the response origin timestamp
- * @param timestamp Timestamp to be set
- * @return void
- */
- void setResponseOriginTimestamp(Timestamp timestamp) {
- responseOriginTimestamp = timestamp;
- }
- /**
- * @brief Sets the requesting port identity
- * @param identity [in] PortIdentity to be set
- * @return void
- */
- void setRequestingPortIdentity(PortIdentity * identity);
-
- /**
- * @brief Gets the response origin timestamp
- * @return responseOriginTimestamp
- */
- Timestamp getResponseOriginTimestamp(void) {
- return responseOriginTimestamp;
- }
- /**
- * @brief Gets the requesting port identity
- * @return Pointer to requesting PortIdentity object
- */
- PortIdentity *getRequestingPortIdentity(void) {
- return requestingPortIdentity;
- }
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-/*Exact fit. No padding*/
-#pragma pack(push,1)
-
-
-/**
- * @brief Provides a Signalling Msg Interval Request TLV interface back to the previous
- * packing mode
- */
-class SignallingTLV {
- private:
- uint16_t tlvType;
- uint16_t lengthField;
- uint8_t organizationId[3];
- uint8_t organizationSubType_ms;
- uint16_t organizationSubType_ls;
- uint8_t linkDelayInterval;
- uint8_t timeSyncInterval;
- uint8_t announceInterval;
- uint8_t flags;
- uint16_t reserved;
- public:
- /**
- * @brief Builds the Signalling Msg Interval Request TLV interface
- */
- SignallingTLV() {
- tlvType = PLAT_htons(0x3);
- lengthField = PLAT_htons(12);
- organizationId[0] = '\x00';
- organizationId[1] = '\x80';
- organizationId[2] = '\xC2';
- organizationSubType_ms = 0;
- organizationSubType_ls = PLAT_htons(2);
- linkDelayInterval = 0;
- timeSyncInterval = 0;
- announceInterval = 0;
- flags = 3;
- reserved = PLAT_htons(0);
- }
-
- /**
- * @brief Gets Msg Interval Request TLV information in a byte
- * string format
- * @param byte_str [out] Msg Interval Request TLV values
- */
- void toByteString(uint8_t * byte_str) {
- memcpy(byte_str, this, sizeof(*this));
- }
-
- /**
- * @brief Gets the link delay interval.
- * @return 8 bit signed value of the link delay interval.
- */
- int8_t getLinkDelayInterval() {
- return linkDelayInterval;
- }
-
- /**
- * @brief Sets the link delay interval.
- * @param 8 bit signed value of the link delay interval.
- * @return void
- */
- void setLinkDelayInterval(int8_t linkDelayInterval) {
- this->linkDelayInterval = linkDelayInterval;
- }
-
- /**
- * @brief Gets the time sync interval.
- * @return 8 bit signed value of the time sync interval.
- */
- int8_t getTimeSyncInterval() {
- return timeSyncInterval;
- }
-
- /**
- * @brief Sets the time sync interval.
- * #param 8 bit signed value of the time sync interval.
- * @return void
- */
- void setTimeSyncInterval(int8_t timeSyncInterval) {
- this->timeSyncInterval = timeSyncInterval;
- }
-
- /**
- * @brief Gets the announce interval.
- * @return 8 bit signed value of the announce interval.
- */
- int8_t getAnnounceInterval() {
- return announceInterval;
- }
-
- /**
- * @brief Sets the announce interval.
- * @param 8 bit signed value of the announce interval.
- * @return void
- */
- void setAnnounceInterval(int8_t announceInterval) {
- this->announceInterval = announceInterval;
- }
-};
-
-/* back to whatever the previous packing mode was */
-#pragma pack(pop)
-
-/**
- * @brief Provides a class for building a PTP signalling message
- */
-class PTPMessageSignalling:public PTPMessageCommon {
-private:
- int8_t targetPortIdentify;
- SignallingTLV tlv;
-
- PTPMessageSignalling(void);
-public:
- static const int8_t sigMsgInterval_Initial = 126;
- static const int8_t sigMsgInterval_NoSend = 127;
- static const int8_t sigMsgInterval_NoChange = -128;
-
- /**
- * @brief Builds the PTPMessageSignalling object
- */
- PTPMessageSignalling( EtherPort *port );
-
- /**
- * @brief Destroys the PTPMessageSignalling object
- */
- ~PTPMessageSignalling();
-
- /**
- * @brief Sets the signalling intervals
- * @param linkDelayInterval link delay interval
- * @param timeSyncInterval Sync interval
- * @param announceInterval Announce interval
- * @return void
- */
- void setintervals(int8_t linkDelayInterval, int8_t timeSyncInterval, int8_t announceInterval);
-
- /**
- * @brief Assembles PTPMessageSignalling message on the
- * EtherPort payload
- * @param port EtherPort where the message will be
- * assembled
- * @param destIdentity [in] Destination PortIdentity
- * @return true on success
- */
- bool sendPort
- ( EtherPort *port, PortIdentity *destIdentity );
-
- void processMessage( CommonPort *port );
-
- friend PTPMessageCommon *buildPTPMessage
- ( char *buf, int size, LinkLayerAddress *remote, CommonPort *port );
-};
-
-#endif
diff --git a/daemons/gptp/common/avbts_oscondition.hpp b/daemons/gptp/common/avbts_oscondition.hpp
deleted file mode 100644
index 93511391..00000000
--- a/daemons/gptp/common/avbts_oscondition.hpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSSIGNAL_HPP
-#define AVBTS_OSSIGNAL_HPP
-
-/**@file*/
-
-/**
- * @brief Provides a generic interface for OS's locking condition
- */
-class OSCondition {
-private:
- int wait_count;
-public:
- /**
- * @brief Waits until a condition is met
- * @return TRUE after waiting
- */
- virtual bool wait() = 0;
-
- /**
- * @brief Waits for lock
- * @return TRUE after waiting
- */
- virtual bool wait_prelock() = 0;
-
- /**
- * @brief Sends a signal to unblock other threads
- * @return TRUE
- */
- virtual bool signal() = 0;
-
- /**
- * @brief Deletes previously declared flags
- */
- virtual ~OSCondition() = 0;
-protected:
- /**
- * @brief Default constructor. Initializes internal variables
- */
- OSCondition() {
- wait_count = 0;
- };
-
- /**
- * @brief Counts up waiting condition
- * @return void
- */
- void up() {
- ++wait_count;
- }
-
- /**
- * @brief Conds down waiting condition
- * @return void
- */
- void down() {
- --wait_count;
- }
-
- /**
- * @brief Checks if OS is waiting
- * @return TRUE if up counter is greater than zero. FALSE otherwise.
- */
- bool waiting() {
- return wait_count > 0;
- }
-};
-
-inline OSCondition::~OSCondition() { }
-
-/**
- * @brief Provides factory design patter for OS Condition class
- */
-class OSConditionFactory {
-public:
- /**
- * @brief Creates OSCondition class
- * @return Pointer to OSCondition object
- */
- virtual OSCondition *createCondition() const = 0;
-
- /**
- * @brief Destroys OSCondition objects
- */
- virtual ~OSConditionFactory() = 0;
-};
-
-inline OSConditionFactory::~OSConditionFactory() {}
-
-
-#endif
diff --git a/daemons/gptp/common/avbts_osipc.hpp b/daemons/gptp/common/avbts_osipc.hpp
deleted file mode 100644
index 2adb3dbd..00000000
--- a/daemons/gptp/common/avbts_osipc.hpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSIPC_HPP
-#define AVBTS_OSIPC_HPP
-
-#include <stdint.h>
-#include <ptptypes.hpp>
-
-/**@file*/
-
-/**
- * @brief Generic interface for Inter Process Communication arguments
- */
-class OS_IPC_ARG {
-public:
- virtual ~OS_IPC_ARG() = 0;
-};
-
-inline OS_IPC_ARG::~OS_IPC_ARG () { }
-
-/**
- * @brief Generic interface for Inter Process Communication
- */
-class OS_IPC {
-public:
- /**
- * @brief Initializes the IPC
- * @return Implementation dependent
- */
- virtual bool init( OS_IPC_ARG *arg = NULL ) = 0;
-
- /**
- * @brief Updates IPC values
- *
- * @param ml_phoffset Master to local phase offset
- * @param ls_phoffset Local to system phase offset
- * @param ml_freqoffset Master to local frequency offset
- * @param ls_freq_offset Local to system frequency offset
- * @param local_time Local time
- * @param sync_count Count of syncs
- * @param pdelay_count Count of pdelays
- * @param port_state Port's state
- * @param asCapable asCapable flag
- *
- * @return Implementation dependent.
- */
- virtual bool update(
- int64_t ml_phoffset,
- int64_t ls_phoffset,
- FrequencyRatio ml_freqoffset,
- FrequencyRatio ls_freq_offset,
- uint64_t local_time,
- uint32_t sync_count,
- uint32_t pdelay_count,
- PortState port_state,
- bool asCapable ) = 0;
-
- /**
- * @brief Updates grandmaster IPC values
- *
- * @param gptp_grandmaster_id Current grandmaster id (all 0's if no grandmaster selected)
- * @param gptp_domain_number gPTP domain number
- *
- * @return Implementation dependent.
- */
- virtual bool update_grandmaster(
- uint8_t gptp_grandmaster_id[],
- uint8_t gptp_domain_number ) = 0;
-
- /**
- * @brief Updates network interface IPC values
- *
- * @param clock_identity The clock identity of the interface
- * @param priority1 The priority1 field of the grandmaster functionality of the interface, or 0xFF if not supported
- * @param clock_class The clockClass field of the grandmaster functionality of the interface, or 0xFF if not supported
- * @param offset_scaled_log_variance The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported
- * @param clock_accuracy The clockAccuracy field of the grandmaster functionality of the interface, or 0xFF if not supported
- * @param priority2 The priority2 field of the grandmaster functionality of the interface, or 0xFF if not supported
- * @param domain_number The domainNumber field of the grandmaster functionality of the interface, or 0 if not supported
- * @param log_sync_interval The currentLogSyncInterval field of the grandmaster functionality of the interface, or 0 if not supported
- * @param log_announce_interval The currentLogAnnounceInterval field of the grandmaster functionality of the interface, or 0 if not supported
- * @param log_pdelay_interval The currentLogPDelayReqInterval field of the grandmaster functionality of the interface, or 0 if not supported
- * @param port_number The portNumber field of the interface, or 0x0000 if not supported
- *
- * @return Implementation dependent.
- */
- virtual bool update_network_interface(
- uint8_t clock_identity[],
- uint8_t priority1,
- uint8_t clock_class,
- int16_t offset_scaled_log_variance,
- uint8_t clock_accuracy,
- uint8_t priority2,
- uint8_t domain_number,
- int8_t log_sync_interval,
- int8_t log_announce_interval,
- int8_t log_pdelay_interval,
- uint16_t port_number ) = 0;
-
- /*
- * Destroys IPC
- */
- virtual ~OS_IPC() = 0;
-};
-
-inline OS_IPC::~OS_IPC() {}
-
-#endif
-
diff --git a/daemons/gptp/common/avbts_oslock.hpp b/daemons/gptp/common/avbts_oslock.hpp
deleted file mode 100644
index c53b904b..00000000
--- a/daemons/gptp/common/avbts_oslock.hpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2001-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSLOCK_HPP
-#define AVBTS_OSLOCK_HPP
-
-/**@file*/
-
-/**
- * @brief Lock type enumeration. The possible values are:
- * - oslock_recursive;
- * - oslock_nonrecursive;
- */
-typedef enum { oslock_recursive, oslock_nonrecursive } OSLockType;
-/**
- * @brief Lock result enumeration. The possible values are:
- * - oslock_ok;
- * - oslock_self;
- * - oslock_held;
- * - oslock_fail;
- */
-typedef enum { oslock_ok, oslock_self, oslock_held, oslock_fail } OSLockResult;
-
-/**
- * @brief Provides a generic mechanism for locking critical sections.
- */
-class OSLock {
- public:
- /**
- * @brief Locks a critical section
- * @return OSLockResult enumeration
- */
- virtual OSLockResult lock() = 0;
-
- /**
- * @brief Unlocks a critical section
- * @return OSLockResult enumeration
- */
- virtual OSLockResult unlock() = 0;
-
- /**
- * @brief Tries locking a critical section
- * @return OSLockResult enumeration
- */
- virtual OSLockResult trylock() = 0;
- protected:
- /**
- * @brief Default constructor
- */
- OSLock() { }
-
- /**
- * @brief Initializes locking mechanism
- * @param type Enumeration OSLockType
- * @return FALSE
- */
- bool initialize(OSLockType type) {
- return false;
- }
- virtual ~OSLock() = 0;
-};
-
-inline OSLock::~OSLock() {}
-
-/**
- * @brief Provides a factory pattern for OSLock
- */
-class OSLockFactory {
- public:
-
- /**
- * @brief Creates locking mechanism
- * @param type Enumeration OSLockType
- * @return Pointer to an enumeration of type OSLock
- */
- virtual OSLock *createLock(OSLockType type) const = 0;
- virtual ~OSLockFactory() = 0;
-};
-
-inline OSLockFactory::~OSLockFactory () {}
-
-#endif
diff --git a/daemons/gptp/common/avbts_osnet.cpp b/daemons/gptp/common/avbts_osnet.cpp
deleted file mode 100644
index 6c930d70..00000000
--- a/daemons/gptp/common/avbts_osnet.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <avbts_osnet.hpp>
-
-std::map
-< factory_name_t, OSNetworkInterfaceFactory * >
-OSNetworkInterfaceFactory::factoryMap;
diff --git a/daemons/gptp/common/avbts_osnet.hpp b/daemons/gptp/common/avbts_osnet.hpp
deleted file mode 100644
index eb3194cb..00000000
--- a/daemons/gptp/common/avbts_osnet.hpp
+++ /dev/null
@@ -1,396 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSNET_HPP
-#define AVBTS_OSNET_HPP
-
-#include <stdint.h>
-#include <string.h>
-#include <map>
-#include <ieee1588.hpp>
-#include <ptptypes.hpp>
-
-/**@file*/
-
-class CommonTimestamper;
-
-#define FACTORY_NAME_LENGTH 48 /*!< Factory name maximum length */
-#define DEFAULT_TIMEOUT 1 /*!< Default timeout in milliseconds*/
-
-/**
- * @brief LinkLayerAddress Class
- * Provides methods for initializing and comparing ethernet addresses.
- */
-class LinkLayerAddress:public InterfaceLabel {
- private:
- //!< Ethernet address
- uint8_t addr[ETHER_ADDR_OCTETS];
- public:
- /**
- * @brief Default constructor
- */
- LinkLayerAddress() {
- };
-
- /**
- * @brief Receives a 64bit scalar address and initializes its internal octet
- * array with the first 48 bits.
- * @param address_scalar 64 bit address
- */
- LinkLayerAddress(uint64_t address_scalar) {
- uint8_t *ptr;
- address_scalar <<= 16;
- if(addr == NULL)
- return;
-
- for (ptr = addr; ptr < addr + ETHER_ADDR_OCTETS; ++ptr) {
- *ptr = (address_scalar & 0xFF00000000000000ULL) >> 56;
- address_scalar <<= 8;
- }
- }
-
- /**
- * @brief Receives an address as an array of octets
- * and copies the first 6 over the internal ethernet address.
- * @param address_octet_array Array of octets containing the address
- */
- LinkLayerAddress(uint8_t * address_octet_array) {
- uint8_t *ptr;
- if( addr == NULL || address_octet_array == NULL)
- return;
-
- for (ptr = addr; ptr < addr + ETHER_ADDR_OCTETS;
- ++ptr, ++address_octet_array)
- {
- *ptr = *address_octet_array;
- }
- }
-
- /**
- * @brief Operator '==' overloading method.
- * It provides a comparison between cmp and the class ethernet address defined
- * at its constructor.
- * @param cmp Value to be compared against.
- * @return TRUE if they are equal; FALSE otherwise.
- */
- bool operator==(const LinkLayerAddress & cmp) const {
- return memcmp
- (this->addr, cmp.addr, ETHER_ADDR_OCTETS) == 0 ? true : false;
- }
-
- /**
- * @brief Operator '<' overloading method.
- ** It provides a comparison between cmp and the class ethernet address defined
- * at its constructor.
- * @param cmp Value to be compared against.
- * @return TRUE if cmp is lower than addr, FALSE otherwise.
- */
- bool operator<(const LinkLayerAddress & cmp)const {
- return memcmp
- (this->addr, cmp.addr, ETHER_ADDR_OCTETS) < 0 ? true : false;
- }
-
- /**
- * @brief Operator '>' overloading method.
- ** It provides a comparison between cmp and the class ethernet address defined
- * at its constructor.
- * @param cmp Value to be compared against.
- * @return TRUE if cmp is bigger than addr, FALSE otherwise.
- */
- bool operator>(const LinkLayerAddress & cmp)const {
- return memcmp
- (this->addr, cmp.addr, ETHER_ADDR_OCTETS) > 0 ? true : false;
- }
-
- /**
- * @brief Gets first 6 bytes from ethernet address of
- * object LinkLayerAddress.
- * @param address_octet_array [out] Pointer to store the
- * ethernet address information.
- * @return void
- */
- void toOctetArray(uint8_t * address_octet_array) {
- uint8_t *ptr;
- if(addr == NULL || address_octet_array == NULL)
- return;
- for (ptr = addr; ptr < addr + ETHER_ADDR_OCTETS;
- ++ptr, ++address_octet_array)
- {
- *address_octet_array = *ptr;
- }
- }
-};
-
-/**
- * @brief Provides methods for dealing with the network interface name
- * @todo: Destructor doesnt delete this->name.
- */
-class InterfaceName: public InterfaceLabel {
- private:
- //!< Interface name
- char *name;
- public:
- /**
- * @brief Default constructor
- */
- InterfaceName() { }
- /**
- * @brief Initializes Interface name with name and size lenght+1
- * @param name [in] String with the interface name
- * @param length Size of name
- */
- InterfaceName(char *name, int length) {
- this->name = new char[length + 1];
- PLAT_strncpy(this->name, name, length);
- }
- ~InterfaceName() {
- delete(this->name);
- }
-
- /**
- * @brief Operator '==' overloading method.
- * Compares parameter cmp to the interface name
- * @param cmp String to be compared
- * @return TRUE if they are equal, FALSE otherwise
- */
- bool operator==(const InterfaceName & cmp) const {
- return strcmp(name, cmp.name) == 0 ? true : false;
- }
-
- /**
- * @brief Operator '<' overloading method.
- * Compares cmp to the interface name
- * @param cmp String to be compared
- * @return TRUE if interface name is found to be less than cmd. FALSE otherwise
- */
- bool operator<(const InterfaceName & cmp)const {
- return strcmp(name, cmp.name) < 0 ? true : false;
- }
-
- /**
- * @brief Operator '>' overloading method.
- * Compares cmp to the interface name
- * @param cmp String to be compared
- * @return TRUE if the interface name is found to be greater than cmd. FALSE otherwise
- */
- bool operator>(const InterfaceName & cmp)const {
- return strcmp(name, cmp.name) > 0 ? true : false;
- }
-
- /**
- * @brief Gets interface name from the class' internal variable
- * @param string [out] String to store interface's name
- * @param length Length of string
- * @return TRUE if length is greater than size of interface name plus one. FALSE otherwise.
- */
- bool toString(char *string, size_t length) {
- if(string == NULL)
- return false;
-
- if (length >= strlen(name) + 1) {
- PLAT_strncpy(string, name, length);
- return true;
- }
- return false;
- }
-};
-
-/**
- * @brief Provides a generic class to be used as a key to create factory maps.
- */
-class factory_name_t {
- private:
- /*<! Factory name*/
- char name[FACTORY_NAME_LENGTH];
- factory_name_t();
- public:
- /**
- * @brief Assign a name to the factory_name
- * @param name_a [in] Name to be assigned to the object
- */
- factory_name_t(const char *name_a) {
- PLAT_strncpy(name, name_a, FACTORY_NAME_LENGTH - 1);
- }
-
- /**
- * @brief Operator '==' overloading method
- * Compares cmp to the factory name
- * @param cmp String to be compared
- * @return TRUE if they are equal, FALSE otherwise
- */
- bool operator==(const factory_name_t & cmp) {
- return strcmp(cmp.name, this->name) == 0 ? true : false;
- }
-
- /**
- * @brief Operator '<' overloading method
- * Compares cmp to the factory name
- * @param cmp String to be compared
- * @return TRUE if the factory_name is to be found less than cmp, FALSE otherwise
- */
- bool operator<(const factory_name_t & cmp)const {
- return strcmp(cmp.name, this->name) < 0 ? true : false;
- }
-
- /**
- * @brief Operator '>' overloading method
- * Compares cmp to the factory name
- * @param cmp String to be compared
- * @return TRUE if the factory_name is to be found greater than cmp, FALSE otherwise
- */
- bool operator>(const factory_name_t & cmp)const {
- return strcmp(cmp.name, this->name) > 0 ? true : false;
- }
-};
-
-/**
- * @brief Enumeration net_result:
- * - net_trfail
- * - net_fatal
- * - net_succeed
- */
-typedef enum { net_trfail, net_fatal, net_succeed } net_result;
-
-
-/**
- * @brief Enumeration net_link_event:
- * - net_linkup
- * - net_linkdown
- */
-typedef enum { NET_LINK_EVENT_DOWN, NET_LINK_EVENT_UP, NET_LINK_EVENT_FAIL } net_link_event;
-
-/**
- * @brief Provides a generic network interface
- */
-class OSNetworkInterface {
- public:
- /**
- * @brief Sends a packet to a remote address
- * @param addr [in] Remote link layer address
- * @param etherType [in] The EtherType of the message
- * @param payload [in] Data buffer
- * @param length Size of data buffer
- * @param timestamp TRUE if to use the event socket with the PTP multicast address. FALSE if to use
- * a general socket.
- */
- virtual net_result send
- (LinkLayerAddress * addr, uint16_t etherType, uint8_t * payload, size_t length,
- bool timestamp) = 0;
-
- /**
- * @brief Receives data
- * @param addr [out] Destination Mac Address
- * @param payload [out] Payload received
- * @param length [out] Received length
- * @return net_result enumeration
- */
- virtual net_result nrecv
- ( LinkLayerAddress *addr, uint8_t *payload, size_t &length ) = 0;
-
- /**
- * @brief Get Link Layer address (mac address)
- * @param addr [out] Link Layer address
- * @return void
- */
- virtual void getLinkLayerAddress(LinkLayerAddress * addr) = 0;
-
- /**
- * @brief Watch for netlink changes.
- */
- virtual void watchNetLink( CommonPort *pPort ) = 0;
-
- /**
- * @brief Provides generic method for getting the payload offset
- */
- virtual unsigned getPayloadOffset() = 0;
-
- /**
- * @brief Native support for polimorphic destruction
- */
- virtual ~OSNetworkInterface() = 0;
-};
-
-inline OSNetworkInterface::~OSNetworkInterface() {}
-
-class OSNetworkInterfaceFactory;
-
-/**
- * @brief Provides a map for the OSNetworkInterfaceFactory::registerFactory method
- */
-typedef std::map < factory_name_t, OSNetworkInterfaceFactory * >FactoryMap_t;
-
-/**
- * @brief Builds and registers a network interface
- */
-class OSNetworkInterfaceFactory {
- public:
- /**
- * @brief Registers network factory
- * @param id
- * @param factory Factory name
- * @return TRUE success, FALSE when could not register it.
- */
- static bool registerFactory
- (factory_name_t id, OSNetworkInterfaceFactory * factory) {
- FactoryMap_t::iterator iter = factoryMap.find(id);
- if (iter != factoryMap.end())
- return false;
- factoryMap[id] = factory;
- return true;
- }
-
- /**
- * @brief Builds the network interface
- * @param iface [out] Pointer to interface name
- * @param id Factory name index
- * @param iflabel Interface label
- * @param timestamper CommonTimestamper class pointer
- * @return TRUE ok, FALSE error.
- */
- static bool buildInterface
- (OSNetworkInterface ** iface, factory_name_t id, InterfaceLabel * iflabel,
- CommonTimestamper * timestamper) {
- return factoryMap[id]->createInterface
- (iface, iflabel, timestamper);
- }
- virtual ~OSNetworkInterfaceFactory() = 0;
-private:
- virtual bool createInterface
- (OSNetworkInterface ** iface, InterfaceLabel * iflabel,
- CommonTimestamper * timestamper) = 0;
- static FactoryMap_t factoryMap;
-};
-
-inline OSNetworkInterfaceFactory::~OSNetworkInterfaceFactory() { }
-
-#endif
diff --git a/daemons/gptp/common/avbts_osthread.hpp b/daemons/gptp/common/avbts_osthread.hpp
deleted file mode 100644
index 9464512f..00000000
--- a/daemons/gptp/common/avbts_osthread.hpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSTHREAD_HPP
-#define AVBTS_OSTHREAD_HPP
-
-/**@file*/
-
-/**
- * @brief thread exit codes. Possible values are:
- * - osthread_ok;
- * - osthread_error;
- */
-typedef enum { osthread_ok, osthread_error } OSThreadExitCode;
-
-/**
- * @brief Provides the OSThreadExitCode callback format
- */
-typedef OSThreadExitCode(*OSThreadFunction) (void *);
-typedef void *OSThreadFunctionArg;
-
-/**
- * @brief Provides a generic interface for threads
- */
-class OSThread {
-public:
- /**
- * @brief Starts a new thread
- * @param function Callback to be started on the thread
- * @param arg Function arguments
- * @return Implementation dependent
- */
- virtual bool start(OSThreadFunction function, void *arg) = 0;
-
- /**
- * @brief Joins the thread
- * @param exit_code OSThreadExitCode enumeration
- * @return Implementation specific
- */
- virtual bool join(OSThreadExitCode & exit_code) = 0;
- virtual ~OSThread() = 0;
-};
-
-inline OSThread::~OSThread() {}
-
-/**
- * @brief Provides factory design pattern for OSThread class
- */
-class OSThreadFactory {
-public:
- /**
- * @brief Creates a new thread
- * @return Pointer to OSThread object
- */
- virtual OSThread * createThread() const = 0;
-
- /**
- * @brief Destroys the new thread
- */
- virtual ~OSThreadFactory() = 0;
-};
-
-inline OSThreadFactory::~OSThreadFactory() {}
-
-
-#endif
diff --git a/daemons/gptp/common/avbts_ostimer.hpp b/daemons/gptp/common/avbts_ostimer.hpp
deleted file mode 100644
index cacdfc95..00000000
--- a/daemons/gptp/common/avbts_ostimer.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSTIMER_HPP
-#define AVBTS_OSTIMER_HPP
-
-/**@file*/
-
-/**
- * @brief OSTimer generic interface
- */
-class OSTimer {
-public:
- /**
- * @brief Sleep for a given amount of time
- * @param micro Time in micro-seconds
- * @return Implmentation specific
- */
- virtual unsigned long sleep(unsigned long micro) = 0;
-
- /*
- * Virtual destructor
- */
- virtual ~OSTimer() = 0;
-};
-
-inline OSTimer::~OSTimer() {}
-
-/**
- * @brief Provides factory design patter for OSTimer class
- */
-class OSTimerFactory {
-public:
- /**
- * @brief Creates the OSTimer
- * @return Pointer to OSTimer object
- */
- virtual OSTimer *createTimer() const = 0;
-
- /*
- * Destroys the OSTimer previsouly created
- */
- virtual ~OSTimerFactory() = 0;
-};
-
-inline OSTimerFactory::~OSTimerFactory() {}
-
-#endif
diff --git a/daemons/gptp/common/avbts_ostimerq.hpp b/daemons/gptp/common/avbts_ostimerq.hpp
deleted file mode 100644
index fc60671f..00000000
--- a/daemons/gptp/common/avbts_ostimerq.hpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef AVBTS_OSTIMERQ_HPP
-#define AVBTS_OSTIMERQ_HPP
-
-/**@file*/
-
-/**
- * @brief ostimerq callback definition
- */
-typedef void (*ostimerq_handler) (void *);
-
-class IEEE1588Clock;
-
-/**
- * @brief OSTimerQueue generic interface
- */
-class OSTimerQueue {
-protected:
- /**
- * @brief Initializes timer queue
- * @return TRUE
- */
- virtual bool init() { return true; }
-
- /**
- * @brief Default constructor
- */
- OSTimerQueue() {}
-public:
- /**
- * @brief Add an event to the timer queue
- * @param micros Time in microsseconds
- * @param type Event type
- * @param func Callback
- * @param arg inner argument of type event_descriptor_t
- * @param dynamic when true, allows elements to be deleted from the queue
- * @param event [inout] Pointer to the event
- * @return TRUE success, FALSE fail
- */
- virtual bool addEvent
- (unsigned long micros, int type, ostimerq_handler func,
- event_descriptor_t * arg, bool dynamic, unsigned *event) = 0;
-
- /**
- * @brief Removes an event from the timer queue
- * @param type Event type
- * @param event [inout] Pointer to the event
- * @return TRUE success, FALSE fail
- */
- virtual bool cancelEvent(int type, unsigned *event) = 0;
- virtual ~OSTimerQueue() = 0;
-};
-
-inline OSTimerQueue::~OSTimerQueue() {}
-
-/**
- * @brief Implements factory design patter for OSTimerQueue class
- */
-class OSTimerQueueFactory {
-public:
- /**
- * @brief Creates the OSTimerQueue object
- * @param clock [in] Pointer to the IEEE1555Clock object
- * @return Pointer to OSTimerQueue
- */
- virtual OSTimerQueue *createOSTimerQueue( IEEE1588Clock *clock ) = 0;
- virtual ~OSTimerQueueFactory() = 0;
-};
-
-inline OSTimerQueueFactory::~OSTimerQueueFactory() {}
-
-#endif
diff --git a/daemons/gptp/common/avbts_persist.hpp b/daemons/gptp/common/avbts_persist.hpp
deleted file mode 100644
index 1c8a3aa0..00000000
--- a/daemons/gptp/common/avbts_persist.hpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2012-2015, Symphony Teleca Corporation, a Harman International Industries, Incorporated company
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Attributions: The inih library portion of the source code is licensed from
-Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
-Complete license and copyright information can be found at
-https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
-*************************************************************************************************************/
-
-#ifndef AVBTS_PERSIST_HPP
-#define AVBTS_PERSIST_HPP
-
-#include <stdint.h>
-#include <ptptypes.hpp>
-
-/**@file*/
-
-
-/**
- * @brief Callback function to write persistent data.
- * @param bufPtr Buffer pointer where the restored persistent data shall be stored.
- * @param bufSize The size of the buffer.
- * @return True on success otherwise False
- */
-typedef void (*gPTPPersistWriteCB_t)(char *bufPtr, uint32_t bufSize);
-
-
-
-/**
- * @brief Generic interface for Simple Persistence for gPTP values
- */
-class GPTPPersist {
-public:
- /**
- * @brief Initializes the GPTP_PERSIST
- * @param persistID string identifer of the persistence storage. For example a file name
- * @return True on success otherwise False
- */
- virtual bool initStorage(const char *persistID) = 0;
-
- /**
- * @brief Closes the GPTP_PERSIST instance
- * @return True on success otherwise False
- */
- virtual bool closeStorage(void) = 0;
-
- /**
- * @brief Read the persistent data
- * @param bufPtr Buffer pointer where the restored persistent data is held.
- * @param bufSize The size of the restored data.
- * @return True on success otherwise False
- */
- virtual bool readStorage(char **bufPtr, uint32_t *bufSize) = 0;
-
- /**
- * @brief Register the write call back
- * @param writeCB Write callback from
- * @return none
- */
- virtual void registerWriteCB(gPTPPersistWriteCB_t writeCB) = 0;
-
- /**
- * @brief Set write data size
- * @param dataSiuze The size of data that will be written
- * @return none
- */
- virtual void setWriteSize(uint32_t dataSize) = 0;
-
- /**
- * @brief Trigger the write callback.
- * @return True on success otherwise False
- */
- virtual bool triggerWriteStorage(void) = 0;
-
- /*
- * Destroys the GPTP_PERSIST instance
- */
- virtual ~GPTPPersist() = 0;
-};
-
-inline GPTPPersist::~GPTPPersist() {}
-
-#endif // AVBTS_PERSIST_HPP
-
diff --git a/daemons/gptp/common/common_port.cpp b/daemons/gptp/common/common_port.cpp
deleted file mode 100644
index dc47d9d2..00000000
--- a/daemons/gptp/common/common_port.cpp
+++ /dev/null
@@ -1,762 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-
-#include <common_port.hpp>
-#include <avbts_clock.hpp>
-#include <common_tstamper.hpp>
-#include <gptp_cfg.hpp>
-
-CommonPort::CommonPort( PortInit_t *portInit ) :
- thread_factory( portInit->thread_factory ),
- timer_factory( portInit->timer_factory ),
- lock_factory( portInit->lock_factory ),
- condition_factory( portInit->condition_factory ),
- _hw_timestamper( portInit->timestamper ),
- clock( portInit->clock ),
- isGM( portInit->isGM ),
- phy_delay( portInit->phy_delay )
-{
- one_way_delay = ONE_WAY_DELAY_DEFAULT;
- neighbor_prop_delay_thresh = portInit->neighborPropDelayThreshold;
- net_label = portInit->net_label;
- link_thread = thread_factory->createThread();
- listening_thread = thread_factory->createThread();
- sync_receipt_thresh = portInit->syncReceiptThreshold;
- wrongSeqIDCounter = 0;
- _peer_rate_offset = 1.0;
- _peer_offset_init = false;
- ifindex = portInit->index;
- testMode = false;
- port_state = PTP_INITIALIZING;
- clock->registerPort(this, ifindex);
- qualified_announce = NULL;
- automotive_profile = portInit->automotive_profile;
- announce_sequence_id = 0;
- signal_sequence_id = 0;
- sync_sequence_id = 0;
- initialLogPdelayReqInterval = portInit->initialLogPdelayReqInterval;
- initialLogSyncInterval = portInit->initialLogSyncInterval;
- log_mean_announce_interval = 0;
- pdelay_count = 0;
- asCapable = false;
- link_speed = INVALID_LINKSPEED;
-}
-
-CommonPort::~CommonPort()
-{
- delete qualified_announce;
-}
-
-bool CommonPort::init_port( void )
-{
- log_mean_sync_interval = initialLogSyncInterval;
-
- if (!OSNetworkInterfaceFactory::buildInterface
- ( &net_iface, factory_name_t("default"), net_label,
- _hw_timestamper))
- return false;
-
- this->net_iface->getLinkLayerAddress(&local_addr);
- clock->setClockIdentity(&local_addr);
-
- this->timestamper_init();
-
- port_identity.setClockIdentity(clock->getClockIdentity());
- port_identity.setPortNumber(&ifindex);
-
- syncReceiptTimerLock = lock_factory->createLock(oslock_recursive);
- syncIntervalTimerLock = lock_factory->createLock(oslock_recursive);
- announceIntervalTimerLock = lock_factory->createLock(oslock_recursive);
-
- return _init_port();
-}
-
-void CommonPort::timestamper_init( void )
-{
- if( _hw_timestamper != NULL )
- {
- if( !_hw_timestamper->HWTimestamper_init
- ( net_label, net_iface ))
- {
- GPTP_LOG_ERROR
- ( "Failed to initialize hardware timestamper, "
- "falling back to software timestamping" );
- return;
- }
- }
-}
-
-void CommonPort::timestamper_reset( void )
-{
- if( _hw_timestamper != NULL )
- {
- _hw_timestamper->HWTimestamper_reset();
- }
-}
-
-PTPMessageAnnounce *CommonPort::calculateERBest( void )
-{
- return qualified_announce;
-}
-
-void CommonPort::recommendState
-( PortState state, bool changed_external_master )
-{
- bool reset_sync = false;
- switch (state) {
- case PTP_MASTER:
- if ( getPortState() != PTP_MASTER )
- {
- setPortState( PTP_MASTER );
- // Start announce receipt timeout timer
- // Start sync receipt timeout timer
- becomeMaster( true );
- reset_sync = true;
- }
- break;
- case PTP_SLAVE:
- if ( getPortState() != PTP_SLAVE )
- {
- becomeSlave( true );
- reset_sync = true;
- } else {
- if( changed_external_master ) {
- GPTP_LOG_STATUS("Changed master!" );
- clock->newSyntonizationSetPoint();
- clock->updateFUPInfo();
- reset_sync = true;
- }
- }
- break;
- default:
- GPTP_LOG_ERROR
- ("Invalid state change requested by call to "
- "1588Port::recommendState()");
- break;
- }
- if( reset_sync ) sync_count = 0;
- return;
-}
-
-bool CommonPort::serializeState( void *buf, off_t *count )
-{
- bool ret = true;
-
- if( buf == NULL ) {
- *count = sizeof(port_state)+sizeof(_peer_rate_offset)+
- sizeof(asCapable)+sizeof(one_way_delay);
- return true;
- }
-
- if( port_state != PTP_MASTER && port_state != PTP_SLAVE ) {
- *count = 0;
- ret = false;
- goto bail;
- }
-
- /* asCapable */
- if( ret && *count >= (off_t) sizeof( asCapable )) {
- memcpy( buf, &asCapable, sizeof( asCapable ));
- *count -= sizeof( asCapable );
- buf = ((char *)buf) + sizeof( asCapable );
- } else if( ret == false ) {
- *count += sizeof( asCapable );
- } else {
- *count = sizeof( asCapable )-*count;
- ret = false;
- }
-
- /* Port State */
- if( ret && *count >= (off_t) sizeof( port_state )) {
- memcpy( buf, &port_state, sizeof( port_state ));
- *count -= sizeof( port_state );
- buf = ((char *)buf) + sizeof( port_state );
- } else if( ret == false ) {
- *count += sizeof( port_state );
- } else {
- *count = sizeof( port_state )-*count;
- ret = false;
- }
-
- /* Link Delay */
- if( ret && *count >= (off_t) sizeof( one_way_delay )) {
- memcpy( buf, &one_way_delay, sizeof( one_way_delay ));
- *count -= sizeof( one_way_delay );
- buf = ((char *)buf) + sizeof( one_way_delay );
- } else if( ret == false ) {
- *count += sizeof( one_way_delay );
- } else {
- *count = sizeof( one_way_delay )-*count;
- ret = false;
- }
-
- /* Neighbor Rate Ratio */
- if( ret && *count >= (off_t) sizeof( _peer_rate_offset )) {
- memcpy( buf, &_peer_rate_offset, sizeof( _peer_rate_offset ));
- *count -= sizeof( _peer_rate_offset );
- buf = ((char *)buf) + sizeof( _peer_rate_offset );
- } else if( ret == false ) {
- *count += sizeof( _peer_rate_offset );
- } else {
- *count = sizeof( _peer_rate_offset )-*count;
- ret = false;
- }
-
- bail:
- return ret;
-}
-
-bool CommonPort::restoreSerializedState
-( void *buf, off_t *count )
-{
- bool ret = true;
-
- /* asCapable */
- if( ret && *count >= (off_t) sizeof( asCapable )) {
- memcpy( &asCapable, buf, sizeof( asCapable ));
- *count -= sizeof( asCapable );
- buf = ((char *)buf) + sizeof( asCapable );
- } else if( ret == false ) {
- *count += sizeof( asCapable );
- } else {
- *count = sizeof( asCapable )-*count;
- ret = false;
- }
-
- /* Port State */
- if( ret && *count >= (off_t) sizeof( port_state )) {
- memcpy( &port_state, buf, sizeof( port_state ));
- *count -= sizeof( port_state );
- buf = ((char *)buf) + sizeof( port_state );
- } else if( ret == false ) {
- *count += sizeof( port_state );
- } else {
- *count = sizeof( port_state )-*count;
- ret = false;
- }
-
- /* Link Delay */
- if( ret && *count >= (off_t) sizeof( one_way_delay )) {
- memcpy( &one_way_delay, buf, sizeof( one_way_delay ));
- *count -= sizeof( one_way_delay );
- buf = ((char *)buf) + sizeof( one_way_delay );
- } else if( ret == false ) {
- *count += sizeof( one_way_delay );
- } else {
- *count = sizeof( one_way_delay )-*count;
- ret = false;
- }
-
- /* Neighbor Rate Ratio */
- if( ret && *count >= (off_t) sizeof( _peer_rate_offset )) {
- memcpy( &_peer_rate_offset, buf, sizeof( _peer_rate_offset ));
- *count -= sizeof( _peer_rate_offset );
- buf = ((char *)buf) + sizeof( _peer_rate_offset );
- } else if( ret == false ) {
- *count += sizeof( _peer_rate_offset );
- } else {
- *count = sizeof( _peer_rate_offset )-*count;
- ret = false;
- }
-
- return ret;
-}
-
-void CommonPort::startSyncReceiptTimer
-( long long unsigned int waitTime )
-{
- clock->getTimerQLock();
- syncReceiptTimerLock->lock();
- clock->deleteEventTimer( this, SYNC_RECEIPT_TIMEOUT_EXPIRES );
- clock->addEventTimer
- ( this, SYNC_RECEIPT_TIMEOUT_EXPIRES, waitTime );
- syncReceiptTimerLock->unlock();
- clock->putTimerQLock();
-}
-
-void CommonPort::stopSyncReceiptTimer( void )
-{
- clock->getTimerQLock();
- syncReceiptTimerLock->lock();
- clock->deleteEventTimer( this, SYNC_RECEIPT_TIMEOUT_EXPIRES );
- syncReceiptTimerLock->unlock();
- clock->putTimerQLock();
-}
-
-void CommonPort::startSyncIntervalTimer
-( long long unsigned int waitTime )
-{
- if( syncIntervalTimerLock->trylock() == oslock_fail ) return;
- clock->deleteEventTimerLocked(this, SYNC_INTERVAL_TIMEOUT_EXPIRES);
- clock->addEventTimerLocked
- (this, SYNC_INTERVAL_TIMEOUT_EXPIRES, waitTime);
- syncIntervalTimerLock->unlock();
-}
-
-void CommonPort::startAnnounceIntervalTimer
-( long long unsigned int waitTime )
-{
- announceIntervalTimerLock->lock();
- clock->deleteEventTimerLocked
- ( this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES );
- clock->addEventTimerLocked
- ( this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES, waitTime );
- announceIntervalTimerLock->unlock();
-}
-
-bool CommonPort::processStateChange( Event e )
-{
- bool changed_external_master;
- uint8_t LastEBestClockIdentity[PTP_CLOCK_IDENTITY_LENGTH];
- int number_ports, j;
- PTPMessageAnnounce *EBest = NULL;
- char EBestClockIdentity[PTP_CLOCK_IDENTITY_LENGTH];
- CommonPort **ports;
-
- // Nothing to do if we are slave only
- if ( clock->getPriority1() == 255 )
- return true;
-
- clock->getPortList(number_ports, ports);
-
- /* Find EBest for all ports */
- j = 0;
- for (int i = 0; i < number_ports; ++i) {
- while (ports[j] == NULL)
- ++j;
- if ( ports[j]->getPortState() == PTP_DISABLED ||
- ports[j]->getPortState() == PTP_FAULTY )
- {
- continue;
- }
- if( EBest == NULL )
- {
- EBest = ports[j]->calculateERBest();
- }
- else if( ports[j]->calculateERBest() )
- {
- if( ports[j]->
- calculateERBest()->isBetterThan(EBest))
- {
- EBest = ports[j]->calculateERBest();
- }
- }
- }
-
- if (EBest == NULL)
- {
- return true;
- }
-
- /* Check if we've changed */
- clock->getLastEBestIdentity().
- getIdentityString( LastEBestClockIdentity );
- EBest->getGrandmasterIdentity( EBestClockIdentity );
- if( memcmp( EBestClockIdentity, LastEBestClockIdentity,
- PTP_CLOCK_IDENTITY_LENGTH ) != 0 )
- {
- ClockIdentity newGM;
- changed_external_master = true;
- newGM.set((uint8_t *) EBestClockIdentity );
- clock->setLastEBestIdentity( newGM );
- }
- else
- {
- changed_external_master = false;
- }
-
- if( clock->isBetterThan( EBest ))
- {
- // We're Grandmaster, set grandmaster info to me
- ClockIdentity clock_identity;
- unsigned char priority1;
- unsigned char priority2;
- ClockQuality clock_quality;
-
- clock_identity = getClock()->getClockIdentity();
- getClock()->setGrandmasterClockIdentity( clock_identity );
- priority1 = getClock()->getPriority1();
- getClock()->setGrandmasterPriority1( priority1 );
- priority2 = getClock()->getPriority2();
- getClock()->setGrandmasterPriority2( priority2 );
- clock_quality = getClock()->getClockQuality();
- getClock()->setGrandmasterClockQuality( clock_quality );
- }
-
- j = 0;
- for( int i = 0; i < number_ports; ++i )
- {
- while (ports[j] == NULL)
- ++j;
- if ( ports[j]->getPortState() ==
- PTP_DISABLED ||
- ports[j]->getPortState() ==
- PTP_FAULTY)
- {
- continue;
- }
- if (clock->isBetterThan(EBest))
- {
- // We are the GrandMaster, all ports are master
- EBest = NULL; // EBest == NULL : we were grandmaster
- ports[j]->recommendState( PTP_MASTER,
- changed_external_master );
- } else {
- if( EBest == ports[j]->calculateERBest() ) {
- // The "best" Announce was received on this
- // port
- ClockIdentity clock_identity;
- unsigned char priority1;
- unsigned char priority2;
- ClockQuality *clock_quality;
-
- ports[j]->recommendState
- ( PTP_SLAVE, changed_external_master );
- clock_identity =
- EBest->getGrandmasterClockIdentity();
- getClock()->setGrandmasterClockIdentity
- ( clock_identity );
- priority1 = EBest->getGrandmasterPriority1();
- getClock()->setGrandmasterPriority1
- ( priority1 );
- priority2 =
- EBest->getGrandmasterPriority2();
- getClock()->setGrandmasterPriority2
- ( priority2 );
- clock_quality =
- EBest->getGrandmasterClockQuality();
- getClock()->setGrandmasterClockQuality
- (*clock_quality);
- } else {
- /* Otherwise we are the master because we have
- sync'd to a better clock */
- ports[j]->recommendState
- (PTP_MASTER, changed_external_master);
- }
- }
- }
-
- return true;
-}
-
-
-bool CommonPort::processSyncAnnounceTimeout( Event e )
-{
- // We're Grandmaster, set grandmaster info to me
- ClockIdentity clock_identity;
- unsigned char priority1;
- unsigned char priority2;
- ClockQuality clock_quality;
-
- Timestamp system_time;
- Timestamp device_time;
- uint32_t local_clock, nominal_clock_rate;
-
- // Nothing to do
- if( clock->getPriority1() == 255 )
- return true;
-
- // Restart timer
- if( e == ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ) {
- clock->addEventTimerLocked
- (this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
- (ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER*
- (unsigned long long)
- (pow((double)2,getAnnounceInterval())*
- 1000000000.0)));
- } else {
- startSyncReceiptTimer
- ((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double) pow((double)2, getSyncInterval()) *
- 1000000000.0)));
- }
-
- if( getPortState() == PTP_MASTER )
- return true;
-
- GPTP_LOG_STATUS(
- "*** %s Timeout Expired - Becoming Master",
- e == ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES ? "Announce" :
- "Sync" );
-
- clock_identity = getClock()->getClockIdentity();
- getClock()->setGrandmasterClockIdentity( clock_identity );
- priority1 = getClock()->getPriority1();
- getClock()->setGrandmasterPriority1( priority1 );
- priority2 = getClock()->getPriority2();
- getClock()->setGrandmasterPriority2( priority2 );
- clock_quality = getClock()->getClockQuality();
- getClock()->setGrandmasterClockQuality( clock_quality );
-
- setPortState( PTP_MASTER );
-
- getDeviceTime( system_time, device_time,
- local_clock, nominal_clock_rate );
-
- (void) clock->calcLocalSystemClockRateDifference
- ( device_time, system_time );
-
- setQualifiedAnnounce( NULL );
-
- clock->addEventTimerLocked
- ( this, SYNC_INTERVAL_TIMEOUT_EXPIRES,
- 16000000 );
-
- startAnnounce();
-
- return true;
-}
-
-bool CommonPort::processEvent( Event e )
-{
- bool ret;
-
- switch( e )
- {
- default:
- // Unhandled event
- ret = _processEvent( e );
- break;
-
- case POWERUP:
- case INITIALIZE:
- GPTP_LOG_DEBUG("Received POWERUP/INITIALIZE event");
-
- // If port has been configured as master or slave, run media
- // specific configuration. If it hasn't been configured
- // start listening for announce messages
- if( clock->getPriority1() == 255 ||
- port_state == PTP_SLAVE )
- {
- becomeSlave( true );
- }
- else if( port_state == PTP_MASTER )
- {
- becomeMaster( true );
- }
- else
- {
- clock->addEventTimerLocked(this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
- (uint64_t) ( ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER * pow(2.0, getAnnounceInterval()) * 1000000000.0 ));
- }
-
- // Do any media specific initialization
- ret = _processEvent( e );
- break;
-
- case STATE_CHANGE_EVENT:
- ret = _processEvent( e );
-
- // If this event wasn't handled in a media specific way, call
- // the default action
- if( !ret )
- ret = processStateChange( e );
- break;
-
- case ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES:
- case SYNC_RECEIPT_TIMEOUT_EXPIRES:
- if (e == ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES) {
- incCounter_ieee8021AsPortStatAnnounceReceiptTimeouts();
- }
- else if (e == SYNC_RECEIPT_TIMEOUT_EXPIRES) {
- incCounter_ieee8021AsPortStatRxSyncReceiptTimeouts();
- }
-
- ret = _processEvent( e );
-
- // If this event wasn't handled in a media specific way, call
- // the default action
- if( !ret )
- ret = processSyncAnnounceTimeout( e );
- break;
-
- case ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES:
- GPTP_LOG_DEBUG("ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES occured");
-
- // Send an announce message
- if ( asCapable)
- {
- PTPMessageAnnounce *annc =
- new PTPMessageAnnounce(this);
- PortIdentity dest_id;
- PortIdentity gmId;
- ClockIdentity clock_id = clock->getClockIdentity();
- gmId.setClockIdentity(clock_id);
- getPortIdentity( dest_id );
- annc->setPortIdentity( &dest_id );
- annc->sendPort( this, NULL );
- delete annc;
- }
-
- startAnnounceIntervalTimer
- ((uint64_t)( pow((double)2, getAnnounceInterval()) *
- 1000000000.0 ));
- ret = true;
- break;
-
- case SYNC_INTERVAL_TIMEOUT_EXPIRES:
- GPTP_LOG_DEBUG("SYNC_INTERVAL_TIMEOUT_EXPIRES occured");
- // If asCapable is true attempt some media specific action
- ret = true;
- if( asCapable )
- ret = _processEvent( e );
-
- /* Do getDeviceTime() after transmitting sync frame
- causing an update to local/system timestamp */
- {
- Timestamp system_time;
- Timestamp device_time;
- uint32_t local_clock, nominal_clock_rate;
- FrequencyRatio local_system_freq_offset;
- int64_t local_system_offset;
-
- getDeviceTime
- ( system_time, device_time,
- local_clock, nominal_clock_rate );
-
- GPTP_LOG_VERBOSE
- ( "port::processEvent(): System time: %u,%u "
- "Device Time: %u,%u",
- system_time.seconds_ls,
- system_time.nanoseconds,
- device_time.seconds_ls,
- device_time.nanoseconds );
-
- local_system_offset =
- TIMESTAMP_TO_NS(system_time) -
- TIMESTAMP_TO_NS(device_time);
- local_system_freq_offset =
- clock->calcLocalSystemClockRateDifference
- ( device_time, system_time );
- clock->setMasterOffset
- ( this, 0, device_time, 1.0,
- local_system_offset, system_time,
- local_system_freq_offset, getSyncCount(),
- pdelay_count, port_state, asCapable );
- }
-
- // Call media specific action for completed sync
- syncDone();
-
- // Restart the timer
- startSyncIntervalTimer
- ((uint64_t)( pow((double)2, getSyncInterval()) *
- 1000000000.0 ));
-
- break;
- }
-
- return ret;
-}
-
-void CommonPort::getDeviceTime
-( Timestamp &system_time, Timestamp &device_time,
- uint32_t &local_clock, uint32_t &nominal_clock_rate )
-{
- if (_hw_timestamper) {
- _hw_timestamper->HWTimestamper_gettime
- ( &system_time, &device_time,
- &local_clock, &nominal_clock_rate );
- } else {
- device_time = system_time = clock->getSystemTime();
- local_clock = nominal_clock_rate = 0;
- }
-
- return;
-}
-
-void CommonPort::startAnnounce()
-{
- startAnnounceIntervalTimer(16000000);
-}
-
-int CommonPort::getTimestampVersion()
-{
- return _hw_timestamper->getVersion();
-}
-
-bool CommonPort::_adjustClockRate( FrequencyRatio freq_offset )
-{
- if( _hw_timestamper )
- {
- return _hw_timestamper->HWTimestamper_adjclockrate
- ((float) freq_offset );
- }
-
- return false;
-}
-
-void CommonPort::getExtendedError( char *msg )
-{
- if (_hw_timestamper)
- {
- _hw_timestamper->HWTimestamper_get_extderror(msg);
- return;
- }
-
- *msg = '\0';
-}
-
-bool CommonPort::adjustClockPhase( int64_t phase_adjust )
-{
- if( _hw_timestamper )
- return _hw_timestamper->
- HWTimestamper_adjclockphase( phase_adjust );
-
- return false;
-}
-
-FrequencyRatio CommonPort::getLocalSystemFreqOffset()
-{
- return clock->getLocalSystemFreqOffset();
-}
-
-Timestamp CommonPort::getTxPhyDelay( uint32_t link_speed ) const
-{
- if( phy_delay->count( link_speed ) != 0 )
- return Timestamp
- ( phy_delay->at(link_speed).get_tx_delay(), 0, 0 );
-
- return Timestamp(0, 0, 0);
-}
-
-Timestamp CommonPort::getRxPhyDelay( uint32_t link_speed ) const
-{
- if( phy_delay->count( link_speed ) != 0 )
- return Timestamp
- ( phy_delay->at(link_speed).get_rx_delay(), 0, 0 );
-
- return Timestamp(0, 0, 0);
-}
diff --git a/daemons/gptp/common/common_port.hpp b/daemons/gptp/common/common_port.hpp
deleted file mode 100644
index 4f195836..00000000
--- a/daemons/gptp/common/common_port.hpp
+++ /dev/null
@@ -1,1534 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-
-#ifndef COMMON_PORT_HPP
-#define COMMON_PORT_HPP
-
-#include <avbts_message.hpp>
-#include <avbts_osthread.hpp>
-#include <avbts_oscondition.hpp>
-#include <avbts_ostimer.hpp>
-#include <avbts_oslock.hpp>
-#include <avbts_osnet.hpp>
-#include <unordered_map>
-
-#include <math.h>
-
-#define SYNC_RECEIPT_TIMEOUT_MULTIPLIER 3 /*!< Sync rcpt timeout multiplier */
-#define ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER 3 /*!< Annc rcpt timeout mult */
-#define LOG2_INTERVAL_INVALID -127 /* Invalid Log base 2 interval value */
-
-class IEEE1588Clock;
-
-/**
- * @brief PortIdentity interface
- * Defined at IEEE 802.1AS Clause 8.5.2
- */
-class PortIdentity {
-private:
- ClockIdentity clock_id;
- uint16_t portNumber;
-public:
- /**
- * @brief Default Constructor
- */
- PortIdentity() { };
-
- /**
- * @brief Constructs PortIdentity interface.
- * @param clock_id Clock ID value as defined at IEEE 802.1AS Clause
- * 8.5.2.2
- * @param portNumber Port Number
- */
- PortIdentity(uint8_t * clock_id, uint16_t * portNumber)
- {
- this->portNumber = *portNumber;
- this->portNumber = PLAT_ntohs(this->portNumber);
- this->clock_id.set(clock_id);
- }
-
- /**
- * @brief Implements the operator '!=' overloading method. Compares
- * clock_id and portNumber.
- * @param cmp Constant PortIdentity value to be compared against.
- * @return TRUE if the comparison value differs from the object's
- * PortIdentity value. FALSE otherwise.
- */
- bool operator!=(const PortIdentity & cmp) const
- {
- return
- !(this->clock_id == cmp.clock_id) ||
- this->portNumber != cmp.portNumber ? true : false;
- }
-
- /**
- * @brief Implements the operator '==' overloading method. Compares
- * clock_id and portNumber.
- * @param cmp Constant PortIdentity value to be compared against.
- * @return TRUE if the comparison value equals to the object's
- * PortIdentity value. FALSE otherwise.
- */
- bool operator==(const PortIdentity & cmp)const
- {
- return
- this->clock_id == cmp.clock_id &&
- this->portNumber == cmp.portNumber ? true : false;
- }
-
- /**
- * @brief Implements the operator '<' overloading method. Compares
- * clock_id and portNumber.
- * @param cmp Constant PortIdentity value to be compared against.
- * @return TRUE if the comparison value is lower than the object's
- * PortIdentity value. FALSE otherwise.
- */
- bool operator<(const PortIdentity & cmp)const
- {
- return
- this->clock_id < cmp.clock_id ?
- true : this->clock_id == cmp.clock_id &&
- this->portNumber < cmp.portNumber ? true : false;
- }
-
- /**
- * @brief Implements the operator '>' overloading method. Compares
- * clock_id and portNumber.
- * @param cmp Constant PortIdentity value to be compared against.
- * @return TRUE if the comparison value is greater than the object's
- * PortIdentity value. FALSE otherwise.
- */
- bool operator>(const PortIdentity & cmp)const
- {
- return
- this->clock_id > cmp.clock_id ?
- true : this->clock_id == cmp.clock_id &&
- this->portNumber > cmp.portNumber ? true : false;
- }
-
- /**
- * @brief Gets the ClockIdentity string
- * @param id [out] Pointer to an array of octets.
- * @return void
- */
- void getClockIdentityString(uint8_t *id)
- {
- clock_id.getIdentityString(id);
- }
-
- /**
- * @brief Sets the ClockIdentity.
- * @param clock_id Clock Identity to be set.
- * @return void
- */
- void setClockIdentity(ClockIdentity clock_id)
- {
- this->clock_id = clock_id;
- }
-
- /**
- * @brief Gets the clockIdentity value
- * @return A copy of Clock identity value.
- */
- ClockIdentity getClockIdentity( void ) {
- return this->clock_id;
- }
-
- /**
- * @brief Gets the port number following the network byte order, i.e.
- * Big-Endian.
- * @param id [out] Port number
- * @return void
- */
- void getPortNumberNO(uint16_t * id) // Network byte order
- {
- uint16_t portNumberNO = PLAT_htons(portNumber);
- *id = portNumberNO;
- }
-
- /**
- * @brief Gets the port number in the host byte order, which can be
- * either Big-Endian
- * or Little-Endian, depending on the processor where it is running.
- * @param id Port number
- * @return void
- */
- void getPortNumber(uint16_t * id) // Host byte order
- {
- *id = portNumber;
- }
-
- /**
- * @brief Sets the Port number
- * @param id [in] Port number
- * @return void
- */
- void setPortNumber(uint16_t * id)
- {
- portNumber = *id;
- }
-};
-
-class phy_delay_spec_t;
-typedef std::unordered_map<uint32_t, phy_delay_spec_t> phy_delay_map_t;
-
-/**
- * @brief Structure for initializing the port class
- */
-typedef struct {
- /* clock IEEE1588Clock instance */
- IEEE1588Clock * clock;
-
- /* index Interface index */
- uint16_t index;
-
- /* timestamper Hardware timestamper instance */
- CommonTimestamper * timestamper;
-
- /* net_label Network label */
- InterfaceLabel *net_label;
-
- /* Virtual Network label (e.g. WiFi Direct network MAC) */
- InterfaceLabel *virtual_label;
-
- /* automotive_profile set the AVnu automotive profile */
- bool automotive_profile;
-
- /* Set to true if the port is the grandmaster. Used for fixed GM in
- * the the AVnu automotive profile */
- bool isGM;
-
- /* Set to true if the port is the grandmaster. Used for fixed GM in
- * the the AVnu automotive profile */
- bool testMode;
-
- /* Set to true if the port's network interface is up. Used to filter
- * false LINKUP/LINKDOWN events */
- bool linkUp;
-
- /* gPTP 10.2.4.4 */
- signed char initialLogSyncInterval;
-
- /* gPTP 11.5.2.2 */
- signed char initialLogPdelayReqInterval;
-
- /* CDS 6.2.1.5 */
- signed char operLogPdelayReqInterval;
-
- /* CDS 6.2.1.6 */
- signed char operLogSyncInterval;
-
- /* condition_factory OSConditionFactory instance */
- OSConditionFactory * condition_factory;
-
- /* thread_factory OSThreadFactory instance */
- OSThreadFactory * thread_factory;
-
- /* timer_factory OSTimerFactory instance */
- OSTimerFactory * timer_factory;
-
- /* lock_factory OSLockFactory instance */
- OSLockFactory * lock_factory;
-
- /* phy delay */
- phy_delay_map_t const *phy_delay;
-
- /* sync receipt threshold */
- unsigned int syncReceiptThreshold;
-
- /* neighbor delay threshold */
- int64_t neighborPropDelayThreshold;
-} PortInit_t;
-
-
-/**
- * @brief Structure for Port Counters
- */
-typedef struct {
- int32_t ieee8021AsPortStatRxSyncCount;
- int32_t ieee8021AsPortStatRxFollowUpCount;
- int32_t ieee8021AsPortStatRxPdelayRequest;
- int32_t ieee8021AsPortStatRxPdelayResponse;
- int32_t ieee8021AsPortStatRxPdelayResponseFollowUp;
- int32_t ieee8021AsPortStatRxAnnounce;
- int32_t ieee8021AsPortStatRxPTPPacketDiscard;
- int32_t ieee8021AsPortStatRxSyncReceiptTimeouts;
- int32_t ieee8021AsPortStatAnnounceReceiptTimeouts;
- int32_t ieee8021AsPortStatPdelayAllowedLostResponsesExceeded;
- int32_t ieee8021AsPortStatTxSyncCount;
- int32_t ieee8021AsPortStatTxFollowUpCount;
- int32_t ieee8021AsPortStatTxPdelayRequest;
- int32_t ieee8021AsPortStatTxPdelayResponse;
- int32_t ieee8021AsPortStatTxPdelayResponseFollowUp;
- int32_t ieee8021AsPortStatTxAnnounce;
-} PortCounters_t;
-
-/**
- * @brief Port functionality common to all network media
- */
-class CommonPort
-{
-private:
- LinkLayerAddress local_addr;
- PortIdentity port_identity;
-
- /* Network socket description
- physical interface number that object represents */
- uint16_t ifindex;
-
- /* Link speed in kb/sec */
- uint32_t link_speed;
-
- /* Signed value allows this to be negative result because of inaccurate
- timestamp */
- int64_t one_way_delay;
- int64_t neighbor_prop_delay_thresh;
-
- InterfaceLabel *net_label;
-
- OSNetworkInterface *net_iface;
-
- PortState port_state;
- bool testMode;
- bool automotive_profile;
-
- signed char log_mean_sync_interval;
- signed char log_mean_announce_interval;
- signed char initialLogSyncInterval;
-
- /*Sync threshold*/
- unsigned int sync_receipt_thresh;
- unsigned int wrongSeqIDCounter;
-
- PortCounters_t counters;
-
- OSThread *listening_thread;
- OSThread *link_thread;
-
- FrequencyRatio _peer_rate_offset;
- Timestamp _peer_offset_ts_theirs;
- Timestamp _peer_offset_ts_mine;
- bool _peer_offset_init;
- bool asCapable;
- unsigned sync_count; /* 0 for master, increment for each sync
- * received as slave */
- unsigned pdelay_count;
-
- signed char initialLogPdelayReqInterval;
- signed char log_min_mean_pdelay_req_interval;
-
- PTPMessageAnnounce *qualified_announce;
-
- uint16_t announce_sequence_id;
- uint16_t signal_sequence_id;
- uint16_t sync_sequence_id;
-
- uint16_t lastGmTimeBaseIndicator;
-
- OSLock *syncReceiptTimerLock;
- OSLock *syncIntervalTimerLock;
- OSLock *announceIntervalTimerLock;
-
-protected:
- static const int64_t INVALID_LINKDELAY = 3600000000000;
- static const int64_t ONE_WAY_DELAY_DEFAULT = INVALID_LINKDELAY;
-
- OSThreadFactory const * const thread_factory;
- OSTimerFactory const * const timer_factory;
- OSLockFactory const * const lock_factory;
- OSConditionFactory const * const condition_factory;
- CommonTimestamper * const _hw_timestamper;
- IEEE1588Clock * const clock;
- const bool isGM;
-
- phy_delay_map_t const * const phy_delay;
-
-public:
- static const int64_t NEIGHBOR_PROP_DELAY_THRESH = 800;
- static const unsigned int DEFAULT_SYNC_RECEIPT_THRESH = 5;
-
- CommonPort( PortInit_t *portInit );
- virtual ~CommonPort();
-
- /**
- * @brief Global media dependent port initialization
- * @return true on success
- */
- bool init_port( void );
-
- /**
- * @brief Media specific port initialization
- * @return true on success
- */
- virtual bool _init_port( void ) = 0;
-
- /**
- * @brief Initializes the hwtimestamper
- */
- void timestamper_init( void );
-
- /**
- * @brief Resets the hwtimestamper
- */
- void timestamper_reset( void );
-
- /**
- * @brief Gets the link delay information.
- * @return one way delay if delay > 0, or zero otherwise.
- */
- uint64_t getLinkDelay( void )
- {
- return one_way_delay > 0LL ? one_way_delay : 0LL;
- }
-
- /**
- * @brief Gets the link delay information.
- * @param [in] delay Pointer to the delay information
- * @return True if valid, false if invalid
- */
- bool getLinkDelay( uint64_t *delay )
- {
- if(delay == NULL) {
- return false;
- }
- *delay = getLinkDelay();
- return *delay < INVALID_LINKDELAY;
- }
-
- /**
- * @brief Sets link delay information.
- * Signed value allows this to be negative result because
- * of inaccurate timestamps.
- * @param delay Link delay
- * @return True if one_way_delay is lower or equal than neighbor
- * propagation delay threshold False otherwise
- */
- bool setLinkDelay( int64_t delay )
- {
- one_way_delay = delay;
- int64_t abs_delay = (one_way_delay < 0 ?
- -one_way_delay : one_way_delay);
-
- if (testMode) {
- GPTP_LOG_STATUS("Link delay: %d", delay);
- }
-
- return (abs_delay <= neighbor_prop_delay_thresh);
- }
-
- /**
- * @brief Return frequency offset between local timestamp clock
- * system clock
- * @return local:system ratio
- */
- FrequencyRatio getLocalSystemFreqOffset();
-
- /**
- * @brief Gets a pointer to IEEE1588Clock
- * @return Pointer to clock
- */
- IEEE1588Clock *getClock( void )
- {
- return clock;
- }
-
- /**
- * @brief Gets the local_addr
- * @return LinkLayerAddress
- */
- LinkLayerAddress *getLocalAddr( void )
- {
- return &local_addr;
- }
-
- /**
- * @brief Gets the testMode
- * @return bool of the test mode value
- */
- bool getTestMode( void )
- {
- return testMode;
- }
-
- /**
- * @brief Sets the testMode
- * @param testMode changes testMode to this value
- */
- void setTestMode( bool testMode )
- {
- this->testMode = testMode;
- }
-
- /**
- * @brief Serializes (i.e. copy over buf pointer) the information from
- * the variables (in that order):
- * - asCapable;
- * - Port Sate;
- * - Link Delay;
- * - Neighbor Rate Ratio
- * @param buf [out] Buffer where to put the results.
- * @param count [inout] Length of buffer. It contains maximum length
- * to be written
- * when the function is called, and the value is decremented by the
- * same amount the
- * buf size increases.
- * @return TRUE if it has successfully written to buf all the values
- * or if buf is NULL.
- * FALSE if count should be updated with the right size.
- */
- bool serializeState( void *buf, long *count );
-
- /**
- * @brief Restores the serialized state from the buffer. Copies the
- * information from buffer
- * to the variables (in that order):
- * - asCapable;
- * - Port State;
- * - Link Delay;
- * - Neighbor Rate Ratio
- * @param buf Buffer containing the serialized state.
- * @param count Buffer lenght. It is decremented by the same size of
- * the variables that are
- * being copied.
- * @return TRUE if everything was copied successfully, FALSE otherwise.
- */
- bool restoreSerializedState( void *buf, long *count );
-
- /**
- * @brief Sets the internal variabl sync_receipt_thresh, which is the
- * flag that monitors the amount of wrong syncs enabled before
- * switching
- * the ptp to master.
- * @param th Threshold to be set
- * @return void
- */
- void setSyncReceiptThresh(unsigned int th)
- {
- sync_receipt_thresh = th;
- }
-
- /**
- * @brief Gets the internal variabl sync_receipt_thresh, which is the
- * flag that monitors the amount of wrong syncs enabled before
- * switching
- * the ptp to master.
- * @return sync_receipt_thresh value
- */
- unsigned int getSyncReceiptThresh( void )
- {
- return sync_receipt_thresh;
- }
-
- /**
- * @brief Sets the wrongSeqIDCounter variable
- * @param cnt Value to be set
- * @return void
- */
- void setWrongSeqIDCounter(unsigned int cnt)
- {
- wrongSeqIDCounter = cnt;
- }
-
- /**
- * @brief Gets the wrongSeqIDCounter value
- * @param [out] cnt Pointer to the counter value. It must be valid
- * @return TRUE if ok and lower than the syncReceiptThreshold value.
- * FALSE otherwise
- */
- bool getWrongSeqIDCounter(unsigned int *cnt)
- {
- if( cnt == NULL )
- {
- return false;
- }
- *cnt = wrongSeqIDCounter;
-
- return( *cnt < getSyncReceiptThresh() );
- }
-
- /**
- * @brief Increments the wrongSeqIDCounter value
- * @param [out] cnt Pointer to the counter value. Must be valid
- * @return TRUE if incremented value is lower than the
- * syncReceiptThreshold. FALSE otherwise.
- */
- bool incWrongSeqIDCounter(unsigned int *cnt)
- {
- if( getAsCapable() )
- {
- wrongSeqIDCounter++;
- }
- bool ret = wrongSeqIDCounter < getSyncReceiptThresh();
-
- if( cnt != NULL)
- {
- *cnt = wrongSeqIDCounter;
- }
-
- return ret;
- }
-
- /**
- * @brief Gets the hardware timestamper version
- * @return HW timestamper version
- */
- int getTimestampVersion();
-
- /**
- * @brief Adjusts the clock frequency.
- * @param freq_offset Frequency offset
- * @return TRUE if adjusted. FALSE otherwise.
- */
- bool _adjustClockRate( FrequencyRatio freq_offset );
-
- /**
- * @brief Adjusts the clock frequency.
- * @param freq_offset Frequency offset
- * @return TRUE if adjusted. FALSE otherwise.
- */
- bool adjustClockRate( FrequencyRatio freq_offset ) {
- return _adjustClockRate( freq_offset );
- }
-
- /**
- * @brief Adjusts the clock phase.
- * @param phase_adjust phase offset in ns
- * @return TRUE if adjusted. FALSE otherwise.
- */
- bool adjustClockPhase( int64_t phase_adjust );
-
- /**
- * @brief Gets extended error message from hardware timestamper
- * @param msg [out] Extended error message
- * @return void
- */
- void getExtendedError(char *msg);
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxSyncCount
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxSyncCount( void )
- {
- counters.ieee8021AsPortStatRxSyncCount++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxFollowUpCount
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxFollowUpCount( void )
- {
- counters.ieee8021AsPortStatRxFollowUpCount++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxPdelayRequest
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxPdelayRequest( void )
- {
- counters.ieee8021AsPortStatRxPdelayRequest++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxPdelayResponse
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxPdelayResponse( void )
- {
- counters.ieee8021AsPortStatRxPdelayResponse++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxPdelayResponseFollowUp
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxPdelayResponseFollowUp( void )
- {
- counters.ieee8021AsPortStatRxPdelayResponseFollowUp++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxAnnounce
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxAnnounce( void )
- {
- counters.ieee8021AsPortStatRxAnnounce++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxPTPPacketDiscard
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxPTPPacketDiscard( void )
- {
- counters.ieee8021AsPortStatRxPTPPacketDiscard++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatRxSyncReceiptTimeouts
- * @return void
- */
- void incCounter_ieee8021AsPortStatRxSyncReceiptTimeouts( void )
- {
- counters.ieee8021AsPortStatRxSyncReceiptTimeouts++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatAnnounceReceiptTimeouts
- * @return void
- */
- void incCounter_ieee8021AsPortStatAnnounceReceiptTimeouts( void )
- {
- counters.ieee8021AsPortStatAnnounceReceiptTimeouts++;
- }
-
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatPdelayAllowedLostResponsesExceeded
- * @return void
- */
- // TODO: Not called
- void incCounter_ieee8021AsPortStatPdelayAllowedLostResponsesExceeded
- ( void )
- {
- counters.
- ieee8021AsPortStatPdelayAllowedLostResponsesExceeded++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxSyncCount
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxSyncCount( void )
- {
- counters.ieee8021AsPortStatTxSyncCount++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxFollowUpCount
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxFollowUpCount( void )
- {
- counters.ieee8021AsPortStatTxFollowUpCount++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxPdelayRequest
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxPdelayRequest( void )
- {
- counters.ieee8021AsPortStatTxPdelayRequest++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxPdelayResponse
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxPdelayResponse( void )
- {
- counters.ieee8021AsPortStatTxPdelayResponse++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxPdelayResponseFollowUp
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxPdelayResponseFollowUp( void )
- {
- counters.ieee8021AsPortStatTxPdelayResponseFollowUp++;
- }
-
- /**
- * @brief Increment IEEE Port counter:
- * ieee8021AsPortStatTxAnnounce
- * @return void
- */
- void incCounter_ieee8021AsPortStatTxAnnounce( void )
- {
- counters.ieee8021AsPortStatTxAnnounce++;
- }
-
- /**
- * @brief Logs port counters
- * @return void
- */
- void logIEEEPortCounters( void )
- {
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxSyncCount : %u",
- counters.ieee8021AsPortStatRxSyncCount );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxFollowUpCount : %u",
- counters.ieee8021AsPortStatRxFollowUpCount );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxPdelayRequest : %u",
- counters.ieee8021AsPortStatRxPdelayRequest );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxPdelayResponse : %u",
- counters.ieee8021AsPortStatRxPdelayResponse );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxPdelayResponseFollowUp "
- ": %u", counters.
- ieee8021AsPortStatRxPdelayResponseFollowUp );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxAnnounce : %u",
- counters.ieee8021AsPortStatRxAnnounce );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxPTPPacketDiscard : %u",
- counters.
- ieee8021AsPortStatRxPTPPacketDiscard );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatRxSyncReceiptTimeouts "
- ": %u", counters.
- ieee8021AsPortStatRxSyncReceiptTimeouts );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatAnnounceReceiptTimeouts "
- ": %u", counters.
- ieee8021AsPortStatAnnounceReceiptTimeouts );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatPdelayAllowed"
- "LostResponsesExceeded : %u", counters.
- ieee8021AsPortStatPdelayAllowedLostResponsesExceeded
- );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxSyncCount : %u",
- counters.ieee8021AsPortStatTxSyncCount );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxFollowUpCount : %u", counters.
- ieee8021AsPortStatTxFollowUpCount);
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxPdelayRequest : %u",
- counters.ieee8021AsPortStatTxPdelayRequest);
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxPdelayResponse : %u", counters.
- ieee8021AsPortStatTxPdelayResponse);
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxPdelayResponseFollowUp : %u",
- counters.ieee8021AsPortStatTxPdelayResponseFollowUp
- );
- GPTP_LOG_STATUS
- ( "IEEE Port Counter "
- "ieee8021AsPortStatTxAnnounce : %u",
- counters.ieee8021AsPortStatTxAnnounce);
- }
-
- /**
- * @brief Get the cross timestamping information.
- * The gPTP subsystem uses these samples to calculate
- * ratios which can be used to translate or extrapolate
- * one clock into another clock reference. The gPTP service
- * uses these supplied cross timestamps to perform internal
- * rate estimation and conversion functions.
- * @param system_time [out] System time
- * @param device_time [out] Device time
- * @param local_clock [out] Local clock
- * @param nominal_clock_rate [out] Nominal clock rate
- * @return True in case of success. FALSE in case of error
- */
- void getDeviceTime
- ( Timestamp &system_time, Timestamp &device_time,
- uint32_t &local_clock, uint32_t & nominal_clock_rate );
-
- /**
- * @brief Sets asCapable flag
- * @param ascap flag to be set. If FALSE, marks peer_offset_init as
- * false.
- * @return void
- */
- void setAsCapable(bool ascap)
- {
- if ( ascap != asCapable ) {
- GPTP_LOG_STATUS
- ("AsCapable: %s", ascap == true
- ? "Enabled" : "Disabled");
- }
- if( !ascap )
- {
- _peer_offset_init = false;
- }
- asCapable = ascap;
- }
-
- /**
- * @brief Gets the asCapable flag
- * @return asCapable flag.
- */
- bool getAsCapable()
- {
- return( asCapable );
- }
-
- /**
- * @brief Gets the Peer rate offset. Used to calculate neighbor
- * rate ratio.
- * @return FrequencyRatio peer rate offset
- */
- FrequencyRatio getPeerRateOffset( void )
- {
- return _peer_rate_offset;
- }
-
- /**
- * @brief Sets the peer rate offset. Used to calculate neighbor rate
- * ratio.
- * @param offset Offset to be set
- * @return void
- */
- void setPeerRateOffset( FrequencyRatio offset ) {
- _peer_rate_offset = offset;
- }
-
- /**
- * @brief Sets peer offset timestamps
- * @param mine Local timestamps
- * @param theirs Remote timestamps
- * @return void
- */
- void setPeerOffset(Timestamp mine, Timestamp theirs) {
- _peer_offset_ts_mine = mine;
- _peer_offset_ts_theirs = theirs;
- _peer_offset_init = true;
- }
-
- /**
- * @brief Gets peer offset timestamps
- * @param mine [out] Reference to local timestamps
- * @param theirs [out] Reference to remote timestamps
- * @return TRUE if peer offset has already been initialized. FALSE
- * otherwise.
- */
- bool getPeerOffset(Timestamp & mine, Timestamp & theirs) {
- mine = _peer_offset_ts_mine;
- theirs = _peer_offset_ts_theirs;
- return _peer_offset_init;
- }
-
- /**
- * @brief Sets the neighbor propagation delay threshold
- * @param delay Delay in nanoseconds
- * @return void
- */
- void setNeighPropDelayThresh(int64_t delay) {
- neighbor_prop_delay_thresh = delay;
- }
-
- /**
- * @brief Restart PDelay
- * @return void
- */
- void restartPDelay() {
- _peer_offset_init = false;
- }
-
- /**
- * @brief Gets a pointer to timer_factory object
- * @return timer_factory pointer
- */
- const OSTimerFactory *getTimerFactory() {
- return timer_factory;
- }
-
- /**
- * @brief Watch for link up and down events.
- * @return Its an infinite loop. Returns NULL in case of error.
- */
- void *watchNetLink( void )
- {
- // Should never return
- net_iface->watchNetLink(this);
-
- return NULL;
- }
-
- /**
- * @brief Receive frame
- */
- net_result recv
- ( LinkLayerAddress *addr, uint8_t *payload, size_t &length,
- uint32_t &link_speed )
- {
- net_result result = net_iface->nrecv( addr, payload, length );
- link_speed = this->link_speed;
- return result;
- }
-
- /**
- * @brief Send frame
- */
- net_result send
- ( LinkLayerAddress *addr, uint16_t etherType, uint8_t *payload,
- size_t length, bool timestamp )
- {
- return net_iface->send
- ( addr, etherType, payload, length, timestamp );
- }
-
- /**
- * @brief Get the payload offset inside a packet
- * @return 0
- */
- unsigned getPayloadOffset()
- {
- return net_iface->getPayloadOffset();
- }
-
- bool linkWatch( OSThreadFunction func, OSThreadFunctionArg arg )
- {
- return link_thread->start( func, arg );
- }
-
- bool linkOpen( OSThreadFunction func, OSThreadFunctionArg arg )
- {
- return listening_thread->start( func, arg );
- }
-
- /**
- * @brief Gets the portState information
- * @return PortState
- */
- PortState getPortState( void ) {
- return port_state;
- }
-
- /**
- * @brief Sets the PortState
- * @param state value to be set
- * @return void
- */
- void setPortState( PortState state ) {
- port_state = state;
- }
-
- /**
- * @brief Gets port identity
- * @param identity [out] Reference to PortIdentity
- * @return void
- */
- void getPortIdentity(PortIdentity & identity) {
- identity = this->port_identity;
- }
-
- /**
- * @brief Gets the "best" announce
- * @return Pointer to PTPMessageAnnounce
- */
- PTPMessageAnnounce *calculateERBest( void );
-
- /**
- * @brief Changes the port state
- * @param state Current state
- * @param changed_external_master TRUE if external master has
- * changed, FALSE otherwise
- * @return void
- */
- void recommendState(PortState state, bool changed_external_master);
-
- /**
- * @brief Locks the TX port
- * @return TRUE if success. FALSE otherwise.
- */
- virtual bool getTxLock()
- {
- return true;
- }
-
- /**
- * @brief Unlocks the port TX.
- * @return TRUE if success. FALSE otherwise.
- */
- virtual bool putTxLock()
- {
- return false;
- }
-
- /**
- * @brief Adds a new qualified announce the port. IEEE 802.1AS
- * Clause 10.3.10.2
- * @param annc PTP announce message
- * @return void
- */
- void setQualifiedAnnounce( PTPMessageAnnounce *annc )
- {
- delete qualified_announce;
- qualified_announce = annc;
- }
-
- /**
- * @brief Switches port to a gPTP master
- * @param annc If TRUE, starts announce event timer.
- * @return void
- */
- virtual void becomeMaster( bool annc ) = 0;
-
- /**
- * @brief Switches port to a gPTP slave.
- * @param restart_syntonization if TRUE, restarts the syntonization
- * @return void
- */
- virtual void becomeSlave( bool restart_syntonization ) = 0;
-
- /**
- * @brief Gets the AVnu automotive profile flag
- * @return automotive_profile flag
- */
- bool getAutomotiveProfile() { return(automotive_profile); }
-
- /**
- * @brief Sets the pDelay minimum interval
- * @param val time interval
- * @return none
- */
- void setPDelayInterval(signed char val) {
- log_min_mean_pdelay_req_interval = val;
- }
-
- /**
- * @brief Gets the pDelay minimum interval
- * @return PDelay interval
- */
- signed char getPDelayInterval(void) {
- return log_min_mean_pdelay_req_interval;
- }
-
- /**
- * @brief Sets the pDelay minimum interval back to initial
- * value
- * @return none
- */
- void resetInitPDelayInterval(void) {
- log_min_mean_pdelay_req_interval = initialLogPdelayReqInterval;
- }
-
- /**
- * @brief set initial pdelay interval
- * @param interval [in] log base 2 pdelay rate
- */
- void setInitPDelayInterval( int8_t interval )
- {
- initialLogPdelayReqInterval = interval;
- }
-
- /**
- * @brief get initial pdelay interval
- * @return log base 2 pdelay rate
- */
- int8_t getInitPDelayInterval(void)
- {
- return initialLogPdelayReqInterval;
- }
-
- /**
- * @brief Start pDelay interval timer
- * @param waitTime time interval
- * @return none
- */
- virtual void startPDelayIntervalTimer( unsigned long long waitTime ) {}
-
- /**
- * @brief Sets current sync count value.
- * @param cnt [in] sync count value
- * @return void
- */
- void setSyncCount(unsigned int cnt)
- {
- sync_count = cnt;
- }
-
- /**
- * @brief Increments sync count
- * @return void
- */
- void incSyncCount() {
- ++sync_count;
- }
-
- /**
- * @brief Gets current sync count value. It is set to zero
- * when master and incremented at each sync received for slave.
- * @return sync count
- */
- unsigned getSyncCount()
- {
- return sync_count;
- }
-
- /**
- * @brief Sets current pdelay count value.
- * @param cnt [in] pdelay count value
- * @return void
- */
- void setPdelayCount(unsigned int cnt) {
- pdelay_count = cnt;
- }
-
- /**
- * @brief Increments Pdelay count
- * @return void
- */
- void incPdelayCount()
- {
- ++pdelay_count;
- }
-
- /**
- * @brief Gets current pdelay count value. It is set to zero
- * when asCapable is false.
- * @return pdelay count
- */
- unsigned getPdelayCount()
- {
- return pdelay_count;
- }
-
- /**
- * @brief Increments announce sequence id and returns
- * @return Next announce sequence id.
- */
- uint16_t getNextAnnounceSequenceId( void )
- {
- return announce_sequence_id++;
- }
-
- /**
- * @brief Increments signal sequence id and returns
- * @return Next signal sequence id.
- */
- uint16_t getNextSignalSequenceId( void )
- {
- return signal_sequence_id++;
- }
-
- /**
- * @brief Increments sync sequence ID and returns
- * @return Next synce sequence id.
- */
- uint16_t getNextSyncSequenceId( void )
- {
- return sync_sequence_id++;
- }
-
- /**
- * @brief Gets the lastGmTimeBaseIndicator
- * @return uint16 of the lastGmTimeBaseIndicator
- */
- uint16_t getLastGmTimeBaseIndicator( void ) {
- return lastGmTimeBaseIndicator;
- }
-
- /**
- * @brief Sets the lastGmTimeBaseIndicator
- * @param gmTimeBaseIndicator from last Follow up message
- * @return void
- */
- void setLastGmTimeBaseIndicator(uint16_t gmTimeBaseIndicator)
- {
- lastGmTimeBaseIndicator = gmTimeBaseIndicator;
- }
-
- /**
- * @brief Gets the sync interval value
- * @return Sync Interval
- */
- signed char getSyncInterval( void )
- {
- return log_mean_sync_interval;
- }
-
- /**
- * @brief Sets the sync interval value
- * @param val time interval
- * @return none
- */
- void setSyncInterval( signed char val )
- {
- log_mean_sync_interval = val;
- }
-
- /**
- * @brief Sets the sync interval back to initial value
- * @return none
- */
- void resetInitSyncInterval( void )
- {
- log_mean_sync_interval = initialLogSyncInterval;;
- }
-
- /**
- * @brief Sets the sync interval
- * @return none
- */
- void setInitSyncInterval( signed char interval )
- {
- initialLogSyncInterval = interval;
- }
-
- /**
- * @brief Gets the sync interval
- * @return sync interval
- */
- signed char getInitSyncInterval( void )
- {
- return initialLogSyncInterval;
- }
-
- /**
- * @brief Gets the announce interval
- * @return Announce interval
- */
- signed char getAnnounceInterval( void ) {
- return log_mean_announce_interval;
- }
-
- /**
- * @brief Sets the announce interval
- * @param val time interval
- * @return none
- */
- void setAnnounceInterval(signed char val) {
- log_mean_announce_interval = val;
- }
- /**
- * @brief Start sync receipt timer
- * @param waitTime time interval
- * @return none
- */
- void startSyncReceiptTimer(long long unsigned int waitTime);
-
- /**
- * @brief Stop sync receipt timer
- * @return none
- */
- void stopSyncReceiptTimer( void );
-
- /**
- * @brief Start sync interval timer
- * @param waitTime time interval in nanoseconds
- * @return none
- */
- void startSyncIntervalTimer(long long unsigned int waitTime);
-
- /**
- * @brief Start announce interval timer
- * @param waitTime time interval
- * @return none
- */
- void startAnnounceIntervalTimer(long long unsigned int waitTime);
-
- /**
- * @brief Starts announce event timer
- * @return void
- */
- void startAnnounce();
-
- /**
- * @brief Process default state change event
- * @return true if event is handled without errors
- */
- bool processStateChange( Event e );
-
- /**
- * @brief Default sync/announce timeout handler
- * @return true if event is handled without errors
- */
- bool processSyncAnnounceTimeout( Event e );
-
-
- /**
- * @brief Perform default event action, can be overridden by media
- * specific actions in _processEvent
- * @return true if event is handled without errors
- */
- bool processEvent( Event e );
-
- /**
- * @brief Perform media specific event handling action
- * @return true if event is handled without errors
- */
- virtual bool _processEvent( Event e ) = 0;
-
- /**
- * @brief Performs media specific setup after start sync is completed
- * @return void
- */
- virtual void syncDone() = 0;
-
- /**
- * @brief Sends a general message to a port. No timestamps
- * @param buf [in] Pointer to the data buffer
- * @param len Size of the message
- * @param mcast_type Enumeration
- * MulticastType (pdelay, none or other). Depracated.
- * @param destIdentity Destination port identity
- * @return void
- */
- virtual void sendGeneralPort
- (uint16_t etherType, uint8_t * buf, int len, MulticastType mcast_type,
- PortIdentity * destIdentity) = 0;
-
- /**
- * @brief Sets link speed
- */
- void setLinkSpeed( uint32_t link_speed )
- {
- this->link_speed = link_speed;
- }
-
- /**
- * @brief Returns link speed
- */
- uint32_t getLinkSpeed( void )
- {
- return link_speed;
- }
-
- /**
- * @brief Returns TX PHY delay
- */
- Timestamp getTxPhyDelay( uint32_t link_speed ) const;
-
- /**
- * @brief Returns RX PHY delay
- */
- Timestamp getRxPhyDelay( uint32_t link_speed ) const;
-};
-
-/**
- * @brief Specifies a RX/TX PHY compensation pair
- */
-class phy_delay_spec_t
-{
-private:
- uint16_t tx_delay;
- uint16_t rx_delay;
-public:
- /**
- * Constructor setting PHY compensation
- */
- phy_delay_spec_t(
- uint16_t tx_delay,
- uint16_t rx_delay )
- {
- this->tx_delay = tx_delay;
- this->rx_delay = rx_delay;
- }
-
- /**
- * Default constructor sets 0 PHY compensation
- */
- phy_delay_spec_t()
- {
- phy_delay_spec_t( 0, 0 );
- }
-
- /**
- * @brief sets PHY compensation
- */
- void set_delay(
- uint16_t tx_delay,
- uint16_t rx_delay )
- {
- this->tx_delay = tx_delay;
- this->rx_delay = rx_delay;
- }
-
- /**
- * @brief sets RX PHY compensation
- */
- void set_tx_delay(
- uint16_t tx_delay )
- {
- this->tx_delay = tx_delay;
- }
-
- /**
- * @brief sets TX PHY compensation
- */
- void set_rx_delay(
- uint16_t rx_delay )
- {
- this->rx_delay = rx_delay;
- }
-
- /**
- * @brief gets TX PHY compensation
- */
- uint16_t get_tx_delay() const
- {
- return tx_delay;
- }
-
- /**
- * @brief gets RX PHY compensation
- */
- uint16_t get_rx_delay() const
- {
- return rx_delay;
- }
-};
-
-#endif/*COMMON_PORT_HPP*/
diff --git a/daemons/gptp/common/common_tstamper.hpp b/daemons/gptp/common/common_tstamper.hpp
deleted file mode 100644
index 557ac184..00000000
--- a/daemons/gptp/common/common_tstamper.hpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef COMMON_TSTAMPER_HPP
-#define COMMON_TSTAMPER_HPP
-
-#include <unordered_map>
-#include <stdint.h>
-#include <avbts_message.hpp>
-
-#define HWTIMESTAMPER_EXTENDED_MESSAGE_SIZE 4096 /*!< Maximum size of HWTimestamper extended message */
-
-/**
- * @brief Provides a generic interface for hardware timestamping
- */
-class CommonTimestamper {
-protected:
- uint8_t version; //!< HWTimestamper version
-
-public:
- /**
- * @brief Initializes the hardware timestamp unit
- * @param iface_label [in] Interface label
- * @param iface [in] Network interface
- * @return true
- */
- virtual bool HWTimestamper_init
- ( InterfaceLabel *iface_label, OSNetworkInterface *iface )
- { return true; }
-
- /**
- * @brief Reset the hardware timestamp unit
- * @return void
- */
- virtual void HWTimestamper_reset(void) {
- }
-
- /**
- * @brief This method is called before the object is de-allocated.
- * @return void
- */
- virtual void HWTimestamper_final(void) {
- }
-
- /**
- * @brief Sets system clock descriptor
- * @param system_clock_desc name of local clock
- * @return false if unimplemented
- */
- virtual bool HWTimestamper_setsystemclock
- ( const char *system_clock_desc )
- { return false; }
-
- /**
- * @brief Adjusts the hardware clock frequency
- * @param frequency_offset Frequency offset
- * @return false
- */
- virtual bool HWTimestamper_adjclockrate
- ( float frequency_offset ) const
- { return false; }
-
- /**
- * @brief Adjusts the hardware clock phase
- * @param phase_adjust Phase offset
- * @return false
- */
- virtual bool HWTimestamper_adjclockphase( int64_t phase_adjust )
- { return false; }
-
- /**
- * @brief Get the cross timestamping information.
- * The gPTP subsystem uses these samples to calculate
- * ratios which can be used to translate or extrapolate
- * one clock into another clock reference. The gPTP service
- * uses these supplied cross timestamps to perform internal
- * rate estimation and conversion functions.
- * @param system_time [out] System time
- * @param device_time [out] Device time
- * @param local_clock [out] Local clock
- * @param nominal_clock_rate [out] Nominal clock rate
- * @return True in case of success. FALSE in case of error
- */
- virtual bool HWTimestamper_gettime(Timestamp * system_time,
- Timestamp * device_time,
- uint32_t * local_clock,
- uint32_t * nominal_clock_rate) const = 0;
-
- /**
- * @brief Gets a string with the error from the hardware timestamp block
- * @param msg [out] String error
- * @return void
- * @todo There is no current implementation for this method.
- */
- virtual void HWTimestamper_get_extderror(char *msg) const
- {
- *msg = '\0';
- }
-
- /**
- * @brief Starts the PPS (pulse per second) interface
- * @return false
- */
- virtual bool HWTimestamper_PPS_start() { return false; };
-
- /**
- * @brief Stops the PPS (pulse per second) interface
- * @return true
- */
- virtual bool HWTimestamper_PPS_stop() { return true; };
-
- /**
- * @brief Gets the HWTimestamper version
- * @return version (signed integer)
- */
- int getVersion() const
- {
- return version;
- }
-
- /**
- * @brief Default constructor. Sets version to zero.
- */
- CommonTimestamper() { version = 0; }
-
- /**
- * @brief Deletes HWtimestamper object
- */
- virtual ~CommonTimestamper() { }
-};
-
-#endif/*COMMON_TSTAMPER_HPP*/
diff --git a/daemons/gptp/common/ether_port.cpp b/daemons/gptp/common/ether_port.cpp
deleted file mode 100644
index 56db3d22..00000000
--- a/daemons/gptp/common/ether_port.cpp
+++ /dev/null
@@ -1,881 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <ieee1588.hpp>
-
-#include <ether_port.hpp>
-#include <avbts_message.hpp>
-#include <avbts_clock.hpp>
-
-#include <avbts_oslock.hpp>
-#include <avbts_osnet.hpp>
-#include <avbts_oscondition.hpp>
-#include <ether_tstamper.hpp>
-
-#include <gptp_log.hpp>
-
-#include <stdio.h>
-
-#include <math.h>
-
-#include <stdlib.h>
-
-LinkLayerAddress EtherPort::other_multicast(OTHER_MULTICAST);
-LinkLayerAddress EtherPort::pdelay_multicast(PDELAY_MULTICAST);
-LinkLayerAddress EtherPort::test_status_multicast
-( TEST_STATUS_MULTICAST );
-
-OSThreadExitCode watchNetLinkWrapper(void *arg)
-{
- EtherPort *port;
-
- port = (EtherPort *) arg;
- if (port->watchNetLink() == NULL)
- return osthread_ok;
- else
- return osthread_error;
-}
-
-OSThreadExitCode openPortWrapper(void *arg)
-{
- EtherPort *port;
-
- port = (EtherPort *) arg;
- if (port->openPort(port) == NULL)
- return osthread_ok;
- else
- return osthread_error;
-}
-
-EtherPort::~EtherPort()
-{
- delete port_ready_condition;
-}
-
-EtherPort::EtherPort( PortInit_t *portInit ) :
- CommonPort( portInit )
-{
- linkUp = portInit->linkUp;
- setTestMode( portInit->testMode );
-
- pdelay_sequence_id = 0;
-
- pdelay_started = false;
- pdelay_halted = false;
- sync_rate_interval_timer_started = false;
-
- duplicate_resp_counter = 0;
- last_invalid_seqid = 0;
-
- operLogPdelayReqInterval = portInit->operLogPdelayReqInterval;
- operLogSyncInterval = portInit->operLogSyncInterval;
-
- if (getAutomotiveProfile())
- {
- setAsCapable( true );
-
- if (getInitSyncInterval() == LOG2_INTERVAL_INVALID)
- setInitSyncInterval( -5 ); // 31.25 ms
- if (getInitPDelayInterval() == LOG2_INTERVAL_INVALID)
- setInitPDelayInterval( 0 ); // 1 second
- if (operLogPdelayReqInterval == LOG2_INTERVAL_INVALID)
- operLogPdelayReqInterval = 0; // 1 second
- if (operLogSyncInterval == LOG2_INTERVAL_INVALID)
- operLogSyncInterval = 0; // 1 second
- } else
- {
- setAsCapable( false );
-
- if ( getInitSyncInterval() == LOG2_INTERVAL_INVALID )
- setInitSyncInterval( -3 ); // 125 ms
- if (getInitPDelayInterval() == LOG2_INTERVAL_INVALID)
- setInitPDelayInterval( 0 ); // 1 second
- if (operLogPdelayReqInterval == LOG2_INTERVAL_INVALID)
- operLogPdelayReqInterval = 0; // 1 second
- if (operLogSyncInterval == LOG2_INTERVAL_INVALID)
- operLogSyncInterval = 0; // 1 second
- }
-
- /*TODO: Add intervals below to a config interface*/
- resetInitPDelayInterval();
-
- last_sync = NULL;
- last_pdelay_req = NULL;
- last_pdelay_resp = NULL;
- last_pdelay_resp_fwup = NULL;
-
- setPdelayCount(0);
- setSyncCount(0);
-
- if( getAutomotiveProfile( ))
- {
- if (isGM) {
- avbSyncState = 1;
- }
- else {
- avbSyncState = 2;
- }
- if (getTestMode())
- {
- linkUpCount = 1; // TODO : really should check the current linkup status http://stackoverflow.com/questions/15723061/how-to-check-if-interface-is-up
- linkDownCount = 0;
- }
- setStationState(STATION_STATE_RESERVED);
- }
-}
-
-bool EtherPort::_init_port( void )
-{
- pdelay_rx_lock = lock_factory->createLock(oslock_recursive);
- port_tx_lock = lock_factory->createLock(oslock_recursive);
-
- pDelayIntervalTimerLock = lock_factory->createLock(oslock_recursive);
-
- port_ready_condition = condition_factory->createCondition();
-
- return true;
-}
-
-void EtherPort::startPDelay()
-{
- if(!pdelayHalted()) {
- if( getAutomotiveProfile( ))
- {
- if( getPDelayInterval() !=
- PTPMessageSignalling::sigMsgInterval_NoSend)
- {
- pdelay_started = true;
- startPDelayIntervalTimer(EVENT_TIMER_GRANULARITY);
- }
- }
- else {
- pdelay_started = true;
- startPDelayIntervalTimer(32000000);
- }
- }
-}
-
-void EtherPort::stopPDelay()
-{
- haltPdelay(true);
- pdelay_started = false;
- clock->deleteEventTimerLocked( this, PDELAY_INTERVAL_TIMEOUT_EXPIRES);
-}
-
-void EtherPort::startSyncRateIntervalTimer()
-{
- if( getAutomotiveProfile( ))
- {
- sync_rate_interval_timer_started = true;
- if (isGM) {
- // GM will wait up to 8 seconds for signaling rate
- // TODO: This isn't according to spec but set because it is believed that some slave devices aren't signalling
- // to reduce the rate
- clock->addEventTimerLocked( this, SYNC_RATE_INTERVAL_TIMEOUT_EXPIRED, 8000000000 );
- }
- else {
- // Slave will time out after 4 seconds
- clock->addEventTimerLocked( this, SYNC_RATE_INTERVAL_TIMEOUT_EXPIRED, 4000000000 );
- }
- }
-}
-
-void EtherPort::processMessage
-( char *buf, int length, LinkLayerAddress *remote, uint32_t link_speed )
-{
- GPTP_LOG_VERBOSE("Processing network buffer");
-
- PTPMessageCommon *msg =
- buildPTPMessage( buf, (int)length, remote, this );
-
- if (msg == NULL)
- {
- GPTP_LOG_ERROR("Discarding invalid message");
- return;
- }
- GPTP_LOG_VERBOSE("Processing message");
-
- if( msg->isEvent() )
- {
- Timestamp rx_timestamp = msg->getTimestamp();
- Timestamp phy_compensation = getRxPhyDelay( link_speed );
- GPTP_LOG_DEBUG( "RX PHY compensation: %s sec",
- phy_compensation.toString().c_str() );
- phy_compensation._version = rx_timestamp._version;
- rx_timestamp = rx_timestamp - phy_compensation;
- msg->setTimestamp( rx_timestamp );
- }
-
- msg->processMessage(this);
- if (msg->garbage())
- delete msg;
-}
-
-void *EtherPort::openPort( EtherPort *port )
-{
- port_ready_condition->signal();
-
- while (1) {
- uint8_t buf[128];
- LinkLayerAddress remote;
- net_result rrecv;
- size_t length = sizeof(buf);
- uint32_t link_speed;
-
- if ( ( rrecv = recv( &remote, buf, length, link_speed ))
- == net_succeed )
- {
- processMessage
- ((char *)buf, (int)length, &remote, link_speed );
- } else if (rrecv == net_fatal) {
- GPTP_LOG_ERROR("read from network interface failed");
- this->processEvent(FAULT_DETECTED);
- break;
- }
- }
-
- return NULL;
-}
-
-net_result EtherPort::port_send
-( uint16_t etherType, uint8_t *buf, int size, MulticastType mcast_type,
- PortIdentity *destIdentity, bool timestamp )
-{
- LinkLayerAddress dest;
-
- if (mcast_type != MCAST_NONE) {
- if (mcast_type == MCAST_PDELAY) {
- dest = pdelay_multicast;
- }
- else if (mcast_type == MCAST_TEST_STATUS) {
- dest = test_status_multicast;
- }
- else {
- dest = other_multicast;
- }
- } else {
- mapSocketAddr(destIdentity, &dest);
- }
-
- return send(&dest, etherType, (uint8_t *) buf, size, timestamp);
-}
-
-void EtherPort::sendEventPort
-( uint16_t etherType, uint8_t *buf, int size, MulticastType mcast_type,
- PortIdentity *destIdentity, uint32_t *link_speed )
-{
- net_result rtx = port_send
- ( etherType, buf, size, mcast_type, destIdentity, true );
- if( rtx != net_succeed )
- {
- GPTP_LOG_ERROR("sendEventPort(): failure");
- return;
- }
-
- *link_speed = this->getLinkSpeed();
-
- return;
-}
-
-void EtherPort::sendGeneralPort
-( uint16_t etherType, uint8_t *buf, int size, MulticastType mcast_type,
- PortIdentity * destIdentity )
-{
- net_result rtx = port_send(etherType, buf, size, mcast_type, destIdentity, false);
- if (rtx != net_succeed) {
- GPTP_LOG_ERROR("sendGeneralPort(): failure");
- }
-
- return;
-}
-
-bool EtherPort::_processEvent( Event e )
-{
- bool ret;
-
- switch (e) {
- case POWERUP:
- case INITIALIZE:
- if( !getAutomotiveProfile( ))
- {
- if ( getPortState() != PTP_SLAVE &&
- getPortState() != PTP_MASTER )
- {
- GPTP_LOG_STATUS("Starting PDelay");
- startPDelay();
- }
- }
- else {
- startPDelay();
- }
-
- port_ready_condition->wait_prelock();
-
- if( !linkWatch(watchNetLinkWrapper, (void *)this) )
- {
- GPTP_LOG_ERROR("Error creating port link thread");
- ret = false;
- break;
- }
-
- if( !linkOpen(openPortWrapper, (void *)this) )
- {
- GPTP_LOG_ERROR("Error creating port thread");
- ret = false;
- break;
- }
-
- port_ready_condition->wait();
-
- if( getAutomotiveProfile( ))
- {
- setStationState(STATION_STATE_ETHERNET_READY);
- if (getTestMode())
- {
- APMessageTestStatus *testStatusMsg = new APMessageTestStatus(this);
- if (testStatusMsg) {
- testStatusMsg->sendPort(this);
- delete testStatusMsg;
- }
- }
- if (!isGM) {
- // Send an initial signalling message
- PTPMessageSignalling *sigMsg = new PTPMessageSignalling(this);
- if (sigMsg) {
- sigMsg->setintervals(PTPMessageSignalling::sigMsgInterval_NoSend, getSyncInterval(), PTPMessageSignalling::sigMsgInterval_NoSend);
- sigMsg->sendPort(this, NULL);
- delete sigMsg;
- }
-
- startSyncReceiptTimer((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double) pow((double)2, getSyncInterval()) *
- 1000000000.0)));
- }
- }
-
- ret = true;
- break;
- case STATE_CHANGE_EVENT:
- // If the automotive profile is enabled, handle the event by
- // doing nothing and returning true, preventing the default
- // action from executing
- if( getAutomotiveProfile( ))
- ret = true;
- else
- ret = false;
-
- break;
- case LINKUP:
- haltPdelay(false);
- startPDelay();
- if( getAutomotiveProfile( ))
- {
- GPTP_LOG_EXCEPTION("LINKUP");
- }
- else {
- GPTP_LOG_STATUS("LINKUP");
- }
-
- if( clock->getPriority1() == 255 || getPortState() == PTP_SLAVE ) {
- becomeSlave( true );
- } else if( getPortState() == PTP_MASTER ) {
- becomeMaster( true );
- } else {
- clock->addEventTimerLocked
- ( this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
- (uint64_t)
- ( ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER *
- pow( 2.0, getAnnounceInterval( )) *
- 1000000000.0 ));
- }
-
- if( getAutomotiveProfile( ))
- {
- setAsCapable( true );
-
- setStationState(STATION_STATE_ETHERNET_READY);
- if (getTestMode())
- {
- APMessageTestStatus *testStatusMsg = new APMessageTestStatus(this);
- if (testStatusMsg) {
- testStatusMsg->sendPort(this);
- delete testStatusMsg;
- }
- }
-
- resetInitSyncInterval();
- setAnnounceInterval( 0 );
- resetInitPDelayInterval();
-
- if (!isGM) {
- // Send an initial signaling message
- PTPMessageSignalling *sigMsg = new PTPMessageSignalling(this);
- if (sigMsg) {
- sigMsg->setintervals(PTPMessageSignalling::sigMsgInterval_NoSend, getSyncInterval(), PTPMessageSignalling::sigMsgInterval_NoSend);
- sigMsg->sendPort(this, NULL);
- delete sigMsg;
- }
-
- startSyncReceiptTimer((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double) pow((double)2, getSyncInterval()) *
- 1000000000.0)));
- }
-
- // Reset Sync count and pdelay count
- setPdelayCount(0);
- setSyncCount(0);
-
- // Start AVB SYNC at 2. It will decrement after each sync. When it reaches 0 the Test Status message
- // can be sent
- if (isGM) {
- avbSyncState = 1;
- }
- else {
- avbSyncState = 2;
- }
-
- if (getTestMode())
- {
- linkUpCount++;
- }
- }
- this->timestamper_reset();
-
- ret = true;
- break;
- case LINKDOWN:
- stopPDelay();
- if( getAutomotiveProfile( ))
- {
- GPTP_LOG_EXCEPTION("LINK DOWN");
- }
- else {
- setAsCapable(false);
- GPTP_LOG_STATUS("LINK DOWN");
- }
- if (getTestMode())
- {
- linkDownCount++;
- }
-
- ret = true;
- break;
- case ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES:
- case SYNC_RECEIPT_TIMEOUT_EXPIRES:
- if( !getAutomotiveProfile( ))
- {
- ret = false;
- break;
- }
-
- // Automotive Profile specific action
- if (e == SYNC_RECEIPT_TIMEOUT_EXPIRES) {
- GPTP_LOG_EXCEPTION("SYNC receipt timeout");
-
- startSyncReceiptTimer((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double) pow((double)2, getSyncInterval()) *
- 1000000000.0)));
- }
- ret = true;
- break;
- case PDELAY_INTERVAL_TIMEOUT_EXPIRES:
- GPTP_LOG_DEBUG("PDELAY_INTERVAL_TIMEOUT_EXPIRES occured");
- {
- Timestamp req_timestamp;
-
- PTPMessagePathDelayReq *pdelay_req =
- new PTPMessagePathDelayReq(this);
- PortIdentity dest_id;
- getPortIdentity(dest_id);
- pdelay_req->setPortIdentity(&dest_id);
-
- {
- Timestamp pending =
- PDELAY_PENDING_TIMESTAMP;
- pdelay_req->setTimestamp(pending);
- }
-
- if (last_pdelay_req != NULL) {
- delete last_pdelay_req;
- }
- setLastPDelayReq(pdelay_req);
-
- getTxLock();
- pdelay_req->sendPort(this, NULL);
- GPTP_LOG_DEBUG("*** Sent PDelay Request message");
- putTxLock();
-
- {
- long long timeout;
- long long interval;
-
- timeout = PDELAY_RESP_RECEIPT_TIMEOUT_MULTIPLIER *
- ((long long)
- (pow((double)2,getPDelayInterval())*1000000000.0));
-
- timeout = timeout > EVENT_TIMER_GRANULARITY ?
- timeout : EVENT_TIMER_GRANULARITY;
- clock->addEventTimerLocked
- (this, PDELAY_RESP_RECEIPT_TIMEOUT_EXPIRES, timeout );
- GPTP_LOG_DEBUG("Schedule PDELAY_RESP_RECEIPT_TIMEOUT_EXPIRES, "
- "PDelay interval %d, timeout %lld",
- getPDelayInterval(), timeout);
-
- interval =
- ((long long)
- (pow((double)2,getPDelayInterval())*1000000000.0));
- interval = interval > EVENT_TIMER_GRANULARITY ?
- interval : EVENT_TIMER_GRANULARITY;
- startPDelayIntervalTimer(interval);
- }
- }
- break;
- case SYNC_INTERVAL_TIMEOUT_EXPIRES:
- {
- /* Set offset from master to zero, update device vs
- system time offset */
-
- // Send a sync message and then a followup to broadcast
- PTPMessageSync *sync = new PTPMessageSync(this);
- PortIdentity dest_id;
- bool tx_succeed;
- getPortIdentity(dest_id);
- sync->setPortIdentity(&dest_id);
- getTxLock();
- tx_succeed = sync->sendPort(this, NULL);
- GPTP_LOG_DEBUG("Sent SYNC message");
-
- if( getAutomotiveProfile() &&
- getPortState() == PTP_MASTER )
- {
- if (avbSyncState > 0) {
- avbSyncState--;
- if (avbSyncState == 0) {
- // Send Avnu Automotive Profile status message
- setStationState(STATION_STATE_AVB_SYNC);
- if (getTestMode()) {
- APMessageTestStatus *testStatusMsg = new APMessageTestStatus(this);
- if (testStatusMsg) {
- testStatusMsg->sendPort(this);
- delete testStatusMsg;
- }
- }
- }
- }
- }
- putTxLock();
-
- if ( tx_succeed )
- {
- Timestamp sync_timestamp = sync->getTimestamp();
-
- GPTP_LOG_VERBOSE("Successful Sync timestamp");
- GPTP_LOG_VERBOSE("Seconds: %u",
- sync_timestamp.seconds_ls);
- GPTP_LOG_VERBOSE("Nanoseconds: %u",
- sync_timestamp.nanoseconds);
-
- PTPMessageFollowUp *follow_up = new PTPMessageFollowUp(this);
- PortIdentity dest_id;
- getPortIdentity(dest_id);
-
- follow_up->setClockSourceTime(getClock()->getFUPInfo());
- follow_up->setPortIdentity(&dest_id);
- follow_up->setSequenceId(sync->getSequenceId());
- follow_up->setPreciseOriginTimestamp
- (sync_timestamp);
- follow_up->sendPort(this, NULL);
- delete follow_up;
- } else {
- GPTP_LOG_ERROR
- ("*** Unsuccessful Sync timestamp");
- }
- delete sync;
- }
- break;
- case FAULT_DETECTED:
- GPTP_LOG_ERROR("Received FAULT_DETECTED event");
- if( !getAutomotiveProfile( ))
- {
- setAsCapable(false);
- }
- break;
- case PDELAY_DEFERRED_PROCESSING:
- GPTP_LOG_DEBUG("PDELAY_DEFERRED_PROCESSING occured");
- pdelay_rx_lock->lock();
- if (last_pdelay_resp_fwup == NULL) {
- GPTP_LOG_ERROR("PDelay Response Followup is NULL!");
- abort();
- }
- last_pdelay_resp_fwup->processMessage(this);
- if (last_pdelay_resp_fwup->garbage()) {
- delete last_pdelay_resp_fwup;
- this->setLastPDelayRespFollowUp(NULL);
- }
- pdelay_rx_lock->unlock();
- break;
- case PDELAY_RESP_RECEIPT_TIMEOUT_EXPIRES:
- if( !getAutomotiveProfile( ))
- {
- GPTP_LOG_EXCEPTION("PDelay Response Receipt Timeout");
- setAsCapable(false);
- }
- setPdelayCount( 0 );
- break;
-
- case PDELAY_RESP_PEER_MISBEHAVING_TIMEOUT_EXPIRES:
- GPTP_LOG_EXCEPTION("PDelay Resp Peer Misbehaving timeout expired! Restarting PDelay");
-
- haltPdelay(false);
- if( getPortState() != PTP_SLAVE &&
- getPortState() != PTP_MASTER )
- {
- GPTP_LOG_STATUS("Starting PDelay" );
- startPDelay();
- }
- break;
- case SYNC_RATE_INTERVAL_TIMEOUT_EXPIRED:
- {
- GPTP_LOG_INFO("SYNC_RATE_INTERVAL_TIMEOUT_EXPIRED occured");
-
- sync_rate_interval_timer_started = false;
-
- bool sendSignalMessage = false;
- if ( getSyncInterval() != operLogSyncInterval )
- {
- setSyncInterval( operLogSyncInterval );
- sendSignalMessage = true;
- }
-
- if( getPDelayInterval() != operLogPdelayReqInterval)
- {
- setPDelayInterval( operLogPdelayReqInterval );
- sendSignalMessage = true;
- }
-
- if (sendSignalMessage) {
- if (!isGM) {
- // Send operational signalling message
- PTPMessageSignalling *sigMsg = new PTPMessageSignalling(this);
- if (sigMsg) {
- if( getAutomotiveProfile( ))
- sigMsg->setintervals(PTPMessageSignalling::sigMsgInterval_NoChange, getSyncInterval(), PTPMessageSignalling::sigMsgInterval_NoChange);
- else
- sigMsg->setintervals(getPDelayInterval(), getSyncInterval(), PTPMessageSignalling::sigMsgInterval_NoChange);
- sigMsg->sendPort(this, NULL);
- delete sigMsg;
- }
-
- startSyncReceiptTimer((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double) pow((double)2, getSyncInterval()) *
- 1000000000.0)));
- }
- }
- }
-
- break;
- default:
- GPTP_LOG_ERROR
- ( "Unhandled event type in "
- "EtherPort::processEvent(), %d", e );
- ret = false;
- break;
- }
-
- return ret;
-}
-
-void EtherPort::recoverPort( void )
-{
- return;
-}
-
-void EtherPort::becomeMaster( bool annc ) {
- setPortState( PTP_MASTER );
- // Stop announce receipt timeout timer
- clock->deleteEventTimerLocked( this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES );
-
- // Stop sync receipt timeout timer
- stopSyncReceiptTimer();
-
- if( annc ) {
- if( !getAutomotiveProfile( ))
- {
- startAnnounce();
- }
- }
- startSyncIntervalTimer(16000000);
- GPTP_LOG_STATUS("Switching to Master" );
-
- clock->updateFUPInfo();
-
- return;
-}
-
-void EtherPort::becomeSlave( bool restart_syntonization ) {
- clock->deleteEventTimerLocked( this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES );
- clock->deleteEventTimerLocked( this, SYNC_INTERVAL_TIMEOUT_EXPIRES );
-
- setPortState( PTP_SLAVE );
-
- if( !getAutomotiveProfile( ))
- {
- clock->addEventTimerLocked
- (this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
- (ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER*
- (unsigned long long)
- (pow((double)2,getAnnounceInterval())*1000000000.0)));
- }
-
- GPTP_LOG_STATUS("Switching to Slave" );
- if( restart_syntonization ) clock->newSyntonizationSetPoint();
-
- getClock()->updateFUPInfo();
-
- return;
-}
-
-void EtherPort::mapSocketAddr
-( PortIdentity *destIdentity, LinkLayerAddress *remote )
-{
- *remote = identity_map[*destIdentity];
- return;
-}
-
-void EtherPort::addSockAddrMap
-( PortIdentity *destIdentity, LinkLayerAddress *remote )
-{
- identity_map[*destIdentity] = *remote;
- return;
-}
-
-int EtherPort::getTxTimestamp
-( PTPMessageCommon *msg, Timestamp &timestamp, unsigned &counter_value,
- bool last )
-{
- PortIdentity identity;
- msg->getPortIdentity(&identity);
- return getTxTimestamp
- (&identity, msg->getMessageId(), timestamp, counter_value, last);
-}
-
-int EtherPort::getRxTimestamp
-( PTPMessageCommon * msg, Timestamp & timestamp, unsigned &counter_value,
- bool last )
-{
- PortIdentity identity;
- msg->getPortIdentity(&identity);
- return getRxTimestamp
- (&identity, msg->getMessageId(), timestamp, counter_value, last);
-}
-
-int EtherPort::getTxTimestamp
-(PortIdentity *sourcePortIdentity, PTPMessageId messageId,
- Timestamp &timestamp, unsigned &counter_value, bool last )
-{
- EtherTimestamper *timestamper =
- dynamic_cast<EtherTimestamper *>(_hw_timestamper);
- if (timestamper)
- {
- return timestamper->HWTimestamper_txtimestamp
- ( sourcePortIdentity, messageId, timestamp,
- counter_value, last );
- }
- timestamp = clock->getSystemTime();
- return 0;
-}
-
-int EtherPort::getRxTimestamp
-( PortIdentity * sourcePortIdentity, PTPMessageId messageId,
- Timestamp &timestamp, unsigned &counter_value, bool last )
-{
- EtherTimestamper *timestamper =
- dynamic_cast<EtherTimestamper *>(_hw_timestamper);
- if (timestamper)
- {
- return timestamper->HWTimestamper_rxtimestamp
- (sourcePortIdentity, messageId, timestamp, counter_value,
- last);
- }
- timestamp = clock->getSystemTime();
- return 0;
-}
-
-void EtherPort::startPDelayIntervalTimer
-( long long unsigned int waitTime )
-{
- pDelayIntervalTimerLock->lock();
- clock->deleteEventTimerLocked(this, PDELAY_INTERVAL_TIMEOUT_EXPIRES);
- clock->addEventTimerLocked(this, PDELAY_INTERVAL_TIMEOUT_EXPIRES, waitTime);
- pDelayIntervalTimerLock->unlock();
-}
-
-void EtherPort::syncDone() {
- GPTP_LOG_VERBOSE("Sync complete");
-
- if( getAutomotiveProfile() && getPortState() == PTP_SLAVE )
- {
- if (avbSyncState > 0) {
- avbSyncState--;
- if (avbSyncState == 0) {
- setStationState(STATION_STATE_AVB_SYNC);
- if (getTestMode()) {
- APMessageTestStatus *testStatusMsg =
- new APMessageTestStatus(this);
- if (testStatusMsg) {
- testStatusMsg->sendPort(this);
- delete testStatusMsg;
- }
- }
- }
- }
- }
-
- if( getAutomotiveProfile( ))
- {
- if (!sync_rate_interval_timer_started) {
- if ( getSyncInterval() != operLogSyncInterval )
- {
- startSyncRateIntervalTimer();
- }
- }
- }
-
- if( !pdelay_started ) {
- startPDelay();
- }
-}
diff --git a/daemons/gptp/common/ether_port.hpp b/daemons/gptp/common/ether_port.hpp
deleted file mode 100644
index 4c878951..00000000
--- a/daemons/gptp/common/ether_port.hpp
+++ /dev/null
@@ -1,598 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef ETHER_PORT_HPP
-#define ETHER_PORT_HPP
-
-#include <ieee1588.hpp>
-#include <avbap_message.hpp>
-
-#include <avbts_ostimer.hpp>
-#include <avbts_oslock.hpp>
-#include <avbts_osnet.hpp>
-#include <avbts_osthread.hpp>
-#include <avbts_oscondition.hpp>
-#include <ipcdef.hpp>
-#include <gptp_log.hpp>
-
-#include <stdint.h>
-
-#include <map>
-#include <list>
-
-#include <common_port.hpp>
-
-/**@file*/
-
-#define GPTP_MULTICAST 0x0180C200000EULL /*!< GPTP multicast adddress */
-#define PDELAY_MULTICAST GPTP_MULTICAST /*!< PDELAY Multicast value */
-#define OTHER_MULTICAST GPTP_MULTICAST /*!< OTHER multicast value */
-#define TEST_STATUS_MULTICAST 0x011BC50AC000ULL /*!< AVnu Automotive profile test status msg Multicast value */
-
-#define PDELAY_RESP_RECEIPT_TIMEOUT_MULTIPLIER 3 /*!< PDelay timeout multiplier*/
-
-/**
- * @brief PortType enumeration. Selects between delay request-response (E2E) mechanism
- * or PTPV1 or PTPV2 P2P (peer delay) mechanism.
- */
-typedef enum {
- V1,
- V2_E2E,
- V2_P2P
-} PortType;
-
-/**
- * @brief Provides a map for the identityMap member of EtherPort
- * class
- */
-typedef std::map < PortIdentity, LinkLayerAddress > IdentityMap_t;
-
-
-/**
- * @brief Ethernet specific port functions
- */
-class EtherPort : public CommonPort
-{
- static LinkLayerAddress other_multicast;
- static LinkLayerAddress pdelay_multicast;
- static LinkLayerAddress test_status_multicast;
-
- /* Port Status */
- // set to 0 when asCapable is false, increment for each pdelay recvd
- bool linkUp;
-
- /* Port Configuration */
- signed char log_mean_unicast_sync_interval;
- signed char log_min_mean_delay_req_interval;
-
- unsigned int duplicate_resp_counter;
- uint16_t last_invalid_seqid;
-
- /* Automotive Profile : Static variables */
- // port_state : already defined as port_state
- bool isGM;
- // asCapable : already defined as asCapable
- signed char operLogPdelayReqInterval;
- signed char operLogSyncInterval;
-
- // Test Status variables
- uint32_t linkUpCount;
- uint32_t linkDownCount;
- StationState_t stationState;
-
-
- /* Automotive Profile : Persistant variables */
- // neighborPropDelay : defined as one_way_delay ??
- // rateRatio : Optional and didn't fine this variable. Will proceed without writing it.
- // neighborRateRatio : defined as _peer_rate_offset ??
-
- // Automotive Profile AVB SYNC state indicator. > 0 will inditate valid AVB SYNC state
- uint32_t avbSyncState;
-
- uint16_t pdelay_sequence_id;
- PTPMessagePathDelayReq *last_pdelay_req;
- PTPMessagePathDelayResp *last_pdelay_resp;
- PTPMessagePathDelayRespFollowUp *last_pdelay_resp_fwup;
-
- IdentityMap_t identity_map;
-
- PTPMessageSync *last_sync;
-
- OSCondition *port_ready_condition;
-
- OSLock *pdelay_rx_lock;
- OSLock *port_tx_lock;
-
- OSLock *pDelayIntervalTimerLock;
-
- net_result port_send
- (uint16_t etherType, uint8_t * buf, int size, MulticastType mcast_type,
- PortIdentity * destIdentity, bool timestamp);
-
- bool pdelay_started;
- bool pdelay_halted;
- bool sync_rate_interval_timer_started;
-
-protected:
- static const unsigned int DUPLICATE_RESP_THRESH = 3;
-
- public:
- void becomeMaster( bool annc );
- void becomeSlave( bool restart_syntonization );
-
- /**
- * @brief Starts pDelay event timer.
- * @return void
- */
- void startPDelay();
-
- /**
- * @brief Stops PDelay event timer
- * @return void
- */
- void stopPDelay();
-
- /**
- * @brief Enable/Disable PDelay Request messages
- * @param hlt True to HALT (stop sending), False to resume (start sending).
- */
- void haltPdelay(bool hlt)
- {
- pdelay_halted = hlt;
- }
-
- /**
- * @brief Get the status of pdelayHalted condition.
- * @return True PdelayRequest halted. False when PDelay Request is running
- */
- bool pdelayHalted(void)
- {
- return pdelay_halted;
- }
-
- /**
- * @brief Starts Sync Rate Interval event timer. Used for the
- * Automotive Profile.
- * @return void
- */
- void startSyncRateIntervalTimer();
-
- /**
- * @brief Starts pDelay event timer if not yet started.
- * @return void
- */
- void syncDone();
-
- /**
- * @brief Destroys a EtherPort
- */
- ~EtherPort();
-
- /**
- * @brief Creates the EtherPort interface.
- * @param init PortInit initialization parameters
- */
- EtherPort( PortInit_t *portInit );
-
- /**
- * @brief Initializes the port. Creates network interface, initializes
- * hardware timestamper and create OS locks conditions
- * @return FALSE if error during building the interface. TRUE if success
- */
- bool _init_port( void );
-
- /**
- * @brief Currently doesnt do anything. Just returns.
- * @return void
- */
- void recoverPort(void);
-
- /**
- * @brief Message processing logic on receipt
- * @param [in] buf buffer containing message
- * @param [in] length buffer length
- * @param [in] remote address of sender
- * @param [in] link_speed of the receiving device
- */
- void processMessage
- ( char *buf, int length, LinkLayerAddress *remote,
- uint32_t link_speed );
-
- /**
- * @brief Receives messages from the network interface
- * @return Its an infinite loop. Returns NULL in case of error.
- */
- void *openPort( EtherPort *port );
-
- /**
- * @brief Sends and event to a IEEE1588 port. It includes timestamp
- * @param buf [in] Pointer to the data buffer
- * @param len Size of the message
- * @param mcast_type Enumeration MulticastType (pdlay, none or other). Depracated.
- * @param destIdentity Destination port identity
- * @param [out] link_speed indicates link speed
- * @return void
- */
- void sendEventPort
- (uint16_t etherType, uint8_t * buf, int len, MulticastType mcast_type,
- PortIdentity * destIdentity, uint32_t *link_speed );
-
- /**
- * @brief Sends a general message to a port. No timestamps
- * @param buf [in] Pointer to the data buffer
- * @param len Size of the message
- * @param mcast_type Enumeration MulticastType (pdelay, none or other). Depracated.
- * @param destIdentity Destination port identity
- * @return void
- */
- void sendGeneralPort
- (uint16_t etherType, uint8_t * buf, int len, MulticastType mcast_type,
- PortIdentity * destIdentity);
-
- /**
- * @brief Process all events for a EtherPort
- * @param e Event to be processed
- * @return true if event is handled, false otherwise
- */
- bool _processEvent(Event e);
-
- /**
- * @brief Adds a foreign master.
- * @param msg [in] PTP announce message
- * @return void
- * @todo Currently not implemented
- */
- void addForeignMaster(PTPMessageAnnounce * msg);
-
- /**
- * @brief Remove a foreign master.
- * @param msg [in] PTP announce message
- * @return void
- * @todo Currently not implemented
- */
- void removeForeignMaster(PTPMessageAnnounce * msg);
-
- /**
- * @brief Remove all foreign masters.
- * @return void
- * @todo Currently not implemented
- */
- void removeForeignMasterAll(void);
-
- /**
- * @brief Start pDelay interval timer
- * @param waitTime time interval
- * @return none
- */
- void startPDelayIntervalTimer(long long unsigned int waitTime);
-
- /**
- * @brief Increments PDelay sequence ID and returns.
- * @return Next PDelay sequence id.
- */
- uint16_t getNextPDelaySequenceId(void) {
- return pdelay_sequence_id++;
- }
-
- /**
- * @brief Gets last sync sequence number from parent
- * @return Parent last sync sequence number
- * @todo Not currently implemented.
- */
- uint16_t getParentLastSyncSequenceNumber(void);
-
- /**
- * @brief Sets last sync sequence number from parent
- * @param num Sequence number
- * @return void
- * @todo Currently not implemented.
- */
- void setParentLastSyncSequenceNumber(uint16_t num);
-
- /**
- * @brief Sets last sync ptp message
- * @param msg [in] PTP sync message
- * @return void
- */
- void setLastSync(PTPMessageSync * msg) {
- last_sync = msg;
- }
-
- /**
- * @brief Gets last sync message
- * @return PTPMessageSync last sync
- */
- PTPMessageSync *getLastSync(void) {
- return last_sync;
- }
-
- /**
- * @brief Locks PDelay RX
- * @return TRUE if acquired the lock. FALSE otherwise
- */
- bool getPDelayRxLock() {
- return pdelay_rx_lock->lock() == oslock_ok ? true : false;
- }
-
- /**
- * @brief Do a trylock on the PDelay RX
- * @return TRUE if acquired the lock. FALSE otherwise.
- */
- bool tryPDelayRxLock() {
- return pdelay_rx_lock->trylock() == oslock_ok ? true : false;
- }
-
- /**
- * @brief Unlocks PDelay RX.
- * @return TRUE if success. FALSE otherwise
- */
- bool putPDelayRxLock() {
- return pdelay_rx_lock->unlock() == oslock_ok ? true : false;
- }
-
- bool getTxLock() {
- return port_tx_lock->lock() == oslock_ok ? true : false;
- }
-
- bool putTxLock() {
- return port_tx_lock->unlock() == oslock_ok ? true : false;
- }
-
- /**
- * @brief Sets the last_pdelay_req message
- * @param msg [in] PTPMessagePathDelayReq message to set
- * @return void
- */
- void setLastPDelayReq(PTPMessagePathDelayReq * msg) {
- last_pdelay_req = msg;
- }
-
- /**
- * @brief Gets the last PTPMessagePathDelayReq message
- * @return Last pdelay request
- */
- PTPMessagePathDelayReq *getLastPDelayReq(void) {
- return last_pdelay_req;
- }
-
- /**
- * @brief Sets the last PTPMessagePathDelayResp message
- * @param msg [in] Last pdelay response
- * @return void
- */
- void setLastPDelayResp(PTPMessagePathDelayResp * msg) {
- last_pdelay_resp = msg;
- }
-
- /**
- * @brief Gets the last PTPMessagePathDelayResp message
- * @return Last pdelay response
- */
- PTPMessagePathDelayResp *getLastPDelayResp(void) {
- return last_pdelay_resp;
- }
-
- /**
- * @brief Sets the last PTPMessagePathDelayRespFollowUp message
- * @param msg [in] last pdelay response follow up
- * @return void
- */
- void setLastPDelayRespFollowUp(PTPMessagePathDelayRespFollowUp * msg) {
- last_pdelay_resp_fwup = msg;
- }
-
- /**
- * @brief Gets the last PTPMessagePathDelayRespFollowUp message
- * @return last pdelay response follow up
- */
- PTPMessagePathDelayRespFollowUp *getLastPDelayRespFollowUp(void) {
- return last_pdelay_resp_fwup;
- }
-
- /**
- * @brief Gets RX timestamp based on port identity
- * @param sourcePortIdentity [in] Source port identity
- * @param sequenceId Sequence ID
- * @param timestamp [out] RX timestamp
- * @param counter_value [out] timestamp count value
- * @param last If true, removes the rx lock.
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- int getRxTimestamp
- (PortIdentity * sourcePortIdentity, PTPMessageId messageId,
- Timestamp & timestamp, unsigned &counter_value, bool last);
-
- /**
- * @brief Gets TX timestamp based on port identity
- * @param sourcePortIdentity [in] Source port identity
- * @param sequenceId Sequence ID
- * @param timestamp [out] TX timestamp
- * @param counter_value [out] timestamp count value
- * @param last If true, removes the TX lock
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- int getTxTimestamp
- (PortIdentity * sourcePortIdentity, PTPMessageId messageId,
- Timestamp & timestamp, unsigned &counter_value, bool last);
-
- /**
- * @brief Gets TX timestamp based on PTP message
- * @param msg PTPMessageCommon message
- * @param timestamp [out] TX timestamp
- * @param counter_value [out] timestamp count value
- * @param last If true, removes the TX lock
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- int getTxTimestamp
- (PTPMessageCommon * msg, Timestamp & timestamp, unsigned &counter_value,
- bool last);
-
- /**
- * @brief Gets RX timestamp based on PTP message
- * @param msg PTPMessageCommon message
- * @param timestamp [out] RX timestamp
- * @param counter_value [out] timestamp count value
- * @param last If true, removes the RX lock
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- int getRxTimestamp
- (PTPMessageCommon * msg, Timestamp & timestamp, unsigned &counter_value,
- bool last);
-
- /**
- * @brief Sets the value of last duplicated SeqID
- * @param seqid Value to set
- * @return void
- */
- void setLastInvalidSeqID(uint16_t seqid)
- {
- last_invalid_seqid = seqid;
- }
-
- /**
- * @brief Get the value of last invalid seqID
- * @return Last invalid seq id
- */
- uint16_t getLastInvalidSeqID(void)
- {
- return last_invalid_seqid;
- }
-
- /**
- * @brief Sets the duplicate pdelay_resp counter.
- * @param cnt Value to be set
- */
- void setDuplicateRespCounter(unsigned int cnt)
- {
- duplicate_resp_counter = cnt;
- }
-
- /**
- * @brief Gets the current value of pdelay_resp duplicate messages counter
- * @return Counter value
- */
- unsigned int getDuplicateRespCounter(void)
- {
- return duplicate_resp_counter;
- }
-
- /**
- * @brief Increment the duplicate PDelayResp message counter
- * @return True if it equals the threshold, False otherwise
- */
- bool incrementDuplicateRespCounter(void)
- {
- return ++duplicate_resp_counter == DUPLICATE_RESP_THRESH;
- }
-
- /**
- * @brief Maps socket addr to the remote link layer address
- * @param destIdentity [in] PortIdentity remote
- * @param remote [in] remote link layer address
- * @return void
- */
- void mapSocketAddr
- (PortIdentity * destIdentity, LinkLayerAddress * remote);
-
- /**
- * @brief Adds New sock addr map
- * @param destIdentity [in] PortIdentity remote
- * @param remote [in] remote link layer address
- * @return void
- */
- void addSockAddrMap
- (PortIdentity * destIdentity, LinkLayerAddress * remote);
-
- /**
- * @brief Gets link up count
- * @return Link up count
- */
- uint32_t getLinkUpCount() {
- return linkUpCount;
- }
-
- /**
- * @brief Gets link down count
- * @return Link down count
- */
- uint32_t getLinkDownCount() {
- return linkDownCount;
- }
-
- /**
- * @brief Sets the Station State for the Test Status message
- * @param StationState_t [in] The station state
- * @return none
- */
- void setStationState(StationState_t _stationState) {
- stationState = _stationState;
- if (stationState == STATION_STATE_ETHERNET_READY) {
- GPTP_LOG_STATUS("AVnu AP Status : STATION_STATE_ETHERNET_READY");
- }
- else if (stationState == STATION_STATE_AVB_SYNC) {
- GPTP_LOG_STATUS("AVnu AP Status : STATION_STATE_AVB_SYNC");
- }
- else if (stationState == STATION_STATE_AVB_MEDIA_READY) {
- GPTP_LOG_STATUS("AVnu AP Status : STATION_STATE_AVB_MEDIA_READY");
- }
- }
-
- /**
- * @brief Gets the Station State for the Test Status
- * message
- * @return station state
- */
- StationState_t getStationState() {
- return stationState;
- }
-
-
- /**
- * @brief Sets the linkUp status
- * @param bool of the linkUp status
- * @return void
- */
- void setLinkUpState(bool state) {
- linkUp = state;
- }
-
- /**
- * @brief Gets the linkUp status
- * @return bool of the linkUp status
- */
- bool getLinkUpState(void) {
- return linkUp;
- }
-};
-
-#endif/*ETHER_PORT_HPP*/
diff --git a/daemons/gptp/common/ether_tstamper.hpp b/daemons/gptp/common/ether_tstamper.hpp
deleted file mode 100644
index bc590cbc..00000000
--- a/daemons/gptp/common/ether_tstamper.hpp
+++ /dev/null
@@ -1,73 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef ETHER_TSTAMPER_HPP
-#define ETHER_TSTAMPER_HPP
-
-#include <common_tstamper.hpp>
-
-class EtherTimestamper : public CommonTimestamper
-{
-public:
- /**
- * @brief Gets the tx timestamp from hardware
- * @param identity PTP port identity
- * @param PTPMessageId Message ID
- * @param timestamp [out] Timestamp value
- * @param clock_value [out] Clock value
- * @param last Signalizes that it is the last timestamp to get. When TRUE, releases the lock when its done.
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- virtual int HWTimestamper_txtimestamp
- ( PortIdentity * identity, PTPMessageId messageId,
- Timestamp &timestamp, unsigned &clock_value, bool last ) = 0;
-
- /**
- * @brief Get rx timestamp
- * @param identity PTP port identity
- * @param messageId Message ID
- * @param timestamp [out] Timestamp value
- * @param clock_value [out] Clock value
- * @param last Signalizes that it is the last timestamp to get. When TRUE, releases the lock when its done.
- * @return GPTP_EC_SUCCESS if no error, GPTP_EC_FAILURE if error and GPTP_EC_EAGAIN to try again.
- */
- virtual int HWTimestamper_rxtimestamp(PortIdentity * identity,
- PTPMessageId messageId,
- Timestamp & timestamp,
- unsigned &clock_value,
- bool last) = 0;
-
- virtual ~EtherTimestamper() {}
-};
-
-#endif/*ETHER_TSTAMPER_HPP*/
diff --git a/daemons/gptp/common/gptp_cfg.cpp b/daemons/gptp/common/gptp_cfg.cpp
deleted file mode 100644
index 943c639a..00000000
--- a/daemons/gptp/common/gptp_cfg.cpp
+++ /dev/null
@@ -1,335 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2015, Coveloz Consulting Ltda
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Attributions: The inih library portion of the source code is licensed from
-Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
-Complete license and copyright information can be found at
-https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
-*************************************************************************************************************/
-
-/**
- * @file
- * MODULE SUMMARY : Reads the .ini file and parses it into information
- * to be used on daemon_cl
- */
-
-#include <iostream>
-
-/* need Microsoft version for strcasecmp() from GCC strings.h */
-#ifdef _MSC_VER
-#define strcasecmp _stricmp
-#else
-#include <strings.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-
-#include "gptp_cfg.hpp"
-
-uint32_t findSpeedByName( const char *name, const char **end );
-
-GptpIniParser::GptpIniParser(std::string filename)
-{
- _config.systemClockDesc[0] = '\0';
- _error = ini_parse(filename.c_str(), iniCallBack, this);
-}
-
-GptpIniParser::~GptpIniParser()
-{
-}
-
-/****************************************************************************/
-
-int GptpIniParser::parserError(void)
-{
- return _error;
-}
-
-/****************************************************************************/
-
-int GptpIniParser::iniCallBack(void *user, const char *section, const char *name, const char *value)
-{
- GptpIniParser *parser = (GptpIniParser*)user;
- bool valOK = false;
-
- if( parseMatch(section, "ptp") )
- {
- if( parseMatch(name, "priority1") )
- {
- errno = 0;
- char *pEnd;
- unsigned char p1 = (unsigned char) strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.priority1 = p1;
- }
- }
- }
- else if( parseMatch(section, "clock") )
- {
- if( parseMatch(name, "SystemClock") )
- {
- valOK = true;
- strncpy( parser->_config.systemClockDesc, value,
- MAX_CLOCK_DESC_LEN );
- parser->_config.systemClockDesc[MAX_CLOCK_DESC_LEN] = '\0';
- }
- }
- else if( parseMatch(section, "port") )
- {
- if( parseMatch(name, "announceReceiptTimeout") )
- {
- errno = 0;
- char *pEnd;
- unsigned int art = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.announceReceiptTimeout = art;
- }
- }
- else if( parseMatch(name, "syncReceiptTimeout") )
- {
- errno = 0;
- char *pEnd;
- unsigned int srt = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.syncReceiptTimeout = srt;
- }
- }
- else if( parseMatch(name, "neighborPropDelayThresh") )
- {
- errno = 0;
- char *pEnd;
- int64_t nt = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.neighborPropDelayThresh = nt;
- }
- }
- else if( parseMatch(name, "syncReceiptThresh") )
- {
- errno = 0;
- char *pEnd;
- unsigned int st = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.syncReceiptThresh = st;
- }
- }
- else if( parseMatch(name, "seqIdAsCapableThresh") )
- {
- errno = 0;
- char *pEnd;
- unsigned int sidt = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.seqIdAsCapableThresh = sidt;
- }
- }
- else if( parseMatch( name, "lostPdelayRespThresh") )
- {
- errno = 0;
- char *pEnd;
- uint16_t lostpdelayth = (uint16_t) strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0 ) {
- valOK = true;
- parser->_config.lostPdelayRespThresh = lostpdelayth;
- }
- }
- }
- else if( parseMatch(section, "eth") )
- {
- if( parseMatch(name, "phy_delay_gb_tx") )
- {
- errno = 0;
- char *pEnd;
- int phdly = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.phy_delay[LINKSPEED_1G].set_tx_delay( phdly );
- }
- }
-
- else if( parseMatch(name, "phy_delay_gb_rx") )
- {
- errno = 0;
- char *pEnd;
- int phdly = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.phy_delay[LINKSPEED_1G].set_rx_delay( phdly );
- }
- }
-
- else if( parseMatch(name, "phy_delay_mb_tx") )
- {
- errno = 0;
- char *pEnd;
- int phdly = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.phy_delay[LINKSPEED_100MB].
- set_tx_delay( phdly );
- }
- }
-
- else if( parseMatch(name, "phy_delay_mb_rx") )
- {
- errno = 0;
- char *pEnd;
- int phdly = strtoul(value, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.phy_delay[LINKSPEED_100MB].
- set_rx_delay( phdly );
- }
- }
-
- else if( parseMatch(name, "phy_delay") )
- {
- errno = 0;
- char *pEnd;
- const char *c_pEnd;
- uint32_t speed = findSpeedByName( value, &c_pEnd );
- if( speed == INVALID_LINKSPEED )
- {
- speed = strtoul( value, &pEnd, 10 );
- c_pEnd = pEnd;
- }
- int ph_tx_dly = strtoul(c_pEnd, &pEnd, 10);
- int ph_rx_dly = strtoul(pEnd, &pEnd, 10);
- if( *pEnd == '\0' && errno == 0) {
- valOK = true;
- parser->_config.phy_delay[speed].
- set_delay( ph_tx_dly, ph_rx_dly );
- }
- }
- }
-
- if(!valOK)
- {
- std::cerr << "Unrecognized configuration item: section=" << section << ", name=" << name << std::endl;
- return 0;
- }
-
- return 1;
-}
-
-
-/****************************************************************************/
-
-bool GptpIniParser::parseMatch(const char *s1, const char *s2)
-{
- return strcasecmp(s1, s2) == 0;
-}
-
-#define PHY_DELAY_DESC_LEN 21
-
-void GptpIniParser::print_phy_delay( void )
-{
-
- phy_delay_map_t map = this->getPhyDelay();
- for( phy_delay_map_t::const_iterator i = map.cbegin();
- i != map.cend(); ++i )
- {
- uint32_t speed;
- uint16_t tx, rx;
- const char *speed_name;
- char phy_delay_desc[PHY_DELAY_DESC_LEN+1];
-
- speed = (*i).first;
- tx = i->second.get_tx_delay();
- rx = i->second.get_rx_delay();
-
- PLAT_snprintf( phy_delay_desc, PHY_DELAY_DESC_LEN+1,
- "TX: %hu | RX: %hu", tx, rx );
-
- speed_name = findNameBySpeed( speed );
- if( speed_name != NULL )
- GPTP_LOG_INFO( "%s - PHY delay\n\t\t\t%s",
- speed_name, phy_delay_desc );
- else
- GPTP_LOG_INFO( "link speed %u - PHY delay\n\t\t\t%s",
- speed, phy_delay_desc );
- }
-}
-
-
-#define DECLARE_SPEED_NAME_MAP( name ) \
- { name, #name }
-
-typedef struct
-{
- const uint32_t speed;
- const char *name;
-} speed_name_map_t;
-
-speed_name_map_t speed_name_map[] =
-{
- DECLARE_SPEED_NAME_MAP( LINKSPEED_10G ),
- DECLARE_SPEED_NAME_MAP( LINKSPEED_2_5G ),
- DECLARE_SPEED_NAME_MAP( LINKSPEED_1G ),
- DECLARE_SPEED_NAME_MAP( LINKSPEED_100MB ),
- DECLARE_SPEED_NAME_MAP( INVALID_LINKSPEED )
-};
-
-const char *findNameBySpeed( uint32_t speed )
-{
- speed_name_map_t *iter = speed_name_map;
-
- while( iter->speed != INVALID_LINKSPEED )
- {
- if( iter->speed == speed )
- {
- break;
- }
- ++iter;
- }
-
- if( iter->speed != INVALID_LINKSPEED )
- return iter->name;
-
- return NULL;
-}
-
-uint32_t findSpeedByName( const char *name, const char **end )
-{
- speed_name_map_t *iter = speed_name_map;
- *end = name;
-
- while( iter->speed != INVALID_LINKSPEED )
- {
- if( strncmp( name, iter->name, strlen( iter->name )) == 0 )
- {
- *end = name + strlen( iter->name );
- break;
- }
- ++iter;
- }
-
- return iter->speed;
-}
-
diff --git a/daemons/gptp/common/gptp_cfg.hpp b/daemons/gptp/common/gptp_cfg.hpp
deleted file mode 100644
index 4b172b4c..00000000
--- a/daemons/gptp/common/gptp_cfg.hpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2015, Coveloz Consulting Ltda
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-Attributions: The inih library portion of the source code is licensed from
-Brush Technology and Ben Hoyt - Copyright (c) 2009, Brush Technology and Copyright (c) 2009, Ben Hoyt.
-Complete license and copyright information can be found at
-https://github.com/benhoyt/inih/commit/74d2ca064fb293bc60a77b0bd068075b293cf175.
-*************************************************************************************************************/
-
-/**
- * @file
- * MODULE SUMMARY : Reads the .ini file and parses it into information
- * to be used on daemon_cl
- */
-
-#include <string>
-
-#include "ini.h"
-#include <limits.h>
-#include <common_port.hpp>
-
-const uint32_t LINKSPEED_10G = 10000000;
-const uint32_t LINKSPEED_2_5G = 2500000;
-const uint32_t LINKSPEED_1G = 1000000;
-const uint32_t LINKSPEED_100MB = 100000;
-const uint32_t INVALID_LINKSPEED = UINT_MAX;
-const uint8_t MAX_CLOCK_DESC_LEN = 64;
-
-/**
- * @brief Returns name given numeric link speed
- * @return NULL if speed/name isn't found
- */
-const char *findNameBySpeed( uint32_t speed );
-
-/**
- * @brief Provides the gptp interface for
- * the iniParser external module
- */
-class GptpIniParser
-{
- public:
-
- /**
- * @brief Container with the information to get from the .ini file
- */
- typedef struct
- {
- /*ptp data set*/
- unsigned char priority1;
-
- /* Clock data set */
- char systemClockDesc[MAX_CLOCK_DESC_LEN+1];
-
- /*port data set*/
- unsigned int announceReceiptTimeout;
- unsigned int syncReceiptTimeout;
- unsigned int syncReceiptThresh; //!< Number of wrong sync messages that will trigger a switch to master
- int64_t neighborPropDelayThresh;
- unsigned int seqIdAsCapableThresh;
- uint16_t lostPdelayRespThresh;
- PortState port_state;
-
- /*ethernet adapter data set*/
- std::string ifname;
- phy_delay_map_t phy_delay;
- } gptp_cfg_t;
-
- /*public methods*/
- GptpIniParser(std::string ini_path);
- ~GptpIniParser();
-
- /**
- * @brief Reads the parser Error value
- * @param void
- * @return Parser Error
- */
- int parserError(void);
-
- /**
- * @brief Read SystemClock description
- * @return pointer to c-string representing system clock
- */
- const char *getSystemClockDesc(void)
- {
- return _config.systemClockDesc;
- }
-
- /**
- * @brief Reads priority1 config value
- * @param void
- * @return priority1
- */
- unsigned char getPriority1(void)
- {
- return _config.priority1;
- }
-
- /**
- * @brief Reads the announceReceiptTimeout configuration value
- * @param void
- * @return announceRecepitTimeout value from .ini file
- */
- unsigned int getAnnounceReceiptTimeout(void)
- {
- return _config.announceReceiptTimeout;
- }
-
- /**
- * @brief Reads the syncRecepitTimeout configuration value
- * @param void
- * @return syncRecepitTimeout value from the .ini file
- */
- unsigned int getSyncReceiptTimeout(void)
- {
- return _config.syncReceiptTimeout;
- }
-
- /**
- * @brief Reads the PHY DELAY values from the configuration file
- * @param void
- * @return PHY delay map structure
- */
- const phy_delay_map_t getPhyDelay(void)
- {
- return _config.phy_delay;
- }
-
- /**
- * @brief Reads the neighbohr propagation delay threshold from the configuration file
- * @param void
- * @return neighborPropDelayThresh value from the .ini file
- */
- int64_t getNeighborPropDelayThresh(void)
- {
- return _config.neighborPropDelayThresh;
- }
-
- /**
- * @brief Reads the sync receipt threshold from the configuration file
- * @return syncRecepitThresh value from the .ini file
- */
- unsigned int getSyncReceiptThresh(void)
- {
- return _config.syncReceiptThresh;
- }
-
- /**
- * @brief Dump PHY delays to screen
- */
- void print_phy_delay( void );
-
- private:
- int _error;
- gptp_cfg_t _config;
-
- static int iniCallBack(void *user, const char *section, const char *name, const char *value);
- static bool parseMatch(const char *s1, const char *s2);
-};
-
diff --git a/daemons/gptp/common/gptp_log.cpp b/daemons/gptp/common/gptp_log.cpp
deleted file mode 100644
index a1a5809f..00000000
--- a/daemons/gptp/common/gptp_log.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2012-2016, Harman International Industries, Incorporated
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*************************************************************************************************************/
-
-#include <gptp_log.hpp>
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <platform.hpp>
-
-// MS VC++ 2013 has C++11 but not C11 support, use this to get millisecond resolution
-#include <chrono>
-
-#ifdef GENIVI_DLT
-DLT_DECLARE_CONTEXT(dlt_con_gptp);
-#endif
-
-void gptplogRegister(void)
-{
-#ifdef GENIVI_DLT
- DLT_REGISTER_APP("GPTP","OpenAVB gPTP");
- DLT_REGISTER_CONTEXT(dlt_con_gptp, "GNRL", "General Context");
-#endif
-}
-
-void gptplogUnregister(void)
-{
-#ifdef GENIVI_DLT
- DLT_UNREGISTER_CONTEXT(dlt_con_gptp);
- DLT_UNREGISTER_APP();
-#endif
-}
-
-void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...)
-{
- char msg[1024];
-
- va_list args;
- va_start(args, fmt);
- vsprintf(msg, fmt, args);
-
-#ifndef GENIVI_DLT
- std::chrono::system_clock::time_point cNow = std::chrono::system_clock::now();
- time_t tNow = std::chrono::system_clock::to_time_t(cNow);
- struct tm tmNow;
- PLAT_localtime(&tNow, &tmNow);
- std::chrono::system_clock::duration roundNow = cNow - std::chrono::system_clock::from_time_t(tNow);
- long int millis = (long int) std::chrono::duration_cast<std::chrono::milliseconds>(roundNow).count();
-
- if (path) {
- fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] [%s:%u] %s\n",
- tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, path, line, msg);
- }
- else {
- fprintf(stderr, "%s: GPTP [%2.2d:%2.2d:%2.2d:%3.3ld] %s\n",
- tag, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec, millis, msg);
- }
-#else
- DltLogLevelType dlt_level;
-
- switch (level) {
- case GPTP_LOG_LVL_CRITICAL:
- dlt_level = DLT_LOG_FATAL;
- break;
- case GPTP_LOG_LVL_ERROR:
- dlt_level = DLT_LOG_ERROR;
- break;
- case GPTP_LOG_LVL_EXCEPTION:
- case GPTP_LOG_LVL_WARNING:
- dlt_level = DLT_LOG_WARN;
- break;
- case GPTP_LOG_LVL_INFO:
- case GPTP_LOG_LVL_STATUS:
- dlt_level = DLT_LOG_INFO;
- break;
- case GPTP_LOG_LVL_DEBUG:
- dlt_level = DLT_LOG_DEBUG;
- break;
- case GPTP_LOG_LVL_VERBOSE:
- dlt_level = DLT_LOG_VERBOSE;
- break;
- default:
- dlt_level = DLT_LOG_INFO;
- break;
- }
-
- DLT_LOG(dlt_con_gptp, dlt_level, DLT_STRING(msg));
-#endif
-
-}
-
diff --git a/daemons/gptp/common/gptp_log.hpp b/daemons/gptp/common/gptp_log.hpp
deleted file mode 100644
index 272d8cd8..00000000
--- a/daemons/gptp/common/gptp_log.hpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*************************************************************************************************************
-Copyright (c) 2012-2016, Harman International Industries, Incorporated
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS LISTED "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS LISTED BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*************************************************************************************************************/
-
-#ifndef GPTP_LOG_HPP
-#define GPTP_LOG_HPP
-
-/**@file*/
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <time.h>
-
-#ifdef GENIVI_DLT
-#include "dlt.h"
-#endif
-
-#define GPTP_LOG_CRITICAL_ON 1
-#define GPTP_LOG_ERROR_ON 1
-#define GPTP_LOG_EXCEPTION_ON 1
-#define GPTP_LOG_WARNING_ON 1
-#define GPTP_LOG_INFO_ON 1
-#define GPTP_LOG_STATUS_ON 1
-//#define GPTP_LOG_DEBUG_ON 1
-//#define GPTP_LOG_VERBOSE_ON 1
-
-typedef enum {
- GPTP_LOG_LVL_CRITICAL,
- GPTP_LOG_LVL_ERROR,
- GPTP_LOG_LVL_EXCEPTION,
- GPTP_LOG_LVL_WARNING,
- GPTP_LOG_LVL_INFO,
- GPTP_LOG_LVL_STATUS,
- GPTP_LOG_LVL_DEBUG,
- GPTP_LOG_LVL_VERBOSE,
-} GPTP_LOG_LEVEL;
-
-
-void gptplogRegister(void);
-void gptplogUnregister(void);
-void gptpLog(GPTP_LOG_LEVEL level, const char *tag, const char *path, int line, const char *fmt, ...);
-
-
-#define GPTP_LOG_REGISTER() gptplogRegister()
-
-#define GPTP_LOG_UNREGISTER() gptplogUnregister()
-
-#ifdef GPTP_LOG_CRITICAL_ON
-#define GPTP_LOG_CRITICAL(fmt,...) gptpLog(GPTP_LOG_LVL_CRITICAL, "CRITICAL ", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_CRITICAL(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_ERROR_ON
-#define GPTP_LOG_ERROR(fmt,...) gptpLog(GPTP_LOG_LVL_ERROR, "ERROR ", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_ERROR(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_EXCEPTION_ON
-#define GPTP_LOG_EXCEPTION(fmt,...) gptpLog(GPTP_LOG_LVL_EXCEPTION, "EXCEPTION", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_EXCEPTION(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_WARNING_ON
-#define GPTP_LOG_WARNING(fmt,...) gptpLog(GPTP_LOG_LVL_WARNING, "WARNING ", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_WARNING(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_INFO_ON
-#define GPTP_LOG_INFO(fmt,...) gptpLog(GPTP_LOG_LVL_INFO, "INFO ", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_INFO(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_STATUS_ON
-#define GPTP_LOG_STATUS(fmt,...) gptpLog(GPTP_LOG_LVL_STATUS, "STATUS ", NULL, 0, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_STATUS(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_DEBUG_ON
-#define GPTP_LOG_DEBUG(fmt,...) gptpLog(GPTP_LOG_LVL_DEBUG, "DEBUG ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_DEBUG(fmt,...)
-#endif
-
-#ifdef GPTP_LOG_VERBOSE_ON
-#define GPTP_LOG_VERBOSE(fmt,...) gptpLog(GPTP_LOG_LVL_VERBOSE, "VERBOSE ", __FILE__, __LINE__, fmt, ## __VA_ARGS__)
-#else
-#define GPTP_LOG_VERBOSE(fmt,...)
-#endif
-
-#endif
diff --git a/daemons/gptp/common/ieee1588.hpp b/daemons/gptp/common/ieee1588.hpp
deleted file mode 100644
index cf3d59e4..00000000
--- a/daemons/gptp/common/ieee1588.hpp
+++ /dev/null
@@ -1,455 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef IEEE1588_HPP
-#define IEEE1588_HPP
-
-/** @file */
-
-#include <string>
-
-#include <stdint.h>
-
-#include <string.h>
-
-#include <stdio.h>
-
-#include <platform.hpp>
-#include <ptptypes.hpp>
-
-#include <gptp_log.hpp>
-#include <limits.h>
-
-#define MAX_PORTS 32 /*!< Maximum number of EtherPort instances */
-
-
-/**
- * @brief Return codes for gPTP
-*/
-#define GPTP_EC_SUCCESS 0 /*!< No errors.*/
-#define GPTP_EC_FAILURE -1 /*!< Generic error */
-#define GPTP_EC_EAGAIN -72 /*!< Error: Try again */
-
-
-class LinkLayerAddress;
-struct ClockQuality;
-class PortIdentity;
-class PTPMessageId;
-class PTPMessageCommon;
-class PTPMessageSync;
-class PTPMessageAnnounce;
-class PTPMessagePathDelayReq;
-class PTPMessagePathDelayResp;
-class PTPMessagePathDelayRespFollowUp;
-class EtherPort;
-class CommonPort;
-class IEEE1588Clock;
-class OSNetworkInterface;
-
-/**
- * @enum Event
- * IEEE 1588 event enumeration type
- * Defined at: IEEE 1588-2008 Clause 9.2.6
- */
-typedef enum {
- NULL_EVENT = 0, //!< Null Event. Used to initialize events.
- POWERUP = 5, //!< Power Up. Initialize state machines.
- INITIALIZE, //!< Same as POWERUP.
- LINKUP, //!< Triggered when link comes up.
- LINKDOWN, //!< Triggered when link goes down.
- STATE_CHANGE_EVENT, //!< Signalizes that something has changed. Recalculates best master.
- SYNC_INTERVAL_TIMEOUT_EXPIRES, //!< Sync interval expired. Its time to send a sync message.
- PDELAY_INTERVAL_TIMEOUT_EXPIRES, //!< PDELAY interval expired. Its time to send pdelay_req message
- SYNC_RECEIPT_TIMEOUT_EXPIRES, //!< Sync receipt timeout. Restart timers and take actions based on port's state.
- QUALIFICATION_TIMEOUT_EXPIRES, //!< Qualification timeout. Event not currently used
- ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES, //!< Announce receipt timeout. Same as SYNC_RECEIPT_TIMEOUT_EXPIRES
- ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES, //!< Announce interval timout. Its time to send an announce message if asCapable is true
- FAULT_DETECTED, //!< A fault was detected.
- PDELAY_DEFERRED_PROCESSING, //!< Defers pdelay processing
- PDELAY_RESP_RECEIPT_TIMEOUT_EXPIRES, //!< Pdelay response message timeout
- PDELAY_RESP_PEER_MISBEHAVING_TIMEOUT_EXPIRES, //!< Timeout for peer misbehaving. This even will re-enable the PDelay Requests
- SYNC_RATE_INTERVAL_TIMEOUT_EXPIRED, //!< Sync rate signal timeout for the Automotive Profile
-} Event;
-
-/**
- * @brief Defines an event descriptor type
- */
-typedef struct {
- CommonPort *port; //!< Media Dependent Ether Port
- Event event; //!< Event enumeration
-} event_descriptor_t;
-
-/**
- * @brief Provides a generic InterfaceLabel class
- */
-class InterfaceLabel {
- public:
- virtual ~ InterfaceLabel() {
- };
-};
-
-/**
- * @brief Provides a ClockIdentity abstraction
- * See IEEE 802.1AS-2011 Clause 8.5.2.2
- */
-class ClockIdentity {
- private:
- uint8_t id[PTP_CLOCK_IDENTITY_LENGTH];
- public:
- /**
- * @brief Default constructor. Sets ID to zero
- */
- ClockIdentity() {
- memset( id, 0, PTP_CLOCK_IDENTITY_LENGTH );
- }
-
- /**
- * @brief Constructs the object and sets its ID
- * @param id [in] clock id as an octet array
- */
- ClockIdentity( uint8_t *id ) {
- set(id);
- }
-
- /**
- * @brief Implements the operator '==' overloading method.
- * @param cmp Reference to the ClockIdentity comparing value
- * @return TRUE if cmp equals to the object's clock identity. FALSE otherwise
- */
- bool operator==(const ClockIdentity & cmp) const {
- return memcmp(this->id, cmp.id,
- PTP_CLOCK_IDENTITY_LENGTH) == 0 ? true : false;
- }
-
- /**
- * @brief Implements the operator '!=' overloading method.
- * @param cmp Reference to the ClockIdentity comparing value
- * @return TRUE if cmp differs from the object's clock identity. FALSE otherwise.
- */
- bool operator!=( const ClockIdentity &cmp ) const {
- return memcmp( this->id, cmp.id, PTP_CLOCK_IDENTITY_LENGTH ) != 0 ? true : false;
- }
-
- /**
- * @brief Implements the operator '<' overloading method.
- * @param cmp Reference to the ClockIdentity comparing value
- * @return TRUE if cmp value is lower than the object's clock identity value. FALSE otherwise.
- */
- bool operator<(const ClockIdentity & cmp)const {
- return memcmp(this->id, cmp.id,
- PTP_CLOCK_IDENTITY_LENGTH) < 0 ? true : false;
- }
-
- /**
- * @brief Implements the operator '>' overloading method.
- * @param cmp Reference to the ClockIdentity comparing value
- * @return TRUE if cmp value is greater than the object's clock identity value. FALSE otherwise
- */
- bool operator>(const ClockIdentity & cmp)const {
- return memcmp(this->id, cmp.id,
- PTP_CLOCK_IDENTITY_LENGTH) > 0 ? true : false;
- }
-
- /**
- * @brief Gets the identity string from the ClockIdentity object
- * @return String containing the clock identity
- */
- std::string getIdentityString();
-
- /**
- * @brief Gets the identity string from the ClockIdentity object
- * @param id [out] Value copied from the object ClockIdentity. Needs to be at least ::PTP_CLOCK_IDENTITY_LENGTH long.
- * @return void
- */
- void getIdentityString(uint8_t *id) {
- memcpy(id, this->id, PTP_CLOCK_IDENTITY_LENGTH);
- }
-
- /**
- * @brief Set the clock id to the object
- * @param id [in] Value to be set
- * @return void
- */
- void set(uint8_t * id) {
- memcpy(this->id, id, PTP_CLOCK_IDENTITY_LENGTH);
- }
-
- /**
- * @brief Set clock id based on the link layer address. Clock id is 8 octets
- * long whereas link layer address is 6 octets long and it is turned into a
- * clock identity as per the 802.1AS standard described in clause 8.5.2.2
- * @param address Link layer address
- * @return void
- */
- void set(LinkLayerAddress * address);
-
- /**
- * @brief This method is only enabled at compiling time. When enabled, it prints on the
- * stderr output the clock identity information
- * @param str [in] String to be print out before the clock identity value
- * @return void
- */
- void print(const char *str) {
- GPTP_LOG_VERBOSE
- ( "Clock Identity(%s): %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx",
- str, id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
- }
-};
-
-#define INVALID_TIMESTAMP_VERSION 0xFF /*!< Value defining invalid timestamp version*/
-#define MAX_NANOSECONDS 1000000000 /*!< Maximum value of nanoseconds (1 second)*/
-#define MAX_TSTAMP_STRLEN 25 /*!< Maximum size of timestamp strlen*/
-
-/**
- * @brief Provides a Timestamp interface
- */
-class Timestamp {
-public:
- /**
- * @brief Creates a Timestamp instance
- * @param ns 32 bit nano-seconds value
- * @param s_l 32 bit seconds field LSB
- * @param s_m 32 bit seconds field MSB
- * @param ver 8 bit version field
- */
- Timestamp
- (uint32_t ns, uint32_t s_l, uint16_t s_m,
- uint8_t ver = INVALID_TIMESTAMP_VERSION) {
- nanoseconds = ns;
- seconds_ls = s_l;
- seconds_ms = s_m;
- _version = ver;
- }
- /*
- * Default constructor. Initializes
- * the private parameters
- */
- Timestamp() {
- Timestamp( 0, 0, 0 );
- }
- uint32_t nanoseconds; //!< 32 bit nanoseconds value
- uint32_t seconds_ls; //!< 32 bit seconds LSB value
- uint16_t seconds_ms; //!< 32 bit seconds MSB value
- uint8_t _version; //!< 8 bit version value
-
- /**
- * @brief Copies the timestamp to the internal string in the following format:
- * seconds_ms seconds_ls nanoseconds
- * @return STL string containing timestamp
- */
- std::string toString() const
- {
- char output_string[MAX_TSTAMP_STRLEN+1];
-
- PLAT_snprintf
- ( output_string, MAX_TSTAMP_STRLEN+1, "%hu %u.%09u",
- seconds_ms, seconds_ls, nanoseconds );
-
- return std::string( output_string );
- }
-
- /**
- * @brief Implements the operator '+' overloading method.
- * @param o Constant reference to the timestamp to be added
- * @return Object's timestamp + o.
- */
- Timestamp operator+( const Timestamp& o ) {
- uint32_t nanoseconds;
- uint32_t seconds_ls;
- uint16_t seconds_ms;
- uint8_t version;
- bool carry;
-
- nanoseconds = this->nanoseconds;
- nanoseconds += o.nanoseconds;
- carry =
- nanoseconds < this->nanoseconds ||
- nanoseconds >= MAX_NANOSECONDS ? true : false;
- nanoseconds -= carry ? MAX_NANOSECONDS : 0;
-
- seconds_ls = this->seconds_ls;
- seconds_ls += o.seconds_ls;
- seconds_ls += carry ? 1 : 0;
- carry = seconds_ls < this->seconds_ls ? true : false;
-
- seconds_ms = this->seconds_ms;
- seconds_ms += o.seconds_ms;
- seconds_ms += carry ? 1 : 0;
- carry = seconds_ms < this->seconds_ms ? true : false;
-
- version = this->_version == o._version ? this->_version :
- INVALID_TIMESTAMP_VERSION;
- return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
- }
-
- /**
- * @brief Implements the operator '-' overloading method.
- * @param o Constant reference to the timestamp to be subtracted
- * @return Object's timestamp - o.
- */
- Timestamp operator-( const Timestamp& o ) {
- uint32_t nanoseconds;
- uint32_t seconds_ls;
- uint16_t seconds_ms;
- uint8_t version;
- bool carry, borrow_this;
- unsigned borrow_total = 0;
-
- borrow_this = this->nanoseconds < o.nanoseconds;
- nanoseconds =
- ((borrow_this ? MAX_NANOSECONDS : 0) + this->nanoseconds) -
- o.nanoseconds;
- carry = nanoseconds > MAX_NANOSECONDS;
- nanoseconds -= carry ? MAX_NANOSECONDS : 0;
- borrow_total += borrow_this ? 1 : 0;
-
- seconds_ls = carry ? 1 : 0;
- seconds_ls += this->seconds_ls;
- borrow_this =
- borrow_total > seconds_ls ||
- seconds_ls - borrow_total < o.seconds_ls;
- seconds_ls =
- borrow_this ? seconds_ls - o.seconds_ls + (uint32_t)-1 :
- (seconds_ls - borrow_total) - o.seconds_ls;
- borrow_total = borrow_this ? borrow_total + 1 : 0;
-
- seconds_ms = carry ? 1 : 0;
- seconds_ms += this->seconds_ms;
- borrow_this =
- borrow_total > seconds_ms ||
- seconds_ms - borrow_total < o.seconds_ms;
- seconds_ms =
- borrow_this ? seconds_ms - o.seconds_ms + (uint32_t)-1 :
- (seconds_ms - borrow_total) - o.seconds_ms;
- borrow_total = borrow_this ? borrow_total + 1 : 0;
-
- version = this->_version == o._version ? this->_version :
- INVALID_TIMESTAMP_VERSION;
- return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
- }
-
- /**
- * @brief Sets a 64bit value to the object's timestamp
- * @param value Value to be set
- * @return void
- */
- void set64( uint64_t value ) {
- nanoseconds = value % 1000000000;
- seconds_ls = (uint32_t) (value / 1000000000);
- seconds_ms = (uint16_t)((value / 1000000000) >> 32);
- }
-};
-
-#define INVALID_TIMESTAMP (Timestamp( 0xC0000000, 0, 0 )) /*!< Defines an invalid timestamp using a Timestamp instance and a fixed value*/
-#define PDELAY_PENDING_TIMESTAMP (Timestamp( 0xC0000001, 0, 0 )) /*!< PDelay is pending timestamp */
-
-static inline uint64_t TIMESTAMP_TO_NS(Timestamp &ts)
-{
- return (((static_cast<long long int>(ts.seconds_ms) << sizeof(ts.seconds_ls)*8) +
- ts.seconds_ls)*1000000000LL + ts.nanoseconds) ; /*!< Converts timestamp value into nanoseconds value*/
-}
-
-/**
- * @brief Swaps out byte-a-byte a 64 bit value
- * @param in Value to be swapped
- * @return Swapped value
- */
-static inline uint64_t byte_swap64(uint64_t in)
-{
- uint8_t *s = (uint8_t *) & in;
- uint8_t *e = s + 7;
- while (e > s) {
- uint8_t t;
- t = *s;
- *s = *e;
- *e = t;
- ++s;
- --e;
- }
- return in;
-}
-
-#define NS_PER_SECOND 1000000000 /*!< Amount of nanoseconds in a second*/
-#define LS_SEC_MAX 0xFFFFFFFFull /*!< Maximum value of seconds LSB field */
-
-/**
- * @brief Subtracts a nanosecond value from the timestamp
- * @param ts [inout] Timestamp value
- * @param ns Nanoseconds value to subtract from ts
- * @return void
- */
-static inline void TIMESTAMP_SUB_NS( Timestamp &ts, uint64_t ns ) {
- uint64_t secs = (uint64_t)ts.seconds_ls | ((uint64_t)ts.seconds_ms) << 32;
- uint64_t nanos = (uint64_t)ts.nanoseconds;
-
- secs -= ns / NS_PER_SECOND;
- ns = ns % NS_PER_SECOND;
-
- if(ns > nanos)
- { //borrow
- nanos += NS_PER_SECOND;
- --secs;
- }
-
- nanos -= ns;
-
- ts.seconds_ms = (uint16_t)(secs >> 32);
- ts.seconds_ls = (uint32_t)(secs & LS_SEC_MAX);
- ts.nanoseconds = (uint32_t)nanos;
-}
-
-/**
- * @brief Adds a nanosecond value to the timestamp
- * @param ts [inout] Timestamp value
- * @param ns Nanoseconds value to add to ts
- * @return void
- */
-static inline void TIMESTAMP_ADD_NS( Timestamp &ts, uint64_t ns ) {
- uint64_t secs = (uint64_t)ts.seconds_ls | ((uint64_t)ts.seconds_ms) << 32;
- uint64_t nanos = (uint64_t)ts.nanoseconds;
-
- secs += ns / NS_PER_SECOND;
- nanos += ns % NS_PER_SECOND;
-
- if(nanos > NS_PER_SECOND)
- { //carry
- nanos -= NS_PER_SECOND;
- ++secs;
- }
-
- ts.seconds_ms = (uint16_t)(secs >> 32);
- ts.seconds_ls = (uint32_t)(secs & LS_SEC_MAX);
- ts.nanoseconds = (uint32_t)nanos;
-}
-
-#endif
diff --git a/daemons/gptp/common/ieee1588clock.cpp b/daemons/gptp/common/ieee1588clock.cpp
deleted file mode 100644
index 3cb7ad8e..00000000
--- a/daemons/gptp/common/ieee1588clock.cpp
+++ /dev/null
@@ -1,500 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <ieee1588.hpp>
-
-#include <avbts_clock.hpp>
-#include <avbts_oslock.hpp>
-#include <avbts_ostimerq.hpp>
-
-#include <stdio.h>
-
-#include <string.h>
-
-#include <stdlib.h>
-
-#include <string.h>
-
-#include <math.h>
-
-std::string ClockIdentity::getIdentityString()
-{
- uint8_t cid[PTP_CLOCK_IDENTITY_LENGTH];
- getIdentityString(cid);
- char scid[PTP_CLOCK_IDENTITY_LENGTH * 3 + 1];
- char* pscid = scid;
- for (unsigned i = 0; i < PTP_CLOCK_IDENTITY_LENGTH; ++i) {
- unsigned byte = cid[i];
- PLAT_snprintf(pscid, 4, "%2.2X:", byte);
- pscid += 3;
- }
- scid[PTP_CLOCK_IDENTITY_LENGTH * 3 - 1] = '\0';
-
- return std::string(scid);
-}
-
-void ClockIdentity::set(LinkLayerAddress * addr)
-{
- uint64_t tmp1 = 0;
- uint32_t tmp2;
- addr->toOctetArray((uint8_t *) & tmp1);
- tmp2 = tmp1 & 0xFFFFFF;
- tmp1 >>= 24;
- tmp1 <<= 16;
- tmp1 |= 0xFEFF;
- tmp1 <<= 24;
- tmp1 |= tmp2;
- memcpy(id, &tmp1, PTP_CLOCK_IDENTITY_LENGTH);
-}
-
-IEEE1588Clock::IEEE1588Clock
-( bool forceOrdinarySlave, bool syntonize, uint8_t priority1,
- OSTimerQueueFactory *timerq_factory, OS_IPC *ipc,
- OSLockFactory *lock_factory )
-{
- this->priority1 = priority1;
- priority2 = 248;
-
- number_ports = 0;
-
- this->forceOrdinarySlave = forceOrdinarySlave;
-
- /*TODO: Make the values below configurable*/
- clock_quality.clockAccuracy = 0x22;
- clock_quality.cq_class = 248;
- clock_quality.offsetScaledLogVariance = 0x436A;
-
- time_source = 160;
-
- domain_number = 0;
-
- _syntonize = syntonize;
- _new_syntonization_set_point = false;
- _ppm = 0;
-
- _phase_error_violation = 0;
-
- _master_local_freq_offset_init = false;
- _local_system_freq_offset_init = false;
-
- this->ipc = ipc;
-
- memset( &LastEBestIdentity, 0xFF, sizeof( LastEBestIdentity ));
-
- timerq_lock = lock_factory->createLock( oslock_recursive );
-
- // This should be done LAST!! to pass fully initialized clock object
- timerq = timerq_factory->createOSTimerQueue( this );
-
- fup_info = new FollowUpTLV();
- fup_status = new FollowUpTLV();
-
- return;
-}
-
-bool IEEE1588Clock::serializeState( void *buf, off_t *count ) {
- bool ret = true;
-
- if( buf == NULL ) {
- *count = sizeof( _master_local_freq_offset ) + sizeof( _local_system_freq_offset ) + sizeof( LastEBestIdentity );
- return true;
- }
-
- // Master-Local Frequency Offset
- if( ret && *count >= (off_t) sizeof( _master_local_freq_offset )) {
- memcpy
- ( buf, &_master_local_freq_offset,
- sizeof( _master_local_freq_offset ));
- *count -= sizeof( _master_local_freq_offset );
- buf = ((char *)buf) + sizeof( _master_local_freq_offset );
- } else if( ret == false ) {
- *count += sizeof( _master_local_freq_offset );
- } else {
- *count = sizeof( _master_local_freq_offset )-*count;
- ret = false;
- }
-
- // Local-System Frequency Offset
- if( ret && *count >= (off_t) sizeof( _local_system_freq_offset )) {
- memcpy
- ( buf, &_local_system_freq_offset,(off_t)
- sizeof( _local_system_freq_offset ));
- *count -= sizeof( _local_system_freq_offset );
- buf = ((char *)buf) + sizeof( _local_system_freq_offset );
- } else if( ret == false ) {
- *count += sizeof( _local_system_freq_offset );
- } else {
- *count = sizeof( _local_system_freq_offset )-*count;
- ret = false;
- }
-
- // LastEBestIdentity
- if( ret && *count >= (off_t) sizeof( LastEBestIdentity )) {
- memcpy( buf, &LastEBestIdentity, (off_t) sizeof( LastEBestIdentity ));
- *count -= sizeof( LastEBestIdentity );
- buf = ((char *)buf) + sizeof( LastEBestIdentity );
- } else if( ret == false ) {
- *count += sizeof( LastEBestIdentity );
- } else {
- *count = sizeof( LastEBestIdentity )-*count;
- ret = false;
- }
-
- return ret;
-}
-
-bool IEEE1588Clock::restoreSerializedState( void *buf, off_t *count ) {
- bool ret = true;
-
- /* Master-Local Frequency Offset */
- if( ret && *count >= (off_t) sizeof( _master_local_freq_offset )) {
- memcpy
- ( &_master_local_freq_offset, buf,
- sizeof( _master_local_freq_offset ));
- *count -= sizeof( _master_local_freq_offset );
- buf = ((char *)buf) + sizeof( _master_local_freq_offset );
- } else if( ret == false ) {
- *count += sizeof( _master_local_freq_offset );
- } else {
- *count = sizeof( _master_local_freq_offset )-*count;
- ret = false;
- }
-
- /* Local-System Frequency Offset */
- if( ret && *count >= (off_t) sizeof( _local_system_freq_offset )) {
- memcpy
- ( &_local_system_freq_offset, buf,
- sizeof( _local_system_freq_offset ));
- *count -= sizeof( _local_system_freq_offset );
- buf = ((char *)buf) + sizeof( _local_system_freq_offset );
- } else if( ret == false ) {
- *count += sizeof( _local_system_freq_offset );
- } else {
- *count = sizeof( _local_system_freq_offset )-*count;
- ret = false;
- }
-
- /* LastEBestIdentity */
- if( ret && *count >= (off_t) sizeof( LastEBestIdentity )) {
- memcpy( &LastEBestIdentity, buf, sizeof( LastEBestIdentity ));
- *count -= sizeof( LastEBestIdentity );
- buf = ((char *)buf) + sizeof( LastEBestIdentity );
- } else if( ret == false ) {
- *count += sizeof( LastEBestIdentity );
- } else {
- *count = sizeof( LastEBestIdentity )-*count;
- ret = false;
- }
-
- return ret;
-}
-
-Timestamp IEEE1588Clock::getSystemTime(void)
-{
- return (Timestamp(0, 0, 0));
-}
-
-void timerq_handler(void *arg)
-{
-
- event_descriptor_t *event_descriptor = (event_descriptor_t *) arg;
- event_descriptor->port->processEvent(event_descriptor->event);
-}
-
-void IEEE1588Clock::addEventTimer
-( CommonPort *target, Event e, unsigned long long time_ns )
-{
- event_descriptor_t *event_descriptor = new event_descriptor_t();
- event_descriptor->event = e;
- event_descriptor->port = target;
- timerq->addEvent
- ((unsigned)(time_ns / 1000), (int)e, timerq_handler, event_descriptor,
- true, NULL);
-}
-
-void IEEE1588Clock::addEventTimerLocked
-( CommonPort *target, Event e, unsigned long long time_ns )
-{
- if( getTimerQLock() == oslock_fail ) return;
- addEventTimer( target, e, time_ns );
- if( putTimerQLock() == oslock_fail ) return;
-}
-
-
-
-void IEEE1588Clock::deleteEventTimer
-( CommonPort *target, Event event )
-{
- timerq->cancelEvent((int)event, NULL);
-}
-
-void IEEE1588Clock::deleteEventTimerLocked
-( CommonPort *target, Event event )
-{
- if( getTimerQLock() == oslock_fail ) return;
-
- timerq->cancelEvent((int)event, NULL);
-
- if( putTimerQLock() == oslock_fail ) return;
-}
-
-FrequencyRatio IEEE1588Clock::calcLocalSystemClockRateDifference( Timestamp local_time, Timestamp system_time ) {
- unsigned long long inter_system_time;
- unsigned long long inter_local_time;
- FrequencyRatio ppt_offset;
-
- GPTP_LOG_DEBUG( "Calculated local to system clock rate difference" );
-
- if( !_local_system_freq_offset_init ) {
- _prev_system_time = system_time;
- _prev_local_time = local_time;
-
- _local_system_freq_offset_init = true;
-
- return 1.0;
- }
-
- inter_system_time =
- TIMESTAMP_TO_NS(system_time) - TIMESTAMP_TO_NS(_prev_system_time);
- inter_local_time =
- TIMESTAMP_TO_NS(local_time) - TIMESTAMP_TO_NS(_prev_local_time);
-
- if( inter_system_time != 0 ) {
- ppt_offset = ((FrequencyRatio)inter_local_time)/inter_system_time;
- } else {
- ppt_offset = 1.0;
- }
-
- _prev_system_time = system_time;
- _prev_local_time = local_time;
-
- return ppt_offset;
-}
-
-
-
-FrequencyRatio IEEE1588Clock::calcMasterLocalClockRateDifference( Timestamp master_time, Timestamp sync_time ) {
- unsigned long long inter_sync_time;
- unsigned long long inter_master_time;
- FrequencyRatio ppt_offset;
-
- GPTP_LOG_DEBUG( "Calculated master to local clock rate difference" );
-
- if( !_master_local_freq_offset_init ) {
- _prev_sync_time = sync_time;
- _prev_master_time = master_time;
-
- _master_local_freq_offset_init = true;
-
- return 1.0;
- }
-
- inter_sync_time =
- TIMESTAMP_TO_NS(sync_time) - TIMESTAMP_TO_NS(_prev_sync_time);
-
- uint64_t master_time_ns = TIMESTAMP_TO_NS(master_time);
- uint64_t prev_master_time_ns = TIMESTAMP_TO_NS(_prev_master_time);
-
- inter_master_time = master_time_ns - prev_master_time_ns;
-
- if( inter_sync_time != 0 ) {
- ppt_offset = ((FrequencyRatio)inter_master_time)/inter_sync_time;
- } else {
- ppt_offset = 1.0;
- }
-
- if( master_time_ns < prev_master_time_ns ) {
- GPTP_LOG_ERROR("Negative time jump detected - inter_master_time: %lld, inter_sync_time: %lld, incorrect ppt_offset: %Lf",
- inter_master_time, inter_sync_time, ppt_offset);
- _master_local_freq_offset_init = false;
-
- return NEGATIVE_TIME_JUMP;
- }
-
- _prev_sync_time = sync_time;
- _prev_master_time = master_time;
-
- return ppt_offset;
-}
-
-void IEEE1588Clock::setMasterOffset
-( CommonPort *port, int64_t master_local_offset,
- Timestamp local_time, FrequencyRatio master_local_freq_offset,
- int64_t local_system_offset, Timestamp system_time,
- FrequencyRatio local_system_freq_offset, unsigned sync_count,
- unsigned pdelay_count, PortState port_state, bool asCapable )
-{
- _master_local_freq_offset = master_local_freq_offset;
- _local_system_freq_offset = local_system_freq_offset;
-
- if (port->getTestMode()) {
- GPTP_LOG_STATUS("Clock offset:%lld Clock rate ratio:%Lf Sync Count:%u PDelay Count:%u",
- master_local_offset, master_local_freq_offset, sync_count, pdelay_count);
- }
-
- if( ipc != NULL ) {
- uint8_t grandmaster_id[PTP_CLOCK_IDENTITY_LENGTH];
- uint8_t clock_id[PTP_CLOCK_IDENTITY_LENGTH];
- PortIdentity port_identity;
- uint16_t port_number;
-
- grandmaster_clock_identity.getIdentityString(grandmaster_id);
- clock_identity.getIdentityString(clock_id);
- port->getPortIdentity(port_identity);
- port_identity.getPortNumber(&port_number);
-
- ipc->update(
- master_local_offset, local_system_offset, master_local_freq_offset,
- local_system_freq_offset, TIMESTAMP_TO_NS(local_time),
- sync_count, pdelay_count, port_state, asCapable);
-
- ipc->update_grandmaster(
- grandmaster_id, domain_number);
-
- ipc->update_network_interface(
- clock_id, priority1,
- clock_quality.cq_class, clock_quality.offsetScaledLogVariance,
- clock_quality.clockAccuracy,
- priority2, domain_number,
- port->getSyncInterval(),
- port->getAnnounceInterval(),
- 0, // TODO: Was port->getPDelayInterval() before refactoring. What do we do now?
- port_number);
- }
-
- if( master_local_offset == 0 && master_local_freq_offset == 1.0 ) {
- return;
- }
-
- if( _syntonize ) {
- if( _new_syntonization_set_point || _phase_error_violation > PHASE_ERROR_MAX_COUNT ) {
- _new_syntonization_set_point = false;
- _phase_error_violation = 0;
- /* Make sure that there are no transmit operations
- in progress */
- getTxLockAll();
- if (port->getTestMode()) {
- GPTP_LOG_STATUS("Adjust clock phase offset:%lld", -master_local_offset);
- }
- port->adjustClockPhase( -master_local_offset );
- _master_local_freq_offset_init = false;
- restartPDelayAll();
- putTxLockAll();
- master_local_offset = 0;
- }
-
- // Adjust for frequency offset
- long double phase_error = (long double) -master_local_offset;
- if( fabsl(phase_error) > PHASE_ERROR_THRESHOLD ) {
- ++_phase_error_violation;
- } else {
- _phase_error_violation = 0;
-
- float syncPerSec = (float)(1.0 / pow((float)2, port->getSyncInterval()));
- _ppm += (float) ((INTEGRAL * syncPerSec * phase_error) + PROPORTIONAL*((master_local_freq_offset-1.0)*1000000));
-
- GPTP_LOG_DEBUG("phase_error = %Lf, ppm = %f", phase_error, _ppm );
- }
-
- if( _ppm < LOWER_FREQ_LIMIT ) _ppm = LOWER_FREQ_LIMIT;
- if( _ppm > UPPER_FREQ_LIMIT ) _ppm = UPPER_FREQ_LIMIT;
- if ( port->getTestMode() ) {
- GPTP_LOG_STATUS("Adjust clock rate ppm:%f", _ppm);
- }
- if( !port->adjustClockRate( _ppm ) ) {
- GPTP_LOG_ERROR( "Failed to adjust clock rate" );
- }
- }
-
- return;
-}
-
-/* Get current time from system clock */
-Timestamp IEEE1588Clock::getTime(void)
-{
- return getSystemTime();
-}
-
-/* Get timestamp from hardware */
-Timestamp IEEE1588Clock::getPreciseTime(void)
-{
- return getSystemTime();
-}
-
-bool IEEE1588Clock::isBetterThan(PTPMessageAnnounce * msg)
-{
- unsigned char this1[14];
- unsigned char that1[14];
- uint16_t tmp;
-
- if (msg == NULL)
- return true;
-
- this1[0] = priority1;
- that1[0] = msg->getGrandmasterPriority1();
-
- this1[1] = clock_quality.cq_class;
- that1[1] = msg->getGrandmasterClockQuality()->cq_class;
-
- this1[2] = clock_quality.clockAccuracy;
- that1[2] = msg->getGrandmasterClockQuality()->clockAccuracy;
-
- tmp = clock_quality.offsetScaledLogVariance;
- tmp = PLAT_htons(tmp);
- memcpy(this1 + 3, &tmp, sizeof(tmp));
- tmp = msg->getGrandmasterClockQuality()->offsetScaledLogVariance;
- tmp = PLAT_htons(tmp);
- memcpy(that1 + 3, &tmp, sizeof(tmp));
-
- this1[5] = priority2;
- that1[5] = msg->getGrandmasterPriority2();
-
- clock_identity.getIdentityString(this1 + 6);
- msg->getGrandmasterIdentity((char *)that1 + 6);
-
-#if 0
- GPTP_LOG_DEBUG("(Clk)Us: ");
- for (int i = 0; i < 14; ++i)
- GPTP_LOG_DEBUG("%hhx ", this1[i]);
- GPTP_LOG_DEBUG("(Clk)Them: ");
- for (int i = 0; i < 14; ++i)
- GPTP_LOG_DEBUG("%hhx ", that1[i]);
-#endif
-
- return (memcmp(this1, that1, 14) < 0) ? true : false;
-}
-
-IEEE1588Clock::~IEEE1588Clock(void)
-{
- // Do nothing
-}
diff --git a/daemons/gptp/common/ini.c b/daemons/gptp/common/ini.c
deleted file mode 100644
index 42da8066..00000000
--- a/daemons/gptp/common/ini.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/* inih -- simple .INI file parser
-
-inih is released under the New BSD license (see LICENSE.txt). Go to the project
-home page for more info:
-
-http://code.google.com/p/inih/
-
-*/
-
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "ini.h"
-
-#if !INI_USE_STACK
-#include <stdlib.h>
-#endif
-
-#define MAX_SECTION 50
-#define MAX_NAME 50
-
-/* Strip whitespace chars off end of given string, in place. Return s. */
-static char* rstrip(char* s)
-{
- char* p = s + strlen(s);
- while (p > s && isspace(*--p))
- *p = '\0';
- return s;
-}
-
-/* Return pointer to first non-whitespace char in given string. */
-static char* lskip(const char* s)
-{
- while (*s && isspace(*s))
- s++;
- return (char*)s;
-}
-
-/* Return pointer to first char c or ';' comment in given string, or pointer to
- null at end of string if neither found. ';' must be prefixed by a whitespace
- character to register as a comment. */
-static char* find_char_or_comment(const char* s, char c)
-{
- int was_whitespace = 0;
- while (*s && *s != c && !(was_whitespace && *s == ';')) {
- was_whitespace = isspace(*s);
- s++;
- }
- return (char*)s;
-}
-
-/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
-static char* strncpy0(char* dest, const char* src, size_t size)
-{
- strncpy(dest, src, size);
- dest[size - 1] = '\0';
- return dest;
-}
-
-/* See documentation in header file. */
-int ini_parse_file(FILE* file,
- int (*handler)(void*, const char*, const char*,
- const char*),
- void* user)
-{
- /* Uses a fair bit of stack (use heap instead if you need to) */
-#if INI_USE_STACK
- char line[INI_MAX_LINE];
-#else
- char* line;
-#endif
- char section[MAX_SECTION] = "";
- char prev_name[MAX_NAME] = "";
-
- char* start;
- char* end;
- char* name;
- char* value;
- int lineno = 0;
- int error = 0;
-
-#if !INI_USE_STACK
- line = (char*)malloc(INI_MAX_LINE);
- if (!line) {
- return -2;
- }
-#endif
-
- /* Scan through file line by line */
- while (fgets(line, INI_MAX_LINE, file) != NULL) {
- lineno++;
-
- start = line;
-#if INI_ALLOW_BOM
- if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
- (unsigned char)start[1] == 0xBB &&
- (unsigned char)start[2] == 0xBF) {
- start += 3;
- }
-#endif
- start = lskip(rstrip(start));
-
- if (*start == ';' || *start == '#') {
- /* Per Python ConfigParser, allow '#' comments at start of line */
- }
-#if INI_ALLOW_MULTILINE
- else if (*prev_name && *start && start > line) {
- /* Non-black line with leading whitespace, treat as continuation
- of previous name's value (as per Python ConfigParser). */
- if (!handler(user, section, prev_name, start) && !error)
- error = lineno;
- }
-#endif
- else if (*start == '[') {
- /* A "[section]" line */
- end = find_char_or_comment(start + 1, ']');
- if (*end == ']') {
- *end = '\0';
- strncpy0(section, start + 1, sizeof(section));
- *prev_name = '\0';
- }
- else if (!error) {
- /* No ']' found on section line */
- error = lineno;
- }
- }
- else if (*start && *start != ';') {
- /* Not a comment, must be a name[=:]value pair */
- end = find_char_or_comment(start, '=');
- if (*end != '=') {
- end = find_char_or_comment(start, ':');
- }
- if (*end == '=' || *end == ':') {
- *end = '\0';
- name = rstrip(start);
- value = lskip(end + 1);
- end = find_char_or_comment(value, '\0');
- if (*end == ';')
- *end = '\0';
- rstrip(value);
-
- /* Valid name[=:]value pair found, call handler */
- strncpy0(prev_name, name, sizeof(prev_name));
- if (!handler(user, section, name, value) && !error)
- error = lineno;
- }
- else if (!error) {
- /* No '=' or ':' found on name[=:]value line */
- error = lineno;
- }
- }
- }
-
-#if !INI_USE_STACK
- free(line);
-#endif
-
- return error;
-}
-
-/* See documentation in header file. */
-int ini_parse(const char* filename,
- int (*handler)(void*, const char*, const char*, const char*),
- void* user)
-{
- FILE* file;
- int error;
-
- file = fopen(filename, "r");
- if (!file)
- return -1;
- error = ini_parse_file(file, handler, user);
- fclose(file);
- return error;
-}
diff --git a/daemons/gptp/common/ini.h b/daemons/gptp/common/ini.h
deleted file mode 100644
index b3a494a2..00000000
--- a/daemons/gptp/common/ini.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* inih -- simple .INI file parser
-
-inih is released under the New BSD license (see LICENSE.txt). Go to the project
-home page for more info:
-
-http://code.google.com/p/inih/
-
-*/
-
-#ifndef __INI_H__
-#define __INI_H__
-
-/* Make this header file easier to include in C++ code */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-
-/* Parse given INI-style file. May have [section]s, name=value pairs
- (whitespace stripped), and comments starting with ';' (semicolon). Section
- is "" if name=value pair parsed before any section heading. name:value
- pairs are also supported as a concession to Python's ConfigParser.
-
- For each name=value pair parsed, call handler function with given user
- pointer as well as section, name, and value (data only valid for duration
- of handler call). Handler should return nonzero on success, zero on error.
-
- Returns 0 on success, line number of first error on parse error (doesn't
- stop on first error), -1 on file open error, or -2 on memory allocation
- error (only when INI_USE_STACK is zero).
-*/
-int ini_parse(const char* filename,
- int (*handler)(void* user, const char* section,
- const char* name, const char* value),
- void* user);
-
-/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
- close the file when it's finished -- the caller must do that. */
-int ini_parse_file(FILE* file,
- int (*handler)(void* user, const char* section,
- const char* name, const char* value),
- void* user);
-
-/* Nonzero to allow multi-line value parsing, in the style of Python's
- ConfigParser. If allowed, ini_parse() will call the handler with the same
- name for each subsequent line parsed. */
-#ifndef INI_ALLOW_MULTILINE
-#define INI_ALLOW_MULTILINE 1
-#endif
-
-/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
- the file. See http://code.google.com/p/inih/issues/detail?id=21 */
-#ifndef INI_ALLOW_BOM
-#define INI_ALLOW_BOM 1
-#endif
-
-/* Nonzero to use stack, zero to use heap (malloc/free). */
-#ifndef INI_USE_STACK
-#define INI_USE_STACK 1
-#endif
-
-/* Maximum line length for any line in INI file. */
-#ifndef INI_MAX_LINE
-#define INI_MAX_LINE 200
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __INI_H__ */
diff --git a/daemons/gptp/common/ipcdef.hpp b/daemons/gptp/common/ipcdef.hpp
deleted file mode 100644
index 670aeeed..00000000
--- a/daemons/gptp/common/ipcdef.hpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
- ******************************************************************************/
-
-#ifndef IPCDEF_HPP
-#define IPCDEF_HPP
-
-/**@file
- * This is a common header file. OS-specific implementations should use
- * this file as base. Currently we have two IPC implementations:
- * Linux: Located at linux/src/linux_ipc.hpp (among other files that include this)
- * Windows: Located at windows/daemon_cl/windows_ipc.hpp
-*/
-
-#if defined (__unix__) || defined(__linux__)
-#include <sys/types.h>
-
-/*Type for process id*/
-#define PID_TYPE pid_t
-
-#elif defined(_WIN32) || defined(_WIN64)
-
-/*Definition of DWORD*/
-#include <IntSafe.h>
-
-/*Type for process ID*/
-#define PID_TYPE DWORD
-
-#else
-/*Create new ifdefs for different OSs and/or add to the existing ones*/
-#error "ERROR. OS not supported"
-#endif /*__unix__ / _WIN*/
-
-#include <ptptypes.hpp>
-
-/**
- * @brief Provides a data structure for gPTP time
- */
-typedef struct {
- int64_t ml_phoffset; //!< Master to local phase offset
- int64_t ls_phoffset; //!< Local to system phase offset
- FrequencyRatio ml_freqoffset; //!< Master to local frequency offset
- FrequencyRatio ls_freqoffset; //!< Local to system frequency offset
- uint64_t local_time; //!< Local time of last update
-
- /* Current grandmaster information */
- /* Referenced by the IEEE Std 1722.1-2013 AVDECC Discovery Protocol Data Unit (ADPDU) */
- uint8_t gptp_grandmaster_id[PTP_CLOCK_IDENTITY_LENGTH]; //!< Current grandmaster id (all 0's if no grandmaster selected)
- uint8_t gptp_domain_number; //!< gPTP domain number
-
- /* Grandmaster support for the network interface */
- /* Referenced by the IEEE Std 1722.1-2013 AVDECC AVB_INTERFACE descriptor */
- uint8_t clock_identity[PTP_CLOCK_IDENTITY_LENGTH]; //!< The clock identity of the interface
- uint8_t priority1; //!< The priority1 field of the grandmaster functionality of the interface, or 0xFF if not supported
- uint8_t clock_class; //!< The clockClass field of the grandmaster functionality of the interface, or 0xFF if not supported
- int16_t offset_scaled_log_variance; //!< The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported
- uint8_t clock_accuracy; //!< The clockAccuracy field of the grandmaster functionality of the interface, or 0xFF if not supported
- uint8_t priority2; //!< The priority2 field of the grandmaster functionality of the interface, or 0xFF if not supported
- uint8_t domain_number; //!< The domainNumber field of the grandmaster functionality of the interface, or 0 if not supported
- int8_t log_sync_interval; //!< The currentLogSyncInterval field of the grandmaster functionality of the interface, or 0 if not supported
- int8_t log_announce_interval; //!< The currentLogAnnounceInterval field of the grandmaster functionality of the interface, or 0 if not supported
- int8_t log_pdelay_interval; //!< The currentLogPDelayReqInterval field of the grandmaster functionality of the interface, or 0 if not supported
- uint16_t port_number; //!< The portNumber field of the interface, or 0x0000 if not supported
-
- /* Linux-specific */
- uint32_t sync_count; //!< Sync messages count
- uint32_t pdelay_count; //!< pdelay messages count
- bool asCapable; //!< asCapable flag: true = device is AS Capable; false otherwise
- PortState port_state; //!< gPTP port state. It can assume values defined at ::PortState
- PID_TYPE process_id; //!< Process id number
-} gPtpTimeData;
-
-/*
-
- Integer64 <master-local phase offset>
- Integer64 <local-system phase offset>
- LongDouble <master-local frequency offset>
- LongDouble <local-system frequency offset>
- UInteger64 <local time of last update>
-
- * Meaning of IPC provided values:
-
- master ~= local - <master-local phase offset>
- local ~= system - <local-system phase offset>
- Dmaster ~= Dlocal * <master-local frequency offset>
- Dlocal ~= Dsystem * <local-system freq offset> (where D denotes a delta)
-
-*/
-
-#endif/*IPCDEF_HPP*/
-
diff --git a/daemons/gptp/common/ptp_message.cpp b/daemons/gptp/common/ptp_message.cpp
deleted file mode 100644
index 8dc6775c..00000000
--- a/daemons/gptp/common/ptp_message.cpp
+++ /dev/null
@@ -1,2018 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <ieee1588.hpp>
-#include <avbts_clock.hpp>
-#include <avbts_message.hpp>
-#include <ether_port.hpp>
-#include <avbts_ostimer.hpp>
-#include <ether_tstamper.hpp>
-
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-PTPMessageCommon::PTPMessageCommon( CommonPort *port )
-{
- // Fill in fields using port/clock dataset as a template
- versionPTP = GPTP_VERSION;
- versionNetwork = PTP_NETWORK_VERSION;
- domainNumber = port->getClock()->getDomain();
- // Set flags as necessary
- memset(flags, 0, PTP_FLAGS_LENGTH);
- flags[PTP_PTPTIMESCALE_BYTE] |= (0x1 << PTP_PTPTIMESCALE_BIT);
- correctionField = 0;
- _gc = false;
- sourcePortIdentity = new PortIdentity();
-
- return;
-}
-
-/* Determine whether the message was sent by given communication technology,
- uuid, and port id fields */
-bool PTPMessageCommon::isSenderEqual(PortIdentity portIdentity)
-{
- return portIdentity == *sourcePortIdentity;
-}
-
-PTPMessageCommon *buildPTPMessage
-( char *buf, int size, LinkLayerAddress *remote,
- CommonPort *port )
-{
- OSTimer *timer = port->getTimerFactory()->createTimer();
- PTPMessageCommon *msg = NULL;
- PTPMessageId messageId;
- MessageType messageType;
- unsigned char tspec_msg_t = 0;
- unsigned char transportSpecific = 0;
-
- uint16_t sequenceId;
- PortIdentity *sourcePortIdentity;
- Timestamp timestamp(0, 0, 0);
- unsigned counter_value = 0;
- EtherPort *eport = NULL;
-
-#if PTP_DEBUG
- {
- int i;
- GPTP_LOG_VERBOSE("Packet Dump:\n");
- for (i = 0; i < size; ++i) {
- GPTP_LOG_VERBOSE("%hhx\t", buf[i]);
- if (i % 8 == 7)
- GPTP_LOG_VERBOSE("\n");
- }
- if (i % 8 != 0)
- GPTP_LOG_VERBOSE("\n");
- }
-#endif
-
- memcpy(&tspec_msg_t,
- buf + PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(PTP_COMMON_HDR_OFFSET),
- sizeof(tspec_msg_t));
- messageType = (MessageType) (tspec_msg_t & 0xF);
- transportSpecific = (tspec_msg_t >> 4) & 0x0F;
-
- sourcePortIdentity = new PortIdentity
- ((uint8_t *)
- (buf + PTP_COMMON_HDR_SOURCE_CLOCK_ID
- (PTP_COMMON_HDR_OFFSET)),
- (uint16_t *)
- (buf + PTP_COMMON_HDR_SOURCE_PORT_ID
- (PTP_COMMON_HDR_OFFSET)));
-
- memcpy
- (&(sequenceId),
- buf + PTP_COMMON_HDR_SEQUENCE_ID(PTP_COMMON_HDR_OFFSET),
- sizeof(sequenceId));
- sequenceId = PLAT_ntohs(sequenceId);
-
- GPTP_LOG_VERBOSE("Captured Sequence Id: %u", sequenceId);
- messageId.setMessageType(messageType);
- messageId.setSequenceId(sequenceId);
-
-
- if (!(messageType >> 3)) {
- int iter = 5;
- long req = 4000; // = 1 ms
-
- eport = dynamic_cast <EtherPort *> ( port );
- if (eport == NULL)
- {
- GPTP_LOG_ERROR
- ( "Received Event Message, but port type "
- "doesn't support timestamping\n" );
- goto abort;
- }
-
- int ts_good =
- eport->getRxTimestamp
- (sourcePortIdentity, messageId, timestamp, counter_value, false);
- while (ts_good != GPTP_EC_SUCCESS && iter-- != 0) {
- // Waits at least 1 time slice regardless of size of 'req'
- timer->sleep(req);
- if (ts_good != GPTP_EC_EAGAIN)
- GPTP_LOG_ERROR(
- "Error (RX) timestamping RX event packet (Retrying), error=%d",
- ts_good );
- ts_good =
- eport->getRxTimestamp(sourcePortIdentity, messageId,
- timestamp, counter_value,
- iter == 0);
- req *= 2;
- }
- if (ts_good != GPTP_EC_SUCCESS) {
- char err_msg[HWTIMESTAMPER_EXTENDED_MESSAGE_SIZE];
- port->getExtendedError(err_msg);
- GPTP_LOG_ERROR
- ("*** Received an event packet but cannot retrieve timestamp, discarding. messageType=%u,error=%d\n%s",
- messageType, ts_good, msg);
- //_exit(-1);
- goto abort;
- }
-
- else {
- GPTP_LOG_VERBOSE("Timestamping event packet");
- }
-
- }
-
- if (1 != transportSpecific) {
- GPTP_LOG_EXCEPTION("*** Received message with unsupported transportSpecific type=%d", transportSpecific);
- goto abort;
- }
-
- switch (messageType) {
- case SYNC_MESSAGE:
-
- GPTP_LOG_DEBUG("*** Received Sync message" );
- GPTP_LOG_VERBOSE("Sync RX timestamp = %hu,%u,%u", timestamp.seconds_ms, timestamp.seconds_ls, timestamp.nanoseconds );
-
- // Be sure buffer is the correction size
- if (size < PTP_COMMON_HDR_LENGTH + PTP_SYNC_LENGTH) {
- goto abort;
- }
- {
- PTPMessageSync *sync_msg = new PTPMessageSync();
- sync_msg->messageType = messageType;
- // Copy in v2 sync specific fields
- memcpy(&(sync_msg->originTimestamp.seconds_ms),
- buf + PTP_SYNC_SEC_MS(PTP_SYNC_OFFSET),
- sizeof(sync_msg->originTimestamp.seconds_ms));
- memcpy(&(sync_msg->originTimestamp.seconds_ls),
- buf + PTP_SYNC_SEC_LS(PTP_SYNC_OFFSET),
- sizeof(sync_msg->originTimestamp.seconds_ls));
- memcpy(&(sync_msg->originTimestamp.nanoseconds),
- buf + PTP_SYNC_NSEC(PTP_SYNC_OFFSET),
- sizeof(sync_msg->originTimestamp.nanoseconds));
- msg = sync_msg;
- }
- break;
- case FOLLOWUP_MESSAGE:
-
- GPTP_LOG_DEBUG("*** Received Follow Up message");
-
- // Be sure buffer is the correction size
- if (size < (int)(PTP_COMMON_HDR_LENGTH + PTP_FOLLOWUP_LENGTH + sizeof(FollowUpTLV))) {
- goto abort;
- }
- {
- PTPMessageFollowUp *followup_msg =
- new PTPMessageFollowUp();
- followup_msg->messageType = messageType;
- // Copy in v2 sync specific fields
- memcpy(&
- (followup_msg->
- preciseOriginTimestamp.seconds_ms),
- buf + PTP_FOLLOWUP_SEC_MS(PTP_FOLLOWUP_OFFSET),
- sizeof(followup_msg->
- preciseOriginTimestamp.seconds_ms));
- memcpy(&
- (followup_msg->
- preciseOriginTimestamp.seconds_ls),
- buf + PTP_FOLLOWUP_SEC_LS(PTP_FOLLOWUP_OFFSET),
- sizeof(followup_msg->
- preciseOriginTimestamp.seconds_ls));
- memcpy(&
- (followup_msg->
- preciseOriginTimestamp.nanoseconds),
- buf + PTP_FOLLOWUP_NSEC(PTP_FOLLOWUP_OFFSET),
- sizeof(followup_msg->
- preciseOriginTimestamp.nanoseconds));
-
- followup_msg->preciseOriginTimestamp.seconds_ms =
- PLAT_ntohs(followup_msg->
- preciseOriginTimestamp.seconds_ms);
- followup_msg->preciseOriginTimestamp.seconds_ls =
- PLAT_ntohl(followup_msg->
- preciseOriginTimestamp.seconds_ls);
- followup_msg->preciseOriginTimestamp.nanoseconds =
- PLAT_ntohl(followup_msg->
- preciseOriginTimestamp.nanoseconds);
-
- memcpy( &(followup_msg->tlv),
- buf+PTP_FOLLOWUP_OFFSET+PTP_FOLLOWUP_LENGTH,
- sizeof(followup_msg->tlv) );
-
- msg = followup_msg;
- }
-
- break;
- case PATH_DELAY_REQ_MESSAGE:
-
- GPTP_LOG_DEBUG("*** Received PDelay Request message");
-
- // Be sure buffer is the correction size
- if (size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_REQ_LENGTH
- && /* For Broadcom compatibility */ size != 46) {
- goto abort;
- }
- {
- PTPMessagePathDelayReq *pdelay_req_msg =
- new PTPMessagePathDelayReq();
- pdelay_req_msg->messageType = messageType;
-
-#if 0
- /*TODO: Do we need the code below? Can we remove it?*/
- // The origin timestamp for PDelay Request packets has been eliminated since it is unused
- // Copy in v2 PDelay Request specific fields
- memcpy(&(pdelay_req_msg->originTimestamp.seconds_ms),
- buf +
- PTP_PDELAY_REQ_SEC_MS(PTP_PDELAY_REQ_OFFSET),
- sizeof(pdelay_req_msg->
- originTimestamp.seconds_ms));
- memcpy(&(pdelay_req_msg->originTimestamp.seconds_ls),
- buf +
- PTP_PDELAY_REQ_SEC_LS(PTP_PDELAY_REQ_OFFSET),
- sizeof(pdelay_req_msg->
- originTimestamp.seconds_ls));
- memcpy(&(pdelay_req_msg->originTimestamp.nanoseconds),
- buf + PTP_PDELAY_REQ_NSEC(PTP_PDELAY_REQ_OFFSET),
- sizeof(pdelay_req_msg->
- originTimestamp.nanoseconds));
-
- pdelay_req_msg->originTimestamp.seconds_ms =
- PLAT_ntohs(pdelay_req_msg->
- originTimestamp.seconds_ms);
- pdelay_req_msg->originTimestamp.seconds_ls =
- PLAT_ntohl(pdelay_req_msg->
- originTimestamp.seconds_ls);
- pdelay_req_msg->originTimestamp.nanoseconds =
- PLAT_ntohl(pdelay_req_msg->
- originTimestamp.nanoseconds);
-#endif
-
- msg = pdelay_req_msg;
- }
- break;
- case PATH_DELAY_RESP_MESSAGE:
-
- GPTP_LOG_DEBUG("*** Received PDelay Response message, Timestamp %u (sec) %u (ns), seqID %u",
- timestamp.seconds_ls, timestamp.nanoseconds,
- sequenceId);
-
- // Be sure buffer is the correction size
- if (size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_RESP_LENGTH) {
- goto abort;
- }
- {
- PTPMessagePathDelayResp *pdelay_resp_msg =
- new PTPMessagePathDelayResp();
- pdelay_resp_msg->messageType = messageType;
- // Copy in v2 PDelay Response specific fields
- pdelay_resp_msg->requestingPortIdentity =
- new PortIdentity((uint8_t *) buf +
- PTP_PDELAY_RESP_REQ_CLOCK_ID
- (PTP_PDELAY_RESP_OFFSET),
- (uint16_t *) (buf +
- PTP_PDELAY_RESP_REQ_PORT_ID
- (PTP_PDELAY_RESP_OFFSET)));
-
-#ifdef DEBUG
- for (int n = 0; n < PTP_CLOCK_IDENTITY_LENGTH; ++n) { // MMM
- GPTP_LOG_VERBOSE("%c",
- pdelay_resp_msg->
- requestingPortIdentity.clockIdentity
- [n]);
- }
-#endif
-
- memcpy(& (pdelay_resp_msg->requestReceiptTimestamp.seconds_ms),
- buf + PTP_PDELAY_RESP_SEC_MS(PTP_PDELAY_RESP_OFFSET),
- sizeof
- (pdelay_resp_msg->requestReceiptTimestamp.seconds_ms));
- memcpy(&
- (pdelay_resp_msg->
- requestReceiptTimestamp.seconds_ls),
- buf +
- PTP_PDELAY_RESP_SEC_LS(PTP_PDELAY_RESP_OFFSET),
- sizeof(pdelay_resp_msg->
- requestReceiptTimestamp.seconds_ls));
- memcpy(&
- (pdelay_resp_msg->
- requestReceiptTimestamp.nanoseconds),
- buf +
- PTP_PDELAY_RESP_NSEC(PTP_PDELAY_RESP_OFFSET),
- sizeof(pdelay_resp_msg->
- requestReceiptTimestamp.nanoseconds));
-
- pdelay_resp_msg->requestReceiptTimestamp.seconds_ms =
- PLAT_ntohs(pdelay_resp_msg->requestReceiptTimestamp.seconds_ms);
- pdelay_resp_msg->requestReceiptTimestamp.seconds_ls =
- PLAT_ntohl(pdelay_resp_msg->requestReceiptTimestamp.seconds_ls);
- pdelay_resp_msg->requestReceiptTimestamp.nanoseconds =
- PLAT_ntohl(pdelay_resp_msg->requestReceiptTimestamp.nanoseconds);
-
- msg = pdelay_resp_msg;
- }
- break;
- case PATH_DELAY_FOLLOWUP_MESSAGE:
-
- GPTP_LOG_DEBUG("*** Received PDelay Response FollowUp message");
-
- // Be sure buffer is the correction size
-// if( size < PTP_COMMON_HDR_LENGTH + PTP_PDELAY_FOLLOWUP_LENGTH ) {
-// goto abort;
-// }
- {
- PTPMessagePathDelayRespFollowUp *pdelay_resp_fwup_msg =
- new PTPMessagePathDelayRespFollowUp();
- pdelay_resp_fwup_msg->messageType = messageType;
- // Copy in v2 PDelay Response specific fields
- pdelay_resp_fwup_msg->requestingPortIdentity =
- new PortIdentity((uint8_t *) buf +
- PTP_PDELAY_FOLLOWUP_REQ_CLOCK_ID
- (PTP_PDELAY_RESP_OFFSET),
- (uint16_t *) (buf +
- PTP_PDELAY_FOLLOWUP_REQ_PORT_ID
- (PTP_PDELAY_FOLLOWUP_OFFSET)));
-
- memcpy(&
- (pdelay_resp_fwup_msg->
- responseOriginTimestamp.seconds_ms),
- buf +
- PTP_PDELAY_FOLLOWUP_SEC_MS
- (PTP_PDELAY_FOLLOWUP_OFFSET),
- sizeof
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- seconds_ms));
- memcpy(&
- (pdelay_resp_fwup_msg->
- responseOriginTimestamp.seconds_ls),
- buf +
- PTP_PDELAY_FOLLOWUP_SEC_LS
- (PTP_PDELAY_FOLLOWUP_OFFSET),
- sizeof
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- seconds_ls));
- memcpy(&
- (pdelay_resp_fwup_msg->
- responseOriginTimestamp.nanoseconds),
- buf +
- PTP_PDELAY_FOLLOWUP_NSEC
- (PTP_PDELAY_FOLLOWUP_OFFSET),
- sizeof
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- nanoseconds));
-
- pdelay_resp_fwup_msg->
- responseOriginTimestamp.seconds_ms =
- PLAT_ntohs
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- seconds_ms);
- pdelay_resp_fwup_msg->
- responseOriginTimestamp.seconds_ls =
- PLAT_ntohl
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- seconds_ls);
- pdelay_resp_fwup_msg->
- responseOriginTimestamp.nanoseconds =
- PLAT_ntohl
- (pdelay_resp_fwup_msg->responseOriginTimestamp.
- nanoseconds);
-
- msg = pdelay_resp_fwup_msg;
- }
- break;
- case ANNOUNCE_MESSAGE:
-
- GPTP_LOG_VERBOSE("*** Received Announce message");
-
- {
- PTPMessageAnnounce *annc = new PTPMessageAnnounce();
- annc->messageType = messageType;
- int tlv_length = size - PTP_COMMON_HDR_LENGTH + PTP_ANNOUNCE_LENGTH;
-
- memcpy(&(annc->currentUtcOffset),
- buf +
- PTP_ANNOUNCE_CURRENT_UTC_OFFSET
- (PTP_ANNOUNCE_OFFSET),
- sizeof(annc->currentUtcOffset));
- annc->currentUtcOffset =
- PLAT_ntohs(annc->currentUtcOffset);
- memcpy(&(annc->grandmasterPriority1),
- buf +
- PTP_ANNOUNCE_GRANDMASTER_PRIORITY1
- (PTP_ANNOUNCE_OFFSET),
- sizeof(annc->grandmasterPriority1));
- memcpy( annc->grandmasterClockQuality,
- buf+
- PTP_ANNOUNCE_GRANDMASTER_CLOCK_QUALITY
- (PTP_ANNOUNCE_OFFSET),
- sizeof( *annc->grandmasterClockQuality ));
- annc->
- grandmasterClockQuality->offsetScaledLogVariance =
- PLAT_ntohs
- ( annc->grandmasterClockQuality->
- offsetScaledLogVariance );
- memcpy(&(annc->grandmasterPriority2),
- buf +
- PTP_ANNOUNCE_GRANDMASTER_PRIORITY2
- (PTP_ANNOUNCE_OFFSET),
- sizeof(annc->grandmasterPriority2));
- memcpy(&(annc->grandmasterIdentity),
- buf +
- PTP_ANNOUNCE_GRANDMASTER_IDENTITY
- (PTP_ANNOUNCE_OFFSET),
- PTP_CLOCK_IDENTITY_LENGTH);
- memcpy(&(annc->stepsRemoved),
- buf +
- PTP_ANNOUNCE_STEPS_REMOVED(PTP_ANNOUNCE_OFFSET),
- sizeof(annc->stepsRemoved));
- annc->stepsRemoved = PLAT_ntohs(annc->stepsRemoved);
- memcpy(&(annc->timeSource),
- buf +
- PTP_ANNOUNCE_TIME_SOURCE(PTP_ANNOUNCE_OFFSET),
- sizeof(annc->timeSource));
-
- // Parse TLV if it exists
- buf += PTP_COMMON_HDR_LENGTH + PTP_ANNOUNCE_LENGTH;
- if( tlv_length > (int) (2*sizeof(uint16_t)) && PLAT_ntohs(*((uint16_t *)buf)) == PATH_TRACE_TLV_TYPE) {
- buf += sizeof(uint16_t);
- tlv_length -= sizeof(uint16_t);
- annc->tlv.parseClockIdentity((uint8_t *)buf, tlv_length);
- }
-
- msg = annc;
- }
- break;
-
- case SIGNALLING_MESSAGE:
- {
- PTPMessageSignalling *signallingMsg = new PTPMessageSignalling();
- signallingMsg->messageType = messageType;
-
- memcpy(&(signallingMsg->targetPortIdentify),
- buf + PTP_SIGNALLING_TARGET_PORT_IDENTITY(PTP_SIGNALLING_OFFSET),
- sizeof(signallingMsg->targetPortIdentify));
-
- memcpy( &(signallingMsg->tlv), buf + PTP_SIGNALLING_OFFSET + PTP_SIGNALLING_LENGTH, sizeof(signallingMsg->tlv) );
-
- msg = signallingMsg;
- }
- break;
-
- default:
-
- GPTP_LOG_EXCEPTION("Received unsupported message type, %d",
- (int)messageType);
- port->incCounter_ieee8021AsPortStatRxPTPPacketDiscard();
-
- goto abort;
- }
-
- msg->_gc = false;
-
- // Copy in common header fields
- memcpy(&(msg->versionPTP),
- buf + PTP_COMMON_HDR_PTP_VERSION(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->versionPTP));
- memcpy(&(msg->messageLength),
- buf + PTP_COMMON_HDR_MSG_LENGTH(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->messageLength));
- msg->messageLength = PLAT_ntohs(msg->messageLength);
- memcpy(&(msg->domainNumber),
- buf + PTP_COMMON_HDR_DOMAIN_NUMBER(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->domainNumber));
- memcpy(&(msg->flags), buf + PTP_COMMON_HDR_FLAGS(PTP_COMMON_HDR_OFFSET),
- PTP_FLAGS_LENGTH);
- memcpy(&(msg->correctionField),
- buf + PTP_COMMON_HDR_CORRECTION(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->correctionField));
- msg->correctionField = PLAT_ntohll(msg->correctionField);
- msg->sourcePortIdentity = sourcePortIdentity;
- msg->sequenceId = sequenceId;
- memcpy(&(msg->control),
- buf + PTP_COMMON_HDR_CONTROL(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->control));
- memcpy(&(msg->logMeanMessageInterval),
- buf + PTP_COMMON_HDR_LOG_MSG_INTRVL(PTP_COMMON_HDR_OFFSET),
- sizeof(msg->logMeanMessageInterval));
-
- if( eport != NULL )
- eport->addSockAddrMap( msg->sourcePortIdentity, remote );
-
- msg->_timestamp = timestamp;
- msg->_timestamp_counter_value = counter_value;
-
- delete timer;
-
- return msg;
-
-abort:
- delete sourcePortIdentity;
- delete timer;
-
- return NULL;
-}
-
-bool PTPMessageCommon::getTxTimestamp( EtherPort *port, uint32_t link_speed )
-{
- OSTimer *timer = port->getTimerFactory()->createTimer();
- int ts_good;
- Timestamp tx_timestamp;
- uint32_t unused;
- unsigned req = TX_TIMEOUT_BASE;
- int iter = TX_TIMEOUT_ITER;
-
- ts_good = port->getTxTimestamp
- ( this, tx_timestamp, unused, false );
- while( ts_good != GPTP_EC_SUCCESS && iter-- != 0 )
- {
- timer->sleep(req);
- if (ts_good != GPTP_EC_EAGAIN && iter < 1)
- GPTP_LOG_ERROR(
- "Error (TX) timestamping PDelay request "
- "(Retrying-%d), error=%d", iter, ts_good);
- ts_good = port->getTxTimestamp
- ( this, tx_timestamp, unused , iter == 0 );
- req *= 2;
- }
-
- if( ts_good == GPTP_EC_SUCCESS )
- {
- Timestamp phy_compensation = port->getTxPhyDelay( link_speed );
- GPTP_LOG_DEBUG( "TX PHY compensation: %s sec",
- phy_compensation.toString().c_str() );
- phy_compensation._version = tx_timestamp._version;
- _timestamp = tx_timestamp + phy_compensation;
- } else
- {
- char msg[HWTIMESTAMPER_EXTENDED_MESSAGE_SIZE];
- port->getExtendedError(msg);
- GPTP_LOG_ERROR(
- "Error (TX) timestamping PDelay request, error=%d\t%s",
- ts_good, msg);
- _timestamp = INVALID_TIMESTAMP;
- }
-
- delete timer;
- return ts_good == GPTP_EC_SUCCESS;
-}
-
-void PTPMessageCommon::processMessage( CommonPort *port )
-{
- _gc = true;
- return;
-}
-
-void PTPMessageCommon::buildCommonHeader(uint8_t * buf)
-{
- unsigned char tspec_msg_t;
- /*TODO: Message type assumes value sbetween 0x0 and 0xD (its an enumeration).
- * So I am not sure why we are adding 0x10 to it
- */
- tspec_msg_t = messageType | 0x10;
- long long correctionField_BE = PLAT_htonll(correctionField);
- uint16_t messageLength_NO = PLAT_htons(messageLength);
-
- memcpy(buf + PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(PTP_COMMON_HDR_OFFSET),
- &tspec_msg_t, sizeof(tspec_msg_t));
- memcpy(buf + PTP_COMMON_HDR_PTP_VERSION(PTP_COMMON_HDR_OFFSET),
- &versionPTP, sizeof(versionPTP));
- memcpy(buf + PTP_COMMON_HDR_MSG_LENGTH(PTP_COMMON_HDR_OFFSET),
- &messageLength_NO, sizeof(messageLength_NO));
- memcpy(buf + PTP_COMMON_HDR_DOMAIN_NUMBER(PTP_COMMON_HDR_OFFSET),
- &domainNumber, sizeof(domainNumber));
- memcpy(buf + PTP_COMMON_HDR_FLAGS(PTP_COMMON_HDR_OFFSET), &flags,
- PTP_FLAGS_LENGTH);
- memcpy(buf + PTP_COMMON_HDR_CORRECTION(PTP_COMMON_HDR_OFFSET),
- &correctionField_BE, sizeof(correctionField));
-
- sourcePortIdentity->getClockIdentityString
- ((uint8_t *) buf+
- PTP_COMMON_HDR_SOURCE_CLOCK_ID(PTP_COMMON_HDR_OFFSET));
- sourcePortIdentity->getPortNumberNO
- ((uint16_t *) (buf + PTP_COMMON_HDR_SOURCE_PORT_ID
- (PTP_COMMON_HDR_OFFSET)));
-
- GPTP_LOG_VERBOSE("Sending Sequence Id: %u", sequenceId);
- sequenceId = PLAT_htons(sequenceId);
- memcpy(buf + PTP_COMMON_HDR_SEQUENCE_ID(PTP_COMMON_HDR_OFFSET),
- &sequenceId, sizeof(sequenceId));
- sequenceId = PLAT_ntohs(sequenceId);
- memcpy(buf + PTP_COMMON_HDR_CONTROL(PTP_COMMON_HDR_OFFSET), &control,
- sizeof(control));
- memcpy(buf + PTP_COMMON_HDR_LOG_MSG_INTRVL(PTP_COMMON_HDR_OFFSET),
- &logMeanMessageInterval, sizeof(logMeanMessageInterval));
-
- return;
-}
-
-void PTPMessageCommon::getPortIdentity(PortIdentity * identity)
-{
- *identity = *sourcePortIdentity;
-}
-
-void PTPMessageCommon::setPortIdentity(PortIdentity * identity)
-{
- *sourcePortIdentity = *identity;
-}
-
-PTPMessageCommon::~PTPMessageCommon(void)
-{
- delete sourcePortIdentity;
- return;
-}
-
-PTPMessageAnnounce::PTPMessageAnnounce(void)
-{
- grandmasterClockQuality = new ClockQuality();
-}
-
-PTPMessageAnnounce::~PTPMessageAnnounce(void)
-{
- delete grandmasterClockQuality;
-}
-
-bool PTPMessageAnnounce::isBetterThan(PTPMessageAnnounce * msg)
-{
- unsigned char this1[14];
- unsigned char that1[14];
- uint16_t tmp;
-
- this1[0] = grandmasterPriority1;
- that1[0] = msg->getGrandmasterPriority1();
-
- this1[1] = grandmasterClockQuality->cq_class;
- that1[1] = msg->getGrandmasterClockQuality()->cq_class;
-
- this1[2] = grandmasterClockQuality->clockAccuracy;
- that1[2] = msg->getGrandmasterClockQuality()->clockAccuracy;
-
- tmp = grandmasterClockQuality->offsetScaledLogVariance;
- tmp = PLAT_htons(tmp);
- memcpy(this1 + 3, &tmp, sizeof(tmp));
- tmp = msg->getGrandmasterClockQuality()->offsetScaledLogVariance;
- tmp = PLAT_htons(tmp);
- memcpy(that1 + 3, &tmp, sizeof(tmp));
-
- this1[5] = grandmasterPriority2;
- that1[5] = msg->getGrandmasterPriority2();
-
- this->getGrandmasterIdentity((char *)this1 + 6);
- msg->getGrandmasterIdentity((char *)that1 + 6);
-
-#if 0
- GPTP_LOG_VERBOSE("Us: ");
- for (int i = 0; i < 14; ++i)
- GPTP_LOG_VERBOSE("%hhx", this1[i]);
- GPTP_LOG_VERBOSE("\n");
- GPTP_LOG_VERBOSE("Them: ");
- for (int i = 0; i < 14; ++i)
- GPTP_LOG_VERBOSE("%hhx", that1[i]);
- GPTP_LOG_VERBOSE("\n");
-#endif
-
- return (memcmp(this1, that1, 14) < 0) ? true : false;
-}
-
-
-PTPMessageSync::PTPMessageSync() {
-}
-
-PTPMessageSync::~PTPMessageSync() {
-}
-
-PTPMessageSync::PTPMessageSync( EtherPort *port ) :
- PTPMessageCommon( port )
-{
- messageType = SYNC_MESSAGE; // This is an event message
- sequenceId = port->getNextSyncSequenceId();
- control = SYNC;
-
- flags[PTP_ASSIST_BYTE] |= (0x1 << PTP_ASSIST_BIT);
-
- originTimestamp = port->getClock()->getTime();
-
- logMeanMessageInterval = port->getSyncInterval();
- return;
-}
-
-bool PTPMessageSync::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0x0;
- Timestamp originTimestamp_BE;
- uint32_t link_speed;
-
- memset(buf_t, 0, 256);
- // Create packet in buf
- // Copy in common header
- messageLength = PTP_COMMON_HDR_LENGTH + PTP_SYNC_LENGTH;
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- // Get timestamp
- originTimestamp = port->getClock()->getTime();
- originTimestamp_BE.seconds_ms = PLAT_htons(originTimestamp.seconds_ms);
- originTimestamp_BE.seconds_ls = PLAT_htonl(originTimestamp.seconds_ls);
- originTimestamp_BE.nanoseconds =
- PLAT_htonl(originTimestamp.nanoseconds);
- // Copy in v2 sync specific fields
- memcpy(buf_ptr + PTP_SYNC_SEC_MS(PTP_SYNC_OFFSET),
- &(originTimestamp_BE.seconds_ms),
- sizeof(originTimestamp.seconds_ms));
- memcpy(buf_ptr + PTP_SYNC_SEC_LS(PTP_SYNC_OFFSET),
- &(originTimestamp_BE.seconds_ls),
- sizeof(originTimestamp.seconds_ls));
- memcpy(buf_ptr + PTP_SYNC_NSEC(PTP_SYNC_OFFSET),
- &(originTimestamp_BE.nanoseconds),
- sizeof(originTimestamp.nanoseconds));
-
- port->sendEventPort
- ( PTP_ETHERTYPE, buf_t, messageLength, MCAST_OTHER,
- destIdentity, &link_speed );
- port->incCounter_ieee8021AsPortStatTxSyncCount();
-
- return getTxTimestamp( port, link_speed );
-}
-
-PTPMessageAnnounce::PTPMessageAnnounce( CommonPort *port ) :
- PTPMessageCommon( port )
-{
- messageType = ANNOUNCE_MESSAGE; // This is an event message
- sequenceId = port->getNextAnnounceSequenceId();
- ClockIdentity id;
- control = MESSAGE_OTHER;
- ClockIdentity clock_identity;
-
- id = port->getClock()->getClockIdentity();
- tlv.appendClockIdentity(&id);
-
- currentUtcOffset = port->getClock()->getCurrentUtcOffset();
- grandmasterPriority1 = port->getClock()->getPriority1();
- grandmasterPriority2 = port->getClock()->getPriority2();
- grandmasterClockQuality = new ClockQuality();
- *grandmasterClockQuality = port->getClock()->getClockQuality();
- stepsRemoved = 0;
- timeSource = port->getClock()->getTimeSource();
- clock_identity = port->getClock()->getGrandmasterClockIdentity();
- clock_identity.getIdentityString(grandmasterIdentity);
-
- logMeanMessageInterval = port->getAnnounceInterval();
- return;
-}
-
-bool PTPMessageAnnounce::sendPort
-( CommonPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0x0;
-
- uint16_t currentUtcOffset_l = PLAT_htons(currentUtcOffset);
- uint16_t stepsRemoved_l = PLAT_htons(stepsRemoved);
- ClockQuality clockQuality_l = *grandmasterClockQuality;
- clockQuality_l.offsetScaledLogVariance =
- PLAT_htons(clockQuality_l.offsetScaledLogVariance);
-
- memset(buf_t, 0, 256);
- // Create packet in buf
- // Copy in common header
- messageLength =
- PTP_COMMON_HDR_LENGTH + PTP_ANNOUNCE_LENGTH + tlv.length();
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- memcpy(buf_ptr + PTP_ANNOUNCE_CURRENT_UTC_OFFSET(PTP_ANNOUNCE_OFFSET),
- &currentUtcOffset_l, sizeof(currentUtcOffset));
- memcpy(buf_ptr +
- PTP_ANNOUNCE_GRANDMASTER_PRIORITY1(PTP_ANNOUNCE_OFFSET),
- &grandmasterPriority1, sizeof(grandmasterPriority1));
- memcpy(buf_ptr +
- PTP_ANNOUNCE_GRANDMASTER_CLOCK_QUALITY(PTP_ANNOUNCE_OFFSET),
- &clockQuality_l, sizeof(clockQuality_l));
- memcpy(buf_ptr +
- PTP_ANNOUNCE_GRANDMASTER_PRIORITY2(PTP_ANNOUNCE_OFFSET),
- &grandmasterPriority2, sizeof(grandmasterPriority2));
- memcpy( buf_ptr+
- PTP_ANNOUNCE_GRANDMASTER_IDENTITY(PTP_ANNOUNCE_OFFSET),
- grandmasterIdentity, PTP_CLOCK_IDENTITY_LENGTH );
- memcpy(buf_ptr + PTP_ANNOUNCE_STEPS_REMOVED(PTP_ANNOUNCE_OFFSET),
- &stepsRemoved_l, sizeof(stepsRemoved));
- memcpy(buf_ptr + PTP_ANNOUNCE_TIME_SOURCE(PTP_ANNOUNCE_OFFSET),
- &timeSource, sizeof(timeSource));
- tlv.toByteString(buf_ptr + PTP_COMMON_HDR_LENGTH + PTP_ANNOUNCE_LENGTH);
-
- port->sendGeneralPort(PTP_ETHERTYPE, buf_t, messageLength, MCAST_OTHER, destIdentity);
- port->incCounter_ieee8021AsPortStatTxAnnounce();
-
- return true;
-}
-
-void PTPMessageAnnounce::processMessage( CommonPort *port )
-{
- ClockIdentity my_clock_identity;
-
- port->incCounter_ieee8021AsPortStatRxAnnounce();
-
- // Delete announce receipt timeout
- port->getClock()->deleteEventTimerLocked
- (port, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES);
-
- if( stepsRemoved >= 255 ) goto bail;
-
- // Reject Announce message from myself
- my_clock_identity = port->getClock()->getClockIdentity();
- if( sourcePortIdentity->getClockIdentity() == my_clock_identity ) {
- goto bail;
- }
-
- if(tlv.has(&my_clock_identity)) {
- goto bail;
- }
-
- // Add message to the list
- port->setQualifiedAnnounce( this );
-
- port->getClock()->addEventTimerLocked(port, STATE_CHANGE_EVENT, 16000000);
- bail:
- port->getClock()->addEventTimerLocked
- (port, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
- (unsigned long long)
- (ANNOUNCE_RECEIPT_TIMEOUT_MULTIPLIER *
- (pow
- ((double)2,
- port->getAnnounceInterval()) *
- 1000000000.0)));
-}
-
-void PTPMessageSync::processMessage( CommonPort *port )
-{
- EtherPort *eport = dynamic_cast <EtherPort *> (port);
- PTPMessageSync *old_sync;
-
- if (eport == NULL)
- {
- GPTP_LOG_ERROR( "Discarding sync message on wrong port type" );
- _gc = true;
- goto done;
- }
-
- if (port->getPortState() == PTP_DISABLED ) {
- // Do nothing Sync messages should be ignored in this state
- return;
- }
- if (port->getPortState() == PTP_FAULTY) {
- // According to spec recovery is implementation specific
- eport->recoverPort();
- return;
- }
-
- port->incCounter_ieee8021AsPortStatRxSyncCount();
-
-#if CHECK_ASSIST_BIT
- if( flags[PTP_ASSIST_BYTE] & (0x1<<PTP_ASSIST_BIT)) {
-#endif
- old_sync = eport->getLastSync();
-
- if (old_sync != NULL) {
- delete old_sync;
- }
- eport->setLastSync(this);
- _gc = false;
- goto done;
-#if CHECK_ASSIST_BIT
- } else {
- GPTP_LOG_ERROR("PTP assist flag is not set, discarding invalid sync");
- _gc = true;
- goto done;
- }
-#endif
-
- done:
- return;
-}
-
-PTPMessageFollowUp::PTPMessageFollowUp( CommonPort *port ) :
- PTPMessageCommon( port )
-{
- messageType = FOLLOWUP_MESSAGE; /* This is an event message */
- control = FOLLOWUP;
-
- logMeanMessageInterval = port->getSyncInterval();
-
- return;
-}
-
-size_t PTPMessageFollowUp::buildMessage( CommonPort *port, uint8_t *buf_ptr )
-{
- /* Create packet in buf
- Copy in common header */
- messageLength =
- PTP_COMMON_HDR_LENGTH + PTP_FOLLOWUP_LENGTH + sizeof(tlv);
- unsigned char tspec_msg_t = 0;
- Timestamp preciseOriginTimestamp_BE;
-
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- preciseOriginTimestamp_BE.seconds_ms =
- PLAT_htons(preciseOriginTimestamp.seconds_ms);
- preciseOriginTimestamp_BE.seconds_ls =
- PLAT_htonl(preciseOriginTimestamp.seconds_ls);
- preciseOriginTimestamp_BE.nanoseconds =
- PLAT_htonl(preciseOriginTimestamp.nanoseconds);
- /* Copy in v2 sync specific fields */
- memcpy(buf_ptr + PTP_FOLLOWUP_SEC_MS(PTP_FOLLOWUP_OFFSET),
- &(preciseOriginTimestamp_BE.seconds_ms),
- sizeof(preciseOriginTimestamp.seconds_ms));
- memcpy(buf_ptr + PTP_FOLLOWUP_SEC_LS(PTP_FOLLOWUP_OFFSET),
- &(preciseOriginTimestamp_BE.seconds_ls),
- sizeof(preciseOriginTimestamp.seconds_ls));
- memcpy(buf_ptr + PTP_FOLLOWUP_NSEC(PTP_FOLLOWUP_OFFSET),
- &(preciseOriginTimestamp_BE.nanoseconds),
- sizeof(preciseOriginTimestamp.nanoseconds));
-
- /*Change time base indicator to Network Order before sending it*/
- uint16_t tbi_NO = PLAT_htonl(tlv.getGMTimeBaseIndicator());
- tlv.setGMTimeBaseIndicator(tbi_NO);
- tlv.toByteString(buf_ptr + PTP_COMMON_HDR_LENGTH +
- PTP_FOLLOWUP_LENGTH);
-
- port->incCounter_ieee8021AsPortStatTxFollowUpCount();
-
- return PTP_COMMON_HDR_LENGTH + PTP_FOLLOWUP_LENGTH + sizeof(tlv);
-}
-
-bool PTPMessageFollowUp::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- memset(buf_t, 0, 256);
- /* Create packet in buf
- Copy in common header */
- buildMessage(port, buf_ptr);
-
- GPTP_LOG_VERBOSE( "Follow-Up Time: %u seconds(hi)",
- preciseOriginTimestamp.seconds_ms);
- GPTP_LOG_VERBOSE( "Follow-Up Time: %u seconds",
- preciseOriginTimestamp.seconds_ls);
- GPTP_LOG_VERBOSE( "FW-UP Time: %u nanoseconds",
- preciseOriginTimestamp.nanoseconds);
- GPTP_LOG_VERBOSE( "FW-UP Time: %x seconds",
- preciseOriginTimestamp.seconds_ls);
- GPTP_LOG_VERBOSE( "FW-UP Time: %x nanoseconds",
- preciseOriginTimestamp.nanoseconds);
-#ifdef DEBUG
- GPTP_LOG_VERBOSE("Follow-up Dump:");
- for (int i = 0; i < messageLength; ++i) {
- GPTP_LOG_VERBOSE("%d:%02x ", i, (unsigned char)buf_t[i]);
- }
-#endif
-
- port->sendGeneralPort( PTP_ETHERTYPE, buf_t, messageLength,
- MCAST_OTHER, destIdentity );
-
- return true;
-}
-
-void PTPMessageFollowUp::processMessage
-( CommonPort *port, Timestamp sync_arrival )
-{
- uint64_t delay;
- Timestamp system_time(0, 0, 0);
- Timestamp device_time(0, 0, 0);
-
- signed long long local_system_offset;
- signed long long scalar_offset;
-
- FrequencyRatio local_clock_adjustment;
- FrequencyRatio local_system_freq_offset;
- FrequencyRatio master_local_freq_offset;
- int64_t correction;
- int32_t scaledLastGmFreqChange = 0;
- scaledNs scaledLastGmPhaseChange;
-
- port->incCounter_ieee8021AsPortStatRxFollowUpCount();
-
- if (!port->getLinkDelay(&delay))
- {
- GPTP_LOG_ERROR( "Received Follow up but "
- "there is no valid link delay" );
- goto done;
- }
-
- master_local_freq_offset = tlv.getRateOffset();
- master_local_freq_offset /= 1ULL << 41;
- master_local_freq_offset += 1.0;
- master_local_freq_offset /= port->getPeerRateOffset();
-
- correctionField /= 1 << 16;
- correction = (int64_t)
- ((delay * master_local_freq_offset) + correctionField);
-
- if (correction > 0)
- TIMESTAMP_ADD_NS(preciseOriginTimestamp, correction);
- else TIMESTAMP_SUB_NS(preciseOriginTimestamp, -correction);
-
- local_clock_adjustment =
- port->getClock()->
- calcMasterLocalClockRateDifference
- (preciseOriginTimestamp, sync_arrival);
-
- if( local_clock_adjustment == NEGATIVE_TIME_JUMP )
- {
- GPTP_LOG_VERBOSE
- ( "Received Follow Up but preciseOrigintimestamp "
- "indicates negative time jump" );
- goto done;
- }
-
- scalar_offset = TIMESTAMP_TO_NS( sync_arrival );
- scalar_offset -= TIMESTAMP_TO_NS( preciseOriginTimestamp );
-
- GPTP_LOG_VERBOSE( "Followup Correction Field: %lld, Link Delay: %lu",
- correctionField, delay );
- GPTP_LOG_VERBOSE( "FollowUp Scalar = %lld",
- scalar_offset );
-
-
- /* Otherwise synchronize clock with approximate Sync time */
- uint32_t local_clock, nominal_clock_rate;
- uint32_t device_sync_time_offset;
-
- port->getDeviceTime(system_time, device_time, local_clock,
- nominal_clock_rate);
- GPTP_LOG_VERBOSE( "Device Time = %llu,System Time = %llu",
- TIMESTAMP_TO_NS( device_time ),
- TIMESTAMP_TO_NS( system_time ));
-
- /* Adjust local_clock to correspond to sync_arrival */
- device_sync_time_offset = (uint32_t)
- ( TIMESTAMP_TO_NS( device_time ) -
- TIMESTAMP_TO_NS( sync_arrival ));
-
- GPTP_LOG_VERBOSE
- ( "ptp_message::FollowUp::processMessage System time: %u,%u "
- "Device Time: %u,%u",
- system_time.seconds_ls, system_time.nanoseconds,
- device_time.seconds_ls, device_time.nanoseconds);
-
- /*Update information on local status structure.*/
- scaledLastGmFreqChange = (int32_t)
- ((1.0 / local_clock_adjustment - 1.0) * (1ULL << 41));
- scaledLastGmPhaseChange.setLSB(tlv.getRateOffset( ));
- port->getClock()->getFUPStatus()->setScaledLastGmFreqChange
- ( scaledLastGmFreqChange );
- port->getClock()->getFUPStatus()->setScaledLastGmPhaseChange
- ( scaledLastGmPhaseChange );
-
- if( port->getPortState() == PTP_SLAVE )
- {
- /*
- * The sync_count counts the number of sync messages received
- * that influence the time on the device. Since adjustments are
- * only made in the PTP_SLAVE state, increment it here
- */
- port->incSyncCount();
-
- /*
- * Do not call calcLocalSystemClockRateDifference it updates
- * state global to the clock object and if we are master then
- * the network is transitioning to us not being master but
- * the master process is still running locally
- */
- local_system_freq_offset = port->getClock()
- ->calcLocalSystemClockRateDifference
- ( device_time, system_time );
- TIMESTAMP_SUB_NS
- (system_time, (uint64_t)
- (((FrequencyRatio)device_sync_time_offset) /
- local_system_freq_offset));
- local_system_offset =
- TIMESTAMP_TO_NS( system_time ) -
- TIMESTAMP_TO_NS( sync_arrival );
-
- port->getClock()->setMasterOffset
- ( port, scalar_offset, sync_arrival, local_clock_adjustment,
- local_system_offset, system_time, local_system_freq_offset,
- port->getSyncCount(), port->getPdelayCount(),
- port->getPortState(), port->getAsCapable( ));
-
- port->syncDone();
- // Restart the SYNC_RECEIPT timer
- port->startSyncReceiptTimer((unsigned long long)
- (SYNC_RECEIPT_TIMEOUT_MULTIPLIER *
- ((double)pow((double)2, port->getSyncInterval()) *
- 1000000000.0)));
- }
-
- uint16_t lastGmTimeBaseIndicator;
- lastGmTimeBaseIndicator = port->getLastGmTimeBaseIndicator();
- if (( lastGmTimeBaseIndicator > 0 ) &&
- ( tlv.getGmTimeBaseIndicator( ) != lastGmTimeBaseIndicator ))
- {
- GPTP_LOG_EXCEPTION( "Sync discontinuity" );
- }
- port->setLastGmTimeBaseIndicator( tlv.getGmTimeBaseIndicator( ));
-
-done:
- _gc = true;
-
- return;
-}
-
-void PTPMessageFollowUp::processMessage( CommonPort *port )
-{
- Timestamp sync_arrival;
- EtherPort *eport = dynamic_cast <EtherPort *> (port);
- if (eport == NULL)
- {
- GPTP_LOG_ERROR
- ( "Discarding followup message on wrong port type" );
- return;
- }
-
- GPTP_LOG_DEBUG("Processing a follow-up message");
-
- // Expire any SYNC_RECEIPT timers that exist
- port->stopSyncReceiptTimer();
-
- if (port->getPortState() == PTP_DISABLED ) {
- // Do nothing Sync messages should be ignored when in this state
- return;
- }
- if (port->getPortState() == PTP_FAULTY) {
- // According to spec recovery is implementation specific
- eport->recoverPort();
- return;
- }
-
- PTPMessageSync *sync = eport->getLastSync();
- {
- PortIdentity sync_id;
- if( sync == NULL )
- {
- GPTP_LOG_ERROR("Received Follow Up but there is no "
- "sync message");
- return;
- }
- sync->getPortIdentity(&sync_id);
-
- if( sync->getSequenceId() != sequenceId ||
- sync_id != *sourcePortIdentity )
- {
- unsigned int cnt = 0;
-
- if( !port->incWrongSeqIDCounter( &cnt ))
- {
- port->becomeMaster( true );
- port->setWrongSeqIDCounter(0);
- }
- GPTP_LOG_ERROR
- ( "Received Follow Up %d times but cannot "
- "find corresponding Sync", cnt );
- goto done;
- }
- }
-
- if( sync->getTimestamp()._version != port->getTimestampVersion( ))
- {
- GPTP_LOG_ERROR( "Received Follow Up but timestamp version "
- "indicates Sync is out of date" );
- goto done;
- }
-
- sync_arrival = sync->getTimestamp();
-
- processMessage(port, sync_arrival);
-
-done:
- eport->setLastSync(NULL);
- delete sync;
-}
-
-PTPMessagePathDelayReq::PTPMessagePathDelayReq
-( EtherPort *port ) : PTPMessageCommon( port )
-{
- logMeanMessageInterval = 0;
- control = MESSAGE_OTHER;
- messageType = PATH_DELAY_REQ_MESSAGE;
- sequenceId = port->getNextPDelaySequenceId();
- return;
-}
-
-void PTPMessagePathDelayReq::processMessage( CommonPort *port )
-{
- OSTimer *timer = port->getTimerFactory()->createTimer();
- PortIdentity resp_fwup_id;
- PortIdentity requestingPortIdentity_p;
- PTPMessagePathDelayResp *resp;
- PortIdentity resp_id;
- PTPMessagePathDelayRespFollowUp *resp_fwup;
-
- EtherPort *eport = dynamic_cast <EtherPort *> (port);
- if (eport == NULL)
- {
- GPTP_LOG_ERROR( "Received Pdelay Request on wrong port type" );
- goto done;
- }
-
- if (port->getPortState() == PTP_DISABLED) {
- // Do nothing all messages should be ignored when in this state
- goto done;
- }
-
- if (port->getPortState() == PTP_FAULTY) {
- // According to spec recovery is implementation specific
- eport->recoverPort();
- goto done;
- }
-
- port->incCounter_ieee8021AsPortStatRxPdelayRequest();
-
- /* Generate and send message */
- resp = new PTPMessagePathDelayResp(eport);
- port->getPortIdentity(resp_id);
- resp->setPortIdentity(&resp_id);
- resp->setSequenceId(sequenceId);
-
- GPTP_LOG_DEBUG("Process PDelay Request SeqId: %u\t", sequenceId);
-
-#ifdef DEBUG
- for (int n = 0; n < PTP_CLOCK_IDENTITY_LENGTH; ++n) {
- GPTP_LOG_VERBOSE("%c", resp_id.clockIdentity[n]);
- }
-#endif
-
- this->getPortIdentity(&requestingPortIdentity_p);
- resp->setRequestingPortIdentity(&requestingPortIdentity_p);
- resp->setRequestReceiptTimestamp(_timestamp);
-
- port->getTxLock();
- resp->sendPort(eport, sourcePortIdentity);
- GPTP_LOG_DEBUG("*** Sent PDelay Response message");
- port->putTxLock();
-
- if( resp->getTimestamp()._version != _timestamp._version ) {
- GPTP_LOG_ERROR("TX timestamp version mismatch: %u/%u",
- resp->getTimestamp()._version, _timestamp._version);
-#if 0 // discarding the request could lead to the peer setting the link to non-asCapable
- delete resp;
- goto done;
-#endif
- }
-
- resp_fwup = new PTPMessagePathDelayRespFollowUp(eport);
- port->getPortIdentity(resp_fwup_id);
- resp_fwup->setPortIdentity(&resp_fwup_id);
- resp_fwup->setSequenceId(sequenceId);
- resp_fwup->setRequestingPortIdentity(sourcePortIdentity);
- resp_fwup->setResponseOriginTimestamp(resp->getTimestamp());
- long long turnaround;
- turnaround = (resp->getTimestamp().seconds_ls - _timestamp.seconds_ls)
- * 1000000000LL;
-
- GPTP_LOG_VERBOSE("Response Depart(sec): %u",
- resp->getTimestamp().seconds_ls);
- GPTP_LOG_VERBOSE("Request Arrival(sec): %u", _timestamp.seconds_ls);
- GPTP_LOG_VERBOSE("#1 Correction Field: %Ld", turnaround);
-
- turnaround += resp->getTimestamp().nanoseconds;
-
- GPTP_LOG_VERBOSE("#2 Correction Field: %Ld", turnaround);
-
- turnaround -= _timestamp.nanoseconds;
-
- GPTP_LOG_VERBOSE("#3 Correction Field: %Ld", turnaround);
-
- resp_fwup->setCorrectionField(0);
- resp_fwup->sendPort(eport, sourcePortIdentity);
-
- GPTP_LOG_DEBUG("*** Sent PDelay Response FollowUp message");
-
- delete resp;
- delete resp_fwup;
-
-done:
- delete timer;
- _gc = true;
- return;
-}
-
-bool PTPMessagePathDelayReq::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint32_t link_speed;
-
- if(port->pdelayHalted())
- return false;
-
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0;
- memset(buf_t, 0, 256);
- /* Create packet in buf */
- /* Copy in common header */
- messageLength = PTP_COMMON_HDR_LENGTH + PTP_PDELAY_REQ_LENGTH;
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- port->sendEventPort
- ( PTP_ETHERTYPE, buf_t, messageLength, MCAST_PDELAY,
- destIdentity, &link_speed );
- port->incCounter_ieee8021AsPortStatTxPdelayRequest();
-
- return getTxTimestamp( port, link_speed );
-}
-
-PTPMessagePathDelayResp::PTPMessagePathDelayResp
-( EtherPort *port ) : PTPMessageCommon( port )
-{
- /*TODO: Why 0x7F?*/
- logMeanMessageInterval = 0x7F;
- control = MESSAGE_OTHER;
- messageType = PATH_DELAY_RESP_MESSAGE;
- versionPTP = GPTP_VERSION;
- requestingPortIdentity = new PortIdentity();
-
- flags[PTP_ASSIST_BYTE] |= (0x1 << PTP_ASSIST_BIT);
-
- return;
-}
-
-PTPMessagePathDelayResp::~PTPMessagePathDelayResp()
-{
- delete requestingPortIdentity;
-}
-
-void PTPMessagePathDelayResp::processMessage( CommonPort *port )
-{
- EtherPort *eport = dynamic_cast <EtherPort *> (port);
- if (eport == NULL)
- {
- GPTP_LOG_ERROR( "Received Pdelay Resp on wrong port type" );
- _gc = true;
- return;
- }
-
- if (port->getPortState() == PTP_DISABLED) {
- // Do nothing all messages should be ignored when in this state
- return;
- }
- if (port->getPortState() == PTP_FAULTY) {
- // According to spec recovery is implementation specific
- eport->recoverPort();
- return;
- }
-
- port->incCounter_ieee8021AsPortStatRxPdelayResponse();
-
- if (eport->tryPDelayRxLock() != true) {
- GPTP_LOG_ERROR("Failed to get PDelay RX Lock");
- return;
- }
-
- PortIdentity resp_id;
- PortIdentity oldresp_id;
- uint16_t resp_port_number;
- uint16_t oldresp_port_number;
-
- PTPMessagePathDelayResp *old_pdelay_resp = eport->getLastPDelayResp();
- if( old_pdelay_resp == NULL ) {
- goto bypass_verify_duplicate;
- }
-
- old_pdelay_resp->getPortIdentity(&oldresp_id);
- oldresp_id.getPortNumber(&oldresp_port_number);
- getPortIdentity(&resp_id);
- resp_id.getPortNumber(&resp_port_number);
-
- /* In the case where we have multiple PDelay responses for the same
- * PDelay request, and they come from different sources, it is necessary
- * to verify if this happens 3 times (sequentially). If it does, PDelayRequests
- * are halted for 5 minutes
- */
- if( getSequenceId() == old_pdelay_resp->getSequenceId() )
- {
- /*If the duplicates are in sequence and from different sources*/
- if( (resp_port_number != oldresp_port_number ) && (
- (eport->getLastInvalidSeqID() + 1 ) == getSequenceId() ||
- eport->getDuplicateRespCounter() == 0 ) ){
- GPTP_LOG_ERROR("Two responses for same Request. seqID %d. First Response Port# %hu. Second Port# %hu. Counter %d",
- getSequenceId(), oldresp_port_number, resp_port_number, eport->getDuplicateRespCounter());
-
- if( eport->incrementDuplicateRespCounter() ) {
- GPTP_LOG_ERROR("Remote misbehaving. Stopping PDelay Requests for 5 minutes.");
- eport->stopPDelay();
- eport->getClock()->addEventTimerLocked
- (port, PDELAY_RESP_PEER_MISBEHAVING_TIMEOUT_EXPIRES, (int64_t)(300 * 1000000000.0));
- }
- }
- else {
- eport->setDuplicateRespCounter(0);
- }
- eport->setLastInvalidSeqID(getSequenceId());
- }
- else
- {
- eport->setDuplicateRespCounter(0);
- }
-
-bypass_verify_duplicate:
- eport->setLastPDelayResp(this);
-
- if (old_pdelay_resp != NULL) {
- delete old_pdelay_resp;
- }
-
- eport->putPDelayRxLock();
- _gc = false;
-
- return;
-}
-
-bool PTPMessagePathDelayResp::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0;
- Timestamp requestReceiptTimestamp_BE;
- uint32_t link_speed;
-
- memset(buf_t, 0, 256);
- // Create packet in buf
- // Copy in common header
- messageLength = PTP_COMMON_HDR_LENGTH + PTP_PDELAY_RESP_LENGTH;
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- requestReceiptTimestamp_BE.seconds_ms =
- PLAT_htons(requestReceiptTimestamp.seconds_ms);
- requestReceiptTimestamp_BE.seconds_ls =
- PLAT_htonl(requestReceiptTimestamp.seconds_ls);
- requestReceiptTimestamp_BE.nanoseconds =
- PLAT_htonl(requestReceiptTimestamp.nanoseconds);
-
- // Copy in v2 PDelay_Req specific fields
- requestingPortIdentity->getClockIdentityString
- (buf_ptr + PTP_PDELAY_RESP_REQ_CLOCK_ID
- (PTP_PDELAY_RESP_OFFSET));
- requestingPortIdentity->getPortNumberNO
- ((uint16_t *)
- (buf_ptr + PTP_PDELAY_RESP_REQ_PORT_ID
- (PTP_PDELAY_RESP_OFFSET)));
- memcpy(buf_ptr + PTP_PDELAY_RESP_SEC_MS(PTP_PDELAY_RESP_OFFSET),
- &(requestReceiptTimestamp_BE.seconds_ms),
- sizeof(requestReceiptTimestamp.seconds_ms));
- memcpy(buf_ptr + PTP_PDELAY_RESP_SEC_LS(PTP_PDELAY_RESP_OFFSET),
- &(requestReceiptTimestamp_BE.seconds_ls),
- sizeof(requestReceiptTimestamp.seconds_ls));
- memcpy(buf_ptr + PTP_PDELAY_RESP_NSEC(PTP_PDELAY_RESP_OFFSET),
- &(requestReceiptTimestamp_BE.nanoseconds),
- sizeof(requestReceiptTimestamp.nanoseconds));
-
- GPTP_LOG_VERBOSE("PDelay Resp Timestamp: %u,%u",
- requestReceiptTimestamp.seconds_ls,
- requestReceiptTimestamp.nanoseconds);
-
- port->sendEventPort
- ( PTP_ETHERTYPE, buf_t, messageLength, MCAST_PDELAY,
- destIdentity, &link_speed );
- port->incCounter_ieee8021AsPortStatTxPdelayResponse();
-
- return getTxTimestamp( port, link_speed );
-}
-
-void PTPMessagePathDelayResp::setRequestingPortIdentity
-(PortIdentity * identity)
-{
- *requestingPortIdentity = *identity;
-}
-
-void PTPMessagePathDelayResp::getRequestingPortIdentity
-(PortIdentity * identity)
-{
- *identity = *requestingPortIdentity;
-}
-
-PTPMessagePathDelayRespFollowUp::PTPMessagePathDelayRespFollowUp
-( EtherPort *port ) : PTPMessageCommon( port )
-{
- logMeanMessageInterval = 0x7F;
- control = MESSAGE_OTHER;
- messageType = PATH_DELAY_FOLLOWUP_MESSAGE;
- versionPTP = GPTP_VERSION;
- requestingPortIdentity = new PortIdentity();
-
- return;
-}
-
-PTPMessagePathDelayRespFollowUp::~PTPMessagePathDelayRespFollowUp()
-{
- delete requestingPortIdentity;
-}
-
-#define US_PER_SEC 1000000
-void PTPMessagePathDelayRespFollowUp::processMessage
-( CommonPort *port )
-{
- PTPMessagePathDelayReq *req;
- PTPMessagePathDelayResp *resp;
-
- Timestamp remote_resp_tx_timestamp(0, 0, 0);
- Timestamp request_tx_timestamp(0, 0, 0);
- Timestamp remote_req_rx_timestamp(0, 0, 0);
- Timestamp response_rx_timestamp(0, 0, 0);
-
- EtherPort *eport = dynamic_cast <EtherPort *> (port);
- if (eport == NULL)
- {
- GPTP_LOG_ERROR( "Received Pdelay Response FollowUp on wrong "
- "port type" );
- goto abort;
- }
-
- if (port->getPortState() == PTP_DISABLED) {
- // Do nothing all messages should be ignored when in this state
- return;
- }
- if (port->getPortState() == PTP_FAULTY) {
- // According to spec recovery is implementation specific
- eport->recoverPort();
- return;
- }
-
- port->incCounter_ieee8021AsPortStatRxPdelayResponseFollowUp();
-
- if (eport->tryPDelayRxLock() != true)
- return;
-
- req = eport->getLastPDelayReq();
- resp = eport->getLastPDelayResp();
-
- if (req == NULL) {
- /* Shouldn't happen */
- GPTP_LOG_ERROR
- (">>> Received PDelay followup but no REQUEST exists");
- goto abort;
- }
-
- if (resp == NULL) {
- /* Probably shouldn't happen either */
- GPTP_LOG_ERROR
- (">>> Received PDelay followup but no RESPONSE exists");
-
- goto abort;
- }
-
- if( req->getSequenceId() != sequenceId ) {
- GPTP_LOG_ERROR
- ( "Received PDelay FUP has different seqID than the "
- "PDelay request (%d/%d)",
- sequenceId, req->getSequenceId() );
- goto abort;
- }
-
- {
- PortIdentity req_id;
- PortIdentity resp_id;
- uint16_t resp_port_number;
- uint16_t req_port_number;
-
- ClockIdentity resp_clkId = resp_id.getClockIdentity();
- ClockIdentity req_clkId = req_id.getClockIdentity();
- PortIdentity fup_sourcePortIdentity;
- PortIdentity resp_sourcePortIdentity;
-
- req->getPortIdentity(&req_id);
- resp->getRequestingPortIdentity(&resp_id);
-
- resp_id.getPortNumber(&resp_port_number);
- requestingPortIdentity->getPortNumber(&req_port_number);
-
- resp->getPortIdentity(&resp_sourcePortIdentity);
- getPortIdentity(&fup_sourcePortIdentity);
-
- /*
- * IEEE 802.1AS, Figure 11-8, subclause 11.2.15.3
- */
- if (resp->getSequenceId() != sequenceId) {
- GPTP_LOG_ERROR
- ("Received PDelay Response Follow Up but cannot find "
- "corresponding response");
- GPTP_LOG_ERROR( "%hu, %hu, %hu, %hu",
- resp->getSequenceId(), sequenceId,
- resp_port_number, req_port_number );
-
- goto abort;
- }
-
- /*
- * IEEE 802.1AS, Figure 11-8, subclause 11.2.15.3
- */
- if (req_clkId != resp_clkId) {
- GPTP_LOG_ERROR
- ( "ClockID Resp/Req differs. PDelay Response ClockID: "
- "%s PDelay Request ClockID: %s",
- req_clkId.getIdentityString().c_str(),
- resp_clkId.getIdentityString().c_str( ));
- goto abort;
- }
-
- /*
- * IEEE 802.1AS, Figure 11-8, subclause 11.2.15.3
- */
- if (resp_port_number != req_port_number) {
- GPTP_LOG_ERROR
- ( "Request port number (%hu) is different from "
- "Response port number (%hu)",
- req_port_number, resp_port_number );
-
- goto abort;
- }
-
- /*
- * IEEE 802.1AS, Figure 11-8, subclause 11.2.15.3
- */
- if (fup_sourcePortIdentity != resp_sourcePortIdentity) {
- GPTP_LOG_ERROR( "Source port identity from "
- "PDelay Response/FUP differ" );
-
- goto abort;
- }
- }
-
- port->getClock()->deleteEventTimerLocked
- (port, PDELAY_RESP_RECEIPT_TIMEOUT_EXPIRES);
-
- GPTP_LOG_VERBOSE("Request Sequence Id: %u", req->getSequenceId());
- GPTP_LOG_VERBOSE("Response Sequence Id: %u", resp->getSequenceId());
- GPTP_LOG_VERBOSE("Follow-Up Sequence Id: %u", sequenceId);
-
- int64_t link_delay;
- unsigned long long turn_around;
-
- /* Assume that we are a two step clock, otherwise originTimestamp
- may be used */
- request_tx_timestamp = req->getTimestamp();
- if( request_tx_timestamp.nanoseconds == INVALID_TIMESTAMP.nanoseconds )
- {
- /* Stop processing the packet */
- goto abort;
- }
-
- if (request_tx_timestamp.nanoseconds ==
- PDELAY_PENDING_TIMESTAMP.nanoseconds) {
- // Defer processing
- if(
- eport->getLastPDelayRespFollowUp() != NULL &&
- eport->getLastPDelayRespFollowUp() != this )
- {
- delete eport->getLastPDelayRespFollowUp();
- }
- eport->setLastPDelayRespFollowUp(this);
- port->getClock()->addEventTimerLocked
- (port, PDELAY_DEFERRED_PROCESSING, 1000000);
- goto defer;
- }
- remote_req_rx_timestamp = resp->getRequestReceiptTimestamp();
- response_rx_timestamp = resp->getTimestamp();
- remote_resp_tx_timestamp = responseOriginTimestamp;
-
- if( request_tx_timestamp._version != response_rx_timestamp._version ) {
- GPTP_LOG_ERROR("RX timestamp version mismatch %d/%d",
- request_tx_timestamp._version, response_rx_timestamp._version );
- goto abort;
- }
-
- port->incPdelayCount();
-
-
- link_delay =
- ((response_rx_timestamp.seconds_ms * 1LL -
- request_tx_timestamp.seconds_ms) << 32) * 1000000000;
- link_delay +=
- (response_rx_timestamp.seconds_ls * 1LL -
- request_tx_timestamp.seconds_ls) * 1000000000;
- link_delay +=
- (response_rx_timestamp.nanoseconds * 1LL -
- request_tx_timestamp.nanoseconds);
-
- turn_around =
- ((remote_resp_tx_timestamp.seconds_ms * 1LL -
- remote_req_rx_timestamp.seconds_ms) << 32) * 1000000000;
- turn_around +=
- (remote_resp_tx_timestamp.seconds_ls * 1LL -
- remote_req_rx_timestamp.seconds_ls) * 1000000000;
- turn_around +=
- (remote_resp_tx_timestamp.nanoseconds * 1LL -
- remote_req_rx_timestamp.nanoseconds);
-
- // Adjust turn-around time for peer to local clock rate difference
- // TODO: Are these .998 and 1.002 specifically defined in the standard?
- // Should we create a define for them ?
- if
- ( port->getPeerRateOffset() > .998 &&
- port->getPeerRateOffset() < 1.002 ) {
- turn_around = (int64_t)
- (turn_around * port->getPeerRateOffset());
- }
-
- GPTP_LOG_VERBOSE
- ("Turn Around Adjustment %Lf",
- ((long long)turn_around * port->getPeerRateOffset()) /
- 1000000000000LL);
- GPTP_LOG_VERBOSE
- ("Step #1: Turn Around Adjustment %Lf",
- ((long long)turn_around * port->getPeerRateOffset()));
- GPTP_LOG_VERBOSE("Adjusted Peer turn around is %Lu", turn_around);
-
- /* Subtract turn-around time from link delay after rate adjustment */
- link_delay -= turn_around;
- link_delay /= 2;
- GPTP_LOG_DEBUG( "Link delay: %ld ns", link_delay );
-
- {
- uint64_t mine_elapsed;
- uint64_t theirs_elapsed;
- Timestamp prev_peer_ts_mine;
- Timestamp prev_peer_ts_theirs;
- FrequencyRatio rate_offset;
- if( port->getPeerOffset( prev_peer_ts_mine, prev_peer_ts_theirs )) {
- FrequencyRatio upper_ratio_limit, lower_ratio_limit;
- upper_ratio_limit =
- PPM_OFFSET_TO_RATIO(UPPER_LIMIT_PPM);
- lower_ratio_limit =
- PPM_OFFSET_TO_RATIO(LOWER_LIMIT_PPM);
-
- mine_elapsed = TIMESTAMP_TO_NS(request_tx_timestamp) -
- TIMESTAMP_TO_NS(prev_peer_ts_mine);
- theirs_elapsed =
- TIMESTAMP_TO_NS(remote_req_rx_timestamp) -
- TIMESTAMP_TO_NS(prev_peer_ts_theirs);
- theirs_elapsed -= port->getLinkDelay();
- theirs_elapsed += link_delay < 0 ? 0 : link_delay;
- rate_offset = ((FrequencyRatio) mine_elapsed)
- / theirs_elapsed;
-
- if( rate_offset < upper_ratio_limit &&
- rate_offset > lower_ratio_limit )
- port->setPeerRateOffset(rate_offset);
- }
- }
- if( !port->setLinkDelay( link_delay ))
- {
- if( !eport->getAutomotiveProfile( ))
- {
- GPTP_LOG_ERROR( "Link delay %ld beyond "
- "neighborPropDelayThresh; "
- "not AsCapable", link_delay );
- port->setAsCapable( false );
- }
- } else
- {
- if( !eport->getAutomotiveProfile( ))
- port->setAsCapable( true );
- }
- port->setPeerOffset( request_tx_timestamp, remote_req_rx_timestamp );
-
- abort:
- delete resp;
- eport->setLastPDelayResp(NULL);
-
- _gc = true;
-
- defer:
- eport->putPDelayRxLock();
-
- return;
-}
-
-bool PTPMessagePathDelayRespFollowUp::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0;
- Timestamp responseOriginTimestamp_BE;
- memset(buf_t, 0, 256);
- /* Create packet in buf
- Copy in common header */
- messageLength = PTP_COMMON_HDR_LENGTH + PTP_PDELAY_RESP_LENGTH;
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
- responseOriginTimestamp_BE.seconds_ms =
- PLAT_htons(responseOriginTimestamp.seconds_ms);
- responseOriginTimestamp_BE.seconds_ls =
- PLAT_htonl(responseOriginTimestamp.seconds_ls);
- responseOriginTimestamp_BE.nanoseconds =
- PLAT_htonl(responseOriginTimestamp.nanoseconds);
-
- // Copy in v2 PDelay_Req specific fields
- requestingPortIdentity->getClockIdentityString
- (buf_ptr + PTP_PDELAY_FOLLOWUP_REQ_CLOCK_ID
- (PTP_PDELAY_FOLLOWUP_OFFSET));
- requestingPortIdentity->getPortNumberNO
- ((uint16_t *)
- (buf_ptr + PTP_PDELAY_FOLLOWUP_REQ_PORT_ID
- (PTP_PDELAY_FOLLOWUP_OFFSET)));
- memcpy
- (buf_ptr + PTP_PDELAY_FOLLOWUP_SEC_MS(PTP_PDELAY_FOLLOWUP_OFFSET),
- &(responseOriginTimestamp_BE.seconds_ms),
- sizeof(responseOriginTimestamp.seconds_ms));
- memcpy
- (buf_ptr + PTP_PDELAY_FOLLOWUP_SEC_LS(PTP_PDELAY_FOLLOWUP_OFFSET),
- &(responseOriginTimestamp_BE.seconds_ls),
- sizeof(responseOriginTimestamp.seconds_ls));
- memcpy
- (buf_ptr + PTP_PDELAY_FOLLOWUP_NSEC(PTP_PDELAY_FOLLOWUP_OFFSET),
- &(responseOriginTimestamp_BE.nanoseconds),
- sizeof(responseOriginTimestamp.nanoseconds));
-
- GPTP_LOG_VERBOSE("PDelay Resp Timestamp: %u,%u",
- responseOriginTimestamp.seconds_ls,
- responseOriginTimestamp.nanoseconds);
-
- port->sendGeneralPort(PTP_ETHERTYPE, buf_t, messageLength, MCAST_PDELAY, destIdentity);
- port->incCounter_ieee8021AsPortStatTxPdelayResponseFollowUp();
-
- return true;
-}
-
-void PTPMessagePathDelayRespFollowUp::setRequestingPortIdentity
-(PortIdentity * identity)
-{
- *requestingPortIdentity = *identity;
-}
-
-
- PTPMessageSignalling::PTPMessageSignalling(void)
-{
-}
-
-PTPMessageSignalling::PTPMessageSignalling
-( EtherPort *port ) : PTPMessageCommon( port )
-{
- messageType = SIGNALLING_MESSAGE;
- sequenceId = port->getNextSignalSequenceId();
-
- targetPortIdentify = (int8_t)0xff;
-
- control = MESSAGE_OTHER;
-
- logMeanMessageInterval = 0x7F; // 802.1AS 2011 10.5.2.2.11 logMessageInterval (Integer8)
-}
-
- PTPMessageSignalling::~PTPMessageSignalling(void)
-{
-}
-
-void PTPMessageSignalling::setintervals(int8_t linkDelayInterval, int8_t timeSyncInterval, int8_t announceInterval)
-{
- tlv.setLinkDelayInterval(linkDelayInterval);
- tlv.setTimeSyncInterval(timeSyncInterval);
- tlv.setAnnounceInterval(announceInterval);
-}
-
-bool PTPMessageSignalling::sendPort
-( EtherPort *port, PortIdentity *destIdentity )
-{
- uint8_t buf_t[256];
- uint8_t *buf_ptr = buf_t + port->getPayloadOffset();
- unsigned char tspec_msg_t = 0x0;
-
- memset(buf_t, 0, 256);
- // Create packet in buf
- // Copy in common header
- messageLength = PTP_COMMON_HDR_LENGTH + PTP_SIGNALLING_LENGTH + sizeof(tlv);
- tspec_msg_t |= messageType & 0xF;
- buildCommonHeader(buf_ptr);
-
- memcpy(buf_ptr + PTP_SIGNALLING_TARGET_PORT_IDENTITY(PTP_SIGNALLING_OFFSET),
- &targetPortIdentify, sizeof(targetPortIdentify));
-
- tlv.toByteString(buf_ptr + PTP_COMMON_HDR_LENGTH + PTP_SIGNALLING_LENGTH);
-
- port->sendGeneralPort(PTP_ETHERTYPE, buf_t, messageLength, MCAST_OTHER, destIdentity);
-
- return true;
-}
-
-void PTPMessageSignalling::processMessage( CommonPort *port )
-{
- long long unsigned int waitTime;
-
- GPTP_LOG_STATUS("Signalling Link Delay Interval: %d", tlv.getLinkDelayInterval());
- GPTP_LOG_STATUS("Signalling Sync Interval: %d", tlv.getTimeSyncInterval());
- GPTP_LOG_STATUS("Signalling Announce Interval: %d", tlv.getAnnounceInterval());
-
- char linkDelayInterval = tlv.getLinkDelayInterval();
- char timeSyncInterval = tlv.getTimeSyncInterval();
- char announceInterval = tlv.getAnnounceInterval();
-
- if (linkDelayInterval == PTPMessageSignalling::sigMsgInterval_Initial) {
- port->resetInitPDelayInterval();
-
- waitTime = ((long long) (pow((double)2, port->getPDelayInterval()) * 1000000000.0));
- waitTime = waitTime > EVENT_TIMER_GRANULARITY ? waitTime : EVENT_TIMER_GRANULARITY;
- port->startPDelayIntervalTimer(waitTime);
- }
- else if (linkDelayInterval == PTPMessageSignalling::sigMsgInterval_NoSend) {
- // TODO: No send functionality needs to be implemented.
- GPTP_LOG_WARNING("Signal received to stop sending pDelay messages: Not implemented");
- }
- else if (linkDelayInterval == PTPMessageSignalling::sigMsgInterval_NoChange) {
- // Nothing to do
- }
- else {
- port->setPDelayInterval(linkDelayInterval);
-
- waitTime = ((long long) (pow((double)2, port->getPDelayInterval()) * 1000000000.0));
- waitTime = waitTime > EVENT_TIMER_GRANULARITY ? waitTime : EVENT_TIMER_GRANULARITY;
- port->startPDelayIntervalTimer(waitTime);
- }
-
- if (timeSyncInterval == PTPMessageSignalling::sigMsgInterval_Initial) {
- port->resetInitSyncInterval();
-
- waitTime = ((long long) (pow((double)2, port->getSyncInterval()) * 1000000000.0));
- waitTime = waitTime > EVENT_TIMER_GRANULARITY ? waitTime : EVENT_TIMER_GRANULARITY;
- port->startSyncIntervalTimer(waitTime);
- }
- else if (timeSyncInterval == PTPMessageSignalling::sigMsgInterval_NoSend) {
- // TODO: No send functionality needs to be implemented.
- GPTP_LOG_WARNING("Signal received to stop sending Sync messages: Not implemented");
- }
- else if (timeSyncInterval == PTPMessageSignalling::sigMsgInterval_NoChange) {
- // Nothing to do
- }
- else {
- port->setSyncInterval(timeSyncInterval);
-
- waitTime = ((long long) (pow((double)2, port->getSyncInterval()) * 1000000000.0));
- waitTime = waitTime > EVENT_TIMER_GRANULARITY ? waitTime : EVENT_TIMER_GRANULARITY;
- port->startSyncIntervalTimer(waitTime);
- }
-
- if (!port->getAutomotiveProfile()) {
- if (announceInterval == PTPMessageSignalling::sigMsgInterval_Initial) {
- // TODO: Needs implementation
- GPTP_LOG_WARNING("Signal received to set Announce message to initial interval: Not implemented");
- }
- else if (announceInterval == PTPMessageSignalling::sigMsgInterval_NoSend) {
- // TODO: No send functionality needs to be implemented.
- GPTP_LOG_WARNING("Signal received to stop sending Announce messages: Not implemented");
- }
- else if (announceInterval == PTPMessageSignalling::sigMsgInterval_NoChange) {
- // Nothing to do
- }
- else {
- port->setAnnounceInterval(announceInterval);
-
- waitTime = ((long long) (pow((double)2, port->getAnnounceInterval()) * 1000000000.0));
- waitTime = waitTime > EVENT_TIMER_GRANULARITY ? waitTime : EVENT_TIMER_GRANULARITY;
- port->startAnnounceIntervalTimer(waitTime);
- }
- }
-}
diff --git a/daemons/gptp/common/ptptypes.hpp b/daemons/gptp/common/ptptypes.hpp
deleted file mode 100644
index f73c8f92..00000000
--- a/daemons/gptp/common/ptptypes.hpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/******************************************************************************
-
- Copyright (c) 2009-2012, Intel Corporation
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of the Intel Corporation nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef PTP_TYPES_HPP
-#define PTP_TYPES_HPP
-
-/**@file*/
-
-#if defined(__clang__) && defined(__x86_64__)
-// Clang/llvm has incompatible long double (fp128) for x86_64.
-typedef double FrequencyRatio; /*!< Frequency Ratio */
-#else
-typedef long double FrequencyRatio; /*!< Frequency Ratio */
-#endif
-
-#define ETHER_HDR_LEN (14)
-#define ETHER_ADDR_OCTETS 6 /*!< Number of octets in a link layer address*/
-#define IP_ADDR_OCTETS 4 /*!< Number of octets in a ip address*/
-#define PTP_ETHERTYPE 0x88F7 /*!< PTP ethertype */
-#define AVTP_ETHERTYPE 0x22F0 /*!< AVTP ethertype used for Test Status Message */
-
-#define PTP_CLOCK_IDENTITY_LENGTH 8 /*!< Size of a clock identifier stored in the ClockIndentity class, described at IEEE 802.1AS-2011 Clause 8.5.2.4*/
-
-/**
- * @brief PortState enumeration
- */
-typedef enum {
- PTP_MASTER = 7, //!< Port is PTP Master
- PTP_PRE_MASTER, //!< Port is not PTP Master yet.
- PTP_SLAVE, //!< Port is PTP Slave
- PTP_UNCALIBRATED, //!< Port is uncalibrated.
- PTP_DISABLED, //!< Port is not PTP enabled. All messages are ignored when in this state.
- PTP_FAULTY, //!< Port is in a faulty state. Recovery is implementation specific.
- PTP_INITIALIZING, //!< Port's initial state.
- PTP_LISTENING //!< Port is in a PTP listening state. Currently not in use.
-} PortState;
-
-#endif/*PTP_TYPES_HPP*/
diff --git a/daemons/gptp/common/wireless_port.cpp b/daemons/gptp/common/wireless_port.cpp
deleted file mode 100644
index 40db5015..00000000
--- a/daemons/gptp/common/wireless_port.cpp
+++ /dev/null
@@ -1,242 +0,0 @@
-/******************************************************************************
-
-Copyright (c) 2009-2015, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the Intel Corporation nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <wireless_port.hpp>
-#include <wireless_tstamper.hpp>
-#include <avbts_clock.hpp>
-
-WirelessPort::~WirelessPort()
-{
- // Intentionally left blank
-}
-
-WirelessPort::WirelessPort( PortInit_t *portInit, LinkLayerAddress peer_addr )
-: CommonPort( portInit )
-{
- this->peer_addr = peer_addr;
-
- setAsCapable( true );
- if ( getInitSyncInterval() == LOG2_INTERVAL_INVALID )
- setInitSyncInterval (-3 ); // 125 ms
- if ( getInitPDelayInterval() == LOG2_INTERVAL_INVALID )
- setInitPDelayInterval( 127 ); // 1 second
-
- prev_dialog.dialog_token = 0;
-}
-
-bool WirelessPort::_init_port(void)
-{
- port_ready_condition = condition_factory->createCondition();
-
- return true;
-}
-
-bool WirelessPort::_processEvent( Event e )
-{
- bool ret;
-
- switch (e)
- {
- default:
- GPTP_LOG_ERROR
- ("Unhandled event type in "
- "WirelessPort::processEvent(), %d", e);
- ret = false;
- break;
-
- case POWERUP:
- case INITIALIZE:
- {
- port_ready_condition->wait_prelock();
-
- if ( !linkOpen(_openPort, (void *)this ))
- {
- GPTP_LOG_ERROR( "Error creating port thread" );
- ret = false;
- break;
- }
-
- port_ready_condition->wait();
-
- ret = true;
- break;
- }
-
- case SYNC_INTERVAL_TIMEOUT_EXPIRES:
- {
- WirelessTimestamper *timestamper =
- dynamic_cast<WirelessTimestamper *>( _hw_timestamper );
- PTPMessageFollowUp *follow_up;
- PortIdentity dest_id;
- uint16_t seq;
- uint8_t buffer[128];
- size_t length;
-
- memset(buffer, 0, sizeof( buffer ));
-
- if( prev_dialog.dialog_token != 0 )
- {
- follow_up = new PTPMessageFollowUp( this );
-
- getPortIdentity(dest_id);
- follow_up->setPortIdentity(&dest_id);
- follow_up->setSequenceId(prev_dialog.fwup_seq);
- follow_up->setPreciseOriginTimestamp
- ( prev_dialog.action );
- length = follow_up->buildMessage
- (this, buffer + timestamper->getFwUpOffset());
-
- delete follow_up;
- }
-
- seq = getNextSyncSequenceId();
- ret = timestamper->requestTimingMeasurement
- ( &peer_addr, seq, &prev_dialog, buffer, (int)length )
- == net_succeed;
-
- ret = true;
- break;
- }
-
- case ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES:
- case SYNC_RECEIPT_TIMEOUT_EXPIRES:
- ret = false;
- break;
-
- case STATE_CHANGE_EVENT:
- ret = false;
- break;
- }
-
- return ret;
-}
-
-bool WirelessPort::openPort()
-{
- port_ready_condition->signal();
-
- while (true)
- {
- uint8_t buf[128];
- LinkLayerAddress remote;
- net_result rrecv;
- size_t length = sizeof(buf);
- uint32_t link_speed;
-
- if(( rrecv = recv( &remote, buf, length, link_speed ))
- == net_succeed )
- {
- processMessage
- ((char *)buf, (int)length, &remote, link_speed );
- }
- else if( rrecv == net_fatal )
- {
- GPTP_LOG_ERROR( "read from network interface failed" );
- this->processEvent( FAULT_DETECTED );
- break;
- }
- }
-
- return false;
-}
-
-void WirelessPort::sendGeneralPort
-(uint16_t etherType, uint8_t * buf, int len, MulticastType mcast_type,
- PortIdentity * destIdentity)
-{
- net_result rtx = send( &peer_addr, etherType, buf, len, false);
- if( rtx != net_succeed )
- GPTP_LOG_ERROR( "sendGeneralPort(): failure" );
-
- return;
-}
-
-void WirelessPort::processMessage
-(char *buf, int length, LinkLayerAddress *remote, uint32_t link_speed)
-{
- GPTP_LOG_VERBOSE( "Processing network buffer" );
-
- PTPMessageCommon *msg =
- buildPTPMessage( buf, (int)length, remote, this );
-
- if( msg == NULL )
- {
- GPTP_LOG_ERROR( "Discarding invalid message" );
- return;
- }
- GPTP_LOG_VERBOSE( "Processing message" );
-
- if( !msg->isEvent( ))
- {
- msg->processMessage( this );
- } else
- {
- GPTP_LOG_ERROR( "Received event message on port "
- "incapable of processing" );
- msg->PTPMessageCommon::processMessage( this );
- }
-
- if (msg->garbage())
- delete msg;
-}
-
-void WirelessPort::becomeSlave(bool restart_syntonization)
-{
- clock->deleteEventTimerLocked(this, ANNOUNCE_INTERVAL_TIMEOUT_EXPIRES);
- clock->deleteEventTimerLocked( this, SYNC_INTERVAL_TIMEOUT_EXPIRES );
-
- setPortState( PTP_SLAVE );
-
- GPTP_LOG_STATUS("Switching to Slave");
- if( restart_syntonization ) clock->newSyntonizationSetPoint();
-
- getClock()->updateFUPInfo();
-}
-
-void WirelessPort::becomeMaster(bool annc)
-{
- setPortState( PTP_MASTER );
- // Stop announce receipt timeout timer
- clock->deleteEventTimerLocked( this, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES);
-
- // Stop sync receipt timeout timer
- stopSyncReceiptTimer();
-
- if (annc)
- startAnnounce();
-
- startSyncIntervalTimer( 16000000 );
- GPTP_LOG_STATUS( "Switching to Master" );
-
- clock->updateFUPInfo();
-}
diff --git a/daemons/gptp/common/wireless_port.hpp b/daemons/gptp/common/wireless_port.hpp
deleted file mode 100644
index bfffbd47..00000000
--- a/daemons/gptp/common/wireless_port.hpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/******************************************************************************
-
-Copyright (c) 2009-2015, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the Intel Corporation nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef WIRELESS_PORT_HPP
-#define WIRELESS_PORT_HPP
-
-#include <common_port.hpp>
-#include <avbts_oscondition.hpp>
-
-class WirelessDialog
-{
-public:
- Timestamp action;
- uint64_t action_devclk;
- Timestamp ack;
- uint64_t ack_devclk;
- uint8_t dialog_token;
- uint16_t fwup_seq;
-
- WirelessDialog( uint32_t action, uint32_t ack, uint8_t dialog_token )
- {
- this->action_devclk = action; this->ack_devclk = ack;
- this->dialog_token = dialog_token;
- }
-
- WirelessDialog() { dialog_token = 0; }
-
- WirelessDialog & operator=( const WirelessDialog & a )
- {
- if (this != &a)
- {
- this->ack = a.ack;
- this->ack_devclk = a.ack_devclk;
- this->action = a.action;
- this->action_devclk = a.action_devclk;
- this->dialog_token = a.dialog_token;
- this->fwup_seq = a.fwup_seq;
- }
- return *this;
- }
-};
-
-class WirelessPort : public CommonPort
-{
-private:
- OSCondition *port_ready_condition;
- LinkLayerAddress peer_addr;
- WirelessDialog prev_dialog;
-
-public:
- WirelessPort( PortInit_t *portInit, LinkLayerAddress peer_addr );
- virtual ~WirelessPort();
-
- /**
- * @brief Media specific port initialization
- * @return true on success
- */
- bool _init_port( void );
-
- /**
- * @brief Perform media specific event handling action
- * @return true if event is handled without errors
- */
- bool _processEvent( Event e );
-
- /**
- * @brief Process message
- * @param buf [in] Pointer to the data buffer
- * @param length Size of the message
- * @param remote [in] source address of message
- * @param link_speed [in] for receive operation
- * @return void
- */
- void processMessage
- (char *buf, int length, LinkLayerAddress *remote, uint32_t link_speed);
-
- /**
- * @brief Sends a general message to a port. No timestamps
- * @param buf [in] Pointer to the data buffer
- * @param len Size of the message
- * @param mcast_type Enumeration
- * MulticastType (pdelay, none or other). Depracated.
- * @param destIdentity Destination port identity
- * @return void
- */
- void sendGeneralPort
- ( uint16_t etherType, uint8_t * buf, int len, MulticastType mcast_type,
- PortIdentity * destIdentity );
-
- /**
- * @brief Nothing required for wireless port
- */
- void syncDone() {}
-
- /**
- * @brief Switches port to a gPTP master
- * @param annc If TRUE, starts announce event timer.
- * @return void
- */
- void becomeMaster( bool annc );
-
- /**
- * @brief Switches port to a gPTP slave.
- * @param restart_syntonization if TRUE, restarts the syntonization
- * @return void
- */
- void becomeSlave( bool restart_syntonization );
-
- /**
- * @brief Receives messages from the network interface
- * @return Its an infinite loop. Returns false in case of error.
- */
- bool openPort();
-
- /**
- * @brief Wraps open port method for argument to thread
- * @param larg pointer to WirelessPort object
- * @return thread exit code
- */
- static OSThreadExitCode _openPort( void *larg )
- {
- WirelessPort *port = (decltype(port))larg;
-
- if (!port->openPort())
- return osthread_error;
-
- return osthread_ok;
- }
-
- /**
- * @brief Sets previous dialog
- * @param dialog new value of prev_dialog
- */
- void setPrevDialog( WirelessDialog *dialog )
- {
- prev_dialog = *dialog;
- }
-
- /**
- * @brief Sets previous dialog
- * @return reference to prev_dialog
- */
- WirelessDialog *getPrevDialog( void )
- {
- return &prev_dialog;
- }
-};
-
-#endif/*WIRELESS_PORT_HPP*/
diff --git a/daemons/gptp/common/wireless_tstamper.cpp b/daemons/gptp/common/wireless_tstamper.cpp
deleted file mode 100644
index 10c3be06..00000000
--- a/daemons/gptp/common/wireless_tstamper.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/******************************************************************************
-
-Copyright (c) 2009-2015, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the Intel Corporation nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#include <wireless_tstamper.hpp>
-#include <wireless_port.hpp>
-
-net_result WirelessTimestamper::requestTimingMeasurement
-( LinkLayerAddress *dest, uint16_t seq, WirelessDialog *prev_dialog,
- uint8_t *follow_up, int followup_length )
-{
- WirelessDialog next_dialog;
- net_result retval;
- TIMINGMSMT_REQUEST *req;
-
- // Valid dialog token > 0 && < 256
- next_dialog.dialog_token = (seq % MAX_DIALOG_TOKEN) + 1;
- next_dialog.fwup_seq = seq;
- next_dialog.action_devclk = 0;
- req = (TIMINGMSMT_REQUEST *)follow_up;
-
- // File in request
- req->DialogToken = next_dialog.dialog_token;
- req->FollowUpDialogToken = prev_dialog->dialog_token;
- req->Category = 0x0;
- req->Action = 0x0;
- req->WiFiVSpecHdr.ElementId = FWUP_VDEF_TAG;
- req->WiFiVSpecHdr.Length = 0;
- if( req->FollowUpDialogToken != 0 && prev_dialog->action_devclk != 0 )
- {
- req->T1 = (uint32_t)prev_dialog->action_devclk;
- req->T4 = (uint32_t)prev_dialog->ack_devclk;
- req->WiFiVSpecHdr.Length = followup_length +
- (uint8_t)sizeof(FwUpLabel); // 1 byte type
- req->PtpSpec.FwUpLabel = FwUpLabel;
- }
- dest->toOctetArray(req->PeerMACAddress);
-
- retval = _requestTimingMeasurement( req );
- port->setPrevDialog(&next_dialog);
-
- return retval;
-}
-
-void WirelessTimestamper::timingMeasurementConfirmCB
-( LinkLayerAddress addr, WirelessDialog *dialog )
-{
- WirelessDialog *prev_dialog = port->getPrevDialog();
-
- // Translate action dev clock to Timestamp
- // ACK timestamp isn't needed
- dialog->action.set64(dialog->action_devclk*10);
-
- if (dialog->dialog_token == prev_dialog->dialog_token)
- {
- dialog->fwup_seq = prev_dialog->fwup_seq;
- port->setPrevDialog(dialog);
- }
-}
-
-void WirelessTimestamper::timeMeasurementIndicationCB
-( LinkLayerAddress addr, WirelessDialog *current, WirelessDialog *previous,
- uint8_t *buf, size_t buflen )
-{
- uint64_t link_delay;
- WirelessDialog *prev_local;
- PTPMessageCommon *msg;
- PTPMessageFollowUp *fwup;
- // Translate devclk scalar to Timestamp
-
- msg = buildPTPMessage((char *)buf, (int)buflen, &addr, port);
- fwup = dynamic_cast<PTPMessageFollowUp *> (msg);
- current->action_devclk *= 10;
- current->ack_devclk *= 10;
- current->action.set64(current->action_devclk);
- prev_local = port->getPrevDialog();
- if ( previous->dialog_token == prev_local->dialog_token &&
- fwup != NULL && previous->action_devclk != 0)
- {
- previous->action_devclk *= 10;
- previous->ack_devclk *= 10;
- unsigned round_trip = (unsigned)
- (previous->ack_devclk - previous->action_devclk);
- unsigned turn_around = (unsigned)
- (prev_local->ack_devclk - prev_local->action_devclk);
- link_delay = (round_trip - turn_around) / 2;
- port->setLinkDelay(link_delay);
- GPTP_LOG_VERBOSE( "Link Delay = %llu(RT=%u,TA=%u,"
- "T4=%llu,T1=%llu,DT=%hhu)",
- link_delay, round_trip, turn_around,
- previous->ack_devclk,
- previous->action_devclk,
- previous->dialog_token);
- fwup->processMessage(port, prev_local->action);
- }
-
- port->setPrevDialog(current);
-}
diff --git a/daemons/gptp/common/wireless_tstamper.hpp b/daemons/gptp/common/wireless_tstamper.hpp
deleted file mode 100644
index 79413d0d..00000000
--- a/daemons/gptp/common/wireless_tstamper.hpp
+++ /dev/null
@@ -1,221 +0,0 @@
-/******************************************************************************
-
-Copyright (c) 2009-2015, Intel Corporation
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
-
-3. Neither the name of the Intel Corporation nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-******************************************************************************/
-
-#ifndef WIRELESS_TSTAMPER_HPP
-#define WIRELESS_TSTAMPER_HPP
-
-#include <common_tstamper.hpp>
-#include <wireless_port.hpp>
-
-#define MAX_DIALOG_TOKEN 255
-#define OUI_8021AS_OCTETS { 0x00, 0x80, 0xC2 }
-static const uint8_t OUI_8021AS[] = OUI_8021AS_OCTETS;
-#define FWUP_TYPE 0
-#define FWUP_VDEF_TAG 0xDD /* Vendor Defined Tag */
-
-typedef enum _WIRELESS_EVENT_TYPE
-{
- TIMINGMSMT_EVENT = 0,
- TIMINGMSMT_CONFIRM_EVENT,
- TIMINGMSMT_CORRELATEDTIME_EVENT,
-} WIRELESS_EVENT_TYPE;
-
-#pragma pack(push, 1)
-typedef struct
-{
- uint8_t oui[sizeof(OUI_8021AS)];
- uint8_t type;
-} FwUpLabel_t;
-
-typedef struct _PTP_SPEC
-{
- FwUpLabel_t FwUpLabel;
- uint8_t fwup_data[1];
-} PTP_SPEC;
-
-static const FwUpLabel_t FwUpLabel = { OUI_8021AS_OCTETS, FWUP_TYPE };
-
-typedef struct _WIFI_VENDOR_SPEC_HDR
-{
- uint8_t ElementId;
- uint8_t Length;
-} WIFI_VENDOR_SPEC_HDR;
-#pragma pack(pop)
-
-typedef struct _TIMINGMSMT_REQUEST
-{
- uint8_t PeerMACAddress[ETHER_ADDR_OCTETS];
- uint8_t Category;
- uint8_t Action;
- uint8_t DialogToken;
- uint8_t FollowUpDialogToken;
- uint32_t T1;
- uint32_t T4;
- uint8_t MaxT1Error;
- uint8_t MaxT4Error;
-
- WIFI_VENDOR_SPEC_HDR WiFiVSpecHdr;
- PTP_SPEC PtpSpec;
-} TIMINGMSMT_REQUEST;
-
-typedef struct _TIMINGMSMT_EVENT_DATA
-{
- uint8_t PeerMACAddress[ETHER_ADDR_OCTETS];
- uint32_t DialogToken;
- uint32_t FollowUpDialogToken;
- uint64_t T1;
- uint32_t MaxT1Error;
- uint64_t T4;
- uint32_t MaxT4Error;
- uint64_t T2;
- uint32_t MaxT2Error;
- uint64_t T3;
- uint32_t MaxT3Error;
-
- WIFI_VENDOR_SPEC_HDR WiFiVSpecHdr;
- PTP_SPEC PtpSpec;
-} TIMINGMSMT_EVENT_DATA;
-
-typedef struct _TIMINGMSMT_CONFIRM_EVENT_DATA
-{
- uint8_t PeerMACAddress[ETHER_ADDR_OCTETS];
- uint32_t DialogToken;
- uint64_t T1;
- uint32_t MaxT1Error;
- uint64_t T4;
- uint32_t MaxT4Error;
-} TIMINGMSMT_CONFIRM_EVENT_DATA;
-
-typedef struct _WIRELESS_CORRELATEDTIME
-{
- uint64_t TSC;
- uint64_t LocalClk;
-} WIRELESS_CORRELATEDTIME;
-
-struct S8021AS_Indication {
- TIMINGMSMT_EVENT_DATA indication;
- uint8_t followup[75]; // (34 header + 10 followup + 32 TLV) - 1 byte contained in indication struct = 75
-};
-
-union TimeSyncEventData
-{
- TIMINGMSMT_CONFIRM_EVENT_DATA confirm;
- S8021AS_Indication indication;
- WIRELESS_CORRELATEDTIME ptm_wa;
-};
-
-class WirelessTimestamper : public CommonTimestamper
-{
-private:
- WirelessPort *port;
-public:
- virtual ~WirelessTimestamper() {}
-
- /**
- * @brief attach timestamper to port
- * @param port port to attach
- */
- void setPort( WirelessPort *port )
- {
- this->port = port;
- }
-
- /**
- * @brief return reference to attached port
- * @return reference to attached port
- */
- WirelessPort *getPort(void) const
- {
- return port;
- }
-
- /**
- * @brief Return buffer offset where followup message should be placed
- * @return byte offset
- */
- uint8_t getFwUpOffset(void)
- {
- // Subtract 1 to compensate for 'bogus' vendor specific buffer
- // length
- return (uint8_t)((size_t) &((TIMINGMSMT_REQUEST *) 0)->
- PtpSpec.fwup_data );
- }
-
- /**
- * @brief Request transmission of TM frame
- * @param dest [in] MAC destination the frame should be sent to
- * @param seq [in] 802.1AS sequence number
- * @param prev_dialog [in] last dialog message
- * @param follow_up [in] buffer containing followup message
- * @param followup_length [in] fw-up message length in bytes
- */
- virtual net_result requestTimingMeasurement
- ( LinkLayerAddress *dest, uint16_t seq, WirelessDialog *prev_dialog,
- uint8_t *follow_up, int followup_length );
-
- /**
- * @brief abstract method for driver/os specific TM transmit code
- * @param timingmsmt_req fully formed TM message
- */
- virtual net_result _requestTimingMeasurement
- ( TIMINGMSMT_REQUEST *timingmsmt_req ) = 0;
-
- /**
- * @brief Asynchronous completion of TM transmit
- * @param addr [in] MAC the message was transmitted to
- * @param dialog [in] dialog filled with T1, T4 timestamps
- */
- void timingMeasurementConfirmCB( LinkLayerAddress addr,
- WirelessDialog *dialog );
-
- /**
- * @brief Reception of TM frame
- * @param addr [in] MAC the message was received from
- * @param current [in] dialog filled with T2, T3 timestamps
- * @param previous [in] dialog filled with T1, T4 timestamps
- * @param buf [in] buffer containing followup message
- * @param previous [in] length of followup message
- */
- void timeMeasurementIndicationCB
- ( LinkLayerAddress addr, WirelessDialog *current,
- WirelessDialog *previous, uint8_t *buf, size_t buflen );
-};
-
-struct WirelessTimestamperCallbackArg
-{
- WIRELESS_EVENT_TYPE iEvent_type;
- WirelessTimestamper *timestamper;
- TimeSyncEventData event_data;
-};
-
-#endif/*WIRELESS_TSTAMPER_HPP*/