Skip to contentSkip to conversation

huawei: reopen the GPRS context when the modem closes it after PPP

PATCH In review Kalle Valo 2 participants 3 messages Jun 29, 2010

lore
Share & tools
lore

Kalle Valo

author
#0 lore raw

PATCH 1/2 huawei: reopen the GPRS context when the modem closes it after PPP

Huawei always closes the tty port after PPP disconnect. Handle this in huawei plugin, similarly as done with novatel. Now there's no need to unplug the modem after disconnection.

Tested with Huawei E1552.

Based on a patch by Marcel Holtmann:

commit 0329a6ceaf8f69857cb5f8437b9db86ca327ef1d

Author: Marcel Holtmann <[email protected]>
Date:   Mon Jun 7 02:36:12 2010 -0700

Reopen the GPRS context channel when the modem closes it after PPP

---
 plugins/huawei.c |   86 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 62 insertions(+), 24 deletions(-)
plugins/huawei.c +62 -24
index e2dfd1e..ae0139a 100644
@@ -56,6 +56,8 @@ struct huawei_data {
 	GAtChat *pcui;
 	struct ofono_sim *sim;
 	gint sim_state;
+	struct ofono_gprs *gprs;
+	struct ofono_gprs_context *gc;
 };
 
 static int huawei_probe(struct ofono_modem *modem)
@@ -196,42 +198,80 @@ static GAtChat *create_port(const char *device)
 	return chat;
 }
 
-static int huawei_enable(struct ofono_modem *modem)
+static GAtChat *open_device(struct ofono_modem *modem,
+				const char *key, char *debug)
 {
 	struct huawei_data *data = ofono_modem_get_data(modem);
-	const char *modem_device, *pcui_device;
+	const char *device;
+	GAtChat *chat;
 
-	DBG("%p", modem);
+	device = ofono_modem_get_string(modem, key);
+	if (device == NULL)
+		return NULL;
 
-	modem_device = ofono_modem_get_string(modem, "Modem");
-	pcui_device = ofono_modem_get_string(modem, "Pcui");
+	DBG("%s %s", key, device);
 
-	if (modem_device == NULL || pcui_device == NULL)
-		return -EINVAL;
+	chat = create_port(device);
+	if (chat == NULL)
+		return NULL;
+
+	g_at_chat_add_terminator(chat, "COMMAND NOT SUPPORT", -1, FALSE);
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(chat, huawei_debug, debug);
+
+	return chat;
+}
+
+static void huawei_disconnect(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct huawei_data *data = ofono_modem_get_data(modem);
+
+	DBG("");
+
+	ofono_gprs_context_remove(data->gc);
 
-	data->modem = create_port(modem_device);
+	g_at_chat_unref(data->modem);
+	data->modem = NULL;
 
+	data->modem = open_device(modem, "Modem", "Modem:");
 	if (data->modem == NULL)
-		return -EIO;
+		return;
 
-	g_at_chat_add_terminator(data->modem, "COMMAND NOT SUPPORT", -1, FALSE);
+	g_at_chat_set_disconnect_function(data->modem,
+						huawei_disconnect, modem);
 
-	if (getenv("OFONO_AT_DEBUG"))
-		g_at_chat_set_debug(data->modem, huawei_debug, "Modem:");
+	ofono_info("Reopened GPRS context channel");
+
+	data->gc = ofono_gprs_context_create(modem, 0, "atmodem",
+							data->modem);
+
+	if (data->gprs && data->gc)
+		ofono_gprs_add_context(data->gprs, data->gc);
+}
+
+static int huawei_enable(struct ofono_modem *modem)
+{
+	struct huawei_data *data = ofono_modem_get_data(modem);
+	const char *modem_device, *pcui_device;
+
+	DBG("%p", modem);
+
+	data->modem = open_device(modem, "Modem", "Modem:");
+	if (data->modem == NULL)
+		return -EINVAL;
 
-	data->pcui = create_port(pcui_device);
+	g_at_chat_set_disconnect_function(data->modem,
+						huawei_disconnect, modem);
 
+	data->pcui = open_device(modem, "Pcui", "Pcui:");
 	if (data->pcui == NULL) {
 		g_at_chat_unref(data->modem);
 		data->modem = NULL;
 		return -EIO;
 	}
 
-	g_at_chat_add_terminator(data->pcui, "COMMAND NOT SUPPORT", -1, FALSE);
-
-	if (getenv("OFONO_AT_DEBUG"))
-		g_at_chat_set_debug(data->pcui, huawei_debug, "Pcui:");
-
 	data->sim_state = 0;
 
 	g_at_chat_send(data->pcui, "ATE0", none_prefix, NULL, NULL, NULL);
@@ -293,9 +333,7 @@ static void huawei_pre_sim(struct ofono_modem *modem)
 static void huawei_post_sim(struct ofono_modem *modem)
 {
 	struct huawei_data *data = ofono_modem_get_data(modem);
-	struct ofono_gprs_context *gc;
 	struct ofono_netreg *netreg;
-	struct ofono_gprs *gprs;
 
 	DBG("%p", modem);
 
@@ -307,11 +345,11 @@ static void huawei_post_sim(struct ofono_modem *modem)
 								data->pcui);
 	ofono_ussd_create(modem, 0, "atmodem", data->pcui);
 
-	gprs = ofono_gprs_create(modem, 0, "atmodem", data->pcui);
-	gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem);
+	data->gprs = ofono_gprs_create(modem, 0, "atmodem", data->pcui);
+	data->gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem);
 
-	if (gprs && gc)
-		ofono_gprs_add_context(gprs, gc);
+	if (data->gprs && data->gc)
+		ofono_gprs_add_context(data->gprs, data->gc);
 }
 
 static struct ofono_modem_driver huawei_driver = {
author
#1 lore raw

PATCH 2/2 PPP GPRS context is now done, update documentation

---
 TODO             |    7 -------
 doc/overview.txt |    6 ------
 2 files changed, 0 insertions(+), 13 deletions(-)
TODO +0 -7
index a25394a..470d4a6 100644
@@ -200,13 +200,6 @@ Flight Mode
 GPRS
 ====
 
-- PPP gprs-context driver support.  Add an implementation for 'atmodem' that
-  will use the GAtPPP stack to drive a GPRS context interface.  Nicely support
-  existing PPP based modems like Huawei, Novatel and Sierra.
-
-  Priority: High
-  Complexity: C2
-
 - PPP Server support.  Extend GAtPPP to support PPP Server role, similarly to
   how existing GSM modems support PPP GPRS contexts.
 
doc/overview.txt +0 -6
index cda9f68..a18e620 100644
@@ -130,12 +130,6 @@ Work in progress features:
 		User initiated USSD support is available, but not
 		network-initiated USSD support.
 
-	PPP
-
-		Modems that use PPP for data connections are currently not
-		supported.  This feature will be available once a functional
-		userspace ppp stack is available.
-
 Not implemented features:
 
 	SIM card storage
#2 lore raw
In reply to Kalle Valo

Hi Kalle,

Quoted 6 lines

Huawei always closes the tty port after PPP disconnect. Handle this in huawei plugin, similarly as done with novatel. Now there's no need to unplug the modem after disconnection.

Tested with Huawei E1552.

Quoted 7 lines

Based on a patch by Marcel Holtmann:

commit 0329a6ceaf8f69857cb5f8437b9db86ca327ef1d

Author: Marcel Holtmann <[email protected]>
Date:   Mon Jun 7 02:36:12 2010 -0700

Reopen the GPRS context channel when the modem closes it after PPP

Both have been applied, thanks.

Regards,
-Denis