1 Chapter 2 Data-link layer Problem Statement To transmit data over physical links from one node to another or more nodes effectively and efficiently, there is much more to do than simply modulating bit stream into signal. Transmission impairments, such as crosstalk between two adjacent pairs, can unexpectedly change transmission signal and hence result in errors. The transmitter may transmit faster than the receiver can afford. If there are multiple stations that share common transmission media, an arbitration mechanism is required to determine who can transmit its own data. The transmitter has to somehow indicate the destination, and usually needs to name itself so that the receiver knows where the source is. These problems need to be addressed by a set of functions above the physical layer. In the Open Systems Interconnection (OSI) seven-layer model, a specific layer, named data-link layer, provides the service of controlling data communications over a physical link. This layer provides solutions to the above problems. In addition, upper layers are therefore exempt from the duty of controlling parameters in a physical network. These services greatly alleviate upper-layer protocol design and make it virtually independent of physical transmission characteristics. Throughout this chapter, we intend to equip readers with fundamental background about (1) services and functions provided in the data-link layer, (2) real-world examples of popular data-link protocols, and (3) open source implementation in Linux. Frankly, there are too many real-world examples to choose. Some are legacy or much less popular nowadays. Some are in the mainstream and still some others are under development. It is nearly impossible to enumerate all of them. We subjectively offer a list of well-known data-link protocols in Table 2.1. Among these protocols, we introduce PPP as it is widely used in dial-up services. Network devices, say routers, also run PPP to carry various network layer protocols over point-to-point links among them. Ethernet technology has occupies more than 95 percent of all local area networks. It is also poised to be ubiquitous in the MAN and WAN. It is undoubtedly a technology we have to know. Wireless links allow greater mobility to make life easy. More devices, such as notebooks, Personal Data Assistant (PDA), cellular phones, and so on, are equipped with the 2 capability to access the Internet. In contrast with desktop PCs, which usually use wired links, these devices are mobile, and hence wireless links are preferred. We choose one typical example for wireless local area network, IEEE 802.11, and another for wireless personal local area network, Bluetooth in this chapter. PAN/LAN/MAN WAN Legacy or Minor Token bus (802.4) Token ring (802.5) DQDB (802.6) HIPPI SMDS Fiber Channel Isochronous (802.9) Demand Priority (802.12) ATM FDDI ISDN X.25 Frame Relay ATM Mainstream or Under development Ethernet (802.3) Resilient Packet Ring (802.17) Point-to-Point Protocol (PPP) HDLC DOCSIS Wireless PAN/LAN/MAN (802.15/11/16) Bluetooth HIPERLAN HomeRF Ethernet (802.3) Resilient Packet Ring (802.17) Point-to-Point Protocol (PPP) Table 2.1 data-link protocols Section 2.1 provides a general introduction of the functions in data-link layer. Specifically, they include framing, addressing, error control, flow control, and access control. We primarily explain why and how in this section, and leave technical details in specific protocols to later sections as possible. Section 2.2 introduces the Point-to-Point Protocol (PPP). The PPP is a standard protocol that carries multi-protocol packets in the upper layer over a point-to-point link. We present the open-source implementation so that the readers can know how the protocol operates in a real system. Following it is Section 2.3, which introduces the dominating LAN technology, Ethernet. Having evolved more than twenty years, Ethernet is rich in its physical specifications. However, this section will focus more on its functions in the data-link layer, and leaves the physical details in further reading. We also provide open Verilog code to be familiar with the implementation. Section 2.4 discusses wireless LAN. The nature of wireless media, such as mobility and lack of reliability, brings new impact in design different from wired media. Two typical examples, IEEE 802.11 and the Bluetooth technology, will be introduced in this section. Section 2.5 illustrates general concepts of device drivers in Linux. We will go deeply into Ethernet and PPP driver implementations, and list a map to indicate the source codes of the other drivers for the readers to