aliro_uwb_session.c
per-session lifecycle and state machine.
Overview
per-session lifecycle and state machine.
depends on woz_log.h aliro_uwb_internal.h aliro_uwb_msg.h aliro_uwb_msg_spec.h aliro_uwb_session.h cherry_ccc.h woz_alloc.h
flowchart TD aliro_ccc_cb --> notify_error
API
Fstatic enum aliro_uwb_err notify_error(struct aliro_uwb_session *session)
Send a general-error notification to the peer.
session- Session on which to build and transmit the error message.
- returns
ALIRO_UWB_ERR_NONEon success,ALIRO_UWB_ERR_INVALID_PARAMETERif session is NULL, orALIRO_UWB_ERR_INTERNALif the message could not be built.
aliro_ccc_cbFstatic void aliro_ccc_cb(struct cherry_ccc_event *event, void *user_data)
CCC seam callback: wrap the CCC event and forward it to the client.
event- CCC event to wrap and forward.
user_data- Aliro UWB session that owns the callback and client data.
notify_errorFstatic void session_close(struct aliro_uwb_session *session)
Tear down: destroy the CCC session, or free directly if there is none.
session- Session to close.
aliro_uwb_session_destroy, aliro_uwb_session_init, aliro_uwb_session_start, aliro_uwb_session_stopFenum aliro_uwb_err aliro_uwb_session_init(struct aliro_uwb_session *session)
Initialize a session by creating and configuring a CCC Aliro responder, setting URSK, protocol version, antennas, and diagnostics, then starting the session. On any error, tears down the session and returns the mapped error code.
session- Session to initialize.
- returns
ALIRO_UWB_ERR_NONEon success,ALIRO_UWB_ERR_INVALID_PARAMETERif session is NULL, or the mapped CCC error on failure.
session_closeFenum aliro_uwb_err aliro_uwb_session_start(struct aliro_uwb_session *session)
Start an active CCC session. On error, tears down the session and returns the mapped error code. the mapped CCC error on failure.
session_closeFenum aliro_uwb_err aliro_uwb_session_stop(struct aliro_uwb_session *session)
Stop an active CCC session, transitioning to SUSPENDED state. On error, tears down the session and returns the mapped error code.
session- Session to stop.
- returns
ALIRO_UWB_ERR_NONEon success,ALIRO_UWB_ERR_INVALID_PARAMETERif session is NULL, or the mapped CCC error on failure.
session_closeFstruct aliro_uwb_session *aliro_uwb_session_create(struct aliro_uwb_adapter *aliro_ctx, uint32_t session_id, aliro_uwb_session_cb_t callback, aliro_uwb_adapter_transmit_message_t transmit, void *user_data)
Allocate an Aliro UWB session in the CREATED state, bound to an adapter and to the caller's transmit and event callbacks. No CCC session is started here.
Fvoid aliro_uwb_session_destroy(struct aliro_uwb_session *session)
Destroy an Aliro UWB session, freeing the URSK and tearing down the underlying CCC session.
session- Session to destroy; no-op if NULL.
session_closeFvoid aliro_uwb_session_message_free(struct aliro_uwb_message *message)
Free a session message, delegating to the message-specific free function.
message- Message to free.
Fvoid aliro_uwb_session_event_free(struct aliro_uwb_session_event *event)
Free a session event, releasing its wrapped CCC event if present.
Fenum aliro_uwb_err aliro_uwb_session_set_ursk(struct aliro_uwb_session *session, const uint8_t *ursk)
Store a copy of the URSK (Unique Ranging Session Key) for later use during session initialization. Allocates a 16-byte buffer and returns ALIRO_UWB_ERR_INTERNAL on allocation failure.
session- Session that receives the copied URSK.
ursk- Source URSK bytes to copy.
- returns
ALIRO_UWB_ERR_NONEon success,ALIRO_UWB_ERR_INVALID_PARAMETERif session or ursk is NULL, orALIRO_UWB_ERR_INTERNALon allocation failure.
Fenum aliro_uwb_err aliro_uwb_session_set_protocol_version(struct aliro_uwb_session *session, uint16_t selected_protocol_version)
Store the protocol version selected by the reader for later use during session initialization.
session- Session that receives the selected protocol version.
selected_protocol_version- Protocol version chosen by the reader.
- returns
ALIRO_UWB_ERR_NONEon success, orALIRO_UWB_ERR_INVALID_PARAMETERif session is NULL.
Fenum aliro_uwb_err aliro_uwb_session_init_setup(struct aliro_uwb_session *session)
Begin session setup by building and transmitting M1, transitioning from CREATED to M1_SENT state. Returns ALIRO_UWB_ERR_INVALID_STATE if not in CREATED state.
session- Session to begin setup on.
- returns
ALIRO_UWB_ERR_NONEon success,ALIRO_UWB_ERR_INVALID_PARAMETERif session is NULL,ALIRO_UWB_ERR_INVALID_STATEif not in CREATED state, orALIRO_UWB_ERR_INTERNALif M1 could not be built.
Fenum aliro_uwb_err aliro_uwb_session_set_time_offset(struct aliro_uwb_session *session, int64_t time_offset)
Store the time offset used to synchronize clocks between reader and device.
session- Session to update.
time_offset- Time offset in microseconds.
- returns
- ALIRO_UWB_ERR_NONE on success, ALIRO_UWB_ERR_INVALID_PARAMETER if session is NULL.
Fenum aliro_uwb_err aliro_uwb_session_message_handle(struct aliro_uwb_session *session, struct aliro_uwb_message *message)
Validate and dispatch an incoming Aliro UWB message to the appropriate protocol handler.
session- Session that received the message.
message- Message to validate and process.
- returns
- ALIRO_UWB_ERR_NONE on success, ALIRO_UWB_ERR_INVALID_PARAMETER if session or message is NULL, ALIRO_UWB_ERR_MSG_MALFORMED if the message is shorter than the header or the payload length does not match, ALIRO_UWB_ERR_MESSAGE_UNSUPPORTED for an unrecognized protocol.
Fenum aliro_uwb_err aliro_uwb_session_suspend(struct aliro_uwb_session *session)
Suspend an active ranging session by sending a suspend request.
session- Session to suspend.
- returns
- ALIRO_UWB_ERR_NONE on success, ALIRO_UWB_ERR_INVALID_PARAMETER if session is NULL, ALIRO_UWB_ERR_INVALID_STATE if there is no active CCC session or the session is not in the RANGING state, ALIRO_UWB_ERR_INTERNAL if the suspend request could not be built.
Fenum aliro_uwb_err aliro_uwb_session_forced_suspend(struct aliro_uwb_session *session)
Forcibly stop the active CCC session, transitioning it to SUSPENDED without a request/response exchange.
session- Session to force-suspend.
- returns
- ALIRO_UWB_ERR_NONE on success, ALIRO_UWB_ERR_INVALID_PARAMETER if session is NULL, ALIRO_UWB_ERR_INVALID_STATE if no CCC session is active, otherwise the error translated from cherry_ccc_session_stop.
Fenum aliro_uwb_err aliro_uwb_session_resume(struct aliro_uwb_session *session)
Resume a suspended ranging session by building and transmitting a resume request. ALIRO_UWB_ERR_INVALID_STATE if there is no active CCC session or the session is not in the SUSPENDED state, ALIRO_UWB_ERR_INTERNAL if the resume request could not be built.