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 UCI unit to format and send UCI
22 * commands(for DH).
23 *
24 ******************************************************************************/
25 #include "uci_hmsgs.h"
26
27 #include "uci_defs.h"
28 #include "uci_log.h"
29 #include "uci_test_defs.h"
30 #include "uwb_api.h"
31 #include "uwb_int.h"
32 #include "uwb_osal_common.h"
33 #include "uwb_target.h"
34
35 /*******************************************************************************
36 **
37 ** Function uci_snd_get_device_info_cmd
38 **
39 ** Description compose and send CORE_GET_DEVICE_INFO_CMD command to command
40 ** queue
41 **
42 ** Returns status
43 **
44 *******************************************************************************/
uci_snd_get_device_info_cmd(void)45 uint8_t uci_snd_get_device_info_cmd(void) {
46 UWB_HDR* p;
47 uint8_t* pp;
48
49 if ((p = UCI_GET_CMD_BUF(UCI_MSG_CORE_DEVICE_INFO_CMD_SIZE)) == NULL)
50 return (UCI_STATUS_FAILED);
51 p->event = BT_EVT_TO_UWB_UCI;
52 p->len = UCI_MSG_HDR_SIZE;
53 p->offset = UCI_MSG_OFFSET_SIZE;
54 pp = (uint8_t*)(p + 1) + p->offset;
55
56 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_CORE);
57 UCI_MSG_BLD_HDR1(pp, UCI_MSG_CORE_DEVICE_INFO);
58 UINT8_TO_STREAM(pp, 0x00);
59 UINT8_TO_STREAM(pp, UCI_MSG_CORE_DEVICE_INFO_CMD_SIZE);
60
61 uwb_ucif_send_cmd(p);
62 return (UCI_STATUS_OK);
63 }
64
65 /*******************************************************************************
66 **
67 ** Function uci_snd_device_reset_cmd
68 **
69 ** Description compose and send CORE_DEVICE_RESET_CMD command to command
70 ** queue
71 **
72 ** Returns status
73 **
74 *******************************************************************************/
uci_snd_device_reset_cmd(uint8_t resetConfig)75 uint8_t uci_snd_device_reset_cmd(uint8_t resetConfig) {
76 UWB_HDR* p;
77 uint8_t* pp;
78 p = UCI_GET_CMD_BUF(UCI_MSG_CORE_DEVICE_RESET_CMD_SIZE);
79 if (p == NULL) return (UCI_STATUS_FAILED);
80
81 p->event = BT_EVT_TO_UWB_UCI;
82 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_CORE_DEVICE_RESET_CMD_SIZE;
83 p->offset = UCI_MSG_OFFSET_SIZE;
84 pp = (uint8_t*)(p + 1) + p->offset;
85
86 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_CORE);
87 UCI_MSG_BLD_HDR1(pp, UCI_MSG_CORE_DEVICE_RESET);
88 UINT8_TO_STREAM(pp, 0x00);
89 UINT8_TO_STREAM(pp, UCI_MSG_CORE_DEVICE_RESET_CMD_SIZE);
90 UINT8_TO_STREAM(pp, resetConfig);
91 uwb_ucif_send_cmd(p);
92
93 return (UCI_STATUS_OK);
94 }
95
96 /*******************************************************************************
97 **
98 ** Function uci_snd_core_set_config_cmd
99 **
100 ** Description compose and send CORE CORE_SET_CONFIG_CMD command to command
101 ** queue
102 **
103 ** Returns status
104 **
105 *******************************************************************************/
uci_snd_core_set_config_cmd(uint8_t * p_param_tlvs,uint8_t tlv_size)106 uint8_t uci_snd_core_set_config_cmd(uint8_t* p_param_tlvs, uint8_t tlv_size) {
107 UWB_HDR* p;
108 uint8_t* pp;
109 uint8_t num = 0, ulen, len, *pt;
110
111 p = UCI_GET_CMD_BUF(tlv_size + 1);
112 if (p == NULL) return (UCI_STATUS_FAILED);
113
114 p->event = BT_EVT_TO_UWB_UCI;
115 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + tlv_size + 1);
116 p->offset = UCI_MSG_OFFSET_SIZE;
117 pp = (uint8_t*)(p + 1) + p->offset;
118
119 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_CORE);
120 UCI_MSG_BLD_HDR1(pp, UCI_MSG_CORE_SET_CONFIG);
121 UINT8_TO_STREAM(pp, 0x00);
122 UINT8_TO_STREAM(pp, (uint8_t)(tlv_size + 1));
123 len = tlv_size;
124 pt = p_param_tlvs;
125 while (len > 1) {
126 len = (uint8_t)(len - 2);
127 pt++;
128 num++;
129 ulen = *pt++;
130 pt += ulen;
131 if (len >= ulen) {
132 len = (uint8_t)(len - ulen);
133 } else {
134 phUwb_GKI_freebuf(p);
135 return UCI_STATUS_FAILED;
136 }
137 }
138
139 UINT8_TO_STREAM(pp, num);
140 ARRAY_TO_STREAM(pp, p_param_tlvs, tlv_size);
141 uwb_ucif_send_cmd(p);
142
143 return (UCI_STATUS_OK);
144 }
145 /*******************************************************************************
146 **
147 ** Function uci_snd_core_get_config_cmd
148 **
149 ** Description compose and send CORE_GET_CONFIG_CMD command to command
150 ** queue
151 **
152 ** Returns status
153 **
154 *******************************************************************************/
uci_snd_core_get_config_cmd(uint8_t * param_ids,uint8_t num_ids)155 uint8_t uci_snd_core_get_config_cmd(uint8_t* param_ids, uint8_t num_ids) {
156 UWB_HDR* p;
157 uint8_t* pp;
158
159 if ((p = UCI_GET_CMD_BUF(num_ids)) == NULL) return (UCI_STATUS_FAILED);
160
161 p->event = BT_EVT_TO_UWB_UCI;
162
163 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + num_ids + 1);
164
165 p->offset = UCI_MSG_OFFSET_SIZE;
166 p->layer_specific = 0;
167 pp = (uint8_t*)(p + 1) + p->offset;
168
169 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_CORE);
170 UCI_MSG_BLD_HDR1(pp, UCI_MSG_CORE_GET_CONFIG);
171 UINT8_TO_STREAM(pp, 0x00);
172
173 UINT8_TO_STREAM(pp, (uint8_t)(num_ids + 1));
174 UINT8_TO_STREAM(pp, num_ids);
175 ARRAY_TO_STREAM(pp, param_ids, num_ids);
176
177 uwb_ucif_send_cmd(p);
178 return (UCI_STATUS_OK);
179 }
180
181 /*******************************************************************************
182 **
183 ** Function uci_snd_session_init_cmd
184 **
185 ** Description compose and send SESSION_INIT_CMD command
186 **
187 ** Returns status
188 **
189 *******************************************************************************/
uci_snd_session_init_cmd(uint32_t session_id,uint8_t sessionType)190 uint8_t uci_snd_session_init_cmd(uint32_t session_id, uint8_t sessionType) {
191 UWB_HDR* p;
192 uint8_t* pp;
193
194 if ((p = UCI_GET_CMD_BUF(UCI_MSG_SESSION_INIT_CMD_SIZE)) == NULL)
195 return (UCI_STATUS_FAILED);
196 p->event = BT_EVT_TO_UWB_UCI;
197 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_SESSION_INIT_CMD_SIZE;
198 p->offset = UCI_MSG_OFFSET_SIZE;
199 pp = (uint8_t*)(p + 1) + p->offset;
200 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
201 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_INIT);
202 UINT8_TO_STREAM(pp, 0x00);
203 UINT8_TO_STREAM(pp, UCI_MSG_SESSION_INIT_CMD_SIZE);
204 UINT32_TO_STREAM(pp, session_id);
205 UINT8_TO_STREAM(pp, sessionType);
206
207 uwb_ucif_send_cmd(p);
208 return (UCI_STATUS_OK);
209 }
210
211 /*******************************************************************************
212 **
213 ** Function uci_snd_session_deinit_cmd
214 **
215 ** Description compose and send SESSION_DEINIT_CMD command
216 **
217 ** Returns status
218 **
219 *******************************************************************************/
uci_snd_session_deinit_cmd(uint32_t session_id)220 uint8_t uci_snd_session_deinit_cmd(uint32_t session_id) {
221 UWB_HDR* p;
222 uint8_t* pp;
223
224 if ((p = UCI_GET_CMD_BUF(UCI_MSG_SESSION_DEINIT_CMD_SIZE)) == NULL)
225 return (UCI_STATUS_FAILED);
226 p->event = BT_EVT_TO_UWB_UCI;
227 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_SESSION_DEINIT_CMD_SIZE;
228 p->offset = UCI_MSG_OFFSET_SIZE;
229 pp = (uint8_t*)(p + 1) + p->offset;
230 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
231 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_DEINIT);
232 UINT8_TO_STREAM(pp, 0x00);
233 UINT8_TO_STREAM(pp, UCI_MSG_SESSION_DEINIT_CMD_SIZE);
234 UINT32_TO_STREAM(pp, session_id);
235
236 uwb_ucif_send_cmd(p);
237 return (UCI_STATUS_OK);
238 }
239
240 /*******************************************************************************
241 **
242 ** Function uci_snd_app_set_config_cmd
243 **
244 ** Description compose and send SESSION_SET_APP_CONFIG_CMD command
245 **
246 ** Returns status
247 **
248 *******************************************************************************/
uci_snd_app_set_config_cmd(uint32_t session_id,uint8_t num_ids,uint8_t length,uint8_t * data)249 uint8_t uci_snd_app_set_config_cmd(uint32_t session_id, uint8_t num_ids,
250 uint8_t length, uint8_t* data) {
251 UWB_HDR* p;
252 uint8_t* pp;
253
254 if ((p = UCI_GET_CMD_BUF(num_ids)) == NULL) return (UCI_STATUS_FAILED);
255
256 p->event = BT_EVT_TO_UWB_UCI;
257
258 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) + sizeof(num_ids) +
259 length);
260
261 p->offset = UCI_MSG_OFFSET_SIZE;
262 p->layer_specific = 0;
263 pp = (uint8_t*)(p + 1) + p->offset;
264
265 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
266 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_SET_APP_CONFIG);
267 UINT8_TO_STREAM(pp, 0x00);
268 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(num_ids) + length);
269
270 UINT32_TO_STREAM(pp, session_id);
271 UINT8_TO_STREAM(pp, num_ids);
272 ARRAY_TO_STREAM(pp, data, length);
273
274 uwb_ucif_send_cmd(p);
275 return (UCI_STATUS_OK);
276 }
277
278 /*******************************************************************************
279 **
280 ** Function uci_snd_app_get_config_cmd
281 **
282 ** Description compose and send SESSION_GET_APP_CONFIG_CMD command
283 **
284 ** Returns status
285 **
286 *******************************************************************************/
uci_snd_app_get_config_cmd(uint32_t session_id,uint8_t num_ids,uint8_t length,uint8_t * param_ids)287 uint8_t uci_snd_app_get_config_cmd(uint32_t session_id, uint8_t num_ids,
288 uint8_t length, uint8_t* param_ids) {
289 UWB_HDR* p;
290 uint8_t* pp;
291
292 if ((p = UCI_GET_CMD_BUF(length)) == NULL) return (UCI_STATUS_FAILED);
293
294 p->event = BT_EVT_TO_UWB_UCI;
295
296 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) + sizeof(num_ids) +
297 length);
298
299 p->offset = UCI_MSG_OFFSET_SIZE;
300 p->layer_specific = 0;
301 pp = (uint8_t*)(p + 1) + p->offset;
302
303 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
304 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_GET_APP_CONFIG);
305 UINT8_TO_STREAM(pp, 0x00);
306 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(num_ids) + length);
307
308 UINT32_TO_STREAM(pp, session_id);
309 UINT8_TO_STREAM(pp, num_ids);
310 ARRAY_TO_STREAM(pp, param_ids, length);
311
312 uwb_ucif_send_cmd(p);
313 return (UCI_STATUS_OK);
314 }
315
316 /*******************************************************************************
317 **
318 ** Function uci_snd_get_session_count_cmd
319 **
320 ** Description compose and send SESSION_GET_COUNT_CMD command
321 **
322 ** Returns status
323 **
324 *******************************************************************************/
uci_snd_get_session_count_cmd(void)325 uint8_t uci_snd_get_session_count_cmd(void) {
326 UWB_HDR* p;
327 uint8_t* pp;
328
329 if ((p = UCI_GET_CMD_BUF(UCI_MSG_SESSION_GET_COUNT_CMD_SIZE)) == NULL)
330 return (UCI_STATUS_FAILED);
331 p->event = BT_EVT_TO_UWB_UCI;
332 p->len = UCI_MSG_HDR_SIZE;
333 p->offset = UCI_MSG_OFFSET_SIZE;
334 pp = (uint8_t*)(p + 1) + p->offset;
335 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
336 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_GET_COUNT);
337 UINT8_TO_STREAM(pp, 0x00);
338 UINT8_TO_STREAM(pp, UCI_MSG_SESSION_GET_COUNT_CMD_SIZE);
339
340 uwb_ucif_send_cmd(p);
341 return (UCI_STATUS_OK);
342 }
343
344 /*******************************************************************************
345 **
346 ** Function uci_snd_get_session_status_cmd
347 **
348 ** Description compose and send SESSION_GET_STATE_CMD command
349 **
350 ** Returns status
351 **
352 *******************************************************************************/
uci_snd_get_session_status_cmd(uint32_t session_id)353 uint8_t uci_snd_get_session_status_cmd(uint32_t session_id) {
354 UWB_HDR* p;
355 uint8_t* pp;
356
357 if ((p = UCI_GET_CMD_BUF(UCI_MSG_SESSION_GET_STATE_SIZE)) == NULL)
358 return (UCI_STATUS_FAILED);
359 p->event = BT_EVT_TO_UWB_UCI;
360 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_SESSION_GET_STATE_SIZE;
361 p->offset = UCI_MSG_OFFSET_SIZE;
362 pp = (uint8_t*)(p + 1) + p->offset;
363 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
364 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_GET_STATE);
365 UINT8_TO_STREAM(pp, 0x00);
366 UINT8_TO_STREAM(pp, UCI_MSG_SESSION_GET_STATE_SIZE);
367 UINT32_TO_STREAM(pp, session_id);
368
369 uwb_ucif_send_cmd(p);
370 return (UCI_STATUS_OK);
371 }
372
373 /*******************************************************************************
374 **
375 ** Function uci_snd_get_range_count_cmd
376 **
377 ** Description compose and send RANGE_GET_RANGING_COUNT_CMD command
378 **
379 ** Returns status
380 **
381 *******************************************************************************/
uci_snd_get_range_count_cmd(uint32_t session_id)382 uint8_t uci_snd_get_range_count_cmd(uint32_t session_id) {
383 UWB_HDR* p;
384 uint8_t* pp;
385
386 if ((p = UCI_GET_CMD_BUF(UCI_MSG_RANGE_GET_COUNT_CMD_SIZE)) == NULL)
387 return (UCI_STATUS_FAILED);
388 p->event = BT_EVT_TO_UWB_UCI;
389 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_RANGE_GET_COUNT_CMD_SIZE;
390 p->offset = UCI_MSG_OFFSET_SIZE;
391 pp = (uint8_t*)(p + 1) + p->offset;
392 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_RANGE_MANAGE);
393 UCI_MSG_BLD_HDR1(pp, UCI_MSG_RANGE_GET_RANGING_COUNT);
394 UINT8_TO_STREAM(pp, 0x00);
395 UINT8_TO_STREAM(pp, UCI_MSG_RANGE_GET_COUNT_CMD_SIZE);
396 UINT32_TO_STREAM(pp, session_id);
397
398 uwb_ucif_send_cmd(p);
399 return (UCI_STATUS_OK);
400 }
401 /*******************************************************************************
402 **
403 ** Function uci_snd_range_start_cmd
404 **
405 ** Description compose and send RANGE_START_CMD command
406 **
407 ** Returns status
408 **
409 *******************************************************************************/
uci_snd_range_start_cmd(uint32_t session_id)410 uint8_t uci_snd_range_start_cmd(uint32_t session_id) {
411 UWB_HDR* p;
412 uint8_t* pp;
413
414 if ((p = UCI_GET_CMD_BUF(UCI_MSG_RANGE_START_CMD_SIZE)) == NULL)
415 return (UCI_STATUS_FAILED);
416 p->event = BT_EVT_TO_UWB_UCI;
417 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_RANGE_START_CMD_SIZE;
418 p->offset = UCI_MSG_OFFSET_SIZE;
419 pp = (uint8_t*)(p + 1) + p->offset;
420 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_RANGE_MANAGE);
421 UCI_MSG_BLD_HDR1(pp, UCI_MSG_RANGE_START);
422 UINT8_TO_STREAM(pp, 0x00);
423 UINT8_TO_STREAM(pp, UCI_MSG_RANGE_START_CMD_SIZE);
424 UINT32_TO_STREAM(pp, session_id);
425
426 uwb_ucif_send_cmd(p);
427 return (UCI_STATUS_OK);
428 }
429
430 /*******************************************************************************
431 **
432 ** Function uci_snd_range_stop_cmd
433 **
434 ** Description compose and send RANGE_STOP_CMD command
435 **
436 ** Returns status
437 **
438 *******************************************************************************/
uci_snd_range_stop_cmd(uint32_t session_id)439 uint8_t uci_snd_range_stop_cmd(uint32_t session_id) {
440 UWB_HDR* p;
441 uint8_t* pp;
442
443 if ((p = UCI_GET_CMD_BUF(UCI_MSG_RANGE_STOP_CMD_SIZE)) == NULL)
444 return (UCI_STATUS_FAILED);
445 p->event = BT_EVT_TO_UWB_UCI;
446 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_RANGE_STOP_CMD_SIZE;
447 p->offset = UCI_MSG_OFFSET_SIZE;
448 pp = (uint8_t*)(p + 1) + p->offset;
449 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_RANGE_MANAGE);
450 UCI_MSG_BLD_HDR1(pp, UCI_MSG_RANGE_STOP);
451 UINT8_TO_STREAM(pp, 0x00);
452 UINT8_TO_STREAM(pp, UCI_MSG_RANGE_STOP_CMD_SIZE);
453 UINT32_TO_STREAM(pp, session_id);
454 uwb_ucif_send_cmd(p);
455 return (UCI_STATUS_OK);
456 }
457
458 /*******************************************************************************
459 **
460 ** Function uci_snd_core_get_device_capability
461 **
462 ** Description compose and send CORE_GET_CAPS_INFO_CMD command
463 **
464 ** Returns status
465 **
466 *******************************************************************************/
uci_snd_core_get_device_capability(void)467 uint8_t uci_snd_core_get_device_capability(void) {
468 UWB_HDR* p;
469 uint8_t* pp;
470 p = UCI_GET_CMD_BUF(UCI_MSG_CORE_GET_CAPS_INFO_CMD_SIZE);
471 if (p == NULL) return (UCI_STATUS_FAILED);
472
473 p->event = BT_EVT_TO_UWB_UCI;
474 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_CORE_GET_CAPS_INFO_CMD_SIZE;
475 p->offset = UCI_MSG_OFFSET_SIZE;
476 pp = (uint8_t*)(p + 1) + p->offset;
477
478 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_CORE);
479 UCI_MSG_BLD_HDR1(pp, UCI_MSG_CORE_GET_CAPS_INFO);
480 UINT8_TO_STREAM(pp, 0x00);
481 UINT8_TO_STREAM(pp, UCI_MSG_CORE_GET_CAPS_INFO_CMD_SIZE);
482 uwb_ucif_send_cmd(p);
483
484 return (UCI_STATUS_OK);
485 }
486
487 /*******************************************************************************
488 **
489 ** Function uci_snd_multicast_list_update_cmd
490 **
491 ** Description compose and send SESSION_UPDATE_CONTROLLER
492 ** _MULTICAST_LIST_CMD command
493 **
494 ** Returns status
495 **
496 *******************************************************************************/
uci_snd_multicast_list_update_cmd(uint32_t session_id,uint8_t action,uint8_t noOfControlees,uint16_t * shortAddressList,uint32_t * subSessionIdList)497 uint8_t uci_snd_multicast_list_update_cmd(uint32_t session_id, uint8_t action,
498 uint8_t noOfControlees,
499 uint16_t* shortAddressList,
500 uint32_t* subSessionIdList) {
501 UWB_HDR* p;
502 uint8_t* pp;
503
504 if ((p = UCI_GET_CMD_BUF(noOfControlees)) == NULL) return (UCI_STATUS_FAILED);
505
506 p->event = BT_EVT_TO_UWB_UCI;
507
508 p->len =
509 (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) + sizeof(action) +
510 sizeof(noOfControlees) + (noOfControlees * SHORT_ADDRESS_LEN) +
511 (noOfControlees * SESSION_ID_LEN));
512
513 p->offset = UCI_MSG_OFFSET_SIZE;
514 p->layer_specific = 0;
515 pp = (uint8_t*)(p + 1) + p->offset;
516
517 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_SESSION_MANAGE);
518 UCI_MSG_BLD_HDR1(pp, UCI_MSG_SESSION_UPDATE_CONTROLLER_MULTICAST_LIST);
519 UINT8_TO_STREAM(pp, 0x00);
520 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(action) +
521 sizeof(noOfControlees) +
522 (noOfControlees * SHORT_ADDRESS_LEN) +
523 (noOfControlees * SESSION_ID_LEN));
524
525 UINT32_TO_STREAM(pp, session_id);
526 UINT8_TO_STREAM(pp, action);
527 UINT8_TO_STREAM(pp, noOfControlees);
528 for (uint8_t i = 0; i < noOfControlees; i++) {
529 UINT16_TO_BE_STREAM(pp, shortAddressList[i]);
530 UINT32_TO_STREAM(pp, subSessionIdList[i]);
531 }
532
533 uwb_ucif_send_cmd(p);
534 return (UCI_STATUS_OK);
535 }
536
537 /*******************************************************************************
538 **
539 ** Function uci_snd_set_country_code_cmd
540 **
541 ** Description compose and send SET_COUNTRY_CODE_CMD command
542 **
543 ** Returns status
544 **
545 *******************************************************************************/
uci_snd_set_country_code_cmd(uint8_t * country_code)546 uint8_t uci_snd_set_country_code_cmd(uint8_t *country_code) {
547 UWB_HDR* p;
548 uint8_t* pp;
549 p = UCI_GET_CMD_BUF(UCI_MSG_ANDROID_SET_COUNTRY_CODE_CMD_SIZE);
550 if (p == NULL) return (UCI_STATUS_FAILED);
551
552 p->event = BT_EVT_TO_UWB_UCI;
553 p->len = UCI_MSG_HDR_SIZE + UCI_MSG_ANDROID_SET_COUNTRY_CODE_CMD_SIZE;
554 p->offset = UCI_MSG_OFFSET_SIZE;
555 pp = (uint8_t*)(p + 1) + p->offset;
556
557 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_ANDROID);
558 UCI_MSG_BLD_HDR1(pp, UCI_MSG_ANDROID_SET_COUNTRY_CODE);
559 UINT8_TO_STREAM(pp, 0x00);
560 UINT8_TO_STREAM(pp, UCI_MSG_ANDROID_SET_COUNTRY_CODE_CMD_SIZE);
561 ARRAY8_TO_STREAM(pp, country_code);
562 uwb_ucif_send_cmd(p);
563
564 return (UCI_STATUS_OK);
565 }
566
567 /*******************************************************************************
568 **
569 ** Function uci_snd_blink_data_cmd
570 **
571 ** Description compose and send BLINK_DATA_TX_CMD command
572 **
573 ** Returns status
574 **
575 *******************************************************************************/
uci_snd_blink_data_cmd(uint32_t session_id,uint8_t repetition_count,uint8_t app_data_len,uint8_t * app_data)576 uint8_t uci_snd_blink_data_cmd(uint32_t session_id, uint8_t repetition_count,
577 uint8_t app_data_len, uint8_t* app_data) {
578 UWB_HDR* p;
579 uint8_t* pp;
580
581 if ((p = UCI_GET_CMD_BUF(sizeof(session_id) + sizeof(repetition_count) +
582 sizeof(app_data_len) + app_data_len)) == NULL)
583 return (UCI_STATUS_FAILED);
584
585 p->event = BT_EVT_TO_UWB_UCI;
586
587 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) +
588 sizeof(repetition_count) + sizeof(app_data_len) +
589 app_data_len);
590
591 p->offset = UCI_MSG_OFFSET_SIZE;
592 p->layer_specific = 0;
593 pp = (uint8_t*)(p + 1) + p->offset;
594
595 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_RANGE_MANAGE);
596 UCI_MSG_BLD_HDR1(pp, UCI_MSG_RANGE_BLINK_DATA_TX);
597 UINT8_TO_STREAM(pp, 0x00);
598 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(repetition_count) +
599 sizeof(app_data_len) + app_data_len);
600
601 UINT32_TO_STREAM(pp, session_id);
602 UINT8_TO_STREAM(pp, repetition_count);
603 UINT8_TO_STREAM(pp, app_data_len);
604 if ((app_data_len > 0) && (app_data != NULL)) {
605 ARRAY_TO_STREAM(pp, app_data, app_data_len);
606 }
607
608 uwb_ucif_send_cmd(p);
609 return (UCI_STATUS_OK);
610 }
611
612 /* APIs for UWB RF test functionality */
613
614 /*******************************************************************************
615 **
616 ** Function uci_snd_test_set_config_cmd
617 **
618 ** Description compose and send TEST_CONFIG_SET_CMD command
619 **
620 ** Returns status
621 **
622 *******************************************************************************/
uci_snd_test_set_config_cmd(uint32_t session_id,uint8_t num_ids,uint8_t length,uint8_t * data)623 uint8_t uci_snd_test_set_config_cmd(uint32_t session_id, uint8_t num_ids,
624 uint8_t length, uint8_t* data) {
625 UWB_HDR* p;
626 uint8_t* pp;
627
628 if ((p = UCI_GET_CMD_BUF(num_ids)) == NULL) return (UCI_STATUS_FAILED);
629
630 p->event = BT_EVT_TO_UWB_UCI;
631
632 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) + sizeof(num_ids) +
633 length);
634
635 p->offset = UCI_MSG_OFFSET_SIZE;
636 p->layer_specific = 0;
637 pp = (uint8_t*)(p + 1) + p->offset;
638
639 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
640 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_SET_CONFIG);
641 UINT8_TO_STREAM(pp, 0x00);
642 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(num_ids) + length);
643
644 UINT32_TO_STREAM(pp, session_id);
645 UINT8_TO_STREAM(pp, num_ids);
646 ARRAY_TO_STREAM(pp, data, length);
647
648 uwb_ucif_send_cmd(p);
649 return (UCI_STATUS_OK);
650 }
651
652 /*******************************************************************************
653 **
654 ** Function uci_snd_test_get_config_cmd
655 **
656 ** Description compose and send TEST_CONFIG_GET_CMD command
657 **
658 ** Returns status
659 **
660 *******************************************************************************/
uci_snd_test_get_config_cmd(uint32_t session_id,uint8_t num_ids,uint8_t length,uint8_t * param_ids)661 uint8_t uci_snd_test_get_config_cmd(uint32_t session_id, uint8_t num_ids,
662 uint8_t length, uint8_t* param_ids) {
663 UWB_HDR* p;
664 uint8_t* pp;
665
666 if ((p = UCI_GET_CMD_BUF(length)) == NULL) return (UCI_STATUS_FAILED);
667
668 p->event = BT_EVT_TO_UWB_UCI;
669
670 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + sizeof(session_id) + sizeof(num_ids) +
671 length);
672
673 p->offset = UCI_MSG_OFFSET_SIZE;
674 p->layer_specific = 0;
675 pp = (uint8_t*)(p + 1) + p->offset;
676
677 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
678 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_GET_CONFIG);
679 UINT8_TO_STREAM(pp, 0x00);
680 UINT8_TO_STREAM(pp, sizeof(session_id) + sizeof(num_ids) + length);
681
682 UINT32_TO_STREAM(pp, session_id);
683 UINT8_TO_STREAM(pp, num_ids);
684 ARRAY_TO_STREAM(pp, param_ids, length);
685
686 uwb_ucif_send_cmd(p);
687 return (UCI_STATUS_OK);
688 }
689
690 /*******************************************************************************
691 **
692 ** Function uci_snd_test_periodic_tx_cmd
693 **
694 ** Description compose and send TEST_PERIODIC_TX_CMD command
695 **
696 ** Returns status
697 **
698 *******************************************************************************/
uci_snd_test_periodic_tx_cmd(uint16_t psduLen,uint8_t * psduData)699 uint8_t uci_snd_test_periodic_tx_cmd(uint16_t psduLen, uint8_t* psduData) {
700 UWB_HDR* p;
701 uint8_t* pp;
702
703 if ((p = UCI_GET_CMD_BUF(psduLen)) == NULL) return (UCI_STATUS_FAILED);
704 p->event = BT_EVT_TO_UWB_UCI;
705 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + psduLen);
706 p->offset = UCI_MSG_OFFSET_SIZE;
707 pp = (uint8_t*)(p + 1) + p->offset;
708 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
709 if (psduLen <= UCI_MAX_PAYLOAD_SIZE) {
710 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_PERIODIC_TX);
711 UINT8_TO_STREAM(pp, 0x00);
712 UINT8_TO_STREAM(pp, psduLen);
713 } else { /* extended len apdu */
714 UCI_MSG_BLD_HDR1(pp, (1 << 7) | UCI_MSG_TEST_PERIODIC_TX);
715 UINT8_TO_STREAM(pp, psduLen & 0x00FF);
716 UINT8_TO_STREAM(pp, (psduLen & 0xFF00) >> 8);
717 }
718 if ((psduLen > 0) && (psduData != NULL)) {
719 ARRAY_TO_STREAM(pp, psduData, psduLen);
720 }
721
722 uwb_ucif_send_cmd(p);
723 return (UCI_STATUS_OK);
724 }
725
726 /*******************************************************************************
727 **
728 ** Function uci_snd_test_per_rx_cmd
729 **
730 ** Description compose and send TEST_PER_RX_CMD command
731 **
732 ** Returns status
733 **
734 *******************************************************************************/
uci_snd_test_per_rx_cmd(uint16_t psduLen,uint8_t * psduData)735 uint8_t uci_snd_test_per_rx_cmd(uint16_t psduLen, uint8_t* psduData) {
736 UWB_HDR* p;
737 uint8_t* pp;
738
739 if ((p = UCI_GET_CMD_BUF(psduLen)) == NULL) return (UCI_STATUS_FAILED);
740 p->event = BT_EVT_TO_UWB_UCI;
741 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + psduLen);
742 p->offset = UCI_MSG_OFFSET_SIZE;
743 pp = (uint8_t*)(p + 1) + p->offset;
744 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
745 if (psduLen <= UCI_MAX_PAYLOAD_SIZE) {
746 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_PER_RX);
747 UINT8_TO_STREAM(pp, 0x00);
748 UINT8_TO_STREAM(pp, psduLen);
749 } else { /* extended len apdu */
750 UCI_MSG_BLD_HDR1(pp, (1 << 7) | UCI_MSG_TEST_PER_RX);
751 UINT8_TO_STREAM(pp, psduLen & 0x00FF);
752 UINT8_TO_STREAM(pp, (psduLen & 0xFF00) >> 8);
753 }
754 if ((psduLen > 0) && (psduData != NULL)) {
755 ARRAY_TO_STREAM(pp, psduData, psduLen);
756 }
757
758 uwb_ucif_send_cmd(p);
759 return (UCI_STATUS_OK);
760 }
761
762 /*******************************************************************************
763 **
764 ** Function uci_snd_test_uwb_loopback_cmd
765 **
766 ** Description compose and send TEST_LOOPBACK_CMD command
767 **
768 ** Returns status
769 **
770 *******************************************************************************/
uci_snd_test_uwb_loopback_cmd(uint16_t psduLen,uint8_t * psduData)771 uint8_t uci_snd_test_uwb_loopback_cmd(uint16_t psduLen, uint8_t* psduData) {
772 UWB_HDR* p;
773 uint8_t* pp;
774
775 if ((p = UCI_GET_CMD_BUF(psduLen)) == NULL) return (UCI_STATUS_FAILED);
776 p->event = BT_EVT_TO_UWB_UCI;
777 p->len = (uint16_t)(UCI_MSG_HDR_SIZE + psduLen);
778 p->offset = UCI_MSG_OFFSET_SIZE;
779 pp = (uint8_t*)(p + 1) + p->offset;
780 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
781 if (psduLen <= UCI_MAX_PAYLOAD_SIZE) {
782 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_LOOPBACK);
783 UINT8_TO_STREAM(pp, 0x00);
784 UINT8_TO_STREAM(pp, psduLen);
785 } else { /* extended len apdu */
786 UCI_MSG_BLD_HDR1(pp, (1 << 7) | UCI_MSG_TEST_LOOPBACK);
787 UINT8_TO_STREAM(pp, psduLen & 0x00FF);
788 UINT8_TO_STREAM(pp, (psduLen & 0xFF00) >> 8);
789 }
790 if ((psduLen > 0) && (psduData != NULL)) {
791 ARRAY_TO_STREAM(pp, psduData, psduLen);
792 }
793
794 uwb_ucif_send_cmd(p);
795 return (UCI_STATUS_OK);
796 }
797
798 /*******************************************************************************
799 **
800 ** Function uci_snd_test_rx_cmd
801 **
802 ** Description compose and send TEST_RX_CMD command
803 **
804 ** Returns status
805 **
806 *******************************************************************************/
uci_snd_test_rx_cmd(void)807 uint8_t uci_snd_test_rx_cmd(void) {
808 UWB_HDR* p;
809 uint8_t* pp;
810
811 if ((p = UCI_GET_CMD_BUF(UCI_MSG_TEST_RX_CMD_SIZE)) == NULL)
812 return (UCI_STATUS_FAILED);
813 p->event = BT_EVT_TO_UWB_UCI;
814 p->len = UCI_MSG_HDR_SIZE;
815 p->offset = UCI_MSG_OFFSET_SIZE;
816 pp = (uint8_t*)(p + 1) + p->offset;
817 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
818 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_RX);
819 UINT8_TO_STREAM(pp, 0x00);
820 UINT8_TO_STREAM(pp, UCI_MSG_TEST_RX_CMD_SIZE);
821
822 uwb_ucif_send_cmd(p);
823 return (UCI_STATUS_OK);
824 }
825
826 /*******************************************************************************
827 **
828 ** Function uci_snd_test_stop_session_cmd
829 **
830 ** Description compose and send TEST_STOP_SESSION_CMD command
831 **
832 ** Returns status
833 **
834 *******************************************************************************/
uci_snd_test_stop_session_cmd(void)835 uint8_t uci_snd_test_stop_session_cmd(void) {
836 UWB_HDR* p;
837 uint8_t* pp;
838
839 if ((p = UCI_GET_CMD_BUF(UCI_MSG_TEST_STOP_SESSION_CMD_SIZE)) == NULL)
840 return (UCI_STATUS_FAILED);
841 p->event = BT_EVT_TO_UWB_UCI;
842 p->len = UCI_MSG_HDR_SIZE;
843 p->offset = UCI_MSG_OFFSET_SIZE;
844 pp = (uint8_t*)(p + 1) + p->offset;
845 UCI_MSG_BLD_HDR0(pp, UCI_MT_CMD, UCI_GID_TEST);
846 UCI_MSG_BLD_HDR1(pp, UCI_MSG_TEST_STOP_SESSION);
847 UINT8_TO_STREAM(pp, 0x00);
848 UINT8_TO_STREAM(pp, UCI_MSG_TEST_STOP_SESSION_CMD_SIZE);
849
850 uwb_ucif_send_cmd(p);
851 return (UCI_STATUS_OK);
852 }
853