aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Poulain <loic.poulain@linaro.org>2020-11-06 18:18:12 +0100
committerLoic Poulain <loic.poulain@linaro.org>2020-11-06 18:23:03 +0100
commit612749ba309a65a1bc792d10a594680d0d00f599 (patch)
tree34445669cd5e3e76f15d300c67e23acb2b5eb3de
parentedf970eadd0aec810ad7d99d63e461f1ca455739 (diff)
Add support for config file
Will deprecate parameters? Support for udev (not yet complete). Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
-rw-r--r--42-mhi.rules2
-rw-r--r--Makefile7
-rwxr-xr-xmhi-qmi-connectbin0 -> 92720 bytes
-rw-r--r--mhi-qmi-connect.c43
-rw-r--r--mhi-qmi-connect.conf10
5 files changed, 60 insertions, 2 deletions
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
--- /dev/null
+++ b/mhi-qmi-connect
Binary files 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 <libqmi-glib.h>
+#include <glib.h>
+#include <glib/gprintf.h>
#include <glib-unix.h>
#include <gio/gio.h>
@@ -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
+