From 1ce32f18e3b524b0d8850fde7c358166b12175d7 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 24 Jul 2015 22:28:39 +0000 Subject: [PATCH] This may in fact stick --- include/patty/ax25.h | 92 +++----------------------------------- include/patty/ax25/defs.h | 23 ++++++++++ include/patty/ax25/if.h | 53 ++++++++++++++++++++++ include/patty/ax25/io.h | 42 +++++++++++++++++ include/patty/ax25/link.h | 16 +++++++ include/patty/ax25/port.h | 14 ++++++ include/patty/ax25/stats.h | 12 +++++ src/ax25.c | 9 ++++ 8 files changed, 174 insertions(+), 87 deletions(-) create mode 100644 include/patty/ax25/defs.h create mode 100644 include/patty/ax25/if.h create mode 100644 include/patty/ax25/io.h create mode 100644 include/patty/ax25/link.h create mode 100644 include/patty/ax25/port.h create mode 100644 include/patty/ax25/stats.h diff --git a/include/patty/ax25.h b/include/patty/ax25.h index d03caf4..4490481 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -8,100 +8,18 @@ #include #include +#include #include #include #include #include - -#define PATTY_AX25_IF_OPT_TYPE_MASK 0x1f - -#define PATTY_AX25_IF_OPT_TYPE(n) \ - ((n) & PATTY_AX25_IF_OPT_TYPE_MASK) - -enum patty_ax25_obj_type { - PATTY_AX25_OBJ_UNKNOWN, - PATTY_AX25_OBJ_IF, - PATTY_AX25_OBJ_PORT, - PATTY_AX25_OBJ_LINK -}; - -enum patty_ax25_if_type { - PATTY_AX25_IF_UNKNOWN = 0x00, - PATTY_AX25_IF_KISS_TNC_TTY = 0x01, - PATTY_AX25_IF_KISS_TNC_PORT = 0x02, - PATTY_AX25_IF_KISS_TNC_I2C = 0x04, - PATTY_AX25_IF_KISS_TNC_SPI = 0x08, - PATTY_AX25_IF_SOFT_TNC = 0x10 -}; - -typedef struct _patty_ax25_stats { - size_t frame_tx; - size_t frame_rx; - size_t frame_drop; -} patty_ax25_stats; - -typedef struct _patty_ax25_port { - enum patty_ax25_obj_type type; - - char callsign[7]; - int ssid; -} patty_ax25_port; - -typedef struct _patty_ax25_if { - enum patty_ax25_if_type type; - - patty_kiss_tnc * tnc; - patty_ax25_stats stats; - patty_list * ports; -} patty_ax25_if; - -typedef struct _patty_ax25_link { - enum patty_ax25_if_type type; - - patty_ax25_if * iface; - patty_ax25_port * local; - patty_ax25_port * remote; - patty_ax25_stats * stats; -} patty_ax25_link; - -typedef struct _patty_ax25 { - patty_list * ifaces; - patty_list * ports; - patty_dict * objs; - int fd; -} patty_ax25; +#include +#include +#include +#include int patty_ax25_init(patty_ax25 *ax25); void patty_ax25_stop(patty_ax25 *ax25); -int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info); - -int patty_ax25_each_if(patty_ax25 *ax25, - int (*callback)(patty_ax25_if *, void *), void *ctx); - -patty_ax25_if *patty_ax25_get_if(patty_ax25 *ax25, const char *name); - -int patty_ax25_destroy_if(patty_ax25 *ax25, patty_ax25_if *iface); - -patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, - const char *callsign, int ssid); - -patty_ax25_link *patty_ax25_connect(patty_ax25 *ax25, patty_ax25_port *port, - const char *callsign, int ssid); - -int patty_ax25_close(patty_ax25 *ax25, patty_ax25_link *link); - -int patty_ax25_recv(patty_ax25 *ax25, - patty_ax25_if *iface, patty_ax25_frame *frame); - -int patty_ax25_send(patty_ax25 *ax25, - patty_ax25_if *iface, const patty_ax25_frame *frame); - -ssize_t patty_ax25_read(patty_ax25 *ax25, - patty_ax25_link *link, void *data, size_t len); - -ssize_t patty_ax25_write(patty_ax25 *ax25, - patty_ax25_link *link, const void *data, size_t len); - #endif /* _PATTY_AX25_IF */ diff --git a/include/patty/ax25/defs.h b/include/patty/ax25/defs.h new file mode 100644 index 0000000..e4b2b74 --- /dev/null +++ b/include/patty/ax25/defs.h @@ -0,0 +1,23 @@ +#ifndef _PATTY_AX25_DEFS_H +#define _PATTY_AX25_DEFS_H + +#include + +#include +#include + +enum patty_ax25_obj_type { + PATTY_AX25_OBJ_UNKNOWN, + PATTY_AX25_OBJ_PORT, + PATTY_AX25_OBJ_LINK +}; + +typedef struct _patty_ax25_stats { + size_t rx; + size_t tx; + size_t dropped; +} patty_ax25_stats; + +typedef struct _patty_ax25 patty_ax25; + +#endif /* _PATTY_AX25_DEFS_H */ diff --git a/include/patty/ax25/if.h b/include/patty/ax25/if.h new file mode 100644 index 0000000..c114df4 --- /dev/null +++ b/include/patty/ax25/if.h @@ -0,0 +1,53 @@ +#ifndef _PATTY_AX25_IF_H +#define _PATTY_AX25_IF_H + +#include +#include + +#include + +#define PATTY_AX25_IF_OPT_TYPE_MASK 0x1f + +#define PATTY_AX25_IF_OPT_TYPE(n) \ + ((n) & PATTY_AX25_IF_OPT_TYPE_MASK) + +enum patty_ax25_if_type { + PATTY_AX25_IF_UNKNOWN = 0x00, + PATTY_AX25_IF_KISS_TNC_TTY = 0x01, + PATTY_AX25_IF_KISS_TNC_PORT = 0x02, + PATTY_AX25_IF_KISS_TNC_I2C = 0x04, + PATTY_AX25_IF_KISS_TNC_SPI = 0x08, + PATTY_AX25_IF_SOFT_TNC = 0x10 +}; + +typedef struct _patty_ax25_if { + enum patty_ax25_if_type type; + patty_ax25_stats stats; + + patty_kiss_tnc * tnc; + patty_list * addresses; +} patty_ax25_if; + +int patty_ax25_if_create(int opts, void *info); + +void patty_ax25_if_destroy(patty_ax25_if *iface); + +int patty_ax25_if_each_address(patty_ax25_if *iface, + int (*callback)(patty_ax25_address *, void *), void *ctx); + +int patty_ax25_if_add_address(patty_ax25_if *iface, + const char *callsign, int ssid); + +int patty_ax25_if_delete_address(patty_ax25_if *iface, + const char *callsign, int ssid); + +int patty_ax25_each_if(patty_ax25 *ax25, + int (*callback)(patty_ax25_if *, void *), void *ctx); + +patty_ax25_if *patty_ax25_get_if(patty_ax25 *ax25, const char *name); + +int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface); + +int patty_ax25_delete_if(patty_ax25 *ax25, patty_ax25_if *iface); + +#endif /* _PATTY_AX25_IF_H */ diff --git a/include/patty/ax25/io.h b/include/patty/ax25/io.h new file mode 100644 index 0000000..996fdad --- /dev/null +++ b/include/patty/ax25/io.h @@ -0,0 +1,42 @@ +#ifndef _PATTY_AX25_IO_H +#define _PATTY_AX25_IO_H + +enum patty_ax25_io_event { + PATTY_AX25_IO_UNKNOWN, + PATTY_AX25_IO_RECV, + PATTY_AX25_IO_SEND, + PATTY_AX25_IO_READ, + PATTY_AX25_IO_WRITE +}; + +int patty_ax25_open(patty_ax25 *ax25, const char *ifname); + +int patty_ax25_socket(patty_ax25 *ax25); + +int patty_ax25_listen(patty_ax25 *ax25, + int socket, const char *callsign, int ssid); + +int patty_ax25_connect(patty_ax25 *ax25, + int socket, const char *callsign, int ssid); + +int patty_ax25_accept(patty_ax25 *ax25, + int socket); + +int patty_ax25_close(patty_ax25 *ax25, int fd); + +int patty_ax25_wait(patty_ax25 *ax25, + int fds, enum patty_ax25_io_event *ev); + +int patty_ax25_recv(patty_ax25 *ax25, + int fd, patty_ax25_frame *frame); + +int patty_ax25_send(patty_ax25 *ax25, + int fd, patty_ax25_frame *frame); + +ssize_t patty_ax25_read(patty_ax25 *ax25, + int fd, void *data, size_t len); + +ssize_t patty_ax25_write(patty_ax25 *ax25, + int fd, const void *data, size_t len); + +#endif /* _PATTY_AX25_IO_H */ diff --git a/include/patty/ax25/link.h b/include/patty/ax25/link.h new file mode 100644 index 0000000..0073ad8 --- /dev/null +++ b/include/patty/ax25/link.h @@ -0,0 +1,16 @@ +#ifndef _PATTY_AX25_LINK_H +#define _PATTY_AX25_LINK_H + +typedef struct _patty_ax25_link { + enum patty_ax25_if_type type; + patty_ax25_stats stats; + + patty_ax25_if * iface; + patty_ax25_port * local; + patty_ax25_port * remote; +} patty_ax25_link; + +patty_ax25_link *patty_ax25_connect(patty_ax25 *ax25, patty_ax25_port *port, + const char *callsign, int ssid); + +#endif /* _PATTY_AX25_LINK_H */ diff --git a/include/patty/ax25/port.h b/include/patty/ax25/port.h new file mode 100644 index 0000000..f4cec82 --- /dev/null +++ b/include/patty/ax25/port.h @@ -0,0 +1,14 @@ +#ifndef _PATTY_AX25_PORT_H +#define _PATTY_AX25_PORT_H + +typedef struct _patty_ax25_port { + enum patty_ax25_obj_type type; + + char callsign[7]; + int ssid; +} patty_ax25_port; + +patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, + const char *callsign, int ssid); + +#endif /* _PATTY_AX25_PORT_H */ diff --git a/include/patty/ax25/stats.h b/include/patty/ax25/stats.h new file mode 100644 index 0000000..1355092 --- /dev/null +++ b/include/patty/ax25/stats.h @@ -0,0 +1,12 @@ +#ifndef _PATTY_AX25_STATS_H +#define _PATTY_AX25_STATS_H + +#include + +typedef struct _patty_ax25_stats { + size_t frame_tx; + size_t frame_rx; + size_t frame_drop; +} patty_ax25_stats; + +#endif /* _PATTY_AX25_STATS_H */ diff --git a/src/ax25.c b/src/ax25.c index 4ee8704..490e112 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -7,6 +7,15 @@ #include #include +typedef struct _patty_ax25 { + patty_list * ifaces; + patty_list * ports; + patty_list * links; + + patty_dict * fd_lookup; + int fd; +} patty_ax25; + int patty_ax25_init(patty_ax25 *ax25) { memset(ax25, '\0', sizeof(*ax25));