How do IOCTL calls get dispatched?

eaosfu

New Member

Reaction score: 1
Messages: 17

I've been trying to wrap my head around how the wpa_supplicant interacts with the 80211 stack.

One of the things I see in the wpa_supplicant code are calls to ioctls like:

Code:
ioctl(drv->global->sock, SIOCGIFMEDIA, &ifmr)

Here global->sock is assigned by simply doing a:

Code:
 global->sock = socket(PF_INET, SOCK_DGRAM, 0);

Additionally, the ioctl call seems to land in net80211/ieee80211_ioctl.c in a function called ieee80211_ioctl.

What I can't figure out is how do we go from the ioctl() call and end up in ieee80211_ioctl().

My hunch is that there is either some dispatch code that does a table lookup somewhere and then jumps to the appropriate function, or there's a linker set somewhere that somehow allows the ioctl call to directly land where it needs to (wild guess).

I'd be really interested in learning how this mechanism works, so any links to documentation or perhaps source files I should be looking at would be greatly welcomed.

Thank you.
 

mark_j

Daemon

Reaction score: 705
Messages: 1,229

I've been trying to wrap my head around how the wpa_supplicant interacts with the 80211 stack.

One of the things I see in the wpa_supplicant code are calls to ioctls like:

Code:
ioctl(drv->global->sock, SIOCGIFMEDIA, &ifmr)

Here global->sock is assigned by simply doing a:

Code:
 global->sock = socket(PF_INET, SOCK_DGRAM, 0);

Additionally, the ioctl call seems to land in net80211/ieee80211_ioctl.c in a function called ieee80211_ioctl.

What I can't figure out is how do we go from the ioctl() call and end up in ieee80211_ioctl().

My hunch is that there is either some dispatch code that does a table lookup somewhere and then jumps to the appropriate function, or there's a linker set somewhere that somehow allows the ioctl call to directly land where it needs to (wild guess).

I'd be really interested in learning how this mechanism works, so any links to documentation or perhaps source files I should be looking at would be greatly welcomed.

Thank you.

I'm not entirely sure: a) what you mean, and b) what you're looking for the answer to?

Anyway, simply IOCTLs are attached to the drivers. They define their own ioctl.
If you look in <sys/conf.h> you'll find cdevsw struct, in it you'll see the read/write/close/open etc and the ioctl which is for everything else, basically.
So the ioctl will do something like set the mode of the wifi (in your example situation). This will be done by the writers of the device driver.

The ones you've listed here are the system IOCTLS, in particular the Socket I/O ones prefixed with SIO. These are "mandated" by POSIX.

If you're interested in how drivers work, especially in FreeBSD, then try to find "Device Drivers - A Guide for the intrepid" by Joseph Kong.
Source code is good. It's available for easy browsing on github.
 

George

Aspiring Daemon

Reaction score: 204
Messages: 510

Probably there is a DEVMETHOD for that ioctl somewhere.
 
Top