All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Simplify ofono_modem_set_powered() logic
@ 2010-11-16 20:49 Gustavo F. Padovan
  2010-11-16 20:49 ` [PATCH 2/4] Add ofono_modem_reset() Gustavo F. Padovan
  2010-11-17 14:30 ` [PATCH 1/4] Simplify ofono_modem_set_powered() logic Denis Kenzior
  0 siblings, 2 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-11-16 20:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2315 bytes --]

---
 src/modem.c |   47 +++++++++++++++++++++++++----------------------
 1 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index 3776461..3fb6809 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -752,6 +752,7 @@ static GDBusSignalTable modem_signals[] = {
 void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
+	dbus_bool_t dbus_powered = powered;
 
 	if (modem->timeout > 0) {
 		g_source_remove(modem->timeout);
@@ -771,32 +772,34 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 
 	modem->powered_pending = powered;
 
-	if (modem->powered != powered) {
-		dbus_bool_t dbus_powered = powered;
-		modem->powered = powered;
+	if (modem->powered == powered)
+		goto out;
 
-		if (modem->driver == NULL) {
-			ofono_error("Calling ofono_modem_set_powered on a"
-					"modem with no driver is not valid, "
-					"please fix the modem driver.");
-			return;
-		}
+	modem->powered = powered;
 
-		ofono_dbus_signal_property_changed(conn, modem->path,
-						OFONO_MODEM_INTERFACE,
-						"Powered", DBUS_TYPE_BOOLEAN,
-						&dbus_powered);
+	if (modem->driver == NULL) {
+		ofono_error("Calling ofono_modem_set_powered on a"
+				"modem with no driver is not valid, "
+				"please fix the modem driver.");
+		return;
+	}
 
-		if (powered) {
-			modem_change_state(modem, MODEM_STATE_PRE_SIM);
+	ofono_dbus_signal_property_changed(conn, modem->path,
+					OFONO_MODEM_INTERFACE,
+					"Powered", DBUS_TYPE_BOOLEAN,
+					&dbus_powered);
 
-			/* Force SIM Ready for devies with no sim atom */
-			if (__ofono_modem_find_atom(modem,
-						OFONO_ATOM_TYPE_SIM) == NULL)
-				sim_state_watch(OFONO_SIM_STATE_READY, modem);
-		} else
-			modem_change_state(modem, MODEM_STATE_POWER_OFF);
-	}
+	if (powered) {
+		modem_change_state(modem, MODEM_STATE_PRE_SIM);
+
+		/* Force SIM Ready for devies with no sim atom */
+		if (__ofono_modem_find_atom(modem,
+					OFONO_ATOM_TYPE_SIM) == NULL)
+			sim_state_watch(OFONO_SIM_STATE_READY, modem);
+	} else
+		modem_change_state(modem, MODEM_STATE_POWER_OFF);
+
+out:
 
 	if (powering_down && powered == FALSE) {
 		modems_remaining -= 1;
-- 
1.7.3.1


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

* [PATCH 2/4] Add ofono_modem_reset()
  2010-11-16 20:49 [PATCH 1/4] Simplify ofono_modem_set_powered() logic Gustavo F. Padovan
@ 2010-11-16 20:49 ` Gustavo F. Padovan
  2010-11-16 20:49   ` [PATCH 3/4] phonesim: Add modem reset trigger Gustavo F. Padovan
  2010-11-17 14:30 ` [PATCH 1/4] Simplify ofono_modem_set_powered() logic Denis Kenzior
  1 sibling, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-11-16 20:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3101 bytes --]

Some modems can screw up everything and then we will need to do a silent
reset of the modem. This patch take the modem back to the OFFLINE state.
---
 include/modem.h |    2 ++
 src/modem.c     |   45 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/include/modem.h b/include/modem.h
index 7b13ee0..a92eb88 100644
--- a/include/modem.h
+++ b/include/modem.h
@@ -46,6 +46,8 @@ int ofono_modem_register(struct ofono_modem *modem);
 ofono_bool_t ofono_modem_is_registered(struct ofono_modem *modem);
 void ofono_modem_remove(struct ofono_modem *modem);
 
+void ofono_modem_reset(struct ofono_modem *modem);
+
 void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered);
 ofono_bool_t ofono_modem_get_powered(struct ofono_modem *modem);
 
diff --git a/src/modem.c b/src/modem.c
index 3fb6809..9ed52c1 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -70,6 +70,7 @@ struct ofono_modem {
 	guint			interface_update;
 	ofono_bool_t		powered;
 	ofono_bool_t		powered_pending;
+	ofono_bool_t		reset;
 	guint			timeout;
 	ofono_bool_t		online;
 	GHashTable		*properties;
@@ -433,6 +434,8 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *user)
 		if (modem->driver->set_online == NULL)
 			modem_change_state(modem, MODEM_STATE_ONLINE);
 
+		modem->reset = FALSE;
+
 		break;
 	}
 }
@@ -784,7 +787,8 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		return;
 	}
 
-	ofono_dbus_signal_property_changed(conn, modem->path,
+	if (!modem->reset)
+		ofono_dbus_signal_property_changed(conn, modem->path,
 					OFONO_MODEM_INTERFACE,
 					"Powered", DBUS_TYPE_BOOLEAN,
 					&dbus_powered);
@@ -799,14 +803,25 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 	} else
 		modem_change_state(modem, MODEM_STATE_POWER_OFF);
 
-out:
+	if (modem->reset && !powering_down) {
+		if (!modem->powered) {
+			int err = set_powered(modem, TRUE);
+
+			if (err == -EINPROGRESS)
+				return;
 
+			modem_change_state(modem, MODEM_STATE_PRE_SIM);
+		}
+	}
+
+out:
 	if (powering_down && powered == FALSE) {
 		modems_remaining -= 1;
 
 		if (modems_remaining == 0)
 			__ofono_exit();
 	}
+
 }
 
 ofono_bool_t ofono_modem_get_powered(struct ofono_modem *modem)
@@ -1566,6 +1581,32 @@ void ofono_modem_remove(struct ofono_modem *modem)
 	g_free(modem);
 }
 
+static gboolean __reset_modem(void *data)
+{
+	struct ofono_modem *modem = data;
+	int err;
+
+	modem->reset = TRUE;
+
+	err = set_powered(modem, FALSE);
+	if (err == -EINPROGRESS)
+		return FALSE;
+
+	err = set_powered(modem, TRUE);
+	if (err == -EINPROGRESS)
+		return FALSE;
+
+	modem_change_state(modem, MODEM_STATE_PRE_SIM);
+	return FALSE;
+}
+
+void ofono_modem_reset(struct ofono_modem *modem)
+{
+	DBG("%p", modem);
+
+	g_idle_add(__reset_modem, modem);
+}
+
 int ofono_modem_driver_register(const struct ofono_modem_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
-- 
1.7.3.1


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

* [PATCH 3/4] phonesim: Add modem reset trigger
  2010-11-16 20:49 ` [PATCH 2/4] Add ofono_modem_reset() Gustavo F. Padovan
@ 2010-11-16 20:49   ` Gustavo F. Padovan
  2010-11-16 20:49     ` [PATCH 4/4] modem: add support to restore state when resetting the modem Gustavo F. Padovan
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-11-16 20:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

---
 plugins/phonesim.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index d2faf42..7426da6 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -237,6 +237,13 @@ static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_modem_set_powered(modem, ok);
 }
 
+static void crst_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	ofono_modem_reset(modem);
+}
+
 static void phonesim_disconnected(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -389,6 +396,9 @@ static int phonesim_enable(struct ofono_modem *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);
+
 	return 0;
 }
 
-- 
1.7.3.1


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

* [PATCH 4/4] modem: add support to restore state when resetting the modem
  2010-11-16 20:49   ` [PATCH 3/4] phonesim: Add modem reset trigger Gustavo F. Padovan
@ 2010-11-16 20:49     ` Gustavo F. Padovan
  0 siblings, 0 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-11-16 20:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3307 bytes --]

