SmartCard Reader Driver not visible in Applications

Hello,

I’m new in driver developing and I’ve the questions. What method call or lib do I need to get my smartcard driver visible to other applications?
The created device is in the system manager and the registry visible.

I copy my code, perhaps, someone of you can give me a hint.

NTSTATUS XXXAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
){
NTSTATUS ntstatus = STATUS_SUCCESS;
PDEVICE_OBJECT pDeviceObject;
PDEVICE_EXTENSION pDeviceExtension;
PREADER_EXTENSION pReaderExtension;
PSMARTCARD_EXTENSION pSmartcardExtension;
UNICODE_STRING LinkName;
ULONG IdxPwrState;
ULONG DeviceInstance;

RtlInitUnicodeString(
&global_Hjp_DeviceName,
L"\DosDevices\XXXReader0");

DbgPrint(“Begin AddDevice:\n”);

for ( DeviceInstance = 0; DeviceInstance < XXX_MAX_DEVICE; DeviceInstance++ ) {
if (DeviceSlot[DeviceInstance] == FALSE) {
DeviceSlot[DeviceInstance] = TRUE;
break;
}
}

if (DeviceInstance == XXX_MAX_DEVICE) {

ntstatus = STATUS_INSUFFICIENT_RESOURCES;
}

if((ntstatus = IoCreateDevice(
DriverObject, sizeof(DEVICE_EXTENSION),
NULL,FILE_DEVICE_SMARTCARD,
0,TRUE,&pDeviceObject))==STATUS_SUCCESS){
DbgPrint(“IoCreateDevice successful! \n”);

// Initialize device and smartcard extension

pDeviceExtension=pDeviceObject->DeviceExtension;
RtlZeroMemory( pDeviceExtension, sizeof(DEVICE_EXTENSION));
pSmartcardExtension = &pDeviceExtension->SmartcardExtension;

DbgPrint(“Begin to allocate Reader Extension!\n”);

pReaderExtension =
ExAllocatePool(NonPagedPool, sizeof(READER_EXTENSION));
if (pReaderExtension != NULL){
DbgPrint(“Allocate Reader Extension successful!\n”);
RtlZeroMemory(pReaderExtension, sizeof(READER_EXTENSION));
pSmartcardExtension->ReaderExtension = pReaderExtension;

pSmartcardExtension = &(pDeviceExtension->SmartcardExtension);
pSmartcardExtension->Version = SMCLIB_VERSION;
pSmartcardExtension->SmartcardRequest.BufferSize = MIN_BUFFER_SIZE;
pSmartcardExtension->SmartcardReply.BufferSize = MIN_BUFFER_SIZE;

//Callback for pDeviceExtension
pSmartcardExtension->ReaderFunction[RDF_CARD_POWER] = XXXPowerReader;
pSmartcardExtension->ReaderFunction[RDF_SET_PROTOCOL] = XXXSetProtocol;
pSmartcardExtension->ReaderFunction[RDF_TRANSMIT] = XXXTransmit;
pSmartcardExtension->ReaderFunction[RDF_CARD_TRACKING] = XXXCardTracking;
pSmartcardExtension->ReaderFunction[RDF_IOCTL_VENDOR] = XXXVendorIOCTL;

// vendor specified Entrys of SmartcardExtension
RtlCopyMemory(
pSmartcardExtension->VendorAttr.VendorName.Buffer,
XXX_VENDOR_NAME,
sizeof( XXX_VENDOR_NAME ));
pSmartcardExtension->VendorAttr.VendorName.Length =
sizeof(XXX_VENDOR_NAME );

//DbgPrint(XXX_VENDOR_NAME);

RtlCopyMemory(pSmartcardExtension->VendorAttr.IfdType.Buffer,
XXX_IFD_TYPE,
sizeof(XXX_IFD_TYPE));
pSmartcardExtension->VendorAttr.VendorName.Length = sizeof(HJP_IFD_TYPE);

pSmartcardExtension->VendorAttr.UnitNo = 0;

// Clk frequency in KHz encoded as little endian integer
pSmartcardExtension->ReaderCapabilities.CLKFrequency.Default = 3571;
pSmartcardExtension->ReaderCapabilities.CLKFrequency.Max = 3571;

// the supported protocols
pSmartcardExtension->ReaderCapabilities.SupportedProtocols =
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
// Reader type
pSmartcardExtension->ReaderCapabilities.ReaderType = SCARD_READER_TYPE_VENDOR;
// Now setup information in our deviceExtension
pSmartcardExtension->ReaderCapabilities.CurrentState = SCARD_UNKNOWN;

//pSmartcardExtension->ReaderCapabilities.ReaderType =

DbgPrint(“SmartcardInitialize! \n”);

if ((ntstatus = SmartcardInitialize(pSmartcardExtension))
== STATUS_SUCCESS){
DbgPrint(“SmartcardInitialize successful! \n”);

pSmartcardExtension->OsData->DeviceObject = pDeviceObject;
pDeviceObject->Flags |= DO_BUFFERED_IO;
pDeviceObject->Flags |= DO_POWER_PAGABLE;
//pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

pDeviceExtension =pDeviceObject->DeviceExtension;
pDeviceExtension->DeviceObject=pDeviceObject;
//Initialize driver power state
pDeviceExtension->SysPwrState = PowerSystemWorking;
pDeviceExtension->DevPwrState = PowerDeviceD0;

//Initialize device power information
global_PowerInfo_Ptr = ExAllocatePool(
NonPagedPool, sizeof(DEVICE_POWER_INFORMATION));
RtlZeroMemory(
global_PowerInfo_Ptr,
sizeof(DEVICE_POWER_INFORMATION));
global_PowerInfo_Ptr->SupportQueryCapability = FALSE;
global_PowerInfo_Ptr->DeviceD1 = 0;
global_PowerInfo_Ptr->DeviceD2 = 0;
global_PowerInfo_Ptr->WakeFromD0 = 0;
global_PowerInfo_Ptr->WakeFromD1 = 0;
global_PowerInfo_Ptr->WakeFromD2 = 0;
global_PowerInfo_Ptr->WakeFromD3 = 0;
global_PowerInfo_Ptr->DeviceWake = 0;
global_PowerInfo_Ptr->SystemWake = 0;
for (IdxPwrState = 0;
IdxPwrState < PowerSystemMaximum;
IdxPwrState++)
{
global_PowerInfo_Ptr->DeviceState[IdxPwrState] = 0;
}

RtlInitUnicodeString(
&pDeviceExtension->Device_Description,
L"This is a XXX Reader\r\n"
L"created by Peter Winkelhane 2007/3/5\r\n");

DbgPrint(“SmartcardCreateLink! \n”);

if ((ntstatus = SmartcardCreateLink(&LinkName, &global_XXX_DeviceName))
== STATUS_SUCCESS){

DbgPrint(“SmartcardCreateLink successful! \n”);

DbgPrint(“Attach device to stack! \n”);

pDeviceExtension->NextDeviceObject
= IoAttachDeviceToDeviceStack(pDeviceObject, PhysicalDeviceObject);

DbgPrint(“Attach device to stack successful! \n”);

DbgPrint(“Register Device\n”);
// register our new device
ntstatus = IoRegisterDeviceInterface(
PhysicalDeviceObject,
&SmartCardReaderGuid,
NULL,
&global_XXX_DeviceName
);

DbgPrint(“Register Device successful!\n”);

pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

}
else{
DbgPrint(“SmartcardCreateLink failed \n”);
IoDeleteDevice(pDeviceObject);
DbgPrint(“Device deleted! \n”);
}
}
else{
DbgPrint(“SmartcardInitialize failed \n”);
IoDeleteDevice(pDeviceObject);
DbgPrint("Device deleted!\n ");
}
}
}

else{
switch(ntstatus){

case STATUS_OBJECT_NAME_EXISTS:
break;
case STATUS_OBJECT_NAME_COLLISION:
break;
case STATUS_INSUFFICIENT_RESOURCES:
break;
case STATUS_OBJECT_NAME_INVALID:
break;
default:
//undefined NTstatus
break;

}
return ntstatus;

}

DbgPrint("End of AddDevice\n ");

return ntstatus;
}

Thank you for your hints. :slight_smile:

Has no one a hint or a solution for my problem?

I despair.