aboutsummaryrefslogtreecommitdiff
path: root/pn54x/common/phNfcTypes.h
blob: d80ad50cdf39d3cdbc8229a543e67f24a0f130f2 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * Copyright (C) 2010-2014 NXP Semiconductors
 *
 * 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.
 */

#ifndef PHNFCTYPES_H
#define PHNFCTYPES_H

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifndef TRUE
#define TRUE (0x01) /* Logical True Value */
#endif
#ifndef FALSE
#define FALSE (0x00) /* Logical False Value */
#endif
typedef uint8_t utf8_t;     /* UTF8 Character String */
typedef uint8_t bool_t;     /* boolean data type */
typedef uint16_t NFCSTATUS; /* Return values */
#define STATIC static

#define PHNFC_MAX_UID_LENGTH 0x0AU /* Maximum UID length expected */
/* Maximum ATR_RES (General Bytes) length expected */
#define PHNFC_MAX_ATR_LENGTH 0x30U
#define PHNFC_NFCID_LENGTH 0x0AU /* Maximum length of NFCID 1.3*/
#define PHNFC_ATQA_LENGTH 0x02U  /* ATQA length */

/*
 * NFC Data structure
 */
typedef struct phNfc_sData {
  uint8_t* buffer; /* Buffer to store data */
  uint32_t length; /* Buffer length */
} phNfc_sData_t;

/*
 * Possible Hardware Configuration exposed to upper layer.
 * Typically this should be port name (Ex:"COM1","COM2") to which PN54X is
 * connected.
 */
typedef enum {
  ENUM_LINK_TYPE_COM1,
  ENUM_LINK_TYPE_COM2,
  ENUM_LINK_TYPE_COM3,
  ENUM_LINK_TYPE_COM4,
  ENUM_LINK_TYPE_COM5,
  ENUM_LINK_TYPE_COM6,
  ENUM_LINK_TYPE_COM7,
  ENUM_LINK_TYPE_COM8,
  ENUM_LINK_TYPE_I2C,
  ENUM_LINK_TYPE_SPI,
  ENUM_LINK_TYPE_USB,
  ENUM_LINK_TYPE_TCP,
  ENUM_LINK_TYPE_NB
} phLibNfc_eConfigLinkType;

/*
 * Deferred message. This message type will be posted to the client application
 * thread
 * to notify that a deferred call must be invoked.
 */
#define PH_LIBNFC_DEFERREDCALL_MSG (0x311)

/*
 * Deferred call declaration.
 * This type of API is called from ClientApplication ( main thread) to notify
 * specific callback.
 */
typedef void (*pphLibNfc_DeferredCallback_t)(void*);

/*
 * Deferred parameter declaration.
 * This type of data is passed as parameter from ClientApplication (main thread)
 * to the
 * callback.
 */
typedef void* pphLibNfc_DeferredParameter_t;

/*
 * Possible Hardware Configuration exposed to upper layer.
 * Typically this should be at least the communication link (Ex:"COM1","COM2")
 * the controller is connected to.
 */
typedef struct phLibNfc_sConfig {
  uint8_t* pLogFile; /* Log File Name*/
  /* Hardware communication link to the controller */
  phLibNfc_eConfigLinkType nLinkType;
  /* The client ID (thread ID or message queue ID) */
  uintptr_t nClientId;
} phLibNfc_sConfig_t, *pphLibNfc_sConfig_t;

/*
 * NFC Message structure contains message specific details like
 * message type, message specific data block details, etc.
 */
typedef struct phLibNfc_Message {
  uint32_t eMsgType; /* Type of the message to be posted*/
  void* pMsgData;    /* Pointer to message specific data block in case any*/
  uint32_t Size;     /* Size of the datablock*/
} phLibNfc_Message_t, *pphLibNfc_Message_t;

/*
 * Deferred message specific info declaration.
 * This type of information is packed as message data when
 * PH_LIBNFC_DEFERREDCALL_MSG
 * type message is posted to message handler thread.
 */
typedef struct phLibNfc_DeferredCall {
  pphLibNfc_DeferredCallback_t pCallback;   /* pointer to Deferred callback */
  pphLibNfc_DeferredParameter_t pParameter; /* pointer to Deferred parameter */
} phLibNfc_DeferredCall_t;

/*
 * Definitions for supported protocol
 */
typedef struct phNfc_sSupProtocol {
  unsigned int MifareUL : 1;    /* Protocol Mifare Ultra Light or any NFC Forum
                                   Type-2 tags */
  unsigned int MifareStd : 1;   /* Protocol Mifare Standard. */
  unsigned int ISO14443_4A : 1; /* Protocol ISO14443-4 Type A.  */
  unsigned int ISO14443_4B : 1; /* Protocol ISO14443-4 Type B.  */
  unsigned int ISO15693 : 1;    /* Protocol ISO15693 HiTag.  */
  unsigned int Felica : 1;      /* Protocol Felica. */
  unsigned int NFC : 1;         /* Protocol NFC. */
  unsigned int Jewel : 1;       /* Protocol Innovision Jewel Tag. or Any T1T*/
  unsigned int
      Desfire : 1;          /*TRUE indicates specified feature (mapping
                            or formatting)for DESFire tag supported else not supported.*/
  unsigned int Kovio : 1;   /* Protocol Kovio Tag*/
  unsigned int HID : 1;     /* Protocol HID(Picopass) Tag*/
  unsigned int Bprime : 1;  /* Protocol BPrime Tag*/
  unsigned int EPCGEN2 : 1; /* Protocol EPCGEN2 Tag*/
} phNfc_sSupProtocol_t;

/*
 *  Enumerated MIFARE Commands
 */

typedef enum phNfc_eMifareCmdList {
  phNfc_eMifareRaw = 0x00U,      /* This command performs raw transcations */
  phNfc_eMifareAuthentA = 0x60U, /* This command performs an authentication with
                                    KEY A for a sector. */
  phNfc_eMifareAuthentB = 0x61U, /* This command performs an authentication with
                                    KEY B for a sector. */
  phNfc_eMifareRead16 = 0x30U,  /* Read 16 Bytes from a Mifare Standard block */
  phNfc_eMifareRead = 0x30U,    /* Read Mifare Standard */
  phNfc_eMifareWrite16 = 0xA0U, /* Write 16 Bytes to a Mifare Standard block */
  phNfc_eMifareWrite4 = 0xA2U,  /* Write 4 bytes. */
  phNfc_eMifareInc = 0xC1U,     /* Increment */
  phNfc_eMifareDec = 0xC0U,     /* Decrement */
  phNfc_eMifareTransfer = 0xB0U,    /* Transfer */
  phNfc_eMifareRestore = 0xC2U,     /* Restore.   */
  phNfc_eMifareReadSector = 0x38U,  /* Read Sector.   */
  phNfc_eMifareWriteSector = 0xA8U, /* Write Sector.   */
  /* Above commands could be used for preparing raw command but below one can
     not be */
  phNfc_eMifareReadN = 0x01,      /* Proprietary Command */
  phNfc_eMifareWriteN = 0x02,     /* Proprietary Command */
  phNfc_eMifareSectorSel = 0x03,  /* Proprietary Command */
  phNfc_eMifareAuth = 0x04,       /* Proprietary Command */
  phNfc_eMifareProxCheck = 0x05,  /* Proprietary Command */
  phNfc_eMifareInvalidCmd = 0xFFU /* Invalid Command */
} phNfc_eMifareCmdList_t;

/*
 * Information about ISO14443A
 */
typedef struct phNfc_sIso14443AInfo {
  uint8_t Uid[PHNFC_MAX_UID_LENGTH]; /* UID information of the TYPE A
                                      * Tag Discovered */
  uint8_t UidLength;                 /* UID information length */
  uint8_t
      AppData[PHNFC_MAX_ATR_LENGTH]; /* Application data information of the
               1                      * tag discovered (= Historical bytes for
                                      * type A) */
  uint8_t AppDataLength;             /* Application data length */
  uint8_t Sak;                       /* SAK information of the TYPE A
                                      * Tag Discovered */
  uint8_t AtqA[PHNFC_ATQA_LENGTH];   /* ATQA informationof the TYPE A
                                      * Tag Discovered */
  uint8_t MaxDataRate;               /* Maximum data rate supported
                                      * by the tag Discovered */
  uint8_t Fwi_Sfgt;                  /* Frame waiting time and start up
                                      * frame guard */
} phNfc_sIso14443AInfo_t;

