| 303 | } |
| 304 | |
| 305 | pub async fn handle_uplink( |
| 306 | region_common_name: CommonName, |
| 307 | region_config_id: &str, |
| 308 | deduplication_id: Uuid, |
| 309 | uplink: gw::UplinkFrameSet, |
| 310 | ) -> Result<()> { |
| 311 | let mut uplink = UplinkFrameSet { |
| 312 | uplink_set_id: deduplication_id, |
| 313 | region_common_name, |
| 314 | region_config_id: region_config_id.to_string(), |
| 315 | dr: 0, |
| 316 | ch: 0, |
| 317 | phy_payload: PhyPayload::from_slice(&uplink.phy_payload)?, |
| 318 | tx_info: uplink.tx_info.context("tx_info must not be None")?, |
| 319 | rx_info_set: uplink.rx_info, |
| 320 | gateway_private_up_map: HashMap::new(), |
| 321 | gateway_private_down_map: HashMap::new(), |
| 322 | gateway_tenant_id_map: HashMap::new(), |
| 323 | gateway_downlink_priority_map: HashMap::new(), |
| 324 | roaming_meta_data: None, |
| 325 | }; |
| 326 | |
| 327 | UPLINK_COUNTER |
| 328 | .get_or_create(&UplinkLabels { |
| 329 | f_type: uplink.phy_payload.mhdr.f_type.to_string(), |
| 330 | }) |
| 331 | .inc(); |
| 332 | |
| 333 | uplink.dr = helpers::get_uplink_dr(&uplink.region_config_id, &uplink.tx_info)?; |
| 334 | uplink.ch = helpers::get_uplink_ch( |
| 335 | &uplink.region_config_id, |
| 336 | uplink.tx_info.frequency, |
| 337 | uplink.dr, |
| 338 | )?; |
| 339 | |
| 340 | info!( |
| 341 | f_type = %uplink.phy_payload.mhdr.f_type, |
| 342 | "Uplink received" |
| 343 | ); |
| 344 | |
| 345 | debug!("Updating gateway meta-data for uplink frame-set"); |
| 346 | update_gateway_metadata(&mut uplink) |
| 347 | .await |
| 348 | .context("Update gateway meta-data")?; |
| 349 | |
| 350 | debug!("Logging uplink frame to Redis Stream"); |
| 351 | let ufl: stream_pb::UplinkFrameLog = (&uplink).try_into()?; |
| 352 | stream::frame::log_uplink_for_gateways(&ufl) |
| 353 | .await |
| 354 | .context("Log uplink for gateways")?; |
| 355 | |
| 356 | match uplink.phy_payload.mhdr.f_type { |
| 357 | FType::JoinRequest => join::JoinRequest::handle(uplink).await, |
| 358 | FType::UnconfirmedDataUp | FType::ConfirmedDataUp => data::Data::handle(uplink).await, |
| 359 | _ => { |
| 360 | return Err(anyhow!( |
| 361 | "Unexpected f_type: {}", |
| 362 | uplink.phy_payload.mhdr.f_type |