FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3.cpp
Go to the documentation of this file.
00001 /*-----------------------------------------------------------
00002 |                                                                                                                       |
00003 | FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3.cpp       |
00004 |                                                                                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright © 2009-2010   FEIG ELECTRONIC GmbH, All Rights Reserved.
00008                                                 Lange Strasse 4
00009                                                 D-35781 Weilburg
00010                                                 Federal Republic of Germany
00011                                                 phone    : +49 6471 31090
00012                                                 fax      : +49 6471 310999
00013                                                 e-mail   : obid-support@feig.de
00014                                                 Internet : http://www.feig.de
00015                                         
00016 Author                  :       Markus Hultsch
00017 Begin                   :       30.03.2009
00018 
00019 Version                 :       03.02.05 / 08.09.2010 / M. Sahm
00020 
00021 Operation Systems       :       independent
00022 
00023 Function                        :       implementation class for OBID® classic-pro transponder ISO14443-4 MIFARE DESFire
00024 
00025 NOTE                            :       this class supports only selected mode in Host-Mode
00026 
00027 
00028 Trademarks:
00029 -----------
00030 OBID®, OBID i-scan® and OBID myAXXESS® are registered Trademarks of FEIG ELECTRONIC GmbH
00031 Other Trademarks: see FEDM.h
00032 */
00033 
00034 
00035 /*############### Questions ##################################################
00036 - CID und NAD für T=CL?
00037 
00038 */
00039 
00040 #if !defined(_FEDM_NO_TAG_HANDLER_ISO14443)
00041 
00042 #include "FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3.h"
00043 #include "FedmIscTagHandler_ISO14443_4_MIFARE_DESFire.h"
00044 #include "FedmIscTagHandler_ISO14443_4.h"
00045 #include "../FEDM_ISCReader.h"
00046 #include "../FEDM_ISOTabItem.h"
00047 #include "../FEDM_ISCReaderID.h"
00048 #include "../FEDM_ISC.h"
00049 #include "../../FEDM_Functions.h"
00050 
00051 
00052 #if _MSC_VER >= 1400
00053         #pragma warning(disable : 4996)
00054 #endif
00055 
00056 
00057 
00058 //####################################################################
00059 // class FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3
00060 // >> supports only ISO Host Commands <<
00061 //####################################################################
00062 
00063 FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3(
00064         FEDM_ISOTabItem* pTabItem, 
00065         FedmIscTagHandler_ISO14443_4_MIFARE_DESFire* pParent )
00066 {
00067         m_pTabItem                      = pTabItem;
00068         m_pParent                       = pParent;
00069 
00070         Init();
00071 }
00072 
00073 FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::~FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3()
00074 {
00075 }
00076 
00077 // set all data members to 0
00078 void FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::Init()
00079 {
00080         m_ucErrorSource = 0;
00081         m_uiErrorCode   = 0;
00082 }
00083 
00084 
00085         //####################################################################
00086         // 5 security related commands
00087         
00088         // [0xFA] : [0xC3] DESFire Commands (Authenticate, AuthenticateISO, AuthenticateAES)
00089 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::Authenticate(
00090         unsigned char ucMode,
00091         unsigned char ucSlot,
00092         unsigned char ucTimeout,
00093         unsigned char ucReaderKeyIndex,
00094         unsigned char ucDESFireAuthMode,
00095         unsigned char ucDESFireKeyNo,
00096         unsigned char ucSamAuthMode,
00097         unsigned char ucSamKeyNo,
00098         unsigned char ucSamKeyVersion,
00099         unsigned char ucSamDivInputLen,
00100         unsigned char* pucDivInput )
00101 {
00102         int iErr = 0;
00103 
00104         if(ucMode == 0x00)
00105         {
00106                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xFA));
00107                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, (unsigned char)0x00));
00108                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_INDEX, ucReaderKeyIndex));
00109                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_NO, ucDESFireKeyNo));
00110         }
00111         else //if(ucMode == 0x01)
00112         {
00113                 if(ucSamDivInputLen > 0)
00114                 {
00115                         FEDM_CHK3(pucDivInput);
00116                 }
00117                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xFA));
00118                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, (unsigned char)0x01));
00119                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00120                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00121                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DESFIRE_AUTH_MODE, ucDESFireAuthMode));
00122                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_NO, ucDESFireKeyNo));               
00123                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_AUTH_MODE, ucSamAuthMode));
00124                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_NO, ucSamKeyNo));
00125                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_VERSION, ucSamKeyVersion));
00126                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_DIV_INPUT_LEN, ucSamDivInputLen));
00127                 if(ucSamDivInputLen > 0)
00128                 {
00129                         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_DIV_INPUT, pucDivInput, ucSamDivInputLen));
00130                 }
00131         }
00132 
00133         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00134         if( iBack==0x00 )
00135         {
00136                 m_ucErrorSource = 0;
00137                 m_uiErrorCode = 0;
00138         }
00139         else if( iBack==0x97 )
00140         {
00141                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00142                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00143         }
00144 
00145         return iBack;
00146 }
00147 
00148         // [0x54] : [0xC3] DESFire Commands
00149 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ChangeKeySettings(
00150         unsigned char ucMode,
00151         unsigned char ucSlot,
00152         unsigned char ucTimeout,
00153         unsigned char ucNewKeySettings )
00154 {
00155         int iErr = 0;
00156 
00157         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x54));
00158         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00159         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00160         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00161         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NEW_KEY_SETTINGS, ucNewKeySettings));
00162 
00163         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00164         if( iBack==0x00 )
00165         {
00166                 m_ucErrorSource = 0;
00167                 m_uiErrorCode = 0;
00168         }
00169         else if( iBack==0x97 )
00170         {
00171                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00172                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00173         }
00174 
00175         return iBack;
00176 }
00177 
00178         // [0x45] : [0xC3] DESFire Commands
00179 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetKeySettings(
00180         unsigned char ucMode,
00181         unsigned char ucSlot,
00182         unsigned char ucTimeout,
00183         unsigned char* pucResponseData,
00184         unsigned int uiResponseBufferLength,
00185         unsigned int& uiResponseLength )
00186 {
00187         FEDM_CHK3(pucResponseData);
00188 
00189         unsigned char* pData = NULL;
00190         int iErr = 0;
00191         int iAdr = 0;
00192         unsigned int uiLen = 0;
00193 
00194         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x45));
00195         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00196         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00197         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00198 
00199         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00200         if( iBack==0x00 )
00201         {
00202                 // Response Daten holen...OK
00203                 m_ucErrorSource = 0;
00204                 m_uiErrorCode = 0;
00205 
00206                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00207                 if(iAdr < 0)
00208                         return iAdr;
00209                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00210                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00211                 if(uiResponseBufferLength < uiLen)
00212                         return FEDM_ERROR_BUFFER_LENGTH;
00213                 uiResponseLength = uiLen;
00214                 memcpy(pucResponseData, pData, uiLen);
00215         }
00216         else if( iBack==0x97 )
00217         {
00218                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00219                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00220                 uiResponseLength = 0;
00221         }
00222 
00223         return iBack;
00224 }
00225 
00226         // [0xC4] : [0xC3] DESFire Commands
00227 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ChangeKey(
00228         unsigned char ucMode,
00229         unsigned char ucSlot,
00230         unsigned char ucTimeout,
00231         unsigned char ucKeyNoToBeChanged,
00232         unsigned char ucAESNewKeyVersion,
00233         std::string sOldKey,
00234         std::string sNewKey,
00235         unsigned char ucSamKeyCompMethod,
00236         unsigned char ucSamCfg,
00237         unsigned char ucSamKeyNoCurrentKey,
00238         unsigned char ucSamKeyVersionCurrentKey,
00239         unsigned char ucSamKeyNoNewKey,
00240         unsigned char ucSamKeyVersionNewKey,
00241         unsigned char ucSamDivInputLen,
00242         unsigned char* pucDivInput )
00243 {
00244         int iErr = 0;
00245         size_t iPadd = 0;
00246 
00247         if(ucMode == 0x00)
00248         {
00249                 if(sOldKey.length() != sNewKey.length())
00250                         return FEDM_ERROR_STRING_LENGTH;
00251 
00252                 if(sOldKey.length() != 16 && sOldKey.length() != 32 && sOldKey.length() != 48)
00253                         return FEDM_ERROR_STRING_LENGTH;
00254 
00255                 if(sNewKey.length() != 16 && sNewKey.length() != 32 && sNewKey.length() != 48)
00256                         return FEDM_ERROR_STRING_LENGTH;
00257 
00258 
00259                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xC4));
00260                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, (unsigned char)0x00));
00261                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_NO_TB_CHANGED, ucKeyNoToBeChanged));
00262                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_LEN, (unsigned char)(sNewKey.length()>>1))); // :2
00263                 //Padding with '00' to 24 Byte KeyLength
00264                 for(iPadd = sOldKey.length(); iPadd < 48; iPadd++)
00265                 {
00266                         sOldKey += "0";
00267                 }
00268                 for(iPadd = sNewKey.length(); iPadd < 48; iPadd++)
00269                 {
00270                         sNewKey += "0";
00271                 }
00272                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_OLD_KEY, sOldKey));
00273                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NEW_KEY, sNewKey));
00274                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NEW_KEY_VERSION, ucAESNewKeyVersion));
00275         }
00276         else //if(ucMode == 0x01)
00277         {
00278                 if(ucSamDivInputLen > 0)
00279                 {
00280                         FEDM_CHK3(pucDivInput);
00281                 }
00282                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xC4));
00283                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, (unsigned char)0x01));
00284                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00285                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00286                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_COMP_METHOD, ucSamKeyCompMethod));
00287                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_CFG, ucSamCfg));
00288                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_NO_CURRENT_KEY, ucSamKeyNoCurrentKey));
00289                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_VERSION_CURRENT_KEY, ucSamKeyVersionCurrentKey));
00290                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_NO_NEW_KEY, ucSamKeyNoNewKey));
00291                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_KEY_VERSION_NEW_KEY, ucSamKeyVersionNewKey));
00292                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_DIV_INPUT_LEN, ucSamDivInputLen));
00293                 if(ucSamDivInputLen > 0)
00294                 {
00295                         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SAM_DIV_INPUT, pucDivInput, ucSamDivInputLen));
00296                 }
00297         }
00298 
00299         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00300         if( iBack==0x00 )
00301         {
00302                 m_ucErrorSource = 0;
00303                 m_uiErrorCode = 0;
00304         }
00305         else if( iBack==0x97 )
00306         {
00307                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00308                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00309         }
00310 
00311         return iBack;
00312 }
00313 
00314         // [0x64] : [0xC3] DESFire Commands
00315 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetKeyVersion(
00316         unsigned char ucMode,
00317         unsigned char ucSlot,
00318         unsigned char ucTimeout,
00319         unsigned char ucDESFireKeyNo,
00320         unsigned char* pucResponseData,
00321         unsigned int uiResponseBufferLength,
00322         unsigned int& uiResponseLength )
00323 {
00324         FEDM_CHK3(pucResponseData);
00325 
00326         unsigned char* pData = NULL;
00327         int iErr = 0;
00328         int iAdr = 0;
00329         unsigned int uiLen = 0;
00330 
00331         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x64));
00332         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00333         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00334         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00335         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_NO, ucDESFireKeyNo));
00336 
00337         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00338         if( iBack==0x00 )
00339         {
00340                 // Response Daten holen...OK
00341                 m_ucErrorSource = 0;
00342                 m_uiErrorCode = 0;
00343 
00344                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00345                 if(iAdr < 0)
00346                         return iAdr;
00347                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00348                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00349                 if(uiResponseBufferLength < uiLen)
00350                         return FEDM_ERROR_BUFFER_LENGTH;
00351                 uiResponseLength = uiLen;
00352                 memcpy(pucResponseData, pData, uiLen);
00353         }
00354         else if( iBack==0x97 )
00355         {
00356                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00357                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00358                 uiResponseLength = 0;
00359         }
00360 
00361         return iBack;
00362 }
00363 
00364 
00365         //####################################################################
00366         // 10 PICC level commands
00367 
00368         // [0xCA] : [0xC3] DESFire Commands
00369 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateApplication(
00370         unsigned char ucMode,
00371         unsigned char ucSlot,
00372         unsigned char ucTimeout,
00373         unsigned char ucPICCLevelFlags,
00374         unsigned int uiApplicationID,
00375         unsigned char ucKeySetting1,
00376         unsigned char ucKeySetting2,
00377         unsigned int uiISOFileID,
00378         std::string sDFName )
00379 {
00380         int iErr = 0;
00381 
00382         // swap MSB with LSB
00383         unsigned int uiTmp = 0;
00384         uiTmp |= ((uiApplicationID & 0x000000FF) << 16);
00385         uiTmp |= ((uiApplicationID & 0x0000FF00) );
00386         uiTmp |= ((uiApplicationID & 0x00FF0000) >> 16);
00387 
00388 
00389         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xCA));
00390         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00391         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00392         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00393         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00394         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APP_ID, uiTmp));
00395         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_SETTINGS1, ucKeySetting1));
00396         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_KEY_SETTINGS2, ucKeySetting2));
00397         if((ucKeySetting2 & 0x40) || (ucPICCLevelFlags & 0x01))
00398         {
00399                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_FILE_ID, uiISOFileID));
00400         }
00401         if((sDFName.length() != 0) || (ucPICCLevelFlags & 0x02))
00402         {
00403                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_DF_NAME_LEN, (unsigned char)sDFName.length()));
00404                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_DF_NAME, sDFName));
00405         }
00406         
00407         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00408         if( iBack==0x00 )
00409         {
00410                 m_ucErrorSource = 0;
00411                 m_uiErrorCode = 0;
00412         }
00413         else if( iBack==0x97 )
00414         {
00415                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00416                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00417         }
00418 
00419         return iBack;
00420 }
00421 
00422         // [0xDA] : [0xC3] DESFire Commands
00423 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::DeleteApplication(
00424         unsigned char ucMode,
00425         unsigned char ucSlot,
00426         unsigned char ucTimeout,
00427         unsigned char ucPICCLevelFlags,
00428         unsigned int uiApplicationID )
00429 {
00430         // swap MSB with LSB
00431         unsigned int uiTmp = 0;
00432         uiTmp |= ((uiApplicationID & 0x000000FF) << 16);
00433         uiTmp |= ((uiApplicationID & 0x0000FF00) );
00434         uiTmp |= ((uiApplicationID & 0x00FF0000) >> 16);
00435 
00436         int iErr = 0;
00437 
00438         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xDA));
00439         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00440         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00441         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00442         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00443         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APP_ID, uiTmp));
00444         
00445         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00446         if( iBack==0x00 )
00447         {
00448                 m_ucErrorSource = 0;
00449                 m_uiErrorCode = 0;
00450         }
00451         else if( iBack==0x97 )
00452         {
00453                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00454                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00455         }
00456 
00457         return iBack;
00458 }
00459 
00460         // [0x6A] : [0xC3] DESFire Commands
00461 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetApplicationIDs(
00462         unsigned char ucMode,
00463         unsigned char ucSlot,
00464         unsigned char ucTimeout,
00465         unsigned char ucPICCLevelFlags,
00466         unsigned char* pucResponseData,
00467         unsigned int uiResponseBufferLength,
00468         unsigned int& uiResponseLength )
00469 {
00470         FEDM_CHK3(pucResponseData);
00471 
00472         unsigned char* pData = NULL;
00473         int iErr = 0;
00474         int iAdr = 0;
00475         unsigned int uiLen = 0;
00476 
00477         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x6A));
00478         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00479         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00480         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00481         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00482         
00483         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00484         if( iBack==0x00 )
00485         {
00486                 // Response Daten holen...OK
00487                 m_ucErrorSource = 0;
00488                 m_uiErrorCode = 0;
00489 
00490                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00491                 if(iAdr < 0)
00492                         return iAdr;
00493                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00494                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00495                 if(uiResponseBufferLength < uiLen)
00496                         return FEDM_ERROR_BUFFER_LENGTH;
00497                 uiResponseLength = uiLen;
00498                 memcpy(pucResponseData, pData, uiLen);
00499         }
00500         else if( iBack==0x97 )
00501         {
00502                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00503                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00504                 uiResponseLength = 0;
00505         }
00506 
00507         return iBack;
00508 }
00509 
00510         // [0x6E] : [0xC3] DESFire Commands
00511 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::FreeMemory(
00512         unsigned char ucMode,
00513         unsigned char ucSlot,
00514         unsigned char ucTimeout,
00515         unsigned char ucPICCLevelFlags,
00516         unsigned char* pucResponseData,
00517         unsigned int uiResponseBufferLength,
00518         unsigned int& uiResponseLength )
00519 {
00520         unsigned char* pData = NULL;
00521         int iErr = 0;
00522         int iAdr = 0;
00523         unsigned int uiLen = 0;
00524 
00525         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x6E));
00526         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00527         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00528         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00529         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00530         
00531         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00532         if( iBack==0x00 )
00533         {
00534                 // Response Daten holen...OK
00535                 m_ucErrorSource = 0;
00536                 m_uiErrorCode = 0;
00537 
00538                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00539                 if(iAdr < 0)
00540                         return iAdr;
00541                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00542                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00543                 if(uiResponseBufferLength < uiLen)
00544                         return FEDM_ERROR_BUFFER_LENGTH;
00545                 uiResponseLength = uiLen;
00546                 memcpy(pucResponseData, pData, uiLen);
00547         }
00548         else if( iBack==0x97 )
00549         {
00550                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00551                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00552                 uiResponseLength = 0;
00553         }
00554 
00555         return iBack;
00556 }
00557 
00558         // [0x6D] : [0xC3] DESFire Commands
00559 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetDFNames(
00560         unsigned char ucMode,
00561         unsigned char ucSlot,
00562         unsigned char ucTimeout,
00563         unsigned char ucPICCLevelFlags,
00564         unsigned char* pucResponseData,
00565         unsigned int uiResponseBufferLength,
00566         unsigned int& uiResponseLength )
00567 {
00568         FEDM_CHK3(pucResponseData);
00569 
00570         unsigned char* pData = NULL;
00571         int iErr = 0;
00572         int iAdr = 0;
00573         unsigned int uiLen = 0;
00574 
00575         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x6D));
00576         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00577         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00578         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00579         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00580         
00581         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00582         if( iBack==0x00 )
00583         {
00584                 // Response Daten holen...OK
00585                 m_ucErrorSource = 0;
00586                 m_uiErrorCode = 0;
00587 
00588                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00589                 if(iAdr < 0)
00590                         return iAdr;
00591                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00592                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00593                 if(uiResponseBufferLength < uiLen)
00594                         return FEDM_ERROR_BUFFER_LENGTH;
00595                 uiResponseLength = uiLen;
00596                 memcpy(pucResponseData, pData, uiLen);
00597         }
00598         else if( iBack==0x97 )
00599         {
00600                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00601                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00602                 uiResponseLength = 0;
00603         }
00604 
00605         return iBack;
00606 }
00607 
00608         // [0x5A] : [0xC3] DESFire Commands
00609 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::SelectApplication(
00610         unsigned char ucMode,
00611         unsigned char ucSlot,
00612         unsigned char ucTimeout,
00613         unsigned char ucPICCLevelFlags,
00614         unsigned int uiApplicationID )
00615 {
00616         // swap MSB with LSB
00617         unsigned int uiTmp = 0;
00618         uiTmp |= ((uiApplicationID & 0x000000FF) << 16);
00619         uiTmp |= ((uiApplicationID & 0x0000FF00) );
00620         uiTmp |= ((uiApplicationID & 0x00FF0000) >> 16);
00621 
00622         int iErr = 0;
00623         
00624         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x5A));
00625         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00626         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00627         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00628         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00629         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APP_ID, uiTmp));
00630         
00631         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00632         if( iBack==0x00 )
00633         {
00634                 m_ucErrorSource = 0;
00635                 m_uiErrorCode = 0;
00636         }
00637         else if( iBack==0x97 )
00638         {
00639                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00640                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00641         }
00642 
00643         return iBack;
00644 }
00645 
00646         // [0xFC] : [0xC3] DESFire Commands
00647 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::FormatPICC(
00648         unsigned char ucMode,
00649         unsigned char ucSlot,
00650         unsigned char ucTimeout,
00651         unsigned char ucPICCLevelFlags )
00652 {
00653         int iErr = 0;
00654 
00655         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xFC));
00656         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00657         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00658         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00659         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00660         
00661         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00662         if( iBack==0x00 )
00663         {
00664                 m_ucErrorSource = 0;
00665                 m_uiErrorCode = 0;
00666         }
00667         else if( iBack==0x97 )
00668         {
00669                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00670                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00671         }
00672 
00673         return iBack;
00674 }
00675 
00676         // [0x60] : [0xC3] DESFire Commands
00677 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetVersion(
00678         unsigned char ucMode,
00679         unsigned char ucSlot,
00680         unsigned char ucTimeout,
00681         unsigned char ucPICCLevelFlags,
00682         unsigned char* pucResponseData,
00683         unsigned int uiResponseBufferLength,
00684         unsigned int& uiResponseLength )
00685 {
00686         FEDM_CHK3(pucResponseData);
00687 
00688         unsigned char* pData = NULL;
00689         int iErr = 0;
00690         int iAdr = 0;
00691         unsigned int uiLen = 0;
00692 
00693         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x60));
00694         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00695         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00696         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00697         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00698         
00699         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00700         if( iBack==0x00 )
00701         {
00702                 // Response Daten holen...OK
00703                 m_ucErrorSource = 0;
00704                 m_uiErrorCode = 0;
00705 
00706                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00707                 if(iAdr < 0)
00708                         return iAdr;
00709                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00710                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00711                 if(uiResponseBufferLength < uiLen)
00712                         return FEDM_ERROR_BUFFER_LENGTH;
00713                 uiResponseLength = uiLen;
00714                 memcpy(pucResponseData, pData, uiLen);
00715         }
00716         else if( iBack==0x97 )
00717         {
00718                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00719                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00720                 uiResponseLength = 0;
00721         }
00722 
00723         return iBack;
00724 }
00725 
00726         // [0x51] : [0xC3] DESFire Commands
00727 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetCardUID(
00728         unsigned char ucMode,
00729         unsigned char ucSlot,
00730         unsigned char ucTimeout,
00731         unsigned char ucPICCLevelFlags,
00732         unsigned char* pucResponseData,
00733         unsigned int uiResponseBufferLength,
00734         unsigned int& uiResponseLength )
00735 {
00736         FEDM_CHK3(pucResponseData);
00737 
00738         unsigned char* pData = NULL;
00739         int iErr = 0;
00740         int iAdr = 0;
00741         unsigned int uiLen = 0;
00742 
00743         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x51));
00744         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00745         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00746         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00747         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00748         
00749         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00750         if( iBack==0x00 )
00751         {
00752                 // Response Daten holen...OK
00753                 m_ucErrorSource = 0;
00754                 m_uiErrorCode = 0;
00755 
00756                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00757                 if(iAdr < 0)
00758                         return iAdr;
00759                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00760                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00761                 if(uiResponseBufferLength < uiLen)
00762                         return FEDM_ERROR_BUFFER_LENGTH;
00763                 uiResponseLength = uiLen;
00764                 memcpy(pucResponseData, pData, uiLen);
00765         }
00766         else if( iBack==0x97 )
00767         {
00768                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00769                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00770                 uiResponseLength = 0;
00771         }
00772 
00773         return iBack;
00774 }
00775 
00776         // [0x5C] : [0xC3] DESFire Commands
00777 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::SetConfiguration(
00778         unsigned char ucMode,
00779         unsigned char ucSlot,
00780         unsigned char ucTimeout,
00781         unsigned char ucPICCLevelFlags,
00782         unsigned char* pucRequestData,
00783         unsigned int uiRequestLength )
00784 {
00785         FEDM_CHK3(pucRequestData);
00786 
00787         int iErr = 0;
00788 
00789         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x5C));
00790         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00791         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00792         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00793         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_PICC_LEVEL_FLAGS, ucPICCLevelFlags));
00794         unsigned char Option = pucRequestData[0];
00795         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_0x6E_OPTION, Option));
00796         if(Option == 0x00)
00797         {
00798                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_0x6E_CONFIG, pucRequestData[1]));
00799         }
00800         else if(Option == 0x01)
00801         {
00802                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_0x6E_DEFAULT_KEY_VERSION, pucRequestData[1]));
00803                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_0x6E_DEFAULT_KEY, &pucRequestData[2], 24));
00804         }
00805         else // if(Option == 0x02)
00806         {
00807                 // first byte of ATS contains length information TL
00808                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_0x6E_USER_DEF_ATS, &pucRequestData[1], pucRequestData[1]));
00809         }
00810         
00811         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00812         if( iBack==0x00 )
00813         {
00814                 m_ucErrorSource = 0;
00815                 m_uiErrorCode = 0;
00816         }
00817         else if( iBack==0x97 )
00818         {
00819                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00820                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00821         }
00822 
00823         return iBack;
00824 }
00825 
00826 
00827         //####################################################################
00828         // 10 application level commands
00829 
00830         // [0x5F] : [0xC3] DESFire Commands
00831 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ChangeFileSettings(
00832         unsigned char ucMode,
00833         unsigned char ucSlot,
00834         unsigned char ucTimeout,
00835         unsigned char ucApplicationLevelFlags,
00836         unsigned char ucFileNo,
00837         unsigned char ucNewFileCommSettings,
00838         unsigned char ucNewFileReadWriteAccessRights,
00839         unsigned char ucNewFileChangeAccessRights,
00840         unsigned char ucNewFileReadAccessRights,
00841         unsigned char ucNewFileWriteAccessRights )
00842 {
00843         int iErr = 0;
00844 
00845         unsigned char ucAccessRights[2];
00846         ucAccessRights[0] = ((ucNewFileReadWriteAccessRights & 0x0F) << 4) + (ucNewFileChangeAccessRights & 0x0F);
00847         ucAccessRights[1] = ((ucNewFileReadAccessRights & 0x0F) << 4) + (ucNewFileWriteAccessRights & 0x0F);
00848 
00849         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x5F));
00850         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00851         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00852         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00853         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
00854         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
00855         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucNewFileCommSettings));
00856         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, ucAccessRights, 2));
00857 
00858         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00859         if( iBack==0x00 )
00860         {
00861                 m_ucErrorSource = 0;
00862                 m_uiErrorCode = 0;
00863         }
00864         else if( iBack==0x97 )
00865         {
00866                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00867                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00868         }
00869 
00870         return iBack;
00871 }
00872 
00873         // [0x6F] : [0xC3] DESFire Commands
00874 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetFileIDs(
00875         unsigned char ucMode,
00876         unsigned char ucSlot,
00877         unsigned char ucTimeout,
00878         unsigned char ucApplicationLevelFlags,
00879         unsigned char* pucResponseData,
00880         unsigned int uiResponseBufferLength,
00881         unsigned int& uiResponseLength )
00882 {
00883         FEDM_CHK3(pucResponseData);
00884 
00885         unsigned char* pData = NULL;
00886         int iErr = 0;
00887         int iAdr = 0;
00888         unsigned int uiLen = 0;
00889 
00890         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x6F));
00891         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00892         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00893         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00894         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
00895 
00896         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00897         if( iBack==0x00 )
00898         {
00899                 // Response Daten holen...OK
00900                 m_ucErrorSource = 0;
00901                 m_uiErrorCode = 0;
00902 
00903                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00904                 if(iAdr < 0)
00905                         return iAdr;
00906                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00907                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00908                 if(uiResponseBufferLength < uiLen)
00909                         return FEDM_ERROR_BUFFER_LENGTH;
00910                 uiResponseLength = uiLen;
00911                 memcpy(pucResponseData, pData, uiLen);
00912         }
00913         else if( iBack==0x97 )
00914         {
00915                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00916                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00917                 uiResponseLength = 0;
00918         }
00919 
00920         return iBack;
00921 }
00922 
00923         // [0xF5] : [0xC3] DESFire Commands
00924 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetFileSettings(
00925         unsigned char ucMode,
00926         unsigned char ucSlot,
00927         unsigned char ucTimeout,
00928         unsigned char ucApplicationLevelFlags,
00929         unsigned char ucFileNo,
00930         unsigned char* pucResponseData,
00931         unsigned int uiResponseBufferLength,
00932         unsigned int& uiResponseLength )
00933 {
00934         FEDM_CHK3(pucResponseData);
00935 
00936         unsigned char* pData = NULL;
00937         int iErr = 0;
00938         int iAdr = 0;
00939         unsigned int uiLen = 0;
00940 
00941         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xF5));
00942         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
00943         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
00944         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
00945         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
00946         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
00947 
00948         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
00949         if( iBack==0x00 )
00950         {
00951                 // Response Daten holen...OK
00952                 m_ucErrorSource = 0;
00953                 m_uiErrorCode = 0;
00954 
00955                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
00956                 if(iAdr < 0)
00957                         return iAdr;
00958                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
00959                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
00960                 if(uiResponseBufferLength < uiLen)
00961                         return FEDM_ERROR_BUFFER_LENGTH;
00962                 uiResponseLength = uiLen;
00963                 memcpy(pucResponseData, pData, uiLen);
00964         }
00965         else if( iBack==0x97 )
00966         {
00967                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
00968                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
00969                 uiResponseLength = 0;
00970         }
00971 
00972         return iBack;
00973 }
00974 
00975         // [0xCD] : [0xC3] DESFire Commands
00976 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateStdDataFile(
00977         unsigned char ucMode,
00978         unsigned char ucSlot,
00979         unsigned char ucTimeout,
00980         unsigned char ucApplicationLevelFlags,
00981         unsigned char ucFileNo,
00982         unsigned int uiISOFileID,
00983         unsigned char ucFileCommSettings,
00984         unsigned char ucFileReadWriteAccessRights,
00985         unsigned char ucFileChangeAccessRights,
00986         unsigned char ucFileReadAccessRights,
00987         unsigned char ucFileWriteAccessRights,
00988         unsigned int uiFileSize )
00989 {
00990         unsigned char TmpAccessRights[2];
00991         TmpAccessRights[0] = ((ucFileReadWriteAccessRights & 0x0F) << 4) + (ucFileChangeAccessRights & 0x0F);
00992         TmpAccessRights[1] = ((ucFileReadAccessRights & 0x0F) << 4) + (ucFileWriteAccessRights & 0x0F);
00993 
00994         // swap MSB with LSB
00995         unsigned int TmpFileSize = 0;
00996         TmpFileSize |= ((uiFileSize & 0x000000FF) << 16);
00997         TmpFileSize |= ((uiFileSize & 0x0000FF00) );
00998         TmpFileSize |= ((uiFileSize & 0x00FF0000) >> 16);
00999 
01000         int iErr = 0;
01001 
01002         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xCD));
01003         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01004         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01005         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01006         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01007         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01008         if(ucApplicationLevelFlags & 0x01)
01009         {
01010                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_FILE_ID, uiISOFileID));
01011         }
01012         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01013         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, TmpAccessRights, 2));
01014         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_SIZE, TmpFileSize));
01015 
01016         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01017         if( iBack==0x00 )
01018         {
01019                 m_ucErrorSource = 0;
01020                 m_uiErrorCode = 0;
01021         }
01022         else if( iBack==0x97 )
01023         {
01024                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01025                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01026         }
01027 
01028         return iBack;
01029 }
01030 
01031         // [0xCB] : [0xC3] DESFire Commands
01032 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateBackupDataFile(
01033         unsigned char ucMode,
01034         unsigned char ucSlot,
01035         unsigned char ucTimeout,
01036         unsigned char ucApplicationLevelFlags,
01037         unsigned char ucFileNo,
01038         unsigned int uiISOFileID,
01039         unsigned char ucFileCommSettings,
01040         unsigned char ucFileReadWriteAccessRights,
01041         unsigned char ucFileChangeAccessRights,
01042         unsigned char ucFileReadAccessRights,
01043         unsigned char ucFileWriteAccessRights,
01044         unsigned int uiFileSize )
01045 {
01046         unsigned char TmpAccessRights[2];
01047         TmpAccessRights[0] = ((ucFileReadWriteAccessRights & 0x0F) << 4) + (ucFileChangeAccessRights & 0x0F);
01048         TmpAccessRights[1] = ((ucFileReadAccessRights & 0x0F) << 4) + (ucFileWriteAccessRights & 0x0F);
01049 
01050         // swap MSB with LSB
01051         unsigned int TmpFileSize = 0;
01052         TmpFileSize |= ((uiFileSize & 0x000000FF) << 16);
01053         TmpFileSize |= ((uiFileSize & 0x0000FF00) );
01054         TmpFileSize |= ((uiFileSize & 0x00FF0000) >> 16);
01055 
01056         int iErr = 0;
01057 
01058         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xCB));
01059         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01060         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01061         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01062         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01063         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01064         if(ucApplicationLevelFlags & 0x01)
01065         {
01066                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_FILE_ID, uiISOFileID));
01067         }
01068         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01069         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, TmpAccessRights, 2));
01070         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_SIZE, TmpFileSize));
01071 
01072         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01073         if( iBack==0x00 )
01074         {
01075                 m_ucErrorSource = 0;
01076                 m_uiErrorCode = 0;
01077         }
01078         else if( iBack==0x97 )
01079         {
01080                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01081                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01082         }
01083 
01084         return iBack;
01085 }
01086 
01087         // [0xCC] : [0xC3] DESFire Commands
01088 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateValueFile(
01089         unsigned char ucMode,
01090         unsigned char ucSlot,
01091         unsigned char ucTimeout,
01092         unsigned char ucApplicationLevelFlags,
01093         unsigned char ucFileNo,
01094         unsigned char ucFileCommSettings,
01095         unsigned char ucFileReadWriteAccessRights,
01096         unsigned char ucFileChangeAccessRights,
01097         unsigned char ucFileReadAccessRights,
01098         unsigned char ucFileWriteAccessRights,
01099         unsigned int uiLowerLimit,
01100         unsigned int uiUpperLimit,
01101         unsigned int uiValue,
01102         unsigned char ucLimitedCreditEnabled )
01103 {
01104         unsigned char TmpAccessRights[2];
01105         TmpAccessRights[0] = ((ucFileReadWriteAccessRights & 0x0F) << 4) + (ucFileChangeAccessRights & 0x0F);
01106         TmpAccessRights[1] = ((ucFileReadAccessRights & 0x0F) << 4) + (ucFileWriteAccessRights & 0x0F);
01107 
01108         // swap MSB with LSB
01109         unsigned int TmpLowerLimit = 0;
01110         TmpLowerLimit |= ((uiLowerLimit & 0x000000FF) << 24);
01111         TmpLowerLimit |= ((uiLowerLimit & 0x0000FF00) << 8);
01112         TmpLowerLimit |= ((uiLowerLimit & 0x00FF0000) >> 8);
01113         TmpLowerLimit |= ((uiLowerLimit & 0xFF000000) >> 24);
01114 
01115         unsigned int TmpUpperLimit = 0;
01116         TmpUpperLimit |= ((uiUpperLimit & 0x000000FF) << 24);
01117         TmpUpperLimit |= ((uiUpperLimit & 0x0000FF00) << 8);
01118         TmpUpperLimit |= ((uiUpperLimit & 0x00FF0000) >> 8);
01119         TmpUpperLimit |= ((uiUpperLimit & 0xFF000000) >> 24);
01120 
01121         unsigned int TmpValue = 0;
01122         TmpValue |= ((uiValue & 0x000000FF) << 24);
01123         TmpValue |= ((uiValue & 0x0000FF00) << 8);
01124         TmpValue |= ((uiValue & 0x00FF0000) >> 8);
01125         TmpValue |= ((uiValue & 0xFF000000) >> 24);
01126 
01127         int iErr = 0;
01128 
01129         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xCC));
01130         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01131         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01132         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01133         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01134         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01135         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01136         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, TmpAccessRights, 2));
01137         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_LOWER_LIMIT, TmpLowerLimit));
01138         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_UPPER_LIMIT, TmpUpperLimit));
01139         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_VALUE, TmpValue));
01140         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_LIMITED_CREDIT_ENABLED, ucLimitedCreditEnabled));
01141 
01142         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01143         if( iBack==0x00 )
01144         {
01145                 m_ucErrorSource = 0;
01146                 m_uiErrorCode = 0;
01147         }
01148         else if( iBack==0x97 )
01149         {
01150                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01151                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01152         }
01153 
01154         return iBack;
01155 }
01156 
01157         // [0xC1] : [0xC3] DESFire Commands
01158 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateLinearRecordFile(
01159         unsigned char ucMode,
01160         unsigned char ucSlot,
01161         unsigned char ucTimeout,
01162         unsigned char ucApplicationLevelFlags,
01163         unsigned char ucFileNo,
01164         unsigned int uiISOFileID,
01165         unsigned char ucFileCommSettings,
01166         unsigned char ucFileReadWriteAccessRights,
01167         unsigned char ucFileChangeAccessRights,
01168         unsigned char ucFileReadAccessRights,
01169         unsigned char ucFileWriteAccessRights,
01170         unsigned int uiRecordSize,
01171         unsigned int uiMaxNoOfRecords )
01172 {
01173         unsigned char TmpAccessRights[2];
01174         TmpAccessRights[0] = ((ucFileReadWriteAccessRights & 0x0F) << 4) + (ucFileChangeAccessRights & 0x0F);
01175         TmpAccessRights[1] = ((ucFileReadAccessRights & 0x0F) << 4) + (ucFileWriteAccessRights & 0x0F);
01176 
01177         // swap MSB with LSB
01178         unsigned int TmpRecordSize = 0;
01179         TmpRecordSize |= ((uiRecordSize & 0x000000FF) << 16);
01180         TmpRecordSize |= ((uiRecordSize & 0x0000FF00));
01181         TmpRecordSize |= ((uiRecordSize & 0x00FF0000) >> 16);
01182 
01183         unsigned int TmpMaxNoOfRecords = 0;
01184         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x000000FF) << 16);
01185         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x0000FF00));
01186         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x00FF0000) >> 16);
01187 
01188         int iErr = 0;
01189 
01190         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xC1));
01191         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01192         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01193         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01194         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01195         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01196         if(ucApplicationLevelFlags & 0x01)
01197         {
01198                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_FILE_ID, uiISOFileID));
01199         }
01200         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01201         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, TmpAccessRights, 2));
01202         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_RECORD_SIZE, TmpRecordSize));
01203         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NO_OF_RECORDS, TmpMaxNoOfRecords));
01204 
01205         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01206         if( iBack==0x00 )
01207         {
01208                 m_ucErrorSource = 0;
01209                 m_uiErrorCode = 0;
01210         }
01211         else if( iBack==0x97 )
01212         {
01213                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01214                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01215         }
01216 
01217         return iBack;
01218 }
01219 
01220         // [0xC0] : [0xC3] DESFire Commands
01221 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CreateCyclicRecordFile(
01222         unsigned char ucMode,
01223         unsigned char ucSlot,
01224         unsigned char ucTimeout,
01225         unsigned char ucApplicationLevelFlags,
01226         unsigned char ucFileNo,
01227         unsigned int uiISOFileID,
01228         unsigned char ucFileCommSettings,
01229         unsigned char ucFileReadWriteAccessRights,
01230         unsigned char ucFileChangeAccessRights,
01231         unsigned char ucFileReadAccessRights,
01232         unsigned char ucFileWriteAccessRights,
01233         unsigned int uiRecordSize,
01234         unsigned int uiMaxNoOfRecords )
01235 {
01236         unsigned char TmpAccessRights[2];
01237         TmpAccessRights[0] = ((ucFileReadWriteAccessRights & 0x0F) << 4) + (ucFileChangeAccessRights & 0x0F);
01238         TmpAccessRights[1] = ((ucFileReadAccessRights & 0x0F) << 4) + (ucFileWriteAccessRights & 0x0F);
01239 
01240         // swap MSB with LSB
01241         unsigned int TmpRecordSize = 0;
01242         TmpRecordSize |= ((uiRecordSize & 0x000000FF) << 16);
01243         TmpRecordSize |= ((uiRecordSize & 0x0000FF00));
01244         TmpRecordSize |= ((uiRecordSize & 0x00FF0000) >> 16);
01245 
01246         unsigned int TmpMaxNoOfRecords = 0;
01247         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x000000FF) << 16);
01248         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x0000FF00));
01249         TmpMaxNoOfRecords |= ((uiMaxNoOfRecords & 0x00FF0000) >> 16);
01250 
01251         int iErr = 0;
01252 
01253         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xC0));
01254         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01255         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01256         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01257         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01258         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01259         if(ucApplicationLevelFlags & 0x01)
01260         {
01261                 FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_ISO7816_FILE_ID, uiISOFileID));
01262         }
01263         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01264         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_ACCESS_RIGHTS, TmpAccessRights, 2));
01265         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_RECORD_SIZE, TmpRecordSize));
01266         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NO_OF_RECORDS, TmpMaxNoOfRecords));
01267 
01268         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01269         if( iBack==0x00 )
01270         {
01271                 m_ucErrorSource = 0;
01272                 m_uiErrorCode = 0;
01273         }
01274         else if( iBack==0x97 )
01275         {
01276                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01277                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01278         }
01279 
01280         return iBack;
01281 }
01282 
01283         // [0xDF] : [0xC3] DESFire Commands
01284 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::DeleteFile(
01285         unsigned char ucMode,
01286         unsigned char ucSlot,
01287         unsigned char ucTimeout,
01288         unsigned char ucApplicationLevelFlags,
01289         unsigned char ucFileNo )
01290 {
01291         int iErr = 0;
01292 
01293         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xDF));
01294         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01295         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01296         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01297         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01298         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01299 
01300         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01301         if( iBack==0x00 )
01302         {
01303                 m_ucErrorSource = 0;
01304                 m_uiErrorCode = 0;
01305         }
01306         else if( iBack==0x97 )
01307         {
01308                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01309                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01310         }
01311 
01312         return iBack;
01313 }
01314 
01315         // [0x61] : [0xC3] DESFire Commands
01316 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetISOFileIDs(
01317         unsigned char ucMode,
01318         unsigned char ucSlot,
01319         unsigned char ucTimeout,
01320         unsigned char ucApplicationLevelFlags,
01321         unsigned char* pucResponseData,
01322         unsigned int uiResponseBufferLength,
01323         unsigned int& uiResponseLength )
01324 {
01325         FEDM_CHK3(pucResponseData);
01326 
01327         unsigned char* pData = NULL;
01328         int iErr = 0;
01329         int iAdr = 0;
01330         unsigned int uiLen = 0;
01331 
01332         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x61));
01333         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01334         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01335         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01336         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_APPLICATION_LEVEL_FLAGS, ucApplicationLevelFlags));
01337 
01338         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01339         if( iBack==0x00 )
01340         {
01341                 // Response Daten holen...OK
01342                 m_ucErrorSource = 0;
01343                 m_uiErrorCode = 0;
01344 
01345                 iAdr = FEDM_GetAdrOfID(FEDM_ISC_TMP_0xC3_RSP_DATA, 32);
01346                 if(iAdr < 0)
01347                         return iAdr;
01348                 pData = &m_pParent->m_pReader->m_TmpData[iAdr];
01349                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_RSP_DATA_LEN, &uiLen));
01350                 if(uiResponseBufferLength < uiLen)
01351                         return FEDM_ERROR_BUFFER_LENGTH;
01352                 uiResponseLength = uiLen;
01353                 memcpy(pucResponseData, pData, uiLen);
01354         }
01355         else if( iBack==0x97 )
01356         {
01357                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01358                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01359                 uiResponseLength = 0;
01360         }
01361 
01362         return iBack;
01363 }
01364 
01365 
01366         //####################################################################
01367         // 11 data manipulation commands
01368         
01369         // [0xBD] : [0xC3] DESFire Commands
01370 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ReadStandardData(
01371         unsigned char ucMode,
01372         unsigned char ucSlot,
01373         unsigned char ucTimeout,
01374         unsigned char ucDataManipulationFlags,
01375         unsigned char ucFileNo,
01376         unsigned char ucFileCommSettings,
01377         unsigned int uiFileOffset,
01378         unsigned int uiFileLen,
01379         unsigned char* pucFileData )
01380 {
01381         FEDM_CHK3(pucFileData);
01382 
01383         int iErr = 0;
01384 
01385         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xBD));
01386         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01387         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01388         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01389         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01390         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01391         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01392         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_OFFSET, uiFileOffset));
01393         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_DATA_LEN, uiFileLen));
01394 
01395         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01396         if( iBack==0x00 )
01397         {
01398                 memcpy(pucFileData, &m_pTabItem->m_ucRxDB[uiFileOffset], uiFileLen);
01399                 m_ucErrorSource = 0;
01400                 m_uiErrorCode = 0;
01401         }
01402         else if( iBack==0x97 )
01403         {
01404                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01405                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01406         }
01407 
01408         return iBack;
01409 }
01410         
01411         // [0x3D] : [0xC3] DESFire Commands
01412 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::WriteStandardData(
01413         unsigned char ucMode,
01414         unsigned char ucSlot,
01415         unsigned char ucTimeout,
01416         unsigned char ucDataManipulationFlags,
01417         unsigned char ucFileNo,
01418         unsigned char ucFileCommSettings,
01419         unsigned int uiFileOffset,
01420         unsigned int uiFileLen,
01421         unsigned char* pucFileData )
01422 {
01423         FEDM_CHK3(pucFileData);
01424 
01425         int iErr = 0;
01426 
01427         if(uiFileOffset + uiFileLen > FEDM_ISC_ISO_TABLE_RxDB_SIZE)
01428                 return FEDM_ERROR_ARRAY_BOUNDARY;
01429 
01430         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x3D));
01431         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01432         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01433         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01434         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01435         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01436         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01437         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_OFFSET, uiFileOffset));
01438         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_DATA_LEN, uiFileLen));
01439 
01440         memcpy(&m_pTabItem->m_ucTxDB[uiFileOffset], pucFileData, uiFileLen);
01441 
01442         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01443         if( iBack==0x00 )
01444         {
01445                 m_ucErrorSource = 0;
01446                 m_uiErrorCode = 0;
01447         }
01448         else if( iBack==0x97 )
01449         {
01450                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01451                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01452         }
01453 
01454         return iBack;
01455 }
01456 
01457         // [0x6C] : [0xC3] DESFire Commands
01458 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::GetValue(
01459         unsigned char ucMode,
01460         unsigned char ucSlot,
01461         unsigned char ucTimeout,
01462         unsigned char ucDataManipulationFlags,
01463         unsigned char ucFileNo,
01464         unsigned char ucFileCommSettings,
01465         unsigned int& uiValue )
01466 {
01467         int iErr = 0;
01468 
01469         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x6C));
01470         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01471         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01472         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01473         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01474         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01475         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01476 
01477         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01478         if( iBack==0x00 )
01479         {
01480                 uiValue = m_pTabItem->m_uiValue;
01481                 m_ucErrorSource = 0;
01482                 m_uiErrorCode = 0;
01483         }
01484         else if( iBack==0x97 )
01485         {
01486                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01487                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01488         }
01489 
01490         return iBack;
01491 }
01492 
01493         // [0x0C] : [0xC3] DESFire Commands
01494 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::Credit(
01495         unsigned char ucMode,
01496         unsigned char ucSlot,
01497         unsigned char ucTimeout,
01498         unsigned char ucDataManipulationFlags,
01499         unsigned char ucFileNo,
01500         unsigned char ucFileCommSettings,
01501         unsigned int uiCreditValue)
01502 {
01503         int iErr = 0;
01504 
01505         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x0C));
01506         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01507         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01508         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01509         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01510         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01511         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01512         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CREDIT_VALUE, uiCreditValue));
01513 
01514         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01515         if( iBack==0x00 )
01516         {
01517                 m_ucErrorSource = 0;
01518                 m_uiErrorCode = 0;
01519         }
01520         else if( iBack==0x97 )
01521         {
01522                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01523                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01524         }
01525 
01526         return iBack;
01527 }
01528 
01529         // [0xDC] : [0xC3] DESFire Commands
01530 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::Debit(
01531         unsigned char ucMode,
01532         unsigned char ucSlot,
01533         unsigned char ucTimeout,
01534         unsigned char ucDataManipulationFlags,
01535         unsigned char ucFileNo,
01536         unsigned char ucFileCommSettings,
01537         unsigned int uiDebitValue )
01538 {
01539         int iErr = 0;
01540 
01541         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xDC));
01542         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01543         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01544         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01545         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01546         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01547         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01548         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DEBIT_VALUE, uiDebitValue));
01549 
01550         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01551         if( iBack==0x00 )
01552         {
01553                 m_ucErrorSource = 0;
01554                 m_uiErrorCode = 0;
01555         }
01556         else if( iBack==0x97 )
01557         {
01558                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01559                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01560         }
01561 
01562         return iBack;
01563 }
01564 
01565 
01566         // [0x1C] : [0xC3] DESFire Commands
01567 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::LimitedCredit(
01568         unsigned char ucMode,
01569         unsigned char ucSlot,
01570         unsigned char ucTimeout,
01571         unsigned char ucDataManipulationFlags,
01572         unsigned char ucFileNo,
01573         unsigned char ucFileCommSettings,
01574         unsigned int uiCreditValue )
01575 {
01576         int iErr = 0;
01577 
01578         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x1C));
01579         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01580         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01581         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01582         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01583         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01584         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01585         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CREDIT_VALUE, uiCreditValue));
01586 
01587         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01588         if( iBack==0x00 )
01589         {
01590                 m_ucErrorSource = 0;
01591                 m_uiErrorCode = 0;
01592         }
01593         else if( iBack==0x97 )
01594         {
01595                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01596                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01597         }
01598 
01599         return iBack;
01600 }
01601 
01602         // [0x3B] : [0xC3] DESFire Commands
01603 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::WriteRecord(
01604         unsigned char ucMode,
01605         unsigned char ucSlot,
01606         unsigned char ucTimeout,
01607         unsigned char ucDataManipulationFlags,
01608         unsigned char ucFileNo,
01609         unsigned char ucFileCommSettings,
01610         unsigned int uiFileOffset,
01611         unsigned int uiRecordLen,
01612         unsigned char* pucRecordData )
01613 {
01614         FEDM_CHK3(pucRecordData);
01615 
01616         int iErr = 0;
01617 
01618         if(uiFileOffset + uiRecordLen > FEDM_ISC_ISO_TABLE_TxDB_SIZE)
01619                 return FEDM_ERROR_ARRAY_BOUNDARY;
01620 
01621         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0x3B));
01622         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01623         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01624         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01625         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01626         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01627         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01628         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_OFFSET, uiFileOffset));
01629         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_DATA_LEN, uiRecordLen));
01630 
01631         memcpy(&m_pTabItem->m_ucTxDB[uiFileOffset], pucRecordData, uiRecordLen);
01632 
01633         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01634         if( iBack==0x00 )
01635         {
01636                 m_ucErrorSource = 0;
01637                 m_uiErrorCode = 0;
01638         }
01639         else if( iBack==0x97 )
01640         {
01641                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01642                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01643         }
01644 
01645         return iBack;
01646 }
01647 
01648         // [0xBB] : [0xC3] DESFire Commands
01649 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ReadRecords(
01650         unsigned char ucMode,
01651         unsigned char ucSlot,
01652         unsigned char ucTimeout,
01653         unsigned char ucDataManipulationFlags,
01654         unsigned char ucFileNo,
01655         unsigned char ucFileCommSettings,
01656         unsigned int uiRecordOffset,
01657         unsigned int uiNoOfRecords,
01658         unsigned int uiRecordSize,
01659         unsigned char* pucRecordData )
01660 {
01661         FEDM_CHK3(pucRecordData);
01662 
01663         int iErr = 0;
01664 
01665         if(uiNoOfRecords * uiRecordSize > FEDM_ISC_ISO_TABLE_RxDB_SIZE)
01666                 return FEDM_ERROR_ARRAY_BOUNDARY;
01667 
01668 
01669         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xBB));
01670         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01671         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01672         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01673         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01674         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01675         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01676         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_RECORD_OFFSET, uiRecordOffset));
01677         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_NO_OF_RECORDS, uiNoOfRecords));
01678         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_RECORD_SIZE, uiRecordSize));
01679 
01680         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01681         if( iBack==0x00 )
01682         {
01683                 memcpy(pucRecordData, &m_pTabItem->m_ucRxDB[0], uiNoOfRecords*uiRecordSize);
01684                 m_ucErrorSource = 0;
01685                 m_uiErrorCode = 0;
01686         }
01687         else if( iBack==0x97 )
01688         {
01689                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01690                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01691         }
01692 
01693         return iBack;
01694 }
01695 
01696         // [0xEB] : [0xC3] DESFire Commands
01697 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::ClearRecordFile(
01698         unsigned char ucMode,
01699         unsigned char ucSlot,
01700         unsigned char ucTimeout,
01701         unsigned char ucDataManipulationFlags,
01702         unsigned char ucFileNo,
01703         unsigned char ucFileCommSettings )
01704 {
01705         int iErr = 0;
01706 
01707         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xEB));
01708         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01709         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01710         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01711         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01712         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_NO, ucFileNo));
01713         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_FILE_COMM_SETTINGS, ucFileCommSettings));
01714 
01715         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01716         if( iBack==0x00 )
01717         {
01718                 m_ucErrorSource = 0;
01719                 m_uiErrorCode = 0;
01720         }
01721         else if( iBack==0x97 )
01722         {
01723                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01724                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01725         }
01726 
01727         return iBack;
01728 }
01729 
01730         // [0xC7] : [0xC3] DESFire Commands
01731 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::CommitTransaction(
01732         unsigned char ucMode,
01733         unsigned char ucSlot,
01734         unsigned char ucTimeout,
01735         unsigned char ucDataManipulationFlags )
01736 {
01737         int iErr = 0;
01738 
01739         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xC7));
01740         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01741         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01742         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01743         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01744 
01745         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01746         if( iBack==0x00 )
01747         {
01748                 m_ucErrorSource = 0;
01749                 m_uiErrorCode = 0;
01750         }
01751         else if( iBack==0x97 )
01752         {
01753                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01754                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01755         }
01756 
01757         return iBack;
01758 }
01759 
01760         // [0xA7] : [0xC3] DESFire Commands
01761 int FedmIscTagHandler_ISO14443_4_MIFARE_DESFire_Impl_C3::AbortTransaction(
01762         unsigned char ucMode,
01763         unsigned char ucSlot,
01764         unsigned char ucTimeout,
01765         unsigned char ucDataManipulationFlags )
01766 {
01767         int iErr = 0;
01768 
01769         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_CMD, (unsigned char)0xA7));
01770         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_MODE, ucMode));
01771         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_SLOT_NO, ucSlot));
01772         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_TIMEOUT, ucTimeout));
01773         FEDM_CHK1(iErr, m_pParent->m_pReader->SetData(FEDM_ISC_TMP_0xC3_DATA_MANIPULATION_FLAGS, ucDataManipulationFlags));
01774 
01775         int iBack = m_pParent->m_pReader->SendProtocol(0xC3);
01776         if( iBack==0x00 )
01777         {
01778                 m_ucErrorSource = 0;
01779                 m_uiErrorCode = 0;
01780         }
01781         else if( iBack==0x97 )
01782         {
01783                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_SOURCE, &m_ucErrorSource));
01784                 FEDM_CHK1(iErr, m_pParent->m_pReader->GetData(FEDM_ISC_TMP_0xC3_ERROR_CODE, &m_uiErrorCode));
01785         }
01786 
01787         return iBack;
01788 }
01789 
01790 #endif // #if !defined(_FEDM_NO_TAG_HANDLER_ISO14443)


maggie_rfid_drivers
Author(s): Raul Perula-Martinez
autogenerated on Mon Sep 14 2015 03:05:30