diff options
-rw-r--r-- | include/net/bluetooth/l2cap.h | 5 | ||||
-rw-r--r-- | net/bluetooth/l2cap_core.c | 391 | ||||
-rw-r--r-- | net/bluetooth/l2cap_sock.c | 16 |
3 files changed, 217 insertions, 195 deletions
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index 469241353d78..82d5b81a779b 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h | |||
@@ -286,6 +286,8 @@ struct l2cap_chan { | |||
286 | __u8 num_conf_req; | 286 | __u8 num_conf_req; |
287 | __u8 num_conf_rsp; | 287 | __u8 num_conf_rsp; |
288 | 288 | ||
289 | __u16 conn_state; | ||
290 | |||
289 | struct list_head list; | 291 | struct list_head list; |
290 | }; | 292 | }; |
291 | 293 | ||
@@ -350,7 +352,6 @@ struct l2cap_pinfo { | |||
350 | __u8 flushable; | 352 | __u8 flushable; |
351 | 353 | ||
352 | __u8 conf_state; | 354 | __u8 conf_state; |
353 | __u16 conn_state; | ||
354 | 355 | ||
355 | __u8 next_tx_seq; | 356 | __u8 next_tx_seq; |
356 | __u8 expected_ack_seq; | 357 | __u8 expected_ack_seq; |
@@ -456,7 +457,7 @@ struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, siz | |||
456 | int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len); | 457 | int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len); |
457 | void l2cap_do_send(struct sock *sk, struct sk_buff *skb); | 458 | void l2cap_do_send(struct sock *sk, struct sk_buff *skb); |
458 | void l2cap_streaming_send(struct sock *sk); | 459 | void l2cap_streaming_send(struct sock *sk); |
459 | int l2cap_ertm_send(struct sock *sk); | 460 | int l2cap_ertm_send(struct l2cap_chan *chan); |
460 | 461 | ||
461 | void l2cap_sock_set_timer(struct sock *sk, long timeout); | 462 | void l2cap_sock_set_timer(struct sock *sk, long timeout); |
462 | void l2cap_sock_clear_timer(struct sock *sk); | 463 | void l2cap_sock_clear_timer(struct sock *sk); |
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index b41e21f46231..b5435cd74f99 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -340,10 +340,11 @@ void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *d | |||
340 | hci_send_acl(conn->hcon, skb, flags); | 340 | hci_send_acl(conn->hcon, skb, flags); |
341 | } | 341 | } |
342 | 342 | ||
343 | static inline void l2cap_send_sframe(struct l2cap_pinfo *pi, u16 control) | 343 | static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control) |
344 | { | 344 | { |
345 | struct sk_buff *skb; | 345 | struct sk_buff *skb; |
346 | struct l2cap_hdr *lh; | 346 | struct l2cap_hdr *lh; |
347 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); | ||
347 | struct l2cap_conn *conn = pi->conn; | 348 | struct l2cap_conn *conn = pi->conn; |
348 | struct sock *sk = (struct sock *)pi; | 349 | struct sock *sk = (struct sock *)pi; |
349 | int count, hlen = L2CAP_HDR_SIZE + 2; | 350 | int count, hlen = L2CAP_HDR_SIZE + 2; |
@@ -360,14 +361,14 @@ static inline void l2cap_send_sframe(struct l2cap_pinfo *pi, u16 control) | |||
360 | count = min_t(unsigned int, conn->mtu, hlen); | 361 | count = min_t(unsigned int, conn->mtu, hlen); |
361 | control |= L2CAP_CTRL_FRAME_TYPE; | 362 | control |= L2CAP_CTRL_FRAME_TYPE; |
362 | 363 | ||
363 | if (pi->conn_state & L2CAP_CONN_SEND_FBIT) { | 364 | if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { |
364 | control |= L2CAP_CTRL_FINAL; | 365 | control |= L2CAP_CTRL_FINAL; |
365 | pi->conn_state &= ~L2CAP_CONN_SEND_FBIT; | 366 | chan->conn_state &= ~L2CAP_CONN_SEND_FBIT; |
366 | } | 367 | } |
367 | 368 | ||
368 | if (pi->conn_state & L2CAP_CONN_SEND_PBIT) { | 369 | if (chan->conn_state & L2CAP_CONN_SEND_PBIT) { |
369 | control |= L2CAP_CTRL_POLL; | 370 | control |= L2CAP_CTRL_POLL; |
370 | pi->conn_state &= ~L2CAP_CONN_SEND_PBIT; | 371 | chan->conn_state &= ~L2CAP_CONN_SEND_PBIT; |
371 | } | 372 | } |
372 | 373 | ||
373 | skb = bt_skb_alloc(count, GFP_ATOMIC); | 374 | skb = bt_skb_alloc(count, GFP_ATOMIC); |
@@ -392,17 +393,19 @@ static inline void l2cap_send_sframe(struct l2cap_pinfo *pi, u16 control) | |||
392 | hci_send_acl(pi->conn->hcon, skb, flags); | 393 | hci_send_acl(pi->conn->hcon, skb, flags); |
393 | } | 394 | } |
394 | 395 | ||
395 | static inline void l2cap_send_rr_or_rnr(struct l2cap_pinfo *pi, u16 control) | 396 | static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control) |
396 | { | 397 | { |
397 | if (pi->conn_state & L2CAP_CONN_LOCAL_BUSY) { | 398 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
399 | |||
400 | if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { | ||
398 | control |= L2CAP_SUPER_RCV_NOT_READY; | 401 | control |= L2CAP_SUPER_RCV_NOT_READY; |
399 | pi->conn_state |= L2CAP_CONN_RNR_SENT; | 402 | chan->conn_state |= L2CAP_CONN_RNR_SENT; |
400 | } else | 403 | } else |
401 | control |= L2CAP_SUPER_RCV_READY; | 404 | control |= L2CAP_SUPER_RCV_READY; |
402 | 405 | ||
403 | control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 406 | control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
404 | 407 | ||
405 | l2cap_send_sframe(pi, control); | 408 | l2cap_send_sframe(chan, control); |
406 | } | 409 | } |
407 | 410 | ||
408 | static inline int __l2cap_no_conn_pending(struct sock *sk) | 411 | static inline int __l2cap_no_conn_pending(struct sock *sk) |
@@ -949,9 +952,10 @@ int __l2cap_wait_ack(struct sock *sk) | |||
949 | 952 | ||
950 | static void l2cap_monitor_timeout(unsigned long arg) | 953 | static void l2cap_monitor_timeout(unsigned long arg) |
951 | { | 954 | { |
952 | struct sock *sk = (void *) arg; | 955 | struct l2cap_chan *chan = (void *) arg; |
956 | struct sock *sk = chan->sk; | ||
953 | 957 | ||
954 | BT_DBG("sk %p", sk); | 958 | BT_DBG("chan %p", chan); |
955 | 959 | ||
956 | bh_lock_sock(sk); | 960 | bh_lock_sock(sk); |
957 | if (l2cap_pi(sk)->retry_count >= l2cap_pi(sk)->remote_max_tx) { | 961 | if (l2cap_pi(sk)->retry_count >= l2cap_pi(sk)->remote_max_tx) { |
@@ -963,13 +967,14 @@ static void l2cap_monitor_timeout(unsigned long arg) | |||
963 | l2cap_pi(sk)->retry_count++; | 967 | l2cap_pi(sk)->retry_count++; |
964 | __mod_monitor_timer(); | 968 | __mod_monitor_timer(); |
965 | 969 | ||
966 | l2cap_send_rr_or_rnr(l2cap_pi(sk), L2CAP_CTRL_POLL); | 970 | l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL); |
967 | bh_unlock_sock(sk); | 971 | bh_unlock_sock(sk); |
968 | } | 972 | } |
969 | 973 | ||
970 | static void l2cap_retrans_timeout(unsigned long arg) | 974 | static void l2cap_retrans_timeout(unsigned long arg) |
971 | { | 975 | { |
972 | struct sock *sk = (void *) arg; | 976 | struct l2cap_chan *chan = (void *) arg; |
977 | struct sock *sk = chan->sk; | ||
973 | 978 | ||
974 | BT_DBG("sk %p", sk); | 979 | BT_DBG("sk %p", sk); |
975 | 980 | ||
@@ -977,9 +982,9 @@ static void l2cap_retrans_timeout(unsigned long arg) | |||
977 | l2cap_pi(sk)->retry_count = 1; | 982 | l2cap_pi(sk)->retry_count = 1; |
978 | __mod_monitor_timer(); | 983 | __mod_monitor_timer(); |
979 | 984 | ||
980 | l2cap_pi(sk)->conn_state |= L2CAP_CONN_WAIT_F; | 985 | chan->conn_state |= L2CAP_CONN_WAIT_F; |
981 | 986 | ||
982 | l2cap_send_rr_or_rnr(l2cap_pi(sk), L2CAP_CTRL_POLL); | 987 | l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL); |
983 | bh_unlock_sock(sk); | 988 | bh_unlock_sock(sk); |
984 | } | 989 | } |
985 | 990 | ||
@@ -1040,8 +1045,9 @@ void l2cap_streaming_send(struct sock *sk) | |||
1040 | } | 1045 | } |
1041 | } | 1046 | } |
1042 | 1047 | ||
1043 | static void l2cap_retransmit_one_frame(struct sock *sk, u8 tx_seq) | 1048 | static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq) |
1044 | { | 1049 | { |
1050 | struct sock *sk = chan->sk; | ||
1045 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1051 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
1046 | struct sk_buff *skb, *tx_skb; | 1052 | struct sk_buff *skb, *tx_skb; |
1047 | u16 control, fcs; | 1053 | u16 control, fcs; |
@@ -1069,9 +1075,9 @@ static void l2cap_retransmit_one_frame(struct sock *sk, u8 tx_seq) | |||
1069 | bt_cb(skb)->retries++; | 1075 | bt_cb(skb)->retries++; |
1070 | control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); | 1076 | control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); |
1071 | 1077 | ||
1072 | if (pi->conn_state & L2CAP_CONN_SEND_FBIT) { | 1078 | if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { |
1073 | control |= L2CAP_CTRL_FINAL; | 1079 | control |= L2CAP_CTRL_FINAL; |
1074 | pi->conn_state &= ~L2CAP_CONN_SEND_FBIT; | 1080 | chan->conn_state &= ~L2CAP_CONN_SEND_FBIT; |
1075 | } | 1081 | } |
1076 | 1082 | ||
1077 | control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) | 1083 | control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) |
@@ -1087,9 +1093,10 @@ static void l2cap_retransmit_one_frame(struct sock *sk, u8 tx_seq) | |||
1087 | l2cap_do_send(sk, tx_skb); | 1093 | l2cap_do_send(sk, tx_skb); |
1088 | } | 1094 | } |
1089 | 1095 | ||
1090 | int l2cap_ertm_send(struct sock *sk) | 1096 | int l2cap_ertm_send(struct l2cap_chan *chan) |
1091 | { | 1097 | { |
1092 | struct sk_buff *skb, *tx_skb; | 1098 | struct sk_buff *skb, *tx_skb; |
1099 | struct sock *sk = chan->sk; | ||
1093 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1100 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
1094 | u16 control, fcs; | 1101 | u16 control, fcs; |
1095 | int nsent = 0; | 1102 | int nsent = 0; |
@@ -1112,9 +1119,9 @@ int l2cap_ertm_send(struct sock *sk) | |||
1112 | control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); | 1119 | control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); |
1113 | control &= L2CAP_CTRL_SAR; | 1120 | control &= L2CAP_CTRL_SAR; |
1114 | 1121 | ||
1115 | if (pi->conn_state & L2CAP_CONN_SEND_FBIT) { | 1122 | if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { |
1116 | control |= L2CAP_CTRL_FINAL; | 1123 | control |= L2CAP_CTRL_FINAL; |
1117 | pi->conn_state &= ~L2CAP_CONN_SEND_FBIT; | 1124 | chan->conn_state &= ~L2CAP_CONN_SEND_FBIT; |
1118 | } | 1125 | } |
1119 | control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) | 1126 | control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) |
1120 | | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); | 1127 | | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); |
@@ -1149,8 +1156,9 @@ int l2cap_ertm_send(struct sock *sk) | |||
1149 | return nsent; | 1156 | return nsent; |
1150 | } | 1157 | } |
1151 | 1158 | ||
1152 | static int l2cap_retransmit_frames(struct sock *sk) | 1159 | static int l2cap_retransmit_frames(struct l2cap_chan *chan) |
1153 | { | 1160 | { |
1161 | struct sock *sk = chan->sk; | ||
1154 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 1162 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
1155 | int ret; | 1163 | int ret; |
1156 | 1164 | ||
@@ -1158,32 +1166,32 @@ static int l2cap_retransmit_frames(struct sock *sk) | |||
1158 | sk->sk_send_head = TX_QUEUE(sk)->next; | 1166 | sk->sk_send_head = TX_QUEUE(sk)->next; |
1159 | 1167 | ||
1160 | pi->next_tx_seq = pi->expected_ack_seq; | 1168 | pi->next_tx_seq = pi->expected_ack_seq; |
1161 | ret = l2cap_ertm_send(sk); | 1169 | ret = l2cap_ertm_send(chan); |
1162 | return ret; | 1170 | return ret; |
1163 | } | 1171 | } |
1164 | 1172 | ||
1165 | static void l2cap_send_ack(struct l2cap_pinfo *pi) | 1173 | static void l2cap_send_ack(struct l2cap_chan *chan) |
1166 | { | 1174 | { |
1167 | struct sock *sk = (struct sock *)pi; | 1175 | struct sock *sk = chan->sk; |
1168 | u16 control = 0; | 1176 | u16 control = 0; |
1169 | 1177 | ||
1170 | control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 1178 | control |= l2cap_pi(sk)->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
1171 | 1179 | ||
1172 | if (pi->conn_state & L2CAP_CONN_LOCAL_BUSY) { | 1180 | if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { |
1173 | control |= L2CAP_SUPER_RCV_NOT_READY; | 1181 | control |= L2CAP_SUPER_RCV_NOT_READY; |
1174 | pi->conn_state |= L2CAP_CONN_RNR_SENT; | 1182 | chan->conn_state |= L2CAP_CONN_RNR_SENT; |
1175 | l2cap_send_sframe(pi, control); | 1183 | l2cap_send_sframe(chan, control); |
1176 | return; | 1184 | return; |
1177 | } | 1185 | } |
1178 | 1186 | ||
1179 | if (l2cap_ertm_send(sk) > 0) | 1187 | if (l2cap_ertm_send(chan) > 0) |
1180 | return; | 1188 | return; |
1181 | 1189 | ||
1182 | control |= L2CAP_SUPER_RCV_READY; | 1190 | control |= L2CAP_SUPER_RCV_READY; |
1183 | l2cap_send_sframe(pi, control); | 1191 | l2cap_send_sframe(chan, control); |
1184 | } | 1192 | } |
1185 | 1193 | ||
1186 | static void l2cap_send_srejtail(struct sock *sk) | 1194 | static void l2cap_send_srejtail(struct l2cap_chan *chan) |
1187 | { | 1195 | { |
1188 | struct srej_list *tail; | 1196 | struct srej_list *tail; |
1189 | u16 control; | 1197 | u16 control; |
@@ -1191,10 +1199,10 @@ static void l2cap_send_srejtail(struct sock *sk) | |||
1191 | control = L2CAP_SUPER_SELECT_REJECT; | 1199 | control = L2CAP_SUPER_SELECT_REJECT; |
1192 | control |= L2CAP_CTRL_FINAL; | 1200 | control |= L2CAP_CTRL_FINAL; |
1193 | 1201 | ||
1194 | tail = list_entry(SREJ_LIST(sk)->prev, struct srej_list, list); | 1202 | tail = list_entry(SREJ_LIST(chan->sk)->prev, struct srej_list, list); |
1195 | control |= tail->tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 1203 | control |= tail->tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
1196 | 1204 | ||
1197 | l2cap_send_sframe(l2cap_pi(sk), control); | 1205 | l2cap_send_sframe(chan, control); |
1198 | } | 1206 | } |
1199 | 1207 | ||
1200 | static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, int len, int count, struct sk_buff *skb) | 1208 | static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, int len, int count, struct sk_buff *skb) |
@@ -1556,15 +1564,17 @@ static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val) | |||
1556 | 1564 | ||
1557 | static void l2cap_ack_timeout(unsigned long arg) | 1565 | static void l2cap_ack_timeout(unsigned long arg) |
1558 | { | 1566 | { |
1559 | struct sock *sk = (void *) arg; | 1567 | struct l2cap_chan *chan = (void *) arg; |
1560 | 1568 | ||
1561 | bh_lock_sock(sk); | 1569 | bh_lock_sock(chan->sk); |
1562 | l2cap_send_ack(l2cap_pi(sk)); | 1570 | l2cap_send_ack(chan); |
1563 | bh_unlock_sock(sk); | 1571 | bh_unlock_sock(chan->sk); |
1564 | } | 1572 | } |
1565 | 1573 | ||
1566 | static inline void l2cap_ertm_init(struct sock *sk) | 1574 | static inline void l2cap_ertm_init(struct l2cap_chan *chan) |
1567 | { | 1575 | { |
1576 | struct sock *sk = chan->sk; | ||
1577 | |||
1568 | l2cap_pi(sk)->expected_ack_seq = 0; | 1578 | l2cap_pi(sk)->expected_ack_seq = 0; |
1569 | l2cap_pi(sk)->unacked_frames = 0; | 1579 | l2cap_pi(sk)->unacked_frames = 0; |
1570 | l2cap_pi(sk)->buffer_seq = 0; | 1580 | l2cap_pi(sk)->buffer_seq = 0; |
@@ -1572,11 +1582,11 @@ static inline void l2cap_ertm_init(struct sock *sk) | |||
1572 | l2cap_pi(sk)->frames_sent = 0; | 1582 | l2cap_pi(sk)->frames_sent = 0; |
1573 | 1583 | ||
1574 | setup_timer(&l2cap_pi(sk)->retrans_timer, | 1584 | setup_timer(&l2cap_pi(sk)->retrans_timer, |
1575 | l2cap_retrans_timeout, (unsigned long) sk); | 1585 | l2cap_retrans_timeout, (unsigned long) chan); |
1576 | setup_timer(&l2cap_pi(sk)->monitor_timer, | 1586 | setup_timer(&l2cap_pi(sk)->monitor_timer, |
1577 | l2cap_monitor_timeout, (unsigned long) sk); | 1587 | l2cap_monitor_timeout, (unsigned long) chan); |
1578 | setup_timer(&l2cap_pi(sk)->ack_timer, | 1588 | setup_timer(&l2cap_pi(sk)->ack_timer, |
1579 | l2cap_ack_timeout, (unsigned long) sk); | 1589 | l2cap_ack_timeout, (unsigned long) chan); |
1580 | 1590 | ||
1581 | __skb_queue_head_init(SREJ_QUEUE(sk)); | 1591 | __skb_queue_head_init(SREJ_QUEUE(sk)); |
1582 | __skb_queue_head_init(BUSY_QUEUE(sk)); | 1592 | __skb_queue_head_init(BUSY_QUEUE(sk)); |
@@ -2305,7 +2315,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr | |||
2305 | l2cap_pi(sk)->expected_tx_seq = 0; | 2315 | l2cap_pi(sk)->expected_tx_seq = 0; |
2306 | __skb_queue_head_init(TX_QUEUE(sk)); | 2316 | __skb_queue_head_init(TX_QUEUE(sk)); |
2307 | if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) | 2317 | if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) |
2308 | l2cap_ertm_init(sk); | 2318 | l2cap_ertm_init(chan); |
2309 | 2319 | ||
2310 | l2cap_chan_ready(sk); | 2320 | l2cap_chan_ready(sk); |
2311 | goto unlock; | 2321 | goto unlock; |
@@ -2396,7 +2406,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr | |||
2396 | l2cap_pi(sk)->expected_tx_seq = 0; | 2406 | l2cap_pi(sk)->expected_tx_seq = 0; |
2397 | __skb_queue_head_init(TX_QUEUE(sk)); | 2407 | __skb_queue_head_init(TX_QUEUE(sk)); |
2398 | if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) | 2408 | if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) |
2399 | l2cap_ertm_init(sk); | 2409 | l2cap_ertm_init(chan); |
2400 | 2410 | ||
2401 | l2cap_chan_ready(sk); | 2411 | l2cap_chan_ready(sk); |
2402 | } | 2412 | } |
@@ -2777,30 +2787,30 @@ static int l2cap_check_fcs(struct l2cap_pinfo *pi, struct sk_buff *skb) | |||
2777 | return 0; | 2787 | return 0; |
2778 | } | 2788 | } |
2779 | 2789 | ||
2780 | static inline void l2cap_send_i_or_rr_or_rnr(struct sock *sk) | 2790 | static inline void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan) |
2781 | { | 2791 | { |
2782 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 2792 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
2783 | u16 control = 0; | 2793 | u16 control = 0; |
2784 | 2794 | ||
2785 | pi->frames_sent = 0; | 2795 | pi->frames_sent = 0; |
2786 | 2796 | ||
2787 | control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 2797 | control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
2788 | 2798 | ||
2789 | if (pi->conn_state & L2CAP_CONN_LOCAL_BUSY) { | 2799 | if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { |
2790 | control |= L2CAP_SUPER_RCV_NOT_READY; | 2800 | control |= L2CAP_SUPER_RCV_NOT_READY; |
2791 | l2cap_send_sframe(pi, control); | 2801 | l2cap_send_sframe(chan, control); |
2792 | pi->conn_state |= L2CAP_CONN_RNR_SENT; | 2802 | chan->conn_state |= L2CAP_CONN_RNR_SENT; |
2793 | } | 2803 | } |
2794 | 2804 | ||
2795 | if (pi->conn_state & L2CAP_CONN_REMOTE_BUSY) | 2805 | if (chan->conn_state & L2CAP_CONN_REMOTE_BUSY) |
2796 | l2cap_retransmit_frames(sk); | 2806 | l2cap_retransmit_frames(chan); |
2797 | 2807 | ||
2798 | l2cap_ertm_send(sk); | 2808 | l2cap_ertm_send(chan); |
2799 | 2809 | ||
2800 | if (!(pi->conn_state & L2CAP_CONN_LOCAL_BUSY) && | 2810 | if (!(chan->conn_state & L2CAP_CONN_LOCAL_BUSY) && |
2801 | pi->frames_sent == 0) { | 2811 | pi->frames_sent == 0) { |
2802 | control |= L2CAP_SUPER_RCV_READY; | 2812 | control |= L2CAP_SUPER_RCV_READY; |
2803 | l2cap_send_sframe(pi, control); | 2813 | l2cap_send_sframe(chan, control); |
2804 | } | 2814 | } |
2805 | } | 2815 | } |
2806 | 2816 | ||
@@ -2847,25 +2857,25 @@ static int l2cap_add_to_srej_queue(struct sock *sk, struct sk_buff *skb, u8 tx_s | |||
2847 | return 0; | 2857 | return 0; |
2848 | } | 2858 | } |
2849 | 2859 | ||
2850 | static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 control) | 2860 | static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control) |
2851 | { | 2861 | { |
2852 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 2862 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
2853 | struct sk_buff *_skb; | 2863 | struct sk_buff *_skb; |
2854 | int err; | 2864 | int err; |
2855 | 2865 | ||
2856 | switch (control & L2CAP_CTRL_SAR) { | 2866 | switch (control & L2CAP_CTRL_SAR) { |
2857 | case L2CAP_SDU_UNSEGMENTED: | 2867 | case L2CAP_SDU_UNSEGMENTED: |
2858 | if (pi->conn_state & L2CAP_CONN_SAR_SDU) | 2868 | if (chan->conn_state & L2CAP_CONN_SAR_SDU) |
2859 | goto drop; | 2869 | goto drop; |
2860 | 2870 | ||
2861 | err = sock_queue_rcv_skb(sk, skb); | 2871 | err = sock_queue_rcv_skb(chan->sk, skb); |
2862 | if (!err) | 2872 | if (!err) |
2863 | return err; | 2873 | return err; |
2864 | 2874 | ||
2865 | break; | 2875 | break; |
2866 | 2876 | ||
2867 | case L2CAP_SDU_START: | 2877 | case L2CAP_SDU_START: |
2868 | if (pi->conn_state & L2CAP_CONN_SAR_SDU) | 2878 | if (chan->conn_state & L2CAP_CONN_SAR_SDU) |
2869 | goto drop; | 2879 | goto drop; |
2870 | 2880 | ||
2871 | pi->sdu_len = get_unaligned_le16(skb->data); | 2881 | pi->sdu_len = get_unaligned_le16(skb->data); |
@@ -2884,12 +2894,12 @@ static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 c | |||
2884 | 2894 | ||
2885 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); | 2895 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); |
2886 | 2896 | ||
2887 | pi->conn_state |= L2CAP_CONN_SAR_SDU; | 2897 | chan->conn_state |= L2CAP_CONN_SAR_SDU; |
2888 | pi->partial_sdu_len = skb->len; | 2898 | pi->partial_sdu_len = skb->len; |
2889 | break; | 2899 | break; |
2890 | 2900 | ||
2891 | case L2CAP_SDU_CONTINUE: | 2901 | case L2CAP_SDU_CONTINUE: |
2892 | if (!(pi->conn_state & L2CAP_CONN_SAR_SDU)) | 2902 | if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) |
2893 | goto disconnect; | 2903 | goto disconnect; |
2894 | 2904 | ||
2895 | if (!pi->sdu) | 2905 | if (!pi->sdu) |
@@ -2904,13 +2914,13 @@ static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 c | |||
2904 | break; | 2914 | break; |
2905 | 2915 | ||
2906 | case L2CAP_SDU_END: | 2916 | case L2CAP_SDU_END: |
2907 | if (!(pi->conn_state & L2CAP_CONN_SAR_SDU)) | 2917 | if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) |
2908 | goto disconnect; | 2918 | goto disconnect; |
2909 | 2919 | ||
2910 | if (!pi->sdu) | 2920 | if (!pi->sdu) |
2911 | goto disconnect; | 2921 | goto disconnect; |
2912 | 2922 | ||
2913 | if (!(pi->conn_state & L2CAP_CONN_SAR_RETRY)) { | 2923 | if (!(chan->conn_state & L2CAP_CONN_SAR_RETRY)) { |
2914 | pi->partial_sdu_len += skb->len; | 2924 | pi->partial_sdu_len += skb->len; |
2915 | 2925 | ||
2916 | if (pi->partial_sdu_len > pi->imtu) | 2926 | if (pi->partial_sdu_len > pi->imtu) |
@@ -2924,19 +2934,19 @@ static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 c | |||
2924 | 2934 | ||
2925 | _skb = skb_clone(pi->sdu, GFP_ATOMIC); | 2935 | _skb = skb_clone(pi->sdu, GFP_ATOMIC); |
2926 | if (!_skb) { | 2936 | if (!_skb) { |
2927 | pi->conn_state |= L2CAP_CONN_SAR_RETRY; | 2937 | chan->conn_state |= L2CAP_CONN_SAR_RETRY; |
2928 | return -ENOMEM; | 2938 | return -ENOMEM; |
2929 | } | 2939 | } |
2930 | 2940 | ||
2931 | err = sock_queue_rcv_skb(sk, _skb); | 2941 | err = sock_queue_rcv_skb(chan->sk, _skb); |
2932 | if (err < 0) { | 2942 | if (err < 0) { |
2933 | kfree_skb(_skb); | 2943 | kfree_skb(_skb); |
2934 | pi->conn_state |= L2CAP_CONN_SAR_RETRY; | 2944 | chan->conn_state |= L2CAP_CONN_SAR_RETRY; |
2935 | return err; | 2945 | return err; |
2936 | } | 2946 | } |
2937 | 2947 | ||
2938 | pi->conn_state &= ~L2CAP_CONN_SAR_RETRY; | 2948 | chan->conn_state &= ~L2CAP_CONN_SAR_RETRY; |
2939 | pi->conn_state &= ~L2CAP_CONN_SAR_SDU; | 2949 | chan->conn_state &= ~L2CAP_CONN_SAR_SDU; |
2940 | 2950 | ||
2941 | kfree_skb(pi->sdu); | 2951 | kfree_skb(pi->sdu); |
2942 | break; | 2952 | break; |
@@ -2950,13 +2960,14 @@ drop: | |||
2950 | pi->sdu = NULL; | 2960 | pi->sdu = NULL; |
2951 | 2961 | ||
2952 | disconnect: | 2962 | disconnect: |
2953 | l2cap_send_disconn_req(pi->conn, sk, ECONNRESET); | 2963 | l2cap_send_disconn_req(pi->conn, chan->sk, ECONNRESET); |
2954 | kfree_skb(skb); | 2964 | kfree_skb(skb); |
2955 | return 0; | 2965 | return 0; |
2956 | } | 2966 | } |
2957 | 2967 | ||
2958 | static int l2cap_try_push_rx_skb(struct sock *sk) | 2968 | static int l2cap_try_push_rx_skb(struct l2cap_chan *chan) |
2959 | { | 2969 | { |
2970 | struct sock *sk = chan->sk; | ||
2960 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 2971 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
2961 | struct sk_buff *skb; | 2972 | struct sk_buff *skb; |
2962 | u16 control; | 2973 | u16 control; |
@@ -2964,7 +2975,7 @@ static int l2cap_try_push_rx_skb(struct sock *sk) | |||
2964 | 2975 | ||
2965 | while ((skb = skb_dequeue(BUSY_QUEUE(sk)))) { | 2976 | while ((skb = skb_dequeue(BUSY_QUEUE(sk)))) { |
2966 | control = bt_cb(skb)->sar << L2CAP_CTRL_SAR_SHIFT; | 2977 | control = bt_cb(skb)->sar << L2CAP_CTRL_SAR_SHIFT; |
2967 | err = l2cap_ertm_reassembly_sdu(sk, skb, control); | 2978 | err = l2cap_ertm_reassembly_sdu(chan, skb, control); |
2968 | if (err < 0) { | 2979 | if (err < 0) { |
2969 | skb_queue_head(BUSY_QUEUE(sk), skb); | 2980 | skb_queue_head(BUSY_QUEUE(sk), skb); |
2970 | return -EBUSY; | 2981 | return -EBUSY; |
@@ -2973,22 +2984,22 @@ static int l2cap_try_push_rx_skb(struct sock *sk) | |||
2973 | pi->buffer_seq = (pi->buffer_seq + 1) % 64; | 2984 | pi->buffer_seq = (pi->buffer_seq + 1) % 64; |
2974 | } | 2985 | } |
2975 | 2986 | ||
2976 | if (!(pi->conn_state & L2CAP_CONN_RNR_SENT)) | 2987 | if (!(chan->conn_state & L2CAP_CONN_RNR_SENT)) |
2977 | goto done; | 2988 | goto done; |
2978 | 2989 | ||
2979 | control = pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 2990 | control = pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
2980 | control |= L2CAP_SUPER_RCV_READY | L2CAP_CTRL_POLL; | 2991 | control |= L2CAP_SUPER_RCV_READY | L2CAP_CTRL_POLL; |
2981 | l2cap_send_sframe(pi, control); | 2992 | l2cap_send_sframe(chan, control); |
2982 | l2cap_pi(sk)->retry_count = 1; | 2993 | l2cap_pi(sk)->retry_count = 1; |
2983 | 2994 | ||
2984 | del_timer(&pi->retrans_timer); | 2995 | del_timer(&pi->retrans_timer); |
2985 | __mod_monitor_timer(); | 2996 | __mod_monitor_timer(); |
2986 | 2997 | ||
2987 | l2cap_pi(sk)->conn_state |= L2CAP_CONN_WAIT_F; | 2998 | chan->conn_state |= L2CAP_CONN_WAIT_F; |
2988 | 2999 | ||
2989 | done: | 3000 | done: |
2990 | pi->conn_state &= ~L2CAP_CONN_LOCAL_BUSY; | 3001 | chan->conn_state &= ~L2CAP_CONN_LOCAL_BUSY; |
2991 | pi->conn_state &= ~L2CAP_CONN_RNR_SENT; | 3002 | chan->conn_state &= ~L2CAP_CONN_RNR_SENT; |
2992 | 3003 | ||
2993 | BT_DBG("sk %p, Exit local busy", sk); | 3004 | BT_DBG("sk %p, Exit local busy", sk); |
2994 | 3005 | ||
@@ -3032,7 +3043,7 @@ static void l2cap_busy_work(struct work_struct *work) | |||
3032 | if (err) | 3043 | if (err) |
3033 | break; | 3044 | break; |
3034 | 3045 | ||
3035 | if (l2cap_try_push_rx_skb(sk) == 0) | 3046 | if (l2cap_try_push_rx_skb(l2cap_pi(sk)->chan) == 0) |
3036 | break; | 3047 | break; |
3037 | } | 3048 | } |
3038 | 3049 | ||
@@ -3042,20 +3053,21 @@ static void l2cap_busy_work(struct work_struct *work) | |||
3042 | release_sock(sk); | 3053 | release_sock(sk); |
3043 | } | 3054 | } |
3044 | 3055 | ||
3045 | static int l2cap_push_rx_skb(struct sock *sk, struct sk_buff *skb, u16 control) | 3056 | static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 control) |
3046 | { | 3057 | { |
3058 | struct sock *sk = chan->sk; | ||
3047 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3059 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3048 | int sctrl, err; | 3060 | int sctrl, err; |
3049 | 3061 | ||
3050 | if (pi->conn_state & L2CAP_CONN_LOCAL_BUSY) { | 3062 | if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { |
3051 | bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; | 3063 | bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; |
3052 | __skb_queue_tail(BUSY_QUEUE(sk), skb); | 3064 | __skb_queue_tail(BUSY_QUEUE(sk), skb); |
3053 | return l2cap_try_push_rx_skb(sk); | 3065 | return l2cap_try_push_rx_skb(chan); |
3054 | 3066 | ||
3055 | 3067 | ||
3056 | } | 3068 | } |
3057 | 3069 | ||
3058 | err = l2cap_ertm_reassembly_sdu(sk, skb, control); | 3070 | err = l2cap_ertm_reassembly_sdu(chan, skb, control); |
3059 | if (err >= 0) { | 3071 | if (err >= 0) { |
3060 | pi->buffer_seq = (pi->buffer_seq + 1) % 64; | 3072 | pi->buffer_seq = (pi->buffer_seq + 1) % 64; |
3061 | return err; | 3073 | return err; |
@@ -3064,15 +3076,15 @@ static int l2cap_push_rx_skb(struct sock *sk, struct sk_buff *skb, u16 control) | |||
3064 | /* Busy Condition */ | 3076 | /* Busy Condition */ |
3065 | BT_DBG("sk %p, Enter local busy", sk); | 3077 | BT_DBG("sk %p, Enter local busy", sk); |
3066 | 3078 | ||
3067 | pi->conn_state |= L2CAP_CONN_LOCAL_BUSY; | 3079 | chan->conn_state |= L2CAP_CONN_LOCAL_BUSY; |
3068 | bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; | 3080 | bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; |
3069 | __skb_queue_tail(BUSY_QUEUE(sk), skb); | 3081 | __skb_queue_tail(BUSY_QUEUE(sk), skb); |
3070 | 3082 | ||
3071 | sctrl = pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 3083 | sctrl = pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
3072 | sctrl |= L2CAP_SUPER_RCV_NOT_READY; | 3084 | sctrl |= L2CAP_SUPER_RCV_NOT_READY; |
3073 | l2cap_send_sframe(pi, sctrl); | 3085 | l2cap_send_sframe(chan, sctrl); |
3074 | 3086 | ||
3075 | pi->conn_state |= L2CAP_CONN_RNR_SENT; | 3087 | chan->conn_state |= L2CAP_CONN_RNR_SENT; |
3076 | 3088 | ||
3077 | del_timer(&pi->ack_timer); | 3089 | del_timer(&pi->ack_timer); |
3078 | 3090 | ||
@@ -3081,9 +3093,9 @@ static int l2cap_push_rx_skb(struct sock *sk, struct sk_buff *skb, u16 control) | |||
3081 | return err; | 3093 | return err; |
3082 | } | 3094 | } |
3083 | 3095 | ||
3084 | static int l2cap_streaming_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 control) | 3096 | static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control) |
3085 | { | 3097 | { |
3086 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3098 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
3087 | struct sk_buff *_skb; | 3099 | struct sk_buff *_skb; |
3088 | int err = -EINVAL; | 3100 | int err = -EINVAL; |
3089 | 3101 | ||
@@ -3094,19 +3106,19 @@ static int l2cap_streaming_reassembly_sdu(struct sock *sk, struct sk_buff *skb, | |||
3094 | 3106 | ||
3095 | switch (control & L2CAP_CTRL_SAR) { | 3107 | switch (control & L2CAP_CTRL_SAR) { |
3096 | case L2CAP_SDU_UNSEGMENTED: | 3108 | case L2CAP_SDU_UNSEGMENTED: |
3097 | if (pi->conn_state & L2CAP_CONN_SAR_SDU) { | 3109 | if (chan->conn_state & L2CAP_CONN_SAR_SDU) { |
3098 | kfree_skb(pi->sdu); | 3110 | kfree_skb(pi->sdu); |
3099 | break; | 3111 | break; |
3100 | } | 3112 | } |
3101 | 3113 | ||
3102 | err = sock_queue_rcv_skb(sk, skb); | 3114 | err = sock_queue_rcv_skb(chan->sk, skb); |
3103 | if (!err) | 3115 | if (!err) |
3104 | return 0; | 3116 | return 0; |
3105 | 3117 | ||
3106 | break; | 3118 | break; |
3107 | 3119 | ||
3108 | case L2CAP_SDU_START: | 3120 | case L2CAP_SDU_START: |
3109 | if (pi->conn_state & L2CAP_CONN_SAR_SDU) { | 3121 | if (chan->conn_state & L2CAP_CONN_SAR_SDU) { |
3110 | kfree_skb(pi->sdu); | 3122 | kfree_skb(pi->sdu); |
3111 | break; | 3123 | break; |
3112 | } | 3124 | } |
@@ -3127,13 +3139,13 @@ static int l2cap_streaming_reassembly_sdu(struct sock *sk, struct sk_buff *skb, | |||
3127 | 3139 | ||
3128 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); | 3140 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); |
3129 | 3141 | ||
3130 | pi->conn_state |= L2CAP_CONN_SAR_SDU; | 3142 | chan->conn_state |= L2CAP_CONN_SAR_SDU; |
3131 | pi->partial_sdu_len = skb->len; | 3143 | pi->partial_sdu_len = skb->len; |
3132 | err = 0; | 3144 | err = 0; |
3133 | break; | 3145 | break; |
3134 | 3146 | ||
3135 | case L2CAP_SDU_CONTINUE: | 3147 | case L2CAP_SDU_CONTINUE: |
3136 | if (!(pi->conn_state & L2CAP_CONN_SAR_SDU)) | 3148 | if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) |
3137 | break; | 3149 | break; |
3138 | 3150 | ||
3139 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); | 3151 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); |
@@ -3147,12 +3159,12 @@ static int l2cap_streaming_reassembly_sdu(struct sock *sk, struct sk_buff *skb, | |||
3147 | break; | 3159 | break; |
3148 | 3160 | ||
3149 | case L2CAP_SDU_END: | 3161 | case L2CAP_SDU_END: |
3150 | if (!(pi->conn_state & L2CAP_CONN_SAR_SDU)) | 3162 | if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) |
3151 | break; | 3163 | break; |
3152 | 3164 | ||
3153 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); | 3165 | memcpy(skb_put(pi->sdu, skb->len), skb->data, skb->len); |
3154 | 3166 | ||
3155 | pi->conn_state &= ~L2CAP_CONN_SAR_SDU; | 3167 | chan->conn_state &= ~L2CAP_CONN_SAR_SDU; |
3156 | pi->partial_sdu_len += skb->len; | 3168 | pi->partial_sdu_len += skb->len; |
3157 | 3169 | ||
3158 | if (pi->partial_sdu_len > pi->imtu) | 3170 | if (pi->partial_sdu_len > pi->imtu) |
@@ -3160,7 +3172,7 @@ static int l2cap_streaming_reassembly_sdu(struct sock *sk, struct sk_buff *skb, | |||
3160 | 3172 | ||
3161 | if (pi->partial_sdu_len == pi->sdu_len) { | 3173 | if (pi->partial_sdu_len == pi->sdu_len) { |
3162 | _skb = skb_clone(pi->sdu, GFP_ATOMIC); | 3174 | _skb = skb_clone(pi->sdu, GFP_ATOMIC); |
3163 | err = sock_queue_rcv_skb(sk, _skb); | 3175 | err = sock_queue_rcv_skb(chan->sk, _skb); |
3164 | if (err < 0) | 3176 | if (err < 0) |
3165 | kfree_skb(_skb); | 3177 | kfree_skb(_skb); |
3166 | } | 3178 | } |
@@ -3175,8 +3187,9 @@ drop: | |||
3175 | return err; | 3187 | return err; |
3176 | } | 3188 | } |
3177 | 3189 | ||
3178 | static void l2cap_check_srej_gap(struct sock *sk, u8 tx_seq) | 3190 | static void l2cap_check_srej_gap(struct l2cap_chan *chan, u8 tx_seq) |
3179 | { | 3191 | { |
3192 | struct sock *sk = chan->sk; | ||
3180 | struct sk_buff *skb; | 3193 | struct sk_buff *skb; |
3181 | u16 control; | 3194 | u16 control; |
3182 | 3195 | ||
@@ -3186,16 +3199,16 @@ static void l2cap_check_srej_gap(struct sock *sk, u8 tx_seq) | |||
3186 | 3199 | ||
3187 | skb = skb_dequeue(SREJ_QUEUE(sk)); | 3200 | skb = skb_dequeue(SREJ_QUEUE(sk)); |
3188 | control = bt_cb(skb)->sar << L2CAP_CTRL_SAR_SHIFT; | 3201 | control = bt_cb(skb)->sar << L2CAP_CTRL_SAR_SHIFT; |
3189 | l2cap_ertm_reassembly_sdu(sk, skb, control); | 3202 | l2cap_ertm_reassembly_sdu(chan, skb, control); |
3190 | l2cap_pi(sk)->buffer_seq_srej = | 3203 | l2cap_pi(sk)->buffer_seq_srej = |
3191 | (l2cap_pi(sk)->buffer_seq_srej + 1) % 64; | 3204 | (l2cap_pi(sk)->buffer_seq_srej + 1) % 64; |
3192 | tx_seq = (tx_seq + 1) % 64; | 3205 | tx_seq = (tx_seq + 1) % 64; |
3193 | } | 3206 | } |
3194 | } | 3207 | } |
3195 | 3208 | ||
3196 | static void l2cap_resend_srejframe(struct sock *sk, u8 tx_seq) | 3209 | static void l2cap_resend_srejframe(struct l2cap_chan *chan, u8 tx_seq) |
3197 | { | 3210 | { |
3198 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3211 | struct sock *sk = chan->sk; |
3199 | struct srej_list *l, *tmp; | 3212 | struct srej_list *l, *tmp; |
3200 | u16 control; | 3213 | u16 control; |
3201 | 3214 | ||
@@ -3207,14 +3220,15 @@ static void l2cap_resend_srejframe(struct sock *sk, u8 tx_seq) | |||
3207 | } | 3220 | } |
3208 | control = L2CAP_SUPER_SELECT_REJECT; | 3221 | control = L2CAP_SUPER_SELECT_REJECT; |
3209 | control |= l->tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 3222 | control |= l->tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
3210 | l2cap_send_sframe(pi, control); | 3223 | l2cap_send_sframe(chan, control); |
3211 | list_del(&l->list); | 3224 | list_del(&l->list); |
3212 | list_add_tail(&l->list, SREJ_LIST(sk)); | 3225 | list_add_tail(&l->list, SREJ_LIST(sk)); |
3213 | } | 3226 | } |
3214 | } | 3227 | } |
3215 | 3228 | ||
3216 | static void l2cap_send_srejframe(struct sock *sk, u8 tx_seq) | 3229 | static void l2cap_send_srejframe(struct l2cap_chan *chan, u8 tx_seq) |
3217 | { | 3230 | { |
3231 | struct sock *sk = chan->sk; | ||
3218 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3232 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3219 | struct srej_list *new; | 3233 | struct srej_list *new; |
3220 | u16 control; | 3234 | u16 control; |
@@ -3222,7 +3236,7 @@ static void l2cap_send_srejframe(struct sock *sk, u8 tx_seq) | |||
3222 | while (tx_seq != pi->expected_tx_seq) { | 3236 | while (tx_seq != pi->expected_tx_seq) { |
3223 | control = L2CAP_SUPER_SELECT_REJECT; | 3237 | control = L2CAP_SUPER_SELECT_REJECT; |
3224 | control |= pi->expected_tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; | 3238 | control |= pi->expected_tx_seq << L2CAP_CTRL_REQSEQ_SHIFT; |
3225 | l2cap_send_sframe(pi, control); | 3239 | l2cap_send_sframe(chan, control); |
3226 | 3240 | ||
3227 | new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC); | 3241 | new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC); |
3228 | new->tx_seq = pi->expected_tx_seq; | 3242 | new->tx_seq = pi->expected_tx_seq; |
@@ -3232,8 +3246,9 @@ static void l2cap_send_srejframe(struct sock *sk, u8 tx_seq) | |||
3232 | pi->expected_tx_seq = (pi->expected_tx_seq + 1) % 64; | 3246 | pi->expected_tx_seq = (pi->expected_tx_seq + 1) % 64; |
3233 | } | 3247 | } |
3234 | 3248 | ||
3235 | static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, struct sk_buff *skb) | 3249 | static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb) |
3236 | { | 3250 | { |
3251 | struct sock *sk = chan->sk; | ||
3237 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3252 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3238 | u8 tx_seq = __get_txseq(rx_control); | 3253 | u8 tx_seq = __get_txseq(rx_control); |
3239 | u8 req_seq = __get_reqseq(rx_control); | 3254 | u8 req_seq = __get_reqseq(rx_control); |
@@ -3242,15 +3257,15 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3242 | int num_to_ack = (pi->tx_win/6) + 1; | 3257 | int num_to_ack = (pi->tx_win/6) + 1; |
3243 | int err = 0; | 3258 | int err = 0; |
3244 | 3259 | ||
3245 | BT_DBG("sk %p len %d tx_seq %d rx_control 0x%4.4x", sk, skb->len, tx_seq, | 3260 | BT_DBG("chan %p len %d tx_seq %d rx_control 0x%4.4x", chan, skb->len, |
3246 | rx_control); | 3261 | tx_seq, rx_control); |
3247 | 3262 | ||
3248 | if (L2CAP_CTRL_FINAL & rx_control && | 3263 | if (L2CAP_CTRL_FINAL & rx_control && |
3249 | l2cap_pi(sk)->conn_state & L2CAP_CONN_WAIT_F) { | 3264 | chan->conn_state & L2CAP_CONN_WAIT_F) { |
3250 | del_timer(&pi->monitor_timer); | 3265 | del_timer(&pi->monitor_timer); |
3251 | if (pi->unacked_frames > 0) | 3266 | if (pi->unacked_frames > 0) |
3252 | __mod_retrans_timer(); | 3267 | __mod_retrans_timer(); |
3253 | pi->conn_state &= ~L2CAP_CONN_WAIT_F; | 3268 | chan->conn_state &= ~L2CAP_CONN_WAIT_F; |
3254 | } | 3269 | } |
3255 | 3270 | ||
3256 | pi->expected_ack_seq = req_seq; | 3271 | pi->expected_ack_seq = req_seq; |
@@ -3269,25 +3284,25 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3269 | goto drop; | 3284 | goto drop; |
3270 | } | 3285 | } |
3271 | 3286 | ||
3272 | if (pi->conn_state == L2CAP_CONN_LOCAL_BUSY) | 3287 | if (chan->conn_state == L2CAP_CONN_LOCAL_BUSY) |
3273 | goto drop; | 3288 | goto drop; |
3274 | 3289 | ||
3275 | if (pi->conn_state & L2CAP_CONN_SREJ_SENT) { | 3290 | if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { |
3276 | struct srej_list *first; | 3291 | struct srej_list *first; |
3277 | 3292 | ||
3278 | first = list_first_entry(SREJ_LIST(sk), | 3293 | first = list_first_entry(SREJ_LIST(sk), |
3279 | struct srej_list, list); | 3294 | struct srej_list, list); |
3280 | if (tx_seq == first->tx_seq) { | 3295 | if (tx_seq == first->tx_seq) { |
3281 | l2cap_add_to_srej_queue(sk, skb, tx_seq, sar); | 3296 | l2cap_add_to_srej_queue(sk, skb, tx_seq, sar); |
3282 | l2cap_check_srej_gap(sk, tx_seq); | 3297 | l2cap_check_srej_gap(chan, tx_seq); |
3283 | 3298 | ||
3284 | list_del(&first->list); | 3299 | list_del(&first->list); |
3285 | kfree(first); | 3300 | kfree(first); |
3286 | 3301 | ||
3287 | if (list_empty(SREJ_LIST(sk))) { | 3302 | if (list_empty(SREJ_LIST(sk))) { |
3288 | pi->buffer_seq = pi->buffer_seq_srej; | 3303 | pi->buffer_seq = pi->buffer_seq_srej; |
3289 | pi->conn_state &= ~L2CAP_CONN_SREJ_SENT; | 3304 | chan->conn_state &= ~L2CAP_CONN_SREJ_SENT; |
3290 | l2cap_send_ack(pi); | 3305 | l2cap_send_ack(chan); |
3291 | BT_DBG("sk %p, Exit SREJ_SENT", sk); | 3306 | BT_DBG("sk %p, Exit SREJ_SENT", sk); |
3292 | } | 3307 | } |
3293 | } else { | 3308 | } else { |
@@ -3299,11 +3314,11 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3299 | 3314 | ||
3300 | list_for_each_entry(l, SREJ_LIST(sk), list) { | 3315 | list_for_each_entry(l, SREJ_LIST(sk), list) { |
3301 | if (l->tx_seq == tx_seq) { | 3316 | if (l->tx_seq == tx_seq) { |
3302 | l2cap_resend_srejframe(sk, tx_seq); | 3317 | l2cap_resend_srejframe(chan, tx_seq); |
3303 | return 0; | 3318 | return 0; |
3304 | } | 3319 | } |
3305 | } | 3320 | } |
3306 | l2cap_send_srejframe(sk, tx_seq); | 3321 | l2cap_send_srejframe(chan, tx_seq); |
3307 | } | 3322 | } |
3308 | } else { | 3323 | } else { |
3309 | expected_tx_seq_offset = | 3324 | expected_tx_seq_offset = |
@@ -3315,7 +3330,7 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3315 | if (tx_seq_offset < expected_tx_seq_offset) | 3330 | if (tx_seq_offset < expected_tx_seq_offset) |
3316 | goto drop; | 3331 | goto drop; |
3317 | 3332 | ||
3318 | pi->conn_state |= L2CAP_CONN_SREJ_SENT; | 3333 | chan->conn_state |= L2CAP_CONN_SREJ_SENT; |
3319 | 3334 | ||
3320 | BT_DBG("sk %p, Enter SREJ", sk); | 3335 | BT_DBG("sk %p, Enter SREJ", sk); |
3321 | 3336 | ||
@@ -3326,9 +3341,9 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3326 | __skb_queue_head_init(BUSY_QUEUE(sk)); | 3341 | __skb_queue_head_init(BUSY_QUEUE(sk)); |
3327 | l2cap_add_to_srej_queue(sk, skb, tx_seq, sar); | 3342 | l2cap_add_to_srej_queue(sk, skb, tx_seq, sar); |
3328 | 3343 | ||
3329 | pi->conn_state |= L2CAP_CONN_SEND_PBIT; | 3344 | chan->conn_state |= L2CAP_CONN_SEND_PBIT; |
3330 | 3345 | ||
3331 | l2cap_send_srejframe(sk, tx_seq); | 3346 | l2cap_send_srejframe(chan, tx_seq); |
3332 | 3347 | ||
3333 | del_timer(&pi->ack_timer); | 3348 | del_timer(&pi->ack_timer); |
3334 | } | 3349 | } |
@@ -3337,29 +3352,29 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str | |||
3337 | expected: | 3352 | expected: |
3338 | pi->expected_tx_seq = (pi->expected_tx_seq + 1) % 64; | 3353 | pi->expected_tx_seq = (pi->expected_tx_seq + 1) % 64; |
3339 | 3354 | ||
3340 | if (pi->conn_state & L2CAP_CONN_SREJ_SENT) { | 3355 | if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { |
3341 | bt_cb(skb)->tx_seq = tx_seq; | 3356 | bt_cb(skb)->tx_seq = tx_seq; |
3342 | bt_cb(skb)->sar = sar; | 3357 | bt_cb(skb)->sar = sar; |
3343 | __skb_queue_tail(SREJ_QUEUE(sk), skb); | 3358 | __skb_queue_tail(SREJ_QUEUE(sk), skb); |
3344 | return 0; | 3359 | return 0; |
3345 | } | 3360 | } |
3346 | 3361 | ||
3347 | err = l2cap_push_rx_skb(sk, skb, rx_control); | 3362 | err = l2cap_push_rx_skb(chan, skb, rx_control); |
3348 | if (err < 0) | 3363 | if (err < 0) |
3349 | return 0; | 3364 | return 0; |
3350 | 3365 | ||
3351 | if (rx_control & L2CAP_CTRL_FINAL) { | 3366 | if (rx_control & L2CAP_CTRL_FINAL) { |
3352 | if (pi->conn_state & L2CAP_CONN_REJ_ACT) | 3367 | if (chan->conn_state & L2CAP_CONN_REJ_ACT) |
3353 | pi->conn_state &= ~L2CAP_CONN_REJ_ACT; | 3368 | chan->conn_state &= ~L2CAP_CONN_REJ_ACT; |
3354 | else | 3369 | else |
3355 | l2cap_retransmit_frames(sk); | 3370 | l2cap_retransmit_frames(chan); |
3356 | } | 3371 | } |
3357 | 3372 | ||
3358 | __mod_ack_timer(); | 3373 | __mod_ack_timer(); |
3359 | 3374 | ||
3360 | pi->num_acked = (pi->num_acked + 1) % num_to_ack; | 3375 | pi->num_acked = (pi->num_acked + 1) % num_to_ack; |
3361 | if (pi->num_acked == num_to_ack - 1) | 3376 | if (pi->num_acked == num_to_ack - 1) |
3362 | l2cap_send_ack(pi); | 3377 | l2cap_send_ack(chan); |
3363 | 3378 | ||
3364 | return 0; | 3379 | return 0; |
3365 | 3380 | ||
@@ -3368,8 +3383,9 @@ drop: | |||
3368 | return 0; | 3383 | return 0; |
3369 | } | 3384 | } |
3370 | 3385 | ||
3371 | static inline void l2cap_data_channel_rrframe(struct sock *sk, u16 rx_control) | 3386 | static inline void l2cap_data_channel_rrframe(struct l2cap_chan *chan, u16 rx_control) |
3372 | { | 3387 | { |
3388 | struct sock *sk = chan->sk; | ||
3373 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3389 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3374 | 3390 | ||
3375 | BT_DBG("sk %p, req_seq %d ctrl 0x%4.4x", sk, __get_reqseq(rx_control), | 3391 | BT_DBG("sk %p, req_seq %d ctrl 0x%4.4x", sk, __get_reqseq(rx_control), |
@@ -3379,154 +3395,156 @@ static inline void l2cap_data_channel_rrframe(struct sock *sk, u16 rx_control) | |||
3379 | l2cap_drop_acked_frames(sk); | 3395 | l2cap_drop_acked_frames(sk); |
3380 | 3396 | ||
3381 | if (rx_control & L2CAP_CTRL_POLL) { | 3397 | if (rx_control & L2CAP_CTRL_POLL) { |
3382 | pi->conn_state |= L2CAP_CONN_SEND_FBIT; | 3398 | chan->conn_state |= L2CAP_CONN_SEND_FBIT; |
3383 | if (pi->conn_state & L2CAP_CONN_SREJ_SENT) { | 3399 | if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { |
3384 | if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) && | 3400 | if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && |
3385 | (pi->unacked_frames > 0)) | 3401 | (pi->unacked_frames > 0)) |
3386 | __mod_retrans_timer(); | 3402 | __mod_retrans_timer(); |
3387 | 3403 | ||
3388 | pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; | 3404 | chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; |
3389 | l2cap_send_srejtail(sk); | 3405 | l2cap_send_srejtail(chan); |
3390 | } else { | 3406 | } else { |
3391 | l2cap_send_i_or_rr_or_rnr(sk); | 3407 | l2cap_send_i_or_rr_or_rnr(chan); |
3392 | } | 3408 | } |
3393 | 3409 | ||
3394 | } else if (rx_control & L2CAP_CTRL_FINAL) { | 3410 | } else if (rx_control & L2CAP_CTRL_FINAL) { |
3395 | pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; | 3411 | chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; |
3396 | 3412 | ||
3397 | if (pi->conn_state & L2CAP_CONN_REJ_ACT) | 3413 | if (chan->conn_state & L2CAP_CONN_REJ_ACT) |
3398 | pi->conn_state &= ~L2CAP_CONN_REJ_ACT; | 3414 | chan->conn_state &= ~L2CAP_CONN_REJ_ACT; |
3399 | else | 3415 | else |
3400 | l2cap_retransmit_frames(sk); | 3416 | l2cap_retransmit_frames(chan); |
3401 | 3417 | ||
3402 | } else { | 3418 | } else { |
3403 | if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) && | 3419 | if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && |
3404 | (pi->unacked_frames > 0)) | 3420 | (pi->unacked_frames > 0)) |
3405 | __mod_retrans_timer(); | 3421 | __mod_retrans_timer(); |
3406 | 3422 | ||
3407 | pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; | 3423 | chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; |
3408 | if (pi->conn_state & L2CAP_CONN_SREJ_SENT) | 3424 | if (chan->conn_state & L2CAP_CONN_SREJ_SENT) |
3409 | l2cap_send_ack(pi); | 3425 | l2cap_send_ack(chan); |
3410 | else | 3426 | else |
3411 | l2cap_ertm_send(sk); | 3427 | l2cap_ertm_send(chan); |
3412 | } | 3428 | } |
3413 | } | 3429 | } |
3414 | 3430 | ||
3415 | static inline void l2cap_data_channel_rejframe(struct sock *sk, u16 rx_control) | 3431 | static inline void l2cap_data_channel_rejframe(struct l2cap_chan *chan, u16 rx_control) |
3416 | { | 3432 | { |
3417 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3433 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
3418 | u8 tx_seq = __get_reqseq(rx_control); | 3434 | u8 tx_seq = __get_reqseq(rx_control); |
3419 | 3435 | ||
3420 | BT_DBG("sk %p, req_seq %d ctrl 0x%4.4x", sk, tx_seq, rx_control); | 3436 | BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); |
3421 | 3437 | ||
3422 | pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; | 3438 | chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; |
3423 | 3439 | ||
3424 | pi->expected_ack_seq = tx_seq; | 3440 | pi->expected_ack_seq = tx_seq; |
3425 | l2cap_drop_acked_frames(sk); | 3441 | l2cap_drop_acked_frames(chan->sk); |
3426 | 3442 | ||
3427 | if (rx_control & L2CAP_CTRL_FINAL) { | 3443 | if (rx_control & L2CAP_CTRL_FINAL) { |
3428 | if (pi->conn_state & L2CAP_CONN_REJ_ACT) | 3444 | if (chan->conn_state & L2CAP_CONN_REJ_ACT) |
3429 | pi->conn_state &= ~L2CAP_CONN_REJ_ACT; | 3445 | chan->conn_state &= ~L2CAP_CONN_REJ_ACT; |
3430 | else | 3446 | else |
3431 | l2cap_retransmit_frames(sk); | 3447 | l2cap_retransmit_frames(chan); |
3432 | } else { | 3448 | } else { |
3433 | l2cap_retransmit_frames(sk); | 3449 | l2cap_retransmit_frames(chan); |
3434 | 3450 | ||
3435 | if (pi->conn_state & L2CAP_CONN_WAIT_F) | 3451 | if (chan->conn_state & L2CAP_CONN_WAIT_F) |
3436 | pi->conn_state |= L2CAP_CONN_REJ_ACT; | 3452 | chan->conn_state |= L2CAP_CONN_REJ_ACT; |
3437 | } | 3453 | } |
3438 | } | 3454 | } |
3439 | static inline void l2cap_data_channel_srejframe(struct sock *sk, u16 rx_control) | 3455 | static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u16 rx_control) |
3440 | { | 3456 | { |
3441 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3457 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
3442 | u8 tx_seq = __get_reqseq(rx_control); | 3458 | u8 tx_seq = __get_reqseq(rx_control); |
3443 | 3459 | ||
3444 | BT_DBG("sk %p, req_seq %d ctrl 0x%4.4x", sk, tx_seq, rx_control); | 3460 | BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); |
3445 | 3461 | ||
3446 | pi->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; | 3462 | chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; |
3447 | 3463 | ||
3448 | if (rx_control & L2CAP_CTRL_POLL) { | 3464 | if (rx_control & L2CAP_CTRL_POLL) { |
3449 | pi->expected_ack_seq = tx_seq; | 3465 | pi->expected_ack_seq = tx_seq; |
3450 | l2cap_drop_acked_frames(sk); | 3466 | l2cap_drop_acked_frames(chan->sk); |
3451 | 3467 | ||
3452 | pi->conn_state |= L2CAP_CONN_SEND_FBIT; | 3468 | chan->conn_state |= L2CAP_CONN_SEND_FBIT; |
3453 | l2cap_retransmit_one_frame(sk, tx_seq); | 3469 | l2cap_retransmit_one_frame(chan, tx_seq); |
3454 | 3470 | ||
3455 | l2cap_ertm_send(sk); | 3471 | l2cap_ertm_send(chan); |
3456 | 3472 | ||
3457 | if (pi->conn_state & L2CAP_CONN_WAIT_F) { | 3473 | if (chan->conn_state & L2CAP_CONN_WAIT_F) { |
3458 | pi->srej_save_reqseq = tx_seq; | 3474 | pi->srej_save_reqseq = tx_seq; |
3459 | pi->conn_state |= L2CAP_CONN_SREJ_ACT; | 3475 | chan->conn_state |= L2CAP_CONN_SREJ_ACT; |
3460 | } | 3476 | } |
3461 | } else if (rx_control & L2CAP_CTRL_FINAL) { | 3477 | } else if (rx_control & L2CAP_CTRL_FINAL) { |
3462 | if ((pi->conn_state & L2CAP_CONN_SREJ_ACT) && | 3478 | if ((chan->conn_state & L2CAP_CONN_SREJ_ACT) && |
3463 | pi->srej_save_reqseq == tx_seq) | 3479 | pi->srej_save_reqseq == tx_seq) |
3464 | pi->conn_state &= ~L2CAP_CONN_SREJ_ACT; | 3480 | chan->conn_state &= ~L2CAP_CONN_SREJ_ACT; |
3465 | else | 3481 | else |
3466 | l2cap_retransmit_one_frame(sk, tx_seq); | 3482 | l2cap_retransmit_one_frame(chan, tx_seq); |
3467 | } else { | 3483 | } else { |
3468 | l2cap_retransmit_one_frame(sk, tx_seq); | 3484 | l2cap_retransmit_one_frame(chan, tx_seq); |
3469 | if (pi->conn_state & L2CAP_CONN_WAIT_F) { | 3485 | if (chan->conn_state & L2CAP_CONN_WAIT_F) { |
3470 | pi->srej_save_reqseq = tx_seq; | 3486 | pi->srej_save_reqseq = tx_seq; |
3471 | pi->conn_state |= L2CAP_CONN_SREJ_ACT; | 3487 | chan->conn_state |= L2CAP_CONN_SREJ_ACT; |
3472 | } | 3488 | } |
3473 | } | 3489 | } |
3474 | } | 3490 | } |
3475 | 3491 | ||
3476 | static inline void l2cap_data_channel_rnrframe(struct sock *sk, u16 rx_control) | 3492 | static inline void l2cap_data_channel_rnrframe(struct l2cap_chan *chan, u16 rx_control) |
3477 | { | 3493 | { |
3478 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3494 | struct l2cap_pinfo *pi = l2cap_pi(chan->sk); |
3479 | u8 tx_seq = __get_reqseq(rx_control); | 3495 | u8 tx_seq = __get_reqseq(rx_control); |
3480 | 3496 | ||
3481 | BT_DBG("sk %p, req_seq %d ctrl 0x%4.4x", sk, tx_seq, rx_control); | 3497 | BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); |
3482 | 3498 | ||
3483 | pi->conn_state |= L2CAP_CONN_REMOTE_BUSY; | 3499 | chan->conn_state |= L2CAP_CONN_REMOTE_BUSY; |
3484 | pi->expected_ack_seq = tx_seq; | 3500 | pi->expected_ack_seq = tx_seq; |
3485 | l2cap_drop_acked_frames(sk); | 3501 | l2cap_drop_acked_frames(chan->sk); |
3486 | 3502 | ||
3487 | if (rx_control & L2CAP_CTRL_POLL) | 3503 | if (rx_control & L2CAP_CTRL_POLL) |
3488 | pi->conn_state |= L2CAP_CONN_SEND_FBIT; | 3504 | chan->conn_state |= L2CAP_CONN_SEND_FBIT; |
3489 | 3505 | ||
3490 | if (!(pi->conn_state & L2CAP_CONN_SREJ_SENT)) { | 3506 | if (!(chan->conn_state & L2CAP_CONN_SREJ_SENT)) { |
3491 | del_timer(&pi->retrans_timer); | 3507 | del_timer(&pi->retrans_timer); |
3492 | if (rx_control & L2CAP_CTRL_POLL) | 3508 | if (rx_control & L2CAP_CTRL_POLL) |
3493 | l2cap_send_rr_or_rnr(pi, L2CAP_CTRL_FINAL); | 3509 | l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_FINAL); |
3494 | return; | 3510 | return; |
3495 | } | 3511 | } |
3496 | 3512 | ||
3497 | if (rx_control & L2CAP_CTRL_POLL) | 3513 | if (rx_control & L2CAP_CTRL_POLL) |
3498 | l2cap_send_srejtail(sk); | 3514 | l2cap_send_srejtail(chan); |
3499 | else | 3515 | else |
3500 | l2cap_send_sframe(pi, L2CAP_SUPER_RCV_READY); | 3516 | l2cap_send_sframe(chan, L2CAP_SUPER_RCV_READY); |
3501 | } | 3517 | } |
3502 | 3518 | ||
3503 | static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, struct sk_buff *skb) | 3519 | static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb) |
3504 | { | 3520 | { |
3505 | BT_DBG("sk %p rx_control 0x%4.4x len %d", sk, rx_control, skb->len); | 3521 | struct sock *sk = chan->sk; |
3522 | |||
3523 | BT_DBG("chan %p rx_control 0x%4.4x len %d", chan, rx_control, skb->len); | ||
3506 | 3524 | ||
3507 | if (L2CAP_CTRL_FINAL & rx_control && | 3525 | if (L2CAP_CTRL_FINAL & rx_control && |
3508 | l2cap_pi(sk)->conn_state & L2CAP_CONN_WAIT_F) { | 3526 | chan->conn_state & L2CAP_CONN_WAIT_F) { |
3509 | del_timer(&l2cap_pi(sk)->monitor_timer); | 3527 | del_timer(&l2cap_pi(sk)->monitor_timer); |
3510 | if (l2cap_pi(sk)->unacked_frames > 0) | 3528 | if (l2cap_pi(sk)->unacked_frames > 0) |
3511 | __mod_retrans_timer(); | 3529 | __mod_retrans_timer(); |
3512 | l2cap_pi(sk)->conn_state &= ~L2CAP_CONN_WAIT_F; | 3530 | chan->conn_state &= ~L2CAP_CONN_WAIT_F; |
3513 | } | 3531 | } |
3514 | 3532 | ||
3515 | switch (rx_control & L2CAP_CTRL_SUPERVISE) { | 3533 | switch (rx_control & L2CAP_CTRL_SUPERVISE) { |
3516 | case L2CAP_SUPER_RCV_READY: | 3534 | case L2CAP_SUPER_RCV_READY: |
3517 | l2cap_data_channel_rrframe(sk, rx_control); | 3535 | l2cap_data_channel_rrframe(chan, rx_control); |
3518 | break; | 3536 | break; |
3519 | 3537 | ||
3520 | case L2CAP_SUPER_REJECT: | 3538 | case L2CAP_SUPER_REJECT: |
3521 | l2cap_data_channel_rejframe(sk, rx_control); | 3539 | l2cap_data_channel_rejframe(chan, rx_control); |
3522 | break; | 3540 | break; |
3523 | 3541 | ||
3524 | case L2CAP_SUPER_SELECT_REJECT: | 3542 | case L2CAP_SUPER_SELECT_REJECT: |
3525 | l2cap_data_channel_srejframe(sk, rx_control); | 3543 | l2cap_data_channel_srejframe(chan, rx_control); |
3526 | break; | 3544 | break; |
3527 | 3545 | ||
3528 | case L2CAP_SUPER_RCV_NOT_READY: | 3546 | case L2CAP_SUPER_RCV_NOT_READY: |
3529 | l2cap_data_channel_rnrframe(sk, rx_control); | 3547 | l2cap_data_channel_rnrframe(chan, rx_control); |
3530 | break; | 3548 | break; |
3531 | } | 3549 | } |
3532 | 3550 | ||
@@ -3536,6 +3554,7 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str | |||
3536 | 3554 | ||
3537 | static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) | 3555 | static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) |
3538 | { | 3556 | { |
3557 | struct l2cap_chan *chan = l2cap_pi(sk)->chan; | ||
3539 | struct l2cap_pinfo *pi = l2cap_pi(sk); | 3558 | struct l2cap_pinfo *pi = l2cap_pi(sk); |
3540 | u16 control; | 3559 | u16 control; |
3541 | u8 req_seq; | 3560 | u8 req_seq; |
@@ -3586,7 +3605,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) | |||
3586 | goto drop; | 3605 | goto drop; |
3587 | } | 3606 | } |
3588 | 3607 | ||
3589 | l2cap_data_channel_iframe(sk, control, skb); | 3608 | l2cap_data_channel_iframe(chan, control, skb); |
3590 | } else { | 3609 | } else { |
3591 | if (len != 0) { | 3610 | if (len != 0) { |
3592 | BT_ERR("%d", len); | 3611 | BT_ERR("%d", len); |
@@ -3594,7 +3613,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) | |||
3594 | goto drop; | 3613 | goto drop; |
3595 | } | 3614 | } |
3596 | 3615 | ||
3597 | l2cap_data_channel_sframe(sk, control, skb); | 3616 | l2cap_data_channel_sframe(chan, control, skb); |
3598 | } | 3617 | } |
3599 | 3618 | ||
3600 | return 0; | 3619 | return 0; |
@@ -3675,7 +3694,7 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk | |||
3675 | else | 3694 | else |
3676 | pi->expected_tx_seq = (tx_seq + 1) % 64; | 3695 | pi->expected_tx_seq = (tx_seq + 1) % 64; |
3677 | 3696 | ||
3678 | l2cap_streaming_reassembly_sdu(sk, skb, control); | 3697 | l2cap_streaming_reassembly_sdu(chan, skb, control); |
3679 | 3698 | ||
3680 | goto done; | 3699 | goto done; |
3681 | 3700 | ||
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 450f57b106b9..66ec966ffc18 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -778,14 +778,16 @@ static int l2cap_sock_sendmsg(struct kiocb *iocb, struct socket *sock, struct ms | |||
778 | 778 | ||
779 | if (pi->mode == L2CAP_MODE_STREAMING) { | 779 | if (pi->mode == L2CAP_MODE_STREAMING) { |
780 | l2cap_streaming_send(sk); | 780 | l2cap_streaming_send(sk); |
781 | } else { | 781 | err = len; |
782 | if ((pi->conn_state & L2CAP_CONN_REMOTE_BUSY) && | 782 | break; |
783 | (pi->conn_state & L2CAP_CONN_WAIT_F)) { | 783 | } |
784 | err = len; | 784 | |
785 | break; | 785 | if ((pi->chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && |
786 | } | 786 | (pi->chan->conn_state & L2CAP_CONN_WAIT_F)) { |
787 | err = l2cap_ertm_send(sk); | 787 | err = len; |
788 | break; | ||
788 | } | 789 | } |
790 | err = l2cap_ertm_send(pi->chan); | ||
789 | 791 | ||
790 | if (err >= 0) | 792 | if (err >= 0) |
791 | err = len; | 793 | err = len; |