SmartCard Reader Driver

All,

I’m developing a SmartCard Reader Driver and I’m a little bit new to
smartcards. I’ve developed the driver to be based more or less on the pscr
DDK example and am testing on 32-bit XP, SP3.

The problem that I am having is that the driver never receives any IOCTL
calls.

At AddDevice time the driver is setting up the SmartCard Extension and then
calls SmartcardInitialize(). This call succeeds and allocates space for the
OsData member. My driver then populates the SpinLock and DeviceObjects of
the structure. At EvtEnterDO, the driver resets the card and then tries to
report the card as present by completing the notification IRP
(OsData.NotificationIrp) but this member is null. From this point on, the
driver never see another I/O request.

Questions:

  1. The driver is setting the ReaderExtension member of the
    SMARTCARD_EXTENSION struct to my driver’s extension and am not using the
    ReaderExtension. I assume that ReaderExtenison is private data and it
    doesn’t matter what goes here - is this correct or must it contain the
    READER_EXTENSION structure?
  2. I assume that the card will work with the default CSP – is this correct?
    Or do I need to develop a custom CSP to recognize the device?

Any feedback on this issue would be greatly appreciated.

TIA!

You have to register your driver with smart card resource manager use IoRegisterInterface call with Smartcard GUID then only the resource manager will recognize your driver and start communicating with it. Reader extension is private data. The CSP must be compatible with the card your using. Default CSP works only with certain set of cards. So you need to check your card vendor if the CSP doesn’t work.

Hi Jimmy James,

For resolve this problem, some way are needed.

First have you got created a queue dedied to your ioctl ( an ioctlQueue)

And have you got registered your callBack function for event smartcard

SmartCardExtension->ReaderExtension = ReaderExtension;
SmartCardExtension->ReaderFunction[RDF_CARD_TRACKING] =
Slot_ScardTracking;
SmartCardExtension->ReaderFunction[RDF_TRANSMIT] =
Slot_ScardTransmit;
SmartCardExtension->ReaderFunction[RDF_SET_PROTOCOL] =
Slot_ScardSetProtocol;
SmartCardExtension->ReaderFunction[RDF_CARD_POWER] =
Slot_ScardPower;
SmartCardExtension->ReaderFunction[RDF_IOCTL_VENDOR] =
Slot_ScardVendorIoctl;

and after this code :

status = SmartcardInitialize(SmartCardExtension);

if (status != STATUS_SUCCESS) {

SmartcardLogError(
WdfDriverWdmGetDriverObject(WdfGetDriver()),
STATUS_INSUFFICIENT_RESOURCES,
NULL,
0
);
return status;
}

SmartCardExtension->OsData->DeviceObject =
WdfDeviceWdmGetDeviceObject(fileSlotContext->Device);

Have you got attached your deviceObject to your OsData code.

For test :
Simulate a card detection :
// Add a fake ATR
static BYTE FakeATR[13] = {0x3b, 0x89, 0x40, 0x14, 0x47, 0x47, 0x32, 0x34, 0x4d, 0x35, 0x32, 0x38, 0x30};
static UCHAR FakeATRLength = 13;

SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_SWALLOWED;
RtlCopyMemory(
SmartcardExtension->IoRequest.ReplyBuffer,
FakeATR,
FakeATRLength
);

*SmartcardExtension->IoRequest.Information = FakeATRLength ;

// Take this Call for update smclib
status = SmartcardUpdateCardCapabilities(SmartcardExtension);

SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_SPECIFIC;
SmartcardExtension->CardCapabilities.Protocol.Selected = SCARD_PROTOCOL_T1;

I hope to help you

Best regards,

Moulefrite

I looked at the smartcard source some years ago. The version in the source
tree at that time was not written by Microsoft and was full of fundamental
bugs; I had a client who was trying to use it, and it was not passing the
Driver Verifier.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Monday, February 21, 2011 5:31 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] SmartCard Reader Driver

Hi Jimmy James,

For resolve this problem, some way are needed.

First have you got created a queue dedied to your ioctl ( an ioctlQueue)

And have you got registered your callBack function for event smartcard

SmartCardExtension->ReaderExtension = ReaderExtension;
SmartCardExtension->ReaderFunction[RDF_CARD_TRACKING] =
Slot_ScardTracking;
SmartCardExtension->ReaderFunction[RDF_TRANSMIT] =
Slot_ScardTransmit;
SmartCardExtension->ReaderFunction[RDF_SET_PROTOCOL] =
Slot_ScardSetProtocol;
SmartCardExtension->ReaderFunction[RDF_CARD_POWER] =
Slot_ScardPower;
SmartCardExtension->ReaderFunction[RDF_IOCTL_VENDOR] =
Slot_ScardVendorIoctl;

and after this code :

status = SmartcardInitialize(SmartCardExtension);

if (status != STATUS_SUCCESS) {

SmartcardLogError(
WdfDriverWdmGetDriverObject(WdfGetDriver()),
STATUS_INSUFFICIENT_RESOURCES,
NULL,
0
);
return status;
}

SmartCardExtension->OsData->DeviceObject =
WdfDeviceWdmGetDeviceObject(fileSlotContext->Device);

Have you got attached your deviceObject to your OsData code.

For test :
Simulate a card detection :
// Add a fake ATR
static BYTE FakeATR[13] = {0x3b, 0x89, 0x40, 0x14, 0x47, 0x47, 0x32, 0x34,
0x4d, 0x35, 0x32, 0x38, 0x30};
static UCHAR FakeATRLength = 13;

SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_SWALLOWED;
RtlCopyMemory(

SmartcardExtension->IoRequest.ReplyBuffer,
FakeATR,
FakeATRLength
);

*SmartcardExtension->IoRequest.Information =
FakeATRLength ;

// Take this Call for update smclib
status =
SmartcardUpdateCardCapabilities(SmartcardExtension);

SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_SPECIFIC;

SmartcardExtension->CardCapabilities.Protocol.Selected = SCARD_PROTOCOL_T1;

I hope to help you

Best regards,

Moulefrite


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.