1 /* 2 * Copyright (C) 2010 NXP Semiconductors 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 * * 20 * * 21 * \file phHciNfc_NfcIPMgmt.c * 22 * \brief HCI NFCIP-1 management routines. * 23 * * 24 * * 25 * Project: NFC-FRI-1.1 * 26 * * 27 * $Date: Tue Jun 8 09:32:31 2010 $ * 28 * $Author: ing04880 $ * 29 * $Revision: 1.33 $ * 30 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $ 31 * * 32 * =========================================================================== * 33 */ 34 35 /* 36 ***************************** Header File Inclusion **************************** 37 */ 38 #include <phNfcCompId.h> 39 #include <phNfcHalTypes.h> 40 #include <phHciNfc_Pipe.h> 41 #include <phHciNfc_RFReader.h> 42 #include <phHciNfc_Emulation.h> 43 #include <phOsalNfc.h> 44 45 #if defined (ENABLE_P2P) 46 #include <phHciNfc_NfcIPMgmt.h> 47 /* 48 ****************************** Macro Definitions ******************************* 49 */ 50 /* RF Error */ 51 #define NFCIP_RF_NO_ERROR 0x00U 52 #define NFCIP_STATUS_MAX_VALUE 0x01U 53 54 /* Read and write to the below registry for initiator and target */ 55 #define NXP_NFCIP_MODE 0x01U 56 #define NXP_NFCIP_ATR_REQ 0x02U 57 #define NXP_NFCIP_ATR_RES 0x03U 58 #define NXP_NFCIP_PSL1 0x04U 59 #define NXP_NFCIP_PSL2 0x05U 60 #define NXP_NFCIP_DID 0x06U 61 #define NXP_NFCIP_NAD 0x07U 62 #define NXP_NFCIP_OPTIONS 0x08U 63 #define NXP_NFCIP_STATUS 0x09U 64 #define NXP_NFCIP_NFCID3I 0x0AU 65 #define NXP_NFCIP_NFCID3T 0x0BU 66 #define NXP_NFCIP_PARAM 0x0CU 67 #define NXP_NFCIP_MERGE 0x0DU 68 69 /* command */ 70 #define NXP_NFCIP_ATTREQUEST 0x12U 71 #define NXP_NFCI_CONTINUE_ACTIVATION 0x13U 72 73 /* Event */ 74 #define NXP_EVT_NFC_SND_DATA 0x01U 75 #define NXP_EVT_NFC_ACTIVATED 0x02U 76 #define NXP_EVT_NFC_DEACTIVATED 0x03U 77 #define NXP_EVT_NFC_RCV_DATA 0x04U 78 #define NXP_EVT_NFC_CONTINUE_MI 0x05U 79 80 #define NFCIP_DATE_RATE_FACTOR 0x40U 81 #define NFCIP_DATE_RATE_SHIFT 0x06U 82 #define NFCIP_DATA_RATE_CALC(val) \ 83 ((((uint8_t)(val) >> NFCIP_DATE_RATE_SHIFT) + \ 84 0x01U) * NFCIP_DATE_RATE_FACTOR) 85 #define NFCIP_COMM_INITIATOR_SHIFT 0x03 86 #define NFCIP_COMM_FACTOR 0x03 87 /* 88 *************************** Structure and Enumeration *************************** 89 */ 90 91 /* 92 *************************** Static Function Declaration ************************** 93 */ 94 static 95 NFCSTATUS 96 phHciNfc_NfcIP_InfoUpdate( 97 phHciNfc_sContext_t *psHciContext, 98 uint8_t index, 99 uint8_t *reg_value, 100 uint8_t reg_length 101 ); 102 103 static 104 NFCSTATUS 105 phHciNfc_NfcIP_RecvData( 106 phHciNfc_sContext_t *psHciContext, 107 void *pHwRef, 108 uint8_t *pResponse, 109 #ifdef ONE_BYTE_LEN 110 uint8_t length 111 #else 112 uint16_t length 113 #endif 114 ); 115 116 static 117 NFCSTATUS 118 phHciNfc_Recv_NfcIP_Response( 119 phHciNfc_sContext_t *psHciContext, 120 phHciNfc_Pipe_Info_t *ppipe_info, 121 uint8_t *pResponse, 122 #ifdef ONE_BYTE_LEN 123 uint8_t length 124 #else 125 uint16_t length 126 #endif 127 ); 128 129 static 130 NFCSTATUS 131 phHciNfc_Recv_NfcIP_Event( 132 phHciNfc_sContext_t *psHciContext, 133 void *pHwRef, 134 uint8_t *pEvent, 135 #ifdef ONE_BYTE_LEN 136 uint8_t length 137 #else 138 uint16_t length 139 #endif 140 ); 141 142 static 143 NFCSTATUS 144 phHciNfc_Recv_Initiator_Event( 145 void *psContext, 146 void *pHwRef, 147 uint8_t *pEvent, 148 #ifdef ONE_BYTE_LEN 149 uint8_t length 150 #else 151 uint16_t length 152 #endif 153 ); 154 155 static 156 NFCSTATUS 157 phHciNfc_Recv_Target_Event( 158 void *psContext, 159 void *pHwRef, 160 uint8_t *pEvent, 161 #ifdef ONE_BYTE_LEN 162 uint8_t length 163 #else 164 uint16_t length 165 #endif 166 ); 167 168 static 169 NFCSTATUS 170 phHciNfc_Recv_Initiator_Response( 171 void *psContext, 172 void *pHwRef, 173 uint8_t *pResponse, 174 #ifdef ONE_BYTE_LEN 175 uint8_t length 176 #else 177 uint16_t length 178 #endif 179 ); 180 181 static 182 NFCSTATUS 183 phHciNfc_Recv_Target_Response( 184 void *psContext, 185 void *pHwRef, 186 uint8_t *pResponse, 187 #ifdef ONE_BYTE_LEN 188 uint8_t length 189 #else 190 uint16_t length 191 #endif 192 ); 193 /* 194 *************************** Function Definitions *************************** 195 */ 196 197 NFCSTATUS 198 phHciNfc_Initiator_Init_Resources( 199 phHciNfc_sContext_t *psHciContext 200 ) 201 { 202 NFCSTATUS status = NFCSTATUS_SUCCESS; 203 phHciNfc_NfcIP_Info_t *p_init_info=NULL; 204 if( NULL == psHciContext ) 205 { 206 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 207 } 208 else 209 { 210 if (NULL != psHciContext->p_nfcip_info) 211 { 212 status = NFCSTATUS_SUCCESS; 213 } 214 else if(( NULL == psHciContext->p_nfcip_info ) && 215 (phHciNfc_Allocate_Resource((void **)(&p_init_info), 216 sizeof(phHciNfc_NfcIP_Info_t))== NFCSTATUS_SUCCESS) 217 ) 218 { 219 psHciContext->p_nfcip_info = p_init_info; 220 p_init_info->nfcip_type = NFCIP_INVALID; 221 p_init_info->current_seq = NFCIP_INVALID_SEQUENCE; 222 p_init_info->next_seq = NFCIP_INVALID_SEQUENCE; 223 p_init_info->p_init_pipe_info = NULL; 224 p_init_info->p_tgt_pipe_info = NULL; 225 } 226 else 227 { 228 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES); 229 } 230 231 } 232 return status; 233 } 234 235 NFCSTATUS 236 phHciNfc_Initiator_Get_PipeID( 237 phHciNfc_sContext_t *psHciContext, 238 uint8_t *ppipe_id 239 ) 240 { 241 NFCSTATUS status = NFCSTATUS_SUCCESS; 242 if( (NULL != psHciContext) 243 && ( NULL != ppipe_id ) 244 && ( NULL != psHciContext->p_nfcip_info ) 245 ) 246 { 247 phHciNfc_NfcIP_Info_t *p_init_info=NULL; 248 p_init_info = (phHciNfc_NfcIP_Info_t *) 249 psHciContext->p_nfcip_info ; 250 *ppipe_id = p_init_info->p_init_pipe_info->pipe.pipe_id ; 251 } 252 else 253 { 254 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 255 } 256 return status; 257 } 258 259 NFCSTATUS 260 phHciNfc_Initiator_Update_PipeInfo( 261 phHciNfc_sContext_t *psHciContext, 262 uint8_t pipeID, 263 phHciNfc_Pipe_Info_t *pPipeInfo 264 ) 265 { 266 NFCSTATUS status = NFCSTATUS_SUCCESS; 267 if( NULL == psHciContext ) 268 { 269 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 270 } 271 else if(NULL == psHciContext->p_nfcip_info) 272 { 273 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 274 } 275 else 276 { 277 phHciNfc_NfcIP_Info_t *p_init_info=NULL; 278 p_init_info = (phHciNfc_NfcIP_Info_t *) 279 psHciContext->p_nfcip_info ; 280 /* Update the pipe_id of the NFCIP-1 initiator Gate obtained from 281 the HCI Response */ 282 p_init_info->p_init_pipe_info = pPipeInfo; 283 p_init_info->p_init_pipe_info->pipe.pipe_id = pipeID; 284 /* Update the Response Receive routine of the NFCIP-1 initiator Gate */ 285 pPipeInfo->recv_resp = &phHciNfc_Recv_Initiator_Response; 286 /* Update the event Receive routine of the NFCIP-1 initiator Gate */ 287 pPipeInfo->recv_event = &phHciNfc_Recv_Initiator_Event; 288 } 289 return status; 290 } 291 292 NFCSTATUS 293 phHciNfc_NfcIP_Presence_Check( 294 phHciNfc_sContext_t *psHciContext, 295 void *pHwRef 296 ) 297 { 298 NFCSTATUS status = NFCSTATUS_SUCCESS; 299 300 if( (NULL == psHciContext) || (NULL == pHwRef) ) 301 { 302 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 303 } 304 else if((NULL == psHciContext->p_nfcip_info) || 305 (NFCIP_INVALID == 306 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))->nfcip_type)) 307 { 308 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 309 } 310 else 311 { 312 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 313 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 314 315 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 316 psHciContext->p_nfcip_info ; 317 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)? 318 p_nfcipinfo->p_init_pipe_info : 319 p_nfcipinfo->p_tgt_pipe_info); 320 321 if(NULL == p_pipe_info ) 322 { 323 status = PHNFCSTVAL(CID_NFC_HCI, 324 NFCSTATUS_INVALID_HCI_INFORMATION); 325 } 326 else 327 { 328 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 329 uint16_t length = HCP_HEADER_LEN; 330 uint8_t pipeid = 0; 331 332 pipeid = p_pipe_info->pipe.pipe_id; 333 psHciContext->tx_total = 0 ; 334 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 335 /* Construct the HCP Frame */ 336 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT, 337 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_COMMAND, 338 (uint8_t)NXP_NFCIP_ATTREQUEST); 339 340 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND; 341 p_pipe_info->prev_msg = (uint8_t)NXP_NFCIP_ATTREQUEST; 342 psHciContext->tx_total = length; 343 psHciContext->response_pending = (uint8_t)TRUE; 344 345 /* Send the Constructed HCP packet to the lower layer */ 346 status = phHciNfc_Send_HCP( psHciContext, pHwRef); 347 p_pipe_info->prev_status = status; 348 } 349 } 350 return status; 351 } 352 353 static 354 NFCSTATUS 355 phHciNfc_Recv_Initiator_Response( 356 void *pContext, 357 void *pHwRef, 358 uint8_t *pResponse, 359 #ifdef ONE_BYTE_LEN 360 uint8_t length 361 #else 362 uint16_t length 363 #endif 364 ) 365 { 366 NFCSTATUS status = NFCSTATUS_SUCCESS; 367 phHciNfc_sContext_t *psHciContext = 368 (phHciNfc_sContext_t *)pContext ; 369 370 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse) 371 || (0 == length)) 372 { 373 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 374 } 375 else if(NULL == psHciContext->p_nfcip_info) 376 { 377 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 378 } 379 else 380 { 381 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL; 382 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 383 384 p_nfcip_info = (phHciNfc_NfcIP_Info_t *) 385 psHciContext->p_nfcip_info ; 386 p_pipe_info = p_nfcip_info->p_init_pipe_info; 387 if( NULL == p_pipe_info) 388 { 389 status = PHNFCSTVAL(CID_NFC_HCI, 390 NFCSTATUS_INVALID_HCI_INFORMATION); 391 } 392 else 393 { 394 status = phHciNfc_Recv_NfcIP_Response(psHciContext, 395 p_pipe_info, pResponse, 396 length); 397 if (NFCSTATUS_SUCCESS == status) 398 { 399 status = phHciNfc_ReaderMgmt_Update_Sequence(psHciContext, 400 UPDATE_SEQ); 401 } 402 } 403 } 404 return status; 405 } 406 407 static 408 NFCSTATUS 409 phHciNfc_Recv_Initiator_Event( 410 void *psContext, 411 void *pHwRef, 412 uint8_t *pEvent, 413 #ifdef ONE_BYTE_LEN 414 uint8_t length 415 #else 416 uint16_t length 417 #endif 418 ) 419 { 420 NFCSTATUS status = NFCSTATUS_SUCCESS; 421 phHciNfc_sContext_t *psHciContext = 422 (phHciNfc_sContext_t *)psContext ; 423 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent) 424 || (0 == length)) 425 { 426 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 427 } 428 else if(NULL == psHciContext->p_nfcip_info) 429 { 430 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 431 } 432 else 433 { 434 phHciNfc_HCP_Packet_t *p_packet = NULL; 435 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL; 436 phHciNfc_HCP_Message_t *message = NULL; 437 uint8_t instruction=0; 438 439 p_nfcip_info = (phHciNfc_NfcIP_Info_t *) 440 psHciContext->p_nfcip_info ; 441 p_packet = (phHciNfc_HCP_Packet_t *)pEvent; 442 message = &p_packet->msg.message; 443 /* Get the instruction bits from the Message Header */ 444 instruction = (uint8_t) GET_BITS8( message->msg_header, 445 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN); 446 if (NXP_EVT_NFC_ACTIVATED == instruction) 447 { 448 p_nfcip_info->nfcip_type = NFCIP_INITIATOR; 449 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator; 450 p_nfcip_info->rem_nfcip_tgt_info.RemDevType = phHal_eNfcIP1_Target; 451 } 452 453 status = phHciNfc_Recv_NfcIP_Event(psHciContext, 454 pHwRef, pEvent, length); 455 } 456 return status; 457 } 458 459 NFCSTATUS 460 phHciNfc_Target_Init_Resources( 461 phHciNfc_sContext_t *psHciContext 462 ) 463 { 464 NFCSTATUS status = NFCSTATUS_SUCCESS; 465 phHciNfc_NfcIP_Info_t *p_target_info=NULL; 466 if( NULL == psHciContext ) 467 { 468 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 469 } 470 else 471 { 472 if (NULL != psHciContext->p_nfcip_info) 473 { 474 status = NFCSTATUS_SUCCESS; 475 } 476 else if( 477 ( NULL == psHciContext->p_nfcip_info ) && 478 (phHciNfc_Allocate_Resource((void **)(&p_target_info), 479 sizeof(phHciNfc_NfcIP_Info_t))== NFCSTATUS_SUCCESS) 480 ) 481 { 482 psHciContext->p_nfcip_info = p_target_info; 483 p_target_info->nfcip_type = NFCIP_INVALID; 484 p_target_info->current_seq = NFCIP_INVALID_SEQUENCE; 485 p_target_info->next_seq = NFCIP_INVALID_SEQUENCE; 486 p_target_info->p_tgt_pipe_info = NULL; 487 p_target_info->p_tgt_pipe_info = NULL; 488 } 489 else 490 { 491 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES); 492 } 493 494 } 495 return status; 496 } 497 498 NFCSTATUS 499 phHciNfc_Target_Get_PipeID( 500 phHciNfc_sContext_t *psHciContext, 501 uint8_t *ppipe_id 502 ) 503 { 504 NFCSTATUS status = NFCSTATUS_SUCCESS; 505 if( (NULL != psHciContext) 506 && ( NULL != ppipe_id ) 507 && ( NULL != psHciContext->p_nfcip_info ) 508 ) 509 { 510 phHciNfc_NfcIP_Info_t *p_target_info=NULL; 511 p_target_info = (phHciNfc_NfcIP_Info_t *) 512 psHciContext->p_nfcip_info ; 513 *ppipe_id = p_target_info->p_tgt_pipe_info->pipe.pipe_id; 514 } 515 else 516 { 517 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 518 } 519 return status; 520 } 521 522 NFCSTATUS 523 phHciNfc_Target_Update_PipeInfo( 524 phHciNfc_sContext_t *psHciContext, 525 uint8_t pipeID, 526 phHciNfc_Pipe_Info_t *pPipeInfo 527 ) 528 { 529 NFCSTATUS status = NFCSTATUS_SUCCESS; 530 if( NULL == psHciContext ) 531 { 532 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 533 } 534 else if(NULL == psHciContext->p_nfcip_info) 535 { 536 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 537 } 538 else 539 { 540 phHciNfc_NfcIP_Info_t *p_target_info=NULL; 541 p_target_info = (phHciNfc_NfcIP_Info_t *) 542 psHciContext->p_nfcip_info ; 543 /* Update the pipe_id of the NFCIP-1 target Gate obtained from 544 the HCI Response */ 545 p_target_info->p_tgt_pipe_info = pPipeInfo; 546 p_target_info->p_tgt_pipe_info->pipe.pipe_id = pipeID; 547 /* Update the Response Receive routine of the NFCIP-1 target Gate */ 548 pPipeInfo->recv_resp = &phHciNfc_Recv_Target_Response; 549 /* Update the event Receive routine of the NFCIP-1 target Gate */ 550 pPipeInfo->recv_event = &phHciNfc_Recv_Target_Event; 551 } 552 return status; 553 } 554 555 static 556 NFCSTATUS 557 phHciNfc_Recv_Target_Response( 558 void *pContext, 559 void *pHwRef, 560 uint8_t *pResponse, 561 #ifdef ONE_BYTE_LEN 562 uint8_t length 563 #else 564 uint16_t length 565 #endif 566 ) 567 { 568 NFCSTATUS status = NFCSTATUS_SUCCESS; 569 phHciNfc_sContext_t *psHciContext = 570 (phHciNfc_sContext_t *)pContext ; 571 572 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse) 573 || (0 == length)) 574 { 575 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 576 } 577 else if(NULL == psHciContext->p_nfcip_info) 578 { 579 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 580 } 581 else 582 { 583 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL; 584 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 585 586 p_nfcip_info = (phHciNfc_NfcIP_Info_t *) 587 psHciContext->p_nfcip_info ; 588 p_pipe_info = p_nfcip_info->p_tgt_pipe_info; 589 if( NULL == p_pipe_info) 590 { 591 status = PHNFCSTVAL(CID_NFC_HCI, 592 NFCSTATUS_INVALID_HCI_INFORMATION); 593 } 594 else 595 { 596 status = phHciNfc_Recv_NfcIP_Response(psHciContext, 597 p_pipe_info, pResponse, 598 length); 599 if (NFCSTATUS_SUCCESS == status) 600 { 601 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext, 602 UPDATE_SEQ); 603 } 604 } 605 } 606 return status; 607 } 608 609 static 610 NFCSTATUS 611 phHciNfc_Recv_Target_Event( 612 void *psContext, 613 void *pHwRef, 614 uint8_t *pEvent, 615 #ifdef ONE_BYTE_LEN 616 uint8_t length 617 #else 618 uint16_t length 619 #endif 620 ) 621 { 622 NFCSTATUS status = NFCSTATUS_SUCCESS; 623 phHciNfc_sContext_t *psHciContext = 624 (phHciNfc_sContext_t *)psContext ; 625 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent) 626 || (0 == length)) 627 { 628 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 629 } 630 else if(NULL == psHciContext->p_nfcip_info) 631 { 632 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 633 } 634 else 635 { 636 phHciNfc_HCP_Packet_t *p_packet = NULL; 637 phHciNfc_NfcIP_Info_t *p_nfcip_info=NULL; 638 phHciNfc_HCP_Message_t *message = NULL; 639 uint8_t instruction=0; 640 641 p_nfcip_info = (phHciNfc_NfcIP_Info_t *)psHciContext->p_nfcip_info ; 642 p_packet = (phHciNfc_HCP_Packet_t *)pEvent; 643 message = &p_packet->msg.message; 644 /* Get the instruction bits from the Message Header */ 645 instruction = (uint8_t) GET_BITS8( message->msg_header, 646 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN); 647 if (NXP_EVT_NFC_ACTIVATED == instruction) 648 { 649 p_nfcip_info->nfcip_type = NFCIP_TARGET; 650 psHciContext->host_rf_type = phHal_eNfcIP1_Target; 651 p_nfcip_info->rem_nfcip_tgt_info.RemDevType = 652 phHal_eNfcIP1_Initiator; 653 } 654 status = phHciNfc_Recv_NfcIP_Event(psHciContext, 655 pHwRef, pEvent, length); 656 } 657 return status; 658 } 659 660 static 661 NFCSTATUS 662 phHciNfc_Recv_NfcIP_Response( 663 phHciNfc_sContext_t *psHciContext, 664 phHciNfc_Pipe_Info_t *ppipe_info, 665 uint8_t *pResponse, 666 #ifdef ONE_BYTE_LEN 667 uint8_t length 668 #else 669 uint16_t length 670 #endif 671 ) 672 { 673 NFCSTATUS status = NFCSTATUS_SUCCESS; 674 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 675 uint8_t prev_cmd = ANY_GET_PARAMETER; 676 677 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 678 psHciContext->p_nfcip_info ; 679 prev_cmd = ppipe_info->prev_msg ; 680 switch(prev_cmd) 681 { 682 case ANY_OPEN_PIPE: 683 { 684 HCI_PRINT("NFCIP-1 NFCIP open pipe complete\n"); 685 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 686 break; 687 } 688 case ANY_CLOSE_PIPE: 689 { 690 HCI_PRINT("NFCIP-1 NFCIP close pipe complete\n"); 691 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 692 break; 693 } 694 case ANY_GET_PARAMETER: 695 { 696 HCI_PRINT("NFCIP-1 NFCIP get parameter complete\n"); 697 if (length >= HCP_HEADER_LEN) 698 { 699 status = phHciNfc_NfcIP_InfoUpdate(psHciContext, 700 ppipe_info->reg_index, 701 &pResponse[HCP_HEADER_LEN], 702 (uint8_t)(length - HCP_HEADER_LEN)); 703 } 704 else 705 { 706 status = PHNFCSTVAL(CID_NFC_HCI, 707 NFCSTATUS_INVALID_HCI_RESPONSE); 708 } 709 break; 710 } 711 case ANY_SET_PARAMETER: 712 { 713 HCI_PRINT("NFCIP-1 NFCIP Parameter Set \n"); 714 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 715 break; 716 } 717 case NXP_NFCI_CONTINUE_ACTIVATION: 718 case NXP_NFCIP_ATTREQUEST: 719 { 720 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 721 break; 722 } 723 default: 724 { 725 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE); 726 break; 727 } 728 } 729 730 if( NFCSTATUS_SUCCESS == status ) 731 { 732 ppipe_info->prev_status = NFCSTATUS_SUCCESS; 733 p_nfcipinfo->current_seq = p_nfcipinfo->next_seq; 734 } 735 return status; 736 } 737 738 static 739 NFCSTATUS 740 phHciNfc_Recv_NfcIP_Event( 741 phHciNfc_sContext_t *psHciContext, 742 void *pHwRef, 743 uint8_t *pEvent, 744 #ifdef ONE_BYTE_LEN 745 uint8_t length 746 #else 747 uint16_t length 748 #endif 749 ) 750 { 751 NFCSTATUS status = NFCSTATUS_SUCCESS; 752 phHciNfc_HCP_Packet_t *p_packet = NULL; 753 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 754 phHciNfc_HCP_Message_t *message = NULL; 755 phNfc_sCompletionInfo_t pCompInfo; 756 uint8_t instruction=0; 757 uint8_t type = 0; 758 759 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 760 psHciContext->p_nfcip_info ; 761 p_packet = (phHciNfc_HCP_Packet_t *)pEvent; 762 message = &p_packet->msg.message; 763 /* Get the instruction bits from the Message Header */ 764 instruction = (uint8_t) GET_BITS8( message->msg_header, 765 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN); 766 767 switch(instruction) 768 { 769 case NXP_EVT_NFC_ACTIVATED: 770 { 771 HCI_PRINT("NFCIP-1 device discovered\n"); 772 773 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type) 774 { 775 pCompInfo.info = &(p_nfcipinfo->rem_nfcip_tgt_info); 776 type = NFC_NOTIFY_TARGET_DISCOVERED; 777 } 778 else 779 { 780 type = NFC_NOTIFY_DEVICE_ACTIVATED; 781 } 782 783 if(length > HCP_HEADER_LEN) 784 { 785 HCI_DEBUG("NfcIP-1 activation mode : %d\n", pEvent[HCP_HEADER_LEN]); 786 /* Mode indicates in which mode the current activation 787 as be done 788 - 0x00: Passive mode 789 - 0x01: Active */ 790 p_nfcipinfo->activation_mode = pEvent[HCP_HEADER_LEN]; 791 } 792 pCompInfo.status = NFCSTATUS_SUCCESS; 793 /* Notify to the HCI Generic layer To Update the FSM */ 794 phHciNfc_Notify_Event(psHciContext, pHwRef, 795 type, &pCompInfo); 796 break; 797 } 798 case NXP_EVT_NFC_DEACTIVATED: 799 { 800 static phHal_sEventInfo_t event_info; 801 802 event_info.eventHost = phHal_eHostController; 803 event_info.eventType = NFC_EVT_DEACTIVATED; 804 p_nfcipinfo->activation_mode = FALSE; 805 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type) 806 { 807 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 808 phHal_eNfcIP1_Target; 809 event_info.eventSource = phHal_eNfcIP1_Initiator; 810 } 811 else 812 { 813 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 814 phHal_eNfcIP1_Initiator; 815 event_info.eventSource = phHal_eNfcIP1_Target; 816 } 817 /* Reset the sequence */ 818 p_nfcipinfo->current_seq = NFCIP_NFCID3I; 819 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 820 821 HCI_PRINT("NFCIP-1 Target Deactivated\n"); 822 phHciNfc_Notify_Event(psHciContext, pHwRef, 823 NFC_NOTIFY_DEVICE_DEACTIVATED, 824 &event_info); 825 break; 826 } 827 case NXP_EVT_NFC_RCV_DATA: 828 { 829 status = phHciNfc_NfcIP_RecvData(psHciContext, 830 pHwRef, 831 &pEvent[HCP_HEADER_LEN], 832 (length - HCP_HEADER_LEN)); 833 break; 834 } 835 case NXP_EVT_NFC_CONTINUE_MI: 836 { 837 /* psHciContext->response_pending = FALSE; */ 838 psHciContext->event_pending = FALSE; 839 break; 840 } 841 default: 842 { 843 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 844 break; 845 } 846 } 847 848 return status; 849 } 850 851 static 852 NFCSTATUS 853 phHciNfc_NfcIP_RecvData( 854 phHciNfc_sContext_t *psHciContext, 855 void *pHwRef, 856 uint8_t *pResponse, 857 #ifdef ONE_BYTE_LEN 858 uint8_t length 859 #else 860 uint16_t length 861 #endif 862 ) 863 { 864 NFCSTATUS status = NFCSTATUS_SUCCESS; 865 uint8_t index = 0; 866 867 if( (NULL == psHciContext) 868 || (NULL == pHwRef) 869 || (NULL == pResponse) 870 || (0 == length)) 871 { 872 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 873 } 874 else 875 { 876 phNfc_sTransactionInfo_t transInfo; 877 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL; 878 uint8_t type = 0; 879 880 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 881 psHciContext->p_nfcip_info; 882 HCI_PRINT("NFCIP-1 received bytes :"); 883 if (NFCIP_RF_NO_ERROR == pResponse[index]) 884 { 885 HCI_PRINT_BUFFER("device ", &pResponse[index], (length - index)); 886 transInfo.status = NFCSTATUS_SUCCESS; 887 index++; 888 if (TRUE == pResponse[index]) 889 { 890 /* Update the more information bit to the upper layer */ 891 transInfo.status = NFCSTATUS_MORE_INFORMATION; 892 } 893 index++; 894 895 896 transInfo.buffer = &pResponse[index]; 897 transInfo.length = (length - index); 898 type = (uint8_t)NFC_NOTIFY_RECV_EVENT; 899 } 900 else 901 { 902 HCI_PRINT("NFCIP-1 receive RF ERROR "); 903 p_nfcipinfo->activation_mode = FALSE; 904 type = (uint8_t)NFC_NOTIFY_RECV_EVENT; 905 transInfo.status = NFCSTATUS_RF_TIMEOUT; 906 transInfo.buffer = NULL; 907 transInfo.length = 0; 908 } 909 status = NFCSTATUS_PENDING; 910 /* Event NXP_EVT_NFC_RCV_DATA: so give received data to 911 the upper layer */ 912 phHciNfc_Notify_Event(psHciContext, pHwRef, 913 type, 914 &transInfo ); 915 } 916 return status; 917 } 918 919 NFCSTATUS 920 phHciNfc_NfcIP_Send_Data ( 921 phHciNfc_sContext_t *psHciContext, 922 void *pHwRef, 923 phHciNfc_XchgInfo_t *sData 924 ) 925 { 926 NFCSTATUS status = NFCSTATUS_SUCCESS; 927 928 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == sData) || 929 (NULL == sData->tx_buffer) || (0 == sData->tx_length)) 930 { 931 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 932 } 933 else if((NULL == psHciContext->p_nfcip_info) || 934 (NFCIP_INVALID == 935 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))->nfcip_type)) 936 { 937 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 938 } 939 else 940 { 941 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 942 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 943 944 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 945 psHciContext->p_nfcip_info ; 946 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)? 947 p_nfcipinfo->p_init_pipe_info : 948 p_nfcipinfo->p_tgt_pipe_info); 949 950 if(NULL == p_pipe_info ) 951 { 952 status = PHNFCSTVAL(CID_NFC_HCI, 953 NFCSTATUS_INVALID_HCI_INFORMATION); 954 } 955 else 956 { 957 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 958 phHciNfc_HCP_Message_t *hcp_message = NULL; 959 uint16_t length = HCP_HEADER_LEN; 960 uint8_t pipeid = 0, 961 i = 0; 962 963 HCI_PRINT_BUFFER("HCI NFCIP-1 Send Data: ", sData->tx_buffer, sData->tx_length); 964 965 psHciContext->tx_total = 0 ; 966 pipeid = p_pipe_info->pipe.pipe_id; 967 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 968 hcp_message = &(hcp_packet->msg.message); 969 hcp_message->payload[i] = sData->params.nfc_info.more_info; 970 i++; 971 972 /* Construct the HCP Frame */ 973 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT, 974 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_EVENT, 975 (uint8_t)NXP_EVT_NFC_SND_DATA); 976 977 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload, 978 i, (uint8_t *)sData->tx_buffer, 979 (uint8_t)sData->tx_length); 980 981 length =(uint16_t)(length + i + sData->tx_length); 982 983 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_EVENT; 984 p_pipe_info->prev_msg = NXP_EVT_NFC_SND_DATA; 985 psHciContext->tx_total = length; 986 /* Send the Constructed HCP packet to the lower layer */ 987 status = phHciNfc_Send_HCP( psHciContext, pHwRef); 988 #if !defined (ENABLE_CONTINUE_MI) 989 if ((TRUE == sData->params.nfc_info.more_info) && 990 (NFCSTATUS_PENDING == status)) 991 { 992 /* If more information bit is set, then wait for the event 993 NXP_EVT_NFC_CONTINUE_MI */ 994 /* psHciContext->response_pending = TRUE; */ 995 psHciContext->event_pending = TRUE; 996 } 997 #endif /* #if defined (ENABLE_CONTINUE_MI) */ 998 p_pipe_info->prev_status = status; 999 } 1000 } 1001 return status; 1002 } 1003 1004 NFCSTATUS 1005 phHciNfc_NfcIP_Info_Sequence ( 1006 phHciNfc_sContext_t *psHciContext, 1007 void *pHwRef 1008 #ifdef NOTIFY_REQD 1009 , 1010 uint8_t notify_reqd 1011 #endif /* #ifdef NOTIFY_REQD */ 1012 ) 1013 { 1014 NFCSTATUS status = NFCSTATUS_SUCCESS; 1015 1016 if( (NULL == psHciContext) 1017 || (NULL == pHwRef) 1018 ) 1019 { 1020 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1021 } 1022 else if((NULL == psHciContext->p_nfcip_info) || 1023 (NFCIP_INVALID == 1024 ((phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info))-> 1025 nfcip_type)) 1026 { 1027 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1028 } 1029 else 1030 { 1031 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1032 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1033 1034 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1035 psHciContext->p_nfcip_info ; 1036 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)? 1037 p_nfcipinfo->p_init_pipe_info: 1038 p_nfcipinfo->p_tgt_pipe_info); 1039 if(NULL == p_pipe_info ) 1040 { 1041 status = PHNFCSTVAL(CID_NFC_HCI, 1042 NFCSTATUS_INVALID_HCI_INFORMATION); 1043 } 1044 else 1045 { 1046 switch(p_nfcipinfo->current_seq) 1047 { 1048 case NFCIP_NFCID3I: 1049 { 1050 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NFCID3I; 1051 /* Fill the data buffer and send the command to the 1052 device */ 1053 status = 1054 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1055 p_pipe_info->pipe.pipe_id, 1056 ANY_GET_PARAMETER); 1057 if(NFCSTATUS_PENDING == status ) 1058 { 1059 p_nfcipinfo->next_seq = NFCIP_NFCID3T; 1060 } 1061 break; 1062 } 1063 case NFCIP_NFCID3T: 1064 { 1065 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NFCID3T; 1066 /* Fill the data buffer and send the command to the 1067 device */ 1068 status = 1069 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1070 p_pipe_info->pipe.pipe_id, 1071 ANY_GET_PARAMETER); 1072 if(NFCSTATUS_PENDING == status ) 1073 { 1074 p_nfcipinfo->next_seq = NFCIP_PARAM; 1075 } 1076 break; 1077 } 1078 case NFCIP_PARAM: 1079 { 1080 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PARAM; 1081 /* Fill the data buffer and send the command to the 1082 device */ 1083 status = 1084 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1085 p_pipe_info->pipe.pipe_id, 1086 ANY_GET_PARAMETER); 1087 if(NFCSTATUS_PENDING == status ) 1088 { 1089 p_nfcipinfo->next_seq = NFCIP_ATR_INFO; 1090 } 1091 break; 1092 } 1093 case NFCIP_ATR_INFO: 1094 { 1095 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == 1096 p_nfcipinfo->nfcip_type)? 1097 NXP_NFCIP_ATR_RES : 1098 NXP_NFCIP_ATR_REQ); 1099 status = 1100 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1101 p_pipe_info->pipe.pipe_id, 1102 ANY_GET_PARAMETER); 1103 1104 if(NFCSTATUS_PENDING == status ) 1105 { 1106 p_nfcipinfo->next_seq = NFCIP_STATUS; 1107 } 1108 break; 1109 } 1110 case NFCIP_STATUS: 1111 { 1112 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_STATUS; 1113 /* Fill the data buffer and send the command to the 1114 device */ 1115 status = 1116 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1117 p_pipe_info->pipe.pipe_id, 1118 ANY_GET_PARAMETER); 1119 if(NFCSTATUS_PENDING == status ) 1120 { 1121 #ifdef NOTIFY_REQD 1122 if(FALSE == notify_reqd) 1123 #else /* #ifdef NOTIFY_REQD */ 1124 if (NULL != psHciContext->p_target_info) 1125 #endif /* #ifdef NOTIFY_REQD */ 1126 { 1127 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 1128 status = NFCSTATUS_SUCCESS; 1129 } 1130 else 1131 { 1132 p_nfcipinfo->next_seq = NFCIP_END_SEQUENCE; 1133 } 1134 } 1135 break; 1136 } 1137 case NFCIP_END_SEQUENCE: 1138 { 1139 phHal_uRemoteDevInfo_t *rem_nfcipinfo = NULL; 1140 1141 if (NULL != psHciContext->p_target_info) 1142 { 1143 /* This is given to user */ 1144 rem_nfcipinfo = 1145 &(psHciContext->p_target_info->RemoteDevInfo); 1146 } 1147 else 1148 { 1149 rem_nfcipinfo = 1150 &(p_nfcipinfo->rem_nfcip_tgt_info.RemoteDevInfo); 1151 } 1152 1153 /* Update maximum frame length */ 1154 rem_nfcipinfo->NfcIP_Info.MaxFrameLength = 1155 p_nfcipinfo->max_frame_len; 1156 1157 p_nfcipinfo->current_seq = NFCIP_NFCID3I; 1158 p_nfcipinfo->next_seq = NFCIP_NFCID3I; 1159 1160 rem_nfcipinfo->NfcIP_Info.Nfcip_Active = 1161 p_nfcipinfo->activation_mode; 1162 1163 1164 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type) 1165 { 1166 phNfc_sCompletionInfo_t CompInfo; 1167 1168 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 1169 phHal_eNfcIP1_Target; 1170 1171 /* Update initiator speed */ 1172 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate = 1173 (phHalNfc_eDataRate_t) 1174 (p_nfcipinfo->initiator_speed); 1175 1176 1177 /* Update ATR info */ 1178 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length = 1179 p_nfcipinfo->atr_res_length; 1180 (void)memcpy( 1181 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo, 1182 (void *)p_nfcipinfo->atr_res_info, 1183 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length); 1184 1185 /* Update NFCID */ 1186 rem_nfcipinfo->NfcIP_Info.NFCID_Length = 1187 p_nfcipinfo->nfcid3i_length; 1188 (void)memcpy( 1189 (void *)rem_nfcipinfo->NfcIP_Info.NFCID, 1190 (void *)p_nfcipinfo->nfcid3i, 1191 rem_nfcipinfo->NfcIP_Info.NFCID_Length); 1192 1193 CompInfo.status = status = NFCSTATUS_SUCCESS; 1194 if (NULL != psHciContext->p_target_info) 1195 { 1196 CompInfo.info = &(psHciContext->p_target_info); 1197 } 1198 else 1199 { 1200 CompInfo.info = &(p_nfcipinfo->rem_nfcip_tgt_info); 1201 } 1202 /* Notify to the upper layer */ 1203 phHciNfc_Tag_Notify(psHciContext, pHwRef, 1204 NFC_NOTIFY_TARGET_DISCOVERED, 1205 &CompInfo); 1206 } 1207 else 1208 { 1209 static phHal_sEventInfo_t event_info; 1210 1211 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 1212 phHal_eNfcIP1_Initiator; 1213 1214 /* Update target speed */ 1215 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate = 1216 (phHalNfc_eDataRate_t) 1217 (p_nfcipinfo->target_speed); 1218 /* Update ATR info */ 1219 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length = 1220 p_nfcipinfo->atr_req_length; 1221 (void)memcpy( 1222 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo, 1223 (void *)p_nfcipinfo->atr_req_info, 1224 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length); 1225 1226 /* Update NFCID */ 1227 rem_nfcipinfo->NfcIP_Info.NFCID_Length = 1228 p_nfcipinfo->nfcid3t_length; 1229 (void)memcpy( 1230 (void *)rem_nfcipinfo->NfcIP_Info.NFCID, 1231 (void *)p_nfcipinfo->nfcid3t, 1232 rem_nfcipinfo->NfcIP_Info.NFCID_Length); 1233 1234 event_info.eventHost = phHal_eHostController; 1235 event_info.eventType = NFC_EVT_ACTIVATED; 1236 event_info.eventSource = phHal_eNfcIP1_Target; 1237 event_info.eventInfo.pRemoteDevInfo = 1238 &(p_nfcipinfo->rem_nfcip_tgt_info); 1239 1240 phHciNfc_Target_Select_Notify((void *)psHciContext, 1241 pHwRef, 1242 NFC_NOTIFY_EVENT, 1243 &(event_info)); 1244 } 1245 break; 1246 } 1247 default: 1248 { 1249 status = PHNFCSTVAL(CID_NFC_HCI, 1250 NFCSTATUS_INVALID_HCI_RESPONSE); 1251 break; 1252 } 1253 } 1254 } 1255 } 1256 return status; 1257 } 1258 1259 static 1260 NFCSTATUS 1261 phHciNfc_NfcIP_InfoUpdate( 1262 phHciNfc_sContext_t *psHciContext, 1263 uint8_t index, 1264 uint8_t *reg_value, 1265 uint8_t reg_length 1266 ) 1267 { 1268 NFCSTATUS status = NFCSTATUS_SUCCESS; 1269 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL; 1270 phHal_sNfcIPInfo_t *p_rem_nfcipinfo = NULL; 1271 1272 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info ); 1273 p_rem_nfcipinfo = &(p_nfcipinfo->rem_nfcip_tgt_info.RemoteDevInfo.NfcIP_Info); 1274 1275 1276 switch(index) 1277 { 1278 case NXP_NFCIP_ATR_RES: 1279 { 1280 if (reg_length <= NFCIP_ATR_MAX_LENGTH) 1281 { 1282 /* Remote device info provided by the user */ 1283 1284 HCI_PRINT_BUFFER("\tNFCIP ATR_RES", reg_value, reg_length); 1285 1286 p_rem_nfcipinfo->ATRInfo_Length = 1287 p_nfcipinfo->atr_res_length = reg_length; 1288 1289 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo, 1290 (void *)reg_value, 1291 p_rem_nfcipinfo->ATRInfo_Length); 1292 1293 (void)memcpy((void *)p_nfcipinfo->atr_res_info, 1294 (void *)reg_value, 1295 p_nfcipinfo->atr_res_length); 1296 if (NULL != psHciContext->p_target_info) 1297 { 1298 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1299 /* This is given to user */ 1300 p_remtgt_info = 1301 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1302 p_remtgt_info->ATRInfo_Length = reg_length; 1303 (void)memcpy((void *)p_remtgt_info->ATRInfo, 1304 (void *)reg_value, 1305 p_remtgt_info->ATRInfo_Length); 1306 } 1307 } 1308 else 1309 { 1310 status = PHNFCSTVAL(CID_NFC_HCI, 1311 NFCSTATUS_INVALID_HCI_RESPONSE); 1312 } 1313 break; 1314 } 1315 case NXP_NFCIP_STATUS: 1316 { 1317 if (sizeof(*reg_value) == reg_length) 1318 #ifdef STATUS_BUFFER_CHECK 1319 && (*reg_value <= NFCIP_STATUS_MAX_VALUE)) 1320 #endif /* #ifdef STATUS_ERROR */ 1321 { 1322 HCI_PRINT_BUFFER("\tNFCIP STATUS", reg_value, reg_length); 1323 p_nfcipinfo->linkstatus = *reg_value; 1324 } 1325 else 1326 { 1327 status = PHNFCSTVAL(CID_NFC_HCI, 1328 NFCSTATUS_INVALID_HCI_RESPONSE); 1329 } 1330 break; 1331 } 1332 case NXP_NFCIP_NFCID3I: 1333 { 1334 if (reg_length <= NFCIP_NFCID_LENGTH) 1335 { 1336 HCI_PRINT_BUFFER("\tNFCIP NFCID3I", reg_value, reg_length); 1337 p_nfcipinfo->nfcid3i_length = 1338 p_rem_nfcipinfo->NFCID_Length = reg_length; 1339 (void)memcpy((void *)p_rem_nfcipinfo->NFCID, 1340 (void *)reg_value, 1341 p_rem_nfcipinfo->NFCID_Length); 1342 (void)memcpy((void *)p_nfcipinfo->nfcid3i, 1343 (void *)reg_value, 1344 reg_length); 1345 if ((NULL != psHciContext->p_target_info) && 1346 (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)) 1347 { 1348 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1349 /* This is given to user */ 1350 p_remtgt_info = 1351 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1352 p_remtgt_info->NFCID_Length = reg_length; 1353 (void)memcpy((void *)p_remtgt_info->NFCID, 1354 (void *)reg_value, 1355 p_remtgt_info->NFCID_Length); 1356 } 1357 } 1358 else 1359 { 1360 status = PHNFCSTVAL(CID_NFC_HCI, 1361 NFCSTATUS_INVALID_HCI_RESPONSE); 1362 } 1363 break; 1364 } 1365 case NXP_NFCIP_NFCID3T: 1366 { 1367 if (reg_length <= NFCIP_NFCID_LENGTH) 1368 { 1369 HCI_PRINT_BUFFER("\tNFCIP NFCID3T", reg_value, reg_length); 1370 p_nfcipinfo->nfcid3t_length = 1371 p_rem_nfcipinfo->NFCID_Length = reg_length; 1372 (void)memcpy((void *)p_rem_nfcipinfo->NFCID, 1373 (void *)reg_value, 1374 p_rem_nfcipinfo->NFCID_Length); 1375 (void)memcpy((void *)p_nfcipinfo->nfcid3t, 1376 (void *)reg_value, 1377 reg_length); 1378 if ((NULL != psHciContext->p_target_info) && 1379 (NFCIP_TARGET == p_nfcipinfo->nfcip_type)) 1380 { 1381 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1382 /* This is given to user */ 1383 p_remtgt_info = 1384 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1385 p_remtgt_info->NFCID_Length = reg_length; 1386 (void)memcpy((void *)p_remtgt_info->NFCID, 1387 (void *)reg_value, 1388 p_remtgt_info->NFCID_Length); 1389 } 1390 } 1391 else 1392 { 1393 status = PHNFCSTVAL(CID_NFC_HCI, 1394 NFCSTATUS_INVALID_HCI_RESPONSE); 1395 } 1396 break; 1397 } 1398 case NXP_NFCIP_PARAM: 1399 { 1400 if (sizeof(*reg_value) == reg_length) 1401 { 1402 HCI_PRINT_BUFFER("\tNFCIP PARAMS", reg_value, reg_length); 1403 p_nfcipinfo->initiator_speed = (phHciNfc_eP2PSpeed_t) 1404 ((*reg_value >> NFCIP_COMM_INITIATOR_SHIFT) 1405 & NFCIP_COMM_FACTOR); 1406 p_nfcipinfo->target_speed = (phHciNfc_eP2PSpeed_t) 1407 (*reg_value & NFCIP_COMM_FACTOR); 1408 p_nfcipinfo->max_frame_len = NFCIP_DATA_RATE_CALC(*reg_value); 1409 1410 if (NULL != psHciContext->p_target_info) 1411 { 1412 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1413 /* This is given to user */ 1414 p_remtgt_info = 1415 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1416 p_remtgt_info->MaxFrameLength = p_nfcipinfo->max_frame_len; 1417 p_remtgt_info->Nfcip_Datarate = (phHalNfc_eDataRate_t) 1418 p_nfcipinfo->initiator_speed; 1419 } 1420 } 1421 else 1422 { 1423 status = PHNFCSTVAL(CID_NFC_HCI, 1424 NFCSTATUS_INVALID_HCI_RESPONSE); 1425 } 1426 break; 1427 } 1428 case NXP_NFCIP_MODE: 1429 { 1430 if (sizeof(*reg_value) == reg_length) 1431 { 1432 HCI_PRINT_BUFFER("\tNFCIP MODE", reg_value, reg_length); 1433 p_nfcipinfo->nfcip_mode = *reg_value; 1434 } 1435 else 1436 { 1437 status = PHNFCSTVAL(CID_NFC_HCI, 1438 NFCSTATUS_INVALID_HCI_RESPONSE); 1439 } 1440 break; 1441 } 1442 case NXP_NFCIP_ATR_REQ: 1443 { 1444 if (reg_length <= NFCIP_ATR_MAX_LENGTH) 1445 { 1446 HCI_PRINT_BUFFER("\tNFCIP ATR_REQ", reg_value, reg_length); 1447 p_rem_nfcipinfo->ATRInfo_Length = 1448 p_nfcipinfo->atr_req_length = reg_length; 1449 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo, 1450 (void *)reg_value, 1451 p_rem_nfcipinfo->ATRInfo_Length); 1452 (void)memcpy((void *)p_nfcipinfo->atr_req_info, 1453 (void *)reg_value, 1454 p_nfcipinfo->atr_req_length); 1455 if (NULL != psHciContext->p_target_info) 1456 { 1457 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1458 /* This is given to user */ 1459 p_remtgt_info = 1460 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1461 p_remtgt_info->NFCID_Length = reg_length; 1462 (void)memcpy((void *)p_remtgt_info->ATRInfo, 1463 (void *)reg_value, 1464 p_remtgt_info->ATRInfo_Length); 1465 } 1466 } 1467 else 1468 { 1469 status = PHNFCSTVAL(CID_NFC_HCI, 1470 NFCSTATUS_INVALID_HCI_RESPONSE); 1471 } 1472 break; 1473 } 1474 case NXP_NFCIP_PSL1: 1475 { 1476 if (sizeof(*reg_value) == reg_length) 1477 { 1478 HCI_PRINT_BUFFER("\tNFCIP PSL1", reg_value, reg_length); 1479 p_nfcipinfo->psl1 = *reg_value; 1480 } 1481 else 1482 { 1483 status = PHNFCSTVAL(CID_NFC_HCI, 1484 NFCSTATUS_INVALID_HCI_RESPONSE); 1485 } 1486 break; 1487 } 1488 case NXP_NFCIP_PSL2: 1489 { 1490 if (sizeof(*reg_value) == reg_length) 1491 { 1492 HCI_PRINT_BUFFER("\tNFCIP PSL2", reg_value, reg_length); 1493 p_nfcipinfo->psl2 = *reg_value; 1494 } 1495 else 1496 { 1497 status = PHNFCSTVAL(CID_NFC_HCI, 1498 NFCSTATUS_INVALID_HCI_RESPONSE); 1499 } 1500 break; 1501 } 1502 case NXP_NFCIP_DID: 1503 { 1504 if (sizeof(*reg_value) == reg_length) 1505 { 1506 HCI_PRINT_BUFFER("\tNFCIP DID", reg_value, reg_length); 1507 p_nfcipinfo->did = *reg_value; 1508 } 1509 else 1510 { 1511 status = PHNFCSTVAL(CID_NFC_HCI, 1512 NFCSTATUS_INVALID_HCI_RESPONSE); 1513 } 1514 break; 1515 } 1516 case NXP_NFCIP_NAD: 1517 { 1518 if (sizeof(*reg_value) == reg_length) 1519 { 1520 HCI_PRINT_BUFFER("\tNFCIP NAD", reg_value, reg_length); 1521 p_nfcipinfo->nad = *reg_value; 1522 } 1523 else 1524 { 1525 status = PHNFCSTVAL(CID_NFC_HCI, 1526 NFCSTATUS_INVALID_HCI_RESPONSE); 1527 } 1528 break; 1529 } 1530 case NXP_NFCIP_OPTIONS: 1531 { 1532 if (sizeof(*reg_value) == reg_length) 1533 { 1534 HCI_PRINT_BUFFER("\tNFCIP OPTIONS", reg_value, reg_length); 1535 p_nfcipinfo->options = *reg_value; 1536 } 1537 else 1538 { 1539 status = PHNFCSTVAL(CID_NFC_HCI, 1540 NFCSTATUS_INVALID_HCI_RESPONSE); 1541 } 1542 break; 1543 } 1544 default: 1545 { 1546 status = PHNFCSTVAL(CID_NFC_HCI, 1547 NFCSTATUS_INVALID_HCI_RESPONSE); 1548 break; 1549 } 1550 } 1551 return status; 1552 } 1553 1554 1555 NFCSTATUS 1556 phHciNfc_NfcIP_SetMode( 1557 phHciNfc_sContext_t *psHciContext, 1558 void *pHwRef, 1559 phHciNfc_eNfcIPType_t nfciptype, 1560 uint8_t nfcip_mode 1561 ) 1562 { 1563 NFCSTATUS status = NFCSTATUS_SUCCESS; 1564 1565 if( (NULL == psHciContext) || (NULL == pHwRef) || 1566 (nfcip_mode > (uint8_t)NFCIP_MODE_ALL)) 1567 { 1568 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1569 } 1570 else if (NFCIP_INVALID == nfciptype) 1571 { 1572 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1573 } 1574 else if(NULL == psHciContext->p_nfcip_info) 1575 { 1576 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1577 } 1578 else 1579 { 1580 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1581 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1582 uint8_t pipeid = 0; 1583 1584 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1585 psHciContext->p_nfcip_info ; 1586 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1587 p_nfcipinfo->p_init_pipe_info: 1588 p_nfcipinfo->p_tgt_pipe_info); 1589 1590 if(NULL == p_pipe_info ) 1591 { 1592 status = PHNFCSTVAL(CID_NFC_HCI, 1593 NFCSTATUS_INVALID_HCI_INFORMATION); 1594 } 1595 else 1596 { 1597 pipeid = p_pipe_info->pipe.pipe_id ; 1598 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MODE; 1599 1600 p_pipe_info->param_info = &nfcip_mode; 1601 p_pipe_info->param_length = sizeof(uint8_t); 1602 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1603 pipeid, (uint8_t)ANY_SET_PARAMETER); 1604 } 1605 } 1606 return status; 1607 } 1608 1609 NFCSTATUS 1610 phHciNfc_NfcIP_SetNAD( 1611 phHciNfc_sContext_t *psHciContext, 1612 void *pHwRef, 1613 phHciNfc_eNfcIPType_t nfciptype, 1614 uint8_t nad 1615 ) 1616 { 1617 NFCSTATUS status = NFCSTATUS_SUCCESS; 1618 1619 if( (NULL == psHciContext) || (NULL == pHwRef)) 1620 { 1621 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1622 } 1623 else if (NFCIP_INVALID == nfciptype) 1624 { 1625 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1626 } 1627 else if(NULL == psHciContext->p_nfcip_info) 1628 { 1629 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1630 } 1631 else 1632 { 1633 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1634 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1635 uint8_t pipeid = 0; 1636 1637 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1638 psHciContext->p_nfcip_info ; 1639 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1640 p_nfcipinfo->p_init_pipe_info: 1641 p_nfcipinfo->p_tgt_pipe_info); 1642 1643 if(NULL == p_pipe_info ) 1644 { 1645 status = PHNFCSTVAL(CID_NFC_HCI, 1646 NFCSTATUS_INVALID_HCI_INFORMATION); 1647 } 1648 else 1649 { 1650 pipeid = p_pipe_info->pipe.pipe_id ; 1651 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NAD; 1652 1653 p_pipe_info->param_info = &nad; 1654 p_pipe_info->param_length = sizeof(uint8_t); 1655 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1656 pipeid, (uint8_t)ANY_SET_PARAMETER); 1657 } 1658 } 1659 return status; 1660 } 1661 1662 NFCSTATUS 1663 phHciNfc_NfcIP_SetDID( 1664 phHciNfc_sContext_t *psHciContext, 1665 void *pHwRef, 1666 uint8_t did 1667 ) 1668 { 1669 NFCSTATUS status = NFCSTATUS_SUCCESS; 1670 1671 if( (NULL == psHciContext) || (NULL == pHwRef)) 1672 { 1673 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1674 } 1675 else if(NULL == psHciContext->p_nfcip_info) 1676 { 1677 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1678 } 1679 else 1680 { 1681 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1682 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1683 uint8_t pipeid = 0; 1684 1685 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1686 psHciContext->p_nfcip_info ; 1687 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1688 1689 if(NULL == p_pipe_info ) 1690 { 1691 status = PHNFCSTVAL(CID_NFC_HCI, 1692 NFCSTATUS_INVALID_HCI_INFORMATION); 1693 } 1694 else 1695 { 1696 pipeid = p_pipe_info->pipe.pipe_id ; 1697 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_DID; 1698 1699 p_pipe_info->param_info = &did; 1700 p_pipe_info->param_length = sizeof(uint8_t); 1701 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1702 pipeid, (uint8_t)ANY_SET_PARAMETER); 1703 } 1704 } 1705 return status; 1706 } 1707 1708 NFCSTATUS 1709 phHciNfc_NfcIP_SetOptions( 1710 phHciNfc_sContext_t *psHciContext, 1711 void *pHwRef, 1712 phHciNfc_eNfcIPType_t nfciptype, 1713 uint8_t nfcip_options 1714 ) 1715 { 1716 NFCSTATUS status = NFCSTATUS_SUCCESS; 1717 1718 if( (NULL == psHciContext) || (NULL == pHwRef)) 1719 { 1720 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1721 } 1722 else if (NFCIP_INVALID == nfciptype) 1723 { 1724 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1725 } 1726 else if(NULL == psHciContext->p_nfcip_info) 1727 { 1728 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1729 } 1730 else 1731 { 1732 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1733 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1734 uint8_t pipeid = 0; 1735 1736 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1737 psHciContext->p_nfcip_info ; 1738 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)? 1739 p_nfcipinfo->p_init_pipe_info: 1740 p_nfcipinfo->p_tgt_pipe_info); 1741 pipeid = p_pipe_info->pipe.pipe_id ; 1742 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_OPTIONS; 1743 1744 p_pipe_info->param_info = &nfcip_options; 1745 p_pipe_info->param_length = sizeof(uint8_t); 1746 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1747 pipeid, (uint8_t)ANY_SET_PARAMETER); 1748 } 1749 return status; 1750 } 1751 1752 NFCSTATUS 1753 phHciNfc_NfcIP_SetATRInfo( 1754 phHciNfc_sContext_t *psHciContext, 1755 void *pHwRef, 1756 phHciNfc_eNfcIPType_t nfciptype, 1757 phHal_sNfcIPCfg_t *atr_info 1758 ) 1759 { 1760 NFCSTATUS status = NFCSTATUS_SUCCESS; 1761 1762 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == atr_info) || 1763 (atr_info->generalBytesLength > NFCIP_ATR_MAX_LENGTH)) 1764 { 1765 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1766 } 1767 else if (NFCIP_INVALID == nfciptype) 1768 { 1769 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1770 } 1771 else if(NULL == psHciContext->p_nfcip_info) 1772 { 1773 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1774 } 1775 else 1776 { 1777 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1778 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1779 uint8_t pipeid = 0; 1780 1781 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1782 psHciContext->p_nfcip_info ; 1783 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1784 p_nfcipinfo->p_init_pipe_info: 1785 p_nfcipinfo->p_tgt_pipe_info); 1786 1787 if(NULL == p_pipe_info ) 1788 { 1789 status = PHNFCSTVAL(CID_NFC_HCI, 1790 NFCSTATUS_INVALID_HCI_INFORMATION); 1791 } 1792 else 1793 { 1794 pipeid = p_pipe_info->pipe.pipe_id ; 1795 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)? 1796 NXP_NFCIP_ATR_REQ : 1797 NXP_NFCIP_ATR_RES); 1798 1799 p_pipe_info->param_info = atr_info->generalBytes; 1800 p_pipe_info->param_length = (uint8_t) 1801 atr_info->generalBytesLength; 1802 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1803 pipeid, (uint8_t)ANY_SET_PARAMETER); 1804 } 1805 } 1806 return status; 1807 } 1808 1809 NFCSTATUS 1810 phHciNfc_NfcIP_SetPSL1( 1811 phHciNfc_sContext_t *psHciContext, 1812 void *pHwRef, 1813 uint8_t psl1 1814 ) 1815 { 1816 NFCSTATUS status = NFCSTATUS_SUCCESS; 1817 1818 if( (NULL == psHciContext) || (NULL == pHwRef)) 1819 { 1820 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1821 } 1822 else if(NULL == psHciContext->p_nfcip_info) 1823 { 1824 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1825 } 1826 else 1827 { 1828 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1829 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1830 uint8_t pipeid = 0; 1831 1832 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1833 psHciContext->p_nfcip_info ; 1834 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1835 1836 if(NULL == p_pipe_info ) 1837 { 1838 status = PHNFCSTVAL(CID_NFC_HCI, 1839 NFCSTATUS_INVALID_HCI_INFORMATION); 1840 } 1841 else 1842 { 1843 pipeid = p_pipe_info->pipe.pipe_id ; 1844 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL1; 1845 1846 p_pipe_info->param_info = &psl1; 1847 p_pipe_info->param_length = sizeof(uint8_t); 1848 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1849 pipeid, (uint8_t)ANY_SET_PARAMETER); 1850 } 1851 } 1852 return status; 1853 } 1854 1855 NFCSTATUS 1856 phHciNfc_NfcIP_SetPSL2( 1857 phHciNfc_sContext_t *psHciContext, 1858 void *pHwRef, 1859 uint8_t psl2 1860 ) 1861 { 1862 NFCSTATUS status = NFCSTATUS_SUCCESS; 1863 1864 if( (NULL == psHciContext) || (NULL == pHwRef)) 1865 { 1866 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1867 } 1868 else if(NULL == psHciContext->p_nfcip_info) 1869 { 1870 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1871 } 1872 else 1873 { 1874 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1875 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1876 uint8_t pipeid = 0; 1877 1878 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1879 psHciContext->p_nfcip_info ; 1880 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1881 1882 if(NULL == p_pipe_info ) 1883 { 1884 status = PHNFCSTVAL(CID_NFC_HCI, 1885 NFCSTATUS_INVALID_HCI_INFORMATION); 1886 } 1887 else 1888 { 1889 pipeid = p_pipe_info->pipe.pipe_id ; 1890 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL2; 1891 1892 p_pipe_info->param_info = &psl2; 1893 p_pipe_info->param_length = sizeof(uint8_t); 1894 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1895 pipeid, (uint8_t)ANY_SET_PARAMETER); 1896 } 1897 } 1898 return status; 1899 } 1900 1901 NFCSTATUS 1902 phHciNfc_NfcIP_GetStatus( 1903 phHciNfc_sContext_t *psHciContext, 1904 void *pHwRef, 1905 phHciNfc_eNfcIPType_t nfciptype 1906 ) 1907 { 1908 NFCSTATUS status = NFCSTATUS_SUCCESS; 1909 1910 if( (NULL == psHciContext) || (NULL == pHwRef)) 1911 { 1912 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1913 } 1914 else if (NFCIP_INVALID == nfciptype) 1915 { 1916 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1917 } 1918 else if(NULL == psHciContext->p_nfcip_info) 1919 { 1920 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1921 } 1922 else 1923 { 1924 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1925 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1926 uint8_t pipeid = 0; 1927 1928 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1929 psHciContext->p_nfcip_info ; 1930 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1931 p_nfcipinfo->p_init_pipe_info : 1932 p_nfcipinfo->p_tgt_pipe_info); 1933 if(NULL == p_pipe_info ) 1934 { 1935 status = PHNFCSTVAL(CID_NFC_HCI, 1936 NFCSTATUS_INVALID_HCI_INFORMATION); 1937 } 1938 else 1939 { 1940 pipeid = p_pipe_info->pipe.pipe_id ; 1941 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_STATUS; 1942 1943 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1944 pipeid, (uint8_t)ANY_GET_PARAMETER); 1945 } 1946 } 1947 return status; 1948 } 1949 1950 NFCSTATUS 1951 phHciNfc_NfcIP_GetParam( 1952 phHciNfc_sContext_t *psHciContext, 1953 void *pHwRef, 1954 phHciNfc_eNfcIPType_t nfciptype 1955 ) 1956 { 1957 NFCSTATUS status = NFCSTATUS_SUCCESS; 1958 1959 if( (NULL == psHciContext) || (NULL == pHwRef)) 1960 { 1961 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1962 } 1963 else if (NFCIP_INVALID == nfciptype) 1964 { 1965 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1966 } 1967 else if(NULL == psHciContext->p_nfcip_info) 1968 { 1969 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1970 } 1971 else 1972 { 1973 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1974 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1975 uint8_t pipeid = 0; 1976 1977 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1978 psHciContext->p_nfcip_info ; 1979 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1980 p_nfcipinfo->p_init_pipe_info : 1981 p_nfcipinfo->p_tgt_pipe_info); 1982 if(NULL == p_pipe_info ) 1983 { 1984 status = PHNFCSTVAL(CID_NFC_HCI, 1985 NFCSTATUS_INVALID_HCI_INFORMATION); 1986 } 1987 else 1988 { 1989 pipeid = p_pipe_info->pipe.pipe_id ; 1990 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PARAM; 1991 1992 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1993 pipeid, (uint8_t)ANY_GET_PARAMETER); 1994 } 1995 } 1996 return status; 1997 } 1998 1999 NFCSTATUS 2000 phHciNfc_Initiator_Cont_Activate ( 2001 phHciNfc_sContext_t *psHciContext, 2002 void *pHwRef 2003 ) 2004 { 2005 NFCSTATUS status = NFCSTATUS_SUCCESS; 2006 2007 if( (NULL == psHciContext) || (NULL == pHwRef) ) 2008 { 2009 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2010 } 2011 else if(NULL == psHciContext->p_nfcip_info) 2012 { 2013 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2014 } 2015 else 2016 { 2017 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL; 2018 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 2019 2020 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2021 psHciContext->p_nfcip_info ; 2022 p_nfcipinfo->nfcip_type = NFCIP_INITIATOR; 2023 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator; 2024 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 2025 if(NULL == p_pipe_info ) 2026 { 2027 status = PHNFCSTVAL(CID_NFC_HCI, 2028 NFCSTATUS_INVALID_HCI_INFORMATION); 2029 } 2030 else 2031 { 2032 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 2033 uint16_t length = HCP_HEADER_LEN; 2034 uint8_t pipeid = 0; 2035 2036 pipeid = p_pipe_info->pipe.pipe_id; 2037 psHciContext->tx_total = 0 ; 2038 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 2039 /* Construct the HCP Frame */ 2040 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT, 2041 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_COMMAND, 2042 (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION); 2043 2044 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND; 2045 p_pipe_info->prev_msg = (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION; 2046 psHciContext->tx_total = length; 2047 psHciContext->response_pending = (uint8_t)TRUE; 2048 2049 /* Send the Constructed HCP packet to the lower layer */ 2050 status = phHciNfc_Send_HCP( psHciContext, pHwRef); 2051 p_pipe_info->prev_status = status; 2052 } 2053 } 2054 return status; 2055 } 2056 2057 2058 NFCSTATUS 2059 phHciNfc_NfcIP_GetATRInfo ( 2060 phHciNfc_sContext_t *psHciContext, 2061 void *pHwRef, 2062 phHciNfc_eNfcIPType_t nfciptype 2063 ) 2064 { 2065 NFCSTATUS status = NFCSTATUS_SUCCESS; 2066 2067 if( (NULL == psHciContext) 2068 || (NULL == pHwRef)) 2069 { 2070 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2071 } 2072 else if (NFCIP_INVALID == nfciptype) 2073 { 2074 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 2075 } 2076 else if(NULL == psHciContext->p_nfcip_info) 2077 { 2078 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2079 } 2080 else 2081 { 2082 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 2083 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 2084 uint8_t pipeid = 0; 2085 2086 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2087 psHciContext->p_nfcip_info ; 2088 2089 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 2090 p_nfcipinfo->p_init_pipe_info : 2091 p_nfcipinfo->p_tgt_pipe_info); 2092 2093 if(NULL == p_pipe_info ) 2094 { 2095 status = PHNFCSTVAL(CID_NFC_HCI, 2096 NFCSTATUS_INVALID_HCI_INFORMATION); 2097 } 2098 else 2099 { 2100 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)? 2101 NXP_NFCIP_ATR_RES : 2102 NXP_NFCIP_ATR_REQ); 2103 pipeid = p_pipe_info->pipe.pipe_id ; 2104 /* Fill the data buffer and send the command to the 2105 device */ 2106 status = 2107 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 2108 pipeid, (uint8_t)ANY_GET_PARAMETER); 2109 } 2110 } 2111 return status; 2112 } 2113 2114 NFCSTATUS 2115 phHciNfc_NfcIP_SetMergeSak( 2116 phHciNfc_sContext_t *psHciContext, 2117 void *pHwRef, 2118 uint8_t sak_value 2119 ) 2120 { 2121 NFCSTATUS status = NFCSTATUS_SUCCESS; 2122 2123 if( (NULL == psHciContext) || (NULL == pHwRef) || 2124 (sak_value > (uint8_t)TRUE)) 2125 { 2126 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2127 } 2128 else if(NULL == psHciContext->p_nfcip_info) 2129 { 2130 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2131 } 2132 else 2133 { 2134 phHciNfc_NfcIP_Info_t *ps_nfcipinfo=NULL; 2135 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 2136 uint8_t pipeid = 0; 2137 2138 ps_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2139 psHciContext->p_nfcip_info ; 2140 ps_pipe_info = ps_nfcipinfo->p_tgt_pipe_info; 2141 2142 if(NULL == ps_pipe_info ) 2143 { 2144 status = PHNFCSTVAL(CID_NFC_HCI, 2145 NFCSTATUS_INVALID_HCI_INFORMATION); 2146 } 2147 else 2148 { 2149 pipeid = ps_pipe_info->pipe.pipe_id ; 2150 ps_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MERGE; 2151 2152 ps_pipe_info->param_info = &sak_value; 2153 ps_pipe_info->param_length = sizeof(uint8_t); 2154 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 2155 pipeid, (uint8_t)ANY_SET_PARAMETER); 2156 } 2157 } 2158 return status; 2159 } 2160 2161 #endif /* #if defined (ENABLE_P2P) */ 2162 2163