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 <jbenc@redhat.com>
master
Jiri Benc 2014-04-11 12:25:53 +02:00 committed by Richard Cochran
parent 3d22154299
commit bbe634d790
6 changed files with 35 additions and 34 deletions

14
msg.h
View File

@ -25,7 +25,6 @@
#include <time.h> #include <time.h>
#include "ddt.h" #include "ddt.h"
#include "transport.h"
#include "tlv.h" #include "tlv.h"
#define PTP_VERSION 2 #define PTP_VERSION 2
@ -55,6 +54,19 @@
#define TIME_TRACEABLE (1<<4) #define TIME_TRACEABLE (1<<4)
#define FREQ_TRACEABLE (1<<5) #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 { enum controlField {
CTL_SYNC, CTL_SYNC,
CTL_DELAY_REQ, CTL_DELAY_REQ,

View File

@ -149,8 +149,7 @@ static int pmc_send(struct pmc *pmc, struct ptp_message *msg, int pdulen)
pr_err("msg_pre_send failed"); pr_err("msg_pre_send failed");
return -1; return -1;
} }
cnt = transport_send(pmc->transport, &pmc->fdarray, 0, cnt = transport_send(pmc->transport, &pmc->fdarray, 0, msg);
msg, pdulen, &msg->hwts);
if (cnt < 0) { if (cnt < 0) {
pr_err("failed to send message"); pr_err("failed to send message");
return -1; return -1;
@ -298,8 +297,7 @@ struct ptp_message *pmc_recv(struct pmc *pmc)
return NULL; return NULL;
} }
msg->hwts.type = TS_SOFTWARE; msg->hwts.type = TS_SOFTWARE;
cnt = transport_recv(pmc->transport, pmc_get_transport_fd(pmc), cnt = transport_recv(pmc->transport, pmc_get_transport_fd(pmc), msg);
msg, sizeof(msg->data), &msg->hwts);
if (cnt <= 0) { if (cnt <= 0) {
pr_err("recv message failed"); pr_err("recv message failed");
goto failed; goto failed;

View File

@ -22,6 +22,7 @@
#define HAVE_PMC_COMMON_H #define HAVE_PMC_COMMON_H
#include "msg.h" #include "msg.h"
#include "transport.h"
struct pmc; struct pmc;

8
port.c
View File

@ -2092,7 +2092,7 @@ enum fsm_event port_event(struct port *p, int fd_index)
msg->hwts.type = p->timestamping; 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) { if (cnt <= 0) {
pr_err("port %hu: recv message failed", portnum(p)); pr_err("port %hu: recv message failed", portnum(p));
msg_put(msg); 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 port_forward(struct port *p, struct ptp_message *msg, int msglen)
{ {
int cnt; 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; return cnt <= 0 ? -1 : 0;
} }
int port_prepare_and_send(struct port *p, struct ptp_message *msg, int event) int port_prepare_and_send(struct port *p, struct ptp_message *msg, int event)
{ {
UInteger16 msg_len;
int cnt; int cnt;
msg_len = msg->header.messageLength;
if (msg_pre_send(msg)) if (msg_pre_send(msg))
return -1; 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; return cnt <= 0 ? -1 : 0;
} }

View File

@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <arpa/inet.h>
#include "transport.h" #include "transport.h"
#include "transport_private.h" #include "transport_private.h"
#include "raw.h" #include "raw.h"
@ -35,22 +37,25 @@ int transport_open(struct transport *t, const char *name,
return t->open(t, name, fda, tt); return t->open(t, name, fda, tt);
} }
int transport_recv(struct transport *t, int fd, int transport_recv(struct transport *t, int fd, struct ptp_message *msg)
void *buf, int buflen, struct hw_timestamp *hwts)
{ {
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, 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, 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) int transport_physical_addr(struct transport *t, uint8_t *addr)

View File

@ -24,6 +24,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "fd.h" #include "fd.h"
#include "msg.h"
/* Values from networkProtocol enumeration 7.4.1 Table 3 */ /* Values from networkProtocol enumeration 7.4.1 Table 3 */
enum transport_type { enum transport_type {
@ -47,19 +48,6 @@ enum transport_event {
TRANS_ONESTEP, 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; struct transport;
int transport_close(struct transport *t, struct fdarray *fda); 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, int transport_open(struct transport *t, const char *name,
struct fdarray *fda, enum timestamp_type tt); struct fdarray *fda, enum timestamp_type tt);
int transport_recv(struct transport *t, int fd, int transport_recv(struct transport *t, int fd, struct ptp_message *msg);
void *buf, int buflen, struct hw_timestamp *hwts);
int transport_send(struct transport *t, struct fdarray *fda, int event, 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, 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. * Returns the transport's type.