From: Santiago Carot-Nemesio <sancane@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Santiago Carot-Nemesio <sancane@gmail.com>
Subject: [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs
Date: Wed, 25 Jan 2012 14:12:34 +0100 [thread overview]
Message-ID: <1327497161-14764-2-git-send-email-sancane@gmail.com> (raw)
In-Reply-To: <1327497161-14764-1-git-send-email-sancane@gmail.com>
UUID services in GATT should be either 16-bit or 128-bit. Current
GATT interface does not allow to provide 128-bit ones. This patch
enables plugins to register services using 128-bit UUIDs.
---
attrib/gatt-service.c | 57 ++++++++++++++++++++++++++++++++++-------------
attrib/gatt-service.h | 2 +-
plugins/gatt-example.c | 7 ++++-
time/server.c | 6 ++++-
4 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index bfefdee..187ef5a 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -116,6 +116,28 @@ static GSList *parse_opts(gatt_option opt1, va_list args)
return l;
}
+static struct attribute *add_service_declaration(struct btd_adapter *adapter,
+ uint16_t handle, uint16_t svc, bt_uuid_t *uuid)
+{
+ bt_uuid_t bt_uuid;
+ uint8_t atval[16];
+ int len;
+
+ if (uuid->type == BT_UUID16) {
+ att_put_u16(uuid->value.u16, &atval[0]);
+ len = 2;
+ } else if (uuid->type == BT_UUID128) {
+ att_put_u128(uuid->value.u128, &atval[0]);
+ len = 16;
+ } else
+ return NULL;
+
+ bt_uuid16_create(&bt_uuid, svc);
+
+ return attrib_db_add(adapter, handle, &bt_uuid, ATT_NONE,
+ ATT_NOT_PERMITTED, atval, len);
+}
+
static int att_read_reqs(int authorization, int authentication, uint8_t props)
{
if (authorization == GATT_CHR_VALUE_READ ||
@@ -268,15 +290,21 @@ static void service_attr_del(struct btd_adapter *adapter, uint16_t start_handle,
}
gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
- uint16_t svc_uuid, gatt_option opt1, ...)
+ bt_uuid_t *svc_uuid, gatt_option opt1, ...)
{
+ char uuidstr[MAX_LEN_UUID_STR];
uint16_t start_handle, h;
unsigned int size;
- bt_uuid_t bt_uuid;
- uint8_t atval[2];
va_list args;
GSList *chrs, *l;
+ bt_uuid_to_string(svc_uuid, uuidstr, MAX_LEN_UUID_STR);
+
+ if (svc_uuid->type != BT_UUID16 && svc_uuid->type != BT_UUID128) {
+ error("Invalid service uuid: %s", uuidstr);
+ return FALSE;
+ }
+
va_start(args, opt1);
chrs = parse_opts(opt1, args);
/* calculate how many attributes are necessary for this service */
@@ -288,31 +316,24 @@ gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
start_handle = attrib_db_find_avail(adapter, size);
if (start_handle == 0) {
error("Not enough free handles to register service");
- g_slist_free_full(chrs, free_gatt_info);
- return FALSE;
+ goto fail;
}
- DBG("New service: handle 0x%04x, UUID 0x%04x, %d attributes",
- start_handle, svc_uuid, size);
+ DBG("New service: handle 0x%04x, UUID %s, %d attributes",
+ start_handle, uuidstr, size);
/* service declaration */
h = start_handle;
- bt_uuid16_create(&bt_uuid, uuid);
- att_put_u16(svc_uuid, &atval[0]);
- if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
- atval, sizeof(atval)) == NULL) {
- g_slist_free_full(chrs, free_gatt_info);
- return FALSE;
- }
+ if (add_service_declaration(adapter, h++, uuid, svc_uuid) == NULL)
+ goto fail;
for (l = chrs; l != NULL; l = l->next) {
struct gatt_info *info = l->data;
DBG("New characteristic: handle 0x%04x", h);
if (!add_characteristic(adapter, &h, info)) {
- g_slist_free_full(chrs, free_gatt_info);
service_attr_del(adapter, start_handle, h - 1);
- return FALSE;
+ goto fail;
}
}
@@ -321,4 +342,8 @@ gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
g_slist_free_full(chrs, free_gatt_info);
return TRUE;
+
+fail:
+ g_slist_free_full(chrs, free_gatt_info);
+ return FALSE;
}
diff --git a/attrib/gatt-service.h b/attrib/gatt-service.h
index 7af2d3e..b810e2e 100644
--- a/attrib/gatt-service.h
+++ b/attrib/gatt-service.h
@@ -48,4 +48,4 @@ typedef enum {
} attrib_event_t;
gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
- uint16_t svc_uuid, gatt_option opt1, ...);
+ bt_uuid_t *svc_uuid, gatt_option opt1, ...);
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index 701c1d7..e791c53 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -105,8 +105,11 @@ static uint8_t battery_state_read(struct attribute *a, gpointer user_data)
static gboolean register_battery_service(struct btd_adapter *adapter)
{
- return gatt_service_add(adapter, GATT_PRIM_SVC_UUID,
- BATTERY_STATE_SVC_UUID,
+ bt_uuid_t uuid;
+
+ bt_uuid16_create(&uuid, BATTERY_STATE_SVC_UUID);
+
+ return gatt_service_add(adapter, GATT_PRIM_SVC_UUID, &uuid,
/* battery state characteristic */
GATT_OPT_CHR_UUID, BATTERY_STATE_UUID,
GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
diff --git a/time/server.c b/time/server.c
index 0730fbb..42b12e2 100644
--- a/time/server.c
+++ b/time/server.c
@@ -115,9 +115,13 @@ static uint8_t local_time_info_read(struct attribute *a, gpointer user_data)
static void register_current_time_service(void)
{
+ bt_uuid_t uuid;
+
+ bt_uuid16_create(&uuid, CURRENT_TIME_SVC_UUID);
+
/* Current Time service */
/* FIXME: Provide the adapter in next function */
- gatt_service_add(NULL, GATT_PRIM_SVC_UUID, CURRENT_TIME_SVC_UUID,
+ gatt_service_add(NULL, GATT_PRIM_SVC_UUID, &uuid,
/* CT Time characteristic */
GATT_OPT_CHR_UUID, CT_TIME_CHR_UUID,
GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
--
1.7.8.4
next prev parent reply other threads:[~2012-01-25 13:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-25 13:12 GATT improvements v3 Santiago Carot-Nemesio
2012-01-25 13:12 ` Santiago Carot-Nemesio [this message]
2012-01-25 13:12 ` [PATCH 2/8] gatt-service: Move va_end just after processing the argument list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 3/8] gatt-service: Provide service uuid in attrib_db_find_avail function Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 4/8] attrib-server: Allocate 16-bits UUIDS at the begining of the list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 5/8] attrib-server: Set database uuids as a double linked list Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 6/8] glib-compat: Add g_list_free_full to deal with issues in old GLib versions Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 7/8] attrib-server: Allocate 128-bits UUIDs using highest available handlers Santiago Carot-Nemesio
2012-01-25 13:12 ` [PATCH 8/8] gatt-example: Fix g_assert checks when an uint16_t value overflows Santiago Carot-Nemesio
2012-02-03 8:37 ` GATT improvements v3 Santiago Carot
2012-02-03 18:48 ` Johan Hedberg
-- strict thread matches above, loose matches on Subject: below --
2012-01-25 10:03 GATT improvements v2 Santiago Carot-Nemesio
2012-01-25 10:03 ` [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs Santiago Carot-Nemesio
2012-01-24 11:06 GATT service improvements Santiago Carot-Nemesio
2012-01-24 11:06 ` [PATCH 1/8] gatt-service: Add support for 128-bit Bluetooth UUIDs Santiago Carot-Nemesio
2012-01-24 12:03 ` 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=1327497161-14764-2-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).