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

📄 复件 test.c

📁 QQ2440 linux刷卡后用户名自动登录getty文件,包含IC读卡器驱动和Makefile文件.
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "ftcard.h"static int String2HEX(const char* pInput, int strlen, char* pOutput, int* pOutLen){    int     i;    char    s1, s2, b1, b2;    if( pInput == NULL || pOutput == NULL ) {        return -1;    }    if ( 0 != strlen % 2 ) {        return -1;    }        if ( *pOutLen < strlen / 2 ) {        return -1;    }    for ( i = 0; i < strlen / 2; ++i ) {        s1 = pInput[ 2 * i ];        s2 = pInput[ 2 * i + 1 ];        b1 = toupper( s1 ) - 0x30;        if ( b1 > 9 )                b1 = b1 - 7;        b2 = toupper( s2 ) - 0x30;        if ( b2 > 9 )                b2 = b2 - 7;        pOutput[i] = (char)( b1 << 4 ) + b2;    }        *pOutLen = strlen/2;        return 0;}int main(){        int           fd;   /* the handle of rockey200 */    int           ret;  /* save the value of return */        int           j;          int           send_len;      /* the length of send message */    int           receive_len;   /* the length of receive message */      //  char          ATRString[ 36 ];  /* save atr info */        unsigned char send_buf[ 256 ];  //   unsigned char receive_buf[ 256 ];            /* the APDU which send to card , you can edit it */        char*         apdu = "0084000008";  /* 0084000008 is the get stochastic number apdu */        /* openepass(int Lun) is used to open the card, it must be called.       if under "/dev" find ftcard0,  the Lun set 0 */    fd = openepass( 0 );	if( fd < 0 ) {	    printf(" \n >>>>not find ftcard driver \n " );		return -1;	}		/* get ATR */	memset( ATRString, 0, sizeof( ATRString ) );	ret = GetAtr( fd, ATRString );	if( ret == 0 ) {		printf(" Get Atr : %s\n", ATRString + 5 );	} else {  		return -1;	}		/* Transmit apdu to get stochastic number */    memset( send_buf, 0, sizeof( send_buf ) );    memset( receive_buf, 0, sizeof( receive_buf ) );        send_len = sizeof( send_buf );            ret = String2HEX( apdu, strlen( apdu ), (unsigned char*)send_buf, (int*)&send_len );    if( ret < 0 ) {        printf( "ret=%d,apdu error!",ret );        return -1;    }        /* send apdu */    ret = TransmitToICC( fd, send_buf, send_len, receive_buf, &receive_len );    if( ret == 0 ) {        for( j = 0; j < receive_len; j++ ) {			printf( "%02x ",receive_buf[j] );		}    } else {        printf( "\n >>>error , not get message \n ");        return -1;    }    printf( "\n" );		/* close pass */	closeepass(fd);        return 0;}

⌨️ 快捷键说明

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