FedmIscTagHandler_ISO14443_4_Maxim_MAX66040.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 |      FedmIscTagHandler_ISO14443_4_Maxim_MAX66040.cpp  |
00004 |                                                       |
00005 ---------------------------------------------------------
00006 
00007 Copyright © 2010-2011   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                   :       04.10.2010
00018 
00019 Version                 :       03.03.02 / 29.04.2011 / M. Raner, M. Hultsch
00020 
00021 Operation Systems       :       independent
00022 
00023 Function                        :       class for OBID® classic-pro transponder ISO14443 of manufacturer MAXIM
00024 
00025 NOTE                            :       this class supports only selected or addressed 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 #if !defined(_FEDM_NO_TAG_HANDLER_ISO14443)
00035 
00036 #include "FedmIscTagHandler_ISO14443_4_Maxim_MAX66040.h"
00037 #include "../FEDM_ISCReader.h"
00038 #include "../FEDM_ISOTabItem.h"
00039 #include "../FEDM_ISCReaderID.h"
00040 #include "../FEDM_ISC.h"
00041 
00042 #include "feisc.h"
00043 
00044 
00045 #if _MSC_VER >= 1400
00046         #pragma warning(disable : 4996)
00047 #endif
00048 
00049 
00050 
00051 //####################################################################
00052 // class FedmIscTagHandler_ISO14443_Maxim
00053 // >> supports only ISO Host Commands <<
00054 //####################################################################
00055 
00056 FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::FedmIscTagHandler_ISO14443_4_Maxim_MAX66040(
00057         FEDM_ISCReader* pReader, 
00058         FEDM_ISOTabItem* pTabItem )
00059         : FedmIscTagHandler_ISO14443_4_Maxim(pReader, FedmIscTagHandler::TYPE_ISO14443_4_MAXIM_MAX66040, pTabItem)
00060 {
00061         m_sTagName = "ISO 14443 Type B : Maxim MAX66040";
00062         UpdateChallenge();
00063 }
00064 
00065 FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::FedmIscTagHandler_ISO14443_4_Maxim_MAX66040(
00066         FEDM_ISCReader* pReader, 
00067         unsigned int uiTagHandlerType,
00068         FEDM_ISOTabItem* pTabItem )
00069         : FedmIscTagHandler_ISO14443_4_Maxim(pReader, uiTagHandlerType, pTabItem)
00070 {
00071         m_sTagName = "ISO 14443 Type B : Maxim MAX66040";
00072         UpdateChallenge();
00073 }
00074 
00075 FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::~FedmIscTagHandler_ISO14443_4_Maxim_MAX66040()
00076 {
00077 }
00078 
00079 // set all data members to 0
00080 /*void FedmIscTagHandler_ISO14443::Init()
00081 {
00082 }*/
00083 
00084 /***************************************************************************
00085   Begin                 :       06.10.2010 / M. Raner
00086 
00087   Version               :       03.02.05 / 06.10.2010 / M. Raner
00088 
00089   Function                      :       computes PageMAC
00090   
00091   Parameters            :       unsigned char* pucSecret                        - [in]  request flags byte
00092                                                 unsigned char* pucMemoryPageData        - [in]  32byte memory page data
00093                                                 unsigned char  ucPageNumber                     - [in]  number of page involved in computation
00094                                                 unsigned char* pucUID                           - [in]  uid value of tag
00095                                                 unsigned char* pucMAC                           - [out] computed page MAC
00096 
00097   Return value          :       0                               - if tramsmission was successful
00098                                                 status byte (>1)- if the reader signals a problem
00099                                                 error code (<0) - if something goes wrong
00100 ***************************************************************************/
00101 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::UserComputePageMAC(
00102                 unsigned char* pucSecret, 
00103                 unsigned char* pucMemoryPageData, 
00104                 unsigned char ucPageNumber, 
00105                 unsigned char* pucUID,
00106                 unsigned char* pucMAC)
00107 {
00108         FEDM_CHK3(pucSecret);
00109         FEDM_CHK3(pucMemoryPageData);
00110         FEDM_CHK3(pucUID);
00111         FEDM_CHK3(pucMAC);
00112 
00113         unsigned char buffer[64];
00114 
00115         int iCnt = 0;
00116 
00117         if((ucPageNumber >= 0x00) && (ucPageNumber <= 0x04))
00118         {
00119                 buffer[0] = pucSecret[0];
00120                 buffer[1] = pucSecret[1];
00121                 buffer[2] = pucSecret[2];
00122                 buffer[3] = pucSecret[3];
00123 
00124                 for(iCnt = 4; iCnt < 36; iCnt++)
00125                 {
00126                         buffer[iCnt] = pucMemoryPageData[iCnt - 4];
00127                 }
00128 
00129                 if(ucPageNumber == 0x04)
00130                 {
00131                         for(iCnt = 20; iCnt < 36; iCnt++)
00132                         {
00133                                 buffer[iCnt] = 0xFF;
00134                         }
00135                 }
00136 
00137                 buffer[36] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[0];
00138                 buffer[37] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[1];
00139 
00140                 buffer[38] = 0xFF;
00141                 buffer[39] = 0xFF;
00142 
00143                 buffer[40] = (unsigned char)((0x4 << 4) |ucPageNumber);
00144 
00145                 for(iCnt = 41; iCnt < 48; iCnt++)
00146                 {       
00147                         buffer[iCnt] = pucUID[iCnt - 41];       
00148                 }
00149                 
00150                 buffer[48] = pucSecret[4];
00151                 buffer[49] = pucSecret[5];
00152                 buffer[50] = pucSecret[6];
00153                 buffer[51] = pucSecret[7];
00154 
00155                 buffer[52] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[2];
00156                 buffer[53] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[3];
00157                 buffer[54] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[4];
00158 
00159                 buffer[55] = 0x80;
00160                 
00161                 for(iCnt = 56; iCnt < 62; iCnt++)
00162                 {
00163                         buffer[iCnt] = 0x00;
00164                 }
00165 
00166                 buffer[62] = 0x01;
00167                 buffer[63] = 0xB8;
00168         }
00169 
00170         unsigned int edcba[5];
00171         FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ComputeMAC(buffer,edcba);
00172 
00173         for(iCnt = 0; iCnt < 4; iCnt++)
00174         {
00175                 pucMAC[0+iCnt] = (unsigned char)((edcba[0] >> (iCnt * 8)) & 0xFF);
00176         }
00177         for(iCnt = 0; iCnt < 4; iCnt++)
00178         {
00179                 pucMAC[4+iCnt] = (unsigned char)((edcba[1] >> (iCnt * 8)) & 0xFF);
00180         }
00181         for(iCnt = 0; iCnt < 4; iCnt++)
00182         {
00183                 pucMAC[8+iCnt] = (unsigned char)((edcba[2] >> (iCnt * 8)) & 0xFF);
00184         }
00185         for(iCnt = 0; iCnt < 4; iCnt++)
00186         {
00187                 pucMAC[12+iCnt] = (unsigned char)((edcba[3] >> (iCnt * 8)) & 0xFF);
00188         }
00189         for(iCnt = 0; iCnt < 4; iCnt++)
00190         {
00191                 pucMAC[16+iCnt] = (unsigned char)((edcba[4] >> (iCnt * 8)) & 0xFF);
00192         }
00193 
00194         return 0;
00195 }
00196 
00197 /***************************************************************************
00198   Begin                 :       06.10.2010 / M. Raner
00199 
00200   Version               :       03.02.05 / 06.10.2010 / M. Raner
00201 
00202   Function                      :       computes a new Secret Value
00203   
00204   Parameters            :       unsigned char* pucSecret                        - [in]  old secret value
00205                                                 unsigned char* pucMemoryPageData        - [in]  memory page must match memory page number in GenerateSecret()
00206                                                 unsigned char* pucPartialSecret         - [in]  this value must match partial secret value in GenerateSecret()
00207                                                 unsigned char* pucNewSecret                     - [out] computed new secret
00208 
00209   Return value          :       0                               - if tramsmission was successful
00210                                                 status byte (>1)- if the reader signals a problem
00211                                                 error code (<0) - if something goes wrong
00212 ***************************************************************************/
00213 int     FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::UserComputeSecret(
00214                 unsigned char* pucSecret, 
00215                 unsigned char* pucMemoryPageData, 
00216                 unsigned char* pucPartialSecret, 
00217                 unsigned char* pucNewSecret)
00218 {
00219         FEDM_CHK3(pucSecret);
00220         FEDM_CHK3(pucMemoryPageData);
00221         FEDM_CHK3(pucPartialSecret);
00222         FEDM_CHK3(pucNewSecret);
00223 
00224         unsigned char buffer[64];
00225         int iCnt = 0;
00226 
00227         buffer[0] = pucSecret[0];
00228         buffer[1] = pucSecret[1];
00229         buffer[2] = pucSecret[2];
00230         buffer[3] = pucSecret[3];
00231 
00232         for(iCnt = 4; iCnt < 36; iCnt++)
00233         {
00234                 buffer[iCnt] = pucMemoryPageData[iCnt - 4];
00235         }
00236 
00237         buffer[36] = 0xFF;
00238         buffer[37] = 0xFF;
00239         buffer[38] = 0xFF;
00240         buffer[39] = 0xFF;
00241 
00242         buffer[40] = pucPartialSecret[0] & 0x3f;
00243 
00244         for(iCnt = 41; iCnt < 48; iCnt++)
00245         {
00246                 buffer[iCnt] = pucPartialSecret[iCnt-40];
00247         }
00248         
00249         buffer[48] = pucSecret[4];
00250         buffer[49] = pucSecret[5];
00251         buffer[50] = pucSecret[6];
00252         buffer[51] = pucSecret[7];
00253 
00254         buffer[52] = 0xFF;
00255         buffer[53] = 0xFF;
00256         buffer[54] = 0xFF;
00257 
00258         buffer[55] = 0x80;
00259         
00260         for(iCnt = 56; iCnt < 62; iCnt++)
00261         {
00262                 buffer[iCnt] = 0x00;
00263         }
00264 
00265         buffer[62] = 0x01;
00266         buffer[63] = 0xB8;
00267 
00268         unsigned int edcba[5];
00269         FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ComputeMAC(buffer,edcba);
00270 
00271         for(iCnt = 0; iCnt < 4; iCnt++)
00272         {
00273                 pucNewSecret[0+iCnt] = (unsigned char)((edcba[0] >> (iCnt * 8)) & 0xFF);
00274         }
00275         for(iCnt = 0; iCnt < 4; iCnt++)
00276         {
00277                 pucNewSecret[4+iCnt] = (unsigned char)((edcba[1] >> (iCnt * 8)) & 0xFF);
00278         }
00279 
00280         return 0;
00281 }
00282 
00283 /***************************************************************************
00284   Begin                 :       06.10.2010 / M. Raner
00285 
00286   Version               :       03.02.05 / 06.10.2010 / M. Raner
00287 
00288   Function                      :       UserComputeCopyBufferMAC
00289   
00290   Parameters            :       unsigned char* pucSecret                                - [in]  secret
00291                                                 unsigned char* pucMemoryPageData                - [in]  memory page must match memory page number used in CopyBuffer()
00292                                                 unsigned char* pucReadWriteBufferData   - [in]  must match data in read/write Buffer
00293                                                 unsigned char* pucIntegrityBytes                - [in]  integrity bytes(write counter) of datablock
00294                                                 unsigned char pucPageNumber                             - [in]  number of page used in CopyBuffer()
00295                                                 unsigned char* pucUID                                   - [in]  uid value of tag
00296                                                 unsigned char* pucMAC                                   - [out] computed CopyBuffer MAC
00297 
00298   Return value          :       0                               - if tramsmission was successful
00299                                                 status byte (>1)- if the reader signals a problem
00300                                                 error code (<0) - if something goes wrong
00301 ***************************************************************************/
00302 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::UserComputeCopyBufferMAC(
00303                 unsigned char* pucSecret, 
00304                 unsigned char* pucMemoryPageData, 
00305                 unsigned char* pucReadWriteBufferData, 
00306                 unsigned char* pucIntegrityBytes,
00307                 unsigned char pucPageNumber, 
00308                 unsigned char* pucUID,
00309                 unsigned char* pucMAC)
00310 {
00311         FEDM_CHK3(pucSecret);
00312         FEDM_CHK3(pucMemoryPageData);
00313         FEDM_CHK3(pucReadWriteBufferData);
00314         FEDM_CHK3(pucIntegrityBytes);
00315         FEDM_CHK3(pucUID);
00316         FEDM_CHK3(pucMAC);
00317 
00318         unsigned char buffer[64];
00319 
00320         int iCnt = 0;
00321 
00322         if((pucPageNumber >= 0x00) && (pucPageNumber <= 0x04))
00323         {
00324                 buffer[0] = pucSecret[0];
00325                 buffer[1] = pucSecret[1];
00326                 buffer[2] = pucSecret[2];
00327                 buffer[3] = pucSecret[3];
00328 
00329                 for(iCnt = 4; iCnt < 32; iCnt++)
00330                 {
00331                         buffer[iCnt] = pucMemoryPageData[iCnt - 4];
00332                 }
00333 
00334                 if(pucPageNumber == 0x04)
00335                 {
00336                         for(iCnt = 20; iCnt < 32; iCnt++)
00337                         {
00338                                 buffer[iCnt] = 0xFF;
00339                         }
00340                 }
00341 
00342                 for(iCnt = 32; iCnt < 40; iCnt++)
00343                 {
00344                         buffer[iCnt] = pucReadWriteBufferData[iCnt-32];
00345                 }
00346 
00347                 buffer[40] = pucPageNumber;
00348 
00349                 for(iCnt = 41; iCnt < 48; iCnt++)
00350                 {
00351                         buffer[iCnt] = pucUID[iCnt - 41];       
00352                 }
00353                 
00354                 buffer[48] = pucSecret[4];
00355                 buffer[49] = pucSecret[5];
00356                 buffer[50] = pucSecret[6];
00357                 buffer[51] = pucSecret[7];
00358 
00359                 buffer[52] = pucIntegrityBytes[0];
00360                 buffer[53] = pucIntegrityBytes[1];
00361                 buffer[54] = 0xFF;
00362 
00363                 buffer[55] = 0x80;
00364                 
00365                 for(iCnt = 56; iCnt < 62; iCnt++)
00366                 {
00367                         buffer[iCnt] = 0x00;
00368                 }
00369 
00370                 buffer[62] = 0x01;
00371                 buffer[63] = 0xB8;
00372         }       
00373 
00374         unsigned int edcba[5];
00375         FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ComputeMAC(buffer,edcba);
00376 
00377         for(iCnt = 0; iCnt < 4; iCnt++)
00378         {
00379                 pucMAC[0+iCnt] = (unsigned char)((edcba[0] >> (iCnt * 8)) & 0xFF);
00380         }
00381         for(iCnt = 0; iCnt < 4; iCnt++)
00382         {
00383                 pucMAC[4+iCnt] = (unsigned char)((edcba[1] >> (iCnt * 8)) & 0xFF);
00384         }
00385         for(iCnt = 0; iCnt < 4; iCnt++)
00386         {
00387                 pucMAC[8+iCnt] = (unsigned char)((edcba[2] >> (iCnt * 8)) & 0xFF);
00388         }
00389         for(iCnt = 0; iCnt < 4; iCnt++)
00390         {
00391                 pucMAC[12+iCnt] = (unsigned char)((edcba[3] >> (iCnt * 8)) & 0xFF);
00392         }
00393         for(iCnt = 0; iCnt < 4; iCnt++)
00394         {
00395                 pucMAC[16+iCnt] = (unsigned char)((edcba[4] >> (iCnt * 8)) & 0xFF);
00396         }
00397 
00398         return 0;
00399 }
00400 
00401 /***************************************************************************
00402   Begin                 :       06.10.2010 / M. Raner
00403 
00404   Version               :       03.02.05 / 06.10.2010 / M. Raner
00405 
00406   Function                      :       Read Memory Page (use ReadSingleBlock())
00407   
00408   Parameters            :       unsigned char   ucPageNumber            - [in]  number of page, which should be read
00409                                                 unsigned char&  ucIndicator                     - [out] error indicator from transponder
00410                                                 unsigned char*  pucMemoryPageData       - [out] 32byte memory page data
00411 
00412   Return value          :       0                               - if tramsmission was successful
00413                                                 status byte (>1)- if the reader signals a problem
00414                                                 error code (<0) - if something goes wrong
00415 ***************************************************************************/
00416 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::GetMemoryPageData( 
00417                 unsigned char ucPageNumber, 
00418                 unsigned char& ucIndicator,
00419                 unsigned char* pucMemoryPageData)
00420 {
00421         FEDM_CHK3(pucMemoryPageData);
00422         int iBack = 0;
00423 
00424         unsigned char pucMemoryData[8];
00425         int iRounds = 0;
00426 
00427         if(ucPageNumber >= 0 && ucPageNumber < 4)
00428         {
00429                 iRounds = 4;
00430         }
00431         else if(ucPageNumber == 4)
00432         {
00433                 iRounds = 3;
00434         }
00435 
00436         for(int iCnt = 0; iCnt < iRounds; iCnt++)
00437         {
00438                 iBack = ReadSingleBlock(ucPageNumber * 4 + iCnt, ucIndicator, pucMemoryData);
00439                 if(iBack != 0)
00440                 {
00441                         return iBack;
00442                 }
00443 
00444                 if(ucIndicator)
00445                         return 0;
00446 
00447                 for(int iCnt2 = 0; iCnt2 < 8; iCnt2++)
00448                 {
00449                         pucMemoryPageData[iCnt*8+iCnt2] = pucMemoryData[iCnt2];
00450                 }
00451         }
00452 
00453         return iBack;
00454 }
00455 
00456 /***************************************************************************
00457   Begin                 :       06.10.2010 / M. Raner
00458 
00459   Version               :       03.02.05 / 06.10.2010 / M. Raner
00460 
00461   Function                      :       computes MAC for UserCompute... functions
00462   
00463   Parameters            :       unsigned char*  pucM    - [in]  input data of sixteen 32-bit Words
00464                                                 unsigned int*   puiMAC  - [out] computed MAC
00465 
00466   Return value          :       0                               - if tramsmission was successful
00467                                                 status byte (>1)- if the reader signals a problem
00468                                                 error code (<0) - if something goes wrong
00469 ***************************************************************************/
00470 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ComputeMAC(                                                    
00471                 unsigned char* pucM, 
00472                 unsigned int* puiMAC)
00473 {
00474         FEDM_CHK3(pucM);
00475         FEDM_CHK3(puiMAC);
00476 
00477         /*
00478                 This function includes a shriked version of SHA1 algorithm. It starts with input of 
00479                 eighty 32-bit words and ends with output of the values A,B,C,D,E of the 160-bit key.
00480                 The final constants, defined in ISO/IEC 10118-3 specification, are removed in this 
00481                 shriked version. The final constants are normally added after each 
00482                 block is computed. Because the MAX66x40 only processes one block, adding these 
00483                 constants does not add additional security.
00484         */
00485         unsigned int uiW[80];                           /* eighty 32-bit words */
00486         unsigned int uiA = 0x67452301;          /* init values defined in FIPS 180-1 */
00487     unsigned int uiB = 0xEFCDAB89;              /* init values defined in FIPS 180-1 */
00488     unsigned int uiC = 0x98BADCFE;              /* init values defined in FIPS 180-1 */
00489     unsigned int uiD = 0x10325476;              /* init values defined in FIPS 180-1 */
00490     unsigned int uiE = 0xC3D2E1F0;              /* init values defined in FIPS 180-1 */
00491     unsigned int uiF;
00492     unsigned int uiK;
00493     unsigned int uiTmp;
00494         int iCnt2 = 0;
00495 
00496         for(int iCnt = 0; iCnt*64 < 64; iCnt++)
00497         {
00498                 for (iCnt2 = 0; iCnt2 < 16; iCnt2++)
00499         {
00500             uiW[iCnt2] = (unsigned int)pucM[iCnt2 * 4 + (iCnt * 64)] << 24 | (unsigned int)pucM[iCnt2 * 4 + 1 + (iCnt * 64)] << 16 | (unsigned int)pucM[iCnt2 * 4 + 2 + (iCnt * 64)] << 8 | (unsigned int)pucM[iCnt2 * 4 + 3 + (iCnt * 64)];
00501         }
00502 
00503         /* Expand from 16 to 80 words */
00504         for (iCnt2 = 16; iCnt2 < 80; iCnt2++)
00505         {
00506                         uiW[iCnt2] = (((uiW[iCnt2 - 3] ^ uiW[iCnt2 - 8] ^ uiW[iCnt2 - 14] ^ uiW[iCnt2 - 16]) << 1) | ((uiW[iCnt2 - 3] ^ uiW[iCnt2 - 8] ^ uiW[iCnt2 - 14] ^ uiW[iCnt2 - 16]) >> (32 - 1)));
00507         }
00508 
00509         for (iCnt2 = 0; iCnt2 < 80; iCnt2++)
00510         {
00511             if (iCnt2 >= 0 && iCnt2 <= 19)
00512             {
00513                 uiF = (uiB & uiC) | (~uiB & uiD);       /* defined in FIPS 180-1 */
00514                 uiK = 0x5A827999;                                               /* defined in FIPS 180-1 */
00515             }
00516             else if (iCnt2 >= 20 && iCnt2 <= 39)
00517             {
00518                 uiF = uiB ^ uiC ^ uiD;  /* defined in FIPS 180-1 */
00519                 uiK = 0x6ED9EBA1;                       /* defined in FIPS 180-1 */
00520             }
00521             else if (iCnt2 >= 40 && iCnt2 <= 59)
00522             {
00523                 uiF = (uiB & uiC) | (uiB & uiD) | (uiC & uiD);  /* defined in FIPS 180-1 */
00524                 uiK = 0x8F1BBCDC;                                                                       /* defined in FIPS 180-1 */
00525             }
00526             else if (iCnt2 >= 60 && iCnt2 <= 79)
00527             {
00528                 uiF = uiB ^ uiC ^ uiD;  /* defined in FIPS 180-1 */
00529                 uiK = 0xCA62C1D6;                       /* defined in FIPS 180-1 */
00530             }
00531 
00532                         uiTmp = ((uiA << 5) | (uiA >> (32 - 5))) + uiF + uiE + uiK + uiW[iCnt2];
00533             uiE = uiD;
00534             uiD = uiC;
00535                         uiC = ((uiB << 30) | (uiB >> (32 - 30)));
00536             uiB = uiA;
00537             uiA = uiTmp;
00538         }
00539         }
00540 
00541         puiMAC[0] = uiE;
00542         puiMAC[1] = uiD;
00543         puiMAC[2] = uiC;
00544         puiMAC[3] = uiB;
00545         puiMAC[4] = uiA;
00546 
00547         return 0;
00548 }
00549 
00550 /***************************************************************************
00551   Begin                 :       06.10.2010 / M. Raner
00552 
00553   Version               :       03.02.05 / 06.10.2010 / M. Raner
00554 
00555   Function                      :       generates new random challenge
00556   
00557   Parameters            :       -
00558 
00559   Return value          :       0                               - if tramsmission was successful
00560                                                 status byte (>1)- if the reader signals a problem
00561                                                 error code (<0) - if something goes wrong
00562 ***************************************************************************/
00563 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::UpdateChallenge()
00564 {
00565         for(int iCnt = 0; iCnt < 5; iCnt++)
00566         {
00567                 ucChallenge[iCnt] = (unsigned char)rand();
00568         }
00569         return 0;
00570 }
00571 
00572 /***************************************************************************
00573   Begin                 :       08.10.2010 / M. Raner
00574 
00575   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00576 
00577   Function                      :       [0xB2][0xBE][0xA0] WriteBuffer
00578   
00579   Parameters            :       unsigned char ucControlByte             - [in]  control code (load, compute, locking)
00580                                                 unsigned char* pucPartialSecret - [in]  secret to be load, used in computation
00581                                                 unsigned char&  ucIndicator             - [out] response indicator byte (if 0x00 then command execution was successful)
00582                                                 unsigned char& ucPageCRCStatus  - [out] status code of crc check
00583 
00584   Return value          :       0                               - if tramsmission was successful
00585                                                 status byte (>1)- if the reader signals a problem
00586                                                 error code (<0) - if something goes wrong
00587 ***************************************************************************/
00588 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::GenerateSecret(        
00589                 unsigned char ucControlByte,
00590                 unsigned char* pucPartialSecret,
00591                 unsigned char& ucIndicator,
00592                 unsigned char& ucPageCRCStatus)
00593 {
00594         //******************************************************************************
00595         // ParameterDescription
00596 
00597                 /*
00598                 control byte(size: 1byte)
00599                         code:   function:                                                       info:
00600                         0xF0    load secret without locking                     
00601                         0x0F    load secret with locking                        secret write protection byte is changed to 0x0A
00602                         0xn5    compute secret without locking          n specifies the page number to be used in computation
00603                         0xnA    compute and lock secret                         WARNING: permanently write protect the secret, n specifies the page number to be used in computation
00604                         0xAA    load and lock secret                            WARNING: permanently write protect the secret
00605 
00606                 partial secret(size 8byte)
00607                         controlByte:            function:
00608                         0xF0, 0x0F, 0xAA        the new secret that will be loaded
00609                         0xn5, 0xnA                      partial secret to be used in computation of new secret
00610                 */
00611 
00612 
00613         //******************************************************************************
00614         // ParameterTesting
00615 
00616         //Test Pointer for NULL
00617         FEDM_CHK3(pucPartialSecret);
00618 
00619         //Check ControlByte for valid values
00620         if(!(ucControlByte == 0xF0 || 
00621                 ucControlByte == 0x0F || 
00622                 (ucControlByte & 0x05) == 0x05 || 
00623                 (ucControlByte & 0x0A) == 0x0A ||
00624                 ucControlByte == 0xAA))
00625         {
00626                 //Error: Control byte is invalid
00627                 return FEDM_ERROR_PARAMETER;
00628         }
00629 
00630         //********************************************************************
00631         // Declaration
00632         unsigned int uiLengthOfResponseData = 0;
00633 
00634         //********************************************************************
00635         // RequestData
00636         m_ucRequestData[0] = 0xA0;      // Command
00637         m_ucRequestData[1] = ucControlByte;
00638         for(int iCnt = 0; iCnt < 8; iCnt++)
00639         {
00640                 m_ucRequestData[2+iCnt] = pucPartialSecret[iCnt];
00641         }
00642 
00643         //******************************************************************************
00644         // CommandExecute
00645         //execute command
00646         int iBack = Apdu(m_ucRequestData, 10, m_ucResponseData, 256, uiLengthOfResponseData);
00647         if(iBack)
00648                 return iBack;
00649 
00650         //******************************************************************************
00651         // ResponseData
00652         if(uiLengthOfResponseData > 0)
00653         {
00654                 ucIndicator = m_ucResponseData[0];
00655                 if(ucIndicator == 0)
00656                 {
00657                         ucPageCRCStatus = m_ucResponseData[1];
00658                 }
00659         }
00660 
00661         return iBack;
00662 }
00663 
00664 /***************************************************************************
00665   Begin                 :       06.10.2010 / M. Raner
00666 
00667   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00668 
00669   Function                      :       [0xB2][0xBE][0xA1] WriteBuffer
00670   
00671   Parameters            :       unsigned char   ucBlockNumber           - [in]  number of block(0x00 to 0x11)
00672                                                 unsigned char*  pucNewBlockData         - [in]  New block-data
00673                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
00674 
00675   Return value          :       0                               - if tramsmission was successful
00676                                                 status byte (>1)- if the reader signals a problem
00677                                                 error code (<0) - if something goes wrong
00678 ***************************************************************************/
00679 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::WriteBuffer(                                           
00680                 unsigned char ucBlockNumber,
00681                 unsigned char* pucNewBlockData,
00682                 unsigned char& ucIndicator)
00683 {
00684         //********************************************************************
00685         // ParameterTesting
00686         //Test Pointer for NULL
00687         FEDM_CHK3(pucNewBlockData);
00688 
00689         //********************************************************************
00690         // Declaration
00691         unsigned int uiLengthOfResponseData = 0;
00692 
00693         //********************************************************************
00694         // RequestData
00695         m_ucRequestData[0] = 0xA1;      // Command
00696         m_ucRequestData[1] = ucBlockNumber;
00697         for(int iCnt = 0; iCnt < 8; iCnt++)
00698         {
00699                 m_ucRequestData[2+iCnt] = pucNewBlockData[iCnt];
00700         }
00701 
00702         //********************************************************************
00703         // CommandExecute
00704         int iBack = Apdu(m_ucRequestData, 10, m_ucResponseData, 256, uiLengthOfResponseData);
00705         if(iBack)
00706                 return iBack;
00707 
00708         //********************************************************************
00709         // ResponseData
00710         if(uiLengthOfResponseData > 0)
00711         {
00712                 ucIndicator = m_ucResponseData[0];
00713         }
00714 
00715         return iBack;
00716 }
00717 
00718 /***************************************************************************
00719   Begin                 :       06.10.2010 / M. Raner
00720 
00721   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00722 
00723   Function                      :       [0xB2][0xBE][0xA2] ReadBuffer
00724   
00725   Parameters            :       unsigned char&  ucIndicator                             - [out] response indicator byte (if 0x00 then command execution was successful)
00726                                                 unsigned char&  ucBlockNumber                   - [out] number of block
00727                                                 unsigned char*  pucReadWriteBufferData  - [out] data of read/write Buffer
00728 
00729   Return value          :       0                               - if tramsmission was successful
00730                                                 status byte (>1)- if the reader signals a problem
00731                                                 error code (<0) - if something goes wrong
00732 ***************************************************************************/
00733 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ReadBuffer(                                                    
00734                 unsigned char& ucIndicator,
00735                 unsigned char& ucBlockNumber,
00736                 unsigned char* pucReadWriteBufferData)
00737 {
00738         //********************************************************************
00739         // ParameterTesting
00740         //Test Pointer for NULL
00741         FEDM_CHK3(pucReadWriteBufferData);
00742         
00743         //********************************************************************
00744         // Declaration
00745         unsigned int uiLengthOfResponseData = 0;
00746 
00747         //********************************************************************
00748         // RequestData
00749         m_ucRequestData[0] = 0xA2;      // Command
00750 
00751         //********************************************************************
00752         // CommandExecute
00753         int iBack = Apdu(m_ucRequestData, 1, m_ucResponseData, 256, uiLengthOfResponseData);
00754         if(iBack)
00755                 return iBack;
00756 
00757         //********************************************************************
00758         // ResponseData
00759         if(uiLengthOfResponseData > 0)
00760         {
00761                 ucIndicator = m_ucResponseData[0];
00762                 if(ucIndicator == 0)
00763                 {
00764                         ucBlockNumber = m_ucResponseData[1];
00765                         for(int iCnt = 0; iCnt < 8; iCnt++)
00766                         {
00767                                 pucReadWriteBufferData[iCnt] = m_ucResponseData[2 + iCnt];
00768                         }
00769                 }
00770         }
00771 
00772         return iBack;
00773 }
00774 
00775 /***************************************************************************
00776   Begin                 :       06.10.2010 / M. Raner
00777 
00778   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00779 
00780   Function                      :       [0xB2][0xBE][0xA3] CopyBuffer
00781   
00782   Parameters            :       unsigned char   ucBlockNumber   - [in]  number of block(0x00 to 0x12)
00783                                                 unsigned char*  pucMAC                  - [in]  CopyBufferMAC from UserComputeCopyBufferMAC()
00784                                                 unsigned char&  ucIndicator             - [out] response indicator byte (if 0x00 then command execution was successful)
00785                                                 unsigned char&  ucPageCRCStatus - [out] status code of crc check
00786 
00787   Return value          :       0                               - if tramsmission was successful
00788                                                 status byte (>1)- if the reader signals a problem
00789                                                 error code (<0) - if something goes wrong
00790 ***************************************************************************/
00791 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::CopyBuffer(                                                    
00792                 unsigned char ucBlockNumber,
00793                 unsigned char* pucMAC,
00794                 unsigned char& ucIndicator,
00795                 unsigned char& ucPageCRCStatus)
00796 {
00797         //********************************************************************
00798         // ParameterTesting
00799         //Test Pointer for NULL
00800         FEDM_CHK3(pucMAC);
00801 
00802         //********************************************************************
00803         // Declaration
00804         unsigned int uiLengthOfResponseData = 0;
00805 
00806         //********************************************************************
00807         // RequestData
00808         m_ucRequestData[0] = 0xA3;      // Command
00809         m_ucRequestData[1] = ucBlockNumber;
00810 
00811         for(int iCnt = 0; iCnt < 20; iCnt++)
00812         {
00813                 m_ucRequestData[2+iCnt] = pucMAC[iCnt];
00814         }
00815 
00816         //********************************************************************
00817         // CommandExecute
00818         int iBack = Apdu(m_ucRequestData, 22, m_ucResponseData, 256, uiLengthOfResponseData);
00819         if(iBack)
00820                 return iBack;
00821 
00822         //********************************************************************
00823         // ResponseData
00824         if(uiLengthOfResponseData > 0)
00825         {
00826                 ucIndicator = m_ucResponseData[0];
00827                 if(ucIndicator == 0)
00828                 {
00829                         ucPageCRCStatus = m_ucResponseData[1];
00830                 }
00831         }
00832 
00833         return iBack;
00834 }
00835 
00836 /***************************************************************************
00837   Begin                 :       06.10.2010 / M. Raner
00838 
00839   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00840 
00841   Function                      :       [0xB2][0xBE][0x20] ReadSingleBlock
00842   
00843   Parameters            :       unsigned char   ucBlockNumber           - [in]  number of block(0x00 to 0x12)
00844                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
00845                                                 unsigned char*  pucMemoryData           - [out] readed memory data
00846 
00847   Return value          :       0                               - if tramsmission was successful
00848                                                 status byte (>1)- if the reader signals a problem
00849                                                 error code (<0) - if something goes wrong
00850 ***************************************************************************/
00851 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ReadSingleBlock(                                       
00852                 unsigned char ucBlockNumber,
00853                 unsigned char& ucIndicator,
00854                 unsigned char* pucMemoryData)
00855 {
00856         //********************************************************************
00857         // ParameterTesting
00858         //Test Pointer for NULL
00859         FEDM_CHK3(pucMemoryData);
00860 
00861         //********************************************************************
00862         // Declaration
00863         unsigned int uiLengthOfResponseData = 0;
00864 
00865         //********************************************************************
00866         // RequestData
00867         m_ucRequestData[0] = 0x20;      // Command
00868         m_ucRequestData[1] = ucBlockNumber;
00869 
00870         //********************************************************************
00871         // CommandExecute
00872         int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00873         if(iBack)
00874                 return iBack;
00875 
00876         //********************************************************************
00877         // ResponseData
00878         if(uiLengthOfResponseData > 0)
00879         {
00880                 ucIndicator = m_ucResponseData[0];
00881                 if(ucIndicator == 0)
00882                 {
00883                         for(int iCnt = 0; iCnt < 8; iCnt++)
00884                         {
00885                                 pucMemoryData[iCnt] = m_ucResponseData[1 + iCnt];
00886                         }
00887                 }
00888         }
00889 
00890         return iBack;
00891 }
00892 
00893 /***************************************************************************
00894   Begin                 :       06.10.2010 / M. Raner
00895 
00896   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00897 
00898   Function                      :       [0xB2][0xBE][0xB0] ReadSingleBlockWithBlockSecurity
00899   
00900   Parameters            :       unsigned char   ucBlockNumber           - [in]  number of block(0x00 to 0x12)
00901                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
00902                                                 unsigned char&  ucSecurityStatus        - [out] security status code
00903                                                 unsigned char*  pucMemoryData           - [out] readed memory data
00904 
00905   Return value          :       0                               - if tramsmission was successful
00906                                                 status byte (>1)- if the reader signals a problem
00907                                                 error code (<0) - if something goes wrong
00908 ***************************************************************************/
00909 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ReadSingleBlockWithBlockSecurity(      
00910                 unsigned char ucBlockNumber,
00911                 unsigned char& ucIndicator,
00912                 unsigned char& ucSecurityStatus,
00913                 unsigned char* pucMemoryData)
00914 {
00915         //********************************************************************
00916         // ParameterTesting
00917         //Test Pointer for NULL
00918         FEDM_CHK3(pucMemoryData);
00919 
00920         //********************************************************************
00921         // Declaration
00922         unsigned int uiLengthOfResponseData = 0;
00923 
00924         //********************************************************************
00925         // RequestData
00926         m_ucRequestData[0] = 0xB0;      // Command
00927         m_ucRequestData[1] = ucBlockNumber;
00928 
00929         //********************************************************************
00930         // CommandExecute
00931         int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00932         if(iBack)
00933                 return iBack;
00934 
00935         //********************************************************************
00936         // ResponseData
00937         if(uiLengthOfResponseData > 0)
00938         {
00939                 ucIndicator = m_ucResponseData[0];
00940                 if(ucIndicator == 0)
00941                 {
00942                         ucSecurityStatus = m_ucResponseData[1];
00943                         for(int iCnt = 0; iCnt < 8; iCnt++)
00944                         {
00945                                 pucMemoryData[iCnt] = m_ucResponseData[2 + iCnt];
00946                         }
00947                 }
00948         }
00949 
00950 
00951         return iBack;
00952 }
00953 
00954 /***************************************************************************
00955   Begin                 :       06.10.2010 / M. Raner
00956 
00957   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
00958 
00959   Function                      :       [0xB2][0xBE][0xA4] CustomReadBlock
00960   
00961   Parameters            :       unsigned char   ucBlockNumber           - [in]  number of block(0x00 to 0x12)
00962                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
00963                                                 unsigned char*  pucMemoryData           - [out] readed memory data
00964                                                 unsigned char*  pucIntegrityBytes       - [out] integrity bytes(write counter) of datablock
00965 
00966   Return value          :       0                               - if tramsmission was successful
00967                                                 status byte (>1)- if the reader signals a problem
00968                                                 error code (<0) - if something goes wrong
00969 ***************************************************************************/
00970 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::CustomReadBlock(                                       
00971                 unsigned char ucBlockNumber,
00972                 unsigned char& ucIndicator,
00973                 unsigned char* pucMemoryData,
00974                 unsigned char* pucIntegrityBytes)
00975 {
00976         //********************************************************************
00977         // ParameterTesting
00978         //Test Pointer for NULL
00979         FEDM_CHK3(pucMemoryData);
00980         FEDM_CHK3(pucIntegrityBytes);
00981 
00982         //********************************************************************
00983         // Declaration
00984         unsigned int uiLengthOfResponseData = 0;
00985 
00986         //********************************************************************
00987         // RequestData
00988         m_ucRequestData[0] = 0xA4;      // Command
00989         m_ucRequestData[1] = ucBlockNumber;
00990 
00991         //********************************************************************
00992         // CommandExecute
00993         int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00994         if(iBack)
00995                 return iBack;
00996 
00997         //********************************************************************
00998         // ResponseData
00999         if(uiLengthOfResponseData > 0)
01000         {
01001                 ucIndicator = m_ucResponseData[0];
01002                 if(ucIndicator == 0)
01003                 {
01004                         for(int iCnt = 0; iCnt < 8; iCnt++)
01005                         {
01006                                 pucMemoryData[iCnt] = m_ucResponseData[1 + iCnt];
01007                         }
01008                         pucIntegrityBytes[0] = m_ucResponseData[9];
01009                         pucIntegrityBytes[1] = m_ucResponseData[10];
01010                 }
01011         }
01012 
01013         return iBack;
01014 }
01015 
01016 /***************************************************************************
01017   Begin                 :       06.10.2010 / M. Raner
01018 
01019   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
01020 
01021   Function                      :       [0xB2][0xBE][0xB4] CustomReadBlockWithBlockSecurity
01022   
01023   Parameters            :       unsigned char   ucBlockNumber           - [in]  number of block(0x00 to 0x12)
01024                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
01025                                                 unsigned char&  ucSecurityStatus        - [out] security status code
01026                                                 unsigned char*  pucMemoryData           - [out] readed memory data
01027                                                 unsigned char*  pucIntegrityBytes       - [out] integrity bytes(write counter) of datablock
01028 
01029   Return value          :       0                               - if tramsmission was successful
01030                                                 status byte (>1)- if the reader signals a problem
01031                                                 error code (<0) - if something goes wrong
01032 ***************************************************************************/
01033 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::CustomReadBlockWithBlockSecurity(      
01034                 unsigned char ucBlockNumber,
01035                 unsigned char& ucIndicator,
01036                 unsigned char& ucSecurityStatus,
01037                 unsigned char* pucMemoryData,
01038                 unsigned char* pucIntegrityBytes)
01039 {
01040         //********************************************************************
01041         // ParameterTesting
01042         //Test Pointer for NULL
01043         FEDM_CHK3(pucMemoryData);
01044         FEDM_CHK3(pucIntegrityBytes);
01045 
01046         //********************************************************************
01047         // Declaration
01048         unsigned int uiLengthOfResponseData = 0;
01049 
01050         //********************************************************************
01051         // RequestData
01052         m_ucRequestData[0] = 0xB4;      // Command
01053         m_ucRequestData[1] = ucBlockNumber;
01054 
01055         //********************************************************************
01056         // CommandExecute
01057         int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
01058         if(iBack)
01059                 return iBack;
01060 
01061         //********************************************************************
01062         // ResponseData
01063         if(uiLengthOfResponseData > 0)
01064         {
01065                 ucIndicator = m_ucResponseData[0];
01066                 if(ucIndicator == 0)
01067                 {
01068                         ucSecurityStatus = m_ucResponseData[1];
01069                         for(int iCnt = 0; iCnt < 8; iCnt++)
01070                         {
01071                                 pucMemoryData[iCnt] = m_ucResponseData[2 + iCnt];
01072                         }
01073                         pucIntegrityBytes[0] = m_ucResponseData[10];
01074                         pucIntegrityBytes[1] = m_ucResponseData[11];
01075                 }
01076         }
01077 
01078         return iBack;
01079 }
01080 
01081 /***************************************************************************
01082   Begin                 :       06.10.2010 / M. Raner
01083 
01084   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
01085 
01086   Function                      :       [0xB2][0xBE][0xA5] ComputePageMAC
01087   
01088   Parameters            :       unsigned char   ucPageNumber            - [in]  number of page will involve in computation
01089                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
01090                                                 unsigned char&  ucPageCRCStatus         - [out] status code of crc check
01091                                                 unsigned char*  pucMAC                          - [out] from transponder computed PageMAC
01092 
01093   Return value          :       0                               - if tramsmission was successful
01094                                                 status byte (>1)- if the reader signals a problem
01095                                                 error code (<0) - if something goes wrong
01096 ***************************************************************************/
01097 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ComputePageMAC(                                                
01098                 unsigned char ucPageNumber,
01099                 unsigned char& ucIndicator,
01100                 unsigned char& ucPageCRCStatus,
01101                 unsigned char* pucMAC)
01102 {
01103         //********************************************************************
01104         // ParameterTesting
01105         //Test Pointer for NULL
01106         FEDM_CHK3(pucMAC);
01107 
01108         //********************************************************************
01109         // Declaration
01110         unsigned int uiLengthOfResponseData = 0;
01111 
01112         //********************************************************************
01113         // RequestData
01114         m_ucRequestData[0] = 0xA5;      // Command
01115         m_ucRequestData[1] = ucPageNumber;
01116 
01117         for(int iCnt = 0; iCnt < 5; iCnt++)
01118         {
01119                 m_ucRequestData[2 + iCnt] = FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ucChallenge[iCnt];
01120         }
01121 
01122         //********************************************************************
01123         // CommandExecute
01124         int iBack = Apdu(m_ucRequestData, 7, m_ucResponseData, 256, uiLengthOfResponseData);
01125         if(iBack)
01126                 return iBack;
01127 
01128         //********************************************************************
01129         // ResponseData
01130         if(uiLengthOfResponseData > 0)
01131         {
01132                 ucIndicator = m_ucResponseData[0];
01133                 if(ucIndicator == 0)
01134                 {
01135                         ucPageCRCStatus = m_ucResponseData[1];
01136                         for(int iCnt = 0; iCnt < 20; iCnt++)
01137                         {
01138                                 pucMAC[iCnt] = m_ucResponseData[2 + iCnt];
01139                         }
01140                 }
01141         }
01142 
01143         return iBack;
01144 }
01145 
01146 /*******************************************************************************
01147   Begin                 :       06.10.2010 / M. Raner
01148 
01149   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
01150 
01151   Function                      :       [0xB2][0xBE][0x27] WriteAFI
01152   
01153   Parameters            :       unsigned char   ucAfiValue                      - [in]  new AFI Value that will be set on tag
01154                                                 unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
01155 
01156   Return value          :       0                               - if tramsmission was successful
01157                                                 status byte (>1)- if the reader signals a problem
01158                                                 error code (<0) - if something goes wrong
01159 *******************************************************************************/ 
01160 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::WriteAFI(                                                      
01161                 unsigned char ucAfiValue,
01162                 unsigned char& ucIndicator)
01163 {
01164         //********************************************************************
01165         // Declaration
01166         unsigned int uiLengthOfResponseData = 0;
01167 
01168         //********************************************************************
01169         // RequestData
01170         m_ucRequestData[0] = 0x27;      // Command
01171         m_ucRequestData[1] = ucAfiValue;
01172 
01173         //********************************************************************
01174         // CommandExecute
01175         int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
01176         if(iBack)
01177                 return iBack;
01178 
01179         //********************************************************************
01180         // ResponseData
01181         if(uiLengthOfResponseData > 0)
01182         {
01183                 ucIndicator = m_ucResponseData[0];
01184         }
01185 
01186         return iBack;
01187 }
01188 
01189 /*******************************************************************************
01190   Begin                 :       06.10.2010 / M. Raner
01191 
01192   Version               :       03.03.02 / 28.04.2011 / M. Raner, M. Hultsch
01193 
01194   Function                      :       [0xB2][0xBE][0x28] LockAFI
01195   
01196   Parameters            :       unsigned char&  ucIndicator                     - [out] response indicator byte (if 0x00 then command execution was successful)
01197 
01198   Return value          :       0                               - if tramsmission was successful
01199                                                 status byte (>1)- if the reader signals a problem
01200                                                 error code (<0) - if something goes wrong
01201 *******************************************************************************/ 
01202 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::LockAFI(                                                       
01203                 unsigned char& ucIndicator)
01204 {
01205         //********************************************************************
01206         // Declaration
01207         unsigned int uiLengthOfResponseData = 0;
01208 
01209         //********************************************************************
01210         // RequestData
01211         m_ucRequestData[0] = 0x28;      // Command
01212 
01213         //********************************************************************
01214         // CommandExecute
01215         int iBack = Apdu(m_ucRequestData, 1, m_ucResponseData, 256, uiLengthOfResponseData);
01216         if(iBack)
01217                 return iBack;
01218 
01219         //********************************************************************
01220         // ResponseData
01221         if(uiLengthOfResponseData > 0)
01222         {
01223                 ucIndicator = m_ucResponseData[0];
01224         }
01225 
01226         return iBack;
01227 }
01228 
01229 #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