Blame view

net/bluetooth/hci_sysfs.c 13.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /* Bluetooth HCI driver model support. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  #include <linux/kernel.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
3
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
  #include <linux/init.h>
ca325f698   Marcel Holtmann   Bluetooth: Conver...
5
  #include <linux/debugfs.h>
d4612cb86   Marcel Holtmann   Bluetooth: Use si...
6
  #include <linux/seq_file.h>
3a9a231d9   Paul Gortmaker   net: Fix files ex...
7
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
  
  #include <net/bluetooth/bluetooth.h>
  #include <net/bluetooth/hci_core.h>
aef7d97cc   Marcel Holtmann   Bluetooth: Conver...
11
  static struct class *bt_class;
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
12

602f9887c   Gustavo F. Padovan   Bluetooth: Fix er...
13
  struct dentry *bt_debugfs;
ca325f698   Marcel Holtmann   Bluetooth: Conver...
14
  EXPORT_SYMBOL_GPL(bt_debugfs);
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
15
16
17
18
19
20
21
22
23
  static inline char *link_typetostr(int type)
  {
  	switch (type) {
  	case ACL_LINK:
  		return "ACL";
  	case SCO_LINK:
  		return "SCO";
  	case ESCO_LINK:
  		return "eSCO";
21061df3a   Peter Hurley   Bluetooth: Add LE...
24
25
  	case LE_LINK:
  		return "LE";
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  	default:
  		return "UNKNOWN";
  	}
  }
  
  static ssize_t show_link_type(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_conn *conn = dev_get_drvdata(dev);
  	return sprintf(buf, "%s
  ", link_typetostr(conn->type));
  }
  
  static ssize_t show_link_address(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_conn *conn = dev_get_drvdata(dev);
d6b2eb2f8   Gustavo F. Padovan   Bluetooth: make b...
41
42
  	return sprintf(buf, "%s
  ", batostr(&conn->dst));
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
43
44
45
46
47
48
49
50
51
52
53
54
55
  }
  
  static ssize_t show_link_features(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_conn *conn = dev_get_drvdata(dev);
  
  	return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x
  ",
  				conn->features[0], conn->features[1],
  				conn->features[2], conn->features[3],
  				conn->features[4], conn->features[5],
  				conn->features[6], conn->features[7]);
  }
602f9887c   Gustavo F. Padovan   Bluetooth: Fix er...
56
57
  #define LINK_ATTR(_name, _mode, _show, _store) \
  struct device_attribute link_attr_##_name = __ATTR(_name, _mode, _show, _store)
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  
  static LINK_ATTR(type, S_IRUGO, show_link_type, NULL);
  static LINK_ATTR(address, S_IRUGO, show_link_address, NULL);
  static LINK_ATTR(features, S_IRUGO, show_link_features, NULL);
  
  static struct attribute *bt_link_attrs[] = {
  	&link_attr_type.attr,
  	&link_attr_address.attr,
  	&link_attr_features.attr,
  	NULL
  };
  
  static struct attribute_group bt_link_group = {
  	.attrs = bt_link_attrs,
  };
a4dbd6740   David Brownell   driver model: con...
73
  static const struct attribute_group *bt_link_groups[] = {
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  	&bt_link_group,
  	NULL
  };
  
  static void bt_link_release(struct device *dev)
  {
  	void *data = dev_get_drvdata(dev);
  	kfree(data);
  }
  
  static struct device_type bt_link = {
  	.name    = "link",
  	.groups  = bt_link_groups,
  	.release = bt_link_release,
  };
6d438e335   Gustavo F. Padovan   Bluetooth: Remove...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  /*
   * The rfcomm tty device will possibly retain even when conn
   * is down, and sysfs doesn't support move zombie device,
   * so we should move the device before conn device is destroyed.
   */
  static int __match_tty(struct device *dev, void *data)
  {
  	return !strncmp(dev_name(dev), "rfcomm", 6);
  }
  
  void hci_conn_init_sysfs(struct hci_conn *conn)
  {
  	struct hci_dev *hdev = conn->hdev;
  
  	BT_DBG("conn %p", conn);
  
  	conn->dev.type = &bt_link;
  	conn->dev.class = bt_class;
  	conn->dev.parent = &hdev->dev;
  
  	device_initialize(&conn->dev);
  }
  
  void hci_conn_add_sysfs(struct hci_conn *conn)
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
113
  {
457ca7bb6   Marcel Holtmann   Bluetooth: Move d...
114
  	struct hci_dev *hdev = conn->hdev;
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
115

6d438e335   Gustavo F. Padovan   Bluetooth: Remove...
116
  	BT_DBG("conn %p", conn);
457ca7bb6   Marcel Holtmann   Bluetooth: Move d...
117
  	dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
f74c77cb1   Dave Young   bluetooth: schedu...
118
  	dev_set_drvdata(&conn->dev, conn);
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
119
120
121
122
  	if (device_add(&conn->dev) < 0) {
  		BT_ERR("Failed to register connection device");
  		return;
  	}
384943ec1   Marcel Holtmann   Bluetooth: Fix wr...
123
124
  
  	hci_dev_hold(hdev);
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
125
  }
6d438e335   Gustavo F. Padovan   Bluetooth: Remove...
126
  void hci_conn_del_sysfs(struct hci_conn *conn)
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
127
  {
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
128
  	struct hci_dev *hdev = conn->hdev;
a67e899cf   Marcel Holtmann   Bluetooth: Fix is...
129
130
  	if (!device_is_registered(&conn->dev))
  		return;
f3784d834   Roger Quadros   Bluetooth: Ensure...
131

90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
132
133
134
135
136
137
  	while (1) {
  		struct device *dev;
  
  		dev = device_find_child(&conn->dev, NULL, __match_tty);
  		if (!dev)
  			break;
ffa6a7054   Cornelia Huck   Driver core: Fix ...
138
  		device_move(dev, NULL, DPM_ORDER_DEV_LAST);
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
139
140
141
142
143
  		put_device(dev);
  	}
  
  	device_del(&conn->dev);
  	put_device(&conn->dev);
384943ec1   Marcel Holtmann   Bluetooth: Fix wr...
144

90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
145
146
  	hci_dev_put(hdev);
  }
c13854cef   Marcel Holtmann   Bluetooth: Conver...
147
  static inline char *host_bustostr(int bus)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  {
c13854cef   Marcel Holtmann   Bluetooth: Conver...
149
  	switch (bus) {
0ac53939a   Marcel Holtmann   [Bluetooth] Add H...
150
  	case HCI_VIRTUAL:
4d0eb0049   Marcel Holtmann   [Bluetooth] Remov...
151
152
153
154
155
156
157
158
159
160
161
  		return "VIRTUAL";
  	case HCI_USB:
  		return "USB";
  	case HCI_PCCARD:
  		return "PCCARD";
  	case HCI_UART:
  		return "UART";
  	case HCI_RS232:
  		return "RS232";
  	case HCI_PCI:
  		return "PCI";
0ac53939a   Marcel Holtmann   [Bluetooth] Add H...
162
163
  	case HCI_SDIO:
  		return "SDIO";
4d0eb0049   Marcel Holtmann   [Bluetooth] Remov...
164
165
166
  	default:
  		return "UNKNOWN";
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167
  }
943da25d9   Marcel Holtmann   Bluetooth: Add co...
168
169
170
171
172
  static inline char *host_typetostr(int type)
  {
  	switch (type) {
  	case HCI_BREDR:
  		return "BR/EDR";
8f1e17422   David Vrabel   Bluetooth: HCI de...
173
174
  	case HCI_AMP:
  		return "AMP";
943da25d9   Marcel Holtmann   Bluetooth: Add co...
175
176
177
178
  	default:
  		return "UNKNOWN";
  	}
  }
c13854cef   Marcel Holtmann   Bluetooth: Conver...
179
  static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
181
  	struct hci_dev *hdev = dev_get_drvdata(dev);
c13854cef   Marcel Holtmann   Bluetooth: Conver...
182
183
  	return sprintf(buf, "%s
  ", host_bustostr(hdev->bus));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
  }
943da25d9   Marcel Holtmann   Bluetooth: Add co...
185
186
187
188
189
190
  static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  	return sprintf(buf, "%s
  ", host_typetostr(hdev->dev_type));
  }
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
191
192
193
  static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
1f6c6378c   Johan Hedberg   Bluetooth: Add de...
194
  	char name[HCI_MAX_NAME_LENGTH + 1];
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
195
  	int i;
1f6c6378c   Johan Hedberg   Bluetooth: Add de...
196
  	for (i = 0; i < HCI_MAX_NAME_LENGTH; i++)
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
197
  		name[i] = hdev->dev_name[i];
1f6c6378c   Johan Hedberg   Bluetooth: Add de...
198
  	name[HCI_MAX_NAME_LENGTH] = '\0';
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
199
200
201
202
203
204
205
206
207
208
209
  	return sprintf(buf, "%s
  ", name);
  }
  
  static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  	return sprintf(buf, "0x%.2x%.2x%.2x
  ",
  			hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
210
  static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
212
  	struct hci_dev *hdev = dev_get_drvdata(dev);
d6b2eb2f8   Gustavo F. Padovan   Bluetooth: make b...
213
214
  	return sprintf(buf, "%s
  ", batostr(&hdev->bdaddr));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
  }
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
216
217
218
219
220
221
222
223
224
225
226
  static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  
  	return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x
  ",
  				hdev->features[0], hdev->features[1],
  				hdev->features[2], hdev->features[3],
  				hdev->features[4], hdev->features[5],
  				hdev->features[6], hdev->features[7]);
  }
1143e5a6d   Marcel Holtmann   [Bluetooth] Read ...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
  static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  	return sprintf(buf, "%d
  ", hdev->manufacturer);
  }
  
  static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  	return sprintf(buf, "%d
  ", hdev->hci_ver);
  }
  
  static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf)
  {
  	struct hci_dev *hdev = dev_get_drvdata(dev);
  	return sprintf(buf, "%d
  ", hdev->hci_rev);
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
247
  static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
248
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
249
  	struct hci_dev *hdev = dev_get_drvdata(dev);
04837f644   Marcel Holtmann   [Bluetooth] Add a...
250
251
252
  	return sprintf(buf, "%d
  ", hdev->idle_timeout);
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
253
  static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
254
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
255
  	struct hci_dev *hdev = dev_get_drvdata(dev);
db940cb0d   Alexey Dobriyan   Bluetooth: conver...
256
257
  	unsigned int val;
  	int rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
258

db940cb0d   Alexey Dobriyan   Bluetooth: conver...
259
260
261
  	rv = kstrtouint(buf, 0, &val);
  	if (rv < 0)
  		return rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
262
263
264
265
266
267
268
269
  
  	if (val != 0 && (val < 500 || val > 3600000))
  		return -EINVAL;
  
  	hdev->idle_timeout = val;
  
  	return count;
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
270
  static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
271
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
272
  	struct hci_dev *hdev = dev_get_drvdata(dev);
04837f644   Marcel Holtmann   [Bluetooth] Add a...
273
274
275
  	return sprintf(buf, "%d
  ", hdev->sniff_max_interval);
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
276
  static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
277
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
278
  	struct hci_dev *hdev = dev_get_drvdata(dev);
db940cb0d   Alexey Dobriyan   Bluetooth: conver...
279
280
  	u16 val;
  	int rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
281

db940cb0d   Alexey Dobriyan   Bluetooth: conver...
282
283
284
  	rv = kstrtou16(buf, 0, &val);
  	if (rv < 0)
  		return rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
285

db940cb0d   Alexey Dobriyan   Bluetooth: conver...
286
  	if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
287
288
289
290
291
292
  		return -EINVAL;
  
  	hdev->sniff_max_interval = val;
  
  	return count;
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
293
  static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
294
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
295
  	struct hci_dev *hdev = dev_get_drvdata(dev);
04837f644   Marcel Holtmann   [Bluetooth] Add a...
296
297
298
  	return sprintf(buf, "%d
  ", hdev->sniff_min_interval);
  }
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
299
  static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
300
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
301
  	struct hci_dev *hdev = dev_get_drvdata(dev);
db940cb0d   Alexey Dobriyan   Bluetooth: conver...
302
303
  	u16 val;
  	int rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
304

db940cb0d   Alexey Dobriyan   Bluetooth: conver...
305
306
307
  	rv = kstrtou16(buf, 0, &val);
  	if (rv < 0)
  		return rv;
04837f644   Marcel Holtmann   [Bluetooth] Add a...
308

db940cb0d   Alexey Dobriyan   Bluetooth: conver...
309
  	if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
04837f644   Marcel Holtmann   [Bluetooth] Add a...
310
311
312
313
314
315
  		return -EINVAL;
  
  	hdev->sniff_min_interval = val;
  
  	return count;
  }
c13854cef   Marcel Holtmann   Bluetooth: Conver...
316
  static DEVICE_ATTR(bus, S_IRUGO, show_bus, NULL);
943da25d9   Marcel Holtmann   Bluetooth: Add co...
317
  static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
318
319
  static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
320
  static DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
a9de92480   Marcel Holtmann   [Bluetooth] Switc...
321
  static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
1143e5a6d   Marcel Holtmann   [Bluetooth] Read ...
322
323
324
  static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
  static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
  static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325

a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
326
  static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
04837f644   Marcel Holtmann   [Bluetooth] Add a...
327
  				show_idle_timeout, store_idle_timeout);
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
328
  static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR,
04837f644   Marcel Holtmann   [Bluetooth] Add a...
329
  				show_sniff_max_interval, store_sniff_max_interval);
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
330
  static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
04837f644   Marcel Holtmann   [Bluetooth] Add a...
331
  				show_sniff_min_interval, store_sniff_min_interval);
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
332
  static struct attribute *bt_host_attrs[] = {
c13854cef   Marcel Holtmann   Bluetooth: Conver...
333
  	&dev_attr_bus.attr,
943da25d9   Marcel Holtmann   Bluetooth: Add co...
334
  	&dev_attr_type.attr,
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
335
336
337
338
339
340
341
  	&dev_attr_name.attr,
  	&dev_attr_class.attr,
  	&dev_attr_address.attr,
  	&dev_attr_features.attr,
  	&dev_attr_manufacturer.attr,
  	&dev_attr_hci_version.attr,
  	&dev_attr_hci_revision.attr,
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
342
343
344
  	&dev_attr_idle_timeout.attr,
  	&dev_attr_sniff_max_interval.attr,
  	&dev_attr_sniff_min_interval.attr,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
  	NULL
  };
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
347
348
  static struct attribute_group bt_host_group = {
  	.attrs = bt_host_attrs,
b219e3ac6   Marcel Holtmann   [Bluetooth] Integ...
349
  };
a4dbd6740   David Brownell   driver model: con...
350
  static const struct attribute_group *bt_host_groups[] = {
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
351
352
  	&bt_host_group,
  	NULL
27d352842   Marcel Holtmann   [Bluetooth] Add p...
353
  };
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
354
  static void bt_host_release(struct device *dev)
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
355
  {
b219e3ac6   Marcel Holtmann   [Bluetooth] Integ...
356
357
358
  	void *data = dev_get_drvdata(dev);
  	kfree(data);
  }
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
359
360
361
362
363
  static struct device_type bt_host = {
  	.name    = "host",
  	.groups  = bt_host_groups,
  	.release = bt_host_release,
  };
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
364

d4612cb86   Marcel Holtmann   Bluetooth: Use si...
365
  static int inquiry_cache_show(struct seq_file *f, void *p)
ca325f698   Marcel Holtmann   Bluetooth: Conver...
366
  {
d4612cb86   Marcel Holtmann   Bluetooth: Use si...
367
  	struct hci_dev *hdev = f->private;
ca325f698   Marcel Holtmann   Bluetooth: Conver...
368
369
  	struct inquiry_cache *cache = &hdev->inq_cache;
  	struct inquiry_entry *e;
ca325f698   Marcel Holtmann   Bluetooth: Conver...
370

09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
371
  	hci_dev_lock(hdev);
ca325f698   Marcel Holtmann   Bluetooth: Conver...
372
373
374
  
  	for (e = cache->list; e; e = e->next) {
  		struct inquiry_data *data = &e->data;
d4612cb86   Marcel Holtmann   Bluetooth: Use si...
375
376
  		seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u
  ",
d6b2eb2f8   Gustavo F. Padovan   Bluetooth: make b...
377
  			   batostr(&data->bdaddr),
d4612cb86   Marcel Holtmann   Bluetooth: Use si...
378
379
380
381
382
  			   data->pscan_rep_mode, data->pscan_period_mode,
  			   data->pscan_mode, data->dev_class[2],
  			   data->dev_class[1], data->dev_class[0],
  			   __le16_to_cpu(data->clock_offset),
  			   data->rssi, data->ssp_mode, e->timestamp);
ca325f698   Marcel Holtmann   Bluetooth: Conver...
383
  	}
