example/6lowpan: expand readme, do not use monitor interface.

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.
This commit is contained in:
Dario Nieuwenhuis 2021-10-07 05:26:44 +02:00
parent 36a0e9b2f3
commit 3b8a0781e5
1 changed files with 47 additions and 27 deletions

View File

@ -1,27 +1,44 @@
/* //! 6lowpan exmaple
//!
# Setup //! This example is designed to run using the Linux ieee802154/6lowpan support,
//! using mac802154_hwsim.
modprobe mac802154_hwsim //!
//! mac802154_hwsim allows you to create multiple "virtual" radios and specify
ip link set wpan0 down //! which is in range with which. This is very useful for testing without
iwpan dev wpan0 set pan_id 0xbeef //! needing real hardware. By default it creates two interfaces `wpan0` and
ip link add link wpan0 name lowpan0 type lowpan //! `wpan1` that are in range with each other. You can customize this with
ip link set wpan0 up //! the `wpan-hwsim` tool.
ip link set lowpan0 up //!
//! We'll configure Linux to speak 6lowpan on `wpan0`, and leave `wpan1`
iwpan dev wpan1 del //! unconfigured so smoltcp can use it with a raw socket.
iwpan phy phy1 interface add monitor%d type monitor //!
//! # Setup
# Running //!
//! modprobe mac802154_hwsim
sudo ./target/debug/examples/sixlowpan //!
//! ip link set wpan0 down
# Teardown //! ip link set wpan1 down
//! iwpan dev wpan0 set pan_id 0xbeef
rmmod mac802154_hwsim //! iwpan dev wpan1 set pan_id 0xbeef
//! ip link add link wpan0 name lowpan0 type lowpan
*/ //! ip link set wpan0 up
//! ip link set wpan1 up
//! ip link set lowpan0 up
//!
//! # Running
//!
//! Run it with `sudo ./target/debug/examples/sixlowpan`.
//!
//! You can set wireshark to sniff on interface `wpan0` to see the packets.
//!
//! Ping it with `ping fe80::180b:4242:4242:4242%lowpan0`.
//!
//! Speak UDP with `nc -uv fe80::180b:4242:4242:4242%lowpan0 6969`.
//!
//! # Teardown
//!
//! rmmod mac802154_hwsim
//!
mod utils; mod utils;
@ -35,7 +52,7 @@ use smoltcp::phy::{wait as phy_wait, Medium, RawSocket};
use smoltcp::socket::SocketSet; use smoltcp::socket::SocketSet;
use smoltcp::socket::{UdpPacketMetadata, UdpSocket, UdpSocketBuffer}; use smoltcp::socket::{UdpPacketMetadata, UdpSocket, UdpSocketBuffer};
use smoltcp::time::Instant; use smoltcp::time::Instant;
use smoltcp::wire::{IpAddress, IpCidr}; use smoltcp::wire::{Ieee802154Pan, IpAddress, IpCidr};
fn main() { fn main() {
utils::setup_logging(""); utils::setup_logging("");
@ -45,7 +62,7 @@ fn main() {
let mut matches = utils::parse_options(&opts, free); let mut matches = utils::parse_options(&opts, free);
let device = RawSocket::new("monitor0", Medium::Ieee802154).unwrap(); let device = RawSocket::new("wpan1", Medium::Ieee802154).unwrap();
let fd = device.as_raw_fd(); let fd = device.as_raw_fd();
let device = utils::parse_middleware_options(&mut matches, device, /*loopback=*/ false); let device = utils::parse_middleware_options(&mut matches, device, /*loopback=*/ false);
@ -64,7 +81,10 @@ fn main() {
64, 64,
)]; )];
let mut builder = InterfaceBuilder::new(device).ip_addrs(ip_addrs); let mut builder = InterfaceBuilder::new(device)
.ip_addrs(ip_addrs)
.dst_pan_id(Ieee802154Pan(0xbeef))
.src_pan_id(Ieee802154Pan(0xbeef));
builder = builder builder = builder
.hardware_addr(ieee802154_addr.into()) .hardware_addr(ieee802154_addr.into())
.neighbor_cache(neighbor_cache); .neighbor_cache(neighbor_cache);