2015-09-17 21:52:09 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2020-07-03 15:13:23 -04:00
|
|
|
#include <errno.h>
|
2015-09-17 21:52:09 -05:00
|
|
|
|
|
|
|
#include <patty/ax25.h>
|
2020-07-02 23:56:13 -04:00
|
|
|
#include <patty/print.h>
|
2015-09-17 21:52:09 -05:00
|
|
|
|
|
|
|
static void usage(int argc, char **argv, const char *message, ...) {
|
|
|
|
if (message) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, message);
|
|
|
|
vfprintf(stderr, message, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:22:42 -04:00
|
|
|
fprintf(stderr, "usage: %s [/dev/ttyXX|kiss.cap]\n", argv[0]);
|
2015-09-17 21:52:09 -05:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
patty_kiss_tnc *tnc;
|
2020-05-27 19:11:25 -04:00
|
|
|
void *buf;
|
2015-09-17 21:52:09 -05:00
|
|
|
int port;
|
|
|
|
|
Implement bin/pattyd.c
Changes:
* Implement src/conf.c, patty_conf_read(), to read a configuration
file to support a OpenBSD-style configuration file format
* Implement bin/pattyd.c to use patty_conf_read() to read a
configuration file and apply its settings to a patty_daemon
object as it is read; also implement a --standalone|-s flag to
allow the user to start a patty server without having to write
a configuration file
* Refactor patty_daemon_if_add() to accept a patty_ax25_if object;
this is necessary as bin/pattyd.c needs to be able to validate
the addresses given in a configuration file 'if' statement
* Refactor patty_ax25_server_new() to no longer accept a client
socket path; instead, patty_ax25_server_start() now accepts the
client socket path
* Remove the client socket 'path' member from patty_ax25_server in
src/server.c
* Refactor patty_kiss_tnc_new() to accept only one argument, a
patty_kiss_tnc_info object containing flags and settings needed
to open a device, use an existing file descriptor, or change
termios settings as appropriate
* Remove patty_kiss_tnc_new_fd(), as its functionality now exists
in patty_kiss_tnc_new() itself
* Add a 'flags' field to patty_kiss_tnc_info; use this bit field
to determine whether a path or file descriptor is provided by
the caller
* Make patty_ax25_if_new() accept an interface name argument, as
names are explicitly required when declaring new interfaces in
configuration files
* Make patty_kiss_tnc_new() able to accept /dev/ptmx as a device
name, regardless of whether this character device exists on a
given platform; when provided, a pseudo TTY pair is allocated
with openpty()
* Refactor examples/ax25dump.c to use the new patty_kiss_tnc_new()
calling convention
* Refactor examples/decode.c to use the new patty_kiss_tnc_new()
calling convention
* Remove examples/daemon.c in favor of bin/pattyd.c
* Rename examples/patty.conf to examples/pattyd.conf; modify to
provide values which would actually function
2020-09-01 16:38:02 -05:00
|
|
|
patty_kiss_tnc_info info;
|
|
|
|
|
2020-05-27 22:22:42 -04:00
|
|
|
if (argc > 2) {
|
|
|
|
usage(argc, argv, NULL);
|
2015-09-17 21:52:09 -05:00
|
|
|
}
|
|
|
|
|
Implement bin/pattyd.c
Changes:
* Implement src/conf.c, patty_conf_read(), to read a configuration
file to support a OpenBSD-style configuration file format
* Implement bin/pattyd.c to use patty_conf_read() to read a
configuration file and apply its settings to a patty_daemon
object as it is read; also implement a --standalone|-s flag to
allow the user to start a patty server without having to write
a configuration file
* Refactor patty_daemon_if_add() to accept a patty_ax25_if object;
this is necessary as bin/pattyd.c needs to be able to validate
the addresses given in a configuration file 'if' statement
* Refactor patty_ax25_server_new() to no longer accept a client
socket path; instead, patty_ax25_server_start() now accepts the
client socket path
* Remove the client socket 'path' member from patty_ax25_server in
src/server.c
* Refactor patty_kiss_tnc_new() to accept only one argument, a
patty_kiss_tnc_info object containing flags and settings needed
to open a device, use an existing file descriptor, or change
termios settings as appropriate
* Remove patty_kiss_tnc_new_fd(), as its functionality now exists
in patty_kiss_tnc_new() itself
* Add a 'flags' field to patty_kiss_tnc_info; use this bit field
to determine whether a path or file descriptor is provided by
the caller
* Make patty_ax25_if_new() accept an interface name argument, as
names are explicitly required when declaring new interfaces in
configuration files
* Make patty_kiss_tnc_new() able to accept /dev/ptmx as a device
name, regardless of whether this character device exists on a
given platform; when provided, a pseudo TTY pair is allocated
with openpty()
* Refactor examples/ax25dump.c to use the new patty_kiss_tnc_new()
calling convention
* Refactor examples/decode.c to use the new patty_kiss_tnc_new()
calling convention
* Remove examples/daemon.c in favor of bin/pattyd.c
* Rename examples/patty.conf to examples/pattyd.conf; modify to
provide values which would actually function
2020-09-01 16:38:02 -05:00
|
|
|
if (argc == 2) {
|
|
|
|
info.flags |= PATTY_KISS_TNC_DEVICE;
|
|
|
|
info.device = argv[1];
|
|
|
|
} else {
|
|
|
|
info.flags |= PATTY_KISS_TNC_FD;
|
|
|
|
info.fd = 0;
|
|
|
|
}
|
2020-05-27 22:22:42 -04:00
|
|
|
|
Implement bin/pattyd.c
Changes:
* Implement src/conf.c, patty_conf_read(), to read a configuration
file to support a OpenBSD-style configuration file format
* Implement bin/pattyd.c to use patty_conf_read() to read a
configuration file and apply its settings to a patty_daemon
object as it is read; also implement a --standalone|-s flag to
allow the user to start a patty server without having to write
a configuration file
* Refactor patty_daemon_if_add() to accept a patty_ax25_if object;
this is necessary as bin/pattyd.c needs to be able to validate
the addresses given in a configuration file 'if' statement
* Refactor patty_ax25_server_new() to no longer accept a client
socket path; instead, patty_ax25_server_start() now accepts the
client socket path
* Remove the client socket 'path' member from patty_ax25_server in
src/server.c
* Refactor patty_kiss_tnc_new() to accept only one argument, a
patty_kiss_tnc_info object containing flags and settings needed
to open a device, use an existing file descriptor, or change
termios settings as appropriate
* Remove patty_kiss_tnc_new_fd(), as its functionality now exists
in patty_kiss_tnc_new() itself
* Add a 'flags' field to patty_kiss_tnc_info; use this bit field
to determine whether a path or file descriptor is provided by
the caller
* Make patty_ax25_if_new() accept an interface name argument, as
names are explicitly required when declaring new interfaces in
configuration files
* Make patty_kiss_tnc_new() able to accept /dev/ptmx as a device
name, regardless of whether this character device exists on a
given platform; when provided, a pseudo TTY pair is allocated
with openpty()
* Refactor examples/ax25dump.c to use the new patty_kiss_tnc_new()
calling convention
* Refactor examples/decode.c to use the new patty_kiss_tnc_new()
calling convention
* Remove examples/daemon.c in favor of bin/pattyd.c
* Rename examples/patty.conf to examples/pattyd.conf; modify to
provide values which would actually function
2020-09-01 16:38:02 -05:00
|
|
|
if ((tnc = patty_kiss_tnc_new(&info)) == NULL) {
|
2015-09-17 21:52:09 -05:00
|
|
|
perror("Unable to open TNC");
|
|
|
|
|
2020-05-23 11:05:32 -04:00
|
|
|
goto error_kiss_tnc_open;
|
2015-09-17 21:52:09 -05:00
|
|
|
}
|
|
|
|
|
2020-05-27 19:11:25 -04:00
|
|
|
if ((buf = malloc(PATTY_KISS_BUFSZ)) == NULL) {
|
|
|
|
perror("malloc()");
|
|
|
|
|
|
|
|
goto error_malloc_buf;
|
|
|
|
}
|
|
|
|
|
2020-05-27 00:22:50 -04:00
|
|
|
while (1) {
|
2020-07-10 00:01:50 -04:00
|
|
|
ssize_t len,
|
2020-07-17 22:57:23 -04:00
|
|
|
decoded,
|
|
|
|
offset = 0;
|
|
|
|
|
2015-09-17 21:52:09 -05:00
|
|
|
patty_ax25_frame frame;
|
|
|
|
|
2020-05-27 19:11:25 -04:00
|
|
|
if ((len = patty_kiss_tnc_recv(tnc, buf, PATTY_KISS_BUFSZ, &port)) < 0) {
|
2020-07-03 15:13:23 -04:00
|
|
|
fprintf(stderr, "%s: %s: %s\n",
|
|
|
|
argv[0], "patty_kiss_tnc_recv()", strerror(errno));
|
2020-05-27 00:22:50 -04:00
|
|
|
|
2020-05-27 19:11:25 -04:00
|
|
|
goto error_kiss_tnc_recv;
|
2020-05-27 00:22:50 -04:00
|
|
|
} else if (len == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:01:50 -04:00
|
|
|
if ((decoded = patty_ax25_frame_decode_address(&frame, buf, len)) < 0) {
|
2020-07-19 20:16:08 -04:00
|
|
|
printf("Invalid frame address\n");
|
2015-09-17 21:52:09 -05:00
|
|
|
|
2020-07-10 00:01:50 -04:00
|
|
|
goto error_ax25_frame_decode_address;
|
2020-07-17 22:57:23 -04:00
|
|
|
} else {
|
|
|
|
offset += decoded;
|
2020-07-10 00:01:50 -04:00
|
|
|
}
|
|
|
|
|
2020-07-17 22:57:23 -04:00
|
|
|
if ((decoded = patty_ax25_frame_decode_control(&frame, PATTY_AX25_FRAME_NORMAL, buf, offset, len)) < 0) {
|
2020-07-19 20:16:08 -04:00
|
|
|
printf("Invalid frame control\n");
|
2020-07-10 00:01:50 -04:00
|
|
|
|
|
|
|
goto error_ax25_frame_decode_control;
|
2020-07-17 22:57:23 -04:00
|
|
|
} else {
|
|
|
|
offset += decoded;
|
2015-09-17 21:52:09 -05:00
|
|
|
}
|
|
|
|
|
2020-07-17 22:57:23 -04:00
|
|
|
if (patty_print_frame_header(stdout, &frame) < 0) {
|
2020-07-03 15:13:23 -04:00
|
|
|
fprintf(stderr, "%s: %s: %s\n",
|
2020-07-17 22:57:23 -04:00
|
|
|
argv[0], "patty_print_frame_header()", strerror(errno));
|
|
|
|
|
2020-07-19 20:16:08 -04:00
|
|
|
goto error_io;
|
2020-07-17 22:57:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (frame.type == PATTY_AX25_FRAME_XID) {
|
|
|
|
patty_ax25_params params;
|
|
|
|
|
|
|
|
if (patty_ax25_frame_decode_xid(¶ms,
|
|
|
|
buf,
|
|
|
|
offset,
|
|
|
|
len) < 0) {
|
2020-07-19 20:16:08 -04:00
|
|
|
printf("Invalid XID parameters\n");
|
2020-07-17 22:57:23 -04:00
|
|
|
|
|
|
|
goto error_ax25_frame_decode_xid;
|
2020-07-19 20:16:08 -04:00
|
|
|
} else {
|
|
|
|
if (patty_print_params(stdout, ¶ms) < 0) {
|
|
|
|
goto error_io;
|
|
|
|
}
|
2020-07-17 22:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 21:52:09 -05:00
|
|
|
|
2020-07-19 20:16:08 -04:00
|
|
|
error_ax25_frame_decode_xid:
|
|
|
|
error_ax25_frame_decode_control:
|
|
|
|
error_ax25_frame_decode_address:
|
2020-07-17 22:57:23 -04:00
|
|
|
if (patty_print_hexdump(stdout, buf, len) < 0) {
|
2020-07-19 20:16:08 -04:00
|
|
|
goto error_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fflush(stdout) < 0) {
|
|
|
|
goto error_io;
|
2015-09-17 21:52:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 19:11:25 -04:00
|
|
|
free(buf);
|
|
|
|
|
2020-06-26 22:44:19 -04:00
|
|
|
patty_kiss_tnc_destroy(tnc);
|
2015-09-17 21:52:09 -05:00
|
|
|
|
|
|
|
return 0;
|
2020-05-23 11:05:32 -04:00
|
|
|
|
2020-07-19 20:16:08 -04:00
|
|
|
error_io:
|
2020-05-27 19:11:25 -04:00
|
|
|
error_kiss_tnc_recv:
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
error_malloc_buf:
|
2020-06-26 22:44:19 -04:00
|
|
|
patty_kiss_tnc_destroy(tnc);
|
2020-05-23 11:05:32 -04:00
|
|
|
|
|
|
|
error_kiss_tnc_open:
|
|
|
|
return 127;
|
2015-09-17 21:52:09 -05:00
|
|
|
}
|