[Bluetooth] Correct SCO buffer size on request
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / bluetooth / hci_sysfs.c
CommitLineData
1da177e4
LT
1/* Bluetooth HCI driver model support. */
2
1da177e4
LT
3#include <linux/kernel.h>
4#include <linux/init.h>
5
6#include <net/bluetooth/bluetooth.h>
7#include <net/bluetooth/hci_core.h>
8
9#ifndef CONFIG_BT_HCI_CORE_DEBUG
10#undef BT_DBG
11#define BT_DBG(D...)
12#endif
13
14static ssize_t show_name(struct class_device *cdev, char *buf)
15{
16 struct hci_dev *hdev = class_get_devdata(cdev);
17 return sprintf(buf, "%s\n", hdev->name);
18}
19
20static ssize_t show_type(struct class_device *cdev, char *buf)
21{
22 struct hci_dev *hdev = class_get_devdata(cdev);
23 return sprintf(buf, "%d\n", hdev->type);
24}
25
26static ssize_t show_address(struct class_device *cdev, char *buf)
27{
28 struct hci_dev *hdev = class_get_devdata(cdev);
29 bdaddr_t bdaddr;
30 baswap(&bdaddr, &hdev->bdaddr);
31 return sprintf(buf, "%s\n", batostr(&bdaddr));
32}
33
34static ssize_t show_flags(struct class_device *cdev, char *buf)
35{
36 struct hci_dev *hdev = class_get_devdata(cdev);
37 return sprintf(buf, "0x%lx\n", hdev->flags);
38}
39
40static ssize_t show_inquiry_cache(struct class_device *cdev, char *buf)
41{
42 struct hci_dev *hdev = class_get_devdata(cdev);
43 struct inquiry_cache *cache = &hdev->inq_cache;
44 struct inquiry_entry *e;
45 int n = 0;
46
47 hci_dev_lock_bh(hdev);
48
49 for (e = cache->list; e; e = e->next) {
50 struct inquiry_data *data = &e->data;
51 bdaddr_t bdaddr;
52 baswap(&bdaddr, &data->bdaddr);
53 n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %u\n",
54 batostr(&bdaddr),
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);
58 }
59
60 hci_dev_unlock_bh(hdev);
61 return n;
62}
63
64static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
65static CLASS_DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
66static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
67static CLASS_DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
68static CLASS_DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
69
70static 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,
76 NULL
77};
78
79#ifdef CONFIG_HOTPLUG
312c004d 80static int bt_uevent(struct class_device *cdev, char **envp, int num_envp, char *buf, int size)
1da177e4
LT
81{
82 struct hci_dev *hdev = class_get_devdata(cdev);
83 int n, i = 0;
84
85 envp[i++] = buf;
86 n = snprintf(buf, size, "INTERFACE=%s", hdev->name) + 1;
87 buf += n;
88 size -= n;
89
90 if ((size <= 0) || (i >= num_envp))
91 return -ENOMEM;
92
93 envp[i] = NULL;
94 return 0;
95}
96#endif
97
98static void bt_release(struct class_device *cdev)
99{
100 struct hci_dev *hdev = class_get_devdata(cdev);
101
102 kfree(hdev);
103}
104
be9d1227 105struct class bt_class = {
1da177e4
LT
106 .name = "bluetooth",
107 .release = bt_release,
108#ifdef CONFIG_HOTPLUG
312c004d 109 .uevent = bt_uevent,
1da177e4
LT
110#endif
111};
112
be9d1227
MH
113EXPORT_SYMBOL_GPL(bt_class);
114
1da177e4
LT
115int hci_register_sysfs(struct hci_dev *hdev)
116{
117 struct class_device *cdev = &hdev->class_dev;
118 unsigned int i;
119 int err;
120
121 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
122
123 cdev->class = &bt_class;
124 class_set_devdata(cdev, hdev);
125
126 strlcpy(cdev->class_id, hdev->name, BUS_ID_SIZE);
127 err = class_device_register(cdev);
128 if (err < 0)
129 return err;
130
131 for (i = 0; bt_attrs[i]; i++)
132 class_device_create_file(cdev, bt_attrs[i]);
133
134 return 0;
135}
136
137void hci_unregister_sysfs(struct hci_dev *hdev)
138{
139 struct class_device * cdev = &hdev->class_dev;
140
141 BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
142
143 class_device_del(cdev);
144}
145
146int __init bt_sysfs_init(void)
147{
148 return class_register(&bt_class);
149}
150
151void __exit bt_sysfs_cleanup(void)
152{
153 class_unregister(&bt_class);
154}