提交 b1f663c9 编写于 作者: J Johan Hedberg 提交者: Marcel Holtmann

Bluetooth: Add debugfs support for min LE encryption key size

This patch adds a debugfs control to set a different minimum LE
encryption key size. This is useful for testing that implementation of
the encryption key size handling is behaving correctly (e.g. that we
get appropriate 'Encryption Key Size' error responses when necessary).
Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 2fd36558
......@@ -84,6 +84,7 @@ struct smp_dev {
u8 local_rand[16];
bool debug_key;
u8 min_key_size;
u8 max_key_size;
struct crypto_blkcipher *tfm_aes;
......@@ -3136,6 +3137,7 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)
smp->tfm_aes = tfm_aes;
smp->tfm_cmac = tfm_cmac;
smp->min_key_size = SMP_MIN_ENC_KEY_SIZE;
smp->max_key_size = SMP_MAX_ENC_KEY_SIZE;
create_chan:
......@@ -3259,6 +3261,50 @@ static const struct file_operations force_bredr_smp_fops = {
.llseek = default_llseek,
};
static ssize_t le_min_key_size_read(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
struct hci_dev *hdev = file->private_data;
char buf[4];
snprintf(buf, sizeof(buf), "%2u\n", SMP_DEV(hdev)->min_key_size);
return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
}
static ssize_t le_min_key_size_write(struct file *file,
const char __user *user_buf,
size_t count, loff_t *ppos)
{
struct hci_dev *hdev = file->private_data;
char buf[32];
size_t buf_size = min(count, (sizeof(buf) - 1));
u8 key_size;
if (copy_from_user(buf, user_buf, buf_size))
return -EFAULT;
buf[buf_size] = '\0';
sscanf(buf, "%hhu", &key_size);
if (key_size > SMP_DEV(hdev)->max_key_size ||
key_size < SMP_MIN_ENC_KEY_SIZE)
return -EINVAL;
SMP_DEV(hdev)->min_key_size = key_size;
return count;
}
static const struct file_operations le_min_key_size_fops = {
.open = simple_open,
.read = le_min_key_size_read,
.write = le_min_key_size_write,
.llseek = default_llseek,
};
static ssize_t le_max_key_size_read(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
......@@ -3287,7 +3333,8 @@ static ssize_t le_max_key_size_write(struct file *file,
sscanf(buf, "%hhu", &key_size);
if (key_size > SMP_MAX_ENC_KEY_SIZE || key_size < SMP_MIN_ENC_KEY_SIZE)
if (key_size > SMP_MAX_ENC_KEY_SIZE ||
key_size < SMP_DEV(hdev)->min_key_size)
return -EINVAL;
SMP_DEV(hdev)->max_key_size = key_size;
......@@ -3326,6 +3373,8 @@ int smp_register(struct hci_dev *hdev)
hdev->smp_data = chan;
debugfs_create_file("le_min_key_size", 0644, hdev->debugfs, hdev,
&le_min_key_size_fops);
debugfs_create_file("le_max_key_size", 0644, hdev->debugfs, hdev,
&le_max_key_size_fops);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册