1// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15little_endian_packets
16
17enum PacketBoundaryFlag : 1 {
18    COMPLETE = 0,
19    NOT_COMPLETE = 1,
20}
21
22enum MessageType : 3 {
23    DATA = 0x0,
24    COMMAND = 0x1,
25    RESPONSE = 0x2,
26    NOTIFICATION = 0x3,
27}
28
29enum GroupId : 4 {
30    CORE = 0x0,
31    SESSION_CONFIG = 0x1,
32    SESSION_CONTROL = 0x2,
33    DATA_CONTROL = 0x3,
34    VENDOR_RESERVED_9 = 0x9,
35    VENDOR_RESERVED_A = 0xa,
36    VENDOR_RESERVED_B = 0xb,
37    VENDOR_ANDROID    = 0xc,
38    TEST = 0xd,
39    VENDOR_RESERVED_E = 0xe,
40    VENDOR_RESERVED_F = 0xf,
41}
42
43enum DataPacketFormat : 4 {
44    DATA_SND = 0x01,
45    DATA_RCV = 0x02,
46}
47
48enum CoreOpcodeId : 6 {
49    DEVICE_RESET = 0x00,
50    DEVICE_STATUS = 0x01,
51    GET_DEVICE_INFO = 0x02,
52    GET_CAPS_INFO = 0x03,
53    SET_CONFIG = 0x04,
54    GET_CONFIG = 0x05,
55    GENERIC_ERROR = 0x07,
56    QUERY_UWBS_TIMESTAMP = 0x08,
57}
58
59enum SessionConfigOpcodeId : 6 {
60    INIT = 0x00,
61    DEINIT = 0x01,
62    STATUS = 0x02,
63    SET_APP_CONFIG = 0x03,
64    GET_APP_CONFIG = 0x04,
65    GET_COUNT = 0x05,
66    GET_STATE = 0x06,
67    UPDATE_CONTROLLER_MULTICAST_LIST = 0x07,
68    UPDATE_DT_ANCHOR_RANGING_ROUNDS = 0x08,
69    UPDATE_DT_TAG_RANGING_ROUNDS = 0x09,
70    QUERY_DATA_SIZE_IN_RANGING = 0x0b,
71}
72
73enum SessionControlOpcodeId : 6 {
74    START = 0x00, // INFO_NTF
75    STOP = 0x01,
76    GET_RANGING_COUNT = 0x03,
77    DATA_CREDIT = 0x04,
78    DATA_TRANSFER_STATUS = 0x05,
79}
80
81enum AndroidOpcodeId : 6 {
82    GET_POWER_STATS = 0x00,
83    SET_COUNTRY_CODE = 0x01,
84    FIRA_RANGE_DIAGNOSTICS = 0x02,
85}
86
87/// [UCI] 8.5 Status Codes
88enum Status : 8 {
89    // Generic Status Codes
90    OK = 0x00,
91    REJECTED = 0x01,
92    FAILED = 0x02,
93    SYNTAX_ERROR = 0x03,
94    INVALID_PARAM = 0x04,
95    INVALID_RANGE = 0x05,
96    INVALID_MESSAGE_SIZE = 0x06,
97    UNKNOWN_GID = 0x07,
98    UNKNOWN_OID = 0x08,
99    READ_ONLY = 0x09,
100    UCI_MESSAGE_RETRY = 0x0A,
101    UNKNOWN = 0x0B,
102    NOT_APPLICABLE = 0x0C,
103
104    // UWB Session Specific Status Codes
105    ERROR_SESSION_NOT_EXIST = 0x11,
106    ERROR_SESSION_DUPLICATE = 0x12,
107    ERROR_SESSION_ACTIVE = 0x13,
108    ERROR_MAX_SESSIONS_EXCEEDED = 0x14,
109    ERROR_SESSION_NOT_CONFIGURED = 0x15,
110    ERROR_ACTIVE_SESSIONS_ONGOING = 0x16,
111    ERROR_MULTICAST_LIST_FULL = 0x17,
112    ERROR_UWB_INITIATION_TIME_TOO_OLD = 0x1A,
113    OK_NEGATIVE_DISTANCE_REPORT = 0x1B,
114
115    // UWB Ranging Session Specific Status Codes
116    RANGING_TX_FAILED = 0x20,
117    RANGING_RX_TIMEOUT = 0x21,
118    RANGING_RX_PHY_DEC_FAILED = 0x22,
119    RANGING_RX_PHY_TOA_FAILED = 0x23,
120    RANGING_RX_PHY_STS_FAILED = 0x24,
121    RANGING_RX_MAC_DEC_FAILED = 0x25,
122    RANGING_RX_MAC_IE_DEC_FAILED = 0x26,
123    RANGING_RX_MAC_IE_MISSING = 0x27,
124    ERROR_ROUND_INDEX_NOT_ACTIVATED = 0x28,
125    ERROR_NUMBER_OF_ACTIVE_RANGING_ROUNDS_EXCEEDED = 0x29,
126    ERROR_DL_TDOA_DEVICE_ADDRESS_NOT_MATCHING_IN_REPLY_TIME_LIST = 0x2A,
127
128    // Vendor Specific Status Codes
129    VENDOR_SPECIFIC = 0x50..0xFF {
130        ERROR_CCC_SE_BUSY = 0x50,
131        ERROR_CCC_LIFECYCLE = 0x51,
132        ERROR_STOPPED_DUE_TO_OTHER_SESSION_CONFLICT = 0x52,
133        REGULATION_UWB_OFF = 0x53,
134    },
135
136    // All others reserved for future use
137    RFU = ..,
138}
139
140// This needs a separate StatusCode as the Status code values in the DATA_RCV packet have
141// different values from the generic StatusCode above.
142enum DataRcvStatusCode : 8 {
143    UCI_STATUS_SUCCESS = 0x00,
144    UCI_STATUS_ERROR = 0x01,
145    UCI_STATUS_UNKNOWN = 0x02,
146}
147
148enum CreditAvailability : 8 {
149    CREDIT_NOT_AVAILABLE = 0,
150    CREDIT_AVAILABLE = 1,
151}
152
153// The UCI spec defines these status codes for a DATA_TRANSFER_STATUS_NTF packet.
154enum DataTransferNtfStatusCode : 8 {
155    UCI_DATA_TRANSFER_STATUS_REPETITION_OK = 0x00,
156    UCI_DATA_TRANSFER_STATUS_OK = 0x01,
157    UCI_DATA_TRANSFER_STATUS_ERROR_DATA_TRANSFER = 0x02,
158    UCI_DATA_TRANSFER_STATUS_ERROR_NO_CREDIT_AVAILABLE = 0x03,
159    UCI_DATA_TRANSFER_STATUS_ERROR_REJECTED = 0x04,
160    UCI_DATA_TRANSFER_STATUS_SESSION_TYPE_NOT_SUPPORTED = 0x05,
161    UCI_DATA_TRANSFER_STATUS_ERROR_DATA_TRANSFER_IS_ONGOING = 0x06,
162    UCI_DATA_TRANSFER_STATUS_INVALID_FORMAT = 0x07,
163}
164
165enum ResetConfig : 8 {
166    UWBS_RESET = 0x00,
167}
168
169// [UCI] Table 45: APP Configuration Parameters IDs
170enum AppConfigTlvType : 8 {
171    DEVICE_TYPE = 0x00,
172    RANGING_ROUND_USAGE = 0x01,
173    STS_CONFIG = 0x02,
174    MULTI_NODE_MODE = 0x03,
175    CHANNEL_NUMBER = 0x04,
176    NUMBER_OF_CONTROLEES = 0x05,
177    DEVICE_MAC_ADDRESS = 0x06,
178    DST_MAC_ADDRESS = 0x07,
179    SLOT_DURATION = 0x08,
180    RANGING_DURATION = 0x09,
181    STS_INDEX = 0x0A,
182    MAC_FCS_TYPE = 0x0B,
183    RANGING_ROUND_CONTROL = 0x0C,
184    AOA_RESULT_REQ = 0x0D,
185    SESSION_INFO_NTF_CONFIG = 0x0E,
186    NEAR_PROXIMITY_CONFIG = 0x0F,
187    FAR_PROXIMITY_CONFIG = 0x10,
188    DEVICE_ROLE = 0x11,
189    RFRAME_CONFIG = 0x12,
190    RSSI_REPORTING = 0x13,
191    PREAMBLE_CODE_INDEX = 0x14,
192    SFD_ID = 0x15,
193    PSDU_DATA_RATE = 0x16,
194    PREAMBLE_DURATION = 0x17,
195    LINK_LAYER_MODE = 0x18,
196    DATA_REPETITION_COUNT = 0x19,
197    RANGING_TIME_STRUCT = 0x1A,
198    SLOTS_PER_RR = 0x1B,
199    AOA_BOUND_CONFIG = 0x1D,
200    PRF_MODE = 0x1F,
201    CAP_SIZE_RANGE = 0x20,
202    TX_JITTER_WINDOW_SIZE = 0x21,
203    SCHEDULE_MODE = 0x22,
204    KEY_ROTATION = 0x23,
205    KEY_ROTATION_RATE = 0x24,
206    SESSION_PRIORITY = 0x25,
207    MAC_ADDRESS_MODE = 0x26,
208    VENDOR_ID = 0x27,
209    STATIC_STS_IV = 0x28,
210    NUMBER_OF_STS_SEGMENTS = 0x29,
211    MAX_RR_RETRY = 0x2A,
212    UWB_INITIATION_TIME = 0x2B,
213    HOPPING_MODE = 0x2C,
214    BLOCK_STRIDE_LENGTH = 0x2D,
215    RESULT_REPORT_CONFIG = 0x2E,
216    IN_BAND_TERMINATION_ATTEMPT_COUNT = 0x2F,
217    SUB_SESSION_ID = 0x30,
218    BPRF_PHR_DATA_RATE = 0x31,
219    MAX_NUMBER_OF_MEASUREMENTS = 0x32,
220    STS_LENGTH = 0x35,
221    MIN_FRAMES_PER_RR = 0x3A,
222    MTU_SIZE = 0x3B,
223    INTER_FRAME_INTERVAL = 0x3C,
224    DL_TDOA_RANGING_METHOD  = 0x3D,
225    DL_TDOA_TX_TIMESTAMP_CONF = 0x3E,
226    DL_TDOA_HOP_COUNT = 0x3F,
227    DL_TDOA_ANCHOR_CFO = 0x40,
228    DL_TDOA_ANCHOR_LOCATION = 0x41,
229    DL_TDOA_TX_ACTIVE_RANGING_ROUNDS = 0x42,
230    DL_TDOA_BLOCK_SKIPPING = 0x43,
231    DL_TDOA_TIME_REFERENCE_ANCHOR = 0x44,
232    SESSION_KEY = 0x45,
233    SUB_SESSION_KEY = 0x46,
234    SESSION_DATA_TRANSFER_STATUS_NTF_CONFIG = 0x47,
235    SESSION_TIME_BASE = 0x48,
236    DL_TDOA_RESPONDER_TOF = 0x49,
237    SECURE_RANGING_NEFA_LEVEL = 0x4A,
238    SECURE_RANGING_CSW_LENGTH = 0x4B,
239    APPLICATION_DATA_ENDPOINT = 0x4C,
240    OWR_AOA_MEASUREMENT_NTF_PERIOD = 0x4D,
241    RFU = 0x4E..0x9F,
242
243    VENDOR_SPECIFIC_1 = 0xA0..0xDF {
244        // CCC specific
245        CCC_HOP_MODE_KEY = 0xA0,
246        CCC_UWB_TIME0 = 0xA1,
247        CCC_RANGING_PROTOCOL_VER = 0xA3,
248        CCC_UWB_CONFIG_ID = 0xA4,
249        CCC_PULSESHAPE_COMBO = 0xA5,
250        CCC_URSK_TTL = 0xA6,
251        CCC_LAST_INDEX_USED  = 0xA8,
252    },
253
254    // Reserved for extension IDs.
255    // ID is 2 Octets in length. Refer section 8.1 for details
256    ID_EXTENSION = 0xE0..0xE2,
257
258    VENDOR_SPECIFIC_2 = 0xE3..0xFF {
259        // Interleaving ratio if AOA_RESULT_REQ is set to 0xF0.
260        NB_OF_RANGE_MEASUREMENTS = 0xE3,
261        NB_OF_AZIMUTH_MEASUREMENTS = 0xE4,
262        NB_OF_ELEVATION_MEASUREMENTS = 0xE5,
263        ENABLE_DIAGNOSTICS = 0xE8,
264        DIAGRAMS_FRAME_REPORTS_FIELDS = 0xE9,
265    },
266}
267
268enum DeviceType : 8 {
269    // [MAC] 5.1.2
270    // Device utilizing the ranging features set through Control Messages
271    CONTROLEE = 0x00,
272    // [MAC] 5.1.1
273    // Device controlling the ranging features through Control Messages
274    CONTROLLER = 0x01,
275}
276
277enum RangingRoundUsage : 8 {
278    SS_TWR_DEFERRED_MODE = 0x01,
279    DS_TWR_DEFERRED_MODE = 0x02,
280    SS_TWR_NON_DEFERRED_MODE = 0x03,
281    DS_TWR_NON_DEFERRED_MODE = 0x04,
282    ON_WAY_RANGING_DL_TDOA = 0x05,
283    OWR_AOA_MEASUREMENT = 0x06,
284    ESS_TWR_NON_DEFERRED = 0x07,
285    ADS_TWR_NON_DEFERRED = 0x08,
286}
287
288enum StsConfig : 8 {
289    STATIC = 0x00, // Default
290    DYNAMIC = 0x01,
291    DYNAMIC_FOR_RESPONDER_SUB_SESSION_KEY = 0x02,
292    PROVISIONED = 0x03,
293    PROVISIONED_FOR_RESPONDER_SUB_SESSION_KEY = 0x04,
294}
295
296enum MultiNodeMode : 8 {
297    ONE_TO_ONE = 0x00,
298    ONE_TO_MANY = 0x01,
299}
300
301enum ChannelNumber : 8 {
302    CHANNEL_NUMBER_5 = 0x05,
303    CHANNEL_NUMBER_6 = 0x06,
304    CHANNEL_NUMBER_8 = 0x08,
305    CHANNEL_NUMBER_9 = 0x09, // Default
306    CHANNEL_NUMBER_10 = 0x0a,
307    CHANNEL_NUMBER_12 = 0x0c,
308    CHANNEL_NUMBER_13 = 0x0d,
309    CHANNEL_NUMBER_14 = 0x0e,
310}
311
312enum MacFcsType : 8 {
313    CRC_16 = 0x00, // Default
314    CRC_32 = 0x01,
315}
316
317struct RangingRoundControl {
318    rrrm : 1, // Default 1
319    _fixed_ = 1 : 1,
320    rcp : 1, // Default 0
321    _reserved_ : 3,
322    mrp : 1, // Default 0
323    mrm : 1, // Default 0
324}
325
326enum AoaResultReq : 8 {
327    AOA_DISABLED = 0x00,
328    AOA_ENABLED = 0x01, // Default
329    AOA_ENABLED_AZIMUTH_ONLY = 0x02,
330    AOA_ENABLED_ELEVATION_ONLY = 0x03,
331}
332
333enum SessionInfoNtfConfig : 8 {
334    DISABLE = 0x00,
335    ENABLE = 0x01, // Default
336    ENABLE_PROXIMITY_TRIGGER = 0x02,
337    ENABLE_AOA_TRIGGER = 0x03,
338    ENABLE_PROXIMITY_AOA_TRIGGER = 0x04,
339    ENABLE_PROXIMITY_EDGE_TRIGGER = 0x05,
340    ENABLE_AOA_EDGE_TRIGGER = 0x06,
341    ENABLE_PROXIMITY_AOA_EDGE_TRIGGER = 0x07,
342}
343
344enum DeviceRole : 8 {
345    // [MAC] 5.1.3
346    // Device initiating a ranging exchange with a ranging initiation message
347    RESPONDER = 0x00,
348    // [MAC] 5.1.4
349    // Device responding to ranging initiation messages
350    INITIATOR = 0x01,
351    ADVERTISER = 0x05,
352    OBSERVER = 0x06,
353    DT_ANCHOR = 0x07,
354    DT_TAG = 0x08,
355}
356
357enum RframeConfig : 8 {
358    SP0 = 0x00,
359    SP1 = 0x01,
360    SP3 = 0x03, // Default
361}
362
363enum RssiReporting : 8 {
364    DISABLE = 0x00, // Default
365    ENABLE = 0x01,
366}
367
368enum PsduDataRate : 8 {
369    DATA_RATE_6M81 = 0x00,
370    DATA_RATE_7M80 = 0x01,
371    DATA_RATE_27M2 = 0x02,
372    DATA_RATE_31M2 = 0x03,
373}
374
375enum PreambleDuration : 8 {
376    DURATION_32_SYMBOLS = 0x00,
377    DURATION_64_SYMBOLS = 0x01, // Default
378}
379
380enum LinkLayerMode : 8 {
381    BYPASS_MODE = 0x00, // Default
382}
383
384enum RangingTimeStruct : 8 {
385    BLOCK_BASED_SCHEDULING = 0x01, // Default
386}
387
388enum PrfMode : 8 {
389    BPRF_MODE = 0x00, // Default
390    HPRF_MODE_124M8 = 0x01,
391    HPRF_MODE_249M6 = 0x02,
392}
393
394enum ScheduleMode : 8 {
395    CONTENTION_BASED = 0x00,
396    TIME_SCHEDULED = 0x01,
397}
398
399enum KeyRotation : 8 {
400    DISABLE = 0x00, // Default
401    ENABLE = 0x01,
402}
403
404enum MacAddressMode : 8 {
405    // MAC address is 2 bytes and 2 bytes to be used in MAC header
406    MODE_0 = 0x00, // Default
407    // MAC address is 8 bytes and 2 bytes to be used in MAC header
408    // (Not supported).
409    MODE_1 = 0x01,
410    // MAC address is 8 bytes and 8 bytes to be used in MAC header
411    MODE_2 = 0x02,
412}
413
414enum HoppingMode : 8 {
415    DISABLE = 0x00, // Default
416    ENABLE = 0x01,
417}
418
419struct ResultReportConfig {
420    tof : 1, // Default 1
421    aoa_azimuth : 1,
422    aoa_elevation : 1,
423    aoa_fom : 1,
424    _reserved_ : 4,
425}
426
427enum BprfPhrDataRate : 8 {
428    DATA_RATE_850K = 0x00, // Default
429    DATA_RATE_6M81 = 0x01
430}
431
432enum StsLength : 8 {
433    LENGTH_32_SYMBOLS = 0x00, // Default
434    LENGTH_64_SYMBOLS = 0x01,
435    LENGTH_128_SYMBOLS = 0x02,
436}
437
438enum DlTdoaRangingMethod : 8 {
439    SS_TWR = 0x00,
440    DS_TWR = 0x01, // Default
441}
442
443enum DlTdoaAnchorCfo : 8 {
444    ANCHOR_CFO_NOT_INCLUDED = 0x00,
445    ANCHOR_CFO_INCLUDED = 0x01, // Default
446}
447
448enum SessionDataTransferStatusNtfConfig : 8 {
449    DISABLE = 0x00, // Default
450    ENABLE = 0x01,
451}
452
453enum CapTlvType : 8 {
454    SUPPORTED_FIRA_PHY_VERSION_RANGE = 0x0,
455    SUPPORTED_FIRA_MAC_VERSION_RANGE = 0x1,
456    SUPPORTED_DEVICE_ROLES = 0x2,
457    SUPPORTED_RANGING_METHOD = 0x3,
458    SUPPORTED_STS_CONFIG = 0x4,
459    SUPPORTED_MULTI_NODE_MODES = 0x5,
460    SUPPORTED_RANGING_TIME_STRUCT = 0x6,
461    SUPPORTED_SCHEDULED_MODE = 0x7,
462    SUPPORTED_HOPPING_MODE = 0x8,
463    SUPPORTED_BLOCK_STRIDING = 0x9,
464    SUPPORTED_UWB_INITIATION_TIME = 0x0A,
465    SUPPORTED_CHANNELS = 0x0B,
466    SUPPORTED_RFRAME_CONFIG = 0x0C,
467    SUPPORTED_CC_CONSTRAINT_LENGTH = 0x0D,
468    SUPPORTED_BPRF_PARAMETER_SETS = 0x0E,
469    SUPPORTED_HPRF_PARAMETER_SETS = 0x0F,
470    SUPPORTED_AOA = 0x10,
471    SUPPORTED_EXTENDED_MAC_ADDRESS = 0x11,
472    SUPPORTED_MAX_MESSAGE_SIZE = 0x12,
473    SUPPORTED_MAX_DATA_PACKET_PAYLOAD_SIZE = 0x13,
474    RFU_CAP_TLV_TYPE_RANGE_1 = 0x14..0x9F,
475
476    VENDOR_SPECIFIC_CAP_TLV_TYPE_RANGE_1 = 0xA0..0xBF {
477        // CCC specific
478        CCC_SUPPORTED_CHAPS_PER_SLOT = 0xA0,
479        CCC_SUPPORTED_SYNC_CODES = 0xA1,
480        CCC_SUPPORTED_HOPPING_CONFIG_MODES_AND_SEQUENCES = 0xA2,
481        CCC_SUPPORTED_CHANNELS = 0xA3,
482        CCC_SUPPORTED_VERSIONS = 0xA4,
483        CCC_SUPPORTED_UWB_CONFIGS = 0xA5,
484        CCC_SUPPORTED_PULSE_SHAPE_COMBOS = 0xA6,
485        CCC_SUPPORTED_RAN_MULTIPLIER = 0xA7,
486        CCC_SUPPORTED_MAX_RANGING_SESSION_NUMBER = 0xA8,
487    },
488
489    SUPPORTED_POWER_STATS = 0xC0,
490    VENDOR_SPECIFIC_CAP_TLV_TYPE_RANGE_2 = 0xC1..0xDF,
491    RFU_CAP_TLV_TYPE_RANGE_2 = 0xE0..0xE2,
492
493    VENDOR_SPECIFIC_CAP_TLV_TYPE_RANGE_3 = 0xE3..0xFF {
494        SUPPORTED_AOA_RESULT_REQ_ANTENNA_INTERLEAVING = 0xE3,
495        SUPPORTED_MIN_RANGING_INTERVAL_MS = 0xE4,
496        SUPPORTED_RANGE_DATA_NTF_CONFIG = 0xE5,
497        SUPPORTED_RSSI_REPORTING = 0xE6,
498        SUPPORTED_DIAGNOSTICS = 0xE7,
499        SUPPORTED_MIN_SLOT_DURATION_RSTU = 0xE8,
500        SUPPORTED_MAX_RANGING_SESSION_NUMBER = 0xE9,
501    },
502}
503
504
505// AOA result request type.
506// Values set for AOA_RESULT_REQ config ID.
507enum AoaResultReqType : 8 {
508    AOA_DISABLE = 0x0,
509    AOA_ENABLE = 0x01,
510    AOA_ENABLE_AZIMUTH = 0x02,
511    AOA_ENABLE_ELEVATION = 0x03,
512    AOA_ENABLE_INTERLEAVED = 0xF0,
513}
514
515enum DeviceState : 8 {
516    DEVICE_STATE_READY = 0x01,
517    DEVICE_STATE_ACTIVE = 0x02,
518    DEVICE_STATE_ERROR = 0xff,
519}
520
521enum SessionState : 8 {
522    SESSION_STATE_INIT = 0x00,
523    SESSION_STATE_DEINIT = 0x01,
524    SESSION_STATE_ACTIVE = 0x02,
525    SESSION_STATE_IDLE = 0x03,
526}
527
528enum ReasonCode : 8 {
529    STATE_CHANGE_WITH_SESSION_MANAGEMENT_COMMANDS = 0x00,
530    MAX_RANGING_ROUND_RETRY_COUNT_REACHED = 0x01,
531    MAX_NUMBER_OF_MEASUREMENTS_REACHED = 0x02,
532    SESSION_SUSPENDED_DUE_TO_INBAND_SIGNAL = 0x03,
533    SESSION_RESUMED_DUE_TO_INBAND_SIGNAL = 0x04,
534    SESSION_STOPPED_DUE_TO_INBAND_SIGNAL = 0x05,
535    RFU_REASON_CODE_RANGE_1 = 0x06..0x1C,
536    ERROR_INVALID_UL_TDOA_RANDOM_WINDOW = 0x1D,
537    ERROR_MIN_RFRAMES_PER_RR_NOT_SUPPORTED = 0x1E,
538    ERROR_TX_DELAY_NOT_SUPPORTED = 0x1F,
539    ERROR_SLOT_LENGTH_NOT_SUPPORTED = 0x20,
540    ERROR_INSUFFICIENT_SLOTS_PER_RR = 0x21,
541    ERROR_MAC_ADDRESS_MODE_NOT_SUPPORTED = 0x22,
542    ERROR_INVALID_RANGING_DURATION = 0x23,
543    ERROR_INVALID_STS_CONFIG = 0x24,
544    ERROR_INVALID_RFRAME_CONFIG = 0x25,
545    ERROR_HUS_NOT_ENOUGH_SLOTS = 0x26,
546    ERROR_HUS_CFP_PHASE_TOO_SHORT = 0x27,
547    ERROR_HUS_CAP_PHASE_TOO_SHORT = 0x28,
548    ERROR_HUS_OTHERS = 0x29,
549    ERROR_STATUS_SESSION_KEY_NOT_FOUND = 0x2A,
550    ERROR_STATUS_SUB_SESSION_KEY_NOT_FOUND = 0x2B,
551    ERROR_INVALID_PREAMBLE_CODE_INDEX = 0x2C,
552    ERROR_INVALID_SFD_ID = 0x2D,
553    ERROR_INVALID_PSDU_DATA_RATE = 0x2E,
554    ERROR_INVALID_PHR_DATA_RATE = 0x2F,
555    ERROR_INVALID_PREAMBLE_DURATION = 0x30,
556    ERROR_INVALID_STS_LENGTH = 0x31,
557    ERROR_INVALID_NUM_OF_STS_SEGMENTS = 0x32,
558    ERROR_INVALID_NUM_OF_CONTROLEES = 0x33,
559    ERROR_MAX_RANGING_REPLY_TIME_EXCEEDED = 0x34,
560    ERROR_INVALID_DST_ADDRESS_LIST = 0x35,
561    ERROR_INVALID_OR_NOT_FOUND_SUB_SESSION_ID = 0x36,
562    ERROR_INVALID_RESULT_REPORT_CONFIG = 0x37,
563    ERROR_INVALID_RANGING_ROUND_CONTROL_CONFIG = 0x38,
564    ERROR_INVALID_RANGING_ROUND_USAGE = 0x39,
565    ERROR_INVALID_MULTI_NODE_MODE = 0x3A,
566    ERROR_RDS_FETCH_FAILURE = 0x3B,
567    ERROR_REF_UWB_SESSION_DOES_NOT_EXIST = 0x3C,
568    ERROR_REF_UWB_SESSION_RANGING_DURATION_MISMATCH = 0x3D,
569    ERROR_REF_UWB_SESSION_INVALID_OFFSET_TIME = 0x3E,
570    ERROR_REF_UWB_SESSION_LOST = 0x3F,
571    RFU_REASON_CODE_RANGE_2 = 0x40..0x7F {
572        ERROR_DT_ANCHOR_RANGING_ROUNDS_NOT_CONFIGURED = 0x40,
573        ERROR_DT_TAG_RANGING_ROUNDS_NOT_CONFIGURED = 0x41,
574    },
575    VENDOR_SPECIFIC_REASON_CODE_RANGE_1 = 0x80..0xFE {
576        ERROR_INVALID_CHANNEL_WITH_AOA = 0x80,
577        ERROR_STOPPED_DUE_TO_OTHER_SESSION_CONFLICT = 0x81,
578    },
579    // For internal usage, we will use 0xFF as default.
580    VENDOR_SPECIFIC_REASON_CODE_2 = 0xFF,
581}
582
583/// [UCI] Table 40: Multicast list update status codes
584enum MulticastUpdateStatus : 8 {
585    OK_MULTICAST_LIST_UPDATE = 0x00,
586    ERROR_MULTICAST_LIST_FULL = 0x01,
587    ERROR_KEY_FETCH_FAIL = 0x02,
588    ERROR_SUB_SESSION_ID_NOT_FOUND = 0x03,
589    ERROR_SUB_SESSION_KEY_NOT_FOUND = 0x04,
590    ERROR_SUB_SESSION_KEY_NOT_APPLICABLE = 0x05,
591    ERROR_SESSION_KEY_NOT_FOUND = 0x06,
592    ERROR_ADDRESS_NOT_FOUND = 0x07,
593    ERROR_ADDRESS_ALREADY_PRESENT = 0x08,
594}
595
596enum MacAddressIndicator : 8 {
597    SHORT_ADDRESS = 0x00,
598    EXTENDED_ADDRESS = 0x01,
599}
600
601enum SessionType: 8 {
602    FIRA_RANGING_SESSION = 0x00,
603    FIRA_RANGING_AND_IN_BAND_DATA_SESSION = 0x01,
604    FIRA_DATA_TRANSFER_SESSION = 0x02,
605    FIRA_RANGING_ONLY_PHASE = 0x03,
606    FIRA_IN_BAND_DATA_PHASE = 0x04,
607    FIRA_RANGING_WITH_DATA_PHASE = 0x05,
608    CCC = 0xA0,
609    DEVICE_TEST_MODE = 0xD0,
610}
611
612// Used to parse message type
613packet CommonPacketHeader {
614  _reserved_ : 4,
615  pbf : PacketBoundaryFlag,
616  mt : MessageType,
617}
618
619// Used to parse control packet length
620packet ControlPacketHeader {
621  _reserved_ : 4,
622  pbf : PacketBoundaryFlag,
623  mt : MessageType,
624  _reserved_ : 16,
625  payload_length : 8,
626}
627
628// Used to parse data packet length
629packet DataPacketHeader {
630  _reserved_ : 4,
631  pbf : PacketBoundaryFlag,
632  mt : MessageType,
633  _reserved_ : 8,
634  payload_length : 16,
635}
636
637// Unframed UCI control packet. The framing information is masked
638// including the payload length. The user must handle segmentation and
639// reassembly on the raw bytes before attempting to parse the packet.
640packet ControlPacket {
641    gid : GroupId,
642    _reserved_ : 1,
643    mt : MessageType,
644    _payload_,
645}
646
647packet DataPacket {
648  dpf : DataPacketFormat,
649  pbf : PacketBoundaryFlag,
650  mt: MessageType,
651  _reserved_ : 8,
652  _reserved_ : 16,
653  _payload_,
654}
655
656packet DataMessageSnd : DataPacket (dpf = DATA_SND, mt = DATA) {
657    session_handle: 32,
658    destination_address: 64,
659    data_sequence_number: 16,
660    _size_(application_data): 16,
661    application_data: 8[]
662}
663
664packet DataMessageRcv : DataPacket (dpf = DATA_RCV, mt = DATA) {
665    session_handle: 32,
666    status: Status,
667    source_address: 64,
668    data_sequence_number: 16,
669    _size_(application_data): 16,
670    application_data: 8[]
671}
672
673packet CorePacket : ControlPacket (gid = CORE) {
674  oid : CoreOpcodeId,
675  _reserved_ : 2,
676  _reserved_ : 16,
677  _payload_,
678}
679
680packet SessionConfigPacket : ControlPacket (gid = SESSION_CONFIG) {
681  oid : SessionConfigOpcodeId,
682  _reserved_ : 2,
683  _reserved_ : 16,
684  _payload_,
685}
686
687packet SessionControlPacket : ControlPacket (gid = SESSION_CONTROL) {
688  oid : SessionControlOpcodeId,
689  _reserved_ : 2,
690  _reserved_ : 16,
691  _payload_,
692}
693
694packet AndroidPacket : ControlPacket (gid = VENDOR_ANDROID) {
695  oid : AndroidOpcodeId,
696  _reserved_ : 2,
697  _reserved_ : 16,
698  _payload_,
699}
700
701// ---------------------------- Core group ---------------------------------- //
702
703packet CoreDeviceResetCmd : CorePacket (mt = COMMAND, oid = DEVICE_RESET) {
704    reset_config: ResetConfig,
705}
706
707test CoreDeviceResetCmd {
708    "\x20\x00\x00\x01\x00\x00\x00\x00",
709}
710
711packet CoreDeviceResetRsp : CorePacket (mt = RESPONSE, oid = DEVICE_RESET) {
712    status: Status,
713}
714
715test CoreDeviceResetRsp {
716    "\x40\x00\x00\x01\x00\x00\x00\x00",
717}
718
719packet CoreDeviceStatusNtf : CorePacket (mt = NOTIFICATION, oid = DEVICE_STATUS) {
720    device_state: DeviceState,
721}
722
723test CoreDeviceStatusNtf {
724    "\x60\x01\x00\x01\x00\x00\x00\x01",
725}
726
727packet CoreGetDeviceInfoCmd : CorePacket (mt = COMMAND, oid = GET_DEVICE_INFO) {
728}
729
730test CoreGetDeviceInfoCmd {
731    "\x20\x02\x00\x00\x00\x00\x00",
732}
733
734packet CoreGetDeviceInfoRsp : CorePacket (mt = RESPONSE, oid = GET_DEVICE_INFO) {
735    status: Status,
736    uci_version: 16,
737    mac_version: 16,
738    phy_version: 16,
739    uci_test_version: 16,
740    _count_(vendor_spec_info): 8,
741    vendor_spec_info: 8[],
742}
743
744test CoreGetDeviceInfoRsp {
745    "\x40\x02\x00\x0b\x00\x00\x00\x01\x01\x00\x02\x00\x03\x00\x04\x00\x01\x0a",
746}
747
748packet CoreGetCapsInfoCmd : CorePacket (mt = COMMAND, oid = GET_CAPS_INFO) {
749}
750
751test CoreGetCapsInfoCmd {
752    "\x20\x03\x00\x00\x00\x00\x00",
753}
754
755struct CapTlv {
756    t: CapTlvType,
757    _count_(v): 8,
758    v: 8[],
759}
760
761
762packet CoreGetCapsInfoRsp : CorePacket (mt = RESPONSE, oid = GET_CAPS_INFO) {
763    status: Status,
764    _count_(tlvs): 8,
765    tlvs: CapTlv[],
766}
767
768test CoreGetCapsInfoRsp {
769    "\x40\x03\x00\x05\x00\x00\x00\x00\x01\x00\x01\x01",
770}
771
772// [UCI] Table 44: Device Configuration Parameters
773enum ConfigParameterId : 8 {
774    DEVICE_STATE = 0x00,
775    LOW_POWER_MODE = 0x01,
776    RFU = ..,
777}
778
779struct ConfigParameter {
780    id: ConfigParameterId,
781    _size_(value): 8,
782    value: 8[],
783}
784
785packet CoreSetConfigCmd : CorePacket (mt = COMMAND, oid = SET_CONFIG) {
786    _count_(parameters): 8,
787    parameters: ConfigParameter[],
788}
789
790test CoreSetConfigCmd {
791    "\x20\x04\x00\x03\x00\x00\x00\x01\x01\x00",
792}
793
794struct ConfigParameterStatus {
795    id: ConfigParameterId,
796    status: Status,
797}
798
799packet CoreSetConfigRsp : CorePacket (mt = RESPONSE, oid = SET_CONFIG) {
800    status: Status,
801    _count_(parameters): 8,
802    parameters: ConfigParameterStatus[],
803}
804
805test CoreSetConfigRsp {
806    "\x40\x04\x00\x04\x00\x00\x00\x01\x01\x01\x01",
807    "\x40\x04\x00\x04\x00\x00\x00\x01\x01\x01\x0B",
808}
809
810packet CoreGetConfigCmd : CorePacket (mt = COMMAND, oid = GET_CONFIG) {
811    _count_(parameter_ids): 8,
812    parameter_ids: ConfigParameterId[],
813}
814
815test CoreGetConfigCmd {
816    "\x20\x05\x00\x02\x00\x00\x00\x01\x01",
817}
818
819packet CoreGetConfigRsp : CorePacket (mt = RESPONSE, oid = GET_CONFIG) {
820    status: Status,
821    _count_(parameters): 8,
822    parameters: ConfigParameter[]
823}
824
825test CoreGetConfigRsp {
826    "\x40\x05\x00\x05\x00\x00\x00\x01\x01\x00\x01\x01",
827}
828
829packet CoreGenericErrorNtf : CorePacket (mt = NOTIFICATION, oid = GENERIC_ERROR) {
830    status: Status,
831}
832
833test CoreGenericErrorNtf {
834    "\x60\x07\x00\x01\x00\x00\x00\x01",
835}
836
837
838packet CoreQueryTimeStampCmd : CorePacket (mt = COMMAND, oid = QUERY_UWBS_TIMESTAMP) {
839}
840
841test CoreQueryTimeStampCmd {
842    "\x20\x08\x00\\x00",
843}
844
845packet CoreQueryTimeStampRsp : CorePacket (mt = RESPONSE, oid = QUERY_UWBS_TIMESTAMP) {
846    status: Status,
847    timeStamp: 64,
848}
849
850test CoreQueryTimeStampRsp {
851    "\x40\x08\x00\x09\x00\x00\x00\x01\x01\x00\x01\x01\x01",
852}
853
854// ---------------------- Session Config group ------------------------------ //
855
856packet SessionInitCmd : SessionConfigPacket (mt = COMMAND, oid = INIT) {
857    session_id: 32,
858    session_type: SessionType,
859}
860
861test SessionInitCmd {
862    "\x21\x00\x00\x05\x00\x00\x00\x01\x02\x03\x04\x01",
863}
864
865// FIRA version 2 introduces a new version of SESSION_INIT_RSP which
866// includes UWBS generated session handle.
867packet SessionInitRsp_V2 : SessionConfigPacket (mt = RESPONSE, oid = INIT) {
868    status: Status,
869    session_handle: 32,
870}
871
872test SessionInitRsp_V2 {
873    "\x41\x00\x00\x01\x00\x00\x00\x11\x00\x00\x00\x01",
874}
875
876packet SessionInitRsp : SessionConfigPacket (mt = RESPONSE, oid = INIT) {
877    status: Status,
878}
879
880test SessionInitRsp {
881    "\x41\x00\x00\x01\x00\x00\x00\x11",
882}
883
884packet SessionDeinitCmd : SessionConfigPacket (mt = COMMAND, oid = DEINIT) {
885    session_token: 32, // Session ID or Session Handle (based on UWBS version)
886}
887
888test SessionDeinitCmd {
889    "\x21\x01\x00\x04\x00\x00\x00\x01\x02\x03\x04",
890}
891
892packet SessionDeinitRsp : SessionConfigPacket (mt = RESPONSE, oid = DEINIT) {
893    status: Status,
894}
895
896test SessionDeinitRsp {
897    "\x41\x01\x00\x01\x00\x00\x00\x00",
898}
899
900packet SessionStatusNtf : SessionConfigPacket (mt = NOTIFICATION, oid = STATUS) {
901    session_token: 32, // Session ID or Session Handle (based on UWBS version)
902    session_state: SessionState,
903    // TODO(b/272775225): Switch back to the enum type ReasonCode, once PDL supports defining a
904    // range inside an enum (for the vendor-specific space), in b/267339120.
905    reason_code: 8,
906}
907
908test SessionStatusNtf {
909    "\x61\x02\x00\x06\x00\x00\x00\x01\x02\x03\x04\x02\x21",
910    "\x61\x02\x00\x06\x00\x00\x00\x01\x02\x03\x04\x01\x82", // Vendor Specific Reason Code
911}
912
913struct AppConfigTlv {
914    cfg_id: AppConfigTlvType,
915    _count_(v): 8,
916    v: 8[],
917}
918
919packet SessionSetAppConfigCmd : SessionConfigPacket (mt = COMMAND, oid = SET_APP_CONFIG) {
920    session_token: 32, // Session ID or Session Handle (based on UWBS version)
921    _count_(tlvs): 8,
922    tlvs: AppConfigTlv[]
923}
924
925test SessionSetAppConfigCmd {
926    "\x21\x03\x00\x05\x00\x00\x00\x01\x02\x03\x04\x00",
927}
928
929struct AppConfigStatus {
930    cfg_id: AppConfigTlvType,
931    status: Status,
932}
933
934packet SessionSetAppConfigRsp : SessionConfigPacket (mt = RESPONSE, oid = SET_APP_CONFIG) {
935    status: Status,
936    _count_(cfg_status): 8,
937    cfg_status: AppConfigStatus[],
938}
939
940test SessionSetAppConfigRsp {
941    "\x41\x03\x00\x04\x00\x00\x00\x01\x01\x01\x00",
942}
943
944packet SessionGetAppConfigCmd : SessionConfigPacket (mt = COMMAND, oid = GET_APP_CONFIG) {
945    session_token: 32, // Session ID or Session Handle (based on UWBS version)
946    _count_(app_cfg): 8,
947    app_cfg: AppConfigTlvType[],
948}
949
950test SessionGetAppConfigCmd {
951    "\x21\x04\x00\x05\x00\x00\x00\x01\x02\x03\x04\x00",
952}
953
954packet SessionGetAppConfigRsp : SessionConfigPacket (mt = RESPONSE, oid = GET_APP_CONFIG) {
955    status: Status,
956    _count_(tlvs): 8,
957    tlvs: AppConfigTlv[],
958}
959
960test SessionGetAppConfigRsp {
961    "\x41\x04\x00\x02\x00\x00\x00\x01\x00",
962}
963
964packet SessionGetCountCmd : SessionConfigPacket (mt = COMMAND, oid = GET_COUNT) {
965}
966
967test SessionGetCountCmd {
968    "\x21\x05\x00\x00\x00\x00\x00",
969}
970
971packet SessionGetCountRsp : SessionConfigPacket (mt = RESPONSE, oid = GET_COUNT) {
972    status: Status,
973    session_count: 8,
974}
975
976test SessionGetCountRsp {
977    "\x41\x05\x00\x02\x00\x00\x00\x00\x01",
978}
979
980packet SessionGetStateCmd : SessionConfigPacket (mt = COMMAND, oid = GET_STATE) {
981    session_token: 32, // Session ID or Session Handle (based on UWBS version)
982}
983
984test SessionGetStateCmd {
985    "\x21\x06\x00\x04\x00\x00\x00\x00\x01\x02\x03",
986}
987
988packet SessionGetStateRsp : SessionConfigPacket (mt = RESPONSE, oid = GET_STATE) {
989    status: Status,
990    session_state: SessionState,
991}
992
993test SessionGetStateRsp {
994    "\x41\x06\x00\x02\x00\x00\x00\x00\x01",
995}
996
997packet SessionUpdateDtAnchorRangingRoundsCmd : SessionConfigPacket (mt = COMMAND, oid = UPDATE_DT_ANCHOR_RANGING_ROUNDS) {
998    // TODO
999}
1000
1001packet SessionUpdateDtAnchorRangingRoundsRsp : SessionConfigPacket (mt = RESPONSE, oid = UPDATE_DT_ANCHOR_RANGING_ROUNDS) {
1002    // TODO
1003}
1004
1005packet SessionUpdateDtTagRangingRoundsCmd : SessionConfigPacket (mt = COMMAND, oid = UPDATE_DT_TAG_RANGING_ROUNDS) {
1006    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1007    _count_(ranging_round_indexes): 8,
1008    ranging_round_indexes: 8[],
1009}
1010
1011test SessionUpdateDtTagRangingRoundsCmd {
1012    "\x21\x09\x00\x0a\x00\x00\x00\x03\x03\x0f\x0c\x05\x08\x00\x00\x00\x00",
1013}
1014
1015packet SessionUpdateDtTagRangingRoundsRsp : SessionConfigPacket (mt = RESPONSE, oid = UPDATE_DT_TAG_RANGING_ROUNDS) {
1016    status: Status,
1017    _count_(ranging_round_indexes): 8,
1018    ranging_round_indexes: 8[],
1019}
1020
1021test SessionUpdateDtTagRangingRoundsRsp {
1022    "\x41\x09\x00\x03\x00\x00\x00\x01\x01\x01",
1023}
1024
1025struct Controlee {
1026    short_address: 8[2],
1027    subsession_id: 32,
1028}
1029
1030struct Controlee_V2_0_16_Byte_Version {
1031    short_address: 8[2],
1032    subsession_id: 32,
1033    subsession_key: 8[16],
1034}
1035
1036struct Controlee_V2_0_32_Byte_Version {
1037    short_address: 8[2],
1038    subsession_id: 32,
1039    subsession_key: 8[32],
1040}
1041
1042/// cf. [UCI] 7.7
1043enum UpdateMulticastListAction: 8 {
1044    ADD_CONTROLEE = 0x00,
1045    REMOVE_CONTROLEE = 0x01,
1046    ADD_CONTROLEE_WITH_SHORT_SUB_SESSION_KEY = 0x02,
1047    ADD_CONTROLEE_WITH_EXTENDED_SUB_SESSION_KEY = 0x03,
1048}
1049
1050packet SessionUpdateControllerMulticastListCmd : SessionConfigPacket (mt = COMMAND, oid = UPDATE_CONTROLLER_MULTICAST_LIST) {
1051    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1052    action: UpdateMulticastListAction,
1053    _payload_,
1054}
1055
1056struct SessionUpdateControllerMulticastListCmdPayload {
1057    _count_(controlees): 8,
1058    controlees: Controlee[],
1059}
1060
1061struct SessionUpdateControllerMulticastListCmd_2_0_16_Byte_Payload {
1062    _count_(controlees): 8,
1063    controlees: Controlee_V2_0_16_Byte_Version[],
1064}
1065
1066struct SessionUpdateControllerMulticastListCmd_2_0_32_Byte_Payload {
1067    _count_(controlees): 8,
1068    controlees: Controlee_V2_0_32_Byte_Version[],
1069}
1070
1071packet SessionUpdateControllerMulticastListRsp : SessionConfigPacket (mt = RESPONSE, oid = UPDATE_CONTROLLER_MULTICAST_LIST) {
1072    status: Status,
1073}
1074
1075test SessionUpdateControllerMulticastListRsp {
1076    "\x41\x07\x00\x01\x00\x00\x00\x00",
1077}
1078
1079struct ControleeStatus {
1080    mac_address: 8[2],
1081    status: MulticastUpdateStatus,
1082}
1083
1084packet SessionUpdateControllerMulticastListNtf : SessionConfigPacket (mt = NOTIFICATION, oid = UPDATE_CONTROLLER_MULTICAST_LIST) {
1085    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1086    _count_(controlee_status): 8,
1087    controlee_status: ControleeStatus[],
1088}
1089
1090test SessionUpdateControllerMulticastListNtf {
1091    "\x61\x07\x00\x06\x00\x00\x00\x00\x01\x02\x03\x04\x00",
1092}
1093
1094// ---------------------- Session Control group ----------------------------- //
1095
1096packet SessionDataCreditNtf : SessionControlPacket (mt = NOTIFICATION, oid = DATA_CREDIT) {
1097    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1098    credit_availability: CreditAvailability,
1099}
1100
1101test SessionDataCreditNtf {
1102    "\x62\x04\x00\x05\x00\x00\x00\x00\x00\x00\x01\x01",
1103}
1104
1105packet SessionDataTransferStatusNtf : SessionControlPacket (mt = NOTIFICATION, oid = DATA_TRANSFER_STATUS) {
1106    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1107    uci_sequence_number: 8,
1108    status: DataTransferNtfStatusCode,
1109    tx_count: 8,
1110}
1111
1112test SessionDataTransferStatusNtf {
1113    "\x62\x05\x00\x06\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00",
1114}
1115
1116packet SessionQueryMaxDataSizeInRangingCmd : SessionConfigPacket (mt = COMMAND, oid = QUERY_DATA_SIZE_IN_RANGING) {
1117    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1118}
1119
1120test SessionQueryMaxDataSizeInRangingCmd {
1121 "\x21\x0B\x00\x04\x00\x00\x00\x00",
1122}
1123
1124packet SessionQueryMaxDataSizeInRangingRsp : SessionConfigPacket (mt = RESPONSE, oid = QUERY_DATA_SIZE_IN_RANGING) {
1125    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1126    max_data_size: 16,
1127}
1128
1129test SessionQueryMaxDataSizeInRangingRsp {
1130  "\x41\x0B\x00\x06\x00\x00\x00\x00\x0E7\0x07",
1131}
1132
1133packet SessionStartCmd : SessionControlPacket (mt = COMMAND, oid = START) {
1134    session_id: 32,
1135}
1136
1137test SessionStartCmd {
1138    "\x22\x00\x00\x04\x00\x00\x00\x00\x01\x02\x03",
1139}
1140
1141packet SessionStartRsp : SessionControlPacket (mt = RESPONSE, oid = START) {
1142    status: Status,
1143}
1144
1145test SessionStartRsp {
1146    "\x42\x00\x00\x01\x00\x00\x00\x00",
1147}
1148
1149struct ShortAddressTwoWayRangingMeasurement {
1150    mac_address: 16,
1151    status: Status,
1152    nlos: 8,
1153    distance: 16,
1154    aoa_azimuth: 16,
1155    aoa_azimuth_fom: 8,
1156    aoa_elevation: 16,
1157    aoa_elevation_fom: 8,
1158    aoa_destination_azimuth: 16,
1159    aoa_destination_azimuth_fom: 8,
1160    aoa_destination_elevation: 16,
1161    aoa_destination_elevation_fom: 8,
1162    slot_index: 8,
1163    rssi: 8,
1164    // b/272301550: The pdl compiler cannot handle individual fields
1165    // larger than 64 bit. The work around is to split the 88 bit
1166    // field into two.
1167    _reserved_: 64,
1168    _reserved_: 24,
1169}
1170
1171struct ExtendedAddressTwoWayRangingMeasurement {
1172    mac_address: 64,
1173    status: Status,
1174    nlos: 8,
1175    distance: 16,
1176    aoa_azimuth: 16,
1177    aoa_azimuth_fom: 8,
1178    aoa_elevation: 16,
1179    aoa_elevation_fom: 8,
1180    aoa_destination_azimuth: 16,
1181    aoa_destination_azimuth_fom: 8,
1182    aoa_destination_elevation: 16,
1183    aoa_destination_elevation_fom: 8,
1184    slot_index: 8,
1185    rssi: 8,
1186    _reserved_: 40,
1187}
1188
1189struct ShortAddressOwrAoaRangingMeasurement {
1190    mac_address: 16,
1191    status: Status,
1192    nlos: 8,
1193    frame_sequence_number: 8,
1194    block_index: 16,
1195    aoa_azimuth: 16,
1196    aoa_azimuth_fom: 8,
1197    aoa_elevation: 16,
1198    aoa_elevation_fom: 8,
1199}
1200
1201struct ExtendedAddressOwrAoaRangingMeasurement {
1202    mac_address: 64,
1203    status: Status,
1204    nlos: 8,
1205    frame_sequence_number: 8,
1206    block_index: 16,
1207    aoa_azimuth: 16,
1208    aoa_azimuth_fom: 8,
1209    aoa_elevation: 16,
1210    aoa_elevation_fom: 8,
1211}
1212
1213enum RangingMeasurementType : 8 {
1214    ONE_WAY = 0x0,
1215    TWO_WAY = 0x1,
1216    DL_TDOA = 0x02,
1217    OWR_AOA = 0x03,
1218}
1219
1220packet SessionInfoNtf : SessionControlPacket (mt = NOTIFICATION, oid = START) {
1221    sequence_number: 32,
1222    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1223    rcr_indicator: 8,
1224    current_ranging_interval: 32,
1225    ranging_measurement_type: RangingMeasurementType,
1226    _reserved_: 8,
1227    mac_address_indicator: MacAddressIndicator,
1228    _reserved_: 64,
1229    _body_,
1230}
1231
1232packet ShortMacTwoWaySessionInfoNtf : SessionInfoNtf (ranging_measurement_type = TWO_WAY, mac_address_indicator = SHORT_ADDRESS) {
1233    _count_(two_way_ranging_measurements) : 8,
1234    two_way_ranging_measurements : ShortAddressTwoWayRangingMeasurement[],
1235    vendor_data: 8[],
1236}
1237
1238test ShortMacTwoWaySessionInfoNtf {
1239    "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1240}
1241
1242packet ExtendedMacTwoWaySessionInfoNtf : SessionInfoNtf (ranging_measurement_type = TWO_WAY, mac_address_indicator = EXTENDED_ADDRESS) {
1243    _count_(two_way_ranging_measurements) : 8,
1244    two_way_ranging_measurements : ExtendedAddressTwoWayRangingMeasurement[],
1245    vendor_data: 8[],
1246}
1247
1248test ExtendedMacTwoWaySessionInfoNtf {
1249    "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1250}
1251
1252packet ShortMacDlTDoASessionInfoNtf : SessionInfoNtf (ranging_measurement_type = DL_TDOA, mac_address_indicator = SHORT_ADDRESS) {
1253    no_of_ranging_measurements : 8,
1254    dl_tdoa_measurements : 8[],
1255}
1256
1257test ShortMacDlTDoASessionInfoNtf {
1258     "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x02\x01\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1259}
1260
1261packet ExtendedMacDlTDoASessionInfoNtf : SessionInfoNtf (ranging_measurement_type = DL_TDOA, mac_address_indicator = EXTENDED_ADDRESS) {
1262    no_of_ranging_measurements : 8,
1263    dl_tdoa_measurements : 8[],
1264}
1265
1266test ExtendedMacDlTDoASessionInfoNtf {
1267     "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1268}
1269
1270packet ShortMacOwrAoaSessionInfoNtf : SessionInfoNtf (ranging_measurement_type = OWR_AOA, mac_address_indicator = SHORT_ADDRESS) {
1271    _count_(owr_aoa_ranging_measurements) : 8,
1272    owr_aoa_ranging_measurements : ShortAddressOwrAoaRangingMeasurement[],
1273    vendor_data: 8[],
1274}
1275
1276test ShortMacOwrAoaSessionInfoNtf {
1277    "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1278    "\x62\x00\x00\x26\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xbb\x00\x00\x01\x01\x00\x03\x04\x60\x05\x06\x50",
1279}
1280
1281packet ExtendedMacOwrAoaSessionInfoNtf : SessionInfoNtf (ranging_measurement_type = OWR_AOA, mac_address_indicator = EXTENDED_ADDRESS) {
1282    _count_(owr_aoa_ranging_measurements) : 8,
1283    owr_aoa_ranging_measurements : ExtendedAddressOwrAoaRangingMeasurement[],
1284    vendor_data: 8[],
1285}
1286
1287test ExtendedMacOwrAoaSessionInfoNtf {
1288    "\x62\x00\x00\x19\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1289    "\x62\x00\x00\x2c\x00\x00\x00\x00\x02\x03\x04\x05\x06\x07\x08\x00\x0a\x01\x01\x01\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\xaa\xbb\xcc\xdd\x01\x02\x03\x04\x00\x00\x01\x01\x00\x03\x04\x60\x05\x06\x50",
1290}
1291
1292packet SessionStopCmd : SessionControlPacket (mt = COMMAND, oid = STOP) {
1293    session_id: 32,
1294}
1295
1296test SessionStopCmd {
1297    "\x22\x01\x00\x04\x00\x00\x00\x00\x02\x03\x04",
1298}
1299
1300packet SessionStopRsp : SessionControlPacket (mt = RESPONSE, oid = STOP) {
1301    status: Status,
1302}
1303
1304test SessionStopRsp {
1305    "\x42\x01\x00\x01\x00\x00\x00\x00",
1306}
1307
1308packet SessionGetRangingCountCmd : SessionControlPacket (mt = COMMAND, oid = GET_RANGING_COUNT) {
1309    session_id: 32,
1310}
1311
1312test SessionGetRangingCountCmd {
1313    "\x22\x03\x00\x04\x00\x00\x00\x00\x02\x03\x04",
1314}
1315
1316packet SessionGetRangingCountRsp : SessionControlPacket (mt = RESPONSE, oid = GET_RANGING_COUNT) {
1317    status: Status,
1318    count: 32,
1319}
1320
1321test SessionGetRangingCountRsp {
1322    "\x42\x03\x00\x05\x00\x00\x00\x00\x02\x03\x04\x05",
1323}
1324
1325// -------------------------- Android group --------------------------------- //
1326
1327packet AndroidGetPowerStatsCmd : AndroidPacket (mt = COMMAND, oid = GET_POWER_STATS) {
1328}
1329
1330test AndroidGetPowerStatsCmd {
1331    "\x2c\x00\x00\x00\x00\x00\x00",
1332}
1333
1334struct PowerStats {
1335    status: Status,
1336    idle_time_ms: 32,
1337    tx_time_ms: 32,
1338    rx_time_ms: 32,
1339    total_wake_count:32,
1340}
1341
1342packet AndroidGetPowerStatsRsp : AndroidPacket (mt = RESPONSE, oid = GET_POWER_STATS) {
1343    stats: PowerStats,
1344}
1345
1346test AndroidGetPowerStatsRsp {
1347    "\x4c\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1348}
1349
1350packet AndroidSetCountryCodeCmd: AndroidPacket (mt = COMMAND, oid = SET_COUNTRY_CODE) {
1351    country_code : 8[2],
1352}
1353
1354// Set country code to US.
1355test AndroidSetCountryCodeCmd {
1356    "\x2c\x01\x00\x02\x00\x00\x00\x55\x53",
1357}
1358
1359packet AndroidSetCountryCodeRsp : AndroidPacket (mt = RESPONSE, oid = SET_COUNTRY_CODE) {
1360    status: Status,
1361}
1362
1363test AndroidSetCountryCodeRsp {
1364    "\x4c\x01\x00\x01\x00\x00\x00\x00",
1365}
1366
1367enum FrameReportTlvType : 8 {
1368    RSSI = 0x0,
1369    AOA = 0x1,
1370    CIR = 0x2,
1371}
1372
1373struct FrameReportTlv {
1374    t: FrameReportTlvType,
1375    _size_(v): 16,
1376    v: 8[],
1377}
1378
1379packet FrameReportTlvPacket {
1380    t: FrameReportTlvType,
1381    _size_(_body_): 16,
1382    _body_,
1383}
1384
1385packet Rssi : FrameReportTlvPacket (t = RSSI) {
1386    rssi: 8[],
1387}
1388
1389struct AoaMeasurement {
1390    tdoa: 16,
1391    pdoa: 16,
1392    aoa: 16,
1393    fom: 8,
1394    t: 8,
1395}
1396
1397packet Aoa : FrameReportTlvPacket (t = AOA) {
1398    aoa: AoaMeasurement[],
1399}
1400
1401test Aoa {
1402    "\x01\x08\x00\x00\x01\x00\x01\x00\x01\x01\x01",
1403}
1404
1405struct CirValue {
1406    first_path_index : 16,
1407    first_path_snr: 16,
1408    first_path_ns: 16,
1409    peak_path_index: 16,
1410    peak_path_snr: 16,
1411    peak_path_ns: 16,
1412    first_path_sample_offset: 8,
1413    samples_number: 8,
1414    _size_(sample_window): 16,
1415    sample_window: 8[],
1416}
1417
1418packet Cir : FrameReportTlvPacket (t = CIR) {
1419    _count_(cir_value): 8,
1420    cir_value: CirValue[],
1421}
1422
1423test Cir {
1424    "\x02\x15\x00\x01\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x00\x02\x04\x00\x01\x02\x03\x04",
1425}
1426
1427struct FrameReport {
1428    uwb_msg_id: 8,
1429    action: 8,
1430    antenna_set: 8,
1431    _count_(frame_report_tlvs): 8,
1432    frame_report_tlvs: FrameReportTlv[],
1433}
1434
1435packet AndroidRangeDiagnosticsNtf : AndroidPacket (mt = NOTIFICATION, oid = FIRA_RANGE_DIAGNOSTICS) {
1436    session_token: 32, // Session ID or Session Handle (based on UWBS version)
1437    sequence_number: 32,
1438    _count_(frame_reports): 8,
1439    frame_reports: FrameReport[],
1440}
1441
1442test AndroidRangeDiagnosticsNtf {
1443    "\x6c\x02\x00\x11\x00\x00\x00\x01\x01\x01\x01\x02\x02\x02\x02\x01\x00\x01\x02\x01\x00\x01\x00\x00",
1444    "\x6c\x02\x00\x34\x00\x00\x00\x01\x01\x01\x01\x02\x02\x02\x02\x01\x00\x01\x02\x03\x01\x08\x00\x01\x02\x01\x02\x01\x02\x01\x01\x02\x15\x00\x01\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x01\x02\x00\x02\x04\x00\x01\x02\x03\x04\x00\x01\x00\x00",
1445}
1446