Home | History | Annotate | Download | only in src

Lines Matching defs:NdefMap

51 static void phFriNfc_MifareUL_H_Complete(phFriNfc_NdefMap_t  *NdefMap,
58 static NFCSTATUS phFriNfc_MfUL_H_Rd16Bytes( phFriNfc_NdefMap_t *NdefMap);
64 static NFCSTATUS phFriNfc_MfUL_H_findNDEFTLV(phFriNfc_NdefMap_t *NdefMap,
71 static NFCSTATUS phFriNfc_MfUL_H_Chk16Bytes(phFriNfc_NdefMap_t *NdefMap,
79 static NFCSTATUS phFriNfc_MfUL_H_RdCardfindNdefTLV( phFriNfc_NdefMap_t *NdefMap,
86 static NFCSTATUS phFriNfc_MfUL_H_ChkRemainTLV(phFriNfc_NdefMap_t *NdefMap,
94 static void phFriNfc_MfUL_H_UpdateLen(phFriNfc_NdefMap_t *NdefMap,
101 static NFCSTATUS phFriNfc_MfUL_H_NxtOp(phFriNfc_NdefMap_t *NdefMap,
108 static NFCSTATUS phFriNfc_MfUL_H_CopyRdBytes(phFriNfc_NdefMap_t *NdefMap);
114 static NFCSTATUS phFriNfc_MfUL_H_CpDataToUserBuf(phFriNfc_NdefMap_t *NdefMap);
120 static NFCSTATUS phFriNfc_MfUL_H_Wr4bytes(phFriNfc_NdefMap_t *NdefMap);
126 static NFCSTATUS phFriNfc_MfUL_H_ChkCCBytes(phFriNfc_NdefMap_t *NdefMap);
132 static NFCSTATUS phFriNfc_MfUL_H_RdBeforeWrite(phFriNfc_NdefMap_t *NdefMap);
138 static NFCSTATUS phFriNfc_MfUL_H_CallWrOp(phFriNfc_NdefMap_t *NdefMap);
144 static NFCSTATUS phFriNfc_MfUL_H_ProWrittenBytes(phFriNfc_NdefMap_t *NdefMap);
150 static NFCSTATUS phFriNfc_MfUL_H_fillSendBufToWr(phFriNfc_NdefMap_t *NdefMap);
156 static NFCSTATUS phFriNfc_MfUL_H_UpdateWrLen(phFriNfc_NdefMap_t *NdefMap);
162 static NFCSTATUS phFriNfc_MfUL_H_WrTermTLV(phFriNfc_NdefMap_t *NdefMap);
168 phFriNfc_NdefMap_t *NdefMap);
175 static NFCSTATUS phFriNfc_MfUL_H_SelectSector(phFriNfc_NdefMap_t *NdefMap,
193 phFriNfc_MfUL_CalcByteNum(phFriNfc_NdefMap_t *NdefMap);
200 NFCSTATUS phFriNfc_MifareUL_H_Reset(phFriNfc_NdefMap_t *NdefMap)
204 if ( NdefMap == NULL)
211 NdefMap->TLVStruct.NdefTLVBlock = PH_FRINFC_NDEFMAP_MFUL_VAL4;
212 NdefMap->TLVStruct.BytesRemainLinTLV = PH_FRINFC_NDEFMAP_MFUL_VAL0;
213 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_NDEFMAP_MFUL_VAL0;
214 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_NDEFMAP_MFUL_VAL0;
215 NdefMap->TLVStruct.prevLenByteValue = PH_FRINFC_NDEFMAP_MFUL_VAL0;
216 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
217 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
218 NdefMap->TLVStruct.ActualSize = PH_FRINFC_NDEFMAP_MFUL_VAL0;
219 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
220 NdefMap->TLVStruct.WrLenFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
223 NdefMap->MifareULContainer.ByteNumber = PH_FRINFC_NDEFMAP_MFUL_VAL0;
224 NdefMap->MifareULContainer.CRindex = PH_FRINFC_NDEFMAP_MFUL_VAL0;
225 NdefMap->MifareULContainer.CurrentSector = PH_FRINFC_NDEFMAP_MFUL_VAL0;
226 NdefMap->MifareULContainer.CurrentBlock = PH_FRINFC_NDEFMAP_MFUL_VAL0;
227 NdefMap->MifareULContainer.InternalLength = PH_FRINFC_NDEFMAP_MFUL_VAL0;
228 NdefMap->MifareULContainer.ReadBufIndex = PH_FRINFC_NDEFMAP_MFUL_VAL0;
229 NdefMap->MifareULContainer.ReadWriteCompleteFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
230 NdefMap->MifareULContainer.RemainingSize = PH_FRINFC_NDEFMAP_MFUL_VAL0;
233 (void)memset(NdefMap->TLVStruct.NdefTLVBuffer,
236 (void)memset(NdefMap->MifareULContainer.Buffer,
239 (void)memset(NdefMap->MifareULContainer.InternalBuf,
242 (void)memset(NdefMap->MifareULContainer.ReadBuf,
257 NFCSTATUS phFriNfc_MifareUL_RdNdef( phFriNfc_NdefMap_t *NdefMap,
265 if((NdefMap != NULL) && (PacketData != NULL) && (PacketDataLength != NULL) &&
268 (NdefMap->CompletionRoutine->CompletionRoutine != NULL) &&
269 (NdefMap->CompletionRoutine->Context != NULL ) &&
270 ((NdefMap->CardState != PH_NDEFMAP_CARD_STATE_INITIALIZED) &&
271 (NdefMap->CardState != PH_NDEFMAP_CARD_STATE_INVALID)))
273 /*Register PacketData to Data Buffer of NdefMap */
274 NdefMap->ApduBuffer = PacketData;
275 /*Register PacketDataLength to Data Length of NdefMap */
276 NdefMap->ApduBufferSize = *PacketDataLength ;
278 NdefMap->NumOfBytesRead = PacketDataLength ;
279 *NdefMap->NumOfBytesRead = 0;
281 if( (Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN) || ( NdefMap->PrevOperation ==
284 NdefMap->MifareULContainer.CurrentBlock = PH_FRINFC_NDEFMAP_MFUL_BLOCK4;
285 NdefMap->TLVStruct.NdefTLVFoundFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
286 NdefMap->TLVStruct.NdefTLVByte = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
287 NdefMap->TLVStruct.NdefTLVBlock = PH_FRINFC_NDEFMAP_MFUL_BLOCK4;
288 NdefMap->MifareULContainer.RemainingSize = NdefMap->CardMemSize;
289 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
290 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_NDEFMAP_MFUL_VAL0;
291 NdefMap->MifareULContainer.ReadBufIndex = PH_FRINFC_NDEFMAP_MFUL_VAL0;
292 NdefMap->MifareULContainer.ReadWriteCompleteFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
295 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
296 NdefMap->MifareULContainer.CRindex = PH_FRINFC_NDEFMAP_CR_RD_NDEF;
299 (NdefMap->MifareULContainer.ReadWriteCompleteFlag ==
310 NdefMap->Offset = (((Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN) &&
311 ( NdefMap->PrevOperation != PH_FRINFC_NDEFMAP_READ_OPE))?
315 Result = ((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN)?
316 phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap, NdefMap->MifareULContainer.CurrentBlock):
317 phFriNfc_MfUL_H_CpDataToUserBuf(NdefMap));
333 NFCSTATUS phFriNfc_MifareUL_WrNdef( phFriNfc_NdefMap_t *NdefMap,
343 if((NdefMap != NULL) && (PacketData != NULL) && (PacketDataLength != NULL) &&
346 (NdefMap->CompletionRoutine->CompletionRoutine != NULL) &&
347 (NdefMap->CompletionRoutine->Context != NULL ) &&
348 ((NdefMap->CardState != PH_NDEFMAP_CARD_STATE_READ_ONLY) &&
349 (NdefMap->CardState != PH_NDEFMAP_CARD_STATE_INVALID)))
351 NdefMap->MifareULContainer.CRindex = PH_FRINFC_NDEFMAP_CR_WR_NDEF;
352 /*Register PacketData to Data Buffer of NdefMap */
353 NdefMap->ApduBuffer = PacketData;
354 /*Register PacketDataLength to Data Length of NdefMap */
355 NdefMap->ApduBufferSize = *PacketDataLength ;
357 NdefMap->WrNdefPacketLength = PacketDataLength ;
358 *NdefMap->WrNdefPacketLength = 0;
360 if( (Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN) || ( NdefMap->PrevOperation ==
363 NdefMap->MifareULContainer.CurrentSector = NdefMap->TLVStruct.NdefTLVSector;
364 NdefMap->MifareULContainer.CurrentBlock = NdefMap->TLVStruct.NdefTLVBlock;
365 NdefMap->TLVStruct.TcheckedinTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
366 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_NDEFMAP_MFUL_VAL0;
367 NdefMap->MifareULContainer.ReadBufIndex = PH_FRINFC_NDEFMAP_MFUL_VAL0;
368 NdefMap->MifareULContainer.ReadWriteCompleteFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
369 NdefMap->TLVStruct.WrLenFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG0;
370 NdefMap->MifareULContainer.InternalLength = PH_FRINFC_NDEFMAP_MFUL_VAL0;
371 NdefMap->MifareULContainer.RemainingSize =
372 (NdefMap->CardMemSize -
373 (((NdefMap->TLVStruct.NdefTLVBlock -
376 NdefMap->TLVStruct.NdefTLVByte +
379 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
380 NdefMap
383 (NdefMap->MifareULContainer.ReadWriteCompleteFlag ==
394 NdefMap->Offset = (((Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN) &&
395 ( NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE))?
399 if (NdefMap->TLVStruct.NdefTLVSector == 1)
401 NdefMap->MifareULContainer.CurrentSector = 1;
404 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
405 NdefMap->MifareULContainer.CurrentSector, 1,
411 Result = ((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN)?
412 phFriNfc_MfUL_H_RdBeforeWrite(NdefMap):
413 phFriNfc_MfUL_H_fillSendBufToWr(NdefMap));
431 NFCSTATUS phFriNfc_MifareUL_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
438 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
439 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
440 NdefMap->psDepAdditionalInfo.NAD = 0;
448 pSensRes[0] = NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.AtqA[0];
450 NdefMap->TLVStruct.NdefTLVBlock = PH_FRINFC_NDEFMAP_MFUL_VAL4;
452 NdefMap->MifareULContainer.CurrentBlock = PH_FRINFC_NDEFMAP_MFUL_BLOCK2;
454 NdefMap->MifareULContainer.CurrentBlock = PH_FRINFC_NDEFMAP_MFUL_BLOCK3;
456 NdefMap->MifareULContainer.CRindex = PH_FRINFC_NDEFMAP_CR_CHK_NDEF;
461 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_CHECK_OPE;
463 NdefMap->SendRecvBuf[index] = NdefMap->MifareULContainer.CurrentBlock;
466 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_MAX_SEND_BUF_TO_READ;
469 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_CHK_NDEF_COMP;
472 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_UL_CARD;
479 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
482 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareUL_Process;
483 NdefMap->MapCompletionInfo.Context = NdefMap;
486 *NdefMap->SendRecvLength = PH_FRINFC_NDEFMAP_MF_READ_BLOCK_SIZE;
490 status = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
491 &NdefMap->MapCompletionInfo,
492 NdefMap->psRemoteDevInfo,
493 NdefMap->Cmd,
494 &NdefMap->psDepAdditionalInfo,
495 NdefMap->SendRecvBuf,
496 NdefMap->SendLength,
497 NdefMap->SendRecvBuf,
498 NdefMap->SendRecvLength);
508 phFriNfc_MfUL_CalcByteNum(phFriNfc_NdefMap_t *NdefMap)
516 if ((NdefMap->MifareULContainer.ReadBuf[i] ==
518 ((NdefMap->MifareULContainer.ReadBuf[i + 1] ==
519 NdefMap->TLVStruct.ActualSize) ||
520 (NdefMap->MifareULContainer.ReadBuf[i + 1] == 0xFF)))
522 if (NdefMap->MifareULContainer.ReadBuf[i + 1] == 0xFF)
524 TemLength = NdefMap->MifareULContainer.ReadBuf[i + 2] |
525 ((uint16_t)NdefMap->MifareULContainer.ReadBuf[i + 3] << 8);
527 if (TemLength == NdefMap->TLVStruct.ActualSize)
529 NdefMap->MifareULContainer.ByteNumber = i + 1;
535 NdefMap->MifareULContainer.ByteNumber = i + 1;
554 phFriNfc_NdefMap_t *NdefMap)
558 if (((NdefMap->SendRecvBuf[index] &
561 (NdefMap->SendRecvBuf[(index + 1)] & MIF_UL_LOCK_BIT_CHECK)))
563 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
586 phFriNfc_NdefMap_t *NdefMap;
595 NdefMap = (phFriNfc_NdefMap_t *)Context;
599 switch (NdefMap->State)
602 if (*NdefMap->SendRecvLength ==
606 Status = phFriNfc_MfUL_H_ChkCCBytes(NdefMap);
616 phFriNfc_MfUL_H_ChkLockBits(NdefMap);
622 NdefMap->MifareULContainer.CurrentBlock = PH_FRINFC_NDEFMAP_MFUL_BLOCK4;
625 phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
626 NdefMap->MifareULContainer.CurrentBlock));
636 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
645 if (*NdefMap->SendRecvLength ==
648 if(NdefMap->MifareULContainer.ReadBufIndex <
649 (NdefMap->TLVStruct.ActualSize + (((NdefMap->TLVStruct.NdefTLVBlock -
651 * PH_FRINFC_NDEFMAP_MFUL_VAL4) + (NdefMap->TLVStruct.NdefTLVByte - 1) + 4)))
654 Status = phFriNfc_MfUL_H_CopyRdBytes(NdefMap);
659 if(NdefMap->MifareULContainer.ReadBufIndex >=
660 (NdefMap->TLVStruct.ActualSize + (((NdefMap->TLVStruct.NdefTLVBlock -
662 * PH_FRINFC_NDEFMAP_MFUL_VAL4) + (NdefMap->TLVStruct.NdefTLVByte - 1) + 4)))
665 phFriNfc_MfUL_CalcByteNum(NdefMap);
669 if ((NdefMap->MifareULContainer.ReadBuf[i] ==
671 ((NdefMap->MifareULContainer.ReadBuf[i + 1] ==
672 NdefMap->TLVStruct.ActualSize) ||
673 (NdefMap->MifareULContainer.ReadBuf[i + 1] == 0xFF)))
675 if (NdefMap->MifareULContainer.ReadBuf[i + 1] == 0xFF)
677 TemLength = NdefMap->MifareULContainer.ReadBuf[i + 2] |
678 ((uint16_t)NdefMap->MifareULContainer.ReadBuf[i + 3] << 8);
680 if (TemLength == NdefMap->TLVStruct.ActualSize)
682 NdefMap->MifareULContainer.ByteNumber = i + 1;
688 NdefMap->MifareULContainer.ByteNumber = i + 1;
695 if (NdefMap->MifareULContainer.ReadBuf
696 [NdefMap->MifareULContainer.ByteNumber] == 0xFF)
698 NdefMap->MifareULContainer.ByteNumber =
699 NdefMap->MifareULContainer.ByteNumber + 3;
703 NdefMap->MifareULContainer.ByteNumber =
704 NdefMap->MifareULContainer.ByteNumber + 1;
707 Status = phFriNfc_MfUL_H_CpDataToUserBuf(NdefMap);
708 if (NdefMap->MifareULContainer.CurrentSector > 0)
710 NdefMap->MifareULContainer.CurrentSector = 0;
711 NdefMap->PrevState = PH_FRINFC_NDEFMAP_MFUL_STATE_READ;
713 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
714 NdefMap->MifareULContainer.CurrentSector, 1,
727 Status = phFriNfc_MfUL_H_Rd16Bytes(NdefMap);
749 Status = phFriNfc_MfUL_H_ProWrittenBytes(NdefMap);
756 if (*NdefMap->SendRecvLength ==
759 switch(NdefMap->PrevOperation)
764 if(NdefMap->TLVStruct.NoLbytesinTLV >
767 Status = phFriNfc_MfUL_H_ChkRemainTLV(NdefMap, &CRFlag);
771 if(NdefMap->TLVStruct.NdefTLVFoundFlag !=
775 Status = phFriNfc_MfUL_H_findNDEFTLV(NdefMap, &CRFlag);
781 if((NdefMap->TLVStruct.NdefTLVFoundFlag ==
783 (NdefMap->TLVStruct.NoLbytesinTLV ==
790 if (NdefMap->MifareULContainer.CurrentSector > 0)
792 NdefMap->MifareULContainer.CurrentSector = 0;
793 NdefMap->PrevState = PH_FRINFC_NDEFMAP_MFUL_STATE_FND_NDEF_COMP;
795 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
796 NdefMap->MifareULContainer.CurrentSector, 1,
805 Status = phFriNfc_MfUL_H_NxtOp(NdefMap, &CRFlag);
813 NdefMap->PrevOperation))
815 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
822 Status = ((NdefMap->TLVStruct.WrLenFlag ==
824 phFriNfc_MfUL_H_UpdateWrLen(NdefMap):
825 phFriNfc_MfUL_H_CallWrOp(NdefMap));
842 Status = phFriNfc_MfUL_H_UpdateWrLen(NdefMap);
849 if(((((NdefMap->TLVStruct.NdefTLVByte -
852 (NdefMap->MifareULContainer.CurrentBlock ==
853 (NdefMap->TLVStruct.NdefTLVBlock +
855 (((NdefMap->TLVStruct.NdefTLVByte -
858 NdefMap->MifareULContainer.CurrentBlock ==
859 NdefMap->TLVStruct.NdefTLVBlock))))
861 (void)memcpy(NdefMap->MifareULContainer.InternalBuf,
862 NdefMap->MifareULContainer.Buffer,
863 NdefMap->MifareULContainer.InternalLength);
865 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
866 NdefMap->MifareULContainer.Buffer,
869 NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
872 NdefMap->CardState);
873 NdefMap->ApduBuffIndex = PH_FRINFC_NDEFMAP_MFUL_VAL0;
874 NdefMap->NumOfBytesWritten = PH_FRINFC_NDEFMAP_MFUL_VAL0;
876 if (NdefMap->MifareULContainer.CurrentSector > 0)
879 NdefMap->MifareULContainer.CurrentSector = 0;
880 NdefMap->PrevState = PH_FRINFC_NDEFMAP_MFUL_STATE_WR_LEN_TLV;
882 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
883 NdefMap->MifareULContainer.CurrentSector, 1,
898 if (*NdefMap->SendRecvLength ==
901 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
904 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
905 NdefMap->MifareULContainer.CurrentSector, 2,
928 NdefMap->MifareULContainer.CurrentBlock +=
931 Status = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
932 NdefMap->MifareULContainer.CurrentBlock);
938 if (*NdefMap->SendRecvLength ==
941 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
944 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
945 NdefMap->MifareULContainer.CurrentSector, 2,
969 if (NdefMap->MifareULContainer.CurrentBlock == 0xFF)
971 NdefMap->MifareULContainer.CurrentBlock = 0;
975 NdefMap->MifareULContainer.CurrentBlock =
976 (NdefMap->TLVStruct.NdefTLVBlock / 4) * 4;
979 Status = phFriNfc_MfUL_H_Rd16Bytes(NdefMap);
988 if (*NdefMap->SendRecvLength ==
991 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
994 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
995 NdefMap->MifareULContainer.CurrentSector, 2,
1018 NdefMap->MifareULContainer.CurrentBlock = 0;
1019 Status = phFriNfc_MfUL_H_fillSendBufToWr(NdefMap);
1022 (NdefMap->TLVStruct.SetTermTLVFlag !=
1024 (NdefMap->MifareULContainer.RemainingSize >
1027 Status = phFriNfc_MfUL_H_WrTermTLV(NdefMap);
1032 (NdefMap->TLVStruct.SetTermTLVFlag ==
1035 Status = phFriNfc_MfUL_H_UpdateWrLen(NdefMap);
1047 if (*NdefMap->SendRecvLength ==
1050 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
1053 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
1054 NdefMap->MifareULContainer.CurrentSector, 2,
1077 Status = ((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN)?
1078 phFriNfc_MfUL_H_RdBeforeWrite(NdefMap):
1079 phFriNfc_MfUL_H_fillSendBufToWr(NdefMap));
1091 if (*NdefMap->SendRecvLength ==
1094 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
1097 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
1098 NdefMap->MifareULContainer.CurrentSector, 2,
1121 NdefMap->MifareULContainer.CurrentBlock = 0;
1123 NdefMap->SendRecvBuf[index] =
1124 NdefMap->MifareULContainer.CurrentBlock;
1126 NdefMap->SendRecvBuf[index] =
1130 if((((NdefMap->TLVStruct.NdefTLVByte -
1132 ((NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1)
1136 TemLength = (((NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1) ==
1141 if(NdefMap->ApduBufferSize >= TemLength)
1144 (void)memcpy(&(NdefMap->SendRecvBuf[
1146 &(NdefMap->ApduBuffer[
1147 NdefMap->ApduBuffIndex]),
1151 NdefMap->NumOfBytesWritten = TemLength;
1155 *NdefMap->DataCount = (index - PH_FRINFC_NDEFMAP_MFUL_VAL1);
1160 (void)memcpy(&(NdefMap->SendRecvBuf[
1162 &(NdefMap->ApduBuffer[
1163 NdefMap->ApduBuffIndex]),
1164 (uint16_t)NdefMap->ApduBufferSize);
1167 NdefMap->NumOfBytesWritten = (uint16_t)NdefMap->ApduBufferSize;
1169 index= index +(uint8_t)NdefMap->ApduBufferSize;
1171 *NdefMap->DataCount = (index - PH_FRINFC_NDEFMAP_MFUL_VAL1);
1175 NdefMap->SendRecvBuf[i] = (uint8_t)((i == index)?
1178 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG1;
1184 (void)memcpy(NdefMap->MifareULContainer.Buffer,
1185 &(NdefMap->SendRecvBuf[
1190 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
1191 NdefMap->MifareULContainer.Buffer,
1196 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE;
1198 Status = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
1210 if (*NdefMap->SendRecvLength ==
1213 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] == 0x0A)
1216 Status = phFriNfc_MfUL_H_SelectSector(NdefMap,
1217 NdefMap->MifareULContainer.CurrentSector, 2,
1240 if (NdefMap->PrevState == PH_FRINFC_NDEFMAP_MFUL_STATE_FND_NDEF_COMP)
1242 Status = phFriNfc_MfUL_H_NxtOp(NdefMap, &CRFlag);
1244 else if (NdefMap->PrevState == PH_FRINFC_NDEFMAP_MFUL_STATE_READ)
1248 else if (NdefMap->PrevState == PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE)
1250 Status = phFriNfc_MfUL_H_UpdateWrLen(NdefMap);
1255 else if (NdefMap->PrevState == PH_FRINFC_NDEFMAP_MFUL_STATE_WR_LEN_TLV)
1273 phFriNfc_MifareUL_H_Complete(NdefMap, Status);
1279 phFriNfc_MifareUL_H_Complete(NdefMap, Status);
1284 phFriNfc_MifareUL_H_Complete(NdefMap,Status);
1288 static NFCSTATUS phFriNfc_MfUL_H_ChkCCBytes(phFriNfc_NdefMap_t *NdefMap )
1294 switch(NdefMap->SendRecvBuf[7])
1296 switch(NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE3])
1302 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INITIALIZED;
1306 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
1310 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
1318 if(( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE4] ==
1320 if(( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE0] ==
1323 (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INITIALIZED) ||
1324 (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY)))
1327 Result =phFriNfc_MapTool_ChkSpcVer( NdefMap,
1341 if (NdefMap->SendRecvBuf[6] == 0x06)
1343 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_UL_CARD;
1345 else if (NdefMap->SendRecvBuf[6] == 0x12)
1347 // NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_ULC_CARD;
1348 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_UL_CARD;
1353 if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE2] == 0x06)
1355 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_UL_CARD;
1357 else if (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE2] == 0x12)
1359 // NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_ULC_CARD;
1360 NdefMap->CardType = PH_FRINFC_NDEFMAP_MIFARE_UL_CARD;
1375 Result = ((( NdefMap->SendRecvBuf[6] !=
1377 Result = ((( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE2] !=
1386 NdefMap->MifareULContainer.RemainingSize =
1387 NdefMap->CardMemSize = ((Result == NFCSTATUS_SUCCESS)?
1389 (NdefMap->SendRecvBuf[6] *
1391 (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_BYTE2] *
1394 NdefMap->CardMemSize);
1396 if (NdefMap->CardMemSize > 256)
1398 NdefMap->CardMemSize = NdefMap->CardMemSize - 2;
1399 NdefMap->MifareULContainer.RemainingSize = NdefMap->CardMemSize;
1405 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
1420 static void phFriNfc_MifareUL_H_Complete(phFriNfc_NdefMap_t *NdefMap,
1423 if(NdefMap!=NULL)
1425 if((PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE == NdefMap->State)
1428 *NdefMap->WrNdefPacketLength = 0;
1431 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
1434 NdefMap->CompletionRoutine[NdefMap->MifareULContainer.CRindex].
1435 CompletionRoutine(NdefMap->CompletionRoutine->Context, Status);
1439 static NFCSTATUS phFriNfc_MfUL_H_Rd16Bytes( phFriNfc_NdefMap_t *NdefMap)
1444 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_READ;
1447 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
1450 if(NdefMap->ApduBuffIndex < NdefMap->ApduBufferSize)
1453 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = PH_FRINFC_NDEFMAP_MFUL_VAL0;
1454 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = PH_FRINFC_NDEFMAP_MFUL_VAL0;
1455 NdefMap->psDepAdditionalInfo.NAD = PH_FRINFC_NDEFMAP_MFUL_VAL0;
1456 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] =
1457 NdefMap->MifareULContainer.CurrentBlock;
1458 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_VAL1;
1459 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1465 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
1468 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1469 &NdefMap->MapCompletionInfo,
1470 NdefMap->psRemoteDevInfo,
1471 NdefMap->Cmd,
1472 &NdefMap->psDepAdditionalInfo,
1473 NdefMap->SendRecvBuf,
1474 NdefMap->SendLength,
1475 NdefMap->SendRecvBuf,
1476 NdefMap->SendRecvLength);
1481 static NFCSTATUS phFriNfc_MfUL_H_Wr4bytes( phFriNfc_NdefMap_t *NdefMap)
1486 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1488 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
1495 NdefMap->Cmd.MfCmd = phHal_eMifareWrite4;
1498 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_MifareUL_Process;
1499 NdefMap->MapCompletionInfo.Context = NdefMap;
1501 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_WR_A_BLK;
1503 Result = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
1504 &NdefMap->MapCompletionInfo,
1505 NdefMap->psRemoteDevInfo,
1506 NdefMap->Cmd,
1507 &NdefMap->psDepAdditionalInfo,
1508 NdefMap->SendRecvBuf,
1509 NdefMap->SendLength,
1510 NdefMap->SendRecvBuf,
1511 NdefMap->SendRecvLength);
1515 static NFCSTATUS phFriNfc_MfUL_H_findNDEFTLV(phFriNfc_NdefMap_t *NdefMap,
1522 Temp16Bytes = ((NdefMap->TLVStruct.NdefTLVByte > PH_FRINFC_NDEFMAP_MFUL_VAL0)?
1523 (NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1):
1524 NdefMap->TLVStruct.NdefTLVByte);
1527 if(NdefMap->SendRecvBuf[Temp16Bytes] ==
1530 NdefMap->MifareULContainer.RemainingSize -=
1536 if (NdefMap->MifareULContainer.RemainingSize ==
1548 Result = ((NdefMap->MifareULContainer.RemainingSize ==
1559 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1563 NdefMap->TLVStruct.NdefTLVBlock =
1564 NdefMap->TLVStruct.NdefTLVBlock + PH_FRINFC_NDEFMAP_MFUL_VAL4;
1571 Result = ((NdefMap->SendRecvBuf[Temp16Bytes] ==
1584 if ((NdefMap->SendRecvBuf[Temp16Bytes] ==
1586 (NdefMap->SendRecvBuf[Temp16Bytes] ==
1588 (NdefMap->SendRecvBuf[Temp16Bytes] ==
1592 NdefMap->TLVStruct.NdefTLVByte =
1597 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1601 NdefMap->TLVStruct.TcheckedinTLVFlag =
1603 NdefMap->TLVStruct.NoLbytesinTLV =
1608 NdefMap->MifareULContainer.RemainingSize -=
1611 if(NdefMap->MifareULContainer.RemainingSize ==
1619 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1623 NdefMap->TLVStruct.TcheckedinTLVFlag =
1625 NdefMap->TLVStruct.NoLbytesinTLV =
1633 if((NdefMap->SendRecvBuf[Temp16Bytes] ==
1635 ((NdefMap->SendRecvBuf[Temp16Bytes] ==
1637 (NdefMap->TLVStruct.NdefTLVFoundFlag !=
1650 NdefMap->TLVStruct.BytesRemainLinTLV =
1651 NdefMap->SendRecvBuf[Temp16Bytes];
1653 NdefMap->TLVStruct.ActualSize =
1654 NdefMap->SendRecvBuf[Temp16Bytes];
1656 if((NdefMap->MifareULContainer.RemainingSize <
1657 NdefMap->SendRecvBuf[Temp16Bytes]) ||
1658 (NdefMap->MifareULContainer.RemainingSize <
1660 (NdefMap->TLVStruct.BytesRemainLinTLV >
1661 (NdefMap->MifareULContainer.RemainingSize)) ||
1662 ((NdefMap->TLVStruct.BytesRemainLinTLV ==
1664 (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE)))
1673 if(NdefMap->TLVStruct.NdefTLVFoundFlag !=
1676 NdefMap->TLVStruct.NdefTLVByte =
1678 NdefMap->SendRecvBuf[Temp16Bytes]) %
1682 NdefMap->TLVStruct.NdefTLVBlock =
1683 (uint8_t)(NdefMap->TLVStruct.NdefTLVBlock
1685 NdefMap->SendRecvBuf[Temp16Bytes] + 1)/
1688 NdefMap->TLVStruct.NdefTLVBlock =
1689 (uint8_t)(((NdefMap->TLVStruct.NdefTLVBlock / PH_FRINFC_NDEFMAP_MFUL_VAL4) *
1691 + ((Temp16Bytes + NdefMap->SendRecvBuf[Temp16Bytes] + 1)/
1696 NdefMap->SendRecvBuf[Temp16Bytes]);
1698 NdefMap->MifareULContainer.RemainingSize =
1699 (NdefMap->MifareULContainer.RemainingSize -
1700 (NdefMap->SendRecvBuf[Temp16Bytes]
1712 phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
1713 NdefMap->TLVStruct.NdefTLVBlock):
1729 NdefMap->MifareULContainer.RemainingSize =
1730 (NdefMap->MifareULContainer.RemainingSize -
1731 (NdefMap->SendRecvBuf[Temp16Bytes + 1]
1734 NdefMap->TLVStruct.NdefTLVBlock =
1735 (uint8_t)(NdefMap->TLVStruct.NdefTLVBlock
1737 NdefMap->SendRecvBuf[Temp16Bytes + 1] + 2)/
1742 NdefMap->SendRecvBuf[Temp16Bytes + 1] + 2;
1749 NdefMap->TLVStruct.NdefTLVFoundFlag =
1750 ((NdefMap->SendRecvBuf[Temp16Bytes] ==
1755 if(NdefMap->TLVStruct.NdefTLVFoundFlag ==
1759 NdefMap->SendRecvBuf[Temp16Bytes]);
1761 NdefMap->TLVStruct.NdefTLVByte =
1766 NdefMap->TLVStruct.NdefTLVBlock =
1767 (uint8_t)(((NdefMap->TLVStruct.NdefTLVBlock /4) * 4)
1771 NdefMap->TLVStruct.NdefTLVSector = NdefMap->MifareULContainer.CurrentSector;
1791 NdefMap->MifareULContainer.RemainingSize -=
1793 if (NdefMap->MifareULContainer.RemainingSize ==
1803 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1815 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1819 NdefMap->TLVStruct.TcheckedinTLVFlag =
1821 NdefMap->TLVStruct.NoLbytesinTLV =
1826 NdefMap->MifareULContainer.RemainingSize -=
1829 if(NdefMap->MifareULContainer.RemainingSize ==
1837 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1841 NdefMap->TLVStruct.TcheckedinTLVFlag =
1843 NdefMap->TLVStruct.NoLbytesinTLV =
1850 if((NdefMap->SendRecvBuf[Temp16Bytes] ==
1852 ((NdefMap->SendRecvBuf[Temp16Bytes] ==
1854 (NdefMap->TLVStruct.NdefTLVFoundFlag !=
1868 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1872 NdefMap->TLVStruct.TcheckedinTLVFlag =
1874 NdefMap->TLVStruct.NoLbytesinTLV =
1880 ShiftLength = (uint16_t) NdefMap->SendRecvBuf[Temp16Bytes];
1881 NdefMap->MifareULContainer.RemainingSize--;
1884 Result = phFriNfc_MfUL_H_Chk16Bytes(NdefMap,
1888 NdefMap->TLVStruct.TcheckedinTLVFlag =
1890 NdefMap->TLVStruct.NoLbytesinTLV =
1892 NdefMap->TLVStruct.prevLenByteValue =
1893 NdefMap->SendRecvBuf[Temp16Bytes - 1];
1899 (uint16_t) (NdefMap->SendRecvBuf[Temp16Bytes]
1902 // NdefMap->MifareULContainer.RemainingSize--;
1904 if(ShiftLength > (NdefMap->MifareULContainer.RemainingSize))
1914 // NdefMap->MifareULContainer.RemainingSize--;
1916 NdefMap->TLVStruct.NdefTLVByte =
1917 (NdefMap->SendRecvBuf[Temp16Bytes] %
1920 NdefMap->TLVStruct.NdefTLVBlock =
1921 (uint8_t)(NdefMap->MifareULContainer.CurrentBlock
1925 NdefMap->TLVStruct.ActualSize =
1926 NdefMap->TLVStruct.BytesRemainLinTLV = ShiftLength;
1928 NdefMap->TLVStruct.NdefTLVFoundFlag = 1;
1930 NdefMap->TLVStruct.NdefTLVSector = NdefMap->MifareULContainer.CurrentSector;
1933 Result = ((NdefMap->TLVStruct.NoLbytesinTLV ==
1935 phFriNfc_MapTool_SetCardState( NdefMap, ShiftLength):
1938 Result = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
1939 NdefMap->TLVStruct.NdefTLVBlock);
1945 NdefMap->TLVStruct.BytesRemainLinTLV =
1946 NdefMap->SendRecvBuf[Temp16Bytes];
1948 NdefMap->TLVStruct.ActualSize =
1949 NdefMap->SendRecvBuf[Temp16Bytes];
1951 if((NdefMap->MifareULContainer.RemainingSize <
1952 NdefMap->SendRecvBuf[Temp16Bytes]) ||
1953 (NdefMap->MifareULContainer.RemainingSize <
1955 (NdefMap->TLVStruct.BytesRemainLinTLV >
1956 (NdefMap->MifareULContainer.RemainingSize)) ||
1957 ((NdefMap->TLVStruct.BytesRemainLinTLV ==
1959 (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE)))
1968 if(NdefMap->TLVStruct.NdefTLVFoundFlag !=
1971 NdefMap->TLVStruct.NdefTLVByte =
1973 NdefMap->SendRecvBuf[Temp16Bytes]) %
1976 NdefMap->TLVStruct.NdefTLVBlock =
1977 (uint8_t)(NdefMap->TLVStruct.NdefTLVBlock
1979 NdefMap->SendRecvBuf[Temp16Bytes] + 1)/
1983 NdefMap->SendRecvBuf[Temp16Bytes]);
1985 NdefMap->MifareULContainer.RemainingSize =
1986 (NdefMap->MifareULContainer.RemainingSize -
1987 (NdefMap->SendRecvBuf[Temp16Bytes]
1999 phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2000 NdefMap->TLVStruct.NdefTLVBlock):
2010 if(NdefMap->TLVStruct.NdefTLVFoundFlag ==
2014 NdefMap->TLVStruct.NdefTLVBlock =
2015 (uint8_t)(NdefMap->TLVStruct.NdefTLVBlock
2019 NdefMap->MifareULContainer.RemainingSize =
2020 (NdefMap->MifareULContainer.RemainingSize -
2022 ShiftLength = NdefMap->SendRecvBuf[Temp16Bytes];
2023 Result = ((NdefMap->TLVStruct.NoLbytesinTLV ==
2025 phFriNfc_MapTool_SetCardState( NdefMap, ShiftLength):
2038 static NFCSTATUS phFriNfc_MfUL_H_Chk16Bytes(phFriNfc_NdefMap_t *NdefMap,
2046 localCurrentBlock = NdefMap->MifareULContainer.CurrentBlock +
2051 NdefMap->MifareULContainer.CurrentBlock +=
2054 Result = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2055 NdefMap->MifareULContainer.CurrentBlock);
2060 NdefMap->MifareULContainer.CurrentSector++;
2062 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
2063 NdefMap->MifareULContainer.CurrentSector, 1,
2116 static NFCSTATUS phFriNfc_MfUL_H_SelectSector(phFriNfc_NdefMap_t *NdefMap,
2125 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2126 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2127 NdefMap->psDepAdditionalInfo.NAD = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2129 NdefMap->State = NextState;
2133 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] = 0x00;
2134 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1] = 0x00;
2135 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL2] = 0xC2;
2136 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL3] = 0xFF;
2137 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_VAL4;
2141 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] = 0x00;
2142 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1] = 0x00;
2143 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL2] = SectorNo;
2144 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL3] = 0;
2145 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL4] = 0;
2146 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL5] = 0;
2147 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_VAL5 + 1;
2152 phFriNfc_MfUL_H_ComputeCrc(CRC_A, &NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL2],
2153 NdefMap->SendLength - 2,
2154 &NdefMap->SendRecvBuf[NdefMap->SendLength],
2155 &NdefMap->SendRecvBuf[NdefMap->SendLength + 1]);
2157 NdefMap->SendLength += PH_FRINFC_NDEFMAP_MFUL_VAL2;
2160 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
2162 NdefMap->Cmd.MfCmd = phHal_eMifareRaw;
2165 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
2166 &NdefMap->MapCompletionInfo,
2167 NdefMap->psRemoteDevInfo,
2168 NdefMap->Cmd,
2169 &NdefMap->psDepAdditionalInfo,
2170 NdefMap->SendRecvBuf,
2171 NdefMap->SendLength,
2172 NdefMap->SendRecvBuf,
2173 NdefMap->SendRecvLength);
2178 static NFCSTATUS phFriNfc_MfUL_H_RdCardfindNdefTLV( phFriNfc_NdefMap_t *NdefMap,
2182 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_FND_NDEF_COMP;
2184 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2185 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2186 NdefMap->psDepAdditionalInfo.NAD = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2187 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] =
2189 NdefMap->SendLength = PH_FRINFC_NDEFMAP_MFUL_VAL1;
2190 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
2196 NdefMap->Cmd.MfCmd = phHal_eMifareRead;
2199 Result = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
2200 &NdefMap->MapCompletionInfo,
2201 NdefMap->psRemoteDevInfo,
2202 NdefMap->Cmd,
2203 &NdefMap->psDepAdditionalInfo,
2204 NdefMap->SendRecvBuf,
2205 NdefMap->SendLength,
2206 NdefMap->SendRecvBuf,
2207 NdefMap->SendRecvLength);
2211 static NFCSTATUS phFriNfc_MfUL_H_ChkRemainTLV(phFriNfc_NdefMap_t *NdefMap,
2218 switch(NdefMap->TLVStruct.NoLbytesinTLV)
2222 ShiftLength = ((NdefMap->TLVStruct.NoLbytesinTLV ==
2224 NdefMap->TLVStruct.prevLenByteValue:
2225 NdefMap->SendRecvBuf[TempLength]);
2226 ShiftLength = ((NdefMap->TLVStruct.NoLbytesinTLV ==
2228 (((uint16_t)(NdefMap->SendRecvBuf[TempLength]) <<
2231 (((uint16_t)(NdefMap->SendRecvBuf[(TempLength +
2236 NdefMap->MifareULContainer.RemainingSize -=
2239 NdefMap->TLVStruct.ActualSize =
2240 NdefMap->TLVStruct.BytesRemainLinTLV = ShiftLength;
2246 Result = ((((NdefMap->MifareULContainer.RemainingSize)<=
2255 phFriNfc_MapTool_SetCardState( NdefMap, ShiftLength):
2267 NdefMap->MifareULContainer.RemainingSize= NdefMap->MifareULContainer.RemainingSize-
2268 NdefMap->TLVStruct.NoLbytesinTLV;
2270 NdefMap->TLVStruct.NdefTLVByte = ((ShiftLength%
2274 NdefMap->TLVStruct.NdefTLVBlock =
2275 NdefMap->MifareULContainer.CurrentBlock
2277 NdefMap->MifareULContainer.CurrentBlock =
2278 NdefMap->TLVStruct.NdefTLVBlock;
2280 Result = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2281 NdefMap->TLVStruct.NdefTLVBlock);
2287 if((NdefMap->SendRecvBuf[TempLength] ==
2289 ((NdefMap->SendRecvBuf[TempLength] ==
2291 (NdefMap->TLVStruct.NdefTLVFoundFlag !=
2304 ShiftLength = NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_NDEFMAP_MFUL_VAL1)];
2305 ShiftLength = (((uint16_t)(NdefMap->SendRecvBuf[(TempLength + PH_FRINFC_NDEFMAP_MFUL_VAL2)])
2308 Result = ((ShiftLength > (NdefMap->MifareULContainer.RemainingSize))?
2315 phFriNfc_MapTool_SetCardState( NdefMap, ShiftLength):
2318 NdefMap->TLVStruct.ActualSize =
2319 NdefMap->TLVStruct.BytesRemainLinTLV = ShiftLength;
2324 NdefMap->MifareULContainer.RemainingSize= NdefMap->MifareULContainer.RemainingSize-
2325 NdefMap->TLVStruct.NoLbytesinTLV;
2327 NdefMap->TLVStruct.NdefTLVByte = ((ShiftLength%
2331 NdefMap->TLVStruct.NdefTLVBlock =
2332 (uint8_t)(NdefMap->MifareULContainer.CurrentBlock
2335 NdefMap->MifareULContainer.CurrentBlock =
2336 NdefMap->TLVStruct.NdefTLVBlock;
2338 Result = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2339 NdefMap->TLVStruct.NdefTLVBlock);
2347 Result = ((NdefMap->SendRecvBuf[TempLength] >
2348 NdefMap->MifareULContainer.RemainingSize)?
2353 NdefMap->TLVStruct.ActualSize =
2354 NdefMap->TLVStruct.BytesRemainLinTLV =
2355 NdefMap->SendRecvBuf[TempLength];
2356 NdefMap->MifareULContainer.RemainingSize--;
2359 (NdefMap->TLVStruct.NdefTLVFoundFlag !=
2362 phFriNfc_MfUL_H_UpdateLen(NdefMap,
2363 (uint16_t)NdefMap->SendRecvBuf[TempLength]);
2365 NdefMap->MifareULContainer.CurrentBlock =
2366 NdefMap->TLVStruct.NdefTLVBlock;
2367 TempLength=TempLength+(NdefMap->SendRecvBuf[TempLength]);
2369 phFriNfc_MfUL_H_findNDEFTLV(NdefMap, CRFlag):
2370 phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2371 NdefMap->TLVStruct.NdefTLVBlock));
2376 NdefMap->TLVStruct.NoLbytesinTLV = PH_FRINFC_NDEFMAP_MFUL_VAL0;
2378 Result = phFriNfc_MapTool_SetCardState( NdefMap, NdefMap->TLVStruct.ActualSize);
2383 static void phFriNfc_MfUL_H_UpdateLen(phFriNfc_NdefMap_t *NdefMap,
2386 NdefMap->MifareULContainer.RemainingSize= NdefMap->MifareULContainer.RemainingSize-DataLen;
2387 NdefMap->TLVStruct.NdefTLVByte = ((DataLen %
2390 NdefMap->TLVStruct.NdefTLVBlock =
2391 (uint8_t)(NdefMap->MifareULContainer.CurrentBlock
2395 static NFCSTATUS phFriNfc_MfUL_H_NxtOp(phFriNfc_NdefMap_t *NdefMap,
2400 switch(NdefMap->PrevOperation)
2405 if (NdefMap->TLVStruct.ActualSize > (NdefMap->CardMemSize - 2))
2413 if (NdefMap->TLVStruct.NdefTLVSector == 1)
2416 NdefMap->MifareULContainer.CurrentSector = 1;
2417 NdefMap->MifareULContainer.CurrentBlock = 0;
2419 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
2420 NdefMap->MifareULContainer.CurrentSector, 1,
2425 NdefMap->MifareULContainer.CurrentBlock = (NdefMap->TLVStruct.NdefTLVBlock / 4) * 4;
2427 Result = phFriNfc_MfUL_H_Rd16Bytes(NdefMap);
2430 NdefMap->MifareULContainer.CurrentBlock =
2433 Result = phFriNfc_MfUL_H_Rd16Bytes(NdefMap);
2453 static NFCSTATUS phFriNfc_MfUL_H_CopyRdBytes(phFriNfc_NdefMap_t *NdefMap)
2461 if (NdefMap->MifareULContainer.CurrentBlock
2462 == NdefMap->TLVStruct.NdefTLVBlock)
2464 if (NdefMap->CardMemSize > (0x12 * PH_FRINFC_NDEFMAP_MFUL_MUL8))
2466 v_field_byte = NdefMap->TLVStruct.NdefTLVByte;
2470 if (NdefMap->TLVStruct.ActualSize >= 0xFF)
2508 (void)memcpy(&(NdefMap->MifareULContainer.ReadBuf[
2509 NdefMap->MifareULContainer.ReadBufIndex]),
2510 (void *)(NdefMap->SendRecvBuf + v_field_byte),
2511 (*NdefMap->SendRecvLength - v_field_byte));
2513 NdefMap->MifareULContainer.ReadBufIndex = (uint16_t)
2514 (NdefMap->MifareULContainer.ReadBufIndex +
2515 (*NdefMap->SendRecvLength - v_field_byte));
2518 (void)memcpy(&(NdefMap->MifareULContainer.ReadBuf[
2519 NdefMap->MifareULContainer.ReadBufIndex]),
2520 NdefMap->SendRecvBuf,
2521 *NdefMap->SendRecvLength);
2523 NdefMap->MifareULContainer.ReadBufIndex=NdefMap->MifareULContainer.ReadBufIndex +*NdefMap->SendRecvLength;
2526 localCurrentBlock = NdefMap->MifareULContainer.CurrentBlock+
2527 (uint8_t)((NdefMap->MifareULContainer.ReadBufIndex !=
2528 NdefMap->CardMemSize)?
2533 NdefMap->MifareULContainer.CurrentBlock = NdefMap->MifareULContainer.CurrentBlock+
2534 (uint8_t)((NdefMap->MifareULContainer.ReadBufIndex !=
2535 NdefMap->CardMemSize)?
2542 if (NdefMap->MifareULContainer.CurrentSector == 0)
2544 NdefMap->MifareULContainer.CurrentSector++;
2545 NdefMap->MifareULContainer.CurrentBlock = 0xff;
2547 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
2548 NdefMap->MifareULContainer.CurrentSector, 1,
2556 static NFCSTATUS phFriNfc_MfUL_H_CpDataToUserBuf(phFriNfc_NdefMap_t *NdefMap)
2562 if(NdefMap->ApduBufferSize >=
2563 NdefMap->TLVStruct.BytesRemainLinTLV)
2565 (void)memcpy(NdefMap->ApduBuffer,
2566 &(NdefMap->MifareULContainer.ReadBuf[
2567 NdefMap->MifareULContainer.ByteNumber]),
2568 NdefMap->TLVStruct.BytesRemainLinTLV);
2570 *(NdefMap->NumOfBytesRead) =
2571 NdefMap->TLVStruct.BytesRemainLinTLV;
2572 NdefMap->MifareULContainer.ByteNumber =
2574 NdefMap->MifareULContainer.ReadWriteCompleteFlag =
2576 NdefMap->MifareULContainer.RemainingSize = NdefMap->MifareULContainer.RemainingSize-
2577 NdefMap->TLVStruct.BytesRemainLinTLV;
2578 NdefMap->TLVStruct.BytesRemainLinTLV =
2583 (void)memcpy(NdefMap->ApduBuffer,
2584 &(NdefMap->MifareULContainer.ReadBuf[
2585 NdefMap->MifareULContainer.ByteNumber]),
2586 NdefMap->ApduBufferSize);
2588 *(NdefMap->NumOfBytesRead) =
2589 NdefMap->ApduBufferSize;
2590 NdefMap->MifareULContainer.ByteNumber = NdefMap->MifareULContainer.ByteNumber+
2591 (uint16_t)NdefMap->ApduBufferSize;
2592 NdefMap->MifareULContainer.RemainingSize=NdefMap->MifareULContainer.RemainingSize-
2593 (uint16_t)NdefMap->ApduBufferSize;
2594 NdefMap->TLVStruct.BytesRemainLinTLV = NdefMap->TLVStruct.BytesRemainLinTLV-
2595 (uint16_t)NdefMap->ApduBufferSize;
2600 static NFCSTATUS phFriNfc_MfUL_H_RdBeforeWrite(phFriNfc_NdefMap_t *NdefMap)
2602 uint16_t localCurrentBlock = NdefMap->TLVStruct.NdefTLVBlock;
2610 switch((NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1))
2614 NdefMap->MifareULContainer.CurrentBlock =
2615 NdefMap->TLVStruct.NdefTLVBlock;
2617 NdefMap->SendRecvBuf[index] =
2618 NdefMap->MifareULContainer.CurrentBlock;
2620 NdefMap->SendRecvBuf[index] =
2623 if (NdefMap->ApduBufferSize > 254)
2625 NdefMap->SendRecvBuf[index] = 0xFF;
2627 NdefMap->SendRecvBuf[index] =
2630 NdefMap->SendRecvBuf[index] =
2636 NdefMap->SendRecvBuf[index] =
2647 Result = phFriNfc_MfUL_H_RdCardfindNdefTLV(NdefMap,
2648 NdefMap->TLVStruct.NdefTLVBlock);
2653 localCurrentBlock = (NdefMap->MifareULContainer.CurrentBlock +
2659 NdefMap->MifareULContainer.CurrentBlock =
2660 (NdefMap->MifareULContainer.CurrentBlock +
2662 NdefMap->SendRecvBuf[index] =
2663 NdefMap->MifareULContainer.CurrentBlock;
2666 if (NdefMap->ApduBufferSize > 254)
2668 NdefMap->SendRecvBuf[index] = 0xFF;
2670 NdefMap->SendRecvBuf[index] =
2673 NdefMap->SendRecvBuf[index] =
2679 NdefMap->SendRecvBuf[index] =
2687 NdefMap->MifareULContainer.CurrentSector++;
2689 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
2690 NdefMap->MifareULContainer.CurrentSector, 1,
2701 if((((NdefMap->TLVStruct.NdefTLVByte -
2703 ((NdefMap
2707 TemLength = (((NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1) ==
2712 if (NdefMap->ApduBufferSize > 254)
2717 if(NdefMap->ApduBufferSize >= TemLength)
2720 (void)memcpy(&(NdefMap->SendRecvBuf[
2722 &(NdefMap->ApduBuffer[
2723 NdefMap->ApduBuffIndex]),
2727 NdefMap->NumOfBytesWritten = TemLength;
2733 *NdefMap->DataCount = (index - PH_FRINFC_NDEFMAP_MFUL_VAL1);
2744 (void)memcpy(&(NdefMap->SendRecvBuf[
2746 &(NdefMap->ApduBuffer[
2747 NdefMap->ApduBuffIndex]),
2748 (uint16_t)NdefMap->ApduBufferSize);
2751 NdefMap->NumOfBytesWritten = (uint16_t)NdefMap->ApduBufferSize;
2753 index= index +(uint8_t)NdefMap->ApduBufferSize;
2755 *NdefMap->DataCount = (index - PH_FRINFC_NDEFMAP_MFUL_VAL1);
2759 NdefMap->SendRecvBuf[i] = (uint8_t)((i == index)?
2762 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG1;
2768 (void)memcpy(NdefMap->MifareULContainer.Buffer,
2769 &(NdefMap->SendRecvBuf[
2774 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
2775 NdefMap->MifareULContainer.Buffer,
2780 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE;
2782 Result = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
2787 static NFCSTATUS phFriNfc_MfUL_H_CallWrOp(phFriNfc_NdefMap_t *NdefMap)
2793 NdefMap->MifareULContainer.CurrentBlock =
2794 NdefMap->TLVStruct.NdefTLVBlock;
2796 (void)memcpy(&(NdefMap->SendRecvBuf[
2798 NdefMap->SendRecvBuf,
2801 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] =
2802 NdefMap->MifareULContainer.CurrentBlock;
2804 if (NdefMap->ApduBufferSize > 254)
2806 NdefMap->SendRecvBuf[(NdefMap->TLVStruct.NdefTLVByte +
2810 if((NdefMap->TLVStruct.NdefTLVByte + PH_FRINFC_NDEFMAP_MFUL_VAL1) <
2813 NdefMap->SendRecvBuf[(NdefMap->TLVStruct.NdefTLVByte +
2816 NdefMap->NumOfLReminWrite = 1;
2821 NdefMap->NumOfLReminWrite = 2;
2823 NdefMap->NumOfBytesWritten = 0;
2828 NdefMap->SendRecvBuf[(NdefMap->TLVStruct.NdefTLVByte +
2832 if((NdefMap->TLVStruct.NdefTLVByte + PH_FRINFC_NDEFMAP_MFUL_VAL1) <
2836 (void)memcpy(&(NdefMap->SendRecvBuf[
2838 &(NdefMap->ApduBuffer[
2839 NdefMap->ApduBuffIndex]),
2842 NdefMap->NumOfBytesWritten = PH_FRINFC_NDEFMAP_MFUL_VAL1;
2846 (void)memcpy(NdefMap->MifareULContainer.Buffer,
2847 &(NdefMap->SendRecvBuf[
2852 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
2853 NdefMap->MifareULContainer.Buffer,
2857 *NdefMap->DataCount = PH_FRINFC_NDEFMAP_MFUL_VAL4;
2860 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE;
2862 Result = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
2867 static NFCSTATUS phFriNfc_MfUL_H_ProWrittenBytes(phFriNfc_NdefMap_t *NdefMap)
2873 if(NdefMap->ApduBuffIndex < NdefMap->ApduBufferSize)
2875 NdefMap->ApduBuffIndex = NdefMap->ApduBuffIndex+NdefMap->NumOfBytesWritten;
2876 if(*NdefMap->DataCount <
2879 (void)memcpy(NdefMap->MifareULContainer.InternalBuf,
2880 NdefMap->MifareULContainer.Buffer,
2881 *NdefMap->DataCount);
2883 NdefMap->MifareULContainer.InternalLength = *NdefMap->DataCount;
2887 NdefMap->MifareULContainer.InternalLength =
2891 NdefMap->MifareULContainer.RemainingSize= NdefMap->MifareULContainer.RemainingSize-
2892 NdefMap->NumOfBytesWritten;
2893 if((NdefMap->ApduBuffIndex == NdefMap->ApduBufferSize) ||
2894 (NdefMap->MifareULContainer.RemainingSize ==
2898 NdefMap->MifareULContainer.ReadWriteCompleteFlag =
2899 (uint8_t)((NdefMap->MifareULContainer.RemainingSize ==
2904 NdefMap->TLVStruct.SetTermTLVFlag =
2905 (uint8_t)(((NdefMap->MifareULContainer.RemainingSize ==
2907 (NdefMap->TLVStruct.SetTermTLVFlag ==
2912 NdefMap->MifareULContainer.CurrentBlock = NdefMap->MifareULContainer.CurrentBlock+
2913 (uint8_t)((NdefMap->MifareULContainer.InternalLength !=
2918 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
2922 localCurrentBlock = NdefMap->MifareULContainer.CurrentBlock + 1;
2925 NdefMap->MifareULContainer.CurrentBlock++;
2926 Result = phFriNfc_MfUL_H_fillSendBufToWr(NdefMap);
2931 NdefMap->MifareULContainer.CurrentSector++;
2933 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
2934 NdefMap->MifareULContainer.CurrentSector, 1,
2941 (NdefMap->TLVStruct.SetTermTLVFlag !=
2943 (NdefMap->MifareULContainer.RemainingSize >
2946 Result = phFriNfc_MfUL_H_WrTermTLV(NdefMap);
2951 (NdefMap->TLVStruct.SetTermTLVFlag ==
2954 Result = phFriNfc_MfUL_H_UpdateWrLen(NdefMap);
2959 static NFCSTATUS phFriNfc_MfUL_H_fillSendBufToWr(phFriNfc_NdefMap_t *NdefMap)
2966 RemainingBytes = (uint16_t)(( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) <=
2967 NdefMap->MifareULContainer.RemainingSize)?
2968 (uint16_t)(NdefMap->ApduBufferSize -
2969 NdefMap->ApduBuffIndex):
2970 NdefMap->MifareULContainer.RemainingSize);
2972 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] =
2973 NdefMap->MifareULContainer.CurrentBlock;
2979 NdefMap->MifareULContainer.InternalLength))?
2982 NdefMap->MifareULContainer.InternalLength));
2984 if (NdefMap->NumOfBytesWritten == 0 && NdefMap->NumOfLReminWrite > 0)
2986 BytesToWrite = BytesToWrite - NdefMap->NumOfLReminWrite;
2988 if (NdefMap->NumOfLReminWrite == 1)
2990 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1] = 0x00;
2994 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1] = 0x00;
2995 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL2] = 0x00;
2999 if(NdefMap->MifareULContainer.InternalLength >
3003 (void)memcpy(&(NdefMap->SendRecvBuf[
3005 NdefMap->MifareULContainer.InternalBuf,
3006 NdefMap->MifareULContainer.InternalLength);
3011 (void)memcpy(&(NdefMap->SendRecvBuf[
3013 NdefMap->MifareULContainer.InternalLength) +
3014 NdefMap->NumOfLReminWrite]),
3015 &(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex]),
3019 NdefMap->NumOfBytesWritten = BytesToWrite;
3023 *NdefMap->DataCount =
3024 (BytesToWrite + NdefMap->MifareULContainer.InternalLength +
3025 NdefMap->NumOfLReminWrite);
3030 if((BytesToWrite + NdefMap->MifareULContainer.InternalLength +
3031 NdefMap->NumOfLReminWrite)
3034 for(index = (uint8_t)((BytesToWrite + NdefMap->MifareULContainer.InternalLength + NdefMap->NumOfLReminWrite) +
3039 NdefMap->SendRecvBuf[index] = (uint8_t)((index ==
3041 NdefMap->MifareULContainer.InternalLength + NdefMap->NumOfLReminWrite) +
3046 NdefMap->TLVStruct.SetTermTLVFlag = PH_FRINFC_NDEFMAP_MFUL_FLAG1;
3052 (void)memcpy(NdefMap->MifareULContainer.Buffer,
3053 &(NdefMap->SendRecvBuf[
3059 if((NdefMap->TLVStruct.NdefTLVByte - PH_FRINFC_NDEFMAP_MFUL_VAL1) <
3062 if ((NdefMap->TLVStruct.NdefTLVSector ==
3063 NdefMap->MifareULContainer.CurrentSector))
3065 if(NdefMap->MifareULContainer.CurrentBlock ==
3066 NdefMap->TLVStruct.NdefTLVBlock)
3068 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
3069 NdefMap->MifareULContainer.Buffer,
3074 if ((NdefMap->TLVStruct.NdefTLVSector ==
3075 NdefMap->MifareULContainer.CurrentSector) ||
3076 (NdefMap->TLVStruct.NdefTLVBlock == 0xFF))
3078 if(NdefMap->MifareULContainer.CurrentBlock ==
3079 (NdefMap->TLVStruct.NdefTLVBlock + PH_FRINFC_NDEFMAP_MFUL_VAL1))
3081 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer1,
3082 NdefMap->MifareULContainer.Buffer,
3089 if ((NdefMap->TLVStruct.NdefTLVSector ==
3090 NdefMap->MifareULContainer.CurrentSector))
3092 if(NdefMap->MifareULContainer.CurrentBlock ==
3093 (NdefMap->TLVStruct.NdefTLVBlock +
3096 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer,
3097 NdefMap->MifareULContainer.Buffer,
3102 if ((NdefMap->TLVStruct.NdefTLVSector ==
3103 NdefMap->MifareULContainer.CurrentSector)||
3104 (NdefMap->TLVStruct.NdefTLVBlock == 0xFF))
3106 if(NdefMap->MifareULContainer.CurrentBlock ==
3107 (NdefMap->TLVStruct.NdefTLVBlock + PH_FRINFC_NDEFMAP_MFUL_VAL2))
3109 (void)memcpy(NdefMap->TLVStruct.NdefTLVBuffer1,
3110 NdefMap->MifareULContainer.Buffer,
3118 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE;
3120 NdefMap->NumOfLReminWrite = 0;
3123 Result = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
3127 static NFCSTATUS phFriNfc_MfUL_H_WrTermTLV(phFriNfc_NdefMap_t *NdefMap)
3134 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_TERM_TLV;
3136 NdefMap->SendRecvBuf[index] =
3137 (NdefMap->MifareULContainer.CurrentBlock +
3140 NdefMap->SendRecvBuf[index] = PH_FRINFC_NDEFMAP_MFUL_TERMTLV;
3145 NdefMap->SendRecvBuf[i] = PH_FRINFC_NDEFMAP_MFUL_NULLTLV;
3148 Result = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
3152 static NFCSTATUS phFriNfc_MfUL_H_UpdateWrLen(phFriNfc_NdefMap_t *NdefMap)
3158 if ((NdefMap->TLVStruct.NdefTLVSector ==
3159 NdefMap->MifareULContainer.CurrentSector) ||
3160 ((NdefMap->TLVStruct.NdefTLVBlock == 0xFF) &&
3161 (NdefMap->TLVStruct.NdefTLVByte == 4) &&
3162 (NdefMap->TLVStruct.NdefTLVSector == 0)))
3164 BlockNo = (((NdefMap->TLVStruct.NdefTLVByte -
3167 NdefMap->TLVStruct.NdefTLVBlock:
3168 (NdefMap->TLVStruct.NdefTLVBlock +
3171 ByteNo = (((NdefMap->TLVStruct.NdefTLVByte -
3175 (NdefMap->TLVStruct.NdefTLVByte +
3178 if (NdefMap->NumOfLReminWrite > 0)
3183 (void)memcpy(&(NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1]),
3184 NdefMap->TLVStruct.NdefTLVBuffer1,
3187 if (NdefMap->NumOfLReminWrite == 1)
3189 /* NdefMap->SendRecvBuf[1] = (uint8_t) ((NdefMap->ApduBuffIndex & 0xFF00) >> 8); */
3190 NdefMap->SendRecvBuf[1] = (uint8_t) NdefMap->ApduBuffIndex;
3193 else if (NdefMap->NumOfLReminWrite == 2)
3195 NdefMap->SendRecvBuf[1] = (uint8_t) ((NdefMap->ApduBuffIndex & 0xFF00) >> 8);
3196 NdefMap->SendRecvBuf[2]= (uint8_t) (NdefMap->ApduBuffIndex);
3203 NdefMap->NumOfLReminWrite = 0;
3208 (void)memcpy(&(NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL1]),
3209 NdefMap->TLVStruct.NdefTLVBuffer,
3213 if (NdefMap->ApduBuffIndex > 254)
3218 NdefMap->SendRecvBuf[ByteNo]= (uint8_t) ((NdefMap->ApduBuffIndex & 0xFF00) >> 8);
3220 NdefMap->SendRecvBuf[ByteNo] = (uint8_t) (NdefMap->ApduBuffIndex);
3222 NdefMap->NumOfLReminWrite = 0;
3226 /* NdefMap->SendRecvBuf[ByteNo]= (uint8_t) (NdefMap->ApduBuffIndex); */
3227 NdefMap->SendRecvBuf[ByteNo]= (uint8_t) ((NdefMap->ApduBuffIndex & 0xFF00) >> 8);
3229 NdefMap->NumOfLReminWrite = 1;
3233 NdefMap->NumOfLReminWrite = 2;
3238 NdefMap->SendRecvBuf[ByteNo]=
3239 (uint8_t)((NdefMap->Offset ==
3241 (uint8_t)NdefMap->ApduBuffIndex:
3242 (NdefMap->ApduBuffIndex +
3243 NdefMap->SendRecvBuf[ByteNo]));
3247 (void)memcpy(NdefMap->MifareULContainer.Buffer,
3248 &(NdefMap->SendRecvBuf[
3252 NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_MFUL_VAL0] = (uint8_t)BlockNo;
3253 Result = phFriNfc_MfUL_H_Wr4bytes(NdefMap);
3255 if (NdefMap->NumOfLReminWrite == 0)
3257 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_WR_LEN_TLV;
3261 NdefMap->State = PH_FRINFC_NDEFMAP_MFUL_STATE_TERM_TLV;
3264 else if (NdefMap->TLVStruct.NdefTLVSector == 0)
3267 NdefMap->MifareULContainer.CurrentSector = 0;
3268 NdefMap->PrevState = PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE;
3270 Result = phFriNfc_MfUL_H_SelectSector(NdefMap,
3271 NdefMap->MifareULContainer.CurrentSector, 1,