All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3 v5] Network Time Plugin
@ 2011-02-09 19:12 Antti Paila
  2011-02-09 19:12 ` [PATCH 1/3] nettime: Network time plugin implementation Antti Paila
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Antti Paila @ 2011-02-09 19:12 UTC (permalink / raw)
  To: ofono

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

 This series of patches introduces the network time part of
 the NITZ feature as outlined in 3GPP spec 22.042.
 The plugin is for delivering network indicated time information
 to timed process which is responsible for maintaining the system
 time. The delivery is achieved by timed implementing an interface
 with a method that is called by the nettime plugin with time related
 info as a parameter of the method.

Antti Paila (3):
  nettime: Network time plugin implementation
  nettime: Makefile.am modification
  nettime: Mock Timed for testing

 Makefile.am             |    6 +-
 plugins/meego-nettime.c |  321 +++++++++++++++++++++++++++++++++++++++++++++++
 test/test-nettime       |   35 +++++
 3 files changed, 361 insertions(+), 1 deletions(-)
 create mode 100644 plugins/meego-nettime.c
 create mode 100755 test/test-nettime


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

* [PATCH 1/3] nettime: Network time plugin implementation
  2011-02-09 19:12 [PATCH 0/3 v5] Network Time Plugin Antti Paila
@ 2011-02-09 19:12 ` Antti Paila
  2011-02-09 19:12 ` [PATCH 2/3] nettime: Makefile.am modification Antti Paila
  2011-02-09 19:12 ` [PATCH 3/3] nettime: Mock Timed for testing Antti Paila
  2 siblings, 0 replies; 4+ messages in thread
From: Antti Paila @ 2011-02-09 19:12 UTC (permalink / raw)
  To: ofono

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

---
 plugins/meego-nettime.c |  321 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 321 insertions(+), 0 deletions(-)
 create mode 100644 plugins/meego-nettime.c

diff --git a/plugins/meego-nettime.c b/plugins/meego-nettime.c
new file mode 100644
index 0000000..442925c
--- /dev/null
+++ b/plugins/meego-nettime.c
@@ -0,0 +1,321 @@
+/*
+ *
+ *  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 <stdlib.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 <gdbus.h>
+#include <string.h>
+#include "ofono.h"
+#include "common.h"
+
+#define TIMED_PATH "/com/meego/timed"
+#define TIMED_SERVICE "com.meego.timed"
+
+struct nt_data {
+	gboolean time_available;
+	gboolean time_pending;
+	time_t nw_time_utc;
+	time_t received;
+	int dst;
+	int time_zone;
+	char mcc[OFONO_MAX_MCC_LENGTH + 1];
+	char mnc[OFONO_MAX_MNC_LENGTH + 1];
+	unsigned int timed_watch;
+	gboolean timed_present;
+	struct ofono_netreg *netreg;
+	unsigned int netreg_status_watch;
+	unsigned int netreg_watch;
+};
+
+static gboolean encode_time_format(struct ofono_network_time *time,
+				 struct tm *tm)
+{
+
+	if (time->year < 0)
+		return FALSE;
+
+	tm->tm_year = time->year - 1900;
+	tm->tm_mon = time->mon - 1;
+	tm->tm_mday = time->mday;
+	tm->tm_hour = time->hour;
+	tm->tm_min = time->min;
+	tm->tm_sec = time->sec;
+
+	return TRUE;
+}
+
+static time_t get_monotonic_time()
+{
+	struct timespec ts;
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+
+	return ts.tv_sec;
+}
+
+static int fill_time_notification(DBusMessage *msg,
+		struct nt_data *ntd)
+{
+	DBusMessageIter iter, iter_array;
+	int64_t utc;
+
+	const char *mcc = ntd->mcc;
+	const char *mnc = ntd->mnc;
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_open_container(&iter,
+					DBUS_TYPE_ARRAY,
+					"{sv}",
+					&iter_array);
+
+	if (ntd->time_pending) {
+		if (ntd->time_available) {
+			utc = ntd->nw_time_utc - ntd->received;
+			ofono_dbus_dict_append(&iter_array,
+						"UTC",
+						DBUS_TYPE_INT64,
+						&utc);
+		}
+
+		ofono_dbus_dict_append(&iter_array,
+					"DST",
+					DBUS_TYPE_INT32,
+					&ntd->dst);
+		ofono_dbus_dict_append(&iter_array,
+					"Timezone",
+					DBUS_TYPE_INT32,
+					&ntd->time_zone);
+	}
+
+	ofono_dbus_dict_append(&iter_array,
+			"MobileCountryCode",
+			DBUS_TYPE_STRING,
+			&mcc);
+	ofono_dbus_dict_append(&iter_array,
+			"MobileNetworkCode",
+			DBUS_TYPE_STRING,
+			&mnc);
+
+	dbus_message_iter_close_container(&iter, &iter_array);
+	return 0;
+}
+
+static DBusMessage *create_time_notification(
+			struct ofono_nettime_context *context)
+{
+	DBusMessage *message;
+	struct nt_data *ntd = context->data;
+	const char *path = ofono_modem_get_path(context->modem);
+
+	if (path == NULL) {
+		ofono_error("Fetching path for modem failed");
+		return NULL;
+	}
+
+	message = dbus_message_new_method_call(TIMED_SERVICE, TIMED_PATH,
+					"com.meego.NetworkTime", "Notify");
+
+	if (message == NULL)
+		return NULL;
+
+	dbus_message_set_no_reply(message, TRUE);
+	fill_time_notification(message, ntd);
+
+	return message;
+}
+
+static void nettime_remove(struct ofono_nettime_context *context)
+{
+	struct nt_data *ntd = context->data;
+
+	DBG("Network Time Remove for modem: %p", context->modem);
+
+	if (ntd->timed_watch > 0)
+		g_dbus_remove_watch(ofono_dbus_get_connection(),
+					ntd->timed_watch);
+
+	if (ntd->netreg_status_watch > 0 && ntd->netreg != NULL) {
+		__ofono_netreg_remove_status_watch(ntd->netreg,
+						ntd->netreg_status_watch);
+	}
+
+	__ofono_modem_remove_atom_watch(context->modem,
+				ntd->netreg_watch);
+	g_free(ntd);
+}
+
+static void notify(void *data)
+{
+	struct ofono_nettime_context *context = data;
+	struct nt_data *ntd = context->data;
+	DBusMessage *message;
+	const char *mcc, *mnc;
+
+	mcc = ofono_netreg_get_mcc(ntd->netreg);
+	mnc = ofono_netreg_get_mnc(ntd->netreg);
+
+	if (ntd->timed_present == FALSE ||
+			mcc == NULL ||
+			mnc == NULL ||
+			(strcmp(ntd->mnc, mnc) == 0 &&
+			strcmp(ntd->mcc, mcc) == 0 &&
+			ntd->time_pending == FALSE))
+		return;
+
+	strcpy(ntd->mnc, mnc);
+	strcpy(ntd->mcc, mcc);
+
+	message = create_time_notification(context);
+	if (message == NULL) {
+		ofono_error("Failed to create Notification message");
+		return;
+	}
+
+	g_dbus_send_message(ofono_dbus_get_connection(), message);
+	ntd->time_pending = FALSE;
+}
+
+static void notify_cb(int status, int lac, int ci, int tech,
+			const char *mcc, const char *mnc, void *data)
+{
+	if (mcc != NULL && mnc != NULL)
+		notify(data);
+}
+
+
+static void nettime_info_received(struct ofono_nettime_context *context,
+				struct ofono_network_time *info)
+{
+	struct tm t;
+	struct nt_data *ntd = context->data;
+
+	DBG("Network time notification received, modem: %p",
+			context->modem);
+
+	if (info == NULL)
+		return;
+
+	ntd->received = get_monotonic_time();
+	ntd->time_pending = TRUE;
+
+	ntd->time_available = encode_time_format(info, &t);
+	if (ntd->time_available == TRUE)
+		ntd->nw_time_utc = timegm(&t);
+
+	ntd->dst = info->dst;
+	ntd->time_zone = info->utcoff;
+
+	notify(context);
+
+}
+
+static void timed_connect(DBusConnection *connection, void *user_data)
+{
+	struct ofono_nettime_context *context = user_data;
+	struct nt_data *ntd = context->data;
+
+	ntd->timed_present = TRUE;
+
+	notify(context);
+}
+
+static void timed_disconnect(DBusConnection *connection, void *user_data)
+{
+	struct ofono_nettime_context *context = user_data;
+	struct nt_data *ntd = context->data;
+
+	ntd->timed_present = FALSE;
+}
+
+static void netreg_watch_cb(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_nettime_context *context = data;
+	struct nt_data *ntd = context->data;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+		ntd->netreg = __ofono_atom_get_data(atom);
+		ntd->netreg_status_watch = __ofono_netreg_add_status_watch(
+					ntd->netreg, notify_cb,
+					context, NULL);
+	} else {
+		ntd->netreg_status_watch = 0;
+		ntd->netreg = NULL;
+	}
+}
+
+static int nettime_probe(struct ofono_nettime_context *context)
+{
+
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct nt_data *ntd = g_new0(struct nt_data, 1);
+
+	DBG("Network Time Probe for modem: %p", context->modem);
+
+	context->data = ntd;
+
+	if (ntd->timed_watch == 0)
+		ntd->timed_watch = g_dbus_add_service_watch(conn, TIMED_SERVICE,
+					timed_connect, timed_disconnect,
+					context, NULL);
+
+	if (ntd->netreg_watch == 0)
+		ntd->netreg_watch = __ofono_modem_add_atom_watch(
+					context->modem,
+					OFONO_ATOM_TYPE_NETREG,
+					netreg_watch_cb,
+					context, NULL);
+
+	return 0;
+}
+
+static struct ofono_nettime_driver nettime_driver = {
+	.name		= "Meego Network Time",
+	.probe		= nettime_probe,
+	.remove		= nettime_remove,
+	.info_received	= nettime_info_received,
+};
+
+
+static int nettime_init(void)
+{
+	return ofono_nettime_driver_register(&nettime_driver);
+}
+
+static void nettime_exit(void)
+{
+	ofono_nettime_driver_unregister(&nettime_driver);
+}
+
+OFONO_PLUGIN_DEFINE(meego_nettime, "Meego Network Time Plugin",
+		VERSION, OFONO_PLUGIN_PRIORITY_DEFAULT,
+		nettime_init, nettime_exit)
+
-- 
1.7.1


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

* [PATCH 2/3] nettime: Makefile.am modification
  2011-02-09 19:12 [PATCH 0/3 v5] Network Time Plugin Antti Paila
  2011-02-09 19:12 ` [PATCH 1/3] nettime: Network time plugin implementation Antti Paila
@ 2011-02-09 19:12 ` Antti Paila
  2011-02-09 19:12 ` [PATCH 3/3] nettime: Mock Timed for testing Antti Paila
  2 siblings, 0 replies; 4+ messages in thread
From: Antti Paila @ 2011-02-09 19:12 UTC (permalink / raw)
  To: ofono

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

---
 Makefile.am |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e402de4..b043f9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -338,6 +338,9 @@ builtin_modules += example_provision
 builtin_sources += examples/provision.c
 endif
 
+builtin_modules += meego_nettime
+builtin_sources += plugins/meego-nettime.c
+
 builtin_modules += smart_messaging
 builtin_sources += plugins/smart-messaging.c
 
@@ -480,7 +483,8 @@ test_scripts = test/backtrace \
 		test/cdma-hangup \
 		test/disable-call-forwarding \
 		test/list-messages \
-		test/test-sms
+		test/test-sms \
+		test/test-nettime
 
 if TEST
 testdir = $(pkglibdir)/test
-- 
1.7.1


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

* [PATCH 3/3] nettime: Mock Timed for testing
  2011-02-09 19:12 [PATCH 0/3 v5] Network Time Plugin Antti Paila
  2011-02-09 19:12 ` [PATCH 1/3] nettime: Network time plugin implementation Antti Paila
  2011-02-09 19:12 ` [PATCH 2/3] nettime: Makefile.am modification Antti Paila
@ 2011-02-09 19:12 ` Antti Paila
  2 siblings, 0 replies; 4+ messages in thread
From: Antti Paila @ 2011-02-09 19:12 UTC (permalink / raw)
  To: ofono

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

---
 test/test-nettime |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)
 create mode 100755 test/test-nettime

diff --git a/test/test-nettime b/test/test-nettime
new file mode 100755
index 0000000..acdd167
--- /dev/null
+++ b/test/test-nettime
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import gobject
+import dbus
+import sys
+import time
+import dbus.service
+import dbus.mainloop.glib
+
+
+class NetworkTime(dbus.service.Object):
+	def __init__(self):
+		busName = dbus.service.BusName('com.meego.timed',
+					bus = dbus.SystemBus())
+		dbus.service.Object.__init__(self, busName, '/com/meego/timed')
+	@dbus.service.method(dbus_interface="com.meego.NetworkTime",
+					in_signature="a{sv}", out_signature="")
+	def Notify(self, arg):
+		print arg
+		print
+		print "Time from mobile: %d" % arg["UTC"]
+		print "DST: %d" % arg["DST"]
+		print "Timezone: %d" % arg["Timezone"]
+		print "MNC: %s" % arg["MobileNetworkCode"]
+		print "MCC: %s" % arg["MobileCountryCode"]
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+	agent = NetworkTime()
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
+
+
+
-- 
1.7.1


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

end of thread, other threads:[~2011-02-09 19:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09 19:12 [PATCH 0/3 v5] Network Time Plugin Antti Paila
2011-02-09 19:12 ` [PATCH 1/3] nettime: Network time plugin implementation Antti Paila
2011-02-09 19:12 ` [PATCH 2/3] nettime: Makefile.am modification Antti Paila
2011-02-09 19:12 ` [PATCH 3/3] nettime: Mock Timed for testing Antti Paila

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.