blob: 7618b33daca9897501a12368dba8408c2eaaa7c1 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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
31#define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk) \
32static ssize_t __name ## _read(struct file *file, \
33 char __user *user_buf, \
34 size_t count, loff_t *ppos) \
35{ \
36 struct hci_dev *hdev = file->private_data; \
37 char buf[3]; \
38 \
39 buf[0] = test_bit(__quirk, &hdev->quirks) ? 'Y' : 'N'; \
40 buf[1] = '\n'; \
41 buf[2] = '\0'; \
42 return simple_read_from_buffer(user_buf, count, ppos, buf, 2); \
43} \
44 \
45static ssize_t __name ## _write(struct file *file, \
46 const char __user *user_buf, \
47 size_t count, loff_t *ppos) \
48{ \
49 struct hci_dev *hdev = file->private_data; \
50 bool enable; \
51 int err; \
52 \
53 if (test_bit(HCI_UP, &hdev->flags)) \
54 return -EBUSY; \
55 \
56 err = kstrtobool_from_user(user_buf, count, &enable); \
57 if (err) \
58 return err; \
59 \
60 if (enable == test_bit(__quirk, &hdev->quirks)) \
61 return -EALREADY; \
62 \
63 change_bit(__quirk, &hdev->quirks); \
64 \
65 return count; \
66} \
67 \
68static const struct file_operations __name ## _fops = { \
69 .open = simple_open, \
70 .read = __name ## _read, \
71 .write = __name ## _write, \
72 .llseek = default_llseek, \
73} \
74
75#define DEFINE_INFO_ATTRIBUTE(__name, __field) \
76static int __name ## _show(struct seq_file *f, void *ptr) \
77{ \
78 struct hci_dev *hdev = f->private; \
79 \
80 hci_dev_lock(hdev); \
81 seq_printf(f, "%s\n", hdev->__field ? : ""); \
82 hci_dev_unlock(hdev); \
83 \
84 return 0; \
85} \
86 \
87DEFINE_SHOW_ATTRIBUTE(__name)
88
89static int features_show(struct seq_file *f, void *ptr)
90{
91 struct hci_dev *hdev = f->private;
92 u8 p;
93
94 hci_dev_lock(hdev);
95 for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++)
96 seq_printf(f, "%2u: %8ph\n", p, hdev->features[p]);
97 if (lmp_le_capable(hdev))
98 seq_printf(f, "LE: %8ph\n", hdev->le_features);
99 hci_dev_unlock(hdev);
100
101 return 0;
102}
103
104DEFINE_SHOW_ATTRIBUTE(features);
105
106static int device_id_show(struct seq_file *f, void *ptr)
107{
108 struct hci_dev *hdev = f->private;
109
110 hci_dev_lock(hdev);
111 seq_printf(f, "%4.4x:%4.4x:%4.4x:%4.4x\n", hdev->devid_source,
112 hdev->devid_vendor, hdev->devid_product, hdev->devid_version);
113 hci_dev_unlock(hdev);
114
115 return 0;
116}
117
118DEFINE_SHOW_ATTRIBUTE(device_id);
119
120static int device_list_show(struct seq_file *f, void *ptr)
121{
122 struct hci_dev *hdev = f->private;
123 struct hci_conn_params *p;
124 struct bdaddr_list *b;
125
126 hci_dev_lock(hdev);
127 list_for_each_entry(b, &hdev->whitelist, list)
128 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
129 list_for_each_entry(p, &hdev->le_conn_params, list) {
130 seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type,
131 p->auto_connect);
132 }
133 hci_dev_unlock(hdev);
134
135 return 0;
136}
137
138DEFINE_SHOW_ATTRIBUTE(device_list);
139
140static int blacklist_show(struct seq_file *f, void *p)
141{
142 struct hci_dev *hdev = f->private;
143 struct bdaddr_list *b;
144
145 hci_dev_lock(hdev);
146 list_for_each_entry(b, &hdev->blacklist, list)
147 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
148 hci_dev_unlock(hdev);
149
150 return 0;
151}
152
153DEFINE_SHOW_ATTRIBUTE(blacklist);
154
155static int uuids_show(struct seq_file *f, void *p)
156{
157 struct hci_dev *hdev = f->private;
158 struct bt_uuid *uuid;
159
160 hci_dev_lock(hdev);
161 list_for_each_entry(uuid, &hdev->uuids, list) {
162 u8 i, val[16];
163
164 /* The Bluetooth UUID values are stored in big endian,
165 * but with reversed byte order. So convert them into
166 * the right order for the %pUb modifier.
167 */
168 for (i = 0; i < 16; i++)
169 val[i] = uuid->uuid[15 - i];
170
171 seq_printf(f, "%pUb\n", val);
172 }
173 hci_dev_unlock(hdev);
174
175 return 0;
176}
177
178DEFINE_SHOW_ATTRIBUTE(uuids);
179
180static int remote_oob_show(struct seq_file *f, void *ptr)
181{
182 struct hci_dev *hdev = f->private;
183 struct oob_data *data;
184
185 hci_dev_lock(hdev);
186 list_for_each_entry(data, &hdev->remote_oob_data, list) {
187 seq_printf(f, "%pMR (type %u) %u %*phN %*phN %*phN %*phN\n",
188 &data->bdaddr, data->bdaddr_type, data->present,
189 16, data->hash192, 16, data->rand192,
190 16, data->hash256, 16, data->rand256);
191 }
192 hci_dev_unlock(hdev);
193
194 return 0;
195}
196
197DEFINE_SHOW_ATTRIBUTE(remote_oob);
198
199static int conn_info_min_age_set(void *data, u64 val)
200{
201 struct hci_dev *hdev = data;
202
203 hci_dev_lock(hdev);
204 if (val == 0 || val > hdev->conn_info_max_age) {
205 hci_dev_unlock(hdev);
206 return -EINVAL;
207 }
208
209 hdev->conn_info_min_age = val;
210 hci_dev_unlock(hdev);
211
212 return 0;
213}
214
215static int conn_info_min_age_get(void *data, u64 *val)
216{
217 struct hci_dev *hdev = data;
218
219 hci_dev_lock(hdev);
220 *val = hdev->conn_info_min_age;
221 hci_dev_unlock(hdev);
222
223 return 0;
224}
225
226DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
227 conn_info_min_age_set, "%llu\n");
228
229static int conn_info_max_age_set(void *data, u64 val)
230{
231 struct hci_dev *hdev = data;
232
233 hci_dev_lock(hdev);
234 if (val == 0 || val < hdev->conn_info_min_age) {
235 hci_dev_unlock(hdev);
236 return -EINVAL;
237 }
238
239 hdev->conn_info_max_age = val;
240 hci_dev_unlock(hdev);
241
242 return 0;
243}
244
245static int conn_info_max_age_get(void *data, u64 *val)
246{
247 struct hci_dev *hdev = data;
248
249 hci_dev_lock(hdev);
250 *val = hdev->conn_info_max_age;
251 hci_dev_unlock(hdev);
252
253 return 0;
254}
255
256DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
257 conn_info_max_age_set, "%llu\n");
258
259static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
260 size_t count, loff_t *ppos)
261{
262 struct hci_dev *hdev = file->private_data;
263 char buf[3];
264
265 buf[0] = hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS) ? 'Y': 'N';
266 buf[1] = '\n';
267 buf[2] = '\0';
268 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
269}
270
271static const struct file_operations use_debug_keys_fops = {
272 .open = simple_open,
273 .read = use_debug_keys_read,
274 .llseek = default_llseek,
275};
276
277static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
278 size_t count, loff_t *ppos)
279{
280 struct hci_dev *hdev = file->private_data;
281 char buf[3];
282
283 buf[0] = hci_dev_test_flag(hdev, HCI_SC_ONLY) ? 'Y': 'N';
284 buf[1] = '\n';
285 buf[2] = '\0';
286 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
287}
288
289static const struct file_operations sc_only_mode_fops = {
290 .open = simple_open,
291 .read = sc_only_mode_read,
292 .llseek = default_llseek,
293};
294
295DEFINE_INFO_ATTRIBUTE(hardware_info, hw_info);
296DEFINE_INFO_ATTRIBUTE(firmware_info, fw_info);
297
298void hci_debugfs_create_common(struct hci_dev *hdev)
299{
300 debugfs_create_file("features", 0444, hdev->debugfs, hdev,
301 &features_fops);
302 debugfs_create_u16("manufacturer", 0444, hdev->debugfs,
303 &hdev->manufacturer);
304 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
305 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
306 debugfs_create_u8("hardware_error", 0444, hdev->debugfs,
307 &hdev->hw_error_code);
308 debugfs_create_file("device_id", 0444, hdev->debugfs, hdev,
309 &device_id_fops);
310
311 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
312 &device_list_fops);
313 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
314 &blacklist_fops);
315 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
316 debugfs_create_file("remote_oob", 0400, hdev->debugfs, hdev,
317 &remote_oob_fops);
318
319 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
320 &conn_info_min_age_fops);
321 debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
322 &conn_info_max_age_fops);
323
324 if (lmp_ssp_capable(hdev) || lmp_le_capable(hdev))
325 debugfs_create_file("use_debug_keys", 0444, hdev->debugfs,
326 hdev, &use_debug_keys_fops);
327
328 if (lmp_sc_capable(hdev) || lmp_le_capable(hdev))
329 debugfs_create_file("sc_only_mode", 0444, hdev->debugfs,
330 hdev, &sc_only_mode_fops);
331
332 if (hdev->hw_info)
333 debugfs_create_file("hardware_info", 0444, hdev->debugfs,
334 hdev, &hardware_info_fops);
335
336 if (hdev->fw_info)
337 debugfs_create_file("firmware_info", 0444, hdev->debugfs,
338 hdev, &firmware_info_fops);
339}
340
341static int inquiry_cache_show(struct seq_file *f, void *p)
342{
343 struct hci_dev *hdev = f->private;
344 struct discovery_state *cache = &hdev->discovery;
345 struct inquiry_entry *e;
346
347 hci_dev_lock(hdev);
348
349 list_for_each_entry(e, &cache->all, all) {
350 struct inquiry_data *data = &e->data;
351 seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
352 &data->bdaddr,
353 data->pscan_rep_mode, data->pscan_period_mode,
354 data->pscan_mode, data->dev_class[2],
355 data->dev_class[1], data->dev_class[0],
356 __le16_to_cpu(data->clock_offset),
357 data->rssi, data->ssp_mode, e->timestamp);
358 }
359
360 hci_dev_unlock(hdev);
361
362 return 0;
363}
364
365DEFINE_SHOW_ATTRIBUTE(inquiry_cache);
366
367static int link_keys_show(struct seq_file *f, void *ptr)
368{
369 struct hci_dev *hdev = f->private;
370 struct link_key *key;
371
372 rcu_read_lock();
373 list_for_each_entry_rcu(key, &hdev->link_keys, list)
374 seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
375 HCI_LINK_KEY_SIZE, key->val, key->pin_len);
376 rcu_read_unlock();
377
378 return 0;
379}
380
381DEFINE_SHOW_ATTRIBUTE(link_keys);
382
383static int dev_class_show(struct seq_file *f, void *ptr)
384{
385 struct hci_dev *hdev = f->private;
386
387 hci_dev_lock(hdev);
388 seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
389 hdev->dev_class[1], hdev->dev_class[0]);
390 hci_dev_unlock(hdev);
391
392 return 0;
393}
394
395DEFINE_SHOW_ATTRIBUTE(dev_class);
396
397static int voice_setting_get(void *data, u64 *val)
398{
399 struct hci_dev *hdev = data;
400
401 hci_dev_lock(hdev);
402 *val = hdev->voice_setting;
403 hci_dev_unlock(hdev);
404
405 return 0;
406}
407
408DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get,
409 NULL, "0x%4.4llx\n");
410
411static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf,
412 size_t count, loff_t *ppos)
413{
414 struct hci_dev *hdev = file->private_data;
415 char buf[3];
416
417 buf[0] = hdev->ssp_debug_mode ? 'Y': 'N';
418 buf[1] = '\n';
419 buf[2] = '\0';
420 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
421}
422
423static const struct file_operations ssp_debug_mode_fops = {
424 .open = simple_open,
425 .read = ssp_debug_mode_read,
426 .llseek = default_llseek,
427};
428
429static int auto_accept_delay_set(void *data, u64 val)
430{
431 struct hci_dev *hdev = data;
432
433 hci_dev_lock(hdev);
434 hdev->auto_accept_delay = val;
435 hci_dev_unlock(hdev);
436
437 return 0;
438}
439
440static int min_encrypt_key_size_set(void *data, u64 val)
441{
442 struct hci_dev *hdev = data;
443
444 if (val < 1 || val > 16)
445 return -EINVAL;
446
447 hci_dev_lock(hdev);
448 hdev->min_enc_key_size = val;
449 hci_dev_unlock(hdev);
450
451 return 0;
452}
453
454static int min_encrypt_key_size_get(void *data, u64 *val)
455{
456 struct hci_dev *hdev = data;
457
458 hci_dev_lock(hdev);
459 *val = hdev->min_enc_key_size;
460 hci_dev_unlock(hdev);
461
462 return 0;
463}
464
465DEFINE_SIMPLE_ATTRIBUTE(min_encrypt_key_size_fops,
466 min_encrypt_key_size_get,
467 min_encrypt_key_size_set, "%llu\n");
468
469static int auto_accept_delay_get(void *data, u64 *val)
470{
471 struct hci_dev *hdev = data;
472
473 hci_dev_lock(hdev);
474 *val = hdev->auto_accept_delay;
475 hci_dev_unlock(hdev);
476
477 return 0;
478}
479
480DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
481 auto_accept_delay_set, "%llu\n");
482
483static int idle_timeout_set(void *data, u64 val)
484{
485 struct hci_dev *hdev = data;
486
487 if (val != 0 && (val < 500 || val > 3600000))
488 return -EINVAL;
489
490 hci_dev_lock(hdev);
491 hdev->idle_timeout = val;
492 hci_dev_unlock(hdev);
493
494 return 0;
495}
496
497static int idle_timeout_get(void *data, u64 *val)
498{
499 struct hci_dev *hdev = data;
500
501 hci_dev_lock(hdev);
502 *val = hdev->idle_timeout;
503 hci_dev_unlock(hdev);
504
505 return 0;
506}
507
508DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
509 idle_timeout_set, "%llu\n");
510
511static int sniff_min_interval_set(void *data, u64 val)
512{
513 struct hci_dev *hdev = data;
514
515 hci_dev_lock(hdev);
516 if (val == 0 || val % 2 || val > hdev->sniff_max_interval) {
517 hci_dev_unlock(hdev);
518 return -EINVAL;
519 }
520
521 hdev->sniff_min_interval = val;
522 hci_dev_unlock(hdev);
523
524 return 0;
525}
526
527static int sniff_min_interval_get(void *data, u64 *val)
528{
529 struct hci_dev *hdev = data;
530
531 hci_dev_lock(hdev);
532 *val = hdev->sniff_min_interval;
533 hci_dev_unlock(hdev);
534
535 return 0;
536}
537
538DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
539 sniff_min_interval_set, "%llu\n");
540
541static int sniff_max_interval_set(void *data, u64 val)
542{
543 struct hci_dev *hdev = data;
544
545 hci_dev_lock(hdev);
546 if (val == 0 || val % 2 || val < hdev->sniff_min_interval) {
547 hci_dev_unlock(hdev);
548 return -EINVAL;
549 }
550
551 hdev->sniff_max_interval = val;
552 hci_dev_unlock(hdev);
553
554 return 0;
555}
556
557static int sniff_max_interval_get(void *data, u64 *val)
558{
559 struct hci_dev *hdev = data;
560
561 hci_dev_lock(hdev);
562 *val = hdev->sniff_max_interval;
563 hci_dev_unlock(hdev);
564
565 return 0;
566}
567
568DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
569 sniff_max_interval_set, "%llu\n");
570
571void hci_debugfs_create_bredr(struct hci_dev *hdev)
572{
573 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev,
574 &inquiry_cache_fops);
575 debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev,
576 &link_keys_fops);
577 debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev,
578 &dev_class_fops);
579 debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
580 &voice_setting_fops);
581
582 if (lmp_ssp_capable(hdev)) {
583 debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
584 hdev, &ssp_debug_mode_fops);
585 debugfs_create_file("min_encrypt_key_size", 0644, hdev->debugfs,
586 hdev, &min_encrypt_key_size_fops);
587 debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
588 hdev, &auto_accept_delay_fops);
589 }
590
591 if (lmp_sniff_capable(hdev)) {
592 debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
593 hdev, &idle_timeout_fops);
594 debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs,
595 hdev, &sniff_min_interval_fops);
596 debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs,
597 hdev, &sniff_max_interval_fops);
598 }
599}
600
601static int identity_show(struct seq_file *f, void *p)
602{
603 struct hci_dev *hdev = f->private;
604 bdaddr_t addr;
605 u8 addr_type;
606
607 hci_dev_lock(hdev);
608
609 hci_copy_identity_address(hdev, &addr, &addr_type);
610
611 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
612 16, hdev->irk, &hdev->rpa);
613
614 hci_dev_unlock(hdev);
615
616 return 0;
617}
618
619DEFINE_SHOW_ATTRIBUTE(identity);
620
621static int rpa_timeout_set(void *data, u64 val)
622{
623 struct hci_dev *hdev = data;
624
625 /* Require the RPA timeout to be at least 30 seconds and at most
626 * 24 hours.
627 */
628 if (val < 30 || val > (60 * 60 * 24))
629 return -EINVAL;
630
631 hci_dev_lock(hdev);
632 hdev->rpa_timeout = val;
633 hci_dev_unlock(hdev);
634
635 return 0;
636}
637
638static int rpa_timeout_get(void *data, u64 *val)
639{
640 struct hci_dev *hdev = data;
641
642 hci_dev_lock(hdev);
643 *val = hdev->rpa_timeout;
644 hci_dev_unlock(hdev);
645
646 return 0;
647}
648
649DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
650 rpa_timeout_set, "%llu\n");
651
652static int random_address_show(struct seq_file *f, void *p)
653{
654 struct hci_dev *hdev = f->private;
655
656 hci_dev_lock(hdev);
657 seq_printf(f, "%pMR\n", &hdev->random_addr);
658 hci_dev_unlock(hdev);
659
660 return 0;
661}
662
663DEFINE_SHOW_ATTRIBUTE(random_address);
664
665static int static_address_show(struct seq_file *f, void *p)
666{
667 struct hci_dev *hdev = f->private;
668
669 hci_dev_lock(hdev);
670 seq_printf(f, "%pMR\n", &hdev->static_addr);
671 hci_dev_unlock(hdev);
672
673 return 0;
674}
675
676DEFINE_SHOW_ATTRIBUTE(static_address);
677
678static ssize_t force_static_address_read(struct file *file,
679 char __user *user_buf,
680 size_t count, loff_t *ppos)
681{
682 struct hci_dev *hdev = file->private_data;
683 char buf[3];
684
685 buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ? 'Y': 'N';
686 buf[1] = '\n';
687 buf[2] = '\0';
688 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
689}
690
691static ssize_t force_static_address_write(struct file *file,
692 const char __user *user_buf,
693 size_t count, loff_t *ppos)
694{
695 struct hci_dev *hdev = file->private_data;
696 bool enable;
697 int err;
698
699 if (test_bit(HCI_UP, &hdev->flags))
700 return -EBUSY;
701
702 err = kstrtobool_from_user(user_buf, count, &enable);
703 if (err)
704 return err;
705
706 if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR))
707 return -EALREADY;
708
709 hci_dev_change_flag(hdev, HCI_FORCE_STATIC_ADDR);
710
711 return count;
712}
713
714static const struct file_operations force_static_address_fops = {
715 .open = simple_open,
716 .read = force_static_address_read,
717 .write = force_static_address_write,
718 .llseek = default_llseek,
719};
720
721static int white_list_show(struct seq_file *f, void *ptr)
722{
723 struct hci_dev *hdev = f->private;
724 struct bdaddr_list *b;
725
726 hci_dev_lock(hdev);
727 list_for_each_entry(b, &hdev->le_white_list, list)
728 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
729 hci_dev_unlock(hdev);
730
731 return 0;
732}
733
734DEFINE_SHOW_ATTRIBUTE(white_list);
735
736static int resolv_list_show(struct seq_file *f, void *ptr)
737{
738 struct hci_dev *hdev = f->private;
739 struct bdaddr_list *b;
740
741 hci_dev_lock(hdev);
742 list_for_each_entry(b, &hdev->le_resolv_list, list)
743 seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
744 hci_dev_unlock(hdev);
745
746 return 0;
747}
748
749DEFINE_SHOW_ATTRIBUTE(resolv_list);
750
751static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
752{
753 struct hci_dev *hdev = f->private;
754 struct smp_irk *irk;
755
756 rcu_read_lock();
757 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
758 seq_printf(f, "%pMR (type %u) %*phN %pMR\n",
759 &irk->bdaddr, irk->addr_type,
760 16, irk->val, &irk->rpa);
761 }
762 rcu_read_unlock();
763
764 return 0;
765}
766
767DEFINE_SHOW_ATTRIBUTE(identity_resolving_keys);
768
769static int long_term_keys_show(struct seq_file *f, void *ptr)
770{
771 struct hci_dev *hdev = f->private;
772 struct smp_ltk *ltk;
773
774 rcu_read_lock();
775 list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list)
776 seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n",
777 &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated,
778 ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
779 __le64_to_cpu(ltk->rand), 16, ltk->val);
780 rcu_read_unlock();
781
782 return 0;
783}
784
785DEFINE_SHOW_ATTRIBUTE(long_term_keys);
786
787static int conn_min_interval_set(void *data, u64 val)
788{
789 struct hci_dev *hdev = data;
790
791 hci_dev_lock(hdev);
792 if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval) {
793 hci_dev_unlock(hdev);
794 return -EINVAL;
795 }
796
797 hdev->le_conn_min_interval = val;
798 hci_dev_unlock(hdev);
799
800 return 0;
801}
802
803static int conn_min_interval_get(void *data, u64 *val)
804{
805 struct hci_dev *hdev = data;
806
807 hci_dev_lock(hdev);
808 *val = hdev->le_conn_min_interval;
809 hci_dev_unlock(hdev);
810
811 return 0;
812}
813
814DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
815 conn_min_interval_set, "%llu\n");
816
817static int conn_max_interval_set(void *data, u64 val)
818{
819 struct hci_dev *hdev = data;
820
821 hci_dev_lock(hdev);
822 if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval) {
823 hci_dev_unlock(hdev);
824 return -EINVAL;
825 }
826
827 hdev->le_conn_max_interval = val;
828 hci_dev_unlock(hdev);
829
830 return 0;
831}
832
833static int conn_max_interval_get(void *data, u64 *val)
834{
835 struct hci_dev *hdev = data;
836
837 hci_dev_lock(hdev);
838 *val = hdev->le_conn_max_interval;
839 hci_dev_unlock(hdev);
840
841 return 0;
842}
843
844DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
845 conn_max_interval_set, "%llu\n");
846
847static int conn_latency_set(void *data, u64 val)
848{
849 struct hci_dev *hdev = data;
850
851 if (val > 0x01f3)
852 return -EINVAL;
853
854 hci_dev_lock(hdev);
855 hdev->le_conn_latency = val;
856 hci_dev_unlock(hdev);
857
858 return 0;
859}
860
861static int conn_latency_get(void *data, u64 *val)
862{
863 struct hci_dev *hdev = data;
864
865 hci_dev_lock(hdev);
866 *val = hdev->le_conn_latency;
867 hci_dev_unlock(hdev);
868
869 return 0;
870}
871
872DEFINE_SIMPLE_ATTRIBUTE(conn_latency_fops, conn_latency_get,
873 conn_latency_set, "%llu\n");
874
875static int supervision_timeout_set(void *data, u64 val)
876{
877 struct hci_dev *hdev = data;
878
879 if (val < 0x000a || val > 0x0c80)
880 return -EINVAL;
881
882 hci_dev_lock(hdev);
883 hdev->le_supv_timeout = val;
884 hci_dev_unlock(hdev);
885
886 return 0;
887}
888
889static int supervision_timeout_get(void *data, u64 *val)
890{
891 struct hci_dev *hdev = data;
892
893 hci_dev_lock(hdev);
894 *val = hdev->le_supv_timeout;
895 hci_dev_unlock(hdev);
896
897 return 0;
898}
899
900DEFINE_SIMPLE_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get,
901 supervision_timeout_set, "%llu\n");
902
903static int adv_channel_map_set(void *data, u64 val)
904{
905 struct hci_dev *hdev = data;
906
907 if (val < 0x01 || val > 0x07)
908 return -EINVAL;
909
910 hci_dev_lock(hdev);
911 hdev->le_adv_channel_map = val;
912 hci_dev_unlock(hdev);
913
914 return 0;
915}
916
917static int adv_channel_map_get(void *data, u64 *val)
918{
919 struct hci_dev *hdev = data;
920
921 hci_dev_lock(hdev);
922 *val = hdev->le_adv_channel_map;
923 hci_dev_unlock(hdev);
924
925 return 0;
926}
927
928DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
929 adv_channel_map_set, "%llu\n");
930
931static int adv_min_interval_set(void *data, u64 val)
932{
933 struct hci_dev *hdev = data;
934
935 hci_dev_lock(hdev);
936 if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) {
937 hci_dev_unlock(hdev);
938 return -EINVAL;
939 }
940
941 hdev->le_adv_min_interval = val;
942 hci_dev_unlock(hdev);
943
944 return 0;
945}
946
947static int adv_min_interval_get(void *data, u64 *val)
948{
949 struct hci_dev *hdev = data;
950
951 hci_dev_lock(hdev);
952 *val = hdev->le_adv_min_interval;
953 hci_dev_unlock(hdev);
954
955 return 0;
956}
957
958DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,
959 adv_min_interval_set, "%llu\n");
960
961static int adv_max_interval_set(void *data, u64 val)
962{
963 struct hci_dev *hdev = data;
964
965 hci_dev_lock(hdev);
966 if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) {
967 hci_dev_unlock(hdev);
968 return -EINVAL;
969 }
970
971 hdev->le_adv_max_interval = val;
972 hci_dev_unlock(hdev);
973
974 return 0;
975}
976
977static int adv_max_interval_get(void *data, u64 *val)
978{
979 struct hci_dev *hdev = data;
980
981 hci_dev_lock(hdev);
982 *val = hdev->le_adv_max_interval;
983 hci_dev_unlock(hdev);
984
985 return 0;
986}
987
988DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
989 adv_max_interval_set, "%llu\n");
990
991static int auth_payload_timeout_set(void *data, u64 val)
992{
993 struct hci_dev *hdev = data;
994
995 if (val < 0x0001 || val > 0xffff)
996 return -EINVAL;
997
998 hci_dev_lock(hdev);
999 hdev->auth_payload_timeout = val;
1000 hci_dev_unlock(hdev);
1001
1002 return 0;
1003}
1004
1005static int auth_payload_timeout_get(void *data, u64 *val)
1006{
1007 struct hci_dev *hdev = data;
1008
1009 hci_dev_lock(hdev);
1010 *val = hdev->auth_payload_timeout;
1011 hci_dev_unlock(hdev);
1012
1013 return 0;
1014}
1015
1016DEFINE_SIMPLE_ATTRIBUTE(auth_payload_timeout_fops,
1017 auth_payload_timeout_get,
1018 auth_payload_timeout_set, "%llu\n");
1019
1020DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
1021 HCI_QUIRK_STRICT_DUPLICATE_FILTER);
1022DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
1023 HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
1024
1025void hci_debugfs_create_le(struct hci_dev *hdev)
1026{
1027 debugfs_create_file("identity", 0400, hdev->debugfs, hdev,
1028 &identity_fops);
1029 debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev,
1030 &rpa_timeout_fops);
1031 debugfs_create_file("random_address", 0444, hdev->debugfs, hdev,
1032 &random_address_fops);
1033 debugfs_create_file("static_address", 0444, hdev->debugfs, hdev,
1034 &static_address_fops);
1035
1036 /* For controllers with a public address, provide a debug
1037 * option to force the usage of the configured static
1038 * address. By default the public address is used.
1039 */
1040 if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1041 debugfs_create_file("force_static_address", 0644,
1042 hdev->debugfs, hdev,
1043 &force_static_address_fops);
1044
1045 debugfs_create_u8("white_list_size", 0444, hdev->debugfs,
1046 &hdev->le_white_list_size);
1047 debugfs_create_file("white_list", 0444, hdev->debugfs, hdev,
1048 &white_list_fops);
1049 debugfs_create_u8("resolv_list_size", 0444, hdev->debugfs,
1050 &hdev->le_resolv_list_size);
1051 debugfs_create_file("resolv_list", 0444, hdev->debugfs, hdev,
1052 &resolv_list_fops);
1053 debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs,
1054 hdev, &identity_resolving_keys_fops);
1055 debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev,
1056 &long_term_keys_fops);
1057 debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev,
1058 &conn_min_interval_fops);
1059 debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev,
1060 &conn_max_interval_fops);
1061 debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev,
1062 &conn_latency_fops);
1063 debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev,
1064 &supervision_timeout_fops);
1065 debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev,
1066 &adv_channel_map_fops);
1067 debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev,
1068 &adv_min_interval_fops);
1069 debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev,
1070 &adv_max_interval_fops);
1071 debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
1072 &hdev->discov_interleaved_timeout);
1073 debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
1074 &auth_payload_timeout_fops);
1075
1076 debugfs_create_file("quirk_strict_duplicate_filter", 0644,
1077 hdev->debugfs, hdev,
1078 &quirk_strict_duplicate_filter_fops);
1079 debugfs_create_file("quirk_simultaneous_discovery", 0644,
1080 hdev->debugfs, hdev,
1081 &quirk_simultaneous_discovery_fops);
1082}
1083
1084void hci_debugfs_create_conn(struct hci_conn *conn)
1085{
1086 struct hci_dev *hdev = conn->hdev;
1087 char name[6];
1088
1089 if (IS_ERR_OR_NULL(hdev->debugfs))
1090 return;
1091
1092 snprintf(name, sizeof(name), "%u", conn->handle);
1093 conn->debugfs = debugfs_create_dir(name, hdev->debugfs);
1094}