Commit graph

63 commits

Author SHA1 Message Date
cb33d799ff Implement patty_ax25_if_driver
Changes:

    * Implement patty_ax25_if_driver type, providing a vtable with
      pointers to methods implementing an AX.25 interface PHY

    * Implement patty_ax25_if_name() to return a pointer to the name
      string of an AX.25 interface

    * Decouple patty_kiss_tnc from src/if.c using patty_ax25_if_driver

    * Remove port input/output arguments from patty_kiss_tnc_send()
      and patty_kiss_tnc_recv(), respectively; use 0 as the default,
      but keep the port argument in patty_kiss_frame_send()

    * Implement patty_ax25_if_fd() to return file descriptor backing a
      PHY; use this rather than patty_kiss_tnc_fd() in src/server.c to
      further decouple interfaces from their implementation

    * Remove 'enum patty_ax25_if_type' type; refactor constructor
      patty_ax25_if_new() to no longer take this as an argument, but
      rather a patty_ax25_if_driver to use to instantiate the PHY
      with the information pointer passed

    * Break out patty_kiss_tnc code from src/kiss.c into src/tnc.c,
      leaving only patty_kiss_frame_send() in the original; this is
      needed to prevent a cyclic dependency within patty_ax25_sock and
      other areas

    * Rename patty_bin_if_config() to patty_bin_if_create(); a separate
      patty_bin_if_config() will likely be created later as necessary
      to change an existing interface

    * Split PHY-specific interface configuration code into separate
      delegates in bin/if.c

    * Implement usage of patty_error to better capture internal error
      states not currently representable with semantic error numbers
      while configuring and instantiating PHYs

    * Pass patty_error object to patty_bin_kiss_config() to receive
      detailed error information
2024-03-01 00:20:47 -05:00
639ec8beb7 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
2024-03-01 00:20:47 -05:00
5cb98de5d0 Allow setting baud, flow control for TNCs
Changes:

    * Add argument to patty_kiss_tnc_new(), patty_kiss_tnc_new_fd(),
      a pointer to patty_kiss_tnc_info, to allow specifying baud and
      flow control

    * Rework patty_ax25_if_kiss_tnc_info to hold patty_kiss_tnc_info as
      a hack to allow instantiating a KISS TNC-based network interface
      with desired baud and flow control
2024-03-01 00:20:47 -05:00
5edb889471 Use tcflush() before tcsetattr() in src/kiss.c 2024-03-01 00:20:47 -05:00
6027a71e28 Use O_NOCTTY in patty_kiss_tnc_open() 2024-03-01 00:20:47 -05:00
f54db37a7e Always clear KISS frame decode state on FEND
Always completely discard KISS frame decode state when encountering an
FEND character
2024-03-01 00:20:47 -05:00
b5ec25eb6a Don't check errno on EOF in patty_kiss_tnc_recv() 2024-03-01 00:20:47 -05:00
63a1c2d56e Clear unwanted errno in patty_kiss_tnc_new_fd()
Clear unwanted errno in patty_kiss_tnc_new_fd() when isatty() returns
false on a file descriptor
2024-03-01 00:20:47 -05:00
b99a6607ba Use tcflush() in patty_kiss_tnc_new()
Use tcflush() to initialize TTY state in patty_kiss_tnc_new(), so that
no unexpected data causes KISS framing errors
2024-03-01 00:20:47 -05:00
1493f913a7 Don't use tcdrain() in patty_kiss_frame_send()
Don't use tcdrain() in patty_kiss_frame_send(), as this may cause a
program to block indefinitely on BSD systems
2024-03-01 00:20:47 -05:00
b2d3d3e03f Fix strncpy() buffer size compiler warnings 2024-03-01 00:20:47 -05:00
c417461a0b Implement patty_kiss_frame_send()
Implement patty_kiss_frame_send() as a means of sending a KISS frame
without requiring a patty_kiss_tnc object
2024-03-01 00:20:47 -05:00
16179894d2 Add tcdrain() at end of patty_kiss_tnc_send() 2024-03-01 00:20:46 -05:00
671d4ef337 Don't tcsetattr() ptmx in patty_kiss_tnc_destroy()
Avoid tcsetattr() on a ptmx in patty_kiss_tnc_destroy(), as the old
attributes are not saved when opening a Unix98 PTY master
2024-03-01 00:20:46 -05:00
1f4ffc98ac Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally

Changes:

    * Implement patty_client_new() to handle opening the server Unix
      domain socket, and to allocate a dict for mapping server-side
      sockets with current process file descriptors

    * Reimplement all server calls in src/call.c around the new
      patty_client type; calls which result in the creation of a
      Unix98 PTY by the patty server now handle opening the local PTY
      and setting the file descriptor to raw mode.  Furthermore, these
      calls deal exclusively in terms of current process file
      descriptors

    * Refactor src/server.c to use the new patty_client type and calls

    * Refactor examples/client.c, examples/server.c, examples/ax25dump.c
      to use the new patty_client type and calls

    * Fix a bug in src/server.c, respond_accept() wherein a 0, rather
      than the file descriptor of the socket, is sent to the client as a
      return value
2024-03-01 00:20:46 -05:00
81d063cb68 Skip tcgetattr() in patty_kiss_tnc_new_fd() w/ptmx
Modify patty_kiss_tnc_new_fd() to avoid tcgetattr()/tcsetattr() when
passed a file descriptor for a PTY master, to address incompatibility
with BSD kernelspace Unix98 PTY implementations
2024-03-01 00:20:46 -05:00
09df948871 Only set use tcsetattr() on TTYs for KISS TNCs
Fix patty_kiss_tnc_new_fd() to only attempt tcgetattr()/tcsetattr() on
file descriptors for whom isatty() is true, allowing files and sockets
to once again be used
2024-03-01 00:20:46 -05:00
10745bbabf Set raw TTY attributes on patty_kiss_tnc_new_fd()
Changes:

    * Use cfmakeraw() to set raw TTY attributes in KISS TNC constructor
      patty_kiss_tnc_new_fd()

    * Restore previous TTY attributes in patty_kiss_tnc_destroy()
