Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v3 00/10] Provider name and SID
@ 2011-12-14 17:56 Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 01/10] cdma-provision: Add driver APIs header Philippe Nunes
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

This version is mainly focused by naming changes for consistency.

Philippe.

Philippe Nunes (10):
  cdma-provision: Add driver APIs header
  ofono.h: add API to get cdma provider name
  cdma-provision: Add driver APIs implementation
  cdma-provision: Add cdma provisioning plugin
  cdma-netreg: Add provider name and SID support
  gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm
  huaweicdma: Open qcdm port to be used for network status and cell
    location
  huaweicdmamodem: Probe the QCDM port with the version info request
  huaweicdmamodem: Add 'serving_system' entry point to get SID
  udevng: Add a default assignment for Huawei QCDM port

 Makefile.am                                    |    4 +-
 drivers/huaweicdmamodem/network-registration.c |  247 ++++++++++++++++++++++-
 gatchat/gatchat.c                              |   26 +++
 gatchat/gatchat.h                              |    4 +
 include/cdma-provision.h                       |   44 +++++
 plugins/cdma-provision.c                       |   79 ++++++++
 plugins/huaweicdma.c                           |   44 +++++
 plugins/udevng.c                               |   30 ++-
 src/cdma-netreg.c                              |   40 ++++
 src/cdma-provision.c                           |   80 ++++++++
 src/ofono.h                                    |    4 +
 11 files changed, 580 insertions(+), 22 deletions(-)
 create mode 100644 include/cdma-provision.h
 create mode 100644 plugins/cdma-provision.c
 create mode 100644 src/cdma-provision.c


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

* [PATCH v3 01/10] cdma-provision: Add driver APIs header
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 02/10] ofono.h: add API to get cdma provider name Philippe Nunes
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 include/cdma-provision.h |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
 create mode 100644 include/cdma-provision.h

diff --git a/include/cdma-provision.h b/include/cdma-provision.h
new file mode 100644
index 0000000..a6d5765
--- /dev/null
+++ b/include/cdma-provision.h
@@ -0,0 +1,44 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  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 __OFONO_CDMA_PROVISION_H
+#define __OFONO_CDMA_PROVISION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ofono_cdma_provision_driver {
+	const char *name;
+	int priority;
+	int (*get_provider_name)(const char *sid, char **name);
+};
+
+int ofono_cdma_provision_driver_register(
+		const struct ofono_cdma_provision_driver *driver);
+void ofono_cdma_provision_driver_unregister(
+		const struct ofono_cdma_provision_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_CDMA_PROVISION_H */
-- 
1.7.1


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

* [PATCH v3 02/10] ofono.h: add API to get cdma provider name
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 01/10] cdma-provision: Add driver APIs header Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 03/10] cdma-provision: Add driver APIs implementation Philippe Nunes
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 src/ofono.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index bfb534d..14cf4dd 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -487,6 +487,10 @@ void __ofono_gprs_provision_free_settings(
 #include <ofono/gnss.h>
 #include <ofono/cdma-sms.h>
 #include <ofono/cdma-netreg.h>
+
+#include <ofono/cdma-provision.h>
+ofono_bool_t __ofono_cdma_provision_get_name(const char *sid, char **name);
+
 #include <ofono/private-network.h>
 
 void __ofono_private_network_release(int id);
-- 
1.7.1


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

* [PATCH v3 03/10] cdma-provision: Add driver APIs implementation
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 01/10] cdma-provision: Add driver APIs header Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 02/10] ofono.h: add API to get cdma provider name Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 04/10] cdma-provision: Add cdma provisioning plugin Philippe Nunes
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am          |    4 +-
 src/cdma-provision.c |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100644 src/cdma-provision.c

diff --git a/Makefile.am b/Makefile.am
index 337aeb7..f276a41 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,7 +18,7 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/location-reporting.h \
 			include/cdma-connman.h include/gnss.h \
 			include/private-network.h include/cdma-netreg.h \
-			include/handsfree.h
+			include/cdma-provision.h include/handsfree.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
@@ -430,7 +430,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
 			src/gnssagent.c src/gnssagent.h \
 			src/cdma-smsutil.h src/cdma-smsutil.c \
 			src/cdma-sms.c src/private-network.c src/cdma-netreg.c \
