MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / construct_join_accept_and_set_keys

Method construct_join_accept_and_set_keys

chirpstack/src/uplink/join.rs:619–758  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

617 }
618
619 fn construct_join_accept_and_set_keys(&mut self) -> Result<()> {
620 trace!("Constructing JoinAccept payload");
621
622 let conf = config::get();
623 let region_network = config::get_region_network(&self.uplink_frame_set.region_config_id)?;
624 let region_conf = region::get(&self.uplink_frame_set.region_config_id)?;
625 let join_request = self.join_request.as_ref().unwrap();
626
627 let d = self.device.as_ref().unwrap();
628 let dk = self.device_keys.as_mut().unwrap();
629
630 let join_nonce = dk.join_nonce - 1; // this was incremented on validation
631 if join_nonce == (1 << 24) - 1 {
632 return Err(anyhow!("Join-nonce overflow"));
633 }
634
635 // The opt_neg flag is set for devices other than 1.0.x.
636 let opt_neg = !self
637 .device_profile
638 .as_ref()
639 .unwrap()
640 .mac_version
641 .to_string()
642 .starts_with("1.0");
643
644 let mut phy = PhyPayload {
645 mhdr: MHDR {
646 f_type: FType::JoinAccept,
647 major: Major::LoRaWANR1,
648 },
649 payload: Payload::JoinAccept(JoinAcceptPayload {
650 join_nonce: join_nonce as u32,
651 home_netid: conf.network.net_id,
652 devaddr: d.dev_addr.unwrap(),
653 dl_settings: DLSettings {
654 opt_neg,
655 rx2_dr: region_network.rx2_dr,
656 rx1_dr_offset: region_network.rx1_dr_offset,
657 },
658 rx_delay: region_network.rx1_delay,
659 cflist: region_conf.get_cf_list(self.device_profile.as_ref().unwrap().mac_version),
660 }),
661 mic: None, // we need to calculate this
662 };
663
664 if opt_neg {
665 let js_int_key = keys::get_js_int_key(&join_request.dev_eui, &dk.nwk_key)?;
666 phy.set_join_accept_mic(
667 JoinType::Join,
668 &join_request.join_eui,
669 join_request.dev_nonce,
670 &js_int_key,
671 )?;
672 } else {
673 phy.set_join_accept_mic(
674 JoinType::Join,
675 &join_request.join_eui,
676 join_request.dev_nonce,

Callers 2

_handleMethod · 0.45
_handle_relayedMethod · 0.45

Calls 15

get_region_networkFunction · 0.85
JoinAcceptClass · 0.85
get_js_int_keyFunction · 0.85
get_f_nwk_s_int_keyFunction · 0.85
get_s_nwk_s_int_keyFunction · 0.85
get_nwk_s_enc_keyFunction · 0.85
get_app_s_keyFunction · 0.85
unwrapMethod · 0.80
as_refMethod · 0.80
to_stringMethod · 0.80
set_join_accept_micMethod · 0.80

Tested by

no test coverage detected