Files
protocol-rs/fuzz/fuzz_targets/lora_config_roundtrip.rs
swaits 4cccb65124 feat!: protocol v2 wire format and module restructure
The wire protocol is re-specified as DongLoRa Protocol v2 (see PROTOCOL.md). Every type_id, tag-correlation rule, and field layout is incompatible with 0.1.0.

* Add PROTOCOL.md as the normative spec for the v2 wire format.

* Replace framing.rs with a streaming FrameDecoder that emits (type_id, tag, payload) triples on each COBS-delimited, CRC-checked frame.

* Split the single-file lib.rs into dedicated modules: frame, commands, events, errors, modulation, info, crc, chip_id. Re-exports preserve convenience imports at the crate root.

* Replace RadioConfig / Bandwidth with a Modulation enum covering LoRa, FSK/GFSK, LR-FHSS, and FLRC, each with its own typed parameter struct.

* Add TxFlags, RxOrigin, SetConfigResult, OkPayload to model v2 response shapes, and RadioChipId for GET_INFO.

* Rewrite fuzz corpus: replace the 4 cobs_* / command_roundtrip targets with decoder_feed, frame_roundtrip, lora_config_roundtrip, and parse_device_message; drop parse_radio_config.

* Expand proptest and mutation-killer coverage for the new wire shape.

* Rewrite canonical-byte test vectors against the v2 spec.
2026-04-22 09:21:11 -06:00

51 lines
1.3 KiB
Rust

//! `LoRaConfig` round-trips through its wire encoding for every
//! construction derived via `Arbitrary`.
#![no_main]
use arbitrary::Arbitrary;
use donglora_protocol::{LoRaBandwidth, LoRaCodingRate, LoRaConfig, LoRaHeaderMode};
use libfuzzer_sys::fuzz_target;
#[derive(Debug, Arbitrary)]
struct Input {
freq_hz: u32,
sf: u8,
bw_raw: u8,
cr_raw: u8,
preamble_len: u16,
sync_word: u16,
tx_power_dbm: i8,
header_raw: u8,
payload_crc: bool,
iq_invert: bool,
}
fuzz_target!(|input: Input| {
let Some(bw) = LoRaBandwidth::from_u8(input.bw_raw & 0x0F) else {
return;
};
let Some(cr) = LoRaCodingRate::from_u8(input.cr_raw & 0x03) else {
return;
};
let Some(header_mode) = LoRaHeaderMode::from_u8(input.header_raw & 0x01) else {
return;
};
let cfg = LoRaConfig {
freq_hz: input.freq_hz,
sf: input.sf,
bw,
cr,
preamble_len: input.preamble_len,
sync_word: input.sync_word,
tx_power_dbm: input.tx_power_dbm,
header_mode,
payload_crc: input.payload_crc,
iq_invert: input.iq_invert,
};
let mut buf = [0u8; 32];
let n = cfg.encode(&mut buf).unwrap();
assert_eq!(LoRaConfig::decode(&buf[..n]).unwrap(), cfg);
});