From: Szymon Janc <szymon.janc@tieto.com>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@tieto.com>
Subject: [PATCH v2 3/5] android/gatt: Choose LE or BR/EDR based on last seen bearer
Date: Thu, 10 Jul 2014 16:30:34 +0200 [thread overview]
Message-ID: <1405002636-10737-3-git-send-email-szymon.janc@tieto.com> (raw)
In-Reply-To: <1405002636-10737-1-git-send-email-szymon.janc@tieto.com>
This allows to connect both over LE and BR/EDR bearer.
---
android/gatt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/android/gatt.c b/android/gatt.c
index e07226c..6f04439 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1702,6 +1702,49 @@ static void app_disconnect_devices(struct gatt_app *client)
}
}
+static int connect_bredr(struct gatt_device *dev)
+{
+ BtIOSecLevel sec_level;
+ GIOChannel *io;
+ GError *gerr = NULL;
+ char addr[18];
+
+ ba2str(&dev->bdaddr, addr);
+
+ /* There is one connection attempt going on */
+ if (dev->att_io) {
+ info("gatt: connection to dev %s is ongoing", addr);
+ return -EALREADY;
+ }
+
+ DBG("Connection attempt to: %s", addr);
+
+ sec_level = bt_device_is_bonded(&dev->bdaddr) ? BT_IO_SEC_MEDIUM :
+ BT_IO_SEC_LOW;
+
+ io = bt_io_connect(connect_cb, device_ref(dev), NULL, &gerr,
+ BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
+ BT_IO_OPT_SOURCE_TYPE, BDADDR_BREDR,
+ BT_IO_OPT_DEST_BDADDR, &dev->bdaddr,
+ BT_IO_OPT_DEST_TYPE, BDADDR_BREDR,
+ BT_IO_OPT_PSM, ATT_PSM,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
+ BT_IO_OPT_INVALID);
+ if (!io) {
+ error("gatt: Failed bt_io_connect(%s): %s", addr,
+ gerr->message);
+ g_error_free(gerr);
+ return -EIO;
+ }
+
+ device_set_state(dev, DEVICE_CONNECT_READY);
+
+ /* Keep this, so we can cancel the connection */
+ dev->att_io = io;
+
+ return 0;
+}
+
static bool trigger_connection(struct app_connection *connection)
{
switch (connection->device->state) {
@@ -1715,6 +1758,11 @@ static bool trigger_connection(struct app_connection *connection)
break;
}
+ /* If device was last seen over BR/EDR connect over it */
+ if (bt_device_last_seen_bearer(&connection->device->bdaddr) ==
+ BDADDR_BREDR)
+ return connect_bredr(connection->device) == 0;
+
/* after state change trigger discovering */
if (!scanning && (connection->device->state == DEVICE_CONNECT_INIT))
if (!bt_le_discovery_start()) {
--
1.9.1
next prev parent reply other threads:[~2014-07-10 14:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-10 14:30 [PATCH v2 1/5] android/gatt: Add support for GATT over BR/EDR Szymon Janc
2014-07-10 14:30 ` [PATCH v2 2/5] android/bluetooth: Add function for checking last seen bearer Szymon Janc
2014-07-10 14:30 ` Szymon Janc [this message]
2014-07-10 14:30 ` [PATCH v2 4/5] shared/gatt: Add function for getting service UUID Szymon Janc
2014-07-10 14:30 ` [PATCH v2 5/5] android/gatt: Register SDP records for services Szymon Janc
2014-07-11 20:10 ` [PATCH v2 1/5] android/gatt: Add support for GATT over BR/EDR Szymon Janc
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=1405002636-10737-3-git-send-email-szymon.janc@tieto.com \
--to=szymon.janc@tieto.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