[ create a new paste ] login | about

Link: http://codepad.org/tkbUSE6r    [ raw code | fork ]

geekoutlaw - C, pasted on Oct 15:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>		/* open */
#include <unistd.h>
#include <stdarg.h>
#include <linux/ioctl.h>
#include <sys/types.h>		/* exit */
#include <sys/stat.h>
#include <sys/ioctl.h>	
#include <sys/mman.h>
#include <sys/poll.h>		/* ioctl */

#define DEVICE_FILE_NAME "/dev/lte"
#define BUFF_LEN 12288
#define MAJOR 100
#define MINOR 0
#define DATA_TO_KERNEL 1
#define DATA_TO_USER   2 
/* 
 * Main - Call the ioctl functions 
 */
int main()
{
	int fd, ret_val, count=0;
	struct pollfd ltepoll;
	int iPollret;
	char *msg ;
	char recv[1024];
	int i;

	fd = open(DEVICE_FILE_NAME,O_RDWR);

	printf("ret_val= %d ,fd =%d \n", ret_val,fd);

	if (0>fd)
	{
		perror("Cannot open device file:");
		exit(-1);
	}
printf("\n");

	ltepoll.fd = fd	;
	ltepoll.events = POLLIN | POLLHUP;


	msg = mmap(NULL, BUFF_LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x00000000 );
	printf("%d\t%d\t%x\t%x\t",BUFF_LEN,fd, MAP_SHARED, msg);
printf("\n");
#if 1
	for (i=0; i < BUFF_LEN; i++)
	{
		//*(msg+i)= i*i + 23;
		msg[i] = 0xAA; 
		printf("%d\t", msg[i]);
	}
printf("\n");
#endif
	printf("Send data to kernel\n");
	ioctl(fd,DATA_TO_KERNEL, 1);

	printf("Receive data from kernel\n");
	//ioctl(fd,DATA_TO_USER, 2);
	ioctl(fd,DATA_TO_KERNEL, 2);

#if 1
	while(1)
	{

		iPollret = poll(&ltepoll, 1,-1);

	printf("iPollRet= %d\n", iPollret);
	printf("ret =%d\n", ret_val);
	if( iPollret > 0 )
		{

			printf("Read data from kernel\n");
			for (i=0; i < BUFF_LEN; i++)
			{
				printf("%d\t", msg[i]);
			}
			printf("\n");

			count++;
			
	//ioctl(fd,DATA_TO_KERNEL, 1);
	//ioctl(fd,DATA_TO_KERNEL, 2);
			if(1 == count)
			break;		
		}
	}
#endif	
	close(fd);
	munmap(msg, BUFF_LEN);

	if (msg<0)
	perror("Unmapping Memory failed:");


return 0;
}


Create a new paste based on this one


Comments: