FedmIscTagHandler_ISO14443_3_Infineon_my_d_move.cpp
Go to the documentation of this file.
00001 /*-------------------------------------------------------
00002 |                                                       |
00003 | FedmIscTagHandler_ISO14443_3_Infineon_my_d_move.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                  :       Manuel Sahm
00017 Begin                   :       17.12.2009
00018 
00019 Version                 :       03.01.00 / 10.02.2010 / M. Sahm, M. Hultsch
00020 
00021 Operation Systems       :       independent
00022 
00023 Function                        :       class for OBID® classic-pro transponder ISO14443-3 Infineon my-d_move
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_3_Infineon_my_d_move.h"
00037 #include "../../FEDM_Functions.h"
00038 #include "../FEDM_ISCReader.h"
00039 #include "../FEDM_ISOTabItem.h"
00040 #include "../FEDM_ISCReaderID.h"
00041 #include "../FEDM_ISC.h"
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_3_Infineon_my_d_move
00053 // >> supports only ISO Host Commands <<
00054 //####################################################################
00055 
00056 FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::FedmIscTagHandler_ISO14443_3_Infineon_my_d_move(
00057         FEDM_ISCReader* pReader, 
00058         FEDM_ISOTabItem* pTabItem )
00059         : FedmIscTagHandler_ISO14443_3(pReader, FedmIscTagHandler::TYPE_ISO14443_3_INFINEON_MY_D_MOVE, pTabItem)
00060 {
00061         m_sTagName = "ISO 14443-3 Type A : Infineon my-d move";
00062 }
00063 
00064 FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::FedmIscTagHandler_ISO14443_3_Infineon_my_d_move(
00065         FEDM_ISCReader* pReader, 
00066         unsigned int uiTagHandlerType,
00067         FEDM_ISOTabItem* pTabItem )
00068         : FedmIscTagHandler_ISO14443_3(pReader, uiTagHandlerType, pTabItem)
00069 {
00070         m_sTagName = "ISO 14443-3 Type A : Infineon my-d move";
00071 }
00072 
00073 FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::~FedmIscTagHandler_ISO14443_3_Infineon_my_d_move()
00074 {
00075 }
00076 
00077 // set all data members to 0
00078 /*void FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Init()
00079 {
00080 }*/
00081 
00082 
00083 /***************************************************************************
00084   Begin                 :       17.12.2009 / M. Sahm
00085 
00086   Version               :       03.01.00 / 20.01.2010 / M. Sahm, M. Hultsch
00087 
00088   Function                      :       [0x30][ADDR][CRC16]: Read 4 Blocks from my-d_move
00089 
00090                                                 NOTE: only for selected tags
00091 
00092   Parameters            :       unsigned char Address                                   - [in]  address: 0x00...0x25
00093                                                 unsigned char* pucData                                  - [out] buffer with data
00094                                                 unsigned int uiDataBufferLen                    - [in]  Size of the DataBuffer 
00095 
00096   Return value          :       0                               - if tramsmission was successful
00097                                                 status byte (>1)- if the reader signals a problem
00098                                                 error code (<0) - if something goes wrong
00099 ***************************************************************************/
00100 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Read4Blocks(unsigned char ucAddress, unsigned char* pucData, unsigned int uiDataBufferLen)
00101 {
00102         FEDM_CHK3(pucData);
00103 
00104         //Check buffer size
00105         if(uiDataBufferLen < 16)
00106         {
00107                 return FEDM_ERROR_ARRAY_BOUNDARY;
00108         }
00109 
00110         if(ucAddress < 0 || ucAddress > 0x25)
00111         {
00112                 return FEDM_ERROR_PARAMETER;    
00113         }
00114 
00115         int iErr = 0;
00116         unsigned char ucTransBuf[8];
00117         unsigned char ucRespBuf[64];
00118         int iRespLen = 0;
00119 
00120         // Build Transmit Data
00121         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00122 
00123         switch(m_pReader->GetReaderType())
00124         {
00125                 case FEDM_ISC_TYPE_CPR30_XX:
00126                 case FEDM_ISC_TYPE_CPR40_XX_U:
00127                 case FEDM_ISC_TYPE_CPR40_XX:
00128                 case FEDM_ISC_TYPE_CPR44_XX:
00129                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Enabled
00130                 break;
00131 
00132                 case FEDM_ISC_TYPE_CPR50_XX:
00133                 case FEDM_ISC_TYPE_CPR52_XX:
00134                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Odd enabled und Parity Enabled
00135                 break;
00136 
00137                 default:
00138                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00139         }
00140         
00141         ucTransBuf[2] = 0x00;           // TX-Settings = 106kBit/s
00142         ucTransBuf[3] = 0x00;           // RX-Settings = 106kBit/s
00143         ucTransBuf[4] = 0x00;           // ReqBits[0]
00144         ucTransBuf[5] = 0x10;           // ReqBits[1]  = 16 Bits : 0x30 ADDR
00145         ucTransBuf[6] = 0x30;           // ReqData[0]
00146         ucTransBuf[7] = ucAddress;      // ReqData[1]
00147 
00148         
00149         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00150                                                                                                 m_pReader->GetBusAddress(), 
00151                                                                                                 0x03,                                                                           // Mode 3
00152                                                                                                 144,                                                                            // expected 16 Byte Data + 2 Bytes CRC16
00153                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00154                                                                                                 8,                                                                                      // DataToSend
00155                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00156                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00157                                                                                                 0)                                                                                      // hex array
00158                                 );
00159 
00160         if(iErr == 0)
00161         {
00162                 //OK - Analyze the response Protocol
00163                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00164                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00165                 {
00166                         //STATUS: NACK0(0x0), or NACK1(0x1)
00167                         return 0x01; //No Transponder in Reader-Field
00168                 }
00169                 else if(uiRespBits == 144)
00170                 {
00171                         if(CalcCRC16Csum(&ucRespBuf[2], 18) == 0)
00172                         {
00173                                 memcpy(pucData, &ucRespBuf[2], 16);
00174                                 return FEDM_OK;
00175                         }
00176                         else
00177                         {
00178                                 //CRC-Error
00179                                 return 0x01; //No Transponder in Reader-Field                           
00180                         }
00181                 }
00182                 else
00183                 {
00184                         //Error
00185                         return 0x01; //No Transponder in Reader-Field
00186                 }
00187         }
00188         else
00189         {
00190                 //Status Byte > 0
00191                 return iErr;
00192         }
00193 }
00194 
00195 /***************************************************************************
00196   Begin                 :       17.12.2009 / M. Sahm
00197 
00198   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00199 
00200   Function                      :       [0xA2][ADDR][4 byte Data][CRC16]: Write 1 Block to my-d_move
00201 
00202                                                 NOTE: only for selected tags
00203 
00204   Parameters            :       unsigned char Address                                   - [in]  address: 0x02...0x24
00205                                                 unsigned char* pucData                                  - [in]  buffer with data
00206                                                 unsigned int uiDataBufferLen                    - [in]  Length of the Data in the Buffer 
00207 
00208   Return value          :       0                               - if tramsmission was successful
00209                                                 status byte (>1)- if the reader signals a problem
00210                                                 error code (<0) - if something goes wrong
00211 ***************************************************************************/
00212 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Write1Block(unsigned char ucAddress, unsigned char* pucData, unsigned int uiDataBufferLen)
00213 {
00214         FEDM_CHK3(pucData);
00215 
00216 
00217         //Check buffer size
00218         if(uiDataBufferLen < 4)
00219         {
00220                 return FEDM_ERROR_ARRAY_BOUNDARY;
00221         }
00222 
00223         if(ucAddress < 0x02 || ucAddress > 0x24)
00224         {
00225                 return FEDM_ERROR_PARAMETER;    
00226         }
00227 
00228         int iErr = 0;
00229         unsigned char ucTransBuf[12];
00230         unsigned char ucRespBuf[64];
00231         int iRespLen = 0;
00232 
00233         // Build Transmit Data
00234         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00235 
00236         switch(m_pReader->GetReaderType())
00237         {
00238                 case FEDM_ISC_TYPE_CPR30_XX:
00239                 case FEDM_ISC_TYPE_CPR40_XX_U:
00240                 case FEDM_ISC_TYPE_CPR40_XX:
00241                 case FEDM_ISC_TYPE_CPR44_XX:
00242                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Enabled
00243                 break;
00244 
00245                 case FEDM_ISC_TYPE_CPR50_XX:
00246                 case FEDM_ISC_TYPE_CPR52_XX:
00247                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Odd enabled und Parity Enabled
00248                 break;
00249 
00250                 default:
00251                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00252         }
00253         
00254         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00255         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00256         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00257         ucTransBuf[5] = 0x30;                   // ReqBits[1]  = 48 Bits : 0xA2 ADDR Data0 Data1 Data2 Data3
00258         ucTransBuf[6] = 0xA2;                   // ReqData[0]
00259         ucTransBuf[7] = ucAddress;              // ReqData[1]
00260         memcpy(&ucTransBuf[8], pucData, 4);     // ReqData[2]...[5]
00261 
00262         
00263         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00264                                                                                                 m_pReader->GetBusAddress(), 
00265                                                                                                 0x03,                                                                           // Mode 3
00266                                                                                                 4,                                                                                      // expected 4 Bit Data
00267                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00268                                                                                                 12,                                                                                     // DataToSend
00269                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00270                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00271                                                                                                 0)                                                                                      // hex array
00272                                 );
00273 
00274         if(iErr == 0)
00275         {
00276                 //OK - Analyze the response Protocol
00277                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00278                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00279                 {
00280                         //STATUS: NACK0(0x0), or NACK1(0x1)
00281                         return 0x01; //No Transponder in Reader-Field
00282                 }
00283                 else if((uiRespBits == 4) && (ucRespBuf[2] == 0x0A))
00284                 {
00285                         //STATUS: ACK0(0xA)
00286                         return FEDM_OK;
00287                 }
00288                 else
00289                 {
00290                         //Error
00291                         return 0x01; //No Transponder in Reader-Field
00292                 }
00293         }
00294         else
00295         {
00296                 //Status Byte > 0
00297                 return iErr;
00298         }
00299 }
00300 
00301 /***************************************************************************
00302   Begin                 :       17.12.2009 / M. Sahm
00303 
00304   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00305 
00306   Function                      :       [0xA0][ADDR][16 Byte data][CRC16]: Compatibility Write Command from my-d_move
00307 
00308                                                 NOTE: only for selected tags
00309 
00310   Parameters            :       unsigned char Address                                   - [in]  address: 0x02...0x24
00311                                                 unsigned char* pucData                                  - [in]  buffer with data
00312                                                 unsigned int uiDataBufferLen                    - [in]  Length of the Data in the Buffer 
00313 
00314   Return value          :       0                               - if tramsmission was successful
00315                                                 status byte (>1)- if the reader signals a problem
00316                                                 error code (<0) - if something goes wrong
00317 ***************************************************************************/
00318 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::CompatibilityWriteCmd(unsigned char ucAddress, unsigned char* pucData, unsigned int uiDataBufferLen)
00319 {
00320         FEDM_CHK3(pucData);
00321 
00322         //Check buffer size
00323         if(uiDataBufferLen < 16)
00324         {
00325                 return FEDM_ERROR_ARRAY_BOUNDARY;
00326         }
00327 
00328         if(ucAddress < 0x02 || ucAddress > 0x24)
00329         {
00330                 return FEDM_ERROR_PARAMETER;    
00331         }
00332 
00333         int iErr = 0;
00334         unsigned char ucTransBuf[22];
00335         unsigned char ucRespBuf[64];
00336         int iRespLen = 0;
00337 
00338         //------------------//
00339         // ----- STEP 1 --- //
00340         //------------------//
00341 
00342         // Build Transmit Data
00343         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00344 
00345         switch(m_pReader->GetReaderType())
00346         {
00347                 case FEDM_ISC_TYPE_CPR30_XX:
00348                 case FEDM_ISC_TYPE_CPR40_XX_U:
00349                 case FEDM_ISC_TYPE_CPR40_XX:
00350                 case FEDM_ISC_TYPE_CPR44_XX:
00351                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Enabled
00352                 break;
00353 
00354                 case FEDM_ISC_TYPE_CPR50_XX:
00355                 case FEDM_ISC_TYPE_CPR52_XX:
00356                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Odd enabled und Parity Enabled
00357                 break;
00358 
00359                 default:
00360                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00361         }
00362         
00363         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00364         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00365         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00366         ucTransBuf[5] = 0x10;                   // ReqBits[1]  = 16 Bits : 0xA0 ADDR
00367         ucTransBuf[6] = 0xA0;                   // ReqData[0]
00368         ucTransBuf[7] = ucAddress;              // ReqData[1]
00369 
00370         
00371         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00372                                                                                                 m_pReader->GetBusAddress(), 
00373                                                                                                 0x03,                                                                           // Mode 3
00374                                                                                                 4,                                                                                      // expected 4 Bit Data
00375                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00376                                                                                                 8,                                                                                      // DataToSend
00377                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00378                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00379                                                                                                 0)                                                                                      // hex array
00380                                 );
00381 
00382         if(iErr == 0)
00383         {
00384                 //OK - Analyze the response Protocol
00385                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00386                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00387                 {
00388                         //STATUS: NACK0(0x0), or NACK1(0x1)
00389                         return 0x01; //No Transponder in Reader-Field
00390                 }
00391                 else if((uiRespBits == 4) && (ucRespBuf[2] == 0x0A))
00392                 {
00393                         //STATUS: ACK0(0xA)
00394                 }
00395                 else
00396                 {
00397                         //Error
00398                         return 0x01; //No Transponder in Reader-Field
00399                 }
00400         }
00401         else
00402         {
00403                 //Status Byte > 0
00404                 return iErr;
00405         }
00406 
00407 
00408         //------------------//
00409         // ----- STEP 2 --- //
00410         //------------------//
00411         iRespLen = 0;
00412 
00413         // Build Transmit Data
00414         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00415 
00416         switch(m_pReader->GetReaderType())
00417         {
00418                 case FEDM_ISC_TYPE_CPR30_XX:
00419                 case FEDM_ISC_TYPE_CPR40_XX_U:
00420                 case FEDM_ISC_TYPE_CPR40_XX:
00421                 case FEDM_ISC_TYPE_CPR44_XX:
00422                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Enabled
00423                 break;
00424 
00425                 case FEDM_ISC_TYPE_CPR50_XX:
00426                 case FEDM_ISC_TYPE_CPR52_XX:
00427                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Odd enabled und Parity Enabled
00428                 break;
00429 
00430                 default:
00431                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00432         }
00433         
00434         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00435         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00436         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00437         ucTransBuf[5] = 0x80;                   // ReqBits[1]  = 128 Bits : Data0 ... Data15
00438         memcpy(&ucTransBuf[6], pucData, 16);
00439         
00440         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00441                                                                                                 m_pReader->GetBusAddress(), 
00442                                                                                                 0x03,                                                                           // Mode 3
00443                                                                                                 4,                                                                                      // expected 4 Bit Data
00444                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00445                                                                                                 22,                                                                                     // DataToSend
00446                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00447                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00448                                                                                                 0)                                                                                      // hex array
00449                                 );
00450 
00451         if(iErr == 0)
00452         {
00453                 //OK - Analyze the response Protocol
00454                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00455                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00456                 {
00457                         //STATUS: NACK0(0x0), or NACK1(0x1)
00458                         return 0x01; //No Transponder in Reader-Field
00459                 }
00460                 else if((uiRespBits == 4) && (ucRespBuf[2] == 0x0A))
00461                 {
00462                         //STATUS: ACK0(0xA)
00463                         return FEDM_OK;
00464                 }
00465                 else
00466                 {
00467                         //Error
00468                         return 0x01; //No Transponder in Reader-Field
00469                 }
00470         }
00471         else
00472         {
00473                 //Status Byte > 0
00474                 return iErr;
00475         }
00476 }
00477 
00478 /***************************************************************************
00479   Begin                 :       17.12.2009 / M. Sahm
00480 
00481   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00482 
00483   Function                      :       [0x31][ADDR][CRC16]: Read 2 Blocks from my-d_move
00484 
00485                                                 NOTE: only for selected tags
00486 
00487   Parameters            :       unsigned char Address                                   - [in]  address: 0x00...0x25
00488                                                 unsigned char* pucData                                  - [out] buffer with data
00489                                                 unsigned int uiDataBufferLen                    - [in]  Size of the DataBuffer 
00490 
00491   Return value          :       0                               - if tramsmission was successful
00492                                                 status byte (>1)- if the reader signals a problem
00493                                                 error code (<0) - if something goes wrong
00494 ***************************************************************************/
00495 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Read2Blocks(unsigned char ucAddress, unsigned char* pucData, unsigned int uiDataBufferLen)
00496 {
00497         FEDM_CHK3(pucData);
00498 
00499         //Check buffer size
00500         if(uiDataBufferLen < 8)
00501         {
00502                 return FEDM_ERROR_ARRAY_BOUNDARY;
00503         }
00504 
00505         if(ucAddress < 0 || ucAddress > 0x25)
00506         {
00507                 return FEDM_ERROR_PARAMETER;    
00508         }
00509 
00510         int iErr = 0;
00511         unsigned char ucTransBuf[8];
00512         unsigned char ucRespBuf[64];
00513         int iRespLen = 0;
00514 
00515         // Build Transmit Data
00516         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00517 
00518         switch(m_pReader->GetReaderType())
00519         {
00520                 case FEDM_ISC_TYPE_CPR30_XX:
00521                 case FEDM_ISC_TYPE_CPR40_XX_U:
00522                 case FEDM_ISC_TYPE_CPR40_XX:
00523                 case FEDM_ISC_TYPE_CPR44_XX:
00524                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Enabled
00525                 break;
00526 
00527                 case FEDM_ISC_TYPE_CPR50_XX:
00528                 case FEDM_ISC_TYPE_CPR52_XX:
00529                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Odd enabled und Parity Enabled
00530                 break;
00531 
00532                 default:
00533                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00534         }
00535         
00536         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00537         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00538         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00539         ucTransBuf[5] = 0x10;                   // ReqBits[1]  = 16 Bits : 0x30 ADDR
00540         ucTransBuf[6] = 0x31;                   // ReqData[0]
00541         ucTransBuf[7] = ucAddress;              // ReqData[1]
00542 
00543         
00544         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00545                                                                                                 m_pReader->GetBusAddress(), 
00546                                                                                                 0x03,                                                                           // Mode 3
00547                                                                                                 80,                                                                             // expected 8 Byte Data + 2 Bytes CRC16
00548                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00549                                                                                                 8,                                                                                      // DataToSend
00550                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00551                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00552                                                                                                 0)                                                                                      // hex array
00553                                 );
00554 
00555         if(iErr == 0)
00556         {
00557                 //OK - Analyze the response Protocol
00558                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00559                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00560                 {
00561                         //STATUS: NACK0(0x0), or NACK1(0x1)
00562                         return 0x01; //No Transponder in Reader-Field
00563                 }
00564                 else if(uiRespBits == 80)
00565                 {
00566                         if(CalcCRC16Csum(&ucRespBuf[2], 10) == 0)
00567                         {
00568                                 memcpy(pucData, &ucRespBuf[2], 8);
00569                                 return FEDM_OK;
00570                         }
00571                         else
00572                         {
00573                                 //CRC-Error
00574                                 return 0x01; //No Transponder in Reader-Field                           
00575                         }
00576                 }
00577                 else
00578                 {
00579                         //Error
00580                         return 0x01; //No Transponder in Reader-Field
00581                 }
00582         }
00583         else
00584         {
00585                 //Status Byte > 0
00586                 return iErr;
00587         }
00588 }
00589 
00590 /***************************************************************************
00591   Begin                 :       17.12.2009 / M. Sahm
00592 
00593   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00594 
00595   Function                      :       [0xA1][ADDR][8 Byte Data][CRC16]: Write 2 Blocks to my-d_move
00596 
00597                                                 NOTE: only for selected tags
00598 
00599   Parameters            :       unsigned char Address                                   - [in]  address: 0x00...0x25
00600                                                 unsigned char* pucData                                  - [in]  buffer with data
00601                                                 unsigned int uiDataBufferLen                    - [in]  Length of the Data in the Buffer 
00602 
00603   Return value          :       0                               - if tramsmission was successful
00604                                                 status byte (>1)- if the reader signals a problem
00605                                                 error code (<0) - if something goes wrong
00606 ***************************************************************************/
00607 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Write2Blocks(unsigned char ucAddress, unsigned char* pucData, unsigned int uiDataBufferLen)
00608 {
00609         FEDM_CHK3(pucData);
00610 
00611         //Check buffer size
00612         if(uiDataBufferLen < 4)
00613         {
00614                 return FEDM_ERROR_ARRAY_BOUNDARY;
00615         }
00616 
00617         if(ucAddress < 0x04 || ucAddress > 0x22)
00618         {
00619                 return FEDM_ERROR_PARAMETER;    
00620         }
00621 
00622         //Only even start addresses allowed
00623         if(ucAddress % 2)
00624         {
00625                 return FEDM_ERROR_PARAMETER;
00626         }
00627 
00628         int iErr = 0;
00629         unsigned char ucTransBuf[16];
00630         unsigned char ucRespBuf[64];
00631         int iRespLen = 0;
00632 
00633         // Build Transmit Data
00634         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00635 
00636         switch(m_pReader->GetReaderType())
00637         {
00638                 case FEDM_ISC_TYPE_CPR30_XX:
00639                 case FEDM_ISC_TYPE_CPR40_XX_U:
00640                 case FEDM_ISC_TYPE_CPR40_XX:
00641                 case FEDM_ISC_TYPE_CPR44_XX:
00642                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Enabled
00643                 break;
00644 
00645                 case FEDM_ISC_TYPE_CPR50_XX:
00646                 case FEDM_ISC_TYPE_CPR52_XX:
00647                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC disabled and Parity Odd enabled und Parity Enabled
00648                 break;
00649 
00650                 default:
00651                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00652         }
00653         
00654         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00655         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00656         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00657         ucTransBuf[5] = 0x50;                   // ReqBits[1]  = 80 Bits : 0xA1 ADDR Data0...Data7
00658         ucTransBuf[6] = 0xA1;                   // ReqData[0]
00659         ucTransBuf[7] = ucAddress;              // ReqData[1]
00660         memcpy(&ucTransBuf[8], pucData, 8);// ReqData[2]...[9]
00661 
00662         
00663         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00664                                                                                                 m_pReader->GetBusAddress(), 
00665                                                                                                 0x03,                                                                           // Mode 3
00666                                                                                                 4,                                                                                      // expected 4 Bit Data
00667                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00668                                                                                                 16,                                                                                     // DataToSend
00669                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00670                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00671                                                                                                 0)                                                                                      // hex array
00672                                 );
00673 
00674         if(iErr == 0)
00675         {
00676                 //OK - Analyze the response Protocol
00677                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00678                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00679                 {
00680                         //STATUS: NACK0(0x0), or NACK1(0x1)
00681                         return 0x01; //No Transponder in Reader-Field
00682                 }
00683                 else if((uiRespBits == 4) && (ucRespBuf[2] == 0x0A))
00684                 {
00685                         //STATUS: ACK0(0xA)
00686                         return FEDM_OK;
00687                 }
00688                 else
00689                 {
00690                         //Error
00691                         return 0x01; //No Transponder in Reader-Field
00692                 }
00693         }
00694         else
00695         {
00696                 //Status Byte > 0
00697                 return iErr;
00698         }
00699 }
00700 
00701 /***************************************************************************
00702   Begin                 :       17.12.2009 / M. Sahm
00703 
00704   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00705 
00706   Function                      :       [0xB1][4 Byte Password][CRC16]: Set Password of my-d_move
00707 
00708                                                 NOTE: only for selected tags
00709 
00710   Parameters            :       string& sPassword                                                       - [in]  password
00711 
00712   Return value          :       0                               - if tramsmission was successful
00713                                                 status byte (>1)- if the reader signals a problem
00714                                                 error code (<0) - if something goes wrong
00715 ***************************************************************************/
00716 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::SetPassword(string& sPassword)
00717 {
00718         //Check buffer size
00719         if(sPassword.length() < 8)
00720         {
00721                 return FEDM_ERROR_STRING_LENGTH;
00722         }
00723 
00724         int iErr = 0;
00725         unsigned char ucTransBuf[12];
00726         unsigned char ucRespBuf[64];
00727         int iRespLen = 0;
00728 
00729         // Build Transmit Data
00730         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00731 
00732         switch(m_pReader->GetReaderType())
00733         {
00734                 case FEDM_ISC_TYPE_CPR30_XX:
00735                 case FEDM_ISC_TYPE_CPR40_XX_U:
00736                 case FEDM_ISC_TYPE_CPR40_XX:
00737                 case FEDM_ISC_TYPE_CPR44_XX:
00738                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Enabled
00739                 break;
00740 
00741                 case FEDM_ISC_TYPE_CPR50_XX:
00742                 case FEDM_ISC_TYPE_CPR52_XX:
00743                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Odd enabled und Parity Enabled
00744                 break;
00745 
00746                 default:
00747                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00748         }
00749         
00750         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00751         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00752         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00753         ucTransBuf[5] = 0x28;                   // ReqBits[1]  = 40 Bits : 0xB1 P0...P3
00754         ucTransBuf[6] = 0xB1;                   // ReqData[0]
00755         FEDM_ConvHexStrToHexUChar(sPassword, &ucTransBuf[7], 4); //ReqData[1]...[4]
00756 
00757         
00758         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00759                                                                                                 m_pReader->GetBusAddress(), 
00760                                                                                                 0x03,                                                                           // Mode 3
00761                                                                                                 48,                                                                                     // expected 4 Bytes Data + 2 Bytes CRC
00762                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00763                                                                                                 11,                                                                                     // DataToSend
00764                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00765                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00766                                                                                                 0)                                                                                      // hex array
00767                                 );
00768 
00769         if(iErr == 0)
00770         {
00771                 //OK - Analyze the response Protocol
00772                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00773                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00774                 {
00775                         //STATUS: NACK0(0x0), or NACK1(0x1)
00776                         return 0x01; //No Transponder in Reader-Field
00777                 }
00778                 else if(uiRespBits == 48)
00779                 {
00780                         if(CalcCRC16Csum(&ucRespBuf[2], 6) == 0)
00781                         {
00782                                 FEDM_ConvHexUCharToHexStr(&ucRespBuf[2], 4, sPassword);
00783                                 return FEDM_OK;
00784                         }
00785                         else
00786                         {
00787                                 //CRC-Error
00788                                 return 0x01; //No Transponder in Reader-Field                           
00789                         }
00790                 }
00791                 else
00792                 {
00793                         //Error
00794                         return 0x01; //No Transponder in Reader-Field
00795                 }
00796         }
00797         else
00798         {
00799                 //Status Byte > 0
00800                 return iErr;
00801         }
00802 
00803 }
00804 
00805 /***************************************************************************
00806   Begin                 :       17.12.2009 / M. Sahm
00807 
00808   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00809 
00810   Function                      :       [0xB2][4 Byte Password][CRC16]: Access with password of my-d_move
00811 
00812                                                 NOTE: only for selected tags
00813 
00814   Parameters            :       string sPassword                                - [in]  password
00815 
00816   Return value          :       0                               - if tramsmission was successful
00817                                                 status byte (>1)- if the reader signals a problem
00818                                                 error code (<0) - if something goes wrong
00819 ***************************************************************************/
00820 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Access(string sPassword)
00821 {
00822         //Check buffer size
00823         if(sPassword.length() < 8)
00824         {
00825                 return FEDM_ERROR_STRING_LENGTH;
00826         }
00827 
00828         int iErr = 0;
00829         unsigned char ucTransBuf[12];
00830         unsigned char ucRespBuf[64];
00831         int iRespLen = 0;
00832 
00833         // Build Transmit Data
00834         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00835 
00836         switch(m_pReader->GetReaderType())
00837         {
00838                 case FEDM_ISC_TYPE_CPR30_XX:
00839                 case FEDM_ISC_TYPE_CPR40_XX_U:
00840                 case FEDM_ISC_TYPE_CPR40_XX:
00841                 case FEDM_ISC_TYPE_CPR44_XX:
00842                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Enabled
00843                 break;
00844 
00845                 case FEDM_ISC_TYPE_CPR50_XX:
00846                 case FEDM_ISC_TYPE_CPR52_XX:
00847                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Odd enabled und Parity Enabled
00848                 break;
00849 
00850                 default:
00851                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00852         }
00853         
00854         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00855         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00856         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00857         ucTransBuf[5] = 0x28;                   // ReqBits[1]  = 40 Bits : 0xB2 Data0...Data3
00858         ucTransBuf[6] = 0xB2;                   // ReqData[0]
00859         FEDM_ConvHexStrToHexUChar(sPassword, &ucTransBuf[7], 5); //ReqData[1]...[4]
00860 
00861         
00862         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00863                                                                                                 m_pReader->GetBusAddress(), 
00864                                                                                                 0x03,                                                                           // Mode 3
00865                                                                                                 4,                                                                                      // expected 4 Bit Data
00866                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00867                                                                                                 11,                                                                                     // DataToSend
00868                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00869                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00870                                                                                                 0)                                                                                      // hex array
00871                                 );
00872 
00873         if(iErr == 0)
00874         {
00875                 //OK - Analyze the response Protocol
00876                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00877                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00878                 {
00879                         //STATUS: NACK0(0x0), or NACK1(0x1)
00880                         return 0x01; //No Transponder in Reader-Field
00881                 }
00882                 else if((uiRespBits == 4) && (ucRespBuf[2] == 0x0A))
00883                 {
00884                         //STATUS: ACK0(0xA)
00885                         return FEDM_OK;
00886                 }
00887                 else
00888                 {
00889                         //Error
00890                         return 0x01; //No Transponder in Reader-Field
00891                 }
00892         }
00893         else
00894         {
00895                 //Status Byte > 0
00896                 return iErr;
00897         }
00898 }
00899 
00900 /***************************************************************************
00901   Begin                 :       17.12.2009 / M. Sahm
00902 
00903   Version               :       03.01.00 / 17.12.2009 / M. Sahm
00904 
00905   Function                      :       [0xD0][2 Byte Counter Value][CRC16]: Decrement the Value Counter
00906 
00907                                                 NOTE: only for selected tags
00908 
00909   Parameters            :       unsigned int uiCounterValue                             - [in]  LSByte = CNT0
00910                                                                                                                                                 MSByte = CNT1
00911                                                 
00912   Return value          :       0                               - if tramsmission was successful
00913                                                 status byte (>1)- if the reader signals a problem
00914                                                 error code (<0) - if something goes wrong
00915 ***************************************************************************/
00916 int FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::Decrement(unsigned int& uiCounterValue)
00917 {
00918         //Check buffer size
00919         if(uiCounterValue > 4095)
00920         {
00921                 return FEDM_ERROR_PARAMETER;
00922         }
00923 
00924         int iErr = 0;
00925         unsigned char ucTransBuf[9];
00926         unsigned char ucRespBuf[64];
00927         int iRespLen = 0;
00928 
00929         // Build Transmit Data
00930         ucTransBuf[0] = 0x7F;                   // Timoeut = 127ms
00931 
00932         switch(m_pReader->GetReaderType())
00933         {
00934                 case FEDM_ISC_TYPE_CPR30_XX:
00935                 case FEDM_ISC_TYPE_CPR40_XX_U:
00936                 case FEDM_ISC_TYPE_CPR40_XX:
00937                 case FEDM_ISC_TYPE_CPR44_XX:
00938                         ucTransBuf[1] = 0x05;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Enabled
00939                 break;
00940 
00941                 case FEDM_ISC_TYPE_CPR50_XX:
00942                 case FEDM_ISC_TYPE_CPR52_XX:
00943                         ucTransBuf[1] = 0x07;                   // CRC-Info        = TxCRC Enabled, RxCRC Disabled and Parity Odd enabled und Parity Enabled
00944                 break;
00945 
00946                 default:
00947                         return FEDM_ERROR_UNKNOWN_READER_TYPE;
00948         }
00949         
00950         ucTransBuf[2] = 0x00;                   // TX-Settings = 106kBit/s
00951         ucTransBuf[3] = 0x00;                   // RX-Settings = 106kBit/s
00952         ucTransBuf[4] = 0x00;                   // ReqBits[0]
00953         ucTransBuf[5] = 0x18;                   // ReqBits[1]  = 24 Bits : 0xD0 Data0 Data1
00954         ucTransBuf[6] = 0xD0;                   // ReqData[0]
00955         ucTransBuf[7] = (unsigned char) (uiCounterValue & 0xFF);                        // ReqData[1]
00956         ucTransBuf[8] = (unsigned char)((uiCounterValue >> 8) & 0xFF);  // ReqData[2]
00957         
00958         
00959         FEDM_CHK1       (iErr, FEISC_0xBD_ISOTranspCmd( m_pReader->GetReaderHnd(), 
00960                                                                                                 m_pReader->GetBusAddress(), 
00961                                                                                                 0x03,                                                                           // Mode 3
00962                                                                                                 32,                                                                                     // expected 16 Bit Data + 2 Bytes CRC
00963                                                                                                 ucTransBuf,                                                                     // ucTransBuf
00964                                                                                                 9,                                                                                      // DataToSend
00965                                                                                                 ucRespBuf,                                                                      // ucRespBuf
00966                                                                                                 &iRespLen,                                                                      // Length of response in Bytes
00967                                                                                                 0)                                                                                      // hex array
00968                                 );
00969 
00970         if(iErr == 0)
00971         {
00972                 //OK - Analyze the response Protocol
00973                 unsigned int uiRespBits = ((unsigned int)ucRespBuf[0] << 8) | (unsigned int)ucRespBuf[1];
00974                 if((uiRespBits == 4) && ((ucRespBuf[2] == 0x00) || (ucRespBuf[2] == 0x01)))
00975                 {
00976                         //STATUS: NACK0(0x0), or NACK1(0x1)
00977                         return 0x01; //No Transponder in Reader-Field
00978                 }
00979                 else if(uiRespBits == 32)
00980                 {
00981                         if(CalcCRC16Csum(&ucRespBuf[2], 4) == 0)
00982                         {
00983                                 uiCounterValue = ucRespBuf[2];
00984                                 uiCounterValue |= (ucRespBuf[3] << 8);
00985                                 return FEDM_OK;
00986                         }
00987                         else
00988                         {
00989                                 //CRC-Error
00990                                 return 0x01; //No Transponder in Reader-Field                           
00991                         }
00992                 }
00993                 else
00994                 {
00995                         //Error
00996                         return 0x01; //No Transponder in Reader-Field
00997                 }
00998         }
00999         else
01000         {
01001                 //Status Byte > 0
01002                 return iErr;
01003         }
01004 }
01005 
01006 /***************************************************************************
01007   Begin                 :       20.01.2010 / M. Sahm
01008 
01009   Version               :       03.01.00 / 20.10.2010 / M. Sahm
01010 
01011   Function                      :       Claculates the CRC16 from ISO 14443A Data
01012 
01013 
01014   Parameters            :       unsigned char *                 pData
01015                                                 unsigned int                    uiDataLen
01016                                                 
01017   Return value          :       CRC16 Value
01018 ***************************************************************************/
01019 unsigned short FedmIscTagHandler_ISO14443_3_Infineon_my_d_move::CalcCRC16Csum(unsigned char *pucData, unsigned int uiDataLen)
01020 {
01021         unsigned short usCrc = 0x6363;
01022         unsigned char chBlock;
01023 
01024         do
01025         {
01026                 chBlock = *pucData++;
01027                 chBlock = (chBlock^(unsigned char)((usCrc) & 0x00FF));
01028                 chBlock = (chBlock^(chBlock<<4));
01029                 usCrc = (usCrc>>8)^((unsigned short)chBlock<<8)^((unsigned short) chBlock <<3)^((unsigned short)chBlock >>4);
01030         }while(--uiDataLen);
01031 
01032         return usCrc;
01033 }
01034 
01035 #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