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

📄 tlp3ce.c

📁 ARM9基于WINDOWSCE的BSP源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    status = SmartcardInitialize(smartcardExtension);
    if (status != STATUS_SUCCESS) {
        SmartcardDebug(DEBUG_INIT|DEBUG_ERROR,(TEXT("%s: SmartcardInitialize failed - %x\n"),
                    szDriverName, status));
        LocalFree(smartcardExtension);
        return NULL;
    }
    //    setup smartcard extension - callback's
    smartcardExtension->ReaderFunction[RDF_CARD_POWER] = TLP3ReaderPower;
    smartcardExtension->ReaderFunction[RDF_TRANSMIT] = TLP3Transmit;
    smartcardExtension->ReaderFunction[RDF_CARD_TRACKING] = TLP3CardTracking;
    smartcardExtension->ReaderFunction[RDF_SET_PROTOCOL] = TLP3SetProtocol;
    smartcardExtension->ReaderFunction[RDF_IOCTL_VENDOR] = TLP3VendorIoctl;

    //    setup smartcard extension - vendor attribute
    RtlCopyMemory(
            smartcardExtension->VendorAttr.VendorName.Buffer,
            TLP3_VENDOR_NAME,sizeof( TLP3_VENDOR_NAME ));
    smartcardExtension->VendorAttr.VendorName.Length = sizeof( TLP3_VENDOR_NAME );

    RtlCopyMemory(
            smartcardExtension->VendorAttr.IfdType.Buffer,
            TLP3_PRODUCT_NAME,sizeof( TLP3_PRODUCT_NAME ));
    smartcardExtension->VendorAttr.IfdType.Length = sizeof(TLP3_PRODUCT_NAME );

    smartcardExtension->VendorAttr.UnitNo = 0;
    smartcardExtension->VendorAttr.IfdVersion.BuildNumber = 0;
    smartcardExtension->VendorAttr.IfdSerialNo.Length = 0;
        
    //
    // Set the reader capabilities
    //
    // Clk frequency in KHz encoded as little endian integer
    smartcardExtension->ReaderCapabilities.CLKFrequency.Default = 3571;
    smartcardExtension->ReaderCapabilities.CLKFrequency.Max = 3571;

    smartcardExtension->ReaderCapabilities.DataRate.Default = 
    smartcardExtension->ReaderCapabilities.DataRate.Max = 
        dataRatesSupported[0];

    // reader could support higher data rates
    smartcardExtension->ReaderCapabilities.DataRatesSupported.List = 
        dataRatesSupported;
    smartcardExtension->ReaderCapabilities.DataRatesSupported.Entries = 
        sizeof(dataRatesSupported) / sizeof(dataRatesSupported[0]);

    smartcardExtension->ReaderCapabilities.MaxIFSD = 254;

    // Now setup information in our deviceExtension
    smartcardExtension->ReaderCapabilities.CurrentState = 
        (ULONG) SCARD_UNKNOWN;
    // This reader supports T=0 and T=1
    smartcardExtension->ReaderCapabilities.SupportedProtocols = 
        SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
    smartcardExtension->ReaderCapabilities.MechProperties = 0;
    smartcardExtension->ReaderCapabilities.ReaderType = SCARD_READER_TYPE_VENDOR;
  //          SCARD_READER_TYPE_PCMCIA;
    smartcardExtension->ReaderCapabilities.Channel = 0;


    smartcardExtension->ReaderExtension->ReaderPowerState = PowerReaderWorking;
    //        PowerReaderOff;

    // Copy the ActivePath
    _tcsncpy(readerExtension->d_ActivePath,ActiveKey,REG_PATH_LEN);
    readerExtension->d_ActivePath[REG_PATH_LEN-1]=0;// terminated if overflow.
    readerExtension->d_uReaderState = STATE_CLOSED;

    return smartcardExtension;
} 


void
TLP3UnloadDevice(PSMARTCARD_EXTENSION SmartcardExtension)
{
    PREADER_EXTENSION pReader = SmartcardExtension->ReaderExtension;
    WCHAR szFriendlyName[MAXIMUM_ATTR_STRING_LENGTH+DEVNAME_LEN+5];
    DWORD retry = 0;

    // remove device from list of active devices managed by this driver
    RemoveDevice(SmartcardExtension);
    
    // At this point no other thread should have a reference to this object
    // make sure that's the case
    while (SmartcardExtension->ReaderExtension->d_RefCount && retry++ < 3)
    {
        Sleep(retry * 32);
        SmartcardDebug(DEBUG_INIT, (TEXT("%s:UnloadDevice - waiting for refCount %d to drop to zero\r\n"),
            szDriverName,SmartcardExtension->ReaderExtension->d_RefCount ));
        
    }
    //  ASSERT(!SmartcardExtension->ReaderExtension->d_RefCount);

    // Remove friendly name
    MakeFriendlyName(SmartcardExtension, szFriendlyName);
    SmartcardDeleteLink(szFriendlyName);
    
    // sign off from SMCLIB
    SmartcardExit(SmartcardExtension);
    
    SmartcardDebug(DEBUG_INIT, (TEXT("%s:UnloadDevice - freeing PCMCIA resources\r\n"),szDriverName));
    LocalFree(SmartcardExtension);
    SmartcardDebug(DEBUG_INIT, (TEXT("%s:UnloadDevice done with 0x%x\r\n"), szDriverName, SmartcardExtension));
}

/*  ++
TLP3CreateSerialPort 
    Open Serial Driver.
return : 
    FALSE: no serial port available.
*/

BOOL TLP3CreateSerialPort(PSMARTCARD_EXTENSION smartcardExtension)
{
 //   HANDLE hSerial;


return TRUE;

}

NTSTATUS
TLP3SerialIo(
    PSMARTCARD_EXTENSION SmartcardExtension
    )
//  The function implements smart card reader Write/Read actions.


/*++

Routine Description:

    This routine sends IOCTL's to the serial driver. It waits on for their
    completion, and then returns.

    Arguments:

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS status = STATUS_SUCCESS;
    ULONG currentByte = 0;
    BOOL bResult;
	int i=0;
	ULONG loop=0;
	int txcount=0;
	int rxcount=0;

	
    if (SmartcardExtension->SmartcardReply.BufferLength > 
        SmartcardExtension->SmartcardReply.BufferSize ||
        SmartcardExtension->SmartcardRequest.BufferLength >
        SmartcardExtension->SmartcardRequest.BufferSize) {

        SmartcardLogError(
            SmartcardExtension->OsData->DeviceObject,
            TLP3_BUFFER_TOO_SMALL,
            NULL,
            0
            );

        return STATUS_BUFFER_TOO_SMALL;
    }


{
        PUCHAR requestBuffer = SmartcardExtension->SmartcardRequest.Buffer;
        PUCHAR replyBuffer = SmartcardExtension->SmartcardReply.Buffer;
        ULONG requestBufferLength = SmartcardExtension->SmartcardRequest.BufferLength;
        ULONG replyBufferLength = SmartcardExtension->SmartcardReply.BufferLength;



         bResult=TRUE; 

        switch (SmartcardExtension->ReaderExtension->SerialIoControlCode) {
            //
            //
            case SMARTCARD_WRITE:


	g_SCI0RegBase->RegCtrl1=0xD;

	
	if(requestBufferLength)
	{	
		do{	

//				DEBUGMSG(1,(TEXT("*requestBuffer = 0x%x\r\n"),*requestBuffer));
                    		g_SCI0RegBase->RegData = *requestBuffer++;
                    		requestBufferLength--;            
  	
		     }while(requestBufferLength);
	
	}		//while((g_SCI0RegBase->RegTxCount)<4)

	g_SCI0RegBase->RegCtrl1=0x0;
                break;

				

           case SMARTCARD_READ:

		for(loop=0;loop<1000000;loop++)
		{
			if(g_SCI0RegBase->RegRxCount)
			{
				*replyBuffer++ = (unsigned char)g_SCI0RegBase->RegData;
	//		  	replyBufferLength--;
	//			TMP++;
				
			}
		//	if(!replyBufferLength)
		//		break;

		}
DEBUGMSG(1,(TEXT("*replyBuffer = 0x%x\r\n"),*SmartcardExtension->SmartcardReply.Buffer));
//DEBUGMSG(1,(TEXT("*replyBuffer+1 = 0x%x\r\n"),*(SmartcardExtension->SmartcardReply.Buffer+1)));


		g_SCI0RegBase->RegIntMask = 0x0003;

	
                break;
				
            default:
                SmartcardDebug( DEBUG_ERROR|DEBUG_SERIAL, 
                    ( TEXT("%s!TLP3SerialIo: Invalid SerialIoControlCode\n"),szDriverName));
                status = STATUS_INVALID_DEVICE_STATE;
                break;


					
        }






  //	SmartcardExtension->SmartcardReply.BufferLength -=(replyBufferLength-1);
  	SmartcardExtension->SmartcardReply.BufferLength -=replyBufferLength;

}

    return status;
}

#define MAX_SCARD_DATA_BUFFERSIZE 0x200


static BOOL InitializeDevice(  )
	{
    		int loop = 0;
    		DEBUGMSG( 1, (TEXT("InitializeDevice\r\n")));

	//DEBUGMSG (1,(TEXT("RegIntRaw:%X\n"),g_SCI0RegBase->RegBaud));

    	g_SCI0RegBase->RegCtrl0       		= 0x00;                  		// Direct convention, LSB first and Even parity
       g_SCI0RegBase->RegClkICC   		= SCI0_DEF_CLKICC;       	// Smartcard clock frequency
   	g_SCI0RegBase->RegBaudValue     	= SCI0_DEF_VALUE;        	// Baud cycles per etu
    	g_SCI0RegBase->RegBaud     		=SCI0_DEF_BAUD;		//SCI0_DEF_BAUD;         // Baud rate clock          		
    	g_SCI0RegBase->RegTide      		= 0x10;  					// RX/TX tide mark
    	g_SCI0RegBase->RegDMACtrl    	= 0x00;                  		// RX/TX DMA control
    	g_SCI0RegBase->RegStable    		= SCI0_DEF_STABLE;       	// Debounce time
    	g_SCI0RegBase->RegATime     		= SCI0_DEF_ATIME;        	// Activation event time
    	g_SCI0RegBase->RegDTime    		= SCI0_DEF_DTIME;        	// Deactivation event time
    	g_SCI0RegBase->RegATRSTime  	= SCI0_DEF_ATRSTIME;     	// Time to the start of the ATR reception
    	g_SCI0RegBase->RegATRDTime 	= SCI0_DEF_ATRDTIME;     	// Maximum duration of the ATR character stream
    	g_SCI0RegBase->RegStopTime  	= SCI0_DEF_STOPTIME;     	// Clock stop time
    	g_SCI0RegBase->RegStartTime		= SCI0_DEF_STARTTIME;    	// Clock start time
    	g_SCI0RegBase->RegRetry    		= SCI0_DEF_RETRY;        	// Retry limit
    	g_SCI0RegBase->RegChTimeMS 	= SCI0_DEF_CHTIMEMS;     	// Character to character timeout value
    	g_SCI0RegBase->RegChTimeLS  	= SCI0_DEF_CHTIMELS;
    	g_SCI0RegBase->RegBlkTimeMS 	= SCI0_DEF_BLKTIMEMS;    // Receive timeout between blocks
   	g_SCI0RegBase->RegBlkTimeLS 	= SCI0_DEF_BLKTIMELS;
    	g_SCI0RegBase->RegChGuard  	= SCI0_DEF_CHGUARD;      // Character to character guard time
    	g_SCI0RegBase->RegBlkGuard  	= SCI0_DEF_BLKGUARD;     // Block guard time
    	g_SCI0RegBase->RegRxTime   		= SCI0_DEF_RXTIME;       	// RX timeout
    	g_SCI0RegBase->RegSyncData   	= SCI0_DEF_SYNCTX;      	// Synchronous TX clock and data drive
    	g_SCI0RegBase->RegSyncRaw    	= SCI0_DEF_SYNCRX;       	// Synchronous RX clock and data drive
 	g_SCI0RegBase->RegIntClear  		= 0x1FFF	;				// ZQ  clear Intr
			

	g_SCI0RegBase->RegCtrl1      		= 0x01;  
//	g_SCI0RegBase->RegCtrl2      		= 0x01;                  		// Start activation sequence


    
	return	1;
	}
/* Sleep function to delay n*mS 
 * Uses Timer1 which is a 16bit down counter that
 * is clocked at 1MHz/PRESCALE. Prescale is 1 so
 * etimer is reached every mS. The msec value must
 * be in the range: 2^32 > msec > 0.
 * To ensure the timer is re-loaded before the first
 * comparison it is necessary to read and compare the
 * timer value before starting.
 */
  void apSleep(unsigned int msec)
{
    

   int i=msec*100;
   int n;
   for(n=0;n<i;n++)
   	{
   	}

   
}


void DEBUGPUT( )
{	
	DEBUGMSG(0, (TEXT("RegData=0x%x\r\n"), 				g_SCI0RegBase->RegData ));	
	DEBUGMSG(0, (TEXT("SCI0_CR0=0x%x\r\n"), 			g_SCI0RegBase->RegCtrl0 ));	
	DEBUGMSG(0, (TEXT("SCI0_CR1=0x%x\r\n"),			g_SCI0RegBase->RegCtrl1));	
    	DEBUGMSG(0, (TEXT("SCI0_CLKICC=0x%x\r\n"), 		g_SCI0RegBase->RegClkICC));	
    	DEBUGMSG(0, (TEXT("SCI0_VALUE=0x%x\r\n"), 			g_SCI0RegBase->RegBaudValue));
    	DEBUGMSG(0, (TEXT("SCI0_BAUD=0x%x\r\n"),			g_SCI0RegBase->RegBaud));
    	DEBUGMSG(0, (TEXT("SCI0_TIDE=0x%x\r\n"),			g_SCI0RegBase->RegTide ));
    	DEBUGMSG(0, (TEXT("SCI0_DMACR=0x%x\r\n"), 		g_SCI0RegBase->RegDMACtrl));
    	DEBUGMSG(0, (TEXT("SCI0_STABLE=0x%x\r\n"),			g_SCI0RegBase->RegStable ));
    	DEBUGMSG(0, (TEXT("SCI0_ATIME=0x%x\r\n"),			g_SCI0RegBase->RegATime ));
    	DEBUGMSG(0, (TEXT("SCI0_DTIME=0x%x\r\n"),			g_SCI0RegBase->RegDTime));
    	DEBUGMSG(0, (TEXT("SCI0_ATRSTIME=0x%x\r\n"), 		g_SCI0RegBase->RegATRSTime));
    	DEBUGMSG(0, (TEXT("SCI0_ATRDTIME=0x%x\r\n"), 		g_SCI0RegBase->RegATRDTime ));
    	DEBUGMSG(0, (TEXT("SCI0_ATRDTIME=0x%x\r\n"), 		g_SCI0RegBase->RegATRDTime ));
    	DEBUGMSG(0, (TEXT("SCI0_STOPTIME=0x%x\r\n"),		g_SCI0RegBase->RegStopTime ));
    	DEBUGMSG(0, (TEXT("SCI0_STARTTIME=0x%x\r\n"), 		g_SCI0RegBase->RegStartTime));
    	DEBUGMSG(0, (TEXT("SCI0_ASCI0_RETRYTIME=0x%x\r\n"), g_SCI0RegBase->RegRetry ));
    	DEBUGMSG(0, (TEXT("SCI0_CHTIMEMS=0x%x\r\n"), 		g_SCI0RegBase->RegChTimeMS));
    	DEBUGMSG(0, (TEXT("SCI0_CHTIMELS=0x%x\r\n"),		g_SCI0RegBase->RegChTimeLS));
    	DEBUGMSG(0, (TEXT("SCI0_DEF_BLKTIMEMS=0x%x\r\n"), g_SCI0RegBase->RegBlkTimeMS));
    	DEBUGMSG(0, (TEXT("SCI0_BLKTIMELS=0x%x\r\n"),		g_SCI0RegBase->RegBlkTimeLS));
    	DEBUGMSG(0, (TEXT("SCI0_CHGUARD=0x%x\r\n"), 		g_SCI0RegBase->RegChGuard));
    	DEBUGMSG(0, (TEXT("SCI0_BLKGUARD=0x%x\r\n"), 		g_SCI0RegBase->RegBlkGuard));
       DEBUGMSG(0, (TEXT("SCI0_RXTIME=0x%x\r\n"),			g_SCI0RegBase->RegRxTime ));
    	DEBUGMSG(0, (TEXT("SCI0_SYNCTX=0x%x\r\n"), 		g_SCI0RegBase->RegSyncData  ));
    	DEBUGMSG(1, (TEXT("SCI0_SYNCRX=0x%x\r\n"), 		g_SCI0RegBase->RegSyncRaw ));
}

