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