linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Santiago Carot-Nemesio <sancane@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Santiago Carot-Nemesio <sancane@gmail.com>
Subject: [PATCH 1/4] attrib-server: Move GAP attributes inside gatt_server struct
Date: Fri, 30 Dec 2011 12:45:06 +0100	[thread overview]
Message-ID: <1325245509-14359-1-git-send-email-sancane@gmail.com> (raw)

---
 src/attrib-server.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 623c91a..36a398f 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -62,6 +62,8 @@ struct gatt_server {
 	uint32_t gap_sdp_handle;
 	GSList *database;
 	GSList *clients;
+	uint16_t name_handle;
+	uint16_t appearance_handle;
 };
 
 struct gatt_channel {
@@ -82,10 +84,6 @@ struct group_elem {
 	uint16_t len;
 };
 
-/* GAP attribute handles */
-static uint16_t name_handle = 0x0000;
-static uint16_t appearance_handle = 0x0000;
-
 static bt_uuid_t prim_uuid = {
 			.type = BT_UUID16,
 			.value.u16 = GATT_PRIM_SVC_UUID
@@ -1138,24 +1136,24 @@ static gboolean register_core_services(struct gatt_server *server)
 								atval, 2);
 
 	/* GAP service: device name characteristic */
-	name_handle = 0x0006;
+	server->name_handle = 0x0006;
 	bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
 	atval[0] = ATT_CHAR_PROPER_READ;
-	att_put_u16(name_handle, &atval[1]);
+	att_put_u16(server->name_handle, &atval[1]);
 	att_put_u16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
 	attrib_db_add_new(server, 0x0004, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
 								atval, 5);
 
 	/* GAP service: device name attribute */
 	bt_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
-	attrib_db_add_new(server, name_handle, &uuid, ATT_NONE,
+	attrib_db_add_new(server, server->name_handle, &uuid, ATT_NONE,
 						ATT_NOT_PERMITTED, NULL, 0);
 
 	/* GAP service: device appearance characteristic */
-	appearance_handle = 0x0008;
+	server->appearance_handle = 0x0008;
 	bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
 	atval[0] = ATT_CHAR_PROPER_READ;
-	att_put_u16(appearance_handle, &atval[1]);
+	att_put_u16(server->appearance_handle, &atval[1]);
 	att_put_u16(GATT_CHARAC_APPEARANCE, &atval[3]);
 	attrib_db_add_new(server, 0x0007, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
 								atval, 5);
@@ -1163,7 +1161,7 @@ static gboolean register_core_services(struct gatt_server *server)
 	/* GAP service: device appearance attribute */
 	bt_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
 	att_put_u16(appearance, &atval[0]);
-	attrib_db_add_new(server, appearance_handle, &uuid, ATT_NONE,
+	attrib_db_add_new(server, server->appearance_handle, &uuid, ATT_NONE,
 						ATT_NOT_PERMITTED, atval, 2);
 	server->gap_sdp_handle = attrib_create_sdp_new(server, 0x0001,
 						"Generic Access Profile");
@@ -1392,16 +1390,24 @@ int attrib_db_del(struct btd_adapter *adapter, uint16_t handle)
 int attrib_gap_set(struct btd_adapter *adapter, uint16_t uuid,
 						const uint8_t *value, int len)
 {
+	struct gatt_server *server;
 	uint16_t handle;
+	GSList *l;
+
+	l = g_slist_find_custom(servers, adapter, adapter_cmp);
+	if (l == NULL)
+		return -ENOENT;
+
+	server = l->data;
 
 	/* FIXME: Missing Privacy and Reconnection Address */
 
 	switch (uuid) {
 	case GATT_CHARAC_DEVICE_NAME:
-		handle = name_handle;
+		handle = server->name_handle;
 		break;
 	case GATT_CHARAC_APPEARANCE:
-		handle = appearance_handle;
+		handle = server->appearance_handle;
 		break;
 	default:
 		return -ENOSYS;
-- 
1.7.8.1


             reply	other threads:[~2011-12-30 11:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-30 11:45 Santiago Carot-Nemesio [this message]
2011-12-30 11:45 ` [PATCH 2/4] gatt-service: Delete attributes when service registration fails Santiago Carot-Nemesio
2011-12-30 11:45   ` [PATCH 3/4] gatt-service: Add missing user_data parameter for callbacks Santiago Carot-Nemesio
2011-12-30 11:45     ` [PATCH 4/4] gatt-example: Fix memory leak Santiago Carot-Nemesio
2012-01-09 12:29 ` [PATCH 1/4] attrib-server: Move GAP attributes inside gatt_server struct Johan Hedberg

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=1325245509-14359-1-git-send-email-sancane@gmail.com \
    --to=sancane@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;
as well as URLs for NNTP newsgroup(s).