《最新在Linux安装USB无线网卡幻灯片.ppt》由会员分享,可在线阅读,更多相关《最新在Linux安装USB无线网卡幻灯片.ppt(36页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、動機l有一張號稱支援Linux的USB無線網卡l雖然有附驅動程式但總是不能成功編譯l網路上有搜尋到幾種修改driver的方法但有待驗證Debug工具l附有兩個debug工具lapdbglmenudbgl安裝方法l make debug目標l將USB無線網卡在Linux上成功安裝運作lhotplugl了解USB無線網卡在Linux的driver架構lsrc/zdusb.c在Linux安裝USB無線網卡Final Projecthotplug問題出在哪?l由於網路上有人抱怨使用此晶片的廠商與產品太多,driver常來不及更新l因此假設問題出在Vendor ID與Device ID取得USB裝置的基
2、本資料 (1/2)lUSB裝置在連接到電腦時, /var/log/messages 會有訊息提示,如下lusb 4-3: new high speed USB device using ehci_hcd and address 9 lehci_hcd : USB 2.0 Enhanced Host Controllerl4 : bus numberl9 : device number取得USB裝置的基本資料 (2/2)lUSB裝置在連接到電腦後,資訊會更新在 /proc/bus/usb/devices 這個檔案lT: Bus=04 Lev=01 Prnt=01 Port=02 Cnt=01 D
3、ev#= 9 Spd=480 MxCh= 0lD: Ver= 2.00 Cls=ff(vend.) Sub=ff Prot=ff MxPS=64 #Cfgs= 1lP: Vendor=2019 ProdID=c007 Rev=47.21lS: Manufacturer=PLANEXlS: Product=PLANEX GW-US54GZLlC:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=500mAlI: If#= 0 Alt= 0 #EPs= 4 Cls=ff(vend.) Sub=00 Prot=00 Driver=zd1211lE: Ad=01(O) Atr=02(Bul
4、k) MxPS= 512 Ivl=0mslE: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0mslE: Ad=83(I) Atr=03(Int.) MxPS= 64 Ivl=125uslE: Ad=04(O) Atr=03(Int.) MxPS= 64 Ivl=125usHotPlug修復 zdusb.c (1/3)static struct usb_device_id zd1211_ids = (省略) USB_DEVICE(VENDOR_3COM, PRODUCT_A727) , USB_DEVICE(0 x2019, 0 xc007) , /加入這項 USB
5、_DEVICE(0 x2019, 0 xc008) ,(省略)HotPlug修復 zdusb.c (2/3)l將zdusb.c修改完成後重新編譯出模組l測試結果HotPlug修復 zdusb.c (3/3)rootTony # tail -17 /var/log/messageskernel: usb 4-3: new high speed USB device using ehci_hcd and address 11kernel: usb 4-3: configuration #1 chosen from 1 choicekernel:kernel: _ _ _ _kernel: |_ /
6、 _| _ / / _|kernel: / / | | | | | |/ _ _ kernel: / /| |_| | |_| / _ _) |kernel: /_, |_/_/ _/kernel: |_/kernel: zd1211 - version 2.8.0.0kernel: Release Ver = 4721kernel: EEPORM Ver = 4330kernel: PA type: 0kernel: AiroHa AL2230RFkernel: AllowedChannel = 000107ffkernel: Region:48kernel: usbcore: regist
7、ered new driver zd1211無線網卡運作情形 (1/2)rootTony # ifconfig eth2eth2Link encap:Ethernet HWaddr 00:90:CC:CC:CE:84inet addr:192.168.1.50 Bcast:192.168.1.255 Mask:255.255.255.0inet6 addr: fe80:290:ccff:fecc:ce84/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:6 errors:0 dropped:0 ov
8、erruns:0 frame:0TX packets:2 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:491 (491.0 b) TX bytes:458 (458.0 b)無線網卡運作情形 (2/2)rootTony # iwconfig eth2 essid CD0rootTony # iwconfig eth2eth2802.11b/g NIC ESSID:CD0Mode:Managed Frequency=2.462 GHz Access Point: 00:80:C8:37:B
9、F:77Bit Rate:11 Mb/sRetry:off RTS thr=2432 B Fragment thr:offEncryption key:offPower Management:offLink Quality:75/100 Signal level:72/100 Noise level:7/100Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0Tx excessive retries:261 Invalid misc:3 Missed beacon:0usbnet.c/drivers/usb/net/usbnet.cAu
10、thor : David BrownellUSB Network Driver Frameworkusbnet.c (1/13)lint usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)l判斷endpointl方向(bEndpointAddress) (in/out)l種類(bmAttributes) (USB_ENDPOINT_XFER_INT/BULK)usbnet.c (2/13)lstatic int init_status (struct usbnet *dev, struct usb_inter
11、face *intf)l初始化l讀取並設定設定最大封包、速度l包含kmalloclvoid usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)l收到封包後更新統計資料usbnet.c (3/13)lstatic void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)lDelaying (spinlock)lvoid usbnet_defer_kevent (struct usbnet *dev, int work)lDe
12、laying (kevent)usbnet.c (4/13)lstatic int usbnet_change_mtu (struct net_device *net, int new_mtu)l改變MTUlstatic struct net_device_stats *usbnet_get_stats (struct net_device *net)l回傳usbnet結構中stat部分usbnet.c (5/13)lstatic void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)l準備urb(USB Reques
13、t Block)l使用usb_submit_urb()將bulk urb送出至USB core或掛到queue尾端lstatic void rx_complete (struct urb *urb, struct pt_regs *regs)l根據urb結構的status變數得知狀態並做各種處理,最後用rx_submit()將urb送出usbnet.c (6/13)lstatic int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)l使用usb_unlink_urb()lstatic int usbnet_stop (stru
14、ct net_device *net)lusbnet結束時的處理l使用remove_wait_queue()與usb_kill_urb()將urb清乾淨usbnet.c (7/13)lstatic int usbnet_open (struct net_device *net)lusbnet的開啟與初始lvoid usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)lmodinfousbnet.c (8/13)lstatic void kevent (void *data)l判斷usbnet結構的fl
15、ag得到狀態l對以下event狀態進行動作l#define EVENT_TX_HALT0l#define EVENT_RX_HALT1l#define EVENT_RX_MEMORY 2l#define EVENT_LINK_RESET 4usbnet.c (9/13)lstatic void tx_complete (struct urb *urb, struct pt_regs *regs)l根據urb結構status變數得狀態並做各種處理l沒有將urb送出lstatic int usbnet_start_xmit (struct sk_buff *skb, struct net_devi
16、ce *net)lusb_fill_bulk_urb()準備bulk urblusb_submit_urb()送出urbusbnet.c (10/13)lInt usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)l呼叫usbnet_get_endpoints()進行初始動作lusb_set_intfdata()儲存data pointerlnetif_device_attach()usbnet.c (11/13)lvoid usbnet_disconnect (struct usb_interf
17、ace *intf)lusb_get_intfdata()查閱資料lusb_set_intfdata()將device部份設為NULLlunregister_netdev()usbnet.c (12/13)lint usbnet_suspend (struct usb_interface *intf, pm_message_t message)lusb_get_intfdata()查閱資料lnetif_device_detach()lunlink_urbs()移除rx/tx的urbusbnet.c (13/13)lint usbnet_resume (struct usb_interface
18、*intf)lusb_get_intfdata()查閱資料lnetif_device_attach()linux/netdevice.hstatic inline void netif_device_attach(struct net_device *dev)if(!test_and_set_bit(_LINK_STATE_PRESENT, &dev-state) & netif_running(dev)netif_wake_queue(dev);netdev_watchdog_up(dev);linux/netdevice.hstatic inline void netif_device_detach(struct net_device *dev)if (test_and_clear_bit(_LINK_STATE_PRESENT, &dev-state) & netif_running(dev) netif_stop_queue(dev);