Skip to content

Commit 8249331

Browse files
Claire Changholtmann
authored andcommitted
Bluetooth: Move force_bredr_smp debugfs into hci_debugfs_create_bredr
Avoid multiple attempts to create the debugfs entry, force_bredr_smp, by moving it from the SMP registration to the BR/EDR controller init section. hci_debugfs_create_bredr is only called when HCI_SETUP and HCI_CONFIG is not set. Signed-off-by: Claire Chang <[email protected]> Reviewed-by: Alain Michaud <[email protected]> Reviewed-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 1fb17df commit 8249331

File tree

3 files changed

+54
-42
lines changed

3 files changed

+54
-42
lines changed

net/bluetooth/hci_debugfs.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,45 @@ static int auto_accept_delay_get(void *data, u64 *val)
494494
DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
495495
auto_accept_delay_set, "%llu\n");
496496

497+
static ssize_t force_bredr_smp_read(struct file *file,
498+
char __user *user_buf,
499+
size_t count, loff_t *ppos)
500+
{
501+
struct hci_dev *hdev = file->private_data;
502+
char buf[3];
503+
504+
buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y' : 'N';
505+
buf[1] = '\n';
506+
buf[2] = '\0';
507+
return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
508+
}
509+
510+
static ssize_t force_bredr_smp_write(struct file *file,
511+
const char __user *user_buf,
512+
size_t count, loff_t *ppos)
513+
{
514+
struct hci_dev *hdev = file->private_data;
515+
bool enable;
516+
int err;
517+
518+
err = kstrtobool_from_user(user_buf, count, &enable);
519+
if (err)
520+
return err;
521+
522+
err = smp_force_bredr(hdev, enable);
523+
if (err)
524+
return err;
525+
526+
return count;
527+
}
528+
529+
static const struct file_operations force_bredr_smp_fops = {
530+
.open = simple_open,
531+
.read = force_bredr_smp_read,
532+
.write = force_bredr_smp_write,
533+
.llseek = default_llseek,
534+
};
535+
497536
static int idle_timeout_set(void *data, u64 val)
498537
{
499538
struct hci_dev *hdev = data;
@@ -589,6 +628,17 @@ void hci_debugfs_create_bredr(struct hci_dev *hdev)
589628
debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev,
590629
&voice_setting_fops);
591630

631+
/* If the controller does not support BR/EDR Secure Connections
632+
* feature, then the BR/EDR SMP channel shall not be present.
633+
*
634+
* To test this with Bluetooth 4.0 controllers, create a debugfs
635+
* switch that allows forcing BR/EDR SMP support and accepting
636+
* cross-transport pairing on non-AES encrypted connections.
637+
*/
638+
if (!lmp_sc_capable(hdev))
639+
debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs,
640+
hdev, &force_bredr_smp_fops);
641+
592642
if (lmp_ssp_capable(hdev)) {
593643
debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
594644
hdev, &ssp_debug_mode_fops);

net/bluetooth/smp.c

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,31 +3353,8 @@ static void smp_del_chan(struct l2cap_chan *chan)
33533353
l2cap_chan_put(chan);
33543354
}
33553355

3356-
static ssize_t force_bredr_smp_read(struct file *file,
3357-
char __user *user_buf,
3358-
size_t count, loff_t *ppos)
3356+
int smp_force_bredr(struct hci_dev *hdev, bool enable)
33593357
{
3360-
struct hci_dev *hdev = file->private_data;
3361-
char buf[3];
3362-
3363-
buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y': 'N';
3364-
buf[1] = '\n';
3365-
buf[2] = '\0';
3366-
return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
3367-
}
3368-
3369-
static ssize_t force_bredr_smp_write(struct file *file,
3370-
const char __user *user_buf,
3371-
size_t count, loff_t *ppos)
3372-
{
3373-
struct hci_dev *hdev = file->private_data;
3374-
bool enable;
3375-
int err;
3376-
3377-
err = kstrtobool_from_user(user_buf, count, &enable);
3378-
if (err)
3379-
return err;
3380-
33813358
if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP))
33823359
return -EALREADY;
33833360

@@ -3399,16 +3376,9 @@ static ssize_t force_bredr_smp_write(struct file *file,
33993376

34003377
hci_dev_change_flag(hdev, HCI_FORCE_BREDR_SMP);
34013378

3402-
return count;
3379+
return 0;
34033380
}
34043381

3405-
static const struct file_operations force_bredr_smp_fops = {
3406-
.open = simple_open,
3407-
.read = force_bredr_smp_read,
3408-
.write = force_bredr_smp_write,
3409-
.llseek = default_llseek,
3410-
};
3411-
34123382
int smp_register(struct hci_dev *hdev)
34133383
{
34143384
struct l2cap_chan *chan;
@@ -3433,17 +3403,7 @@ int smp_register(struct hci_dev *hdev)
34333403

34343404
hdev->smp_data = chan;
34353405

3436-
/* If the controller does not support BR/EDR Secure Connections
3437-
* feature, then the BR/EDR SMP channel shall not be present.
3438-
*
3439-
* To test this with Bluetooth 4.0 controllers, create a debugfs
3440-
* switch that allows forcing BR/EDR SMP support and accepting
3441-
* cross-transport pairing on non-AES encrypted connections.
3442-
*/
34433406
if (!lmp_sc_capable(hdev)) {
3444-
debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs,
3445-
hdev, &force_bredr_smp_fops);
3446-
34473407
/* Flag can be already set here (due to power toggle) */
34483408
if (!hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP))
34493409
return 0;

net/bluetooth/smp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ bool smp_irk_matches(struct hci_dev *hdev, const u8 irk[16],
193193
int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa);
194194
int smp_generate_oob(struct hci_dev *hdev, u8 hash[16], u8 rand[16]);
195195

196+
int smp_force_bredr(struct hci_dev *hdev, bool enable);
197+
196198
int smp_register(struct hci_dev *hdev);
197199
void smp_unregister(struct hci_dev *hdev);
198200

0 commit comments

Comments
 (0)