小公司研发总监,既当司令也当兵!
分类: linux
2016-04-15 08:36:33
sock_ioctl:./net/socket.c, 以file_operations注册在socket的文件结构中,接收应用层通过ioctl下放的命令
|---dev_ioctl: ./net/core/dev.c, 接收上层用户空间下发给内核网络模块的命令。
|---wext_handle_ioctl: 处理的命令范围为:(cmd >= siociwfirst && cmd <= siociwlast, siociwfirst=0x8b00 siociwlast = 0x8bff) 最多255个命令。主要有四种处理方法:定义在:linux\kernels\mips-linux-2.6.31\include\linux\wireless.h.
|---wext_ioctl_dispatch : 根据cmd分发,主要有两个回调函数ioctl_standard_call,ioctl_private_call
|---wireless_process_ioctl,
|---get_handler,通过命令字查找记录在设备wireless_handlers字段中的注册handle
|---ioctl_standard_call, 处理标准的无线ioctl命令(0x8b00-0x8bdf)
|---&(standard_ioctl[cmd - siociwfirst]),获取无线扩展的ioctl描述符(如果添加新的“标准”ioctl命令,需要同步增加该描述符映射,否则无法下传)
|---[handle](), 回调无线驱动为该命令绑定的处理函数
|---ioctl_private_call,处理无线设备私有的ioctl(0x8be0-0x8bff)
|---get_priv_descr_and_size, 检查是否有额外参数
|---ioctl_private_iw_point, 如果有额外参数,从用户空间复制数据到内核,调用handle回调
|---[handle](), 回到无线驱动为该命令绑定的处理函数
|---dev->netdev_ops->ndo_do_ioctl,如果没有获取的到注册的handle,则回调设备注册的ndo_do_ioctl(老驱动类型)
该函数是socket内核ioctl响应的入口函数,主要完成依据下发的ioctl命令类型进行分类处理:
(1) 如果下放的ioctl命令类型是设备私有类型,则交由设备驱动的ioctl处理(dev_ioctl);
(2) 如果系统支持无线设备扩展,并且下发的ioctl命令类型属于无线设备类型(0x8b00-0x8bff)则交由设备驱动的ioctl处理(dev_ioctl);
(3) 匹配标准的socket ioctl类型,如果匹配进行对应处理;
(4) 如果不匹配标准socket ioctl类型,尝试匹配socket注册的协议的ioctl类型并处理;
(5) 如果以上都不匹配,则尝试下发到设备驱动处理(dev_ioctl)。
该函数是设备层的ioctl响应入口函数,功能:
(1) 匹配下发的ioctl命令,进行通用命令匹配和处理;
(2) 如果是私有命令,则回调设备注册的私有ioctl响应函数(设备注册的ndo_do_ioctl);
(3) 如果是无线扩展的ioctl命令,交由wext_handle_ioctl处理。
wext_handle_ioctl主要是处理无线扩展设备的ioctl的,无线设备的ioctl命令字范围是0x8b00 – 0x8bff,共计255个操作类型;其中,0x8be0到0x8bff共32个操作类型为无线设备私有ioctl,由不同无线厂商自行定义。
wext_handle_ioctl处理下发的无线ioctl命令:
(1) 通过匹配设备的数据结构体中wireless_handlers字段(注册的ioctl handles),如果有匹配的handle,则交由对应的handle处理;
(2) 如果没有匹配的handle,则统一下发到无线设备的ndo_do_ioctl(初始化时注册处理函数)尝试处理。
网络设备通用ioctl命令字:
分类 |
命令字 |
命名数值 |
描述 |
备注 |
|
特别类型 |
siocinq |
fionread/0x514b |
|
|
|
siocoutq |
tiocoutq/0x5411 |
|
|
||
路由表管理 |
siocaddrt |
0x890b |
add routing table entry |
|
|
siocdelrt |
0x890c |
delete routing table entry |
|
||
siocrtmsg |
0x890d |
call to routing system |
|
||
socket配 |
siocgifname |
0x8910 |
get iface name |
|
|
siocsiflink |
0x8911 |
set iface channel |
|
||
siocgifconf |
0x8912 |
get iface list |
|
||
siocgifflags |
0x8913 |
get flags |
|
||
siocsifflags |
0x8914 |
set flags |
|
||
siocgifaddr |
0x8915 |
get pa address |
|
||
siocsifaddr |
0x8916 |
set pa address |
|
||
siocgifdstaddr |
0x8917 |
get remote pa address |
|
||
siocsifdstaddr |
0x8918 |
set remote pa address |
|
||
siocgifbrdaddr |
0x8919 |
get broadcast pa address |
|
||
siocsifbrdaddr |
0x891a |
set broadcast pa address |
|
||
siocgifnetmask |
0x891b |
get network pa mask |
|
||
siocsifnetmask |
0x891c |
set network pa mask |
|
||
siocgifmetric |
0x891d |
get metric |
|
||
siocsifmetric |
0x891e |
set metric |
|
||
siocgifmem |
0x891f |
get memory address (bsd) |
|
||
siocsifmem |
0x8920 |
set memory address (bsd) |
|
||
siocgifmtu |
0x8921 |
get mtu size |
|
||
siocsifmtu |
0x8922 |
set mtu size |
|
||
siocsifname |
0x8923 |
set interface name |
|
||
siocsifhwaddr |
0x8924 |
set hardware address |
|
||
siocgifencap |
0x8925 |
getencapsulations |
|
||
siocsifencap |
0x8926 |
|
|
||
siocgifhwaddr |
0x8927 |
get hardware address |
|
||
siocgifslave |
0x8929 |
driver slaving support |
|
||
siocsifslave |
0x8930 |
|
|
||
siocaddmulti |
0x8931 |
multicast address lists |
|
||
siocdelmulti |
0x8932 |
|
|
||
siocgifindex |
0x8933 |
name -> if_index mapping |
|
||
siogifindex |
siocgifindex/0x8933 |
misprint compatibility |
|
||
siocsifpflags |
0x8934 |
setextended flags set |
|
||
siocgifpflags |
0x8935 |
|
|
||
siocdifaddr |
0x8936 |
delete pa address |
|
||
siocsifhwbroadcast |
0x8937 |
set hardware broadcast addr |
|
||
siocgifcount |
0x8938 |
get number of devices |
|
||
siocgifbr |
0x8940 |
bridging support |
|
||
siocsifbr |
0x8941 |
set bridging options |
|
||
siocgiftxqlen |
0x8942 |
get the tx queue length |
|
||
siocsiftxqlen |
0x8943 |
set the tx queue length |
|
||
siocethtool |
0x8946 |
ethtool interface |
|
||
siocgmiiphy |
0x8947 |
get address of mii phy in use. |
|
||
siocgmiireg |
0x8948 |
read mii phy register. |
|
||
siocsmiireg |
0x8949 |
write mii phy register. |
|
||
siocwandev |
0x894a |
getnetdev parameters |
|
||
arp 缓存 |
siocdarp |
0x8953 |
delete arp table entry |
|
|
siocgarp |
0x8954 |
get arp table entry |
|
||
siocsarp |
0x8955 |
set arp table entry |
|
||
rarp缓存 |
siocdrarp |
0x8960 |
delete rarp table entry |
|
|
siocgrarp |
0x8961 |
get rarp table entry |
|
||
siocsrarp |
0x8962 |
set rarp table entry |
|
||
驱动配置 |
siocgifmap |
0x8970 |
get device parameters |
|
|
siocsifmap |
0x8971 |
set device parameters |
|
||
dlci配置 |
siocadddlci |
0x8980 |
create new dlci device |
|
|
siocdeldlci |
0x8981 |
delete dlci device |
|
||
siocgifvlan |
0x8982 |
802.1q vlan support |
|
||
siocsifvlan |
0x8983 |
set 802.1q vlan options |
|
||
网桥管理 |
siocbraddbr |
0x89a0 |
create new bridge device |
|
|
siocbrdelbr |
0x89a1 |
remove bridge device |
|
||
siocbraddif |
0x89a2 |
add interface to bridge |
|
||
siocbrdelif |
0x89a3 |
remove interface from bridge |
|
||
时间戳 |
siocshwtstamp |
0x89b0 |
hardware time stamping |
|
|
设备私有 |
siocdevprivate |
0x89f0 |
|
0x89f0 - 0x89ff |
|
协议私有 |
siocprotoprivate |
0x89e0 |
|
0x89e0 - 0x89ef |
|
无线扩展 |
|
|
|
见附表 iw-ioctls |
|
无线设备扩展ioctl命令字:
分类 |
命令字 |
命名数值 |
描述 |
标 |
siocsiwcommit |
0x8b00 |
commit pending changes to driver |
siocgiwname |
0x8b01 |
get name == wireless protocol |
|
siocsiwnwid |
0x8b02 |
set network id (pre-802.11) |
|
siocgiwnwid |
0x8b03 |
get network id (the cell) |
|
siocsiwfreq |
0x8b04 |
set channel(hz) |
|
siocgiwfreq |
0x8b05 |
get channel(hz) |
|
siocsiwmode |
0x8b06 |
set operation mode |
|
siocgiwmode |
0x8b07 |
get operation mode |
|
siocsiwsens |
0x8b08 |
set sensitivity (dbm) |
|
siocgiwsens |
0x8b09 |
get sensitivity (dbm) |
|
siocsiwrange |
0x8b0a |
unused |
|
siocgiwrange |
0x8b0b |
get range of parameters |
|
siocsiwpriv |
0x8b0c |
unused |
|
siocgiwpriv |
0x8b0d |
get private ioctl interface info |
|
siocsiwstats |
0x8b0e |
unused |
|
siocgiwstats |
0x8b0f |
get stats |
|
siocsiwspy |
0x8b10 |
set spy addresses |
|
siocgiwspy |
0x8b11 |
get spy info (quality of link) |
|
siocsiwthrspy |
0x8b12 |
set spy threshold (spy event) |
|
siocgiwthrspy |
0x8b13 |
get spy threshold |
|
siocsiwap |
0x8b14 |
set access point mac addresses |
|
siocgiwap |
0x8b15 |
get access point mac addresses |
|
siocgiwaplist |
0x8b17 |
deprecated in favor of scanning |
|
siocsiwscan |
0x8b18 |
trigger scanning (list cells) |
|
siocgiwscan |
0x8b19 |
get scanning results |
|
siocsiwessid |
0x8b1a |
set essid (network name) |
|
siocgiwessid |
0x8b1b |
get essid |
|
siocsiwnickn |
0x8b1c |
set node name |
|
siocgiwnickn |
0x8b1d |
get node name |
|
siocsiwrate |
0x8b20 |
set default bit rate (bps) |
|
siocgiwrate |
0x8b21 |
get default bit rate (bps) |
|
siocsiwrts |
0x8b22 |
set rtsthreshold (bytes) |
|
siocgiwrts |
0x8b23 |
get rtsthreshold (bytes) |
|
siocsiwfrag |
0x8b24 |
set fragmentation thr (bytes) |
|
siocgiwfrag |
0x8b25 |
get fragmentation thr (bytes) |
|
siocsiwtxpow |
0x8b26 |
set transmit power (dbm) |
|
siocgiwtxpow |
0x8b27 |
get transmit power (dbm) |
|
siocsiwretry |
0x8b28 |
set retry limits and lifetime |
|
siocgiwretry |
0x8b29 |
get retry limits and lifetime |
|
siocsiwencode |
0x8b2a |
set encoding token & mode |
|
siocgiwencode |
0x8b2b |
get encoding token & mode |
|
siocsiwpower |
0x8b2c |
set power management settings |
|
siocgiwpower |
0x8b2d |
get power management settings |
|
siocsiwgenie |
0x8b30 |
set generic ie |
|
siocgiwgenie |
0x8b31 |
get generic ie |
|
siocsiwmlme |
0x8b16 |
request mlme operation, uses struct iw_mlme |
|
siocsiwauth |
0x8b32 |
set authentication mode params |
|
siocgiwauth |
0x8b33 |
get authentication mode params |
|
siocsiwencodeext |
0x8b34 |
set encoding token & mode |
|
siocgiwencodeext |
0x8b35 |
get encoding token & mode |
|
siocsiwpmksa |
0x8b36 |
pmksa cache operation |
|
私有类型 |
siociwfirstpriv |
0x8be0 |
|
siociwlastpriv |
0x8bff |
|
atheros实现的部分私有ioctl命令:
siocg80211stats | (siocdevprivate 2) |
ieee80211_ioctl_getkey | (siocdevprivate 3) |
ieee80211_ioctl_getwpaie | (siocdevprivate 4) |
ieee80211_ioctl_sta_stats | (siocdevprivate 5) |
ieee80211_ioctl_sta_info | (siocdevprivate 6) |
sioc80211ifcreate | (siocdevprivate 7) |
sioc80211ifdestroy | (siocdevprivate 8) |
ieee80211_ioctl_scan_results | (siocdevprivate 9) |
ieee80211_ioctl_res_req | (siocdevprivate 10) |
ieee80211_ioctl_getmac | (siocdevprivate 11) |
ieee80211_ioctl_config_generic | (siocdevprivate 12) |
siocioctltx99 | (siocdevprivate 13) |
ieee80211_ioctl_p2p_big_param | (siocdevprivate 14) |
siocdevvendor | (siocdevprivate 15) |
ieee80211_ioctl_get_scan_space | (siocdevprivate 16) |