From e010937783db7ef84941e18fff7682bf552685d4 Mon Sep 17 00:00:00 2001 From: Geoff Salmon Date: Tue, 8 Jan 2013 19:21:24 -0500 Subject: [PATCH] transport: adds interface for getting type, and physical/protocol address Needed for CLOCK_DESCRIPTION management TLV. --- transport.c | 38 +++++++++++++++++++++++++++++++++----- transport.h | 26 ++++++++++++++++++++++++++ transport_private.h | 6 ++++++ 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/transport.c b/transport.c index a06530c..3c70b2b 100644 --- a/transport.c +++ b/transport.c @@ -53,23 +53,51 @@ int transport_peer(struct transport *t, struct fdarray *fda, int event, return t->send(t, fda, event, 1, buf, buflen, hwts); } +int transport_physical_addr(struct transport *t, uint8_t *addr) +{ + if (t->physical_addr) { + return t->physical_addr(t, addr); + } + return 0; +} + +int transport_protocol_addr(struct transport *t, uint8_t *addr) +{ + if (t->protocol_addr) { + return t->protocol_addr(t, addr); + } + return 0; +} + +enum transport_type transport_type(struct transport *t) +{ + return t->type; +} + struct transport *transport_create(enum transport_type type) { + struct transport *t = NULL; switch (type) { case TRANS_UDS: - return uds_transport_create(); + t = uds_transport_create(); + break; case TRANS_UDP_IPV4: - return udp_transport_create(); + t = udp_transport_create(); + break; case TRANS_UDP_IPV6: - return udp6_transport_create(); + t = udp6_transport_create(); + break; case TRANS_IEEE_802_3: - return raw_transport_create(); + t = raw_transport_create(); + break; case TRANS_DEVICENET: case TRANS_CONTROLNET: case TRANS_PROFINET: break; } - return NULL; + if (t) + t->type = type; + return t; } void transport_destroy(struct transport *t) diff --git a/transport.h b/transport.h index d714b85..46af456 100644 --- a/transport.h +++ b/transport.h @@ -21,6 +21,7 @@ #define HAVE_TRANSPORT_H #include +#include #include "fd.h" @@ -74,6 +75,31 @@ int transport_send(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); +/** + * Returns the transport's type. + */ +enum transport_type transport_type(struct transport *t); + +#define TRANSPORT_ADDR_LEN 16 + +/** + * Gets the transport's physical address. + * @param t The transport. + * @param addr The address will be written to this buffer. + * @return The number of bytes written to the buffer. Will be 0-16 + * bytes + */ +int transport_physical_addr(struct transport *t, uint8_t *addr); + +/** + * Gets the transport's protocol address. + * @param t The transport. + * @param addr The address will be written to this buffer. + * @return The number of bytes written to the buffer. Will be 0-16 + * bytes + */ +int transport_protocol_addr(struct transport *t, uint8_t *addr); + /** * Allocate an instance of the specified transport. * @param type Which transport to obtain. diff --git a/transport_private.h b/transport_private.h index 255035d..0c553e1 100644 --- a/transport_private.h +++ b/transport_private.h @@ -26,6 +26,8 @@ #include "transport.h" struct transport { + enum transport_type type; + int (*close)(struct transport *t, struct fdarray *fda); int (*open)(struct transport *t, char *name, struct fdarray *fda, @@ -38,6 +40,10 @@ struct transport { void *buf, int buflen, struct hw_timestamp *hwts); void (*release)(struct transport *t); + + int (*physical_addr)(struct transport *t, uint8_t *addr); + + int (*protocol_addr)(struct transport *t, uint8_t *addr); }; #endif