Skip to contentSkip to conversation

Huawei GPRS support

PATCH Superseded Kalle Valo 2 participants 8 messages May 20, 2010

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kalle Valo

author
#0 lore raw

v4 cover Huawei GPRS support

Hello,

here's v4 of Huawei GPRS support. Lots of whitespace cleanup, a memory leak fixed and a new function at_util_convert_signal_strength(). All based on comments from Denis.

---

Kalle Valo (3):
huawei: add gprs context
Move report_signal_strength to atutil
huawei: detect possible secondary device

 drivers/atmodem/atutil.h               |   12 +++
 drivers/atmodem/network-registration.c |    8 +-
 plugins/huawei.c                       |  129 +++++++++++++++++++++++++++++---
 plugins/udev.c                         |   61 +++++++++++++--
 4 files changed, 186 insertions(+), 24 deletions(-)
author
#1 lore raw

PATCH v4 1/3 huawei: detect possible secondary device

---

 plugins/huawei.c |   68 ++++++++++++++++++++++++++++++++++++++++++++----------
 plugins/udev.c   |   61 ++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 108 insertions(+), 21 deletions(-)
plugins/huawei.c +55 -13
index df4d177..2a95cf6 100644
@@ -45,7 +45,7 @@
 #include <drivers/atmodem/vendor.h>
 
 struct huawei_data {
-	GAtChat *chat;
+	GAtChat *chat, *event;
 };
 
 static int huawei_probe(struct ofono_modem *modem)
@@ -72,6 +72,7 @@ static void huawei_remove(struct ofono_modem *modem)
 	ofono_modem_set_data(modem, NULL);
 
 	g_at_chat_unref(data->chat);
+	g_at_chat_unref(data->event);
 	g_free(data);
 }
 
@@ -80,6 +81,11 @@ static void huawei_debug(const char *str, void *user_data)
 	ofono_info("%s", str);
 }
 
+static void huawei_event_debug(const char *str, void *user_data)
+{
+	ofono_info("* %s", str);
+}
+
 static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -90,29 +96,43 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 		ofono_modem_set_powered(modem, TRUE);
 }
 
-static int huawei_enable(struct ofono_modem *modem)
+static GAtChat *create_port(const char *device)
 {
-	struct huawei_data *data = ofono_modem_get_data(modem);
 	GAtSyntax *syntax;
 	GIOChannel *channel;
-	const char *device;
-
-	DBG("%p", modem);
-
-	device = ofono_modem_get_string(modem, "Device");
-	if (!device)
-			return -EINVAL;
+	GAtChat *chat;
 
 	channel = g_at_tty_open(device, NULL);
 	if (!channel)
-		return -EIO;
+		return NULL;
 
 	syntax = g_at_syntax_new_gsm_permissive();
-	data->chat = g_at_chat_new(channel, syntax);
+	chat = g_at_chat_new(channel, syntax);
 	g_at_syntax_unref(syntax);
 	g_io_channel_unref(channel);
 
-	if (!data->chat)
+	if (!chat)
+		return NULL;
+
+	return chat;
+}
+
+static int huawei_enable(struct ofono_modem *modem)
+{
+	struct huawei_data *data = ofono_modem_get_data(modem);
+	const char *modem_device, *event_device;
+
+	DBG("%p", modem);
+
+	modem_device = ofono_modem_get_string(modem, "Device");
+	event_device = ofono_modem_get_string(modem, "SecondaryDevice");
+
+	if (modem_device == NULL || event_device == NULL)
+		return -EINVAL;
+
+	data->chat = create_port(modem_device);
+
+	if (data->chat == NULL)
 		return -EIO;
 
 	g_at_chat_add_terminator(data->chat, "COMMAND NOT SUPPORT", -1, FALSE);
@@ -120,6 +140,20 @@ static int huawei_enable(struct ofono_modem *modem)
 	if (getenv("OFONO_AT_DEBUG"))
 		g_at_chat_set_debug(data->chat, huawei_debug, NULL);
 
+	data->event = create_port(modem_device);
+
+	if (data->event == NULL) {
+		g_at_chat_unref(data->chat);
+		data->chat = NULL;
+		return -EIO;
+	}
+
+	g_at_chat_add_terminator(data->event, "COMMAND NOT SUPPORT", -1,
+					FALSE);
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_chat_set_debug(data->event, huawei_event_debug, NULL);
+
 	g_at_chat_send(data->chat, "ATE0", NULL, NULL, NULL, NULL);
 
 	g_at_chat_send(data->chat, "AT+CFUN=1", NULL,
@@ -138,6 +172,9 @@ static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data)
 	g_at_chat_unref(data->chat);
 	data->chat = NULL;
 
+	g_at_chat_unref(data->event);
+	data->event = NULL;
+
 	if (ok)
 		ofono_modem_set_powered(modem, FALSE);
 }
@@ -148,6 +185,11 @@ static int huawei_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	if (data->event) {
+		g_at_chat_cancel_all(data->event);
+		g_at_chat_unregister_all(data->event);
+	}
+
 	if (!data->chat)
 		return 0;
 
plugins/udev.c +53 -8

77 lines not on this page · raw message

#2 lore raw

Re: [PATCH v4 1/3] huawei: detect possible secondary device

Hi Kalle,

plugins/huawei.c line 49

Quoted 5 lines

struct huawei_data {

plugins/huawei.c +1 -1
-	GAtChat *chat;
+	GAtChat *chat, *event;
 };

Minor nitpick, but we prefer:
GAtChat *chat;
GAtChat *event;

in structures.

plugins/huawei.c static void huawei_debug(const char *str, void · line 88

Quoted 9 lines
plugins/huawei.c +5 -0
@@ -80,6 +81,11 @@ static void huawei_debug(const char *str, void
 *user_data) ofono_info("%s", str);
 }
 
+static void huawei_event_debug(const char *str, void *user_data)
+{
+	ofono_info("* %s", str);
+}
+

There is no need for a separate function here. user_data can be used for this:

const char *prefix = user_data;
ofono_info("%s: %s", prefix, str);

Quoted 13 lines
plugins/huawei.c +9 -0
+	modem_device = ofono_modem_get_string(modem, "Device");
+	event_device = ofono_modem_get_string(modem, "SecondaryDevice");
+
+	if (modem_device == NULL || event_device == NULL)
+		return -EINVAL;
+
+	data->chat = create_port(modem_device);
+
+	if (data->chat == NULL)
 		return -EIO;
 
 	g_at_chat_add_terminator(data->chat, "COMMAND NOT SUPPORT", -1, FALSE);

plugins/huawei.c static int huawei_enable(struct ofono_modem *modem) · line 144

Quoted 5 lines
plugins/huawei.c +2 -0
@@ -120,6 +140,20 @@ static int huawei_enable(struct ofono_modem *modem)
 	if (getenv("OFONO_AT_DEBUG"))
 		g_at_chat_set_debug(data->chat, huawei_debug, NULL);
 
+	data->event = create_port(modem_device);
+

Event port using the modem device again?

plugins/huawei.c static int huawei_disable(struct ofono_modem *modem) · line 192

Quoted 5 lines
plugins/huawei.c +5 -0
+	if (data->event) {
+		g_at_chat_cancel_all(data->event);
+		g_at_chat_unregister_all(data->event);
+	}
+

You might want to unref event here instead of cfun_disable

Regards,
-Denis

author
#3 lore raw

Re: [PATCH v4 1/3] huawei: detect possible secondary device

Quoted 1 line · Denis Kenzior

Hi Kalle,

Hi Denis,

Quoted 11 lines

plugins/huawei.c line 49

Quoted 5 lines

struct huawei_data {

plugins/huawei.c +1 -1
-	GAtChat *chat;
+	GAtChat *chat, *event;
 };

Minor nitpick, but we prefer:
GAtChat *chat;
GAtChat *event;

in structures.

Changed.

Quoted 13 lines

plugins/huawei.c static void huawei_debug(const char *str, void · line 88

Quoted 9 lines
plugins/huawei.c +5 -0
@@ -80,6 +81,11 @@ static void huawei_debug(const char *str, void
 *user_data) ofono_info("%s", str);
 }
 
+static void huawei_event_debug(const char *str, void *user_data)
+{
+	ofono_info("* %s", str);
+}
+

There is no need for a separate function here. user_data can be used for this:

Quoted 2 lines

const char *prefix = user_data;
ofono_info("%s: %s", prefix, str);

I did it like this:

g_at_chat_set_debug(data->chat, huawei_debug, "");

g_at_chat_set_debug(data->event, huawei_debug, "EventChannel: ");

Quoted 8 lines

plugins/huawei.c static int huawei_enable(struct ofono_modem *modem) · line 144

Quoted 6 lines
plugins/huawei.c +2 -0
@@ -120,6 +140,20 @@ static int huawei_enable(struct ofono_modem *modem)
 	if (getenv("OFONO_AT_DEBUG"))
 		g_at_chat_set_debug(data->chat, huawei_debug, NULL);
 
+	data->event = create_port(modem_device);
+

Event port using the modem device again?

Good catch. I actually fixed this, but commited to the wrong patch. I moved that part now from patch 3 to patch 1.

Quoted 7 lines

plugins/huawei.c static int huawei_disable(struct ofono_modem *modem) · line 192

Quoted 5 lines
plugins/huawei.c +5 -0
+	if (data->event) {
+		g_at_chat_cancel_all(data->event);
+		g_at_chat_unregister_all(data->event);
+	}
+

You might want to unref event here instead of cfun_disable

Done.

Signature · 1 line
Kalle Valo
author
#4 lore raw

PATCH v4 2/3 Move report_signal_strength to atutil

In reply to Kalle Valo

The function is needed in two different places, better to move it to atutil.h.
---

 drivers/atmodem/atutil.h               |   12 ++++++++++++
 drivers/atmodem/network-registration.c |    4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)
drivers/atmodem/atutil.h +12 -0
index 9303ed4..265a5ad 100644
@@ -55,6 +55,18 @@ static inline struct cb_data *cb_data_new(void *cb, void *data)
 	return ret;
 }
 
+static inline int at_util_convert_signal_strength(int strength)
+{
+	int result;
+
+	if (strength == 99)
+		result = -1;
+	else
+		result = (strength * 100) / 31;
+
+	return result;
+}
+
 #define DECLARE_FAILURE(e) 			\
 	struct ofono_error e;			\
 	e.type = OFONO_ERROR_TYPE_FAILURE;	\
drivers/atmodem/network-registration.c +2 -2
index f7aafbe..ff94160 100644
@@ -473,7 +473,6 @@ static inline void report_signal_strength(struct ofono_netreg *netreg,
 	else
 		strength = (strength * 100) / 31;
 
-	ofono_netreg_strength_notify(netreg, strength);
 }
 
 static void csq_notify(GAtResult *result, gpointer user_data)
@@ -490,7 +489,8 @@ static void csq_notify(GAtResult *result, gpointer user_data)
 	if (!g_at_result_iter_next_number(&iter, &strength))
 		return;
 
-	report_signal_strength(netreg, strength);
+	ofono_netreg_strength_notify(netreg,
+				at_util_convert_signal_strength(strength));
 }
 
 static void calypso_csq_notify(GAtResult *result, gpointer user_data)
#5 lore raw

Re: [PATCH v4 2/3] Move report_signal_strength to atutil

Hi Kalle,

drivers/atmodem/network-registration.c static void csq_notify(GAtResult *result, gpointer · line 494

Quoted 10 lines

static void csq_notify(GAtResult *result, gpointer user_data)

drivers/atmodem/network-registration.c +2 -1
@@ -490,7 +489,8 @@ static void csq_notify(GAtResult *result, gpointer
 user_data) if (!g_at_result_iter_next_number(&iter, &strength))
 		return;
 
-	report_signal_strength(netreg, strength);
+	ofono_netreg_strength_notify(netreg,
+				at_util_convert_signal_strength(strength));
 }

How about fixing all other instances of report_signal_strength and removing it from this file as well? ;)

Regards,
-Denis

author
#6 lore raw

Re: [PATCH v4 2/3] Move report_signal_strength to atutil

Quoted 8 lines · Denis Kenzior

Hi Kalle,

Quoted 6 lines

static void csq_notify(GAtResult *result, gpointer user_data)

(quoted diff) +0 -0
@@ -490,7 +489,8 @@ static void csq_notify(GAtResult *result, gpointer
 user_data) if (!g_at_result_iter_next_number(&iter, &strength))
 		return;
 
Quoted 7 lines

drivers/atmodem/network-registration.c static void csq_notify(GAtResult *result, gpointer user_data) · line 494

Quoted 4 lines
drivers/atmodem/network-registration.c +2 -1
-	report_signal_strength(netreg, strength);
+	ofono_netreg_strength_notify(netreg,
+				at_util_convert_signal_strength(strength));
 }

How about fixing all other instances of report_signal_strength and removing it from this file as well? ;)

Oops, I totally forgot to remove the function network-registration.c. Fixed now.

Signature · 1 line
Kalle Valo
author
#7 lore raw

PATCH v4 3/3 huawei: add gprs context

In reply to Kalle Valo

Tested with Huawei E1552 HSDPA USB stick using a finnish Saunalahti prepaid SIM.
---

 drivers/atmodem/network-registration.c |    4 ++
 plugins/huawei.c                       |   63 +++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 2 deletions(-)
drivers/atmodem/network-registration.c +4 -0
index ff94160..777b3ee 100644
@@ -916,6 +916,10 @@ static void at_creg_set_cb(gboolean ok, GAtResult *result, gpointer user_data)
 				cind_support_cb, netreg, NULL);
 
 		break;
+	case OFONO_VENDOR_HUAWEI:
+		/* huawei doesn't support CIND */
+		ofono_netreg_register(netreg);
+		break;
 	default:
 		g_at_chat_send(nd->chat, "AT+CIND=?", cind_prefix,
 				cind_support_cb, netreg, NULL);
plugins/huawei.c +61 -2

89 lines not on this page · raw message