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
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(-)
attrib/gatt-service.c +3 -1
@@ -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);
plugins/gatt-example.c +14 -11
@@ -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);
proximity/reporter.c +7 -3
@@ -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 ;
src/attrib-server.c +5 -5
@@ -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;
src/attrib-server.h +1 -1
@@ -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,
time/server.c +1 -0
@@ -30,6 +30,7 @@#include <time.h> #include <errno.h> #include <bluetooth/uuid.h> +#include <adapter.h> #include "att.h" #include "gattrib.h"
Signature · 1 line
1.7.8.1
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(-)
attrib/gatt-service.c +10 -5
@@ -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) {
plugins/gatt-example.c +60 -33
263 lines not on this page · raw message
proximity/reporter.c +20 -10
@@ -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); }
src/attrib-server.c +7 -8
@@ -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); }
src/attrib-server.h +3 -2
@@ -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);
Signature · 1 line
1.7.8.1
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(-)
attrib/gatt-service.c +13 -18
@@ -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; }
attrib/gatt-service.h +2 -1
@@ -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, ...);
plugins/gatt-example.c +4 -3
@@ -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 ;
time/server.c +2 -1
@@ -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 |
Signature · 1 line
1.7.8.1
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(-)
plugins/gatt-example.c +2 -1
@@ -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 ; }
src/attrib-server.c +10 -7
@@ -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 ); }
src/attrib-server.h +2 -1
@@ -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);
time/server.c +4 -2
@@ -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 ; }
Signature · 1 line
1.7.8.1
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(-)
src/adapter.c +2 -2
@@ -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)); }
src/attrib-server.c +3 -5
@@ -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 ); }
src/attrib-server.h +2 -1
@@ -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);
Signature · 1 line
1.7.8.1
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(-)
src/attrib-server.c +5 -5
@@ -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),
src/attrib-server.h +1 -1
@@ -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);
Signature · 1 line
1.7.8.1
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(-)
plugins/gatt-example.c +4 -2
@@ -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));
src/attrib-server.c +6 -7
@@ -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)
src/attrib-server.h +2 -1
@@ -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);
Signature · 1 line
1.7.8.1
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(-)
src/attrib-server.c +15 -24
@@ -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;
src/attrib-server.h +1 -1
@@ -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);
src/device.c +3 -3
@@ -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 ; }
Signature · 1 line
1.7.8.1
Hi
2011/12/27 Santiago Carot-Nemesio <[email protected]>:
Quoted 13 lines
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.
Quoted 8 lines
[PATCH 1/8] attrib-server: Add blutooth adapter to
[PATCH 2/8] attrib-server: Add bluetooth adapter inattrib_db_add[PATCH 3/8] gatt-service: Add bluetooth adapter ingatt_service_add[PATCH 4/8] attrib-server: Add bluetooth adapter inattrib_db_update[PATCH 5/8] attrib-server: Add bluetooth adapter inattrib_gap_set[PATCH 6/8] attrib-server: Add bluetooth adapter inattrib_db_del[PATCH 7/8] attrib-server: Add bluetooth adapter in [PATCH 8/8] attrib-server: Add Gattrib inattrib_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.