diff mbox series

[05/11] modem: add implementation for the Capabilities property

Message ID 20240322140942.2703042-5-denkenz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [01/11] phonesim: Allow phonesim to work with Multiplexer=internal | expand

Commit Message

Denis Kenzior March 22, 2024, 2:09 p.m. UTC
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     | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
diff mbox series

Patch

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 7486a56aa183..3744330a6225 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,22 @@  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));
+
+	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 +866,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 +928,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 +1262,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 +1912,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;