RE: Kernel module <-> user communication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 23 Aug 2002 steve_lustbader@hsgmed.com wrote:

> I'd like to tie the user and kernel parts together more tightly than
> using ioctls if possible.  If I have to use ioctl, though, I will.
> How do I get a file descriptor to my device?  It's a network driver,
> not a char driver, so there's no /dev/foo entry.


You can of course always create a character interface for control.  I
wrote a network driver a few years ago that needed very intensive setup
(and contunious maintenace) of an on board dsp.  The DSP wasn't timming
critical per say, just needed someone to maintain the state machine all
the time. I didn't want to do this in the kernel so I had the network
driver sending and receiving packets normally, and a character device
sending communicating with the dsp.  I send something like:

struct command_pkt {

u8 command;
u8 reg;
u8 value;
etc
};

back and forth over the /dev/char device.  It got pretty fancy with the
ability to forward interrupt events to userland via the char interface.

ioctl's didn't work for me since it locked parts of the kernel if I had to
sleep_on_interruptable().

Anyways, to answer your question about how to get the file descriptor.
Here's a snibbit I used to use:

	ifname="hdlc0";
	fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (fd < 0) {
		fprintf(stderr, "socket: %s\n", strerror(errno));
		exit(1);
	}

	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	ifr.ifr_data = (caddr_t)&ctl;

	ioctl(fd, LMCIOCGINFO, &ifr);

I'm not sure about the SOCK_DGRAM, or if it even matters.  *shrug*  It
works and the rest is left as an excersize for the reader. ;)

-Andrew

---
Andrew Stanley-Jones         | "It's kind of fun to do the impossible."
EE, LongEz N87KJ             |                           -- Walt Disney


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux