Commit graph

353 commits

Author SHA1 Message Date
XANTRONIX Development
a08a70151c Better implementations of Timers T1, T2 and T3
More strictly adhere to the behaviors of Timers T1, T2 and T3 as
prescribed in the AX.25 v2.2 Specification, Section 4.4.5 "Timeout Error
Recovery" descriptions for Timer T1 and T3, as well as Section 6.7.1.2
"Response Delay Timer T2"
2024-03-01 00:20:46 -05:00
XANTRONIX Development
ba3923495e Implement patty_timer type
Changes:

    * Implement patty_timer type to store both a struct timeval and a
      bitfield for indicating timer state; currently, this only holds
      the PATTY_TIMER_RUNNING flag to indicate whether a timer has been
      stopped (irrespective of its "expired" status)

    * Remove 'target' argument from patty_timer_start(); instead, rely
      on select() polling every 1s to cause events to trigger at a
      regular interval

    * Make patty_timer_expired() return false if PATTY_TIMER_RUNNING is
      not set

    * Implement patty_timer_stop() to clear the PATTY_TIMER_RUNNING flag
      of a timer

    * Make patty_timer_clear() set all fields to zero, including
      clearing the PATTY_TIMER_RUNNING flag
2024-03-01 00:20:46 -05:00
XANTRONIX Development
a619bc4906 Start Timer T1 when sending I frames 2024-03-01 00:20:46 -05:00
XANTRONIX Development
e432d57ff3 Fix incorrect control P/F encoding in src/sock.c
Fix incorrect control P/F encoding in src/sock.c wherein the P/F flag
value was passed to patty_ax25_sock_send() as an information field body
length, rather than the pf argument for the internal functions
control_i(), control_s(), and control_u(); this corrects the following
functions:

    * patty_ax25_sock_send_rr()

    * patty_ax25_sock_send_rnr()

    * patty_ax25_sock_send_rej()
2024-03-01 00:20:46 -05:00
XANTRONIX Development
aa2fd9b06d Implement Response Delay Timer T2
Implement AX.25 v2.2 Section 6.7.1.2 "Response Delay Timer T2" as per
specification; do not acknowledge several sequential I frames until a
certain period of time has passed since the receipt of the most recent I
frame
2024-03-01 00:20:46 -05:00
XANTRONIX Development
05cac588f2 Send REJ implicitly for out-of-order I frames
Send REJ implicitly for out-of-order I frames, regardless of I frame P/F
flag
2024-03-01 00:20:46 -05:00
XANTRONIX Development
62c116a17c Fix I frame encoding issue
Fix I frame encoding issue in patty_ax25_sock_write() wherein the N(S)
field was incorrectly encoded one bit too far to the right in the
control field
2024-03-01 00:20:46 -05:00
XANTRONIX Development
c61b09dedc Only use TX slot for outgoing I frames
In patty_ax25_sock_send(), only use a numbered TX slot in the ring
buffer when sending I frames, rather than the prior case when the frame
was not a U frame
2024-03-01 00:20:46 -05:00
XANTRONIX Development
55d40749a4 Fix patty_timer_start()
Fix patty_timer_start() to only set the running timer to the value of
the timer being started, rather than adding the value of the started
timer to the running timer
2024-03-01 00:20:46 -05:00
XANTRONIX Development
d6fbea1824 Fix patty_timer_expired()
Fix patty_timer_expired() to only check the tv_sec field for a value <=0
when testing for expiry
2024-03-01 00:20:46 -05:00
XANTRONIX Development
08d7594433 Remove unused maxsz() inline in src/sock.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
c321f6150e Add byte order swapping macros to configure
Changes:

    * Make ./configure generate src/config.h, which will contain the
      appropriate #include for endian.h, or #defines to provide
      alternatives

    * Make sure to include config.h in src/frame.c to allow compiling
      on macOS
