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

📄 uscrdbg.c

📁 usblsccid-0.9.2: ED1x Smart Card Reader Driver
💻 C
字号:
/*++Copyright (c) 2004  QWY MicroSystem Inc.Module Name:    uscrdbg.c Abstract:    USB SmartCard Reader driver for CCID/lsCCID compatible device.Environment:    kernel mode onlyNotes:Revision History:    4/24/2005: Adapted from BULKUSB DDK sample.--*/

#if DBG


#include "wdm.h"
#include "stdarg.h"
#include "stdio.h"

#include "usbdi.h"
#include "usbdlib.h"
#include "uscr.h"


// begin, data/code  used only in DBG build

//  may be overridden  in registry in DBG buils only
// higher == more verbose, default is 1, 0 turns off all
int gDebugLevel = DBGLVL_MAXIMUM ; 

// count outstanding allocations via ExAllocatePool
int gExAllocCount =0;

USCR_DBGDATA gDbgBuf = { 0, 0, 0, 0 }; 

// ptr to global debug data struct; txt buffer is only allocated in DBG builds
PUSCR_DBGDATA gpDbg = &gDbgBuf; 




BOOLEAN
USCR_GetRegistryDword(
    IN      PWCHAR    RegPath,
    IN      PWCHAR    ValueName,
    IN OUT  PULONG    Value
    )

/*++

Routine Description:

	Obtain a Dword value from the registry


Arguments:

    RegPath  -- supplies absolute registry path
    ValueName    - Supplies the Value Name.
    Value      - receives the REG_DWORD value.

Return Value:

    TRUE if successfull, FALSE on fail.

--*/

{
    UNICODE_STRING path;
    RTL_QUERY_REGISTRY_TABLE paramTable[2];  //zero'd second table terminates parms
    ULONG lDef = *Value;                     // default
    NTSTATUS status;
    BOOLEAN fres;
	WCHAR wbuf[ MAXIMUM_FILENAME_LENGTH ];

    USCR_KdPrint( DBGLVL_HIGH,("Enter USCR_GetRegistryDword() RegPath = %ws\n   ValueName =%ws\n", RegPath, ValueName));
    path.Length = 0;
    path.MaximumLength = MAXIMUM_FILENAME_LENGTH * sizeof( WCHAR );  // MAXIMUM_FILENAME_LENGTH defined in wdm.h
    path.Buffer = wbuf;


    RtlZeroMemory(path.Buffer, path.MaximumLength);
    RtlMoveMemory(path.Buffer, RegPath, wcslen( RegPath) * sizeof( WCHAR ));

    USCR_KdPrint( DBGLVL_HIGH,("USCR_GetRegistryDword() path= %ws\n", path.Buffer ));

    RtlZeroMemory(paramTable, sizeof(paramTable));

    paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;

    paramTable[0].Name = ValueName;

    paramTable[0].EntryContext = Value;
    paramTable[0].DefaultType = REG_DWORD;
    paramTable[0].DefaultData = &lDef;
    paramTable[0].DefaultLength = sizeof(ULONG);


    status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
                                    path.Buffer, paramTable, NULL, NULL);

    if (NT_SUCCESS(status)) {
        USCR_KdPrint( DBGLVL_MEDIUM,("Exit USCR_GetRegistryDWord() SUCCESS, value = decimal %d 0x%x\n", *Value, *Value));
        fres = TRUE;

    } else {

        USCR_KdPrintCond( DBGLVL_MEDIUM, (status == STATUS_INVALID_PARAMETER) ,("USCR_GetRegistryDWord() STATUS_INVALID_PARAMETER\n"));
 
		USCR_KdPrintCond( DBGLVL_MEDIUM, (status == STATUS_OBJECT_NAME_NOT_FOUND) ,("USCR_GetRegistryDWord() STATUS_OBJECT_NAME_NOT_FOUND\n"));

        fres = FALSE;

    }

    return fres;
}

PVOID 
    USCR_ExAllocatePool(
        IN POOL_TYPE PoolType,
        IN ULONG NumberOfBytes
        )
{
	gExAllocCount++;
  //  USCR_KdPrint( DBGLVL_HIGH,("USCR_ExAllocatePool() gExAllocCount = dec %d,Len=%d\n", gExAllocCount,NumberOfBytes ));
	return ExAllocatePool(  PoolType, NumberOfBytes );

}


VOID 
    USCR_ExFreePool(
        IN PVOID p
        )
{
	gExAllocCount--;
   // USCR_KdPrint( DBGLVL_HIGH,("USCR_ExFreePool() gExAllocCount = dec %d\n", gExAllocCount ));
	ExFreePool(  p );

}

