diff options
author | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-04-12 17:31:57 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-04-27 17:51:35 -0400 |
commit | 4343478f3a4806394136d8141b2e451aa5443f03 (patch) | |
tree | 3f8b367bf650dee21c848da206e1c06c36ec1b97 | |
parent | 77a74c7e0861e6ebac7effe233fd7e83f1ad9ecc (diff) |
Bluetooth: Move some more elements to struct l2cap_chan
In this commit sec_level, force_reliable, role_switch and flushable.
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r-- | include/net/bluetooth/l2cap.h | 12 | ||||
-rw-r--r-- | net/bluetooth/l2cap_core.c | 78 | ||||
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 52 |
3 files changed, 77 insertions, 65 deletions
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index f70935000345..684deee6ec52 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h | |||
@@ -284,6 +284,12 @@ struct srej_list { | |||
284 | 284 | ||
285 | struct l2cap_chan { | 285 | struct l2cap_chan { |
286 | struct sock *sk; | 286 | struct sock *sk; |
287 | |||
288 | __u8 sec_level; | ||
289 | __u8 role_switch; | ||
290 | __u8 force_reliable; | ||
291 | __u8 flushable; | ||
292 | |||
287 | __u8 ident; | 293 | __u8 ident; |
288 | 294 | ||
289 | __u8 conf_req[64]; | 295 | __u8 conf_req[64]; |
@@ -371,10 +377,6 @@ struct l2cap_pinfo { | |||
371 | __u8 mode; | 377 | __u8 mode; |
372 | 378 | ||
373 | __u8 fcs; | 379 | __u8 fcs; |
374 | __u8 sec_level; | ||
375 | __u8 role_switch; | ||
376 | __u8 force_reliable; | ||
377 | __u8 flushable; | ||
378 | 380 | ||
379 | __u8 tx_win; | 381 | __u8 tx_win; |
380 | __u8 max_tx; | 382 | __u8 max_tx; |
@@ -452,7 +454,7 @@ struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, s | |||
452 | struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len); | 454 | struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len); |
453 | struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen); | 455 | struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen); |
454 | int l2cap_sar_segment_sdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len); | 456 | int l2cap_sar_segment_sdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len); |
455 | void l2cap_do_send(struct sock *sk, struct sk_buff *skb); | 457 | void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb); |
456 | void l2cap_streaming_send(struct l2cap_chan *chan); | 458 | void l2cap_streaming_send(struct l2cap_chan *chan); |
457 | int l2cap_ertm_send(struct l2cap_chan *chan); | 459 | int l2cap_ertm_send(struct l2cap_chan *chan); |
458 | 460 | ||
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 29742d875e60..0fc6bbe85d41 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -262,10 +262,12 @@ free: | |||
262 | kfree(chan); | 262 | kfree(chan); |
263 | } | 263 | } |
264 | 264 | ||
265 | static inline u8 l2cap_get_auth_type(struct sock *sk) | 265 | static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan) |
266 | { | 266 | { |
267 | struct sock *sk = chan->sk; | ||
268 | |||
267 | if (sk->sk_type == SOCK_RAW) { | 269 | if (sk->sk_type == SOCK_RAW) { |
268 | switch (l2cap_pi(sk)->sec_level) { | 270 | switch (chan->sec_level) { |
269 | case BT_SECURITY_HIGH: | 271 | case BT_SECURITY_HIGH: |
270 | return HCI_AT_DEDICATED_BONDING_MITM; | 272 | return HCI_AT_DEDICATED_BONDING_MITM; |
271 | case BT_SECURITY_MEDIUM: | 273 | case BT_SECURITY_MEDIUM: |
@@ -274,15 +276,15 @@ static inline u8 l2cap_get_auth_type(struct sock *sk) | |||
274 | return HCI_AT_NO_BONDING; | 276 | return HCI_AT_NO_BONDING; |
275 | } | 277 | } |
276 | } else if (l2cap_pi(sk)->psm == cpu_to_le16(0x0001)) { | 278 | } else if (l2cap_pi(sk)->psm == cpu_to_le16(0x0001)) { |
277 | if (l2cap_pi(sk)->sec_level == BT_SECURITY_LOW) | 279 | if (chan->sec_level == BT_SECURITY_LOW) |
278 | l2cap_pi(sk)->sec_level = BT_SECURITY_SDP; | 280 | chan->sec_level = BT_SECURITY_SDP; |
279 | 281 | ||
280 | if (l2cap_pi(sk)->sec_level == BT_SECURITY_HIGH) | 282 | if (chan->sec_level == BT_SECURITY_HIGH) |
281 | return HCI_AT_NO_BONDING_MITM; | 283 | return HCI_AT_NO_BONDING_MITM; |
282 | else | 284 | else |
283 | return HCI_AT_NO_BONDING; | 285 | return HCI_AT_NO_BONDING; |
284 | } else { | 286 | } else { |
285 | switch (l2cap_pi(sk)->sec_level) { | 287 | switch (chan->sec_level) { |
286 | case BT_SECURITY_HIGH: | 288 | case BT_SECURITY_HIGH: |
287 | return HCI_AT_GENERAL_BONDING_MITM; | 289 | return HCI_AT_GENERAL_BONDING_MITM; |
288 | case BT_SECURITY_MEDIUM: | 290 | case BT_SECURITY_MEDIUM: |
@@ -294,15 +296,14 @@ static inline u8 l2cap_get_auth_type(struct sock *sk) | |||
294 | } | 296 | } |
295 | 297 | ||
296 | /* Service level security */ | 298 | /* Service level security */ |
297 | static inline int l2cap_check_security(struct sock *sk) | 299 | static inline int l2cap_check_security(struct l2cap_chan *chan) |
298 | { | 300 | { |
299 | struct l2cap_conn *conn = l2cap_pi(sk)->conn; | 301 | struct l2cap_conn *conn = l2cap_pi(chan->sk)->conn; |
300 | __u8 auth_type; | 302 | __u8 auth_type; |
301 | 303 | ||
302 | auth_type = l2cap_get_auth_type(sk); | 304 | auth_type = l2cap_get_auth_type(chan); |
303 | 305 | ||
304 | return hci_conn_security(conn->hcon, l2cap_pi(sk)->sec_level, | 306 | return hci_conn_security(conn->hcon, chan->sec_level, auth_type); |
305 | auth_type); | ||
306 | } | 307 | } |
307 | 308 | ||
308 | u8 l2cap_get_ident(struct l2cap_conn *conn) | 309 | u8 l2cap_get_ident(struct l2cap_conn *conn) |
@@ -425,7 +426,8 @@ static void l2cap_do_start(struct l2cap_chan *chan) | |||
425 | if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) | 426 | if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) |
426 | return; | 427 | return; |
427 | 428 | ||
428 | if (l2cap_check_security(sk) && __l2cap_no_conn_pending(chan)) { | 429 | if (l2cap_check_security(chan) && |
430 | __l2cap_no_conn_pending(chan)) { | ||
429 | struct l2cap_conn_req req; | 431 | struct l2cap_conn_req req; |
430 | req.scid = cpu_to_le16(l2cap_pi(sk)->scid); | 432 | req.scid = cpu_to_le16(l2cap_pi(sk)->scid); |
431 | req.psm = l2cap_pi(sk)->psm; | 433 | req.psm = l2cap_pi(sk)->psm; |
@@ -515,7 +517,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) | |||
515 | if (sk->sk_state == BT_CONNECT) { | 517 | if (sk->sk_state == BT_CONNECT) { |
516 | struct l2cap_conn_req req; | 518 | struct l2cap_conn_req req; |
517 | 519 | ||
518 | if (!l2cap_check_security(sk) || | 520 | if (!l2cap_check_security(chan) || |
519 | !__l2cap_no_conn_pending(chan)) { | 521 | !__l2cap_no_conn_pending(chan)) { |
520 | bh_unlock_sock(sk); | 522 | bh_unlock_sock(sk); |
521 | continue; | 523 | continue; |
@@ -549,7 +551,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) | |||
549 | rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid); | 551 | rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid); |
550 | rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid); | 552 | rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid); |
551 | 553 | ||
552 | if (l2cap_check_security(sk)) { | 554 | if (l2cap_check_security(chan)) { |
553 | if (bt_sk(sk)->defer_setup) { | 555 | if (bt_sk(sk)->defer_setup) { |
554 | struct sock *parent = bt_sk(sk)->parent; | 556 | struct sock *parent = bt_sk(sk)->parent; |
555 | rsp.result = cpu_to_le16(L2CAP_CR_PEND); | 557 | rsp.result = cpu_to_le16(L2CAP_CR_PEND); |
@@ -722,7 +724,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err) | |||
722 | list_for_each_entry(chan, &conn->chan_l, list) { | 724 | list_for_each_entry(chan, &conn->chan_l, list) { |
723 | struct sock *sk = chan->sk; | 725 | struct sock *sk = chan->sk; |
724 | 726 | ||
725 | if (l2cap_pi(sk)->force_reliable) | 727 | if (chan->force_reliable) |
726 | sk->sk_err = err; | 728 | sk->sk_err = err; |
727 | } | 729 | } |
728 | 730 | ||
@@ -867,14 +869,14 @@ int l2cap_chan_connect(struct l2cap_chan *chan) | |||
867 | 869 | ||
868 | hci_dev_lock_bh(hdev); | 870 | hci_dev_lock_bh(hdev); |
869 | 871 | ||
870 | auth_type = l2cap_get_auth_type(sk); | 872 | auth_type = l2cap_get_auth_type(chan); |
871 | 873 | ||
872 | if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA) | 874 | if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA) |
873 | hcon = hci_connect(hdev, LE_LINK, dst, | 875 | hcon = hci_connect(hdev, LE_LINK, dst, |
874 | l2cap_pi(sk)->sec_level, auth_type); | 876 | chan->sec_level, auth_type); |
875 | else | 877 | else |
876 | hcon = hci_connect(hdev, ACL_LINK, dst, | 878 | hcon = hci_connect(hdev, ACL_LINK, dst, |
877 | l2cap_pi(sk)->sec_level, auth_type); | 879 | chan->sec_level, auth_type); |
878 | 880 | ||
879 | if (IS_ERR(hcon)) { | 881 | if (IS_ERR(hcon)) { |
880 | err = PTR_ERR(hcon); | 882 | err = PTR_ERR(hcon); |
@@ -900,7 +902,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan) | |||
900 | if (sk->sk_type != SOCK_SEQPACKET && | 902 | if (sk->sk_type != SOCK_SEQPACKET && |
901 | sk->sk_type != SOCK_STREAM) { | 903 | sk->sk_type != SOCK_STREAM) { |
902 | l2cap_sock_clear_timer(sk); | 904 | l2cap_sock_clear_timer(sk); |
903 | if (l2cap_check_security(sk)) | 905 | if (l2cap_check_security(chan)) |
904 | sk->sk_state = BT_CONNECTED; | 906 | sk->sk_state = BT_CONNECTED; |
905 | } else | 907 | } else |
906 | l2cap_do_start(chan); | 908 | l2cap_do_start(chan); |
@@ -1002,15 +1004,15 @@ static void l2cap_drop_acked_frames(struct l2cap_chan *chan) | |||
1002 | del_timer(&chan->retrans_timer); | 1004 | del_timer(&chan->retrans_timer); |
1003 | } | 1005 | } |
1004 | 1006 | ||
1005 | void l2cap_do_send(struct sock *sk, struct sk_buff *skb) | 1007 | void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb) |
1006 | { | 1008 | { |
1007 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1009 | struct sock *sk = chan->sk; |
1008 | struct hci_conn *hcon = pi->conn->hcon; | 1010 | struct hci_conn *hcon = l2cap_pi(sk)->conn->hcon; |
1009 | u16 flags; | 1011 | u16 flags; |
1010 | 1012 | ||
1011 | BT_DBG("sk %p, skb %p len %d", sk, skb, skb->len); | 1013 | BT_DBG("chan %p, skb %p len %d", chan, skb, skb->len); |
1012 | 1014 | ||
1013 | if (!pi->flushable && lmp_no_flush_capable(hcon->hdev)) | 1015 | if (!chan->flushable && lmp_no_flush_capable(hcon->hdev)) |
1014 | flags = ACL_START_NO_FLUSH; | 1016 | flags = ACL_START_NO_FLUSH; |
1015 | else | 1017 | else |
1016 | flags = ACL_START; | 1018 | flags = ACL_START; |
@@ -1035,7 +1037,7 @@ void l2cap_streaming_send(struct l2cap_chan *chan) | |||
1035 | put_unaligned_le16(fcs, skb->data + skb->len - 2); | 1037 | put_unaligned_le16(fcs, skb->data + skb->len - 2); |
1036 | } | 1038 | } |
1037 | 1039 | ||
1038 | l2cap_do_send(sk, skb); | 1040 | l2cap_do_send(chan, skb); |
1039 | 1041 | ||
1040 | chan->next_tx_seq = (chan->next_tx_seq + 1) % 64; | 1042 | chan->next_tx_seq = (chan->next_tx_seq + 1) % 64; |
1041 | } | 1043 | } |
@@ -1087,7 +1089,7 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq) | |||
1087 | put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2); | 1089 | put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2); |
1088 | } | 1090 | } |
1089 | 1091 | ||
1090 | l2cap_do_send(sk, tx_skb); | 1092 | l2cap_do_send(chan, tx_skb); |
1091 | } | 1093 | } |
1092 | 1094 | ||
1093 | int l2cap_ertm_send(struct l2cap_chan *chan) | 1095 | int l2cap_ertm_send(struct l2cap_chan *chan) |
@@ -1130,7 +1132,7 @@ int l2cap_ertm_send(struct l2cap_chan *chan) | |||
1130 | put_unaligned_le16(fcs, skb->data + tx_skb->len - 2); | 1132 | put_unaligned_le16(fcs, skb->data + tx_skb->len - 2); |
1131 | } | 1133 | } |
1132 | 1134 | ||
1133 | l2cap_do_send(sk, tx_skb); | 1135 | l2cap_do_send(chan, tx_skb); |
1134 | 1136 | ||
1135 | __mod_retrans_timer(); | 1137 | __mod_retrans_timer(); |
1136 | 1138 | ||
@@ -2100,7 +2102,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd | |||
2100 | chan->ident = cmd->ident; | 2102 | chan->ident = cmd->ident; |
2101 | 2103 | ||
2102 | if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { | 2104 | if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { |
2103 | if (l2cap_check_security(sk)) { | 2105 | if (l2cap_check_security(chan)) { |
2104 | if (bt_sk(sk)->defer_setup) { | 2106 | if (bt_sk(sk)->defer_setup) { |
2105 | sk->sk_state = BT_CONNECT2; | 2107 | sk->sk_state = BT_CONNECT2; |
2106 | result = L2CAP_CR_PEND; | 2108 | result = L2CAP_CR_PEND; |
@@ -3805,17 +3807,19 @@ static int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) | |||
3805 | /* Find listening sockets and check their link_mode */ | 3807 | /* Find listening sockets and check their link_mode */ |
3806 | read_lock(&l2cap_sk_list.lock); | 3808 | read_lock(&l2cap_sk_list.lock); |
3807 | sk_for_each(sk, node, &l2cap_sk_list.head) { | 3809 | sk_for_each(sk, node, &l2cap_sk_list.head) { |
3810 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
3811 | |||
3808 | if (sk->sk_state != BT_LISTEN) | 3812 | if (sk->sk_state != BT_LISTEN) |
3809 | continue; | 3813 | continue; |
3810 | 3814 | ||
3811 | if (!bacmp(&bt_sk(sk)->src, &hdev->bdaddr)) { | 3815 | if (!bacmp(&bt_sk(sk)->src, &hdev->bdaddr)) { |
3812 | lm1 |= HCI_LM_ACCEPT; | 3816 | lm1 |= HCI_LM_ACCEPT; |
3813 | if (l2cap_pi(sk)->role_switch) | 3817 | if (chan->role_switch) |
3814 | lm1 |= HCI_LM_MASTER; | 3818 | lm1 |= HCI_LM_MASTER; |
3815 | exact++; | 3819 | exact++; |
3816 | } else if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY)) { | 3820 | } else if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY)) { |
3817 | lm2 |= HCI_LM_ACCEPT; | 3821 | lm2 |= HCI_LM_ACCEPT; |
3818 | if (l2cap_pi(sk)->role_switch) | 3822 | if (chan->role_switch) |
3819 | lm2 |= HCI_LM_MASTER; | 3823 | lm2 |= HCI_LM_MASTER; |
3820 | } | 3824 | } |
3821 | } | 3825 | } |
@@ -3867,19 +3871,21 @@ static int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason) | |||
3867 | return 0; | 3871 | return 0; |
3868 | } | 3872 | } |
3869 | 3873 | ||
3870 | static inline void l2cap_check_encryption(struct sock *sk, u8 encrypt) | 3874 | static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt) |
3871 | { | 3875 | { |
3876 | struct sock *sk = chan->sk; | ||
3877 | |||
3872 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM) | 3878 | if (sk->sk_type != SOCK_SEQPACKET && sk->sk_type != SOCK_STREAM) |
3873 | return; | 3879 | return; |
3874 | 3880 | ||
3875 | if (encrypt == 0x00) { | 3881 | if (encrypt == 0x00) { |
3876 | if (l2cap_pi(sk)->sec_level == BT_SECURITY_MEDIUM) { | 3882 | if (chan->sec_level == BT_SECURITY_MEDIUM) { |
3877 | l2cap_sock_clear_timer(sk); | 3883 | l2cap_sock_clear_timer(sk); |
3878 | l2cap_sock_set_timer(sk, HZ * 5); | 3884 | l2cap_sock_set_timer(sk, HZ * 5); |
3879 | } else if (l2cap_pi(sk)->sec_level == BT_SECURITY_HIGH) | 3885 | } else if (chan->sec_level == BT_SECURITY_HIGH) |
3880 | __l2cap_sock_close(sk, ECONNREFUSED); | 3886 | __l2cap_sock_close(sk, ECONNREFUSED); |
3881 | } else { | 3887 | } else { |
3882 | if (l2cap_pi(sk)->sec_level == BT_SECURITY_MEDIUM) | 3888 | if (chan->sec_level == BT_SECURITY_MEDIUM) |
3883 | l2cap_sock_clear_timer(sk); | 3889 | l2cap_sock_clear_timer(sk); |
3884 | } | 3890 | } |
3885 | } | 3891 | } |
@@ -3908,7 +3914,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) | |||
3908 | 3914 | ||
3909 | if (!status && (sk->sk_state == BT_CONNECTED || | 3915 | if (!status && (sk->sk_state == BT_CONNECTED || |
3910 | sk->sk_state == BT_CONFIG)) { | 3916 | sk->sk_state == BT_CONFIG)) { |
3911 | l2cap_check_encryption(sk, encrypt); | 3917 | l2cap_check_encryption(chan, encrypt); |
3912 | bh_unlock_sock(sk); | 3918 | bh_unlock_sock(sk); |
3913 | continue; | 3919 | continue; |
3914 | } | 3920 | } |
@@ -4083,7 +4089,7 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p) | |||
4083 | batostr(&bt_sk(sk)->dst), | 4089 | batostr(&bt_sk(sk)->dst), |
4084 | sk->sk_state, __le16_to_cpu(pi->psm), | 4090 | sk->sk_state, __le16_to_cpu(pi->psm), |
4085 | pi->scid, pi->dcid, | 4091 | pi->scid, pi->dcid, |
4086 | pi->imtu, pi->omtu, pi->sec_level, | 4092 | pi->imtu, pi->omtu, pi->chan->sec_level, |
4087 | pi->mode); | 4093 | pi->mode); |
4088 | } | 4094 | } |
4089 | 4095 | ||
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 50437c665d1e..612955679b34 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -51,7 +51,7 @@ static void l2cap_sock_timeout(unsigned long arg) | |||
51 | if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG) | 51 | if (sk->sk_state == BT_CONNECTED || sk->sk_state == BT_CONFIG) |
52 | reason = ECONNREFUSED; | 52 | reason = ECONNREFUSED; |
53 | else if (sk->sk_state == BT_CONNECT && | 53 | else if (sk->sk_state == BT_CONNECT && |
54 | l2cap_pi(sk)->sec_level != BT_SECURITY_SDP) | 54 | l2cap_pi(sk)->chan->sec_level != BT_SECURITY_SDP) |
55 | reason = ECONNREFUSED; | 55 | reason = ECONNREFUSED; |
56 | else | 56 | else |
57 | reason = ETIMEDOUT; | 57 | reason = ETIMEDOUT; |
@@ -91,6 +91,7 @@ found: | |||
91 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) | 91 | static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) |
92 | { | 92 | { |
93 | struct sock *sk = sock->sk; | 93 | struct sock *sk = sock->sk; |
94 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
94 | struct sockaddr_l2 la; | 95 | struct sockaddr_l2 la; |
95 | int len, err = 0; | 96 | int len, err = 0; |
96 | 97 | ||
@@ -142,7 +143,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) | |||
142 | 143 | ||
143 | if (__le16_to_cpu(la.l2_psm) == 0x0001 || | 144 | if (__le16_to_cpu(la.l2_psm) == 0x0001 || |
144 | __le16_to_cpu(la.l2_psm) == 0x0003) | 145 | __le16_to_cpu(la.l2_psm) == 0x0003) |
145 | l2cap_pi(sk)->sec_level = BT_SECURITY_SDP; | 146 | chan->sec_level = BT_SECURITY_SDP; |
146 | } | 147 | } |
147 | 148 | ||
148 | if (la.l2_cid) | 149 | if (la.l2_cid) |
@@ -382,6 +383,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l | |||
382 | static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen) | 383 | static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __user *optval, int __user *optlen) |
383 | { | 384 | { |
384 | struct sock *sk = sock->sk; | 385 | struct sock *sk = sock->sk; |
386 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
385 | struct l2cap_options opts; | 387 | struct l2cap_options opts; |
386 | struct l2cap_conninfo cinfo; | 388 | struct l2cap_conninfo cinfo; |
387 | int len, err = 0; | 389 | int len, err = 0; |
@@ -412,7 +414,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us | |||
412 | break; | 414 | break; |
413 | 415 | ||
414 | case L2CAP_LM: | 416 | case L2CAP_LM: |
415 | switch (l2cap_pi(sk)->sec_level) { | 417 | switch (chan->sec_level) { |
416 | case BT_SECURITY_LOW: | 418 | case BT_SECURITY_LOW: |
417 | opt = L2CAP_LM_AUTH; | 419 | opt = L2CAP_LM_AUTH; |
418 | break; | 420 | break; |
@@ -428,10 +430,10 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us | |||
428 | break; | 430 | break; |
429 | } | 431 | } |
430 | 432 | ||
431 | if (l2cap_pi(sk)->role_switch) | 433 | if (chan->role_switch) |
432 | opt |= L2CAP_LM_MASTER; | 434 | opt |= L2CAP_LM_MASTER; |
433 | 435 | ||
434 | if (l2cap_pi(sk)->force_reliable) | 436 | if (chan->force_reliable) |
435 | opt |= L2CAP_LM_RELIABLE; | 437 | opt |= L2CAP_LM_RELIABLE; |
436 | 438 | ||
437 | if (put_user(opt, (u32 __user *) optval)) | 439 | if (put_user(opt, (u32 __user *) optval)) |
@@ -467,6 +469,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, char __us | |||
467 | static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) | 469 | static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) |
468 | { | 470 | { |
469 | struct sock *sk = sock->sk; | 471 | struct sock *sk = sock->sk; |
472 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
470 | struct bt_security sec; | 473 | struct bt_security sec; |
471 | int len, err = 0; | 474 | int len, err = 0; |
472 | 475 | ||
@@ -491,7 +494,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch | |||
491 | break; | 494 | break; |
492 | } | 495 | } |
493 | 496 | ||
494 | sec.level = l2cap_pi(sk)->sec_level; | 497 | sec.level = chan->sec_level; |
495 | 498 | ||
496 | len = min_t(unsigned int, len, sizeof(sec)); | 499 | len = min_t(unsigned int, len, sizeof(sec)); |
497 | if (copy_to_user(optval, (char *) &sec, len)) | 500 | if (copy_to_user(optval, (char *) &sec, len)) |
@@ -511,7 +514,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch | |||
511 | break; | 514 | break; |
512 | 515 | ||
513 | case BT_FLUSHABLE: | 516 | case BT_FLUSHABLE: |
514 | if (put_user(l2cap_pi(sk)->flushable, (u32 __user *) optval)) | 517 | if (put_user(chan->flushable, (u32 __user *) optval)) |
515 | err = -EFAULT; | 518 | err = -EFAULT; |
516 | 519 | ||
517 | break; | 520 | break; |
@@ -592,14 +595,14 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us | |||
592 | } | 595 | } |
593 | 596 | ||
594 | if (opt & L2CAP_LM_AUTH) | 597 | if (opt & L2CAP_LM_AUTH) |
595 | l2cap_pi(sk)->sec_level = BT_SECURITY_LOW; | 598 | chan->sec_level = BT_SECURITY_LOW; |
596 | if (opt & L2CAP_LM_ENCRYPT) | 599 | if (opt & L2CAP_LM_ENCRYPT) |
597 | l2cap_pi(sk)->sec_level = BT_SECURITY_MEDIUM; | 600 | chan->sec_level = BT_SECURITY_MEDIUM; |
598 | if (opt & L2CAP_LM_SECURE) | 601 | if (opt & L2CAP_LM_SECURE) |
599 | l2cap_pi(sk)->sec_level = BT_SECURITY_HIGH; | 602 | chan->sec_level = BT_SECURITY_HIGH; |
600 | 603 | ||
601 | l2cap_pi(sk)->role_switch = (opt & L2CAP_LM_MASTER); | 604 | chan->role_switch = (opt & L2CAP_LM_MASTER); |
602 | l2cap_pi(sk)->force_reliable = (opt & L2CAP_LM_RELIABLE); | 605 | chan->force_reliable = (opt & L2CAP_LM_RELIABLE); |
603 | break; | 606 | break; |
604 | 607 | ||
605 | default: | 608 | default: |
@@ -614,6 +617,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us | |||
614 | static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) | 617 | static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen) |
615 | { | 618 | { |
616 | struct sock *sk = sock->sk; | 619 | struct sock *sk = sock->sk; |
620 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
617 | struct bt_security sec; | 621 | struct bt_security sec; |
618 | int len, err = 0; | 622 | int len, err = 0; |
619 | u32 opt; | 623 | u32 opt; |
@@ -650,7 +654,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch | |||
650 | break; | 654 | break; |
651 | } | 655 | } |
652 | 656 | ||
653 | l2cap_pi(sk)->sec_level = sec.level; | 657 | chan->sec_level = sec.level; |
654 | break; | 658 | break; |
655 | 659 | ||
656 | case BT_DEFER_SETUP: | 660 | case BT_DEFER_SETUP: |
@@ -688,7 +692,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch | |||
688 | } | 692 | } |
689 | } | 693 | } |
690 | 694 | ||
691 | l2cap_pi(sk)->flushable = opt; | 695 | chan->flushable = opt; |
692 | break; | 696 | break; |
693 | 697 | ||
694 | default: | 698 | default: |
@@ -730,7 +734,7 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms | |||
730 | if (IS_ERR(skb)) { | 734 | if (IS_ERR(skb)) { |
731 | err = PTR_ERR(skb); | 735 | err = PTR_ERR(skb); |
732 | } else { | 736 | } else { |
733 | l2cap_do_send(sk, skb); | 737 | l2cap_do_send(pi->chan, skb); |
734 | err = len; | 738 | err = len; |
735 | } | 739 | } |
736 | goto done; | 740 | goto done; |
@@ -751,7 +755,7 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms | |||
751 | goto done; | 755 | goto done; |
752 | } | 756 | } |
753 | 757 | ||
754 | l2cap_do_send(sk, skb); | 758 | l2cap_do_send(pi->chan, skb); |
755 | err = len; | 759 | err = len; |
756 | break; | 760 | break; |
757 | 761 | ||
@@ -997,10 +1001,10 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
997 | pi->fcs = l2cap_pi(parent)->fcs; | 1001 | pi->fcs = l2cap_pi(parent)->fcs; |
998 | pi->max_tx = l2cap_pi(parent)->max_tx; | 1002 | pi->max_tx = l2cap_pi(parent)->max_tx; |
999 | pi->tx_win = l2cap_pi(parent)->tx_win; | 1003 | pi->tx_win = l2cap_pi(parent)->tx_win; |
1000 | pi->sec_level = l2cap_pi(parent)->sec_level; | 1004 | chan->sec_level = pchan->sec_level; |
1001 | pi->role_switch = l2cap_pi(parent)->role_switch; | 1005 | chan->role_switch = pchan->role_switch; |
1002 | pi->force_reliable = l2cap_pi(parent)->force_reliable; | 1006 | chan->force_reliable = pchan->force_reliable; |
1003 | pi->flushable = l2cap_pi(parent)->flushable; | 1007 | chan->flushable = pchan->flushable; |
1004 | } else { | 1008 | } else { |
1005 | pi->imtu = L2CAP_DEFAULT_MTU; | 1009 | pi->imtu = L2CAP_DEFAULT_MTU; |
1006 | pi->omtu = 0; | 1010 | pi->omtu = 0; |
@@ -1013,10 +1017,10 @@ void l2cap_sock_init(struct sock *sk, struct sock *parent) | |||
1013 | pi->max_tx = L2CAP_DEFAULT_MAX_TX; | 1017 | pi->max_tx = L2CAP_DEFAULT_MAX_TX; |
1014 | pi->fcs = L2CAP_FCS_CRC16; | 1018 | pi->fcs = L2CAP_FCS_CRC16; |
1015 | pi->tx_win = L2CAP_DEFAULT_TX_WINDOW; | 1019 | pi->tx_win = L2CAP_DEFAULT_TX_WINDOW; |
1016 | pi->sec_level = BT_SECURITY_LOW; | 1020 | chan->sec_level = BT_SECURITY_LOW; |
1017 | pi->role_switch = 0; | 1021 | chan->role_switch = 0; |
1018 | pi->force_reliable = 0; | 1022 | chan->force_reliable = 0; |
1019 | pi->flushable = BT_FLUSHABLE_OFF; | 1023 | chan->flushable = BT_FLUSHABLE_OFF; |
1020 | } | 1024 | } |
1021 | 1025 | ||
1022 | /* Default config options */ | 1026 | /* Default config options */ |