moonbit-radioframe

MoonBit wireless frame, link simulation, security, routing, and 6LoWPAN toolkit

wireless
ieee802154
frame
simulation
bitstream
mac
sixlowpan
ipv6
routing
moon add lxyhgvb/moonbit-radioframe@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
12 hours ago
Downloads
1
README

#MoonBit RadioFrame

moonbit-radioframe is a pure MoonBit toolkit for low-power wireless protocol encoding, link simulation, security, routing, and packet analysis. It is designed for deterministic tests, embedded-protocol experiments, and tooling that needs to inspect or generate IEEE 802.15.4-family traffic without a hardware radio.

#What it provides

  • Bit-level readers and writers with explicit width, order, and bounds checks.
  • IEEE 802.15.4 MAC frames, addressing modes, PAN compression, auxiliary security headers, BLE advertising PDUs, LoRaWAN headers, and Zigbee NWK headers.
  • CRC16-CCITT, CRC32, Internet checksum, parity helpers, and corruption diagnostics.
  • In-memory channel impairment models for loss, latency, jitter, duplication, collision windows, fading, noise, and BER experiments.
  • CSMA/CA, ACK/retry accounting, superframe timing, GTS allocation, MAC command payloads, RSSI/LQI, path-loss models, AODV-Jr, and RPL building blocks.
  • AES-128 and IEEE 802.15.4 / RFC 3610 AES-CCM* authenticated encryption, MIC generation, CTR mode, and replay-window checks.
  • A stateless 6LoWPAN data path covering IPv6, IPHC, UDP NHC, RFC 4944-style fragmentation, bounded out-of-order reassembly, and dispatch validation.
  • ASCII topology output, PCAP/PCAPNG export, hexadecimal trace analysis, and a small command-line demonstration.

#6LoWPAN support boundary

The src/sixlowpan package is intentionally explicit about the supported profile. It supports uncompressed IPv6 dispatch, stateless IPHC traffic and link-local address compression, UDP NHC port compression, and RFC 4944 fragmentation/reassembly. Stateful contexts, multicast address compression, extension-header compression, and UDP checksum elision are rejected with an error instead of being silently misinterpreted.

#Quick start

Install the latest stable MoonBit toolchain, then run the CLI example:

moon update moon run cmd/main

A minimal IPv6/UDP compression flow looks like this:

let source = @sixlowpan.Ipv6Address::link_local_from_eui64(
Bytes::from_array([(0x00).to_byte(), (0x01).to_byte(), (0x02).to_byte(), (0x03).to_byte(),
(0x04).to_byte(), (0x05).to_byte(), (0x06).to_byte(), (0x07).to_byte()]),
).unwrap()
let destination = @sixlowpan.Ipv6Address::link_local_from_eui64(
Bytes::from_array([(0x10).to_byte(), (0x11).to_byte(), (0x12).to_byte(), (0x13).to_byte(),
(0x14).to_byte(), (0x15).to_byte(), (0x16).to_byte(), (0x17).to_byte()]),
).unwrap()
let udp = @sixlowpan.UdpDatagram {
source_port: 61616,
destination_port: 61617,
checksum: 0U,
payload: Bytes::from_array([(0x68).to_byte(), (0x69).to_byte()]),
}
let packet = @sixlowpan.Ipv6Packet {
traffic_class: 0,
flow_label: 0U,
next_header: 17,
hop_limit: 64,
src: source,
dst: destination,
payload: udp.encode_with_ipv6_checksum(source, destination).unwrap(),
}
let compressed = @sixlowpan.compress_ipv6_packet(
packet,
@sixlowpan.CompressionConfig::default(),
).unwrap()
let decoded = @sixlowpan.decompress_iphc_packet(compressed).unwrap()

The end-to-end version, including fragmentation and reassembly, is exercised by the integration test in test/integration.mbt.

#Package map

PackageResponsibility
src/bitstreamBit packing, reading, alignment, and endianness
src/integrityCRC, checksum, parity, and corruption helpers
src/frame802.15.4, BLE, LoRaWAN, and Zigbee frame codecs
src/filterPAN and destination filtering
src/macCSMA/CA, ACK/retry, superframe, GTS, and MAC commands
src/channelLoss, delay, jitter, fading, noise, and collision simulation
src/phyDSSS, ISM channel, link-budget, and BER models
src/topologyPositions, path loss, RSSI/LQI, and graph helpers
src/meshAODV-Jr and RPL routing primitives
src/securityAES-128, AES-CCM*, MIC, CTR, and replay protection
src/sixlowpanIPv6, IPHC, UDP NHC, fragmentation, and reassembly
src/visualizationASCII topology and PCAP/PCAPNG exporters
src/energyRadio states, energy accounting, and battery estimates
src/cliTrace parsing, summaries, and CLI reporting
cmd/mainExecutable demonstration
testUnit, boundary, integration, and benchmark tests

#Verification

The repository's workflows run the same checks locally and in CI:

moon fmt git diff --exit-code moon update moon info git diff --exit-code moon check --deny-warn --target all moon build --target all moon test --deny-warn --target all moon bench --target native --release -p test

For a reproducible benchmark snapshot and its machine/toolchain metadata, see benchmarks/native-2026-08-24.md. Benchmark latency is environment-dependent; the recorded values are a reference for regression review, not a hardware-independent guarantee.

#Standards and references

#License

Apache-2.0. See LICENSE.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io