powerpc/eeh: Fix PE#0 check in eeh_add_to_parent_pe()
[linux/fpc-iii.git] / net / bluetooth / hci_debugfs.c
blob65261e5d4b84bbbdc1da1d11083b9f32b6233d7a
1 /*
2 BlueZ - Bluetooth protocol stack for Linux
4 Copyright (C) 2014 Intel Corporation
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;
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.
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.
24 #include <linux/debugfs.h>
26 #include <net/bluetooth/bluetooth.h>
27 #include <net/bluetooth/hci_core.h>
29 #include "hci_debugfs.h"
31 static int features_show(struct seq_file *f, void *ptr)
33 struct hci_dev *hdev = f->private;
34 u8 p;
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]);
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);
54 return 0;
57 static int features_open(struct inode *inode, struct file *file)
59 return single_open(file, features_show, inode->i_private);
62 static const struct file_operations features_fops = {
63 .open = features_open,
64 .read = seq_read,
65 .llseek = seq_lseek,
66 .release = single_release,
69 static int device_list_show(struct seq_file *f, void *ptr)
71 struct hci_dev *hdev = f->private;
72 struct hci_conn_params *p;
73 struct bdaddr_list *b;
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);
82 hci_dev_unlock(hdev);
84 return 0;
87 static int device_list_open(struct inode *inode, struct file *file)
89 return single_open(file, device_list_show, inode->i_private);
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,
99 static int blacklist_show(struct seq_file *f, void *p)
101 struct hci_dev *hdev = f->private;
102 struct bdaddr_list *b;
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);
109 return 0;
112 static int blacklist_open(struct inode *inode, struct file *file)
114 return single_open(file, blacklist_show, inode->i_private);
117 static const struct file_operations blacklist_fops = {
118 .open = blacklist_open,
119 .read = seq_read,
120 .llseek = seq_lseek,
121 .release = single_release,
124 static int uuids_show(struct seq_file *f, void *p)
126 struct hci_dev *hdev = f->private;
127 struct bt_uuid *uuid;
129 hci_dev_lock(hdev);
130 list_for_each_entry(uuid, &hdev->uuids, list) {
131 u8 i, val[16];
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.
137 for (i = 0; i < 16; i++)
138 val[i] = uuid->uuid[15 - i];
140 seq_printf(f, "%pUb\n", val);
142 hci_dev_unlock(hdev);
144 return 0;
147 static int uuids_open(struct inode *inode, struct file *file)
149 return single_open(file, uuids_show, inode->i_private);
152 static const struct file_operations uuids_fops = {
153 .open = uuids_open,
154 .read = seq_read,
155 .llseek = seq_lseek,
156 .release = single_release,
159 static int remote_oob_show(struct seq_file *f, void *ptr)
161 struct hci_dev *hdev = f->private;
162 struct oob_data *data;
164 hci_dev_lock(hdev);
165 list_for_each_entry(data, &hdev->remote_oob_data, list) {
166 seq_printf(f, "%pMR (type %u) %u %*phN %*phN %*phN %*phN\n",
167 &data->bdaddr, data->bdaddr_type, data->present,
168 16, data->hash192, 16, data->rand192,
169 16, data->hash256, 19, data->rand256);
171 hci_dev_unlock(hdev);
173 return 0;
176 static int remote_oob_open(struct inode *inode, struct file *file)
178 return single_open(file, remote_oob_show, inode->i_private);
181 static const struct file_operations remote_oob_fops = {
182 .open = remote_oob_open,
183 .read = seq_read,
184 .llseek = seq_lseek,
185 .release = single_release,
188 static int conn_info_min_age_set(void *data, u64 val)
190 struct hci_dev *hdev = data;
192 if (val == 0 || val > hdev->conn_info_max_age)
193 return -EINVAL;
195 hci_dev_lock(hdev);
196 hdev->conn_info_min_age = val;
197 hci_dev_unlock(hdev);
199 return 0;
202 static int conn_info_min_age_get(void *data, u64 *val)
204 struct hci_dev *hdev = data;
206 hci_dev_lock(hdev);
207 *val = hdev->conn_info_min_age;
208 hci_dev_unlock(hdev);
210 return 0;
213 DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
214 conn_info_min_age_set, "%llu\n");
216 static int conn_info_max_age_set(void *data, u64 val)
218 struct hci_dev *hdev = data;
220 if (val == 0 || val < hdev->conn_info_min_age)
221 return -EINVAL;
223 hci_dev_lock(hdev);
224 hdev->conn_info_max_age = val;
225 hci_dev_unlock(hdev);
227 return 0;
230 static int conn_info_max_age_get(void *data, u64 *val)
232 struct hci_dev *hdev = data;
234 hci_dev_lock(hdev);
235 *val = hdev->conn_info_max_age;
236 hci_dev_unlock(hdev);
238 return 0;
241 DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
242 conn_info_max_age_set, "%llu\n");
244 static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
245 size_t count, loff_t *ppos)
247 struct hci_dev *hdev = file->private_data;
248 char buf[3];
250 buf[0] = test_bit(HCI_USE_DEBUG_KEYS, &hdev->dev_flags) ? 'Y': 'N';
251 buf[1] = '\n';
252 buf[2] = '\0';
253 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
256 static const struct file_operations use_debug_keys_fops = {
257 .open = simple_open,
258 .read = use_debug_keys_read,
259 .llseek = default_llseek,
262 static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
263 size_t count, loff_t *ppos)
265 struct hci_dev *hdev = file->private_data;
266 char buf[3];
268 buf[0] = test_bit(HCI_SC_ONLY, &hdev->dev_flags) ? 'Y': 'N';
269 buf[1] = '\n';
270 buf[2] = '\0';
271 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
274 static const struct file_operations sc_only_mode_fops = {
275 .open = simple_open,
276 .read = sc_only_mode_read,
277 .llseek = default_llseek,
280 void hci_debugfs_create_common(struct hci_dev *hdev)
282 debugfs_create_file("features", 0444, hdev->debugfs, hdev,
283 &features_fops);
284 debugfs_create_u16("manufacturer", 0444, hdev->debugfs,
285 &hdev->manufacturer);
286 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
287 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
288 debugfs_create_u8("hardware_error", 0444, hdev->debugfs,
289 &hdev->hw_error_code);
291 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
292 &device_list_fops);
293 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
294 &blacklist_fops);
295 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
296 debugfs_create_file("remote_oob", 0400, hdev->debugfs, hdev,
297 &remote_oob_fops);
299 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
300 &conn_info_min_age_fops);
301 debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
302 &conn_info_max_age_fops);
304 if (lmp_ssp_capable(hdev) || lmp_le_capable(hdev))
305 debugfs_create_file("use_debug_keys", 0444, hdev->debugfs,
306 hdev, &use_debug_keys_fops);
308 if (lmp_sc_capable(hdev) || lmp_le_capable(hdev))
309 debugfs_create_file("sc_only_mode", 0444, hdev->debugfs,
310 hdev, &sc_only_mode_fops);
313 static int inquiry_cache_show(struct seq_file *f, void *p)
315 struct hci_dev *hdev = f->private;
316 struct discovery_state *cache = &hdev->discovery;
317 struct inquiry_entry *e;
319 hci_dev_lock(hdev);
321 list_for_each_entry(e, &cache->all, all) {
322 struct inquiry_data *data = &e->data;
323 seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
324 &data->bdaddr,
325 data->pscan_rep_mode, data->pscan_period_mode,
326 data->pscan_mode, data->dev_class[2],
327 data->dev_class[1], data->dev_class[0],
328 __le16_to_cpu(data->clock_offset),
329 data->rssi, data->ssp_mode, e->timestamp);
332 hci_dev_unlock(hdev);
334 return 0;
337 static int inquiry_cache_open(struct inode *inode, struct file *file)
339 return single_open(file, inquiry_cache_show, inode->i_private);
342 static const struct file_operations inquiry_cache_fops = {
343 .open = inquiry_cache_open,
344 .read = seq_read,
345 .llseek = seq_lseek,
346 .release = single_release,
349 static int link_keys_show(struct seq_file *f, void *ptr)
351 struct hci_dev *hdev = f->private;
352 struct link_key *key;
354 rcu_read_lock();
355 list_for_each_entry_rcu(key, &hdev->link_keys, list)
356 seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
357 HCI_LINK_KEY_SIZE, key->val, key->pin_len);
358 rcu_read_unlock();
360 return 0;
363 static int link_keys_open(struct inode *inode, struct file *file)
365 return single_open(file, link_keys_show, inode->i_private);
368 static const struct file_operations link_keys_fops = {
369 .open = link_keys_open,
370 .read = seq_read,
371 .llseek = seq_lseek,
372 .release = single_release,
375 static int dev_class_show(struct seq_file *f, void *ptr)
377 struct hci_dev *hdev = f->private;
379 hci_dev_lock(hdev);
380 seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
381 hdev->dev_class[1], hdev->dev_class[0]);
382 hci_dev_unlock(hdev);
384 return 0;
387 static int dev_class_open(struct inode *inode, struct file *file)
389 return single_open(file, dev_class_show, inode->i_private);
392 static const struct file_operations dev_class_fops = {
393 .open = dev_class_open,
394 .read = seq_read,
395 .llseek = seq_lseek,
396 .release = single_release,
399 static int voice_setting_get(void *data, u64 *val)
401 struct hci_dev *hdev = data;
403 hci_dev_lock(hdev);
404 *val = hdev->voice_setting;
405 hci_dev_unlock(hdev);
407 return 0;
410 DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get,
411 NULL, "0x%4.4llx\n");
413 static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf,
414 size_t count, loff_t *ppos)
416 struct hci_dev *hdev = file->private_data;
417 char buf[3];
419 buf[0] = hdev->ssp_debug_mode ? 'Y': 'N';
420 buf[1] = '\n';
421 buf[2] = '\0';
422 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
425 static const struct file_operations ssp_debug_mode_fops = {
426 .open = simple_open,
427 .read = ssp_debug_mode_read,
428 .llseek = default_llseek,
431 static int auto_accept_delay_set(void *data, u64 val)
433 struct hci_dev *hdev = data;
435 hci_dev_lock(hdev);
436 hdev->auto_accept_delay = val;
437 hci_dev_unlock(hdev);
439 return 0;
442 static int auto_accept_delay_get(void *data, u64 *val)
444 struct hci_dev *hdev = data;
446 hci_dev_lock(hdev);
447 *val = hdev->auto_accept_delay;
448 hci_dev_unlock(hdev);
450 return 0;
453 DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
454 auto_accept_delay_set, "%llu\n");
456 static int idle_timeout_set(void *data, u64 val)
458 struct hci_dev *hdev = data;
460 if (val != 0 && (val < 500 || val > 3600000))
461 return -EINVAL;
463 hci_dev_lock(hdev);
464 hdev->idle_timeout = val;
465 hci_dev_unlock(hdev);
467 return 0;
470 static int idle_timeout_get(void *data, u64 *val)
472 struct hci_dev *hdev = data;
474 hci_dev_lock(hdev);
475 *val = hdev->idle_timeout;
476 hci_dev_unlock(hdev);
478 return 0;
481 DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
482 idle_timeout_set, "%llu\n");
484 static int sniff_min_interval_set(void *data, u64 val)
486 struct hci_dev *hdev = data;
488 if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
489 return -EINVAL;
491 hci_dev_lock(hdev);
492 hdev->sniff_min_interval = val;
493 hci_dev_unlock(hdev);
495 return 0;
498 static int sniff_min_interval_get(void *data, u64 *val)
500 struct hci_dev *hdev = data;
502 hci_dev_lock(hdev);
503 *val = hdev->sniff_min_interval;
504 hci_dev_unlock(hdev);
506 return 0;
509 DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
510 sniff_min_interval_set, "%llu\n");
512 static int sniff_max_interval_set(void *data, u64 val)
514 struct hci_dev *hdev = data;
516 if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
517 return -EINVAL;
519 hci_dev_lock(hdev);
520 hdev->sniff_max_interval = val;
521 hci_dev_unlock(hdev);
523 return 0;
526 static int sniff_max_interval_get(void *data, u64 *val)
528 struct hci_dev *hdev = data;
530 hci_dev_lock(hdev);
531 *val = hdev->sniff_max_interval;
532 hci_dev_unlock(hdev);
534 return 0;
537 DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
538 sniff_max_interval_set, "%llu\n");
540 void hci_debugfs_create_bredr(struct hci_dev *hdev)
542 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev,
543 &inquiry_cache_fops);
544 debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev,
545 &link_keys_fops);
546 debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev,
547 &dev_class_fops);
548 debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
549 &voice_setting_fops);
551 if (lmp_ssp_capable(hdev)) {
552 debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
553 hdev, &ssp_debug_mode_fops);
554 debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
555 hdev, &auto_accept_delay_fops);
558 if (lmp_sniff_capable(hdev)) {
559 debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
560 hdev, &idle_timeout_fops);
561 debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs,
562 hdev, &sniff_min_interval_fops);
563 debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs,
564 hdev, &sniff_max_interval_fops);
568 static int identity_show(struct seq_file *f, void *p)
570 struct hci_dev *hdev = f->private;
571 bdaddr_t addr;
572 u8 addr_type;
574 hci_dev_lock(hdev);
576 hci_copy_identity_address(hdev, &addr, &addr_type);
578 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
579 16, hdev->irk, &hdev->rpa);
581 hci_dev_unlock(hdev);
583 return 0;
586 static int identity_open(struct inode *inode, struct file *file)
588 return single_open(file, identity_show, inode->i_private);
591 static const struct file_operations identity_fops = {
592 .open = identity_open,
593 .read = seq_read,
594 .llseek = seq_lseek,
595 .release = single_release,
598 static int rpa_timeout_set(void *data, u64 val)
600 struct hci_dev *hdev = data;
602 /* Require the RPA timeout to be at least 30 seconds and at most
603 * 24 hours.
605 if (val < 30 || val > (60 * 60 * 24))
606 return -EINVAL;
608 hci_dev_lock(hdev);
609 hdev->rpa_timeout = val;
610 hci_dev_unlock(hdev);
612 return 0;
615 static int rpa_timeout_get(void *data, u64 *val)
617 struct hci_dev *hdev = data;
619 hci_dev_lock(hdev);
620 *val = hdev->rpa_timeout;
621 hci_dev_unlock(hdev);
623 return 0;
626 DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
627 rpa_timeout_set, "%llu\n");
629 static int random_address_show(struct seq_file *f, void *p)
631 struct hci_dev *hdev = f->private;
633 hci_dev_lock(hdev);
634 seq_printf(f, "%pMR\n", &hdev->random_addr);
635 hci_dev_unlock(hdev);
637 return 0;
640 static int random_address_open(struct inode *inode, struct file *file)
642 return single_open(file, random_address_show, inode->i_private);
645 static const struct file_operations random_address_fops = {
646 .open = random_address_open,
647 .read = seq_read,
648 .llseek = seq_lseek,
649 .release = single_release,
652 static int static_address_show(struct seq_file *f, void *p)
654 struct hci_dev *hdev = f->private;
656 hci_dev_lock(hdev);
657 seq_printf(f, "%pMR\n", &hdev->static_addr);
658 hci_dev_unlock(hdev);
660 return 0;
663 static int static_address_open(struct inode *inode, struct file *file)
665 return single_open(file, static_address_show, inode->i_private);
668 static const struct file_operations static_address_fops = {
669 .open = static_address_open,
670 .read = seq_read,
671 .llseek = seq_lseek,
672 .release = single_release,
675 static ssize_t force_static_address_read(struct file *file,
676 char __user *user_buf,
677 size_t count, loff_t *ppos)
679 struct hci_dev *hdev = file->private_data;
680 char buf[3];
682 buf[0] = test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags) ? 'Y': 'N';
683 buf[1] = '\n';
684 buf[2] = '\0';
685 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
688 static ssize_t force_static_address_write(struct file *file,
689 const char __user *user_buf,
690 size_t count, loff_t *ppos)
692 struct hci_dev *hdev = file->private_data;
693 char buf[32];
694 size_t buf_size = min(count, (sizeof(buf)-1));
695 bool enable;
697 if (test_bit(HCI_UP, &hdev->flags))
698 return -EBUSY;
700 if (copy_from_user(buf, user_buf, buf_size))
701 return -EFAULT;
703 buf[buf_size] = '\0';
704 if (strtobool(buf, &enable))
705 return -EINVAL;
707 if (enable == test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags))
708 return -EALREADY;
710 change_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags);
712 return count;
715 static const struct file_operations force_static_address_fops = {
716 .open = simple_open,
717 .read = force_static_address_read,
718 .write = force_static_address_write,
719 .llseek = default_llseek,
722 static int white_list_show(struct seq_file *f, void *ptr)
724 struct hci_dev *hdev = f->private;
725 struct bdaddr_list *b;
727 hci_dev_lock(hdev);
728 list_for_each_entry(b, &hdev->le_white_list, list)
729 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
730 hci_dev_unlock(hdev);
732 return 0;
735 static int white_list_open(struct inode *inode, struct file *file)
737 return single_open(file, white_list_show, inode->i_private);
740 static const struct file_operations white_list_fops = {
741 .open = white_list_open,
742 .read = seq_read,
743 .llseek = seq_lseek,
744 .release = single_release,
747 static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
749 struct hci_dev *hdev = f->private;
750 struct smp_irk *irk;
752 rcu_read_lock();
753 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
754 seq_printf(f, "%pMR (type %u) %*phN %pMR\n",
755 &irk->bdaddr, irk->addr_type,
756 16, irk->val, &irk->rpa);
758 rcu_read_unlock();
760 return 0;
763 static int identity_resolving_keys_open(struct inode *inode, struct file *file)
765 return single_open(file, identity_resolving_keys_show,
766 inode->i_private);
769 static const struct file_operations identity_resolving_keys_fops = {
770 .open = identity_resolving_keys_open,
771 .read = seq_read,
772 .llseek = seq_lseek,
773 .release = single_release,
776 static int long_term_keys_show(struct seq_file *f, void *ptr)
778 struct hci_dev *hdev = f->private;
779 struct smp_ltk *ltk;
781 rcu_read_lock();
782 list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list)
783 seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n",
784 &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated,
785 ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
786 __le64_to_cpu(ltk->rand), 16, ltk->val);
787 rcu_read_unlock();
789 return 0;
792 static int long_term_keys_open(struct inode *inode, struct file *file)
794 return single_open(file, long_term_keys_show, inode->i_private);
797 static const struct file_operations long_term_keys_fops = {
798 .open = long_term_keys_open,
799 .read = seq_read,
800 .llseek = seq_lseek,
801 .release = single_release,
804 static int conn_min_interval_set(void *data, u64 val)
806 struct hci_dev *hdev = data;
808 if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
809 return -EINVAL;
811 hci_dev_lock(hdev);
812 hdev->le_conn_min_interval = val;
813 hci_dev_unlock(hdev);
815 return 0;
818 static int conn_min_interval_get(void *data, u64 *val)
820 struct hci_dev *hdev = data;
822 hci_dev_lock(hdev);
823 *val = hdev->le_conn_min_interval;
824 hci_dev_unlock(hdev);
826 return 0;
829 DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
830 conn_min_interval_set, "%llu\n");
832 static int conn_max_interval_set(void *data, u64 val)
834 struct hci_dev *hdev = data;
836 if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
837 return -EINVAL;
839 hci_dev_lock(hdev);
840 hdev->le_conn_max_interval = val;
841 hci_dev_unlock(hdev);
843 return 0;
846 static int conn_max_interval_get(void *data, u64 *val)
848 struct hci_dev *hdev = data;
850 hci_dev_lock(hdev);
851 *val = hdev->le_conn_max_interval;
852 hci_dev_unlock(hdev);
854 return 0;
857 DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
858 conn_max_interval_set, "%llu\n");
860 static int conn_latency_set(void *data, u64 val)
862 struct hci_dev *hdev = data;
864 if (val > 0x01f3)
865 return -EINVAL;
867 hci_dev_lock(hdev);
868 hdev->le_conn_latency = val;
869 hci_dev_unlock(hdev);
871 return 0;
874 static int conn_latency_get(void *data, u64 *val)
876 struct hci_dev *hdev = data;
878 hci_dev_lock(hdev);
879 *val = hdev->le_conn_latency;
880 hci_dev_unlock(hdev);
882 return 0;
885 DEFINE_SIMPLE_ATTRIBUTE(conn_latency_fops, conn_latency_get,
886 conn_latency_set, "%llu\n");
888 static int supervision_timeout_set(void *data, u64 val)
890 struct hci_dev *hdev = data;
892 if (val < 0x000a || val > 0x0c80)
893 return -EINVAL;
895 hci_dev_lock(hdev);
896 hdev->le_supv_timeout = val;
897 hci_dev_unlock(hdev);
899 return 0;
902 static int supervision_timeout_get(void *data, u64 *val)
904 struct hci_dev *hdev = data;
906 hci_dev_lock(hdev);
907 *val = hdev->le_supv_timeout;
908 hci_dev_unlock(hdev);
910 return 0;
913 DEFINE_SIMPLE_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get,
914 supervision_timeout_set, "%llu\n");
916 static int adv_channel_map_set(void *data, u64 val)
918 struct hci_dev *hdev = data;
920 if (val < 0x01 || val > 0x07)
921 return -EINVAL;
923 hci_dev_lock(hdev);
924 hdev->le_adv_channel_map = val;
925 hci_dev_unlock(hdev);
927 return 0;
930 static int adv_channel_map_get(void *data, u64 *val)
932 struct hci_dev *hdev = data;
934 hci_dev_lock(hdev);
935 *val = hdev->le_adv_channel_map;
936 hci_dev_unlock(hdev);
938 return 0;
941 DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
942 adv_channel_map_set, "%llu\n");
944 static int adv_min_interval_set(void *data, u64 val)
946 struct hci_dev *hdev = data;
948 if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval)
949 return -EINVAL;
951 hci_dev_lock(hdev);
952 hdev->le_adv_min_interval = val;
953 hci_dev_unlock(hdev);
955 return 0;
958 static int adv_min_interval_get(void *data, u64 *val)
960 struct hci_dev *hdev = data;
962 hci_dev_lock(hdev);
963 *val = hdev->le_adv_min_interval;
964 hci_dev_unlock(hdev);
966 return 0;
969 DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,
970 adv_min_interval_set, "%llu\n");
972 static int adv_max_interval_set(void *data, u64 val)
974 struct hci_dev *hdev = data;
976 if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval)
977 return -EINVAL;
979 hci_dev_lock(hdev);
980 hdev->le_adv_max_interval = val;
981 hci_dev_unlock(hdev);
983 return 0;
986 static int adv_max_interval_get(void *data, u64 *val)
988 struct hci_dev *hdev = data;
990 hci_dev_lock(hdev);
991 *val = hdev->le_adv_max_interval;
992 hci_dev_unlock(hdev);
994 return 0;
997 DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
998 adv_max_interval_set, "%llu\n");
1000 void hci_debugfs_create_le(struct hci_dev *hdev)
1002 debugfs_create_file("identity", 0400, hdev->debugfs, hdev,
1003 &identity_fops);
1004 debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev,
1005 &rpa_timeout_fops);
1006 debugfs_create_file("random_address", 0444, hdev->debugfs, hdev,
1007 &random_address_fops);
1008 debugfs_create_file("static_address", 0444, hdev->debugfs, hdev,
1009 &static_address_fops);
1011 /* For controllers with a public address, provide a debug
1012 * option to force the usage of the configured static
1013 * address. By default the public address is used.
1015 if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1016 debugfs_create_file("force_static_address", 0644,
1017 hdev->debugfs, hdev,
1018 &force_static_address_fops);
1020 debugfs_create_u8("white_list_size", 0444, hdev->debugfs,
1021 &hdev->le_white_list_size);
1022 debugfs_create_file("white_list", 0444, hdev->debugfs, hdev,
1023 &white_list_fops);
1024 debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs,
1025 hdev, &identity_resolving_keys_fops);
1026 debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev,
1027 &long_term_keys_fops);
1028 debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev,
1029 &conn_min_interval_fops);
1030 debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev,
1031 &conn_max_interval_fops);
1032 debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev,
1033 &conn_latency_fops);
1034 debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev,
1035 &supervision_timeout_fops);
1036 debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev,
1037 &adv_channel_map_fops);
1038 debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev,
1039 &adv_min_interval_fops);
1040 debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev,
1041 &adv_max_interval_fops);
1042 debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
1043 &hdev->discov_interleaved_timeout);
1046 void hci_debugfs_create_conn(struct hci_conn *conn)
1048 struct hci_dev *hdev = conn->hdev;
1049 char name[6];
1051 if (IS_ERR_OR_NULL(hdev->debugfs))
1052 return;
1054 snprintf(name, sizeof(name), "%u", conn->handle);
1055 conn->debugfs = debugfs_create_dir(name, hdev->debugfs);