www.dbasko.com : Main page, DES (56 bits) 8051 core, development of PnP serial device and WDM driver, PC/SC driver for WINDOWS, How to enable PowerNow! for Sony Vaio on Win2K and other projects.

PC / SC compatible device driver for WINDOWS

Part 2.
Source codes of PC/SC driver (MS VC++.NET) and auxilary utilities.

  1. This project is a typical PC/SC driver, tested on WIN2K. List of files, included in the project can be found here. The most important function is SendSmdReader().This function should be implemented in an external hardware (smartcard reader, secure token). In order to simulate insertion and removal of the virtual smartcard I create additional WORKER thread (function VdVendorIOCTL) where I create named event (IoCreateSynchronizationEvent, name is SC_INSERT_REMOVE). User application (ins_rem.exe) switches this event and driver simulates insertion and removal of the virtual smartcard. Second user application (sc_mon.exe) reports about current state of the virtual smartcard.Additionally it is possible to use any other tools to check the presence of virt. smartcard like PCSCInf.exe.
    This driver supports SYSTEM EVENT LOG, putting there correspondent messages about it current state and errors. All this information can be viewed with usage of standard EVENT VIEWER.
    The ATR data, the path to the binary file which emulates the smartcard memory are stored in the driver's code. It can be easily changed and be set up through the Registry, for example.
    The name of the virtual reader is "COMRAD 000001 0"
    The driver supports 3 ISO 7816 commands:
    • SELECT -
      {
      _CmdBytes.bCla = 0xA0;
      _CmdBytes.bIns = 0xA4;
      _CmdBytes.bP1 = 0;
      _CmdBytes.bP2 = 0;
      _CmdBytes.bP3 = 0;
      }
    • READ_BINARY -
      {
      _CmdBytes.bCla = 0x00;
      _CmdBytes.bIns = 0xB0;
      _CmdBytes.bP1 = 0; \ offset for data in the virtual smartcard
      _CmdBytes.bP2 = 0; / for us this is file c:\CARD.bin
      _CmdBytes.bP3 = ?;- the number of data, which is read from
      SC (c:\CARD.bin)
      }
      Attention, please: the sum (bP1+bP2+bP3) MUST be less then 128 bytes.
      It means, the driver emulates the access ONLY to 128 bytes of the memory.
      The parameter is checked by driver internally.
    • WRITE_BINARY -
      {
      _CmdBytes.bCla = 0x00;
      _CmdBytes.bIns = 0xD0;
      _CmdBytes.bP1 = 0; \ offset for data in the virtual smartcard
      _CmdBytes.bP2 = 0; / for us this is file c:\CARD.bin
      _CmdBytes.bP3 = ?; - the number of data which will be written in SC (c:\CARD.bin)
      }
      Attention, please: the sum (bP1+bP2+bP3) MUST be less then 128 bytes.
      It means, the driver emulates the access ONLY to 128 bytes of the memory.
      The parameter is checked by driver internally.

      Additional hint: In order to compile this project you should set up DDK
      includes,defining variable DDK_INC and path to the DDK libraries, defining
      variable DDK_LIB. Additionally, the project produces automatically nms files
      (symbols for SOFTICE) if MS VC can find nmsym.exe through the variable PATH.
      For remote debug I'd recommend usage of PsTools from Mark Russinovich. If you do not plan to use SoftIce you should disable Post-Build event where I form NMS file for the future debug. Project includes all necessary definitions for the smart card library.All necessary instructions regard to driver installation you can find in \install\install.txt
      Source code and binaries of the project can be downloaded from here
  2. Auxilary utilities:
    a) sc_test; This utility allows selecting, reading a writing binary data into (from) virtual smartcard, in reality this virtual SC is only file (card.bin) on the hard disk. Source code is included.
    b) sc_mon; This utility allows checking state of the virtual smartcard's reader. This state can be: "virtual smartcard in the reader" and "virtual smartcard is not present in the reader". If virtual smartcard is not present in the reader utility is waiting for the virtual smartcard insertion and reports about it. Source code is included.
    c) ins_rem; This utility allows emulating insertion or removal of virtual smartcard in (from) the reader. For this goal PC/SC driver checks the state of EVENT and reports to Resource manager about its different states.The utility instructs the driver to create this event or uses already created and just switches this event, forcing the driver to emulate various reader's states. Please notice: every time when set the EVENT (SC_INSERT_REMOVE) the driver changes the state of the reader to opposite one: if virt. SC was inserted, next time it will be removed and vice versa. Therefore this utility does not know about initial state of the reader, this state will be shown by sc_mon utility. This behavior can be easily changed with small modification in the driver or ins_rem should check the internal state of the reader via MS Smartcard API.
  3. Highly recommended tools for PC/SC driver testing:
    1. TAPDUDemoCard from Vizvary Istvan; It can be used for communication with virtual smartcard without writing even one line of the code. Communication occurs in interactive way.
    2. APDU command test from Vizvary Istvan; Very similar to the first utility and can be used also for the same purposes.
    3.PCSC Info from ZeitControl cardsystems GmbH; Utility, allowing testing any PC/SC compatible reader. It controls state of the smartcard in the reader and reports its current state.

© 2003 Dmitry Basko