summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Chaisson <pchaisson@broadcom.com>2012-10-02 12:55:52 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-02 12:55:52 -0700
commitef953e21ec44e2512ae2cae082d98cf8d492ef2a (patch)
tree433f67a38989e576f123a7a937f94b4d3bb647a6
parenta3bf4c351001569dccfba5ab4ed019b2ec03ca9b (diff)
parente897cc402e50a06ccd08b03c8942a2f17e46daef (diff)
downloadpackages_apps_nfc-ef953e21ec44e2512ae2cae082d98cf8d492ef2a.zip
packages_apps_nfc-ef953e21ec44e2512ae2cae082d98cf8d492ef2a.tar.gz
packages_apps_nfc-ef953e21ec44e2512ae2cae082d98cf8d492ef2a.tar.bz2
am e897cc40: Substitute empty select for configurable AID.
* commit 'e897cc402e50a06ccd08b03c8942a2f17e46daef': Substitute empty select for configurable AID.
-rwxr-xr-xnci/jni/SecureElement.cpp46
-rwxr-xr-xnci/jni/SecureElement.h2
2 files changed, 47 insertions, 1 deletions
diff --git a/nci/jni/SecureElement.cpp b/nci/jni/SecureElement.cpp
index 5f370cc..2522e35 100755
--- a/nci/jni/SecureElement.cpp
+++ b/nci/jni/SecureElement.cpp
@@ -82,6 +82,7 @@ SecureElement::SecureElement ()
memset (&mUiccInfo, 0, sizeof(mUiccInfo));
memset (&mHciCfg, 0, sizeof(mHciCfg));
memset (mResponseData, 0, sizeof(mResponseData));
+ memset (mAidForEmptySelect, 0, sizeof(mAidForEmptySelect));
}
@@ -178,6 +179,7 @@ bool SecureElement::initialize (nfc_jni_native_data* native)
memset (&mUiccInfo, 0, sizeof(mUiccInfo));
memset (&mHciCfg, 0, sizeof(mHciCfg));
mUsedAids.clear ();
+ memset(mAidForEmptySelect, 0, sizeof(mAidForEmptySelect));
// Get Fresh EE info.
if (! getEeInfo())
@@ -219,6 +221,8 @@ bool SecureElement::initialize (nfc_jni_native_data* native)
mRouteDataSet.import (); //read XML file
HostAidRouter::getInstance().initialize ();
+ GetStrValue(NAME_AID_FOR_EMPTY_SELECT, (char*)&mAidForEmptySelect[0], sizeof(mAidForEmptySelect));
+
mIsInit = true;
ALOGD ("%s: exit", fn);
return (true);
@@ -847,9 +851,51 @@ bool SecureElement::transceive (UINT8* xmitBuffer, INT32 xmitBufferSize, UINT8*
tNFA_STATUS nfaStat = NFA_STATUS_FAILED;
bool isSuccess = false;
bool waitOk = false;
+ UINT8 newSelectCmd[NCI_MAX_AID_LEN + 10];
ALOGD ("%s: enter; xmitBufferSize=%ld; recvBufferMaxSize=%ld; timeout=%ld", fn, xmitBufferSize, recvBufferMaxSize, timeoutMillisec);
+ // Check if we need to replace an "empty" SELECT command.
+ // 1. Has there been a AID configured, and
+ // 2. Is that AID a valid length (i.e 16 bytes max), and
+ // 3. Is the APDU at least 4 bytes (for header), and
+ // 4. Is INS == 0xA4 (SELECT command), and
+ // 5. Is P1 == 0x04 (SELECT by AID), and
+ // 6. Is the APDU len 4 or 5 bytes.
+ //
+ // Note, the length of the configured AID is in the first
+ // byte, and AID starts from the 2nd byte.
+ if (mAidForEmptySelect[0] // 1
+ && (mAidForEmptySelect[0] <= NCI_MAX_AID_LEN) // 2
+ && (xmitBufferSize >= 4) // 3
+ && (xmitBuffer[1] == 0xA4) // 4
+ && (xmitBuffer[2] == 0x04) // 5
+ && (xmitBufferSize <= 5)) // 6
+ {
+ UINT8 idx = 0;
+
+ // Copy APDU command header from the input buffer.
+ memcpy(&newSelectCmd[0], &xmitBuffer[0], 4);
+ idx = 4;
+
+ // Set the Lc value to length of the new AID
+ newSelectCmd[idx++] = mAidForEmptySelect[0];
+
+ // Copy the AID
+ memcpy(&newSelectCmd[idx], &mAidForEmptySelect[1], mAidForEmptySelect[0]);
+ idx += mAidForEmptySelect[0];
+
+ // If there is an Le (5th byte of APDU), add it to the end.
+ if (xmitBufferSize == 5)
+ newSelectCmd[idx++] = xmitBuffer[4];
+
+ // Point to the new APDU
+ xmitBuffer = &newSelectCmd[0];
+ xmitBufferSize = idx;
+
+ ALOGD ("%s: Empty AID SELECT cmd detected, substituting AID from config file, new length=%d", fn, idx);
+ }
+
{
SyncEventGuard guard (mTransceiveEvent);
mActualResponseSize = 0;
diff --git a/nci/jni/SecureElement.h b/nci/jni/SecureElement.h
index 6a5cebd..8339a29 100755
--- a/nci/jni/SecureElement.h
+++ b/nci/jni/SecureElement.h
@@ -396,7 +396,7 @@ private:
UINT8 mResponseData [MAX_RESPONSE_SIZE];
RouteDataSet mRouteDataSet; //routing data
std::vector<std::string> mUsedAids; //AID's that are used in current routes
-
+ UINT8 mAidForEmptySelect[NCI_MAX_AID_LEN+1];
/*******************************************************************************
**