1 /* Bluetooth HCI driver model support. */
3 #include <linux/kernel.h>
4 #include <linux/init.h>
6 #include <net/bluetooth/bluetooth.h>
7 #include <net/bluetooth/hci_core.h>
9 #ifndef CONFIG_BT_HCI_CORE_DEBUG
14 static ssize_t show_name(struct class_device *cdev, char *buf)
16 struct hci_dev *hdev = class_get_devdata(cdev);
17 return sprintf(buf, "%s\n", hdev->name);
20 static ssize_t show_type(struct class_device *cdev, char *buf)
22 struct hci_dev *hdev = class_get_devdata(cdev);
23 return sprintf(buf, "%d\n", hdev->type);
26 static ssize_t show_address(struct class_device *cdev, char *buf)
28 struct hci_dev *hdev = class_get_devdata(cdev);
30 baswap(&bdaddr, &hdev->bdaddr);
31 return sprintf(buf, "%s\n", batostr(&bdaddr));
34 static ssize_t show_flags(struct class_device *cdev, char *buf)
36 struct hci_dev *hdev = class_get_devdata(cdev);
37 return sprintf(buf, "0x%lx\n", hdev->flags);
40 static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf)
42 struct hci_dev *hdev = class_get_devdata(cdev);
43 struct inquiry_cache *cache = &hdev->inq_cache;
44 struct inquiry_entry *e;
47 hci_dev_lock_bh(hdev);
49 for (e = cache->list; e; e = e->next) {
50 struct inquiry_data *data = &e->data;
52 baswap(&bdaddr, &data->bdaddr);
53 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
55 data->pscan_rep_mode, data->pscan_period_mode, data->pscan_mode,
56 data->dev_class[2], data->dev_class[1], data->dev_class[0],
57 __le16_to_cpu(data->clock_offset), data->rssi, e->timestamp);
60 hci_dev_unlock_bh(hdev);
64 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
65 static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
66 static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
67 static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
68 static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
70 static struct class_device_attribute *bt_attrs[] = {
71 &class_device_attr_name,
72 &class_device_attr_type,
73 &class_device_attr_address,
74 &class_device_attr_flags,
75 &class_device_attr_inquiry_cache,
80 static int bt_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size)
82 struct hci_dev *hdev = class_get_devdata(cdev);
86 n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1;
90 if ((size <= 0) || (i >= num_envp))
98 static void bt_release(struct class_device *cdev)
100 struct hci_dev *hdev = class_get_devdata(cdev);
105 struct class bt_class = {
107 .release = bt_release,
108 #ifdef CONFIG_HOTPLUG
113 EXPORT_SYMBOL_GPL(bt_class);
115 int hci_register_sysfs(struct hci_dev *hdev)
117 struct class_device *cdev = &hdev->class_dev;
121 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
123 cdev->class = &bt_class;
124 class_set_devdata(cdev, hdev);
126 strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE);
127 err = class_device_register(cdev);
131 for (i = 0; bt_attrs[i]; i++)
132 class_device_create_file(cdev, bt_attrs[i]);
137 void hci_unregister_sysfs(struct hci_dev *hdev)
139 struct class_device * cdev = &hdev->class_dev;
141 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
143 class_device_del(cdev);
146 int __init bt_sysfs_init(void)
148 return class_register(&bt_class);
151 void __exit bt_sysfs_cleanup(void)
153 class_unregister(&bt_class);