10#define ARQ_PROTOCOL_H_
20#define ARQ_PROTO_VERSION 3
48#define ARQ_HDR_SUBTYPE_IDX 1
49#define ARQ_HDR_FLAGS_IDX 2
50#define ARQ_HDR_SESSION_IDX 3
51#define ARQ_HDR_SEQ_IDX 4
52#define ARQ_HDR_ACK_IDX 5
53#define ARQ_HDR_SNR_IDX 6
54#define ARQ_HDR_DELAY_IDX 7
55#define ARQ_FRAME_HDR_SIZE 8
64#define ARQ_CONNECT_SESSION_IDX 1
65#define ARQ_CONNECT_PAYLOAD_IDX 2
66#define ARQ_CONNECT_SESSION_MASK 0x7F
67#define ARQ_CONNECT_ACCEPT_FLAG 0x80
68#define ARQ_CONTROL_FRAME_SIZE 14
69#define ARQ_CONNECT_META_SIZE 2
70#define ARQ_CONNECT_MAX_ENCODED (ARQ_CONTROL_FRAME_SIZE - ARQ_CONNECT_META_SIZE)
76#define ARQ_FLAG_TURN_REQ 0x80
77#define ARQ_FLAG_HAS_DATA 0x40
78#define ARQ_FLAG_LEN_HI 0x20
117 uint8_t ack_delay_raw;
139 float frame_duration_s;
142 float retry_interval_s;
147#define ARQ_CHANNEL_GUARD_MS 700
155#define ARQ_ISS_POST_ACK_GUARD_MS 900
165#define ARQ_TURN_WAIT_AFTER_ACK_MS 3500
167#define ARQ_ACCEPT_RX_WINDOW_MS 9000
172#define ARQ_ACK_GUARD_S 1
173#define ARQ_CALL_RETRY_SLOTS 4
174#define ARQ_ACCEPT_RETRY_SLOTS 4
175#define ARQ_DATA_RETRY_SLOTS 10
176#define ARQ_DISCONNECT_RETRY_SLOTS 2
177#define ARQ_CONNECT_GRACE_SLOTS 2
178#define ARQ_CONNECT_BUSY_EXT_S 2
179#define ARQ_KEEPALIVE_INTERVAL_S 20
180#define ARQ_KEEPALIVE_MISS_LIMIT 5
181#define ARQ_TURN_REQ_RETRIES 2
182#define ARQ_MODE_REQ_RETRIES 2
183#define ARQ_MODE_SWITCH_HYST_COUNT 1
184#define ARQ_STARTUP_MAX_S 8
185#define ARQ_STARTUP_ACKS_REQUIRED 1
186#define ARQ_PEER_PAYLOAD_HOLD_S 15
187#define ARQ_SNR_HYST_DB 1.0f
188#define ARQ_SNR_MIN_DATAC4_DB -4.0f
189#define ARQ_SNR_MIN_DATAC3_DB -1.0f
190#define ARQ_SNR_MIN_DATAC1_DB 3.0f
191#define ARQ_BACKLOG_MIN_DATAC3 56
192#define ARQ_BACKLOG_MIN_DATAC1 126
193#define ARQ_BACKLOG_MIN_BIDIR_UPGRADE 48
194#define ARQ_LADDER_LEVELS 3
195#define ARQ_LADDER_UP_SUCCESSES 4
196#define ARQ_RETRY_DOWNGRADE_THRESHOLD 2
197#define ARQ_MODE_HOLD_AFTER_DOWNGRADE_S 15
204#define ARQ_DATA_LEN_FULL 0
272 uint8_t session_id, uint8_t rx_ack_seq,
273 uint8_t flags, uint8_t snr_raw,
274 uint8_t ack_delay_raw);
278 uint8_t session_id, uint8_t snr_raw);
282 uint8_t session_id, uint8_t snr_raw);
286 uint8_t session_id, uint8_t snr_raw);
297 uint8_t session_id, uint8_t rx_ack_seq,
302 uint8_t session_id, uint8_t snr_raw);
313 uint8_t session_id, uint8_t snr_raw,
318 uint8_t session_id, uint8_t snr_raw,
337 uint8_t session_id, uint8_t tx_seq,
338 uint8_t rx_ack_seq, uint8_t flags,
339 uint8_t snr_raw, uint8_t payload_valid,
340 const uint8_t *payload,
size_t payload_len);
355 const char *src,
const char *dst);
367 const char *src,
const char *dst);
379 uint8_t *session_id_out,
380 char *src_out,
char *dst_out);
386 uint8_t *session_id_out,
387 char *src_out,
char *dst_out);
int arq_protocol_parse_accept(const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *src_out, char *dst_out)
Parse an ACCEPT frame; same layout as CALL.
Definition arq_protocol.c:417
int arq_protocol_build_mode_ack(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw, int freedv_mode)
MODE_ACK frame — accept peer's mode request.
Definition arq_protocol.c:260
int arq_protocol_build_accept(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *src, const char *dst)
Build an ACCEPT frame.
Definition arq_protocol.c:389
int arq_protocol_build_turn_ack(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
TURN_ACK frame.
Definition arq_protocol.c:240
const int arq_mode_table_count
Definition arq_protocol.c:60
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:67
int arq_protocol_build_ack(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t rx_ack_seq, uint8_t flags, uint8_t snr_raw, uint8_t ack_delay_raw)
ACK frame.
Definition arq_protocol.c:192
int arq_protocol_build_disconnect(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
DISCONNECT frame.
Definition arq_protocol.c:203
int arq_protocol_build_keepalive_ack(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
KEEPALIVE_ACK frame.
Definition arq_protocol.c:221
int arq_protocol_build_keepalive(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw)
KEEPALIVE frame.
Definition arq_protocol.c:212
uint8_t arq_protocol_encode_ack_delay(uint32_t delay_ms)
Encode ack_delay_ms to the 8-bit wire value (10ms units, max 2.55s).
Definition arq_protocol.c:143
int arq_protocol_parse_call(const uint8_t *buf, size_t buf_len, uint8_t *session_id_out, char *src_out, char *dst_out)
Parse a CALL frame; extract callsigns.
Definition arq_protocol.c:410
int arq_protocol_build_turn_req(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t rx_ack_seq, uint8_t snr_raw)
TURN_REQ frame.
Definition arq_protocol.c:230
int arq_protocol_build_call(uint8_t *buf, size_t buf_len, uint8_t session_id, const char *src, const char *dst)
Build a CALL frame.
Definition arq_protocol.c:382
int arq_protocol_build_data(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t tx_seq, uint8_t rx_ack_seq, uint8_t flags, uint8_t snr_raw, uint8_t payload_valid, const uint8_t *payload, size_t payload_len)
DATA frame — 8-byte header + payload bytes.
Definition arq_protocol.c:271
uint32_t arq_protocol_decode_ack_delay(uint8_t raw)
Decode the 8-bit wire ack_delay to milliseconds.
Definition arq_protocol.c:153
int arq_protocol_build_mode_req(uint8_t *buf, size_t buf_len, uint8_t session_id, uint8_t snr_raw, int freedv_mode)
MODE_REQ frame.
Definition arq_protocol.c:249
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:121
const arq_mode_timing_t arq_mode_table[]
Definition arq_protocol.c:52
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:98
float arq_protocol_decode_snr(uint8_t snr_raw)
Decode snr_raw wire byte back to float dB.
Definition arq_protocol.c:129
arq_subtype_t
Definition arq_protocol.h:85
@ ARQ_SUBTYPE_DISCONNECT
Definition arq_protocol.h:89
@ ARQ_SUBTYPE_ACCEPT
Definition arq_protocol.h:87
@ ARQ_SUBTYPE_DATA
Definition arq_protocol.h:90
@ ARQ_SUBTYPE_CALL
Definition arq_protocol.h:86
@ ARQ_SUBTYPE_KEEPALIVE
Definition arq_protocol.h:91
@ ARQ_SUBTYPE_MODE_ACK
Definition arq_protocol.h:94
@ ARQ_SUBTYPE_TURN_ACK
Definition arq_protocol.h:96
@ ARQ_SUBTYPE_TURN_REQ
Definition arq_protocol.h:95
@ ARQ_SUBTYPE_KEEPALIVE_ACK
Definition arq_protocol.h:92
@ ARQ_SUBTYPE_MODE_REQ
Definition arq_protocol.h:93
@ ARQ_SUBTYPE_ACK
Definition arq_protocol.h:88
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:82
Definition arq_protocol.h:105
Definition arq_protocol.h:133