diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 14d992c..8c13415 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -13,6 +13,9 @@ #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, @@ -40,8 +43,6 @@ typedef struct _patty_ax25_if { patty_kiss_tnc * tnc; patty_ax25_stats stats; patty_dict * ports; - - char name[8]; } patty_ax25_if; typedef struct _patty_ax25 { @@ -54,8 +55,7 @@ int patty_ax25_init(patty_ax25 *ax25); void patty_ax25_finish(patty_ax25 *ax25); -int patty_ax25_create_if(patty_ax25 *ax25, const char *name, - int opts, void *info); +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); diff --git a/include/patty/kiss.h b/include/patty/kiss.h index 609719e..7c0eb0e 100644 --- a/include/patty/kiss.h +++ b/include/patty/kiss.h @@ -8,6 +8,8 @@ #define PATTY_KISS_TFEND 0xdc #define PATTY_KISS_TFESC 0xdd +#define PATTY_KISS_BUFSZ 2048 + #define PATTY_KISS_COMMAND_PORT(cmd) \ ((cmd & 0xf0) >> 4) diff --git a/src/ax25.c b/src/ax25.c index 4334acb..813a1e8 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -1,5 +1,9 @@ +#include #include +#include +#include +#include #include int patty_ax25_init(patty_ax25 *ax25) { @@ -34,3 +38,46 @@ void patty_ax25_finish(patty_ax25 *ax25) { patty_dict_destroy(ax25->ports); patty_dict_destroy(ax25->ax25_ifs); } + +static int create_if_tnc(patty_ax25 *ax25, const char *device) { + patty_ax25_if *iface; + + if ((iface = malloc(sizeof(*iface))) == NULL) { + goto error_malloc_iface; + } + + memset(iface, '\0', sizeof(*iface)); + + if ((iface->ports = patty_dict_new()) == NULL) { + goto error_dict_new_ports; + } + + if ((iface->tnc = patty_kiss_tnc_open(device, PATTY_KISS_BUFSZ)) == NULL) { + goto error_kiss_tnc_open; + } + + return 0; + +error_kiss_tnc_open: + patty_dict_destroy(iface->ports); + +error_dict_new_ports: + free(iface); + +error_malloc_iface: + return -1; +} + +int 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); + } + + default: break; + } + + errno = EINVAL; + + return -1; +} diff --git a/src/kiss.c b/src/kiss.c index d922a9f..376545c 100644 --- a/src/kiss.c +++ b/src/kiss.c @@ -16,6 +16,8 @@ enum kiss_flags { }; struct _patty_kiss_tnc { + const char * device; + int fd; int dropped; void * frame; @@ -44,6 +46,7 @@ patty_kiss_tnc *patty_kiss_tnc_open(const char *device, size_t bufsz) { } tnc->dropped = 0; + tnc->device = device; tnc->bufsz = bufsz; tnc->buflen = 0;