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