Skip to content

Commit

Permalink
Let transport_recv/send/peer use ptp_message
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Benc authored and richardcochran committed Apr 17, 2014
1 parent 3d22154 commit bbe634d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
14 changes: 13 additions & 1 deletion msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <time.h>

#include "ddt.h"
#include "transport.h"
#include "tlv.h"

#define PTP_VERSION 2
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions pmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pmc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define HAVE_PMC_COMMON_H

#include "msg.h"
#include "transport.h"

struct pmc;

Expand Down
8 changes: 3 additions & 5 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
19 changes: 12 additions & 7 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
21 changes: 4 additions & 17 deletions transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -47,34 +48,20 @@ 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);

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.
Expand Down

0 comments on commit bbe634d

Please sign in to comment.