* [PATCH 1/2] android/ipc: Zero initialize cmsg buffer
From: Andrei Emeltchenko @ 2013-11-21 14:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This fixes valgrind warnings:
...
Syscall param sendmsg(msg.msg_control) points to uninitialised byte(s)
...
---
android/ipc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/ipc.c b/android/ipc.c
index 2fa90bd..4044d4d 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -47,6 +47,7 @@ void ipc_send(int sk, uint8_t service_id, uint8_t opcode, uint16_t len,
memset(&msg, 0, sizeof(msg));
memset(&m, 0, sizeof(m));
+ memset(cmsgbuf, 0, sizeof(cmsgbuf));
m.service_id = service_id;
m.opcode = opcode;
--
1.8.3.2
^ permalink raw reply related
* Re: BUG??
From: Bruno Bruzzano @ 2013-11-21 14:17 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CACA6DsVt_Q38k6CGP5=9iUCRSPU9sP4hTogs97Po6_Mi-oUBfg@mail.gmail.com>
Hi Luiz,
I did as you suggested, disabling temporarily the SELinux.
Unfortunally the result is the same. Here I made a pastebin which
shows the last part of the connection and the fail.
http://pastebin.com/K4QKCHgN
Let me know. Thanks!.
Best Regards,
Bruno Bruzzano
On Thu, Nov 21, 2013 at 9:07 AM, Bruno Bruzzano <brunano21@gmail.com> wrote:
> Hi Luiz,
>
> I did as you suggested, disabling temporarily the SELinux.
> Unfortunally the result is the same. Here I made a pastebin which
> shows the last part of the connection and the fail.
>
> Let me know. Thanks!.
> Best Regards,
> Bruno Bruzzano
>
> On Thu, Nov 21, 2013 at 7:02 AM, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
>> Hi Bruno,
>>
>> On Thu, Nov 21, 2013 at 12:18 AM, Bruno Bruzzano <brunano21@gmail.com> wrote:
>>> Hi all,
>>>
>>> Maybe I encountered a bug. I'm using git version of Bluez5 on Fedora
>>> 20 beta and all crash when I try to connect to a generic profile. In
>>> particular, the steps to reproduce it are the following:
>>> - start bluetooth daemon (with -ndE args)
>>> - using bluetoothctl (in client folder):
>>> -- agent on
>>> -- scan on
>>> -- wait to discovery my android device
>>> -- scan off
>>> -- pair maddr -> pair complete!
>>>
>>> After that I try to connect using AVRCP profile. It works.
>>> The problem appears when a tap on my smartphone's player. Bluetoothd crashes!!
>>>
>>> Here, you can find some pastebins.
>>> bluetoothd -> http://pastebin.com/ZSER2Df6
>>> bluetoothctl -> http://pastebin.com/rexVrruB
>>>
>>> I hope someone can give me a feedback or a
>>> tip!
>>
>> Give the following message I believe there is something wrong with the
>> D-Bus conf file:
>>
>> bluetoothd[2009]: src/agent.c:simple_agent_reply() agent error reply:
>> org.freedesktop.DBus.Error.NoReply, Message did not receive a reply
>> (timeout by message bus)
>> bluetoothd[2009]: Access denied: Message did not receive a reply
>> (timeout by message bus)
>>
>> Also it is quite possible that bluetoothd is being disconnected from
>> D-Bus due to SELinux policy, you can try disabling it and see if that
>> works, if it does then we need to let the fedora folks know so they
>> add a proper rule for it.
>>
>>
>> --
>> Luiz Augusto von Dentz
^ permalink raw reply
* Re: BUG??
From: Bruno Bruzzano @ 2013-11-21 14:07 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZJN7b3aQAUPw=Lx0SSooW20Dkyan1OL-MZTw4xaSQpQgw@mail.gmail.com>
Hi Luiz,
I did as you suggested, disabling temporarily the SELinux.
Unfortunally the result is the same. Here I made a pastebin which
shows the last part of the connection and the fail.
Let me know. Thanks!.
Best Regards,
Bruno Bruzzano
On Thu, Nov 21, 2013 at 7:02 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Bruno,
>
> On Thu, Nov 21, 2013 at 12:18 AM, Bruno Bruzzano <brunano21@gmail.com> wrote:
>> Hi all,
>>
>> Maybe I encountered a bug. I'm using git version of Bluez5 on Fedora
>> 20 beta and all crash when I try to connect to a generic profile. In
>> particular, the steps to reproduce it are the following:
>> - start bluetooth daemon (with -ndE args)
>> - using bluetoothctl (in client folder):
>> -- agent on
>> -- scan on
>> -- wait to discovery my android device
>> -- scan off
>> -- pair maddr -> pair complete!
>>
>> After that I try to connect using AVRCP profile. It works.
>> The problem appears when a tap on my smartphone's player. Bluetoothd crashes!!
>>
>> Here, you can find some pastebins.
>> bluetoothd -> http://pastebin.com/ZSER2Df6
>> bluetoothctl -> http://pastebin.com/rexVrruB
>>
>> I hope someone can give me a feedback or a
>> tip!
>
> Give the following message I believe there is something wrong with the
> D-Bus conf file:
>
> bluetoothd[2009]: src/agent.c:simple_agent_reply() agent error reply:
> org.freedesktop.DBus.Error.NoReply, Message did not receive a reply
> (timeout by message bus)
> bluetoothd[2009]: Access denied: Message did not receive a reply
> (timeout by message bus)
>
> Also it is quite possible that bluetoothd is being disconnected from
> D-Bus due to SELinux policy, you can try disabling it and see if that
> works, if it does then we need to let the fedora folks know so they
> add a proper rule for it.
>
>
> --
> Luiz Augusto von Dentz
^ permalink raw reply
* Re: BUG??
From: Luiz Augusto von Dentz @ 2013-11-21 12:02 UTC (permalink / raw)
To: Bruno Bruzzano; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CACA6DsU+5gp_diykBarJhmJ_WTLwVZc==CbPOVRKfkHdEtBY0w@mail.gmail.com>
Hi Bruno,
On Thu, Nov 21, 2013 at 12:18 AM, Bruno Bruzzano <brunano21@gmail.com> wrote:
> Hi all,
>
> Maybe I encountered a bug. I'm using git version of Bluez5 on Fedora
> 20 beta and all crash when I try to connect to a generic profile. In
> particular, the steps to reproduce it are the following:
> - start bluetooth daemon (with -ndE args)
> - using bluetoothctl (in client folder):
> -- agent on
> -- scan on
> -- wait to discovery my android device
> -- scan off
> -- pair maddr -> pair complete!
>
> After that I try to connect using AVRCP profile. It works.
> The problem appears when a tap on my smartphone's player. Bluetoothd crashes!!
>
> Here, you can find some pastebins.
> bluetoothd -> http://pastebin.com/ZSER2Df6
> bluetoothctl -> http://pastebin.com/rexVrruB
>
> I hope someone can give me a feedback or a
> tip!
Give the following message I believe there is something wrong with the
D-Bus conf file:
bluetoothd[2009]: src/agent.c:simple_agent_reply() agent error reply:
org.freedesktop.DBus.Error.NoReply, Message did not receive a reply
(timeout by message bus)
bluetoothd[2009]: Access denied: Message did not receive a reply
(timeout by message bus)
Also it is quite possible that bluetoothd is being disconnected from
D-Bus due to SELinux policy, you can try disabling it and see if that
works, if it does then we need to let the fedora folks know so they
add a proper rule for it.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH BlueZ] android/a2dp: Cleanup devices on unregister
From: Johan Hedberg @ 2013-11-21 8:16 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1384940394-24668-1-git-send-email-luiz.dentz@gmail.com>
Hi Luiz,
On Wed, Nov 20, 2013, Luiz Augusto von Dentz wrote:
> This cleanup any existing devices in bt_a2dp_unregister
> ---
> android/a2dp.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply
* BUG??
From: Bruno Bruzzano @ 2013-11-20 22:18 UTC (permalink / raw)
To: linux-bluetooth
Hi all,
Maybe I encountered a bug. I'm using git version of Bluez5 on Fedora
20 beta and all crash when I try to connect to a generic profile. In
particular, the steps to reproduce it are the following:
- start bluetooth daemon (with -ndE args)
- using bluetoothctl (in client folder):
-- agent on
-- scan on
-- wait to discovery my android device
-- scan off
-- pair maddr -> pair complete!
After that I try to connect using AVRCP profile. It works.
The problem appears when a tap on my smartphone's player. Bluetoothd crashes!!
Here, you can find some pastebins.
bluetoothd -> http://pastebin.com/ZSER2Df6
bluetoothctl -> http://pastebin.com/rexVrruB
I hope someone can give me a feedback or a
tip!
Thanks in advance
^ permalink raw reply
* [RFC v3 12/12] Bluetooth: Add le_auto_conn file on debugfs
From: Andre Guedes @ 2013-11-20 22:09 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch adds to debugfs the le_auto_conn file. This file will be
used to test LE auto connection infrastructure.
To add a new auto connection address we write on le_auto_conn file
following the format <address> <address type> <auto_connect>.
The <address type> values are:
* 0 for public address
* 1 for random address
The <auto_connect> values are (for more details see struct hci_
conn_params):
* 0 for disabled
* 1 for always
* 2 for link loss
So for instance, if you want the kernel autonomously establishes
connections with device AA:BB:CC:DD:EE:FF (public address) every
time the device enters in connectable mode (starts advertising),
you should run the command:
$ echo "AA:BB:CC:DD:EE:FF 0 1" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
To get the list of connection parameters configured in kernel, read
the le_auto_conn file:
$ cat /sys/kernel/debug/bluetooth/hci0/le_auto_conn
Finally, to clear the connection parameters list, write an empty
string:
$ echo "" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
This file is created only if LE is enabled.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_core.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index beb51ce..be7da12 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -636,6 +636,89 @@ static int conn_max_interval_get(void *data, u64 *val)
DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
conn_max_interval_set, "%llu\n");
+static int le_auto_conn_show(struct seq_file *sf, void *ptr)
+{
+ struct hci_dev *hdev = sf->private;
+ struct hci_conn_params *p;
+
+ hci_dev_lock(hdev);
+
+ list_for_each_entry(p, &hdev->le_conn_params, list) {
+ seq_printf(sf, "%pMR %u %u\n", &p->addr, p->addr_type,
+ p->auto_connect);
+ }
+
+ hci_dev_unlock(hdev);
+
+ return 0;
+}
+
+static int le_auto_conn_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, le_auto_conn_show, inode->i_private);
+}
+
+static ssize_t le_auto_conn_write(struct file *file, const char __user *data,
+ size_t count, loff_t *offset)
+{
+ struct seq_file *sf = file->private_data;
+ struct hci_dev *hdev = sf->private;
+ u8 auto_connect;
+ bdaddr_t addr;
+ u8 addr_type;
+ char *buf;
+ int n;
+
+ /* Don't allow partial write */
+ if (*offset != 0)
+ return -EINVAL;
+
+ /* If empty string, clear the connection parameters and pending LE
+ * connection list.
+ */
+ if (count == 1) {
+ hci_dev_lock(hdev);
+ hci_conn_params_clear(hdev);
+ hci_pend_le_conns_clear(hdev);
+ hci_dev_unlock(hdev);
+ return count;
+ }
+
+ buf = kzalloc(count, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ if (copy_from_user(buf, data, count)) {
+ kfree(buf);
+ return -EFAULT;
+ }
+
+ n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu %hhu", &addr.b[5],
+ &addr.b[4], &addr.b[3], &addr.b[2], &addr.b[1], &addr.b[0],
+ &addr_type, &auto_connect);
+ if (n != 8) {
+ kfree(buf);
+ return -EINVAL;
+ }
+
+ hci_dev_lock(hdev);
+ hci_conn_params_add(hdev, &addr, addr_type, auto_connect,
+ hdev->le_conn_min_interval,
+ hdev->le_conn_max_interval);
+ hci_dev_unlock(hdev);
+
+ kfree(buf);
+ return count;
+}
+
+static const struct file_operations le_auto_conn_fops = {
+ .open = le_auto_conn_open,
+ .read = seq_read,
+ .write = le_auto_conn_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/* ---- HCI requests ---- */
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result)
@@ -1406,6 +1489,8 @@ static int __hci_init(struct hci_dev *hdev)
hdev, &conn_min_interval_fops);
debugfs_create_file("conn_max_interval", 0644, hdev->debugfs,
hdev, &conn_max_interval_fops);
+ debugfs_create_file("le_auto_conn", 0644, hdev->debugfs, hdev,
+ &le_auto_conn_fops);
}
return 0;
--
1.8.4
^ permalink raw reply related
* [RFC v3 11/12] Bleutooth: Add support for auto connect options
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch adds support for the HCI_AUTO_CONN_ALWAYS and HCI_AUTO_
CONN_LINK_LOSS options from struct hci_conn_params.
The HCI_AUTO_CONN_ALWAYS option configures the kernel to always re-
establish the connection, no matter the reason the connection was
terminated. This feature is required by some LE profiles such as
HID over GATT, Health Thermometer and Blood Pressure. These profiles
require the host autonomously connect to the device as soon as it
enters in connectable mode (start advertising) so the device is able
to delivery notifications or indications.
The BT_AUTO_CONN_LINK_LOSS option configures the kernel to re-
establish the connection in case the connection was terminated due
to a link loss. This feature is required by the majority of LE
profiles such as Proximity, Find Me, Cycling Speed and Cadence and
Time.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_event.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index e4f288a..a4ce922 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1780,6 +1780,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_ev_disconn_complete *ev = (void *) skb->data;
u8 reason = hci_to_mgmt_reason(ev->reason);
+ struct hci_conn_params *params;
struct hci_conn *conn;
u8 type;
@@ -1806,6 +1807,23 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (conn->type == ACL_LINK && conn->flush_key)
hci_remove_link_key(hdev, &conn->dst);
+ params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
+ if (params) {
+ switch (params->auto_connect) {
+ case HCI_AUTO_CONN_LINK_LOSS:
+ if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT)
+ break;
+ /* Fall through */
+
+ case HCI_AUTO_CONN_ALWAYS:
+ hci_pend_le_conn_add(hdev, &conn->dst, conn->dst_type);
+ break;
+
+ default:
+ break;
+ }
+ }
+
type = conn->type;
hci_proto_disconn_cfm(conn, ev->reason);
--
1.8.4
^ permalink raw reply related
* [RFC v3 10/12] Bluetooth: Auto connection and power on
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
When hdev is closed (e.g. Mgmt power off command, RFKILL or controller
is reset), the ongoing active connections are silently dropped by the
controller (no Disconnection Complete Event is sent to host). For that
reason, the devices that require HCI_AUTO_CONN_ALWAYS are not added to
hdev->pend_le_conns list and they won't auto connect.
So to fix this issue, during hdev closing, we remove all pending LE
connections. After adapter is powered on, we add a pending LE connection
for each HCI_AUTO_CONN_ALWAYS address.
This way, the auto connection mechanism works propely after a power
off and power on sequence as well as RFKILL block/unblock.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_core.c | 1 +
net/bluetooth/mgmt.c | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 5bb73cf..beb51ce 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1969,6 +1969,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
hci_dev_lock(hdev);
hci_inquiry_cache_flush(hdev);
hci_conn_hash_flush(hdev);
+ hci_pend_le_conns_clear(hdev);
hci_dev_unlock(hdev);
hci_notify(hdev, HCI_DEV_DOWN);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 81b8cfa..3fccb52 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4247,6 +4247,17 @@ void mgmt_index_removed(struct hci_dev *hdev)
mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL);
}
+/* This function requires the caller holds hdev->lock */
+static void restart_le_auto_conns(struct hci_dev *hdev)
+{
+ struct hci_conn_params *p;
+
+ list_for_each_entry(p, &hdev->le_conn_params, list) {
+ if (p->auto_connect == HCI_AUTO_CONN_ALWAYS)
+ hci_pend_le_conn_add(hdev, &p->addr, p->addr_type);
+ }
+}
+
static void powered_complete(struct hci_dev *hdev, u8 status)
{
struct cmd_lookup match = { NULL, hdev };
@@ -4255,6 +4266,8 @@ static void powered_complete(struct hci_dev *hdev, u8 status)
hci_dev_lock(hdev);
+ restart_le_auto_conns(hdev);
+
mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match);
new_settings(hdev, match.sk);
--
1.8.4
^ permalink raw reply related
* [RFC v3 09/12] Bluetooth: Temporarily stop background scanning on discovery
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
If the user send a mgmt start discovery command while the background
scanning is running, we should temporarily stop it. Once the discovery
finishes, we start the background scanning again.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_core.c | 2 ++
net/bluetooth/mgmt.c | 12 ++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 47d31bd..5bb73cf 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1498,6 +1498,8 @@ void hci_discovery_set_state(struct hci_dev *hdev, int state)
switch (state) {
case DISCOVERY_STOPPED:
+ hci_update_background_scan(hdev);
+
if (hdev->discovery.state != DISCOVERY_STARTING)
mgmt_discovering(hdev, 0);
break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index a03ca3c..81b8cfa 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3280,11 +3280,15 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
goto failed;
}
+ /* If controller is scanning, it means the background scanning
+ * is running. Thus, we should temporarily stop it in order to
+ * set the discovery scanning parameters.
+ */
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
- err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
- MGMT_STATUS_BUSY);
- mgmt_pending_remove(cmd);
- goto failed;
+ memset(&enable_cp, 0, sizeof(enable_cp));
+ enable_cp.enable = LE_SCAN_DISABLE;
+ hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE,
+ sizeof(enable_cp), &enable_cp);
}
memset(¶m_cp, 0, sizeof(param_cp));
--
1.8.4
^ permalink raw reply related
* [RFC v3 08/12] Bluetooth: Re-enable background scan in case of error
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
Since we temporarily stop the background scanning in favor of
connection, we should re-enable it in case something goes wrong
with connection establishment. So this patch adds a hci_update_
background_scan() call in create_le_conn_complete() and hci_le_
conn_complete_evt() error flow.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_conn.c | 2 ++
net/bluetooth/hci_event.c | 1 +
2 files changed, 3 insertions(+)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 750a39d..2ca34fa 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -548,6 +548,8 @@ static void create_le_conn_complete(struct hci_dev *hdev, u8 status)
hci_conn_del(conn);
+ hci_update_background_scan(hdev);
+
done:
hci_dev_unlock(hdev);
}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 60ca708..e4f288a 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3522,6 +3522,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_proto_connect_cfm(conn, ev->status);
conn->state = BT_CLOSED;
hci_conn_del(conn);
+ hci_update_background_scan(hdev);
goto unlock;
}
--
1.8.4
^ permalink raw reply related
* [RFC v3 07/12] Bluetooth: Introduce LE auto connection infrastructure
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch introduces the LE auto connection infrastructure.
This infrastructure will be used to implement the auto_connect
options from hci_conn_params.
In summary, the auto connection mechanism works as follows: Once the
first pending LE connection is created, the background scanning is
started. When the target device is found in range, the kernel
autonomously starts the connection attempt. If connection is
established successfully, that pending LE connection is deleted and
the background is stopped.
To achieve that, this patch introduces the hci_update_background_scan()
which controls the background scanning state. This function starts or
stops the background scanning based on the hdev->pend_le_conns list. If
there is no pending LE connection, the background scanning is stopped.
Otherwise, we start the background scanning.
Then, every time a pending LE connection is added we call hci_update_
background_scan() so the background scanning is started (in case it is
not already running). Likewise, every time a pending LE connection is
deleted we call hci_update_background_scan() so the background scanning
is stopped (in case this was the last pending LE connection) or it is
started again (in case we have more pending LE connections). This way
the background scanning keeps running until all pending LE connection
are established.
When a device with pending connection is in range, we establish the
connection and delete the pending connection.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci_core.h | 2 +
net/bluetooth/hci_core.c | 86 +++++++++++++++++++++++++++++++++++++++-
net/bluetooth/hci_event.c | 41 +++++++++++++++++++
3 files changed, 127 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 490eae2..f8fa990 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -772,6 +772,8 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
void hci_pend_le_conns_clear(struct hci_dev *hdev);
+void hci_update_background_scan(struct hci_dev *hdev);
+
int hci_uuids_clear(struct hci_dev *hdev);
int hci_link_keys_clear(struct hci_dev *hdev);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 05e6073..47d31bd 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2873,7 +2873,7 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
if (entry)
- return;
+ goto done;
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
if (!entry) {
@@ -2887,6 +2887,9 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
list_add(&entry->list, &hdev->pend_le_conns);
BT_DBG("addr %pMR (type %u)", addr, addr_type);
+
+done:
+ hci_update_background_scan(hdev);
}
/* This function requires the caller holds hdev->lock */
@@ -2896,12 +2899,15 @@ void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
if (!entry)
- return;
+ goto done;
list_del(&entry->list);
kfree(entry);
BT_DBG("addr %pMR (type %u)", addr, addr_type);
+
+done:
+ hci_update_background_scan(hdev);
}
/* This function requires the caller holds hdev->lock */
@@ -4443,3 +4449,79 @@ static void hci_cmd_work(struct work_struct *work)
}
}
}
+
+static void update_background_scan_complete(struct hci_dev *hdev, u8 status)
+{
+ if (status)
+ BT_DBG("HCI request failed to update background scanning: "
+ "status 0x%2.2x", status);
+}
+
+/* This function controls the background scanning based on hdev->pend_le_conns
+ * list. If there are pending LE connection we start the background scanning,
+ * otherwise we stop it.
+ *
+ * This function requires the caller holds hdev->lock.
+ */
+void hci_update_background_scan(struct hci_dev *hdev)
+{
+ struct hci_cp_le_set_scan_param param_cp;
+ struct hci_cp_le_set_scan_enable enable_cp;
+ struct hci_request req;
+ struct hci_conn *conn;
+ int err;
+
+ hci_req_init(&req, hdev);
+
+ if (list_empty(&hdev->pend_le_conns)) {
+ /* If there is no pending LE connections, we should stop
+ * the background scanning.
+ */
+
+ /* If controller is not scanning we are done. */
+ if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags))
+ return;
+
+ memset(&enable_cp, 0, sizeof(enable_cp));
+ enable_cp.enable = LE_SCAN_DISABLE;
+ hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
+ &enable_cp);
+
+ BT_DBG("%s stopping background scanning", hdev->name);
+ } else {
+ /* If there is at least one pending LE connection, we should
+ * keep the background scan running.
+ */
+
+ /* If controller is already scanning we are done. */
+ if (test_bit(HCI_LE_SCAN, &hdev->dev_flags))
+ return;
+
+ /* If controller is connecting, we should not start scanning
+ * since some controllers are not able to scan and connect at
+ * the same time.
+ */
+ conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
+ if (conn)
+ return;
+
+ memset(¶m_cp, 0, sizeof(param_cp));
+ param_cp.type = LE_SCAN_PASSIVE;
+ param_cp.interval = cpu_to_le16(hdev->le_scan_interval);
+ param_cp.window = cpu_to_le16(hdev->le_scan_window);
+ hci_req_add(&req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
+ ¶m_cp);
+
+ memset(&enable_cp, 0, sizeof(enable_cp));
+ enable_cp.enable = LE_SCAN_ENABLE;
+ enable_cp.filter_dup = LE_SCAN_FILTER_DUP_DISABLE;
+ hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
+ &enable_cp);
+
+ BT_DBG("%s starting background scanning", hdev->name);
+ }
+
+ err = hci_req_run(&req, update_background_scan_complete);
+ if (err)
+ BT_ERR("Failed to run HCI request: err %d", err);
+}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5fb3df6..60ca708 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3537,25 +3537,66 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_proto_connect_cfm(conn, ev->status);
+ hci_pend_le_conn_del(hdev, &ev->bdaddr, ev->bdaddr_type);
+
unlock:
hci_dev_unlock(hdev);
}
+/* This function requires the caller holds hdev->lock */
+static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
+ u8 addr_type)
+{
+ struct hci_conn *conn;
+ u8 bdaddr_type;
+
+ if (!hci_pend_le_conn_lookup(hdev, addr, addr_type))
+ return;
+
+ if (addr_type == ADDR_LE_DEV_PUBLIC)
+ bdaddr_type = BDADDR_LE_PUBLIC;
+ else
+ bdaddr_type = BDADDR_LE_RANDOM;
+
+ conn = hci_connect(hdev, LE_LINK, addr, bdaddr_type, BT_SECURITY_LOW,
+ HCI_AT_NO_BONDING);
+ if (!IS_ERR(conn))
+ return;
+
+ switch (PTR_ERR(conn)) {
+ case -EBUSY:
+ /* If hci_connect() returns -EBUSY it means there is already
+ * an LE connection attempt going on. Since controllers don't
+ * support more than one connection attempt at the time, we
+ * don't consider this an error case.
+ */
+ break;
+ default:
+ BT_ERR("Failed to connect: err %ld", PTR_ERR(conn));
+ }
+}
+
static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
{
u8 num_reports = skb->data[0];
void *ptr = &skb->data[1];
s8 rssi;
+ hci_dev_lock(hdev);
+
while (num_reports--) {
struct hci_ev_le_advertising_info *ev = ptr;
+ check_pending_le_conn(hdev, &ev->bdaddr, ev->bdaddr_type);
+
rssi = ev->data[ev->length];
mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type,
NULL, rssi, 0, 1, ev->data, ev->length);
ptr += sizeof(*ev) + ev->length + 1;
}
+
+ hci_dev_unlock(hdev);
}
static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
--
1.8.4
^ permalink raw reply related
* [RFC v3 06/12] Bluetooth: Introduce hdev->pend_le_conn list
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch introduces the hdev->pend_le_conn list which holds the
device addresses the kernel should autonomously connect. It also
introduces some helper functions to manipulate the list.
The list and helper functions will be used by the next patch which
implements the LE auto connection infrastructure.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci_core.h | 7 +++++
net/bluetooth/hci_core.c | 68 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index bdda971..490eae2 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -268,6 +268,7 @@ struct hci_dev {
struct list_head long_term_keys;
struct list_head remote_oob_data;
struct list_head le_conn_params;
+ struct list_head pend_le_conns;
struct hci_dev_stats stat;
@@ -765,6 +766,12 @@ void hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
void hci_conn_params_clear(struct hci_dev *hdev);
+struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type);
+void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
+void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
+void hci_pend_le_conns_clear(struct hci_dev *hdev);
+
int hci_uuids_clear(struct hci_dev *hdev);
int hci_link_keys_clear(struct hci_dev *hdev);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index dd9a25c..05e6073 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2851,6 +2851,72 @@ void hci_conn_params_clear(struct hci_dev *hdev)
BT_DBG("All LE connection parameters were removed");
}
+/* This function requires the caller holds hdev->lock */
+struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type)
+{
+ struct bdaddr_list *entry;
+
+ list_for_each_entry(entry, &hdev->pend_le_conns, list) {
+ if (bacmp(&entry->bdaddr, addr) == 0 &&
+ entry->bdaddr_type == addr_type)
+ return entry;
+ }
+
+ return NULL;
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
+{
+ struct bdaddr_list *entry;
+
+ entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
+ if (entry)
+ return;
+
+ entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ if (!entry) {
+ BT_ERR("Out of memory");
+ return;
+ }
+
+ bacpy(&entry->bdaddr, addr);
+ entry->bdaddr_type = addr_type;
+
+ list_add(&entry->list, &hdev->pend_le_conns);
+
+ BT_DBG("addr %pMR (type %u)", addr, addr_type);
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
+{
+ struct bdaddr_list *entry;
+
+ entry = hci_pend_le_conn_lookup(hdev, addr, addr_type);
+ if (!entry)
+ return;
+
+ list_del(&entry->list);
+ kfree(entry);
+
+ BT_DBG("addr %pMR (type %u)", addr, addr_type);
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_pend_le_conns_clear(struct hci_dev *hdev)
+{
+ struct bdaddr_list *entry, *tmp;
+
+ list_for_each_entry_safe(entry, tmp, &hdev->pend_le_conns, list) {
+ list_del(&entry->list);
+ kfree(entry);
+ }
+
+ BT_DBG("All LE pending connections cleared");
+}
+
static void inquiry_complete(struct hci_dev *hdev, u8 status)
{
if (status) {
@@ -2962,6 +3028,7 @@ struct hci_dev *hci_alloc_dev(void)
INIT_LIST_HEAD(&hdev->long_term_keys);
INIT_LIST_HEAD(&hdev->remote_oob_data);
INIT_LIST_HEAD(&hdev->le_conn_params);
+ INIT_LIST_HEAD(&hdev->pend_le_conns);
INIT_LIST_HEAD(&hdev->conn_hash.list);
INIT_WORK(&hdev->rx_work, hci_rx_work);
@@ -3148,6 +3215,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
hci_smp_ltks_clear(hdev);
hci_remote_oob_data_clear(hdev);
hci_conn_params_clear(hdev);
+ hci_pend_le_conns_clear(hdev);
hci_dev_unlock(hdev);
hci_dev_put(hdev);
--
1.8.4
^ permalink raw reply related
* [RFC v3 05/12] Bluetooth: Stop scanning on LE connection
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
Some LE controllers don't support scanning and creating a connection
at the same time. So we should always stop scanning in order to
establish the connection.
Since we may prematurely stop the discovery procedure in favor of
the connection establishment, we should also cancel hdev->le_scan_
disable delayed work and set the discovery state to DISCOVERY_STOPPED.
This change does a small improvement since it is not mandatory the
user stops scanning before connecting anymore. Moreover, this change
is required by upcoming LE auto connection mechanism in order to work
properly with controllers that don't support background scanning and
connection establishment at the same time.
In future, we might want to do a small optimization by checking if
controller is able to scan and connect at the same time. For now,
we want the simplest approach so we always stop scanning (even if
the controller is able to carry out both operations).
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_conn.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index b5c3ebff..750a39d 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -518,8 +518,17 @@ static void create_le_conn_complete(struct hci_dev *hdev, u8 status)
{
struct hci_conn *conn;
- if (status == 0)
+ if (status == 0) {
+ /* If the discovery procedure was running, we prematurely
+ * stopped it. So we have to change the discovery state.
+ */
+ if (hdev->discovery.state == DISCOVERY_FINDING) {
+ cancel_delayed_work(&hdev->le_scan_disable);
+ hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+ }
+
return;
+ }
BT_ERR("HCI request failed to create LE connection: status 0x%2.2x",
status);
@@ -552,6 +561,18 @@ static int hci_create_le_conn(struct hci_conn *conn)
hci_req_init(&req, hdev);
+ /* If controller is scanning, we stop it since some controllers are
+ * not able to scan and connect at the same time.
+ */
+ if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
+ struct hci_cp_le_set_scan_enable enable_cp;
+
+ memset(&enable_cp, 0, sizeof(enable_cp));
+ enable_cp.enable = LE_SCAN_DISABLE;
+ hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
+ &enable_cp);
+ }
+
memset(&cp, 0, sizeof(cp));
cp.scan_interval = cpu_to_le16(hdev->le_scan_interval);
cp.scan_window = cpu_to_le16(hdev->le_scan_window);
--
1.8.4
^ permalink raw reply related
* [RFC v3 04/12] Bluetooth: Use connection parameters if any
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch changes hci_connect_le() so it uses the connection
parameters specified for the certain device. If no parameters
were configured, we use the default values.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
net/bluetooth/hci_conn.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 15c689e..b5c3ebff 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -578,6 +578,7 @@ static int hci_create_le_conn(struct hci_conn *conn)
static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
u8 dst_type, u8 sec_level, u8 auth_type)
{
+ struct hci_conn_params *params;
struct hci_conn *conn;
int err;
@@ -624,8 +625,15 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
conn->sec_level = BT_SECURITY_LOW;
conn->pending_sec_level = sec_level;
conn->auth_type = auth_type;
- conn->le_conn_min_interval = hdev->le_conn_min_interval;
- conn->le_conn_max_interval = hdev->le_conn_max_interval;
+
+ params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
+ if (params) {
+ conn->le_conn_min_interval = params->conn_min_interval;
+ conn->le_conn_max_interval = params->conn_max_interval;
+ } else {
+ conn->le_conn_min_interval = hdev->le_conn_min_interval;
+ conn->le_conn_max_interval = hdev->le_conn_max_interval;
+ }
err = hci_create_le_conn(conn);
if (err)
--
1.8.4
^ permalink raw reply related
* [RFC v3 03/12] Bluetooth: Introduce connection parameters list
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch adds to hdev the connection parameters list (hdev->le_
conn_params). The elements from this list (struct hci_conn_params)
contains the connection parameters (for now, minimum and maximum
connection interval) that should be used during the connection
establishment.
The struct hci_conn_params also defines the 'auto_connect' field
which will be used to implement the auto connection mechanism.
Moreover, this patch adds helper functions to manipulate hdev->le_
conn_params list. Some of these functions are also declared in
hci_core.h since they will be used outside hci_core.c in upcoming
patches.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci_core.h | 25 +++++++++++++
net/bluetooth/hci_core.c | 80 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index bbb097d..bdda971 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -267,6 +267,7 @@ struct hci_dev {
struct list_head link_keys;
struct list_head long_term_keys;
struct list_head remote_oob_data;
+ struct list_head le_conn_params;
struct hci_dev_stats stat;
@@ -371,6 +372,22 @@ struct hci_chan {
__u8 state;
};
+struct hci_conn_params {
+ struct list_head list;
+
+ bdaddr_t addr;
+ u8 addr_type;
+
+ enum {
+ HCI_AUTO_CONN_DISABLED,
+ HCI_AUTO_CONN_ALWAYS,
+ HCI_AUTO_CONN_LINK_LOSS,
+ } auto_connect;
+
+ u16 conn_min_interval;
+ u16 conn_max_interval;
+};
+
extern struct list_head hci_dev_list;
extern struct list_head hci_cb_list;
extern rwlock_t hci_dev_list_lock;
@@ -740,6 +757,14 @@ int hci_blacklist_clear(struct hci_dev *hdev);
int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
+struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type);
+void hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
+ u8 auto_connect, u16 conn_min_interval,
+ u16 conn_max_interval);
+void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
+void hci_conn_params_clear(struct hci_dev *hdev);
+
int hci_uuids_clear(struct hci_dev *hdev);
int hci_link_keys_clear(struct hci_dev *hdev);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 03e8355..dd9a25c 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2773,6 +2773,84 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
return mgmt_device_unblocked(hdev, bdaddr, type);
}
+/* This function requires the caller holds hdev->lock */
+struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
+ bdaddr_t *addr, u8 addr_type)
+{
+ struct hci_conn_params *params;
+
+ list_for_each_entry(params, &hdev->le_conn_params, list) {
+ if (bacmp(¶ms->addr, addr) == 0 &&
+ params->addr_type == addr_type) {
+ return params;
+ }
+ }
+
+ return NULL;
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
+ u8 auto_connect, u16 conn_min_interval,
+ u16 conn_max_interval)
+{
+ struct hci_conn_params *params;
+
+ params = hci_conn_params_lookup(hdev, addr, addr_type);
+ if (params) {
+ params->auto_connect = auto_connect;
+ params->conn_min_interval = conn_min_interval;
+ params->conn_max_interval = conn_max_interval;
+ return;
+ }
+
+ params = kzalloc(sizeof(*params), GFP_KERNEL);
+ if (!params) {
+ BT_ERR("Out of memory");
+ return;
+ }
+
+ bacpy(¶ms->addr, addr);
+ params->addr_type = addr_type;
+ params->auto_connect = auto_connect;
+ params->conn_min_interval = conn_min_interval;
+ params->conn_max_interval = conn_max_interval;
+
+ list_add(¶ms->list, &hdev->le_conn_params);
+
+ BT_DBG("addr %pMR (type %u) auto_connect %u conn_min_interval 0x%.4x "
+ "conn_max_interval 0x%.4x", addr, addr_type, auto_connect,
+ conn_min_interval, conn_max_interval);
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
+{
+ struct hci_conn_params *params;
+
+ params = hci_conn_params_lookup(hdev, addr, addr_type);
+ if (!params)
+ return;
+
+ list_del(¶ms->list);
+ kfree(params);
+
+ BT_DBG("addr %pMR (type %u)", addr, addr_type);
+}
+
+/* This function requires the caller holds hdev->lock */
+void hci_conn_params_clear(struct hci_dev *hdev)
+{
+ struct hci_conn_params *params, *tmp;
+
+ list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) {
+ list_del(¶ms->list);
+ kfree(params);
+ }
+
+ BT_DBG("All LE connection parameters were removed");
+}
+
static void inquiry_complete(struct hci_dev *hdev, u8 status)
{
if (status) {
@@ -2883,6 +2961,7 @@ struct hci_dev *hci_alloc_dev(void)
INIT_LIST_HEAD(&hdev->link_keys);
INIT_LIST_HEAD(&hdev->long_term_keys);
INIT_LIST_HEAD(&hdev->remote_oob_data);
+ INIT_LIST_HEAD(&hdev->le_conn_params);
INIT_LIST_HEAD(&hdev->conn_hash.list);
INIT_WORK(&hdev->rx_work, hci_rx_work);
@@ -3068,6 +3147,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
hci_link_keys_clear(hdev);
hci_smp_ltks_clear(hdev);
hci_remote_oob_data_clear(hdev);
+ hci_conn_params_clear(hdev);
hci_dev_unlock(hdev);
hci_dev_put(hdev);
--
1.8.4
^ permalink raw reply related
* [RFC v3 02/12] Bluetooth: Group list_head fields from strcut hci_dev together
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch groups the list_head fields from struct hci_dev together
and removes empty lines between them.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci_core.h | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 1e38871..bbb097d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -257,18 +257,15 @@ struct hci_dev {
__u32 req_status;
__u32 req_result;
- struct list_head mgmt_pending;
struct discovery_state discovery;
struct hci_conn_hash conn_hash;
- struct list_head blacklist;
+ struct list_head mgmt_pending;
+ struct list_head blacklist;
struct list_head uuids;
-
struct list_head link_keys;
-
struct list_head long_term_keys;
-
struct list_head remote_oob_data;
struct hci_dev_stats stat;
--
1.8.4
^ permalink raw reply related
* [RFC v3 01/12] Bluetooth: Save connection interval parameters in hci_conn
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384985340-2902-1-git-send-email-andre.guedes@openbossa.org>
This patch creates two new fields in struct hci_conn to save the
minimum and maximum connection interval values used to establish
the connection this object represents.
This change is required in order to know what parameters the
connection is currently using.
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 6 ++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8c0ab3d..1e38871 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -332,6 +332,8 @@ struct hci_conn {
__u8 passkey_entered;
__u16 disc_timeout;
__u16 setting;
+ __u16 le_conn_min_interval;
+ __u16 le_conn_max_interval;
unsigned long flags;
__u8 remote_cap;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index ba5366c..15c689e 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -558,8 +558,8 @@ static int hci_create_le_conn(struct hci_conn *conn)
bacpy(&cp.peer_addr, &conn->dst);
cp.peer_addr_type = conn->dst_type;
cp.own_address_type = conn->src_type;
- cp.conn_interval_min = cpu_to_le16(hdev->le_conn_min_interval);
- cp.conn_interval_max = cpu_to_le16(hdev->le_conn_max_interval);
+ cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval);
+ cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval);
cp.supervision_timeout = __constant_cpu_to_le16(0x002a);
cp.min_ce_len = __constant_cpu_to_le16(0x0000);
cp.max_ce_len = __constant_cpu_to_le16(0x0000);
@@ -624,6 +624,8 @@ static struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
conn->sec_level = BT_SECURITY_LOW;
conn->pending_sec_level = sec_level;
conn->auth_type = auth_type;
+ conn->le_conn_min_interval = hdev->le_conn_min_interval;
+ conn->le_conn_max_interval = hdev->le_conn_max_interval;
err = hci_create_le_conn(conn);
if (err)
--
1.8.4
^ permalink raw reply related
* [RFC v3 00/12] LE auto connection and connection parameters
From: Andre Guedes @ 2013-11-20 22:08 UTC (permalink / raw)
To: linux-bluetooth
Hi all,
The main changes from the previous version are:
* Debugfs interface to add auto connect address instead of new mgmt
commands.
* We always stop LE scanning in favor of connection establishment even if
the controller supports scanning and connection at the same time.
* Background scanning is now controlled in one single place (hci_update_
background_scan function).
* RCU was replaced by hdev->lock to protect hdev->le_conn_params list. After
all the changes since the original version of this patch set, I realized
we always operate on hdev->le_conn_params with hdev->lock held so there is
no point in use RCU to protect this list.
In order to test the LE auto connection mechanism please follow the
instructions below.
To add a new auto connection address we write on le_auto_conn file following
the format <address> <address type> <auto_connect>.
The <address type> values are:
* 0 for public address
* 1 for random address
The <auto_connect> values are (for more details see struct hci_conn_params):
* 0 for disabled
* 1 for always
* 2 for link loss
So for instance, if you want the kernel autonomously establishes connections
with device AA:BB:CC:DD:EE:FF (public address) every time the device enters in
connectable mode (starts advertising), you should run the command:
$ echo "AA:BB:CC:DD:EE:FF 0 1" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
To get the list of connection parameters configured in kernel, read the
le_auto_conn file:
$ cat /sys/kernel/debug/bluetooth/hci0/le_auto_conn
Finally, to clear the connection parameters list, write an empty string:
$ echo "" > /sys/kernel/debug/bluetooth/hci0/le_auto_conn
Regards,
Andre Guedes
Andre Guedes (12):
Bluetooth: Save connection interval parameters in hci_conn
Bluetooth: Group list_head fields from strcut hci_dev together
Bluetooth: Introduce connection parameters list
Bluetooth: Use connection parameters if any
Bluetooth: Stop scanning on LE connection
Bluetooth: Introduce hdev->pend_le_conn list
Bluetooth: Introduce LE auto connection infrastructure
Bluetooth: Re-enable background scan in case of error
Bluetooth: Temporarily stop background scanning on discovery
Bluetooth: Auto connection and power on
Bleutooth: Add support for auto connect options
Bluetooth: Add le_auto_conn file on debugfs
include/net/bluetooth/hci_core.h | 43 +++++-
net/bluetooth/hci_conn.c | 39 ++++-
net/bluetooth/hci_core.c | 318 +++++++++++++++++++++++++++++++++++++++
net/bluetooth/hci_event.c | 60 ++++++++
net/bluetooth/mgmt.c | 25 ++-
5 files changed, 473 insertions(+), 12 deletions(-)
--
1.8.4
^ permalink raw reply
* [PATCH] Adding paired-devices cmd to the bluetoothctl
From: Sebastian @ 2013-11-20 20:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sebastian Chlad
From: Sebastian Chlad <sebastian.chlad@tieto.com>
Paired-devices command lists only paired devices
---
client/main.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/client/main.c b/client/main.c
index 0dd1510..c39ebf8 100644
--- a/client/main.c
+++ b/client/main.c
@@ -538,6 +538,26 @@ static void cmd_devices(const char *arg)
}
}
+static void cmd_devices_paired(const char *arg)
+{
+ GList *list;
+
+ for (list = g_list_first(dev_list); list; list = g_list_next(list)) {
+ DBusMessageIter iter;
+ GDBusProxy *proxy = list->data;
+ dbus_bool_t paired;
+
+ if (g_dbus_proxy_get_property(proxy, "Paired", &iter) == FALSE)
+ return;
+ dbus_message_iter_get_basic(&iter, &paired);
+
+ if (!paired)
+ break;
+
+ print_device(proxy, NULL);
+ }
+}
+
static void generic_callback(const DBusError *error, void *user_data)
{
char *str = user_data;
@@ -1047,6 +1067,8 @@ static const struct {
{ "select", "<ctrl>", cmd_select, "Select default controller",
ctrl_generator },
{ "devices", NULL, cmd_devices, "List available devices" },
+ { "paired-devices", NULL, cmd_devices_paired,
+ "List paired devices"},
{ "system-alias", "<name>", cmd_system_alias },
{ "reset-alias", NULL, cmd_reset_alias },
{ "power", "<on/off>", cmd_power, "Set controller power" },
--
1.8.1.2
^ permalink raw reply related
* Re: Bluetooth: oops in rfcomm_sock_getsockopt_old
From: Johan Hedberg @ 2013-11-20 15:02 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Marcel Holtmann, Gustavo Padovan, netdev, linux-bluetooth
In-Reply-To: <alpine.LNX.2.00.1311201553040.31451@pobox.suse.cz>
Hi Jiri,
On Wed, Nov 20, 2013, Jiri Kosina wrote:
> I am seeing this during boot (when bluetoothd is starting) with current
> Linus' tree (HEAD == b4789b8e6b), after latest netdev/bluetooth merge:
>
> BUG: unable to handle kernel paging request at 000000234df5351a
> IP: [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
> PGD 0
> Oops: 0000 [#1] SMP
> Modules linked in: rfcomm bnep cpufreq_conservative cpufreq_userspace cpufreq_powersa
> CO_vendor_support kvm_intel snd_hda_codec_conexant kvm iwldvm mac80211 btusb bluetooth
> d_hda_intel snd_hda_codec snd_hwdep cfg80211 thinkpad_acpi snd_seq pcspkr snd_pcm i2c_i801 lpc_ich mfd_core rfkill e1000e ehci_pci snd_timer snd_page_alloc snd_seq_device ptp pps_core wmi snd tpm_tis soundcore battery ac tpm tpm_bios acpi_cpufreq autofs4 uhci_hcd ehci_hcd i915 usbcore usb_common drm_kms_helper drm i2c_algo_bit button video edd fan processor ata_generic thermal thermal_sys
> CPU: 0 PID: 1024 Comm: bluetoothd Not tainted 3.11.0-07976-g8d6083f #1
> Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
> task: ffff880076c0e000 ti: ffff880036f94000 task.ti: ffff880036f94000
> RIP: 0010:[<ffffffffa05e95b9>] [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
> RSP: 0018:ffff880036f95e78 EFLAGS: 00010246
> RAX: 000000234df53512 RBX: 00007fff5ebe9e9c RCX: 00007fff5ebe9e9c
> RDX: 00007fff5ebe9e98 RSI: 0000000000000003 RDI: ffff8800784eb480
> RBP: ffff880036f95ec8 R08: ffff880076c1e000 R09: 00007fff5ebea148
> R10: 00007fff5ebe9e98 R11: 0000000000000202 R12: ffff880076c1e000
> R13: 0000000000000003 R14: 00007fff5ebe9e9c R15: 00007fff5ebe9e98
> FS: 00007fd5d7655700(0000) GS:ffff88007c200000(0000) knlGS:0000000000000000
> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 000000234df5351a CR3: 0000000037b06000 CR4: 00000000000007f0
> Stack:
> 0000000000000004 00007fff5ebe9e98 ffff880036f95ea8 ffffffff81582e8f
> ffffffff8148e61b ffff8800784eb480 0000000000000012 0000000000000003
> 00007fff5ebe9e9c 00007fff5ebe9e98 ffff880036f95f28 ffffffffa05e9763
> Call Trace:
> [<ffffffff81582e8f>] ? _raw_spin_unlock_bh+0x3f/0x50
> [<ffffffff8148e61b>] ? release_sock+0x2b/0xa0
> [<ffffffffa05e9763>] rfcomm_sock_getsockopt+0x53/0x190 [rfcomm]
> [<ffffffff8158b737>] ? sysret_check+0x1b/0x56
> [<ffffffff81486933>] SyS_getsockopt+0x73/0xe0
> [<ffffffff8158b712>] system_call_fastpath+0x16/0x1b
> Code: 04 48 89 5d d8 4c 89 6d e8 48 89 cb 4c 89 65 e0 4c 89 75 f0 41 89 f5 4c 89 7d f8 48 89 55 b8 4c 8b 67 20 49 8b 84 24 50 04 00 00 <4c> 8b 78 08 0f 85 27 01 00 00 e8 e8 83 b6 e0 48 89 d8 e8 60 40
> RIP [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
> RSP <ffff880036f95e78>
> CR2: 000000234df5351a
> ---[ end trace d84df5c733bb1019 ]---
>
>
> I have bisected this to 94a86df01. I don't immediately see how this could
> be causing the issue directly, hence sending out this as a heads-up, and
> will continue looking into this eventually.
>
> It seems to be very reliably reproducible, so I expect the bisection to be
> correct (to be verified still).
The issue is already fixed in the bluetooth and wireless trees but
the patch hasn't yet made it to the net or Linus' tree.
Johan
^ permalink raw reply
* Bluetooth: oops in rfcomm_sock_getsockopt_old
From: Jiri Kosina @ 2013-11-20 14:57 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Gustavo Padovan; +Cc: netdev, linux-bluetooth
Hi,
I am seeing this during boot (when bluetoothd is starting) with current
Linus' tree (HEAD == b4789b8e6b), after latest netdev/bluetooth merge:
BUG: unable to handle kernel paging request at 000000234df5351a
IP: [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
PGD 0
Oops: 0000 [#1] SMP
Modules linked in: rfcomm bnep cpufreq_conservative cpufreq_userspace cpufreq_powersa
CO_vendor_support kvm_intel snd_hda_codec_conexant kvm iwldvm mac80211 btusb bluetooth
d_hda_intel snd_hda_codec snd_hwdep cfg80211 thinkpad_acpi snd_seq pcspkr snd_pcm i2c_i801 lpc_ich mfd_core rfkill e1000e ehci_pci snd_timer snd_page_alloc snd_seq_device ptp pps_core wmi snd tpm_tis soundcore battery ac tpm tpm_bios acpi_cpufreq autofs4 uhci_hcd ehci_hcd i915 usbcore usb_common drm_kms_helper drm i2c_algo_bit button video edd fan processor ata_generic thermal thermal_sys
CPU: 0 PID: 1024 Comm: bluetoothd Not tainted 3.11.0-07976-g8d6083f #1
Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
task: ffff880076c0e000 ti: ffff880036f94000 task.ti: ffff880036f94000
RIP: 0010:[<ffffffffa05e95b9>] [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
RSP: 0018:ffff880036f95e78 EFLAGS: 00010246
RAX: 000000234df53512 RBX: 00007fff5ebe9e9c RCX: 00007fff5ebe9e9c
RDX: 00007fff5ebe9e98 RSI: 0000000000000003 RDI: ffff8800784eb480
RBP: ffff880036f95ec8 R08: ffff880076c1e000 R09: 00007fff5ebea148
R10: 00007fff5ebe9e98 R11: 0000000000000202 R12: ffff880076c1e000
R13: 0000000000000003 R14: 00007fff5ebe9e9c R15: 00007fff5ebe9e98
FS: 00007fd5d7655700(0000) GS:ffff88007c200000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000234df5351a CR3: 0000000037b06000 CR4: 00000000000007f0
Stack:
0000000000000004 00007fff5ebe9e98 ffff880036f95ea8 ffffffff81582e8f
ffffffff8148e61b ffff8800784eb480 0000000000000012 0000000000000003
00007fff5ebe9e9c 00007fff5ebe9e98 ffff880036f95f28 ffffffffa05e9763
Call Trace:
[<ffffffff81582e8f>] ? _raw_spin_unlock_bh+0x3f/0x50
[<ffffffff8148e61b>] ? release_sock+0x2b/0xa0
[<ffffffffa05e9763>] rfcomm_sock_getsockopt+0x53/0x190 [rfcomm]
[<ffffffff8158b737>] ? sysret_check+0x1b/0x56
[<ffffffff81486933>] SyS_getsockopt+0x73/0xe0
[<ffffffff8158b712>] system_call_fastpath+0x16/0x1b
Code: 04 48 89 5d d8 4c 89 6d e8 48 89 cb 4c 89 65 e0 4c 89 75 f0 41 89 f5 4c 89 7d f8 48 89 55 b8 4c 8b 67 20 49 8b 84 24 50 04 00 00 <4c> 8b 78 08 0f 85 27 01 00 00 e8 e8 83 b6 e0 48 89 d8 e8 60 40
RIP [<ffffffffa05e95b9>] rfcomm_sock_getsockopt_old+0x39/0x190 [rfcomm]
RSP <ffff880036f95e78>
CR2: 000000234df5351a
---[ end trace d84df5c733bb1019 ]---
I have bisected this to 94a86df01. I don't immediately see how this could
be causing the issue directly, hence sending out this as a heads-up, and
will continue looking into this eventually.
It seems to be very reliably reproducible, so I expect the bisection to be
correct (to be verified still).
--
Jiri Kosina
SUSE Labs
^ permalink raw reply
* Re: [PATCHv6 10/19] android/socket: Parse SDP response and connect
From: Johan Hedberg @ 2013-11-20 13:21 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1384943077-5366-11-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Wed, Nov 20, 2013, Andrei Emeltchenko wrote:
> Parse SDP response, find RFCOMM channel and connect.
> ---
> android/socket.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
Patches 1-9 have been applied (I merged 2 and 3 to avoid the compilation
error reported earlier), but one issue here:
> + io = bt_io_connect(connect_cb, rfsock, NULL, &gerr,
> + BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
> + BT_IO_OPT_DEST_BDADDR, &rfsock->dst,
> + BT_IO_OPT_CHANNEL, chan,
> + BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
> + BT_IO_OPT_INVALID);
> + if (!io) {
> + error("Failed connect: %s", gerr->message);
> + g_error_free(gerr);
> + goto fail;
> + }
> +
> + rfsock->real_sock = g_io_channel_unix_get_fd(io);
> + rfsock->channel = chan;
> + connections = g_list_append(connections, rfsock);
> + return;
Looks like you're leaking a reference for the GIOChannel since you don't
store it anywhere and return from the function without doing a
g_io_channel_unref().
Johan
^ permalink raw reply
* Re: [PATCHv6 02/19] android/socket: Handling rfcomm sockets
From: Johan Hedberg @ 2013-11-20 13:06 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1384943077-5366-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Wed, Nov 20, 2013, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Implement functions creating and destroying rfcomm_socket structures.
> ---
> android/socket.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 63 insertions(+), 1 deletion(-)
I've applied the first patch, but this one doesn't compile:
android/socket.c:81:13: error: ‘cleanup_rfsock’ defined but not used [-Werror=unused-function]
static void cleanup_rfsock(struct rfcomm_sock *rfsock)
Johan
^ permalink raw reply
* [RFC v5 5/5] Bluetooth: Manually enable or disable 6LoWPAN between devices
From: Jukka Rissanen @ 2013-11-20 12:07 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384949243-829-1-git-send-email-jukka.rissanen@linux.intel.com>
This is a temporary patch where user can manually enable or
disable BT 6LoWPAN functionality between devices.
Eventually the connection is established automatically if
the devices are advertising suitable capability and this patch
can be removed.
Before connecting the devices do this
echo 1 > /sys/kernel/debug/bluetooth/hci0/6lowpan
This enables 6LoWPAN support and creates the bt0 interface
automatically when devices are finally connected.
Rebooting or unloading the bluetooth kernel module will also clear the
settings from the kernel.
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
---
net/bluetooth/hci_core.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 03e8355..0a2ec42 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -636,6 +636,97 @@ static int conn_max_interval_get(void *data, u64 *val)
DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
conn_max_interval_set, "%llu\n");
+static LIST_HEAD(lowpan_user_enabled);
+static DEFINE_RWLOCK(lowpan_enabled_lock);
+
+struct lowpan_enabled {
+ __u8 dev_name[HCI_MAX_NAME_LENGTH];
+ bool enabled;
+ struct list_head list;
+};
+
+static int lowpan_debugfs_show(struct seq_file *f, void *p)
+{
+ struct hci_dev *hdev = f->private;
+
+ if (test_bit(HCI_6LOWPAN_ENABLED, &hdev->dev_flags))
+ seq_printf(f, "1\n");
+ else
+ seq_printf(f, "0\n");
+
+ return 0;
+}
+
+static int lowpan_debugfs_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, lowpan_debugfs_show, inode->i_private);
+}
+
+static ssize_t lowpan_writer(struct file *fp, const char __user *user_buffer,
+ size_t count, loff_t *position)
+{
+ struct hci_dev *hdev = fp->f_inode->i_private;
+ struct lowpan_enabled *entry = NULL, *tmp;
+ bool new_value, old_value;
+ char buf[3] = { 0 };
+ ssize_t ret;
+
+ BT_DBG("dev %s count %zd", hdev->dev_name, count);
+
+ ret = simple_write_to_buffer(buf, 2, position, user_buffer, count);
+ if (ret <= 0)
+ return ret;
+
+ if (strtobool(buf, &new_value) < 0)
+ return -EINVAL;
+
+ ret = -ENOENT;
+
+ write_lock(&lowpan_enabled_lock);
+ list_for_each_entry_safe(entry, tmp, &lowpan_user_enabled, list) {
+ if (!strncmp(entry->dev_name, hdev->dev_name,
+ HCI_MAX_NAME_LENGTH)) {
+ old_value = entry->enabled;
+ entry->enabled = new_value;
+ ret = 0;
+ break;
+ }
+ }
+ write_unlock(&lowpan_enabled_lock);
+
+ if (ret == 0 && old_value == new_value)
+ return count;
+
+ if (ret < 0) {
+ entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ if (!entry)
+ return -ENOMEM;
+
+ strncpy(entry->dev_name, hdev->dev_name, HCI_MAX_NAME_LENGTH);
+ entry->enabled = new_value;
+
+ write_lock(&lowpan_enabled_lock);
+ INIT_LIST_HEAD(&entry->list);
+ list_add(&entry->list, &lowpan_user_enabled);
+ write_unlock(&lowpan_enabled_lock);
+ }
+
+ if (new_value == true)
+ set_bit(HCI_6LOWPAN_ENABLED, &hdev->dev_flags);
+ else
+ clear_bit(HCI_6LOWPAN_ENABLED, &hdev->dev_flags);
+
+ return count;
+}
+
+static const struct file_operations lowpan_debugfs_fops = {
+ .open = lowpan_debugfs_open,
+ .read = seq_read,
+ .write = lowpan_writer,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
/* ---- HCI requests ---- */
static void hci_req_sync_complete(struct hci_dev *hdev, u8 result)
@@ -1406,6 +1497,8 @@ static int __hci_init(struct hci_dev *hdev)
hdev, &conn_min_interval_fops);
debugfs_create_file("conn_max_interval", 0644, hdev->debugfs,
hdev, &conn_max_interval_fops);
+ debugfs_create_file("6lowpan", 0644, hdev->debugfs, hdev,
+ &lowpan_debugfs_fops);
}
return 0;
--
1.8.3.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox