Partager via


Smart Card Driver Development Concepts (Windows Embedded CE 6.0)

1/6/2010

Smart card device drivers expose the stream interface. By convention, smart card reader drivers use the SCR prefix.

The Device Manager calls the SCR_Init entry point when a new device is instantiated. The SCR_Init routine creates a device context that is used to talk to the reader. The SCR_Open entry point is called when a program, such as the Smart Card Resource Manager, attempts to open the reader using the CreateFile API, passing in the device file name as a parameter. Most smart card readers have a device file name of the form SCRn:, where SCR is the device file name prefix and n is the device file name index. For more information on device file names, see Device File Names.

Applications access smart card readers using the Smart Card Resource Manager. The Smart Card Resource Manager serializes access to the smart card reader for multiple applications. Because smart card reader drivers are not expected to support direct shared access by multiple applications, there is no need to create a separate open context. When a program, such as the Smart Card Resource Manager, releases the device by calling CloseHandle, the SCR_Close entry point is invoked. When it is time to remove the device from the system, the Device Manager calls SCR_Deinit.

SCR_IOControl is the main entry point for smart card requests. SCR_IOControl should immediately call the Smart Card Driver Library. If the library is unable to handle the IOCTL call because it is driver-specific, the driver's callback for unknown IOCTL codes is called.

A typical driver IOCTL function is shown in the following code example.

BOOL SCR_IOControl(
    DWORD Handle,
    DWORD dwIoControlCode,
    PBYTE pInBuf,
    DWORD nInBufSize,
    PBYTE pOutBuf,
    DWORD nOutBufSize,
    PDWORD pBytesReturned
    )
{
    NTSTATUS status;
    PSMARTCARD_EXTENSION pSmartcardExtension = (PSMARTCARD_EXTENSION) Handle;

    if (pSmartcardExtension->ReaderExtension->d_uReaderState != STATE_OPENED)
    {
        SmartcardDebug(DEBUG_ERROR,(TEXT("%s: DeviceIOCTL - invalid state %d\n"), szDriverName,
            pSmartcardExtension->ReaderExtension->d_uReaderState
            ));
        status = ERROR_GEN_FAILURE;
    }
    else
        status = SmartcardDeviceControl(
            pSmartcardExtension, dwIoControlCode,
            pInBuf, nInBufSize,
            pOutBuf, nOutBufSize,
            pBytesReturned);

    return (status == STATUS_SUCCESS ? TRUE: FALSE);
}

See Also

Concepts

Smart Card Driver Architecture
Smart Card Driver Samples
Smart Card Driver Registry Settings
Smart Card Driver Debugging
Smart Card Driver Library

Other Resources

Smart Card Drivers