2 * Copyright (C) 2010 NXP Semiconductors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * \file phFriNfcNdefMap.c
\r
19 * \brief NFC Ndef Mapping For Different Smart Cards.
\r
23 * $Date: Mon Dec 13 14:14:12 2010 $
\r
24 * $Author: ing02260 $
\r
31 #include <phFriNfc_NdefMap.h>
\r
33 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
34 #include <phFriNfc_MifareULMap.h>
\r
35 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
\r
37 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
38 #include <phFriNfc_TopazMap.h>
\r
39 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED */
\r
41 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
42 #include <phFriNfc_MifareStdMap.h>
\r
43 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
45 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
46 #include <phFriNfc_DesfireMap.h>
\r
47 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
49 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
50 #include <phFriNfc_FelicaMap.h>
\r
51 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
53 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
54 #include <phFriNfc_ISO15693Map.h>
\r
55 #endif /* PH_FRINFC_MAP_ISO15693_DISABLED */
\r
57 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
58 #include <phFriNfc_MockupMap.h>
\r
59 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
62 #include <phFriNfc_OvrHal.h>
\r
64 /*! \ingroup grp_file_attributes
\r
65 * \name NDEF Mapping
\r
67 * File: \ref phFriNfcNdefMap.c
\r
71 #define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.39 $"
\r
72 #define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: $"
\r
75 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
76 /* Desfire capability Container Reset Helper */
\r
77 static void phFriNfc_DesfCapCont_HReset(phFriNfc_NdefMap_t *NdefMap);
\r
78 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
80 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
81 /* Felica Smart Tag Reset Helper */
\r
82 static void phFriNfc_Felica_HReset(phFriNfc_NdefMap_t *NdefMap);
\r
83 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
86 /* \note This function has to be called at the beginning, after creating an
\r
87 * instance of \ref phFriNfc_NdefMap_t . Use this function to reset
\r
88 * the instance and/or switch to a different underlying device (
\r
89 * different NFC device or device mode, or different Remote Device).
\r
92 NFCSTATUS phFriNfc_NdefMap_Reset( phFriNfc_NdefMap_t *NdefMap,
\r
94 phHal_sRemoteDevInformation_t *psRemoteDevInfo,
\r
95 phHal_sDevInputParam_t *psDevInputParam,
\r
97 uint16_t TrxBufferSize,
\r
98 uint8_t *ReceiveBuffer,
\r
99 uint16_t *ReceiveLength,
\r
100 uint16_t *DataCount)
\r
102 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
105 if ( (ReceiveLength == NULL) || (NdefMap == NULL) || (psRemoteDevInfo == NULL) ||
\r
106 (TrxBuffer == NULL) || (TrxBufferSize == 0) || (LowerDevice == NULL) ||
\r
107 (*ReceiveLength == 0) || (ReceiveBuffer == NULL) || (DataCount == NULL) ||
\r
108 (psDevInputParam == NULL) ||
\r
109 (*ReceiveLength < PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE ))
\r
111 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
115 /* Initialise the state to Init */
\r
116 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
\r
118 for(index = 0;index<PH_FRINFC_NDEFMAP_CR;index++)
\r
120 /* Initialise the NdefMap Completion Routine to Null */
\r
121 NdefMap->CompletionRoutine[index].CompletionRoutine = NULL;
\r
122 /* Initialise the NdefMap Completion Routine context to Null */
\r
123 NdefMap->CompletionRoutine[index].Context = NULL;
\r
126 /* Lower Device(Always Overlapped HAL Struct initialised in application
\r
127 is registred in NdefMap Lower Device) */
\r
128 NdefMap->LowerDevice = LowerDevice;
\r
130 /* Remote Device info received from Manual Device Discovery is registered here */
\r
131 NdefMap->psRemoteDevInfo = psRemoteDevInfo;
\r
133 /* Transfer Buffer registered */
\r
134 NdefMap->ApduBuffer = TrxBuffer;
\r
136 /* Set the MaxApduBufferSize */
\r
137 NdefMap->ApduBufferSize = TrxBufferSize;
\r
139 /* Set APDU Buffer Index */
\r
140 NdefMap->ApduBuffIndex = 0;
\r
142 /* Register Transfer Buffer Length */
\r
143 NdefMap->SendLength = 0;
\r
145 /* Register Receive Buffer */
\r
146 NdefMap->SendRecvBuf = ReceiveBuffer;
\r
148 /* Register Receive Buffer Length */
\r
149 NdefMap->SendRecvLength = ReceiveLength;
\r
151 /* Register Temporary Receive Buffer Length */
\r
152 NdefMap->TempReceiveLength = *ReceiveLength;
\r
154 /* Register Data Count variable and set it to zero */
\r
155 NdefMap->DataCount = DataCount;
\r
156 *NdefMap->DataCount = 0;
\r
158 /* Reset the PageOffset */
\r
159 NdefMap->Offset = 0;
\r
161 /* Reset the NumOfBytesRead*/
\r
162 NdefMap->NumOfBytesRead = 0;
\r
164 /* Reset the NumOfBytesWritten*/
\r
165 NdefMap->NumOfBytesWritten = 0;
\r
167 /* Reset the Card Type */
\r
168 NdefMap->CardType = 0;
\r
170 /* Reset the Memory Card Size*/
\r
171 NdefMap->CardMemSize = 0;
\r
173 /* Reset the Previous Operation*/
\r
174 NdefMap->PrevOperation = 0;
\r
176 /* Reset the Desfire Operation Flag*/
\r
177 NdefMap->DespOpFlag = 0;
\r
179 /* Reset MapCompletion Info*/
\r
180 NdefMap->MapCompletionInfo.CompletionRoutine = NULL;
\r
181 NdefMap->MapCompletionInfo.Context = NULL;
\r
183 /* Reset the ReadingForWriteOperation flag. */
\r
184 NdefMap->ReadingForWriteOperation = 0; /* FALSE */
\r
186 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
187 /*Reset Desfire Cap Container elements*/
\r
188 phFriNfc_DesfCapCont_HReset(NdefMap);
\r
189 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
191 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
192 /*Reset Mifare Standard Container elements*/
\r
193 NdefMap->StdMifareContainer.DevInputParam = psDevInputParam;
\r
194 status = phFriNfc_MifareStdMap_H_Reset(NdefMap);
\r
195 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
197 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
198 /*Reset Felica Tag elements*/
\r
199 NdefMap->FelicaPollDetails.DevInputParam = psDevInputParam;
\r
200 phFriNfc_Felica_HReset(NdefMap);
\r
201 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
203 #if !(defined(PH_FRINFC_MAP_TOPAZ_DISABLED ) || defined (PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED ))
\r
205 phFriNfc_TopazMap_H_Reset(NdefMap);
\r
206 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED || PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */
\r
209 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
210 status = phFriNfc_MifareUL_H_Reset(NdefMap);
\r
213 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
214 /*Reset Desfire Cap Container elements*/
\r
215 phFriNfc_Mockup_H_Reset(NdefMap);
\r
216 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
219 * Fix for PR - 0001256
\r
222 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
\r
229 * Registering the Completion Routine.
\r
231 * This function requires the caller to set a Completion Routine
\r
232 * which serves as notifier for the upper component.
\r
233 * NOTE: Please refer the header file for more information.
\r
237 NFCSTATUS phFriNfc_NdefMap_SetCompletionRoutine(phFriNfc_NdefMap_t *NdefMap,
\r
238 uint8_t FunctionID,
\r
239 pphFriNfc_Cr_t CompletionRoutine,
\r
240 void *CompletionRoutineContext)
\r
242 NFCSTATUS status = NFCSTATUS_SUCCESS;
\r
244 if ( ( NdefMap == NULL ) || (FunctionID >= PH_FRINFC_NDEFMAP_CR) ||
\r
245 ( CompletionRoutine == NULL) || (CompletionRoutineContext == NULL))
\r
247 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
251 /* Register the application callback with the NdefMap Completion Routine */
\r
252 NdefMap->CompletionRoutine[FunctionID].CompletionRoutine = CompletionRoutine;
\r
254 /* Register the application context with the NdefMap Completion Routine context */
\r
255 NdefMap->CompletionRoutine[FunctionID].Context = CompletionRoutineContext;
\r
262 * Initiates Reading of NDEF information from the Remote Device.
\r
264 * Remote Peer device may be of type any card. Ex: desfire,felica,jewel
\r
265 * mifareUL,mifare 1K etc. The function initiates the reading of NDEF
\r
266 * information from a Remote Device.
\r
268 * This is the main NdefMap read function call.Internally,depending upon
\r
269 * the CardType,respective mifare/desfire read functions are called.
\r
270 * In future this can be extended to support any types of card.
\r
272 * It performs a reset of the state and triggers/starts the raed action (state machine).
\r
273 * A periodic call of the \ref phFriNfcNdefMap_Process has to be done once the action
\r
274 * has been triggered.
\r
276 * NOTE: Please refer the header file for more information.
\r
280 NFCSTATUS phFriNfc_NdefMap_RdNdef( phFriNfc_NdefMap_t *NdefMap,
\r
281 uint8_t *PacketData,
\r
282 uint32_t *PacketDataLength,
\r
285 NFCSTATUS status = NFCSTATUS_PENDING;
\r
288 /* check for validity of input parameters*/
\r
289 if (( PacketData == NULL )
\r
290 || ( NdefMap == NULL )
\r
291 || ( PacketDataLength == NULL )
\r
292 || ( *PacketDataLength == 0 )
\r
293 || ( ( Offset != PH_FRINFC_NDEFMAP_SEEK_CUR) && (Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ))
\r
294 || (NdefMap->CompletionRoutine->CompletionRoutine == NULL)
\r
295 || (NdefMap->CompletionRoutine->Context == NULL )
\r
298 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
300 else if (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID)
\r
302 /* Card is in invalid state, cannot have any read/write
\r
304 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
305 NFCSTATUS_INVALID_FORMAT);
\r
307 else if(NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INITIALIZED)
\r
309 /* Can't read any data from the card:TLV length is zero*/
\r
310 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
\r
312 NdefMap->NumOfBytesRead = PacketDataLength;
\r
313 *NdefMap->NumOfBytesRead = 0;
\r
317 else if ( (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_WRITE_OPE) && (Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ))
\r
319 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);
\r
323 /* Check the offset given by the user
\r
324 If the offset is 1 (SEEK_BEGIN), reset everything and start
\r
325 reading from the first Page of the card.
\r
326 else if offset is 0 (PH_FRINFC_NDEFMAP_SEEK_CUR), continue reading
\r
327 No need to reset the parameters. */
\r
329 if ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
\r
331 NdefMap->ApduBuffIndex = 0;
\r
332 *NdefMap->DataCount = 0;
\r
335 if ( (NdefMap->CardType == PH_FRINFC_NDEFMAP_ISO14443_4A_CARD) &&
\r
336 (Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) && (*NdefMap->DataCount == 0 ))
\r
339 /* A READ operation cannot be done if the previuos operation was WRITE
\r
340 unless the offset is set to PH_FRINFC_NDEFMAP_SEEK_BEGIN Or
\r
341 Read Operation with Offset set to Continue & DataCount set to 0 */
\r
342 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);
\r
346 switch ( NdefMap->CardType)
\r
348 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
349 case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
\r
350 /* Mifare card selected. Call Mifare read */
\r
351 status = phFriNfc_MifareUL_RdNdef ( NdefMap,
\r
356 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
\r
358 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
359 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
\r
361 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 :
\r
362 #endif /* #ifdef DESFIRE_EV1 */
\r
363 /* Desfire card selected. Call Desfire read */
\r
364 status = phFriNfc_Desfire_RdNdef( NdefMap,
\r
369 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
371 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
372 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
\r
373 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
\r
374 /* Mifare card selected. Call Mifare read */
\r
375 status = phFriNfc_MifareStdMap_RdNdef ( NdefMap,
\r
380 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
382 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
383 case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
\r
384 /* Desfire card selected. Call Desfire Write */
\r
385 status = phFriNfc_Felica_RdNdef( NdefMap,
\r
390 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
392 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
393 case PH_FRINFC_NDEFMAP_TOPAZ_CARD :
\r
394 /* Topaz card selected. Call Topaz read */
\r
395 status = phFriNfc_TopazMap_RdNdef( NdefMap,
\r
400 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
401 case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD :
\r
402 /* Topaz card selected. Call Topaz read */
\r
403 status = phFriNfc_TopazDynamicMap_RdNdef( NdefMap,
\r
408 #endif /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */
\r
409 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED */
\r
411 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
412 case PH_FRINFC_NDEFMAP_ISO15693_CARD:
\r
413 status = phFriNfc_ISO15693_RdNdef( NdefMap,
\r
418 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
\r
420 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
421 case PH_FRINFC_NDEFMAP_MOCKUP_CARD :
\r
422 /* Mockup card selected. Call Mockup Write */
\r
423 status = phFriNfc_Mockup_RdNdef( NdefMap,
\r
428 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
431 /* Unknown card type. Return error */
\r
432 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
433 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
443 * Initiates Writing of NDEF information to the Remote Device.
\r
445 * The function initiates the writing of NDEF information to a Remote Device
\r
447 * Remote Peer device may be of type any card. Ex: desfire,felica,jewel
\r
448 * mifareUL,mifare 1K etc. The function initiates the reading of NDEF
\r
449 * information from a Remote Device.
\r
451 * This is a main write api.Internally,depending upon the CardType,
\r
452 * respective mifare/desfire write apis are called.In future this can be
\r
453 * extended to support any types of card.
\r
455 * It performs a reset of the state and starts the action (state machine).
\r
456 * A periodic call of the \ref phFriNfcNdefMap_Process has to be done once
\r
457 * the action has been triggered.
\r
459 * NOTE: Please refer the header file for more information.
\r
464 NFCSTATUS phFriNfc_NdefMap_WrNdef( phFriNfc_NdefMap_t *NdefMap,
\r
465 uint8_t *PacketData,
\r
466 uint32_t *PacketDataLength,
\r
469 NFCSTATUS status = NFCSTATUS_PENDING;
\r
470 uint8_t StatusChk=0;
\r
472 if ( (PacketData == NULL)
\r
473 || ( NdefMap == NULL )
\r
475 || ( PacketDataLength == NULL )
\r
477 || ( *PacketDataLength == 0 )
\r
478 || ((Offset != PH_FRINFC_NDEFMAP_SEEK_CUR) && (Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ))
\r
479 || (NdefMap->CompletionRoutine->CompletionRoutine == NULL)
\r
480 || (NdefMap->CompletionRoutine->Context == NULL)
\r
483 /* Invalid input parameter error */
\r
484 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);
\r
486 else if (( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID) &&
\r
487 (PH_FRINFC_NDEFMAP_TOPAZ_CARD != NdefMap->CardType) &&
\r
488 (PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD != NdefMap->CardType))
\r
490 /* Card is in invalid state, cannot have any read/write
\r
492 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
493 NFCSTATUS_INVALID_FORMAT);
\r
496 else if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY )
\r
499 /*Can't write to the card :No Grants */
\r
500 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
501 NFCSTATUS_NOT_ALLOWED);
\r
503 /* set the no. bytes written is zero*/
\r
504 NdefMap->WrNdefPacketLength = PacketDataLength;
\r
505 *NdefMap->WrNdefPacketLength = 0;
\r
510 /* Check the offset given by the user
\r
511 If the offset is 1 (SEEK_BEGIN), reset everything and start
\r
512 writing from the first Byte of the card.
\r
513 else if offset is 0 (PH_FRINFC_NDEFMAP_SEEK_CUR), continue writing
\r
514 No need to reset the parameters. */
\r
515 if (( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID) &&
\r
516 (PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD == NdefMap->CardType))
\r
518 /* If Topaz Dynamic card CC bytes are not valid then also allow writing,
\r
519 If card is really good then writing will be done properly and reading can be performed,
\r
520 otherwise writing or reading will fail. so, setting card state to
\r
521 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE */
\r
522 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE;
\r
525 if ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
\r
527 NdefMap->ApduBuffIndex = 0;
\r
528 *NdefMap->DataCount = 0;
\r
531 if ( (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_UL_CARD) ||
\r
532 (NdefMap->CardType == PH_FRINFC_NDEFMAP_ISO14443_4A_CARD))
\r
534 if (( (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE) && (Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN )) ||
\r
535 ( (Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) && (*NdefMap->DataCount == 0 )))
\r
537 /* A WRITE operation cannot be done if the previuos operation was READ
\r
538 unless the offset is set to PH_FRINFC_NDEFMAP_SEEK_BEGIN OR
\r
539 Write Operation with Offset set to Continue & DataCount set to 0 */
\r
540 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);
\r
546 NdefMap->WrNdefPacketLength = PacketDataLength;
\r
547 switch ( NdefMap->CardType)
\r
549 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
550 case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
\r
551 /* Mifare card selected. Call Mifare Write */
\r
552 status = phFriNfc_MifareUL_WrNdef( NdefMap,
\r
557 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
\r
559 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
560 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
\r
562 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 :
\r
563 #endif /* #ifdef DESFIRE_EV1 */
\r
564 /* Desfire card selected. Call Desfire Write */
\r
565 status = phFriNfc_Desfire_WrNdef( NdefMap,
\r
570 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
572 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
573 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
\r
574 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
\r
575 /* Mifare card selected. Call Mifare read */
\r
576 status = phFriNfc_MifareStdMap_WrNdef ( NdefMap,
\r
581 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
583 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
584 case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
\r
585 /* Desfire card selected. Call Desfire Write */
\r
586 status = phFriNfc_Felica_WrNdef( NdefMap,
\r
591 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
593 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
594 case PH_FRINFC_NDEFMAP_TOPAZ_CARD :
\r
595 /* Topaz card selected. Call Topaz Write */
\r
596 status = phFriNfc_TopazMap_WrNdef( NdefMap,
\r
601 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
602 case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD :
\r
603 /* Topaz card selected. Call Topaz Write */
\r
604 status = phFriNfc_TopazDynamicMap_WrNdef( NdefMap,
\r
609 #endif /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */
\r
610 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED */
\r
612 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
613 case PH_FRINFC_NDEFMAP_ISO15693_CARD:
\r
614 status = phFriNfc_ISO15693_WrNdef( NdefMap,
\r
619 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
\r
622 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
623 case PH_FRINFC_NDEFMAP_MOCKUP_CARD :
\r
624 /* Mockup card selected. Call Mockup Write */
\r
625 status = phFriNfc_Mockup_WrNdef( NdefMap,
\r
630 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
632 /* Unknown card type. Return error */
\r
633 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
634 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
642 #ifdef FRINFC_READONLY_NDEF
\r
645 phFriNfc_NdefMap_ConvertToReadOnly (
\r
646 phFriNfc_NdefMap_t *NdefMap)
\r
648 NFCSTATUS result = NFCSTATUS_PENDING;
\r
651 /* Check for ndefmap context and relevant state. Else return error*/
\r
652 if (NULL == NdefMap)
\r
654 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
656 else if ((NdefMap->CompletionRoutine->CompletionRoutine == NULL)
\r
657 || (NdefMap->CompletionRoutine->Context == NULL))
\r
659 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
663 switch (NdefMap->CardType)
\r
665 case PH_FRINFC_NDEFMAP_TOPAZ_CARD:
\r
667 result = phFriNfc_TopazMap_ConvertToReadOnly (NdefMap);
\r
671 case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD:
\r
673 result = phFriNfc_TopazDynamicMap_ConvertToReadOnly (NdefMap);
\r
677 case PH_FRINFC_NDEFMAP_ISO15693_CARD:
\r
679 result = phFriNfc_ISO15693_ConvertToReadOnly (NdefMap);
\r
685 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
686 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
694 #endif /* #ifdef FRINFC_READONLY_NDEF */
\r
697 * Check whether a particular Remote Device is NDEF compliant.
\r
699 * The function initiates the ndef compliancy check.
\r
701 * This is a main check ndef api.Internally,depending upon the different
\r
702 * opmodes,respective mifare/desfire checkNdef apis are called.
\r
703 * In future this can be extended to check any types of card ndef
\r
706 * It performs a reset of the state and starts the action (state machine).
\r
707 * A periodic call of the \ref phFriNfcNdefMap_Process has to be done once
\r
708 * the action has been triggered.
\r
710 * NOTE: Please refer the header file for more information.
\r
714 NFCSTATUS phFriNfc_NdefMap_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
\r
716 NFCSTATUS status = NFCSTATUS_PENDING;
\r
720 /* Check for ndefmap context and relevant state. Else return error*/
\r
721 if ( NdefMap == NULL )
\r
723 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
727 if( (NdefMap->State != PH_FRINFC_NDEFMAP_STATE_RESET_INIT) ||
\r
728 (NdefMap->psRemoteDevInfo->SessionOpened != 0x01 ) )
\r
729 /* Harsha: If SessionOpened is not 1, this means that connect has not happened */
\r
731 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);
\r
733 else if ( (NdefMap->CompletionRoutine->CompletionRoutine == NULL) || (NdefMap->CompletionRoutine->Context == NULL ))
\r
735 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
741 * CardInfo106 Replace with the ReaderA_Info.
\r
744 sak = NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak;
\r
748 * Description: Opmode replace with RemDevType.
\r
752 switch ( NdefMap->psRemoteDevInfo->RemDevType )
\r
754 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
755 case phHal_eISO15693_PICC:
\r
757 status = phFriNfc_ISO15693_ChkNdef (NdefMap);
\r
760 #else /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
\r
761 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
762 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
763 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
\r
765 case phHal_eMifare_PICC:
\r
766 case phHal_eISO14443_3A_PICC:
\r
767 /* Remote device is Mifare card . Check for Mifare
\r
771 /* The SAK/Sel_Res says the card is of the type
\r
773 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
774 status = phFriNfc_MifareUL_ChkNdef( NdefMap);
\r
775 #else /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
\r
776 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
777 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
778 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
\r
780 else if ((0x08 == (sak & 0x18)) ||
\r
781 (0x18 == (sak & 0x18)))
\r
783 /* The SAK/Sel_Res says the card is of the type
\r
785 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
786 status = phFriNfc_MifareStdMap_ChkNdef( NdefMap);
\r
787 #else /* PH_FRINFC_MAP_MIFARESTD_DISABLED*/
\r
788 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
789 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
790 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED*/
\r
794 /* Invalid Mifare UL card, as the remote device
\r
795 info - opmode says its a Mifare UL card but,
\r
796 The SAK/Sel_Res is wrong */
\r
797 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
798 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
801 case phHal_eISO14443_B_PICC:
\r
803 status = phFriNfc_Desfire_ChkNdef(NdefMap);
\r
806 case phHal_eISO14443_A_PICC :
\r
807 /* Remote device is Desfire card . Check for Desfire
\r
809 if(0x20 == (sak & 0x20))
\r
811 /* The SAK/Sel_Res says the card is of the type
\r
813 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
814 status = phFriNfc_Desfire_ChkNdef(NdefMap);
\r
815 #else /* PH_FRINFC_MAP_DESFIRE_DISABLED*/
\r
816 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
817 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
818 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED*/
\r
822 /* Invalid Desfire card, as the remote device
\r
823 info - opmode says its a desfire card but,
\r
824 The SAK/Sel_Res is wrong */
\r
825 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
826 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
830 case phHal_eFelica_PICC:
\r
832 /*Set the OpMode Type Flag*/
\r
833 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
834 #ifndef PH_HAL4_ENABLE
\r
835 NdefMap->OpModeType[0] = phHal_eOpModesFelica212;
\r
836 NdefMap->OpModeType[1] = phHal_eOpModesArrayTerminator;
\r
837 #endif /* #ifndef PH_HAL4_ENABLE */
\r
838 status = phFriNfc_Felica_ChkNdef(NdefMap);
\r
839 #else /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
840 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
841 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
842 #endif /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
846 #ifndef PH_HAL4_ENABLE
\r
847 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
848 case phHal_eFelica424:
\r
849 /*Set the OpMode Ttype Flag*/
\r
850 NdefMap->OpModeType[0] = phHal_eOpModesFelica424;
\r
851 NdefMap->OpModeType[1] = phHal_eOpModesArrayTerminator;
\r
852 status = phFriNfc_Felica_ChkNdef(NdefMap);
\r
853 #else /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
854 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
855 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
856 #endif /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
860 case phHal_eJewel_PICC :
\r
861 /* Remote device is Topaz card . Check for Topaz
\r
863 #ifdef PH_HAL4_ENABLE
\r
864 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
865 /* Decide on the Header bytes to know the
\r
866 Type of the Topaz card.Card could be Static or
\r
867 Dynamic type. These are of type NFFC-NDEF Data Application*/
\r
868 if ( NdefMap->psRemoteDevInfo->RemoteDevInfo.Jewel_Info.HeaderRom0
\r
869 == PH_FRINFC_TOPAZ_HEADROM0_VAL)
\r
872 status = phFriNfc_TopazMap_ChkNdef(NdefMap);
\r
874 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
875 else if( NdefMap->psRemoteDevInfo->RemoteDevInfo.Jewel_Info.HeaderRom0
\r
876 == PH_FRINFC_TOPAZ_DYNAMIC_HEADROM0_VAL)
\r
879 status = phFriNfc_TopazDynamicMap_ChkNdef(NdefMap);
\r
885 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
886 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
895 /* The SAK/Sel_Res says the card is of the type
\r
897 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
898 status = phFriNfc_TopazMap_ChkNdef(NdefMap);
\r
899 #else /* PH_FRINFC_MAP_TOPAZ_DISABLED*/
\r
900 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
901 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
902 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED*/
\r
906 /* Invalid Topaz card, as the remote device
\r
907 info - opmode says its a desfire card but,
\r
908 The SAK/Sel_Res is wrong */
\r
909 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
910 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
915 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
916 case phHal_eOpModesMockup :
\r
917 /*Set the OpMode Ttype Flag*/
\r
918 NdefMap->OpModeType[0] = phHal_eOpModesMockup;
\r
919 NdefMap->OpModeType[1] = phHal_eOpModesArrayTerminator;
\r
920 status = phFriNfc_Mockup_ChkNdef(NdefMap);
\r
922 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
925 /* Remote device is not recognised.
\r
926 Probably not NDEF compliant */
\r
927 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
928 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
938 * \brief Completion Routine, Processing function, needed to avoid long blocking.
\r
939 * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
\r
940 * Routine in order to be able to notify the component that an I/O has finished and data are
\r
941 * ready to be processed.
\r
942 * This is a main Ndef Map Process api.Internally,depending upon the different
\r
943 * CardTypes,respective mifare/desfire process functions are called.
\r
947 void phFriNfc_NdefMap_Process( void *Context,
\r
951 if ( Context != NULL )
\r
953 phFriNfc_NdefMap_t *NdefMap = (phFriNfc_NdefMap_t *)Context;
\r
956 * Description: Opmode replace with RevDevTyp.
\r
959 switch ( NdefMap->psRemoteDevInfo->RemDevType )
\r
961 case phHal_eMifare_PICC :
\r
962 case phHal_eISO14443_3A_PICC:
\r
964 if((NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD) ||
\r
965 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))
\r
967 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
968 /* Remote device is Mifare Standard card */
\r
969 phFriNfc_MifareStdMap_Process(NdefMap,Status);
\r
970 #else /* PH_FRINFC_MAP_MIFARESTD_DISABLED*/
\r
971 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
972 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
973 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED*/
\r
977 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
978 /* Remote device is Mifare UL card */
\r
979 phFriNfc_MifareUL_Process(NdefMap,Status);
\r
980 #else /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
\r
981 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
982 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
983 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
\r
987 case phHal_eISO14443_A_PICC :
\r
988 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
989 /* Remote device is Desfire card */
\r
990 phFriNfc_Desfire_Process(NdefMap, Status);
\r
991 #else /* PH_FRINFC_MAP_DESFIRE_DISABLED*/
\r
992 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
993 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
994 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED*/
\r
996 case phHal_eISO14443_B_PICC:
\r
997 /* Remote device is Desfire card */
\r
998 phFriNfc_Desfire_Process(NdefMap, Status);
\r
1001 case phHal_eFelica_PICC :
\r
1002 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
1003 /* Remote device is Felica Smart card */
\r
1004 phFriNfc_Felica_Process(NdefMap, Status);
\r
1005 #else /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
1006 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
1007 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1008 #endif /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
1011 case phHal_eJewel_PICC:
\r
1012 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
1013 if ( NdefMap->CardType == PH_FRINFC_NDEFMAP_TOPAZ_CARD )
\r
1015 /* Remote device is Topaz Smart card */
\r
1016 phFriNfc_TopazMap_Process(NdefMap, Status);
\r
1018 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
1019 else if ( NdefMap->CardType == PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD )
\r
1021 /* Remote device is Topaz Smart card */
\r
1022 phFriNfc_TopazDynamicMap_Process(NdefMap, Status);
\r
1026 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
1027 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1031 #endif /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED*/
\r
1035 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
1036 case phHal_eOpModesMockup:
\r
1037 /* Remote device is Desfire card */
\r
1038 phFriNfc_Mockup_Process(NdefMap, Status);
\r
1040 #endif /* PHFRINFC_OVRHAL_MOCKUP*/
\r
1042 /* Remote device opmode not recognised.
\r
1043 Probably not NDEF compliant */
\r
1044 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
1045 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1046 /* set the state back to the Reset_Init state*/
\r
1047 NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
\r
1049 /* set the completion routine*/
\r
1050 NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_INVALID_OPE].
\r
1051 CompletionRoutine(NdefMap->CompletionRoutine->Context, Status);
\r
1057 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
1058 NFCSTATUS_INVALID_PARAMETER);
\r
1059 /* The control should not come here. As Context itself is NULL ,
\r
1060 Can't call the CR*/
\r
1066 NFCSTATUS phFriNfc_ChkAndParseTLV(phFriNfc_NdefMap_t *NdefMap)
\r
1068 NFCSTATUS status = NFCSTATUS_PENDING;
\r
1070 switch ( NdefMap->CardType )
\r
1072 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
1073 case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
\r
1077 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
\r
1079 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
1080 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
\r
1081 status = phFriNfc_Desf_ChkAndParseTLV(NdefMap);
\r
1085 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
1087 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
1088 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
\r
1089 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
\r
1092 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
1094 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
1095 case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
\r
1098 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
1101 /* Unknown card type. Return error */
\r
1102 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
1103 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1113 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
1114 static void phFriNfc_DesfCapCont_HReset(phFriNfc_NdefMap_t *NdefMap)
\r
1116 /* Initialise/reset the desfire capability contatiner structure variables*/
\r
1117 NdefMap->DesfireCapContainer.DesfVersion = 0;
\r
1118 NdefMap->DesfireCapContainer.NdefMsgFid = 0;
\r
1119 NdefMap->DesfireCapContainer.NdefFileSize = 0;
\r
1120 NdefMap->DesfireCapContainer.MaxCmdSize = 0;
\r
1121 NdefMap->DesfireCapContainer.MaxRespSize = 0;
\r
1122 NdefMap->DesfireCapContainer.ReadAccess = 0;
\r
1123 NdefMap->DesfireCapContainer.WriteAccess = 0;
\r
1125 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
1127 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
1128 static void phFriNfc_Felica_HReset(phFriNfc_NdefMap_t *NdefMap)
\r
1132 /* Initialise/reset the different felica structure variables*/
\r
1133 /* Reset all the felica Basic staruture variables*/
\r
1134 NdefMap->Felica.CurBlockNo = 0;
\r
1136 for(index = 0;index<PH_FRINFC_NDEFMAP_FELICA_BLOCK_SIZE;index++)
\r
1138 NdefMap->Felica.Rd_BytesToCopyBuff[index] = 0;
\r
1139 NdefMap->Felica.Wr_RemainedBytesBuff[index] = 0;
\r
1141 NdefMap->Felica.Rd_NoBytesToCopy = 0;
\r
1142 NdefMap->Felica.Wr_BytesRemained = 0;
\r
1145 /* Reset all the felica attribute information staruture variables*/
\r
1146 for(index = 0;index<PH_FRINFC_NDEFMAP_FELICA_ATTR_NDEF_DATA_LEN;index++)
\r
1148 NdefMap->FelicaAttrInfo.LenBytes[index] = 0;
\r
1151 NdefMap->FelicaAttrInfo.Nmaxb = 0;
\r
1152 NdefMap->FelicaAttrInfo.Nbr = 0;
\r
1153 NdefMap->FelicaAttrInfo.Nbw= 0;
\r
1154 NdefMap->FelicaAttrInfo.RdWrFlag = 0;
\r
1155 NdefMap->FelicaAttrInfo.WriteFlag = 0;
\r
1156 NdefMap->Felica.CurrBytesRead=0;
\r
1158 /* Reset all the felica manufacture details staruture variables*/
\r
1159 for(index = 0;index<PH_FRINFC_NDEFMAP_FELICA_MANUF_ID_DATA_LEN;index++)
\r
1161 NdefMap->FelicaManufDetails.ManufID[index] = 0;
\r
1162 NdefMap->FelicaManufDetails.ManufParameter[index] = 0;
\r
1164 NdefMap->Felica.NoBlocksWritten=0;
\r
1166 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
1168 NFCSTATUS phFriNfc_NdefMap_EraseNdef(phFriNfc_NdefMap_t *NdefMap)
\r
1170 NFCSTATUS status = NFCSTATUS_PENDING;
\r
1172 static uint8_t PktData[3] = PH_FRINFC_NDEFMAP_EMPTY_NDEF_MSG;
\r
1173 uint8_t MemOffset = PH_FRINFC_NDEFMAP_SEEK_BEGIN;
\r
1174 uint32_t PacketDataLength = sizeof(PktData);
\r
1176 if (NdefMap == NULL )
\r
1178 /* Invalid input parameter error */
\r
1179 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);
\r
1183 switch ( NdefMap->CardType)
\r
1185 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
1186 case PH_FRINFC_NDEFMAP_MOCKUP_CARD :
\r
1187 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
1188 case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
\r
1189 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
\r
1190 #ifdef DESFIRE_EV1
\r
1191 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 :
\r
1192 #endif /* #ifdef DESFIRE_EV1 */
\r
1193 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
\r
1194 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
\r
1195 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
1196 case PH_FRINFC_NDEFMAP_TOPAZ_CARD :
\r
1197 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
1198 case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD :
\r
1200 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
1201 case PH_FRINFC_NDEFMAP_ISO15693_CARD:
\r
1204 /* Mifare card selected. Call Mifare Write */
\r
1205 status = phFriNfc_NdefMap_WrNdef( NdefMap,
\r
1207 &PacketDataLength,
\r
1211 case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
\r
1213 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
1214 /* Felica card selected. Call to write EMPTY NDEF Msg */
\r
1215 status = phFriNfc_Felica_EraseNdef( NdefMap );
\r
1216 #else /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
1217 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
1218 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1219 #endif /* PH_FRINFC_MAP_FELICA_DISABLED*/
\r
1223 /* Unknown card type. Return error */
\r
1224 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
\r
1225 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1231 /* Harsha: Fix for the mantis entry 0000420: NDEF_MAP: Size of NDEF data:
\r
1232 no abstracted way for user to know how many bytes to read/write */
\r
1235 * \brief Helper API, exposed to the user to enable him to know the size
\r
1236 * of the NDEF data that he can write in to the card.
\r
1238 NFCSTATUS phFriNfc_NdefMap_GetContainerSize(const phFriNfc_NdefMap_t *NdefMap,uint32_t *maxSize, uint32_t *actualSize)
\r
1240 NFCSTATUS result = NFCSTATUS_SUCCESS;
\r
1241 uint8_t sect_index = 0;
\r
1242 uint8_t actual_sect_index = 0;
\r
1243 uint8_t count_index = 0;
\r
1245 if( (NdefMap == NULL) || (maxSize == NULL) || (actualSize == NULL))
\r
1247 /* Invalid input parameter error */
\r
1248 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);
\r
1252 /* Which card ? */
\r
1253 switch(NdefMap->CardType)
\r
1255 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
\r
1256 case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
\r
1257 /* Mifare UL card */
\r
1258 /* The integration needs to ensure that the checkNdef
\r
1259 function has been called before calling this function,
\r
1260 otherwise NdefMap->CardMemSize will be 0 */
\r
1261 *maxSize = NdefMap->MifareULContainer.RemainingSize;
\r
1262 /* In Mifare UL card, the actual size is the length field
\r
1263 value of the TLV */
\r
1264 *actualSize = NdefMap->TLVStruct.ActualSize;
\r
1266 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
\r
1268 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
\r
1269 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
\r
1270 #ifdef DESFIRE_EV1
\r
1271 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 :
\r
1272 #endif /* #ifdef DESFIRE_EV1 */
\r
1273 /* Desfire card */
\r
1274 /* The integration needs to ensure that the checkNdef
\r
1275 function has been called before calling this function,
\r
1276 otherwise NdefMap->DesfireCapContainer.NdefFileSize
\r
1278 /* -2 bytes represents the size field bytes*/
\r
1279 *maxSize = NdefMap->DesfireCapContainer.NdefFileSize - 2;
\r
1280 /* In Desfire card, the actual size cant be calculated so
\r
1281 the actual size is given as 0xFFFFFFFF */
\r
1282 *actualSize = NdefMap->DesfireCapContainer.NdefDataLen;
\r
1284 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
\r
1286 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
\r
1287 case PH_FRINFC_NDEFMAP_TOPAZ_CARD :
\r
1289 /* The integration needs to ensure that the checkNdef
\r
1290 function has been called before calling this function,
\r
1291 otherwise NdefMap->CardMemSize will be 0 */
\r
1292 *maxSize = NdefMap->TopazContainer.RemainingSize;
\r
1293 /* In Topaz card, the actual size is the length field value of the
\r
1295 *actualSize = NdefMap->TLVStruct.BytesRemainLinTLV;
\r
1297 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
\r
1298 case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD :
\r
1299 /* Topaz 512 card */
\r
1300 /* The integration needs to ensure that the checkNdef
\r
1301 function has been called before calling this function,
\r
1302 otherwise NdefMap->CardMemSize will be 0 */
\r
1303 *maxSize = NdefMap->TopazContainer.NDEFRWSize;
\r
1304 /* In Topaz card, the actual size is the length field value of the
\r
1306 *actualSize = NdefMap->TopazContainer.ActualNDEFMsgSize;
\r
1309 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED */
\r
1310 #endif /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */
\r
1311 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
\r
1312 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
\r
1313 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
\r
1314 /* Mifare std card */
\r
1316 /* Max size is the number of NDEF compliant blocks in the card
\r
1317 multiplied by 16 bytes */
\r
1318 #ifndef PH_HAL4_ENABLE
\r
1320 *maxSize = NdefMap->StdMifareContainer.remainingSize;
\r
1322 #else /* #ifndef PH_HAL4_ENABLE */
\r
1324 while ((PH_FRINFC_MIFARESTD_NDEF_COMP ==
\r
1325 NdefMap->StdMifareContainer.aid[count_index]) &&
\r
1327 PH_FRINFC_NDEFMAP_MIFARESTD_TOTALNO_BLK))
\r
1329 actual_sect_index++;
\r
1332 /* Total number of sectors in 1k = 16 (0 to 15, MAD sector number = 0)
\r
1333 Total number of sectors in 4k = 40 (0 to 39,
\r
1334 MAD sector number = 0 and 16, After block number 31, each sector
\r
1336 Every last block of the sector is the sector header, So the blocks
\r
1337 that can be read or written in each sector is always
\r
1338 (number of blocks in each sector - 1)
\r
1339 No of blocks in the one sector till the sector number 0 to 31
\r
1340 (total 32 sectors) =
\r
1341 4 blocks, So blocks that can be read/write = (4 - 1 = 3 blocks)
\r
1342 No of blocks in the one sector after the sector number 31 to 39 =
\r
1343 16 blocks, So blocks that can be read/write = (16 - 1 = 15 blocks)
\r
1344 Each block has 16 bytes
\r
1345 To calculate number of bytes in the sector, depending on the number
\r
1346 of blocks multiplied by 16
\r
1348 if (PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD ==
\r
1349 NdefMap->CardType)
\r
1351 if (actual_sect_index > 32)
\r
1353 sect_index = (actual_sect_index - 32);
\r
1354 /* Here, 30 is used because block number 0 and 16 are MAD blocks
\r
1355 which cannot be used for reading and writing data
\r
1356 3 and 15 are blocks in each sector which can be read/write
\r
1357 3 indicates the sector is in between (0 and 31)
\r
1358 15 indicates the sector is in between (32 to 39)
\r
1359 16 is always number of bytes in each block
\r
1360 4 is used because each NDEF write has to write using the
\r
1361 TLV format and T & L takes 4 bytes length and V is the
\r
1364 *maxSize = (((30 * (16 * 3)) + (sect_index * (16 * 15))) - 4);
\r
1366 else if (actual_sect_index <= 16)
\r
1368 *maxSize = (((actual_sect_index - 1) * (16 * 3)) - 4);
\r
1372 *maxSize = (((actual_sect_index - 2) * (16 * 3)) - 4);
\r
1377 /* Here, 16 is always number of bytes in each block
\r
1378 3 indicates the sector is in between (0 and 31) */
\r
1379 if (actual_sect_index > NdefMap->StdMifareContainer.SectorIndex)
\r
1381 actual_sect_index = NdefMap->StdMifareContainer.SectorIndex;
\r
1383 *maxSize = (((actual_sect_index - 1) * (16 * 3)) - 4);
\r
1386 #endif /* #ifndef PH_HAL4_ENABLE */
\r
1387 *actualSize = NdefMap->TLVStruct.BytesRemainLinTLV;
\r
1390 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
\r
1392 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
\r
1393 case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
\r
1396 *maxSize = NdefMap->FelicaAttrInfo.Nmaxb * 0x10;
\r
1398 /* In Felica Card, actual size is calculated using the Length Bytes */
\r
1399 *actualSize = NdefMap->FelicaAttrInfo.LenBytes[0];
\r
1400 *actualSize = *actualSize << 16;
\r
1401 *actualSize += NdefMap->FelicaAttrInfo.LenBytes[1];
\r
1402 *actualSize = *actualSize << 8;
\r
1403 *actualSize += NdefMap->FelicaAttrInfo.LenBytes[2];
\r
1405 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
\r
1407 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
\r
1408 case PH_FRINFC_NDEFMAP_ISO15693_CARD:
\r
1411 uint16_t block_no = 0;
\r
1412 uint8_t byte_no = 0;
\r
1414 block_no = (uint16_t)
\r
1415 ISO15693_GET_VALUE_FIELD_BLOCK_NO (
\r
1416 NdefMap->ISO15693Container.ndef_tlv_type_blk,
\r
1417 NdefMap->ISO15693Container.ndef_tlv_type_byte,
\r
1418 NdefMap->ISO15693Container.actual_ndef_size);
\r
1419 byte_no = (uint8_t)
\r
1420 ISO15693_GET_VALUE_FIELD_BYTE_NO (
\r
1421 NdefMap->ISO15693Container.ndef_tlv_type_blk,
\r
1422 NdefMap->ISO15693Container.ndef_tlv_type_byte,
\r
1423 NdefMap->ISO15693Container.actual_ndef_size);
\r
1425 *maxSize = (NdefMap->ISO15693Container.max_data_size -
\r
1426 ((block_no * ISO15693_BYTES_PER_BLOCK) + byte_no));
\r
1428 /* 2 is used to exclude the T and L part of the TLV */
\r
1429 *maxSize = (NdefMap->ISO15693Container.max_data_size
\r
1430 - ISO15693_BYTES_PER_BLOCK - 2);
\r
1431 #endif /* #if 1 */
\r
1432 *actualSize = NdefMap->ISO15693Container.actual_ndef_size;
\r
1437 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
1438 case PH_FRINFC_NDEFMAP_MOCKUP_CARD :
\r
1439 *maxSize = 0xFFFFFFFF;
\r
1440 /* In Desfire card, the actual size cant be calculated so
\r
1441 the actual size is given as 0xFFFFFFFF */
\r
1442 *actualSize = 0xFFFFFFFF;
\r
1444 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r
1447 /* Unknown card type. Return error */
\r
1448 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
\r
1449 NFCSTATUS_INVALID_REMOTE_DEVICE);
\r
1456 #ifdef PHFRINFC_OVRHAL_MOCKUP
\r
1457 NFCSTATUS phFriNfc_NdefMap_MockupCardSetter(phFriNfc_NdefMap_t *NdefMap,
\r
1458 uint8_t *NdefData,
\r
1459 uint32_t NdefActualSize,
\r
1460 uint32_t NdefMaxSize,
\r
1461 uint32_t CardSize)
\r
1463 NFCSTATUS Status = NFCSTATUS_SUCCESS;
\r
1464 // First check all parameters
\r
1465 if((NdefData != NULL) && (NdefMap != NULL))
\r
1468 NdefMap->MochupContainer.NdefData = NdefData;
\r
1469 NdefMap->MochupContainer.NdefActualSize = NdefActualSize;
\r
1470 NdefMap->MochupContainer.NdefMaxSize = NdefMaxSize;
\r
1471 NdefMap->MochupContainer.CardSize = CardSize;
\r
1472 NdefMap->MochupContainer.CurrentBlock = 0;
\r
1476 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);
\r
1481 NFCSTATUS phFriNfc_NdefMap_MockupNDefModeEn(uint8_t *pNdefCompliancy, uint8_t *pCardType, uint8_t Enable)
\r
1483 *pNdefCompliancy = Enable;
\r
1484 *pCardType = PH_FRINFC_NDEFMAP_MOCKUP_CARD;
\r
1485 return NFCSTATUS_SUCCESS;
\r
1487 #endif /* PHFRINFC_OVRHAL_MOCKUP */
\r