All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH_v5 0/8] Create CDMA Network Registration atom
@ 2011-08-03 13:50 Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 1/8] cdmamodem: Define " Bertrand Aygon
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

Create an org.ofono.cdma.NetworkRegistration interface.
Create the skeleton for the new interface.
Add status information to the CDMA Network registration atom.
Create a Huawei CDMA driver with a dedicated CDMA netreg atom. 
Modify Huawei CDMA driver to register this atom.

Bertrand Aygon (8):
  cdmamodem: Define CDMA Network Registration atom.
  cdmamodem: define CDMA netreg atom.
  cdmamodem: create include file for CDMA netreg.
  cdmamodem: create the interface for CDMA netreg.
  cdmamodem: define cdma network status.
  cdmamodem: implement cdma network status.
  huaweicdmamodem: create a huawei cdma driver.
  huaweicdma: register to CDMA netreg atom.

 Makefile.am                                    |   10 +-
 drivers/huaweicdmamodem/huaweicdmamodem.c      |   45 +++++
 drivers/huaweicdmamodem/huaweicdmamodem.h      |   23 +++
 drivers/huaweicdmamodem/network-registration.c |  159 ++++++++++++++++
 include/cdma-netreg.h                          |   67 +++++++
 include/dbus.h                                 |    2 +
 plugins/huaweicdma.c                           |    3 +
 src/cdma-netreg.c                              |  238 ++++++++++++++++++++++++
 src/ofono.h                                    |    2 +
 9 files changed, 547 insertions(+), 2 deletions(-)
 create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.c
 create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.h
 create mode 100644 drivers/huaweicdmamodem/network-registration.c
 create mode 100644 include/cdma-netreg.h
 create mode 100644 src/cdma-netreg.c

-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 1/8] cdmamodem: Define CDMA Network Registration atom.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 2/8] cdmamodem: define CDMA netreg atom Bertrand Aygon
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 include/dbus.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/dbus.h b/include/dbus.h
index 4dd9db5..65bda72 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -63,6 +63,8 @@ extern "C" {
 #define OFONO_CDMA_VOICECALL_MANAGER_INTERFACE "org.ofono.cdma.VoiceCallManager"
 #define OFONO_CDMA_MESSAGE_MANAGER_INTERFACE "org.ofono.cdma.MessageManager"
 #define OFONO_CDMA_CONNECTION_MANAGER_INTERFACE "org.ofono.cdma.ConnectionManager"
+#define OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE \
+					"org.ofono.cdma.NetworkRegistration"
 
 /* Essentially a{sv} */
 #define OFONO_PROPERTIES_ARRAY_SIGNATURE DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 2/8] cdmamodem: define CDMA netreg atom.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 1/8] cdmamodem: Define " Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 3/8] cdmamodem: create include file for CDMA netreg Bertrand Aygon
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/ofono.h b/src/ofono.h
index 808a8f1..ef5e77d 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -135,6 +135,7 @@ enum ofono_atom_type {
 	OFONO_ATOM_TYPE_LOCATION_REPORTING,
 	OFONO_ATOM_TYPE_GNSS,
 	OFONO_ATOM_TYPE_CDMA_SMS,
+	OFONO_ATOM_TYPE_CDMA_NETREG,
 };
 
 enum ofono_atom_watch_condition {
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 3/8] cdmamodem: create include file for CDMA netreg.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 1/8] cdmamodem: Define " Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 2/8] cdmamodem: define CDMA netreg atom Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 4/8] cdmamodem: create the interface " Bertrand Aygon
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am           |    2 +-
 include/cdma-netreg.h |   58 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/ofono.h           |    1 +
 3 files changed, 60 insertions(+), 1 deletions(-)
 create mode 100644 include/cdma-netreg.h

diff --git a/Makefile.am b/Makefile.am
index cef9892..e188034 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,7 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/gprs-provision.h include/emulator.h \
 			include/location-reporting.h \
 			include/cdma-connman.h include/gnss.h \
-			include/private-network.h
+			include/private-network.h include/cdma-netreg.h
 
 nodist_pkginclude_HEADERS = include/version.h
 
diff --git a/include/cdma-netreg.h b/include/cdma-netreg.h
new file mode 100644
index 0000000..0da7cbb
--- /dev/null
+++ b/include/cdma-netreg.h
@@ -0,0 +1,58 @@
+/*
+ *
+ *  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_NETREG_H
+#define __OFONO_CDMA_NETREG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ofono/types.h>
+
+struct ofono_cdma_netreg;
+
+struct ofono_cdma_netreg_driver {
+	const char *name;
+	int (*probe)(struct ofono_cdma_netreg *cdma_netreg, unsigned int vendor,
+			void *data);
+	void (*remove)(struct ofono_cdma_netreg *cdma_netreg);
+};
+
+int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d);
+void ofono_cdma_netreg_driver_unregister(const struct ofono_cdma_netreg_driver *d);
+
+struct ofono_cdma_netreg *ofono_cdma_netreg_create(struct ofono_modem *modem,
+						unsigned int vendor,
+						const char *driver,
+						void *data);
+
+void ofono_cdma_netreg_register(struct ofono_cdma_netreg *cdma_netreg);
+void ofono_cdma_netreg_remove(struct ofono_cdma_netreg *cdma_netreg);
+
+void ofono_cdma_netreg_set_data(struct ofono_cdma_netreg *cdma_netreg, void *data);
+void *ofono_cdma_netreg_get_data(struct ofono_cdma_netreg *cdma_netreg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_CDMA_NETREG_H */
diff --git a/src/ofono.h b/src/ofono.h
index ef5e77d..5e3a6b5 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -481,6 +481,7 @@ void __ofono_gprs_provision_free_settings(
 #include <ofono/emulator.h>
 #include <ofono/gnss.h>
 #include <ofono/cdma-sms.h>
+#include <ofono/cdma-netreg.h>
 #include <ofono/private-network.h>
 
 void __ofono_private_network_release(int id);
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 4/8] cdmamodem: create the interface for CDMA netreg.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
                   ` (2 preceding siblings ...)
  2011-08-03 13:50 ` [PATCH_v5 3/8] cdmamodem: create include file for CDMA netreg Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 5/8] cdmamodem: define cdma network status Bertrand Aygon
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am       |    2 +-
 src/cdma-netreg.c |  188 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+), 1 deletions(-)
 create mode 100644 src/cdma-netreg.c

diff --git a/Makefile.am b/Makefile.am
index e188034..56c1d6a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -416,7 +416,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
 			src/cdma-connman.c src/gnss.c \
 			src/gnssagent.c src/gnssagent.h \
 			src/cdma-smsutil.h src/cdma-smsutil.c \
