| 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> | 
|  | 4 | #include <linux/init.h> | 
|  | 5 |  | 
|  | 6 | #include <net/bluetooth/bluetooth.h> | 
|  | 7 | #include <net/bluetooth/hci_core.h> | 
|  | 8 |  | 
|  | 9 | #ifndef CONFIG_BT_HCI_CORE_DEBUG | 
|  | 10 | #undef  BT_DBG | 
|  | 11 | #define BT_DBG(D...) | 
|  | 12 | #endif | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 13 |  | 
|  | 14 | struct class *bt_class = NULL; | 
|  | 15 | EXPORT_SYMBOL_GPL(bt_class); | 
|  | 16 |  | 
| Dave Young | b6c0632 | 2008-01-29 21:14:08 -0800 | [diff] [blame] | 17 | static struct workqueue_struct *btaddconn; | 
|  | 18 | static struct workqueue_struct *btdelconn; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 20 | static inline char *link_typetostr(int type) | 
|  | 21 | { | 
|  | 22 | switch (type) { | 
|  | 23 | case ACL_LINK: | 
|  | 24 | return "ACL"; | 
|  | 25 | case SCO_LINK: | 
|  | 26 | return "SCO"; | 
|  | 27 | case ESCO_LINK: | 
|  | 28 | return "eSCO"; | 
|  | 29 | default: | 
|  | 30 | return "UNKNOWN"; | 
|  | 31 | } | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | static ssize_t show_link_type(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 35 | { | 
|  | 36 | struct hci_conn *conn = dev_get_drvdata(dev); | 
|  | 37 | return sprintf(buf, "%s\n", link_typetostr(conn->type)); | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | static ssize_t show_link_address(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 41 | { | 
|  | 42 | struct hci_conn *conn = dev_get_drvdata(dev); | 
|  | 43 | bdaddr_t bdaddr; | 
|  | 44 | baswap(&bdaddr, &conn->dst); | 
|  | 45 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | static ssize_t show_link_features(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 49 | { | 
|  | 50 | struct hci_conn *conn = dev_get_drvdata(dev); | 
|  | 51 |  | 
|  | 52 | return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", | 
|  | 53 | conn->features[0], conn->features[1], | 
|  | 54 | conn->features[2], conn->features[3], | 
|  | 55 | conn->features[4], conn->features[5], | 
|  | 56 | conn->features[6], conn->features[7]); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | #define LINK_ATTR(_name,_mode,_show,_store) \ | 
|  | 60 | struct device_attribute link_attr_##_name = __ATTR(_name,_mode,_show,_store) | 
|  | 61 |  | 
|  | 62 | static LINK_ATTR(type, S_IRUGO, show_link_type, NULL); | 
|  | 63 | static LINK_ATTR(address, S_IRUGO, show_link_address, NULL); | 
|  | 64 | static LINK_ATTR(features, S_IRUGO, show_link_features, NULL); | 
|  | 65 |  | 
|  | 66 | static struct attribute *bt_link_attrs[] = { | 
|  | 67 | &link_attr_type.attr, | 
|  | 68 | &link_attr_address.attr, | 
|  | 69 | &link_attr_features.attr, | 
|  | 70 | NULL | 
|  | 71 | }; | 
|  | 72 |  | 
|  | 73 | static struct attribute_group bt_link_group = { | 
|  | 74 | .attrs = bt_link_attrs, | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | static struct attribute_group *bt_link_groups[] = { | 
|  | 78 | &bt_link_group, | 
|  | 79 | NULL | 
|  | 80 | }; | 
|  | 81 |  | 
|  | 82 | static void bt_link_release(struct device *dev) | 
|  | 83 | { | 
|  | 84 | void *data = dev_get_drvdata(dev); | 
|  | 85 | kfree(data); | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | static struct device_type bt_link = { | 
|  | 89 | .name    = "link", | 
|  | 90 | .groups  = bt_link_groups, | 
|  | 91 | .release = bt_link_release, | 
|  | 92 | }; | 
|  | 93 |  | 
|  | 94 | static void add_conn(struct work_struct *work) | 
|  | 95 | { | 
|  | 96 | struct hci_conn *conn = container_of(work, struct hci_conn, work); | 
|  | 97 |  | 
|  | 98 | flush_workqueue(btdelconn); | 
|  | 99 |  | 
|  | 100 | if (device_add(&conn->dev) < 0) { | 
|  | 101 | BT_ERR("Failed to register connection device"); | 
|  | 102 | return; | 
|  | 103 | } | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | void hci_conn_add_sysfs(struct hci_conn *conn) | 
|  | 107 | { | 
|  | 108 | struct hci_dev *hdev = conn->hdev; | 
|  | 109 |  | 
|  | 110 | BT_DBG("conn %p", conn); | 
|  | 111 |  | 
|  | 112 | conn->dev.type = &bt_link; | 
|  | 113 | conn->dev.class = bt_class; | 
|  | 114 | conn->dev.parent = &hdev->dev; | 
|  | 115 |  | 
|  | 116 | snprintf(conn->dev.bus_id, BUS_ID_SIZE, "%s:%d", | 
|  | 117 | hdev->name, conn->handle); | 
|  | 118 |  | 
|  | 119 | dev_set_drvdata(&conn->dev, conn); | 
|  | 120 |  | 
|  | 121 | device_initialize(&conn->dev); | 
|  | 122 |  | 
|  | 123 | INIT_WORK(&conn->work, add_conn); | 
|  | 124 |  | 
|  | 125 | queue_work(btaddconn, &conn->work); | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | /* | 
|  | 129 | * The rfcomm tty device will possibly retain even when conn | 
|  | 130 | * is down, and sysfs doesn't support move zombie device, | 
|  | 131 | * so we should move the device before conn device is destroyed. | 
|  | 132 | */ | 
|  | 133 | static int __match_tty(struct device *dev, void *data) | 
|  | 134 | { | 
|  | 135 | return !strncmp(dev->bus_id, "rfcomm", 6); | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | static void del_conn(struct work_struct *work) | 
|  | 139 | { | 
|  | 140 | struct hci_conn *conn = container_of(work, struct hci_conn, work); | 
|  | 141 | struct hci_dev *hdev = conn->hdev; | 
|  | 142 |  | 
|  | 143 | while (1) { | 
|  | 144 | struct device *dev; | 
|  | 145 |  | 
|  | 146 | dev = device_find_child(&conn->dev, NULL, __match_tty); | 
|  | 147 | if (!dev) | 
|  | 148 | break; | 
|  | 149 | device_move(dev, NULL); | 
|  | 150 | put_device(dev); | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | device_del(&conn->dev); | 
|  | 154 | put_device(&conn->dev); | 
|  | 155 | hci_dev_put(hdev); | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | void hci_conn_del_sysfs(struct hci_conn *conn) | 
|  | 159 | { | 
|  | 160 | BT_DBG("conn %p", conn); | 
|  | 161 |  | 
|  | 162 | if (!device_is_registered(&conn->dev)) | 
|  | 163 | return; | 
|  | 164 |  | 
|  | 165 | INIT_WORK(&conn->work, del_conn); | 
|  | 166 |  | 
|  | 167 | queue_work(btdelconn, &conn->work); | 
|  | 168 | } | 
|  | 169 |  | 
|  | 170 | static inline char *host_typetostr(int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { | 
| Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 172 | switch (type) { | 
| 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 | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 192 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 194 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 195 | return sprintf(buf, "%s\n", host_typetostr(hdev->type)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } | 
|  | 197 |  | 
| Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 198 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 199 | { | 
|  | 200 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 201 | char name[249]; | 
|  | 202 | int i; | 
|  | 203 |  | 
|  | 204 | for (i = 0; i < 248; i++) | 
|  | 205 | name[i] = hdev->dev_name[i]; | 
|  | 206 |  | 
|  | 207 | name[248] = '\0'; | 
|  | 208 | return sprintf(buf, "%s\n", name); | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 212 | { | 
|  | 213 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 214 | return sprintf(buf, "0x%.2x%.2x%.2x\n", | 
|  | 215 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); | 
|  | 216 | } | 
|  | 217 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 218 | 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] | 219 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 220 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | bdaddr_t bdaddr; | 
|  | 222 | baswap(&bdaddr, &hdev->bdaddr); | 
|  | 223 | return sprintf(buf, "%s\n", batostr(&bdaddr)); | 
|  | 224 | } | 
|  | 225 |  | 
| Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 226 | static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 227 | { | 
|  | 228 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 229 |  | 
|  | 230 | return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", | 
|  | 231 | hdev->features[0], hdev->features[1], | 
|  | 232 | hdev->features[2], hdev->features[3], | 
|  | 233 | hdev->features[4], hdev->features[5], | 
|  | 234 | hdev->features[6], hdev->features[7]); | 
|  | 235 | } | 
|  | 236 |  | 
| Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 237 | static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 238 | { | 
|  | 239 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 240 | return sprintf(buf, "%d\n", hdev->manufacturer); | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 244 | { | 
|  | 245 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 246 | return sprintf(buf, "%d\n", hdev->hci_ver); | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 250 | { | 
|  | 251 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
|  | 252 | return sprintf(buf, "%d\n", hdev->hci_rev); | 
|  | 253 | } | 
|  | 254 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 255 | static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 257 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct inquiry_cache *cache = &hdev->inq_cache; | 
|  | 259 | struct inquiry_entry *e; | 
|  | 260 | int n = 0; | 
|  | 261 |  | 
|  | 262 | hci_dev_lock_bh(hdev); | 
|  | 263 |  | 
|  | 264 | for (e = cache->list; e; e = e->next) { | 
|  | 265 | struct inquiry_data *data = &e->data; | 
|  | 266 | bdaddr_t bdaddr; | 
|  | 267 | baswap(&bdaddr, &data->bdaddr); | 
| Marcel Holtmann | a8bd28ba | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 268 | n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | batostr(&bdaddr), | 
| Marcel Holtmann | a8bd28ba | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 270 | data->pscan_rep_mode, data->pscan_period_mode, | 
|  | 271 | data->pscan_mode, data->dev_class[2], | 
|  | 272 | data->dev_class[1], data->dev_class[0], | 
|  | 273 | __le16_to_cpu(data->clock_offset), | 
|  | 274 | data->rssi, data->ssp_mode, e->timestamp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } | 
|  | 276 |  | 
|  | 277 | hci_dev_unlock_bh(hdev); | 
|  | 278 | return n; | 
|  | 279 | } | 
|  | 280 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 281 | 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] | 282 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 283 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 284 | return sprintf(buf, "%d\n", hdev->idle_timeout); | 
|  | 285 | } | 
|  | 286 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 287 | 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] | 288 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 289 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 290 | char *ptr; | 
|  | 291 | __u32 val; | 
|  | 292 |  | 
|  | 293 | val = simple_strtoul(buf, &ptr, 10); | 
|  | 294 | if (ptr == buf) | 
|  | 295 | return -EINVAL; | 
|  | 296 |  | 
|  | 297 | if (val != 0 && (val < 500 || val > 3600000)) | 
|  | 298 | return -EINVAL; | 
|  | 299 |  | 
|  | 300 | hdev->idle_timeout = val; | 
|  | 301 |  | 
|  | 302 | return count; | 
|  | 303 | } | 
|  | 304 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 305 | 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] | 306 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 307 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 308 | return sprintf(buf, "%d\n", hdev->sniff_max_interval); | 
|  | 309 | } | 
|  | 310 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 311 | 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] | 312 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 313 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 314 | char *ptr; | 
|  | 315 | __u16 val; | 
|  | 316 |  | 
|  | 317 | val = simple_strtoul(buf, &ptr, 10); | 
|  | 318 | if (ptr == buf) | 
|  | 319 | return -EINVAL; | 
|  | 320 |  | 
|  | 321 | if (val < 0x0002 || val > 0xFFFE || val % 2) | 
|  | 322 | return -EINVAL; | 
|  | 323 |  | 
|  | 324 | if (val < hdev->sniff_min_interval) | 
|  | 325 | return -EINVAL; | 
|  | 326 |  | 
|  | 327 | hdev->sniff_max_interval = val; | 
|  | 328 |  | 
|  | 329 | return count; | 
|  | 330 | } | 
|  | 331 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 332 | 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] | 333 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 334 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 335 | return sprintf(buf, "%d\n", hdev->sniff_min_interval); | 
|  | 336 | } | 
|  | 337 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 338 | 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] | 339 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 340 | struct hci_dev *hdev = dev_get_drvdata(dev); | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 341 | char *ptr; | 
|  | 342 | __u16 val; | 
|  | 343 |  | 
|  | 344 | val = simple_strtoul(buf, &ptr, 10); | 
|  | 345 | if (ptr == buf) | 
|  | 346 | return -EINVAL; | 
|  | 347 |  | 
|  | 348 | if (val < 0x0002 || val > 0xFFFE || val % 2) | 
|  | 349 | return -EINVAL; | 
|  | 350 |  | 
|  | 351 | if (val > hdev->sniff_max_interval) | 
|  | 352 | return -EINVAL; | 
|  | 353 |  | 
|  | 354 | hdev->sniff_min_interval = val; | 
|  | 355 |  | 
|  | 356 | return count; | 
|  | 357 | } | 
|  | 358 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 359 | static DEVICE_ATTR(type, S_IRUGO, show_type, NULL); | 
| Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 360 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 
|  | 361 | static DEVICE_ATTR(class, S_IRUGO, show_class, NULL); | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 362 | static DEVICE_ATTR(address, S_IRUGO, show_address, NULL); | 
| Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 363 | static DEVICE_ATTR(features, S_IRUGO, show_features, NULL); | 
| Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 364 | static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL); | 
|  | 365 | static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL); | 
|  | 366 | static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 367 | static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 369 | static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 370 | show_idle_timeout, store_idle_timeout); | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 371 | static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 372 | show_sniff_max_interval, store_sniff_max_interval); | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 373 | static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, | 
| Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 374 | show_sniff_min_interval, store_sniff_min_interval); | 
|  | 375 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 376 | static struct attribute *bt_host_attrs[] = { | 
|  | 377 | &dev_attr_type.attr, | 
|  | 378 | &dev_attr_name.attr, | 
|  | 379 | &dev_attr_class.attr, | 
|  | 380 | &dev_attr_address.attr, | 
|  | 381 | &dev_attr_features.attr, | 
|  | 382 | &dev_attr_manufacturer.attr, | 
|  | 383 | &dev_attr_hci_version.attr, | 
|  | 384 | &dev_attr_hci_revision.attr, | 
|  | 385 | &dev_attr_inquiry_cache.attr, | 
|  | 386 | &dev_attr_idle_timeout.attr, | 
|  | 387 | &dev_attr_sniff_max_interval.attr, | 
|  | 388 | &dev_attr_sniff_min_interval.attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | NULL | 
|  | 390 | }; | 
|  | 391 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 392 | static struct attribute_group bt_host_group = { | 
|  | 393 | .attrs = bt_host_attrs, | 
|  | 394 | }; | 
| Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 395 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 396 | static struct attribute_group *bt_host_groups[] = { | 
|  | 397 | &bt_host_group, | 
| Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 398 | NULL | 
|  | 399 | }; | 
|  | 400 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 401 | static void bt_host_release(struct device *dev) | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 402 | { | 
| Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 403 | void *data = dev_get_drvdata(dev); | 
|  | 404 | kfree(data); | 
|  | 405 | } | 
|  | 406 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 407 | static struct device_type bt_host = { | 
|  | 408 | .name    = "host", | 
|  | 409 | .groups  = bt_host_groups, | 
|  | 410 | .release = bt_host_release, | 
|  | 411 | }; | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 412 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | int hci_register_sysfs(struct hci_dev *hdev) | 
|  | 414 | { | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 415 | struct device *dev = &hdev->dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | int err; | 
|  | 417 |  | 
|  | 418 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 
|  | 419 |  | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 420 | dev->type = &bt_host; | 
|  | 421 | dev->class = bt_class; | 
| Marcel Holtmann | e9c4bec | 2006-10-15 17:30:50 +0200 | [diff] [blame] | 422 | dev->parent = hdev->parent; | 
| Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 423 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 424 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); | 
| Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 425 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 426 | dev_set_drvdata(dev, hdev); | 
|  | 427 |  | 
|  | 428 | err = device_register(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | if (err < 0) | 
|  | 430 | return err; | 
|  | 431 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | return 0; | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | void hci_unregister_sysfs(struct hci_dev *hdev) | 
|  | 436 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 
|  | 438 |  | 
| Marcel Holtmann | 4d0eb00 | 2006-07-06 12:34:41 +0200 | [diff] [blame] | 439 | device_del(&hdev->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } | 
|  | 441 |  | 
|  | 442 | int __init bt_sysfs_init(void) | 
|  | 443 | { | 
| Dave Young | b6c0632 | 2008-01-29 21:14:08 -0800 | [diff] [blame] | 444 | btaddconn = create_singlethread_workqueue("btaddconn"); | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 445 | if (!btaddconn) | 
|  | 446 | return -ENOMEM; | 
| Dave Young | 5396c93 | 2008-01-31 18:33:10 -0800 | [diff] [blame] | 447 |  | 
| Dave Young | b6c0632 | 2008-01-29 21:14:08 -0800 | [diff] [blame] | 448 | btdelconn = create_singlethread_workqueue("btdelconn"); | 
|  | 449 | if (!btdelconn) { | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 450 | destroy_workqueue(btaddconn); | 
|  | 451 | return -ENOMEM; | 
| Dave Young | b6c0632 | 2008-01-29 21:14:08 -0800 | [diff] [blame] | 452 | } | 
|  | 453 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 454 | bt_class = class_create(THIS_MODULE, "bluetooth"); | 
|  | 455 | if (IS_ERR(bt_class)) { | 
| Marcel Holtmann | 90855d7 | 2008-08-18 13:23:53 +0200 | [diff] [blame] | 456 | destroy_workqueue(btdelconn); | 
|  | 457 | destroy_workqueue(btaddconn); | 
|  | 458 | return PTR_ERR(bt_class); | 
| Marcel Holtmann | 27d3528 | 2006-07-03 10:02:37 +0200 | [diff] [blame] | 459 | } | 
|  | 460 |  | 
|  | 461 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
| Arnaud Patard | 860e13b | 2006-09-28 15:29:37 -0700 | [diff] [blame] | 464 | void bt_sysfs_cleanup(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { | 
| Dave Young | b6c0632 | 2008-01-29 21:14:08 -0800 | [diff] [blame] | 466 | destroy_workqueue(btaddconn); | 
|  | 467 | destroy_workqueue(btdelconn); | 
| Dave Young | 5396c93 | 2008-01-31 18:33:10 -0800 | [diff] [blame] | 468 |  | 
| Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 469 | class_destroy(bt_class); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |