2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * \file phFriNfc_MapTools.c
19 * \brief NFC Ndef Internal Mapping File.
23 * $Date: Fri Oct 15 13:50:54 2010 $
30 #include <phFriNfc_NdefMap.h>
31 #include <phFriNfc_MapTools.h>
33 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
34 #include <phFriNfc_MifareULMap.h>
35 #endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
37 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
38 #include <phFriNfc_MifareStdMap.h>
39 #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
41 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
42 #include <phFriNfc_DesfireMap.h>
43 #endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
45 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
46 #include <phFriNfc_FelicaMap.h>
47 #endif /* PH_FRINFC_MAP_FELICA_DISABLED */
49 #include <phFriNfc_OvrHal.h>
51 /*! \ingroup grp_file_attributes
54 * File: \ref phFriNfc_MapTools.c
55 * This file has functions which are used common across all the
56 * typ1/type2/type3/type4 tags.
60 #define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.6 $"
61 #define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: $"
64 NFCSTATUS phFriNfc_MapTool_SetCardState(phFriNfc_NdefMap_t *NdefMap,
67 NFCSTATUS Result = NFCSTATUS_SUCCESS;
68 if(Length == PH_FRINFC_NDEFMAP_MFUL_VAL0)
70 /* As the NDEF LEN / TLV Len is Zero, irrespective of any state the card
71 shall be set to INITIALIZED STATE*/
72 NdefMap->CardState =(uint8_t) (((NdefMap->CardState ==
73 PH_NDEFMAP_CARD_STATE_READ_ONLY) ||
74 (NdefMap->CardState ==
75 PH_NDEFMAP_CARD_STATE_INVALID))?
76 PH_NDEFMAP_CARD_STATE_INVALID:
77 PH_NDEFMAP_CARD_STATE_INITIALIZED);
81 switch(NdefMap->CardState)
83 case PH_NDEFMAP_CARD_STATE_INITIALIZED:
84 NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
85 PH_NDEFMAP_CARD_STATE_INVALID)?
87 PH_NDEFMAP_CARD_STATE_READ_WRITE);
90 case PH_NDEFMAP_CARD_STATE_READ_ONLY:
91 NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
92 PH_NDEFMAP_CARD_STATE_INVALID)?
94 PH_NDEFMAP_CARD_STATE_READ_ONLY);
97 case PH_NDEFMAP_CARD_STATE_READ_WRITE:
98 NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
99 PH_NDEFMAP_CARD_STATE_INVALID)?
101 PH_NDEFMAP_CARD_STATE_READ_WRITE);
105 NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
106 Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
107 NFCSTATUS_NO_NDEF_SUPPORT);
111 Result = ((NdefMap->CardState ==
112 PH_NDEFMAP_CARD_STATE_INVALID)?
113 PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
114 NFCSTATUS_NO_NDEF_SUPPORT):
119 /* To check mapping spec version */
121 NFCSTATUS phFriNfc_MapTool_ChkSpcVer( const phFriNfc_NdefMap_t *NdefMap,
122 uint8_t VersionIndex)
124 NFCSTATUS status = NFCSTATUS_SUCCESS;
126 uint8_t TagVerNo = NdefMap->SendRecvBuf[VersionIndex];
130 /*Return Status Error
\93 Invalid Format
\94*/
131 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
135 switch (NdefMap->CardType)
137 case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD:
138 case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD:
140 /* calculate the major and minor version number of Mifare std version number */
141 status = (( (( PH_NFCFRI_MFSTDMAP_NFCDEV_MAJOR_VER_NUM ==
142 PH_NFCFRI_MFSTDMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
143 ( PH_NFCFRI_MFSTDMAP_NFCDEV_MINOR_VER_NUM ==
144 PH_NFCFRI_MFSTDMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
145 (( PH_NFCFRI_MFSTDMAP_NFCDEV_MAJOR_VER_NUM ==
146 PH_NFCFRI_MFSTDMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
147 ( PH_NFCFRI_MFSTDMAP_NFCDEV_MINOR_VER_NUM <
148 PH_NFCFRI_MFSTDMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))?
150 PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
151 NFCSTATUS_INVALID_FORMAT));
156 case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1:
158 /* calculate the major and minor version number of T3VerNo */
159 if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 ==
160 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
161 ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM ==
162 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
163 (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 ==
164 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
165 ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
166 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))
168 status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
172 if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 <
173 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo) ) ||
174 ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 >
175 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo)))
177 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
182 #endif /* #ifdef DESFIRE_EV1 */
186 /* calculate the major and minor version number of T3VerNo */
187 if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
188 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
189 ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM ==
190 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
191 (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
192 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
193 ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
194 PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))
196 status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
200 if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM <
201 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo) ) ||
202 ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM >
203 PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo)))
205 status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);