From 86f5dd44b9399f7288376560f6079946f6fb7056 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 21 Jul 2015 01:01:41 -0500 Subject: [PATCH] That's better --- include/patty/ax25.h | 37 ++++++++++++++++++++----------------- src/ax25.c | 14 ++++++++------ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index a686fd5..326a997 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -40,9 +40,10 @@ typedef struct _patty_ax25_link { } patty_ax25_link; typedef struct _patty_ax25_if { - patty_kiss_tnc * tnc; - patty_ax25_stats stats; - patty_dict * ports; + enum patty_ax25_if_type type; + patty_kiss_tnc * tnc; + patty_ax25_stats stats; + patty_dict * ports; } patty_ax25_if; typedef struct _patty_ax25 { @@ -53,35 +54,37 @@ typedef struct _patty_ax25 { int patty_ax25_init(patty_ax25 *ax25); -void patty_ax25_finish(patty_ax25 *ax25); +void patty_ax25_stop(patty_ax25 *ax25); -int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info); +patty_ax25_if *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); -int patty_ax25_get_if(patty_ax25 *ax25, const char *name); +patty_ax25_if *patty_ax25_get_if(patty_ax25 *ax25, const char *name); -int patty_ax25_destroy_if(patty_ax25 *ax25, int iface); +int patty_ax25_destroy_if(patty_ax25 *ax25, patty_ax25_if *iface); -int patty_ax25_listen(patty_ax25 *ax25, int iface, +patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const char *callsign, int ssid); -int patty_ax25_shutdown(patty_ax25 *ax25, int port); +int patty_ax25_shutdown(patty_ax25 *ax25, patty_ax25_port *port); -int patty_ax25_connect(patty_ax25 *ax25, int port, +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, int link); +int patty_ax25_close(patty_ax25 *ax25, patty_ax25_link *link); -int patty_ax25_recv(patty_ax25 *ax25, int iface, patty_ax25_frame *frame); +int patty_ax25_recv(patty_ax25 *ax25, + patty_ax25_if *iface, patty_ax25_frame *frame); -int patty_ax25_send(patty_ax25 *ax25, int iface, - const 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, int link, void *data, size_t len); +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, int link, - const 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/src/ax25.c b/src/ax25.c index 6861b6a..3cafc33 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -33,13 +33,13 @@ error_dict_new_ifaces: return -1; } -void patty_ax25_finish(patty_ax25 *ax25) { +void patty_ax25_stop(patty_ax25 *ax25) { patty_dict_destroy(ax25->links); patty_dict_destroy(ax25->ports); patty_dict_destroy(ax25->ifaces); } -static int create_if_tnc(patty_ax25 *ax25, const char *device) { +static patty_ax25_if *create_if_tnc(patty_ax25 *ax25, const char *device) { patty_ax25_if *iface; if ((iface = malloc(sizeof(*iface))) == NULL) { @@ -56,11 +56,13 @@ static int create_if_tnc(patty_ax25 *ax25, const char *device) { goto error_kiss_tnc_open; } + iface->type = PATTY_AX25_IF_KISS_TNC_TTY; + if (patty_dict_set(ax25->ifaces, (void *)device, strlen(device), iface) == NULL) { goto error_dict_set_iface; } - return 0; + return iface; error_dict_set_iface: patty_kiss_tnc_close(iface->tnc); @@ -72,10 +74,10 @@ error_dict_new_ports: free(iface); error_malloc_iface: - return -1; + return NULL; } -int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { +patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { switch (PATTY_AX25_IF_OPT_TYPE(opts)) { case PATTY_AX25_IF_KISS_TNC_TTY: { return create_if_tnc(ax25, (const char *)info); @@ -86,5 +88,5 @@ int patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { errno = EINVAL; - return -1; + return NULL; }