• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Copyright 2021 NXP.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * You may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  *
21  *  This file contains the definition from UCI specification
22  *
23  ******************************************************************************/
24 
25 #ifndef UWB_UCI_DEFS_H
26 #define UWB_UCI_DEFS_H
27 
28 #include <stdint.h>
29 
30 /* Define the message header size for all UCI Commands and Notifications.
31  */
32 #define UCI_MSG_HDR_SIZE 0x04     /* per UCI spec */
33 #define UCI_MAX_PAYLOAD_SIZE 4096 /* max control message size */
34 #define UCI_MAX_PKT_SIZE 259 /* Max payload size + header size */
35 #define UCI_PSDU_SIZE_4K 4096     /* PSDU Data size */
36 #define UCI_VENDOR_INFO_MAX_SIZE 0xFF
37 
38 #define UCI_PAYLOAD_SUPPORT 1
39 #define MAX_UCI_DATA_PKT_SIZE 4096
40 #define LENGTH_INDCATOR_BIT 0x80  // 1000 0000
41 #define UCI_LENGTH_SHIFT 8
42 #define UCI_RESPONSE_STATUS_OFFSET 0x04
43 
44 /* UCI Command and Notification Format:
45  * 4 byte message header:
46  * byte 0: MT PBF GID
47  * byte 1: OID
48  * byte 2: RFU - To be used for extended playload length
49  * byte 3: Message Length */
50 
51 /* MT: Message Type (byte 0) */
52 #define UCI_MT_MASK 0xE0
53 #define UCI_MT_SHIFT 0x05
54 #define UCI_MT_CMD 0x01 /* (UCI_MT_CMD << UCI_MT_SHIFT) = 0x20 */
55 #define UCI_MT_RSP 0x02 /* (UCI_MT_RSP << UCI_MT_SHIFT) = 0x40 */
56 #define UCI_MT_NTF 0x03 /* (UCI_MT_NTF << UCI_MT_SHIFT) = 0x60 */
57 
58 #define UCI_MTS_CMD 0x20
59 #define UCI_MTS_RSP 0x40
60 #define UCI_MTS_NTF 0x60
61 
62 #define UCI_NTF_BIT 0x80 /* the tUWB_VS_EVT is a notification */
63 #define UCI_RSP_BIT 0x40 /* the tUWB_VS_EVT is a response     */
64 
65 /* PBF: Packet Boundary Flag (byte 0) */
66 #define UCI_PBF_MASK 0x10
67 #define UCI_PBF_SHIFT 0x04
68 #define UCI_PBF_NO_OR_LAST 0x00 /* not fragmented or last fragment */
69 #define UCI_PBF_ST_CONT 0x10    /* start or continuing fragment */
70 
71 /* GID: Group Identifier (byte 0) */
72 #define UCI_GID_MASK 0x0F
73 #define UCI_GID_SHIFT 0x00
74 #define UCI_GID_CORE 0x00           /* 0000b UCI Core group */
75 #define UCI_GID_SESSION_MANAGE 0x01 /* 0001b Session Config commands */
76 #define UCI_GID_RANGE_MANAGE 0x02   /* 0010b Range Management group */
77 #define UCI_GID_ANDROID 0x0E        /* 1110b Android vendor group */
78 #define UCI_GID_TEST 0x0D           /* 1101b RF Test Gropup */
79 
80 /* Vendor specific group Identifier */
81 #define UCI_GID_VENDOR_SPECIFIC_0x09 0x09
82 #define UCI_GID_VENDOR_SPECIFIC_0x0A 0x0A
83 #define UCI_GID_VENDOR_SPECIFIC_0x0B 0x0B
84 #define UCI_GID_VENDOR_SPECIFIC_0x0C 0x0C
85 #define UCI_GID_VENDOR_SPECIFIC_0x0E 0x0E
86 #define UCI_GID_VENDOR_SPECIFIC_0x0F 0x0F
87 
88 /* OID: Opcode Identifier (byte 1) */
89 #define UCI_OID_MASK 0x3F
90 #define UCI_OID_SHIFT 0x00
91 
92 /* builds byte0 of UCI Command and Notification packet */
93 #define UCI_MSG_BLD_HDR0(p, mt, gid) \
94   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | (gid));
95 
96 #define UCI_MSG_PBLD_HDR0(p, mt, pbf, gid) \
97   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | ((pbf) << UCI_PBF_SHIFT) | (gid));
98 
99 /* builds byte1 of UCI Command and Notification packet */
100 #define UCI_MSG_BLD_HDR1(p, oid) *(p)++ = (uint8_t)(((oid) << UCI_OID_SHIFT));
101 
102 /* parse byte0 of UCI packet */
103 #define UCI_MSG_PRS_HDR0(p, mt, pbf, gid)     \
104   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT;    \
105   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT; \
106   gid = *(p)++ & UCI_GID_MASK;
107 
108 /* parse MT and PBF bits of UCI packet */
109 #define UCI_MSG_PRS_MT_PBF(p, mt, pbf)     \
110   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT; \
111   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT;
112 
113 /* parse byte1 of UCI Cmd/Ntf */
114 #define UCI_MSG_PRS_HDR1(p, oid) \
115   oid = (*(p)&UCI_OID_MASK);     \
116   (p)++;
117 
118 /* Allocate smallest possible buffer (for platforms with limited RAM) */
119 #define UCI_GET_CMD_BUF(paramlen)                                          \
120   ((UWB_HDR*)phUwb_GKI_getbuf((uint16_t)(UWB_HDR_SIZE + UCI_MSG_HDR_SIZE + \
121                                          UCI_MSG_OFFSET_SIZE + (paramlen))))
122 
123 /**********************************************
124  * UCI Core Group-0: Opcodes and size of commands
125  **********************************************/
126 #define UCI_MSG_CORE_DEVICE_RESET 0x00
127 #define UCI_MSG_CORE_DEVICE_STATUS_NTF 0x01
128 #define UCI_MSG_CORE_DEVICE_INFO 0x02
129 #define UCI_MSG_CORE_GET_CAPS_INFO 0x03
130 #define UCI_MSG_CORE_SET_CONFIG 0x04
131 #define UCI_MSG_CORE_GET_CONFIG 0x05
132 #define UCI_MSG_CORE_DEVICE_SUSPEND 0x06
133 #define UCI_MSG_CORE_GENERIC_ERROR_NTF 0x07
134 
135 #define UCI_MSG_CORE_DEVICE_RESET_CMD_SIZE 0x01
136 #define UCI_MSG_CORE_DEVICE_INFO_CMD_SIZE 0x00
137 #define UCI_MSG_CORE_GET_CAPS_INFO_CMD_SIZE 0x00
138 
139 /*********************************************************
140  * UCI session config Group-2: Opcodes and size of command
141  ********************************************************/
142 #define UCI_MSG_SESSION_INIT 0x00
143 #define UCI_MSG_SESSION_DEINIT 0x01
144 #define UCI_MSG_SESSION_STATUS_NTF 0x02
145 #define UCI_MSG_SESSION_SET_APP_CONFIG 0x03
146 #define UCI_MSG_SESSION_GET_APP_CONFIG 0x04
147 #define UCI_MSG_SESSION_GET_COUNT 0x05
148 #define UCI_MSG_SESSION_GET_STATE 0x06
149 #define UCI_MSG_SESSION_UPDATE_CONTROLLER_MULTICAST_LIST 0x07
150 
151 /* Pay load size for each command*/
152 #define UCI_MSG_SESSION_INIT_CMD_SIZE 0x05
153 #define UCI_MSG_SESSION_DEINIT_CMD_SIZE 0x04
154 #define UCI_MSG_SESSION_STATUS_NTF_LEN 0x06
155 #define UCI_MSG_SESSION_GET_COUNT_CMD_SIZE 0x00
156 #define UCI_MSG_SESSION_GET_STATE_SIZE 0x04
157 
158 /*********************************************************
159  * UWB Ranging Control Group-3: Opcodes and size of command
160  *********************************************************/
161 #define UCI_MSG_RANGE_START 0x00
162 #define UCI_MSG_RANGE_STOP 0x01
163 #define UCI_MSG_RANGE_GET_RANGING_COUNT 0x03
164 #define UCI_MSG_RANGE_BLINK_DATA_TX 0x04
165 
166 #define UCI_MSG_RANGE_DATA_NTF 0x00
167 #define UCI_MSG_RANGE_BLINK_DATA_TX_NTF 0x04
168 
169 #define UCI_MSG_RANGE_START_CMD_SIZE 0x04
170 #define UCI_MSG_RANGE_STOP_CMD_SIZE 0x04
171 #define UCI_MSG_RANGE_GET_COUNT_CMD_SIZE 0x04
172 
173 /**********************************************
174  * UCI Android Vendor Group-E: Opcodes and size of commands
175  **********************************************/
176 #define UCI_MSG_ANDROID_GET_POWER_STATS 0x00
177 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE 0x01
178 
179 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE_CMD_SIZE COUNTRY_CODE_ARRAY_LEN
180 
181 /**********************************************
182  * UCI Parameter IDs : Device Configurations
183  **********************************************/
184 #define UCI_PARAM_ID_DEVICE_STATE 0x00
185 #define UCI_PARAM_ID_LOW_POWER_MODE 0x01
186 
187 /* UCI Parameter ID Length */
188 #define UCI_PARAM_LEN_DEVICE_STATE 0x01
189 #define UCI_PARAM_LEN_LOW_POWER_MODE 0x01
190 
191 /*************************************************
192  * UCI Parameter IDs : Application Configurations
193  ************************************************/
194 #define UCI_PARAM_ID_DEVICE_TYPE 0x00
195 #define UCI_PARAM_ID_RANGING_ROUND_USAGE 0x01
196 #define UCI_PARAM_ID_STS_CONFIG 0x02
197 #define UCI_PARAM_ID_MULTI_NODE_MODE 0x03
198 #define UCI_PARAM_ID_CHANNEL_NUMBER 0x04
199 #define UCI_PARAM_ID_NO_OF_CONTROLEE 0x05
200 #define UCI_PARAM_ID_DEVICE_MAC_ADDRESS 0x06
201 #define UCI_PARAM_ID_DST_MAC_ADDRESS 0x07
202 #define UCI_PARAM_ID_SLOT_DURATION 0x08
203 #define UCI_PARAM_ID_RANGING_INTERVAL 0x09
204 #define UCI_PARAM_ID_STS_INDEX 0x0A
205 #define UCI_PARAM_ID_MAC_FCS_TYPE 0x0B
206 #define UCI_PARAM_ID_RANGING_ROUND_CONTROL 0x0C
207 #define UCI_PARAM_ID_AOA_RESULT_REQ 0x0D
208 #define UCI_PARAM_ID_RNG_DATA_NTF 0x0E
209 #define UCI_PARAM_ID_RNG_DATA_NTF_PROXIMITY_NEAR 0x0F
210 #define UCI_PARAM_ID_RNG_DATA_NTF_PROXIMITY_FAR 0x10
211 #define UCI_PARAM_ID_DEVICE_ROLE 0x11
212 #define UCI_PARAM_ID_RFRAME_CONFIG 0x12
213 #define UCI_PARAM_ID_PREAMBLE_CODE_INDEX 0x14
214 #define UCI_PARAM_ID_SFD_ID 0x15
215 #define UCI_PARAM_ID_PSDU_DATA_RATE 0x16
216 #define UCI_PARAM_ID_PREAMBLE_DURATION 0x17
217 #define UCI_PARAM_ID_RANGING_TIME_STRUCT 0x1A
218 #define UCI_PARAM_ID_SLOTS_PER_RR 0x1B
219 #define UCI_PARAM_ID_TX_ADAPTIVE_PAYLOAD_POWER 0x1C
220 #define UCI_PARAM_ID_RESPONDER_SLOT_INDEX 0x1E
221 #define UCI_PARAM_ID_PRF_MODE 0x1F
222 #define UCI_PARAM_ID_SCHEDULED_MODE 0x22
223 #define UCI_PARAM_ID_KEY_ROTATION 0x23
224 #define UCI_PARAM_ID_KEY_ROTATION_RATE 0x24
225 #define UCI_PARAM_ID_SESSION_PRIORITY 0x25
226 #define UCI_PARAM_ID_MAC_ADDRESS_MODE 0x26
227 #define UCI_PARAM_ID_VENDOR_ID 0x27
228 #define UCI_PARAM_ID_STATIC_STS_IV 0x28
229 #define UCI_PARAM_ID_NUMBER_OF_STS_SEGMENTS 0x29
230 #define UCI_PARAM_ID_MAX_RR_RETRY 0x2A
231 #define UCI_PARAM_ID_UWB_INITIATION_TIME 0x2B
232 #define UCI_PARAM_ID_HOPPING_MODE 0x2C
233 #define UCI_PARAM_ID_BLOCK_STRIDE_LENGTH 0x2D
234 #define UCI_PARAM_ID_RESULT_REPORT_CONFIG 0x2E
235 #define UCI_PARAM_ID_IN_BAND_TERMINATION_ATTEMPT_COUNT 0x2F
236 #define UCI_PARAM_ID_SUB_SESSION_ID 0x30
237 #define UCI_PARAM_ID_BPRF_PHR_DATA_RATE 0x31
238 #define UCI_PARAM_ID_MAX_NUMBER_OF_MEASUREMENTS 0x32
239 
240 /* UCI Parameter ID Length */
241 #define UCI_PARAM_LEN_DEVICE_ROLE 0x01
242 #define UCI_PARAM_LEN_RANGING_ROUND_USAGE 0x01
243 #define UCI_PARAM_LEN_STS_CONFIG 0x01
244 #define UCI_PARAM_LEN_MULTI_NODE_MODE 0x01
245 #define UCI_PARAM_LEN_CHANNEL_NUMBER 0x01
246 #define UCI_PARAM_LEN_NO_OF_CONTROLEE 0x01
247 #define UCI_PARAM_LEN_DEVICE_MAC_ADDRESS 0x02
248 #define UCI_PARAM_LEN_DEST_MAC_ADDRESS 0x02
249 #define UCI_PARAM_LEN_SLOT_DURATION 0x02
250 #define UCI_PARAM_LEN_RANGING_INTERVAL 0x02
251 #define UCI_PARAM_LEN_STS_INDEX 0x01
252 #define UCI_PARAM_LEN_MAC_FCS_TYPE 0x01
253 #define UCI_PARAM_LEN_RANGING_ROUND_CONTROL 0x01
254 #define UCI_PARAM_LEN_AOA_RESULT_REQ 0x01
255 #define UCI_PARAM_LEN_RNG_DATA_NTF 0x01
256 #define UCI_PARAM_LEN_RNG_DATA_NTF_PROXIMITY_NEAR 0x02
257 #define UCI_PARAM_LEN_RNG_DATA_NTF_PROXIMITY_FAR 0x02
258 #define UCI_PARAM_LEN_DEVICE_TYPE 0x01
259 #define UCI_PARAM_LEN_RFRAME_CONFIG 0x01
260 #define UCI_PARAM_LEN_RX_MODE 0x01
261 #define UCI_PARAM_LEN_PREAMBLE_CODE_INDEX 0x01
262 #define UCI_PARAM_LEN_SFD_ID 0x01
263 #define UCI_PARAM_LEN_PSDU_DATA_RATE 0x01
264 #define UCI_PARAM_LEN_PREAMPLE_DURATION 0x01
265 #define UCI_PARAM_LEN_ANTENA_PAIR_SELECTION 0x01
266 #define UCI_PARAM_LEN_MAC_CFG 0x01
267 #define UCI_PARAM_LEN_RANGING_TIME_STRUCT 0x01
268 #define UCI_PARAM_LEN_SLOTS_PER_RR 0x01
269 #define UCI_PARAM_LEN_TX_POWER_ID 0x01
270 #define UCI_PARAM_LEN_TX_ADAPTIVE_PAYLOAD_POWER 0x01
271 #define UCI_PARAM_LEN_VENDOR_ID 0x02
272 #define UCI_PARAM_LEN_STATIC_STS_IV 0x06
273 #define UCI_PARAM_LEN_NUMBER_OF_STS_SEGMENTS 0x01
274 #define UCI_PARAM_LEN_MAX_RR_RETRY 0x02
275 #define UCI_PARAM_LEN_UWB_INITIATION_TIME 0x04
276 #define UCI_PARAM_LEN_HOPPING_MODE 0x01
277 #define UCI_PARAM_LEN_RESULT_REPORT_CONFIG 0x01
278 #define UCI_PARAM_LEN_IN_BAND_TERMINATION_ATTEMPT_COUNT 0x01
279 #define UCI_PARAM_LEN_SUB_SESSION_ID 0x04
280 #define UCI_PARAM_LEN_BLOCK_STRIDE_LENGTH 0x01
281 
282 #define MAX_VENDOR_INFO_LENGTH   1000 // vendor specific info of rangedata max length considering 24 measures for TDOA
283 
284 /*************************************************
285  * Status codes
286  ************************************************/
287 /* Generic Status Codes */
288 #define UCI_STATUS_OK 0x00
289 #define UCI_STATUS_REJECTED 0x01
290 #define UCI_STATUS_FAILED 0x02
291 #define UCI_STATUS_SYNTAX_ERROR 0x03
292 #define UCI_STATUS_INVALID_PARAM 0x04
293 #define UCI_STATUS_INVALID_RANGE 0x05
294 #define UCI_STATUS_INVALID_MSG_SIZE 0x06
295 #define UCI_STATUS_UNKNOWN_GID 0x07
296 #define UCI_STATUS_UNKNOWN_OID 0x08
297 #define UCI_STATUS_READ_ONLY 0x09
298 #define UCI_STATUS_COMMAND_RETRY 0x0A
299 
300 /* UWB Session Specific Status Codes*/
301 #define UCI_STATUS_SESSSION_NOT_EXIST 0x11
302 #define UCI_STATUS_SESSSION_DUPLICATE 0x12
303 #define UCI_STATUS_SESSSION_ACTIVE 0x13
304 #define UCI_STATUS_MAX_SESSSIONS_EXCEEDED 0x14
305 #define UCI_STATUS_SESSION_NOT_CONFIGURED 0x15
306 
307 /* UWB Ranging Session Specific Status Codes */
308 #define UCI_STATUS_RANGING_TX_FAILED 0x20
309 #define UCI_STATUS_RANGING_RX_TIMEOUT 0x21
310 #define UCI_STATUS_RANGING_RX_PHY_DEC_FAILED 0x22
311 #define UCI_STATUS_RANGING_RX_PHY_TOA_FAILED 0x23
312 #define UCI_STATUS_RANGING_RX_PHY_STS_FAILED 0x24
313 #define UCI_STATUS_RANGING_RX_MAC_DEC_FAILED 0x25
314 #define UCI_STATUS_RANGING_RX_MAC_IE_DEC_FAILED 0x26
315 #define UCI_STATUS_RANGING_RX_MAC_IE_MISSING 0x27
316 
317 /* UWB Data Session Specific Status Codes */
318 #define UCI_STATUS_DATA_MAX_TX_PSDU_SIZE_EXCEEDED 0x30
319 #define UCI_STATUS_DATA_RX_CRC_ERROR 0x31
320 
321 /*************************************************
322  * Device Role config
323  **************************************************/
324 #define UWB_CONTROLLER 0x00
325 #define UWB_CONTROLEE 0x01
326 
327 /*************************************************
328  * Ranging Method config
329  **************************************************/
330 #define ONE_WAY_RANGING 0x00
331 #define SS_TWR_RANGING 0x01
332 #define DS_TWR_RANGING 0x02
333 
334 /*************************************************
335  * Ranging Mesaurement type
336  **************************************************/
337 #define MEASUREMENT_TYPE_ONEWAY 0x00
338 #define MEASUREMENT_TYPE_TWOWAY 0x01
339 
340 /*************************************************
341  * Mac Addressing Mode Indicator
342  **************************************************/
343 #define SHORT_MAC_ADDRESS 0x00
344 #define EXTENDED_MAC_ADDRESS 0x01
345 #define EXTENDED_MAC_ADDRESS_AND_HEADER 0x02
346 
347 #define SESSION_ID_LEN 0x04
348 #define SHORT_ADDRESS_LEN 0x02
349 #define EXTENDED_ADDRESS_LEN 0x08
350 #define MAX_NUM_OF_TDOA_MEASURES 24
351 #define MAX_NUM_RESPONDERS \
352   12  // max number of responders for contention based raning
353 #define MAX_NUM_CONTROLLEES \
354   8  // max bumber of controlees for  time schedules rangng ( multicast)
355 #define COUNTRY_CODE_ARRAY_LEN 2
356 
357 /* device status */
358 typedef enum {
359   UWBS_STATUS_READY = 0x01,   /* UWBS is ready for  performing uwb session with
360                                  non SE use cases */
361   UWBS_STATUS_ACTIVE,         /* UWBS is busy running uwb session */
362   UWBS_STATUS_TIMEOUT = 0xFE, /* To notify timeout to UWB service layer */
363   UWBS_STATUS_ERROR = 0xFF    /* error occured in UWBS*/
364 } eUWBS_DEVICE_STATUS_t;
365 
366 /* Session status */
367 typedef enum {
368   UWB_SESSION_INITIALIZED,
369   UWB_SESSION_DEINITIALIZED,
370   UWB_SESSION_ACTIVE,
371   UWB_SESSION_IDLE,
372   UWB_UNKNOWN_SESSION = 0xFF
373 } eSESSION_STATUS_t;
374 
375 /* Session status idle reason code */
376 typedef enum {
377   UWB_SESSION_STATE_CHANGED = 0x00,
378   UWB_SESSION_MAX_RR_RETRY_COUNT_REACHED = 0x01,
379   UWB_SESSION_MAX_RANGING_MEASUREMENTS_REACHED = 0x02,
380   UWB_SESSION_SLOT_LENTGH_NOT_SUPPORTED = 0x20,
381   UWB_SESSION_SLOTS_PER_RR_NOT_SUFFICIENT = 0x21,
382   UWB_SESSION_MAC_ADDRESS_MODE_NOT_SUPPORTED = 0x22,
383   UWB_SESSION_INVALID_RANGING_INTERVAL = 0x23,
384   UWB_SESSION_INVALID_STS_CONFIG = 0x24,
385   UWB_SESSION_INVALID_RFRAME_CONFIG = 0x25
386 } eSESSION_STATUS_REASON_CODES_t;
387 
388 #endif /* UWB_UCI_DEFS_H */
389