From: Vishal Agarwal <vishal.agarwal@stericsson.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: <naresh.gupta@stericsson.com>,
Vishal Agarwal <vishal.agarwal@stericsson.com>
Subject: [PATCH BlueZ v1 1/1] Add Support for BLE Services to Adapter
Date: Thu, 19 Jan 2012 10:37:34 +0530 [thread overview]
Message-ID: <1326949654-23244-2-git-send-email-vishal.agarwal@stericsson.com> (raw)
In-Reply-To: <1326949654-23244-1-git-send-email-vishal.agarwal@stericsson.com>
This patch adds support for adding primary service UUIDs
to adapter's list. These uuids can then be sent to upper
layers using the DBUS method of get_properties and signal
adapter_emit_uuids_updated.
---
proximity/manager.c | 23 +++++++++++++++++++
src/adapter.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
src/adapter.h | 2 +
3 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/proximity/manager.c b/proximity/manager.c
index a767554..ff5af6d 100644
--- a/proximity/manager.c
+++ b/proximity/manager.c
@@ -83,6 +83,21 @@ static void attio_device_remove(struct btd_device *device)
monitor_unregister(connection, device);
}
+static int proximity_adapter_probe(struct btd_adapter *adapter)
+{
+ add_primary(adapter, LINK_LOSS_SERVICE_ID);
+ add_primary(adapter, IMMEDIATE_ALERT_SERVICE_ID);
+ add_primary(adapter, TX_POWER_SERVICE_ID);
+ return 0;
+}
+
+static void proximity_adapter_remove(struct btd_adapter *adapter)
+{
+ remove_primary(adapter, LINK_LOSS_SERVICE_ID);
+ remove_primary(adapter, IMMEDIATE_ALERT_SERVICE_ID);
+ remove_primary(adapter, TX_POWER_SERVICE_ID);
+}
+
static struct btd_device_driver monitor_driver = {
.name = "Proximity GATT Driver",
.uuids = BTD_UUIDS(IMMEDIATE_ALERT_UUID, LINK_LOSS_UUID, TX_POWER_UUID),
@@ -90,6 +105,12 @@ static struct btd_device_driver monitor_driver = {
.remove = attio_device_remove,
};
+static struct btd_adapter_driver proximity_adapter = {
+ .name = "Proximity",
+ .probe = proximity_adapter_probe,
+ .remove = proximity_adapter_remove,
+};
+
static void load_config_file(GKeyFile *config)
{
char **list;
@@ -118,6 +139,7 @@ int proximity_manager_init(DBusConnection *conn, GKeyFile *config)
load_config_file(config);
+ btd_register_adapter_driver(&proximity_adapter);
/* TODO: Register Proximity Monitor/Reporter drivers */
ret = btd_register_device_driver(&monitor_driver);
if (ret < 0)
@@ -132,5 +154,6 @@ void proximity_manager_exit(void)
{
reporter_exit();
btd_unregister_device_driver(&monitor_driver);
+ btd_unregister_adapter_driver(&proximity_adapter);
dbus_connection_unref(connection);
}
diff --git a/src/adapter.c b/src/adapter.c
index a75a0c4..c206a20 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -154,6 +154,7 @@ struct btd_adapter {
GSList *pin_callbacks;
GSList *loaded_drivers;
+ GSList *primaries;
};
static void dev_info_free(void *data)
@@ -879,11 +880,12 @@ static void adapter_emit_uuids_updated(struct btd_adapter *adapter)
char **uuids;
int i;
sdp_list_t *list;
+ GSList *primary_list;
if (!adapter->initialized)
return;
- uuids = g_new0(char *, sdp_list_len(adapter->services) + 1);
+ uuids = g_new0(char *, sdp_list_len(adapter->services) + g_slist_length(adapter->primaries) + 1);
for (i = 0, list = adapter->services; list; list = list->next) {
char *uuid;
@@ -894,6 +896,15 @@ static void adapter_emit_uuids_updated(struct btd_adapter *adapter)
uuids[i++] = uuid;
}
+ for (primary_list = adapter->primaries; primary_list; primary_list = primary_list->next) {
+ char *uuid;
+ uuid_t *rec = primary_list->data;
+
+ uuid = bt_uuid2string(rec);
+ if (uuid)
+ uuids[i++] = uuid;
+ }
+
emit_array_property_changed(connection, adapter->path,
ADAPTER_INTERFACE, "UUIDs", DBUS_TYPE_STRING, &uuids, i);
@@ -986,6 +997,41 @@ void adapter_service_remove(struct btd_adapter *adapter, void *r)
adapter_emit_uuids_updated(adapter);
}
+static void adapter_primary_insert(struct btd_adapter *adapter, void *u)
+{
+ uuid_t *uuid = u;
+ if (!g_slist_find_custom(adapter->primaries, uuid, (GCompareFunc) sdp_uuid_cmp))
+ adapter->primaries = g_slist_append(adapter->primaries, uuid);
+ else
+ free(u);
+}
+
+static void adapter_primary_remove(struct btd_adapter *adapter, void *u)
+{
+ uuid_t *uuid = u;
+ GSList *list_pos;
+
+ list_pos = g_slist_find_custom(adapter->primaries, uuid, (GCompareFunc) sdp_uuid_cmp);
+ if (!list_pos) {
+ adapter->primaries = g_slist_remove(adapter->primaries, list_pos->data);
+ free(list_pos->data);
+ }
+}
+
+void add_primary(struct btd_adapter *adapter, uint16_t val)
+{
+ uuid_t *primary = malloc(sizeof(uuid_t));
+ sdp_uuid16_create(primary, val);
+ adapter_primary_insert(adapter, primary);
+}
+
+void remove_primary(struct btd_adapter *adapter, uint16_t val)
+{
+ uuid_t primary;
+ sdp_uuid16_create(&primary, val);
+ adapter_primary_remove(adapter, &primary);
+}
+
static struct btd_device *adapter_create_device(DBusConnection *conn,
struct btd_adapter *adapter,
const char *address,
@@ -1148,6 +1194,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
int i;
GSList *l;
sdp_list_t *list;
+ GSList *primary_list;
ba2str(&adapter->bdaddr, srcaddr);
@@ -1214,7 +1261,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
g_free(devices);
/* UUIDs */
- uuids = g_new0(char *, sdp_list_len(adapter->services) + 1);
+ uuids = g_new0(char *, sdp_list_len(adapter->services) + g_slist_length(adapter->primaries) + 1);
for (i = 0, list = adapter->services; list; list = list->next) {
sdp_record_t *rec = list->data;
@@ -1225,6 +1272,15 @@ static DBusMessage *get_properties(DBusConnection *conn,
uuids[i++] = uuid;
}
+ for (primary_list = adapter->primaries; primary_list; primary_list = primary_list->next) {
+ char *uuid;
+ uuid_t *rec = primary_list->data;
+
+ uuid = bt_uuid2string(rec);
+ if (uuid)
+ uuids[i++] = uuid;
+ }
+
dict_append_array(&dict, "UUIDs", DBUS_TYPE_STRING, &uuids, i);
g_strfreev(uuids);
@@ -2324,6 +2380,7 @@ static void adapter_free(gpointer user_data)
off_timer_remove(adapter);
sdp_list_free(adapter->services, NULL);
+ g_slist_free(adapter->primaries);
g_slist_free_full(adapter->found_devices, dev_info_free);
diff --git a/src/adapter.h b/src/adapter.h
index c1f981a..c1228ae 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -123,6 +123,8 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name);
void adapter_name_changed(struct btd_adapter *adapter, const char *name);
void adapter_service_insert(struct btd_adapter *adapter, void *rec);
void adapter_service_remove(struct btd_adapter *adapter, void *rec);
+void add_primary(struct btd_adapter *adapter, uint16_t val);
+void remove_primary(struct btd_adapter *adapter, uint16_t val);
void btd_adapter_class_changed(struct btd_adapter *adapter,
uint32_t new_class);
void btd_adapter_pairable_changed(struct btd_adapter *adapter,
--
1.7.0.4
next prev parent reply other threads:[~2012-01-19 5:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-19 5:07 [PATCH BlueZ v1 0/1] Add Support for BLE Services to Adapter Vishal Agarwal
2012-01-19 5:07 ` Vishal Agarwal [this message]
2012-01-20 17:35 ` [PATCH BlueZ v1 1/1] " Vinicius Costa Gomes
2012-01-24 3:51 ` Vishal AGARWAL
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=1326949654-23244-2-git-send-email-vishal.agarwal@stericsson.com \
--to=vishal.agarwal@stericsson.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=naresh.gupta@stericsson.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 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).