All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ v1 05/14] core: gatt: Add GATT/GAP services to local db
Date: Wed, 11 Feb 2015 19:17:35 -0800	[thread overview]
Message-ID: <1423711064-7390-6-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1423711064-7390-1-git-send-email-armansito@chromium.org>

This patch adds the GATT & GAP services to the local GATT database.
---
 src/gatt-database.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 113 insertions(+), 1 deletion(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 57bdf1a..2da5a09 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -39,6 +39,9 @@
 #define ATT_CID 4
 #endif
 
+#define UUID_GAP	0x1800
+#define UUID_GATT	0x1801
+
 static struct queue *servers = NULL;
 
 struct btd_gatt_database {
@@ -126,6 +129,115 @@ static bool match_adapter(const void *a, const void *b)
 	return server->adapter == adapter;
 }
 
+static void gap_device_name_read_cb(struct gatt_db_attribute *attrib,
+					unsigned int id, uint16_t offset,
+					uint8_t opcode, struct bt_att *att,
+					void *user_data)
+{
+	struct btd_gatt_database *server = user_data;
+	uint8_t error = 0;
+	size_t len = 0;
+	const uint8_t *value = NULL;
+	const char *device_name;
+
+	DBG("GAP Device Name read request\n");
+
+	device_name = btd_adapter_get_name(server->adapter);
+	len = strlen(device_name);
+
+	if (offset > len) {
+		error = BT_ATT_ERROR_INVALID_OFFSET;
+		goto done;
+	}
+
+	len -= offset;
+	value = len ? (const uint8_t *) &device_name[offset] : NULL;
+
+done:
+	gatt_db_attribute_read_result(attrib, id, error, value, len);
+}
+
+static void gap_appearance_read_cb(struct gatt_db_attribute *attrib,
+					unsigned int id, uint16_t offset,
+					uint8_t opcode, struct bt_att *att,
+					void *user_data)
+{
+	struct btd_gatt_database *server = user_data;
+	uint8_t error = 0;
+	size_t len = 2;
+	const uint8_t *value = NULL;
+	uint8_t appearance[2];
+	uint32_t dev_class;
+
+	DBG("GAP Appearance read request\n");
+
+	dev_class = btd_adapter_get_class(server->adapter);
+
+	if (offset > 2) {
+		error = BT_ATT_ERROR_INVALID_OFFSET;
+		goto done;
+	}
+
+	appearance[0] = dev_class & 0x00ff;
+	appearance[1] = (dev_class >> 8) & 0x001f;
+
+	len -= offset;
+	value = len ? &appearance[offset] : NULL;
+
+done:
+	gatt_db_attribute_read_result(attrib, id, error, value, len);
+}
+
+static void populate_gap_service(struct btd_gatt_database *server)
+{
+	bt_uuid_t uuid;
+	struct gatt_db_attribute *service;
+
+	/* Add the GAP service */
+	bt_uuid16_create(&uuid, UUID_GAP);
+	service = gatt_db_add_service(server->db, &uuid, true, 5);
+
+	/*
+	 * Device Name characteristic.
+	 */
+	bt_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
+	gatt_db_service_add_characteristic(service, &uuid, BT_ATT_PERM_READ,
+							BT_GATT_CHRC_PROP_READ,
+							gap_device_name_read_cb,
+							NULL, server);
+
+	/*
+	 * Device Appearance characteristic.
+	 */
+	bt_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
+	gatt_db_service_add_characteristic(service, &uuid, BT_ATT_PERM_READ,
+							BT_GATT_CHRC_PROP_READ,
+							gap_appearance_read_cb,
+							NULL, server);
+
+	gatt_db_service_set_active(service, true);
+}
+
+static void populate_gatt_service(struct btd_gatt_database *server)
+{
+	bt_uuid_t uuid;
+	struct gatt_db_attribute *service;
+
+	/* Add the GATT service */
+	bt_uuid16_create(&uuid, UUID_GATT);
+	service = gatt_db_add_service(server->db, &uuid, true, 1);
+
+	/* TODO: Add "Service Changed" characteristic and handle CCC */
+
+	gatt_db_service_set_active(service, true);
+}
+
+static void register_core_services(struct btd_gatt_database *server)
+{
+	populate_gap_service(server);
+	populate_gatt_service(server);
+}
+
 bool btd_gatt_database_register_adapter(struct btd_adapter *adapter)
 {
 	struct btd_gatt_database *server;
@@ -169,7 +281,7 @@ bool btd_gatt_database_register_adapter(struct btd_adapter *adapter)
 
 	queue_push_tail(servers, server);
 
-	/* TODO: Set up GAP/GATT services */
+	register_core_services(server);
 
 	return true;
 
-- 
2.2.0.rc0.207.ga3a616c


  parent reply	other threads:[~2015-02-12  3:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12  3:17 [PATCH BlueZ v1 00/14] Rewrite local GATT server using shared/gatt Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 01/14] shared/att: Add bt_att_get_fd Arman Uguray
2015-02-12 13:40   ` Luiz Augusto von Dentz
2015-02-12 18:21     ` Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 02/14] shared/gatt: Pass bt_att instead of bdaddr_t Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 03/14] core: Introduce btd_gatt_database Arman Uguray
2015-02-13 16:06   ` Luiz Augusto von Dentz
2015-02-13 16:21     ` Arman Uguray
2015-02-17 12:03       ` Luiz Augusto von Dentz
2015-02-18  0:43         ` Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 04/14] core: Attach gatt-server to bt_att Arman Uguray
2015-02-12  3:17 ` Arman Uguray [this message]
2015-02-12  3:17 ` [PATCH BlueZ v1 06/14] core: Add GATT UUIDs to Adapter1.UUIDs Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 07/14] core: Support per-client CCC state Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 08/14] core: Setup added/removed handlers in GATT database Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 09/14] core: Add Service Changed characteristic Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 10/14] core: device: Add getter for GATT server Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 11/14] core: gatt-server: Send "Service Changed" Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 12/14] core: adapter: Send UUIDs changed for GATT services Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 13/14] shared/gatt: Don't incorrectly terminate discovery Arman Uguray
2015-02-12  3:17 ` [PATCH BlueZ v1 14/14] TODO: Update GATT items Arman Uguray
2015-02-16  9:13 ` [PATCH BlueZ v1 00/14] Rewrite local GATT server using shared/gatt 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=1423711064-7390-6-git-send-email-armansito@chromium.org \
    --to=armansito@chromium.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /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.