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_SmtCrdFmt.c |
| 19 | * \brief This component encapsulates different smart and simple tag formatting functionalities, |
| 20 | * for the mapping layer. |
| 21 | * |
| 22 | * Project: NFC-FRI |
| 23 | * |
Martijn Coenen | 4f3ef02 | 2011-01-20 01:27:17 +0100 | [diff] [blame] | 24 | * $Date: Mon Dec 13 14:14:13 2010 $ |
| 25 | * $Author: ing02260 $ |
| 26 | * $Revision: 1.9 $ |
| 27 | * $Aliases: $ |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 28 | * |
| 29 | */ |
| 30 | |
| 31 | #ifndef PH_FRINFC_CARD_FORMAT_DISABLED |
| 32 | |
| 33 | #include <phNfcTypes.h> |
| 34 | #include <phFriNfc_OvrHal.h> |
| 35 | #include <phFriNfc_SmtCrdFmt.h> |
| 36 | #ifdef DISABLE_FORMAT |
| 37 | #include <phFriNfc_TopazFormat.h> |
| 38 | #endif /* #ifdef DISABLE_FORMAT */ |
| 39 | #include <phFriNfc_MifULFormat.h> |
| 40 | #include <phFriNfc_DesfireFormat.h> |
| 41 | #include <phFriNfc_MifStdFormat.h> |
Martijn Coenen | 4f3ef02 | 2011-01-20 01:27:17 +0100 | [diff] [blame] | 42 | #ifndef PH_FRINFC_FMT_ISO15693_DISABLED |
| 43 | #include <phFriNfc_ISO15693Format.h> |
| 44 | #endif /* #ifndef PH_FRINFC_FMT_ISO15693_DISABLED */ |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 45 | |
| 46 | |
| 47 | /*! \ingroup grp_file_attributes |
| 48 | * \name NDEF Mapping |
| 49 | * |
| 50 | * File: \ref phFriNfc_CardFormatFunctions.c |
| 51 | * |
| 52 | */ |
| 53 | /*@{*/ |
| 54 | // file versions |
| 55 | /*@}*/ |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | void phFriNfc_SmtCrdFmt_HCrHandler(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, |
| 61 | NFCSTATUS Status) |
| 62 | { |
| 63 | /* set the state back to the Reset_Init state*/ |
| 64 | NdefSmtCrdFmt->State = PH_FRINFC_SMTCRDFMT_STATE_RESET_INIT; |
| 65 | |
| 66 | /* set the completion routine*/ |
| 67 | NdefSmtCrdFmt->CompletionRoutine[PH_FRINFC_SMTCRDFMT_CR_FORMAT]. |
| 68 | CompletionRoutine(NdefSmtCrdFmt->CompletionRoutine->Context, Status); |
| 69 | } |
| 70 | |
| 71 | /*! |
| 72 | * \brief Used to Reset the context variables , before the actual smart card formatting |
| 73 | * procedure. |
| 74 | * |
| 75 | */ |
| 76 | NFCSTATUS phFriNfc_NdefSmtCrd_Reset(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, |
| 77 | void *LowerDevice, |
| 78 | phHal_sRemoteDevInformation_t *psRemoteDevInfo, |
| 79 | phHal_sDevInputParam_t *psDevInputParam, |
| 80 | uint8_t *SendRecvBuffer, |
| 81 | uint16_t *SendRecvBuffLen) |
| 82 | { |
| 83 | NFCSTATUS result = NFCSTATUS_SUCCESS; |
| 84 | uint8_t index; |
| 85 | |
| 86 | if ( (SendRecvBuffLen == NULL) || (NdefSmtCrdFmt == NULL) || (psRemoteDevInfo == NULL) || |
| 87 | (SendRecvBuffer == NULL) || (LowerDevice == NULL) || |
| 88 | (*SendRecvBuffLen == 0) || (psDevInputParam == NULL) || |
| 89 | (*SendRecvBuffLen < PH_FRINFC_SMTCRDFMT_MAX_SEND_RECV_BUF_SIZE) ) |
| 90 | { |
| 91 | result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, NFCSTATUS_INVALID_PARAMETER); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | /* Initialise the state to Init */ |
| 96 | NdefSmtCrdFmt->State = PH_FRINFC_SMTCRDFMT_STATE_RESET_INIT; |
| 97 | |
| 98 | for(index = 0;index<PH_FRINFC_SMTCRDFMT_CR;index++) |
| 99 | { |
| 100 | /* Initialise the NdefMap Completion Routine to Null */ |
| 101 | NdefSmtCrdFmt->CompletionRoutine[index].CompletionRoutine = NULL; |
| 102 | /* Initialise the NdefMap Completion Routine context to Null */ |
| 103 | NdefSmtCrdFmt->CompletionRoutine[index].Context = NULL; |
| 104 | } |
| 105 | |
| 106 | /* Lower Device(Always Overlapped HAL Struct initialised in application |
| 107 | is registred in NdefMap Lower Device) */ |
| 108 | NdefSmtCrdFmt->LowerDevice = LowerDevice; |
| 109 | |
| 110 | /* Remote Device info received from Manual Device Discovery is registered here */ |
| 111 | NdefSmtCrdFmt->psRemoteDevInfo = psRemoteDevInfo; |
| 112 | |
| 113 | /* Trx Buffer registered */ |
| 114 | NdefSmtCrdFmt->SendRecvBuf = SendRecvBuffer; |
| 115 | |
| 116 | /* Trx Buffer Size */ |
| 117 | NdefSmtCrdFmt->SendRecvLength = SendRecvBuffLen; |
| 118 | |
| 119 | /* Register Transfer Buffer Length */ |
| 120 | NdefSmtCrdFmt->SendLength = 0; |
| 121 | |
| 122 | /* Initialise the Format status flag*/ |
| 123 | NdefSmtCrdFmt->FmtProcStatus = 0; |
| 124 | |
| 125 | /* Reset the Card Type */ |
| 126 | NdefSmtCrdFmt->CardType = 0; |
| 127 | |
| 128 | /* Reset MapCompletion Info*/ |
| 129 | NdefSmtCrdFmt->SmtCrdFmtCompletionInfo.CompletionRoutine = NULL; |
| 130 | NdefSmtCrdFmt->SmtCrdFmtCompletionInfo.Context = NULL; |
| 131 | |
| 132 | #ifndef PH_FRINFC_FMT_TOPAZ_DISABLED |
| 133 | phFriNfc_Topaz_Reset(NdefSmtCrdFmt); |
| 134 | |
| 135 | #endif /* PH_FRINFC_FMT_TOPAZ_DISABLED */ |
| 136 | |
| 137 | #ifndef PH_FRINFC_FMT_DESFIRE_DISABLED |
| 138 | /*Reset Desfire Cap Container elements*/ |
| 139 | phFriNfc_Desfire_Reset(NdefSmtCrdFmt); |
| 140 | #endif /* PH_FRINFC_FMT_DESFIRE_DISABLED */ |
| 141 | |
| 142 | #ifndef PH_FRINFC_FMT_MIFARESTD_DISABLED |
| 143 | /*Reset Mifare Standard Container elements*/ |
| 144 | NdefSmtCrdFmt->AddInfo.MfStdInfo.DevInputParam = psDevInputParam; |
| 145 | phFriNfc_MfStd_Reset(NdefSmtCrdFmt); |
| 146 | #endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */ |
| 147 | |
| 148 | #ifndef PH_FRINFC_FMT_MIFAREUL_DISABLED |
| 149 | phFriNfc_MfUL_Reset(NdefSmtCrdFmt); |
| 150 | #endif /* #ifndef PH_FRINFC_FMT_MIFAREUL_DISABLED */ |
| 151 | |
Martijn Coenen | 4f3ef02 | 2011-01-20 01:27:17 +0100 | [diff] [blame] | 152 | #ifndef PH_FRINFC_FMT_ISO15693_DISABLED |
| 153 | phFriNfc_ISO15693_FmtReset (NdefSmtCrdFmt); |
| 154 | #endif /* #ifndef PH_FRINFC_FMT_ISO15693_DISABLED */ |
| 155 | |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 156 | #ifdef PHFRINFC_OVRHAL_MOCKUP |
| 157 | /*Reset Desfire Cap Container elements*/ |
| 158 | // phFriNfc_Mockup_H_Reset(NdefSmtCrdFmt); |
| 159 | #endif /* PHFRINFC_OVRHAL_MOCKUP */ |
| 160 | |
| 161 | } |
| 162 | return (result); |
| 163 | |
| 164 | } |
| 165 | |
| 166 | /*! |
| 167 | * \brief Completion Routine initialisation |
| 168 | * |
| 169 | */ |
| 170 | NFCSTATUS phFriNfc_NdefSmtCrd_SetCR(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, |
| 171 | uint8_t FunctionID, |
| 172 | pphFriNfc_Cr_t CompletionRoutine, |
| 173 | void *CompletionRoutineContext) |
| 174 | { |
| 175 | NFCSTATUS status = NFCSTATUS_SUCCESS; |
| 176 | |
| 177 | if ((NdefSmtCrdFmt == NULL) || (FunctionID >= PH_FRINFC_SMTCRDFMT_CR) || |
| 178 | (CompletionRoutine == NULL) || (CompletionRoutineContext == NULL)) |
| 179 | { |
| 180 | status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, NFCSTATUS_INVALID_PARAMETER); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | /* Register the application callback with the NdefMap Completion Routine */ |
| 185 | NdefSmtCrdFmt->CompletionRoutine[FunctionID].CompletionRoutine = CompletionRoutine; |
| 186 | |
| 187 | /* Register the application context with the NdefMap Completion Routine context */ |
| 188 | NdefSmtCrdFmt->CompletionRoutine[FunctionID].Context = CompletionRoutineContext; |
| 189 | } |
| 190 | |
| 191 | return status; |
| 192 | } |
| 193 | |
Martijn Coenen | 80ee29b | 2010-12-16 23:24:55 +0100 | [diff] [blame] | 194 | #ifdef FRINFC_READONLY_NDEF |
| 195 | |
| 196 | NFCSTATUS |
| 197 | phFriNfc_NdefSmtCrd_ConvertToReadOnly ( |
| 198 | phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt) |
| 199 | { |
| 200 | NFCSTATUS result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 201 | NFCSTATUS_INVALID_PARAMETER); |
| 202 | uint8_t sak = 0; |
| 203 | |
| 204 | if((NdefSmtCrdFmt != NULL) |
| 205 | && (NdefSmtCrdFmt->CompletionRoutine->CompletionRoutine != NULL) |
| 206 | && (NdefSmtCrdFmt->CompletionRoutine->Context != NULL)) |
| 207 | { |
| 208 | sak = NdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak; |
| 209 | switch (NdefSmtCrdFmt->psRemoteDevInfo->RemDevType) |
| 210 | { |
| 211 | case phHal_eMifare_PICC: |
| 212 | { |
| 213 | if (0x00 == sak) |
| 214 | { |
| 215 | result = phFriNfc_MfUL_ConvertToReadOnly (NdefSmtCrdFmt); |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | /* MIFARE classic 1k/4k is not supported */ |
| 220 | result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 221 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 222 | } |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | case phHal_eISO14443_A_PICC: |
| 227 | { |
| 228 | result = phFriNfc_Desfire_ConvertToReadOnly (NdefSmtCrdFmt); |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | default : |
| 233 | { |
| 234 | /* Remote device is not recognised. |
| 235 | Probably not NDEF compliant */ |
| 236 | result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 237 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | return result; |
| 243 | } |
| 244 | |
| 245 | #endif /* #ifdef FRINFC_READONLY_NDEF */ |
| 246 | |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 247 | |
| 248 | /*! |
| 249 | * \brief Used to format the different smart cards. |
| 250 | * |
| 251 | */ |
| 252 | NFCSTATUS phFriNfc_NdefSmtCrd_Format( phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt, const uint8_t *ScrtKeyB ) |
| 253 | { |
| 254 | /* Component ID needs to be changed */ |
| 255 | NFCSTATUS Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 256 | NFCSTATUS_INVALID_PARAMETER); |
| 257 | uint8_t sak = 0; |
| 258 | |
| 259 | /* Check for the correct context structure */ |
| 260 | if((NdefSmtCrdFmt != NULL) && |
| 261 | (NdefSmtCrdFmt->CompletionRoutine->CompletionRoutine != NULL) && |
| 262 | (NdefSmtCrdFmt->CompletionRoutine->Context != NULL)) |
| 263 | { |
| 264 | #ifdef PH_HAL4_ENABLE |
| 265 | /* SAK (Select response) */ |
| 266 | sak = NdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak; |
| 267 | |
| 268 | /* Depending on the Opmodes, call the respective card functions */ |
| 269 | switch ( NdefSmtCrdFmt->psRemoteDevInfo->RemDevType ) |
| 270 | #else |
| 271 | /* SAK (Select response) */ |
| 272 | sak = NdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.CardInfo106. |
| 273 | Startup106.SelRes; |
| 274 | |
| 275 | /* Depending on the Opmodes, call the respective card functions */ |
| 276 | switch ( NdefSmtCrdFmt->psRemoteDevInfo->OpMode ) |
| 277 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 278 | { |
| 279 | #ifdef PH_HAL4_ENABLE |
| 280 | case phHal_eMifare_PICC : |
| 281 | #else |
| 282 | case phHal_eOpModesMifare : |
| 283 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 284 | /* Remote device is Mifare card . Check for Mifare |
| 285 | NDEF compliance */ |
| 286 | if(0x00 == sak) |
| 287 | { |
| 288 | #ifndef PH_FRINFC_FMT_MIFAREUL_DISABLED |
| 289 | /* The SAK/Sel_Res says the card is of the type |
| 290 | Mifare UL */ |
| 291 | NdefSmtCrdFmt->CardType = PH_FRINFC_SMTCRDFMT_MIFARE_UL_CARD; |
| 292 | if (NdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.UidLength == 7 && |
| 293 | NdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Uid[0] == 0x04) |
| 294 | { |
| 295 | |
| 296 | Result = phFriNfc_MfUL_Format( NdefSmtCrdFmt); |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 301 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 302 | } |
| 303 | #else |
| 304 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 305 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 306 | #endif /* #ifndef PH_FRINFC_FMT_MIFAREUL_DISABLED */ |
| 307 | } |
| 308 | else if((0x08 == (sak & 0x18)) || |
Sunil Jogi | eb6da80 | 2011-11-23 15:06:27 -0800 | [diff] [blame] | 309 | (0x18 == (sak & 0x18)) || |
| 310 | (0x01 == sak)) |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 311 | { |
| 312 | #ifndef PH_FRINFC_FMT_MIFARESTD_DISABLED |
| 313 | NdefSmtCrdFmt->CardType = (uint8_t) |
| 314 | (((sak & 0x18) == 0x08)? |
| 315 | PH_FRINFC_SMTCRDFMT_MFSTD_1K_CRD: |
| 316 | PH_FRINFC_SMTCRDFMT_MFSTD_4K_CRD); |
| 317 | |
| 318 | /* The SAK/Sel_Res says the card is of the type |
| 319 | Mifare standard */ |
| 320 | Result = phFriNfc_MfStd_Format( NdefSmtCrdFmt, ScrtKeyB); |
| 321 | #else |
| 322 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 323 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 324 | #endif /* #ifndef PH_FRINFC_FMT_MIFARESTD_DISABLED */ |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | /* Invalid Mifare card, as the remote device |
| 329 | info - opmode says its a Mifare card but, |
| 330 | The SAK/Sel_Res is wrong */ |
| 331 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 332 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 333 | } |
| 334 | break; |
| 335 | #ifdef PH_HAL4_ENABLE |
| 336 | case phHal_eISO14443_A_PICC : |
| 337 | #else |
| 338 | case phHal_eOpModesISO14443_4A : |
| 339 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 340 | /* Remote device is Desfire card . Check for Desfire |
| 341 | NDEF compliancy */ |
| 342 | if(0x20 == (sak & 0xFF)) |
| 343 | { |
| 344 | #ifndef PH_FRINFC_FMT_DESFIRE_DISABLED |
| 345 | NdefSmtCrdFmt->CardType = PH_FRINFC_SMTCRDFMT_ISO14443_4A_CARD; |
| 346 | /* The SAK/Sel_Res says the card is of the type |
| 347 | ISO14443_4A */ |
| 348 | |
| 349 | Result = phFriNfc_Desfire_Format(NdefSmtCrdFmt); |
| 350 | #else |
| 351 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 352 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 353 | #endif /* #ifndef PH_FRINFC_FMT_DESFIRE_DISABLED */ |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | /* Invalid Desfire card, as the remote device |
| 358 | info - opmode says its a desfire card but, |
| 359 | The SAK/Sel_Res is wrong */ |
| 360 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 361 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 362 | } |
| 363 | break; |
| 364 | #ifdef PH_HAL4_ENABLE |
| 365 | case phHal_eJewel_PICC : |
| 366 | #else |
| 367 | case phHal_eOpModesJewel : |
| 368 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 369 | /* Remote device is Topaz card . Check for Topaz |
| 370 | NDEF compliancy */ |
| 371 | if(0xC2 == sak) |
| 372 | { |
| 373 | #ifndef PH_FRINFC_FMT_TOPAZ_DISABLED |
| 374 | NdefSmtCrdFmt->CardType = PH_FRINFC_SMTCRDFMT_TOPAZ_CARD; |
| 375 | /* The SAK/Sel_Res says the card is of the type |
| 376 | ISO14443_4A */ |
| 377 | Result = phFriNfc_Topaz_Format(NdefSmtCrdFmt); |
| 378 | #else |
| 379 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 380 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 381 | #endif /* #ifndef PH_FRINFC_FMT_TOPAZ_DISABLED */ |
| 382 | |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | /* Invalid Topaz card, as the remote device |
| 387 | info - opmode says its a desfire card but, |
| 388 | The SAK/Sel_Res is wrong */ |
| 389 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 390 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 391 | } |
| 392 | break; |
| 393 | |
| 394 | #ifdef PHFRINFC_OVRHAL_MOCKUP |
| 395 | case phHal_eOpModesMockup : |
| 396 | /*Set the OpMode Ttype Flag*/ |
| 397 | NdefSmtCrdFmt->OpModeType[0] = phHal_eOpModesMockup; |
| 398 | NdefSmtCrdFmt->OpModeType[1] = phHal_eOpModesArrayTerminator; |
| 399 | //Result = phFriNfc_Mockup_ChkNdef(NdefSmtCrdFmt); |
| 400 | break; |
| 401 | #endif /* PHFRINFC_OVRHAL_MOCKUP */ |
| 402 | |
Martijn Coenen | 4f3ef02 | 2011-01-20 01:27:17 +0100 | [diff] [blame] | 403 | #ifndef PH_FRINFC_FMT_ISO15693_DISABLED |
| 404 | case phHal_eISO15693_PICC: |
| 405 | { |
| 406 | Result = phFriNfc_ISO15693_Format (NdefSmtCrdFmt); |
| 407 | break; |
| 408 | } |
| 409 | #endif /* #ifndef PH_FRINFC_FMT_ISO15693_DISABLED */ |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 410 | default : |
| 411 | /* Remote device is not recognised. |
| 412 | Probably not NDEF compliant */ |
| 413 | Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 414 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 415 | break; |
| 416 | } |
| 417 | } |
| 418 | return Result; |
| 419 | } |
| 420 | /*! |
| 421 | * \brief Handles different request and responses from the integration layer. |
| 422 | * |
| 423 | */ |
| 424 | void phFriNfc_NdefSmtCrd_Process(void *Context, |
| 425 | NFCSTATUS Status) |
| 426 | { |
| 427 | if ( Context != NULL ) |
| 428 | { |
| 429 | phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt = (phFriNfc_sNdefSmtCrdFmt_t *)Context; |
| 430 | #ifdef PH_HAL4_ENABLE |
| 431 | switch ( NdefSmtCrdFmt->psRemoteDevInfo->RemDevType ) |
| 432 | #else |
| 433 | switch ( NdefSmtCrdFmt->psRemoteDevInfo->OpMode ) |
| 434 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 435 | { |
| 436 | #ifdef PH_HAL4_ENABLE |
| 437 | case phHal_eMifare_PICC : |
| 438 | #else |
| 439 | case phHal_eOpModesMifare : |
| 440 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 441 | if((NdefSmtCrdFmt->CardType == PH_FRINFC_SMTCRDFMT_MFSTD_1K_CRD) || |
| 442 | (NdefSmtCrdFmt->CardType == PH_FRINFC_SMTCRDFMT_MFSTD_4K_CRD)) |
| 443 | { |
| 444 | #ifndef PH_FRINFC_FMT_MIFARESTD_DISABLED |
| 445 | /* Remote device is Mifare Standard card */ |
| 446 | phFriNfc_MfStd_Process(NdefSmtCrdFmt,Status); |
| 447 | |
| 448 | #else /* PH_FRINFC_FMT_MIFARESTD_DISABLED*/ |
| 449 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 450 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 451 | #endif /* PH_FRINFC_FMT_MIFARESTD_DISABLED*/ |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | #ifndef PH_FRINFC_FMT_MIFAREUL_DISABLED |
| 456 | /* Remote device is Mifare UL card */ |
| 457 | phFriNfc_MfUL_Process(NdefSmtCrdFmt,Status); |
| 458 | #else /* PH_FRINFC_FMT_MIFAREUL_DISABLED*/ |
| 459 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 460 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 461 | #endif /* PH_FRINFC_FMT_MIFAREUL_DISABLED*/ |
| 462 | } |
| 463 | break; |
| 464 | |
| 465 | #ifdef PH_HAL4_ENABLE |
| 466 | case phHal_eISO14443_A_PICC : |
| 467 | #else |
| 468 | case phHal_eOpModesISO14443_4A : |
| 469 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 470 | #ifndef PH_FRINFC_FMT_DESFIRE_DISABLED |
| 471 | /* Remote device is Desfire card */ |
| 472 | phFriNfc_Desf_Process(NdefSmtCrdFmt, Status); |
| 473 | #else /* PH_FRINFC_FMT_DESFIRE_DISABLED*/ |
| 474 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 475 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 476 | #endif /* PH_FRINFC_FMT_DESFIRE_DISABLED*/ |
| 477 | break; |
| 478 | #ifdef PH_HAL4_ENABLE |
| 479 | case phHal_eJewel_PICC : |
| 480 | #else |
| 481 | case phHal_eOpModesJewel: |
| 482 | #endif /* #ifdef PH_HAL4_ENABLE */ |
| 483 | #ifndef PH_FRINFC_FMT_TOPAZ_DISABLED |
| 484 | /* Remote device is Topaz Smart card */ |
| 485 | phFriNfc_Topaz_Process(NdefSmtCrdFmt, Status); |
| 486 | #else /* PH_FRINFC_FMT_TOPAZ_DISABLED*/ |
| 487 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 488 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 489 | #endif /* PH_FRINFC_FMT_TOPAZ_DISABLED*/ |
| 490 | break; |
| 491 | |
Martijn Coenen | 4f3ef02 | 2011-01-20 01:27:17 +0100 | [diff] [blame] | 492 | #ifndef PH_FRINFC_FMT_ISO15693_DISABLED |
| 493 | case phHal_eISO15693_PICC : |
| 494 | { |
| 495 | phFriNfc_ISO15693_FmtProcess (NdefSmtCrdFmt, Status); |
| 496 | break; |
| 497 | } |
| 498 | #endif /* #ifndef PH_FRINFC_FMT_ISO15693_DISABLED */ |
| 499 | |
Nick Pelly | 5d9927b | 2010-09-23 12:47:58 -0700 | [diff] [blame] | 500 | #ifdef PHFRINFC_OVRHAL_MOCKUP |
| 501 | case phHal_eOpModesMockup: |
| 502 | /* Remote device is Desfire card */ |
| 503 | //phFriNfc_Mockup_Process(NdefSmtCrdFmt, Status); |
| 504 | break; |
| 505 | #endif /* PHFRINFC_OVRHAL_MOCKUP*/ |
| 506 | default : |
| 507 | /* Remote device opmode not recognised. |
| 508 | Probably not NDEF compliant */ |
| 509 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT, |
| 510 | NFCSTATUS_INVALID_REMOTE_DEVICE); |
| 511 | /* set the state back to the Reset_Init state*/ |
| 512 | NdefSmtCrdFmt->State = PH_FRINFC_SMTCRDFMT_STATE_RESET_INIT; |
| 513 | |
| 514 | /* set the completion routine*/ |
| 515 | NdefSmtCrdFmt->CompletionRoutine[PH_FRINFC_SMTCRDFMT_CR_INVALID_OPE]. |
| 516 | CompletionRoutine(NdefSmtCrdFmt->CompletionRoutine->Context, Status); |
| 517 | break; |
| 518 | } |
| 519 | } |
| 520 | else |
| 521 | { |
| 522 | Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,\ |
| 523 | NFCSTATUS_INVALID_PARAMETER); |
| 524 | /* The control should not come here. As Context itself is NULL , |
| 525 | Can't call the CR*/ |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | #endif /* PH_FRINFC_CARD_FORMAT_DISABLED */ |
| 530 | |