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 if (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type) 1164 { 1165 phNfc_sCompletionInfo_t CompInfo; 1166 1167 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 1168 phHal_eNfcIP1_Target; 1169 1170 /* Update initiator speed */ 1171 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate = 1172 (phHalNfc_eDataRate_t) 1173 (p_nfcipinfo->initiator_speed); 1174 1175 1176 /* Update ATR info */ 1177 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length = 1178 p_nfcipinfo->atr_res_length; 1179 (void)memcpy( 1180 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo, 1181 (void *)p_nfcipinfo->atr_res_info, 1182 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length); 1183 1184 /* Update NFCID */ 1185 rem_nfcipinfo->NfcIP_Info.NFCID_Length = 1186 p_nfcipinfo->nfcid3i_length; 1187 (void)memcpy( 1188 (void *)rem_nfcipinfo->NfcIP_Info.NFCID, 1189 (void *)p_nfcipinfo->nfcid3i, 1190 rem_nfcipinfo->NfcIP_Info.NFCID_Length); 1191 1192 CompInfo.status = status = NFCSTATUS_SUCCESS; 1193 if (NULL != psHciContext->p_target_info) 1194 { 1195 CompInfo.info = &(psHciContext->p_target_info); 1196 } 1197 else 1198 { 1199 CompInfo.info = &(p_nfcipinfo->rem_nfcip_tgt_info); 1200 } 1201 /* Notify to the upper layer */ 1202 phHciNfc_Tag_Notify(psHciContext, pHwRef, 1203 NFC_NOTIFY_TARGET_DISCOVERED, 1204 &CompInfo); 1205 } 1206 else 1207 { 1208 static phHal_sEventInfo_t event_info; 1209 1210 p_nfcipinfo->rem_nfcip_tgt_info.RemDevType = 1211 phHal_eNfcIP1_Initiator; 1212 1213 /* Update target speed */ 1214 rem_nfcipinfo->NfcIP_Info.Nfcip_Datarate = 1215 (phHalNfc_eDataRate_t) 1216 (p_nfcipinfo->target_speed); 1217 /* Update ATR info */ 1218 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length = 1219 p_nfcipinfo->atr_req_length; 1220 (void)memcpy( 1221 (void *)rem_nfcipinfo->NfcIP_Info.ATRInfo, 1222 (void *)p_nfcipinfo->atr_req_info, 1223 rem_nfcipinfo->NfcIP_Info.ATRInfo_Length); 1224 1225 /* Update NFCID */ 1226 rem_nfcipinfo->NfcIP_Info.NFCID_Length = 1227 p_nfcipinfo->nfcid3t_length; 1228 (void)memcpy( 1229 (void *)rem_nfcipinfo->NfcIP_Info.NFCID, 1230 (void *)p_nfcipinfo->nfcid3t, 1231 rem_nfcipinfo->NfcIP_Info.NFCID_Length); 1232 1233 event_info.eventHost = phHal_eHostController; 1234 event_info.eventType = NFC_EVT_ACTIVATED; 1235 event_info.eventSource = phHal_eNfcIP1_Target; 1236 event_info.eventInfo.pRemoteDevInfo = 1237 &(p_nfcipinfo->rem_nfcip_tgt_info); 1238 1239 phHciNfc_Target_Select_Notify((void *)psHciContext, 1240 pHwRef, 1241 NFC_NOTIFY_EVENT, 1242 &(event_info)); 1243 } 1244 break; 1245 } 1246 default: 1247 { 1248 status = PHNFCSTVAL(CID_NFC_HCI, 1249 NFCSTATUS_INVALID_HCI_RESPONSE); 1250 break; 1251 } 1252 } 1253 } 1254 } 1255 return status; 1256 } 1257 1258 static 1259 NFCSTATUS 1260 phHciNfc_NfcIP_InfoUpdate( 1261 phHciNfc_sContext_t *psHciContext, 1262 uint8_t index, 1263 uint8_t *reg_value, 1264 uint8_t reg_length 1265 ) 1266 { 1267 NFCSTATUS status = NFCSTATUS_SUCCESS; 1268 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL; 1269 phHal_sNfcIPInfo_t *p_rem_nfcipinfo = NULL; 1270 1271 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *)(psHciContext->p_nfcip_info ); 1272 p_rem_nfcipinfo = &(p_nfcipinfo->rem_nfcip_tgt_info.RemoteDevInfo.NfcIP_Info); 1273 1274 1275 switch(index) 1276 { 1277 case NXP_NFCIP_ATR_RES: 1278 { 1279 if (reg_length <= NFCIP_ATR_MAX_LENGTH) 1280 { 1281 /* Remote device info provided by the user */ 1282 1283 HCI_PRINT_BUFFER("\tNFCIP ATR_RES", reg_value, reg_length); 1284 1285 p_rem_nfcipinfo->ATRInfo_Length = 1286 p_nfcipinfo->atr_res_length = reg_length; 1287 1288 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo, 1289 (void *)reg_value, 1290 p_rem_nfcipinfo->ATRInfo_Length); 1291 1292 (void)memcpy((void *)p_nfcipinfo->atr_res_info, 1293 (void *)reg_value, 1294 p_nfcipinfo->atr_res_length); 1295 if (NULL != psHciContext->p_target_info) 1296 { 1297 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1298 /* This is given to user */ 1299 p_remtgt_info = 1300 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1301 p_remtgt_info->ATRInfo_Length = reg_length; 1302 (void)memcpy((void *)p_remtgt_info->ATRInfo, 1303 (void *)reg_value, 1304 p_remtgt_info->ATRInfo_Length); 1305 } 1306 } 1307 else 1308 { 1309 status = PHNFCSTVAL(CID_NFC_HCI, 1310 NFCSTATUS_INVALID_HCI_RESPONSE); 1311 } 1312 break; 1313 } 1314 case NXP_NFCIP_STATUS: 1315 { 1316 if (sizeof(*reg_value) == reg_length) 1317 #ifdef STATUS_BUFFER_CHECK 1318 && (*reg_value <= NFCIP_STATUS_MAX_VALUE)) 1319 #endif /* #ifdef STATUS_ERROR */ 1320 { 1321 HCI_PRINT_BUFFER("\tNFCIP STATUS", reg_value, reg_length); 1322 p_nfcipinfo->linkstatus = *reg_value; 1323 } 1324 else 1325 { 1326 status = PHNFCSTVAL(CID_NFC_HCI, 1327 NFCSTATUS_INVALID_HCI_RESPONSE); 1328 } 1329 break; 1330 } 1331 case NXP_NFCIP_NFCID3I: 1332 { 1333 if (reg_length <= NFCIP_NFCID_LENGTH) 1334 { 1335 HCI_PRINT_BUFFER("\tNFCIP NFCID3I", reg_value, reg_length); 1336 p_nfcipinfo->nfcid3i_length = 1337 p_rem_nfcipinfo->NFCID_Length = reg_length; 1338 (void)memcpy((void *)p_rem_nfcipinfo->NFCID, 1339 (void *)reg_value, 1340 p_rem_nfcipinfo->NFCID_Length); 1341 (void)memcpy((void *)p_nfcipinfo->nfcid3i, 1342 (void *)reg_value, 1343 reg_length); 1344 if ((NULL != psHciContext->p_target_info) && 1345 (NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)) 1346 { 1347 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1348 /* This is given to user */ 1349 p_remtgt_info = 1350 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1351 p_remtgt_info->NFCID_Length = reg_length; 1352 (void)memcpy((void *)p_remtgt_info->NFCID, 1353 (void *)reg_value, 1354 p_remtgt_info->NFCID_Length); 1355 } 1356 } 1357 else 1358 { 1359 status = PHNFCSTVAL(CID_NFC_HCI, 1360 NFCSTATUS_INVALID_HCI_RESPONSE); 1361 } 1362 break; 1363 } 1364 case NXP_NFCIP_NFCID3T: 1365 { 1366 if (reg_length <= NFCIP_NFCID_LENGTH) 1367 { 1368 HCI_PRINT_BUFFER("\tNFCIP NFCID3T", reg_value, reg_length); 1369 p_nfcipinfo->nfcid3t_length = 1370 p_rem_nfcipinfo->NFCID_Length = reg_length; 1371 (void)memcpy((void *)p_rem_nfcipinfo->NFCID, 1372 (void *)reg_value, 1373 p_rem_nfcipinfo->NFCID_Length); 1374 (void)memcpy((void *)p_nfcipinfo->nfcid3t, 1375 (void *)reg_value, 1376 reg_length); 1377 if ((NULL != psHciContext->p_target_info) && 1378 (NFCIP_TARGET == p_nfcipinfo->nfcip_type)) 1379 { 1380 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1381 /* This is given to user */ 1382 p_remtgt_info = 1383 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1384 p_remtgt_info->NFCID_Length = reg_length; 1385 (void)memcpy((void *)p_remtgt_info->NFCID, 1386 (void *)reg_value, 1387 p_remtgt_info->NFCID_Length); 1388 } 1389 } 1390 else 1391 { 1392 status = PHNFCSTVAL(CID_NFC_HCI, 1393 NFCSTATUS_INVALID_HCI_RESPONSE); 1394 } 1395 break; 1396 } 1397 case NXP_NFCIP_PARAM: 1398 { 1399 if (sizeof(*reg_value) == reg_length) 1400 { 1401 HCI_PRINT_BUFFER("\tNFCIP PARAMS", reg_value, reg_length); 1402 p_nfcipinfo->initiator_speed = (phHciNfc_eP2PSpeed_t) 1403 ((*reg_value >> NFCIP_COMM_INITIATOR_SHIFT) 1404 & NFCIP_COMM_FACTOR); 1405 if (p_nfcipinfo->nfcip_type == NFCIP_INITIATOR) { 1406 switch(p_nfcipinfo->initiator_speed) { 1407 case phNfc_eDataRate_106: 1408 ALOGI("I'm P2P %s Initiator @ 106 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1409 break; 1410 case phNfc_eDataRate_212: 1411 ALOGI("I'm P2P %s Initiator @ 212 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1412 break; 1413 case phNfc_eDataRate_424: 1414 ALOGI("I'm P2P %s Initiator @ 424 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1415 break; 1416 } 1417 } 1418 p_nfcipinfo->target_speed = (phHciNfc_eP2PSpeed_t) 1419 (*reg_value & NFCIP_COMM_FACTOR); 1420 if (p_nfcipinfo->nfcip_type == NFCIP_TARGET) { 1421 switch(p_nfcipinfo->target_speed) { 1422 case phNfc_eDataRate_106: 1423 ALOGI("I'm P2P %s Target @ 106 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1424 break; 1425 case phNfc_eDataRate_212: 1426 ALOGI("I'm P2P %s Target @ 212 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1427 break; 1428 case phNfc_eDataRate_424: 1429 ALOGI("I'm P2P %s Target @ 424 kb/s", p_nfcipinfo->activation_mode ? "Active" : "Passive"); 1430 break; 1431 } 1432 } 1433 p_nfcipinfo->max_frame_len = NFCIP_DATA_RATE_CALC(*reg_value); 1434 1435 if (p_nfcipinfo->max_frame_len > NFCIP_MAX_DEP_REQ_HDR_LEN) 1436 { 1437 p_nfcipinfo->max_frame_len -= NFCIP_MAX_DEP_REQ_HDR_LEN; 1438 1439 if (NULL != psHciContext->p_target_info) 1440 { 1441 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1442 /* This is given to user */ 1443 p_remtgt_info = 1444 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1445 p_remtgt_info->MaxFrameLength = p_nfcipinfo->max_frame_len; 1446 p_remtgt_info->Nfcip_Datarate = (phHalNfc_eDataRate_t) 1447 p_nfcipinfo->initiator_speed; 1448 } 1449 } 1450 else 1451 { 1452 status = PHNFCSTVAL(CID_NFC_HCI, 1453 NFCSTATUS_INVALID_HCI_RESPONSE); 1454 } 1455 } 1456 else 1457 { 1458 status = PHNFCSTVAL(CID_NFC_HCI, 1459 NFCSTATUS_INVALID_HCI_RESPONSE); 1460 } 1461 break; 1462 } 1463 case NXP_NFCIP_MODE: 1464 { 1465 if (sizeof(*reg_value) == reg_length) 1466 { 1467 HCI_PRINT_BUFFER("\tNFCIP MODE", reg_value, reg_length); 1468 p_nfcipinfo->nfcip_mode = *reg_value; 1469 } 1470 else 1471 { 1472 status = PHNFCSTVAL(CID_NFC_HCI, 1473 NFCSTATUS_INVALID_HCI_RESPONSE); 1474 } 1475 break; 1476 } 1477 case NXP_NFCIP_ATR_REQ: 1478 { 1479 if (reg_length <= NFCIP_ATR_MAX_LENGTH) 1480 { 1481 HCI_PRINT_BUFFER("\tNFCIP ATR_REQ", reg_value, reg_length); 1482 p_rem_nfcipinfo->ATRInfo_Length = 1483 p_nfcipinfo->atr_req_length = reg_length; 1484 (void)memcpy((void *)p_rem_nfcipinfo->ATRInfo, 1485 (void *)reg_value, 1486 p_rem_nfcipinfo->ATRInfo_Length); 1487 (void)memcpy((void *)p_nfcipinfo->atr_req_info, 1488 (void *)reg_value, 1489 p_nfcipinfo->atr_req_length); 1490 if (NULL != psHciContext->p_target_info) 1491 { 1492 phHal_sNfcIPInfo_t *p_remtgt_info = NULL; 1493 /* This is given to user */ 1494 p_remtgt_info = 1495 &(psHciContext->p_target_info->RemoteDevInfo.NfcIP_Info); 1496 p_remtgt_info->NFCID_Length = reg_length; 1497 (void)memcpy((void *)p_remtgt_info->ATRInfo, 1498 (void *)reg_value, 1499 p_remtgt_info->ATRInfo_Length); 1500 } 1501 } 1502 else 1503 { 1504 status = PHNFCSTVAL(CID_NFC_HCI, 1505 NFCSTATUS_INVALID_HCI_RESPONSE); 1506 } 1507 break; 1508 } 1509 case NXP_NFCIP_PSL1: 1510 { 1511 if (sizeof(*reg_value) == reg_length) 1512 { 1513 HCI_PRINT_BUFFER("\tNFCIP PSL1", reg_value, reg_length); 1514 p_nfcipinfo->psl1 = *reg_value; 1515 } 1516 else 1517 { 1518 status = PHNFCSTVAL(CID_NFC_HCI, 1519 NFCSTATUS_INVALID_HCI_RESPONSE); 1520 } 1521 break; 1522 } 1523 case NXP_NFCIP_PSL2: 1524 { 1525 if (sizeof(*reg_value) == reg_length) 1526 { 1527 HCI_PRINT_BUFFER("\tNFCIP PSL2", reg_value, reg_length); 1528 p_nfcipinfo->psl2 = *reg_value; 1529 } 1530 else 1531 { 1532 status = PHNFCSTVAL(CID_NFC_HCI, 1533 NFCSTATUS_INVALID_HCI_RESPONSE); 1534 } 1535 break; 1536 } 1537 case NXP_NFCIP_DID: 1538 { 1539 if (sizeof(*reg_value) == reg_length) 1540 { 1541 HCI_PRINT_BUFFER("\tNFCIP DID", reg_value, reg_length); 1542 p_nfcipinfo->did = *reg_value; 1543 } 1544 else 1545 { 1546 status = PHNFCSTVAL(CID_NFC_HCI, 1547 NFCSTATUS_INVALID_HCI_RESPONSE); 1548 } 1549 break; 1550 } 1551 case NXP_NFCIP_NAD: 1552 { 1553 if (sizeof(*reg_value) == reg_length) 1554 { 1555 HCI_PRINT_BUFFER("\tNFCIP NAD", reg_value, reg_length); 1556 p_nfcipinfo->nad = *reg_value; 1557 } 1558 else 1559 { 1560 status = PHNFCSTVAL(CID_NFC_HCI, 1561 NFCSTATUS_INVALID_HCI_RESPONSE); 1562 } 1563 break; 1564 } 1565 case NXP_NFCIP_OPTIONS: 1566 { 1567 if (sizeof(*reg_value) == reg_length) 1568 { 1569 HCI_PRINT_BUFFER("\tNFCIP OPTIONS", reg_value, reg_length); 1570 p_nfcipinfo->options = *reg_value; 1571 } 1572 else 1573 { 1574 status = PHNFCSTVAL(CID_NFC_HCI, 1575 NFCSTATUS_INVALID_HCI_RESPONSE); 1576 } 1577 break; 1578 } 1579 default: 1580 { 1581 status = PHNFCSTVAL(CID_NFC_HCI, 1582 NFCSTATUS_INVALID_HCI_RESPONSE); 1583 break; 1584 } 1585 } 1586 return status; 1587 } 1588 1589 1590 NFCSTATUS 1591 phHciNfc_NfcIP_SetMode( 1592 phHciNfc_sContext_t *psHciContext, 1593 void *pHwRef, 1594 phHciNfc_eNfcIPType_t nfciptype, 1595 uint8_t nfcip_mode 1596 ) 1597 { 1598 NFCSTATUS status = NFCSTATUS_SUCCESS; 1599 1600 if( (NULL == psHciContext) || (NULL == pHwRef) || 1601 (nfcip_mode > (uint8_t)NFCIP_MODE_ALL)) 1602 { 1603 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1604 } 1605 else if (NFCIP_INVALID == nfciptype) 1606 { 1607 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1608 } 1609 else if(NULL == psHciContext->p_nfcip_info) 1610 { 1611 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1612 } 1613 else 1614 { 1615 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1616 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1617 uint8_t pipeid = 0; 1618 1619 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1620 psHciContext->p_nfcip_info ; 1621 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1622 p_nfcipinfo->p_init_pipe_info: 1623 p_nfcipinfo->p_tgt_pipe_info); 1624 1625 if(NULL == p_pipe_info ) 1626 { 1627 status = PHNFCSTVAL(CID_NFC_HCI, 1628 NFCSTATUS_INVALID_HCI_INFORMATION); 1629 } 1630 else 1631 { 1632 pipeid = p_pipe_info->pipe.pipe_id ; 1633 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MODE; 1634 1635 p_pipe_info->param_info = &nfcip_mode; 1636 p_pipe_info->param_length = sizeof(uint8_t); 1637 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1638 pipeid, (uint8_t)ANY_SET_PARAMETER); 1639 } 1640 } 1641 return status; 1642 } 1643 1644 NFCSTATUS 1645 phHciNfc_NfcIP_SetNAD( 1646 phHciNfc_sContext_t *psHciContext, 1647 void *pHwRef, 1648 phHciNfc_eNfcIPType_t nfciptype, 1649 uint8_t nad 1650 ) 1651 { 1652 NFCSTATUS status = NFCSTATUS_SUCCESS; 1653 1654 if( (NULL == psHciContext) || (NULL == pHwRef)) 1655 { 1656 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1657 } 1658 else if (NFCIP_INVALID == nfciptype) 1659 { 1660 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1661 } 1662 else if(NULL == psHciContext->p_nfcip_info) 1663 { 1664 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1665 } 1666 else 1667 { 1668 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1669 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1670 uint8_t pipeid = 0; 1671 1672 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1673 psHciContext->p_nfcip_info ; 1674 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1675 p_nfcipinfo->p_init_pipe_info: 1676 p_nfcipinfo->p_tgt_pipe_info); 1677 1678 if(NULL == p_pipe_info ) 1679 { 1680 status = PHNFCSTVAL(CID_NFC_HCI, 1681 NFCSTATUS_INVALID_HCI_INFORMATION); 1682 } 1683 else 1684 { 1685 pipeid = p_pipe_info->pipe.pipe_id ; 1686 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_NAD; 1687 1688 p_pipe_info->param_info = &nad; 1689 p_pipe_info->param_length = sizeof(uint8_t); 1690 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1691 pipeid, (uint8_t)ANY_SET_PARAMETER); 1692 } 1693 } 1694 return status; 1695 } 1696 1697 NFCSTATUS 1698 phHciNfc_NfcIP_SetDID( 1699 phHciNfc_sContext_t *psHciContext, 1700 void *pHwRef, 1701 uint8_t did 1702 ) 1703 { 1704 NFCSTATUS status = NFCSTATUS_SUCCESS; 1705 1706 if( (NULL == psHciContext) || (NULL == pHwRef)) 1707 { 1708 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1709 } 1710 else if(NULL == psHciContext->p_nfcip_info) 1711 { 1712 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1713 } 1714 else 1715 { 1716 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1717 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1718 uint8_t pipeid = 0; 1719 1720 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1721 psHciContext->p_nfcip_info ; 1722 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1723 1724 if(NULL == p_pipe_info ) 1725 { 1726 status = PHNFCSTVAL(CID_NFC_HCI, 1727 NFCSTATUS_INVALID_HCI_INFORMATION); 1728 } 1729 else 1730 { 1731 pipeid = p_pipe_info->pipe.pipe_id ; 1732 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_DID; 1733 1734 p_pipe_info->param_info = &did; 1735 p_pipe_info->param_length = sizeof(uint8_t); 1736 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1737 pipeid, (uint8_t)ANY_SET_PARAMETER); 1738 } 1739 } 1740 return status; 1741 } 1742 1743 NFCSTATUS 1744 phHciNfc_NfcIP_SetOptions( 1745 phHciNfc_sContext_t *psHciContext, 1746 void *pHwRef, 1747 phHciNfc_eNfcIPType_t nfciptype, 1748 uint8_t nfcip_options 1749 ) 1750 { 1751 NFCSTATUS status = NFCSTATUS_SUCCESS; 1752 1753 if( (NULL == psHciContext) || (NULL == pHwRef)) 1754 { 1755 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1756 } 1757 else if (NFCIP_INVALID == nfciptype) 1758 { 1759 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1760 } 1761 else if(NULL == psHciContext->p_nfcip_info) 1762 { 1763 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1764 } 1765 else 1766 { 1767 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1768 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1769 uint8_t pipeid = 0; 1770 1771 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1772 psHciContext->p_nfcip_info ; 1773 p_pipe_info = ((NFCIP_INITIATOR == p_nfcipinfo->nfcip_type)? 1774 p_nfcipinfo->p_init_pipe_info: 1775 p_nfcipinfo->p_tgt_pipe_info); 1776 pipeid = p_pipe_info->pipe.pipe_id ; 1777 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_OPTIONS; 1778 1779 p_pipe_info->param_info = &nfcip_options; 1780 p_pipe_info->param_length = sizeof(uint8_t); 1781 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1782 pipeid, (uint8_t)ANY_SET_PARAMETER); 1783 } 1784 return status; 1785 } 1786 1787 NFCSTATUS 1788 phHciNfc_NfcIP_SetATRInfo( 1789 phHciNfc_sContext_t *psHciContext, 1790 void *pHwRef, 1791 phHciNfc_eNfcIPType_t nfciptype, 1792 phHal_sNfcIPCfg_t *atr_info 1793 ) 1794 { 1795 NFCSTATUS status = NFCSTATUS_SUCCESS; 1796 1797 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == atr_info) || 1798 (atr_info->generalBytesLength > NFCIP_ATR_MAX_LENGTH)) 1799 { 1800 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1801 } 1802 else if (NFCIP_INVALID == nfciptype) 1803 { 1804 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1805 } 1806 else if(NULL == psHciContext->p_nfcip_info) 1807 { 1808 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1809 } 1810 else 1811 { 1812 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1813 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1814 uint8_t pipeid = 0; 1815 1816 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1817 psHciContext->p_nfcip_info ; 1818 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1819 p_nfcipinfo->p_init_pipe_info: 1820 p_nfcipinfo->p_tgt_pipe_info); 1821 1822 if(NULL == p_pipe_info ) 1823 { 1824 status = PHNFCSTVAL(CID_NFC_HCI, 1825 NFCSTATUS_INVALID_HCI_INFORMATION); 1826 } 1827 else 1828 { 1829 pipeid = p_pipe_info->pipe.pipe_id ; 1830 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)? 1831 NXP_NFCIP_ATR_REQ : 1832 NXP_NFCIP_ATR_RES); 1833 1834 p_pipe_info->param_info = atr_info->generalBytes; 1835 p_pipe_info->param_length = (uint8_t) 1836 atr_info->generalBytesLength; 1837 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1838 pipeid, (uint8_t)ANY_SET_PARAMETER); 1839 } 1840 } 1841 return status; 1842 } 1843 1844 NFCSTATUS 1845 phHciNfc_NfcIP_SetPSL1( 1846 phHciNfc_sContext_t *psHciContext, 1847 void *pHwRef, 1848 uint8_t psl1 1849 ) 1850 { 1851 NFCSTATUS status = NFCSTATUS_SUCCESS; 1852 1853 if( (NULL == psHciContext) || (NULL == pHwRef)) 1854 { 1855 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1856 } 1857 else if(NULL == psHciContext->p_nfcip_info) 1858 { 1859 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1860 } 1861 else 1862 { 1863 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1864 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1865 uint8_t pipeid = 0; 1866 1867 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1868 psHciContext->p_nfcip_info ; 1869 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1870 1871 if(NULL == p_pipe_info ) 1872 { 1873 status = PHNFCSTVAL(CID_NFC_HCI, 1874 NFCSTATUS_INVALID_HCI_INFORMATION); 1875 } 1876 else 1877 { 1878 pipeid = p_pipe_info->pipe.pipe_id ; 1879 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL1; 1880 1881 p_pipe_info->param_info = &psl1; 1882 p_pipe_info->param_length = sizeof(uint8_t); 1883 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1884 pipeid, (uint8_t)ANY_SET_PARAMETER); 1885 } 1886 } 1887 return status; 1888 } 1889 1890 NFCSTATUS 1891 phHciNfc_NfcIP_SetPSL2( 1892 phHciNfc_sContext_t *psHciContext, 1893 void *pHwRef, 1894 uint8_t psl2 1895 ) 1896 { 1897 NFCSTATUS status = NFCSTATUS_SUCCESS; 1898 1899 if( (NULL == psHciContext) || (NULL == pHwRef)) 1900 { 1901 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1902 } 1903 else if(NULL == psHciContext->p_nfcip_info) 1904 { 1905 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1906 } 1907 else 1908 { 1909 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1910 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1911 uint8_t pipeid = 0; 1912 1913 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1914 psHciContext->p_nfcip_info ; 1915 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 1916 1917 if(NULL == p_pipe_info ) 1918 { 1919 status = PHNFCSTVAL(CID_NFC_HCI, 1920 NFCSTATUS_INVALID_HCI_INFORMATION); 1921 } 1922 else 1923 { 1924 pipeid = p_pipe_info->pipe.pipe_id ; 1925 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PSL2; 1926 1927 p_pipe_info->param_info = &psl2; 1928 p_pipe_info->param_length = sizeof(uint8_t); 1929 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1930 pipeid, (uint8_t)ANY_SET_PARAMETER); 1931 } 1932 } 1933 return status; 1934 } 1935 1936 NFCSTATUS 1937 phHciNfc_NfcIP_GetStatus( 1938 phHciNfc_sContext_t *psHciContext, 1939 void *pHwRef, 1940 phHciNfc_eNfcIPType_t nfciptype 1941 ) 1942 { 1943 NFCSTATUS status = NFCSTATUS_SUCCESS; 1944 1945 if( (NULL == psHciContext) || (NULL == pHwRef)) 1946 { 1947 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1948 } 1949 else if (NFCIP_INVALID == nfciptype) 1950 { 1951 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1952 } 1953 else if(NULL == psHciContext->p_nfcip_info) 1954 { 1955 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1956 } 1957 else 1958 { 1959 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 1960 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 1961 uint8_t pipeid = 0; 1962 1963 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 1964 psHciContext->p_nfcip_info ; 1965 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 1966 p_nfcipinfo->p_init_pipe_info : 1967 p_nfcipinfo->p_tgt_pipe_info); 1968 if(NULL == p_pipe_info ) 1969 { 1970 status = PHNFCSTVAL(CID_NFC_HCI, 1971 NFCSTATUS_INVALID_HCI_INFORMATION); 1972 } 1973 else 1974 { 1975 pipeid = p_pipe_info->pipe.pipe_id ; 1976 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_STATUS; 1977 1978 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 1979 pipeid, (uint8_t)ANY_GET_PARAMETER); 1980 } 1981 } 1982 return status; 1983 } 1984 1985 NFCSTATUS 1986 phHciNfc_NfcIP_GetParam( 1987 phHciNfc_sContext_t *psHciContext, 1988 void *pHwRef, 1989 phHciNfc_eNfcIPType_t nfciptype 1990 ) 1991 { 1992 NFCSTATUS status = NFCSTATUS_SUCCESS; 1993 1994 if( (NULL == psHciContext) || (NULL == pHwRef)) 1995 { 1996 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1997 } 1998 else if (NFCIP_INVALID == nfciptype) 1999 { 2000 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 2001 } 2002 else if(NULL == psHciContext->p_nfcip_info) 2003 { 2004 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2005 } 2006 else 2007 { 2008 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 2009 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 2010 uint8_t pipeid = 0; 2011 2012 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2013 psHciContext->p_nfcip_info ; 2014 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 2015 p_nfcipinfo->p_init_pipe_info : 2016 p_nfcipinfo->p_tgt_pipe_info); 2017 if(NULL == p_pipe_info ) 2018 { 2019 status = PHNFCSTVAL(CID_NFC_HCI, 2020 NFCSTATUS_INVALID_HCI_INFORMATION); 2021 } 2022 else 2023 { 2024 pipeid = p_pipe_info->pipe.pipe_id ; 2025 p_pipe_info->reg_index = (uint8_t)NXP_NFCIP_PARAM; 2026 2027 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 2028 pipeid, (uint8_t)ANY_GET_PARAMETER); 2029 } 2030 } 2031 return status; 2032 } 2033 2034 NFCSTATUS 2035 phHciNfc_Initiator_Cont_Activate ( 2036 phHciNfc_sContext_t *psHciContext, 2037 void *pHwRef 2038 ) 2039 { 2040 NFCSTATUS status = NFCSTATUS_SUCCESS; 2041 2042 if( (NULL == psHciContext) || (NULL == pHwRef) ) 2043 { 2044 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2045 } 2046 else if(NULL == psHciContext->p_nfcip_info) 2047 { 2048 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2049 } 2050 else 2051 { 2052 phHciNfc_NfcIP_Info_t *p_nfcipinfo = NULL; 2053 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 2054 2055 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2056 psHciContext->p_nfcip_info ; 2057 p_nfcipinfo->nfcip_type = NFCIP_INITIATOR; 2058 psHciContext->host_rf_type = phHal_eNfcIP1_Initiator; 2059 p_pipe_info = p_nfcipinfo->p_init_pipe_info; 2060 if(NULL == p_pipe_info ) 2061 { 2062 status = PHNFCSTVAL(CID_NFC_HCI, 2063 NFCSTATUS_INVALID_HCI_INFORMATION); 2064 } 2065 else 2066 { 2067 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 2068 uint16_t length = HCP_HEADER_LEN; 2069 uint8_t pipeid = 0; 2070 2071 pipeid = p_pipe_info->pipe.pipe_id; 2072 psHciContext->tx_total = 0 ; 2073 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 2074 /* Construct the HCP Frame */ 2075 phHciNfc_Build_HCPFrame(hcp_packet,(uint8_t)HCP_CHAINBIT_DEFAULT, 2076 (uint8_t) pipeid, (uint8_t)HCP_MSG_TYPE_COMMAND, 2077 (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION); 2078 2079 p_pipe_info->sent_msg_type = (uint8_t)HCP_MSG_TYPE_COMMAND; 2080 p_pipe_info->prev_msg = (uint8_t)NXP_NFCI_CONTINUE_ACTIVATION; 2081 psHciContext->tx_total = length; 2082 psHciContext->response_pending = (uint8_t)TRUE; 2083 2084 /* Send the Constructed HCP packet to the lower layer */ 2085 status = phHciNfc_Send_HCP( psHciContext, pHwRef); 2086 p_pipe_info->prev_status = status; 2087 } 2088 } 2089 return status; 2090 } 2091 2092 2093 NFCSTATUS 2094 phHciNfc_NfcIP_GetATRInfo ( 2095 phHciNfc_sContext_t *psHciContext, 2096 void *pHwRef, 2097 phHciNfc_eNfcIPType_t nfciptype 2098 ) 2099 { 2100 NFCSTATUS status = NFCSTATUS_SUCCESS; 2101 2102 if( (NULL == psHciContext) 2103 || (NULL == pHwRef)) 2104 { 2105 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2106 } 2107 else if (NFCIP_INVALID == nfciptype) 2108 { 2109 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 2110 } 2111 else if(NULL == psHciContext->p_nfcip_info) 2112 { 2113 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2114 } 2115 else 2116 { 2117 phHciNfc_NfcIP_Info_t *p_nfcipinfo=NULL; 2118 phHciNfc_Pipe_Info_t *p_pipe_info=NULL; 2119 uint8_t pipeid = 0; 2120 2121 p_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2122 psHciContext->p_nfcip_info ; 2123 2124 p_pipe_info = ((NFCIP_INITIATOR == nfciptype)? 2125 p_nfcipinfo->p_init_pipe_info : 2126 p_nfcipinfo->p_tgt_pipe_info); 2127 2128 if(NULL == p_pipe_info ) 2129 { 2130 status = PHNFCSTVAL(CID_NFC_HCI, 2131 NFCSTATUS_INVALID_HCI_INFORMATION); 2132 } 2133 else 2134 { 2135 p_pipe_info->reg_index = (uint8_t)((NFCIP_INITIATOR == nfciptype)? 2136 NXP_NFCIP_ATR_RES : 2137 NXP_NFCIP_ATR_REQ); 2138 pipeid = p_pipe_info->pipe.pipe_id ; 2139 /* Fill the data buffer and send the command to the 2140 device */ 2141 status = 2142 phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 2143 pipeid, (uint8_t)ANY_GET_PARAMETER); 2144 } 2145 } 2146 return status; 2147 } 2148 2149 NFCSTATUS 2150 phHciNfc_NfcIP_SetMergeSak( 2151 phHciNfc_sContext_t *psHciContext, 2152 void *pHwRef, 2153 uint8_t sak_value 2154 ) 2155 { 2156 NFCSTATUS status = NFCSTATUS_SUCCESS; 2157 2158 if( (NULL == psHciContext) || (NULL == pHwRef) || 2159 (sak_value > (uint8_t)TRUE)) 2160 { 2161 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2162 } 2163 else if(NULL == psHciContext->p_nfcip_info) 2164 { 2165 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 2166 } 2167 else 2168 { 2169 phHciNfc_NfcIP_Info_t *ps_nfcipinfo=NULL; 2170 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 2171 uint8_t pipeid = 0; 2172 2173 ps_nfcipinfo = (phHciNfc_NfcIP_Info_t *) 2174 psHciContext->p_nfcip_info ; 2175 ps_pipe_info = ps_nfcipinfo->p_tgt_pipe_info; 2176 2177 if(NULL == ps_pipe_info ) 2178 { 2179 status = PHNFCSTVAL(CID_NFC_HCI, 2180 NFCSTATUS_INVALID_HCI_INFORMATION); 2181 } 2182 else 2183 { 2184 pipeid = ps_pipe_info->pipe.pipe_id ; 2185 ps_pipe_info->reg_index = (uint8_t)NXP_NFCIP_MERGE; 2186 2187 ps_pipe_info->param_info = &sak_value; 2188 ps_pipe_info->param_length = sizeof(uint8_t); 2189 status = phHciNfc_Send_Generic_Cmd( psHciContext, pHwRef, 2190 pipeid, (uint8_t)ANY_SET_PARAMETER); 2191 } 2192 } 2193 return status; 2194 } 2195 2196 #endif /* #if defined (ENABLE_P2P) */ 2197 2198