2024-03-01 00:20:46 -05:00
XANTRONIX Development
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
XANTRONIX Development
e10ce6b8e1 Implement generic timer functions in src/timer.c
Changes:

    * Implement patty_timer_expired() to determine if a timer has
      expired or has gone negative

    * Implement patty_timer_cancel() to set a timer to zero

    * Implement patty_timer_start() to initialize a timer, add a
      specified number of milliseconds, and ensure a target timer (such
      as the server timer) is set for at least that value as well

    * Implement patty_timer_tick() to subtract an elapsed time value
      from a timer

    * Remove functions specific to each timer in src/sock.c, as those
      can now be handled generically by src/timer.c

    * Replace calls to patty_ax25_sock_timer_t1_*() with patty_timer_*()
      calls instead; reference the struct timeval objects directly
      within the sock (for the time being, pending opaque structures)
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1060ff6ab8 Rename timers to their documented T1, T2, T3 names 2024-03-01 00:20:46 -05:00
XANTRONIX Development
8632e7ccb8 Merge patty_ax25_sock_timer_ack_restart(), _set()
Changes:

    * Combine patty_ax25_sock_ack_timer_restart() and _set() into one
      method, patty_ax25_sock_ack_timer_start(), which accepts a new
      struct timeval argument to potentially add the Timer T1 value to

    * Reorder some functions in src/sock.c, include/patty/ax25/sock.h
2024-03-01 00:20:46 -05:00
XANTRONIX Development
9db9234a56 Make sure to activate Timer T1 in connect() 2024-03-01 00:20:46 -05:00
XANTRONIX Development
499445d8b1 Implement patty_ax25_timer_ack_set()
Implement patty_ax25_timer_ack_set() to set a timer to at least the
value indicated in Timer T1
2024-03-01 00:20:46 -05:00
XANTRONIX Development
7ed169d7cc Implement XID, SABM, SABME ack timer in server
Implement XID, SABM, SABME ack Timer T1 semantics in src/server.c, as
per AX.25 v2.2 Section 6.3.1 "Link Connection Establishment"
2024-03-01 00:20:46 -05:00
XANTRONIX Development
8ab4c24b4a Implement XID/SABM/SABME ack timers
Changes:

    * Implement patty_ax25_sock_timeR_ack_restart() to initialize the
      XID/SABM/SABME ack Timer T1

    * Implement patty_ax25_sock_timer_ack_cancel() to clear Timer T1

    * Implement patty_ax25_sock_timer_ack_sub() to subtract the value of
      a struct timeval from Timer T1

    * Implement patty_ax25_sock_timer_ack_expired() to indicate if the
      ack Timer T1 has expired

Other changes:

    * Rearrange patty_ax25_sock a bit
2024-03-01 00:20:46 -05:00
XANTRONIX Development
578c9183e8 Remove patty_ax25_sock_send_sabme()
Remove patty_ax25_sock_send_sabme() in favor of making send_sabm() check
the socket for SABM or SABME mode and send the correct frame accordingly
2024-03-01 00:20:46 -05:00
XANTRONIX Development
9463e22481 Use ptsname(), not ptsname_r(), for portability 2024-03-01 00:20:46 -05:00
XANTRONIX Development
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
XANTRONIX Development
0aea65487a (Re)implement patty_ax25_sock_reset()
Begin to reimplement patty_ax25_sock_reset() to follow the AX.25 v2.2
Specification, Section 6.5 "Resetting Procedure" indications to set V(S)
and V(R) to 0
2024-03-01 00:20:46 -05:00
XANTRONIX Development
df7c0fad38 Rename patty_ax25_sock_reset() to _init(),
Rename patty_ax25_sock_reset() to patty_ax25_sock_init(), so as to allow
for the implementation of a future _reset() method which shall be used
to implement AX.25 v2.2 Section 6.5 "Resetting Procedure"
2024-03-01 00:20:46 -05:00
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
7b25597e6e realloc() TX/RX bufs on XID negotiation 2024-03-01 00:20:46 -05:00
XANTRONIX Development
3ef0da27b5 Ensure socket TX buf size is separate from RX size
After performing XID parameter negotiation, do not simply use the
negotiated TX buffer size when allocating the RX buffer; this resolves
an issue wherein read()s into the RX buffer (allocated with a size equal
to the TX buffer, which may be smaller) would cause memory errors
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
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