All of lore.kernel.org
 help / color / mirror / Atom feed
* Network time patches, take two
@ 2010-05-18 16:36 Aki Niemi
  2010-05-18 16:36 ` [PATCH 1/2] Add network time support Aki Niemi
  2010-05-18 16:36 ` [PATCH 2/2] Add isimodem support for network time Aki Niemi
  0 siblings, 2 replies; 3+ messages in thread
From: Aki Niemi @ 2010-05-18 16:36 UTC (permalink / raw)
  To: ofono

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

Resending, as the first patch of the two was failing make distcheck.


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

* [PATCH 1/2] Add network time support
  2010-05-18 16:36 Network time patches, take two Aki Niemi
@ 2010-05-18 16:36 ` Aki Niemi
  2010-05-18 16:36 ` [PATCH 2/2] Add isimodem support for network time Aki Niemi
  1 sibling, 0 replies; 3+ messages in thread
From: Aki Niemi @ 2010-05-18 16:36 UTC (permalink / raw)
  To: ofono

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

Adding a new notify function in the netreg atom for notifying a
received Network Identification and Timezone (NITZ) indication. This
data is consumed via a nettime plugin, of which there is also an
example.
---
 Makefile.am               |   10 ++--
 include/netreg.h          |    2 +
 include/nettime.h         |   52 +++++++++++++++++++
 include/types.h           |   11 ++++
 plugins/example_nettime.c |   84 +++++++++++++++++++++++++++++++
 src/modem.c               |    1 +
 src/nettime.c             |  121 +++++++++++++++++++++++++++++++++++++++++++++
 src/network.c             |   11 ++++
 src/ofono.h               |    8 +++
 9 files changed, 296 insertions(+), 4 deletions(-)
 create mode 100644 include/nettime.h
 create mode 100644 plugins/example_nettime.c
 create mode 100644 src/nettime.c

diff --git a/Makefile.am b/Makefile.am
index 7fd862f..ed13346 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,7 +12,8 @@ include_HEADERS = include/log.h include/plugin.h include/history.h \
 			include/netreg.h include/voicecall.h include/devinfo.h \
 			include/cbs.h include/call-volume.h \
 			include/gprs.h include/gprs-context.h \
-			include/radio-settings.h include/stk.h
+			include/radio-settings.h include/stk.h \
+			include/nettime.h
 
 nodist_include_HEADERS = include/version.h
 
@@ -242,8 +243,8 @@ builtin_sources += plugins/ste.c
 endif
 
 if MAINTAINER_MODE
-builtin_modules += example_history
-builtin_sources += plugins/example_history.c
+builtin_modules += example_history example_nettime
+builtin_sources += plugins/example_history.c plugins/example_nettime.c
 endif
 
 sbin_PROGRAMS = src/ofonod
@@ -260,7 +261,8 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) \
 			src/simutil.h src/simutil.c src/storage.h \
 			src/storage.c src/cbs.c src/watch.c src/call-volume.c \
 			src/gprs.c src/idmap.h src/idmap.c \
-			src/radio-settings.c src/stkutil.h src/stkutil.c
+			src/radio-settings.c src/stkutil.h src/stkutil.c \
+			src/nettime.c
 
 src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl
 
diff --git a/include/netreg.h b/include/netreg.h
index 0079477..8860960 100644
--- a/include/netreg.h
+++ b/include/netreg.h
@@ -93,6 +93,8 @@ struct ofono_netreg_driver {
 void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength);
 void ofono_netreg_status_notify(struct ofono_netreg *netreg, int status,
 					int lac, int ci, int tech);
+void ofono_netreg_time_notify(struct ofono_netreg *netreg,
+				struct ofono_network_time *info);
 
 int ofono_netreg_driver_register(const struct ofono_netreg_driver *d);
 void ofono_netreg_driver_unregister(const struct ofono_netreg_driver *d);
diff --git a/include/nettime.h b/include/nettime.h
new file mode 100644
index 0000000..0f23cc7
--- /dev/null
+++ b/include/nettime.h
@@ -0,0 +1,52 @@
+/*
+ *
+ *  oFono - Open Telephony stack for Linux
+ *
+ *  Copyright (C) 2010  Nokia Corporation and/or its subsidiary(-ies).
+ *
+ *  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_NETTIME_H
+#define __OFONO_NETTIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ofono_network_time;
+
+struct ofono_nettime_context {
+	struct ofono_nettime_driver *driver;
+	struct ofono_modem *modem;
+	void *data;
+};
+
+struct ofono_nettime_driver {
+	const char *name;
+	int (*probe)(struct ofono_nettime_context *context);
+	void (*remove)(struct ofono_nettime_context *context);
+	void (*info_received)(struct ofono_nettime_context *context,
+				struct ofono_network_time *info);
+};
+
+int ofono_nettime_driver_register(const struct ofono_nettime_driver *driver);
+void ofono_nettime_driver_unregister(const struct ofono_nettime_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_NETTIME_H */
diff --git a/include/types.h b/include/types.h
index 7b08b8c..2b154f0 100644
--- a/include/types.h
+++ b/include/types.h
@@ -92,6 +92,17 @@ struct ofono_call {
 	int clip_validity;
 };
 
+struct ofono_network_time {
+	int sec;	/* Seconds [0..59], -1 if unavailable */
+	int min;	/* Minutes [0..59], -1 if unavailable */
+	int hour;	/* Hours [0..23], -1 if unavailable */
+	int mday;	/* Day of month [1..31], -1 if unavailable */
+	int mon;	/* Month [1..12], -1 if unavailable */
+	int year;	/* Current year, -1 if unavailable */
+	int dst;	/* Current adjustment, in seconds */
+	int utcoff;	/* Offset from UTC in seconds */
+};
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/plugins/example_nettime.c b/plugins/example_nettime.c
new file mode 100644
index 0000000..60045be
--- /dev/null
+++ b/plugins/example_nettime.c
@@ -0,0 +1,84 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Nokia Corporation and/or its subsidiary(-ies).
+ *
+ *  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>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/nettime.h>
+#include <ofono/types.h>
+
+#include "common.h"
+
+static int example_nettime_probe(struct ofono_nettime_context *context)
+{
+	ofono_debug("Example Network Time Probe for modem: %p",
+			context->modem);
+	return 0;
+}
+
+static void example_nettime_remove(struct ofono_nettime_context *context)
+{
+	ofono_debug("Example Network Time Remove for modem: %p",
+			context->modem);
+}
+
+static void example_nettime_info_received(struct ofono_nettime_context *context,
+						struct ofono_network_time *info)
+{
+	if (!info)
+		return;
+
+	ofono_debug("Received a network time notification on modem: %p",
+			context->modem);
+	ofono_debug("Time: %04d-%02d-%02d %02d:%02d:%02d%c%02d:%02d (DST=%d)",
+			info->year, info->mon, info->mday, info->hour,
+			info->min, info->sec, info->utcoff > 0 ? '+' : '-',
+			info->utcoff / 3600, (info->utcoff % 3600) / 60,
+			info->dst / 3600);
+}
+
+static struct ofono_nettime_driver example_driver = {
+	.name		= "Example Network Time",
+	.probe		= example_nettime_probe,
+	.remove		= example_nettime_remove,
+	.info_received	= example_nettime_info_received,
+};
+
+static int example_nettime_init(void)
+{
+	return ofono_nettime_driver_register(&example_driver);
+}
+
+static void example_nettime_exit(void)
+{
+	ofono_nettime_driver_unregister(&example_driver);
+}
+
+OFONO_PLUGIN_DEFINE(example_nettime, "Example Network Time Plugin",
+			VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+			example_nettime_init, example_nettime_exit)
diff --git a/src/modem.c b/src/modem.c
index 0d0cb2a..bf77eb9 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -1147,6 +1147,7 @@ static void modem_sim_ready(void *user, enum ofono_sim_state new_state)
 			modem->driver->post_sim(modem);
 
 		__ofono_history_probe_drivers(modem);
+		__ofono_nettime_probe_drivers(modem);
 	}
 }
 
diff --git a/src/nettime.c b/src/nettime.c
new file mode 100644
index 0000000..b17e375
--- /dev/null
+++ b/src/nettime.c
@@ -0,0 +1,121 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2010  Nokia Corporation and/or its subsidiary(-ies).
+ *
+ *  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 <stdio.h>
+
+#include <glib.h>
+
+#include "ofono.h"
+
+static GSList *nettime_drivers = NULL;
+
+static struct ofono_nettime_context *nettime_context_create(
+					struct ofono_modem *modem,
+					struct ofono_nettime_driver *driver)
+{
+	struct ofono_nettime_context *context;
+
+	if (driver->probe == NULL)
+		return NULL;
+
+	context = g_try_new0(struct ofono_nettime_context, 1);
+
+	if (context == NULL)
+		return NULL;
+
+	context->driver = driver;
+	context->modem = modem;
+
+	if (driver->probe(context) < 0) {
+		g_free(context);
+		return NULL;
+	}
+
+	return context;
+}
+
+static void context_remove(struct ofono_atom *atom)
+{
+	struct ofono_nettime_context *context = __ofono_atom_get_data(atom);
+
+	if (context->driver->remove)
+		context->driver->remove(context);
+
+	g_free(context);
+}
+
+void __ofono_nettime_probe_drivers(struct ofono_modem *modem)
+{
+	struct ofono_nettime_driver *driver;
+	struct ofono_nettime_context *context;
+	GSList *l;
+
+	for (l = nettime_drivers; l; l = l->next) {
+		driver = l->data;
+
+		context = nettime_context_create(modem, driver);
+
+		if (!context)
+			continue;
+
+		__ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_NETTIME,
+						context_remove, context);
+	}
+}
+
+static void nettime_info_received(struct ofono_atom *atom, void *data)
+{
+	struct ofono_nettime_context *context = __ofono_atom_get_data(atom);
+	struct ofono_network_time *info = data;
+
+	if (context->driver->info_received == NULL)
+		return;
+
+	context->driver->info_received(context, info);
+}
+
+void __ofono_nettime_info_received(struct ofono_modem *modem,
+					struct ofono_network_time *info)
+{
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_NETTIME,
+					nettime_info_received, info);
+}
+
+int ofono_nettime_driver_register(const struct ofono_nettime_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	nettime_drivers = g_slist_prepend(nettime_drivers, (void *)driver);
+
+	return 0;
+}
+
+void ofono_nettime_driver_unregister(const struct ofono_nettime_driver *driver)
+{
+	DBG("driver: %p name: %s", driver, driver->name);
+
+	nettime_drivers = g_slist_remove(nettime_drivers, driver);
+}
diff --git a/src/network.c b/src/network.c
index b2e5821..87a73e3 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1065,6 +1065,17 @@ void ofono_netreg_status_notify(struct ofono_netreg *netreg, int status,
 	notify_status_watches(netreg);
 }
 
