Back to home page

OSCL-LXR

 
 

    


0001 /*
0002    BlueZ - Bluetooth protocol stack for Linux
0003 
0004    Copyright (C) 2014 Intel Corporation
0005 
0006    This program is free software; you can redistribute it and/or modify
0007    it under the terms of the GNU General Public License version 2 as
0008    published by the Free Software Foundation;
0009 
0010    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0011    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0012    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
0013    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
0014    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
0015    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0016    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0017    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0018 
0019    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
0020    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
0021    SOFTWARE IS DISCLAIMED.
0022 */
0023 
0024 #include <linux/debugfs.h>
0025 
0026 #include <net/bluetooth/bluetooth.h>
0027 #include <net/bluetooth/hci_core.h>
0028 
0029 #include "smp.h"
0030 #include "hci_request.h"
0031 #include "hci_debugfs.h"
0032 
0033 #define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk)                   \
0034 static ssize_t __name ## _read(struct file *file,                 \
0035                 char __user *user_buf,                \
0036                 size_t count, loff_t *ppos)           \
0037 {                                         \
0038     struct hci_dev *hdev = file->private_data;                \
0039     char buf[3];                                  \
0040                                           \
0041     buf[0] = test_bit(__quirk, &hdev->quirks) ? 'Y' : 'N';            \
0042     buf[1] = '\n';                                \
0043     buf[2] = '\0';                                \
0044     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);        \
0045 }                                         \
0046                                           \
0047 static ssize_t __name ## _write(struct file *file,                \
0048                  const char __user *user_buf,             \
0049                  size_t count, loff_t *ppos)              \
0050 {                                         \
0051     struct hci_dev *hdev = file->private_data;                \
0052     bool enable;                                  \
0053     int err;                                  \
0054                                           \
0055     if (test_bit(HCI_UP, &hdev->flags))                   \
0056         return -EBUSY;                            \
0057                                           \
0058     err = kstrtobool_from_user(user_buf, count, &enable);             \
0059     if (err)                                  \
0060         return err;                           \
0061                                           \
0062     if (enable == test_bit(__quirk, &hdev->quirks))               \
0063         return -EALREADY;                         \
0064                                           \
0065     change_bit(__quirk, &hdev->quirks);                   \
0066                                           \
0067     return count;                                 \
0068 }                                         \
0069                                           \
0070 static const struct file_operations __name ## _fops = {               \
0071     .open       = simple_open,                        \
0072     .read       = __name ## _read,                    \
0073     .write      = __name ## _write,                   \
0074     .llseek     = default_llseek,                     \
0075 }                                         \
0076 
0077 #define DEFINE_INFO_ATTRIBUTE(__name, __field)                    \
0078 static int __name ## _show(struct seq_file *f, void *ptr)             \
0079 {                                         \
0080     struct hci_dev *hdev = f->private;                    \
0081                                           \
0082     hci_dev_lock(hdev);                           \
0083     seq_printf(f, "%s\n", hdev->__field ? : "");                  \
0084     hci_dev_unlock(hdev);                             \
0085                                           \
0086     return 0;                                 \
0087 }                                         \
0088                                           \
0089 DEFINE_SHOW_ATTRIBUTE(__name)
0090 
0091 static int features_show(struct seq_file *f, void *ptr)
0092 {
0093     struct hci_dev *hdev = f->private;
0094     u8 p;
0095 
0096     hci_dev_lock(hdev);
0097     for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++)
0098         seq_printf(f, "%2u: %8ph\n", p, hdev->features[p]);
0099     if (lmp_le_capable(hdev))
0100         seq_printf(f, "LE: %8ph\n", hdev->le_features);
0101     hci_dev_unlock(hdev);
0102 
0103     return 0;
0104 }
0105 
0106 DEFINE_SHOW_ATTRIBUTE(features);
0107 
0108 static int device_id_show(struct seq_file *f, void *ptr)
0109 {
0110     struct hci_dev *hdev = f->private;
0111 
0112     hci_dev_lock(hdev);
0113     seq_printf(f, "%4.4x:%4.4x:%4.4x:%4.4x\n", hdev->devid_source,
0114           hdev->devid_vendor, hdev->devid_product, hdev->devid_version);
0115     hci_dev_unlock(hdev);
0116 
0117     return 0;
0118 }
0119 
0120 DEFINE_SHOW_ATTRIBUTE(device_id);
0121 
0122 static int device_list_show(struct seq_file *f, void *ptr)
0123 {
0124     struct hci_dev *hdev = f->private;
0125     struct hci_conn_params *p;
0126     struct bdaddr_list *b;
0127 
0128     hci_dev_lock(hdev);
0129     list_for_each_entry(b, &hdev->accept_list, list)
0130         seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
0131     list_for_each_entry(p, &hdev->le_conn_params, list) {
0132         seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type,
0133                p->auto_connect);
0134     }
0135     hci_dev_unlock(hdev);
0136 
0137     return 0;
0138 }
0139 
0140 DEFINE_SHOW_ATTRIBUTE(device_list);
0141 
0142 static int blacklist_show(struct seq_file *f, void *p)
0143 {
0144     struct hci_dev *hdev = f->private;
0145     struct bdaddr_list *b;
0146 
0147     hci_dev_lock(hdev);
0148     list_for_each_entry(b, &hdev->reject_list, list)
0149         seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
0150     hci_dev_unlock(hdev);
0151 
0152     return 0;
0153 }
0154 
0155 DEFINE_SHOW_ATTRIBUTE(blacklist);
0156 
0157 static int blocked_keys_show(struct seq_file *f, void *p)
0158 {
0159     struct hci_dev *hdev = f->private;
0160     struct blocked_key *key;
0161 
0162     rcu_read_lock();
0163     list_for_each_entry_rcu(key, &hdev->blocked_keys, list)
0164         seq_printf(f, "%u %*phN\n", key->type, 16, key->val);
0165     rcu_read_unlock();
0166 
0167     return 0;
0168 }
0169 
0170 DEFINE_SHOW_ATTRIBUTE(blocked_keys);
0171 
0172 static int uuids_show(struct seq_file *f, void *p)
0173 {
0174     struct hci_dev *hdev = f->private;
0175     struct bt_uuid *uuid;
0176 
0177     hci_dev_lock(hdev);
0178     list_for_each_entry(uuid, &hdev->uuids, list) {
0179         u8 i, val[16];
0180 
0181         /* The Bluetooth UUID values are stored in big endian,
0182          * but with reversed byte order. So convert them into
0183          * the right order for the %pUb modifier.
0184          */
0185         for (i = 0; i < 16; i++)
0186             val[i] = uuid->uuid[15 - i];
0187 
0188         seq_printf(f, "%pUb\n", val);
0189     }
0190     hci_dev_unlock(hdev);
0191 
0192        return 0;
0193 }
0194 
0195 DEFINE_SHOW_ATTRIBUTE(uuids);
0196 
0197 static int remote_oob_show(struct seq_file *f, void *ptr)
0198 {
0199     struct hci_dev *hdev = f->private;
0200     struct oob_data *data;
0201 
0202     hci_dev_lock(hdev);
0203     list_for_each_entry(data, &hdev->remote_oob_data, list) {
0204         seq_printf(f, "%pMR (type %u) %u %*phN %*phN %*phN %*phN\n",
0205                &data->bdaddr, data->bdaddr_type, data->present,
0206                16, data->hash192, 16, data->rand192,
0207                16, data->hash256, 16, data->rand256);
0208     }
0209     hci_dev_unlock(hdev);
0210 
0211     return 0;
0212 }
0213 
0214 DEFINE_SHOW_ATTRIBUTE(remote_oob);
0215 
0216 static int conn_info_min_age_set(void *data, u64 val)
0217 {
0218     struct hci_dev *hdev = data;
0219 
0220     if (val == 0 || val > hdev->conn_info_max_age)
0221         return -EINVAL;
0222 
0223     hci_dev_lock(hdev);
0224     hdev->conn_info_min_age = val;
0225     hci_dev_unlock(hdev);
0226 
0227     return 0;
0228 }
0229 
0230 static int conn_info_min_age_get(void *data, u64 *val)
0231 {
0232     struct hci_dev *hdev = data;
0233 
0234     hci_dev_lock(hdev);
0235     *val = hdev->conn_info_min_age;
0236     hci_dev_unlock(hdev);
0237 
0238     return 0;
0239 }
0240 
0241 DEFINE_DEBUGFS_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
0242               conn_info_min_age_set, "%llu\n");
0243 
0244 static int conn_info_max_age_set(void *data, u64 val)
0245 {
0246     struct hci_dev *hdev = data;
0247 
0248     if (val == 0 || val < hdev->conn_info_min_age)
0249         return -EINVAL;
0250 
0251     hci_dev_lock(hdev);
0252     hdev->conn_info_max_age = val;
0253     hci_dev_unlock(hdev);
0254 
0255     return 0;
0256 }
0257 
0258 static int conn_info_max_age_get(void *data, u64 *val)
0259 {
0260     struct hci_dev *hdev = data;
0261 
0262     hci_dev_lock(hdev);
0263     *val = hdev->conn_info_max_age;
0264     hci_dev_unlock(hdev);
0265 
0266     return 0;
0267 }
0268 
0269 DEFINE_DEBUGFS_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
0270               conn_info_max_age_set, "%llu\n");
0271 
0272 static ssize_t use_debug_keys_read(struct file *file, char __user *user_buf,
0273                    size_t count, loff_t *ppos)
0274 {
0275     struct hci_dev *hdev = file->private_data;
0276     char buf[3];
0277 
0278     buf[0] = hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS) ? 'Y' : 'N';
0279     buf[1] = '\n';
0280     buf[2] = '\0';
0281     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0282 }
0283 
0284 static const struct file_operations use_debug_keys_fops = {
0285     .open       = simple_open,
0286     .read       = use_debug_keys_read,
0287     .llseek     = default_llseek,
0288 };
0289 
0290 static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf,
0291                  size_t count, loff_t *ppos)
0292 {
0293     struct hci_dev *hdev = file->private_data;
0294     char buf[3];
0295 
0296     buf[0] = hci_dev_test_flag(hdev, HCI_SC_ONLY) ? 'Y' : 'N';
0297     buf[1] = '\n';
0298     buf[2] = '\0';
0299     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0300 }
0301 
0302 static const struct file_operations sc_only_mode_fops = {
0303     .open       = simple_open,
0304     .read       = sc_only_mode_read,
0305     .llseek     = default_llseek,
0306 };
0307 
0308 DEFINE_INFO_ATTRIBUTE(hardware_info, hw_info);
0309 DEFINE_INFO_ATTRIBUTE(firmware_info, fw_info);
0310 
0311 void hci_debugfs_create_common(struct hci_dev *hdev)
0312 {
0313     debugfs_create_file("features", 0444, hdev->debugfs, hdev,
0314                 &features_fops);
0315     debugfs_create_u16("manufacturer", 0444, hdev->debugfs,
0316                &hdev->manufacturer);
0317     debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver);
0318     debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev);
0319     debugfs_create_u8("hardware_error", 0444, hdev->debugfs,
0320               &hdev->hw_error_code);
0321     debugfs_create_file("device_id", 0444, hdev->debugfs, hdev,
0322                 &device_id_fops);
0323 
0324     debugfs_create_file("device_list", 0444, hdev->debugfs, hdev,
0325                 &device_list_fops);
0326     debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev,
0327                 &blacklist_fops);
0328     debugfs_create_file("blocked_keys", 0444, hdev->debugfs, hdev,
0329                 &blocked_keys_fops);
0330     debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
0331     debugfs_create_file("remote_oob", 0400, hdev->debugfs, hdev,
0332                 &remote_oob_fops);
0333 
0334     debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
0335                 &conn_info_min_age_fops);
0336     debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
0337                 &conn_info_max_age_fops);
0338 
0339     if (lmp_ssp_capable(hdev) || lmp_le_capable(hdev))
0340         debugfs_create_file("use_debug_keys", 0444, hdev->debugfs,
0341                     hdev, &use_debug_keys_fops);
0342 
0343     if (lmp_sc_capable(hdev) || lmp_le_capable(hdev))
0344         debugfs_create_file("sc_only_mode", 0444, hdev->debugfs,
0345                     hdev, &sc_only_mode_fops);
0346 
0347     if (hdev->hw_info)
0348         debugfs_create_file("hardware_info", 0444, hdev->debugfs,
0349                     hdev, &hardware_info_fops);
0350 
0351     if (hdev->fw_info)
0352         debugfs_create_file("firmware_info", 0444, hdev->debugfs,
0353                     hdev, &firmware_info_fops);
0354 }
0355 
0356 static int inquiry_cache_show(struct seq_file *f, void *p)
0357 {
0358     struct hci_dev *hdev = f->private;
0359     struct discovery_state *cache = &hdev->discovery;
0360     struct inquiry_entry *e;
0361 
0362     hci_dev_lock(hdev);
0363 
0364     list_for_each_entry(e, &cache->all, all) {
0365         struct inquiry_data *data = &e->data;
0366         seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
0367                &data->bdaddr,
0368                data->pscan_rep_mode, data->pscan_period_mode,
0369                data->pscan_mode, data->dev_class[2],
0370                data->dev_class[1], data->dev_class[0],
0371                __le16_to_cpu(data->clock_offset),
0372                data->rssi, data->ssp_mode, e->timestamp);
0373     }
0374 
0375     hci_dev_unlock(hdev);
0376 
0377     return 0;
0378 }
0379 
0380 DEFINE_SHOW_ATTRIBUTE(inquiry_cache);
0381 
0382 static int link_keys_show(struct seq_file *f, void *ptr)
0383 {
0384     struct hci_dev *hdev = f->private;
0385     struct link_key *key;
0386 
0387     rcu_read_lock();
0388     list_for_each_entry_rcu(key, &hdev->link_keys, list)
0389         seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
0390                HCI_LINK_KEY_SIZE, key->val, key->pin_len);
0391     rcu_read_unlock();
0392 
0393     return 0;
0394 }
0395 
0396 DEFINE_SHOW_ATTRIBUTE(link_keys);
0397 
0398 static int dev_class_show(struct seq_file *f, void *ptr)
0399 {
0400     struct hci_dev *hdev = f->private;
0401 
0402     hci_dev_lock(hdev);
0403     seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
0404            hdev->dev_class[1], hdev->dev_class[0]);
0405     hci_dev_unlock(hdev);
0406 
0407     return 0;
0408 }
0409 
0410 DEFINE_SHOW_ATTRIBUTE(dev_class);
0411 
0412 static int voice_setting_get(void *data, u64 *val)
0413 {
0414     struct hci_dev *hdev = data;
0415 
0416     hci_dev_lock(hdev);
0417     *val = hdev->voice_setting;
0418     hci_dev_unlock(hdev);
0419 
0420     return 0;
0421 }
0422 
0423 DEFINE_DEBUGFS_ATTRIBUTE(voice_setting_fops, voice_setting_get,
0424               NULL, "0x%4.4llx\n");
0425 
0426 static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf,
0427                    size_t count, loff_t *ppos)
0428 {
0429     struct hci_dev *hdev = file->private_data;
0430     char buf[3];
0431 
0432     buf[0] = hdev->ssp_debug_mode ? 'Y' : 'N';
0433     buf[1] = '\n';
0434     buf[2] = '\0';
0435     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0436 }
0437 
0438 static const struct file_operations ssp_debug_mode_fops = {
0439     .open       = simple_open,
0440     .read       = ssp_debug_mode_read,
0441     .llseek     = default_llseek,
0442 };
0443 
0444 static int auto_accept_delay_set(void *data, u64 val)
0445 {
0446     struct hci_dev *hdev = data;
0447 
0448     hci_dev_lock(hdev);
0449     hdev->auto_accept_delay = val;
0450     hci_dev_unlock(hdev);
0451 
0452     return 0;
0453 }
0454 
0455 static int min_encrypt_key_size_set(void *data, u64 val)
0456 {
0457     struct hci_dev *hdev = data;
0458 
0459     if (val < 1 || val > 16)
0460         return -EINVAL;
0461 
0462     hci_dev_lock(hdev);
0463     hdev->min_enc_key_size = val;
0464     hci_dev_unlock(hdev);
0465 
0466     return 0;
0467 }
0468 
0469 static int min_encrypt_key_size_get(void *data, u64 *val)
0470 {
0471     struct hci_dev *hdev = data;
0472 
0473     hci_dev_lock(hdev);
0474     *val = hdev->min_enc_key_size;
0475     hci_dev_unlock(hdev);
0476 
0477     return 0;
0478 }
0479 
0480 DEFINE_DEBUGFS_ATTRIBUTE(min_encrypt_key_size_fops,
0481               min_encrypt_key_size_get,
0482               min_encrypt_key_size_set, "%llu\n");
0483 
0484 static int auto_accept_delay_get(void *data, u64 *val)
0485 {
0486     struct hci_dev *hdev = data;
0487 
0488     hci_dev_lock(hdev);
0489     *val = hdev->auto_accept_delay;
0490     hci_dev_unlock(hdev);
0491 
0492     return 0;
0493 }
0494 
0495 DEFINE_DEBUGFS_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
0496               auto_accept_delay_set, "%llu\n");
0497 
0498 static ssize_t force_bredr_smp_read(struct file *file,
0499                     char __user *user_buf,
0500                     size_t count, loff_t *ppos)
0501 {
0502     struct hci_dev *hdev = file->private_data;
0503     char buf[3];
0504 
0505     buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y' : 'N';
0506     buf[1] = '\n';
0507     buf[2] = '\0';
0508     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0509 }
0510 
0511 static ssize_t force_bredr_smp_write(struct file *file,
0512                      const char __user *user_buf,
0513                      size_t count, loff_t *ppos)
0514 {
0515     struct hci_dev *hdev = file->private_data;
0516     bool enable;
0517     int err;
0518 
0519     err = kstrtobool_from_user(user_buf, count, &enable);
0520     if (err)
0521         return err;
0522 
0523     err = smp_force_bredr(hdev, enable);
0524     if (err)
0525         return err;
0526 
0527     return count;
0528 }
0529 
0530 static const struct file_operations force_bredr_smp_fops = {
0531     .open       = simple_open,
0532     .read       = force_bredr_smp_read,
0533     .write      = force_bredr_smp_write,
0534     .llseek     = default_llseek,
0535 };
0536 
0537 static int idle_timeout_set(void *data, u64 val)
0538 {
0539     struct hci_dev *hdev = data;
0540 
0541     if (val != 0 && (val < 500 || val > 3600000))
0542         return -EINVAL;
0543 
0544     hci_dev_lock(hdev);
0545     hdev->idle_timeout = val;
0546     hci_dev_unlock(hdev);
0547 
0548     return 0;
0549 }
0550 
0551 static int idle_timeout_get(void *data, u64 *val)
0552 {
0553     struct hci_dev *hdev = data;
0554 
0555     hci_dev_lock(hdev);
0556     *val = hdev->idle_timeout;
0557     hci_dev_unlock(hdev);
0558 
0559     return 0;
0560 }
0561 
0562 DEFINE_DEBUGFS_ATTRIBUTE(idle_timeout_fops, idle_timeout_get,
0563               idle_timeout_set, "%llu\n");
0564 
0565 static int sniff_min_interval_set(void *data, u64 val)
0566 {
0567     struct hci_dev *hdev = data;
0568 
0569     if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
0570         return -EINVAL;
0571 
0572     hci_dev_lock(hdev);
0573     hdev->sniff_min_interval = val;
0574     hci_dev_unlock(hdev);
0575 
0576     return 0;
0577 }
0578 
0579 static int sniff_min_interval_get(void *data, u64 *val)
0580 {
0581     struct hci_dev *hdev = data;
0582 
0583     hci_dev_lock(hdev);
0584     *val = hdev->sniff_min_interval;
0585     hci_dev_unlock(hdev);
0586 
0587     return 0;
0588 }
0589 
0590 DEFINE_DEBUGFS_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get,
0591               sniff_min_interval_set, "%llu\n");
0592 
0593 static int sniff_max_interval_set(void *data, u64 val)
0594 {
0595     struct hci_dev *hdev = data;
0596 
0597     if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
0598         return -EINVAL;
0599 
0600     hci_dev_lock(hdev);
0601     hdev->sniff_max_interval = val;
0602     hci_dev_unlock(hdev);
0603 
0604     return 0;
0605 }
0606 
0607 static int sniff_max_interval_get(void *data, u64 *val)
0608 {
0609     struct hci_dev *hdev = data;
0610 
0611     hci_dev_lock(hdev);
0612     *val = hdev->sniff_max_interval;
0613     hci_dev_unlock(hdev);
0614 
0615     return 0;
0616 }
0617 
0618 DEFINE_DEBUGFS_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
0619               sniff_max_interval_set, "%llu\n");
0620 
0621 void hci_debugfs_create_bredr(struct hci_dev *hdev)
0622 {
0623     debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev,
0624                 &inquiry_cache_fops);
0625     debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev,
0626                 &link_keys_fops);
0627     debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev,
0628                 &dev_class_fops);
0629     debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
0630                 &voice_setting_fops);
0631 
0632     /* If the controller does not support BR/EDR Secure Connections
0633      * feature, then the BR/EDR SMP channel shall not be present.
0634      *
0635      * To test this with Bluetooth 4.0 controllers, create a debugfs
0636      * switch that allows forcing BR/EDR SMP support and accepting
0637      * cross-transport pairing on non-AES encrypted connections.
0638      */
0639     if (!lmp_sc_capable(hdev))
0640         debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs,
0641                     hdev, &force_bredr_smp_fops);
0642 
0643     if (lmp_ssp_capable(hdev)) {
0644         debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
0645                     hdev, &ssp_debug_mode_fops);
0646         debugfs_create_file("min_encrypt_key_size", 0644, hdev->debugfs,
0647                     hdev, &min_encrypt_key_size_fops);
0648         debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
0649                     hdev, &auto_accept_delay_fops);
0650     }
0651 
0652     if (lmp_sniff_capable(hdev)) {
0653         debugfs_create_file("idle_timeout", 0644, hdev->debugfs,
0654                     hdev, &idle_timeout_fops);
0655         debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs,
0656                     hdev, &sniff_min_interval_fops);
0657         debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs,
0658                     hdev, &sniff_max_interval_fops);
0659     }
0660 }
0661 
0662 static int identity_show(struct seq_file *f, void *p)
0663 {
0664     struct hci_dev *hdev = f->private;
0665     bdaddr_t addr;
0666     u8 addr_type;
0667 
0668     hci_dev_lock(hdev);
0669 
0670     hci_copy_identity_address(hdev, &addr, &addr_type);
0671 
0672     seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type,
0673            16, hdev->irk, &hdev->rpa);
0674 
0675     hci_dev_unlock(hdev);
0676 
0677     return 0;
0678 }
0679 
0680 DEFINE_SHOW_ATTRIBUTE(identity);
0681 
0682 static int rpa_timeout_set(void *data, u64 val)
0683 {
0684     struct hci_dev *hdev = data;
0685 
0686     /* Require the RPA timeout to be at least 30 seconds and at most
0687      * 24 hours.
0688      */
0689     if (val < 30 || val > (60 * 60 * 24))
0690         return -EINVAL;
0691 
0692     hci_dev_lock(hdev);
0693     hdev->rpa_timeout = val;
0694     hci_dev_unlock(hdev);
0695 
0696     return 0;
0697 }
0698 
0699 static int rpa_timeout_get(void *data, u64 *val)
0700 {
0701     struct hci_dev *hdev = data;
0702 
0703     hci_dev_lock(hdev);
0704     *val = hdev->rpa_timeout;
0705     hci_dev_unlock(hdev);
0706 
0707     return 0;
0708 }
0709 
0710 DEFINE_DEBUGFS_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get,
0711               rpa_timeout_set, "%llu\n");
0712 
0713 static int random_address_show(struct seq_file *f, void *p)
0714 {
0715     struct hci_dev *hdev = f->private;
0716 
0717     hci_dev_lock(hdev);
0718     seq_printf(f, "%pMR\n", &hdev->random_addr);
0719     hci_dev_unlock(hdev);
0720 
0721     return 0;
0722 }
0723 
0724 DEFINE_SHOW_ATTRIBUTE(random_address);
0725 
0726 static int static_address_show(struct seq_file *f, void *p)
0727 {
0728     struct hci_dev *hdev = f->private;
0729 
0730     hci_dev_lock(hdev);
0731     seq_printf(f, "%pMR\n", &hdev->static_addr);
0732     hci_dev_unlock(hdev);
0733 
0734     return 0;
0735 }
0736 
0737 DEFINE_SHOW_ATTRIBUTE(static_address);
0738 
0739 static ssize_t force_static_address_read(struct file *file,
0740                      char __user *user_buf,
0741                      size_t count, loff_t *ppos)
0742 {
0743     struct hci_dev *hdev = file->private_data;
0744     char buf[3];
0745 
0746     buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ? 'Y' : 'N';
0747     buf[1] = '\n';
0748     buf[2] = '\0';
0749     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
0750 }
0751 
0752 static ssize_t force_static_address_write(struct file *file,
0753                       const char __user *user_buf,
0754                       size_t count, loff_t *ppos)
0755 {
0756     struct hci_dev *hdev = file->private_data;
0757     bool enable;
0758     int err;
0759 
0760     if (test_bit(HCI_UP, &hdev->flags))
0761         return -EBUSY;
0762 
0763     err = kstrtobool_from_user(user_buf, count, &enable);
0764     if (err)
0765         return err;
0766 
0767     if (enable == hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR))
0768         return -EALREADY;
0769 
0770     hci_dev_change_flag(hdev, HCI_FORCE_STATIC_ADDR);
0771 
0772     return count;
0773 }
0774 
0775 static const struct file_operations force_static_address_fops = {
0776     .open       = simple_open,
0777     .read       = force_static_address_read,
0778     .write      = force_static_address_write,
0779     .llseek     = default_llseek,
0780 };
0781 
0782 static int white_list_show(struct seq_file *f, void *ptr)
0783 {
0784     struct hci_dev *hdev = f->private;
0785     struct bdaddr_list *b;
0786 
0787     hci_dev_lock(hdev);
0788     list_for_each_entry(b, &hdev->le_accept_list, list)
0789         seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
0790     hci_dev_unlock(hdev);
0791 
0792     return 0;
0793 }
0794 
0795 DEFINE_SHOW_ATTRIBUTE(white_list);
0796 
0797 static int resolv_list_show(struct seq_file *f, void *ptr)
0798 {
0799     struct hci_dev *hdev = f->private;
0800     struct bdaddr_list *b;
0801 
0802     hci_dev_lock(hdev);
0803     list_for_each_entry(b, &hdev->le_resolv_list, list)
0804         seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type);
0805     hci_dev_unlock(hdev);
0806 
0807     return 0;
0808 }
0809 
0810 DEFINE_SHOW_ATTRIBUTE(resolv_list);
0811 
0812 static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
0813 {
0814     struct hci_dev *hdev = f->private;
0815     struct smp_irk *irk;
0816 
0817     rcu_read_lock();
0818     list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
0819         seq_printf(f, "%pMR (type %u) %*phN %pMR\n",
0820                &irk->bdaddr, irk->addr_type,
0821                16, irk->val, &irk->rpa);
0822     }
0823     rcu_read_unlock();
0824 
0825     return 0;
0826 }
0827 
0828 DEFINE_SHOW_ATTRIBUTE(identity_resolving_keys);
0829 
0830 static int long_term_keys_show(struct seq_file *f, void *ptr)
0831 {
0832     struct hci_dev *hdev = f->private;
0833     struct smp_ltk *ltk;
0834 
0835     rcu_read_lock();
0836     list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list)
0837         seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n",
0838                &ltk->bdaddr, ltk->bdaddr_type, ltk->authenticated,
0839                ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv),
0840                __le64_to_cpu(ltk->rand), 16, ltk->val);
0841     rcu_read_unlock();
0842 
0843     return 0;
0844 }
0845 
0846 DEFINE_SHOW_ATTRIBUTE(long_term_keys);
0847 
0848 static int conn_min_interval_set(void *data, u64 val)
0849 {
0850     struct hci_dev *hdev = data;
0851 
0852     if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval)
0853         return -EINVAL;
0854 
0855     hci_dev_lock(hdev);
0856     hdev->le_conn_min_interval = val;
0857     hci_dev_unlock(hdev);
0858 
0859     return 0;
0860 }
0861 
0862 static int conn_min_interval_get(void *data, u64 *val)
0863 {
0864     struct hci_dev *hdev = data;
0865 
0866     hci_dev_lock(hdev);
0867     *val = hdev->le_conn_min_interval;
0868     hci_dev_unlock(hdev);
0869 
0870     return 0;
0871 }
0872 
0873 DEFINE_DEBUGFS_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get,
0874               conn_min_interval_set, "%llu\n");
0875 
0876 static int conn_max_interval_set(void *data, u64 val)
0877 {
0878     struct hci_dev *hdev = data;
0879 
0880     if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval)
0881         return -EINVAL;
0882 
0883     hci_dev_lock(hdev);
0884     hdev->le_conn_max_interval = val;
0885     hci_dev_unlock(hdev);
0886 
0887     return 0;
0888 }
0889 
0890 static int conn_max_interval_get(void *data, u64 *val)
0891 {
0892     struct hci_dev *hdev = data;
0893 
0894     hci_dev_lock(hdev);
0895     *val = hdev->le_conn_max_interval;
0896     hci_dev_unlock(hdev);
0897 
0898     return 0;
0899 }
0900 
0901 DEFINE_DEBUGFS_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
0902               conn_max_interval_set, "%llu\n");
0903 
0904 static int conn_latency_set(void *data, u64 val)
0905 {
0906     struct hci_dev *hdev = data;
0907 
0908     if (val > 0x01f3)
0909         return -EINVAL;
0910 
0911     hci_dev_lock(hdev);
0912     hdev->le_conn_latency = val;
0913     hci_dev_unlock(hdev);
0914 
0915     return 0;
0916 }
0917 
0918 static int conn_latency_get(void *data, u64 *val)
0919 {
0920     struct hci_dev *hdev = data;
0921 
0922     hci_dev_lock(hdev);
0923     *val = hdev->le_conn_latency;
0924     hci_dev_unlock(hdev);
0925 
0926     return 0;
0927 }
0928 
0929 DEFINE_DEBUGFS_ATTRIBUTE(conn_latency_fops, conn_latency_get,
0930               conn_latency_set, "%llu\n");
0931 
0932 static int supervision_timeout_set(void *data, u64 val)
0933 {
0934     struct hci_dev *hdev = data;
0935 
0936     if (val < 0x000a || val > 0x0c80)
0937         return -EINVAL;
0938 
0939     hci_dev_lock(hdev);
0940     hdev->le_supv_timeout = val;
0941     hci_dev_unlock(hdev);
0942 
0943     return 0;
0944 }
0945 
0946 static int supervision_timeout_get(void *data, u64 *val)
0947 {
0948     struct hci_dev *hdev = data;
0949 
0950     hci_dev_lock(hdev);
0951     *val = hdev->le_supv_timeout;
0952     hci_dev_unlock(hdev);
0953 
0954     return 0;
0955 }
0956 
0957 DEFINE_DEBUGFS_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get,
0958               supervision_timeout_set, "%llu\n");
0959 
0960 static int adv_channel_map_set(void *data, u64 val)
0961 {
0962     struct hci_dev *hdev = data;
0963 
0964     if (val < 0x01 || val > 0x07)
0965         return -EINVAL;
0966 
0967     hci_dev_lock(hdev);
0968     hdev->le_adv_channel_map = val;
0969     hci_dev_unlock(hdev);
0970 
0971     return 0;
0972 }
0973 
0974 static int adv_channel_map_get(void *data, u64 *val)
0975 {
0976     struct hci_dev *hdev = data;
0977 
0978     hci_dev_lock(hdev);
0979     *val = hdev->le_adv_channel_map;
0980     hci_dev_unlock(hdev);
0981 
0982     return 0;
0983 }
0984 
0985 DEFINE_DEBUGFS_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
0986               adv_channel_map_set, "%llu\n");
0987 
0988 static int adv_min_interval_set(void *data, u64 val)
0989 {
0990     struct hci_dev *hdev = data;
0991 
0992     if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval)
0993         return -EINVAL;
0994 
0995     hci_dev_lock(hdev);
0996     hdev->le_adv_min_interval = val;
0997     hci_dev_unlock(hdev);
0998 
0999     return 0;
1000 }
1001 
1002 static int adv_min_interval_get(void *data, u64 *val)
1003 {
1004     struct hci_dev *hdev = data;
1005 
1006     hci_dev_lock(hdev);
1007     *val = hdev->le_adv_min_interval;
1008     hci_dev_unlock(hdev);
1009 
1010     return 0;
1011 }
1012 
1013 DEFINE_DEBUGFS_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get,
1014               adv_min_interval_set, "%llu\n");
1015 
1016 static int adv_max_interval_set(void *data, u64 val)
1017 {
1018     struct hci_dev *hdev = data;
1019 
1020     if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval)
1021         return -EINVAL;
1022 
1023     hci_dev_lock(hdev);
1024     hdev->le_adv_max_interval = val;
1025     hci_dev_unlock(hdev);
1026 
1027     return 0;
1028 }
1029 
1030 static int adv_max_interval_get(void *data, u64 *val)
1031 {
1032     struct hci_dev *hdev = data;
1033 
1034     hci_dev_lock(hdev);
1035     *val = hdev->le_adv_max_interval;
1036     hci_dev_unlock(hdev);
1037 
1038     return 0;
1039 }
1040 
1041 DEFINE_DEBUGFS_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get,
1042               adv_max_interval_set, "%llu\n");
1043 
1044 static int min_key_size_set(void *data, u64 val)
1045 {
1046     struct hci_dev *hdev = data;
1047 
1048     if (val > hdev->le_max_key_size || val < SMP_MIN_ENC_KEY_SIZE)
1049         return -EINVAL;
1050 
1051     hci_dev_lock(hdev);
1052     hdev->le_min_key_size = val;
1053     hci_dev_unlock(hdev);
1054 
1055     return 0;
1056 }
1057 
1058 static int min_key_size_get(void *data, u64 *val)
1059 {
1060     struct hci_dev *hdev = data;
1061 
1062     hci_dev_lock(hdev);
1063     *val = hdev->le_min_key_size;
1064     hci_dev_unlock(hdev);
1065 
1066     return 0;
1067 }
1068 
1069 DEFINE_DEBUGFS_ATTRIBUTE(min_key_size_fops, min_key_size_get,
1070               min_key_size_set, "%llu\n");
1071 
1072 static int max_key_size_set(void *data, u64 val)
1073 {
1074     struct hci_dev *hdev = data;
1075 
1076     if (val > SMP_MAX_ENC_KEY_SIZE || val < hdev->le_min_key_size)
1077         return -EINVAL;
1078 
1079     hci_dev_lock(hdev);
1080     hdev->le_max_key_size = val;
1081     hci_dev_unlock(hdev);
1082 
1083     return 0;
1084 }
1085 
1086 static int max_key_size_get(void *data, u64 *val)
1087 {
1088     struct hci_dev *hdev = data;
1089 
1090     hci_dev_lock(hdev);
1091     *val = hdev->le_max_key_size;
1092     hci_dev_unlock(hdev);
1093 
1094     return 0;
1095 }
1096 
1097 DEFINE_DEBUGFS_ATTRIBUTE(max_key_size_fops, max_key_size_get,
1098               max_key_size_set, "%llu\n");
1099 
1100 static int auth_payload_timeout_set(void *data, u64 val)
1101 {
1102     struct hci_dev *hdev = data;
1103 
1104     if (val < 0x0001 || val > 0xffff)
1105         return -EINVAL;
1106 
1107     hci_dev_lock(hdev);
1108     hdev->auth_payload_timeout = val;
1109     hci_dev_unlock(hdev);
1110 
1111     return 0;
1112 }
1113 
1114 static int auth_payload_timeout_get(void *data, u64 *val)
1115 {
1116     struct hci_dev *hdev = data;
1117 
1118     hci_dev_lock(hdev);
1119     *val = hdev->auth_payload_timeout;
1120     hci_dev_unlock(hdev);
1121 
1122     return 0;
1123 }
1124 
1125 DEFINE_DEBUGFS_ATTRIBUTE(auth_payload_timeout_fops,
1126               auth_payload_timeout_get,
1127               auth_payload_timeout_set, "%llu\n");
1128 
1129 static ssize_t force_no_mitm_read(struct file *file,
1130                   char __user *user_buf,
1131                   size_t count, loff_t *ppos)
1132 {
1133     struct hci_dev *hdev = file->private_data;
1134     char buf[3];
1135 
1136     buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_NO_MITM) ? 'Y' : 'N';
1137     buf[1] = '\n';
1138     buf[2] = '\0';
1139     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1140 }
1141 
1142 static ssize_t force_no_mitm_write(struct file *file,
1143                    const char __user *user_buf,
1144                    size_t count, loff_t *ppos)
1145 {
1146     struct hci_dev *hdev = file->private_data;
1147     char buf[32];
1148     size_t buf_size = min(count, (sizeof(buf) - 1));
1149     bool enable;
1150 
1151     if (copy_from_user(buf, user_buf, buf_size))
1152         return -EFAULT;
1153 
1154     buf[buf_size] = '\0';
1155     if (strtobool(buf, &enable))
1156         return -EINVAL;
1157 
1158     if (enable == hci_dev_test_flag(hdev, HCI_FORCE_NO_MITM))
1159         return -EALREADY;
1160 
1161     hci_dev_change_flag(hdev, HCI_FORCE_NO_MITM);
1162 
1163     return count;
1164 }
1165 
1166 static const struct file_operations force_no_mitm_fops = {
1167     .open       = simple_open,
1168     .read       = force_no_mitm_read,
1169     .write      = force_no_mitm_write,
1170     .llseek     = default_llseek,
1171 };
1172 
1173 DEFINE_QUIRK_ATTRIBUTE(quirk_strict_duplicate_filter,
1174                HCI_QUIRK_STRICT_DUPLICATE_FILTER);
1175 DEFINE_QUIRK_ATTRIBUTE(quirk_simultaneous_discovery,
1176                HCI_QUIRK_SIMULTANEOUS_DISCOVERY);
1177 
1178 void hci_debugfs_create_le(struct hci_dev *hdev)
1179 {
1180     debugfs_create_file("identity", 0400, hdev->debugfs, hdev,
1181                 &identity_fops);
1182     debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev,
1183                 &rpa_timeout_fops);
1184     debugfs_create_file("random_address", 0444, hdev->debugfs, hdev,
1185                 &random_address_fops);
1186     debugfs_create_file("static_address", 0444, hdev->debugfs, hdev,
1187                 &static_address_fops);
1188 
1189     /* For controllers with a public address, provide a debug
1190      * option to force the usage of the configured static
1191      * address. By default the public address is used.
1192      */
1193     if (bacmp(&hdev->bdaddr, BDADDR_ANY))
1194         debugfs_create_file("force_static_address", 0644,
1195                     hdev->debugfs, hdev,
1196                     &force_static_address_fops);
1197 
1198     debugfs_create_u8("white_list_size", 0444, hdev->debugfs,
1199               &hdev->le_accept_list_size);
1200     debugfs_create_file("white_list", 0444, hdev->debugfs, hdev,
1201                 &white_list_fops);
1202     debugfs_create_u8("resolv_list_size", 0444, hdev->debugfs,
1203               &hdev->le_resolv_list_size);
1204     debugfs_create_file("resolv_list", 0444, hdev->debugfs, hdev,
1205                 &resolv_list_fops);
1206     debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs,
1207                 hdev, &identity_resolving_keys_fops);
1208     debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev,
1209                 &long_term_keys_fops);
1210     debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev,
1211                 &conn_min_interval_fops);
1212     debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev,
1213                 &conn_max_interval_fops);
1214     debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev,
1215                 &conn_latency_fops);
1216     debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev,
1217                 &supervision_timeout_fops);
1218     debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev,
1219                 &adv_channel_map_fops);
1220     debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev,
1221                 &adv_min_interval_fops);
1222     debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev,
1223                 &adv_max_interval_fops);
1224     debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs,
1225                &hdev->discov_interleaved_timeout);
1226     debugfs_create_file("min_key_size", 0644, hdev->debugfs, hdev,
1227                 &min_key_size_fops);
1228     debugfs_create_file("max_key_size", 0644, hdev->debugfs, hdev,
1229                 &max_key_size_fops);
1230     debugfs_create_file("auth_payload_timeout", 0644, hdev->debugfs, hdev,
1231                 &auth_payload_timeout_fops);
1232     debugfs_create_file("force_no_mitm", 0644, hdev->debugfs, hdev,
1233                 &force_no_mitm_fops);
1234 
1235     debugfs_create_file("quirk_strict_duplicate_filter", 0644,
1236                 hdev->debugfs, hdev,
1237                 &quirk_strict_duplicate_filter_fops);
1238     debugfs_create_file("quirk_simultaneous_discovery", 0644,
1239                 hdev->debugfs, hdev,
1240                 &quirk_simultaneous_discovery_fops);
1241 }
1242 
1243 void hci_debugfs_create_conn(struct hci_conn *conn)
1244 {
1245     struct hci_dev *hdev = conn->hdev;
1246     char name[6];
1247 
1248     if (IS_ERR_OR_NULL(hdev->debugfs))
1249         return;
1250 
1251     snprintf(name, sizeof(name), "%u", conn->handle);
1252     conn->debugfs = debugfs_create_dir(name, hdev->debugfs);
1253 }
1254 
1255 static ssize_t dut_mode_read(struct file *file, char __user *user_buf,
1256                  size_t count, loff_t *ppos)
1257 {
1258     struct hci_dev *hdev = file->private_data;
1259     char buf[3];
1260 
1261     buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? 'Y' : 'N';
1262     buf[1] = '\n';
1263     buf[2] = '\0';
1264     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1265 }
1266 
1267 static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,
1268                   size_t count, loff_t *ppos)
1269 {
1270     struct hci_dev *hdev = file->private_data;
1271     struct sk_buff *skb;
1272     bool enable;
1273     int err;
1274 
1275     if (!test_bit(HCI_UP, &hdev->flags))
1276         return -ENETDOWN;
1277 
1278     err = kstrtobool_from_user(user_buf, count, &enable);
1279     if (err)
1280         return err;
1281 
1282     if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE))
1283         return -EALREADY;
1284 
1285     hci_req_sync_lock(hdev);
1286     if (enable)
1287         skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL,
1288                      HCI_CMD_TIMEOUT);
1289     else
1290         skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
1291                      HCI_CMD_TIMEOUT);
1292     hci_req_sync_unlock(hdev);
1293 
1294     if (IS_ERR(skb))
1295         return PTR_ERR(skb);
1296 
1297     kfree_skb(skb);
1298 
1299     hci_dev_change_flag(hdev, HCI_DUT_MODE);
1300 
1301     return count;
1302 }
1303 
1304 static const struct file_operations dut_mode_fops = {
1305     .open       = simple_open,
1306     .read       = dut_mode_read,
1307     .write      = dut_mode_write,
1308     .llseek     = default_llseek,
1309 };
1310 
1311 static ssize_t vendor_diag_read(struct file *file, char __user *user_buf,
1312                 size_t count, loff_t *ppos)
1313 {
1314     struct hci_dev *hdev = file->private_data;
1315     char buf[3];
1316 
1317     buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N';
1318     buf[1] = '\n';
1319     buf[2] = '\0';
1320     return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
1321 }
1322 
1323 static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf,
1324                  size_t count, loff_t *ppos)
1325 {
1326     struct hci_dev *hdev = file->private_data;
1327     bool enable;
1328     int err;
1329 
1330     err = kstrtobool_from_user(user_buf, count, &enable);
1331     if (err)
1332         return err;
1333 
1334     /* When the diagnostic flags are not persistent and the transport
1335      * is not active or in user channel operation, then there is no need
1336      * for the vendor callback. Instead just store the desired value and
1337      * the setting will be programmed when the controller gets powered on.
1338      */
1339     if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) &&
1340         (!test_bit(HCI_RUNNING, &hdev->flags) ||
1341          hci_dev_test_flag(hdev, HCI_USER_CHANNEL)))
1342         goto done;
1343 
1344     hci_req_sync_lock(hdev);
1345     err = hdev->set_diag(hdev, enable);
1346     hci_req_sync_unlock(hdev);
1347 
1348     if (err < 0)
1349         return err;
1350 
1351 done:
1352     if (enable)
1353         hci_dev_set_flag(hdev, HCI_VENDOR_DIAG);
1354     else
1355         hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG);
1356 
1357     return count;
1358 }
1359 
1360 static const struct file_operations vendor_diag_fops = {
1361     .open       = simple_open,
1362     .read       = vendor_diag_read,
1363     .write      = vendor_diag_write,
1364     .llseek     = default_llseek,
1365 };
1366 
1367 void hci_debugfs_create_basic(struct hci_dev *hdev)
1368 {
1369     debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev,
1370                 &dut_mode_fops);
1371 
1372     if (hdev->set_diag)
1373         debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev,
1374                     &vendor_diag_fops);
1375 }