1 /*
2  * Copyright 2018-2024 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 /**********************************************
72  * UCI Core Group-0: Opcodes and size of commands
73  **********************************************/
74 #define UCI_MSG_CORE_DEVICE_STATUS_NTF 1
75 #define UCI_MSG_CORE_DEVICE_INFO 2
76 #define UCI_MSG_CORE_GET_CAPS_INFO 3
77 #define UCI_MSG_CORE_GET_CAPS_INFO_NR_OFFSET  5
78 #define UCI_MSG_CORE_GET_CAPS_INFO_TLV_OFFSET 6
79 
80 #define UCI_MSG_CORE_SET_CONFIG 4
81 #define UCI_MSG_CORE_GENERIC_ERROR_NTF 7
82 
83 /*********************************************************
84  * UCI session config Group-1: Opcodes and size of command
85  ********************************************************/
86 #define UCI_MSG_SESSION_STATUS_NTF 2
87 #define UCI_MSG_SESSION_STATUS_NTF_HANDLE_OFFSET      4
88 #define UCI_MSG_SESSION_STATUS_NTF_STATE_OFFSET       8
89 #define UCI_MSG_SESSION_STATUS_NTF_REASON_OFFSET      9
90 #define UCI_MSG_SESSION_STATUS_NTF_LENGTH             10
91 
92 #define UCI_MSG_SESSION_STATE_INIT                    (0x00)
93 #define UCI_MSG_SESSION_STATE_INIT_CMD_LEN            (9)
94 #define UCI_MSG_SESSION_STATE_INIT_CMD_ID_OFFSET      (4)
95 #define UCI_MSG_SESSION_STATE_INIT_CMD_TYPE_OFFSET    (8)
96 #define UCI_MSG_SESSION_STATE_INIT_RSP_LEN            (9)
97 #define UCI_MSG_SESSION_STATE_INIT_RSP_STATUS_OFFSET  (4)
98 #define UCI_MSG_SESSION_STATE_INIT_RSP_HANDLE_OFFSET  (5)
99 #define UCI_MSG_SESSION_STATE_DEINIT                  (0x01)
100 #define UCI_MSG_SESSION_STATE_ACTIVE                  (0x02)
101 #define UCI_MSG_SESSION_STATE_IDLE                    (0x03)
102 #define UCI_MSG_SESSION_STATE_UNDEFINED               (0xFF)  // SW defined
103 
104 #define UCI_MSG_SESSION_SET_APP_CONFIG                3
105 #define UCI_MSG_SESSION_SET_APP_CONFIG_HANDLE_OFFSET  4
106 #define UCI_MSG_SESSION_GET_APP_CONFIG                4
107 
108 // Parameter Tags
109 #define UCI_APP_CONFIG_FIRA_STS_INDEX                 0x0A
110 #define UCI_APP_CONFIG_CCC_LAST_STS_INDEX_USED        0xA8
111 
112 #define UCI_MSG_SESSION_QUERY_DATA_SIZE               0x0B
113 #define UCI_MSG_SESSION_QUERY_DATA_SIZE_STATUS_OFFSET 8
114 
115 // Session Type field in SESSION_INIT_CMD
116 constexpr uint8_t kSessionType_Ranging = 0x00;
117 constexpr uint8_t kSessionType_RangingAndData = 0x01;
118 constexpr uint8_t kSessionType_CCCRanging = 0xA0;
119 
120 /*********************************************************
121  * UCI session config Group-2: Opcodes and size of command
122  ********************************************************/
123 #define UCI_MSG_SESSION_START                         0x00
124 #define UCI_MSG_SESSION_START_CMD_LENGTH              (8)
125 #define UCI_MSG_SESSION_START_HANDLE_OFFSET           (4)
126 
127 #define UCI_MSG_SESSION_STOP                          0x01
128 
129 /**********************************************************
130  * UCI Android Vendor Group-C: Opcodes and size of commands
131  **********************************************************/
132 #define UCI_MSG_ANDROID_SET_COUNTRY_CODE 0x01
133 
134 /**********************************************
135  * UWB Prop Group Opcode-E Opcodes
136  **********************************************/
137 #define UCI_MSG_BINDING_STATUS_NTF 0x06
138 
139 /**********************************************************
140  * OTP Calibration
141  **********************************************************/
142 #define UCI_MSG_WRITE_CALIB_DATA  0x00
143 #define UCI_MSG_READ_CALIB_DATA   0x01
144 
145 #define OTP_ID_XTAL_CAP_GM_CTRL   0x02
146 
147 /**********************************************
148  * UWB Prop Group Opcode-F Opcodes
149  **********************************************/
150 #define UCI_MSG_URSK_DELETE               0x01
151 #define UCI_MSG_SET_DEVICE_CALIBRATION    0x21
152 #define UCI_MSG_GET_DEVICE_CALIBRATION    0x22
153 #define UCI_MSG_UWB_ESE_BINDING           0x31
154 #define UCI_MSG_UWB_ESE_BINDING_CHECK     0x32
155 
156 /**********************************************
157  * UCI Parameter IDs : Device Configurations
158  **********************************************/
159 #define UCI_PARAM_ID_LOW_POWER_MODE 0x01
160 
161 /*************************************************
162  * UCI Parameter IDs : Application Configurations
163  ************************************************/
164 #define UCI_PARAM_ID_CHANNEL_NUMBER 0x04
165 #define UCI_PARAM_ID_TX_ADAPTIVE_PAYLOAD_POWER  0x1C  /* 2.0.0-0.9r4 CR-1038 removed this */
166 #define UCI_PARAM_ID_AOA_AZIMUTH_MEASUREMENTS 0xE3
167 #define UCI_PARAM_ID_AOA_ELEVATION_MEASUREMENTS 0xE4
168 #define UCI_PARAM_ID_RANGE_MEASUREMENTS 0xE5
169 
170 /*************************************************
171  * Device Calibration Parameters IDs
172  ************************************************/
173 // XXX: Should this be chip-dependant?
174 #define NXP_PARAM_ID_TX_POWER_PER_ANTENNA       0x04
175 
176 /*************************************************
177  * Status codes
178  ************************************************/
179 /* Generic Status Codes */
180 #define UCI_STATUS_OK 0x00
181 #define UCI_STATUS_FAILED 0x02
182 #define UCI_STATUS_SYNTAX_ERROR 0x03
183 #define UCI_STATUS_INVALID_PARAM 0x04
184 #define UCI_STATUS_COMMAND_RETRY 0x0A
185 #define UCI_STATUS_UNKNOWN 0x0B
186 #define UCI_STATUS_THERMAL_RUNAWAY 0x54
187 #define UCI_STATUS_BUFFER_UNDERFLOW 0x58
188 #define UCI_STATUS_LOW_VBAT 0x59
189 #define UCI_STATUS_HW_RESET 0xFE
190 
191 /* Status code for feature not supported */
192 #define UCI_STATUS_FEATURE_NOT_SUPPORTED 0x55
193 
194 #define UCI_STATUS_COUNTRY_CODE_BLOCKED_CHANNEL 0x56
195 #define UCI_STATUS_CODE_ANDROID_REGULATION_UWB_OFF 0x53
196 
197 #endif /* UWB_UCI_DEFS_H */
198