summaryrefslogtreecommitdiffstats
path: root/src/phFriNfc_DesfireFormat.h
blob: 2a7fc83e1f3e4d4ed2373030312750ca25ed8686 (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), NXP Semiconductors
*
*                       (C)NXP N.V.2007
*         All rights are reserved. Reproduction in whole or in part is
*        prohibited without the written consent of the copyright owner.
*    NXP reserves the right to make changes without notice at any time.
*   NXP makes no warranty, expressed, implied or statutory, including but
*   not limited to any implied warranty of merchantability or fitness for any
*  particular purpose, or that the use will not infringe any third party patent,
*   copyright or trademark. NXP must not be liable for any loss or damage
*                            arising from its use.
*
*/

/*!
* \file  phFriNfc_DesfireFormat.h
* \brief Type4 Smart card formatting.
*
* Project: NFC-FRI
*
* $Date: Tue Jul 27 08:59:52 2010 $
* $Author: ing02260 $
* $Revision: 1.3 $
* $Aliases:  $
*
*/

#ifndef PHFRINFC_DESFIREFORMAT_H
#define PHFRINFC_DESFIREFORMAT_H


/*! \ingroup grp_file_attributes
*  \name NDEF Smart Card Foramting
*
* File: \ref phFriNfc_DesfireFormat.h
*
*/
/*@{*/

/*@}*/


/* Enum to represent the state variables*/
enum{

    PH_FRINFC_DESF_STATE_CREATE_AID = 0, 
    PH_FRINFC_DESF_STATE_SELECT_APP = 1,
    PH_FRINFC_DESF_STATE_CREATE_CCFILE = 2,
    PH_FRINFC_DESF_STATE_CREATE_NDEFFILE = 3,
    PH_FRINFC_DESF_STATE_WRITE_CC_FILE = 4,
    PH_FRINFC_DESF_STATE_WRITE_NDEF_FILE = 5,
    PH_FRINFC_DESF_STATE_DISCON = 6,
    PH_FRINFC_DESF_STATE_CON = 7,
    PH_FRINFC_DESF_STATE_POLL = 8,
    PH_FRINFC_DESF_STATE_GET_UID = 9,
    PH_FRINFC_DESF_STATE_GET_SW_VERSION = 10,
    PH_FRINFC_DESF_STATE_GET_HW_VERSION = 11,

    /* following are used in the ISO wrapper commands*/
    PH_FRINFC_DESF_CREATEAPP_CMD = 0,
    PH_FRINFC_DESF_SELECTAPP_CMD = 1,
    PH_FRINFC_DESF_CREATECC_CMD = 2,
    PH_FRINFC_DESF_CREATENDEF_CMD = 3,
    PH_FRINFC_DESF_WRITECC_CMD = 4,
    PH_FRINFC_DESF_WRITENDEF_CMD = 5,
    PH_FRINFC_DESF_GET_HW_VERSION_CMD = 6,
    PH_FRINFC_DESF_GET_SW_VERSION_CMD = 7,
    PH_FRINFC_DESF_GET_UID_CMD = 8,
    PH_FRINFC_DESF_WRITENDEF_CMD_SNLEN = 15,
    PH_FRINFC_DESF_WRITECC_CMD_SNLEN = 28,
    PH_FRINFC_DESF_CREATECCNDEF_CMD_SNLEN = 13,
    PH_FRINFC_DESF_SELECTAPP_CMD_SNLEN = 9,
    PH_FRINFC_DESF_CREATEAPP_CMD_SNLEN = 11,
    PH_FRINFC_DESF_NATIVE_OFFSET_P1 = 0x00,
    PH_FRINFC_DESF_NATIVE_OFFSET_P2 = 0x00,
    PH_FRINFC_DESF_NATIVE_LE_BYTE = 0x00,
    PH_FRINFC_DESF_NATIVE_CRAPP_WRDT_LEN = 5,
    PH_FRINFC_DESF_NATIVE_SLAPP_WRDT_LEN = 3,
    PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN = 7,
    PH_FRINFC_DESF_NATIVE_WRCC_WRDT_LEN = 22,
    PH_FRINFC_DESF_NATIVE_WRNDEF_WRDT_LEN = 9

};


/* CC File contents*/

#define  PH_FRINFC_DESF_CCFILE_BYTES                    {0x00,0x0f,0x10,0x00,0x3B,0x00,0x34,0x04,0x06,0xE1,0x04,0x04,0x00,0x00,0x00 }
#define  PH_FRINFC_DESF_NDEFFILE_BYTES                  {0x00,0x00}
#define  PH_FRINFC_DESF_PICC_MASTER_KEY                 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
#define  PH_FRINFC_DESF_NFCFORUM_APP_KEY                {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
#define  PH_FRINFC_DESF_COMM_SETTINGS                   0x00
#define  PH_FRINFC_DESF_CREATE_DATA_FILE_CMD            0xCD
#define  PH_FRINFC_DESF_NATIVE_CLASS_BYTE               0x90

