• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018-2022 NXP
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /******************************************************************************
17  *
18  *  This file contains the definition from UCI specification
19  *
20  ******************************************************************************/
21 
22 #ifndef UWB_UCI_DEFS_H
23 #define UWB_UCI_DEFS_H
24 
25 #include <stdint.h>
26 
27 /* Define the message header size for all UCI Commands and Notifications.
28 */
29 #define UCI_MSG_HDR_SIZE 4  /* per UCI spec */
30 #define UCI_MAX_PAYLOAD_SIZE 0xFF /* max control message size */
31 #define APP_DATA_MAX_SIZE  116  /* Max Applicaiton data trasnfer As per UCI Spec*/
32 #define UCI_DEVICE_INFO_MAX_SIZE 18
33 #define UCI_RESPONSE_STATUS_OFFSET 4
34 #define UCI_RESPONSE_PAYLOAD_OFFSET 5
35 #define UCI_CMD_SESSION_ID_OFFSET 4
36 #define UCI_GET_APP_CONFIG_NO_OF_PARAM_OFFSET 5
37 #define UCI_GET_APP_CONFIG_PARAM_OFFSET 6
38 
39 /* UCI Command and Notification Format:
40  * 4 byte message header:
41  * byte 0: MT PBF GID
42  * byte 1: OID
43  * byte 2: RFU - To be used for extended playload length
44  * byte 3: Message Length */
45 
46 /* MT: Message Type (byte 0) */
47 #define UCI_MT_MASK 0xE0
48 #define UCI_MT_SHIFT 5
49 #define UCI_MT_CMD 1 /* (UCI_MT_CMD << UCI_MT_SHIFT) = 0x20 */
50 #define UCI_MT_RSP 2 /* (UCI_MT_RSP << UCI_MT_SHIFT) = 0x40 */
51 #define UCI_MT_NTF 3 /* (UCI_MT_NTF << UCI_MT_SHIFT) = 0x60 */
52 
53 #define UCI_MTS_CMD 0x20
54 #define UCI_MTS_RSP 0x40
55 #define UCI_MTS_NTF 0x60
56 
57 #define UCI_NTF_BIT 0x80 /* the tUWB_VS_EVT is a notification */
58 #define UCI_RSP_BIT 0x40 /* the tUWB_VS_EVT is a response     */
59 
60 /* PBF: Packet Boundary Flag (byte 0) */
61 #define UCI_PBF_MASK 0x10
62 #define UCI_PBF_SHIFT 4
63 #define UCI_PBF_NO_OR_LAST 0x00 /* not fragmented or last fragment */
64 #define UCI_PBF_ST_CONT 0x10    /* start or continuing fragment */
65 
66 /* GID: Group Identifier (byte 0) */
67 #define UCI_GID_MASK 0x0F
68 #define UCI_GID_SHIFT 0
69 #define UCI_GID_CORE            0x00  /* 0000b UCI Core group */
70 #define UCI_GID_SESSION_MANAGE  0x01  /* 0001b Session Config commands */
71 #define UCI_GID_RANGE_MANAGE    0x02  /* 0010b Range Management group */
72 #define UCI_GID_APP_DATA_MANAGE 0x09  /* 0011b Data Control */
73 #define UCI_GID_ANDROID         0x0C  /* 1100b Android vendor group */
74 #define UCI_GID_TEST            0x0D  /* 1101b RF Test Gropup */
75 #define UCI_GID_PROPRIETARY     0x0E  /* 1110b Proprietary Group */
76 
77 #define UCI_OID_RADAR_RX_NTF    0x0A
78 /* 0100b - 1100b RFU */
79 
80 /* OID: Opcode Identifier (byte 1) */
81 #define UCI_OID_MASK 0x3F
82 #define UCI_OID_SHIFT 0
83 
84 /* builds byte0 of UCI Command and Notification packet */
85 #define UCI_MSG_BLD_HDR0(p, mt, gid) \
86   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | (gid));
87 
88 #define UCI_MSG_PBLD_HDR0(p, mt, pbf, gid) \
89   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | ((pbf) << UCI_PBF_SHIFT) | (gid));
90 
91 /* builds byte1 of UCI Command and Notification packet */
92 #define UCI_MSG_BLD_HDR1(p, oid) *(p)++ = (uint8_t)(((oid) << UCI_OID_SHIFT));
93 
94 /* parse byte0 of UCI packet */
95 #define UCI_MSG_PRS_HDR0(p, mt, pbf, gid)     \
96   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT;    \
97   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT; \
98   gid = *(p)++ & UCI_GID_MASK;
99 
100 /* parse MT and PBF bits of UCI packet */
101 #define UCI_MSG_PRS_MT_PBF(p, mt, pbf)     \
102   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT; \
103   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT;
104 
105 /* parse byte1 of UCI Cmd/Ntf */
106 #define UCI_MSG_PRS_HDR1(p, oid) \
107   oid = (*(p)&UCI_OID_MASK);     \
108   (p)++;
109 
110 #define UINT8_TO_STREAM(p, u8) \
111   { *(p)++ = (uint8_t)(u8); }
112 
113 #define ARRAY_TO_STREAM(p, a, len)                                \
114   {                                                               \
115     int ijk;                                                      \
116     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
117   }
118 
119 /* Allocate smallest possible buffer (for platforms with limited RAM) */
120 #define UCI_GET_CMD_BUF(paramlen)                                    \
121   ((UWB_HDR*)phUwb_GKI_getbuf((uint16_t)(UWB_HDR_SIZE + UCI_MSG_HDR_SIZE + \
122                                    UCI_MSG_OFFSET_SIZE + (paramlen))))
123 
124 /**********************************************
125  * UCI Core Group-0: Opcodes and size of commands
126  **********************************************/
127 #define UCI_MSG_CORE_DEVICE_RESET        0
128 #define UCI_MSG_CORE_DEVICE_STATUS_NTF   1
129 #define UCI_MSG_CORE_DEVICE_INFO    2
130 #define UCI_MSG_CORE_GET_CAPS_INFO  3
131 #define UCI_MSG_CORE_SET_CONFIG     4
132 #define UCI_MSG_CORE_GET_CONFIG     5
133 #define UCI_MSG_CORE_DEVICE_SUSPEND 6
134 #define UCI_MSG_CORE_GENERIC_ERROR_NTF 7
135 
136 #define UCI_MSG_CORE_DEVICE_RESET_CMD_SIZE 1
137 #define UCI_MSG_CORE_DEVICE_INFO_CMD_SIZE    0
138 #define UCI_MSG_CORE_GET_CAPS_INFO_CMD_SIZE  0
139 
140 /*********************************************************
141  * UCI session config Group-2: Opcodes and size of command
142  ********************************************************/
143 #define UCI_MSG_SESSION_INIT   0
144 #define UCI_MSG_SESSION_DEINIT 1
145 #define UCI_MSG_SESSION_STATUS_NTF 2
146 #define UCI_MSG_SESSION_SET_APP_CONFIG  3
147 #define UCI_MSG_SESSION_GET_APP_CONFIG  4
148 #define UCI_MSG_SESSION_GET_COUNT   5
149 #define UCI_MSG_SESSION_GET_STATE   6
150 #define UCI_MSG_SESSION_UPDATE_CONTROLLER_MULTICAST_LIST   7
151 #define UCI_MSG_SESSION_CONFIGURE_DT_ANCHOR_RR_RDM_LIST    10
152 
153 /* Pay load size for each command*/
154 #define UCI_MSG_SESSION_INIT_CMD_SIZE   5
155 #define UCI_MSG_SESSION_DEINIT_CMD_SIZE 4
156 #define UCI_MSG_SESSION_STATUS_NTF_LEN 6
157 #define UCI_MSG_SESSION_GET_COUNT_CMD_SIZE  0
158 #define UCI_MSG_SESSION_GET_STATE_SIZE   4
159 
160 /*********************************************************
161  * UWB Ranging Control Group-3: Opcodes and size of command
162  *********************************************************/
163 #define UCI_MSG_RANGE_START       0
164 #define UCI_MSG_RANGE_STOP        1
165 #define UCI_MSG_RANGE_CTRL_REQ    2
166 #define UCI_MSG_RANGE_GET_RANGING_COUNT    3
167 
168 #define UCI_MSG_RANGE_DATA_NTF 0
169 
170 #define UCI_MSG_RANGE_START_CMD_SIZE               4
171 #define UCI_MSG_RANGE_STOP_CMD_SIZE                4
172 #define UCI_MSG_RANGE_INTERVAL_UPDATE_REQ_CMD_SIZE 6
173 #define UCI_MSG_RANGE_GET_COUNT_CMD_SIZE           4
174 
175 /**********************************************
176  * UWB APP DATA  Group Opcode-4 Opcodes and size of command
177  **********************************************/
178 #define UCI_MSG_APP_DATA_TX   0
179 #define UCI_MSG_APP_DATA_RX   1
180 #define UCI_MSG_APP_DATA_TX_NTF 0
181 #define UCI_MSG_APP_DATA_RX_NTF 1
182 
183 #define UCI_MSG_APP_DATA_TX_CMD_SIZE  6
184 #define UCI_MSG_APP_DATA_RX_CMD_SIZE  6
185 #define UCI_MSG_APP_DATA_RX_NTF_SIZE  5
186 #define UCI_MSG_APP_DATA_TX_NTF_SIZE  5
187 
188 /**********************************************
189  * UCI Android Vendor Group-C: Opcodes and size of commands
190  **********************************************/
191 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE 0x01
192 
193 /**********************************************
194  * UWB Prop Group Opcode-E Opcodes
195  **********************************************/
196 #define UCI_MSG_BINDING_STATUS_NTF  0x13
197 
198 /**********************************************
199  * UCI Parameter IDs : Device Configurations
200  **********************************************/
201 #define UCI_PARAM_ID_DEVICE_STATE 0x00
202 #define UCI_PARAM_ID_LOW_POWER_MODE 0x01
203 #define UCI_PARAM_ID_LOW_POWER_MODE_LEN 0x01
204 /*
205 Reserved for Extention of IDs: 0xE0-0xE2
206 Reserved for Proprietary use: 0xE3-0xFF
207 */
208 /* UCI Parameter ID Length */
209 #define UCI_PARAM_LEN_DEVICE_STATE 1
210 #define UCI_PARAM_LEN_LOW_POWER_MODE 1
211 
212 
213 /*************************************************
214  * UCI Parameter IDs : Application Configurations
215  ************************************************/
216 #define UCI_PARAM_ID_DEVICE_ROLE                 0x00
217 #define UCI_PARAM_ID_RANGING_METHOD              0x01
218 #define UCI_PARAM_ID_STS_CONFIG                  0x02
219 #define UCI_PARAM_ID_MULTI_NODE_MODE             0x03
220 #define UCI_PARAM_ID_CHANNEL_NUMBER              0x04
221 #define UCI_PARAM_ID_NO_OF_CONTROLEE             0x05
222 #define UCI_PARAM_ID_DEVICE_MAC_ADDRESS          0x06
223 #define UCI_PARAM_ID_DST_MAC_ADDRESS             0x07
224 #define UCI_PARAM_ID_SLOT_DURATION               0x08
225 #define UCI_PARAM_ID_RANGING_INTERVAL            0x09
226 #define UCI_PARAM_ID_STS_INDEX                   0x0A
227 #define UCI_PARAM_ID_MAC_FCS_TYPE                0x0B
228 #define UCI_PARAM_ID_MEASUREMENT_REPORT_REQ      0x0C
229 #define UCI_PARAM_ID_AOA_RESULT_REQ              0x0D
230 #define UCI_PARAM_ID_RNG_DATA_NTF                0x0E
231 #define UCI_PARAM_ID_RNG_DATA_NTF_PROXIMITY_NEAR 0x0F
232 #define UCI_PARAM_ID_RNG_DATA_NTF_PROXIMITY_FAR  0x10
233 #define UCI_PARAM_ID_DEVICE_TYPE                 0x11
234 #define UCI_PARAM_ID_RFRAME_CONFIG               0x12
235 #define UCI_PARAM_ID_RX_MODE                     0x13
236 #define UCI_PARAM_ID_PREAMBLE_CODE_INDEX         0x14
237 #define UCI_PARAM_ID_SFD_ID                      0x15
238 #define UCI_PARAM_ID_PSDU_DATA_RATE              0x16
239 #define UCI_PARAM_ID_PREAMBLE_DURATION           0x17
240 #define UCI_PARAM_ID_ANTENNA_PAIR_SELECTION      0x18
241 #define UCI_PARAM_ID_MAC_CFG                     0x19
242 #define UCI_PARAM_ID_RANGING_TIME_STRUCT         0x1A
243 #define UCI_PARAM_ID_RFU                         0x1B
244 #define UCI_PARAM_ID_TX_ADAPTIVE_PAYLOAD_POWER   0x1C
245 #define UCI_PARAM_ID_TX_ANTENNA_SELECTION        0x1D
246 #define UCI_PARAM_ID_RESPONDER_SLOT_INDEX        0x1E
247 #define UCI_PARAM_ID_PRF_MODE                    0x1F
248 #define UCI_PARAM_ID_MAX_CONTENTION_PHASE_LEN    0x20
249 #define UCI_PARAM_ID_CONTENTION_PHASE_UPDATE_LEN 0x21
250 #define UCI_PARAM_ID_SCHEDULED_MODE              0x22
251 #define UCI_PARAM_ID_KEY_ROTATION                0x23
252 #define UCI_PARAM_ID_KEY_ROTATION_RATE           0x24
253 #define UCI_PARAM_ID_SESSION_PRIORITY            0x25
254 #define UCI_PARAM_ID_MAC_ADDRESS_MODE            0x26
255 #define UCI_PARAM_ID_VENDOR_ID                   0x27
256 #define UCI_PARAM_ID_STATIC_STS_IV               0x28
257 #define UCI_PARAM_ID_NUMBER_OF_STS_SEGMENTS      0x29
258 #define UCI_PARAM_ID_MAX_RR_RETRY                0x2A
259 #define UCI_PARAM_ID_UWB_INITIATION_TIME         0x2B
260 #define UCI_PARAM_ID_RANGING_ROUND_HOPPING       0x2C
261 #define UCI_PARAM_ID_SUSPEND_RANGING_ROUNDS      0x36
262 /* ENABLE_PROVISIONAL_STS_START */
263 #define UCI_PARAM_ID_SESSION_KEY                 0x45
264 #define UCI_PARAM_ID_SUB_SESSION_KEY             0x46
265 /* ENABLE_PROVISIONAL_STS_END */
266 
267 /* UCI Parameter ID Length */
268 #define UCI_PARAM_LEN_DEVICE_ROLE                 1
269 #define UCI_PARAM_LEN_RANGING_METHOD              1
270 #define UCI_PARAM_LEN_STS_CONFIG                  1
271 #define UCI_PARAM_LEN_MULTI_NODE_MODE             1
272 #define UCI_PARAM_LEN_CHANNEL_NUMBER              1
273 #define UCI_PARAM_LEN_NO_OF_CONTROLEE             1
274 #define UCI_PARAM_LEN_DEVICE_MAC_ADDRESS          2
275 #define UCI_PARAM_LEN_DEST_MAC_ADDRESS            2
276 #define UCI_PARAM_LEN_SLOT_DURATION               2
277 #define UCI_PARAM_LEN_RANGING_INTERVAL            2
278 #define UCI_PARAM_LEN_STS_INDEX                   1
279 #define UCI_PARAM_LEN_MAC_FCS_TYPE                1
280 #define UCI_PARAM_LEN_MEASUREMENT_REPORT_REQ      1
281 #define UCI_PARAM_LEN_AOA_RESULT_REQ              1
282 #define UCI_PARAM_LEN_RNG_DATA_NTF                1
283 #define UCI_PARAM_LEN_RNG_DATA_NTF_PROXIMITY_NEAR 2
284 #define UCI_PARAM_LEN_RNG_DATA_NTF_PROXIMITY_FAR  2
285 #define UCI_PARAM_LEN_DEVICE_TYPE                 1
286 #define UCI_PARAM_LEN_RFRAME_CONFIG               1
287 #define UCI_PARAM_LEN_RX_MODE                     1
288 #define UCI_PARAM_LEN_PREAMBLE_CODE_INDEX         1
289 #define UCI_PARAM_LEN_SFD_ID                      1
290 #define UCI_PARAM_LEN_PSDU_DATA_RATE              1
291 #define UCI_PARAM_LEN_PREAMPLE_DURATION           1
292 #define UCI_PARAM_LEN_ANTENA_PAIR_SELECTION       1
293 #define UCI_PARAM_LEN_MAC_CFG                     1
294 #define UCI_PARAM_LEN_RANGING_TIME_STRUCT         1
295 #define UCI_PARAM_LEN_TX_POWER_ID                 1
296 #define UCI_PARAM_LEN_TX_ADAPTIVE_PAYLOAD_POWER   1
297 #define UCI_PARAM_LEN_VENDOR_ID                   2
298 #define UCI_PARAM_LEN_STATIC_STS_IV               6
299 #define UCI_PARAM_LEN_NUMBER_OF_STS_SEGMENTS      1
300 #define UCI_PARAM_LEN_MAX_RR_RETRY                2
301 #define UCI_PARAM_LEN_UWB_INITIATION_TIME         4
302 #define UCI_PARAM_LEN_RANGING_ROUND_HOPPING       1
303 
304 /*************************************************
305  * Status codes
306  ************************************************/
307 /* Generic Status Codes */
308 #define UCI_STATUS_OK 0x00
309 #define UCI_STATUS_REJECTED 0x01
310 #define UCI_STATUS_FAILED 0x02
311 #define UCI_STATUS_SYNTAX_ERROR 0x03
312 #define UCI_STATUS_INVALID_PARAM 0x04
313 #define UCI_STATUS_INVALID_RANGE 0x05
314 #define UCI_STATUS_INVALID_MSG_SIZE 0x06
315 #define UCI_STATUS_UNKNOWN_GID 0x07
316 #define UCI_STATUS_UNKNOWN_OID 0x08
317 #define UCI_STATUS_READ_ONLY 0x09
318 #define UCI_STATUS_COMMAND_RETRY 0x0A
319 #define UCI_STATUS_THERMAL_RUNAWAY 0x54
320 #define UCI_STATUS_HW_RESET 0xFE
321 
322 /* UWB Session Specific Status Codes*/
323 #define UCI_STATUS_SESSSION_NOT_EXIST 0x11
324 #define UCI_STATUS_SESSSION_DUPLICATE 0x12
325 #define UCI_STATUS_SESSSION_ACTIVE 0x13
326 #define UCI_STATUS_MAX_SESSSIONS_EXCEEDED 0x14
327 #define UCI_STATUS_SESSION_NOT_CONFIGURED 0x15
328 
329 /* UWB Ranging Session Specific Status Codes */
330 #define UCI_STATUS_RANGING_TX_FAILED 0x20
331 #define UCI_STATUS_RANGING_RX_TIMEOUT 0x21
332 #define UCI_STATUS_RANGING_RX_PHY_DEC_FAILED 0x22
333 #define UCI_STATUS_RANGING_RX_PHY_TOA_FAILED 0x23
334 #define UCI_STATUS_RANGING_RX_PHY_STS_FAILED 0x24
335 #define UCI_STATUS_RANGING_RX_MAC_DEC_FAILED 0x25
336 #define UCI_STATUS_RANGING_RX_MAC_IE_DEC_FAILED 0x26
337 #define UCI_STATUS_RANGING_RX_MAC_IE_MISSING 0x27
338 #define UCI_STATUS_ERROR_ROUND_INDEX_NOT_ACTIVATED 0x28
339 #define UCI_STATUS_ERROR_NUMBER_OF_ACTIVE_RANGING_ROUNDS_EXCEEDED 0x29
340 #define UCI_STATUS_ERROR_ROUND_INDEX_NOT_SET_AS_INITIATOR 0x2A
341 #define UCI_STATUS_ERROR_DL_TDOA_DEVICE_ADDRESS_NOT_MATCHING_IN_REPLY_TIME_LIST 0x2B
342 
343 /* UWB Data Session Specific Status Codes */
344 #define UCI_STATUS_DATA_MAX_TX_APDU_SIZE_EXCEEDED 0x30
345 #define UCI_STATUS_DATA_RX_CRC_ERROR 0x31
346 
347 /* UWB proprietary status codes */
348 #define UCI_STATUS_ESE_RSP_TIMEOUT 0x52
349 
350 /* Status code for feature not supported */
351 #define UCI_STATUS_FEATURE_NOT_SUPPORTED 0x55
352 
353 
354 /*************************************************
355 * Device Role config
356 **************************************************/
357 #define UWB_CONTROLLER  0
358 #define UWB_CONTROLEE   1
359 
360 /*************************************************
361 * Ranging Method config
362 **************************************************/
363 #define ONE_WAY_RANGING  0
364 #define SS_TWR_RANGING   1
365 #define DS_TWR_RANGING   2
366 
367 
368 /*************************************************
369 * Ranging Mesaurement type
370 **************************************************/
371 #define MEASUREMENT_TYPE_ONEWAY  0
372 #define MEASUREMENT_TYPE_TWOWAY  1
373 #define MEASUREMENT_TYPE_DLTDOA  2
374 
375 
376 /* device status */
377 typedef enum {
378 #if(NXP_UWB_EXTNS == TRUE)
379   UWBD_STATUS_INIT=0,  /* UWBD is idle */
380 #endif
381   UWBD_STATUS_READY=1, /* UWBD is ready to establish UWB session*/
382   UWBD_STATUS_ACTIVE,  /* UWBD is Acive in performing UWB session*/
383   UWBD_STATUS_ERROR = 0xFF  /* error occured in UWBD*/
384 }eUWBD_DEVICE_STATUS_t;
385 
386 /* Session status */
387 typedef enum {
388   UWB_SESSION_INITIALIZED,
389   UWB_SESSION_DEINITIALIZED,
390   UWB_SESSION_ACTIVE,
391   UWB_SESSION_IDLE,
392   UWB_UNKNOWN_SESSION = 0xFF
393 }eSESSION_STATUS_t;
394 #endif /* UWB_UCI_DEFS_H */
395