diff options
author | Martijn Coenen <maco@google.com> | 2011-08-19 14:11:24 +0200 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2011-08-26 10:53:49 -0700 |
commit | bf6e5d1655d5ad524a8ec007413c7011ed969df8 (patch) | |
tree | dd430bd3bc1ab6a29611772b61d987bf3078278c | |
parent | a8c503840d56eb615d65f2e707bd2decad0015b9 (diff) | |
download | packages_apps_nfc-bf6e5d1655d5ad524a8ec007413c7011ed969df8.zip packages_apps_nfc-bf6e5d1655d5ad524a8ec007413c7011ed969df8.tar.gz packages_apps_nfc-bf6e5d1655d5ad524a8ec007413c7011ed969df8.tar.bz2 |
Support for getMaxTransceiveLength() API.
Maximum transceive length is enforced in calls to transceive.
Change-Id: I94a4f16283e5fd5df9143b02e52c16f868b1c3ab
-rw-r--r-- | src/com/android/nfc/DeviceHost.java | 7 | ||||
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 32 | ||||
-rwxr-xr-x | src/com/android/nfc/nxp/NativeNfcManager.java | 34 | ||||
-rwxr-xr-x | src/com/android/nfc/nxp/NativeNfcTag.java | 3 |
4 files changed, 70 insertions, 6 deletions
diff --git a/src/com/android/nfc/DeviceHost.java b/src/com/android/nfc/DeviceHost.java index d8192b7..70a6011 100644 --- a/src/com/android/nfc/DeviceHost.java +++ b/src/com/android/nfc/DeviceHost.java @@ -80,6 +80,8 @@ public interface DeviceHost { boolean formatNdef(byte[] key); boolean isNdefFormatable(); boolean makeReadOnly(); + + int getConnectedTechnology(); } public interface NfceeEndpoint { @@ -179,4 +181,9 @@ public interface DeviceHost { public int getTimeout(int technology); public void doAbort(); + + boolean canMakeReadOnly(int technology); + + int getMaxTransceiveLength(int technology); + } diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 705a82a..1568b27 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -890,13 +890,21 @@ public class NfcService extends Application implements DeviceHostListener { /* find the tag in the hmap */ tag = (TagEndpoint) findObject(nativeHandle); if (tag != null) { + // Check if length is within limits + if (data.length > getMaxTransceiveLength(tag.getConnectedTechnology())) { + return new TransceiveResult(TransceiveResult.RESULT_EXCEEDED_LENGTH, null); + } int[] targetLost = new int[1]; response = tag.transceive(data, raw, targetLost); - TransceiveResult transResult = new TransceiveResult( - (response != null) ? true : false, - (targetLost[0] == 1) ? true : false, - response); - return transResult; + int result; + if (response != null) { + result = TransceiveResult.RESULT_SUCCESS; + } else if (targetLost[0] == 1) { + result = TransceiveResult.RESULT_TAGLOST; + } else { + result = TransceiveResult.RESULT_FAILURE; + } + return new TransceiveResult(result, response); } return null; } @@ -1070,6 +1078,20 @@ public class NfcService extends Application implements DeviceHostListener { mDeviceHost.resetTimeouts(); } + + @Override + public boolean canMakeReadOnly(int ndefType) throws RemoteException { + mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR); + + return mDeviceHost.canMakeReadOnly(ndefType); + } + + @Override + public int getMaxTransceiveLength(int tech) throws RemoteException { + mContext.enforceCallingOrSelfPermission(NFC_PERM, NFC_PERM_ERROR); + + return mDeviceHost.getMaxTransceiveLength(tech); + } }; private void _nfcEeClose(boolean checkPid, int callingPid) throws IOException { diff --git a/src/com/android/nfc/nxp/NativeNfcManager.java b/src/com/android/nfc/nxp/NativeNfcManager.java index bce9fa9..90236ad 100755 --- a/src/com/android/nfc/nxp/NativeNfcManager.java +++ b/src/com/android/nfc/nxp/NativeNfcManager.java @@ -23,6 +23,8 @@ import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.nfc.ErrorCodes; +import android.nfc.tech.Ndef; +import android.nfc.tech.TagTechnology; import android.util.Log; /** @@ -151,6 +153,38 @@ public class NativeNfcManager implements DeviceHost { return doGetTimeout(tech); } + + @Override + public boolean canMakeReadOnly(int ndefType) { + return (ndefType == Ndef.TYPE_1 || ndefType == Ndef.TYPE_2); + } + + @Override + public int getMaxTransceiveLength(int technology) { + switch (technology) { + case (TagTechnology.NFC_A): + case (TagTechnology.MIFARE_CLASSIC): + case (TagTechnology.MIFARE_ULTRALIGHT): + return 253; // PN544 RF buffer = 255 bytes, subtract two for CRC + case (TagTechnology.NFC_B): + return 0; // PN544 does not support transceive of raw NfcB + case (TagTechnology.NFC_V): + return 253; // PN544 RF buffer = 255 bytes, subtract two for CRC + case (TagTechnology.ISO_DEP): + /* The maximum length of a normal IsoDep frame consists of: + * CLA, INS, P1, P2, LC, LE + 255 payload bytes = 261 bytes + * such a frame is supported. Extended length frames however + * are not supported. + */ + return 261; // Will be automatically split in two frames on the RF layer + case (TagTechnology.NFC_F): + return 252; // PN544 RF buffer = 255 bytes, subtract one for SoD, two for CRC + default: + return 0; + } + + } + /** * Notifies Ndef Message (TODO: rename into notifyTargetDiscovered) */ diff --git a/src/com/android/nfc/nxp/NativeNfcTag.java b/src/com/android/nfc/nxp/NativeNfcTag.java index f0e123e..dcbbf14 100755 --- a/src/com/android/nfc/nxp/NativeNfcTag.java +++ b/src/com/android/nfc/nxp/NativeNfcTag.java @@ -415,7 +415,8 @@ public class NativeNfcTag implements TagEndpoint { } } - private int getConnectedTechnology() { + @Override + public int getConnectedTechnology() { if (mConnectedTechIndex != -1 && mConnectedTechIndex < mTechList.length) { return mTechList[mConnectedTechIndex]; } else { |