-			src/handsfree.c
+			src/cdma-provision.c src/handsfree.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/cdma-provision.c b/src/cdma-provision.c
new file mode 100644
index 0000000..33b31b0
--- /dev/null
+++ b/src/cdma-provision.c
@@ -0,0 +1,80 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  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 <glib.h>
+#include "ofono.h"
+
+static GSList *g_drivers = NULL;
+
+ofono_bool_t __ofono_cdma_provision_get_name(const char *sid, char **name)
+{
+	GSList *d;
+
+	if (sid == NULL || strlen(sid) == 0)
+		return FALSE;
+
+	for (d = g_drivers; d != NULL; d = d->next) {
+		const struct ofono_cdma_provision_driver *driver = d->data;
+
+		if (driver->get_provider_name == NULL)
+			continue;
+
+		DBG("Calling cdma provision plugin '%s'", driver->name);
+
+		if (driver->get_provider_name(sid, name) < 0)
+			continue;
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+	const struct ofono_cdma_provision_driver *plugin1 = a;
+	const struct ofono_cdma_provision_driver *plugin2 = b;
+
+	return plugin2->priority - plugin1->priority;
+}
+
+int ofono_cdma_provision_driver_register(
+		const struct ofono_cdma_provision_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	g_drivers = g_slist_insert_sorted(g_drivers, (void *) driver,
+						compare_priority);
+	return 0;
+}
+
+void ofono_cdma_provision_driver_unregister(
+		const struct ofono_cdma_provision_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	g_drivers = g_slist_remove(g_drivers, driver);
+}
-- 
1.7.1


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

* [PATCH v3 04/10] cdma-provision: Add cdma provisioning plugin
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (2 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 03/10] cdma-provision: Add driver APIs implementation Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 05/10] cdma-netreg: Add provider name and SID support Philippe Nunes
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 plugins/cdma-provision.c |   79 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)
 create mode 100644 plugins/cdma-provision.c

diff --git a/plugins/cdma-provision.c b/plugins/cdma-provision.c
new file mode 100644
index 0000000..1ac7be7
--- /dev/null
+++ b/plugins/cdma-provision.c
@@ -0,0 +1,79 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  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 <errno.h>
+#include <string.h>
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/types.h>
+#include <ofono/log.h>
+#include <ofono/plugin.h>
+#include <ofono/modem.h>
+#include <ofono/gprs-provision.h>
+#include <ofono/cdma-provision.h>
+
+#include "mbpi.h"
+
+static int cdma_provision_get_provider_name(const char *sid, char **name)
+{
+	GError *error = NULL;
+
+	DBG("Search provider name for SID %s", sid);
+
+	*name = mbpi_lookup_cdma_provider_name(sid, &error);
+	if (*name == NULL) {
+		if (error != NULL) {
+			ofono_error("%s", error->message);
+			g_error_free(error);
+		}
+
+		return -ENOENT;
+	}
+
+	DBG("Found provider name: %s", *name);
+
+	return 0;
+}
+
+static struct ofono_cdma_provision_driver provision_driver = {
+	.name = "CDMA provisioning",
+	.get_provider_name = cdma_provision_get_provider_name
+};
+
+static int cdma_provision_init(void)
+{
+	return ofono_cdma_provision_driver_register(&provision_driver);
+}
+
+static void cdma_provision_exit(void)
+{
+	ofono_cdma_provision_driver_unregister(&provision_driver);
+}
+
+OFONO_PLUGIN_DEFINE(cdma_provision, "CDMA provisioning Plugin", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT,
+			cdma_provision_init, cdma_provision_exit)
-- 
1.7.1


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

* [PATCH v3 05/10] cdma-netreg: Add provider name and SID support
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (3 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 04/10] cdma-provision: Add cdma provisioning plugin Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2012-01-07 18:51   ` Denis Kenzior
  2011-12-14 17:56 ` [PATCH v3 06/10] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 src/cdma-netreg.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/cdma-netreg.c b/src/cdma-netreg.c
index 222c3b7..1a88d33 100644
--- a/src/cdma-netreg.c
+++ b/src/cdma-netreg.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <errno.h>
+#include <string.h>
 
 #include <gdbus.h>
 
@@ -38,6 +39,8 @@ struct ofono_cdma_netreg {
 	const struct ofono_cdma_netreg_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	char *provider_name;
+	char *sid;
 };
 
 static const char *cdma_netreg_status_to_string(enum cdma_netreg_status status)
@@ -90,6 +93,15 @@ static DBusMessage *network_get_properties(DBusConnection *conn,
 					&strength);
 	}
 
