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 * * 22 * \file phHciNfc_Sequence.c * 23 * \brief State Machine Implementation for the HCI Management and * 24 * and the Function Sequence for a particular State * 25 * * 26 * * 27 * Project: NFC-FRI-1.1 * 28 * * 29 * $Date: Tue Jun 8 09:33:46 2010 $ * 30 * $Author: ing04880 $ * 31 * $Revision: 1.85 $ * 32 * $Aliases: NFC_FRI1.1_WK1023_R35_1 $ 33 * * 34 * =========================================================================== * 35 */ 36 37 /* 38 ################################################################################ 39 ***************************** Header File Inclusion **************************** 40 ################################################################################ 41 */ 42 43 #include <phNfcCompId.h> 44 #include <phNfcConfig.h> 45 #include <phHciNfc.h> 46 #include <phHciNfc_Sequence.h> 47 #include <phHciNfc_AdminMgmt.h> 48 #include <phHciNfc_IDMgmt.h> 49 #include <phHciNfc_LinkMgmt.h> 50 #include <phHciNfc_DevMgmt.h> 51 #include <phHciNfc_PollingLoop.h> 52 #include <phHciNfc_RFReader.h> 53 #include <phHciNfc_RFReaderA.h> 54 #include <phHciNfc_Emulation.h> 55 #ifdef ENABLE_P2P 56 #include <phHciNfc_NfcIPMgmt.h> 57 #endif 58 #include <phHciNfc_SWP.h> 59 #include <phHciNfc_WI.h> 60 #include <phOsalNfc.h> 61 62 /* 63 ################################################################################ 64 ****************************** Macro Definitions ******************************* 65 ################################################################################ 66 */ 67 68 /* 69 ################################################################################ 70 ********************** Structure/Enumeration Definitions *********************** 71 ################################################################################ 72 */ 73 74 75 #ifdef VALIDATE_FSM 76 77 typedef struct phHciNfc_sFsm 78 { 79 phHciNfc_eState_t from_state; 80 phHciNfc_eState_t to_state; 81 uint8_t valid; 82 }phHciNfc_sFsm_t; 83 84 static phHciNfc_sFsm_t phHciNfc_Valid_Fsm[] = { 85 {hciState_Reset, hciState_Initialise , TRUE}, 86 /* {hciState_Reset, hciState_Config, FALSE}, */ 87 {hciState_Initialise, hciState_Config, TRUE}, 88 {hciState_Initialise, hciState_Release, TRUE}, 89 {hciState_Config, hciState_Connect, TRUE}, 90 {hciState_Config, hciState_Release, TRUE}, 91 {hciState_Connect, hciState_Activate, TRUE}, 92 {hciState_Connect, hciState_Transact, TRUE}, 93 {hciState_Connect, hciState_Disconnect, TRUE}, 94 {hciState_Disconnect, hciState_Config, TRUE}, 95 /* {hciState_Disconnect, hciState_Release, TRUE}, */ 96 {hciState_Reset, hciState_Initialise, TRUE}, 97 }; 98 99 #endif 100 101 102 /* 103 ################################################################################ 104 ************************* Function Prototype Declaration *********************** 105 ################################################################################ 106 */ 107 108 109 static 110 NFCSTATUS 111 phHciNfc_Config_Sequence( 112 phHciNfc_sContext_t *psHciContext, 113 void *pHwRef 114 ); 115 116 117 /** 118 * \ingroup grp_hci_nfc 119 * 120 * The phHciNfc_Connect_Sequence function sequence selects the 121 * discovered target for performing the transaction. 122 * 123 * \param[in] psHciContext psHciContext is the context of 124 * the HCI Layer. 125 * \param[in] pHwRef pHwRef is the Information of 126 * the Device Interface Link . 127 * 128 * \retval NFCSTATUS_SUCCESS HCI target selection sequence successful. 129 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 130 * could not be interpreted properly. 131 * \retval Other errors Other related errors 132 * 133 */ 134 135 static 136 NFCSTATUS 137 phHciNfc_Transact_Sequence( 138 phHciNfc_sContext_t *psHciContext, 139 void *pHwRef 140 ); 141 142 /** 143 * \ingroup grp_hci_nfc 144 * 145 * The phHciNfc_Info_Sequence function sequence selects the 146 * discovered target for performing the transaction. 147 * 148 * \param[in] psHciContext psHciContext is the context of 149 * the HCI Layer. 150 * \param[in] pHwRef pHwRef is the Information of 151 * the Device Interface Link . 152 * 153 * \retval NFCSTATUS_SUCCESS HCI target selection sequence successful. 154 * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters 155 * could not be interpreted properly. 156 * \retval Other errors Other related errors 157 * 158 */ 159 160 static 161 NFCSTATUS 162 phHciNfc_Info_Sequence( 163 phHciNfc_sContext_t *psHciContext, 164 void *pHwRef 165 ); 166 167 static 168 NFCSTATUS 169 phHciNfc_Test_Sequence( 170 phHciNfc_sContext_t *psHciContext, 171 void *pHwRef, 172 NFCSTATUS test_status, 173 uint8_t *pdata, 174 uint8_t length 175 ); 176 177 #ifdef HCI_FSM_RESET 178 179 static 180 void 181 phHciNfc_FSM_Reset( 182 phHciNfc_sContext_t *psHciContext 183 ); 184 185 #endif 186 187 static 188 NFCSTATUS 189 phHciNfc_IO_Sequence( 190 phHciNfc_sContext_t *psHciContext, 191 void *pHwRef, 192 NFCSTATUS test_status, 193 uint8_t *pdata, 194 uint8_t length 195 ); 196 197 static 198 NFCSTATUS 199 phHciNfc_Pending_Sequence( 200 phHciNfc_sContext_t *psHciContext, 201 void *pHwRef 202 ); 203 204 205 /* 206 ################################################################################ 207 ***************************** Function Definitions ***************************** 208 ################################################################################ 209 */ 210 211 NFCSTATUS 212 phHciNfc_FSM_Validate( 213 phHciNfc_sContext_t *psHciContext, 214 phHciNfc_eState_t state, 215 uint8_t validate_type 216 ) 217 { 218 NFCSTATUS status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 219 phHciNfc_eState_t cur_state = (phHciNfc_eState_t) 220 psHciContext->hci_state.cur_state; 221 222 switch(validate_type) 223 { 224 case NFC_FSM_CURRENT: 225 { 226 if( cur_state == (uint8_t) state ) 227 { 228 status = NFCSTATUS_SUCCESS; 229 } 230 break; 231 } 232 case NFC_FSM_NEXT: 233 { 234 phHciNfc_eState_t next_state = state; 235 switch (cur_state) 236 { 237 case hciState_Reset: 238 { 239 switch(next_state) 240 { 241 /* Specifies the Starting of the init Sequence */ 242 case hciState_Initialise: 243 /* Initialise to Perform Test on 244 the Antenna/SWP Link */ 245 case hciState_Test: 246 status = NFCSTATUS_SUCCESS; 247 break; 248 default: 249 break; 250 } 251 break; 252 } 253 case hciState_Initialise: 254 { 255 switch(next_state) 256 { 257 /* Discovery Resume after connect failure */ 258 case hciState_Initialise: 259 /* Configuring the Discovery/Emulation */ 260 case hciState_Config: 261 /* Configuring the Memory */ 262 case hciState_IO: 263 /* Occurence of the Tag Discovered Event */ 264 case hciState_Select: 265 /* Occurence of the Target Activated Event */ 266 case hciState_Listen: 267 /* Specifies the Starting of the Release Sequence */ 268 case hciState_Release: 269 status = NFCSTATUS_SUCCESS; 270 break; 271 default: 272 break; 273 } 274 break; 275 } 276 case hciState_Test: 277 { 278 if ((hciState_Test == next_state ) 279 || (hciState_IO == next_state) 280 || (hciState_Release == next_state)) 281 { 282 /* Next Test/Reset Sequence */ 283 status = NFCSTATUS_SUCCESS; 284 } 285 break; 286 } 287 case hciState_Select: 288 { 289 switch(next_state) 290 { 291 /* Restart the Wheel */ 292 case hciState_Initialise: 293 /* Select the next Tag in the Field or 294 * already Selected Tag Again 295 */ 296 /* Configuring the Memory */ 297 case hciState_IO: 298 case hciState_Select: 299 /* Configuring the Discovery/Emulation */ 300 case hciState_Config: 301 /* Re-Activate the Target or 302 * Discover the next target 303 */ 304 case hciState_Reactivate: 305 /* Connect the Discovered Target */ 306 case hciState_Connect: 307 /* Specifies the Starting of the Release Sequence */ 308 case hciState_Release: 309 status = NFCSTATUS_SUCCESS; 310 break; 311 default: 312 break; 313 } 314 break; 315 } 316 case hciState_Connect: 317 { 318 switch(next_state) 319 { 320 /* Disabling the Tag Discovery */ 321 case hciState_Initialise: 322 /* Configuring the Discovery/Emulation */ 323 /* This should not be allowed if the target 324 * is connected. 325 */ 326 /* Configuring the Memory */ 327 case hciState_IO: 328 case hciState_Config: 329 /* Re-Activate the Target or 330 * Discover the next target 331 */ 332 case hciState_Reactivate: 333 /* Intermediate Transceive State */ 334 case hciState_Transact: 335 /* Intermediate Presence Check State */ 336 case hciState_Presence: 337 /* Disconnect the Target Connected */ 338 case hciState_Disconnect: 339 /* Specifies the Starting of the Release Sequence */ 340 case hciState_Release: 341 status = NFCSTATUS_SUCCESS; 342 break; 343 default: 344 break; 345 } 346 break; 347 } 348 case hciState_Listen: 349 { 350 switch(next_state) 351 { 352 /* Releasing from the Emulation/Target Mode */ 353 case hciState_Initialise: 354 /* Occurence of the Tag Discovered Event 355 * after the Disconnect Operation 356 */ 357 case hciState_Select: 358 /* Configuring the Memory */ 359 case hciState_IO: 360 /* Configuring the Discovery/Emulation */ 361 case hciState_Config: 362 /* Intermediate Transceive State */ 363 case hciState_Transact: 364 /* Specifies the Starting of the Release Sequence */ 365 case hciState_Release: 366 status = NFCSTATUS_SUCCESS; 367 break; 368 default: 369 break; 370 } 371 break; 372 } 373 case hciState_Reactivate: 374 { 375 switch(next_state) 376 { 377 /* Restart/Discovery after the Target is removed 378 * after Reactivation. 379 */ 380 /* case hciState_Initialise: */ 381 /* Re-Connect the Re-Activated Target */ 382 case hciState_Connect: 383 /* Configuring the Memory */ 384 case hciState_IO: 385 /* Configuring the Discovery/Emulation */ 386 case hciState_Config: 387 /* Specifies the Starting of the Release Sequence */ 388 case hciState_Release: 389 status = NFCSTATUS_SUCCESS; 390 break; 391 default: 392 break; 393 } 394 break; 395 } 396 case hciState_Disconnect: 397 { 398 switch(next_state) 399 { 400 /* Discovery Resume after connect failure 401 after the disconnect */ 402 case hciState_Initialise: 403 /* Configuring the Memory */ 404 case hciState_IO: 405 /* Configuring the Discovery/Emulation */ 406 case hciState_Config: 407 /* Occurence of the Tag Discovered Event 408 * after the Disconnect Operation 409 */ 410 case hciState_Select: 411 /* Occurence of the Target Activated Event */ 412 case hciState_Listen: 413 /* Specifies the Starting of the Release Sequence */ 414 case hciState_Release: 415 status = NFCSTATUS_SUCCESS; 416 break; 417 default: 418 break; 419 } 420 break; 421 } 422 #ifdef USE_M5 423 case hciState_Presence: 424 case hciState_Transact: 425 case hciState_Release: 426 { 427 break; 428 } 429 #endif 430 /* case phHciNfc_Unknown: */ 431 default: 432 { 433 /* status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); */ 434 break; 435 } 436 } /* End of State Validation Switch */ 437 if( NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition ) 438 { 439 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 440 } 441 break; 442 } 443 default: 444 { 445 HCI_DEBUG("State Validate Type:%x is Unknown/Incorrect \n", 446 validate_type); 447 break; 448 } 449 } 450 return status; 451 } 452 453 NFCSTATUS 454 phHciNfc_FSM_Update( 455 phHciNfc_sContext_t *psHciContext, 456 phHciNfc_eState_t next_state 457 ) 458 { 459 NFCSTATUS status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 460 461 HCI_DEBUG(" HCI: Current State --> %02u \n", 462 psHciContext->hci_state.cur_state ); 463 HCI_DEBUG(" HCI: Transition Before FSM Update --> %02u \n", 464 psHciContext->hci_state.transition ); 465 HCI_DEBUG(" HCI: Next State Before FSM Update --> %02u \n", 466 psHciContext->hci_state.next_state ); 467 468 status = phHciNfc_FSM_Validate(psHciContext, next_state, NFC_FSM_NEXT ); 469 if(NFCSTATUS_SUCCESS == status) 470 { 471 psHciContext->hci_state.next_state = (uint8_t) next_state; 472 psHciContext->hci_state.transition = NFC_FSM_IN_PROGRESS; 473 psHciContext->response_pending = FALSE; 474 HCI_DEBUG(" HCI: Next State After FSM Update --> %02u \n", 475 psHciContext->hci_state.next_state ); 476 } 477 else 478 { 479 HCI_DEBUG(" HCI: FSM - Invalid next state --> %02u \n", 480 next_state ); 481 } 482 483 return status; 484 } 485 486 487 NFCSTATUS 488 phHciNfc_FSM_Complete( 489 phHciNfc_sContext_t *psHciContext 490 ) 491 { 492 NFCSTATUS status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 493 494 HCI_DEBUG("HCI: In Function: %s \n", __FUNCTION__); 495 496 HCI_DEBUG(" HCI: Transition Before FSM Complete --> %02u \n", 497 psHciContext->hci_state.transition ); 498 499 HCI_DEBUG(" HCI: Current State Before FSM Complete --> %02u \n", 500 psHciContext->hci_state.cur_state ); 501 502 HCI_DEBUG(" HCI: Next State Before FSM Complete --> %02u \n", 503 psHciContext->hci_state.next_state ); 504 505 if( (NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition) 506 ) 507 { 508 psHciContext->hci_state.cur_state = 509 psHciContext->hci_state.next_state ; 510 psHciContext->hci_state.transition = NFC_FSM_COMPLETE ; 511 psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ; 512 /* Reset the HCI Sequence */ 513 psHciContext->response_pending = FALSE; 514 psHciContext->hci_seq = HCI_INVALID_SEQ; 515 status = NFCSTATUS_SUCCESS; 516 } 517 518 HCI_DEBUG(" HCI: Current State After FSM Complete --> %02u \n", 519 psHciContext->hci_state.cur_state ); 520 521 return status; 522 } 523 524 void 525 phHciNfc_FSM_Rollback( 526 phHciNfc_sContext_t *psHciContext 527 ) 528 { 529 530 HCI_DEBUG("HCI: In Function: %s \n", __FUNCTION__); 531 532 HCI_DEBUG(" HCI: Transition Before FSM Rollback --> %02u \n", 533 psHciContext->hci_state.transition ); 534 535 HCI_DEBUG(" HCI: Current State Before FSM Rollback --> %02u \n", 536 psHciContext->hci_state.cur_state ); 537 538 HCI_DEBUG(" HCI: Next State Before FSM Rollback --> %02u \n", 539 psHciContext->hci_state.next_state ); 540 541 if( (NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition) 542 ) 543 { 544 psHciContext->hci_state.transition = NFC_FSM_COMPLETE ; 545 psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ; 546 /* Reset the HCI Sequence */ 547 psHciContext->hci_seq = HCI_INVALID_SEQ; 548 psHciContext->response_pending = FALSE; 549 } 550 } 551 552 #ifdef HCI_FSM_RESET 553 static 554 void 555 phHciNfc_FSM_Reset( 556 phHciNfc_sContext_t *psHciContext 557 ) 558 { 559 560 if( (hciState_Reset != psHciContext->hci_state.cur_state ) 561 ) 562 { 563 psHciContext->hci_state.cur_state = (uint8_t) hciState_Initialise ; 564 psHciContext->hci_state.transition = NFC_FSM_COMPLETE ; 565 psHciContext->hci_state.next_state = (uint8_t) hciState_Unknown ; 566 /* Reset the HCI Sequence */ 567 psHciContext->hci_seq = HCI_INVALID_SEQ; 568 } 569 570 } 571 #endif 572 573 574 575 static 576 NFCSTATUS 577 phHciNfc_Pending_Sequence( 578 phHciNfc_sContext_t *psHciContext, 579 void *pHwRef 580 ) 581 { 582 NFCSTATUS status = NFCSTATUS_SUCCESS; 583 584 PHNFC_UNUSED_VARIABLE(status); 585 586 HCI_DEBUG("HCI: psHciContext->target_release --> %s \n", 587 (psHciContext->target_release)?"TRUE":"FALSE"); 588 if(TRUE == psHciContext->target_release) 589 { 590 #ifdef SW_RELEASE_TARGET 591 status = phHciNfc_ReaderMgmt_Deselect( 592 psHciContext, pHwRef, phHal_eISO14443_A_PICC, TRUE); 593 if(NFCSTATUS_PENDING == status ) 594 { 595 psHciContext->target_release = FALSE ; 596 } 597 } 598 else 599 { 600 status = psHciContext->error_status; 601 #else 602 psHciContext->target_release = FALSE ; 603 #endif 604 } 605 606 return status; 607 } 608 609 610 void 611 phHciNfc_Error_Sequence( 612 void *psContext, 613 void *pHwRef, 614 NFCSTATUS error_status, 615 void *pdata, 616 uint8_t length 617 ) 618 { 619 NFCSTATUS status = NFCSTATUS_SUCCESS; 620 phHciNfc_sContext_t *psHciContext = (phHciNfc_sContext_t *)psContext; 621 622 PHNFC_UNUSED_VARIABLE(status); 623 624 HCI_DEBUG("HCI: In Function: %s \n", 625 __FUNCTION__); 626 627 HCI_DEBUG ("HCI : Error Status : %04X\n", error_status); 628 629 HCI_DEBUG(" HCI: Current HCI State --> %02u \n", 630 psHciContext->hci_state.cur_state ); 631 HCI_DEBUG(" HCI: Next HCI State --> %02u \n", 632 psHciContext->hci_state.next_state ); 633 634 635 if ( NFC_FSM_IN_PROGRESS == psHciContext->hci_state.transition ) 636 { 637 switch(psHciContext->hci_state.next_state) 638 { 639 case hciState_Initialise: 640 { 641 if (hciState_Reset == psHciContext->hci_state.cur_state) 642 { 643 phNfc_sCompletionInfo_t comp_info; 644 645 phHciNfc_Release_Lower( psHciContext, pHwRef ); 646 /* Release all the resources and 647 * Notify the Receive Error Scenario to the Upper Layer 648 */ 649 comp_info.status = error_status ; 650 phHciNfc_Release_Notify (psHciContext, pHwRef, 651 NFC_NOTIFY_INIT_FAILED, &comp_info); 652 } 653 else if (hciState_Config == psHciContext->hci_state.cur_state) 654 { 655 /* Notify the Poll/Emulation Configure failure to the upper layer */ 656 657 phNfc_sCompletionInfo_t comp_info; 658 659 comp_info.status = error_status ; 660 661 psHciContext->error_status = error_status; 662 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 663 /* Rollback the FSM as the Poll/Emulation configuration Failed */ 664 phHciNfc_FSM_Rollback(psHciContext); 665 psHciContext->error_status = NFCSTATUS_SUCCESS; 666 phHciNfc_Notify(psHciContext->p_upper_notify, 667 psHciContext->p_upper_context, pHwRef, 668 NFC_NOTIFY_CONFIG_ERROR, &comp_info); 669 } 670 else 671 { 672 673 /* Notify the Poll Configure failure to the upper layer */ 674 phNfc_sCompletionInfo_t comp_info; 675 676 psHciContext->error_status = error_status; 677 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 678 /* Rollback the FSM as the Poll Disable Failed */ 679 phHciNfc_FSM_Rollback(psHciContext); 680 comp_info.status = error_status ; 681 psHciContext->error_status = NFCSTATUS_SUCCESS; 682 phHciNfc_Notify(psHciContext->p_upper_notify, 683 psHciContext->p_upper_context, pHwRef, 684 NFC_NOTIFY_ERROR, &comp_info); 685 } 686 break; 687 } 688 case hciState_Test: 689 { 690 status = phHciNfc_Test_Sequence( psHciContext, pHwRef , error_status, 691 (uint8_t *)pdata, length ); 692 break; 693 } 694 case hciState_IO: 695 { 696 status = phHciNfc_IO_Sequence( psHciContext, pHwRef , error_status, 697 (uint8_t *)pdata, length ); 698 break; 699 } 700 case hciState_Config: 701 { 702 /* Notify the Configure failure to the upper layer */ 703 phNfc_sCompletionInfo_t comp_info; 704 705 psHciContext->error_status = error_status; 706 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 707 /* Rollback the FSM as the Poll Failed */ 708 phHciNfc_FSM_Rollback(psHciContext); 709 comp_info.status = psHciContext->error_status ; 710 psHciContext->error_status = NFCSTATUS_SUCCESS; 711 phHciNfc_Notify(psHciContext->p_upper_notify, 712 psHciContext->p_upper_context, pHwRef, 713 NFC_NOTIFY_CONFIG_ERROR, &comp_info); 714 break; 715 } 716 case hciState_Select: 717 { 718 /* Notify the Configure failure to the upper layer */ 719 phNfc_sCompletionInfo_t comp_info={FALSE}; 720 721 /* Rollback the FSM as the Target Discovery Failed */ 722 phHciNfc_FSM_Rollback(psHciContext); 723 status = phHciNfc_ReaderMgmt_Update_Sequence( 724 psHciContext, INFO_SEQ ); 725 comp_info.status = error_status ; 726 phHciNfc_Notify(psHciContext->p_upper_notify, 727 psHciContext->p_upper_context, pHwRef, 728 NFC_NOTIFY_DISCOVERY_ERROR, &comp_info); 729 730 #if 0 731 /* Polling Wheel will be restarted by the upper layer 732 * to Rediscover again */ 733 if(NFCSTATUS_SUCCESS == status) 734 { 735 status = phHciNfc_ReaderMgmt_Deselect( 736 psHciContext, pHwRef, phHal_eISO14443_A_PICC, FALSE); 737 } 738 phHciNfc_FSM_Rollback(psHciContext); 739 #endif 740 break; 741 } 742 case hciState_Transact: 743 /* Notify the Transceive failure to the upper layer */ 744 { 745 phNfc_sTransactionInfo_t transact_info; 746 747 /* Rollback the FSM as the Transceive Failed */ 748 phHciNfc_FSM_Rollback(psHciContext); 749 transact_info.status = error_status; 750 transact_info.buffer = NULL; 751 transact_info.length = FALSE; 752 psHciContext->p_xchg_info = NULL ; 753 phHciNfc_Notify(psHciContext->p_upper_notify, 754 psHciContext->p_upper_context, pHwRef, 755 NFC_NOTIFY_TRANSCEIVE_ERROR, &transact_info); 756 break; 757 758 } 759 case hciState_Connect: 760 { 761 /* Notify the General failure to the upper layer */ 762 phNfc_sCompletionInfo_t comp_info; 763 764 /* psHciContext->host_rf_type = phHal_eUnknown_DevType; */ 765 status = phHciNfc_ReaderMgmt_Update_Sequence( 766 psHciContext, INFO_SEQ ); 767 psHciContext->p_target_info = NULL; 768 psHciContext->hci_state.cur_state = hciState_Select; 769 phHciNfc_FSM_Rollback(psHciContext); 770 comp_info.status = error_status ; 771 phHciNfc_Notify(psHciContext->p_upper_notify, 772 psHciContext->p_upper_context, pHwRef, 773 NFC_NOTIFY_CONNECT_FAILED, &comp_info); 774 break; 775 } 776 case hciState_Reactivate: 777 { 778 /* Notify the General failure to the upper layer */ 779 phNfc_sCompletionInfo_t comp_info={FALSE}; 780 781 /* psHciContext->host_rf_type = phHal_eUnknown_DevType; 782 status = phHciNfc_ReaderMgmt_Update_Sequence( 783 psHciContext, INFO_SEQ ); 784 psHciContext->p_target_info = NULL; 785 psHciContext->hci_state.cur_state = hciState_Select; */ 786 phHciNfc_FSM_Rollback(psHciContext); 787 comp_info.status = error_status ; 788 phHciNfc_Notify(psHciContext->p_upper_notify, 789 psHciContext->p_upper_context, pHwRef, 790 NFC_NOTIFY_CONNECT_FAILED, &comp_info); 791 break; 792 } 793 case hciState_Presence: 794 { 795 phNfc_sCompletionInfo_t comp_info; 796 797 /* Roll Back to Connect State as Presence Check is Complete */ 798 phHciNfc_FSM_Rollback(psHciContext); 799 800 /* Initialisation Complete Notification to the Upper Layer */ 801 comp_info.status = error_status; 802 phHciNfc_Notify(psHciContext->p_upper_notify, 803 psHciContext->p_upper_context, pHwRef, 804 NFC_NOTIFY_ERROR, &comp_info); 805 HCI_PRINT(" HCI Remote Target Removed from the Field. \n"); 806 break; 807 } 808 /* Notify the Connect or Disconnect failure to the upper layer */ 809 case hciState_Disconnect: 810 { 811 /* Notify the General failure to the upper layer */ 812 phNfc_sCompletionInfo_t comp_info; 813 814 phHciNfc_FSM_Rollback(psHciContext); 815 comp_info.status = error_status ; 816 phHciNfc_Notify(psHciContext->p_upper_notify, 817 psHciContext->p_upper_context, pHwRef, 818 NFC_NOTIFY_DISCONNECT_FAILED, &comp_info); 819 break; 820 } 821 case hciState_Release: 822 { 823 #ifdef NXP_HCI_SHUTDOWN_OVERRIDE 824 status = phHciNfc_Release_Sequence(psHciContext ,pHwRef); 825 #else 826 phNfc_sCompletionInfo_t comp_info; 827 828 phHciNfc_Release_Lower( psHciContext, pHwRef ); 829 /* Release all the resources and 830 * Notify the Receive Error Scenario to the Upper Layer 831 */ 832 comp_info.status = error_status ; 833 phHciNfc_Release_Notify (psHciContext, pHwRef, 834 NFC_NOTIFY_DEINIT_FAILED, &comp_info); 835 #endif 836 break; 837 } 838 default: 839 { 840 /* Notify the General failure to the upper layer */ 841 phNfc_sCompletionInfo_t comp_info; 842 843 phHciNfc_FSM_Rollback(psHciContext); 844 comp_info.status = error_status ; 845 psHciContext->error_status = error_status; 846 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 847 if (NFCSTATUS_PENDING != status) 848 { 849 psHciContext->error_status = NFCSTATUS_SUCCESS; 850 phHciNfc_Notify(psHciContext->p_upper_notify, 851 psHciContext->p_upper_context, pHwRef, 852 NFC_NOTIFY_ERROR, &comp_info); 853 } 854 break; 855 } 856 857 } /* End of the Processing of HCI State*/ 858 } 859 else 860 { 861 /* Notify the General failure to the upper layer */ 862 phNfc_sCompletionInfo_t comp_info; 863 864 phHciNfc_FSM_Rollback(psHciContext); 865 comp_info.status = error_status ; 866 /* Disable the Notification to the Upper Layer */ 867 if(NFCSTATUS_BOARD_COMMUNICATION_ERROR 868 == PHNFCSTATUS(error_status)) 869 { 870 phHciNfc_Notify(psHciContext->p_upper_notify, 871 psHciContext->p_upper_context, pHwRef, 872 NFC_NOTIFY_ERROR, &comp_info); 873 } 874 else 875 { 876 psHciContext->error_status = error_status; 877 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 878 if (NFCSTATUS_PENDING != status) 879 { 880 psHciContext->error_status = NFCSTATUS_SUCCESS; 881 } 882 } 883 } 884 return; 885 } 886 887 888 889 NFCSTATUS 890 phHciNfc_Resume_Sequence( 891 phHciNfc_sContext_t *psHciContext, 892 void *pHwRef 893 ) 894 { 895 NFCSTATUS status = NFCSTATUS_SUCCESS; 896 897 HCI_DEBUG("HCI: In Function: %s \n", 898 __FUNCTION__); 899 900 HCI_DEBUG(" HCI: Current HCI State --> %02u \n", 901 psHciContext->hci_state.cur_state ); 902 HCI_DEBUG(" HCI: Next HCI State --> %02u \n", 903 psHciContext->hci_state.next_state ); 904 905 switch(psHciContext->hci_state.next_state) 906 { 907 /* Process the Admin Gate Response based on the HCI State */ 908 case hciState_Initialise: 909 { 910 switch (psHciContext->hci_state.cur_state) 911 { 912 /* Initialise State after Power on */ 913 case hciState_Reset: 914 { 915 status = phHciNfc_Initialise_Sequence(psHciContext ,pHwRef); 916 break; 917 } 918 /* Initialise State after Power on */ 919 case hciState_Config: 920 { 921 status = phHciNfc_Config_Sequence(psHciContext ,pHwRef); 922 break; 923 } 924 /* Discovery Resume after connect failure */ 925 case hciState_Initialise: 926 case hciState_Select: 927 case hciState_Connect: 928 { 929 phNfc_sCompletionInfo_t comp_info; 930 931 /* Update to the Intialise state as the discovery wheel is 932 * restarted. 933 */ 934 status = phHciNfc_FSM_Complete(psHciContext); 935 936 psHciContext->host_rf_type = phHal_eUnknown_DevType; 937 psHciContext->p_target_info = NULL; 938 psHciContext->p_xchg_info = NULL; 939 940 /* Initialisation Complete Notification to the Upper Layer */ 941 comp_info.status = status; 942 phHciNfc_Notify(psHciContext->p_upper_notify, 943 psHciContext->p_upper_context, pHwRef, 944 NFC_NOTIFY_POLL_RESTARTED , &comp_info); 945 HCI_PRINT(" HCI Remote Target Still Present in the Field. \n"); 946 break; 947 } 948 default: 949 { 950 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 951 break; 952 } 953 } 954 break; 955 } 956 case hciState_Release: 957 { 958 status = phHciNfc_Release_Sequence(psHciContext ,pHwRef); 959 break; 960 } 961 case hciState_Config: 962 { 963 status = phHciNfc_Config_Sequence(psHciContext ,pHwRef); 964 break; 965 } 966 case hciState_Listen: 967 case hciState_Select: 968 { 969 status = phHciNfc_Info_Sequence( psHciContext, pHwRef ); 970 break; 971 } 972 case hciState_Reactivate: 973 case hciState_Connect: 974 { 975 status = phHciNfc_Connect_Sequence( psHciContext, pHwRef ); 976 break; 977 } 978 case hciState_Transact: 979 { 980 status = phHciNfc_Transact_Sequence( 981 psHciContext, pHwRef ); 982 break; 983 } 984 case hciState_Presence: 985 { 986 phNfc_sCompletionInfo_t comp_info; 987 988 /* Roll Back to Connect State as Presence Check is Complete */ 989 phHciNfc_FSM_Rollback(psHciContext); 990 991 /* Initialisation Complete Notification to the Upper Layer */ 992 comp_info.status = NFCSTATUS_SUCCESS; 993 phHciNfc_Notify(psHciContext->p_upper_notify, 994 psHciContext->p_upper_context, pHwRef, 995 NFC_NOTIFY_TARGET_PRESENT , &comp_info); 996 HCI_PRINT(" HCI Remote Target Still Present in the Field. \n"); 997 break; 998 } 999 case hciState_Disconnect: 1000 { 1001 status = phHciNfc_Disconnect_Sequence( psHciContext, pHwRef ); 1002 break; 1003 } 1004 case hciState_Test: 1005 { 1006 status = phHciNfc_Test_Sequence( psHciContext, pHwRef , status, NULL, 0 ); 1007 break; 1008 } 1009 case hciState_IO: 1010 { 1011 status = phHciNfc_IO_Sequence( psHciContext, pHwRef , status, NULL, 0 ); 1012 break; 1013 } 1014 case hciState_Unknown: 1015 { 1016 break; 1017 } 1018 default: 1019 { 1020 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_STATE); 1021 break; 1022 } 1023 } /* End of the Processing of HCI State*/ 1024 1025 return status; 1026 } 1027 1028 1029 NFCSTATUS 1030 phHciNfc_Initialise_Sequence( 1031 phHciNfc_sContext_t *psHciContext, 1032 void *pHwRef 1033 ) 1034 { 1035 NFCSTATUS status = NFCSTATUS_SUCCESS; 1036 static uint8_t config = 0; 1037 1038 PHNFC_UNUSED_VARIABLE(config); 1039 1040 switch(psHciContext->hci_seq) 1041 { 1042 case ADMIN_INIT_SEQ: 1043 { 1044 status = phHciNfc_Admin_Initialise( psHciContext,pHwRef ); 1045 if(NFCSTATUS_SUCCESS == status) 1046 { 1047 #ifdef ESTABLISH_SESSION 1048 if( hciMode_Session == psHciContext->hci_mode) 1049 { 1050 /* TODO: Initialise Link Management 1051 Gate Resources */ 1052 NFCSTATUS info_status = NFCSTATUS_SUCCESS; 1053 PHNFC_UNUSED_VARIABLE(info_status); 1054 info_status = phHciNfc_IDMgmt_Update_Sequence( 1055 psHciContext, INFO_SEQ ); 1056 1057 if(NFCSTATUS_SUCCESS == info_status) 1058 { 1059 psHciContext->hci_seq = PL_STOP_SEQ; 1060 } 1061 else 1062 { 1063 psHciContext->hci_seq = HCI_END_SEQ; 1064 status = PHNFCSTVAL(CID_NFC_HCI, 1065 NFCSTATUS_INVALID_HCI_SEQUENCE); 1066 } 1067 } 1068 else 1069 #endif 1070 { 1071 psHciContext->hci_seq = LINK_MGMT_INIT_SEQ; 1072 } 1073 } 1074 break; 1075 } 1076 case LINK_MGMT_INIT_SEQ: 1077 { 1078 status = phHciNfc_LinkMgmt_Initialise( psHciContext,pHwRef ); 1079 if(NFCSTATUS_SUCCESS == status) 1080 { 1081 psHciContext->hci_seq = IDENTITY_INIT_SEQ; 1082 } 1083 break; 1084 } 1085 case IDENTITY_INIT_SEQ: 1086 { 1087 status = phHciNfc_IDMgmt_Initialise( psHciContext,pHwRef ); 1088 if(NFCSTATUS_SUCCESS == status) 1089 { 1090 psHciContext->hci_seq = DEV_INIT_SEQ; 1091 } 1092 break; 1093 } 1094 case DEV_INIT_SEQ: 1095 { 1096 status = phHciNfc_DevMgmt_Initialise( psHciContext,pHwRef ); 1097 if(NFCSTATUS_SUCCESS == status) 1098 { 1099 if (HCI_SELF_TEST != psHciContext->init_mode) 1100 { 1101 psHciContext->hci_seq = PL_INIT_SEQ; 1102 } 1103 else 1104 { 1105 #ifdef ESTABLISH_SESSION 1106 NFCSTATUS info_status = NFCSTATUS_SUCCESS; 1107 PHNFC_UNUSED_VARIABLE(info_status); 1108 info_status = phHciNfc_IDMgmt_Update_Sequence( 1109 psHciContext, INFO_SEQ ); 1110 1111 if(NFCSTATUS_SUCCESS == info_status) 1112 { 1113 psHciContext->hci_seq = IDENTITY_INFO_SEQ; 1114 } 1115 else 1116 { 1117 psHciContext->hci_seq = HCI_END_SEQ; 1118 status = PHNFCSTVAL(CID_NFC_HCI, 1119 NFCSTATUS_INVALID_HCI_SEQUENCE); 1120 } 1121 #else 1122 psHciContext->hci_seq = HCI_END_SEQ; 1123 1124 #endif 1125 } 1126 1127 } 1128 break; 1129 } 1130 case PL_INIT_SEQ: 1131 { 1132 status = phHciNfc_PollLoop_Initialise( psHciContext,pHwRef ); 1133 if(NFCSTATUS_SUCCESS == status) 1134 { 1135 NFCSTATUS reset_status = NFCSTATUS_SUCCESS; 1136 PHNFC_UNUSED_VARIABLE(reset_status); 1137 reset_status = phHciNfc_ReaderMgmt_Update_Sequence( 1138 psHciContext, RESET_SEQ ); 1139 psHciContext->hci_seq = READER_MGMT_INIT_SEQ; 1140 } 1141 break; 1142 } 1143 case READER_MGMT_INIT_SEQ: 1144 { 1145 status = phHciNfc_ReaderMgmt_Initialise( psHciContext,pHwRef ); 1146 if(NFCSTATUS_SUCCESS == status) 1147 { 1148 NFCSTATUS reset_status = NFCSTATUS_SUCCESS; 1149 PHNFC_UNUSED_VARIABLE(reset_status); 1150 reset_status = phHciNfc_EmuMgmt_Update_Seq( 1151 psHciContext, RESET_SEQ ); 1152 psHciContext->hci_seq = EMULATION_INIT_SEQ; 1153 } 1154 break; 1155 } 1156 case EMULATION_INIT_SEQ: 1157 { 1158 status = phHciNfc_EmuMgmt_Initialise( psHciContext,pHwRef ); 1159 if(NFCSTATUS_SUCCESS == status) 1160 { 1161 #ifdef ESTABLISH_SESSION 1162 psHciContext->hci_seq = ADMIN_SESSION_SEQ; 1163 #else 1164 psHciContext->hci_seq = HCI_END_SEQ; 1165 #endif 1166 } 1167 break; 1168 } 1169 #ifdef ESTABLISH_SESSION 1170 case ADMIN_SESSION_SEQ: 1171 { 1172 status = phHciNfc_Admin_Initialise( psHciContext,pHwRef ); 1173 if(NFCSTATUS_SUCCESS == status) 1174 { 1175 psHciContext->hci_seq = IDENTITY_INFO_SEQ; 1176 } 1177 break; 1178 } 1179 case PL_STOP_SEQ: 1180 { 1181 status = phHciNfc_ReaderMgmt_Disable_Discovery( 1182 psHciContext, pHwRef ); 1183 if(NFCSTATUS_SUCCESS == status) 1184 { 1185 #ifdef SW_AUTO_ACTIVATION 1186 psHciContext->hci_seq = READER_SW_AUTO_SEQ; 1187 #else 1188 psHciContext->hci_seq = IDENTITY_INFO_SEQ; 1189 #endif 1190 } 1191 break; 1192 } 1193 #ifdef SW_AUTO_ACTIVATION 1194 case READER_SW_AUTO_SEQ: 1195 { 1196 uint8_t activate_enable = FALSE; 1197 uint8_t rdr_enable = TRUE; 1198 1199 status = phHciNfc_ReaderA_Update_Info( 1200 psHciContext, HCI_READER_A_ENABLE, 1201 &rdr_enable); 1202 if(status == NFCSTATUS_SUCCESS) 1203 { 1204 status = phHciNfc_ReaderA_Auto_Activate( psHciContext, 1205 pHwRef, activate_enable ); 1206 if(status == NFCSTATUS_SUCCESS) 1207 { 1208 psHciContext->hci_seq = IDENTITY_INFO_SEQ; 1209 } 1210 } 1211 break; 1212 } 1213 #endif 1214 /* fall through */ 1215 case IDENTITY_INFO_SEQ: 1216 { 1217 status = phHciNfc_IDMgmt_Info_Sequence( psHciContext,pHwRef ); 1218 if(NFCSTATUS_SUCCESS == status) 1219 { 1220 if ((HCI_SELF_TEST != psHciContext->init_mode) 1221 /* && ( TRUE == ((phHal_sHwReference_t *)pHwRef)->se_detect ) */ 1222 && (HCI_CUSTOM_INIT != psHciContext->init_mode)) 1223 { 1224 NFCSTATUS info_status = NFCSTATUS_SUCCESS; 1225 PHNFC_UNUSED_VARIABLE(info_status); 1226 info_status = phHciNfc_EmuMgmt_Update_Seq( 1227 psHciContext, INFO_SEQ ); 1228 1229 if(NFCSTATUS_SUCCESS == info_status) 1230 { 1231 psHciContext->hci_seq = EMULATION_SWP_SEQ; 1232 } 1233 } 1234 else 1235 { 1236 psHciContext->hci_seq = HCI_END_SEQ; 1237 } 1238 } 1239 break; 1240 } 1241 case EMULATION_SWP_SEQ: 1242 { 1243 status = phHciNfc_EmuMgmt_Initialise( psHciContext,pHwRef ); 1244 if(NFCSTATUS_SUCCESS == status) 1245 { 1246 psHciContext->hci_seq = HCI_END_SEQ; 1247 } 1248 break; 1249 } 1250 #endif 1251 case HCI_END_SEQ: 1252 { 1253 if (HCI_SELF_TEST == psHciContext->init_mode ) 1254 { 1255 psHciContext->hci_state.next_state 1256 = (uint8_t) hciState_Test; 1257 } 1258 status = phHciNfc_FSM_Complete ( psHciContext ); 1259 #ifdef UICC_CONNECTIVITY_PATCH 1260 phHciNfc_Uicc_Connectivity( psHciContext, pHwRef ); 1261 #endif /* #ifdef UICC_CONNECTIVITY_PATCH */ 1262 1263 /* Initialisation Complete Notification to the Upper Layer */ 1264 if(NFCSTATUS_SUCCESS == status) 1265 { 1266 phNfc_sCompletionInfo_t comp_info; 1267 1268 comp_info.status = status; 1269 phHciNfc_Notify(psHciContext->p_upper_notify, 1270 psHciContext->p_upper_context, pHwRef, 1271 NFC_NOTIFY_INIT_COMPLETED, &comp_info); 1272 HCI_PRINT("HCI Initialisation Completed \n"); 1273 } 1274 else 1275 { 1276 pphNfcIF_Notification_CB_t p_upper_notify = psHciContext->p_upper_notify; 1277 void *pcontext = psHciContext->p_upper_context; 1278 phNfc_sCompletionInfo_t comp_info; 1279 1280 1281 phHciNfc_Release_Lower( psHciContext, pHwRef ); 1282 phHciNfc_Release_Resources( &psHciContext ); 1283 /* Notify the Failure to the Upper Layer */ 1284 comp_info.status = status; 1285 phHciNfc_Notify( p_upper_notify, pcontext, pHwRef, 1286 NFC_NOTIFY_INIT_FAILED, &comp_info); 1287 HCI_PRINT("HCI FSM Initialisation Error \n"); 1288 } 1289 break; 1290 } 1291 default: 1292 break; 1293 } 1294 1295 return status; 1296 } 1297 1298 1299 NFCSTATUS 1300 phHciNfc_Release_Sequence( 1301 phHciNfc_sContext_t *psHciContext, 1302 void *pHwRef 1303 ) 1304 { 1305 NFCSTATUS status = NFCSTATUS_SUCCESS; 1306 1307 switch(psHciContext->hci_seq) 1308 { 1309 case PL_STOP_SEQ: 1310 { 1311 status = phHciNfc_ReaderMgmt_Disable_Discovery( 1312 psHciContext, pHwRef ); 1313 if(NFCSTATUS_SUCCESS == status) 1314 { 1315 (void)phHciNfc_EmuMgmt_Update_Seq( 1316 psHciContext, REL_SEQ ); 1317 psHciContext->hci_seq = EMULATION_REL_SEQ; 1318 status = NFCSTATUS_PENDING; 1319 } 1320 break; 1321 } 1322 case EMULATION_REL_SEQ: 1323 { 1324 status = phHciNfc_EmuMgmt_Release( psHciContext,pHwRef ); 1325 if(NFCSTATUS_SUCCESS == status) 1326 { 1327 (void)phHciNfc_DevMgmt_Update_Sequence( 1328 psHciContext, REL_SEQ ); 1329 psHciContext->hci_seq = ADMIN_REL_SEQ; 1330 status = NFCSTATUS_PENDING; 1331 } 1332 break; 1333 } 1334 case DEV_REL_SEQ: 1335 { 1336 status = phHciNfc_DevMgmt_Release( psHciContext, pHwRef ); 1337 if(NFCSTATUS_SUCCESS == status) 1338 { 1339 psHciContext->hci_seq = HCI_END_SEQ; 1340 status = NFCSTATUS_PENDING; 1341 } 1342 break; 1343 } 1344 case READER_MGMT_REL_SEQ: 1345 { 1346 status = phHciNfc_ReaderMgmt_Release( psHciContext,pHwRef ); 1347 if(NFCSTATUS_SUCCESS == status) 1348 { 1349 psHciContext->hci_seq = PL_REL_SEQ; 1350 status = NFCSTATUS_PENDING; 1351 } 1352 break; 1353 } 1354 case PL_REL_SEQ: 1355 { 1356 status = phHciNfc_PollLoop_Release( psHciContext,pHwRef ); 1357 if(NFCSTATUS_SUCCESS == status) 1358 { 1359 psHciContext->hci_seq = IDENTITY_REL_SEQ; 1360 status = NFCSTATUS_PENDING; 1361 } 1362 break; 1363 } 1364 case IDENTITY_REL_SEQ: 1365 { 1366 status = phHciNfc_IDMgmt_Release( psHciContext,pHwRef ); 1367 if(NFCSTATUS_SUCCESS == status) 1368 { 1369 psHciContext->hci_seq = LINK_MGMT_REL_SEQ; 1370 status = NFCSTATUS_PENDING; 1371 } 1372 break; 1373 } 1374 case LINK_MGMT_REL_SEQ: 1375 { 1376 status = phHciNfc_LinkMgmt_Release( psHciContext,pHwRef ); 1377 if(NFCSTATUS_SUCCESS == status) 1378 { 1379 psHciContext->hci_seq = ADMIN_REL_SEQ; 1380 status = NFCSTATUS_PENDING; 1381 } 1382 break; 1383 } 1384 case ADMIN_REL_SEQ: 1385 { 1386 /* Admin Management Release Sequence */ 1387 status = phHciNfc_Admin_Release( psHciContext,pHwRef, phHciNfc_TerminalHostID ); 1388 if(NFCSTATUS_SUCCESS == status) 1389 { 1390 psHciContext->hci_seq = DEV_REL_SEQ; 1391 status = NFCSTATUS_PENDING; 1392 } 1393 break; 1394 } 1395 case HCI_END_SEQ: 1396 { 1397 pphNfcIF_Notification_CB_t p_upper_notify = 1398 psHciContext->p_upper_notify; 1399 phNfc_sLowerIF_t *plower_if = 1400 &(psHciContext->lower_interface); 1401 void *pcontext = 1402 psHciContext->p_upper_context; 1403 phNfc_sCompletionInfo_t comp_info; 1404 1405 1406 status = plower_if->release((void *)plower_if->pcontext, 1407 (void *)pHwRef); 1408 1409 phHciNfc_Release_Resources( &psHciContext ); 1410 /* De-Initialisation Complete Notification to the Upper Layer */ 1411 comp_info.status = status; 1412 phHciNfc_Notify(p_upper_notify, pcontext, pHwRef, 1413 NFC_NOTIFY_DEINIT_COMPLETED, &comp_info); 1414 1415 HCI_PRINT("HCI Release Completed \n"); 1416 break; 1417 } 1418 default: 1419 { 1420 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1421 break; 1422 } 1423 } 1424 1425 return status; 1426 } 1427 1428 1429 static 1430 NFCSTATUS 1431 phHciNfc_Config_Sequence( 1432 phHciNfc_sContext_t *psHciContext, 1433 void *pHwRef 1434 ) 1435 { 1436 NFCSTATUS status = NFCSTATUS_SUCCESS; 1437 phNfc_sCompletionInfo_t comp_info; 1438 1439 switch(psHciContext->config_type) 1440 { 1441 case POLL_LOOP_CFG: 1442 { 1443 status = phHciNfc_PollLoop_Sequence( psHciContext, pHwRef ); 1444 break; 1445 } 1446 case SMX_WI_MODE: 1447 { 1448 status = phHciNfc_SmartMx_Mode_Sequence( psHciContext, pHwRef ); 1449 break; 1450 } 1451 #ifdef ENABLE_P2P 1452 case NFC_GENERAL_CFG: 1453 { 1454 if(TARGET_GENERAL_SEQ == psHciContext->hci_seq) 1455 { 1456 status = phHciNfc_NfcIP_SetATRInfo( psHciContext, 1457 pHwRef, NFCIP_TARGET, 1458 psHciContext->p_config_params); 1459 if( NFCSTATUS_PENDING != status ) 1460 { 1461 /* Roll Back the State Machine to its Original State */ 1462 phHciNfc_FSM_Rollback ( psHciContext ); 1463 } 1464 else 1465 { 1466 psHciContext->hci_seq = HCI_END_SEQ; 1467 } 1468 } 1469 else 1470 { 1471 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 1472 if (NFCSTATUS_PENDING != status) 1473 { 1474 /* Roll Back to its Current State as Configuration is Complete */ 1475 phHciNfc_FSM_Rollback(psHciContext); 1476 1477 HCI_PRINT(" NFC-IP(P2P) Configuration Completed. \n"); 1478 comp_info.status = status; 1479 psHciContext->error_status = NFCSTATUS_SUCCESS; 1480 phHciNfc_Notify(psHciContext->p_upper_notify, 1481 psHciContext->p_upper_context, pHwRef, 1482 NFC_NOTIFY_CONFIG_SUCCESS , &comp_info); 1483 } 1484 } 1485 break; 1486 } 1487 #endif 1488 case SWP_PROTECT_CFG: 1489 case SWP_EVT_CFG: 1490 case SMX_WI_CFG: 1491 { 1492 /* Roll Back to its Current State as Configuration is Complete */ 1493 phHciNfc_FSM_Rollback(psHciContext); 1494 1495 HCI_DEBUG(" %s Configuration Completed. \n", 1496 ((SMX_WI_CFG == psHciContext->config_type)? 1497 "SmartMX" : "SWP Event/Protection")); 1498 1499 comp_info.status = status; 1500 phHciNfc_Notify(psHciContext->p_upper_notify, 1501 psHciContext->p_upper_context, pHwRef, 1502 NFC_NOTIFY_CONFIG_SUCCESS, &comp_info); 1503 break; 1504 } 1505 case NFC_TARGET_CFG: 1506 { 1507 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1508 break; 1509 } 1510 case UICC_SWP_CFG: 1511 #if 0 1512 { 1513 phHal_sEmulationCfg_t *p_emulation_cfg = 1514 (phHal_sEmulationCfg_t * ) 1515 psHciContext->p_config_params; 1516 if (NULL != p_emulation_cfg) 1517 { 1518 phHal_sUiccEmuCfg_t *uicc_config = 1519 &p_emulation_cfg->config.uiccEmuCfg; 1520 if( TRUE == uicc_config->enableUicc ) 1521 { 1522 status = phHciNfc_Uicc_Connect_Status(psHciContext,pHwRef); 1523 if( NFCSTATUS_PENDING == status ) 1524 { 1525 break; 1526 } /* Or Else Fall through to notify the above layer */ 1527 } 1528 } 1529 } 1530 #endif 1531 /* fall through */ 1532 case NFC_CE_A_CFG: 1533 case NFC_CE_B_CFG: 1534 { 1535 status = phHciNfc_EmulationCfg_Sequence( psHciContext, pHwRef ); 1536 break; 1537 } 1538 default: 1539 { 1540 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE); 1541 break; 1542 } 1543 } 1544 1545 return status; 1546 } 1547 1548 1549 NFCSTATUS 1550 phHciNfc_PollLoop_Sequence( 1551 phHciNfc_sContext_t *psHciContext, 1552 void *pHwRef 1553 ) 1554 { 1555 NFCSTATUS status = NFCSTATUS_SUCCESS; 1556 phHal_sADD_Cfg_t *p_poll_config = (phHal_sADD_Cfg_t * ) 1557 psHciContext->p_config_params; 1558 if (NULL != p_poll_config) 1559 { 1560 uint8_t speed = 1561 p_poll_config->NfcIP_Mode; 1562 switch(psHciContext->hci_seq) 1563 { 1564 case PL_DURATION_SEQ: 1565 { 1566 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef, 1567 (uint8_t)PL_DURATION , NULL); 1568 if(NFCSTATUS_SUCCESS == status) 1569 { 1570 #if defined (ENABLE_P2P) && defined (TARGET_SPEED) 1571 psHciContext->hci_seq = TARGET_SPEED_SEQ; 1572 #elif defined (ENABLE_P2P) && defined (INITIATOR_SPEED) 1573 psHciContext->hci_seq = INITIATOR_SPEED_SEQ; 1574 #elif defined (ENABLE_P2P) && defined (NFCIP_TGT_DISABLE_CFG) 1575 psHciContext->hci_seq = PL_TGT_DISABLE_SEQ; 1576 #else 1577 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1578 #endif 1579 1580 status = NFCSTATUS_PENDING; 1581 } 1582 break; 1583 } 1584 #if defined (ENABLE_P2P) && defined (TARGET_SPEED) 1585 case TARGET_SPEED_SEQ: 1586 { 1587 #define NFCIP_ACTIVE_SHIFT 0x03U 1588 #define NFCIP_PASSIVE_MASK 0x07U 1589 uint8_t mode = ( NXP_NFCIP_ACTIVE_DEFAULT << NFCIP_ACTIVE_SHIFT ) | 1590 ( DEFAULT_NFCIP_MODE_SUPPORT & NFCIP_PASSIVE_MASK ); 1591 status = 1592 phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_TARGET, 1593 (uint8_t) mode ); 1594 if(NFCSTATUS_PENDING == status) 1595 { 1596 #if defined (INITIATOR_SPEED) 1597 psHciContext->hci_seq = INITIATOR_SPEED_SEQ; 1598 #elif defined (NFCIP_TGT_DISABLE_CFG) 1599 psHciContext->hci_seq = PL_TGT_DISABLE_SEQ; 1600 #else 1601 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1602 #endif 1603 status = NFCSTATUS_PENDING; 1604 } 1605 break; 1606 } 1607 #endif 1608 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED) 1609 case INITIATOR_SPEED_SEQ: 1610 { 1611 status = 1612 phHciNfc_NfcIP_SetMode( psHciContext, pHwRef, NFCIP_INITIATOR, 1613 (uint8_t) (speed & DEFAULT_NFCIP_MODE_SUPPORT)); 1614 if(NFCSTATUS_PENDING == status) 1615 { 1616 #if defined (NFCIP_TGT_DISABLE_CFG) 1617 psHciContext->hci_seq = PL_TGT_DISABLE_SEQ; 1618 #else 1619 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1620 #endif 1621 status = NFCSTATUS_PENDING; 1622 } 1623 break; 1624 } 1625 #endif 1626 #if defined (ENABLE_P2P) && defined (NFCIP_TGT_DISABLE_CFG) 1627 case PL_TGT_DISABLE_SEQ: 1628 { 1629 /* Configure the Polling Loop Target Disable Parameter */ 1630 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef, 1631 (uint8_t)PL_DISABLE_TARGET, &p_poll_config->NfcIP_Tgt_Disable ); 1632 if(NFCSTATUS_SUCCESS == status) 1633 { 1634 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1635 status = NFCSTATUS_PENDING; 1636 } 1637 break; 1638 } 1639 #endif 1640 case PL_CONFIG_PHASE_SEQ: 1641 { 1642 phHal_sPollDevInfo_t *p_poll_info = 1643 &(p_poll_config->PollDevInfo.PollCfgInfo); 1644 1645 p_poll_info->EnableIso14443A = 1646 ( (p_poll_info->EnableIso14443A) 1647 || ( speed & (uint8_t)phHal_ePassive106 ) 1648 ); 1649 p_poll_info->EnableFelica212 = 1650 ( (p_poll_info->EnableFelica212) 1651 || ( speed & (uint8_t)phHal_ePassive212 ) 1652 ); 1653 p_poll_info->EnableFelica424 = 1654 ( (p_poll_info->EnableFelica424) 1655 || ( speed & (uint8_t)phHal_ePassive424 ) 1656 ); 1657 /* Configure the Polling Loop Gate Parameters */ 1658 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef, 1659 (uint8_t)PL_RD_PHASES, NULL ); 1660 if(NFCSTATUS_SUCCESS == status) 1661 { 1662 if(((~(PL_RD_PHASES_DISABLE)) & 1663 p_poll_config->PollDevInfo.PollEnabled)!= 0) 1664 { 1665 psHciContext->hci_seq = READER_ENABLE_SEQ; 1666 } 1667 else 1668 { 1669 /* psHciContext->hci_seq = READER_DISABLE_SEQ; */ 1670 psHciContext->hci_seq = HCI_END_SEQ; 1671 } 1672 status = NFCSTATUS_PENDING; 1673 } 1674 break; 1675 } 1676 case READER_ENABLE_SEQ: 1677 { 1678 status = 1679 phHciNfc_ReaderMgmt_Enable_Discovery( 1680 psHciContext, pHwRef ); 1681 if(NFCSTATUS_SUCCESS == status) 1682 { 1683 /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */ 1684 psHciContext->hci_seq = HCI_END_SEQ; 1685 status = NFCSTATUS_PENDING; 1686 } 1687 break; 1688 } 1689 case READER_DISABLE_SEQ: 1690 { 1691 status = phHciNfc_ReaderMgmt_Disable_Discovery( 1692 psHciContext, pHwRef ); 1693 1694 if(NFCSTATUS_SUCCESS == status) 1695 { 1696 if((~(PL_RD_PHASES_DISABLE) & 1697 p_poll_config->PollDevInfo.PollEnabled)!= 0) 1698 { 1699 psHciContext->hci_seq = PL_DURATION_SEQ; 1700 } 1701 else 1702 { 1703 #if defined (ENABLE_P2P) && defined (INITIATOR_SPEED) 1704 psHciContext->hci_seq = INITIATOR_SPEED_SEQ; 1705 #elif defined (ENABLE_P2P) && defined (NFCIP_TGT_DISABLE_CFG) 1706 psHciContext->hci_seq = PL_TGT_DISABLE_SEQ; 1707 #else 1708 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1709 #endif 1710 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1711 } 1712 status = NFCSTATUS_PENDING; 1713 } 1714 break; 1715 } 1716 case HCI_END_SEQ: 1717 { 1718 phNfc_sCompletionInfo_t comp_info; 1719 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 1720 if (NFCSTATUS_PENDING != status) 1721 { 1722 /* status = phHciNfc_FSM_Complete ( psHciContext );*/ 1723 phHciNfc_FSM_Rollback ( psHciContext ); 1724 /* Poll Configuration Notification to the Upper Layer */ 1725 if((~(PL_RD_PHASES_DISABLE) & 1726 p_poll_config->PollDevInfo.PollEnabled)!= 0) 1727 { 1728 comp_info.status = status; 1729 phHciNfc_Notify(psHciContext->p_upper_notify, 1730 psHciContext->p_upper_context, pHwRef, 1731 NFC_NOTIFY_POLL_ENABLED, &comp_info); 1732 } 1733 else 1734 { 1735 comp_info.status = status; 1736 phHciNfc_Notify(psHciContext->p_upper_notify, 1737 psHciContext->p_upper_context, pHwRef, 1738 NFC_NOTIFY_POLL_DISABLED, &comp_info); 1739 } 1740 HCI_PRINT("HCI Discovery Configuration Completed \n"); 1741 } 1742 break; 1743 } 1744 default: 1745 { 1746 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1747 break; 1748 } 1749 }/* End of the Poll Sequence Switch */ 1750 }/* End of the Poll Config info Check */ 1751 1752 return status; 1753 } 1754 1755 1756 NFCSTATUS 1757 phHciNfc_EmulationCfg_Sequence( 1758 phHciNfc_sContext_t *psHciContext, 1759 void *pHwRef 1760 ) 1761 { 1762 NFCSTATUS status = NFCSTATUS_SUCCESS; 1763 static phNfc_sCompletionInfo_t comp_info; 1764 #if defined(HOST_EMULATION) 1765 phHciNfc_GateID_t ce_gate = phHciNfc_UnknownGate; 1766 #endif /* #ifdef HOST_EMULATION */ 1767 phHal_sEmulationCfg_t *p_emulation_cfg = (phHal_sEmulationCfg_t * ) 1768 psHciContext->p_config_params; 1769 #ifdef UICC_SESSION_RESET 1770 uint8_t uicc_clear_pipes = FALSE; 1771 #endif 1772 1773 1774 if (NULL != p_emulation_cfg) 1775 { 1776 #if defined(HOST_EMULATION) 1777 if(NFC_HOST_CE_A_EMULATION == p_emulation_cfg->emuType) 1778 { 1779 psHciContext->config_type = NFC_CE_A_CFG; 1780 if (NULL == psHciContext->p_ce_a_info) 1781 { 1782 ce_gate = phHciNfc_CETypeAGate; 1783 } 1784 } 1785 else if (NFC_HOST_CE_B_EMULATION == p_emulation_cfg->emuType) 1786 { 1787 psHciContext->config_type = NFC_CE_B_CFG; 1788 if (NULL == psHciContext->p_ce_b_info) 1789 { 1790 ce_gate = phHciNfc_CETypeBGate; 1791 } 1792 } 1793 #ifdef UICC_SESSION_RESET 1794 else if ((NFC_UICC_EMULATION == p_emulation_cfg->emuType) 1795 &&(FALSE == p_emulation_cfg->config.uiccEmuCfg.enableUicc) 1796 ) 1797 { 1798 uicc_clear_pipes = TRUE; 1799 } 1800 #endif 1801 else 1802 { 1803 ; 1804 } 1805 #endif /* #ifdef HOST_EMULATION */ 1806 1807 switch(psHciContext->hci_seq) 1808 { 1809 #if defined(HOST_EMULATION) 1810 case ADMIN_CE_SEQ: 1811 { 1812 if(phHciNfc_UnknownGate != ce_gate) 1813 { 1814 status = phHciNfc_Admin_CE_Init(psHciContext, pHwRef, ce_gate); 1815 } 1816 else 1817 { 1818 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_NOT_ALLOWED); 1819 } 1820 1821 if(NFCSTATUS_SUCCESS == status) 1822 { 1823 psHciContext->hci_seq = EMULATION_CONFIG_SEQ; 1824 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1825 status = NFCSTATUS_PENDING; 1826 } 1827 break; 1828 } 1829 #endif 1830 case EMULATION_CONFIG_SEQ: 1831 { 1832 status = phHciNfc_Emulation_Cfg(psHciContext, pHwRef, 1833 psHciContext->config_type); 1834 if(NFCSTATUS_SUCCESS == status) 1835 { 1836 /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */ 1837 #ifdef UICC_SESSION_RESET 1838 if(UICC_SWP_CFG == psHciContext->config_type) 1839 { 1840 psHciContext->hci_seq = ADMIN_REL_SEQ; 1841 } 1842 else 1843 #endif /* UICC_SESSION_RESET */ 1844 { 1845 psHciContext->hci_seq = HCI_END_SEQ; 1846 } 1847 status = NFCSTATUS_PENDING; 1848 } 1849 break; 1850 } 1851 #ifdef UICC_SESSION_RESET 1852 case ADMIN_REL_SEQ: 1853 { 1854 if (TRUE == uicc_clear_pipes) 1855 { 1856 /* Admin Management UICC Release Sequence */ 1857 status = phHciNfc_Admin_Release( psHciContext,pHwRef, phHciNfc_UICCHostID ); 1858 if(NFCSTATUS_SUCCESS == status) 1859 { 1860 psHciContext->hci_seq = HCI_END_SEQ; 1861 if (UICC_SWP_CFG == psHciContext->config_type) 1862 { 1863 (void)phHciNfc_SWP_Update_Sequence(psHciContext, 1864 CONFIG_SEQ ); 1865 } 1866 status = NFCSTATUS_PENDING; 1867 } 1868 break; 1869 } 1870 } 1871 #endif /* UICC_SESSION_RESET */ 1872 /* fall through */ 1873 case HCI_END_SEQ: 1874 { 1875 phHciNfc_FSM_Rollback(psHciContext); 1876 1877 HCI_PRINT(" Emulation Configuration Completed. \n"); 1878 1879 comp_info.status = status; 1880 phHciNfc_Notify(psHciContext->p_upper_notify, 1881 psHciContext->p_upper_context, pHwRef, 1882 NFC_NOTIFY_CONFIG_SUCCESS, &comp_info); 1883 break; 1884 } 1885 default: 1886 { 1887 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1888 break; 1889 } 1890 } 1891 /* 1892 NFC_CE_A_CFG; 1893 NFC_CE_B_CFG; */ 1894 1895 }/* End of the Emulation Config info Check */ 1896 1897 return status; 1898 } 1899 1900 1901 NFCSTATUS 1902 phHciNfc_SmartMx_Mode_Sequence( 1903 phHciNfc_sContext_t *psHciContext, 1904 void *pHwRef 1905 ) 1906 { 1907 NFCSTATUS status = NFCSTATUS_SUCCESS; 1908 phHal_sADD_Cfg_t *p_poll_config = (phHal_sADD_Cfg_t * ) 1909 psHciContext->p_config_params; 1910 phNfc_sCompletionInfo_t comp_info; 1911 1912 if (NULL != p_poll_config) 1913 { 1914 switch(psHciContext->hci_seq) 1915 { 1916 case READER_DISABLE_SEQ: 1917 { 1918 status = phHciNfc_ReaderMgmt_Disable_Discovery( 1919 psHciContext, pHwRef ); 1920 if(NFCSTATUS_SUCCESS == status) 1921 { 1922 psHciContext->hci_seq = EMULATION_CONFIG_SEQ; 1923 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1924 status = NFCSTATUS_PENDING; 1925 } 1926 break; 1927 } 1928 case EMULATION_CONFIG_SEQ: 1929 { 1930 status = phHciNfc_WI_Configure_Mode( 1931 psHciContext, pHwRef,psHciContext->smx_mode ); 1932 if(NFCSTATUS_SUCCESS == status) 1933 { 1934 psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; 1935 /* psHciContext->hci_seq = HCI_END_SEQ; */ 1936 status = NFCSTATUS_PENDING; 1937 } 1938 break; 1939 } 1940 case PL_CONFIG_PHASE_SEQ: 1941 { 1942 /* Configure the Polling Loop Gate Parameters */ 1943 status = phHciNfc_PollLoop_Cfg( psHciContext, pHwRef, 1944 (uint8_t)PL_RD_PHASES, NULL ); 1945 if(NFCSTATUS_SUCCESS == status) 1946 { 1947 psHciContext->hci_seq = READER_ENABLE_SEQ; 1948 status = NFCSTATUS_PENDING; 1949 } 1950 break; 1951 } 1952 case READER_ENABLE_SEQ: 1953 { 1954 status = 1955 phHciNfc_ReaderMgmt_Enable_Discovery( 1956 psHciContext, pHwRef ); 1957 if(NFCSTATUS_SUCCESS == status) 1958 { 1959 /* psHciContext->hci_seq = PL_CONFIG_PHASE_SEQ; */ 1960 psHciContext->hci_seq = HCI_END_SEQ; 1961 status = NFCSTATUS_PENDING; 1962 } 1963 break; 1964 } 1965 case HCI_END_SEQ: 1966 { 1967 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 1968 if (NFCSTATUS_PENDING != status) 1969 { 1970 /* status = phHciNfc_FSM_Complete ( psHciContext );*/ 1971 phHciNfc_FSM_Rollback ( psHciContext ); 1972 if( hciState_Disconnect == psHciContext->hci_state.cur_state) 1973 { 1974 psHciContext->host_rf_type = phHal_eUnknown_DevType; 1975 psHciContext->p_target_info = NULL; 1976 psHciContext->p_xchg_info = NULL; 1977 } 1978 /* Poll Configuration Notification to the Upper Layer */ 1979 if((~(PL_RD_PHASES_DISABLE) & 1980 p_poll_config->PollDevInfo.PollEnabled)!= 0) 1981 { 1982 comp_info.status = status; 1983 phHciNfc_Notify(psHciContext->p_upper_notify, 1984 psHciContext->p_upper_context, pHwRef, 1985 NFC_NOTIFY_POLL_ENABLED, &comp_info); 1986 } 1987 else 1988 { 1989 comp_info.status = status; 1990 phHciNfc_Notify(psHciContext->p_upper_notify, 1991 psHciContext->p_upper_context, pHwRef, 1992 NFC_NOTIFY_POLL_DISABLED, &comp_info); 1993 } 1994 HCI_PRINT("HCI Discovery Configuration Completed \n"); 1995 } 1996 break; 1997 } 1998 default: 1999 { 2000 /* psHciContext->hci_seq = HCI_END_SEQ; */ 2001 break; 2002 } 2003 }/* End of the Poll Sequence Switch */ 2004 }/* End of the Poll Config info Check */ 2005 2006 return status; 2007 } 2008 2009 2010 NFCSTATUS 2011 phHciNfc_Connect_Sequence( 2012 phHciNfc_sContext_t *psHciContext, 2013 void *pHwRef 2014 ) 2015 { 2016 NFCSTATUS status = NFCSTATUS_SUCCESS; 2017 static phNfc_sCompletionInfo_t comp_info; 2018 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; 2019 2020 if( NULL != psHciContext->p_target_info ) 2021 { 2022 2023 target_type = psHciContext->p_target_info->RemDevType; 2024 switch(psHciContext->hci_seq) 2025 { 2026 case READER_REACTIVATE_SEQ: 2027 { 2028 /* Complete the Reactivate Sequence and notify the HAL */ 2029 status = phHciNfc_FSM_Complete ( psHciContext ); 2030 /* Reactivate Complete Notification to the Upper Layer */ 2031 if(NFCSTATUS_SUCCESS == status) 2032 { 2033 comp_info.status = status; 2034 phHciNfc_Notify(psHciContext->p_upper_notify, 2035 psHciContext->p_upper_context, pHwRef, 2036 NFC_NOTIFY_TARGET_REACTIVATED , &comp_info); 2037 HCI_PRINT(" HCI Remote Target Reactivated. \n"); 2038 } 2039 else 2040 { 2041 comp_info.status = status; 2042 phHciNfc_FSM_Rollback ( psHciContext ); 2043 phHciNfc_Notify(psHciContext->p_upper_notify, 2044 psHciContext->p_upper_context, pHwRef, 2045 NFC_NOTIFY_ERROR , &comp_info); 2046 HCI_PRINT("HCI FSM Invalid Selection State \n"); 2047 HCI_PRINT("HCI Remote Target Reactivation Failed \n"); 2048 } 2049 break; 2050 } 2051 case READER_SELECT_SEQ: 2052 { 2053 /* If the Target is Mifare then it should fall through */ 2054 if(( phHal_eMifare_PICC != target_type ) 2055 &&(phHal_eISO14443_3A_PICC != target_type) 2056 #ifdef TYPE_B 2057 && ( phHal_eISO14443_B_PICC != target_type ) 2058 && ( phHal_eISO14443_4B_PICC != target_type ) 2059 #endif 2060 #ifdef TYPE_FELICA 2061 && ( phHal_eFelica_PICC != target_type ) 2062 #endif 2063 #ifdef TYPE_JEWEL 2064 && ( phHal_eJewel_PICC != target_type ) 2065 #endif /* #ifdef TYPE_JEWEL */ 2066 #ifdef TYPE_ISO15693 2067 && ( phHal_eISO15693_PICC != target_type ) 2068 #endif /* #ifdef TYPE_ISO15693 */ 2069 2070 ) 2071 { 2072 status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef ); 2073 if(NFCSTATUS_SUCCESS == status) 2074 { 2075 psHciContext->hci_seq = HCI_END_SEQ; 2076 status = NFCSTATUS_PENDING; 2077 } 2078 break; 2079 } 2080 } 2081 /* fall through */ 2082 case HCI_END_SEQ: 2083 { 2084 /* Complete the Connect Sequence and notify the HAL */ 2085 status = phHciNfc_FSM_Complete ( psHciContext ); 2086 /* Connection Complete Notification to the Upper Layer */ 2087 if(NFCSTATUS_SUCCESS == status) 2088 { 2089 /* Invalidate the previously polled RF Reader Type */ 2090 /* psHciContext->host_rf_type = phHal_eInvalidRFType;*/ 2091 comp_info.status = status; 2092 phHciNfc_Notify(psHciContext->p_upper_notify, 2093 psHciContext->p_upper_context, pHwRef, 2094 NFC_NOTIFY_TARGET_CONNECTED , &comp_info); 2095 HCI_PRINT(" HCI Remote Target Selected for Transaction. \n"); 2096 } 2097 else 2098 { 2099 comp_info.status = status; 2100 /* phHciNfc_FSM_Rollback ( psHciContext ); */ 2101 phHciNfc_Notify(psHciContext->p_upper_notify, 2102 psHciContext->p_upper_context, pHwRef, 2103 NFC_NOTIFY_ERROR , &comp_info); 2104 HCI_PRINT("HCI FSM Invalid Selection State \n"); 2105 HCI_PRINT("HCI Remote Target Selection Failed \n"); 2106 } 2107 break; 2108 } 2109 default: 2110 { 2111 HCI_PRINT("\t Invalid HCI Connect Sequence \n"); 2112 /* psHciContext->hci_seq = HCI_END_SEQ; */ 2113 break; 2114 } 2115 }/* End of the Connect Sequence Switch */ 2116 } 2117 2118 return status; 2119 } 2120 2121 2122 NFCSTATUS 2123 phHciNfc_Disconnect_Sequence( 2124 phHciNfc_sContext_t *psHciContext, 2125 void *pHwRef 2126 ) 2127 { 2128 NFCSTATUS status = NFCSTATUS_SUCCESS; 2129 static phNfc_sCompletionInfo_t comp_info; 2130 phHal_eRemDevType_t target_type = phHal_eUnknown_DevType; 2131 uint8_t re_poll = 0; 2132 2133 if( NULL != psHciContext->p_target_info ) 2134 { 2135 2136 target_type = psHciContext->p_target_info->RemDevType; 2137 switch(psHciContext->hci_seq) 2138 { 2139 case READER_UICC_DISPATCH_SEQ: 2140 { 2141 status = phHciNfc_ReaderMgmt_UICC_Dispatch( 2142 psHciContext, pHwRef, target_type ); 2143 psHciContext->hci_seq = READER_DESELECT_SEQ; 2144 if(NFCSTATUS_PENDING == status) 2145 { 2146 break; 2147 } 2148 } 2149 /* fall through */ 2150 case READER_DESELECT_SEQ: 2151 { 2152 re_poll = (uint8_t) ( NULL != psHciContext->p_config_params )? 2153 *((uint8_t *)psHciContext->p_config_params):FALSE; 2154 status = phHciNfc_ReaderMgmt_Deselect( 2155 psHciContext, pHwRef, target_type, re_poll); 2156 if(NFCSTATUS_PENDING == status) 2157 { 2158 psHciContext->hci_seq = HCI_END_SEQ; 2159 psHciContext->p_config_params = NULL; 2160 } 2161 break; 2162 } 2163 case HCI_END_SEQ: 2164 { 2165 /* Complete the Disconnect Sequence and notify the HAL */ 2166 status = phHciNfc_FSM_Complete ( psHciContext ); 2167 /* Disconnect Notification to the Upper Layer */ 2168 if(NFCSTATUS_SUCCESS == status) 2169 { 2170 /* Invalidate the previously polled RF Reader Type */ 2171 psHciContext->host_rf_type = phHal_eUnknown_DevType; 2172 psHciContext->p_target_info = NULL; 2173 psHciContext->p_xchg_info = NULL; 2174 comp_info.status = status; 2175 phHciNfc_Notify(psHciContext->p_upper_notify, 2176 psHciContext->p_upper_context, pHwRef, 2177 NFC_NOTIFY_TARGET_DISCONNECTED , &comp_info); 2178 HCI_PRINT(" HCI Remote Target De-Selected. \n"); 2179 } 2180 else 2181 { 2182 comp_info.status = status; 2183 /* phHciNfc_FSM_Rollback ( psHciContext ); */ 2184 phHciNfc_Notify(psHciContext->p_upper_notify, 2185 psHciContext->p_upper_context, pHwRef, 2186 NFC_NOTIFY_ERROR , &comp_info); 2187 HCI_PRINT("HCI FSM Invalid De-Selection State \n"); 2188 HCI_PRINT("HCI Remote Target De-Selection Failed \n"); 2189 } 2190 2191 break; 2192 } 2193 default: 2194 { 2195 HCI_PRINT("\t Invalid HCI Connect Sequence \n"); 2196 /* psHciContext->hci_seq = HCI_END_SEQ; */ 2197 break; 2198 } 2199 }/* End of the Connect Sequence Switch */ 2200 } 2201 2202 return status; 2203 } 2204 2205 2206 static 2207 NFCSTATUS 2208 phHciNfc_Transact_Sequence( 2209 phHciNfc_sContext_t *psHciContext, 2210 void *pHwRef 2211 ) 2212 { 2213 static phNfc_sTransactionInfo_t transact_info; 2214 2215 pphNfcIF_Notification_CB_t p_upper_notify = psHciContext->p_upper_notify; 2216 void *pcontext = psHciContext->p_upper_context; 2217 uint8_t transact_result = NFC_NOTIFY_ERROR; 2218 2219 /* Roll Back to Connect State as Transceive is Complete */ 2220 phHciNfc_FSM_Rollback(psHciContext); 2221 2222 switch (psHciContext->host_rf_type) 2223 { 2224 case phHal_eISO14443_A_PCD: 2225 #ifdef TYPE_B 2226 case phHal_eISO14443_B_PCD: 2227 #endif 2228 case phHal_eISO14443_BPrime_PCD: 2229 #ifdef TYPE_FELICA 2230 case phHal_eFelica_PCD: 2231 #endif 2232 #ifdef TYPE_ISO15693 2233 case phHal_eISO15693_PCD: 2234 #endif 2235 { 2236 if(ZERO != psHciContext->rx_index) 2237 { 2238 transact_info.status = NFCSTATUS_SUCCESS; 2239 transact_info.buffer = 2240 &psHciContext->recv_buffer[psHciContext->rx_index]; 2241 transact_info.length = 2242 psHciContext->rx_total - psHciContext->rx_index; 2243 transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED; 2244 } 2245 else 2246 { 2247 transact_info.status = NFCSTATUS_FAILED; 2248 transact_result = NFC_NOTIFY_TRANSCEIVE_ERROR; 2249 } 2250 HCI_PRINT(" HCI Transceive operation Completed. \n"); 2251 psHciContext->p_xchg_info = NULL ; 2252 break; 2253 } 2254 #ifdef TYPE_JEWEL 2255 /* fall through */ 2256 case phHal_eJewel_PCD: 2257 #endif 2258 { 2259 transact_info.status = NFCSTATUS_SUCCESS; 2260 transact_info.buffer = 2261 &psHciContext->recv_buffer[psHciContext->rx_index]; 2262 transact_info.length = 2263 psHciContext->rx_total - psHciContext->rx_index; 2264 transact_result = NFC_NOTIFY_TRANSCEIVE_COMPLETED; 2265 HCI_PRINT(" HCI Transceive operation Completed. \n"); 2266 psHciContext->p_xchg_info = NULL ; 2267 break; 2268 } 2269 #if defined(ENABLE_P2P) 2270 case phHal_eNfcIP1_Initiator: 2271 case phHal_eNfcIP1_Target: 2272 #endif 2273 { 2274 HCI_PRINT(" HCI Send operation Completed. \n"); 2275 transact_info.status = NFCSTATUS_SUCCESS; 2276 transact_result = NFC_NOTIFY_SEND_COMPLETED; 2277 break; 2278 } 2279 case phHal_eUnknown_DevType: 2280 default: 2281 { 2282 transact_info.status = 2283 PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2284 break; 2285 } 2286 2287 } 2288 /* Notify the Transceive Completion to the Upper layer */ 2289 phHciNfc_Notify( p_upper_notify, pcontext , pHwRef, 2290 transact_result, &transact_info); 2291 2292 return (NFCSTATUS)NFCSTATUS_SUCCESS; 2293 } 2294 2295 static 2296 NFCSTATUS 2297 phHciNfc_Info_Sequence( 2298 phHciNfc_sContext_t *psHciContext, 2299 void *pHwRef 2300 ) 2301 { 2302 NFCSTATUS status = NFCSTATUS_SUCCESS; 2303 2304 HCI_DEBUG(" HCI: Info Sequence Entry --> Reader Type : %02X \n", 2305 psHciContext->host_rf_type); 2306 switch (psHciContext->host_rf_type) 2307 { 2308 case phHal_eISO14443_A_PCD: 2309 #ifdef TYPE_B 2310 case phHal_eISO14443_B_PCD: 2311 #endif 2312 case phHal_eISO14443_BPrime_PCD: 2313 #ifdef TYPE_FELICA 2314 case phHal_eFelica_PCD: 2315 #endif 2316 #ifdef TYPE_JEWEL 2317 case phHal_eJewel_PCD: 2318 #endif 2319 #ifdef TYPE_ISO15693 2320 case phHal_eISO15693_PCD: 2321 #endif 2322 { 2323 /* To update the select sequence to retrieve 2324 * the target information using the reader type. 2325 */ 2326 status = phHciNfc_ReaderMgmt_Info_Sequence( psHciContext, pHwRef ); 2327 break; 2328 } 2329 #if defined(ENABLE_P2P) 2330 case phHal_eNfcIP1_Initiator: 2331 case phHal_eNfcIP1_Target: 2332 { 2333 status = phHciNfc_NfcIP_Info_Sequence( psHciContext, pHwRef ); 2334 break; 2335 } 2336 #endif 2337 case phHal_eUnknown_DevType: 2338 default: 2339 { 2340 status = 2341 PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 2342 break; 2343 } 2344 2345 } 2346 return status; 2347 } 2348 2349 static 2350 NFCSTATUS 2351 phHciNfc_Test_Sequence( 2352 phHciNfc_sContext_t *psHciContext, 2353 void *pHwRef, 2354 NFCSTATUS test_status, 2355 uint8_t *pdata, 2356 uint8_t length 2357 ) 2358 { 2359 NFCSTATUS status = NFCSTATUS_SUCCESS; 2360 static phNfc_sCompletionInfo_t comp_info; 2361 static phNfc_sData_t test_result; 2362 2363 /* Complete the Test Sequence and notify the HAL */ 2364 status = phHciNfc_FSM_Complete ( psHciContext ); 2365 /* Test Results to the Upper Layer */ 2366 if(NFCSTATUS_SUCCESS == status) 2367 { 2368 comp_info.status = test_status; 2369 if ( (NULL != pdata) && (length >= HCP_HEADER_LEN) ) 2370 { 2371 test_result.buffer = ( pdata + HCP_HEADER_LEN); 2372 test_result.length = length - HCP_HEADER_LEN; 2373 } 2374 else 2375 { 2376 status = phHciNfc_DevMgmt_Get_Test_Result( 2377 psHciContext, &test_result ); 2378 } 2379 comp_info.info = &test_result; 2380 phHciNfc_Notify(psHciContext->p_upper_notify, 2381 psHciContext->p_upper_context, pHwRef, 2382 NFC_NOTIFY_RESULT , &comp_info); 2383 HCI_PRINT(" HCI System Test Completed. \n"); 2384 } 2385 else 2386 { 2387 comp_info.status = status; 2388 phHciNfc_FSM_Rollback ( psHciContext ); 2389 phHciNfc_Notify(psHciContext->p_upper_notify, 2390 psHciContext->p_upper_context, pHwRef, 2391 NFC_NOTIFY_ERROR , &comp_info); 2392 HCI_PRINT("HCI FSM Invalid Test State \n"); 2393 } 2394 2395 return status; 2396 } 2397 2398 static 2399 NFCSTATUS 2400 phHciNfc_IO_Sequence( 2401 phHciNfc_sContext_t *psHciContext, 2402 void *pHwRef, 2403 NFCSTATUS io_status, 2404 uint8_t *pdata, 2405 uint8_t length 2406 ) 2407 { 2408 NFCSTATUS status = NFCSTATUS_SUCCESS; 2409 static phNfc_sCompletionInfo_t comp_info; 2410 2411 /* To remove "warning (VS 4100) : unreferenced formal parameter" */ 2412 PHNFC_UNUSED_VARIABLE(pdata); 2413 PHNFC_UNUSED_VARIABLE(length); 2414 /* Complete the Test Sequence and notify the HAL */ 2415 phHciNfc_FSM_Rollback ( psHciContext ); 2416 /* Test Results to the Upper Layer */ 2417 comp_info.status = io_status; 2418 status = phHciNfc_Pending_Sequence(psHciContext, pHwRef ); 2419 if(NFCSTATUS_SUCCESS == io_status) 2420 { 2421 phHciNfc_Notify(psHciContext->p_upper_notify, 2422 psHciContext->p_upper_context, pHwRef, 2423 NFC_IO_SUCCESS , &comp_info); 2424 HCI_PRINT(" HCI System IO Successful. \n"); 2425 } 2426 else 2427 { 2428 phHciNfc_Notify(psHciContext->p_upper_notify, 2429 psHciContext->p_upper_context, pHwRef, 2430 NFC_IO_ERROR , &comp_info); 2431 HCI_PRINT("HCI IO Error \n"); 2432 } 2433 return status; 2434 } 2435 2436 2437 2438 #ifdef OTHER_TAGS 2439 2440 NFCSTATUS 2441 phHciNfc_Activate_Sequence( 2442 phHciNfc_sContext_t *psHciContext, 2443 void *pHwRef 2444 ) 2445 { 2446 NFCSTATUS status = NFCSTATUS_SUCCESS; 2447 2448 return status; 2449 } 2450 2451 2452 #endif 2453 2454 2455