| 296 | } |
| 297 | |
| 298 | async fn validate_mic(&self) -> Result<()> { |
| 299 | let device_keys = self.device_keys.as_ref().unwrap(); |
| 300 | |
| 301 | if self |
| 302 | .uplink_frame_set |
| 303 | .phy_payload |
| 304 | .validate_join_request_mic(&device_keys.nwk_key)? |
| 305 | { |
| 306 | return Ok(()); |
| 307 | } |
| 308 | |
| 309 | let app = self.application.as_ref().unwrap(); |
| 310 | let dev = self.device.as_ref().unwrap(); |
| 311 | |
| 312 | integration::log_event( |
| 313 | app.id.into(), |
| 314 | &dev.variables, |
| 315 | &integration_pb::LogEvent { |
| 316 | time: Some(Utc::now().into()), |
| 317 | device_info: self.device_info.clone(), |
| 318 | level: integration_pb::LogLevel::Error.into(), |
| 319 | code: integration_pb::LogCode::UplinkMic.into(), |
| 320 | description: "MIC of join-request is invalid, make sure keys are correct".into(), |
| 321 | context: [( |
| 322 | "deduplication_id".to_string(), |
| 323 | self.uplink_frame_set.uplink_set_id.to_string(), |
| 324 | )] |
| 325 | .iter() |
| 326 | .cloned() |
| 327 | .collect(), |
| 328 | }, |
| 329 | ) |
| 330 | .await; |
| 331 | |
| 332 | metrics::save( |
| 333 | &format!("device:{}", dev.dev_eui), |
| 334 | &metrics::Record { |
| 335 | time: Local::now(), |
| 336 | kind: metrics::Kind::ABSOLUTE, |
| 337 | metrics: [("error_UPLINK_MIC".into(), 1f64)] |
| 338 | .iter() |
| 339 | .cloned() |
| 340 | .collect(), |
| 341 | }, |
| 342 | &metrics::Aggregation::default_aggregations(), |
| 343 | ) |
| 344 | .await?; |
| 345 | |
| 346 | Err(anyhow!("Invalid MIC")) |
| 347 | } |
| 348 | |
| 349 | async fn validate_dev_nonce_and_get_device_keys(&mut self) -> Result<()> { |
| 350 | trace!("Validate dev-nonce and get device-keys"); |