Skip to content

Commit

Permalink
Merge #575
Browse files Browse the repository at this point in the history
575: ieee802154: random sequence number r=Dirbaio a=thibautvdv

Set the sequence number to a random value when building the interface (builds on #573).

Co-authored-by: Thibaut Vandervelden <thvdveld@vub.be>
  • Loading branch information
bors[bot] and thvdveld authored Dec 4, 2021
2 parents 3644b94 + bf525bf commit bc93fbe
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/iface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ pub struct InterfaceBuilder<'a, DeviceT: for<'d> Device<'d>> {
#[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
neighbor_cache: Option<NeighborCache<'a>>,
#[cfg(feature = "medium-ieee802154")]
sequence_no: u8,
#[cfg(feature = "medium-ieee802154")]
pan_id: Option<Ieee802154Pan>,
ip_addrs: ManagedSlice<'a, IpCidr>,
sockets: SocketSet<'a>,
Expand Down Expand Up @@ -126,8 +124,6 @@ let iface = InterfaceBuilder::new(device, vec![])
#[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
neighbor_cache: None,

#[cfg(feature = "medium-ieee802154")]
sequence_no: 1,
#[cfg(feature = "medium-ieee802154")]
pan_id: None,

Expand Down Expand Up @@ -166,15 +162,6 @@ let iface = InterfaceBuilder::new(device, vec![])
self
}

/// Set the initial IEEE802.15.4 sequence number the interface will use.
///
/// **NOTE**: this needs to be initailized randomly and not equal to 0.
#[cfg(feature = "medium-ieee802154")]
pub fn sequence_no(mut self, sequence_no: u8) -> Self {
self.sequence_no = sequence_no;
self
}

/// Set the IEEE802.15.4 PAN ID the interface will use.
///
/// **NOTE**: we use the same PAN ID for destination and source.
Expand Down Expand Up @@ -312,6 +299,21 @@ let iface = InterfaceBuilder::new(device, vec![])

let caps = self.device.capabilities();

#[cfg(feature = "medium-ieee802154")]
let mut rand = Rand::new(self.random_seed);
#[cfg(not(feature = "medium-ieee802154"))]
let rand = Rand::new(self.random_seed);

#[cfg(feature = "medium-ieee802154")]
let mut sequence_no;
#[cfg(feature = "medium-ieee802154")]
loop {
sequence_no = (rand.rand_u32() & 0xff) as u8;
if sequence_no != 0 {
break;
}
}

Interface {
device: self.device,
sockets: self.sockets,
Expand All @@ -331,10 +333,10 @@ let iface = InterfaceBuilder::new(device, vec![])
#[cfg(feature = "proto-igmp")]
igmp_report_state: IgmpReportState::Inactive,
#[cfg(feature = "medium-ieee802154")]
sequence_no: self.sequence_no,
sequence_no,
#[cfg(feature = "medium-ieee802154")]
pan_id: self.pan_id,
rand: Rand::new(self.random_seed),
rand,
},
}
}
Expand Down

0 comments on commit bc93fbe

Please sign in to comment.