aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-02-08 10:22:31 -0500
committerMarcel Holtmann <marcel@holtmann.org>2010-02-27 08:05:38 -0500
commitca325f698996c1a0770a67f41e7dc97a007d8bc2 (patch)
tree8232f4c0cf8a2bef09b883280d3742735776c842 /net/bluetooth
parentc13854cef4751000b968d4e8ac95796562d5b96f (diff)
Bluetooth: Convert inquiry cache to use debugfs instead of sysfs
The output of the inquiry cache is only useful for debugging purposes and so move it into debugfs. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_sysfs.c92
1 files changed, 62 insertions, 30 deletions
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 9b5f376813b7..f9d93f9cbcd2 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -2,6 +2,7 @@
2 2
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/debugfs.h>
5 6
6#include <net/bluetooth/bluetooth.h> 7#include <net/bluetooth/bluetooth.h>
7#include <net/bluetooth/hci_core.h> 8#include <net/bluetooth/hci_core.h>
@@ -9,6 +10,9 @@
9struct class *bt_class = NULL; 10struct class *bt_class = NULL;
10EXPORT_SYMBOL_GPL(bt_class); 11EXPORT_SYMBOL_GPL(bt_class);
11 12
13struct dentry *bt_debugfs = NULL;
14EXPORT_SYMBOL_GPL(bt_debugfs);
15
12static struct workqueue_struct *bt_workq; 16static struct workqueue_struct *bt_workq;
13 17
14static inline char *link_typetostr(int type) 18static inline char *link_typetostr(int type)
@@ -251,32 +255,6 @@ static ssize_t show_hci_revision(struct device *dev, struct device_attribute *at
251 return sprintf(buf, "%d\n", hdev->hci_rev); 255 return sprintf(buf, "%d\n", hdev->hci_rev);
252} 256}
253 257
254static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
255{
256 struct hci_dev *hdev = dev_get_drvdata(dev);
257 struct inquiry_cache *cache = &hdev->inq_cache;
258 struct inquiry_entry *e;
259 int n = 0;
260
261 hci_dev_lock_bh(hdev);
262
263 for (e = cache->list; e; e = e->next) {
264 struct inquiry_data *data = &e->data;
265 bdaddr_t bdaddr;
266 baswap(&bdaddr, &data->bdaddr);
267 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
268 batostr(&bdaddr),
269 data->pscan_rep_mode, data->pscan_period_mode,
270 data->pscan_mode, data->dev_class[2],
271 data->dev_class[1], data->dev_class[0],
272 __le16_to_cpu(data->clock_offset),
273 data->rssi, data->ssp_mode, e->timestamp);
274 }
275
276 hci_dev_unlock_bh(hdev);
277 return n;
278}
279
280static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) 258static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
281{ 259{
282 struct hci_dev *hdev = dev_get_drvdata(dev); 260 struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -363,7 +341,6 @@ static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
363static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); 341static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
364static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); 342static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
365static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); 343static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
366static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
367 344
368static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, 345static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
369 show_idle_timeout, store_idle_timeout); 346 show_idle_timeout, store_idle_timeout);
@@ -381,7 +358,6 @@ static struct attribute *bt_host_attrs[] = {
381 &dev_attr_manufacturer.attr, 358 &dev_attr_manufacturer.attr,
382 &dev_attr_hci_version.attr, 359 &dev_attr_hci_version.attr,
383 &dev_attr_hci_revision.attr, 360 &dev_attr_hci_revision.attr,
384 &dev_attr_inquiry_cache.attr,
385 &dev_attr_idle_timeout.attr, 361 &dev_attr_idle_timeout.attr,
386 &dev_attr_sniff_max_interval.attr, 362 &dev_attr_sniff_max_interval.attr,
387 &dev_attr_sniff_min_interval.attr, 363 &dev_attr_sniff_min_interval.attr,
@@ -409,6 +385,46 @@ static struct device_type bt_host = {
409 .release = bt_host_release, 385 .release = bt_host_release,
410}; 386};
411 387
388static int inquiry_cache_open(struct inode *inode, struct file *file)
389{
390 file->private_data = inode->i_private;
391 return 0;
392}
393
394static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
395 size_t count, loff_t *ppos)
396{
397 struct hci_dev *hdev = file->private_data;
398 struct inquiry_cache *cache = &hdev->inq_cache;
399 struct inquiry_entry *e;
400 char buf[4096];
401 int n = 0;
402
403 hci_dev_lock_bh(hdev);
404
405 for (e = cache->list; e; e = e->next) {
406 struct inquiry_data *data = &e->data;
407 bdaddr_t bdaddr;
408 baswap(&bdaddr, &data->bdaddr);
409 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
410 batostr(&bdaddr),
411 data->pscan_rep_mode, data->pscan_period_mode,
412 data->pscan_mode, data->dev_class[2],
413 data->dev_class[1], data->dev_class[0],
414 __le16_to_cpu(data->clock_offset),
415 data->rssi, data->ssp_mode, e->timestamp);
416 }
417
418 hci_dev_unlock_bh(hdev);
419
420 return simple_read_from_buffer(userbuf, count, ppos, buf, n);
421}
422
423static const struct file_operations inquiry_cache_fops = {
424 .open = inquiry_cache_open,
425 .read = inquiry_cache_read,
426};
427
412int hci_register_sysfs(struct hci_dev *hdev) 428int hci_register_sysfs(struct hci_dev *hdev)
413{ 429{
414 struct device *dev = &hdev->dev; 430 struct device *dev = &hdev->dev;
@@ -428,6 +444,16 @@ int hci_register_sysfs(struct hci_dev *hdev)
428 if (err < 0) 444 if (err < 0)
429 return err; 445 return err;
430 446
447 if (!bt_debugfs)
448 return 0;
449
450 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs);
451 if (!hdev->debugfs)
452 return 0;
453
454 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
455 hdev, &inquiry_cache_fops);
456
431 return 0; 457 return 0;
432} 458}
433 459
@@ -435,6 +461,8 @@ void hci_unregister_sysfs(struct hci_dev *hdev)
435{ 461{
436 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); 462 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
437 463
464 debugfs_remove_recursive(hdev->debugfs);
465
438 device_del(&hdev->dev); 466 device_del(&hdev->dev);
439} 467}
440 468
@@ -444,6 +472,8 @@ int __init bt_sysfs_init(void)
444 if (!bt_workq) 472 if (!bt_workq)
445 return -ENOMEM; 473 return -ENOMEM;
446 474
475 bt_debugfs = debugfs_create_dir("bluetooth", NULL);
476
447 bt_class = class_create(THIS_MODULE, "bluetooth"); 477 bt_class = class_create(THIS_MODULE, "bluetooth");
448 if (IS_ERR(bt_class)) { 478 if (IS_ERR(bt_class)) {
449 destroy_workqueue(bt_workq); 479 destroy_workqueue(bt_workq);
@@ -455,7 +485,9 @@ int __init bt_sysfs_init(void)
455 485
456void bt_sysfs_cleanup(void) 486void bt_sysfs_cleanup(void)
457{ 487{
458 destroy_workqueue(bt_workq);
459
460 class_destroy(bt_class); 488 class_destroy(bt_class);
489
490 debugfs_remove_recursive(bt_debugfs);
491
492 destroy_workqueue(bt_workq);
461} 493}