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