nRF5 SDK v14.2.0
Connecting devices to the router
In order to comply with RFC 7668 (Linux Kernel >= 4.12), set BLE_6LOWPAN_LEGACY_MODE define in sdk_config.h to 0. If this define is set to 1, 6LoWPAN module will not be able to decompress packets correctly.

Use the following procedure to establish a connection between an nRF5x device and the Linux router. Depending on the Linux variant that you are using, the commands may differ slightly.

# Log in as a root user.
sudo su
# Mount debugfs file system.
mount -t debugfs none /sys/kernel/debug
# Load 6LoWPAN module.
modprobe bluetooth_6lowpan
# Enable the bluetooth 6lowpan module.
echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
# Look for available HCI devices.
# Reset HCI device - for example hci0 device.
hciconfig hci0 reset
# Read 00:AA:BB:XX:YY:ZZ address of the nRF5x device.
hcitool lescan
# Connect to the device.
echo "connect 00:AA:BB:XX:YY:ZZ 1" > /sys/kernel/debug/bluetooth/6lowpan_control
# Check if you have established a connection.
# Try to ping the device using its link-local address, for example, on bt0 interface.
ping6 -I bt0 fe80::2AA:BBFF:FEXX:YYZZ
# Disconnect from the device.
echo "disconnect 00:AA:BB:XX:YY:ZZ" > /sys/kernel/debug/bluetooth/6lowpan_control
# Check if there are active connections left.
If using a Linux kernel version less than 4.0, the kernel debug file 6lowpan_enable will not be present. Instead you should use "echo 35 > /sys/kernel/debug/bluetooth/6lowpan_psm" to set PSM channel as 0x23 (35), and enable the bluetooth 6lowpan module.

Some of the commands, like loading the 6LoWPAN module or setting the PSM value, can be called only once per Linux session. If you are not familiar with the required Linux commands, check the following sections for more information about each command.

Root access

Several of the commands require administrator credentials, so you should log in as a root user by issuing the sudo su command.

# Log in as root user.
sudo su
# Proceed with caution.

Bluetooth 6LoWPAN module initialization

Current versions of the Linux kernel provide support for 6LoWPAN in Bluetooth low energy in a stand-alone module. The module must be compiled and enabled. After initializing the module, you will have access to the essential debugfs files.

You must initialize the module after each reboot. Once initialized, you do not need to repeat the steps for each connection.

debugfs file system

In most Linux distributions, the debugfs file system is mounted to /sys/kernel/debug. However, Raspbian OS does not automatically mount the debugfs file system. Therefore, you must mount it manually before 6LoWPAN can use it:

# Mount debugfs file system.
mount -t debugfs none /sys/kernel/debug
# Check the contents of the folder.
ls /sys/kernel/debug

You must mount the debugfs file system once after every reboot. Alternatively, you can make the mount persistent by editing the /etc/fstab file.

6LoWPAN initialization

To initialize the 6LoWPAN module, you must first load it:

modprobe bluetooth_6lowpan

Enable the bluetooth_6lowpan module:

echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
If using a Linux kernel version less than 4.0, the kernel debug file 6lowpan_enable will not be present. Instead you should use "echo 35 > /sys/kernel/debug/bluetooth/6lowpan_psm" to set PSM channel as 0x23 (35), and enable the bluetooth 6lowpan module.

To verify that the module is indeed loaded:

lsmod | grep bluetooth_6lowpan

Bluetooth 6LoWPAN commands

To use 6LoWPAN communication, both a GAP connection and an L2CAP connection oriented channel must be established. You can control both of them by issuing the debugfs command 6lowpan_control. Use this command to connect a device to or disconnect it from the Linux router.

The parameters of this command are:

To establish a 6LoWPAN connection:

echo "connect 00:AA:BB:XX:YY:ZZ 1" > /sys/kernel/debug/bluetooth/6lowpan_control
On some Linux kernel versions, you might need to repeat this procedure several times to successfully establish a connection.

To disconnect a device from the router:

echo "disconnect 00:AA:BB:XX:YY:ZZ 1" > /sys/kernel/debug/bluetooth/6lowpan_control

HCI commands

HCI commands are used to configure Bluetooth devices. The device name hciX is assigned to the device installed in the system.

To display basic status information, for example, about interface type, BD address, MTU, and flags (up, running, ...):


To check that the Bluetooth device installed in the system has low-energy support:

hciconfig hciX lestates

To reset the HCI device hciX (to ensure that it is cleared before starting):

hciconfig hciX reset

To discover all advertising devices:

hcitool lescan

Figure 1 displays an example of the output of the hcitool command.

Figure 1. Scan using hcitool.

To list all connected BLE devices:

hcitool con

Linux interfaces

You can use the ifconfig command to display and configure Linux network interfaces that are currently active. After successfully establishing a 6LoWPAN connection, you should see a newly added btX interface on the list.

To display all active network interfaces:


Specify an interface name (for example, bt0) to display information about that interface:

ifconfig bt0

You can assign a static IP address to the interface which can be used in the examples:

ifconfig bt0 add 2001:db8::1/64

Figure 2. Display information about the bt0 interface using ifconfig.

Ping devices

Communication between Linux and the device through IPv6 can use different types of protocols. One of these protocols is ICMPv6, which has diagnostic capabilities by sending and receiving echo request and echo response messages.

Use the IPv6 link-local address (see Creating link-local IPv6 addresses) to ping a specific device:

ping6 -I bt0 fe80::2AA:BBFF:FEXX:YYZZ
For Linux Kernel versions higher or equal to 4.12, an IPv6 link local address has the following form: fe80::AA:BBFF:FEXX:YYZZ.

Figure 3. Ping6 command with a unicast address.

Send an echo request to an IPv6 multicast all nodes address to discover all devices that are currently attached to the router:

ping6 -I bt0 ff02::1

In this case, not only the device will respond, but also the btX interface itself.

Figure 4. Ping6 command with multicast all node address.

The device will only send an echo response message if the application supports it (for example, when using Nordic's stack).

Documentation feedback | Developer Zone | Subscribe | Updated