Skip to contentSkip to conversation

phonesim: Allow phonesim to work with Multiplexer=internal

PATCH Superseded Denis Kenzior 1 participant 11 messages Mar 22, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/11 phonesim: Allow phonesim to work with Multiplexer=internal

If use_mux code path was used, certain commands (like querying of the SIM status) were not sent, resulting in incomplete modem initialization. Fix that.

---
 plugins/phonesim.c | 102 +++++++++++++++++++++++++--------------------
 1 file changed, 56 insertions(+), 46 deletions(-)
plugins/phonesim.c +56 -46
index 07afc14d56bb..29a983611d75 100644
@@ -512,13 +512,27 @@ static void usimstate_notify(GAtResult *result, gpointer user_data)
 	ofono_sim_inserted_notify(data->sim, inserted);
 }
 
-static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
+static void emulator_battery_cb(struct ofono_atom *atom, void *data)
 {
-	struct ofono_modem *modem = user_data;
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+	int val = 0;
 
-	DBG("");
+	if (GPOINTER_TO_INT(data) > 0)
+		val = (GPOINTER_TO_INT(data) - 1) / 20 + 1;
 
-	ofono_modem_set_powered(modem, ok);
+	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_BATTERY, val);
+}
+
+static void emulator_hfp_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *user_data)
+{
+	struct phonesim_data *data = user_data;
+
+	if (cond != OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+		return;
+
+	emulator_battery_cb(atom, GUINT_TO_POINTER(data->batt_level));
 }
 
 static gboolean phonesim_reset(void *user_data)
@@ -545,17 +559,6 @@ static void crst_notify(GAtResult *result, gpointer user_data)
 	g_idle_add(phonesim_reset, user_data);
 }
 
-static void emulator_battery_cb(struct ofono_atom *atom, void *data)
-{
-	struct ofono_emulator *em = __ofono_atom_get_data(atom);
-	int val = 0;
-
-	if (GPOINTER_TO_INT(data) > 0)
-		val = (GPOINTER_TO_INT(data) - 1) / 20 + 1;
-
-	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_BATTERY, val);
-}
-
 static void cbc_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -582,6 +585,43 @@ static void cbc_notify(GAtResult *result, gpointer user_data)
 						GUINT_TO_POINTER(level));
 }
 
+static void finish_powerup(struct ofono_modem *modem)
+{
+	struct phonesim_data *data = ofono_modem_get_data(modem);
+
+	g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix,
+			NULL, NULL, NULL);
+
+	g_at_chat_register(data->chat, "+CRST:",
+				crst_notify, FALSE, modem, NULL);
+
+	g_at_chat_register(data->chat, "+CBC:",
+				cbc_notify, FALSE, modem, NULL);
+
+	g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL);
+
+	g_at_chat_send(data->chat, "AT+SIMSTATE?", simstate_prefix,
+					simstate_query, modem, NULL);
+	g_at_chat_register(data->chat, "+USIMSTATE:", usimstate_notify,
+						FALSE, modem, NULL);
+
+	data->hfp_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_EMULATOR_HFP,
+					emulator_hfp_watch, data, NULL);
+}
+
+static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	DBG("");
+
+	ofono_modem_set_powered(modem, ok);
+
+	if (ok)
+		finish_powerup(modem);
+}
+
 static void phonesim_disconnected(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -644,18 +684,6 @@ static void mux_setup(GAtMux *mux, gpointer user_data)
 					cfun_set_on_cb, modem, NULL);
 }
 
-static void emulator_hfp_watch(struct ofono_atom *atom,
-				enum ofono_atom_watch_condition cond,
-				void *user_data)
-{
-	struct phonesim_data *data = user_data;
-
-	if (cond != OFONO_ATOM_WATCH_CONDITION_REGISTERED)
-		return;
-
-	emulator_battery_cb(atom, GUINT_TO_POINTER(data->batt_level));
-}
-
 static int connect_socket(const char *address, int port)
 {
 	struct sockaddr_in addr;
@@ -755,25 +783,7 @@ static int phonesim_enable(struct ofono_modem *modem)
 		return -EINPROGRESS;
 	}
 
-	g_at_chat_send(data->chat, "AT+CSCS=\"GSM\"", none_prefix,
-			NULL, NULL, NULL);
-
-	g_at_chat_register(data->chat, "+CRST:",
-				crst_notify, FALSE, modem, NULL);
-
-	g_at_chat_register(data->chat, "+CBC:",
-				cbc_notify, FALSE, modem, NULL);
-
-	g_at_chat_send(data->chat, "AT+CBC", none_prefix, NULL, NULL, NULL);
-
-	g_at_chat_send(data->chat, "AT+SIMSTATE?", simstate_prefix,
-					simstate_query, modem, NULL);
-	g_at_chat_register(data->chat, "+USIMSTATE:", usimstate_notify,
-						FALSE, modem, NULL);
-
-	data->hfp_watch = __ofono_modem_add_atom_watch(modem,
-					OFONO_ATOM_TYPE_EMULATOR_HFP,
-					emulator_hfp_watch, data, NULL);
+	finish_powerup(modem);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/11 modem: commonize feature string list generation

This code was repeated in multiple places, factor it out into a common function.

---
 src/modem.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
src/modem.c +16 -8
index 788e86fba0f6..37d9bd57fdd9 100644
@@ -137,6 +137,18 @@ static const char *modem_type_to_string(enum ofono_modem_type type)
 	return "unknown";
 }
 
+static char **get_features(struct ofono_modem *modem)
+{
+	char **features = l_new(char *, g_slist_length(modem->feature_list) + 1);
+	unsigned int i;
+	GSList *l;
+
+	for (i = 0, l = modem->feature_list; l; l = l->next, i++)
+		features[i] = l->data;
+
+	return features;
+}
+
 unsigned int __ofono_modem_callid_next(struct ofono_modem *modem)
 {
 	unsigned int i;
@@ -878,12 +890,10 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 					&interfaces);
 	g_free(interfaces);
 
-	features = g_new0(char *, g_slist_length(modem->feature_list) + 1);
-	for (i = 0, l = modem->feature_list; l; l = l->next, i++)
-		features[i] = l->data;
+	features = get_features(modem);
 	ofono_dbus_dict_append_array(dict, "Features", DBUS_TYPE_STRING,
 					&features);
-	g_free(features);
+	l_free(features);
 
 	if (modem->name)
 		ofono_dbus_dict_append(dict, "Name", DBUS_TYPE_STRING,
@@ -1303,14 +1313,12 @@ static gboolean trigger_interface_update(void *data)
 						&interfaces);
 	g_free(interfaces);
 
-	features = g_new0(char *, g_slist_length(modem->feature_list) + 1);
-	for (i = 0, l = modem->feature_list; l; l = l->next, i++)
-		features[i] = l->data;
+	features = get_features(modem);
 	ofono_dbus_signal_array_property_changed(conn, modem->path,
 						OFONO_MODEM_INTERFACE,
 						"Features", DBUS_TYPE_STRING,
 						&features);
-	g_free(features);
+	l_free(features);
 
 	modem->interface_update = 0;
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/11 modem: commonize interface string list generation

In reply to Denis Kenzior

This code was repeated in multiple places, factor it out into a common function.

---
 src/modem.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
src/modem.c +15 -10
index 37d9bd57fdd9..7486a56aa183 100644
@@ -149,6 +149,19 @@ static char **get_features(struct ofono_modem *modem)
 	return features;
 }
 
+static char **get_interfaces(struct ofono_modem *modem)
+{
+	char **interfaces = l_new(char *,
+				g_slist_length(modem->interface_list) + 1);
+	unsigned int i;
+	GSList *l;
+
+	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
+		interfaces[i] = l->data;
+
+	return interfaces;
+}
+
 unsigned int __ofono_modem_callid_next(struct ofono_modem *modem)
 {
 	unsigned int i;
@@ -832,8 +845,6 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 {
 	char **interfaces;
 	char **features;
-	int i;
-	GSList *l;
 	struct ofono_devinfo *info;
 	dbus_bool_t emergency = ofono_modem_get_emergency_mode(modem);
 	const char *strtype;
@@ -883,9 +894,7 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 		ofono_dbus_dict_append(dict, "SystemPath", DBUS_TYPE_STRING,
 					&system_path);
 
-	interfaces = g_new0(char *, g_slist_length(modem->interface_list) + 1);
-	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
-		interfaces[i] = l->data;
+	interfaces = get_interfaces(modem);
 	ofono_dbus_dict_append_array(dict, "Interfaces", DBUS_TYPE_STRING,
 					&interfaces);
 	g_free(interfaces);
@@ -1301,12 +1310,8 @@ static gboolean trigger_interface_update(void *data)
 	DBusConnection *conn = ofono_dbus_get_connection();
 	char **interfaces;
 	char **features;
-	GSList *l;
-	int i;
 
-	interfaces = g_new0(char *, g_slist_length(modem->interface_list) + 1);
-	for (i = 0, l = modem->interface_list; l; l = l->next, i++)
-		interfaces[i] = l->data;
+	interfaces = get_interfaces(modem);
 	ofono_dbus_signal_array_property_changed(conn, modem->path,
 						OFONO_MODEM_INTERFACE,
 						"Interfaces", DBUS_TYPE_STRING,
Signature · 1 line
2.43.0
#3 lore raw

PATCH 4/11 doc: Add new Modem.Capabilities property

In reply to Denis Kenzior

The intent of this property is to give an early hint to external clients, such as ConnMan, about this modem's capabilities such that the clients can modify their behavior accordingly. For example, ConnMan might choose to drive the modem slightly differently if it knows that a modem is LTE capable.

---
 doc/modem-api.txt | 6 ++++++
 1 file changed, 6 insertions(+)
doc/modem-api.txt +6 -0
index ff9facdce422..69108ab0057d 100644
@@ -182,3 +182,9 @@ Properties	boolean Powered [readwrite]
 			supported by this modem.
 
 			Possible values are "test", "hfp", "sap" and "hardware".
+
+		array{string} Capabilities [readonly, optional]
+
+			Contains the capabilities of this modem.
+
+			Possible values are "lte".
Signature · 1 line
2.43.0
#4 lore raw

PATCH 5/11 modem: add implementation for the Capabilities property

In reply to Denis Kenzior

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(+)
include/modem.h +14 -0
index 1fa3df33544d..a70723a229a8 100644
@@ -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);
src/modem.c +49 -0

85 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

PATCH 6/11 phonesim: Set modem lte capable

In reply to Denis Kenzior
---
 plugins/phonesim.c | 1 +
 1 file changed, 1 insertion(+)
plugins/phonesim.c +1 -0
index 29a983611d75..ac83e88fa3d4 100644
@@ -447,6 +447,7 @@ static int phonesim_probe(struct ofono_modem *modem)
 		return -ENOMEM;
 
 	ofono_modem_set_data(modem, data);
+	ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#6 lore raw

PATCH 7/11 gemalto: Set modem lte capable

In reply to Denis Kenzior
---
 plugins/gemalto.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
plugins/gemalto.c +7 -1
index 358d56a7aaf1..219354f7300e 100644
@@ -217,11 +217,17 @@ static void sim_state_cb(gboolean present, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
 	struct gemalto_data *data = ofono_modem_get_data(modem);
+	const char *model = ofono_modem_get_string(modem, "Model");
 
 	at_util_sim_state_query_free(data->sim_state_query);
 	data->sim_state_query = NULL;
 
 	data->have_sim = present;
+
+	if (!g_strcmp0(model, GEMALTO_MODEL_ALS3_PLS8x) ||
+			!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
+		ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
+
 	ofono_modem_set_powered(modem, TRUE);
 
 	/* Register for specific sim status reports */
@@ -609,7 +615,7 @@ static void gemalto_post_sim(struct ofono_modem *modem)
 		ofono_gprs_add_context(gprs, gc);
 
 	if (!g_strcmp0(model, GEMALTO_MODEL_ALS3_PLS8x) ||
-	    !g_strcmp0(model, GEMALTO_MODEL_ELS81x))
+			!g_strcmp0(model, GEMALTO_MODEL_ELS81x))
 		ofono_lte_create(modem, OFONO_VENDOR_GEMALTO,
 						"atmodem", data->app);
 }
Signature · 1 line
2.43.0
#7 lore raw

PATCH 8/11 xmm7xxx: Set modem as lte capable

In reply to Denis Kenzior
---
 plugins/xmm7xxx.c | 1 +
 1 file changed, 1 insertion(+)
plugins/xmm7xxx.c +1 -0
index 871c964c03b8..a02f1f5aa027 100644
@@ -1682,6 +1682,7 @@ static int xmm7xxx_probe(struct ofono_modem *modem)
 		return -ENOMEM;
 
 	ofono_modem_set_data(modem, data);
+	ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#8 lore raw

PATCH 9/11 ublox: Set modem lte capable

In reply to Denis Kenzior
---
 plugins/ublox.c | 1 +
 1 file changed, 1 insertion(+)
plugins/ublox.c +1 -0
index c5661ab6b1ad..c2fab0e7184e 100644
@@ -91,6 +91,7 @@ static int ublox_probe(struct ofono_modem *modem)
 		return -ENOMEM;
 
 	ofono_modem_set_data(modem, data);
+	ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#9 lore raw

PATCH 10/11 gobi: Set modem lte capable

In reply to Denis Kenzior
---
 plugins/gobi.c | 1 +
 1 file changed, 1 insertion(+)
plugins/gobi.c +1 -0
index 8d3b7ef4cdfc..7a07b080d895 100644
@@ -117,6 +117,7 @@ static int gobi_probe(struct ofono_modem *modem)
 	DBG("net: %s (%d)", data->main_net_name, data->main_net_ifindex);
 
 	ofono_modem_set_data(modem, data);
+	ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
 
 	return 0;
 }
Signature · 1 line
2.43.0
#10 lore raw

PATCH 11/11 quectel: Set modem lte capable

In reply to Denis Kenzior
---
 plugins/quectel.c | 4 ++++
 1 file changed, 4 insertions(+)
plugins/quectel.c +4 -0
index 69e1ff48729d..18cc33123759 100644
@@ -648,6 +648,10 @@ static void qinistat_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	}
 
 	data->sim_ready = true;
+
+	if (quectel_model_supports_lte(data->model))
+		ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE);
+
 	ofono_modem_set_powered(modem, TRUE);
 }
 
Signature · 1 line
2.43.0