diff mbox series

[v2,09/15] provision: Add new module

Message ID 20231219184016.420116-9-denkenz@gmail.com (mailing list archive)
State Changes Requested, archived
Headers show
Series [v2,01/15] build: Fix typo that breaks --fsanitize=leak check | expand

Commit Message

Denis Kenzior Dec. 19, 2023, 6:37 p.m. UTC
This module will replace the gprs-provision module.  The new provisiondb
supercedes all other plugins in capability and there's no desire to
maintain the old code any longer.
---
 Makefile.am     |  3 +-
 src/ofono.h     |  5 ++++
 src/provision.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 src/provision.c
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index 3023ed0c..cfa05bf7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -726,7 +726,8 @@  src_ofonod_SOURCES = $(builtin_sources) $(gatchat_sources) src/ofono.ver \
 			src/netmon.c src/lte.c src/ims.c \
 			src/netmonagent.c src/netmonagent.h \
 			src/module.c \
-			src/provisiondb.h src/provisiondb.c
+			src/provisiondb.h src/provisiondb.c \
+			src/provision.c
 
 src_ofonod_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) $(ell_ldadd) \
 			@GLIB_LIBS@ @DBUS_LIBS@ -ldl
diff --git a/src/ofono.h b/src/ofono.h
index e289ff08..6a8c53a1 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -582,6 +582,11 @@  void __ofono_nettime_info_received(struct ofono_modem *modem,
 #include <ofono/sim-auth.h>
 
 #include <ofono/gprs-provision.h>
+bool __ofono_provision_get_settings(const char *mcc,
+				const char *mnc, const char *spn,
+				struct ofono_gprs_provision_data **settings,
+				size_t *count);
+
 ofono_bool_t __ofono_gprs_provision_get_settings(const char *mcc,
 				const char *mnc, const char *spn,
 				struct ofono_gprs_provision_data **settings,
diff --git a/src/provision.c b/src/provision.c
new file mode 100644
index 00000000..e419d15c
--- /dev/null
+++ b/src/provision.c
@@ -0,0 +1,73 @@ 
+/*
+ *  oFono - Open Source Telephony
+ *  Copyright (C) 2023  Cruise, LLC
+ *
+ *  SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stddef.h>
+
+#include "provisiondb.h"
+#include "ofono.h"
+
+static struct provision_db *pdb;
+
+bool __ofono_provision_get_settings(const char *mcc,
+				const char *mnc, const char *spn,
+				struct ofono_gprs_provision_data **settings,
+				size_t *count)
+{
+	size_t n_contexts;
+	struct ofono_gprs_provision_data *contexts;
+	int r;
+	size_t i;
+
+	if (mcc == NULL || strlen(mcc) == 0 || mnc == NULL || strlen(mnc) == 0)
+		return false;
+
+	r = provision_db_lookup(pdb, mcc, mnc, spn, &contexts, &n_contexts);
+	if (r < 0)
+		return false;
+
+	DBG("Obtained %zd contexts for %s%s, spn: %s",
+			n_contexts, mcc, mnc, spn);
+
+	for (i = 0; i < n_contexts; i++) {
+		struct ofono_gprs_provision_data *ap = contexts + i;
+
+		DBG("APN: %s, Type: %x, Proto: %x",
+				ap->apn, ap->type, ap->proto);
+
+		if (ap->type & OFONO_GPRS_CONTEXT_TYPE_MMS)
+			DBG("MMS Proxy: %s, MMSC: %s", ap->message_proxy,
+					ap->message_center);
+	}
+
+	*count = n_contexts;
+	*settings = contexts;
+
+	return true;
+}
+
+static int provision_init(void)
+{
+	DBG("");
+
+	pdb = provision_db_new_default();
+
+	if (!pdb)
+		l_warn("Unable to open provisioning database!");
+
+	return 0;
+}
+
+static void provision_exit(void)
+{
+	provision_db_free(pdb);
+}
+
+OFONO_MODULE(provision, provision_init, provision_exit)