summaryrefslogtreecommitdiffstats
path: root/src/phFriNfc_MifULFormat.h
blob: 523801436496421a56c44fbced9bfbcbd987e14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * Copyright (C) 2010 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * \file  phFriNfc_MifULFormat.h
 * \brief NFC Ndef Formatting For Mifare standard card.
 *
 * Project: NFC-FRI
 *
 * $Date: Mon Dec 13 14:14:12 2010 $
 * $Author: ing02260 $
 * $Revision: 1.5 $
 * $Aliases:  $
 *
 */

#ifndef PHFRINFC_MIFULFORMAT_H
#define PHFRINFC_MIFULFORMAT_H

#include <phFriNfc.h>
#ifdef PH_HAL4_ENABLE
    #include <phHal4Nfc.h>
#else
    #include <phHalNfc.h>
#endif
#include <phNfcStatus.h>
#include <phNfcTypes.h>
#include <phFriNfc_SmtCrdFmt.h>

#ifdef PH_NDEF_MIFARE_ULC
#include <phFriNfc_NdefMap.h>
#endif /* #ifdef PH_NDEF_MIFARE_ULC */

#define PH_FRINFC_MIFUL_FORMAT_FILEREVISION "$Revision: 1.5 $"
#define PH_FRINFC_MIFUL_FORMAT_FILEALIASES  "$Aliases:  $"


/*!
 * \name Mifare UL - constants for the state
 *
 */
/*@{*/
#define PH_FRINFC_MFUL_FMT_RESET_INIT               0 /*!< Reset state */
#define PH_FRINFC_MFUL_FMT_RD_16BYTES               1 /*!< Read 16 bytes */
#define PH_FRINFC_MFUL_FMT_WR_OTPBYTES              2 /*!< Write OTP bytes */
#define PH_FRINFC_MFUL_FMT_WR_TLV                   3 /*!< Write TLV */  
#ifdef PH_NDEF_MIFARE_ULC
#define PH_FRINFC_MFUL_FMT_WR_TLV1                  4 /*!< Write TLV (second part) */ 
#endif  /* #ifdef PH_NDEF_MIFARE_ULC */
#ifdef FRINFC_READONLY_NDEF
#define PH_FRINFC_MFUL_FMT_RO_RD_16BYTES            5 /*!< Read only the tag */
#define PH_FRINFC_MFUL_FMT_RO_WR_LOCK_BYTES         6 /*!< Write lock bytes to make the tag Read only */
#define PH_FRINFC_MFUL_FMT_RO_WR_OTP_BYTES          7 /*!< Write OTP bytes to make the tag Read only */

#ifdef PH_NDEF_MIFARE_ULC
#define PH_FRINFC_MFUL_FMT_RO_RD_DYN_LOCK_BYTES     8 /*!< Read default dynamic lock bytes address */
#define PH_FRINFC_MFUL_FMT_RO_WR_DYN_LOCK_BYTES     9 /*!< Write default dynamic lock bytes address */
#define PH_FRINFC_MFUL_FMT_RO_PARSE_NDEF            10 /*!< Write default dynamic lock bytes address */
#define PH_FRINFC_MFUL_FMT_RO_NDEF_PARSE_RD_BYTES   12 /*!< Read bytes from the card for parsing NDEF */
#endif /* #ifdef PH_NDEF_MIFARE_ULC */

#endif /* #ifdef FRINFC_READONLY_NDEF */

/*@}*/


/*!
* \name Mifare standard - Block numbers
*
*/
/*@{*/
#define PH_FRINFC_MFUL_FMT_LOCK_BITS_VAL       0x00   /*!< Lock bits block is 2 */

/*@}*/

/*!
 * \name Mifare UL - OTP bytes
 *
 */
/*@{*/
#ifdef PH_NDEF_MIFARE_ULC
#define PH_FRINFC_MFULC_FMT_OTP_BYTES           {0xE1, 0x10, 0x12, 0x00}   /*!< OTP bytes macro */
#endif /* #ifdef PH_NDEF_MIFARE_ULC */
#define PH_FRINFC_MFUL_FMT_OTP_BYTES           {0xE1, 0x10, 0x06, 0x00}   /*!< OTP bytes macro */

/*@}*/

