• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 NXP Semiconductors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 /*
18  * \file  phFriNfc_MifStdFormat.h
19  * \brief NFC Ndef Formatting For Mifare standard card.
20  *
21  * Project: NFC-FRI
22  *
23  * $Date: Fri Sep 25 15:24:17 2009 $
24  * $Author: ing07299 $
25  * $Revision: 1.4 $
26  * $Aliases: NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
27  *
28  */
29 
30 #ifndef PHFRINFC_MIFSTDFORMAT_H
31 #define PHFRINFC_MIFSTDFORMAT_H
32 
33 #include <phFriNfc.h>
34 #ifdef PH_HAL4_ENABLE
35     #include <phHal4Nfc.h>
36 #else
37     #include <phHalNfc.h>
38 #endif /* #ifdef PH_HAL4_ENABLE */
39 #include <phNfcStatus.h>
40 #include <phNfcTypes.h>
41 #include <phFriNfc_SmtCrdFmt.h>
42 
43 #define PH_FRINFC_MIFSTD_FORMAT_FILEREVISION "$Revision: 1.4 $"
44 #define PH_FRINFC_MIFSTD_FORMAT_FILEALIASES  "$Aliases: NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"
45 
46 
47 /*!
48  * \name Mifare standard - constants for the state
49  *
50  */
51 /*@{*/
52 #define PH_FRINFC_MFSTD_FMT_RESET_INIT          0 /*!< Reset state */
53 #define PH_FRINFC_MFSTD_FMT_AUTH_SECT           1 /*!< Sector authentication is in progress */
54 #define PH_FRINFC_MFSTD_FMT_DIS_CON             2 /*!< Disconnect is in progress */
55 #define PH_FRINFC_MFSTD_FMT_CON                 3 /*!< Connect is in progress */
56 #define PH_FRINFC_MFSTD_FMT_POLL                4 /*!< Poll is in progress */
57 #define PH_FRINFC_MFSTD_FMT_RD_SECT_TR          5 /*!< Read sector trailer is in progress */
58 #define PH_FRINFC_MFSTD_FMT_WR_SECT_TR          6 /*!< Write sector trailer is in progress */
59 #define PH_FRINFC_MFSTD_FMT_WR_TLV              7 /*!< Write sector trailer is in progress */
60 #define PH_FRINFC_MFSTD_FMT_WR_MAD_BLK          8 /*!< Write MAD is in progress */
61 #define PH_FRINFC_MFSTD_FMT_UPD_MAD_BLK         9 /*!< Write MAD is in progress */
62 /*@}*/
63 
64 /*!
65 * \name Mifare standard - Authenticate states
66 *
67 */
68 /*@{*/
69 #define PH_FRINFC_MFSTD_FMT_AUTH_DEF_KEY    0   /*!< Trying to authenticate with the default key */
70 #define PH_FRINFC_MFSTD_FMT_AUTH_NFC_KEY    1   /*!< Trying to authenticate with the MAD key */
71 #define PH_FRINFC_MFSTD_FMT_AUTH_MAD_KEY    2   /*!< Trying to authenticate with the NFC forum key */
72 #define PH_FRINFC_MFSTD_FMT_AUTH_KEYB       3   /*!< Trying to authenticate with key B */
73 #define PH_FRINFC_MFSTD_FMT_AUTH_SCRT_KEYB  4   /*!< Trying to authenticate with secret key B */
74 
75 /*@}*/
76 
77 /*!
78 * \name Mifare standard - Update MAD block flag
79 *
80 */
81 /*@{*/
82 #define PH_FRINFC_MFSTD_FMT_NOT_A_MAD_BLK       0   /*!< Not a MAD block */
83 #define PH_FRINFC_MFSTD_FMT_MAD_BLK_1           1   /*!< MAD block number 1 */
84 #define PH_FRINFC_MFSTD_FMT_MAD_BLK_2           2   /*!< MAD block number 2 */
85 #define PH_FRINFC_MFSTD_FMT_MAD_BLK_64          64  /*!< MAD block number 64 (only used for Mifare 4k card) */
86 #define PH_FRINFC_MFSTD_FMT_MAD_BLK_65          65  /*!< MAD block number 65 (only used for Mifare 4k card) */
87 #define PH_FRINFC_MFSTD_FMT_MAD_BLK_66          66  /*!< MAD block number 66 (only used for Mifare 4k card) */
88 
89 /*@}*/
90 
91 /*!
92 * \name Mifare standard - Update MAD block flag
93 *
94 */
95 /*@{*/
96 #define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_KEYA_ACS_BIT_1K        {0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0x78,0x77,0x88,0xC1}
97 #define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_KEYA_ACS_BIT_4K        {0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0x78,0x77,0x88,0xC2}
98 #define  PH_FRINFC_SMTCRDFMT_NFCFORUMSECT_KEYA_ACS_BIT           {0xD3,0xF7,0xD3,0xF7,0xD3,0xF7,0x7F,0x07,0x88,0x40}
99 
100 /*@}*/
101 /*!
102  * \name Mifare standard - Key and access bit constants
103  *
104  */
105 /*@{*/
106 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_KEYA0      0xD3    /*!< NFC forum sector key A */
107 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_KEYA1      0xF7    /*!< NFC forum sector key A */
108 
109 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA0      0xA0    /*!< MAD sector key A */
110 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA1      0xA1    /*!< MAD sector key A */
111 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA2      0xA2    /*!< MAD sector key A */
112 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA3      0xA3    /*!< MAD sector key A */
113 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA4      0xA4    /*!< MAD sector key A */
114 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_KEYA5      0xA5    /*!< MAD sector key A */
115 
116 #define PH_FRINFC_MFSTD_FMT_DEFAULT_KEY         0xFF    /*!< Default key A or B */
117 
118 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_ACS6       0x78    /*!< MAD sector access bits 6 */
119 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_ACS7       0x77    /*!< MAD sector access bits 7 */
120 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_ACS8       0x88    /*!< MAD sector access bits 8 */
121 #define PH_FRINFC_MFSTD_FMT_MAD_SECT_GPB        0xC1    /*!< MAD sector GPB */
122 
123 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RW6    0x7F    /*!< NFC forum sector access bits 6 for read write */
124 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RW7    0x07    /*!< NFC forum sector access bits 7 for read write */
125 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RW8    0x88    /*!< NFC forum sector access bits 8 for read write */
126 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_GPB_RW     0x40    /*!< NFC forum sector GPB for read write */
127 
128 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RO6    0x07    /*!< NFC forum sector access bits 6 for read only */
129 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RO7    0x8F    /*!< NFC forum sector access bits 7 for read only */
130 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_ACS_RO8    0x0F    /*!< NFC forum sector access bits 8 for read only */
131 #define PH_FRINFC_MFSTD_FMT_NFC_SECT_GPB_R0     0x43    /*!< NFC forum sector GPB for read only */
132 
133 /*@}*/
134 
135 /*!
136  * \name Mifare standard - enums the values
137  *
138  */
139 /*@{*/
140 typedef enum{
141 PH_FRINFC_MFSTD_FMT_VAL_0,
142 PH_FRINFC_MFSTD_FMT_VAL_1,
143 PH_FRINFC_MFSTD_FMT_VAL_2,
144 PH_FRINFC_MFSTD_FMT_VAL_3,
145 PH_FRINFC_MFSTD_FMT_VAL_4,
146 PH_FRINFC_MFSTD_FMT_VAL_5,
147 PH_FRINFC_MFSTD_FMT_VAL_6,
148 PH_FRINFC_MFSTD_FMT_VAL_7,
149 PH_FRINFC_MFSTD_FMT_VAL_8,
150 PH_FRINFC_MFSTD_FMT_VAL_9,
151 PH_FRINFC_MFSTD_FMT_VAL_10,
152 PH_FRINFC_MFSTD_FMT_VAL_11
153 }phFriNfc_MfStdVal;
154 /*@}*/
155 
156 /*!
157  * \name Mifare standard - NDEF information constants
158  *
159  */
160 /*@{*/
161 #define PH_FRINFC_MFSTD_FMT_NON_NDEF_COMPL  0       /*!< Sector is not ndef compliant */
162 #define PH_FRINFC_MFSTD_FMT_NDEF_COMPL      1       /*!< Sector is ndef compliant */
163 #define PH_FRINFC_MFSTD_FMT_NDEF_INFO1      0x03    /*!< If sector is ndef compliant, then one of the MAD
164                                                         sector byte is 0x03 */
165 #define PH_FRINFC_MFSTD_FMT_NDEF_INFO2      0xE1    /*!< If sector is ndef compliant, then one of the MAD
166                                                         sector byte is 0xE1 */
167 /*@}*/
168 
169 /*!
170  * \name Mifare standard - constants
171  *
172  */
173 /*@{*/
174 #define PH_FRINFC_MFSTD_FMT_MAX_RECV_LENGTH     252 /*!< Maximum receive length */
175 #define PH_FRINFC_MFSTD_FMT_WR_SEND_LENGTH      17  /*!< Send length for write */
176 #define PH_FRINFC_MFSTD_FMT_MAX_SECT_IND_1K     16  /*!< Maximum sector index for Mifare 1k = 16 */
177 #define PH_FRINFC_MFSTD_FMT_MAX_SECT_IND_4K     40  /*!< Maximum sector index for Mifare 4k = 40 */
178 #define PH_FRINFC_MFSTD_FMT_MAX_BLOCKS_1K       64  /*!< Maximum sector index for Mifare 1k = 16 */
179 #define PH_FRINFC_MFSTD_FMT_MAX_BLOCKS_4K       256 /*!< Maximum sector index for Mifare 4k = 40 */
180 /*@}*/
181 
182 /*!
183  * \name Mifare standard - constants for filling send buffer, calculating the block number,
184  * checking the authenticate state
185  *
186  */
187 /*@{*/
188 /* Copy default keyA to send buffer */
189 #ifdef PH_HAL4_ENABLE
190 
191 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_DEF(mem)\
192 do \
193 {\
194     (void)memset(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
195                 PH_FRINFC_MFSTD_FMT_DEFAULT_KEY,\
196                 PH_FRINFC_MFSTD_FMT_VAL_6);\
197     NdefSmtCrdFmt->Cmd.MfCmd = ((NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState == \
198             PH_FRINFC_MFSTD_FMT_AUTH_DEF_KEY)? \
199             phHal_eMifareAuthentA: \
200             phHal_eMifareAuthentB); \
201     NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7; \
202 }while(0)
203 
204 /* Copy NFC forum sector keyA to send buffer */
205 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_NFCSECT_KEYA(mem)\
206 do \
207 {\
208     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
209         NdefSmtCrdFmt->AddInfo.MfStdInfo.NFCForumSect_KeyA,\
210         PH_FRINFC_MFSTD_FMT_VAL_6);\
211         NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareAuthentA;\
212         NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
213 } while(0)
214 
215 /* Copy MAD sector keyA to send buffer */
216 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_MADSECT_KEYA(mem)\
217 do \
218 {\
219     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
220         NdefSmtCrdFmt->AddInfo.MfStdInfo.MADSect_KeyA,\
221         PH_FRINFC_MFSTD_FMT_VAL_6);\
222         NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareAuthentA;\
223         NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
224 } while(0)
225 
226 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_SCRT_KEY(mem) \
227 do \
228 {\
229     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
230                NdefSmtCrdFmt->AddInfo.MfStdInfo.ScrtKeyB,\
231                PH_FRINFC_MFSTD_FMT_VAL_6);\
232                NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareAuthentB;\
233                NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
234 } while(0)
235 
236 #else
237 
238 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_DEF(mem)\
239 do \
240 {\
241     (void)memset(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
242                 PH_FRINFC_MFSTD_FMT_DEFAULT_KEY,\
243                 PH_FRINFC_MFSTD_FMT_VAL_6);\
244     NdefSmtCrdFmt->Cmd.MfCmd = ((NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState == \
245             PH_FRINFC_MFSTD_FMT_AUTH_DEF_KEY)? \
246             phHal_eMifareCmdListMifareAuthentA: \
247             phHal_eMifareCmdListMifareAuthentB); \
248     NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7; \
249 }while(0)
250 
251 /* Copy NFC forum sector keyA to send buffer */
252 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_NFCSECT_KEYA(mem)\
253 do \
254 {\
255     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
256         NdefSmtCrdFmt->AddInfo.MfStdInfo.NFCForumSect_KeyA,\
257         PH_FRINFC_MFSTD_FMT_VAL_6);\
258         NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareCmdListMifareAuthentA;\
259         NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
260 } while(0)
261 
262 /* Copy MAD sector keyA to send buffer */
263 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_MADSECT_KEYA(mem)\
264 do \
265 {\
266     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
267         NdefSmtCrdFmt->AddInfo.MfStdInfo.MADSect_KeyA,\
268         PH_FRINFC_MFSTD_FMT_VAL_6);\
269         NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareCmdListMifareAuthentA;\
270         NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
271 } while(0)
272 
273 #define PH_FRINFC_MFSTD_FMT_AUTH_SEND_BUF_SCRT_KEY(mem) \
274 do \
275 {\
276     (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[PH_FRINFC_MFSTD_FMT_VAL_1],\
277                NdefSmtCrdFmt->AddInfo.MfStdInfo.ScrtKeyB,\
278                PH_FRINFC_MFSTD_FMT_VAL_6);\
279                NdefSmtCrdFmt->Cmd.MfCmd = phHal_eMifareCmdListMifareAuthentB;\
280                NdefSmtCrdFmt->SendLength = PH_FRINFC_MFSTD_FMT_VAL_7;\
281 } while(0)
282 
283 #endif /* #ifdef PH_HAL4_ENABLE */
284 
285 
286 /* Get the next block */
287 #define PH_FRINFC_MFSTD_FMT_CUR_BLK_INC() \
288                     NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock += \
289                         ((NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock >= 127)?\
290                         16:4)
291 
292 /* Get the sector index */
293 #define PH_FRINFC_MFSTD_FMT_SECT_INDEX_CALC \
294                     ((NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock >= 128)?\
295                     (32 + ((NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock - 128)/16)):\
296                     (NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock/4))
297 
298 #define PH_FRINFC_MFSTD_FMT_CUR_BLK_CHK\
299                     ((NdefSmtCrdFmt->CardType == PH_FRINFC_SMTCRDFMT_MFSTD_1K_CRD) && \
300                     (NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock >= \
301                     PH_FRINFC_MFSTD_FMT_MAX_BLOCKS_1K)) || \
302                     ((NdefSmtCrdFmt->CardType == PH_FRINFC_SMTCRDFMT_MFSTD_4K_CRD) && \
303                     (NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock >= \
304                     PH_FRINFC_MFSTD_FMT_MAX_BLOCKS_4K))
305 
306 /* Get the next authenticate state */
307 #define PH_FRINFC_MFSTD_FMT_NXT_AUTH_STATE() \
308 do \
309 {\
310     switch(NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState)\
311     {\
312         case PH_FRINFC_MFSTD_FMT_AUTH_DEF_KEY:\
313         {\
314             NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = (uint8_t) \
315                 ((((NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock <= 3) || \
316                 ((NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock > 63) && \
317                 (NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock < 67))))? \
318                 PH_FRINFC_MFSTD_FMT_AUTH_MAD_KEY: \
319                 PH_FRINFC_MFSTD_FMT_AUTH_NFC_KEY);\
320         }\
321         break;\
322         case PH_FRINFC_MFSTD_FMT_AUTH_NFC_KEY:\
323         {\
324         NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = \
325                             PH_FRINFC_MFSTD_FMT_AUTH_KEYB;\
326         }\
327         break;\
328         case PH_FRINFC_MFSTD_FMT_AUTH_MAD_KEY:\
329         {\
330         NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = \
331                         PH_FRINFC_MFSTD_FMT_AUTH_NFC_KEY;\
332         }\
333         break;\
334         case PH_FRINFC_MFSTD_FMT_AUTH_KEYB:\
335         { \
336         NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = \
337                         PH_FRINFC_MFSTD_FMT_AUTH_SCRT_KEYB;\
338         } \
339         break;\
340         case PH_FRINFC_MFSTD_FMT_AUTH_SCRT_KEYB:\
341         default:\
342         { \
343         NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = \
344                         PH_FRINFC_MFSTD_FMT_AUTH_DEF_KEY;\
345         }\
346         break;\
347     }\
348 } while(0)
349 
350 
351 /* Increment the sector index */
352 #define PH_FRINFC_MFSTD_FMT_INCR_SECT \
353 do \
354 {\
355     SectIndex++;\
356     SectIndex = (uint8_t)((SectIndex == 16)?\
357                         (SectIndex + PH_FRINFC_MFSTD_FMT_VAL_1):\
358                         SectIndex);\
359 } while(0)
360 
361 
362 /* Increment the sector index */
363 #define PH_FRINFC_MFSTD_FMT_CHK_SECT_ARRAY \
364 do \
365 {\
366     while ((index < PH_FRINFC_MFSTD_FMT_MAX_SECT_IND_4K) && \
367             (memcompare != PH_FRINFC_MFSTD_FMT_VAL_0))\
368     {\
369         /* Compare any one among the sectors is NDEF COMPLIANT */\
370         memcompare = (uint32_t)phFriNfc_MfStd_MemCompare(&Buffer[PH_FRINFC_MFSTD_FMT_VAL_0], \
371         &NdefSmtCrdFmt->AddInfo.MfStdInfo.SectCompl[index],\
372         PH_FRINFC_MFSTD_FMT_VAL_1);\
373         /* increment the index */\
374         index += (uint8_t)((index == (PH_FRINFC_MFSTD_FMT_MAX_SECT_IND_1K - \
375                             PH_FRINFC_MFSTD_FMT_VAL_1))?\
376                             PH_FRINFC_MFSTD_FMT_VAL_2:\
377                             PH_FRINFC_MFSTD_FMT_VAL_1);\
378     }\
379 } while(0)
380 
381 #define PH_FRINFC_MFSTD_FMT_CHK_END_OF_CARD() \
382 do \
383 { \
384     phFriNfc_MfStd_H_NdefComplSect(NdefSmtCrdFmt->CardType, \
385                                 NdefSmtCrdFmt->AddInfo.MfStdInfo.SectCompl); \
386     PH_FRINFC_MFSTD_FMT_CHK_SECT_ARRAY; \
387     if(memcompare == PH_FRINFC_MFSTD_FMT_VAL_0) \
388     { \
389         phFriNfc_MfStd_H_StrNdefData(NdefSmtCrdFmt); \
390         NdefSmtCrdFmt->AddInfo.MfStdInfo.CurrentBlock = \
391                                 PH_FRINFC_MFSTD_FMT_VAL_1; \
392         NdefSmtCrdFmt->AddInfo.MfStdInfo.UpdMADBlk = \
393             PH_FRINFC_MFSTD_FMT_MAD_BLK_1; \
394         NdefSmtCrdFmt->AddInfo.MfStdInfo.AuthState = \
395             PH_FRINFC_MFSTD_FMT_AUTH_SCRT_KEYB; \
396         NdefSmtCrdFmt->State = PH_FRINFC_MFSTD_FMT_AUTH_SECT; \
397         Result = phFriNfc_MfStd_H_WrRdAuth(NdefSmtCrdFmt); \
398     } \
399     else \
400     { \
401         Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, \
402                             NFCSTATUS_FORMAT_ERROR); \
403     } \
404 } while(0)
405 /*@}*/
406 
407 
408 /**
409  * \ingroup grp_fri_smart_card_formatting
410  * \brief Smart Card Formatting \b Reset function
411  *
412  * \copydoc page_reg Resets the component instance to the initial state and initializes the
413  *          internal variables.
414  */
415 void phFriNfc_MfStd_Reset(phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);
416 
417 /*!
418  * \ingroup grp_fri_smart_card_formatting
419  *
420  * \brief Initiates the card formatting procedure for Remote Smart Card Type.
421  *
422  * \copydoc page_ovr  The function initiates and formats the Smart Card.After this formation, remote
423  * card would be properly initialized and Ndef Compliant.
424  * Depending upon the different card type, this function handles formatting procedure.
425  * This function also handles the different recovery procedures for different types of the cards. For both
426  * Format and Recovery Management same API is used.
427  *
428  * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
429  *                             structure describing the component context.
430  * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
431  * \retval  Other values        An error has occurred.
432  *
433  */
434 NFCSTATUS phFriNfc_MfStd_Format(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, const uint8_t *ScrtKeyB);
435 
436 /**
437  *\ingroup grp_fri_smart_card_formatting
438  *
439  * \brief Smart card Formatting \b Completion \b Routine or \b Process function
440  *
441  * \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
442  *                  when an I/O operation has finished. The internal state machine decides
443  *                  whether to call into the lower device again or to complete the process
444  *                  by calling into the upper layer's completion routine, stored within this
445  *                  component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
446  *
447  * The function call scheme is according to \ref grp_interact. No State reset is performed during
448  * operation.
449  *
450  * \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
451  *            calling layer, upon its completion.
452  * \param[in] Status  The completion status of the lower layer (to be handled by the implementation of
453  *                    the state machine of this function like a regular return value of an internally
454  *                    called function).
455  *
456  * \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
457  *
458  */
459 void phFriNfc_MfStd_Process(void            *Context,
460                             NFCSTATUS       Status);
461 #endif /* PHFRINFC_MIFSTDFMT_H */
462