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

📄 simcb.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
            break;

        case SCARD_PROTOCOL_RAW:
            SmartcardDebug(DEBUG_ERROR,( TEXT("RAW protocol is not supported in this driver!\n")));
            return (STATUS_UNSUCCESSFUL);
            break;

        default:
            NTStatus = STATUS_INVALID_DEVICE_REQUEST;
            break;
    }

    SmartcardDebug( DEBUG_TRACE, (TEXT("-CBTransmit Exit: %X\n"),NTStatus ));

    return( NTStatus );
}


//-----------------------------------------------------------------------------
//
// Function: CBT0Transmit
//
// This function finishes the callback RDF_TRANSMIT for the T0 protocol
//
// Parameters:
//      SmartcardExtension
//          [in]Pointer of the context of call
//
// Returns:
//      NTSTATUS:
//      STATUS_SUCCESS
//      STATUS_NO_MEDIA
//      STATUS_TIMEOUT
//      STATUS_INVALID_DEVICE_REQUEST
//
//-----------------------------------------------------------------------------
static NTSTATUS CBT0Transmit(PSMARTCARD_EXTENSION SmartcardExtension)
{
    NTSTATUS NTStatus = STATUS_SUCCESS;

    SmartcardDebug( DEBUG_TRACE, (TEXT("+CBT0Transmit Enter\n")));

    SmartcardExtension->SmartcardRequest.BufferLength = 0;

    //    let the lib setup the T=1 APDU & check for errors
    NTStatus = SmartcardT0Request( SmartcardExtension );

    if( NTStatus == STATUS_SUCCESS )
    {
        NTStatus = T0_ExchangeData(
            SmartcardExtension->ReaderExtension,
            SmartcardExtension->SmartcardRequest.Buffer,
            SmartcardExtension->SmartcardRequest.BufferLength,
            SmartcardExtension->SmartcardReply.Buffer,
            &SmartcardExtension->SmartcardReply.BufferLength);

        if( NTStatus == STATUS_SUCCESS )
        {
            //    let the lib evaluate the result & tansfer the data
            NTStatus = SmartcardT0Reply( SmartcardExtension );
        }
    }

    SmartcardDebug( DEBUG_TRACE,(TEXT("-CBT0Transmit Exit: %X\n"),NTStatus ));

    return( NTStatus );
}


//-----------------------------------------------------------------------------
//
// Function: T0_ExchangeData
//
// This function does T=0 management
//
// Parameters:
//      ReaderExtension
//          [in]Pointer of the context of call
//      pRequest
//          [in]Request buffer
//      RequestLen
//          [in]/[out]Request buffer length
//      pReply
//          [in]Reply buffer
//      pReplyLen
//          [in]/[out]Reply buffer length
//
// Returns:
//      NTSTATUS:
//
//-----------------------------------------------------------------------------
static NTSTATUS T0_ExchangeData(
    PREADER_EXTENSION    ReaderExtension,
    PUCHAR                pRequest,
    ULONG                RequestLen,
    PUCHAR                pReply,
    PULONG                pReplyLen)
{
    NTSTATUS NTStatus = STATUS_SUCCESS;
    BOOLEAN Direction;
    UCHAR Ins, Pcb;
    ULONG Len, DataIdx;

    SmartcardDebug( DEBUG_TRACE, (TEXT("+T0_ExchangeData Enter\n")));


    //    get direction
    Ins = pRequest[ INS_IDX ] & 0xFE;
    Len    = pRequest[ P3_IDX ];

    if( RequestLen == 5 )
    {
        Direction    = ISO_OUT;
        DataIdx        = 0;
        // For an ISO OUT command Len=0 means that the host expect an 
        // 256 byte answer
        if( !Len )
        {
            Len = 0x100;
        }
        // Add 2 for SW1 SW2
        Len+=2;

        DataIdx += Len;
    } 
    else
    {
        Direction    = ISO_IN;
        DataIdx        = 5;
    }

    //    send header CLASS,INS,P1,P2,P3
    NTStatus = SIM_WriteData( ReaderExtension->pSIMReg, pRequest, 5 );

    if( NTStatus == STATUS_SUCCESS )
    {
        NTStatus = STATUS_MORE_PROCESSING_REQUIRED;
    }

    while( NTStatus == STATUS_MORE_PROCESSING_REQUIRED )
    {
        // PCB reading
        Pcb = 0;
        NTStatus = SIM_ReadData( ReaderExtension->pSIMReg, &Pcb, 1 );
        
        if( NTStatus == STATUS_SUCCESS )
        {
            if( Pcb == 0x60 )
            {
                //    null byte?
                NTStatus = STATUS_MORE_PROCESSING_REQUIRED;
                continue;
            }
            else if( ( Pcb & 0xFE ) == Ins )
            {
                //    transfer all
                if( Direction == ISO_IN )
                {
                    //    write remaining data
                    NTStatus = SIM_WriteData( ReaderExtension->pSIMReg, pRequest + DataIdx, Len );
                    if( NTStatus == STATUS_SUCCESS )
                    {
                        //    if all data successful written the status word is expected
                        NTStatus    = STATUS_MORE_PROCESSING_REQUIRED;
                        Direction    = ISO_OUT;
                        DataIdx        = 0;
                        Len            = 2;
                    }
                }
                else
                {
                    //    read remaining data
                    NTStatus = SIM_ReadData( ReaderExtension->pSIMReg, pReply, Len );
					
                }
            }
            else if( (( Pcb & 0xFE ) ^ Ins ) == 0xFE )
            {
                //    transfer next
                if( Direction == ISO_IN )
                {
                    //    write next

                    NTStatus = SIM_WriteData( ReaderExtension->pSIMReg, pRequest + DataIdx, 1 );

                    if( NTStatus == STATUS_SUCCESS )
                    {
                        DataIdx++;

                        //    if all data successful written the status word is expected
                        if( --Len == 0 )
                        {
                            Direction    = ISO_OUT;
                            DataIdx        = 0;
                            Len            = 2;
                        }
                        NTStatus = STATUS_MORE_PROCESSING_REQUIRED;
                    }
                }
                else
                {
                    //    read next
                    NTStatus = SIM_ReadData( ReaderExtension->pSIMReg, pReply + DataIdx, 1 );


                    if( NTStatus == STATUS_SUCCESS )
                    {
                        NTStatus = STATUS_MORE_PROCESSING_REQUIRED;
                        Len--;
                        DataIdx++;
                    }
                }
            }
            else if( (( Pcb & 0x60 ) == 0x60 ) || (( Pcb & 0x90 ) == 0x90 ) || (( Pcb & 0x9F ) == 0x9F ) )
            {
                if( Direction == ISO_IN )
                {
                    Direction    = ISO_OUT;
                    DataIdx        = 0;
                }

                //    SW1
                *pReply    = Pcb;

                //    read SW2 and leave
                NTStatus = SIM_ReadData( ReaderExtension->pSIMReg, &Pcb, 1 );

                *(pReply + 1)    = Pcb;
                DataIdx            += 2;
            }
            else
            {
                NTStatus = STATUS_UNSUCCESSFUL;
            }
        }
    }

    if(( NTStatus == STATUS_SUCCESS ) && ( pReplyLen != NULL ))
    {
        *pReplyLen = DataIdx;
    }

    SmartcardDebug( DEBUG_TRACE, (TEXT("-T0_ExchangeData Enter\n")));

    return( NTStatus );        
}


//-----------------------------------------------------------------------------
//
// Function: CBCardTracking
//
// This function is the callback handler for SMCLIB RDF_CARD_TRACKING
//
// Parameters:
//      SmartcardExtension
//          [in]Pointer of the context of call
//
// Returns:
//      NTSTATUS:
//      STATUS_PENDING
//
//-----------------------------------------------------------------------------
NTSTATUS CBCardTracking(PSMARTCARD_EXTENSION SmartcardExtension)
{
    SmartcardDebug(DEBUG_TRACE, (TEXT("+CBCardTracking\n")));

    SmartcardExtension->ReaderExtension->IoctlPending=TRUE;

    SmartcardDebug(DEBUG_TRACE, (TEXT("-CBCardTracking\n")));

    return( STATUS_PENDING );

}


//-----------------------------------------------------------------------------
//
// Function: CBSynchronizeSIM
//
// This function updates the card dependend data of the SIM
//
// Parameters:
//      SmartcardExtension
//          [in]Pointer of the context of call
//
// Returns:
//      NTSTATUS
//
//-----------------------------------------------------------------------------
static NTSTATUS CBSynchronizeSIM(PSMARTCARD_EXTENSION SmartcardExtension)
{
    NTSTATUS NTStatus = STATUS_SUCCESS;
    BOOL Clock, Time;

    SmartcardDebug(DEBUG_TRACE, (TEXT("+CBSynchronizeSIM\n")));
    
    //    set character waiting & guard time
    switch ( SmartcardExtension->CardCapabilities.Protocol.Selected )
    {
        case SCARD_PROTOCOL_T0:
            Clock = SIM_ConfigCLK(SmartcardExtension->ReaderExtension->pSIMReg, 
                SmartcardExtension->CardCapabilities.Fl, 
                SmartcardExtension->CardCapabilities.Dl);

            if(Clock == FALSE)
                SmartcardDebug( DEBUG_DRIVER,( TEXT("Problems in clock configuration\n")));

            Time = SIM_ConfigTime(SmartcardExtension->ReaderExtension->pSIMReg, 
                SmartcardExtension->CardCapabilities.N, 
                SmartcardExtension->CardCapabilities.T0.WI);
            if(Time == FALSE)
                SmartcardDebug( DEBUG_DRIVER,( TEXT("Problems in time configuration\n")));    
            break;

        case SCARD_PROTOCOL_T1:
                SmartcardDebug(DEBUG_ERROR,( TEXT("T1 protocol is not supported in this driver!\n")));

        default:
            NTStatus = STATUS_UNSUCCESSFUL;
            break;
    }

    SmartcardDebug(DEBUG_TRACE, (TEXT("-CBSynchronizeSIM\n")));

    return( NTStatus );
}



//-----------------------------------------------------------------------------
//
// Function: CBUpdateCardState
//
// This function updates the variable CurrentState in SmartcardExtension
//
// Parameters:
//      SmartcardExtension
//          [in]Pointer of the context of call
//
// Returns:
//      NTSTATUS:
//      STATUS_SUCCESS
//
//-----------------------------------------------------------------------------
NTSTATUS CBUpdateCardState(PSMARTCARD_EXTENSION SmartcardExtension)
{
    NTSTATUS NTStatus = STATUS_SUCCESS;

    SmartcardDebug(DEBUG_TRACE, (TEXT("+CBUpdateCardState\n")));
    
    //    read card state
    SmartcardLockDevice(SmartcardExtension);

    if(SIM_CheckCard(SmartcardExtension->ReaderExtension->pSIMReg))
        SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_PRESENT;
    else
        SmartcardExtension->ReaderCapabilities.CurrentState = SCARD_ABSENT;

    SmartcardUnlockDevice(SmartcardExtension);
    SmartcardDebug(DEBUG_TRACE, (TEXT("-CBUpdateCardState\n")));
    
    return(NTStatus);
}


//	-------------------------------- END OF FILE ------------------------------




⌨️ 快捷键说明

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