Home | History | Annotate | Download | only in src

Lines Matching defs:NdefMap

53 static NFCSTATUS   phFriNfc_Felica_HRdAttrInfo(phFriNfc_NdefMap_t *NdefMap);
54 static NFCSTATUS phFriNfc_Felica_HUpdateAttrInfo(phFriNfc_NdefMap_t *NdefMap);
61 static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
65 static NFCSTATUS phFriNfc_Felica_HUpdateManufIdDetails(const phFriNfc_NdefMap_t *NdefMap);
68 static NFCSTATUS phFriNfc_Felica_HReadData(phFriNfc_NdefMap_t *NdefMap,uint8_t offset);
69 static uint16_t phFriNfc_Felica_HGetMaximumBlksToRead(const phFriNfc_NdefMap_t *NdefMap,uint8_t NbcOrNmaxb );
70 static void phFriNfc_Felica_HAfterRead_CopyDataToBuff(phFriNfc_NdefMap_t *NdefMap);
71 static NFCSTATUS phFriNfc_Felica_HSetTransceiveForRead(phFriNfc_NdefMap_t *NdefMap,uint16_t TrxLen,uint8_t Offset);
72 static uint16_t phFriNfc_Felica_HSetTrxLen(phFriNfc_NdefMap_t *NdefMap,uint16_t Nbc);
73 static NFCSTATUS phFriNfc_Felica_HChkApduBuff_Size( phFriNfc_NdefMap_t *NdefMap);
76 static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap);
77 static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForRdOp(phFriNfc_NdefMap_t *NdefMap,
79 static NFCSTATUS phFriNfc_Felica_HUpdateAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap,uint8_t isStarted);
80 static NFCSTATUS phFriNfc_Felica_HUpdateData(phFriNfc_NdefMap_t *NdefMap);
81 static NFCSTATUS phFriNfc_Felica_HWriteDataBlk(phFriNfc_NdefMap_t *NdefMap);
84 static NFCSTATUS phFriNfc_Felica_HWrEmptyMsg(phFriNfc_NdefMap_t *NdefMap);
87 static NFCSTATUS phFriNfc_Felica_HCheckManufId(const phFriNfc_NdefMap_t *NdefMap);
88 static void phFriNfc_Felica_HCrHandler(phFriNfc_NdefMap_t *NdefMap,
102 static uint16_t phFriNfc_Felica_HGetMaximumBlksToRead(const phFriNfc_NdefMap_t *NdefMap, uint8_t NbcOrNmaxb )
109 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
110 NdefMap->FelicaAttrInfo.LenBytes[1],
111 NdefMap->FelicaAttrInfo.LenBytes[2],
120 BlksToRead = NdefMap->FelicaAttrInfo.Nmaxb;
139 NFCSTATUS phFriNfc_Felica_RdNdef( phFriNfc_NdefMap_t *NdefMap,
148 NdefMap->ApduBufferSize = *PacketDataLength;
150 NdefMap->ApduBuffer = PacketData;
152 NdefMap->NumOfBytesRead = PacketDataLength ;
153 *NdefMap->NumOfBytesRead = 0;
154 NdefMap->ApduBuffIndex = 0;
156 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
157 NdefMap->Felica.Offset = Offset;
159 if( ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )||( NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_WRITE_OPE))
161 NdefMap->Felica.CurBlockNo = 0;
162 NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP;
163 NdefMap->Felica.IntermediateCpyFlag = FALSE;
164 NdefMap->Felica.IntermediateCpyLen = 0;
165 NdefMap->Felica.Rd_NoBytesToCopy = 0;
166 NdefMap->Felica.EofCardReachedFlag= FALSE ;
167 NdefMap->Felica.LastBlkReachedFlag = FALSE;
168 NdefMap->Felica.CurrBytesRead = 0;
170 phFriNfc_Felica_HInitInternalBuf(NdefMap->Felica.Rd_BytesToCopyBuff);
173 status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
178 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,status);
183 Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
186 if(( ( Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) && (NdefMap->Felica.CurBlockNo == Nbc)) &&
187 (NdefMap->Felica.EofCardReachedFlag == FELICA_RD_WR_EOF_CARD_REACHED ))
194 NdefMap->Felica.CurrBytesRead = ((NdefMap->Felica.CurBlockNo * 16)- NdefMap->Felica.Rd_NoBytesToCopy);
195 status = phFriNfc_Felica_HReadData(NdefMap,NdefMap->Felica.Offset);
210 static NFCSTATUS phFriNfc_Felica_HReadData(phFriNfc_NdefMap_t *NdefMap,uint8_t offset)
215 Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
216 if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) > 0) && (NdefMap->Felica.CurBlockNo < Nbc ))
219 if (NdefMap->Felica.Rd_NoBytesToCopy > 0 )
222 phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
224 status = phFriNfc_Felica_HChkApduBuff_Size(NdefMap);
225 if ( (status != NFCSTATUS_SUCCESS) && (NdefMap->Felica.IntermediateRdFlag == TRUE ))
228 TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
229 status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
240 TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
241 status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
247 status = phFriNfc_Felica_HChkApduBuff_Size(NdefMap);
248 if ( (status != NFCSTATUS_SUCCESS) && (NdefMap->Felica.IntermediateRdFlag == TRUE ))
250 TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
251 status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
261 static uint16_t phFriNfc_Felica_HSetTrxLen(phFriNfc_NdefMap_t *NdefMap,uint16_t Nbc)
265 if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)% 16) == 0)
267 BlocksToRead = (uint16_t)( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16 );
271 BlocksToRead = (uint16_t)(((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16) +1);
273 if ( (BlocksToRead > Nbc) ||( (BlocksToRead) > ( Nbc - NdefMap->Felica.CurBlockNo)) )
275 BlocksToRead = Nbc - NdefMap->Felica.CurBlockNo;
279 if ( BlocksToRead >= NdefMap->FelicaAttrInfo.Nbr)
281 if( NdefMap->FelicaAttrInfo.Nbr < Nbc )
283 TranscLen = NdefMap->FelicaAttrInfo.Nbr*16;
288 NdefMap->Felica.LastBlkReachedFlag =1;
295 if ( ( BlocksToRead * 16) == ((Nbc *16) - (NdefMap->Felica.CurBlockNo * 16)))
297 NdefMap->Felica.LastBlkReachedFlag =1;
310 NdefMap->Felica.TrxLen = TranscLen;
319 static void phFriNfc_Felica_HAfterRead_CopyDataToBuff(phFriNfc_NdefMap_t *NdefMap)
325 Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC );
327 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
328 NdefMap->FelicaAttrInfo.LenBytes[1],
329 NdefMap->FelicaAttrInfo.LenBytes[2],
332 if( NdefMap->Felica.Rd_NoBytesToCopy > 0 )
334 if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) < NdefMap->Felica.Rd_NoBytesToCopy )
336 NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
338 if (NdefMap->Felica.IntermediateCpyFlag == TRUE )
341 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
342 (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
343 (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
348 NdefMap->Felica.IntermediateCpyLen += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
349 NdefMap->Felica.IntermediateCpyFlag = 1;
352 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
353 NdefMap->FelicaAttrInfo.LenBytes[1],
354 NdefMap->FelicaAttrInfo.LenBytes[2],
357 if ( NdefMap->Felica.Rd_NoBytesToCopy == 0)
359 NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
365 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
366 NdefMap->Felica.Rd_BytesToCopyBuff,
367 (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
369 NdefMap->ApduBuffIndex += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
372 else if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) == NdefMap->Felica.Rd_NoBytesToCopy )
374 if ( NdefMap->Felica.IntermediateCpyFlag == TRUE )
377 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
378 (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
379 NdefMap->Felica.Rd_NoBytesToCopy);
384 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
385 NdefMap->Felica.Rd_BytesToCopyBuff,
386 NdefMap->Felica.Rd_NoBytesToCopy);
390 NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
391 NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBuffIndex);
399 if ( NdefMap->Felica.IntermediateCpyFlag == TRUE )
402 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
403 (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
404 NdefMap->Felica.Rd_NoBytesToCopy);
409 NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
410 NdefMap->Felica.Rd_BytesToCopyBuff,
411 NdefMap->Felica.Rd_NoBytesToCopy);
414 NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
423 if ( ((NdefMap->Felica.LastBlkReachedFlag == 1) && (( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= 16)) )
426 if (( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= DataLen)
428 NdefMap->Felica.CurrBytesRead = (uint16_t)((DataLen) - (NdefMap->Felica.CurrBytesRead +
429 NdefMap->ApduBuffIndex));
431 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
432 (&(NdefMap->SendRecvBuf[13])),
433 NdefMap->Felica.CurrBytesRead);
435 NdefMap->ApduBuffIndex += NdefMap->Felica.CurrBytesRead;
436 if ( NdefMap->ApduBuffIndex == DataLen)
444 if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) <= NdefMap->Felica.TrxLen )||
445 ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) <= DataLen ))
452 NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(16-(( Nbc * 16) - (DataLen)));
454 if ( NdefMap->Felica.Rd_NoBytesToCopy > (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))
457 NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
467 NdefMap->Felica.CurrBytesRead = (uint16_t)((DataLen)- (NdefMap->Felica.CurrBytesRead +
468 NdefMap->ApduBuffIndex));
470 if(NdefMap->Felica.CurrBytesRead <
471 (uint16_t)(NdefMap->ApduBufferSize -
472 NdefMap->ApduBuffIndex))
474 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
475 (&(NdefMap->SendRecvBuf[13])),
476 NdefMap->Felica.CurrBytesRead);
480 (void)memcpy( (&( NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
481 (&( NdefMap->SendRecvBuf[13])),
482 (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
485 if ( NdefMap->Felica.LastBlkReachedFlag == 1 )
487 NdefMap->Felica.Rd_NoBytesToCopy =
488 (uint8_t)((NdefMap->Felica.CurrBytesRead >
489 (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))?
490 (NdefMap->Felica.CurrBytesRead -
491 (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)):
494 ResetFlag = ((NdefMap->Felica.Rd_NoBytesToCopy == 0)?TRUE:FALSE);
499 NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)( NdefMap->Felica.TrxLen - (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
503 (void)memcpy( NdefMap->Felica.Rd_BytesToCopyBuff,
504 (&(NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN+(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)])),
505 NdefMap->Felica.Rd_NoBytesToCopy);
509 NdefMap->Felica.IntermediateCpyFlag = TRUE;
511 NdefMap->ApduBuffIndex += ((NdefMap->Felica.CurrBytesRead <
512 (uint16_t)(NdefMap->ApduBufferSize -
513 NdefMap->ApduBuffIndex))?
514 NdefMap->Felica.CurrBytesRead:
515 (uint16_t)(NdefMap->ApduBufferSize -
516 NdefMap->ApduBuffIndex));
521 (void)memcpy( (&( NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
522 (&( NdefMap->SendRecvBuf[13])),
523 NdefMap->Felica.Rd_NoBytesToCopy);
525 NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
534 if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) < NdefMap->Felica.TrxLen )
537 if ( NdefMap->Felica.LastBlkReachedFlag == 1)
539 NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(16-(( Nbc * 16) - DataLen));
541 if ( NdefMap->Felica.Rd_NoBytesToCopy > (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))
544 NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
550 NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(NdefMap->Felica.TrxLen - (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
556 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
557 (&(NdefMap->SendRecvBuf[13])),
558 NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
561 (void)memcpy( NdefMap->Felica.Rd_BytesToCopyBuff,
562 (&(NdefMap->SendRecvBuf[13+(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)])),
563 NdefMap->Felica.Rd_NoBytesToCopy);
565 NdefMap->Felica.IntermediateCpyFlag = TRUE;
566 NdefMap->ApduBuffIndex += (uint16_t)NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex;
571 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
572 (&(NdefMap->SendRecvBuf[13])),
573 NdefMap->Felica.Rd_NoBytesToCopy);
575 NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
579 if ( DataLen <= (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) )
581 NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
588 else if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) == NdefMap->Felica.TrxLen )
592 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
593 (&(NdefMap->SendRecvBuf[13])),
594 (NdefMap->Felica.TrxLen ));
596 NdefMap->ApduBuffIndex += NdefMap->Felica.TrxLen;
600 if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) > NdefMap->Felica.TrxLen )
603 (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
604 (&(NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN])),
605 NdefMap->Felica.TrxLen);
607 NdefMap->ApduBuffIndex += (uint16_t)NdefMap->Felica.TrxLen;
615 NdefMap->Felica.Rd_NoBytesToCopy =0;
616 NdefMap->Felica.IntermediateCpyLen =0;
617 NdefMap->Felica.IntermediateCpyFlag =FALSE;
629 static NFCSTATUS phFriNfc_Felica_HChkApduBuff_Size( phFriNfc_NdefMap_t *NdefMap)
636 Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
639 if ( (( NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0) &&
640 (NdefMap->Felica.CurBlockNo < Nbc ))
645 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
646 NdefMap->ApduBuffIndex = 0;
648 }/*if( (NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0 && NdefMap->Felica.CurBlockNo < NdefMap->FelicaAttrInfo.Nmaxb )*/
651 if (( ( NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0) &&
652 (NdefMap->Felica.CurBlockNo == Nbc ))
657 ResetFlag = ((NdefMap->Felica.Rd_NoBytesToCopy > 0 )?
662 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
664 NdefMap->ApduBuffIndex = 0;
666 }/*if ((NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0 && NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb )*/
670 if ( NdefMap->ApduBuffIndex == (Nbc*16))
678 if ((NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )> 0 )
680 if ( NdefMap->Felica.CurBlockNo == Nbc )
683 if ( NdefMap->Felica.Rd_NoBytesToCopy > 0)
685 if ( NdefMap->Felica.EofCardReachedFlag == TRUE )
689 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
690 NdefMap->ApduBuffIndex=0;
694 phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
695 if( NdefMap->Felica.Rd_NoBytesToCopy > 0 )
699 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
700 NdefMap->ApduBuffIndex=0;
725 NdefMap->Felica.IntermediateRdFlag = TRUE;
737 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
738 NdefMap->FelicaAttrInfo.LenBytes[1],
739 NdefMap->FelicaAttrInfo.LenBytes[2],
741 if (NdefMap->ApduBuffIndex > DataLen)
743 *NdefMap->NumOfBytesRead = DataLen;
747 *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
750 NdefMap->ApduBuffIndex = 0;
751 NdefMap->Felica.Rd_NoBytesToCopy=0;
752 NdefMap->Felica.EofCardReachedFlag=FELICA_RD_WR_EOF_CARD_REACHED;
763 NdefMap,uint16_t TrxLen,uint8_t Offset)
770 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
772 NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
776 NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK;
779 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
780 NdefMap->MapCompletionInfo.Context = NdefMap;
783 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
784 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
787 NdefMap->SendRecvBuf[BufIndex] = 0x00;
790 NdefMap->SendRecvBuf[BufIndex] = 0x06;
795 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
796 (void * )(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
799 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
800 (void * )(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
807 NdefMap->SendRecvBuf[BufIndex] = 0x01;
811 NdefMap->SendRecvBuf[BufIndex] = 0x0B;
814 NdefMap->SendRecvBuf[BufIndex] = 0x00;
818 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(TrxLen/16);
826 NdefMap->SendRecvBuf[BufIndex] = 0x80;
830 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(i + 1);
839 NdefMap->SendRecvBuf[BufIndex] = 0x80;
843 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(NdefMap->Felica.CurBlockNo + i);
849 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = (uint8_t) BufIndex;
852 NdefMap->SendLength = BufIndex;
854 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
856 TrxStatus = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
857 &NdefMap->MapCompletionInfo,
858 NdefMap->psRemoteDevInfo,
859 NdefMap->Cmd,
860 &NdefMap->psDepAdditionalInfo,
861 NdefMap->SendRecvBuf,
862 NdefMap->SendLength,
863 NdefMap->SendRecvBuf,
864 NdefMap->SendRecvLength);
877 NFCSTATUS phFriNfc_Felica_WrNdef( phFriNfc_NdefMap_t *NdefMap,
885 NdefMap->ApduBufferSize = *PacketDataLength;
887 NdefMap->ApduBuffer = PacketData;
890 NdefMap->WrNdefPacketLength = PacketDataLength;
891 *NdefMap->WrNdefPacketLength = 0;
894 NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
895 NdefMap->Felica.Offset = Offset;
897 NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP;
898 status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
903 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,status);
917 NFCSTATUS phFriNfc_Felica_EraseNdef( phFriNfc_NdefMap_t *NdefMap)
923 if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID )
930 else if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY )
936 NdefMap->WrNdefPacketLength = &PktDtLength;
937 *NdefMap->WrNdefPacketLength = 0;
943 NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP;
945 status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
959 static NFCSTATUS phFriNfc_Felica_HUpdateAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap,uint8_t isStarted)
969 NdefMap->State =
974 if( ( NdefMap->State == PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN)||
975 ( NdefMap->State == PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END) )
980 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
982 NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
986 NdefMap->SendRecvBuf[BufIndex] = 0x00;
990 NdefMap->SendRecvBuf[BufIndex] = 0x08;
995 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
996 (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
999 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1000 (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
1006 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
1009 NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
1012 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
1015 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to Write*/
1018 NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
1021 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
1025 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Version;
1028 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbr;
1031 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
1034 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) >> 8);
1037 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) & (0x00ff));
1040 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1043 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1046 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1049 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1054 NdefMap->SendRecvBuf[BufIndex] = 0x0F; /* Write Flag Made On*/
1057 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
1061 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[0];
1064 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[1];
1067 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[2];
1076 if ( (NdefMap->Felica.Wr_BytesRemained > 0) && (NdefMap->Felica.CurBlockNo == 0))
1085 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Write Flag Made Off*/
1088 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
1091 if ( NdefMap->Felica.Wr_BytesRemained > 0 )
1093 TotNoWrittenBytes = ( (NdefMap->Felica.CurBlockNo *16)- (16 - (NdefMap->Felica.Wr_BytesRemained)));
1097 TotNoWrittenBytes = ( NdefMap->Felica.CurBlockNo *16);
1102 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(( TotNoWrittenBytes & 0x00ff0000) >> 16);
1105 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((TotNoWrittenBytes & 0x0000ff00) >> 8);
1108 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(TotNoWrittenBytes & 0x000000ff);
1118 ChkSum += NdefMap->SendRecvBuf[index];
1122 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(ChkSum >> 8);
1125 NdefMap->SendRecvBuf[BufIndex] = (uint8_t )(ChkSum & 0x00ff);
1129 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
1131 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1134 NdefMap->SendLength = BufIndex;
1137 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
1138 NdefMap->MapCompletionInfo.Context = NdefMap;
1141 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
1142 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
1145 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1146 &NdefMap->MapCompletionInfo,
1147 NdefMap->psRemoteDevInfo,
1148 NdefMap->Cmd,
1149 &NdefMap->psDepAdditionalInfo,
1150 NdefMap->SendRecvBuf,
1151 NdefMap->SendLength,
1152 NdefMap->SendRecvBuf,
1153 NdefMap->SendRecvLength);
1165 static NFCSTATUS phFriNfc_Felica_HWrEmptyMsg(phFriNfc_NdefMap_t *NdefMap)
1174 NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_WR_EMPTY_MSG;
1178 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
1180 NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
1184 NdefMap->SendRecvBuf[BufIndex] = 0x00;
1188 NdefMap->SendRecvBuf[BufIndex] = 0x08;
1193 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1194 (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
1197 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1198 (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
1205 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
1208 NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
1211 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
1214 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to Write*/
1217 NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
1220 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
1224 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Version;
1227 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbr;
1230 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
1233 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) >> 8);
1236 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap
1239 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1242 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1245 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1248 NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
1251 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.WriteFlag;
1254 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
1258 NdefMap->SendRecvBuf[BufIndex] = 0x00;
1261 NdefMap->SendRecvBuf[BufIndex] = 0x00;
1264 NdefMap->SendRecvBuf[BufIndex] = 0x00;
1270 ChkSum += NdefMap->SendRecvBuf[index];
1274 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(ChkSum >> 8);
1277 NdefMap->SendRecvBuf[BufIndex] = (uint8_t )(ChkSum & 0x00ff);
1281 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
1283 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
1286 NdefMap->SendLength = BufIndex;
1289 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
1290 NdefMap->MapCompletionInfo.Context = NdefMap;
1293 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
1294 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
1297 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
1298 &NdefMap->MapCompletionInfo,
1299 NdefMap->psRemoteDevInfo,
1300 NdefMap->Cmd,
1301 &NdefMap->psDepAdditionalInfo,
1302 NdefMap->SendRecvBuf,
1303 NdefMap->SendLength,
1304 NdefMap->SendRecvBuf,
1305 NdefMap->SendRecvLength);
1323 static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap)
1330 if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x00)
1338 if ( ( NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN) ||
1339 ( ( NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE) &&
1340 (NdefMap->Felica.Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ) ))
1343 if (NdefMap->ApduBufferSize > (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb *16))
1345 NdefMap->Felica.EofCardReachedFlag = FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET;
1349 NdefMap->Felica.EofCardReachedFlag = FALSE;
1354 NdefMap->Felica.Wr_BytesRemained = 0;
1355 NdefMap->Felica.CurBlockNo = 0;
1356 NdefMap->Felica.NoBlocksWritten = 0;
1357 phFriNfc_Felica_HInitInternalBuf(NdefMap->Felica.Wr_RemainedBytesBuff);
1358 status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
1363 if (NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_CUR )
1366 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
1367 NdefMap->FelicaAttrInfo.LenBytes[1],
1368 NdefMap->FelicaAttrInfo.LenBytes[2],
1371 if (( NdefMap->ApduBufferSize + (DataLen )) >
1372 (uint32_t)( NdefMap->FelicaAttrInfo.Nmaxb *16))
1374 if(( DataLen ) == (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb *16) )
1382 NdefMap->Felica.EofCardReachedFlag =FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET;
1383 NdefMap->ApduBuffIndex =0;
1384 NdefMap->Felica.NoBlocksWritten = 0;
1385 status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
1390 NdefMap->ApduBuffIndex =0;
1391 NdefMap->Felica.NoBlocksWritten = 0;
1392 status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
1394 }/*if (NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_CUR )*/
1408 static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForRdOp(phFriNfc_NdefMap_t *NdefMap,
1415 if ( NdefMap->FelicaAttrInfo.WriteFlag == 0x0F )
1420 *NdefMap->NumOfBytesRead = 0;
1424 status = phFriNfc_MapTool_SetCardState( NdefMap,NdefLen);
1428 status = phFriNfc_Felica_HReadData(NdefMap,NdefMap->Felica.Offset);
1441 static NFCSTATUS phFriNfc_Felica_HUpdateData(phFriNfc_NdefMap_t *NdefMap)
1458 if( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) > 0 )
1462 NdefMap->SendRecvBuf[BufIndex] = 0x00;
1466 NdefMap->SendRecvBuf[BufIndex] = 0x08;
1471 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1472 (&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
1475 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1476 (&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
1482 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
1485 NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
1488 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
1491 if ( NdefMap->Felica.EofCardReachedFlag == FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET)
1495 BytesRemainedInCard= ( (NdefMap->FelicaAttrInfo.Nmaxb*16) - (NdefMap->Felica.CurBlockNo * 16));
1500 if ( NdefMap->Felica.EofCardReachedFlag == FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET )
1503 (void)phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
1505 if ( NdefMap->Felica.Wr_BytesRemained )
1507 TotNoWrittenBytes = ( (NdefMap->Felica.CurBlockNo *16)- (16 - (NdefMap->Felica.Wr_BytesRemained)));
1511 TotNoWrittenBytes = ( NdefMap->Felica.CurBlockNo *16);
1514 BytesRemainedInCard = (NdefMap->FelicaAttrInfo.Nmaxb*16 - (TotNoWrittenBytes));
1519 if(NdefMap->Felica.Wr_BytesRemained > 0)
1523 NdefMap->SendRecvBuf[BufIndex] = 0;
1533 if ( NdefMap->ApduBufferSize >(uint32_t) (16 - NdefMap->Felica.Wr_BytesRemained))
1536 if ( NdefMap->Felica.EofCardReachedFlag )
1543 BytesRemained = (uint8_t)NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained);
1549 if (!NdefMap->Felica.EofCardReachedFlag)
1555 if ( BlkNo >= NdefMap->FelicaAttrInfo.Nbw )
1557 BlkNo = NdefMap->FelicaAttrInfo.Nbw;
1573 NdefMap->Felica.PadByteFlag = TRUE;
1574 NdefMap->Felica.NoBlocksWritten = BlkNo;
1585 NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
1589 if ( !(BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained)== 0 ))
1597 if ( NdefMap->Felica.PadByteFlag )
1599 NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
1608 BlkNo =(uint8_t)(( BytesRemained - ((16 -NdefMap->Felica.Wr_BytesRemained)) )/16);
1611 if ( BlkNo >= NdefMap->FelicaAttrInfo.Nbw )
1613 BlkNo = NdefMap->FelicaAttrInfo.Nbw;
1628 if(((!NbwCheck) &&( BytesRemained- (16 - NdefMap->Felica.Wr_BytesRemained))%16) != 0)
1632 NdefMap->Felica.PadByteFlag = TRUE;
1633 NdefMap->Felica.NoBlocksWritten = BlkNo;
1644 NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
1649 if ( !(BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained)== 0 ))
1658 if ( NdefMap->Felica.PadByteFlag )
1660 NdefMap->Felica.NoBlocksWritten = TotNoBlks -1;
1671 }/*if ( NdefMap->ApduBufferSize >(uint32_t) (16 - NdefMap->Felica.Wr_BytesRemained))*/
1675 NdefMap->Felica.NoBlocksWritten = 0;
1681 NdefMap->SendRecvBuf[BufIndex] = 0x80;
1684 if ( NdefMap->Felica.PadByteFlag == TRUE )
1686 NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
1691 CurBlk = NdefMap->Felica.CurBlockNo +1;
1692 NdefMap->SendRecvBuf[BufIndex] = CurBlk + i;
1697 if((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16 - NdefMap->Felica.Wr_BytesRemained))
1701 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1702 NdefMap->Felica.Wr_RemainedBytesBuff,
1703 NdefMap->Felica.Wr_BytesRemained);
1706 BufIndex += NdefMap->Felica.Wr_BytesRemained;
1710 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1711 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
1712 (16 - NdefMap->Felica.Wr_BytesRemained));
1715 NdefMap->NumOfBytesWritten = 16 - NdefMap->Felica.Wr_BytesRemained;
1718 BufIndex += 16 - NdefMap->Felica.Wr_BytesRemained;
1722 if (!NdefMap->Felica.EofCardReachedFlag)
1728 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1729 (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
1730 (NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained)));
1734 NdefMap->NumOfBytesWritten += (uint16_t)(NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained));
1736 BufIndex += (uint8_t)(NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained));
1742 NdefMap->SendRecvBuf[BufIndex] =0x00;
1746 NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
1749 (void)memcpy( NdefMap->Felica.Wr_RemainedBytesBuff,
1750 (&( NdefMap->ApduBuffer[(NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained)])),
1751 ( NdefMap->Felica.Wr_BytesRemained));
1756 NdefMap->Felica.Wr_BytesRemained = 0;
1764 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1765 (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
1766 (NdefMap->FelicaAttrInfo.Nbw - 1) * 16);
1769 BufIndex += ((NdefMap->FelicaAttrInfo.Nbw - 1 )*16);
1771 NdefMap->Felica.Wr_BytesRemained = 0;
1772 NdefMap->NumOfBytesWritten+= ((NdefMap->FelicaAttrInfo.Nbw -1)*16);
1773 NdefMap->Felica.PadByteFlag =FALSE;
1775 }/*if (!NdefMap->Felica.EofCardReachedFlag)*/
1782 (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
1783 (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
1784 ( BytesRemained - ((16 -NdefMap->Felica.Wr_BytesRemained) )));
1787 NdefMap->NumOfBytesWritten += (uint16_t)( BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained));
1789 BufIndex += (uint8_t)( BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained));
1795 NdefMap->SendRecvBuf[BufIndex] =0x00;
1800 NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
1803 (void)memcpy(NdefMap->Felica.Wr_RemainedBytesBuff,
1804 (&(NdefMap->ApduBuffer[(NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained)])),
1805 (NdefMap->Felica.Wr_BytesRemained));
1810 NdefMap->Felica.Wr_BytesRemained = 0;
1817 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1818 (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
1819 (NdefMap->FelicaAttrInfo.Nbw - 1) * 16);
1822 BufIndex += ((NdefMap->FelicaAttrInfo.Nbw - 1 )*16);
1824 NdefMap->Felica.Wr_BytesRemained = 0;
1825 NdefMap->NumOfBytesWritten+= ((NdefMap->FelicaAttrInfo.Nbw -1)*16);
1827 NdefMap->Felica.PadByteFlag =FALSE;
1833 NdefMap->Felica.Wr_BytesRemained = 0;
1836 NdefMap->SendRecvBuf[NoOfBlks -1 ]=TotNoBlks;
1837 }/*if((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16 - NdefMap->Felica.Wr_BytesRemained))*/
1841 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1842 NdefMap->Felica.Wr_RemainedBytesBuff,
1843 (NdefMap->Felica.Wr_BytesRemained));
1846 BufIndex+=NdefMap->Felica.Wr_BytesRemained;
1849 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1850 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
1851 NdefMap->ApduBufferSize);
1854 BufIndex+= (uint8_t)NdefMap->ApduBufferSize;
1857 BytesRemained = NdefMap->Felica.Wr_BytesRemained + NdefMap->ApduBufferSize;
1864 NdefMap->SendRecvBuf[BufIndex] =0x00;
1869 NdefMap->NumOfBytesWritten = (uint16_t)NdefMap->ApduBufferSize;
1873 NdefMap->Felica.IntermediateWrFlag = TRUE;
1875 if ( NdefMap->Felica.PadByteFlag )
1877 NdefMap->Felica.NoBlocksWritten = 0;
1881 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
1882 NdefMap->SendLength = BufIndex;
1884 NdefMap->SendRecvBuf[NoOfBlks -1 ]=TotNoBlks;
1889 if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw ))
1892 if ( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo >= NdefMap->FelicaAttrInfo.Nbw)
1896 NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
1900 for ( i=1; i<= NdefMap->FelicaAttrInfo.Nbw; i++)
1902 NdefMap->SendRecvBuf[BufIndex] = 0x80;
1905 NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
1910 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1911 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
1912 NdefMap->FelicaAttrInfo.Nbw * 16);
1915 BufIndex += (NdefMap->FelicaAttrInfo.Nbw*16);
1918 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
1920 NdefMap->Felica.Wr_BytesRemained = 0;
1921 NdefMap->NumOfBytesWritten = (NdefMap->FelicaAttrInfo.Nbw*16);
1922 NdefMap->Felica.NoBlocksWritten = NdefMap->FelicaAttrInfo.Nbw;
1925 NdefMap->SendLength = BufIndex;
1927 NdefMap->Felica.PadByteFlag = FALSE;
1928 }/*if ( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo >= NdefMap->FelicaAttrInfo.Nbw)*/
1934 NdefMap->SendRecvBuf[BufIndex] = (uint8_t)( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo);
1938 for ( i=1; i<= (NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo); i++)
1940 NdefMap->SendRecvBuf[BufIndex] = 0x80;
1942 NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
1947 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
1948 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
1949 (NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo)*16);
1952 BufIndex += (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo )*16);
1955 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
1957 NdefMap->NumOfBytesWritten = ((NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo)*16);
1958 NdefMap->Felica.NoBlocksWritten = (uint8_t)(NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo);
1961 NdefMap->SendLength = BufIndex;
1963 NdefMap->Felica.PadByteFlag =FALSE;
1964 NdefMap->Felica.Wr_BytesRemained = 0;
1966 }/* if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw )) */
1970 if ( NdefMap->Felica.EofCardReachedFlag)
1977 NdefMap->Felica.PadByteFlag = TRUE;
1983 BlkNo =((uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16);
1984 if(((uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)%16) != 0)
1987 PadBytes = (BlkNo * 16) - (uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
1988 NdefMap->Felica.PadByteFlag = TRUE;
1997 NdefMap->SendRecvBuf[BufIndex] = BlkNo;
2000 NdefMap->Felica.NoBlocksWritten = BlkNo;
2005 NdefMap->SendRecvBuf[BufIndex] = 0x80;
2008 CurBlk = NdefMap->Felica.CurBlockNo +1;
2009 NdefMap->SendRecvBuf[BufIndex] = CurBlk + i;
2013 if ( NdefMap->Felica.EofCardReachedFlag )
2016 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
2017 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
2022 NdefMap->NumOfBytesWritten = (uint16_t)BytesRemainedInCard ;
2027 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
2028 (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
2029 (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
2032 BufIndex += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
2033 NdefMap->NumOfBytesWritten = (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
2039 NdefMap->SendRecvBuf[BufIndex] =0x00;
2043 NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
2045 if ( NdefMap->Felica.EofCardReachedFlag )
2048 (void)memcpy(NdefMap->Felica.Wr_RemainedBytesBuff,
2049 (&(NdefMap->ApduBuffer[((BytesRemainedInCard - (BytesRemainedInCard % 16)))])),
2050 ( NdefMap->Felica.Wr_BytesRemained));
2056 (void)memcpy( NdefMap->Felica.Wr_RemainedBytesBuff,
2057 (&(NdefMap->ApduBuffer[((NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained))])),
2058 ( NdefMap->Felica.Wr_BytesRemained));
2064 NdefMap->Felica.Wr_BytesRemained = 0;
2065 NdefMap->Felica.PadByteFlag = FALSE;
2068 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
2069 NdefMap->SendLength = BufIndex;
2071 }/* else of if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw )) */
2072 status = phFriNfc_Felica_HWriteDataBlk(NdefMap);
2077 status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
2088 static NFCSTATUS phFriNfc_Felica_HWriteDataBlk(phFriNfc_NdefMap_t *NdefMap)
2093 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
2094 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
2098 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
2100 NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
2104 NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK;
2107 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
2110 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
2111 &NdefMap->MapCompletionInfo,
2112 NdefMap->psRemoteDevInfo,
2113 NdefMap->Cmd,
2114 &NdefMap->psDepAdditionalInfo,
2115 NdefMap->SendRecvBuf,
2116 NdefMap->SendLength,
2117 NdefMap->SendRecvBuf,
2118 NdefMap->SendRecvLength);
2127 NFCSTATUS phFriNfc_Felica_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
2136 status = phFriNfc_Felica_HPollCard( NdefMap,sysCode,PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP);
2146 static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
2153 NdefMap->SendRecvBuf[0] = 0x06;
2154 NdefMap->SendRecvBuf[1] = 0x00;
2155 NdefMap->SendRecvBuf[2] = sysCode[0];
2156 NdefMap->SendRecvBuf[3] = sysCode[1];
2157 NdefMap->SendRecvBuf[4] = 0x01;
2158 NdefMap->SendRecvBuf[5] = 0x03;
2160 NdefMap->SendLength = 6;
2163 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
2164 NdefMap->MapCompletionInfo.Context = NdefMap;
2167 NdefMap->State = state;
2170 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
2173 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
2174 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
2176 status = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
2177 &NdefMap->MapCompletionInfo,
2178 NdefMap->psRemoteDevInfo,
2179 NdefMap->Cmd,
2180 &NdefMap->psDepAdditionalInfo,
2181 NdefMap->SendRecvBuf,
2182 NdefMap->SendLength,
2183 NdefMap->SendRecvBuf,
2184 NdefMap->SendRecvLength);
2191 static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
2198 NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[0] = 0x00;
2199 NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[1] = sysCode[0];
2200 NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[2] = sysCode[1];
2201 NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[3] = 0x01;
2202 NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[4] = 0x03;
2205 NdefMap->FelicaPollDetails.DevInputParam->GeneralByteLength =0x00;
2207 NdefMap->NoOfDevices = PH_FRINFC_NDEFMAP_FELI_NUM_DEVICE_TO_DETECT;
2210 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
2211 NdefMap->MapCompletionInfo.Context = NdefMap;
2214 NdefMap->State = state;
2222 (void) memcpy( &NdefMap->FelicaPollDetails.psTempRemoteDevInfo,
2223 NdefMap->psRemoteDevInfo,
2227 NdefMap->FelicaPollDetails.psTempRemoteDevInfo.SessionOpened = 0x00;
2230 status = phFriNfc_OvrHal_Poll( NdefMap->LowerDevice,
2231 &NdefMap->MapCompletionInfo,
2232 NdefMap->OpModeType,
2233 &NdefMap->FelicaPollDetails.psTempRemoteDevInfo,
2234 &NdefMap->NoOfDevices,
2235 NdefMap->FelicaPollDetails.DevInputParam);
2244 static NFCSTATUS phFriNfc_Felica_HUpdateManufIdDetails(const phFriNfc_NdefMap_t *NdefMap)
2249 if (NdefMap->SendRecvLength >= 20)
2251 (void)memcpy( (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
2252 (uint8_t *)&NdefMap->SendRecvBuf[2], 8);
2253 (void)memcpy( (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.PMm,
2254 (uint8_t *)&NdefMap->SendRecvBuf[10], 8);
2255 NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[1] = NdefMap->SendRecvBuf[18];
2256 NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[0] = NdefMap->SendRecvBuf[19];
2257 NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDmLength = 8;
2260 (void)memcpy( (uint8_t *)(NdefMap->FelicaManufDetails.ManufID),
2261 (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
2263 (void)memcpy( (uint8_t *)(NdefMap->FelicaManufDetails.ManufParameter),
2264 (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.PMm,
2266 if((NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[1] == 0x12)
2267 && (NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[0] == 0xFC))
2305 phFriNfc_NdefMap_t *NdefMap = (phFriNfc_NdefMap_t *)Context;
2309 switch (NdefMap->State)
2314 Status = phFriNfc_Felica_HUpdateManufIdDetails(NdefMap);
2320 NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP;
2321 Status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
2335 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,Status);
2342 if ( NdefMap->SendRecvBuf[10] == 0x00)
2345 Status = phFriNfc_Felica_HCheckManufId(NdefMap);
2349 Status = phFriNfc_Felica_HUpdateAttrInfo(NdefMap);
2352 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
2353 NdefMap->FelicaAttrInfo.LenBytes[1],
2354 NdefMap->FelicaAttrInfo.LenBytes[2],
2357 if ( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP )
2360 Status = phFriNfc_Felica_HChkAttrBlkForWrOp(NdefMap);
2365 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2368 else if( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP )
2371 Status = phFriNfc_Felica_HChkAttrBlkForRdOp(NdefMap,NDEFLen);
2375 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
2378 else if( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP )
2381 Status = phFriNfc_MapTool_SetCardState( NdefMap,
2384 NdefMap->CardType = PH_FRINFC_NDEFMAP_FELICA_SMART_CARD;
2386 NdefMap->ApduBuffIndex = 0;
2388 NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_OP_NONE;
2390 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,Status);
2392 else if ( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP )
2395 Status = phFriNfc_Felica_HWrEmptyMsg(NdefMap);
2400 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_ERASE_NDEF,Status);
2432 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
2438 if ( NdefMap->SendRecvBuf[10] == 0x00 )
2441 Status =phFriNfc_Felica_HUpdateData(NdefMap);
2445 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2453 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2460 if ( NdefMap->SendRecvBuf[10] == 0x00)
2472 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2478 if ( NdefMap->SendRecvBuf[10] == 0x00)
2490 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2494 if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE )
2497 if ( NdefMap->SendRecvBuf[10] == 0x00 )
2500 if ( NdefMap->Felica.IntermediateWrFlag == TRUE )
2504 (void)memcpy( (&(NdefMap->Felica.Wr_RemainedBytesBuff[NdefMap->Felica.Wr_BytesRemained])),
2505 NdefMap->ApduBuffer,
2506 NdefMap->NumOfBytesWritten);
2508 NdefMap->Felica.Wr_BytesRemained +=
2509 (uint8_t)( NdefMap->NumOfBytesWritten);
2512 NdefMap->ApduBuffIndex +=
2513 NdefMap->NumOfBytesWritten;
2515 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
2516 NdefMap->Felica.IntermediateWrFlag = FALSE;
2518 Status = phFriNfc_Felica_HUpdateData(NdefMap);
2523 NdefMap->ApduBuffIndex += NdefMap->NumOfBytesWritten;
2524 *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
2525 if ( NdefMap->Felica.EofCardReachedFlag )
2527 if ( NdefMap->Felica.CurBlockNo < NdefMap->FelicaAttrInfo.Nmaxb)
2529 NdefMap->Felica.CurBlockNo += NdefMap->Felica.NoBlocksWritten;
2531 if (( NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb) &&
2532 ( NdefMap->ApduBuffIndex == (NdefMap->FelicaAttrInfo.Nmaxb*16)))
2534 NdefMap->Felica.EofCardReachedFlag = FELICA_RD_WR_EOF_CARD_REACHED ;
2536 Status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
2540 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2545 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
2546 NdefMap->FelicaAttrInfo.LenBytes[1],
2547 NdefMap->FelicaAttrInfo.LenBytes[2],
2549 if ( ( NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb) &&
2550 ((TotNoWrittenBytes + NdefMap->ApduBuffIndex) == (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb*16)))
2552 NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
2554 Status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
2558 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2564 Status = phFriNfc_Felica_HUpdateData(NdefMap);
2568 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2572 }/*if ( NdefMap->Felica.EofCardReachedFlag )*/
2575 NdefMap->Felica.CurBlockNo += NdefMap->Felica.NoBlocksWritten;
2577 Status = phFriNfc_Felica_HUpdateData(NdefMap);
2581 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2585 }/*if ( NdefMap->SendRecvBuf[10] == 0x00 )*/
2594 }/*if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE )*/
2606 NdefMap->ApduBuffIndex=0;
2607 NdefMap->Felica.Wr_BytesRemained = 0;
2608 NdefMap->ApduBufferSize = 0;
2609 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
2617 Status = phFriNfc_Felica_HCheckManufId(NdefMap);
2620 if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_RD_RESP_BYTE )
2623 Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
2625 RecvTxLen= phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
2626 BytesToRecv = NdefMap->SendRecvBuf[12]*16;
2629 if ( NdefMap->SendRecvBuf[10] == 0x00)
2633 NdefMap->Felica.CurBlockNo += (uint8_t)(RecvTxLen/16);
2634 phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
2635 Status = phFriNfc_Felica_HReadData(NdefMap,PH_FRINFC_NDEFMAP_SEEK_CUR);
2648 NdefMap->ApduBuffIndex = 0;
2649 NdefMap->Felica.Rd_NoBytesToCopy = 0;
2654 NdefMap->ApduBuffIndex=0;
2664 NdefMap->ApduBuffIndex=0;
2677 phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
2684 phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_INVALID_OPE, Status);
2693 switch ( NdefMap->State)
2699 phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_CHK_NDEF,
2705 phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_WR_NDEF,
2709 phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_RD_NDEF,
2715 phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_INVALID_OPE, Status);
2725 static NFCSTATUS phFriNfc_Felica_HRdAttrInfo(phFriNfc_NdefMap_t *NdefMap)
2733 NdefMap->Cmd.FelCmd = phHal_eFelica_Raw;
2735 NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
2739 NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
2740 NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
2743 NdefMap->SendRecvBuf[BufIndex] = 0x00;
2747 NdefMap->SendRecvBuf[BufIndex] = 0x06;
2752 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
2753 (void * )&NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
2756 (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
2757 (void * )&NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t,
2764 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
2767 NdefMap->SendRecvBuf[BufIndex] = 0x0B; /* Service Code List*/
2770 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
2773 NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to read)*/
2776 NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
2779 NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
2782 NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
2784 *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
2787 NdefMap->SendLength = BufIndex;
2790 NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR;
2793 NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
2794 NdefMap->MapCompletionInfo.Context = NdefMap;
2797 status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
2798 &NdefMap->MapCompletionInfo,
2799 NdefMap->psRemoteDevInfo,
2800 NdefMap->Cmd,
2801 &NdefMap->psDepAdditionalInfo,
2802 NdefMap->SendRecvBuf,
2803 NdefMap->SendLength,
2804 NdefMap->SendRecvBuf,
2805 NdefMap->SendRecvLength);
2814 static NFCSTATUS phFriNfc_Felica_HCheckManufId(const phFriNfc_NdefMap_t *NdefMap)
2821 result = (uint8_t)(phFriNfc_Felica_MemCompare( (void *)(&(NdefMap->SendRecvBuf[2])),
2822 (void *)NdefMap->FelicaManufDetails.ManufID,
2873 static NFCSTATUS phFriNfc_Felica_HUpdateAttrInfo(phFriNfc_NdefMap_t *NdefMap)
2887 status = phFriNfc_MapTool_ChkSpcVer(NdefMap,
2896 Nmaxb1 = NdefMap->SendRecvBuf[16];
2897 Nmaxb2 = NdefMap->SendRecvBuf[17];
2904 if ( NdefMap->SendRecvBuf[14] > Nmaxblk )
2913 if ( (NdefMap->SendRecvBuf[15] > Nmaxblk) ||
2914 ((NdefMap->SendRecvBuf[22] != 0x00) && (NdefMap->SendRecvBuf[22] !=0x0f ))||
2915 ( (NdefMap->SendRecvBuf[23] != 0x00) && (NdefMap->SendRecvBuf[23] !=0x01 ))||
2916 ( NdefMap->SendRecvBuf[18] != 0x00) ||
2917 ( NdefMap->SendRecvBuf[19] != 0x00) ||
2918 ( NdefMap->SendRecvBuf[20] != 0x00) ||
2919 ( NdefMap->SendRecvBuf[21] != 0x00))
2927 PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES( NdefMap->SendRecvBuf[24],
2928 NdefMap->SendRecvBuf[25],
2929 NdefMap->SendRecvBuf[26],
2944 NdefMap->FelicaAttrInfo.Version = NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX];
2945 NdefMap->FelicaAttrInfo.Nbr = NdefMap->SendRecvBuf[14];
2946 NdefMap->FelicaAttrInfo.Nbw = NdefMap->SendRecvBuf[15];
2948 NdefMap->FelicaAttrInfo.Nmaxb = Nmaxblk;
2950 NdefMap->FelicaAttrInfo.WriteFlag = NdefMap->SendRecvBuf[22];
2951 NdefMap->FelicaAttrInfo.RdWrFlag = NdefMap->SendRecvBuf[23];
2954 ChkSum1 = NdefMap->SendRecvBuf[27];
2955 ChkSum2 = NdefMap->SendRecvBuf[28];
2960 status = phFriNfc_Felica_HCalCheckSum(NdefMap->SendRecvBuf,
2972 if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x00 )
2974 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
2976 else if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x01 ) // additional check for R/W access
2978 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE;
2982 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
2985 NdefMap->FelicaAttrInfo.LenBytes[0] = NdefMap->SendRecvBuf[24];
2986 NdefMap->FelicaAttrInfo.LenBytes[1] = NdefMap->SendRecvBuf[25];
2987 NdefMap->FelicaAttrInfo.LenBytes[2] = NdefMap->SendRecvBuf[26];
3001 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
3016 static void phFriNfc_Felica_HCrHandler(phFriNfc_NdefMap_t *NdefMap,
3021 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
3024 NdefMap->CompletionRoutine[CrIndex].
3025 CompletionRoutine(NdefMap->CompletionRoutine->Context, Status);