⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smcce.c

📁 ARM9基于WINDOWSCE的BSP源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++


Module Name:

    smcce.c

Abstract:

    This module handles all OS-specific requests to the smart card reader.

Environment:

    Kernel mode only.

Notes:

--*/

#define _ISO_TABLES_
#include <smclib.h>
#include "maperr.h"
#define	ZQ 1
extern NTSTATUS
SMCDeviceIoControl(
    PSMARTCARD_EXTENSION SmartcardExtension
    );
#if (DBG || DEBUG)
PTCHAR 
MapIoControlCodeToString(
    ULONG IoControlCode
    );
#endif

typedef LONG  (WINAPI * PFN_SCARDINTRODUCEREADERW)(ULONG , LPCWSTR , LPCWSTR );
typedef LONG  (WINAPI * PFN_SCARDFORGETREADERW)(ULONG , LPCWSTR );
PFN_SCARDINTRODUCEREADERW g_pfnIntroduceReader = 0;
PFN_SCARDFORGETREADERW g_pfnForgetReader = 0;

NTSTATUS
SmartcardCreateLink(IN LPCWSTR pszFriendlyName, IN LPCWSTR pszDeviceName)
{
    HMODULE hMod;
    NTSTATUS status = STATUS_UNSUCCESSFUL;
	DEBUGMSG(ZQ,(TEXT("==>>SmartcardCreateLink( )\r\n")));
    if (!g_pfnIntroduceReader)
    {
        hMod = GetModuleHandle(TEXT("WINSCARD.DLL"));
        if (hMod)
        {
            g_pfnIntroduceReader = (PFN_SCARDINTRODUCEREADERW)GetProcAddress(hMod, TEXT("SCardIntroduceReaderW"));
            g_pfnForgetReader = (PFN_SCARDFORGETREADERW)GetProcAddress(hMod, TEXT("SCardForgetReaderW"));
        }
    }
    if (g_pfnIntroduceReader)
    {
        if ((*g_pfnIntroduceReader)(0, pszFriendlyName, pszDeviceName) == 0)
            status = STATUS_SUCCESS;
        SmartcardDebug(
            DEBUG_INFO,
            (TEXT("%s!SmartcardCreateLink: [%s] -> [%s] , status = %x.\n"),
            DRIVER_NAME,
            pszFriendlyName, pszDeviceName, status)
            );
    }
	DEBUGMSG(ZQ,(TEXT("<<==SmartcardCreateLink( )\r\n")));
    return status;
        
}

NTSTATUS
SmartcardDeleteLink(IN LPCWSTR pszFriendlyName)
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    if (g_pfnForgetReader)
    {
         if ((*g_pfnForgetReader)(0, pszFriendlyName) == 0)
            status = STATUS_SUCCESS;
    }
    SmartcardDebug(
        DEBUG_INFO,
        (TEXT("%s!SmartcardDeleteLink: [%s] , status = %x.\n"),
        DRIVER_NAME,
        pszFriendlyName, status)
        );
    return status;
}

NTSTATUS
SmartcardInitialize(
	IN PSMARTCARD_EXTENSION SmartcardExtension
	)
