Difference between revisions of "Raspberry Pi 3B+ 802.15.4/6LoWPAN Setup"

From Embedded Lab Vienna for IoT & Security
Jump to navigation Jump to search
Line 141: Line 141:
  #IP6="fdaa:bb:cc:dd::1/64"
  #IP6="fdaa:bb:cc:dd::1/64"
  # Set ACK requests (Only enable if all devices on your PAN support ACKs)
  # Set ACK requests (Only enable if all devices on your PAN support ACKs)
ACKREQ=0
ACKREQ=0


Note: <code>MAC="02:0:0:0:0:0:0:1"</code> was taken from https://jan.newmarch.name/IoT/LinuxJournal/Routing/, this results in a link-local address of <code>fe80::1</code> for the Raspberry.
Note: <code>MAC="02:0:0:0:0:0:0:1"</code> was taken from https://jan.newmarch.name/IoT/LinuxJournal/Routing/, this results in a link-local address of <code>fe80::1</code> for the Raspberry.
Line 157: Line 157:
     TX packets 19  bytes 2114 (2.0 KiB)
     TX packets 19  bytes 2114 (2.0 KiB)
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
     TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  wpan0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 123
  wpan0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 123
         unspec 02-00-00-00-00-00-00-01-00-00-00-00-00-00-00-00  txqueuelen 300  (UNSPEC)
         unspec 02-00-00-00-00-00-00-01-00-00-00-00-00-00-00-00  txqueuelen 300  (UNSPEC)

Revision as of 13:19, 28 November 2023

Summary

Information on how to setup a Raspberry Pi 3B+ for 802.15.4 radio/6LoWPAN communication by utilizing an Openlabs 802.15.4 radio module.

This was tested successfully with Raspbian 10 (Buster) and Raspbian 11 (Bullseye). I assume it is also working on the latest Raspbian 12 (Bookworm).

Requirements

Description

Install Raspbian on Raspberry Pi 3B+

Preparation of Raspbian

Access the Raspberry Pi by attaching it via HDMI to a monitor. After enabling SSH it is possible to connect via SSH/terminal (default credentials are pi:raspberry).

  • (Optionally) Change keyboard setting to "German" and reboot:
sudo dpkg-reconfigure keyboard-configuration
  • Activate and start SSH on Raspberry:
sudo systemctl start ssh
sudo systemctl enable ssh
  • Upgrade of Raspbian:
sudo apt update && sudo apt upgrade

Enable support for IEEE 802.15.4/LoWPAN devices

  • Plug the OpenLabs 802.15.4 radio module directly onto pins 15-26 of the Raspberry's P1 header (in the middle):

Raspberry-pi-802.15.4-radio module.jpgRaspberry-pi-802.15.4-radio connected.jpg

  • There is an existing overlay for this transceiver shipped with Raspbian, should be in /boot/overlays/at86rf233-overlay.dtb or /boot/overlays/at86rf233.dtbo:
ls /boot/overlays/at86rf233.dtbo
  • Enable transceiver by modifying the /boot/config.txt file and reboot:

Installation of Linux WPAN tools

Sources/Links: see References:#Linux WPAN tools

  • First install git and clone the wpan-tools Repository:
sudo apt install git
sudo mkdir /opt/src
sudo chown pi /opt/src
cd /opt/src
git clone https://github.com/linux-wpan/wpan-tools
  • Install some required packages before building the wpan-tools:
sudo apt install dh-autoreconf libnl-3-dev libnl-genl-3-dev
  • Configure, build and install wpan-tools:
cd /opt/src/wpan-tools
./autogen.sh
./configure CFLAGS='-g -O0' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
make
sudo make install
  • Verification/test of wpan-tools installation:
iwpan dev

MANUAL WPAN interface configuration

Sources/Links: see References:#WPAN interface configuration

  • Configure the default PAN ID of RIOT-OS/SAMR21-xpro: 0x23
  • Configure the default channel ID of RIOT-OS/SAMR21-xpro: 26
