简介:本文是在上文的基础上,介绍下无线扩展socekt控制ioctl的实例。
文章基础:
WIFI设备管理工具iwconfig/iwpriv及对应内核态的实现机制
一、ioctl的cmd
(注意理解其中的地址大小包含关系)
-
#define SIOCDEVPRIVATE 0x89F0//①老的无线私有ioctl:最初的iwpriv实现使用的ioctl号范围由SIOCDEVPRIVATE确定[#define SIOCDEVPRIVATE 0x89F0 /* to 89FF */];但这些ioctl被其它功能占用,支持功能有限。
-
-
#define SIOCIWFIRST 0x8B00//④新的无线标准ioctl。
-
-
#define SIOCGIWPRIV 0x8B0D//③用户可以使用SIOCGIWPRIV(#define SIOCGIWPRIV 0x8B0D)来获取私有ioctl的描述信息。
-
-
-
#define SIOCIWFIRSTPRIV 0x8BE0//②新的无线私有ioctl:新ioctl范围由SIOCIWFIRSTPRIV确定;这些ioctl是特定为无线扩展使用,不用担心与其它功能冲突;SIOCIWFIRSTPRIV支持私有ioctl号为32个。
-
-
#define SIOCIWLASTPRIV 0x8BFF
-
-
-
#define SIOCIWLAST SIOCIWLASTPRIV 0x8BFF
注释:无线扩展(Wireless Extensions)就是新的无线标准ioctl+新的无线私有ioctl。
二、ioctl的cmd调用实例(有空在排版,我直接上传我排版好的txt)
-
//Old driver API
-
wlanconfig ath4 list sta IEEE80211_IOCTL_STA_INFO -> case IEEE80211_IOCTL_STA_INFO -> ieee80211_ioctl() -> ndo_do_ioctl = ieee80211_ioctl() -> dev->netdev_ops->ndo_do_ioctl
-
//无线标准ioctl用户态工具对应iwconfig
-
iwconfig ath16 txpower 15 SIOCSIWTXPOW(注意区别于SIOCSIWPOWER)(无) -> 无 -> static const iw_handler ieee80211_handlers[] = {...(iw_handler) ieee80211_ioctl_siwtxpow, /* SIOCSIWTXPOW */...} -> dev->wireless_handlers = &ieee80211_iw_handler_def -> dev->wireless_handlers
-
//无线私有ioctl用户态工具对应iwpriv
-
iwpriv wifi0 get_country ATH_IOCTL_GETCOUNTRY(static const struct iw_priv_args ol_ath_iw_priv_args[] = {...ATH_IOCTL_GETCOUNTRY...}) -> case ATH_IOCTL_GETCOUNTRY -> static const iw_handler ol_ath_iw_priv_handlers[] = {...(iw_handler) ol_ath_iw_setcountry, /* SIOCWFIRSTPRIV+2 */...} -> dev->wireless_handlers = &ol_ath_iw_handler_def -> dev->wireless_handlers
-
iwpriv wifi0 sync_sta OL_ATH_PARAM_SYNC_STA(static const struct iw_priv_args ol_ath_iw_priv_args[] = {...OL_ATH_PARAM_SYNC_STA...}) -> case OL_ATH_PARAM_SYNC_STA -> static const iw_handler ol_ath_iw_priv_handlers[] = {...(iw_handler) ol_ath_iw_getparam, /* SIOCWFIRSTPRIV+1 */...} ->在其case中处理 -> dev->wireless_handlers = &ol_ath_iw_handler_def -> dev->wireless_handlers
-
iwpriv ath0 get_mode IEEE80211_IOCTL_GETMODE(static const struct ieee80211_priv_args[] = {...IEEE80211_IOCTL_GETMODE...}) -> case IEEE80211_IOCTL_GETMODE -> static const iw_handler ieee80211_priv_handlers[] = {...(iw_handler) ieee80211_ioctl_getmode, /* SIOCWFIRSTPRIV+17 */...} -> dev->wireless_handlers = &ieee80211_iw_handler_def -> dev->wireless_handlers
-
iwpriv ath0 get_sta_count IEEE80211_PARAM_STA_COUNT(static const struct ieee80211_priv_args[] = {...IEEE80211_PARAM_STA_COUNT...}) -> case IEEE80211_PARAM_STA_COUNT -> static const iw_handler ieee80211_priv_handlers[] = {...(iw_handler) ieee80211_ioctl_getparam, /* SIOCWFIRSTPRIV+1 */...} ->在其case中处理 -> dev->wireless_handlers = &ieee80211_iw_handler_def -> dev->wireless_handlers
-
-
另外,我们研究下iwpriv工具。在iwpriv中,就巧妙利用了SIOCGIWPRIV来玩转所有私有cmd:
-
iwpriv/iwpriv ath0 -> print_priv_info -> iw_get_priv_info
-
iwpriv -a/iwpriv ath0 -a -> print_priv_all -> iw_get_priv_info
-
iwpriv ath0 getmode -> set_private -> iw_get_priv_info//即调用iwlib.c中的iw_get_priv_info中通过ioctl(SIOCGIWPRIV)获取到私有信息,其次调用set_private_cmd中匹配到私有cmd并ioctl(私有cmd)。 -> if (cmd == SIOCGIWPRIV && dev->wireless_handlers)//获取私有ioctl的描述信息
example.txt
阅读(4423) | 评论(0) | 转发(0) |