|
openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
|
— setup/notification message codec. More...
#include "aliro_uwb_msg.h"#include "aliro_uwb_msg_builder.h"#include "aliro_uwb_msg_parser.h"#include "aliro_uwb_msg_spec.h"#include <aliro_uwb_adapter/aliro_uwb_adapter.h>#include "aliro_round_config.h"#include "woz_alloc.h"#include <string.h>#include "woz_log.h"#include "woz_util.h"Functions | |
| void | aliro_uwb_msg_free (struct aliro_uwb_message *message) |
| Releases a message allocated by this layer's message builders. | |
| struct aliro_uwb_message * | aliro_uwb_msg_build_m1 (struct aliro_uwb_session *session) |
| Builds the M1 ranging-session-setup message advertising configuration IDs, pulse-shape combos, channel bitmask, and session ID. | |
| static struct aliro_uwb_message * | aliro_uwb_msg_build_m3 (struct aliro_uwb_session *session) |
| Builds the M3 ranging-parameters message, deriving RAN multiplier and chaps-per-slot from the M2-negotiated durations and committing the reader's MAC mode. | |
| struct aliro_uwb_message * | aliro_uwb_msg_build_suspend_resume_request (struct aliro_uwb_session *session, bool suspend) |
| Builds a suspend or resume request message carrying the session identifier. | |
| static struct aliro_uwb_message * | aliro_uwb_msg_build_suspend_response (struct aliro_uwb_session *session, uint8_t status) |
| Builds a suspend-response message carrying an accept or reject status. | |
| struct aliro_uwb_message * | aliro_uwb_msg_build_general_error (struct aliro_uwb_session *session, uint8_t error_code) |
| Builds an Aliro general-error notification message carrying the given error code. | |
| uint8_t | aliro_uwb_msg_protocol_header (const uint8_t *bytes) |
| Extracts the protocol type from byte 0 of an Aliro message header. | |
| uint8_t | aliro_uwb_msg_message_id (const uint8_t *bytes) |
| Extracts the message type ID from byte 1 of an Aliro message header, used to dispatch M1-M4 setup and ranging messages during parsing. | |
| uint16_t | aliro_uwb_msg_payload_length (const uint8_t *bytes) |
| Extracts the payload length from bytes 2-3 of an Aliro message header as a 16-bit big-endian integer. | |
| static enum aliro_uwb_err | parse_config_id (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the UWB configuration ID attribute from M2 and stores it in the session config. | |
| static enum aliro_uwb_err | parse_pulse_shape (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the pulse-shape-combo attribute from M2 and stores it in the session config. | |
| static enum aliro_uwb_err | parse_session_id (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the session-identifier attribute from M2 and verifies it matches the session's active session ID. | |
| static enum aliro_uwb_err | parse_channel (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the channel bitmask attribute from M2, mapping it to channel 5 or 9 in the session config. | |
| static enum aliro_uwb_err | parse_ran_multiplier (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the RAN multiplier attribute from M3, selecting the larger of the peer's value and the reader's minimum, and computes the ranging duration in milliseconds. | |
| static enum aliro_uwb_err | parse_slot_bitmask (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the slot bitmask attribute from M3, intersects it with the local capability bitmask, and maps the lowest common bit to a chaps-per-slot count to compute slot duration. | |
| static enum aliro_uwb_err | parse_sync_code_bitmask (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the sync code bitmask attribute from M2 and logs the peer's offered bitmask; the reader retains its own capability bitmask for M3 and does not update the session config. | |
| static enum aliro_uwb_err | parse_sync_code_index (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the sync code index attribute from M3 and stores it in the session config. | |
| static enum aliro_uwb_err | parse_hopping_bitmask (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the hopping configuration bitmask attribute from M2, intersects peer capabilities with local CCC capabilities, and selects the first mutually supported preferred hopping config. | |
| static enum aliro_uwb_err | parse_sts_index0 (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the STS index 0 attribute from M2 and stores it in the session config. | |
| static enum aliro_uwb_err | parse_uwb_time0 (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the UWB time 0 attribute from M2 and stores it as the session's initial UWB time. | |
| static enum aliro_uwb_err | parse_hop_mode_key (struct aliro_uwb_session *session, struct aliro_uwb_msg_attribute *attr) |
| Parses the hop mode key attribute from M2 and stores the raw key bytes in the session config; unused downstream on this lock. | |
| static enum aliro_uwb_err | parse_status (struct aliro_uwb_msg_attribute *attr, uint8_t *status) |
| Parses a status attribute from a ranging message into the given output parameter. | |
| static enum aliro_uwb_err | parse_session_attribute (struct aliro_uwb_msg_attribute *attr, struct aliro_uwb_session *session) |
| Dispatches a ranging-service session attribute to its type-specific parser and applies it to the session; unknown attributes are logged and ignored. | |
| static enum aliro_uwb_err | parse_ranging (struct aliro_uwb_session *session, struct aliro_uwb_message *message, uint32_t *attr_mask, uint8_t *status) |
| Parses all ranging-service attributes in a message, applying each to the session and recording which attributes were present. | |
| static void | compute_initiation_time (struct aliro_uwb_session *session) |
| Sets the session's ranging initiation time from its time offset, using zero if unsynchronized or adding the offset to the existing UWB time otherwise. | |
| static enum aliro_uwb_err | set_resume_params (struct aliro_uwb_session *session) |
| Sets the STS index and initiation time on the CCC session in preparation for re-arming ranging after a suspend. | |
| static enum aliro_uwb_err | handle_m2 (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Handles an inbound M2 message by validating its attributes and session state, then building and transmitting M3 and advancing to the M3_SENT state. | |
| static enum aliro_uwb_err | handle_m4 (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Handles an inbound M4 message by validating its attributes and session state, computing the ranging initiation time, initializing the session, and advancing to the RANGING state. | |
| static enum aliro_uwb_err | handle_suspend_request (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Handles an inbound suspend request by validating session state, stopping the session, then building and transmitting a suspend response with acceptance or rejection status. | |
| static enum aliro_uwb_err | handle_suspend_response (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Handles an inbound suspend response by validating its attributes and session state, stopping the session if accepted or returning to the RANGING state if rejected. | |
| static enum aliro_uwb_err | handle_resume_response (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Handle an inbound resume response, arm timing and CCC state, and start ranging. | |
| enum aliro_uwb_err | aliro_uwb_msg_process_ranging (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Dispatch an inbound ranging-phase message to its handler based on message type. | |
| static enum aliro_uwb_err | handle_init_ranging_later (struct aliro_uwb_session *session) |
| Handle an "init ranging later" notification, returning the session to CREATED state. | |
| static enum aliro_uwb_err | handle_resume_later (struct aliro_uwb_session *session) |
| Handle a "resume later" notification, moving the session to SUSPENDED without re-arming ranging. | |
| static enum aliro_uwb_err | handle_ranging_suspended (struct aliro_uwb_session *session) |
| Handle a "ranging suspended" notification by stopping the session and moving it to SUSPENDED. | |
| static enum aliro_uwb_err | parse_event_notification (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Parse an Aliro event notification message, logging busy, general-error, and reader-descriptor events. | |
| static enum aliro_uwb_err | parse_ranging_notification (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Parse a ranging-setup notification message and dispatch each attribute to its session state handler. | |
| enum aliro_uwb_err | aliro_uwb_msg_process_notification (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Dispatch a received notification message to its parser by message ID. | |
| enum aliro_uwb_err | aliro_uwb_msg_process_supplementary (struct aliro_uwb_session *session, struct aliro_uwb_message *message) |
| Log every attribute of a Supplementary Service message (protocol 0x03). | |
— setup/notification message codec.
| struct aliro_uwb_message * aliro_uwb_msg_build_general_error | ( | struct aliro_uwb_session * | session, |
| uint8_t | error_code | ||
| ) |
Builds an Aliro general-error notification message carrying the given error code.
Build a general-error message for the given session.
| session | Unused; reserved for a consistent builder signature. |
| error_code | Error code to encode in the general-error notification attribute. |
| struct aliro_uwb_message * aliro_uwb_msg_build_m1 | ( | struct aliro_uwb_session * | session | ) |
Builds the M1 ranging-session-setup message advertising configuration IDs, pulse-shape combos, channel bitmask, and session ID.
| session | Session whose Aliro capabilities and session ID populate the message. |
|
static |
Builds the M3 ranging-parameters message, deriving RAN multiplier and chaps-per-slot from the M2-negotiated durations and committing the reader's MAC mode.
| session | Session whose negotiated M2 config and reader settings populate the M3 attributes. |
|
static |
Builds a suspend-response message carrying an accept or reject status.
| session | Unused; reserved for a consistent builder signature. |
| status | Response status; must be ALIRO_UWB_RANGING_SERVICE_STATUS_ACCEPT or ALIRO_UWB_RANGING_SERVICE_STATUS_REJECT. |
| struct aliro_uwb_message * aliro_uwb_msg_build_suspend_resume_request | ( | struct aliro_uwb_session * | session, |
| bool | suspend | ||
| ) |
Builds a suspend or resume request message carrying the session identifier.
| session | Session whose session ID is encoded into the message. |
| suspend | True to build a suspend request, false to build a resume request. |
| void aliro_uwb_msg_free | ( | struct aliro_uwb_message * | message | ) |
Releases a message allocated by this layer's message builders.
Release a message built by this layer.
| uint8_t aliro_uwb_msg_message_id | ( | const uint8_t * | bytes | ) |
Extracts the message type ID from byte 1 of an Aliro message header, used to dispatch M1-M4 setup and ranging messages during parsing.
| bytes | Pointer to the start of the raw message bytes. |
| uint16_t aliro_uwb_msg_payload_length | ( | const uint8_t * | bytes | ) |
Extracts the payload length from bytes 2-3 of an Aliro message header as a 16-bit big-endian integer.
| bytes | Pointer to the start of the raw message bytes. |
| enum aliro_uwb_err aliro_uwb_msg_process_notification | ( | struct aliro_uwb_session * | session, |
| struct aliro_uwb_message * | message | ||
| ) |
Dispatch a received notification message to its parser by message ID.
Reader-status notifications are informational and ignored; unknown IDs are logged and ignored.
| session | Aliro UWB session to update with the parsed notification's effects. |
| message | Received notification message to dispatch. |
| enum aliro_uwb_err aliro_uwb_msg_process_ranging | ( | struct aliro_uwb_session * | session, |
| struct aliro_uwb_message * | message | ||
| ) |
Dispatch an inbound ranging-phase message to its handler based on message type.
| session | Aliro UWB session to update. |
| message | Received ranging message to dispatch. |
| enum aliro_uwb_err aliro_uwb_msg_process_supplementary | ( | struct aliro_uwb_session * | session, |
| struct aliro_uwb_message * | message | ||
| ) |
Log every attribute of a Supplementary Service message (protocol 0x03).
The phone sends one of these at session establishment. Nothing is modelled yet and no response is emitted, so this only surfaces the payload: the semantics are unknown and are being characterised by diffing the attributes across conditions.
| session | Aliro UWB session (unused; no state is driven from here yet). |
| message | Received supplementary-service message to log. |
| uint8_t aliro_uwb_msg_protocol_header | ( | const uint8_t * | bytes | ) |
Extracts the protocol type from byte 0 of an Aliro message header.
| bytes | Pointer to the start of the raw message bytes. |
|
static |
Sets the session's ranging initiation time from its time offset, using zero if unsynchronized or adding the offset to the existing UWB time otherwise.
| session | Session whose config's uwb_time_us is updated in place. |
|
static |
Handle an "init ranging later" notification, returning the session to CREATED state.
| session | Aliro UWB session expected to be in M1_SENT state. |
|
static |
Handles an inbound M2 message by validating its attributes and session state, then building and transmitting M3 and advancing to the M3_SENT state.
| session | Session receiving the M2 message. |
| message | Inbound M2 message to process. |
|
static |
Handles an inbound M4 message by validating its attributes and session state, computing the ranging initiation time, initializing the session, and advancing to the RANGING state.
| session | Session receiving the M4 message. |
| message | Inbound M4 message to process. |
|
static |
Handle a "ranging suspended" notification by stopping the session and moving it to SUSPENDED.
| session | Aliro UWB session expected to be in RANGING state. |
|
static |
Handle a "resume later" notification, moving the session to SUSPENDED without re-arming ranging.
| session | Aliro UWB session expected to be in RESUME_REQ_SENT state. |
|
static |
Handle an inbound resume response, arm timing and CCC state, and start ranging.
| session | Aliro UWB session expected to be in RESUME_REQ_SENT state. |
| message | Received resume response message to validate and parse. |
|
static |
Handles an inbound suspend request by validating session state, stopping the session, then building and transmitting a suspend response with acceptance or rejection status.
| session | Session receiving the suspend request. |
| message | Inbound suspend-request message to process. |
|
static |
Handles an inbound suspend response by validating its attributes and session state, stopping the session if accepted or returning to the RANGING state if rejected.
| session | Session receiving the suspend response. |
| message | Inbound suspend-response message to process. |
|
static |
Parses the channel bitmask attribute from M2, mapping it to channel 5 or 9 in the session config.
| session | Session whose config receives the resolved channel number. |
| attr | Attribute to parse. |
|
static |
Parses the UWB configuration ID attribute from M2 and stores it in the session config.
| session | Session whose config receives the parsed configuration ID. |
| attr | Attribute to parse. |
|
static |
Parse an Aliro event notification message, logging busy, general-error, and reader-descriptor events.
| session | Aliro UWB session (unused). |
| message | Received event notification message to parse. |
|
static |
Parses the hop mode key attribute from M2 and stores the raw key bytes in the session config; unused downstream on this lock.
| session | Session whose config receives the parsed hop mode key. |
| attr | Attribute to parse. |
|
static |
Parses the hopping configuration bitmask attribute from M2, intersects peer capabilities with local CCC capabilities, and selects the first mutually supported preferred hopping config.
| session | Session whose reader preferences are matched and whose config receives the selected hopping mode. |
| attr | Attribute to parse. |
|
static |
Parses the pulse-shape-combo attribute from M2 and stores it in the session config.
| session | Session whose config receives the parsed pulse shape. |
| attr | Attribute to parse. |
|
static |
Parses the RAN multiplier attribute from M3, selecting the larger of the peer's value and the reader's minimum, and computes the ranging duration in milliseconds.
| session | Session whose config receives the computed ranging duration. |
| attr | Attribute to parse. |
|
static |
Parses all ranging-service attributes in a message, applying each to the session and recording which attributes were present.
| session | Session updated by attribute-specific parsers. |
| message | Message whose attributes are parsed. |
| attr_mask | Output parameter receiving a bitmask of attribute IDs present in the message. |
| status | Output parameter receiving the parsed status, or ALIRO_UWB_RANGING_SERVICE_STATUS_UNKNOWN if no status attribute is present. |
|
static |
Parse a ranging-setup notification message and dispatch each attribute to its session state handler.
| session | Aliro UWB session to update. |
| message | Received ranging notification message to parse. |
|
static |
Dispatches a ranging-service session attribute to its type-specific parser and applies it to the session; unknown attributes are logged and ignored.
| attr | Attribute to parse and apply. |
| session | Session updated by the attribute-specific parser. |
|
static |
Parses the session-identifier attribute from M2 and verifies it matches the session's active session ID.
| session | Session whose session ID is checked against the parsed value. |
| attr | Attribute to parse. |
|
static |
Parses the slot bitmask attribute from M3, intersects it with the local capability bitmask, and maps the lowest common bit to a chaps-per-slot count to compute slot duration.
| session | Session whose config receives the computed slot duration. |
| attr | Attribute to parse. |
|
static |
Parses a status attribute from a ranging message into the given output parameter.
| attr | Attribute to parse. |
| status | Output parameter receiving the parsed 8-bit status value. |
|
static |
Parses the STS index 0 attribute from M2 and stores it in the session config.
| session | Session whose config receives the parsed STS index. |
| attr | Attribute to parse. |
|
static |
Parses the sync code bitmask attribute from M2 and logs the peer's offered bitmask; the reader retains its own capability bitmask for M3 and does not update the session config.
| session | Unused; reserved for a consistent parser signature. |
| attr | Attribute to parse. |
|
static |
Parses the sync code index attribute from M3 and stores it in the session config.
| session | Session whose config receives the parsed sync code index. |
| attr | Attribute to parse. |
|
static |
Parses the UWB time 0 attribute from M2 and stores it as the session's initial UWB time.
| session | Session whose config receives the parsed UWB time. |
| attr | Attribute to parse. |
|
static |
Sets the STS index and initiation time on the CCC session in preparation for re-arming ranging after a suspend.
| session | Session whose CCC session and Aliro config supply the resume parameters. |