//////////////////////////////////////////////// //MifareTest Card explorer V.1.00 //Programma realizzato da Francesco Germinara //www.germinara.it 2005 FREEWARE //info@germinara.it //http://www.germinara.it //programmatore PINEROLO TORINO ITALIA //Data realizzazione: 19/luglio/2005 //////////////////////////////////////////////// // // Thanks to Stoyan Yordanov for the help and the technical support. //////////////////////////////////////////////////////////////////////// // MIFARETestView.h : interface of the CMIFARETestView class // #pragma once #include "GemTagAPI.h" //This enum must match the CStringArray saMifareCardType in CFGMifareObj enum MifareCartTypeID { MIFARE_ULTRA_LIGTH, MIFARE_1K, MIFARE_4K, MIFARE_DES_FIRE, MIFARE_ProX, MIFARE_SmartMX, eEND }; typedef struct _tag_card_data { unsigned char HasPart4; //I don't know what this mean I believe that is T=CL Support unsigned short BlocksCount; unsigned char SectorsCount; unsigned char Method; MIF_SINGLE_UID ChipID; }CARD_DATA; #define UNKNOW_METHOD 0x000 #define ULTRA_LIGTH_METHOD 0x001 #define MIFARE_1K_METHOD 0x002 #define MIFARE_4K_METHOD 0x003 #define MIFARE_DES_FIRE_METHOD 0x004 #define T_CL_METHOD 0x005 #define KEY_A 0 #define KEY_B 1 #define WRITE_KEY_A 2 #define WRITE_KEY_B 3 #define ID_CARD_REMOVED 9999 class CFGMifareCard { private: CString strCardType; //Card Type Description CARD_DATA cardInfo; //Card Info (UID, Number of block, Number of sector,Has Part4 ??? CString strCardUID; //Card Type UID int nMethodType; //Type of call method supported unsigned char KeyA[6]; //Default Key A value unsigned char KeyB[6]; //Default Key B value public: CFGMifareCard(); ~CFGMifareCard(); friend class CFGMifareObj; void ClearData(); //Clear data structure void SetCardType(CString str); //Set Card Type Description CString CardType(); //Get the Card Type Description void SetMethodType(int meth); //Set type of method call int MethodType(int meth); //Get the type of method call CARD_DATA * GetCardInfo(); //Get the Card Info structure CString Uid(); //Return UID as string object void SetUid(CString CardUID); //Set Uid of the card as string value void SetKeyA(unsigned char byte0,unsigned char byte1,unsigned char byte2,unsigned char byte3,unsigned char byte4,unsigned char byte5); //set KeyA void SetKeyB(unsigned char byte0,unsigned char byte1,unsigned char byte2,unsigned char byte3,unsigned char byte4,unsigned char byte5); //set KeyB CString GetKeyA(); //Return Key A value as string object void GetKeyA(unsigned char key[6]); //Return Key A value void GetKeyB(unsigned char key[6]); //Return Key B value CString GetKeyB(); //Return Key B value as string object void GetKeyA(unsigned char &byte0,unsigned char &byte1,unsigned char &byte2,unsigned char &byte3,unsigned char &byte4,unsigned char &byte5); //get KeyA void GetKeyB(unsigned char &byte0,unsigned char &byte1,unsigned char &byte2,unsigned char &byte3,unsigned char &byte4,unsigned char &byte5); //get KeyB void SetKeyA(CString byte0,CString byte1,CString byte2,CString byte3,CString byte4,CString byte5); //set KeyA as CString void SetKeyB(CString byte0,CString byte1,CString byte2,CString byte3,CString byte4,CString byte5); //set KeyA as CString unsigned char atoh(CString strValue); //Convert Hex double bytes value as unsigned char value bool operator==( CFGMifareCard & obj ); //Operator Overload }; class CFGMifareObj { private: bool bIsDebug; //bIsDebug Debug mode CString msgErr;//Error message int nDelayWaitCard;//Dalay Time for test if a card is RF range unsigned char ATQ[2],ATS; unsigned char ChipID[TRIPLE_UID_BYTES]; unsigned char ChipIDSize; SESSION_HANDLE hSess; //Session int nCardsInRF; //Number of card in RF field CPtrArray paCards; //List of all selected card in the field void FillCFGMifareCardInfo(); //Fill Card Info void HaltTheCard(); //Halt communication with the card BOOL SearchCard(CFGMifareCard *pSelectedCard); //Check if a card was already registered. void ClearData(); //Clear all data card CFGMifareCard *paCard; //A selected card it's a temporary object HTREEITEM AddOneItem(CTreeCtrl& aTree, HTREEITEM hParent, CString szText, HTREEITEM hInsAfter, int iImage,CFGMifareCard *aCard); //Add a element to CTreeCtrl public: CStringArray saMifareCardTypes; //Array of MIFARE card type supported CStringArray saGemini2kReader; //Array of Gemini2kReader supported int nIDGemini2kReader; //Reader to use selected by user CFGMifareObj(void); //Standard Constructor ~CFGMifareObj(void); void SetDebugMode(bool bSts); //For internal Use only void SetReaderToUse(int nIndex); //0=Use the first reader how specified in saGemini2kReader array 1=The second and so on... void SetDelayForWaitCard(int nMilliSec); //Set the delay time for loop check of card presence in RF field int DelayForWaitCard(); //Get the delay time for loop check of card presence in RF field bool ConnectToReader(); //Try to open a session and connect to the USB reader void DisconnectToReader(); //Disconnect to the USB reader and release session void DisplayMsgErr(); //Helper function to display error message if present and if bIsDebug==TRUE int SelectAidleCard(); //Select Idle Card // int SelectWakeUpCard(); // What is the differences from the SelectIdleCard call ? int NumberOfRegisteredCards(); //Return Number of registered card //UI helper void FillTree(CTreeCtrl& aTree); //Fill a Tree with card INFO int SelectACard(CFGMifareCard *pSelectedCard); //Select a Card void RemoveCard(CFGMifareCard *pSelectedCard); //Remove specified card from internal list //Access Data on Card //As Block int ReadBlock(CFGMifareCard *pSelectedCard,int nBlock,int usingKey,unsigned char *BlockData); //Read a single Block int WriteBlock(CFGMifareCard *pSelectedCard,int nBlock,int usingKey,unsigned char *BlockData);//Write a single Block int EraseBlock(CFGMifareCard *pSelectedCard,int nBlock,int usingKey); //Erase a single Block //As Sector int ReadSector(CFGMifareCard *pSelectedCard,int nBlock,int usingKey,unsigned char *SecData,int* bytesRead); //Read a single sector int WriteSector(CFGMifareCard *pSelectedCard,int nSector,int usingKey,unsigned char *SecData); //Write a single sector int EraseSector(CFGMifareCard *pSelectedCard,int nSector,int usingKey);//Erase a single sector int ReadAllSector(CFGMifareCard *pSelectedCard,CByteArray& dataOnCard,int usingKey,CProgressCtrl *aPrgBar); //Read all data on the card int WriteAllSector(CFGMifareCard *pSelectedCard,CByteArray& dataToWrite,int usingKey,CProgressCtrl *aPrgBar); //Write all data to the card int ReadACL(CFGMifareCard *pSelectedCard,int nSector,int usingKey,unsigned char *pACL,MIF_KEY& theKeyB); //Read 4 BYTES ACL int WriteACL(CFGMifareCard *pSelectedCard,int nSector,MIF_KEY& theWriteKey,unsigned char *pACL,MIF_KEY& theKeyA,MIF_KEY& theKeyB); //Write 4 BYTES ACL };