RE: Kernel module <-> user communication

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

 



I'm not writing a driver for a standard ethernet card; the card is used to communicate with other components in a closed system.  I hesitate to even call it a "network driver," but it's closer to that than to a char driver since it's interrupt driven.  To send data with it, what I'd really like to do is pass it a pointer and a length and the device itself will send the data at that location, so I don't even need to worry about forming packets.  Can I do this with ioctl, or would the char driver be more amenable?  There's no direct reading from or writing to the device, just writing to registers on it.

If I do use ioctl, how do I make socket connect to my driver, rather than, say, "eth0"?  Is that what ifname is for (where does this variable come from)?  Also, is AF_INET the correct domain for socket, or does it not matter since all I'm doing with that socket is calling ioctl?

-Steve

-----Original Message-----
From: Andrew Stanley-Jones [mailto:asj@cban.com] 
Sent: Friday, August 23, 2002 1:25 PM
To: steve_lustbader@hsgmed.com
Cc: felipewd@terra.com.br; kernelnewbies@nl.linux.org
Subject: RE: Kernel module <-> user communication


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