From bbe634d790cff73d28046f1946cdd9a1481686f8 Mon Sep 17 00:00:00 2001 From: Jiri Benc Date: Fri, 11 Apr 2014 12:25:53 +0200 Subject: [PATCH] Let transport_recv/send/peer use ptp_message The callers of those functions are all using ptp_message. As we're going to return more information (the address), let those functions just fill in the ptp_message fields directly. Some minor reshuffling needed to prevent circular header dependencies. Signed-off-by: Jiri Benc --- msg.h | 14 +++++++++++++- pmc_common.c | 6 ++---- pmc_common.h | 1 + port.c | 8 +++----- transport.c | 19 ++++++++++++------- transport.h | 21 ++++----------------- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/msg.h b/msg.h index 7f471ca..564cc9b 100644 --- a/msg.h +++ b/msg.h @@ -25,7 +25,6 @@ #include #include "ddt.h" -#include "transport.h" #include "tlv.h" #define PTP_VERSION 2 @@ -55,6 +54,19 @@ #define TIME_TRACEABLE (1<<4) #define FREQ_TRACEABLE (1<<5) +enum timestamp_type { + TS_SOFTWARE, + TS_HARDWARE, + TS_LEGACY_HW, + TS_ONESTEP, +}; + +struct hw_timestamp { + enum timestamp_type type; + struct timespec ts; + struct timespec sw; +}; + enum controlField { CTL_SYNC, CTL_DELAY_REQ, diff --git a/pmc_common.c b/pmc_common.c index e52d68f..a7201f9 100644 --- a/pmc_common.c +++ b/pmc_common.c @@ -149,8 +149,7 @@ static int pmc_send(struct pmc *pmc, struct ptp_message *msg, int pdulen) pr_err("msg_pre_send failed"); return -1; } - cnt = transport_send(pmc->transport, &pmc->fdarray, 0, - msg, pdulen, &msg->hwts); + cnt = transport_send(pmc->transport, &pmc->fdarray, 0, msg); if (cnt < 0) { pr_err("failed to send message"); return -1; @@ -298,8 +297,7 @@ struct ptp_message *pmc_recv(struct pmc *pmc) return NULL; } msg->hwts.type = TS_SOFTWARE; - cnt = transport_recv(pmc->transport, pmc_get_transport_fd(pmc), - msg, sizeof(msg->data), &msg->hwts); + cnt = transport_recv(pmc->transport, pmc_get_transport_fd(pmc), msg); if (cnt <= 0) { pr_err("recv message failed"); goto failed; diff --git a/pmc_common.h b/pmc_common.h index 850d85f..9fcb51d 100644 --- a/pmc_common.h +++ b/pmc_common.h @@ -22,6 +22,7 @@ #define HAVE_PMC_COMMON_H #include "msg.h" +#include "transport.h" struct pmc; diff --git a/port.c b/port.c index 568bd30..390aa38 100644 --- a/port.c +++ b/port.c @@ -2092,7 +2092,7 @@ enum fsm_event port_event(struct port *p, int fd_index) msg->hwts.type = p->timestamping; - cnt = transport_recv(p->trp, fd, msg, sizeof(msg->data), &msg->hwts); + cnt = transport_recv(p->trp, fd, msg); if (cnt <= 0) { pr_err("port %hu: recv message failed", portnum(p)); msg_put(msg); @@ -2166,19 +2166,17 @@ enum fsm_event port_event(struct port *p, int fd_index) int port_forward(struct port *p, struct ptp_message *msg, int msglen) { int cnt; - cnt = transport_send(p->trp, &p->fda, 0, msg, msglen, &msg->hwts); + cnt = transport_send(p->trp, &p->fda, 0, msg); return cnt <= 0 ? -1 : 0; } int port_prepare_and_send(struct port *p, struct ptp_message *msg, int event) { - UInteger16 msg_len; int cnt; - msg_len = msg->header.messageLength; if (msg_pre_send(msg)) return -1; - cnt = transport_send(p->trp, &p->fda, event, msg, msg_len, &msg->hwts); + cnt = transport_send(p->trp, &p->fda, event, msg); return cnt <= 0 ? -1 : 0; } diff --git a/transport.c b/transport.c index b5346e5..cb799a6 100644 --- a/transport.c +++ b/transport.c @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #include "transport.h" #include "transport_private.h" #include "raw.h" @@ -35,22 +37,25 @@ int transport_open(struct transport *t, const char *name, return t->open(t, name, fda, tt); } -int transport_recv(struct transport *t, int fd, - void *buf, int buflen, struct hw_timestamp *hwts) +int transport_recv(struct transport *t, int fd, struct ptp_message *msg) { - return t->recv(t, fd, buf, buflen, hwts); + return t->recv(t, fd, msg, sizeof(msg->data), &msg->hwts); } int transport_send(struct transport *t, struct fdarray *fda, int event, - void *buf, int buflen, struct hw_timestamp *hwts) + struct ptp_message *msg) { - return t->send(t, fda, event, 0, buf, buflen, hwts); + int len = ntohs(msg->header.messageLength); + + return t->send(t, fda, event, 0, msg, len, &msg->hwts); } int transport_peer(struct transport *t, struct fdarray *fda, int event, - void *buf, int buflen, struct hw_timestamp *hwts) + struct ptp_message *msg) { - return t->send(t, fda, event, 1, buf, buflen, hwts); + int len = ntohs(msg->header.messageLength); + + return t->send(t, fda, event, 1, msg, len, &msg->hwts); } int transport_physical_addr(struct transport *t, uint8_t *addr) diff --git a/transport.h b/transport.h index aa2018b..5153c46 100644 --- a/transport.h +++ b/transport.h @@ -24,6 +24,7 @@ #include #include "fd.h" +#include "msg.h" /* Values from networkProtocol enumeration 7.4.1 Table 3 */ enum transport_type { @@ -47,19 +48,6 @@ enum transport_event { TRANS_ONESTEP, }; -enum timestamp_type { - TS_SOFTWARE, - TS_HARDWARE, - TS_LEGACY_HW, - TS_ONESTEP, -}; - -struct hw_timestamp { - enum timestamp_type type; - struct timespec ts; - struct timespec sw; -}; - struct transport; int transport_close(struct transport *t, struct fdarray *fda); @@ -67,14 +55,13 @@ int transport_close(struct transport *t, struct fdarray *fda); int transport_open(struct transport *t, const char *name, struct fdarray *fda, enum timestamp_type tt); -int transport_recv(struct transport *t, int fd, - void *buf, int buflen, struct hw_timestamp *hwts); +int transport_recv(struct transport *t, int fd, struct ptp_message *msg); int transport_send(struct transport *t, struct fdarray *fda, int event, - void *buf, int buflen, struct hw_timestamp *hwts); + struct ptp_message *msg); int transport_peer(struct transport *t, struct fdarray *fda, int event, - void *buf, int buflen, struct hw_timestamp *hwts); + struct ptp_message *msg); /** * Returns the transport's type.