Triple Security in ZigBee: Link, Network and Application layer Encryptions

Libelium Banner Old

As pointed out in a previous article, the 802.15.4 MAC layer implements several features which are used by the ZigBee protocol in the network and application layers. One of this features is the security services.

IEEE 802.15.4 sets the encryption algorithm to use when cyphering the data to transmit, however, the standard does not specify how the keys have to be managed or what kind of authentication policies have to be applied. These issues are treated in the upper layers which are managed by technologies such as ZigBee.

Waspmote allows working on both 802.15.4 and ZigBee networks using XBee modules. These modules implement the necessary hardware to encrypt the data using AES algorithm with a 128b key length.

This article shows how to handle security matters using Waspmote and its open source API. To know more about the IEEE 802.15.4 security details, please read before the article dealing with this matter: Security in 802.15.4 and ZigBee networks.

Configuring security parameters is a very simple task to do using Waspmote API. All the information related to the library functions can be found in the 802.15.4 and ZigBee Networking Guides in the Waspmote Development section.

First of all, the security must be enabled using the following function:


The second step is setting the link key. This key must be the same on all the nodes to make them capable of communicating within the network. As explained previously, this is a 128b key length. The following function sets this key:


Enabling security decreases the Payload as the below figure shows, however it is worth paying for this decrease of information transmitted while ensuring the privacy of our network.



@16bit Unicast

@64bit Unicast



98 Bytes

94 Bytes

95 Bytes

NO Encrypted

100 Bytes

100 Bytes

100 Bytes

Waspmote API lets you set the security configuration in two easy steps.

ZigBee implements two extra security layers on top of the 802.15.4 one: the Network and Application security layers. XBee ZigBee modules integrated in Waspmote also implement these two extra security layers.

ZigBee networks need a coordinator to work. If encryption is enabled on the coordinator, then it will apply a security policy to the network when it is created.

Enabling security adds an authentication step to the joining process. For instance, after a router joins a network, it must then obtain the network security key to become authenticated. If the device cannot obtain the network security key, authentication fails, and the device leaves the network since it cannot communicate with anyone on the network.

First of all, the security must be enabled using the following function:


Security should be enabled on all nodes, not only on the Coordinator.

XBee ZigBee networks may work using a node as a Trust Center.

A Trust Center (TC) is a single device that is responsible for determining who may join the network. If a TC is enabled it must approve each router or end device which want join the network. If a router allows a new device to join the network, the router sends a notification to the TC that a join has occurred. The TC instructs the router to either authenticate the newly joined device or to force the device to leave. A TC is required for some public ZigBee profiles.

To use the TC in a ZigBee network, the coordinator should set the “use trust center” bit correctly in the ‘Encryption Options’ parameter before starting a network. Only the coordinator can serve as a TC.

Waspmote API allows you to set a Coordinator as a TC sing the following function:


XBee ZigBee networks may use three different keys:

  • Link Key: it is used to send the ‘Network Key’ cyphered. If this key is set to zero, then the key will be sent without cyphering to the joining nodes. Setting this key using Waspmote API is as simple as:



  • Network Key: it is used to cypher all the data sent within the network. Setting this key using Waspmote API is as simple as:


  • Application Key: it is used to cypher the data at the application layer. It is unique between each pair of nodes. This key is not configurable, though we must specify if it is going to be used or not with the following function:


Modules define a network key and a link key (trust center link key). Both keys are 128-bits and are used to apply AES encryption to RF packets.

The coordinator selects a network security key using the ‘Encryption Key’ parameter. Similarly, the coordinator must also specify a link key using the ‘Link Key’ parameter.

When a new device wants to join a secure network, it must obtain the network key from the Coordinator. The coordinator will either transmit the network key in clear, or it can encrypt the network key using a pre-installed link key. If the ‘Encryption Options’ bit is set to transmit the network key unencrypted, or if the ‘Link Key’ parameter is set to 0 on the coordinator (select a random link key), the coordinator will transmit the network key in  clear (unencrypted). Otherwise, if the ‘Encryption Options’ bit is not set and ‘Link Key’ is > 0, the coordinator will encrypt the network key with the link key and transmit the network key encrypted to any joining devices.

If a joining device does not have the right preconfigured link key, and the network key is being sent encrypted, then the joining device will not be able to join the network.
Network security requires a 32-bit frame counter to be maintained by each device. This frame counter is incremented after each transmission and cannot wrap to 0. If a neighbour receives a transmission with a frame counter that is less than or equal to the last received frame counter, the packet will be discarded.

To prevent an eventual lockup where the frame counter on a device reaches 0xFFFFFFFF, the network key should be periodically updated on all devices in the network. To update the network key in the network, the coordinator should issue the ‘Encryption Key’ parameter with a new security key. This will send a broadcast retransmission throughout the network causing the frame counters on all devices to reset to 0, and causing devices to begin using the new network key. All devices will also retain the previous key for a short time until everyone has switched to the new key.

Enabling security decreases the Payload as the below figure shows, however it is worth paying for this decrease of information transmitted while ensuring the privacy of our network.


@16bit Unicast


Encrypted (no APS)

66 Bytes

84 Bytes

Encrypted (APS)

62 Bytes

80 Bytes

NO Encrypted74 Bytes92 Bytes


External References: