diff options
Diffstat (limited to 'net/bluetooth/hci_sysfs.c')
| -rw-r--r-- | net/bluetooth/hci_sysfs.c | 325 |
1 files changed, 264 insertions, 61 deletions
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 0ed38740388c..989b22d9042e 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | /* Bluetooth HCI driver model support. */ | 1 | /* Bluetooth HCI driver model support. */ |
| 2 | 2 | ||
| 3 | #include <linux/config.h> | ||
| 4 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
| 5 | #include <linux/init.h> | 4 | #include <linux/init.h> |
| 6 | 5 | ||
| 6 | #include <linux/platform_device.h> | ||
| 7 | |||
| 7 | #include <net/bluetooth/bluetooth.h> | 8 | #include <net/bluetooth/bluetooth.h> |
| 8 | #include <net/bluetooth/hci_core.h> | 9 | #include <net/bluetooth/hci_core.h> |
| 9 | 10 | ||
| @@ -12,35 +13,63 @@ | |||
| 12 | #define BT_DBG(D...) | 13 | #define BT_DBG(D...) |
| 13 | #endif | 14 | #endif |
| 14 | 15 | ||
| 15 | static ssize_t show_name(struct class_device *cdev, char *buf) | 16 | static inline char *typetostr(int type) |
| 16 | { | 17 | { |
| 17 | struct hci_dev *hdev = class_get_devdata(cdev); | 18 | switch (type) { |
| 18 | return sprintf(buf, "%s\n", hdev->name); | 19 | case HCI_VIRTUAL: |
| 20 | return "VIRTUAL"; | ||
| 21 | case HCI_USB: | ||
| 22 | return "USB"; | ||
| 23 | case HCI_PCCARD: | ||
| 24 | return "PCCARD"; | ||
| 25 | case HCI_UART: | ||
| 26 | return "UART"; | ||
| 27 | case HCI_RS232: | ||
| 28 | return "RS232"; | ||
| 29 | case HCI_PCI: | ||
| 30 | return "PCI"; | ||
| 31 | case HCI_SDIO: | ||
| 32 | return "SDIO"; | ||
| 33 | default: | ||
| 34 | return "UNKNOWN"; | ||
| 35 | } | ||
| 19 | } | 36 | } |
| 20 | 37 | ||
| 21 | static ssize_t show_type(struct class_device *cdev, char *buf) | 38 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 22 | { | 39 | { |
| 23 | struct hci_dev *hdev = class_get_devdata(cdev); | 40 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 24 | return sprintf(buf, "%d\n", hdev->type); | 41 | return sprintf(buf, "%s\n", typetostr(hdev->type)); |
| 25 | } | 42 | } |
| 26 | 43 | ||
| 27 | static ssize_t show_address(struct class_device *cdev, char *buf) | 44 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) |
| 28 | { | 45 | { |
| 29 | struct hci_dev *hdev = class_get_devdata(cdev); | 46 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 30 | bdaddr_t bdaddr; | 47 | bdaddr_t bdaddr; |
| 31 | baswap(&bdaddr, &hdev->bdaddr); | 48 | baswap(&bdaddr, &hdev->bdaddr); |
| 32 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | 49 | return sprintf(buf, "%s\n", batostr(&bdaddr)); |
| 33 | } | 50 | } |
| 34 | 51 | ||
| 35 | static ssize_t show_flags(struct class_device *cdev, char *buf) | 52 | static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) |
| 53 | { | ||
| 54 | struct hci_dev *hdev = dev_get_drvdata(dev); | ||
| 55 | return sprintf(buf, "%d\n", hdev->manufacturer); | ||
| 56 | } | ||
| 57 | |||
| 58 | static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 59 | { | ||
| 60 | struct hci_dev *hdev = dev_get_drvdata(dev); | ||
| 61 | return sprintf(buf, "%d\n", hdev->hci_ver); | ||
| 62 | } | ||
| 63 | |||
| 64 | static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 36 | { | 65 | { |
| 37 | struct hci_dev *hdev = class_get_devdata(cdev); | 66 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 38 | return sprintf(buf, "0x%lx\n", hdev->flags); | 67 | return sprintf(buf, "%d\n", hdev->hci_rev); |
| 39 | } | 68 | } |
| 40 | 69 | ||
| 41 | static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf) | 70 | static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf) |
| 42 | { | 71 | { |
| 43 | struct hci_dev *hdev = class_get_devdata(cdev); | 72 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 44 | struct inquiry_cache *cache = &hdev->inq_cache; | 73 | struct inquiry_cache *cache = &hdev->inq_cache; |
| 45 | struct inquiry_entry *e; | 74 | struct inquiry_entry *e; |
| 46 | int n = 0; | 75 | int n = 0; |
| @@ -62,94 +91,268 @@ static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf) | |||
| 62 | return n; | 91 | return n; |
| 63 | } | 92 | } |
| 64 | 93 | ||
| 65 | static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 94 | static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) |
| 66 | static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL); | 95 | { |
| 67 | static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL); | 96 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 68 | static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); | 97 | return sprintf(buf, "%d\n", hdev->idle_timeout); |
| 69 | static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); | 98 | } |
| 70 | 99 | ||
| 71 | static struct class_device_attribute *bt_attrs[] = { | 100 | static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 72 | &class_device_attr_name, | 101 | { |
| 73 | &class_device_attr_type, | 102 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 74 | &class_device_attr_address, | 103 | char *ptr; |
| 75 | &class_device_attr_flags, | 104 | __u32 val; |
| 76 | &class_device_attr_inquiry_cache, | 105 | |
| 77 | NULL | 106 | val = simple_strtoul(buf, &ptr, 10); |
| 78 | }; | 107 | if (ptr == buf) |
| 108 | return -EINVAL; | ||
| 109 | |||
| 110 | if (val != 0 && (val < 500 || val > 3600000)) | ||
| 111 | return -EINVAL; | ||
| 112 | |||
| 113 | hdev->idle_timeout = val; | ||
| 114 | |||
| 115 | return count; | ||
| 116 | } | ||
| 79 | 117 | ||
| 80 | #ifdef CONFIG_HOTPLUG | 118 | static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) |
| 81 | static int bt_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size) | ||
| 82 | { | 119 | { |
| 83 | struct hci_dev *hdev = class_get_devdata(cdev); | 120 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 84 | int n, i = 0; | 121 | return sprintf(buf, "%d\n", hdev->sniff_max_interval); |
| 122 | } | ||
| 85 | 123 | ||
| 86 | envp[i++] = buf; | 124 | static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 87 | n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1; | 125 | { |
| 88 | buf += n; | 126 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 89 | size -= n; | 127 | char *ptr; |
| 128 | __u16 val; | ||
| 90 | 129 | ||
| 91 | if ((size <= 0) || (i >= num_envp)) | 130 | val = simple_strtoul(buf, &ptr, 10); |
| 92 | return -ENOMEM; | 131 | if (ptr == buf) |
| 132 | return -EINVAL; | ||
| 93 | 133 | ||
| 94 | envp[i] = NULL; | 134 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 95 | return 0; | 135 | return -EINVAL; |
| 136 | |||
| 137 | if (val < hdev->sniff_min_interval) | ||
| 138 | return -EINVAL; | ||
| 139 | |||
| 140 | hdev->sniff_max_interval = val; | ||
| 141 | |||
| 142 | return count; | ||
| 143 | } | ||
| 144 | |||
| 145 | static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 146 | { | ||
| 147 | struct hci_dev *hdev = dev_get_drvdata(dev); | ||
| 148 | return sprintf(buf, "%d\n", hdev->sniff_min_interval); | ||
| 96 | } | 149 | } |
| 97 | #endif | ||
| 98 | 150 | ||
| 99 | static void bt_release(struct class_device *cdev) | 151 | static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 100 | { | 152 | { |
| 101 | struct hci_dev *hdev = class_get_devdata(cdev); | 153 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 154 | char *ptr; | ||
| 155 | __u16 val; | ||
| 156 | |||
| 157 | val = simple_strtoul(buf, &ptr, 10); | ||
| 158 | if (ptr == buf) | ||
| 159 | return -EINVAL; | ||
| 102 | 160 | ||
| 103 | kfree(hdev); | 161 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 162 | return -EINVAL; | ||
| 163 | |||
| 164 | if (val > hdev->sniff_max_interval) | ||
| 165 | return -EINVAL; | ||
| 166 | |||
| 167 | hdev->sniff_min_interval = val; | ||
| 168 | |||
| 169 | return count; | ||
| 104 | } | 170 | } |
| 105 | 171 | ||
| 106 | struct class bt_class = { | 172 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); |
| 107 | .name = "bluetooth", | 173 | static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); |
| 108 | .release = bt_release, | 174 | static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); |
| 109 | #ifdef CONFIG_HOTPLUG | 175 | static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); |
| 110 | .uevent = bt_uevent, | 176 | static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); |
| 111 | #endif | 177 | static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); |
| 178 | |||
| 179 | static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, | ||
| 180 | show_idle_timeout, store_idle_timeout); | ||
| 181 | static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, | ||
| 182 | show_sniff_max_interval, store_sniff_max_interval); | ||
| 183 | static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, | ||
| 184 | show_sniff_min_interval, store_sniff_min_interval); | ||
| 185 | |||
| 186 | static struct device_attribute *bt_attrs[] = { | ||
| 187 | &dev_attr_type, | ||
| 188 | &dev_attr_address, | ||
| 189 | &dev_attr_manufacturer, | ||
| 190 | &dev_attr_hci_version, | ||
| 191 | &dev_attr_hci_revision, | ||
| 192 | &dev_attr_inquiry_cache, | ||
| 193 | &dev_attr_idle_timeout, | ||
| 194 | &dev_attr_sniff_max_interval, | ||
| 195 | &dev_attr_sniff_min_interval, | ||
| 196 | NULL | ||
| 112 | }; | 197 | }; |
| 113 | 198 | ||
| 199 | static ssize_t show_conn_type(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 200 | { | ||
| 201 | struct hci_conn *conn = dev_get_drvdata(dev); | ||
| 202 | return sprintf(buf, "%s\n", conn->type == ACL_LINK ? "ACL" : "SCO"); | ||
| 203 | } | ||
| 204 | |||
| 205 | static ssize_t show_conn_address(struct device *dev, struct device_attribute *attr, char *buf) | ||
| 206 | { | ||
| 207 | struct hci_conn *conn = dev_get_drvdata(dev); | ||
| 208 | bdaddr_t bdaddr; | ||
| 209 | baswap(&bdaddr, &conn->dst); | ||
| 210 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | ||
| 211 | } | ||
| 212 | |||
| 213 | #define CONN_ATTR(_name,_mode,_show,_store) \ | ||
| 214 | struct device_attribute conn_attr_##_name = __ATTR(_name,_mode,_show,_store) | ||
| 215 | |||
| 216 | static CONN_ATTR(type, S_IRUGO, show_conn_type, NULL); | ||
| 217 | static CONN_ATTR(address, S_IRUGO, show_conn_address, NULL); | ||
| 218 | |||
| 219 | static struct device_attribute *conn_attrs[] = { | ||
| 220 | &conn_attr_type, | ||
| 221 | &conn_attr_address, | ||
| 222 | NULL | ||
| 223 | }; | ||
| 224 | |||
| 225 | struct class *bt_class = NULL; | ||
| 114 | EXPORT_SYMBOL_GPL(bt_class); | 226 | EXPORT_SYMBOL_GPL(bt_class); |
| 115 | 227 | ||
| 228 | static struct bus_type bt_bus = { | ||
| 229 | .name = "bluetooth", | ||
| 230 | }; | ||
| 231 | |||
| 232 | static struct platform_device *bt_platform; | ||
| 233 | |||
| 234 | static void bt_release(struct device *dev) | ||
| 235 | { | ||
| 236 | void *data = dev_get_drvdata(dev); | ||
| 237 | kfree(data); | ||
| 238 | } | ||
| 239 | |||
| 240 | static void add_conn(void *data) | ||
| 241 | { | ||
| 242 | struct hci_conn *conn = data; | ||
| 243 | int i; | ||
| 244 | |||
| 245 | device_register(&conn->dev); | ||
| 246 | |||
| 247 | for (i = 0; conn_attrs[i]; i++) | ||
| 248 | device_create_file(&conn->dev, conn_attrs[i]); | ||
| 249 | } | ||
| 250 | |||
| 251 | void hci_conn_add_sysfs(struct hci_conn *conn) | ||
| 252 | { | ||
| 253 | struct hci_dev *hdev = conn->hdev; | ||
| 254 | bdaddr_t *ba = &conn->dst; | ||
| 255 | |||
| 256 | BT_DBG("conn %p", conn); | ||
| 257 | |||
| 258 | conn->dev.parent = &hdev->dev; | ||
| 259 | conn->dev.release = bt_release; | ||
| 260 | |||
| 261 | snprintf(conn->dev.bus_id, BUS_ID_SIZE, | ||
| 262 | "%s%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", | ||
| 263 | conn->type == ACL_LINK ? "acl" : "sco", | ||
| 264 | ba->b[5], ba->b[4], ba->b[3], | ||
| 265 | ba->b[2], ba->b[1], ba->b[0]); | ||
| 266 | |||
| 267 | dev_set_drvdata(&conn->dev, conn); | ||
| 268 | |||
| 269 | INIT_WORK(&conn->work, add_conn, (void *) conn); | ||
| 270 | |||
| 271 | schedule_work(&conn->work); | ||
| 272 | } | ||
| 273 | |||
| 274 | static void del_conn(void *data) | ||
| 275 | { | ||
| 276 | struct hci_conn *conn = data; | ||
| 277 | device_del(&conn->dev); | ||
| 278 | } | ||
| 279 | |||
| 280 | void hci_conn_del_sysfs(struct hci_conn *conn) | ||
| 281 | { | ||
| 282 | BT_DBG("conn %p", conn); | ||
| 283 | |||
| 284 | INIT_WORK(&conn->work, del_conn, (void *) conn); | ||
| 285 | |||
| 286 | schedule_work(&conn->work); | ||
| 287 | } | ||
| 288 | |||
| 116 | int hci_register_sysfs(struct hci_dev *hdev) | 289 | int hci_register_sysfs(struct hci_dev *hdev) |
| 117 | { | 290 | { |
| 118 | struct class_device *cdev = &hdev->class_dev; | 291 | struct device *dev = &hdev->dev; |
| 119 | unsigned int i; | 292 | unsigned int i; |
| 120 | int err; | 293 | int err; |
| 121 | 294 | ||
| 122 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 295 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 123 | 296 | ||
| 124 | cdev->class = &bt_class; | 297 | dev->class = bt_class; |
| 125 | class_set_devdata(cdev, hdev); | ||
| 126 | 298 | ||
| 127 | strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE); | 299 | if (hdev->parent) |
| 128 | err = class_device_register(cdev); | 300 | dev->parent = hdev->parent; |
| 301 | else | ||
| 302 | dev->parent = &bt_platform->dev; | ||
| 303 | |||
| 304 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); | ||
| 305 | |||
| 306 | dev->release = bt_release; | ||
| 307 | |||
| 308 | dev_set_drvdata(dev, hdev); | ||
| 309 | |||
| 310 | err = device_register(dev); | ||
| 129 | if (err < 0) | 311 | if (err < 0) |
| 130 | return err; | 312 | return err; |
| 131 | 313 | ||
| 132 | for (i = 0; bt_attrs[i]; i++) | 314 | for (i = 0; bt_attrs[i]; i++) |
| 133 | class_device_create_file(cdev, bt_attrs[i]); | 315 | device_create_file(dev, bt_attrs[i]); |
| 134 | 316 | ||
| 135 | return 0; | 317 | return 0; |
| 136 | } | 318 | } |
| 137 | 319 | ||
| 138 | void hci_unregister_sysfs(struct hci_dev *hdev) | 320 | void hci_unregister_sysfs(struct hci_dev *hdev) |
| 139 | { | 321 | { |
| 140 | struct class_device * cdev = &hdev->class_dev; | ||
| 141 | |||
| 142 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 322 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 143 | 323 | ||
| 144 | class_device_del(cdev); | 324 | device_del(&hdev->dev); |
| 145 | } | 325 | } |
| 146 | 326 | ||
| 147 | int __init bt_sysfs_init(void) | 327 | int __init bt_sysfs_init(void) |
| 148 | { | 328 | { |
| 149 | return class_register(&bt_class); | 329 | int err; |
| 330 | |||
| 331 | bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0); | ||
| 332 | if (IS_ERR(bt_platform)) | ||
| 333 | return PTR_ERR(bt_platform); | ||
| 334 | |||
| 335 | err = bus_register(&bt_bus); | ||
| 336 | if (err < 0) { | ||
| 337 | platform_device_unregister(bt_platform); | ||
| 338 | return err; | ||
| 339 | } | ||
| 340 | |||
| 341 | bt_class = class_create(THIS_MODULE, "bluetooth"); | ||
| 342 | if (IS_ERR(bt_class)) { | ||
| 343 | bus_unregister(&bt_bus); | ||
| 344 | platform_device_unregister(bt_platform); | ||
| 345 | return PTR_ERR(bt_class); | ||
| 346 | } | ||
| 347 | |||
| 348 | return 0; | ||
| 150 | } | 349 | } |
| 151 | 350 | ||
| 152 | void __exit bt_sysfs_cleanup(void) | 351 | void bt_sysfs_cleanup(void) |
| 153 | { | 352 | { |
| 154 | class_unregister(&bt_class); | 353 | class_destroy(bt_class); |
| 354 | |||
| 355 | bus_unregister(&bt_bus); | ||
| 356 | |||
| 357 | platform_device_unregister(bt_platform); | ||
| 155 | } | 358 | } |