2024-03-01 00:20:46 -05:00
4f3f8bd5e5 Use S_IFMT mask to test for S_IFSOCK in src/kiss.c 2024-03-01 00:20:46 -05:00
216bd91050 Let patty_kiss_tnc_new() use Unix domain sockets
Modify patty_kiss_tnc_new() to connect to a Unix domain socket
2024-03-01 00:20:46 -05:00
905d5b117c Better handle read()s of multiple frames from TNC
Implement better handling of situations when read() captures multiple
TNC frames; ensure each frame is handled in src/server.c, function
handle_iface(), to ensure packets aren't ignored before the next
select() call
2024-03-01 00:20:46 -05:00
ebbfb50b1c Use KISS framing for raw sockets
Use KISS framing for raw sockets to avoid multiple write() calls from
being buffered, which caused read() on the other end of a file
descriptor to read more than frame at once
2024-03-01 00:20:46 -05:00
bdb73c8805 Making significant headway towards a working server 2024-03-01 00:20:46 -05:00
b5ed9e9b61 Fix patty_kiss_tnc_recv() reads less than bufsz
Fix issues with patty_kiss_tnc_recv() when read() calls return less than
the allocated buffer size
2024-03-01 00:20:46 -05:00
307a668d6d That hurt 2024-03-01 00:20:46 -05:00
d266058ad4 Fix patty_kiss_tnc_recv() issues
Fix patty_kiss_tnc_recv() issues with small buffers (~330 bytes) by
more properly detecting EOF being the condition at which the current
decoder offset in the buffer is equal to the last buffer read size; the
offset can never be the number of bytes read, and the initial read
length is -1, so early EOF conditions are avoided
2024-03-01 00:20:46 -05:00
2e0adee54e Remove _unix suffix from patty_kiss_tnc_fd_unix() 2024-03-01 00:20:46 -05:00
750ab452d2 Refactor patty_kiss_tnc_recv()
Refactor patty_kiss_tnc_recv() to always read a fixed number of bytes
into a circular buffer

Other changes:

    * Avoid needing memmove() per packet processed

    * Allow processing packets larger than the internal read buffer
2024-03-01 00:20:46 -05:00
66e5de9d6c Make patty_kiss_tnc_open() use default buffer size
Make patty_kiss_tnc_open() use default buffer size

Other changes:

    * Make src/decode.c no longer require a filename to use as a TNC
2024-03-01 00:20:46 -05:00
d44889121e Do not decode KISS frames into internal buffer
Changes:

    * Modify patty_kiss_tnc_recv() to accept a pointer to a read buffer,
      and a maximum length argument, to receive one packet

    * Modify src/decode.c to use the new patty_kiss_tnc_recv() calling
      form
2024-03-01 00:20:46 -05:00
e74941f714 Fix patty_kiss_tnc_send()
Fix patty_kiss_tnc_send() to ensure frames survive unmodified through
round trips of patty_kiss_tnc_send() and patty_kiss_tnc_recv() calls
2024-03-01 00:20:46 -05:00
54a521e8a8 Use only one write(2) call per frame start
Use only one write(2) call per frame start in src/kiss.c
2024-03-01 00:20:46 -05:00
d7ab08338c Implement patty_kiss_tnc_open_fd()
Implement patty_kiss_tnc_open_fd() to create a TNC object for an
existing Unix file descriptor
2024-03-01 00:20:46 -05:00
ede262397b Refactor patty_kiss_tnc_recv()
Refactor patty_kiss_tnc_recv() to be much more compact and correct;
ensure the KISS command byte is absolutely required, and that
consecutive frame end markers are handled without error
2024-03-01 00:20:46 -05:00
663965db71 Getting there 2024-03-01 00:20:46 -05:00
9217b0366f Sprucing things up a bit 2024-03-01 00:20:46 -05:00
f1e7fc356f Use enum kiss_flags type, not int 2024-03-01 00:20:46 -05:00
df23b0b8e3 Remove irrelevant comment 2024-03-01 00:20:46 -05:00
de0c0ef844 Use uint8_t instead of unsigned char in src/kiss.c 2024-03-01 00:20:46 -05:00
b44a6789a8 Keep escape sequences as static variables 2024-03-01 00:20:46 -05:00
1666666e9d This is all very necessary if I am to wrest tight control over frame decoding into my own hands 2024-03-01 00:20:46 -05:00
63f031b461 It occurs to me I'll need patty_kiss_tnc_decode() to be exported 2024-03-01 00:20:46 -05:00
2c0974658a I'm running out of shitty commit messages 2024-03-01 00:20:46 -05:00
ff76e77336 Stub out patty_ax25_next_event() 2024-03-01 00:20:46 -05:00
86b099bd58 Hmm! Getting somewhere maybe 2015-07-20 23:21:45 -05:00
22874e6e06 Since we broke off, I'm using lipstick again 2015-07-17 00:45:14 +00:00
775c2c5283 s/errors/dropped/g 2015-07-15 21:59:56 -05:00
9af63066b6 Go to hell and back to get valid frames off the wire, and keep track of error counts 2015-07-15 21:59:08 -05:00
6a427c4097 Make tnc_buffer() only return bytes actually read 2015-07-15 21:45:46 -05:00
e7b1c2cf54 Riveting commentary 2015-07-15 21:19:34 -05:00