1 #include <linux/config.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
5 #include <net/bluetooth/bluetooth.h>
6 #include <net/bluetooth/hci_core.h>
8 #ifndef CONFIG_BT_HCI_CORE_DEBUG
10 #define BT_DBG( A... )
13 static ssize_t show_name(struct class_device *cdev, char *buf)
15 struct hci_dev *hdev = class_get_devdata(cdev);
16 return sprintf(buf, "%s\n", hdev->name);
19 static ssize_t show_type(struct class_device *cdev, char *buf)
21 struct hci_dev *hdev = class_get_devdata(cdev);
22 return sprintf(buf, "%d\n", hdev->type);
25 static ssize_t show_address(struct class_device *cdev, char *buf)
27 struct hci_dev *hdev = class_get_devdata(cdev);
29 baswap(&bdaddr, &hdev->bdaddr);
30 return sprintf(buf, "%s\n", batostr(&bdaddr));
33 static ssize_t show_flags(struct class_device *cdev, char *buf)
35 struct hci_dev *hdev = class_get_devdata(cdev);
36 return sprintf(buf, "0x%lx\n", hdev->flags);
39 static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf)
41 struct hci_dev *hdev = class_get_devdata(cdev);
42 struct inquiry_cache *cache = &hdev->inq_cache;
43 struct inquiry_entry *e;
46 hci_dev_lock_bh(hdev);
48 for (e = cache->list; e; e = e->next) {
49 struct inquiry_info *info = &e->info;
51 baswap(&bdaddr, &info->bdaddr);
52 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x 0x%.2x %u\n",
54 info->pscan_rep_mode, info->pscan_period_mode, info->pscan_mode,
55 info->dev_class[2], info->dev_class[1], info->dev_class[0],
56 info->clock_offset, 0, e->timestamp);
59 hci_dev_unlock_bh(hdev);
63 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
64 static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
65 static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
66 static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
67 static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
69 static struct class_device_attribute *bt_attrs[] = {
70 &class_device_attr_name,
71 &class_device_attr_type,
72 &class_device_attr_address,
73 &class_device_attr_flags,
74 &class_device_attr_inquiry_cache,
79 static int bt_hotplug(struct class_device *cdev, char **envp, int num_envp, char *buf, int size)
81 struct hci_dev *hdev = class_get_devdata(cdev);
85 n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1;
89 if ((size <= 0) || (i >= num_envp))
97 static void bt_release(struct class_device *cdev)
99 struct hci_dev *hdev = class_get_devdata(cdev);
104 static struct class bt_class = {
106 .release = bt_release,
107 #ifdef CONFIG_HOTPLUG
108 .hotplug = bt_hotplug,
112 int hci_register_sysfs(struct hci_dev *hdev)
114 struct class_device *cdev = &hdev->class_dev;
117 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
119 cdev->class = &bt_class;
120 class_set_devdata(cdev, hdev);
122 strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE);
123 err = class_device_register(cdev);
127 for (i = 0; bt_attrs[i]; i++)
128 class_device_create_file(cdev, bt_attrs[i]);
133 void hci_unregister_sysfs(struct hci_dev *hdev)
135 struct class_device * cdev = &hdev->class_dev;
137 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
139 class_device_del(cdev);
142 int __init bt_sysfs_init(void)
144 return class_register(&bt_class);
147 void __exit bt_sysfs_cleanup(void)
149 class_unregister(&bt_class);