diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-08-12 23:09:13 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-08-12 23:09:13 +0000 |
commit | 220646dd1238976195d0ebb0ce2328a42c5aae57 (patch) | |
tree | 97dd730c1158a3742f1f3071850e09956e857a75 | |
parent | 7492ba3ed7160977ad4796067e5da5a924ed2696 (diff) | |
parent | 16d7dd9294a4ff1da8eefe31d2a762983baaab72 (diff) | |
download | secure_element-android11-qpr1-d-release.tar.gz |
Snap for 6758226 from 16d7dd9294a4ff1da8eefe31d2a762983baaab72 to rvc-qpr1-releaseandroid-11.0.0_r31android-11.0.0_r29android-11.0.0_r28android-11.0.0_r27android-11.0.0_r26android-11.0.0_r24android-11.0.0_r23android-11.0.0_r22android-11.0.0_r21android-11.0.0_r20android-11.0.0_r19android-11.0.0_r18android11-qpr1-s2-releaseandroid11-qpr1-s1-releaseandroid11-qpr1-releaseandroid11-qpr1-d-s1-releaseandroid11-qpr1-d-release
Change-Id: I1cc8a01825289324fb339d30555d23bf7b124f31
-rw-r--r-- | ese-spi-driver/SpiLayerComm.cc | 19 | ||||
-rw-r--r-- | ese-spi-driver/SpiLayerComm.h | 8 | ||||
-rw-r--r-- | ese-spi-driver/SpiLayerDriver.cc | 39 | ||||
-rw-r--r-- | ese-spi-driver/SpiLayerDriver.h | 9 | ||||
-rw-r--r-- | ese-spi-driver/SpiLayerInterface.cc | 3 | ||||
-rw-r--r-- | ese-spi-driver/SpiLayerInterface.h | 4 | ||||
-rw-r--r-- | ese-spi-driver/StEseApi.cc | 58 | ||||
-rw-r--r-- | ese-spi-driver/T1protocol.cc | 23 | ||||
-rw-r--r-- | ese-spi-driver/utils-lib/Utils.cc | 16 | ||||
-rw-r--r-- | ese-spi-driver/utils-lib/Utils.h | 10 | ||||
-rw-r--r-- | ese-spi-driver/utils-lib/ese_config.h | 2 | ||||
-rw-r--r-- | libese-hal-st.conf | 11 |
12 files changed, 158 insertions, 44 deletions
diff --git a/ese-spi-driver/SpiLayerComm.cc b/ese-spi-driver/SpiLayerComm.cc index a6e4008..3139e80 100644 --- a/ese-spi-driver/SpiLayerComm.cc +++ b/ese-spi-driver/SpiLayerComm.cc @@ -35,6 +35,21 @@ int pollInterval; /******************************************************************************* ** +** Function SpiLayerComm_init +** +** Description Initialize +** +** Parameters spiDevPath - Spi device path. +** +** Returns null +** +*******************************************************************************/ +void SpiLayerComm_init(SpiDriver_config_t* tSpiDriver) { + pollInterval = tSpiDriver->polling_interval; + STLOG_HAL_D("SpiLayerDriver_init pollInterval= %d us", pollInterval); +} +/******************************************************************************* +** ** Function SpiLayerComm_waitForAtpLength ** ** Description Starts the polling mechanism to read the length of the ATP. @@ -236,7 +251,8 @@ int SpiLayerComm_waitForResponse(Tpdu* respTpdu, int nBwt) { // Start the polling mechanism while (true) { // Wait between each polling sequence - usleep(1000); + usleep(pollInterval); + // Read the slave response by sending three null bytes if (SpiLayerDriver_read(&pollingRxByte, 1) != 1) { STLOG_HAL_E("Error reading a valid NAD from the slave."); @@ -268,7 +284,6 @@ int SpiLayerComm_waitForResponse(Tpdu* respTpdu, int nBwt) { if (SpiLayerDriver_read(buffer, 2) != 2) { return -1; } - // Save the prologue read into the tpduRx respTpdu->nad = pollingRxByte; respTpdu->pcb = buffer[0]; diff --git a/ese-spi-driver/SpiLayerComm.h b/ese-spi-driver/SpiLayerComm.h index 442f30f..fa06586 100644 --- a/ese-spi-driver/SpiLayerComm.h +++ b/ese-spi-driver/SpiLayerComm.h @@ -19,6 +19,7 @@ #ifndef SPILAYERCOMM_H_ #define SPILAYERCOMM_H_ +#include "SpiLayerInterface.h" #include "utils-lib/Tpdu.h" #define NAD_HOST_TO_SLAVE 0x21 @@ -29,6 +30,13 @@ // Global variables /** + * Initialize internal variables. + * + * @return null + */ + +void SpiLayerComm_init(SpiDriver_config_t* tSpiDriver); +/** * Starts the polling mechanism to read the length of the ATP. * * @returns 0 if everything is ok, -1 otherwise. diff --git a/ese-spi-driver/SpiLayerDriver.cc b/ese-spi-driver/SpiLayerDriver.cc index d2a1509..757fde8 100644 --- a/ese-spi-driver/SpiLayerDriver.cc +++ b/ese-spi-driver/SpiLayerDriver.cc @@ -28,9 +28,25 @@ int spiDeviceId; int currentMode; struct timeval lastRxTxTime; #define LINUX_DBGBUFFER_SIZE 300 +int BGT = 1000; // in us /******************************************************************************* ** +** Function SpiLayerDriver_init +** +** Description Initialize +** +** Parameters spiDevPath - Spi device path. +** +** Returns null +** +*******************************************************************************/ +void SpiLayerDriver_init(SpiDriver_config_t* tSpiDriver) { + BGT = tSpiDriver->bgt; + STLOG_HAL_D("SpiLayerDriver_init BGT= %d us", BGT); +} +/******************************************************************************* +** ** Function SpiLayerDriver_open ** ** Description Open the spi device driver. @@ -95,11 +111,12 @@ int SpiLayerDriver_read(uint8_t* rxBuffer, unsigned int bytesToRead) { struct timeval currentTime; gettimeofday(¤tTime, 0); STLOG_HAL_V(" Now: %ld,%ld", currentTime.tv_sec, currentTime.tv_usec); - int elapsedTime = Utils_getElapsedTimeInMs(lastRxTxTime, currentTime); - if (elapsedTime < MIN_TIME_BETWEEN_MODE_SWITCH) { - int waitTime = MIN_TIME_BETWEEN_MODE_SWITCH - elapsedTime; - STLOG_HAL_V("Waiting %d ms to switch from TX to RX", waitTime); - usleep(waitTime * 1000); + + int elapsedTimeUs = Utils_getElapsedTimeInUs(lastRxTxTime, currentTime); + if (elapsedTimeUs < BGT) { + int waitTime = BGT - elapsedTimeUs; + STLOG_HAL_V("Waiting %d us to switch from TX to RX", waitTime); + usleep(waitTime); } gettimeofday(¤tTime, 0); STLOG_HAL_V("Start RX: %ld,%ld", currentTime.tv_sec, currentTime.tv_usec); @@ -162,12 +179,12 @@ int SpiLayerDriver_write(uint8_t* txBuffer, unsigned int txBufferLength) { STLOG_HAL_V(" Last RX: %ld,%ld", lastRxTxTime.tv_sec, lastRxTxTime.tv_usec); struct timeval currentTime; gettimeofday(¤tTime, 0); - STLOG_HAL_V(" Now: %ld,%ld", currentTime.tv_sec, currentTime.tv_usec); - int elapsedTime = Utils_getElapsedTimeInMs(lastRxTxTime, currentTime); - if (elapsedTime < MIN_TIME_BETWEEN_MODE_SWITCH) { - int waitTime = MIN_TIME_BETWEEN_MODE_SWITCH - elapsedTime; - STLOG_HAL_V("Waiting %d ms to switch from RX to TX", waitTime); - usleep(waitTime * 1000); + + int elapsedTimeUs = Utils_getElapsedTimeInUs(lastRxTxTime, currentTime); + if (elapsedTimeUs < BGT) { + int waitTime = BGT - elapsedTimeUs; + STLOG_HAL_V("Waiting %d us to switch from RX to TX", waitTime); + usleep(waitTime); } gettimeofday(¤tTime, 0); STLOG_HAL_V("Start TX: %ld,%ld", currentTime.tv_sec, currentTime.tv_usec); diff --git a/ese-spi-driver/SpiLayerDriver.h b/ese-spi-driver/SpiLayerDriver.h index 5da1ab6..61b75cc 100644 --- a/ese-spi-driver/SpiLayerDriver.h +++ b/ese-spi-driver/SpiLayerDriver.h @@ -25,6 +25,7 @@ #include <stdio.h> #include <sys/ioctl.h> #include <unistd.h> +#include "SpiLayerInterface.h" #define ATP_FILE_PATH "/data/vendor/ese/atp.bin" @@ -35,6 +36,14 @@ #define ST54J_SE_PULSE_RESET _IOR(ST54J_SE_MAGIC, 0x01, unsigned int) /** + * Initialize internal variables. + * + * @return null + */ + +void SpiLayerDriver_init(SpiDriver_config_t* tSpiDriver); + +/** * Open the spi device driver. * * @return -1 if an error occurred, file descriptor if success. diff --git a/ese-spi-driver/SpiLayerInterface.cc b/ese-spi-driver/SpiLayerInterface.cc index 11b9f65..11a7065 100644 --- a/ese-spi-driver/SpiLayerInterface.cc +++ b/ese-spi-driver/SpiLayerInterface.cc @@ -51,6 +51,9 @@ int SpiLayerInterface_init(SpiDriver_config_t* tSpiDriver) { // Configure the SPI before start the data exchange with the eSE char* spiDevPath = tSpiDriver->pDevName; + SpiLayerComm_init(tSpiDriver); + SpiLayerDriver_init(tSpiDriver); + int DevHandle = SpiLayerDriver_open(spiDevPath); tSpiDriver->pDevHandle = (void*)((intptr_t)DevHandle); if (DevHandle == -1) { diff --git a/ese-spi-driver/SpiLayerInterface.h b/ese-spi-driver/SpiLayerInterface.h index 01c0cf9..c6ed047 100644 --- a/ese-spi-driver/SpiLayerInterface.h +++ b/ese-spi-driver/SpiLayerInterface.h @@ -30,6 +30,10 @@ typedef struct SpiDriver_config { * e.g. On Linux based systems this would be /dev/p73 */ + int bgt; + + int polling_interval; + uint32_t devMaxFreq; /*!< Communication speed between DH and ESE * diff --git a/ese-spi-driver/StEseApi.cc b/ese-spi-driver/StEseApi.cc index 9f046d7..f47ede6 100644 --- a/ese-spi-driver/StEseApi.cc +++ b/ese-spi-driver/StEseApi.cc @@ -18,11 +18,11 @@ ******************************************************************************/ #define LOG_TAG "StEse_HalApi" -#include <pthread.h> #include "StEseApi.h" -#include "SpiLayerComm.h" #include <cutils/properties.h> #include <ese_config.h> +#include <pthread.h> +#include "SpiLayerComm.h" #include "T1protocol.h" #include "android_logmsg.h" @@ -31,10 +31,14 @@ /* ESE Context structure */ ese_Context_t ese_ctxt; -const char* halVersion = "ST54-SE HAL1.0 Version 1.0.20"; +const char* halVersion = "ST54-SE HAL1.0 Version 1.0.22"; pthread_mutex_t mutex; +bool ConfRead = 0; +unsigned int PollInt_confvalue = 1000; +unsigned int BGT_confvalue = 1000; + /****************************************************************************** * Function StEseLog_InitializeLogLevel * @@ -84,6 +88,16 @@ ESESTATUS StEse_init() { strcpy(ese_dev_node, ese_node.c_str()); tSpiDriver.pDevName = ese_dev_node; + if (!ConfRead) { + PollInt_confvalue = + EseConfig::getUnsigned(NAME_ST_ESE_DEV_POLLING_INTERVAL, 1000); + BGT_confvalue = EseConfig::getUnsigned(NAME_ST_ESE_DEV_BGT, 1000); + ConfRead = true; + } + + tSpiDriver.polling_interval = PollInt_confvalue; + tSpiDriver.bgt = BGT_confvalue; + /* Initialize SPI Driver layer */ if (T1protocol_init(&tSpiDriver) != ESESTATUS_SUCCESS) { STLOG_HAL_E("T1protocol_init Failed"); @@ -134,6 +148,7 @@ bool StEseApi_isOpen() { ESESTATUS StEse_Transceive(StEse_data* pCmd, StEse_data* pRsp) { ESESTATUS status = ESESTATUS_SUCCESS; static int pTxBlock_len = 0; + int retry_count = 0; uint16_t pCmdlen = pCmd->len; STLOG_HAL_D("%s : Enter EseLibStatus = %d ", __func__, ese_ctxt.EseLibStatus); @@ -155,33 +170,50 @@ ESESTATUS StEse_Transceive(StEse_data* pCmd, StEse_data* pRsp) { uint8_t* CmdPart = pCmd->p_data; +retry: while (pCmdlen > ATP.ifsc) { pTxBlock_len = ATP.ifsc; int rc = T1protocol_transcieveApduPart(CmdPart, pTxBlock_len, false, - (StEse_data*) pRsp); - if (rc < 0) { + (StEse_data*)pRsp); + + if ((rc == -2) && (retry_count < 3)) { + retry_count++; + STLOG_HAL_E(" %s ESE - resync was needed, resend the whole frame\n", + __FUNCTION__); + pCmdlen = pCmd->len; + CmdPart = pCmd->p_data; + goto retry; + } else if (rc < 0) { STLOG_HAL_E(" %s ESE - Error, release access \n", __FUNCTION__); status = ESESTATUS_FAILED; - + retry_count = 0; pthread_mutex_unlock(&mutex); return status; + } else { + retry_count = 0; } + pCmdlen -= pTxBlock_len; CmdPart = CmdPart + pTxBlock_len; - if (ESESTATUS_SUCCESS != status) { - STLOG_HAL_E(" %s T1protocol_transcieveApduPart- Failed \n", __FUNCTION__); - } } - int rc = T1protocol_transcieveApduPart(CmdPart, pCmdlen, true, - (StEse_data*) pRsp); - if (rc < 0) status = ESESTATUS_FAILED; + + int rc = + T1protocol_transcieveApduPart(CmdPart, pCmdlen, true, (StEse_data*)pRsp); + if ((rc == -2) && (retry_count < 3)) { + retry_count++; + STLOG_HAL_E(" %s ESE - resync was needed, resend\n", __FUNCTION__); + pCmdlen = pCmd->len; + CmdPart = pCmd->p_data; + goto retry; + } else if (rc < 0) + status = ESESTATUS_FAILED; if (ESESTATUS_SUCCESS != status) { STLOG_HAL_E(" %s T1protocol_transcieveApduPart- Failed \n", __FUNCTION__); } - + retry_count = 0; STLOG_HAL_D(" %s ESE - Processing complete, release access \n", __FUNCTION__); pthread_mutex_unlock(&mutex); diff --git a/ese-spi-driver/T1protocol.cc b/ese-spi-driver/T1protocol.cc index c9db707..7b84790 100644 --- a/ese-spi-driver/T1protocol.cc +++ b/ese-spi-driver/T1protocol.cc @@ -576,9 +576,9 @@ int T1protocol_formSblockResponse(Tpdu* responseTpdu, Tpdu* requestTpdu) { ** Returns 0 If all went is ok, -1 otherwise. ** *******************************************************************************/ -int T1protocol_processSBlock(Tpdu* originalCmdTpdu, Tpdu* lastCmdTpduSent, +int T1protocol_processSBlock(__attribute((unused)) Tpdu* originalCmdTpdu, + __attribute((unused)) Tpdu* lastCmdTpduSent, Tpdu* lastRespTpduReceived) { - int rc; if (lastRespTpduReceived->pcb == (uint8_t)SBLOCK_WTX_REQUEST_MASK) { gNextCmd = S_WTX_RES; } else if (lastRespTpduReceived->pcb == (uint8_t)SBLOCK_IFS_REQUEST_MASK) { @@ -593,20 +593,9 @@ int T1protocol_processSBlock(Tpdu* originalCmdTpdu, Tpdu* lastCmdTpduSent, } else if (lastRespTpduReceived->pcb == (uint8_t)SBLOCK_RESYNCH_RESPONSE_MASK) { T1protocol_resetSequenceNumbers(); - // Reset the sequence number of the original Tpdu if needed - if ((originalCmdTpdu->pcb & IBLOCK_NS_BIT_MASK) > 0) { - originalCmdTpdu->pcb &= ~IBLOCK_NS_BIT_MASK; - - rc = Tpdu_formTpdu(originalCmdTpdu->nad, originalCmdTpdu->pcb, - originalCmdTpdu->len, originalCmdTpdu->data, - originalCmdTpdu); - if (rc < 0) { - return rc; - } - } - Tpdu_copy(lastCmdTpduSent, originalCmdTpdu); - gNextCmd = I_block; + STLOG_HAL_E("RESYNCH response - resend the whole frame"); + return -2; } else if (lastRespTpduReceived->pcb == (uint8_t)SBLOCK_ABORT_REQUEST_MASK) { // TODO @@ -705,8 +694,8 @@ void T1protocol_updateRecoveryStatus() { break; case RECOVERY_STATUS_RESEND_1: - STLOG_HAL_D("recoveryStatus: RESEND 1 -> RESYNC 1"); - recoveryStatus = RECOVERY_STATUS_RESYNC_1; + STLOG_HAL_D("recoveryStatus: RESEND 1 -> RESYNC 1"); + recoveryStatus = RECOVERY_STATUS_RESYNC_1; break; case RECOVERY_STATUS_RESYNC_1: diff --git a/ese-spi-driver/utils-lib/Utils.cc b/ese-spi-driver/utils-lib/Utils.cc index c444b2b..7c411cd 100644 --- a/ese-spi-driver/utils-lib/Utils.cc +++ b/ese-spi-driver/utils-lib/Utils.cc @@ -62,6 +62,22 @@ int Utils_getElapsedTimeInMs(struct timeval t1, struct timeval t2) { /*******************************************************************************
**
+** Function Utils_getElapsedTimeInUs
+**
+** Description Returns the difference of time (in Us) between t1 and t2.
+**
+** Parameters t1 - initial time.
+** t2 - final time.
+**
+** Returns The difference t2 - t1 in ms.
+**
+*******************************************************************************/
+int Utils_getElapsedTimeInUs(struct timeval t1, struct timeval t2) {
+ return (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
+}
+
+/*******************************************************************************
+**
** Function Utils_printCurrentTime
**
** Description Prints current time to standard log.
diff --git a/ese-spi-driver/utils-lib/Utils.h b/ese-spi-driver/utils-lib/Utils.h index 16bded2..3c74beb 100644 --- a/ese-spi-driver/utils-lib/Utils.h +++ b/ese-spi-driver/utils-lib/Utils.h @@ -45,6 +45,16 @@ char* convert(uint8_t* buf); int Utils_getElapsedTimeInMs(struct timeval t1, struct timeval t2);
/**
+ * Returns the difference of time (in us) between t1 and t2.
+ *
+ * @param t1 The initial time.
+ * @param t2 The final time.
+ *
+ * @return The difference t2 - t1 in ms.
+ */
+int Utils_getElapsedTimeInUs(struct timeval t1, struct timeval t2);
+
+/**
* Prints current time to standard log.
*
* @param prefix The prefix to be printed before the time.
diff --git a/ese-spi-driver/utils-lib/ese_config.h b/ese-spi-driver/utils-lib/ese_config.h index 84624e5..5fd41a4 100644 --- a/ese-spi-driver/utils-lib/ese_config.h +++ b/ese-spi-driver/utils-lib/ese_config.h @@ -28,6 +28,8 @@ * ########################## */ #define NAME_STESE_HAL_LOGLEVEL "STESE_HAL_LOGLEVEL" #define NAME_ST_ESE_DEV_NODE "ST_ESE_DEV_NODE" +#define NAME_ST_ESE_DEV_BGT "ST_ESE_DEV_BGT" +#define NAME_ST_ESE_DEV_POLLING_INTERVAL "ST_ESE_DEV_POLLING_INTERVAL" class EseConfig { public: diff --git a/libese-hal-st.conf b/libese-hal-st.conf index a650760..c43e0e1 100644 --- a/libese-hal-st.conf +++ b/libese-hal-st.conf @@ -5,6 +5,15 @@ # ST HAL trace log level STESE_HAL_LOGLEVEL=4 -ST_ESE_DEV_NODE="/dev/st54j" +############################################################################### +# Configure the device node +ST_ESE_DEV_NODE="/dev/st54j_se" + +############################################################################### +# Configure the polling interval (in us) +ST_ESE_DEV_POLLING_INTERVAL=1500 +############################################################################### +# Configure the BGT timing (in us) +ST_ESE_DEV_BGT=1000 |