/* Remote device information structure */
typedef union phNfc_uRemoteDevInfo {
  phNfc_sIso14443AInfo_t Iso14443A_Info; /* ISO1443A Remote device info */
} phNfc_uRemoteDevInfo_t;

/*
*
*  The RF Device Type List is used to identify the type of
*  remote device that is discovered and connected.
*
*/

typedef enum phNfc_eRFDevType {
  phNfc_eUnknown_DevType = 0x00U,

  phNfc_eISO14443_A_PCD,
  phNfc_eISO14443_B_PCD,
  phNfc_eISO14443_BPrime_PCD,
  phNfc_eFelica_PCD,
  phNfc_eJewel_PCD,
  phNfc_eISO15693_PCD,
  phNfc_eEpcGen2_PCD,
  phNfc_ePCD_DevType,

  phNfc_ePICC_DevType,
  phNfc_eISO14443_A_PICC,
  phNfc_eISO14443_4A_PICC,
  phNfc_eISO14443_3A_PICC,
  phNfc_eMifare_PICC,
  phNfc_eISO14443_B_PICC,
  phNfc_eISO14443_4B_PICC,
  phNfc_eISO14443_BPrime_PICC,
  phNfc_eFelica_PICC,
  phNfc_eJewel_PICC,
  phNfc_eISO15693_PICC,
  phNfc_eEpcGen2_PICC,

  phNfc_eNfcIP1_Target,
  phNfc_eNfcIP1_Initiator,

  phNfc_eInvalid_DevType

} phNfc_eRFDevType_t;

/*
 * The Remote Device Type List is used to identify the type of
 * remote device that is discovered/connected
 */
typedef phNfc_eRFDevType_t phNfc_eRemDevType_t;
typedef phNfc_eRemDevType_t phHal_eRemDevType_t;

/*
 *   Union for each available type of Commands.
 */

typedef union phNfc_uCommand {
  phNfc_eMifareCmdList_t MfCmd; /* Mifare command structure.  */
} phNfc_uCmdList_t;

/*
 *  The Remote Device Information Structure holds information about one single
 * Remote
 *  Device detected.
 */
typedef struct phNfc_sRemoteDevInformation {
  uint8_t SessionOpened;                /* Flag indicating the validity of
                                         * the handle of the remote device.
                                         * 1 = Device is not activer (Only discovered), 2 =
                                         * Device is active and ready for use*/
  phNfc_eRemDevType_t RemDevType;       /* Remote device type */
  phNfc_uRemoteDevInfo_t RemoteDevInfo; /* Union of available Remote Device */
} phNfc_sRemoteDevInformation_t;

/*
 * Transceive Information Data Structure for sending commands/response to the
 * remote device
 */

typedef struct phNfc_sTransceiveInfo {
  phNfc_uCmdList_t cmd; /* Command for transceive */
  uint8_t addr;         /* Start Block Number */
  uint8_t NumBlock;     /* Number of Blocks to perform operation */
  /* For Felica only*/
  uint16_t* ServiceCodeList; /* 2 Byte service Code List */
  uint16_t* Blocklist;       /* 2 Byte Block list */
  phNfc_sData_t sSendData;   /* Send data */
  phNfc_sData_t sRecvData;   /* Recv data */
  /* For EPC-GEN */
  uint32_t dwWordPtr;  /* Word address for the memory write */
  uint8_t bWordPtrLen; /* Specifies the length of word pointer
                       00: 8  bits
                       01: 16 bits
                       10: 24 bits
                       11: 32 bits
                       */
  uint8_t bWordCount;  /* Number of words to be read or written */
} phNfc_sTransceiveInfo_t;

#define UNUSED(X) (void)X;

#endif /* PHNFCTYPES_H */