Home | History | Annotate | Download | only in src
      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_DesfireFormat.h
     19 * \brief Type4 Smart card formatting.
     20 *
     21 * Project: NFC-FRI
     22 *
     23 * $Date: Fri Jan 30 14:17:04 2009 $
     24 * $Author: ing07299 $
     25 * $Revision: 1.2 $
     26 * $Aliases: NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,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_DESFIREFORMAT_H
     31 #define PHFRINFC_DESFIREFORMAT_H
     32 
     33 
     34 /*! \ingroup grp_file_attributes
     35 *  \name NDEF Smart Card Foramting
     36 *
     37 * File: \ref phFriNfc_DesfireFormat.h
     38 *
     39 */
     40 /*@{*/
     41 
     42 /*@}*/
     43 
     44 
     45 /* Enum to represent the state variables*/
     46 enum{
     47 
     48     PH_FRINFC_DESF_STATE_CREATE_AID = 0,
     49     PH_FRINFC_DESF_STATE_SELECT_APP = 1,
     50     PH_FRINFC_DESF_STATE_CREATE_CCFILE = 2,
     51     PH_FRINFC_DESF_STATE_CREATE_NDEFFILE = 3,
     52     PH_FRINFC_DESF_STATE_WRITE_CC_FILE = 4,
     53     PH_FRINFC_DESF_STATE_WRITE_NDEF_FILE = 5,
     54     PH_FRINFC_DESF_STATE_DISCON = 6,
     55     PH_FRINFC_DESF_STATE_CON = 7,
     56     PH_FRINFC_DESF_STATE_POLL = 8,
     57     PH_FRINFC_DESF_STATE_GET_UID = 9,
     58     PH_FRINFC_DESF_STATE_GET_SW_VERSION = 10,
     59     PH_FRINFC_DESF_STATE_GET_HW_VERSION = 11,
     60 
     61     /* following are used in the ISO wrapper commands*/
     62     PH_FRINFC_DESF_CREATEAPP_CMD = 0,
     63     PH_FRINFC_DESF_SELECTAPP_CMD = 1,
     64     PH_FRINFC_DESF_CREATECC_CMD = 2,
     65     PH_FRINFC_DESF_CREATENDEF_CMD = 3,
     66     PH_FRINFC_DESF_WRITECC_CMD = 4,
     67     PH_FRINFC_DESF_WRITENDEF_CMD = 5,
     68     PH_FRINFC_DESF_GET_HW_VERSION_CMD = 6,
     69     PH_FRINFC_DESF_GET_SW_VERSION_CMD = 7,
     70     PH_FRINFC_DESF_GET_UID_CMD = 8,
     71     PH_FRINFC_DESF_WRITENDEF_CMD_SNLEN = 15,
     72     PH_FRINFC_DESF_WRITECC_CMD_SNLEN = 28,
     73     PH_FRINFC_DESF_CREATECCNDEF_CMD_SNLEN = 13,
     74     PH_FRINFC_DESF_SELECTAPP_CMD_SNLEN = 9,
     75     PH_FRINFC_DESF_CREATEAPP_CMD_SNLEN = 11,
     76     PH_FRINFC_DESF_NATIVE_OFFSET_P1 = 0x00,
     77     PH_FRINFC_DESF_NATIVE_OFFSET_P2 = 0x00,
     78     PH_FRINFC_DESF_NATIVE_LE_BYTE = 0x00,
     79     PH_FRINFC_DESF_NATIVE_CRAPP_WRDT_LEN = 5,
     80     PH_FRINFC_DESF_NATIVE_SLAPP_WRDT_LEN = 3,
     81     PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN = 7,
     82     PH_FRINFC_DESF_NATIVE_WRCC_WRDT_LEN = 22,
     83     PH_FRINFC_DESF_NATIVE_WRNDEF_WRDT_LEN = 9
     84 
     85 };
     86 
     87 
     88 /* CC File contents*/
     89 
     90 #define  PH_FRINFC_DESF_CCFILE_BYTES                    {0x00,0x0f,0x10,0x00,0x3B,0x00,0x34,0x04,0x06,0xE1,0x04,0x04,0x00,0x00,0x00 }
     91 #define  PH_FRINFC_DESF_NDEFFILE_BYTES                  {0x00,0x00}
     92 #define  PH_FRINFC_DESF_PICC_MASTER_KEY                 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
     93 #define  PH_FRINFC_DESF_NFCFORUM_APP_KEY                {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
     94 #define  PH_FRINFC_DESF_COMM_SETTINGS                   0x00
     95 #define  PH_FRINFC_DESF_CREATE_DATA_FILE_CMD            0xCD
     96 #define  PH_FRINFC_DESF_NATIVE_CLASS_BYTE               0x90
     97 
     98 /* Constant defined to specify the NFC Forum Application ID : 0xEEEE10*/
     99 /* This is defined in order to support to N/W Byte order style : LSB : : MSB*/
    100 #define PH_FRINFC_DESF_FIRST_AID_BYTE                   0x10
    101 #define PH_FRINFC_DESF_SEC_AID_BYTE                     0xEE
    102 #define PH_FRINFC_DESF_THIRD_AID_BYTE                   0xEE
    103 
    104 
    105 /* Create File command constants*/
    106 #define  PH_FRINFC_DESF_CREATE_AID_CMD                  0xCA
    107 /* This settings can be changed, depending on the requirement*/
    108 #define  PH_FRINFC_DESF_PICC_NFC_KEY_SETTING            0x0F
    109 /* Specifies the NFC Forum App Number of Keys*/
    110 #define  PH_FRINFC_DESF_NFCFORUM_APP_NO_OF_KEYS         0x01
    111 
    112 #define  PH_FRINFC_DESF_SLECT_APP_CMD                   0x5A
    113 
    114 #define  PH_FRINFC_DESF_GET_VER_CMD                     0x60
    115 
    116 
    117 #define  PH_FRINFC_DESF_NATIVE_RESP_BYTE1               0x91
    118 #define  PH_FRINFC_DESF_NATIVE_RESP_BYTE2               0x00
    119 
    120 /* Create CC File Commands*/
    121 #define  PH_FRINFC_DESF_CC_FILE_ID                      0x03
    122 #define  PH_FRINFC_DESF_CC_FILE_SIZE                    0x0F
    123 #define  PH_FRINFC_DESF_FIRST_BYTE_CC_ACCESS_RIGHTS     0x00
    124 #define  PH_FRINFC_DESF_SEC_BYTE_CC_ACCESS_RIGHTS       0xE0
    125 
    126 
    127 /* Create NDEF File Commands*/
    128 #define  PH_FRINFC_DESF_NDEF_FILE_ID                    0x04
    129 #define  PH_FRINFC_DESF_NDEF_FILE_SIZE                  0x04
    130 #define  PH_FRINFC_DESF_FIRST_BYTE_NDEF_ACCESS_RIGHTS   0xE0
    131 #define  PH_FRINFC_DESF_SEC_BYTE_NDEF_ACCESS_RIGHTS     0xEE
    132 
    133 
    134 /* Write/Read Data commands/constants*/
    135 #define  PH_FRINFC_DESF_WRITE_CMD                       0x3D
    136 
    137 /* PICC additional frame response*/
    138 #define  PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP            0xAF
    139 
    140 /* Response for PICC native DESFire wrapper cmd*/
    141 #define  PH_FRINFC_DESF_NAT_WRAP_FIRST_RESP_BYTE        0x91
    142 #define  PH_FRINFC_DESF_NAT_WRAP_SEC_RESP_BYTE          0x00
    143 
    144 /* DESFire4 Major/Minor versions*/
    145 #define  PH_FRINFC_DESF4_MAJOR_VERSION                  0x00
    146 #define  PH_FRINFC_DESF4_MINOR_VERSION                  0x06
    147 
    148 /* DESFire4 memory size*/
    149 #define  PH_FRINFC_DESF4_MEMORY_SIZE                    0xEDE
    150 
    151 enum{
    152     PH_SMTCRDFMT_DESF_VAL0 = 0,
    153     PH_SMTCRDFMT_DESF_VAL1 = 1,
    154     PH_SMTCRDFMT_DESF_VAL2 = 2,
    155     PH_SMTCRDFMT_DESF_VAL3 = 3,
    156     PH_SMTCRDFMT_DESF_VAL4 = 4,
    157     PH_SMTCRDFMT_DESF_VAL14 = 14,
    158     PH_SMTCRDFMT_DESF_VAL15 = 15
    159 };
    160 
    161 
    162 
    163 /*!
    164 * \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about
    165 *        the list of registered items. Moreover, the lower device is set.
    166 *
    167 * \param[in] NdefSmtCrdFmt Pointer to a valid or uninitialized instance of \ref phFriNfc_sNdefSmtCrdFmt_t.
    168 *
    169 * \note  This function has to be called at the beginning, after creating an instance of
    170 *        \ref phFriNfc_sNdefSmtCrdFmt_t. Use this function to reset the instance of smart card
    171 formatting context variables.
    172 */
    173 void phFriNfc_Desfire_Reset(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
    174 
    175 /*!
    176 * \ingroup grp_fri_smart_card_formatting
    177 *
    178 * \brief Initiates the card formatting procedure for Remote Smart Card Type.
    179 *
    180 * \copydoc page_ovr The function initiates and formats the DESFire Card.After this
    181 *                   operation,remote card would be properly initialized and
    182 *                   Ndef Compliant.Depending upon the different card type, this
    183 *                   function handles formatting procedure.This function also handles
    184 *                   the different recovery procedures for different types of the cards.
    185 *                   For both Format and Recovery Management same API is used.
    186 *
    187 * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
    188 *                             structure describing the component context.
    189 *
    190 * \retval NFCSTATUS_SUCCESS                  Card formatting has been successfully completed.
    191 * \retval NFCSTATUS_PENDING                  The action has been successfully triggered.
    192 * \retval NFCSTATUS_FORMAT_ERROR             Error occured during the formatting procedure.
    193 * \retval NFCSTATUS_INVALID_REMOTE_DEVICE    Card Type is unsupported.
    194 * \retval NFCSTATUS_INVALID_DEVICE_REQUEST   Command or Operation types are mismatching.
    195 *
    196 */
    197 NFCSTATUS phFriNfc_Desfire_Format(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
    198 
    199 /**
    200 *\ingroup grp_fri_smart_card_formatting
    201 *
    202 * \brief Smart card Formatting \b Completion \b Routine or \b Process function
    203 *
    204 * \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
    205 *                  when an I/O operation has finished. The internal state machine decides
    206 *                  whether to call into the lower device again or to complete the process
    207 *                  by calling into the upper layer's completion routine, stored within this
    208 *                  component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
    209 *
    210 * The function call scheme is according to \ref grp_interact. No State reset is performed during
    211 * operation.
    212 *
    213 * \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
    214 *            calling layer, upon its completion.
    215 * \param[in] Status  The completion status of the lower layer (to be handled by the implementation of
    216 *                    the state machine of this function like a regular return value of an internally
    217 *                    called function).
    218 *
    219 * \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
    220 *
    221 */
    222 void phFriNfc_Desf_Process(void        *Context,
    223                            NFCSTATUS   Status);
    224 
    225 
    226 #endif
    227 
    228