---
 src/modem.c |   72 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index 9ed52c1..64500f6 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -61,6 +61,7 @@ enum modem_state {
 struct ofono_modem {
 	char			*path;
 	enum modem_state	modem_state;
+	enum modem_state	old_state;
 	GSList			*atoms;
 	struct ofono_watchlist	*atom_watches;
 	GSList			*interface_list;
@@ -414,48 +415,26 @@ static void modem_change_state(struct ofono_modem *modem,
 	}
 }
 
-static void sim_state_watch(enum ofono_sim_state new_state, void *user)
-{
-	struct ofono_modem *modem = user;
-
-	switch (new_state) {
-	case OFONO_SIM_STATE_NOT_PRESENT:
-		modem_change_state(modem, MODEM_STATE_PRE_SIM);
-		break;
-	case OFONO_SIM_STATE_INSERTED:
-		break;
-	case OFONO_SIM_STATE_READY:
-		modem_change_state(modem, MODEM_STATE_OFFLINE);
-
-		/*
-		 * If we don't have the set_online method, also proceed
-		 * straight to the online state
-		 */
-		if (modem->driver->set_online == NULL)
-			modem_change_state(modem, MODEM_STATE_ONLINE);
-
-		modem->reset = FALSE;
-
-		break;
-	}
-}
-
 static void online_cb(const struct ofono_error *error, void *data)
 {
 	struct ofono_modem *modem = data;
 	DBusMessage *reply;
 
 	if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
-			modem->modem_state == MODEM_STATE_OFFLINE)
+			modem->modem_state == MODEM_STATE_OFFLINE) {
+		modem_change_state(modem, MODEM_STATE_ONLINE);
+
+		if (modem->reset) {
+			modem->reset = FALSE;
+			return;
+		}
+
 		reply = dbus_message_new_method_return(modem->pending);
-	else
+	} else {
 		reply = __ofono_error_failed(modem->pending);
+	}
 
 	__ofono_dbus_pending_reply(&modem->pending, reply);
-
-	if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
-			modem->modem_state == MODEM_STATE_OFFLINE)
-		modem_change_state(modem, MODEM_STATE_ONLINE);
 }
 
 static void offline_cb(const struct ofono_error *error, void *data)
@@ -475,6 +454,34 @@ static void offline_cb(const struct ofono_error *error, void *data)
 		modem_change_state(modem, MODEM_STATE_OFFLINE);
 }
 
+static void sim_state_watch(enum ofono_sim_state new_state, void *user)
+{
+	struct ofono_modem *modem = user;
+
+	switch (new_state) {
+	case OFONO_SIM_STATE_NOT_PRESENT:
+		modem_change_state(modem, MODEM_STATE_PRE_SIM);
+		break;
+	case OFONO_SIM_STATE_INSERTED:
+		break;
+	case OFONO_SIM_STATE_READY:
+		modem_change_state(modem, MODEM_STATE_OFFLINE);
+
+		/*
+		 * If we don't have the set_online method, also proceed
+		 * straight to the online state
+		 */
+		if (modem->driver->set_online == NULL)
+			modem_change_state(modem, MODEM_STATE_ONLINE);
+		else if (modem->old_state > MODEM_STATE_OFFLINE)
+			modem->driver->set_online(modem, 1, online_cb, modem);
+		else
+			modem->reset = FALSE;
+
+		break;
+	}
+}
+
 static DBusMessage *set_property_online(struct ofono_modem *modem,
 					DBusMessage *msg,
 					DBusMessageIter *var)
@@ -1586,6 +1593,7 @@ static gboolean __reset_modem(void *data)
 	struct ofono_modem *modem = data;
 	int err;
 
+	modem->old_state = modem->modem_state;
 	modem->reset = TRUE;
 
 	err = set_powered(modem, FALSE);
-- 
1.7.3.1


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

* Re: [PATCH 1/4] Simplify ofono_modem_set_powered() logic
  2010-11-16 20:49 [PATCH 1/4] Simplify ofono_modem_set_powered() logic Gustavo F. Padovan
  2010-11-16 20:49 ` [PATCH 2/4] Add ofono_modem_reset() Gustavo F. Padovan
@ 2010-11-17 14:30 ` Denis Kenzior
  1 sibling, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2010-11-17 14:30 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]

Hi Gustavo,

On 11/16/2010 02:49 PM, Gustavo F. Padovan wrote:
> ---
>  src/modem.c |   47 +++++++++++++++++++++++++----------------------
>  1 files changed, 25 insertions(+), 22 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

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

end of thread, other threads:[~2010-11-17 14:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 20:49 [PATCH 1/4] Simplify ofono_modem_set_powered() logic Gustavo F. Padovan
2010-11-16 20:49 ` [PATCH 2/4] Add ofono_modem_reset() Gustavo F. Padovan
2010-11-16 20:49   ` [PATCH 3/4] phonesim: Add modem reset trigger Gustavo F. Padovan
2010-11-16 20:49     ` [PATCH 4/4] modem: add support to restore state when resetting the modem Gustavo F. Padovan
2010-11-17 14:30 ` [PATCH 1/4] Simplify ofono_modem_set_powered() logic Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.