Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 4/8] obexd/client: Add DatabaseIdentifier property
Date: Mon,  1 Dec 2014 10:47:14 +0200	[thread overview]
Message-ID: <1417423638-29222-4-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1417423638-29222-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds DatabaseIdentifier property to PhonebookAccess interface.
---
 doc/obex-api.txt    |  4 ++-
 obexd/client/pbap.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/doc/obex-api.txt b/doc/obex-api.txt
index 349fe4c..ea82e39 100644
--- a/doc/obex-api.txt
+++ b/doc/obex-api.txt
@@ -500,8 +500,10 @@ Properties	string Folder [readonly]
 
 		string DatabaseIdentifier [readonly, optional]
 
-			128 bits persistent identifier.
+			128 bits persistent database identifier.
 
+			Possible values: 32-character hexadecimal such
+			as A1A2A3A4B1B2C1C2D1D2E1E2E3E4E5E6
 
 Synchronization hierarchy
 =========================
diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c
index 57f58ee..97c7cb9 100644
--- a/obexd/client/pbap.c
+++ b/obexd/client/pbap.c
@@ -73,6 +73,7 @@
 #define FORMAT_TAG		0X07
 #define PHONEBOOKSIZE_TAG	0X08
 #define NEWMISSEDCALLS_TAG	0X09
+#define DATABASEID_TAG		0X0D
 
 #define DOWNLOAD_FEATURE	0x00000001
 #define BROWSE_FEATURE		0x00000002
@@ -133,6 +134,7 @@ struct pbap_data {
 	char *path;
 	uint16_t version;
 	uint32_t supported_features;
+	uint8_t databaseid[16];
 };
 
 struct pending_request {
@@ -272,8 +274,33 @@ static void pbap_setpath_cb(struct obc_session *session,
 	pending_request_free(request);
 }
 
+static void read_databaseid(struct pbap_data *pbap, GObexApparam *apparam)
+{
+	const guint8 *data;
+	guint8 value[16];
+	gsize len;
+
+	if (!(pbap->supported_features & DATABASEID_FEATURE))
+		return;
+
+	if (!g_obex_apparam_get_bytes(apparam, DATABASEID_TAG, &data, &len)) {
+		len = sizeof(value);
+		memset(value, 0, len);
+		data = value;
+	}
+
+	if (memcmp(data, pbap->databaseid, len)) {
+		memcpy(pbap->databaseid, data, len);
+		g_dbus_emit_property_changed(conn,
+					obc_session_get_path(pbap->session),
+					PBAP_INTERFACE, "DatabaseIdentifier");
+	}
+}
+
 static void read_return_apparam(struct obc_transfer *transfer,
-				guint16 *phone_book_size, guint8 *new_missed_calls)
+					struct pbap_data *pbap,
+					guint16 *phone_book_size,
+					guint8 *new_missed_calls)
 {
 	GObexApparam *apparam;
 
@@ -288,6 +315,8 @@ static void read_return_apparam(struct obc_transfer *transfer,
 							phone_book_size);
 	g_obex_apparam_get_uint8(apparam, NEWMISSEDCALLS_TAG,
 							new_missed_calls);
+
+	read_databaseid(pbap, apparam);
 }
 
 static void phonebook_size_callback(struct obc_session *session,
@@ -308,7 +337,8 @@ static void phonebook_size_callback(struct obc_session *session,
 
 	reply = dbus_message_new_method_return(request->msg);
 
-	read_return_apparam(transfer, &phone_book_size, &new_missed_calls);
+	read_return_apparam(transfer, request->pbap, &phone_book_size,
+							&new_missed_calls);
 
 	dbus_message_append_args(reply,
 			DBUS_TYPE_UINT16, &phone_book_size,
@@ -995,8 +1025,45 @@ static gboolean get_folder(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean databaseid_exists(const GDBusPropertyTable *property,
+								void *data)
+{
+	struct pbap_data *pbap = data;
+
+	return pbap->supported_features & DATABASEID_FEATURE;
+}
+
+static int u128_to_string(uint8_t *data, char *str, size_t len)
+{
+	return snprintf(str, len, "%02X%02X%02X%02X%02X%02X%02X%02X"
+					"%02X%02X%02X%02X%02X%02X%02X%02X",
+					data[0], data[1], data[2], data[3],
+					data[3], data[5], data[6], data[7],
+					data[8], data[9], data[10], data[11],
+					data[12], data[13], data[14], data[15]);
+}
+
+static gboolean get_databaseid(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct pbap_data *pbap = data;
+	char value[33];
+	const char *pvalue = value;
+
+	if (!pbap->databaseid)
+		return FALSE;
+
+	if (u128_to_string(pbap->databaseid, value, sizeof(value)) < 0)
+		return FALSE;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &pvalue);
+
+	return TRUE;
+}
+
 static const GDBusPropertyTable pbap_properties[] = {
 	{ "Folder", "s", get_folder, NULL, folder_exists },
+	{ "DatabaseIdentifier", "s", get_databaseid, NULL, databaseid_exists },
 	{ }
 };
 
-- 
1.9.3


  parent reply	other threads:[~2014-12-01  8:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01  8:47 [PATCH BlueZ 1/8] obexd/client: Add support for reading version Luiz Augusto von Dentz
2014-12-01  8:47 ` [PATCH BlueZ 2/8] obexd/client: Parse PBAP record Luiz Augusto von Dentz
2014-12-01  8:47 ` [PATCH BlueZ 3/8] obexd/client: Add Folder property Luiz Augusto von Dentz
2014-12-01  8:47 ` Luiz Augusto von Dentz [this message]
2014-12-01  8:47 ` [PATCH BlueZ 5/8] obexd/client: Add folder counters properties Luiz Augusto von Dentz
2014-12-01  8:47 ` [PATCH BlueZ 6/8] obexd/client: Add FixedImageSize property Luiz Augusto von Dentz
2014-12-01  8:47 ` [PATCH BlueZ 7/8] obexd/client: Add UpdateVersion to PhonebookAccess Luiz Augusto von Dentz
2014-12-01  8:47 ` [PATCH BlueZ 8/8] obexd/client: Add supported_features support Luiz Augusto von Dentz
2014-12-01 12:17   ` Gowtham Anandha Babu
2014-12-01 12:51     ` Luiz Augusto von Dentz
2014-12-01 13:31       ` Gowtham Anandha Babu
2014-12-01 13:34         ` Luiz Augusto von Dentz
2014-12-01 14:00           ` Luiz Augusto von Dentz
     [not found]             ` <003c01d00d71$f818ba20$e84a2e60$@samsung.com>
2014-12-01 14:41               ` Luiz Augusto von Dentz
2014-12-02  6:37                 ` Gowtham Anandha Babu
2014-12-02  9:32                   ` Luiz Augusto von Dentz
2014-12-02  9:39 ` [PATCH BlueZ 1/8] obexd/client: Add support for reading version Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417423638-29222-4-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox