10#define ARQ_PROTOCOL_H_
34#define ARQ_HDR_SUBTYPE_IDX 1
35#define ARQ_HDR_FLAGS_IDX 2
36#define ARQ_HDR_SESSION_IDX 3
37#define ARQ_HDR_SEQ_IDX 4
38#define ARQ_HDR_ACK_IDX 5
39#define ARQ_HDR_SNR_IDX 6
40#define ARQ_HDR_DELAY_IDX 7
41#define ARQ_FRAME_HDR_SIZE 8
52#define ARQ_CONNECT_SESSION_IDX 1
53#define ARQ_CONNECT_PAYLOAD_IDX 2
54#define ARQ_CONNECT_SESSION_MASK 0x7F
55#define ARQ_CONNECT_ACCEPT_FLAG 0x80
56#define ARQ_CONTROL_FRAME_SIZE 14
57#define ARQ_CONNECT_META_SIZE 2
58#define ARQ_CONNECT_MAX_ENCODED (ARQ_CONTROL_FRAME_SIZE - ARQ_CONNECT_META_SIZE)
59#define ARQ_CONNECT_DST_CRC_SIZE 2
60#define ARQ_CONNECT_SRC_MAX_ENCODED (ARQ_CONNECT_MAX_ENCODED - ARQ_CONNECT_DST_CRC_SIZE)
68#define ARQ_CQ_PAYLOAD_IDX 1
69#define ARQ_CQ_SRC_MAX_ENCODED (ARQ_CONTROL_FRAME_SIZE - ARQ_CQ_PAYLOAD_IDX)
72#define ARQ_BW_TOKEN_NONE 0
73#define ARQ_BW_TOKEN_500 1
74#define ARQ_BW_TOKEN_2300 2
75#define ARQ_BW_TOKEN_2750 3
109#define ARQ_BURST_MAX 5
124#define ARQ_CONTROL_MODE FREEDV_MODE_DATAC16
129#define ARQ_CHANNEL_GUARD_MS 700
138#define ARQ_ISS_POST_ACK_GUARD_MS 900
148#define ARQ_ACCEPT_RX_WINDOW_MS 9000
159#define ARQ_LISTEN_OFF_GRACE_MS 2000
160#define ARQ_CALL_RETRY_SLOTS_DEFAULT 4
166#define ARQ_CALL_FAST_SLOTS_DEFAULT 2
171#define ARQ_CALL_FAST_SLOTS_MAX 4
177#define ARQ_CALL_FAST_SLOTS atomic_load(&arq_call_fast_slots)
183#define ARQ_ACCEPT_RX_WINDOW_FLOOR_MS 26000
184#define ARQ_ACCEPT_RETRY_SLOTS_DEFAULT 4
185#define ARQ_DISCONNECT_RETRY_SLOTS_DEFAULT 2
197#define ARQ_TX_MFSK_ONLY atomic_load(&arq_tx_mfsk_only)
203#define ARQ_CALLINT_MIN_S 4.0f
204#define ARQ_CALLINT_DEFAULT_S 0.0f
211#define ARQ_RETRY_STAGGER_MS_DEFAULT 2000
212#define ARQ_RETRY_STAGGER_MS_MAX 5000
228#define ARQ_SILENCE_FALLBACK_S_DEFAULT 150
229#define ARQ_SILENCE_FALLBACK_S_MIN 110
230#define ARQ_SILENCE_FALLBACK_S_MAX 600
239#define ARQ_CALL_MAX_S_DEFAULT 300
240#define ARQ_CALL_MAX_S_MAX 3600
262 const char *local_call,
const char *connect_src,
264 char *src,
char *dst,
size_t bufsz);
266#define ARQ_CALL_RETRY_SLOTS atomic_load(&arq_call_retry_slots)
267#define ARQ_ACCEPT_RETRY_SLOTS atomic_load(&arq_accept_retry_slots)
268#define ARQ_DISCONNECT_RETRY_SLOTS atomic_load(&arq_disconnect_retry_slots)
275#define ARQ_ACK_DATA_GAP_MS 300
287#define ARQ_CHANNEL_SYNC_HOLD_MS 250
288#define ARQ_CHANNEL_DEFER_MS 500
289#define ARQ_CHANNEL_DEFER_MAX 20
298#define ARQ_CHANNEL_DEFER_KEYED_MAX 64
305#define ARQ_CALL_DECODE_WAIT_MS (4500 + ARQ_CHANNEL_DEFER_MS)
309#define ARQ_REPLY_WINDOW_MARGIN_MS 1000
313#define ARQ_SNR_HYST_DB 5.0f
314#define ARQ_SNR_MIN_DATAC15_DB -7.0f
316#define ARQ_SNR_MIN_DATAC4_DB -6.0f
319#define ARQ_SNR_MIN_DATAC3_DB -1.0f
320#define ARQ_SNR_MIN_DATAC1_DB 3.0f
321#define ARQ_SNR_MIN_DATAC17_DB 7.0f
324#define ARQ_SNR_MIN_QAM16C2_DB 13.0f
336#define ARQ_DISCONNECT_DRAIN_TIMEOUT_S_DEFAULT 45
338#define ARQ_DISCONNECT_DRAIN_TIMEOUT_S atomic_load(&arq_disconnect_drain_timeout_s)
436 uint8_t session_id, uint8_t snr_raw);
473#define ARQ_CONNECT_MINOR 1
474#define ARQ_CONNECT_EXT_BW_MASK 0x03
475#define ARQ_CONNECT_EXT_MINOR_SHIFT 2
476#define ARQ_CONNECT_EXT_MINOR_MASK 0x0C
477#define ARQ_CONNECT_EXT_TXMFSK 0x10
478#define ARQ_ACCEPT_CALLED_CRC_IDX 4
479#define ARQ_ACCEPT_NONCE_IDX 6
480#define ARQ_ACCEPT_LEVEL_IDX 8
481#define ARQ_ACCEPT_LEVEL_MASK 0x07
482#define ARQ_ACCEPT_CTL_DEAF_BIT 0x08
484#define ARQ_ACCEPT_SNR_IDX 9
490 const char *caller,
const char *called,
491 int bw_hz,
bool tx_mfsk);
500 const char *called,
const char *caller,
501 int bw_hz,
int start_level,
bool ctl_deaf,
502 float call_snr_db, uint16_t nonce,
514 const char *callsign);
520 uint8_t *session_id_out,
char *caller_out,
521 int *bw_hz_out,
bool *tx_mfsk_out);
542 const char *src,
int bw_hz);
548 char *src_out,
int *bw_hz_out);
int arq_protocol_bw_hz_from_token(uint8_t bw_token)
Map an on-air BW token back to Hz.
Definition arq_protocol.c:277
int arq_protocol_build_accept(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *called, const char *caller, int bw_hz, int start_level, bool ctl_deaf, float call_snr_db, uint16_t nonce, bool tx_mfsk)
Build an ACCEPT.
Definition arq_protocol.c:528
int arq_protocol_parse_call(const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *caller_out, int *bw_hz_out, bool *tx_mfsk_out)
Parse a CALL: session id, the caller's callsign, the bandwidth, and the caller's TX-MFSK-only capabil...
Definition arq_protocol.c:561
int arq_protocol_parse_cq(const uint8_t *buf, size_t buf_len, char *src_out, int *bw_hz_out)
Parse a compact DATAC16 CQ frame.
Definition arq_protocol.c:631
_Atomic int arq_disconnect_retry_slots
Definition arq_protocol.c:22
_Atomic float arq_callint_override_s
Definition arq_protocol.c:92
int arq_protocol_build_call(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *caller, const char *called, int bw_hz, bool tx_mfsk)
Build a CALL.
Definition arq_protocol.c:498
_Atomic int arq_call_max_s
Definition arq_protocol.c:24
int arq_protocol_parse_accept(const uint8_t *buf, size_t buf_len, arq_accept_t *out)
Parse an ACCEPT.
Definition arq_protocol.c:579
_Atomic int arq_retry_stagger_ms
Definition arq_protocol.c:25
int arq_floor_mode(int bw_hz)
Definition arq_protocol.c:163
uint16_t arq_protocol_callsign_crc16(const char *callsign)
Compute CRC16-CCITT of an uppercase-normalised callsign.
Definition arq_protocol.c:341
float arq_protocol_longest_burst_s(void)
Longest single-burst airtime across the whole mode table, in seconds.
Definition arq_protocol.c:104
_Atomic int arq_accept_retry_slots
Definition arq_protocol.c:21
const int arq_mode_table_count
Definition arq_protocol.c:81
_Atomic int arq_call_retry_slots
Definition arq_protocol.c:19
const arq_mode_timing_t * arq_protocol_mode_timing(int freedv_mode)
Look up mode timing entry for a FreeDV mode.
Definition arq_protocol.c:94
float arq_protocol_call_interval_s(void)
Return the CALL/ACCEPT retry interval in seconds, applying any CALLINT override.
Definition arq_protocol.c:117
_Atomic int arq_silence_fallback_s
Definition arq_protocol.c:23
int arq_protocol_build_disconnect(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
DISCONNECT frame (PACKET_TYPE_ARQ_CONTROL).
Definition arq_protocol.c:322
void arq_protocol_set_call_fast_slots(int retries)
Definition arq_protocol.c:153
int arq_protocol_connect_minor(const uint8_t *buf)
The 2.x minor revision of a CALL or ACCEPT (version_ok already checked).
Definition arq_protocol.c:483
void arq_protocol_set_silence_fallback_s(int seconds)
Definition arq_protocol.c:139
void arq_protocol_set_call_max_s(int seconds)
Definition arq_protocol.c:146
uint8_t arq_protocol_bw_token_from_hz(int bw_hz)
Map a configured bandwidth in Hz to an on-air BW token.
Definition arq_protocol.c:262
_Atomic int arq_tx_mfsk_only
Definition arq_protocol.c:27
bool arq_protocol_connect_dst_matches(const uint8_t *buf, size_t buf_len, const char *callsign)
Is a CALL or ACCEPT addressed to callsign (bytes 2-3, all 16 bits)? Requires at least ARQ_CONNECT_PAY...
Definition arq_protocol.c:553
uint64_t arq_protocol_retry_deadline_ms(float seconds, int rank)
Definition arq_protocol.c:178
_Atomic int arq_call_fast_slots
Definition arq_protocol.c:20
void arq_protocol_session_calls(bool we_called, const char *remote_call, const char *local_call, const char *connect_src, const char *my_call, char *src, char *dst, size_t bufsz)
Definition arq_protocol.c:205
uint8_t arq_protocol_encode_snr(float snr_db)
Encode a floating-point SNR (dB) into the snr_raw wire byte.
Definition arq_protocol.c:299
int arq_protocol_retry_rank(const char *local_call, const char *remote_call)
Definition arq_protocol.c:168
_Atomic int arq_disconnect_drain_timeout_s
Definition arq_protocol.c:26
int arq_protocol_build_cq(uint8_t *buf, size_t buf_len, const char *src, int bw_hz)
Build a compact DATAC16 CQ frame carrying source callsign and BW token.
Definition arq_protocol.c:607
const arq_mode_timing_t arq_mode_table[]
Definition arq_protocol.c:61
float arq_protocol_call_interval_for_mode_s(int mode)
Definition arq_protocol.c:127
bool arq_protocol_connect_version_ok(const uint8_t *buf, size_t buf_len)
Is buf a CALL or ACCEPT of this protocol (2.0, any minor revision)?
Definition arq_protocol.c:475
int arq_protocol_decode_hdr(const uint8_t *buf, size_t buf_len, arq_frame_hdr_t *hdr)
Decode the ARQ header from the first bytes of buf.
Definition arq_protocol.c:245
float arq_protocol_decode_snr(uint8_t snr_raw)
Decode snr_raw wire byte back to float dB.
Definition arq_protocol.c:310
arq_subtype_t
Definition arq_protocol.h:83
@ ARQ_SUBTYPE_DISCONNECT
Definition arq_protocol.h:84
int arq_protocol_encode_hdr(uint8_t *buf, size_t buf_len, const arq_frame_hdr_t *hdr)
Encode a parsed header into the first ARQ_FRAME_HDR_SIZE bytes of buf.
Definition arq_protocol.c:229
int mode
Definition carousel.c:2916
int bw_hz
Definition carousel.c:2962
Definition arq_protocol.h:494
Definition arq_protocol.h:92
uint8_t packet_type
Definition arq_protocol.h:93
uint8_t session_id
Definition arq_protocol.h:97
uint8_t frame_ext
Definition arq_protocol.h:94
uint8_t flags
Definition arq_protocol.h:96
uint8_t tx_seq
Definition arq_protocol.h:98
uint8_t subtype
Definition arq_protocol.h:95
uint8_t ack_delay_raw
Definition arq_protocol.h:101
uint8_t snr_raw
Definition arq_protocol.h:100
uint8_t rx_ack_seq
Definition arq_protocol.h:99
Definition arq_protocol.h:112
float retry_interval_s
Definition arq_protocol.h:115
int payload_bytes
Definition arq_protocol.h:116
float frame_duration_s
Definition arq_protocol.h:114
int freedv_mode
Definition arq_protocol.h:113