+void ofono_netreg_time_notify(struct ofono_netreg *netreg,
+				struct ofono_network_time *info)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(netreg->atom);
+
+	if (!info)
+		return;
+
+	__ofono_nettime_info_received(modem, info);
+}
+
 static GSList *compress_operator_list(const struct ofono_network_operator *list,
 					int total)
 {
diff --git a/src/ofono.h b/src/ofono.h
index 7b13cce..84b5c23 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -115,6 +115,7 @@ enum ofono_atom_type {
 	OFONO_ATOM_TYPE_GPRS_CONTEXT = 17,
 	OFONO_ATOM_TYPE_RADIO_SETTINGS = 18,
 	OFONO_ATOM_TYPE_STK = 19,
+	OFONO_ATOM_TYPE_NETTIME = 20,
 };
 
 enum ofono_atom_watch_condition {
@@ -264,3 +265,10 @@ struct sms;
 
 void __ofono_message_waiting_mwi(struct ofono_message_waiting *mw,
 				struct sms *sms, gboolean *out_discard);
+
+#include <ofono/nettime.h>
+
+void __ofono_nettime_probe_drivers(struct ofono_modem *modem);
+
+void __ofono_nettime_info_received(struct ofono_modem * modem,
+					struct ofono_network_time *info);
-- 
1.7.0.4


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

* [PATCH 2/2] Add isimodem support for network time
  2010-05-18 16:36 Network time patches, take two Aki Niemi
  2010-05-18 16:36 ` [PATCH 1/2] Add network time support Aki Niemi
@ 2010-05-18 16:36 ` Aki Niemi
  1 sibling, 0 replies; 3+ messages in thread
From: Aki Niemi @ 2010-05-18 16:36 UTC (permalink / raw)
  To: ofono

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

---
 drivers/isimodem/debug.c                |    2 +
 drivers/isimodem/network-registration.c |   39 +++++++++++++++++++++++++++++++
 drivers/isimodem/network.h              |    3 ++
 3 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/drivers/isimodem/debug.c b/drivers/isimodem/debug.c
index 3ba9d52..86530fd 100644
--- a/drivers/isimodem/debug.c
+++ b/drivers/isimodem/debug.c
@@ -744,6 +744,7 @@ const char *net_message_id_name(enum net_message_id value)
 		_(NET_RSSI_GET_REQ);
 		_(NET_RSSI_GET_RESP);
 		_(NET_RSSI_IND);
+		_(NET_TIME_IND);
 		_(NET_RAT_IND);
 		_(NET_RAT_REQ);
 		_(NET_RAT_RESP);
@@ -768,6 +769,7 @@ const char *net_subblock_name(enum net_subblock value)
 		_(NET_GSM_REG_INFO);
 		_(NET_DETAILED_NETWORK_INFO);
 		_(NET_GSM_OPERATOR_INFO);
+		_(NET_TIME_INFO);
 		_(NET_GSM_BAND_INFO);
 		_(NET_RAT_INFO);
 		_(NET_AVAIL_NETWORK_INFO_COMMON);
diff --git a/drivers/isimodem/network-registration.c b/drivers/isimodem/network-registration.c
index eddf6fd..75dd6bc 100644
--- a/drivers/isimodem/network-registration.c
+++ b/drivers/isimodem/network-registration.c
@@ -746,6 +746,44 @@ static void rssi_ind_cb(GIsiClient *client, const void *restrict data,
 	ofono_netreg_strength_notify(netreg, msg[1]);
 }
 
+static void time_ind_cb(GIsiClient *client, const void *restrict data,
+			size_t len, uint16_t object, void *opaque)
+{
+	const unsigned char *msg = data;
+	const unsigned char *nitz = msg + 3;
+	struct ofono_netreg *netreg = opaque;
+
+	struct ofono_network_time info;
+
+	if (!msg || len < 13 || msg[0] != NET_TIME_IND
+		|| nitz[0] != NET_TIME_INFO)
+		return;
+
+	nitz += 2;
+
+	/* Value is years since last turn of century */
+	info.year = nitz[0] != NET_INVALID_TIME ? nitz[0] : -1;
+	info.year += 2000;
+
+	info.mon = nitz[1] != NET_INVALID_TIME ? nitz[1] : -1;
+	info.mday = nitz[2] != NET_INVALID_TIME ? nitz[2] : -1;
+	info.hour = nitz[3] != NET_INVALID_TIME ? nitz[3] : -1;
+	info.min = nitz[4] != NET_INVALID_TIME ? nitz[4] : -1;
+	info.sec = nitz[5] != NET_INVALID_TIME ? nitz[5] : -1;
+
+	/* Most significant bit set indicates negative offset. The
+	 * second most significant bit is 'reserved'. The value is the
+	 * offset from UTCin a count of 15min intervals, possibly
+	 * including the current DST adjustment. */
+	info.utcoff = (nitz[6] & 0x3F) * 15 * 60;
+	if (nitz[6] & 0x80)
+		info.utcoff *= -1;
+
+	info.dst = nitz[7] != NET_INVALID_TIME ? nitz[7] : -1;
+
+	ofono_netreg_time_notify(netreg, &info);
+}
+
 static bool rssi_resp_cb(GIsiClient *client, const void *restrict data,
 				size_t len, uint16_t object, void *opaque)
 {
@@ -851,6 +889,7 @@ static gboolean isi_netreg_register(gpointer user)
 	g_isi_subscribe(nd->client, NET_REG_STATUS_IND, reg_status_ind_cb,
 			netreg);
 	g_isi_subscribe(nd->client, NET_RAT_IND, rat_ind_cb, netreg);
+	g_isi_subscribe(nd->client, NET_TIME_IND, time_ind_cb, netreg);
 
 	/* Bootstrap current RAT setting */
 	if (!g_isi_request_make(nd->client, rat, sizeof(rat),
diff --git a/drivers/isimodem/network.h b/drivers/isimodem/network.h
index ec52321..77b4ec3 100644
--- a/drivers/isimodem/network.h
+++ b/drivers/isimodem/network.h
@@ -30,6 +30,7 @@ extern "C" {
 #define NETWORK_TIMEOUT		5
 #define NETWORK_SCAN_TIMEOUT	180
 #define NETWORK_SET_TIMEOUT	240
+#define NET_INVALID_TIME	0x64
 
 enum net_message_id {
 	NET_SET_REQ = 0x07,
@@ -37,6 +38,7 @@ enum net_message_id {
 	NET_RSSI_GET_REQ = 0x0B,
 	NET_RSSI_GET_RESP = 0x0C,
 	NET_RSSI_IND = 0x1E,
+	NET_TIME_IND = 0x27,
 	NET_RAT_IND = 0x35,
 	NET_RAT_REQ = 0x36,
 	NET_RAT_RESP = 0x37,
@@ -57,6 +59,7 @@ enum net_subblock {
 	NET_GSM_REG_INFO = 0x09,
 	NET_DETAILED_NETWORK_INFO = 0x0B,
 	NET_GSM_OPERATOR_INFO = 0x0C,
+	NET_TIME_INFO = 0x10,
 	NET_GSM_BAND_INFO = 0x11,
 	NET_RAT_INFO = 0x2C,
 	NET_AVAIL_NETWORK_INFO_COMMON = 0xE1,
-- 
1.7.0.4


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

end of thread, other threads:[~2010-05-18 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-18 16:36 Network time patches, take two Aki Niemi
2010-05-18 16:36 ` [PATCH 1/2] Add network time support Aki Niemi
2010-05-18 16:36 ` [PATCH 2/2] Add isimodem support for network time Aki Niemi

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.