2011-12-27 09:29:34

by Santiago Carot

[permalink] [raw]
Subject: Multi-adapter GATT server support

These set of patches completes multi-adapter GATT server support.
They depend on the latest patches sent on December the 20th.
These patches change the gatt server interface to provide a new
paramenter that is the adapter in which the operation takes place.

The only pending task after applying these pacthes is to refactor
the code for GATT server plugins in order to register their attributes
whenever an adapter is plugged instead of doing that when the plugin
is loaded.

Plugins what will need a refactorization after this set of patches are
time and proximity. Example plugin is already fixed.

[PATCH 1/8] attrib-server: Add blutooth adapter to
[PATCH 2/8] attrib-server: Add bluetooth adapter in attrib_db_add
[PATCH 3/8] gatt-service: Add bluetooth adapter in gatt_service_add
[PATCH 4/8] attrib-server: Add bluetooth adapter in attrib_db_update
[PATCH 5/8] attrib-server: Add bluetooth adapter in attrib_gap_set
[PATCH 6/8] attrib-server: Add bluetooth adapter in attrib_db_del
[PATCH 7/8] attrib-server: Add bluetooth adapter in
[PATCH 8/8] attrib-server: Add Gattrib in attrib_channel_detach


2011-12-27 14:46:56

by Santiago Carot

[permalink] [raw]
Subject: Re: Multi-adapter GATT server support

Hi

2011/12/27 Santiago Carot-Nemesio <[email protected]>:
> These set of patches completes multi-adapter GATT server support.
> They depend on the latest patches sent on December the 20th.
> These patches change the gatt server interface to provide a new
> paramenter that is the adapter in which the operation takes place.
>
> The only pending task after applying these pacthes is to refactor
> the code for GATT server plugins in order to register their attributes
> whenever an adapter is plugged instead of doing that when the plugin
> is loaded.
>
> Plugins what will need a refactorization after this set of patches are
> time and proximity. Example plugin is already fixed.
>
> [PATCH 1/8] attrib-server: Add blutooth adapter to
> [PATCH 2/8] attrib-server: Add bluetooth adapter in attrib_db_add
> [PATCH 3/8] gatt-service: Add bluetooth adapter in gatt_service_add
> [PATCH 4/8] attrib-server: Add bluetooth adapter in attrib_db_update
> [PATCH 5/8] attrib-server: Add bluetooth adapter in attrib_gap_set
> [PATCH 6/8] attrib-server: Add bluetooth adapter in attrib_db_del
> [PATCH 7/8] attrib-server: Add bluetooth adapter in
> [PATCH 8/8] attrib-server: Add Gattrib in attrib_channel_detach

Please, ignore this set of patches because it requires some
modifications after making the changes suggested for the patches wich
this set depends on, so they will result in conflicts when applying.

I'll send another set fixing this issue.
Regards.

2011-12-27 09:29:41

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 7/8] attrib-server: Add bluetooth adapter in attrib_create_sdp function

---
plugins/gatt-example.c | 6 ++++--
src/attrib-server.c | 13 ++++++-------
src/attrib-server.h | 3 ++-
3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index 332c190..ae9d41d 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -231,7 +231,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
g_assert(h - start_handle == svc_size);

/* Add an SDP record for the above service */
- sdp_handle = attrib_create_sdp(start_handle, "Thermometer");
+ sdp_handle = attrib_create_sdp(adapter->adapter, start_handle,
+ "Thermometer");
if (sdp_handle)
adapter->sdp_handles = g_slist_prepend(adapter->sdp_handles,
GUINT_TO_POINTER(sdp_handle));
@@ -496,7 +497,8 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
g_assert(h - start_handle == svc_size);

/* Add an SDP record for the above service */
- sdp_handle = attrib_create_sdp(start_handle, "Weight Service");
+ sdp_handle = attrib_create_sdp(adapter->adapter, start_handle,
+ "Weight Service");
if (sdp_handle)
adapter->sdp_handles = g_slist_prepend(adapter->sdp_handles,
GUINT_TO_POINTER(sdp_handle));
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 3a469c6..929a505 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1264,17 +1264,16 @@ void btd_adapter_gatt_server_stop(struct btd_adapter *adapter)
gatt_adapter_free(gadapter);
}

-uint32_t attrib_create_sdp(uint16_t handle, const char *name)
+uint32_t attrib_create_sdp(struct btd_adapter *adapter, uint16_t handle,
+ const char *name)
{
- struct gatt_adapter *gadapter;
-
- DBG("Deprecated function!");
+ GSList *l;

- gadapter = get_default_gatt_adapter();
- if (gadapter == NULL)
+ l = g_slist_find_custom(adapters, adapter, adapter_cmp);
+ if (l == NULL)
return 0;

- return attrib_create_sdp_new(gadapter, handle, name);
+ return attrib_create_sdp_new(l->data, handle, name);
}

void attrib_free_sdp(uint32_t sdp_handle)
diff --git a/src/attrib-server.h b/src/attrib-server.h
index becb3a8..dc08bfb 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -32,7 +32,8 @@ int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
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);
-uint32_t attrib_create_sdp(uint16_t handle, const char *name);
+uint32_t attrib_create_sdp(struct btd_adapter *adapter, uint16_t handle,
+ const char *name);
void attrib_free_sdp(uint32_t sdp_handle);
guint attrib_channel_attach(GAttrib *attrib, gboolean out);
gboolean attrib_channel_detach(guint id);
--
1.7.8.1


2011-12-27 09:29:39

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 5/8] attrib-server: Add bluetooth adapter in attrib_gap_set function

---
src/adapter.c | 4 ++--
src/attrib-server.c | 8 +++-----
src/attrib-server.h | 3 ++-
3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 57e4c12..6d5f63d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -850,7 +850,7 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint32_t new_class)
if (main_opts.attrib_server) {
/* Removes service class */
class[1] = class[1] & 0x1f;
- attrib_gap_set(GATT_CHARAC_APPEARANCE, class, 2);
+ attrib_gap_set(adapter, GATT_CHARAC_APPEARANCE, class, 2);
}

emit_property_changed(connection, adapter->path,
@@ -872,7 +872,7 @@ void adapter_name_changed(struct btd_adapter *adapter, const char *name)
DBUS_TYPE_STRING, &name);

if (main_opts.attrib_server)
- attrib_gap_set(GATT_CHARAC_DEVICE_NAME,
+ attrib_gap_set(adapter, GATT_CHARAC_DEVICE_NAME,
(const uint8_t *) name, strlen(name));
}

diff --git a/src/attrib-server.c b/src/attrib-server.c
index d163cb9..2ee4804 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1399,12 +1399,11 @@ int attrib_db_del(uint16_t handle)
return 0;
}

-int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len)
+int attrib_gap_set(struct btd_adapter *adapter, uint16_t uuid,
+ const uint8_t *value, int len)
{
uint16_t handle;

- DBG("Deprecated function!");
-
/* FIXME: Missing Privacy and Reconnection Address */

switch (uuid) {
@@ -1418,6 +1417,5 @@ int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len)
return -ENOSYS;
}

- /* FIXME: Provide the adapter in next function */
- return attrib_db_update(NULL, handle, NULL, value, len, NULL);
+ return attrib_db_update(adapter, handle, NULL, value, len, NULL);
}
diff --git a/src/attrib-server.h b/src/attrib-server.h
index 1265bd1..fb7f285 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -30,7 +30,8 @@ int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr);
int attrib_db_del(uint16_t handle);
-int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len);
+int attrib_gap_set(struct btd_adapter *adapter, uint16_t uuid,
+ const uint8_t *value, int len);
uint32_t attrib_create_sdp(uint16_t handle, const char *name);
void attrib_free_sdp(uint32_t sdp_handle);
guint attrib_channel_attach(GAttrib *attrib, gboolean out);
--
1.7.8.1


2011-12-27 09:29:42

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 8/8] attrib-server: Add Gattrib in attrib_channel_detach function

---
src/attrib-server.c | 39 +++++++++++++++------------------------
src/attrib-server.h | 2 +-
src/device.c | 6 +++---
3 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 929a505..8cdb5b7 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -180,27 +180,6 @@ static struct gatt_adapter *find_gatt_adapter(const bdaddr_t *bdaddr)
return l->data;
}

-static struct gatt_adapter *get_default_gatt_adapter(void)
-{
- struct btd_adapter *adapter;
- GSList *l;
-
- adapter = manager_get_default_adapter();
- if (adapter == NULL) {
- error("Can't get default adapter");
- return NULL;
- }
-
- l = g_slist_find_custom(adapters, adapter, adapter_cmp);
- if (l == NULL) {
- error("Not GATT server initialized on adapter %s",
- adapter_get_path(adapter));
- return NULL;
- }
-
- return l->data;
-}
-
static sdp_record_t *server_record_new(uuid_t *uuid, uint16_t start, uint16_t end)
{
sdp_list_t *svclass_id, *apseq, *proto[2], *root, *aproto;
@@ -1080,15 +1059,27 @@ static gint channel_id_cmp(gconstpointer data, gconstpointer user_data)
return channel->id - id;
}

-gboolean attrib_channel_detach(guint id)
+gboolean attrib_channel_detach(GAttrib *attrib, guint id)
{
struct gatt_adapter *gadapter;
struct gatt_channel *channel;
+ GError *gerr = NULL;
+ GIOChannel *io;
+ bdaddr_t src;
GSList *l;

- DBG("Deprecated function");
+ io = g_attrib_get_channel(attrib);
+
+ bt_io_get(io, BT_IO_L2CAP, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src,
+ BT_IO_OPT_INVALID);
+
+ if (gerr != NULL) {
+ error("bt_io_get: %s", gerr->message);
+ g_error_free(gerr);
+ return FALSE;
+ }

- gadapter = get_default_gatt_adapter();
+ gadapter = find_gatt_adapter(&src);
if (gadapter == NULL)
return FALSE;

diff --git a/src/attrib-server.h b/src/attrib-server.h
index dc08bfb..2c6f428 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -36,4 +36,4 @@ uint32_t attrib_create_sdp(struct btd_adapter *adapter, uint16_t handle,
const char *name);
void attrib_free_sdp(uint32_t sdp_handle);
guint attrib_channel_attach(GAttrib *attrib, gboolean out);
-gboolean attrib_channel_detach(guint id);
+gboolean attrib_channel_detach(GAttrib *attrib, guint id);
diff --git a/src/device.c b/src/device.c
index bb97089..5be3fc5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1725,7 +1725,7 @@ static void attrib_disconnected(gpointer user_data)

g_slist_foreach(device->attios, attio_disconnected, NULL);

- attrib_channel_detach(device->attachid);
+ attrib_channel_detach(device->attrib, device->attachid);
g_attrib_unref(device->attrib);
device->attrib = NULL;

@@ -1774,7 +1774,7 @@ static void primary_cb(GSList *services, guint8 status, gpointer user_data)
device_probe_drivers(device, uuids);

if (device->attios == NULL && device->attios_offline == NULL) {
- attrib_channel_detach(device->attachid);
+ attrib_channel_detach(device->attrib, device->attachid);
g_attrib_unref(device->attrib);
device->attrib = NULL;
} else
@@ -2869,7 +2869,7 @@ gboolean btd_device_remove_attio_callback(struct btd_device *device, guint id)
return TRUE;

if (device->attachid) {
- attrib_channel_detach(device->attachid);
+ attrib_channel_detach(device->attrib, device->attachid);
device->attachid = 0;
}

--
1.7.8.1


2011-12-27 09:29:40

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 6/8] attrib-server: Add bluetooth adapter in attrib_db_del

---
src/attrib-server.c | 10 +++++-----
src/attrib-server.h | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 2ee4804..3a469c6 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1371,19 +1371,19 @@ int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
return 0;
}

-int attrib_db_del(uint16_t handle)
+int attrib_db_del(struct btd_adapter *adapter, uint16_t handle)
{
struct gatt_adapter *gadapter;
struct attribute *a;
GSList *l;
guint h = handle;

- DBG("Deprecated function!");
-
- gadapter = get_default_gatt_adapter();
- if (gadapter == NULL)
+ l = g_slist_find_custom(adapters, adapter, adapter_cmp);
+ if (l == NULL)
return -ENOENT;

+ gadapter = l->data;
+
DBG("handle=0x%04x", handle);

l = g_slist_find_custom(gadapter->database, GUINT_TO_POINTER(h),
diff --git a/src/attrib-server.h b/src/attrib-server.h
index fb7f285..becb3a8 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -29,7 +29,7 @@ struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle,
int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr);
-int attrib_db_del(uint16_t handle);
+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);
uint32_t attrib_create_sdp(uint16_t handle, const char *name);
--
1.7.8.1


2011-12-27 09:29:37

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 3/8] gatt-service: Add bluetooth adapter in gatt_service_add function

---
attrib/gatt-service.c | 31 +++++++++++++------------------
attrib/gatt-service.h | 3 ++-
plugins/gatt-example.c | 7 ++++---
time/server.c | 3 ++-
4 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 73230f2..3bfa565 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -151,7 +151,8 @@ static gint find_callback(gconstpointer a, gconstpointer b)
return cb->event - event;
}

-static gboolean add_characteristic(uint16_t *handle, struct gatt_info *info)
+static gboolean add_characteristic(struct btd_adapter *adapter,
+ uint16_t *handle, struct gatt_info *info)
{
int read_reqs, write_reqs;
uint16_t h = *handle;
@@ -197,14 +198,12 @@ static gboolean add_characteristic(uint16_t *handle, struct gatt_info *info)
atval[0] = info->props;
att_put_u16(h + 1, &atval[1]);
att_put_u16(info->uuid.value.u16, &atval[3]);
- /* FIXME: Provide the adapter in next function */
- attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
- sizeof(atval));
+ attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, sizeof(atval));

/* characteristic value */
- /* FIXME: Provide the adapter in next function */
- a = attrib_db_add(NULL, h++, &info->uuid, read_reqs, write_reqs, NULL,
- 0);
+ a = attrib_db_add(adapter, h++, &info->uuid, read_reqs, write_reqs,
+ NULL, 0);
for (l = info->callbacks; l != NULL; l = l->next) {
struct attrib_cb *cb = l->data;

@@ -228,8 +227,7 @@ static gboolean add_characteristic(uint16_t *handle, struct gatt_info *info)
bt_uuid16_create(&bt_uuid, GATT_CLIENT_CHARAC_CFG_UUID);
cfg_val[0] = 0x00;
cfg_val[1] = 0x00;
- /* FIXME: Provide the adapter in next function */
- a = attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE,
+ a = attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE,
ATT_AUTHENTICATION, cfg_val, sizeof(cfg_val));

if (info->ccc_handle != NULL)
@@ -249,7 +247,8 @@ static void free_gatt_info(void *data)
g_free(info);
}

-gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...)
+gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
+ uint16_t svc_uuid, gatt_option opt1, ...)
{
uint16_t start_handle, h;
unsigned int size;
@@ -266,9 +265,7 @@ gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ..
size += info->num_attrs;
}
va_end(args);
-
- /* FIXME: Provide the adapter in next function */
- start_handle = attrib_db_find_avail(NULL, size);
+ 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);
@@ -282,15 +279,13 @@ gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ..
h = start_handle;
bt_uuid16_create(&bt_uuid, uuid);
att_put_u16(svc_uuid, &atval[0]);
- /* FIXME: Provide the adapter in next function */
- attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
- sizeof(atval));
-
+ attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, sizeof(atval));
for (l = chrs; l != NULL; l = l->next) {
struct gatt_info *info = l->data;

DBG("New characteristic: handle 0x%04x", h);
- if (!add_characteristic(&h, info)) {
+ if (!add_characteristic(adapter, &h, info)) {
g_slist_free_full(chrs, free_gatt_info);
return FALSE;
}
diff --git a/attrib/gatt-service.h b/attrib/gatt-service.h
index 95064c0..7af2d3e 100644
--- a/attrib/gatt-service.h
+++ b/attrib/gatt-service.h
@@ -47,4 +47,5 @@ typedef enum {
ATTRIB_WRITE,
} attrib_event_t;

-gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...);
+gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
+ uint16_t svc_uuid, gatt_option opt1, ...);
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index f3f2b3a..27d3d13 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -102,9 +102,10 @@ static uint8_t battery_state_read(struct attribute *a, gpointer user_data)
return 0;
}

-static gboolean register_battery_service(void)
+static gboolean register_battery_service(struct btd_adapter *adapter)
{
- return gatt_service_add(GATT_PRIM_SVC_UUID, BATTERY_STATE_SVC_UUID,
+ return gatt_service_add(adapter, GATT_PRIM_SVC_UUID,
+ BATTERY_STATE_SVC_UUID,
/* battery state characteristic */
GATT_OPT_CHR_UUID, BATTERY_STATE_UUID,
GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
@@ -509,7 +510,7 @@ static int gatt_example_adapter_probe(struct btd_adapter *adapter)
gadapter = g_new0(struct gatt_example_adapter, 1);
gadapter->adapter = btd_adapter_ref(adapter);

- if (!register_battery_service()) {
+ if (!register_battery_service(adapter)) {
DBG("Battery service could not be registered");
gatt_example_adapter_free(gadapter);
return -EIO;
diff --git a/time/server.c b/time/server.c
index 5636cca..839b33a 100644
--- a/time/server.c
+++ b/time/server.c
@@ -114,7 +114,8 @@ static uint8_t local_time_info_read(struct attribute *a, gpointer user_data)
static void register_current_time_service(void)
{
/* Current Time service */
- gatt_service_add(GATT_PRIM_SVC_UUID, CURRENT_TIME_SVC_UUID,
+ /* FIXME: Provide the adapter in next function */
+ gatt_service_add(NULL, GATT_PRIM_SVC_UUID, CURRENT_TIME_SVC_UUID,
/* CT Time characteristic */
GATT_OPT_CHR_UUID, CT_TIME_CHR_UUID,
GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
--
1.7.8.1


2011-12-27 09:29:38

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 4/8] attrib-server: Add bluetooth adapter in attrib_db_update function

---
plugins/gatt-example.c | 3 ++-
src/attrib-server.c | 17 ++++++++++-------
src/attrib-server.h | 3 ++-
time/server.c | 6 ++++--
4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index 27d3d13..332c190 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -97,7 +97,8 @@ static uint8_t battery_state_read(struct attribute *a, gpointer user_data)
uint8_t value;

value = 0x04;
- attrib_db_update(a->handle, NULL, &value, sizeof(value), NULL);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_update(NULL, a->handle, NULL, &value, sizeof(value), NULL);

return 0;
}
diff --git a/src/attrib-server.c b/src/attrib-server.c
index cdf54ee..d163cb9 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -844,7 +844,8 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle,

if (bt_uuid_cmp(&ccc_uuid, &a->uuid) != 0) {

- attrib_db_update(handle, NULL, value, vlen, NULL);
+ attrib_db_update(channel->gadapter->adapter, handle, NULL,
+ value, vlen, NULL);

if (a->write_cb) {
status = a->write_cb(a, a->cb_user_data);
@@ -1330,7 +1331,8 @@ struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle,
value, len);
}

-int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
+int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
+ bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr)
{
struct gatt_adapter *gadapter;
@@ -1338,12 +1340,12 @@ int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
GSList *l;
guint h = handle;

- DBG("Deprecated function!");
-
- gadapter = get_default_gatt_adapter();
- if (gadapter == NULL)
+ l = g_slist_find_custom(adapters, adapter, adapter_cmp);
+ if (l == NULL)
return -ENOENT;

+ gadapter = l->data;
+
DBG("handle=0x%04x", handle);

l = g_slist_find_custom(gadapter->database, GUINT_TO_POINTER(h),
@@ -1416,5 +1418,6 @@ int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len)
return -ENOSYS;
}

- return attrib_db_update(handle, NULL, value, len, NULL);
+ /* FIXME: Provide the adapter in next function */
+ return attrib_db_update(NULL, handle, NULL, value, len, NULL);
}
diff --git a/src/attrib-server.h b/src/attrib-server.h
index ac1c388..1265bd1 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -26,7 +26,8 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, uint16_t nitems);
struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle,
bt_uuid_t *uuid, int read_reqs, int write_reqs,
const uint8_t *value, int len);
-int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
+int attrib_db_update(struct btd_adapter *adapter, uint16_t handle,
+ bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr);
int attrib_db_del(uint16_t handle);
int attrib_gap_set(uint16_t uuid, const uint8_t *value, int len);
diff --git a/time/server.c b/time/server.c
index 839b33a..4ed9cf2 100644
--- a/time/server.c
+++ b/time/server.c
@@ -85,7 +85,8 @@ static uint8_t current_time_read(struct attribute *a, gpointer user_data)
if (encode_current_time(value) < 0)
return ATT_ECODE_IO;

- attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_update(NULL, a->handle, NULL, value, sizeof(value), NULL);

return 0;
}
@@ -106,7 +107,8 @@ static uint8_t local_time_info_read(struct attribute *a, gpointer user_data)
* format (offset from UTC in number of 15 minutes increments). */
value[1] = (uint8_t) (-1 * timezone / (60 * 15));

- attrib_db_update(a->handle, NULL, value, sizeof(value), NULL);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_update(NULL, a->handle, NULL, value, sizeof(value), NULL);

return 0;
}
--
1.7.8.1


2011-12-27 09:29:36

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 2/8] attrib-server: Add bluetooth adapter in attrib_db_add

Because of there can be many adapters plugged, the GATT servers
must provide te adapter in wich the attributes will be retgistered.
---
attrib/gatt-service.c | 15 +++++---
plugins/gatt-example.c | 93 +++++++++++++++++++++++++++++++-----------------
proximity/reporter.c | 30 ++++++++++-----
src/attrib-server.c | 15 ++++----
src/attrib-server.h | 5 ++-
5 files changed, 100 insertions(+), 58 deletions(-)

diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 327569f..73230f2 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -197,11 +197,14 @@ static gboolean add_characteristic(uint16_t *handle, struct gatt_info *info)
atval[0] = info->props;
att_put_u16(h + 1, &atval[1]);
att_put_u16(info->uuid.value.u16, &atval[3]);
- attrib_db_add(h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
sizeof(atval));

/* characteristic value */
- a = attrib_db_add(h++, &info->uuid, read_reqs, write_reqs, NULL, 0);
+ /* FIXME: Provide the adapter in next function */
+ a = attrib_db_add(NULL, h++, &info->uuid, read_reqs, write_reqs, NULL,
+ 0);
for (l = info->callbacks; l != NULL; l = l->next) {
struct attrib_cb *cb = l->data;

@@ -225,8 +228,9 @@ static gboolean add_characteristic(uint16_t *handle, struct gatt_info *info)
bt_uuid16_create(&bt_uuid, GATT_CLIENT_CHARAC_CFG_UUID);
cfg_val[0] = 0x00;
cfg_val[1] = 0x00;
- a = attrib_db_add(h++, &bt_uuid, ATT_NONE, ATT_AUTHENTICATION,
- cfg_val, sizeof(cfg_val));
+ /* FIXME: Provide the adapter in next function */
+ a = attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE,
+ ATT_AUTHENTICATION, cfg_val, sizeof(cfg_val));

if (info->ccc_handle != NULL)
*info->ccc_handle = a->handle;
@@ -278,7 +282,8 @@ gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ..
h = start_handle;
bt_uuid16_create(&bt_uuid, uuid);
att_put_u16(svc_uuid, &atval[0]);
- attrib_db_add(h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
sizeof(atval));

for (l = chrs; l != NULL; l = l->next) {
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index 4aa5a8b..f3f2b3a 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -140,7 +140,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
/* Thermometer: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
att_put_u16(THERM_HUMIDITY_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 2);

bt_uuid16_create(&uuid, GATT_INCLUDE_UUID);

@@ -149,8 +150,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
att_put_u16(manuf1[0], &atval[0]);
att_put_u16(manuf1[1], &atval[2]);
att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
- 6);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
+ ATT_NOT_PERMITTED, atval, 6);
}

/* Thermometer: Include */
@@ -158,8 +159,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
att_put_u16(manuf2[0], &atval[0]);
att_put_u16(manuf2[1], &atval[2]);
att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[4]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
- 6);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
+ ATT_NOT_PERMITTED, atval, 6);
}

/* Thermometer: temperature characteristic */
@@ -167,13 +168,15 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(TEMPERATURE_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Thermometer: temperature characteristic value */
bt_uuid16_create(&uuid, TEMPERATURE_UUID);
atval[0] = 0x8A;
atval[1] = 0x02;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 2);

