Commit graph

88 commits

Author SHA1 Message Date
XANTRONIX Development
06ddf1bbaf Fix uninintialized frame ack field
Fix uninintialized frame ack field when initializing TX slots
2024-03-01 00:20:47 -05:00
XANTRONIX Development
484981de34 Implement better frame ack strategy
Implement AX.25 v2.2, Section 6.4.6 "Receiving Acknowledgement"
semantics more consistently

Changes:

    * Add frame_ack() method in src/server.c to unify logic for
      acknowledging frames and handling I frame transmission flow
      control

    * Ensure that the Timer T1 retry counter is reset as appropriate
      when Timer T1 is restarted

    * Add excerpts from the AX.25 v2.2 documentation to accompanying
      code to better document the purpose of important aspects of the
      state machine and protocol

    * When receiving an S frame with N(R) acknowledgement of a frame
      sent earlier than indicated by V(S), set V(S) to that N(R) value

    * Implement patty_ax25_sock_resend_pending() as a means to resend
      one frame previously sent which remains unacknowledged; this
      uses V(S) to determine the frame to resend, and increments V(S) if
      there was indeed an unacknowledged frame

    * Call patty_ax25_sock_resend_pending() in src/server.c, method
      handle_sock() to send a single frame previously sent but pending
      acknowledgement
2024-03-01 00:20:47 -05:00
XANTRONIX Development
cd943f5c9c Minor syntax change, patty_ax25_sock_ack_pending() 2024-03-01 00:20:47 -05:00
XANTRONIX Development
1fd1be2cb6 Improvements to patty_ax25_sock_ack()
Changes:

    * Make patty_ax25_sock_ack() take a N(R) argument directly, rather
      than having the caller specify N(R)-1

    * Only perform acknowledgement of frames within the range between
      V(A) and N(R)-1
2024-03-01 00:20:47 -05:00
XANTRONIX Development
1819b7fb34 Rename patty_ax25_sock 'pending' to 'rx_pending'
Rename patty_ax25_sock 'pending' to 'rx_pending' to better document its
purpose
2024-03-01 00:20:47 -05:00
XANTRONIX Development
0fb7d08872 Implement patty_timer_init()
Implement patty_timer_init() to allow the caller to specify a timer
value to use each time patty_timer_start() is called, obviating the need
to pass the same argument redundantly; if the timer value must be
changed, then another call to patty_timer_init() may be used
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4577b5f223 More WIP; please kill me 2024-03-01 00:20:47 -05:00
XANTRONIX Development
f26e977bfc Implement patty_ax25_sock_ack()
Implement patty_ax25_sock_ack() to keep track of I frames sent which
have been successfully acknowledged by a peer
2024-03-01 00:20:47 -05:00
XANTRONIX Development
a5d74ecf2e Initial flow control improvements 2024-03-01 00:20:47 -05:00
XANTRONIX Development
776949b90c Implement frame segmentation/reassembly
Implement frame segmentation/reassembly state machine as per AX.25 v2.2
specifications, as per Section 6.6 "Disassembler/Reassembler" and
associated appendices
2024-03-01 00:20:47 -05:00
XANTRONIX Development
50c8a30915 Refactor frame_send() in src/sock.c
Refactor frame_send() in src/sock.c and usages thereof to pass a proto
argument, rather than implicitly using the value of sock->proto
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4befed8d45 Check for nil buffers in patty_ax25_sock_destroy()
Check before trying to free() nil buffers in patty_ax25_sock_destroy()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
a1ec1e00d0 Improve patty_ax25_sock_destroy() for raw sockets
Changes:

    * Don't clear socket from an interface's promiscuous socket table if
      the socket state is not SOCK_PROMISC

    * Destroy socket TNC if socket type is SOCK_RAW

    * Only attempt to close socket file descriptors >0
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4899aa4796 Implement SOCK_DGRAM
Implement PATTY_AX25_SOCK_DGRAM type sockets as a means of exchanging UI
frames between stations without requiring calling code to encode and
decode UI frames explicitly
2024-03-01 00:20:47 -05:00
XANTRONIX Development
b2d3d3e03f Fix strncpy() buffer size compiler warnings 2024-03-01 00:20:47 -05:00
XANTRONIX Development
ca06f34eed Rename patty_ax25_sock member 'status' to 'state' 2024-03-01 00:20:47 -05:00
XANTRONIX Development
2e56ae55eb Allow setting retry count with setsockopt()
Allow setting retry count with patty_client_setsockopt()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
04176659ec Allow changing socket ack timer with setsockopt()
Allow changing socket ack timer with patty_client_setsockopt()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
eb071de230 Add SOCK_PARAMS to patty_client_setsockopt()
Add SOCK_PARAMS to patty_client_setsockopt() to allow for setting
(presently) the MTU and TX window of a given socket to accommodate the
needs of specific remote stations
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4d47b62f5f Implement additional socket flow control
Implement the SOCK_WAIT and SOCK_READY socket flow control states to
indicate a Receive Ready or Receive Not Ready state on the remote end

