Linux bluetooth development
 help / color / mirror / Atom feed
From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Andre Dieb Martins <andre.dieb@signove.com>
Subject: [PATCHv2 3/5] Check permissions before setting client configs
Date: Tue, 22 Feb 2011 18:01:29 -0300	[thread overview]
Message-ID: <1298408491-11154-3-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1298323843-31106-1-git-send-email-anderson.lizardo@openbossa.org>

From: Andre Dieb Martins <andre.dieb@signove.com>

Only enable notification/indication if the descriptor allows it.
---
 src/attrib-server.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 8c74a5b..aa24985 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -199,19 +199,21 @@ static uint8_t client_set_notifications(struct attribute *attr,
 	struct gatt_channel *channel = user_data;
 	struct attribute *a, *last_chr_val = NULL;
 	uint16_t handle, cfg_val;
+	uint8_t perm;
 	uuid_t uuid;
 	GSList *l;
 
 	cfg_val = att_get_u16(attr->data);
 
 	sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
-	for (l = database, handle = 0; l != NULL; l = l->next) {
+	for (l = database, handle = 0, perm = 0; l != NULL; l = l->next) {
 		a = l->data;
 
 		if (a->handle >= attr->handle)
 			break;
 
 		if (sdp_uuid_cmp(&a->uuid, &uuid) == 0) {
+			perm = att_get_u8(&a->data[0]);
 			handle = att_get_u16(&a->data[1]);
 			continue;
 		}
@@ -223,8 +225,11 @@ static uint8_t client_set_notifications(struct attribute *attr,
 	if (last_chr_val == NULL)
 		return 0;
 
-	/* FIXME: Characteristic properties shall be checked for
-	 * Notification/Indication permissions. */
+	if ((cfg_val & 0x0001) && !(perm & ATT_CHAR_PROPER_NOTIFY))
+		return ATT_ECODE_WRITE_NOT_PERM;
+
+	if ((cfg_val & 0x0002) && !(perm & ATT_CHAR_PROPER_INDICATE))
+		return ATT_ECODE_WRITE_NOT_PERM;
 
 	if (cfg_val & 0x0001)
 		channel->notify = g_slist_append(channel->notify, last_chr_val);
-- 
1.7.0.4


  parent reply	other threads:[~2011-02-22 21:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 21:30 [PATCH 1/5] Add read/write callbacks to attribute server Anderson Lizardo
2011-02-21 21:30 ` [PATCH 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-21 21:30 ` [PATCH 3/5] Check permissions before setting client configs Anderson Lizardo
2011-02-21 21:30 ` [PATCH 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-21 21:30 ` [PATCH 5/5] Implement ATT handle indication Anderson Lizardo
2011-02-22 21:01 ` [PATCHv2 1/5] Add read/write callbacks to attribute server Anderson Lizardo
2011-02-23  3:21   ` Johan Hedberg
2011-02-23 14:28     ` Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 " Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 3/5] Check properties before setting client configs Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 5/5] Implement ATT handle indication Anderson Lizardo
2011-02-24 19:10     ` Johan Hedberg
2011-02-22 21:01 ` [PATCHv2 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-23  3:26   ` Johan Hedberg
2011-02-23 14:29     ` Anderson Lizardo
2011-03-07 20:52     ` Peter Dons Tychsen
2011-02-22 21:01 ` Anderson Lizardo [this message]
2011-02-22 21:01 ` [PATCHv2 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-22 21:01 ` [PATCHv2 5/5] Implement ATT handle indication Anderson Lizardo

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=1298408491-11154-3-git-send-email-anderson.lizardo@openbossa.org \
    --to=anderson.lizardo@openbossa.org \
    --cc=andre.dieb@signove.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