Commit graph

182 commits

Author SHA1 Message Date
XANTRONIX Development
1bd93e3bcc Make functions sending RR, RNR, REJ take P/F flag
Changes:

    * Make patty_ax25_sock_send_rr() accept a P/F flag value

    * Make patty_ax25_sock_send_rnr() accept a P/F flag value

    * Make patty_ax25_sock_send_rej() accept a P/F flag value
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1ba57a8df2 Prevent I frame TX overflow
As per the AX.25 v2.2 Specification, Section 6.4.1, "Sending I Frames",
do not send an I frame if V(R) + x (TX window) equals V(S)
2024-03-01 00:20:46 -05:00
XANTRONIX Development
7fd8be445a Fix REJ handling when N(R) > V(S)
Changes:

    * Allow REJ handling to occur when the V(S) send state counter wraps
      to a value lower than indicated in the frame N(R) field

    * Fix tx_slot() in src/sock.c to not buffer overflow when the TX
      window is less than the maximum for the SABM/SABME mode
2024-03-01 00:20:46 -05:00
XANTRONIX Development
8a26cace95 Allow upgrading socks to certain versions of AX.25
Changes:

    * Add an enum patty_ax25_version argument to the function
      patty_ax25_sock_upgrade() to allow upgrading a socket to a certain
      set of AX.25 defaults
2024-03-01 00:20:46 -05:00
XANTRONIX Development
971fc2c375 Streamline responding to accept(), connect() calls
Changes:

    * Implement and use respond_accept() and respond_connect()
      convenience methods instead of stack allocating response objects,
      populating them, and using write() to send them to the client

    * When receiving XID frames in response to either an accept() or
      connect() call, respond to the client if any of the parameters
      sent from the peer are not compatible with a socket or interface,
      with the appropriate errno value
2024-03-01 00:20:46 -05:00
XANTRONIX Development
be6ff4b660 Make bind() not care about socket status 2024-03-01 00:20:46 -05:00
XANTRONIX Development
3657c883c7 Make bind() perform more validation
Changes:

    * Make bind() validate that no other socket has the same
      callsign/SSID bound to a listening socket, emitting EADDRINUSE if
      one already exists

    * Make bind() validate that no address is already bound to the
      socket, emitting EINVAL otherwise
2024-03-01 00:20:46 -05:00
XANTRONIX Development
e06a9d195e Prevent UA frame from terminating socket w/o DISC
Changes:

    * Add a "pending disconnect" state to enum patty_ax25_sock_state
     (PATTY_AX25_SOCK_PENDING_DISCONNECT), used when an originating
     system sends a DISC frame, pending a UA response

    * When handling a UA frame, rather than terminating a socket in the
      established state implicitly, check for a "pending disconnect"
      state explicitly

Other changes:

    * When a remote socket has already been obtained in handle_frame()
      in src/server.c, pass that socket to any other method that would
      otherwise be looking up the same socket
2024-03-01 00:20:46 -05:00
XANTRONIX Development
8761a4e3c2 Refactor to adhere better to AX.25 v2.2
Changes:

    * Don't use a separate dict for keeping track of sockets pending
      accept and sockets pending connect; rely more on the semantic
      meaning of the enum patty_ax25_sock_status values

    * Ensure DISC frames are acknowledged by UA frames

    * Ensure a receiving system only shuts down a connection after
      receiving a UA frame in response to a sent DISC frame

    * Ensure a sending system only shuts down a connection just prior to
      sending a UA frame in response to a received DISC frame

    * Don't use the P/F flag for the connection management U frames;
      implicitly assume the P/F flag is set to 1, and always send frames
      with a true P/F flag
2024-03-01 00:20:46 -05:00
XANTRONIX Development
fa53b8d49d Keep separate TX, RX single buffers in socks
Changes:

    * Replace patty_ax25_sock member 'buf' with 'tx_buf' and 'rx_buf'
      for transmitting or receiving single, non-sequential packets

    * Make patty_ax25_sock_upgrade() reallocate all I/O buffers based on
      window size and MTU/MRU, useful when entering SABME mode
2024-03-01 00:20:46 -05:00
XANTRONIX Development
5fa29da680 Make fd_clear() in src/server.c faster 2024-03-01 00:20:46 -05:00
XANTRONIX Development
6711f37ab9 Ensure XID frame response is encoded as responses
Changes:

    * Modify patty_ax25_sock_send_xid() to require the 'cr' argument,
      which specifies whether the frame address field is to be encoded
      with the 'command' or 'response' bits set as appropriate
