==========================================================================
PC/SC compatible driver of virtual smartcard reader (pcsc_drv.sys)
==========================================================================
This is a typical PC/SC driver, tested on WIN2K. 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 project produces automatically nms files
(symbols for SOFTICE) if MS VC can find nmsym.exe through the variable PATH.
For preparation to remote debug I'd recommend usage of PsTools from Mark
Russinovich.
11.06.2003. Function IoDeleteSymbolicLink was added in pcsc_drv.c. LinkName
was moved into DeviceExtensions. Now driver can be restarted
correctly. But before stopping pcsc_drv Scardsvr must be also
stopped.
Additional information can be found : http://www.dbasko.com/pc_sc.htm
-------------------------------------------------------------------------
You may contact the author by:
E-mail: contact@dbasko.com Dmitry Basko, 2001