]>
Commit | Line | Data |
---|---|---|
60c5f5fb MH |
1 | /* |
2 | BlueZ - Bluetooth protocol stack for Linux | |
3 | ||
4 | Copyright (C) 2014 Intel Corporation | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License version 2 as | |
8 | published by the Free Software Foundation; | |
9 | ||
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
11 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | |
13 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | |
14 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES | |
15 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
16 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
17 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
18 | ||
19 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, | |
20 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | |
21 | SOFTWARE IS DISCLAIMED. | |
22 | */ | |
23 | ||
24 | #include <linux/debugfs.h> | |
25 | ||
26 | #include <net/bluetooth/bluetooth.h> | |
27 | #include <net/bluetooth/hci_core.h> | |
28 | ||
29 | #include "hci_debugfs.h" | |
30 | ||
40ce72b1 MH |
31 | static int features_show(struct seq_file *f, void *ptr) |
32 | { | |
33 | struct hci_dev *hdev = f->private; | |
34 | u8 p; | |
35 | ||
36 | hci_dev_lock(hdev); | |
37 | for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { | |
38 | seq_printf(f, "%2u: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x " | |
39 | "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", p, | |
40 | hdev->features[p][0], hdev->features[p][1], | |
41 | hdev->features[p][2], hdev->features[p][3], | |
42 | hdev->features[p][4], hdev->features[p][5], | |
43 | hdev->features[p][6], hdev->features[p][7]); | |
44 | } | |
45 | if (lmp_le_capable(hdev)) | |
46 | seq_printf(f, "LE: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x " | |
47 | "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", | |
48 | hdev->le_features[0], hdev->le_features[1], | |
49 | hdev->le_features[2], hdev->le_features[3], | |
50 | hdev->le_features[4], hdev->le_features[5], | |
51 | hdev->le_features[6], hdev->le_features[7]); | |
52 | hci_dev_unlock(hdev); | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | static int features_open(struct inode *inode, struct file *file) | |
58 | { | |
59 | return single_open(file, features_show, inode->i_private); | |
60 | } | |
61 | ||
62 | static const struct file_operations features_fops = { | |
63 | .open = features_open, | |
64 | .read = seq_read, | |
65 | .llseek = seq_lseek, | |
66 | .release = single_release, | |
67 | }; | |
68 | ||
69 | static int device_list_show(struct seq_file *f, void *ptr) | |
70 | { | |
71 | struct hci_dev *hdev = f->private; | |
72 | struct hci_conn_params *p; | |
73 | struct bdaddr_list *b; | |
74 | ||
75 | hci_dev_lock(hdev); | |
76 | list_for_each_entry(b, &hdev->whitelist, list) | |
77 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
78 | list_for_each_entry(p, &hdev->le_conn_params, list) { | |
79 | seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type, | |
80 | p->auto_connect); | |
81 | } | |
82 | hci_dev_unlock(hdev); | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | static int device_list_open(struct inode *inode, struct file *file) | |
88 | { | |
89 | return single_open(file, device_list_show, inode->i_private); | |
90 | } | |
91 | ||
92 | static const struct file_operations device_list_fops = { | |
93 | .open = device_list_open, | |
94 | .read = seq_read, | |
95 | .llseek = seq_lseek, | |
96 | .release = single_release, | |
97 | }; | |
98 | ||
99 | static int blacklist_show(struct seq_file *f, void *p) | |
100 | { | |
101 | struct hci_dev *hdev = f->private; | |
102 | struct bdaddr_list *b; | |
103 | ||
104 | hci_dev_lock(hdev); | |
105 | list_for_each_entry(b, &hdev->blacklist, list) | |
106 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
107 | hci_dev_unlock(hdev); | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | static int blacklist_open(struct inode *inode, struct file *file) | |
113 | { | |
114 | return single_open(file, blacklist_show, inode->i_private); | |
115 | } | |
116 | ||
117 | static const struct file_operations blacklist_fops = { | |
118 | .open = blacklist_open, | |
119 | .read = seq_read, | |
120 | .llseek = seq_lseek, | |
121 | .release = single_release, | |
122 | }; | |
123 | ||
124 | static int uuids_show(struct seq_file *f, void *p) | |
125 | { | |
126 | struct hci_dev *hdev = f->private; | |
127 | struct bt_uuid *uuid; | |
128 | ||
129 | hci_dev_lock(hdev); | |
130 | list_for_each_entry(uuid, &hdev->uuids, list) { | |
131 | u8 i, val[16]; | |
132 | ||
133 | /* The Bluetooth UUID values are stored in big endian, | |
134 | * but with reversed byte order. So convert them into | |
135 | * the right order for the %pUb modifier. | |
136 | */ | |
137 | for (i = 0; i < 16; i++) | |
138 | val[i] = uuid->uuid[15 - i]; | |
139 | ||
140 | seq_printf(f, "%pUb\n", val); | |
141 | } | |
142 | hci_dev_unlock(hdev); | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
147 | static int uuids_open(struct inode *inode, struct file *file) | |
148 | { | |
149 | return single_open(file, uuids_show, inode->i_private); | |
150 | } | |
151 | ||
152 | static const struct file_operations uuids_fops = { | |
153 | .open = uuids_open, | |
154 | .read = seq_read, | |
155 | .llseek = seq_lseek, | |
156 | .release = single_release, | |
157 | }; | |
158 | ||
159 | static int conn_info_min_age_set(void *data, u64 val) | |
160 | { | |
161 | struct hci_dev *hdev = data; | |
162 | ||
163 | if (val == 0 || val > hdev->conn_info_max_age) | |
164 | return -EINVAL; | |
165 | ||
166 | hci_dev_lock(hdev); | |
167 | hdev->conn_info_min_age = val; | |
168 | hci_dev_unlock(hdev); | |
169 | ||
170 | return 0; | |
171 | } | |
172 | ||
173 | static int conn_info_min_age_get(void *data, u64 *val) | |
174 | { | |
175 | struct hci_dev *hdev = data; | |
176 | ||
177 | hci_dev_lock(hdev); | |
178 | *val = hdev->conn_info_min_age; | |
179 | hci_dev_unlock(hdev); | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
184 | DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get, | |
185 | conn_info_min_age_set, "%llu\n"); | |
186 | ||
187 | static int conn_info_max_age_set(void *data, u64 val) | |
188 | { | |
189 | struct hci_dev *hdev = data; | |
190 | ||
191 | if (val == 0 || val < hdev->conn_info_min_age) | |
192 | return -EINVAL; | |
193 | ||
194 | hci_dev_lock(hdev); | |
195 | hdev->conn_info_max_age = val; | |
196 | hci_dev_unlock(hdev); | |
197 | ||
198 | return 0; | |
199 | } | |
200 | ||
201 | static int conn_info_max_age_get(void *data, u64 *val) | |
202 | { | |
203 | struct hci_dev *hdev = data; | |
204 | ||
205 | hci_dev_lock(hdev); | |
206 | *val = hdev->conn_info_max_age; | |
207 | hci_dev_unlock(hdev); | |
208 | ||
209 | return 0; | |
210 | } | |
211 | ||
212 | DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get, | |
213 | conn_info_max_age_set, "%llu\n"); | |
214 | ||
60c5f5fb MH |
215 | void hci_debugfs_create_common(struct hci_dev *hdev) |
216 | { | |
40ce72b1 MH |
217 | debugfs_create_file("features", 0444, hdev->debugfs, hdev, |
218 | &features_fops); | |
219 | debugfs_create_u16("manufacturer", 0444, hdev->debugfs, | |
220 | &hdev->manufacturer); | |
221 | debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver); | |
222 | debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev); | |
223 | debugfs_create_file("device_list", 0444, hdev->debugfs, hdev, | |
224 | &device_list_fops); | |
225 | debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev, | |
226 | &blacklist_fops); | |
227 | debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops); | |
228 | ||
229 | debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev, | |
230 | &conn_info_min_age_fops); | |
231 | debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev, | |
232 | &conn_info_max_age_fops); | |
60c5f5fb MH |
233 | } |
234 | ||
71c3b60e MH |
235 | static int inquiry_cache_show(struct seq_file *f, void *p) |
236 | { | |
237 | struct hci_dev *hdev = f->private; | |
238 | struct discovery_state *cache = &hdev->discovery; | |
239 | struct inquiry_entry *e; | |
240 | ||
241 | hci_dev_lock(hdev); | |
242 | ||
243 | list_for_each_entry(e, &cache->all, all) { | |
244 | struct inquiry_data *data = &e->data; | |
245 | seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", | |
246 | &data->bdaddr, | |
247 | data->pscan_rep_mode, data->pscan_period_mode, | |
248 | data->pscan_mode, data->dev_class[2], | |
249 | data->dev_class[1], data->dev_class[0], | |
250 | __le16_to_cpu(data->clock_offset), | |
251 | data->rssi, data->ssp_mode, e->timestamp); | |
252 | } | |
253 | ||
254 | hci_dev_unlock(hdev); | |
255 | ||
256 | return 0; | |
257 | } | |
258 | ||
259 | static int inquiry_cache_open(struct inode *inode, struct file *file) | |
260 | { | |
261 | return single_open(file, inquiry_cache_show, inode->i_private); | |
262 | } | |
263 | ||
264 | static const struct file_operations inquiry_cache_fops = { | |
265 | .open = inquiry_cache_open, | |
266 | .read = seq_read, | |
267 | .llseek = seq_lseek, | |
268 | .release = single_release, | |
269 | }; | |
270 | ||
271 | static int link_keys_show(struct seq_file *f, void *ptr) | |
272 | { | |
273 | struct hci_dev *hdev = f->private; | |
274 | struct link_key *key; | |
275 | ||
276 | rcu_read_lock(); | |
277 | list_for_each_entry_rcu(key, &hdev->link_keys, list) | |
278 | seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type, | |
279 | HCI_LINK_KEY_SIZE, key->val, key->pin_len); | |
280 | rcu_read_unlock(); | |
281 | ||
282 | return 0; | |
283 | } | |
284 | ||
285 | static int link_keys_open(struct inode *inode, struct file *file) | |
286 | { | |
287 | return single_open(file, link_keys_show, inode->i_private); | |
288 | } | |
289 | ||
290 | static const struct file_operations link_keys_fops = { | |
291 | .open = link_keys_open, | |
292 | .read = seq_read, | |
293 | .llseek = seq_lseek, | |
294 | .release = single_release, | |
295 | }; | |
296 | ||
297 | static int dev_class_show(struct seq_file *f, void *ptr) | |
298 | { | |
299 | struct hci_dev *hdev = f->private; | |
300 | ||
301 | hci_dev_lock(hdev); | |
302 | seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2], | |
303 | hdev->dev_class[1], hdev->dev_class[0]); | |
304 | hci_dev_unlock(hdev); | |
305 | ||
306 | return 0; | |
307 | } | |
308 | ||
309 | static int dev_class_open(struct inode *inode, struct file *file) | |
310 | { | |
311 | return single_open(file, dev_class_show, inode->i_private); | |
312 | } | |
313 | ||
314 | static const struct file_operations dev_class_fops = { | |
315 | .open = dev_class_open, | |
316 | .read = seq_read, | |
317 | .llseek = seq_lseek, | |
318 | .release = single_release, | |
319 | }; | |
320 | ||
321 | static int voice_setting_get(void *data, u64 *val) | |
322 | { | |
323 | struct hci_dev *hdev = data; | |
324 | ||
325 | hci_dev_lock(hdev); | |
326 | *val = hdev->voice_setting; | |
327 | hci_dev_unlock(hdev); | |
328 | ||
329 | return 0; | |
330 | } | |
331 | ||
332 | DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get, | |
333 | NULL, "0x%4.4llx\n"); | |
334 | ||
335 | static int auto_accept_delay_set(void *data, u64 val) | |
336 | { | |
337 | struct hci_dev *hdev = data; | |
338 | ||
339 | hci_dev_lock(hdev); | |
340 | hdev->auto_accept_delay = val; | |
341 | hci_dev_unlock(hdev); | |
342 | ||
343 | return 0; | |
344 | } | |
345 | ||
346 | static int auto_accept_delay_get(void *data, u64 *val) | |
347 | { | |
348 | struct hci_dev *hdev = data; | |
349 | ||
350 | hci_dev_lock(hdev); | |
351 | *val = hdev->auto_accept_delay; | |
352 | hci_dev_unlock(hdev); | |
353 | ||
354 | return 0; | |
355 | } | |
356 | ||
357 | DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, | |
358 | auto_accept_delay_set, "%llu\n"); | |
359 | ||
360 | static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, | |
361 | size_t count, loff_t *ppos) | |
362 | { | |
363 | struct hci_dev *hdev = file->private_data; | |
364 | char buf[3]; | |
365 | ||
366 | buf[0] = test_bit(HCI_SC_ONLY, &hdev->dev_flags) ? 'Y': 'N'; | |
367 | buf[1] = '\n'; | |
368 | buf[2] = '\0'; | |
369 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | |
370 | } | |
371 | ||
372 | static const struct file_operations sc_only_mode_fops = { | |
373 | .open = simple_open, | |
374 | .read = sc_only_mode_read, | |
375 | .llseek = default_llseek, | |
376 | }; | |
377 | ||
71c3b60e MH |
378 | static int idle_timeout_set(void *data, u64 val) |
379 | { | |
380 | struct hci_dev *hdev = data; | |
381 | ||
382 | if (val != 0 && (val < 500 || val > 3600000)) | |
383 | return -EINVAL; | |
384 | ||
385 | hci_dev_lock(hdev); | |
386 | hdev->idle_timeout = val; | |
387 | hci_dev_unlock(hdev); | |
388 | ||
389 | return 0; | |
390 | } | |
391 | ||
392 | static int idle_timeout_get(void *data, u64 *val) | |
393 | { | |
394 | struct hci_dev *hdev = data; | |
395 | ||
396 | hci_dev_lock(hdev); | |
397 | *val = hdev->idle_timeout; | |
398 | hci_dev_unlock(hdev); | |
399 | ||
400 | return 0; | |
401 | } | |
402 | ||
403 | DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get, | |
404 | idle_timeout_set, "%llu\n"); | |
405 | ||
406 | static int sniff_min_interval_set(void *data, u64 val) | |
407 | { | |
408 | struct hci_dev *hdev = data; | |
409 | ||
410 | if (val == 0 || val % 2 || val > hdev->sniff_max_interval) | |
411 | return -EINVAL; | |
412 | ||
413 | hci_dev_lock(hdev); | |
414 | hdev->sniff_min_interval = val; | |
415 | hci_dev_unlock(hdev); | |
416 | ||
417 | return 0; | |
418 | } | |
419 | ||
420 | static int sniff_min_interval_get(void *data, u64 *val) | |
421 | { | |
422 | struct hci_dev *hdev = data; | |
423 | ||
424 | hci_dev_lock(hdev); | |
425 | *val = hdev->sniff_min_interval; | |
426 | hci_dev_unlock(hdev); | |
427 | ||
428 | return 0; | |
429 | } | |
430 | ||
431 | DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get, | |
432 | sniff_min_interval_set, "%llu\n"); | |
433 | ||
434 | static int sniff_max_interval_set(void *data, u64 val) | |
435 | { | |
436 | struct hci_dev *hdev = data; | |
437 | ||
438 | if (val == 0 || val % 2 || val < hdev->sniff_min_interval) | |
439 | return -EINVAL; | |
440 | ||
441 | hci_dev_lock(hdev); | |
442 | hdev->sniff_max_interval = val; | |
443 | hci_dev_unlock(hdev); | |
444 | ||
445 | return 0; | |
446 | } | |
447 | ||
448 | static int sniff_max_interval_get(void *data, u64 *val) | |
449 | { | |
450 | struct hci_dev *hdev = data; | |
451 | ||
452 | hci_dev_lock(hdev); | |
453 | *val = hdev->sniff_max_interval; | |
454 | hci_dev_unlock(hdev); | |
455 | ||
456 | return 0; | |
457 | } | |
458 | ||
459 | DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get, | |
460 | sniff_max_interval_set, "%llu\n"); | |
461 | ||
60c5f5fb MH |
462 | void hci_debugfs_create_bredr(struct hci_dev *hdev) |
463 | { | |
71c3b60e MH |
464 | debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev, |
465 | &inquiry_cache_fops); | |
466 | debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev, | |
467 | &link_keys_fops); | |
468 | debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev, | |
469 | &dev_class_fops); | |
470 | debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev, | |
471 | &voice_setting_fops); | |
472 | ||
473 | if (lmp_ssp_capable(hdev)) { | |
474 | debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs, | |
475 | hdev, &auto_accept_delay_fops); | |
476 | debugfs_create_file("sc_only_mode", 0444, hdev->debugfs, | |
477 | hdev, &sc_only_mode_fops); | |
71c3b60e MH |
478 | } |
479 | ||
480 | if (lmp_sniff_capable(hdev)) { | |
481 | debugfs_create_file("idle_timeout", 0644, hdev->debugfs, | |
482 | hdev, &idle_timeout_fops); | |
483 | debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs, | |
484 | hdev, &sniff_min_interval_fops); | |
485 | debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs, | |
486 | hdev, &sniff_max_interval_fops); | |
487 | } | |
60c5f5fb MH |
488 | } |
489 | ||
3a5c82b7 MH |
490 | static int identity_show(struct seq_file *f, void *p) |
491 | { | |
492 | struct hci_dev *hdev = f->private; | |
493 | bdaddr_t addr; | |
494 | u8 addr_type; | |
495 | ||
496 | hci_dev_lock(hdev); | |
497 | ||
498 | hci_copy_identity_address(hdev, &addr, &addr_type); | |
499 | ||
500 | seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type, | |
501 | 16, hdev->irk, &hdev->rpa); | |
502 | ||
503 | hci_dev_unlock(hdev); | |
504 | ||
505 | return 0; | |
506 | } | |
507 | ||
508 | static int identity_open(struct inode *inode, struct file *file) | |
509 | { | |
510 | return single_open(file, identity_show, inode->i_private); | |
511 | } | |
512 | ||
513 | static const struct file_operations identity_fops = { | |
514 | .open = identity_open, | |
515 | .read = seq_read, | |
516 | .llseek = seq_lseek, | |
517 | .release = single_release, | |
518 | }; | |
519 | ||
520 | static int rpa_timeout_set(void *data, u64 val) | |
521 | { | |
522 | struct hci_dev *hdev = data; | |
523 | ||
524 | /* Require the RPA timeout to be at least 30 seconds and at most | |
525 | * 24 hours. | |
526 | */ | |
527 | if (val < 30 || val > (60 * 60 * 24)) | |
528 | return -EINVAL; | |
529 | ||
530 | hci_dev_lock(hdev); | |
531 | hdev->rpa_timeout = val; | |
532 | hci_dev_unlock(hdev); | |
533 | ||
534 | return 0; | |
535 | } | |
536 | ||
537 | static int rpa_timeout_get(void *data, u64 *val) | |
538 | { | |
539 | struct hci_dev *hdev = data; | |
540 | ||
541 | hci_dev_lock(hdev); | |
542 | *val = hdev->rpa_timeout; | |
543 | hci_dev_unlock(hdev); | |
544 | ||
545 | return 0; | |
546 | } | |
547 | ||
548 | DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get, | |
549 | rpa_timeout_set, "%llu\n"); | |
550 | ||
551 | static int random_address_show(struct seq_file *f, void *p) | |
552 | { | |
553 | struct hci_dev *hdev = f->private; | |
554 | ||
555 | hci_dev_lock(hdev); | |
556 | seq_printf(f, "%pMR\n", &hdev->random_addr); | |
557 | hci_dev_unlock(hdev); | |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
562 | static int random_address_open(struct inode *inode, struct file *file) | |
563 | { | |
564 | return single_open(file, random_address_show, inode->i_private); | |
565 | } | |
566 | ||
567 | static const struct file_operations random_address_fops = { | |
568 | .open = random_address_open, | |
569 | .read = seq_read, | |
570 | .llseek = seq_lseek, | |
571 | .release = single_release, | |
572 | }; | |
573 | ||
574 | static int static_address_show(struct seq_file *f, void *p) | |
575 | { | |
576 | struct hci_dev *hdev = f->private; | |
577 | ||
578 | hci_dev_lock(hdev); | |
579 | seq_printf(f, "%pMR\n", &hdev->static_addr); | |
580 | hci_dev_unlock(hdev); | |
581 | ||
582 | return 0; | |
583 | } | |
584 | ||
585 | static int static_address_open(struct inode *inode, struct file *file) | |
586 | { | |
587 | return single_open(file, static_address_show, inode->i_private); | |
588 | } | |
589 | ||
590 | static const struct file_operations static_address_fops = { | |
591 | .open = static_address_open, | |
592 | .read = seq_read, | |
593 | .llseek = seq_lseek, | |
594 | .release = single_release, | |
595 | }; | |
596 | ||
597 | static ssize_t force_static_address_read(struct file *file, | |
598 | char __user *user_buf, | |
599 | size_t count, loff_t *ppos) | |
600 | { | |
601 | struct hci_dev *hdev = file->private_data; | |
602 | char buf[3]; | |
603 | ||
604 | buf[0] = test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags) ? 'Y': 'N'; | |
605 | buf[1] = '\n'; | |
606 | buf[2] = '\0'; | |
607 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | |
608 | } | |
609 | ||
610 | static ssize_t force_static_address_write(struct file *file, | |
611 | const char __user *user_buf, | |
612 | size_t count, loff_t *ppos) | |
613 | { | |
614 | struct hci_dev *hdev = file->private_data; | |
615 | char buf[32]; | |
616 | size_t buf_size = min(count, (sizeof(buf)-1)); | |
617 | bool enable; | |
618 | ||
619 | if (test_bit(HCI_UP, &hdev->flags)) | |
620 | return -EBUSY; | |
621 | ||
622 | if (copy_from_user(buf, user_buf, buf_size)) | |
623 | return -EFAULT; | |
624 | ||
625 | buf[buf_size] = '\0'; | |
626 | if (strtobool(buf, &enable)) | |
627 | return -EINVAL; | |
628 | ||
629 | if (enable == test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags)) | |
630 | return -EALREADY; | |
631 | ||
632 | change_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags); | |
633 | ||
634 | return count; | |
635 | } | |
636 | ||
637 | static const struct file_operations force_static_address_fops = { | |
638 | .open = simple_open, | |
639 | .read = force_static_address_read, | |
640 | .write = force_static_address_write, | |
641 | .llseek = default_llseek, | |
642 | }; | |
643 | ||
644 | static int white_list_show(struct seq_file *f, void *ptr) | |
645 | { | |
646 | struct hci_dev *hdev = f->private; | |
647 | struct bdaddr_list *b; | |
648 | ||
649 | hci_dev_lock(hdev); | |
650 | list_for_each_entry(b, &hdev->le_white_list, list) | |
651 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
652 | hci_dev_unlock(hdev); | |
653 | ||
654 | return 0; | |
655 | } | |
656 | ||
657 | static int white_list_open(struct inode *inode, struct file *file) | |
658 | { | |
659 | return single_open(file, white_list_show, inode->i_private); | |
660 | } | |
661 | ||
662 | static const struct file_operations white_list_fops = { | |
663 | .open = white_list_open, | |
664 | .read = seq_read, | |
665 | .llseek = seq_lseek, | |
666 | .release = single_release, | |
667 | }; | |
668 | ||
669 | static int identity_resolving_keys_show(struct seq_file *f, void *ptr) | |
670 | { | |
671 | struct hci_dev *hdev = f->private; | |
672 | struct smp_irk *irk; | |
673 | ||
674 | rcu_read_lock(); | |
675 | list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { | |
676 | seq_printf(f, "%pMR (type %u) %*phN %pMR\n", | |
677 | &irk->bdaddr, irk->addr_type, | |
678 | 16, irk->val, &irk->rpa); | |
679 | } | |
680 | rcu_read_unlock(); | |
681 | ||
682 | return 0; | |
683 | } | |
684 | ||
685 | static int identity_resolving_keys_open(struct inode *inode, struct file *file) | |
686 | { | |
687 | return single_open(file, identity_resolving_keys_show, | |
688 | inode->i_private); | |
689 | } | |
690 | ||
691 | static const struct file_operations identity_resolving_keys_fops = { | |
692 | .open = identity_resolving_keys_open, | |
693 | .read = seq_read, | |
694 | .llseek = seq_lseek, | |
695 | .release = single_release, | |
696 | }; | |
697 | ||
698 | static int long_term_keys_show(struct seq_file *f, void *ptr) | |
699 | { | |
700 | struct hci_dev *hdev = f->private; | |
701 | struct smp_ltk *ltk; | |
702 | ||
703 | rcu_read_lock(); | |
704 | list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list) | |
705 | seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n", | |
706 | <k->bdaddr, ltk->bdaddr_type, ltk->authenticated, | |
707 | ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv), | |
708 | __le64_to_cpu(ltk->rand), 16, ltk->val); | |
709 | rcu_read_unlock(); | |
710 | ||
711 | return 0; | |
712 | } | |
713 | ||
714 | static int long_term_keys_open(struct inode *inode, struct file *file) | |
715 | { | |
716 | return single_open(file, long_term_keys_show, inode->i_private); | |
717 | } | |
718 | ||
719 | static const struct file_operations long_term_keys_fops = { | |
720 | .open = long_term_keys_open, | |
721 | .read = seq_read, | |
722 | .llseek = seq_lseek, | |
723 | .release = single_release, | |
724 | }; | |
725 | ||
726 | static int conn_min_interval_set(void *data, u64 val) | |
727 | { | |
728 | struct hci_dev *hdev = data; | |
729 | ||
730 | if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval) | |
731 | return -EINVAL; | |
732 | ||
733 | hci_dev_lock(hdev); | |
734 | hdev->le_conn_min_interval = val; | |
735 | hci_dev_unlock(hdev); | |
736 | ||
737 | return 0; | |
738 | } | |
739 | ||
740 | static int conn_min_interval_get(void *data, u64 *val) | |
741 | { | |
742 | struct hci_dev *hdev = data; | |
743 | ||
744 | hci_dev_lock(hdev); | |
745 | *val = hdev->le_conn_min_interval; | |
746 | hci_dev_unlock(hdev); | |
747 | ||
748 | return 0; | |
749 | } | |
750 | ||
751 | DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get, | |
752 | conn_min_interval_set, "%llu\n"); | |
753 | ||
754 | static int conn_max_interval_set(void *data, u64 val) | |
755 | { | |
756 | struct hci_dev *hdev = data; | |
757 | ||
758 | if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval) | |
759 | return -EINVAL; | |
760 | ||
761 | hci_dev_lock(hdev); | |
762 | hdev->le_conn_max_interval = val; | |
763 | hci_dev_unlock(hdev); | |
764 | ||
765 | return 0; | |
766 | } | |
767 | ||
768 | static int conn_max_interval_get(void *data, u64 *val) | |
769 | { | |
770 | struct hci_dev *hdev = data; | |
771 | ||
772 | hci_dev_lock(hdev); | |
773 | *val = hdev->le_conn_max_interval; | |
774 | hci_dev_unlock(hdev); | |
775 | ||
776 | return 0; | |
777 | } | |
778 | ||
779 | DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get, | |
780 | conn_max_interval_set, "%llu\n"); | |
781 | ||
782 | static int conn_latency_set(void *data, u64 val) | |
783 | { | |
784 | struct hci_dev *hdev = data; | |
785 | ||
786 | if (val > 0x01f3) | |
787 | return -EINVAL; | |
788 | ||
789 | hci_dev_lock(hdev); | |
790 | hdev->le_conn_latency = val; | |
791 | hci_dev_unlock(hdev); | |
792 | ||
793 | return 0; | |
794 | } | |
795 | ||
796 | static int conn_latency_get(void *data, u64 *val) | |
797 | { | |
798 | struct hci_dev *hdev = data; | |
799 | ||
800 | hci_dev_lock(hdev); | |
801 | *val = hdev->le_conn_latency; | |
802 | hci_dev_unlock(hdev); | |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | DEFINE_SIMPLE_ATTRIBUTE(conn_latency_fops, conn_latency_get, | |
808 | conn_latency_set, "%llu\n"); | |
809 | ||
810 | static int supervision_timeout_set(void *data, u64 val) | |
811 | { | |
812 | struct hci_dev *hdev = data; | |
813 | ||
814 | if (val < 0x000a || val > 0x0c80) | |
815 | return -EINVAL; | |
816 | ||
817 | hci_dev_lock(hdev); | |
818 | hdev->le_supv_timeout = val; | |
819 | hci_dev_unlock(hdev); | |
820 | ||
821 | return 0; | |
822 | } | |
823 | ||
824 | static int supervision_timeout_get(void *data, u64 *val) | |
825 | { | |
826 | struct hci_dev *hdev = data; | |
827 | ||
828 | hci_dev_lock(hdev); | |
829 | *val = hdev->le_supv_timeout; | |
830 | hci_dev_unlock(hdev); | |
831 | ||
832 | return 0; | |
833 | } | |
834 | ||
835 | DEFINE_SIMPLE_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get, | |
836 | supervision_timeout_set, "%llu\n"); | |
837 | ||
838 | static int adv_channel_map_set(void *data, u64 val) | |
839 | { | |
840 | struct hci_dev *hdev = data; | |
841 | ||
842 | if (val < 0x01 || val > 0x07) | |
843 | return -EINVAL; | |
844 | ||
845 | hci_dev_lock(hdev); | |
846 | hdev->le_adv_channel_map = val; | |
847 | hci_dev_unlock(hdev); | |
848 | ||
849 | return 0; | |
850 | } | |
851 | ||
852 | static int adv_channel_map_get(void *data, u64 *val) | |
853 | { | |
854 | struct hci_dev *hdev = data; | |
855 | ||
856 | hci_dev_lock(hdev); | |
857 | *val = hdev->le_adv_channel_map; | |
858 | hci_dev_unlock(hdev); | |
859 | ||
860 | return 0; | |
861 | } | |
862 | ||
863 | DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get, | |
864 | adv_channel_map_set, "%llu\n"); | |
865 | ||
866 | static int adv_min_interval_set(void *data, u64 val) | |
867 | { | |
868 | struct hci_dev *hdev = data; | |
869 | ||
870 | if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) | |
871 | return -EINVAL; | |
872 | ||
873 | hci_dev_lock(hdev); | |
874 | hdev->le_adv_min_interval = val; | |
875 | hci_dev_unlock(hdev); | |
876 | ||
877 | return 0; | |
878 | } | |
879 | ||
880 | static int adv_min_interval_get(void *data, u64 *val) | |
881 | { | |
882 | struct hci_dev *hdev = data; | |
883 | ||
884 | hci_dev_lock(hdev); | |
885 | *val = hdev->le_adv_min_interval; | |
886 | hci_dev_unlock(hdev); | |
887 | ||
888 | return 0; | |
889 | } | |
890 | ||
891 | DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get, | |
892 | adv_min_interval_set, "%llu\n"); | |
893 | ||
894 | static int adv_max_interval_set(void *data, u64 val) | |
895 | { | |
896 | struct hci_dev *hdev = data; | |
897 | ||
898 | if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) | |
899 | return -EINVAL; | |
900 | ||
901 | hci_dev_lock(hdev); | |
902 | hdev->le_adv_max_interval = val; | |
903 | hci_dev_unlock(hdev); | |
904 | ||
905 | return 0; | |
906 | } | |
907 | ||
908 | static int adv_max_interval_get(void *data, u64 *val) | |
909 | { | |
910 | struct hci_dev *hdev = data; | |
911 | ||
912 | hci_dev_lock(hdev); | |
913 | *val = hdev->le_adv_max_interval; | |
914 | hci_dev_unlock(hdev); | |
915 | ||
916 | return 0; | |
917 | } | |
918 | ||
919 | DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get, | |
920 | adv_max_interval_set, "%llu\n"); | |
921 | ||
60c5f5fb MH |
922 | void hci_debugfs_create_le(struct hci_dev *hdev) |
923 | { | |
3a5c82b7 MH |
924 | debugfs_create_file("identity", 0400, hdev->debugfs, hdev, |
925 | &identity_fops); | |
926 | debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev, | |
927 | &rpa_timeout_fops); | |
928 | debugfs_create_file("random_address", 0444, hdev->debugfs, hdev, | |
929 | &random_address_fops); | |
930 | debugfs_create_file("static_address", 0444, hdev->debugfs, hdev, | |
931 | &static_address_fops); | |
932 | ||
933 | /* For controllers with a public address, provide a debug | |
934 | * option to force the usage of the configured static | |
935 | * address. By default the public address is used. | |
936 | */ | |
937 | if (bacmp(&hdev->bdaddr, BDADDR_ANY)) | |
938 | debugfs_create_file("force_static_address", 0644, | |
939 | hdev->debugfs, hdev, | |
940 | &force_static_address_fops); | |
941 | ||
942 | debugfs_create_u8("white_list_size", 0444, hdev->debugfs, | |
943 | &hdev->le_white_list_size); | |
944 | debugfs_create_file("white_list", 0444, hdev->debugfs, hdev, | |
945 | &white_list_fops); | |
946 | debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs, | |
947 | hdev, &identity_resolving_keys_fops); | |
948 | debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev, | |
949 | &long_term_keys_fops); | |
950 | debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev, | |
951 | &conn_min_interval_fops); | |
952 | debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev, | |
953 | &conn_max_interval_fops); | |
954 | debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev, | |
955 | &conn_latency_fops); | |
956 | debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev, | |
957 | &supervision_timeout_fops); | |
958 | debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev, | |
959 | &adv_channel_map_fops); | |
960 | debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev, | |
961 | &adv_min_interval_fops); | |
962 | debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev, | |
963 | &adv_max_interval_fops); | |
964 | debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs, | |
965 | &hdev->discov_interleaved_timeout); | |
60c5f5fb | 966 | } |
23b9ceb7 MH |
967 | |
968 | void hci_debugfs_create_conn(struct hci_conn *conn) | |
969 | { | |
970 | struct hci_dev *hdev = conn->hdev; | |
971 | char name[6]; | |
972 | ||
973 | if (IS_ERR_OR_NULL(hdev->debugfs)) | |
974 | return; | |
975 | ||
976 | snprintf(name, sizeof(name), "%u", conn->handle); | |
977 | conn->debugfs = debugfs_create_dir(name, hdev->debugfs); | |
978 | } |