All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC BlueZ 0/4] Time GATT Profile (server)
@ 2011-09-26 21:01 Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 1/4] GATT Time Server: add Current Time service Anderson Lizardo
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Anderson Lizardo @ 2011-09-26 21:01 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

Next in our "work in progress" profiles, is Time Profile. This short series
contain the implementation for the Current Time Service (including Local Time
Information characteristic), and a dummy "Reference Time Update Service"
(RTUS).

We are currently working on RTUS support for N9/harmattan, and we should send
an updated RFC containing it soon.

A few notes:

* Current Time Service implementation uses POSIX fuctions, so it should be
  platform independent.

* Reference Time Update Service needs a certain level of interaction with the
  platform, therefore we need an abstraction to support multiple platforms.

To follow current development (including the experimental N9 support), see:

git://gitorious.org/~lizardo/bluez/lizardo-bluez.git (branch "time-server")

Feedback is very welcome!
--
Anderson Lizardo
Instituto Nokia de Tecnologia (INdT)
Manaus - Brazil


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

* [PATCH RFC BlueZ 1/4] GATT Time Server: add Current Time service
  2011-09-26 21:01 [PATCH RFC BlueZ 0/4] Time GATT Profile (server) Anderson Lizardo
@ 2011-09-26 21:01 ` Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 2/4] GATT Time Server: add Reference Time Update service Anderson Lizardo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Anderson Lizardo @ 2011-09-26 21:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 time/server.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/time/server.c b/time/server.c
index 89cc460..5001874 100644
--- a/time/server.c
+++ b/time/server.c
@@ -26,10 +26,75 @@
 #include <config.h>
 #endif
 
+#include <glib.h>
+#include <time.h>
+#include <errno.h>
+#include <bluetooth/uuid.h>
+
+#include "att.h"
+#include "gattrib.h"
+#include "attrib-server.h"
+#include "gatt-service.h"
+#include "log.h"
 #include "server.h"
 
+/* UUIDs not yet approved by Bluetooth SIG */
+#define CURRENT_TIME_SVC_UUID		0x1805
+
+#define CT_TIME_CHR_UUID		0x2A2B
+
+static uint8_t current_time_read(struct attribute *a, gpointer user_data)
+{
+	struct timespec tp;
+	struct tm tm;
+	uint8_t value[10];
+
+	if (clock_gettime(CLOCK_REALTIME, &tp) == -1) {
+		error("clock_gettime: %s", strerror(errno));
+		/* FIXME: add proper application error codes */
+		return ATT_ECODE_IO;
+	}
+
+	if (localtime_r(&tp.tv_sec, &tm) == NULL) {
+		error("localtime_r() failed");
+		return ATT_ECODE_IO;
+	}
+
+	att_put_u16(1900 + tm.tm_year, &value[0]); /* Year */
+	value[2] = tm.tm_mon + 1; /* Month */
+	value[3] = tm.tm_mday; /* Day */
+	value[4] = tm.tm_hour; /* Hours */
+	value[5] = tm.tm_min; /* Minutes */
+	value[6] = tm.tm_sec; /* Seconds */
+	value[7] = tm.tm_wday == 0 ? 7 : tm.tm_wday; /* Day of Week */
+	/* From Time Profile spec: "The number of 1/256 fractions of a second."
+	 * In 1s there are 256 fractions, in 1ns there are 256/10^9 fractions.
+	 * To avoid integer overflow, we use the equivalent 1/3906250 ratio. */
+	value[8] = tp.tv_nsec / 3906250; /* Fractions256 */
+	value[9] = 0x00; /* Adjust Reason */
+
+	attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
+
+	return 0;
+}
+
+static void register_current_time_service(void)
+{
+	/* Current Time service */
+	gatt_service_add(GATT_PRIM_SVC_UUID, CURRENT_TIME_SVC_UUID,
+				/* CT Time characteristic */
+				GATT_OPT_CHR_UUID, CT_TIME_CHR_UUID,
+				GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
+							ATT_CHAR_PROPER_NOTIFY,
+				GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+							current_time_read,
+				GATT_OPT_INVALID);
+}
+
 int time_server_init(void)
 {
+	register_current_time_service();
+
 	return 0;
 }
 
-- 
1.7.0.4


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

* [PATCH RFC BlueZ 2/4] GATT Time Server: add Reference Time Update service
  2011-09-26 21:01 [PATCH RFC BlueZ 0/4] Time GATT Profile (server) Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 1/4] GATT Time Server: add Current Time service Anderson Lizardo
@ 2011-09-26 21:01 ` Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 3/4] Time Server: Local Time Information characteristic Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 4/4] Time Server: use time zone and DST from system Anderson Lizardo
  3 siblings, 0 replies; 5+ messages in thread
From: Anderson Lizardo @ 2011-09-26 21:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 time/server.c |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/time/server.c b/time/server.c
index 5001874..fbe5b23 100644
--- a/time/server.c
+++ b/time/server.c
@@ -40,7 +40,10 @@
 
 /* UUIDs not yet approved by Bluetooth SIG */
 #define CURRENT_TIME_SVC_UUID		0x1805
+#define REF_TIME_UPDATE_SVC_UUID	0x1806
 
+#define TIME_UPDATE_CTRL_CHR_UUID	0x2A16
+#define TIME_UPDATE_STAT_CHR_UUID	0x2A17
 #define CT_TIME_CHR_UUID		0x2A2B
 
 static uint8_t current_time_read(struct attribute *a, gpointer user_data)
@@ -88,12 +91,54 @@ static void register_current_time_service(void)
 							ATT_CHAR_PROPER_NOTIFY,
 				GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
 							current_time_read,
+
+				GATT_OPT_INVALID);
+}
+
+static uint8_t time_update_control(struct attribute *a, gpointer user_data)
+{
+	DBG("handle 0x%04x", a->handle);
+
+	return 0;
+}
+
+static uint8_t time_update_status(struct attribute *a, gpointer user_data)
+{
+	uint8_t value[2];
+
+	DBG("handle 0x%04x", a->handle);
+
+	value[0] = 0x00; /* Current State: Idle */
+	value[1] = 0x00; /* Result: Successful */
+	attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
+
+	return 0;
+}
+
+static void register_reference_time_update_service(void)
+{
+	/* Reference Time Update service */
+	gatt_service_add(GATT_PRIM_SVC_UUID, REF_TIME_UPDATE_SVC_UUID,
+				/* Time Update control point */
+				GATT_OPT_CHR_UUID, TIME_UPDATE_CTRL_CHR_UUID,
+				GATT_OPT_CHR_PROPS,
+					ATT_CHAR_PROPER_WRITE_WITHOUT_RESP,
+				GATT_OPT_CHR_VALUE_CB, ATTRIB_WRITE,
+							time_update_control,
+
+				/* Time Update status */
+				GATT_OPT_CHR_UUID, TIME_UPDATE_STAT_CHR_UUID,
+				GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
+				GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+							time_update_status,
+
 				GATT_OPT_INVALID);
 }
 
 int time_server_init(void)
 {
 	register_current_time_service();
+	register_reference_time_update_service();
 
 	return 0;
 }
-- 
1.7.0.4


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

* [PATCH RFC BlueZ 3/4] Time Server: Local Time Information characteristic
  2011-09-26 21:01 [PATCH RFC BlueZ 0/4] Time GATT Profile (server) Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 1/4] GATT Time Server: add Current Time service Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 2/4] GATT Time Server: add Reference Time Update service Anderson Lizardo
@ 2011-09-26 21:01 ` Anderson Lizardo
  2011-09-26 21:01 ` [PATCH RFC BlueZ 4/4] Time Server: use time zone and DST from system Anderson Lizardo
  3 siblings, 0 replies; 5+ messages in thread
From: Anderson Lizardo @ 2011-09-26 21:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 time/server.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/time/server.c b/time/server.c
index fbe5b23..5079f35 100644
--- a/time/server.c
+++ b/time/server.c
@@ -42,6 +42,7 @@
 #define CURRENT_TIME_SVC_UUID		0x1805
 #define REF_TIME_UPDATE_SVC_UUID	0x1806
 
+#define LOCAL_TIME_INFO_CHR_UUID	0x2A0F
 #define TIME_UPDATE_CTRL_CHR_UUID	0x2A16
 #define TIME_UPDATE_STAT_CHR_UUID	0x2A17
 #define CT_TIME_CHR_UUID		0x2A2B
@@ -81,6 +82,19 @@ static uint8_t current_time_read(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
+static uint8_t local_time_info_read(struct attribute *a, gpointer user_data)
+{
+	uint8_t value[2];
+
+	DBG("a=%p", a);
+
+	value[0] = 0xff; /* DST Offset (255: unknown) */
+	value[1] = 0x80; /* Time Zone (-128: unknown) */
+	attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
+
+	return 0;
+}
+
 static void register_current_time_service(void)
 {
 	/* Current Time service */
@@ -92,6 +106,12 @@ static void register_current_time_service(void)
 				GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
 							current_time_read,
 
+				/* Local Time Information characteristic */
+				GATT_OPT_CHR_UUID, LOCAL_TIME_INFO_CHR_UUID,
+				GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
+				GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+							local_time_info_read,
+
 				GATT_OPT_INVALID);
 }
 
-- 
1.7.0.4


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

* [PATCH RFC BlueZ 4/4] Time Server: use time zone and DST from system
  2011-09-26 21:01 [PATCH RFC BlueZ 0/4] Time GATT Profile (server) Anderson Lizardo
                   ` (2 preceding siblings ...)
  2011-09-26 21:01 ` [PATCH RFC BlueZ 3/4] Time Server: Local Time Information characteristic Anderson Lizardo
@ 2011-09-26 21:01 ` Anderson Lizardo
  3 siblings, 0 replies; 5+ messages in thread
From: Anderson Lizardo @ 2011-09-26 21:01 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 time/server.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/time/server.c b/time/server.c
index 5079f35..1f624a6 100644
--- a/time/server.c
+++ b/time/server.c
@@ -88,8 +88,16 @@ static uint8_t local_time_info_read(struct attribute *a, gpointer user_data)
 
 	DBG("a=%p", a);
 
-	value[0] = 0xff; /* DST Offset (255: unknown) */
-	value[1] = 0x80; /* Time Zone (-128: unknown) */
+	tzset();
+
+	/* FIXME: POSIX "daylight" variable only indicates whether there is DST
+	 * for the local time or not. The offset is unknown. */
+	value[0] = daylight ? 0xff : 0x00;
+
+	/* Convert POSIX "timezone" (seconds West of GMT) to Time Profile
+	 * format (offset from UTC in number of 15 minutes increments). */
+	value[1] = (uint8_t) (-1 * timezone / (60 * 15));
+
 	attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
 
 	return 0;
-- 
1.7.0.4


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

end of thread, other threads:[~2011-09-26 21:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-26 21:01 [PATCH RFC BlueZ 0/4] Time GATT Profile (server) Anderson Lizardo
2011-09-26 21:01 ` [PATCH RFC BlueZ 1/4] GATT Time Server: add Current Time service Anderson Lizardo
2011-09-26 21:01 ` [PATCH RFC BlueZ 2/4] GATT Time Server: add Reference Time Update service Anderson Lizardo
2011-09-26 21:01 ` [PATCH RFC BlueZ 3/4] Time Server: Local Time Information characteristic Anderson Lizardo
2011-09-26 21:01 ` [PATCH RFC BlueZ 4/4] Time Server: use time zone and DST from system Anderson Lizardo

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.