diff options
author | Daniel Tomas <dtomas.nxp@gmail.com> | 2011-07-22 12:06:11 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2011-07-25 13:31:09 -0700 |
commit | 04a29c85c9bdbf0b25171332013934c3436ab0ec (patch) | |
tree | c1f4eec9ed6e4e6616cfa868730688394296f46b /jni | |
parent | 7aedb9c2ae08b424c58628261befa97bdf0052e1 (diff) | |
download | packages_apps_nfc-04a29c85c9bdbf0b25171332013934c3436ab0ec.zip packages_apps_nfc-04a29c85c9bdbf0b25171332013934c3436ab0ec.tar.gz packages_apps_nfc-04a29c85c9bdbf0b25171332013934c3436ab0ec.tar.bz2 |
Prevent SE from being opened while target is in field.
This fixes an issue where an attempt to open the SE while the NFC
Controller is in initiator (reader/writer or P2P Initiator) mode
would cause a strange error response, and all further attempts to
open the SE fail.
Change-Id: I6401f644c73a993433cb73fee2eff8c11ededa1d
Diffstat (limited to 'jni')
-rw-r--r-- | jni/com_android_nfc_NativeNfcManager.cpp | 21 | ||||
-rwxr-xr-x | jni/com_android_nfc_NativeNfcSecureElement.cpp | 9 | ||||
-rw-r--r-- | jni/com_android_nfc_NativeNfcTag.cpp | 6 | ||||
-rw-r--r-- | jni/com_android_nfc_NativeP2pDevice.cpp | 5 |
4 files changed, 38 insertions, 3 deletions
diff --git a/jni/com_android_nfc_NativeNfcManager.cpp b/jni/com_android_nfc_NativeNfcManager.cpp index cdbfa82..dc233ca 100644 --- a/jni/com_android_nfc_NativeNfcManager.cpp +++ b/jni/com_android_nfc_NativeNfcManager.cpp @@ -33,6 +33,8 @@ void *gHWRef; static phNfc_sData_t gInputParam; static phNfc_sData_t gOutputParam; +uint8_t device_connected_flag; + static phLibNfc_Handle hLlcpHandle; static NFCSTATUS lastErrorStatus = NFCSTATUS_FAILED; static phLibNfc_Llcp_eLinkStatus_t g_eLinkStatus = phFriNfc_LlcpMac_eLinkDefault; @@ -371,6 +373,9 @@ static int nfc_jni_initialize(struct nfc_jni_native_data *nat) { goto clean_and_return; } + /* Reset device connected handle */ + device_connected_flag = 0; + /* Reset stored handle */ storedHandle = 0; @@ -662,6 +667,9 @@ void nfc_jni_restart_discovery_locked(struct nfc_jni_native_data *nat) /* Reset the PN544 ISO XCHG / sw watchdog timeouts */ nfc_jni_reset_timeout_values(); + /* Reset device connected flag */ + device_connected_flag = 0; + /* Restart Polling loop */ TRACE("****** Start NFC Discovery ******"); REENTRANCE_LOCK(); @@ -846,12 +854,15 @@ static void nfc_jni_llcp_linkStatus_callback(void *pContext, sLinkParams.miu, sLinkParams.option, sLinkParams.wks); + device_connected_flag = 1; } } else if(eLinkStatus == phFriNfc_LlcpMac_eLinkDeactivated) { LOGI("LLCP Link deactivated"); free(pContextData); + /* Reset device connected flag */ + device_connected_flag = 0; /* Reset incoming socket list */ while (!LIST_EMPTY(&pMonitor->incoming_socket_head)) @@ -989,7 +1000,10 @@ static void nfc_jni_Discovery_notification_callback(void *pContext, { LOG_CALLBACK("nfc_jni_Discovery_notification_callback", status); TRACE("Discovered %d tags", uNofRemoteDev); - + + /* Reset device connected flag */ + device_connected_flag = 1; + if((psRemoteDevList->psRemoteDevInfo->RemDevType == phNfc_eNfcIP1_Initiator) || (psRemoteDevList->psRemoteDevInfo->RemDevType == phNfc_eNfcIP1_Target)) { @@ -1413,6 +1427,9 @@ static void nfc_jni_start_discovery_locked(struct nfc_jni_native_data *nat) /* Reset the PN544 ISO XCHG / sw watchdog timeouts */ nfc_jni_reset_timeout_values(); + /* Reset device connected flag */ + device_connected_flag = 0; + #if 0 nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE; nat->discovery_cfg.PollDevInfo.PollCfgInfo.EnableIso14443B = TRUE; @@ -1760,7 +1777,7 @@ static jboolean com_android_nfc_NfcManager_deinitialize(JNIEnv *e, jobject o) struct nfc_jni_callback_data cb_data; /* Retrieve native structure address */ - nat = nfc_jni_get_nat(e, o); + nat = nfc_jni_get_nat(e, o); /* Clear previous configuration */ memset(&nat->discovery_cfg, 0, sizeof(phLibNfc_sADD_Cfg_t)); diff --git a/jni/com_android_nfc_NativeNfcSecureElement.cpp b/jni/com_android_nfc_NativeNfcSecureElement.cpp index f309122..f4a402b 100755 --- a/jni/com_android_nfc_NativeNfcSecureElement.cpp +++ b/jni/com_android_nfc_NativeNfcSecureElement.cpp @@ -24,6 +24,7 @@ static phNfc_sRemoteDevInformation_t* SecureElementInfo; static int secureElementHandle; extern void *gHWRef; static int SecureElementTech; +extern uint8_t device_connected_flag; namespace android { @@ -204,6 +205,13 @@ static jint com_android_nfc_NativeNfcSecureElement_doOpenSecureElementConnection TRACE("Open Secure Element"); + /* Check if NFC device is already connected to a tag or P2P peer */ + if (device_connected_flag == 1) + { + LOGD("Unable to open SE connection, device already connected to a P2P peer or a Tag"); + goto clean_and_return; + } + /* Test if External RF field is detected */ InParam.buffer = ExternalRFDetected; InParam.length = 3; @@ -215,6 +223,7 @@ static jint com_android_nfc_NativeNfcSecureElement_doOpenSecureElementConnection if(ret!=NFCSTATUS_PENDING) { LOGE("IOCTL status error"); + goto clean_and_return; } /* Wait for callback response */ diff --git a/jni/com_android_nfc_NativeNfcTag.cpp b/jni/com_android_nfc_NativeNfcTag.cpp index 566b28e..ade5307 100644 --- a/jni/com_android_nfc_NativeNfcTag.cpp +++ b/jni/com_android_nfc_NativeNfcTag.cpp @@ -25,7 +25,7 @@ static phLibNfc_Handle handle; uint8_t *nfc_jni_ndef_buf = NULL; uint32_t nfc_jni_ndef_buf_len = 0; - +extern uint8_t device_connected_flag; namespace android { @@ -639,9 +639,12 @@ static jboolean com_android_nfc_NativeNfcTag_doDisconnect(JNIEnv *e, jobject o) { goto clean_and_return; } + result = JNI_TRUE; clean_and_return: + /* Reset device connected flag */ + device_connected_flag = 0; nfc_cb_data_deinit(&cb_data); CONCURRENCY_UNLOCK(); return result; @@ -1051,6 +1054,7 @@ static jboolean com_android_nfc_NativeNfcTag_doPresenceCheck(JNIEnv *e, jobject clean_and_return: nfc_cb_data_deinit(&cb_data); + CONCURRENCY_UNLOCK(); return result; diff --git a/jni/com_android_nfc_NativeP2pDevice.cpp b/jni/com_android_nfc_NativeP2pDevice.cpp index fd9af3e..ed85620 100644 --- a/jni/com_android_nfc_NativeP2pDevice.cpp +++ b/jni/com_android_nfc_NativeP2pDevice.cpp @@ -20,6 +20,8 @@ #include "com_android_nfc.h" +extern uint8_t device_connected_flag; + namespace android { extern void nfc_jni_restart_discovery_locked(struct nfc_jni_native_data *nat); @@ -252,9 +254,12 @@ static jboolean com_android_nfc_NativeP2pDevice_doDisconnect(JNIEnv *e, jobject { goto clean_and_return; } + result = JNI_TRUE; clean_and_return: + /* Reset device connected flag */ + device_connected_flag = 0; nfc_cb_data_deinit(&cb_data); CONCURRENCY_UNLOCK(); return result; |