All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC 2/2] client: Add authorized property handling to characteristic attribute
Date: Wed,  2 May 2018 11:17:57 +0200	[thread overview]
Message-ID: <20180502091757.24190-3-grzegorz.kolodziejczyk@codecoup.pl> (raw)
In-Reply-To: <20180502091757.24190-1-grzegorz.kolodziejczyk@codecoup.pl>

This patch adds handling of authorized property to bluetoothctl.
---
 client/gatt.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/client/gatt.c b/client/gatt.c
index 6bf644c48..fffa86851 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -1432,6 +1432,30 @@ static gboolean chrc_notify_acquired_exists(const GDBusPropertyTable *property,
 	return FALSE;
 }
 
+static gboolean chrc_get_authorized(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct chrc *chrc = data;
+	dbus_bool_t value;
+
+	value = chrc->authorized ? TRUE : FALSE;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
+
+	return TRUE;
+}
+
+static gboolean chrc_get_authorized_exists(const GDBusPropertyTable *property,
+								void *data)
+{
+	struct chrc *chrc = data;
+
+	if (chrc->authorization_req)
+		return TRUE;
+
+	return FALSE;
+}
+
 static const GDBusPropertyTable chrc_properties[] = {
 	{ "UUID", "s", chrc_get_uuid, NULL, NULL },
 	{ "Service", "o", chrc_get_service, NULL, NULL },
@@ -1442,6 +1466,8 @@ static const GDBusPropertyTable chrc_properties[] = {
 					chrc_write_acquired_exists },
 	{ "NotifyAcquired", "b", chrc_get_notify_acquired, NULL,
 					chrc_notify_acquired_exists },
+	{ "Authorized", "b", chrc_get_authorized, NULL,
+						chrc_get_authorized_exists },
 	{ }
 };
 
@@ -1665,6 +1691,15 @@ static void authorize_write_response(const char *input, void *user_data)
 
 	chrc->authorized = true;
 
+	/* Authorization check of prepare writes */
+	if (!chrc->value_len) {
+		reply = g_dbus_create_reply(pending_message, DBUS_TYPE_INVALID);
+		g_dbus_send_message(aad->conn, reply);
+		g_free(aad);
+
+		return;
+	}
+
 	errsv = parse_value_arg(&iter, &chrc->value, &chrc->value_len,
 							chrc->max_val_len);
 	if (errsv == -EINVAL) {
@@ -1701,8 +1736,16 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
 	DBusMessageIter iter;
 	char *str;
 	int errsv;
+	uint16_t offset = 0;
 
 	dbus_message_iter_init(msg, &iter);
+	/* Get offset only (second parameter) */
+	dbus_message_iter_next(&iter);
+
+	parse_options(&iter, &offset, NULL, NULL, NULL);
+
+	if (chrc->authorization_req && offset == 0)
+		chrc->authorized = false;
 
 	if (chrc->authorization_req && !chrc->authorized) {
 		struct authorize_attribute_data *aad;
@@ -1722,6 +1765,9 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
 		return NULL;
 	}
 
+	/* Rewind to value parameter */
+	dbus_message_iter_init(msg, &iter);
+
 	errsv = parse_value_arg(&iter, &chrc->value, &chrc->value_len,
 							chrc->max_val_len);
 	if (errsv == -EINVAL) {
-- 
2.13.6


  parent reply	other threads:[~2018-05-02  9:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02  9:17 [RFC 0/2] Add support for prepare writes authorization Grzegorz Kolodziejczyk
2018-05-02  9:17 ` [RFC 1/2] shared/gatt-server: Request authorization for prepare writes Grzegorz Kolodziejczyk
2018-05-02 11:32   ` Luiz Augusto von Dentz
2018-05-02 13:31     ` Grzegorz Kołodziejczyk
2018-05-03  9:54       ` Luiz Augusto von Dentz
2018-05-02  9:17 ` Grzegorz Kolodziejczyk [this message]
2018-05-02 10:42   ` [RFC 2/2] client: Add authorized property handling to characteristic attribute Luiz Augusto von Dentz
2018-05-02 13:06     ` Grzegorz Kołodziejczyk
2018-05-03  9:58       ` Luiz Augusto von Dentz
2018-05-04 14:03         ` Grzegorz Kołodziejczyk

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=20180502091757.24190-3-grzegorz.kolodziejczyk@codecoup.pl \
    --to=grzegorz.kolodziejczyk@codecoup.pl \
    --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 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.