summaryrefslogtreecommitdiffstats
path: root/nci/jni/extns/pn54x/src/mifare/phFriNfc_SmtCrdFmt.h
blob: ac10dee7b9fa80821f3b82243f51c4dd6b6e51a2 (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
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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.
 */

/*
 * Smart Card Completion Routing component
 */

#ifndef PHFRINFC_SMTCRDFMT_H
#define PHFRINFC_SMTCRDFMT_H

#include <phNfcTypes_Mapping.h>

/********************* Definitions and structures *****************************/

#define DESFIRE_FMT_EV1

#define  PH_FRI_NFC_SMTCRDFMT_NFCSTATUS_FORMAT_ERROR             9                /* Format error */
#define  PH_FRINFC_SMTCRDFMT_MSTD_DEFAULT_KEYA_OR_KEYB           {0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF} /* Default Key */
#define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_KEYA                   {0xA0, 0xA1,0xA2,0xA3,0xA4,0xA5} /* Key A */
#define  PH_FRINFC_SMTCRDFMT_NFCFORUMSECT_KEYA                   {0xD3, 0xF7,0xD3,0xF7,0xD3,0xF7} /* NFC Forum Key */
#define  PH_FRINFC_SMTCRDFMT_MSTD_MADSECT_ACCESSBITS             {0x78,0x77,0x88} /* Access bits */
#define  PH_FRINFC_SMTCRDFMT_MSTD_NFCFORUM_ACCESSBITS            {0x7F,0x07,0x88} /* NFC Forum access bits */
#define  PH_FRINFC_SMTCRDFMT_MAX_TLV_TYPE_SUPPORTED              1                /* TLV support */
#define  PH_FRINFC_SMTCRDFMT_MAX_SEND_RECV_BUF_SIZE              252              /* Buffer size */
#define  PH_FRINFC_SMTCRDFMT_STATE_RESET_INIT                    1                /* Format state */

/*
 * Enum definition contains Tag Types
 */
enum
{
    PH_FRINFC_SMTCRDFMT_MIFARE_UL_CARD,
    PH_FRINFC_SMTCRDFMT_ISO14443_4A_CARD,
    PH_FRINFC_SMTCRDFMT_MFSTD_1K_CRD,
    PH_FRINFC_SMTCRDFMT_MFSTD_2K_CRD,
    PH_FRINFC_SMTCRDFMT_MFSTD_4K_CRD,
    PH_FRINFC_SMTCRDFMT_TOPAZ_CARD
};

#define PH_FRINFC_SMTCRDFMT_CR_FORMAT         0  /* Index for phFriNfc_SmtCrd_Format */
#define PH_FRINFC_SMTCRDFMT_CR_INVALID_OPE    1  /* Index for Unknown States/Operations */
#define  PH_FRINFC_SMTCRDFMT_CR               2  /* Number of completion routines */

 /*
  * Mifare Std Additional Information Structure
  */
 typedef struct phFriNfc_MfStd_AddInfo
{
    uint8_t     Default_KeyA_OR_B[6];          /* Stores the Default KeyA and KeyB values */
    uint8_t     MADSect_KeyA[6];               /* Key A of MAD sector */
    uint8_t     NFCForumSect_KeyA[6];          /* Key A of NFC Forum Sector sector */
    uint8_t     MADSect_AccessBits[3];         /* Access Bits of MAD sector */
    uint8_t     NFCForumSect_AccessBits[3];    /* Access Bits of NFC Forum sector */
    uint8_t     ScrtKeyB[6];                   /* Secret key B to given by the application */
    uint8_t     AuthState;                     /* Status of the different authentication */
    uint16_t    CurrentBlock;                  /* Stores the current block */
    uint8_t     NoOfDevices;                   /* Stores the current block */
    uint8_t     SectCompl[40];                 /* Store the compliant sectors */
    uint8_t     WrMADBlkFlag;                  /* Flag to know that MAD sector */
    uint8_t     MADSectBlk[80];                /* Fill the MAD sector blocks */
    uint8_t     UpdMADBlk;                     /* Fill the MAD sector blocks */
} phFriNfc_MfStd_AddInfo_t;

/*
 *  Ndef Mifare Std Additional Information Structure
 */
typedef struct phFriNfc_sNdefSmtCrdFmt_AddInfo
{
   phFriNfc_MfStd_AddInfo_t         MfStdInfo;  /* Mifare Std Additional Information Structure */

}phFriNfc_sNdefSmtCrdFmt_AddInfo_t;

/*
 *  Context information Structure
 */
typedef struct phFriNfc_sNdefSmtCrdFmt
{
    phNfc_sTransceiveInfo_t             *pTransceiveInfo;     /* Pointer to the Transceive information */
    phHal_sRemoteDevInformation_t       *psRemoteDevInfo;     /* Pointer to the Remote Device Information */
    uint8_t                             CardType;             /* Stores the type of the smart card */
    uint8_t                             State;                /* The state of the operation */
    uint8_t                             CardState;            /* Stores the card state */
    phFriNfc_CplRt_t                    CompletionRoutine[PH_FRINFC_SMTCRDFMT_CR];     /* Completion Routine Context */
    phFriNfc_CplRt_t                    SmtCrdFmtCompletionInfo;     /* Holds the completion routine informations of the Smart Card Formatting Layer */
    phHal_uCmdList_t                    Cmd;                  /* Holds the Command Type(read/write) */
    uint16_t                            *SendRecvLength;      /* Holds the length of the received data */
    uint8_t                             *SendRecvBuf;         /* Holds the ack of some intial commands */
    uint16_t                            SendLength;           /* Holds the length of the data to be sent */
    NFCSTATUS                           FmtProcStatus;        /* Stores the output/result of the format procedure */
    phFriNfc_sNdefSmtCrdFmt_AddInfo_t   AddInfo;              /* Stores Additional Information needed to format the different types of tags*/
    uint8_t         TLVMsg[PH_FRINFC_SMTCRDFMT_MAX_TLV_TYPE_SUPPORTED][8];    /* Stores NDEF message TLV */
} phFriNfc_sNdefSmtCrdFmt_t;

NFCSTATUS phFriNfc_NdefSmtCrd_Reset(phFriNfc_sNdefSmtCrdFmt_t       *NdefSmtCrdFmt,
                                    void                            *LowerDevice,
                                    phHal_sRemoteDevInformation_t   *psRemoteDevInfo,
                                    uint8_t                         *SendRecvBuffer,
                                    uint16_t                        *SendRecvBuffLen);

NFCSTATUS phFriNfc_NdefSmtCrd_SetCR(phFriNfc_sNdefSmtCrdFmt_t     *NdefSmtCrdFmt,
                                    uint8_t                       FunctionID,
                                    pphFriNfc_Cr_t                CompletionRoutine,
                                    void                          *CompletionRoutineContext);

void phFriNfc_NdefSmtCrd_Process(void *Context, NFCSTATUS Status);

void phFriNfc_SmtCrdFmt_HCrHandler(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, NFCSTATUS Status);

#endif /* PHFRINFC_SMTCRDFMT_H */