Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Apr 1996 22:32:43 -0600 (MDT)
From:      "G. Jeffrey Francis" <jfrancis@frii.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Device Driver ioctl() help
Message-ID:  <199604220432.WAA06308@deimos.frii.com>

next in thread | raw e-mail | index | archive | help
	I've written a device driver to talk to a JDR experimenter's
breadboard that works quite well, but now I want to add some more
functionality to the driver, and I'm running into problems
understanding BSD's ioctl() mechanism.  I'll use the joy.c driver as
an example of the problem I'm having.

	In /sys/i386/include/joystick.h is the following code:

... blah blah blah...
#define JOY_SETTIMEOUT    _IOW('J', 1, int)    /* set timeout */
... blah blah blah...

	In /sys/sys/ioccom.h is this code:

... blah blah blah...
#define	_IOC(inout,group,num,len) \
	(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
... blah blah blah...
#define	_IOW(g,n,t)	_IOC(IOC_IN,	(g), (n), sizeof(t))
... blah blah blah...

	Ok, it looks like the 'J' has something to do with a "group",
but what kind of group?  How is this value chosen and what does it do?
I can reliably open() my device, issue an ioctl(), and things happen
(as confirmed by printf() statements in the driver), but I'm not able
to actually pass any data to or from the driver's ioctl() function
from my user-level code (the probe(), attach(), read(), write(),
open(), and close() routines all work just dandy).

	In my user-level code, I can call `ioctl(fd,STUFF,0x69)'.  In
the driver, the `case STUFF:' code in the `switch(cmd)' statement gets
executed (usually, but why not always?), but I can't get at the value
passed (0x69 in this case).  Obviously I'm missing something, but none
of the kernel books I have tell me what, and I can't seem to sort it
out.  I'd be happy to post actual code fragments if it would help.

+---------+------------------------------+--------------------------+---------+
|         |         Jeff Francis         |                          |         |
|   (__)  |      Network Specialist      |  We are smart.           |   (__)  |
|  /( oo  |     Paranet - Denver, CO     |                          |  /( oo  |
|   /\_|  |    jfrancis@mail.frii.com    |  We make things go.      |   /\_|  |
|         | Powered by FreeBSD & Mtn Dew |                          |         |
+---------+------------------------------+--------------------------+---------+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604220432.WAA06308>