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_SWP.c * 22 * \brief HCI SWP gate Management Routines. * 23 * * 24 * * 25 * Project: NFC-FRI-1.1 * 26 * * 27 * $Date: Tue Aug 18 10:16:36 2009 $ * 28 * $Author: ing04880 $ * 29 * $Revision: 1.31 $ * 30 * $Aliases: NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $ * * 31 * =========================================================================== * 32 */ 33 34 /* 35 ***************************** Header File Inclusion **************************** 36 */ 37 #include <phNfcCompId.h> 38 #include <phHciNfc_Pipe.h> 39 #include <phHciNfc_SWP.h> 40 #include <phOsalNfc.h> 41 #include <phHciNfc_Emulation.h> 42 #include <phHciNfc_DevMgmt.h> 43 /* 44 ****************************** Macro Definitions ******************************* 45 */ 46 47 /* SWP Gate regsitry Settings */ 48 /* set default mode mode as virtual mode */ 49 #define NXP_SWP_DEFAULT_MODE_INDEX (0x01U) 50 /* Get the Status of the UICC Connection */ 51 #define NXP_SWP_STATUS_INDEX (0x02U) 52 53 /* Configure the Secure Element Protected Mode */ 54 #define NXP_SWP_PROTECTED_INDEX (0x03U) 55 56 /* Switch mode index */ 57 #define NXP_EVT_SWP_SWITCH_MODE (0x03U) 58 59 /* Protected Event from the Host Controller */ 60 #define NXP_EVT_SWP_PROTECTED (0x04U) 61 62 /****************** Structure and Enumeration ****************************/ 63 64 /****************** Static Function Declaration **************************/ 65 66 static 67 NFCSTATUS 68 phHciNfc_Recv_SWP_Response( 69 void *psContext, 70 void *pHwRef, 71 uint8_t *pResponse, 72 #ifdef ONE_BYTE_LEN 73 uint8_t length 74 #else 75 uint16_t length 76 #endif 77 ); 78 79 static 80 NFCSTATUS 81 phHciNfc_Send_SWP_Event( 82 phHciNfc_sContext_t *psHciContext, 83 void *pHwRef, 84 uint8_t pipe_id, 85 uint8_t event 86 ); 87 88 89 static 90 NFCSTATUS 91 phHciNfc_Recv_SWP_Event( 92 void *psContext, 93 void *pHwRef, 94 uint8_t *pEvent, 95 #ifdef ONE_BYTE_LEN 96 uint8_t length 97 #else 98 uint16_t length 99 #endif 100 ); 101 102 static 103 NFCSTATUS 104 phHciNfc_SWP_InfoUpdate( 105 phHciNfc_sContext_t *psHciContext, 106 uint8_t index, 107 uint8_t *reg_value, 108 uint8_t reg_length 109 ); 110 111 /* 112 *************************** Function Definitions *************************** 113 */ 114 115 NFCSTATUS 116 phHciNfc_SWP_Get_PipeID( 117 phHciNfc_sContext_t *psHciContext, 118 uint8_t *ppipe_id 119 ) 120 { 121 NFCSTATUS status = NFCSTATUS_SUCCESS; 122 123 if( (NULL != psHciContext) 124 && ( NULL != ppipe_id ) 125 && ( NULL != psHciContext->p_swp_info ) 126 ) 127 { 128 phHciNfc_SWP_Info_t *p_swp_info=NULL; 129 p_swp_info = (phHciNfc_SWP_Info_t *) 130 psHciContext->p_swp_info ; 131 *ppipe_id = p_swp_info->pipe_id ; 132 } 133 else 134 { 135 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 136 } 137 return status; 138 } 139 140 NFCSTATUS 141 phHciNfc_SWP_Init_Resources(phHciNfc_sContext_t *psHciContext) 142 { 143 NFCSTATUS status = NFCSTATUS_SUCCESS; 144 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 145 146 if( NULL == psHciContext ) 147 { 148 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 149 } 150 else 151 { 152 if(( NULL == psHciContext->p_swp_info ) && 153 (phHciNfc_Allocate_Resource((void **)(&ps_swp_info), 154 sizeof(phHciNfc_SWP_Info_t))== NFCSTATUS_SUCCESS)) 155 { 156 psHciContext->p_swp_info = ps_swp_info; 157 ps_swp_info->current_seq = SWP_INVALID_SEQUENCE; 158 ps_swp_info->next_seq = SWP_INVALID_SEQUENCE; 159 ps_swp_info->pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID; 160 } 161 else 162 { 163 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES); 164 } 165 166 } 167 return status; 168 } 169 170 171 NFCSTATUS 172 phHciNfc_SWP_Update_PipeInfo( 173 phHciNfc_sContext_t *psHciContext, 174 uint8_t pipeID, 175 phHciNfc_Pipe_Info_t *pPipeInfo 176 ) 177 { 178 NFCSTATUS status = NFCSTATUS_SUCCESS; 179 180 if( NULL == psHciContext ) 181 { 182 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 183 } 184 else if(NULL == psHciContext->p_swp_info) 185 { 186 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 187 } 188 else 189 { 190 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 191 ps_swp_info = (phHciNfc_SWP_Info_t *) 192 psHciContext->p_swp_info ; 193 /* Update the pipe_id of the SWP Gate obtained from HCI Response */ 194 ps_swp_info->pipe_id = pipeID; 195 ps_swp_info->p_pipe_info = pPipeInfo; 196 if (NULL != pPipeInfo) 197 { 198 /* Update the Response Receive routine of the SWP Gate */ 199 pPipeInfo->recv_resp = &phHciNfc_Recv_SWP_Response; 200 pPipeInfo->recv_event =&phHciNfc_Recv_SWP_Event; 201 } 202 } 203 return status; 204 } 205 206 207 static 208 NFCSTATUS 209 phHciNfc_Recv_SWP_Response( 210 void *psContext, 211 void *pHwRef, 212 uint8_t *pResponse, 213 #ifdef ONE_BYTE_LEN 214 uint8_t length 215 #else 216 uint16_t length 217 #endif 218 ) 219 { 220 NFCSTATUS status = NFCSTATUS_SUCCESS; 221 phHciNfc_sContext_t *psHciContext = 222 (phHciNfc_sContext_t *)psContext ; 223 224 225 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pResponse) 226 || (length == 0)) 227 { 228 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 229 } 230 else if(NULL == psHciContext->p_swp_info) 231 { 232 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 233 } 234 else 235 { 236 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 237 uint8_t prev_cmd = ANY_GET_PARAMETER; 238 239 ps_swp_info = (phHciNfc_SWP_Info_t *) 240 psHciContext->p_swp_info ; 241 if( NULL == ps_swp_info->p_pipe_info) 242 { 243 status = PHNFCSTVAL(CID_NFC_HCI, 244 NFCSTATUS_INVALID_HCI_INFORMATION); 245 } 246 else 247 { 248 prev_cmd = ps_swp_info->p_pipe_info->prev_msg ; 249 switch(prev_cmd) 250 { 251 case ANY_GET_PARAMETER: 252 { 253 HCI_PRINT(" Getting the SWP Parameter \n"); 254 status = phHciNfc_SWP_InfoUpdate(psHciContext, 255 ps_swp_info->p_pipe_info->reg_index, 256 &pResponse[HCP_HEADER_LEN], 257 (uint8_t)(length - HCP_HEADER_LEN)); 258 259 break; 260 } 261 case ANY_SET_PARAMETER: 262 { 263 HCI_PRINT("SWP Parameter Set \n"); 264 break; 265 } 266 case ANY_OPEN_PIPE: 267 { 268 HCI_PRINT("SWP gate open pipe complete\n"); 269 break; 270 } 271 case ANY_CLOSE_PIPE: 272 { 273 HCI_PRINT("SWP close pipe complete\n"); 274 break; 275 } 276 default: 277 { 278 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE); 279 break; 280 } 281 } 282 if( NFCSTATUS_SUCCESS == status ) 283 { 284 status = phHciNfc_EmuMgmt_Update_Seq(psHciContext, 285 UPDATE_SEQ); 286 ps_swp_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS; 287 ps_swp_info->current_seq = ps_swp_info->next_seq; 288 } 289 } 290 } 291 return status; 292 } 293 294 295 NFCSTATUS 296 phHciNfc_SWP_Configure_Default( 297 void *psHciHandle, 298 void *pHwRef, 299 uint8_t enable_type 300 ) 301 { 302 NFCSTATUS status = NFCSTATUS_SUCCESS; 303 static uint8_t param = 0 ; 304 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle); 305 306 if((NULL == psHciContext)||(NULL == pHwRef)) 307 { 308 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 309 } 310 else if(NULL == psHciContext->p_swp_info) 311 { 312 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 313 } 314 else 315 { 316 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 317 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 318 319 ps_swp_info = (phHciNfc_SWP_Info_t*)psHciContext->p_swp_info; 320 ps_pipe_info = ps_swp_info->p_pipe_info; 321 322 if(NULL == ps_pipe_info) 323 { 324 status = PHNFCSTVAL(CID_NFC_HCI, 325 NFCSTATUS_INVALID_HCI_INFORMATION); 326 } 327 else 328 { 329 ps_pipe_info->reg_index = NXP_SWP_DEFAULT_MODE_INDEX; 330 /* Enable/Disable SWP link */ 331 param = (uint8_t)enable_type; 332 ps_pipe_info->param_info =(void*)¶m ; 333 ps_pipe_info->param_length = sizeof(param) ; 334 status = phHciNfc_Send_Generic_Cmd(psHciContext, pHwRef, 335 ps_swp_info->pipe_id, 336 (uint8_t)ANY_SET_PARAMETER); 337 } 338 339 } 340 return status; 341 } 342 343 344 NFCSTATUS 345 phHciNfc_SWP_Get_Status( 346 void *psHciHandle, 347 void *pHwRef 348 ) 349 { 350 NFCSTATUS status = NFCSTATUS_SUCCESS; 351 /* static uint8_t param = 0 ; */ 352 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle); 353 354 if((NULL == psHciContext)||(NULL == pHwRef)) 355 { 356 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 357 } 358 else if(NULL == psHciContext->p_swp_info) 359 { 360 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 361 } 362 else 363 { 364 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 365 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 366 367 ps_swp_info = (phHciNfc_SWP_Info_t*)psHciContext->p_swp_info; 368 ps_pipe_info = ps_swp_info->p_pipe_info; 369 370 if(NULL == ps_pipe_info) 371 { 372 status = PHNFCSTVAL(CID_NFC_HCI, 373 NFCSTATUS_INVALID_HCI_INFORMATION); 374 } 375 else 376 { 377 ps_pipe_info->reg_index = NXP_SWP_STATUS_INDEX; 378 status = phHciNfc_Send_Generic_Cmd(psHciContext, pHwRef, 379 ps_swp_info->pipe_id, 380 (uint8_t)ANY_GET_PARAMETER); 381 } 382 } 383 return status; 384 } 385 386 387 NFCSTATUS 388 phHciNfc_SWP_Get_Bitrate( 389 void *psHciHandle, 390 void *pHwRef 391 ) 392 { 393 NFCSTATUS status = NFCSTATUS_SUCCESS; 394 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *) 395 psHciHandle); 396 397 if((NULL == psHciContext) || (NULL == pHwRef)) 398 { 399 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 400 } 401 else if(NULL == psHciContext->p_swp_info) 402 { 403 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 404 } 405 else 406 { 407 phHciNfc_SWP_Info_t *ps_swp_info = NULL; 408 409 ps_swp_info = (phHciNfc_SWP_Info_t*)psHciContext->p_swp_info; 410 411 status = phHciNfc_DevMgmt_Get_Info(psHciContext, pHwRef, 412 NFC_ADDRESS_SWP_BITRATE, &(ps_swp_info->uicc_bitrate)); 413 414 } 415 return status; 416 } 417 418 419 NFCSTATUS 420 phHciNfc_SWP_Protection( 421 void *psHciHandle, 422 void *pHwRef, 423 uint8_t mode 424 ) 425 { 426 NFCSTATUS status = NFCSTATUS_SUCCESS; 427 static uint8_t param = 0 ; 428 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *)psHciHandle); 429 430 if((NULL == psHciContext)||(NULL == pHwRef)) 431 { 432 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 433 } 434 else if(NULL == psHciContext->p_swp_info) 435 { 436 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 437 } 438 else 439 { 440 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 441 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 442 443 ps_swp_info = (phHciNfc_SWP_Info_t*)psHciContext->p_swp_info; 444 ps_pipe_info = ps_swp_info->p_pipe_info; 445 446 if(NULL == ps_pipe_info) 447 { 448 status = PHNFCSTVAL(CID_NFC_HCI, 449 NFCSTATUS_INVALID_HCI_INFORMATION); 450 } 451 else 452 { 453 ps_pipe_info->reg_index = NXP_SWP_PROTECTED_INDEX; 454 /* Enable/Disable SWP Protection */ 455 param = (uint8_t)mode; 456 ps_pipe_info->param_info =(void*)¶m ; 457 ps_pipe_info->param_length = sizeof(param) ; 458 status = phHciNfc_Send_Generic_Cmd(psHciContext, pHwRef, 459 ps_swp_info->pipe_id, 460 (uint8_t)ANY_SET_PARAMETER); 461 } 462 463 } 464 return status; 465 } 466 467 468 469 470 static 471 NFCSTATUS 472 phHciNfc_SWP_InfoUpdate( 473 phHciNfc_sContext_t *psHciContext, 474 uint8_t index, 475 uint8_t *reg_value, 476 uint8_t reg_length 477 ) 478 { 479 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 480 NFCSTATUS status = NFCSTATUS_SUCCESS; 481 482 ps_swp_info = (phHciNfc_SWP_Info_t *) 483 psHciContext->p_swp_info ; 484 485 /* To remove "warning (VS C4100) : unreferenced formal parameter" */ 486 PHNFC_UNUSED_VARIABLE(reg_length); 487 switch(index) 488 { 489 case NXP_SWP_DEFAULT_MODE_INDEX: 490 { 491 HCI_PRINT_BUFFER("\tUICC Enable Register:",reg_value,reg_length); 492 break; 493 } 494 /* Get the Status of the UICC Connection */ 495 case NXP_SWP_STATUS_INDEX: 496 { 497 HCI_PRINT_BUFFER("\tUICC Connection Status:", reg_value, reg_length); 498 ps_swp_info->uicc_status = (phHciNfc_SWP_Status_t ) *reg_value ; 499 break; 500 } 501 case NXP_SWP_PROTECTED_INDEX: 502 { 503 HCI_PRINT_BUFFER("\t UICC Card Emulation Rights :",reg_value,reg_length); 504 505 break; 506 } 507 default: 508 { 509 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 510 break; 511 } 512 } /* End of switch(index) */ 513 514 return status; 515 } 516 517 NFCSTATUS 518 phHciNfc_SWP_Configure_Mode( 519 void *psHciHandle, 520 void *pHwRef, 521 uint8_t uicc_mode 522 ) 523 { 524 NFCSTATUS status = NFCSTATUS_SUCCESS; 525 static uint8_t param = 0; 526 phHciNfc_sContext_t *psHciContext = ((phHciNfc_sContext_t *) 527 psHciHandle); 528 529 if( (NULL == psHciContext)||(NULL == pHwRef)) 530 { 531 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 532 } 533 else if ( NULL == psHciContext->p_swp_info ) 534 { 535 status = PHNFCSTVAL(CID_NFC_HCI, 536 NFCSTATUS_INVALID_HCI_INFORMATION); 537 } 538 else 539 { 540 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 541 phHciNfc_Pipe_Info_t *ps_pipe_info=NULL; 542 543 ps_swp_info = (phHciNfc_SWP_Info_t*)psHciContext->p_swp_info; 544 545 ps_pipe_info = ps_swp_info->p_pipe_info; 546 if(NULL == ps_pipe_info) 547 { 548 status = PHNFCSTVAL(CID_NFC_HCI, 549 NFCSTATUS_INVALID_HCI_INFORMATION); 550 } 551 else 552 { 553 /* Switch the Mode of the SmartMx */ 554 param = uicc_mode; 555 ps_pipe_info->param_info =(void*)¶m ; 556 ps_pipe_info->param_length = sizeof(param) ; 557 status = phHciNfc_Send_SWP_Event( psHciContext, pHwRef, 558 ps_swp_info->pipe_id, 559 NXP_EVT_SWP_SWITCH_MODE ); 560 561 /* Send the Success Status as this is an event */ 562 status = ((status == NFCSTATUS_PENDING)? 563 NFCSTATUS_SUCCESS : status); 564 565 }/* End of else part*/ 566 } 567 return status; 568 } 569 570 static 571 NFCSTATUS 572 phHciNfc_Recv_SWP_Event( 573 void *psContext, 574 void *pHwRef, 575 uint8_t *pEvent, 576 #ifdef ONE_BYTE_LEN 577 uint8_t length 578 #else 579 uint16_t length 580 #endif 581 ) 582 { 583 NFCSTATUS status = NFCSTATUS_SUCCESS; 584 phHciNfc_sContext_t *psHciContext = 585 (phHciNfc_sContext_t *)psContext ; 586 static phHal_sEventInfo_t EventInfo; 587 588 589 if( (NULL == psHciContext) || (NULL == pHwRef) || (NULL == pEvent) 590 || (length == 0)) 591 { 592 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 593 } 594 else if(NULL == psHciContext->p_swp_info) 595 { 596 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 597 } 598 else 599 { 600 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 601 602 ps_swp_info = (phHciNfc_SWP_Info_t *) 603 psHciContext->p_swp_info ; 604 if( NULL == ps_swp_info->p_pipe_info) 605 { 606 status = PHNFCSTVAL(CID_NFC_HCI, 607 NFCSTATUS_INVALID_HCI_INFORMATION); 608 } 609 else 610 { 611 phHciNfc_HCP_Packet_t *p_packet = NULL; 612 phHciNfc_HCP_Message_t *message = NULL; 613 uint8_t EventType = 0; 614 615 p_packet = (phHciNfc_HCP_Packet_t *)pEvent; 616 message = &(p_packet->msg.message); 617 /* Get the instruction bits from the Message Header */ 618 EventType = (uint8_t) GET_BITS8( message->msg_header, 619 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN); 620 621 EventInfo.eventHost = phHal_eHostController; 622 EventInfo.eventSource = phHal_ePICC_DevType; 623 /* Occurrence of the Protected events for reporting */ 624 if (NXP_EVT_SWP_PROTECTED == EventType) 625 { 626 EventInfo.eventType = NFC_EVT_PROTECTED; 627 } 628 else 629 { 630 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_RESPONSE); 631 } 632 633 if (NFCSTATUS_SUCCESS == status ) 634 { 635 phHciNfc_Notify_Event( psHciContext, pHwRef, 636 NFC_NOTIFY_EVENT, (void*)&EventInfo); 637 } 638 639 } 640 } 641 return status; 642 } 643 644 645 646 static 647 NFCSTATUS 648 phHciNfc_Send_SWP_Event( 649 phHciNfc_sContext_t *psHciContext, 650 void *pHwRef, 651 uint8_t pipe_id, 652 uint8_t event 653 ) 654 { 655 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 656 phHciNfc_HCP_Message_t *hcp_message = NULL; 657 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 658 uint8_t length = 0; 659 uint8_t i=0; 660 NFCSTATUS status = NFCSTATUS_SUCCESS; 661 662 p_pipe_info = (phHciNfc_Pipe_Info_t *) 663 psHciContext->p_pipe_list[pipe_id]; 664 psHciContext->tx_total = 0 ; 665 length = (length + HCP_HEADER_LEN); 666 667 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 668 /* Construct the HCP Frame */ 669 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT, 670 (uint8_t) pipe_id, 671 HCP_MSG_TYPE_EVENT, event); 672 673 hcp_message = &(hcp_packet->msg.message); 674 675 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload, 676 i, 677 (uint8_t *)p_pipe_info->param_info, 678 p_pipe_info->param_length); 679 length = (uint8_t)(length + i + p_pipe_info->param_length); 680 681 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT ; 682 p_pipe_info->prev_msg = event ; 683 psHciContext->tx_total = length; 684 685 /* Send the Constructed HCP packet to the lower layer */ 686 status = phHciNfc_Send_HCP( psHciContext, pHwRef ); 687 if(NFCSTATUS_PENDING == status) 688 { 689 ((phHciNfc_SWP_Info_t *)psHciContext->p_swp_info)->current_seq = 690 ((phHciNfc_SWP_Info_t *)psHciContext->p_swp_info)->next_seq; 691 p_pipe_info->prev_status = status; 692 } 693 694 return status; 695 } 696 697 NFCSTATUS 698 phHciNfc_SWP_Update_Sequence( 699 phHciNfc_sContext_t *psHciContext, 700 phHciNfc_eSeqType_t SWP_seq 701 ) 702 { 703 NFCSTATUS status = NFCSTATUS_SUCCESS; 704 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 705 if( NULL == psHciContext ) 706 { 707 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 708 } 709 else if( NULL == psHciContext->p_swp_info ) 710 { 711 status = PHNFCSTVAL(CID_NFC_HCI, 712 NFCSTATUS_INVALID_HCI_INFORMATION); 713 } 714 else 715 { 716 ps_swp_info = (phHciNfc_SWP_Info_t *) 717 psHciContext->p_swp_info ; 718 switch(SWP_seq) 719 { 720 case RESET_SEQ: 721 case INIT_SEQ: 722 { 723 ps_swp_info->current_seq = SWP_INVALID_SEQUENCE; 724 ps_swp_info->next_seq = SWP_INVALID_SEQUENCE ; 725 break; 726 } 727 case UPDATE_SEQ: 728 { 729 ps_swp_info->current_seq = ps_swp_info->next_seq; 730 break; 731 } 732 case REL_SEQ: 733 { 734 ps_swp_info->current_seq = SWP_INVALID_SEQUENCE; 735 ps_swp_info->next_seq = SWP_INVALID_SEQUENCE; 736 break; 737 } 738 case CONFIG_SEQ: 739 { 740 ps_swp_info->current_seq = SWP_STATUS_SEQ; 741 ps_swp_info->next_seq = SWP_STATUS_SEQ; 742 break; 743 } 744 default: 745 { 746 break; 747 } 748 } 749 } 750 return status; 751 } 752 753 NFCSTATUS 754 phHciNfc_SWP_Config_Sequence( 755 phHciNfc_sContext_t *psHciContext, 756 void *pHwRef, 757 phHal_sEmulationCfg_t *ps_emulation_cfg 758 ) 759 { 760 NFCSTATUS status = NFCSTATUS_SUCCESS; 761 phHciNfc_SWP_Info_t *ps_swp_info=NULL; 762 763 if ((NULL == psHciContext) || (NULL == pHwRef) || 764 (NULL == ps_emulation_cfg)) 765 { 766 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 767 } 768 else if( NULL == psHciContext->p_swp_info ) 769 { 770 status = PHNFCSTVAL(CID_NFC_HCI, 771 NFCSTATUS_INVALID_HCI_INFORMATION); 772 } 773 else 774 { 775 phHciNfc_Pipe_Info_t *ps_pipe_info = NULL; 776 phHal_sUiccEmuCfg_t *uicc_config = 777 &(ps_emulation_cfg->config.uiccEmuCfg); 778 779 ps_swp_info = (phHciNfc_SWP_Info_t *)psHciContext->p_swp_info; 780 ps_pipe_info = ps_swp_info->p_pipe_info; 781 782 if (NULL == ps_pipe_info) 783 { 784 status = PHNFCSTVAL(CID_NFC_HCI, 785 NFCSTATUS_INVALID_HCI_INFORMATION); 786 } 787 else 788 { 789 switch(ps_swp_info->current_seq) 790 { 791 case SWP_STATUS_SEQ : 792 { 793 status = phHciNfc_SWP_Configure_Default( psHciContext, 794 pHwRef, uicc_config->enableUicc ); 795 796 if(status == NFCSTATUS_PENDING) 797 { 798 ps_swp_info->next_seq = SWP_STATUS_SEQ; 799 status = NFCSTATUS_SUCCESS; 800 } 801 break; 802 } 803 case SWP_MODE_SEQ : 804 { 805 status = phHciNfc_SWP_Configure_Mode( psHciContext, 806 pHwRef, UICC_SWITCH_MODE_DEFAULT ); 807 /* UICC_SWITCH_MODE_ON */ 808 if(status == NFCSTATUS_PENDING) 809 { 810 ps_swp_info->next_seq = SWP_STATUS_SEQ; 811 status = NFCSTATUS_SUCCESS; 812 } 813 break; 814 } 815 default : 816 { 817 status = PHNFCSTVAL(CID_NFC_HCI, 818 NFCSTATUS_INVALID_HCI_INFORMATION); 819 break; 820 } 821 } 822 } 823 } 824 return status; 825 } 826 827 828 829