diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2014-07-16 04:42:27 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-07-16 05:04:23 -0400 |
commit | 40bef302f6323d1ee6fb3dc0e62edb0f446d0339 (patch) | |
tree | 2b77646a8adf90560b66e7f72df64ab4cc76240e /net | |
parent | ba165a90b59812ab1d9cd2943fd104cfc25c601e (diff) |
Bluetooth: Convert HCI_CONN_MASTER flag to a conn->role variable
Having a dedicated u8 role variable in the hci_conn struct greatly
simplifies tracking of the role, since this is the native way that it's
represented on the HCI level.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/hci_conn.c | 13 | ||||
-rw-r--r-- | net/bluetooth/hci_event.c | 27 | ||||
-rw-r--r-- | net/bluetooth/l2cap_core.c | 4 | ||||
-rw-r--r-- | net/bluetooth/smp.c | 12 |
4 files changed, 23 insertions, 33 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 490ee8846d9e..6c1c5048984c 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c | |||
@@ -66,8 +66,7 @@ static void hci_acl_create_connection(struct hci_conn *conn) | |||
66 | 66 | ||
67 | conn->state = BT_CONNECT; | 67 | conn->state = BT_CONNECT; |
68 | conn->out = true; | 68 | conn->out = true; |
69 | 69 | conn->role = HCI_ROLE_MASTER; | |
70 | set_bit(HCI_CONN_MASTER, &conn->flags); | ||
71 | 70 | ||
72 | conn->attempt++; | 71 | conn->attempt++; |
73 | 72 | ||
@@ -335,7 +334,7 @@ static void hci_conn_timeout(struct work_struct *work) | |||
335 | * event handling and hci_clock_offset_evt function. | 334 | * event handling and hci_clock_offset_evt function. |
336 | */ | 335 | */ |
337 | if (conn->type == ACL_LINK && | 336 | if (conn->type == ACL_LINK && |
338 | test_bit(HCI_CONN_MASTER, &conn->flags)) { | 337 | conn->role == HCI_ROLE_MASTER) { |
339 | struct hci_dev *hdev = conn->hdev; | 338 | struct hci_dev *hdev = conn->hdev; |
340 | struct hci_cp_read_clock_offset cp; | 339 | struct hci_cp_read_clock_offset cp; |
341 | 340 | ||
@@ -786,8 +785,8 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, | |||
786 | goto create_conn; | 785 | goto create_conn; |
787 | } | 786 | } |
788 | 787 | ||
789 | conn->out = true; | 788 | conn->out = true; |
790 | set_bit(HCI_CONN_MASTER, &conn->flags); | 789 | conn->role = HCI_ROLE_MASTER; |
791 | 790 | ||
792 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); | 791 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
793 | if (params) { | 792 | if (params) { |
@@ -1076,7 +1075,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role) | |||
1076 | { | 1075 | { |
1077 | BT_DBG("hcon %p", conn); | 1076 | BT_DBG("hcon %p", conn); |
1078 | 1077 | ||
1079 | if (!role && test_bit(HCI_CONN_MASTER, &conn->flags)) | 1078 | if (role == conn->role) |
1080 | return 1; | 1079 | return 1; |
1081 | 1080 | ||
1082 | if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) { | 1081 | if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) { |
@@ -1151,7 +1150,7 @@ static u32 get_link_mode(struct hci_conn *conn) | |||
1151 | { | 1150 | { |
1152 | u32 link_mode = 0; | 1151 | u32 link_mode = 0; |
1153 | 1152 | ||
1154 | if (test_bit(HCI_CONN_MASTER, &conn->flags)) | 1153 | if (conn->role == HCI_ROLE_MASTER) |
1155 | link_mode |= HCI_LM_MASTER; | 1154 | link_mode |= HCI_LM_MASTER; |
1156 | 1155 | ||
1157 | if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) | 1156 | if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) |
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 13f83c48face..3b1d2dadedc8 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c | |||
@@ -101,12 +101,8 @@ static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) | |||
101 | hci_dev_lock(hdev); | 101 | hci_dev_lock(hdev); |
102 | 102 | ||
103 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); | 103 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
104 | if (conn) { | 104 | if (conn) |
105 | if (rp->role) | 105 | conn->role = rp->role; |
106 | clear_bit(HCI_CONN_MASTER, &conn->flags); | ||
107 | else | ||
108 | set_bit(HCI_CONN_MASTER, &conn->flags); | ||
109 | } | ||
110 | 106 | ||
111 | hci_dev_unlock(hdev); | 107 | hci_dev_unlock(hdev); |
112 | } | 108 | } |
@@ -1420,8 +1416,8 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) | |||
1420 | if (!conn) { | 1416 | if (!conn) { |
1421 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr); | 1417 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr); |
1422 | if (conn) { | 1418 | if (conn) { |
1423 | conn->out = true; | 1419 | conn->out = true; |
1424 | set_bit(HCI_CONN_MASTER, &conn->flags); | 1420 | conn->role = HCI_ROLE_MASTER; |
1425 | } else | 1421 | } else |
1426 | BT_ERR("No memory for new connection"); | 1422 | BT_ERR("No memory for new connection"); |
1427 | } | 1423 | } |
@@ -2924,12 +2920,8 @@ static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) | |||
2924 | 2920 | ||
2925 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | 2921 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
2926 | if (conn) { | 2922 | if (conn) { |
2927 | if (!ev->status) { | 2923 | if (!ev->status) |
2928 | if (ev->role) | 2924 | conn->role = ev->role; |
2929 | clear_bit(HCI_CONN_MASTER, &conn->flags); | ||
2930 | else | ||
2931 | set_bit(HCI_CONN_MASTER, &conn->flags); | ||
2932 | } | ||
2933 | 2925 | ||
2934 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); | 2926 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
2935 | 2927 | ||
@@ -4116,10 +4108,9 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | |||
4116 | 4108 | ||
4117 | conn->dst_type = ev->bdaddr_type; | 4109 | conn->dst_type = ev->bdaddr_type; |
4118 | 4110 | ||
4119 | if (ev->role == HCI_ROLE_MASTER) { | 4111 | conn->role = ev->role; |
4112 | if (conn->role == HCI_ROLE_MASTER) | ||
4120 | conn->out = true; | 4113 | conn->out = true; |
4121 | set_bit(HCI_CONN_MASTER, &conn->flags); | ||
4122 | } | ||
4123 | 4114 | ||
4124 | /* If we didn't have a hci_conn object previously | 4115 | /* If we didn't have a hci_conn object previously |
4125 | * but we're in master role this must be something | 4116 | * but we're in master role this must be something |
@@ -4527,7 +4518,7 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, | |||
4527 | return send_conn_param_neg_reply(hdev, handle, | 4518 | return send_conn_param_neg_reply(hdev, handle, |
4528 | HCI_ERROR_INVALID_LL_PARAMS); | 4519 | HCI_ERROR_INVALID_LL_PARAMS); |
4529 | 4520 | ||
4530 | if (test_bit(HCI_CONN_MASTER, &hcon->flags)) { | 4521 | if (hcon->role == HCI_ROLE_MASTER) { |
4531 | struct hci_conn_params *params; | 4522 | struct hci_conn_params *params; |
4532 | u8 store_hint; | 4523 | u8 store_hint; |
4533 | 4524 | ||
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 8538cb07b0c0..ea68d3219b7e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -1487,7 +1487,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) | |||
1487 | * been configured for this connection. If not, then trigger | 1487 | * been configured for this connection. If not, then trigger |
1488 | * the connection update procedure. | 1488 | * the connection update procedure. |
1489 | */ | 1489 | */ |
1490 | if (!test_bit(HCI_CONN_MASTER, &hcon->flags) && | 1490 | if (hcon->role == HCI_ROLE_SLAVE && |
1491 | (hcon->le_conn_interval < hcon->le_conn_min_interval || | 1491 | (hcon->le_conn_interval < hcon->le_conn_min_interval || |
1492 | hcon->le_conn_interval > hcon->le_conn_max_interval)) { | 1492 | hcon->le_conn_interval > hcon->le_conn_max_interval)) { |
1493 | struct l2cap_conn_param_update_req req; | 1493 | struct l2cap_conn_param_update_req req; |
@@ -5227,7 +5227,7 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn, | |||
5227 | u16 min, max, latency, to_multiplier; | 5227 | u16 min, max, latency, to_multiplier; |
5228 | int err; | 5228 | int err; |
5229 | 5229 | ||
5230 | if (!test_bit(HCI_CONN_MASTER, &hcon->flags)) | 5230 | if (hcon->role != HCI_ROLE_MASTER) |
5231 | return -EINVAL; | 5231 | return -EINVAL; |
5232 | 5232 | ||
5233 | if (cmd_len != sizeof(struct l2cap_conn_param_update_req)) | 5233 | if (cmd_len != sizeof(struct l2cap_conn_param_update_req)) |
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 8339d6b0f2b8..78eeb8b5970a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c | |||
@@ -445,7 +445,7 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth, | |||
445 | * Confirms and the slave Enters the passkey. | 445 | * Confirms and the slave Enters the passkey. |
446 | */ | 446 | */ |
447 | if (method == OVERLAP) { | 447 | if (method == OVERLAP) { |
448 | if (test_bit(HCI_CONN_MASTER, &hcon->flags)) | 448 | if (hcon->role == HCI_ROLE_MASTER) |
449 | method = CFM_PASSKEY; | 449 | method = CFM_PASSKEY; |
450 | else | 450 | else |
451 | method = REQ_PASSKEY; | 451 | method = REQ_PASSKEY; |
@@ -686,7 +686,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) | |||
686 | if (skb->len < sizeof(*req)) | 686 | if (skb->len < sizeof(*req)) |
687 | return SMP_INVALID_PARAMS; | 687 | return SMP_INVALID_PARAMS; |
688 | 688 | ||
689 | if (test_bit(HCI_CONN_MASTER, &conn->hcon->flags)) | 689 | if (conn->hcon->role != HCI_ROLE_SLAVE) |
690 | return SMP_CMD_NOTSUPP; | 690 | return SMP_CMD_NOTSUPP; |
691 | 691 | ||
692 | if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) | 692 | if (!test_and_set_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) |
@@ -755,7 +755,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) | |||
755 | if (skb->len < sizeof(*rsp)) | 755 | if (skb->len < sizeof(*rsp)) |
756 | return SMP_INVALID_PARAMS; | 756 | return SMP_INVALID_PARAMS; |
757 | 757 | ||
758 | if (!test_bit(HCI_CONN_MASTER, &conn->hcon->flags)) | 758 | if (conn->hcon->role != HCI_ROLE_MASTER) |
759 | return SMP_CMD_NOTSUPP; | 759 | return SMP_CMD_NOTSUPP; |
760 | 760 | ||
761 | skb_pull(skb, sizeof(*rsp)); | 761 | skb_pull(skb, sizeof(*rsp)); |
@@ -903,7 +903,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) | |||
903 | if (skb->len < sizeof(*rp)) | 903 | if (skb->len < sizeof(*rp)) |
904 | return SMP_INVALID_PARAMS; | 904 | return SMP_INVALID_PARAMS; |
905 | 905 | ||
906 | if (!test_bit(HCI_CONN_MASTER, &conn->hcon->flags)) | 906 | if (hcon->role != HCI_ROLE_MASTER) |
907 | return SMP_CMD_NOTSUPP; | 907 | return SMP_CMD_NOTSUPP; |
908 | 908 | ||
909 | sec_level = authreq_to_seclevel(rp->auth_req); | 909 | sec_level = authreq_to_seclevel(rp->auth_req); |
@@ -961,7 +961,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) | |||
961 | if (sec_level > hcon->pending_sec_level) | 961 | if (sec_level > hcon->pending_sec_level) |
962 | hcon->pending_sec_level = sec_level; | 962 | hcon->pending_sec_level = sec_level; |
963 | 963 | ||
964 | if (test_bit(HCI_CONN_MASTER, &hcon->flags)) | 964 | if (hcon->role == HCI_ROLE_MASTER) |
965 | if (smp_ltk_encrypt(conn, hcon->pending_sec_level)) | 965 | if (smp_ltk_encrypt(conn, hcon->pending_sec_level)) |
966 | return 0; | 966 | return 0; |
967 | 967 | ||
@@ -981,7 +981,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level) | |||
981 | hcon->pending_sec_level > BT_SECURITY_MEDIUM) | 981 | hcon->pending_sec_level > BT_SECURITY_MEDIUM) |
982 | authreq |= SMP_AUTH_MITM; | 982 | authreq |= SMP_AUTH_MITM; |
983 | 983 | ||
984 | if (test_bit(HCI_CONN_MASTER, &hcon->flags)) { | 984 | if (hcon->role == HCI_ROLE_MASTER) { |
985 | struct smp_cmd_pairing cp; | 985 | struct smp_cmd_pairing cp; |
986 | 986 | ||
987 | build_pairing_cmd(conn, &cp, NULL, authreq); | 987 | build_pairing_cmd(conn, &cp, NULL, authreq); |