summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSunil Jogi <sunil.jogi@nxp.com>2012-01-16 09:13:58 -0800
committerMartijn Coenen <maco@google.com>2012-04-02 10:35:35 -0700
commitc3a87316a08d782d8b336d2d9663b47a4ec37d21 (patch)
treeb732cb0a09683225bf058bc4ef430b9c157f3e56 /src
parent40734e7599249717860f7aeabda494e1bcd86ffe (diff)
downloadexternal_libnfc-nxp-c3a87316a08d782d8b336d2d9663b47a4ec37d21.zip
external_libnfc-nxp-c3a87316a08d782d8b336d2d9663b47a4ec37d21.tar.gz
external_libnfc-nxp-c3a87316a08d782d8b336d2d9663b47a4ec37d21.tar.bz2
Added support for tearing recovery for MIFARE Classic Readonly
When readonly is interrupted in between next readonly call make remaining sectors readonly and return true. If all sectors are readonly then call to readonly returns error. Change-Id: Id47a77198b41d69b743f24259849e943954c7a58
Diffstat (limited to 'src')
-rw-r--r--src/phFriNfc_MifareStdMap.c22
-rw-r--r--src/phFriNfc_NdefMap.h2
-rw-r--r--src/phLibNfc_ndef_raw.c6
3 files changed, 16 insertions, 14 deletions
diff --git a/src/phFriNfc_MifareStdMap.c b/src/phFriNfc_MifareStdMap.c
index 3e8b6db..efe86d6 100644
--- a/src/phFriNfc_MifareStdMap.c
+++ b/src/phFriNfc_MifareStdMap.c
@@ -1192,9 +1192,18 @@ void phFriNfc_MifareStdMap_Process( void *Context,
CRFlag = (uint8_t)((Status != NFCSTATUS_PENDING)?
PH_FRINFC_MIFARESTD_FLAG1:
PH_FRINFC_MIFARESTD_FLAG0);
- break;
+ if ((CRFlag == PH_FRINFC_MIFARESTD_FLAG1) &&
+ (NdefMap->StdMifareContainer.WriteAcsBitFlag == PH_FRINFC_MIFARESTD_FLAG0))
+ {
+ Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
+ NFCSTATUS_INVALID_DEVICE_REQUEST);
+ }
+ break;
case PH_FRINFC_NDEFMAP_STATE_WRITE_SEC:
+ /* Set flag for writing of Acs bit */
+ NdefMap->StdMifareContainer.WriteAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG1;
+
/* The first NDEF sector is already made read only,
set card state to read only and proceed*/
if(NdefMap->CardState != PH_NDEFMAP_CARD_STATE_READ_ONLY)
@@ -6064,11 +6073,6 @@ phFriNfc_MifareStdMap_ConvertToReadOnly (
{
result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_STATE);
}
- else if (PH_NDEFMAP_CARD_STATE_INITIALIZED == NdefMap->CardState ||
- PH_NDEFMAP_CARD_STATE_READ_ONLY == NdefMap->CardState )
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_NOT_ALLOWED);
- }
else
{
/* card state is PH_NDEFMAP_CARD_STATE_READ_WRITE now */
@@ -6107,6 +6111,7 @@ phFriNfc_MifareStdMap_ConvertToReadOnly (
NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
+ NdefMap->StdMifareContainer.WriteAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG0;
/* Sector 0 is MAD sector .Start from Sector 1 */
for(NdefMap->StdMifareContainer.ReadOnlySectorIndex = PH_FRINFC_MIFARESTD_FLAG1;
@@ -6191,10 +6196,11 @@ static NFCSTATUS phFriNfc_MifStd_H_ProSectorTrailorAcsBits(phFriNfc_NdefMap_t *N
Result = phFriNfc_MifStd_H_ChkAcsBit(NdefMap);
if(Result == NFCSTATUS_SUCCESS)
{
+
if(NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY)
{
- /* No permission to read */
- Result = PHNFCSTVAL( CID_FRI_NFC_NDEF_MAP, NFCSTATUS_NOT_ALLOWED);
+ /* Go to next sector */
+ Result = phFriNfc_MifStd_H_ProWrSectorTrailor(NdefMap);
}
else
{
diff --git a/src/phFriNfc_NdefMap.h b/src/phFriNfc_NdefMap.h
index b559d4d..4c4ab45 100644
--- a/src/phFriNfc_NdefMap.h
+++ b/src/phFriNfc_NdefMap.h
@@ -446,6 +446,8 @@ typedef struct phFriNfc_MifareStdCont
uint8_t SectorIndex;
/** to read the access bits of each sector */
uint8_t ReadAcsBitFlag;
+ /** Flag to check if Acs bit was written in this call */
+ uint8_t WriteAcsBitFlag;
/** Buffer to store 16 bytes */
uint8_t Buffer[PH_FRINFC_NDEFMAP_MIFARESTD_RDWR_SIZE];
/** to store the AIDs of Mifare 1k or 4k */
diff --git a/src/phLibNfc_ndef_raw.c b/src/phLibNfc_ndef_raw.c
index 15ad001..31dbbac 100644
--- a/src/phLibNfc_ndef_raw.c
+++ b/src/phLibNfc_ndef_raw.c
@@ -1390,12 +1390,6 @@ phLibNfc_ConvertToReadOnlyNdef (
ret_val = NFCSTATUS_REJECTED;
PHDBG_INFO("LIbNfc:Previous Callback is Pending");
}
- else if (PH_NDEFMAP_CARD_STATE_READ_WRITE !=
- gpphLibContext->ndef_cntx.psNdefMap->CardState)
- {
- /* Tag is in different state */
- ret_val = NFCSTATUS_REJECTED;
- }
else
{
gpphLibContext->ndef_cntx.eLast_Call = NdefReadOnly;