Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IEEE 802.15.4/6LoWPAN support #469

Merged
merged 23 commits into from Oct 20, 2021
Merged

Conversation

thvdveld
Copy link
Contributor

This adds the IEEE 802.15.4 frame representation.
Still a work in progress and interested to know what you think about this.

I really would like to add 6LowPAN as well, however I'm not sure where to put this in smoltcp, since 6LowPAN is kind of weird.

@Dirbaio
Copy link
Member

Dirbaio commented May 2, 2021

Very interesting! ieee802154/6lowpan support would be definitely great to have in smoltcp, but it's not a small task :)

I believe the 6lowpan frame format is quite different than standard ipv6, so it might be a separate wire Packet and emit/parse methods. Support could be added in Interface, with a new Medium variant.

There's also 6lowpan over BLE (bluetooth low energy), which would use 6lowpan but not ieee802154 framing, passing the 6lowpan frames to a separate BLE stack.

How "independent" is 6lowpan from ieee802154? It would be great if it could be implemented at a layer lower than Interface instead of inside Interface itself, but I'm fearing that may not be possible, like with Ethernet. Ethernet support is super interlinked with IP, since it has to do ARP and NDP and silence the sockets until neighbors are discovered, etc. I tried splitting it in #336 and the result wasn't pretty. Is there similar neighbor discovery / MAC addressing issues with 6lowpan over ieee802154?

@thvdveld
Copy link
Contributor Author

thvdveld commented May 3, 2021