-			src/cdma-sms.c src/private-network.c
+			src/cdma-sms.c src/private-network.c src/cdma-netreg.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/src/cdma-netreg.c b/src/cdma-netreg.c
new file mode 100644
index 0000000..b1cbd53
--- /dev/null
+++ b/src/cdma-netreg.c
@@ -0,0 +1,188 @@
+/*
+ *
+ *  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 <gdbus.h>
+
+#include "ofono.h"
+
+static GSList *g_drivers;
+
+struct ofono_cdma_netreg {
+	const struct ofono_cdma_netreg_driver *driver;
+	void *driver_data;
+	struct ofono_atom *atom;
+};
+
+static DBusMessage *network_get_properties(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+
+	reply = dbus_message_new_method_return(msg);
+	if (reply == NULL)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
+static GDBusMethodTable cdma_netreg_manager_methods[] = {
+	{ "GetProperties",  "",  "a{sv}",	network_get_properties },
+	{ }
+};
+
+static GDBusSignalTable cdma_netreg_manager_signals[] = {
+	{ }
+};
+
+int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	if (d->probe == NULL)
+		return -EINVAL;
+
+	g_drivers = g_slist_prepend(g_drivers, (void *)d);
+
+	return 0;
+}
+
+void ofono_cdma_netreg_driver_unregister(const struct ofono_cdma_netreg_driver *d)
+{
+	DBG("driver: %p, name: %s", d, d->name);
+
+	g_drivers = g_slist_remove(g_drivers, (void *)d);
+}
+
+static void cdma_netreg_unregister(struct ofono_atom *atom)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(atom);
+	const char *path = __ofono_atom_get_path(atom);
+
+	g_dbus_unregister_interface(conn, path,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE);
+
+	ofono_modem_remove_interface(modem,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE);
+}
+
+static void cdma_netreg_remove(struct ofono_atom *atom)
+{
+	struct ofono_cdma_netreg *cdma_netreg = __ofono_atom_get_data(atom);
+
+	DBG("atom: %p", atom);
+
+	if (cdma_netreg == NULL)
+		return;
+
+	if (cdma_netreg->driver && cdma_netreg->driver->remove)
+		cdma_netreg->driver->remove(cdma_netreg);
+
+	g_free(cdma_netreg);
+}
+
+struct ofono_cdma_netreg *ofono_cdma_netreg_create(struct ofono_modem *modem,
+						unsigned int vendor,
+						const char *driver,
+						void *data)
+{
+	struct ofono_cdma_netreg *cdma_netreg;
+	GSList *l;
+
+	if (driver == NULL)
+		return NULL;
+
+	cdma_netreg = g_try_new0(struct ofono_cdma_netreg, 1);
+	if (cdma_netreg == NULL)
+		return NULL;
+
+	cdma_netreg->atom = __ofono_modem_add_atom(modem,
+					OFONO_ATOM_TYPE_CDMA_NETREG,
+					cdma_netreg_remove, cdma_netreg);
+
+	for (l = g_drivers; l; l = l->next) {
+		const struct ofono_cdma_netreg_driver *drv = l->data;
+
+		if (g_strcmp0(drv->name, driver))
+			continue;
+
+		if (drv->probe(cdma_netreg, vendor, data) < 0)
+			continue;
+
+		cdma_netreg->driver = drv;
+		break;
+	}
+
+	return cdma_netreg;
+}
+
+void ofono_cdma_netreg_register(struct ofono_cdma_netreg *cdma_netreg)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(cdma_netreg->atom);
+	const char *path = __ofono_atom_get_path(cdma_netreg->atom);
+
+	if (!g_dbus_register_interface(conn, path,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
+				cdma_netreg_manager_methods,
+				cdma_netreg_manager_signals,
+				NULL, cdma_netreg, NULL)) {
+		ofono_error("Could not create %s interface",
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE);
+		return;
+	}
+
+	ofono_modem_add_interface(modem,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE);
+
+	__ofono_atom_register(cdma_netreg->atom, cdma_netreg_unregister);
+}
+
+void ofono_cdma_netreg_remove(struct ofono_cdma_netreg *cdma_netreg)
+{
+	__ofono_atom_free(cdma_netreg->atom);
+}
+
+void ofono_cdma_netreg_set_data(struct ofono_cdma_netreg *cdma_netreg, void *data)
+{
+	cdma_netreg->driver_data = data;
+}
+
+void *ofono_cdma_netreg_get_data(struct ofono_cdma_netreg *cdma_netreg)
+{
+	return cdma_netreg->driver_data;
+}
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 5/8] cdmamodem: define cdma network status.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
                   ` (3 preceding siblings ...)
  2011-08-03 13:50 ` [PATCH_v5 4/8] cdmamodem: create the interface " Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 6/8] cdmamodem: implement " Bertrand Aygon
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 include/cdma-netreg.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/cdma-netreg.h b/include/cdma-netreg.h
index 0da7cbb..b8b85f7 100644
--- a/include/cdma-netreg.h
+++ b/include/cdma-netreg.h
@@ -28,6 +28,12 @@ extern "C" {
 
 #include <ofono/types.h>
 
+enum cdma_netreg_status {
+	CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED =	0,
+	CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED =		1,
+	CDMA_NETWORK_REGISTRATION_STATUS_ROAMING =		2,
+};
+
 struct ofono_cdma_netreg;
 
 struct ofono_cdma_netreg_driver {
@@ -37,6 +43,9 @@ struct ofono_cdma_netreg_driver {
 	void (*remove)(struct ofono_cdma_netreg *cdma_netreg);
 };
 
+void ofono_cdma_netreg_status_notify(struct ofono_cdma_netreg *netreg,
+					enum cdma_netreg_status status);
+
 int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d);
 void ofono_cdma_netreg_driver_unregister(const struct ofono_cdma_netreg_driver *d);
 
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 6/8] cdmamodem: implement cdma network status.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
                   ` (4 preceding siblings ...)
  2011-08-03 13:50 ` [PATCH_v5 5/8] cdmamodem: define cdma network status Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver Bertrand Aygon
  2011-08-03 13:50 ` [PATCH_v5 8/8] huaweicdma: register to CDMA netreg atom Bertrand Aygon
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 src/cdma-netreg.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/cdma-netreg.c b/src/cdma-netreg.c
index b1cbd53..02eff24 100644
--- a/src/cdma-netreg.c
+++ b/src/cdma-netreg.c
@@ -32,18 +32,36 @@
 static GSList *g_drivers;
 
 struct ofono_cdma_netreg {
+	enum cdma_netreg_status status;
 	const struct ofono_cdma_netreg_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
 };
 
+static const char *cdma_netreg_status_to_string(enum cdma_netreg_status status)
+{
+	switch (status) {
+	case CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED:
+		return "unregistered";
+	case CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED:
+		return "registered";
+	case CDMA_NETWORK_REGISTRATION_STATUS_ROAMING:
+		return "roaming";
+	}
+
+	return "";
+}
+
 static DBusMessage *network_get_properties(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
+	struct ofono_cdma_netreg *cdma_netreg = data;
 	DBusMessage *reply;
 	DBusMessageIter iter;
 	DBusMessageIter dict;
 
+	const char *status = cdma_netreg_status_to_string(cdma_netreg->status);
+
 	reply = dbus_message_new_method_return(msg);
 	if (reply == NULL)
 		return NULL;
@@ -54,6 +72,8 @@ static DBusMessage *network_get_properties(DBusConnection *conn,
 					OFONO_PROPERTIES_ARRAY_SIGNATURE,
 					&dict);
 
+	ofono_dbus_dict_append(&dict, "Status", DBUS_TYPE_STRING, &status);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
@@ -68,6 +88,32 @@ static GDBusSignalTable cdma_netreg_manager_signals[] = {
 	{ }
 };
 
+
+static void set_registration_status(struct ofono_cdma_netreg *cdma_netreg,
+						enum cdma_netreg_status status)
+{
+	const char *str_status = cdma_netreg_status_to_string(status);
+	const char *path = __ofono_atom_get_path(cdma_netreg->atom);
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	cdma_netreg->status = status;
+
+	ofono_dbus_signal_property_changed(conn, path,
+				OFONO_CDMA_NETWORK_REGISTRATION_INTERFACE,
+				"Status", DBUS_TYPE_STRING,
+				&str_status);
+}
+
+void ofono_cdma_netreg_status_notify(struct ofono_cdma_netreg *cdma_netreg,
+					enum cdma_netreg_status status)
+{
+	if (cdma_netreg == NULL)
+		return;
+
+	if (cdma_netreg->status != status)
+		set_registration_status(cdma_netreg, status);
+}
+
 int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
@@ -80,7 +126,8 @@ int ofono_cdma_netreg_driver_register(const struct ofono_cdma_netreg_driver *d)
 	return 0;
 }
 
-void ofono_cdma_netreg_driver_unregister(const struct ofono_cdma_netreg_driver *d)
+void ofono_cdma_netreg_driver_unregister(
+			const struct ofono_cdma_netreg_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
 
@@ -130,6 +177,8 @@ struct ofono_cdma_netreg *ofono_cdma_netreg_create(struct ofono_modem *modem,
 	if (cdma_netreg == NULL)
 		return NULL;
 
+	cdma_netreg->status = CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
+
 	cdma_netreg->atom = __ofono_modem_add_atom(modem,
 					OFONO_ATOM_TYPE_CDMA_NETREG,
 					cdma_netreg_remove, cdma_netreg);
@@ -177,7 +226,8 @@ void ofono_cdma_netreg_remove(struct ofono_cdma_netreg *cdma_netreg)
 	__ofono_atom_free(cdma_netreg->atom);
 }
 
-void ofono_cdma_netreg_set_data(struct ofono_cdma_netreg *cdma_netreg, void *data)
+void ofono_cdma_netreg_set_data(struct ofono_cdma_netreg *cdma_netreg,
+					void *data)
 {
 	cdma_netreg->driver_data = data;
 }
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
                   ` (5 preceding siblings ...)
  2011-08-03 13:50 ` [PATCH_v5 6/8] cdmamodem: implement " Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  2011-08-05  8:49   ` Marcel Holtmann
  2011-08-03 13:50 ` [PATCH_v5 8/8] huaweicdma: register to CDMA netreg atom Bertrand Aygon
  7 siblings, 1 reply; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am                                    |    6 +
 drivers/huaweicdmamodem/huaweicdmamodem.c      |   45 +++++++
 drivers/huaweicdmamodem/huaweicdmamodem.h      |   23 ++++
 drivers/huaweicdmamodem/network-registration.c |  159 ++++++++++++++++++++++++
 4 files changed, 233 insertions(+), 0 deletions(-)
 create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.c
 create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.h
 create mode 100644 drivers/huaweicdmamodem/network-registration.c

diff --git a/Makefile.am b/Makefile.am
index 56c1d6a..afa5e6f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -276,6 +276,12 @@ builtin_sources += drivers/cdmamodem/cdmamodem.h \
 			drivers/cdmamodem/voicecall.c \
 			drivers/cdmamodem/devinfo.c \
 			drivers/cdmamodem/connman.c
+
+builtin_modules += huaweicdmamodem
+builtin_sources += drivers/huaweicdmamodem/huaweicdmamodem.h \
+			drivers/huaweicdmamodem/huaweicdmamodem.c \
+			drivers/huaweicdmamodem/network-registration.c
+
 endif
 
 builtin_modules += g1
diff --git a/drivers/huaweicdmamodem/huaweicdmamodem.c b/drivers/huaweicdmamodem/huaweicdmamodem.c
new file mode 100644
index 0000000..4e9c400
--- /dev/null
+++ b/drivers/huaweicdmamodem/huaweicdmamodem.c
@@ -0,0 +1,45 @@
+/*
+ *
+ *  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
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+
+#include "huaweicdmamodem.h"
+
+static int huaweicdmamodem_init(void)
+{
+	huaweicdma_netreg_init();
+
+	return 0;
+}
+
+static void huaweicdmamodem_exit(void)
+{
+	huaweicdma_netreg_exit();
+}
+
+OFONO_PLUGIN_DEFINE(huaweicdmamodem, "Huawei CDMA modem driver", VERSION,
+			OFONO_PLUGIN_PRIORITY_DEFAULT,
+			huaweicdmamodem_init, huaweicdmamodem_exit)
diff --git a/drivers/huaweicdmamodem/huaweicdmamodem.h b/drivers/huaweicdmamodem/huaweicdmamodem.h
new file mode 100644
index 0000000..799d3a8
--- /dev/null
+++ b/drivers/huaweicdmamodem/huaweicdmamodem.h
@@ -0,0 +1,23 @@
+/*
+ *
+ *  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
+ *
+ */
+
+extern void huaweicdma_netreg_init(void);
+extern void huaweicdma_netreg_exit(void);
diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
new file mode 100644
index 0000000..e4c5c41
--- /dev/null
+++ b/drivers/huaweicdmamodem/network-registration.c
@@ -0,0 +1,159 @@
+/*
+ *
+ *  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
+
+#define _GNU_SOURCE
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/cdma-netreg.h>
+
+#include "gatchat.h"
+
+#include "huaweicdmamodem.h"
+
+static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
+
+struct huaweicdma_netreg_data {
+	GAtChat *chat;
+};
+
+static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	gint srv_status;
+	gint srv_domain;
+	gint roaming_status;
+	int status;
+	GAtResultIter iter;
+
+	if (!ok)
+		return;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "^SYSINFO:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &srv_status))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &srv_domain))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &roaming_status))
+		return;
+
+	DBG("%d, %d, %d", srv_status, srv_domain, roaming_status);
+
+	switch (srv_status) {
+	case 1:	/* Restricted service */
+	case 2:	/* Service valid */
+	case 3:	/* Restricted region service */
+		status = CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED;
+		break;
+	case 0:	/* No service */
+	case 4:	/* Not registered */
+	default:
+		status = CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
+		break;
+	}
+
+	switch (srv_domain) {
+	case 0: /* No service */
+	case 255: /* CDMA not supported */
+		status = CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
+		break;
+	case 1: /* Only CS */
+	case 2: /* Only PS */
+	case 3: /* CS + PS */
+	case 4: /* CS registered, PS in searching state */
+		break;
+	}
+	
+	if (status == CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED
+				&& roaming_status)
+		status = CDMA_NETWORK_REGISTRATION_STATUS_ROAMING;
+
+	ofono_cdma_netreg_status_notify(netreg, status);
+}
+
+
+static void mode_notify(GAtResult *result, gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct huaweicdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix, sysinfo_cb,
+				netreg, NULL);
+}
+
+static int huaweicdma_netreg_probe(struct ofono_cdma_netreg *netreg,
+				unsigned int vendor, void *data)
+{
+	GAtChat *chat = data;
+	struct huaweicdma_netreg_data *nd;
+
+	nd = g_try_new0(struct huaweicdma_netreg_data, 1);
+
+	nd->chat = g_at_chat_clone(chat);
+	ofono_cdma_netreg_set_data(netreg, nd);
+
+	g_at_chat_register(nd->chat, "^MODE:",
+				mode_notify, FALSE, netreg, NULL);
+
+	ofono_cdma_netreg_register(netreg);
+
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix, sysinfo_cb,
+				netreg, NULL);
+
+	return 0;
+}
+
+static void huaweicdma_netreg_remove(struct ofono_cdma_netreg *netreg)
+{
+	struct huaweicdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+	ofono_cdma_netreg_set_data(netreg, NULL);
+
+	g_at_chat_unref(nd->chat);
+	g_free(nd);
+}
+
+static struct ofono_cdma_netreg_driver driver = {
+	.name	= "huaweicdmamodem",
+	.probe	= huaweicdma_netreg_probe,
+	.remove	= huaweicdma_netreg_remove,
+};
+
+void huaweicdma_netreg_init(void)
+{
+	ofono_cdma_netreg_driver_register(&driver);
+}
+
+void huaweicdma_netreg_exit(void)
+{
+	ofono_cdma_netreg_driver_unregister(&driver);
+}
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* [PATCH_v5 8/8] huaweicdma: register to CDMA netreg atom.
  2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
                   ` (6 preceding siblings ...)
  2011-08-03 13:50 ` [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver Bertrand Aygon
@ 2011-08-03 13:50 ` Bertrand Aygon
  7 siblings, 0 replies; 10+ messages in thread
From: Bertrand Aygon @ 2011-08-03 13:50 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/plugins/huaweicdma.c b/plugins/huaweicdma.c
index 75aacb2..4c83114 100644
--- a/plugins/huaweicdma.c
+++ b/plugins/huaweicdma.c
@@ -34,6 +34,7 @@
 #include <ofono/plugin.h>
 #include <ofono/modem.h>
 #include <ofono/devinfo.h>
+#include <ofono/cdma-netreg.h>
 #include <ofono/cdma-connman.h>
 #include <ofono/log.h>
 
@@ -210,6 +211,8 @@ static void huaweicdma_post_online(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
+	ofono_cdma_netreg_create(modem, 0, "huaweicdmamodem", data->modem);
+
 	ofono_cdma_connman_create(modem, 0, "cdmamodem", data->modem);
 }
 
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

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

* Re: [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver.
  2011-08-03 13:50 ` [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver Bertrand Aygon
@ 2011-08-05  8:49   ` Marcel Holtmann
  0 siblings, 0 replies; 10+ messages in thread
From: Marcel Holtmann @ 2011-08-05  8:49 UTC (permalink / raw)
  To: ofono

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

Hi Bertrand,

>  Makefile.am                                    |    6 +
>  drivers/huaweicdmamodem/huaweicdmamodem.c      |   45 +++++++
>  drivers/huaweicdmamodem/huaweicdmamodem.h      |   23 ++++
>  drivers/huaweicdmamodem/network-registration.c |  159 ++++++++++++++++++++++++
>  4 files changed, 233 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.c
>  create mode 100644 drivers/huaweicdmamodem/huaweicdmamodem.h
>  create mode 100644 drivers/huaweicdmamodem/network-registration.c

these need to be split into two. First put the core plugin into place
and then add features to it.

> diff --git a/Makefile.am b/Makefile.am
> index 56c1d6a..afa5e6f 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -276,6 +276,12 @@ builtin_sources += drivers/cdmamodem/cdmamodem.h \
>  			drivers/cdmamodem/voicecall.c \
>  			drivers/cdmamodem/devinfo.c \
>  			drivers/cdmamodem/connman.c
> +
> +builtin_modules += huaweicdmamodem
> +builtin_sources += drivers/huaweicdmamodem/huaweicdmamodem.h \
> +			drivers/huaweicdmamodem/huaweicdmamodem.c \
> +			drivers/huaweicdmamodem/network-registration.c
> +
>  endif
>  
>  builtin_modules += g1
> diff --git a/drivers/huaweicdmamodem/huaweicdmamodem.c b/drivers/huaweicdmamodem/huaweicdmamodem.c
> new file mode 100644
> index 0000000..4e9c400
> --- /dev/null
> +++ b/drivers/huaweicdmamodem/huaweicdmamodem.c
> @@ -0,0 +1,45 @@
> +/*
> + *
> + *  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
> +
> +#define OFONO_API_SUBJECT_TO_CHANGE
> +#include <ofono/plugin.h>
> +
> +#include "huaweicdmamodem.h"
> +
> +static int huaweicdmamodem_init(void)
> +{
> +	huaweicdma_netreg_init();
> +
> +	return 0;
> +}
> +
> +static void huaweicdmamodem_exit(void)
> +{
> +	huaweicdma_netreg_exit();
> +}
> +
> +OFONO_PLUGIN_DEFINE(huaweicdmamodem, "Huawei CDMA modem driver", VERSION,
> +			OFONO_PLUGIN_PRIORITY_DEFAULT,
> +			huaweicdmamodem_init, huaweicdmamodem_exit)
> diff --git a/drivers/huaweicdmamodem/huaweicdmamodem.h b/drivers/huaweicdmamodem/huaweicdmamodem.h
> new file mode 100644
> index 0000000..799d3a8
> --- /dev/null
> +++ b/drivers/huaweicdmamodem/huaweicdmamodem.h
> @@ -0,0 +1,23 @@
> +/*
> + *
> + *  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
> + *
> + */
> +
> +extern void huaweicdma_netreg_init(void);
> +extern void huaweicdma_netreg_exit(void);
> diff --git a/drivers/huaweicdmamodem/network-registration.c b/drivers/huaweicdmamodem/network-registration.c
> new file mode 100644
> index 0000000..e4c5c41
> --- /dev/null
> +++ b/drivers/huaweicdmamodem/network-registration.c
> @@ -0,0 +1,159 @@
> +/*
> + *
> + *  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
> +
> +#define _GNU_SOURCE
> +#include <glib.h>
> +
> +#include <ofono/log.h>
> +#include <ofono/modem.h>
> +#include <ofono/cdma-netreg.h>
> +
> +#include "gatchat.h"
> +
> +#include "huaweicdmamodem.h"
> +
> +static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
> +
> +struct huaweicdma_netreg_data {
> +	GAtChat *chat;
> +};
> +
> +static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_cdma_netreg *netreg = user_data;
> +	gint srv_status;
> +	gint srv_domain;
> +	gint roaming_status;
> +	int status;
> +	GAtResultIter iter;
> +
> +	if (!ok)
> +		return;
> +
> +	g_at_result_iter_init(&iter, result);
> +
> +	if (!g_at_result_iter_next(&iter, "^SYSINFO:"))
> +		return;
> +
> +	if (!g_at_result_iter_next_number(&iter, &srv_status))
> +		return;
> +
> +	if (!g_at_result_iter_next_number(&iter, &srv_domain))
> +		return;
> +
> +	if (!g_at_result_iter_next_number(&iter, &roaming_status))
> +		return;
> +
> +	DBG("%d, %d, %d", srv_status, srv_domain, roaming_status);
> +
> +	switch (srv_status) {
> +	case 1:	/* Restricted service */
> +	case 2:	/* Service valid */
> +	case 3:	/* Restricted region service */
> +		status = CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED;
> +		break;
> +	case 0:	/* No service */
> +	case 4:	/* Not registered */
> +	default:
> +		status = CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
> +		break;
> +	}
> +
> +	switch (srv_domain) {
> +	case 0: /* No service */
> +	case 255: /* CDMA not supported */
> +		status = CDMA_NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
> +		break;
> +	case 1: /* Only CS */
> +	case 2: /* Only PS */
> +	case 3: /* CS + PS */
> +	case 4: /* CS registered, PS in searching state */
> +		break;
> +	}
> +	
> +	if (status == CDMA_NETWORK_REGISTRATION_STATUS_REGISTERED
> +				&& roaming_status)
> +		status = CDMA_NETWORK_REGISTRATION_STATUS_ROAMING;

Do we really have to make it this complicated? Just nest the switch
statement for srv_status and srv_domain.

It is pretty obvious that if srv_status results in not registered that
we do not have to do any further checks.

> +	ofono_cdma_netreg_status_notify(netreg, status);
> +}
> +
> +
> +static void mode_notify(GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_cdma_netreg *netreg = user_data;
> +	struct huaweicdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
> +
> +	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix, sysinfo_cb,
> +				netreg, NULL);

Just for style sake, put sysinfo_cb on the next line. Most of the
command do that. Even if it fits into the previous line.

> +}
> +
> +static int huaweicdma_netreg_probe(struct ofono_cdma_netreg *netreg,
> +				unsigned int vendor, void *data)
> +{
> +	GAtChat *chat = data;
> +	struct huaweicdma_netreg_data *nd;
> +
> +	nd = g_try_new0(struct huaweicdma_netreg_data, 1);

You need to check if memory allocation succeeded here.

> +	nd->chat = g_at_chat_clone(chat);

Extra empty line here.

> +	ofono_cdma_netreg_set_data(netreg, nd);
> +
> +	g_at_chat_register(nd->chat, "^MODE:",
> +				mode_notify, FALSE, netreg, NULL);
> +
> +	ofono_cdma_netreg_register(netreg);

Please do not do that here. Also I am not sure that has actually been
tested, but this should fail and cause various side effects.

Just have a different callback for the initial AT^SYSINFO call. You
should really only register that atom once you know that it is supported
and at least on AT^SYSINFO succeeded

> +	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix, sysinfo_cb,
> +				netreg, NULL);

Same style comment as above.

> +
> +	return 0;
> +}
> +
> +static void huaweicdma_netreg_remove(struct ofono_cdma_netreg *netreg)
> +{
> +	struct huaweicdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
> +
> +	ofono_cdma_netreg_set_data(netreg, NULL);
> +
> +	g_at_chat_unref(nd->chat);
> +	g_free(nd);
> +}
> +
> +static struct ofono_cdma_netreg_driver driver = {
> +	.name	= "huaweicdmamodem",
> +	.probe	= huaweicdma_netreg_probe,
> +	.remove	= huaweicdma_netreg_remove,
> +};
> +
> +void huaweicdma_netreg_init(void)
> +{
> +	ofono_cdma_netreg_driver_register(&driver);
> +}
> +
> +void huaweicdma_netreg_exit(void)
> +{
> +	ofono_cdma_netreg_driver_unregister(&driver);
> +}

Regards

Marcel



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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03 13:50 [PATCH_v5 0/8] Create CDMA Network Registration atom Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 1/8] cdmamodem: Define " Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 2/8] cdmamodem: define CDMA netreg atom Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 3/8] cdmamodem: create include file for CDMA netreg Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 4/8] cdmamodem: create the interface " Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 5/8] cdmamodem: define cdma network status Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 6/8] cdmamodem: implement " Bertrand Aygon
2011-08-03 13:50 ` [PATCH_v5 7/8] huaweicdmamodem: create a huawei cdma driver Bertrand Aygon
2011-08-05  8:49   ` Marcel Holtmann
2011-08-03 13:50 ` [PATCH_v5 8/8] huaweicdma: register to CDMA netreg atom Bertrand Aygon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.