Chinaunix首页 | 论坛 | 博客
  • 博客访问: 678546
  • 博文数量: 141
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1114
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-17 14:32
个人简介

小公司研发总监,即当司令也当兵!

文章分类

全部博文(141)

分类: LINUX

2016-04-15 08:36:33

1.    调用关系和说明


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,处理无线设备私有的ioctl0x8BE0-0x8BFF

                                   |---get_priv_descr_and_size, 检查是否有额外参数

                                   |---ioctl_private_iw_point, 如果有额外参数,从用户空间复制数据到内核,调用handle回调

                                   |---[handle](), 回到无线驱动为该命令绑定的处理函数

                            |---dev->netdev_ops->ndo_do_ioctl,如果没有获取的到注册的handle,则回调设备注册的ndo_do_ioctl(老驱动类型)

1.1  sock_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)。

1.2  dev_ioctl

该函数是设备层的ioctl响应入口函数,功能:

(1)    匹配下发的ioctl命令,进行通用命令匹配和处理;

(2)    如果是私有命令,则回调设备注册的私有ioctl响应函数(设备注册的ndo_do_ioctl);

(3)    如果是无线扩展的ioctl命令,交由wext_handle_ioctl处理。

1.3  wext_handle_ioctl

wext_handle_ioctl主要是处理无线扩展设备的ioctl的,无线设备的ioctl命令字范围是0x8B00 – 0x8BFF,共计255个操作类型;其中,0x8BE00x8BFF32个操作类型为无线设备私有ioctl,由不同无线厂商自行定义。

wext_handle_ioctl处理下发的无线ioctl命令:

(1)    通过匹配设备的数据结构体中wireless_handlers字段(注册的ioctl handles),如果有匹配的handle,则交由对应的handle处理;

(2)    如果没有匹配的handle,则统一下发到无线设备的ndo_do_ioctl(初始化时注册处理函数)尝试处理。


2.    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)

阅读(3068) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~