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