1 /* Bluetooth HCI driver model support. */
3 #include <linux/kernel.h>
4 #include <linux/init.h>
6 #include <linux/platform_device.h>
8 #include <net/bluetooth/bluetooth.h>
9 #include <net/bluetooth/hci_core.h>
11 #ifndef CONFIG_BT_HCI_CORE_DEBUG
16 static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
18 struct hci_dev *hdev = dev_get_drvdata(dev);
19 return sprintf(buf, "%s\n", hdev->name);
22 static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
24 struct hci_dev *hdev = dev_get_drvdata(dev);
25 return sprintf(buf, "%d\n", hdev->type);
28 static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
30 struct hci_dev *hdev = dev_get_drvdata(dev);
32 baswap(&bdaddr, &hdev->bdaddr);
33 return sprintf(buf, "%s\n", batostr(&bdaddr));
36 static ssize_t show_flags(struct device *dev, struct device_attribute *attr, char *buf)
38 struct hci_dev *hdev = dev_get_drvdata(dev);
39 return sprintf(buf, "0x%lx\n", hdev->flags);
42 static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
44 struct hci_dev *hdev = dev_get_drvdata(dev);
45 struct inquiry_cache *cache = &hdev->inq_cache;
46 struct inquiry_entry *e;
49 hci_dev_lock_bh(hdev);
51 for (e = cache->list; e; e = e->next) {
52 struct inquiry_data *data = &e->data;
54 baswap(&bdaddr, &data->bdaddr);
55 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
57 data->pscan_rep_mode, data->pscan_period_mode, data->pscan_mode,
58 data->dev_class[2], data->dev_class[1], data->dev_class[0],
59 __le16_to_cpu(data->clock_offset), data->rssi, e->timestamp);
62 hci_dev_unlock_bh(hdev);
66 static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
68 struct hci_dev *hdev = dev_get_drvdata(dev);
69 return sprintf(buf, "%d\n", hdev->idle_timeout);
72 static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
74 struct hci_dev *hdev = dev_get_drvdata(dev);
78 val = simple_strtoul(buf, &ptr, 10);
82 if (val != 0 && (val < 500 || val > 3600000))
85 hdev->idle_timeout = val;
90 static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf)
92 struct hci_dev *hdev = dev_get_drvdata(dev);
93 return sprintf(buf, "%d\n", hdev->sniff_max_interval);
96 static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
98 struct hci_dev *hdev = dev_get_drvdata(dev);
102 val = simple_strtoul(buf, &ptr, 10);
106 if (val < 0x0002 || val > 0xFFFE || val % 2)
109 if (val < hdev->sniff_min_interval)
112 hdev->sniff_max_interval = val;
117 static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf)
119 struct hci_dev *hdev = dev_get_drvdata(dev);
120 return sprintf(buf, "%d\n", hdev->sniff_min_interval);
123 static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
125 struct hci_dev *hdev = dev_get_drvdata(dev);
129 val = simple_strtoul(buf, &ptr, 10);
133 if (val < 0x0002 || val > 0xFFFE || val % 2)
136 if (val > hdev->sniff_max_interval)
139 hdev->sniff_min_interval = val;
144 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
145 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
146 static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
147 static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
148 static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
150 static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
151 show_idle_timeout, store_idle_timeout);
152 static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR,
153 show_sniff_max_interval, store_sniff_max_interval);
154 static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
155 show_sniff_min_interval, store_sniff_min_interval);
157 static struct device_attribute *bt_attrs[] = {
162 &dev_attr_inquiry_cache,
163 &dev_attr_idle_timeout,
164 &dev_attr_sniff_max_interval,
165 &dev_attr_sniff_min_interval,
169 struct class *bt_class = NULL;
170 EXPORT_SYMBOL_GPL(bt_class);
172 static struct bus_type bt_bus = {
176 static struct platform_device *bt_platform;
178 static void bt_release(struct device *dev)
180 struct hci_dev *hdev = dev_get_drvdata(dev);
184 int hci_register_sysfs(struct hci_dev *hdev)
186 struct device *dev = &hdev->dev;
190 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
192 dev->class = bt_class;
195 dev->parent = hdev->parent;
197 dev->parent = &bt_platform->dev;
199 strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE);
201 dev->release = bt_release;
203 dev_set_drvdata(dev, hdev);
205 err = device_register(dev);
209 for (i = 0; bt_attrs[i]; i++)
210 device_create_file(dev, bt_attrs[i]);
215 void hci_unregister_sysfs(struct hci_dev *hdev)
217 struct device *dev = &hdev->dev;
219 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
224 int __init bt_sysfs_init(void)
228 bt_platform = platform_device_register_simple("bluetooth", -1, NULL, 0);
229 if (IS_ERR(bt_platform))
230 return PTR_ERR(bt_platform);
232 err = bus_register(&bt_bus);
234 platform_device_unregister(bt_platform);
238 bt_class = class_create(THIS_MODULE, "bluetooth");
239 if (IS_ERR(bt_class)) {
240 bus_unregister(&bt_bus);
241 platform_device_unregister(bt_platform);
242 return PTR_ERR(bt_class);
248 void __exit bt_sysfs_cleanup(void)
250 class_destroy(bt_class);
252 bus_unregister(&bt_bus);
254 platform_device_unregister(bt_platform);