nRF51 IoT SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
6LoWPAN over BLE

The BLE 6LoWPAN library implements the 6lo (IPv6) over BLE (Bluetooth low energy) adaptation layer functionality defined in the IETF draft. The location of the 6LoWPAN layer is shown in Figure 1 below. This layer contains IPSP, which communicate directly with the SoftDevice, and manages traffic on the transport layer (L2CAP Channel).

6lowpan_arch.png
Figure 1. BLE_6LOWPAN localization in the nRF51 layer structure.

The main responsibilities of the 6LoWPAN module are:

  • Decompression of the IPv6 header from IP header compression.
  • Decompression of the UDP header from NHC compression.
  • Compression of the IPv6 header to IPHC format.
  • Compression of the UDP header to NHC format.
  • Maintaining the 6LoWPAN interfaces and mapping them to L2CAP channels maintaining their dedicated transmission FIFO.
  • Creating the interface for IP stacks.
  • Using the cross-layer Context Manager for stateful compression and decompression.

This module does not contain the following functionality:

  • Neighbor discovery procedures as described in the IETF draft.
  • Establishment or Tear down of the BLE link or the L2CAP channel.

Internally, the module can be visualized to be consisting of three sub-layers as shown in Figure 2:

  • API: Enables communication between the physical interface and the IP stack.
  • CORE: Performs compression and decompression as defined for the 6LoWPAN interfaces.
  • TRANSPORT: Manages the traffic on the connection between BLE devices at the L2CAP level.
6lowpan_arch_internal.png
Figure 1. BLE 6LoWPAN internal logical layer structure.

6LoWPAN interface

To distinguish the connections from different BLE devices (on Master), concept of interfaces is created (iot_interface_t). Each interface is of the Point-to-Point type and is a logical representation of the L2CAP CoC connection, which contains several parameters:

  • Local EUI-64 address constructed from the local BLE address.
  • Peer EUI-64 address constructed from the peer BLE address.
  • Transmit Context Identifier (shared context). This is used for stateful compression of the packets. The context identifiers can be provided by the IP stack to speed up the context searching procedure on 6LoWPAN. Setting both to IPV6_CONTEXT_IDENTIFIER_NONE results in looking for contexts using the Context Manager if needed, then global addresses are used.
  • Application specific pointers to the transport layer and upper stack references that, for example, hold data from the IPSP channel identifying the peer and the L2CAP channel.

Each of the 6LoWPAN interfaces can be enumerated as a point-to-point network interface with the IP stack.

API functions

Initialization/setup procedure

Before the module can be used, an initialization via the ble_6lowpan_init function is mandatory. The function takes two parameters:

  • Asynchronous event notification handler registered with the module to receive the events from the module.
  • Local EUI-64 for each interface, which is needed by the IPv6 stacks.

Send procedure

The ble_6lowpan_interface_send function allows the application to send IPv6 packets. The size of the packets should be at least 40 bytes to contain the IPv6 header. This API expects the packet to be an entire IPv6 packet without any compression performed on it. Compression is done by the module.

Sometimes the transport channel cannot send the packet immediately, and then the packet is queued to be transmitted later. In case of overflowing the transmit queue, the BLE_6LOWPAN_TX_FIFO_FULL return value is used.

This API expects that the buffer used to transmit the packet is an allocated one, and it frees the packet once the transmission is complete. This is done to ensure that there is no need to copy the data in each module.

Is it also possible to speed up the stateful compression procedure by setting the tx_contexts on the IoT interface. It stops any additional address compression for the 64-bit prefix.

Asynchronous Event Notification Callback

6LoWPAN notifies the application of the following asynchronous events by using the callback registered with it at the initialization:

Event Description
BLE_6LO_EVT_ERROR When an error occurs in the module.
BLE_6LO_EVT_INTERFACE_ADD When a new interface is available for IPv6 exchange.
BLE_6LO_EVT_INTERFACE_DELETE When an interface is no longer available for IPv6 exchange.
BLE_6LO_EVT_INTERFACE_DATA_RX When IP traffic is received on the interface.

The interface for which an event is notified is identified by using the interface identification in the callback. Each event is also accompanied with an event result to provide any additional status information. For example, an IP packet could not be successfully decompressed,and this is notified to the IP stack using the event result for BLE_6LO_EVT_INTERFACE_DATA_RX. Event parameters contain related parameters (if any).

In case stateful compression is used and no context table or context identifier is found, then BLE_6LO_EVT_INTERFACE_DATA_RX with the result BLE_6LOWPAN_CID_NOT_FOUND is generated. The stack is then responsible for taking a decision about the decompression source and the destination addresses. Used contexts are always attached to the event parameters.

It is a good idea to refer to the MSC to better understand 6LoWPAN events and the application interface with respect to the IPSP and the IPv6 stack.