.. _rust_link_layer: ===================================== Rust Link Layer Drivers ===================================== The ``rustflexstack::link_layer`` module moves GeoNetworking packets between the GeoNetworking router and the network interface. Every driver is connected to the router by two ``std::sync::mpsc`` channels: received packets go to the router, and the router's outgoing packets come from it. Available Drivers ================= .. list-table:: :widths: 25 35 40 :header-rows: 1 * - Driver - Underlying Technology - Feature Flag * - ``RawLinkLayer`` - ``pnet`` raw datalink channels (Ethernet, IEEE 802.11p OCB), EtherType ``0x8947`` - Default * - ``Cv2xLinkLayer`` - Qualcomm Telematics SDK through a C FFI (e.g. Cohda MK6) - ``--features cv2x`` RawLinkLayer ============ ``RawLinkLayer::new(gn_tx, gn_rx, iface, mac)`` takes the sender of received packets, the receiver of the router's packets, the interface name and the station's MAC address; ``start()`` launches its receive and transmit threads. Received frames with the GeoNetworking EtherType are passed on without the Ethernet header; outgoing packets are broadcast, or sent to the next hop's MAC address when unicast forwarding is enabled with ``with_unicast_receiver``. .. code-block:: rust use std::sync::mpsc; use std::thread; use rustflexstack::geonet::gn_address::{GNAddress, M, MID, ST}; use rustflexstack::geonet::mib::{GnIfType, Mib}; use rustflexstack::geonet::router::Router as GNRouter; use rustflexstack::link_layer::raw_link_layer::RawLinkLayer; let mac = [0x02u8, 0x11, 0x22, 0x33, 0x44, 0x55]; let mut mib = Mib::new(); mib.itsGnLocalGnAddr = GNAddress::new(M::GnMulticast, ST::PassengerCar, MID::new(mac)); mib.itsGnIfType = GnIfType::ItsG5; let (gn_handle, gn_to_ll_rx, _gn_to_btp_rx) = GNRouter::spawn(mib, None, None, None); let (ll_to_gn_tx, ll_to_gn_rx) = mpsc::channel::>(); let (unicast_tx, unicast_rx) = mpsc::channel(); gn_handle.set_unicast_sender(unicast_tx); let raw_ll = RawLinkLayer::new(ll_to_gn_tx, gn_to_ll_rx, "eth0", mac).with_unicast_receiver(unicast_rx); // ETSI TS 103 836-4-2 clause 6.1: over ITS-G5 the MID is the interface MAC address assert!(mib.media_dependent_address_ok(Some(raw_ll.media_dependent_mid()))); raw_ll.start(); // Received packets to the GeoNetworking router let gn = gn_handle.clone(); thread::spawn(move || { while let Ok(packet) = ll_to_gn_rx.recv() { gn.send_incoming_packet(packet); } }); Opening raw sockets needs root privileges or the ``CAP_NET_RAW`` capability. Qualcomm C-V2X Driver (``Cv2xLinkLayer``) ========================================= Built with ``--features cv2x`` against the Qualcomm Telematics SDK (see :ref:`rust_cv2x_embedded`), ``Cv2xLinkLayer::new(gn_tx, gn_rx)`` opens the C-V2X transmit and receive flows and is started in the same way. ``examples/cv2x_denm_sender_receiver.rs`` and ``examples/v2x_cli_cv2x.rs`` show the complete wiring.