Lines Matching defs:NdefMap
65 static NFCSTATUS phFriNfc_MifStd_H_RdABlock(phFriNfc_NdefMap_t *NdefMap);
71 static NFCSTATUS phFriNfc_MifStd_H_WrABlock(phFriNfc_NdefMap_t *NdefMap);
77 static NFCSTATUS phFriNfc_MifStd_H_AuthSector(phFriNfc_NdefMap_t *NdefMap);
83 static NFCSTATUS phFriNfc_MifStd4k_H_CheckNdef(phFriNfc_NdefMap_t *NdefMap);
88 static void phFriNfc_MifStd_H_fillAIDarray(phFriNfc_NdefMap_t *NdefMap);
100 static NFCSTATUS phFriNfc_MifStd_H_BlkChk(phFriNfc_NdefMap_t *NdefMap);
105 static NFCSTATUS phFriNfc_MifStd_H_RdAcsBit(phFriNfc_NdefMap_t *NdefMap);
110 static NFCSTATUS phFriNfc_MifStd_H_ChkAcsBit(phFriNfc_NdefMap_t *NdefMap);
116 static NFCSTATUS phFriNfc_MifStd_H_ChkRdWr(phFriNfc_NdefMap_t *NdefMap);
122 static void phFriNfc_MifStd_H_ChkNdefCmpltSects(phFriNfc_NdefMap_t *NdefMap);
129 static uint8_t phFriNfc_MifStd_H_ChkNdefLen(phFriNfc_NdefMap_t *NdefMap,
137 static NFCSTATUS phFriNfc_MifStd_H_RdNdefTLV(phFriNfc_NdefMap_t *NdefMap,
146 static NFCSTATUS phFriNfc_MifStd_H_RemainTLV(phFriNfc_NdefMap_t *NdefMap,
154 static NFCSTATUS phFriNfc_MifStd_H_ChkIntLen(phFriNfc_NdefMap_t *NdefMap);
160 static NFCSTATUS phFriNfc_MifStd_H_IntLenWioutNdef(phFriNfc_NdefMap_t *NdefMap,
168 static NFCSTATUS phFriNfc_MifStd_H_IntLenWithNdef(phFriNfc_NdefMap_t *NdefMap,
175 static uint8_t phFriNfc_MifStd_H_UpdateTLV(phFriNfc_NdefMap_t *NdefMap);
181 static NFCSTATUS phFriNfc_MifStd_H_WriteNdefLen(phFriNfc_NdefMap_t *NdefMap);
187 static NFCSTATUS phFriNfc_MifStd_H_ChkNdefCmpltBlocks(phFriNfc_NdefMap_t *NdefMap);
193 static void phFriNfc_MifStd_H_SetNdefBlkAuth(phFriNfc_NdefMap_t *NdefMap);
199 static void phFriNfc_MifStd_H_RdWrReset(phFriNfc_NdefMap_t *NdefMap);
205 static NFCSTATUS phFriNfc_MifStd_H_RdtoWrNdefLen(phFriNfc_NdefMap_t *NdefMap);
211 static NFCSTATUS phFriNfc_MifStd_H_GetActCardLen(phFriNfc_NdefMap_t *NdefMap);
217 static NFCSTATUS phFriNfc_MifStd_H_ChkTLVs(phFriNfc_NdefMap_t *NdefMap,
224 static NFCSTATUS phFriNfc_MifStd_H_GetNxtTLV(phFriNfc_NdefMap_t *NdefMap,
232 static NFCSTATUS phFriNfc_MifStd_H_Chk16Bytes(phFriNfc_NdefMap_t *NdefMap,
239 static NFCSTATUS phFriNfc_MifStd_H_ChkRemainTLVs(phFriNfc_NdefMap_t *NdefMap,
247 static void phFriNfc_MifStd_H_Complete(phFriNfc_NdefMap_t *NdefMap,
254 static void phFriNfc_MifStd_H_Get1kStTrail(phFriNfc_NdefMap_t *NdefMap);
260 static void phFriNfc_MifStd_H_Get4kStTrail(phFriNfc_NdefMap_t *NdefMap);
266 static NFCSTATUS phFriNfc_MifStd_H_ProChkNdef(phFriNfc_NdefMap_t *NdefMap);
272 static NFCSTATUS phFriNfc_MifStd_H_ProAuth(phFriNfc_NdefMap_t *NdefMap);
278 static NFCSTATUS phFriNfc_MifStd_H_Rd16Bytes(phFriNfc_NdefMap_t *NdefMap,
285 static NFCSTATUS phFriNfc_MifStd_H_ProAcsBits(phFriNfc_NdefMap_t *NdefMap);
290 static NFCSTATUS phFriNfc_MifStd_H_GPBChk(phFriNfc_NdefMap_t *NdefMap);
296 static NFCSTATUS phFriNfc_MifStd_H_ProStatNotValid(phFriNfc_NdefMap_t *NdefMap,
302 static NFCSTATUS phFriNfc_MifStd_H_RdBeforeWr(phFriNfc_NdefMap_t *NdefMap);
308 static NFCSTATUS phFriNfc_MifStd_H_ProBytesToWr(phFriNfc_NdefMap_t *NdefMap);
313 static NFCSTATUS phFriNfc_MifStd_H_fillSendBuf(phFriNfc_NdefMap_t *NdefMap,
319 static NFCSTATUS phFriNfc_MifStd_H_WrTLV(phFriNfc_NdefMap_t *NdefMap);
324 static NFCSTATUS phFriNfc_MifStd_H_ProWrTLV(phFriNfc_NdefMap_t *NdefMap);
329 static uint8_t phFriNfc_MifStd_H_UpdRemTLV(phFriNfc_NdefMap_t *NdefMap);
335 static void phFriNfc_MifStd_H_fillTLV1(phFriNfc_NdefMap_t *NdefMap);
341 static void phFriNfc_MifStd_H_fillTLV2(phFriNfc_NdefMap_t *NdefMap);
347 static NFCSTATUS phFriNfc_MifStd_H_CallWrNdefLen(phFriNfc_NdefMap_t *NdefMap);
353 static NFCSTATUS phFriNfc_MifStd_H_BlkChk_1(phFriNfc_NdefMap_t *NdefMap);
359 static void phFriNfc_MifStd_H_fillTLV1_1(phFriNfc_NdefMap_t *NdefMap);
365 static void phFriNfc_MifStd_H_fillTLV2_1(phFriNfc_NdefMap_t *NdefMap);
370 static NFCSTATUS phFriNfc_MifStd_H_RdTLV(phFriNfc_NdefMap_t *NdefMap);
375 static NFCSTATUS phFriNfc_MifStd_H_ProRdTLV(phFriNfc_NdefMap_t *NdefMap);
380 static NFCSTATUS phFriNfc_MifStd_H_WrTermTLV(phFriNfc_NdefMap_t *NdefMap);
385 static NFCSTATUS phFriNfc_MifStd_H_ProWrABlock(phFriNfc_NdefMap_t *NdefMap);
392 static NFCSTATUS phFriNfc_MifStd_H_CallPoll(phFriNfc_NdefMap_t *NdefMap);
399 static NFCSTATUS phFriNfc_MifStd_H_CallConnect(phFriNfc_NdefMap_t *NdefMap);
405 static NFCSTATUS phFriNfc_MifStd_H_CallDisCon(phFriNfc_NdefMap_t *NdefMap);
410 static void phFriNfc_MifStd1k_H_BlkChk(phFriNfc_NdefMap_t *NdefMap,
415 static NFCSTATUS phFriNfc_MifStd_H_ProSectorTrailorAcsBits(phFriNfc_NdefMap_t *NdefMap);
416 static NFCSTATUS phFriNfc_MifStd_H_WrSectorTrailorBlock(phFriNfc_NdefMap_t *NdefMap);
417 static NFCSTATUS phFriNfc_MifStd_H_ProWrSectorTrailor(phFriNfc_NdefMap_t *NdefMap);
463 NFCSTATUS phFriNfc_MifareStdMap_H_Reset(phFriNfc_NdefMap_t *NdefMap)
467 if ( NdefMap == NULL)
474 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_VAL0;
480 NdefMap->StdMifareContainer.internalBuf[index] = PH_FRINFC_MIFARESTD_VAL0;
483 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
485 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INITIALIZED;
488 NdefMap->StdMifareContainer.RemainingBufFlag = PH_FRINFC_MIFARESTD_FLAG0;
492 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
495 NdefMap->StdMifareContainer.internalBufFlag = PH_FRINFC_MIFARESTD_FLAG0;
498 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
501 NdefMap->StdMifareContainer.SectorIndex = PH_FRINFC_MIFARESTD_VAL0;
503 NdefMap->StdMifareContainer.NdefBlocks = PH_FRINFC_MIFARESTD_VAL0;
505 NdefMap->StdMifareContainer.NoOfNdefCompBlocks = PH_FRINFC_MIFARESTD_VAL0;
507 NdefMap->StdMifareContainer.ReadAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG0;
509 NdefMap->StdMifareContainer.remSizeUpdFlag = PH_FRINFC_MIFARESTD_FLAG0;
511 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_VAL0;
513 NdefMap->TLVStruct.prevLenByteValue = PH_FRINFC_MIFARESTD_VAL0;
515 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_MIFARESTD_VAL0;
517 NdefMap->TLVStruct.NdefTLVBlock = PH_FRINFC_MIFARESTD_VAL0;
519 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL0;
521 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
523 NdefMap->StdMifareContainer.remainingSize = PH_FRINFC_MIFARESTD_VAL0;
525 NdefMap->StdMifareContainer.ReadNdefFlag = PH_FRINFC_MIFARESTD_FLAG0;
527 NdefMap->StdMifareContainer.WrNdefFlag = PH_FRINFC_MIFARESTD_FLAG0;
529 NdefMap->StdMifareContainer.ChkNdefFlag = PH_FRINFC_MIFARESTD_FLAG0;
531 NdefMap->StdMifareContainer.aidCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
533 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
535 NdefMap->StdMifareContainer.ProprforumSectFlag = PH_FRINFC_MIFARESTD_PROP_1ST_CONFIG;
537 NdefMap->StdMifareContainer.ReadCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
539 NdefMap->StdMifareContainer.FirstReadFlag = PH_FRINFC_MIFARESTD_FLAG0;
541 NdefMap->StdMifareContainer.WrLength = PH_FRINFC_MIFARESTD_VAL1;
543 NdefMap->StdMifareContainer.ChkNdefCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
545 NdefMap->StdMifareContainer.ReadOnlySectorIndex = PH_FRINFC_MIFARESTD_FLAG0;
547 NdefMap->StdMifareContainer.TotalNoSectors = PH_FRINFC_MIFARESTD_FLAG0;
549 NdefMap->StdMifareContainer.SectorTrailerBlockNo = PH_FRINFC_MIFARESTD_FLAG0;
560 * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
568 NFCSTATUS phFriNfc_MifareStdMap_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
574 if ( NdefMap == NULL)
581 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
582 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
583 NdefMap->psDepAdditionalInfo.NAD = 0;
584 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_CHECK_OPE;
585 NdefMap->StdMifareContainer.CRIndex = PH_FRINFC_NDEFMAP_CR_CHK_NDEF;
590 sak = NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo106.
592 atq = NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo106.
595 sak = NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak;
596 atq = NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[0];
603 NdefMap->StdMifareContainer.NoOfNdefCompBlocks =
605 NdefMap->StdMifareContainer.remainingSize =
606 ((NdefMap->CardType == PH_FRINFC_MIFARESTD_VAL0)?
609 NdefMap->StdMifareContainer.remainingSize);
610 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD;
615 NdefMap->StdMifareContainer.NoOfNdefCompBlocks =
617 NdefMap->StdMifareContainer.remainingSize =
618 ((NdefMap->CardType == PH_FRINFC_MIFARESTD_VAL0)?
621 NdefMap->StdMifareContainer.remainingSize);
622 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD;
630 if((NdefMap->StdMifareContainer.currentBlock != 0) &&
631 (NdefMap->StdMifareContainer.currentBlock != 1) &&
632 (NdefMap->StdMifareContainer.currentBlock != 2) &&
633 (NdefMap->StdMifareContainer.currentBlock != 64) &&
634 (NdefMap->StdMifareContainer.currentBlock != 65) &&
635 (NdefMap->StdMifareContainer.currentBlock != 66) )
639 else if( NdefMap->StdMifareContainer.AuthDone == 0)
645 if(NdefMap->StdMifareContainer.currentBlock == 0)
647 NdefMap->StdMifareContainer.currentBlock = 1;
650 status = phFriNfc_MifStd_H_AuthSector(NdefMap);
656 if ((NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD) ||
657 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD))
660 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_CHK_NDEF_COMP;
661 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_CHECK_OPE;
662 NdefMap->StdMifareContainer.ChkNdefFlag = PH_FRINFC_MIFARESTD_FLAG1;
664 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
665 NdefMap->MapCompletionInfo.Context = NdefMap;
668 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareRead;
670 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
672 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
673 NdefMap->SendRecvBuf[0] = NdefMap->StdMifareContainer.currentBlock;
674 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_READ;
677 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
678 &NdefMap->MapCompletionInfo,
679 NdefMap->psRemoteDevInfo,
680 NdefMap->Cmd,
681 &NdefMap->psDepAdditionalInfo,
682 NdefMap->SendRecvBuf,
683 NdefMap->SendLength,
684 NdefMap->SendRecvBuf,
685 NdefMap->SendRecvLength);
709 NFCSTATUS phFriNfc_MifareStdMap_RdNdef( phFriNfc_NdefMap_t *NdefMap,
716 NdefMap->ApduBufferSize = *PacketDataLength;
717 NdefMap->NumOfBytesRead = PacketDataLength;
718 *NdefMap->NumOfBytesRead = 0;
719 NdefMap->ApduBuffIndex = 0;
720 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
721 NdefMap->StdMifareContainer.CRIndex = PH_FRINFC_NDEFMAP_CR_RD_NDEF;
723 if((NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID)
724 || (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INITIALIZED))
732 if( (Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN) || ( NdefMap->PrevOperation ==
735 phFriNfc_MifStd_H_RdWrReset(NdefMap);
736 NdefMap->StdMifareContainer.ReadNdefFlag = PH_FRINFC_MIFARESTD_FLAG1;
737 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
741 (NdefMap->StdMifareContainer.ReadWriteCompleteFlag ==
748 NdefMap->Offset = (((Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN) &&
749 ( NdefMap->PrevOperation ==
753 status = phFriNfc_MifStd_H_BlkChk(NdefMap);
756 NdefMap->ApduBuffer = PacketData;
759 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
763 ((NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)?
764 phFriNfc_MifStd_H_RdABlock(NdefMap):
765 phFriNfc_MifStd_H_AuthSector(NdefMap));
780 NFCSTATUS phFriNfc_MifareStdMap_WrNdef( phFriNfc_NdefMap_t *NdefMap,
787 NdefMap->ApduBuffer = PacketData;
788 NdefMap->ApduBufferSize = *PacketDataLength;
789 NdefMap->ApduBuffIndex = PH_FRINFC_MIFARESTD_VAL0;
790 NdefMap->WrNdefPacketLength = PacketDataLength;
791 *NdefMap->WrNdefPacketLength = PH_FRINFC_MIFARESTD_VAL0;
792 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
793 NdefMap->StdMifareContainer.CRIndex = PH_FRINFC_NDEFMAP_CR_WR_NDEF;
795 if((NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID)
796 || (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY))
805 (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE))
807 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
808 NdefMap->StdMifareContainer.RdBeforeWrFlag = PH_FRINFC_MIFARESTD_FLAG1;
809 NdefMap->StdMifareContainer.WrNdefFlag = PH_FRINFC_MIFARESTD_FLAG1;
810 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
811 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
812 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
813 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
814 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL0;
815 NdefMap->TLVStruct.NdefTLVAuthFlag = PH_FRINFC_MIFARESTD_FLAG0;
816 NdefMap->StdMifareContainer.FirstReadFlag = PH_FRINFC_MIFARESTD_FLAG0;
817 NdefMap->StdMifareContainer.remainingSize =
818 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks *
820 NdefMap->StdMifareContainer.currentBlock =
822 NdefMap->StdMifareContainer.NdefBlocks = PH_FRINFC_MIFARESTD_VAL1;
823 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
833 NdefMap->StdMifareContainer.PollFlag = PH_FRINFC_MIFARESTD_FLAG0;
835 NdefMap->StdMifareContainer.PollFlag = PH_FRINFC_MIFARESTD_FLAG1;
837 NdefMap->StdMifareContainer.WrLength = PH_FRINFC_MIFARESTD_VAL0;
838 NdefMap->StdMifareContainer.FirstWriteFlag = PH_FRINFC_MIFARESTD_FLAG1;
842 (NdefMap->StdMifareContainer.ReadWriteCompleteFlag ==
843 PH_FRINFC_MIFARESTD_FLAG1)) || ((NdefMap->StdMifareContainer.PollFlag ==
852 NdefMap->Offset = (((Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN) &&
853 ( NdefMap->PrevOperation ==
857 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
858 status = phFriNfc_MifStd_H_BlkChk(NdefMap);
859 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
862 if(NdefMap->StdMifareContainer.PollFlag ==
867 status = phFriNfc_MifStd_H_CallDisCon(NdefMap);
870 else if(NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)
872 status = ((NdefMap->Offset ==
874 phFriNfc_MifStd_H_RdBeforeWr(NdefMap):
875 phFriNfc_MifStd_H_WrABlock(NdefMap));
879 status = phFriNfc_MifStd_H_AuthSector(NdefMap);
900 phFriNfc_NdefMap_t *NdefMap;
908 NdefMap = (phFriNfc_NdefMap_t *)Context;
912 switch(NdefMap->State)
915 Status = phFriNfc_MifStd_H_ProChkNdef(NdefMap);
924 if((*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ) &&
925 (NdefMap->ApduBuffIndex < (uint16_t)NdefMap->ApduBufferSize))
929 if(NdefMap->TLVStruct.BytesRemainLinTLV != 0)
934 Status = phFriNfc_MifStd_H_RemainTLV(NdefMap, &NDEFFlag, &Temp16Bytes);
945 (NdefMap->TLVStruct.NdefTLVFoundFlag ==
949 Status = phFriNfc_MifStd_H_RdNdefTLV(NdefMap, &Temp16Bytes);
961 Status = phFriNfc_MifStd_H_ProWrABlock(NdefMap);
969 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
974 NdefMap->StdMifareContainer.FirstReadFlag = PH_FRINFC_MIFARESTD_FLAG0;
975 Status = phFriNfc_MifStd_H_ProAuth(NdefMap);
982 Status = phFriNfc_MifStd_H_ProAcsBits(NdefMap);
989 if(NdefMap->StdMifareContainer.RdAfterWrFlag ==
992 Status = phFriNfc_MifStd_H_CallWrNdefLen(NdefMap);
1000 if(NdefMap->StdMifareContainer.TempBlockNo ==
1001 NdefMap->StdMifareContainer.currentBlock)
1003 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
1004 NdefMap->StdMifareContainer.Buffer,
1005 NdefMap->StdMifareContainer.internalLength);
1007 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
1008 NdefMap->StdMifareContainer.currentBlock =
1009 NdefMap->StdMifareContainer.TempBlockNo;
1010 NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
1013 NdefMap->CardState);
1016 /*NdefMap->StdMifareContainer.remainingSize -=
1017 (((NdefMap->ApduBufferSize) > (PH_FRINFC_MIFARESTD_NDEFTLV_L -
1019 ((uint16_t)(*NdefMap->WrNdefPacketLength +
1021 ((uint16_t)(*NdefMap->WrNdefPacketLength +
1029 if(*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ)
1031 /* Size of NdefMap->SendRecvBuf is set by phLibNfc_Gen_NdefMapReset to PH_LIBNFC_GEN_MAX_BUFFER */
1035 NdefMap->SendRecvBuf[i] = NdefMap->SendRecvBuf[i-1];
1037 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
1038 NdefMap->StdMifareContainer.currentBlock;
1039 Status = phFriNfc_MifStd_H_WriteNdefLen(NdefMap);
1048 if(NdefMap->TLVStruct.NoLbytesinTLV > PH_FRINFC_MIFARESTD_VAL0)
1051 Status = phFriNfc_MifStd_H_ChkRemainTLVs(NdefMap, &CRFlag, &NDEFFlag);
1052 NdefMap->TLVStruct.NoLbytesinTLV =
1058 Status = phFriNfc_MifStd_H_ChkTLVs(NdefMap, &CRFlag);
1060 if(((NdefMap->StdMifareContainer.ReadNdefFlag ==
1062 (NdefMap->StdMifareContainer.WrNdefFlag ==
1066 NdefMap->StdMifareContainer.NFCforumSectFlag =
1071 if(((NdefMap->StdMifareContainer.WrNdefFlag ==
1073 (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY)) ||
1074 ((NdefMap->StdMifareContainer.ReadNdefFlag ==
1076 (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INITIALIZED)))
1081 if(NdefMap->StdMifareContainer.AuthDone ==
1084 Status = phFriNfc_MifStd_H_AuthSector(NdefMap);
1088 Status = ((NdefMap->StdMifareContainer.ReadNdefFlag ==
1090 phFriNfc_MifStd_H_RdTLV(NdefMap):
1091 phFriNfc_MifStd_H_RdBeforeWr(NdefMap));
1093 NdefMap->StdMifareContainer.ReadNdefFlag =
1095 NdefMap->StdMifareContainer.WrNdefFlag =
1099 if(NdefMap->StdMifareContainer.ChkNdefFlag ==
1110 Status = phFriNfc_MifStd_H_ProBytesToWr(NdefMap);
1117 Status = phFriNfc_MifStd_H_ProWrTLV(NdefMap);
1124 Status = phFriNfc_MifStd_H_ProRdTLV(NdefMap);
1131 phFriNfc_MifStd_H_SetNdefBlkAuth(NdefMap);
1132 NdefMap->StdMifareContainer.currentBlock =
1133 NdefMap->TLVStruct.NdefTLVBlock;
1134 Status = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
1141 NdefMap->StdMifareContainer.PollFlag = PH_FRINFC_MIFARESTD_FLAG0;
1144 Status = phFriNfc_MifStd_H_CallPoll(NdefMap);
1152 Status = phFriNfc_MifStd_H_CallConnect(NdefMap);
1159 if(NdefMap->StdMifareContainer.FirstReadFlag == PH_FRINFC_MIFARESTD_FLAG1)
1161 NdefMap->StdMifareContainer.FirstReadFlag = PH_FRINFC_MIFARESTD_FLAG0;
1162 NdefMap);
1164 else if((NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD ||
1165 NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD) &&
1166 (NdefMap->StdMifareContainer.ReadOnlySectorIndex &&
1167 NdefMap->StdMifareContainer.SectorTrailerBlockNo == NdefMap->StdMifareContainer.currentBlock))
1169 NdefMap->StdMifareContainer.ReadOnlySectorIndex =
1171 NdefMap->StdMifareContainer.SectorTrailerBlockNo =
1173 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_FLAG0;
1178 Status = ((((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) &&
1179 (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_WRITE_OPE)) ||
1180 (NdefMap->StdMifareContainer.WrLength >
1182 phFriNfc_MifStd_H_ProStatNotValid(NdefMap, Status):
1183 phFriNfc_MifStd_H_AuthSector(NdefMap));
1191 Status = phFriNfc_MifStd_H_ProSectorTrailorAcsBits(NdefMap);
1196 (NdefMap->StdMifareContainer.WriteAcsBitFlag == PH_FRINFC_MIFARESTD_FLAG0))
1205 NdefMap->StdMifareContainer.WriteAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG1;
1209 if(NdefMap->CardState != PH_NDEFMAP_CARD_STATE_READ_ONLY)
1211 Status = phFriNfc_MapTool_SetCardState(NdefMap, NdefMap->TLVStruct.BytesRemainLinTLV);
1220 Status = phFriNfc_MifStd_H_ProWrSectorTrailor(NdefMap);
1234 else if(NdefMap->State == PH_FRINFC_NDEFMAP_STATE_AUTH)
1236 NdefMap->StdMifareContainer.PollFlag = PH_FRINFC_MIFARESTD_FLAG1;
1237 if(NdefMap->StdMifareContainer.FirstWriteFlag ==
1240 NdefMap->StdMifareContainer.FirstWriteFlag =
1242 NdefMap->StdMifareContainer.WrLength =
1243 ((NdefMap->StdMifareContainer.NFCforumSectFlag ==
1246 NdefMap->StdMifareContainer.WrLength);
1248 /*if(NdefMap->StdMifareContainer.WrLength != PH_FRINFC_MIFARESTD_VAL0)
1251 NdefMap->StdMifareContainer.ReadCompleteFlag =
1253 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
1256 else*/ if(NdefMap->StdMifareContainer.WrLength == PH_FRINFC_MIFARESTD_VAL0)
1265 Status = phFriNfc_MifStd_H_CallDisCon(NdefMap);
1280 phFriNfc_MifStd_H_Complete(NdefMap, Status);
1284 static NFCSTATUS phFriNfc_MifStd_H_RdABlock(phFriNfc_NdefMap_t *NdefMap)
1289 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
1290 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
1291 NdefMap->psDepAdditionalInfo.NAD = 0;
1293 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_READ;
1294 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
1295 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
1296 NdefMap->MapCompletionInfo.Context = NdefMap;
1298 if( NdefMap->ApduBuffIndex <
1299 (uint16_t)NdefMap->ApduBufferSize)
1302 if(NdefMap->StdMifareContainer.internalLength > PH_FRINFC_MIFARESTD_VAL0)
1304 status = phFriNfc_MifStd_H_ChkIntLen(NdefMap);
1308 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
1309 NdefMap->StdMifareContainer.currentBlock;
1310 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_READ;
1311 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1314 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareRead;
1316 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
1319 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1320 &NdefMap->MapCompletionInfo,
1321 NdefMap->psRemoteDevInfo,
1322 NdefMap->Cmd,
1323 &NdefMap->psDepAdditionalInfo,
1324 NdefMap->SendRecvBuf,
1325 NdefMap->SendLength,
1326 NdefMap->SendRecvBuf,
1327 NdefMap->SendRecvLength);
1333 if((((NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
1334 NdefMap->StdMifareContainer.NdefBlocks) *
1336 (NdefMap->ApduBufferSize == NdefMap->ApduBuffIndex))
1338 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
1339 (uint8_t)((((NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
1340 NdefMap->StdMifareContainer.NdefBlocks) *
1344 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
1363 static NFCSTATUS phFriNfc_MifStd_H_WrABlock(phFriNfc_NdefMap_t *NdefMap)
1374 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
1375 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
1376 NdefMap->psDepAdditionalInfo.NAD = 0;
1377 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
1378 NdefMap->MapCompletionInfo.Context = NdefMap;
1379 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
1381 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_WRITE;
1384 if( NdefMap->ApduBuffIndex <
1385 (uint16_t)NdefMap->ApduBufferSize)
1387 RemainingBytes = (((uint16_t)(NdefMap->ApduBufferSize -
1388 NdefMap->ApduBuffIndex) <
1389 NdefMap->StdMifareContainer.remainingSize )?
1390 (uint16_t)(NdefMap->ApduBufferSize -
1391 NdefMap->ApduBuffIndex):
1392 NdefMap->StdMifareContainer.remainingSize);
1394 NdefMap->SendRecvBuf[0] = NdefMap->StdMifareContainer.currentBlock;
1398 if(NdefMap->StdMifareContainer.internalLength > 0)
1401 (void)memcpy(&( NdefMap->SendRecvBuf[Temp16Bytes]),
1402 NdefMap->StdMifareContainer.internalBuf,
1403 NdefMap->StdMifareContainer.internalLength);
1405 Temp16Bytes += (uint8_t)(NdefMap->StdMifareContainer.internalLength);
1411 (void)memcpy(&(NdefMap->SendRecvBuf[Temp16Bytes]),
1412 NdefMap->ApduBuffer,
1415 NdefMap->NumOfBytesWritten =
1418 *NdefMap->DataCount = (Temp16Bytes - PH_FRINFC_MIFARESTD_VAL1);
1422 (void)memcpy(&(NdefMap->SendRecvBuf[Temp16Bytes]),
1423 NdefMap->ApduBuffer,
1426 NdefMap->StdMifareContainer.internalBufFlag = PH_FRINFC_MIFARESTD_FLAG1;
1427 NdefMap->NumOfBytesWritten = RemainingBytes;
1429 *NdefMap->DataCount = (Temp16Bytes - PH_FRINFC_MIFARESTD_VAL1);
1435 NdefMap->SendRecvBuf[(Temp16Bytes + index)] =
1439 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
1450 (void)memcpy( &(NdefMap->SendRecvBuf[
1452 &(NdefMap->ApduBuffer[
1453 NdefMap->ApduBuffIndex]),
1456 NdefMap->NumOfBytesWritten = (MIFARE_MAX_SEND_BUF_TO_WRITE - Temp16Bytes);
1458 *NdefMap->DataCount = (Temp16Bytes - PH_FRINFC_MIFARESTD_VAL1);
1464 (void)memcpy(&(NdefMap->SendRecvBuf[
1466 &(NdefMap->ApduBuffer[
1467 NdefMap->ApduBuffIndex]),
1470 NdefMap->StdMifareContainer.RemainingBufFlag = PH_FRINFC_MIFARESTD_FLAG1;
1471 NdefMap->NumOfBytesWritten = RemainingBytes;
1473 *NdefMap->DataCount = (Temp16Bytes - PH_FRINFC_MIFARESTD_VAL1);
1479 NdefMap->SendRecvBuf[index] = (uint8_t)((index ==
1484 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
1489 (void)memcpy( NdefMap->StdMifareContainer.Buffer,
1490 &(NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_INC_1]),
1494 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_WRITE;
1496 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareWrite16;
1498 NdefMap->Cmd.MfCmd = phHal_eMifareWrite16;
1500 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1502 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1503 &NdefMap->MapCompletionInfo,
1504 NdefMap->psRemoteDevInfo,
1505 NdefMap->Cmd,
1506 &NdefMap->psDepAdditionalInfo,
1507 NdefMap->SendRecvBuf,
1508 NdefMap->SendLength,
1509 NdefMap->SendRecvBuf,
1510 NdefMap->SendRecvLength);
1514 if(NdefMap->StdMifareContainer.NdefBlocks >
1515 NdefMap->StdMifareContainer.NoOfNdefCompBlocks)
1517 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
1522 else if( NdefMap->ApduBuffIndex ==
1523 (uint16_t)NdefMap->ApduBufferSize)
1542 static NFCSTATUS phFriNfc_MifStd_H_AuthSector(phFriNfc_NdefMap_t *NdefMap)
1547 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
1548 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
1549 NdefMap->psDepAdditionalInfo.NAD = 0;
1550 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
1551 NdefMap->MapCompletionInfo.Context = NdefMap;
1553 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1554 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_AUTH;
1558 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareAuthentA;
1560 NdefMap->Cmd.MfCmd = phHal_eMifareAuthentA;
1562 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
1563 ((NdefMap->TLVStruct.NdefTLVAuthFlag ==
1565 NdefMap->TLVStruct.NdefTLVBlock:
1566 NdefMap->StdMifareContainer.currentBlock);
1571 if(( (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK0) &&
1572 (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK1) &&
1573 (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK2) &&
1574 (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK64) &&
1575 (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK65) &&
1576 (NdefMap->StdMifareContainer.currentBlock != PH_FRINFC_MIFARESTD_MAD_BLK66)) ||
1577 (NdefMap->TLVStruct.NdefTLVAuthFlag ==
1580 NdefMap->SendRecvBuf[1] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
1581 NdefMap->SendRecvBuf[2] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
1582 NdefMap->SendRecvBuf[3] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
1583 NdefMap->SendRecvBuf[4] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
1584 NdefMap->SendRecvBuf[5] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
1585 NdefMap->SendRecvBuf[6] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
1589 NdefMap->SendRecvBuf[1] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT1; /* 0xA0 */
1590 NdefMap->SendRecvBuf[2] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT2; /* 0xA1 */
1591 NdefMap->SendRecvBuf[3] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT3; /* 0xA2 */
1592 NdefMap->SendRecvBuf[4] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT4; /* 0xA3 */
1593 NdefMap->SendRecvBuf[5] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT5; /* 0xA4 */
1594 NdefMap->SendRecvBuf[6] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_MADSECT6; /* 0xA5 */
1597 if (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD ||
1598 NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD)
1600 if (NdefMap->StdMifareContainer.ReadOnlySectorIndex &&
1601 NdefMap->StdMifareContainer.SectorTrailerBlockNo == NdefMap->StdMifareContainer.currentBlock)
1603 memcpy (&NdefMap->SendRecvBuf[1], &NdefMap->StdMifareContainer.UserScrtKeyB[0], PH_FRINFC_MIFARESTD_KEY_LEN);
1607 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareAuthentB;
1609 NdefMap->Cmd.MfCmd = phHal_eMifareAuthentB;
1614 NdefMap->SendLength = MIFARE_AUTHENTICATE_CMD_LENGTH;
1615 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1617 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1618 &NdefMap->MapCompletionInfo,
1619 NdefMap->psRemoteDevInfo,
1620 NdefMap->Cmd,
1621 &NdefMap->psDepAdditionalInfo,
1622 NdefMap->SendRecvBuf,
1623 NdefMap->SendLength,
1624 NdefMap->SendRecvBuf,
1625 NdefMap->SendRecvLength);
1630 static void phFriNfc_MifStd_H_Complete(phFriNfc_NdefMap_t *NdefMap,
1634 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
1637 NdefMap->CompletionRoutine[NdefMap->StdMifareContainer.CRIndex].
1638 CompletionRoutine(NdefMap->CompletionRoutine->Context, Result);
1641 static NFCSTATUS phFriNfc_MifStd4k_H_CheckNdef(phFriNfc_NdefMap_t *NdefMap)
1646 if(NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK2)
1648 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_MAD_BLK64;
1649 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
1651 else if(NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK64)
1653 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_MAD_BLK65;
1657 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_MAD_BLK66;
1660 Result = phFriNfc_MifareStdMap_ChkNdef(NdefMap);
1666 static void phFriNfc_MifStd_H_fillAIDarray(phFriNfc_NdefMap_t *NdefMap)
1670 if( (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK1) ||
1671 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK64))
1676 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.SectorIndex] =
1678 NdefMap->StdMifareContainer.SectorIndex++;
1684 if((NdefMap->SendRecvBuf[byteindex] == PH_FRINFC_NDEFMAP_MIFARESTD_NDEF_COMPVAL2) &&
1685 (NdefMap->SendRecvBuf[(byteindex + 1)] == PH_FRINFC_NDEFMAP_MIFARESTD_NDEF_COMPVAL1))
1689 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG1;
1690 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.SectorIndex] =
1692 NdefMap->StdMifareContainer.SectorIndex++;
1696 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.SectorIndex] =
1698 NdefMap->StdMifareContainer.SectorIndex++;
1702 NdefMap->StdMifareContainer.aidCompleteFlag =
1703 ((NdefMap->StdMifareContainer.NFCforumSectFlag ==
1708 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
1709 if(NdefMap->StdMifareContainer.aidCompleteFlag == PH_FRINFC_MIFARESTD_FLAG1)
1719 if((NdefMap->StdMifareContainer.aidCompleteFlag == PH_FRINFC_MIFARESTD_FLAG1) &&
1720 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD))
1724 for(byteindex = NdefMap->StdMifareContainer.SectorIndex;
1728 NdefMap->StdMifareContainer.aid[byteindex] =
1734 else if((NdefMap->StdMifareContainer.aidCompleteFlag == PH_FRINFC_MIFARESTD_FLAG1) &&
1735 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))
1737 for(byteindex = NdefMap->StdMifareContainer.SectorIndex;
1741 NdefMap->StdMifareContainer.aid[byteindex] =
1747 static NFCSTATUS phFriNfc_MifStd_H_BlkChk(phFriNfc_NdefMap_t *NdefMap)
1755 SectorID = phFriNfc_MifStd_H_GetSect(NdefMap->StdMifareContainer.currentBlock);
1758 if(NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD)
1763 SectorID = phFriNfc_MifStd_H_GetSect(NdefMap->StdMifareContainer.currentBlock);
1771 phFriNfc_MifStd1k_H_BlkChk(NdefMap, SectorID, &callbreak);
1784 else if(NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK64)
1786 NdefMap->StdMifareContainer.currentBlock += PH_FRINFC_MIFARESTD_BLK4;
1792 if(NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK63)
1794 NdefMap->StdMifareContainer.currentBlock += PH_FRINFC_MIFARESTD_BLK4;
1798 phFriNfc_MifStd1k_H_BlkChk(NdefMap, SectorID, &callbreak);
1804 if(((NdefMap->StdMifareContainer.currentBlock + 1) %
1807 NdefMap->StdMifareContainer.currentBlock++;
1811 if(NdefMap->StdMifareContainer.aid[SectorID] ==
1820 if((NdefMap->StdMifareContainer.currentBlock ==
1823 (NdefMap->StdMifareContainer.internalLength == 0))
1825 NdefMap->StdMifareContainer.AuthDone = 0;
1831 NdefMap->StdMifareContainer.currentBlock += 16;
1862 static NFCSTATUS phFriNfc_MifStd_H_RdAcsBit(phFriNfc_NdefMap_t *NdefMap)
1865 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RD_ACS_BIT;
1867 if( NdefMap->StdMifareContainer.ReadOnlySectorIndex &&
1868 NdefMap->StdMifareContainer.currentBlock == NdefMap->StdMifareContainer.SectorTrailerBlockNo)
1870 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RD_SEC_ACS_BIT;
1873 if(NdefMap->StdMifareContainer.ReadAcsBitFlag == PH_FRINFC_MIFARESTD_FLAG1)
1876 ((NdefMap->StdMifareContainer.currentBlock > 127)?
1877 phFriNfc_MifStd_H_Get4kStTrail(NdefMap):
1878 phFriNfc_MifStd_H_Get1kStTrail(NdefMap));
1883 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
1884 NdefMap->StdMifareContainer.currentBlock;
1887 Result = phFriNfc_MifStd_H_Rd16Bytes(NdefMap,
1888 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0]);
1893 static NFCSTATUS phFriNfc_MifStd_H_ChkAcsBit(phFriNfc_NdefMap_t *NdefMap)
1898 if((NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK0) ||
1899 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK1) ||
1900 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK2) ||
1901 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK3) ||
1902 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK64) ||
1903 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK65) ||
1904 (NdefMap->StdMifareContainer.currentBlock == PH_FRINFC_MIFARESTD_MAD_BLK66) )
1909 if(((NdefMap->SendRecvBuf[
1913 ((NdefMap->SendRecvBuf[
1917 ((NdefMap->SendRecvBuf[
1922 NdefMap->StdMifareContainer.WriteFlag =
1924 NdefMap->StdMifareContainer.ReadFlag =
1929 NdefMap->StdMifareContainer.WriteFlag =
1931 NdefMap->StdMifareContainer.ReadFlag =
1937 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INITIALIZED;
1945 if(((NdefMap->SendRecvBuf[
1949 ((NdefMap->SendRecvBuf[
1953 ((NdefMap->SendRecvBuf[
1958 NdefMap->StdMifareContainer.WriteFlag =
1960 NdefMap->StdMifareContainer.ReadFlag =
1963 else if(((NdefMap->SendRecvBuf[
1967 ((NdefMap->SendRecvBuf[
1971 ((NdefMap->SendRecvBuf[
1979 NdefMap->StdMifareContainer.WriteFlag =
1981 NdefMap->StdMifareContainer.ReadFlag =
1986 NdefMap->StdMifareContainer.WriteFlag =
1988 NdefMap->StdMifareContainer.ReadFlag =
1998 Result = phFriNfc_MifStd_H_GPBChk(NdefMap);
2006 Result = phFriNfc_MifStd_H_GPBChk(NdefMap);
2013 static NFCSTATUS phFriNfc_MifStd_H_ChkRdWr(phFriNfc_NdefMap_t *NdefMap)
2016 switch(NdefMap->PrevOperation)
2019 if(NdefMap->CardState ==
2026 else if((NdefMap->StdMifareContainer.currentBlock > 3) &&
2027 (NdefMap->StdMifareContainer.ChkNdefCompleteFlag ==
2029 (NdefMap->StdMifareContainer.currentBlock !=
2031 (NdefMap->StdMifareContainer.currentBlock !=
2034 /* NdefMap->StdMifareContainer.currentBlock =
2035 ((NdefMap->StdMifareContainer.ReadCompleteFlag ==
2037 NdefMap->StdMifareContainer.currentBlock:
2038 (NdefMap->StdMifareContainer.currentBlock +
2040 NdefMap->StdMifareContainer.currentBlock =
2041 ((NdefMap->StdMifareContainer.currentBlock ==
2043 (NdefMap->StdMifareContainer.currentBlock +
2045 NdefMap->StdMifareContainer.currentBlock);*/
2047 Result = ((NdefMap->StdMifareContainer.ReadAcsBitFlag ==
2049 phFriNfc_MifStd_H_RdAcsBit(NdefMap):
2050 phFriNfc_MifStd_H_AuthSector(NdefMap));
2054 Result = phFriNfc_MifareStdMap_ChkNdef(NdefMap);
2059 if(NdefMap->CardState ==
2066 else if(NdefMap->StdMifareContainer.ReadNdefFlag ==
2069 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
2073 Result = phFriNfc_MifStd_H_RdABlock(NdefMap);
2078 if((NdefMap->CardState ==
2080 (NdefMap->CardState ==
2087 else if(NdefMap->StdMifareContainer.WrNdefFlag ==
2090 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
2092 else if(NdefMap->StdMifareContainer.RdBeforeWrFlag ==
2095 /*NdefMap->StdMifareContainer.ReadFlag =
2097 Result = phFriNfc_MifStd_H_RdBeforeWr(NdefMap);
2099 else if(NdefMap->StdMifareContainer.RdAfterWrFlag ==
2102 Result = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
2106 Result = (((NdefMap->TLVStruct.NdefTLVBlock ==
2107 NdefMap->StdMifareContainer.currentBlock) &&
2108 (NdefMap->Offset ==
2110 phFriNfc_MifStd_H_RdBeforeWr(NdefMap):
2111 phFriNfc_MifStd_H_WrABlock(NdefMap));
2116 Result = ((NdefMap->StdMifareContainer.ReadFlag ==
2120 phFriNfc_MifStd_H_GetActCardLen(NdefMap));
2133 static void phFriNfc_MifStd_H_ChkNdefCmpltSects(phFriNfc_NdefMap_t *NdefMap)
2136 if(NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD)
2145 && (NdefMap->StdMifareContainer.aid[index] ==
2149 NdefMap->StdMifareContainer.NoOfNdefCompBlocks -=
2156 if(NdefMap->StdMifareContainer.aid[index] ==
2160 NdefMap->StdMifareContainer.NoOfNdefCompBlocks -=
2172 if(NdefMap->StdMifareContainer.aid[index] ==
2178 NdefMap->StdMifareContainer.NoOfNdefCompBlocks -=
2186 static uint8_t phFriNfc_MifStd_H_ChkNdefLen(phFriNfc_NdefMap_t *NdefMap,
2194 TempLength = ((NdefMap->StdMifareContainer.internalLength > 0)?
2195 NdefMap->StdMifareContainer.internalLength :
2198 if(NdefMap->StdMifareContainer.internalLength > 0)
2201 NdefMap->StdMifareContainer.internalBuf,
2207 NdefMap->SendRecvBuf,
2212 if(NdefMap->TLVStruct.NoLbytesinTLV != PH_FRINFC_MIFARESTD_VAL0)
2214 switch(NdefMap->TLVStruct.NoLbytesinTLV)
2220 NdefMap->TLVStruct.BytesRemainLinTLV = *TempBuffer;
2221 NdefMap->TLVStruct.BytesRemainLinTLV =
2222 ((NdefMap->TLVStruct.BytesRemainLinTLV
2226 *CRFlag = (uint8_t)((NdefMap->TLVStruct.BytesRemainLinTLV <
2230 NdefMap->TLVStruct.BytesRemainLinTLV = ((*CRFlag ==
2233 NdefMap->TLVStruct.BytesRemainLinTLV);
2240 NdefMap->TLVStruct.BytesRemainLinTLV =
2241 NdefMap->TLVStruct.prevLenByteValue;
2243 NdefMap->TLVStruct.BytesRemainLinTLV =
2244 ((NdefMap->TLVStruct.BytesRemainLinTLV
2246 *CRFlag = (uint8_t)((NdefMap->TLVStruct.BytesRemainLinTLV <
2251 NdefMap->TLVStruct.BytesRemainLinTLV = ((*CRFlag ==
2254 NdefMap->TLVStruct.BytesRemainLinTLV);
2260 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_NDEFTLV_LBYTES0;
2261 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2262 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2269 NdefMap->TLVStruct.BytesRemainLinTLV =
2273 NdefMap->TLVStruct.TcheckedinTLVFlag = (((NDEFlength + PH_FRINFC_MIFARESTD_INC_1)
2278 NdefMap->TLVStruct.LcheckedinTLVFlag = (((NDEFlength + PH_FRINFC_MIFARESTD_INC_1)
2290 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_VAL2;
2292 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
2293 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2300 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_VAL1;
2302 NdefMap
2303 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2305 NdefMap->TLVStruct.prevLenByteValue =
2306 NdefMap->SendRecvBuf[(NDEFlength + PH_FRINFC_MIFARESTD_INC_1)];
2311 NdefMap->TLVStruct.TcheckedinTLVFlag = (((NDEFlength + PH_FRINFC_MIFARESTD_INC_3)
2317 NdefMap->TLVStruct.LcheckedinTLVFlag = (((NDEFlength + PH_FRINFC_MIFARESTD_INC_1)
2323 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_VAL0;
2327 NdefMap->TLVStruct.BytesRemainLinTLV =
2331 NdefMap->TLVStruct.BytesRemainLinTLV =
2332 ((NdefMap->TLVStruct.BytesRemainLinTLV
2336 *CRFlag = (uint8_t)((NdefMap->TLVStruct.BytesRemainLinTLV <
2346 static NFCSTATUS phFriNfc_MifStd_H_RdNdefTLV(phFriNfc_NdefMap_t *NdefMap,
2355 while(PH_FRINFC_MIFARESTD_FLAG1 == NdefMap->TLVStruct.NdefTLVFoundFlag)
2357 RemainingBytes = ((uint16_t)NdefMap->ApduBufferSize -
2358 NdefMap->ApduBuffIndex);
2359 if(((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
2360 NdefMap->StdMifareContainer.NdefBlocks) *
2368 RemainingBytes = ((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
2369 NdefMap->StdMifareContainer.NdefBlocks) * 16) +
2370 NdefMap->StdMifareContainer.internalLength);
2374 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
2376 if((NdefMap->TLVStruct.TcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1) &&
2377 (NdefMap->TLVStruct.LcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1) &&
2378 (NdefMap->TLVStruct.NoLbytesinTLV != PH_FRINFC_MIFARESTD_NDEFTLV_LBYTES0))
2388 if(NdefMap->TLVStruct.TcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1)
2390 CRFlag = ((NdefMap->SendRecvBuf[(*Temp16Bytes)]!=
2397 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
2407 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2412 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2413 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
2415 NdefMap->StdMifareContainer.currentBlock++;
2416 NdefMap->StdMifareContainer.NdefBlocks++;
2417 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2420 if(NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)
2422 Result = phFriNfc_MifStd_H_RdABlock(NdefMap);
2426 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
2432 if(NdefMap->TLVStruct.LcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1)
2434 /*CRFlag = (((*(NdefMap->SendRecvBuf + *Temp16Bytes) ==
2436 (NdefMap->TLVStruct.NoLbytesinTLV ==
2442 *Temp16Bytes += phFriNfc_MifStd_H_ChkNdefLen(NdefMap,
2447 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
2455 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2460 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2461 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
2463 NdefMap->StdMifareContainer.currentBlock++;
2464 NdefMap->StdMifareContainer.NdefBlocks++;
2465 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2468 if(NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)
2470 Result = phFriNfc_MifStd_H_RdABlock(NdefMap);
2474 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
2480 if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2483 NdefMap->TLVStruct.BytesRemainLinTLV))
2486 (void)memcpy(&(NdefMap->ApduBuffer[
2487 NdefMap->ApduBuffIndex]),
2488 &(NdefMap->SendRecvBuf[
2491 NdefMap->ApduBuffIndex += RemainingBytes;
2493 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
2495 if(NdefMap->TLVStruct.BytesRemainLinTLV == 0)
2497 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2498 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2499 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2505 (void)memcpy(NdefMap->StdMifareContainer.internalBuf,
2506 &(NdefMap->SendRecvBuf[(*Temp16Bytes)]),
2510 NdefMap->StdMifareContainer.internalLength =
2516 else if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2519 NdefMap->TLVStruct.BytesRemainLinTLV))
2522 (void)memcpy(&(NdefMap->ApduBuffer[
2523 NdefMap->ApduBuffIndex]),
2524 &(NdefMap->SendRecvBuf[
2526 NdefMap->TLVStruct.BytesRemainLinTLV);
2528 NdefMap->ApduBuffIndex += NdefMap->TLVStruct.BytesRemainLinTLV;
2529 *Temp16Bytes += ((uint8_t)NdefMap->TLVStruct.BytesRemainLinTLV);
2530 NdefMap->TLVStruct.BytesRemainLinTLV = 0;
2531 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2532 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2533 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2539 NdefMap->StdMifareContainer.currentBlock++;
2540 NdefMap->StdMifareContainer.NdefBlocks++;
2541 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2544 if(NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)
2546 Result = phFriNfc_MifStd_H_RdABlock(NdefMap);
2550 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
2556 else if((NdefMap->TLVStruct.BytesRemainLinTLV >
2562 (void)memcpy(&(NdefMap->ApduBuffer[
2563 NdefMap->ApduBuffIndex]),
2564 &(NdefMap->SendRecvBuf[
2567 NdefMap->ApduBuffIndex += RemainingBytes;
2568 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
2571 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
2572 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
2573 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
2578 NdefMap->StdMifareContainer.currentBlock++;
2579 NdefMap->StdMifareContainer.NdefBlocks++;
2585 (void)memcpy(NdefMap->StdMifareContainer.internalBuf,
2586 &(NdefMap->SendRecvBuf[((*Temp16Bytes) + RemainingBytes)]),
2591 NdefMap->StdMifareContainer.internalLength =
2601 if((NdefMap->TLVStruct.BytesRemainLinTLV >
2607 (void)memcpy(&(NdefMap->ApduBuffer[
2608 NdefMap->ApduBuffIndex]),
2609 &(NdefMap->SendRecvBuf[
2612 NdefMap->ApduBuffIndex += (PH_FRINFC_MIFARESTD_BYTES_READ - *Temp16Bytes);
2613 NdefMap->TLVStruct.BytesRemainLinTLV -=
2619 NdefMap->StdMifareContainer.currentBlock++;
2620 NdefMap->StdMifareContainer.NdefBlocks++;
2621 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2624 Result = ((NdefMap->StdMifareContainer.AuthDone ==
2626 phFriNfc_MifStd_H_RdABlock(NdefMap):
2627 phFriNfc_MifStd_H_AuthSector(NdefMap));
2637 (NdefMap->ApduBuffIndex == PH_FRINFC_MIFARESTD_VAL0))?
2641 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
2642 phFriNfc_MifStd_H_Complete(NdefMap, Result);
2648 static NFCSTATUS phFriNfc_MifStd_H_RemainTLV(phFriNfc_NdefMap_t *NdefMap,
2656 RemainingBytes = ((uint16_t)NdefMap->ApduBufferSize -
2657 NdefMap->ApduBuffIndex);
2659 if(NdefMap->StdMifareContainer.remainingSize <
2665 RemainingBytes = NdefMap->StdMifareContainer.remainingSize;
2669 if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2671 (RemainingBytes <= NdefMap->TLVStruct.BytesRemainLinTLV))
2674 (void)memcpy(&(NdefMap->ApduBuffer[
2675 NdefMap->ApduBuffIndex]),
2676 &(NdefMap->SendRecvBuf[
2679 NdefMap->ApduBuffIndex += RemainingBytes;
2680 NdefMap->StdMifareContainer.remainingSize -= RemainingBytes;
2684 if(RemainingBytes != NdefMap->TLVStruct.BytesRemainLinTLV)
2686 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
2688 &(NdefMap->SendRecvBuf[((*Temp16Bytes) + RemainingBytes)]),
2690 &(NdefMap->SendRecvBuf[RemainingBytes]),
2696 NdefMap->StdMifareContainer.internalLength =
2702 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
2704 if(NdefMap->StdMifareContainer.internalLength == PH_FRINFC_MIFARESTD_VAL0)
2706 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
2707 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
2708 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
2713 NdefMap->StdMifareContainer.currentBlock++;
2714 NdefMap->StdMifareContainer.NdefBlocks++;
2717 if(NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0)
2721 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2722 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2723 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2729 else if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2731 (RemainingBytes > NdefMap->TLVStruct.BytesRemainLinTLV))
2734 (void)memcpy(&(NdefMap->ApduBuffer[
2735 NdefMap->ApduBuffIndex]),
2736 &(NdefMap->SendRecvBuf[
2738 NdefMap->TLVStruct.BytesRemainLinTLV);
2739 NdefMap->ApduBuffIndex += NdefMap->TLVStruct.BytesRemainLinTLV;
2740 NdefMap->StdMifareContainer.remainingSize -=
2741 NdefMap->TLVStruct.BytesRemainLinTLV;
2742 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2743 *Temp16Bytes += ((uint8_t)NdefMap->TLVStruct.BytesRemainLinTLV);
2744 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_MIFARESTD_VAL0;
2748 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2749 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2751 if(NdefMap->TLVStruct.BytesRemainLinTLV ==
2755 NdefMap->TLVStruct.BytesRemainLinTLV =
2757 NdefMap->StdMifareContainer.currentBlock++;
2758 NdefMap->StdMifareContainer.NdefBlocks++;
2759 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2762 if(NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)
2764 Result = phFriNfc_MifStd_H_RdABlock(NdefMap);
2768 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
2774 NdefMap->TLVStruct.BytesRemainLinTLV =
2781 else if((NdefMap->TLVStruct.BytesRemainLinTLV >
2786 (void)memcpy(&(NdefMap->ApduBuffer[
2787 NdefMap->ApduBuffIndex]),
2788 &(NdefMap->SendRecvBuf[
2791 NdefMap->ApduBuffIndex += RemainingBytes;
2792 NdefMap->StdMifareContainer.remainingSize -= RemainingBytes;
2795 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
2811 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
2812 &(NdefMap->SendRecvBuf[(RemainingBytes + (*Temp16Bytes))]),
2817 NdefMap->StdMifareContainer.internalLength =
2822 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
2823 &(NdefMap->SendRecvBuf[RemainingBytes]),
2828 NdefMap->StdMifareContainer.internalLength =
2834 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
2835 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
2836 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
2841 NdefMap->StdMifareContainer.currentBlock++;
2842 NdefMap->StdMifareContainer.NdefBlocks++;
2845 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
2851 if((NdefMap->TLVStruct.BytesRemainLinTLV >
2857 (void)memcpy(&(NdefMap->ApduBuffer
2858 [NdefMap->ApduBuffIndex]),
2859 &(NdefMap->SendRecvBuf[
2862 NdefMap->ApduBuffIndex += (PH_FRINFC_MIFARESTD_BYTES_READ - (*Temp16Bytes));
2863 NdefMap->StdMifareContainer.remainingSize -=
2865 NdefMap->TLVStruct.BytesRemainLinTLV -= (PH_FRINFC_MIFARESTD_BYTES_READ - (*Temp16Bytes));
2867 if(NdefMap->TLVStruct.BytesRemainLinTLV != PH_FRINFC_MIFARESTD_NDEFTLV_LBYTES0)
2869 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
2872 NdefMap->StdMifareContainer.currentBlock++;
2873 NdefMap->StdMifareContainer.NdefBlocks++;
2874 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
2877 Result = ((NdefMap->StdMifareContainer.AuthDone ==
2879 phFriNfc_MifStd_H_RdABlock(NdefMap):
2880 phFriNfc_MifStd_H_AuthSector(NdefMap));
2887 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
2888 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
2889 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
2890 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
2898 static NFCSTATUS phFriNfc_MifStd_H_ChkIntLen(phFriNfc_NdefMap_t *NdefMap)
2904 if(NdefMap->TLVStruct.BytesRemainLinTLV != 0)
2908 Result = phFriNfc_MifStd_H_IntLenWioutNdef(NdefMap, &NDEFFlag, &TempintBytes);
2916 (NdefMap->TLVStruct.NdefTLVFoundFlag ==
2920 Result = phFriNfc_MifStd_H_IntLenWithNdef(NdefMap, &TempintBytes);
2926 static NFCSTATUS phFriNfc_MifStd_H_IntLenWioutNdef(phFriNfc_NdefMap_t *NdefMap,
2934 RemainingBytes = ((uint16_t)NdefMap->ApduBufferSize -
2935 NdefMap->ApduBuffIndex);
2937 if(NdefMap->StdMifareContainer.remainingSize <
2943 RemainingBytes = NdefMap->StdMifareContainer.remainingSize;
2947 if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2948 NdefMap->StdMifareContainer.internalLength) &&
2949 (RemainingBytes <= NdefMap->TLVStruct.BytesRemainLinTLV))
2951 (void)memcpy(&(NdefMap->ApduBuffer[
2952 NdefMap->ApduBuffIndex]),
2953 &(NdefMap->StdMifareContainer.internalBuf[
2956 NdefMap->ApduBuffIndex += RemainingBytes;
2957 NdefMap->StdMifareContainer.remainingSize -= RemainingBytes;
2962 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
2963 &(NdefMap->StdMifareContainer.internalBuf[RemainingBytes]),
2964 (NdefMap->StdMifareContainer.internalLength - RemainingBytes));
2967 NdefMap->StdMifareContainer.internalLength -= RemainingBytes;
2969 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
2970 if(NdefMap->StdMifareContainer.internalLength == PH_FRINFC_MIFARESTD_VAL0)
2972 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
2973 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
2974 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
2979 NdefMap->StdMifareContainer.currentBlock++;
2980 NdefMap->StdMifareContainer.NdefBlocks++;
2984 if(NdefMap->TLVStruct.BytesRemainLinTLV == 0)
2988 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
2989 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2990 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
2996 else if((NdefMap->TLVStruct.BytesRemainLinTLV <=
2997 NdefMap->StdMifareContainer.internalLength) &&
2998 (RemainingBytes > NdefMap->TLVStruct.BytesRemainLinTLV))
3000 (void)memcpy(&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex]),
3001 &(NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]),
3002 NdefMap->TLVStruct.BytesRemainLinTLV);
3004 NdefMap->ApduBuffIndex += NdefMap->TLVStruct.BytesRemainLinTLV;
3005 NdefMap->StdMifareContainer.remainingSize -=
3006 NdefMap->TLVStruct.BytesRemainLinTLV;
3007 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
3009 *TempintBytes += ((uint8_t)NdefMap->TLVStruct.BytesRemainLinTLV);
3012 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3013 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3015 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_MIFARESTD_VAL0;
3016 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
3017 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
3018 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
3024 NdefMap->StdMifareContainer.ReadWriteCompleteFlag)
3031 if( NdefMap->TLVStruct.BytesRemainLinTLV ==
3032 NdefMap->StdMifareContainer.internalLength)
3035 NdefMap->TLVStruct.BytesRemainLinTLV =
3037 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
3040 NdefMap->StdMifareContainer.currentBlock++;
3041 NdefMap->StdMifareContainer.NdefBlocks++;
3042 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3046 ((NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)?
3047 phFriNfc_MifStd_H_RdABlock(NdefMap):
3048 phFriNfc_MifStd_H_AuthSector(NdefMap));
3054 NdefMap->TLVStruct.BytesRemainLinTLV =
3059 else if((NdefMap->TLVStruct.BytesRemainLinTLV >
3060 NdefMap->StdMifareContainer.internalLength) &&
3061 (RemainingBytes <= NdefMap->StdMifareContainer.internalLength))
3063 (void)memcpy(&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex]),
3064 &(NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]),
3067 NdefMap->ApduBuffIndex += RemainingBytes;
3068 NdefMap->StdMifareContainer.remainingSize -=
3072 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
3076 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
3077 &(NdefMap->StdMifareContainer.internalBuf[RemainingBytes]),
3078 (NdefMap->StdMifareContainer.internalLength - RemainingBytes));
3081 NdefMap->StdMifareContainer.internalLength -= RemainingBytes;
3082 if(NdefMap->StdMifareContainer.internalLength == PH_FRINFC_MIFARESTD_VAL0)
3084 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
3085 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
3086 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
3091 NdefMap->StdMifareContainer.currentBlock++;
3092 NdefMap->StdMifareContainer.NdefBlocks++;
3095 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
3101 if((NdefMap->TLVStruct.BytesRemainLinTLV >
3102 NdefMap->StdMifareContainer.internalLength) &&
3103 (RemainingBytes > NdefMap->StdMifareContainer.internalLength))
3105 (void)memcpy(&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex]),
3106 &(NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]),
3107 NdefMap->StdMifareContainer.internalLength);
3109 NdefMap->ApduBuffIndex += NdefMap->StdMifareContainer.internalLength;
3110 NdefMap->StdMifareContainer.remainingSize -=
3111 NdefMap->StdMifareContainer.internalLength;
3112 NdefMap->TLVStruct.BytesRemainLinTLV -= NdefMap->StdMifareContainer.internalLength;
3114 if(NdefMap->TLVStruct.BytesRemainLinTLV != PH_FRINFC_MIFARESTD_NDEFTLV_LBYTES0)
3116 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
3119 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
3121 NdefMap->StdMifareContainer.currentBlock++;
3122 NdefMap->StdMifareContainer.NdefBlocks++;
3123 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3126 Result = ((NdefMap->StdMifareContainer.AuthDone ==
3128 phFriNfc_MifStd_H_RdABlock(NdefMap):
3129 phFriNfc_MifStd_H_AuthSector(NdefMap));
3136 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = (uint8_t)
3137 (((NdefMap->StdMifareContainer.remainingSize == PH_FRINFC_MIFARESTD_VAL0) ||
3138 (NdefMap->TLVStruct.BytesRemainLinTLV == PH_FRINFC_MIFARESTD_VAL0))?
3141 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
3146 static NFCSTATUS phFriNfc_MifStd_H_IntLenWithNdef(phFriNfc_NdefMap_t *NdefMap,
3155 RemainingBytes = (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
3156 while(PH_FRINFC_MIFARESTD_FLAG1 == NdefMap->TLVStruct.NdefTLVFoundFlag)
3158 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
3159 RemainingBytes = ((uint16_t)NdefMap->ApduBufferSize -
3160 NdefMap->ApduBuffIndex);
3161 if(((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3162 NdefMap->StdMifareContainer.NdefBlocks) *
3164 (NdefMap->StdMifareContainer.internalLength -
3171 RemainingBytes = ((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3172 NdefMap->StdMifareContainer.NdefBlocks) * 16) +
3173 (NdefMap->StdMifareContainer.internalLength -
3178 if((NdefMap->TLVStruct.TcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1) &&
3179 (NdefMap->TLVStruct.LcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1) &&
3180 (NdefMap->TLVStruct.NoLbytesinTLV != PH_FRINFC_MIFARESTD_NDEFTLV_LBYTES0))
3190 if(NdefMap->TLVStruct.TcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1)
3192 CRFlag =(uint8_t) ((NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]!=
3199 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
3209 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3212 if(*TempintBytes == NdefMap->StdMifareContainer.internalLength)
3214 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
3215 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
3216 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
3218 NdefMap->StdMifareContainer.currentBlock++;
3219 NdefMap->StdMifareContainer.NdefBlocks++;
3220 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3224 ((NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)?
3225 phFriNfc_MifStd_H_RdABlock(NdefMap):
3226 phFriNfc_MifStd_H_AuthSector(NdefMap));
3232 if(NdefMap->TLVStruct.LcheckedinTLVFlag != PH_FRINFC_MIFARESTD_FLAG1)
3234 CRFlag = (uint8_t)((NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]==
3241 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
3247 *TempintBytes += phFriNfc_MifStd_H_ChkNdefLen(NdefMap,
3252 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
3260 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3263 if(*TempintBytes == NdefMap->StdMifareContainer.internalLength)
3265 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
3266 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
3267 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
3269 NdefMap->StdMifareContainer.currentBlock++;
3270 NdefMap->StdMifareContainer.NdefBlocks++;
3271 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3274 Result = ((NdefMap->StdMifareContainer.AuthDone ==
3276 phFriNfc_MifStd_H_RdABlock(NdefMap):
3277 phFriNfc_MifStd_H_AuthSector(NdefMap));
3282 if( (NdefMap->TLVStruct.BytesRemainLinTLV <=
3283 (NdefMap->StdMifareContainer.internalLength - *TempintBytes)) &&
3284 (RemainingBytes <= NdefMap->TLVStruct.BytesRemainLinTLV))
3287 (void)memcpy(&(NdefMap->ApduBuffer[
3288 NdefMap->ApduBuffIndex]),
3289 &(NdefMap->StdMifareContainer.internalBuf[
3293 NdefMap->ApduBuffIndex += RemainingBytes;
3295 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
3296 if(NdefMap->TLVStruct.BytesRemainLinTLV == 0)
3298 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
3301 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
3302 &(NdefMap->StdMifareContainer.internalBuf[
3305 NdefMap->StdMifareContainer.internalLength -= (*TempintBytes +
3311 else if((NdefMap->TLVStruct.BytesRemainLinTLV <=
3312 (NdefMap->StdMifareContainer.internalLength - *TempintBytes)) &&
3313 (RemainingBytes > NdefMap->TLVStruct.BytesRemainLinTLV))
3316 (void)memcpy(&(NdefMap->ApduBuffer[
3317 NdefMap->ApduBuffIndex]),
3318 &(NdefMap->StdMifareContainer.internalBuf[
3320 NdefMap->TLVStruct.BytesRemainLinTLV);
3323 NdefMap->ApduBuffIndex += NdefMap->TLVStruct.BytesRemainLinTLV;
3324 *TempintBytes += ((uint8_t)NdefMap->TLVStruct.BytesRemainLinTLV);
3325 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_MIFARESTD_VAL0;
3326 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG1;
3329 if(*TempintBytes == NdefMap->StdMifareContainer.internalLength)
3332 NdefMap->StdMifareContainer.currentBlock++;
3333 NdefMap->StdMifareContainer.NdefBlocks++;
3334 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3337 Result = ((NdefMap->StdMifareContainer.AuthDone ==
3339 phFriNfc_MifStd_H_RdABlock(NdefMap):
3340 phFriNfc_MifStd_H_AuthSector(NdefMap));
3345 else if((NdefMap->TLVStruct.BytesRemainLinTLV >
3346 (NdefMap->StdMifareContainer.internalLength - *TempintBytes)) &&
3347 (RemainingBytes <= (NdefMap->StdMifareContainer.internalLength -
3351 (void)memcpy(&(NdefMap->ApduBuffer[
3352 NdefMap->ApduBuffIndex]),
3353 &(NdefMap->StdMifareContainer.internalBuf[
3356 NdefMap->ApduBuffIndex += RemainingBytes;
3358 NdefMap->TLVStruct.BytesRemainLinTLV -= RemainingBytes;
3362 (void)memcpy(NdefMap->StdMifareContainer.internalBuf,
3363 &(NdefMap->StdMifareContainer.internalBuf[(*TempintBytes)]),
3364 (NdefMap->StdMifareContainer.internalLength - *TempintBytes));
3367 NdefMap->StdMifareContainer.internalLength -= *TempintBytes;
3373 if((NdefMap->TLVStruct.BytesRemainLinTLV >
3374 (NdefMap->StdMifareContainer.internalLength - *TempintBytes)) &&
3375 (RemainingBytes > (NdefMap->StdMifareContainer.internalLength -
3379 (void)memcpy(&(NdefMap->ApduBuffer[
3380 NdefMap->ApduBuffIndex]),
3381 &(NdefMap->StdMifareContainer.internalBuf[
3383 (NdefMap->StdMifareContainer.internalLength -
3385 NdefMap->ApduBuffIndex += (NdefMap->StdMifareContainer.internalLength -
3387 NdefMap->TLVStruct.BytesRemainLinTLV -=
3388 (NdefMap->StdMifareContainer.internalLength - *TempintBytes);
3389 *TempintBytes += (uint8_t)(NdefMap->StdMifareContainer.internalLength -
3392 NdefMap->StdMifareContainer.internalLength -= *TempintBytes;
3395 NdefMap->StdMifareContainer.currentBlock++;
3396 NdefMap->StdMifareContainer.NdefBlocks++;
3397 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3400 Result = ((NdefMap->StdMifareContainer.AuthDone ==
3402 phFriNfc_MifStd_H_RdABlock(NdefMap):
3403 phFriNfc_MifStd_H_AuthSector(NdefMap));
3410 if(((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3411 NdefMap->StdMifareContainer.NdefBlocks) *
3413 NdefMap->StdMifareContainer.internalLength) ==
3416 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
3423 (NdefMap->ApduBuffIndex == PH_FRINFC_MIFARESTD_VAL0))?
3428 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
3435 static NFCSTATUS phFriNfc_MifStd_H_WriteNdefLen(phFriNfc_NdefMap_t *NdefMap)
3438 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_WR_NDEF_LEN;
3444 if(NdefMap->StdMifareContainer.currentBlock ==
3445 NdefMap->TLVStruct.NdefTLVBlock)
3448 if(NdefMap->TLVStruct.NULLTLVCount >=
3451 phFriNfc_MifStd_H_fillTLV1(NdefMap);
3455 phFriNfc_MifStd_H_fillTLV2(NdefMap);
3460 if(NdefMap->TLVStruct.NULLTLVCount >=
3463 phFriNfc_MifStd_H_fillTLV1_1(NdefMap);
3467 phFriNfc_MifStd_H_fillTLV2_1(NdefMap);
3471 (void)memcpy( NdefMap->StdMifareContainer.Buffer,
3472 &(NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL1]),
3477 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_WRITE;
3480 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareWrite16;
3482 NdefMap->Cmd.MfCmd = phHal_eMifareWrite16;
3485 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
3487 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
3488 &NdefMap->MapCompletionInfo,
3489 NdefMap->psRemoteDevInfo,
3490 NdefMap->Cmd,
3491 &NdefMap->psDepAdditionalInfo,
3492 NdefMap->SendRecvBuf,
3493 NdefMap->SendLength,
3494 NdefMap->SendRecvBuf,
3495 NdefMap->SendRecvLength);
3500 static NFCSTATUS phFriNfc_MifStd_H_ChkNdefCmpltBlocks(phFriNfc_NdefMap_t *NdefMap)
3506 if((NdefMap->StdMifareContainer.NoOfNdefCompBlocks !=
3508 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks <=
3513 NdefMap->StdMifareContainer.currentBlock = 4;
3514 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
3515 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
3517 (NdefMap->StdMifareContainer.AuthDone ==
3520 NdefMap->StdMifareContainer.ReadAcsBitFlag = 0;
3521 Result = phFriNfc_MifStd_H_RdAcsBit(NdefMap);
3525 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
3532 static void phFriNfc_MifStd_H_RdWrReset(phFriNfc_NdefMap_t *NdefMap)
3534 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_BLK4;
3535 NdefMap->StdMifareContainer.NdefBlocks = PH_FRINFC_MIFARESTD_VAL1;
3536 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_MIFARESTD_VAL0;
3537 NdefMap->TLVStruct.LcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3538 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
3539 NdefMap->TLVStruct.NdefTLVAuthFlag = PH_FRINFC_MIFARESTD_FLAG0;
3540 NdefMap->TLVStruct.NdefTLVBlock = PH_FRINFC_MIFARESTD_MAD_BLK0;
3541 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL0;
3542 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_MIFARESTD_VAL0;
3543 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
3544 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
3545 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
3546 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
3547 NdefMap->StdMifareContainer.FirstReadFlag = PH_FRINFC_MIFARESTD_FLAG1;
3548 NdefMap->StdMifareContainer.ReadWriteCompleteFlag = PH_FRINFC_MIFARESTD_FLAG0;
3549 NdefMap->StdMifareContainer.remainingSize = (uint16_t)
3550 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks *
3552 NdefMap->StdMifareContainer.WrLength = PH_FRINFC_MIFARESTD_VAL1;
3556 static NFCSTATUS phFriNfc_MifStd_H_RdtoWrNdefLen(phFriNfc_NdefMap_t *NdefMap)
3559 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RD_TO_WR_NDEF_LEN;
3561 if(NdefMap->TLVStruct.NdefTLVAuthFlag == PH_FRINFC_MIFARESTD_FLAG1)
3563 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
3564 Result = phFriNfc_MifStd_H_AuthSector(NdefMap);
3568 NdefMap->SendRecvBuf[0] = NdefMap->StdMifareContainer.currentBlock;
3569 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_READ;
3570 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
3573 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareRead;
3575 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
3578 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
3579 &NdefMap->MapCompletionInfo,
3580 NdefMap->psRemoteDevInfo,
3581 NdefMap->Cmd,
3582 &NdefMap->psDepAdditionalInfo,
3583 NdefMap->SendRecvBuf,
3584 NdefMap->SendLength,
3585 NdefMap->SendRecvBuf,
3586 NdefMap->SendRecvLength);
3592 static void phFriNfc_MifStd_H_SetNdefBlkAuth(phFriNfc_NdefMap_t *NdefMap)
3594 NdefMap->TLVStruct.NdefTLVAuthFlag =
3595 ((phFriNfc_MifStd_H_GetSect(NdefMap->TLVStruct.NdefTLVBlock)
3596 == phFriNfc_MifStd_H_GetSect(NdefMap->StdMifareContainer.currentBlock))?
3601 static NFCSTATUS phFriNfc_MifStd_H_GetActCardLen(phFriNfc_NdefMap_t *NdefMap)
3604 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_GET_ACT_CARDSIZE;
3605 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_GET_ACTSIZE_OPE;
3607 Result = ((NdefMap->StdMifareContainer.AuthDone ==
3609 phFriNfc_MifStd_H_AuthSector(NdefMap):
3610 phFriNfc_MifStd_H_Rd16Bytes(NdefMap,
3611 NdefMap->StdMifareContainer.currentBlock));
3616 static NFCSTATUS phFriNfc_MifStd_H_ChkTLVs(phFriNfc_NdefMap_t *NdefMap,
3623 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_GET_ACTSIZE_OPE;
3624 TempLength = NdefMap->TLVStruct.NdefTLVByte;
3628 if((NdefMap->SendRecvBuf[TempLength] != PH_FRINFC_MIFARESTD_TERMTLV_T) &&
3629 (NdefMap->SendRecvBuf[TempLength] != PH_FRINFC_MIFARESTD_NULLTLV_T) &&
3630 (NdefMap->SendRecvBuf[TempLength] != PH_FRINFC_MIFARESTD_NDEFTLV_T) &&
3631 (FALSE == NdefMap->TLVStruct.NdefTLVFoundFlag))
3635 NdefMap->TLVStruct.BytesRemainLinTLV = 0;
3636 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
3643 if((NdefMap->SendRecvBuf[TempLength] != PH_FRINFC_MIFARESTD_TERMTLV_T) &&
3644 (NdefMap->SendRecvBuf[TempLength] != PH_FRINFC_MIFARESTD_NULLTLV_T))
3646 if(NdefMap->SendRecvBuf[TempLength] == PH_FRINFC_MIFARESTD_NDEFTLV_T)
3648 NdefMap->TLVStruct.NdefTLVBlock =
3649 NdefMap->StdMifareContainer.currentBlock;
3650 NdefMap->TLVStruct.NdefTLVByte = (uint8_t)TempLength;
3651 NdefMap->TLVStruct.NdefTLVFoundFlag =
3652 ((NdefMap->SendRecvBuf[TempLength] ==
3657 NdefMap->TLVStruct.NULLTLVCount = ((NdefMap->TLVStruct.NULLTLVCount
3660 NdefMap->TLVStruct.NULLTLVCount);
3664 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
3670 NdefMap->TLVStruct.TcheckedinTLVFlag =
3672 NdefMap->TLVStruct.NoLbytesinTLV =
3675 Result = phFriNfc_MifStd_H_Chk16Bytes( NdefMap,
3685 if((((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3686 NdefMap->StdMifareContainer.NdefBlocks) *
3690 NdefMap->SendRecvBuf[TempLength]) &&
3691 ((NdefMap->SendRecvBuf[TempLength] <
3693 (NdefMap->TLVStruct.NdefTLVFoundFlag !=
3703 if((((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3704 NdefMap->StdMifareContainer.NdefBlocks) *
3708 NdefMap->SendRecvBuf[TempLength]) &&
3709 ((NdefMap->SendRecvBuf[TempLength] ==
3711 (NdefMap->TLVStruct.NdefTLVFoundFlag ==
3721 if((NdefMap->TLVStruct.NdefTLVFoundFlag ==
3723 (NdefMap->SendRecvBuf[TempLength] <
3726 Result = phFriNfc_MapTool_SetCardState(NdefMap,
3727 NdefMap->SendRecvBuf[TempLength]);
3728 NdefMap->TLVStruct.BytesRemainLinTLV =
3729 NdefMap->SendRecvBuf[TempLength];
3730 NdefMap->StdMifareContainer.remainingSize -=
3733 NdefMap->StdMifareContainer.remSizeUpdFlag =
3734 (uint8_t)((NdefMap->TLVStruct.NULLTLVCount >=
3743 NdefMap->StdMifareContainer.remainingSize -=
3744 (( NdefMap->SendRecvBuf[TempLength] <
3746 (NdefMap->SendRecvBuf[TempLength]
3750 if(( NdefMap->SendRecvBuf[TempLength] ==
3762 ((NdefMap->SendRecvBuf[TempLength] <
3764 phFriNfc_MifStd_H_GetNxtTLV(NdefMap, &TempLength, &TL4bytesFlag):
3770 NdefMap->TLVStruct.TcheckedinTLVFlag =
3772 NdefMap->TLVStruct.NoLbytesinTLV =
3775 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
3786 Result = ((NdefMap->SendRecvBuf[TempLength] ==
3797 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
3802 NdefMap->TLVStruct.TcheckedinTLVFlag =
3804 NdefMap->TLVStruct.NoLbytesinTLV =
3807 Result = phFriNfc_MifStd_H_Chk16Bytes( NdefMap,
3814 ShiftLength = NdefMap->SendRecvBuf[TempLength];
3818 NdefMap->TLVStruct.TcheckedinTLVFlag =
3820 NdefMap->TLVStruct.NoLbytesinTLV =
3822 NdefMap->TLVStruct.prevLenByteValue =
3823 NdefMap->SendRecvBuf[(TempLength -
3826 Result = phFriNfc_MifStd_H_Chk16Bytes( NdefMap,
3834 if(((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
3835 NdefMap->StdMifareContainer.NdefBlocks) *
3840 << 8) + NdefMap->SendRecvBuf[TempLength]))
3848 if(NdefMap->TLVStruct.NdefTLVFoundFlag ==
3852 NdefMap->SendRecvBuf[TempLength]);
3853 NdefMap->TLVStruct.BytesRemainLinTLV = ShiftLength;
3854 Result = phFriNfc_MapTool_SetCardState(NdefMap,
3856 NdefMap->StdMifareContainer.remainingSize -=
3862 NdefMap->StdMifareContainer.remainingSize -=
3864 NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL1)]);
3868 Result = phFriNfc_MifStd_H_GetNxtTLV(NdefMap, &TempLength, &TL4bytesFlag);
3873 NdefMap->TLVStruct.TcheckedinTLVFlag =
3875 NdefMap->TLVStruct.NoLbytesinTLV =
3877 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
3885 else if((NdefMap->SendRecvBuf[TempLength] == PH_FRINFC_MIFARESTD_TERMTLV_T) &&
3886 (NdefMap->TLVStruct.NdefTLVFoundFlag == PH_FRINFC_MIFARESTD_FLAG0))
3890 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
3895 else if(NdefMap->SendRecvBuf[TempLength] == PH_FRINFC_MIFARESTD_NULLTLV_T)
3898 NdefMap->TLVStruct.NULLTLVCount += PH_FRINFC_MIFARESTD_VAL1;
3899 ShiftLength = NdefMap->SendRecvBuf[(TempLength - PH_FRINFC_MIFARESTD_VAL1)];
3900 NdefMap->StdMifareContainer.remainingSize -= PH_FRINFC_MIFARESTD_VAL1;
3901 if(NdefMap->StdMifareContainer.remainingSize <
3902 (( ShiftLength << 8) + NdefMap->SendRecvBuf[TempLength]))
3908 Result = phFriNfc_MifStd_H_Chk16Bytes( NdefMap,
3912 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL0;
3918 if((NdefMap->SendRecvBuf[TempLength] == PH_FRINFC_MIFARESTD_TERMTLV_T) &&
3919 (NdefMap->TLVStruct.NdefTLVFoundFlag == PH_FRINFC_MIFARESTD_FLAG1))
3923 NdefMap->StdMifareContainer.remainingSize -=
3929 if(NdefMap->TLVStruct.BytesRemainLinTLV >
3930 NdefMap->StdMifareContainer.remainingSize)
3937 if(NdefMap->StdMifareContainer.remainingSize ==
3940 Result = ((NdefMap->TLVStruct.NdefTLVFoundFlag ==
3950 static NFCSTATUS phFriNfc_MifStd_H_GetNxtTLV(phFriNfc_NdefMap_t *NdefMap,
3965 (*TempLength) += (NdefMap->SendRecvBuf[TempLen] +
3968 if(NdefMap->TLVStruct.NdefTLVFoundFlag == PH_FRINFC_MIFARESTD_FLAG0)
3973 (NdefMap->SendRecvBuf[TempLen] -
3981 (NdefMap->SendRecvBuf[TempLen] -
3988 if(NdefMap->TLVStruct.NoLbytesinTLV ==
3991 ShiftLength = NdefMap->TLVStruct.prevLenByteValue;
3993 << 8) + NdefMap->SendRecvBuf[TempLen] +
3998 << 8) + NdefMap->SendRecvBuf[TempLen]) -
4003 ShiftLength = NdefMap->SendRecvBuf[(TempLen - PH_FRINFC_MIFARESTD_VAL1)];
4005 << 8) + NdefMap->SendRecvBuf[TempLen] +
4010 << 8) + NdefMap->SendRecvBuf[TempLen]) -
4015 NdefMap->TLVStruct.NdefTLVByte =
4022 NdefMap->StdMifareContainer.currentBlock++;
4023 NdefMap->StdMifareContainer.NdefBlocks++;
4024 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4031 if(NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL0)
4033 NdefMap->StdMifareContainer.currentBlock++;
4034 NdefMap->StdMifareContainer.NdefBlocks++;
4035 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4041 static NFCSTATUS phFriNfc_MifStd_H_Chk16Bytes(phFriNfc_NdefMap_t *NdefMap,
4047 NdefMap->StdMifareContainer.currentBlock++;
4048 NdefMap->StdMifareContainer.NdefBlocks++;
4049 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4052 ((NdefMap->StdMifareContainer.AuthDone == PH_FRINFC_MIFARESTD_FLAG1)?
4053 phFriNfc_MifStd_H_GetActCardLen(NdefMap):
4054 phFriNfc_MifStd_H_AuthSector(NdefMap));
4059 static NFCSTATUS phFriNfc_MifStd_H_ChkRemainTLVs(phFriNfc_NdefMap_t *NdefMap,
4068 switch(NdefMap->TLVStruct.NoLbytesinTLV)
4072 Result = ((NdefMap->TLVStruct.NdefTLVFoundFlag ==
4074 phFriNfc_MapTool_SetCardState(NdefMap,
4075 NdefMap->SendRecvBuf[TempLength]):
4081 if((NdefMap->SendRecvBuf[TempLength] <
4085 NdefMap->StdMifareContainer.remainingSize -=
4088 Result = ((NdefMap->SendRecvBuf[TempLength] >
4089 NdefMap->StdMifareContainer.remainingSize)?
4094 if((NdefMap->TLVStruct.NdefTLVFoundFlag ==
4098 NdefMap->TLVStruct.BytesRemainLinTLV =
4099 NdefMap->SendRecvBuf[TempLength];
4106 Result = phFriNfc_MifStd_H_GetNxtTLV(NdefMap,
4109 NdefMap->StdMifareContainer.remainingSize -=
4110 NdefMap->SendRecvBuf[TempLength];
4115 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
4124 else if((NdefMap->SendRecvBuf[TempLength] ==
4129 NdefMap->StdMifareContainer.remainingSize -=
4132 Result = (((((uint16_t)NdefMap->SendRecvBuf[TempLength] << 8) +
4133 NdefMap->SendRecvBuf[(TempLength +
4135 NdefMap->StdMifareContainer.remainingSize)?
4139 if((NdefMap->TLVStruct.NdefTLVFoundFlag ==
4143 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
4144 NdefMap->TLVStruct.BytesRemainLinTLV =
4145 (((uint16_t)NdefMap->SendRecvBuf[TempLength] << 8) +
4146 NdefMap->SendRecvBuf[(TempLength +
4154 Result = phFriNfc_MifStd_H_GetNxtTLV(NdefMap,
4156 NdefMap->StdMifareContainer.remainingSize -=
4157 (((uint16_t)NdefMap->SendRecvBuf[TempLength] << 8) +
4158 NdefMap->SendRecvBuf[(TempLength +
4162 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
4181 ShiftLength = ((NdefMap->TLVStruct.NoLbytesinTLV ==
4183 ((NdefMap->TLVStruct.prevLenByteValue << 8) +
4184 NdefMap->SendRecvBuf[TempLength]):
4185 (((uint16_t)NdefMap->SendRecvBuf[TempLength] << 8) +
4186 NdefMap->SendRecvBuf[(TempLength +
4188 if(((( NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
4189 NdefMap->StdMifareContainer.NdefBlocks) *
4202 NdefMap->StdMifareContainer.remainingSize -=
4204 if(NdefMap->TLVStruct.NdefTLVFoundFlag ==
4207 NdefMap->TLVStruct.BytesRemainLinTLV = ShiftLength;
4208 if(NdefMap->TLVStruct.BytesRemainLinTLV >
4209 NdefMap->StdMifareContainer.remainingSize)
4219 NdefMap->StdMifareContainer.remainingSize -=
4224 Result = ((NdefMap->TLVStruct.NdefTLVFoundFlag == PH_FRINFC_MIFARESTD_FLAG1)?
4226 phFriNfc_MifStd_H_GetNxtTLV(NdefMap, &TempLength, &TL4bytesFlag));
4229 Result = phFriNfc_MifStd_H_GetActCardLen(NdefMap);
4240 static void phFriNfc_MifStd_H_Get1kStTrail(phFriNfc_NdefMap_t *NdefMap)
4242 switch((NdefMap->StdMifareContainer.currentBlock % 4))
4245 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4246 (NdefMap->StdMifareContainer.currentBlock +
4251 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4252 (NdefMap->StdMifareContainer.currentBlock +
4257 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4258 (NdefMap->StdMifareContainer.currentBlock +
4263 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4264 NdefMap->StdMifareContainer.currentBlock;
4269 static void phFriNfc_MifStd_H_Get4kStTrail(phFriNfc_NdefMap_t *NdefMap)
4271 switch((NdefMap->StdMifareContainer.currentBlock % 16))
4274 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4275 (NdefMap->StdMifareContainer.currentBlock +
4280 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4281 (NdefMap->StdMifareContainer.currentBlock +
4286 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4287 (NdefMap->StdMifareContainer.currentBlock +
4292 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4293 (NdefMap->StdMifareContainer.currentBlock +
4298 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4299 (NdefMap->StdMifareContainer.currentBlock +
4304 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4305 (NdefMap->StdMifareContainer.currentBlock +
4310 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4311 (NdefMap->StdMifareContainer.currentBlock +
4316 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4317 (NdefMap->StdMifareContainer.currentBlock +
4322 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4323 (NdefMap->StdMifareContainer.currentBlock +
4328 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4329 (NdefMap->StdMifareContainer.currentBlock +
4334 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4335 (NdefMap->StdMifareContainer.currentBlock +
4340 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4341 (NdefMap->StdMifareContainer.currentBlock +
4346 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4347 (NdefMap->StdMifareContainer.currentBlock +
4352 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4353 (NdefMap->StdMifareContainer.currentBlock +
4358 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4359 (NdefMap->StdMifareContainer.currentBlock +
4364 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4365 NdefMap->StdMifareContainer.currentBlock;
4370 static NFCSTATUS phFriNfc_MifStd_H_ProChkNdef(phFriNfc_NdefMap_t *NdefMap)
4375 if(NdefMap->StdMifareContainer.currentBlock ==
4379 phFriNfc_MifStd_H_fillAIDarray(NdefMap);
4381 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_VAL2;
4383 Result = ((NdefMap->StdMifareContainer.aidCompleteFlag ==
4386 phFriNfc_MifareStdMap_ChkNdef( NdefMap));
4388 else if(((NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD) &&
4389 (NdefMap->StdMifareContainer.currentBlock ==
4391 (NdefMap->StdMifareContainer.currentBlock ==
4393 (NdefMap->CardType ==
4397 phFriNfc_MifStd_H_fillAIDarray(NdefMap);
4399 NdefMap->StdMifareContainer.aidCompleteFlag =
4402 else if((NdefMap->StdMifareContainer.currentBlock >
4404 (NdefMap->CardType ==
4407 phFriNfc_MifStd_H_fillAIDarray(NdefMap);
4410 Result = ((NdefMap->StdMifareContainer.aidCompleteFlag ==
4413 phFriNfc_MifStd4k_H_CheckNdef(NdefMap));
4425 if(NdefMap->StdMifareContainer.aidCompleteFlag ==
4428 NdefMap->StdMifareContainer.ChkNdefCompleteFlag =
4435 phFriNfc_MifStd_H_ChkNdefCmpltSects(NdefMap);
4436 if((NdefMap->StdMifareContainer.NoOfNdefCompBlocks == 0) ||
4437 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks > 255))
4444 NdefMap->StdMifareContainer.aidCompleteFlag =
4446 NdefMap->StdMifareContainer.NFCforumSectFlag =
4448 NdefMap->StdMifareContainer.currentBlock = PH_FRINFC_MIFARESTD_BLK4;
4449 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4451 Result:phFriNfc_MifStd_H_AuthSector(NdefMap));
4458 static NFCSTATUS phFriNfc_MifStd_H_ProAuth(phFriNfc_NdefMap_t *NdefMap)
4461 if(NdefMap->TLVStruct.NdefTLVAuthFlag ==
4464 NdefMap->TLVStruct.NdefTLVAuthFlag =
4466 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG1;
4467 Result = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
4471 NdefMap->StdMifareContainer.AuthDone = 1;
4472 NdefMap->StdMifareContainer.ReadAcsBitFlag = 1;
4473 Result = phFriNfc_MifStd_H_RdAcsBit(NdefMap);
4478 static NFCSTATUS phFriNfc_MifStd_H_Rd16Bytes(phFriNfc_NdefMap_t *NdefMap,
4482 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] = BlockNo;
4483 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_READ;
4484 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
4486 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareRead;
4488 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
4490 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
4491 NdefMap->MapCompletionInfo.Context = NdefMap;
4493 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
4494 &NdefMap->MapCompletionInfo,
4495 NdefMap->psRemoteDevInfo,
4496 NdefMap->Cmd,
4497 &NdefMap->psDepAdditionalInfo,
4498 NdefMap->SendRecvBuf,
4499 NdefMap->SendLength,
4500 NdefMap->SendRecvBuf,
4501 NdefMap->SendRecvLength);
4505 static NFCSTATUS phFriNfc_MifStd_H_ProAcsBits(phFriNfc_NdefMap_t *NdefMap)
4509 if(*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ)
4511 if(NdefMap->StdMifareContainer.ReadAcsBitFlag ==
4515 Result = phFriNfc_MifStd_H_ChkAcsBit(NdefMap);
4517 if((NdefMap->StdMifareContainer.ChkNdefFlag ==
4521 if(NdefMap->CardState ==
4524 NdefMap->StdMifareContainer.NoOfNdefCompBlocks =
4525 ((NdefMap->StdMifareContainer.currentBlock >=
4527 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
4529 (NdefMap->StdMifareContainer.NoOfNdefCompBlocks -
4532 NdefMap->StdMifareContainer.ProprforumSectFlag =
4533 ((NdefMap->StdMifareContainer.NFCforumSectFlag ==
4538 Result = phFriNfc_MifStd_H_ProStatNotValid(NdefMap, Result);
4542 NdefMap->StdMifareContainer.NFCforumSectFlag =
4543 (((NdefMap->StdMifareContainer.currentBlock == 64) &&
4544 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))?
4545 NdefMap->StdMifareContainer.NFCforumSectFlag:
4549 if(NdefMap->StdMifareContainer.ProprforumSectFlag !=
4552 NdefMap->StdMifareContainer.ReadAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG0;
4553 /* ((NdefMap->StdMifareContainer.ReadCompleteFlag ==
4558 NdefMap->StdMifareContainer.ReadCompleteFlag =
4559 (uint8_t)((((((NdefMap->StdMifareContainer.currentBlock +
4562 (NdefMap->CardType ==
4564 (NdefMap->StdMifareContainer.ReadCompleteFlag ==
4566 (NdefMap->StdMifareContainer.ReadCompleteFlag ==
4571 NdefMap->StdMifareContainer.ReadCompleteFlag =
4572 (uint8_t)((((((uint16_t)(NdefMap->StdMifareContainer.currentBlock +
4575 (NdefMap->CardType ==
4577 (NdefMap->StdMifareContainer.ReadCompleteFlag ==
4579 (NdefMap->StdMifareContainer.ReadCompleteFlag ==
4584 NdefMap->StdMifareContainer.currentBlock =
4585 ((NdefMap->StdMifareContainer.ReadCompleteFlag ==
4588 NdefMap->StdMifareContainer.currentBlock);
4591 ((NdefMap->StdMifareContainer.ReadCompleteFlag ==
4593 phFriNfc_MifStd_H_BlkChk(NdefMap):
4600 phFriNfc_MifStd_H_ChkRdWr(NdefMap));
4604 NdefMap->StdMifareContainer.ChkNdefFlag =
4608 Result = phFriNfc_MifStd_H_ChkTLVs(NdefMap, &CRFlag);
4624 static NFCSTATUS phFriNfc_MifStd_H_GPBChk(phFriNfc_NdefMap_t *NdefMap)
4629 Result = phFriNfc_MapTool_ChkSpcVer(NdefMap, PH_FRINFC_MIFARESTD_VAL9);
4637 if(((NdefMap->SendRecvBuf[
4641 ((NdefMap->SendRecvBuf[
4646 NdefMap->CardState = (((NdefMap->StdMifareContainer.ChkNdefFlag ==
4648 (NdefMap->StdMifareContainer.ReadNdefFlag ==
4650 (NdefMap->StdMifareContainer.WrNdefFlag ==
4655 else if(((NdefMap->SendRecvBuf[
4659 ((NdefMap->SendRecvBuf[
4666 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
4670 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
4676 static NFCSTATUS phFriNfc_MifStd_H_ProStatNotValid(phFriNfc_NdefMap_t *NdefMap,
4683 if(NdefMap->StdMifareContainer.NFCforumSectFlag ==
4686 NdefMap->StdMifareContainer.ProprforumSectFlag =
4688 if(NdefMap->StdMifareContainer.currentBlock <
4698 if(((NdefMap->StdMifareContainer.currentBlock <
4700 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD)) ||
4701 ((NdefMap->StdMifareContainer.currentBlock <=
4703 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD)))
4708 else if((NdefMap->StdMifareContainer.currentBlock <
4710 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))
4713 NdefMap->StdMifareContainer.currentBlock =
4718 if(((NdefMap->StdMifareContainer.currentBlock +
4721 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD))
4728 NdefMap->StdMifareContainer.remainingSize -=
4730 NdefMap->StdMifareContainer.currentBlock +=
4732 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4735 else if((NdefMap->StdMifareContainer.currentBlock +
4744 NdefMap->StdMifareContainer.remainingSize -=
4746 NdefMap->StdMifareContainer.currentBlock +=
4748 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
4753 phFriNfc_MifStd_H_AuthSector(NdefMap));
4755 else if((NdefMap->StdMifareContainer.ProprforumSectFlag ==
4757 (NdefMap->StdMifareContainer.NFCforumSectFlag ==
4769 NdefMap->StdMifareContainer.ProprforumSectFlag =
4771 switch(NdefMap->PrevOperation)
4780 if((NdefMap->TLVStruct.NdefTLVFoundFlag ==
4782 (NdefMap->TLVStruct.NoLbytesinTLV ==
4785 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
4799 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
4802 NdefMap->StdMifareContainer.TempBlockNo =
4803 NdefMap->StdMifareContainer.currentBlock;
4804 phFriNfc_MifStd_H_SetNdefBlkAuth(NdefMap);
4805 NdefMap->StdMifareContainer.currentBlock =
4806 NdefMap->TLVStruct.NdefTLVBlock;
4807 Result = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
4814 static NFCSTATUS phFriNfc_MifStd_H_RdBeforeWr(phFriNfc_NdefMap_t *NdefMap)
4817 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RD_BEF_WR;
4818 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
4820 Result = phFriNfc_MifStd_H_Rd16Bytes(NdefMap,
4821 NdefMap->StdMifareContainer.currentBlock);
4825 static NFCSTATUS phFriNfc_MifStd_H_ProBytesToWr(phFriNfc_NdefMap_t *NdefMap)
4830 if(*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ)
4832 (void)memcpy(&NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL1],
4833 NdefMap->SendRecvBuf,
4837 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4838 NdefMap->StdMifareContainer.currentBlock;
4840 TempLength = ((NdefMap->StdMifareContainer.currentBlock ==
4841 NdefMap->TLVStruct.NdefTLVBlock)?
4842 phFriNfc_MifStd_H_UpdateTLV(NdefMap):
4843 phFriNfc_MifStd_H_UpdRemTLV(NdefMap));
4845 NdefMap->StdMifareContainer.remainingSize -=
4846 ((NdefMap->StdMifareContainer.remSizeUpdFlag ==
4851 NdefMap->StdMifareContainer.remSizeUpdFlag = PH_FRINFC_MIFARESTD_FLAG0;
4852 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_WR_TLV;
4854 phFriNfc_MifStd_H_WrTLV(NdefMap):
4855 phFriNfc_MifStd_H_fillSendBuf(NdefMap, TempLength));
4866 static uint8_t phFriNfc_MifStd_H_UpdateTLV(phFriNfc_NdefMap_t *NdefMap)
4869 TempLength = (uint8_t)(NdefMap->TLVStruct.NdefTLVByte + PH_FRINFC_MIFARESTD_VAL1);
4871 if(NdefMap->TLVStruct.NULLTLVCount >= 2)
4876 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
4880 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
4882 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L0;
4891 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4895 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4897 NdefMap->TLVStruct.prevLenByteValue =
4898 (uint16_t)((NdefMap->SendRecvBuf[TempLength] >=
4901 NdefMap->SendRecvBuf[TempLength]);
4902 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4906 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4908 NdefMap->TLVStruct.prevLenByteValue =
4909 (uint16_t)((NdefMap->SendRecvBuf[TempLength] >=
4911 NdefMap->SendRecvBuf[(TempLength +
4913 NdefMap->SendRecvBuf[TempLength]);
4914 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4916 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
4920 NdefMap->TLVStruct.prevLenByteValue =
4921 NdefMap->SendRecvBuf[TempLength];
4922 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4924 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
4926 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
4928 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L0;
4936 static NFCSTATUS phFriNfc_MifStd_H_fillSendBuf(phFriNfc_NdefMap_t *NdefMap,
4946 RemainingBytes = (uint16_t)((NdefMap->StdMifareContainer.remainingSize
4947 < (uint16_t)(NdefMap->ApduBufferSize -
4948 NdefMap->ApduBuffIndex))?
4949 NdefMap->StdMifareContainer.remainingSize:
4950 (NdefMap->ApduBufferSize -
4951 NdefMap->ApduBuffIndex));
4953 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] =
4954 NdefMap->StdMifareContainer.currentBlock;
4959 NdefMap->StdMifareContainer.internalLength))?
4962 NdefMap->StdMifareContainer.internalLength));
4964 if(NdefMap->StdMifareContainer.internalLength >
4968 (void)memcpy(&(NdefMap->SendRecvBuf[
4970 NdefMap->StdMifareContainer.internalBuf,
4971 NdefMap->StdMifareContainer.internalLength);
4975 (void)memcpy(&(NdefMap->SendRecvBuf[
4977 NdefMap->StdMifareContainer.internalLength)]),
4978 &(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex]),
4982 NdefMap->NumOfBytesWritten = BytesToWrite;
4986 *NdefMap->DataCount =
4987 ((BytesToWrite + NdefMap->StdMifareContainer.internalLength
4992 if((BytesToWrite + NdefMap->StdMifareContainer.internalLength +
4996 NdefMap->StdMifareContainer.internalLength +
5001 NdefMap->SendRecvBuf[index] = (uint8_t)((index ==
5003 NdefMap->StdMifareContainer.internalLength))?
5007 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
5012 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_MIFARESTD_FLAG1;
5018 (void)memcpy(NdefMap->StdMifareContainer.Buffer,
5019 &(NdefMap->SendRecvBuf[
5023 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_WR_TLV;
5024 Result = phFriNfc_MifStd_H_WrTLV(NdefMap);
5028 static NFCSTATUS phFriNfc_MifStd_H_WrTLV(phFriNfc_NdefMap_t *NdefMap)
5033 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
5034 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
5035 NdefMap->psDepAdditionalInfo.NAD = 0;
5036 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
5037 NdefMap->MapCompletionInfo.Context = NdefMap;
5039 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_WRITE;
5042 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareWrite16;
5044 NdefMap->Cmd.MfCmd = phHal_eMifareWrite16;
5047 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
5049 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
5050 &NdefMap->MapCompletionInfo,
5051 NdefMap->psRemoteDevInfo,
5052 NdefMap->Cmd,
5053 &NdefMap->psDepAdditionalInfo,
5054 NdefMap->SendRecvBuf,
5055 NdefMap->SendLength,
5056 NdefMap->SendRecvBuf,
5057 NdefMap->SendRecvLength);
5063 static NFCSTATUS phFriNfc_MifStd_H_ProWrTLV(phFriNfc_NdefMap_t *NdefMap)
5069 NdefMap->TLVStruct.NdefTLVByte) ==
5071 (NdefMap->TLVStruct.NULLTLVCount >=
5074 NdefMap->TLVStruct.NdefTLVByte) <=
5076 (NdefMap->TLVStruct.NULLTLVCount ==
5078 (NdefMap->StdMifareContainer.currentBlock ==
5079 NdefMap->TLVStruct.NdefTLVBlock))
5083 NdefMap->StdMifareContainer.RdBeforeWrFlag = PH_FRINFC_MIFARESTD_FLAG1;
5084 NdefMap->StdMifareContainer.currentBlock++;
5085 NdefMap->StdMifareContainer.NdefBlocks++;
5086 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5089 Result = ((NdefMap->StdMifareContainer.AuthDone ==
5091 phFriNfc_MifStd_H_AuthSector(NdefMap):
5092 phFriNfc_MifStd_H_RdBeforeWr(NdefMap));
5097 NdefMap->StdMifareContainer.RdBeforeWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
5098 if(NdefMap->ApduBuffIndex <
5099 (uint16_t)NdefMap->ApduBufferSize)
5101 if(*NdefMap->DataCount < PH_FRINFC_MIFARESTD_BLOCK_BYTES)
5104 NdefMap->StdMifareContainer.internalLength =
5105 *NdefMap->DataCount;
5109 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
5110 NdefMap->StdMifareContainer.Buffer,
5111 NdefMap->StdMifareContainer.internalLength);
5115 NdefMap->ApduBuffIndex += NdefMap->NumOfBytesWritten;
5117 NdefMap->StdMifareContainer.remainingSize -=
5118 NdefMap->NumOfBytesWritten;
5121 if((NdefMap->StdMifareContainer.remainingSize ==
5123 (NdefMap->ApduBuffIndex == NdefMap->ApduBufferSize))
5125 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
5126 (uint8_t)((NdefMap->StdMifareContainer.remainingSize == 0)?
5129 if(NdefMap->StdMifareContainer.internalLength ==
5132 NdefMap->StdMifareContainer.currentBlock++;
5135 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5136 NdefMap->StdMifareContainer.NdefBlocks++;
5139 NdefMap->TLVStruct.SetTermTLVFlag =
5140 (uint8_t)(((NdefMap->StdMifareContainer.remainingSize ==
5142 (NdefMap->TLVStruct.SetTermTLVFlag ==
5150 NdefMap->StdMifareContainer.currentBlock++;
5153 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5156 NdefMap->StdMifareContainer.NdefBlocks++;
5157 Result = ((NdefMap->StdMifareContainer.AuthDone ==
5159 phFriNfc_MifStd_H_WrABlock(NdefMap):
5160 phFriNfc_MifStd_H_AuthSector(NdefMap));
5167 (NdefMap->TLVStruct.SetTermTLVFlag !=
5169 (NdefMap->StdMifareContainer.remainingSize >
5172 Result = phFriNfc_MifStd_H_WrTermTLV(NdefMap);
5177 (NdefMap->TLVStruct.SetTermTLVFlag ==
5181 NdefMap->StdMifareContainer.TempBlockNo =
5182 NdefMap->StdMifareContainer.currentBlock;
5183 phFriNfc_MifStd_H_SetNdefBlkAuth(NdefMap);
5184 NdefMap->StdMifareContainer.currentBlock =
5185 NdefMap->TLVStruct.NdefTLVBlock;
5186 Result = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
5192 static uint8_t phFriNfc_MifStd_H_UpdRemTLV(phFriNfc_NdefMap_t *NdefMap)
5195 if(NdefMap->TLVStruct.NULLTLVCount >=
5198 NdefMap->TLVStruct.prevLenByteValue = NdefMap->SendRecvBuf[TempLength];
5199 NdefMap->SendRecvBuf[TempLength] =
5205 NdefMap->TLVStruct.NdefTLVByte))
5208 NdefMap->TLVStruct.prevLenByteValue =
5209 (((NdefMap->SendRecvBuf[TempLength] ==
5211 (((uint16_t)NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL1)]
5213 NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL2)]):
5214 NdefMap->SendRecvBuf[TempLength]);
5215 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5217 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5219 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L0;
5223 NdefMap->TLVStruct.prevLenByteValue =
5224 (((NdefMap->SendRecvBuf[TempLength] ==
5226 (((uint16_t)NdefMap->SendRecvBuf[TempLength] <<
5228 NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL1)]):
5229 NdefMap->SendRecvBuf[TempLength]);
5230 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5232 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L0;
5237 NdefMap->TLVStruct.prevLenByteValue =
5238 ((NdefMap->TLVStruct.prevLenByteValue <<
5240 + NdefMap->SendRecvBuf[TempLength]);
5241 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L0;
5248 static void phFriNfc_MifStd_H_fillTLV1(phFriNfc_NdefMap_t *NdefMap)
5250 uint8_t TempLength = (uint8_t)(NdefMap->TLVStruct.NdefTLVByte +
5253 NdefMap->TLVStruct.prevLenByteValue =
5254 ((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_CUR)?
5255 (NdefMap->TLVStruct.prevLenByteValue +
5256 NdefMap->ApduBuffIndex):
5257 NdefMap->ApduBuffIndex);
5259 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG1;
5260 switch(NdefMap->TLVStruct.NdefTLVByte)
5263 if(NdefMap->TLVStruct.prevLenByteValue >=
5266 NdefMap->SendRecvBuf[TempLength] =
5267 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5269 NdefMap->SendRecvBuf[(TempLength +
5271 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5275 NdefMap->SendRecvBuf[TempLength] =
5277 NdefMap->SendRecvBuf[(TempLength +
5279 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5281 NdefMap->StdMifareContainer.RdAfterWrFlag =
5287 if(NdefMap->TLVStruct.prevLenByteValue >=
5290 NdefMap->SendRecvBuf[TempLength - PH_FRINFC_MIFARESTD_VAL1] =
5292 NdefMap->SendRecvBuf[TempLength] =
5293 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5295 NdefMap->SendRecvBuf[(TempLength +
5297 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5301 NdefMap->SendRecvBuf[TempLength] =
5303 NdefMap->SendRecvBuf[(TempLength +
5305 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5306 NdefMap->StdMifareContainer.RdAfterWrFlag =
5313 if(NdefMap->TLVStruct.prevLenByteValue >=
5317 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
5318 NdefMap->TLVStruct.NdefTLVBlock =
5319 NdefMap->StdMifareContainer.currentBlock;
5320 NdefMap->TLVStruct.NdefTLVByte =
5323 NdefMap->SendRecvBuf[(TempLength - PH_FRINFC_MIFARESTD_VAL2)] =
5325 NdefMap->SendRecvBuf[(TempLength - PH_FRINFC_MIFARESTD_VAL1)] =
5327 NdefMap->SendRecvBuf[TempLength] =
5328 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5333 NdefMap->SendRecvBuf[TempLength] =
5340 if(NdefMap->TLVStruct.prevLenByteValue >=
5344 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
5345 NdefMap->TLVStruct.NdefTLVBlock =
5346 NdefMap->StdMifareContainer.currentBlock;
5347 NdefMap->TLVStruct.NdefTLVByte =
5350 NdefMap->SendRecvBuf[(TempLength - PH_FRINFC_MIFARESTD_VAL2)] =
5352 NdefMap->SendRecvBuf[(TempLength - PH_FRINFC_MIFARESTD_VAL1)] =
5354 NdefMap->SendRecvBuf[TempLength] =
5355 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5357 NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL1)] =
5358 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5362 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5363 NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_MIFARESTD_VAL1)] =
5364 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5366 NdefMap->StdMifareContainer.RdAfterWrFlag =
5372 static void phFriNfc_MifStd_H_fillTLV2(phFriNfc_NdefMap_t *NdefMap)
5374 uint8_t TempLength = (uint8_t)(NdefMap->TLVStruct.NdefTLVByte +
5377 NdefMap->TLVStruct.prevLenByteValue = ((NdefMap->Offset ==
5379 (NdefMap->TLVStruct.prevLenByteValue +
5380 NdefMap->ApduBuffIndex):
5381 NdefMap->ApduBuffIndex);
5382 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG1;
5383 switch(NdefMap->TLVStruct.NdefTLVByte)
5386 if(NdefMap->TLVStruct.prevLenByteValue >=
5389 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5391 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L;
5393 NdefMap->SendRecvBuf[TempLength] = (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5398 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5400 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5404 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL2;
5405 NdefMap->TLVStruct.NdefTLVBlock =
5406 NdefMap->StdMifareContainer.currentBlock;
5407 NdefMap->TLVStruct.NdefTLVByte =
5410 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5415 if(NdefMap->TLVStruct.prevLenByteValue >=
5418 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5420 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L;
5424 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5426 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5431 if(NdefMap->TLVStruct.prevLenByteValue >=
5434 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5438 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5443 if(NdefMap->TLVStruct.prevLenByteValue >=
5446 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5448 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_L;
5450 NdefMap->SendRecvBuf[TempLength] = (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5453 NdefMap->SendRecvBuf[TempLength] =
5454 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5458 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5460 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5464 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL2;
5465 NdefMap->TLVStruct.NdefTLVBlock =
5466 NdefMap->StdMifareContainer.currentBlock;
5467 NdefMap->TLVStruct.NdefTLVByte =
5470 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5472 NdefMap->SendRecvBuf[TempLength] =
5473 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5475 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
5480 static NFCSTATUS phFriNfc_MifStd_H_CallWrNdefLen(phFriNfc_NdefMap_t *NdefMap)
5483 if(NdefMap->TLVStruct.NULLTLVCount >= PH_FRINFC_MIFARESTD_VAL2)
5485 if((NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL0) ||
5486 (NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL1) )
5490 NdefMap->StdMifareContainer.currentBlock--;
5491 Result = phFriNfc_MifStd_H_BlkChk_1(NdefMap);
5495 /* case NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL15:
5498 NdefMap->StdMifareContainer.currentBlock++;
5499 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5504 if((NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL13) ||
5505 (NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL14) ||
5506 (NdefMap->TLVStruct.NdefTLVByte == PH_FRINFC_MIFARESTD_VAL15))
5510 NdefMap->StdMifareContainer.currentBlock++;
5511 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5516 phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap):
5521 static NFCSTATUS phFriNfc_MifStd_H_BlkChk_1(phFriNfc_NdefMap_t *NdefMap)
5531 SectorID = phFriNfc_MifStd_H_GetSect(NdefMap->StdMifareContainer.currentBlock);
5535 if((NdefMap->StdMifareContainer.aid[SectorID] ==
5538 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD)) ||
5540 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))))
5542 if(NdefMap->StdMifareContainer.currentBlock > 128)
5544 NdefMap->TLVStruct.NdefTLVAuthFlag =
5545 ((((NdefMap->StdMifareContainer.currentBlock +
5552 NdefMap->StdMifareContainer.currentBlock -=
5553 ((((NdefMap->StdMifareContainer.currentBlock +
5563 NdefMap->TLVStruct.NdefTLVAuthFlag =
5564 ((((NdefMap->StdMifareContainer.currentBlock +
5571 NdefMap->StdMifareContainer.currentBlock -=
5572 ((((NdefMap->StdMifareContainer.currentBlock +
5591 static void phFriNfc_MifStd_H_fillTLV1_1(phFriNfc_NdefMap_t *NdefMap)
5593 switch(NdefMap->TLVStruct.NdefTLVByte)
5599 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
5600 NdefMap->TLVStruct.NdefTLVBlock =
5601 NdefMap->StdMifareContainer.currentBlock;
5602 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_MIFARESTD_VAL14;
5604 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL15] =
5606 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL16] =
5614 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL0;
5615 NdefMap->TLVStruct.NdefTLVBlock =
5616 NdefMap->StdMifareContainer.currentBlock;
5617 NdefMap->TLVStruct.NdefTLVByte =
5619 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL16] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5626 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL1] =
5627 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5630 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
5633 static void phFriNfc_MifStd_H_fillTLV2_1(phFriNfc_NdefMap_t *NdefMap)
5636 switch(NdefMap->TLVStruct.NdefTLVByte)
5641 NdefMap->SendRecvBuf[TempLength] =
5642 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5648 if(NdefMap->TLVStruct.prevLenByteValue >=
5651 NdefMap->SendRecvBuf[TempLength] =
5652 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5655 NdefMap->SendRecvBuf[TempLength] =
5656 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5660 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL2;
5661 NdefMap->TLVStruct.NdefTLVBlock =
5662 NdefMap->StdMifareContainer.currentBlock;
5663 NdefMap->TLVStruct.NdefTLVByte =
5665 NdefMap->SendRecvBuf[TempLength] = PH_FRINFC_MIFARESTD_NDEFTLV_T;
5667 NdefMap->SendRecvBuf[TempLength] =
5668 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5674 if(NdefMap->TLVStruct.prevLenByteValue >=
5679 NdefMap->SendRecvBuf[TempLength] =
5682 NdefMap->SendRecvBuf[TempLength] =
5683 (uint8_t)(NdefMap->TLVStruct.prevLenByteValue >>
5686 NdefMap->SendRecvBuf[TempLength] =
5687 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5691 NdefMap->SendRecvBuf[TempLength] =
5694 NdefMap->TLVStruct.NULLTLVCount = PH_FRINFC_MIFARESTD_VAL2;
5695 NdefMap->TLVStruct.NdefTLVBlock =
5696 NdefMap->StdMifareContainer.currentBlock;
5697 NdefMap->TLVStruct.NdefTLVByte =
5699 NdefMap->SendRecvBuf[TempLength] =
5702 NdefMap->SendRecvBuf[TempLength] =
5703 (uint8_t)NdefMap->TLVStruct.prevLenByteValue;
5707 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
5710 static NFCSTATUS phFriNfc_MifStd_H_RdTLV(phFriNfc_NdefMap_t *NdefMap)
5713 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RD_TLV;
5714 NdefMap
5716 Result = phFriNfc_MifStd_H_Rd16Bytes(NdefMap,
5717 NdefMap->StdMifareContainer.currentBlock);
5721 static NFCSTATUS phFriNfc_MifStd_H_ProRdTLV(phFriNfc_NdefMap_t *NdefMap)
5728 /*TempLength = (uint8_t)(((NdefMap->TLVStruct.NULLTLVCount >=
5730 (NdefMap->TLVStruct.BytesRemainLinTLV > 0xFE))?
5731 ((NdefMap->TLVStruct.NdefTLVByte +
5734 ((NdefMap->TLVStruct.NdefTLVByte +
5738 TempLength = (uint8_t)((NdefMap->TLVStruct.BytesRemainLinTLV <= 0xFE)?
5739 ((NdefMap->TLVStruct.NdefTLVByte +
5742 ((NdefMap->TLVStruct.NdefTLVByte +
5746 if((*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ) &&
5747 (NdefMap->ApduBuffIndex < NdefMap->ApduBufferSize))
5749 if(NdefMap->TLVStruct.BytesRemainLinTLV != 0)
5753 Result = phFriNfc_MifStd_H_RemainTLV(NdefMap, &NDEFFlag, &TempLength);
5759 static NFCSTATUS phFriNfc_MifStd_H_WrTermTLV(phFriNfc_NdefMap_t *NdefMap)
5765 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_TERM_TLV;
5767 NdefMap->SendRecvBuf[index] =
5768 NdefMap->StdMifareContainer.currentBlock;
5770 NdefMap->SendRecvBuf[index] = PH_FRINFC_MIFARESTD_TERMTLV_T;
5775 NdefMap->SendRecvBuf[index] = PH_FRINFC_MIFARESTD_NULLTLV_T;
5779 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_MIFARESTD_FLAG0;
5781 Result = phFriNfc_MifStd_H_WrTLV(NdefMap);
5787 static NFCSTATUS phFriNfc_MifStd_H_ProWrABlock(phFriNfc_NdefMap_t *NdefMap)
5791 NdefMap->StdMifareContainer.WrLength = PH_FRINFC_MIFARESTD_VAL0;
5792 if(NdefMap->ApduBuffIndex <
5793 (uint16_t)NdefMap->ApduBufferSize)
5796 if(NdefMap->StdMifareContainer.RemainingBufFlag ==
5800 NdefMap->StdMifareContainer.internalLength =
5801 *NdefMap->DataCount;
5805 (void)memcpy( NdefMap->StdMifareContainer.internalBuf,
5806 NdefMap->StdMifareContainer.Buffer,
5807 NdefMap->StdMifareContainer.internalLength);
5810 NdefMap->ApduBuffIndex += NdefMap->NumOfBytesWritten;
5812 NdefMap->StdMifareContainer.remainingSize -=
5813 NdefMap->NumOfBytesWritten;
5815 NdefMap->StdMifareContainer.RemainingBufFlag = PH_FRINFC_MIFARESTD_VAL0;
5817 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
5818 (uint8_t)((NdefMap->StdMifareContainer.remainingSize ==
5823 NdefMap->TLVStruct.SetTermTLVFlag =
5824 (uint8_t)(((NdefMap->StdMifareContainer.remainingSize ==
5826 (NdefMap->TLVStruct.SetTermTLVFlag ==
5832 else if(NdefMap->StdMifareContainer.internalBufFlag ==
5835 (void)memcpy(NdefMap->StdMifareContainer.internalBuf,
5836 NdefMap->StdMifareContainer.Buffer,
5837 *NdefMap->DataCount);
5839 NdefMap->StdMifareContainer.internalLength =
5840 *NdefMap->DataCount;
5843 NdefMap->ApduBuffIndex +=
5844 NdefMap->NumOfBytesWritten;
5846 NdefMap->StdMifareContainer.remainingSize -=
5847 NdefMap->NumOfBytesWritten;
5849 NdefMap->StdMifareContainer.internalBufFlag =
5852 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
5853 (uint8_t)(((NdefMap->StdMifareContainer.remainingSize ==
5855 (NdefMap->StdMifareContainer.internalLength ==
5860 NdefMap->TLVStruct.SetTermTLVFlag =
5861 (uint8_t)(((NdefMap->StdMifareContainer.remainingSize ==
5863 (NdefMap->TLVStruct.SetTermTLVFlag ==
5870 NdefMap->StdMifareContainer.internalLength = 0;
5872 NdefMap->ApduBuffIndex +=
5873 NdefMap->NumOfBytesWritten;
5874 NdefMap->StdMifareContainer.remainingSize -=
5875 NdefMap->NumOfBytesWritten;
5878 if((NdefMap->StdMifareContainer.remainingSize ==
5880 (NdefMap->ApduBuffIndex == NdefMap->ApduBufferSize))
5882 NdefMap->StdMifareContainer.ReadWriteCompleteFlag =
5883 (uint8_t)((NdefMap->StdMifareContainer.remainingSize == 0)?
5886 if(NdefMap->StdMifareContainer.internalLength ==
5889 NdefMap->StdMifareContainer.currentBlock++;
5892 Result = ((NdefMap->StdMifareContainer.remainingSize == 0)?
5894 phFriNfc_MifStd_H_BlkChk(NdefMap));
5895 NdefMap->StdMifareContainer.NdefBlocks++;
5897 NdefMap->TLVStruct.SetTermTLVFlag =
5898 (uint8_t)(((NdefMap->StdMifareContainer.remainingSize ==
5900 (NdefMap->TLVStruct.SetTermTLVFlag ==
5907 NdefMap->StdMifareContainer.currentBlock++;
5908 NdefMap->StdMifareContainer.WrLength =
5909 (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
5912 Result = phFriNfc_MifStd_H_BlkChk(NdefMap);
5915 NdefMap->StdMifareContainer.NdefBlocks++;
5916 Result = ((NdefMap->StdMifareContainer.AuthDone ==
5918 phFriNfc_MifStd_H_WrABlock(NdefMap):
5919 phFriNfc_MifStd_H_AuthSector(NdefMap));
5931 (NdefMap->TLVStruct.SetTermTLVFlag !=
5933 (NdefMap->StdMifareContainer.remainingSize >
5936 Result = phFriNfc_MifStd_H_WrTermTLV(NdefMap);
5941 (NdefMap->TLVStruct.SetTermTLVFlag ==
5945 NdefMap->StdMifareContainer.TempBlockNo =
5946 NdefMap->StdMifareContainer.currentBlock;
5947 phFriNfc_MifStd_H_SetNdefBlkAuth(NdefMap);
5948 NdefMap->StdMifareContainer.currentBlock =
5949 NdefMap->TLVStruct.NdefTLVBlock;
5950 Result = phFriNfc_MifStd_H_RdtoWrNdefLen(NdefMap);
5956 static NFCSTATUS phFriNfc_MifStd_H_CallDisCon(phFriNfc_NdefMap_t *NdefMap)
5960 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_DISCONNECT;
5961 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
5962 NdefMap->MapCompletionInfo.Context = NdefMap;
5966 Result = phFriNfc_OvrHal_Disconnect( NdefMap->LowerDevice,
5967 &NdefMap->MapCompletionInfo,
5968 NdefMap->psRemoteDevInfo);
5971 Result = phFriNfc_OvrHal_Reconnect( NdefMap->LowerDevice,
5972 &NdefMap->MapCompletionInfo,
5973 NdefMap->psRemoteDevInfo);
5980 static NFCSTATUS phFriNfc_MifStd_H_CallPoll(phFriNfc_NdefMap_t *NdefMap)
5984 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_POLL;
5986 NdefMap->OpModeType[PH_FRINFC_MIFARESTD_VAL0] = phHal_eOpModesMifare;
5987 NdefMap->OpModeType[PH_FRINFC_MIFARESTD_VAL1] = phHal_eOpModesArrayTerminator;
5990 NdefMap->NoOfDevices = PH_FRINFC_MIFARESTD_VAL1;
5993 Result = phFriNfc_OvrHal_Poll( NdefMap->LowerDevice,
5994 &NdefMap->MapCompletionInfo,
5995 NdefMap->OpModeType,
5996 NdefMap->psRemoteDevInfo,
5997 &NdefMap->NoOfDevices,
5998 NdefMap->StdMifareContainer.DevInputParam);
6003 static NFCSTATUS phFriNfc_MifStd_H_CallConnect(phFriNfc_NdefMap_t *NdefMap)
6007 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_CONNECT;
6010 Result = phFriNfc_OvrHal_Connect( NdefMap->LowerDevice,
6011 &NdefMap->MapCompletionInfo,
6012 NdefMap->psRemoteDevInfo,
6013 NdefMap->StdMifareContainer.DevInputParam);
6017 static void phFriNfc_MifStd1k_H_BlkChk(phFriNfc_NdefMap_t *NdefMap,
6022 if(((NdefMap->StdMifareContainer.currentBlock + PH_FRINFC_MIFARESTD_INC_1) %
6025 NdefMap->StdMifareContainer.currentBlock++;
6029 if(NdefMap->StdMifareContainer.aid[SectorID] ==
6036 if((NdefMap->StdMifareContainer.currentBlock ==
6038 (NdefMap->StdMifareContainer.internalLength == 0))
6040 NdefMap->StdMifareContainer.AuthDone = 0;
6046 NdefMap->StdMifareContainer.currentBlock += PH_FRINFC_MIFARESTD_BLK4;
6062 phFriNfc_NdefMap_t *NdefMap,
6068 if ( NdefMap == NULL)
6072 else if ( PH_NDEFMAP_CARD_STATE_INVALID == NdefMap->CardState )
6080 if( PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD == NdefMap->CardType )
6084 else if ( PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD == NdefMap->CardType )
6092 memset (NdefMap->StdMifareContainer.UserScrtKeyB, PH_FRINFC_MFSTD_FMT_DEFAULT_KEY,
6097 memcpy (NdefMap->StdMifareContainer.UserScrtKeyB, ScrtKeyB, PH_FRINFC_MIFARESTD_KEY_LEN);
6100 NdefMap->StdMifareContainer.TotalNoSectors = totalNoSectors;
6107 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_MIFARESTD_FLAG0;
6108 NdefMap->StdMifareContainer.RdBeforeWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
6109 NdefMap->StdMifareContainer.WrNdefFlag = PH_FRINFC_MIFARESTD_FLAG0;
6110 NdefMap->StdMifareContainer.internalLength = PH_FRINFC_MIFARESTD_VAL0;
6111 NdefMap->StdMifareContainer.RdAfterWrFlag = PH_FRINFC_MIFARESTD_FLAG0;
6112 NdefMap->StdMifareContainer.AuthDone = PH_FRINFC_MIFARESTD_FLAG0;
6113 NdefMap->StdMifareContainer.NFCforumSectFlag = PH_FRINFC_MIFARESTD_FLAG0;
6114 NdefMap->StdMifareContainer.WriteAcsBitFlag = PH_FRINFC_MIFARESTD_FLAG0;
6117 for(NdefMap->StdMifareContainer.ReadOnlySectorIndex = PH_FRINFC_MIFARESTD_FLAG1;
6118 NdefMap->StdMifareContainer.ReadOnlySectorIndex < totalNoSectors;
6119 NdefMap
6122 if( PH_FRINFC_MIFARESTD_SECTOR_NO16 == NdefMap->StdMifareContainer.ReadOnlySectorIndex )
6129 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.ReadOnlySectorIndex])
6135 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.ReadOnlySectorIndex])
6139 phFriNfc_MifStd_H_GetSectorTrailerBlkNo(NdefMap->StdMifareContainer.ReadOnlySectorIndex);
6140 NdefMap->StdMifareContainer.currentBlock = sectorTrailerBlockNo;
6141 NdefMap->StdMifareContainer.SectorTrailerBlockNo = sectorTrailerBlockNo;
6145 result = phFriNfc_MifStd_H_AuthSector(NdefMap);
6155 if(NdefMap->StdMifareContainer.ReadOnlySectorIndex == totalNoSectors &&
6186 static NFCSTATUS phFriNfc_MifStd_H_ProSectorTrailorAcsBits(phFriNfc_NdefMap_t *NdefMap)
6190 if(*NdefMap->SendRecvLength == PH_FRINFC_MIFARESTD_BYTES_READ)
6192 if(NdefMap->StdMifareContainer.ReadAcsBitFlag ==
6196 Result = phFriNfc_MifStd_H_ChkAcsBit(NdefMap);
6200 if(NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY)
6203 Result = phFriNfc_MifStd_H_ProWrSectorTrailor(NdefMap);
6208 Result = phFriNfc_MifStd_H_WrSectorTrailorBlock(NdefMap);
6224 static NFCSTATUS phFriNfc_MifStd_H_WrSectorTrailorBlock(phFriNfc_NdefMap_t *NdefMap)
6229 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
6230 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
6231 NdefMap->psDepAdditionalInfo.NAD = 0;
6232 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareStdMap_Process;
6233 NdefMap->MapCompletionInfo.Context = NdefMap;
6234 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
6237 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_WRITE_SEC;
6240 if(NdefMap->SendRecvBuf != NULL)
6242 NdefMap->SendRecvBuf[10] = 0x00;
6243 NdefMap->SendRecvBuf[10] = NdefMap->SendRecvBuf[9] | PH_FRINFC_MIFARESTD_MASK_GPB_WR; /* WR bits 11*/
6245 /*The NdefMap->SendRecvBuf already has the sector trailor.
6247 NdefMap->SendRecvBuf[1] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
6248 NdefMap->SendRecvBuf[2] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
6249 NdefMap->SendRecvBuf[3] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
6250 NdefMap->SendRecvBuf[4] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
6251 NdefMap->SendRecvBuf[5] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT1; /* 0xD3 */
6252 NdefMap->SendRecvBuf[6] = PH_FRINFC_NDEFMAP_MIFARESTD_AUTH_NDEFSECT2; /* 0xF7 */
6254 NdefMap->SendRecvBuf[7] = PH_FRINFC_MIFARESTD_NFCSECT_RDACS_BYTE6;/* 0x07 */
6255 NdefMap->SendRecvBuf[8] = PH_FRINFC_MIFARESTD_NFCSECT_RDACS_BYTE7;/* 0x8F */
6256 NdefMap->SendRecvBuf[9] = PH_FRINFC_MIFARESTD_NFCSECT_RDACS_BYTE8;/* 0x0F */
6258 NdefMap->SendRecvBuf[11] = NdefMap->StdMifareContainer.UserScrtKeyB[0];
6259 NdefMap->SendRecvBuf[12] = NdefMap->StdMifareContainer.UserScrtKeyB[1];
6260 NdefMap->SendRecvBuf[13] = NdefMap->StdMifareContainer.UserScrtKeyB[2];
6261 NdefMap->SendRecvBuf[14] = NdefMap->StdMifareContainer.UserScrtKeyB[3];
6262 NdefMap->SendRecvBuf[15] = NdefMap->StdMifareContainer.UserScrtKeyB[4];
6263 NdefMap->SendRecvBuf[16] = NdefMap->StdMifareContainer.UserScrtKeyB[5];
6266 NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL0] = NdefMap->StdMifareContainer.currentBlock;
6269 (void)memcpy(NdefMap->StdMifareContainer.Buffer,
6270 &(NdefMap->SendRecvBuf[PH_FRINFC_MIFARESTD_VAL1]),
6274 NdefMap->SendLength = MIFARE_MAX_SEND_BUF_TO_WRITE;
6276 NdefMap->Cmd.MfCmd = phHal_eMifareCmdListMifareWrite16;
6278 NdefMap->Cmd.MfCmd = phHal_eMifareWrite16;
6280 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
6283 status = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
6284 &NdefMap->MapCompletionInfo,
6285 NdefMap->psRemoteDevInfo,
6286 NdefMap->Cmd,
6287 &NdefMap->psDepAdditionalInfo,
6288 NdefMap->SendRecvBuf,
6289 NdefMap->SendLength,
6290 NdefMap->SendRecvBuf,
6291 NdefMap->SendRecvLength);
6308 static NFCSTATUS phFriNfc_MifStd_H_ProWrSectorTrailor(phFriNfc_NdefMap_t *NdefMap)
6314 NdefMap->StdMifareContainer.ReadOnlySectorIndex++;
6317 if(PH_FRINFC_MIFARESTD_SECTOR_NO16 == NdefMap->StdMifareContainer.ReadOnlySectorIndex )
6319 NdefMap->StdMifareContainer.ReadOnlySectorIndex++;
6325 if (NdefMap->StdMifareContainer.ReadOnlySectorIndex >= NdefMap->StdMifareContainer.TotalNoSectors ||
6327 NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.ReadOnlySectorIndex])
6331 else if(PH_FRINFC_MIFARESTD_NDEF_COMP == NdefMap->StdMifareContainer.aid[NdefMap->StdMifareContainer.ReadOnlySectorIndex])
6334 sectorTrailerBlockNo = phFriNfc_MifStd_H_GetSectorTrailerBlkNo(NdefMap->StdMifareContainer.ReadOnlySectorIndex);
6335 NdefMap->StdMifareContainer.currentBlock = sectorTrailerBlockNo;
6336 NdefMap->StdMifareContainer.SectorTrailerBlockNo = sectorTrailerBlockNo;
6338 status = phFriNfc_MifStd_H_AuthSector(NdefMap);