## 3 ZigBee Protocol Stack Overview and Configuration
### ZigBee Overview  
The ZigBee stack consists of four layers: the physical (PHY), the medium access control (MAC), the network (NWK) and the application (APL) layers. These layers are described next with a special emphasis on the settings that we evaluate in this paper. The PHY and MAC layers are adopted from the IEEE 802.15.4 specification, which defines mechanisms for, amongst others, the one-hop communication and channel access coordination amidst the nodes [24]. The IEEE 802.15.4 PHY layer is defined for three different radio frequency bands: 868 MHz, 915 MHz and 2.4 GHz. In the 2.4 GHz frequency band, which is available worldwide, orthogonal-quadrature phase shift keying (O-QPSK) is used to modulate the radio signal. The direct sequence spread spectrum (DSSS) is applied, increasing the robustness of data transmissions. With these settings, data rates of up to 250 kbit/s can be achieved. In the alternative frequency bands, which are used in Europe (868 MHz) and North America (915 MHz), binary phase shift keying (BPSK) is used in combination with DSSS, facilitating data rates of 20 kbit/s and 40 kbit/s, respectively. IEEE 802.15.4 defines two node roles, namely full-function devices (FFDs) and reduced-function devices (RFDs). While an FFD can talk to any other device, RFDs can only communicate with FFDs. In addition, only FFDs take part in routing. The resources of an RFD, like memory and processing power, are normally more restricted than the ones of an FFD. RFDs apply duty cycling to reduce energy consumption. A ZigBee network may operate in the beacon-enabled or beacon-less mode of IEEE 802.15.4, depending on the necessities of the application and the network topology. While in the beacon-enabled mode, channel access is organized by means of a superframe structure defined by beacons; in the beacon-less mode, nodes compete for the channel access without centralized coordination. According to the specification, in hierarchical (_i.e._, tree) topologies any of these modes can be used; however, in mesh topologies, beacon-less mode is the only option. In the beacon-enabled mode, the time between two beacons is split into the contention access period (CAP), the contention-free period (CFP) and an inactive period. While in CFP, devices are assigned guaranteed time slots (GTSs), in CAP, as well as in the beacon-less mode, devices employ carrier sense multiple access with collision avoidance (CSMA/CA). In CSMA/CA, before the transmission of data is initiated, a random backoff is applied and the channel occupation is sensed. If the channel is found to be busy, the channel access procedure is repeated up to a certain number of times. Independently of the operational mode, the IEEE 802.15.4 MAC layer provides optional one-hop reliability by using MAC layer acknowledgments (ACKs) to confirm the reception of packets. By default, MAC layer ACKs are enabled. If an ACK is not received after a specific duration (54 symbol durations), the delivery of the data frame is supposed to have failed. After an unsuccessful delivery, a retransmission is initiated, if the allowed retransmission count has not been reached for that data frame. This value is defined by the MAC layer parameter _macMaxFrameRetries_[24]. Once this many retries have been performed without receiving an ACK, the transmission of the data frame is considered to be unsuccessful. Possible values for the _macMaxFrameRetries_ parameter are defined to be between zero and seven, with a default value of three. The analysis of different configurations of this parameter is important, since it is related to the one-hop reliability and the link break detection mechanism of the NWK layer. The ZigBee NWK layer is responsible for, among other functions, discovering and maintaining routes between devices and relaying messages. It specifies a hierarchical routing scheme for the hierarchical (tree) topology and a peer-to-peer routing protocol based on the _Ad hoc_ On-demand Distance Vector routing protocol (AODV) [25] for the mesh topology.