版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、iwpriv工具通過ioctl動態(tài)獲取相應(yīng)無線網(wǎng)卡驅(qū)動的private_args所有擴(kuò)展參數(shù)iwpriv是處理下面的wlan_private_args的所有擴(kuò)展命令,iwpriv的實現(xiàn)上,是這樣的, = main= set_private= iw_get_priv_info 獲取 wireless 網(wǎng)卡所能處理的所有 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網(wǎng)卡對應(yīng)的p
3、rivate命令還沒有完,還有,這樣iwpriv將會繼續(xù)/maxpriv默認(rèn)為16,即將以16個為一組,一組一組的從wifi網(wǎng)卡驅(qū)動讀取該網(wǎng)卡所能支持 的所有private_args參數(shù)/newpriv = realloc(priv, maxpriv * sizeof(priv0)繼續(xù)申請,繼續(xù)拷貝,知道將 wifi 網(wǎng)卡自定義的wlan_private_args參數(shù)全部傳出到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;我們驅(qū)動的最后處
5、理函數(shù) 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網(wǎng)卡驅(qū)動的所能支持的所有命令,也就是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網(wǎng)卡驅(qū)動支持如下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網(wǎng)卡控制函數(shù)ioctl實現(xiàn)具體流程1
13、.應(yīng)用層程序iwprivwireless tools網(wǎng)絡(luò)配置應(yīng)用程序iwpriv命令格式:iwpriv ethX private-command parametersiwpriv部分實現(xiàn)源碼如下:int main(int argc, char *argv)sockfd = socket(AF_INE SOCK_STREAM, 0);ioctl(sockfd, ioctl_val, &iwr);/將控制命令通過ioctl發(fā)送到無線網(wǎng)卡 2.系統(tǒng)調(diào)用sys_ioctl應(yīng)用層通過ioctl(sockfd, ioctl_val, &iwr);觸發(fā)sys_ioctl系統(tǒng)調(diào)用,實際流程: sys_ioct
14、l = vfs_ioctl = do_ioctl=最后調(diào)用filp-f_op-unlocked_ioctl執(zhí)行具體的ioctl操作,該操作就是sock_ioctl,至于為什么是sock_ioctl,后邊作了進(jìn)一步分析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涵數(shù), 從系統(tǒng)管理的net鏈表中,把ioctl指定的ethX對應(yīng)的struct net_device摘出來, 最后調(diào)用 ioctl_private_call(handler)或者調(diào)用 dev-do_ioctl(dev, ifr cmd)來處理該 ioctl,這兩個函數(shù)分別指向wlan_handler_def和wlan_do_ioctl3.wifi網(wǎng)卡是怎么登記到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系統(tǒng)調(diào)用如何關(guān)聯(lián)上ioctl和ethX設(shè)備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文件系統(tǒng)的超級塊上申請一個inode節(jié)點,這樣也就同時 獲得了由該inode描述的一個sock結(jié)構(gòu)體單元,所以sokcet和dentry目錄項等效, 接下來從net_families全局管理結(jié)構(gòu)體中找到當(dāng)前family對應(yīng)的ops操作集, net_proto_family *pf=net_familiesfamily;pf-create(net, sock, protocol);/核心調(diào)用,對于 ipv4,就是 inet_create以ipv4為例static struct net
19、_proto_family inet_family_ops = .family = PF_INET,.create = inet_create,.owner = THIS_MODULE,;還記得上面應(yīng)用層創(chuàng)建sokcet的函數(shù)吧,sockfd = socket(AF_INET, SOCK_STREAM, 0);/AF_INET雖然等于 PF_INET,但是 因為種種原因我們提倡使用PF_INET可見family等于AF_INET,type等于SOCK_STREAM,協(xié)議protocol為0,也就是采用IP 協(xié)議,inet_create=inetswsock-type也就是 inetswSOCK
20、_STREAM,從inetswsock-type中找到已經(jīng)登記的protocol網(wǎng)絡(luò)協(xié)議處理函數(shù),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號優(yōu)先級被build in到了內(nèi)核中,當(dāng) kernel啟動時會在start_kernel = rest_init=kernel_init=do_basic_setup=do_initcalls 中依據(jù)優(yōu)先級號優(yōu)先于其他module驅(qū)動被調(diào)用.這樣 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()應(yīng)用程序調(diào)用的 file-f_op 就是 socket_file_ops了,比如:read()對應(yīng)sock_aio_read網(wǎng)絡(luò)異步讀write()對應(yīng)sock_aio_write網(wǎng)絡(luò)異步寫ioctl()對應(yīng) sock_ioctlsocket_file_ops結(jié)構(gòu)體具體實現(xiàn)如下: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,;網(wǎng)卡控制因為涉及到的知識點比較多,上面只是從宏觀上對數(shù)據(jù)流程做了一個簡單的介紹, 深入到其中的每個知識點,都會牽扯出一系列文章,讀者需要自己去一個個的慢慢深入,希望 本文能夠?qū)倓偨佑|網(wǎng)絡(luò)驅(qū)動的讀者有所幫助和啟發(fā)【gliethttp.Leith】wireless extention擴(kuò)展接口 Blog作者的回復(fù):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 = 將調(diào)用 wlan_enter_ps 和 wlan_exit_pssbi_interrupt=從sdio 口上傳來的中斷數(shù)據(jù),sdio_irq_thread = process_sdio_pending_irqs= 調(diào)用 func-irq_handler(func);即本.在 mmc_signal_sdio_irq = 將調(diào)用 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 還存在,那么就會執(zhí)行 wlan_dnld_cmd_to_fw(wlan_private * priv, CmdCtrlNode * CmdNode)將CmdNode中的數(shù)據(jù)下發(fā)下去,然后重新觸發(fā) wlan_mod_timer(&Adapter-MrvDrvCommandTimei, MRVDRV_TIMER_5S);也就是wlan_cmd_timeout_func命令超時處理函數(shù),在cmd已經(jīng)有了恢復(fù)之后,在主線程中調(diào)用wla
29、n_process_cmdresp,立即調(diào)用 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節(jié)點wlan_get_cmd_node,當(dāng)完成賦值之后,執(zhí)行如下語
30、句, 將CmdNode節(jié)點添加到處理隊列中:wlan_insert_cmd_to_pending_q(Adapter, CmdNode, TRUE);wake_up_interruptible(&priv-MainThread.waitQ);另外在數(shù)組中/* iwconfig settable callbacks*/static const iw_handler wlan_handler這個數(shù)組中全部是回調(diào)函數(shù),/* 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 函數(shù)中dev-wireless_handlers = (struct iw_handler_def *) &wlan_handler_def;= = = = = = = = = = = = = = =在 kernel 的 net 中使用 wireless extention 擴(kuò)展接口 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 臨時占用土地租賃協(xié)議
- 快件賒銷協(xié)議書
- 2024建設(shè)工程補充合同范本
- 求職意向書樣本-書信范本
- 2024幼兒園保安聘用合同
- 勞務(wù)施工安全協(xié)議書范本2024年
- 浙江省初中名校七年級上學(xué)期語文期中試卷5套【附答案】
- 吉林省雜糧采購合同
- 4.1 夯實法治基礎(chǔ) (大單元教學(xué)設(shè)計) 2024-2025學(xué)年統(tǒng)編版道德與法治九年級上冊
- 家庭雇傭保姆合同模板
- 煤礦皮帶智能化集控系統(tǒng)PPT教學(xué)講授課件
- 個人財務(wù)管理系統(tǒng)的設(shè)計與實現(xiàn)--論文
- 分?jǐn)?shù)乘除法整理復(fù)習(xí)(課堂PPT)
- 杭州會展業(yè)發(fā)展與對策研究文獻(xiàn)綜述
- 小學(xué)六年級英語上冊《Unit 1 How can I get there》教案
- 完整版方法驗證報告模板最終
- 電力管道資料表格(共30頁)
- 大班科學(xué)活動教案《豆豆家族》含PPT課件
- 【精品試卷】部編人教版(統(tǒng)編)一年級上冊語文第一單元測試卷含答案
- 金屬有機化學(xué)ppt課件
- 數(shù)學(xué)說題稿(共4頁)
評論
0/150
提交評論