This may in fact stick
This commit is contained in:
parent
f7b3d3d35c
commit
1ce32f18e3
8 changed files with 174 additions and 87 deletions
|
@ -8,100 +8,18 @@
|
||||||
#include <patty/list.h>
|
#include <patty/list.h>
|
||||||
#include <patty/dict.h>
|
#include <patty/dict.h>
|
||||||
|
|
||||||
|
#include <patty/ax25/defs.h>
|
||||||
#include <patty/ax25/macros.h>
|
#include <patty/ax25/macros.h>
|
||||||
#include <patty/ax25/proto.h>
|
#include <patty/ax25/proto.h>
|
||||||
#include <patty/ax25/address.h>
|
#include <patty/ax25/address.h>
|
||||||
#include <patty/ax25/frame.h>
|
#include <patty/ax25/frame.h>
|
||||||
|
#include <patty/ax25/if.h>
|
||||||
#define PATTY_AX25_IF_OPT_TYPE_MASK 0x1f
|
#include <patty/ax25/port.h>
|
||||||
|
#include <patty/ax25/link.h>
|
||||||
#define PATTY_AX25_IF_OPT_TYPE(n) \
|
#include <patty/ax25/io.h>
|
||||||
((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;
|
|
||||||
|
|
||||||
int patty_ax25_init(patty_ax25 *ax25);
|
int patty_ax25_init(patty_ax25 *ax25);
|
||||||
|
|
||||||
void patty_ax25_stop(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 */
|
#endif /* _PATTY_AX25_IF */
|
||||||
|
|
23
include/patty/ax25/defs.h
Normal file
23
include/patty/ax25/defs.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef _PATTY_AX25_DEFS_H
|
||||||
|
#define _PATTY_AX25_DEFS_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <patty/list.h>
|
||||||
|
#include <patty/dict.h>
|
||||||
|
|
||||||
|
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 */
|
53
include/patty/ax25/if.h
Normal file
53
include/patty/ax25/if.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef _PATTY_AX25_IF_H
|
||||||
|
#define _PATTY_AX25_IF_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <patty/list.h>
|
||||||
|
|
||||||
|
#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 */
|
42
include/patty/ax25/io.h
Normal file
42
include/patty/ax25/io.h
Normal file
|
@ -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 */
|
16
include/patty/ax25/link.h
Normal file
16
include/patty/ax25/link.h
Normal file
|
@ -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 */
|
14
include/patty/ax25/port.h
Normal file
14
include/patty/ax25/port.h
Normal file
|
@ -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 */
|
12
include/patty/ax25/stats.h
Normal file
12
include/patty/ax25/stats.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _PATTY_AX25_STATS_H
|
||||||
|
#define _PATTY_AX25_STATS_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
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 */
|
|
@ -7,6 +7,15 @@
|
||||||
#include <patty/kiss.h>
|
#include <patty/kiss.h>
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
|
||||||
|
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) {
|
int patty_ax25_init(patty_ax25 *ax25) {
|
||||||
memset(ax25, '\0', sizeof(*ax25));
|
memset(ax25, '\0', sizeof(*ax25));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue