예제 #1
0
PThread_Control_Unit::PThread_Control_Unit()
{
#if 1
	JCG("Init");
	golbe_i0 = 0;
	pthread_mutex_init(&mutex, &attr);
	pthread_mutexattr_init(&attr);
#endif
}
예제 #2
0
int read_file_from_mmc()
{
	char cmd_buf[1024];
	sync();
	usleep(100*1000);
	/*remove data*/
	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s %s",CMD_PREFIX,"rm -rf", DATA_PATH);
	system(cmd_buf);		//system("/system/xbin/busybox rm -f /sdcard/sn.dat ");
	JCG("cmd-->%s",cmd_buf);
	/*get data from mmc*/
	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s",SOURCE_DATA_PATH , DATA_PATH, CMD_ARGS);
	system(cmd_buf);		//system("dd if=/dev/block/mmcblk1 of=/sdcard/sn.dat skip=5200 bs=512 count=5");
	JCG("cmd-->%s",cmd_buf);
	sync();
	return 0;
}
예제 #3
0
void testSHA256(){  
	unsigned char in[]="asdfwerqrewrasfaser";  
	unsigned char out[32];  

	size_t n;  
	int i;  

	n=strlen((const char*)in);  

	SHA256(in,n,out);  
	JCG("\n\nSHA256 digest result:\n");  

	JCG("%d\n",sizeof(out));  

	for(i=0;i<32;i++)  
		JCG("%d",out[i]);  
	JCG("\n");  

}
예제 #4
0
파일: tve.c 프로젝트: alessandroste/testBSP
static long tve_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	switch (cmd)
	{
		case	TVE_STAT:	// 6
			JCG("change stat");
			break;
		case	TVE_DISABLE:		// 1
			tve_stat = STAT_DISCONNECT;
			JCG("TVE_DISABLE");
			tve_stat = STAT_CONNECT;
			break;
		case	TVE_ENABLE:		// 2
			JCG("TVE_ENABLE");
			break;
		case	TVE_SET_RESOLUTION_PAL:	// 3	/* VGA 720x576p */
			JCG("TVE_PAL");
			break;
		case	TVE_SET_RESOLUTION_NTSC:	// 4	/* VGA 640x480p */
			JCG("TVE_NTSC");
			break;
		case	TVE_SET_RESOLUTION_800_600_60:	// 5
			JCG("TVE_800_600");
			break;
		case	TVE_SET_RESOLUTION_1024_768_60:	// 6
			JCG("TVE_1024_768");
			break;
		default:
			JCG("TVE_INVAL");
		//	return -EINVAL;
			break;
	}
#ifdef CONFIG_CS8556_TVOUT
		ret |= cs8556.miscdev.fops->unlocked_ioctl(file,cmd,arg);
#endif
#ifdef CONFIG_CH7025_7026_TVOUT
		ret |= ch7026.miscdev.fops->unlocked_ioctl(file,cmd,arg);
#endif
#ifdef CONFIG_NS115_STICK_LCD_OUT
		ret |= stick_minor_display.miscdev.fops->unlocked_ioctl(file,cmd,arg);
#endif
			JCG("---===============ret:%d================--------",ret);
		if(cmd == TVE_STAT)
			return ret;
		return 0;
}
예제 #5
0
void testRSAGen(){  
	RSA *r;  
	int bits=512,ret;  
	unsigned long e=RSA_3;  
	BIGNUM  *bne;  
	r=RSA_generate_key(bits,e,NULL,NULL);  
	RSA_print_fp(stdout,r,11);  
	JCG("--------------------------------\n");  
	RSA_free(r);  
	bne=BN_new();  
	ret=BN_set_word(bne,e);  
	r=RSA_new();  
	ret=RSA_generate_key_ex(r,bits,bne,NULL);  
	if(ret!=1)  
	{  
		JCG("RSA_generate_key_ex err!\n");  
		return;  
	}  
	/*RSA_print_fp(stdout,r,11);   */
	RSA_free(r);  
}
예제 #6
0
int write_file_to_mmc()
{
	char cmd_buf[1024];
	sync();
	usleep(100*1000);
	/* write to flash */
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s",DATA_PATH,SOURCE_DATA_PATH,CMD_ARGS_WRITE);
	system(cmd_buf);		/*system("dd if=/sdcard/sn.dat of=/dev/block/mmcblk1 seek=5200 bs=512");*/
	JCG("cmd-->%s",cmd_buf);
	sync();
	return 0;
}
예제 #7
0
int delete_data_file()
{
	char cmd_buf[1024];
	sync();
	usleep(100*1000);
	/* write to flash */
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"rm %s ",DATA_PATH);
	system(cmd_buf);		/*system("dd if=/sdcard/sn.dat of=/dev/block/mmcblk1 seek=5200 bs=512");*/
	JCG("cmd-->%s",cmd_buf);
	sync();
	return 0;
}
예제 #8
0
void *
PThread_Control_Unit::Print_Thread_Test(void *m_data)
{
	int i0 = 0;
	int ret;
	pthread_t *m_pid_1;
	pthread_attr_t m_attr;
	sched_param param;

#if 1 //mutex
	pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
	pthread_mutex_lock(&mutex);
#endif
#if 0
	pthread_attr_init(&m_attr);
	pthread_attr_setschedparam(&m_attr, &param);
	param.sched_priority = 0;
	pthread_attr_setschedparam(&m_attr, &param);

	ret= pthread_create(m_pid_1, &m_attr, Print_Thread_Test_1, m_data);
	if(ret < 0)
		JCG("Error in creating pthread!");
#endif
	while(1)
	{
		JCG("loop [ %d : %d ] get --> %s ",i0, golbe_i0 ,(char*)m_data);
		sleep(1);
		i0++;
		golbe_i0++;
		if(i0 > 5)
			break;
	}
#if 1 //mutex
	pthread_mutex_unlock(&mutex);
#endif
	//pthread_attr_destroy(&m_attr);
	pthread_exit((void*)"return this message!");
}
예제 #9
0
int clear_data()
{
	char cmd_buf[128];
	/*remove data*/
	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s", "/dev/zero",SOURCE_DATA_PATH,CMD_ARGS_WRITE);
	system(cmd_buf);		//system("dd if=/dev/zeroof=/dev/block/mmcblk1 seek=5200 bs=512 count=5 ");
	JCG("cmd-->%s",cmd_buf);

	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"rm -rf %s", DATA_PATH);
	system(cmd_buf);		//system("rm -rf /sdcard/sn.dat");
	sync();
	return 0;
}
예제 #10
0
void *
PThread_Control_Unit::Print_Thread_Test_1(void *m_data)
{
	int i0 = 999;
	while(1)
	{
		JCG("loop [ %d : %d ] get --> %s ",i0, golbe_i0 ,(char*)m_data);
		golbe_i0++;
		i0--;
		sleep(1);
		if(i0 < 997)
			break;
	}
	
}
예제 #11
0
pthread_t*
PThread_Control_Unit::Thread_Creat_test(void* m_data)
{
	int ret;
	pthread_t m_pid;
	pthread_t m_pid_1;

	pthread_attr_t m_attr;
	pthread_attr_init(&m_attr);
	//pthread_attr_setscope(&m_attr,PTHREAD_SCOPE_SYSTEM);
	//pthread_attr_setscope(&m_attr,PTHREAD_SCOPE_PROCESS);
	//pthread_attr_setdetachstate(&m_attr,PTHREAD_CREATE_JOINABLE);
	//PTHREAD_CREATE_JOINABLE
	//PTHREAD_CREATE_DETACHED
	//SCHED_OTHER		Normal, not realtime
	//SCHED_RR			realtime
	//SCHED_FIFO
	//sched_priority	//only availible when RR or FIFO is seted

#if 1
	ret= pthread_create(&m_pid, &m_attr, Print_Thread_Test, m_data);
#else
	ret= pthread_create(&m_pid, NULL, Print_Thread_Test, m_data);
#endif
	if(ret < 0)
		JCG("Error in creating pthread!");
#if 0
	ret= pthread_create(m_pid_1, NULL, Print_Thread_Test_1, m_data);
#else
	ret= pthread_create(&m_pid_1, NULL, Print_Thread_Test, (void*)"OPQRSTUVWXYZ");
#endif
	if(ret < 0)
		JCG("Error in creating pthread!");
	pthread_attr_destroy(&m_attr);
	return &m_pid;
}
예제 #12
0
int encrypt_write_data(char *data,  int isappend)
{
	int fd;
	char test_data[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
BBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
CBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
DBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
EBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
FBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
GBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
HBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
JBCDEFGHIJKLMNOPQRSTUVWXYZ--1234567890-\n\
KBCDEFGHIJKLMNOPQRSTUVWXYZ--1234--end\n\
		";
	int get_len;
	int i0 = 0;
	char m_str[128];
	char m_del[128];
	char mode = 0;
	/*testSHA256();  */
	memset(m_str,0x0,sizeof(m_str));
	memset(m_del,0x0,sizeof(m_del));

	if(!isappend)
	{
		JCG("using memory mode, not append mode!");
//		sprintf(m_del, "rm -rf %s",ENC_DATA_PATH);
//		system(m_del);
		fd = open(ENC_DATA_PATH ,O_RDWR | O_CREAT ,0666);
	}
	else
	{
		JCG("using APPEND mode");
		mode |= O_APPEND ;
		fd = open(ENC_DATA_PATH ,O_RDWR | O_CREAT | O_APPEND ,0666);
	}

	//fd = open(ENC_DATA_PATH ,O_RDWR | O_CREAT | mode,0666);
	if(fd < 0 )
	{
		JCG("can not write to encode file %d !",fd);
		return -1;
	}

#if 0		//test
	get_len = strlen(test_data);
	while(get_len > 0)
	{
		snprintf(m_str, sizeof(m_str) - 12 +1 ,"%s", test_data + (sizeof(m_str) - 12)* i0);
		Encode_RSA(m_str, fd);
		get_len -= (sizeof(m_str) - 12);
		i0++;
	}
#else
	get_len = strlen(data);
	while(get_len > 0)
	{
		snprintf(m_str, sizeof(m_str) - 12 +1 ,"%s", data + (sizeof(m_str) - 12)* i0);
		Encode_RSA((unsigned char*)m_str, fd);
		get_len -= (sizeof(m_str) - 12);
		i0++;
	}
#endif
	close(fd);

	return 0;
}
예제 #13
0
int main(int argc, char *argv[])
{
	char str_to_write[1024];
	int i0 = 0;
	int  fd_read;
	int  fd;
	int  ret = 0;

	char sn_header[16];
	char serial_number[SN_MAX_LEN];
	char *str_sn;
	char str_slip[] = "-";
	char arg_val[8][64];
	CARD_INFO *card_data;
	CARD_INFO *card_tmp;
	char *str_read;

	int fd0;
	char buf[sizeof(char)+1];
	char str_storeu[2048];
	int read_flag = 0;
#ifdef DEBUG_IN_LINUX
	char m_data[2048];
#endif

	char cmd_buf[256];
	CARD_INFO *card_store[MAX_CARD_NUMBER];

	memset(str_to_write  , 0x0 , sizeof(str_to_write));
	memset(sn_header     , 0x0 , sizeof(sn_header));
	memset(serial_number , 0x0 , sizeof(serial_number));
	memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
#ifdef DEBUG_IN_LINUX
	memset(m_data        , 0x0 , sizeof(m_data));
#endif
	#ifdef ENABLE_STRUCT
	i0 = 0;
	while(i0 < sizeof(card_store)/sizeof(CARD_INFO))
	{
		memset(card_store,0x0,sizeof(CARD_INFO));
		i0++;
	}
	#endif
	prepare_env();

	//read_file_from_mmc();
	/* go out if argument less than 2 */
	if(argc < 2)
	{
#ifdef DEBUG_IN_LINUX
		//testRSAGen();
		//encrypt_write_data("test data!",0);
		//decrypt_read_data(m_data);
		//JCG("read -->\n%s\n",m_data);
#endif
		JCG("bad args, should be ./q YCT-000000123455; ./q read; ./q write etc.");
		ret = -1;
		goto RET_ERR;
	}
	JCG("argv[0]:%s, argv[1]:%s.\n",argv[0],argv[1]);

	if(strcasecmp(argv[1],"clear") == 0)
	{
		clear_data();
		JCG("clear");
		ret = 0;
		goto RET_SUCC;
	}

	#ifdef MAC_WRITER_SUPPORT
	else if(strncasecmp(argv[1],"mac",sizeof("mac")) == 0)
	{
		ret = main_mac(argc,argv);
		JCG(" MAC Writer!!");
		goto RET_SUCC;
	}
	#endif

	else if(strcasecmp(argv[1],"read") == 0)
	{
#if 0
		char str_store[2048];

		char cmd_buf[256];
		char data_buf[256];

		memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
		memset(data_buf      , 0x0 , sizeof(data_buf));

		/* read data from flash*/
		read_data(NULL, str_store);
		JCG("get read data:%s\n",str_store);
#else
		char get_read_data[2048];
		/* read data from flash*/
		read_file_from_mmc();
		#ifdef ENABLE_STRUCT
		card_data = (CARD_INFO*) malloc(sizeof(CARD_INFO));
		read_data(card_data, NULL);
		card_tmp = card_data->next;
		print_card_info(card_data);
		free(card_data);
		#else	//not ENABLE_STRUCT
		memset(get_read_data,0x0,sizeof(get_read_data));
		read_data(NULL, get_read_data);
		JCG("get data -->\n%s\n",get_read_data);
		#endif
#endif
 		JCG("read");
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"del",3) == 0)
	{
		/* read data from flash*/
		delete_data(argv[1], NULL);
 		JCG("delete");
		ret = 0;
		write_file_to_mmc();
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"search",strlen("search")) == 0)
	{
		search_data(NULL);
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"mmcread",strlen("mmcread")) == 0)
	{
		read_file_from_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"mmcwrite",strlen("mmcwrite")) == 0)
	{
		write_file_to_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"rmda",strlen("rmda")) == 0)
	{
		delete_data_file();
		ret = 0;
		goto RET_SUCC;
	}

	JCG("-------- format: ./mac_writer YHK-000000123455 ---------------------------");
	write_data(argv[1], NULL);
	JCG("-----------------------------------");
	ret = 0;
	write_file_to_mmc();
	goto RET_SUCC;

RET_SUCC:
#ifdef DEBUG_IN_ANDROID
	property_set("persist.sys.mac_writer.proc" ,"done");
#else
#endif
	destroye_env();

	return ret;
RET_ERR:
	destroye_env();
	return ret;

}
예제 #14
0
int read_data(CARD_INFO *card_data , char* str_get)
{
	int fd;
	char buf[sizeof(char)+1];
	char str_store[2048];
	int read_flag = 0;
	int i0, i1;
	char *str_sn;
	int fd1;
	char str_slip[] = "-\n";
	//CARD_INFO *card_get[MAX_CARD_NUMBER];
	char cmd_buf[128];
	char get_str_store[2048];

	memset(str_store     , 0x0 , sizeof(str_store));
	memset(buf           , 0x0 , sizeof(buf));
	memset(get_str_store , 0x0 , sizeof(get_str_store));


#if 0
	/*get data from mmc*/
	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s",SOURCE_DATA_PATH , DATA_PATH, CMD_ARGS);
	system(cmd_buf);		//system("dd if=/dev/block/mmcblk1 of=/sdcard/sn.dat skip=5200 bs=512 count=5");
	JCG("cmd-->%s",cmd_buf);

	sync();
#endif
	memset(cmd_buf,0x0, sizeof(cmd_buf));
	sprintf(cmd_buf,"%s", DATA_PATH);
	fd = open(DATA_PATH,O_RDWR);
	if(fd < 0)
	{
		return -1;
		JCG("read file error");
	}

#ifdef USE_OPENSSL_RSA_ENCRYPT
	decrypt_read_data(get_str_store);
#else
	while((read_flag = read(fd,buf,sizeof(char))) > 0)
	{
		sprintf(str_store,"%s%s",str_store,buf);
	}
#endif

	sprintf(str_store,"%s",get_str_store);
	JCG("read data is:-->\n%s\n<--\n",str_store);
	if(str_get != NULL)
		sprintf(str_get,"%s",str_store);

	if(strlen(str_store) == 0)
		return 0;

#ifdef ENABLE_STRUCT
	if(card_data != NULL)
	{
		i0 = 0;
		str_sn = strtok(str_store,str_slip);
		i1 = 0;
		while(str_sn != NULL)
		{
			if(str_sn == NULL)
				break;
			//JCG("get: %s",str_sn);
			if(i0%2 == 0)
			{
				JCG("i0:%d--i1:%d--name:%s,ADDR-->0x%x<--",i0,i1,str_sn,card_get[i1]->name);
				if(strlen(str_sn) <= 8)
				{
					sprintf(card_get[i1]->name,"%s",str_sn);
				}
				else
				{
					JCG("data format error!");
					goto CONT;
				}
			}
			else
			{
				if( strlen(card_get[i1]->name) <= 0 )
					goto CONT;
				//JCG("get number: %s",str_sn);
				if(strlen(str_sn) < 32)
				{
					strcpy(card_get[i1]->number,str_sn);
				}
				else
				{
					JCG("data format error!");
					goto CONT;
				}
				i1++;
			}

CONT:
			/*if(i0 != 0)*/
			str_sn = strtok(NULL,str_slip);
			if(str_sn == NULL)
				break;
			i0++;
			continue;
		}

	i0 =0;
	while(i0 < i1)
	{
		if(i0 == i1 - 1)
			card_get[i0]->next = NULL;
		else
			card_get[i0]->next = card_get[i0+1];
		/*JCG("card_get: %s --> %s.",card_get[i0]->name,card_get[i0]->number);*/
		i0++;
	}

		memcpy(card_data, card_get[0], sizeof(CARD_INFO));
		#if 1
		i0 =0;
		while(i0 < i1)
		{
			JCG("%04d 0x%x 0x%x 0x%x %d",i0,card_get[i0], (card_get[i0]->name),(card_get[i0]->number),__LINE__);
			i0++;
		}
		#endif
		#if 1
		i0 =0;
		//while(i0 < i1)
		{
			JCG("--------------------------------------------------------");
			JCG("%04d 0x%x 0x%x 0x%x %d",__LINE__,card_data, &(card_data->name),&(card_data->number),__LINE__);
			JCG("%04d 0x%x 0x%x 0x%x %d",__LINE__,card_data->next, &(card_data->next->name),&(card_data->next->number),__LINE__);
			//JCG("%04d 0x%x 0x%x 0x%x %d",__LINE__,card_data->next->next, &(card_data->next->next->name),&(card_data->next->next->number),__LINE__);
			JCG("--------------------------------------------------------");
		}
		#endif
	}
#else		//ENABLE_STRUCT
#endif		//ENABLE_STRUCT

	close(fd);
	memset(cmd_buf,0x0,sizeof(cmd_buf));
	sprintf(cmd_buf, "%s %s %s", CMD_PREFIX, "chmod 666 " , DATA_PATH);
	system(cmd_buf);		/*system("/system/xbin/busybox chmod 666 /sdcard/sn.dat ");*/
	return 0;
}
예제 #15
0
파일: tve.c 프로젝트: alessandroste/testBSP
static ssize_t tve_test_store(struct device *pdev, struct device_attribute *attr,const char *buff, size_t size)
{
	JCG();
	ns115_tve_hot_disconnect();
}
예제 #16
0
int write_data(char *argv, char* str)
{
	char str_to_write[2048];
	int i0 = 0;
	int  fd_read;
	int  fd;
	int  ret;

	char empty_str[11] = "-";
	char sn_header[16];
	char serial_number[SN_MAX_LEN];
	char *str_sn;
	char str_slip[] = "-";
	char arg_val[8][64];
	char *str_read;

	int fd0;
	char buf[sizeof(char)+1];
	char str_store[2048];
	int read_flag = 0;

	char cmd_buf[256];
	char data_buf[256];

	memset(str_to_write  , 0x0 , sizeof(str_to_write));
	memset(sn_header     , 0x0 , sizeof(sn_header));
	memset(serial_number , 0x0 , sizeof(serial_number));
	memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
	memset(data_buf      , 0x0 , sizeof(data_buf));

	/* read data from flash*/
	read_data(NULL, str_store);
	JCG("get read data:%s\n",str_store);

	/* get args */
	while( i0 < (sizeof(arg_val)/sizeof(arg_val[0])))
	{
		memset(arg_val[i0], 0, sizeof(arg_val[0]));
		i0++;
	}

	JCG();
	/* get arguments */
	i0 = 0;
	sprintf(data_buf,"%s",argv);
	str_sn = strtok(data_buf,str_slip);
	while(str_sn != NULL)
	{
		if(i0 != 0)
			str_sn = strtok(NULL,str_slip);
		if(str_sn == NULL)
			break;
		sprintf(arg_val[i0], "%s", str_sn);

		JCG("arg_val[%d]:%s.\n",i0,arg_val[i0]);
		i0++;
		if(i0 > (sizeof(arg_val)/sizeof(arg_val[0])))
			break;
	}


	i0 = 0;
	while( i0 < (sizeof(arg_val)/sizeof(arg_val[0])) )
	{
		if((strncasecmp(arg_val[i0],"YCT", 3) == 0 || strncasecmp(arg_val[i0],"YHK", 3) == 0 ) \
				&& i0 < (sizeof(arg_val)/sizeof(arg_val[0]) -1) )
		{
			JCG("arg_val[%d]:%s,arg[%d]:%s",i0,arg_val[i0], i0,arg_val[i0+1]);
			//get sn by argument
			strcpy(serial_number, arg_val[i0+1]);

			/* Setup serial number */
			if(strlen(serial_number) != 0)
			{
				sprintf(sn_header,"%s",arg_val[i0]);
				JCG("serial number is: %s",serial_number);
				ret = strip_sn_str(serial_number);
				if(ret < 0)
				{
					ret = -1;
					goto MAC_ERROR;
				}
				ret = check_dec(serial_number);
				if(ret < 0)
				{
					ret = -1;
					goto MAC_ERROR;
				}
			}
			else
			{
				JCG("serial number is wrong!");
				ret = -1;
				goto MAC_ERROR;
			}

			sprintf(str_to_write, "%s%s%s%s\n", str_to_write , \
				sn_header,empty_str,serial_number);
		}
		i0++;
	}

#if 0
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s %s",CMD_PREFIX, "rm -rf ", DATA_PATH);
	system(cmd_buf);		/*system("rm -f dsn.dat ");*/
#endif

	fd = open(DATA_PATH ,O_RDWR | O_CREAT | O_APPEND ,0666);

	if(fd < 0)
	{
		JCG("Error in open files!");
		return -1;
	}

	JCG("read data : \n%s\n", str_store );
	JCG("str_to_write: \n%s\n", str_to_write );
	sprintf(str_store,"%s%s",str_store, str_to_write);
#ifdef USE_OPENSSL_RSA_ENCRYPT
	close(fd);
	//encrypt_write_data(str_store,0);
	encrypt_write_data(str_to_write,1);
#else
	write(fd,str_store,strlen(str_store));
	close(fd);
#endif
	/*JCG("strlen of str to write is :%d",strlen(str_to_write));*/

#if 0
	/* write to flash */
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s",DATA_PATH,SOURCE_DATA_PATH,CMD_ARGS_WRITE);
	system(cmd_buf);		/*system("dd if=/sdcard/sn.dat of=/dev/block/mmcblk1 seek=5200 bs=512");*/
	JCG("cmd-->%s",cmd_buf);
	sync();
#endif

	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s",CMD_PREFIX, "echo SUCESS!");
	system(cmd_buf);		/*system("/system/xbin/busybox echo SUCESS!");*/

	sync();
	return 0;
MAC_ERROR:
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s",CMD_PREFIX, "echo ERROR!");
	system(cmd_buf);		/*system("echo ERROR!");*/
	LOGE("str format error!");
	return -1;
}
예제 #17
0
파일: tve.c 프로젝트: alessandroste/testBSP
static ssize_t tve_test_show(struct device *pdev, struct device_attribute *attr, char *buf)
{
	JCG();
	ns115_tve_hot_connect();
}
예제 #18
0
int Net_Server_Basic()
{
	int	m_sock_fd;
	int	m_new_fd;
	struct sockaddr_in	m_serv_addr;
	struct sockaddr_in	m_sent_addr;
	int	m_sin_size;
	char	m_buf[BUFFER_SIZE];
	int	m_num_bytes;

//build TCP Socket		//IPv4 TCP
	if((m_sock_fd =socket(AF_INET,SOCK_STREAM,0))==-1)
	{
		perror("socket");
		exit(1);
	}

	//init and listen port 2323	//IPv4 port 2323 
	m_serv_addr.sin_family		= AF_INET;
	m_serv_addr.sin_port		= htons(2323);
	m_serv_addr.sin_addr.s_addr	= INADDR_ANY;

	bzero(&(m_serv_addr.sin_zero),8);

	//绑定socket
	if(bind
		(m_sock_fd,(struct sockaddr *)&m_serv_addr,sizeof(struct sockaddr)) 
		== -1)
	{
		perror("bind");
		exit(1);
	}

	//创建监听socket
	if(listen(m_sock_fd,10)==-1)
	{
		perror("listen");
		exit(1);
	}

	//wait to connect
	while(1)
	{
		//memset(m_buf,0x0,sizeof(m_buf));
		m_sin_size = sizeof(struct sockaddr_in);
		//perror("server is run");
		//if connect sucessed, it will create a new socket
		if((m_new_fd = accept(m_sock_fd,(struct sockaddr*)&m_sent_addr,(socklen_t*)&m_sin_size)) == -1)
		{
			perror("acess");
			exit (1);
		}

		//fork a child process to complete connect to client
		if(fork() ==0)
		{
			//READ client message
			//printf("buffer: %s , len: %d. [%s:%d] \n",m_buf, m_num_bytes,__FILE__,__LINE__);
			if((m_num_bytes = recv(m_new_fd,m_buf, sizeof(m_buf),0)) ==-1)
			{
				perror("fork recv");
				exit(1);
			}
			JCG("Server recv: %s , len: %d.",m_buf, m_num_bytes);
			if(strcmp(m_buf,"QUIT")==0)
			{
				close(m_new_fd);
				break;
			}

			//then sent back to client
			if(send(m_new_fd,m_buf,strlen(m_buf)+1 ,0) == -1)
			{
				perror("fork send");
			}
			close(m_new_fd);
			JCG("Server sent: %s , len: %d.",m_buf, strlen(m_buf) + 1);
			exit(0);
		}
		close(m_new_fd);
	}
	close(m_sock_fd);


}
예제 #19
0
int Net_Client_Basic(char* m_str)
{
	int	m_sock_fd;
	int	m_num_bytes;
	char	m_buf[BUFFER_SIZE];
	struct	hostent *m_rec;
	struct	sockaddr_in	m_rec_addr;
	int	m_i;
	char	m_sent_buf[BUFFER_SIZE];
	
//	if(m_str != NULL)
	
//	m_rec = gethostbyname("192.168.48.2");
	m_rec = gethostbyname("127.0.0.1");
	if((m_sock_fd = socket(AF_INET,SOCK_STREAM,0)) == -1)
	{
		perror("socket");
		exit(1);
	}

	// init struct
	m_rec_addr.sin_family	= AF_INET;
	m_rec_addr.sin_port	= htons(2323);
	m_rec_addr.sin_addr	= *((struct in_addr *)m_rec->h_addr);

	bzero(&(m_rec_addr.sin_zero),8);

	//connect to server
	if(connect(m_sock_fd,(struct sockaddr *)&m_rec_addr,sizeof(struct sockaddr)) == -1)
	{
		perror("connect");
		exit(1);
	}


	if(m_str != NULL)
	{
		sprintf(m_sent_buf,"%s",m_str,__FILE__,__LINE__);
	}
	else
	{
		sprintf(m_sent_buf,"Sent_buffer[%s:%d]",__FILE__,__LINE__);
	}

	if(send(m_sock_fd, m_sent_buf, strlen(m_sent_buf)+1, 0) == -1)
	{
		perror("send");
		exit(1);
	}
	JCG("Client sent: %s , len: %d.", m_sent_buf, strlen(m_sent_buf)+1);

	if((m_num_bytes = recv(m_sock_fd,m_buf,BUFFER_SIZE,0))==-1)
	{
		perror("recv");
		exit(-1);
	}
	m_buf[m_num_bytes]='\0';
	JCG("Client recv: %s , len: %d", m_buf, m_num_bytes);

	return 0;

}
예제 #20
0
void get_vpn_info()
{
#if 0
	int	m_sock_fd;
	int	m_num_bytes;
	char	m_buf[BUFFER_SIZE];
	struct	hostent *m_rec;
	struct	sockaddr_in	m_rec_addr;
	int	m_i;
	char	m_sent_buf[BUFFER_SIZE];
	
//	if(m_str != NULL)
	
//	m_rec = gethostbyname("192.168.48.2");
	m_rec = gethostbyname("218.251.112.191");
	if((m_sock_fd = socket(AF_INET,SOCK_STREAM,0)) == -1)
	{
		perror("socket");
		exit(1);
	}

	// init struct
	m_rec_addr.sin_family	= AF_INET;
	m_rec_addr.sin_port	= htons(2012);
	m_rec_addr.sin_addr	= *((struct in_addr *)m_rec->h_addr);

	bzero(&(m_rec_addr.sin_zero),8);

	//connect to server
	if(connect(m_sock_fd,(struct sockaddr *)&m_rec_addr,sizeof(struct sockaddr)) == -1)
	{
		perror("connect");
		exit(1);
	}


	//if(m_str != NULL)
	//{
		//sprintf(m_sent_buf,"%s",m_str);
	//}
	//else
	{
		sprintf(m_sent_buf,">>>>>Hello!<<<<<");
	}

	if(send(m_sock_fd,m_sent_buf,strlen(m_sent_buf)+1,0) == -1)
	{
		perror("send");
		exit(1);
	}
	JCG("Server sent: %s , len: %d.", m_sent_buf, strlen(m_sent_buf)+1);

	if((m_num_bytes = recv(m_sock_fd,m_buf,BUFFER_SIZE,0))==-1)
	{
		perror("recv");
		exit(-1);
	}
	m_buf[m_num_bytes]='\0';
	JCG("Server recv: %s , len: %d.", m_buf, m_num_bytes);

#endif
	return;

}
예제 #21
0
int delete_data(char *argv, char* str)
{
	char str_to_write[1024];
	int i0 = 0;
	int  fd_read;
	int  fd;
	int  ret;

	char sn_header[16];
	char serial_name[SN_MAX_LEN];
	char serial_number[SN_MAX_LEN];
	char *str_sn;
	char str_slip[] = "-";
	char arg_val[8][64];
	CARD_INFO *card;
	CARD_INFO *card_tmp;
	char *str_read;

	int fd0;
	char buf[sizeof(char)+1];
	char str_store[2048];
	int read_flag = 0;

	char cmd_buf[256];
	char data_buf[256];

	char *str_search; //[2048];
	char str_tmp[2048];
	char arg_full[256];
	char arg_full_non[256];
	int st_len;
	int sr_len;

	memset(str_to_write  , 0x0 , sizeof(str_to_write));
	memset(sn_header     , 0x0 , sizeof(sn_header));
	memset(serial_name   , 0x0 , sizeof(serial_name));
	memset(serial_number , 0x0 , sizeof(serial_number));
	memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
	memset(data_buf      , 0x0 , sizeof(data_buf));
	memset(str_tmp       , 0x0 , sizeof(str_tmp));
	memset(arg_full      , 0x0 , sizeof(arg_full));
	memset(arg_full_non  , 0x0 , sizeof(arg_full_non));

	card = (CARD_INFO*) malloc(sizeof(CARD_INFO));
	card_tmp = (CARD_INFO*) malloc(sizeof(CARD_INFO));


	fd = open(DATA_PATH ,O_RDWR | O_CREAT,0666);
	if(fd < 0)
	{
		JCG("Error in open files!");
		return -1;
	}


	/* get args */
	while( i0 < (sizeof(arg_val)/sizeof(arg_val[0])))
	{
		memset(arg_val[i0], 0, sizeof(arg_val[0]));
		i0++;
	}

	/* get arguments */
	i0 = 0;
	sprintf(data_buf,"%s",argv);
	str_sn = strtok(data_buf,str_slip);
	while(str_sn != NULL)
	{
		if(i0 != 0)
			str_sn = strtok(NULL,str_slip);
		if(str_sn == NULL)
			break;
		sprintf(arg_val[i0], "%s", str_sn);

		JCG("arg_val[%d]:%s.\n",i0,arg_val[i0]);
		i0++;
		if(i0 > (sizeof(arg_val)/sizeof(arg_val[0])))
			break;
	}


	i0 = 0;
	while( i0 < (sizeof(arg_val)/sizeof(arg_val[0])) )
	{
		if((strncasecmp(arg_val[i0],"DEL", 3) == 0 ) \
				&& i0 < (sizeof(arg_val)/sizeof(arg_val[0]) - 2) )
		{
			JCG("arg_val[%d]:%s,arg[%d]:%s,arg[%d]:%s",i0,arg_val[i0], i0+1 ,arg_val[i0+1],i0+2,arg_val[i0+2]);
			//get sn by argument
			strcpy(serial_name   , arg_val[i0+1]);
			strcpy(serial_number , arg_val[i0+2]);

			sprintf(arg_full,"%s-%s\n",arg_val[i0+1],arg_val[i0+2]);
			sprintf(arg_full_non,"%s-%s",arg_val[i0+1],arg_val[i0+2]);

			/* Setup serial number */
			if(strlen(serial_number) != 0)
			{
				JCG("serial number is: %s",serial_number);
				ret = strip_sn_str(serial_number);
				if(ret < 0)
				{
					ret = -1;
					goto MAC_ERROR;
				}
				ret = check_dec(serial_number);
				if(ret < 0)
				{
					ret = -1;
					goto MAC_ERROR;
				}
			}
			else
			{
				JCG("serial number is wrong! shoule be ./mac_writer del-YHK-012345");
				ret = -1;
				goto MAC_ERROR;
			}
		}
		i0++;
	}

	JCG("serial number is:%s",serial_number);

	read_data(card, str_store);
	JCG("get read data:\n%s\n",str_store);

	memset(str_to_write,0x0,sizeof(str_to_write));

#ifdef ENABLE_STRUCT
	i0 = 0;
	while(card->next != NULL)
	{
		JCG("get read struct data:%s --> %s. serial_number is--> %s\n",card->name,card->number,serial_number);
		if(strcmp(card->number, serial_number) == 0 && strcmp(card->name, serial_name) == 0)
		{
		}
		else
		{
			sprintf(str_to_write,"%s%s-%s\n",str_to_write,card->name,card->number);
		}

		card_tmp = card;
		//memcpy(card_tmp , card, sizeof(CARD_INFO));
		if(card_tmp->next != NULL)
		{
			JCG("address -->0x%08x 0x%08x",card,card_tmp->next);
			card = (CARD_INFO*)card_tmp->next;

			JCG("address -->0x%08x 0x%08x",card,card_tmp->next);
			if(card->name == NULL || card->number == NULL)
			{
				break;
			}
			else if((strncasecmp(card->name, "YCT", 3) != 0) && strncasecmp(card->name,"YHK",3) !=0 )//|| card->next == NULL)
			{
				card  = NULL;
				break;
			}
			else
			{
				JCG("get read struct data:%s --> %s. serial_number is--> %s\n",card->name,card->number,serial_number);
			}
		}
		else
		{
			break;
		}
	}
	if(card != NULL)
	{
		JCG("get read struct data:\n%s --> %s\n",card->name,card->number);
		if(strcmp(card->number, serial_number) != 0)
			sprintf(str_to_write,"%s%s-%s\n",str_to_write,card->name,card->number);
	}
	JCG("data:%s",str_to_write);

#else		//not ENABLE_STRUCT
	JCG("str_store -->\n%s",str_store);
	JCG("arg_full -->%s",arg_full);
	JCG("arg_full_non -->%s",arg_full_non);
	str_search = strcasestr(str_store,arg_full);
	if(str_search == NULL)			//if use \n fail then with no \n
	{
		JCG();
		str_search = strcasestr(str_store,arg_full);
		if(str_search == NULL)
			return -1;
	}

	JCG("str_search --> %s",str_search);
	sr_len = strlen(str_store);
	st_len = strlen(str_search);
	strncpy(str_tmp,str_store,sr_len - st_len);
	JCG("str_tmp --> %s",str_tmp);
	sprintf(str_to_write,"%s%s",str_tmp,str_search + strlen(arg_full));

	JCG("delete-->%s",arg_full);
	JCG("str_tmp-->%s",str_tmp);
	JCG("str to write --> %s, strlen is --> %d",str_to_write, strlen(str_to_write));

#endif
	if(strlen(str_to_write) != 0)
	{
#ifdef USE_OPENSSL_RSA_ENCRYPT
	encrypt_write_data(str_to_write,0);
#else
	write(fd,str_to_write,strlen(str_to_write));
#endif
	}
	else
	{
		memset(str_to_write,0x0,sizeof(str_to_write));
		write(fd,str_to_write,sizeof(str_to_write));
	}

	close(fd);
	/*JCG("strlen of str to write is :%d",strlen(str_to_write));*/

#if 0
	/* write to flash */
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"dd if=%s of=%s %s",DATA_PATH,SOURCE_DATA_PATH,CMD_ARGS_WRITE);
	system(cmd_buf);		/*system("dd if=/sdcard/sn.dat of=/dev/block/mmcblk1 seek=5200 bs=512");*/
	JCG("cmd-->%s",cmd_buf);
	sync();
#endif


	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s",CMD_PREFIX, "echo SUCESS!");
	system(cmd_buf);		/*system("/system/xbin/busybox echo SUCESS!");*/

	free(card_tmp);
	free(card);
	sync();
	return 0;
MAC_ERROR:
	memset(cmd_buf, 0x0 , sizeof(cmd_buf));
	sprintf(cmd_buf,"%s %s",CMD_PREFIX, "echo ERROR!");
	system(cmd_buf);		/*system("echo ERROR!");*/
	free(card_tmp);
	free(card);
	LOGE("str format error!");
	return -1;
}
예제 #22
0
void Decode_RSA(unsigned char *encData, int fd ,char *getData)
{
	RSA *r;
	BIGNUM *bne,*bnn,*bnd;
	int bits = 1024, ret, len, flen, padding, i;
	unsigned char *key, *p;
	BIO *b;
	/*unsigned char *encData;*/
	unsigned char *decData,*tmpData;//加密后的数据/解密后的数据/临时指针
       /* Key data */
	unsigned long e = 75011;  

	/* 构建RSA数据结构   */
	bne = BN_new();  
	bnd = BN_new();  
	bnn = BN_new();  
	ret = BN_set_word(bne, e);  
	BN_hex2bn(&bnd, PRIVATE);  
	BN_hex2bn(&bnn, MODULUS);  

	r = RSA_new();  
	r->e=bne;  
	r->d=bnd;  
	r->n=bnn;
	/* output key */
	/*RSA_print_fp(stdout, r, 5);*/

	flen =  RSA_size(r);// - 11;   
	/*encData =  (unsigned char *)malloc(flen);  */
	/*bzero(encData, flen);//memset(encData, 0, flen);   */

	//JCG("Begin RSA_private_decrypt \n");  
	if(ret < 0){
		JCG("Encrypt failed!\n");  
		return;  
	}  

#if 0
	tmpData=encData;
	for  (i=0; i<ret; i++)
	{
		JDG("0x%02x, ", *tmpData);
		if(i%16 == 7)
			JDG("\t");
		else if(i%16 == 15)
			JDG("\n");
		tmpData++;  
	}
	JDG("\n");
#endif


	flen =  RSA_size(r);// - 11;   
	decData =  (unsigned char *)malloc(flen);  
	bzero(decData, flen);//memset(encData, 0, flen);   

	ret =  RSA_public_decrypt(flen, encData, decData, r,  RSA_NO_PADDING);  
	if(ret < 0){  
		JCG("RSA_public_decrypt failed!");  
		return;
	}  

	sprintf(getData,"%s",decData);
	free(decData);  
	RSA_free(r);  

}