/* Thermometer: temperature characteristic format */
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
@@ -182,25 +185,29 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
att_put_u16(FMT_CELSIUS_UUID, &atval[2]);
atval[4] = 0x01;
att_put_u16(FMT_OUTSIDE_UUID, &atval[5]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 7);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 7);

/* Thermometer: characteristic user description */
bt_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID);
len = strlen(desc_out_temp);
strncpy((char *) atval, desc_out_temp, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

/* Thermometer: relative humidity characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(RELATIVE_HUMIDITY_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Thermometer: relative humidity value */
bt_uuid16_create(&uuid, RELATIVE_HUMIDITY_UUID);
atval[0] = 0x27;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 1);

/* Thermometer: relative humidity characteristic format */
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
@@ -209,13 +216,15 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
att_put_u16(FMT_PERCENT_UUID, &atval[2]);
att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
att_put_u16(FMT_OUTSIDE_UUID, &atval[6]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 8);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 8);

/* Thermometer: characteristic user description */
bt_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID);
len = strlen(desc_out_hum);
strncpy((char *) atval, desc_out_hum, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

g_assert(h - start_handle == svc_size);

@@ -250,33 +259,38 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,
/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Manufacturer name characteristic value */
bt_uuid16_create(&uuid, MANUFACTURER_NAME_UUID);
len = strlen(manufacturer_name1);
strncpy((char *) atval, manufacturer_name1, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

/* Manufacturer serial number characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Manufacturer serial number characteristic value */
bt_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID);
len = strlen(serial1);
strncpy((char *) atval, serial1, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

g_assert(h - start_handle == svc_size);

@@ -308,33 +322,38 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,
/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Manufacturer name attribute */
bt_uuid16_create(&uuid, MANUFACTURER_NAME_UUID);
len = strlen(manufacturer_name2);
strncpy((char *) atval, manufacturer_name2, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

/* Characteristic: serial number */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Serial number characteristic value */
bt_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID);
len = strlen(serial2);
strncpy((char *) atval, serial2, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

g_assert(h - start_handle == svc_size);

@@ -363,14 +382,16 @@ static void register_vendor_service(struct gatt_example_adapter *adapter,
/* Secondary Service: Vendor Specific Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 2);

/* Vendor Specific Type characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
att_put_u16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 5);

/* Vendor Specific Type characteristic value */
bt_uuid16_create(&uuid, VENDOR_SPECIFIC_TYPE_UUID);
@@ -380,7 +401,8 @@ static void register_vendor_service(struct gatt_example_adapter *adapter,
atval[3] = 0x64;
atval[4] = 0x6F;
atval[5] = 0x72;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 6);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 6);

g_assert(h - start_handle == svc_size);

@@ -422,7 +444,8 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
/* Weight service: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
memcpy(atval, &prim_weight_uuid_btorder, 16);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 16);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 16);

if (vendor[0] && vendor[1]) {
/* Weight: include */
@@ -430,8 +453,8 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
att_put_u16(vendor[0], &atval[0]);
att_put_u16(vendor[1], &atval[2]);
att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval,
- 6);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
+ ATT_NOT_PERMITTED, atval, 6);
}

/* Weight: characteristic */
@@ -439,7 +462,8 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(h + 1, &atval[1]);
memcpy(&atval[3], &char_weight_uuid_btorder, 16);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 19);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 19);

/* Weight: characteristic value */
bt_uuid128_create(&uuid, char_weight_uuid);
@@ -447,7 +471,8 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
atval[1] = 0x55;
atval[2] = 0x00;
atval[3] = 0x00;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 4);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 4);

/* Weight: characteristic format */
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
@@ -456,13 +481,15 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
att_put_u16(FMT_KILOGRAM_UUID, &atval[2]);
att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
att_put_u16(FMT_HANGING_UUID, &atval[6]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 8);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, 8);

/* Weight: characteristic user description */
bt_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID);
len = strlen(desc_weight);
strncpy((char *) atval, desc_weight, len);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len);
+ attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
+ atval, len);

g_assert(h - start_handle == svc_size);

diff --git a/proximity/reporter.c b/proximity/reporter.c
index 050b1c7..d8cc58f 100644
--- a/proximity/reporter.c
+++ b/proximity/reporter.c
@@ -73,19 +73,22 @@ static void register_link_loss(void)
/* Primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
att_put_u16(LINK_LOSS_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);

/* Alert level characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_WRITE;
att_put_u16(h + 1, &atval[1]);
att_put_u16(ALERT_LEVEL_CHR_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);

/* Alert level value */
bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
att_put_u8(NO_ALERT, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);

g_assert(h - start_handle == svc_size);
}
@@ -111,26 +114,30 @@ static void register_tx_power(void)
/* Primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
att_put_u16(TX_POWER_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);

/* Power level characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_NOTIFY;
att_put_u16(h + 1, &atval[1]);
att_put_u16(POWER_LEVEL_CHR_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);

/* Power level value */
bt_uuid16_create(&uuid, POWER_LEVEL_CHR_UUID);
att_put_u8(0x00, &atval[0]);
tx_power_handle = h;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1);

