Skip to content

Commit 58a96fc

Browse files
holtmannjhedberg
authored andcommitted
Bluetooth: Add debug setting for changing minimum encryption key size
For testing and qualification purposes it is useful to allow changing the minimum encryption key size value that the host stack is going to enforce. This adds a new debugfs setting min_encrypt_key_size to achieve this functionality. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 6600c08 commit 58a96fc

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ struct hci_dev {
278278
__u16 conn_info_min_age;
279279
__u16 conn_info_max_age;
280280
__u16 auth_payload_timeout;
281+
__u8 min_enc_key_size;
281282
__u8 ssp_debug_mode;
282283
__u8 hw_error_code;
283284
__u32 clock;

‎net/bluetooth/hci_core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,7 @@ struct hci_dev *hci_alloc_dev(void)
32023202
hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE;
32033203
hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE;
32043204
hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
3205+
hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE;
32053206

32063207
mutex_init(&hdev->lock);
32073208
mutex_init(&hdev->req_lock);

‎net/bluetooth/hci_debugfs.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,35 @@ static int auto_accept_delay_set(void *data, u64 val)
433433
return 0;
434434
}
435435

436+
static int min_encrypt_key_size_set(void *data, u64 val)
437+
{
438+
struct hci_dev *hdev = data;
439+
440+
if (val < 1 || val > 16)
441+
return -EINVAL;
442+
443+
hci_dev_lock(hdev);
444+
hdev->min_enc_key_size = val;
445+
hci_dev_unlock(hdev);
446+
447+
return 0;
448+
}
449+
450+
static int min_encrypt_key_size_get(void *data, u64 *val)
451+
{
452+
struct hci_dev *hdev = data;
453+
454+
hci_dev_lock(hdev);
455+
*val = hdev->min_enc_key_size;
456+
hci_dev_unlock(hdev);
457+
458+
return 0;
459+
}
460+
461+
DEFINE_SIMPLE_ATTRIBUTE(min_encrypt_key_size_fops,
462+
min_encrypt_key_size_get,
463+
min_encrypt_key_size_set, "%llu\n");
464+
436465
static int auto_accept_delay_get(void *data, u64 *val)
437466
{
438467
struct hci_dev *hdev = data;
@@ -545,6 +574,8 @@ void hci_debugfs_create_bredr(struct hci_dev *hdev)
545574
if (lmp_ssp_capable(hdev)) {
546575
debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs,
547576
hdev, &ssp_debug_mode_fops);
577+
debugfs_create_file("min_encrypt_key_size", 0644, hdev->debugfs,
578+
hdev, &min_encrypt_key_size_fops);
548579
debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs,
549580
hdev, &auto_accept_delay_fops);
550581
}

‎net/bluetooth/l2cap_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon)
13611361
* actually encrypted before enforcing a key size.
13621362
*/
13631363
return (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags) ||
1364-
hcon->enc_key_size >= HCI_MIN_ENC_KEY_SIZE);
1364+
hcon->enc_key_size >= hcon->hdev->min_enc_key_size);
13651365
}
13661366

13671367
static void l2cap_do_start(struct l2cap_chan *chan)

0 commit comments

Comments
 (0)