1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
31static 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
57static int features_open(struct inode *inode, struct file *file)
58{
59 return single_open(file, features_show, inode->i_private);
60}
61
62static const struct file_operations features_fops = {
63 .open = features_open,
64 .read = seq_read,
65 .llseek = seq_lseek,
66 .release = single_release,
67};
68
69static 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
87static int device_list_open(struct inode *inode, struct file *file)
88{
89 return single_open(file, device_list_show, inode->i_private);
90}
91
92static 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
99static 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
112static int blacklist_open(struct inode *inode, struct file *file)
113{
114 return single_open(file, blacklist_show, inode->i_private);
115}
116
117static const struct file_operations blacklist_fops = {
118 .open = blacklist_open,
119 .read = seq_read,
120 .llseek = seq_lseek,
121 .release = single_release,
122};
123
124static 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
134
135
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
147static int uuids_open(struct inode *inode, struct file *file)
148{
149 return single_open(file, uuids_show, inode->i_private);
150}
151
152static const struct file_operations uuids_fops = {
153 .open = uuids_open,
154 .read = seq_read,
155 .llseek = seq_lseek,
156 .release = single_release,
157};
158
159static int remote_oob_show(struct seq_file *f, void *ptr)
160{
161 struct hci_dev *hdev = f->private;
162 struct oob_data *data;
163
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);
170 }
171 hci_dev_unlock(hdev);
172
173 return 0;
174}
175
176static int remote_oob_open(struct inode *inode, struct file *file)
177{
178 return single_open(file, remote_oob_show, inode->i_private);
179}
180
181static const struct file_operations remote_oob_fops = {
182 .open = remote_oob_open,
183 .read = seq_read,
184 .llseek = seq_lseek,
185 .release = single_release,
186};
187
188static int conn_info_min_age_set(void *data, u64 val)
189{
190 struct hci_dev *hdev = data;
191
192 if (val == 0 || val > hdev->conn_info_max_age)
193 return -EINVAL;
194
195 hci_dev_lock(hdev);
196 hdev->conn_info_min_age = val;
197 hci_dev_unlock(hdev);
198
199 return 0;
200}
201
202static int conn_info_min_age_get(void *data, u64 *val)
203{
204 struct hci_dev *hdev = data;
205
206 hci_dev_lock(hdev);
207 *val = hdev->conn_info_min_age;
208 hci_dev_unlock(hdev);
209
210 return 0;
211}
212
213DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
214 conn_info_min_age_set, "%llu\n");
215
216static int conn_info_max_age_set(void *data, u64 val)
217{
218 struct hci_dev *hdev = data;
219
220 if (val == 0 || val < hdev->conn_info_min_age)
221 return -EINVAL;
222
223 hci_dev_lock(hdev);
224 hdev->conn_info_max_age = val;
225 hci_dev_unlock(hdev);
226
227 return 0;
228}
229
230static int conn_info_max_age_get(void *data, u64 *val)
231{
232 struct hci_dev *hdev = data;
233
234 hci_dev_lock(hdev);
235 *val = hdev->conn_info_max_age;
236 hci_dev_unlock(hdev);
237
238 return 0;
239}
240
241DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
242 conn_info_max_age_set, "%llu\n");
243
244static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
245 size_t count, loff_t *ppos)
246{
247 struct hci_dev *hdev = file->private_data;
248 char buf[3];
249
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);
254}
255
256static const struct file_operations use_debug_keys_fops = {
257 .open = simple_open,
258 .read = use_debug_keys_read,
259 .llseek = default_llseek,
260};
261
262static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
263 size_t count, loff_t *ppos)
264{
265 struct hci_dev *hdev = file->private_data;
266 char buf[3];
267
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);
272}
273
274static const struct file_operations sc_only_mode_fops = {
275 .open = simple_open,
276 .read = sc_only_mode_read,
277 .llseek = default_llseek,
278};
279
280void hci_debugfs_create_common(struct hci_dev *hdev)
281{
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);
290
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);
298
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);
303
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);
307
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);
311}
312
313static int inquiry_cache_show(struct seq_file *f, void *p)
314{
315 struct hci_dev *hdev = f->private;
316 struct discovery_state *cache = &hdev->discovery;
317 struct inquiry_entry *e;
318
319 hci_dev_lock(hdev);
320
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);
330 }
331
332 hci_dev_unlock(hdev);
333
334 return 0;
335}
336
337static int inquiry_cache_open(struct inode *inode, struct file *file)
338{
339 return single_open(file, inquiry_cache_show, inode->i_private);
340}
341
342static const struct file_operations inquiry_cache_fops = {
343 .open = inquiry_cache_open,
344 .read = seq_read,
345 .llseek = seq_lseek,
346 .release = single_release,
347};
348
349static int link_keys_show(struct seq_file *f, void *ptr)
350{
351 struct hci_dev *hdev = f->private;
352 struct link_key *key;
353
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();
359
360 return 0;
361}
362
363static int link_keys_open(struct inode *inode, struct file *file)
364{
365 return single_open(file, link_keys_show, inode->i_private);
366}
367
368static const struct file_operations link_keys_fops = {
369 .open = link_keys_open,
370 .read = seq_read,
371 .llseek = seq_lseek,
372 .release = single_release,
373};
374
375static int dev_class_show(struct seq_file *f, void *ptr)
376{
377 struct hci_dev *hdev = f->private;
378
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);
383
384 return 0;
385}
386
387static int dev_class_open(struct inode *inode, struct file *file)
388{
389 return single_open(file, dev_class_show, inode->i_private);
390}
391
392static const struct file_operations dev_class_fops = {
393 .open = dev_class_open,
394 .read = seq_read,
395 .llseek = seq_lseek,
396 .release = single_release,
397};
398
399static int voice_setting_get(void *data, u64 *val)
400{
401 struct hci_dev *hdev = data;
402
403 hci_dev_lock(hdev);
404 *val = hdev->voice_setting;
405 hci_dev_unlock(hdev);
406
407 return 0;
408}
409
410DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get,
411 NULL, "0x%4.4llx\n");
412
413static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf,
414 size_t count, loff_t *ppos)
415{
416 struct hci_dev *hdev = file->private_data;
417 char buf[3];
418
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);
423}
424
425static const struct file_operations ssp_debug_mode_fops = {
426 .open = simple_open,
427 .read = ssp_debug_mode_read,
428 .llseek = default_llseek,
429};
430
431static int auto_accept_delay_set(void *data, u64 val)
432{
433 struct hci_dev *hdev = data;
434
435 hci_dev_lock(hdev);
436 hdev->auto_accept_delay = val;
437 hci_dev_unlock(hdev);
438
439 return 0;
440}
441
442static int auto_accept_delay_get(void *data, u64 *val)
443{
444 struct hci_dev *hdev = data;
445
446 hci_dev_lock(hdev);
447 *val = hdev->auto_accept_delay;
448 hci_dev_unlock(hdev);
449
450 return 0;
451}
452
453DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
454 auto_accept_delay_set, "%llu\n");
455
456static int idle_timeout_set(void *data, u64 val)
457{
458 struct hci_dev *hdev = data;
459
460 if (val != 0 && (val < 500 || val > 3600000))
461 return -EINVAL;
462
463 hci_dev_lock(hdev);
464 hdev->idle_timeout = val;
465 hci_dev_unlock(hdev);
466
467 return 0;
468}
469
470static int idle_timeout_get(void *data, u64 *val)
471{
472 struct hci_dev *hdev = data;
473
474 hci_dev_lock(hdev);
475 *val = hdev->idle_timeout;
476 hci_dev_unlock(hdev);
477
478 return 0;
479}
480
481DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
482 idle_timeout_set, "%llu\n");
483
484static int sniff_min_interval_set(void *data, u64 val)
485{
486 struct hci_dev *hdev = data;
487
488 if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
489 return -EINVAL;
490
491 hci_dev_lock(hdev);
492 hdev->sniff_min_interval = val;
493 hci_dev_unlock(hdev);
494
495 return 0;
496}
497
498static int sniff_min_interval_get(void *data, u64 *val)
499{
500 struct hci_dev *hdev = data;
501
502 hci_dev_lock(hdev);
503 *val = hdev->sniff_min_interval;
504 hci_dev_unlock(hdev);
505
506 return 0;
507}
508
509DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
510 sniff_min_interval_set, "%llu\n");
511
512static int sniff_max_interval_set(void *data, u64 val)
513{
514 struct hci_dev *hdev = data;
515
516 if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
517 return -EINVAL;
518
519 hci_dev_lock(hdev);
520 hdev->sniff_max_interval = val;
521 hci_dev_unlock(hdev);
522
523 return 0;
524}
525
526static int sniff_max_interval_get(void *data, u64 *val)
527{
528 struct hci_dev *hdev = data;
529
530 hci_dev_lock(hdev);
531 *val = hdev->sniff_max_interval;
532 hci_dev_unlock(hdev);
533
534 return 0;
535}
536
537DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
538 sniff_max_interval_set, "%llu\n");
539
540void hci_debugfs_create_bredr(struct hci_dev *hdev)
541{
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);
550
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);
556 }
557
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);
565 }
566}
567
568static int identity_show(struct seq_file *f, void *p)
569{
570 struct hci_dev *hdev = f->private;
571 bdaddr_t addr;
572 u8 addr_type;
573
574 hci_dev_lock(hdev);
575
576 hci_copy_identity_address(hdev, &addr, &addr_type);
577
578 seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
579 16, hdev->irk, &hdev->rpa);
580
581 hci_dev_unlock(hdev);
582
583 return 0;
584}
585
586static int identity_open(struct inode *inode, struct file *file)
587{
588 return single_open(file, identity_show, inode->i_private);
589}
590
591static const struct file_operations identity_fops = {
592 .open = identity_open,
593 .read = seq_read,
594 .llseek = seq_lseek,
595 .release = single_release,
596};
597
598static int rpa_timeout_set(void *data, u64 val)
599{
600 struct hci_dev *hdev = data;
601
602
603
604
605 if (val < 30 || val > (60 * 60 * 24))
606 return -EINVAL;
607
608 hci_dev_lock(hdev);
609 hdev->rpa_timeout = val;
610 hci_dev_unlock(hdev);
611
612 return 0;
613}
614
615static int rpa_timeout_get(void *data, u64 *val)
616{
617 struct hci_dev *hdev = data;
618
619 hci_dev_lock(hdev);
620 *val = hdev->rpa_timeout;
621 hci_dev_unlock(hdev);
622
623 return 0;
624}
625
626DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
627 rpa_timeout_set, "%llu\n");
628
629static int random_address_show(struct seq_file *f, void *p)
630{
631 struct hci_dev *hdev = f->private;
632
633 hci_dev_lock(hdev);
634 seq_printf(f, "%pMR\n", &hdev->random_addr);
635 hci_dev_unlock(hdev);
636
637 return 0;
638}
639
640static int random_address_open(struct inode *inode, struct file *file)
641{
642 return single_open(file, random_address_show, inode->i_private);
643}
644
645static const struct file_operations random_address_fops = {
646 .open = random_address_open,
647 .read = seq_read,
648 .llseek = seq_lseek,
649 .release = single_release,
650};
651
652static int static_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->static_addr);
658 hci_dev_unlock(hdev);
659
660 return 0;
661}
662
663static int static_address_open(struct inode *inode, struct file *file)
664{
665 return single_open(file, static_address_show, inode->i_private);
666}
667
668static const struct file_operations static_address_fops = {
669 .open = static_address_open,
670 .read = seq_read,
671 .llseek = seq_lseek,
672 .release = single_release,
673};
674
675static ssize_t force_static_address_read(struct file *file,
676 char __user *user_buf,
677 size_t count, loff_t *ppos)
678{
679 struct hci_dev *hdev = file->private_data;
680 char buf[3];
681
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);
686}
687
688static ssize_t force_static_address_write(struct file *file,
689 const char __user *user_buf,
690 size_t count, loff_t *ppos)
691{
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;
696
697 if (test_bit(HCI_UP, &hdev->flags))
698 return -EBUSY;
699
700 if (copy_from_user(buf, user_buf, buf_size))
701 return -EFAULT;
702
703 buf[buf_size] = '\0';
704 if (strtobool(buf, &enable))
705 return -EINVAL;
706
707 if (enable == test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags))
708 return -EALREADY;
709
710 change_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags);
711
712 return count;
713}
714
715static 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,
720};
721
722static int white_list_show(struct seq_file *f, void *ptr)
723{
724 struct hci_dev *hdev = f->private;
725 struct bdaddr_list *b;
726
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);
731
732 return 0;
733}
734
735static int white_list_open(struct inode *inode, struct file *file)
736{
737 return single_open(file, white_list_show, inode->i_private);
738}
739
740static const struct file_operations white_list_fops = {
741 .open = white_list_open,
742 .read = seq_read,
743 .llseek = seq_lseek,
744 .release = single_release,
745};
746
747static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
748{
749 struct hci_dev *hdev = f->private;
750 struct smp_irk *irk;
751
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);
757 }
758 rcu_read_unlock();
759
760 return 0;
761}
762
763static int identity_resolving_keys_open(struct inode *inode, struct file *file)
764{
765 return single_open(file, identity_resolving_keys_show,
766 inode->i_private);
767}
768
769static 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,
774};
775
776static int long_term_keys_show(struct seq_file *f, void *ptr)
777{
778 struct hci_dev *hdev = f->private;
779 struct smp_ltk *ltk;
780
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 <k->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();
788
789 return 0;
790}
791
792static int long_term_keys_open(struct inode *inode, struct file *file)
793{
794 return single_open(file, long_term_keys_show, inode->i_private);
795}
796
797static 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,
802};
803
804static int conn_min_interval_set(void *data, u64 val)
805{
806 struct hci_dev *hdev = data;
807
808 if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
809 return -EINVAL;
810
811 hci_dev_lock(hdev);
812 hdev->le_conn_min_interval = val;
813 hci_dev_unlock(hdev);
814
815 return 0;
816}
817
818static int conn_min_interval_get(void *data, u64 *val)
819{
820 struct hci_dev *hdev = data;
821
822 hci_dev_lock(hdev);
823 *val = hdev->le_conn_min_interval;
824 hci_dev_unlock(hdev);
825
826 return 0;
827}
828
829DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
830 conn_min_interval_set, "%llu\n");
831
832static int conn_max_interval_set(void *data, u64 val)
833{
834 struct hci_dev *hdev = data;
835
836 if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
837 return -EINVAL;
838
839 hci_dev_lock(hdev);
840 hdev->le_conn_max_interval = val;
841 hci_dev_unlock(hdev);
842
843 return 0;
844}
845
846static int conn_max_interval_get(void *data, u64 *val)
847{
848 struct hci_dev *hdev = data;
849
850 hci_dev_lock(hdev);
851 *val = hdev->le_conn_max_interval;
852 hci_dev_unlock(hdev);
853
854 return 0;
855}
856
857DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
858 conn_max_interval_set, "%llu\n");
859
860static int conn_latency_set(void *data, u64 val)
861{
862 struct hci_dev *hdev = data;
863
864 if (val > 0x01f3)
865 return -EINVAL;
866
867 hci_dev_lock(hdev);
868 hdev->le_conn_latency = val;
869 hci_dev_unlock(hdev);
870
871 return 0;
872}
873
874static int conn_latency_get(void *data, u64 *val)
875{
876 struct hci_dev *hdev = data;
877
878 hci_dev_lock(hdev);
879 *val = hdev->le_conn_latency;
880 hci_dev_unlock(hdev);
881
882 return 0;
883}
884
885DEFINE_SIMPLE_ATTRIBUTE(conn_latency_fops, conn_latency_get,
886 conn_latency_set, "%llu\n");
887
888static int supervision_timeout_set(void *data, u64 val)
889{
890 struct hci_dev *hdev = data;
891
892 if (val < 0x000a || val > 0x0c80)
893 return -EINVAL;
894
895 hci_dev_lock(hdev);
896 hdev->le_supv_timeout = val;
897 hci_dev_unlock(hdev);
898
899 return 0;
900}
901
902static int supervision_timeout_get(void *data, u64 *val)
903{
904 struct hci_dev *hdev = data;
905
906 hci_dev_lock(hdev);
907 *val = hdev->le_supv_timeout;
908 hci_dev_unlock(hdev);
909
910 return 0;
911}
912
913DEFINE_SIMPLE_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get,
914 supervision_timeout_set, "%llu\n");
915
916static int adv_channel_map_set(void *data, u64 val)
917{
918 struct hci_dev *hdev = data;
919
920 if (val < 0x01 || val > 0x07)
921 return -EINVAL;
922
923 hci_dev_lock(hdev);
924 hdev->le_adv_channel_map = val;
925 hci_dev_unlock(hdev);
926
927 return 0;
928}
929
930static int adv_channel_map_get(void *data, u64 *val)
931{
932 struct hci_dev *hdev = data;
933
934 hci_dev_lock(hdev);
935 *val = hdev->le_adv_channel_map;
936 hci_dev_unlock(hdev);
937
938 return 0;
939}
940
941DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
942 adv_channel_map_set, "%llu\n");
943
944static int adv_min_interval_set(void *data, u64 val)
945{
946 struct hci_dev *hdev = data;
947
948 if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval)
949 return -EINVAL;
950
951 hci_dev_lock(hdev);
952 hdev->le_adv_min_interval = val;
953 hci_dev_unlock(hdev);
954
955 return 0;
956}
957
958static int adv_min_interval_get(void *data, u64 *val)
959{
960 struct hci_dev *hdev = data;
961
962 hci_dev_lock(hdev);
963 *val = hdev->le_adv_min_interval;
964 hci_dev_unlock(hdev);
965
966 return 0;
967}
968
969DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,
970 adv_min_interval_set, "%llu\n");
971
972static int adv_max_interval_set(void *data, u64 val)
973{
974 struct hci_dev *hdev = data;
975
976 if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval)
977 return -EINVAL;
978
979 hci_dev_lock(hdev);
980 hdev->le_adv_max_interval = val;
981 hci_dev_unlock(hdev);
982
983 return 0;
984}
985
986static int adv_max_interval_get(void *data, u64 *val)
987{
988 struct hci_dev *hdev = data;
989
990 hci_dev_lock(hdev);
991 *val = hdev->le_adv_max_interval;
992 hci_dev_unlock(hdev);
993
994 return 0;
995}
996
997DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
998 adv_max_interval_set, "%llu\n");
999
1000void hci_debugfs_create_le(struct hci_dev *hdev)
1001{
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);
1010
1011
1012
1013
1014
1015 if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1016 debugfs_create_file("force_static_address", 0644,
1017 hdev->debugfs, hdev,
1018 &force_static_address_fops);
1019
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);
1044}
1045
1046void hci_debugfs_create_conn(struct hci_conn *conn)
1047{
1048 struct hci_dev *hdev = conn->hdev;
1049 char name[6];
1050
1051 if (IS_ERR_OR_NULL(hdev->debugfs))
1052 return;
1053
1054 snprintf(name, sizeof(name), "%u", conn->handle);
1055 conn->debugfs = debugfs_create_dir(name, hdev->debugfs);
1056}
1057