void CardActive( PSMARTCARD_EXTENSION SmartcardExtension,BOOL COLDSET)
{
	unsigned loop;
	ULONG replyBufferLength=0;
	PUCHAR replyBuffer = SmartcardExtension->SmartcardReply.Buffer;


  if(COLDSET)
  	{   

	/*execute the cold reset*/
	g_SCI0RegBase->RegCtrl2 	=	0x0001;
	g_SCI0RegBase->RegCtrl2 	=	0x0004;
    SmartcardExtension->ReaderExtension->CardStatus=PL131_STATE_ACTIVECARD;
  	}
  else{
  	   SmartcardExtension->ReaderExtension->CardStatus= PL131_STATE_ACTIVECARD; 
	   g_SCI0RegBase->RegCtrl2 	=	0x0004;
  	}

	
                      
//Receive ATR string
	for(loop=0;loop<10000000;loop++)
		{
			if(g_SCI0RegBase->RegRxCount)
			{
			//	RETAILMSG(1,(TEXT("RegRxCount = 0x%x\r\n"),TMP));
				
				*replyBuffer ++= (unsigned char)g_SCI0RegBase->RegData;
			  	replyBufferLength++;
                       
			}
		
		}

	
	SmartcardExtension->SmartcardReply.BufferLength=replyBufferLength;
	RETAILMSG(0,(TEXT("ATR length = %x\r\n"),replyBufferLength ));

	SmartcardExtension->ReaderCapabilities.CurrentState =SCARD_POWERED;
	
    }

	


void POWERDOWN()
{
	g_SCI0RegBase->RegCtrl2 	=	0x0002;
}



 void Clean(  )
	{
	    /*flush FIFOs - any values here will clear the FIFOs*/

		g_SCI0RegBase->RegTxCount = 0xffff;
  		g_SCI0RegBase->RegRxCount = 0xffff;

	 /*clear all interrupts except card moving*/	
		g_SCI0RegBase->RegIntClear = 0x1fff;

	 }

⌨️ 快捷键说明

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