diff options
author | Yerriswamy <yerriswamy.kurubathayanna@nxp.com> | 2017-10-23 16:53:35 +0530 |
---|---|---|
committer | nxpandroid <srikrishna.pramoda@nxp.com> | 2017-11-16 09:36:10 +0530 |
commit | f3dd540730594f503867445384235f2089f0aa7b (patch) | |
tree | 7b28f68c427e7eca8bd9e363e473659110a03c89 | |
parent | 1754ee0df13f110ab544744bb65f52a17301f230 (diff) | |
download | android_vendor_nxp_opensource_packages_apps_Nfc-f3dd540730594f503867445384235f2089f0aa7b.tar.gz android_vendor_nxp_opensource_packages_apps_Nfc-f3dd540730594f503867445384235f2089f0aa7b.tar.bz2 android_vendor_nxp_opensource_packages_apps_Nfc-f3dd540730594f503867445384235f2089f0aa7b.zip |
p61-jcop-lib library dynamic loading implementation
-rw-r--r-- | nci/jni/AlaLib.h | 107 | ||||
-rw-r--r-- | nci/jni/Android.mk | 15 | ||||
-rw-r--r-- | nci/jni/IChannel.h | 87 | ||||
-rw-r--r-- | nci/jni/JcDnld.h | 78 | ||||
-rw-r--r-- | nci/jni/JcopManager.cpp | 388 | ||||
-rw-r--r-- | nci/jni/JcopManager.h | 289 | ||||
-rw-r--r-- | nci/jni/NativeNfcAla.cpp | 37 | ||||
-rwxr-xr-x | nci/jni/NativeNfcManager.cpp | 21 |
8 files changed, 981 insertions, 41 deletions
diff --git a/nci/jni/AlaLib.h b/nci/jni/AlaLib.h new file mode 100644 index 00000000..0ad3b417 --- /dev/null +++ b/nci/jni/AlaLib.h @@ -0,0 +1,107 @@ + /* + * Copyright (C) 2015 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifdef __cplusplus + +extern "C" { + +#endif + + +#ifndef ALALIB_H_ +#define ALALIB_H_ + +#include <stdio.h> +#include <stdint.h> +#include <stdbool.h> +#include "IChannel.h" + +/******************************************************************************* +** +** Function: ALA_Init +** +** Description: Initializes the ALA library and opens the DWP communication channel +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char ALA_Init(IChannel *channel); + +/******************************************************************************* +** +** Function: ALA_Start +** +** Description: Starts the ALA over DWP +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +#if(NXP_LDR_SVC_VER_2 == TRUE) +unsigned char ALA_Start(const char *name, const char *dest, uint8_t *pdata, uint16_t len, uint8_t *respSW); +#else +unsigned char ALA_Start(const char *name, uint8_t *pdata, uint16_t len); +#endif + +/******************************************************************************* +** +** Function: ALA_DeInit +** +** Description: Deinitializes the ALA Lib +** +** Returns: true if ok. +** +*******************************************************************************/ +bool ALA_DeInit(); + +#if(NXP_LDR_SVC_VER_2 == TRUE) +/******************************************************************************* +** +** Function: ALA_lsGetVersion +** +** Description: Get the Loader service Applet and cleint version +** +** Returns: byte[] array. +** +*******************************************************************************/ +unsigned char ALA_lsGetVersion(uint8_t *pVersion); +unsigned char ALA_lsGetStatus(uint8_t *pVersion); +unsigned char ALA_lsGetAppletStatus(uint8_t *pVersion); +#else +void ALA_GetlistofApplets(char *list[], uint8_t* num); +unsigned char ALA_GetCertificateKey(uint8_t *pKey, int32_t *pKeylen); +#endif + +inline int FSCANF_BYTE(FILE *stream, const char *format, void* pVal) +{ + int Result = 0; + + if((NULL != stream) && (NULL != format) && (NULL != pVal)) + { + unsigned int dwVal; + unsigned char* pTmp = (unsigned char*)pVal; + Result = fscanf(stream, format, &dwVal); + + (*pTmp) = (unsigned char)(dwVal & 0x000000FF); + } + return Result; +} + +#endif /* ALALIB_H_ */ + +#ifdef __cplusplus + +} + +#endif diff --git a/nci/jni/Android.mk b/nci/jni/Android.mk index c1a8223c..0c87dee2 100644 --- a/nci/jni/Android.mk +++ b/nci/jni/Android.mk @@ -22,8 +22,6 @@ LOCAL_CFLAGS += -DNFC_NXP_HFO_SETTINGS=FALSE #Enable HCE-F specific LOCAL_CFLAGS += -DNXP_NFCC_HCE_F=TRUE -NFC_NXP_ESE:= TRUE - NFC_POWER_MANAGEMENT:= TRUE ifeq ($(NFC_POWER_MANAGEMENT),TRUE) LOCAL_CFLAGS += -DNFC_POWER_MANAGEMENT=TRUE @@ -31,11 +29,7 @@ else LOCAL_CFLAGS += -DNFC_POWER_MANAGEMENT=FALSE endif -ifeq ($(NFC_NXP_ESE),TRUE) LOCAL_CFLAGS += -DNXP_LDR_SVC_VER_2=TRUE -else -LOCAL_CFLAGS += -DNXP_LDR_SVC_VER_2=FALSE -endif LOCAL_SRC_FILES := $(call all-subdir-cpp-files) $(call all-subdir-c-files) @@ -53,11 +47,6 @@ LOCAL_C_INCLUDES += \ $(VOB_COMPONENTS)/gki/common \ vendor/nxp/opensource/hardware/interfaces/nxpnfc/1.0/default/ -ifeq ($(NFC_NXP_ESE),TRUE) -LOCAL_C_INCLUDES +=external/p61-jcop-kit/include - -endif - LOCAL_SHARED_LIBRARIES := \ libicuuc \ libnativehelper \ @@ -68,10 +57,6 @@ LOCAL_SHARED_LIBRARIES := \ android.hardware.nfc@1.0\ vendor.nxp.nxpnfc@1.0 -ifeq ($(NFC_NXP_ESE),TRUE) -LOCAL_SHARED_LIBRARIES += libp61-jcop-kit -endif - #LOCAL_STATIC_LIBRARIES := libxml2 ifeq (true,$(TARGET_IS_64_BIT)) LOCAL_MULTILIB := 64 diff --git a/nci/jni/IChannel.h b/nci/jni/IChannel.h new file mode 100644 index 00000000..4e42242e --- /dev/null +++ b/nci/jni/IChannel.h @@ -0,0 +1,87 @@ + /* + * Copyright (C) 2015 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ICHANNEL_H_ +#define ICHANNEL_H_ + +typedef struct IChannel +{ +/******************************************************************************* +** +** Function: Open +** +** Description: Initialize the channel. +** +** Returns: True if ok. +** +*******************************************************************************/ +int16_t (*open)(); +/******************************************************************************* +** +** Function: close +** +** Description: Close the channel. +** +** Returns: True if ok. +** +*******************************************************************************/ +bool (*close)(int16_t mHandle); + +/******************************************************************************* +** +** Function: transceive +** +** Description: Send data to the secure element; read it's response. +** xmitBuffer: Data to transmit. +** xmitBufferSize: Length of data. +** recvBuffer: Buffer to receive response. +** recvBufferMaxSize: Maximum size of buffer. +** recvBufferActualSize: Actual length of response. +** timeoutMillisec: timeout in millisecond +** +** Returns: True if ok. +** +*******************************************************************************/ +bool (*transceive) (uint8_t* xmitBuffer, int32_t xmitBufferSize, uint8_t* recvBuffer, + int32_t recvBufferMaxSize, int32_t& recvBufferActualSize, int32_t timeoutMillisec); + +/******************************************************************************* +** +** Function: doeSE_Reset +** +** Description: Power OFF and ON to eSE +** +** Returns: None. +** +*******************************************************************************/ + +void (*doeSE_Reset)(); +/******************************************************************************* +** +** Function: doeSE_JcopDownLoadReset +** +** Description: Power OFF and ON to eSE during JCOP Update +** +** Returns: None. +** +*******************************************************************************/ + +void (*doeSE_JcopDownLoadReset)(); + +}IChannel_t; + + +#endif /* ICHANNEL_H_ */ diff --git a/nci/jni/JcDnld.h b/nci/jni/JcDnld.h new file mode 100644 index 00000000..630dd7d8 --- /dev/null +++ b/nci/jni/JcDnld.h @@ -0,0 +1,78 @@ + /* + * Copyright (C) 2015 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifdef __cplusplus + +extern "C" { + +#endif + + +#ifndef JCDNLD_H_ +#define JCDNLD_H_ + +#include "IChannel.h" +/******************************************************************************* +** +** Function: JCDNLD_Init +** +** Description: Initializes the JCOP library and opens the DWP communication channel +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char JCDNLD_Init(IChannel *channel); + +/******************************************************************************* +** +** Function: JCDNLD_StartDownload +** +** Description: Starts the JCOP update +** +** Returns: SUCCESS if ok. +** +*******************************************************************************/ +unsigned char JCDNLD_StartDownload(); + +/******************************************************************************* +** +** Function: JCDNLD_DeInit +** +** Description: Deinitializes the JCOP Lib +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_DeInit(); + +/******************************************************************************* +** +** Function: JCDNLD_CheckVersion +** +** Description: Check the existing JCOP OS version +** +** Returns: true if ok. +** +*******************************************************************************/ +bool JCDNLD_CheckVersion(); + + +#endif /* JCDNLD_H_ */ + +#ifdef __cplusplus + +} + +#endif diff --git a/nci/jni/JcopManager.cpp b/nci/jni/JcopManager.cpp new file mode 100644 index 00000000..336fbcf8 --- /dev/null +++ b/nci/jni/JcopManager.cpp @@ -0,0 +1,388 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/****************************************************************************** + * + * The original Work has been changed by NXP Semiconductors. + * + * Copyright (C) 2015 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.Pgpx_Jcop_handle + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ +/* + * Communicate with secure elements that are attached to the NFC + * controller. + */ + +#include "JcopManager.h" +#include "_OverrideLog.h" +#include <dlfcn.h> + +JcopManager* JcopManager::mJcpMgr = NULL; +static void* Pgpx_JCP_handle = NULL; +static phJcop_Context_t g_mPhJcpCtxt; +static phJcop_Context_t *pg_mPhJcpCtxt = &g_mPhJcpCtxt; +static void *Pgpx_Jcop_handle = NULL; +#define DL_STATUS_OK 0x00 + +JcopManager::JcopManager() +{ +} + +JcopManager::~JcopManager() +{ +} + +/******************************************************************************* +** +** Function: getInstance +** +** Description: Get the JcopManager singleton object. +** +** Returns: JcopManager object. +** +*******************************************************************************/ +JcopManager* JcopManager::getInstance () +{ + if(mJcpMgr == NULL){ + mJcpMgr = new JcopManager(); + } + return mJcpMgr; +} + +/******************************************************************************* +** +** Function: deleteInstance +** +** Description: Delete the JcopManager singleton object. +** +*******************************************************************************/ +void JcopManager::deleteInstance () +{ + delete mJcpMgr; +} + +/******************************************************************************* +** +** Function: JcopInitialize +** +** Description: Load the library and initialize the symbols and variables. +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFA_STATUS JcopManager::JcopInitialize () +{ + tNFA_STATUS wStatus = NFA_STATUS_OK; + //Getting pointer to JCOP module + Pgpx_Jcop_handle = dlopen("system/lib64/libp61-jcop-kit.so",RTLD_NOW); + if(Pgpx_Jcop_handle == NULL){ + ALOGE("%s: Error : opening (system/lib64/libp61-jcop-kit.so) !!", __func__); + return NFA_STATUS_FAILED; + } + // Getting pointer to ALA_Init function + if((pg_mPhJcpCtxt->ala_init = (tJCOP_INIT_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_Init")) == NULL){ + ALOGE("%s: Error while linking JCOP context (ALA_Init) !!", __func__); + return NFA_STATUS_FAILED; + } + // Getting pointer to ALA_Start function + if((pg_mPhJcpCtxt->ala_start = (tALA_START_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_Start")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_Start) !!", __func__); + } + +#if (NXP_LDR_SVC_VER_2 == FALSE) + // Getting pointer to ALA_GetlistofApplets function + if((pg_mPhJcpCtxt->ala_applets_list = (tALA_APPLET_LIST_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_GetlistofApplets")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_GetlistofApplets) !!", __func__); + } + // Getting pointer to ALA_GetCertificateKey function + if((pg_mPhJcpCtxt->ala_get_certkey = (tALA_GET_CERTKEY_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_GetCertificateKey")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_GetCertificateKey) !!", __func__); + } +#endif + + // Getting pointer to ALA_DeInit function + if((pg_mPhJcpCtxt->ala_deinit = (tJCOP_DEINIT_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_DeInit")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_DeInit) !!", __func__); + } + // Getting pointer to ALA_lsGetVersion function + if((pg_mPhJcpCtxt->ala_lsgetversion = (tALA_LS_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_lsGetVersion")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_lsGetVersion) !!", __func__); + } + // Getting pointer to ALA_lsGetStatus function + if((pg_mPhJcpCtxt->ala_lsgetstatus = (tALA_LS_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_lsGetStatus")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_lsGetStatus) !!", __func__); + } + // Getting pointer to ALA_lsGetAppletStatus function + if((pg_mPhJcpCtxt->ala_lsgetappletstatus = (tALA_LS_CBACK *)dlsym(Pgpx_Jcop_handle, "ALA_lsGetAppletStatus")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (ALA_lsGetAppletStatus) !!", __func__); + } + // Getting pointer to JCDNLD_Init function + if((pg_mPhJcpCtxt->jcop_init = (tJCOP_INIT_CBACK *)dlsym(Pgpx_Jcop_handle, "JCDNLD_Init")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (JCDNLD_Init) !!", __func__); + } + // Getting pointer to JCDNLD_StartDownload function + if((pg_mPhJcpCtxt->jcdnld_startdnld = (tJCDNLD_DWLD_CBACK *)dlsym(Pgpx_Jcop_handle, "JCDNLD_StartDownload")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (JCDNLD_StartDownload) !!", __func__); + } + // Getting pointer to JCDNLD_DeInit function + if((pg_mPhJcpCtxt->ala_deinit = (tJCOP_DEINIT_CBACK *)dlsym(Pgpx_Jcop_handle, "JCDNLD_DeInit")) == NULL){ + wStatus = NFA_STATUS_FAILED; + ALOGE("%s: Error while linking JCOP context (JCDNLD_DeInit) !!", __func__); + } + return wStatus; +} + +/******************************************************************************* +** +** Function: JcopDeInitialize +** +** Description: De-initialize the library +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFA_STATUS JcopManager::JcopDeInitialize () +{ + if(Pgpx_Jcop_handle != NULL){ + if((dlclose(Pgpx_Jcop_handle)) != DL_STATUS_OK){ + ALOGE("%s: Error : closing (system/lib64/libp61-jcop-kit.so) !!", __func__); + return NFA_STATUS_FAILED; + } + }else{ + ALOGE("%s: Invalid handle !!", __func__); + } + return NFA_STATUS_OK; +} + +/******************************************************************************* +** +** Function: AlaInitialize +** +** Description: Initializes the ALA library and opens the DWP communication channel +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::AlaInitialize (IChannel *channel) +{ + if(channel == NULL) + { + ALOGE("%s: Invalid handle !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_init(channel); +} + +/******************************************************************************* +** +** Function: AlaDeInitialize +** +** Description: Deinitializes the ALA Lib +** +** Returns: True if ok. +** +*******************************************************************************/ +bool JcopManager::AlaDeInitialize () { return pg_mPhJcpCtxt->ala_deinit(); } + +/******************************************************************************* +** +** Function: AlaStart +** +** Description: Starts the ALA over DWP +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +#if (NXP_LDR_SVC_VER_2 == TRUE) +tNFC_JBL_STATUS JcopManager::AlaStart (const char *name, const char *dest, uint8_t *pdata, uint16_t len, uint8_t *respSW) +{ + if( !name || !dest || !pdata || !respSW){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_start(name, dest, pdata, len, respSW); +} +#else +tNFC_JBL_STATUS JcopManager::AlaStart (const char *name, uint8_t *pdata, uint16_t len) +{ + if( !name || !pdata ){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_start(name, dest, pdata, len, respSW); +} +#endif + +#if (NXP_LDR_SVC_VER_2 == FALSE) +/******************************************************************************* +** +** Function: AlaGetlistofApplets +** +** Description: list all the applets. +** +*******************************************************************************/ +void JcopManager::AlaGetlistofApplets (char *list[], uint8_t* num) +{ + if(!list || !num){ + ALOGE("%s: Invalid Params !!", __func__); + return; + } + pg_mPhJcpCtxt->ala_applets_list(list, num); +} + +/******************************************************************************* +** +** Function: AlaGetCertificateKey +** +** Description: Get the certification key +** +** Returns: True if ok. +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::AlaGetCertificateKey (uint8_t *pKey, int32_t *pKeylen) +{ + if(!pKey || !pKeylen){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_get_certkey(pKey, pKeylen); +} +#endif + +/******************************************************************************* +** +** Function: AlaLsGetVersion +** +** Description: Get the version of the loader version +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::AlaLsGetVersion (uint8_t *pVersion) +{ + if(!pVersion){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_lsgetversion(pVersion); +} + +/******************************************************************************* +** +** Function: AlaLsGetAppletStatus +** +** Description: Get the status of the loader service version +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::AlaLsGetAppletStatus (uint8_t *pVersion) +{ + if(!pVersion){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_lsgetappletstatus(pVersion); +} + +/******************************************************************************* +** +** Function: AlaLsGetAppletStatus +** +** Description: Get the status of the loader service +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::AlaLsGetStatus (uint8_t *pVersion) +{ + if(!pVersion){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->ala_lsgetstatus(pVersion); +} + +/******************************************************************************* +** +** Function: JCDnldInit +** +** Description: Initializes the JCOP library and opens the DWP communication channel +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::JCDnldInit (IChannel *channel) +{ + if(!channel){ + ALOGE("%s: Invalid Params !!", __func__); + return NFA_STATUS_FAILED; + } + return pg_mPhJcpCtxt->jcop_init(channel); +} + +/******************************************************************************* +** +** Function: JCDnldStartDownload +** +** Description: Starts the JCOP update +** +** Returns: STATUS_OK if Success. +** STATUS_FAILED if unSuccessfull +** +*******************************************************************************/ +tNFC_JBL_STATUS JcopManager::JCDnldStartDownload () { return pg_mPhJcpCtxt->jcdnld_startdnld(); } + +/******************************************************************************* +** +** Function: JCDnldDeInit +** +** Description: De-initializes the JCOP Library +** +** Returns: True if ok. +** +*******************************************************************************/ +bool JcopManager::JCDnldDeInit () { return pg_mPhJcpCtxt->jcdnld_deinit(); } + + diff --git a/nci/jni/JcopManager.h b/nci/jni/JcopManager.h new file mode 100644 index 00000000..609a17d2 --- /dev/null +++ b/nci/jni/JcopManager.h @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/****************************************************************************** + * + * The original Work has been changed by NXP Semiconductors. + * + * Copyright (C) 2015 NXP Semiconductors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ +/* + * Communicate with secure elements that are attached to the NFC + * controller. + */ + +#pragma once + +extern "C"{ +#include "nfa_api.h" +#include "AlaLib.h" +#include "JcDnld.h" +#include "IChannel.h" +} + +#define pJcopMgr (JcopManager::getInstance ()) +typedef unsigned char (tJCOP_INIT_CBACK)(IChannel *channel); +#if (NXP_LDR_SVC_VER_2 == TRUE) +typedef unsigned char (tALA_START_CBACK)(const char *name, const char *dest, uint8_t *pdata, uint16_t len, uint8_t *respSW); +#else +typedef unsigned char (tALA_START_CBACK)(const char *name, uint8_t *pdata, uint16_t len); +typedef unsigned char (tALA_GET_CERTKEY_CBACK)(uint8_t *pKey, int32_t *pKeylen); +typedef void (tALA_APPLET_LIST_CBACK)(char *list[], uint8_t* num); +#endif +typedef unsigned char (tALA_LS_CBACK)(uint8_t *pVersion); +typedef unsigned char (tJCDNLD_DWLD_CBACK)(); +typedef bool (tJCOP_DEINIT_CBACK)(); + +typedef struct phJcop_Context +{ + /* Call backs */ + tJCOP_INIT_CBACK *jcop_init; + tJCOP_INIT_CBACK *ala_init; + tALA_START_CBACK *ala_start; +#if (NXP_LDR_SVC_VER_2 == FALSE) + tALA_APPLET_LIST_CBACK *ala_applets_list; + tALA_GET_CERTKEY_CBACK *ala_get_certkey; +#endif + tALA_LS_CBACK *ala_lsgetversion; + tALA_LS_CBACK *ala_lsgetstatus; + tALA_LS_CBACK *ala_lsgetappletstatus; + tJCDNLD_DWLD_CBACK *jcdnld_startdnld; + tJCOP_DEINIT_CBACK *ala_deinit; + tJCOP_DEINIT_CBACK *jcdnld_deinit; +}phJcop_Context_t; +typedef unsigned char tNFC_JBL_STATUS; + +class JcopManager +{ +private: + static JcopManager *mJcpMgr; + /******************************************************************************* + ** + ** Function: JcopManager + ** + ** Description: Initialize member variables. + ** + ** Returns: None + ** + *******************************************************************************/ + JcopManager (); + + + /******************************************************************************* + ** + ** Function: ~JcopManager + ** + ** Description: Release all resources. + ** + ** Returns: None + ** + *******************************************************************************/ + ~JcopManager (); + +public: + /******************************************************************************* + ** + ** Function: getInstance + ** + ** Description: Get the JcopManager singleton object. + ** + ** Returns: JcopManager object. + ** + *******************************************************************************/ + static JcopManager* getInstance (); + + /******************************************************************************* + ** + ** Function: deleteInstance + ** + ** Description: Delete the JcopManager singleton object. + ** + *******************************************************************************/ + void deleteInstance (); + + /******************************************************************************* + ** + ** Function: JcopInitialize + ** + ** Description: Load the library and initialize the symbols and variables. + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFA_STATUS JcopInitialize (); + + /******************************************************************************* + ** + ** Function: JcopDeInitialize + ** + ** Description: De-initialize the library + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFA_STATUS JcopDeInitialize (); + + /******************************************************************************* + ** + ** Function: AlaInitialize + ** + ** Description: Initializes the ALA library and opens the DWP communication channel + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS AlaInitialize (IChannel *channel); + + /******************************************************************************* + ** + ** Function: AlaDeInitialize + ** + ** Description: Deinitializes the ALA Lib + ** + ** Returns: True if ok. + ** + *******************************************************************************/ + bool AlaDeInitialize (); + + /******************************************************************************* + ** + ** Function: AlaStart + ** + ** Description: Starts the ALA over DWP + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ +#if (NXP_LDR_SVC_VER_2 == TRUE) + tNFC_JBL_STATUS AlaStart (const char *name, const char *dest, uint8_t *pdata, uint16_t len, uint8_t *respSW); +#else + tNFC_JBL_STATUS AlaStart (const char *name, uint8_t *pdata, uint16_t len); +#endif + + /******************************************************************************* + ** + ** Function: AlaLsGetVersion + ** + ** Description: Get the version of the loader version + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS AlaLsGetVersion (uint8_t *pVersion); + + /******************************************************************************* + ** + ** Function: AlaLsGetAppletStatus + ** + ** Description: Get the status of the loader service version + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS AlaLsGetAppletStatus (uint8_t *pVersion); + + /******************************************************************************* + ** + ** Function: AlaLsGetAppletStatus + ** + ** Description: Get the status of the loader service + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS AlaLsGetStatus (uint8_t *pVersion); + +#if (NXP_LDR_SVC_VER_2 == FALSE) + /******************************************************************************* + ** + ** Function: AlaGetlistofApplets + ** + ** Description: list all the applets. + ** + *******************************************************************************/ + + void AlaGetlistofApplets (char *list[], uint8_t* num); + + + /******************************************************************************* + ** + ** Function: AlaGetCertificateKey + ** + ** Description: Get the certification key + ** + ** Returns: True if ok. + ** + *******************************************************************************/ + tNFC_JBL_STATUS AlaGetCertificateKey (uint8_t *pKey, int32_t *pKeylen); +#endif + + + + /******************************************************************************* + ** + ** Function: JCDnldInit + ** + ** Description: Initializes the JCOP library and opens the DWP communication channel + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS JCDnldInit (IChannel *channel); + + /******************************************************************************* + ** + ** Function: JCDnldStartDownload + ** + ** Description: Starts the JCOP update + ** + ** Returns: STATUS_OK if Success. + ** STATUS_FAILED if unSuccessfull + ** + *******************************************************************************/ + tNFC_JBL_STATUS JCDnldStartDownload (); + + /******************************************************************************* + ** + ** Function: JCDnldDeInit + ** + ** Description: De-initializes the JCOP Library + ** + ** Returns: True if ok. + ** + *******************************************************************************/ + bool JCDnldDeInit (); + +}; diff --git a/nci/jni/NativeNfcAla.cpp b/nci/jni/NativeNfcAla.cpp index 705737bf..c331672c 100644 --- a/nci/jni/NativeNfcAla.cpp +++ b/nci/jni/NativeNfcAla.cpp @@ -21,10 +21,9 @@ #include "DwpChannel.h" #include "SecureElement.h" #include "TransactionController.h" +#include "JcopManager.h" extern "C" { - #include "AlaLib.h" - #include "IChannel.h" #include "phNxpConfig.h" } #define LS_DEFAULT_VERSION 0x20 @@ -82,7 +81,7 @@ int nfcManager_GetAppletsList(JNIEnv* e, jobject o, jobjectArray list) startRfDiscovery (false); } ALOGV("%s: list_len=0x%x", __func__, list_len); - ALA_GetlistofApplets(name, &num); + pJcopMgr->AlaGetlistofApplets(name, &num); if((num != 0) && (list_len >= num)) @@ -155,7 +154,7 @@ int nfcManager_doAppletLoadApplet(JNIEnv* e, jobject o, jstring name, jbyteArray startRfDiscovery (false); } DWPChannel_init(&Dwp); - wStatus = ALA_Init(&Dwp); + wStatus = JcopManager::getInstance().AlaInitialize(&Dwp); if(wStatus != NFA_STATUS_OK) { ALOGE("%s: ALA initialization failed", __func__); @@ -168,9 +167,9 @@ int nfcManager_doAppletLoadApplet(JNIEnv* e, jobject o, jstring name, jbyteArray ScopedByteArrayRO bytes(e, data); uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); size_t bufLen = bytes.size(); - wStatus = ALA_Start(choice, buf, bufLen); + wStatus = pJcopMgr->AlaStart(choice, buf, bufLen); } - stat = ALA_DeInit(); + stat = pJcopMgr->AlaDeInitialize(); if(choice != NULL) e->ReleaseStringUTFChars(name, choice); @@ -237,7 +236,7 @@ jbyteArray nfcManager_lsExecuteScript(JNIEnv* e, jobject o, jstring name, jstrin startRfDiscovery (false); } DWPChannel_init(&Dwp); - wStatus = ALA_Init(&Dwp); + wStatus = pJcopMgr->AlaInitialize(&Dwp); if(wStatus != NFA_STATUS_OK) { ALOGE("%s: ALA initialization failed", __func__); @@ -264,7 +263,7 @@ jbyteArray nfcManager_lsExecuteScript(JNIEnv* e, jobject o, jstring name, jstrin ScopedByteArrayRO bytes(e, data); uint8_t* buf = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(&bytes[0])); size_t bufLen = bytes.size(); - wStatus = ALA_Start(choice,destpath, buf, bufLen,resSW); + wStatus = pJcopMgr->AlaStart(choice,destpath, buf, bufLen,resSW); //copy results back to java result = e->NewByteArray(lsExecuteResponseSize); @@ -283,7 +282,7 @@ jbyteArray nfcManager_lsExecuteScript(JNIEnv* e, jobject o, jstring name, jstrin sNfaVSCResponseEvent.wait(); //wait for NFA VS command to finish }*/ - stat = ALA_DeInit(); + stat = pJcopMgr->AlaDeInitialize(); if(choice != NULL) e->ReleaseStringUTFChars(name, choice); @@ -338,7 +337,7 @@ jbyteArray nfcManager_GetCertificateKey(JNIEnv* e, jobject) startRfDiscovery (false); } DWPChannel_init(&Dwp); - wStatus = ALA_Init(&Dwp); + wStatus = pJcopMgr->AlaInitialize(&Dwp); if(wStatus != NFA_STATUS_OK) { ALOGE("%s: ALA initialization failed", __func__); @@ -346,7 +345,7 @@ jbyteArray nfcManager_GetCertificateKey(JNIEnv* e, jobject) else { ALOGE("%s: start Get reference Certificate Key", __func__); - wStatus = ALA_GetCertificateKey(recvBuffer, &recvBufferActualSize); + wStatus = pJcopMgr->AlaGetCertificateKey(recvBuffer, &recvBufferActualSize); } //copy results back to java @@ -356,7 +355,7 @@ jbyteArray nfcManager_GetCertificateKey(JNIEnv* e, jobject) e->SetByteArrayRegion(result, 0, recvBufferActualSize, (jbyte *) recvBuffer); } - stat = ALA_DeInit(); + stat = pJcopMgr->AlaDeInitialize(); startRfDiscovery (true); ALOGV("%s: exit: recv len=%ld", __func__, recvBufferActualSize); @@ -404,7 +403,7 @@ jbyteArray nfcManager_lsGetVersion(JNIEnv* e, jobject) startRfDiscovery (false); } DWPChannel_init(&Dwp); - wStatus = ALA_Init(&Dwp); + wStatus = pJcopMgr->AlaInitialize(&Dwp); if(wStatus != NFA_STATUS_OK) { ALOGE("%s: ALA initialization failed", __func__); @@ -412,7 +411,7 @@ jbyteArray nfcManager_lsGetVersion(JNIEnv* e, jobject) else { ALOGE("%s: start Get reference Certificate Key", __func__); - wStatus = ALA_lsGetVersion(recvBuffer); + wStatus = pJcopMgr->AlaLsGetVersion(recvBuffer); } //copy results back to java @@ -422,7 +421,7 @@ jbyteArray nfcManager_lsGetVersion(JNIEnv* e, jobject) e->SetByteArrayRegion(result, 0, recvBufferMaxSize, (jbyte *) recvBuffer); } - stat = ALA_DeInit(); + stat = pJcopMgr->AlaDeInitialize(); if(dwpChannelForceClose == false) startRfDiscovery (true); @@ -469,7 +468,7 @@ jbyteArray nfcManager_lsGetAppletStatus(JNIEnv* e, jobject) startRfDiscovery (false); } DWPChannel_init(&Dwp); - wStatus = ALA_Init(&Dwp); + wStatus = pJcopMgr->AlaInitialize(&Dwp); if(wStatus != NFA_STATUS_OK) { ALOGE("%s: ALA initialization failed", __func__); @@ -477,7 +476,7 @@ jbyteArray nfcManager_lsGetAppletStatus(JNIEnv* e, jobject) else { ALOGE("%s: start Get reference Certificate Key", __func__); - wStatus = ALA_lsGetAppletStatus(recvBuffer); + wStatus = pJcopMgr->AlaLsGetAppletStatus(recvBuffer); } ALOGV("%s: lsGetAppletStatus values %x %x", __func__, recvBuffer[0], recvBuffer[1]); @@ -487,7 +486,7 @@ jbyteArray nfcManager_lsGetAppletStatus(JNIEnv* e, jobject) { e->SetByteArrayRegion(result, 0, recvBufferMaxSize, (jbyte *) recvBuffer); } - stat = ALA_DeInit(); + stat = pJcopMgr->AlaDeInitialize(); if(dwpChannelForceClose == false) startRfDiscovery (true); @@ -523,7 +522,7 @@ jbyteArray nfcManager_lsGetStatus(JNIEnv* e, jobject) const int32_t recvBufferMaxSize = 2; uint8_t recvBuffer [recvBufferMaxSize] = {0x63,0x40}; - wStatus = ALA_lsGetStatus(recvBuffer); + wStatus = pJcopMgr->AlaLsGetStatus(recvBuffer); ALOGV("%s: lsGetStatus values %x %x", __func__, recvBuffer[0], recvBuffer[1]); //copy results back to java diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp index 17048fd3..880d93c5 100755 --- a/nci/jni/NativeNfcManager.cpp +++ b/nci/jni/NativeNfcManager.cpp @@ -59,6 +59,7 @@ #include "DwpChannel.h" #include "TransactionController.h" #include <fcntl.h> +#include "JcopManager.h" extern "C" { #include "nfc_api.h" @@ -71,10 +72,6 @@ extern "C" #include "phNxpExtns.h" #include "phNxpConfig.h" -#if(NXP_EXTNS == TRUE) - #include "JcDnld.h" - #include "IChannel.h" -#endif } #define ALOGV ALOGD #define SAK_VALUE_AT 17 @@ -2198,6 +2195,11 @@ static jboolean nfcManager_doInitialize (JNIEnv* e, jobject o) #endif stat = nfcManagerEnableNfc(theInstance); nfcManager_getFeatureList(); + if(nfcFL.nfcNxpEse){ + ALOGV("ESE Present Loading p61-jcop-lib"); + pJcopMgr->JcopInitialize(); + }else + ALOGV("ESE Not Present"); EXTNS_Init (nfaDeviceManagementCallback, nfaConnectionCallback); if (stat == NFA_STATUS_OK ) @@ -3365,6 +3367,11 @@ if(nfcFL.eseFL._JCOP_WA_ENABLE) { if(nfcFL.eseFL._JCOP_WA_ENABLE) { NFA_HciW4eSETransaction_Complete(Wait); } + if(nfcFL.nfcNxpEse){ + ALOGV("De-Initializing p61-jcop-lib library"); + pJcopMgr->JcopDeInitialize(); + pJcopMgr->deleteInstance(); + } pn544InteropAbortNow (); RoutingManager::getInstance().onNfccShutdown(); @@ -5624,7 +5631,7 @@ static int nfcManager_doJcosDownload(JNIEnv* e, jobject o) startRfDiscovery (false); } DWPChannel_init(&Dwp); - status = JCDNLD_Init(&Dwp); + status = pJcopMgr->JCDnldInit(&Dwp); if(status != NFA_STATUS_OK) { ALOGE("%s: JCDND initialization failed", __func__); @@ -5633,7 +5640,7 @@ static int nfcManager_doJcosDownload(JNIEnv* e, jobject o) { ALOGE("%s: start JcopOs_Download", __func__); se.mDownloadMode = JCOP_DOWNLOAD; - status = JCDNLD_StartDownload(); + status = pJcopMgr->JCDnldStartDownload(); } if(nfcFL.eseFL._ESE_JCOP_DWNLD_PROTECTION) { ret_val = NFC_SetP61Status ((void *)&ese_status, JCP_DWP_DWNLD_COMPLETE); @@ -5650,7 +5657,7 @@ static int nfcManager_doJcosDownload(JNIEnv* e, jobject o) } } } - stat = JCDNLD_DeInit(); + stat = pJcopMgr->JCDnldDeInit(); if(nfcFL.eseFL._ESE_JCOP_DWNLD_PROTECTION) { pTransactionController->transactionEnd(TRANSACTION_REQUESTOR(jcosDownload)); if(pendingScreenState == true) |