Skip to content

Commit

Permalink
Merge pull request #30 from thvdveld/fix-issue-29
Browse files Browse the repository at this point in the history
Fix panic when different pan IDs
  • Loading branch information
thvdveld authored Dec 17, 2024
2 parents 3ac06da + 1f235c9 commit 7eda7ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dot15d4-frame/src/repr/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ impl<'p, T> FrameBuilder<'p, T> {
addr.src_pan_id,
) {
(Some(_), Some(_), Some(dst_pan_id), Some(src_pan_id)) => {
self.frame.frame_control.pan_id_compression = dst_pan_id == src_pan_id;
addr.src_pan_id = None;
if dst_pan_id == src_pan_id {
self.frame.frame_control.pan_id_compression = true;
addr.src_pan_id = None;
}
}
(Some(_), None, Some(_), _) => {
self.frame.frame_control.pan_id_compression = false;
Expand Down
23 changes: 23 additions & 0 deletions dot15d4-frame/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,26 @@ fn emit_enhanced_beacon() {
],
);
}

/// https://github.com/thvdveld/dot15d4/issues/29
/// Setting `dst_pan_id` to a different value than `src_pan_id` made the `emit` function panic.
#[test]
fn issue29() {
let frame = FrameBuilder::new_data(&[0x2b, 0x00, 0x00, 0x00])
.set_sequence_number(1)
.set_dst_pan_id(0xabce)
.set_dst_address(Address::Short([0x02, 0x04]))
.set_src_pan_id(0xabcd)
.set_src_address(Address::Extended([
0x00, 0x12, 0x4b, 0x00, 0x14, 0xb5, 0xd9, 0xc7,
]))
.finalize()
.unwrap();

let mut buffer = vec![0; frame.buffer_len()];

frame.emit(&mut Frame::new_unchecked(&mut buffer[..]));

println!("{:?}", frame);
println!("packet = {:#04X?}", buffer);
}

0 comments on commit 7eda7ad

Please sign in to comment.