Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 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 /**
     18  * \file  phFriNfc_NdefMap.h
     19  * \brief NFC Ndef Mapping For Different Smart Cards.
     20  *
     21  * Project: NFC-FRI
     22  *
     23  * $Date: Mon Dec 13 14:14:14 2010 $
     24  * $Author: ing02260 $
     25  * $Revision: 1.25 $
     26  * $Aliases:  $
     27  *
     28  */
     29 
     30 #ifndef PHFRINFC_NDEFMAP_H
     31 #define PHFRINFC_NDEFMAP_H
     32 
     33 
     34 /*include files*/
     35 #include <phNfcTypes.h>
     36 #include <phNfcStatus.h>
     37 #include <phFriNfc.h>
     38 #ifdef PH_HAL4_ENABLE
     39     #include <phHal4Nfc.h>
     40 #else
     41     #include <phHalNfc.h>
     42 #endif
     43 
     44 
     45 #include <phFriNfc_OvrHal.h>
     46 
     47 #ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
     48 
     49 /**
     50  * \name NDEF Mapping
     51  *
     52  * File: \ref phFriNfc_NdefMap.h
     53  *
     54  */
     55 /*@{*/
     56 #define PH_FRINFC_NDEFMAP_FILEREVISION "$Revision: 1.25 $"  /**< \ingroup grp_file_attributes */
     57 #define PH_FRINFC_NDEFMAP_FILEALIASES  "$Aliases:  $"       /**< \ingroup grp_file_attributes */
     58 /*@}*/
     59 
     60 #endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
     61 
     62 
     63 /** \defgroup grp_fri_nfc_ndef_map NDEF Mapping Component
     64  *
     65  *  This component implements the read/write/check NDEF functions for remote devices.
     66  *  NDEF data, as defined by the NFC Forum NDEF specification are written to or read from
     67  *  a remote device that can be a smart- or memory card. \n\n
     68  *  Please notice that the NDEF mapping command sequence must
     69  *  be \b contiguous (after correct initialisation): \n
     70  *  \b Examples:
     71  *  - Checking and Reading
     72  *      - \ref phFriNfc_NdefMap_ChkNdef
     73  *      - \ref phFriNfc_NdefMap_RdNdef
     74  *      .
     75  *  - Checking and Writing
     76  *      - \ref phFriNfc_NdefMap_ChkNdef
     77  *      - \ref phFriNfc_NdefMap_WrNdef
     78  *      .
     79  *  - Checking, Reading and Writing
     80  *      - \ref phFriNfc_NdefMap_ChkNdef
     81  *      - \ref phFriNfc_NdefMap_RdNdef
     82  *      - \ref phFriNfc_NdefMap_WrNdef
     83  *      .
     84  *  .
     85  * There must be \b no \b other FRI or HAL call between these mapping commands. Exceptions to this
     86  * rule are specific to the NDEF mapping of certain card / remote device types and separately noted,
     87  * typically for true multi-activation capable devices.
     88  *
     89  */
     90 
     91 /**
     92  * \name NDEF Mapping - specifies the different card types
     93  * These are the only recognised card types in this version.
     94  *
     95  */
     96 /*@{*/
     97 
     98 #define DESFIRE_EV1
     99 
    100 #define PH_FRINFC_NDEFMAP_MIFARE_UL_CARD                  1 /**< \internal Mifare UL */
    101 #define PH_FRINFC_NDEFMAP_ISO14443_4A_CARD                2 /**< \internal Iso 14443-4A */
    102 #define PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD              3 /**< \internal Mifare Standard */
    103 #define PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD              4 /**< \internal Mifare Standard */
    104 #define PH_FRINFC_NDEFMAP_FELICA_SMART_CARD               5 /**< \internal Felica Smart Tag */
    105 #define PH_FRINFC_NDEFMAP_TOPAZ_CARD                      7 /**< \internal Felica Smart Tag */
    106 #define PH_FRINFC_NDEFMAP_TOPAZ_DYNAMIC_CARD              8 /**< \internal Felica Smart Tag */
    107 #ifdef DESFIRE_EV1
    108 #define PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1            9 /**< \internal Iso 14443-4A EV1 */
    109 #endif /* #ifdef DESFIRE_EV1 */
    110 
    111 #define PH_FRINFC_NDEFMAP_ISO15693_CARD                   10 /**< \internal ISO 15693 */
    112 
    113 
    114 #ifdef PH_NDEF_MIFARE_ULC
    115 #define PH_FRINFC_NDEFMAP_MIFARE_ULC_CARD                  8 /**< \internal Mifare UL */
    116 #endif /* #ifdef PH_NDEF_MIFARE_ULC */
    117 
    118 #define PH_FRINFC_NDEFMAP_EMPTY_NDEF_MSG                  {0xD0, 0x00, 0x00}  /**< \internal Empty ndef message */
    119 
    120 
    121 #ifdef PHFRINFC_OVRHAL_MOCKUP  /* */
    122 #define PH_FRINFC_NDEFMAP_MOCKUP_CARD                     6 /**< \internal Mocup*/
    123 #endif  /* PHFRINFC_OVRHAL_MOCKUP */
    124 
    125 
    126 
    127 /* Enum reperesents the different card state*/
    128 typedef enum
    129 {
    130     PH_NDEFMAP_CARD_STATE_INITIALIZED,
    131     PH_NDEFMAP_CARD_STATE_READ_ONLY,
    132     PH_NDEFMAP_CARD_STATE_READ_WRITE,
    133     PH_NDEFMAP_CARD_STATE_INVALID
    134 }phNDEF_CARD_STATE;
    135 
    136 
    137 /*@}*/
    138 
    139 
    140 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
    141 /**
    142  * \name NDEF Mapping - specifies the Compliant Blocks in the Mifare 1k and 4k card types
    143  *
    144  */
    145 /*@{*/
    146 #define PH_FRINFC_NDEFMAP_MIFARESTD_1KNDEF_COMPBLOCK      45 /**< \internal Total Ndef Compliant blocks Mifare 1k */
    147 #define PH_FRINFC_NDEFMAP_MIFARESTD_4KNDEF_COMPBLOCK      210 /**< \internal Total Ndef Compliant blocks Mifare 4k */
    148 #define PH_FRINFC_NDEFMAP_MIFARESTD_RDWR_SIZE             16 /**< \internal Bytes read/write for one read/write operation*/
    149 #define PH_FRINFC_NDEFMAP_MIFARESTD_TOTALNO_BLK           40 /**< \internal Total number of sectors in Mifare 4k */
    150 #define PH_FRINFC_NDEFMAP_MIFARESTD_ST15_BYTES            15 /**< \internal To store 15 bytes after reading a block */
    151 /*@}*/
    152 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
    153 
    154 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
    155 /**
    156  * \name NDEF Mapping - specifies the Compliant Blocks in the Mifare 1k and 4k card types
    157  *
    158  */
    159 /*@{*/
    160 #define PH_FRINFC_NDEFMAP_TOPAZ_MAX_SIZE                  256  /**< \internal Total Memory size = 96 bytes (newer version have mode) */
    161 #define PH_FRINFC_NDEFMAP_TOPAZ_UID_SIZE                  0x04  /**< \internal UID size returned by READID command = 4 bytes */
    162 /*@}*/
    163 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED */
    164 
    165 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
    166 /* Felica Mapping - Constants */
    167 #define PH_FRINFC_NDEFMAP_FELICA_BLOCK_SIZE               16
    168 #define PH_FRINFC_NDEFMAP_FELICA_ATTR_NDEF_DATA_LEN        3
    169 #define PH_FRINFC_NDEFMAP_FELICA_MANUF_ID_DATA_LEN         8
    170 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */
    171 
    172 /* MifareUL/Type2 specific constants*/
    173 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
    174 
    175 #ifdef PH_NDEF_MIFARE_ULC
    176 #define PH_FRINFC_NDEFMAP_MFUL_64BYTES_BUF                2048 /**< \internal To store 2048 bytes after reading entire card */
    177 #else
    178 #define PH_FRINFC_NDEFMAP_MFUL_64BYTES_BUF                64 /**< \internal To store 64 bytes after reading entire card */
    179 #endif /*#ifdef PH_NDEF_MIFARE_ULC */
    180 
    181 #define PH_FRINFC_NDEFMAP_MFUL_4BYTES_BUF                 4  /**< \internal To store 4 bytes after write */
    182 
    183 #endif /*#ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED*/
    184 
    185 #ifdef PHFRINFC_OVRHAL_MOCKUP  /* */
    186 
    187 #define PH_FRINFC_NDEFMAP_MOCKUP_4096BYTES_BUF            4096  /**< \internal To store 4 bytes after write */
    188 
    189 #endif /*#ifndef PH_FRINFC_MAP_MOCKUP_DISABLED*/
    190 
    191 /**
    192  * \name Completion Routine Indices
    193  *
    194  * These are the indices of the completion routine pointers within the component context.
    195  * Completion routines belong to upper components.
    196  *
    197  */
    198 /*@{*/
    199 /** \ingroup grp_fri_nfc_ndef_map
    200  *  Completion Routine Index for \ref phFriNfc_NdefMap_ChkNdef */
    201 #define PH_FRINFC_NDEFMAP_CR_CHK_NDEF       0  /* */
    202 /** \ingroup grp_fri_nfc_ndef_map
    203  *  Completion Routine Index for \ref phFriNfc_NdefMap_RdNdef */
    204 #define PH_FRINFC_NDEFMAP_CR_RD_NDEF        1  /* */
    205 /** \ingroup grp_fri_nfc_ndef_map
    206  *  Completion Routine Index for \ref phFriNfc_NdefMap_WrNdef */
    207 #define PH_FRINFC_NDEFMAP_CR_WR_NDEF        2  /* */
    208 /** \ingroup grp_fri_nfc_ndef_map
    209  *  Completion Routine Index for \ref phFriNfc_NdefMap_EraseNdef */
    210 #define PH_FRINFC_NDEFMAP_CR_ERASE_NDEF     3  /* */
    211 /** \ingroup grp_fri_nfc_ndef_map Completion
    212  *  Routine Index for Unknown States/Operations */
    213 #define PH_FRINFC_NDEFMAP_CR_INVALID_OPE    4  /* */
    214 /** \ingroup grp_fri_nfc_ndef_map
    215  *  Number of completion routines that have to be initialised */
    216 #define PH_FRINFC_NDEFMAP_CR                5  /* */
    217 /*@}*/
    218 
    219 /**
    220  * \name File Offset Attributes
    221  *
    222  * Following values are used to determine the offset value for Read/Write. This specifies whether
    223  * the Read/Write operation needs to be restarted/continued from the last offset set.
    224  *
    225  */
    226 /*@{*/
    227 /** \ingroup grp_fri_nfc_ndef_map
    228  *  Read/Write operation shall start from the last offset set */
    229 #define PH_FRINFC_NDEFMAP_SEEK_CUR                          0 /* */
    230 /** \ingroup grp_fri_nfc_ndef_map
    231  *  Read/Write operation shall start from the begining of the file/card */
    232 #define PH_FRINFC_NDEFMAP_SEEK_BEGIN                        1 /* */
    233 /*@}*/
    234 
    235 
    236 /**
    237  * \name Buffer Size Definitions
    238  *
    239  */
    240 /*@{*/
    241 /** \ingroup grp_fri_nfc_ndef_map Minimum size of the TRX buffer required */
    242 #define PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE            252 /* */
    243 /** \internal The size of s MIFARE block */
    244 #define PH_FRINFC_NDEFMAP_MF_READ_BLOCK_SIZE                16  /* */
    245 
    246 
    247 #ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
    248 
    249 
    250 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
    251 
    252 #define ISO15693_MAX_DATA_TO_STORE           0x04U
    253 
    254 typedef struct phFriNfc_ISO15693Cont
    255 {
    256     /**< \internal block number that is executed */
    257     uint16_t    current_block;
    258     /**< \internal The state of the operation */
    259     uint8_t     state;
    260     /**< \internal Completion routine index */
    261     uint8_t     cr_index;
    262     /**< \internal Execution sequence */
    263     uint8_t     ndef_seq;
    264     /**< \internal NDEF TLV size */
    265     uint16_t    actual_ndef_size;
    266     /**< \internal NDEF TLV size */
    267     uint16_t    max_data_size;
    268     /**< \internal NDEF TLV TYPE block number */
    269     uint16_t    ndef_tlv_type_blk;
    270     /**< \internal NDEF TLV TYPE byte number in the
    271         "ndef_tlv_type_blk" */
    272     uint8_t     ndef_tlv_type_byte;
    273     /**< \internal Store the remaining bytes that can be used for
    274     READ with continue option */
    275     uint8_t     store_read_data[ISO15693_MAX_DATA_TO_STORE];
    276     uint8_t     store_length;
    277     /**< \internal Remaining size that can be read */
    278     uint16_t    remaining_size_to_read;
    279     uint8_t     read_capabilities;
    280 
    281 
    282 }phFriNfc_ISO15693Cont_t;
    283 
    284 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
    285 
    286 
    287 
    288 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
    289 /**
    290  *  \ingroup grp_fri_nfc_ndef_map
    291  *  \brief Felica Basic structure which details the different vaiables
    292  *         used for Reading/writing.
    293  *
    294  */
    295 typedef struct phFriNfc_Felica
    296 {
    297     /**< Current block being read or written*/
    298     uint8_t     CurBlockNo;
    299 
    300     /**< No. Of Written*/
    301     uint8_t     NoBlocksWritten;
    302 
    303     /**< Following are different variables used for write operation*/
    304     uint8_t     Wr_BytesRemained;   /* No of bytes to pad*/
    305 
    306     /**< Buffer to store odd number of block data */
    307     uint8_t     Wr_RemainedBytesBuff[PH_FRINFC_NDEFMAP_FELICA_BLOCK_SIZE];
    308 
    309     /**< Following are different variables used for read operation*/
    310     uint8_t     Rd_NoBytesToCopy;         /*specifies the extra number of read bytes */
    311 
    312     /**< stores extra read data bytes*/
    313     uint8_t     Rd_BytesToCopyBuff[PH_FRINFC_NDEFMAP_FELICA_BLOCK_SIZE];
    314 
    315     /**< Flag determines Intermediate Copy Operation*/
    316     uint8_t     IntermediateCpyFlag;
    317 
    318     /**< Stores Intermediate Copy data len*/
    319     uint8_t     IntermediateCpyLen;
    320 
    321     /**< Flag specifies Pad Byte Information*/
    322     uint8_t     PadByteFlag;
    323 
    324     /**< Flag specifies Intermediate WR Information*/
    325     uint8_t     IntermediateWrFlag;
    326 
    327     /**< Flag specifies Intermediate Rd Information*/
    328     uint8_t     IntermediateRdFlag;
    329 
    330     /**< Flag specifies Last Block Reached Information*/
    331     uint8_t     LastBlkReachedFlag;
    332 
    333     /**< Specifies how many bytes read from the card*/
    334     uint16_t        CurrBytesRead;
    335 
    336     /**< Flag specifies EOF card reached Information*/
    337     uint8_t     EofCardReachedFlag;
    338 
    339     /**< Flag specifies different Operation Types*/
    340     uint8_t     OpFlag;
    341 
    342     /**< Specifies Offset*/
    343     uint8_t     Offset;
    344 
    345     /**< Specifies TrxLen Information*/
    346     uint16_t    TrxLen;
    347 
    348 }phFriNfc_Felica_t;
    349 
    350 /**
    351  *  \ingroup grp_fri_nfc_ndef_map
    352  *  \brief Felica structure which details the different vaiables
    353  *         used to store the poll related information.
    354  *
    355  */
    356 typedef struct phFriNfc_Felica_PollDetails
    357 {
    358     phHal_sDevInputParam_t          *DevInputParam;
    359 #ifndef PH_HAL4_ENABLE
    360     phHal_eOpModes_t                *OpMode;
    361 #endif
    362     /**<   Temporary place holder to the Remote Device
    363                     Information, required to store the Felica
    364                     session opened information. */
    365     phHal_sRemoteDevInformation_t   psTempRemoteDevInfo;
    366 }phFriNfc_Felica_PollDetails_t;
    367 
    368 /**
    369  *  \ingroup grp_fri_nfc_ndef_map
    370  *  \brief Felica structure which details the attribute related information.
    371  *
    372  */
    373 typedef struct phFriNfc_Felica_AttrInfo
    374 {
    375     /** Version of the Ndefmap document*/
    376     uint8_t     Version;
    377     /** Nbr for check cmd*/
    378     uint8_t     Nbr;
    379     /** Nbw for update cmd*/
    380     uint8_t     Nbw;
    381     /** Maximum number of blocks to store Ndef data*/
    382     uint16_t    Nmaxb;
    383     /** Flag to indicate the status of the write operation*/
    384     uint8_t     WriteFlag;
    385     /** Flag to indicate the status of the read/write operation*/
    386     uint8_t     RdWrFlag;
    387     /** Represents the length of Ndef data : 3 bytes*/
    388     uint8_t     LenBytes[PH_FRINFC_NDEFMAP_FELICA_ATTR_NDEF_DATA_LEN];
    389     /** Specifies the ERASE NDEF Message Operation */
    390     uint8_t     EraseMsgFlag;
    391 
    392 }phFriNfc_Felica_AttrInfo_t;
    393 
    394 /**
    395  *  \ingroup grp_fri_nfc_ndef_map
    396  *  \brief Felica structure which details the different vaiables
    397  *         used to store the Card Manufacturer details.
    398  */
    399 typedef struct phFriNfc_Felica_ManufDetails
    400 {
    401     /** Manufacture identifier*/
    402     uint8_t     ManufID[PH_FRINFC_NDEFMAP_FELICA_MANUF_ID_DATA_LEN];
    403     /** Manufacture Parameters*/
    404     uint8_t     ManufParameter[PH_FRINFC_NDEFMAP_FELICA_MANUF_ID_DATA_LEN];
    405 }phFriNfc_Felica_ManufDetails_t;
    406 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */
    407 
    408 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
    409 typedef struct phFriNfc_MifareStdCont
    410 {
    411     /** Device input parameter for poll and connect after failed authentication */
    412     phHal_sDevInputParam_t  *DevInputParam;
    413     /** to store bytes that will be used in the
    414         next write/read operation, if any */
    415     uint8_t             internalBuf[PH_FRINFC_NDEFMAP_MIFARESTD_ST15_BYTES];
    416     /** to Store the length of the internalBuf */
    417     uint16_t            internalLength;
    418     /** holds the block number which is presently been used */
    419     uint8_t             currentBlock;
    420     /** the number of Ndef Compliant blocks written/read */
    421     uint8_t             NdefBlocks;
    422     /** Total Number of Ndef Complaint Blocks */
    423     uint16_t            NoOfNdefCompBlocks;
    424     /** used in write ndef, to know that internal bytes
    425         are accessed */
    426     uint8_t             internalBufFlag;
    427     /** used in write ndef, to know that last 16 bytes
    428         are used to write*/
    429     uint8_t             RemainingBufFlag;
    430     /** indicates that Read has reached the end of the
    431         card */
    432     uint8_t             ReadWriteCompleteFlag;
    433     /** indicates that Read has reached the end of the
    434         card */
    435     uint8_t             ReadCompleteFlag;
    436     /** indicates that Write is possible or not */
    437     uint8_t             WriteFlag;
    438     /** indicates that Write is possible or not */
    439     uint8_t             ReadFlag;
    440     /** indicates that Write is possible or not */
    441     uint8_t             RdBeforeWrFlag;
    442     /** Authentication Flag indicating that a particular
    443         sector is authenticated or not */
    444     uint8_t             AuthDone;
    445     /** to store the last Sector ID in Check Ndef */
    446     uint8_t             SectorIndex;
    447     /** to read the access bits of each sector */
    448     uint8_t             ReadAcsBitFlag;
    449     /** Buffer to store 16 bytes */
    450     uint8_t             Buffer[PH_FRINFC_NDEFMAP_MIFARESTD_RDWR_SIZE];
    451     /** to store the AIDs of Mifare 1k or 4k */
    452     uint8_t             aid[PH_FRINFC_NDEFMAP_MIFARESTD_TOTALNO_BLK];
    453     /** flag to write with offset begin */
    454     uint8_t             WrNdefFlag;
    455     /** flag to read with offset begin */
    456     uint8_t             ReadNdefFlag;
    457     /** flag to check with offset begin */
    458     uint8_t             ChkNdefFlag;
    459     /** To store the remaining size of the Mifare 1k or 4k card */
    460     uint16_t            remainingSize;
    461     /** To update the remaining size when writing to the Mifare 1k or 4k card */
    462     uint8_t             remSizeUpdFlag;
    463     /** The flag is to know that there is a different AID apart from
    464         NFC forum sector AID */
    465     uint16_t            aidCompleteFlag;
    466     /** The flag is to know that there is a a NFC forum sector exists
    467         in the card */
    468     uint16_t            NFCforumSectFlag;
    469     /** The flag is to know that the particular sector is a proprietary
    470         NFC forum sector */
    471     uint16_t            ProprforumSectFlag;
    472     /** The flag is set after reading the MAD sectors */
    473     uint16_t            ChkNdefCompleteFlag;
    474     /** Flag to store the current block */
    475     uint8_t             TempBlockNo;
    476     /** Completion routine index */
    477     uint8_t             CRIndex;
    478     /** Bytes remaining to write for one write procedure */
    479     uint16_t            WrLength;
    480     /** Flag to read after write */
    481     uint8_t             RdAfterWrFlag;
    482     /** Flag to say that poll is required before write ndef (authentication) */
    483     uint8_t             PollFlag;
    484     /** Flag is to know that this is first time the read has been called. This
    485     is required when read is called after write (especially for the card formatted
    486     with the 2nd configuration) */
    487     uint8_t             FirstReadFlag;
    488     /** Flag is to know that this is first time the write has been called. This
    489     is required when the card formatted with the 3rd configuration */
    490     uint8_t             FirstWriteFlag;
    491 }phFriNfc_MifareStdCont_t;
    492 /*@}*/
    493 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
    494 
    495 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
    496 /**
    497  *  \ingroup grp_fri_nfc_ndef_map
    498  *  \brief Capability Container.
    499  *
    500  *  The Capability Container structure required for smart card operations.
    501  *
    502  */
    503 typedef struct phFriNfc_DesfireCapCont
    504 {
    505     uint16_t    DesfVersion; /**< \internal Desfire Version . */
    506     uint16_t    NdefMsgFid;  /**< \internal Ndef Message file pointer*/
    507     uint16_t    NdefFileSize; /**< \internal Holds Desfire File Size */
    508     uint8_t     ReadAccess;  /**< \internal Read Access Information. */
    509     uint8_t     WriteAccess; /**< \internal Write Access Information. */
    510     uint16_t    MaxRespSize; /**< \internal Maximum expected response size. */
    511     uint16_t    MaxCmdSize;  /**< \internal Maximum command size. */
    512     uint16_t    NdefDataLen;  /**< \internal Holds actual NDEF Data Len.*/
    513     uint8_t     IsNlenPresentFlag; /**< \internal specifies NLEN presence .*/
    514     uint8_t     SkipNlenBytesFlag; /**< \internal sets on presence of NLEN.*/
    515 } phFriNfc_DesfireCapCont_t;
    516 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */
    517 
    518 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
    519 /**
    520  *  \ingroup grp_fri_nfc_ndef_map
    521  *  \brief Mifare UL Basic structure which details the different vaiables
    522  *         used for Reading/writing.
    523  *
    524  */
    525 typedef struct phFriNfc_MifareULCont
    526 {
    527     /** to store bytes that will be used in the
    528         next write/read operation, if any */
    529     uint8_t             InternalBuf[PH_FRINFC_NDEFMAP_MFUL_4BYTES_BUF];
    530     /** to Store the length of the internalBuf */
    531     uint16_t            InternalLength;
    532     /** holds the sector number which is presently been used */
    533     uint8_t             CurrentSector;
    534     /** holds the block number which is presently been used */
    535     uint8_t             CurrentBlock;
    536     /** to know the completion routine */
    537     uint8_t             CRindex;
    538     /** This stores the free memory size left in the card */
    539     uint16_t            RemainingSize;
    540     /** Copy all the data(including non NDEF TLVs) from the card */
    541     uint8_t             ReadBuf[PH_FRINFC_NDEFMAP_MFUL_64BYTES_BUF];
    542     /** index of the above buffer */
    543     uint16_t            ReadBufIndex;
    544     /** This variable stores the index of the "ReadBuf" from which actual
    545         data has to be copied into the user buffer */
    546     uint16_t            ByteNumber;
    547     /** indicates that read/write has reached the end of the
    548         card */
    549     uint8_t             ReadWriteCompleteFlag;
    550     /** Buffer to store 4 bytes of data which is written to a block */
    551     uint8_t             Buffer[PH_FRINFC_NDEFMAP_MFUL_4BYTES_BUF];
    552 }phFriNfc_MifareULCont_t;
    553 #endif  /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
    554 
    555 #ifdef PHFRINFC_OVRHAL_MOCKUP  /* */
    556 /**
    557  *  \ingroup grp_fri_nfc_ndef_map
    558  *  \brief Mifare UL Basic structure which details the different vaiables
    559  *         used for Reading/writing.
    560  *
    561  */
    562 typedef struct phFriNfc_MockupCont
    563 {
    564     /** to store bytes that will be used in the
    565         next write/read operation, if any */
    566     uint8_t             *NdefData;
    567     /** to Store the length of the internalBuf */
    568     uint32_t            NdefActualSize;
    569     /** to Store the length of the internalBuf */
    570     uint32_t            NdefMaxSize;
    571     /** to Store the length of the internalBuf */
    572     uint32_t            CardSize;
    573     /** holds the block number which is presently been used */
    574     uint32_t             CurrentBlock;
    575 } phFriNfc_MockupCont_t;
    576 #endif  /* PHFRINFC_OVRHAL_MOCKUP */
    577 
    578 #endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
    579 
    580 /**
    581  *  \ingroup grp_fri_nfc_ndef_map
    582  *  \brief NDEF TLV structure which details the different vaiables
    583  *         used for TLV.
    584  *
    585  */
    586 typedef struct phFriNfc_NDEFTLVCont
    587 {
    588     /** Flag is to know that the TLV Type Found */
    589     uint8_t             NdefTLVFoundFlag;
    590     /** Sector number of the next/present available TLV */
    591     uint8_t             NdefTLVSector;
    592     /** Following two variables are used to store the
    593         T byte and the Block number in which the T is
    594         found in Tag */
    595     /** Byte number of the next/present available TLV */
    596     uint16_t            NdefTLVByte;
    597     /** Block number of the next/present available TLV */
    598     uint8_t             NdefTLVBlock;
    599     /** Authentication flag for NDEF TLV Block */
    600     uint8_t             NdefTLVAuthFlag;
    601     /** if the 16th byte of the last read is type (T) of TLV
    602         and next read contains length (L) bytes of TLV. This flag
    603         is set when the type (T) of TLV is found in the last read */
    604     uint8_t             TcheckedinTLVFlag;
    605     /** if the 16th byte of the last read is Length (L) of TLV
    606         and next read contains length (L) bytes of TLV. This flag
    607         is set when the Length (L) of TLV is found in the last read */
    608     uint8_t             LcheckedinTLVFlag;
    609     /** This flag is set, if Terminator TLV is already written
    610         and next read contains value (V) bytes of TLV. This flag
    611         is set when the value (V) of TLV is found in the last read */
    612     uint8_t             SetTermTLVFlag;
    613     /** To know the number of Length (L) field is present in the
    614         next block */
    615     uint8_t             NoLbytesinTLV;
    616     /** The value of 3 bytes length(L) field in TLV. In 3 bytes
    617         length field, 2 bytes are in one block and other 1 byte
    618         is in the next block. To store the former block length
    619         field value, this variable is used */
    620     uint16_t            prevLenByteValue;
    621     /** The value of length(L) field in TLV. */
    622     uint16_t            BytesRemainLinTLV;
    623     /** Actual size to read and write. This will be always equal to the
    624         length (L) of TLV as there is only one NDEF TLV . */
    625     uint16_t            ActualSize;
    626     /** Flag is to write the length (L) field of the TLV */
    627     uint8_t             WrLenFlag;
    628     /** Flag is to write the length (L) field of the TLV */
    629     uint16_t            NULLTLVCount;
    630     /** Buffer to store 4 bytes of data which is written to a block */
    631     uint8_t             NdefTLVBuffer[PH_FRINFC_NDEFMAP_MFUL_4BYTES_BUF];
    632     /** Buffer to store 4 bytes of data which is written to a next block */
    633     uint8_t             NdefTLVBuffer1[PH_FRINFC_NDEFMAP_MFUL_4BYTES_BUF];
    634 }phFriNfc_NDEFTLVCont_t;
    635 
    636 /**
    637  *  \ingroup grp_fri_nfc_ndef_map
    638  *  \brief Lock Control TLV structure which stores the Position,
    639  *         Size and PageCntrl details.
    640  */
    641 
    642 typedef struct phFriNfc_LockCntrlTLVCont
    643 {
    644     /** Specifies the Byte Position of the lock cntrl tlv
    645         in the card memory*/
    646     uint16_t             ByteAddr;
    647 
    648     /** Specifies the Size of the lock area in terms of
    649         bits/bytes*/
    650     uint16_t             Size;
    651 
    652     /** Specifies the Bytes per Page*/
    653     uint8_t             BytesPerPage;
    654 
    655     /** Specifies the BytesLockedPerLockBit */
    656     uint8_t             BytesLockedPerLockBit;
    657 
    658     /** Specifies the index of Lock cntrl TLV*/
    659     uint8_t             LockTlvBuffIdx;
    660 
    661     /** Store the content of Lock cntrl TLV*/
    662     uint8_t             LockTlvBuff[8];
    663 
    664     /** Specifies the Block number Lock cntrl TLV*/
    665     uint16_t             BlkNum;
    666 
    667     /** Specifies the Byte Number position of Lock cntrl TLV*/
    668     uint16_t             ByteNum;
    669 
    670 
    671 }phFriNfc_LockCntrlTLVCont_t;
    672 
    673 
    674 /**
    675  *  \ingroup grp_fri_nfc_ndef_map
    676  *  \brief Memeory Control TLV structure which stores the Position,
    677  *         Size and PageCntrl details of the reserved byte area.
    678  */
    679 
    680 typedef struct phFriNfc_ResMemCntrlTLVCont
    681 {
    682     /** Specifies the Byte Position of the lock cntrl tlv
    683         in the card memory*/
    684     uint16_t             ByteAddr;
    685 
    686     /** Specifies the Size of the lock area in terms of
    687         bits/bytes*/
    688     uint16_t             Size;
    689 
    690     /** Store the content of Memory cntrl TLV*/
    691     uint8_t             MemCntrlTlvBuff[8];
    692 
    693     /** Specifies the Bytes per Page*/
    694     uint8_t             BytesPerPage;
    695 
    696     /** Specifies the index of Mem cntrl TLV*/
    697     uint8_t             MemTlvBuffIdx;
    698 
    699     /** Specifies the Block number Lock cntrl TLV*/
    700     uint16_t             BlkNum;
    701 
    702     /** Specifies the Byte Number position of Lock cntrl TLV*/
    703     uint16_t             ByteNum;
    704 
    705 
    706 
    707 }phFriNfc_ResMemCntrlTLVCont_t;
    708 
    709 #if !(defined(PH_FRINFC_MAP_TOPAZ_DISABLED ) || defined (PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED ))
    710 
    711 /**
    712  *  \ingroup grp_fri_nfc_ndef_map
    713  *  \brief Topaz container structure which details the different vaiables
    714  *         used for Topaz card mapping.
    715  *
    716  */
    717 typedef struct phFriNfc_TopazCont
    718 {
    719     /** This stores the free memory size left in the card. In case of topaz,
    720         this is updated only during check ndef */
    721     uint16_t            RemainingSize;
    722     /** Stores the current block number */
    723     uint8_t             CurrentBlock;
    724     /** Stores the current block number */
    725     uint8_t             ByteNumber;
    726     /** To know the completion routine call */
    727     uint8_t             CRIndex;
    728 
    729     uint8_t             ReadWriteCompleteFlag;
    730     /** This state is used for write */
    731     uint8_t             InternalState;
    732      /** This state is used for write */
    733     uint8_t             SkipLockBlkFlag;
    734     /** To store the UID */
    735     uint8_t             UID[PH_FRINFC_NDEFMAP_TOPAZ_UID_SIZE];
    736     /** To CC bytes length */
    737     uint8_t             CCByteBuf[4];
    738     /** Store the Buffer Index */
    739     uint16_t             Cur_RW_Index;
    740 
    741     /* No of bytes read or write*/
    742     uint16_t            ByteRWFrmCard;
    743 
    744     /* Cuurent Segment */
    745     uint8_t             CurrentSeg;
    746 
    747      /** Store the read bytes */
    748     uint8_t             ReadBuffer[PH_FRINFC_NDEFMAP_TOPAZ_MAX_SIZE];
    749 
    750     /** Size to know the exact data filled in the ReadBuffer. Useful, when the
    751         offset = PH_FRINFC_NDEFMAP_SEEK_CUR */
    752     uint8_t             ReadBufferSize;
    753 
    754     /** NDEF TLV byte address, This stores the byte address of
    755         TYPE field of the TLV */
    756     uint16_t            NdefTLVByteAddress;
    757 
    758     /** Expected sequence */
    759     uint8_t             ExpectedSeq;
    760 
    761     /** Write sequence */
    762     uint8_t             WriteSeq;
    763 
    764     /** Actual NDEF message size */
    765     uint16_t            ActualNDEFMsgSize;
    766 
    767     /** NDEF Read Write size in the card, this excludes lock and reserved bytes,
    768         mentioned in the LOCK and MEMORY control TLVs */
    769     uint16_t            NDEFRWSize;
    770 
    771     /** Remaining read size in the card, after reading the card.
    772         User has asked for the data less than " ActualNDEFMsgSize ",
    773         then remaining read bytes are stored in this variable.
    774         If the next read is with offset = PH_FRINFC_NDEFMAP_SEEK_CUR,
    775         then this variable is used.
    776     */
    777     uint16_t            RemainingReadSize;
    778 #ifdef FRINFC_READONLY_NDEF
    779     uint8_t             read_only_seq;
    780     uint8_t             lock_bytes_written;
    781 #endif /* #ifdef FRINFC_READONLY_NDEF */
    782 
    783 }phFriNfc_TopazCont_t;
    784 
    785 #endif /* PH_FRINFC_MAP_TOPAZ_DISABLED */
    786 /**
    787  *  \ingroup grp_fri_nfc_ndef_map
    788  *  \brief NFC NDEF Mapping Component Context Structure
    789  *
    790  *  This structure is used to store the current context information of the instance.
    791  *
    792  */
    793 typedef struct phFriNfc_NdefMap
    794 {
    795     /**< \internal The state of the operation. */
    796     uint8_t                         State;
    797 
    798     /**< \internal Completion Routine Context. */
    799     phFriNfc_CplRt_t                CompletionRoutine[PH_FRINFC_NDEFMAP_CR];
    800 
    801     /**< \internal Pointer to the lower (HAL) instance. */
    802     void                            *LowerDevice;
    803 
    804     /**<\internal Holds the device additional informations*/
    805     phHal_sDepAdditionalInfo_t      psDepAdditionalInfo;
    806 
    807     /**<\internal Holds the completion routine informations of the Map Layer*/
    808     phFriNfc_CplRt_t                MapCompletionInfo;
    809 
    810     /**< \internal Pointer to the Remote Device Information */
    811     phHal_sRemoteDevInformation_t   *psRemoteDevInfo;
    812 
    813     /**<\internal Holds the Command Type(read/write)*/
    814     phHal_uCmdList_t               Cmd;
    815 
    816     /**< \internal Pointer to a temporary buffer. Could be
    817           used for read/write purposes */
    818     uint8_t                         *ApduBuffer;
    819 
    820     /**< \internal Size allocated to the ApduBuffer. */
    821     uint32_t                        ApduBufferSize;
    822 
    823     /**< \internal Index to the APDU Buffer. Used for internal calculations */
    824     uint16_t                        ApduBuffIndex;
    825 
    826     /**< \internal Pointer to the user-provided Data Size to be written trough WrNdef function. */
    827     uint32_t                        *WrNdefPacketLength;
    828 
    829 
    830     /**< \internal Holds the length of the received data. */
    831     uint16_t                        *SendRecvLength;
    832 
    833     /**<\internal Holds the ack of some intial commands*/
    834     uint8_t                         *SendRecvBuf;
    835 
    836     /**< \internal Holds the length of the data to be sent. */
    837     uint16_t                        SendLength;
    838 
    839     /**< \internal Data Byte Count, which gives the offset to the integration.*/
    840     uint16_t                        *DataCount;
    841 
    842     /**< \ internal Holds the previous operation on the card*/
    843     uint8_t                         PrevOperation;
    844 
    845     /**< \ internal Holds the previous state on the card*/
    846     uint8_t                         PrevState;
    847 
    848     /**< \internal Stores the type of the smart card. */
    849     uint8_t                         CardType;
    850 
    851      /**< \internal Stores the card state. */
    852     uint8_t                         CardState;
    853 
    854     /**< \internal Stores the memory size of the card */
    855     uint16_t                        CardMemSize;
    856 
    857     /**<\internal to Store the page offset on the mifare ul card*/
    858     uint8_t                         Offset;
    859 
    860     /** \internal specifies the desfire operation to be performed*/
    861     uint8_t                         DespOpFlag;
    862 
    863     /** \internal  Used to remeber how many bytes were written, to update
    864                    the dataCount and the BufferIndex */
    865     uint16_t                        NumOfBytesWritten;
    866 
    867     /**\internal used to remember number of L byte Remaining to be written */
    868     uint16_t                        NumOfLReminWrite;
    869 
    870     /** \internal  Pointer Used to remeber and return how many bytes were read,
    871                    to update the PacketDataLength in case of Read operation */
    872     /*  Fix for 0000238: [gk] MAP: Number of bytes actually read out is
    873         not returned. */
    874     uint32_t                        *NumOfBytesRead;
    875 
    876     /** \internal  Flag used to tell the process function that WRITE has
    877                    requested for an internal READ.*/
    878     uint8_t                         ReadingForWriteOperation;
    879 
    880     /** \internal  Buffer of 5 bytes used for the write operation for the
    881                    Mifare UL card.*/
    882     uint8_t                         BufferForWriteOp[5];
    883 
    884     /** \internal Temporary Receive Length to update the Receive Length
    885                   when every time the Overlapped HAL is called. */
    886     uint16_t                        TempReceiveLength;
    887 
    888     uint8_t                         NoOfDevices ;
    889 
    890     /** \internal stores operating mode type of the felica smart tag */
    891     /* phHal_eOpModes_t                OpModeType[2]; */
    892 
    893     /** \internal stores the type of the TLV found */
    894     uint8_t                         TLVFoundFlag;
    895 
    896     /** \internal stores the TLV structure related informations  */
    897     phFriNfc_NDEFTLVCont_t          TLVStruct;
    898 
    899 
    900     /** \internal stores the Lock Contrl Tlv related informations  */
    901     phFriNfc_LockCntrlTLVCont_t     LockTlv;
    902 
    903     /** \internal stores the Mem Contrl Tlv related informations  */
    904     phFriNfc_ResMemCntrlTLVCont_t   MemTlv;
    905 
    906 
    907 
    908     /** Capabilitity Containers: */
    909     #ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
    910         /** \internal Desfire capability Container Structure. */
    911 #ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
    912         phFriNfc_DesfireCapCont_t       DesfireCapContainer;
    913 #endif  /* PH_FRINFC_MAP_DESFIRE_DISABLED */
    914 
    915 #ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
    916         /** \internal Pointer to the Mifare Standard capability Container Structure. */
    917         phFriNfc_MifareStdCont_t        StdMifareContainer;
    918 #endif  /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
    919 
    920 #ifndef PH_FRINFC_MAP_FELICA_DISABLED
    921         /** \internal Following are the Felica Smart tag related strucutre & variables */
    922         phFriNfc_Felica_t               Felica;
    923 
    924         /** \internal Struture Stores the dev i/p , opmode informations of smart tag */
    925         phFriNfc_Felica_PollDetails_t   FelicaPollDetails;
    926 
    927         /** \internal Struture Stores the different attribute informations of smart tag */
    928         phFriNfc_Felica_AttrInfo_t      FelicaAttrInfo;
    929 
    930         /** \internal Struture Stores the PMm,IDm informations of smart tag */
    931         phFriNfc_Felica_ManufDetails_t  FelicaManufDetails;
    932 #endif  /* PH_FRINFC_MAP_FELICA_DISABLED */
    933 #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
    934         /** \internal Mifare UL capability container structure. */
    935         phFriNfc_MifareULCont_t         MifareULContainer;
    936 #endif  /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
    937 #ifndef PH_FRINFC_MAP_TOPAZ_DISABLED
    938         /** \internal Mifare UL capability container structure. */
    939         phFriNfc_TopazCont_t            TopazContainer;
    940 #endif  /* PH_FRINFC_MAP_TOPAZ_DISABLED */
    941 
    942 #ifndef PH_FRINFC_MAP_ISO15693_DISABLED
    943         phFriNfc_ISO15693Cont_t         ISO15693Container;
    944 #endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
    945 
    946 #ifdef PHFRINFC_OVRHAL_MOCKUP
    947         phFriNfc_MockupCont_t MochupContainer;
    948 #endif  /* PHFRINFC_OVRHAL_MOCKUP */
    949 
    950     #endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
    951 
    952 } phFriNfc_NdefMap_t;
    953 
    954 
    955 #ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
    956 
    957 /**
    958  * \ingroup grp_fri_nfc_ndef_map
    959  *
    960  * \brief Ndef Mapping \b Reset function
    961  *
    962  * \copydoc page_reg Resets the component instance to the initial state and initialises the
    963  *          internal variables.
    964  *
    965  * \param[in] NdefMap is a Pointer to a valid and initialised or uninitialised instance
    966  *            of \ref phFriNfc_NdefMap_t .
    967  * \param[in] LowerDevice Overlapped HAL reference, pointing at a valid instance of this
    968  *            underlying component.
    969  * \param[in] psRemoteDevInfo Points to the Remote Device Information structure encapsulating
    970  *                            the information about the device (Smart card, NFC device) to access.
    971  * \param[in] psDevInputParam The Device input parameter, as used for the HAL POLL function.
    972  *                            This parameter is needed by the component in special cases, when an internal call
    973  *                            to POLL is required again, such as for FeliCa. The storage of the structure behind
    974  *                            the pointer must be retained by the calling software. The component itself only
    975  *                            keeps the reference. No change is applied to the structure's content.
    976  * \param[in] TrxBuffer Pointer to an internally used buffer. The buffer has to be allocated by
    977  *                      the integrating software (not done by the component). The purpose of
    978  *                      this storage is to serve as an intermediate buffer for data frame
    979  *                      composition and analysis.
    980  *                      The size shall be at least \ref PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE .
    981  * \param[in] TrxBufferSize The size of TrxBuffer:
    982  *            The size shall be at least \ref PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE .
    983  * \param[in] ReceiveBuffer Pointer to a buffer that the component uses internally use to
    984  *            store the data received from the lower component.
    985  *            The size shall be at least \ref PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE .
    986  * \param[in] ReceiveLength The size of ReceiveBuffer. This specifies the actual length
    987  *            of the data received from the lower component.
    988  *            The size shall be at least \ref PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE .
    989  * \param[in] DataCount Specifies the offset count during read/write operations. This can be
    990  *            used by the integrating software to know about the total number of bytes read/written
    991  *            from/to the card. The caller shall set the value behind the pointer to zero
    992  *            before calling this function.
    993  *
    994  * \retval NFCSTATUS_SUCCESS                Operation successful.
    995  * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
    996  *
    997  * \note  The DataCount variable is internally updated by the module and must not be changed by the
    998  *        embedding software.
    999  * \note  This function has to be called at the beginning, after creating an instance of
   1000  *        \ref phFriNfc_NdefMap_t .  Use this function to reset the instance and/or to switch
   1001  *        to a different underlying device (different NFC device or device mode).
   1002  */
   1003 NFCSTATUS phFriNfc_NdefMap_Reset(phFriNfc_NdefMap_t              *NdefMap,
   1004                                  void                            *LowerDevice,
   1005                                  phHal_sRemoteDevInformation_t   *psRemoteDevInfo,
   1006                                  phHal_sDevInputParam_t          *psDevInputParam,
   1007                                  uint8_t                         *TrxBuffer,
   1008                                  uint16_t                         TrxBufferSize,
   1009                                  uint8_t                         *ReceiveBuffer,
   1010                                  uint16_t                        *ReceiveLength,
   1011                                  uint16_t                        *DataCount);
   1012 
   1013 
   1014 /**
   1015  * \ingroup grp_fri_nfc_ndef_map
   1016  *
   1017  * \brief Ndef Mapping \b Set \b Completion \b Routine function
   1018  *
   1019  * \copydoc page_reg Setting of the Completion Routine.
   1020  *
   1021  * This function sets the Completion Routine for the specified function ID:\n
   1022  * The completion routine is a function of an upper layer in the stack that needs to be notified
   1023  * when the current instance has completed an I/O operation and data and/or an I/O status value
   1024  * is available. The list of valid function IDs can be found under the section
   1025  * "Completion Routine Indices", like e.g. \ref PH_FRINFC_NDEFMAP_CR_CHK_NDEF.
   1026  *
   1027  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure
   1028  *                    serving as the component context.
   1029  * \param[in] FunctionID ID of the component API function to set a with a completion routine for.
   1030  *                       A valid routine has to be assigned for each function ID.
   1031  *                       Use the "Completion Routine Indices", such as \ref PH_FRINFC_NDEFMAP_CR_CHK_NDEF .
   1032  * \param[in] CompletionRoutine Pointer to a completion routine (part of a component of the upper layer)
   1033  *                              to be called when the non-blocking opertaion has finished.
   1034  * \param[in] CompletionRoutineContext Pointer to the context of the (upper) component where the
   1035  *                                     particular completion routine is located.
   1036  *
   1037  * \retval NFCSTATUS_SUCCESS                Operation successful.
   1038  * \retval NFCSTATUS_INVALID_PARAMETER      At least one parameter of the function is invalid.
   1039  *
   1040  * \note  This function has to be called after \ref phFriNfc_NdefMap_Reset .
   1041  */
   1042 NFCSTATUS phFriNfc_NdefMap_SetCompletionRoutine(phFriNfc_NdefMap_t  *NdefMap,
   1043                                                 uint8_t              FunctionID,
   1044                                                 pphFriNfc_Cr_t       CompletionRoutine,
   1045                                                 void                *CompletionRoutineContext);
   1046 
   1047 
   1048 /**
   1049  * \ingroup grp_fri_nfc_ndef_map
   1050  *
   1051  * \brief Ndef Mapping \b Read \b Ndef function
   1052  *
   1053  * \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device.
   1054  *
   1055  * The function initiates the reading of NDEF information from a Remote Device.
   1056  * It performs a reset of the state and restarts the state machine.
   1057  *
   1058  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1059  *                    component context structure.
   1060  * \param[in,out] PacketData  Pointer to a location that shall receive the NDEF Packet.
   1061  * \param[in,out] PacketDataLength Pointer to a variable that shall receive the length of the NDEF packet.
   1062  *                                 The caller has to provide the maximum length, the function fills
   1063  *                                 in the actual number of bytes received.
   1064  * \param[in] Offset Indicates whether the read operation shall start from the begining of the
   1065  *            file/card storage \b or continue from the last offset. The last Offset set is stored
   1066  *            within a context (Data Count) variable (must not be modified by the integration).
   1067  *            If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
   1068  *            start reading from the last offset set (continue where it has stopped before).
   1069  *            If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading
   1070  *            from the begining of the card (restarted)
   1071  *
   1072  * \retval NFCSTATUS_PENDING               The action has been successfully triggered.
   1073  * \retval NFCSTATUS_SUCCESS               Operation Successful.
   1074  *
   1075  * \retval NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
   1076  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
   1077  * \retval NFCSTATUS_EOF_CARD_REACHED      No Space in the File to read.
   1078  * \retval NFCSTATUS_INVALID_DEVICE        The device has not been opened or has been disconnected
   1079  *                                         meanwhile.
   1080  * \retval NFCSTATUS_CMD_ABORTED           The caller/driver has aborted the request.
   1081  * \retval NFCSTATUS_BUFFER_TOO_SMALL      The buffer provided by the caller is too small.
   1082  * \retval NFCSTATUS_RF_TIMEOUT            No data has been received within the TIMEOUT period.
   1083  *
   1084  */
   1085 NFCSTATUS phFriNfc_NdefMap_RdNdef(phFriNfc_NdefMap_t      *NdefMap,
   1086                                   uint8_t                 *PacketData,
   1087                                   uint32_t                *PacketDataLength,
   1088                                   uint8_t                  Offset);
   1089 
   1090 
   1091 /**
   1092  * \ingroup grp_fri_nfc_ndef_map
   1093  *
   1094  * \brief Ndef Mapping \b Check \b Ndef function
   1095  *
   1096  * \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
   1097  *
   1098  * The function initiates the writing of NDEF information to a Remote Device.
   1099  * It performs a reset of the state and starts the action (state machine).
   1100  * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
   1101  * has been triggered.
   1102  *
   1103  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1104  *                    component context structure.
   1105  * \param[in] PacketData  Pointer to a location that holds the prepared NDEF Packet.
   1106  * \param[in,out] PacketDataLength Pointer to a variable that shall specify the length of the prepared NDEF packet.
   1107  *                                 The caller has to provide the length, the function fills
   1108  *                                 in the actual number of bytes received.
   1109  * \param[in] Offset Indicates whether the write operation shall start from the begining of the
   1110  *            file/card storage \b or continue from the last offset. The last Offset set is stored
   1111  *            within a context (Data Count) variable (must not be modified by the integration).
   1112  *            If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
   1113  *            start writing from the last offset set (continue where it has stopped before).
   1114  *            If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing
   1115  *            from the begining of the card (restarted)
   1116  *
   1117  * \retval NFCSTATUS_PENDING               The action has been successfully triggered.
   1118  * \retval NFCSTATUS_SUCCESS               Operation Successful.
   1119  *
   1120  * \retval NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
   1121  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
   1122  * \retval NFCSTATUS_EOF_CARD_REACHED      No Space in the File to write.
   1123  * \retval NFCSTATUS_INVALID_DEVICE        The device has not been opened or has been disconnected
   1124  *                                         meanwhile.
   1125  * \retval NFCSTATUS_CMD_ABORTED           The caller/driver has aborted the request.
   1126  * \retval NFCSTATUS_BUFFER_TOO_SMALL      The buffer provided by the caller is too small.
   1127  * \retval NFCSTATUS_RF_TIMEOUT            No data has been received within the TIMEOUT period.
   1128  *
   1129  */
   1130 
   1131 extern NFCSTATUS phFriNfc_NdefMap_WrNdef(phFriNfc_NdefMap_t  *NdefMap,
   1132                                   uint8_t             *PacketData,
   1133                                   uint32_t            *PacketDataLength,
   1134                                   uint8_t              Offset);
   1135 
   1136 
   1137 /**
   1138  * \ingroup grp_fri_nfc_ndef_map
   1139  *
   1140  * \brief Ndef Mapping \b Check \b NDEF function
   1141  *
   1142  * \copydoc page_ovr Check whether a particular Remote Device is NDEF compliant.
   1143  *
   1144  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1145  *                    component context structure.
   1146  *
   1147  * \retval NFCSTATUS_PENDING               The action has been successfully triggered.
   1148  * \retval NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
   1149  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
   1150  * \retval NFCSTATUS_INVALID_PARAMETER     Completion Routine is NULL.
   1151  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE OpModes invalid.
   1152  * \retval NFCSTATUS_INVALID_DEVICE        The device has not been opened or has been disconnected
   1153  *                                         meanwhile.
   1154  * \retval NFCSTATUS_CMD_ABORTED           The caller/driver has aborted the request.
   1155  * \retval NFCSTATUS_BUFFER_TOO_SMALL      The buffer provided by the caller is too small.
   1156  * \retval NFCSTATUS_RF_TIMEOUT            No data has been received within the TIMEOUT period.
   1157  *
   1158  */
   1159 NFCSTATUS phFriNfc_NdefMap_ChkNdef(phFriNfc_NdefMap_t *NdefMap);
   1160 
   1161 #ifdef FRINFC_READONLY_NDEF
   1162 /*!
   1163  * \ingroup grp_fri_smart_card_formatting
   1164  *
   1165  * \brief Initiates the conversion of the already NDEF formatted tag to READ ONLY.
   1166  *
   1167  * \copydoc page_ovr  The function initiates the conversion of the already NDEF formatted
   1168  * tag to READ ONLY.After this formation, remote card would be properly Ndef Compliant and READ ONLY.
   1169  * Depending upon the different card type, this function handles formatting procedure.
   1170  * This function supports only for the TOPAZ tags.
   1171  *
   1172  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
   1173  *                    the component context.
   1174  * \retval  NFCSTATUS_PENDING   The action has been successfully triggered.
   1175  * \retval  Other values        An error has occurred.
   1176  *
   1177  */
   1178 NFCSTATUS
   1179 phFriNfc_NdefMap_ConvertToReadOnly (
   1180     phFriNfc_NdefMap_t          *NdefMap);
   1181 
   1182 #endif /* #ifdef FRINFC_READONLY_NDEF */
   1183 
   1184 /**
   1185  * \ingroup grp_fri_nfc_ndef_map
   1186  *
   1187  * \brief Ndef Mapping \b Erase \b NDEF function
   1188  *
   1189  * \copydoc page_ovr find the position of the existing NDEF TLV and overwrite with \b empty NDEF
   1190  * message \b at that position.
   1191  *
   1192  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1193  *                    component context structure.
   1194  *
   1195  * \retval NFCSTATUS_PENDING               The action has been successfully triggered.
   1196  * \retval NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
   1197  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
   1198  * \retval NFCSTATUS_INVALID_PARAMETER     Completion Routine is NULL.
   1199  * \retval NFCSTATUS_INVALID_REMOTE_DEVICE OpModes invalid.
   1200  * \retval NFCSTATUS_INVALID_DEVICE        The device has not been opened or has been disconnected
   1201  *                                         meanwhile.
   1202  * \retval NFCSTATUS_CMD_ABORTED           The caller/driver has aborted the request.
   1203  * \retval NFCSTATUS_BUFFER_TOO_SMALL      The buffer provided by the caller is too small.
   1204  * \retval NFCSTATUS_RF_TIMEOUT            No data has been received within the TIMEOUT period.
   1205  *
   1206  */
   1207 NFCSTATUS phFriNfc_NdefMap_EraseNdef(phFriNfc_NdefMap_t *NdefMap);
   1208 
   1209 /**
   1210  * \ingroup grp_fri_nfc_ndef_map
   1211  *
   1212  * \brief Ndef Mapping \b Get Container size function
   1213  *
   1214  * \copydoc page_ovr Returns the size of the NDEF data that the card can hold to the caller.
   1215  *
   1216  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1217  *                    component context structure.
   1218  *
   1219  * \param[out] size Pointer to a uint32_t variable, which receives the size of the NDEF data
   1220  *
   1221  * \retval  NFCSTATUS_SUCCESS               The size has been successfully calculated.
   1222  * \retval  NFCSTATUS_INVALID_PARAMETER     At least one parameter of the function is invalid.
   1223  * \retval  NFCSTATUS_INVALID_REMOTE_DEVICE          Card Type is unsupported.
   1224  *
   1225  */
   1226 
   1227 NFCSTATUS phFriNfc_NdefMap_GetContainerSize(const phFriNfc_NdefMap_t *NdefMap,uint32_t *maxSize, uint32_t *actualSize);
   1228 
   1229 /**
   1230  * \ingroup grp_fri_nfc_ndef_map
   1231  *
   1232  * \brief Ndef Mapping \b Completion \b Routine or \b Process function
   1233  *
   1234  * \copydoc page_cb Completion Routine: This function is called by the lower layer (OVR HAL)
   1235  *                  when an I/O operation has finished. The internal state machine decides
   1236  *                  whether to call into the lower device again or to complete the process
   1237  *                  by calling into the upper layer's completion routine, stored within this
   1238  *                  component's context (\ref phFriNfc_NdefMap_t).
   1239  *
   1240  * The function call scheme is according to \ref grp_interact. No State reset is performed during
   1241  * operation.
   1242  *
   1243  * \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
   1244  *            calling layer, upon its completion.
   1245  * \param[in] Status  The completion status of the lower layer (to be handled by the implementation of
   1246  *                    the state machine of this function like a regular return value of an internally
   1247  *                    called function).
   1248  *
   1249  * \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
   1250  *
   1251  */
   1252 void phFriNfc_NdefMap_Process(void        *Context,
   1253                               NFCSTATUS   Status);
   1254 
   1255 
   1256 
   1257 /**
   1258  * \ingroup grp_fri_nfc_ndef_map
   1259  *
   1260  * \brief Ndef Mapping \b Check And Parse TLV Structure \b NDEF function
   1261  *
   1262  * \copydoc page_ovr Checks the presence of a valid TLV's(NDEF/Propritery).
   1263  *
   1264  * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t
   1265  *                    component context structure.
   1266  *
   1267  * \retval NFCSTATUS_INVALID_FORMAT         No valid TLV Found.
   1268  * \retval NFCSTATUS_SUCCESS                Operation Successful.
   1269  *
   1270  */
   1271 NFCSTATUS phFriNfc_ChkAndParseTLV(phFriNfc_NdefMap_t    *NdefMap);
   1272 
   1273 
   1274 #ifdef PHFRINFC_OVRHAL_MOCKUP  /* */
   1275 
   1276 /**
   1277  * \ingroup grp_fri_nfc_ndef_map
   1278  *
   1279  * \brief Set data NDEF in mockup mode
   1280  *
   1281  * \param[in]       NdefMap          Pointer to a valid instance of the \ref phFriNfc_NdefMap_t component context structure.
   1282  * \param[in]       NdefData         Pointer to card mockup data
   1283  * \param[in]       NdefActualSize    The actual data length
   1284  * \param[in]       NdefMaxSize       The max data length
   1285  * \param[in]       NdefCardSize     The total card size
   1286  *
   1287  * \retval NFCSTATUS_SUCCESS          The operation is ok.
   1288  *
   1289  */
   1290 NFCSTATUS phFriNfc_NdefMap_MockupCardSetter(phFriNfc_NdefMap_t *NdefMap, uint8_t *NdefData, uint32_t NdefActualSize, uint32_t NdefMaxSize, uint32_t CardSize);
   1291 NFCSTATUS phFriNfc_NdefMap_MockupNDefModeEn(uint8_t  *pNdefCompliancy, uint8_t  *pCardType, uint8_t Enable);
   1292 #endif /*#ifndef PH_FRINFC_MAP_MOCKUP_DISABLED*/
   1293 
   1294 
   1295 /**
   1296  * \internal
   1297  * \name States of the FSM.
   1298  *
   1299  */
   1300 /*@{*/
   1301 #define PH_FRINFC_NDEFMAP_STATE_RESET_INIT                  0   /**< \internal Initial state */
   1302 #define PH_FRINFC_NDEFMAP_STATE_CR_REGISTERED               1   /**< \internal CR has been registered */
   1303 #define PH_FRINFC_NDEFMAP_STATE_EOF_CARD                    2   /**< \internal EOF card reached */
   1304 /*@}*/
   1305 
   1306 /* Following values specify the previous operation on the card. This value is assigned to
   1307    the context structure variable: PrevOperation. */
   1308 
   1309 /**< Previous operation is check*/
   1310 #define PH_FRINFC_NDEFMAP_CHECK_OPE                         1
   1311 /**< Previous operation is read*/
   1312 #define PH_FRINFC_NDEFMAP_READ_OPE                          2
   1313 /**< Previous operation is write */
   1314 #define PH_FRINFC_NDEFMAP_WRITE_OPE                         3
   1315 /**< Previous operation is Actual size */
   1316 #define PH_FRINFC_NDEFMAP_GET_ACTSIZE_OPE                   4
   1317 
   1318 /* This flag is set when there is a need of write operation on the odd positions
   1319    ex: 35,5 etc. This is used with MfUlOp Flag */
   1320 #define PH_FRINFC_MFUL_INTERNAL_READ                        3  /**< \internal Read/Write control*/
   1321 
   1322 
   1323 #endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
   1324 
   1325 #endif /* PHFRINFC_NDEFMAP_H */
   1326