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

📄 test_crypt.c

📁 光学指纹头加密芯片IIC的驱动(linux 2.4)
💻 C
字号:
#include <stdio.h>     
#include <stdlib.h>
#include <sys/ioctl.h>  
#include <unistd.h>
#include <fcntl.h>

//#include <linux/cryptdriver.h>

#include "cryptdriver.h"

#define DEVICE_CRYPT  "/dev/cryptdriver"

int main()
{
	int fd; 
	int val=-1;
	int ret = 0;
	unsigned char  buf[4],i;
	//unsigned char *pPassword;
       struct crypt_ioctl_data argm;
	  
	if((fd=open(DEVICE_CRYPT,O_RDONLY | O_NONBLOCK))<0)
	{
		perror("can not open device");
		exit(1);
	}

	while(1){
		printf("1:write block ,2:read block,3:reset chip,4:Verify PWD ,5:Init Auth,6:Verify Auth,0:quit :");
		scanf("%d",&val);
		if(val==1) {//write block
			buf[0]=21;
			argm.Zone=3;  		// Zone
	  		argm.Start=0x0f;		//Start
	  		argm.PBuffer=buf;		//PBuffer
			argm.Count=1;		//Count
			ret =ioctl(fd,WRITE_BLOCK,&argm);//write the data:25 to the MTD
			printf("Result: %d\n", ret);
		}else if(val==2){//read block
		       buf[0]=0;
		       argm.PBuffer=buf;	//PBuffer
			argm.Zone=3;		// Zone		
	  		argm.Start=0x0f;		//Start
			argm.Count=1;		//Count
			ret =ioctl(fd,READ_BLOCK,&argm);//Read the data from MTD
			buf[0]=argm.PBuffer[0];
			printf("read result: %d\n",buf[0]);
		}else if(val==3){//reset chip
			ioctl(fd,RESET_CHIP,&buf[0]);//reset the chip,return the 4 bytes ATR
			for(i=0;i<4;i++){
				printf("ATR[%d]:",i);
				printf("%02X,",buf[i]);
				}
			printf("\n");	
		}else if(val==4){//verify password
			argm.Zone=0;		//bRead
	  		argm.Start=1;			//nIndex
			argm.PBuffer[0]=0x12;	argm.PBuffer[1]=0x34;argm.PBuffer[2]=0x56;//pPassword
			ret =ioctl(fd,VERIFY_PWD,&argm);//verify password 
			printf("Verify PWD result: %d\n",ret);
		}else if(val==5){//Initialize Authentication
			argm.PBuffer[0]=1;argm.PBuffer[1]=2;argm.PBuffer[2]=3;//Authentication
			argm.PBuffer[3]=4;argm.PBuffer[4]=5;argm.PBuffer[5]=6;argm.PBuffer[6]=6;
			ret =ioctl(fd,INIT_AUTH,&argm);//Initialize Authentication
			printf("Init Auth result: %d\n",ret);
		}else if(val==6){//Verify Authentication
			argm.PBuffer[0]=1;argm.PBuffer[1]=2;argm.PBuffer[2]=3;//Authentication
			argm.PBuffer[3]=4;argm.PBuffer[4]=5;argm.PBuffer[5]=6;argm.PBuffer[6]=6;
			ret =ioctl(fd,VERIFY_AUTH,&argm);//Verify Authentication
			printf("Verify Auth result: %d\n",ret);
		}else if(val==0) {
			close(fd);
			exit(0);
		}
	}
	return 0;
}

⌨️ 快捷键说明

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