• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018-2025 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  *
19  *  This file contains the definition from UCI specification
20  *
21  ******************************************************************************/
22 
23 #ifndef UWB_UCI_DEFS_H
24 #define UWB_UCI_DEFS_H
25 
26 #include <stdint.h>
27 
28 /* Define the message header size for all UCI Commands and Notifications */
29 #define UCI_MSG_HDR_SIZE 4 /* per UCI spec */
30 #define UCI_RESPONSE_STATUS_OFFSET 4
31 #define UCI_CMD_SESSION_ID_OFFSET 4
32 #define UCI_RESPONSE_PAYLOAD_OFFSET 5
33 
34 /* UCI Command and Notification Format:
35  * 4 byte message header:
36  * byte 0: MT PBF GID
37  * byte 1: OID
38  * byte 2: RFU - To be used for extended playload length
39  * byte 3: Message Length */
40 
41 /* MT: Message Type (byte 0) */
42 #define UCI_MT_MASK 0xE0
43 #define UCI_MT_SHIFT 5
44 #define UCI_MT_DATA 0
45 #define UCI_MT_CMD 1 /* (UCI_MT_CMD << UCI_MT_SHIFT) = 0x20 */
46 #define UCI_MT_RSP 2 /* (UCI_MT_RSP << UCI_MT_SHIFT) = 0x40 */
47 #define UCI_MT_NTF 3 /* (UCI_MT_NTF << UCI_MT_SHIFT) = 0x60 */
48 
49 /* PBF: Packet Boundary Flag (byte 0) */
50 #define UCI_PBF_MASK 0x10
51 #define UCI_PBF_SHIFT 4
52 #define UCI_PBF_ST_CONT 0x10    /* start or continuing fragment */
53 
54 /* Ocet 3 = Payload Length(L) */
55 #define UCI_PAYLOAD_LENGTH_OFFSET 3
56 
57 /* GID: Group Identifier (byte 0) */
58 #define UCI_GID_MASK              0x0F
59 #define UCI_GID_CORE              0x00 /* UCI Core group */
60 #define UCI_GID_SESSION_MANAGE    0x01 /* Session Config Group */
61 #define UCI_GID_SESSION_CONTROL   0x02 /* Session Control Group */
62 #define UCI_GID_ANDROID           0x0C /* Android vendor group */
63 #define UCI_GID_PROPRIETARY_0X0A  0x0A /* Proprietary Group */
64 #define UCI_GID_PROPRIETARY       0x0E /* Proprietary Group */
65 #define UCI_GID_PROPRIETARY_0X0F  0x0F /* Proprietary Group */
66 #define UCI_GID_INTERNAL          0x0B /* Internal Group */
67 
68 /* OID: Opcode Identifier (byte 1) */
69 #define UCI_OID_MASK 0x3F
70 #define UCI_OID_SHIFT 0
71 
72 /**********************************************
73  * UCI Core Group-0: Opcodes and size of commands
74  **********************************************/
75 #define UCI_MSG_CORE_DEVICE_STATUS_NTF 1
76 #define UCI_MSG_CORE_DEVICE_INFO 2
77 #define UCI_MSG_CORE_GET_CAPS_INFO 3
78 #define UCI_MSG_CORE_GET_CAPS_INFO_NR_OFFSET  5
79 #define UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET 6
80 
81 #define UCI_MSG_CORE_SET_CONFIG 4
82 #define UCI_MSG_CORE_GENERIC_ERROR_NTF 7
83 
84 /*********************************************************
85  * UCI session config Group-1: Opcodes and size of command
86  ********************************************************/
87 #define UCI_MSG_SESSION_STATUS_NTF 2
88 #define UCI_MSG_SESSION_STATUS_NTF_HANDLE_OFFSET      4
89 #define UCI_MSG_SESSION_STATUS_NTF_STATE_OFFSET       8
90 #define UCI_MSG_SESSION_STATUS_NTF_REASON_OFFSET      9
91 #define UCI_MSG_SESSION_STATUS_NTF_LENGTH             10
92 
93 #define UCI_MSG_SESSION_STATE_INIT                    (0x00)
94 #define UCI_MSG_SESSION_STATE_INIT_CMD_LEN            (9)
95 #define UCI_MSG_SESSION_STATE_INIT_CMD_ID_OFFSET      (4)
96 #define UCI_MSG_SESSION_STATE_INIT_CMD_TYPE_OFFSET    (8)
97 #define UCI_MSG_SESSION_STATE_INIT_RSP_LEN            (9)
98 #define UCI_MSG_SESSION_STATE_INIT_RSP_STATUS_OFFSET  (4)
99 #define UCI_MSG_SESSION_STATE_INIT_RSP_HANDLE_OFFSET  (5)
100 #define UCI_MSG_SESSION_STATE_DEINIT                  (0x01)
101 #define UCI_MSG_SESSION_STATE_ACTIVE                  (0x02)
102 #define UCI_MSG_SESSION_STATE_IDLE                    (0x03)
103 #define UCI_MSG_SESSION_STATE_UNDEFINED               (0xFF)  // SW defined
104 
105 #define UCI_MSG_SESSION_SET_APP_CONFIG                3
106 #define UCI_MSG_SESSION_SET_APP_CONFIG_HANDLE_OFFSET  4
107 #define UCI_MSG_SESSION_GET_APP_CONFIG                4
108 
109 // Parameter Tags
110 #define UCI_APP_CONFIG_FIRA_STS_INDEX                 0x0A
111 #define UCI_APP_CONFIG_CCC_LAST_STS_INDEX_USED        0xA8
112 
113 #define UCI_MSG_SESSION_QUERY_DATA_SIZE               0x0B
114 #define UCI_MSG_SESSION_QUERY_DATA_SIZE_STATUS_OFFSET 8
115 
116 // Session Type field in SESSION_INIT_CMD
117 constexpr uint8_t kSessionType_Ranging = 0x00;
118 constexpr uint8_t kSessionType_RangingAndData = 0x01;
119 constexpr uint8_t kSessionType_CCCRanging = 0xA0;
120 constexpr uint8_t kSessionType_AliroRanging = 0xA2;
121 
122 /*********************************************************
123  * UCI session config Group-2: Opcodes and size of command
124  ********************************************************/
125 #define UCI_MSG_SESSION_START                         0x00
126 #define UCI_MSG_SESSION_START_CMD_LENGTH              (8)
127 #define UCI_MSG_SESSION_START_HANDLE_OFFSET           (4)
128 
129 #define UCI_MSG_SESSION_STOP                          0x01
130 
131 /**********************************************************
132  * UCI Android Vendor Group-C: Opcodes and size of commands
133  **********************************************************/
134 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE 0x01
135 
136 /**********************************************
137  * UWB Prop Group Opcode-E Opcodes
138  **********************************************/
139 #define UCI_MSG_BINDING_STATUS_NTF 0x06
140 
141 /**********************************************************
142  * OTP Calibration
143  **********************************************************/
144 #define UCI_MSG_WRITE_CALIB_DATA  0x00
145 #define UCI_MSG_READ_CALIB_DATA   0x01
146 
147 #define OTP_ID_XTAL_CAP_GM_CTRL   0x02
148 
149 /**********************************************
150  * UWB Prop Group Opcode-F Opcodes
151  **********************************************/
152 #define UCI_MSG_URSK_DELETE               0x01
153 #define UCI_MSG_SET_DEVICE_CALIBRATION    0x21
154 #define UCI_MSG_GET_DEVICE_CALIBRATION    0x22
155 #define UCI_MSG_UWB_ESE_BINDING           0x31
156 #define UCI_MSG_UWB_ESE_BINDING_CHECK     0x32
157 
158 /**********************************************
159  * UCI Parameter IDs : Device Configurations
160  **********************************************/
161 #define UCI_PARAM_ID_LOW_POWER_MODE 0x01
162 
163 /*************************************************
164  * UCI Parameter IDs : Application Configurations
165  ************************************************/
166 #define UCI_PARAM_ID_CHANNEL_NUMBER 0x04
167 #define UCI_PARAM_ID_TX_ADAPTIVE_PAYLOAD_POWER  0x1C  /* 2.0.0-0.9r4 CR-1038 removed this */
168 #define UCI_PARAM_ID_AOA_AZIMUTH_MEASUREMENTS 0xE3
169 #define UCI_PARAM_ID_AOA_ELEVATION_MEASUREMENTS 0xE4
170 #define UCI_PARAM_ID_RANGE_MEASUREMENTS 0xE5
171 
172 /*************************************************
173  * Device Calibration Parameters IDs
174  ************************************************/
175 // XXX: Should this be chip-dependant?
176 #define NXP_PARAM_ID_TX_POWER_PER_ANTENNA       0x04
177 
178 /*************************************************
179  * Status codes
180  ************************************************/
181 /* Generic Status Codes */
182 #define UCI_STATUS_OK 0x00
183 #define UCI_STATUS_FAILED 0x02
184 #define UCI_STATUS_SYNTAX_ERROR 0x03
185 #define UCI_STATUS_INVALID_PARAM 0x04
186 #define UCI_STATUS_COMMAND_RETRY 0x0A
187 #define UCI_STATUS_UNKNOWN 0x0B
188 #define UCI_STATUS_THERMAL_RUNAWAY 0x54
189 #define UCI_STATUS_BUFFER_UNDERFLOW 0x58
190 #define UCI_STATUS_LOW_VBAT 0x59
191 #define UCI_STATUS_HW_RESET 0xFE
192 #define UWBS_STATUS_ERROR 0xFF /* error occurred in UWBS*/
193 
194 /* Status code for feature not supported */
195 #define UCI_STATUS_FEATURE_NOT_SUPPORTED 0x55
196 
197 #define UCI_STATUS_COUNTRY_CODE_BLOCKED_CHANNEL 0x56
198 #define UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF 0x53
199 
200 #endif /* UWB_UCI_DEFS_H */
201