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

Method _update_uplink_list

chirpstack/src/downlink/data.rs:1551–1715  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1549 }
1550
1551 async fn _update_uplink_list(&mut self) -> Result<()> {
1552 trace!("Updating Relay uplink list");
1553
1554 let dev_eui = self.device.dev_eui;
1555 let ds = self.device.get_device_session_mut()?;
1556
1557 if ds.relay.is_none() {
1558 ds.relay = Some(internal::Relay::default());
1559 }
1560
1561 // Get a copy of the current relay state.
1562 let relay = ds.relay.as_ref().unwrap().clone();
1563
1564 // Get devices that must be configured on the relay.
1565 let relay_devices = relay::list_devices(
1566 15,
1567 0,
1568 &relay::DeviceFilters {
1569 relay_dev_eui: Some(dev_eui),
1570 },
1571 )
1572 .await?;
1573
1574 // Calculate unused slots.
1575 let used_slots: Vec<u32> = relay.devices.iter().map(|d| d.index).collect();
1576 let free_slots: Vec<u32> = (0..15).filter(|x| !used_slots.contains(x)).collect();
1577
1578 // Iterate over the list of devices under this relay.
1579 for device in &relay_devices {
1580 // We need a dev_addr for the filter. Ignore devices that do not have a DevAddr (e.g.
1581 // they have never been activated).
1582 if let Some(dev_addr) = device.dev_addr {
1583 let mut found = false;
1584
1585 for rd in &mut ds.relay.as_mut().unwrap().devices {
1586 if rd.dev_eui == device.dev_eui.to_vec() {
1587 found = true;
1588
1589 // The device has not yet been provisioned, or
1590 // the settings must be updated
1591 if !rd.provisioned
1592 || rd.dev_addr != dev_addr.to_vec()
1593 || rd.uplink_limit_bucket_size
1594 != device.relay_ed_uplink_limit_bucket_size as u32
1595 || rd.uplink_limit_reload_rate
1596 != device.relay_ed_uplink_limit_reload_rate as u32
1597 {
1598 let mut d = device::get(&device.dev_eui).await?;
1599 let ds = match d.get_device_session_mut() {
1600 Ok(v) => v,
1601 Err(_) => {
1602 // It is valid that the device is no longer activated.
1603 continue;
1604 }
1605 };
1606 let root_wor_s_key = keys::get_root_wor_s_key(&AES128Key::from_slice(
1607 &ds.nwk_s_enc_key,
1608 )?)?;

Callers 2

set_mac_commandsMethod · 0.80
test_update_uplink_listFunction · 0.80

Calls 13

get_root_wor_s_keyFunction · 0.85
unwrapMethod · 0.80
as_refMethod · 0.80
iterMethod · 0.80
containsMethod · 0.80
pushMethod · 0.80
get_device_sessionMethod · 0.80
list_devicesFunction · 0.50
getFunction · 0.50
partial_updateFunction · 0.50
to_vecMethod · 0.45

Tested by 1

test_update_uplink_listFunction · 0.64