Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

define my own IOCTL numbers for a network device

103 views
Skip to first unread message

InuY4sha

unread,
Sep 3, 2008, 4:41:23 AM9/3/08
to
Hi all,
I'm writing a driver module for a wireless interface (under linux).
The module is currently able to process the ioctls coming from
wireless tools (such as changing ESSID or freq etc...
I see that iwtools offer a set of "private" IOCTL numbers for driver
specific purposes (SIOCIWFIRSTPRIV).

What I don't understand is HOW to define my own *additional* ioctl
numbers and using them from the userspace.

I've been trying something like this in the kernel module:
#define IOCTL_APP_TYPE 'k'
#define USER_APP_IOCTL _IOWR(IOCTL_APP_TYPE,0, struct iwreq *)
but I have no clues about what that 'k' means.
Moreover, when using SIOCIWFIRSTPRIV+N (wit N witin 0 and 32), as the
ioctl number, everything works fine, while when using my own
"USER_APP_IOCTL" the driver ioctl handler is not triggered and I get
-1 as ret value from ioctl(...).

I don't know if this is of any help to you, but the printk of
USER_APP_IOCTL gives me a negative number which smells fishy..

Consider I'm a newbie with regards to this topic so take it easy on
me :)
Thanks in advance,
RM

InuY4sha

unread,
Sep 3, 2008, 5:21:09 AM9/3/08
to
Some more remarkable information:
reading through wireless.h header file, I noticed that all the numbers
start wit 0x8B**
So I picked up one of the numbers left unused and tried with that
(outside the range of the SIOCIWFIRSTPRIV+N numers); in this case
everything works fine ...
I'm trying to understand from LDD user maunal.. but they don't make it
easy..

The steps I'm missing are
(1) where in wireless tools the "_IO" macros are used (if they are)
(2) where in wireless tools the 'k' is defined and how the association
with the kernel module is obtained.

Jens Thoms Toerring

unread,
Sep 3, 2008, 12:31:04 PM9/3/08
to

Did you read the file 'Documentation/ioctl_numbers.txt' in the
kernel sources? I guess that it should answer several of your
questions quite well. About the ioctl number: the thing called
here 'IOCTL_APP_TYPE' is a 1-byte value that becomes, together
with the second argument of the _IO(R|W) macro part of the ioctl
number. One way to pick something is to use the major device
number for this, the other to pick one from the file in the
documentation listed as not yet used. But in your case it
certainly makes sense to stay with the one that already is
used, in this case 'k' and just use something not used yet just
for the second number (by the way, you should start with N set
to 1 and not 0 for the new ioctls you're adding, otherwise you
would redefine the one or SIOCIWFIRSTPRIV (given that this is
the last already used)).

You put the defines for these numbers into a header file that
gets included when you build your module, but that also
gets included by user-space programs that want to call these
ioctls. Then everything should work out fine.

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de

0 new messages