Git Product home page Git Product logo

rust-ieee802.15.4's People

Contributors

blueluna avatar hannobraun avatar henrikssn avatar jonas-schievink avatar korken89 avatar ryankurte avatar xoac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-ieee802.15.4's Issues

Replace handwritten encoding/decoding code

I've handwritten all the code I needed for encoding and decoding frames. While this gets the job done, it's an error-prone approach, and hard to maintain. Ideally, all this code would be generated from a declarative definition of the messages.

There's probably a third-party crate that can help here.

New release?

Hi, could you make a new release including the PR I made?

Thanks!

Fix existing Clippy warnings

warning: this expression borrows a reference (`&[u8]`) that is immediately dereferenced by the compiler
Warning:    --> src/mac/beacon.rs:105:19
    |
105 |         check_len(&bytes, 2)?;
    |                   ^^^^^^ help: change this to: `bytes`
    |
    = note: `#[warn(clippy::needless_borrow)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: using `clone` on type `mac::beacon::BeaconOrder` which implements the `Copy` trait
Warning:    --> src/mac/beacon.rs:133:27
    |
133 |         let bo = u8::from(self.beacon_order.clone());
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.beacon_order`
    |
    = note: `#[warn(clippy::clone_on_copy)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on type `mac::beacon::SuperframeOrder` which implements the `Copy` trait
Warning:    --> src/mac/beacon.rs:134:27
    |
134 |         let so = u8::from(self.superframe_order.clone());
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.superframe_order`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: you should consider adding a `Default` implementation for `GuaranteedTimeSlotDescriptor`
Warning:    --> src/mac/beacon.rs:182:5
    |
182 | /     pub fn new() -> Self {
183 | |         GuaranteedTimeSlotDescriptor {
184 | |             short_address: ShortAddress::broadcast(),
185 | |             starting_slot: 0,
...   |
188 | |         }
189 | |     }
    | |_____^
    |
    = note: `#[warn(clippy::new_without_default)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try adding this
    |
180 + impl Default for GuaranteedTimeSlotDescriptor {
181 +     fn default() -> Self {
182 +         Self::new()
183 +     }
184 + }
    |

warning: this expression borrows a reference (`&[u8]`) that is immediately dereferenced by the compiler
Warning:    --> src/mac/beacon.rs:195:19
    |
195 |         check_len(&bytes, 3)?;
    |                   ^^^^^^ help: change this to: `bytes`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: you should consider adding a `Default` implementation for `GuaranteedTimeSlotInformation`
Warning:    --> src/mac/beacon.rs:248:5
    |
248 | /     pub fn new() -> Self {
249 | |         GuaranteedTimeSlotInformation {
250 | |             permit: false,
251 | |             slot_count: 0,
252 | |             slots: [GuaranteedTimeSlotDescriptor::new(); 7],
253 | |         }
254 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try adding this
    |
246 + impl Default for GuaranteedTimeSlotInformation {
247 +     fn default() -> Self {
248 +         Self::new()
249 +     }
250 + }
    |

warning: manual implementation of an assign operation
Warning:    --> src/mac/beacon.rs:278:25
    |
278 |                         direction_mask = direction_mask | dir;
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `direction_mask |= dir`
    |
    = note: `#[warn(clippy::assign_op_pattern)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:    --> src/mac/beacon.rs:280:21
    |
280 |                     dir = dir << 1;
    |                     ^^^^^^^^^^^^^^ help: replace it with: `dir <<= 1`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: the loop variable `n` is only used to index `slots`
Warning:    --> src/mac/beacon.rs:310:22
    |
