## 3 IEEE 802.15.4
### MAC Sublayer  
Because devices that are in each other's proximity share the same communication medium, the access to the medium has to be controlled. When a device wants to send a packet, the MAC sublayer asks the PHY layer's CCA to check whether the medium is occupied. If the CCA indicates that another transmission is currently taking place, the MAC sublayer defers its transmission and waits for a set amount of time before it retries sending the packet. If, on the other hand, the CCA determines the medium to be free then the MAC sublayer transmits the packet immediately.  
Apart from medium access control the MAC sublayer also provides acknowledgement of frame reception and validation of incoming frames. The standard defines three different network structures: star topology, mesh topology and cluster tree topology. However, these 802.15.4 topologies are hardly ever used in practice and protocols that run on top of 802.15.4 build their own networks instead. To limit energy consumption, duty cycles are often used by MAC protocols. As a result, transceivers can be in sleeping mode up to 99% of the time, which drastically reduces power consumption and increases operational lifespan.  
The _Physical Protocol Data Unit_ (PPDU) and _MAC Protocol Data Unit_ (MPDU) formats as defined in IEEE Std 802.15.4-2011 are shown in Figure 3. The PPDU for O-QPSK consists of a SYNC header (for receiver clock synchronization), a PHY header (which contains the length of the PSDU) and a PHY payload referred to as the _Physical Service Data Unit_ (PSDU). To limit packet error rates, the PSDU is limited in size to 127 bytes. An 802.15.4 MPDU or MAC frame is transported as the PSDU of the PPDU and consists of three parts: (i) the _MAC header_ (MHR), (ii) the MAC payload and (iii) the _MAC footer_ (MFR). The MHR comprises frame control (indicating the type of frame), sequence number (for referring to frames, e.g., in acknowledgements), addressing information (for source and destination identification) and security-related information, and is of variable length. The frame payload also has a variable length and contains information specific to the frame type. Finally, the MFR is 2 bytes long and contains a _frame check sequence_ (FCS) that is calculated by the sender and that is used for frame validation by the receiver.  
Figure 3: IEEE 802.15.4 The _Physical Protocol Data Unit_ (PPDU) and _MAC Protocol Data Unit_ (MPDU) formats.  
Depending on the frame type the length of the addressing fields varies. An acknowledgement control frame for instance will not contain any addressing information. For data frames the length depends on which addressing format is being used and whether or not (optional) PAN identifiers of 2 bytes are included. The standard specifies two addressing formats: long 64-bit addresses that are globally unique and short 16-bit addresses that are unique within a PAN. When using the long addressing format, the MHR's length is 19 bytes and the maximum size of the payload is limited to 106 bytes. For the short addressing format the MHR is 7 bytes long and the maximum payload size is limited to 118 bytes. Using link-layer security can further reduce the size available for the payload size by as much as 14 bytes.