Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 0/9] Bluetooth: Add LE support for mgmt_set_discoverable
From: johan.hedberg @ 2013-10-19 20:38 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

In addition to a couple if fixes in the existing mgmt code (first 5
patches), this patch set adds support for hooking up the
set_discoverable command to LE, in particular the advertising flags.

Johan

----------------------------------------------------------------
Johan Hedberg (9):
      Bluetooth: Check for flag instead of features in update_scan_rsp_data()
      Bluetooth: Check for flag instead of features in update_adv_data()
      Bluetooth: Add missing check for BREDR_ENABLED flag in update_class()
      Bluetooth: Refactor set_connectable settings update to separate function
      Bluetooth: Fix updating settings when there are no HCI commands to send
      Bluetooth: Move mgmt_pending_find to avoid forward declarations
      Bluetooth: Fix sending write_scan_enable when BR/EDR is disabled
      Bluetooth: Move HCI_LIMITED_DISCOVERABLE changes to a general place
      Bluetooth: Update Set Discoverable to support LE

 net/bluetooth/mgmt.c | 147 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 100 insertions(+), 47 deletions(-)


^ permalink raw reply

* Re: [PATCH] Bluetooth: Fix minor coding style issue in hci_core.c
From: Johan Hedberg @ 2013-10-19 17:52 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382203155-27291-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> A few variable assignments ended up with missing a space between the
> variable and equal sign.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Fix UUID values in blacklist debugfs file
From: Johan Hedberg @ 2013-10-19 17:51 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382200319-26951-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> The uuid entry struct is used for the UUID byte stream. That is
> actually the wrong value. The correct value is uuid->uuid.
> 
> Besides fixing this up, use the %pUb modifier to print the UUID
> string. However since the UUID is stored in big endian with
> reversed byte order, change the byte order before printing.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 22 ++++++++++------------
>  1 file changed, 10 insertions(+), 12 deletions(-)

Applied (after removing the bogus "blacklist" word from the subject).
Thanks.

Johan

^ permalink raw reply

* [PATCH] Bluetooth: Fix minor coding style issue in hci_core.c
From: Marcel Holtmann @ 2013-10-19 17:19 UTC (permalink / raw)
  To: linux-bluetooth

A few variable assignments ended up with missing a space between the
variable and equal sign.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index c5fb3a3..6ccc4eb 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -423,7 +423,7 @@ static int idle_timeout_set(void *data, u64 val)
 		return -EINVAL;
 
 	hci_dev_lock(hdev);
-	hdev->idle_timeout= val;
+	hdev->idle_timeout = val;
 	hci_dev_unlock(hdev);
 
 	return 0;
@@ -451,7 +451,7 @@ static int sniff_min_interval_set(void *data, u64 val)
 		return -EINVAL;
 
 	hci_dev_lock(hdev);
-	hdev->sniff_min_interval= val;
+	hdev->sniff_min_interval = val;
 	hci_dev_unlock(hdev);
 
 	return 0;
@@ -479,7 +479,7 @@ static int sniff_max_interval_set(void *data, u64 val)
 		return -EINVAL;
 
 	hci_dev_lock(hdev);
-	hdev->sniff_max_interval= val;
+	hdev->sniff_max_interval = val;
 	hci_dev_unlock(hdev);
 
 	return 0;
@@ -588,7 +588,7 @@ static int conn_min_interval_set(void *data, u64 val)
 		return -EINVAL;
 
 	hci_dev_lock(hdev);
-	hdev->le_conn_min_interval= val;
+	hdev->le_conn_min_interval = val;
 	hci_dev_unlock(hdev);
 
 	return 0;
@@ -616,7 +616,7 @@ static int conn_max_interval_set(void *data, u64 val)
 		return -EINVAL;
 
 	hci_dev_lock(hdev);
-	hdev->le_conn_max_interval= val;
+	hdev->le_conn_max_interval = val;
 	hci_dev_unlock(hdev);
 
 	return 0;
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH v2 3/3] Bluetooth: Expose debugfs settings for LE connection interval
From: Anderson Lizardo @ 2013-10-19 17:07 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <1382191753-59287-3-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013 at 10:09 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> +static int conn_min_interval_set(void *data, u64 val)
> +{
> +       struct hci_dev *hdev = data;
> +
> +       if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
> +               return -EINVAL;
> +
> +       hci_dev_lock(hdev);
> +       hdev->le_conn_min_interval= val;

Minor style issue: missing space before "=".

> +       hci_dev_unlock(hdev);
> +
> +       return 0;
> +}
> [snip]
> +static int conn_max_interval_set(void *data, u64 val)
> +{
> +       struct hci_dev *hdev = data;
> +
> +       if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
> +               return -EINVAL;
> +
> +       hci_dev_lock(hdev);
> +       hdev->le_conn_max_interval= val;

Same above.

> +       hci_dev_unlock(hdev);
> +
> +       return 0;
> +}

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* [PATCH] Bluetooth: Fix UUID values in blacklist debugfs file
From: Marcel Holtmann @ 2013-10-19 16:31 UTC (permalink / raw)
  To: linux-bluetooth

The uuid entry struct is used for the UUID byte stream. That is
actually the wrong value. The correct value is uuid->uuid.

Besides fixing this up, use the %pUb modifier to print the UUID
string. However since the UUID is stored in big endian with
reversed byte order, change the byte order before printing.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index b5c8cb3..c5fb3a3 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -193,18 +193,16 @@ static int uuids_show(struct seq_file *f, void *p)
 
 	hci_dev_lock(hdev);
 	list_for_each_entry(uuid, &hdev->uuids, list) {
-		u32 data0, data5;
-		u16 data1, data2, data3, data4;
-
-		data5 = get_unaligned_le32(uuid);
-		data4 = get_unaligned_le16(uuid + 4);
-		data3 = get_unaligned_le16(uuid + 6);
-		data2 = get_unaligned_le16(uuid + 8);
-		data1 = get_unaligned_le16(uuid + 10);
-		data0 = get_unaligned_le32(uuid + 12);
-
-		seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.4x%.8x\n",
-			   data0, data1, data2, data3, data4, data5);
+		u8 i, val[16];
+
+		/* The Bluetooth UUID values are stored in big endian,
+		 * but with reversed byte order. So convert them into
+		 * the right order for the %pUb modifier.
+		 */
+		for (i = 0; i < 16; i++)
+			val[i] = uuid->uuid[15 - i];
+
+		seq_printf(f, "%pUb\n", val);
 	}
 	hci_dev_unlock(hdev);
 
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH v2 1/3] Bluetooth: Add support for setting SSP debug mode
From: Johan Hedberg @ 2013-10-19 16:07 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382191753-59287-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> Enabling and disabling SSP debug mode is useful for development. This
> adds a debugfs entry that allows to configure the SSP debug mode.
> 
> On purpose this has been implemented as debugfs entry and not a public
> API since it is really only useful during testing and development.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/hci.h      |  2 ++
>  include/net/bluetooth/hci_core.h |  1 +
>  net/bluetooth/hci_core.c         | 54 +++++++++++++++++++++++++++++++++++++++-
>  net/bluetooth/hci_event.c        |  2 ++
>  4 files changed, 58 insertions(+), 1 deletion(-)

All three patches have been applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* [PATCH v2 3/3] Bluetooth: Expose debugfs settings for LE connection interval
From: Marcel Holtmann @ 2013-10-19 14:09 UTC (permalink / raw)
  To: linux-bluetooth

For testing purposes expose the default LE connection interval values
via debugfs.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_conn.c         |  5 ++--
 net/bluetooth/hci_core.c         | 62 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d50cc7a..8c0ab3d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -169,6 +169,8 @@ struct hci_dev {
 	__u8		page_scan_type;
 	__u16		le_scan_interval;
 	__u16		le_scan_window;
+	__u16		le_conn_min_interval;
+	__u16		le_conn_max_interval;
 	__u8		ssp_debug_mode;
 
 	__u16		devid_source;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 974d7bc..ba5366c 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -558,11 +558,12 @@ 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 = __constant_cpu_to_le16(0x0028);
-	cp.conn_interval_max = __constant_cpu_to_le16(0x0038);
+	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.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);
+
 	hci_req_add(&req, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
 
 	err = hci_req_run(&req, create_le_conn_complete);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 4a5e567..b5c8cb3 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -582,6 +582,62 @@ static const struct file_operations long_term_keys_fops = {
 	.release	= single_release,
 };
 
+static int conn_min_interval_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->le_conn_min_interval= val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int conn_min_interval_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->le_conn_min_interval;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
+			conn_min_interval_set, "%llu\n");
+
+static int conn_max_interval_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->le_conn_max_interval= val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int conn_max_interval_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->le_conn_max_interval;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
+			conn_max_interval_set, "%llu\n");
+
 /* ---- HCI requests ---- */
 
 static void hci_req_sync_complete(struct hci_dev *hdev, u8 result)
@@ -1346,6 +1402,10 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &own_address_type_fops);
 		debugfs_create_file("long_term_keys", 0400, hdev->debugfs,
 				    hdev, &long_term_keys_fops);
+		debugfs_create_file("conn_min_interval", 0644, hdev->debugfs,
+				    hdev, &conn_min_interval_fops);
+		debugfs_create_file("conn_max_interval", 0644, hdev->debugfs,
+				    hdev, &conn_max_interval_fops);
 	}
 
 	return 0;
@@ -2811,6 +2871,8 @@ struct hci_dev *hci_alloc_dev(void)
 
 	hdev->le_scan_interval = 0x0060;
 	hdev->le_scan_window = 0x0030;
+	hdev->le_conn_min_interval = 0x0028;
+	hdev->le_conn_max_interval = 0x0038;
 
 	mutex_init(&hdev->lock);
 	mutex_init(&hdev->req_lock);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH v2 2/3] Bluetooth: Add support for setting DUT mode
From: Marcel Holtmann @ 2013-10-19 14:09 UTC (permalink / raw)
  To: linux-bluetooth

The Device Under Test (DUT) mode is useful for doing certification
testing and so expose this as debugfs option.

This mode is actually special since you can only enter it. Restoring
normal operation means that a HCI Reset is required. The current mode
value gets tracked as a new device flag and when disabling it, the
correct command to reset the controller is sent.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h |  3 ++
 net/bluetooth/hci_core.c    | 73 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ac9c4a7..1784c48 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -115,6 +115,7 @@ enum {
 	HCI_PAIRABLE,
 	HCI_SERVICE_CACHE,
 	HCI_DEBUG_KEYS,
+	HCI_DUT_MODE,
 	HCI_UNREGISTER,
 	HCI_USER_CHANNEL,
 
@@ -1043,6 +1044,8 @@ struct hci_rp_write_remote_amp_assoc {
 	__u8     phy_handle;
 } __packed;
 
+#define HCI_OP_ENABLE_DUT_MODE		0x1803
+
 #define HCI_OP_WRITE_SSP_DEBUG_MODE	0x1804
 
 #define HCI_OP_LE_SET_EVENT_MASK	0x2001
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 2a9e925..4a5e567 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -58,6 +58,71 @@ static void hci_notify(struct hci_dev *hdev, int event)
 
 /* ---- HCI debugfs entries ---- */
 
+static ssize_t dut_mode_read(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	struct hci_dev *hdev = file->private_data;
+	char buf[3];
+
+	buf[0] = test_bit(HCI_DUT_MODE, &hdev->dev_flags) ? 'Y': 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
+			      size_t count, loff_t *ppos)
+{
+	struct hci_dev *hdev = file->private_data;
+	struct sk_buff *skb;
+	char buf[32];
+	size_t buf_size = min(count, (sizeof(buf)-1));
+	bool enable;
+	int err;
+
+	if (!test_bit(HCI_UP, &hdev->flags))
+		return -ENETDOWN;
+
+	if (copy_from_user(buf, user_buf, buf_size))
+		return -EFAULT;
+
+	buf[buf_size] = '\0';
+	if (strtobool(buf, &enable))
+		return -EINVAL;
+
+	if (enable == test_bit(HCI_DUT_MODE, &hdev->dev_flags))
+		return -EALREADY;
+
+	hci_req_lock(hdev);
+	if (enable)
+		skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL,
+				     HCI_CMD_TIMEOUT);
+	else
+		skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
+				     HCI_CMD_TIMEOUT);
+	hci_req_unlock(hdev);
+
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	err = -bt_to_errno(skb->data[0]);
+	kfree_skb(skb);
+
+	if (err < 0)
+		return err;
+
+	change_bit(HCI_DUT_MODE, &hdev->dev_flags);
+
+	return count;
+}
+
+static const struct file_operations dut_mode_fops = {
+	.open		= simple_open,
+	.read		= dut_mode_read,
+	.write		= dut_mode_write,
+	.llseek		= default_llseek,
+};
+
 static int features_show(struct seq_file *f, void *ptr)
 {
 	struct hci_dev *hdev = f->private;
@@ -1200,6 +1265,14 @@ static int __hci_init(struct hci_dev *hdev)
 	if (err < 0)
 		return err;
 
+	/* The Device Under Test (DUT) mode is special and available for
+	 * all controller types. So just create it early on.
+	 */
+	if (test_bit(HCI_SETUP, &hdev->dev_flags)) {
+		debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev,
+				    &dut_mode_fops);
+	}
+
 	/* HCI_BREDR covers both single-mode LE, BR/EDR and dual-mode
 	 * BR/EDR/LE type controllers. AMP controllers only need the
 	 * first stage init.
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH v2 1/3] Bluetooth: Add support for setting SSP debug mode
From: Marcel Holtmann @ 2013-10-19 14:09 UTC (permalink / raw)
  To: linux-bluetooth

Enabling and disabling SSP debug mode is useful for development. This
adds a debugfs entry that allows to configure the SSP debug mode.

On purpose this has been implemented as debugfs entry and not a public
API since it is really only useful during testing and development.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h      |  2 ++
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         | 54 +++++++++++++++++++++++++++++++++++++++-
 net/bluetooth/hci_event.c        |  2 ++
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 77a971a..ac9c4a7 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1043,6 +1043,8 @@ struct hci_rp_write_remote_amp_assoc {
 	__u8     phy_handle;
 } __packed;
 
+#define HCI_OP_WRITE_SSP_DEBUG_MODE	0x1804
+
 #define HCI_OP_LE_SET_EVENT_MASK	0x2001
 struct hci_cp_le_set_event_mask {
 	__u8     mask[8];
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index c689bcf..d50cc7a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -169,6 +169,7 @@ struct hci_dev {
 	__u8		page_scan_type;
 	__u16		le_scan_interval;
 	__u16		le_scan_window;
+	__u8		ssp_debug_mode;
 
 	__u16		devid_source;
 	__u16		devid_vendor;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 384b9db..2a9e925 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -303,6 +303,55 @@ static int auto_accept_delay_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
 			auto_accept_delay_set, "%llu\n");
 
+static int ssp_debug_mode_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+	struct sk_buff *skb;
+	__u8 mode;
+	int err;
+
+	if (val != 0 && val != 1)
+		return -EINVAL;
+
+	if (!test_bit(HCI_UP, &hdev->flags))
+		return -ENETDOWN;
+
+	hci_req_lock(hdev);
+	mode = val;
+	skb = __hci_cmd_sync(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, sizeof(mode),
+			     &mode, HCI_CMD_TIMEOUT);
+	hci_req_unlock(hdev);
+
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	err = -bt_to_errno(skb->data[0]);
+	kfree_skb(skb);
+
+	if (err < 0)
+		return err;
+
+	hci_dev_lock(hdev);
+	hdev->ssp_debug_mode = val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int ssp_debug_mode_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->ssp_debug_mode;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(ssp_debug_mode_fops, ssp_debug_mode_get,
+			ssp_debug_mode_set, "%llu\n");
+
 static int idle_timeout_set(void *data, u64 val)
 {
 	struct hci_dev *hdev = data;
@@ -1199,9 +1248,12 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &voice_setting_fops);
 	}
 
-	if (lmp_ssp_capable(hdev))
+	if (lmp_ssp_capable(hdev)) {
 		debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
 				    hdev, &auto_accept_delay_fops);
+		debugfs_create_file("ssp_debug_mode", 0644, hdev->debugfs,
+				    hdev, &ssp_debug_mode_fops);
+	}
 
 	if (lmp_sniff_capable(hdev)) {
 		debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 1214d4b..5935f74 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -198,6 +198,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 
 	memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data));
 	hdev->scan_rsp_data_len = 0;
+
+	hdev->ssp_debug_mode = 0;
 }
 
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
-- 
1.8.3.1


^ permalink raw reply related

* Re: [PATCH] Bluetooth: Remove interval parameter from HCI connection
From: Johan Hedberg @ 2013-10-19 13:52 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382185617-43385-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> The conn->interval parameter of HCI connections is not used at all
> and so just remove it.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/hci_core.h | 1 -
>  net/bluetooth/hci_event.c        | 1 -
>  2 files changed, 2 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Add LE features to debugfs if available
From: Johan Hedberg @ 2013-10-19 13:52 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382174733-25708-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> For LE capable controllers at the special LE features page to the
> debugfs list with all the other features pages.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH v2] Bluetooth: Add support for setting SSP debug mode
From: Johan Hedberg @ 2013-10-19 13:34 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382174000-18946-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Sat, Oct 19, 2013, Marcel Holtmann wrote:
> +static int ssp_debug_mode_set(void *data, u64 val)
> +{
> +	struct hci_dev *hdev = data;
> +	struct sk_buff *skb;
> +	__u8 mode;
> +
> +	if (val != 0 && val != 1)
> +		return -EINVAL;
> +
> +	if (!test_bit(HCI_UP, &hdev->flags))
> +		return -ENETDOWN;
> +
> +	hci_req_lock(hdev);
> +	mode = val;
> +	skb = __hci_cmd_sync(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, sizeof(mode),
> +			     &mode, HCI_CMD_TIMEOUT);
> +	hci_req_unlock(hdev);
> +
> +	if (IS_ERR(skb))
> +		return PTR_ERR(skb);
> +
> +	if (skb->data[0]) {
> +		u8 status = skb->data[0];
> +		kfree_skb(skb);
> +		return -bt_to_errno(status);
> +	}
> +
> +	hci_dev_lock(hdev);
> +	hdev->ssp_debug_mode = val;
> +	hci_dev_unlock(hdev);
> +
> +	return 0;
> +}

Looks like skb is being leaked here if the HCI command succeeds.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Expose setting if debug keys are used or not
From: Johan Hedberg @ 2013-10-19 13:31 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382141662-6799-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> The system can be figured to accept and use debug keys. Expose this
> value in debugfs for debugging purposes.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/2] Bluetooth: Select the own address type during initial setup phase
From: Johan Hedberg @ 2013-10-19 13:30 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382139490-306-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> The own address type is based on the fact if the controller has
> a public address or not. This means that this detail can be just
> configured once during setup phase.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/hci_core.h |  1 +
>  net/bluetooth/hci_conn.c         |  7 +------
>  net/bluetooth/hci_core.c         | 13 ++++++++++++-
>  net/bluetooth/mgmt.c             | 10 ++--------
>  4 files changed, 16 insertions(+), 15 deletions(-)

Both patches have been applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 0/5] Initial Android IPC
From: Szymon Janc @ 2013-10-19 13:28 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1382137302-17237-1-git-send-email-szymon.janc@gmail.com>

> This adds initial code for Android IPC
> - only connection establishment
> - connecting ipc from daemon to HAL after adapter is initialized
> - daemon track HAL lib lifetime and shutdown if socket is closed
> - HAL library starts daemon (via android init) and wait for it to
>   connect
> - HAL library is *not* yet tracking lifetime of daemon

One more note I forgot to mention: this is not yet runtime tested on Android.
(build was verified though)

-- 
Szymon K. Janc
szymon.janc@gmail.com

^ permalink raw reply

* Re: [PATCH] Bluetooth: Expose current list of long term keys via debugfs
From: Johan Hedberg @ 2013-10-19 13:27 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382137017-56186-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> For debugging purposes expose the current list of long term keys
> via debugfs. This file is read-only and limited to root access.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Expose white list size information in debugfs
From: Johan Hedberg @ 2013-10-19 13:27 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382135026-48008-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> Knowing the white list size information is important for
> debugging. So export it via debugfs.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Remove bus attribute in favor of hierarchy
From: Johan Hedberg @ 2013-10-19 13:27 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382125167-44247-1-git-send-email-marcel@holtmann.org>

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> The bus information are exposed in the actual hierarchy and should
> not be exposed as attribute.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_sysfs.c | 31 -------------------------------
>  1 file changed, 31 deletions(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH 1/7] Bluetooth: Move HCI device features into hci_core.c
From: Johan Hedberg @ 2013-10-19 13:25 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1382123092-35256-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Fri, Oct 18, 2013, Marcel Holtmann wrote:
> Move the handling of HCI device features debugfs into hci_core.c and
> also extend it with handling of multiple feature pages.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/hci_core.c  | 34 +++++++++++++++++++++++++++++++++-
>  net/bluetooth/hci_sysfs.c | 14 --------------
>  2 files changed, 33 insertions(+), 15 deletions(-)

All seven patches have been applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* [PATCH] Bluetooth: Expose debugfs settings for LE connection interval
From: Marcel Holtmann @ 2013-10-19 12:44 UTC (permalink / raw)
  To: linux-bluetooth

For testing purposes expose the default LE connection interval values
via debugfs.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h |  2 ++
 net/bluetooth/hci_conn.c         |  5 ++--
 net/bluetooth/hci_core.c         | 62 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d50cc7a..8c0ab3d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -169,6 +169,8 @@ struct hci_dev {
 	__u8		page_scan_type;
 	__u16		le_scan_interval;
 	__u16		le_scan_window;
+	__u16		le_conn_min_interval;
+	__u16		le_conn_max_interval;
 	__u8		ssp_debug_mode;
 
 	__u16		devid_source;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 974d7bc..ba5366c 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -558,11 +558,12 @@ 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 = __constant_cpu_to_le16(0x0028);
-	cp.conn_interval_max = __constant_cpu_to_le16(0x0038);
+	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.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);
+
 	hci_req_add(&req, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
 
 	err = hci_req_run(&req, create_le_conn_complete);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index e30352a..26e9dfd 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -580,6 +580,62 @@ static const struct file_operations long_term_keys_fops = {
 	.release	= single_release,
 };
 
+static int conn_min_interval_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->le_conn_min_interval= val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int conn_min_interval_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->le_conn_min_interval;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
+			conn_min_interval_set, "%llu\n");
+
+static int conn_max_interval_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->le_conn_max_interval= val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int conn_max_interval_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->le_conn_max_interval;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
+			conn_max_interval_set, "%llu\n");
+
 /* ---- HCI requests ---- */
 
 static void hci_req_sync_complete(struct hci_dev *hdev, u8 result)
@@ -1344,6 +1400,10 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &own_address_type_fops);
 		debugfs_create_file("long_term_keys", 0400, hdev->debugfs,
 				    hdev, &long_term_keys_fops);
+		debugfs_create_file("conn_min_interval", 0644, hdev->debugfs,
+				    hdev, &conn_min_interval_fops);
+		debugfs_create_file("conn_max_interval", 0644, hdev->debugfs,
+				    hdev, &conn_max_interval_fops);
 	}
 
 	return 0;
@@ -2809,6 +2869,8 @@ struct hci_dev *hci_alloc_dev(void)
 
 	hdev->le_scan_interval = 0x0060;
 	hdev->le_scan_window = 0x0030;
+	hdev->le_conn_min_interval = 0x0028;
+	hdev->le_conn_max_interval = 0x0038;
 
 	mutex_init(&hdev->lock);
 	mutex_init(&hdev->req_lock);
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Bluetooth: Remove interval parameter from HCI connection
From: Marcel Holtmann @ 2013-10-19 12:26 UTC (permalink / raw)
  To: linux-bluetooth

The conn->interval parameter of HCI connections is not used at all
and so just remove it.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h | 1 -
 net/bluetooth/hci_event.c        | 1 -
 2 files changed, 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f621c5b..d50cc7a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -316,7 +316,6 @@ struct hci_conn {
 	__u8		attempt;
 	__u8		dev_class[3];
 	__u8		features[HCI_MAX_PAGES][8];
-	__u16		interval;
 	__u16		pkt_type;
 	__u16		link_policy;
 	__u32		link_mode;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 83478da..5935f74 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2551,7 +2551,6 @@ static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
 	if (conn) {
 		conn->mode = ev->mode;
-		conn->interval = __le16_to_cpu(ev->interval);
 
 		if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,
 					&conn->flags)) {
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Bluetooth: Add support for setting DUT mode
From: Marcel Holtmann @ 2013-10-19 10:05 UTC (permalink / raw)
  To: linux-bluetooth

The Device Under Test (DUT) mode is useful for doing certification
testing and so expose this as debugfs option.

This mode is actually special since you can only enter it. Restoring
normal operation means that a HCI Reset is required. The current mode
value gets tracked as a new device flag and when disabling it, the
correct command to reset the controller is sent.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h |  3 ++
 net/bluetooth/hci_core.c    | 72 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ac9c4a7..1784c48 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -115,6 +115,7 @@ enum {
 	HCI_PAIRABLE,
 	HCI_SERVICE_CACHE,
 	HCI_DEBUG_KEYS,
+	HCI_DUT_MODE,
 	HCI_UNREGISTER,
 	HCI_USER_CHANNEL,
 
@@ -1043,6 +1044,8 @@ struct hci_rp_write_remote_amp_assoc {
 	__u8     phy_handle;
 } __packed;
 
+#define HCI_OP_ENABLE_DUT_MODE		0x1803
+
 #define HCI_OP_WRITE_SSP_DEBUG_MODE	0x1804
 
 #define HCI_OP_LE_SET_EVENT_MASK	0x2001
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index bfd0e0e..e30352a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -58,6 +58,70 @@ static void hci_notify(struct hci_dev *hdev, int event)
 
 /* ---- HCI debugfs entries ---- */
 
+static ssize_t dut_mode_read(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	struct hci_dev *hdev = file->private_data;
+	char buf[3];
+
+	buf[0] = test_bit(HCI_DUT_MODE, &hdev->dev_flags) ? 'Y': 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
+			      size_t count, loff_t *ppos)
+{
+	struct hci_dev *hdev = file->private_data;
+	struct sk_buff *skb;
+	char buf[32];
+	size_t buf_size = min(count, (sizeof(buf)-1));
+	bool enable;
+
+	if (!test_bit(HCI_UP, &hdev->flags))
+		return -ENETDOWN;
+
+	if (copy_from_user(buf, user_buf, buf_size))
+		return -EFAULT;
+
+	buf[buf_size] = '\0';
+	if (strtobool(buf, &enable))
+		return -EINVAL;
+
+	if (enable == test_bit(HCI_DUT_MODE, &hdev->dev_flags))
+		return -EALREADY;
+
+	hci_req_lock(hdev);
+	if (enable)
+		skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL,
+				     HCI_CMD_TIMEOUT);
+	else
+		skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
+				     HCI_CMD_TIMEOUT);
+	hci_req_unlock(hdev);
+
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	if (skb->data[0]) {
+		u8 status = skb->data[0];
+		kfree_skb(skb);
+		return -bt_to_errno(status);
+	}
+
+	change_bit(HCI_DUT_MODE, &hdev->dev_flags);
+
+	return count;
+}
+
+static const struct file_operations dut_mode_fops = {
+	.open		= simple_open,
+	.read		= dut_mode_read,
+	.write		= dut_mode_write,
+	.llseek		= default_llseek,
+};
+
 static int features_show(struct seq_file *f, void *ptr)
 {
 	struct hci_dev *hdev = f->private;
@@ -1199,6 +1263,14 @@ static int __hci_init(struct hci_dev *hdev)
 	if (err < 0)
 		return err;
 
+	/* The Device Under Test (DUT) mode is special and available for
+	 * all controller types. So just create it early on.
+	 */
+	if (test_bit(HCI_SETUP, &hdev->dev_flags)) {
+		debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev,
+				    &dut_mode_fops);
+	}
+
 	/* HCI_BREDR covers both single-mode LE, BR/EDR and dual-mode
 	 * BR/EDR/LE type controllers. AMP controllers only need the
 	 * first stage init.
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH] Bluetooth: Add LE features to debugfs if available
From: Marcel Holtmann @ 2013-10-19  9:25 UTC (permalink / raw)
  To: linux-bluetooth

For LE capable controllers at the special LE features page to the
debugfs list with all the other features pages.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/hci_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 8aae80b..bfd0e0e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -65,13 +65,20 @@ static int features_show(struct seq_file *f, void *ptr)
 
 	hci_dev_lock(hdev);
 	for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) {
-		seq_printf(f, "Page %u: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x "
+		seq_printf(f, "%2u: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x "
 			   "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", p,
 			   hdev->features[p][0], hdev->features[p][1],
 			   hdev->features[p][2], hdev->features[p][3],
 			   hdev->features[p][4], hdev->features[p][5],
 			   hdev->features[p][6], hdev->features[p][7]);
 	}
+	if (lmp_le_capable(hdev))
+		seq_printf(f, "LE: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x "
+			   "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n",
+			   hdev->le_features[0], hdev->le_features[1],
+			   hdev->le_features[2], hdev->le_features[3],
+			   hdev->le_features[4], hdev->le_features[5],
+			   hdev->le_features[6], hdev->le_features[7]);
 	hci_dev_unlock(hdev);
 
 	return 0;
-- 
1.8.3.1


^ permalink raw reply related

* [PATCH v2] Bluetooth: Add support for setting SSP debug mode
From: Marcel Holtmann @ 2013-10-19  9:13 UTC (permalink / raw)
  To: linux-bluetooth

Enabling and disabling SSP debug mode is useful for development. This
adds a debugfs entry that allows to configure the SSP debug mode.

On purpose this has been implemented as debugfs entry and not a public
API since it is really only useful during testing and development.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci.h      |  2 ++
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         | 53 +++++++++++++++++++++++++++++++++++++++-
 net/bluetooth/hci_event.c        |  2 ++
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 77a971a..ac9c4a7 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1043,6 +1043,8 @@ struct hci_rp_write_remote_amp_assoc {
 	__u8     phy_handle;
 } __packed;
 
+#define HCI_OP_WRITE_SSP_DEBUG_MODE	0x1804
+
 #define HCI_OP_LE_SET_EVENT_MASK	0x2001
 struct hci_cp_le_set_event_mask {
 	__u8     mask[8];
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 0daac39..f621c5b 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -169,6 +169,7 @@ struct hci_dev {
 	__u8		page_scan_type;
 	__u16		le_scan_interval;
 	__u16		le_scan_window;
+	__u8		ssp_debug_mode;
 
 	__u16		devid_source;
 	__u16		devid_vendor;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 94d5342..8aae80b 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -296,6 +296,54 @@ static int auto_accept_delay_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
 			auto_accept_delay_set, "%llu\n");
 
+static int ssp_debug_mode_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+	struct sk_buff *skb;
+	__u8 mode;
+
+	if (val != 0 && val != 1)
+		return -EINVAL;
+
+	if (!test_bit(HCI_UP, &hdev->flags))
+		return -ENETDOWN;
+
+	hci_req_lock(hdev);
+	mode = val;
+	skb = __hci_cmd_sync(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, sizeof(mode),
+			     &mode, HCI_CMD_TIMEOUT);
+	hci_req_unlock(hdev);
+
+	if (IS_ERR(skb))
+		return PTR_ERR(skb);
+
+	if (skb->data[0]) {
+		u8 status = skb->data[0];
+		kfree_skb(skb);
+		return -bt_to_errno(status);
+	}
+
+	hci_dev_lock(hdev);
+	hdev->ssp_debug_mode = val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int ssp_debug_mode_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->ssp_debug_mode;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(ssp_debug_mode_fops, ssp_debug_mode_get,
+			ssp_debug_mode_set, "%llu\n");
+
 static int idle_timeout_set(void *data, u64 val)
 {
 	struct hci_dev *hdev = data;
@@ -1192,9 +1240,12 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &voice_setting_fops);
 	}
 
-	if (lmp_ssp_capable(hdev))
+	if (lmp_ssp_capable(hdev)) {
 		debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
 				    hdev, &auto_accept_delay_fops);
+		debugfs_create_file("ssp_debug_mode", 0644, hdev->debugfs,
+				    hdev, &ssp_debug_mode_fops);
+	}
 
 	if (lmp_sniff_capable(hdev)) {
 		debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8480452..83478da 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -198,6 +198,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
 
 	memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data));
 	hdev->scan_rsp_data_len = 0;
+
+	hdev->ssp_debug_mode = 0;
 }
 
 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
-- 
1.8.3.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox