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

Function get_for_phy_payload

chirpstack/src/storage/passive_roaming.rs:119–168  ·  view source on GitHub ↗
(
    phy: &lrwn::PhyPayload,
)

Source from the content-addressed store, hash-verified

117}
118
119pub async fn get_for_phy_payload(
120 phy: &lrwn::PhyPayload,
121) -> Result<Vec<internal::PassiveRoamingDeviceSession>, Error> {
122 // Clone the PhyPayload, as we will update the f_cnt to the full (32bit) frame-counter value
123 // for calculating the MIC.
124 let mut phy = phy.clone();
125
126 let (dev_addr, f_cnt_orig) = if let lrwn::Payload::MACPayload(v) = &phy.payload {
127 (v.fhdr.devaddr, v.fhdr.f_cnt)
128 } else {
129 return Err(Error::InvalidPayload("MacPayload".to_string()));
130 };
131
132 let sessions = get_sessions_for_dev_addr(dev_addr).await?;
133 let mut out: Vec<internal::PassiveRoamingDeviceSession> = Vec::new();
134
135 for ds in sessions {
136 // We will not validate the MIC.
137 if !ds.validate_mic {
138 out.push(ds);
139 continue;
140 }
141
142 let f_nwk_s_int_key = AES128Key::from_slice(&ds.f_nwk_s_int_key)?;
143
144 // Set the full frame-counter.
145 if let lrwn::Payload::MACPayload(pl) = &mut phy.payload {
146 pl.fhdr.f_cnt = get_full_f_cnt_up(ds.f_cnt_up, f_cnt_orig);
147 }
148
149 let mic_ok = if ds.lorawan_1_1 {
150 phy.validate_uplink_data_micf(&f_nwk_s_int_key)?
151 } else {
152 phy.validate_uplink_data_mic(
153 lrwn::MACVersion::LoRaWAN1_0,
154 0,
155 0,
156 0,
157 &f_nwk_s_int_key,
158 &f_nwk_s_int_key,
159 )?
160 };
161
162 if mic_ok {
163 out.push(ds);
164 }
165 }
166
167 Ok(out)
168}
169
170async fn get_sessions_for_dev_addr(
171 dev_addr: DevAddr,

Callers 1

Calls 6

to_stringMethod · 0.80
pushMethod · 0.80
get_full_f_cnt_upFunction · 0.70

Tested by

no test coverage detected