?? test111.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 + -