All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] reopen once if open device failed
@ 2011-05-20  8:56 Caiwen Zhang
  2011-05-20 13:53 ` Marcel Holtmann
  0 siblings, 1 reply; 3+ messages in thread
From: Caiwen Zhang @ 2011-05-20  8:56 UTC (permalink / raw)
  To: ofono

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

(1) Sometimes when open the data device, it may fail. If open the data device failed,
retry once one second later.

(2) Fix Huawei NDIS modem gprs doesn't work issue

---
 plugins/huawei.c |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/plugins/huawei.c b/plugins/huawei.c
index e791718..6b2caa4 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -80,6 +80,7 @@ struct huawei_data {
 	gboolean ndis;
 	guint sim_poll_timeout;
 	guint sim_poll_count;
+	guint reopen_timeout;
 };
 
 #define MAX_SIM_POLL_COUNT 5
@@ -107,6 +108,11 @@ static void huawei_remove(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	if (data->reopen_timeout > 0) {
+		g_source_remove(data->reopen_timeout);
+		data->reopen_timeout = 0;
+	}
+
 	ofono_modem_set_data(modem, NULL);
 
 	if (data->modem)
@@ -465,6 +471,20 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static void huawei_disconnect(gpointer user_data);
+
+static gboolean reopen_callback(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct huawei_data *data = ofono_modem_get_data(modem);
+
+	huawei_disconnect(user_data);
+
+	data->reopen_timeout = 0;
+
+	return FALSE;
+}
+
 static void huawei_disconnect(gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -476,8 +496,17 @@ static void huawei_disconnect(gpointer user_data)
 	data->modem = NULL;
 
 	data->modem = open_device(modem, "Modem", "Modem: ");
-	if (data->modem == NULL)
+	/* retry once if failed */
+	if (data->modem == NULL) {
+		if (data->reopen_timeout == 0) {
+			data->reopen_timeout =
+				g_timeout_add_seconds(1, reopen_callback,
+					modem);
+
+			ofono_debug("open device failed, try to reopen it.");
+		}
 		return;
+	}
 
 	g_at_chat_set_disconnect_function(data->modem,
 						huawei_disconnect, modem);
@@ -559,6 +588,11 @@ static int huawei_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	if (data->reopen_timeout > 0) {
+		g_source_remove(data->reopen_timeout);
+		data->reopen_timeout = 0;
+	}
+
 	if (data->sim_poll_timeout > 0) {
 		g_source_remove(data->sim_poll_timeout);
 		data->sim_poll_timeout = 0;
@@ -682,16 +716,15 @@ static void huawei_post_online(struct ofono_modem *modem)
 	ofono_ussd_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
 						"atmodem", data->pcui);
 
-	if ((data->sim_state == HUAWEI_SIM_STATE_VALID ||
-			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) &&
-			data->modem != NULL) {
+	if (data->sim_state == HUAWEI_SIM_STATE_VALID ||
+			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {
 		data->gprs = ofono_gprs_create(modem, OFONO_VENDOR_HUAWEI,
 						"atmodem", data->pcui);
 
 		if (data->ndis == TRUE)
 			data->gc = ofono_gprs_context_create(modem, 0,
 						"huaweimodem", data->pcui);
-		else
+		else if (data->modem != NULL)
 			data->gc = ofono_gprs_context_create(modem, 0,
 						"atmodem", data->modem);
 
-- 
1.7.5


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

* Re: [PATCH v2] reopen once if open device failed
  2011-05-20  8:56 [PATCH v2] reopen once if open device failed Caiwen Zhang
@ 2011-05-20 13:53 ` Marcel Holtmann
  2011-05-23  2:49   ` Zhang, Caiwen
  0 siblings, 1 reply; 3+ messages in thread
From: Marcel Holtmann @ 2011-05-20 13:53 UTC (permalink / raw)
  To: ofono

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

Hi Caiwen,

> (1) Sometimes when open the data device, it may fail. If open the data device failed,
> retry once one second later.
> 
> (2) Fix Huawei NDIS modem gprs doesn't work issue

what does this comment mean. We should just not try the NDIS part of
Huawei until I get clear specs on how to use the NDIS port. Even the
basic AT^DHCP handling of this is unreliable.

> ---
>  plugins/huawei.c |   43 ++++++++++++++++++++++++++++++++++++++-----
>  1 files changed, 38 insertions(+), 5 deletions(-)
> 
> diff --git a/plugins/huawei.c b/plugins/huawei.c
> index e791718..6b2caa4 100644
> --- a/plugins/huawei.c
> +++ b/plugins/huawei.c
> @@ -80,6 +80,7 @@ struct huawei_data {
>  	gboolean ndis;
>  	guint sim_poll_timeout;
>  	guint sim_poll_count;
> +	guint reopen_timeout;
>  };
>  
>  #define MAX_SIM_POLL_COUNT 5
> @@ -107,6 +108,11 @@ static void huawei_remove(struct ofono_modem *modem)
>  
>  	DBG("%p", modem);
>  
> +	if (data->reopen_timeout > 0) {
> +		g_source_remove(data->reopen_timeout);
> +		data->reopen_timeout = 0;
> +	}
> +
>  	ofono_modem_set_data(modem, NULL);
>  
>  	if (data->modem)
> @@ -465,6 +471,20 @@ static GAtChat *open_device(struct ofono_modem *modem,
>  	return chat;
>  }
>  
> +static void huawei_disconnect(gpointer user_data);
> +
> +static gboolean reopen_callback(gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	struct huawei_data *data = ofono_modem_get_data(modem);
> +
> +	huawei_disconnect(user_data);
> +
> +	data->reopen_timeout = 0;
> +
> +	return FALSE;
> +}
> +
>  static void huawei_disconnect(gpointer user_data)
>  {
>  	struct ofono_modem *modem = user_data;
> @@ -476,8 +496,17 @@ static void huawei_disconnect(gpointer user_data)
>  	data->modem = NULL;
>  
>  	data->modem = open_device(modem, "Modem", "Modem: ");
> -	if (data->modem == NULL)
> +	/* retry once if failed */
> +	if (data->modem == NULL) {
> +		if (data->reopen_timeout == 0) {
> +			data->reopen_timeout =
> +				g_timeout_add_seconds(1, reopen_callback,
> +					modem);
> +
> +			ofono_debug("open device failed, try to reopen it.");
> +		}
>  		return;
> +	}

Please do not nest here.

	if (data->modem == NULL) {
		if (data->reopen_timeout > 0)
			return;

		data->reopen_timeout = ...

		return;
	}

>  
>  	g_at_chat_set_disconnect_function(data->modem,
>  						huawei_disconnect, modem);
> @@ -559,6 +588,11 @@ static int huawei_disable(struct ofono_modem *modem)
>  
>  	DBG("%p", modem);
>  
> +	if (data->reopen_timeout > 0) {
> +		g_source_remove(data->reopen_timeout);
> +		data->reopen_timeout = 0;
> +	}
> +
>  	if (data->sim_poll_timeout > 0) {
>  		g_source_remove(data->sim_poll_timeout);
>  		data->sim_poll_timeout = 0;
> @@ -682,16 +716,15 @@ static void huawei_post_online(struct ofono_modem *modem)
>  	ofono_ussd_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
>  						"atmodem", data->pcui);
>  
> -	if ((data->sim_state == HUAWEI_SIM_STATE_VALID ||
> -			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) &&
> -			data->modem != NULL) {
> +	if (data->sim_state == HUAWEI_SIM_STATE_VALID ||
> +			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {

Why this change?

>  		data->gprs = ofono_gprs_create(modem, OFONO_VENDOR_HUAWEI,
>  						"atmodem", data->pcui);
>  
>  		if (data->ndis == TRUE)
>  			data->gc = ofono_gprs_context_create(modem, 0,
>  						"huaweimodem", data->pcui);
> -		else
> +		else if (data->modem != NULL)
>  			data->gc = ofono_gprs_context_create(modem, 0,
>  						"atmodem", data->modem);
>  

I do not understand this change.

Regards

Marcel



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

* RE: [PATCH v2] reopen once if open device failed
  2011-05-20 13:53 ` Marcel Holtmann
@ 2011-05-23  2:49   ` Zhang, Caiwen
  0 siblings, 0 replies; 3+ messages in thread
From: Zhang, Caiwen @ 2011-05-23  2:49 UTC (permalink / raw)
  To: ofono

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



> >
> > (2) Fix Huawei NDIS modem gprs doesn't work issue
> 
> what does this comment mean. We should just not try the NDIS part of
> Huawei until I get clear specs on how to use the NDIS port. Even the
> basic AT^DHCP handling of this is unreliable.
> 

I find this issue when I get a Huawei EM820W modem. I see according current
Implementation, gprs atom and context will not be created, because if NDIS
is supported, no device opened for data transmission. Please refer to function 
huawei_enable() and post_online().

I don't have specs about how to use NDIS too. Here I just simply correct this
Issue.

> >
> > -	if ((data->sim_state == HUAWEI_SIM_STATE_VALID ||
> > -			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) &&
> > -			data->modem != NULL) {
> > +	if (data->sim_state == HUAWEI_SIM_STATE_VALID ||
> > +			data->sim_state == HUAWEI_SIM_STATE_INVALID_CS) {
> 
> Why this change?

As above comment, because data->modem will always be NULL for modems support NDIS.

> 
> >  		data->gprs = ofono_gprs_create(modem, OFONO_VENDOR_HUAWEI,
> >  						"atmodem", data->pcui);
> >
> >  		if (data->ndis == TRUE)
> >  			data->gc = ofono_gprs_context_create(modem, 0,
> >  						"huaweimodem", data->pcui);
> > -		else
> > +		else if (data->modem != NULL)
> >  			data->gc = ofono_gprs_context_create(modem, 0,
> >  						"atmodem", data->modem);
> >
> 
> I do not understand this change.
> 

data->modem may be NULL, due to open device fail. 

Best regards
Caiwen


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

end of thread, other threads:[~2011-05-23  2:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-20  8:56 [PATCH v2] reopen once if open device failed Caiwen Zhang
2011-05-20 13:53 ` Marcel Holtmann
2011-05-23  2:49   ` Zhang, Caiwen

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.