iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_第1页
iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_第2页
iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_第3页
iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_第4页
iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、iwpriv工具通过ioctl动态获取相应无线网卡驱动的private_args所有扩展参数iwpriv是处理下面的wlan_private_args的所有扩展命令,iwpriv的实现上,是这样的, = main= set_private= iw_get_priv_info 获取 wireless 网卡所能处理的所有 wlan_private_args类型. dev_ioctl= wext_handle_ioctl= wireless_process_ioctlif (cmd = SIOCGIWPRIV & dev-wireless_handlers) return ioctl_standar

2、d_call(dev, ifr cmd, &iw_handler_get_private);static int ioctl_standard_call(struct net_device * dev,struct ifreq * ifr,unsigned int cmd, iw_handlerhandler)./* Call the handler */ret = handler(dev, &info, &(iwr-u), extra);if (user_length u.data.length) kfree(extra);return -E2BIG;通知iwpriv,本wifi网卡对应的p

3、rivate命令还没有完,还有,这样iwpriv将会继续/maxpriv默认为16,即将以16个为一组,一组一组的从wifi网卡驱动读取该网卡所能支持 的所有private_args参数/newpriv = realloc(priv, maxpriv * sizeof(priv0)继续申请,继续拷贝,知道将 wifi 网卡自定义的wlan_private_args参数全部传出到iwpriv为止. /* New driver API : try to find the handler */ handler = get_handler(dev, cmd);/ 获取if (handler) /* S

4、tandard and private are not the same */ if (cmd do_ioctl 完成的.return ioctl_private_call(dev, ifr, cmd, handler);/* Old driver API : call driver ioctl handler */if (dev-do_ioctl)如果 dev-wireless_handlers-standard 和dev-wireless_handlers-privateindex都不对该 cmd 作处理,那么由 /dev-do_ioctl = wlan_do_ioctl;我们驱动的最后处

5、理函数 wlan_do_ioctl 处理.return dev-do_ioctl(dev, ifr, cmd);static iw_handler get_handler(struct net_device *dev, unsigned int cmd)/* Dont optimise the following variable, it will crash */unsigned int index; /* *MUST* be unsigned */* Check if we have some wireless handlers defined */ if (dev-wireless_ha

6、ndlers = NULL)return NULL;/* Try as a standard command */index = cmd - SIOCIWFIRST;if (index wireless_handlers-num_standard) return dev-wireless_handlers-standardindex;/* Try as a private command */index = cmd - SIOCIWFIRSTPRIV;/if (index wireless_handlers-num_private)return dev-wireless_handlers-pr

7、ivateindex; 7该 private 命令的 handler./* Not found */return NULL;下面wlan_private_args为本wifi网卡驱动的所能支持的所有命令,也就是iwpriv命令所 能支持的所有命令struct iw_handler_def wlan_handler_def = num_standard:sizeof(wlan_handler) / sizeof(iw_handler),num_private:sizeof(wlan_private_handler) / sizeof(iw_handler), num_private_args:s

8、izeof(wlan_private_args) / sizeof(struct iw_priv_args), standard:(iw_handler *) wlan_handler, private:(iw_handler *) wlan_private_handler;private_args:(struct iw_priv_args *) wlan_private_args,#if WIRELESS_EXT 20get_wireless_stats:wlan_get_wireless_stats,#endif;以下为示意代码,我们的wifi网卡驱动支持如下iwpriv命令.static

9、 const struct iw_priv_args wlan_private_args = extscanhostcmdarpfilterregrdwrsdcmd52rw”sdcmd53rw”setgetconfgetcisscantypedeauthgetNFgetRSSIbgscanenable11dadhocgratesdioclockwmmuapsdnullgensetcoalescingadhocgprotsetpowerconswmm_qosinfololisteninterfwwakeupmethodpsnullintervalbcnmistoadhocawakepdmodul

10、etypeautodeepsleepenhancepswakeupmtsetrxantsettxantauthalgsencryptionmodesetregioncodesetlistenintersetmultipledtimsetbcnavgsetdataavgassociategetregioncode getlisteninter getmultipledtim gettxrate getbcnavg getdataavg getrxant gettxantgettsf wpssession deepsleep adhocstop radioon radiooffrmaeskey c

11、rypto_test reasso-on reasso-off wlanidle-on wlanidle-offsleepparams requesttpc powercap measreq bca-ts scanmodegetadhocstatus setgenie getgenie qstatus ts_status setaeskeygetaeskey version verext setwpaie setband setadhocchchanswann getband getadhocch getlog tpccfg scanprobesledgpio sleeppd rateadap

12、t getSNR getrate getrxinfo atimwindow bcninterval sdiopullctrl scantime sysclock txcontrol hscfg hssetpara inactoext dbgscfg drvdbg drvdelaymax intfctrl setquietiesetuserscan getscantable setmrvltlv getassocrsp addts delts qconfig qstats txpktstats getcfptable mefcfg getmem ;浅析ethx网卡控制函数ioctl实现具体流程1

13、.应用层程序iwprivwireless tools网络配置应用程序iwpriv命令格式:iwpriv ethX private-command parametersiwpriv部分实现源码如下:int main(int argc, char *argv)sockfd = socket(AF_INE SOCK_STREAM, 0);ioctl(sockfd, ioctl_val, &iwr);/将控制命令通过ioctl发送到无线网卡 2.系统调用sys_ioctl应用层通过ioctl(sockfd, ioctl_val, &iwr);触发sys_ioctl系统调用,实际流程: sys_ioct

14、l = vfs_ioctl = do_ioctl=最后调用filp-f_op-unlocked_ioctl执行具体的ioctl操作,该操作就是sock_ioctl,至于为什么是sock_ioctl,后边作了进一步分析sock_ioctl = #ifdef CONFIG_WIRELESS_EXTif (cmd = SIOCIWFIRST & cmd wext_handle_ioctl/* Take care of Wireless Extensions */if (cmd = SIOCIWFIRST & cmd wireless_process_ioctl = 然后通过 if (dev = _d

15、ev_get_by_name(net, ifr-ifr_name) = NULL涵数, 从系统管理的net链表中,把ioctl指定的ethX对应的struct net_device摘出来, 最后调用 ioctl_private_call(handler)或者调用 dev-do_ioctl(dev, ifr cmd)来处理该 ioctl,这两个函数分别指向wlan_handler_def和wlan_do_ioctl3.wifi网卡是怎么登记到kernel上的wlan_probe() = wlan_add_card() = alloc_etherdev() = 之后将操作方法添加到struct n

16、et_device *dev=alloc_etherdev()申请的dev上去,其 中包括:/* Setup the OS Interface to our functions */dev-open = wlan_open;dev-hard_start_xmit = wlan_hard_start_xmit;dev-stop = wlan_close;dev-do_ioctl = wlan_do_ioctl;dev-set_mac_address = wlan_set_mac_address;dev-tx_timeout = wlan_tx_timeout;dev-get_stats = wl

17、an_get_stats;dev-watchdog_timeo = MRVDRV_DEFAULT_WATCHDOG_TIMEOUT; dev-wireless_handlers = (struct iw_handler_def *) &wlan_handler_def; dev-set_multicast_list = wlan_set_multicast_list;4.socket系统调用如何关联上ioctl和ethX设备asmlinkage long sys_socket(int family, int type, int protocol);sys_socket=sock_create=

18、_sock_create=sock = sock_alloc();通 sock_mnt-mnt_sb从socket文件系统的超级块上申请一个inode节点,这样也就同时 获得了由该inode描述的一个sock结构体单元,所以sokcet和dentry目录项等效, 接下来从net_families全局管理结构体中找到当前family对应的ops操作集, net_proto_family *pf=net_familiesfamily;pf-create(net, sock, protocol);/核心调用,对于 ipv4,就是 inet_create以ipv4为例static struct net

19、_proto_family inet_family_ops = .family = PF_INET,.create = inet_create,.owner = THIS_MODULE,;还记得上面应用层创建sokcet的函数吧,sockfd = socket(AF_INET, SOCK_STREAM, 0);/AF_INET虽然等于 PF_INET,但是 因为种种原因我们提倡使用PF_INET可见family等于AF_INET,type等于SOCK_STREAM,协议protocol为0,也就是采用IP 协议,inet_create=inetswsock-type也就是 inetswSOCK

20、_STREAM,从inetswsock-type中找到已经登记的protocol网络协议处理函数,inetsw是怎么填充的呢?inet_init() = inet_register_protosw(inetsw_array) = 这 样inetsw_array中的所有protocol处理模块都将登记到inetsw中了,static struct inet_protosw inetsw_array=.type = SOCK_STREAM,.protocol = IPPROTO_TCP,.prot = &tcp_prot,.ops = &inet_stream_ops,.capability =

21、-1,.no_check = 0,.flags = INET_PROTOSW_PERMANENT | INET_PROTOSW_ICSK,.type = SOCK_DGRAM,.protocol = IPPROTO_UDP,.prot = &udp_prot,.ops = &inet_dgram_ops,.capability = -1,.no_check = UDP_CSUM_DEFAULT,.flags = INET_PROTOSW_PERMANENT,.type = SOCK_RAW,.protocol = IPPROTO_IP, /* wild card */.prot = &raw_

22、prot,.ops = &inet_sockraw_ops,.capability = CAP_NET_RAW,.no_check = UDP_CSUM_DEFAULT,.flags = INET_PROTOSW_REUSE,;至于inet_init,则是以fs_initcall(inet_init)方式,以5号优先级被build in到了内核中,当 kernel启动时会在start_kernel = rest_init=kernel_init=do_basic_setup=do_initcalls 中依据优先级号优先于其他module驱动被调用.这样 sock-ops = answer-op

23、s;对于 ipv4也就等于 inet_stream_ops,接下来就是将ops填充到file操作指针中了,sys_socket=sock_map_fd = sock_attach_fd = dentry-d_op = &sockfs_dentry_operations;init_file(file, sock_mnt, dentry, FMODE_READ | FMODE_WRITE,&socket_file_ops);file-private_data = sock;其中 init_file=file-f_op = fop;也就是 file-f_op = socket_file_ops;所以

24、 read(),wirte(),poll()和 ioctl()应用程序调用的 file-f_op 就是 socket_file_ops了,比如:read()对应sock_aio_read网络异步读write()对应sock_aio_write网络异步写ioctl()对应 sock_ioctlsocket_file_ops结构体具体实现如下:static const struct file_operations socket_file_ops = .owner =THIS_MODULE,.llseek =no_llseek,.aio_read =sock_aio_read,.aio_write

25、=sock_aio_write,.poll = sock_poll,.unlocked_ioctl = sock_ioctl,#ifdef CONFIG_COMPAT.compat_ioctl = compat_sock_ioctl,#endif.mmap = sock_mmap,.open = sock_no_open, /* special open code to disallow open via /proc */.release = sock_close,.fasync = sock_fasync,.sendpage = sock_sendpage,.splice_write = g

26、eneric_splice_sendpage,;网卡控制因为涉及到的知识点比较多,上面只是从宏观上对数据流程做了一个简单的介绍, 深入到其中的每个知识点,都会牵扯出一系列文章,读者需要自己去一个个的慢慢深入,希望 本文能够对刚刚接触网络驱动的读者有所帮助和启发【gliethttp.Leith】wireless extention扩展接口 Blog作者的回复:wlan_add_card = wlan_create_thread(wlan_service_main_thread, &priv-MainThread, wlan_main_service);= wlan_service_main_th

27、read = wlan_exec_next_cmd = 将调用 wlan_enter_ps 和 wlan_exit_pssbi_interrupt=从sdio 口上传来的中断数据,sdio_irq_thread = process_sdio_pending_irqs= 调用 func-irq_handler(func);即本.在 mmc_signal_sdio_irq = 将调用 wake_up_process(host-sdio_irq_thread);来 唤醒该irq处理线程,可能还有其他命令需要处理wlan_exec_next_cmd这个pxamci_irq就是 mmc的物理irq中断了

28、 ,pxamci_irq = mmc_signal_sdio_irq(host-mmc);wlan_exec_next_cmd = 只要 cmd 链表上 CmdNode 还存在,那么就会执行 wlan_dnld_cmd_to_fw(wlan_private * priv, CmdCtrlNode * CmdNode)将CmdNode中的数据下发下去,然后重新触发 wlan_mod_timer(&Adapter-MrvDrvCommandTimei, MRVDRV_TIMER_5S);也就是wlan_cmd_timeout_func命令超时处理函数,在cmd已经有了恢复之后,在主线程中调用wla

29、n_process_cmdresp,立即调用 wlan_cancel_timer(&Adapter-MrvDrvCommandTimer);来删除定时器 wlan_service_main_thread = 每次唤醒都会检查/* Execute the next command */if (!priv-wlan_dev.cmd_sent & !Adapter-CurCmd)wlan_exec_next_cmd(priv);wlan_prepare_cmd = wlan_hostcmd_ioctl = 获取一个空闲的CmdNode节点wlan_get_cmd_node,当完成赋值之后,执行如下语

30、句, 将CmdNode节点添加到处理队列中:wlan_insert_cmd_to_pending_q(Adapter, CmdNode, TRUE);wake_up_interruptible(&priv-MainThread.waitQ);另外在数组中/* iwconfig settable callbacks*/static const iw_handler wlan_handler这个数组中全部是回调函数,/* wlan_handler_def */struct iw_handler_def wlan_handler_def = num_standard:sizeof(wlan_hand

31、ler) / sizeof(iw_handler),num_private:sizeof(wlan_private_handler) / sizeof(iw_handler),num_private_args:sizeof(wlan_private_args) / sizeof(struct iw_priv_args), standard:(iw_handler *) wlan_handlei,private:(iw_handler *) wlan_private_handlerprivate_args:(struct iw_priv_args *) wlan_private_args,#if

32、 WIRELESS_EXT 20get_wireless_stats:wlan_get_wireless_stats,#endif;在 wlan_add_card 函数中dev-wireless_handlers = (struct iw_handler_def *) &wlan_handler_def;= = = = = = = = = = = = = = =在 kernel 的 net 中使用 wireless extention 扩展接口 static iw_handler get_handler(struct net_device *dev, unsigned int cmd)/* D

33、ont optimise the following variable, it will crash */unsigned int index; /* *MUST* be unsigned */* Check if we have some wireless handlers defined */if (dev-wireless_handlers = NULL) return NULL;/* Try as a standard command */index = cmd - SIOCIWFIRST;if (index wireless_handlers-num_standard) return dev-wireless_handlers-standardindex;/* Try as a private command */index = cmd - SIOCIWFIRSTPRIV;if (index wireless_handlers-num_private) return dev-wireless_handlers-privateindex;/* Not found */ret

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论