Bluetooth: Convert hci_conn->link_mode into flags
Since the link_mode member of the hci_conn struct is a bit field and we already have a flags member as well it makes sense to merge these two together. This patch moves all used link_mode bits into corresponding flags. To keep backwards compatibility with user space we still need to provide a get_link_mode() helper function for the ioctl's that expect a link_mode style value. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
This commit is contained in:
parent
70775dca2a
commit
6cf656a667
|
@ -324,7 +324,6 @@ struct hci_conn {
|
|||
__u16 interval;
|
||||
__u16 pkt_type;
|
||||
__u16 link_policy;
|
||||
__u32 link_mode;
|
||||
__u8 key_type;
|
||||
__u8 auth_type;
|
||||
__u8 sec_level;
|
||||
|
@ -451,6 +450,10 @@ enum {
|
|||
HCI_CONN_SSP_ENABLED,
|
||||
HCI_CONN_POWER_SAVE,
|
||||
HCI_CONN_REMOTE_OOB,
|
||||
HCI_CONN_MASTER,
|
||||
HCI_CONN_ENCRYPT,
|
||||
HCI_CONN_AUTH,
|
||||
HCI_CONN_SECURE,
|
||||
};
|
||||
|
||||
static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
|
||||
|
@ -922,7 +925,7 @@ static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
|
|||
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
|
||||
return;
|
||||
|
||||
encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
|
||||
encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
|
||||
l2cap_security_cfm(conn, status, encrypt);
|
||||
|
||||
if (conn->security_cfm_cb)
|
||||
|
@ -963,7 +966,7 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
|
|||
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
|
||||
return;
|
||||
|
||||
encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
|
||||
encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
|
||||
|
||||
read_lock(&hci_cb_list_lock);
|
||||
list_for_each_entry(cb, &hci_cb_list, list) {
|
||||
|
|
|
@ -39,7 +39,7 @@ static void hci_le_create_connection(struct hci_conn *conn)
|
|||
|
||||
conn->state = BT_CONNECT;
|
||||
conn->out = true;
|
||||
conn->link_mode |= HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
conn->sec_level = BT_SECURITY_LOW;
|
||||
|
||||
memset(&cp, 0, sizeof(cp));
|
||||
|
@ -72,7 +72,7 @@ static void hci_acl_create_connection(struct hci_conn *conn)
|
|||
conn->state = BT_CONNECT;
|
||||
conn->out = true;
|
||||
|
||||
conn->link_mode = HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
|
||||
conn->attempt++;
|
||||
|
||||
|
@ -664,7 +664,8 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
|
|||
{
|
||||
BT_DBG("hcon %pK", conn);
|
||||
|
||||
if (hci_conn_ssp_enabled(conn) && !(conn->link_mode & HCI_LM_ENCRYPT))
|
||||
if (hci_conn_ssp_enabled(conn) &&
|
||||
!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
||||
return 0;
|
||||
|
||||
/* The minimum encryption key size needs to be enforced by the
|
||||
|
@ -688,7 +689,7 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
|
|||
|
||||
if (sec_level > conn->sec_level)
|
||||
conn->pending_sec_level = sec_level;
|
||||
else if (conn->link_mode & HCI_LM_AUTH)
|
||||
else if (test_bit(HCI_CONN_AUTH, &conn->flags))
|
||||
return 1;
|
||||
|
||||
/* Make sure we preserve an existing MITM requirement*/
|
||||
|
@ -706,7 +707,7 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
|
|||
/* If we're already encrypted set the REAUTH_PEND flag,
|
||||
* otherwise set the ENCRYPT_PEND.
|
||||
*/
|
||||
if (conn->link_mode & HCI_LM_ENCRYPT)
|
||||
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
||||
set_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
|
||||
else
|
||||
set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
|
||||
|
@ -747,7 +748,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
|
|||
return 1;
|
||||
|
||||
/* For other security levels we need the link key. */
|
||||
if (!(conn->link_mode & HCI_LM_AUTH))
|
||||
if (!test_bit(HCI_CONN_AUTH, &conn->flags))
|
||||
goto auth;
|
||||
|
||||
/* An authenticated combination key has sufficient security for any
|
||||
|
@ -777,7 +778,7 @@ auth:
|
|||
return 0;
|
||||
|
||||
encrypt:
|
||||
if (conn->link_mode & HCI_LM_ENCRYPT)
|
||||
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
||||
return 1;
|
||||
|
||||
hci_conn_encrypt(conn);
|
||||
|
@ -820,7 +821,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role)
|
|||
{
|
||||
BT_DBG("hcon %pK", conn);
|
||||
|
||||
if (!role && conn->link_mode & HCI_LM_MASTER)
|
||||
if (!role && test_bit(HCI_CONN_MASTER, &conn->flags))
|
||||
return 1;
|
||||
|
||||
if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) {
|
||||
|
@ -915,6 +916,25 @@ void hci_conn_check_pending(struct hci_dev *hdev)
|
|||
hci_dev_unlock(hdev);
|
||||
}
|
||||
|
||||
static u32 get_link_mode(struct hci_conn *conn)
|
||||
{
|
||||
u32 link_mode = 0;
|
||||
|
||||
if (test_bit(HCI_CONN_MASTER, &conn->flags))
|
||||
link_mode |= HCI_LM_MASTER;
|
||||
|
||||
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
||||
link_mode |= HCI_LM_ENCRYPT;
|
||||
|
||||
if (test_bit(HCI_CONN_AUTH, &conn->flags))
|
||||
link_mode |= HCI_LM_AUTH;
|
||||
|
||||
if (test_bit(HCI_CONN_SECURE, &conn->flags))
|
||||
link_mode |= HCI_LM_SECURE;
|
||||
|
||||
return link_mode;
|
||||
}
|
||||
|
||||
int hci_get_conn_list(void __user *arg)
|
||||
{
|
||||
struct hci_conn *c;
|
||||
|
@ -950,7 +970,7 @@ int hci_get_conn_list(void __user *arg)
|
|||
(ci + n)->type = c->type;
|
||||
(ci + n)->out = c->out;
|
||||
(ci + n)->state = c->state;
|
||||
(ci + n)->link_mode = c->link_mode;
|
||||
(ci + n)->link_mode = get_link_mode(c);
|
||||
if (c->type == SCO_LINK) {
|
||||
(ci + n)->mtu = hdev->sco_mtu;
|
||||
(ci + n)->cnt = hdev->sco_cnt;
|
||||
|
@ -995,7 +1015,7 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg)
|
|||
ci.type = conn->type;
|
||||
ci.out = conn->out;
|
||||
ci.state = conn->state;
|
||||
ci.link_mode = conn->link_mode;
|
||||
ci.link_mode = get_link_mode(conn);
|
||||
if (req.type == SCO_LINK) {
|
||||
ci.mtu = hdev->sco_mtu;
|
||||
ci.cnt = hdev->sco_cnt;
|
||||
|
|
|
@ -105,9 +105,9 @@ static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
|
||||
if (conn) {
|
||||
if (rp->role)
|
||||
conn->link_mode &= ~HCI_LM_MASTER;
|
||||
clear_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
else
|
||||
conn->link_mode |= HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
}
|
||||
|
||||
hci_dev_unlock(hdev);
|
||||
|
@ -1122,7 +1122,7 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
|
|||
conn = hci_conn_add(hdev, ACL_LINK, 0, &cp->bdaddr);
|
||||
if (conn) {
|
||||
conn->out = true;
|
||||
conn->link_mode |= HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
} else
|
||||
BT_ERR("No memory for new connection");
|
||||
}
|
||||
|
@ -1705,10 +1705,10 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
hci_conn_add_sysfs(conn);
|
||||
|
||||
if (test_bit(HCI_AUTH, &hdev->flags))
|
||||
conn->link_mode |= HCI_LM_AUTH;
|
||||
set_bit(HCI_CONN_AUTH, &conn->flags);
|
||||
|
||||
if (test_bit(HCI_ENCRYPT, &hdev->flags))
|
||||
conn->link_mode |= HCI_LM_ENCRYPT;
|
||||
set_bit(HCI_CONN_ENCRYPT, &conn->flags);
|
||||
|
||||
/* Get remote features */
|
||||
if (conn->type == ACL_LINK) {
|
||||
|
@ -1918,7 +1918,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
|
||||
BT_INFO("re-auth of legacy device is not possible.");
|
||||
} else {
|
||||
conn->link_mode |= HCI_LM_AUTH;
|
||||
set_bit(HCI_CONN_AUTH, &conn->flags);
|
||||
conn->sec_level = conn->pending_sec_level;
|
||||
}
|
||||
} else {
|
||||
|
@ -2019,11 +2019,11 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
if (!ev->status) {
|
||||
if (ev->encrypt) {
|
||||
/* Encryption implies authentication */
|
||||
conn->link_mode |= HCI_LM_AUTH;
|
||||
conn->link_mode |= HCI_LM_ENCRYPT;
|
||||
set_bit(HCI_CONN_AUTH, &conn->flags);
|
||||
set_bit(HCI_CONN_ENCRYPT, &conn->flags);
|
||||
conn->sec_level = conn->pending_sec_level;
|
||||
} else
|
||||
conn->link_mode &= ~HCI_LM_ENCRYPT;
|
||||
clear_bit(HCI_CONN_ENCRYPT, &conn->flags);
|
||||
}
|
||||
|
||||
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
|
||||
|
@ -2061,7 +2061,7 @@ static void hci_change_link_key_complete_evt(struct hci_dev *hdev,
|
|||
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
|
||||
if (conn) {
|
||||
if (!ev->status)
|
||||
conn->link_mode |= HCI_LM_SECURE;
|
||||
set_bit(HCI_CONN_SECURE, &conn->flags);
|
||||
|
||||
clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
|
||||
|
||||
|
@ -2462,9 +2462,9 @@ static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
if (conn) {
|
||||
if (!ev->status) {
|
||||
if (ev->role)
|
||||
conn->link_mode &= ~HCI_LM_MASTER;
|
||||
clear_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
else
|
||||
conn->link_mode |= HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
}
|
||||
|
||||
clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
|
||||
|
@ -3580,7 +3580,7 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
|
|||
|
||||
if (ev->role == LE_CONN_ROLE_MASTER) {
|
||||
conn->out = true;
|
||||
conn->link_mode |= HCI_LM_MASTER;
|
||||
set_bit(HCI_CONN_MASTER, &conn->flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5242,7 +5242,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
|
|||
u16 min, max, latency, to_multiplier, cmd_len;
|
||||
int err;
|
||||
|
||||
if (!(hcon->link_mode & HCI_LM_MASTER))
|
||||
if (!test_bit(HCI_CONN_MASTER, &hcon->flags))
|
||||
return -EINVAL;
|
||||
|
||||
cmd_len = __le16_to_cpu(cmd->len);
|
||||
|
|
|
@ -333,7 +333,7 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
|
|||
* Confirms and the slave Enters the passkey.
|
||||
*/
|
||||
if (method == OVERLAP) {
|
||||
if (hcon->link_mode & HCI_LM_MASTER)
|
||||
if (test_bit(HCI_CONN_MASTER, &hcon->flags))
|
||||
method = CFM_PASSKEY;
|
||||
else
|
||||
method = REQ_PASSKEY;
|
||||
|
@ -576,7 +576,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
|
|||
|
||||
BT_DBG("conn %pK", conn);
|
||||
|
||||
if (conn->hcon->link_mode & HCI_LM_MASTER)
|
||||
if (test_bit(HCI_CONN_MASTER, &conn->hcon->flags))
|
||||
return SMP_CMD_NOTSUPP;
|
||||
|
||||
if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags))
|
||||
|
@ -630,7 +630,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
|
|||
|
||||
BT_DBG("conn %pK", conn);
|
||||
|
||||
if (!(conn->hcon->link_mode & HCI_LM_MASTER))
|
||||
if (!test_bit(HCI_CONN_MASTER, &conn->hcon->flags))
|
||||
return SMP_CMD_NOTSUPP;
|
||||
|
||||
skb_pull(skb, sizeof(*rsp));
|
||||
|
@ -801,7 +801,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
|
|||
if (hcon->sec_level >= sec_level)
|
||||
return 1;
|
||||
|
||||
if (hcon->link_mode & HCI_LM_MASTER)
|
||||
if (test_bit(HCI_CONN_MASTER, &hcon->flags))
|
||||
if (smp_ltk_encrypt(conn, sec_level))
|
||||
goto done;
|
||||
|
||||
|
@ -814,7 +814,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
|
|||
|
||||
authreq = seclevel_to_authreq(sec_level);
|
||||
|
||||
if (hcon->link_mode & HCI_LM_MASTER) {
|
||||
if (test_bit(HCI_CONN_MASTER, &hcon->flags)) {
|
||||
struct smp_cmd_pairing cp;
|
||||
|
||||
build_pairing_cmd(conn, &cp, NULL, authreq);
|
||||
|
|
Loading…
Reference in New Issue