aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-07-16 04:42:28 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-07-16 05:04:23 -0400
commite804d25d4a07c0ff9e5e1c58ea5ee67232aa9af8 (patch)
treeb52e7927dace2aa691585d9dd12534d36ade1b87
parent40bef302f6323d1ee6fb3dc0e62edb0f446d0339 (diff)
Bluetooth: Use explicit role instead of a bool in function parameters
To make the code more understandable it makes sense to use the new HCI defines for connection role instead of a "bool master" parameter. This makes it immediately clear when looking at the function calls what the last parameter is describing. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/bluetooth/hci_core.h6
-rw-r--r--net/bluetooth/hci_conn.c7
-rw-r--r--net/bluetooth/hci_core.c19
-rw-r--r--net/bluetooth/hci_event.c5
-rw-r--r--net/bluetooth/l2cap_core.c9
-rw-r--r--net/bluetooth/mgmt.c4
-rw-r--r--net/bluetooth/smp.c4
7 files changed, 30 insertions, 24 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index e335c5fd8824..abe5083becd3 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -707,7 +707,7 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
707 707
708struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, 708struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
709 u8 dst_type, u8 sec_level, u16 conn_timeout, 709 u8 dst_type, u8 sec_level, u16 conn_timeout,
710 bool master); 710 u8 role);
711struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, 711struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
712 u8 sec_level, u8 auth_type); 712 u8 sec_level, u8 auth_type);
713struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, 713struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
@@ -881,12 +881,12 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
881 bdaddr_t *bdaddr, u8 *val, u8 type, 881 bdaddr_t *bdaddr, u8 *val, u8 type,
882 u8 pin_len, bool *persistent); 882 u8 pin_len, bool *persistent);
883struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand, 883struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
884 bool master); 884 u8 role);
885struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, 885struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
886 u8 addr_type, u8 type, u8 authenticated, 886 u8 addr_type, u8 type, u8 authenticated,
887 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand); 887 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
888struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 888struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
889 u8 addr_type, bool master); 889 u8 addr_type, u8 role);
890int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type); 890int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
891void hci_smp_ltks_clear(struct hci_dev *hdev); 891void hci_smp_ltks_clear(struct hci_dev *hdev);
892int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 892int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 6c1c5048984c..6edd55340157 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -697,7 +697,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
697 697
698struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, 698struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
699 u8 dst_type, u8 sec_level, u16 conn_timeout, 699 u8 dst_type, u8 sec_level, u16 conn_timeout,
700 bool master) 700 u8 role)
701{ 701{
702 struct hci_conn_params *params; 702 struct hci_conn_params *params;
703 struct hci_conn *conn; 703 struct hci_conn *conn;
@@ -769,8 +769,10 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
769 &enable); 769 &enable);
770 } 770 }
771 771
772 conn->role = role;
773
772 /* If requested to connect as slave use directed advertising */ 774 /* If requested to connect as slave use directed advertising */
773 if (!master) { 775 if (conn->role == HCI_ROLE_SLAVE) {
774 /* If we're active scanning most controllers are unable 776 /* If we're active scanning most controllers are unable
775 * to initiate advertising. Simply reject the attempt. 777 * to initiate advertising. Simply reject the attempt.
776 */ 778 */
@@ -786,7 +788,6 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
786 } 788 }
787 789
788 conn->out = true; 790 conn->out = true;
789 conn->role = HCI_ROLE_MASTER;
790 791
791 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); 792 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
792 if (params) { 793 if (params) {
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 172041e2b15a..f575abdf2b4e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -3121,13 +3121,16 @@ static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
3121 return false; 3121 return false;
3122} 3122}
3123 3123
3124static bool ltk_type_master(u8 type) 3124static u8 ltk_role(u8 type)
3125{ 3125{
3126 return (type == SMP_LTK); 3126 if (type == SMP_LTK)
3127 return HCI_ROLE_MASTER;
3128
3129 return HCI_ROLE_SLAVE;
3127} 3130}
3128 3131
3129struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand, 3132struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
3130 bool master) 3133 u8 role)
3131{ 3134{
3132 struct smp_ltk *k; 3135 struct smp_ltk *k;
3133 3136
@@ -3135,7 +3138,7 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
3135 if (k->ediv != ediv || k->rand != rand) 3138 if (k->ediv != ediv || k->rand != rand)
3136 continue; 3139 continue;
3137 3140
3138 if (ltk_type_master(k->type) != master) 3141 if (ltk_role(k->type) != role)
3139 continue; 3142 continue;
3140 3143
3141 return k; 3144 return k;
@@ -3145,14 +3148,14 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
3145} 3148}
3146 3149
3147struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 3150struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
3148 u8 addr_type, bool master) 3151 u8 addr_type, u8 role)
3149{ 3152{
3150 struct smp_ltk *k; 3153 struct smp_ltk *k;
3151 3154
3152 list_for_each_entry(k, &hdev->long_term_keys, list) 3155 list_for_each_entry(k, &hdev->long_term_keys, list)
3153 if (addr_type == k->bdaddr_type && 3156 if (addr_type == k->bdaddr_type &&
3154 bacmp(bdaddr, &k->bdaddr) == 0 && 3157 bacmp(bdaddr, &k->bdaddr) == 0 &&
3155 ltk_type_master(k->type) == master) 3158 ltk_role(k->type) == role)
3156 return k; 3159 return k;
3157 3160
3158 return NULL; 3161 return NULL;
@@ -3247,9 +3250,9 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
3247 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand) 3250 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand)
3248{ 3251{
3249 struct smp_ltk *key, *old_key; 3252 struct smp_ltk *key, *old_key;
3250 bool master = ltk_type_master(type); 3253 u8 role = ltk_role(type);
3251 3254
3252 old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type, master); 3255 old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type, role);
3253 if (old_key) 3256 if (old_key)
3254 key = old_key; 3257 key = old_key;
3255 else { 3258 else {
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3b1d2dadedc8..5f7fd410fb3b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4263,9 +4263,8 @@ static void check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
4263 return; 4263 return;
4264 4264
4265connect: 4265connect:
4266 /* Request connection in master = true role */
4267 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, 4266 conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
4268 HCI_LE_AUTOCONN_TIMEOUT, true); 4267 HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER);
4269 if (!IS_ERR(conn)) 4268 if (!IS_ERR(conn))
4270 return; 4269 return;
4271 4270
@@ -4443,7 +4442,7 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
4443 if (conn == NULL) 4442 if (conn == NULL)
4444 goto not_found; 4443 goto not_found;
4445 4444
4446 ltk = hci_find_ltk(hdev, ev->ediv, ev->rand, conn->out); 4445 ltk = hci_find_ltk(hdev, ev->ediv, ev->rand, conn->role);
4447 if (ltk == NULL) 4446 if (ltk == NULL)
4448 goto not_found; 4447 goto not_found;
4449 4448
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ea68d3219b7e..d0f36336b6ce 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -7128,7 +7128,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7128 chan->dcid = cid; 7128 chan->dcid = cid;
7129 7129
7130 if (bdaddr_type_is_le(dst_type)) { 7130 if (bdaddr_type_is_le(dst_type)) {
7131 bool master; 7131 u8 role;
7132 7132
7133 /* Convert from L2CAP channel address type to HCI address type 7133 /* Convert from L2CAP channel address type to HCI address type
7134 */ 7134 */
@@ -7137,10 +7137,13 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7137 else 7137 else
7138 dst_type = ADDR_LE_DEV_RANDOM; 7138 dst_type = ADDR_LE_DEV_RANDOM;
7139 7139
7140 master = !test_bit(HCI_ADVERTISING, &hdev->dev_flags); 7140 if (test_bit(HCI_ADVERTISING, &hdev->dev_flags))
7141 role = HCI_ROLE_SLAVE;
7142 else
7143 role = HCI_ROLE_MASTER;
7141 7144
7142 hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level, 7145 hcon = hci_connect_le(hdev, dst, dst_type, chan->sec_level,
7143 HCI_LE_CONN_TIMEOUT, master); 7146 HCI_LE_CONN_TIMEOUT, role);
7144 } else { 7147 } else {
7145 u8 auth_type = l2cap_get_auth_type(chan); 7148 u8 auth_type = l2cap_get_auth_type(chan);
7146 hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type); 7149 hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7703b72653ff..b981bfb87f86 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3154,9 +3154,9 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
3154 */ 3154 */
3155 hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type); 3155 hci_conn_params_add(hdev, &cp->addr.bdaddr, addr_type);
3156 3156
3157 /* Request a connection with master = true role */
3158 conn = hci_connect_le(hdev, &cp->addr.bdaddr, addr_type, 3157 conn = hci_connect_le(hdev, &cp->addr.bdaddr, addr_type,
3159 sec_level, HCI_LE_CONN_TIMEOUT, true); 3158 sec_level, HCI_LE_CONN_TIMEOUT,
3159 HCI_ROLE_MASTER);
3160 } 3160 }
3161 3161
3162 if (IS_ERR(conn)) { 3162 if (IS_ERR(conn)) {
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 78eeb8b5970a..70b726518d7b 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -849,7 +849,7 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
849 struct hci_conn *hcon = conn->hcon; 849 struct hci_conn *hcon = conn->hcon;
850 850
851 key = hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type, 851 key = hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type,
852 hcon->out); 852 hcon->role);
853 if (!key) 853 if (!key)
854 return false; 854 return false;
855 855
@@ -881,7 +881,7 @@ bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level)
881 */ 881 */
882 if (test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) && 882 if (test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags) &&
883 hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type, 883 hci_find_ltk_by_addr(hcon->hdev, &hcon->dst, hcon->dst_type,
884 hcon->out)) 884 hcon->role))
885 return false; 885 return false;
886 886
887 if (hcon->sec_level >= sec_level) 887 if (hcon->sec_level >= sec_level)