ofono.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH v2 05/11] modem: add implementation for the Capabilities property
Date: Fri, 22 Mar 2024 10:42:18 -0500	[thread overview]
Message-ID: <20240322154234.2720542-5-denkenz@gmail.com> (raw)
In-Reply-To: <20240322154234.2720542-1-denkenz@gmail.com>

The Capabilities property is made available via GetProperties() D-Bus
method.  It is also emitted prior to emitting the PropertyChanged signal
for the Powered property.  This ensures that any clients that might use
the capability information, will obtain it prior to the modem being
enabled / powered up.
---
 include/modem.h | 14 ++++++++++++++
 src/modem.c     | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/include/modem.h b/include/modem.h
index 1fa3df33544d..a70723a229a8 100644
--- a/include/modem.h
+++ b/include/modem.h
@@ -40,6 +40,10 @@ enum ofono_modem_type {
 	OFONO_MODEM_TYPE_TEST,
 };
 
+enum ofono_modem_capability {
+	OFONO_MODEM_CAPABILITY_LTE = 0x1,
+};
+
 typedef void (*ofono_modem_online_cb_t)(const struct ofono_error *error,
 					void *data);
 
@@ -134,6 +138,16 @@ ofono_bool_t ofono_modem_get_emergency_mode(struct ofono_modem *modem);
 void ofono_modem_set_name(struct ofono_modem *modem, const char *name);
 void ofono_modem_set_driver(struct ofono_modem *modem, const char *type);
 
+/*
+ * Set the capabilities of the modem.  This method should be called in
+ * the driver probe() method if the capability information can be obtained
+ * early, for example using the model information, or vid/pid of the device.
+ *
+ * Otherwise, it should be called prior to setting the device powered.
+ */
+void ofono_modem_set_capabilities(struct ofono_modem *modem,
+						unsigned int capabilities);
+
 int ofono_modem_set_string(struct ofono_modem *modem,
 				const char *key, const char *value);
 const char *ofono_modem_get_string(struct ofono_modem *modem, const char *key);
diff --git a/src/modem.c b/src/modem.c
index 24ab61761325..bfd5d7a81c45 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -88,6 +88,7 @@ struct ofono_modem {
 	void			*driver_data;
 	char			*driver_type;
 	char			*name;
+	unsigned int		capabilities;
 };
 
 struct ofono_devinfo {
@@ -162,6 +163,23 @@ static char **get_interfaces(struct ofono_modem *modem)
 	return interfaces;
 }
 
+static char **get_capabilities(struct ofono_modem *modem)
+{
+	char **capabilities;
+	unsigned int i = 0;
+
+	if (!modem->capabilities)
+		return NULL;
+
+	capabilities = l_new(char *,
+			__builtin_popcount(modem->capabilities) + 1);
+
+	if (modem->capabilities & OFONO_MODEM_CAPABILITY_LTE)
+		capabilities[i++] = "lte";
+
+	return capabilities;
+}
+
 unsigned int __ofono_modem_callid_next(struct ofono_modem *modem)
 {
 	unsigned int i;
@@ -849,6 +867,7 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 	dbus_bool_t emergency = ofono_modem_get_emergency_mode(modem);
 	const char *strtype;
 	const char *system_path;
+	char **capabilities;
 
 	ofono_dbus_dict_append(dict, "Online", DBUS_TYPE_BOOLEAN,
 				&modem->online);
@@ -910,6 +929,13 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 
 	strtype = modem_type_to_string(modem->driver->modem_type);
 	ofono_dbus_dict_append(dict, "Type", DBUS_TYPE_STRING, &strtype);
+
+	capabilities = get_capabilities(modem);
+	if (capabilities) {
+		ofono_dbus_dict_append_array(dict, "Capabilities",
+						DBUS_TYPE_STRING, &capabilities);
+		l_free(capabilities);
+	}
 }
 
 static DBusMessage *modem_get_properties(DBusConnection *conn,
@@ -1237,6 +1263,19 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		modem->timeout = 0;
 	}
 
+	if (powered && powered != modem->powered) {
+		char **capabilities = get_capabilities(modem);
+
+		if (capabilities) {
+			ofono_dbus_signal_array_property_changed(conn,
+						modem->path,
+						OFONO_MODEM_INTERFACE,
+						"Capabilities", DBUS_TYPE_STRING,
+						&capabilities);
+			l_free(capabilities);
+		}
+	}
+
 	if (modem->powered_pending != modem->powered &&
 						modem->pending != NULL) {
 		DBusMessage *reply;
@@ -1874,6 +1913,17 @@ void ofono_modem_set_driver(struct ofono_modem *modem, const char *type)
 	modem->driver_type = l_strdup(type);
 }
 
+void ofono_modem_set_capabilities(struct ofono_modem *modem,
+						unsigned int capabilities)
+{
+	if (!modem)
+		return;
+
+	DBG("%u", capabilities);
+
+	modem->capabilities = capabilities;
+}
+
 struct ofono_modem *ofono_modem_create(const char *name, const char *type)
 {
 	struct ofono_modem *modem;
-- 
2.43.0


  parent reply	other threads:[~2024-03-22 15:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 15:42 [PATCH v2 01/11] phonesim: Allow phonesim to work with Multiplexer=internal Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 02/11] modem: commonize feature string list generation Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 03/11] modem: commonize interface " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 04/11] doc: Add new Modem.Capabilities property Denis Kenzior
2024-03-22 15:42 ` Denis Kenzior [this message]
2024-03-22 15:42 ` [PATCH v2 06/11] phonesim: Set modem lte capable Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 07/11] gemalto: " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 08/11] xmm7xxx: Set modem as " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 09/11] ublox: Set modem " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 10/11] gobi: " Denis Kenzior
2024-03-22 15:42 ` [PATCH v2 11/11] quectel: " Denis Kenzior
2024-03-22 16:20 ` [PATCH v2 01/11] phonesim: Allow phonesim to work with Multiplexer=internal patchwork-bot+ofono

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240322154234.2720542-5-denkenz@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ofono@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).