/*!
 * \name Mifare UL - enums the values 
 *
 */
/*@{*/
enum{
PH_FRINFC_MFUL_FMT_VAL_0, 
PH_FRINFC_MFUL_FMT_VAL_1,
PH_FRINFC_MFUL_FMT_VAL_2,
PH_FRINFC_MFUL_FMT_VAL_3,
PH_FRINFC_MFUL_FMT_VAL_4,
PH_FRINFC_MFUL_FMT_VAL_5,
PH_FRINFC_MFUL_FMT_VAL_6,
PH_FRINFC_MFUL_FMT_VAL_7
};
/*@}*/

/*!
 * \name Mifare UL - constants
 *
 */
/*@{*/
#define PH_FRINFC_MFUL_FMT_NON_NDEF_COMPL  0   /*!< Card is not ndef compliant */
#define PH_FRINFC_MFUL_FMT_NDEF_COMPL      1   /*!< Card is ndef compliant */
/*@}*/

/*!
 * \name Mifare UL - constants
 *
 */
/*@{*/
#define PH_FRINFC_MFUL_FMT_MAX_RECV_LENGTH      252 /*!< Maximum receive length */
#define PH_FRINFC_MFUL_FMT_WR_SEND_LENGTH       5  /*!< Send length for write */
#define PH_FRINFC_MFUL_FMT_MAX_BLK              16  /*!< Maximum blocks */

/*@}*/

/*!
 * \name Mifare UL - constants for filling send buffer, calculating the block number,
 * checking the authenticate state
 *
 */
/*@{*/

/*@}*/


/**
 * \ingroup grp_fri_smart_card_formatting
 * \brief Smart Card Formatting \b Reset function
 *
 * \copydoc page_reg Resets the component instance to the initial state and initializes the 
 *          internal variables.
 */
void phFriNfc_MfUL_Reset(phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);

/*!
 * \ingroup grp_fri_smart_card_formatting
 *
 * \brief Initiates the card formatting procedure for Remote Smart Card Type.
 *
 * \copydoc page_ovr  The function initiates and formats the Smart Card.After this formation, remote
 * card would be properly initialized and Ndef Compliant.
 * Depending upon the different card type, this function handles formatting procedure.
 * This function also handles the different recovery procedures for different types of the cards. For both
 * Format and Recovery Management same API is used.
 * 
 * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
 *                             structure describing the component context.
 * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
 * \retval  Other values        An error has occurred.
 *
 */
NFCSTATUS phFriNfc_MfUL_Format(phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);

#ifdef FRINFC_READONLY_NDEF

/*!
 * \ingroup grp_fri_smart_card_formatting
 *
 * \brief Initiates the conversion of the already NDEF formatted tag to READ ONLY.
 *
 * \copydoc page_ovr  The function initiates the conversion of the already NDEF formatted
 * tag to READ ONLY.After this formation, remote card would be properly Ndef Compliant and READ ONLY.
 * Depending upon the different card type, this function handles formatting procedure.
 *
 * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
 *                             structure describing the component context.
 * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
 * \retval  Other values        An error has occurred.
 *
 */
NFCSTATUS
phFriNfc_MfUL_ConvertToReadOnly (
    phFriNfc_sNdefSmtCrdFmt_t    *NdefSmtCrdFmt);

#endif /* #ifdef FRINFC_READONLY_NDEF */

/**
 *\ingroup grp_fri_smart_card_formatting
 *
 * \brief Smart card Formatting \b Completion \b Routine or \b Process function
 *
 * \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
 *                  when an I/O operation has finished. The internal state machine decides
 *                  whether to call into the lower device again or to complete the process
 *                  by calling into the upper layer's completion routine, stored within this
 *                  component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
 *
 * The function call scheme is according to \ref grp_interact. No State reset is performed during
 * operation.
 *
 * \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
 *            calling layer, upon its completion.
 * \param[in] Status  The completion status of the lower layer (to be handled by the implementation of
 *                    the state machine of this function like a regular return value of an internally
 *                    called function).
 *
 * \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
 *
 */
void phFriNfc_MfUL_Process(void            *Context,
                            NFCSTATUS       Status);
#endif /* PHFRINFC_MIFULFORMAT_H */