Skip to contentSkip to conversation

modem: only unref pending if it is a powered pending

PATCH In review Gustavo F. Padovan 2 participants 14 messages Dec 3, 2010 – Dec 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 modem: only unref pending if it is a powered pending

---
 src/modem.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/modem.c +1 -1
index 52e647b..d6ab316 100644
@@ -804,7 +804,7 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		modem->timeout = 0;
 	}
 
-	if (modem->pending != NULL) {
+	if (modem->powered_pending != powered && modem->pending != NULL) {
 		DBusMessage *reply;
 
 		if (powered == modem->powered_pending)
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH 2/5 modem: add ofono_modem_reset() to modem.h

---
 include/modem.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/modem.h +2 -0
index 7b13ee0..a92eb88 100644
@@ -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);
 
Signature · 1 line
1.7.3.2
#2 lore raw

PATCH 3/5 Add ofono_modem_reset()

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.

---
 src/modem.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
src/modem.c +20 -0
index d6ab316..3126af1 100644
@@ -1615,6 +1615,26 @@ void ofono_modem_remove(struct ofono_modem *modem)
 	g_free(modem);
 }
 
+void ofono_modem_reset(struct ofono_modem *modem)
+{
+	int err;
+
+	DBG("%p", modem);
+
+	if (modem->pending) {
+		DBusMessage *reply = __ofono_error_failed(modem->pending);
+		__ofono_dbus_pending_reply(&modem->pending, reply);
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+	err = set_powered(modem, TRUE);
+	if (err == -EINPROGRESS)
+		return;
+
+	modem_change_state(modem, MODEM_STATE_PRE_SIM);
+}
+
 int ofono_modem_driver_register(const struct ofono_modem_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
Signature · 1 line
1.7.3.2
#3 lore raw

PATCH 4/5 phonesim: Add modem reset trigger

---
 plugins/phonesim.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
plugins/phonesim.c +27 -0
index 6b483ff..c7ef0d7 100644
@@ -374,6 +374,30 @@ static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_modem_set_powered(modem, ok);
 }
 
+static gboolean phonesim_reset(void *user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct phonesim_data *data = ofono_modem_get_data(modem);
+
+	g_at_chat_unref(data->chat);
+	data->chat = NULL;
+
+	if (data->mux) {
+		g_at_mux_shutdown(data->mux);
+		g_at_mux_unref(data->mux);
+		data->mux = NULL;
+	}
+
+	ofono_modem_reset(modem);
+
+	return FALSE;
+}
+
+static void crst_notify(GAtResult *result, gpointer user_data)
+{
+	g_idle_add(phonesim_reset, user_data);
+}
+
 static void phonesim_disconnected(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -526,6 +550,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;
 }
 
Signature · 1 line
1.7.3.2
#4 lore raw

PATCH 5/5 modem: add support to restore state when resetting the modem

---
 src/modem.c |   74 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 44 insertions(+), 30 deletions(-)
src/modem.c +44 -30
index 3126af1..638c33f 100644
@@ -70,6 +70,7 @@ struct ofono_modem {
 	guint			interface_update;
 	ofono_bool_t		powered;
 	ofono_bool_t		powered_pending;
+	ofono_bool_t		get_online;
 	guint			timeout;
 	ofono_bool_t		online;
 	struct ofono_watchlist	*online_watches;
@@ -434,30 +435,6 @@ 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);
-
-		break;
-	}
-}
-
 unsigned int __ofono_modem_add_online_watch(struct ofono_modem *modem,
 					ofono_modem_online_notify_func notify,
 					void *data, ofono_destroy_func destroy)
@@ -488,16 +465,22 @@ static void online_cb(const struct ofono_error *error, void *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->pending)
+			return;
+
 		reply = dbus_message_new_method_return(modem->pending);
-	else
+	} else {
+
+		if (!modem->pending)
+			return;
+
 		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)
@@ -517,6 +500,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->get_online)
+			modem->driver->set_online(modem, 1, online_cb, modem);
+
+		modem->get_online = FALSE;
+
+		break;
+	}
+}
+
 static DBusMessage *set_property_online(struct ofono_modem *modem,
 					DBusMessage *msg,
 					DBusMessageIter *var)
@@ -1626,6 +1637,9 @@ void ofono_modem_reset(struct ofono_modem *modem)
 		__ofono_dbus_pending_reply(&modem->pending, reply);
 	}
 
+	if (modem->modem_state == MODEM_STATE_ONLINE)
+		modem->get_online = TRUE;
+
 	ofono_modem_set_powered(modem, FALSE);
 
 	err = set_powered(modem, TRUE);
Signature · 1 line
1.7.3.2
#11 lore raw
In reply to Gustavo F. Padovan
Quoted 9 lines · Gustavo F. Padovan
---
 src/modem.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/modem.c +0 -0
index 52e647b..d6ab316 100644

src/modem.c void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered) · line 807

Quoted 5 lines
src/modem.c +1 -1
@@ -804,7 +804,7 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		modem->timeout = 0;
 	}
 
-	if (modem->pending != NULL) {
+	if (modem->powered_pending != powered && modem->pending != NULL) {

This one is wrong, I'll resend it. It should be modem->powered instead of powered.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#12 lore raw

PATCH 1/1 modem: only unref pending if it is a powered pending

In reply to Gustavo F. Padovan
---
 src/modem.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/modem.c +2 -1
index 52e647b..ae427b3 100644
@@ -804,7 +804,8 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		modem->timeout = 0;
 	}
 
-	if (modem->pending != NULL) {
+	if (modem->powered_pending != modem->powered &&
+						modem->pending != NULL) {
 		DBusMessage *reply;
 
 		if (powered == modem->powered_pending)
Signature · 1 line
1.7.3.2
#13 lore raw

Hi Gustavo,

Quoted 9 lines · Gustavo F. Padovan
---
 src/modem.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/modem.c +0 -0
index 52e647b..ae427b3 100644

src/modem.c void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered) · line 811

Quoted 9 lines
src/modem.c +2 -1
@@ -804,7 +804,8 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
 		modem->timeout = 0;
 	}
 
-	if (modem->pending != NULL) {
+	if (modem->powered_pending != modem->powered &&
+						modem->pending != NULL) {
 		DBusMessage *reply;
 
 		if (powered == modem->powered_pending)

Patch has been applied, thanks.

Regards,
-Denis

#10 lore raw

Re: [PATCH -v3 2/5] modem: add ofono_modem_reset() to modem.h

In reply to Gustavo F. Padovan

Hi Gustavo,

Quoted 4 lines · Gustavo F. Padovan
---
 include/modem.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#9 lore raw

Re: [PATCH -v3 3/5] Add ofono_modem_reset()

In reply to Gustavo F. Padovan

Hi Gustavo,

Quoted 6 lines · Gustavo F. Padovan

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.

---
 src/modem.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

Looks good to me. Patch has been applied, thanks.

Regards,
-Denis

#8 lore raw

Re: [PATCH -v3 4/5] phonesim: Add modem reset trigger

In reply to Gustavo F. Padovan

Hi Gustavo,

Quoted 4 lines · Gustavo F. Padovan
---
 plugins/phonesim.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#5 lore raw

Re: [PATCH -v3 5/5] modem: add support to restore state when resetting the modem

In reply to Gustavo F. Padovan

Hi Gustavo,

src/modem.c static void online_cb(const struct ofono_error *error, void *data) · line 469

Quoted 7 lines
src/modem.c +2 -1
@@ -488,16 +465,22 @@ static void online_cb(const struct ofono_error *error, void *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);

This actually breaks the (yet unwritten) rule to try to return from the method call before signaling the property changed.

Can you leave this be and add something like:

if (modem->pending == NULL)

	goto out;

or something prior to this if condition?

src/modem.c static void online_cb(const struct ofono_error *error, void *data) · line 473

Quoted 4 lines
src/modem.c +4 -0
+
+		if (!modem->pending)
+			return;
+

Then you can omit this

src/modem.c static void online_cb(const struct ofono_error *error, void *data) · line 479

Quoted 7 lines
src/modem.c +5 -1
 		reply = dbus_message_new_method_return(modem->pending);
-	else
+	} else {
+
+		if (!modem->pending)
+			return;
+

And this

src/modem.c static void online_cb(const struct ofono_error *error, void *data) · line 483

Quoted 4 lines
src/modem.c +1 -0
 		reply = __ofono_error_failed(modem->pending);
+	}
 
 	__ofono_dbus_pending_reply(&modem->pending, reply);

And just add a label here...

src/modem.c static void online_cb(const struct ofono_error *error, void *data) · line 486

Quoted 7 lines
src/modem.c +0 -4
-
-	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)

Regards,
-Denis

#6 lore raw

PATCH 1/1 modem: add support to restore state when resetting the modem

---
 src/modem.c |   60 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 24 deletions(-)
src/modem.c +36 -24
index 2f9387c..816443e 100644
@@ -70,6 +70,7 @@ struct ofono_modem {
 	guint			interface_update;
 	ofono_bool_t		powered;
 	ofono_bool_t		powered_pending;
+	ofono_bool_t		get_online;
 	guint			timeout;
 	ofono_bool_t		online;
 	struct ofono_watchlist	*online_watches;
@@ -434,30 +435,6 @@ 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);
-
-		break;
-	}
-}
-
 unsigned int __ofono_modem_add_online_watch(struct ofono_modem *modem,
 					ofono_modem_online_notify_func notify,
 					void *data, ofono_destroy_func destroy)
@@ -487,6 +464,9 @@ static void online_cb(const struct ofono_error *error, void *data)
 	struct ofono_modem *modem = data;
 	DBusMessage *reply;
 
+	if (!modem->pending)
+		goto out;
+
 	if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
 			modem->modem_state == MODEM_STATE_OFFLINE)
 		reply = dbus_message_new_method_return(modem->pending);
@@ -495,6 +475,7 @@ static void online_cb(const struct ofono_error *error, void *data)
 
 	__ofono_dbus_pending_reply(&modem->pending, reply);
 
+out:
 	if (error->type == OFONO_ERROR_TYPE_NO_ERROR &&
 			modem->modem_state == MODEM_STATE_OFFLINE)
 		modem_change_state(modem, MODEM_STATE_ONLINE);
@@ -517,6 +498,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->get_online)
+			modem->driver->set_online(modem, 1, online_cb, modem);
+
+		modem->get_online = FALSE;
+
+		break;
+	}
+}
+
 static DBusMessage *set_property_online(struct ofono_modem *modem,
 					DBusMessage *msg,
 					DBusMessageIter *var)
@@ -1627,6 +1636,9 @@ void ofono_modem_reset(struct ofono_modem *modem)
 		__ofono_dbus_pending_reply(&modem->pending, reply);
 	}
 
+	if (modem->modem_state == MODEM_STATE_ONLINE)
+		modem->get_online = TRUE;
+
 	ofono_modem_set_powered(modem, FALSE);
 
 	err = set_powered(modem, TRUE);
Signature · 1 line
1.7.3.2
#7 lore raw

Re: [PATCH] modem: add support to restore state when resetting the modem

Hi Gustavo,

Quoted 4 lines · Gustavo F. Padovan
---
 src/modem.c |   60 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 36 insertions(+), 24 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis