diff options
| author | Jizhou Liao <jizhou.liao@nxp.com> | 2018-11-05 15:43:13 -0800 |
|---|---|---|
| committer | Jizhou Liao <jizhou.liao@nxp.com> | 2018-12-11 22:59:53 +0000 |
| commit | 3a083ccd2ce301bea8205e8d8f432e2cc76ea5f8 (patch) | |
| tree | f714f0c91206c6d140c60bfb182be3712df091d7 /halimpl | |
| parent | d4398d96e06537510fae6c4f0f6defcbfd660182 (diff) | |
| download | android_hardware_nxp_nfc-3a083ccd2ce301bea8205e8d8f432e2cc76ea5f8.tar.gz android_hardware_nxp_nfc-3a083ccd2ce301bea8205e8d8f432e2cc76ea5f8.tar.bz2 android_hardware_nxp_nfc-3a083ccd2ce301bea8205e8d8f432e2cc76ea5f8.zip | |
eSE not working after NFC OFF/ON during SPI session
The fix includes:
1. Close NFC HAL when eSE is closed
2. send RF_NFCEE_DISCOVERY_REQ_NTF to libnfc-nci if
eSE is connected and enabled
Test: eSE HAL enable/disable & NFC enable/disable combination test
Bug: 118046462
Change-Id: I2f35c77c9fd74c80fe9f243ca04e3157e422f4d7
Diffstat (limited to 'halimpl')
| -rwxr-xr-x | halimpl/hal/phNxpNciHal.cc | 58 | ||||
| -rwxr-xr-x | halimpl/tml/phTmlNfc.cc | 21 | ||||
| -rwxr-xr-x[-rw-r--r--] | halimpl/tml/phTmlNfc.h | 2 |
3 files changed, 62 insertions, 19 deletions
diff --git a/halimpl/hal/phNxpNciHal.cc b/halimpl/hal/phNxpNciHal.cc index 46670b5..d798f0c 100755 --- a/halimpl/hal/phNxpNciHal.cc +++ b/halimpl/hal/phNxpNciHal.cc @@ -51,6 +51,7 @@ static uint8_t config_access = false; static uint8_t config_success = true; static bool persist_uicc_enabled =false; +static ThreadMutex sHalFnLock; /* NCI HAL Control structure */ phNxpNciHal_Control_t nxpncihal_ctrl; @@ -205,8 +206,8 @@ static void* phNxpNciHal_client_thread(void* arg) { /* Send the event */ (*nxpncihal_ctrl.p_nfc_stack_cback)(HAL_NFC_CLOSE_CPLT_EVT, HAL_NFC_STATUS_OK); - phNxpNciHal_kill_client_thread(&nxpncihal_ctrl); } + phNxpNciHal_kill_client_thread(&nxpncihal_ctrl); REENTRANCE_UNLOCK(); break; } @@ -360,7 +361,7 @@ static NFCSTATUS phNxpNciHal_fw_download(void) { if (NFCSTATUS_SUCCESS != phNxpNciHal_fw_mw_ver_check()) { NXPLOG_NCIHAL_D("Chip Version Middleware Version mismatch!!!!"); phOsalNfc_Timer_Cleanup(); - phTmlNfc_Shutdown(); + phTmlNfc_Shutdown_CleanUp(); status = NFCSTATUS_FAILED; } else { NXPLOG_NCIHAL_E("FW download failed, Continue NFCC init"); @@ -377,7 +378,7 @@ static NFCSTATUS phNxpNciHal_fw_download(void) { (pphTmlNfc_TransactCompletionCb_t)&phNxpNciHal_read_complete, NULL); if (readRestoreStatus != NFCSTATUS_PENDING) { NXPLOG_NCIHAL_E("TML Read status error status = %x", readRestoreStatus); - readRestoreStatus = phTmlNfc_Shutdown(); + readRestoreStatus = phTmlNfc_Shutdown_CleanUp(); if (readRestoreStatus != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_E("TML Shutdown failed. Status = %x", readRestoreStatus); } @@ -552,6 +553,8 @@ int phNxpNciHal_MinOpen (){ static uint8_t cmd_reset_nci[] = {0x20, 0x00, 0x01, 0x00}; /*NCI2_0_INIT_CMD*/ static uint8_t cmd_init_nci2_0[] = {0x20, 0x01, 0x02, 0x00, 0x00}; + + AutoThreadMutex a(sHalFnLock); if (nxpncihal_ctrl.halStatus == HAL_STATUS_MIN_OPEN) { NXPLOG_NCIHAL_E("phNxpNciHal_MinOpen(): already open"); return NFCSTATUS_SUCCESS; @@ -626,15 +629,11 @@ int phNxpNciHal_MinOpen (){ } /* Create the client thread */ - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - ret_val = pthread_create(&nxpncihal_ctrl.client_thread, &attr, + ret_val = pthread_create(&nxpncihal_ctrl.client_thread, NULL, phNxpNciHal_client_thread, &nxpncihal_ctrl); - pthread_attr_destroy(&attr); if (ret_val != 0) { NXPLOG_NCIHAL_E("pthread_create failed"); - wConfigStatus = phTmlNfc_Shutdown(); + wConfigStatus = phTmlNfc_Shutdown_CleanUp(); goto clean_and_return; } @@ -646,7 +645,7 @@ int phNxpNciHal_MinOpen (){ (pphTmlNfc_TransactCompletionCb_t)&phNxpNciHal_read_complete, NULL); if (status != NFCSTATUS_PENDING) { NXPLOG_NCIHAL_E("TML Read status error status = %x", status); - wConfigStatus = phTmlNfc_Shutdown(); + wConfigStatus = phTmlNfc_Shutdown_CleanUp(); wConfigStatus = NFCSTATUS_FAILED; goto clean_and_return; } @@ -669,7 +668,7 @@ init_retry: goto init_retry; } else init_retry_cnt = 0; - wConfigStatus = phTmlNfc_Shutdown(); + wConfigStatus = phTmlNfc_Shutdown_CleanUp(); wConfigStatus = NFCSTATUS_FAILED; goto clean_and_return; } @@ -701,7 +700,7 @@ init_retry: goto init_retry; } else init_retry_cnt = 0; - wConfigStatus = phTmlNfc_Shutdown(); + wConfigStatus = phTmlNfc_Shutdown_CleanUp(); wConfigStatus = NFCSTATUS_FAILED; goto clean_and_return; } @@ -1132,6 +1131,22 @@ static void phNxpNciHal_read_complete(void* pContext, (status == NFCSTATUS_SUCCESS)) { (*nxpncihal_ctrl.p_nfc_stack_data_cback)(nxpncihal_ctrl.rx_data_len, nxpncihal_ctrl.p_rx_data); + //workaround for sync issue between SPI and NFC + if ((nfcFL.chipType == pn557) && nxpncihal_ctrl.p_rx_data[0] == 0x62 && + nxpncihal_ctrl.p_rx_data[1] == 0x00 && + nxpncihal_ctrl.p_rx_data[3] == 0xC0 && + nxpncihal_ctrl.p_rx_data[4] == 0x00) { + uint8_t nfcee_notifiations[3][9] = { + {0x61, 0x0A, 0x06, 0x01, 0x00, 0x03, 0xC0, 0x80, 0x04}, + {0x61, 0x0A, 0x06, 0x01, 0x00, 0x03, 0xC0, 0x81, 0x04}, + {0x61, 0x0A, 0x06, 0x01, 0x00, 0x03, 0xC0, 0x82, 0x03}, + }; + + for (int i = 0; i < 3; i++) { + (*nxpncihal_ctrl.p_nfc_stack_data_cback)(sizeof(nfcee_notifiations[i]), + nfcee_notifiations[i]); + } + } } } else { NXPLOG_NCIHAL_E("read error status = 0x%x", pInfo->wStatus); @@ -2053,6 +2068,7 @@ int phNxpNciHal_close(bool bShutdown) { static uint8_t cmd_ven_disable_nci[] = {0x20, 0x02, 0x05, 0x01, 0xA0, 0x07, 0x01, 0x02}; + AutoThreadMutex a(sHalFnLock); if (nxpncihal_ctrl.halStatus == HAL_STATUS_CLOSE) { NXPLOG_NCIHAL_E("phNxpNciHal_close is already closed, ignoring close"); return NFCSTATUS_FAILED; @@ -2099,6 +2115,12 @@ int phNxpNciHal_close(bool bShutdown) { status = phTmlNfc_Shutdown(); + if (0 != pthread_join(nxpncihal_ctrl.client_thread, (void **)NULL)) { + NXPLOG_TML_E("Fail to kill client thread!"); + } + + phTmlNfc_CleanUp(); + phDal4Nfc_msgrelease(nxpncihal_ctrl.gDrvCfg.nClientId); memset(&nxpncihal_ctrl, 0x00, sizeof(nxpncihal_ctrl)); @@ -2438,14 +2460,14 @@ int phNxpNciHal_ioctl(long arg, void* p_data) { if(pInpOutData->out.data.nciRsp.p_rsp[0] == 0x4F && pInpOutData->out.data.nciRsp.p_rsp[1] == 0x01 && pInpOutData->out.data.nciRsp.p_rsp[2] == 0x01 && pInpOutData->out.data.nciRsp.p_rsp[3] == 0x00 - && pInpOutData->inp.data.nciCmd.p_cmd[1] == 0x01) + && pInpOutData->inp.data.nciCmd.p_cmd[3] == 0x01) { NXPLOG_NCIHAL_D("OMAPI COMMAND for Open SUCCESS : 0x%x",pInpOutData->out.data.nciRsp.p_rsp[3]); ret=pInpOutData->out.data.nciRsp.p_rsp[3]; } else if(pInpOutData->out.data.nciRsp.p_rsp[0] == 0x4F && pInpOutData->out.data.nciRsp.p_rsp[1] == 0x01 && pInpOutData->out.data.nciRsp.p_rsp[2] == 0x01 && pInpOutData->out.data.nciRsp.p_rsp[3] == 0x00 - && pInpOutData->inp.data.nciCmd.p_cmd[1] == 0x00) + && pInpOutData->inp.data.nciCmd.p_cmd[3] == 0x00) { NXPLOG_NCIHAL_D("OMAPI COMMAND for Close SUCCESS : 0x%x",pInpOutData->out.data.nciRsp.p_rsp[3]); @@ -2458,8 +2480,12 @@ int phNxpNciHal_ioctl(long arg, void* p_data) { } break; case HAL_NFC_SET_SPM_PWR: - ret = phPalEse_spi_ioctl(phPalEse_e_ChipRst, gpphTmlNfc_Context->pDevHandle, level); - break; + ret = phPalEse_spi_ioctl(phPalEse_e_ChipRst, gpphTmlNfc_Context->pDevHandle, level); + if ((nxpncihal_ctrl.halStatus == HAL_STATUS_MIN_OPEN) && (level == 0x01)) { + NXPLOG_NCIHAL_D(" HAL close after SPI close , while NFC is Off"); + phNxpNciHal_close(false); + } + break; case HAL_NFC_SET_POWER_SCHEME: ret = phPalEse_spi_ioctl(phPalEse_e_SetPowerScheme,gpphTmlNfc_Context->pDevHandle,level); break; diff --git a/halimpl/tml/phTmlNfc.cc b/halimpl/tml/phTmlNfc.cc index 87ec71f..b8d7628 100755 --- a/halimpl/tml/phTmlNfc.cc +++ b/halimpl/tml/phTmlNfc.cc @@ -43,7 +43,6 @@ static uint8_t bCurrentRetryCount = (2000 / PHTMLNFC_MAXTIME_RETRANSMIT) + 1; phTmlNfc_Context_t* gpphTmlNfc_Context = NULL; /* Local Function prototypes */ static NFCSTATUS phTmlNfc_StartThread(void); -static void phTmlNfc_CleanUp(void); static void phTmlNfc_ReadDeferredCb(void* pParams); static void phTmlNfc_WriteDeferredCb(void* pParams); static void * phTmlNfc_TmlThread(void* pParam); @@ -543,7 +542,7 @@ static void * phTmlNfc_TmlWriterThread(void* pParam) { ** Returns None ** *******************************************************************************/ -static void phTmlNfc_CleanUp(void) { +void phTmlNfc_CleanUp(void) { if (NULL == gpphTmlNfc_Context) { return; } @@ -606,7 +605,6 @@ NFCSTATUS phTmlNfc_Shutdown(void) { } NXPLOG_TML_D("bThreadDone == 0"); - phTmlNfc_CleanUp(); } else { wShutdownStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_NOT_INITIALISED); } @@ -975,3 +973,20 @@ void phTmlNfc_set_fragmentation_enabled(phTmlNfc_i2cfragmentation_t result) { phTmlNfc_i2cfragmentation_t phTmlNfc_get_fragmentation_enabled() { return fragmentation_enabled; } + +/******************************************************************************* +** +** Function phTmlNfc_Shutdown_CleanUp +** +** Description wrapper function for shutdown and cleanup of resources +** +** Parameters None +** +** Returns NFCSTATUS +** +*******************************************************************************/ +NFCSTATUS phTmlNfc_Shutdown_CleanUp() { + NFCSTATUS wShutdownStatus = phTmlNfc_Shutdown(); + phTmlNfc_CleanUp(); + return wShutdownStatus; +} diff --git a/halimpl/tml/phTmlNfc.h b/halimpl/tml/phTmlNfc.h index 03cde41..16c6c70 100644..100755 --- a/halimpl/tml/phTmlNfc.h +++ b/halimpl/tml/phTmlNfc.h @@ -210,6 +210,8 @@ typedef enum { /* Function declarations */ NFCSTATUS phTmlNfc_Init(pphTmlNfc_Config_t pConfig); NFCSTATUS phTmlNfc_Shutdown(void); +NFCSTATUS phTmlNfc_Shutdown_CleanUp(); +void phTmlNfc_CleanUp(void); NFCSTATUS phTmlNfc_Write(uint8_t* pBuffer, uint16_t wLength, pphTmlNfc_TransactCompletionCb_t pTmlWriteComplete, void* pContext); |