09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
384
  	hci_dev_unlock(hdev);
ca325f698   Marcel Holtmann   Bluetooth: Conver...
385

d4612cb86   Marcel Holtmann   Bluetooth: Use si...
386
387
388
389
390
391
  	return 0;
  }
  
  static int inquiry_cache_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, inquiry_cache_show, inode->i_private);
ca325f698   Marcel Holtmann   Bluetooth: Conver...
392
393
394
  }
  
  static const struct file_operations inquiry_cache_fops = {
d4612cb86   Marcel Holtmann   Bluetooth: Use si...
395
396
397
398
  	.open		= inquiry_cache_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
ca325f698   Marcel Holtmann   Bluetooth: Conver...
399
  };
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
400
401
402
  static int blacklist_show(struct seq_file *f, void *p)
  {
  	struct hci_dev *hdev = f->private;
8035ded46   Luiz Augusto von Dentz   Bluetooth: replac...
403
  	struct bdaddr_list *b;
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
404

09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
405
  	hci_dev_lock(hdev);
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
406

8035ded46   Luiz Augusto von Dentz   Bluetooth: replac...
407
  	list_for_each_entry(b, &hdev->blacklist, list)
d6b2eb2f8   Gustavo F. Padovan   Bluetooth: make b...
408
409
  		seq_printf(f, "%s
  ", batostr(&b->bdaddr));
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
410

09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
411
  	hci_dev_unlock(hdev);
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
  
  	return 0;
  }
  
  static int blacklist_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, blacklist_show, inode->i_private);
  }
  
  static const struct file_operations blacklist_fops = {
  	.open		= blacklist_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
930e13363   Johan Hedberg   Bluetooth: Implem...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
  
  static void print_bt_uuid(struct seq_file *f, u8 *uuid)
  {
  	u32 data0, data4;
  	u16 data1, data2, data3, data5;
  
  	memcpy(&data0, &uuid[0], 4);
  	memcpy(&data1, &uuid[4], 2);
  	memcpy(&data2, &uuid[6], 2);
  	memcpy(&data3, &uuid[8], 2);
  	memcpy(&data4, &uuid[10], 4);
  	memcpy(&data5, &uuid[14], 2);
  
  	seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x
  ",
  				ntohl(data0), ntohs(data1), ntohs(data2),
  				ntohs(data3), ntohl(data4), ntohs(data5));
  }
  
  static int uuids_show(struct seq_file *f, void *p)
  {
  	struct hci_dev *hdev = f->private;
8035ded46   Luiz Augusto von Dentz   Bluetooth: replac...
449
  	struct bt_uuid *uuid;
930e13363   Johan Hedberg   Bluetooth: Implem...
450

09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
451
  	hci_dev_lock(hdev);
930e13363   Johan Hedberg   Bluetooth: Implem...
452

8035ded46   Luiz Augusto von Dentz   Bluetooth: replac...
453
  	list_for_each_entry(uuid, &hdev->uuids, list)
930e13363   Johan Hedberg   Bluetooth: Implem...
454
  		print_bt_uuid(f, uuid->uuid);
930e13363   Johan Hedberg   Bluetooth: Implem...
455

09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
456
  	hci_dev_unlock(hdev);
930e13363   Johan Hedberg   Bluetooth: Implem...
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
  
  	return 0;
  }
  
  static int uuids_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, uuids_show, inode->i_private);
  }
  
  static const struct file_operations uuids_fops = {
  	.open		= uuids_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
9f61656a6   Johan Hedberg   Bluetooth: Add va...
472
473
474
  static int auto_accept_delay_set(void *data, u64 val)
  {
  	struct hci_dev *hdev = data;
09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
475
  	hci_dev_lock(hdev);
9f61656a6   Johan Hedberg   Bluetooth: Add va...
476
477
  
  	hdev->auto_accept_delay = val;
09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
478
  	hci_dev_unlock(hdev);
9f61656a6   Johan Hedberg   Bluetooth: Add va...
479
480
481
482
483
484
485
  
  	return 0;
  }
  
  static int auto_accept_delay_get(void *data, u64 *val)
  {
  	struct hci_dev *hdev = data;
09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
486
  	hci_dev_lock(hdev);
9f61656a6   Johan Hedberg   Bluetooth: Add va...
487
488
  
  	*val = hdev->auto_accept_delay;
09fd0de5b   Gustavo F. Padovan   Bluetooth: Replac...
489
  	hci_dev_unlock(hdev);
9f61656a6   Johan Hedberg   Bluetooth: Add va...
490
491
492
493
494
495
496
  
  	return 0;
  }
  
  DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
  					auto_accept_delay_set, "%llu
  ");
0ac7e7002   David Herrmann   Bluetooth: Fix hc...
497
498
499
500
501
502
503
504
505
506
  void hci_init_sysfs(struct hci_dev *hdev)
  {
  	struct device *dev = &hdev->dev;
  
  	dev->type = &bt_host;
  	dev->class = bt_class;
  
  	dev_set_drvdata(dev, hdev);
  	device_initialize(dev);
  }
ce242970f   David Herrmann   Bluetooth: Rename...
507
  int hci_add_sysfs(struct hci_dev *hdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
509
  	struct device *dev = &hdev->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
  	int err;
c13854cef   Marcel Holtmann   Bluetooth: Conver...
511
  	BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512

e9c4bec63   Marcel Holtmann   [Bluetooth] Make ...
513
  	dev->parent = hdev->parent;
2e792995e   Marcel Holtmann   Bluetooth: Fix fo...
514
  	dev_set_name(dev, "%s", hdev->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515

0ac7e7002   David Herrmann   Bluetooth: Fix hc...
516
  	err = device_add(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517
518
  	if (err < 0)
  		return err;
ca325f698   Marcel Holtmann   Bluetooth: Conver...
519
520
521
522
523
524
525
526
527
  	if (!bt_debugfs)
  		return 0;
  
  	hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs);
  	if (!hdev->debugfs)
  		return 0;
  
  	debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
  						hdev, &inquiry_cache_fops);
32c2ece5e   Johan Hedberg   Bluetooth: Add de...
528
529
  	debugfs_create_file("blacklist", 0444, hdev->debugfs,
  						hdev, &blacklist_fops);
930e13363   Johan Hedberg   Bluetooth: Implem...
530
  	debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
9f61656a6   Johan Hedberg   Bluetooth: Add va...
531
532
  	debugfs_create_file("auto_accept_delay", 0444, hdev->debugfs, hdev,
  						&auto_accept_delay_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
  	return 0;
  }
ce242970f   David Herrmann   Bluetooth: Rename...
535
  void hci_del_sysfs(struct hci_dev *hdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
  {
c13854cef   Marcel Holtmann   Bluetooth: Conver...
537
  	BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
538

ca325f698   Marcel Holtmann   Bluetooth: Conver...
539
  	debugfs_remove_recursive(hdev->debugfs);
4d0eb0049   Marcel Holtmann   [Bluetooth] Remov...
540
  	device_del(&hdev->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541
542
543
544
  }
  
  int __init bt_sysfs_init(void)
  {
ca325f698   Marcel Holtmann   Bluetooth: Conver...
545
  	bt_debugfs = debugfs_create_dir("bluetooth", NULL);
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
546
  	bt_class = class_create(THIS_MODULE, "bluetooth");
f48fd9c8c   Marcel Holtmann   Bluetooth: Create...
547
  	if (IS_ERR(bt_class))
90855d7b7   Marcel Holtmann   [Bluetooth] Fix u...
548
  		return PTR_ERR(bt_class);
27d352842   Marcel Holtmann   [Bluetooth] Add p...
549
550
  
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551
  }
860e13b5c   Arnaud Patard   [Bluetooth]: Fix ...
552
  void bt_sysfs_cleanup(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
  {
a91f2e396   Marcel Holtmann   [Bluetooth] Use r...
554
  	class_destroy(bt_class);
ca325f698   Marcel Holtmann   Bluetooth: Conver...
555
556
  
  	debugfs_remove_recursive(bt_debugfs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
  }