• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018-2023 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 
33 /* UCI Command and Notification Format:
34  * 4 byte message header:
35  * byte 0: MT PBF GID
36  * byte 1: OID
37  * byte 2: RFU - To be used for extended playload length
38  * byte 3: Message Length */
39 
40 /* MT: Message Type (byte 0) */
41 #define UCI_MT_MASK 0xE0
42 #define UCI_MT_SHIFT 5
43 #define UCI_MT_DATA 0
44 #define UCI_MT_CMD 1 /* (UCI_MT_CMD << UCI_MT_SHIFT) = 0x20 */
45 #define UCI_MT_RSP 2 /* (UCI_MT_RSP << UCI_MT_SHIFT) = 0x40 */
46 #define UCI_MT_NTF 3 /* (UCI_MT_NTF << UCI_MT_SHIFT) = 0x60 */
47 
48 /* PBF: Packet Boundary Flag (byte 0) */
49 #define UCI_PBF_MASK 0x10
50 #define UCI_PBF_SHIFT 4
51 #define UCI_PBF_ST_CONT 0x10    /* start or continuing fragment */
52 
53 /* Ocet 3 = Payload Length(L) */
54 #define UCI_PAYLOAD_LENGTH_OFFSET 3
55 
56 /* GID: Group Identifier (byte 0) */
57 #define UCI_GID_MASK              0x0F
58 #define UCI_GID_CORE              0x00 /* UCI Core group */
59 #define UCI_GID_SESSION_MANAGE    0x01 /* Session Config Group */
60 #define UCI_GID_SESSION_CONTROL   0x02 /* Session Control Group */
61 #define UCI_GID_ANDROID           0x0C /* Android vendor group */
62 #define UCI_GID_PROPRIETARY_0X0A  0x0A /* Proprietary Group */
63 #define UCI_GID_PROPRIETARY       0x0E /* Proprietary Group */
64 #define UCI_GID_PROPRIETARY_0X0F  0x0F /* Proprietary Group */
65 #define UCI_GID_INTERNAL          0x0B /* Internal Group */
66 
67 /* OID: Opcode Identifier (byte 1) */
68 #define UCI_OID_MASK 0x3F
69 #define UCI_OID_SHIFT 0
70 
71 /* builds byte0 of UCI Command and Notification packet */
72 #define UCI_MSG_BLD_HDR0(p, mt, gid) \
73   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | (gid));
74 
75 #define UCI_MSG_PBLD_HDR0(p, mt, pbf, gid) \
76   *(p)++ = (uint8_t)(((mt) << UCI_MT_SHIFT) | ((pbf) << UCI_PBF_SHIFT) | (gid));
77 
78 /* builds byte1 of UCI Command and Notification packet */
79 #define UCI_MSG_BLD_HDR1(p, oid) *(p)++ = (uint8_t)(((oid) << UCI_OID_SHIFT));
80 
81 /* parse byte0 of UCI packet */
82 #define UCI_MSG_PRS_HDR0(p, mt, pbf, gid)     \
83   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT;    \
84   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT; \
85   gid = *(p)++ & UCI_GID_MASK;
86 
87 /* parse MT and PBF bits of UCI packet */
88 #define UCI_MSG_PRS_MT_PBF(p, mt, pbf)     \
89   mt = (*(p)&UCI_MT_MASK) >> UCI_MT_SHIFT; \
90   pbf = (*(p)&UCI_PBF_MASK) >> UCI_PBF_SHIFT;
91 
92 /* parse byte1 of UCI Cmd/Ntf */
93 #define UCI_MSG_PRS_HDR1(p, oid) \
94   oid = (*(p)&UCI_OID_MASK);     \
95   (p)++;
96 
97 #define UINT8_TO_STREAM(p, u8) \
98   { *(p)++ = (uint8_t)(u8); }
99 
100 #define ARRAY_TO_STREAM(p, a, len)                                \
101   {                                                               \
102     int ijk;                                                      \
103     for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
104   }
105 
106 /* Allocate smallest possible buffer (for platforms with limited RAM) */
107 #define UCI_GET_CMD_BUF(paramlen)                                    \
108   ((UWB_HDR*)phUwb_GKI_getbuf((uint16_t)(UWB_HDR_SIZE + UCI_MSG_HDR_SIZE + \
109                                    UCI_MSG_OFFSET_SIZE + (paramlen))))
110 
111 /**********************************************
112  * UCI Core Group-0: Opcodes and size of commands
113  **********************************************/
114 #define UCI_MSG_CORE_DEVICE_STATUS_NTF 1
115 #define UCI_MSG_CORE_DEVICE_INFO 2
116 #define UCI_MSG_CORE_GET_CAPS_INFO 3
117 #define UCI_MSG_CORE_GET_CAPS_INFO_NR_OFFSET  5
118 #define UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET 6
119 
120 #define UCI_MSG_CORE_SET_CONFIG 4
121 #define UCI_MSG_CORE_GENERIC_ERROR_NTF 7
122 
123 /*********************************************************
124  * UCI session config Group-1: Opcodes and size of command
125  ********************************************************/
126 #define UCI_MSG_SESSION_STATUS_NTF 2
127 #define UCI_MSG_SESSION_STATUS_NTF_HANDLE_OFFSET      4
128 #define UCI_MSG_SESSION_STATUS_NTF_STATE_OFFSET       8
129 #define UCI_MSG_SESSION_STATUS_NTF_REASON_OFFSET      9
130 #define UCI_MSG_SESSION_STATUS_NTF_LENGTH             10
131 
132 #define UCI_MSG_SESSION_STATE_INIT                    (0x00)
133 #define UCI_MSG_SESSION_STATE_INIT_CMD_LEN            (9)
134 #define UCI_MSG_SESSION_STATE_INIT_CMD_ID_OFFSET      (4)
135 #define UCI_MSG_SESSION_STATE_INIT_CMD_TYPE_OFFSET    (8)
136 #define UCI_MSG_SESSION_STATE_INIT_RSP_LEN            (9)
137 #define UCI_MSG_SESSION_STATE_INIT_RSP_STATUS_OFFSET  (4)
138 #define UCI_MSG_SESSION_STATE_INIT_RSP_HANDLE_OFFSET  (5)
139 #define UCI_MSG_SESSION_STATE_DEINIT                  (0x01)
140 #define UCI_MSG_SESSION_STATE_ACTIVE                  (0x02)
141 #define UCI_MSG_SESSION_STATE_IDLE                    (0x03)
142 #define UCI_MSG_SESSION_STATE_UNDEFINED               (0xFF)  // SW defined
143 
144 #define UCI_MSG_SESSION_SET_APP_CONFIG                3
145 #define UCI_MSG_SESSION_SET_APP_CONFIG_HANDLE_OFFSET  4
146 #define UCI_MSG_SESSION_GET_APP_CONFIG                4
147 
148 // Parameter Tags
149 #define UCI_APP_CONFIG_FIRA_STS_INDEX                 0x0A
150 #define UCI_APP_CONFIG_CCC_LAST_STS_INDEX_USED        0xA8
151 
152 #define UCI_MSG_SESSION_QUERY_DATA_SIZE               0x0B
153 #define UCI_MSG_SESSION_QUERY_DATA_SIZE_STATUS_OFFSET 8
154 
155 // Session Type field in SESSION_INIT_CMD
156 constexpr uint8_t kSessionType_Ranging = 0x00;
157 constexpr uint8_t kSessionType_RangingAndData = 0x01;
158 constexpr uint8_t kSessionType_CCCRanging = 0xA0;
159 
160 /*********************************************************
161  * UCI session config Group-2: Opcodes and size of command
162  ********************************************************/
163 #define UCI_MSG_SESSION_START                         0x00
164 #define UCI_MSG_SESSION_START_CMD_LENGTH              (8)
165 #define UCI_MSG_SESSION_START_HANDLE_OFFSET           (4)
166 
167 #define UCI_MSG_SESSION_STOP                          0x01
168 
169 /**********************************************************
170  * UCI Android Vendor Group-C: Opcodes and size of commands
171  **********************************************************/
172 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE 0x01
173 
174 /**********************************************
175  * UWB Prop Group Opcode-E Opcodes
176  **********************************************/
177 #define UCI_MSG_BINDING_STATUS_NTF 0x06
178 
179 /**********************************************************
180  * OTP Calibration
181  **********************************************************/
182 #define UCI_MSG_WRITE_CALIB_DATA  0x00
183 #define UCI_MSG_READ_CALIB_DATA   0x01
184 
185 #define OTP_ID_XTAL_CAP_GM_CTRL   0x02
186 
187 /**********************************************
188  * UWB Prop Group Opcode-F Opcodes
189  **********************************************/
190 #define UCI_MSG_URSK_DELETE               0x01
191 #define UCI_MSG_SET_DEVICE_CALIBRATION    0x21
192 #define UCI_MSG_GET_DEVICE_CALIBRATION    0x22
193 #define UCI_MSG_UWB_ESE_BINDING           0x31
194 #define UCI_MSG_UWB_ESE_BINDING_CHECK     0x32
195 
196 /**********************************************
197  * UCI Parameter IDs : Device Configurations
198  **********************************************/
199 #define UCI_PARAM_ID_LOW_POWER_MODE 0x01
200 
201 /*************************************************
202  * UCI Parameter IDs : Application Configurations
203  ************************************************/
204 #define UCI_PARAM_ID_CHANNEL_NUMBER 0x04
205 #define UCI_PARAM_ID_TX_ADAPTIVE_PAYLOAD_POWER  0x1C  /* 2.0.0-0.9r4 CR-1038 removed this */
206 #define UCI_PARAM_ID_AOA_AZIMUTH_MEASUREMENTS 0xE3
207 #define UCI_PARAM_ID_AOA_ELEVATION_MEASUREMENTS 0xE4
208 #define UCI_PARAM_ID_RANGE_MEASUREMENTS 0xE5
209 
210 /*************************************************
211  * Device Calibration Parameters IDs
212  ************************************************/
213 // XXX: Should this be chip-dependant?
214 #define NXP_PARAM_ID_TX_POWER_PER_ANTENNA       0x04
215 
216 /*************************************************
217  * Status codes
218  ************************************************/
219 /* Generic Status Codes */
220 #define UCI_STATUS_OK 0x00
221 #define UCI_STATUS_FAILED 0x02
222 #define UCI_STATUS_INVALID_PARAM 0x04
223 #define UCI_STATUS_COMMAND_RETRY 0x0A
224 #define UCI_STATUS_UNKNOWN 0x0B
225 #define UCI_STATUS_THERMAL_RUNAWAY 0x54
226 #define UCI_STATUS_LOW_VBAT 0x59
227 #define UCI_STATUS_HW_RESET 0xFE
228 
229 /* Status code for feature not supported */
230 #define UCI_STATUS_FEATURE_NOT_SUPPORTED 0x55
231 
232 #define UCI_STATUS_COUNTRY_CODE_BLOCKED_CHANNEL 0x56
233 #define UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF 0x53
234 
235 #endif /* UWB_UCI_DEFS_H */
236