+	if (cdma_netreg->sid)
+		ofono_dbus_dict_append(&dict, "SystemIdentifier",
+						DBUS_TYPE_STRING,
+						&cdma_netreg->sid);
+
+	if (cdma_netreg->provider_name)
+		ofono_dbus_dict_append(&dict, "Name", DBUS_TYPE_STRING,
+						&cdma_netreg->provider_name);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
@@ -108,6 +120,8 @@ static void serving_system_callback(const struct ofono_error *error,
 					const char *sid, void *data)
 {
 	struct ofono_cdma_netreg *cdma_netreg = data;
+	const char *path = __ofono_atom_get_path(cdma_netreg->atom);
+	DBusConnection *conn = ofono_dbus_get_connection();
 
 	if (cdma_netreg->status != CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED
 			&& cdma_netreg->status !=
@@ -120,6 +134,30 @@ static void serving_system_callback(const struct ofono_error *error,
 	}
 
 	DBG("Serving system Identifier: %s", sid);
+
+	if (cdma_netreg->sid != NULL && !strcmp(cdma_netreg->sid, sid))
+		return;
+
+	g_free(cdma_netreg->provider_name);
+	g_free(cdma_netreg->sid);
+	cdma_netreg->provider_name = NULL;
+	cdma_netreg->sid = g_strdup(sid);
+
+	ofono_dbus_signal_property_changed(conn, path,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
+				"SystemIdentifier", DBUS_TYPE_STRING,
+				&cdma_netreg->sid);
+
+	if (__ofono_cdma_provision_get_name(sid,
+				&cdma_netreg->provider_name) == FALSE) {
+		ofono_warn("Provider name not found");
+		return;
+	}
+
+	ofono_dbus_signal_property_changed(conn, path,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
+				"Name", DBUS_TYPE_STRING,
+				&cdma_netreg->provider_name);
 }
 
 static void set_registration_status(struct ofono_cdma_netreg *cdma_netreg,
@@ -251,6 +289,8 @@ static void cdma_netreg_remove(struct ofono_atom *atom)
 	if (cdma_netreg->driver && cdma_netreg->driver->remove)
 		cdma_netreg->driver->remove(cdma_netreg);
 
+	g_free(cdma_netreg->sid);
+	g_free(cdma_netreg->provider_name);
 	g_free(cdma_netreg);
 }
 
-- 
1.7.1


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

* [PATCH v3 06/10] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (4 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 05/10] cdma-netreg: Add provider name and SID support Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 07/10] huaweicdma: Open qcdm port to be used for network status and cell location Philippe Nunes
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 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] 14+ messages in thread

* [PATCH v3 07/10] huaweicdma: Open qcdm port to be used for network status and cell location
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (5 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 06/10] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request Philippe Nunes
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/plugins/huaweicdma.c b/plugins/huaweicdma.c
index 6fba0c1..f32e27f 100644
--- a/plugins/huaweicdma.c
+++ b/plugins/huaweicdma.c
@@ -43,6 +43,7 @@
 struct huaweicdma_data {
 	GAtChat *modem;
 	GAtChat *pcui;
+	GAtHDLC *diag;
 };
 
 static void huaweicdma_debug(const char *str, void *data)
@@ -77,6 +78,7 @@ static void huaweicdma_remove(struct ofono_modem *modem)
 
 	/* Cleanup after hot-unplug */
 	g_at_chat_unref(data->pcui);
+	g_at_hdlc_unref(data->diag);
 
 	g_free(data);
 }
@@ -94,6 +96,9 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
 
 		g_at_chat_unref(data->pcui);
 		data->pcui = NULL;
+
+		g_at_hdlc_unref(data->diag);
+		data->diag = NULL;
 	}
 
 	ofono_modem_set_powered(modem, ok);
@@ -132,6 +137,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, huaweicdma_debug, "DIAG: ");
+
+	g_at_hdlc_set_xmit_accm(hdlc, 0);
+	g_at_hdlc_set_recv_accm(hdlc, 0);
+
+	return hdlc;
+}
+
 static int huaweicdma_enable(struct ofono_modem *modem)
 {
 	struct huaweicdma_data *data = ofono_modem_get_data(modem);
@@ -149,6 +186,10 @@ static int huaweicdma_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 &C0 +CMEE=1", NULL, NULL, NULL, NULL);
@@ -186,6 +227,9 @@ static int huaweicdma_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] 14+ messages in thread