2024-03-01 00:20:46 -05:00
XANTRONIX Development
803ebd0048 Simplify frame encoding
Changes:

    * Add 'format' member to patty_ax25_frame

    * Drop 'format' argument in patty_ax25_encode_reply_to()

    * Drop 'format' argument in patty_ax25_encode()

    * Consolidate private functions for encoding frame addresses to one
      much simpler function to perform encoding; simplify encoding of
      addresses in frames sent in reply to other frames
2024-03-01 00:20:46 -05:00
XANTRONIX Development
67f66d5570 Ensure socket mode is SABM or SABME as needed
When accepting a SABM or SABME frame, ensure the peer socket mode is set
accordingly to ensure control fields are encoded properly
2024-03-01 00:20:46 -05:00
XANTRONIX Development
5371f92cd9 Attempt to negotiate remote connections with XID
Implement the AX.25 v2.2 XID parameter exchange as a preamble for
initiating connections with peers, with the following workflow:

    * Upon a connect() call, send an XID frame to the peer

    * When a DM is received, assume the peer is unable to accept a
      connection

    * When a FRMR is received, assume the peer does not adhere to the
      AX.25 v2.2 standard, and attempt to initiate a connection with a
      SABM frame instead

    * When an XID is received, adapt local parameters to meet the
      needs of the peer, and respond with an SABM or an SABME frame,
      depending on which mode is indicated
2024-03-01 00:20:46 -05:00
XANTRONIX Development
c2550d075a Use patty_ax25_sock_bind_if() in server_connect()
Use patty_ax25_sock_bind_if() in server_connect() to ensure any other
functions which must take place are attended to when assigning an
interface to a socket
2024-03-01 00:20:46 -05:00
XANTRONIX Development
4bfe7da77b Handle XID frames in src/server.c
Handle XID frames in src/server.c by decoding the parameter information
and passing it to patty_ax25_sock_params_set()
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1fbf09c9ba Refactor parameter decoding/display
Changes:

    * Implement patty_ax25_params struct to contain all parameters
      supported by patty, at the interface and socket level alike

    * Move parameter enumerate types into include/patty/ax25.h, from
      include/patty/ax25/frame.h; make corrections as necessary

    * Reimplement patty_ax25_frame_decode_xid() to parse known XID
      information parameters into a patty_ax25_params object

    * Implement patty_print_params() in src/print.c

    * Refactor patty_print_frame() as patty_print_frame_header(),
      without a call to patty_print_hexdump(); this allows
      patty_print_params() to be called prior to patty_print_hexdump(),
      for better readability

    * Use patty_print_params() in examples/ax25dump.c, decode.c

    * Refactor usage of patty_ax25_frame_decode_xid() in src/server.c to
      parse XID frames into a patty_ax25_params object
2024-03-01 00:20:46 -05:00
XANTRONIX Development
a722b8f9b3 Better implementation of AX.25 v2.2 default params 2024-03-01 00:20:46 -05:00
XANTRONIX Development
aeee7449eb Use new signature for XID param callback 2024-03-01 00:20:46 -05:00
XANTRONIX Development
ffe8599db1 Rename tx, rx_bufsz to mtu, mru in src/if.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
ce8c5b1cbb Initial code for handling XID in src/server.c
Write initial code for handling XID frames in src/server.c
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1eb3d09608 Handle receipt of REJ, SREJ frames
Utilizing the sock TX ring buffer, respond to peer requests to resend
certain numbered I frames indicated by REJ and SREJ frames
2024-03-01 00:20:46 -05:00
XANTRONIX Development
c26c7509f4 Implement ring buffer for sock sent frames
Implement ring buffer for frames sent in a SABM or SABME session,
facilitating the ability to retransmit select frames upon request,
retaining a copy of the full frame and its transmitted size
2024-03-01 00:20:46 -05:00
XANTRONIX Development
6df612b910 Reply to I frames with REJ only with P/F bit set 2024-03-01 00:20:46 -05:00
XANTRONIX Development
34353fa1d9 Remove FRMR responses from server
Remove FRMR responses from server, as they are not included in the
current AX.25 v2.2 standard
2024-03-01 00:20:46 -05:00
XANTRONIX Development
9066fe10da Implement better handling of command/response bits
Implement better handling of command/response bits whilst decoding and
encoding addresses

Changes:

    * Add an enum patty_ax25_frame_cr argument to functions in
      src/sock.c which send specific types of frames

    * Detect AX.25 version >2.0 based on the command/response SSID bits

    * Simplify address copying/encoding by usage of the new function
      patty_ax25_addr_copy()

    * Implement showing AX.25 version, command/response indicator for
      frames in src/print.c
