1 /******************************************************************************
2 *
3 * Copyright (C) 2010-2014 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 /******************************************************************************
20 *
21 * This file contains function of the NCI unit to format and send NCI
22 * commands (for DH).
23 *
24 ******************************************************************************/
25 #include "nci_hmsgs.h"
26
27 #include <string.h>
28
29 #include "include/debug_lmrt.h"
30 #include "nci_defs.h"
31 #include "nfc_api.h"
32 #include "nfc_int.h"
33 #include "nfc_target.h"
34
35 /*******************************************************************************
36 **
37 ** Function nci_snd_core_reset
38 **
39 ** Description compose and send CORE RESET command to command queue
40 **
41 ** Returns status
42 **
43 *******************************************************************************/
nci_snd_core_reset(uint8_t reset_type)44 uint8_t nci_snd_core_reset(uint8_t reset_type) {
45 NFC_HDR* p;
46 uint8_t* pp;
47
48 p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_RESET);
49 if (p == nullptr) return (NCI_STATUS_FAILED);
50
51 p->event = BT_EVT_TO_NFC_NCI;
52 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_RESET;
53 p->offset = NCI_MSG_OFFSET_SIZE;
54 p->layer_specific = 0;
55 pp = (uint8_t*)(p + 1) + p->offset;
56
57 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
58 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_RESET);
59 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_RESET);
60 UINT8_TO_STREAM(pp, reset_type);
61
62 nfc_ncif_send_cmd(p);
63 return (NCI_STATUS_OK);
64 }
65
66 /*******************************************************************************
67 **
68 ** Function nci_snd_core_init
69 **
70 ** Description compose and send CORE INIT command to command queue
71 **
72 ** Returns status
73 **
74 *******************************************************************************/
nci_snd_core_init(uint8_t nci_version)75 uint8_t nci_snd_core_init(uint8_t nci_version) {
76 NFC_HDR* p;
77 uint8_t* pp;
78
79 if ((p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_INIT(nci_version))) == nullptr)
80 return (NCI_STATUS_FAILED);
81
82 p->event = BT_EVT_TO_NFC_NCI;
83 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_INIT(nci_version);
84 p->offset = NCI_MSG_OFFSET_SIZE;
85 p->layer_specific = 0;
86 pp = (uint8_t*)(p + 1) + p->offset;
87
88 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
89 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_INIT);
90 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_INIT(nci_version));
91 if (nfc_cb.nci_version == NCI_VERSION_2_0) {
92 UINT8_TO_STREAM(pp, NCI2_0_CORE_INIT_CMD_BYTE_0);
93 UINT8_TO_STREAM(pp, NCI2_0_CORE_INIT_CMD_BYTE_1);
94 }
95
96 nfc_ncif_send_cmd(p);
97 return (NCI_STATUS_OK);
98 }
99
100 /*******************************************************************************
101 **
102 ** Function nci_snd_core_get_config
103 **
104 ** Description compose and send CORE GET_CONFIG command to command queue
105 **
106 ** Returns status
107 **
108 *******************************************************************************/
nci_snd_core_get_config(uint8_t * param_ids,uint8_t num_ids)109 uint8_t nci_snd_core_get_config(uint8_t* param_ids, uint8_t num_ids) {
110 NFC_HDR* p;
111 uint8_t* pp;
112
113 p = NCI_GET_CMD_BUF(num_ids);
114 if (p == nullptr) return (NCI_STATUS_FAILED);
115
116 p->event = BT_EVT_TO_NFC_NCI;
117 p->len = NCI_MSG_HDR_SIZE + num_ids + 1;
118 p->offset = NCI_MSG_OFFSET_SIZE;
119 p->layer_specific = 0;
120 pp = (uint8_t*)(p + 1) + p->offset;
121
122 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
123 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_GET_CONFIG);
124 UINT8_TO_STREAM(pp, (uint8_t)(num_ids + 1));
125 UINT8_TO_STREAM(pp, num_ids);
126 ARRAY_TO_STREAM(pp, param_ids, num_ids);
127
128 nfc_ncif_send_cmd(p);
129 return (NCI_STATUS_OK);
130 }
131
132 /*******************************************************************************
133 **
134 ** Function nci_snd_core_set_config
135 **
136 ** Description compose and send CORE SET_CONFIG command to command queue
137 **
138 ** Returns status
139 **
140 *******************************************************************************/
nci_snd_core_set_config(uint8_t * p_param_tlvs,uint8_t tlv_size)141 uint8_t nci_snd_core_set_config(uint8_t* p_param_tlvs, uint8_t tlv_size) {
142 NFC_HDR* p;
143 uint8_t* pp;
144 uint8_t num = 0, ulen, len, *pt;
145
146 p = NCI_GET_CMD_BUF(tlv_size + 1);
147 if (p == nullptr) return (NCI_STATUS_FAILED);
148
149 p->event = BT_EVT_TO_NFC_NCI;
150 p->len = NCI_MSG_HDR_SIZE + tlv_size + 1;
151 p->offset = NCI_MSG_OFFSET_SIZE;
152 pp = (uint8_t*)(p + 1) + p->offset;
153
154 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
155 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_SET_CONFIG);
156 UINT8_TO_STREAM(pp, (uint8_t)(tlv_size + 1));
157 len = tlv_size;
158 pt = p_param_tlvs;
159 while (len > 1) {
160 len -= 2;
161 pt++;
162 num++;
163 ulen = *pt++;
164 pt += ulen;
165 if (len >= ulen) {
166 len -= ulen;
167 } else {
168 GKI_freebuf(p);
169 return NCI_STATUS_FAILED;
170 }
171 }
172
173 UINT8_TO_STREAM(pp, num);
174 ARRAY_TO_STREAM(pp, p_param_tlvs, tlv_size);
175 nfc_ncif_send_cmd(p);
176
177 return (NCI_STATUS_OK);
178 }
179
180 /*******************************************************************************
181 **
182 ** Function nci_snd_core_conn_create
183 **
184 ** Description compose and send CORE CONN_CREATE command to command queue
185 **
186 ** Returns status
187 **
188 *******************************************************************************/
nci_snd_core_conn_create(uint8_t dest_type,uint8_t num_tlv,uint8_t tlv_size,uint8_t * p_param_tlvs)189 uint8_t nci_snd_core_conn_create(uint8_t dest_type, uint8_t num_tlv,
190 uint8_t tlv_size, uint8_t* p_param_tlvs) {
191 NFC_HDR* p;
192 uint8_t* pp;
193 uint8_t size = NCI_CORE_PARAM_SIZE_CON_CREATE + tlv_size;
194
195 p = NCI_GET_CMD_BUF(size);
196 if (p == nullptr) return (NCI_STATUS_FAILED);
197
198 p->event = BT_EVT_TO_NFC_NCI;
199 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_CON_CREATE;
200 p->offset = NCI_MSG_OFFSET_SIZE;
201 p->layer_specific = 0;
202 pp = (uint8_t*)(p + 1) + p->offset;
203
204 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
205 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_CONN_CREATE);
206 UINT8_TO_STREAM(pp, size);
207 UINT8_TO_STREAM(pp, dest_type);
208 UINT8_TO_STREAM(pp, num_tlv);
209 if (tlv_size) {
210 ARRAY_TO_STREAM(pp, p_param_tlvs, tlv_size);
211 p->len += tlv_size;
212 }
213
214 nfc_ncif_send_cmd(p);
215 return (NCI_STATUS_OK);
216 }
217
218 /*******************************************************************************
219 **
220 ** Function nci_snd_core_conn_close
221 **
222 ** Description compose and send CORE CONN_CLOSE command to command queue
223 **
224 ** Returns status
225 **
226 *******************************************************************************/
nci_snd_core_conn_close(uint8_t conn_id)227 uint8_t nci_snd_core_conn_close(uint8_t conn_id) {
228 NFC_HDR* p;
229 uint8_t* pp;
230
231 p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_CON_CLOSE);
232 if (p == nullptr) return (NCI_STATUS_FAILED);
233
234 p->event = BT_EVT_TO_NFC_NCI;
235 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_CON_CLOSE;
236 p->offset = NCI_MSG_OFFSET_SIZE;
237 p->layer_specific = 0;
238 pp = (uint8_t*)(p + 1) + p->offset;
239
240 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
241 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_CONN_CLOSE);
242 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_CON_CLOSE);
243 UINT8_TO_STREAM(pp, conn_id);
244
245 nfc_ncif_send_cmd(p);
246 return (NCI_STATUS_OK);
247 }
248
249 #if (NFC_NFCEE_INCLUDED == TRUE)
250 #if (NFC_RW_ONLY == FALSE)
251 /*******************************************************************************
252 **
253 ** Function nci_snd_nfcee_discover
254 **
255 ** Description compose and send NFCEE Management NFCEE_DISCOVER command
256 ** to command queue
257 **
258 ** Returns status
259 **
260 *******************************************************************************/
nci_snd_nfcee_discover(uint8_t discover_action)261 uint8_t nci_snd_nfcee_discover(uint8_t discover_action) {
262 NFC_HDR* p;
263 uint8_t* pp;
264
265 p = NCI_GET_CMD_BUF(NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion()));
266 if (p == nullptr) return (NCI_STATUS_FAILED);
267
268 p->event = BT_EVT_TO_NFC_NCI;
269 p->len =
270 NCI_MSG_HDR_SIZE + NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion());
271 p->offset = NCI_MSG_OFFSET_SIZE;
272 p->layer_specific = 0;
273 pp = (uint8_t*)(p + 1) + p->offset;
274
275 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
276 NCI_MSG_BLD_HDR1(pp, NCI_MSG_NFCEE_DISCOVER);
277 UINT8_TO_STREAM(pp, NCI_PARAM_SIZE_DISCOVER_NFCEE(NFC_GetNCIVersion()));
278 if (NFC_GetNCIVersion() != NCI_VERSION_2_0) {
279 UINT8_TO_STREAM(pp, discover_action);
280 }
281 nfc_ncif_send_cmd(p);
282 return (NCI_STATUS_OK);
283 }
284
285 /*******************************************************************************
286 **
287 ** Function nci_snd_nfcee_mode_set
288 **
289 ** Description compose and send NFCEE Management NFCEE MODE SET command
290 ** to command queue
291 **
292 ** Returns status
293 **
294 *******************************************************************************/
nci_snd_nfcee_mode_set(uint8_t nfcee_id,uint8_t nfcee_mode)295 uint8_t nci_snd_nfcee_mode_set(uint8_t nfcee_id, uint8_t nfcee_mode) {
296 NFC_HDR* p;
297 uint8_t* pp;
298
299 p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET);
300 if (p == nullptr) return (NCI_STATUS_FAILED);
301
302 p->event = BT_EVT_TO_NFC_NCI;
303 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET;
304 p->offset = NCI_MSG_OFFSET_SIZE;
305 p->layer_specific = 0;
306 pp = (uint8_t*)(p + 1) + p->offset;
307
308 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
309 NCI_MSG_BLD_HDR1(pp, NCI_MSG_NFCEE_MODE_SET);
310 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_NFCEE_MODE_SET);
311 UINT8_TO_STREAM(pp, nfcee_id);
312 UINT8_TO_STREAM(pp, nfcee_mode);
313
314 nfc_ncif_send_cmd(p);
315 return (NCI_STATUS_OK);
316 }
317
318 /*******************************************************************************
319 **
320 ** Function nci_snd_iso_dep_nak_presence_check_cmd
321 **
322 ** Description compose and send RF Management presence check ISO-DEP NAK
323 ** command.
324 **
325 **
326 ** Returns status
327 **
328 *******************************************************************************/
nci_snd_iso_dep_nak_presence_check_cmd()329 uint8_t nci_snd_iso_dep_nak_presence_check_cmd() {
330 NFC_HDR* p;
331 uint8_t* pp;
332
333 if ((p = NCI_GET_CMD_BUF(0)) == nullptr) return (NCI_STATUS_FAILED);
334
335 p->event = BT_EVT_TO_NFC_NCI;
336 p->offset = NCI_MSG_OFFSET_SIZE;
337 p->len = NCI_MSG_HDR_SIZE + 0;
338 p->layer_specific = 0;
339 pp = (uint8_t*)(p + 1) + p->offset;
340
341 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
342 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_ISO_DEP_NAK_PRESENCE);
343 UINT8_TO_STREAM(pp, 0x00);
344 nfc_ncif_send_cmd(p);
345 return (NCI_STATUS_OK);
346 }
347 #endif
348 #endif
349
350 /*******************************************************************************
351 **
352 ** Function nci_snd_discover_cmd
353 **
354 ** Description compose and send RF Management DISCOVER command to command
355 ** queue
356 **
357 ** Returns status
358 **
359 *******************************************************************************/
nci_snd_discover_cmd(uint8_t num,tNCI_DISCOVER_PARAMS * p_param)360 uint8_t nci_snd_discover_cmd(uint8_t num, tNCI_DISCOVER_PARAMS* p_param) {
361 NFC_HDR* p;
362 uint8_t *pp, *p_size, *p_start;
363 int xx;
364 int size;
365
366 size = num * sizeof(tNCI_DISCOVER_PARAMS) + 1;
367 p = NCI_GET_CMD_BUF(size);
368 if (p == nullptr) return (NCI_STATUS_FAILED);
369
370 p->event = BT_EVT_TO_NFC_NCI;
371 p->offset = NCI_MSG_OFFSET_SIZE;
372 p->layer_specific = 0;
373 pp = (uint8_t*)(p + 1) + p->offset;
374
375 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
376 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_DISCOVER);
377 p_size = pp;
378 pp++;
379 p_start = pp;
380 UINT8_TO_STREAM(pp, num);
381 for (xx = 0; xx < num; xx++) {
382 UINT8_TO_STREAM(pp, p_param[xx].type);
383 UINT8_TO_STREAM(pp, p_param[xx].frequency);
384 }
385 *p_size = (uint8_t)(pp - p_start);
386 p->len = NCI_MSG_HDR_SIZE + *p_size;
387
388 nfc_ncif_send_cmd(p);
389 return (NCI_STATUS_OK);
390 }
391
392 /*******************************************************************************
393 **
394 ** Function nci_snd_discover_select_cmd
395 **
396 ** Description compose and send RF Management DISCOVER SELECT command
397 ** to command queue
398 **
399 ** Returns status
400 **
401 *******************************************************************************/
nci_snd_discover_select_cmd(uint8_t rf_disc_id,uint8_t protocol,uint8_t rf_interface)402 uint8_t nci_snd_discover_select_cmd(uint8_t rf_disc_id, uint8_t protocol,
403 uint8_t rf_interface) {
404 NFC_HDR* p;
405 uint8_t* pp;
406
407 p = NCI_GET_CMD_BUF(NCI_DISCOVER_PARAM_SIZE_SELECT);
408 if (p == nullptr) return (NCI_STATUS_FAILED);
409
410 p->event = BT_EVT_TO_NFC_NCI;
411 p->len = NCI_MSG_HDR_SIZE + NCI_DISCOVER_PARAM_SIZE_SELECT;
412 p->offset = NCI_MSG_OFFSET_SIZE;
413 p->layer_specific = 0;
414 pp = (uint8_t*)(p + 1) + p->offset;
415
416 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
417 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_DISCOVER_SELECT);
418 UINT8_TO_STREAM(pp, NCI_DISCOVER_PARAM_SIZE_SELECT);
419 UINT8_TO_STREAM(pp, rf_disc_id);
420 UINT8_TO_STREAM(pp, protocol);
421 UINT8_TO_STREAM(pp, rf_interface);
422
423 nfc_ncif_send_cmd(p);
424 return (NCI_STATUS_OK);
425 }
426
427 /*******************************************************************************
428 **
429 ** Function nci_snd_deactivate_cmd
430 **
431 ** Description compose and send RF Management DEACTIVATE command
432 ** to command queue
433 **
434 ** Returns status
435 **
436 *******************************************************************************/
nci_snd_deactivate_cmd(uint8_t de_act_type)437 uint8_t nci_snd_deactivate_cmd(uint8_t de_act_type) {
438 NFC_HDR* p;
439 uint8_t* pp;
440
441 nfc_cb.reassembly = true;
442
443 p = NCI_GET_CMD_BUF(NCI_DISCOVER_PARAM_SIZE_DEACT);
444 if (p == nullptr) return (NCI_STATUS_FAILED);
445
446 p->event = BT_EVT_TO_NFC_NCI;
447 p->len = NCI_MSG_HDR_SIZE + NCI_DISCOVER_PARAM_SIZE_DEACT;
448 p->offset = NCI_MSG_OFFSET_SIZE;
449 p->layer_specific = 0;
450 pp = (uint8_t*)(p + 1) + p->offset;
451
452 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
453 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_DEACTIVATE);
454 UINT8_TO_STREAM(pp, NCI_DISCOVER_PARAM_SIZE_DEACT);
455 UINT8_TO_STREAM(pp, de_act_type);
456
457 nfc_ncif_send_cmd(p);
458 return (NCI_STATUS_OK);
459 }
460
461 /*******************************************************************************
462 **
463 ** Function nci_snd_discover_map_cmd
464 **
465 ** Description compose and send RF Management DISCOVER MAP command
466 ** to command queue
467 **
468 ** Returns status
469 **
470 *******************************************************************************/
nci_snd_discover_map_cmd(uint8_t num,tNCI_DISCOVER_MAPS * p_maps)471 uint8_t nci_snd_discover_map_cmd(uint8_t num, tNCI_DISCOVER_MAPS* p_maps) {
472 NFC_HDR* p;
473 uint8_t *pp, *p_size, *p_start;
474 int xx;
475 int size;
476
477 size = num * sizeof(tNCI_DISCOVER_MAPS) + 1;
478
479 p = NCI_GET_CMD_BUF(size);
480 if (p == nullptr) return (NCI_STATUS_FAILED);
481
482 p->event = BT_EVT_TO_NFC_NCI;
483 p->offset = NCI_MSG_OFFSET_SIZE;
484 p->layer_specific = 0;
485 pp = (uint8_t*)(p + 1) + p->offset;
486
487 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
488 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_DISCOVER_MAP);
489 p_size = pp;
490 pp++;
491 p_start = pp;
492 UINT8_TO_STREAM(pp, num);
493 for (xx = 0; xx < num; xx++) {
494 UINT8_TO_STREAM(pp, p_maps[xx].protocol);
495 UINT8_TO_STREAM(pp, p_maps[xx].mode);
496 UINT8_TO_STREAM(pp, p_maps[xx].intf_type);
497 }
498 *p_size = (uint8_t)(pp - p_start);
499 p->len = NCI_MSG_HDR_SIZE + *p_size;
500 nfc_ncif_send_cmd(p);
501 return (NCI_STATUS_OK);
502 }
503 /*******************************************************************************
504 **
505 ** Function nci_snd_t3t_polling
506 **
507 ** Description compose and send RF Management T3T POLLING command
508 ** to command queue
509 **
510 ** Returns status
511 **
512 *******************************************************************************/
nci_snd_t3t_polling(uint16_t system_code,uint8_t rc,uint8_t tsn)513 uint8_t nci_snd_t3t_polling(uint16_t system_code, uint8_t rc, uint8_t tsn) {
514 NFC_HDR* p;
515 uint8_t* pp;
516
517 p = NCI_GET_CMD_BUF(NCI_RF_PARAM_SIZE_T3T_POLLING);
518 if (p == nullptr) return (NCI_STATUS_FAILED);
519
520 p->event = BT_EVT_TO_NFC_NCI;
521 p->len = NCI_MSG_HDR_SIZE + NCI_RF_PARAM_SIZE_T3T_POLLING;
522 p->offset = NCI_MSG_OFFSET_SIZE;
523 p->layer_specific = 0;
524 pp = (uint8_t*)(p + 1) + p->offset;
525
526 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
527 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_T3T_POLLING);
528 UINT8_TO_STREAM(pp, NCI_RF_PARAM_SIZE_T3T_POLLING);
529 UINT16_TO_BE_STREAM(pp, system_code);
530 UINT8_TO_STREAM(pp, rc);
531 UINT8_TO_STREAM(pp, tsn);
532
533 nfc_ncif_send_cmd(p);
534 return (NCI_STATUS_OK);
535 }
536
537 /*******************************************************************************
538 **
539 ** Function nci_snd_parameter_update_cmd
540 **
541 ** Description compose and send RF Management RF Communication Parameter
542 ** Update commandto command queue
543 **
544 ** Returns status
545 **
546 *******************************************************************************/
nci_snd_parameter_update_cmd(uint8_t * p_param_tlvs,uint8_t tlv_size)547 uint8_t nci_snd_parameter_update_cmd(uint8_t* p_param_tlvs, uint8_t tlv_size) {
548 NFC_HDR* p;
549 uint8_t* pp;
550 uint8_t num = 0, ulen, len, *pt;
551
552 p = NCI_GET_CMD_BUF(tlv_size + 1);
553 if (p == nullptr) return (NCI_STATUS_FAILED);
554
555 p->event = BT_EVT_TO_NFC_NCI;
556 p->len = NCI_MSG_HDR_SIZE + tlv_size + 1;
557 p->offset = NCI_MSG_OFFSET_SIZE;
558 pp = (uint8_t*)(p + 1) + p->offset;
559
560 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
561 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_PARAMETER_UPDATE);
562 UINT8_TO_STREAM(pp, (uint8_t)(tlv_size + 1));
563 len = tlv_size;
564 pt = p_param_tlvs;
565 while (len > 1) {
566 len -= 2;
567 pt++;
568 num++;
569 ulen = *pt++;
570 pt += ulen;
571 if (len >= ulen) {
572 len -= ulen;
573 } else {
574 GKI_freebuf(p);
575 return NCI_STATUS_FAILED;
576 }
577 }
578
579 UINT8_TO_STREAM(pp, num);
580 ARRAY_TO_STREAM(pp, p_param_tlvs, tlv_size);
581 nfc_ncif_send_cmd(p);
582
583 return (NCI_STATUS_OK);
584 }
585
586 /*******************************************************************************
587 **
588 ** Function nci_snd_nfcee_power_link_control
589 **
590 ** Description compose and send NFCEE Management NFCEE Power and Link
591 ** Control command to command queue
592 **
593 ** Returns status
594 **
595 *******************************************************************************/
nci_snd_nfcee_power_link_control(uint8_t nfcee_id,uint8_t pl_config)596 uint8_t nci_snd_nfcee_power_link_control(uint8_t nfcee_id, uint8_t pl_config) {
597 uint8_t* pp;
598 NFC_HDR* p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL);
599 if (p == nullptr) return NCI_STATUS_FAILED;
600
601 p->event = NFC_EVT_TO_NFC_NCI;
602 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL;
603 p->offset = NCI_MSG_OFFSET_SIZE;
604 p->layer_specific = 0;
605 pp = (uint8_t*)(p + 1) + p->offset;
606
607 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_EE_MANAGE);
608 NCI_MSG_BLD_HDR1(pp, NCI_MSG_NFCEE_POWER_LINK_CTRL);
609 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_NFCEE_PL_CTRL);
610 UINT8_TO_STREAM(pp, nfcee_id);
611 UINT8_TO_STREAM(pp, pl_config);
612
613 nfc_ncif_send_cmd(p);
614 return NCI_STATUS_OK;
615 }
616
617 #if (NFC_NFCEE_INCLUDED == TRUE)
618 #if (NFC_RW_ONLY == FALSE)
619 /*******************************************************************************
620 **
621 ** Function nci_snd_set_routing_cmd
622 **
623 ** Description compose and send RF Management SET_LISTEN_MODE_ROUTING
624 ** command to command queue
625 **
626 ** Returns status
627 **
628 *******************************************************************************/
nci_snd_set_routing_cmd(bool more,uint8_t num_tlv,uint8_t tlv_size,uint8_t * p_param_tlvs)629 uint8_t nci_snd_set_routing_cmd(bool more, uint8_t num_tlv, uint8_t tlv_size,
630 uint8_t* p_param_tlvs) {
631 NFC_HDR* p;
632 uint8_t* pp;
633 uint8_t size = tlv_size + 2;
634
635 if (size < tlv_size) {
636 return (NCI_STATUS_FAILED);
637 }
638
639 if (tlv_size == 0) {
640 /* just to terminate routing table
641 * 2 bytes (more=FALSE and num routing entries=0) */
642 size = 2;
643 }
644
645 p = NCI_GET_CMD_BUF(size);
646 if (p == nullptr) return (NCI_STATUS_FAILED);
647
648 p->event = BT_EVT_TO_NFC_NCI;
649 p->offset = NCI_MSG_OFFSET_SIZE;
650 p->len = NCI_MSG_HDR_SIZE + size;
651 p->layer_specific = 0;
652 pp = (uint8_t*)(p + 1) + p->offset;
653
654 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
655 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_SET_ROUTING);
656 UINT8_TO_STREAM(pp, size);
657 UINT8_TO_STREAM(pp, more);
658 if (size == 2) {
659 UINT8_TO_STREAM(pp, 0);
660 } else {
661 UINT8_TO_STREAM(pp, num_tlv);
662 ARRAY_TO_STREAM(pp, p_param_tlvs, tlv_size);
663 }
664
665 uint8_t* lmrt_head_ptr = (uint8_t*)(p + 1) + p->offset;
666 lmrt_capture(lmrt_head_ptr, size + 3);
667
668 nfc_ncif_send_cmd(p);
669
670 return (NCI_STATUS_OK);
671 }
672 /*******************************************************************************
673 **
674 ** Function nci_snd_set_power_sub_state_cmd
675 **
676 ** Description compose and send core CORE_SET_POWER_SUB_STATE command
677 ** to command queue
678 **
679 ** Returns status
680 **
681 *******************************************************************************/
nci_snd_core_set_power_sub_state(uint8_t screen_state)682 uint8_t nci_snd_core_set_power_sub_state(uint8_t screen_state) {
683 NFC_HDR* p = NCI_GET_CMD_BUF(NCI_CORE_PARAM_SIZE_SET_POWER_SUB_STATE);
684 uint8_t* pp;
685
686 if (p == nullptr) return (NCI_STATUS_FAILED);
687
688 p->event = BT_EVT_TO_NFC_NCI;
689 p->offset = NCI_MSG_OFFSET_SIZE;
690 p->len = NCI_MSG_HDR_SIZE + NCI_CORE_PARAM_SIZE_SET_POWER_SUB_STATE;
691 p->layer_specific = 0;
692 pp = (uint8_t*)(p + 1) + p->offset;
693
694 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_CORE);
695 NCI_MSG_BLD_HDR1(pp, NCI_MSG_CORE_SET_POWER_SUB_STATE);
696 UINT8_TO_STREAM(pp, NCI_CORE_PARAM_SIZE_SET_POWER_SUB_STATE);
697 UINT8_TO_STREAM(pp, screen_state);
698
699 nfc_ncif_send_cmd(p);
700
701 return (NCI_STATUS_OK);
702 }
703 /*******************************************************************************
704 **
705 ** Function nci_snd_get_routing_cmd
706 **
707 ** Description compose and send RF Management GET_LISTEN_MODE_ROUTING
708 ** command to command queue
709 **
710 ** Returns status
711 **
712 *******************************************************************************/
nci_snd_get_routing_cmd(void)713 uint8_t nci_snd_get_routing_cmd(void) {
714 NFC_HDR* p;
715 uint8_t* pp;
716 uint8_t param_size = 0;
717
718 p = NCI_GET_CMD_BUF(param_size);
719 if (p == nullptr) return (NCI_STATUS_FAILED);
720
721 p->event = BT_EVT_TO_NFC_NCI;
722 p->len = NCI_MSG_HDR_SIZE + param_size;
723 p->offset = NCI_MSG_OFFSET_SIZE;
724 p->layer_specific = 0;
725 pp = (uint8_t*)(p + 1) + p->offset;
726
727 NCI_MSG_BLD_HDR0(pp, NCI_MT_CMD, NCI_GID_RF_MANAGE);
728 NCI_MSG_BLD_HDR1(pp, NCI_MSG_RF_GET_ROUTING);
729 UINT8_TO_STREAM(pp, param_size);
730
731 nfc_ncif_send_cmd(p);
732 return (NCI_STATUS_OK);
733 }
734 #endif
735 #endif
736