| /************************************************************************ | 
 | *¹¦ÄܽéÉÜ£ºÓû§Ä£Ê½ÇÐÑз¢Ä£Ê½¼øÈ¨ | 
 | *¸ºÔðÈË£º | 
 | *±¸·ÝÈË£º | 
 | *ÐÞ¸ÄÈÕ£º2019/9/20 | 
 | *ÐÞ¸ÄÄÚÈÝ£º | 
 | *°æ±¾ºÅ£ºv1.0 | 
 | ************************************************************************/ | 
 | #include <stdio.h> | 
 | #include <unistd.h> | 
 | #include <getopt.h> | 
 | #include <sys/types.h> | 
 | #include <sys/stat.h> | 
 | #include <fcntl.h> | 
 | #include <sys/ioctl.h> | 
 | #include <strings.h> | 
 | #include <sys/types.h> | 
 | #include <assert.h> | 
 | #include "os_type_def.h" | 
 | #include "RONvParam_AMT.h" | 
 | #include "libcpnv.h" | 
 |  | 
 | int auth_device_key_init_value(void) | 
 | { | 
 | 	/*³õʼֵΪ0´ò¿ªÑз¢Ä£Ê½ÐèÃÜÂëÇл»¹¦ÄÜ£¬Ä¬ÈÏΪ1²»´ò¿ª*/ | 
 | 	//return 0; | 
 | 	return 1; | 
 | } | 
 |  | 
 | int verify_device_key(char *device_key,int key_len,char *seed,int seed_len) | 
 | { | 
 | 	int verify_result = auth_device_key_init_value(); | 
 | 	//char myInit[16] = "ZXIC-TSP"; | 
 | 	 | 
 | 	//»ñÈ¡IMEIºÅ | 
 | 	unsigned int retCode =  CPNV_ERROR; | 
 |     unsigned char imei_bcd[8]= {0}; | 
 | 	int abImeiindex = 0,imeistrindex = 0; | 
 |     char imeistr[2*8] = {0}; | 
 | 	int i = 0; | 
 |  | 
 | 	if((device_key == NULL)||(key_len != 6)||(seed == NULL)||(seed_len != 8)) | 
 | 	{ | 
 |     	printf("parameter error!\r\n"); | 
 | 		return verify_result; | 
 | 	} | 
 | 	printf("parameter device key = %s,key_len=%d,seed = %s,seed_len=%d\r\n",device_key,key_len,seed,seed_len); | 
 | 	retCode = cpnv_NvItemRead(OS_FLASH_AMT_COMM_RO_IMEI_ADDRESS, (unsigned char *)imei_bcd, OS_FLASH_AMT_COMM_RO_IMEI_SIZE); | 
 |     printf("retCode = %d\r\n",retCode ); | 
 |     if(CPNV_ERROR == retCode ) | 
 |     { | 
 |         printf("read imei fail!\r\n"); | 
 |         return verify_result; //»ñÈ¡imeiºÅʧ°Ü | 
 |     } | 
 |     #if 0 | 
 | 	for (i = 0; i < sizeof(imei_bcd); i++) | 
 | 	{ | 
 | 		printf("imei_bcd[%d] = %02x\r\n",i,imei_bcd[i]); | 
 | 	} | 
 |      | 
 |     for (abImeiindex=0; abImeiindex< 8-1; abImeiindex++,imeistrindex+=2) | 
 |     { | 
 |         imeistr[imeistrindex] = (imei_bcd[abImeiindex]&0x0F) + '0'; | 
 |         imeistr[imeistrindex+1] = ((imei_bcd[abImeiindex]&0xF0)>>4)+ '0'; | 
 |     } | 
 |      | 
 |     imeistr[2*8-2]=(imei_bcd[8-1]&0x0F)+ '0'; | 
 |     imeistr[2*8-1] = '\0'; | 
 |  | 
 | 	printf("imei = %s\r\n",imeistr); | 
 | 	#endif | 
 | 	 | 
 |     imei_bcd[7] |= 0xF0; | 
 | 	for (i = 0; i < sizeof(imei_bcd); i++) | 
 | 	{ | 
 | 		imei_bcd[i] += seed[i]; | 
 | 	} | 
 |  | 
 | 	for (i = 0; i < sizeof(imei_bcd); i++) | 
 | 	{ | 
 | 		printf("imei_bcd[%d] = %02x\r\n",i,imei_bcd[i]); | 
 | 	} | 
 |  | 
 | 	unsigned int crc = crc32(0, imei_bcd, sizeof(imei_bcd)); | 
 | 	printf("crc = %02x\r\n",crc); | 
 |  | 
 | 	char buf[16] = { 0 }; | 
 |  | 
 | 	for (i = 0; i < 8; i++) | 
 | 	{ | 
 | 		buf[i] = ((crc >> (28 - i * 4)) & 0xF); | 
 | 		if (buf[i] > 9) | 
 | 		{ | 
 | 			buf[i] = buf[i] + 'A' - 10; | 
 | 		} | 
 | 		else | 
 | 		{ | 
 | 			buf[i] = buf[i] + '0'; | 
 | 		} | 
 | 	} | 
 |  | 
 | 	//printf("buf = %s\r\n",buf); | 
 |  | 
 | 	printf("current device key = %s\r\n",buf+2); | 
 |  | 
 | 	if(strcmp(buf+2,device_key)== 0) | 
 | 	{ | 
 | 		verify_result = 1; | 
 | 		printf("verify device key success!verify_result=%d\r\n",verify_result); | 
 | 	} | 
 | 	else | 
 | 	{ | 
 | 		printf("verify device key fail!verify_result=%d\r\n",verify_result); | 
 | 	} | 
 | 	 | 
 | 	return verify_result; | 
 | } | 
 |  | 
 |  | 
 |  |