VOIDhexdump(	UCHAR *p,	ULONG len	){	UCHAR *line = p;	ULONG thisline, offset = 0;	ULONG i;	while (offset < len)	{		DbgPrint("%04x ", offset);		thisline = len - offset;		if (thisline > 16)			thisline = 16;		for (i = 0; i < thisline; i++)		{			DbgPrint("%02x ", line[i]);        	}		for (; i < 16; i++)		{			DbgPrint("   ");		}		for (i = 0; i < thisline; i++)		{			DbgPrint("%c",(line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');		}		DbgPrint("\n");		offset += thisline;		line += thisline;	}}
void
USCR_DumpCardCapabilities(PSMARTCARD_EXTENSION SmartcardExtension)
{
	DbgPrint( "====================dump SCARD_CARD_CAPABILITIES==============\n");
	DbgPrint("InversConvention:%d\n",SmartcardExtension->CardCapabilities.InversConvention);
	DbgPrint("etu:%d\n",SmartcardExtension->CardCapabilities.etu);
	DbgPrint("ATR length:%d\n",SmartcardExtension->CardCapabilities.ATR.Length);
	hexdump(SmartcardExtension->CardCapabilities.ATR.Buffer,SmartcardExtension->CardCapabilities.ATR.Length);
	DbgPrint("Fl:%d\n",SmartcardExtension->CardCapabilities.Fl);
	DbgPrint("Dl:%d\n",SmartcardExtension->CardCapabilities.Dl);
	DbgPrint("Maximum programming current:%d\n",SmartcardExtension->CardCapabilities.II);
	DbgPrint("Programming voltage:%d\n",SmartcardExtension->CardCapabilities.P);
	DbgPrint("Extra guard time in etu:%d\n", SmartcardExtension->CardCapabilities.N);
	DbgPrint("Calculated guard time in micro seconds:%d\n",SmartcardExtension->CardCapabilities.GT);
	DbgPrint("Protocol Support:%x\n",SmartcardExtension->CardCapabilities.Protocol.Supported);
	DbgPrint("Protocol Selected:%x\n",SmartcardExtension->CardCapabilities.Protocol.Selected);
	DbgPrint("T0 Waiting integer:%d\n",SmartcardExtension->CardCapabilities.T0.WI);
	DbgPrint("T0 Waiting time in micro seconds:%d\n",SmartcardExtension->CardCapabilities.T0.WT);
	DbgPrint("T1 Skip ...\n");
	DbgPrint("PtsData Type:%d\n",SmartcardExtension->CardCapabilities.PtsData.Type);
	DbgPrint("PtsData Fl:%d\n",SmartcardExtension->CardCapabilities.PtsData.Fl);
	DbgPrint("PtsData Dl:%d\n",SmartcardExtension->CardCapabilities.PtsData.Dl);
	DbgPrint("PtsData CLKFrequency:%d\n",SmartcardExtension->CardCapabilities.PtsData.CLKFrequency);
	DbgPrint("PtsData DataRate:%d\n",SmartcardExtension->CardCapabilities.PtsData.DataRate);
	DbgPrint("PtsData StopBits:%d\n",SmartcardExtension->CardCapabilities.PtsData.StopBits);
	DbgPrint("ReaderCapabilities.CurrentState:%d\n", SmartcardExtension->ReaderCapabilities.CurrentState);
}

void
USCR_ShowIoctlCode(PIRP Irp)
{
    PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
    ULONG ControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
		ULONG InputLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
		ULONG OutputLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;

		switch(ControlCode)
		{
			case	IOCTL_SMARTCARD_POWER:
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_POWER InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;        
			case	IOCTL_SMARTCARD_GET_ATTRIBUTE:
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_GET_ATTRIBUTE InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;    
			case	IOCTL_SMARTCARD_SET_ATTRIBUTE:
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_SET_ATTRIBUTE InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
			case	IOCTL_SMARTCARD_CONFISCATE:
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_CONFISCATE InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
			case	IOCTL_SMARTCARD_TRANSMIT:        
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_TRANSMIT InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_EJECT:           
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_EJECT InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_SWALLOW:         
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_SWALLOW InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
	
			case	IOCTL_SMARTCARD_IS_PRESENT:      
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_IS_PRESENT InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_IS_ABSENT:       
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_IS_ABSENT InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_SET_PROTOCOL:    
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_SET_PROTOCOL InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_GET_STATE:       
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_GET_STATE InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_GET_LAST_ERROR:  
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_GET_LAST_ERROR InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
				
			case	IOCTL_SMARTCARD_GET_PERF_CNTR:   
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: IOCTL_SMARTCARD_GET_PERF_CNTR InputLength %d OutputLength %d\n",
					InputLength, OutputLength)
					);  
				break;     
			default:
				SmartcardDebug(
					DEBUG_TRACE,
					("DeviceIoControl: Control code %x InputLength %d OutputLength %d\n",
					ControlCode, InputLength, OutputLength)
				);
		}		
}
  	
#endif // end , if DBG


⌨️ 快捷键说明

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