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 function of the UWB unit to receive/process UCI
22 * commands.
23 *
24 ******************************************************************************/
25
26 #include "uci_defs.h"
27 #include "uci_hmsgs.h"
28 #include "uci_log.h"
29 #include "uci_test_defs.h"
30 #include "uwa_sys.h"
31 #include "uwb_api.h"
32 #include "uwb_gki.h"
33 #include "uwb_hal_int.h"
34 #include "uwb_int.h"
35 #include "uwb_osal_common.h"
36 #include "uwb_target.h"
37
38 /*******************************************************************************
39 **
40 ** Function uwb_proc_core_rsp
41 **
42 ** Description Process UCI responses in the CORE group
43 **
44 ** Returns true-caller of this function to free the GKI buffer p_msg
45 **
46 *******************************************************************************/
uwb_proc_core_rsp(uint8_t op_code,uint8_t * p_buf,uint16_t len)47 bool uwb_proc_core_rsp(uint8_t op_code, uint8_t* p_buf, uint16_t len) {
48 bool free = true;
49
50 /* process the message based on the opcode and message type */
51 switch (op_code) {
52 case UCI_MSG_CORE_DEVICE_RESET:
53 uwb_ucif_proc_core_device_reset_rsp_status(p_buf, len);
54 break;
55 case UCI_MSG_CORE_DEVICE_INFO:
56 uwb_ucif_proc_get_device_info_rsp(p_buf, len);
57 break;
58 case UCI_MSG_CORE_GET_CAPS_INFO:
59 uwb_ucif_proc_get_device_capability_rsp(p_buf, len);
60 break;
61 case UCI_MSG_CORE_GET_CONFIG:
62 uwb_ucif_proc_core_get_config_rsp(p_buf, len);
63 break;
64 case UCI_MSG_CORE_SET_CONFIG:
65 uwb_ucif_proc_core_set_config_status(p_buf, len);
66 break;
67 default:
68 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
69 break;
70 }
71
72 return free;
73 }
74 /*******************************************************************************
75 **
76 ** Function uci_proc_core_management_ntf
77 **
78 ** Description Process UCI notifications in the core Management group
79 **
80 ** Returns void
81 **
82 *******************************************************************************/
uci_proc_core_management_ntf(uint8_t op_code,uint8_t * p_buf,uint16_t len)83 void uci_proc_core_management_ntf(uint8_t op_code, uint8_t* p_buf,
84 uint16_t len) {
85 switch (op_code) {
86 case UCI_MSG_CORE_GENERIC_ERROR_NTF:
87 uwb_ucif_proc_core_generic_error_ntf(p_buf, len);
88 break;
89 case UCI_MSG_CORE_DEVICE_STATUS_NTF:
90 uwb_ucif_proc_core_device_status(p_buf, len);
91 break;
92 default:
93 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
94 break;
95 }
96 }
97
98 /*******************************************************************************
99 **
100 ** Function uci_proc_session_management_rsp
101 **
102 ** Description Process UCI responses in the Session Management group
103 **
104 ** Returns void
105 **
106 *******************************************************************************/
uci_proc_session_management_rsp(uint8_t op_code,uint8_t * p_buf,uint16_t len)107 void uci_proc_session_management_rsp(uint8_t op_code, uint8_t* p_buf,
108 uint16_t len) {
109 switch (op_code) {
110 case UCI_MSG_SESSION_INIT:
111 uwb_ucif_session_management_status(UWB_SESSION_INIT_REVT, p_buf, len);
112 break;
113 case UCI_MSG_SESSION_DEINIT:
114 uwb_ucif_session_management_status(UWB_SESSION_DEINIT_REVT, p_buf, len);
115 break;
116 case UCI_MSG_SESSION_GET_APP_CONFIG:
117 uwb_ucif_proc_app_get_config_status(p_buf, len);
118 break;
119 case UCI_MSG_SESSION_SET_APP_CONFIG:
120 uwb_ucif_proc_app_set_config_status(p_buf, len);
121 break;
122 case UCI_MSG_SESSION_GET_COUNT:
123 uwb_ucif_session_management_status(UWB_SESSION_GET_COUNT_REVT, p_buf,
124 len);
125 break;
126 case UCI_MSG_SESSION_GET_STATE:
127 uwb_ucif_session_management_status(UWB_SESSION_GET_STATE_REVT, p_buf,
128 len);
129 break;
130 case UCI_MSG_SESSION_UPDATE_CONTROLLER_MULTICAST_LIST:
131 uwb_ucif_session_management_status(UWB_SESSION_UPDATE_MULTICAST_LIST_REVT,
132 p_buf, len);
133 break;
134 default:
135 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
136 break;
137 }
138 }
139
140 /*******************************************************************************
141 **
142 ** Function uci_proc_test_management_rsp
143 **
144 ** Description Process UCI responses in the Test Management group
145 **
146 ** Returns void
147 **
148 *******************************************************************************/
uci_proc_test_management_rsp(uint8_t op_code,uint8_t * p_buf,uint16_t len)149 void uci_proc_test_management_rsp(uint8_t op_code, uint8_t* p_buf,
150 uint16_t len) {
151 switch (op_code) {
152 case UCI_MSG_TEST_GET_CONFIG:
153 uwb_ucif_proc_test_get_config_status(p_buf, len);
154 break;
155 case UCI_MSG_TEST_SET_CONFIG:
156 uwb_ucif_proc_test_set_config_status(p_buf, len);
157 break;
158 case UCI_MSG_TEST_PERIODIC_TX:
159 uwb_ucif_test_management_status(UWB_TEST_PERIODIC_TX_REVT, p_buf, len);
160 break;
161 case UCI_MSG_TEST_PER_RX:
162 uwb_ucif_test_management_status(UWB_TEST_PER_RX_REVT, p_buf, len);
163 break;
164 case UCI_MSG_TEST_LOOPBACK:
165 uwb_ucif_test_management_status(UWB_TEST_LOOPBACK_REVT, p_buf, len);
166 break;
167 case UCI_MSG_TEST_RX:
168 uwb_ucif_test_management_status(UWB_TEST_RX_REVT, p_buf, len);
169 break;
170 case UCI_MSG_TEST_STOP_SESSION:
171 uwb_ucif_test_management_status(UWB_TEST_STOP_SESSION_REVT, p_buf, len);
172 break;
173 default:
174 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
175 break;
176 }
177 }
178
179 /*******************************************************************************
180 **
181 ** Function uci_proc_session_management_ntf
182 **
183 ** Description Process UCI notifications in the Session Management group
184 **
185 ** Returns void
186 **
187 *******************************************************************************/
uci_proc_session_management_ntf(uint8_t op_code,uint8_t * p_buf,uint16_t len)188 void uci_proc_session_management_ntf(uint8_t op_code, uint8_t* p_buf,
189 uint16_t len) {
190 switch (op_code) {
191 case UCI_MSG_SESSION_STATUS_NTF:
192 uwb_ucif_proc_session_status(p_buf, len);
193 break;
194 case UCI_MSG_SESSION_UPDATE_CONTROLLER_MULTICAST_LIST:
195 uwb_ucif_proc_multicast_list_update_ntf(p_buf, len);
196 break;
197 default:
198 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
199 break;
200 }
201 }
202
203 /*******************************************************************************
204 **
205 ** Function uci_proc_rang_management_rsp
206 **
207 ** Description Process UCI responses in the Ranging Management group
208 **
209 ** Returns void
210 **
211 *******************************************************************************/
uci_proc_rang_management_rsp(uint8_t op_code,uint8_t * p_buf,uint16_t len)212 void uci_proc_rang_management_rsp(uint8_t op_code, uint8_t* p_buf,
213 uint16_t len) {
214 switch (op_code) {
215 case UCI_MSG_RANGE_START:
216 uwb_ucif_range_management_status(UWB_START_RANGE_REVT, p_buf, len);
217 break;
218 case UCI_MSG_RANGE_STOP:
219 uwb_ucif_range_management_status(UWB_STOP_RANGE_REVT, p_buf, len);
220 break;
221 case UCI_MSG_RANGE_GET_RANGING_COUNT:
222 uwb_ucif_get_range_count_status(UWB_GET_RANGE_COUNT_REVT, p_buf, len);
223 break;
224 case UCI_MSG_RANGE_BLINK_DATA_TX:
225 uwb_ucif_range_management_status(UWB_BLINK_DATA_TX_REVT, p_buf, len);
226 break;
227 default:
228 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
229 break;
230 }
231 }
232
233 /*******************************************************************************
234 **
235 ** Function uci_proc_rang_management_ntf
236 **
237 ** Description Process UCI notifications in the Ranging Management group
238 **
239 ** Returns void
240 **
241 *******************************************************************************/
uci_proc_rang_management_ntf(uint8_t op_code,uint8_t * p_buf,uint16_t len)242 void uci_proc_rang_management_ntf(uint8_t op_code, uint8_t* p_buf,
243 uint16_t len) {
244 switch (op_code) {
245 case UCI_MSG_RANGE_DATA_NTF:
246 uwb_ucif_proc_ranging_data(p_buf, len);
247 break;
248 case UCI_MSG_RANGE_BLINK_DATA_TX_NTF:
249 uwb_ucif_proc_send_blink_data_ntf(p_buf, len);
250 break;
251 default:
252 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
253 break;
254 }
255 }
256
257 /*******************************************************************************
258 **
259 ** Function uci_proc_android_rsp
260 **
261 ** Description Process UCI responses in the vendor Android group
262 **
263 ** Returns void
264 **
265 *******************************************************************************/
uci_proc_android_rsp(uint8_t op_code,uint8_t * p_buf,uint16_t len)266 void uci_proc_android_rsp(uint8_t op_code, uint8_t* p_buf, uint16_t len) {
267 switch (op_code) {
268 case UCI_MSG_ANDROID_GET_POWER_STATS:
269 break;
270 case UCI_MSG_ANDROID_SET_COUNTRY_CODE:
271 uwb_ucif_proc_android_set_country_code_status(p_buf, len);
272 break;
273 default:
274 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
275 break;
276 }
277 }
278
279 /*******************************************************************************
280 **
281 ** Function uci_proc_proprietary_ntf
282 **
283 ** Description Process UCI notifications in the proprietary Management group
284 **
285 ** Returns void
286 **
287 *******************************************************************************/
uci_proc_vendor_specific_ntf(uint8_t gid,uint8_t * p_buf,uint16_t len)288 void uci_proc_vendor_specific_ntf(uint8_t gid, uint8_t* p_buf, uint16_t len) {
289 tUWB_RESPONSE evt_data;
290 UNUSED(gid);
291 if (len > 0) {
292
293 if (uwb_cb.p_resp_cback == NULL) {
294 UCI_TRACE_E("ext response callback is null");
295 } else {
296 evt_data.sVendor_specific_ntf.len = len;
297 if (evt_data.sVendor_specific_ntf.len > 0) {
298 STREAM_TO_ARRAY(evt_data.sVendor_specific_ntf.data, p_buf,
299 len);
300 }
301 (*uwb_cb.p_resp_cback)(UWB_VENDOR_SPECIFIC_UCI_NTF_EVT, &evt_data);
302 }
303 } else {
304 UCI_TRACE_E("%s: len is zero", __func__);
305 }
306 }
307
308 /*******************************************************************************
309 **
310 ** Function uci_proc_raw_cmd_rsp
311 **
312 ** Description Process RAW CMD responses
313 **
314 ** Returns void
315 **
316 *******************************************************************************/
uci_proc_raw_cmd_rsp(uint8_t * p_buf,uint16_t len)317 void uci_proc_raw_cmd_rsp(uint8_t* p_buf, uint16_t len) {
318 tUWB_RAW_CBACK* p_cback = (tUWB_RAW_CBACK*)uwb_cb.p_raw_cmd_cback;
319
320 UCI_TRACE_I(" uci_proc_raw_cmd_rsp:"); // for debug
321
322 /* If there's a pending/stored command, restore the associated address of the
323 * callback function */
324 if (p_cback == NULL) {
325 UCI_TRACE_E("p_raw_cmd_cback is null");
326 } else {
327 (*p_cback)(0 /*unused in this case*/, len, p_buf);
328 uwb_cb.p_raw_cmd_cback = NULL;
329 }
330 uwb_cb.rawCmdCbflag = false;
331 uwb_ucif_update_cmd_window();
332 }
333
334 /*******************************************************************************
335 **
336 ** Function uci_proc_test_management_ntf
337 **
338 ** Description Process UCI notifications in the Test Management group
339 **
340 ** Returns void
341 **
342 *******************************************************************************/
uci_proc_test_management_ntf(uint8_t op_code,uint8_t * p_buf,uint16_t len)343 void uci_proc_test_management_ntf(uint8_t op_code, uint8_t* p_buf,
344 uint16_t len) {
345 switch (op_code) {
346 case UCI_MSG_TEST_PERIODIC_TX:
347 uwb_ucif_proc_rf_test_data(UWB_TEST_PERIODIC_TX_DATA_REVT, p_buf, len);
348 break;
349 case UCI_MSG_TEST_PER_RX:
350 uwb_ucif_proc_rf_test_data(UWB_TEST_PER_RX_DATA_REVT, p_buf, len);
351 break;
352 case UCI_MSG_TEST_LOOPBACK:
353 uwb_ucif_proc_rf_test_data(UWB_TEST_LOOPBACK_DATA_REVT, p_buf, len);
354 break;
355 case UCI_MSG_TEST_RX:
356 uwb_ucif_proc_rf_test_data(UWB_TEST_RX_DATA_REVT, p_buf, len);
357 break;
358 default:
359 UCI_TRACE_E("%s: unknown opcode:0x%x", __func__, op_code);
360 break;
361 }
362 }
363