code update
[adaptation/devices/nfc-plugin-nxp.git] / src / phFriNfc_NdefMap.c
1 /*\r
2  * Copyright (C) 2010 NXP Semiconductors\r
3  *\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
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 /*!\r
18 * \file  phFriNfcNdefMap.c\r
19 * \brief NFC Ndef Mapping For Different Smart Cards.\r
20 *\r
21 * Project: NFC-FRI\r
22 *\r
23 * $Date: Mon Dec 13 14:14:12 2010 $\r
24 * $Author: ing02260 $\r
25 * $Revision: 1.39 $\r
26 * $Aliases:  $\r
27 *\r
28 */\r
29 \r
30 \r
31 #include <phFriNfc_NdefMap.h>\r
32 \r
33 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED\r
34 #include <phFriNfc_MifareULMap.h>\r
35 #endif  /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/\r
36 \r
37 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED\r
38 #include <phFriNfc_TopazMap.h>\r
39 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED */\r
40 \r
41 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED\r
42 #include <phFriNfc_MifareStdMap.h>\r
43 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */\r
44 \r
45 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED\r
46 #include <phFriNfc_DesfireMap.h>\r
47 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
48 \r
49 #ifndef PH_FRINFC_MAP_FELICA_DISABLED\r
50 #include <phFriNfc_FelicaMap.h>\r
51 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
52 \r
53 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
54 #include <phFriNfc_ISO15693Map.h>\r
55 #endif  /* PH_FRINFC_MAP_ISO15693_DISABLED */\r
56 \r
57 #ifdef PHFRINFC_OVRHAL_MOCKUP\r
58 #include <phFriNfc_MockupMap.h>\r
59 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
60 \r
61 \r
62 #include <phFriNfc_OvrHal.h>\r
63 \r
64 /*! \ingroup grp_file_attributes\r
65 *  \name NDEF Mapping\r
66 *\r
67 * File: \ref phFriNfcNdefMap.c\r
68 *\r
69 */\r
70 /*@{*/\r
71 #define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.39 $"\r
72 #define PHFRINFCNDEFMAP_FILEALIASES  "$Aliases:  $"\r
73 /*@}*/\r
74 \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
79 \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
84 \r
85 \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
90 */\r
91 \r
92 NFCSTATUS phFriNfc_NdefMap_Reset(   phFriNfc_NdefMap_t              *NdefMap,\r
93                                  void                            *LowerDevice,\r
94                                  phHal_sRemoteDevInformation_t   *psRemoteDevInfo,\r
95                                  phHal_sDevInputParam_t          *psDevInputParam,\r
96                                  uint8_t                         *TrxBuffer,\r
97                                  uint16_t                        TrxBufferSize,\r
98                                  uint8_t                         *ReceiveBuffer,\r
99                                  uint16_t                        *ReceiveLength,\r
100                                  uint16_t                        *DataCount)\r
101 {\r
102     NFCSTATUS   status = NFCSTATUS_SUCCESS;\r
103     uint8_t     index;\r
104 \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
110     {\r
111         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
112     }\r
113     else\r
114     {\r
115         /* Initialise the state to Init */\r
116         NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;\r
117 \r
118         for(index = 0;index<PH_FRINFC_NDEFMAP_CR;index++)\r
119         {\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
124         }\r
125 \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
129 \r
130         /* Remote Device info received from Manual Device Discovery is registered here */\r
131         NdefMap->psRemoteDevInfo = psRemoteDevInfo;\r
132 \r
133         /* Transfer Buffer registered */\r
134         NdefMap->ApduBuffer = TrxBuffer;\r
135 \r
136         /* Set the MaxApduBufferSize */\r
137         NdefMap->ApduBufferSize = TrxBufferSize;\r
138 \r
139         /* Set APDU Buffer Index */\r
140         NdefMap->ApduBuffIndex = 0;\r
141 \r
142         /* Register Transfer Buffer Length */\r
143         NdefMap->SendLength = 0;\r
144 \r
145         /* Register Receive Buffer */\r
146         NdefMap->SendRecvBuf = ReceiveBuffer;\r
147 \r
148         /* Register Receive Buffer Length */\r
149         NdefMap->SendRecvLength = ReceiveLength;\r
150 \r
151         /* Register Temporary Receive Buffer Length */\r
152         NdefMap->TempReceiveLength = *ReceiveLength;\r
153 \r
154         /* Register Data Count variable and set it to zero */\r
155         NdefMap->DataCount = DataCount;\r
156         *NdefMap->DataCount = 0;\r
157 \r
158         /* Reset the PageOffset */\r
159         NdefMap->Offset = 0;\r
160 \r
161         /* Reset the NumOfBytesRead*/\r
162         NdefMap->NumOfBytesRead = 0;\r
163 \r
164         /* Reset the NumOfBytesWritten*/\r
165         NdefMap->NumOfBytesWritten = 0;\r
166 \r
167         /* Reset the Card Type */\r
168         NdefMap->CardType = 0;\r
169 \r
170         /* Reset the Memory Card Size*/\r
171         NdefMap->CardMemSize = 0;\r
172 \r
173         /* Reset the Previous Operation*/\r
174         NdefMap->PrevOperation = 0;\r
175 \r
176         /* Reset the Desfire Operation Flag*/\r
177         NdefMap->DespOpFlag = 0;\r
178 \r
179         /* Reset MapCompletion Info*/\r
180         NdefMap->MapCompletionInfo.CompletionRoutine = NULL;\r
181         NdefMap->MapCompletionInfo.Context = NULL;\r
182 \r
183         /*  Reset the ReadingForWriteOperation flag. */\r
184         NdefMap->ReadingForWriteOperation = 0;  /*  FALSE  */\r
185 \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
190 \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
196 \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
202 \r
203 #if !(defined(PH_FRINFC_MAP_TOPAZ_DISABLED ) || defined (PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED ))\r
204 \r
205         phFriNfc_TopazMap_H_Reset(NdefMap);\r
206 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED || PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED  */\r
207 \r
208 \r
209 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED\r
210         status = phFriNfc_MifareUL_H_Reset(NdefMap);\r
211 #endif\r
212 \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
217 \r
218         /*\r
219         *  Fix for PR - 0001256\r
220         *  Date- 08-08-08\r
221         */\r
222         NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;\r
223     }\r
224 \r
225     return (status);\r
226 }\r
227 \r
228 /*!\r
229 * Registering the Completion Routine.\r
230 *\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
234 *\r
235 */\r
236 \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
241 {\r
242     NFCSTATUS   status = NFCSTATUS_SUCCESS;\r
243 \r
244     if ( ( NdefMap == NULL ) || (FunctionID >= PH_FRINFC_NDEFMAP_CR) ||\r
245         ( CompletionRoutine == NULL) || (CompletionRoutineContext == NULL))\r
246     {\r
247         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
248     }\r
249     else\r
250     {\r
251         /* Register the application callback with the NdefMap Completion Routine */\r
252         NdefMap->CompletionRoutine[FunctionID].CompletionRoutine = CompletionRoutine;\r
253 \r
254         /* Register the application context with the NdefMap Completion Routine context */\r
255         NdefMap->CompletionRoutine[FunctionID].Context = CompletionRoutineContext;\r
256     }\r
257 \r
258     return status;\r
259 }\r
260 \r
261 /*!\r
262 * Initiates Reading of NDEF information from the Remote Device.\r
263 *\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
267 *\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
271 *\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
275 *\r
276 * NOTE: Please refer the header file for more information.\r
277 *\r
278 */\r
279 \r
280 NFCSTATUS phFriNfc_NdefMap_RdNdef(  phFriNfc_NdefMap_t  *NdefMap,\r
281                                   uint8_t             *PacketData,\r
282                                   uint32_t            *PacketDataLength,\r
283                                   uint8_t             Offset)\r
284 {\r
285     NFCSTATUS   status = NFCSTATUS_PENDING;\r
286 \r
287 \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
296         )\r
297     {\r
298         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
299     }\r
300     else if (NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID)\r
301     {\r
302         /*  Card is in invalid state, cannot have any read/write\r
303         operations*/\r
304         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\\r
305             NFCSTATUS_INVALID_FORMAT);\r
306     }\r
307     else if(NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INITIALIZED)\r
308     {\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
311 \r
312         NdefMap->NumOfBytesRead = PacketDataLength;\r
313         *NdefMap->NumOfBytesRead = 0;\r
314 \r
315 \r
316     }\r
317     else if ( (NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_WRITE_OPE) && (Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ))\r
318     {\r
319         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);\r
320     }\r
321     else\r
322     {\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
328 \r
329         if ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )\r
330         {\r
331             NdefMap->ApduBuffIndex = 0;\r
332             *NdefMap->DataCount = 0;\r
333         }\r
334 \r
335         if  ( (NdefMap->CardType == PH_FRINFC_NDEFMAP_ISO14443_4A_CARD) &&\r
336             (Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) && (*NdefMap->DataCount == 0 ))\r
337         {\r
338 \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
343         }\r
344         else\r
345         {\r
346             switch ( NdefMap->CardType)\r
347             {\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
352                         PacketData,\r
353                         PacketDataLength,\r
354                         Offset);\r
355                     break;\r
356 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */\r
357 \r
358 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED\r
359                 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :\r
360 #ifdef DESFIRE_EV1\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
365                         PacketData,\r
366                         PacketDataLength,\r
367                         Offset);\r
368                     break;\r
369 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
370 \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
376                         PacketData,\r
377                         PacketDataLength,\r
378                         Offset);\r
379                     break;\r
380 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */\r
381 \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
386                         PacketData,\r
387                         PacketDataLength,\r
388                         Offset);\r
389                     break;\r
390 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
391 \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
396                         PacketData,\r
397                         PacketDataLength,\r
398                         Offset);\r
399                     break;\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
404                         PacketData,\r
405                         PacketDataLength,\r
406                         Offset);\r
407                     break;\r
408 #endif  /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */\r
409 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED */\r
410 \r
411 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
412                 case PH_FRINFC_NDEFMAP_ISO15693_CARD:\r
413                     status =  phFriNfc_ISO15693_RdNdef(  NdefMap,\r
414                         PacketData,\r
415                         PacketDataLength,\r
416                         Offset);\r
417                     break;\r
418 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */\r
419 \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
424                         PacketData,\r
425                         PacketDataLength,\r
426                         Offset);\r
427                     break;\r
428 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
429 \r
430                 default :\r
431                     /*  Unknown card type. Return error */\r
432                     status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\\r
433                         NFCSTATUS_INVALID_REMOTE_DEVICE);\r
434 \r
435                     break;\r
436             }\r
437         }\r
438     }\r
439     return status;\r
440 }\r
441 \r
442 /*!\r
443 * Initiates Writing of NDEF information to the Remote Device.\r
444 *\r
445 * The function initiates the writing of NDEF information to a Remote Device\r
446 *\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
450 *\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
454 *\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
458 *\r
459 * NOTE: Please refer the header file for more information.\r
460 *\r
461 */\r
462 \r
463 \r
464 NFCSTATUS phFriNfc_NdefMap_WrNdef(  phFriNfc_NdefMap_t  *NdefMap,\r
465                                   uint8_t             *PacketData,\r
466                                   uint32_t            *PacketDataLength,\r
467                                   uint8_t             Offset)\r
468 {\r
469     NFCSTATUS   status = NFCSTATUS_PENDING;\r
470     uint8_t     StatusChk=0;\r
471 \r
472      if (     (PacketData          == NULL)\r
473         ||  ( NdefMap             == NULL )\r
474         /* + Mantis 442 */\r
475         || ( PacketDataLength    == NULL )\r
476         /* - Mantis 442 */\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
481         )\r
482     {\r
483         /*  Invalid input parameter error   */\r
484         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);\r
485     }\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
489     {\r
490         /*  Card is in invalid state, cannot have any read/write\r
491         operations*/\r
492         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\\r
493             NFCSTATUS_INVALID_FORMAT);\r
494     }\r
495 \r
496     else if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY )\r
497 \r
498     {\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
502 \r
503         /* set the no. bytes written is zero*/\r
504         NdefMap->WrNdefPacketLength = PacketDataLength;\r
505         *NdefMap->WrNdefPacketLength = 0;\r
506 \r
507     }\r
508     else\r
509     {\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
517         {\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
523         }\r
524 \r
525         if ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )\r
526         {\r
527             NdefMap->ApduBuffIndex = 0;\r
528             *NdefMap->DataCount = 0;\r
529         }\r
530 \r
531         if ( (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_UL_CARD) ||\r
532             (NdefMap->CardType == PH_FRINFC_NDEFMAP_ISO14443_4A_CARD))\r
533         {\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
536             {\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
541                 StatusChk = 1;\r
542             }\r
543         }\r
544         if(StatusChk != 1)\r
545         {\r
546             NdefMap->WrNdefPacketLength =   PacketDataLength;\r
547             switch ( NdefMap->CardType)\r
548             {\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
553                         PacketData,\r
554                         PacketDataLength,\r
555                         Offset);\r
556                     break;\r
557 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */\r
558 \r
559 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED\r
560                 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :\r
561 #ifdef DESFIRE_EV1\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
566                         PacketData,\r
567                         PacketDataLength,\r
568                         Offset);\r
569                     break;\r
570 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
571 \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
577                         PacketData,\r
578                         PacketDataLength,\r
579                         Offset);\r
580                     break;\r
581 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */\r
582 \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
587                         PacketData,\r
588                         PacketDataLength,\r
589                         Offset);\r
590                     break;\r
591 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
592 \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
597                         PacketData,\r
598                         PacketDataLength,\r
599                         Offset);\r
600                     break;\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
605                         PacketData,\r
606                         PacketDataLength,\r
607                         Offset);\r
608                     break;\r
609 #endif  /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED */\r
610 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED */\r
611 \r
612 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
613                 case PH_FRINFC_NDEFMAP_ISO15693_CARD:\r
614                     status =  phFriNfc_ISO15693_WrNdef(  NdefMap,\r
615                         PacketData,\r
616                         PacketDataLength,\r
617                         Offset);\r
618                     break;\r
619 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */\r
620 \r
621 \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
626                         PacketData,\r
627                         PacketDataLength,\r
628                         Offset);\r
629                     break;\r
630 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
631                 default :\r
632                     /*  Unknown card type. Return error */\r
633                     status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\r
634                         NFCSTATUS_INVALID_REMOTE_DEVICE);\r
635                     break;\r
636             }\r
637         }\r
638     }\r
639     return status;\r
640 }\r
641 \r
642 #ifdef FRINFC_READONLY_NDEF\r
643 \r
644 NFCSTATUS\r
645 phFriNfc_NdefMap_ConvertToReadOnly (\r
646     phFriNfc_NdefMap_t          *NdefMap)\r
647 {\r
648     NFCSTATUS   result = NFCSTATUS_PENDING;\r
649 \r
650 \r
651     /*  Check for ndefmap context and relevant state. Else return error*/\r
652     if (NULL == NdefMap)\r
653     {\r
654         result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
655     }\r
656     else if ((NdefMap->CompletionRoutine->CompletionRoutine == NULL) \r
657         || (NdefMap->CompletionRoutine->Context == NULL))\r
658     {\r
659         result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
660     }\r
661     else\r
662     {\r
663         switch (NdefMap->CardType)\r
664         {\r
665             case PH_FRINFC_NDEFMAP_TOPAZ_CARD:\r
666             {\r
667                 result = phFriNfc_TopazMap_ConvertToReadOnly (NdefMap);\r
668                 break;\r
669             }\r
670 \r
671             case PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD:\r
672             {\r
673                 result = phFriNfc_TopazDynamicMap_ConvertToReadOnly (NdefMap);\r
674                 break;\r
675             }\r
676 \r
677             case PH_FRINFC_NDEFMAP_ISO15693_CARD:\r
678             {\r
679                 result = phFriNfc_ISO15693_ConvertToReadOnly (NdefMap);\r
680                 break;\r
681             }\r
682 \r
683             default:\r
684             {\r
685                 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\r
686                                     NFCSTATUS_INVALID_REMOTE_DEVICE);\r
687                 break;\r
688             }\r
689         }\r
690     }\r
691     return result;\r
692 }\r
693 \r
694 #endif /* #ifdef FRINFC_READONLY_NDEF */\r
695 \r
696 /*!\r
697 * Check whether a particular Remote Device is NDEF compliant.\r
698 *\r
699 * The function initiates the ndef compliancy check.\r
700 *\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
704 * compliancy.\r
705 *\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
709 *\r
710 * NOTE: Please refer the header file for more information.\r
711 *\r
712 */\r
713 \r
714 NFCSTATUS phFriNfc_NdefMap_ChkNdef( phFriNfc_NdefMap_t     *NdefMap)\r
715 {\r
716     NFCSTATUS   status = NFCSTATUS_PENDING;\r
717     uint8_t     sak;\r
718 \r
719 \r
720     /*  Check for ndefmap context and relevant state. Else return error*/\r
721     if ( NdefMap == NULL )\r
722     {\r
723         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
724     }\r
725     else\r
726     {\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
730         {\r
731             status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);\r
732         }\r
733         else if ( (NdefMap->CompletionRoutine->CompletionRoutine == NULL) || (NdefMap->CompletionRoutine->Context == NULL ))\r
734         {\r
735             status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
736         }\r
737         else\r
738         {\r
739             /*\r
740             * 1.Changed\r
741             *   CardInfo106 Replace with the ReaderA_Info.\r
742             */\r
743 \r
744             sak = NdefMap->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak;\r
745 \r
746             /*\r
747             * 3. Changed\r
748             *    Description: Opmode replace with RemDevType.\r
749             */\r
750 \r
751 \r
752             switch ( NdefMap->psRemoteDevInfo->RemDevType )\r
753             {\r
754 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
755             case phHal_eISO15693_PICC:\r
756             {\r
757                 status = phFriNfc_ISO15693_ChkNdef (NdefMap);\r
758                 break;\r
759             }\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
764 \r
765             case phHal_eMifare_PICC:\r
766             case phHal_eISO14443_3A_PICC:\r
767                 /*  Remote device is Mifare card . Check for Mifare\r
768                 NDEF compliancy */\r
769                 if(0x00 == sak)\r
770                 {\r
771                     /*  The SAK/Sel_Res says the card is of the type\r
772                     Mifare UL */\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
779                 }\r
780                 else if ((0x08 == (sak & 0x18)) ||\r
781                         (0x18 == (sak & 0x18)))\r
782                 {\r
783                     /*  The SAK/Sel_Res says the card is of the type\r
784                     Mifare Standard */\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
791                 }\r
792                 else\r
793                 {\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
799                 }\r
800                 break;\r
801             case phHal_eISO14443_B_PICC:\r
802                 {\r
803                     status = phFriNfc_Desfire_ChkNdef(NdefMap);\r
804                 }\r
805                 break;\r
806             case  phHal_eISO14443_A_PICC :\r
807                 /*  Remote device is Desfire card . Check for Desfire\r
808                 NDEF compliancy */\r
809                 if(0x20 == (sak & 0x20))\r
810                 {\r
811                     /*  The SAK/Sel_Res says the card is of the type\r
812                     ISO14443_4A */\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
819                 }\r
820                 else\r
821                 {\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
827                 }\r
828                 break;\r
829 \r
830             case phHal_eFelica_PICC:\r
831 \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
843 \r
844                 break;\r
845 \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
857                 break;\r
858 #endif\r
859 \r
860             case phHal_eJewel_PICC :\r
861                 /*  Remote device is Topaz card . Check for Topaz\r
862                 NDEF compliancy */\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
870                 {\r
871 \r
872                         status = phFriNfc_TopazMap_ChkNdef(NdefMap);\r
873                 }\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
877                 {\r
878 \r
879                     status = phFriNfc_TopazDynamicMap_ChkNdef(NdefMap);\r
880                 }\r
881 #endif\r
882                 else\r
883                 {\r
884 \r
885                     status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\r
886                            NFCSTATUS_INVALID_REMOTE_DEVICE);\r
887 \r
888                 }\r
889 #endif\r
890 \r
891 \r
892 #else\r
893                 if(0xC2 == sak)\r
894                 {\r
895                     /*  The SAK/Sel_Res says the card is of the type\r
896                     ISO14443_4A */\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
903                 }\r
904                 else\r
905                 {\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
911                 }\r
912 #endif\r
913                 break;\r
914 \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
921                 break;\r
922 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
923 \r
924             default :\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
929                 break;\r
930             }\r
931         }\r
932     }\r
933     return status;\r
934 }\r
935 \r
936 \r
937 /*!\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
944 *\r
945 */\r
946 \r
947 void phFriNfc_NdefMap_Process(  void        *Context,\r
948                               NFCSTATUS   Status)\r
949 {\r
950 \r
951     if ( Context != NULL )\r
952     {\r
953         phFriNfc_NdefMap_t  *NdefMap = (phFriNfc_NdefMap_t *)Context;\r
954         /*\r
955         * 4 Changed\r
956         *   Description: Opmode replace with RevDevTyp.\r
957         */\r
958 \r
959         switch ( NdefMap->psRemoteDevInfo->RemDevType )\r
960         {\r
961         case  phHal_eMifare_PICC :\r
962         case phHal_eISO14443_3A_PICC:\r
963 \r
964             if((NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD) ||\r
965                 (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD))\r
966             {\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
974             }\r
975             else\r
976             {\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
984             }\r
985             break;\r
986 \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
995             break;\r
996         case phHal_eISO14443_B_PICC:\r
997             /*  Remote device is Desfire card */\r
998             phFriNfc_Desfire_Process(NdefMap, Status);\r
999             break;\r
1000 \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
1009             break;\r
1010 \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
1014             {\r
1015                 /*  Remote device is Topaz Smart card */\r
1016                 phFriNfc_TopazMap_Process(NdefMap, Status);\r
1017             }\r
1018 #ifndef PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED\r
1019             else if ( NdefMap->CardType == PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD )\r
1020             {\r
1021                 /*  Remote device is Topaz Smart card */\r
1022                 phFriNfc_TopazDynamicMap_Process(NdefMap, Status);\r
1023             }\r
1024             else\r
1025             {\r
1026                 Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\r
1027                 NFCSTATUS_INVALID_REMOTE_DEVICE);\r
1028 \r
1029             }\r
1030             break;\r
1031 #endif  /* PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED*/\r
1032 #endif\r
1033 \r
1034 \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
1039             break;\r
1040 #endif  /* PHFRINFC_OVRHAL_MOCKUP*/\r
1041         default :\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
1048 \r
1049             /* set the completion routine*/\r
1050             NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_INVALID_OPE].\r
1051                 CompletionRoutine(NdefMap->CompletionRoutine->Context, Status);\r
1052             break;\r
1053         }\r
1054     }\r
1055     else\r
1056     {\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
1061     }\r
1062 }\r
1063 \r
1064 #if 0\r
1065 \r
1066 NFCSTATUS phFriNfc_ChkAndParseTLV(phFriNfc_NdefMap_t    *NdefMap)\r
1067 {\r
1068     NFCSTATUS status = NFCSTATUS_PENDING;\r
1069 \r
1070     switch ( NdefMap->CardType )\r
1071     {\r
1072 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED\r
1073             case  PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :\r
1074 \r
1075 \r
1076                 break;\r
1077 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */\r
1078 \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
1082                 return (status);\r
1083 \r
1084                 break;\r
1085 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
1086 \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
1090 \r
1091                 break;\r
1092 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */\r
1093 \r
1094 #ifndef PH_FRINFC_MAP_FELICA_DISABLED\r
1095             case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :\r
1096                 ;\r
1097                 break;\r
1098 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
1099 \r
1100             default :\r
1101                 /*  Unknown card type. Return error */\r
1102                 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\\r
1103                     NFCSTATUS_INVALID_REMOTE_DEVICE);\r
1104 \r
1105                 break;\r
1106     }\r
1107 \r
1108     return ( status);\r
1109 }\r
1110 #endif\r
1111 \r
1112 \r
1113 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED\r
1114 static void phFriNfc_DesfCapCont_HReset(phFriNfc_NdefMap_t *NdefMap)\r
1115 {\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
1124 }\r
1125 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
1126 \r
1127 #ifndef PH_FRINFC_MAP_FELICA_DISABLED\r
1128 static void phFriNfc_Felica_HReset(phFriNfc_NdefMap_t *NdefMap)\r
1129 {\r
1130     uint8_t index=0;\r
1131 \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
1135 \r
1136     for(index = 0;index<PH_FRINFC_NDEFMAP_FELICA_BLOCK_SIZE;index++)\r
1137     {\r
1138         NdefMap->Felica.Rd_BytesToCopyBuff[index] = 0;\r
1139         NdefMap->Felica.Wr_RemainedBytesBuff[index] = 0;\r
1140     }\r
1141     NdefMap->Felica.Rd_NoBytesToCopy = 0;\r
1142     NdefMap->Felica.Wr_BytesRemained = 0;\r
1143 \r
1144 \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
1147     {\r
1148         NdefMap->FelicaAttrInfo.LenBytes[index] = 0;\r
1149     }\r
1150 \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
1157 \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
1160     {\r
1161         NdefMap->FelicaManufDetails.ManufID[index] = 0;\r
1162         NdefMap->FelicaManufDetails.ManufParameter[index] = 0;\r
1163     }\r
1164     NdefMap->Felica.NoBlocksWritten=0;\r
1165 }\r
1166 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
1167 \r
1168 NFCSTATUS phFriNfc_NdefMap_EraseNdef(phFriNfc_NdefMap_t *NdefMap)\r
1169 {\r
1170     NFCSTATUS   status = NFCSTATUS_PENDING;\r
1171 \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
1175 \r
1176     if (NdefMap == NULL )\r
1177     {\r
1178         /*  Invalid input parameter error   */\r
1179         status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);\r
1180     }\r
1181     else\r
1182     {\r
1183         switch ( NdefMap->CardType)\r
1184         {\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
1199 #endif\r
1200 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
1201             case PH_FRINFC_NDEFMAP_ISO15693_CARD:\r
1202 #endif\r
1203 #endif\r
1204                 /*  Mifare card selected. Call Mifare Write */\r
1205                 status =  phFriNfc_NdefMap_WrNdef( NdefMap,\r
1206                     PktData,\r
1207                     &PacketDataLength,\r
1208                     MemOffset);\r
1209                 break;\r
1210 \r
1211             case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :\r
1212 \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
1220 \r
1221                 break;\r
1222             default :\r
1223                 /*  Unknown card type. Return error */\r
1224                 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\r
1225                     NFCSTATUS_INVALID_REMOTE_DEVICE);\r
1226                 break;\r
1227         }\r
1228     }\r
1229     return status;\r
1230 }\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
1233 \r
1234 /*!\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
1237 */\r
1238 NFCSTATUS phFriNfc_NdefMap_GetContainerSize(const phFriNfc_NdefMap_t *NdefMap,uint32_t *maxSize, uint32_t *actualSize)\r
1239 {\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
1244 \r
1245     if( (NdefMap == NULL) || (maxSize == NULL) || (actualSize == NULL))\r
1246     {\r
1247         /*  Invalid input parameter error   */\r
1248         result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_PARAMETER);\r
1249     }\r
1250     else\r
1251     {\r
1252         /*  Which card ? */\r
1253         switch(NdefMap->CardType)\r
1254         {\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
1265                 break;\r
1266 #endif  /* PH_FRINFC_MAP_MIFAREUL_DISABLED */\r
1267 \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
1277                 will be 0 */\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
1283                 break;\r
1284 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */\r
1285 \r
1286 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED\r
1287             case PH_FRINFC_NDEFMAP_TOPAZ_CARD :\r
1288                 /*  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
1294                 TLV */\r
1295                 *actualSize = NdefMap->TLVStruct.BytesRemainLinTLV;\r
1296                 break;\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
1305                 TLV */\r
1306                 *actualSize = NdefMap->TopazContainer.ActualNDEFMsgSize;\r
1307                 break;\r
1308 \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
1315 \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
1319 \r
1320                 *maxSize = NdefMap->StdMifareContainer.remainingSize;\r
1321 \r
1322 #else /* #ifndef PH_HAL4_ENABLE */\r
1323 \r
1324                 while ((PH_FRINFC_MIFARESTD_NDEF_COMP ==\r
1325                         NdefMap->StdMifareContainer.aid[count_index]) &&\r
1326                         (count_index <\r
1327                         PH_FRINFC_NDEFMAP_MIFARESTD_TOTALNO_BLK))\r
1328                 {\r
1329                     actual_sect_index++;\r
1330                     count_index++;\r
1331                 }\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
1335                         has 16 blocks)\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
1347                 */\r
1348                 if (PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD ==\r
1349                     NdefMap->CardType)\r
1350                 {\r
1351                     if (actual_sect_index > 32)\r
1352                     {\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
1362                             input data\r
1363                         */\r
1364                         *maxSize = (((30 * (16 * 3)) + (sect_index * (16 * 15))) - 4);\r
1365                     }\r
1366                     else if (actual_sect_index <= 16)\r
1367                     {\r
1368                         *maxSize = (((actual_sect_index - 1) * (16 * 3)) - 4);\r
1369                     }\r
1370                     else\r
1371                     {\r
1372                         *maxSize = (((actual_sect_index - 2)  * (16 * 3)) - 4);\r
1373                     }\r
1374                 }\r
1375                 else\r
1376                 {\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
1380                     {\r
1381                         actual_sect_index = NdefMap->StdMifareContainer.SectorIndex;\r
1382                     }\r
1383                     *maxSize = (((actual_sect_index - 1) * (16 * 3)) - 4);\r
1384                 }\r
1385 \r
1386 #endif /* #ifndef PH_HAL4_ENABLE */\r
1387                 *actualSize = NdefMap->TLVStruct.BytesRemainLinTLV;\r
1388 \r
1389                 break;\r
1390 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */\r
1391 \r
1392 #ifndef PH_FRINFC_MAP_FELICA_DISABLED\r
1393             case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :\r
1394                 /*  Felica card */\r
1395 \r
1396                 *maxSize = NdefMap->FelicaAttrInfo.Nmaxb * 0x10;\r
1397 \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
1404                 break;\r
1405 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */\r
1406 \r
1407 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED\r
1408             case PH_FRINFC_NDEFMAP_ISO15693_CARD:\r
1409             {\r
1410 #if 1\r
1411                 uint16_t                    block_no = 0;\r
1412                 uint8_t                     byte_no = 0;\r
1413 \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
1424 \r
1425                 *maxSize = (NdefMap->ISO15693Container.max_data_size - \r
1426                             ((block_no * ISO15693_BYTES_PER_BLOCK) + byte_no));\r
1427 #else /* #if 1 */\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
1433                 break;\r
1434             }\r
1435 #endif\r
1436 \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
1443                 break;\r
1444 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
1445 \r
1446             default :\r
1447                 /*  Unknown card type. Return error */\r
1448                 result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\\r
1449                     NFCSTATUS_INVALID_REMOTE_DEVICE);\r
1450                 break;\r
1451         }\r
1452     }\r
1453     return(result);\r
1454 }\r
1455 \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
1462 {\r
1463     NFCSTATUS Status = NFCSTATUS_SUCCESS;\r
1464     // First check all parameters\r
1465     if((NdefData != NULL) && (NdefMap != NULL))\r
1466     {\r
1467         // OK we can set\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
1473 \r
1474     } else\r
1475     {\r
1476         Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_PARAMETER);\r
1477     }\r
1478     return Status;\r
1479 }\r
1480 \r
1481 NFCSTATUS phFriNfc_NdefMap_MockupNDefModeEn(uint8_t  *pNdefCompliancy, uint8_t  *pCardType, uint8_t Enable)\r
1482 {\r
1483     *pNdefCompliancy = Enable;\r
1484     *pCardType = PH_FRINFC_NDEFMAP_MOCKUP_CARD;\r
1485     return NFCSTATUS_SUCCESS;\r
1486 }\r
1487 #endif  /* PHFRINFC_OVRHAL_MOCKUP */\r
1488 \r
1489 \r
1490 \r
1491 \r
1492 \r
1493 \r
1494 \r
1495 \r