1 /* 2 * Copyright (C) 2012-2014 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 #include <phNxpNciHal_ext.h> 17 #include <phNxpNciHal.h> 18 #include <phTmlNfc.h> 19 #include <phDal4Nfc_messageQueueLib.h> 20 #include <phNxpNciHal_NfcDepSWPrio.h> 21 #include <phNxpNciHal_Kovio.h> 22 #include <phNxpLog.h> 23 #include <phNxpConfig.h> 24 25 #define HAL_EXTNS_WRITE_RSP_TIMEOUT (1000) /* Timeout value to wait for response from PN548AD */ 26 27 #undef P2P_PRIO_LOGIC_HAL_IMP 28 29 /******************* Global variables *****************************************/ 30 extern phNxpNciHal_Control_t nxpncihal_ctrl; 31 extern phNxpNciProfile_Control_t nxpprofile_ctrl; 32 33 extern int kovio_detected; 34 extern int disable_kovio; 35 extern int send_to_upper_kovio; 36 extern uint32_t cleanup_timer; 37 uint8_t icode_detected = 0x00; 38 uint8_t icode_send_eof = 0x00; 39 #if(NFC_NXP_CHIP_TYPE == PN548C2) 40 uint8_t nfcdep_detected = 0x00; 41 #endif 42 static uint8_t ee_disc_done = 0x00; 43 uint8_t EnableP2P_PrioLogic = FALSE; 44 static uint32_t RfDiscID = 1; 45 static uint32_t RfProtocolType = 4; 46 /* NFCEE Set mode */ 47 static uint8_t setEEModeDone = 0x00; 48 static uint8_t cmd_nfcee_setmode_enable[] = { 0x22, 0x01, 0x02, 0x01, 0x01 }; 49 50 /* External global variable to get FW version from NCI response*/ 51 extern uint32_t wFwVerRsp; 52 /* External global variable to get FW version from FW file*/ 53 extern uint16_t wFwVer; 54 55 uint16_t fw_maj_ver; 56 uint16_t rom_version; 57 /* local buffer to store CORE_INIT response */ 58 static uint32_t bCoreInitRsp[40]; 59 static uint32_t iCoreInitRspLen; 60 61 extern uint32_t timeoutTimerId; 62 63 extern NFCSTATUS read_retry(); 64 65 /************** HAL extension functions ***************************************/ 66 static void hal_extns_write_rsp_timeout_cb(uint32_t TimerId, void *pContext); 67 68 /*Proprietary cmd sent to HAL to send reader mode flag 69 * Last byte of 4 byte proprietary cmd data contains ReaderMode flag 70 * If this flag is enabled, NFC-DEP protocol is modified to T3T protocol 71 * if FrameRF interface is selected. This needs to be done as the FW 72 * always sends Ntf for FrameRF with NFC-DEP even though FrameRF with T3T is 73 * previously selected with DISCOVER_SELECT_CMD 74 */ 75 #define PROPRIETARY_CMD_FELICA_READER_MODE 0xFE 76 static uint8_t gFelicaReaderMode; 77 78 79 /******************************************************************************* 80 ** 81 ** Function phNxpNciHal_ext_init 82 ** 83 ** Description initialize extension function 84 ** 85 *******************************************************************************/ 86 void phNxpNciHal_ext_init (void) 87 { 88 icode_detected = 0x00; 89 icode_send_eof = 0x00; 90 setEEModeDone = 0x00; 91 kovio_detected = 0x00; 92 disable_kovio = 0x00; 93 send_to_upper_kovio = 0x01; 94 EnableP2P_PrioLogic = FALSE; 95 } 96 97 /******************************************************************************* 98 ** 99 ** Function phNxpNciHal_process_ext_rsp 100 ** 101 ** Description Process extension function response 102 ** 103 ** Returns NFCSTATUS_SUCCESS if success 104 ** 105 *******************************************************************************/ 106 NFCSTATUS phNxpNciHal_process_ext_rsp (uint8_t *p_ntf, uint16_t *p_len) 107 { 108 109 NFCSTATUS status = NFCSTATUS_SUCCESS; 110 uint16_t rf_technology_length_param = 0; 111 112 if (p_ntf[0] == 0x61 && 113 p_ntf[1] == 0x05 && 114 p_ntf[4] == 0x03 && 115 p_ntf[5] == 0x05 && 116 nxpprofile_ctrl.profile_type == EMV_CO_PROFILE) 117 { 118 p_ntf[4] = 0xFF; 119 p_ntf[5] = 0xFF; 120 p_ntf[6] = 0xFF; 121 NXPLOG_NCIHAL_D("Nfc-Dep Detect in EmvCo profile - Restart polling"); 122 } 123 124 if (p_ntf[0] == 0x61 && 125 p_ntf[1] == 0x05 && 126 p_ntf[4] == 0x01 && 127 p_ntf[5] == 0x05 && 128 p_ntf[6] == 0x02 && 129 gFelicaReaderMode) 130 { 131 /*If FelicaReaderMode is enabled,Change Protocol to T3T from NFC-DEP 132 * when FrameRF interface is selected*/ 133 p_ntf[5] = 0x03; 134 NXPLOG_NCIHAL_D("FelicaReaderMode:Activity 1.1"); 135 } 136 137 #ifdef P2P_PRIO_LOGIC_HAL_IMP 138 if(p_ntf[0] == 0x61 && 139 p_ntf[1] == 0x05 && 140 p_ntf[4] == 0x02 && 141 p_ntf[5] == 0x04 && 142 nxpprofile_ctrl.profile_type == NFC_FORUM_PROFILE) 143 { 144 EnableP2P_PrioLogic = TRUE; 145 } 146 147 NXPLOG_NCIHAL_D("Is EnableP2P_PrioLogic: 0x0%X", EnableP2P_PrioLogic); 148 if(phNxpDta_IsEnable() == FALSE) 149 { 150 if ((icode_detected != 1)&&(kovio_detected != 1) && (EnableP2P_PrioLogic == TRUE)) 151 { 152 if (phNxpNciHal_NfcDep_comapre_ntf(p_ntf, *p_len) == NFCSTATUS_FAILED) 153 { 154 status = phNxpNciHal_NfcDep_rsp_ext(p_ntf,p_len); 155 if(status != NFCSTATUS_INVALID_PARAMETER) 156 { 157 return status; 158 } 159 } 160 } 161 } 162 #endif 163 164 status = NFCSTATUS_SUCCESS; 165 status = phNxpNciHal_kovio_rsp_ext(p_ntf,p_len); 166 167 if (p_ntf[0] == 0x61 && 168 p_ntf[1] == 0x05) 169 { 170 #if(NFC_NXP_CHIP_TYPE == PN548C2) 171 if (nfcdep_detected) 172 { 173 nfcdep_detected = 0x00; 174 } 175 #endif 176 177 switch (p_ntf[4]) 178 { 179 case 0x00: 180 NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFCEE Direct RF"); 181 break; 182 case 0x01: 183 NXPLOG_NCIHAL_D("NxpNci: RF Interface = Frame RF"); 184 break; 185 case 0x02: 186 NXPLOG_NCIHAL_D("NxpNci: RF Interface = ISO-DEP"); 187 break; 188 case 0x03: 189 NXPLOG_NCIHAL_D("NxpNci: RF Interface = NFC-DEP"); 190 #if(NFC_NXP_CHIP_TYPE == PN548C2) 191 nfcdep_detected = 0x01; 192 #endif 193 break; 194 case 0x80: 195 NXPLOG_NCIHAL_D("NxpNci: RF Interface = MIFARE"); 196 break; 197 default: 198 NXPLOG_NCIHAL_D("NxpNci: RF Interface = Unknown"); 199 break; 200 } 201 202 switch (p_ntf[5]) 203 { 204 case 0x01: 205 NXPLOG_NCIHAL_D("NxpNci: Protocol = T1T"); 206 phNxpDta_T1TEnable(); 207 break; 208 case 0x02: 209 NXPLOG_NCIHAL_D("NxpNci: Protocol = T2T"); 210 break; 211 case 0x03: 212 NXPLOG_NCIHAL_D("NxpNci: Protocol = T3T"); 213 break; 214 case 0x04: 215 NXPLOG_NCIHAL_D("NxpNci: Protocol = ISO-DEP"); 216 break; 217 case 0x05: 218 NXPLOG_NCIHAL_D("NxpNci: Protocol = NFC-DEP"); 219 break; 220 case 0x06: 221 NXPLOG_NCIHAL_D("NxpNci: Protocol = 15693"); 222 break; 223 case 0x80: 224 NXPLOG_NCIHAL_D("NxpNci: Protocol = MIFARE"); 225 break; 226 #if(NFC_NXP_CHIP_TYPE != PN547C2) 227 case 0x81: 228 #else 229 case 0x8A: 230 #endif 231 NXPLOG_NCIHAL_D("NxpNci: Protocol = Kovio"); 232 break; 233 default: 234 NXPLOG_NCIHAL_D("NxpNci: Protocol = Unknown"); 235 break; 236 } 237 238 switch (p_ntf[6]) 239 { 240 case 0x00: 241 NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Poll"); 242 break; 243 case 0x01: 244 NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Poll"); 245 break; 246 case 0x02: 247 NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Poll"); 248 break; 249 case 0x03: 250 NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Poll"); 251 break; 252 case 0x05: 253 NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Poll"); 254 break; 255 case 0x06: 256 NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Poll"); 257 break; 258 #if(NFC_NXP_CHIP_TYPE != PN547C2) 259 case 0x70: 260 #else 261 case 0x77: 262 #endif 263 NXPLOG_NCIHAL_D("NxpNci: Mode = Kovio"); 264 break; 265 case 0x80: 266 NXPLOG_NCIHAL_D("NxpNci: Mode = A Passive Listen"); 267 break; 268 case 0x81: 269 NXPLOG_NCIHAL_D("NxpNci: Mode = B Passive Listen"); 270 break; 271 case 0x82: 272 NXPLOG_NCIHAL_D("NxpNci: Mode = F Passive Listen"); 273 break; 274 case 0x83: 275 NXPLOG_NCIHAL_D("NxpNci: Mode = A Active Listen"); 276 break; 277 case 0x85: 278 NXPLOG_NCIHAL_D("NxpNci: Mode = F Active Listen"); 279 break; 280 case 0x86: 281 NXPLOG_NCIHAL_D("NxpNci: Mode = 15693 Passive Listen"); 282 break; 283 default: 284 NXPLOG_NCIHAL_D("NxpNci: Mode = Unknown"); 285 break; 286 } 287 } 288 289 if (p_ntf[0] == 0x61 && 290 p_ntf[1] == 0x05 && 291 p_ntf[2] == 0x15 && 292 p_ntf[4] == 0x01 && 293 p_ntf[5] == 0x06 && 294 p_ntf[6] == 0x06) 295 { 296 NXPLOG_NCIHAL_D ("> Going through workaround - notification of ISO 15693"); 297 icode_detected = 0x01; 298 p_ntf[21] = 0x01; 299 p_ntf[22] = 0x01; 300 } 301 else if (icode_detected == 1 && 302 icode_send_eof == 2) 303 { 304 icode_send_eof = 3; 305 } 306 else if (p_ntf[0] == 0x00 && 307 p_ntf[1] == 0x00 && 308 icode_detected == 1) 309 { 310 if (icode_send_eof == 3) 311 { 312 icode_send_eof = 0; 313 } 314 if (p_ntf[p_ntf[2]+ 2] == 0x00) 315 { 316 NXPLOG_NCIHAL_D ("> Going through workaround - data of ISO 15693"); 317 p_ntf[2]--; 318 (*p_len)--; 319 } 320 else 321 { 322 p_ntf[p_ntf[2]+ 2] |= 0x01; 323 } 324 } 325 else if (p_ntf[2] == 0x02 && 326 p_ntf[1] == 0x00 && icode_detected == 1) 327 { 328 NXPLOG_NCIHAL_D ("> ICODE EOF response do not send to upper layer"); 329 } 330 else if(p_ntf[0] == 0x61 && 331 p_ntf[1] == 0x06 && icode_detected == 1) 332 { 333 NXPLOG_NCIHAL_D ("> Polling Loop Re-Started"); 334 icode_detected = 0; 335 icode_send_eof = 0; 336 } 337 else if(*p_len == 4 && 338 p_ntf[0] == 0x40 && 339 p_ntf[1] == 0x02 && 340 p_ntf[2] == 0x01 && 341 p_ntf[3] == 0x06 ) 342 { 343 NXPLOG_NCIHAL_D ("> Deinit workaround for LLCP set_config 0x%x 0x%x 0x%x", p_ntf[21], p_ntf[22], p_ntf[23]); 344 p_ntf[0] = 0x40; 345 p_ntf[1] = 0x02; 346 p_ntf[2] = 0x02; 347 p_ntf[3] = 0x00; 348 p_ntf[4] = 0x00; 349 *p_len = 5; 350 } 351 else if ((p_ntf[0] == 0x40) && (p_ntf[1] == 0x01)) 352 { 353 int len = p_ntf[2] + 2; /*include 2 byte header*/ 354 wFwVerRsp= (((uint32_t)p_ntf[len - 2])<< 16U)|(((uint32_t)p_ntf[len - 1])<< 8U)|p_ntf[len]; 355 if(wFwVerRsp == 0) 356 status = NFCSTATUS_FAILED; 357 iCoreInitRspLen = *p_len; 358 memcpy(bCoreInitRsp, p_ntf, *p_len); 359 NXPLOG_NCIHAL_D ("NxpNci> FW Version: %x.%x.%x", p_ntf[len-2], p_ntf[len-1], p_ntf[len]); 360 fw_maj_ver = p_ntf[len-1]; 361 rom_version = p_ntf[len-2]; 362 } 363 //4200 02 00 01 364 else if(p_ntf[0] == 0x42 && p_ntf[1] == 0x00 && ee_disc_done == 0x01) 365 { 366 NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP"); 367 if(p_ntf[4] == 0x01) 368 { 369 p_ntf[4] = 0x00; 370 371 ee_disc_done = 0x00; 372 } 373 NXPLOG_NCIHAL_D("Going through workaround - NFCEE_DISCOVER_RSP - END"); 374 375 } 376 else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x03 /*&& cleanup_timer!=0*/) 377 { 378 if(cleanup_timer!=0) 379 { 380 /* if RF Notification Type of RF_DISCOVER_NTF is Last Notification */ 381 if(0== (*(p_ntf + 2 + (*(p_ntf+2))))) 382 { 383 phNxpNciHal_select_RF_Discovery(RfDiscID,RfProtocolType); 384 status = NFCSTATUS_FAILED; 385 return status; 386 } 387 else 388 { 389 RfDiscID=p_ntf[3]; 390 RfProtocolType=p_ntf[4]; 391 } 392 status = NFCSTATUS_FAILED; 393 return status; 394 395 } 396 } 397 else if(p_ntf[0] == 0x41 && p_ntf[1] == 0x04 && cleanup_timer!=0) 398 { 399 status = NFCSTATUS_FAILED; 400 return status; 401 } 402 else if(p_ntf[0] == 0x60 && p_ntf[1] == 0x00) 403 { 404 NXPLOG_NCIHAL_E ("CORE_RESET_NTF received!"); 405 #if(NFC_NXP_CHIP_TYPE == PN548C2) 406 if ( nfcdep_detected && 407 !(p_ntf[2] == 0x06 && p_ntf[3] == 0xA0 && p_ntf[4] == 0x00 408 && ((p_ntf[5] == 0xC9 && p_ntf[6] == 0x95 409 && p_ntf[7] == 0x00 && p_ntf[8] == 0x00) 410 || (p_ntf[5] == 0x07 && p_ntf[6] == 0x39 411 && p_ntf[7] == 0xF2 && p_ntf[8] == 0x00)) )) 412 { 413 nfcdep_detected = 0x00; 414 } 415 #endif 416 phNxpNciHal_emergency_recovery (); 417 status = NFCSTATUS_FAILED; 418 return status; 419 } 420 #if(NFC_NXP_CHIP_TYPE == PN547C2) 421 else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x05 422 && p_ntf[4] == 0x02 && p_ntf[5] == 0x80 423 && p_ntf[6] == 0x00 ) 424 { 425 NXPLOG_NCIHAL_D("Going through workaround - iso-dep interface mifare protocol with sak value not equal to 0x20"); 426 rf_technology_length_param = p_ntf[9]; 427 if((p_ntf[ 9 + rf_technology_length_param] & 0x20) != 0x20) 428 { 429 p_ntf[4] = 0x80; 430 } 431 } 432 #endif 433 else if (*p_len == 4 && 434 p_ntf[0] == 0x4F && 435 p_ntf[1] == 0x11 && 436 p_ntf[2] == 0x01 ) 437 { 438 if (p_ntf[3] == 0x00) 439 { 440 NXPLOG_NCIHAL_D ("> Workaround for ISO-DEP Presence Check, ignore response and wait for notification"); 441 p_ntf[0] = 0x60; 442 p_ntf[1] = 0x06; 443 p_ntf[2] = 0x03; 444 p_ntf[3] = 0x01; 445 p_ntf[4] = 0x00; 446 p_ntf[5] = 0x01; 447 *p_len = 6; 448 } 449 else 450 { 451 NXPLOG_NCIHAL_D ("> Workaround for ISO-DEP Presence Check, presence check return failed"); 452 p_ntf[0] = 0x60; 453 p_ntf[1] = 0x08; 454 p_ntf[2] = 0x02; 455 p_ntf[3] = 0xB2; 456 p_ntf[4] = 0x00; 457 *p_len = 5; 458 459 } 460 } 461 else if (*p_len == 4 && 462 p_ntf[0] == 0x6F && 463 p_ntf[1] == 0x11 && 464 p_ntf[2] == 0x01 ) 465 { 466 if (p_ntf[3] == 0x01) 467 { 468 NXPLOG_NCIHAL_D ("> Workaround for ISO-DEP Presence Check - Card still in field"); 469 p_ntf[0] = 0x00; 470 p_ntf[1] = 0x00; 471 p_ntf[2] = 0x01; 472 p_ntf[3] = 0x7E; 473 } 474 else 475 { 476 NXPLOG_NCIHAL_D ("> Workaround for ISO-DEP Presence Check - Card not in field"); 477 p_ntf[0] = 0x60; 478 p_ntf[1] = 0x08; 479 p_ntf[2] = 0x02; 480 p_ntf[3] = 0xB2; 481 p_ntf[4] = 0x00; 482 *p_len = 5; 483 } 484 } 485 /* 486 else if(p_ntf[0] == 0x61 && p_ntf[1] == 0x05 && p_ntf[4] == 0x01 && p_ntf[5] == 0x00 && p_ntf[6] == 0x01) 487 { 488 NXPLOG_NCIHAL_D("Picopass type 3-B with undefined protocol is not supported, disabling"); 489 p_ntf[4] = 0xFF; 490 p_ntf[5] = 0xFF; 491 p_ntf[6] = 0xFF; 492 }*/ 493 494 return status; 495 } 496 497 /****************************************************************************** 498 * Function phNxpNciHal_process_ext_cmd_rsp 499 * 500 * Description This function process the extension command response. It 501 * also checks the received response to expected response. 502 * 503 * Returns returns NFCSTATUS_SUCCESS if response is as expected else 504 * returns failure. 505 * 506 ******************************************************************************/ 507 static NFCSTATUS phNxpNciHal_process_ext_cmd_rsp(uint16_t cmd_len, uint8_t *p_cmd) 508 { 509 NFCSTATUS status = NFCSTATUS_FAILED; 510 uint16_t data_written = 0; 511 512 /* Create the local semaphore */ 513 if (phNxpNciHal_init_cb_data(&nxpncihal_ctrl.ext_cb_data, NULL) 514 != NFCSTATUS_SUCCESS) 515 { 516 NXPLOG_NCIHAL_D("Create ext_cb_data failed"); 517 return NFCSTATUS_FAILED; 518 } 519 520 nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_SUCCESS; 521 522 /* Send ext command */ 523 data_written = phNxpNciHal_write_unlocked(cmd_len, p_cmd); 524 if (data_written != cmd_len) 525 { 526 NXPLOG_NCIHAL_D("phNxpNciHal_write failed for hal ext"); 527 goto clean_and_return; 528 } 529 530 /* Start timer */ 531 status = phOsalNfc_Timer_Start(timeoutTimerId, 532 HAL_EXTNS_WRITE_RSP_TIMEOUT, 533 &hal_extns_write_rsp_timeout_cb, 534 NULL); 535 if (NFCSTATUS_SUCCESS == status) 536 { 537 NXPLOG_NCIHAL_D("Response timer started"); 538 } 539 else 540 { 541 NXPLOG_NCIHAL_E("Response timer not started!!!"); 542 status = NFCSTATUS_FAILED; 543 goto clean_and_return; 544 } 545 546 /* Wait for rsp */ 547 NXPLOG_NCIHAL_D("Waiting after ext cmd sent"); 548 if (SEM_WAIT(nxpncihal_ctrl.ext_cb_data)) 549 { 550 NXPLOG_NCIHAL_E("p_hal_ext->ext_cb_data.sem semaphore error"); 551 goto clean_and_return; 552 } 553 554 /* Stop Timer */ 555 status = phOsalNfc_Timer_Stop(timeoutTimerId); 556 557 if (NFCSTATUS_SUCCESS == status) 558 { 559 NXPLOG_NCIHAL_D("Response timer stopped"); 560 } 561 else 562 { 563 NXPLOG_NCIHAL_E("Response timer stop ERROR!!!"); 564 status = NFCSTATUS_FAILED; 565 goto clean_and_return; 566 } 567 568 if(nxpncihal_ctrl.ext_cb_data.status != NFCSTATUS_SUCCESS) 569 { 570 NXPLOG_NCIHAL_E("Callback Status is failed!! Timer Expired!! Couldn't read it! 0x%x", nxpncihal_ctrl.ext_cb_data.status); 571 status = NFCSTATUS_FAILED; 572 goto clean_and_return; 573 } 574 575 NXPLOG_NCIHAL_D("Checking response"); 576 status = NFCSTATUS_SUCCESS; 577 578 clean_and_return: 579 phNxpNciHal_cleanup_cb_data(&nxpncihal_ctrl.ext_cb_data); 580 581 return status; 582 } 583 584 /****************************************************************************** 585 * Function phNxpNciHal_write_ext 586 * 587 * Description This function inform the status of phNxpNciHal_open 588 * function to libnfc-nci. 589 * 590 * Returns It return NFCSTATUS_SUCCESS then continue with send else 591 * sends NFCSTATUS_FAILED direct response is prepared and 592 * do not send anything to NFCC. 593 * 594 ******************************************************************************/ 595 596 NFCSTATUS phNxpNciHal_write_ext(uint16_t *cmd_len, uint8_t *p_cmd_data, 597 uint16_t *rsp_len, uint8_t *p_rsp_data) 598 { 599 NFCSTATUS status = NFCSTATUS_SUCCESS; 600 601 unsigned long retval = 0; 602 int isfound = GetNxpNumValue(NAME_MIFARE_READER_ENABLE, &retval, sizeof(unsigned long)); 603 604 phNxpNciHal_NfcDep_cmd_ext(p_cmd_data, cmd_len); 605 606 if(phNxpDta_IsEnable() == TRUE) 607 { 608 status = phNxpNHal_DtaUpdate(cmd_len, p_cmd_data,rsp_len, p_rsp_data); 609 } 610 611 if (p_cmd_data[0] == PROPRIETARY_CMD_FELICA_READER_MODE && 612 p_cmd_data[1] == PROPRIETARY_CMD_FELICA_READER_MODE && 613 p_cmd_data[2] == PROPRIETARY_CMD_FELICA_READER_MODE) 614 { 615 NXPLOG_NCIHAL_D ("Received proprietary command to set Felica Reader mode:%d",p_cmd_data[3]); 616 gFelicaReaderMode = p_cmd_data[3]; 617 /* frame the dummy response */ 618 *rsp_len = 4; 619 p_rsp_data[0] = 0x00; 620 p_rsp_data[1] = 0x00; 621 p_rsp_data[2] = 0x00; 622 p_rsp_data[3] = 0x00; 623 status = NFCSTATUS_FAILED; 624 } 625 else if (p_cmd_data[0] == 0x20 && 626 p_cmd_data[1] == 0x02 && 627 p_cmd_data[2] == 0x05 && 628 p_cmd_data[3] == 0x01 && 629 p_cmd_data[4] == 0xA0 && 630 p_cmd_data[5] == 0x44 && 631 p_cmd_data[6] == 0x01 && 632 p_cmd_data[7] == 0x01) 633 { 634 nxpprofile_ctrl.profile_type = EMV_CO_PROFILE; 635 NXPLOG_NCIHAL_D ("EMV_CO_PROFILE mode - Enabled"); 636 status = NFCSTATUS_SUCCESS; 637 } 638 else if (p_cmd_data[0] == 0x20 && 639 p_cmd_data[1] == 0x02 && 640 p_cmd_data[2] == 0x05 && 641 p_cmd_data[3] == 0x01 && 642 p_cmd_data[4] == 0xA0 && 643 p_cmd_data[5] == 0x44 && 644 p_cmd_data[6] == 0x01 && 645 p_cmd_data[7] == 0x00) 646 { 647 NXPLOG_NCIHAL_D ("NFC_FORUM_PROFILE mode - Enabled"); 648 nxpprofile_ctrl.profile_type = NFC_FORUM_PROFILE; 649 status = NFCSTATUS_SUCCESS; 650 } 651 652 if (nxpprofile_ctrl.profile_type == EMV_CO_PROFILE) 653 { 654 if (p_cmd_data[0] == 0x21 && 655 p_cmd_data[1] == 0x06 && 656 p_cmd_data[2] == 0x01 && 657 p_cmd_data[3] == 0x03) 658 { 659 #if 0 660 //Needs clarification whether to keep it or not 661 NXPLOG_NCIHAL_D ("EmvCo Poll mode - RF Deactivate discard"); 662 phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 663 *rsp_len = 4; 664 p_rsp_data[0] = 0x41; 665 p_rsp_data[1] = 0x06; 666 p_rsp_data[2] = 0x01; 667 p_rsp_data[3] = 0x00; 668 phNxpNciHal_print_packet("RECV", p_rsp_data, 4); 669 status = NFCSTATUS_FAILED; 670 #endif 671 } 672 else if(p_cmd_data[0] == 0x21 && 673 p_cmd_data[1] == 0x03 ) 674 { 675 NXPLOG_NCIHAL_D ("EmvCo Poll mode - Discover map only for A and B"); 676 p_cmd_data[2] = 0x05; 677 p_cmd_data[3] = 0x02; 678 p_cmd_data[4] = 0x00; 679 p_cmd_data[5] = 0x01; 680 p_cmd_data[6] = 0x01; 681 p_cmd_data[7] = 0x01; 682 *cmd_len = 8; 683 } 684 } 685 686 if (retval == 0x01 && 687 p_cmd_data[0] == 0x21 && 688 p_cmd_data[1] == 0x00) 689 { 690 NXPLOG_NCIHAL_D ("Going through extns - Adding Mifare in RF Discovery"); 691 p_cmd_data[2] += 3; 692 p_cmd_data[3] += 1; 693 p_cmd_data[*cmd_len] = 0x80; 694 p_cmd_data[*cmd_len + 1] = 0x01; 695 p_cmd_data[*cmd_len + 2] = 0x80; 696 *cmd_len += 3; 697 status = NFCSTATUS_SUCCESS; 698 NXPLOG_NCIHAL_D ("Going through extns - Adding Mifare in RF Discovery - END"); 699 } 700 else if (p_cmd_data[3] == 0x81 && 701 p_cmd_data[4] == 0x01 && 702 p_cmd_data[5] == 0x03) 703 { 704 NXPLOG_NCIHAL_D("> Going through workaround - set host list"); 705 706 #if(NFC_NXP_CHIP_TYPE != PN547C2) 707 *cmd_len = 8; 708 709 p_cmd_data[2] = 0x05; 710 p_cmd_data[6] = 0x02; 711 p_cmd_data[7] = 0xC0; 712 #else 713 *cmd_len = 7; 714 715 p_cmd_data[2] = 0x04; 716 p_cmd_data[6] = 0xC0; 717 #endif 718 719 NXPLOG_NCIHAL_D("> Going through workaround - set host list - END"); 720 status = NFCSTATUS_SUCCESS; 721 } 722 else if(icode_detected) 723 { 724 if ((p_cmd_data[3] & 0x40) == 0x40 && 725 (p_cmd_data[4] == 0x21 || 726 p_cmd_data[4] == 0x22 || 727 p_cmd_data[4] == 0x24 || 728 p_cmd_data[4] == 0x27 || 729 p_cmd_data[4] == 0x28 || 730 p_cmd_data[4] == 0x29 || 731 p_cmd_data[4] == 0x2a)) 732 { 733 NXPLOG_NCIHAL_D ("> Send EOF set"); 734 icode_send_eof = 1; 735 } 736 737 if(p_cmd_data[3] == 0x20 || p_cmd_data[3] == 0x24 || 738 p_cmd_data[3] == 0x60) 739 { 740 NXPLOG_NCIHAL_D ("> NFC ISO_15693 Proprietary CMD "); 741 p_cmd_data[3] += 0x02; 742 } 743 } 744 else if(p_cmd_data[0] == 0x21 && 745 p_cmd_data[1] == 0x03 ) 746 { 747 NXPLOG_NCIHAL_D ("> Polling Loop Started"); 748 icode_detected = 0; 749 icode_send_eof = 0; 750 #if(NFC_NXP_CHIP_TYPE == PN548C2) 751 // Cache discovery cmd for recovery 752 phNxpNciHal_discovery_cmd_ext (p_cmd_data, *cmd_len); 753 #endif 754 } 755 //22000100 756 else if (p_cmd_data[0] == 0x22 && 757 p_cmd_data[1] == 0x00 && 758 p_cmd_data[2] == 0x01 && 759 p_cmd_data[3] == 0x00 760 ) 761 { 762 //ee_disc_done = 0x01;//Reader Over SWP event getting 763 *rsp_len = 0x05; 764 p_rsp_data[0] = 0x42; 765 p_rsp_data[1] = 0x00; 766 p_rsp_data[2] = 0x02; 767 p_rsp_data[3] = 0x00; 768 p_rsp_data[4] = 0x00; 769 phNxpNciHal_print_packet("RECV", p_rsp_data,5); 770 status = NFCSTATUS_FAILED; 771 } 772 //2002 0904 3000 3100 3200 5000 773 else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) && 774 ( (p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) /*|| 775 (p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/ 776 ) 777 ) 778 { 779 *cmd_len += 0x01; 780 p_cmd_data[2] += 0x01; 781 p_cmd_data[9] = 0x01; 782 p_cmd_data[10] = 0x40; 783 p_cmd_data[11] = 0x50; 784 p_cmd_data[12] = 0x00; 785 786 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config "); 787 // phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 788 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End "); 789 } 790 // 20020703300031003200 791 // 2002 0301 3200 792 else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) && 793 ( 794 (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x03) || 795 (p_cmd_data[2] == 0x03 && p_cmd_data[3] == 0x01 && p_cmd_data[4] == 0x32) 796 ) 797 ) 798 { 799 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config "); 800 phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 801 *rsp_len = 5; 802 p_rsp_data[0] = 0x40; 803 p_rsp_data[1] = 0x02; 804 p_rsp_data[2] = 0x02; 805 p_rsp_data[3] = 0x00; 806 p_rsp_data[4] = 0x00; 807 808 phNxpNciHal_print_packet("RECV", p_rsp_data, 5); 809 status = NFCSTATUS_FAILED; 810 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End "); 811 } 812 813 //2002 0D04 300104 310100 320100 500100 814 //2002 0401 320100 815 else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) && 816 ( 817 /*(p_cmd_data[2] == 0x0D && p_cmd_data[3] == 0x04)*/ 818 (p_cmd_data[2] == 0x04 && p_cmd_data[3] == 0x01 && p_cmd_data[4] == 0x32 && p_cmd_data[5] == 0x00) 819 ) 820 ) 821 { 822 // p_cmd_data[12] = 0x40; 823 824 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config "); 825 phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 826 p_cmd_data[6] = 0x60; 827 828 phNxpNciHal_print_packet("RECV", p_rsp_data, 5); 829 // status = NFCSTATUS_FAILED; 830 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End "); 831 } 832 else if(p_cmd_data[0] == 0x21 && 833 p_cmd_data[1] == 0x00 ) 834 { 835 NXPLOG_NCIHAL_D ("> Going through workaround - Add Mifare Classic in Discovery Map"); 836 p_cmd_data[*cmd_len] = 0x80; 837 p_cmd_data[*cmd_len +1] = 0x01; 838 p_cmd_data[*cmd_len + 2] = 0x80; 839 p_cmd_data[5] = 0x01; 840 p_cmd_data[6] = 0x01; 841 p_cmd_data[2] += 3; 842 p_cmd_data[3] += 1; 843 *cmd_len += 3; 844 } 845 else if (*cmd_len == 3 && 846 p_cmd_data[0] == 0x00 && 847 p_cmd_data[1] == 0x00 && 848 p_cmd_data[2] == 0x00 ) 849 { 850 NXPLOG_NCIHAL_D ("> Going through workaround - ISO-DEP Presence Check "); 851 p_cmd_data[0] = 0x2F; 852 p_cmd_data[1] = 0x11; 853 p_cmd_data[2] = 0x00; 854 status = NFCSTATUS_SUCCESS; 855 NXPLOG_NCIHAL_D ("> Going through workaround - ISO-DEP Presence Check - End"); 856 } 857 858 #if 0 859 else if ( (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02 ) && 860 ((p_cmd_data[2] == 0x09 && p_cmd_data[3] == 0x04) || 861 (p_cmd_data[2] == 0x0B && p_cmd_data[3] == 0x05) || 862 (p_cmd_data[2] == 0x07 && p_cmd_data[3] == 0x02) || 863 (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x03) || 864 (p_cmd_data[2] == 0x0A && p_cmd_data[3] == 0x04) || 865 (p_cmd_data[2] == 0x05 && p_cmd_data[3] == 0x02)) 866 ) 867 { 868 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config "); 869 phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 870 *rsp_len = 5; 871 p_rsp_data[0] = 0x40; 872 p_rsp_data[1] = 0x02; 873 p_rsp_data[2] = 0x02; 874 p_rsp_data[3] = 0x00; 875 p_rsp_data[4] = 0x00; 876 877 phNxpNciHal_print_packet("RECV", p_rsp_data, 5); 878 status = NFCSTATUS_FAILED; 879 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End "); 880 } 881 882 else if((p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) && 883 ((p_cmd_data[3] == 0x00) || 884 ((*cmd_len >= 0x06) && (p_cmd_data[5] == 0x00)))) /*If the length of the first param id is zero don't allow*/ 885 { 886 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config "); 887 phNxpNciHal_print_packet("SEND", p_cmd_data, *cmd_len); 888 *rsp_len = 5; 889 p_rsp_data[0] = 0x40; 890 p_rsp_data[1] = 0x02; 891 p_rsp_data[2] = 0x02; 892 p_rsp_data[3] = 0x00; 893 p_rsp_data[4] = 0x00; 894 895 phNxpNciHal_print_packet("RECV", p_rsp_data, 5); 896 status = NFCSTATUS_FAILED; 897 NXPLOG_NCIHAL_D ("> Going through workaround - Dirty Set Config - End "); 898 } 899 #endif 900 else if ((wFwVerRsp & 0x0000FFFF) == wFwVer) 901 { 902 /* skip CORE_RESET and CORE_INIT from Brcm */ 903 if (p_cmd_data[0] == 0x20 && 904 p_cmd_data[1] == 0x00 && 905 p_cmd_data[2] == 0x01 && 906 p_cmd_data[3] == 0x01 907 ) 908 { 909 // *rsp_len = 6; 910 // 911 // NXPLOG_NCIHAL_D("> Going - core reset optimization"); 912 // 913 // p_rsp_data[0] = 0x40; 914 // p_rsp_data[1] = 0x00; 915 // p_rsp_data[2] = 0x03; 916 // p_rsp_data[3] = 0x00; 917 // p_rsp_data[4] = 0x10; 918 // p_rsp_data[5] = 0x01; 919 // 920 // status = NFCSTATUS_FAILED; 921 // NXPLOG_NCIHAL_D("> Going - core reset optimization - END"); 922 } 923 /* CORE_INIT */ 924 else if ( 925 p_cmd_data[0] == 0x20 && 926 p_cmd_data[1] == 0x01 && 927 p_cmd_data[2] == 0x00 928 ) 929 { 930 // NXPLOG_NCIHAL_D("> Going - core init optimization"); 931 // *rsp_len = iCoreInitRspLen; 932 // memcpy(p_rsp_data, bCoreInitRsp, iCoreInitRspLen); 933 // status = NFCSTATUS_FAILED; 934 // NXPLOG_NCIHAL_D("> Going - core init optimization - END"); 935 } 936 } 937 938 #if(NFC_NXP_CHIP_TYPE == PN548C2) 939 if (p_cmd_data[0] == 0x20 && p_cmd_data[1] == 0x02) 940 { 941 uint8_t temp; 942 uint8_t *p = p_cmd_data + 4; 943 uint8_t *end = p_cmd_data + *cmd_len; 944 while (p < end) 945 { 946 if (*p == 0x53) //LF_T3T_FLAGS 947 { 948 NXPLOG_NCIHAL_D ("> Going through workaround - LF_T3T_FLAGS swap"); 949 temp = *(p + 3); 950 *(p + 3) = *(p + 2); 951 *(p + 2) = temp; 952 NXPLOG_NCIHAL_D ("> Going through workaround - LF_T3T_FLAGS - End"); 953 status = NFCSTATUS_SUCCESS; 954 break; 955 } 956 if (*p == 0xA0) 957 { 958 p += *(p + 2) + 3; 959 } 960 else 961 { 962 p += *(p + 1) + 2; 963 } 964 } 965 } 966 #endif 967 968 return status; 969 } 970 971 /****************************************************************************** 972 * Function phNxpNciHal_send_ext_cmd 973 * 974 * Description This function send the extension command to NFCC. No 975 * response is checked by this function but it waits for 976 * the response to come. 977 * 978 * Returns Returns NFCSTATUS_SUCCESS if sending cmd is successful and 979 * response is received. 980 * 981 ******************************************************************************/ 982 NFCSTATUS phNxpNciHal_send_ext_cmd(uint16_t cmd_len, uint8_t *p_cmd) 983 { 984 NFCSTATUS status = NFCSTATUS_FAILED; 985 986 HAL_ENABLE_EXT(); 987 nxpncihal_ctrl.cmd_len = cmd_len; 988 memcpy(nxpncihal_ctrl.p_cmd_data, p_cmd, cmd_len); 989 status = phNxpNciHal_process_ext_cmd_rsp(nxpncihal_ctrl.cmd_len, nxpncihal_ctrl.p_cmd_data); 990 HAL_DISABLE_EXT(); 991 992 return status; 993 } 994 995 /****************************************************************************** 996 * Function hal_extns_write_rsp_timeout_cb 997 * 998 * Description Timer call back function 999 * 1000 * Returns None 1001 * 1002 ******************************************************************************/ 1003 static void hal_extns_write_rsp_timeout_cb(uint32_t timerId, void *pContext) 1004 { 1005 UNUSED(timerId); 1006 UNUSED(pContext); 1007 NXPLOG_NCIHAL_E("hal_extns_write_rsp_timeout_cb - write timeout!!!"); 1008 nxpncihal_ctrl.ext_cb_data.status = NFCSTATUS_FAILED; 1009 usleep(1); 1010 SEM_POST(&(nxpncihal_ctrl.ext_cb_data)); 1011 1012 return; 1013 } 1014