00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00053
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
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
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
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
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
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
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
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
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
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
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
00479
00480
00481
00482
00483
00484
00485 unsigned int uiW[80];
00486 unsigned int uiA = 0x67452301;
00487 unsigned int uiB = 0xEFCDAB89;
00488 unsigned int uiC = 0x98BADCFE;
00489 unsigned int uiD = 0x10325476;
00490 unsigned int uiE = 0xC3D2E1F0;
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
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);
00514 uiK = 0x5A827999;
00515 }
00516 else if (iCnt2 >= 20 && iCnt2 <= 39)
00517 {
00518 uiF = uiB ^ uiC ^ uiD;
00519 uiK = 0x6ED9EBA1;
00520 }
00521 else if (iCnt2 >= 40 && iCnt2 <= 59)
00522 {
00523 uiF = (uiB & uiC) | (uiB & uiD) | (uiC & uiD);
00524 uiK = 0x8F1BBCDC;
00525 }
00526 else if (iCnt2 >= 60 && iCnt2 <= 79)
00527 {
00528 uiF = uiB ^ uiC ^ uiD;
00529 uiK = 0xCA62C1D6;
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
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
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
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
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
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 FEDM_CHK3(pucPartialSecret);
00618
00619
00620 if(!(ucControlByte == 0xF0 ||
00621 ucControlByte == 0x0F ||
00622 (ucControlByte & 0x05) == 0x05 ||
00623 (ucControlByte & 0x0A) == 0x0A ||
00624 ucControlByte == 0xAA))
00625 {
00626
00627 return FEDM_ERROR_PARAMETER;
00628 }
00629
00630
00631
00632 unsigned int uiLengthOfResponseData = 0;
00633
00634
00635
00636 m_ucRequestData[0] = 0xA0;
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
00645
00646 int iBack = Apdu(m_ucRequestData, 10, m_ucResponseData, 256, uiLengthOfResponseData);
00647 if(iBack)
00648 return iBack;
00649
00650
00651
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
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::WriteBuffer(
00680 unsigned char ucBlockNumber,
00681 unsigned char* pucNewBlockData,
00682 unsigned char& ucIndicator)
00683 {
00684
00685
00686
00687 FEDM_CHK3(pucNewBlockData);
00688
00689
00690
00691 unsigned int uiLengthOfResponseData = 0;
00692
00693
00694
00695 m_ucRequestData[0] = 0xA1;
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
00704 int iBack = Apdu(m_ucRequestData, 10, m_ucResponseData, 256, uiLengthOfResponseData);
00705 if(iBack)
00706 return iBack;
00707
00708
00709
00710 if(uiLengthOfResponseData > 0)
00711 {
00712 ucIndicator = m_ucResponseData[0];
00713 }
00714
00715 return iBack;
00716 }
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ReadBuffer(
00734 unsigned char& ucIndicator,
00735 unsigned char& ucBlockNumber,
00736 unsigned char* pucReadWriteBufferData)
00737 {
00738
00739
00740
00741 FEDM_CHK3(pucReadWriteBufferData);
00742
00743
00744
00745 unsigned int uiLengthOfResponseData = 0;
00746
00747
00748
00749 m_ucRequestData[0] = 0xA2;
00750
00751
00752
00753 int iBack = Apdu(m_ucRequestData, 1, m_ucResponseData, 256, uiLengthOfResponseData);
00754 if(iBack)
00755 return iBack;
00756
00757
00758
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
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
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
00799
00800 FEDM_CHK3(pucMAC);
00801
00802
00803
00804 unsigned int uiLengthOfResponseData = 0;
00805
00806
00807
00808 m_ucRequestData[0] = 0xA3;
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
00818 int iBack = Apdu(m_ucRequestData, 22, m_ucResponseData, 256, uiLengthOfResponseData);
00819 if(iBack)
00820 return iBack;
00821
00822
00823
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
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::ReadSingleBlock(
00852 unsigned char ucBlockNumber,
00853 unsigned char& ucIndicator,
00854 unsigned char* pucMemoryData)
00855 {
00856
00857
00858
00859 FEDM_CHK3(pucMemoryData);
00860
00861
00862
00863 unsigned int uiLengthOfResponseData = 0;
00864
00865
00866
00867 m_ucRequestData[0] = 0x20;
00868 m_ucRequestData[1] = ucBlockNumber;
00869
00870
00871
00872 int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00873 if(iBack)
00874 return iBack;
00875
00876
00877
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
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
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
00917
00918 FEDM_CHK3(pucMemoryData);
00919
00920
00921
00922 unsigned int uiLengthOfResponseData = 0;
00923
00924
00925
00926 m_ucRequestData[0] = 0xB0;
00927 m_ucRequestData[1] = ucBlockNumber;
00928
00929
00930
00931 int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00932 if(iBack)
00933 return iBack;
00934
00935
00936
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
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
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
00978
00979 FEDM_CHK3(pucMemoryData);
00980 FEDM_CHK3(pucIntegrityBytes);
00981
00982
00983
00984 unsigned int uiLengthOfResponseData = 0;
00985
00986
00987
00988 m_ucRequestData[0] = 0xA4;
00989 m_ucRequestData[1] = ucBlockNumber;
00990
00991
00992
00993 int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
00994 if(iBack)
00995 return iBack;
00996
00997
00998
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
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
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
01042
01043 FEDM_CHK3(pucMemoryData);
01044 FEDM_CHK3(pucIntegrityBytes);
01045
01046
01047
01048 unsigned int uiLengthOfResponseData = 0;
01049
01050
01051
01052 m_ucRequestData[0] = 0xB4;
01053 m_ucRequestData[1] = ucBlockNumber;
01054
01055
01056
01057 int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
01058 if(iBack)
01059 return iBack;
01060
01061
01062
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
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
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
01105
01106 FEDM_CHK3(pucMAC);
01107
01108
01109
01110 unsigned int uiLengthOfResponseData = 0;
01111
01112
01113
01114 m_ucRequestData[0] = 0xA5;
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
01124 int iBack = Apdu(m_ucRequestData, 7, m_ucResponseData, 256, uiLengthOfResponseData);
01125 if(iBack)
01126 return iBack;
01127
01128
01129
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
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::WriteAFI(
01161 unsigned char ucAfiValue,
01162 unsigned char& ucIndicator)
01163 {
01164
01165
01166 unsigned int uiLengthOfResponseData = 0;
01167
01168
01169
01170 m_ucRequestData[0] = 0x27;
01171 m_ucRequestData[1] = ucAfiValue;
01172
01173
01174
01175 int iBack = Apdu(m_ucRequestData, 2, m_ucResponseData, 256, uiLengthOfResponseData);
01176 if(iBack)
01177 return iBack;
01178
01179
01180
01181 if(uiLengthOfResponseData > 0)
01182 {
01183 ucIndicator = m_ucResponseData[0];
01184 }
01185
01186 return iBack;
01187 }
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202 int FedmIscTagHandler_ISO14443_4_Maxim_MAX66040::LockAFI(
01203 unsigned char& ucIndicator)
01204 {
01205
01206
01207 unsigned int uiLengthOfResponseData = 0;
01208
01209
01210
01211 m_ucRequestData[0] = 0x28;
01212
01213
01214
01215 int iBack = Apdu(m_ucRequestData, 1, m_ucResponseData, 256, uiLengthOfResponseData);
01216 if(iBack)
01217 return iBack;
01218
01219
01220
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)