From 612749ba309a65a1bc792d10a594680d0d00f599 Mon Sep 17 00:00:00 2001 From: Loic Poulain Date: Fri, 6 Nov 2020 18:18:12 +0100 Subject: Add support for config file Will deprecate parameters? Support for udev (not yet complete). Signed-off-by: Loic Poulain --- 42-mhi.rules | 2 ++ Makefile | 7 +++++++ mhi-qmi-connect | Bin 0 -> 92720 bytes mhi-qmi-connect.c | 43 +++++++++++++++++++++++++++++++++++++++++-- mhi-qmi-connect.conf | 10 ++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 42-mhi.rules create mode 100755 mhi-qmi-connect create mode 100644 mhi-qmi-connect.conf diff --git a/42-mhi.rules b/42-mhi.rules new file mode 100644 index 0000000..1a13508 --- /dev/null +++ b/42-mhi.rules @@ -0,0 +1,2 @@ +# TODO build tool path +ACTION=="add", SUBSYSTEM=="mhi_uci", KERNEL=="mhi_0000:02:00.0_QMI", RUN+="/bin/mhi-qmi-connect --udev" diff --git a/Makefile b/Makefile index 7eb59b5..2f01aae 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,13 @@ $(MHI_QMI_CONNECT): $(OBJS) install: $(MHI_QMI_CONNECT) install -D -m 755 $< $(DESTDIR)$(prefix)/bin/$< + install -D -m 644 mhi-qmi-connect.conf $(DESTDIR)$(prefix)/etc/ + +install_udev: + install -m 644 -p 42-mhi.rules $(DESTDIR)$(prefix)/lib/udev/rules.d + +#TODO uninstall + clean: rm -f $(MHI_QMI_CONNECT) $(OBJS) diff --git a/mhi-qmi-connect b/mhi-qmi-connect new file mode 100755 index 0000000..b7cf0c1 Binary files /dev/null and b/mhi-qmi-connect differ diff --git a/mhi-qmi-connect.c b/mhi-qmi-connect.c index 72c2658..fc0f8f1 100644 --- a/mhi-qmi-connect.c +++ b/mhi-qmi-connect.c @@ -4,6 +4,8 @@ #include +#include +#include #include #include @@ -35,6 +37,8 @@ static gboolean default_route; static gboolean set_ip; static guint32 mux_id = 1; static gchar *qmi_dev; +static gboolean udev; +static gchar *config; static gchar ip4_addr[INET_ADDRSTRLEN]; static gchar ip4_dns[INET_ADDRSTRLEN]; @@ -850,6 +854,9 @@ static gboolean signals_handler(void) } static GOptionEntry main_entries[] = { + { "config", 'c', 0, G_OPTION_ARG_STRING, &config, + "Configuration file to use (not working)", "[CONFIG_FILE]" + }, { "apn", 'a', 0, G_OPTION_ARG_STRING, &apn_str, "Specify device APN name", "[APN]" }, @@ -857,10 +864,10 @@ static GOptionEntry main_entries[] = { "Specify SIM1 pin code", "[SIM1-PIN]" }, { "device", 'd', 0, G_OPTION_ARG_STRING, &qmi_dev, - "Use passed MHI QMI device (instead of IPCR)", NULL + "Use passed MHI QMI device (instead of IPCR)", "[DEVICE]" }, { "mux-id", 0, 0, G_OPTION_ARG_INT, &mux_id, - "QMAP/RMNET mux-id of the connection (default is 1)", NULL + "QMAP/RMNET mux-id of the connection (default is 1)", "[ID]" }, { "set-ip", 0, 0, G_OPTION_ARG_NONE, &set_ip, "Setup rmnet IP address and DNS from Bearer context info", NULL @@ -868,6 +875,9 @@ static GOptionEntry main_entries[] = { { "default-route", 0, 0, G_OPTION_ARG_NONE, &default_route, "Set rmnet interface as the defaut network route", NULL }, + { "udev", 0, 0, G_OPTION_ARG_NONE, &udev, + "When executed from udev rule", NULL + }, { NULL } }; @@ -916,6 +926,24 @@ int mainloop(void) return exit_reason; } +static int read_config(const gchar *config) +{ + GKeyFile *key_file = g_key_file_new(); + + if (!g_key_file_load_from_file(key_file, config, 0, NULL)) { + g_printerr("error: Unable to load %s\n", config); + } + + /* cleanup this */ + + apn_str = g_key_file_get_string(key_file, "APN", "name", NULL); + sim1_pin_str = g_key_file_get_string(key_file, "SIM", "pin", NULL); + set_ip = g_key_file_get_boolean(key_file, "RMNET", "ip_from_bearer", NULL); + default_route = g_key_file_get_boolean(key_file, "RMNET", "default_route", NULL); + + return 0; +} + int main(int argc, char **argv) { GOptionContext *context; @@ -931,6 +959,17 @@ int main(int argc, char **argv) } g_option_context_free(context); + if (udev) { + qmi_dev = g_strdup(g_getenv("DEVNAME")); + g_printerr("QMIdev=%s\n", qmi_dev); + config = "/etc/mhi-qmi-connect.conf"; + // todo g_free() + } + + if (config) { + read_config(config); + } + if (!apn_str) { g_printerr("error: no APN name\n"); exit(EXIT_FAILURE); diff --git a/mhi-qmi-connect.conf b/mhi-qmi-connect.conf new file mode 100644 index 0000000..d64aaee --- /dev/null +++ b/mhi-qmi-connect.conf @@ -0,0 +1,10 @@ +[APN] +name=free + +[SIM] +#pin=1234 + +[RMNET] +ip_from_bearer=true +default_route=true + -- cgit v1.2.3