1 /* Bluetooth HCI driver model support. */
3 #include <linux/config.h>
4 #include <linux/kernel.h>
5 #include <linux/init.h>
7 #include <net/bluetooth/bluetooth.h>
8 #include <net/bluetooth/hci_core.h>
10 #ifndef CONFIG_BT_HCI_CORE_DEBUG
15 static ssize_t show_name(struct class_device *cdev, char *buf)
17 struct hci_dev *hdev = class_get_devdata(cdev);
18 return sprintf(buf, "%s\n", hdev->name);
21 static ssize_t show_type(struct class_device *cdev, char *buf)
23 struct hci_dev *hdev = class_get_devdata(cdev);
24 return sprintf(buf, "%d\n", hdev->type);
27 static ssize_t show_address(struct class_device *cdev, char *buf)
29 struct hci_dev *hdev = class_get_devdata(cdev);
31 baswap(&bdaddr, &hdev->bdaddr);
32 return sprintf(buf, "%s\n", batostr(&bdaddr));
35 static ssize_t show_flags(struct class_device *cdev, char *buf)
37 struct hci_dev *hdev = class_get_devdata(cdev);
38 return sprintf(buf, "0x%lx\n", hdev->flags);
41 static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf)
43 struct hci_dev *hdev = class_get_devdata(cdev);
44 struct inquiry_cache *cache = &hdev->inq_cache;
45 struct inquiry_entry *e;
48 hci_dev_lock_bh(hdev);
50 for (e = cache->list; e; e = e->next) {
51 struct inquiry_data *data = &e->data;
53 baswap(&bdaddr, &data->bdaddr);
54 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
56 data->pscan_rep_mode, data->pscan_period_mode, data->pscan_mode,
57 data->dev_class[2], data->dev_class[1], data->dev_class[0],
58 __le16_to_cpu(data->clock_offset), data->rssi, e->timestamp);
61 hci_dev_unlock_bh(hdev);
65 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
66 static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
67 static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
68 static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
69 static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
71 static struct class_device_attribute *bt_attrs[] = {
72 &class_device_attr_name,
73 &class_device_attr_type,
74 &class_device_attr_address,
75 &class_device_attr_flags,
76 &class_device_attr_inquiry_cache,
81 static int bt_hotplug(struct class_device *cdev, char **envp, int num_envp, char *buf, int size)
83 struct hci_dev *hdev = class_get_devdata(cdev);
87 n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1;
91 if ((size <= 0) || (i >= num_envp))
99 static void bt_release(struct class_device *cdev)
101 struct hci_dev *hdev = class_get_devdata(cdev);
106 static struct class bt_class = {
108 .release = bt_release,
109 #ifdef CONFIG_HOTPLUG
110 .hotplug = bt_hotplug,
114 int hci_register_sysfs(struct hci_dev *hdev)
116 struct class_device *cdev = &hdev->class_dev;
120 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
122 cdev->class = &bt_class;
123 class_set_devdata(cdev, hdev);
125 strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE);
126 err = class_device_register(cdev);
130 for (i = 0; bt_attrs[i]; i++)
131 class_device_create_file(cdev, bt_attrs[i]);
136 void hci_unregister_sysfs(struct hci_dev *hdev)
138 struct class_device * cdev = &hdev->class_dev;
140 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
142 class_device_del(cdev);
145 int __init bt_sysfs_init(void)
147 return class_register(&bt_class);
150 void __exit bt_sysfs_cleanup(void)
152 class_unregister(&bt_class);