[][src]Struct lorawan::creator::DataPayloadCreator

pub struct DataPayloadCreator<D, F> { /* fields omitted */ }

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::AES128([2; 16]);
let app_skey = lorawan::keys::AES128([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

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

pub fn with_options<'a>(data: D, factory: F) -> Result<Self, &'a str>[src]

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.

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

Sets whether the packet is confirmed or unconfirmed.

Argument

  • confirmed - whether the packet is confirmed or unconfirmed.

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

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.

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

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

Argument

  • fctrl - the FCtrl to be set.

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

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.

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

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.

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

Whether a set of mac commands can be piggybacked.

pub fn build<'a, 'b, 'c, 'd, 'e>(
    &mut self,
    payload: &[u8],
    cmds: &'a [&'b dyn SerializableMacCommand],
    nwk_skey: &'c AES128,
    app_skey: &'d AES128
) -> Result<&[u8], &'e str>
[src]

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::MacCommand::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::AES128([2; 16]);
let app_skey = lorawan::keys::AES128([1; 16]);
phy.build(&[], &cmds[..], &nwk_skey, &app_skey).unwrap();

impl DataPayloadCreator<GenericArray<u8, U256>, DefaultFactory>[src]

pub fn new() -> Self[src]

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::AES128([2; 16]);
let app_skey = lorawan::keys::AES128([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

impl<D: Default, F: Default> Default for DataPayloadCreator<D, F>[src]

Auto Trait Implementations

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.