summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nci/jni/IntervalTimer.cpp21
-rwxr-xr-xnci/jni/NativeNfcManager.cpp35
-rwxr-xr-xnci/jni/NativeNfcTag.cpp68
-rwxr-xr-xnci/jni/NfcTag.cpp55
-rwxr-xr-xnci/jni/NfcTag.h30
-rw-r--r--nci/jni/PeerToPeer.cpp34
-rwxr-xr-xnci/src/com/android/nfc/dhimpl/NativeNfcTag.java24
7 files changed, 254 insertions, 13 deletions
diff --git a/nci/jni/IntervalTimer.cpp b/nci/jni/IntervalTimer.cpp
index 9453451d..f3f94415 100644
--- a/nci/jni/IntervalTimer.cpp
+++ b/nci/jni/IntervalTimer.cpp
@@ -13,6 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
/*
* Asynchronous interval timer.
@@ -80,7 +99,7 @@ void IntervalTimer::kill()
bool IntervalTimer::create(TIMER_FUNC cb)
{
- struct sigevent se;
+ struct sigevent se = {0};
int stat = 0;
/*
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 0c7ba8bb..0c82e200 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -13,7 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
#include <semaphore.h>
#include <errno.h>
#include "OverrideLog.h"
@@ -100,6 +118,7 @@ namespace android
void doStartupConfig ();
void startStopPolling (bool isStartPolling);
void startRfDiscovery (bool isStart);
+ bool isDiscoveryStarted();
void setUiccIdleTimeout (bool enable);
void restartPollingWithTechMask(int mask);
}
@@ -2018,6 +2037,20 @@ void startRfDiscovery(bool isStart)
}
}
+/*******************************************************************************
+**
+** Function: isDiscoveryStarted
+**
+** Description: Ask if polling and listening has started on device.
+**
+** Returns: True - if started, False - if not.
+**
+*******************************************************************************/
+bool isDiscoveryStarted()
+{
+ return sRfEnabled;
+}
+
/*******************************************************************************
**
diff --git a/nci/jni/NativeNfcTag.cpp b/nci/jni/NativeNfcTag.cpp
index 2a1ea8ca..72ce65ec 100755
--- a/nci/jni/NativeNfcTag.cpp
+++ b/nci/jni/NativeNfcTag.cpp
@@ -13,6 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
#include <semaphore.h>
#include <errno.h>
@@ -75,7 +94,7 @@ namespace android
#define NDEF_TYPE4_TAG 4
#define NDEF_MIFARE_CLASSIC_TAG 101
-#define STATUS_CODE_TARGET_LOST 146 // this error code comes from the service
+#define STATUS_CODE_TARGET_LOST 146 // this error code comes from the service
static uint32_t sCheckNdefCurrentSize = 0;
static tNFA_STATUS sCheckNdefStatus = 0; //whether tag already contains a NDEF message
@@ -1344,8 +1363,8 @@ static jboolean nativeNfcTag_doPresenceCheck (JNIEnv*, jobject)
** Returns: True if formattable.
**
*******************************************************************************/
-static jboolean nativeNfcTag_doIsNdefFormatable (JNIEnv*,
- jobject, jint /*libNfcType*/, jbyteArray, jbyteArray,
+static jboolean nativeNfcTag_doIsNdefFormatable (JNIEnv* e,
+ jobject o, jint /*libNfcType*/, jbyteArray, jbyteArray,
jbyteArray)
{
jboolean isFormattable = JNI_FALSE;
@@ -1359,6 +1378,43 @@ static jboolean nativeNfcTag_doIsNdefFormatable (JNIEnv*,
case NFA_PROTOCOL_T2T:
isFormattable = NfcTag::getInstance().isMifareUltralight() ? JNI_TRUE : JNI_FALSE;
+ break;
+ case NFA_PROTOCOL_ISO_DEP:
+ /**
+ * Determines whether this is a formatable IsoDep tag - currectly only NXP DESFire
+ * is supported.
+ */
+ uint8_t cmd[] = {0x90, 0x60, 0x00, 0x00, 0x00};
+
+ if(NfcTag::getInstance().isMifareDESFire())
+ {
+ /* Identifies as DESfire, use get version cmd to be sure */
+ jbyteArray versionCmd = e->NewByteArray(5);
+ e->SetByteArrayRegion(versionCmd, 0, 5, (jbyte*)cmd);
+ jbyteArray respBytes = nativeNfcTag_doTransceive(e, o,
+ versionCmd, JNI_TRUE, NULL);
+ if (respBytes != NULL)
+ {
+ // Check whether the response matches a typical DESfire
+ // response.
+ // libNFC even does more advanced checking than we do
+ // here, and will only format DESfire's with a certain
+ // major/minor sw version and NXP as a manufacturer.
+ // We don't want to do such checking here, to avoid
+ // having to change code in multiple places.
+ // A succesful (wrapped) DESFire getVersion command returns
+ // 9 bytes, with byte 7 0x91 and byte 8 having status
+ // code 0xAF (these values are fixed and well-known).
+ int respLength = e->GetArrayLength(respBytes);
+ uint8_t* resp = (uint8_t*)e->GetByteArrayElements(respBytes, NULL);
+ if (respLength == 9 && resp[7] == 0x91 && resp[8] == 0xAF)
+ {
+ isFormattable = JNI_TRUE;
+ }
+ e->ReleaseByteArrayElements(respBytes, (jbyte *)resp, JNI_ABORT);
+ }
+ }
+ break;
}
ALOGD("%s: is formattable=%u", __FUNCTION__, isFormattable);
return isFormattable;
@@ -1400,7 +1456,7 @@ static jboolean nativeNfcTag_doIsIsoDepNdefFormatable (JNIEnv *e, jobject o, jby
** Returns: True if ok.
**
*******************************************************************************/
-static jboolean nativeNfcTag_doNdefFormat (JNIEnv*, jobject, jbyteArray)
+static jboolean nativeNfcTag_doNdefFormat (JNIEnv *e, jobject o, jbyteArray)
{
ALOGD ("%s: enter", __FUNCTION__);
tNFA_STATUS status = NFA_STATUS_OK;
@@ -1425,6 +1481,10 @@ static jboolean nativeNfcTag_doNdefFormat (JNIEnv*, jobject, jbyteArray)
ALOGE ("%s: error status=%u", __FUNCTION__, status);
sem_destroy (&sFormatSem);
+ if (NfcTag::getInstance ().mTechLibNfcTypes[0] == NFA_PROTOCOL_ISO_DEP)
+ {
+ nativeNfcTag_doReconnect (e, o);
+ }
ALOGD ("%s: exit", __FUNCTION__);
return (status == NFA_STATUS_OK) ? JNI_TRUE : JNI_FALSE;
}
diff --git a/nci/jni/NfcTag.cpp b/nci/jni/NfcTag.cpp
index 5db6df2e..b0fe9ab7 100755
--- a/nci/jni/NfcTag.cpp
+++ b/nci/jni/NfcTag.cpp
@@ -13,7 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
/*
* Tag-reading, tag-writing operations.
*/
@@ -1074,7 +1092,7 @@ void NfcTag::resetTechnologies ()
{
static const char fn [] = "NfcTag::resetTechnologies";
ALOGD ("%s", fn);
- mNumTechList = 0;
+ mNumTechList = 0;
memset (mTechList, 0, sizeof(mTechList));
memset (mTechHandles, 0, sizeof(mTechHandles));
memset (mTechLibNfcTypes, 0, sizeof(mTechLibNfcTypes));
@@ -1233,6 +1251,39 @@ bool NfcTag::isMifareUltralight ()
return retval;
}
+/*******************************************************************************
+**
+** Function: isMifareDESFire
+**
+** Description: Whether the currently activated tag is Mifare DESFire.
+**
+** Returns: True if tag is Mifare DESFire.
+**
+*******************************************************************************/
+bool NfcTag::isMifareDESFire ()
+{
+ static const char fn [] = "NfcTag::isMifareDESFire";
+ bool retval = false;
+
+ for (int i =0; i < mNumTechList; i++)
+ {
+ if ( (mTechParams[i].mode == NFC_DISCOVERY_TYPE_POLL_A) ||
+ (mTechParams[i].mode == NFC_DISCOVERY_TYPE_LISTEN_A) ||
+ (mTechParams[i].mode == NFC_DISCOVERY_TYPE_LISTEN_A_ACTIVE) )
+ {
+ /* DESfire has one sak byte and 2 ATQA bytes */
+ if ( (mTechParams[i].param.pa.sens_res[0] == 0x44) &&
+ (mTechParams[i].param.pa.sens_res[1] == 3) &&
+ (mTechParams[i].param.pa.sel_rsp == 0x20))
+ {
+ retval = true;
+ }
+ break;
+ }
+ }
+ ALOGD ("%s: return=%u", fn, retval);
+ return retval;
+}
/*******************************************************************************
**
diff --git a/nci/jni/NfcTag.h b/nci/jni/NfcTag.h
index 6fc87bad..de15bd1f 100755
--- a/nci/jni/NfcTag.h
+++ b/nci/jni/NfcTag.h
@@ -13,7 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
/*
* Tag-reading, tag-writing operations.
*/
@@ -219,6 +237,16 @@ public:
*******************************************************************************/
bool isMifareUltralight ();
+ /*******************************************************************************
+ **
+ ** Function: isMifareDESFire
+ **
+ ** Description: Whether the currently activated tag is Mifare Ultralight.
+ **
+ ** Returns: True if tag is Mifare Ultralight.
+ **
+ *******************************************************************************/
+ bool isMifareDESFire ();
/*******************************************************************************
**
diff --git a/nci/jni/PeerToPeer.cpp b/nci/jni/PeerToPeer.cpp
index bc66ebd5..bca989f9 100644
--- a/nci/jni/PeerToPeer.cpp
+++ b/nci/jni/PeerToPeer.cpp
@@ -13,6 +13,25 @@
* 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) 2013-2014 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 a peer using NFC-DEP, LLCP, SNEP.
@@ -40,6 +59,8 @@ namespace android
{
extern void nativeNfcTag_registerNdefTypeHandler ();
extern void nativeNfcTag_deregisterNdefTypeHandler ();
+ extern void startRfDiscovery(bool isStart);
+ extern bool isDiscoveryStarted();
}
@@ -472,6 +493,7 @@ bool PeerToPeer::deregisterServer (tJNI_HANDLE jniHandle)
ALOGD ("%s: enter; JNI handle: %u", fn, jniHandle);
tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
sp<P2pServer> pSrv = NULL;
+ bool rfEnabled = false;
mMutex.lock();
if ((pSrv = findServerLocked (jniHandle)) == NULL)
@@ -482,6 +504,13 @@ bool PeerToPeer::deregisterServer (tJNI_HANDLE jniHandle)
}
mMutex.unlock();
+ //Check if discovery has started
+ rfEnabled = android::isDiscoveryStarted();
+ if(rfEnabled)
+ {
+ android::startRfDiscovery(false);
+ }
+
{
// Server does not call NFA_P2pDisconnect(), so unblock the accept()
SyncEventGuard guard (pSrv->mConnRequestEvent);
@@ -496,6 +525,11 @@ bool PeerToPeer::deregisterServer (tJNI_HANDLE jniHandle)
removeServer (jniHandle);
+ if(rfEnabled)
+ {
+ android::startRfDiscovery(true);
+ }
+
ALOGD ("%s: exit", fn);
return true;
}
diff --git a/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java b/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
index 633392ff..92adecee 100755
--- a/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
+++ b/nci/src/com/android/nfc/dhimpl/NativeNfcTag.java
@@ -13,7 +13,25 @@
* 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) 2013-2014 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.
+ *
+ ******************************************************************************/
package com.android.nfc.dhimpl;
import com.android.nfc.DeviceHost.TagEndpoint;
@@ -175,7 +193,7 @@ public class NativeNfcTag implements TagEndpoint {
// special case for NDEF, this will cause switch to ISO_DEP frame intf
i = 0;
// status = 0;
- }
+ }
status = reconnectWithStatus(i);
/*
if ((technology != TagTechnology.ISO_DEP) &&
@@ -195,8 +213,6 @@ public class NativeNfcTag implements TagEndpoint {
status = 0;
}
*/
-
-
if (status == 0) {
mConnectedTechIndex = i;
// Handle was already identical