diff options
Diffstat (limited to 'net/bluetooth/hci_sysfs.c')
| -rw-r--r-- | net/bluetooth/hci_sysfs.c | 211 | 
1 files changed, 156 insertions, 55 deletions
| diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 19b234c86f33..3987d167f04e 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> | 
| 4 | #include <linux/init.h> | 4 | #include <linux/init.h> | 
| 5 | 5 | ||
| 6 | #include <linux/platform_device.h> | ||
| 7 | |||
| 6 | #include <net/bluetooth/bluetooth.h> | 8 | #include <net/bluetooth/bluetooth.h> | 
| 7 | #include <net/bluetooth/hci_core.h> | 9 | #include <net/bluetooth/hci_core.h> | 
| 8 | 10 | ||
| @@ -11,35 +13,35 @@ | |||
| 11 | #define BT_DBG(D...) | 13 | #define BT_DBG(D...) | 
| 12 | #endif | 14 | #endif | 
| 13 | 15 | ||
| 14 | static ssize_t show_name(struct class_device *cdev, char *buf) | 16 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) | 
| 15 | { | 17 | { | 
| 16 | struct hci_dev *hdev = class_get_devdata(cdev); | 18 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 17 | return sprintf(buf, "%s\n", hdev->name); | 19 | return sprintf(buf, "%s\n", hdev->name); | 
| 18 | } | 20 | } | 
| 19 | 21 | ||
| 20 | static ssize_t show_type(struct class_device *cdev, char *buf) | 22 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) | 
| 21 | { | 23 | { | 
| 22 | struct hci_dev *hdev = class_get_devdata(cdev); | 24 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 23 | return sprintf(buf, "%d\n", hdev->type); | 25 | return sprintf(buf, "%d\n", hdev->type); | 
| 24 | } | 26 | } | 
| 25 | 27 | ||
| 26 | static ssize_t show_address(struct class_device *cdev, char *buf) | 28 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) | 
| 27 | { | 29 | { | 
| 28 | struct hci_dev *hdev = class_get_devdata(cdev); | 30 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 29 | bdaddr_t bdaddr; | 31 | bdaddr_t bdaddr; | 
| 30 | baswap(&bdaddr, &hdev->bdaddr); | 32 | baswap(&bdaddr, &hdev->bdaddr); | 
| 31 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | 33 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | 
| 32 | } | 34 | } | 
| 33 | 35 | ||
| 34 | static ssize_t show_flags(struct class_device *cdev, char *buf) | 36 | static ssize_t show_flags(struct device *dev, struct device_attribute *attr, char *buf) | 
| 35 | { | 37 | { | 
| 36 | struct hci_dev *hdev = class_get_devdata(cdev); | 38 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 37 | return sprintf(buf, "0x%lx\n", hdev->flags); | 39 | return sprintf(buf, "0x%lx\n", hdev->flags); | 
| 38 | } | 40 | } | 
| 39 | 41 | ||
| 40 | static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf) | 42 | static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf) | 
| 41 | { | 43 | { | 
| 42 | struct hci_dev *hdev = class_get_devdata(cdev); | 44 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 43 | struct inquiry_cache *cache = &hdev->inq_cache; | 45 | struct inquiry_cache *cache = &hdev->inq_cache; | 
| 44 | struct inquiry_entry *e; | 46 | struct inquiry_entry *e; | 
| 45 | int n = 0; | 47 | int n = 0; | 
| @@ -61,94 +63,193 @@ static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf) | |||
| 61 | return n; | 63 | return n; | 
| 62 | } | 64 | } | 
| 63 | 65 | ||
| 64 | static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 66 | static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) | 
| 65 | static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL); | 67 | { | 
| 66 | static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL); | 68 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 67 | static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); | 69 | return sprintf(buf, "%d\n", hdev->idle_timeout); | 
| 68 | static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); | 70 | } | 
| 69 | 71 | ||
| 70 | static struct class_device_attribute *bt_attrs[] = { | 72 | static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| 71 | &class_device_attr_name, | 73 | { | 
| 72 | &class_device_attr_type, | 74 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 73 | &class_device_attr_address, | 75 | char *ptr; | 
| 74 | &class_device_attr_flags, | 76 | __u32 val; | 
| 75 | &class_device_attr_inquiry_cache, | 77 | |
| 76 | NULL | 78 | val = simple_strtoul(buf, &ptr, 10); | 
| 77 | }; | 79 | if (ptr == buf) | 
| 80 | return -EINVAL; | ||
| 78 | 81 | ||
| 79 | #ifdef CONFIG_HOTPLUG | 82 | if (val != 0 && (val < 500 || val > 3600000)) | 
| 80 | static int bt_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size) | 83 | return -EINVAL; | 
| 84 | |||
| 85 | hdev->idle_timeout = val; | ||
| 86 | |||
| 87 | return count; | ||
| 88 | } | ||
| 89 | |||
| 90 | static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 81 | { | 91 | { | 
| 82 | struct hci_dev *hdev = class_get_devdata(cdev); | 92 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 83 | int n, i = 0; | 93 | return sprintf(buf, "%d\n", hdev->sniff_max_interval); | 
| 94 | } | ||
| 84 | 95 | ||
| 85 | envp[i++] = buf; | 96 | static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| 86 | n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1; | 97 | { | 
| 87 | buf += n; | 98 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 88 | size -= n; | 99 | char *ptr; | 
| 100 | __u16 val; | ||
| 89 | 101 | ||
| 90 | if ((size <= 0) || (i >= num_envp)) | 102 | val = simple_strtoul(buf, &ptr, 10); | 
| 91 | return -ENOMEM; | 103 | if (ptr == buf) | 
| 104 | return -EINVAL; | ||
| 92 | 105 | ||
| 93 | envp[i] = NULL; | 106 | if (val < 0x0002 || val > 0xFFFE || val % 2) | 
| 94 | return 0; | 107 | return -EINVAL; | 
| 108 | |||
| 109 | if (val < hdev->sniff_min_interval) | ||
| 110 | return -EINVAL; | ||
| 111 | |||
| 112 | hdev->sniff_max_interval = val; | ||
| 113 | |||
| 114 | return count; | ||
| 115 | } | ||
| 116 | |||
| 117 | static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 118 | { | ||
| 119 | struct hci_dev *hdev = dev_get_drvdata(dev); | ||
| 120 | return sprintf(buf, "%d\n", hdev->sniff_min_interval); | ||
| 95 | } | 121 | } | 
| 96 | #endif | ||
| 97 | 122 | ||
| 98 | static void bt_release(struct class_device *cdev) | 123 | static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 
| 99 | { | 124 | { | 
| 100 | struct hci_dev *hdev = class_get_devdata(cdev); | 125 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| 126 | char *ptr; | ||
| 127 | __u16 val; | ||
| 101 | 128 | ||
| 102 | kfree(hdev); | 129 | val = simple_strtoul(buf, &ptr, 10); | 
| 130 | if (ptr == buf) | ||
| 131 | return -EINVAL; | ||
| 132 | |||
| 133 | if (val < 0x0002 || val > 0xFFFE || val % 2) | ||
| 134 | return -EINVAL; | ||
| 135 | |||
| 136 | if (val > hdev->sniff_max_interval) | ||
| 137 | return -EINVAL; | ||
| 138 | |||
| 139 | hdev->sniff_min_interval = val; | ||
| 140 | |||
| 141 | return count; | ||
| 103 | } | 142 | } | 
| 104 | 143 | ||
| 105 | struct class bt_class = { | 144 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 
| 106 | .name = "bluetooth", | 145 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); | 
| 107 | .release = bt_release, | 146 | static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); | 
| 108 | #ifdef CONFIG_HOTPLUG | 147 | static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); | 
| 109 | .uevent = bt_uevent, | 148 | static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); | 
| 110 | #endif | 149 | |
| 150 | static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, | ||
| 151 | show_idle_timeout, store_idle_timeout); | ||
| 152 | static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, | ||
| 153 | show_sniff_max_interval, store_sniff_max_interval); | ||
| 154 | static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, | ||
| 155 | show_sniff_min_interval, store_sniff_min_interval); | ||
| 156 | |||
| 157 | static struct device_attribute *bt_attrs[] = { | ||
| 158 | &dev_attr_name, | ||
| 159 | &dev_attr_type, | ||
| 160 | &dev_attr_address, | ||
| 161 | &dev_attr_flags, | ||
| 162 | &dev_attr_inquiry_cache, | ||
| 163 | &dev_attr_idle_timeout, | ||
| 164 | &dev_attr_sniff_max_interval, | ||
| 165 | &dev_attr_sniff_min_interval, | ||
| 166 | NULL | ||
| 111 | }; | 167 | }; | 
| 112 | 168 | ||
| 169 | struct class *bt_class = NULL; | ||
| 113 | EXPORT_SYMBOL_GPL(bt_class); | 170 | EXPORT_SYMBOL_GPL(bt_class); | 
| 114 | 171 | ||
| 172 | static struct bus_type bt_bus = { | ||
| 173 | .name = "bluetooth", | ||
| 174 | }; | ||
| 175 | |||
| 176 | static struct platform_device *bt_platform; | ||
| 177 | |||
| 178 | static void bt_release(struct device *dev) | ||
| 179 | { | ||
| 180 | struct hci_dev *hdev = dev_get_drvdata(dev); | ||
| 181 | kfree(hdev); | ||
| 182 | } | ||
| 183 | |||
| 115 | int hci_register_sysfs(struct hci_dev *hdev) | 184 | int hci_register_sysfs(struct hci_dev *hdev) | 
| 116 | { | 185 | { | 
| 117 | struct class_device *cdev = &hdev->class_dev; | 186 | struct device *dev = &hdev->dev; | 
| 118 | unsigned int i; | 187 | unsigned int i; | 
| 119 | int err; | 188 | int err; | 
| 120 | 189 | ||
| 121 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 190 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 
| 122 | 191 | ||
| 123 | cdev->class = &bt_class; | 192 | dev->class = bt_class; | 
| 124 | class_set_devdata(cdev, hdev); | 193 | |
| 194 | if (hdev->parent) | ||
| 195 | dev->parent = hdev->parent; | ||
| 196 | else | ||
| 197 | dev->parent = &bt_platform->dev; | ||
| 198 | |||
| 199 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); | ||
| 200 | |||
| 201 | dev->release = bt_release; | ||
| 125 | 202 | ||
| 126 | strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE); | 203 | dev_set_drvdata(dev, hdev); | 
| 127 | err = class_device_register(cdev); | 204 | |
| 205 | err = device_register(dev); | ||
| 128 | if (err < 0) | 206 | if (err < 0) | 
| 129 | return err; | 207 | return err; | 
| 130 | 208 | ||
| 131 | for (i = 0; bt_attrs[i]; i++) | 209 | for (i = 0; bt_attrs[i]; i++) | 
| 132 | class_device_create_file(cdev, bt_attrs[i]); | 210 | device_create_file(dev, bt_attrs[i]); | 
| 133 | 211 | ||
| 134 | return 0; | 212 | return 0; | 
| 135 | } | 213 | } | 
| 136 | 214 | ||
| 137 | void hci_unregister_sysfs(struct hci_dev *hdev) | 215 | void hci_unregister_sysfs(struct hci_dev *hdev) | 
| 138 | { | 216 | { | 
| 139 | struct class_device * cdev = &hdev->class_dev; | 217 | struct device *dev = &hdev->dev; | 
| 140 | 218 | ||
| 141 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 219 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 
| 142 | 220 | ||
| 143 | class_device_del(cdev); | 221 | device_del(dev); | 
| 144 | } | 222 | } | 
| 145 | 223 | ||
| 146 | int __init bt_sysfs_init(void) | 224 | int __init bt_sysfs_init(void) | 
| 147 | { | 225 | { | 
| 148 | return class_register(&bt_class); | 226 | int err; | 
| 227 | |||
| 228 | bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0); | ||
| 229 | if (IS_ERR(bt_platform)) | ||
| 230 | return PTR_ERR(bt_platform); | ||
| 231 | |||
| 232 | err = bus_register(&bt_bus); | ||
| 233 | if (err < 0) { | ||
| 234 | platform_device_unregister(bt_platform); | ||
| 235 | return err; | ||
| 236 | } | ||
| 237 | |||
| 238 | bt_class = class_create(THIS_MODULE, "bluetooth"); | ||
| 239 | if (IS_ERR(bt_class)) { | ||
| 240 | bus_unregister(&bt_bus); | ||
| 241 | platform_device_unregister(bt_platform); | ||
| 242 | return PTR_ERR(bt_class); | ||
| 243 | } | ||
| 244 | |||
| 245 | return 0; | ||
| 149 | } | 246 | } | 
| 150 | 247 | ||
| 151 | void __exit bt_sysfs_cleanup(void) | 248 | void __exit bt_sysfs_cleanup(void) | 
| 152 | { | 249 | { | 
| 153 | class_unregister(&bt_class); | 250 | class_destroy(bt_class); | 
| 251 | |||
| 252 | bus_unregister(&bt_bus); | ||
| 253 | |||
| 254 | platform_device_unregister(bt_platform); | ||
| 154 | } | 255 | } | 
