ofono.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs
@ 2024-01-30 21:21 Denis Kenzior
  2024-01-30 21:21 ` [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode Denis Kenzior
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

/var/lib is used by oFono to store various long term settings.  Make
sure the settings from the system are not used by mistake.  Also, since
the host filesystem is mounted read-only, updating of /var/lib locations
by oFono wouldn't work anyway, which might be confusing.
---
 tools/umlrunner | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/umlrunner b/tools/umlrunner
index c1d4c9864487..bb2f24a6dbb9 100755
--- a/tools/umlrunner
+++ b/tools/umlrunner
@@ -45,6 +45,8 @@ mounts_common = [
     MountInfo('tmpfs', 'tmpfs', '/etc', '', 0),
     MountInfo('tmpfs', 'tmpfs', '/usr/share/dbus-1', 'mode=0755',
               MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME),
+    MountInfo('tmpfs', 'tmpfs', '/var/lib', 'mode=0755',
+              MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME),
 ]
 
 dev_table = [
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 03/17] build: Bring in more ell classes Denis Kenzior
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Using backtrace() is of no use when building with PIE (which most
distro compilers do by default) and prevents catching the coredump
for later retracing, which is needed since distros usually don't
install debug symbols by default either.

This patch thus only enables backtrace() when --enable-maintainer-mode
is passed and also tries to explicitly disable PIE.

This commit is based on the following commit from 'iwd':
b6910e121082 ("build: only enable backtrace(3) in maintainer mode")
---
 configure.ac | 11 +++++++++++
 src/log.c    |  8 ++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index c18cfa3a696f..551f863538ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,17 @@ AC_ARG_ENABLE(ubsan, AS_HELP_STRING([--enable-ubsan],
 AC_CHECK_FUNCS(explicit_bzero)
 AC_CHECK_FUNCS(rawmemchr)
 
+# In maintainer mode: try to build with application backtrace and disable PIE.
+if (test "${USE_MAINTAINER_MODE}" = yes); then
+	AC_SEARCH_LIBS([backtrace], [execinfo],
+		[
+			AC_DEFINE([HAVE_BACKTRACE], [1],
+				[Define to 1 if you have backtrace(3).])
+			CFLAGS="$CFLAGS -fno-PIE"
+			LDFLAGS="$LDFLAGS -no-pie"
+		])
+fi
+
 AC_CHECK_FUNC(signalfd, dummy=yes,
 			AC_MSG_ERROR(signalfd support is required))
 
diff --git a/src/log.c b/src/log.c
index b33a7d262474..a8b4ef10eaae 100644
--- a/src/log.c
+++ b/src/log.c
@@ -30,7 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
-#ifdef __GLIBC__
+#ifdef HAVE_BACKTRACE
 #include <execinfo.h>
 #endif
 #include <dlfcn.h>
@@ -115,7 +115,7 @@ void ofono_debug(const char *format, ...)
 	va_end(ap);
 }
 
-#ifdef __GLIBC__
+#ifdef HAVE_BACKTRACE
 static void print_backtrace(unsigned int offset)
 {
 	void *frames[99];
@@ -303,7 +303,7 @@ int __ofono_log_init(const char *program, const char *debug,
 	if (detach == FALSE)
 		option |= LOG_PERROR;
 
-#ifdef __GLIBC__
+#ifdef HAVE_BACKTRACE
 	signal_setup(signal_handler);
 #endif
 
@@ -320,7 +320,7 @@ void __ofono_log_cleanup(void)
 
 	closelog();
 
-#ifdef __GLIBC__
+#ifdef HAVE_BACKTRACE
 	signal_setup(SIG_DFL);
 #endif
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 03/17] build: Bring in more ell classes
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
  2024-01-30 21:21 ` [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 04/17] provisiondb: Remove some duplicate MCCMNC entries Denis Kenzior
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Some ell classes are still not used by oFono.  Bring them all into the
build for future use.
---
 Makefile.am | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 79645e767b05..5221b1cca138 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,8 +36,8 @@ ell_headers = ell/util.h \
 			ell/checksum.h \
 			ell/netlink.h \
 			ell/genl.h \
-			ell/dbus.h \
 			ell/rtnl.h \
+			ell/dbus.h \
 			ell/dbus-service.h \
 			ell/dbus-client.h \
 			ell/hwdb.h \
@@ -52,14 +52,20 @@ ell_headers = ell/util.h \
 			ell/file.h \
 			ell/dir.h \
 			ell/net.h \
+			ell/dhcp.h \
+			ell/dhcp6.h \
 			ell/cert.h \
 			ell/ecc.h \
 			ell/ecdh.h \
 			ell/time.h \
+			ell/gpio.h \
 			ell/path.h \
+			ell/icmp6.h \
+			ell/acd.h \
 			ell/cleanup.h \
+			ell/netconfig.h \
 			ell/sysctl.h \
-			ell/gpio.h
+			ell/minheap.h
 
 ell_sources = ell/private.h \
 			ell/missing.h \
@@ -103,30 +109,46 @@ ell_sources = ell/private.h \
 			ell/uintset.c \
 			ell/base64.c \
 			ell/asn1-private.h \
-			ell/pem.c \
 			ell/pem-private.h \
+			ell/pem.c \
 			ell/tls-private.h \
 			ell/tls.c \
 			ell/tls-record.c \
-			ell/tls-suites.c \
 			ell/tls-extensions.c \
+			ell/tls-suites.c \
 			ell/uuid.c \
 			ell/key.c \
 			ell/file.c \
 			ell/dir.c \
 			ell/net-private.h \
 			ell/net.c \
+			ell/dhcp-private.h \
+			ell/dhcp.c \
+			ell/dhcp-transport.c \
+			ell/dhcp-lease.c \
+			ell/dhcp6-private.h \
+			ell/dhcp6.c \
+			ell/dhcp6-transport.c \
+			ell/dhcp6-lease.c \
+			ell/dhcp-util.c \
+			ell/dhcp-server.c \
 			ell/cert-private.h \
 			ell/cert.c \
-			ell/ecc-external.c \
+			ell/cert-crypto.c \
 			ell/ecc-private.h \
+			ell/ecc-external.c \
 			ell/ecc.c \
 			ell/ecdh.c \
 			ell/time.c \
 			ell/time-private.h \
+			ell/gpio.c \
 			ell/path.c \
+			ell/icmp6.c \
+			ell/icmp6-private.h \
+			ell/acd.c \
+			ell/netconfig.c \
 			ell/sysctl.c \
-			ell/gpio.c
+			ell/minheap.c
 
 ell_shared = ell/useful.h ell/asn1-private.h
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 04/17] provisiondb: Remove some duplicate MCCMNC entries
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
  2024-01-30 21:21 ` [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode Denis Kenzior
  2024-01-30 21:21 ` [PATCH 03/17] build: Bring in more ell classes Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 05/17] storage: Introduce storage_get_file_path() Denis Kenzior
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

---
 provision.json | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/provision.json b/provision.json
index ae9a08482254..77d5bb977254 100644
--- a/provision.json
+++ b/provision.json
@@ -14145,7 +14145,6 @@
       "310070",
       "310080",
       "310090",
-      "310090",
       "310150",
       "310170",
       "310280",
@@ -14153,8 +14152,6 @@
       "310410",
       "310560",
       "310670",
-      "310670",
-      "310680",
       "310680",
       "310950",
       "311070",
@@ -14309,7 +14306,6 @@
       "310011",
       "310012",
       "311480",
-      "311480",
       "311481",
       "311482",
       "311483",
@@ -15038,4 +15034,4 @@
       }
     ]
   }
-]
\ No newline at end of file
+]
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 05/17] storage: Introduce storage_get_file_path()
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (2 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 04/17] provisiondb: Remove some duplicate MCCMNC entries Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 06/17] storage: Convert g_strdup_* use to l_strdup_* Denis Kenzior
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

There are multiple locations where the same steps are followed to
produce a file path for a given storage location.  Pull this logic into
a single function and expose it for potential use by other modules.
While here, convert use of GLib functions to ell.
---
 src/storage.c | 36 +++++++++++++++++-------------------
 src/storage.h |  1 +
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 05d9b88a0237..c7bbb1c6142a 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -171,45 +171,43 @@ error_create_dirs:
 	return r;
 }
 
-GKeyFile *storage_open(const char *imsi, const char *store)
+char *storage_get_file_path(const char *imsi, const char *store)
 {
-	GKeyFile *keyfile;
-	char *path;
-
 	if (store == NULL)
 		return NULL;
 
 	if (imsi)
-		path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
+		return l_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
 	else
-		path = g_strdup_printf(STORAGEDIR "/%s", store);
+		return l_strdup_printf(STORAGEDIR "/%s", store);
+}
 
-	keyfile = g_key_file_new();
+GKeyFile *storage_open(const char *imsi, const char *store)
+{
+	GKeyFile *keyfile;
+	char *path = storage_get_file_path(imsi, store);
 
-	if (path) {
-		g_key_file_load_from_file(keyfile, path, 0, NULL);
-		g_free(path);
-	}
+	if (!path)
+		return NULL;
+
+	keyfile = g_key_file_new();
+	g_key_file_load_from_file(keyfile, path, 0, NULL);
+	l_free(path);
 
 	return keyfile;
 }
 
 void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 {
-	char *path;
+	char *path = storage_get_file_path(imsi, store);
 	char *data;
 	gsize length = 0;
 
-	if (imsi)
-		path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
-	else
-		path = g_strdup_printf(STORAGEDIR "/%s", store);
-
 	if (path == NULL)
 		return;
 
 	if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
-		g_free(path);
+		l_free(path);
 		return;
 	}
 
@@ -218,7 +216,7 @@ void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 	g_file_set_contents(path, data, length, NULL);
 
 	g_free(data);
-	g_free(path);
+	l_free(path);
 }
 
 void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,
diff --git a/src/storage.h b/src/storage.h
index 4dc792ccf7f9..3a1e64493546 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -32,6 +32,7 @@ ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
 			const char *path_fmt, ...)
 	__attribute__((format(printf, 4, 5)));
 
+char *storage_get_file_path(const char *imsi, const char *store);
 GKeyFile *storage_open(const char *imsi, const char *store);
 void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile);
 void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 06/17] storage: Convert g_strdup_* use to l_strdup_*
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (3 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 05/17] storage: Introduce storage_get_file_path() Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 07/17] common: Drop GLib use from gprs_auth_proto_to_string Denis Kenzior
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

---
 src/storage.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index c7bbb1c6142a..2313835a49ce 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -93,12 +93,12 @@ ssize_t read_file(unsigned char *buffer, size_t len,
 	int fd;
 
 	va_start(ap, path_fmt);
-	path = g_strdup_vprintf(path_fmt, ap);
+	path = l_strdup_vprintf(path_fmt, ap);
 	va_end(ap);
 
 	fd = L_TFR(open(path, O_RDONLY));
 
-	g_free(path);
+	l_free(path);
 
 	if (fd == -1)
 		return -1;
@@ -129,10 +129,10 @@ ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
 	int fd;
 
 	va_start(ap, path_fmt);
-	path = g_strdup_vprintf(path_fmt, ap);
+	path = l_strdup_vprintf(path_fmt, ap);
 	va_end(ap);
 
-	tmp_path = g_strdup_printf("%s.XXXXXX.tmp", path);
+	tmp_path = l_strdup_printf("%s.XXXXXX.tmp", path);
 
 	r = -1;
 	if (create_dirs(path, mode | S_IXUSR) != 0)
@@ -166,8 +166,8 @@ error_write:
 	unlink(tmp_path);
 error_mkstemp_full:
 error_create_dirs:
-	g_free(tmp_path);
-	g_free(path);
+	l_free(tmp_path);
+	l_free(path);
 	return r;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 07/17] common: Drop GLib use from gprs_auth_proto_to_string
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (4 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 06/17] storage: Convert g_strdup_* use to l_strdup_* Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 08/17] common: Drop GLib use from gprs_proto_to_string Denis Kenzior
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Refactor this function to use bool from stdbool.h as well as drop usage
of GLib in favor of ell.
---
 src/common.c | 15 ++++++++-------
 src/common.h |  3 ++-
 src/gprs.c   |  4 ++--
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/common.c b/src/common.c
index 9a55990b6435..79094ee4906c 100644
--- a/src/common.c
+++ b/src/common.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 
 #include <glib.h>
+#include <ell/ell.h>
 
 #include <ofono/types.h>
 #include <ofono/gprs-context.h>
@@ -747,20 +748,20 @@ const char *gprs_proto_to_string(enum ofono_gprs_proto proto)
 	return NULL;
 }
 
-gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto)
+bool gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto)
 {
-	if (g_str_equal(str, "ip")) {
+	if (l_streq0(str, "ip")) {
 		*proto = OFONO_GPRS_PROTO_IP;
-		return TRUE;
-	} else if (g_str_equal(str, "ipv6")) {
+		return true;
+	} else if (l_streq0(str, "ipv6")) {
 		*proto = OFONO_GPRS_PROTO_IPV6;
-		return TRUE;
+		return true;
 	} else if (g_str_equal(str, "dual")) {
 		*proto = OFONO_GPRS_PROTO_IPV4V6;
-		return TRUE;
+		return true;
 	}
 
-	return FALSE;
+	return false;
 }
 
 const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth)
diff --git a/src/common.h b/src/common.h
index 3d30e2497ebb..779de7278446 100644
--- a/src/common.h
+++ b/src/common.h
@@ -19,6 +19,7 @@
  *
  */
 
+#include <stdbool.h>
 #include <glib.h>
 
 #include <ofono/types.h>
@@ -185,7 +186,7 @@ gboolean is_valid_apn(const char *apn);
 const char *call_status_to_string(enum call_status status);
 
 const char *gprs_proto_to_string(enum ofono_gprs_proto proto);
-gboolean gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto);
+bool gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto);
 
 const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth);
 gboolean gprs_auth_method_from_string(const char *str,
diff --git a/src/gprs.c b/src/gprs.c
index 7b681d850c21..3eb7df83ac54 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1087,7 +1087,7 @@ static DBusMessage *pri_set_proto(struct pri_context *ctx,
 	GKeyFile *settings = ctx->gprs->settings;
 	enum ofono_gprs_proto proto;
 
-	if (gprs_proto_from_string(str, &proto) == FALSE)
+	if (!gprs_proto_from_string(str, &proto))
 		return __ofono_error_invalid_format(msg);
 
 	if (ctx->context.proto == proto)
@@ -3162,7 +3162,7 @@ static gboolean load_context(struct ofono_gprs *gprs, const char *group)
 	if (protostr == NULL)
 		protostr = g_strdup("ip");
 
-	if (gprs_proto_from_string(protostr, &proto) == FALSE)
+	if (!gprs_proto_from_string(protostr, &proto))
 		goto error;
 
 	username = g_key_file_get_string(gprs->settings, group,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 08/17] common: Drop GLib use from gprs_proto_to_string
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (5 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 07/17] common: Drop GLib use from gprs_auth_proto_to_string Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 09/17] storage: Remove mode parameter Denis Kenzior
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Refactor this function to use bool from stdbool.h as well as drop usage
of GLib in favor of ell.
---
 src/common.c | 16 ++++++++--------
 src/common.h |  2 +-
 src/gprs.c   |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/common.c b/src/common.c
index 79094ee4906c..abb151b6e8a1 100644
--- a/src/common.c
+++ b/src/common.c
@@ -778,19 +778,19 @@ const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth)
 	return NULL;
 }
 
-gboolean gprs_auth_method_from_string(const char *str,
+bool gprs_auth_method_from_string(const char *str,
 					enum ofono_gprs_auth_method *auth)
 {
-	if (g_str_equal(str, "chap")) {
+	if (l_streq0(str, "chap")) {
 		*auth = OFONO_GPRS_AUTH_METHOD_CHAP;
-		return TRUE;
-	} else if (g_str_equal(str, "pap")) {
+		return true;
+	} else if (l_streq0(str, "pap")) {
 		*auth = OFONO_GPRS_AUTH_METHOD_PAP;
-		return TRUE;
-	} else if (g_str_equal(str, "none")) {
+		return true;
+	} else if (l_streq0(str, "none")) {
 		*auth = OFONO_GPRS_AUTH_METHOD_NONE;
-		return TRUE;
+		return true;
 	}
 
-	return FALSE;
+	return false;
 }
diff --git a/src/common.h b/src/common.h
index 779de7278446..bfbf2cff0437 100644
--- a/src/common.h
+++ b/src/common.h
@@ -189,5 +189,5 @@ const char *gprs_proto_to_string(enum ofono_gprs_proto proto);
 bool gprs_proto_from_string(const char *str, enum ofono_gprs_proto *proto);
 
 const char *gprs_auth_method_to_string(enum ofono_gprs_auth_method auth);
-gboolean gprs_auth_method_from_string(const char *str,
+bool gprs_auth_method_from_string(const char *str,
 					enum ofono_gprs_auth_method *auth);
diff --git a/src/gprs.c b/src/gprs.c
index 3eb7df83ac54..dbf9b0605b7c 100644
--- a/src/gprs.c
+++ b/src/gprs.c
@@ -1201,7 +1201,7 @@ static DBusMessage *pri_set_auth_method(struct pri_context *ctx,
 	GKeyFile *settings = ctx->gprs->settings;
 	enum ofono_gprs_auth_method auth;
 
-	if (gprs_auth_method_from_string(str, &auth) == FALSE)
+	if (!gprs_auth_method_from_string(str, &auth))
 		return __ofono_error_invalid_format(msg);
 
 	if (ctx->context.auth_method == auth)
@@ -3183,7 +3183,7 @@ static gboolean load_context(struct ofono_gprs *gprs, const char *group)
 	if (authstr == NULL)
 		authstr = g_strdup("chap");
 
-	if (gprs_auth_method_from_string(authstr, &auth) == FALSE)
+	if (!gprs_auth_method_from_string(authstr, &auth))
 		goto error;
 
 	if (strlen(password) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 09/17] storage: Remove mode parameter
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (6 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 08/17] common: Drop GLib use from gprs_proto_to_string Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 10/17] storage: Use l_malloc Denis Kenzior
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Files are always written with owner read and write permissions.  No
other permissions make sense, so remove the mode parameter to simplify
calling code.
---
 src/simfs.c   | 5 ++---
 src/smsutil.c | 8 +++-----
 src/storage.c | 3 ++-
 src/storage.h | 4 ++--
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/simfs.c b/src/simfs.c
index 515f5c97f7a7..38d4852b1886 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -1158,8 +1158,7 @@ void sim_fs_cache_image(struct sim_fs *fs, const char *image, int id)
 		return;
 
 	write_file((const unsigned char *) image, strlen(image),
-			SIM_CACHE_MODE, SIM_IMAGE_CACHE_PATH, imsi,
-			phase, id);
+			SIM_IMAGE_CACHE_PATH, imsi, phase, id);
 }
 
 char *sim_fs_get_cached_image(struct sim_fs *fs, int id)
@@ -1262,7 +1261,7 @@ void sim_fs_check_version(struct sim_fs *fs)
 	sim_fs_cache_flush(fs);
 
 	version = SIM_FS_VERSION;
-	write_file(&version, 1, SIM_CACHE_MODE, SIM_CACHE_VERSION, imsi, phase);
+	write_file(&version, 1, SIM_CACHE_VERSION, imsi, phase);
 }
 
 void sim_fs_cache_flush(struct sim_fs *fs)
diff --git a/src/smsutil.c b/src/smsutil.c
index f2b6f44c2aa9..d07960190103 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -42,7 +42,6 @@
 
 #define uninitialized_var(x) x = x
 
-#define SMS_BACKUP_MODE 0600
 #define SMS_BACKUP_PATH STORAGEDIR "/%s/sms_assembly"
 #define SMS_BACKUP_PATH_DIR SMS_BACKUP_PATH "/%s-%i-%i"
 #define SMS_BACKUP_PATH_FILE SMS_BACKUP_PATH_DIR "/%03i"
@@ -2505,8 +2504,7 @@ static gboolean sms_assembly_store(struct sms_assembly *assembly,
 
 	len = sms_serialize(buf, sms);
 
-	if (write_file(buf, len, SMS_BACKUP_MODE,
-				SMS_BACKUP_PATH_FILE, assembly->imsi, straddr,
+	if (write_file(buf, len, SMS_BACKUP_PATH_FILE, assembly->imsi, straddr,
 				node->ref, node->max_fragments, seq) != len)
 		return FALSE;
 
@@ -2889,7 +2887,7 @@ static gboolean sr_assembly_add_fragment_backup(const char *imsi,
 		return FALSE;
 
 	/* storagedir/%s/sms_sr/%s-%s */
-	if (write_file((unsigned char *) node, len, SMS_BACKUP_MODE,
+	if (write_file((unsigned char *) node, len,
 			SMS_SR_BACKUP_PATH_FILE, imsi,
 			straddr, msgid_str) != len)
 		return FALSE;
@@ -3370,7 +3368,7 @@ gboolean sms_tx_backup_store(const char *imsi, unsigned long id,
 	/*
 	 * file name is: imsi/tx_queue/order-flags-uuid/pdu
 	 */
-	if (write_file(buf, len, SMS_BACKUP_MODE, SMS_TX_BACKUP_PATH_FILE,
+	if (write_file(buf, len, SMS_TX_BACKUP_PATH_FILE,
 					imsi, id, flags, uuid, seq) != len)
 		return FALSE;
 
diff --git a/src/storage.c b/src/storage.c
index 2313835a49ce..89c11cac4452 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -120,13 +120,14 @@ ssize_t read_file(unsigned char *buffer, size_t len,
  * file with a temporary name and when closed, it is renamed to the
  * specified name (@path_fmt+args).
  */
-ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
+ssize_t write_file(const unsigned char *buffer, size_t len,
 			const char *path_fmt, ...)
 {
 	va_list ap;
 	char *tmp_path, *path;
 	ssize_t r;
 	int fd;
+	mode_t mode = S_IRUSR | S_IWUSR;
 
 	va_start(ap, path_fmt);
 	path = l_strdup_vprintf(path_fmt, ap);
diff --git a/src/storage.h b/src/storage.h
index 3a1e64493546..76069949e747 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -28,9 +28,9 @@ ssize_t read_file(unsigned char *buffer, size_t len,
 			const char *path_fmt, ...)
 	__attribute__((format(printf, 3, 4)));
 
-ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
+ssize_t write_file(const unsigned char *buffer, size_t len,
 			const char *path_fmt, ...)
-	__attribute__((format(printf, 4, 5)));
+	__attribute__((format(printf, 3, 4)));
 
 char *storage_get_file_path(const char *imsi, const char *store);
 GKeyFile *storage_open(const char *imsi, const char *store);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 10/17] storage: Use l_malloc
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (7 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 09/17] storage: Remove mode parameter Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 11/17] storage: Remove mode argument Denis Kenzior
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Instead of g_try_malloc
---
 src/storage.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 89c11cac4452..1c873474a927 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -61,10 +61,7 @@ int create_dirs(const char *filename, const mode_t mode)
 	if (!err && S_ISREG(st.st_mode))
 		return 0;
 
-	dir = g_try_malloc(strlen(filename) + 1);
-	if (dir == NULL)
-		return -1;
-
+	dir = l_malloc(strlen(filename) + 1);
 	strcpy(dir, "/");
 
 	for (prev = filename; (next = strchr(prev + 1, '/')); prev = next) {
@@ -75,12 +72,12 @@ int create_dirs(const char *filename, const mode_t mode)
 		strncat(dir, prev + 1, next - prev);
 
 		if (mkdir(dir, mode) == -1 && errno != EEXIST) {
-			g_free(dir);
+			l_free(dir);
 			return -1;
 		}
 	}
 
-	g_free(dir);
+	l_free(dir);
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 11/17] storage: Remove mode argument
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (8 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 10/17] storage: Use l_malloc Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 12/17] storage: Use void * instead of unsigned char * Denis Kenzior
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

oFono should be making all sub-directories in STORAGEDIR (typically
/var/lib/ofono) as owner readable/writable.  No other permissions make
sense.  Remove the mode argument from the function signature to make
this explicit.
---
 src/storage.c | 10 ++++++----
 src/storage.h |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 1c873474a927..f169195c8df7 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -37,6 +37,8 @@
 
 #include "storage.h"
 
+#define STORAGE_DIR_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
+
 const char *ofono_config_dir(void)
 {
 	return CONFIGDIR;
@@ -47,7 +49,7 @@ const char *ofono_storage_dir(void)
 	return STORAGEDIR;
 }
 
-int create_dirs(const char *filename, const mode_t mode)
+int create_dirs(const char *filename)
 {
 	struct stat st;
 	char *dir;
@@ -71,7 +73,7 @@ int create_dirs(const char *filename, const mode_t mode)
 
 		strncat(dir, prev + 1, next - prev);
 
-		if (mkdir(dir, mode) == -1 && errno != EEXIST) {
+		if (mkdir(dir, STORAGE_DIR_MODE) == -1 && errno != EEXIST) {
 			l_free(dir);
 			return -1;
 		}
@@ -133,7 +135,7 @@ ssize_t write_file(const unsigned char *buffer, size_t len,
 	tmp_path = l_strdup_printf("%s.XXXXXX.tmp", path);
 
 	r = -1;
-	if (create_dirs(path, mode | S_IXUSR) != 0)
+	if (create_dirs(path) != 0)
 		goto error_create_dirs;
 
 	fd = L_TFR(g_mkstemp_full(tmp_path, O_WRONLY | O_CREAT | O_TRUNC, mode));
@@ -204,7 +206,7 @@ void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
 	if (path == NULL)
 		return;
 
-	if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
+	if (create_dirs(path) != 0) {
 		l_free(path);
 		return;
 	}
diff --git a/src/storage.h b/src/storage.h
index 76069949e747..46efd2d1a208 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -22,7 +22,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 
-int create_dirs(const char *filename, const mode_t mode);
+int create_dirs(const char *filename);
 
 ssize_t read_file(unsigned char *buffer, size_t len,
 			const char *path_fmt, ...)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 12/17] storage: Use void * instead of unsigned char *
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (9 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 11/17] storage: Remove mode argument Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 13/17] storage: use l_file_set_contents Denis Kenzior
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

This allows passing both binary and string data to write_file() and
read_file()
---
 src/storage.c | 6 ++----
 src/storage.h | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index f169195c8df7..30e004e75d91 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -83,8 +83,7 @@ int create_dirs(const char *filename)
 	return 0;
 }
 
-ssize_t read_file(unsigned char *buffer, size_t len,
-			const char *path_fmt, ...)
+ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
 {
 	va_list ap;
 	char *path;
@@ -119,8 +118,7 @@ ssize_t read_file(unsigned char *buffer, size_t len,
  * file with a temporary name and when closed, it is renamed to the
  * specified name (@path_fmt+args).
  */
-ssize_t write_file(const unsigned char *buffer, size_t len,
-			const char *path_fmt, ...)
+ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
 {
 	va_list ap;
 	char *tmp_path, *path;
diff --git a/src/storage.h b/src/storage.h
index 46efd2d1a208..135674c6f517 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -24,12 +24,10 @@
 
 int create_dirs(const char *filename);
 
-ssize_t read_file(unsigned char *buffer, size_t len,
-			const char *path_fmt, ...)
+ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
 	__attribute__((format(printf, 3, 4)));
 
-ssize_t write_file(const unsigned char *buffer, size_t len,
-			const char *path_fmt, ...)
+ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
 	__attribute__((format(printf, 3, 4)));
 
 char *storage_get_file_path(const char *imsi, const char *store);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 13/17] storage: use l_file_set_contents
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (10 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 12/17] storage: Use void * instead of unsigned char * Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 14/17] lte: Refactor lte settings management Denis Kenzior
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

Use ell convenience function to set the file contents.
---
 src/storage.c | 41 ++++++-----------------------------------
 1 file changed, 6 insertions(+), 35 deletions(-)

diff --git a/src/storage.c b/src/storage.c
index 30e004e75d91..130fcc9ce4a7 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -3,6 +3,7 @@
  *  oFono - Open Source Telephony
  *
  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2024  Cruise, LLC
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -121,50 +122,20 @@ ssize_t read_file(void *buffer, size_t len, const char *path_fmt, ...)
 ssize_t write_file(const void *buffer, size_t len, const char *path_fmt, ...)
 {
 	va_list ap;
-	char *tmp_path, *path;
-	ssize_t r;
-	int fd;
-	mode_t mode = S_IRUSR | S_IWUSR;
+	char *path;
+	int r;
 
 	va_start(ap, path_fmt);
 	path = l_strdup_vprintf(path_fmt, ap);
 	va_end(ap);
 
-	tmp_path = l_strdup_printf("%s.XXXXXX.tmp", path);
-
-	r = -1;
-	if (create_dirs(path) != 0)
+	r = create_dirs(path);
+	if (r < 0)
 		goto error_create_dirs;
 
-	fd = L_TFR(g_mkstemp_full(tmp_path, O_WRONLY | O_CREAT | O_TRUNC, mode));
-	if (fd == -1)
-		goto error_mkstemp_full;
-
-	r = L_TFR(write(fd, buffer, len));
-
-	L_TFR(close(fd));
-
-	if (r != (ssize_t) len) {
-		r = -1;
-		goto error_write;
-	}
-
-	/*
-	 * Now that the file contents are written, rename to the real
-	 * file name; this way we are uniquely sure that the whole
-	 * thing is there.
-	 */
-	unlink(path);
-
-	/* conserve @r's value from 'write' */
-	if (link(tmp_path, path) == -1)
-		r = -1;
+	r = l_file_set_contents(path, buffer, len);
 
-error_write:
-	unlink(tmp_path);
-error_mkstemp_full:
 error_create_dirs:
-	l_free(tmp_path);
 	l_free(path);
 	return r;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 14/17] lte: Refactor lte settings management
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (11 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 13/17] storage: use l_file_set_contents Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 15/17] lte: Add provisioning support Denis Kenzior
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

In preparation for support LTE Default bearer provisioning, refactor how
the settings are loaded and saved from disk:
  1. Instead of storing the imsi in a malloced variable, obtain it directly
     from the sim atom.
  2. Do not try to save the settings when the lte atom is removed.  If
     the settings have not been provisioned or modified by the user,
     writing the settings file will have no effect, and makes it harder
     to detect whether provisioning should be attempted in the future.
  3. Use ell for the nicer to use _auto_ variables, access to the
     L_WARN macro.
  4. Use l_settings instead of g_key_file.  The underlying file format is
     identical.
  5. Convert g_strlcpy to l_strlcpy
  6. Convert g_str_equal to l_streq0
  7. Convert strdup/g_free to l_strdup and l_free
---
 src/lte.c | 169 +++++++++++++++++++++++++++---------------------------
 1 file changed, 85 insertions(+), 84 deletions(-)

diff --git a/src/lte.c b/src/lte.c
index 7280b2913a8d..d412e15d90f9 100644
--- a/src/lte.c
+++ b/src/lte.c
@@ -32,6 +32,8 @@
 
 #include <glib.h>
 #include <gdbus.h>
+#include <ell/ell.h>
+#include <ell/useful.h>
 
 #include "ofono.h"
 
@@ -50,59 +52,50 @@ struct ofono_lte {
 	const struct ofono_lte_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
-	char *imsi;
-	GKeyFile *settings;
+	struct l_settings *settings;
 	DBusMessage *pending;
 	struct ofono_lte_default_attach_info pending_info;
 	struct ofono_lte_default_attach_info info;
 };
 
-static void lte_load_settings(struct ofono_lte *lte)
+static int lte_load_settings(struct ofono_lte *lte)
 {
-	char *apn;
-	char *proto_str;
-	char *auth_method_str;
-	char *username;
-	char *password;
-
-	if (lte->imsi == NULL)
-		return;
-
-	lte->settings = storage_open(lte->imsi, SETTINGS_STORE);
-
-	if (lte->settings == NULL) {
-		ofono_error("LTE: Can't open settings file, "
-				"changes won't be persistent");
-		return;
-	}
-
-	apn = g_key_file_get_string(lte->settings, SETTINGS_GROUP,
-				LTE_APN, NULL);
-	proto_str = g_key_file_get_string(lte->settings, SETTINGS_GROUP,
-				LTE_PROTO, NULL);
-	auth_method_str = g_key_file_get_string(lte->settings, SETTINGS_GROUP,
-				LTE_AUTH_METHOD, NULL);
-	username = g_key_file_get_string(lte->settings, SETTINGS_GROUP,
-				LTE_USERNAME, NULL);
-	password = g_key_file_get_string(lte->settings, SETTINGS_GROUP,
-				LTE_PASSWORD, NULL);
-	if (apn && is_valid_apn(apn))
-		strcpy(lte->info.apn, apn);
+	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
+	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+	const char *imsi = ofono_sim_get_imsi(sim);
+	_auto_(l_free) char *path = NULL;
+	_auto_(l_free) char *apn = NULL;
+	const char *proto_str;
+	const char *auth_method_str;
+	_auto_(l_free) char *username = NULL;
+	_auto_(l_free) char *password = NULL;
+
+	if (L_WARN_ON(!sim || !imsi))
+		return -ENOKEY;
+
+	path = storage_get_file_path(imsi, SETTINGS_STORE);
+	if (!l_settings_load_from_file(lte->settings, path))
+		return -ENOENT;
+
+	apn = l_settings_get_string(lte->settings, SETTINGS_GROUP, LTE_APN);
+	proto_str = l_settings_get_value(lte->settings, SETTINGS_GROUP,
+						LTE_PROTO);
+	auth_method_str = l_settings_get_value(lte->settings, SETTINGS_GROUP,
+						LTE_AUTH_METHOD);
+	username = l_settings_get_string(lte->settings, SETTINGS_GROUP,
+						LTE_USERNAME);
+	password = l_settings_get_string(lte->settings, SETTINGS_GROUP,
+						LTE_PASSWORD);
 
-	if (proto_str == NULL)
-		proto_str = g_strdup("ip");
+	if (!gprs_auth_method_from_string(auth_method_str,
+							&lte->info.auth_method))
+		lte->info.auth_method = OFONO_GPRS_AUTH_METHOD_NONE;
 
-	/* this must have a valid default */
 	if (!gprs_proto_from_string(proto_str, &lte->info.proto))
 		lte->info.proto = OFONO_GPRS_PROTO_IP;
 
-	if (auth_method_str == NULL)
-		auth_method_str = g_strdup("none");
-
-	/* this must have a valid default */
-	if (!gprs_auth_method_from_string(auth_method_str,
-							&lte->info.auth_method))
-		lte->info.auth_method = OFONO_GPRS_AUTH_METHOD_NONE;
+	if (apn && is_valid_apn(apn))
+		strcpy(lte->info.apn, apn);
 
 	if (username && strlen(username) <= OFONO_GPRS_MAX_USERNAME_LENGTH)
 		strcpy(lte->info.username, username);
@@ -110,11 +103,28 @@ static void lte_load_settings(struct ofono_lte *lte)
 	if (password && strlen(password) <= OFONO_GPRS_MAX_PASSWORD_LENGTH)
 		strcpy(lte->info.password, password);
 
-	g_free(apn);
-	g_free(proto_str);
-	g_free(auth_method_str);
-	g_free(username);
-	g_free(password);
+	return 0;
+}
+
+static void lte_save_settings(struct ofono_lte *lte)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
+	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+	const char *imsi = ofono_sim_get_imsi(sim);
+	_auto_(l_free) char *path = NULL;
+	_auto_(l_free) char *data = NULL;
+	size_t len;
+
+	if (!imsi)
+		return;
+
+	data = l_settings_to_data(lte->settings, &len);
+	if (!data)
+		return;
+
+	path = storage_get_file_path(imsi, SETTINGS_STORE);
+
+	L_WARN_ON(write_file(data, len, "%s", path) < 0);
 }
 
 static DBusMessage *lte_get_properties(DBusConnection *conn,
@@ -180,12 +190,12 @@ static void lte_set_default_attach_info_cb(const struct ofono_error *error,
 	 */
 	dbus_message_iter_init(lte->pending, &iter);
 	dbus_message_iter_get_basic(&iter, &str);
-	key = strdup(str);
+	key = l_strdup(str);
 
 	dbus_message_iter_next(&iter);
 	dbus_message_iter_recurse(&iter, &var);
 	dbus_message_iter_get_basic(&var, &str);
-	value = strdup(str);
+	value = l_strdup(str);
 
 	memcpy(&lte->info, &lte->pending_info, sizeof(lte->info));
 
@@ -200,13 +210,13 @@ static void lte_set_default_attach_info_cb(const struct ofono_error *error,
 		 */
 		if (!*value)
 			/* Clear entry on empty string. */
-			g_key_file_remove_key(lte->settings,
-				SETTINGS_GROUP, key, NULL);
+			l_settings_remove_key(lte->settings,
+						SETTINGS_GROUP, key);
 		else
-			g_key_file_set_string(lte->settings,
-				SETTINGS_GROUP, key, value);
+			l_settings_set_string(lte->settings,
+						SETTINGS_GROUP, key, value);
 
-		storage_sync(lte->imsi, SETTINGS_STORE, lte->settings);
+		lte_save_settings(lte);
 	}
 
 	ofono_dbus_signal_property_changed(conn, path,
@@ -214,8 +224,8 @@ static void lte_set_default_attach_info_cb(const struct ofono_error *error,
 					key,
 					DBUS_TYPE_STRING, &value);
 
-	g_free(value);
-	g_free(key);
+	l_free(value);
+	l_free(key);
 }
 
 static DBusMessage *lte_set_property(DBusConnection *conn,
@@ -257,14 +267,14 @@ static DBusMessage *lte_set_property(DBusConnection *conn,
 	memcpy(&lte->pending_info, &lte->info, sizeof(lte->info));
 
 	if ((strcmp(property, LTE_APN) == 0)) {
-		if (g_str_equal(str, lte->info.apn))
+		if (l_streq0(str, lte->info.apn))
 			return dbus_message_new_method_return(msg);
 
 		/* We do care about empty value: it can be used for reset. */
 		if (is_valid_apn(str) == FALSE && str[0] != '\0')
 			return __ofono_error_invalid_format(msg);
 
-		g_strlcpy(lte->pending_info.apn, str,
+		l_strlcpy(lte->pending_info.apn, str,
 					OFONO_GPRS_MAX_APN_LENGTH + 1);
 	} else if ((strcmp(property, LTE_PROTO) == 0)) {
 		if (!gprs_proto_from_string(str, &proto))
@@ -286,19 +296,19 @@ static DBusMessage *lte_set_property(DBusConnection *conn,
 		if (strlen(str) > OFONO_GPRS_MAX_USERNAME_LENGTH)
 			return __ofono_error_invalid_format(msg);
 
-		if (g_str_equal(str, lte->info.username))
+		if (l_streq0(str, lte->info.username))
 			return dbus_message_new_method_return(msg);
 
-		g_strlcpy(lte->pending_info.username, str,
+		l_strlcpy(lte->pending_info.username, str,
 					OFONO_GPRS_MAX_USERNAME_LENGTH + 1);
 	} else if (strcmp(property, LTE_PASSWORD) == 0) {
 		if (strlen(str) > OFONO_GPRS_MAX_PASSWORD_LENGTH)
 			return __ofono_error_invalid_format(msg);
 
-		if (g_str_equal(str, lte->info.password))
+		if (l_streq0(str, lte->info.password))
 			return dbus_message_new_method_return(msg);
 
-		g_strlcpy(lte->pending_info.password, str,
+		l_strlcpy(lte->pending_info.password, str,
 					OFONO_GPRS_MAX_PASSWORD_LENGTH + 1);
 	} else
 		return __ofono_error_invalid_args(msg);
@@ -332,24 +342,19 @@ static void lte_remove(struct ofono_atom *atom)
 
 	DBG("atom: %p", atom);
 
-	if (lte == NULL)
-		return;
-
-	if (lte->settings) {
-		storage_close(lte->imsi, SETTINGS_STORE, lte->settings, TRUE);
-		lte->settings = NULL;
-	}
+	l_settings_free(lte->settings);
 
 	if (lte->driver && lte->driver->remove)
 		lte->driver->remove(lte);
 
-	g_free(lte->imsi);
-	lte->imsi = NULL;
-
 	g_free(lte);
 }
 
-OFONO_DEFINE_ATOM_CREATE(lte, OFONO_ATOM_TYPE_LTE)
+OFONO_DEFINE_ATOM_CREATE(lte, OFONO_ATOM_TYPE_LTE, {
+	atom->settings = l_settings_new();
+	atom->info.proto = OFONO_GPRS_PROTO_IP;
+	atom->info.auth_method = OFONO_GPRS_AUTH_METHOD_NONE;
+})
 
 static void lte_atom_unregister(struct ofono_atom *atom)
 {
@@ -391,29 +396,25 @@ static void lte_init_default_attach_info_cb(const struct ofono_error *error,
 
 void ofono_lte_register(struct ofono_lte *lte)
 {
-	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
-	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
-	const char *imsi = ofono_sim_get_imsi(sim);
+	/* No settings, go straight to registering the interface on D-Bus */
+	if (lte_load_settings(lte) < 0)
+		goto finish_register;
 
-	if (imsi == NULL) {
-		ofono_error("No sim atom found. It is required for registering LTE atom.");
-		return;
-	}
-
-	lte->imsi = g_strdup(imsi);
-
-	lte_load_settings(lte);
 	if (lte->driver->set_default_attach_info) {
 		lte->driver->set_default_attach_info(lte, &lte->info,
 					lte_init_default_attach_info_cb, lte);
 		return;
 	}
 
+finish_register:
 	ofono_lte_finish_register(lte);
 }
 
 void ofono_lte_remove(struct ofono_lte *lte)
 {
+	if (!lte)
+		return;
+
 	__ofono_atom_free(lte->atom);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 15/17] lte: Add provisioning support
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (12 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 14/17] lte: Refactor lte settings management Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 16/17] phonesim: Add lte atom Denis Kenzior
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

If settings do not exist on disk, try to obtain them from the
provisioning database.  This requires for lte atom to wait until the
EFspn has been read from the SIM.  This is accomplished by creating a
sim spn watch and providing a callback.

When the callback is invoked, try to provision settings with the
MCC/MNC/SPN.  If provisioning succeeds, set the settings into the
currently active default_attach_info.  In all cases, forward the
settings to the the driver and register the interface with D-Bus.
---
 src/lte.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 82 insertions(+), 4 deletions(-)

diff --git a/src/lte.c b/src/lte.c
index d412e15d90f9..433b18956468 100644
--- a/src/lte.c
+++ b/src/lte.c
@@ -37,6 +37,7 @@
 
 #include "ofono.h"
 
+#include "provisiondb.h"
 #include "common.h"
 #include "storage.h"
 
@@ -56,8 +57,54 @@ struct ofono_lte {
 	DBusMessage *pending;
 	struct ofono_lte_default_attach_info pending_info;
 	struct ofono_lte_default_attach_info info;
+	unsigned int spn_watch;
 };
 
+static bool provision_default_attach_info(struct ofono_lte *lte,
+						const char *mcc, const char *mnc,
+						const char *spn)
+{
+	struct provision_db_entry *settings;
+	_auto_(l_free) const struct provision_db_entry *ap = NULL;
+	size_t count;
+	size_t i;
+
+	DBG("Provisioning default bearer info with mcc:'%s', mnc:'%s', spn:'%s'",
+			mcc, mnc, spn);
+
+	if (!__ofono_provision_get_settings(mcc, mnc, spn, &settings, &count))
+		return false;
+
+	DBG("Obtained %zu candidates", count);
+
+	for (i = 0; i < count; i++) {
+		if (settings[i].type & OFONO_GPRS_CONTEXT_TYPE_IA) {
+			ap = &settings[i];
+			break;
+		}
+	}
+
+	if (!is_valid_apn(ap->apn))
+		return false;
+
+	if (ap->username && strlen(ap->username) >
+			OFONO_GPRS_MAX_USERNAME_LENGTH)
+		return false;
+
+	if (ap->password && strlen(ap->password) >
+			OFONO_GPRS_MAX_PASSWORD_LENGTH)
+		return false;
+
+	l_strlcpy(lte->info.apn, ap->apn, sizeof(lte->info.apn));
+	l_strlcpy(lte->info.username, ap->username, sizeof(lte->info.username));
+	l_strlcpy(lte->info.password, ap->password, sizeof(lte->info.password));
+	lte->info.proto = ap->proto;
+	lte->info.auth_method = ap->auth_method;
+
+	DBG("Provisioned successfully");
+	return true;
+}
+
 static int lte_load_settings(struct ofono_lte *lte)
 {
 	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
@@ -361,6 +408,11 @@ static void lte_atom_unregister(struct ofono_atom *atom)
 	DBusConnection *conn = ofono_dbus_get_connection();
 	struct ofono_modem *modem = __ofono_atom_get_modem(atom);
 	const char *path = __ofono_atom_get_path(atom);
+	struct ofono_lte *lte = __ofono_atom_get_data(atom);
+	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+
+	if (lte->spn_watch)
+		ofono_sim_remove_spn_watch(sim, &lte->spn_watch);
 
 	ofono_modem_remove_interface(modem, OFONO_LTE_INTERFACE);
 	g_dbus_unregister_interface(conn, path, OFONO_LTE_INTERFACE);
@@ -394,11 +446,38 @@ static void lte_init_default_attach_info_cb(const struct ofono_error *error,
 	ofono_lte_finish_register(lte);
 }
 
+static void spn_read_cb(const char *spn, const char *dc, void *data)
+{
+	struct ofono_lte *lte = data;
+	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
+	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+
+	ofono_sim_remove_spn_watch(sim, &lte->spn_watch);
+
+	provision_default_attach_info(lte, ofono_sim_get_mcc(sim),
+					ofono_sim_get_mnc(sim), spn);
+
+	if (lte->driver->set_default_attach_info) {
+		lte->driver->set_default_attach_info(lte, &lte->info,
+					lte_init_default_attach_info_cb, lte);
+		return;
+	}
+
+	ofono_lte_finish_register(lte);
+}
+
 void ofono_lte_register(struct ofono_lte *lte)
 {
-	/* No settings, go straight to registering the interface on D-Bus */
-	if (lte_load_settings(lte) < 0)
-		goto finish_register;
+	/* Wait for SPN to be read in order to try provisioning */
+	if (lte_load_settings(lte) < 0) {
+		struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
+		struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM,
+								modem);
+
+		ofono_sim_add_spn_watch(sim, &lte->spn_watch,
+						spn_read_cb, lte, NULL);
+		return;
+	}
 
 	if (lte->driver->set_default_attach_info) {
 		lte->driver->set_default_attach_info(lte, &lte->info,
@@ -406,7 +485,6 @@ void ofono_lte_register(struct ofono_lte *lte)
 		return;
 	}
 
-finish_register:
 	ofono_lte_finish_register(lte);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 16/17] phonesim: Add lte atom
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (13 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 15/17] lte: Add provisioning support Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-01-30 21:21 ` [PATCH 17/17] lte: Write provisioned info to disk Denis Kenzior
  2024-02-02 23:30 ` [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs patchwork-bot+ofono
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

---
 plugins/phonesim.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index 67cdc605189b..a4fdddc68489 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -864,6 +864,7 @@ static void phonesim_post_sim(struct ofono_modem *modem)
 
 	ofono_radio_settings_create(modem, 0, "phonesim", data->chat);
 	ofono_sim_auth_create(modem);
+	ofono_lte_create(modem, 0, "atmodem", data->chat);
 }
 
 static void phonesim_post_online(struct ofono_modem *modem)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 17/17] lte: Write provisioned info to disk
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (14 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 16/17] phonesim: Add lte atom Denis Kenzior
@ 2024-01-30 21:21 ` Denis Kenzior
  2024-02-02 23:30 ` [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs patchwork-bot+ofono
  16 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2024-01-30 21:21 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

If provisioning succeeded, then save the information to disk.  Next time
the modem is powered, the saved information will be used instead of
being obtained via provisioning.
---
 src/lte.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/lte.c b/src/lte.c
index 433b18956468..c3decc5c891c 100644
--- a/src/lte.c
+++ b/src/lte.c
@@ -451,11 +451,37 @@ static void spn_read_cb(const char *spn, const char *dc, void *data)
 	struct ofono_lte *lte = data;
 	struct ofono_modem *modem = __ofono_atom_get_modem(lte->atom);
 	struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+	bool r;
 
 	ofono_sim_remove_spn_watch(sim, &lte->spn_watch);
 
-	provision_default_attach_info(lte, ofono_sim_get_mcc(sim),
-					ofono_sim_get_mnc(sim), spn);
+	r = provision_default_attach_info(lte, ofono_sim_get_mcc(sim),
+						ofono_sim_get_mnc(sim), spn);
+	if (r) {
+		const char *str;
+
+		if (lte->info.apn[0])
+			l_settings_set_string(lte->settings, SETTINGS_GROUP,
+						LTE_APN, lte->info.apn);
+
+		if (lte->info.username[0])
+			l_settings_set_string(lte->settings, SETTINGS_GROUP,
+					LTE_USERNAME, lte->info.username);
+
+		if (lte->info.password[0])
+			l_settings_set_string(lte->settings, SETTINGS_GROUP,
+					LTE_PASSWORD, lte->info.password);
+
+		str = gprs_proto_to_string(lte->info.proto);
+		l_settings_set_string(lte->settings, SETTINGS_GROUP,
+					LTE_PROTO, str);
+
+		str = gprs_auth_method_to_string(lte->info.auth_method);
+		l_settings_set_string(lte->settings, SETTINGS_GROUP,
+					LTE_AUTH_METHOD, str);
+
+		lte_save_settings(lte);
+	}
 
 	if (lte->driver->set_default_attach_info) {
 		lte->driver->set_default_attach_info(lte, &lte->info,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs
  2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
                   ` (15 preceding siblings ...)
  2024-01-30 21:21 ` [PATCH 17/17] lte: Write provisioned info to disk Denis Kenzior
@ 2024-02-02 23:30 ` patchwork-bot+ofono
  16 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+ofono @ 2024-02-02 23:30 UTC (permalink / raw)
  To: Denis Kenzior; +Cc: ofono

Hello:

This series was applied to ofono.git (master)
by Denis Kenzior <denkenz@gmail.com>:

On Tue, 30 Jan 2024 15:21:06 -0600 you wrote:
> /var/lib is used by oFono to store various long term settings.  Make
> sure the settings from the system are not used by mistake.  Also, since
> the host filesystem is mounted read-only, updating of /var/lib locations
> by oFono wouldn't work anyway, which might be confusing.
> ---
>  tools/umlrunner | 2 ++
>  1 file changed, 2 insertions(+)

Here is the summary with links:
  - [01/17] umlrunner: Also mount /var/lib as tmpfs
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=aba0f71b784a
  - [02/17] build: Only enable backtrace(3) in maintainer mode
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=05eabee2524d
  - [03/17] build: Bring in more ell classes
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=2a9ccea64b54
  - [04/17] provisiondb: Remove some duplicate MCCMNC entries
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=19a0d53ba5d5
  - [05/17] storage: Introduce storage_get_file_path()
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=cebe22caedd1
  - [06/17] storage: Convert g_strdup_* use to l_strdup_*
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=d650fe8936cf
  - [07/17] common: Drop GLib use from gprs_auth_proto_to_string
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=6f63dbbbb5c9
  - [08/17] common: Drop GLib use from gprs_proto_to_string
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=c934b708742c
  - [09/17] storage: Remove mode parameter
    (no matching commit)
  - [10/17] storage: Use l_malloc
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=4619f19d3ac7
  - [11/17] storage: Remove mode argument
    (no matching commit)
  - [12/17] storage: Use void * instead of unsigned char *
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=75998e0898bc
  - [13/17] storage: use l_file_set_contents
    (no matching commit)
  - [14/17] lte: Refactor lte settings management
    (no matching commit)
  - [15/17] lte: Add provisioning support
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=69adffb51633
  - [16/17] phonesim: Add lte atom
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=783b036d7bc8
  - [17/17] lte: Write provisioned info to disk
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=53c13ead095c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-02-02 23:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 21:21 [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs Denis Kenzior
2024-01-30 21:21 ` [PATCH 02/17] build: Only enable backtrace(3) in maintainer mode Denis Kenzior
2024-01-30 21:21 ` [PATCH 03/17] build: Bring in more ell classes Denis Kenzior
2024-01-30 21:21 ` [PATCH 04/17] provisiondb: Remove some duplicate MCCMNC entries Denis Kenzior
2024-01-30 21:21 ` [PATCH 05/17] storage: Introduce storage_get_file_path() Denis Kenzior
2024-01-30 21:21 ` [PATCH 06/17] storage: Convert g_strdup_* use to l_strdup_* Denis Kenzior
2024-01-30 21:21 ` [PATCH 07/17] common: Drop GLib use from gprs_auth_proto_to_string Denis Kenzior
2024-01-30 21:21 ` [PATCH 08/17] common: Drop GLib use from gprs_proto_to_string Denis Kenzior
2024-01-30 21:21 ` [PATCH 09/17] storage: Remove mode parameter Denis Kenzior
2024-01-30 21:21 ` [PATCH 10/17] storage: Use l_malloc Denis Kenzior
2024-01-30 21:21 ` [PATCH 11/17] storage: Remove mode argument Denis Kenzior
2024-01-30 21:21 ` [PATCH 12/17] storage: Use void * instead of unsigned char * Denis Kenzior
2024-01-30 21:21 ` [PATCH 13/17] storage: use l_file_set_contents Denis Kenzior
2024-01-30 21:21 ` [PATCH 14/17] lte: Refactor lte settings management Denis Kenzior
2024-01-30 21:21 ` [PATCH 15/17] lte: Add provisioning support Denis Kenzior
2024-01-30 21:21 ` [PATCH 16/17] phonesim: Add lte atom Denis Kenzior
2024-01-30 21:21 ` [PATCH 17/17] lte: Write provisioned info to disk Denis Kenzior
2024-02-02 23:30 ` [PATCH 01/17] umlrunner: Also mount /var/lib as tmpfs patchwork-bot+ofono

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).