Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #88 from DimiL/bug_1043782
Browse files Browse the repository at this point in the history
Bug 1043782 - [NFC][Flame] Cannot detect correct tag type for Mifare-Cla...
  • Loading branch information
rvandermeulen committed Mar 12, 2015
2 parents 95faf8d + 9c5e860 commit 16836b5
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 44 deletions.
12 changes: 12 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ LOCAL_MODULE_TAGS := optional

LOCAL_CFLAGS := -DDEBUG -DPLATFORM_ANDROID -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DSILENT=1 -DNO_SIGNALS=1 -DNO_EXECUTE_PERMISSION=1 -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP -D_FILE_OFFSET_BITS=64 -DNO_UNALIGNED_ACCESS

ifeq ($(TARGET_DEVICE),flame)
LOCAL_CFLAGS += -DNFCC_PN547

LOCAL_C_INCLUDES += \
external/libnfc-pn547/inc \
external/libnfc-pn547/src/utils \
external/libnfc-pn547/src/common

LOCAL_SHARED_LIBRARIES += \
libnfc-pn547
endif

include $(BUILD_EXECUTABLE)

#endif #} TARGET_PROVIDES_NFCD
42 changes: 35 additions & 7 deletions src/nci/NfcManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@

extern "C"
{
#include "nfa_api.h"
#include "nfa_p2p_api.h"
#include "rw_api.h"
#include "nfa_ee_api.h"
#include "nfc_brcm_defs.h"
#include "ce_api.h"
#ifdef NFCC_PN547
#include "phNxpExtns.h"
#include "phNxpConfig.h"
#endif
}

#undef LOG_TAG
Expand Down Expand Up @@ -153,6 +156,9 @@ bool NfcManager::Initialize()
} else {
ALOGE("%s: NFA_Enable fail, error = 0x%X", __FUNCTION__, stat);
}
#ifdef NFCC_PN547
EXTNS_Init(NfaDeviceManagementCallback, NfaConnectionCallback);
#endif
}

if (stat == NFA_STATUS_OK) {
Expand Down Expand Up @@ -184,8 +190,9 @@ bool NfcManager::Initialize()
}
}

if (sIsNfaEnabled)
stat = NFA_Disable(FALSE /* ungraceful */);
if (sIsNfaEnabled) {
stat = Disable(FALSE /* ungraceful */);
}

theInstance.Finalize();

Expand All @@ -208,7 +215,7 @@ bool NfcManager::Deinitialize()
if (sIsNfaEnabled) {
SyncEventGuard guard(sNfaDisableEvent);

tNFA_STATUS stat = NFA_Disable(TRUE /* graceful */);
tNFA_STATUS stat = Disable(TRUE /* graceful */);
if (stat == NFA_STATUS_OK) {
ALOGD("%s: wait for completion", __FUNCTION__);
sNfaDisableEvent.Wait(); // Wait for NFA command to finish.
Expand Down Expand Up @@ -480,6 +487,14 @@ bool NfcManager::DoDeselectSecureElement()
return result;
}

tNFA_STATUS NfcManager::Disable(bool aGraceful)
{
#ifdef NFCC_PN547
EXTNS_Close();
#endif
return NFA_Disable(aGraceful);
}

/**
* Private functions.
*/
Expand Down Expand Up @@ -591,7 +606,7 @@ void NfaDeviceManagementCallback(UINT8 dmEvent, tNFA_DM_CBACK_DATA* eventData)
PowerSwitch::GetInstance().Abort();

if (!sIsDisabling && sIsNfaEnabled) {
NFA_Disable(FALSE);
NfcManager::Disable(false);
sIsDisabling = true;
} else {
sIsNfaEnabled = false;
Expand Down Expand Up @@ -663,8 +678,17 @@ static void NfaConnectionCallback(UINT8 connEvent, tNFA_CONN_EVT_DATA* eventData
// NFC link/protocol activated.
case NFA_ACTIVATED_EVT:
ALOGD("%s: NFA_ACTIVATED_EVT: gIsSelectingRfInterface=%d, sIsDisabling=%d", __FUNCTION__, gIsSelectingRfInterface, sIsDisabling);
if (sIsDisabling || !sIsNfaEnabled)
if (sIsDisabling || !sIsNfaEnabled) {
break;
}

#ifdef NFCC_PN547
if (EXTNS_GetConnectFlag()) {
NfcTag::GetInstance().SetActivationState();
NfcTagManager::DoConnectStatus(true);
break;
}
#endif

NfcTag::GetInstance().SetActivationState();
if (gIsSelectingRfInterface) {
Expand Down Expand Up @@ -708,6 +732,10 @@ static void NfaConnectionCallback(UINT8 connEvent, tNFA_CONN_EVT_DATA* eventData
NfcTag::GetInstance().Abort();
} else if (gIsTagDeactivating) {
NfcTagManager::DoDeactivateStatus(0);
#ifdef NFCC_PN547
} else if (EXTNS_GetDeactivateFlag()) {
NfcTagManager::DoDeactivateStatus(0);
#endif
}

// If RF is activated for what we think is a Secure Element transaction
Expand Down Expand Up @@ -816,7 +844,7 @@ static void NfaConnectionCallback(UINT8 connEvent, tNFA_CONN_EVT_DATA* eventData

case NFA_FORMAT_CPLT_EVT:
ALOGD("%s: NFA_FORMAT_CPLT_EVT: status=0x%X", __FUNCTION__, eventData->status);
NfcTagManager::FormatStatus(eventData->status == NFA_STATUS_OK);
NfcTagManager::DoFormatStatus(eventData->status == NFA_STATUS_OK);
break;

case NFA_CE_UICC_LISTEN_CONFIGURED_EVT :
Expand Down
10 changes: 10 additions & 0 deletions src/nci/NfcManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "DeviceHost.h"
#include "INfcManager.h"

extern "C"
{
#include "nfa_api.h"
}

class P2pDevice;
class NfcTagManager;
class ILlcpServerSocket;
Expand Down Expand Up @@ -174,6 +179,11 @@ class NfcManager
*/
bool DoDeselectSecureElement();

/**
* This function is called to shutdown NFC.
*/
static tNFA_STATUS Disable(bool aGraceful);

private:
P2pDevice* mP2pDevice;
NfcTagManager* mNfcTagManager;
Expand Down
38 changes: 38 additions & 0 deletions src/nci/NfcTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
extern "C"
{
#include "rw_int.h"
#ifdef NFCC_PN547
#include "phNxpExtns.h"
#endif
}

#undef LOG_TAG
Expand Down Expand Up @@ -237,6 +240,20 @@ void NfcTag::DiscoverTechnologies(tNFA_ACTIVATED& aActivationData)
mTechList[mNumTechList] = TECHNOLOGY_TYPE_KOVIO_BARCODE;
break;

#ifdef NFCC_PN547
case NFC_PROTOCOL_MIFARE:
ALOGD("%s: Mifare Classic detected", fn);
EXTNS_MfcInit(aActivationData);
mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A;
mNumTechList++;
mTechHandles[mNumTechList] = rfDetail.rf_disc_id;
mTechLibNfcTypes[mNumTechList] = rfDetail.protocol;
// Save the stack's data structure for interpretation later.
memcpy(&(mTechParams[mNumTechList]), &(rfDetail.rf_tech_param),
sizeof(rfDetail.rf_tech_param));
mTechList[mNumTechList] = TECHNOLOGY_TYPE_MIFARE_CLASSIC;
break;
#endif
default:
ALOGE("%s: unknown protocol ????", fn);
mTechList[mNumTechList] = TECHNOLOGY_TYPE_UNKNOWN;
Expand Down Expand Up @@ -320,6 +337,18 @@ void NfcTag::DiscoverTechnologies(tNFA_DISC_RESULT& aDiscoveryData)
mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO15693;
break;

#ifdef NFCC_PN547
case NFC_PROTOCOL_MIFARE:
mTechHandles[mNumTechList] = discovery_ntf.rf_disc_id;
mTechLibNfcTypes[mNumTechList] = discovery_ntf.protocol;
mTechList[mNumTechList] = TECHNOLOGY_TYPE_MIFARE_CLASSIC;
// Save the stack's data structure for interpretation later
memcpy(&(mTechParams[mNumTechList]), &(discovery_ntf.rf_tech_param),
sizeof(discovery_ntf.rf_tech_param));
mNumTechList++;
mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A;
break;
#endif
default:
ALOGE("%s: unknown protocol ????", fn);
mTechList[mNumTechList] = TECHNOLOGY_TYPE_UNKNOWN;
Expand Down Expand Up @@ -584,6 +613,15 @@ void NfcTag::FillNfcTagMembers4(INfcTag* aINfcTag,
break;
} // Case NFC_PROTOCOL_ISO_DEP: //t4t.

#ifdef NFCC_PN547
case NFC_PROTOCOL_MIFARE: {
ALOGD("%s: Mifare Classic; tech A", fn);
actBytes.clear();
actBytes.push_back(mTechParams[i].param.pa.sel_rsp);
break;
}
#endif

case NFC_PROTOCOL_15693: {
ALOGD("%s: tech iso 15693", fn);
// iso 15693 response flags: 1 octet.
Expand Down

0 comments on commit 16836b5

Please sign in to comment.