pub struct DataPayloadCreator<D, F> { /* private fields */ }
Expand description

DataPayloadCreator serves for creating binary representation of Physical Payload of DataUp or DataDown messages.

Example

let mut phy = lorawan::creator::DataPayloadCreator::new();
let nwk_skey = lorawan::keys::NewSKey::from([2; 16]);
let app_skey = lorawan::keys::AppSKey::from([1; 16]);
phy.set_confirmed(true)
    .set_uplink(true)
    .set_f_port(42)
    .set_dev_addr(&[4, 3, 2, 1])
    .set_fctrl(&lorawan::parser::FCtrl::new(0x80, true)) // ADR: true, all others: false
    .set_fcnt(76543);
phy.build(b"hello lora", &[], &nwk_skey, &app_skey).unwrap();

Implementations§

source§

impl<D: AsMut<[u8]>, F: CryptoFactory + Default> DataPayloadCreator<D, F>

source

pub fn with_options(data: D, factory: F) -> Result<Self, Error>

Creates a well initialized DataPayloadCreator with specific crypto functions.

By default the packet is unconfirmed data up packet.

Sets whether the packet is uplink or downlink.

Argument
  • uplink - whether the packet is uplink or downlink.
source

pub fn set_confirmed(&mut self, confirmed: bool) -> &mut Self

Sets whether the packet is confirmed or unconfirmed.

Argument
  • confirmed - whether the packet is confirmed or unconfirmed.
source

pub fn set_dev_addr<H: AsRef<[u8]>, T: Into<DevAddr<H>>>( &mut self, dev_addr: T ) -> &mut Self

Sets the device address of the DataPayload to the provided value.

Argument
  • dev_addr - instance of lorawan::parser::DevAddr or anything that can be converted into it.
source

pub fn set_fctrl(&mut self, fctrl: &FCtrl) -> &mut Self

Sets the FCtrl header of the DataPayload packet to the specified value.

Argument
  • fctrl - the FCtrl to be set.
source

pub fn set_fcnt(&mut self, fcnt: u32) -> &mut Self

Sets the FCnt header of the DataPayload packet to the specified value.

NOTE: In the packet header the value will be truncated to u16.

Argument
  • fctrl - the FCtrl to be set.
source

pub fn set_f_port(&mut self, f_port: u8) -> &mut Self

Sets the FPort header of the DataPayload packet to the specified value.

If f_port == 0, automatically sets encrypt_mac_commands to true.

Argument
  • f_port - the FPort to be set.
source

pub fn can_piggyback(cmds: &[&dyn SerializableMacCommand]) -> bool

Whether a set of mac commands can be piggybacked.

source

pub fn build( &mut self, payload: &[u8], cmds: &[&dyn SerializableMacCommand], nwk_skey: &NewSKey, app_skey: &AppSKey ) -> Result<&[u8], Error>

Provides the binary representation of the DataPayload physical payload with the MIC set and payload encrypted.

Argument
  • payload - the FRMPayload (application) to be sent.
  • nwk_skey - the key to be used for setting the MIC and possibly for MAC command encryption.
  • app_skey - the key to be used for payload encryption if fport not 0, otherwise nwk_skey is only used.
Example
let mut phy = lorawan::creator::DataPayloadCreator::new();
let mac_cmd1 = lorawan::maccommands::UplinkMacCommand::LinkCheckReq(
    lorawan::maccommands::LinkCheckReqPayload());
let mut mac_cmd2 = lorawan::maccommandcreator::LinkADRAnsCreator::new();
mac_cmd2
    .set_channel_mask_ack(true)
    .set_data_rate_ack(false)
    .set_tx_power_ack(true);
let mut cmds: Vec<&dyn lorawan::maccommands::SerializableMacCommand> = Vec::new();
cmds.push(&mac_cmd1);
cmds.push(&mac_cmd2);
let nwk_skey = lorawan::keys::NewSKey::from([2; 16]);
let app_skey = lorawan::keys::AppSKey::from([1; 16]);
phy.build(&[], &cmds, &nwk_skey, &app_skey).unwrap();
source§

impl DataPayloadCreator<GenericArray<u8, U256>, DefaultFactory>

source

pub fn new() -> Self

Creates a well initialized DataPayloadCreator.

By default the packet is unconfirmed data up packet.

Examples
let mut phy = lorawan::creator::DataPayloadCreator::new();
let nwk_skey = lorawan::keys::NewSKey::from([2; 16]);
let app_skey = lorawan::keys::AppSKey::from([1; 16]);
let fctrl = lorawan::parser::FCtrl::new(0x80, true);
phy.set_confirmed(false).
    set_uplink(true).
    set_f_port(1).
    set_dev_addr(&[4, 3, 2, 1]).
    set_fctrl(&fctrl). // ADR: true, all others: false
    set_fcnt(1);
let payload = phy.build(b"hello", &[], &nwk_skey, &app_skey).unwrap();

Trait Implementations§

source§

impl<D: Default, F: Default> Default for DataPayloadCreator<D, F>

source§

fn default() -> DataPayloadCreator<D, F>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D, F> RefUnwindSafe for DataPayloadCreator<D, F>

§

impl<D, F> Send for DataPayloadCreator<D, F>
where D: Send, F: Send,

§

impl<D, F> Sync for DataPayloadCreator<D, F>
where D: Sync, F: Sync,

§

impl<D, F> Unpin for DataPayloadCreator<D, F>
where D: Unpin, F: Unpin,

§

impl<D, F> UnwindSafe for DataPayloadCreator<D, F>
where D: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.