Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Bluetooth HCI driver model support. */ |
| 2 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 6 | #include <linux/debugfs.h> |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 7 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | #include <net/bluetooth/bluetooth.h> |
| 10 | #include <net/bluetooth/hci_core.h> |
| 11 | |
Marcel Holtmann | aef7d97 | 2010-03-21 05:27:45 +0100 | [diff] [blame] | 12 | static struct class *bt_class; |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 13 | |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 14 | struct dentry *bt_debugfs = NULL; |
| 15 | EXPORT_SYMBOL_GPL(bt_debugfs); |
| 16 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 17 | static inline char *link_typetostr(int type) |
| 18 | { |
| 19 | switch (type) { |
| 20 | case ACL_LINK: |
| 21 | return "ACL"; |
| 22 | case SCO_LINK: |
| 23 | return "SCO"; |
| 24 | case ESCO_LINK: |
| 25 | return "eSCO"; |
| 26 | default: |
| 27 | return "UNKNOWN"; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | static ssize_t show_link_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 32 | { |
| 33 | struct hci_conn *conn = dev_get_drvdata(dev); |
| 34 | return sprintf(buf, "%s\n", link_typetostr(conn->type)); |
| 35 | } |
| 36 | |
| 37 | static ssize_t show_link_address(struct device *dev, struct device_attribute *attr, char *buf) |
| 38 | { |
| 39 | struct hci_conn *conn = dev_get_drvdata(dev); |
Gustavo F. Padovan | d6b2eb2 | 2010-09-03 18:29:46 -0300 | [diff] [blame] | 40 | return sprintf(buf, "%s\n", batostr(&conn->dst)); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static ssize_t show_link_features(struct device *dev, struct device_attribute *attr, char *buf) |
| 44 | { |
| 45 | struct hci_conn *conn = dev_get_drvdata(dev); |
| 46 | |
| 47 | return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 48 | conn->features[0], conn->features[1], |
| 49 | conn->features[2], conn->features[3], |
| 50 | conn->features[4], conn->features[5], |
| 51 | conn->features[6], conn->features[7]); |
| 52 | } |
| 53 | |
| 54 | #define LINK_ATTR(_name,_mode,_show,_store) \ |
| 55 | struct device_attribute link_attr_##_name = __ATTR(_name,_mode,_show,_store) |
| 56 | |
| 57 | static LINK_ATTR(type, S_IRUGO, show_link_type, NULL); |
| 58 | static LINK_ATTR(address, S_IRUGO, show_link_address, NULL); |
| 59 | static LINK_ATTR(features, S_IRUGO, show_link_features, NULL); |
| 60 | |
| 61 | static struct attribute *bt_link_attrs[] = { |
| 62 | &link_attr_type.attr, |
| 63 | &link_attr_address.attr, |
| 64 | &link_attr_features.attr, |
| 65 | NULL |
| 66 | }; |
| 67 | |
| 68 | static struct attribute_group bt_link_group = { |
| 69 | .attrs = bt_link_attrs, |
| 70 | }; |
| 71 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 72 | static const struct attribute_group *bt_link_groups[] = { |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 73 | &bt_link_group, |
| 74 | NULL |
| 75 | }; |
| 76 | |
| 77 | static void bt_link_release(struct device *dev) |
| 78 | { |
| 79 | void *data = dev_get_drvdata(dev); |
| 80 | kfree(data); |
| 81 | } |
| 82 | |
| 83 | static struct device_type bt_link = { |
| 84 | .name = "link", |
| 85 | .groups = bt_link_groups, |
| 86 | .release = bt_link_release, |
| 87 | }; |
| 88 | |
| 89 | static void add_conn(struct work_struct *work) |
| 90 | { |
Roger Quadros | f3784d8 | 2009-04-23 14:50:54 +0300 | [diff] [blame] | 91 | struct hci_conn *conn = container_of(work, struct hci_conn, work_add); |
Marcel Holtmann | 457ca7b | 2009-05-05 13:09:01 -0700 | [diff] [blame] | 92 | struct hci_dev *hdev = conn->hdev; |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 93 | |
Marcel Holtmann | 457ca7b | 2009-05-05 13:09:01 -0700 | [diff] [blame] | 94 | dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle); |
| 95 | |
Dave Young | f74c77c | 2009-10-18 20:24:41 +0000 | [diff] [blame] | 96 | dev_set_drvdata(&conn->dev, conn); |
| 97 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 98 | if (device_add(&conn->dev) < 0) { |
| 99 | BT_ERR("Failed to register connection device"); |
| 100 | return; |
| 101 | } |
Marcel Holtmann | 384943e | 2009-05-08 18:20:43 -0700 | [diff] [blame] | 102 | |
| 103 | hci_dev_hold(hdev); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 106 | /* |
| 107 | * The rfcomm tty device will possibly retain even when conn |
| 108 | * is down, and sysfs doesn't support move zombie device, |
| 109 | * so we should move the device before conn device is destroyed. |
| 110 | */ |
| 111 | static int __match_tty(struct device *dev, void *data) |
| 112 | { |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 113 | return !strncmp(dev_name(dev), "rfcomm", 6); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static void del_conn(struct work_struct *work) |
| 117 | { |
Roger Quadros | f3784d8 | 2009-04-23 14:50:54 +0300 | [diff] [blame] | 118 | struct hci_conn *conn = container_of(work, struct hci_conn, work_del); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 119 | struct hci_dev *hdev = conn->hdev; |
| 120 | |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 121 | if (!device_is_registered(&conn->dev)) |
| 122 | return; |
Roger Quadros | f3784d8 | 2009-04-23 14:50:54 +0300 | [diff] [blame] | 123 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 124 | while (1) { |
| 125 | struct device *dev; |
| 126 | |
| 127 | dev = device_find_child(&conn->dev, NULL, __match_tty); |
| 128 | if (!dev) |
| 129 | break; |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 130 | device_move(dev, NULL, DPM_ORDER_DEV_LAST); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 131 | put_device(dev); |
| 132 | } |
| 133 | |
| 134 | device_del(&conn->dev); |
| 135 | put_device(&conn->dev); |
Marcel Holtmann | 384943e | 2009-05-08 18:20:43 -0700 | [diff] [blame] | 136 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 137 | hci_dev_put(hdev); |
| 138 | } |
| 139 | |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 140 | void hci_conn_init_sysfs(struct hci_conn *conn) |
| 141 | { |
| 142 | struct hci_dev *hdev = conn->hdev; |
| 143 | |
| 144 | BT_DBG("conn %p", conn); |
| 145 | |
| 146 | conn->dev.type = &bt_link; |
| 147 | conn->dev.class = bt_class; |
| 148 | conn->dev.parent = &hdev->dev; |
| 149 | |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 150 | device_initialize(&conn->dev); |
| 151 | |
| 152 | INIT_WORK(&conn->work_add, add_conn); |
| 153 | INIT_WORK(&conn->work_del, del_conn); |
| 154 | } |
| 155 | |
| 156 | void hci_conn_add_sysfs(struct hci_conn *conn) |
| 157 | { |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 158 | BT_DBG("conn %p", conn); |
| 159 | |
Marcel Holtmann | f48fd9c | 2010-03-20 15:20:04 +0100 | [diff] [blame] | 160 | queue_work(conn->hdev->workqueue, &conn->work_add); |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 163 | void hci_conn_del_sysfs(struct hci_conn *conn) |
| 164 | { |
| 165 | BT_DBG("conn %p", conn); |
| 166 | |
Marcel Holtmann | f48fd9c | 2010-03-20 15:20:04 +0100 | [diff] [blame] | 167 | queue_work(conn->hdev->workqueue, &conn->work_del); |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 170 | static inline char *host_bustostr(int bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 172 | switch (bus) { |
Marcel Holtmann | 0ac5393 | 2006-07-08 13:57:15 +0200 | [diff] [blame] | 173 | case HCI_VIRTUAL: |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 174 | return "VIRTUAL"; |
| 175 | case HCI_USB: |
| 176 | return "USB"; |
| 177 | case HCI_PCCARD: |
| 178 | return "PCCARD"; |
| 179 | case HCI_UART: |
| 180 | return "UART"; |
| 181 | case HCI_RS232: |
| 182 | return "RS232"; |
| 183 | case HCI_PCI: |
| 184 | return "PCI"; |
Marcel Holtmann | 0ac5393 | 2006-07-08 13:57:15 +0200 | [diff] [blame] | 185 | case HCI_SDIO: |
| 186 | return "SDIO"; |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 187 | default: |
| 188 | return "UNKNOWN"; |
| 189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 192 | static inline char *host_typetostr(int type) |
| 193 | { |
| 194 | switch (type) { |
| 195 | case HCI_BREDR: |
| 196 | return "BR/EDR"; |
David Vrabel | 8f1e174 | 2010-08-09 17:38:10 -0400 | [diff] [blame] | 197 | case HCI_AMP: |
| 198 | return "AMP"; |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 199 | default: |
| 200 | return "UNKNOWN"; |
| 201 | } |
| 202 | } |
| 203 | |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 204 | static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 206 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 207 | return sprintf(buf, "%s\n", host_bustostr(hdev->bus)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 210 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 211 | { |
| 212 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 213 | return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type)); |
| 214 | } |
| 215 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 216 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) |
| 217 | { |
| 218 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 219 | char name[249]; |
| 220 | int i; |
| 221 | |
| 222 | for (i = 0; i < 248; i++) |
| 223 | name[i] = hdev->dev_name[i]; |
| 224 | |
| 225 | name[248] = '\0'; |
| 226 | return sprintf(buf, "%s\n", name); |
| 227 | } |
| 228 | |
| 229 | static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf) |
| 230 | { |
| 231 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 232 | return sprintf(buf, "0x%.2x%.2x%.2x\n", |
| 233 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); |
| 234 | } |
| 235 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 236 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 238 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Gustavo F. Padovan | d6b2eb2 | 2010-09-03 18:29:46 -0300 | [diff] [blame] | 239 | return sprintf(buf, "%s\n", batostr(&hdev->bdaddr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 242 | static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf) |
| 243 | { |
| 244 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 245 | |
| 246 | return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", |
| 247 | hdev->features[0], hdev->features[1], |
| 248 | hdev->features[2], hdev->features[3], |
| 249 | hdev->features[4], hdev->features[5], |
| 250 | hdev->features[6], hdev->features[7]); |
| 251 | } |
| 252 | |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 253 | static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) |
| 254 | { |
| 255 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 256 | return sprintf(buf, "%d\n", hdev->manufacturer); |
| 257 | } |
| 258 | |
| 259 | static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf) |
| 260 | { |
| 261 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 262 | return sprintf(buf, "%d\n", hdev->hci_ver); |
| 263 | } |
| 264 | |
| 265 | static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf) |
| 266 | { |
| 267 | struct hci_dev *hdev = dev_get_drvdata(dev); |
| 268 | return sprintf(buf, "%d\n", hdev->hci_rev); |
| 269 | } |
| 270 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 271 | static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 272 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 273 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 274 | return sprintf(buf, "%d\n", hdev->idle_timeout); |
| 275 | } |
| 276 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 277 | static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 278 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 279 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 280 | unsigned long val; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 281 | |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 282 | if (strict_strtoul(buf, 0, &val) < 0) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 283 | return -EINVAL; |
| 284 | |
| 285 | if (val != 0 && (val < 500 || val > 3600000)) |
| 286 | return -EINVAL; |
| 287 | |
| 288 | hdev->idle_timeout = val; |
| 289 | |
| 290 | return count; |
| 291 | } |
| 292 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 293 | static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 294 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 295 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 296 | return sprintf(buf, "%d\n", hdev->sniff_max_interval); |
| 297 | } |
| 298 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 299 | static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 300 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 301 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 302 | unsigned long val; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 303 | |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 304 | if (strict_strtoul(buf, 0, &val) < 0) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | |
| 307 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 308 | return -EINVAL; |
| 309 | |
| 310 | if (val < hdev->sniff_min_interval) |
| 311 | return -EINVAL; |
| 312 | |
| 313 | hdev->sniff_max_interval = val; |
| 314 | |
| 315 | return count; |
| 316 | } |
| 317 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 318 | static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 319 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 320 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 321 | return sprintf(buf, "%d\n", hdev->sniff_min_interval); |
| 322 | } |
| 323 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 324 | static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 325 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 326 | struct hci_dev *hdev = dev_get_drvdata(dev); |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 327 | unsigned long val; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 328 | |
Tomas Winkler | 7b767ca | 2010-03-09 21:38:03 +0200 | [diff] [blame] | 329 | if (strict_strtoul(buf, 0, &val) < 0) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 330 | return -EINVAL; |
| 331 | |
| 332 | if (val < 0x0002 || val > 0xFFFE || val % 2) |
| 333 | return -EINVAL; |
| 334 | |
| 335 | if (val > hdev->sniff_max_interval) |
| 336 | return -EINVAL; |
| 337 | |
| 338 | hdev->sniff_min_interval = val; |
| 339 | |
| 340 | return count; |
| 341 | } |
| 342 | |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 343 | static DEVICE_ATTR(bus, S_IRUGO, show_bus, NULL); |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 344 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 345 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 346 | static DEVICE_ATTR(class, S_IRUGO, show_class, NULL); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 347 | static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 348 | static DEVICE_ATTR(features, S_IRUGO, show_features, NULL); |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 349 | static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); |
| 350 | static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); |
| 351 | static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 353 | static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 354 | show_idle_timeout, store_idle_timeout); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 355 | static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 356 | show_sniff_max_interval, store_sniff_max_interval); |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 357 | static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 358 | show_sniff_min_interval, store_sniff_min_interval); |
| 359 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 360 | static struct attribute *bt_host_attrs[] = { |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 361 | &dev_attr_bus.attr, |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 362 | &dev_attr_type.attr, |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 363 | &dev_attr_name.attr, |
| 364 | &dev_attr_class.attr, |
| 365 | &dev_attr_address.attr, |
| 366 | &dev_attr_features.attr, |
| 367 | &dev_attr_manufacturer.attr, |
| 368 | &dev_attr_hci_version.attr, |
| 369 | &dev_attr_hci_revision.attr, |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 370 | &dev_attr_idle_timeout.attr, |
| 371 | &dev_attr_sniff_max_interval.attr, |
| 372 | &dev_attr_sniff_min_interval.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | NULL |
| 374 | }; |
| 375 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 376 | static struct attribute_group bt_host_group = { |
| 377 | .attrs = bt_host_attrs, |
| 378 | }; |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 379 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 380 | static const struct attribute_group *bt_host_groups[] = { |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 381 | &bt_host_group, |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 382 | NULL |
| 383 | }; |
| 384 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 385 | static void bt_host_release(struct device *dev) |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 386 | { |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 387 | void *data = dev_get_drvdata(dev); |
| 388 | kfree(data); |
| 389 | } |
| 390 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 391 | static struct device_type bt_host = { |
| 392 | .name = "host", |
| 393 | .groups = bt_host_groups, |
| 394 | .release = bt_host_release, |
| 395 | }; |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 396 | |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 397 | static int inquiry_cache_show(struct seq_file *f, void *p) |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 398 | { |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 399 | struct hci_dev *hdev = f->private; |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 400 | struct inquiry_cache *cache = &hdev->inq_cache; |
| 401 | struct inquiry_entry *e; |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 402 | |
| 403 | hci_dev_lock_bh(hdev); |
| 404 | |
| 405 | for (e = cache->list; e; e = e->next) { |
| 406 | struct inquiry_data *data = &e->data; |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 407 | seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", |
Gustavo F. Padovan | d6b2eb2 | 2010-09-03 18:29:46 -0300 | [diff] [blame] | 408 | batostr(&data->bdaddr), |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 409 | data->pscan_rep_mode, data->pscan_period_mode, |
| 410 | data->pscan_mode, data->dev_class[2], |
| 411 | data->dev_class[1], data->dev_class[0], |
| 412 | __le16_to_cpu(data->clock_offset), |
| 413 | data->rssi, data->ssp_mode, e->timestamp); |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | hci_dev_unlock_bh(hdev); |
| 417 | |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int inquiry_cache_open(struct inode *inode, struct file *file) |
| 422 | { |
| 423 | return single_open(file, inquiry_cache_show, inode->i_private); |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static const struct file_operations inquiry_cache_fops = { |
Marcel Holtmann | d4612cb | 2010-03-02 15:48:23 +0000 | [diff] [blame] | 427 | .open = inquiry_cache_open, |
| 428 | .read = seq_read, |
| 429 | .llseek = seq_lseek, |
| 430 | .release = single_release, |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 431 | }; |
| 432 | |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 433 | static int blacklist_show(struct seq_file *f, void *p) |
| 434 | { |
| 435 | struct hci_dev *hdev = f->private; |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 436 | struct list_head *l; |
| 437 | |
| 438 | hci_dev_lock_bh(hdev); |
| 439 | |
David Miller | ea4bd8b | 2010-07-30 21:54:49 -0700 | [diff] [blame] | 440 | list_for_each(l, &hdev->blacklist) { |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 441 | struct bdaddr_list *b; |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 442 | |
| 443 | b = list_entry(l, struct bdaddr_list, list); |
| 444 | |
Gustavo F. Padovan | d6b2eb2 | 2010-09-03 18:29:46 -0300 | [diff] [blame] | 445 | seq_printf(f, "%s\n", batostr(&b->bdaddr)); |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | hci_dev_unlock_bh(hdev); |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static int blacklist_open(struct inode *inode, struct file *file) |
| 454 | { |
| 455 | return single_open(file, blacklist_show, inode->i_private); |
| 456 | } |
| 457 | |
| 458 | static const struct file_operations blacklist_fops = { |
| 459 | .open = blacklist_open, |
| 460 | .read = seq_read, |
| 461 | .llseek = seq_lseek, |
| 462 | .release = single_release, |
| 463 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | int hci_register_sysfs(struct hci_dev *hdev) |
| 465 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 466 | struct device *dev = &hdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | int err; |
| 468 | |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 469 | BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 471 | dev->type = &bt_host; |
| 472 | dev->class = bt_class; |
Marcel Holtmann | e9c4bec | 2006-10-15 17:30:50 +0200 | [diff] [blame] | 473 | dev->parent = hdev->parent; |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 474 | |
Marcel Holtmann | 2e79299 | 2008-11-30 12:17:29 +0100 | [diff] [blame] | 475 | dev_set_name(dev, "%s", hdev->name); |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 476 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 477 | dev_set_drvdata(dev, hdev); |
| 478 | |
| 479 | err = device_register(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if (err < 0) |
| 481 | return err; |
| 482 | |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 483 | if (!bt_debugfs) |
| 484 | return 0; |
| 485 | |
| 486 | hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); |
| 487 | if (!hdev->debugfs) |
| 488 | return 0; |
| 489 | |
| 490 | debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, |
| 491 | hdev, &inquiry_cache_fops); |
| 492 | |
Johan Hedberg | 32c2ece | 2010-05-18 13:54:49 +0200 | [diff] [blame] | 493 | debugfs_create_file("blacklist", 0444, hdev->debugfs, |
| 494 | hdev, &blacklist_fops); |
| 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | void hci_unregister_sysfs(struct hci_dev *hdev) |
| 500 | { |
Marcel Holtmann | c13854ce | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 501 | BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 503 | debugfs_remove_recursive(hdev->debugfs); |
| 504 | |
Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 505 | device_del(&hdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | int __init bt_sysfs_init(void) |
| 509 | { |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 510 | bt_debugfs = debugfs_create_dir("bluetooth", NULL); |
| 511 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 512 | bt_class = class_create(THIS_MODULE, "bluetooth"); |
Marcel Holtmann | f48fd9c | 2010-03-20 15:20:04 +0100 | [diff] [blame] | 513 | if (IS_ERR(bt_class)) |
Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 514 | return PTR_ERR(bt_class); |
Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 515 | |
| 516 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Arnaud Patard | 860e13b | 2006-09-28 15:29:37 -0700 | [diff] [blame] | 519 | void bt_sysfs_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 521 | class_destroy(bt_class); |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 522 | |
| 523 | debugfs_remove_recursive(bt_debugfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |