summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandrew-elder <aelder@audioscience.com>2017-12-01 18:14:30 -0500
committerGitHub <noreply@github.com>2017-12-01 18:14:30 -0500
commit9bbb455e4eb27a428404e00bb82b2cf3976dd087 (patch)
tree122ab613431009622099b9cb86bdeeacec672413
parent0f76b064f4b984a5ca572a09e8fcd79f0ce2dfb3 (diff)
parent3fde53e712e70b48a5405fd286aef637df751d33 (diff)
downloadOpen-AVB-9bbb455e4eb27a428404e00bb82b2cf3976dd087.tar.gz
Merge pull request #728 from mgalka/open-avb-next
Fixing stale Tx timestamp fetch.
-rw-r--r--daemons/gptp/common/ptptypes.hpp1
-rw-r--r--daemons/gptp/linux/src/linux_hal_generic.cpp21
2 files changed, 19 insertions, 3 deletions
diff --git a/daemons/gptp/common/ptptypes.hpp b/daemons/gptp/common/ptptypes.hpp
index 03cd57be..f73c8f92 100644
--- a/daemons/gptp/common/ptptypes.hpp
+++ b/daemons/gptp/common/ptptypes.hpp
@@ -43,6 +43,7 @@ typedef double FrequencyRatio; /*!< Frequency Ratio */
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 */
diff --git a/daemons/gptp/linux/src/linux_hal_generic.cpp b/daemons/gptp/linux/src/linux_hal_generic.cpp
index 5364fa6a..9eeba46f 100644
--- a/daemons/gptp/linux/src/linux_hal_generic.cpp
+++ b/daemons/gptp/linux/src/linux_hal_generic.cpp
@@ -30,9 +30,10 @@
POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
-
#include <linux_hal_generic.hpp>
#include <linux_hal_generic_tsprivate.hpp>
+#include <platform.hpp>
+#include <avbts_message.hpp>
#include <sys/select.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
@@ -285,6 +286,10 @@ int LinuxTimestamperGeneric::HWTimestamper_txtimestamp
struct cmsghdr *cmsg;
struct sockaddr_ll remote;
struct iovec sgentry;
+ PTPMessageId reflectedMessageId;
+ uint8_t reflected_bytes[ETHER_HDR_LEN + PTP_COMMON_HDR_LENGTH];
+ uint8_t *gptpCommonHeader;
+ uint16_t sequenceId;
struct {
struct cmsghdr cm;
char control[256];
@@ -296,8 +301,10 @@ int LinuxTimestamperGeneric::HWTimestamper_txtimestamp
msg.msg_iov = &sgentry;
msg.msg_iovlen = 1;
- sgentry.iov_base = NULL;
- sgentry.iov_len = 0;
+ sgentry.iov_base = reflected_bytes;
+ sgentry.iov_len = sizeof(reflected_bytes);
+
+ gptpCommonHeader = reflected_bytes + ETHER_HDR_LEN;
memset( &remote, 0, sizeof(remote));
msg.msg_name = (caddr_t) &remote;
@@ -316,6 +323,14 @@ int LinuxTimestamperGeneric::HWTimestamper_txtimestamp
goto done;
}
}
+ sequenceId = PLAT_ntohs(*((uint16_t*)(PTP_COMMON_HDR_SEQUENCE_ID(gptpCommonHeader))));
+ reflectedMessageId.setSequenceId(sequenceId);
+ reflectedMessageId.setMessageType((MessageType)(*PTP_COMMON_HDR_TRANSSPEC_MSGTYPE(gptpCommonHeader) & 0xF));
+ if (messageId != reflectedMessageId) {
+ GPTP_LOG_WARNING("Timestamp discarded due to wrong message id");
+ ret = GPTP_EC_EAGAIN;
+ goto done;
+ }
// Retrieve the timestamp
cmsg = CMSG_FIRSTHDR(&msg);