Home | History | Annotate | Download | only in mifare
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      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  * Smart Card Completion Routing component
     19  */
     20 
     21 #ifndef PHFRINFC_SMTCRDFMT_H
     22 #define PHFRINFC_SMTCRDFMT_H
     23 
     24 #include <phNfcTypes_Mapping.h>
     25 
     26 /********************* Definitions and structures *****************************/
     27 
     28 #define DESFIRE_FMT_EV1
     29 
     30 #define  PH_FRI_NFC_SMTCRDFMT_NFCSTATUS_FORMAT_ERROR             9                /* Format error */
     31 #define  PH_FRINFC_SMTCRDFMT_MSTD_DEFAULT_KEYA_OR_KEYB           {0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF} /* Default Key */
     32 #define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_KEYA                   {0xA0, 0xA1,0xA2,0xA3,0xA4,0xA5} /* Key A */
     33 #define  PH_FRINFC_SMTCRDFMT_NFCFORUMSECT_KEYA                   {0xD3, 0xF7,0xD3,0xF7,0xD3,0xF7} /* NFC Forum Key */
     34 #define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_ACCESSBITS             {0x78,0x77,0x88} /* Access bits */
     35 #define  PH_FRINFC_SMTCRDFMT_MSTD_NFCFORUM_ACCESSBITS            {0x7F,0x07,0x88} /* NFC Forum access bits */
     36 #define  PH_FRINFC_SMTCRDFMT_MAX_TLV_TYPE_SUPPORTED              1                /* TLV support */
     37 #define  PH_FRINFC_SMTCRDFMT_MAX_SEND_RECV_BUF_SIZE              252              /* Buffer size */
     38 #define  PH_FRINFC_SMTCRDFMT_STATE_RESET_INIT                    1                /* Format state */
     39 
     40 /*
     41  * Enum definition contains Tag Types
     42  */
     43 enum
     44 {
     45     PH_FRINFC_SMTCRDFMT_MIFARE_UL_CARD,
     46     PH_FRINFC_SMTCRDFMT_ISO14443_4A_CARD,
     47     PH_FRINFC_SMTCRDFMT_MFSTD_1K_CRD,
     48     PH_FRINFC_SMTCRDFMT_MFSTD_2K_CRD,
     49     PH_FRINFC_SMTCRDFMT_MFSTD_4K_CRD,
     50     PH_FRINFC_SMTCRDFMT_TOPAZ_CARD
     51 };
     52 
     53 #define PH_FRINFC_SMTCRDFMT_CR_FORMAT         0  /* Index for phFriNfc_SmtCrd_Format */
     54 #define PH_FRINFC_SMTCRDFMT_CR_INVALID_OPE    1  /* Index for Unknown States/Operations */
     55 #define  PH_FRINFC_SMTCRDFMT_CR               2  /* Number of completion routines */
     56 
     57  /*
     58   * Mifare Std Additional Information Structure
     59   */
     60  typedef struct phFriNfc_MfStd_AddInfo
     61 {
     62     uint8_t     Default_KeyA_OR_B[6];          /* Stores the Default KeyA and KeyB values */
     63     uint8_t     MADSect_KeyA[6];               /* Key A of MAD sector */
     64     uint8_t     NFCForumSect_KeyA[6];          /* Key A of NFC Forum Sector sector */
     65     uint8_t     MADSect_AccessBits[3];         /* Access Bits of MAD sector */
     66     uint8_t     NFCForumSect_AccessBits[3];    /* Access Bits of NFC Forum sector */
     67     uint8_t     ScrtKeyB[6];                   /* Secret key B to given by the application */
     68     uint8_t     AuthState;                     /* Status of the different authentication */
     69     uint16_t    CurrentBlock;                  /* Stores the current block */
     70     uint8_t     NoOfDevices;                   /* Stores the current block */
     71     uint8_t     SectCompl[40];                 /* Store the compliant sectors */
     72     uint8_t     WrMADBlkFlag;                  /* Flag to know that MAD sector */
     73     uint8_t     MADSectBlk[80];                /* Fill the MAD sector blocks */
     74     uint8_t     UpdMADBlk;                     /* Fill the MAD sector blocks */
     75 } phFriNfc_MfStd_AddInfo_t;
     76 
     77 /*
     78  *  Ndef Mifare Std Additional Information Structure
     79  */
     80 typedef struct phFriNfc_sNdefSmtCrdFmt_AddInfo
     81 {
     82    phFriNfc_MfStd_AddInfo_t         MfStdInfo;  /* Mifare Std Additional Information Structure */
     83 
     84 }phFriNfc_sNdefSmtCrdFmt_AddInfo_t;
     85 
     86 /*
     87  *  Context information Structure
     88  */
     89 typedef struct phFriNfc_sNdefSmtCrdFmt
     90 {
     91     phNfc_sTransceiveInfo_t             *pTransceiveInfo;     /* Pointer to the Transceive information */
     92     phHal_sRemoteDevInformation_t       *psRemoteDevInfo;     /* Pointer to the Remote Device Information */
     93     uint8_t                             CardType;             /* Stores the type of the smart card */
     94     uint8_t                             State;                /* The state of the operation */
     95     uint8_t                             CardState;            /* Stores the card state */
     96     phFriNfc_CplRt_t                    CompletionRoutine[PH_FRINFC_SMTCRDFMT_CR];     /* Completion Routine Context */
     97     phFriNfc_CplRt_t                    SmtCrdFmtCompletionInfo;     /* Holds the completion routine informations of the Smart Card Formatting Layer */
     98     phHal_uCmdList_t                    Cmd;                  /* Holds the Command Type(read/write) */
     99     uint16_t                            *SendRecvLength;      /* Holds the length of the received data */
    100     uint8_t                             *SendRecvBuf;         /* Holds the ack of some intial commands */
    101     uint16_t                            SendLength;           /* Holds the length of the data to be sent */
    102     NFCSTATUS                           FmtProcStatus;        /* Stores the output/result of the format procedure */
    103     phFriNfc_sNdefSmtCrdFmt_AddInfo_t   AddInfo;              /* Stores Additional Information needed to format the different types of tags*/
    104     uint8_t         TLVMsg[PH_FRINFC_SMTCRDFMT_MAX_TLV_TYPE_SUPPORTED][8];    /* Stores NDEF message TLV */
    105 } phFriNfc_sNdefSmtCrdFmt_t;
    106 
    107 NFCSTATUS phFriNfc_NdefSmtCrd_Reset(phFriNfc_sNdefSmtCrdFmt_t       *NdefSmtCrdFmt,
    108                                     void                            *LowerDevice,
    109                                     phHal_sRemoteDevInformation_t   *psRemoteDevInfo,
    110                                     uint8_t                         *SendRecvBuffer,
    111                                     uint16_t                        *SendRecvBuffLen);
    112 
    113 NFCSTATUS phFriNfc_NdefSmtCrd_SetCR(phFriNfc_sNdefSmtCrdFmt_t     *NdefSmtCrdFmt,
    114                                     uint8_t                       FunctionID,
    115                                     pphFriNfc_Cr_t                CompletionRoutine,
    116                                     void                          *CompletionRoutineContext);
    117 
    118 void phFriNfc_NdefSmtCrd_Process(void *Context, NFCSTATUS Status);
    119 
    120 void phFriNfc_SmtCrdFmt_HCrHandler(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, NFCSTATUS Status);
    121 
    122 #endif /* PHFRINFC_SMTCRDFMT_H */
    123