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