Network Device Drivers


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Network Device Drivers

  1. 1. Network Device Drivers
  2. 2. Outline ● Brief look at Device Drivers ● Network Device Drivers ● Network Devices ● Madwifi Architecture ● Device Initialization ● Device Registration ● Opening and Closing a device ● Transmission of packets ● receiving packets ● IOCTL implementation
  3. 3. Brief look at Device Drivers ● Abstract the hardware ● Provide Mechanism, Not Policy ● e.g. Compare X Server to KDE ● Linux has 3 types of devices – char – block – network
  4. 4. Why are Network DD different ? ● It is similar to a block device – register with the kernel ● “Everything is a file” -- not applicable ● Asynchronous packet reception from outside ● Also needed for administrative purposes, the API is hence different
  5. 5. Higher protocols Uniform interface for Abstract the tech access to properties of a upper network adapter protocol instances Network Device Interface Network Driver (Adapter Specific)
  6. 6. Network Devices ● Represented by a struct net_device – General Fields (name,index,state) – Hardware specific fields (irq,memory addresses of buffers) – Data on the physical layer (mtu,hdr length, watchdog_timer) – Data on the network layer (protocol family) – Device Driver Methods (init,open,hard_start_xmit,get_stats,do_ioctl)
  7. 7. Network Devices <---> Device Drivers ● Network devices abstract the Device drivers by providing a uniform interface ● This is done with the help of function pointers ● E.g. Upper layers would call the standard function hard_start_xmit () – dev->hard_start_xmit = ieee80211_hardstart; Device Net Driver Device Function Function
  8. 8. MadWifi ● Partial open source Linux device driver for WLAN chipsets from Atheros ● Allows much more tweaking – good from a research POV ● Operation Modes supported – Station – Access Point – Ad hoc – Ahdemo – BSS mode – Monitor – WDS
  9. 9. Madwifi Architecture Implements the interface to the network device More Generic Code net80211 module Callbacks for the net80211 module and access hw Ath module through HAL Closed Source API from the HW for the device driver HAL
  10. 10. Device Initialization ● Search for the matching network adapter – Discover the I/O port – First 3 bytes of a MAC address identify the manufacturer ● Find the IRQ and DMA channels and reserve them ● Initialize driver specific methods dev->get_stats = ieee80211_getstats; dev->open = ieee80211_open; dev->stop = ieee80211_stop; dev->hard_start_xmit = ieee80211_hardstart;
  11. 11. Device Registration ● Kernel maintains a Linked List for all the registered network devices – dev_base ● register_netdevice () is used to add a new network device dev_base eth1 eth0
  12. 12. Opening and Closing ● Admins use ifconfig – ifconfig eth0 up – ifconfig eth0 down ● A device can only be opened once it has been registered ● ifconfig uses ioctl () to pass the appropriate flags for opening and closing devices.
  13. 13. Madwifi Implementation ● Madwifi seems to have equivalent init() and open() functions int ieee80211_open(struct net_device *dev) {         return ieee80211_init(dev, 0); } For new cards open reserves the DMA and IRQ lines since they  are not fixed
  14. 14. Transmission of Data Packets ● The net device interface function is hard_start_xmit () ● Packet data is copied to the buffer location of the network adapter and the time is marked        ath_hal_txstart(ah, txq­>axq_qnum); ath module code                 sc­>sc_dev­>trans_start = jiffies; ● In most cases, it is checked if there is space on the buffer location and netif_queue_stopped (dev) is called. ● However Madwifi doesnt seem to be using it. Perhaps the HAL takes care of it.
  15. 15. receiving packets Acknowledgment of tx receiving error interrupt
  16. 16. receiving packets ● Network Adapter interrupts the system processor ● Memory is allocated by using dev_alloc_skb () ● Try to learn the protocol type                   skb­>protocol = eth_type_trans(skb, dev) ● Place the socket buffer in the input queue ● update the last received packet time netif_rx(skb);                 dev­>last_rx = jiffies;
  17. 17. IOCTL implementation static int ieee80211_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {         struct ieee80211vap *vap = dev­>priv;         u_int unit;         switch (cmd) {         case SIOCG80211STATS:                 return copy_to_user(ifr­>ifr_data, &vap­>iv_stats,                         sizeof (vap­>iv_stats)) ? ­EFAULT : 0;         case SIOC80211IFDESTROY:                 if (!capable(CAP_NET_ADMIN))                         return ­EPERM;                 ieee80211_stop(vap­>iv_dev);    /* force state before cleanup */                 unit = vap­>iv_unit;                 vap­>iv_ic­>ic_vap_delete(vap);                 return 0;      
  18. 18. References ● Linux Device Drivers Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman ● The Linux Networking Architecture ● Understanding Linux Networking Internals ● ● Madwifi Source Code