ip link set lowpan0 down
ip link set wpan0 down
iwpan phy phy0 set channel 0 26 # same network ID and channel as RIOT default
iwpan dev wpan0 set pan_id 0x23 # same network ID and channel as RIOT default
ip link add link wpan0 name lowpan0 type lowpan
ip link set wpan0 up
ip link set lowpan0 up
  • Afterwards the lowpan0 interface on Raspberry has a link-local IPv6 address:
root@raspberrypi:~# ip a
1: lo: [...]
2: eth0: [...]
3: wlan0: [...]
4: wpan0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 123 qdisc pfifo_fast state UNKNOWN group default qlen 300
   link/ieee802.15.4 36:3a:07:cc:65:41:2b:31 brd ff:ff:ff:ff:ff:ff:ff:ff
5: lowpan0@wpan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1280 qdisc noqueue state UNKNOWN group default qlen 1000
   link/6lowpan 36:3a:07:cc:65:41:2b:31 brd ff:ff:ff:ff:ff:ff:ff:ff
   inet6 fe80::343a:7cc:6541:2b31/64 scope link
      valid_lft forever preferred_lft forever

NOTE/CAUTION: Every reboot changes the link-local IPv6 address of the lowpan0 interface on the Raspberry!

See #PERSISTENT wpan0 and lowpan0 configuration to configure a persistent link-local address.

There are also scripts available to create/delete a lowpan interface (or to create/delete a monitor interface): https://github.com/RIOT-Makers/wpan-raspbian

PERSISTENT wpan0 and lowpan0 configuration

With static long hardware address and static link-local IPv6 address (to avoid a random link-local IPv6 address on each reboot).

Sources/Links: see References:#Persistent WPAN interface configuration

  • Clone riot-makers/wpan-raspbian GitHub repo:
cd /opt/src
git clone https://github.com/riot-makers/wpan-raspbian
cd wpan-raspbian
  • Copy some helper (shell) scripts to a well-known location:
sudo cp -r usr/local/sbin/* /usr/local/sbin/.
sudo chmod +x /usr/local/sbin/*
  • Afterwards copy files for systemd integration:
sudo cp etc/default/lowpan /etc/default/.
sudo cp etc/systemd/system/lowpan.service /etc/systemd/system/.
  • Modify 802.15.4 channel ID and PAN ID in /etc/default/lowpan as needed:
sudo nano /etc/default/lowpan
CHN="13"
PAN="0xbeef"
# set MAC to "" for random mac/hw address
MAC="02:0:0:0:0:0:0:1"
# set IPv6 to "" if not required; note: set a prefix length
#IP6="fdaa:bb:cc:dd::1/64"
# Set ACK requests (Only enable if all devices on your PAN support ACKs)
ACKREQ=0

Note: MAC="02:0:0:0:0:0:0:1" was taken from https://jan.newmarch.name/IoT/LinuxJournal/Routing/, this results in a link-local address of fe80::1 for the Raspberry.

  • Enable lowpan.service autostart, start 6LoWPAN service and verification:
sudo systemctl enable lowpan.service
sudo systemctl start lowpan.service
ifconfig
lowpan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1280
   inet6 fe80::1  prefixlen 64  scopeid 0x20<link>
   unspec 02-00-00-00-00-00-00-01-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
   RX packets 0  bytes 0 (0.0 B)
   RX errors 0  dropped 0  overruns 0  frame 0
   TX packets 19  bytes 2114 (2.0 KiB)
   TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
wpan0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 123
       unspec 02-00-00-00-00-00-00-01-00-00-00-00-00-00-00-00  txqueuelen 300  (UNSPEC)
       RX packets 72  bytes 2016 (1.9 KiB)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 74  bytes 5320 (5.1 KiB)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Used Hardware

Courses

  • IT-Security master's programme: Mobile and Embedded Security ILV

References

Linux WPAN tools

WPAN interface configuration

Persistent WPAN interface configuration