openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
ccc_mac.h
Go to the documentation of this file.
1
3#ifndef CCC_MAC_H
4#define CCC_MAC_H
5
6#include <stdbool.h>
7#include <stddef.h>
8#include <stdint.h>
9
10#include "ccc_kdf.h"
11
13uint16_t ccc_hop_round_index(uint32_t block_index, uint32_t hop_key_rw, uint32_t n_round);
14
15/* ── SP0 frame codec ──────────────────────────────────────────────────────── */
16
18#define CCC_MHR_LEN 23
20#define CCC_PRE_POLL_LEN 13
22#define CCC_FINAL_DATA_HDR_LEN 18
24#define CCC_RESPONDER_LEN 7
26#define CCC_MAX_RESPONDERS 10
28#define CCC_MSG_ID_PRE_POLL 0x01u
30#define CCC_MSG_ID_FINAL_DATA 0x02u
31
42
44int ccc_build_mhr(const struct ccc_mhr_fields *f, uint8_t out[CCC_MHR_LEN]);
45
47int ccc_parse_mhr(const uint8_t in[CCC_MHR_LEN], struct ccc_mhr_fields *f);
48
53 uint32_t uwb_session_id;
54 uint32_t poll_sts_index;
55 uint16_t ranging_block;
56 uint8_t hop_flag;
57 uint16_t round_index;
58};
59
61int ccc_pre_poll_pack(const struct ccc_pre_poll *p, uint8_t out[CCC_PRE_POLL_LEN]);
62
64int ccc_pre_poll_parse(const uint8_t in[CCC_PRE_POLL_LEN], struct ccc_pre_poll *p);
65
75
80 uint32_t uwb_session_id;
81 uint16_t ranging_block;
82 uint8_t hop_flag;
83 uint16_t round_index;
84 uint32_t final_sts_index;
87 struct ccc_responder_ts responders[CCC_MAX_RESPONDERS];
88};
89
91int ccc_final_data_pack(const struct ccc_final_data *f, uint8_t *out, size_t cap, size_t *len);
92
94int ccc_final_data_parse(const uint8_t *in, size_t len, struct ccc_final_data *f);
95
96/* ── Ranging schedule ─────────────────────────────────────────────────────── */
97
103
112
117 uint32_t sts_index0;
119 uint16_t n_round;
120 uint8_t n_responder;
121 uint32_t hop_key_rw;
123};
124
129 uint8_t hop_flag;
130 uint16_t round_index;
131};
132
134uint16_t ccc_block_round(const struct ccc_ran_params *p, uint32_t block);
135
137uint32_t ccc_slot_sts_index(const struct ccc_ran_params *p, uint32_t block, uint16_t round,
138 enum ccc_slot slot, uint8_t responder);
139
141struct ccc_hop_decision ccc_initiator_next_hop(const struct ccc_ran_params *p, uint32_t block);
142
143/* ── Double-sided two-way ranging ─────────────────────────────────────────── */
144
149 uint32_t t_round1;
150 uint32_t t_reply1;
151 uint32_t t_round2;
152 uint32_t t_reply2;
153};
154
156uint32_t ccc_ds_twr_tof(const struct ccc_ds_twr *t);
157
159int ccc_responder_ds_twr(const struct ccc_final_data *fd, uint8_t responder, uint32_t t_reply1,
160 uint32_t t_round2, struct ccc_ds_twr *out);
161
162/* ── URSK lifetime ────────────────────────────────────────────────────────── */
163
165#define CCC_STS_INDEX_MAX 0x7FFFFFFFu
166
169bool ccc_ursk_exhausted(const struct ccc_ran_params *p, uint32_t block);
170
171#endif /* CCC_MAC_H */
UWB ranging key schedule + SP0 frame crypto (CONFIG_WOZ_ALIRO).
#define CCC_KEYSOURCE_LEN
KeySource length, bytes (KeySourceHigh || KeySourceLow).
Definition ccc_kdf.h:38
uint32_t ccc_slot_sts_index(const struct ccc_ran_params *p, uint32_t block, uint16_t round, enum ccc_slot slot, uint8_t responder)
STS index for one slot of a ranging round (uint32 wraps mod 2^32).
Definition ccc_mac.c:288
int ccc_final_data_pack(const struct ccc_final_data *f, uint8_t *out, size_t cap, size_t *len)
Pack a Final_Data payload little-endian.
Definition ccc_mac.c:177
int ccc_responder_ds_twr(const struct ccc_final_data *fd, uint8_t responder, uint32_t t_reply1, uint32_t t_round2, struct ccc_ds_twr *out)
Assemble the DS-TWR intervals at the responder from a received Final_Data.
Definition ccc_mac.c:339
#define CCC_PRE_POLL_LEN
Pre-POLL MAC payload length, bytes.
Definition ccc_mac.h:20
bool ccc_ursk_exhausted(const struct ccc_ran_params *p, uint32_t block)
Whether the current URSK is exhausted for a ranging block (true once its highest STS index would exce...
Definition ccc_mac.c:355
#define CCC_MAX_RESPONDERS
Max responders in one Final_Data (127-byte payload cap).
Definition ccc_mac.h:26
int ccc_build_mhr(const struct ccc_mhr_fields *f, uint8_t out[CCC_MHR_LEN])
Build the 23-byte SP0 MHR (little-endian on the wire).
Definition ccc_mac.c:82
uint32_t ccc_ds_twr_tof(const struct ccc_ds_twr *t)
DS-TWR one-way time-of-flight in timestamp ticks (0 if the denominator is 0).
Definition ccc_mac.c:327
int ccc_final_data_parse(const uint8_t *in, size_t len, struct ccc_final_data *f)
Parse a Final_Data payload (-EINVAL if length is inconsistent with num_responders).
Definition ccc_mac.c:215
uint16_t ccc_block_round(const struct ccc_ran_params *p, uint32_t block)
The ranging round a block uses (block 0 uses round 0; continuous hopping uses S(i) for i>=1).
Definition ccc_mac.c:269
struct ccc_hop_decision ccc_initiator_next_hop(const struct ccc_ran_params *p, uint32_t block)
The initiator's hop decision for the block after block, written into its Final_Data.
Definition ccc_mac.c:309
uint16_t ccc_hop_round_index(uint32_t block_index, uint32_t hop_key_rw, uint32_t n_round)
Default hopping round index S(i) in [0, n_round) for a ranging block, keyed by HOP_Key_RW.
Definition ccc_mac.c:18
int ccc_pre_poll_pack(const struct ccc_pre_poll *p, uint8_t out[CCC_PRE_POLL_LEN])
Pack a Pre-POLL payload little-endian.
Definition ccc_mac.c:134
int ccc_pre_poll_parse(const uint8_t in[CCC_PRE_POLL_LEN], struct ccc_pre_poll *p)
Parse a 13-byte Pre-POLL payload.
Definition ccc_mac.c:154
ccc_hop_mode
Hopping mode.
Definition ccc_mac.h:99
@ CCC_HOP_CONTINUOUS
Continuous hopping: block i uses round S(i).
Definition ccc_mac.h:101
@ CCC_HOP_NONE
No hopping: every block uses ranging round 0.
Definition ccc_mac.h:100
int ccc_parse_mhr(const uint8_t in[CCC_MHR_LEN], struct ccc_mhr_fields *f)
Parse and validate a 23-byte SP0 MHR, extracting the variable fields (-EINVAL on mismatch).
Definition ccc_mac.c:110
#define CCC_MHR_LEN
SP0 MHR length, bytes.
Definition ccc_mac.h:18
ccc_slot
Slot role within a ranging round.
Definition ccc_mac.h:105
@ CCC_SLOT_FINAL_DATA
SP0 data packet, initiator.
Definition ccc_mac.h:110
@ CCC_SLOT_PRE_POLL
Slot 0 — SP0 data packet, initiator.
Definition ccc_mac.h:106
@ CCC_SLOT_FINAL
SP3 RFRAME, initiator.
Definition ccc_mac.h:109
@ CCC_SLOT_POLL
Slot 1 — SP3 RFRAME, initiator.
Definition ccc_mac.h:107
@ CCC_SLOT_RESPONSE
Slots 2..1+N — SP3 RFRAME, responder l.
Definition ccc_mac.h:108
The four DS-TWR intervals, in ranging-timestamp ticks (uint32, wrap mod 2^32).
Definition ccc_mac.h:148
uint32_t t_reply1
Responder POLL rx → RESPONSE tx (t3 − t2).
Definition ccc_mac.h:150
uint32_t t_round2
Responder RESPONSE tx → FINAL rx (t6 − t3).
Definition ccc_mac.h:151
uint32_t t_reply2
Initiator RESPONSE rx → FINAL tx (t5 − t4).
Definition ccc_mac.h:152
uint32_t t_round1
Initiator POLL tx → RESPONSE rx (t4 − t1).
Definition ccc_mac.h:149
Final_Data message parameters.
Definition ccc_mac.h:79
uint32_t final_sts_index
STS index of the preceding FINAL message.
Definition ccc_mac.h:84
uint8_t num_responders
Responder records that follow (≤ CCC_MAX_RESPONDERS).
Definition ccc_mac.h:86
uint32_t ranging_ts_final_tx
POLL→Final transmit time difference.
Definition ccc_mac.h:85
uint16_t ranging_block
Index of the current ranging block.
Definition ccc_mac.h:81
uint16_t round_index
Ranging round for the next ranging block.
Definition ccc_mac.h:83
uint8_t hop_flag
Hop flag for the next ranging block.
Definition ccc_mac.h:82
uint32_t uwb_session_id
ID of the UWB ranging session.
Definition ccc_mac.h:80
The initiator's next-block hop decision, carried in Final_Data.
Definition ccc_mac.h:128
uint8_t hop_flag
Hop_Flag for the next ranging block.
Definition ccc_mac.h:129
uint16_t round_index
Round_Index for the next ranging block.
Definition ccc_mac.h:130
The per-frame-variable fields of an SP0 MHR (fixed fields are built in by ccc_build_mhr).
Definition ccc_mac.h:35
uint8_t payload_len
Vendor Info byte 2 (MAC payload length).
Definition ccc_mac.h:40
uint8_t msg_id
Vendor Info byte 1 (CCC_MSG_ID_*).
Definition ccc_mac.h:39
uint8_t key_source[CCC_KEYSOURCE_LEN]
Aux Security Header Key Source.
Definition ccc_mac.h:38
uint32_t frame_counter
Aux Security Header frame counter.
Definition ccc_mac.h:37
uint16_t dest_short_addr
Destination Short Address.
Definition ccc_mac.h:36
Pre-POLL request message parameters.
Definition ccc_mac.h:52
uint16_t ranging_block
Session's index of the current ranging block.
Definition ccc_mac.h:55
uint32_t uwb_session_id
ID of the UWB ranging session.
Definition ccc_mac.h:53
uint8_t hop_flag
Hop flag for the current ranging block.
Definition ccc_mac.h:56
uint32_t poll_sts_index
STS index of the succeeding POLL message.
Definition ccc_mac.h:54
uint16_t round_index
Ranging round index for the current block.
Definition ccc_mac.h:57
Per-session ranging schedule parameters (negotiated in setup).
Definition ccc_mac.h:116
uint32_t sts_index0
STS_Index0 — ranging round 0 of block 0.
Definition ccc_mac.h:117
uint32_t hop_key_rw
HOP_Key_RW (continuous hopping).
Definition ccc_mac.h:121
uint16_t n_slot_per_round
N_Slot_per_Round.
Definition ccc_mac.h:118
enum ccc_hop_mode hop_mode
Hopping mode.
Definition ccc_mac.h:122
uint8_t n_responder
N_Responder (1..CCC_MAX_RESPONDERS).
Definition ccc_mac.h:120
uint16_t n_round
N_Round — rounds per block (> 0).
Definition ccc_mac.h:119
One responder's timestamp record in a Final_Data message.
Definition ccc_mac.h:69
uint32_t timestamp
POLL→RESPONSE time difference at the initiator.
Definition ccc_mac.h:71
uint8_t ranging_status
Per-responder ranging status.
Definition ccc_mac.h:73
uint8_t timestamp_uncertainty
Ranging timestamp uncertainty.
Definition ccc_mac.h:72
uint8_t responder_index
Index of the responder this record refers to.
Definition ccc_mac.h:70