• 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 #ifndef PHNFCTYPES_H
18 #define PHNFCTYPES_H
19 
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 
26 #ifndef TRUE
27 #define TRUE (0x01) /* Logical True Value */
28 #endif
29 #ifndef FALSE
30 #define FALSE (0x00) /* Logical False Value */
31 #endif
32 typedef uint8_t utf8_t;     /* UTF8 Character String */
33 typedef uint8_t bool_t;     /* boolean data type */
34 typedef uint16_t NFCSTATUS; /* Return values */
35 
36 #define PHNFC_MAX_UID_LENGTH 0x0AU /* Maximum UID length expected */
37 #define PHNFC_MAX_ATR_LENGTH \
38   0x30U /* Maximum ATR_RES (General Bytes) length expected */
39 #define PHNFC_NFCID_LENGTH 0x0AU /* Maximum length of NFCID 1.3*/
40 #define PHNFC_ATQA_LENGTH 0x02U  /* ATQA length */
41 
42 /*
43  * NFC Data structure
44  */
45 typedef struct phNfc_sData {
46   uint8_t* buffer; /* Buffer to store data */
47   uint32_t length; /* Buffer length */
48 } phNfc_sData_t;
49 
50 /*
51  * Possible Hardware Configuration exposed to upper layer.
52  * Typically this should be port name (Ex:"COM1","COM2") to which PN547 is
53  * connected.
54  */
55 typedef enum {
56   ENUM_LINK_TYPE_COM1,
57   ENUM_LINK_TYPE_COM2,
58   ENUM_LINK_TYPE_COM3,
59   ENUM_LINK_TYPE_COM4,
60   ENUM_LINK_TYPE_COM5,
61   ENUM_LINK_TYPE_COM6,
62   ENUM_LINK_TYPE_COM7,
63   ENUM_LINK_TYPE_COM8,
64   ENUM_LINK_TYPE_I2C,
65   ENUM_LINK_TYPE_SPI,
66   ENUM_LINK_TYPE_USB,
67   ENUM_LINK_TYPE_TCP,
68   ENUM_LINK_TYPE_NB
69 } phLibNfc_eConfigLinkType;
70 
71 /*
72  * Deferred message. This message type will be posted to the client application
73  * thread to notify that a deferred call must be invoked.
74  */
75 #define PH_LIBNFC_DEFERREDCALL_MSG (0x311)
76 
77 /*
78  * Deferred call declaration.
79  * This type of API is called from ClientApplication ( main thread) to notify
80  * specific callback.
81  */
82 typedef void (*pphLibNfc_DeferredCallback_t)(void*);
83 
84 /*
85  * Deferred parameter declaration.
86  * This type of data is passed as parameter from ClientApplication (main thread)
87  * to the callback.
88  */
89 typedef void* pphLibNfc_DeferredParameter_t;
90 
91 /*
92  * Possible Hardware Configuration exposed to upper layer.
93  * Typically this should be at least the communication link (Ex:"COM1","COM2")
94  * the controller is connected to.
95  */
96 typedef struct phLibNfc_sConfig {
97   uint8_t* pLogFile; /* Log File Name*/
98   /* Hardware communication link to the controller */
99   phLibNfc_eConfigLinkType nLinkType;
100   /* The client ID (thread ID or message queue ID) */
101   unsigned int nClientId;
102 } phLibNfc_sConfig_t, *pphLibNfc_sConfig_t;
103 
104 /*
105  * NFC Message structure contains message specific details like
106  * message type, message specific data block details, etc.
107  */
108 typedef struct phLibNfc_Message {
109   uint32_t eMsgType; /* Type of the message to be posted*/
110   void* pMsgData;    /* Pointer to message specific data block in case any*/
111   uint32_t Size;     /* Size of the datablock*/
112 } phLibNfc_Message_t, *pphLibNfc_Message_t;
113 
114 /*
115  * Deferred message specific info declaration.
116  * This type of information is packed as message data when
117  * PH_LIBNFC_DEFERREDCALL_MSG type message is posted to message handler thread.
118  */
119 typedef struct phLibNfc_DeferredCall {
120   pphLibNfc_DeferredCallback_t pCallback;   /* pointer to Deferred callback */
121   pphLibNfc_DeferredParameter_t pParameter; /* pointer to Deferred parameter */
122 } phLibNfc_DeferredCall_t;
123 
124 /*
125  * Definitions for supported protocol
126  */
127 typedef struct phNfc_sSupProtocol {
128   unsigned int MifareUL : 1;    /* Protocol Mifare Ultra Light or any NFC Forum
129                                    Type-2 tags */
130   unsigned int MifareStd : 1;   /* Protocol Mifare Standard. */
131   unsigned int ISO14443_4A : 1; /* Protocol ISO14443-4 Type A.  */
132   unsigned int ISO14443_4B : 1; /* Protocol ISO14443-4 Type B.  */
133   unsigned int ISO15693 : 1;    /* Protocol ISO15693 HiTag.  */
134   unsigned int Felica : 1;      /* Protocol Felica. */
135   unsigned int NFC : 1;         /* Protocol NFC. */
136   unsigned int Jewel : 1;       /* Protocol Innovision Jewel Tag. or Any T1T*/
137   unsigned int
138       Desfire : 1;          /*TRUE indicates specified feature (mapping
139                             or formatting)for DESFire tag supported else not supported.*/
140   unsigned int Kovio : 1;   /* Protocol Kovio Tag*/
141   unsigned int HID : 1;     /* Protocol HID(Picopass) Tag*/
142   unsigned int Bprime : 1;  /* Protocol BPrime Tag*/
143   unsigned int EPCGEN2 : 1; /* Protocol EPCGEN2 Tag*/
144 } phNfc_sSupProtocol_t;
145 
146 /*
147  *  Enumerated MIFARE Commands
148  */
149 
150 typedef enum phNfc_eMifareCmdList {
151   phNfc_eMifareRaw = 0x00U,      /* This command performs raw transcations */
152   phNfc_eMifareAuthentA = 0x60U, /* This command performs an authentication with
153                                     KEY A for a sector. */
154   phNfc_eMifareAuthentB = 0x61U, /* This command performs an authentication with
155                                     KEY B for a sector. */
156   phNfc_eMifareRead16 = 0x30U,  /* Read 16 Bytes from a Mifare Standard block */
157   phNfc_eMifareRead = 0x30U,    /* Read Mifare Standard */
158   phNfc_eMifareWrite16 = 0xA0U, /* Write 16 Bytes to a Mifare Standard block */
159   phNfc_eMifareWrite4 = 0xA2U,  /* Write 4 bytes. */
160   phNfc_eMifareInc = 0xC1U,     /* Increment */
161   phNfc_eMifareDec = 0xC0U,     /* Decrement */
162   phNfc_eMifareTransfer = 0xB0U,    /* Transfer */
163   phNfc_eMifareRestore = 0xC2U,     /* Restore.   */
164   phNfc_eMifareReadSector = 0x38U,  /* Read Sector.   */
165   phNfc_eMifareWriteSector = 0xA8U, /* Write Sector.   */
166   /* Above commands could be used for preparing raw command but below one can
167      not be */
168   phNfc_eMifareReadN = 0x01,      /* Proprietary Command */
169   phNfc_eMifareWriteN = 0x02,     /* Proprietary Command */
170   phNfc_eMifareSectorSel = 0x03,  /* Proprietary Command */
171   phNfc_eMifareAuth = 0x04,       /* Proprietary Command */
172   phNfc_eMifareProxCheck = 0x05,  /* Proprietary Command */
173   phNfc_eMifareInvalidCmd = 0xFFU /* Invalid Command */
174 } phNfc_eMifareCmdList_t;
175 
176 /*
177  * Information about ISO14443A
178  */
179 typedef struct phNfc_sIso14443AInfo {
180   uint8_t Uid[PHNFC_MAX_UID_LENGTH]; /* UID information of the TYPE A
181                                       * Tag Discovered */
182   uint8_t UidLength;                 /* UID information length */
183   uint8_t
184       AppData[PHNFC_MAX_ATR_LENGTH]; /* Application data information of the
185                1                      * tag discovered (= Historical bytes for
186                                       * type A) */
187   uint8_t AppDataLength;             /* Application data length */
188   uint8_t Sak;                       /* SAK information of the TYPE A
189                                       * Tag Discovered */
190   uint8_t AtqA[PHNFC_ATQA_LENGTH];   /* ATQA informationof the TYPE A
191                                       * Tag Discovered */
192   uint8_t MaxDataRate;               /* Maximum data rate supported
193                                       * by the tag Discovered */
194   uint8_t Fwi_Sfgt;                  /* Frame waiting time and start up
195                                       * frame guard */
196 } phNfc_sIso14443AInfo_t;
197 
198 /* Remote device information structure */
199 typedef union phNfc_uRemoteDevInfo {
200   phNfc_sIso14443AInfo_t Iso14443A_Info; /* ISO1443A Remote device info */
201 } phNfc_uRemoteDevInfo_t;
202 
203 /*
204  *
205  *  The RF Device Type List is used to identify the type of
206  *  remote device that is discovered and connected.
207  *
208  */
209 
210 typedef enum phNfc_eRFDevType {
211   phNfc_eUnknown_DevType = 0x00U,
212   phNfc_eISO14443_A_PCD,
213   phNfc_eISO14443_B_PCD,
214   phNfc_eISO14443_BPrime_PCD,
215   phNfc_eFelica_PCD,
216   phNfc_eJewel_PCD,
217   phNfc_eISO15693_PCD,
218   phNfc_eEpcGen2_PCD,
219   phNfc_ePCD_DevType,
220   phNfc_ePICC_DevType,
221   phNfc_eISO14443_A_PICC,
222   phNfc_eISO14443_4A_PICC,
223   phNfc_eISO14443_3A_PICC,
224   phNfc_eMifare_PICC,
225   phNfc_eISO14443_B_PICC,
226   phNfc_eISO14443_4B_PICC,
227   phNfc_eISO14443_BPrime_PICC,
228   phNfc_eFelica_PICC,
229   phNfc_eJewel_PICC,
230   phNfc_eISO15693_PICC,
231   phNfc_eEpcGen2_PICC,
232   phNfc_eNfcIP1_Target,
233   phNfc_eNfcIP1_Initiator,
234   phNfc_eInvalid_DevType
235 } phNfc_eRFDevType_t;
236 
237 /*
238  * The Remote Device Type List is used to identify the type of
239  * remote device that is discovered/connected
240  */
241 typedef phNfc_eRFDevType_t phNfc_eRemDevType_t;
242 typedef phNfc_eRemDevType_t phHal_eRemDevType_t;
243 
244 /*
245  *   Union for each available type of Commands.
246  */
247 
248 typedef union phNfc_uCommand {
249   phNfc_eMifareCmdList_t MfCmd; /* Mifare command structure.  */
250 } phNfc_uCmdList_t;
251 
252 /*
253  *  The Remote Device Information Structure holds information about one single
254  * Remote Device detected.
255  */
256 typedef struct phNfc_sRemoteDevInformation {
257   uint8_t SessionOpened;                /* Flag indicating the validity of
258                                          * the handle of the remote device.
259                                          * 1 = Device is not activer (Only discovered), 2 =
260                                          * Device is active and ready for use*/
261   phNfc_eRemDevType_t RemDevType;       /* Remote device type */
262   phNfc_uRemoteDevInfo_t RemoteDevInfo; /* Union of available Remote Device */
263 } phNfc_sRemoteDevInformation_t;
264 
265 /*
266  * Transceive Information Data Structure for sending commands/response to the
267  * remote device
268  */
269 
270 typedef struct phNfc_sTransceiveInfo {
271   phNfc_uCmdList_t cmd; /* Command for transceive */
272   uint8_t addr;         /* Start Block Number */
273   uint8_t NumBlock;     /* Number of Blocks to perform operation */
274   /* For Felica only*/
275   uint16_t* ServiceCodeList; /* 2 Byte service Code List */
276   uint16_t* Blocklist;       /* 2 Byte Block list */
277   phNfc_sData_t sSendData;   /* Send data */
278   phNfc_sData_t sRecvData;   /* Recv data */
279   /* For EPC-GEN */
280   uint32_t dwWordPtr;  /* Word address for the memory write */
281   uint8_t bWordPtrLen; /* Specifies the length of word pointer
282                        00: 8  bits
283                        01: 16 bits
284                        10: 24 bits
285                        11: 32 bits
286                        */
287   uint8_t bWordCount;  /* Number of words to be read or written */
288 } phNfc_sTransceiveInfo_t;
289 
290 #endif /* PHNFCTYPES_H */
291