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 ssize_t
show_idle_timeout(struct class_device
*cdev
, char *buf
)
66 struct hci_dev
*hdev
= class_get_devdata(cdev
);
67 return sprintf(buf
, "%d\n", hdev
->idle_timeout
);
70 static ssize_t
store_idle_timeout(struct class_device
*cdev
, const char *buf
, size_t count
)
72 struct hci_dev
*hdev
= class_get_devdata(cdev
);
76 val
= simple_strtoul(buf
, &ptr
, 10);
80 if (val
!= 0 && (val
< 500 || val
> 3600000))
83 hdev
->idle_timeout
= val
;
88 static ssize_t
show_sniff_max_interval(struct class_device
*cdev
, char *buf
)
90 struct hci_dev
*hdev
= class_get_devdata(cdev
);
91 return sprintf(buf
, "%d\n", hdev
->sniff_max_interval
);
94 static ssize_t
store_sniff_max_interval(struct class_device
*cdev
, const char *buf
, size_t count
)
96 struct hci_dev
*hdev
= class_get_devdata(cdev
);
100 val
= simple_strtoul(buf
, &ptr
, 10);
104 if (val
< 0x0002 || val
> 0xFFFE || val
% 2)
107 if (val
< hdev
->sniff_min_interval
)
110 hdev
->sniff_max_interval
= val
;
115 static ssize_t
show_sniff_min_interval(struct class_device
*cdev
, char *buf
)
117 struct hci_dev
*hdev
= class_get_devdata(cdev
);
118 return sprintf(buf
, "%d\n", hdev
->sniff_min_interval
);
121 static ssize_t
store_sniff_min_interval(struct class_device
*cdev
, const char *buf
, size_t count
)
123 struct hci_dev
*hdev
= class_get_devdata(cdev
);
127 val
= simple_strtoul(buf
, &ptr
, 10);
131 if (val
< 0x0002 || val
> 0xFFFE || val
% 2)
134 if (val
> hdev
->sniff_max_interval
)
137 hdev
->sniff_min_interval
= val
;
142 static CLASS_DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
143 static CLASS_DEVICE_ATTR(type
, S_IRUGO
, show_type
, NULL
);
144 static CLASS_DEVICE_ATTR(address
, S_IRUGO
, show_address
, NULL
);
145 static CLASS_DEVICE_ATTR(flags
, S_IRUGO
, show_flags
, NULL
);
146 static CLASS_DEVICE_ATTR(inquiry_cache
, S_IRUGO
, show_inquiry_cache
, NULL
);
148 static CLASS_DEVICE_ATTR(idle_timeout
, S_IRUGO
| S_IWUSR
,
149 show_idle_timeout
, store_idle_timeout
);
150 static CLASS_DEVICE_ATTR(sniff_max_interval
, S_IRUGO
| S_IWUSR
,
151 show_sniff_max_interval
, store_sniff_max_interval
);
152 static CLASS_DEVICE_ATTR(sniff_min_interval
, S_IRUGO
| S_IWUSR
,
153 show_sniff_min_interval
, store_sniff_min_interval
);
155 static struct class_device_attribute
*bt_attrs
[] = {
156 &class_device_attr_name
,
157 &class_device_attr_type
,
158 &class_device_attr_address
,
159 &class_device_attr_flags
,
160 &class_device_attr_inquiry_cache
,
161 &class_device_attr_idle_timeout
,
162 &class_device_attr_sniff_max_interval
,
163 &class_device_attr_sniff_min_interval
,
167 #ifdef CONFIG_HOTPLUG
168 static int bt_uevent(struct class_device
*cdev
, char **envp
, int num_envp
, char *buf
, int size
)
170 struct hci_dev
*hdev
= class_get_devdata(cdev
);
174 n
= snprintf(buf
, size
, "INTERFACE=%s", hdev
->name
) + 1;
178 if ((size
<= 0) || (i
>= num_envp
))
186 static void bt_release(struct class_device
*cdev
)
188 struct hci_dev
*hdev
= class_get_devdata(cdev
);
193 struct class bt_class
= {
195 .release
= bt_release
,
196 #ifdef CONFIG_HOTPLUG
201 EXPORT_SYMBOL_GPL(bt_class
);
203 int hci_register_sysfs(struct hci_dev
*hdev
)
205 struct class_device
*cdev
= &hdev
->class_dev
;
209 BT_DBG("%p name %s type %d", hdev
, hdev
->name
, hdev
->type
);
211 cdev
->class = &bt_class
;
212 class_set_devdata(cdev
, hdev
);
214 strlcpy(cdev
->class_id
, hdev
->name
, BUS_ID_SIZE
);
215 err
= class_device_register(cdev
);
219 for (i
= 0; bt_attrs
[i
]; i
++)
220 class_device_create_file(cdev
, bt_attrs
[i
]);
225 void hci_unregister_sysfs(struct hci_dev
*hdev
)
227 struct class_device
* cdev
= &hdev
->class_dev
;
229 BT_DBG("%p name %s type %d", hdev
, hdev
->name
, hdev
->type
);
231 class_device_del(cdev
);
234 int __init
bt_sysfs_init(void)
236 return class_register(&bt_class
);
239 void __exit
bt_sysfs_cleanup(void)
241 class_unregister(&bt_class
);