Other changes:

    * Fix issue wherein flow control was never halted when the remote
      end has received k (window) number of frames without the sending
      station asking for acknowledgment
2024-03-01 00:20:47 -05:00
XANTRONIX Development
36f98bf7f0 Improve SOCK_RAW facilities
Changes:

    * Reimplement patty_ax25_sock_send() to be geared specifically for
      sending raw frames; the function which formerly held this name is
      now a private method

    * Implement patty_ax25_sock_recv() to receive a frame from a raw
      socket

    * Implement patty_ax25_sock_recv_pending() to determine how many raw
      frames are pending receipt in the buffer

    * When handling raw sockets, use patty_ax25_sock_recv_pending() to
      ensure any raw pending frames read from a client intended for
      transmission on an interface are read completely
2024-03-01 00:20:47 -05:00
XANTRONIX Development
d0d17b58fb Implement support for sending frames with SOCK_RAW
Changes:

    * When associating a promiscuous socket with an interface, rather
      than creating a patty_kiss_tnc object, simply store the socket
      file descriptor and use patty_kiss_frame_send() to send incoming
      or outgoing frames for that interface to the promiscuous socket

    * Add special initialization code in src/sock.c for SOCK_RAW; don't
      allocate any buffers, but instead set a few flags and otherwise
      use 0-initialized defaults

    * Implement handle_sock_raw() in src/server.c to check to see if any
      raw frames are pending, and if so, send them to the associated
      interface if provided by setsockopt()

    * Make patty_ax25_sock_bind_if() only call the function
      patty_ax25_if_add_promisc() only if the socket status is PROMISC;
      this allows support for non-promiscuous sockets used for outbound
      purposes
2024-03-01 00:20:47 -05:00
XANTRONIX Development
967f2f6830 Rename patty_ax25_sock sequences per Section 4.2.4
Changes:

    * Rename seq_send to vs, ie, V(S)

    * Rename seq_recv to vr, ie, V(R)

    * Ensure handling RR responses updates V(S) with the N(R) value of
      the received frame
2024-03-01 00:20:47 -05:00
XANTRONIX Development
2db5a0d0b9 Fix issues with TX slots in src/sock.c
Fix issues with TX slots in src/sock.c wherein packets saved for resend
would not be able to be resent, as their total length was not encoded
properly into the slot structure
2024-03-01 00:20:46 -05:00
XANTRONIX Development
575adc5d31 Fix numerous XID negotiation bugs
Changes:

    * Fix Classes of Operations and HDLC parameter bit flags in
      include/patty/ax25.h to match the documentation after more careful
      analysis; resolve issues with byte order

    * Add support for previously missing HDLC parameters to function
      patty_print_params()

    * Fix Info TX/RX field encodings to be in bits, rather than bytes

    * Implement patty_ax25_sock_realloc_bufs() to reallocate buffers
      based on current window and I frame sizes

    * Implement patty_ax25_sock_params_upgrade() to upgrade a socket's
      parameters to the AX.25 v2.2 documented defaults; this will not
      change parameters if the socket is already set to v2.2

    * Implement patty_ax25_sock_params_max() to upgrade a socket's
      parameters to the highest values supported by patty

    * Reimplement patty_ax25_sock_send_xid() to send highest desired
      parameters, rather than the values currently set on the socket

    * When receiving XID frames destined to listening sockets, use
      patty_ax25_sock_params_max() to negotiate from high to low
      parameters

    * When receiving SABME flags, use patty_ax25_sock_params_upgrade()
      to ensure at least base AX.25 v2.2 parameter defaults are set

    * Fix issue where outbound connections initiated with XID were
      unable to time out after N retries
2024-03-01 00:20:46 -05:00
XANTRONIX Development
eb04bc4bb5 Fix XID I field size TX, RX parameter encoding
Fix XID I field size TX, RX parameter encoding to indicate the I frame
size in bits, rather than octets
2024-03-01 00:20:46 -05:00
XANTRONIX Development
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
XANTRONIX Development
2c3b9ab799 Implement patty_ax25_sock_send_test()
Implement patty_ax25_sock_send_test() to send TEST frames
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
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
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
08d7594433 Remove unused maxsz() inline in src/sock.c 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
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
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
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
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