diff --git a/README.md b/README.md index c27a5af..433a192 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Further details about the stack [here](https://github.com/NXPNFCLinux/linux_libn Release version --------------- -R2.1 includes support for PN7150 NFC Controller IC +R2.1 includes support for PN7150 NFC Controller IC and some bug fixes (refer to the [documentation](https://github.com/NXPNFCLinux/linux_libnfc-nci/blob/master/doc/AN11697%20-%20PN71x0%20Linux%20Software%20Stack%20Integration%20Guidelines.pdf) for more details). R2.0 includes LLCP1.3 support and some bug fixes (refer to the [documentation](https://github.com/NXPNFCLinux/linux_libnfc-nci/blob/master/doc/AN11697%20-%20PN71x0%20Linux%20Software%20Stack%20Integration%20Guidelines.pdf) for more details). diff --git a/conf/PN7150/libnfc-nxp.conf b/conf/PN7150/libnfc-nxp.conf index 03c9352..29f7265 100644 --- a/conf/PN7150/libnfc-nxp.conf +++ b/conf/PN7150/libnfc-nxp.conf @@ -75,11 +75,12 @@ NXP_EXT_TVDD_CFG_2={20, 02, 07, 01, A0, 0E, 03, 06, 64, 00} ############################################################################### # NXP Proprietary core configuration extensions # For more details refer to the NFC Controller User Manual -NXP_CORE_CONF_EXTN={20, 02, 10, 03, +NXP_CORE_CONF_EXTN={20, 02, 24, 04, A0, 5E, 01, 01, A0, 40, 01, 00, - A0, 0D, 04, 34, 44, 22, 00 - } + A0, 0D, 04, 34, 44, 22, 00, + A0, 1D, 11, 57, 33, 14, 17, 00, AA, 85, 00, 80, 55, 2A, 04, 00, 63, 00, 00, 00 +} ############################################################################### # To enable i2c fragmentation set i2c fragmentation enable 0x01 to disable set to 0x00 @@ -101,4 +102,28 @@ NXP_CORE_CONF={ 20, 02, 2B, 0D, 81, 01, 01, 82, 01, 0E, 18, 01, 01 - } +} + +############################################################################### +# RF configuration settings +NXP_RF_CONF_BLK_1={ 20, 02, A3, 13, + A0, 0D, 06, 04, 35, 90, 01, F4, 01, + A0, 0D, 06, 06, 44, 01, 90, 03, 00, + A0, 0D, 06, 06, 30, B0, 01, 10, 00, + A0, 0D, 06, 06, 42, 02, 00, FF, FF, + A0, 0D, 03, 06, 3F, 06, + A0, 0D, 06, 20, 42, 88, 00, FF, FF, + A0, 0D, 04, 22, 44, 23, 00, + A0, 0D, 06, 22, 2D, 50, 34, 0C, 00, + A0, 0D, 06, 32, 42, F8, 00, FF, FF, + A0, 0D, 06, 34, 2D, 24, 37, 0C, 00, + A0, 0D, 06, 34, 33, 86, 80, 00, 70, + A0, 0D, 04, 34, 44, 22, 00, + A0, 0D, 06, 42, 2D, 15, 45, 0D, 00, + A0, 0D, 04, 46, 44, 22, 00, + A0, 0D, 06, 46, 2D, 05, 59, 0E, 00, + A0, 0D, 06, 44, 42, 88, 00, FF, FF, + A0, 0D, 06, 56, 2D, 05, 9F, 0C, 00, + A0, 0D, 06, 54, 42, 88, 00, FF, FF, + A0, 0D, 06, 0A, 33, 80, 86, 00, 70 +} diff --git a/doc/AN11697 - PN71x0 Linux Software Stack Integration Guidelines.pdf b/doc/AN11697 - PN71x0 Linux Software Stack Integration Guidelines.pdf index 2f86889..51f2aae 100644 Binary files a/doc/AN11697 - PN71x0 Linux Software Stack Integration Guidelines.pdf and b/doc/AN11697 - PN71x0 Linux Software Stack Integration Guidelines.pdf differ diff --git a/src/halimpl/pn54x/common/phNfcStatus.h b/src/halimpl/pn54x/common/phNfcStatus.h index fb1d818..5d6c81d 100644 --- a/src/halimpl/pn54x/common/phNfcStatus.h +++ b/src/halimpl/pn54x/common/phNfcStatus.h @@ -182,6 +182,14 @@ */ #define NFCSTATUS_NOT_ALLOWED (0x003A) +/* + * FW version error while performing FW download, + * FW major version mismatch (cannot downgrade FW major version) or FW version already upto date + * User may be trying to flash Mobile FW on top of Infra FW, which is not allowed + * Download appropriate version of FW + */ +#define NFCSTATUS_FW_VERSION_ERROR (0x003C) + /* * The system is busy with the previous operation. */ diff --git a/src/halimpl/pn54x/dnld/phDnldNfc.c b/src/halimpl/pn54x/dnld/phDnldNfc.c index 68fd9ec..040cee4 100644 --- a/src/halimpl/pn54x/dnld/phDnldNfc.c +++ b/src/halimpl/pn54x/dnld/phDnldNfc.c @@ -28,6 +28,9 @@ static void *pFwLibHandle; /* Global firmware lib handle used in this file only */ uint16_t wMwVer = 0; /* Middleware version no */ uint16_t wFwVer = 0; /* Firmware version no */ +#if(NFC_NXP_CHIP_TYPE == PN548C2) + uint8_t gRecFWDwnld; // flag set to true to indicate dummy FW download +#endif static pphDnldNfc_DlContext_t gpphDnldContext = NULL; /* Download contex */ static pphDnldNfc_RspCb_t UserCb; /* Upper layer call back function */ static void* UserCtxt; /* Pointer to upper layer context */ @@ -869,7 +872,12 @@ NFCSTATUS phDnldNfc_InitImgInfo(void) phDnldNfc_SetHwDevHandle(); /* load the library and get the image info pointer */ - wStatus = phDnldNfc_LoadFW(FW_LIB_PATH, &pImageInfo, &ImageInfoLen); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (gRecFWDwnld == TRUE) + wStatus = phDnldNfc_LoadRecoveryFW (FW_LIB_PATH, &pImageInfo, &ImageInfoLen); + else +#endif + wStatus = phDnldNfc_LoadFW (FW_LIB_PATH, &pImageInfo, &ImageInfoLen); NXPLOG_FWDNLD_D("FW Image Length - ImageInfoLen %d",ImageInfoLen); NXPLOG_FWDNLD_D("FW Image Info Pointer - pImageInfo %x",(uintptr_t)pImageInfo); @@ -940,7 +948,12 @@ NFCSTATUS phDnldNfc_LoadRecInfo(void) /* if memory is not allocated then allocate memory for donwload context structure */ phDnldNfc_SetHwDevHandle(); - wStatus = phDnldNfc_LoadFW(PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (gRecFWDwnld == TRUE) + wStatus = phDnldNfc_LoadRecoveryFW (PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen); + else +#endif + wStatus = phDnldNfc_LoadFW (PLATFORM_LIB_PATH, &pImageInfo, &ImageInfoLen); if((pImageInfo == NULL) || (ImageInfoLen == 0)) { @@ -997,8 +1010,12 @@ NFCSTATUS phDnldNfc_LoadPKInfo(void) phDnldNfc_SetHwDevHandle(); /* load the PKU image library */ - wStatus = phDnldNfc_LoadFW(PKU_LIB_PATH, &pImageInfo, &ImageInfoLen); - +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (gRecFWDwnld == TRUE) + wStatus = phDnldNfc_LoadRecoveryFW (PKU_LIB_PATH, &pImageInfo, &ImageInfoLen); + else +#endif + wStatus = phDnldNfc_LoadFW (PKU_LIB_PATH, &pImageInfo, &ImageInfoLen); if((pImageInfo == NULL) || (ImageInfoLen == 0)) { NXPLOG_FWDNLD_E("Image extraction Failed - invalid imginfo or imginfolen!!"); @@ -1167,6 +1184,75 @@ NFCSTATUS phDnldNfc_UnloadFW(void) return wStatus; } +#if(NFC_NXP_CHIP_TYPE == PN548C2) +/******************************************************************************* +** +** Function phDnldNfc_LoadRecoveryFW +** +** Description Load the dummy firmware version form firmware lib for recovery +** This will change the FW version of the NFCC firmware +** and enable flashing of firmware of same version. +** +** Parameters pathName - Firmware image path +** pImgInfo - Firmware image handle +** pImgInfoLen - Firmware image length +** +** Returns NFCSTATUS +** +*******************************************************************************/ +NFCSTATUS phDnldNfc_LoadRecoveryFW (const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen) +{ + void* pImageInfo = NULL; + void* pImageInfoLen = NULL; + + /* check for path name */ + if (pathName == NULL) + { + pathName = "/system/vendor/firmware/libpn548ad_fw.so"; + } + + /* check if the handle is not NULL then free the library */ + if (pFwLibHandle != NULL) + { + phDnldNfc_UnloadFW (); + pFwLibHandle = NULL; + } + /* load the DLL file */ + pFwLibHandle = dlopen (pathName, RTLD_LAZY); + NXPLOG_FWDNLD_D ("phDnldNfc_LoadRecoveryFW %s ", pathName); + + /* if library load failed then handle will be NULL */ + if (pFwLibHandle == NULL) + { + NXPLOG_FWDNLD_E("NULL handler : unable to load the library file, specify correct path"); + return NFCSTATUS_FAILED; + } + + dlerror (); /* Clear any existing error */ + + /* load the address of download image pointer and image size */ + pImageInfo = (void*)dlsym (pFwLibHandle, "gphDnldNfc_DummyDlSeq"); + + if (dlerror() || (NULL == pImageInfo)) + { + NXPLOG_FWDNLD_E ("Problem loading symbol : gphDnldNfc_DummyDlSeq"); + return NFCSTATUS_FAILED; + } + + (*pImgInfo) = (*(uint8_t**)pImageInfo); + pImageInfoLen = (void*)dlsym (pFwLibHandle, "gphDnldNfc_DlSeqDummyFwSz"); + if (dlerror() ||(NULL == pImageInfoLen)) + { + NXPLOG_FWDNLD_E ("Problem loading symbol : gphDnldNfc_DlSeqDummyFwSz"); + return NFCSTATUS_FAILED; + } + + (*pImgInfoLen) = (uint16_t)(*((uint16_t*)pImageInfoLen)); + + return NFCSTATUS_SUCCESS; +} +#endif + #ifdef EEPROM_Read_Mem_IMP /******************************************************************************* ** diff --git a/src/halimpl/pn54x/dnld/phDnldNfc.h b/src/halimpl/pn54x/dnld/phDnldNfc.h index df95c93..331d39b 100644 --- a/src/halimpl/pn54x/dnld/phDnldNfc.h +++ b/src/halimpl/pn54x/dnld/phDnldNfc.h @@ -104,5 +104,8 @@ extern NFCSTATUS phDnldNfc_LoadRecInfo(void); extern NFCSTATUS phDnldNfc_LoadPKInfo(void); extern void phDnldNfc_CloseFwLibHandle(void); extern NFCSTATUS phDnldNfc_LoadFW(const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen); +#if(NFC_NXP_CHIP_TYPE == PN548C2) +extern NFCSTATUS phDnldNfc_LoadRecoveryFW (const char* pathName, uint8_t **pImgInfo, uint16_t* pImgInfoLen); +#endif extern NFCSTATUS phDnldNfc_UnloadFW(void); #endif /* PHDNLDNFC_H */ diff --git a/src/halimpl/pn54x/dnld/phDnldNfc_Internal.c b/src/halimpl/pn54x/dnld/phDnldNfc_Internal.c index 628e582..e97dd2f 100644 --- a/src/halimpl/pn54x/dnld/phDnldNfc_Internal.c +++ b/src/halimpl/pn54x/dnld/phDnldNfc_Internal.c @@ -275,6 +275,8 @@ static void phDnldNfc_ProcessSeqState(void *pContext, phTmlNfc_TransactInfo_t *p (pphTmlNfc_TransactCompletionCb_t)&phDnldNfc_ProcessSeqState, (void *)pDlCtxt); + /* set read status to pDlCtxt->wCmdSendStatus to enable callback */ + pDlCtxt->wCmdSendStatus = wStatus; break; } else @@ -454,6 +456,8 @@ static void phDnldNfc_ProcessRWSeqState(void *pContext, phTmlNfc_TransactInfo_t (pphTmlNfc_TransactCompletionCb_t)&phDnldNfc_ProcessRWSeqState, (void *)pDlCtxt); + /* set read status to pDlCtxt->wCmdSendStatus to enable callback */ + pDlCtxt->wCmdSendStatus = wStatus; break; } else @@ -1232,12 +1236,12 @@ static NFCSTATUS phDnldNfc_UpdateRsp(pphDnldNfc_DlContext_t pDlContext, phTmlN } else if(PH_DL_STATUS_FIRMWARE_VERSION_ERROR == (pInfo->pBuff[PHDNLDNFC_FRAMESTATUS_OFFSET])) { - NXPLOG_FWDNLD_E("Firmware Already Up To Date!!"); + NXPLOG_FWDNLD_E("FW version Error !!!could be either due to FW major version mismatch or Firmware Already Up To Date !!"); (pDlContext->tRWInfo.bFirstWrReq) = FALSE; /* resetting wRemBytes to 0 to avoid any further write frames send */ (pDlContext->tRWInfo.wRemBytes) = 0; (pDlContext->tRWInfo.wOffset) = 0; - wStatus = NFCSTATUS_SUCCESS; + wStatus = NFCSTATUS_FW_VERSION_ERROR; } else if(PH_DL_STATUS_PLL_ERROR == (pInfo->pBuff[PHDNLDNFC_FRAMESTATUS_OFFSET])) { diff --git a/src/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c b/src/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c index c8acb13..bb28788 100644 --- a/src/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c +++ b/src/halimpl/pn54x/dnld/phNxpNciHal_Dnld.c @@ -35,6 +35,9 @@ /* External global variable to get FW version */ extern uint16_t wFwVer; extern uint16_t wMwVer; +#if(NFC_NXP_CHIP_TYPE == PN548C2) +extern uint8_t gRecFWDwnld; +#endif /* RF Configuration structure */ typedef struct phLibNfc_IoctlSetRfConfig @@ -179,6 +182,20 @@ static NFCSTATUS (*phNxpNciHal_dwnld_seqhandler[])( NULL }; +#if(NFC_NXP_CHIP_TYPE == PN548C2) +/* Array of pointers to start dummy fw download seq */ +static NFCSTATUS (*phNxpNciHal_dummy_rec_dwnld_seqhandler[])( + void* pContext, NFCSTATUS status, void* pInfo) = { + phNxpNciHal_fw_dnld_normal, + phNxpNciHal_fw_dnld_normal, + phNxpNciHal_fw_dnld_get_sessn_state, + phNxpNciHal_fw_dnld_get_version, + phNxpNciHal_fw_dnld_log_read, + phNxpNciHal_fw_dnld_write, + NULL +}; +#endif + /* Download Recovery Sequence */ static NFCSTATUS (*phNxpNciHal_dwnld_rec_seqhandler[])( void* pContext, NFCSTATUS status, void* pInfo) = { @@ -1671,6 +1688,12 @@ static NFCSTATUS phNxpNciHal_fw_dnld_complete(void* pContext,NFCSTATUS status, (gphNxpNciHal_fw_IoctlCtx.bDnldInitiated) = FALSE; /* Perform the Logging sequence */ wStatus = phNxpNciHal_fw_seq_handler(phNxpNciHal_dwnld_log_seqhandler); + if (NFCSTATUS_SUCCESS != gphNxpNciHal_fw_IoctlCtx.bLastStatus) + { + /* update the previous Download Write status to upper layer and not the status of Log command */ + wStatus = gphNxpNciHal_fw_IoctlCtx.bLastStatus; + NXPLOG_FWDNLD_E ("phNxpNciHal_fw_dnld_complete: Last Download Write Status before Log command bLastStatus = 0x%x", gphNxpNciHal_fw_IoctlCtx.bLastStatus); + } status = phNxpNciHal_fw_dnld_complete(pContext, wStatus, &pInfo); if (NFCSTATUS_SUCCESS == status) { @@ -1680,7 +1703,6 @@ static NFCSTATUS phNxpNciHal_fw_dnld_complete(void* pContext,NFCSTATUS status, { NXPLOG_FWDNLD_E(" phNxpNciHal_fw_dnld_complete : FAILED"); } - } else if(TRUE == (gphNxpNciHal_fw_IoctlCtx.bDnldRecovery)) { @@ -1727,6 +1749,7 @@ static NFCSTATUS phNxpNciHal_fw_dnld_complete(void* pContext,NFCSTATUS status, } else { + NXPLOG_FWDNLD_D ("phNxpNciHal_fw_dnld_complete: Download Status = 0x%x", status); if(FALSE == (gphNxpNciHal_fw_IoctlCtx.bSkipSeq)) { if(NFCSTATUS_SUCCESS == status) @@ -1854,7 +1877,16 @@ NFCSTATUS phNxpNciHal_fw_download_seq(uint8_t bClkSrcVal, uint8_t bClkFreqVal) if (NFCSTATUS_SUCCESS == phDnldNfc_InitImgInfo()) { NXPLOG_FWDNLD_D("phDnldNfc_InitImgInfo:SUCCESS"); - status = phNxpNciHal_fw_seq_handler(phNxpNciHal_dwnld_seqhandler); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (gRecFWDwnld == TRUE) + { + status = phNxpNciHal_fw_seq_handler (phNxpNciHal_dummy_rec_dwnld_seqhandler); + } + else +#endif + { + status = phNxpNciHal_fw_seq_handler (phNxpNciHal_dwnld_seqhandler); + } } else { diff --git a/src/halimpl/pn54x/hal/phNxpNciHal.c b/src/halimpl/pn54x/hal/phNxpNciHal.c index a602123..ee53a63 100644 --- a/src/halimpl/pn54x/hal/phNxpNciHal.c +++ b/src/halimpl/pn54x/hal/phNxpNciHal.c @@ -54,6 +54,10 @@ extern uint16_t wFwVer; extern int send_to_upper_kovio; extern int kovio_detected; extern int disable_kovio; +#if(NFC_NXP_CHIP_TYPE == PN548C2) +extern uint8_t gRecFWDwnld; +static uint8_t gRecFwRetryCount; //variable to hold dummy FW recovery count +#endif static uint8_t Rx_data[NCI_MAX_DATA_LEN]; uint32_t timeoutTimerId = 0; @@ -82,7 +86,13 @@ static NFCSTATUS phNxpNciHal_CheckValidFwVersion(void); static void phNxpNciHal_enable_i2c_fragmentation(); NFCSTATUS phNxpNciHal_check_clock_config(void); NFCSTATUS phNxpNciHal_china_tianjin_rf_setting(void); +#if(NFC_NXP_CHIP_TYPE == PN548C2) +static NFCSTATUS phNxpNciHalRFConfigCmdRecSequence (); +static NFCSTATUS phNxpNciHal_CheckRFCmdRespStatus (); +#endif + int check_config_parameter(); + /****************************************************************************** * Function phNxpNciHal_client_thread * @@ -323,6 +333,12 @@ static NFCSTATUS phNxpNciHal_CheckValidFwVersion(void) NXPLOG_NCIHAL_D("Firmware download not allowed (NXP_FW_PROTECION_OVERRIDE not defiend)"); } } +#if(NFC_NXP_CHIP_TYPE == PN548C2) + else if (gRecFWDwnld == TRUE) + { + status = NFCSTATUS_SUCCESS; + } +#endif else if (wFwVerRsp == 0) { NXPLOG_NCIHAL_E("FW Version not received by NCI command >>> Force Firmware download"); @@ -969,6 +985,9 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) int temp_fix = 1; #if(NFC_NXP_CHIP_TYPE == PN548C2) unsigned long num = 0; + //initialize dummy FW recovery variables + gRecFwRetryCount = 0; + gRecFWDwnld = 0; #endif // recovery --start /*NCI_INIT_CMD*/ @@ -983,7 +1002,10 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) retry_core_init: config_access = FALSE; if(buffer != NULL) + { free(buffer); + buffer = NULL; + } if(retry_core_init_cnt > 3) { return NFCSTATUS_FAILED; @@ -1165,11 +1187,28 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) } #endif retlen = 0; +#if(NFC_NXP_CHIP_TYPE == PN548C2) + config_access = FALSE; +#endif NXPLOG_NCIHAL_D ("Performing RF Settings BLK 1"); isfound = GetNxpByteArrayValue(NAME_NXP_RF_CONF_BLK_1, (char *) buffer, bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 1 failed"); retry_core_init_cnt++; @@ -1183,6 +1222,20 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 2 failed"); retry_core_init_cnt++; @@ -1196,6 +1249,20 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 3 failed"); retry_core_init_cnt++; @@ -1209,6 +1276,20 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 4 failed"); retry_core_init_cnt++; @@ -1222,6 +1303,20 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 5 failed"); retry_core_init_cnt++; @@ -1235,6 +1330,20 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) bufflen, &retlen); if (retlen > 0) { status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("RF Settings BLK 6 failed"); retry_core_init_cnt++; @@ -1242,6 +1351,9 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) } } retlen = 0; +#if(NFC_NXP_CHIP_TYPE == PN548C2) + config_access = TRUE; +#endif NXPLOG_NCIHAL_D ("Performing NAME_NXP_CORE_CONF_EXTN Settings"); isfound = GetNxpByteArrayValue(NAME_NXP_CORE_CONF_EXTN, @@ -1271,18 +1383,39 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) } retlen = 0; - +#if(NFC_NXP_CHIP_TYPE == PN548C2) + config_access = FALSE; +#endif isfound = GetNxpByteArrayValue(NAME_NXP_CORE_RF_FIELD, (char *) buffer, bufflen, &retlen); if (retlen > 0) { /* NXP ACT Proprietary Ext */ status = phNxpNciHal_send_ext_cmd(retlen, buffer); +#if(NFC_NXP_CHIP_TYPE == PN548C2) + if (status == NFCSTATUS_SUCCESS) + { + status = phNxpNciHal_CheckRFCmdRespStatus (); + /*STATUS INVALID PARAM 0x09*/ + if (status == 0x09) + { + phNxpNciHalRFConfigCmdRecSequence (); + retry_core_init_cnt++; + goto retry_core_init; + } + } + else +#endif if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("Setting NXP_CORE_RF_FIELD status failed"); retry_core_init_cnt++; goto retry_core_init; } } + +#if(NFC_NXP_CHIP_TYPE == PN548C2) + config_access = TRUE; +#endif + #if(NFC_NXP_CHIP_TYPE != PN547C2) retlen = 0; @@ -1551,8 +1684,14 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) if(buffer) { free(buffer); + buffer = NULL; } +#if(NFC_NXP_CHIP_TYPE == PN548C2) + //initialize dummy FW recovery variables + gRecFWDwnld = 0; + gRecFwRetryCount = 0; +#endif if(!((*p_core_init_rsp_params > 0) && (*p_core_init_rsp_params < 4))) phNxpNciHal_core_initialized_complete(status); else @@ -1577,6 +1716,98 @@ int phNxpNciHal_core_initialized(uint8_t* p_core_init_rsp_params) return NFCSTATUS_SUCCESS; } +#if(NFC_NXP_CHIP_TYPE == PN548C2) +/****************************************************************************** + * Function phNxpNciHal_CheckRFCmdRespStatus + * + * Description This function is called to check the resp status of + * RF update commands. + * + * Returns NFCSTATUS_SUCCESS if successful, + * NFCSTATUS_INVALID_PARAMETER if parameter is inavlid + * NFCSTATUS_FAILED if failed response + * + ******************************************************************************/ +NFCSTATUS phNxpNciHal_CheckRFCmdRespStatus () +{ + NFCSTATUS status = NFCSTATUS_SUCCESS; + static uint16_t INVALID_PARAM = 0x09; + if ((nxpncihal_ctrl.rx_data_len > 0) && (nxpncihal_ctrl.p_rx_data[2] > 0)) + { + if (nxpncihal_ctrl.p_rx_data[3] == 0x09) + { + status = INVALID_PARAM; + } + else if (nxpncihal_ctrl.p_rx_data[3] != NFCSTATUS_SUCCESS) + { + status = NFCSTATUS_FAILED; + } + } + return status; +} + +/****************************************************************************** + * Function phNxpNciHalRFConfigCmdRecSequence + * + * Description This function is called to handle dummy FW recovery sequence + * Whenever RF settings are failed to apply with invalid param + * response, recovery mechanism includes dummy firmware download + * followed by firmware download and then config settings. The dummy + * firmware changes the major number of the firmware inside NFCC. + * Then actual firmware dowenload will be successful. This can be + * retried maximum three times. + * + * Returns Always returns NFCSTATUS_SUCCESS + * + ******************************************************************************/ +NFCSTATUS phNxpNciHalRFConfigCmdRecSequence () +{ + NFCSTATUS status = NFCSTATUS_SUCCESS; + uint16_t recFWState = 1; + gRecFWDwnld = TRUE; + gRecFwRetryCount++; + if (gRecFwRetryCount > 0x03) + { + NXPLOG_NCIHAL_D ("Max retry count for RF config FW recovery exceeded "); + gRecFWDwnld = FALSE; + return NFCSTATUS_FAILED; + } + do { + status = phTmlNfc_IoCtl (phTmlNfc_e_ResetDevice); + phDnldNfc_InitImgInfo (); + if (NFCSTATUS_SUCCESS == phNxpNciHal_CheckValidFwVersion ()) + { + fw_download_success = 0; + status = phNxpNciHal_fw_download (); + if (status == NFCSTATUS_SUCCESS) + { + fw_download_success = 1; + status = phTmlNfc_Read( + nxpncihal_ctrl.p_cmd_data, + NCI_MAX_DATA_LEN, + (pphTmlNfc_TransactCompletionCb_t) &phNxpNciHal_read_complete, + NULL); + if (status != NFCSTATUS_PENDING) + { + NXPLOG_NCIHAL_E ("TML Read status error status = %x", status); + phTmlNfc_Shutdown (); + status = NFCSTATUS_FAILED; + break; + } + } + else + { + status = NFCSTATUS_FAILED; + break; + } + } + gRecFWDwnld = FALSE; + }while (recFWState--); + gRecFWDwnld = FALSE; + return status; +} +#endif + /****************************************************************************** * Function phNxpNciHal_core_initialized_complete * diff --git a/src/libnfc-nci/nfc/cipher/cipher.c b/src/libnfc-nci/nfc/cipher/cipher.c index 9ef3542..8641eb3 100644 --- a/src/libnfc-nci/nfc/cipher/cipher.c +++ b/src/libnfc-nci/nfc/cipher/cipher.c @@ -30,6 +30,7 @@ #if(NFC_NXP_LLCP_SECURED_P2P == TRUE) #include "cipher.h" + void cipher_init() { diff --git a/src/service/interface/RoutingManager.cpp b/src/service/interface/RoutingManager.cpp index d8ec44f..cfa6802 100644 --- a/src/service/interface/RoutingManager.cpp +++ b/src/service/interface/RoutingManager.cpp @@ -98,6 +98,12 @@ bool RoutingManager::initialize () NXPLOG_API_E ("%s:NXP_FWD_FUNCTIONALITY_ENABLE=%d;", __FUNCTION__, mFwdFuntnEnable); } + if ((GetNumValue(NAME_HOST_LISTEN_ENABLE, &tech, sizeof(tech)))) + { + mHostListnEnable = tech; + NXPLOG_API_E ("%s:HOST_LISTEN_ENABLE=%d;", __FUNCTION__, mHostListnEnable); + } + tNFA_STATUS nfaStat; { SyncEventGuard guard (mEeRegisterEvent); diff --git a/src/service/interface/nativeNfcManager.cpp b/src/service/interface/nativeNfcManager.cpp index 0eec454..93e7c99 100644 --- a/src/service/interface/nativeNfcManager.cpp +++ b/src/service/interface/nativeNfcManager.cpp @@ -1575,8 +1575,8 @@ void nativeNfcManager_enableDiscovery (INT32 technologies_mask, #if(NXP_NFC_NATIVE_ENABLE_HCE == TRUE) if (enable_host_routing && FLAG_HCE_ENABLE_HCE) { - NXPLOG_API_D ("Host Card Emulation Enabled"); - RoutingManager::getInstance().enableRoutingToHost(enable_host_routing & FLAG_HCE_SKIP_NDEF_CHECK); + NXPLOG_API_D ("Host Card Emulation Enabled"); + RoutingManager::getInstance().enableRoutingToHost(enable_host_routing & FLAG_HCE_SKIP_NDEF_CHECK); } else #endif @@ -1590,7 +1590,19 @@ void nativeNfcManager_enableDiscovery (INT32 technologies_mask, { // No technologies configured, stop polling stopPolling_rfDiscoveryDisabled(); - } + + #if(NXP_NFC_NATIVE_ENABLE_HCE == TRUE) + if (enable_host_routing && FLAG_HCE_ENABLE_HCE) + { + NXPLOG_API_D ("Host Card Emulation Enabled"); + RoutingManager::getInstance().enableRoutingToHost(enable_host_routing & FLAG_HCE_SKIP_NDEF_CHECK); + } + else +#endif + { + RoutingManager::getInstance().disableRoutingToHost(); + } + } // Start P2P listening if tag polling was enabled or the mask was 0. if (sDiscoveryEnabled || (tech_mask == 0))