Linux bluetooth development
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
Subject: [PATCH BlueZ 1/8] Add link_type information to the mgmt "Device Connected" event
Date: Fri, 19 Aug 2011 21:09:22 -0300	[thread overview]
Message-ID: <1313798969-8772-2-git-send-email-vinicius.gomes@openbossa.org> (raw)
In-Reply-To: <1313798969-8772-1-git-send-email-vinicius.gomes@openbossa.org>

In the case of incomming connections we have to know the type of
the device that connected to us.

Through hciops we have the LE Connection Complete event, that
information was lost when Management interface was being used.

The documentation is updated to reflect this.
---
 doc/mgmt-api.txt  |    1 +
 lib/hci.h         |    2 ++
 lib/mgmt.h        |    1 +
 plugins/hciops.c  |    4 ++--
 plugins/mgmtops.c |    2 +-
 src/event.c       |    5 ++++-
 src/event.h       |    2 +-
 tools/hcitool.c   |    3 ---
 8 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index 127af94..e700366 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -498,6 +498,7 @@ Device Connected Event
 Event Code		0x000B
 Controller Index:	<controller id>
 Event Parameters	Address (6 Octets)
+			Link Type (1 Octet)
 
 Device Disconnected Event
 =========================
diff --git a/lib/hci.h b/lib/hci.h
index d6f79f2..451e134 100644
--- a/lib/hci.h
+++ b/lib/hci.h
@@ -212,6 +212,8 @@ enum {
 #define SCO_LINK	0x00
 #define ACL_LINK	0x01
 #define ESCO_LINK	0x02
+/* Low Energy links do not have defined link type. Use invented one */
+#define LE_LINK		0x80
 
 /* LMP features */
 #define LMP_3SLOT	0x01
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 0c52850..b0c2a5e 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -282,6 +282,7 @@ struct mgmt_ev_new_key {
 #define MGMT_EV_DEVICE_CONNECTED	0x000B
 struct mgmt_ev_device_connected {
 	bdaddr_t bdaddr;
+	uint8_t link_type;
 } __packed;
 
 #define MGMT_EV_DEVICE_DISCONNECTED	0x000C
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 03eec82..5d7b0db 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2060,7 +2060,7 @@ static inline void conn_complete(int index, void *ptr)
 	conn = get_connection(dev, &evt->bdaddr);
 	conn->handle = btohs(evt->handle);
 
-	btd_event_conn_complete(&dev->bdaddr, &evt->bdaddr);
+	btd_event_conn_complete(&dev->bdaddr, &evt->bdaddr, evt->link_type);
 
 	if (conn->secmode3)
 		bonding_complete(dev, conn, 0);
@@ -2096,7 +2096,7 @@ static inline void le_conn_complete(int index, void *ptr)
 	conn = get_connection(dev, &evt->peer_bdaddr);
 	conn->handle = btohs(evt->handle);
 
-	btd_event_conn_complete(&dev->bdaddr, &evt->peer_bdaddr);
+	btd_event_conn_complete(&dev->bdaddr, &evt->peer_bdaddr, LE_LINK);
 
 	/* check if the remote version needs be requested */
 	ba2str(&dev->bdaddr, local_addr);
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 3fd1b3f..e6f5a4f 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -436,7 +436,7 @@ static void mgmt_device_connected(int sk, uint16_t index, void *buf, size_t len)
 
 	info = &controllers[index];
 
-	btd_event_conn_complete(&info->bdaddr, &ev->bdaddr);
+	btd_event_conn_complete(&info->bdaddr, &ev->bdaddr, ev->link_type);
 }
 
 static void mgmt_device_disconnected(int sk, uint16_t index, void *buf,
diff --git a/src/event.c b/src/event.c
index ade882e..6d276f4 100644
--- a/src/event.c
+++ b/src/event.c
@@ -466,7 +466,7 @@ int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t *key,
 	return ret;
 }
 
-void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer)
+void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t link_type)
 {
 	struct btd_adapter *adapter;
 	struct btd_device *device;
@@ -476,6 +476,9 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer)
 
 	update_lastused(local, peer);
 
+	if (link_type == LE_LINK)
+		device_set_type(device, DEVICE_TYPE_LE);
+
 	adapter_add_connection(adapter, device);
 }
 
diff --git a/src/event.h b/src/event.h
index 5047db1..3dd25f1 100644
--- a/src/event.h
+++ b/src/event.h
@@ -28,7 +28,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
 void btd_event_remote_class(bdaddr_t *local, bdaddr_t *peer, uint32_t class);
 void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char *name);
-void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer);
+void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t link_type);
 void btd_event_conn_failed(bdaddr_t *local, bdaddr_t *peer, uint8_t status);
 void btd_event_disconn_complete(bdaddr_t *local, bdaddr_t *peer);
 void btd_event_bonding_complete(bdaddr_t *local, bdaddr_t *peer,
diff --git a/tools/hcitool.c b/tools/hcitool.c
index ece187c..dd13ced 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -46,9 +46,6 @@
 #include "textfile.h"
 #include "oui.h"
 
-/* Unofficial value, might still change */
-#define LE_LINK		0x03
-
 #define FLAGS_AD_TYPE 0x01
 #define FLAGS_LIMITED_MODE_BIT 0x01
 #define FLAGS_GENERAL_MODE_BIT 0x02
-- 
1.7.6


  reply	other threads:[~2011-08-20  0:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-20  0:09 [PATCH BlueZ 0/8] Proper support for pairing LE devices Vinicius Costa Gomes
2011-08-20  0:09 ` Vinicius Costa Gomes [this message]
2011-08-31  7:51   ` [PATCH BlueZ 1/8] Add link_type information to the mgmt "Device Connected" event Johan Hedberg
2011-08-31 11:25     ` Luiz Augusto von Dentz
2011-08-31 12:27       ` Johan Hedberg
2011-08-20  0:09 ` [PATCH BlueZ 2/8] Fix doing SDP service discovery for LE devices Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 3/8] Set the Paired property of a device when restoring from storage Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 4/8] Fix not using the same way for pairing LE devices Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 5/8] Fix not using the "bonded" property for new bondings Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 6/8] Fix connecting to the local adapter when receiving new keys Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 7/8] Remove the default security level from btio Vinicius Costa Gomes
2011-08-20  0:09 ` [PATCH BlueZ 8/8] Fix btio users to not expect a default security level Vinicius Costa Gomes

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=1313798969-8772-2-git-send-email-vinicius.gomes@openbossa.org \
    --to=vinicius.gomes@openbossa.org \
    --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