summaryrefslogtreecommitdiff
path: root/fw/app/src/syslog.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-04-15 17:14:06 +0200
committerxengineering <me@xengineering.eu>2025-04-15 18:00:03 +0200
commit698832f42c11d1df2b955de37b6b130c980dadce (patch)
tree02397e0aa07ceafc27adb84a6c0b15a5b4f24fea /fw/app/src/syslog.c
parent4e0f0849d6e7997cbc128d998ba824d6ac3e7181 (diff)
downloadiot-contact-698832f42c11d1df2b955de37b6b130c980dadce.tar
iot-contact-698832f42c11d1df2b955de37b6b130c980dadce.tar.zst
iot-contact-698832f42c11d1df2b955de37b6b130c980dadce.zip
fw: app: syslog: Make target IP configurable
Diffstat (limited to 'fw/app/src/syslog.c')
-rw-r--r--fw/app/src/syslog.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/fw/app/src/syslog.c b/fw/app/src/syslog.c
index e19a196..6dc0bd6 100644
--- a/fw/app/src/syslog.c
+++ b/fw/app/src/syslog.c
@@ -4,8 +4,10 @@
* obtain one at https://mozilla.org/MPL/2.0/.
*/
+#include <errno.h>
#include <stdbool.h>
+#include <string.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
@@ -14,6 +16,8 @@
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/logging/log_core.h>
#include <zephyr/net/conn_mgr_connectivity.h>
+#include <zephyr/settings/settings.h>
+#include <zephyr/sys/util.h>
#ifdef CONFIG_IOT_CONTACT_NETWORK_HACK
#include <zephyr/sys/reboot.h>
@@ -23,9 +27,11 @@ LOG_MODULE_REGISTER(syslog);
#define NETWORK_BUG_DELAY K_MSEC(4000)
#define L4_EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
+#define IPV6_STRLEN_MAX 40 // including '\0'
struct net_mgmt_event_callback l4_cb;
static K_SEM_DEFINE(network_connected, 0, 1);
+static char target_ip[IPV6_STRLEN_MAX] = CONFIG_LOG_BACKEND_NET_SERVER;
void l4_event_handler(
struct net_mgmt_event_callback *cb,
@@ -79,6 +85,10 @@ int init_syslog(void)
/* flush log messages to ensure first syslog message is reproducible */
while (log_process());
log_backend_init(backend);
+ LOG_INF("Setting syslog target to: '%s'", target_ip);
+ if (log_backend_net_set_addr(target_ip) == false) {
+ LOG_ERR("Could not set target IP to '%s'", target_ip);
+ }
log_backend_enable(backend, backend->cb->ctx, CONFIG_LOG_MAX_LEVEL);
LOG_INF("Syslog backend enabled");
} else {
@@ -88,3 +98,50 @@ int init_syslog(void)
return 0;
}
SYS_INIT(init_syslog, APPLICATION, 50);
+
+int syslog_handle_set(const char *name, size_t len, settings_read_cb read_cb,
+ void *cb_arg)
+{
+ const char* next = NULL;
+
+ if (settings_name_steq(name, "target/ip", &next) && !next) {
+ memset(target_ip, '\0', sizeof(target_ip));
+ ssize_t ret = read_cb(cb_arg, target_ip, MIN(sizeof(target_ip) - 1, len));
+ if (ret < 0) {
+ LOG_ERR("Failed to read syslog/target/ip setting (%d)", ret);
+ return (int)ret;
+ }
+ LOG_INF("Setting target IP address to '%s'", target_ip);
+ return 0;
+ }
+
+ return 0;
+}
+
+int syslog_handle_commit(void)
+{
+ LOG_WRN("Settings commit not implemented");
+ return 0;
+}
+
+int syslog_handle_export(int (*cb)(const char *name, const void *value,
+ size_t val_len))
+{
+ LOG_WRN("Settings export not implemented");
+ return 0;
+}
+
+int syslog_handle_get(const char *name, char *val, int val_len_max)
+{
+ LOG_WRN("Settings get not implemented");
+ return 0;
+}
+
+SETTINGS_STATIC_HANDLER_DEFINE(
+ syslog_settings_handler,
+ "syslog",
+ syslog_handle_get,
+ syslog_handle_set,
+ syslog_handle_commit,
+ syslog_handle_export
+);