* [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (6 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 07/10] huaweicdma: Open qcdm port to be used for network status and cell location Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2012-01-07 19:12   ` Denis Kenzior
  2011-12-14 17:56 ` [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID Philippe Nunes
  2011-12-14 17:56 ` [PATCH v3 10/10] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes
  9 siblings, 1 reply; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 drivers/huaweicdmamodem/network-registration.c |  106 +++++++++++++++++++++---
 1 files changed, 95 insertions(+), 11 deletions(-)

diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
index 0052044..44d3152 100644
--- a/drivers/huaweicdmamodem/network-registration.c
+++ b/drivers/huaweicdmamodem/network-registration.c
@@ -24,6 +24,8 @@
 #endif
 
 #define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -35,8 +37,32 @@
 
 #include "huaweicdmamodem.h"
 
+#define DIAG_CMD_VERSION_INFO	0	/* Version info */
+
 static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
 
+struct netreg_data {
+	GAtChat *chat;
+	GAtHDLC *diag;
+	guint8 cmd;
+};
+
+struct version_info {
+	guint8 code;
+	char comp_date[11];
+	char comp_time[8];
+	char rel_date[11];
+	char rel_time[8];
+	char model[8];
+	guint8 scm;
+	guint8 mob_cai_rev;
+	guint8 mob_model;
+	guint16 mob_firmware_rev;
+	guint8 slot_cycle_index;
+	guint8 msm_ver;
+	guint8 unknown;
+} __attribute__ ((packed));
+
 static gboolean parse_sysinfo(GAtResult *result, gint *status)
 {
 	GAtResultIter iter;
@@ -107,12 +133,56 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_cdma_netreg_status_notify(netreg, status);
 }
 
+static void send_command(GAtHDLC *hdlc, guint8 cmd)
+{
+	unsigned char cmdbuf[1];
+
+	cmdbuf[0] = cmd;
+
+	g_at_hdlc_send(hdlc, cmdbuf, sizeof(cmdbuf));
+}
+
+static void hdlc_receive(const unsigned char *buf, gsize len, void *user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+	if (nd->cmd == DIAG_CMD_VERSION_INFO) {
+		struct version_info *verinfo;
+		char str[12];
+
+		if (len < 1 || len > sizeof(struct version_info) ||
+				nd->cmd != buf[0]) {
+			/* This is probably not a QCDM port */
+			g_at_hdlc_unref(nd->diag);
+			nd->diag = NULL;
+			return;
+		}
+
+		DBG("Version information\n");
+		verinfo = (struct version_info *)buf;
+		snprintf(str, 12, "%s", verinfo->comp_date);
+		DBG("Compiled Date: %s\n", str);
+		snprintf(str, 9, "%s", verinfo->comp_time);
+		DBG("Compiled Time: %s\n", str);
+		snprintf(str, 12, "%s", verinfo->rel_date);
+		DBG("Release Date: %s\n", str);
+		snprintf(str, 9, "%s", verinfo->rel_time);
+		DBG("Release Time: %s\n", str);
+		snprintf(str, 9, "%s", verinfo->model);
+		DBG("Model: %s\n", str);
+		DBG("MSM version: %d\n", verinfo->msm_ver);
+	}
+
+	return;
+}
+
 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 +239,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 +261,37 @@ static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
 static int huaweicdma_netreg_probe(struct ofono_cdma_netreg *netreg,
 				unsigned int vendor, void *data)
 {
-	GAtChat *chat = g_at_chat_clone(data);
+	struct netreg_data *nd;
+
+	nd = g_new0(struct netreg_data, 1);
+
+	nd->chat = g_at_chat_clone(data);
+	nd->diag = g_at_chat_get_slave_qcdm(data);
 
-	ofono_cdma_netreg_set_data(netreg, chat);
+	ofono_cdma_netreg_set_data(netreg, nd);
 
-	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
 				probe_cb, netreg, NULL);
 
+	if (nd->diag) {
+		g_at_hdlc_set_receive(nd->diag, hdlc_receive, netreg);
+		/* Request version info to probe the QCDM port */
+		nd->cmd = DIAG_CMD_VERSION_INFO;
+		send_command(nd->diag, nd->cmd);
+	}
+
 	return 0;
 }
 
 static void huaweicdma_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] 14+ messages in thread

* [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (7 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  2012-01-07 19:16   ` Denis Kenzior
  2011-12-14 17:56 ` [PATCH v3 10/10] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes
  9 siblings, 1 reply; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 UTC (permalink / raw)
  To: ofono

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

---
 drivers/huaweicdmamodem/network-registration.c |  141 ++++++++++++++++++++++++
 1 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
index 44d3152..0ffba7b 100644
--- a/drivers/huaweicdmamodem/network-registration.c
+++ b/drivers/huaweicdmamodem/network-registration.c
@@ -36,8 +36,10 @@
 #include "gatchat.h"
 
 #include "huaweicdmamodem.h"
+#include <drivers/atmodem/atutil.h>
 
 #define DIAG_CMD_VERSION_INFO	0	/* Version info */
+#define DIAG_CMD_STATUS		12	/* Station status */
 
 static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
 
@@ -45,6 +47,8 @@ struct netreg_data {
 	GAtChat *chat;
 	GAtHDLC *diag;
 	guint8 cmd;
+	void *cb;
+	void *cb_data;
 };
 
 struct version_info {
@@ -63,6 +67,32 @@ struct version_info {
 	guint8 unknown;
 } __attribute__ ((packed));
 
+struct cdma_status {
+	guint8 code;
+	guint8 _unknown[3];
+	guint8 esn[4];
+	guint16 rf_mode;
+	guint8 min1_analog[4];
+	guint8 min1_cdma[4];
+	guint8 min2_analog[2];
+	guint8 min2_cdma[2];
+	guint8 _unknown1;
+	guint16 cdma_rx_state;
+	guint8 good_frames;
+	guint16 analog_corrected_frames;
+	guint16 analog_bad_frames;
+	guint16 analog_word_syncs;
+	guint16 entry_reason;
+	guint16 curr_chan;
+	guint8 cdma_code_chan;
+	guint16 pilot_base;
+	guint16 sid;
+	guint16 nid;
+	guint16 analog_locaid;
+	guint16 analog_rssi;
+	guint8 analog_power;
+} __attribute__ ((packed));
+
 static gboolean parse_sysinfo(GAtResult *result, gint *status)
 {
 	GAtResultIter iter;
@@ -133,6 +163,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 send_command(GAtHDLC *hdlc, guint8 cmd)
 {
 	unsigned char cmdbuf[1];
@@ -172,6 +262,35 @@ static void hdlc_receive(const unsigned char *buf, gsize len, void *user_data)
 		snprintf(str, 9, "%s", verinfo->model);
 		DBG("Model: %s\n", str);
 		DBG("MSM version: %d\n", verinfo->msm_ver);
+	} else if (nd->cmd == DIAG_CMD_STATUS) {
+		ofono_cdma_netreg_serving_system_cb_t cb = nd->cb;
+		struct cdma_status *status;
+		char str[6];
+
+		if (len < 1 || len > sizeof(struct cdma_status) ||
+				nd->cmd != buf[0]) {
+			/* 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;
+		}
+
+		DBG("Status command response\n");
+		status = (struct cdma_status *) (buf);
+		DBG("Serving Identification number: SID %d", status->sid);
+		DBG("Network Identification number NID: %d", status->nid);
+
+		/* check if network is registered */
+		if (status->cdma_rx_state == 0) {
+			CALLBACK_WITH_FAILURE(cb, NULL, nd->cb_data);
+			return;
+		}
+
+		snprintf(str, 6, "%d", status->sid);
+		CALLBACK_WITH_SUCCESS(cb, str, nd->cb_data);
 	}
 
 	return;
@@ -294,10 +413,32 @@ static void huaweicdma_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 */
+		nd->cmd = 0x0c;
+		send_command(nd->diag, nd->cmd);
+		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	= "huaweicdmamodem",
 	.probe	= huaweicdma_netreg_probe,
 	.remove	= huaweicdma_netreg_remove,
+	.serving_system = huaweicdma_netreg_serving_system,
 };
 
 void huaweicdma_netreg_init(void)
-- 
1.7.1


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

* [PATCH v3 10/10] udevng: Add a default assignment for Huawei QCDM port
  2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
                   ` (8 preceding siblings ...)
  2011-12-14 17:56 ` [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID Philippe Nunes
@ 2011-12-14 17:56 ` Philippe Nunes
  9 siblings, 0 replies; 14+ messages in thread
From: Philippe Nunes @ 2011-12-14 17:56 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 be87320..67660e3 100644
--- a/plugins/udevng.c
+++ b/plugins/udevng.c
@@ -235,6 +235,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);
@@ -264,22 +265,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] 14+ messages in thread

