Commit graph

423 commits

Author SHA1 Message Date
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
810361647a Switch to struct timeval for sock timers 2024-03-01 00:20:46 -05:00
XANTRONIX Development
a0660345bb Fix typo in patty_ax25_sock_reset()
Fix typo in patty_ax25_sock_reset() wherein n_maxlen_rx would never be
initialized with its proper default
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
1a87ac3858 Improve patty_ax25_sock_params_set() validation
Changes:

    * Improve patty_ax25_sock_params_set() validation by setting ENOTSUP
      when setting options on a socket that don't make sense, such as no
      Asynchronous Balanced Mode
2024-03-01 00:20:46 -05:00
XANTRONIX Development
e90b5803bf Add validation to patty_ax25_sock_send_xid()
Changes:

    * Make patty_ax25_sock_send_xid() set ENETDOWN when no network
      interface is associated with a sock
2024-03-01 00:20:46 -05:00
XANTRONIX Development
fe72380888 Add validation to patty_ax25_sock_send()
Changes:

    * Make patty_ax25_sock_send() set ENETDOWN when no network interface
      is associated with a sock

    * Make patty_ax25_sock_send() set EBADF when no remote address is
      associated with a sock
2024-03-01 00:20:46 -05:00
XANTRONIX Development
2c585ca4fe Keep default Classes of Procedures for socks, ifs
Keep distinct default Classes of Procedures parameter flag values for
sockets and interfaces, as the Asynchronous Balanced Mode parameter does
not apply to the interface itself, and the Half/Full Duplex parameters
do not apply to the sock
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
529112225a Make duplicate interface addresses emit EADDRINUSE 2024-03-01 00:20:46 -05:00
XANTRONIX Development
1bad5978ec Better denote command/response frames 2024-03-01 00:20:46 -05:00
XANTRONIX Development
4f3f8bd5e5 Use S_IFMT mask to test for S_IFSOCK in src/kiss.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
f75a78eb4b Encode I frames as commands 2024-03-01 00:20:46 -05:00
XANTRONIX Development
8d7800fe95 Abbreviate 'command' and 'response' as 'C', 'R'
patty_print_frame_header(): Abbreviate 'command' and 'response' as 'C'
and 'R'
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
edfc32ce33 Fix patty_ax25_frame_decode_control() P/F flag bug
Fix patty_ax25_frame_decode_control() P/F flag bug which occurred due to
not implicitly using the 8-bit control field format when parsing U
frames
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
0fa6a29024 Fix subtle sequence issues in src/sock.c
Fix subtle sequence issues in src/sock.c wherein non-I frames which are
sent may overwrite a previously sent I frame with the same sequence
number, which would cause issues with the remote end expecting an I
frame and possibly getting a non-I frame
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
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
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
311a8b106f Fix small stylistic issues 2024-03-01 00:20:46 -05:00
XANTRONIX Development
acce657f63 Fix byte order of extended control encode, decode
Fix byte order of extended format control encoding and decoding in the
following src/frame.c functions:

    * patty_ax25_frame_decode_control()

    * patty_ax25_frame_encode_reply_to()
2024-03-01 00:20:46 -05:00
XANTRONIX Development
08c952ae07 Fix issue setting parameter bit fields in sock.c
Fix issue setting parameter bit fields in patty_ax25_sock_send_xid() in
src/sock.c, wherein the numerical values were simply bitwise ORed
2024-03-01 00:20:46 -05:00
XANTRONIX Development
d494ffecfc Fix issues encoding extended frame control fields
Changes:

    * When encoding extended frame control fields, ensure the least
      significant byte is written first, as per the AX.25 v2.2 standard
2024-03-01 00:20:46 -05:00
XANTRONIX Development
8b741cadc8 Remove patty_ax25_sock_mode_set() 2024-03-01 00:20:46 -05:00
XANTRONIX Development
754baabf11 Don't exit when unable to decode specific frames
Changes:

    * Modify examples/ax25dump.c and decode.c to not die upon failure to
      decode a specific frame or field; instead, indicate the error,
      print a hex dump of the frame, and move on to the next frame
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
052c7d94d0 Implement functions for setting params on sockets
Changes:

    * Implement patty_ax25_sock_upgrade() to upgrade a socket from the
      default AX.25 2.0 parameters to AX.25 2.2 parameters, meant to be
      used upon receipt of an XID frame

    * Implement patty_ax25_sock_params_set() to set lowest common
      denominator parameters to a socket, downgrading or adapting to the
      parameters advertised by a peer XID frame as necessary
2024-03-01 00:20:46 -05:00
XANTRONIX Development
a4f50d6bea Add Classes of Procedures, HDLC params to sockets
Changes:

    * Define different sets of default parameters for AX.25 versions
      2.2 and prior

    * Add flags_classes, flags_hdlc and version to patty_ax25_sock

    * Remove flags member from patty_ax25_sock

    * Inherit Classes of Procedures value from interface when an
      interface is bound to a socket
2024-03-01 00:20:46 -05:00
XANTRONIX Development
5a64ea15d3 Don't send TX I len, TX window in XID frames
Don't send TX I len, TX window in XID frames, as the only relevant
information the peer can action upon is the originating station's
RX parameters
2024-03-01 00:20:46 -05:00
XANTRONIX Development
bd148fff10 Add Class of Procedures flag to patty_ax25_if 2024-03-01 00:20:46 -05:00
XANTRONIX Development
cd41101425 Declare default classes of procedures in ax25.h 2024-03-01 00:20:46 -05:00
XANTRONIX Development
ab27aebb55 Remove enum patty_ax25_sock_flags 2024-03-01 00:20:46 -05:00
XANTRONIX Development
87a9f1eb3f Fix sequencing issues with SABM vs SABME sockets 2024-03-01 00:20:46 -05:00
XANTRONIX Development
420b406411 Use fflush() for each frame in examples/ax25dump.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
305653e19b Don't bind SSID to interface addresses
Changes:

    * Remove ssid arguments from functions in src/if.c
2024-03-01 00:20:46 -05:00
XANTRONIX Development
e95994bf19 Implement patty_ax25_sock_send_xid()
Implement patty_ax25_sock_send_xid() to send the current socket
parameters to a remote peer
2024-03-01 00:20:46 -05:00
XANTRONIX Development
92ff180d57 Use bigger defaults for session parameters
Changes:

    * Declare bigger defaults for certain session parameters in
      include/patty/ax25/sock.h

    * Use patty_ax25_sock_reset() to initialize parameter variables in
      patty_ax25_sock_new(), to save many lines of code

    * Add patty_ax25_sock member n_ack
2024-03-01 00:20:46 -05:00
XANTRONIX Development
afbaeea95e Implement patty_ax25_frame_encode_xid()
Implement patty_ax25_frame_encode_xid() to encode a patty_ax25_params
object into a buffer to be used as an Information field
2024-03-01 00:20:46 -05:00
XANTRONIX Development
6911a59455 Rename patty_ax25_params 'found' to 'flags' 2024-03-01 00:20:46 -05:00
XANTRONIX Development
5e1d74c971 Rename 'flag' arguments to 'pf' in sock methods 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