2024-03-01 00:20:46 -05:00
XANTRONIX Development
359742f949 Implement support for handling SABME frames 2024-03-01 00:20:46 -05:00
XANTRONIX Development
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
XANTRONIX Development
f0c1a0e782 I like those names better 2024-03-01 00:20:46 -05:00
XANTRONIX Development
566f302a1f Adhere to proper P/F procedure
Adhere to proper P/F procedure for SABM, I, and DISC frames
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1265108efd Reply to I frames outside of SABM(E) with DM 2024-03-01 00:20:46 -05:00
XANTRONIX Development
a4518a839a Implement better modulo-128 I and S frame support
Changes:

    * Split patty_ax25_frame_decode() into the following:

      - patty_ax25_frame_decode_address()
      - patty_ax25_frame_decode_control()

      This allows for look up an established socket for a given address
      pair, to determine if an SABME session is in progress,
      necessitating modulo-128 control decoding

    * Decode I and S N(R), N(S) sequence numbers, poll/final
      bits properly in both modulo-8 and modulo-128 mode

    * Perform better frame control validation

    * Implement the following functions in src/sock.c:

      - patty_ax25_sock_send_rr()
      - patty_ax25_sock_send_rnr()
      - patty_ax25_sock_send_rej()
      - patty_ax25_sock_send_srej()

      Corresponding functions have been removed from src/server.c

    * Implement better functions in src/sock.c for encoding frame
      control, with send/receive sequences associated with the socket,
      with modulo-128 encoding for SABME sessions

Other changes:

    * Move or delete macros from include/patty/ax25/macros.h into
      include/patty/ax25.h and include/patty/ax25/frame.h

    * Move definitions from include/patty/ax25/proto.h to header file
      include/patty/ax25.h

    * Perform better bounds checking while decoding frames

    * Improve frame control printing in src/print.c; display frame
      type names, N(R), (NS) sequence numbers, and poll/final bits
2024-03-01 00:20:46 -05:00
XANTRONIX Development
b281925eba Significantly simplify dictionaries
Significantly simplify dictionaries so that dictionary keys are always
uint32_t; this number can be an arbitrary integer, be it a file
descriptor, for instance, or a hashed value
2024-03-01 00:20:46 -05:00
XANTRONIX Development
0bfd5795ad Do a slightly better job handling sock control fields 2024-03-01 00:20:46 -05:00
XANTRONIX Development
84ae427037 Move raw frame capture to patty_ax25_if
Move raw frame interface capture to patty_ax25_if, patty_ax25_sock; this
resolves the issue wherein only bytes received, not sent, would be
captured by a raw socket bound to a specific interface with setsockopt()
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1888b70ed9 Drop patty_ax25_server member fds_w 2024-03-01 00:20:46 -05:00
XANTRONIX Development
8d24566e83 Implement generalized enumerate types; REJ reply 2024-03-01 00:20:46 -05:00
XANTRONIX Development
9ec0255204 De-embiggen an expression 2024-03-01 00:20:46 -05:00
XANTRONIX Development
84809755a1 Implement clients_by_sock convenience methods
Implement clients_by_sock convenience methods in src/server.c
2024-03-01 00:20:46 -05:00
XANTRONIX Development
3d2922f2a4 Remove trailing whitespace 2024-03-01 00:20:46 -05:00
XANTRONIX Development
ab2c283542 Refactor socket(), openif() as setsockopt()
Other changes:

    * Fix blocking on disconnects when a raw socket is bound to an
      interface
2024-03-01 00:20:46 -05:00
XANTRONIX Development
5a14f81c4a whitespace 2024-03-01 00:20:46 -05:00
XANTRONIX Development
619890c206 Shave off a few lines of code in src/server.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
73ae096b2d Implement openif(), raw packet interface access 2024-03-01 00:20:46 -05:00
XANTRONIX Development
c853b79529 Remove unnecessary #include <stdio.h> 2024-03-01 00:20:46 -05:00
XANTRONIX Development
65bfa95820 s/socket/fd/ for all such named members, variables 2024-03-01 00:20:46 -05:00
XANTRONIX Development
5a3660450f Get rid of patty_list_iterator (too expensive) 2024-03-01 00:20:46 -05:00
XANTRONIX Development
c6aac035e1 Add proto arg to patty_ax25_sock_new()
Other changes:

    * Remove proto arg from patty_ax25_sock_send() and
      patty_ax25_sock_write(); instead, use the proto member of
      patty_ax25_sock
2024-03-01 00:20:46 -05:00
XANTRONIX Development
f835f19e53 Move some stuff, remove some damn labels 2024-03-01 00:20:46 -05:00