|
|
|
@ -1217,7 +1217,73 @@ int SpiLIb::SM2cert(int type,int index,string cert,unsigned char *out_cert)//证
|
|
|
|
|
close(fd);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int SpiLIb::Indentify(unsigned char *to_idt,unsigned char *out_idt)//安全认证
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int cnt;
|
|
|
|
|
unsigned char txbuf[512];
|
|
|
|
|
unsigned char rxbuf[512];
|
|
|
|
|
|
|
|
|
|
int retval;
|
|
|
|
|
int msglen;
|
|
|
|
|
int fd;
|
|
|
|
|
const char *devname = "/dev/spidevSE";
|
|
|
|
|
//const char *devname = "/dev/spidev0.0";
|
|
|
|
|
//const char *devname = "/dev/mtkgpioctrl";
|
|
|
|
|
|
|
|
|
|
// NrsecSpiPort spi("/dev/spidevSE");
|
|
|
|
|
//
|
|
|
|
|
// // NrsecSpiPort spi("/dev/spidev0.0")
|
|
|
|
|
fd = open(devname, O_RDWR);
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
perror("open");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
spi_master_init(devname, fd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msglen = 5;
|
|
|
|
|
memset(rxbuf, 0, sizeof(rxbuf));
|
|
|
|
|
memset(txbuf, 0, sizeof(txbuf));
|
|
|
|
|
|
|
|
|
|
//printf("tx %1d bytes: ", msglen);
|
|
|
|
|
//__android_log_print(ANDROID_LOG_INFO, "SPi", "tx %1d bytes", msglen);
|
|
|
|
|
|
|
|
|
|
CMD_RESEND:
|
|
|
|
|
|
|
|
|
|
memcpy(txbuf, (const void *) Indentify_CMD, sizeof(Indentify_CMD));
|
|
|
|
|
|
|
|
|
|
SendCmdHeader(fd, txbuf, rxbuf);
|
|
|
|
|
|
|
|
|
|
RcvINS(fd,txbuf,rxbuf,txbuf[1]);
|
|
|
|
|
|
|
|
|
|
SendId(fd,txbuf,rxbuf, 0x55);
|
|
|
|
|
|
|
|
|
|
memcpy(txbuf, to_idt, 32);
|
|
|
|
|
|
|
|
|
|
SendData(fd, txbuf, rxbuf,32);
|
|
|
|
|
|
|
|
|
|
SendEnd(fd,txbuf,rxbuf);
|
|
|
|
|
|
|
|
|
|
memcpy(txbuf, (const void *) SM2decoder_CMD, sizeof(SM2decoder_CMD));
|
|
|
|
|
|
|
|
|
|
RcvINS(fd,txbuf,rxbuf,txbuf[1]);
|
|
|
|
|
|
|
|
|
|
RcvLEN(fd,txbuf,rxbuf+1, 1);
|
|
|
|
|
|
|
|
|
|
RcvData(fd, txbuf, rxbuf+2);
|
|
|
|
|
|
|
|
|
|
RcvSW(fd, txbuf, rxbuf+2+rxbuf[1], 0x90);
|
|
|
|
|
|
|
|
|
|
//__android_log_print(ANDROID_LOG_INFO, "SPi", "rx %1d bytes:", rxbuf[1]+4);
|
|
|
|
|
for (i = 2; i < rxbuf[1]+2; i++) {
|
|
|
|
|
//sprintf(output, " %02x ", rxbuf[i]);
|
|
|
|
|
out_idt[i-2]= rxbuf[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|