310 |             for n in 0..slot_count {
    |                      ^^^^^^^^^^^^^
    |
    = note: `#[warn(clippy::needless_range_loop)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
help: consider using an iterator
    |
310 |             for <item> in slots.iter_mut().take(slot_count) {
    |                 ~~~~~~    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: manual implementation of an assign operation
Warning:    --> src/mac/beacon.rs:319:17
    |
319 |                 direction_mask = direction_mask >> 1;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `direction_mask >>= 1`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: you should consider adding a `Default` implementation for `PendingAddress`
Warning:    --> src/mac/beacon.rs:367:5
    |
367 | /     pub fn new() -> Self {
368 | |         PendingAddress {
369 | |             short_address_count: 0,
370 | |             short_addresses: [ShortAddress::broadcast(); 7],
...   |
373 | |         }
374 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try adding this
    |
365 + impl Default for PendingAddress {
366 +     fn default() -> Self {
367 +         Self::new()
368 +     }
369 + }
    |

warning: the loop variable `n` is only used to index `short_addresses`
Warning:    --> src/mac/beacon.rs:396:18
    |
396 |         for n in 0..sl {
    |                  ^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
help: consider using an iterator
    |
396 |         for <item> in short_addresses.iter_mut().take(sl) {
    |             ~~~~~~    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: the loop variable `n` is only used to index `extended_addresses`
Warning:    --> src/mac/beacon.rs:400:18
    |
400 |         for n in 0..el {
    |                  ^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
help: consider using an iterator
    |
400 |         for <item> in extended_addresses.iter_mut().take(el) {
    |             ~~~~~~    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: re-implementing `PartialEq::ne` is unnecessary
Warning:   --> src/utils.rs:59:13
   |
59 | /             fn ne(&self, other: &$name) -> bool {
60 | |                 match *other {
61 | |                     $( $name::$var => *self != $val, )*
62 | |                 }
63 | |             }
   | |_____________^
   |
  ::: src/mac/command.rs:12:1
   |
12 | / extended_enum!(
13 | |     /// MAC command identifiers
14 | |     CommandId, u8,
15 | |     /// Association request, request association to PAN
...  |
32 | |     GuaranteedTimeSlotRequest => 9,
33 | | );
   | |__- in this macro invocation
   |
   = note: `#[warn(clippy::partialeq_ne_impl)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
   = note: this warning originates in the macro `extended_enum` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: manual implementation of an assign operation
Warning:   --> src/mac/command.rs:83:13
   |
83 |             byte = byte | CAP_FFD;
   |             ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= CAP_FFD`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:   --> src/mac/command.rs:86:13
   |
86 |             byte = byte | CAP_MAINS_POWER;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= CAP_MAINS_POWER`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:   --> src/mac/command.rs:89:13
   |
89 |             byte = byte | CAP_IDLE_RECEIVE;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= CAP_IDLE_RECEIVE`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:   --> src/mac/command.rs:92:13
   |
92 |             byte = byte | CAP_FRAME_PROTECTION;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= CAP_FRAME_PROTECTION`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:   --> src/mac/command.rs:95:13
   |
95 |             byte = byte | CAP_ALLOCATE_ADDRESS;
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= CAP_ALLOCATE_ADDRESS`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: re-implementing `PartialEq::ne` is unnecessary
Warning:    --> src/utils.rs:59:13
    |
59  | /             fn ne(&self, other: &$name) -> bool {
60  | |                 match *other {
61  | |                     $( $name::$var => *self != $val, )*
62  | |                 }
63  | |             }
    | |_____________^
    |
   ::: src/mac/command.rs:101:1
    |
101 | / extended_enum!(
102 | |     /// Association Status
103 | |     AssociationStatus, u8,
104 | |     /// Successful
...   |
113 | |     FastAssociationSuccesful => 0x80,
114 | | );
    | |__- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
    = note: this warning originates in the macro `extended_enum` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: re-implementing `PartialEq::ne` is unnecessary
Warning:    --> src/utils.rs:59:13
    |
59  | /             fn ne(&self, other: &$name) -> bool {
60  | |                 match *other {
61  | |                     $( $name::$var => *self != $val, )*
62  | |                 }
63  | |             }
    | |_____________^
    |
   ::: src/mac/command.rs:116:1
    |
116 | / extended_enum!(
117 | |     /// Disassociation Reason
118 | |     DisassociationReason, u8,
119 | |     /// Coordinator requested device to leave
...   |
122 | |     DeviceLeave => 2,
123 | | );
    | |__- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
    = note: this warning originates in the macro `extended_enum` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: this expression borrows a reference (`&[u8]`) that is immediately dereferenced by the compiler
Warning:    --> src/mac/command.rs:160:19
    |
160 |         check_len(&bytes, 7)?;
    |                   ^^^^^^ help: change this to: `bytes`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: manual implementation of an assign operation
Warning:    --> src/mac/command.rs:216:13
    |
216 |             byte = byte | GTSC_RECEIVE_ONLY;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= GTSC_RECEIVE_ONLY`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: manual implementation of an assign operation
Warning:    --> src/mac/command.rs:219:13
    |
219 |             byte = byte | GTSC_ALLOCATION;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `byte |= GTSC_ALLOCATION`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
Warning:    --> src/mac/frame/header.rs:92:13
    |
92  | /             match i {
93  | |                 Some(addr) => {
94  | |                     // pan ID
95  | |                     len += 2;
...   |
102 | |                 _ => {}
103 | |             }
    | |_____________^
    |
    = note: `#[warn(clippy::single_match)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
help: try this
    |
92  ~             if let Some(addr) = i {
93  +                 // pan ID
94  +                 len += 2;
95  +                 // Address length
96  +                 match addr {
97  +                     Address::Short(..) => len += 2,
  ...

warning: this expression borrows a reference (`&[u8]`) that is immediately dereferenced by the compiler
Warning:    --> src/mac/frame/header.rs:118:19
    |
118 |         check_len(&bytes, 3)?;
    |                   ^^^^^^ help: change this to: `bytes`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: returning an `Err(_)` with the `?` operator
Warning:    --> src/mac/frame/header.rs:287:20
    |
287 |             return Err(EncodeError::MissingSecurityCtx)?;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err(EncodeError::MissingSecurityCtx.into())`
    |
    = note: `#[warn(clippy::try_err)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: returning an `Err(_)` with the `?` operator
Warning:    --> src/mac/frame/header.rs:294:36
    |
294 |                     None => return Err(EncodeError::UnknownError)?,
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err(EncodeError::UnknownError.into())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: returning an `Err(_)` with the `?` operator
Warning:    --> src/mac/frame/header.rs:296:32
    |
296 |                 None => return Err(EncodeError::UnknownError)?,
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err(EncodeError::UnknownError.into())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: returning the result of a `let` binding from a block
Warning:   --> src/mac/frame/security/auxiliary_security_header.rs:40:9
   |
28 | /         let length = 1
29 | |             + 4
30 | |             + match self.key_identifier {
31 | |                 Some(key_id) => match key_id.key_source {
...  |
38 | |                 None => 0,
39 | |             };
   | |______________- unnecessary `let` binding
40 |           length
   |           ^^^^^^
   |
   = note: `#[warn(clippy::let_and_return)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
help: return the expression directly
   |
28 ~         
29 ~         1
30 +             + 4
31 +             + match self.key_identifier {
32 +                 Some(key_id) => match key_id.key_source {
33 +                     Some(source) => match source {
 ...

warning: unsafe function's docs miss `# Safety` section
Warning:   --> src/mac/frame/security/auxiliary_security_header.rs:59:5
   |
59 | /     pub unsafe fn new_unsafe(
60 | |         control: SecurityControl,
61 | |         key_identifier: Option<KeyIdentifier>,
62 | |         frame_counter: u32,
...  |
68 | |         }
69 | |     }
   | |_____^
   |
   = note: `#[warn(clippy::missing_safety_doc)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
Warning:    --> src/mac/frame/security/auxiliary_security_header.rs:146:9
    |
146 | /         match self.key_identifier {
147 | |             Some(key_identifier) => {
148 | |                 bytes.write(offset, key_identifier)?;
149 | |             }
150 | |             _ => {}
151 | |         }
    | |_________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
help: try this
    |
146 ~         if let Some(key_identifier) = self.key_identifier {
147 +             bytes.write(offset, key_identifier)?;
148 +         }
    |

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
Warning:    --> src/mac/frame/security/auxiliary_security_header.rs:169:9
    |
169 | /         match self.key_source {
170 | |             Some(source) => match source {
171 | |                 KeySource::Short(src) => bytes.write(offset, src)?,
172 | |                 KeySource::Long(src) => bytes.write(offset, src)?,
173 | |             },
174 | |             _ => {}
175 | |         }
    | |_________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
help: try this
    |
169 ~         if let Some(source) = self.key_source { match source {
170 +             KeySource::Short(src) => bytes.write(offset, src)?,
171 +             KeySource::Long(src) => bytes.write(offset, src)?,
172 +         } }
    |

warning: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
Warning:    --> src/mac/frame/security/security_control.rs:104:27
    |
104 |     pub(crate) fn to_bits(&self) -> u8 {
    |                           ^^^^^
    |
    = note: `#[warn(clippy::wrong_self_convention)]` on by default
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

warning: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value
Warning:    --> src/mac/frame/security/security_control.rs:153:16
    |
153 |     fn to_bits(&self) -> u8 {
    |                ^^^^^
    |
    = help: consider choosing a less ambiguous name
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention

warning: the loop variable `i` is used to index `output`
Warning:    --> src/mac/frame/security/mod.rs:306:14
    |
306 |     for i in 0..8 {
    |              ^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
help: consider using an iterator
    |
306 |     for (i, <item>) in output.iter_mut().enumerate().take(8) {
    |         ~~~~~~~~~~~    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

warning: this lifetime isn't used in the function definition
Warning:    --> src/mac/frame/security/mod.rs:329:28
    |
329 | pub(crate) fn secure_frame<'a, AEADBLKCIPH, KEYDESCLO>(
    |                            ^^
    |
    = note: `#[warn(clippy::extra_unused_lifetimes)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes

warning: this boolean expression can be simplified
Warning:    --> src/mac/frame/security/mod.rs:371:16
    |
371 |               if !(frame.payload.len()
    |  ________________^
372 | |                 + frame.header.get_octet_size()
373 | |                 + aux_len
374 | |                 + auth_len
375 | |                 + 2
376 | |                 <= 127)
    | |_______________________^
    |
    = note: `#[warn(clippy::nonminimal_bool)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
help: try
    |
371 ~             if frame.payload.len()
372 +                 + frame.header.get_octet_size()
373 +                 + aux_len
374 +                 + auth_len
375 +                 + 2 > 127
    |

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:485:17
    |
485 |                 return Ok(offset);
    |                 ^^^^^^^^^^^^^^^^^^ help: remove `return`: `Ok(offset)`
    |
    = note: `#[warn(clippy::needless_return)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:487:17
    |
487 |                 return Err(SecurityError::UnavailableKey);
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `Err(SecurityError::UnavailableKey)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:490:13
    |
490 |             return Err(SecurityError::AuxSecHeaderAbsent);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `Err(SecurityError::AuxSecHeaderAbsent)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:493:9
    |
493 |         return Err(SecurityError::SecurityNotEnabled);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `Err(SecurityError::SecurityNotEnabled)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: casting integer literal to `usize` is unnecessary
Warning:    --> src/mac/frame/security/mod.rs:350:22
    |
350 |     let mut offset = 0 as usize;
    |                      ^^^^^^^^^^ help: try: `0_usize`
    |
    = note: `#[warn(clippy::unnecessary_cast)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast

warning: the method `encrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:435:33
    |
435 |                                   &mut [],
    |                                   ^^^^^^^
...
462 | /                         do_secure!(
463 | |                             U4,
464 | |                             SecurityLevel::MIC32,
465 | |                             SecurityLevel::ENCMIC32
466 | |                         );
    | |__________________________- in this macro invocation
    |
    = note: `#[warn(clippy::unnecessary_mut_passed)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_secure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: the method `encrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:435:33
    |
435 |                                   &mut [],
    |                                   ^^^^^^^
...
469 | /                         do_secure!(
470 | |                             U8,
471 | |                             SecurityLevel::MIC64,
472 | |                             SecurityLevel::ENCMIC64
473 | |                         );
    | |__________________________- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_secure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: the method `encrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:435:33
    |
435 |                                   &mut [],
    |                                   ^^^^^^^
...
476 | /                         do_secure!(
477 | |                             CcmU16,
478 | |                             SecurityLevel::MIC128,
479 | |                             SecurityLevel::ENCMIC128
480 | |                         );
    | |__________________________- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_secure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: this lifetime isn't used in the function definition
Warning:    --> src/mac/frame/security/mod.rs:513:30
    |
513 | pub(crate) fn unsecure_frame<'a, AEADBLKCIPH, KEYDESCLO, DEVDESCLO>(
    |                              ^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:673:9
    |
673 |         return Ok(taglen);
    |         ^^^^^^^^^^^^^^^^^^ help: remove `return`: `Ok(taglen)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: unneeded `return` statement
Warning:    --> src/mac/frame/security/mod.rs:675:9
    |
675 |         return Err(SecurityError::SecurityNotEnabled);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `Err(SecurityError::SecurityNotEnabled)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return

warning: the method `decrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:621:37
    |
621 |   ...                           &mut [],
    |                                 ^^^^^^^
...
644 | / ...                   do_unsecure!(
645 | | ...                       U4,
646 | | ...                       SecurityLevel::MIC32,
647 | | ...                       SecurityLevel::ENCMIC32
648 | | ...                   );
    | |________________________- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_unsecure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: the method `decrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:621:37
    |
621 |   ...                           &mut [],
    |                                 ^^^^^^^
...
651 | / ...                   do_unsecure!(
652 | | ...                       U8,
653 | | ...                       SecurityLevel::MIC64,
654 | | ...                       SecurityLevel::ENCMIC64
655 | | ...                   );
    | |________________________- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_unsecure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: the method `decrypt_in_place_detached` doesn't need a mutable reference
Warning:    --> src/mac/frame/security/mod.rs:621:37
    |
621 |   ...                           &mut [],
    |                                 ^^^^^^^
...
658 | / ...                   do_unsecure!(
659 | | ...                       U16,
660 | | ...                       SecurityLevel::MIC128,
661 | | ...                       SecurityLevel::ENCMIC128
662 | | ...                   );
    | |________________________- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
    = note: this warning originates in the macro `do_unsecure` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: returning an `Err(_)` with the `?` operator
Warning:    --> src/mac/frame/mod.rs:252:33
    |
252 |                     _ => return Err(e)?,
    |                                 ^^^^^^^ help: try this: `Err(e.into())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: returning an `Err(_)` with the `?` operator
Warning:    --> src/mac/frame/mod.rs:346:20
    |
346 |             return Err(DecodeError::SecurityEnabled)?;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `Err(DecodeError::SecurityEnabled.into())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err

warning: `ieee802154` (lib) generated 54 warnings
Warning:     Finished dev [unoptimized + debuginfo] target(s) in 53.51s

Supporting security on MAC layer with current `byte::TryRead` interface is not possible.

I'm implementing the security features specified by the 802.15.4 standard for this crate. Implementing the procedures by themselves and encrypting outgoing frames is working as expected, but I've run into a bit of a roadblock when it comes to decrypting incoming frames using the current interface. You can find the progress here.

Because byte::TryRead::try_read only takes an immutable buffer, we can't perform in-place unsecuring of the payload, and because it is a reference in Frame, we can't create a copy of the secured data, unsecure it, and reassign the payload (which would be rather undesirable anyways for performance reasons).

In my solution, I've implemented Frame::try_read_with_unsecure that takes an &mut [u8] instead. It works fine, but doesn't fit into the currently used interface (since it expects a &mut [u8] for reading) here.

I'm not sure if there is a better way to do this, or what kind of redesign it would require to remake this.

Is panicking when the buffer is too small the best approach?

Currently, the encoding code panics, if the buffer provided is not large enough. I believe there are two reasons to justify this:

  • There are no other error conditions, so adding an error for this would place an additional burden on the caller.
  • Providing a buffer that is too small is a developer error that can't be handled at runtime.

However, I'm not sure if the second one holds. There may be cases where the size of the frame is only known at runtime, or where multiple frames are written to the same buffer, until there is no more room, or whatever else one might imagine. Feedback welcome!

Encoded frame cannot be decoded

If a frame with a header that has the the pan_id_compress flag set and a destination address set to None is encoded, the resulting frame data cannot be decoded.

For example:

let mut frame_data = [0u8; 127];

let frame = Frame {
    header: Header {
        frame_type: FrameType::Data,
        version: FrameVersion::Ieee802154_2006,
        frame_pending: false,
        ack_request: false,
        pan_id_compress: true,
        destination: None,
        source: Some(Address::Extended(
            PanId(0xABCD),
            ExtendedAddress(0xFF),
        )),
        seq: 1,
        seq_no_suppress: false,
        ie_present: false,
        auxiliary_security_header: None,
    },
    content: FrameContent::Data,
    payload: &[],
    footer: [0; 2],
};

let frame_len = frame
    .try_write(
        &mut frame_data,
        &mut FrameSerDesContext::no_security(FooterMode::None),
    )
    .unwrap();

let frame = Frame::try_read(&frame_data[..frame_len], FooterMode::None)
    .unwrap();

Crashes on the second unwrap. I would sooner expect the encode step to return an Err, as that's where the "error" is introduced, since we're effectively allowed to encode an invalid frame.

Add stable channel to Travis configuration

I've created this crate with the edition = 2018 option in Cargo.toml. Since Rust 2018 is not released yet on stable, this means this crate doesn't support stable until the next stable Rust version is released.

Once that has happened, add the stable channel to the Travis CI configuration.

Fix rendering of README on crates.io

The second-to-last line of the README doesn't render on crates.io. I suspect this is due to the <br /> tag, and might be fixed by adding a space before it.

Not urgent, but should be handled with the next release.

`try_read` produce error for at least Acknowledge frames

I decided to upgrade my ieee802154 dependency from 0.3 to 0.6.1.
But I kept getting byte::Error::Incomplete when using data.read_with::<Frame>(&mut 0, FooterMode::None). A sample of data is &[0x02, 0x00, 0x04] which is an Acknowledge frame with sequence number four. The problem in Frame::try_read is that when the Header has been read the offset is the same as bytes.len() the FrameContent read_with will always fail. This because read_with checks if the offset is equal to or larger than the slice length.

My current fix is a bit of a kludge but works for me,

--- a/src/mac/frame/mod.rs
+++ b/src/mac/frame/mod.rs
@@ -340,22 +340,39 @@ impl<'a> TryRead<'a, FooterMode> for Frame<'a> {
     ) -> byte::Result<(Self, usize)> {
         let offset = &mut 0;
         let header: Header = bytes.read(offset)?;
-        let content = bytes.read_with(offset, &header)?;
+        let bytes_left = bytes.len() - *offset;
+        let content = if bytes_left == 0 {
+            match header.frame_type {
+                FrameType::Data => FrameContent::Data,
+                FrameType::Acknowledgement => FrameContent::Acknowledgement,
+                FrameType::Multipurpose => FrameContent::Multipurpose,
+                FrameType::FragOrFragAck => FrameContent::FragOrFragAck,
+                FrameType::Extended => FrameContent::Extended,
+                FrameType::Beacon | FrameType::MacCommand => {
+                    return Err(byte::Error::Incomplete);
+                }
+            }
+        } else {
+            bytes.read_with(offset, &header)?
+        };
 
         if header.has_security() {
             return Err(DecodeError::SecurityEnabled)?;
         }
-
-        let (payload, footer) = match mode {
-            FooterMode::None => (
-                bytes.read_with(offset, Bytes::Len(bytes.len() - *offset))?,
-                0u16,
-            ),
-            FooterMode::Explicit => (
-                bytes
-                    .read_with(offset, Bytes::Len(bytes.len() - *offset - 2))?,
-                bytes.read_with(offset, LE)?,
-            ),
+        let bytes_left = bytes.len() - *offset;
+        let (payload, footer) = if bytes_left == 0 {
+            let end = bytes.len() - 1;
+            (&bytes[end..end], 0)
+        } else {
+            match mode {
+                FooterMode::None => {
+                    (bytes.read_with(offset, Bytes::Len(bytes_left))?, 0u16)
+                }
+                FooterMode::Explicit => (
+                    bytes.read_with(offset, Bytes::Len(bytes_left - 2))?,
+                    bytes.read_with(offset, LE)?,
+                ),
+            }
         };
 
         let frame = Frame {

Transferring this repository to Rust IoT

I've decided to transfer this repository to Rust IoT, who have offered to maintain it. This issue exists to document that this transfer is happening, provide a place to discuss it, and a place to ping anyone who might be interested.

Since I haven't used this library in a long time, and what little IEEE 802.15.4 knowledge I had has degraded in the years since, I'm happy to retire as a maintainer, and have a group with a more active interest take over.

cc @henrikssn and @ryankurte of Rust IoT, who I've been discussing this with on Rust IoT's Matrix channel.

cc @blueluna and @jamesmunns, who have write access to this repository, but haven't been active in a long time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.