openaliro
Aliro reader: UWB/CCC core and ESP32-S3/C5/C6 port
Loading...
Searching...
No Matches
ble_message.h
1/* Aliro 1.0 Bluetooth LE message framing (section 11.7). */
2#pragma once
3
4#include <stddef.h>
5#include <stdint.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11enum {
12 WOZ_ALIRO_BLE_HEADER_SIZE = 4,
13 WOZ_ALIRO_BLE_AUTH_TAG_SIZE = 16,
14};
15
16enum woz_aliro_ble_protocol {
17 WOZ_ALIRO_BLE_PROTOCOL_AP = 0,
18 WOZ_ALIRO_BLE_PROTOCOL_UWB = 1,
19 WOZ_ALIRO_BLE_PROTOCOL_NOTIFICATION = 2,
20 WOZ_ALIRO_BLE_PROTOCOL_SUPPLEMENTARY = 3,
21};
22
23enum woz_aliro_ble_notification {
24 WOZ_ALIRO_BLE_NOTIFICATION_EVENT = 0,
25 WOZ_ALIRO_BLE_NOTIFICATION_RANGING = 1,
26 WOZ_ALIRO_BLE_NOTIFICATION_READER_STATUS_CHANGED = 2,
27 WOZ_ALIRO_BLE_NOTIFICATION_ACCESS_COMPLETED = 3,
28 WOZ_ALIRO_BLE_NOTIFICATION_RKE_REQUEST = 4,
29 WOZ_ALIRO_BLE_NOTIFICATION_INITIATE_ACCESS = 5,
30};
31
32enum woz_aliro_ble_supplementary_service {
33 WOZ_ALIRO_BLE_SUPPLEMENTARY_TIME_SYNC = 0,
34};
35
36enum woz_aliro_ble_result {
37 WOZ_ALIRO_BLE_OK = 0,
38 WOZ_ALIRO_BLE_INVALID_ARGUMENT = -1,
39 WOZ_ALIRO_BLE_TRUNCATED = -2,
40 WOZ_ALIRO_BLE_MALFORMED = -3,
41 WOZ_ALIRO_BLE_BUFFER_TOO_SMALL = -4,
42};
43
48 uint8_t protocol;
49 uint8_t message_id;
50 const uint8_t *payload;
51 size_t payload_length;
52};
53
54/* Parse exactly one message at the beginning of data. consumed permits an
55 * L2CAP SDU containing several concatenated Aliro messages. */
56int woz_aliro_ble_parse_message(const uint8_t *data, size_t data_length,
57 struct woz_aliro_ble_message *message, size_t *consumed);
58
59int woz_aliro_ble_build_message(uint8_t protocol, uint8_t message_id, const uint8_t *payload,
60 size_t payload_length, uint8_t *output, size_t output_capacity,
61 size_t *output_length);
62
63/* Parse Notification/Initiate Access Protocol and return the complete encoded
64 * A5 Proprietary Information TLV carried by attribute 0. */
65int woz_aliro_ble_parse_initiate_access(const struct woz_aliro_ble_message *message,
66 const uint8_t **proprietary_information,
67 size_t *proprietary_information_length);
68
69/* True for messages owned by the BLE/UWB adapter after Access Protocol
70 * completion. Keep this narrow so unrelated notifications and third-party
71 * payloads cannot enter the ranging state machine. */
72int woz_aliro_ble_is_uwb_control_message(const struct woz_aliro_ble_message *message);
73
74/* Build the unencrypted forms. The caller applies BleSK protection to the
75 * payload and adjusts the length before transmission. */
76int woz_aliro_ble_build_access_completed(uint8_t reader_capabilities, uint8_t reader_state,
77 uint8_t output[8]);
78int woz_aliro_ble_build_reader_status_changed(uint8_t operation_source, uint8_t reader_state,
79 uint8_t output[8]);
80
81#ifdef __cplusplus
82}
83#endif
int woz_aliro_ble_build_reader_status_changed(uint8_t operation_source, uint8_t reader_state, uint8_t output[8])
Build an 8-byte unencrypted BLE Reader Status Changed notification with operation_source and reader_s...
Definition ble_message.c:137
int woz_aliro_ble_build_message(uint8_t protocol, uint8_t message_id, const uint8_t *payload, size_t payload_length, uint8_t *output, size_t output_capacity, size_t *output_length)
Build a BLE protocol message with a given payload.
Definition ble_message.c:45
Parsed Aliro BLE message: protocol version, message ID, and opaque payload.
Definition ble_message.h:47