/* Client characteristic configuration */
bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
atval[0] = 0x00;
atval[1] = 0x00;
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NONE, atval, 2);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 2);

g_assert(h - start_handle == svc_size);
}
@@ -156,19 +163,22 @@ static void register_immediate_alert(void)
/* Primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
att_put_u16(IMMEDIATE_ALERT_SVC_UUID, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);

/* Alert level characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_WRITE;
att_put_u16(h + 1, &atval[1]);
att_put_u16(ALERT_LEVEL_CHR_UUID, &atval[3]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);

/* Alert level value */
bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
att_put_u8(NO_ALERT, &atval[0]);
- attrib_db_add(h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);
+ /* FIXME: Provide the adapter in next function */
+ attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);

g_assert(h - start_handle == svc_size);
}
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 6a3ce4f..cdf54ee 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1316,18 +1316,17 @@ uint16_t attrib_db_find_avail(struct btd_adapter *adapter, uint16_t nitems)
return 0;
}

-struct attribute *attrib_db_add(uint16_t handle, bt_uuid_t *uuid, int read_reqs,
- int write_reqs, const uint8_t *value, int len)
+struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle,
+ bt_uuid_t *uuid, int read_reqs, int write_reqs,
+ const uint8_t *value, int len)
{
- struct gatt_adapter *gadapter;
-
- DBG("Deprecated function!");
+ GSList *l;

- gadapter = get_default_gatt_adapter();
- if (gadapter == NULL)
+ l = g_slist_find_custom(adapters, adapter, adapter_cmp);
+ if (l == NULL)
return NULL;

- return attrib_db_add_new(gadapter, handle, uuid, read_reqs, write_reqs,
+ return attrib_db_add_new(l->data, handle, uuid, read_reqs, write_reqs,
value, len);
}

diff --git a/src/attrib-server.h b/src/attrib-server.h
index 8bf9c07..ac1c388 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -23,8 +23,9 @@
*/

uint16_t attrib_db_find_avail(struct btd_adapter *adapter, uint16_t nitems);
-struct attribute *attrib_db_add(uint16_t handle, bt_uuid_t *uuid, int read_reqs,
- int write_reqs, const uint8_t *value, int len);
+struct attribute *attrib_db_add(struct btd_adapter *adapter, uint16_t handle,
+ bt_uuid_t *uuid, int read_reqs, int write_reqs,
+ const uint8_t *value, int len);
int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
int len, struct attribute **attr);
int attrib_db_del(uint16_t handle);
--
1.7.8.1


2011-12-27 09:29:35

by Santiago Carot

[permalink] [raw]
Subject: [PATCH 1/8] attrib-server: Add blutooth adapter to attrib_db_find_avail function

Adapters manage their own list of handlers so we need to specify
the adapter where the handlers will be registered.
---
attrib/gatt-service.c | 4 +++-
plugins/gatt-example.c | 25 ++++++++++++++-----------
proximity/reporter.c | 10 +++++++---
src/attrib-server.c | 10 +++++-----
src/attrib-server.h | 2 +-
time/server.c | 1 +
6 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index b904ce6..327569f 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -29,6 +29,7 @@
#include <glib.h>
#include <bluetooth/uuid.h>
#include <bluetooth/sdp.h>
+#include <adapter.h>

#include "att.h"
#include "gattrib.h"
@@ -262,7 +263,8 @@ gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ..
}
va_end(args);

- start_handle = attrib_db_find_avail(size);
+ /* FIXME: Provide the adapter in next function */
+ start_handle = attrib_db_find_avail(NULL, size);
if (start_handle == 0) {
error("Not enough free handles to register service");
g_slist_free_full(chrs, free_gatt_info);
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index 4e8f36f..4aa5a8b 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -126,7 +126,7 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid_t uuid;
int len;

- start_handle = attrib_db_find_avail(svc_size);
+ start_handle = attrib_db_find_avail(adapter->adapter, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -226,7 +226,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
GUINT_TO_POINTER(sdp_handle));
}

-static void register_manuf1_service(uint16_t range[2])
+static void register_manuf1_service(struct gatt_example_adapter *adapter,
+ uint16_t range[2])
{
const char *manufacturer_name1 = "ACME Temperature Sensor";
const char *serial1 = "237495-3282-A";
@@ -236,7 +237,7 @@ static void register_manuf1_service(uint16_t range[2])
bt_uuid_t uuid;
int len;

- start_handle = attrib_db_find_avail(svc_size);
+ start_handle = attrib_db_find_avail(adapter->adapter, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -283,7 +284,8 @@ static void register_manuf1_service(uint16_t range[2])
range[1] = start_handle + svc_size - 1;
}

-static void register_manuf2_service(uint16_t range[2])
+static void register_manuf2_service(struct gatt_example_adapter *adapter,
+ uint16_t range[2])
{
const char *manufacturer_name2 = "ACME Weighing Scales";
const char *serial2 = "11267-2327A00239";
@@ -293,7 +295,7 @@ static void register_manuf2_service(uint16_t range[2])
bt_uuid_t uuid;
int len;

- start_handle = attrib_db_find_avail(svc_size);
+ start_handle = attrib_db_find_avail(adapter->adapter, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -340,14 +342,15 @@ static void register_manuf2_service(uint16_t range[2])
range[1] = start_handle + svc_size - 1;
}

-static void register_vendor_service(uint16_t range[2])
+static void register_vendor_service(struct gatt_example_adapter *adapter,
+ uint16_t range[2])
{
uint16_t start_handle, h;
const int svc_size = 3;
uint8_t atval[256];
bt_uuid_t uuid;

- start_handle = attrib_db_find_avail(svc_size);
+ start_handle = attrib_db_find_avail(adapter->adapter, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -405,7 +408,7 @@ static void register_weight_service(struct gatt_example_adapter *adapter,

btoh128(&char_weight_uuid_btorder, &char_weight_uuid);

- start_handle = attrib_db_find_avail(svc_size);
+ start_handle = attrib_db_find_avail(adapter->adapter, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -485,10 +488,10 @@ static int gatt_example_adapter_probe(struct btd_adapter *adapter)
return -EIO;
}

- register_manuf1_service(manuf1_range);
- register_manuf2_service(manuf2_range);
+ register_manuf1_service(gadapter, manuf1_range);
+ register_manuf2_service(gadapter, manuf2_range);
register_termometer_service(gadapter, manuf1_range, manuf2_range);
- register_vendor_service(vendor_range);
+ register_vendor_service(gadapter, vendor_range);
register_weight_service(gadapter, vendor_range);

adapters = g_slist_append(adapters, gadapter);
diff --git a/proximity/reporter.c b/proximity/reporter.c
index 77a7dcd..050b1c7 100644
--- a/proximity/reporter.c
+++ b/proximity/reporter.c
@@ -28,6 +28,7 @@

#include <glib.h>
#include <bluetooth/uuid.h>
+#include <adapter.h>

#include "log.h"

@@ -58,7 +59,8 @@ static void register_link_loss(void)
uint8_t atval[256];
bt_uuid_t uuid;

- start_handle = attrib_db_find_avail(svc_size);
+ /* FIXME: Provide the adapter in next function */
+ start_handle = attrib_db_find_avail(NULL, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -95,7 +97,8 @@ static void register_tx_power(void)
uint8_t atval[256];
bt_uuid_t uuid;

- start_handle = attrib_db_find_avail(svc_size);
+ /* FIXME: Provide the adapter in next function */
+ start_handle = attrib_db_find_avail(NULL, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
@@ -139,7 +142,8 @@ static void register_immediate_alert(void)
uint8_t atval[256];
bt_uuid_t uuid;

- start_handle = attrib_db_find_avail(svc_size);
+ /* FIXME: Provide the adapter in next function */
+ start_handle = attrib_db_find_avail(NULL, svc_size);
if (start_handle == 0) {
error("Not enough free handles to register service");
return;
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 90ec1c2..6a3ce4f 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1281,20 +1281,20 @@ void attrib_free_sdp(uint32_t sdp_handle)
remove_record_from_server(sdp_handle);
}

-uint16_t attrib_db_find_avail(uint16_t nitems)
+uint16_t attrib_db_find_avail(struct btd_adapter *adapter, uint16_t nitems)
{
struct gatt_adapter *gadapter;
uint16_t handle;
GSList *l;

- DBG("Deprecated function!");
-
g_assert(nitems > 0);

- gadapter = get_default_gatt_adapter();
- if (gadapter == NULL)
+ l = g_slist_find_custom(adapters, adapter, adapter_cmp);
+ if (l == NULL)
return 0;

+ gadapter = l->data;
+
for (l = gadapter->database, handle = 0; l; l = l->next) {
struct attribute *a = l->data;

diff --git a/src/attrib-server.h b/src/attrib-server.h
index 943096c..8bf9c07 100644
--- a/src/attrib-server.h
+++ b/src/attrib-server.h
@@ -22,7 +22,7 @@
*
*/

-uint16_t attrib_db_find_avail(uint16_t nitems);
+uint16_t attrib_db_find_avail(struct btd_adapter *adapter, uint16_t nitems);
struct attribute *attrib_db_add(uint16_t handle, bt_uuid_t *uuid, int read_reqs,
int write_reqs, const uint8_t *value, int len);
int attrib_db_update(uint16_t handle, bt_uuid_t *uuid, const uint8_t *value,
diff --git a/time/server.c b/time/server.c
index 5c32dc2..5636cca 100644
--- a/time/server.c
+++ b/time/server.c
@@ -30,6 +30,7 @@
#include <time.h>
#include <errno.h>
#include <bluetooth/uuid.h>
+#include <adapter.h>

#include "att.h"
#include "gattrib.h"
--
1.7.8.1