phFriNfc_MifULFormat.h revision c0bdf30e40dd60628bfafd5f93a3a911e3b91da9
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_MifULFormat.h
19 * \brief NFC Ndef Formatting For Mifare standard card.
20 *
21 * Project: NFC-FRI
22 *
23 * $Date: Mon Dec 13 14:14:12 2010 $
24 * $Author: ing02260 $
25 * $Revision: 1.5 $
26 * $Aliases:  $
27 *
28 */
29
30#ifndef PHFRINFC_MIFULFORMAT_H
31#define PHFRINFC_MIFULFORMAT_H
32
33#include <phFriNfc.h>
34#ifdef PH_HAL4_ENABLE
35    #include <phHal4Nfc.h>
36#else
37    #include <phHalNfc.h>
38#endif
39#include <phNfcStatus.h>
40#include <phNfcTypes.h>
41#include <phFriNfc_SmtCrdFmt.h>
42
43#ifdef PH_NDEF_MIFARE_ULC
44#include <phFriNfc_NdefMap.h>
45#endif /* #ifdef PH_NDEF_MIFARE_ULC */
46
47#define PH_FRINFC_MIFUL_FORMAT_FILEREVISION "$Revision: 1.5 $"
48#define PH_FRINFC_MIFUL_FORMAT_FILEALIASES  "$Aliases:  $"
49
50
51/*!
52 * \name Mifare UL - constants for the state
53 *
54 */
55/*@{*/
56#define PH_FRINFC_MFUL_FMT_RESET_INIT          0 /*!< Reset state */
57#define PH_FRINFC_MFUL_FMT_RD_16BYTES          1 /*!< Read 16 bytes */
58#define PH_FRINFC_MFUL_FMT_WR_OTPBYTES         2 /*!< Write OTP bytes */
59#define PH_FRINFC_MFUL_FMT_WR_TLV              3 /*!< Write TLV */
60#ifdef PH_NDEF_MIFARE_ULC
61#define PH_FRINFC_MFUL_FMT_WR_TLV1             4 /*!< Write TLV (second part) */
62#endif  /* #ifdef PH_NDEF_MIFARE_ULC */
63#ifdef FRINFC_READONLY_NDEF
64#define PH_FRINFC_MFUL_FMT_RO_RD_16BYTES       5 /*!< Read only the tag */
65#define PH_FRINFC_MFUL_FMT_RO_WR_LOCK_BYTES    6 /*!< Write lock bytes to make the tag Read only */
66#define PH_FRINFC_MFUL_FMT_RO_WR_OTP_BYTES     7 /*!< Write OTP bytes to make the tag Read only */
67#endif /* #ifdef FRINFC_READONLY_NDEF */
68
69/*@}*/
70
71
72/*!
73* \name Mifare standard - Block numbers
74*
75*/
76/*@{*/
77#define PH_FRINFC_MFUL_FMT_LOCK_BITS_VAL       0x00   /*!< Lock bits block is 2 */
78
79/*@}*/
80
81/*!
82 * \name Mifare UL - OTP bytes
83 *
84 */
85/*@{*/
86#ifdef PH_NDEF_MIFARE_ULC
87#define PH_FRINFC_MFULC_FMT_OTP_BYTES           {0xE1, 0x10, 0x12, 0x00}   /*!< OTP bytes macro */
88#endif /* #ifdef PH_NDEF_MIFARE_ULC */
89#define PH_FRINFC_MFUL_FMT_OTP_BYTES           {0xE1, 0x10, 0x06, 0x00}   /*!< OTP bytes macro */
90
91/*@}*/
92
93/*!
94 * \name Mifare UL - enums the values
95 *
96 */
97/*@{*/
98enum{
99PH_FRINFC_MFUL_FMT_VAL_0,
100PH_FRINFC_MFUL_FMT_VAL_1,
101PH_FRINFC_MFUL_FMT_VAL_2,
102PH_FRINFC_MFUL_FMT_VAL_3,
103PH_FRINFC_MFUL_FMT_VAL_4,
104PH_FRINFC_MFUL_FMT_VAL_5,
105PH_FRINFC_MFUL_FMT_VAL_6,
106PH_FRINFC_MFUL_FMT_VAL_7
107};
108/*@}*/
109
110/*!
111 * \name Mifare UL - constants
112 *
113 */
114/*@{*/
115#define PH_FRINFC_MFUL_FMT_NON_NDEF_COMPL  0   /*!< Card is not ndef compliant */
116#define PH_FRINFC_MFUL_FMT_NDEF_COMPL      1   /*!< Card is ndef compliant */
117/*@}*/
118
119/*!
120 * \name Mifare UL - constants
121 *
122 */
123/*@{*/
124#define PH_FRINFC_MFUL_FMT_MAX_RECV_LENGTH      252 /*!< Maximum receive length */
125#define PH_FRINFC_MFUL_FMT_WR_SEND_LENGTH       5  /*!< Send length for write */
126#define PH_FRINFC_MFUL_FMT_MAX_BLK              16  /*!< Maximum blocks */
127
128/*@}*/
129
130/*!
131 * \name Mifare UL - constants for filling send buffer, calculating the block number,
132 * checking the authenticate state
133 *
134 */
135/*@{*/
136
137/*@}*/
138
139
140/**
141 * \ingroup grp_fri_smart_card_formatting
142 * \brief Smart Card Formatting \b Reset function
143 *
144 * \copydoc page_reg Resets the component instance to the initial state and initializes the
145 *          internal variables.
146 */
147void phFriNfc_MfUL_Reset(phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);
148
149/*!
150 * \ingroup grp_fri_smart_card_formatting
151 *
152 * \brief Initiates the card formatting procedure for Remote Smart Card Type.
153 *
154 * \copydoc page_ovr  The function initiates and formats the Smart Card.After this formation, remote
155 * card would be properly initialized and Ndef Compliant.
156 * Depending upon the different card type, this function handles formatting procedure.
157 * This function also handles the different recovery procedures for different types of the cards. For both
158 * Format and Recovery Management same API is used.
159 *
160 * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
161 *                             structure describing the component context.
162 * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
163 * \retval  Other values        An error has occurred.
164 *
165 */
166NFCSTATUS phFriNfc_MfUL_Format(phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);
167
168#ifdef FRINFC_READONLY_NDEF
169
170/*!
171 * \ingroup grp_fri_smart_card_formatting
172 *
173 * \brief Initiates the conversion of the already NDEF formatted tag to READ ONLY.
174 *
175 * \copydoc page_ovr  The function initiates the conversion of the already NDEF formatted
176 * tag to READ ONLY.After this formation, remote card would be properly Ndef Compliant and READ ONLY.
177 * Depending upon the different card type, this function handles formatting procedure.
178 *
179 * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
180 *                             structure describing the component context.
181 * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
182 * \retval  Other values        An error has occurred.
183 *
184 */
185NFCSTATUS
186phFriNfc_MfUL_ConvertToReadOnly (
187    phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);
188
189#endif /* #ifdef FRINFC_READONLY_NDEF */
190
191/**
192 *\ingroup grp_fri_smart_card_formatting
193 *
194 * \brief Smart card Formatting \b Completion \b Routine or \b Process function
195 *
196 * \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
197 *                  when an I/O operation has finished. The internal state machine decides
198 *                  whether to call into the lower device again or to complete the process
199 *                  by calling into the upper layer's completion routine, stored within this
200 *                  component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
201 *
202 * The function call scheme is according to \ref grp_interact. No State reset is performed during
203 * operation.
204 *
205 * \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
206 *            calling layer, upon its completion.
207 * \param[in] Status  The completion status of the lower layer (to be handled by the implementation of
208 *                    the state machine of this function like a regular return value of an internally
209 *                    called function).
210 *
211 * \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
212 *
213 */
214void phFriNfc_MfUL_Process(void            *Context,
215                            NFCSTATUS       Status);
216#endif /* PHFRINFC_MIFULFORMAT_H */
217
218