Skip to content

Commit 4d9b952

Browse files
dwinkler2Johan Hedberg
authored andcommitted
Bluetooth: Change MGMT security info CMD to be more generic
For advertising, we wish to know the LE tx power capabilities of the controller in userspace, so this patch edits the Security Info MGMT command to be more generic, such that other various controller capabilities can be included in the EIR data. This change also includes the LE min and max tx power into this newly-named command. The change was tested by manually verifying that the MGMT command returns the tx power range as expected in userspace. Reviewed-by: Sonny Sasaka <[email protected]> Signed-off-by: Daniel Winkler <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent 7c395ea commit 4d9b952

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

include/net/bluetooth/mgmt.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,16 @@ struct mgmt_cp_set_blocked_keys {
686686

687687
#define MGMT_OP_SET_WIDEBAND_SPEECH 0x0047
688688

689-
#define MGMT_OP_READ_SECURITY_INFO 0x0048
690-
#define MGMT_READ_SECURITY_INFO_SIZE 0
691-
struct mgmt_rp_read_security_info {
692-
__le16 sec_len;
693-
__u8 sec[];
689+
#define MGMT_CAP_SEC_FLAGS 0x01
690+
#define MGMT_CAP_MAX_ENC_KEY_SIZE 0x02
691+
#define MGMT_CAP_SMP_MAX_ENC_KEY_SIZE 0x03
692+
#define MGMT_CAP_LE_TX_PWR 0x04
693+
694+
#define MGMT_OP_READ_CONTROLLER_CAP 0x0048
695+
#define MGMT_READ_CONTROLLER_CAP_SIZE 0
696+
struct mgmt_rp_read_controller_cap {
697+
__le16 cap_len;
698+
__u8 cap[0];
694699
} __packed;
695700

696701
#define MGMT_OP_READ_EXP_FEATURES_INFO 0x0049

net/bluetooth/mgmt.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static const u16 mgmt_commands[] = {
110110
MGMT_OP_SET_APPEARANCE,
111111
MGMT_OP_SET_BLOCKED_KEYS,
112112
MGMT_OP_SET_WIDEBAND_SPEECH,
113-
MGMT_OP_READ_SECURITY_INFO,
113+
MGMT_OP_READ_CONTROLLER_CAP,
114114
MGMT_OP_READ_EXP_FEATURES_INFO,
115115
MGMT_OP_SET_EXP_FEATURE,
116116
MGMT_OP_READ_DEF_SYSTEM_CONFIG,
@@ -176,7 +176,7 @@ static const u16 mgmt_untrusted_commands[] = {
176176
MGMT_OP_READ_CONFIG_INFO,
177177
MGMT_OP_READ_EXT_INDEX_LIST,
178178
MGMT_OP_READ_EXT_INFO,
179-
MGMT_OP_READ_SECURITY_INFO,
179+
MGMT_OP_READ_CONTROLLER_CAP,
180180
MGMT_OP_READ_EXP_FEATURES_INFO,
181181
MGMT_OP_READ_DEF_SYSTEM_CONFIG,
182182
MGMT_OP_READ_DEF_RUNTIME_CONFIG,
@@ -3710,13 +3710,14 @@ static int set_wideband_speech(struct sock *sk, struct hci_dev *hdev,
37103710
return err;
37113711
}
37123712

3713-
static int read_security_info(struct sock *sk, struct hci_dev *hdev,
3714-
void *data, u16 data_len)
3713+
static int read_controller_cap(struct sock *sk, struct hci_dev *hdev,
3714+
void *data, u16 data_len)
37153715
{
3716-
char buf[16];
3717-
struct mgmt_rp_read_security_info *rp = (void *)buf;
3718-
u16 sec_len = 0;
3716+
char buf[20];
3717+
struct mgmt_rp_read_controller_cap *rp = (void *)buf;
3718+
u16 cap_len = 0;
37193719
u8 flags = 0;
3720+
u8 tx_power_range[2];
37203721

37213722
bt_dev_dbg(hdev, "sock %p", sk);
37223723

@@ -3740,23 +3741,37 @@ static int read_security_info(struct sock *sk, struct hci_dev *hdev,
37403741

37413742
flags |= 0x08; /* Encryption key size enforcement (LE) */
37423743

3743-
sec_len = eir_append_data(rp->sec, sec_len, 0x01, &flags, 1);
3744+
cap_len = eir_append_data(rp->cap, cap_len, MGMT_CAP_SEC_FLAGS,
3745+
&flags, 1);
37443746

37453747
/* When the Read Simple Pairing Options command is supported, then
37463748
* also max encryption key size information is provided.
37473749
*/
37483750
if (hdev->commands[41] & 0x08)
3749-
sec_len = eir_append_le16(rp->sec, sec_len, 0x02,
3751+
cap_len = eir_append_le16(rp->cap, cap_len,
3752+
MGMT_CAP_MAX_ENC_KEY_SIZE,
37503753
hdev->max_enc_key_size);
37513754

3752-
sec_len = eir_append_le16(rp->sec, sec_len, 0x03, SMP_MAX_ENC_KEY_SIZE);
3755+
cap_len = eir_append_le16(rp->cap, cap_len,
3756+
MGMT_CAP_SMP_MAX_ENC_KEY_SIZE,
3757+
SMP_MAX_ENC_KEY_SIZE);
3758+
3759+
/* Append the min/max LE tx power parameters if we were able to fetch
3760+
* it from the controller
3761+
*/
3762+
if (hdev->commands[38] & 0x80) {
3763+
memcpy(&tx_power_range[0], &hdev->min_le_tx_power, 1);
3764+
memcpy(&tx_power_range[1], &hdev->max_le_tx_power, 1);
3765+
cap_len = eir_append_data(rp->cap, cap_len, MGMT_CAP_LE_TX_PWR,
3766+
tx_power_range, 2);
3767+
}
37533768

3754-
rp->sec_len = cpu_to_le16(sec_len);
3769+
rp->cap_len = cpu_to_le16(cap_len);
37553770

37563771
hci_dev_unlock(hdev);
37573772

3758-
return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_SECURITY_INFO, 0,
3759-
rp, sizeof(*rp) + sec_len);
3773+
return mgmt_cmd_complete(sk, hdev->id, MGMT_OP_READ_CONTROLLER_CAP, 0,
3774+
rp, sizeof(*rp) + cap_len);
37603775
}
37613776

37623777
#ifdef CONFIG_BT_FEATURE_DEBUG
@@ -8193,7 +8208,7 @@ static const struct hci_mgmt_handler mgmt_handlers[] = {
81938208
{ set_blocked_keys, MGMT_OP_SET_BLOCKED_KEYS_SIZE,
81948209
HCI_MGMT_VAR_LEN },
81958210
{ set_wideband_speech, MGMT_SETTING_SIZE },
8196-
{ read_security_info, MGMT_READ_SECURITY_INFO_SIZE,
8211+
{ read_controller_cap, MGMT_READ_CONTROLLER_CAP_SIZE,
81978212
HCI_MGMT_UNTRUSTED },
81988213
{ read_exp_features_info, MGMT_READ_EXP_FEATURES_INFO_SIZE,
81998214
HCI_MGMT_UNTRUSTED |

0 commit comments

Comments
 (0)