/*++

Routine Description:

	This function allocated the send and receive buffers for smart card 
	data. It also sets the pointer to 2 ISO tables to make them accessible 
	to the driver
    
Arguments:

    SmartcardExtension 

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS status = STATUS_SUCCESS;
    HANDLE hCancelEvent = NULL;
    HANDLE hChangeEvent = NULL;
    SmartcardDebug(
        DEBUG_INFO,
        (TEXT("%s!SmartcardInitialize: Enter. Version %lx, %s %s\n"),
        DRIVER_NAME,
        SMCLIB_VERSION,
        __DATE__,
        __TIME__)
        );

      ASSERT(SmartcardExtension != NULL);
      ASSERT(SmartcardExtension->OsData == NULL);

    if (SmartcardExtension == NULL) {

        return STATUS_INVALID_PARAMETER;     	
    }

    if (SmartcardExtension->Version > SMCLIB_VERSION ||
        SmartcardExtension->Version < SMCLIB_VERSION_REQUIRED) {

        SmartcardDebug(
            DEBUG_ERROR,
            (TEXT("%s!SmartcardInitialize: Incompatible version in SMARTCARD_EXTENSION.\n"),
            DRIVER_NAME)
            );

        return STATUS_UNSUCCESSFUL;
    }

	if (SmartcardExtension->SmartcardRequest.BufferSize < MIN_BUFFER_SIZE) {

        SmartcardDebug(
            DEBUG_ERROR, 
            (TEXT("%s!SmartcardInitialize: WARNING: SmartcardRequest.BufferSize (%ld) < MIN_BUFFER_SIZE (%ld)\n"),
            DRIVER_NAME,
            SmartcardExtension->SmartcardRequest.BufferSize,
            MIN_BUFFER_SIZE)
            );
		
		SmartcardExtension->SmartcardRequest.BufferSize = MIN_BUFFER_SIZE;
   	}	

	if (SmartcardExtension->SmartcardReply.BufferSize < MIN_BUFFER_SIZE) {

        SmartcardDebug(
            DEBUG_ERROR, 
            (TEXT("%s!SmartcardInitialize: WARNING: SmartcardReply.BufferSize (%ld) < MIN_BUFFER_SIZE (%ld)\n"),
            DRIVER_NAME,
            SmartcardExtension->SmartcardReply.BufferSize,
            MIN_BUFFER_SIZE)
            );
		
		SmartcardExtension->SmartcardReply.BufferSize = MIN_BUFFER_SIZE;
   	}	

	SmartcardExtension->SmartcardRequest.Buffer = LocalAlloc(
		LPTR,
		SmartcardExtension->SmartcardRequest.BufferSize
		);

	SmartcardExtension->SmartcardReply.Buffer = LocalAlloc(
		LPTR,
		SmartcardExtension->SmartcardReply.BufferSize
		);

    SmartcardExtension->OsData = LocalAlloc(
        LPTR,
        sizeof(OS_DEP_DATA)
        );

    hCancelEvent = CreateEvent(NULL,TRUE,FALSE,NULL);   // manual reset, initially off
    hChangeEvent = CreateEvent(NULL,TRUE,FALSE,NULL);   // manual reset, initially off
    
    //
    // Check if one of the above allocations failed
    //
    if (SmartcardExtension->SmartcardRequest.Buffer == NULL ||
        SmartcardExtension->SmartcardReply.Buffer == NULL ||
        SmartcardExtension->OsData == NULL ||
        hCancelEvent == NULL ||
        hChangeEvent == NULL
        ) {

        status = STATUS_INSUFFICIENT_RESOURCES;

        if (SmartcardExtension->SmartcardRequest.Buffer) {

            LocalFree(SmartcardExtension->SmartcardRequest.Buffer);     	
        }

        if (SmartcardExtension->SmartcardReply.Buffer) {
     	    
            LocalFree(SmartcardExtension->SmartcardReply.Buffer);     	
        }

        if (SmartcardExtension->OsData) {
     	    
            LocalFree(SmartcardExtension->OsData);     	
            SmartcardExtension->OsData = NULL;
        }
    }
    else
    {
        SmartcardExtension->OsData->hChangeEvent = hChangeEvent;
        SmartcardExtension->OsData->hCancelEvent = hCancelEvent;
    }
    
    if (status != STATUS_SUCCESS) {

        return status;     	
    }


    // Initialize the Critical Section that is used to synch. access to the driver
    InitializeCriticalSection(&SmartcardExtension->OsData->CritSect);
    // set the back pointer to the SmartcardExtension
    // may not be required!
    SmartcardExtension->OsData->pSmartCardExtension = SmartcardExtension;
    
	// Make the 2 ISO tables accessible to the driver
	SmartcardExtension->CardCapabilities.ClockRateConversion = 
		&ClockRateConversion[0];

	SmartcardExtension->CardCapabilities.BitRateAdjustment = 
		&BitRateAdjustment[0];

    SmartcardDebug(
        DEBUG_TRACE,
        (TEXT("%s!SmartcardInitialize: Exit\n"),
        DRIVER_NAME)
        );

	return status;
}


VOID 
SmartcardExit(
	IN PSMARTCARD_EXTENSION SmartcardExtension
	)
/*++

Routine Description:

    This routine frees the send and receive buffer.
	It is usually called when the driver unloads.
    
Arguments:

    SmartcardExtension 

Return Value:

    NTSTATUS

--*/
{
    SmartcardDebug(
        DEBUG_TRACE,
        (TEXT("%s!SmartcardExit: Enter\n"),
        DRIVER_NAME)
        );

    //
    // Free all allocated buffers
    //
	if (SmartcardExtension->SmartcardRequest.Buffer) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -