Subject: bluetooth class fun --- include/net/bluetooth/bluetooth.h | 2 ++ net/bluetooth/hci_sysfs.c | 10 ++++++++++ net/bluetooth/sco.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -177,4 +177,6 @@ extern void bt_sysfs_cleanup(void); extern struct class *bt_class; +extern struct dentry *bt_debug; + #endif /* __BLUETOOTH_H */ --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c @@ -2,6 +2,7 @@ #include #include +#include #include @@ -264,6 +265,9 @@ static struct device_attribute *conn_att struct class *bt_class = NULL; EXPORT_SYMBOL_GPL(bt_class); +struct dentry *bt_debug; +EXPORT_SYMBOL_GPL(bt_debug); + static struct bus_type bt_bus = { .name = "bluetooth", }; @@ -423,6 +427,10 @@ int __init bt_sysfs_init(void) if (err < 0) goto out_bus; + bt_debug = debugfs_create_dir("bluetooth", NULL); + if (!bt_debug) + goto out_class; + bt_class = class_create(THIS_MODULE, "bluetooth"); if (IS_ERR(bt_class)) { err = PTR_ERR(bt_class); @@ -451,6 +459,8 @@ void bt_sysfs_cleanup(void) class_destroy(bt_class); + debugfs_remove(bt_debug); + bus_unregister(&bt_bus); platform_device_unregister(bt_platform); --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -909,6 +909,38 @@ static ssize_t sco_sysfs_show(struct cla static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL); +static int sco_open(struct inode *inode, struct file *file) +{ + return 0; +} + +static int sco_release(struct inode *inode, struct file *file) +{ + return 0; +} + +static ssize_t sco_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) +{ + read_lock_bh(&sco_sk_list.lock); + + sk_for_each(sk, node, &sco_sk_list.head) { + str += sprintf(str, "%s %s %d\n", + batostr(&bt_sk(sk)->src), batostr(&bt_sk(sk)->dst), + sk->sk_state); + } + + read_unlock_bh(&sco_sk_list.lock); +} + +static const struct file_operations sco_file_ops = { + .owner = THIS_MODULE, + .open = sco_open, + .llseek = no_llseek, + .read = sco_read, + .release = sco_close, +}; + + static const struct proto_ops sco_sock_ops = { .family = PF_BLUETOOTH, .owner = THIS_MODULE, @@ -965,6 +997,9 @@ static int __init sco_init(void) goto error; } + sco_debug = debugfs_create_file("sco", S_IRUGO, bt_debug, NULL, + &sco_fops); + if (class_create_file(bt_class, &class_attr_sco) < 0) BT_ERR("Failed to create SCO info file");