Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 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_MifareULMap.h |
| 19 | * \brief NFC Ndef Mapping For Mifare UL Card. |
| 20 | * |
| 21 | * Project: NFC-FRI |
| 22 | * |
| 23 | * $Date: Fri Aug 7 13:06:49 2009 $ |
| 24 | * $Author: ing07336 $ |
| 25 | * $Revision: 1.9 $ |
| 26 | * $Aliases: NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $ |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #ifndef PHFRINFC_MIFAREULMAP_H |
| 31 | #define PHFRINFC_MIFAREULMAP_H |
| 32 | |
| 33 | #include <phFriNfc.h> |
| 34 | #if !defined PH_HAL4_ENABLE |
| 35 | #include <phHal4Nfc.h> |
| 36 | #endif |
| 37 | #include <phNfcStatus.h> |
| 38 | #include <phNfcTypes.h> |
| 39 | #include <phFriNfc_NdefMap.h> |
| 40 | |
| 41 | #define PH_FRINFC_NDEFMAP_MIFAREMAP_FILEREVISION "$Revision: 1.9 $" |
| 42 | #define PH_FRINFC_NDEFMAP_MIFAREMAP_FILEALIASES "$Aliases: NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $" |
| 43 | |
| 44 | |
| 45 | /*! |
| 46 | * \name Mifare UL - states of the Finite State machine |
| 47 | * |
| 48 | */ |
| 49 | /*@{*/ |
| 50 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_READ 1 /*!< Read State */ |
| 51 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_WRITE 2 /*!< Write is going on*/ |
| 52 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_CHK_NDEF_COMP 3 /*!< Check Ndef is going on */ |
| 53 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_FND_NDEF_COMP 4 /*!< to find the NDEF TLV */ |
| 54 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_TERM_TLV 5 /*!< to write the terminator TLV */ |
| 55 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_WR_LEN_TLV 6 /*!< Write L value of TLV */ |
| 56 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_CHK_1 7 /*!< to send sector select command 1 */ |
| 57 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_CHK_2 8 /*!< to send sector select command 2 */ |
| 58 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_RESET_1 9 /*!< to send sector select command 1 for resetting sector 0 */ |
| 59 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_RESET_2 10 /*!< to send sector select command 2 for resetting sector 0 */ |
| 60 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_READ_1 11 /*!< to send sector select command 1 for resetting sector 0 */ |
| 61 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_READ_2 12 /*!< to send sector select command 2 for resetting sector 0 */ |
| 62 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_WRITE_1 13 /*!< to send sector select command 1 for resetting sector 0 */ |
| 63 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_WRITE_2 14 /*!< to send sector select command 2 for resetting sector 0 */ |
| 64 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_RW_1 15 /*!< to send sector select command 1 for resetting sector 0 */ |
| 65 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_RW_2 16 /*!< to send sector select command 2 for resetting sector 0 */ |
| 66 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_WRITE_INIT_1 17 /*!< to send sector select command 1 for resetting sector 0 */ |
| 67 | #define PH_FRINFC_NDEFMAP_MFUL_STATE_SELECT_SECTOR_WRITE_INIT_2 18 /*!< to send sector select command 2 for resetting sector 0 */ |
| 68 | |
| 69 | |
| 70 | /*@}*/ |
| 71 | |
| 72 | /*! |
| 73 | * \name Mifare - constants for the capability container |
| 74 | * |
| 75 | */ |
| 76 | /*@{*/ |
| 77 | #define PH_FRINFC_NDEFMAP_MFUL_CC_BYTE0 0xE1 /*!< Capability container byte 0 = 0xE1 */ |
| 78 | #define PH_FRINFC_NDEFMAP_MFUL_CC_BYTE1 0x10 /*!< Capability container byte 1 = 0x10 */ |
| 79 | #define PH_FRINFC_NDEFMAP_MFUL_CC_BYTE2 0x06 /*!< Capability container byte 2 = 0x06 */ |
| 80 | #define PH_FRINFC_NDEFMAP_MFUL_CC_BYTE3_RW 0x00 /*!< Capability container byte 3 = 0x00 for |
| 81 | READ WRITE/INITIALISED card state*/ |
| 82 | #define PH_FRINFC_NDEFMAP_MFUL_CC_BYTE3_RO 0x0F /*!< Capability container byte 3 = 0x0F for |
| 83 | READ only card state*/ |
| 84 | /*@}*/ |
| 85 | |
| 86 | /*! |
| 87 | * \name Mifare - constants for Flags |
| 88 | * |
| 89 | */ |
| 90 | /*@{*/ |
| 91 | #define PH_FRINFC_NDEFMAP_MFUL_FLAG0 0 /*!< Flag value = 0 */ |
| 92 | #define PH_FRINFC_NDEFMAP_MFUL_FLAG1 1 /*!< Flag value = 1 */ |
| 93 | /*@}*/ |
| 94 | |
| 95 | /*! |
| 96 | * \name Mifare - constants for left shift |
| 97 | * |
| 98 | */ |
| 99 | /*@{*/ |
| 100 | #define PH_FRINFC_NDEFMAP_MFUL_SHIFT8 8 /*!< Flag value = 0 */ |
| 101 | /*@}*/ |
| 102 | |
| 103 | /*! |
| 104 | * \name Mifare - TLV related constants |
| 105 | * |
| 106 | */ |
| 107 | /*@{*/ |
| 108 | #define PH_FRINFC_NDEFMAP_MFUL_NDEFTLV_T 0x03 /*!< Type value of TLV = 0x03 */ |
| 109 | #define PH_FRINFC_NDEFMAP_MFUL_NDEFTLV_L 0x00 /*!< Length value of TLV = 0x00 */ |
| 110 | #define PH_FRINFC_NDEFMAP_MFUL_NDEFTLV_LFF 0xFF /*!< Length value of TLV = 0xFF */ |
| 111 | #define PH_FRINFC_NDEFMAP_MFUL_TERMTLV 0xFE /*!< Terminator TLV value = 0xFE */ |
| 112 | #define PH_FRINFC_NDEFMAP_MFUL_NULLTLV 0x00 /*!< Null TLV value = 0x00 */ |
| 113 | #define PH_FRINFC_NDEFMAP_MFUL_LOCK_CTRL_TLV 0x01 /*!< Lock Control TLV value = 0x01 */ |
| 114 | #define PH_FRINFC_NDEFMAP_MFUL_MEM_CTRL_TLV 0x02 /*!< Memory Control TVL value = 0x02 */ |
| 115 | #define PH_FRINFC_NDEFMAP_MFUL_PROPRIETRY_TLV 0xFD /*!< Proprietry TVL value = 0xFD */ |
| 116 | |
| 117 | |
| 118 | /*@}*/ |
| 119 | |
| 120 | |
| 121 | /*! |
| 122 | * \name Mifare - Standard constants |
| 123 | * |
| 124 | */ |
| 125 | /*@{*/ |
| 126 | #define PH_FRINFC_NDEFMAP_MFUL_WR_A_BLK 0x05 /*!< Send Length for Write Ndef */ |
| 127 | #define PH_FRINFC_NDEFMAP_MFUL_MAX_SEND_BUF_TO_READ 0x01 /*!< Send Length for Read Ndef */ |
| 128 | #define PH_FRINFC_NDEFMAP_MFUL_CHECK_RESP 0x04 /*!< Value of the Sense Response for Mifare UL */ |
| 129 | #define PH_FRINFC_NDEFMAP_MFUL_OTP_OFFSET 3 /*!< To initialise the Offset */ |
| 130 | #define PH_FRINFC_NDEFMAP_MFUL_MUL8 8 /*!< Multiply by 8 */ |
| 131 | #define PH_FRINFC_NDEFMAP_MFUL_VAL0 0 /*!< Value 0 */ |
| 132 | #define PH_FRINFC_NDEFMAP_MFUL_VAL1 1 /*!< Value 1 */ |
| 133 | #define PH_FRINFC_NDEFMAP_MFUL_VAL2 2 /*!< Value 2 */ |
| 134 | #define PH_FRINFC_NDEFMAP_MFUL_VAL3 3 /*!< Value 3 */ |
| 135 | #define PH_FRINFC_NDEFMAP_MFUL_VAL4 4 /*!< Value 4 */ |
| 136 | #define PH_FRINFC_NDEFMAP_MFUL_VAL5 5 /*!< Value 5 */ |
| 137 | #define PH_FRINFC_NDEFMAP_MFUL_VAL64 64 /*!< Value 64 */ |
| 138 | #define PH_FRINFC_NDEFMAP_MFUL_BYTE0 0x00 /*!< Byte number 0 */ |
| 139 | #define PH_FRINFC_NDEFMAP_MFUL_BYTE1 0x01 /*!< Byte number 1 */ |
| 140 | #define PH_FRINFC_NDEFMAP_MFUL_BYTE2 0x02 /*!< Byte number 2 */ |
| 141 | #define PH_FRINFC_NDEFMAP_MFUL_BYTE3 0x03 /*!< Byte number 3 */ |
| 142 | #define PH_FRINFC_NDEFMAP_MFUL_BYTE4 0x04 /*!< Byte number 4 */ |
| 143 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK0 0x00 /*!< Block number 0 */ |
| 144 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK1 0x01 /*!< Block number 1 */ |
| 145 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK2 0x02 /*!< Block number 2 */ |
| 146 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK3 0x03 /*!< Block number 3 */ |
| 147 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK4 0x04 /*!< Block number 4 */ |
| 148 | #define PH_FRINFC_NDEFMAP_MFUL_BLOCK5 0x05 /*!< Block number 5 */ |
| 149 | |
| 150 | #define PH_FRINFC_NDEFMAP_MFUL_RDBYTES_16 0x10 /*!< Read Bytes 16 */ |
| 151 | #define PH_FRINFC_NDEFMAP_STMFUL_MAX_CARD_SZ 48 /*!< For static maximum memory size is 48 bytes */ |
| 152 | #define PH_FRINFC_NDEFMAP_MFUL_WR_BUF_STR 0x04 /*!< To store the block of data written to the card */ |
| 153 | /*@}*/ |
| 154 | |
| 155 | /*! |
| 156 | * \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about |
| 157 | * the list of registered items. Moreover, the lower device is set. |
| 158 | * |
| 159 | * \param[in] NdefMap Pointer to a valid or uninitialised instance of \ref phFriNfc_NdefMap_t . |
| 160 | * |
| 161 | * \note This function has to be called at the beginning, after creating an instance of |
| 162 | * \ref phFriNfc_NdefMap_t . Use this function to reset the instance and/or switch |
| 163 | * to a different underlying device (different NFC device or device mode, or different |
| 164 | * Remote Device). |
| 165 | */ |
| 166 | NFCSTATUS phFriNfc_MifareUL_H_Reset( phFriNfc_NdefMap_t *NdefMap); |
| 167 | |
| 168 | /*! |
| 169 | * \brief \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device. |
| 170 | * |
| 171 | * The function initiates the reading of NDEF information from a Remote Device. |
| 172 | * It performs a reset of the state and starts the action (state machine). |
| 173 | * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action |
| 174 | * has been triggered. |
| 175 | * |
| 176 | * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing |
| 177 | * the component context. |
| 178 | * |
| 179 | * \param[in] PacketData Pointer to a location that receives the NDEF Packet. |
| 180 | * |
| 181 | * \param[in,out] PacketDataLength Pointer to a variable receiving the length of the NDEF packet. |
| 182 | * |
| 183 | * \param[in] Offset Indicates whether the read operation shall start from the begining of the |
| 184 | * file/card storage \b or continue from the last offset. The last Offset set is stored |
| 185 | * within a context variable (must not be modified by the integration). |
| 186 | * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall |
| 187 | * start reading from the last offset set (continue where it has stopped before). |
| 188 | * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading |
| 189 | * from the begining of the card (restarted) |
| 190 | * |
| 191 | * \retval NFCSTATUS_PENDING The action has been successfully triggered. |
| 192 | * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset |
| 193 | * is Current then this error is displayed. |
| 194 | * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED No Space in the File to read. |
| 195 | * \retval NFCSTATUS_MORE_INFORMATION There are more bytes to read in the card. |
| 196 | * \retval NFCSTATUS_SUCCESS Last Byte of the card read. |
| 197 | * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected |
| 198 | * meanwhile. |
| 199 | * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request. |
| 200 | * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small. |
| 201 | * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period. |
| 202 | * |
| 203 | */ |
| 204 | |
| 205 | NFCSTATUS phFriNfc_MifareUL_RdNdef( phFriNfc_NdefMap_t *NdefMap, |
| 206 | uint8_t *PacketData, |
| 207 | uint32_t *PacketDataLength, |
| 208 | uint8_t Offset); |
| 209 | |
| 210 | /*! |
| 211 | * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device. |
| 212 | * |
| 213 | * The function initiates the writing of NDEF information to a Remote Device. |
| 214 | * It performs a reset of the state and starts the action (state machine). |
| 215 | * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action |
| 216 | * has been triggered. |
| 217 | * |
| 218 | * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing |
| 219 | * the component context. |
| 220 | * |
| 221 | * \param[in] PacketData Pointer to a location that holds the prepared NDEF Packet. |
| 222 | * |
| 223 | * \param[in,out] PacketDataLength Variable specifying the length of the prepared NDEF packet. |
| 224 | * |
| 225 | * \param[in] Offset Indicates whether the write operation shall start from the begining of the |
| 226 | * file/card storage \b or continue from the last offset. The last Offset set is stored |
| 227 | * within a context variable (must not be modified by the integration). |
| 228 | * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall |
| 229 | * start writing from the last offset set (continue where it has stopped before). |
| 230 | * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing |
| 231 | * from the begining of the card (restarted) |
| 232 | * |
| 233 | * \retval NFCSTATUS_PENDING The action has been successfully triggered. |
| 234 | * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset |
| 235 | * is Current then this error is displayed. |
| 236 | * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED Last byte is written to the card after this |
| 237 | * no further writing is possible. |
| 238 | * \retval NFCSTATUS_SUCCESS Buffer provided by the user is completely written |
| 239 | * into the card. |
| 240 | * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected |
| 241 | * meanwhile. |
| 242 | * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request. |
| 243 | * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small. |
| 244 | * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period. |
| 245 | * |
| 246 | */ |
| 247 | |
| 248 | NFCSTATUS phFriNfc_MifareUL_WrNdef( phFriNfc_NdefMap_t *NdefMap, |
| 249 | uint8_t *PacketData, |
| 250 | uint32_t *PacketDataLength, |
| 251 | uint8_t Offset); |
| 252 | |
| 253 | /*! |
| 254 | * \brief \copydoc page_ovr Check whether a particulat Remote Device is NDEF compliant. |
| 255 | * |
| 256 | * The function checks whether the peer device is NDEF compliant. |
| 257 | * |
| 258 | * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing |
| 259 | * the component context. |
| 260 | * |
| 261 | * \retval NFCSTATUS_PENDING The action has been successfully triggered. |
| 262 | * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid. |
| 263 | * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected |
| 264 | * meanwhile. |
| 265 | * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request. |
| 266 | * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small. |
| 267 | * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period. |
| 268 | * |
| 269 | */ |
| 270 | |
| 271 | NFCSTATUS phFriNfc_MifareUL_ChkNdef( phFriNfc_NdefMap_t *NdefMap); |
| 272 | |
| 273 | /*! |
| 274 | * \brief \copydoc page_cb Completion Routine, Processing function, needed to avoid long blocking. |
| 275 | * |
| 276 | * The function call scheme is according to \ref grp_interact. No State reset is performed during operation. |
| 277 | * |
| 278 | * \copydoc pphFriNfc_Cr_t |
| 279 | * |
| 280 | * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion |
| 281 | * Routine in order to be able to notify the component that an I/O has finished and data are |
| 282 | * ready to be processed. |
| 283 | * |
| 284 | */ |
| 285 | |
| 286 | void phFriNfc_MifareUL_Process( void *Context, |
| 287 | NFCSTATUS Status); |
| 288 | |
| 289 | |
| 290 | #endif /* PHFRINFC_MIFAREULMAP_H */ |