linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
Subject: [PATCH 13/32] Implement connection of health instances
Date: Fri,  4 Jun 2010 10:30:06 +0200	[thread overview]
Message-ID: <1275640225-4186-14-git-send-email-santoscadenas@gmail.com> (raw)
In-Reply-To: <1275640225-4186-13-git-send-email-santoscadenas@gmail.com>

---
 health/hdp.c      |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 health/hdp_util.c |   26 ++++++++++++++
 health/hdp_util.h |    2 +
 3 files changed, 123 insertions(+), 5 deletions(-)

diff --git a/health/hdp.c b/health/hdp.c
index 840af0f..b9f637e 100644
--- a/health/hdp.c
+++ b/health/hdp.c
@@ -52,6 +52,13 @@ struct health_instances_aux {
 	GSList		*end_points;
 };
 
+struct hdp_connection_cb {
+	struct hdp_device	*device;
+	struct hdp_instance	*hdpi;
+	uint32_t		rem_id;
+	DBusMessage		*msg;
+};
+
 static struct hdp_adapter *find_adapter(GSList *list,
 					struct btd_adapter *btd_adapter)
 {
@@ -240,7 +247,7 @@ static DBusMessage *get_health_instances(DBusConnection *conn,
 	bdaddr_t src, dst;
 	uuid_t uuid;
 
-	adapter = device_get_adapter(device->dev);
+	adapter = device->hdp_adapter->btd_adapter;
 	adapter_get_address(adapter, &src);
 	device_get_address(device->dev, &dst);
 
@@ -284,12 +291,82 @@ static void dev_path_unregister(void *data)
 	health_device_free(device);
 }
 
+static sdp_record_t *get_record(sdp_list_t *recs, uint32_t handle)
+{
+	sdp_record_t *rec;
+	sdp_list_t *l;
+
+	for (l = recs; l; l = l->next) {
+		rec = l->data;
+		if (rec->handle == handle)
+			return rec;
+	}
+
+	return NULL;
+}
+
+static void hdp_mcl_connect_cb(struct mcap_mcl *mcl, GError *err, void *data)
+{
+	struct hdp_connection_cb *cb_data = data;
+
+	/* TODO */
+	g_free(cb_data);
+}
+
+static void connect_health_instance(sdp_list_t *recs, int err, gpointer data)
+{
+	struct hdp_connection_cb *cb_data = data;
+	struct hdp_device *device = cb_data->device;
+	struct hdp_instance *hdpi = cb_data->hdpi;
+	GError *gerr = NULL;
+	uint32_t rid = cb_data->rem_id;
+	DBusMessage *msg = cb_data->msg;
+	DBusMessage *reply;
+	sdp_record_t *rec;
+	guint16 ccpsm, version;
+	bdaddr_t dst;
+
+	if (err != 0) {
+		reply = g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+				"Error getting remote information");
+		goto fail;
+	}
+
+	rec = get_record(recs, rid);
+	if (!rec) {
+		reply = g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+				"Error getting remote information");
+		goto fail;
+	}
+
+	if (!hdp_get_prot_desc_list(rec, &ccpsm, &version)) {
+		reply = g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+			"Error getting remote protocol descriptor list");
+		goto fail;
+	}
+
+	device_get_address(device->dev, &dst);
+	mcap_create_mcl(hdpi->mi, &dst, ccpsm, &gerr, hdp_mcl_connect_cb,
+								cb_data);
+	if (!gerr)
+		return;
+
+	reply = g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+			"Error getting remote protocol descriptor list");
+fail:
+	g_dbus_send_message(device->conn, reply);
+	g_free(cb_data);
+}
+
 static DBusMessage *hdp_connect(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
 	struct hdp_device *device = user_data;
-	struct hdp_instance *hdpi;
+	struct hdp_connection_cb *cb_data;
+	struct btd_adapter *adapter;
+	bdaddr_t src, dst;
 	uint32_t lid, rid;
+	uuid_t uuid;
 	GSList *l;
 
 	if (!dbus_message_get_args(msg, NULL,
@@ -307,11 +384,24 @@ static DBusMessage *hdp_connect(DBusConnection *conn,
 		return g_dbus_create_error(msg,
 					   ERROR_INTERFACE ".InvalidArguments",
 					   "Invalid local instance id");
-	hdpi = l->data;
 
+	cb_data = g_new0(struct hdp_connection_cb, 1);
+	cb_data->device = device;
+	cb_data->hdpi = l->data;
+	cb_data->rem_id = rid;
+	cb_data->msg = dbus_message_ref(msg);
 
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".HdpError",
-					"Function is not yet implemented");
+	adapter = device->hdp_adapter->btd_adapter;
+	adapter_get_address(adapter, &src);
+	device_get_address(device->dev, &dst);
+
+	bt_string2uuid(&uuid, HDP_UUID);
+	if (bt_search_service(&src, &dst, &uuid, connect_health_instance,
+							cb_data, NULL) == 0)
+		return NULL;
+
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".HealthError",
+				   "Error getting remote information");
 }
 
 static GDBusMethodTable device_methods[] = {
diff --git a/health/hdp_util.c b/health/hdp_util.c
index 921a1e1..066147a 100644
--- a/health/hdp_util.c
+++ b/health/hdp_util.c
@@ -883,6 +883,32 @@ gboolean hdp_get_data_exchange_spec(const sdp_record_t *rec, guint8 *val)
 	return TRUE;
 }
 
+gboolean hdp_get_prot_desc_list(const sdp_record_t *rec, guint16 *psm,
+							guint16 *version)
+{
+	if (!(psm || version))
+		return TRUE;
+
+	/* TODO:
+	sdp_data_t *pdl, *l;
+
+	exspec = sdp_data_get(rec, SDP_ATTR_PROTO_DESC_LIST);
+	if (exspec->dtd != SDP_SEQ8)
+		return FALSE;
+
+	for (l = pdl->val.dataseq; l; l = l->next) {
+		if (l->dtd != SDP_SEQ8)
+			continue;
+		epl = get_feature(epl, l->val.dataseq);
+	}
+	*/
+	if (psm)
+		*psm = 0x1001;
+	if (version)
+		*version = 0x0100;
+	return TRUE;
+}
+
 static gint cmp_feat_mdep(gconstpointer a, gconstpointer b)
 {
 	const struct hdp_supp_fts *fts = a;
diff --git a/health/hdp_util.h b/health/hdp_util.h
index 08e6471..03a7256 100644
--- a/health/hdp_util.h
+++ b/health/hdp_util.h
@@ -37,6 +37,8 @@ typedef void (*hdp_dbus_fill_up)(DBusMessageIter *iter, gpointer data);
 struct hdp_config *hdp_get_config(DBusMessageIter *iter, GError **err);
 gboolean hdp_register_sdp_record(struct hdp_instance *hdps);
 gboolean hdp_get_data_exchange_spec(const sdp_record_t *rec, guint8 *val);
+gboolean hdp_get_prot_desc_list(const sdp_record_t *rec, guint16 *psm,
+							guint16 *version);
 GSList *hdp_get_end_points(const sdp_record_t *rec);
 void hdp_instance_free(struct hdp_instance *hdpi);
 
-- 
1.6.3.3


  reply	other threads:[~2010-06-04  8:30 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-04  8:29 [PATCH 00/32] Health Device Prifile (HDP) -- updated Jose Antonio Santos Cadenas
2010-06-04  8:29 ` [PATCH 01/32] Add Health api description Jose Antonio Santos Cadenas
2010-06-04  8:29   ` [PATCH 02/32] Initial support for HDP Jose Antonio Santos Cadenas
2010-06-04  8:29     ` [PATCH 03/32] Add functions to resiger health instances in SDP Jose Antonio Santos Cadenas
2010-06-04  8:29       ` [PATCH 04/32] Initial support for hdp_device_drivers Jose Antonio Santos Cadenas
2010-06-04  8:29         ` [PATCH 05/32] Register healt_driver interfaces in d-bus Jose Antonio Santos Cadenas
2010-06-04  8:29           ` [PATCH 06/32] Add delete instance petition Jose Antonio Santos Cadenas
2010-06-04  8:30             ` [PATCH 07/32] Add watcher to control client disconections to delete hdp instance Jose Antonio Santos Cadenas
2010-06-04  8:30               ` [PATCH 08/32] Work in getting remote SDP records Jose Antonio Santos Cadenas
2010-06-04  8:30                 ` [PATCH 09/32] Adds functions to get remote suported features from its SDP record Jose Antonio Santos Cadenas
2010-06-04  8:30                   ` [PATCH 10/32] Insert end_point in array returned by get_health_instances Jose Antonio Santos Cadenas
2010-06-04  8:30                     ` [PATCH 11/32] Initial support for connecting instances Jose Antonio Santos Cadenas
2010-06-04  8:30                       ` [PATCH 12/32] Complete the response dictionary in GetHealthInstances response Jose Antonio Santos Cadenas
2010-06-04  8:30                         ` Jose Antonio Santos Cadenas [this message]
2010-06-04  8:30                           ` [PATCH 14/32] Manage mcap instances Jose Antonio Santos Cadenas
2010-06-04  8:30                             ` [PATCH 15/32] Implement connect MCL callback in health instances connection Jose Antonio Santos Cadenas
2010-06-04  8:30                               ` [PATCH 16/32] Register Health link int the bus when MCL is connected Jose Antonio Santos Cadenas
2010-06-04  8:30                                 ` [PATCH 17/32] Analize remote record looking for psm Jose Antonio Santos Cadenas
2010-06-04  8:30                                   ` [PATCH 18/32] Unify the creation of health links Jose Antonio Santos Cadenas
2010-06-04  8:30                                     ` [PATCH 19/32] Remove hdp_device pointer from health link struct Jose Antonio Santos Cadenas
2010-06-04  8:30                                       ` [PATCH 20/32] Release health link resources Jose Antonio Santos Cadenas
2010-06-04  8:30                                         ` [PATCH 21/32] Manage mcap disconnections and reconnections Jose Antonio Santos Cadenas
2010-06-04  8:30                                           ` [PATCH 22/32] Initial work for disconnecting health links Jose Antonio Santos Cadenas
2010-06-04  8:30                                             ` [PATCH 23/32] Avoid multiple links with the same device Jose Antonio Santos Cadenas
2010-06-04  8:30                                               ` [PATCH 24/32] Disconnect health link petition Jose Antonio Santos Cadenas
2010-06-04  8:30                                                 ` [PATCH 25/32] Create new structure to manage data channels in HDP Jose Antonio Santos Cadenas
2010-06-04  8:30                                                   ` [PATCH 26/32] Implement connect data channel callback Jose Antonio Santos Cadenas
2010-06-04  8:30                                                     ` [PATCH 27/32] Change function name when retreiving remote SDP records Jose Antonio Santos Cadenas
2010-06-04  8:30                                                       ` [PATCH 28/32] Changed HEALTH_MANAGER_INTERFACE to HEALTH_MANAGER Jose Antonio Santos Cadenas
2010-06-04  8:30                                                         ` [PATCH 29/32] Call the agent when a new Health Link is created Jose Antonio Santos Cadenas
2010-06-04  8:30                                                           ` [PATCH 30/32] Add a test that creates a simple health agent Jose Antonio Santos Cadenas
2010-06-04  8:30                                                             ` [PATCH 31/32] Send MCL disconnect callback to agents Jose Antonio Santos Cadenas
2010-06-04  8:30                                                               ` [PATCH 32/32] Add support for mcl reconnections Jose Antonio Santos Cadenas
  -- strict thread matches above, loose matches on Subject: below --
2010-06-02 13:18 [PATCH 00/32] Health device profile (HDP) Jose Antonio Santos Cadenas
2010-06-02 13:18 ` [PATCH 01/32] Add Health api description Jose Antonio Santos Cadenas
2010-06-02 13:18   ` [PATCH 02/32] Initial support for HDP Jose Antonio Santos Cadenas
2010-06-02 13:18     ` [PATCH 03/32] Add functions to resiger health instances in SDP Jose Antonio Santos Cadenas
2010-06-02 13:19       ` [PATCH 04/32] Initial support for hdp_device_drivers Jose Antonio Santos Cadenas
2010-06-02 13:19         ` [PATCH 05/32] Register healt_driver interfaces in d-bus Jose Antonio Santos Cadenas
2010-06-02 13:19           ` [PATCH 06/32] Add delete instance petition Jose Antonio Santos Cadenas
2010-06-02 13:19             ` [PATCH 07/32] Add watcher to control client disconections to delete hdp instance Jose Antonio Santos Cadenas
2010-06-02 13:19               ` [PATCH 08/32] Work in getting remote SDP records Jose Antonio Santos Cadenas
2010-06-02 13:19                 ` [PATCH 09/32] Adds functions to get remote suported features from its SDP record Jose Antonio Santos Cadenas
2010-06-02 13:19                   ` [PATCH 10/32] Insert end_point in array returned by get_health_instances Jose Antonio Santos Cadenas
2010-06-02 13:19                     ` [PATCH 11/32] Initial support for connecting instances Jose Antonio Santos Cadenas
2010-06-02 13:19                       ` [PATCH 12/32] Complete the response dictionary in GetHealthInstances response Jose Antonio Santos Cadenas
2010-06-02 13:19                         ` [PATCH 13/32] Implement connection of health instances Jose Antonio Santos Cadenas

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=1275640225-4186-14-git-send-email-santoscadenas@gmail.com \
    --to=santoscadenas@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).