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
parent
3d22154299
commit
bbe634d790
14
msg.h
14
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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define HAVE_PMC_COMMON_H
|
||||
|
||||
#include "msg.h"
|
||||
#include "transport.h"
|
||||
|
||||
struct pmc;
|
||||
|
||||
|
|
8
port.c
8
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;
|
||||
}
|
||||
|
||||
|
|
19
transport.c
19
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)
|
||||
|
|
21
transport.h
21
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.
|
||||
|
|
Loading…
Reference in New Issue