2 BlueZ - Bluetooth protocol stack for Linux
4 Copyright (C) 2014 Intel Corporation
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED.
24 #include <linux/debugfs.h>
26 #include <net/bluetooth/bluetooth.h>
27 #include <net/bluetooth/hci_core.h>
29 #include "hci_debugfs.h"
31 static int features_show(struct seq_file *f, void *ptr)
33 struct hci_dev *hdev = f->private;
37 for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) {
38 seq_printf(f, "%2u: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x "
39 "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", p,
40 hdev->features[p][0], hdev->features[p][1],
41 hdev->features[p][2], hdev->features[p][3],
42 hdev->features[p][4], hdev->features[p][5],
43 hdev->features[p][6], hdev->features[p][7]);
45 if (lmp_le_capable(hdev))
46 seq_printf(f, "LE: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x "
47 "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n",
48 hdev->le_features[0], hdev->le_features[1],
49 hdev->le_features[2], hdev->le_features[3],
50 hdev->le_features[4], hdev->le_features[5],
51 hdev->le_features[6], hdev->le_features[7]);
57 static int features_open(struct inode *inode, struct file *file)
59 return single_open(file, features_show, inode->i_private);
62 static const struct file_operations features_fops = {
63 .open = features_open,
66 .release = single_release,
69 static int device_list_show(struct seq_file *f, void *ptr)
71 struct hci_dev *hdev = f->private;
72 struct hci_conn_params *p;
73 struct bdaddr_list *b;
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,
87 static int device_list_open(struct inode *inode, struct file *file)
89 return single_open(file, device_list_show, inode->i_private);
92 static const struct file_operations device_list_fops = {
93 .open = device_list_open,
96 .release = single_release,
99 static int blacklist_show(struct seq_file *f, void *p)
101 struct hci_dev *hdev = f->private;
102 struct bdaddr_list *b;
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);
112 static int blacklist_open(struct inode *inode, struct file *file)
114 return single_open(file, blacklist_show, inode->i_private);
117 static const struct file_operations blacklist_fops = {
118 .open = blacklist_open,
121 .release = single_release,
124 static int uuids_show(struct seq_file *f, void *p)
126 struct hci_dev *hdev = f->private;
127 struct bt_uuid *uuid;
130 list_for_each_entry(uuid, &hdev->uuids, list) {
133 /* The Bluetooth UUID values are stored in big endian,
134 * but with reversed byte order. So convert them into
135 * the right order for the %pUb modifier.
137 for (i = 0; i < 16; i++)
138 val[i] = uuid->uuid[15 - i];
140 seq_printf(f, "%pUb\n", val);
142 hci_dev_unlock(hdev);
147 static int uuids_open(struct inode *inode, struct file *file)
149 return single_open(file, uuids_show, inode->i_private);
152 static const struct file_operations uuids_fops = {
156 .release = single_release,
159 static int conn_info_min_age_set(void *data, u64 val)
161 struct hci_dev *hdev = data;
163 if (val == 0 || val > hdev->conn_info_max_age)
167 hdev->conn_info_min_age = val;
168 hci_dev_unlock(hdev);
173 static int conn_info_min_age_get(void *data, u64 *val)
175 struct hci_dev *hdev = data;
178 *val = hdev->conn_info_min_age;
179 hci_dev_unlock(hdev);
184 DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
185 conn_info_min_age_set, "%llu\n");
187 static int conn_info_max_age_set(void *data, u64 val)
189 struct hci_dev *hdev = data;
191 if (val == 0 || val < hdev->conn_info_min_age)
195 hdev->conn_info_max_age = val;
196 hci_dev_unlock(hdev);
201 static int conn_info_max_age_get(void *data, u64 *val)
203 struct hci_dev *hdev = data;
206 *val = hdev->conn_info_max_age;
207 hci_dev_unlock(hdev);
212 DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
213 conn_info_max_age_set, "%llu\n");
215 void hci_debugfs_create_common(struct hci_dev *hdev)
217 debugfs_create_file("features", 0444, hdev->debugfs, hdev,
219 debugfs_create_u16("manufacturer", 0444, hdev->debugfs,
220 &hdev->manufacturer);
221 debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
222 debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
223 debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
225 debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
227 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
229 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
230 &conn_info_min_age_fops);
231 debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
232 &conn_info_max_age_fops);
235 static int inquiry_cache_show(struct seq_file *f, void *p)
237 struct hci_dev *hdev = f->private;
238 struct discovery_state *cache = &hdev->discovery;
239 struct inquiry_entry *e;
243 list_for_each_entry(e, &cache->all, all) {
244 struct inquiry_data *data = &e->data;
245 seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
247 data->pscan_rep_mode, data->pscan_period_mode,
248 data->pscan_mode, data->dev_class[2],
249 data->dev_class[1], data->dev_class[0],
250 __le16_to_cpu(data->clock_offset),
251 data->rssi, data->ssp_mode, e->timestamp);
254 hci_dev_unlock(hdev);
259 static int inquiry_cache_open(struct inode *inode, struct file *file)
261 return single_open(file, inquiry_cache_show, inode->i_private);
264 static const struct file_operations inquiry_cache_fops = {
265 .open = inquiry_cache_open,
268 .release = single_release,
271 static int link_keys_show(struct seq_file *f, void *ptr)
273 struct hci_dev *hdev = f->private;
274 struct link_key *key;
277 list_for_each_entry_rcu(key, &hdev->link_keys, list)
278 seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
279 HCI_LINK_KEY_SIZE, key->val, key->pin_len);
285 static int link_keys_open(struct inode *inode, struct file *file)
287 return single_open(file, link_keys_show, inode->i_private);
290 static const struct file_operations link_keys_fops = {
291 .open = link_keys_open,
294 .release = single_release,
297 static int dev_class_show(struct seq_file *f, void *ptr)
299 struct hci_dev *hdev = f->private;
302 seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
303 hdev->dev_class[1], hdev->dev_class[0]);
304 hci_dev_unlock(hdev);
309 static int dev_class_open(struct inode *inode, struct file *file)
311 return single_open(file, dev_class_show, inode->i_private);
314 static const struct file_operations dev_class_fops = {
315 .open = dev_class_open,
318 .release = single_release,
321 static int voice_setting_get(void *data, u64 *val)
323 struct hci_dev *hdev = data;
326 *val = hdev->voice_setting;
327 hci_dev_unlock(hdev);
332 DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get,
333 NULL, "0x%4.4llx\n");
335 static int auto_accept_delay_set(void *data, u64 val)
337 struct hci_dev *hdev = data;
340 hdev->auto_accept_delay = val;
341 hci_dev_unlock(hdev);
346 static int auto_accept_delay_get(void *data, u64 *val)
348 struct hci_dev *hdev = data;
351 *val = hdev->auto_accept_delay;
352 hci_dev_unlock(hdev);
357 DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
358 auto_accept_delay_set, "%llu\n");
360 static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
361 size_t count, loff_t *ppos)
363 struct hci_dev *hdev = file->private_data;
366 buf[0] = test_bit(HCI_SC_ONLY, &hdev->dev_flags) ? 'Y': 'N';
369 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
372 static const struct file_operations sc_only_mode_fops = {
374 .read = sc_only_mode_read,
375 .llseek = default_llseek,
378 static ssize_t force_sc_support_read(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
381 struct hci_dev *hdev = file->private_data;
384 buf[0] = test_bit(HCI_FORCE_SC, &hdev->dbg_flags) ? 'Y': 'N';
387 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
390 static ssize_t force_sc_support_write(struct file *file,
391 const char __user *user_buf,
392 size_t count, loff_t *ppos)
394 struct hci_dev *hdev = file->private_data;
396 size_t buf_size = min(count, (sizeof(buf)-1));
399 if (test_bit(HCI_UP, &hdev->flags))
402 if (copy_from_user(buf, user_buf, buf_size))
405 buf[buf_size] = '\0';
406 if (strtobool(buf, &enable))
409 if (enable == test_bit(HCI_FORCE_SC, &hdev->dbg_flags))
412 change_bit(HCI_FORCE_SC, &hdev->dbg_flags);
417 static const struct file_operations force_sc_support_fops = {
419 .read = force_sc_support_read,
420 .write = force_sc_support_write,
421 .llseek = default_llseek,
424 static ssize_t force_lesc_support_read(struct file *file,
425 char __user *user_buf,
426 size_t count, loff_t *ppos)
428 struct hci_dev *hdev = file->private_data;
431 buf[0] = test_bit(HCI_FORCE_LESC, &hdev->dbg_flags) ? 'Y': 'N';
434 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
437 static ssize_t force_lesc_support_write(struct file *file,
438 const char __user *user_buf,
439 size_t count, loff_t *ppos)
441 struct hci_dev *hdev = file->private_data;
443 size_t buf_size = min(count, (sizeof(buf)-1));
446 if (copy_from_user(buf, user_buf, buf_size))
449 buf[buf_size] = '\0';
450 if (strtobool(buf, &enable))
453 if (enable == test_bit(HCI_FORCE_LESC, &hdev->dbg_flags))
456 change_bit(HCI_FORCE_LESC, &hdev->dbg_flags);
461 static const struct file_operations force_lesc_support_fops = {
463 .read = force_lesc_support_read,
464 .write = force_lesc_support_write,
465 .llseek = default_llseek,
468 static int idle_timeout_set(void *data, u64 val)
470 struct hci_dev *hdev = data;
472 if (val != 0 && (val < 500 || val > 3600000))
476 hdev->idle_timeout = val;
477 hci_dev_unlock(hdev);
482 static int idle_timeout_get(void *data, u64 *val)
484 struct hci_dev *hdev = data;
487 *val = hdev->idle_timeout;
488 hci_dev_unlock(hdev);
493 DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
494 idle_timeout_set, "%llu\n");
496 static int sniff_min_interval_set(void *data, u64 val)
498 struct hci_dev *hdev = data;
500 if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
504 hdev->sniff_min_interval = val;
505 hci_dev_unlock(hdev);
510 static int sniff_min_interval_get(void *data, u64 *val)
512 struct hci_dev *hdev = data;
515 *val = hdev->sniff_min_interval;
516 hci_dev_unlock(hdev);
521 DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
522 sniff_min_interval_set, "%llu\n");
524 static int sniff_max_interval_set(void *data, u64 val)
526 struct hci_dev *hdev = data;
528 if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
532 hdev->sniff_max_interval = val;
533 hci_dev_unlock(hdev);
538 static int sniff_max_interval_get(void *data, u64 *val)
540 struct hci_dev *hdev = data;
543 *val = hdev->sniff_max_interval;
544 hci_dev_unlock(hdev);
549 DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
550 sniff_max_interval_set, "%llu\n");
552 void hci_debugfs_create_bredr(struct hci_dev *hdev)
554 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev,
555 &inquiry_cache_fops);
556 debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev,
558 debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev,
560 debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
561 &voice_setting_fops);
563 if (lmp_ssp_capable(hdev)) {
564 debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
565 hdev, &auto_accept_delay_fops);
566 debugfs_create_file("sc_only_mode", 0444, hdev->debugfs,
567 hdev, &sc_only_mode_fops);
569 debugfs_create_file("force_sc_support", 0644, hdev->debugfs,
570 hdev, &force_sc_support_fops);
572 if (lmp_le_capable(hdev))
573 debugfs_create_file("force_lesc_support", 0644,
575 &force_lesc_support_fops);
578 if (lmp_sniff_capable(hdev)) {
579 debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
580 hdev, &idle_timeout_fops);
581 debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs,
582 hdev, &sniff_min_interval_fops);
583 debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs,
584 hdev, &sniff_max_interval_fops);
588 void hci_debugfs_create_le(struct hci_dev *hdev)