summaryrefslogtreecommitdiffstats
path: root/nxp/jni/com_android_nfc_NativeNfcTag.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'nxp/jni/com_android_nfc_NativeNfcTag.cpp')
-rwxr-xr-x[-rw-r--r--]nxp/jni/com_android_nfc_NativeNfcTag.cpp610
1 files changed, 378 insertions, 232 deletions
diff --git a/nxp/jni/com_android_nfc_NativeNfcTag.cpp b/nxp/jni/com_android_nfc_NativeNfcTag.cpp
index a621d2a..94e56c2 100644..100755
--- a/nxp/jni/com_android_nfc_NativeNfcTag.cpp
+++ b/nxp/jni/com_android_nfc_NativeNfcTag.cpp
@@ -452,15 +452,35 @@ static jint com_android_nfc_NativeNfcTag_doConnect(JNIEnv *e,
jint status;
struct nfc_jni_callback_data cb_data;
phLibNfc_sRemoteDevInformation_t* pRemDevInfo = NULL;
-
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, &pRemDevInfo))
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- status = NFCSTATUS_NOT_ENOUGH_MEMORY;
- goto clean_and_return;
- }
+ if(pRemDevInfoPCD->SessionOpened==TRUE)
+ {
+ storedHandle = handle;
+ pRemDevInfo = pRemDevInfoPCD;
+ // Success, set poll & act bytes
+ set_target_pollBytes(e, o, pRemDevInfo);
+ set_target_activationBytes(e, o, pRemDevInfo);
+ status = NFCSTATUS_SUCCESS;
+ }
+ else
+ {
+ status = NFCSTATUS_FAILED;
+ }
+ }
+ else
+ {
+ CONCURRENCY_LOCK();
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, &pRemDevInfo))
+ {
+ status = NFCSTATUS_NOT_ENOUGH_MEMORY;
+ goto clean_and_return;
+ }
TRACE("phLibNfc_RemoteDev_Connect(RW)");
REENTRANCE_LOCK();
@@ -485,9 +505,10 @@ static jint com_android_nfc_NativeNfcTag_doConnect(JNIEnv *e,
status = cb_data.status;
TRACE("phLibNfc_RemoteDev_Connect() - Status code = %d", status);
- /* Connect Status */
- if(status != NFCSTATUS_SUCCESS)
- {
+ nfc_cb_data_deinit(&cb_data);
+ /* Connect Status */
+ if(status != NFCSTATUS_SUCCESS)
+ {
goto clean_and_return;
}
@@ -496,9 +517,11 @@ static jint com_android_nfc_NativeNfcTag_doConnect(JNIEnv *e,
set_target_activationBytes(e, o, pRemDevInfo);
clean_and_return:
- nfc_cb_data_deinit(&cb_data);
- CONCURRENCY_UNLOCK();
- return status;
+
+ CONCURRENCY_UNLOCK();
+ }
+
+ return status;
}
static jint com_android_nfc_NativeNfcTag_doHandleReconnect(JNIEnv *e,
@@ -509,46 +532,65 @@ static jint com_android_nfc_NativeNfcTag_doHandleReconnect(JNIEnv *e,
jint status;
struct nfc_jni_callback_data cb_data;
phLibNfc_sRemoteDevInformation_t* pRemDevInfo = NULL;
- CONCURRENCY_LOCK();
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, &pRemDevInfo))
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- status = NFCSTATUS_NOT_ENOUGH_MEMORY;
- goto clean_and_return;
+ if(pRemDevInfoPCD->SessionOpened==TRUE)
+ {
+ storedHandle = handle;
+ pRemDevInfo = pRemDevInfoPCD;
+ status = NFCSTATUS_SUCCESS;
+ }
+ else
+ status = NFCSTATUS_FAILED;
}
-
- TRACE("phLibNfc_RemoteDev_ReConnect(RW)");
- REENTRANCE_LOCK();
- storedHandle = handle;
- status = phLibNfc_RemoteDev_ReConnect(handle, nfc_jni_connect_callback,(void *)&cb_data);
- REENTRANCE_UNLOCK();
- if(status != NFCSTATUS_PENDING)
+ else
{
- ALOGE("phLibNfc_RemoteDev_ReConnect(RW) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
- goto clean_and_return;
- }
- TRACE("phLibNfc_RemoteDev_ReConnect(RW) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
+ CONCURRENCY_LOCK();
- /* Wait for callback response */
- if(sem_wait(&cb_data.sem))
- {
- ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
- status = NFCSTATUS_ABORTED;
- goto clean_and_return;
- }
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, &pRemDevInfo))
+ {
+ status = NFCSTATUS_NOT_ENOUGH_MEMORY;
+ goto clean_and_return;
+ }
+
+ TRACE("phLibNfc_RemoteDev_ReConnect(RW)");
+ REENTRANCE_LOCK();
+ storedHandle = handle;
+ status = phLibNfc_RemoteDev_ReConnect(handle, nfc_jni_connect_callback,(void *)&cb_data);
+ REENTRANCE_UNLOCK();
+ if(status != NFCSTATUS_PENDING)
+ {
+ ALOGE("phLibNfc_RemoteDev_ReConnect(RW) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
+ goto clean_and_return;
+ }
+ TRACE("phLibNfc_RemoteDev_ReConnect(RW) returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
+
+ /* Wait for callback response */
+ if(sem_wait(&cb_data.sem))
+ {
+ ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
+ status = NFCSTATUS_ABORTED;
+ goto clean_and_return;
+ }
- status = cb_data.status;
+ status = cb_data.status;
- /* Connect Status */
- if(status != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
+ /* Connect Status */
+ if(status != NFCSTATUS_SUCCESS)
+ {
+ goto clean_and_return;
+ }
clean_and_return:
- nfc_cb_data_deinit(&cb_data);
- CONCURRENCY_UNLOCK();
+ nfc_cb_data_deinit(&cb_data);
+ CONCURRENCY_UNLOCK();
+ }
return status;
}
@@ -587,6 +629,7 @@ static jboolean com_android_nfc_NativeNfcTag_doDisconnect(JNIEnv *e, jobject o)
CONCURRENCY_LOCK();
handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfo = (phLibNfc_sRemoteDevInformation_t *) storedHandle;
/* Create the local semaphore */
if (!nfc_cb_data_init(&cb_data, NULL))
@@ -601,49 +644,64 @@ static jboolean com_android_nfc_NativeNfcTag_doDisconnect(JNIEnv *e, jobject o)
/* Disconnect */
TRACE("Disconnecting from tag (%x)", handle);
-
- if (handle == -1) {
+
+ if(pRemDevInfo!=NULL &&
+ (pRemDevInfo->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfo->RemDevType == phNfc_eISO14443_B_PCD))
+ {
+ if(pRemDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer!=NULL &&
+ pRemDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length>0)
+ {
+ free(pRemDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer);
+ pRemDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer = NULL;
+ pRemDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length = 0;
+ }
+ phOsalNfc_FreeMemory(pRemDevInfo);
+ }
+ else if(handle==-1)
+ {
// Was never connected to any tag, exit
result = JNI_TRUE;
ALOGE("doDisconnect() - Target already disconnected");
nfc_jni_restart_discovery_locked(nfc_jni_get_nat_ext(e));
goto clean_and_return;
}
+ else
+ {
+ TRACE("phLibNfc_RemoteDev_Disconnect(%x)", handle);
+ REENTRANCE_LOCK();
+ status = phLibNfc_RemoteDev_Disconnect(handle, NFC_DISCOVERY_CONTINUE,
+ nfc_jni_disconnect_callback, (void *)&cb_data);
+ REENTRANCE_UNLOCK();
- TRACE("phLibNfc_RemoteDev_Disconnect(%x)", handle);
- REENTRANCE_LOCK();
- status = phLibNfc_RemoteDev_Disconnect(handle, NFC_DISCOVERY_CONTINUE,
- nfc_jni_disconnect_callback, (void *)&cb_data);
- REENTRANCE_UNLOCK();
-
- if(status == NFCSTATUS_TARGET_NOT_CONNECTED)
- {
- result = JNI_TRUE;
- TRACE("phLibNfc_RemoteDev_Disconnect() - Target already disconnected");
- goto clean_and_return;
- }
- if(status != NFCSTATUS_PENDING)
- {
- ALOGE("phLibNfc_RemoteDev_Disconnect(%x) returned 0x%04x[%s]", handle, status, nfc_jni_get_status_name(status));
- nfc_jni_restart_discovery_locked(nfc_jni_get_nat_ext(e));
- goto clean_and_return;
- }
- TRACE("phLibNfc_RemoteDev_Disconnect(%x) returned 0x%04x[%s]", handle, status, nfc_jni_get_status_name(status));
+ if(status == NFCSTATUS_TARGET_NOT_CONNECTED)
+ {
+ result = JNI_TRUE;
+ TRACE("phLibNfc_RemoteDev_Disconnect() - Target already disconnected");
+ goto clean_and_return;
+ }
+ if(status != NFCSTATUS_PENDING)
+ {
+ ALOGE("phLibNfc_RemoteDev_Disconnect(%x) returned 0x%04x[%s]", handle, status, nfc_jni_get_status_name(status));
+ nfc_jni_restart_discovery_locked(nfc_jni_get_nat_ext(e));
+ goto clean_and_return;
+ }
+ TRACE("phLibNfc_RemoteDev_Disconnect(%x) returned 0x%04x[%s]", handle, status, nfc_jni_get_status_name(status));
- /* Wait for callback response */
- if(sem_wait(&cb_data.sem))
- {
- ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
- goto clean_and_return;
- }
-
- /* Disconnect Status */
- if(cb_data.status != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
+ /* Wait for callback response */
+ if(sem_wait(&cb_data.sem))
+ {
+ ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
+ goto clean_and_return;
+ }
- result = JNI_TRUE;
+ /* Disconnect Status */
+ if(cb_data.status != NFCSTATUS_SUCCESS)
+ {
+ goto clean_and_return;
+ }
+ }
+ result = JNI_TRUE;
clean_and_return:
/* Reset device connected flag */
@@ -721,6 +779,7 @@ static jbyteArray com_android_nfc_NativeNfcTag_doTransceive(JNIEnv *e,
jbyteArray result = NULL;
int res;
phLibNfc_Handle handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* psRemoteDevInfo = (phLibNfc_sRemoteDevInformation_t *) handle;
NFCSTATUS status;
struct nfc_jni_callback_data cb_data;
int selectedTech = 0;
@@ -739,50 +798,56 @@ static jbyteArray com_android_nfc_NativeNfcTag_doTransceive(JNIEnv *e,
}
memset(&transceive_info, 0, sizeof(transceive_info));
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, NULL))
+ selectedTech = nfc_jni_get_connected_technology(e, o);
+ buf = (uint8_t *)e->GetByteArrayElements(data, NULL);
+ if((selectedTech == TARGET_TYPE_ISO14443_4A_PCD ||
+ selectedTech == TARGET_TYPE_ISO14443_4B_PCD) &&
+ psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer!=NULL &&
+ psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length>0
+ )
{
- goto clean_and_return;
+ if(psRemoteDevInfo->SessionOpened==TRUE)
+ {
+ result = e->NewByteArray(psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length);
+ if (result != NULL) {
+ e->SetByteArrayRegion(result, 0,
+ psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length,
+ (jbyte *)psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer);
+ free(psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer);
+ psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.buffer = NULL;
+ psRemoteDevInfo->RemoteDevInfo.Iso14443_4_PCD_Info.length = 0;
+ status = NFCSTATUS_SUCCESS;
+ }
+ else
+ status = NFCSTATUS_FAILED;
+ }
+ else
+ status = NFCSTATUS_FAILED;
}
+ else
+ {
- selectedTech = nfc_jni_get_connected_technology(e, o);
- selectedLibNfcType = nfc_jni_get_connected_technology_libnfc_type(e, o);
-
- buf = outbuf = (uint8_t *)e->GetByteArrayElements(data, NULL);
- buflen = outlen = (uint32_t)e->GetArrayLength(data);
-
- switch (selectedTech) {
- case TARGET_TYPE_FELICA:
- transceive_info.cmd.FelCmd = phNfc_eFelica_Raw;
- transceive_info.addr = 0;
- break;
- case TARGET_TYPE_MIFARE_CLASSIC:
- case TARGET_TYPE_MIFARE_UL:
- if (raw) {
- transceive_info.cmd.MfCmd = phHal_eMifareRaw;
- transceive_info.addr = 0;
- // Need to add in the crc here
- outbuf = (uint8_t*)malloc(buflen + 2);
- outlen += 2;
- memcpy(outbuf, buf, buflen);
- nfc_insert_crc_a(outbuf, buflen);
-
- checkResponseCrc = true;
- } else {
- offset = 2;
- transceive_info.cmd.MfCmd = (phNfc_eMifareCmdList_t)buf[0];
- transceive_info.addr = (uint8_t)buf[1];
- }
- break;
- case TARGET_TYPE_ISO14443_3A:
- // Check which libnfc type
- if (selectedLibNfcType == phNfc_eJewel_PICC) {
- // For the Jewel pipe, CRC is automatically computed
- transceive_info.cmd.JewelCmd = phNfc_eJewel_Raw;
+ CONCURRENCY_LOCK();
+
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, NULL))
+ {
+ goto clean_and_return;
+ }
+
+ outbuf = buf;
+
+ buflen = outlen = (uint32_t)e->GetArrayLength(data);
+
+ selectedLibNfcType = nfc_jni_get_connected_technology_libnfc_type(e, o);
+
+ switch (selectedTech) {
+ case TARGET_TYPE_FELICA:
+ transceive_info.cmd.FelCmd = phNfc_eFelica_Raw;
transceive_info.addr = 0;
- } else {
+ break;
+ case TARGET_TYPE_MIFARE_CLASSIC:
+ case TARGET_TYPE_MIFARE_UL:
if (raw) {
// Use Mifare Raw to implement a standard
// ISO14443-3A transceive, with CRC added
@@ -801,94 +866,129 @@ static jbyteArray com_android_nfc_NativeNfcTag_doTransceive(JNIEnv *e,
transceive_info.cmd.MfCmd = (phNfc_eMifareCmdList_t)buf[0];
transceive_info.addr = (uint8_t)buf[1];
}
+ break;
+ case TARGET_TYPE_ISO14443_3A:
+ // Check which libnfc type
+ if (selectedLibNfcType == phNfc_eJewel_PICC) {
+ // For the Jewel pipe, CRC is automatically computed
+ transceive_info.cmd.JewelCmd = phNfc_eJewel_Raw;
+ transceive_info.addr = 0;
+ } else {
+ if (raw) {
+ // Use Mifare Raw to implement a standard
+ // ISO14443-3A transceive, with CRC added
+ transceive_info.cmd.MfCmd = phHal_eMifareRaw;
+ transceive_info.addr = 0;
+ // Need to add in the crc here
+ outbuf = (uint8_t*)malloc(buflen + 2);
+ outlen += 2;
+ memcpy(outbuf, buf, buflen);
+ nfc_insert_crc_a(outbuf, buflen);
+
+ checkResponseCrc = true;
+ } else {
+ // Use the mifare pipe
+ offset = 2;
+ transceive_info.cmd.MfCmd = (phNfc_eMifareCmdList_t)buf[0];
+ transceive_info.addr = (uint8_t)buf[1];
+ }
- }
- break;
- case TARGET_TYPE_ISO14443_4:
- transceive_info.cmd.Iso144434Cmd = phNfc_eIso14443_4_Raw;
- transceive_info.addr = 0;
- break;
- case TARGET_TYPE_ISO15693:
- transceive_info.cmd.Iso15693Cmd = phNfc_eIso15693_Cmd;
- transceive_info.addr = 0;
- break;
- case TARGET_TYPE_UNKNOWN:
- case TARGET_TYPE_ISO14443_3B:
- // Not supported
- goto clean_and_return;
- default:
- break;
- }
+ }
+ break;
+ case TARGET_TYPE_ISO14443_4A_PCD:
+ case TARGET_TYPE_ISO14443_4B_PCD:
+ case TARGET_TYPE_ISO14443_4:
+ transceive_info.cmd.Iso144434Cmd = phNfc_eIso14443_4_Raw;
+ transceive_info.addr = 0;
+ break;
+ case TARGET_TYPE_ISO15693:
+ transceive_info.cmd.Iso15693Cmd = phNfc_eIso15693_Cmd;
+ transceive_info.addr = 0;
+ break;
+ case TARGET_TYPE_UNKNOWN:
+ case TARGET_TYPE_ISO14443_3B:
+ // Not supported
+ goto clean_and_return;
+ default:
+ break;
+ }
- transceive_info.sSendData.buffer = outbuf + offset;
- transceive_info.sSendData.length = outlen - offset;
- transceive_info.sRecvData.buffer = (uint8_t*)malloc(1024);
- transceive_info.sRecvData.length = 1024;
- if(transceive_info.sRecvData.buffer == NULL)
- {
- goto clean_and_return;
- }
+ transceive_info.sSendData.buffer = outbuf + offset;
+ transceive_info.sSendData.length = outlen - offset;
+ transceive_info.sRecvData.buffer = (uint8_t*)malloc(1024);
+ transceive_info.sRecvData.length = 1024;
+ if(transceive_info.sRecvData.buffer == NULL)
+ {
+ goto clean_and_return;
+ }
- TRACE("phLibNfc_RemoteDev_Transceive()");
- REENTRANCE_LOCK();
- status = phLibNfc_RemoteDev_Transceive(handle, &transceive_info,
- nfc_jni_transceive_callback, (void *)&cb_data);
- REENTRANCE_UNLOCK();
- if(status != NFCSTATUS_PENDING)
- {
- ALOGE("phLibNfc_RemoteDev_Transceive() returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
- if ((targetLost != NULL) && (status == NFCSTATUS_TARGET_LOST)) {
- *targetLost = 1;
- }
- goto clean_and_return;
- }
- TRACE("phLibNfc_RemoteDev_Transceive() returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
+ TRACE("phLibNfc_RemoteDev_Transceive()");
+ REENTRANCE_LOCK();
+ status = phLibNfc_RemoteDev_Transceive(handle, &transceive_info,
+ nfc_jni_transceive_callback, (void *)&cb_data);
+ REENTRANCE_UNLOCK();
+ if(status != NFCSTATUS_PENDING)
+ {
+ ALOGE("phLibNfc_RemoteDev_Transceive() returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
+ if ((targetLost != NULL) &&
+ (status == NFCSTATUS_TARGET_LOST || selectedTech == TARGET_TYPE_ISO14443_4A_PCD || selectedTech == TARGET_TYPE_ISO14443_4B_PCD)
+ ) {
+ *targetLost = 1;
+ }
+ goto clean_and_return;
+ }
+ TRACE("phLibNfc_RemoteDev_Transceive() returned 0x%04x[%s]", status, nfc_jni_get_status_name(status));
- /* Wait for callback response */
- if(sem_wait(&cb_data.sem))
- {
- ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
- goto clean_and_return;
- }
+ /* Wait for callback response */
+ if(sem_wait(&cb_data.sem))
+ {
+ ALOGE("Failed to wait for semaphore (errno=0x%08x)", errno);
+ goto clean_and_return;
+ }
- if(cb_data.status != NFCSTATUS_SUCCESS)
- {
- if ((targetLost != NULL) && (cb_data.status == NFCSTATUS_TARGET_LOST)) {
- *targetLost = 1;
+ if(cb_data.status != NFCSTATUS_SUCCESS)
+ {
+ if ((targetLost != NULL) && (cb_data.status == NFCSTATUS_TARGET_LOST)) {
+ *targetLost = 1;
+ }
+ goto clean_and_return;
}
- goto clean_and_return;
- }
- /* Copy results back to Java *
- * In case of NfcA and raw, also check the CRC in the response
- * and cut it off in the returned data.
- */
- if ((nfc_jni_transceive_buffer->length > 2) && checkResponseCrc) {
- if (crc_valid(nfc_jni_transceive_buffer->buffer, nfc_jni_transceive_buffer->length)) {
- result = e->NewByteArray(nfc_jni_transceive_buffer->length - 2);
+ /* Copy results back to Java *
+ * In case of NfcA and raw, also check the CRC in the response
+ * and cut it off in the returned data.
+ */
+ if ((nfc_jni_transceive_buffer->length > 2) && checkResponseCrc) {
+ if (crc_valid(nfc_jni_transceive_buffer->buffer, nfc_jni_transceive_buffer->length)) {
+ result = e->NewByteArray(nfc_jni_transceive_buffer->length - 2);
+ if (result != NULL) {
+ e->SetByteArrayRegion(result, 0,
+ nfc_jni_transceive_buffer->length - 2,
+ (jbyte *)nfc_jni_transceive_buffer->buffer);
+ }
+ }
+ } else {
+ result = e->NewByteArray(nfc_jni_transceive_buffer->length);
if (result != NULL) {
e->SetByteArrayRegion(result, 0,
- nfc_jni_transceive_buffer->length - 2,
+ nfc_jni_transceive_buffer->length,
(jbyte *)nfc_jni_transceive_buffer->buffer);
}
}
- } else {
- result = e->NewByteArray(nfc_jni_transceive_buffer->length);
- if (result != NULL) {
- e->SetByteArrayRegion(result, 0,
- nfc_jni_transceive_buffer->length,
- (jbyte *)nfc_jni_transceive_buffer->buffer);
- }
- }
clean_and_return:
- if(transceive_info.sRecvData.buffer != NULL)
- {
- free(transceive_info.sRecvData.buffer);
- }
+ nfc_cb_data_deinit(&cb_data);
+
+ CONCURRENCY_UNLOCK();
+
+ if(transceive_info.sRecvData.buffer != NULL)
+ {
+ free(transceive_info.sRecvData.buffer);
+ }
- if ((outbuf != buf) && (outbuf != NULL)) {
- // Buf was extended and re-alloced with crc bytes, free separately
- free(outbuf);
+ if ((outbuf != buf) && (outbuf != NULL)) {
+ // Buf was extended and re-alloced with crc bytes, free separately
+ free(outbuf);
+ }
}
e->ReleaseByteArrayElements(data,
@@ -898,10 +998,6 @@ clean_and_return:
e->ReleaseIntArrayElements(statusTargetLost, targetLost, 0);
}
- nfc_cb_data_deinit(&cb_data);
-
- CONCURRENCY_UNLOCK();
-
return result;
}
@@ -951,18 +1047,27 @@ static jint com_android_nfc_NativeNfcTag_doCheckNdef(JNIEnv *e, jobject o, jintA
struct nfc_jni_callback_data cb_data;
jint *ndef = e->GetIntArrayElements(ndefinfo, 0);
int apiCardState = NDEF_MODE_UNKNOWN;
+ handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, NULL))
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- status = NFCSTATUS_NOT_ENOUGH_MEMORY;
- goto clean_and_return;
+ status = NFCSTATUS_FAILED;
}
- cb_data.pContext = &sNdefInfo;
+ else
+ {
+ CONCURRENCY_LOCK();
- handle = nfc_jni_get_connected_handle(e, o);
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, NULL))
+ {
+ status = NFCSTATUS_NOT_ENOUGH_MEMORY;
+ goto clean_and_return;
+ }
+ cb_data.pContext = &sNdefInfo;
TRACE("phLibNfc_Ndef_CheckNdef()");
REENTRANCE_LOCK();
@@ -1010,9 +1115,11 @@ static jint com_android_nfc_NativeNfcTag_doCheckNdef(JNIEnv *e, jobject o, jintA
ndef[1] = apiCardState;
clean_and_return:
+ nfc_cb_data_deinit(&cb_data);
+ CONCURRENCY_UNLOCK();
+ }
+
e->ReleaseIntArrayElements(ndefinfo, ndef, 0);
- nfc_cb_data_deinit(&cb_data);
- CONCURRENCY_UNLOCK();
return status;
}
@@ -1022,16 +1129,32 @@ static jboolean com_android_nfc_NativeNfcTag_doPresenceCheck(JNIEnv *e, jobject
NFCSTATUS status;
jboolean result = JNI_FALSE;
struct nfc_jni_callback_data cb_data;
+ handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, NULL))
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- goto clean_and_return;
+ if(pRemDevInfoPCD->SessionOpened==TRUE)
+ {
+ result = JNI_TRUE;
+ }
+ else
+ {
+ result = JNI_FALSE;
+ }
}
+ else
+ {
+ CONCURRENCY_LOCK();
- handle = nfc_jni_get_connected_handle(e, o);
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, NULL))
+ {
+ goto clean_and_return;
+ }
TRACE("phLibNfc_RemoteDev_CheckPresence()");
REENTRANCE_LOCK();
@@ -1060,7 +1183,8 @@ static jboolean com_android_nfc_NativeNfcTag_doPresenceCheck(JNIEnv *e, jobject
clean_and_return:
nfc_cb_data_deinit(&cb_data);
- CONCURRENCY_UNLOCK();
+ CONCURRENCY_UNLOCK();
+ }
return result;
}
@@ -1118,16 +1242,25 @@ static jboolean com_android_nfc_NativeNfcTag_doNdefFormat(JNIEnv *e, jobject o,
phNfc_sData_t keyBuffer;
jboolean result = JNI_FALSE;
struct nfc_jni_callback_data cb_data;
+ handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, NULL))
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- goto clean_and_return;
+ result = JNI_FALSE;
}
+ else
+ {
+ CONCURRENCY_LOCK();
- handle = nfc_jni_get_connected_handle(e, o);
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, NULL))
+ {
+ goto clean_and_return;
+ }
keyBuffer.buffer = (uint8_t *)e->GetByteArrayElements(key, NULL);
keyBuffer.length = e->GetArrayLength(key);
@@ -1150,15 +1283,16 @@ static jboolean com_android_nfc_NativeNfcTag_doNdefFormat(JNIEnv *e, jobject o,
goto clean_and_return;
}
- if (cb_data.status == NFCSTATUS_SUCCESS)
- {
- result = JNI_TRUE;
+ if (cb_data.status == NFCSTATUS_SUCCESS)
+ {
+ result = JNI_TRUE;
+ }
+clean_and_return:
+ nfc_cb_data_deinit(&cb_data);
+ CONCURRENCY_UNLOCK();
}
-clean_and_return:
e->ReleaseByteArrayElements(key, (jbyte *)keyBuffer.buffer, JNI_ABORT);
- nfc_cb_data_deinit(&cb_data);
- CONCURRENCY_UNLOCK();
return result;
}
@@ -1169,16 +1303,26 @@ static jboolean com_android_nfc_NativeNfcTag_doMakeReadonly(JNIEnv *e, jobject o
jboolean result = JNI_FALSE;
struct nfc_jni_callback_data cb_data;
phNfc_sData_t keyBuffer;
+ handle = nfc_jni_get_connected_handle(e, o);
+ phLibNfc_sRemoteDevInformation_t* pRemDevInfoPCD = (phLibNfc_sRemoteDevInformation_t *) handle;
- CONCURRENCY_LOCK();
-
- /* Create the local semaphore */
- if (!nfc_cb_data_init(&cb_data, NULL))
+ if(pRemDevInfoPCD!=NULL &&
+ (pRemDevInfoPCD->RemDevType == phNfc_eISO14443_A_PCD ||
+ pRemDevInfoPCD->RemDevType == phNfc_eISO14443_B_PCD)
+ )
{
- goto clean_and_return;
+ result = JNI_FALSE;
}
+ else
+ {
+ CONCURRENCY_LOCK();
+
+ /* Create the local semaphore */
+ if (!nfc_cb_data_init(&cb_data, NULL))
+ {
+ goto clean_and_return;
+ }
- handle = nfc_jni_get_connected_handle(e, o);
keyBuffer.buffer = (uint8_t *)e->GetByteArrayElements(key, NULL);
keyBuffer.length = e->GetArrayLength(key);
TRACE("phLibNfc_ConvertToReadOnlyNdef()");
@@ -1210,6 +1354,8 @@ clean_and_return:
e->ReleaseByteArrayElements(key, (jbyte *)keyBuffer.buffer, JNI_ABORT);
nfc_cb_data_deinit(&cb_data);
CONCURRENCY_UNLOCK();
+ }
+
return result;
}
/*