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 <jb...@redhat.com>
---
 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 7f471ca555aa..564cc9bfa0df 100644
--- a/msg.h
+++ b/msg.h
@@ -25,7 +25,6 @@
 #include <time.h>
 
 #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 e52d68f5b5f7..a7201f92454d 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 850d85fe13e8..9fcb51da3fd4 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 568bd30c8815..390aa389adc4 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 b5346e5e51f4..cb799a68aa9f 100644
--- a/transport.c
+++ b/transport.c
@@ -17,6 +17,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <arpa/inet.h>
+
 #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 aa2018b4ecdf..5153c46d7887 100644
--- a/transport.h
+++ b/transport.h
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 
 #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.
-- 
1.7.6.5


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to