1

This question is asked to eventually allow developing a device driver that will take as input IPv6 data that has had 6LoWPAN header compression and data segmentation done on it. To help me understand how to make data sent by an application have 6LoWPAN adaptation performed on it, and how to receive said data for this prospective driver I want to make a server/client pair in which the data exchanged has 6LoWPAN adaptation performed on it.

I've always learned more from taking an example and breaking and fixing it, but I am a little unsure on whether an example could even be assembled in this case. I have made TCP and UDP server/client pairs in the past for similar (learning for eventual development) purpose, and in trying to figure out how to implement 6LoWPAN between a TCP server/client using IPv6 addressing I copied https://gist.github.com/inaz2/0e77c276a834ad8e3131.

I have found FOSS 6LoWPAN implementations on Contiki and in the Linux Kernel. From http://contiki.sourceforge.net/docs/2.6/a01794.html, "[6LoWPAN] is called by the MAC process when a 6lowpan packet is received, and by the tcpip process when an IPv6 packet needs to be sent." Then, is 6LoWPAN adaptation invoked before sending from a server, and that the client would need to be listening for 802.15.4? Or is there some interface configuration done to let the operating system know that this data should be formatted in 6LoWPAN?

The linux kernel 802.15.4 documentation (https://www.kernel.org/doc/html/latest/networking/ieee802154.html) mentions fake mac drivers for development, which seem like what I'm hoping for.

So my question is whether my understanding as expressed sounds correct, and if so I would follow with a request for direction toward something that can be used as a starting point for making a TCP IPv6 server direct output to 6LoWPAN adaptation, and/or an example of the fake mac drivers in use.

1
  • Aside: it’s 802.15.4, not 802.11.15.4.
    – jcaron
    Jan 7, 2022 at 8:42

1 Answer 1

2

The question points to the right place, the 'wpan-tools' package from the current Linux kernel has example programs. The 'fake mac' drivers refer to a module named 'mac802154_hwsim.' When searching on this topic one may see references to 'fakelb' which is a module that mac802154_hwsim was developed from. Part of wpan-tools is 'iwpan' which closely matches wifi management tool 'iw;' As I understand, fakelb was renamed to more closely match the naming convention of iw. Both fakelb and mac802154_hwsim create a pair of virtual 802.15.4 radios, with associated PHY and wpan interfaces. fakelb means fake loopback; the idea is that data can be sent from one virtual radio to the other similar to a loopback interface.

The example programs in 'wpan-tools' (https://github.com/linux-wpan/wpan-tools) have UDP (i.e. SOCK_DGRAM data type when opening the socket) tx/rx pairs for IPv6/6LoWPAN and 802.15.4 MAC interfaces. Also, there is a raw data (i.e. SOCK_RAW data type) 802.15.4 tx/rx pair in which raw data is assembled into a packet for transmission and received as a hex dump.

Incidentally, I've had no luck getting the UDP pair connecting to 802.15.4 interfaces (af_ieee802154_tx.c,af_ieee802154_rx.c) to work. When attempting to run the programs, each errors out with "socket: Address family not supported by protocol." However, the raw data and 6LoWPAN examples (af_inet6_tx.c,af_inet6_rx.c,af_packet_tx.c & af_packet_rx.c) do work, and the following describes how to send data from the 6LoWPAN interface to an 802.15.4 interface using mac802154_hwsim.

iwpan package is required, for debian-based OS, install with:

sudo apt install wpan-tools

Bring up the virtual radios:

sudo modprobe mac802154_hwsim

The example programs use pan_id 0x0023 for the radio that will be connected to the 6LoWPAN interface (hereafter referred to as the 'local' wpan interface, the counterpart will be referred to as 'remote'). Set pan_id for 'wpan0':

sudo ip link set wpan0 down
sudo iwpan dev wpan0 set pan_id 0x0023
sudo ip link set wpan0 up

Example program 'af_packet_rx.c' opens the socket on interface 'monitor0', but I aim to listen on the remote interface, 'wpan1.' Then, to be more consistent in naming:

sudo iwpan dev wpan1 del
sudo iwpan phy phy1 interface add monitor1 type monitor
sudo iwpan phy phy1 set channel 0 13
sudo ip link set monitor1 up

The interface name in af_packet_rx.c should be corrected to 'monitor1' on line 57.

Now attach a 6LoWPAN interface to the local wpan interface:

sudo ip link add link wpan0 name lowpan0 type lowpan
sudo ip link set lowpan0 up

Open two terminals, compile af_inet6_tx.c and af_packet_rx.c:

gcc -o wpan_rx af_packet_rx.c
gcc -o lowpan_tx af_inet6_tx.c

and run them; wpan_rx requires root privleges, in the first terminal window:

sudo ./wpan_rx

and in the other terminal window:

./lowpan_tx

The terminal running wpan_rx prints the hex dump of the packet sent from the 6LoWPAN interface. The contents of the packet payload can be verified by plugging the string sent from lowpan_rx "Hello world from AF_INET6 socket example" into an ascii to hex converter.

1
  • I did ask for a TCP server, but, well, I'm answering my own question, so I guess I get final say whether I'm right or not.
    – btgwynn
    Feb 24, 2022 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.