From 5f9163af4bf6b54ea08f7fef112e9fcf4a669e56 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 17 Mar 2018 12:12:59 -0700 Subject: [PATCH] transport: Introduce method for fetching a deferred transmit time stamp. When a messages is sent with the DEFER_EVENT flag, the lower transport code does not fetch the time stamp right away. This patch introduces a method that allows a second call to retrieve the waiting transmit time stamp. Signed-off-by: Richard Cochran --- transport.c | 11 +++++++++++ transport.h | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/transport.c b/transport.c index ff5e307..8fb94de 100644 --- a/transport.c +++ b/transport.c @@ -66,6 +66,17 @@ int transport_sendto(struct transport *t, struct fdarray *fda, return t->send(t, fda, event, 0, msg, len, &msg->address, &msg->hwts); } +int transport_txts(struct transport *t, struct fdarray *fda, + struct ptp_message *msg) +{ + int cnt, len = ntohs(msg->header.messageLength); + struct hw_timestamp *hwts = &msg->hwts; + unsigned char pkt[1600]; + + cnt = sk_receive(fda->fd[FD_EVENT], pkt, len, NULL, hwts, MSG_ERRQUEUE); + return cnt > 0 ? 0 : cnt; +} + int transport_physical_addr(struct transport *t, uint8_t *addr) { if (t->physical_addr) { diff --git a/transport.h b/transport.h index 171e59f..4f6dc36 100644 --- a/transport.h +++ b/transport.h @@ -101,6 +101,19 @@ int transport_peer(struct transport *t, struct fdarray *fda, int transport_sendto(struct transport *t, struct fdarray *fda, enum transport_event event, struct ptp_message *msg); +/** + * Fetches the transmit time stamp for a PTP message that was sent + * with the TRANS_DEFER_EVENT flag. + * + * @param t The transport. + * @param fda The array of descriptors filled in by transport_open. + * @param msg The message previously sent using transport_send(), + * transport_peer(), or transport_sendto(). + * @return Zero on success, or negative value in case of an error. + */ +int transport_txts(struct transport *t, struct fdarray *fda, + struct ptp_message *msg); + /** * Returns the transport's type. */