Bluetooth: Use single_open() for inquiry cache within debugfs
[pandora-kernel.git] / net / bluetooth / hci_sysfs.c
index f9d93f9..cafb55b 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
@@ -192,12 +193,30 @@ static inline char *host_bustostr(int bus)
        }
 }
 
+static inline char *host_typetostr(int type)
+{
+       switch (type) {
+       case HCI_BREDR:
+               return "BR/EDR";
+       case HCI_80211:
+               return "802.11";
+       default:
+               return "UNKNOWN";
+       }
+}
+
 static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
        return sprintf(buf, "%s\n", host_bustostr(hdev->bus));
 }
 
+static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type));
+}
+
 static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -334,6 +353,7 @@ static ssize_t store_sniff_min_interval(struct device *dev, struct device_attrib
 }
 
 static DEVICE_ATTR(bus, S_IRUGO, show_bus, NULL);
+static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
 static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
 static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
@@ -351,6 +371,7 @@ static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
 
 static struct attribute *bt_host_attrs[] = {
        &dev_attr_bus.attr,
+       &dev_attr_type.attr,
        &dev_attr_name.attr,
        &dev_attr_class.attr,
        &dev_attr_address.attr,
@@ -385,20 +406,11 @@ static struct device_type bt_host = {
        .release = bt_host_release,
 };
 
-static int inquiry_cache_open(struct inode *inode, struct file *file)
-{
-       file->private_data = inode->i_private;
-       return 0;
-}
-
-static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
-                                               size_t count, loff_t *ppos)
+static int inquiry_cache_show(struct seq_file *f, void *p)
 {
-       struct hci_dev *hdev = file->private_data;
+       struct hci_dev *hdev = f->private;
        struct inquiry_cache *cache = &hdev->inq_cache;
        struct inquiry_entry *e;
-       char buf[4096];
-       int n = 0;
 
        hci_dev_lock_bh(hdev);
 
@@ -406,23 +418,30 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
                struct inquiry_data *data = &e->data;
                bdaddr_t bdaddr;
                baswap(&bdaddr, &data->bdaddr);
-               n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
-                               batostr(&bdaddr),
-                               data->pscan_rep_mode, data->pscan_period_mode,
-                               data->pscan_mode, data->dev_class[2],
-                               data->dev_class[1], data->dev_class[0],
-                               __le16_to_cpu(data->clock_offset),
-                               data->rssi, data->ssp_mode, e->timestamp);
+               seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
+                          batostr(&bdaddr),
+                          data->pscan_rep_mode, data->pscan_period_mode,
+                          data->pscan_mode, data->dev_class[2],
+                          data->dev_class[1], data->dev_class[0],
+                          __le16_to_cpu(data->clock_offset),
+                          data->rssi, data->ssp_mode, e->timestamp);
        }
 
        hci_dev_unlock_bh(hdev);
 
-       return simple_read_from_buffer(userbuf, count, ppos, buf, n);
+       return 0;
+}
+
+static int inquiry_cache_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, inquiry_cache_show, inode->i_private);
 }
 
 static const struct file_operations inquiry_cache_fops = {
-       .open = inquiry_cache_open,
-       .read = inquiry_cache_read,
+       .open           = inquiry_cache_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
 };
 
 int hci_register_sysfs(struct hci_dev *hdev)