* Re: [PATCH v3 05/10] cdma-netreg: Add provider name and SID support
  2011-12-14 17:56 ` [PATCH v3 05/10] cdma-netreg: Add provider name and SID support Philippe Nunes
@ 2012-01-07 18:51   ` Denis Kenzior
  0 siblings, 0 replies; 14+ messages in thread
From: Denis Kenzior @ 2012-01-07 18:51 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

> @@ -120,6 +134,30 @@ static void serving_system_callback(const struct ofono_error *error,
>  	}
>  
>  	DBG("Serving system Identifier: %s", sid);
> +
> +	if (cdma_netreg->sid != NULL && !strcmp(cdma_netreg->sid, sid))
> +		return;
> +
> +	g_free(cdma_netreg->provider_name);
> +	g_free(cdma_netreg->sid);
> +	cdma_netreg->provider_name = NULL;
> +	cdma_netreg->sid = g_strdup(sid);
> +
> +	ofono_dbus_signal_property_changed(conn, path,
> +				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
> +				"SystemIdentifier", DBUS_TYPE_STRING,
> +				&cdma_netreg->sid);
> +
> +	if (__ofono_cdma_provision_get_name(sid,
> +				&cdma_netreg->provider_name) == FALSE) {
> +		ofono_warn("Provider name not found");
> +		return;
> +	}
> +
> +	ofono_dbus_signal_property_changed(conn, path,
> +				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
> +				"Name", DBUS_TYPE_STRING,
> +				&cdma_netreg->provider_name);

So in theory the Name might not have changed since there can be multiple
SIDs associated with a name.  Something that should probably be fixed in
a follow-on patch.

>  }
>  
>  static void set_registration_status(struct ofono_cdma_netreg *cdma_netreg,

the first 5 patches in this series have been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request
  2011-12-14 17:56 ` [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request Philippe Nunes
@ 2012-01-07 19:12   ` Denis Kenzior
  0 siblings, 0 replies; 14+ messages in thread
From: Denis Kenzior @ 2012-01-07 19:12 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

On 12/14/2011 11:56 AM, Philippe Nunes wrote:
> ---
>  drivers/huaweicdmamodem/network-registration.c |  106 +++++++++++++++++++++---
>  1 files changed, 95 insertions(+), 11 deletions(-)
> 

so the huawecdmamodem tree no longer exists, and I'm not sure that the
QCDM pieces really belong here, perhaps we need a separate helper
library for parsing this information.

> diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
> index 0052044..44d3152 100644
> --- a/drivers/huaweicdmamodem/network-registration.c
> +++ b/drivers/huaweicdmamodem/network-registration.c
> @@ -24,6 +24,8 @@
>  #endif
>  
>  #define _GNU_SOURCE
> +#include <string.h>
> +#include <stdio.h>
>  #include <glib.h>
>  #include <errno.h>
>  
> @@ -35,8 +37,32 @@
>  
>  #include "huaweicdmamodem.h"
>  
> +#define DIAG_CMD_VERSION_INFO	0	/* Version info */
> +
>  static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
>  
> +struct netreg_data {
> +	GAtChat *chat;
> +	GAtHDLC *diag;
> +	guint8 cmd;
> +};
> +
> +struct version_info {
> +	guint8 code;
> +	char comp_date[11];
> +	char comp_time[8];
> +	char rel_date[11];
> +	char rel_time[8];
> +	char model[8];
> +	guint8 scm;
> +	guint8 mob_cai_rev;
> +	guint8 mob_model;
> +	guint16 mob_firmware_rev;
> +	guint8 slot_cycle_index;
> +	guint8 msm_ver;
> +	guint8 unknown;
> +} __attribute__ ((packed));
> +
>  static gboolean parse_sysinfo(GAtResult *result, gint *status)
>  {
>  	GAtResultIter iter;
> @@ -107,12 +133,56 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
>  	ofono_cdma_netreg_status_notify(netreg, status);
>  }
>  
> +static void send_command(GAtHDLC *hdlc, guint8 cmd)
> +{
> +	unsigned char cmdbuf[1];
> +
> +	cmdbuf[0] = cmd;
> +
> +	g_at_hdlc_send(hdlc, cmdbuf, sizeof(cmdbuf));
> +}
> +
> +static void hdlc_receive(const unsigned char *buf, gsize len, void *user_data)
> +{
> +	struct ofono_cdma_netreg *netreg = user_data;
> +	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
> +
> +	if (nd->cmd == DIAG_CMD_VERSION_INFO) {
> +		struct version_info *verinfo;
> +		char str[12];
> +
> +		if (len < 1 || len > sizeof(struct version_info) ||
> +				nd->cmd != buf[0]) {
> +			/* This is probably not a QCDM port */
> +			g_at_hdlc_unref(nd->diag);
> +			nd->diag = NULL;
> +			return;
> +		}
> +
> +		DBG("Version information\n");
> +		verinfo = (struct version_info *)buf;

You really can't do this since the endian-ness of QCDM is likely always
little-endian, while oFono might be running on big-endian machine.

> +		snprintf(str, 12, "%s", verinfo->comp_date);
> +		DBG("Compiled Date: %s\n", str);
> +		snprintf(str, 9, "%s", verinfo->comp_time);
> +		DBG("Compiled Time: %s\n", str);
> +		snprintf(str, 12, "%s", verinfo->rel_date);
> +		DBG("Release Date: %s\n", str);
> +		snprintf(str, 9, "%s", verinfo->rel_time);
> +		DBG("Release Time: %s\n", str);
> +		snprintf(str, 9, "%s", verinfo->model);
> +		DBG("Model: %s\n", str);
> +		DBG("MSM version: %d\n", verinfo->msm_ver);
> +	}
> +
> +	return;
> +}
> +
>  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 +239,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 +261,37 @@ static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
>  static int huaweicdma_netreg_probe(struct ofono_cdma_netreg *netreg,
>  				unsigned int vendor, void *data)
>  {
> -	GAtChat *chat = g_at_chat_clone(data);
> +	struct netreg_data *nd;
> +
> +	nd = g_new0(struct netreg_data, 1);
> +
> +	nd->chat = g_at_chat_clone(data);
> +	nd->diag = g_at_chat_get_slave_qcdm(data);
>  
> -	ofono_cdma_netreg_set_data(netreg, chat);
> +	ofono_cdma_netreg_set_data(netreg, nd);
>  
> -	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
> +	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
>  				probe_cb, netreg, NULL);
>  
> +	if (nd->diag) {
> +		g_at_hdlc_set_receive(nd->diag, hdlc_receive, netreg);
> +		/* Request version info to probe the QCDM port */
> +		nd->cmd = DIAG_CMD_VERSION_INFO;
> +		send_command(nd->diag, nd->cmd);
> +	}
> +
>  	return 0;
>  }
>  
>  static void huaweicdma_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 = {

Regards,
-Denis

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

* Re: [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID
  2011-12-14 17:56 ` [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID Philippe Nunes
@ 2012-01-07 19:16   ` Denis Kenzior
  0 siblings, 0 replies; 14+ messages in thread
From: Denis Kenzior @ 2012-01-07 19:16 UTC (permalink / raw)
  To: ofono

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

Hi Philippe,

On 12/14/2011 11:56 AM, Philippe Nunes wrote:
> ---
>  drivers/huaweicdmamodem/network-registration.c |  141 ++++++++++++++++++++++++
>  1 files changed, 141 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
> index 44d3152..0ffba7b 100644
> --- a/drivers/huaweicdmamodem/network-registration.c
> +++ b/drivers/huaweicdmamodem/network-registration.c
> @@ -36,8 +36,10 @@
>  #include "gatchat.h"
>  
>  #include "huaweicdmamodem.h"
> +#include <drivers/atmodem/atutil.h>
>  
>  #define DIAG_CMD_VERSION_INFO	0	/* Version info */
> +#define DIAG_CMD_STATUS		12	/* Station status */
>  
>  static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
>  
> @@ -45,6 +47,8 @@ struct netreg_data {
>  	GAtChat *chat;
>  	GAtHDLC *diag;
>  	guint8 cmd;
> +	void *cb;
> +	void *cb_data;
>  };
>  
>  struct version_info {
> @@ -63,6 +67,32 @@ struct version_info {
>  	guint8 unknown;
>  } __attribute__ ((packed));
>  
> +struct cdma_status {
> +	guint8 code;
> +	guint8 _unknown[3];
> +	guint8 esn[4];
> +	guint16 rf_mode;
> +	guint8 min1_analog[4];
> +	guint8 min1_cdma[4];
> +	guint8 min2_analog[2];
> +	guint8 min2_cdma[2];
> +	guint8 _unknown1;
> +	guint16 cdma_rx_state;
> +	guint8 good_frames;
> +	guint16 analog_corrected_frames;
> +	guint16 analog_bad_frames;
> +	guint16 analog_word_syncs;
> +	guint16 entry_reason;
> +	guint16 curr_chan;
> +	guint8 cdma_code_chan;
> +	guint16 pilot_base;
> +	guint16 sid;
> +	guint16 nid;
> +	guint16 analog_locaid;
> +	guint16 analog_rssi;
> +	guint8 analog_power;
> +} __attribute__ ((packed));
> +
>  static gboolean parse_sysinfo(GAtResult *result, gint *status)
>  {
>  	GAtResultIter iter;
> @@ -133,6 +163,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;
> +}

Are you sure you need this fallback?  I'd really rather leave this out
due to already discussed problems with CSS.  I don't know is better than
the wrong result...

> +
> +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 send_command(GAtHDLC *hdlc, guint8 cmd)
>  {
>  	unsigned char cmdbuf[1];
> @@ -172,6 +262,35 @@ static void hdlc_receive(const unsigned char *buf, gsize len, void *user_data)
>  		snprintf(str, 9, "%s", verinfo->model);
>  		DBG("Model: %s\n", str);
>  		DBG("MSM version: %d\n", verinfo->msm_ver);
> +	} else if (nd->cmd == DIAG_CMD_STATUS) {
> +		ofono_cdma_netreg_serving_system_cb_t cb = nd->cb;
> +		struct cdma_status *status;
> +		char str[6];
> +
> +		if (len < 1 || len > sizeof(struct cdma_status) ||
> +				nd->cmd != buf[0]) {
> +			/* 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;
> +		}
> +
> +		DBG("Status command response\n");
> +		status = (struct cdma_status *) (buf);
> +		DBG("Serving Identification number: SID %d", status->sid);
> +		DBG("Network Identification number NID: %d", status->nid);
> +
> +		/* check if network is registered */
> +		if (status->cdma_rx_state == 0) {
> +			CALLBACK_WITH_FAILURE(cb, NULL, nd->cb_data);
> +			return;
> +		}
> +
> +		snprintf(str, 6, "%d", status->sid);
> +		CALLBACK_WITH_SUCCESS(cb, str, nd->cb_data);

This structure is really not maintainable long term, there needs to be a
proper framework for executing commands and receiving results, not a
giant if/else statement.  Also, all the comments from the previous patch
apply, you have to pay attention to endianness here or the results you
will get will be wrong.

>  	}
>  
>  	return;
> @@ -294,10 +413,32 @@ static void huaweicdma_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 */
> +		nd->cmd = 0x0c;
> +		send_command(nd->diag, nd->cmd);
> +		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	= "huaweicdmamodem",
>  	.probe	= huaweicdma_netreg_probe,
>  	.remove	= huaweicdma_netreg_remove,
> +	.serving_system = huaweicdma_netreg_serving_system,
>  };
>  
>  void huaweicdma_netreg_init(void)

Regards,
-Denis

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

end of thread, other threads:[~2012-01-07 19:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-14 17:56 [PATCH v3 00/10] Provider name and SID Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 01/10] cdma-provision: Add driver APIs header Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 02/10] ofono.h: add API to get cdma provider name Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 03/10] cdma-provision: Add driver APIs implementation Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 04/10] cdma-provision: Add cdma provisioning plugin Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 05/10] cdma-netreg: Add provider name and SID support Philippe Nunes
2012-01-07 18:51   ` Denis Kenzior
2011-12-14 17:56 ` [PATCH v3 06/10] gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 07/10] huaweicdma: Open qcdm port to be used for network status and cell location Philippe Nunes
2011-12-14 17:56 ` [PATCH v3 08/10] huaweicdmamodem: Probe the QCDM port with the version info request Philippe Nunes
2012-01-07 19:12   ` Denis Kenzior
2011-12-14 17:56 ` [PATCH v3 09/10] huaweicdmamodem: Add 'serving_system' entry point to get SID Philippe Nunes
2012-01-07 19:16   ` Denis Kenzior
2011-12-14 17:56 ` [PATCH v3 10/10] udevng: Add a default assignment for Huawei QCDM port Philippe Nunes

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