transport: adds interface for getting type, and physical/protocol address
Needed for CLOCK_DESCRIPTION management TLV.master
parent
5c47cbfedf
commit
e010937783
38
transport.c
38
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);
|
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 *transport_create(enum transport_type type)
|
||||||
{
|
{
|
||||||
|
struct transport *t = NULL;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TRANS_UDS:
|
case TRANS_UDS:
|
||||||
return uds_transport_create();
|
t = uds_transport_create();
|
||||||
|
break;
|
||||||
case TRANS_UDP_IPV4:
|
case TRANS_UDP_IPV4:
|
||||||
return udp_transport_create();
|
t = udp_transport_create();
|
||||||
|
break;
|
||||||
case TRANS_UDP_IPV6:
|
case TRANS_UDP_IPV6:
|
||||||
return udp6_transport_create();
|
t = udp6_transport_create();
|
||||||
|
break;
|
||||||
case TRANS_IEEE_802_3:
|
case TRANS_IEEE_802_3:
|
||||||
return raw_transport_create();
|
t = raw_transport_create();
|
||||||
|
break;
|
||||||
case TRANS_DEVICENET:
|
case TRANS_DEVICENET:
|
||||||
case TRANS_CONTROLNET:
|
case TRANS_CONTROLNET:
|
||||||
case TRANS_PROFINET:
|
case TRANS_PROFINET:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return NULL;
|
if (t)
|
||||||
|
t->type = type;
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void transport_destroy(struct transport *t)
|
void transport_destroy(struct transport *t)
|
||||||
|
|
26
transport.h
26
transport.h
|
@ -21,6 +21,7 @@
|
||||||
#define HAVE_TRANSPORT_H
|
#define HAVE_TRANSPORT_H
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "fd.h"
|
#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,
|
int transport_peer(struct transport *t, struct fdarray *fda, int event,
|
||||||
void *buf, int buflen, struct hw_timestamp *hwts);
|
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.
|
* Allocate an instance of the specified transport.
|
||||||
* @param type Which transport to obtain.
|
* @param type Which transport to obtain.
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
|
||||||
struct transport {
|
struct transport {
|
||||||
|
enum transport_type type;
|
||||||
|
|
||||||
int (*close)(struct transport *t, struct fdarray *fda);
|
int (*close)(struct transport *t, struct fdarray *fda);
|
||||||
|
|
||||||
int (*open)(struct transport *t, char *name, 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 *buf, int buflen, struct hw_timestamp *hwts);
|
||||||
|
|
||||||
void (*release)(struct transport *t);
|
void (*release)(struct transport *t);
|
||||||
|
|
||||||
|
int (*physical_addr)(struct transport *t, uint8_t *addr);
|
||||||
|
|
||||||
|
int (*protocol_addr)(struct transport *t, uint8_t *addr);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue