Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v4 0/6] Provider name and SID
@ 2012-01-18 17:05 Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 1/6] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

This version introduces a QCDM helper library.
Also, to simplify the QCDM handling, a dedicated callback is set for each
command sent.
Currently, we are not considering that a new command can be issued before the
answer from the previous command is handled. If this case occurs, then we would
need to introduce a command queue in the GAtHDLC structure to be able to invoke
properly the callbacks.

Philippe.    

Philippe Nunes (6):
  gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm
  huawei: Open qcdm port to fetch network status & SID
  gatqcdm: Add helper functions for QCDM handling
  huaweimodem: Probe the QCDM port with the version info request
  huaweimodem: Add 'serving_system' entry point to get SID
  udevng: Add a default assignment for Huawei QCDM port

 Makefile.am                       |    1 +
 drivers/huaweimodem/cdma-netreg.c |  174 ++++++++++++++++++++++++++++++++++---
 gatchat/gatchat.c                 |   26 ++++++
 gatchat/gatchat.h                 |    4 +
 gatchat/gatqcdm.c                 |   84 ++++++++++++++++++
 gatchat/gatqcdm.h                 |   57 ++++++++++++
 plugins/huawei.c                  |   44 +++++++++
 plugins/udevng.c                  |   30 +++++--
 8 files changed, 400 insertions(+), 20 deletions(-)
 create mode 100644 gatchat/gatqcdm.c
 create mode 100644 gatchat/gatqcdm.h


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

* [PATCH v4 1/6] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 2/6] huawei: Open qcdm port to fetch network status & SID Philippe Nunes
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

---
 gatchat/gatchat.c |   26 ++++++++++++++++++++++++++
 gatchat/gatchat.h |    4 ++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 7a0ef35..2fde572 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -35,6 +35,7 @@
 #include "ringbuffer.h"
 #include "gatchat.h"
 #include "gatio.h"
+#include "gathdlc.h"
 
 /* #define WRITE_SCHEDULER_DEBUG 1 */
 
@@ -110,6 +111,7 @@ struct _GAtChat {
 	struct at_chat *parent;
 	guint group;
 	GAtChat *slave;
+	GAtHDLC	*qcdm;
 };
 
 struct terminator_info {
@@ -1354,6 +1356,30 @@ GAtChat *g_at_chat_get_slave(GAtChat *chat)
 	return chat->slave;
 }
 
+GAtHDLC *g_at_chat_set_slave_qcdm(GAtChat *chat, GAtHDLC *diag)
+{
+	if (chat == NULL)
+		return NULL;
+
+	if (chat->qcdm != NULL)
+		g_at_hdlc_unref(chat->qcdm);
+
+	if (diag != NULL)
+		chat->qcdm = g_at_hdlc_ref(diag);
+	else
+		chat->qcdm = NULL;
+
+	return chat->qcdm;
+}
+
+GAtHDLC *g_at_chat_get_slave_qcdm(GAtChat *chat)
+{
+	if (chat == NULL)
+		return NULL;
+
+	return chat->qcdm;
+}
+
 GIOChannel *g_at_chat_get_channel(GAtChat *chat)
 {
 	if (chat == NULL || chat->parent->io == NULL)
diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h
index 367581e..496b3dc 100644
--- a/gatchat/gatchat.h
+++ b/gatchat/gatchat.h
@@ -30,6 +30,7 @@ extern "C" {
 #include "gatsyntax.h"
 #include "gatutil.h"
 #include "gatio.h"
+#include "gathdlc.h"
 
 struct _GAtChat;
 
@@ -68,6 +69,9 @@ GAtChat *g_at_chat_clone(GAtChat *chat);
 GAtChat *g_at_chat_set_slave(GAtChat *chat, GAtChat *slave);
 GAtChat *g_at_chat_get_slave(GAtChat *chat);
 
+GAtHDLC *g_at_chat_set_slave_qcdm(GAtChat *chat, GAtHDLC *diag);
+GAtHDLC *g_at_chat_get_slave_qcdm(GAtChat *chat);
+
 void g_at_chat_suspend(GAtChat *chat);
 void g_at_chat_resume(GAtChat *chat);
 
-- 
1.7.1


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

* [PATCH v4 2/6] huawei: Open qcdm port to fetch network status & SID
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 1/6] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 3/6] gatqcdm: Add helper functions for QCDM handling Philippe Nunes
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/plugins/huawei.c b/plugins/huawei.c
index 5d8875a..58f8832 100644
--- a/plugins/huawei.c
+++ b/plugins/huawei.c
@@ -78,6 +78,7 @@ enum {
 struct huawei_data {
 	GAtChat *modem;
 	GAtChat *pcui;
+	GAtHDLC *diag;
 	gboolean have_sim;
 	int sim_state;
 	guint sysinfo_poll_source;
@@ -120,6 +121,7 @@ static void huawei_remove(struct ofono_modem *modem)
 
 	/* Cleanup after hot-unplug */
 	g_at_chat_unref(data->pcui);
+	g_at_hdlc_unref(data->diag);
 
 	g_free(data);
 }
@@ -357,6 +359,9 @@ static void shutdown_device(struct huawei_data *data)
 	g_at_chat_unref(data->modem);
 	data->modem = NULL;
 
+	g_at_hdlc_unref(data->diag);
+	data->diag = NULL;
+
 	g_at_chat_cancel_all(data->pcui);
 	g_at_chat_unregister_all(data->pcui);
 
@@ -577,6 +582,38 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static GAtHDLC *open_qcdm(struct ofono_modem *modem)
+{
+	const char *device;
+	GIOChannel *channel;
+	GAtHDLC *hdlc;
+
+	device = ofono_modem_get_string(modem, "Diag");
+	if (device == NULL)
+		return NULL;
+
+	DBG("Diagnostic Monitor %s", device);
+
+	channel = g_at_tty_open_qcdm(device);
+	if (channel == NULL)
+		return NULL;
+
+	hdlc = g_at_hdlc_new(channel);
+
+	g_io_channel_unref(channel);
+
+	if (hdlc == NULL)
+		return NULL;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_hdlc_set_debug(hdlc, huawei_debug, "DIAG: ");
+
+	g_at_hdlc_set_xmit_accm(hdlc, 0);
+	g_at_hdlc_set_recv_accm(hdlc, 0);
+
+	return hdlc;
+}
+
 static int huawei_enable(struct ofono_modem *modem)
 {
 	struct huawei_data *data = ofono_modem_get_data(modem);
@@ -594,6 +631,10 @@ static int huawei_enable(struct ofono_modem *modem)
 		return -EIO;
 	}
 
+	data->diag = open_qcdm(modem);
+	if (data->diag != NULL)
+		g_at_chat_set_slave_qcdm(data->pcui, data->diag);
+
 	g_at_chat_set_slave(data->modem, data->pcui);
 
 	g_at_chat_send(data->modem, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
@@ -634,6 +675,9 @@ static int huawei_disable(struct ofono_modem *modem)
 	g_at_chat_unref(data->modem);
 	data->modem = NULL;
 
+	g_at_hdlc_unref(data->diag);
+	data->diag = NULL;
+
 	g_at_chat_cancel_all(data->pcui);
 	g_at_chat_unregister_all(data->pcui);
 
-- 
1.7.1


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

* [PATCH v4 3/6] gatqcdm: Add helper functions for QCDM handling
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 1/6] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 2/6] huawei: Open qcdm port to fetch network status & SID Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 4/6] huaweimodem: Probe the QCDM port with the version info request Philippe Nunes
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am       |    1 +
 gatchat/gatqcdm.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gatchat/gatqcdm.h |   57 ++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 gatchat/gatqcdm.c
 create mode 100644 gatchat/gatqcdm.h

diff --git a/Makefile.am b/Makefile.am
index 0472dfa..fc8bc42 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,6 +72,7 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \
 				gatchat/gatserver.h gatchat/gatserver.c \
 				gatchat/gatrawip.h gatchat/gatrawip.c \
 				gatchat/gathdlc.c gatchat/gathdlc.h \
+				gatchat/gatqcdm.c gatchat/gatqcdm.h \
 				gatchat/gatppp.c gatchat/gatppp.h \
 				gatchat/ppp.h gatchat/ppp_cp.h \
 				gatchat/ppp_cp.c gatchat/ppp_lcp.c \
diff --git a/gatchat/gatqcdm.c b/gatchat/gatqcdm.c
new file mode 100644
index 0000000..3941a8e
--- /dev/null
+++ b/gatchat/gatqcdm.c
@@ -0,0 +1,84 @@
+/*
+ *
+ *  AT chat library with GLib integration
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include "gatqcdm.h"
+
+#define QCDM_RESULT_VERSION_LENGTH	55
+#define QCDM_RESULT_STATUS_LENGTH	48
+
+#define QCDM_RESULT_STATUS_CDMA_RX_STATE_OFFSET	23
+#define QCDM_RESULT_STATUS_SID_OFFSET	39
+
+gboolean g_at_qcdm_send(GAtHDLC *hdlc, guint8 cmd, GAtReceiveFunc func,
+							gpointer user_data)
+{
+	unsigned char cmdbuf[1];
+
+	cmdbuf[0] = cmd;
+
+	g_at_hdlc_set_receive(hdlc, func, user_data);
+	return g_at_hdlc_send(hdlc, cmdbuf, sizeof(cmdbuf));
+}
+
+
+gboolean g_at_qcdm_result_get_version_info(const unsigned char *buf, gsize len,
+						struct version_info *verinfo)
+{
+	if (len < 1 || len > QCDM_RESULT_VERSION_LENGTH ||
+			buf[0] != G_AT_QCDM_CMD_VERSION_INFO)
+		return FALSE;
+
+	memcpy(verinfo->comp_date, buf+1, 11);
+	verinfo->comp_date[11] = '\0';
+	memcpy(verinfo->comp_time, buf+12, 8);
+	verinfo->comp_time[8] = '\0';
+	memcpy(verinfo->rel_date, buf+20, 11);
+	verinfo->rel_date[11] = '\0';
+	memcpy(verinfo->rel_time, buf+31, 8);
+	verinfo->rel_time[8] = '\0';
+	memcpy(verinfo->model, buf+39, 8);
+	verinfo->model[8] = '\0';
+	verinfo->msm_ver = buf[53];
+
+	return TRUE;
+}
+
+gboolean g_at_qcdm_result_parse_status(const unsigned char *buf, gsize len,
+						guint16 *sid)
+{
+	if (len < 1 || len > QCDM_RESULT_STATUS_LENGTH ||
+			buf[0] != G_AT_QCDM_CMD_STATUS)
+		return FALSE;
+
+	/* check if network is registered */
+	if (buf[QCDM_RESULT_STATUS_CDMA_RX_STATE_OFFSET] == 0)
+		return FALSE;
+
+	*sid = buf[QCDM_RESULT_STATUS_SID_OFFSET+1] << 8 |
+			buf[QCDM_RESULT_STATUS_SID_OFFSET];
+
+	return TRUE;
+}
diff --git a/gatchat/gatqcdm.h b/gatchat/gatqcdm.h
new file mode 100644
index 0000000..2e6cf46
--- /dev/null
+++ b/gatchat/gatqcdm.h
@@ -0,0 +1,57 @@
+/*
+ *
+ *  AT chat library with GLib integration
+ *
+ *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __G_AT_QCDM_H
+#define __G_AT_QCDM_H
+
+#include <glib.h>
+#include "gathdlc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define G_AT_QCDM_CMD_VERSION_INFO	0	/* Version info */
+#define G_AT_QCDM_CMD_STATUS		12	/* Station status */
+
+struct version_info {
+	char comp_date[12];
+	char comp_time[9];
+	char rel_date[12];
+	char rel_time[9];
+	char model[9];
+	guint8 msm_ver;
+};
+
+gboolean g_at_qcdm_send(GAtHDLC *hdlc, guint8 cmd, GAtReceiveFunc func,
+				gpointer user_data);
+
+gboolean g_at_qcdm_result_get_version_info(const unsigned char *buf, gsize len,
+						struct version_info *verinfo);
+
+gboolean g_at_qcdm_result_parse_status(const unsigned char *buf, gsize len,
+						guint16 *sid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __G_AT_QCDM_H */
-- 
1.7.1


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

* [PATCH v4 4/6] huaweimodem: Probe the QCDM port with the version info request
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
                   ` (2 preceding siblings ...)
  2012-01-18 17:05 ` [PATCH v4 3/6] gatqcdm: Add helper functions for QCDM handling Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 5/6] huaweimodem: Add 'serving_system' entry point to get SID Philippe Nunes
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

---
 drivers/huaweimodem/cdma-netreg.c |   66 ++++++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/drivers/huaweimodem/cdma-netreg.c b/drivers/huaweimodem/cdma-netreg.c
index 2ae66e1..bf48b53 100644
--- a/drivers/huaweimodem/cdma-netreg.c
+++ b/drivers/huaweimodem/cdma-netreg.c
@@ -24,6 +24,8 @@
 #endif
 
 #define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -32,11 +34,19 @@
 #include <ofono/cdma-netreg.h>
 
 #include "gatchat.h"
+#include "gatqcdm.h"
 
 #include "huaweimodem.h"
 
 static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
 
+struct netreg_data {
+	GAtChat *chat;
+	GAtHDLC *diag;
+	void *cb;
+	void *cb_data;
+};
+
 static gboolean parse_sysinfo(GAtResult *result, gint *status)
 {
 	GAtResultIter iter;
@@ -107,12 +117,34 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_cdma_netreg_status_notify(netreg, status);
 }
 
+static void version_info_cb(const unsigned char *buf, gsize len,
+							gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+	struct version_info verinfo;
+
+	if (!g_at_qcdm_result_get_version_info(buf, len, &verinfo)) {
+		/* This is probably not a QCDM port */
+		g_at_hdlc_unref(nd->diag);
+		nd->diag = NULL;
+		return;
+	}
+
+	DBG("Version information\n");
+	DBG("Compiled Date: %s\n", verinfo.comp_date);
+	DBG("Compiled Time: %s\n", verinfo.comp_time);
+	DBG("Release Date: %s\n", verinfo.rel_date);
+	DBG("Release Time: %s\n", verinfo.rel_time);
+	DBG("Model: %s\n", verinfo.model);
+	DBG("MSM version: %d\n", verinfo.msm_ver);
+}
 static void mode_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
-	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
 				sysinfo_cb, netreg, NULL);
 }
 
@@ -169,20 +201,20 @@ error:
 static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
 	if (!ok) {
 		ofono_cdma_netreg_remove(netreg);
 		return;
 	}
 
-	g_at_chat_register(chat, "^MODE:",
+	g_at_chat_register(nd->chat, "^MODE:",
 				mode_notify, FALSE, netreg, NULL);
 
-	g_at_chat_register(chat, "^RSSILVL:",
+	g_at_chat_register(nd->chat, "^RSSILVL:",
 				rssilvl_notify, FALSE, netreg, NULL);
 
-	g_at_chat_register(chat, "^HRSSILVL:",
+	g_at_chat_register(nd->chat, "^HRSSILVL:",
 				hrssilvl_notify, FALSE, netreg, NULL);
 
 	ofono_cdma_netreg_register(netreg);
@@ -191,23 +223,35 @@ static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
 static int huawei_cdma_netreg_probe(struct ofono_cdma_netreg *netreg,
 				unsigned int vendor, void *data)
 {
-	GAtChat *chat = g_at_chat_clone(data);
+	struct netreg_data *nd;
 
-	ofono_cdma_netreg_set_data(netreg, chat);
+	nd = g_new0(struct netreg_data, 1);
 
-	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
+	nd->chat = g_at_chat_clone(data);
+	nd->diag = g_at_chat_get_slave_qcdm(data);
+
+	ofono_cdma_netreg_set_data(netreg, nd);
+
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
 				probe_cb, netreg, NULL);
 
+	if (nd->diag)
+		/* Request version info to probe the QCDM port */
+		g_at_qcdm_send(nd->diag, G_AT_QCDM_CMD_VERSION_INFO,
+					version_info_cb, netreg);
+
 	return 0;
 }
 
 static void huawei_cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
 {
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
 	ofono_cdma_netreg_set_data(netreg, NULL);
 
-	g_at_chat_unref(chat);
+	g_at_chat_unref(nd->chat);
+	g_at_hdlc_unref(nd->diag);
+	g_free(nd);
 }
 
 static struct ofono_cdma_netreg_driver driver = {
-- 
1.7.1


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

* [PATCH v4 5/6] huaweimodem: Add 'serving_system' entry point to get SID
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
                   ` (3 preceding siblings ...)
  2012-01-18 17:05 ` [PATCH v4 4/6] huaweimodem: Probe the QCDM port with the version info request Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:05 ` [PATCH v4 6/6] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes
  2012-01-18 17:32 ` [PATCH v4 0/6] Provider name and SID Marcel Holtmann
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

---
 drivers/huaweimodem/cdma-netreg.c |  108 +++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/drivers/huaweimodem/cdma-netreg.c b/drivers/huaweimodem/cdma-netreg.c
index bf48b53..e9dd3e2 100644
--- a/drivers/huaweimodem/cdma-netreg.c
+++ b/drivers/huaweimodem/cdma-netreg.c
@@ -117,6 +117,66 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_cdma_netreg_status_notify(netreg, status);
 }
 
+static gboolean parse_css(GAtResult *result, const char **sid)
+{
+	GAtResultIter iter;
+	/*
+	* According TIA/EIA/IS-707, CSS query returns <AB>,<SID> but
+	* according TIA/EIA/IS-707-A , it returns <Band_Class>,<Band>,<SID>.
+	* PREV field which has been added afterward is ignored
+	*/
+
+	g_at_result_iter_init(&iter, result);
+
+	g_at_result_iter_next(&iter, NULL);
+
+	/* Skip first field since we are not interested in this */
+	if (!g_at_result_iter_skip_next(&iter))
+		return FALSE;
+
+	if (!g_at_result_iter_next_unquoted_string(&iter, sid))
+		return FALSE;
+	/*
+	* As CSS answer may differ according which revision of TIA/EIA/IS-707
+	* the modem is compliant, we need to check if this field is Band or SID
+	*/
+	if ((*sid[0] >= 'A' && *sid[0] <= 'F') || (*sid[0] == 'Z'))
+		/* This is the band field, the next field is the SID*/
+		if (!g_at_result_iter_next_unquoted_string(&iter, sid))
+			return FALSE;
+
+	if (!strcmp(*sid, "99999"))
+		/* The mobile station is not registered.*/
+		return FALSE;
+
+	return TRUE;
+}
+
+static void serving_system_cb(gboolean ok, GAtResult *result,
+				gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_cdma_netreg_serving_system_cb_t cb = cbd->cb;
+	struct ofono_error error;
+	const char *sid;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (!ok) {
+		cb(&error, NULL, cbd->data);
+		return;
+	}
+
+	if (parse_css(result, &sid) == FALSE) {
+		CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
+		return;
+	}
+
+	DBG("serving system: SID %s", sid);
+
+	cb(&error, sid, cbd->data);
+}
+
 static void version_info_cb(const unsigned char *buf, gsize len,
 							gpointer user_data)
 {
@@ -139,6 +199,32 @@ static void version_info_cb(const unsigned char *buf, gsize len,
 	DBG("Model: %s\n", verinfo.model);
 	DBG("MSM version: %d\n", verinfo.msm_ver);
 }
+
+static void status_cb(const unsigned char *buf, gsize len, gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+	ofono_cdma_netreg_serving_system_cb_t cb = nd->cb;
+	char str[6];
+	guint16 sid;
+
+	if (!g_at_qcdm_result_parse_status(buf, len, &sid)) {
+		/* fall back to use +CSS */
+		if (g_at_chat_send(nd->chat, "AT+CSS=?", NULL,
+				serving_system_cb, netreg, NULL) > 0)
+			return;
+
+		CALLBACK_WITH_FAILURE(cb, NULL, nd->cb_data);
+		return;
+	}
+
+	snprintf(str, 6, "%d", sid);
+	DBG("Status command response\n");
+	DBG("Serving Identification number: SID %s", str);
+
+	CALLBACK_WITH_SUCCESS(cb, str, nd->cb_data);
+}
+
 static void mode_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
@@ -254,10 +340,32 @@ static void huawei_cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
 	g_free(nd);
 }
 
+static void huaweicdma_netreg_serving_system(struct ofono_cdma_netreg *netreg,
+		ofono_cdma_netreg_serving_system_cb_t cb, void *data)
+{
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+	nd->cb = cb;
+	nd->cb_data = data;
+
+	/* First use QCDM port if any */
+	if (nd->diag) {
+		/* Request Station status */
+		if (g_at_qcdm_send(nd->diag, G_AT_QCDM_CMD_STATUS,
+				status_cb, netreg) > 0)
+			return;
+	} else if (g_at_chat_send(nd->chat, "AT+CSS=?", NULL,
+					serving_system_cb, netreg, NULL) > 0)
+		return;
+
+	CALLBACK_WITH_FAILURE(cb, NULL, data);
+}
+
 static struct ofono_cdma_netreg_driver driver = {
 	.name	= "huaweimodem",
 	.probe	= huawei_cdma_netreg_probe,
 	.remove	= huawei_cdma_netreg_remove,
+	.serving_system = huaweicdma_netreg_serving_system,
 };
 
 void huawei_cdma_netreg_init(void)
-- 
1.7.1


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

* [PATCH v4 6/6] udevng: Add a default assignment for Huawei QCDM port
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
                   ` (4 preceding siblings ...)
  2012-01-18 17:05 ` [PATCH v4 5/6] huaweimodem: Add 'serving_system' entry point to get SID Philippe Nunes
@ 2012-01-18 17:05 ` Philippe Nunes
  2012-01-18 17:32 ` [PATCH v4 0/6] Provider name and SID Marcel Holtmann
  6 siblings, 0 replies; 8+ messages in thread
From: Philippe Nunes @ 2012-01-18 17:05 UTC (permalink / raw)
  To: ofono

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

---
 plugins/udevng.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/plugins/udevng.c b/plugins/udevng.c
index 2a9200d..7b0d60f 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -237,6 +237,7 @@ static gboolean setup_sierra(struct modem_info *modem)
 static gboolean setup_huawei(struct modem_info *modem)
 {
 	const char *mdm = NULL, *pcui = NULL, *diag = NULL;
+	const char *default_pcui = NULL;
 	GSList *list;
 
 	DBG("%s", modem->syspath);
@@ -266,22 +267,33 @@ static gboolean setup_huawei(struct modem_info *modem)
 			if (mdm != NULL && pcui != NULL)
 				break;
 		} else if (g_strcmp0(info->interface, "255/255/255") == 0) {
-			if (g_strcmp0(info->number, "00") == 0)
+			if (mdm == NULL && g_strcmp0(info->number, "00") == 0)
 				mdm = info->devnode;
-			else if (g_strcmp0(info->number, "01") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "02") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "03") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "04") == 0)
-				pcui = info->devnode;
+			else if (diag == NULL) {
+				if (g_strcmp0(info->number, "01") == 0)
+					diag = info->devnode;
+			} else if (pcui == NULL) {
+				if (g_strcmp0(info->number, "01") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "02") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "03") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "04") == 0)
+					default_pcui = info->devnode;
+			}
 		}
 	}
 
