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