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 inline char *typetostr(int type
)
36 static ssize_t
show_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
38 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
39 return sprintf(buf
, "%s\n", typetostr(hdev
->type
));
42 static ssize_t
show_address(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
44 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
46 baswap(&bdaddr
, &hdev
->bdaddr
);
47 return sprintf(buf
, "%s\n", batostr(&bdaddr
));
50 static ssize_t
show_inquiry_cache(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
52 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
53 struct inquiry_cache
*cache
= &hdev
->inq_cache
;
54 struct inquiry_entry
*e
;
57 hci_dev_lock_bh(hdev
);
59 for (e
= cache
->list
; e
; e
= e
->next
) {
60 struct inquiry_data
*data
= &e
->data
;
62 baswap(&bdaddr
, &data
->bdaddr
);
63 n
+= sprintf(buf
+ n
, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
65 data
->pscan_rep_mode
, data
->pscan_period_mode
, data
->pscan_mode
,
66 data
->dev_class
[2], data
->dev_class
[1], data
->dev_class
[0],
67 __le16_to_cpu(data
->clock_offset
), data
->rssi
, e
->timestamp
);
70 hci_dev_unlock_bh(hdev
);
74 static ssize_t
show_idle_timeout(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
76 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
77 return sprintf(buf
, "%d\n", hdev
->idle_timeout
);
80 static ssize_t
store_idle_timeout(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
82 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
86 val
= simple_strtoul(buf
, &ptr
, 10);
90 if (val
!= 0 && (val
< 500 || val
> 3600000))
93 hdev
->idle_timeout
= val
;
98 static ssize_t
show_sniff_max_interval(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
100 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
101 return sprintf(buf
, "%d\n", hdev
->sniff_max_interval
);
104 static ssize_t
store_sniff_max_interval(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
106 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
110 val
= simple_strtoul(buf
, &ptr
, 10);
114 if (val
< 0x0002 || val
> 0xFFFE || val
% 2)
117 if (val
< hdev
->sniff_min_interval
)
120 hdev
->sniff_max_interval
= val
;
125 static ssize_t
show_sniff_min_interval(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
127 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
128 return sprintf(buf
, "%d\n", hdev
->sniff_min_interval
);
131 static ssize_t
store_sniff_min_interval(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
133 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
137 val
= simple_strtoul(buf
, &ptr
, 10);
141 if (val
< 0x0002 || val
> 0xFFFE || val
% 2)
144 if (val
> hdev
->sniff_max_interval
)
147 hdev
->sniff_min_interval
= val
;
152 static DEVICE_ATTR(type
, S_IRUGO
, show_type
, NULL
);
153 static DEVICE_ATTR(address
, S_IRUGO
, show_address
, NULL
);
154 static DEVICE_ATTR(inquiry_cache
, S_IRUGO
, show_inquiry_cache
, NULL
);
156 static DEVICE_ATTR(idle_timeout
, S_IRUGO
| S_IWUSR
,
157 show_idle_timeout
, store_idle_timeout
);
158 static DEVICE_ATTR(sniff_max_interval
, S_IRUGO
| S_IWUSR
,
159 show_sniff_max_interval
, store_sniff_max_interval
);
160 static DEVICE_ATTR(sniff_min_interval
, S_IRUGO
| S_IWUSR
,
161 show_sniff_min_interval
, store_sniff_min_interval
);
163 static struct device_attribute
*bt_attrs
[] = {
166 &dev_attr_inquiry_cache
,
167 &dev_attr_idle_timeout
,
168 &dev_attr_sniff_max_interval
,
169 &dev_attr_sniff_min_interval
,
173 struct class *bt_class
= NULL
;
174 EXPORT_SYMBOL_GPL(bt_class
);
176 static struct bus_type bt_bus
= {
180 static struct platform_device
*bt_platform
;
182 static void bt_release(struct device
*dev
)
184 struct hci_dev
*hdev
= dev_get_drvdata(dev
);
188 int hci_register_sysfs(struct hci_dev
*hdev
)
190 struct device
*dev
= &hdev
->dev
;
194 BT_DBG("%p name %s type %d", hdev
, hdev
->name
, hdev
->type
);
196 dev
->class = bt_class
;
199 dev
->parent
= hdev
->parent
;
201 dev
->parent
= &bt_platform
->dev
;
203 strlcpy(dev
->bus_id
, hdev
->name
, BUS_ID_SIZE
);
205 dev
->release
= bt_release
;
207 dev_set_drvdata(dev
, hdev
);
209 err
= device_register(dev
);
213 for (i
= 0; bt_attrs
[i
]; i
++)
214 device_create_file(dev
, bt_attrs
[i
]);
219 void hci_unregister_sysfs(struct hci_dev
*hdev
)
221 BT_DBG("%p name %s type %d", hdev
, hdev
->name
, hdev
->type
);
223 device_del(&hdev
->dev
);
226 int __init
bt_sysfs_init(void)
230 bt_platform
= platform_device_register_simple("bluetooth", -1, NULL
, 0);
231 if (IS_ERR(bt_platform
))
232 return PTR_ERR(bt_platform
);
234 err
= bus_register(&bt_bus
);
236 platform_device_unregister(bt_platform
);
240 bt_class
= class_create(THIS_MODULE
, "bluetooth");
241 if (IS_ERR(bt_class
)) {
242 bus_unregister(&bt_bus
);
243 platform_device_unregister(bt_platform
);
244 return PTR_ERR(bt_class
);
250 void __exit
bt_sysfs_cleanup(void)
252 class_destroy(bt_class
);
254 bus_unregister(&bt_bus
);
256 platform_device_unregister(bt_platform
);