+	if (pcui == NULL && default_pcui != NULL)
+		pcui = default_pcui;
+
 	if (mdm == NULL || pcui == NULL)
 		return FALSE;
 
+	if (diag != NULL && g_strcmp0(diag, pcui) == 0)
+		diag = NULL;
+
 	DBG("modem=%s pcui=%s diag=%s", mdm, pcui, diag);
 
 	ofono_modem_set_string(modem->modem, "Modem", mdm);
-- 
1.7.1


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

* Re: [PATCH v4 0/6] Provider name and SID
  2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
                   ` (5 preceding siblings ...)
  2012-01-18 17:05 ` [PATCH v4 6/6] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes
@ 2012-01-18 17:32 ` Marcel Holtmann
  6 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2012-01-18 17:32 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

> This version introduces a QCDM helper library.
> Also, to simplify the QCDM handling, a dedicated callback is set for each
> command sent.
> Currently, we are not considering that a new command can be issued before the
> answer from the previous command is handled. If this case occurs, then we would
> need to introduce a command queue in the GAtHDLC structure to be able to invoke
> properly the callbacks.

I would actually prefer if you create a clean GAtQCDM with proper queue
handling and a clean API. Command queue inside GAtHDLC is wrong since
that is not what HDLC actually is about.

Regards

Marcel



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

end of thread, other threads:[~2012-01-18 17:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18 17:05 [PATCH v4 0/6] Provider name and SID Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 1/6] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 2/6] huawei: Open qcdm port to fetch network status & SID Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 3/6] gatqcdm: Add helper functions for QCDM handling Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 4/6] huaweimodem: Probe the QCDM port with the version info request Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 5/6] huaweimodem: Add 'serving_system' entry point to get SID Philippe Nunes
2012-01-18 17:05 ` [PATCH v4 6/6] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes
2012-01-18 17:32 ` [PATCH v4 0/6] Provider name and SID Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox