diff --git a/src/NfcGonkMessage.h b/src/NfcGonkMessage.h index 37c60e9..99f8510 100644 --- a/src/NfcGonkMessage.h +++ b/src/NfcGonkMessage.h @@ -104,19 +104,18 @@ typedef enum { } NfcRFState; /** - * NFC technologies. + * NFC technologies, this is defined in interface/TagTechnology.cpp + * + * UNKNOWN = -1 + * NFC_A = 0 + * NFC_B = 1 + * NFC_F = 2 + * NFC_V = 3 + * NFC_ISO_DEP = 4 + * MIFARE_CLASSIC = 5 + * MIFARE_ULTRALIGHT = 6 + * NFC_BARCODE = 7 */ -typedef enum { - NFC_TECH_UNKNOWN = -1, - NFC_TECH_NFCA = 0, - NFC_TECH_NFCB = 1, - NFC_TECH_NFCF = 2, - NFC_TECH_NFCV = 3, - NFC_TECH_ISO_DEP = 4, - NFC_TECH_MIFARE_CLASSIC = 5, - NFC_TECH_MIFARE_ULTRALIGHT = 6, - NFC_TECH_BARCODE = 7 -} NfcTechnology; /** * NDEF type diff --git a/src/NfcService.cpp b/src/NfcService.cpp index dae6c33..e14c3eb 100644 --- a/src/NfcService.cpp +++ b/src/NfcService.cpp @@ -294,9 +294,7 @@ void NfcService::handleTagDiscovered(NfcEvent* event) int techCount = techList.size(); uint8_t* gonkTechList = new uint8_t[techCount]; - for(int i = 0; i < techCount; i++) { - gonkTechList[i] = (uint8_t)NfcUtil::convertTagTechToGonkFormat(techList[i]); - } + std::copy(techList.begin(), techList.end(), gonkTechList); TechDiscoveredEvent* data = new TechDiscoveredEvent(); data->sessionId = SessionId::generateNewId(); @@ -592,7 +590,7 @@ void NfcService::handleTagTransceiveResponse(NfcEvent* event) NfcErrorCode code = pINfcTag->connect(static_cast(tech)) ? NFC_SUCCESS : NFC_ERROR_IO; - if (NFC_SUCCESS != code) { + if (NFC_SUCCESS == code) { code = !!pINfcTag ? (pINfcTag->transceive(*command, response) ? NFC_SUCCESS : NFC_ERROR_IO) : NFC_ERROR_NOT_SUPPORTED; } diff --git a/src/NfcUtil.cpp b/src/NfcUtil.cpp index 3935c93..51d0852 100644 --- a/src/NfcUtil.cpp +++ b/src/NfcUtil.cpp @@ -27,22 +27,6 @@ void NfcUtil::convertNdefPduToNdefMessage(NdefMessagePdu& ndefPdu, NdefMessage* } } -NfcTechnology NfcUtil::convertTagTechToGonkFormat(TagTechnology tagTech) { - switch(tagTech) { - case NFC_A: return NFC_TECH_NFCA; - case NFC_B: return NFC_TECH_NFCB; - case NFC_ISO_DEP: return NFC_TECH_ISO_DEP; - case NFC_F: return NFC_TECH_NFCF; - case NFC_V: return NFC_TECH_NFCV; - case MIFARE_CLASSIC: return NFC_TECH_MIFARE_CLASSIC; - case MIFARE_ULTRALIGHT: return NFC_TECH_MIFARE_ULTRALIGHT; - case NFC_BARCODE: return NFC_TECH_MIFARE_ULTRALIGHT; - case UNKNOWN_TECH: - default: return NFC_TECH_UNKNOWN; - } - return NFC_TECH_NFCA; -} - NfcEvtTransactionOrigin NfcUtil::convertOriginType(TransactionEvent::OriginType type) { switch (type) { diff --git a/src/NfcUtil.h b/src/NfcUtil.h index eed52b7..96eef98 100644 --- a/src/NfcUtil.h +++ b/src/NfcUtil.h @@ -27,7 +27,6 @@ class NfcUtil{ public: static void convertNdefPduToNdefMessage(NdefMessagePdu& ndefPdu, NdefMessage* ndefMessage); - static NfcTechnology convertTagTechToGonkFormat(TagTechnology tagTech); static NfcEvtTransactionOrigin convertOriginType(TransactionEvent::OriginType type); static NfcNdefType convertNdefType(NdefType type); private: diff --git a/src/interface/TagTechnology.h b/src/interface/TagTechnology.h index 96283cd..c89fb5a 100644 --- a/src/interface/TagTechnology.h +++ b/src/interface/TagTechnology.h @@ -20,19 +20,18 @@ // Used by getTechList() of INfcTag. // Define the tag technology. typedef enum { + UNKNOWN_TECH = -1, NFC_A = 0, NFC_B = 1, - NFC_ISO_DEP = 2, - NFC_F = 3, - NFC_V = 4, - NDEF = 5, - MIFARE_CLASSIC = 6, - MIFARE_ULTRALIGHT = 7, - NFC_BARCODE = 8, - UNKNOWN_TECH = 9 + NFC_F = 2, + NFC_V = 3, + NFC_ISO_DEP = 4, + MIFARE_CLASSIC = 5, + MIFARE_ULTRALIGHT = 6, + NFC_BARCODE = 7, + NDEF = 8, } TagTechnology; - // Pre-defined tag type values. typedef enum { NDEF_UNKNOWN_TYPE = -1, diff --git a/src/nci/NfcNciUtil.cpp b/src/nci/NfcNciUtil.cpp index 6575d9b..49d1911 100644 --- a/src/nci/NfcNciUtil.cpp +++ b/src/nci/NfcNciUtil.cpp @@ -16,34 +16,36 @@ #include "NfcNciUtil.h" -TagTechnology NfcNciUtil::toGenericTagTechnology(unsigned int tagTech) +TagTechnology NfcNciUtil::toTagTechnology(TechnologyType techType) { - switch(tagTech) { - case TARGET_TYPE_ISO14443_3A: return NFC_A; - case TARGET_TYPE_ISO14443_3B: return NFC_B; - case TARGET_TYPE_ISO14443_4: return NFC_ISO_DEP; - case TARGET_TYPE_FELICA: return NFC_F; - case TARGET_TYPE_ISO15693: return NFC_V; - case TARGET_TYPE_MIFARE_CLASSIC: return MIFARE_CLASSIC; - case TARGET_TYPE_MIFARE_UL: return MIFARE_ULTRALIGHT; - case TARGET_TYPE_KOVIO_BARCODE: return NFC_BARCODE; - case TARGET_TYPE_UNKNOWN: - default: return UNKNOWN_TECH; + switch(techType) { + case TECHNOLOGY_TYPE_ISO14443_3A: return NFC_A; + case TECHNOLOGY_TYPE_ISO14443_3B: return NFC_B; + case TECHNOLOGY_TYPE_ISO14443_4: return NFC_ISO_DEP; + case TECHNOLOGY_TYPE_FELICA: return NFC_F; + case TECHNOLOGY_TYPE_ISO15693: return NFC_V; + case TECHNOLOGY_TYPE_MIFARE_CLASSIC: return MIFARE_CLASSIC; + case TECHNOLOGY_TYPE_MIFARE_UL: return MIFARE_ULTRALIGHT; + case TECHNOLOGY_TYPE_KOVIO_BARCODE: return NFC_BARCODE; + case TECHNOLOGY_TYPE_NDEF: return NDEF; + case TECHNOLOGY_TYPE_UNKNOWN: + default: return UNKNOWN_TECH; } } -unsigned int NfcNciUtil::toNciTagTechnology(TagTechnology tagTech) +TechnologyType NfcNciUtil::toTechnologyType(TagTechnology tagTech) { switch(tagTech) { - case NFC_A: return TARGET_TYPE_ISO14443_3A; - case NFC_B: return TARGET_TYPE_ISO14443_3B; - case NFC_ISO_DEP: return TARGET_TYPE_ISO14443_4; - case NFC_F: return TARGET_TYPE_FELICA; - case NFC_V: return TARGET_TYPE_ISO15693; - case MIFARE_CLASSIC: return TARGET_TYPE_MIFARE_CLASSIC; - case MIFARE_ULTRALIGHT: return TARGET_TYPE_MIFARE_UL; - case NFC_BARCODE: return TARGET_TYPE_KOVIO_BARCODE; + case NFC_A: return TECHNOLOGY_TYPE_ISO14443_3A; + case NFC_B: return TECHNOLOGY_TYPE_ISO14443_3B; + case NFC_ISO_DEP: return TECHNOLOGY_TYPE_ISO14443_4; + case NFC_F: return TECHNOLOGY_TYPE_FELICA; + case NFC_V: return TECHNOLOGY_TYPE_ISO15693; + case MIFARE_CLASSIC: return TECHNOLOGY_TYPE_MIFARE_CLASSIC; + case MIFARE_ULTRALIGHT: return TECHNOLOGY_TYPE_MIFARE_UL; + case NFC_BARCODE: return TECHNOLOGY_TYPE_KOVIO_BARCODE; + case NDEF: return TECHNOLOGY_TYPE_NDEF; case UNKNOWN_TECH: - default: return TARGET_TYPE_UNKNOWN; + default: return TECHNOLOGY_TYPE_UNKNOWN; } } diff --git a/src/nci/NfcNciUtil.h b/src/nci/NfcNciUtil.h index f15ed69..a9683a0 100644 --- a/src/nci/NfcNciUtil.h +++ b/src/nci/NfcNciUtil.h @@ -62,17 +62,20 @@ /** - * Name strings for target types. + * Name strings for technology types. */ -#define TARGET_TYPE_UNKNOWN -1 -#define TARGET_TYPE_ISO14443_3A 1 -#define TARGET_TYPE_ISO14443_3B 2 -#define TARGET_TYPE_ISO14443_4 3 -#define TARGET_TYPE_FELICA 4 -#define TARGET_TYPE_ISO15693 5 -#define TARGET_TYPE_MIFARE_CLASSIC 6 -#define TARGET_TYPE_MIFARE_UL 7 -#define TARGET_TYPE_KOVIO_BARCODE 8 +enum TechnologyType{ + TECHNOLOGY_TYPE_UNKNOWN = -1, + TECHNOLOGY_TYPE_ISO14443_3A = 1, + TECHNOLOGY_TYPE_ISO14443_3B = 2, + TECHNOLOGY_TYPE_ISO14443_4 = 3, + TECHNOLOGY_TYPE_FELICA = 4, + TECHNOLOGY_TYPE_ISO15693 = 5, + TECHNOLOGY_TYPE_NDEF = 6, + TECHNOLOGY_TYPE_MIFARE_CLASSIC = 7, + TECHNOLOGY_TYPE_MIFARE_UL = 8, + TECHNOLOGY_TYPE_KOVIO_BARCODE = 9, +}; // Define a few NXP error codes that NFC service expects. @@ -114,8 +117,8 @@ struct nfc_data class NfcNciUtil { public: - static TagTechnology toGenericTagTechnology(unsigned int tagTech); - static unsigned int toNciTagTechnology(TagTechnology tagTech); + static TagTechnology toTagTechnology(TechnologyType techType); + static TechnologyType toTechnologyType(TagTechnology tagTech); private: NfcNciUtil(); }; diff --git a/src/nci/NfcTag.cpp b/src/nci/NfcTag.cpp index d00ad63..8ed7ae5 100644 --- a/src/nci/NfcTag.cpp +++ b/src/nci/NfcTag.cpp @@ -169,11 +169,11 @@ void NfcTag::discoverTechnologies(tNFA_ACTIVATED& activationData) switch (rfDetail.protocol) { case NFC_PROTOCOL_T1T: - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. break; case NFC_PROTOCOL_T2T: - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. // Could be MifFare UL or Classic or Kovio. { // Need to look at first byte of uid to find manuf. @@ -189,18 +189,18 @@ void NfcTag::discoverTechnologies(tNFA_ACTIVATED& activationData) 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] = TARGET_TYPE_MIFARE_UL; // Is TagTechnology.MIFARE_ULTRALIGHT by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_MIFARE_UL; // Is TagTechnology.MIFARE_ULTRALIGHT by Java API. } } } break; case NFC_PROTOCOL_T3T: - mTechList[mNumTechList] = TARGET_TYPE_FELICA; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_FELICA; break; case NFC_PROTOCOL_ISO_DEP: // Type-4 tag uses technology ISO-DEP and technology A or B. - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_4; // Is TagTechnology.ISO_DEP by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_4; // Is TagTechnology.ISO_DEP by Java API. if ( (rfDetail.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_A) || (rfDetail.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_A_ACTIVE) || (rfDetail.rf_tech_param.mode == NFC_DISCOVERY_TYPE_LISTEN_A) || @@ -208,7 +208,7 @@ void NfcTag::discoverTechnologies(tNFA_ACTIVATED& activationData) mNumTechList++; mTechHandles[mNumTechList] = rfDetail.rf_disc_id; mTechLibNfcTypes[mNumTechList] = rfDetail.protocol; - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; //is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; //is TagTechnology.NFC_A by Java API. // Save the stack's data structure for interpretation later memcpy(&(mTechParams[mNumTechList]), &(rfDetail.rf_tech_param), sizeof(rfDetail.rf_tech_param)); } else if ( (rfDetail.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_B) || @@ -218,24 +218,24 @@ void NfcTag::discoverTechnologies(tNFA_ACTIVATED& activationData) mNumTechList++; mTechHandles[mNumTechList] = rfDetail.rf_disc_id; mTechLibNfcTypes[mNumTechList] = rfDetail.protocol; - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3B; // Is TagTechnology.NFC_B by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3B; // Is TagTechnology.NFC_B by Java API. // Save the stack's data structure for interpretation later. memcpy(&(mTechParams[mNumTechList]), &(rfDetail.rf_tech_param), sizeof(rfDetail.rf_tech_param)); } break; case NFC_PROTOCOL_15693: // Is TagTechnology.NFC_V by Java API. - mTechList[mNumTechList] = TARGET_TYPE_ISO15693; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO15693; break; case NFC_PROTOCOL_KOVIO: ALOGD("%s: Kovio", fn); - mTechList[mNumTechList] = TARGET_TYPE_KOVIO_BARCODE; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_KOVIO_BARCODE; break; default: ALOGE("%s: unknown protocol ????", fn); - mTechList[mNumTechList] = TARGET_TYPE_UNKNOWN; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_UNKNOWN; break; } @@ -265,18 +265,18 @@ void NfcTag::discoverTechnologies(tNFA_DISC_RESULT& discoveryData) switch (discovery_ntf.protocol) { case NFC_PROTOCOL_T1T: - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. break; case NFC_PROTOCOL_T2T: - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. // Type-2 tags are identitical to Mifare Ultralight, so Ultralight is also discovered. if (discovery_ntf.rf_tech_param.param.pa.sel_rsp == 0) { // Mifare Ultralight. mNumTechList++; mTechHandles[mNumTechList] = discovery_ntf.rf_disc_id; mTechLibNfcTypes[mNumTechList] = discovery_ntf.protocol; - mTechList[mNumTechList] = TARGET_TYPE_MIFARE_UL; // Is TagTechnology.MIFARE_ULTRALIGHT by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_MIFARE_UL; // Is TagTechnology.MIFARE_ULTRALIGHT by Java API. } // Save the stack's data structure for interpretation later. @@ -284,11 +284,11 @@ void NfcTag::discoverTechnologies(tNFA_DISC_RESULT& discoveryData) break; case NFC_PROTOCOL_T3T: - mTechList[mNumTechList] = TARGET_TYPE_FELICA; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_FELICA; break; case NFC_PROTOCOL_ISO_DEP: // Type-4 tag uses technology ISO-DEP and technology A or B. - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_4; // Is TagTechnology.ISO_DEP by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_4; // Is TagTechnology.ISO_DEP by Java API. if ( (discovery_ntf.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_A) || (discovery_ntf.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_A_ACTIVE) || (discovery_ntf.rf_tech_param.mode == NFC_DISCOVERY_TYPE_LISTEN_A) || @@ -296,7 +296,7 @@ void NfcTag::discoverTechnologies(tNFA_DISC_RESULT& discoveryData) mNumTechList++; mTechHandles[mNumTechList] = discovery_ntf.rf_disc_id; mTechLibNfcTypes[mNumTechList] = discovery_ntf.protocol; - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3A; // Is TagTechnology.NFC_A by Java API. // Save the stack's data structure for interpretation later. memcpy(&(mTechParams[mNumTechList]), &(discovery_ntf.rf_tech_param), sizeof(discovery_ntf.rf_tech_param)); } else if ( (discovery_ntf.rf_tech_param.mode == NFC_DISCOVERY_TYPE_POLL_B) || @@ -306,19 +306,19 @@ void NfcTag::discoverTechnologies(tNFA_DISC_RESULT& discoveryData) mNumTechList++; mTechHandles[mNumTechList] = discovery_ntf.rf_disc_id; mTechLibNfcTypes[mNumTechList] = discovery_ntf.protocol; - mTechList[mNumTechList] = TARGET_TYPE_ISO14443_3B; // Is TagTechnology.NFC_B by Java API + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO14443_3B; // Is TagTechnology.NFC_B by Java API // Save the stack's data structure for interpretation later memcpy(&(mTechParams[mNumTechList]), &(discovery_ntf.rf_tech_param), sizeof(discovery_ntf.rf_tech_param)); } break; case NFC_PROTOCOL_15693: // Is TagTechnology.NFC_V by Java API. - mTechList[mNumTechList] = TARGET_TYPE_ISO15693; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_ISO15693; break; default: ALOGE("%s: unknown protocol ????", fn); - mTechList[mNumTechList] = TARGET_TYPE_UNKNOWN; + mTechList[mNumTechList] = TECHNOLOGY_TYPE_UNKNOWN; break; } @@ -382,7 +382,7 @@ void NfcTag::fillNfcTagMembers1(INfcTag* pINfcTag) gNat.handles[i] = mTechHandles[i]; // Convert from vendor specific technology definition to common tag technology definition. - techList.push_back(NfcNciUtil::toGenericTagTechnology(mTechList[i])); + techList.push_back(NfcNciUtil::toTagTechnology(mTechList[i])); techHandles.push_back(mTechHandles[i]); techLibNfcTypes.push_back(mTechLibNfcTypes[i]); } @@ -423,11 +423,11 @@ void NfcTag::fillNfcTagMembers3(INfcTag* pINfcTag, tNFA_ACTIVATED& activationDat case NFC_DISCOVERY_TYPE_POLL_B_PRIME: case NFC_DISCOVERY_TYPE_LISTEN_B: case NFC_DISCOVERY_TYPE_LISTEN_B_PRIME: - if (mTechList [i] == TARGET_TYPE_ISO14443_3B) { // Is TagTechnology.NFC_B by Java API. + if (mTechList [i] == TECHNOLOGY_TYPE_ISO14443_3B) { // Is TagTechnology.NFC_B by Java API. // See NFC Forum Digital Protocol specification; section 5.6.2. // In SENSB_RES response, byte 6 through 9 is Application Data, byte 10-12 or 13 is Protocol Info. // Used by public API: NfcB.getApplicationData(), NfcB.getProtocolInfo(). - ALOGD("%s: tech B; TARGET_TYPE_ISO14443_3B", fn); + ALOGD("%s: tech B; TECHNOLOGY_TYPE_ISO14443_3B", fn); len = mTechParams[i].param.pb.sensb_res_len; len = len - 4; // Subtract 4 bytes for NFCID0 at byte 2 through 5. pollBytes.clear(); @@ -526,7 +526,7 @@ void NfcTag::fillNfcTagMembers4(INfcTag* pINfcTag, tNFA_ACTIVATED& activationDat } case NFC_PROTOCOL_ISO_DEP: { // t4t. - if (mTechList [i] == TARGET_TYPE_ISO14443_4) { // Is TagTechnology.ISO_DEP by Java API. + if (mTechList [i] == TECHNOLOGY_TYPE_ISO14443_4) { // Is TagTechnology.ISO_DEP by Java API. if ( (mTechParams[i].mode == NFC_DISCOVERY_TYPE_POLL_A) || (mTechParams[i].mode == NFC_DISCOVERY_TYPE_POLL_A_ACTIVE) || (mTechParams[i].mode == NFC_DISCOVERY_TYPE_LISTEN_A) || @@ -568,7 +568,7 @@ void NfcTag::fillNfcTagMembers4(INfcTag* pINfcTag, tNFA_ACTIVATED& activationDat actBytes.clear(); } } - } else if (mTechList [i] == TARGET_TYPE_ISO14443_3A) { // Is TagTechnology.NFC_A by Java API. + } else if (mTechList [i] == TECHNOLOGY_TYPE_ISO14443_3A) { // Is TagTechnology.NFC_A by Java API. ALOGD("%s: T4T; tech A", fn); actBytes.clear(); actBytes.push_back(mTechParams [i].param.pa.sel_rsp); @@ -896,14 +896,14 @@ void NfcTag::connectionEventHandler(UINT8 event, tNFA_CONN_EVT_DATA* data) void NfcTag::resetAllTransceiveTimeouts() { - mTimeoutTable[TARGET_TYPE_ISO14443_3A] = 618; // NfcA - mTimeoutTable[TARGET_TYPE_ISO14443_3B] = 1000; // NfcB - mTimeoutTable[TARGET_TYPE_ISO14443_4] = 309; // ISO-DEP - mTimeoutTable[TARGET_TYPE_FELICA] = 255; // Felica - mTimeoutTable[TARGET_TYPE_ISO15693] = 1000; // NfcV - mTimeoutTable[TARGET_TYPE_MIFARE_CLASSIC] = 618; // MifareClassic - mTimeoutTable[TARGET_TYPE_MIFARE_UL] = 618; // MifareUltralight - mTimeoutTable[TARGET_TYPE_KOVIO_BARCODE] = 1000; // NfcBarcode + mTimeoutTable[TECHNOLOGY_TYPE_ISO14443_3A] = 618; // NfcA + mTimeoutTable[TECHNOLOGY_TYPE_ISO14443_3B] = 1000; // NfcB + mTimeoutTable[TECHNOLOGY_TYPE_ISO14443_4] = 309; // ISO-DEP + mTimeoutTable[TECHNOLOGY_TYPE_FELICA] = 255; // Felica + mTimeoutTable[TECHNOLOGY_TYPE_ISO15693] = 1000; // NfcV + mTimeoutTable[TECHNOLOGY_TYPE_MIFARE_CLASSIC] = 618; // MifareClassic + mTimeoutTable[TECHNOLOGY_TYPE_MIFARE_UL] = 618; // MifareUltralight + mTimeoutTable[TECHNOLOGY_TYPE_KOVIO_BARCODE] = 1000; // NfcBarcode } int NfcTag::getTransceiveTimeout(int techId) diff --git a/src/nci/NfcTag.h b/src/nci/NfcTag.h index 62557aa..81a4190 100644 --- a/src/nci/NfcTag.h +++ b/src/nci/NfcTag.h @@ -35,14 +35,17 @@ class INfcTag; class NfcTag { public: + NfcTag(); + enum ActivationState {Idle, Sleep, Active}; - static const int MAX_NUM_TECHNOLOGY = 10; // Max number of technologies supported by one or more tags. - int mTechList [MAX_NUM_TECHNOLOGY]; // Array of NFC technologies according to NFC service. - int mTechHandles [MAX_NUM_TECHNOLOGY]; // Array of tag handles according to NFC service. - int mTechLibNfcTypes [MAX_NUM_TECHNOLOGY]; // Array of detailed tag types according to NFC service. - int mNumTechList; // Current number of NFC technologies in the list. - NfcTag(); + // Max number of technologies supported by one or more tags. + static const int MAX_NUM_TECHNOLOGY = 10; + + TechnologyType mTechList [MAX_NUM_TECHNOLOGY]; // Array of NFC technologies. + int mTechHandles [MAX_NUM_TECHNOLOGY]; // Array of tag handles. + int mTechLibNfcTypes [MAX_NUM_TECHNOLOGY]; // Array of detailed tag types. + int mNumTechList; // Number of NFC technologies in the list. /** * Get a reference to the singleton NfcTag object. @@ -85,7 +88,7 @@ class NfcTag /** * Get the timeout value for one technology. * - * @param techId One of the values in TARGET_TYPE_* defined in NfcNciUtil.h. + * @param techId One of the values in TECHNOLOGY_TYPE_* defined in NfcNciUtil.h. * @return Timeout value in millisecond. */ int getTransceiveTimeout(int techId); diff --git a/src/nci/NfcTagManager.cpp b/src/nci/NfcTagManager.cpp index a111dae..56205cb 100644 --- a/src/nci/NfcTagManager.cpp +++ b/src/nci/NfcTagManager.cpp @@ -23,7 +23,6 @@ #include "NdefMessage.h" #include "TagTechnology.h" -#include "NfcNciUtil.h" #include "NfcTag.h" #include "config.h" #include "Mutex.h" @@ -52,42 +51,42 @@ bool gIsSelectingRfInterface = false; #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. -static bool sCheckNdefCapable = false; // Whether tag has NDEF capability. -static tNFA_HANDLE sNdefTypeHandlerHandle = NFA_HANDLE_INVALID; -static tNFA_INTF_TYPE sCurrentRfInterface = NFA_INTERFACE_ISO_DEP; -static uint8_t* sTransceiveData = NULL; -static uint32_t sTransceiveDataLen = 0; -static bool sWaitingForTransceive = false; -static bool sTransceiveRfTimeout = false; -static bool sNeedToSwitchRf = false; -static Mutex sRfInterfaceMutex; -static uint32_t sReadDataLen = 0; -static uint8_t* sReadData = NULL; -static bool sIsReadingNdefMessage = false; -static SyncEvent sReadEvent; -static sem_t sWriteSem; -static sem_t sFormatSem; -static SyncEvent sTransceiveEvent; -static SyncEvent sReconnectEvent; -static sem_t sCheckNdefSem; -static sem_t sPresenceCheckSem; -static sem_t sMakeReadonlySem; -static IntervalTimer sSwitchBackTimer; // Timer used to tell us to switch back to ISO_DEP frame interface. -static bool sWriteOk = false; -static bool sWriteWaitingForComplete = false; -static bool sFormatOk = false; -static bool sConnectOk = false; -static bool sConnectWaitingForComplete = false; -static bool sGotDeactivate = false; -static uint32_t sCheckNdefMaxSize = 0; -static bool sCheckNdefCardReadOnly = false; -static bool sCheckNdefWaitingForComplete = false; -static int sCountTagAway = 0; // Count the consecutive number of presence-check failures. -static tNFA_STATUS sMakeReadonlyStatus = NFA_STATUS_FAILED; -static bool sMakeReadonlyWaitingForComplete = false; -static int sCurrentConnectedTargetType = TARGET_TYPE_UNKNOWN; +static uint32_t sCheckNdefCurrentSize = 0; +static tNFA_STATUS sCheckNdefStatus = 0; // Whether tag already contains a NDEF message. +static bool sCheckNdefCapable = false; // Whether tag has NDEF capability. +static tNFA_HANDLE sNdefTypeHandlerHandle = NFA_HANDLE_INVALID; +static tNFA_INTF_TYPE sCurrentRfInterface = NFA_INTERFACE_ISO_DEP; +static uint8_t* sTransceiveData = NULL; +static uint32_t sTransceiveDataLen = 0; +static bool sWaitingForTransceive = false; +static bool sTransceiveRfTimeout = false; +static bool sNeedToSwitchRf = false; +static Mutex sRfInterfaceMutex; +static uint32_t sReadDataLen = 0; +static uint8_t* sReadData = NULL; +static bool sIsReadingNdefMessage = false; +static SyncEvent sReadEvent; +static sem_t sWriteSem; +static sem_t sFormatSem; +static SyncEvent sTransceiveEvent; +static SyncEvent sReconnectEvent; +static sem_t sCheckNdefSem; +static sem_t sPresenceCheckSem; +static sem_t sMakeReadonlySem; +static IntervalTimer sSwitchBackTimer; // Timer used to tell us to switch back to ISO_DEP frame interface. +static bool sWriteOk = false; +static bool sWriteWaitingForComplete = false; +static bool sFormatOk = false; +static bool sConnectOk = false; +static bool sConnectWaitingForComplete = false; +static bool sGotDeactivate = false; +static uint32_t sCheckNdefMaxSize = 0; +static bool sCheckNdefCardReadOnly = false; +static bool sCheckNdefWaitingForComplete = false; +static int sCountTagAway = 0; // Count the consecutive number of presence-check failures. +static tNFA_STATUS sMakeReadonlyStatus = NFA_STATUS_FAILED; +static bool sMakeReadonlyWaitingForComplete = false; +static TechnologyType sCurrentConnectedTargetType = TECHNOLOGY_TYPE_UNKNOWN; static void ndefHandlerCallback(tNFA_NDEF_EVT event, tNFA_NDEF_EVT_DATA *eventData) { @@ -241,7 +240,7 @@ int NfcTagManager::reconnectWithStatus() } // Special case for Kovio. - if (tag.mTechList[0] == TARGET_TYPE_KOVIO_BARCODE) { + if (tag.mTechList[0] == TECHNOLOGY_TYPE_KOVIO_BARCODE) { ALOGD("%s: fake out reconnect for Kovio", __FUNCTION__); goto TheEnd; } @@ -258,14 +257,14 @@ int NfcTagManager::reconnectWithStatus() return retCode; } -int NfcTagManager::reconnectWithStatus(int technology) +int NfcTagManager::reconnectWithStatus(int targetHandle) { int status = -1; - status = doConnect(technology); + status = doConnect(targetHandle); return status; } -int NfcTagManager::connectWithStatus(int technology) +int NfcTagManager::connectWithStatus(TechnologyType technology) { int status = -1; NfcTag& tag = NfcTag::getInstance(); @@ -305,7 +304,7 @@ int NfcTagManager::connectWithStatus(int technology) // any handle). // 2) We are connecting to the ndef technology - always // allowed. - if (technology == NDEF) { + if (technology == TECHNOLOGY_TYPE_NDEF) { i = 0; } @@ -484,7 +483,7 @@ int NfcTagManager::doCheckNdef(int ndefInfo[]) NfcTag& tag = NfcTag::getInstance(); // Special case for Kovio. - if (tag.mTechList[0] == TARGET_TYPE_KOVIO_BARCODE) { + if (tag.mTechList[0] == TECHNOLOGY_TYPE_KOVIO_BARCODE) { ALOGD("%s: Kovio tag, no NDEF", __FUNCTION__); ndefInfo[0] = 0; ndefInfo[1] = NDEF_MODE_READ_ONLY; @@ -492,7 +491,7 @@ int NfcTagManager::doCheckNdef(int ndefInfo[]) } // Special case for Kovio. - if (tag.mTechList[0] == TARGET_TYPE_KOVIO_BARCODE) { + if (tag.mTechList[0] == TECHNOLOGY_TYPE_KOVIO_BARCODE) { ALOGD("%s: Kovio tag, no NDEF", __FUNCTION__); ndefInfo[0] = 0; ndefInfo[1] = NDEF_MODE_READ_ONLY; @@ -587,7 +586,7 @@ void NfcTagManager::doAbortWaits() sem_post(&sPresenceCheckSem); sem_post(&sMakeReadonlySem); - sCurrentConnectedTargetType = TARGET_TYPE_UNKNOWN; + sCurrentConnectedTargetType = TECHNOLOGY_TYPE_UNKNOWN; } void NfcTagManager::doReadCompleted(tNFA_STATUS status) @@ -816,7 +815,7 @@ int NfcTagManager::doConnect(int targetHandle) goto TheEnd; } - if (tag.mTechList[i] == TARGET_TYPE_ISO14443_3A || tag.mTechList[i] == TARGET_TYPE_ISO14443_3B) { + if (tag.mTechList[i] == TECHNOLOGY_TYPE_ISO14443_3A || tag.mTechList[i] == TECHNOLOGY_TYPE_ISO14443_3B) { ALOGD("%s: switching to tech: %d need to switch rf intf to frame", __FUNCTION__, tag.mTechList[i]); // Connecting to NfcA or NfcB don't actually switch until/unless we get a transceive. sNeedToSwitchRf = true; @@ -840,7 +839,7 @@ bool NfcTagManager::doPresenceCheck() // Special case for Kovio. The deactivation would have already occurred // but was ignored so that normal tag opertions could complete. Now we // want to process as if the deactivate just happened. - if (tag.mTechList[0] == TARGET_TYPE_KOVIO_BARCODE) { + if (tag.mTechList[0] == TECHNOLOGY_TYPE_KOVIO_BARCODE) { ALOGD("%s: Kovio, force deactivate handling", __FUNCTION__); tNFA_DEACTIVATED deactivated = {NFA_DEACTIVATE_TYPE_IDLE}; @@ -1158,7 +1157,7 @@ bool NfcTagManager::doIsNdefFormatable() bool NfcTagManager::connect(TagTechnology technology) { pthread_mutex_lock(&mMutex); - int status = connectWithStatus(NfcNciUtil::toNciTagTechnology(technology)); + int status = connectWithStatus(NfcNciUtil::toTechnologyType(technology)); pthread_mutex_unlock(&mMutex); return NFCSTATUS_SUCCESS == status; } diff --git a/src/nci/NfcTagManager.h b/src/nci/NfcTagManager.h index 36c118e..e1f5479 100644 --- a/src/nci/NfcTagManager.h +++ b/src/nci/NfcTagManager.h @@ -21,6 +21,8 @@ #include #include "INfcTag.h" +#include "NfcNciUtil.h" + extern "C" { #include "nfa_rw_api.h" @@ -241,8 +243,8 @@ class NfcTagManager static bool doIsNdefFormatable(); - int connectWithStatus(int technology); - int reconnectWithStatus(int technology); + int connectWithStatus(TechnologyType technology); + int reconnectWithStatus(int targetHandle); int reconnectWithStatus(); NdefMessage* doReadNdef(); NdefInfo* doReadNdefInfo();