From f9efed2317a6f244287048044e51b3791f44f162 Mon Sep 17 00:00:00 2001
From: Orne Brocaar <info@brocaar.com>
Date: Mon, 17 Feb 2025 09:40:22 +0000
Subject: [PATCH] Rename ts00x_port to _f_port.

This is consistent with the naming in the lrwn package.
---
 chirpstack/src/api/device_profile.rs          | 11 ++++++
 .../src/storage/fields/device_profile.rs      | 34 +++++++++++++++++--
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/chirpstack/src/api/device_profile.rs b/chirpstack/src/api/device_profile.rs
index da94fe59..41942b3f 100644
--- a/chirpstack/src/api/device_profile.rs
+++ b/chirpstack/src/api/device_profile.rs
@@ -147,6 +147,7 @@ impl DeviceProfileService for DeviceProfile {
                     ts003_version: app_layer_params.ts003_version().from_proto(),
                     ts004_version: app_layer_params.ts004_version().from_proto(),
                     ts005_version: app_layer_params.ts005_version().from_proto(),
+                    ..Default::default()
                 }
             },
             ..Default::default()
@@ -392,6 +393,16 @@ impl DeviceProfileService for DeviceProfile {
             } else {
                 None
             },
+            app_layer_params: {
+                let app_layer_params = req_dp.app_layer_params.unwrap_or_default();
+
+                fields::AppLayerParams {
+                    ts003_version: app_layer_params.ts003_version().from_proto(),
+                    ts004_version: app_layer_params.ts004_version().from_proto(),
+                    ts005_version: app_layer_params.ts005_version().from_proto(),
+                    ..Default::default()
+                }
+            },
             ..Default::default()
         })
         .await
diff --git a/chirpstack/src/storage/fields/device_profile.rs b/chirpstack/src/storage/fields/device_profile.rs
index 65dc0ca2..d91e03cf 100644
--- a/chirpstack/src/storage/fields/device_profile.rs
+++ b/chirpstack/src/storage/fields/device_profile.rs
@@ -235,15 +235,43 @@ mod ed_activation_mode {
     }
 }
 
-#[derive(
-    Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize, AsExpression, FromSqlRow,
-)]
+#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, AsExpression, FromSqlRow)]
 #[cfg_attr(feature = "postgres", diesel(sql_type = Jsonb))]
 #[cfg_attr(feature = "sqlite", diesel(sql_type = Text))]
+#[serde(default)]
 pub struct AppLayerParams {
     pub ts003_version: Option<Ts003Version>,
     pub ts004_version: Option<Ts004Version>,
     pub ts005_version: Option<Ts005Version>,
+    pub ts003_f_port: u8,
+    pub ts004_f_port: u8,
+    pub ts005_f_port: u8,
+}
+
+impl Default for AppLayerParams {
+    fn default() -> Self {
+        Self {
+            ts003_version: None,
+            ts004_version: None,
+            ts005_version: None,
+            ts003_f_port: 202,
+            ts004_f_port: 201,
+            ts005_f_port: 200,
+        }
+    }
+}
+
+impl AppLayerParams {
+    pub fn is_app_layer_f_port(&self, f_port: u8) -> bool {
+        if (self.ts003_version.is_some() && self.ts003_f_port == f_port)
+            || (self.ts004_version.is_some() && self.ts004_f_port == f_port)
+            || (self.ts005_version.is_some() && self.ts005_f_port == f_port)
+        {
+            true
+        } else {
+            false
+        }
+    }
 }
 
 #[cfg(feature = "postgres")]