/* Constant defined to specify the NFC Forum Application ID : 0xEEEE10*/
/* This is defined in order to support to N/W Byte order style : LSB : : MSB*/
#define PH_FRINFC_DESF_FIRST_AID_BYTE                   0x10
#define PH_FRINFC_DESF_SEC_AID_BYTE                     0xEE
#define PH_FRINFC_DESF_THIRD_AID_BYTE                   0xEE


/* Create File command constants*/
#define  PH_FRINFC_DESF_CREATE_AID_CMD                  0xCA
   
/* Specifies the NFC Forum App Number of Keys*/
#define  PH_FRINFC_DESF_NFCFORUM_APP_NO_OF_KEYS         0x01

#define  PH_FRINFC_DESF_SLECT_APP_CMD                   0x5A

#define  PH_FRINFC_DESF_GET_VER_CMD                     0x60


#define  PH_FRINFC_DESF_NATIVE_RESP_BYTE1               0x91 
#define  PH_FRINFC_DESF_NATIVE_RESP_BYTE2               0x00

/* Create CC File Commands*/
#define  PH_FRINFC_DESF_CC_FILE_ID                      0x03 
#define  PH_FRINFC_DESF_CC_FILE_SIZE                    0x0F
#define  PH_FRINFC_DESF_FIRST_BYTE_CC_ACCESS_RIGHTS     0x00
#define  PH_FRINFC_DESF_SEC_BYTE_CC_ACCESS_RIGHTS       0xE0


/* Create NDEF File Commands*/
#define  PH_FRINFC_DESF_NDEF_FILE_ID                    0x04
#define  PH_FRINFC_DESF_NDEF_FILE_SIZE                  0x04
#define  PH_FRINFC_DESF_FIRST_BYTE_NDEF_ACCESS_RIGHTS   0xE0
#define  PH_FRINFC_DESF_SEC_BYTE_NDEF_ACCESS_RIGHTS     0xEE


/* Write/Read Data commands/constants*/
#define  PH_FRINFC_DESF_WRITE_CMD                       0x3D

/* PICC additional frame response*/
#define  PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP            0xAF

/* Response for PICC native DESFire wrapper cmd*/
#define  PH_FRINFC_DESF_NAT_WRAP_FIRST_RESP_BYTE        0x91
#define  PH_FRINFC_DESF_NAT_WRAP_SEC_RESP_BYTE          0x00

/* DESFire4 Major/Minor versions*/
#define  PH_FRINFC_DESF4_MAJOR_VERSION                  0x00
#define  PH_FRINFC_DESF4_MINOR_VERSION                  0x06

/* DESFire4 memory size*/
#define  PH_FRINFC_DESF4_MEMORY_SIZE                    0xEDE

enum{
    PH_SMTCRDFMT_DESF_VAL0 = 0,
    PH_SMTCRDFMT_DESF_VAL1 = 1,
    PH_SMTCRDFMT_DESF_VAL2 = 2,
    PH_SMTCRDFMT_DESF_VAL3 = 3,
    PH_SMTCRDFMT_DESF_VAL4 = 4,
    PH_SMTCRDFMT_DESF_VAL14 = 14,
    PH_SMTCRDFMT_DESF_VAL15 = 15
};



/*!
* \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about
*        the list of registered items. Moreover, the lower device is set.
*
* \param[in] NdefSmtCrdFmt Pointer to a valid or uninitialized instance of \ref phFriNfc_sNdefSmtCrdFmt_t.
*
* \note  This function has to be called at the beginning, after creating an instance of
*        \ref phFriNfc_sNdefSmtCrdFmt_t. Use this function to reset the instance of smart card
formatting context variables.
*/
void phFriNfc_Desfire_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 DESFire Card.After this 
*                   operation,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_SUCCESS                  Card formatting has been successfully completed.
* \retval NFCSTATUS_PENDING                  The action has been successfully triggered.
* \retval NFCSTATUS_FORMAT_ERROR             Error occured during the formatting procedure.
* \retval NFCSTATUS_INVALID_REMOTE_DEVICE    Card Type is unsupported.
* \retval NFCSTATUS_INVALID_DEVICE_REQUEST   Command or Operation types are mismatching.
*
*/
NFCSTATUS phFriNfc_Desfire_Format(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);

/**
*\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_Desf_Process(void        *Context,
                           NFCSTATUS   Status);


#endif