6lowpan needs to set the addresses in the ieee802154 header (ieee802154 doesn't really do a lot, it has a sequence number per frame, and the source/destination address/pan ID and some security feature).

The problem with 6lowpan is that it is hugely interlinked with IP, doing IP layer compression and fragmentation, since ieee802154 only allows 127 octets per frame. It also needs to perform the ARP and NDP, etc.

I'm not sure what you mean with your last question.

@thvdveld
Copy link
Contributor Author

thvdveld commented May 8, 2021

Just added 6LoWPAN IPHC parsing in wire, as well as the 6LoWPAN NHC parsing for UDP.

@thvdveld
Copy link
Contributor Author

Most of the wire implementation is done (need some more work on resolving the Address and probably other stuff that will come up when implementing the higher layers).

Currently, only IEEE 802.15.4 addresses are used (and thus not the BLE addresses).

I think I now understand your last question. I think 6LoWPAN also needs to handle the ARP and NDP.

@thvdveld
Copy link
Contributor Author

Hi @Dirbaio, I think the wire part is mostly done (probably still needs some more tests etc.).
I started in interface.rs but then I was wondering what the best approach was.
Would you handle each LOWPAN packet with new functions or should we first convert the incoming LOWPAN packet to an IPv6 packet and then handle it with the already existing functions?
The response is then converted back to a LOWPAN packet before sending it to the lower layers.
Not sure what the best approach is here.

@thvdveld
Copy link
Contributor Author

The current state of this PR is that I can use UDP sockets over 6LoWPAN for receiving.
Sending is also possible although only when an address is manually added to the neighbour cache.

@thvdveld thvdveld force-pushed the ieee802154 branch 2 times, most recently from 6de56b0 to 5a477ed Compare May 28, 2021 15:14
@thvdveld
Copy link
Contributor Author

thvdveld commented May 28, 2021

OK, still need correct some tests :'-).
The next step is probably updating ICMP and NDP since 6LoWPAN also has it's RFC for that...

@thvdveld thvdveld changed the title Add IEEE 802.15.4 frame support Add IEEE 802.15.4/6LoWPAN support May 28, 2021
@Dirbaio
Copy link
Member

Dirbaio commented May 28, 2021

This is so cool!

How do you test it out? Is there a way to create a "6lowpan tun/tap" to get Linux to talk to it?

@thvdveld
Copy link
Contributor Author

I'm testing it on real hardware. Our research group at the university uses Contiki on Zolertia RE-Motes to research protocols used in IEEE802.15.4. Now we are starting to test protocols written in Rust.

The tests I have are really not that great yet: using a Contiki implementation + using a Rust implementation + an IEEE802.15.4 sniffer...

@Dirbaio
Copy link
Member

Dirbaio commented May 28, 2021

Fun! It seems like it should be possible to get it going with fakelb (now deprecated? the replacement is ieee82154_hwsim?): https://www.netdevconf.org/2.1/slides/apr8/aring_virtual_mesh.pdf

@thvdveld
Copy link
Contributor Author

It seems so that ieee82154_hwsim with wpan-tools is the way to go for testing, however my knowledge about those tools (especially modprobe, ip, etc.) is non-existent.

@Dirbaio
Copy link
Member

Dirbaio commented May 29, 2021

I've got hwsim working! I've pushed it to your branch (hope you don't mind). The sixlowpan example has the commands to set it up. Once it's running it sends/receives packets to the Linux 6lowpan stack, so you can talk to it with regular Linux ping etc.

I've tried pinging it (with ping fe80::180b:4242:4242:4242%lowpan0) but it seems the ICMP checkum fails because IPHC doesn't decompress to the right dst addr (smoltcp says fe80::00ff:fe00:ffff, wireshark says ff02::1:ff42:4242. it's a broadcast Neighbor Solicitation)

@thvdveld
Copy link
Contributor Author

Thank you for the test!

I didn't test NDISC, since I manually added the neighbour address into the cache in my tests.
The reason why I didn't test it yet is because the Contiki stack uses the compressed version of ndisc (which I didn't implement yet for smoltcp). However, 6LoWPAN should be able to work with uncompressed formats of ndisc. I'll try to debug the example now.

@thvdveld
Copy link
Contributor Author

14d553e fixes the addressing issue. I'll now try to adapt ICMP for 6LoWPAN (uncompressed version).

@thvdveld
Copy link
Contributor Author

thvdveld commented Jun 8, 2021

ping should now work. Next step is to polish the code a little since a lot is still spaghetti code.

@thvdveld thvdveld force-pushed the ieee802154 branch 5 times, most recently from f246229 to 5ed4d4a Compare August 18, 2021 10:01
@thvdveld
Copy link
Contributor Author

Rebased on master.

1 test is failing but I have not yet figured out what causes this.

@thvdveld
Copy link
Contributor Author

Apparently the UDP API has changed, so need to update the Sixlowpan part.

Cargo.toml Outdated Show resolved Hide resolved
src/dhcp/clientv4.rs Outdated Show resolved Hide resolved
thvdveld and others added 21 commits October 21, 2021 01:25
This avoids wire needing to know what medium we're on.
We assume the FCS is checked by lower layers or by hardware.

- Makes it consistent with Ethernet mediums, where we don't handle the FCS either.
- Linux ieee802154 raw sockets send/receive packets without the FCS.
Using a raw socket on `monitor0` causes weird results: packets we receive
include FCS, packets we send are parsed as if they didn't have FCS, except
by wireshark which always expects a FCS??

Turns out the sane way is to use raw sockets on normal `wpanX` interfaces,
in which case all packets we send/receive are without FCS.
Also check for the correct destination PAN id when receiving a frame (as
discussed). Linux does this as well.
However, hardware implementations also can drop those packets.
When there is no medium in the feature flags, then there is no
HardwareAddress.
@Dirbaio Dirbaio marked this pull request as ready for review October 20, 2021 23:43
Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thibautvdv I'm going to merge this. It's complete, works great, code is well structured! 👍 The few remaining TODOs don't seem very critical, they can be addressed in future PRs.

I want to do some big changes to Interface code, which would send this to conflict hell otherwise.

@Dirbaio
Copy link
Member

Dirbaio commented Oct 20, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 20, 2021

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants