Fix device activation not setting the device class for LoRaWAN 1.0 on ABP. (#344)

This commit is contained in:
Liu Woon Yung 2024-01-11 20:39:15 +08:00 committed by GitHub
parent f248379259
commit 3b7ab175b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,8 @@ use super::error::ToStatus;
use super::helpers::{self, FromProto, ToProto};
use crate::storage::error::Error;
use crate::storage::{
device, device_keys, device_profile, device_queue, device_session, fields, metrics,
device::{self, DeviceClass},
device_keys, device_profile, device_queue, device_session, fields, metrics,
};
use crate::{codec, devaddr::get_random_dev_addr};
@ -538,6 +539,17 @@ impl DeviceService for Device {
.map_err(|e| e.status())?;
}
// LoRaWAN 1.1 devices send a mac-command when changing to Class-C. Change the class here for LoRaWAN 1.0 devices.
if dp.supports_class_c && dp.mac_version.to_string().starts_with("1.0") {
let _ = device::set_enabled_class(&dev_eui, DeviceClass::C)
.await
.map_err(|e| e.status())?;
} else {
let _ = device::set_enabled_class(&dev_eui, DeviceClass::A)
.await
.map_err(|e| e.status())?;
}
let mut resp = Response::new(());
resp.metadata_mut()
.insert("x-log-dev_eui", req_da.dev_eui.parse().unwrap());