pmaports/temp/usb-moded/0001-dyn-config-Add-option-for-running-a-command-on-mode-.patch
Dylan Van Assche 002191af2b
temp/usb-moded: fork from Alpine
Adjust with support for NCM gadget, generalize FunctionFS functionality,
and disabling rescue mode.

USB Moded modes contain:
- Tethering mode script
- Developer mode script
- umtprd daemon for MTP mode

Co-authored-by: Clayton Craft <craftyguy@postmarketos.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6531>
2025-12-27 22:44:27 -08:00

112 lines
4.9 KiB
Diff

From 2782277f64a4d47dbdf5f5e4a78fcaa75fe711a8 Mon Sep 17 00:00:00 2001
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Sat, 10 May 2025 14:37:52 +0200
Subject: [PATCH 1/5] [dyn-config] Add option for running a command on mode
start/stop
Allow specifying a command to execute on starting and stopping an USB mode
such as a DHCP server, MTP responder, or another daemon which is needed
for operating this USB mode. This feature complements DBus activation
and systemd service activation.
Signed-off-by: Dylan Van Assche <me@dylanvanassche.be>
---
src/usb_moded-dyn-config.c | 11 +++++++++++
src/usb_moded-dyn-config.h | 10 ++++++++++
2 files changed, 21 insertions(+)
diff --git a/src/usb_moded-dyn-config.c b/src/usb_moded-dyn-config.c
index a6d9d7e..0623b57 100644
--- a/src/usb_moded-dyn-config.c
+++ b/src/usb_moded-dyn-config.c
@@ -4,6 +4,7 @@
* Copyright (c) 2011 Nokia Corporation. All rights reserved.
* Copyright (c) 2013 - 2021 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
+ * Copyright (c) 2025 Dylan Van Assche
*
* @author Philippe De Swert <philippe.de-swert@nokia.com>
* @author Philippe De Swert <philippedeswert@gmail.com>
@@ -11,6 +12,7 @@
* @author Thomas Perl <thomas.perl@jolla.com>
* @author Slava Monich <slava.monich@jolla.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ * @author Dylan Van Assche <me@dylanvanassche.be>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public License
@@ -100,6 +102,9 @@ modedata_free(modedata_t *self)
#ifdef CONNMAN
g_free(self->connman_tethering);
#endif
+ g_free(self->command_up);
+ g_free(self->command_down);
+ g_free(self->ffs_daemon_mountpoint);
modedata_flush_settings(self);
free(self);
}
@@ -151,6 +156,9 @@ modedata_copy(const modedata_t *that)
self->cached_gateway = g_strdup(that->cached_gateway);
self->cached_nat_interface = g_strdup(that->cached_nat_interface);
self->cached_netmask = g_strdup(that->cached_netmask);
+ self->command_up = g_strdup(that->command_up);
+ self->command_down = g_strdup(that->command_down);
+ self->ffs_daemon_mountpoint = g_strdup(that->ffs_daemon_mountpoint);
EXIT:
return self;
@@ -275,6 +283,9 @@ modedata_load(const gchar *filename)
#ifdef CONNMAN
self->connman_tethering = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_CONNMAN_TETHERING, NULL);
#endif
+ self->command_up = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_COMMAND_UP, NULL);
+ self->command_down = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_COMMAND_DOWN, NULL);
+ self->ffs_daemon_mountpoint = g_key_file_get_string(settingsfile, MODE_OPTIONS_ENTRY, MODE_FFS_DAEMON_MOUNTPOINT, NULL);
//log_debug("Dynamic mode sysfs path = %s\n", self->sysfs_path);
//log_debug("Dynamic mode sysfs value = %s\n", self->sysfs_value);
diff --git a/src/usb_moded-dyn-config.h b/src/usb_moded-dyn-config.h
index 79a143e..6e368a2 100644
--- a/src/usb_moded-dyn-config.h
+++ b/src/usb_moded-dyn-config.h
@@ -4,6 +4,7 @@
* Copyright (c) 2011 Nokia Corporation. All rights reserved.
* Copyright (c) 2013 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
+ * Copyright (c) 2025 Dylan Van Assche
*
* @author Philippe De Swert <philippe.de-swert@nokia.com>
* @author Philippe De Swert <phdeswer@lumi.maa>
@@ -13,6 +14,7 @@
* @author Slava Monich <slava.monich@jolla.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
* @author Andrew den Exter <andrew.den.exter@jolla.com>
+ * @author Dylan Van Assche <me@dylanvanassche.be>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public License
@@ -89,6 +91,10 @@
# define MODE_CONNMAN_TETHERING "connman_tethering"
# endif
+# define MODE_COMMAND_UP "command_up"
+# define MODE_COMMAND_DOWN "command_down"
+# define MODE_FFS_DAEMON_MOUNTPOINT "ffs_daemon_mountpoint"
+
/* ========================================================================= *
* Types
* ========================================================================= */
@@ -129,6 +135,10 @@ typedef struct modedata_t
gchar *cached_nat_interface; /**< Cached NETWORK_NAT_INTERFACE_KEY setting */
gchar *cached_netmask; /**< Cached NETWORK_NETMASK_KEY setting */
+ gchar *command_up; /**< Command to execute when starting an USB mode */
+ gchar *command_down; /**< Command to execute when stopping an USB mode */
+ gchar *ffs_daemon_mountpoint; /**< Device mountpoint for userspace FunctionFS daemon */
+
} modedata_t;
/* ========================================================================= *
--
2.49.0