Layer 2 is the Data Link layer. This layer uses a Media Access Controller (MAC) to generate the frames that will be transmitted. As the name suggests, the MAC controls the physical transmission media. The wireless transmission media used for WiFi or 802.11 has different requirements from the wired transmission media used for Ethernet or 802.3, and therefore needs a different MAC and PHY. Note the upper layer software is not aware of or affected by the physical interface.
When transmitting data, this layer adds a header containing the source and destination MAC addresses to the packet received from the Network layer. The frame it creates will then be forwarded to the Physical layer.
When receiving data, this layer is used to determine if the Frame received by the host contains the host’s MAC address. If it does, the data is forwarded up to the Network layer.
Every host on the network has at least one MAC address. Laptops typically have two: one for the wired LAN and one for the wireless LAN. Home routers also typically have two MACs: one for the local network and one for the Internet.
Most switches are referred to as “layer 2” devices because they route frames based on their MAC addresses.
Ethernet and WiFi Frame Format
As you probably guessed, the Data Link layer adds more than just the source and destination MAC addresses to the packet. Note the Media Access Controller for Ethernet and WiFi are different and generate different frames.