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_DevMgmt.c * 23 * \brief HCI PN544 Device Management Gate Routines. * 24 * * 25 * * 26 * Project: NFC-FRI-1.1 * 27 * * 28 * $Date: Fri Mar 12 10:21:54 2010 $ * 29 * $Author: ing04880 $ * 30 * $Revision: 1.29 $ * 31 * $Aliases: NFC_FRI1.1_WK1007_R33_3,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 $ * 32 * * 33 * =========================================================================== * 34 */ 35 36 /* 37 ***************************** Header File Inclusion **************************** 38 */ 39 #include <phNfcConfig.h> 40 #include <phNfcCompId.h> 41 #include <phHciNfc_Pipe.h> 42 #include <phHciNfc_DevMgmt.h> 43 #include <phHciNfc_Emulation.h> 44 #include <phOsalNfc.h> 45 46 /* 47 ****************************** Macro Definitions ******************************* 48 */ 49 50 /* Commands for System Management module */ 51 #define NXP_RF_CHECK_SETTINGS 0x10U 52 #define NXP_RF_UPDATE_SETTINGS 0x11U 53 54 /* Self Test Commands */ 55 #define NXP_SELF_TEST_ANTENNA 0x20U 56 #define NXP_SELF_TEST_SWP 0x21U 57 #define NXP_SELF_TEST_NFCWI 0x22U 58 #define NXP_SELF_TEST_PRBS 0x25U 59 60 /* System Management propreitary control */ 61 #define NXP_DBG_READ 0x3EU 62 #define NXP_DBG_WRITE 0x3FU 63 64 /* System Management Events */ 65 #define NXP_EVT_SET_AUTONOMOUS 0x01U 66 #define NXP_EVT_CLF_WAKEUP 0x02U 67 68 /* System Management Information Events */ 69 #define NXP_EVT_INFO_TXLDO_OVERCUR 0x10U 70 #define NXP_EVT_INFO_PMUVCC 0x11U 71 #define NXP_EVT_INFO_EXT_RF_FIELD 0x12U 72 #define NXP_EVT_INFO_MEM_VIOLATION 0x13U 73 #define NXP_EVT_INFO_TEMP_OVERHEAT 0x14U 74 75 #define NFC_DEV_TXLDO_MASK 0x03U 76 77 78 /* 79 *************************** Structure and Enumeration *************************** 80 */ 81 82 83 /** \defgroup grp_hci_nfc HCI PN544 Device Management Component 84 * 85 * 86 */ 87 88 typedef enum phHciNfc_DevMgmt_Seq{ 89 DEV_MGMT_PIPE_OPEN = 0x00U, 90 DEV_MGMT_SET_PWR_STATUS, 91 DEV_MGMT_SET_INFO_EVT, 92 DEV_MGMT_GET_EEPROM_INFO, 93 DEV_MGMT_GPIO_PDIR, 94 DEV_MGMT_GPIO_PEN, 95 DEV_MGMT_TX_LDO, 96 DEV_MGMT_IFC_TO_RX_H, 97 DEV_MGMT_IFC_TO_RX_L, 98 DEV_MGMT_IFC_TO_TX_H, 99 DEV_MGMT_IFC_TO_TX_L, 100 DEV_MGMT_ANAIRQ_CONF, 101 DEV_MGMT_PMOS_MOD, 102 DEV_MGMT_CLK_REQ, 103 DEV_MGMT_INPUT_CLK, 104 DEV_MGMT_UICC_PWR_REQUEST, 105 DEV_MGMT_ACTIVE_GUARD_TO, 106 DEV_MGMT_MAX_ACT_TO_LOW, 107 DEV_MGMT_MAX_ACT_TO_HIGH, 108 DEV_MGMT_UICC_CE_A_ACCESS, 109 DEV_MGMT_UICC_CE_B_ACCESS, 110 DEV_MGMT_UICC_CE_BP_ACCESS, 111 DEV_MGMT_UICC_CE_F_ACCESS, 112 DEV_MGMT_UICC_RD_A_ACCESS, 113 DEV_MGMT_UICC_RD_B_ACCESS, 114 DEV_MGMT_UICC_BIT_RATE, 115 DEV_MGMT_UICC_RX_ERR_CNT, 116 DEV_MGMT_UICC_TX_ERR_CNT, 117 DEV_MGMT_LLC_GRD_TO_H, 118 DEV_MGMT_LLC_GRD_TO_L, 119 DEV_MGMT_LLC_ACK_TO_H, 120 DEV_MGMT_LLC_ACK_TO_L, 121 DEV_MGMT_EVT_AUTONOMOUS, 122 DEV_MGMT_PIPE_CLOSE 123 } phHciNfc_DevMgmt_Seq_t; 124 125 126 typedef struct phHciNfc_DevMgmt_Info{ 127 phHciNfc_DevMgmt_Seq_t current_seq; 128 phHciNfc_DevMgmt_Seq_t next_seq; 129 phHciNfc_Pipe_Info_t *p_pipe_info; 130 uint8_t test_status; 131 uint8_t value; 132 uint8_t rf_status; 133 uint8_t pmuvcc_status; 134 uint8_t overheat_status; 135 uint8_t *p_val; 136 uint8_t eeprom_crc; 137 phNfc_sData_t test_result; 138 139 } phHciNfc_DevMgmt_Info_t; 140 141 142 /* 143 *************************** Static Function Declaration ************************** 144 */ 145 146 static 147 NFCSTATUS 148 phHciNfc_DevMgmt_InfoUpdate( 149 phHciNfc_sContext_t *psHciContext, 150 phHal_sHwReference_t *pHwRef, 151 uint8_t index, 152 uint8_t *reg_value, 153 uint8_t reg_length 154 ); 155 156 static 157 NFCSTATUS 158 phHciNfc_Recv_DevMgmt_Response( 159 void *psHciContext, 160 void *pHwRef, 161 uint8_t *pResponse, 162 #ifdef ONE_BYTE_LEN 163 uint8_t length 164 #else 165 uint16_t length 166 #endif 167 ); 168 169 static 170 NFCSTATUS 171 phHciNfc_Recv_DevMgmt_Event( 172 void *psContext, 173 void *pHwRef, 174 uint8_t *pEvent, 175 #ifdef ONE_BYTE_LEN 176 uint8_t length 177 #else 178 uint16_t length 179 #endif 180 ); 181 182 183 static 184 NFCSTATUS 185 phHciNfc_Send_DevMgmt_Command ( 186 phHciNfc_sContext_t *psHciContext, 187 void *pHwRef, 188 uint8_t pipe_id, 189 uint8_t cmd 190 ); 191 192 static 193 NFCSTATUS 194 phHciNfc_Send_DevMgmt_Event ( 195 phHciNfc_sContext_t *psHciContext, 196 void *pHwRef, 197 uint8_t pipe_id, 198 uint8_t event 199 ); 200 201 /* 202 *************************** Function Definitions *************************** 203 */ 204 205 206 NFCSTATUS 207 phHciNfc_DevMgmt_Init_Resources( 208 phHciNfc_sContext_t *psHciContext 209 ) 210 { 211 NFCSTATUS status = NFCSTATUS_SUCCESS; 212 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 213 214 if( NULL == psHciContext ) 215 { 216 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 217 } 218 else 219 { 220 if(( NULL == psHciContext->p_device_mgmt_info ) && 221 (phHciNfc_Allocate_Resource((void **)(&p_device_mgmt_info), 222 sizeof(phHciNfc_DevMgmt_Info_t))== NFCSTATUS_SUCCESS)) 223 { 224 psHciContext->p_device_mgmt_info = p_device_mgmt_info; 225 p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN; 226 p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN; 227 p_device_mgmt_info->p_pipe_info = NULL; 228 } 229 else 230 { 231 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INSUFFICIENT_RESOURCES); 232 } 233 } 234 return status; 235 } 236 237 238 NFCSTATUS 239 phHciNfc_DevMgmt_Get_PipeID( 240 phHciNfc_sContext_t *psHciContext, 241 uint8_t *ppipe_id 242 ) 243 { 244 NFCSTATUS status = NFCSTATUS_SUCCESS; 245 246 if( (NULL != psHciContext) 247 && ( NULL != ppipe_id ) 248 && ( NULL != psHciContext->p_device_mgmt_info ) 249 ) 250 { 251 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 252 p_pipe_info = ((phHciNfc_DevMgmt_Info_t *) 253 psHciContext->p_device_mgmt_info)->p_pipe_info ; 254 if (NULL != p_pipe_info) 255 { 256 *ppipe_id = p_pipe_info->pipe.pipe_id ; 257 } 258 else 259 { 260 *ppipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID; 261 } 262 263 } 264 else 265 { 266 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 267 } 268 return status; 269 } 270 271 272 NFCSTATUS 273 phHciNfc_DevMgmt_Get_Test_Result( 274 phHciNfc_sContext_t *psHciContext, 275 phNfc_sData_t *p_test_result 276 ) 277 { 278 NFCSTATUS status = NFCSTATUS_SUCCESS; 279 280 if( (NULL != psHciContext) 281 && ( NULL != p_test_result ) 282 && ( NULL != psHciContext->p_device_mgmt_info ) 283 ) 284 { 285 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 286 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 287 psHciContext->p_device_mgmt_info ; 288 p_test_result->buffer = p_device_mgmt_info->test_result.buffer; 289 p_test_result->length = p_device_mgmt_info->test_result.length; 290 291 } 292 else 293 { 294 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 295 } 296 297 return status; 298 } 299 300 301 NFCSTATUS 302 phHciNfc_DevMgmt_Set_Test_Result( 303 phHciNfc_sContext_t *psHciContext, 304 uint8_t test_status 305 ) 306 { 307 NFCSTATUS status = NFCSTATUS_SUCCESS; 308 309 if( (NULL != psHciContext) 310 && ( NULL != psHciContext->p_device_mgmt_info ) 311 ) 312 { 313 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 314 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 315 psHciContext->p_device_mgmt_info ; 316 p_device_mgmt_info->test_status = test_status; 317 318 } 319 else 320 { 321 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 322 } 323 324 return status; 325 } 326 327 328 329 NFCSTATUS 330 phHciNfc_DevMgmt_Update_PipeInfo( 331 phHciNfc_sContext_t *psHciContext, 332 uint8_t pipeID, 333 phHciNfc_Pipe_Info_t *pPipeInfo 334 ) 335 { 336 NFCSTATUS status = NFCSTATUS_SUCCESS; 337 338 if( NULL == psHciContext ) 339 { 340 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 341 } 342 else if(NULL == psHciContext->p_device_mgmt_info) 343 { 344 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 345 } 346 else 347 { 348 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 349 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 350 psHciContext->p_device_mgmt_info ; 351 /* Update the pipe_info of the Device Management Gate obtained 352 * from HCI Response */ 353 p_device_mgmt_info->p_pipe_info = pPipeInfo; 354 if (( NULL != pPipeInfo) 355 && ((uint8_t)HCI_UNKNOWN_PIPE_ID != pipeID) 356 ) 357 { 358 /* Update the Response Receive routine of the Device 359 * Managment Gate */ 360 pPipeInfo->recv_resp = &phHciNfc_Recv_DevMgmt_Response; 361 pPipeInfo->recv_event = &phHciNfc_Recv_DevMgmt_Event; 362 } 363 } 364 365 return status; 366 } 367 368 369 NFCSTATUS 370 phHciNfc_DevMgmt_Configure ( 371 phHciNfc_sContext_t *psHciContext, 372 void *pHwRef, 373 uint16_t address, 374 uint8_t value 375 ) 376 { 377 NFCSTATUS status = NFCSTATUS_SUCCESS; 378 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 379 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID; 380 uint8_t i=0; 381 uint8_t params[5]; 382 383 if( (NULL == psHciContext) || (NULL == pHwRef) ) 384 { 385 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 386 } 387 else if( NULL == psHciContext->p_device_mgmt_info ) 388 { 389 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 390 } 391 else 392 { 393 p_pipe_info = ((phHciNfc_DevMgmt_Info_t *) 394 psHciContext->p_device_mgmt_info)->p_pipe_info ; 395 396 if(NULL == p_pipe_info ) 397 { 398 status = PHNFCSTVAL(CID_NFC_HCI, 399 NFCSTATUS_INVALID_HCI_SEQUENCE); 400 } 401 else 402 { 403 pipe_id = p_pipe_info->pipe.pipe_id ; 404 params[i++] = 0x00; 405 params[i++] = (uint8_t)(address >> BYTE_SIZE); 406 params[i++] = (uint8_t)address; 407 params[i++] = value; 408 p_pipe_info->param_info = ¶ms; 409 p_pipe_info->param_length = i ; 410 status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef, 411 pipe_id, (uint8_t)NXP_DBG_WRITE ); 412 } 413 } 414 return status; 415 } 416 417 418 NFCSTATUS 419 phHciNfc_DevMgmt_Get_Info ( 420 phHciNfc_sContext_t *psHciContext, 421 void *pHwRef, 422 uint16_t address, 423 uint8_t *p_val 424 ) 425 { 426 NFCSTATUS status = NFCSTATUS_SUCCESS; 427 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 428 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID; 429 uint8_t i=0; 430 uint8_t params[5]; 431 432 if( (NULL == psHciContext) || (NULL == pHwRef) ) 433 { 434 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 435 } 436 else if( NULL == psHciContext->p_device_mgmt_info ) 437 { 438 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 439 } 440 else 441 { 442 p_pipe_info = ((phHciNfc_DevMgmt_Info_t *) 443 psHciContext->p_device_mgmt_info)->p_pipe_info ; 444 445 if(NULL == p_pipe_info ) 446 { 447 status = PHNFCSTVAL(CID_NFC_HCI, 448 NFCSTATUS_INVALID_HCI_SEQUENCE); 449 } 450 else 451 { 452 ((phHciNfc_DevMgmt_Info_t *) 453 psHciContext->p_device_mgmt_info)->p_val = p_val; 454 pipe_id = p_pipe_info->pipe.pipe_id ; 455 params[i++] = 0x00; 456 params[i++] = (uint8_t)(address >> BYTE_SIZE); 457 params[i++] = (uint8_t) address; 458 p_pipe_info->param_info = ¶ms; 459 p_pipe_info->param_length = i ; 460 status = phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef, 461 pipe_id, (uint8_t)NXP_DBG_READ ); 462 } 463 } 464 return status; 465 466 } 467 468 /*! 469 * \brief Initialisation of PN544 Device Managment Gate. 470 * 471 * This function initialses the PN544 Device Management gate and 472 * populates the PN544 Device Management Information Structure 473 * 474 */ 475 476 NFCSTATUS 477 phHciNfc_DevMgmt_Initialise( 478 phHciNfc_sContext_t *psHciContext, 479 void *pHwRef 480 ) 481 { 482 NFCSTATUS status = NFCSTATUS_SUCCESS; 483 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 484 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 485 static uint8_t config = 0x10; 486 487 if( ( NULL == psHciContext ) 488 || (NULL == pHwRef ) 489 ) 490 { 491 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 492 } 493 else if (NULL == psHciContext->p_device_mgmt_info) 494 { 495 status = PHNFCSTVAL(CID_NFC_HCI, 496 NFCSTATUS_INVALID_HCI_INFORMATION); 497 }/* End of the PN544 Device Info Memory Check */ 498 else 499 { 500 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 501 psHciContext->p_device_mgmt_info ; 502 p_pipe_info = p_device_mgmt_info->p_pipe_info; 503 504 if (NULL == p_pipe_info) 505 { 506 status = PHNFCSTVAL(CID_NFC_HCI, 507 NFCSTATUS_INVALID_HCI_SEQUENCE); 508 } 509 else 510 { 511 switch(p_device_mgmt_info->current_seq ) 512 { 513 /* PN544 Device Mgmt pipe open sequence */ 514 case DEV_MGMT_PIPE_OPEN: 515 { 516 status = phHciNfc_Open_Pipe( psHciContext, 517 pHwRef, p_pipe_info ); 518 if(status == NFCSTATUS_SUCCESS) 519 { 520 521 if (HCI_SELF_TEST == psHciContext->init_mode ) 522 { 523 p_device_mgmt_info->next_seq = 524 DEV_MGMT_GPIO_PDIR; 525 } 526 else 527 { 528 p_device_mgmt_info->next_seq = 529 DEV_MGMT_GET_EEPROM_INFO; 530 } 531 status = NFCSTATUS_PENDING; 532 } 533 break; 534 } 535 case DEV_MGMT_GET_EEPROM_INFO: 536 { 537 p_pipe_info->reg_index = DEVICE_INFO_EEPROM_INDEX; 538 status = phHciNfc_Send_Generic_Cmd( psHciContext, 539 pHwRef, (uint8_t)p_pipe_info->pipe.pipe_id, 540 (uint8_t)ANY_GET_PARAMETER); 541 if(NFCSTATUS_PENDING == status ) 542 { 543 #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) 544 p_device_mgmt_info->next_seq = 545 DEV_MGMT_IFC_TO_TX_H; 546 #else 547 p_device_mgmt_info->next_seq = 548 DEV_MGMT_TX_LDO; 549 #endif /* #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */ 550 } 551 break; 552 } 553 case DEV_MGMT_GPIO_PDIR: 554 { 555 config = 0x00; 556 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 557 NFC_ADDRESS_GPIO_PDIR , config ); 558 if(NFCSTATUS_PENDING == status ) 559 { 560 p_device_mgmt_info->next_seq = 561 DEV_MGMT_GPIO_PEN; 562 } 563 break; 564 } 565 case DEV_MGMT_GPIO_PEN: 566 { 567 config = NXP_NFC_GPIO_MASK(NXP_DOWNLOAD_GPIO)| 0x03 ; 568 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 569 NFC_ADDRESS_GPIO_PEN , config ); 570 if(NFCSTATUS_PENDING == status ) 571 { 572 #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) 573 p_device_mgmt_info->next_seq = 574 DEV_MGMT_IFC_TO_TX_H; 575 #else 576 p_device_mgmt_info->next_seq = 577 DEV_MGMT_TX_LDO; 578 #endif /* #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */ 579 } 580 break; 581 } 582 583 #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) 584 585 case DEV_MGMT_IFC_TO_TX_H: 586 { 587 config = (uint8_t) 588 ( NXP_NFC_IFC_CONFIG_DEFAULT >> BYTE_SIZE ) /* 0x03 */; 589 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 590 NFC_ADDRESS_IFC_TO_TX_H , config ); 591 if(NFCSTATUS_PENDING == status ) 592 { 593 p_device_mgmt_info->next_seq = 594 DEV_MGMT_IFC_TO_TX_L; 595 } 596 break; 597 } 598 case DEV_MGMT_IFC_TO_TX_L: 599 { 600 config = (uint8_t) 601 ( NXP_NFC_IFC_CONFIG_DEFAULT & BYTE_MASK ) /* 0xE8 */; 602 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 603 NFC_ADDRESS_IFC_TO_TX_L , config ); 604 if(NFCSTATUS_PENDING == status ) 605 { 606 #if ( NXP_NFC_IFC_TIMEOUT & 0x02 ) 607 p_device_mgmt_info->next_seq = 608 DEV_MGMT_IFC_TO_RX_H; 609 #else 610 p_device_mgmt_info->next_seq = 611 DEV_MGMT_TX_LDO; 612 #endif /* #if ( NXP_NFC_IFC_TIMEOUT & 0x02 ) */ 613 } 614 break; 615 } 616 case DEV_MGMT_IFC_TO_RX_H: 617 { 618 config = 0x10; 619 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 620 NFC_ADDRESS_IFC_TO_RX_H , config ); 621 if(NFCSTATUS_PENDING == status ) 622 { 623 p_device_mgmt_info->next_seq = 624 DEV_MGMT_IFC_TO_RX_L; 625 } 626 break; 627 } 628 case DEV_MGMT_IFC_TO_RX_L: 629 { 630 config = 0x1E; 631 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 632 NFC_ADDRESS_IFC_TO_RX_L , config ); 633 if(NFCSTATUS_PENDING == status ) 634 { 635 p_device_mgmt_info->next_seq = 636 DEV_MGMT_TX_LDO; 637 } 638 break; 639 } 640 641 #endif /* #if ( NXP_NFC_IFC_TIMEOUT & 0x01 ) */ 642 case DEV_MGMT_TX_LDO: 643 { 644 config = (NFC_DEV_HWCONF_DEFAULT | 645 (NXP_DEFAULT_TX_LDO & NFC_DEV_TXLDO_MASK)); 646 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 647 NFC_ADDRESS_HW_CONF , config ); 648 if(NFCSTATUS_PENDING == status ) 649 { 650 #if ( SW_TYPE_RF_TUNING_BF & 0x01) 651 p_device_mgmt_info->next_seq = DEV_MGMT_ANAIRQ_CONF; 652 #else 653 p_device_mgmt_info->next_seq = DEV_MGMT_CLK_REQ; 654 #endif 655 /* status = NFCSTATUS_SUCCESS; */ 656 } 657 break; 658 } 659 #if ( SW_TYPE_RF_TUNING_BF & 0x01) 660 /* The Analogue IRQ Configuartion */ 661 case DEV_MGMT_ANAIRQ_CONF: 662 { 663 config = 0x04; 664 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 665 NFC_ADDRESS_ANAIRQ_CONF , config ); 666 if(NFCSTATUS_PENDING == status ) 667 { 668 p_device_mgmt_info->next_seq = 669 DEV_MGMT_PMOS_MOD; 670 /* status = NFCSTATUS_SUCCESS; */ 671 } 672 break; 673 } 674 /* The PMOS Modulation Index */ 675 case DEV_MGMT_PMOS_MOD: 676 { 677 config = NFC_DEV_PMOS_MOD_DEFAULT; 678 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 679 NFC_ADDRESS_PMOS_MOD , config ); 680 if(NFCSTATUS_PENDING == status ) 681 { 682 p_device_mgmt_info->next_seq = 683 DEV_MGMT_CLK_REQ; 684 /* status = NFCSTATUS_SUCCESS; */ 685 } 686 break; 687 } 688 #endif /* #if ( SW_TYPE_RF_TUNING_BF & 0x01) */ 689 case DEV_MGMT_CLK_REQ: 690 { 691 config = ((phHal_sHwConfig_t *) 692 psHciContext->p_config_params)->clk_req ; 693 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 694 NFC_ADDRESS_CLK_REQ , config ); 695 if(NFCSTATUS_PENDING == status ) 696 { 697 p_device_mgmt_info->next_seq = 698 DEV_MGMT_INPUT_CLK; 699 /* status = NFCSTATUS_SUCCESS; */ 700 } 701 break; 702 } 703 case DEV_MGMT_INPUT_CLK: 704 { 705 config = ((phHal_sHwConfig_t *) 706 psHciContext->p_config_params)->input_clk; 707 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 708 NFC_ADDRESS_CLK_INPUT , config ); 709 if(NFCSTATUS_PENDING == status ) 710 { 711 p_device_mgmt_info->next_seq = 712 DEV_MGMT_UICC_PWR_REQUEST; 713 } 714 break; 715 } 716 case DEV_MGMT_UICC_PWR_REQUEST: 717 { 718 config = NXP_UICC_PWR_REQUEST; 719 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 720 NFC_ADDRESS_SWP_PWR_REQ , config ); 721 if(NFCSTATUS_PENDING == status ) 722 { 723 p_device_mgmt_info->next_seq = 724 DEV_MGMT_UICC_RD_A_ACCESS; 725 } 726 break; 727 } 728 case DEV_MGMT_UICC_RD_A_ACCESS: 729 { 730 #if ( NXP_UICC_RD_RIGHTS & 0x01 ) 731 config = (uint8_t) phHciNfc_RFReaderAGate; 732 #else 733 config = 0xFFU; 734 #endif /* #if ( NXP_UICC_RD_RIGHTS & 0x01 ) */ 735 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 736 NFC_ADDRESS_UICC_RD_A_ACCESS , config ); 737 if(NFCSTATUS_PENDING == status ) 738 { 739 p_device_mgmt_info->next_seq = 740 DEV_MGMT_UICC_RD_B_ACCESS; 741 } 742 break; 743 } 744 case DEV_MGMT_UICC_RD_B_ACCESS: 745 { 746 #if ( NXP_UICC_RD_RIGHTS & 0x02 ) 747 config = (uint8_t) phHciNfc_RFReaderBGate; 748 #else 749 config = 0xFFU; 750 #endif /* #if ( NXP_UICC_RD_RIGHTS & 0x02 ) */ 751 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 752 NFC_ADDRESS_UICC_RD_B_ACCESS , config ); 753 if(NFCSTATUS_PENDING == status ) 754 { 755 p_device_mgmt_info->next_seq = 756 DEV_MGMT_UICC_CE_A_ACCESS; 757 } 758 break; 759 } 760 case DEV_MGMT_UICC_CE_A_ACCESS: 761 { 762 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x01 ) 763 config = (uint8_t) phHciNfc_CETypeAGate; 764 #else 765 config = 0xFFU; 766 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x01 ) */ 767 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 768 NFC_ADDRESS_UICC_CE_A_ACCESS , config ); 769 if(NFCSTATUS_PENDING == status ) 770 { 771 p_device_mgmt_info->next_seq = 772 DEV_MGMT_UICC_CE_B_ACCESS; 773 } 774 break; 775 } 776 case DEV_MGMT_UICC_CE_B_ACCESS: 777 { 778 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x02 ) 779 config = (uint8_t) phHciNfc_CETypeBGate; 780 #else 781 config = 0xFFU; 782 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x02 ) */ 783 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 784 NFC_ADDRESS_UICC_CE_B_ACCESS , config ); 785 if(NFCSTATUS_PENDING == status ) 786 { 787 p_device_mgmt_info->next_seq = 788 DEV_MGMT_UICC_CE_BP_ACCESS; 789 } 790 break; 791 } 792 case DEV_MGMT_UICC_CE_BP_ACCESS: 793 { 794 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x04 ) 795 config = (uint8_t) phHciNfc_CETypeBPrimeGate; 796 #else 797 config = 0xFFU; 798 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x04 ) */ 799 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 800 NFC_ADDRESS_UICC_CE_BP_ACCESS , config ); 801 if(NFCSTATUS_PENDING == status ) 802 { 803 p_device_mgmt_info->next_seq = 804 DEV_MGMT_UICC_CE_F_ACCESS; 805 } 806 break; 807 } 808 case DEV_MGMT_UICC_CE_F_ACCESS: 809 { 810 #if defined(HOST_EMULATION) || ( NXP_UICC_CE_RIGHTS & 0x08 ) 811 config = (uint8_t) phHciNfc_CETypeFGate; 812 #else 813 config = 0xFFU; 814 #endif /* #if ( NXP_UICC_CE_RIGHTS & 0x08 ) */ 815 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 816 NFC_ADDRESS_UICC_CE_F_ACCESS , config ); 817 if(NFCSTATUS_PENDING == status ) 818 { 819 p_device_mgmt_info->next_seq = 820 DEV_MGMT_UICC_BIT_RATE; 821 } 822 break; 823 } 824 case DEV_MGMT_UICC_BIT_RATE: 825 { 826 config = NXP_UICC_BIT_RATE; 827 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 828 NFC_ADDRESS_SWP_BITRATE , config ); 829 if(NFCSTATUS_PENDING == status ) 830 { 831 #if defined (CFG_PWR_STATUS) 832 p_device_mgmt_info->next_seq = 833 DEV_MGMT_SET_PWR_STATUS; 834 #else 835 p_device_mgmt_info->next_seq = 836 DEV_MGMT_SET_INFO_EVT; 837 #endif 838 } 839 break; 840 } 841 #ifdef CFG_PWR_STATUS 842 case DEV_MGMT_SET_PWR_STATUS: 843 { 844 config = NXP_SYSTEM_PWR_STATUS; 845 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 846 NFC_ADDRESS_PWR_STATUS , config ); 847 if(NFCSTATUS_PENDING == status ) 848 { 849 p_device_mgmt_info->next_seq = 850 DEV_MGMT_SET_INFO_EVT; 851 } 852 break; 853 } 854 #endif 855 case DEV_MGMT_SET_INFO_EVT: 856 { 857 config = NXP_SYSTEM_EVT_INFO; 858 status = phHciNfc_Set_Param(psHciContext, pHwRef, 859 p_pipe_info, DEVICE_INFO_EVT_INDEX, 860 (uint8_t *)&config, sizeof(config) ); 861 if(NFCSTATUS_PENDING == status ) 862 { 863 #if ( HOST_LINK_TIMEOUT & 0x01 ) 864 p_device_mgmt_info->next_seq = 865 DEV_MGMT_LLC_GRD_TO_H; 866 #else 867 p_device_mgmt_info->next_seq = 868 DEV_MGMT_EVT_AUTONOMOUS; 869 status = NFCSTATUS_SUCCESS; 870 #endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */ 871 } 872 break; 873 } 874 #if ( HOST_LINK_TIMEOUT & 0x01 ) 875 876 case DEV_MGMT_LLC_GRD_TO_H: 877 { 878 config =(uint8_t) 879 ( NXP_NFC_LINK_GRD_CFG_DEFAULT >> BYTE_SIZE ) /* 0x00 */; 880 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 881 NFC_ADDRESS_LLC_GRD_TO_H , config ); 882 if(NFCSTATUS_PENDING == status ) 883 { 884 p_device_mgmt_info->next_seq = 885 DEV_MGMT_LLC_GRD_TO_L; 886 } 887 break; 888 } 889 case DEV_MGMT_LLC_GRD_TO_L: 890 { 891 config = (uint8_t) 892 ( NXP_NFC_LINK_GRD_CFG_DEFAULT & BYTE_MASK ) /* 0x32 */; 893 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 894 NFC_ADDRESS_LLC_GRD_TO_L , config ); 895 if(NFCSTATUS_PENDING == status ) 896 { 897 #if ( HOST_LINK_TIMEOUT & 0x02 ) 898 p_device_mgmt_info->next_seq = 899 DEV_MGMT_LLC_ACK_TO_H; 900 #else 901 p_device_mgmt_info->next_seq = 902 DEV_MGMT_EVT_AUTONOMOUS; 903 status = NFCSTATUS_SUCCESS; 904 #endif /* #if ( HOST_LINK_TIMEOUT & 0x02 ) */ 905 } 906 break; 907 } 908 case DEV_MGMT_LLC_ACK_TO_H: 909 { 910 config = (uint8_t) 911 ( NXP_NFC_LINK_ACK_CFG_DEFAULT >> BYTE_SIZE )/* 0x00 */; 912 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 913 NFC_ADDRESS_LLC_ACK_TO_H , config ); 914 if(NFCSTATUS_PENDING == status ) 915 { 916 p_device_mgmt_info->next_seq = 917 DEV_MGMT_LLC_ACK_TO_L; 918 } 919 break; 920 } 921 case DEV_MGMT_LLC_ACK_TO_L: 922 { 923 config = (uint8_t) 924 ( NXP_NFC_LINK_ACK_CFG_DEFAULT & BYTE_MASK ) /* 0x00 */;; 925 status = phHciNfc_DevMgmt_Configure( psHciContext, pHwRef, 926 NFC_ADDRESS_LLC_ACK_TO_L , config ); 927 if(NFCSTATUS_PENDING == status ) 928 { 929 p_device_mgmt_info->next_seq = 930 DEV_MGMT_EVT_AUTONOMOUS; 931 status = NFCSTATUS_SUCCESS; 932 } 933 break; 934 } 935 936 #endif /* #if ( HOST_LINK_TIMEOUT & 0x01 ) */ 937 default: 938 { 939 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE); 940 break; 941 } 942 943 }/* End of the Sequence Switch */ 944 } 945 946 } /* End of Null Context Check */ 947 948 return status; 949 } 950 951 /*! 952 * \brief Releases the resources allocated the PN544 Device Management. 953 * 954 * This function Releases the resources allocated the PN544 Device Management 955 * and resets the hardware to the reset state. 956 */ 957 958 NFCSTATUS 959 phHciNfc_DevMgmt_Release( 960 phHciNfc_sContext_t *psHciContext, 961 void *pHwRef 962 ) 963 { 964 NFCSTATUS status = NFCSTATUS_SUCCESS; 965 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 966 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 967 968 if( (NULL == psHciContext) || (NULL == pHwRef) ) 969 { 970 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 971 } 972 else 973 { 974 if( NULL != psHciContext->p_device_mgmt_info ) 975 { 976 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 977 psHciContext->p_device_mgmt_info ; 978 switch(p_device_mgmt_info->current_seq) 979 { 980 981 /* PN544 Device pipe close sequence */ 982 case DEV_MGMT_EVT_AUTONOMOUS: 983 { 984 p_pipe_info = p_device_mgmt_info->p_pipe_info; 985 986 p_pipe_info->param_info = NULL; 987 p_pipe_info->param_length = HCP_ZERO_LEN; 988 989 status = phHciNfc_Send_DevMgmt_Event(psHciContext, pHwRef, 990 p_pipe_info->pipe.pipe_id, NXP_EVT_SET_AUTONOMOUS); 991 if(status == NFCSTATUS_PENDING) 992 { 993 p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN; 994 status = NFCSTATUS_SUCCESS; 995 } 996 break; 997 } 998 /* PN544 Device pipe close sequence */ 999 case DEV_MGMT_PIPE_CLOSE: 1000 { 1001 p_pipe_info = p_device_mgmt_info->p_pipe_info; 1002 1003 status = phHciNfc_Close_Pipe( psHciContext, 1004 pHwRef, p_pipe_info ); 1005 if(status == NFCSTATUS_SUCCESS) 1006 { 1007 p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN; 1008 /* status = NFCSTATUS_PENDING; */ 1009 } 1010 break; 1011 } 1012 default: 1013 { 1014 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_SEQUENCE); 1015 break; 1016 } 1017 1018 }/* End of the Sequence Switch */ 1019 1020 }/* End of the PN544 Device Info Memory Check */ 1021 1022 } /* End of Null Context Check */ 1023 1024 return status; 1025 } 1026 1027 NFCSTATUS 1028 phHciNfc_DevMgmt_Update_Sequence( 1029 phHciNfc_sContext_t *psHciContext, 1030 phHciNfc_eSeqType_t DevMgmt_seq 1031 ) 1032 { 1033 NFCSTATUS status = NFCSTATUS_SUCCESS; 1034 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 1035 if( NULL == psHciContext ) 1036 { 1037 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1038 } 1039 else if ( NULL == psHciContext->p_device_mgmt_info ) 1040 { 1041 status = PHNFCSTVAL(CID_NFC_HCI, 1042 NFCSTATUS_INVALID_HCI_INFORMATION); 1043 } 1044 else 1045 { 1046 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 1047 psHciContext->p_device_mgmt_info ; 1048 switch(DevMgmt_seq) 1049 { 1050 case RESET_SEQ: 1051 case INIT_SEQ: 1052 { 1053 p_device_mgmt_info->current_seq = DEV_MGMT_PIPE_OPEN; 1054 p_device_mgmt_info->next_seq = DEV_MGMT_PIPE_OPEN ; 1055 }break; 1056 case UPDATE_SEQ: 1057 { 1058 p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq; 1059 1060 }break; 1061 case REL_SEQ: 1062 { 1063 p_device_mgmt_info->current_seq = DEV_MGMT_EVT_AUTONOMOUS; 1064 p_device_mgmt_info->next_seq = DEV_MGMT_EVT_AUTONOMOUS ; 1065 }break; 1066 default: 1067 { 1068 break; 1069 } 1070 }/* End of Update Sequence Switch */ 1071 } 1072 return status; 1073 1074 } 1075 1076 1077 1078 /*! 1079 * \brief Perform the System Management Tests 1080 * provided by the corresponding peripheral device. 1081 * 1082 * This function performs the System Management Tests provided by the NFC 1083 * Peripheral device. 1084 */ 1085 1086 NFCSTATUS 1087 phHciNfc_DevMgmt_Test( 1088 void *psContext, 1089 void *pHwRef, 1090 uint8_t test_type, 1091 phNfc_sData_t *test_param 1092 ) 1093 { 1094 phHciNfc_sContext_t *psHciContext = 1095 (phHciNfc_sContext_t *)psContext ; 1096 NFCSTATUS status = NFCSTATUS_SUCCESS; 1097 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 1098 uint8_t pipe_id = (uint8_t)HCI_UNKNOWN_PIPE_ID; 1099 1100 if( (NULL == psHciContext) || (NULL == pHwRef) ) 1101 { 1102 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1103 } 1104 else if( NULL == psHciContext->p_device_mgmt_info ) 1105 { 1106 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1107 } 1108 else 1109 { 1110 p_pipe_info = ((phHciNfc_DevMgmt_Info_t *) 1111 psHciContext->p_device_mgmt_info)->p_pipe_info ; 1112 switch(test_type) 1113 { 1114 case NXP_SELF_TEST_ANTENNA: 1115 case NXP_SELF_TEST_SWP: 1116 case NXP_SELF_TEST_PRBS: 1117 /* case NXP_SELF_TEST_NFCWI: */ 1118 { 1119 if (NULL != p_pipe_info) 1120 { 1121 pipe_id = p_pipe_info->pipe.pipe_id ; 1122 if ( NULL != test_param ) 1123 { 1124 p_pipe_info->param_info = test_param->buffer; 1125 p_pipe_info->param_length = (uint8_t)test_param->length; 1126 } 1127 status = 1128 phHciNfc_Send_DevMgmt_Command( psHciContext, pHwRef, 1129 pipe_id, (uint8_t)test_type ); 1130 } 1131 else 1132 { 1133 status = PHNFCSTVAL(CID_NFC_HCI, 1134 NFCSTATUS_INVALID_HCI_INFORMATION); 1135 } 1136 break; 1137 } 1138 default: 1139 { 1140 status = PHNFCSTVAL(CID_NFC_HCI, 1141 NFCSTATUS_FEATURE_NOT_SUPPORTED); 1142 break; 1143 } 1144 } 1145 1146 } 1147 return status; 1148 } 1149 1150 1151 /*! 1152 * \brief Receives the HCI Response from the corresponding peripheral device. 1153 * 1154 * This function receives the HCI Command Response from the connected NFC 1155 * Peripheral device. 1156 */ 1157 static 1158 NFCSTATUS 1159 phHciNfc_Recv_DevMgmt_Response( 1160 void *psContext, 1161 void *pHwRef, 1162 uint8_t *pResponse, 1163 #ifdef ONE_BYTE_LEN 1164 uint8_t length 1165 #else 1166 uint16_t length 1167 #endif 1168 ) 1169 { 1170 phHciNfc_sContext_t *psHciContext = 1171 (phHciNfc_sContext_t *)psContext ; 1172 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 1173 NFCSTATUS status = NFCSTATUS_SUCCESS; 1174 uint8_t prev_cmd = ANY_GET_PARAMETER; 1175 1176 if( (NULL == psHciContext) || (NULL == pHwRef) ) 1177 { 1178 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1179 } 1180 else if( NULL == psHciContext->p_device_mgmt_info ) 1181 { 1182 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1183 } 1184 else 1185 { 1186 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 1187 psHciContext->p_device_mgmt_info ; 1188 prev_cmd = p_device_mgmt_info->p_pipe_info->prev_msg ; 1189 switch(prev_cmd) 1190 { 1191 case ANY_GET_PARAMETER: 1192 { 1193 status = phHciNfc_DevMgmt_InfoUpdate(psHciContext, 1194 (phHal_sHwReference_t *)pHwRef, 1195 p_device_mgmt_info->p_pipe_info->reg_index, 1196 &pResponse[HCP_HEADER_LEN], 1197 (uint8_t)(length - HCP_HEADER_LEN)); 1198 break; 1199 } 1200 case ANY_SET_PARAMETER: 1201 { 1202 break; 1203 } 1204 case ANY_OPEN_PIPE: 1205 { 1206 break; 1207 } 1208 case ANY_CLOSE_PIPE: 1209 { 1210 phOsalNfc_FreeMemory(p_device_mgmt_info->p_pipe_info); 1211 p_device_mgmt_info->p_pipe_info = NULL; 1212 psHciContext->p_pipe_list[PIPETYPE_STATIC_LINK] = NULL; 1213 break; 1214 } 1215 case NXP_DBG_READ: 1216 { 1217 *p_device_mgmt_info->p_val = (uint8_t)( length > HCP_HEADER_LEN ) ? 1218 pResponse[HCP_HEADER_LEN]: 0; 1219 p_device_mgmt_info->p_val = NULL; 1220 1221 } 1222 /* fall through */ 1223 case NXP_DBG_WRITE: 1224 { 1225 break; 1226 } 1227 /* Self Test Commands */ 1228 case NXP_SELF_TEST_ANTENNA: 1229 case NXP_SELF_TEST_SWP: 1230 case NXP_SELF_TEST_NFCWI: 1231 case NXP_SELF_TEST_PRBS: 1232 { 1233 p_device_mgmt_info->test_status = (uint8_t) ( length > HCP_HEADER_LEN ) ? 1234 pResponse[HCP_HEADER_LEN]: 0; 1235 p_device_mgmt_info->test_result.buffer = (uint8_t)( length > HCP_HEADER_LEN ) ? 1236 &pResponse[HCP_HEADER_LEN]: NULL; 1237 p_device_mgmt_info->test_result.length = ( length - HCP_HEADER_LEN ); 1238 break; 1239 } 1240 default: 1241 { 1242 status = PHNFCSTVAL(CID_NFC_HCI, 1243 NFCSTATUS_INVALID_HCI_RESPONSE); 1244 break; 1245 } 1246 } 1247 if( NFCSTATUS_SUCCESS == status ) 1248 { 1249 if( NULL != p_device_mgmt_info->p_pipe_info) 1250 { 1251 p_device_mgmt_info->p_pipe_info->prev_status = NFCSTATUS_SUCCESS; 1252 } 1253 p_device_mgmt_info->current_seq = p_device_mgmt_info->next_seq; 1254 } 1255 1256 } 1257 return status; 1258 } 1259 1260 /*! 1261 * \brief Receives the HCI Event from the corresponding peripheral device. 1262 * 1263 * This function receives the HCI Event from the connected NFC 1264 * Peripheral device. 1265 */ 1266 1267 static 1268 NFCSTATUS 1269 phHciNfc_Recv_DevMgmt_Event( 1270 void *psContext, 1271 void *pHwRef, 1272 uint8_t *pEvent, 1273 #ifdef ONE_BYTE_LEN 1274 uint8_t length 1275 #else 1276 uint16_t length 1277 #endif 1278 ) 1279 { 1280 phHciNfc_sContext_t *psHciContext = 1281 (phHciNfc_sContext_t *)psContext ; 1282 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 1283 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 1284 phHciNfc_HCP_Message_t *hcp_message = NULL; 1285 NFCSTATUS status = NFCSTATUS_SUCCESS; 1286 phHal_sEventInfo_t event_info; 1287 uint8_t event = (uint8_t) HCP_MSG_INSTRUCTION_INVALID; 1288 1289 if( (NULL == psHciContext) || (NULL == pHwRef) ) 1290 { 1291 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1292 } 1293 else if( NULL == psHciContext->p_device_mgmt_info ) 1294 { 1295 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED); 1296 } 1297 else 1298 { 1299 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 1300 psHciContext->p_device_mgmt_info ; 1301 hcp_packet = (phHciNfc_HCP_Packet_t *)pEvent; 1302 hcp_message = &hcp_packet->msg.message; 1303 1304 /* Get the Event instruction bits from the Message Header */ 1305 event = (uint8_t) GET_BITS8( hcp_message->msg_header, 1306 HCP_MSG_INSTRUCTION_OFFSET, HCP_MSG_INSTRUCTION_LEN); 1307 event_info.eventHost = phHal_eHostController ; 1308 event_info.eventSource = phHal_ePCD_DevType; 1309 1310 switch(event) 1311 { 1312 /* Information Events */ 1313 case NXP_EVT_INFO_TXLDO_OVERCUR: 1314 { 1315 event_info.eventType = NFC_INFO_TXLDO_OVERCUR; 1316 break; 1317 } 1318 case NXP_EVT_INFO_PMUVCC: 1319 { 1320 p_device_mgmt_info->pmuvcc_status = (uint8_t) ( length > HCP_HEADER_LEN ) ? 1321 pEvent[HCP_HEADER_LEN]: 0; 1322 break; 1323 } 1324 case NXP_EVT_INFO_EXT_RF_FIELD: 1325 { 1326 event_info.eventSource = phHal_ePICC_DevType ; 1327 p_device_mgmt_info->rf_status = (uint8_t) ( length > HCP_HEADER_LEN ) ? 1328 pEvent[HCP_HEADER_LEN]: 0; 1329 #ifdef EVT_INFO_EXT_EVT_DIRECT 1330 event_info.eventType = ( CE_EVT_NFC_FIELD_ON == 1331 (p_device_mgmt_info->rf_status & 0x1FU))? 1332 NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF; 1333 #else 1334 event_info.eventType = (TRUE == p_device_mgmt_info->rf_status)? 1335 NFC_EVT_FIELD_ON : NFC_EVT_FIELD_OFF; 1336 #endif 1337 break; 1338 } 1339 case NXP_EVT_INFO_MEM_VIOLATION: 1340 { 1341 event_info.eventType = NFC_INFO_MEM_VIOLATION; 1342 break; 1343 } 1344 case NXP_EVT_INFO_TEMP_OVERHEAT: 1345 { 1346 p_device_mgmt_info->overheat_status = (uint8_t)( length > HCP_HEADER_LEN ) ? 1347 pEvent[HCP_HEADER_LEN]: 0; 1348 event_info.eventType = NFC_INFO_TEMP_OVERHEAT; 1349 event_info.eventInfo.overheat_status = 1350 p_device_mgmt_info->overheat_status; 1351 break; 1352 } 1353 default: 1354 { 1355 status = PHNFCSTVAL(CID_NFC_HCI, 1356 NFCSTATUS_INVALID_HCI_RESPONSE); 1357 break; 1358 } 1359 } 1360 if( NFCSTATUS_SUCCESS == status ) 1361 { 1362 if( NULL != p_device_mgmt_info->p_pipe_info) 1363 { 1364 p_device_mgmt_info->p_pipe_info->prev_status = 1365 NFCSTATUS_SUCCESS; 1366 } 1367 p_device_mgmt_info->current_seq = 1368 p_device_mgmt_info->next_seq; 1369 phHciNfc_Notify_Event(psHciContext, pHwRef, 1370 NFC_NOTIFY_EVENT, &event_info); 1371 } 1372 } 1373 return status; 1374 } 1375 1376 1377 static 1378 NFCSTATUS 1379 phHciNfc_DevMgmt_InfoUpdate( 1380 phHciNfc_sContext_t *psHciContext, 1381 phHal_sHwReference_t *pHwRef, 1382 uint8_t index, 1383 uint8_t *reg_value, 1384 uint8_t reg_length 1385 ) 1386 { 1387 phHciNfc_DevMgmt_Info_t *p_device_mgmt_info=NULL; 1388 NFCSTATUS status = NFCSTATUS_SUCCESS; 1389 uint8_t i=0; 1390 1391 PHNFC_UNUSED_VARIABLE(pHwRef); 1392 if( (NULL == psHciContext) 1393 || (NULL == reg_value) 1394 || (reg_length == 0) 1395 ) 1396 { 1397 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1398 } 1399 else if ( NULL == psHciContext->p_device_mgmt_info ) 1400 { 1401 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_HCI_INFORMATION); 1402 } 1403 else 1404 { 1405 p_device_mgmt_info = (phHciNfc_DevMgmt_Info_t *) 1406 psHciContext->p_device_mgmt_info ; 1407 1408 switch(index) 1409 { 1410 case DEVICE_INFO_EEPROM_INDEX: 1411 { 1412 p_device_mgmt_info->eeprom_crc = reg_value[i]; 1413 break; 1414 } 1415 default: 1416 { 1417 break; 1418 } 1419 } 1420 1421 } /* End of Context and the PN544 Device information validity check */ 1422 1423 return status; 1424 } 1425 1426 1427 1428 /*! 1429 * \brief Sends the RF Settings HCI Additonal Commands to the connected 1430 * reader device. 1431 * 1432 * This function Sends the RF Settings HCI Command frames in the HCP packet 1433 * format to the connected reader device. 1434 */ 1435 static 1436 NFCSTATUS 1437 phHciNfc_Send_DevMgmt_Command ( 1438 phHciNfc_sContext_t *psHciContext, 1439 void *pHwRef, 1440 uint8_t pipe_id, 1441 uint8_t cmd 1442 ) 1443 { 1444 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 1445 phHciNfc_HCP_Message_t *hcp_message = NULL; 1446 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 1447 uint8_t length=0; 1448 uint8_t i = 0; 1449 NFCSTATUS status = NFCSTATUS_SUCCESS; 1450 1451 if( (NULL == psHciContext) 1452 || ( pipe_id > PHHCINFC_MAX_PIPE) 1453 ||(NULL == psHciContext->p_pipe_list[pipe_id]) 1454 ) 1455 { 1456 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1457 HCI_DEBUG("%s: Invalid Arguments passed \n", 1458 "phHciNfc_Send_DevMgmt_Command"); 1459 } 1460 else 1461 { 1462 p_pipe_info = (phHciNfc_Pipe_Info_t *) 1463 psHciContext->p_pipe_list[pipe_id]; 1464 psHciContext->tx_total = 0 ; 1465 length += HCP_HEADER_LEN ; 1466 switch( cmd ) 1467 { 1468 /* Self Test Commands */ 1469 case NXP_SELF_TEST_ANTENNA: 1470 case NXP_SELF_TEST_SWP: 1471 case NXP_SELF_TEST_NFCWI: 1472 case NXP_SELF_TEST_PRBS: 1473 /* Internal Properietary Commands */ 1474 case NXP_DBG_READ: 1475 case NXP_DBG_WRITE: 1476 { 1477 1478 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 1479 /* Construct the HCP Frame */ 1480 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT, 1481 (uint8_t) pipe_id, HCP_MSG_TYPE_COMMAND, cmd); 1482 hcp_message = &(hcp_packet->msg.message); 1483 /* Append the RF Setting Parameter also the optional Value */ 1484 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload, 1485 i, p_pipe_info->param_info, 1486 p_pipe_info->param_length); 1487 length =(uint8_t)(length + i + p_pipe_info->param_length); 1488 break; 1489 } 1490 default: 1491 { 1492 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED ); 1493 HCI_DEBUG("%s: Statement Should Not Occur \n", 1494 "phHciNfc_Send_DevMgmt_Command"); 1495 break; 1496 } 1497 } 1498 if( NFCSTATUS_SUCCESS == status ) 1499 { 1500 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_COMMAND; 1501 p_pipe_info->prev_msg = cmd; 1502 psHciContext->tx_total = length; 1503 psHciContext->response_pending = TRUE ; 1504 1505 /* Send the Constructed HCP packet to the lower layer */ 1506 status = phHciNfc_Send_HCP( psHciContext, pHwRef ); 1507 p_pipe_info->prev_status = NFCSTATUS_PENDING; 1508 } 1509 } 1510 1511 return status; 1512 } 1513 1514 1515 1516 /*! 1517 * \brief Sends the RF Settings HCI Additonal Events to the connected 1518 * reader device. 1519 * 1520 * This function Sends the RF Settings HCI Events frames in the HCP packet 1521 * format to the connected reader device. 1522 */ 1523 1524 static 1525 NFCSTATUS 1526 phHciNfc_Send_DevMgmt_Event ( 1527 phHciNfc_sContext_t *psHciContext, 1528 void *pHwRef, 1529 uint8_t pipe_id, 1530 uint8_t event 1531 ) 1532 { 1533 phHciNfc_HCP_Packet_t *hcp_packet = NULL; 1534 phHciNfc_HCP_Message_t *hcp_message = NULL; 1535 phHciNfc_Pipe_Info_t *p_pipe_info = NULL; 1536 uint8_t length=0; 1537 uint8_t i = 0; 1538 NFCSTATUS status = NFCSTATUS_SUCCESS; 1539 1540 if( (NULL == psHciContext) 1541 || ( pipe_id > PHHCINFC_MAX_PIPE) 1542 ||(NULL == psHciContext->p_pipe_list[pipe_id]) 1543 ) 1544 { 1545 status = PHNFCSTVAL(CID_NFC_HCI, NFCSTATUS_INVALID_PARAMETER); 1546 HCI_DEBUG("%s: Invalid Arguments passed \n", 1547 "phHciNfc_Send_DevMgmt_Event"); 1548 } 1549 else 1550 { 1551 p_pipe_info = (phHciNfc_Pipe_Info_t *) 1552 psHciContext->p_pipe_list[pipe_id]; 1553 psHciContext->tx_total = 0 ; 1554 length += HCP_HEADER_LEN ; 1555 if( NXP_EVT_SET_AUTONOMOUS == event ) 1556 { 1557 1558 hcp_packet = (phHciNfc_HCP_Packet_t *) psHciContext->send_buffer; 1559 /* Construct the HCP Frame */ 1560 phHciNfc_Build_HCPFrame(hcp_packet,HCP_CHAINBIT_DEFAULT, 1561 (uint8_t) pipe_id, HCP_MSG_TYPE_EVENT, event); 1562 hcp_message = &(hcp_packet->msg.message); 1563 /* Append the RF Setting Parameter also the optional Value */ 1564 phHciNfc_Append_HCPFrame((uint8_t *)hcp_message->payload, 1565 i, p_pipe_info->param_info, 1566 p_pipe_info->param_length); 1567 length =(uint8_t)(length + i + p_pipe_info->param_length); 1568 } 1569 else 1570 { 1571 status = PHNFCSTVAL( CID_NFC_HCI, NFCSTATUS_FEATURE_NOT_SUPPORTED ); 1572 HCI_DEBUG("%s: Statement Should Not Occur \n", 1573 "phHciNfc_Send_DevMgmt_Event"); 1574 } 1575 if( NFCSTATUS_SUCCESS == status ) 1576 { 1577 p_pipe_info->sent_msg_type = HCP_MSG_TYPE_EVENT; 1578 p_pipe_info->prev_msg = event; 1579 psHciContext->tx_total = length; 1580 1581 /* Send the Constructed HCP packet to the lower layer */ 1582 status = phHciNfc_Send_HCP( psHciContext, pHwRef ); 1583 p_pipe_info->prev_status = NFCSTATUS_PENDING; 1584 } 1585 } 1586 1587 return status; 1588 } 1589 1590 1591 1592 1593 1594