Linux bluetooth development
 help / color / mirror / Atom feed
From: Jukka Rissanen <jukka.rissanen@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [RFC v4 6/6] Bluetooth: Manually enable or disable 6LoWPAN between devices
Date: Wed, 13 Nov 2013 12:11:35 +0200	[thread overview]
Message-ID: <1384337495-9043-7-git-send-email-jukka.rissanen@linux.intel.com> (raw)
In-Reply-To: <1384337495-9043-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/6lowpan.c  | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/6lowpan.h  |   1 +
 net/bluetooth/hci_core.c |   4 ++
 3 files changed, 110 insertions(+)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 5f0489c..579a75f 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -26,6 +26,8 @@
  */
 
 #include <linux/version.h>
+#include <linux/debugfs.h>
+#include <linux/string.h>
 #include <linux/bitops.h>
 #include <linux/if_arp.h>
 #include <linux/netdevice.h>
@@ -1571,6 +1573,109 @@ static struct notifier_block bt_6lowpan_dev_notifier = {
 	.notifier_call = device_event,
 };
 
+static LIST_HEAD(user_enabled);
+DEFINE_RWLOCK(enabled_lock);
+
+struct lowpan_enabled {
+	__u8 dev_name[HCI_MAX_NAME_LENGTH];
+	bool enabled;
+	struct list_head list;
+};
+
+static int debugfs_show(struct seq_file *f, void *p)
+{
+	struct lowpan_enabled *entry, *tmp;
+	bool found = false;
+
+	write_lock(&enabled_lock);
+	list_for_each_entry_safe(entry, tmp, &user_enabled, list) {
+		seq_printf(f, "%d\n", entry->enabled);
+		found = true;
+	}
+	write_unlock(&enabled_lock);
+
+	if (!found)
+		seq_printf(f, "0\n");
+
+	return 0;
+}
+
+static int debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, debugfs_show, inode->i_private);
+}
+
+static ssize_t 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(&enabled_lock);
+	list_for_each_entry_safe(entry, tmp, &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(&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(&enabled_lock);
+		INIT_LIST_HEAD(&entry->list);
+		list_add(&entry->list, &user_enabled);
+		write_unlock(&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 ble_6lowpan_debugfs_fops = {
+	.open		= debugfs_open,
+	.read		= seq_read,
+	.write		= writer,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
+void bt_6lowpan_add_debugfs(struct hci_dev *hdev)
+{
+	debugfs_create_file("6lowpan", 0644, hdev->debugfs, hdev,
+			&ble_6lowpan_debugfs_fops);
+}
+
 int bt_6lowpan_init(void)
 {
 	return register_netdevice_notifier(&bt_6lowpan_dev_notifier);
diff --git a/net/bluetooth/6lowpan.h b/net/bluetooth/6lowpan.h
index 680eac8..5f60cf2 100644
--- a/net/bluetooth/6lowpan.h
+++ b/net/bluetooth/6lowpan.h
@@ -22,5 +22,6 @@ int bt_6lowpan_add_conn(struct l2cap_conn *conn);
 int bt_6lowpan_del_conn(struct l2cap_conn *conn);
 int bt_6lowpan_init(void);
 void bt_6lowpan_cleanup(void);
+void bt_6lowpan_add_debugfs(struct hci_dev *hdev);
 
 #endif /* __6LOWPAN_H */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 03e8355..a229ce0 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -34,6 +34,8 @@
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 
+#include "6lowpan.h"
+
 static void hci_rx_work(struct work_struct *work);
 static void hci_cmd_work(struct work_struct *work);
 static void hci_tx_work(struct work_struct *work);
@@ -1408,6 +1410,8 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &conn_max_interval_fops);
 	}
 
+	bt_6lowpan_add_debugfs(hdev);
+
 	return 0;
 }
 
-- 
1.8.3.1


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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13 10:11 [RFC v4 0/6] Bluetooth LE 6LoWPAN Jukka Rissanen
2013-11-13 10:11 ` [RFC v4 1/6] net: if_arp: add ARPHRD_RAWIP type Jukka Rissanen
2013-11-13 10:11 ` [RFC v4 2/6] ipv6: Add checks for RAWIP ARP type Jukka Rissanen
2013-11-13 10:11 ` [RFC v4 3/6] Bluetooth: Initial skeleton code for BT 6LoWPAN Jukka Rissanen
2013-11-14  7:58   ` Marcel Holtmann
2013-11-13 10:11 ` [RFC v4 4/6] Bluetooth: Enable 6LoWPAN support for BT LE devices Jukka Rissanen
2013-11-13 10:11 ` [RFC v4 5/6] Bluetooth: Enable 6LoWPAN if device supports it Jukka Rissanen
2013-11-13 10:11 ` Jukka Rissanen [this message]
2013-11-14  8:07   ` [RFC v4 6/6] 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=1384337495-9043-7-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