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>
25 #include <linux/kstrtox.h>
27 #include <net/bluetooth/bluetooth.h>
28 #include <net/bluetooth/hci_core.h>
31 #include "hci_request.h"
32 #include "hci_debugfs.h"
34 #define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk) \
35 static ssize_t __name ## _read(struct file *file, \
36 char __user *user_buf, \
37 size_t count, loff_t *ppos) \
39 struct hci_dev *hdev = file->private_data; \
42 buf[0] = test_bit(__quirk, &hdev->quirks) ? 'Y' : 'N'; \
45 return simple_read_from_buffer(user_buf, count, ppos, buf, 2); \
48 static ssize_t __name ## _write(struct file *file, \
49 const char __user *user_buf, \
50 size_t count, loff_t *ppos) \
52 struct hci_dev *hdev = file->private_data; \
56 if (test_bit(HCI_UP, &hdev->flags)) \
59 err = kstrtobool_from_user(user_buf, count, &enable); \
63 if (enable == test_bit(__quirk, &hdev->quirks)) \
66 change_bit(__quirk, &hdev->quirks); \
71 static const struct file_operations __name ## _fops = { \
72 .open = simple_open, \
73 .read = __name ## _read, \
74 .write = __name ## _write, \
75 .llseek = default_llseek, \
78 #define DEFINE_INFO_ATTRIBUTE(__name, __field) \
79 static int __name ## _show(struct seq_file *f, void *ptr) \
81 struct hci_dev *hdev = f->private; \
84 seq_printf(f, "%s\n", hdev->__field ? : ""); \
85 hci_dev_unlock(hdev); \
90 DEFINE_SHOW_ATTRIBUTE(__name)
92 static int features_show(struct seq_file *f, void *ptr)
94 struct hci_dev *hdev = f->private;
98 for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++)
99 seq_printf(f, "%2u: %8ph\n", p, hdev->features[p]);
100 if (lmp_le_capable(hdev))
101 seq_printf(f, "LE: %8ph\n", hdev->le_features);
102 hci_dev_unlock(hdev);
107 DEFINE_SHOW_ATTRIBUTE(features);
109 static int device_id_show(struct seq_file *f, void *ptr)
111 struct hci_dev *hdev = f->private;
114 seq_printf(f, "%4.4x:%4.4x:%4.4x:%4.4x\n", hdev->devid_source,
115 hdev->devid_vendor, hdev->devid_product, hdev->devid_version);
116 hci_dev_unlock(hdev);
121 DEFINE_SHOW_ATTRIBUTE(device_id);
123 static int device_list_show(struct seq_file *f, void *ptr)
125 struct hci_dev *hdev = f->private;
126 struct hci_conn_params *p;
127 struct bdaddr_list *b;
130 list_for_each_entry(b, &hdev->accept_list, list)
131 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
132 list_for_each_entry(p, &hdev->le_conn_params, list) {
133 seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type,
136 hci_dev_unlock(hdev);
141 DEFINE_SHOW_ATTRIBUTE(device_list);
143 static int blacklist_show(struct seq_file *f, void *p)
145 struct hci_dev *hdev = f->private;
146 struct bdaddr_list *b;
149 list_for_each_entry(b, &hdev->reject_list, list)
150 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
151 hci_dev_unlock(hdev);
156 DEFINE_SHOW_ATTRIBUTE(blacklist);
158 static int blocked_keys_show(struct seq_file *f, void *p)
160 struct hci_dev *hdev = f->private;
161 struct blocked_key *key;
164 list_for_each_entry_rcu(key, &hdev->blocked_keys, list)
165 seq_printf(f, "%u %*phN\n", key->type, 16, key->val);
171 DEFINE_SHOW_ATTRIBUTE(blocked_keys);
173 static int uuids_show(struct seq_file *f, void *p)
175 struct hci_dev *hdev = f->private;
176 struct bt_uuid *uuid;
179 list_for_each_entry(uuid, &hdev->uuids, list) {
182 /* The Bluetooth UUID values are stored in big endian,
183 * but with reversed byte order. So convert them into
184 * the right order for the %pUb modifier.
186 for (i = 0; i < 16; i++)
187 val[i] = uuid->uuid[15 - i];
189 seq_printf(f, "%pUb\n", val);
191 hci_dev_unlock(hdev);
196 DEFINE_SHOW_ATTRIBUTE(uuids);
198 static int remote_oob_show(struct seq_file *f, void *ptr)
200 struct hci_dev *hdev = f->private;
201 struct oob_data *data;
204 list_for_each_entry(data, &hdev->remote_oob_data, list) {
205 seq_printf(f, "%pMR (type %u) %u %*phN %*phN %*phN %*phN\n",
206 &data->bdaddr, data->bdaddr_type, data->present,
207 16, data->hash192, 16, data->rand192,
208 16, data->hash256, 16, data->rand256);
210 hci_dev_unlock(hdev);
215 DEFINE_SHOW_ATTRIBUTE(remote_oob);
217 static int conn_info_min_age_set(void *data, u64 val)
219 struct hci_dev *hdev = data;
221 if (val == 0 || val > hdev->conn_info_max_age)
225 hdev->conn_info_min_age = val;
226 hci_dev_unlock(hdev);
231 static int conn_info_min_age_get(void *data, u64 *val)
233 struct hci_dev *hdev = data;
236 *val = hdev->conn_info_min_age;
237 hci_dev_unlock(hdev);
242 DEFINE_DEBUGFS_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
243 conn_info_min_age_set, "%llu\n");
245 static int conn_info_max_age_set(void *data, u64 val)
247 struct hci_dev *hdev = data;
249 if (val == 0 || val < hdev->conn_info_min_age)
253 hdev->conn_info_max_age = val;
254 hci_dev_unlock(hdev);
259 static int conn_info_max_age_get(void *data, u64 *val)
261 struct hci_dev *hdev = data;
264 *val = hdev->conn_info_max_age;
265 hci_dev_unlock(hdev);
270 DEFINE_DEBUGFS_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
271 conn_info_max_age_set, "%llu\n");
273 static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
274 size_t count, loff_t *ppos)
276 struct hci_dev *hdev = file->private_data;
279 buf[0] = hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS) ? 'Y' : 'N';
282 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
285 static const struct file_operations use_debug_keys_fops = {
287 .read = use_debug_keys_read,
288 .llseek = default_llseek,
291 static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
292 size_t count, loff_t *ppos)
294 struct hci_dev *hdev = file->private_data;
297 buf[0] = hci_dev_test_flag(hdev, HCI_SC_ONLY) ? 'Y' : 'N';
300 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
303 static const struct file_operations sc_only_mode_fops = {
305 .read = sc_only_mode_read,
306 .llseek = default_llseek,
309 DEFINE_INFO_ATTRIBUTE(hardware_info, hw_info);
310 DEFINE_INFO_ATTRIBUTE(firmware_info, fw_info);
312 void hci_debugfs_create_common(struct hci_dev *hdev)
314 debugfs_create_file("features", 0444, hdev->debugfs, hdev,
316 debugfs_create_u16("manufacturer", 0444, hdev->debugfs,
317 &hdev->manufacturer);
318 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
319 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
320 debugfs_create_u8("hardware_error", 0444, hdev->debugfs,
321 &hdev->hw_error_code);
322 debugfs_create_file("device_id", 0444, hdev->debugfs, hdev,
325 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
327 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
329 debugfs_create_file("blocked_keys", 0444, hdev->debugfs, hdev,
331 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
332 debugfs_create_file("remote_oob", 0400, hdev->debugfs, hdev,
335 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
336 &conn_info_min_age_fops);
337 debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
338 &conn_info_max_age_fops);
340 if (lmp_ssp_capable(hdev) || lmp_le_capable(hdev))
341 debugfs_create_file("use_debug_keys", 0444, hdev->debugfs,
342 hdev, &use_debug_keys_fops);
344 if (lmp_sc_capable(hdev) || lmp_le_capable(hdev))
345 debugfs_create_file("sc_only_mode", 0444, hdev->debugfs,
346 hdev, &sc_only_mode_fops);
349 debugfs_create_file("hardware_info", 0444, hdev->debugfs,
350 hdev, &hardware_info_fops);
353 debugfs_create_file("firmware_info", 0444, hdev->debugfs,
354 hdev, &firmware_info_fops);
357 static int inquiry_cache_show(struct seq_file *f, void *p)
359 struct hci_dev *hdev = f->private;
360 struct discovery_state *cache = &hdev->discovery;
361 struct inquiry_entry *e;
365 list_for_each_entry(e, &cache->all, all) {
366 struct inquiry_data *data = &e->data;
367 seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
369 data->pscan_rep_mode, data->pscan_period_mode,
370 data->pscan_mode, data->dev_class[2],
371 data->dev_class[1], data->dev_class[0],
372 __le16_to_cpu(data->clock_offset),
373 data->rssi, data->ssp_mode, e->timestamp);
376 hci_dev_unlock(hdev);
381 DEFINE_SHOW_ATTRIBUTE(inquiry_cache);
383 static int link_keys_show(struct seq_file *f, void *ptr)
385 struct hci_dev *hdev = f->private;
386 struct link_key *key;
389 list_for_each_entry_rcu(key, &hdev->link_keys, list)
390 seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
391 HCI_LINK_KEY_SIZE, key->val, key->pin_len);
397 DEFINE_SHOW_ATTRIBUTE(link_keys);
399 static int dev_class_show(struct seq_file *f, void *ptr)
401 struct hci_dev *hdev = f->private;
404 seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
405 hdev->dev_class[1], hdev->dev_class[0]);
406 hci_dev_unlock(hdev);
411 DEFINE_SHOW_ATTRIBUTE(dev_class);
413 static int voice_setting_get(void *data, u64 *val)
415 struct hci_dev *hdev = data;
418 *val = hdev->voice_setting;
419 hci_dev_unlock(hdev);
424 DEFINE_DEBUGFS_ATTRIBUTE(voice_setting_fops, voice_setting_get,
425 NULL, "0x%4.4llx\n");
427 static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf,
428 size_t count, loff_t *ppos)
430 struct hci_dev *hdev = file->private_data;
433 buf[0] = hdev->ssp_debug_mode ? 'Y' : 'N';
436 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
439 static const struct file_operations ssp_debug_mode_fops = {
441 .read = ssp_debug_mode_read,
442 .llseek = default_llseek,
445 static int auto_accept_delay_set(void *data, u64 val)
447 struct hci_dev *hdev = data;
450 hdev->auto_accept_delay = val;
451 hci_dev_unlock(hdev);
456 static int min_encrypt_key_size_set(void *data, u64 val)
458 struct hci_dev *hdev = data;
460 if (val < 1 || val > 16)
464 hdev->min_enc_key_size = val;
465 hci_dev_unlock(hdev);
470 static int min_encrypt_key_size_get(void *data, u64 *val)
472 struct hci_dev *hdev = data;
475 *val = hdev->min_enc_key_size;
476 hci_dev_unlock(hdev);
481 DEFINE_DEBUGFS_ATTRIBUTE(min_encrypt_key_size_fops,
482 min_encrypt_key_size_get,
483 min_encrypt_key_size_set, "%llu\n");
485 static int auto_accept_delay_get(void *data, u64 *val)
487 struct hci_dev *hdev = data;
490 *val = hdev->auto_accept_delay;
491 hci_dev_unlock(hdev);
496 DEFINE_DEBUGFS_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
497 auto_accept_delay_set, "%llu\n");
499 static ssize_t force_bredr_smp_read(struct file *file,
500 char __user *user_buf,
501 size_t count, loff_t *ppos)
503 struct hci_dev *hdev = file->private_data;
506 buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y' : 'N';
509 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
512 static ssize_t force_bredr_smp_write(struct file *file,
513 const char __user *user_buf,
514 size_t count, loff_t *ppos)
516 struct hci_dev *hdev = file->private_data;
520 err = kstrtobool_from_user(user_buf, count, &enable);
524 err = smp_force_bredr(hdev, enable);
531 static const struct file_operations force_bredr_smp_fops = {
533 .read = force_bredr_smp_read,
534 .write = force_bredr_smp_write,
535 .llseek = default_llseek,
538 static int idle_timeout_set(void *data, u64 val)
540 struct hci_dev *hdev = data;
542 if (val != 0 && (val < 500 || val > 3600000))
546 hdev->idle_timeout = val;
547 hci_dev_unlock(hdev);
552 static int idle_timeout_get(void *data, u64 *val)
554 struct hci_dev *hdev = data;
557 *val = hdev->idle_timeout;
558 hci_dev_unlock(hdev);
563 DEFINE_DEBUGFS_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
564 idle_timeout_set, "%llu\n");
566 static int sniff_min_interval_set(void *data, u64 val)
568 struct hci_dev *hdev = data;
570 if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
574 hdev->sniff_min_interval = val;
575 hci_dev_unlock(hdev);
580 static int sniff_min_interval_get(void *data, u64 *val)
582 struct hci_dev *hdev = data;
585 *val = hdev->sniff_min_interval;
586 hci_dev_unlock(hdev);
591 DEFINE_DEBUGFS_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
592 sniff_min_interval_set, "%llu\n");
594 static int sniff_max_interval_set(void *data, u64 val)
596 struct hci_dev *hdev = data;
598 if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
602 hdev->sniff_max_interval = val;
603 hci_dev_unlock(hdev);
608 static int sniff_max_interval_get(void *data, u64 *val)
610 struct hci_dev *hdev = data;
613 *val = hdev->sniff_max_interval;
614 hci_dev_unlock(hdev);
619 DEFINE_DEBUGFS_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
620 sniff_max_interval_set, "%llu\n");
622 void hci_debugfs_create_bredr(struct hci_dev *hdev)
624 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev,
625 &inquiry_cache_fops);
626 debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev,
628 debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev,
630 debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
631 &voice_setting_fops);
633 /* If the controller does not support BR/EDR Secure Connections
634 * feature, then the BR/EDR SMP channel shall not be present.
636 * To test this with Bluetooth 4.0 controllers, create a debugfs
637 * switch that allows forcing BR/EDR SMP support and accepting
638 * cross-transport pairing on non-AES encrypted connections.
640 if (!lmp_sc_capable(hdev))
641 debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs,
642 hdev, &force_bredr_smp_fops);
644 if (lmp_ssp_capable(hdev)) {
645 debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
646 hdev, &ssp_debug_mode_fops);
647 debugfs_create_file("min_encrypt_key_size", 0644, hdev->debugfs,
648 hdev, &min_encrypt_key_size_fops);
649 debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
650 hdev, &auto_accept_delay_fops);
653 if (lmp_sniff_capable(hdev)) {
654 debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
655 hdev, &idle_timeout_fops);
656 debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs,
657 hdev, &sniff_min_interval_fops);
658 debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs,
659 hdev, &sniff_max_interval_fops);
663 static int identity_show(struct seq_file *f, void *p)
665 struct hci_dev *hdev = f->private;
671 hci_copy_identity_address(hdev, &addr, &addr_type);
673 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
674 16, hdev->irk, &hdev->rpa);
676 hci_dev_unlock(hdev);
681 DEFINE_SHOW_ATTRIBUTE(identity);
683 static int rpa_timeout_set(void *data, u64 val)
685 struct hci_dev *hdev = data;
687 /* Require the RPA timeout to be at least 30 seconds and at most
690 if (val < 30 || val > (60 * 60 * 24))
694 hdev->rpa_timeout = val;
695 hci_dev_unlock(hdev);
700 static int rpa_timeout_get(void *data, u64 *val)
702 struct hci_dev *hdev = data;
705 *val = hdev->rpa_timeout;
706 hci_dev_unlock(hdev);
711 DEFINE_DEBUGFS_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
712 rpa_timeout_set, "%llu\n");
714 static int random_address_show(struct seq_file *f, void *p)
716 struct hci_dev *hdev = f->private;
719 seq_printf(f, "%pMR\n", &hdev->random_addr);
720 hci_dev_unlock(hdev);
725 DEFINE_SHOW_ATTRIBUTE(random_address);
727 static int static_address_show(struct seq_file *f, void *p)
729 struct hci_dev *hdev = f->private;
732 seq_printf(f, "%pMR\n", &hdev->static_addr);
733 hci_dev_unlock(hdev);
738 DEFINE_SHOW_ATTRIBUTE(static_address);
740 static ssize_t force_static_address_read(struct file *file,
741 char __user *user_buf,
742 size_t count, loff_t *ppos)
744 struct hci_dev *hdev = file->private_data;
747 buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ? 'Y' : 'N';
750 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
753 static ssize_t force_static_address_write(struct file *file,
754 const char __user *user_buf,
755 size_t count, loff_t *ppos)
757 struct hci_dev *hdev = file->private_data;
761 if (hdev_is_powered(hdev))
764 err = kstrtobool_from_user(user_buf, count, &enable);
768 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR))
771 hci_dev_change_flag(hdev, HCI_FORCE_STATIC_ADDR);
776 static const struct file_operations force_static_address_fops = {
778 .read = force_static_address_read,
779 .write = force_static_address_write,
780 .llseek = default_llseek,
783 static int white_list_show(struct seq_file *f, void *ptr)
785 struct hci_dev *hdev = f->private;
786 struct bdaddr_list *b;
789 list_for_each_entry(b, &hdev->le_accept_list, list)
790 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
791 hci_dev_unlock(hdev);
796 DEFINE_SHOW_ATTRIBUTE(white_list);
798 static int resolv_list_show(struct seq_file *f, void *ptr)
800 struct hci_dev *hdev = f->private;
801 struct bdaddr_list *b;
804 list_for_each_entry(b, &hdev->le_resolv_list, list)
805 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
806 hci_dev_unlock(hdev);
811 DEFINE_SHOW_ATTRIBUTE(resolv_list);
813 static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
815 struct hci_dev *hdev = f->private;
819 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
820 seq_printf(f, "%pMR (type %u) %*phN %pMR\n",
821 &irk->bdaddr, irk->addr_type,
822 16, irk->val, &irk->rpa);
829 DEFINE_SHOW_ATTRIBUTE(identity_resolving_keys);
831 static int long_term_keys_show(struct seq_file *f, void *ptr)
833 struct hci_dev *hdev = f->private;
837 list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list)
838 seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n",
839 <k->bdaddr, ltk->bdaddr_type, ltk->authenticated,
840 ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
841 __le64_to_cpu(ltk->rand), 16, ltk->val);
847 DEFINE_SHOW_ATTRIBUTE(long_term_keys);
849 static int conn_min_interval_set(void *data, u64 val)
851 struct hci_dev *hdev = data;
853 if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
857 hdev->le_conn_min_interval = val;
858 hci_dev_unlock(hdev);
863 static int conn_min_interval_get(void *data, u64 *val)
865 struct hci_dev *hdev = data;
868 *val = hdev->le_conn_min_interval;
869 hci_dev_unlock(hdev);
874 DEFINE_DEBUGFS_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
875 conn_min_interval_set, "%llu\n");
877 static int conn_max_interval_set(void *data, u64 val)
879 struct hci_dev *hdev = data;
881 if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
885 hdev->le_conn_max_interval = val;
886 hci_dev_unlock(hdev);
891 static int conn_max_interval_get(void *data, u64 *val)
893 struct hci_dev *hdev = data;
896 *val = hdev->le_conn_max_interval;
897 hci_dev_unlock(hdev);
902 DEFINE_DEBUGFS_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
903 conn_max_interval_set, "%llu\n");
905 static int conn_latency_set(void *data, u64 val)
907 struct hci_dev *hdev = data;
913 hdev->le_conn_latency = val;
914 hci_dev_unlock(hdev);
919 static int conn_latency_get(void *data, u64 *val)
921 struct hci_dev *hdev = data;
924 *val = hdev->le_conn_latency;
925 hci_dev_unlock(hdev);
930 DEFINE_DEBUGFS_ATTRIBUTE(conn_latency_fops, conn_latency_get,
931 conn_latency_set, "%llu\n");
933 static int supervision_timeout_set(void *data, u64 val)
935 struct hci_dev *hdev = data;
937 if (val < 0x000a || val > 0x0c80)
941 hdev->le_supv_timeout = val;
942 hci_dev_unlock(hdev);
947 static int supervision_timeout_get(void *data, u64 *val)
949 struct hci_dev *hdev = data;
952 *val = hdev->le_supv_timeout;
953 hci_dev_unlock(hdev);
958 DEFINE_DEBUGFS_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get,
959 supervision_timeout_set, "%llu\n");
961 static int adv_channel_map_set(void *data, u64 val)
963 struct hci_dev *hdev = data;
965 if (val < 0x01 || val > 0x07)
969 hdev->le_adv_channel_map = val;
970 hci_dev_unlock(hdev);
975 static int adv_channel_map_get(void *data, u64 *val)
977 struct hci_dev *hdev = data;
980 *val = hdev->le_adv_channel_map;
981 hci_dev_unlock(hdev);
986 DEFINE_DEBUGFS_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
987 adv_channel_map_set, "%llu\n");
989 static int adv_min_interval_set(void *data, u64 val)
991 struct hci_dev *hdev = data;
993 if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval)
997 hdev->le_adv_min_interval = val;
998 hci_dev_unlock(hdev);
1003 static int adv_min_interval_get(void *data, u64 *val)
1005 struct hci_dev *hdev = data;
1008 *val = hdev->le_adv_min_interval;
1009 hci_dev_unlock(hdev);
1014 DEFINE_DEBUGFS_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,
1015 adv_min_interval_set, "%llu\n");
1017 static int adv_max_interval_set(void *data, u64 val)
1019 struct hci_dev *hdev = data;
1021 if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval)
1025 hdev->le_adv_max_interval = val;
1026 hci_dev_unlock(hdev);
1031 static int adv_max_interval_get(void *data, u64 *val)
1033 struct hci_dev *hdev = data;
1036 *val = hdev->le_adv_max_interval;
1037 hci_dev_unlock(hdev);
1042 DEFINE_DEBUGFS_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
1043 adv_max_interval_set, "%llu\n");
1045 static int min_key_size_set(void *data, u64 val)
1047 struct hci_dev *hdev = data;
1049 if (val > hdev->le_max_key_size || val < SMP_MIN_ENC_KEY_SIZE)
1053 hdev->le_min_key_size = val;
1054 hci_dev_unlock(hdev);
1059 static int min_key_size_get(void *data, u64 *val)
1061 struct hci_dev *hdev = data;
1064 *val = hdev->le_min_key_size;
1065 hci_dev_unlock(hdev);
1070 DEFINE_DEBUGFS_ATTRIBUTE(min_key_size_fops, min_key_size_get,
1071 min_key_size_set, "%llu\n");
1073 static int max_key_size_set(void *data, u64 val)
1075 struct hci_dev *hdev = data;
1077 if (val > SMP_MAX_ENC_KEY_SIZE || val < hdev->le_min_key_size)
1081 hdev->le_max_key_size = val;
1082 hci_dev_unlock(hdev);
1087 static int max_key_size_get(void *data, u64 *val)
1089 struct hci_dev *hdev = data;
1092 *val = hdev->le_max_key_size;
1093 hci_dev_unlock(hdev);
1098 DEFINE_DEBUGFS_ATTRIBUTE(max_key_size_fops, max_key_size_get,
1099 max_key_size_set, "%llu\n");
1101 static int auth_payload_timeout_set(void *data, u64 val)
1103 struct hci_dev *hdev = data;
1105 if (val < 0x0001 || val > 0xffff)
1109 hdev->auth_payload_timeout = val;
1110 hci_dev_unlock(hdev);
1115 static int auth_payload_timeout_get(void *data, u64 *val)
1117 struct hci_dev *hdev = data;
1120 *val = hdev->auth_payload_timeout;
1121 hci_dev_unlock(hdev);
1126 DEFINE_DEBUGFS_ATTRIBUTE(auth_payload_timeout_fops,
1127 auth_payload_timeout_get,
1128 auth_payload_timeout_set, "%llu\n");
1130 static ssize_t force_no_mitm_read(struct file *file,
1131 char __user *user_buf,
1132 size_t count, loff_t *ppos)
1134 struct hci_dev *hdev = file->private_data;
1137 buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_NO_MITM) ? 'Y' : 'N';
1140 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1143 static ssize_t force_no_mitm_write(struct file *file,
1144 const char __user *user_buf,
1145 size_t count, loff_t *ppos)
1147 struct hci_dev *hdev = file->private_data;
1149 size_t buf_size = min(count, (sizeof(buf) - 1));
1152 if (copy_from_user(buf, user_buf, buf_size))
1155 buf[buf_size] = '\0';
1156 if (kstrtobool(buf, &enable))
1159 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_NO_MITM))
1162 hci_dev_change_flag(hdev, HCI_FORCE_NO_MITM);
1167 static const struct file_operations force_no_mitm_fops = {
1168 .open = simple_open,
1169 .read = force_no_mitm_read,
1170 .write = force_no_mitm_write,
1171 .llseek = default_llseek,
1174 DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
1175 HCI_QUIRK_STRICT_DUPLICATE_FILTER);
1176 DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
1177 HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
1179 void hci_debugfs_create_le(struct hci_dev *hdev)
1181 debugfs_create_file("identity", 0400, hdev->debugfs, hdev,
1183 debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev,
1185 debugfs_create_file("random_address", 0444, hdev->debugfs, hdev,
1186 &random_address_fops);
1187 debugfs_create_file("static_address", 0444, hdev->debugfs, hdev,
1188 &static_address_fops);
1190 /* For controllers with a public address, provide a debug
1191 * option to force the usage of the configured static
1192 * address. By default the public address is used.
1194 if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1195 debugfs_create_file("force_static_address", 0644,
1196 hdev->debugfs, hdev,
1197 &force_static_address_fops);
1199 debugfs_create_u8("white_list_size", 0444, hdev->debugfs,
1200 &hdev->le_accept_list_size);
1201 debugfs_create_file("white_list", 0444, hdev->debugfs, hdev,
1203 debugfs_create_u8("resolv_list_size", 0444, hdev->debugfs,
1204 &hdev->le_resolv_list_size);
1205 debugfs_create_file("resolv_list", 0444, hdev->debugfs, hdev,
1207 debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs,
1208 hdev, &identity_resolving_keys_fops);
1209 debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev,
1210 &long_term_keys_fops);
1211 debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev,
1212 &conn_min_interval_fops);
1213 debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev,
1214 &conn_max_interval_fops);
1215 debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev,
1216 &conn_latency_fops);
1217 debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev,
1218 &supervision_timeout_fops);
1219 debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev,
1220 &adv_channel_map_fops);
1221 debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev,
1222 &adv_min_interval_fops);
1223 debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev,
1224 &adv_max_interval_fops);
1225 debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
1226 &hdev->discov_interleaved_timeout);
1227 debugfs_create_file("min_key_size", 0644, hdev->debugfs, hdev,
1228 &min_key_size_fops);
1229 debugfs_create_file("max_key_size", 0644, hdev->debugfs, hdev,
1230 &max_key_size_fops);
1231 debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
1232 &auth_payload_timeout_fops);
1233 debugfs_create_file("force_no_mitm", 0644, hdev->debugfs, hdev,
1234 &force_no_mitm_fops);
1236 debugfs_create_file("quirk_strict_duplicate_filter", 0644,
1237 hdev->debugfs, hdev,
1238 &quirk_strict_duplicate_filter_fops);
1239 debugfs_create_file("quirk_simultaneous_discovery", 0644,
1240 hdev->debugfs, hdev,
1241 &quirk_simultaneous_discovery_fops);
1244 void hci_debugfs_create_conn(struct hci_conn *conn)
1246 struct hci_dev *hdev = conn->hdev;
1249 if (IS_ERR_OR_NULL(hdev->debugfs) || conn->debugfs)
1252 snprintf(name, sizeof(name), "%u", conn->handle);
1253 conn->debugfs = debugfs_create_dir(name, hdev->debugfs);
1256 static ssize_t dut_mode_read(struct file *file, char __user *user_buf,
1257 size_t count, loff_t *ppos)
1259 struct hci_dev *hdev = file->private_data;
1262 buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? 'Y' : 'N';
1265 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1268 static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
1269 size_t count, loff_t *ppos)
1271 struct hci_dev *hdev = file->private_data;
1272 struct sk_buff *skb;
1276 if (!test_bit(HCI_UP, &hdev->flags))
1279 err = kstrtobool_from_user(user_buf, count, &enable);
1283 if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE))
1286 hci_req_sync_lock(hdev);
1288 skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL,
1291 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
1293 hci_req_sync_unlock(hdev);
1296 return PTR_ERR(skb);
1300 hci_dev_change_flag(hdev, HCI_DUT_MODE);
1305 static const struct file_operations dut_mode_fops = {
1306 .open = simple_open,
1307 .read = dut_mode_read,
1308 .write = dut_mode_write,
1309 .llseek = default_llseek,
1312 static ssize_t vendor_diag_read(struct file *file, char __user *user_buf,
1313 size_t count, loff_t *ppos)
1315 struct hci_dev *hdev = file->private_data;
1318 buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N';
1321 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1324 static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,
1325 size_t count, loff_t *ppos)
1327 struct hci_dev *hdev = file->private_data;
1331 err = kstrtobool_from_user(user_buf, count, &enable);
1335 /* When the diagnostic flags are not persistent and the transport
1336 * is not active or in user channel operation, then there is no need
1337 * for the vendor callback. Instead just store the desired value and
1338 * the setting will be programmed when the controller gets powered on.
1340 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) &&
1341 (!test_bit(HCI_RUNNING, &hdev->flags) ||
1342 hci_dev_test_flag(hdev, HCI_USER_CHANNEL)))
1345 hci_req_sync_lock(hdev);
1346 err = hdev->set_diag(hdev, enable);
1347 hci_req_sync_unlock(hdev);
1354 hci_dev_set_flag(hdev, HCI_VENDOR_DIAG);
1356 hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG);
1361 static const struct file_operations vendor_diag_fops = {
1362 .open = simple_open,
1363 .read = vendor_diag_read,
1364 .write = vendor_diag_write,
1365 .llseek = default_llseek,
1368 void hci_debugfs_create_basic(struct hci_dev *hdev)
1370 debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev,
1374 debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev,