linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jukka Rissanen <jukka.rissanen@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v7 5/5] Bluetooth: Manually enable or disable 6LoWPAN between devices
Date: Tue, 10 Dec 2013 13:37:37 +0200	[thread overview]
Message-ID: <1386675457-26024-6-git-send-email-jukka.rissanen@linux.intel.com> (raw)
In-Reply-To: <1386675457-26024-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 8b8b5f8..e289072 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


  parent reply	other threads:[~2013-12-10 11:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-10 11:37 [PATCH v7 0/5] Bluetooth LE 6LoWPAN Jukka Rissanen
2013-12-10 11:37 ` [PATCH v7 1/5] 6lowpan: Moving generic compression code into 6lowpan_iphc.c Jukka Rissanen
2013-12-10 12:08   ` Marcel Holtmann
2013-12-10 11:37 ` [PATCH v7 2/5] net: if_arp: add ARPHRD_6LOWPAN type Jukka Rissanen
2013-12-10 11:37 ` [PATCH v7 3/5] ipv6: Add checks for 6LOWPAN ARP type Jukka Rissanen
2013-12-10 11:37 ` [PATCH v7 4/5] Bluetooth: Enable 6LoWPAN support for BT LE devices Jukka Rissanen
2013-12-10 12:06   ` Marcel Holtmann
2013-12-10 13:15     ` Jukka Rissanen
2013-12-10 11:37 ` Jukka Rissanen [this message]
2013-12-10 11:55   ` [PATCH v7 5/5] Bluetooth: Manually enable or disable 6LoWPAN between devices Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386675457-26024-6-git-send-email-jukka.rissanen@linux.intel.com \
    --to=jukka.rissanen@linux.intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).