aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorGustavo F. Padovan <padovan@profusion.mobi>2011-06-10 20:28:49 -0400
committerGustavo F. Padovan <padovan@profusion.mobi>2011-06-16 17:57:15 -0400
commite2ab43536c53ba112a0adfb4c0dba286544c41f6 (patch)
tree5387e283430437f54c743fa2d9b33538e9850594 /net
parentc1360a1cf35117d6f3898cb5183ce4349d06714c (diff)
Bluetooth: Use bit operations on conn_state
Instead of setting bits manually we use set_bit, test_bit, etc. Also remove L2CAP_ prefix from macros. Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/l2cap_core.c161
1 files changed, 74 insertions, 87 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b4e927eb174e..25f31f4c7d08 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -584,15 +584,11 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
584 count = min_t(unsigned int, conn->mtu, hlen); 584 count = min_t(unsigned int, conn->mtu, hlen);
585 control |= L2CAP_CTRL_FRAME_TYPE; 585 control |= L2CAP_CTRL_FRAME_TYPE;
586 586
587 if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { 587 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
588 control |= L2CAP_CTRL_FINAL; 588 control |= L2CAP_CTRL_FINAL;
589 chan->conn_state &= ~L2CAP_CONN_SEND_FBIT;
590 }
591 589
592 if (chan->conn_state & L2CAP_CONN_SEND_PBIT) { 590 if (test_and_clear_bit(CONN_SEND_PBIT, &chan->conn_state))
593 control |= L2CAP_CTRL_POLL; 591 control |= L2CAP_CTRL_POLL;
594 chan->conn_state &= ~L2CAP_CONN_SEND_PBIT;
595 }
596 592
597 skb = bt_skb_alloc(count, GFP_ATOMIC); 593 skb = bt_skb_alloc(count, GFP_ATOMIC);
598 if (!skb) 594 if (!skb)
@@ -620,9 +616,9 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
620 616
621static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control) 617static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control)
622{ 618{
623 if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { 619 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
624 control |= L2CAP_SUPER_RCV_NOT_READY; 620 control |= L2CAP_SUPER_RCV_NOT_READY;
625 chan->conn_state |= L2CAP_CONN_RNR_SENT; 621 set_bit(CONN_RNR_SENT, &chan->conn_state);
626 } else 622 } else
627 control |= L2CAP_SUPER_RCV_READY; 623 control |= L2CAP_SUPER_RCV_READY;
628 624
@@ -1223,7 +1219,7 @@ static void l2cap_retrans_timeout(unsigned long arg)
1223 chan->retry_count = 1; 1219 chan->retry_count = 1;
1224 __set_monitor_timer(chan); 1220 __set_monitor_timer(chan);
1225 1221
1226 chan->conn_state |= L2CAP_CONN_WAIT_F; 1222 set_bit(CONN_WAIT_F, &chan->conn_state);
1227 1223
1228 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL); 1224 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL);
1229 bh_unlock_sock(sk); 1225 bh_unlock_sock(sk);
@@ -1314,10 +1310,8 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
1314 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1310 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1315 control &= L2CAP_CTRL_SAR; 1311 control &= L2CAP_CTRL_SAR;
1316 1312
1317 if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { 1313 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
1318 control |= L2CAP_CTRL_FINAL; 1314 control |= L2CAP_CTRL_FINAL;
1319 chan->conn_state &= ~L2CAP_CONN_SEND_FBIT;
1320 }
1321 1315
1322 control |= (chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1316 control |= (chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1323 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1317 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
@@ -1356,10 +1350,9 @@ int l2cap_ertm_send(struct l2cap_chan *chan)
1356 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1350 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1357 control &= L2CAP_CTRL_SAR; 1351 control &= L2CAP_CTRL_SAR;
1358 1352
1359 if (chan->conn_state & L2CAP_CONN_SEND_FBIT) { 1353 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
1360 control |= L2CAP_CTRL_FINAL; 1354 control |= L2CAP_CTRL_FINAL;
1361 chan->conn_state &= ~L2CAP_CONN_SEND_FBIT; 1355
1362 }
1363 control |= (chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1356 control |= (chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1364 | (chan->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1357 | (chan->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
1365 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE); 1358 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
@@ -1411,9 +1404,9 @@ static void l2cap_send_ack(struct l2cap_chan *chan)
1411 1404
1412 control |= chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; 1405 control |= chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT;
1413 1406
1414 if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { 1407 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
1415 control |= L2CAP_SUPER_RCV_NOT_READY; 1408 control |= L2CAP_SUPER_RCV_NOT_READY;
1416 chan->conn_state |= L2CAP_CONN_RNR_SENT; 1409 set_bit(CONN_RNR_SENT, &chan->conn_state);
1417 l2cap_send_sframe(chan, control); 1410 l2cap_send_sframe(chan, control);
1418 return; 1411 return;
1419 } 1412 }
@@ -1680,8 +1673,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
1680 break; 1673 break;
1681 } 1674 }
1682 1675
1683 if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && 1676 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) &&
1684 (chan->conn_state & L2CAP_CONN_WAIT_F)) { 1677 test_bit(CONN_WAIT_F, &chan->conn_state)) {
1685 err = len; 1678 err = len;
1686 break; 1679 break;
1687 } 1680 }
@@ -3071,18 +3064,18 @@ static inline void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan)
3071 3064
3072 control |= chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; 3065 control |= chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT;
3073 3066
3074 if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { 3067 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
3075 control |= L2CAP_SUPER_RCV_NOT_READY; 3068 control |= L2CAP_SUPER_RCV_NOT_READY;
3076 l2cap_send_sframe(chan, control); 3069 l2cap_send_sframe(chan, control);
3077 chan->conn_state |= L2CAP_CONN_RNR_SENT; 3070 set_bit(CONN_RNR_SENT, &chan->conn_state);
3078 } 3071 }
3079 3072
3080 if (chan->conn_state & L2CAP_CONN_REMOTE_BUSY) 3073 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state))
3081 l2cap_retransmit_frames(chan); 3074 l2cap_retransmit_frames(chan);
3082 3075
3083 l2cap_ertm_send(chan); 3076 l2cap_ertm_send(chan);
3084 3077
3085 if (!(chan->conn_state & L2CAP_CONN_LOCAL_BUSY) && 3078 if (!test_bit(CONN_LOCAL_BUSY, &chan->conn_state) &&
3086 chan->frames_sent == 0) { 3079 chan->frames_sent == 0) {
3087 control |= L2CAP_SUPER_RCV_READY; 3080 control |= L2CAP_SUPER_RCV_READY;
3088 l2cap_send_sframe(chan, control); 3081 l2cap_send_sframe(chan, control);
@@ -3138,13 +3131,13 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
3138 3131
3139 switch (control & L2CAP_CTRL_SAR) { 3132 switch (control & L2CAP_CTRL_SAR) {
3140 case L2CAP_SDU_UNSEGMENTED: 3133 case L2CAP_SDU_UNSEGMENTED:
3141 if (chan->conn_state & L2CAP_CONN_SAR_SDU) 3134 if (test_bit(CONN_SAR_SDU, &chan->conn_state))
3142 goto drop; 3135 goto drop;
3143 3136
3144 return chan->ops->recv(chan->data, skb); 3137 return chan->ops->recv(chan->data, skb);
3145 3138
3146 case L2CAP_SDU_START: 3139 case L2CAP_SDU_START:
3147 if (chan->conn_state & L2CAP_CONN_SAR_SDU) 3140 if (test_bit(CONN_SAR_SDU, &chan->conn_state))
3148 goto drop; 3141 goto drop;
3149 3142
3150 chan->sdu_len = get_unaligned_le16(skb->data); 3143 chan->sdu_len = get_unaligned_le16(skb->data);
@@ -3163,12 +3156,12 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
3163 3156
3164 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len); 3157 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len);
3165 3158
3166 chan->conn_state |= L2CAP_CONN_SAR_SDU; 3159 set_bit(CONN_SAR_SDU, &chan->conn_state);
3167 chan->partial_sdu_len = skb->len; 3160 chan->partial_sdu_len = skb->len;
3168 break; 3161 break;
3169 3162
3170 case L2CAP_SDU_CONTINUE: 3163 case L2CAP_SDU_CONTINUE:
3171 if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) 3164 if (!test_bit(CONN_SAR_SDU, &chan->conn_state))
3172 goto disconnect; 3165 goto disconnect;
3173 3166
3174 if (!chan->sdu) 3167 if (!chan->sdu)
@@ -3183,13 +3176,13 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
3183 break; 3176 break;
3184 3177
3185 case L2CAP_SDU_END: 3178 case L2CAP_SDU_END:
3186 if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) 3179 if (!test_bit(CONN_SAR_SDU, &chan->conn_state))
3187 goto disconnect; 3180 goto disconnect;
3188 3181
3189 if (!chan->sdu) 3182 if (!chan->sdu)
3190 goto disconnect; 3183 goto disconnect;
3191 3184
3192 if (!(chan->conn_state & L2CAP_CONN_SAR_RETRY)) { 3185 if (!test_bit(CONN_SAR_RETRY, &chan->conn_state)) {
3193 chan->partial_sdu_len += skb->len; 3186 chan->partial_sdu_len += skb->len;
3194 3187
3195 if (chan->partial_sdu_len > chan->imtu) 3188 if (chan->partial_sdu_len > chan->imtu)
@@ -3203,19 +3196,19 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
3203 3196
3204 _skb = skb_clone(chan->sdu, GFP_ATOMIC); 3197 _skb = skb_clone(chan->sdu, GFP_ATOMIC);
3205 if (!_skb) { 3198 if (!_skb) {
3206 chan->conn_state |= L2CAP_CONN_SAR_RETRY; 3199 set_bit(CONN_SAR_RETRY, &chan->conn_state);
3207 return -ENOMEM; 3200 return -ENOMEM;
3208 } 3201 }
3209 3202
3210 err = chan->ops->recv(chan->data, _skb); 3203 err = chan->ops->recv(chan->data, _skb);
3211 if (err < 0) { 3204 if (err < 0) {
3212 kfree_skb(_skb); 3205 kfree_skb(_skb);
3213 chan->conn_state |= L2CAP_CONN_SAR_RETRY; 3206 set_bit(CONN_SAR_RETRY, &chan->conn_state);
3214 return err; 3207 return err;
3215 } 3208 }
3216 3209
3217 chan->conn_state &= ~L2CAP_CONN_SAR_RETRY; 3210 clear_bit(CONN_SAR_RETRY, &chan->conn_state);
3218 chan->conn_state &= ~L2CAP_CONN_SAR_SDU; 3211 clear_bit(CONN_SAR_SDU, &chan->conn_state);
3219 3212
3220 kfree_skb(chan->sdu); 3213 kfree_skb(chan->sdu);
3221 break; 3214 break;
@@ -3251,7 +3244,7 @@ static int l2cap_try_push_rx_skb(struct l2cap_chan *chan)
3251 chan->buffer_seq = (chan->buffer_seq + 1) % 64; 3244 chan->buffer_seq = (chan->buffer_seq + 1) % 64;
3252 } 3245 }
3253 3246
3254 if (!(chan->conn_state & L2CAP_CONN_RNR_SENT)) 3247 if (!test_bit(CONN_RNR_SENT, &chan->conn_state))
3255 goto done; 3248 goto done;
3256 3249
3257 control = chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT; 3250 control = chan->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT;
@@ -3262,11 +3255,11 @@ static int l2cap_try_push_rx_skb(struct l2cap_chan *chan)
3262 __clear_retrans_timer(chan); 3255 __clear_retrans_timer(chan);
3263 __set_monitor_timer(chan); 3256 __set_monitor_timer(chan);
3264 3257
3265 chan->conn_state |= L2CAP_CONN_WAIT_F; 3258 set_bit(CONN_WAIT_F, &chan->conn_state);
3266 3259
3267done: 3260done:
3268 chan->conn_state &= ~L2CAP_CONN_LOCAL_BUSY; 3261 clear_bit(CONN_LOCAL_BUSY, &chan->conn_state);
3269 chan->conn_state &= ~L2CAP_CONN_RNR_SENT; 3262 clear_bit(CONN_RNR_SENT, &chan->conn_state);
3270 3263
3271 BT_DBG("chan %p, Exit local busy", chan); 3264 BT_DBG("chan %p, Exit local busy", chan);
3272 3265
@@ -3324,7 +3317,7 @@ static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 c
3324{ 3317{
3325 int sctrl, err; 3318 int sctrl, err;
3326 3319
3327 if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) { 3320 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
3328 bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; 3321 bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT;
3329 __skb_queue_tail(&chan->busy_q, skb); 3322 __skb_queue_tail(&chan->busy_q, skb);
3330 return l2cap_try_push_rx_skb(chan); 3323 return l2cap_try_push_rx_skb(chan);
@@ -3341,7 +3334,7 @@ static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 c
3341 /* Busy Condition */ 3334 /* Busy Condition */
3342 BT_DBG("chan %p, Enter local busy", chan); 3335 BT_DBG("chan %p, Enter local busy", chan);
3343 3336
3344 chan->conn_state |= L2CAP_CONN_LOCAL_BUSY; 3337 set_bit(CONN_LOCAL_BUSY, &chan->conn_state);
3345 bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT; 3338 bt_cb(skb)->sar = control >> L2CAP_CTRL_SAR_SHIFT;
3346 __skb_queue_tail(&chan->busy_q, skb); 3339 __skb_queue_tail(&chan->busy_q, skb);
3347 3340
@@ -3349,7 +3342,7 @@ static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 c
3349 sctrl |= L2CAP_SUPER_RCV_NOT_READY; 3342 sctrl |= L2CAP_SUPER_RCV_NOT_READY;
3350 l2cap_send_sframe(chan, sctrl); 3343 l2cap_send_sframe(chan, sctrl);
3351 3344
3352 chan->conn_state |= L2CAP_CONN_RNR_SENT; 3345 set_bit(CONN_RNR_SENT, &chan->conn_state);
3353 3346
3354 __clear_ack_timer(chan); 3347 __clear_ack_timer(chan);
3355 3348
@@ -3370,7 +3363,7 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
3370 3363
3371 switch (control & L2CAP_CTRL_SAR) { 3364 switch (control & L2CAP_CTRL_SAR) {
3372 case L2CAP_SDU_UNSEGMENTED: 3365 case L2CAP_SDU_UNSEGMENTED:
3373 if (chan->conn_state & L2CAP_CONN_SAR_SDU) { 3366 if (test_bit(CONN_SAR_SDU, &chan->conn_state)) {
3374 kfree_skb(chan->sdu); 3367 kfree_skb(chan->sdu);
3375 break; 3368 break;
3376 } 3369 }
@@ -3382,7 +3375,7 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
3382 break; 3375 break;
3383 3376
3384 case L2CAP_SDU_START: 3377 case L2CAP_SDU_START:
3385 if (chan->conn_state & L2CAP_CONN_SAR_SDU) { 3378 if (test_bit(CONN_SAR_SDU, &chan->conn_state)) {
3386 kfree_skb(chan->sdu); 3379 kfree_skb(chan->sdu);
3387 break; 3380 break;
3388 } 3381 }
@@ -3403,13 +3396,13 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
3403 3396
3404 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len); 3397 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len);
3405 3398
3406 chan->conn_state |= L2CAP_CONN_SAR_SDU; 3399 set_bit(CONN_SAR_SDU, &chan->conn_state);
3407 chan->partial_sdu_len = skb->len; 3400 chan->partial_sdu_len = skb->len;
3408 err = 0; 3401 err = 0;
3409 break; 3402 break;
3410 3403
3411 case L2CAP_SDU_CONTINUE: 3404 case L2CAP_SDU_CONTINUE:
3412 if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) 3405 if (!test_bit(CONN_SAR_SDU, &chan->conn_state))
3413 break; 3406 break;
3414 3407
3415 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len); 3408 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len);
@@ -3423,12 +3416,12 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
3423 break; 3416 break;
3424 3417
3425 case L2CAP_SDU_END: 3418 case L2CAP_SDU_END:
3426 if (!(chan->conn_state & L2CAP_CONN_SAR_SDU)) 3419 if (!test_bit(CONN_SAR_SDU, &chan->conn_state))
3427 break; 3420 break;
3428 3421
3429 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len); 3422 memcpy(skb_put(chan->sdu, skb->len), skb->data, skb->len);
3430 3423
3431 chan->conn_state &= ~L2CAP_CONN_SAR_SDU; 3424 clear_bit(CONN_SAR_SDU, &chan->conn_state);
3432 chan->partial_sdu_len += skb->len; 3425 chan->partial_sdu_len += skb->len;
3433 3426
3434 if (chan->partial_sdu_len > chan->imtu) 3427 if (chan->partial_sdu_len > chan->imtu)
@@ -3519,11 +3512,11 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3519 tx_seq, rx_control); 3512 tx_seq, rx_control);
3520 3513
3521 if (L2CAP_CTRL_FINAL & rx_control && 3514 if (L2CAP_CTRL_FINAL & rx_control &&
3522 chan->conn_state & L2CAP_CONN_WAIT_F) { 3515 test_bit(CONN_WAIT_F, &chan->conn_state)) {
3523 __clear_monitor_timer(chan); 3516 __clear_monitor_timer(chan);
3524 if (chan->unacked_frames > 0) 3517 if (chan->unacked_frames > 0)
3525 __set_retrans_timer(chan); 3518 __set_retrans_timer(chan);
3526 chan->conn_state &= ~L2CAP_CONN_WAIT_F; 3519 clear_bit(CONN_WAIT_F, &chan->conn_state);
3527 } 3520 }
3528 3521
3529 chan->expected_ack_seq = req_seq; 3522 chan->expected_ack_seq = req_seq;
@@ -3542,10 +3535,10 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3542 goto drop; 3535 goto drop;
3543 } 3536 }
3544 3537
3545 if (chan->conn_state & L2CAP_CONN_LOCAL_BUSY) 3538 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state))
3546 goto drop; 3539 goto drop;
3547 3540
3548 if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { 3541 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) {
3549 struct srej_list *first; 3542 struct srej_list *first;
3550 3543
3551 first = list_first_entry(&chan->srej_l, 3544 first = list_first_entry(&chan->srej_l,
@@ -3559,7 +3552,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3559 3552
3560 if (list_empty(&chan->srej_l)) { 3553 if (list_empty(&chan->srej_l)) {
3561 chan->buffer_seq = chan->buffer_seq_srej; 3554 chan->buffer_seq = chan->buffer_seq_srej;
3562 chan->conn_state &= ~L2CAP_CONN_SREJ_SENT; 3555 clear_bit(CONN_SREJ_SENT, &chan->conn_state);
3563 l2cap_send_ack(chan); 3556 l2cap_send_ack(chan);
3564 BT_DBG("chan %p, Exit SREJ_SENT", chan); 3557 BT_DBG("chan %p, Exit SREJ_SENT", chan);
3565 } 3558 }
@@ -3588,7 +3581,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3588 if (tx_seq_offset < expected_tx_seq_offset) 3581 if (tx_seq_offset < expected_tx_seq_offset)
3589 goto drop; 3582 goto drop;
3590 3583
3591 chan->conn_state |= L2CAP_CONN_SREJ_SENT; 3584 set_bit(CONN_SREJ_SENT, &chan->conn_state);
3592 3585
3593 BT_DBG("chan %p, Enter SREJ", chan); 3586 BT_DBG("chan %p, Enter SREJ", chan);
3594 3587
@@ -3599,7 +3592,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3599 __skb_queue_head_init(&chan->busy_q); 3592 __skb_queue_head_init(&chan->busy_q);
3600 l2cap_add_to_srej_queue(chan, skb, tx_seq, sar); 3593 l2cap_add_to_srej_queue(chan, skb, tx_seq, sar);
3601 3594
3602 chan->conn_state |= L2CAP_CONN_SEND_PBIT; 3595 set_bit(CONN_SEND_PBIT, &chan->conn_state);
3603 3596
3604 l2cap_send_srejframe(chan, tx_seq); 3597 l2cap_send_srejframe(chan, tx_seq);
3605 3598
@@ -3610,7 +3603,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
3610expected: 3603expected:
3611 chan->expected_tx_seq = (chan->expected_tx_seq + 1) % 64; 3604 chan->expected_tx_seq = (chan->expected_tx_seq + 1) % 64;
3612 3605
3613 if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { 3606 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) {
3614 bt_cb(skb)->tx_seq = tx_seq; 3607 bt_cb(skb)->tx_seq = tx_seq;
3615 bt_cb(skb)->sar = sar; 3608 bt_cb(skb)->sar = sar;
3616 __skb_queue_tail(&chan->srej_q, skb); 3609 __skb_queue_tail(&chan->srej_q, skb);
@@ -3622,9 +3615,7 @@ expected:
3622 return 0; 3615 return 0;
3623 3616
3624 if (rx_control & L2CAP_CTRL_FINAL) { 3617 if (rx_control & L2CAP_CTRL_FINAL) {
3625 if (chan->conn_state & L2CAP_CONN_REJ_ACT) 3618 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state))
3626 chan->conn_state &= ~L2CAP_CONN_REJ_ACT;
3627 else
3628 l2cap_retransmit_frames(chan); 3619 l2cap_retransmit_frames(chan);
3629 } 3620 }
3630 3621
@@ -3650,33 +3641,31 @@ static inline void l2cap_data_channel_rrframe(struct l2cap_chan *chan, u16 rx_co
3650 l2cap_drop_acked_frames(chan); 3641 l2cap_drop_acked_frames(chan);
3651 3642
3652 if (rx_control & L2CAP_CTRL_POLL) { 3643 if (rx_control & L2CAP_CTRL_POLL) {
3653 chan->conn_state |= L2CAP_CONN_SEND_FBIT; 3644 set_bit(CONN_SEND_FBIT, &chan->conn_state);
3654 if (chan->conn_state & L2CAP_CONN_SREJ_SENT) { 3645 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) {
3655 if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && 3646 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) &&
3656 (chan->unacked_frames > 0)) 3647 (chan->unacked_frames > 0))
3657 __set_retrans_timer(chan); 3648 __set_retrans_timer(chan);
3658 3649
3659 chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3650 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3660 l2cap_send_srejtail(chan); 3651 l2cap_send_srejtail(chan);
3661 } else { 3652 } else {
3662 l2cap_send_i_or_rr_or_rnr(chan); 3653 l2cap_send_i_or_rr_or_rnr(chan);
3663 } 3654 }
3664 3655
3665 } else if (rx_control & L2CAP_CTRL_FINAL) { 3656 } else if (rx_control & L2CAP_CTRL_FINAL) {
3666 chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3657 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3667 3658
3668 if (chan->conn_state & L2CAP_CONN_REJ_ACT) 3659 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state))
3669 chan->conn_state &= ~L2CAP_CONN_REJ_ACT;
3670 else
3671 l2cap_retransmit_frames(chan); 3660 l2cap_retransmit_frames(chan);
3672 3661
3673 } else { 3662 } else {
3674 if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) && 3663 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) &&
3675 (chan->unacked_frames > 0)) 3664 (chan->unacked_frames > 0))
3676 __set_retrans_timer(chan); 3665 __set_retrans_timer(chan);
3677 3666
3678 chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3667 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3679 if (chan->conn_state & L2CAP_CONN_SREJ_SENT) 3668 if (test_bit(CONN_SREJ_SENT, &chan->conn_state))
3680 l2cap_send_ack(chan); 3669 l2cap_send_ack(chan);
3681 else 3670 else
3682 l2cap_ertm_send(chan); 3671 l2cap_ertm_send(chan);
@@ -3689,21 +3678,19 @@ static inline void l2cap_data_channel_rejframe(struct l2cap_chan *chan, u16 rx_c
3689 3678
3690 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); 3679 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control);
3691 3680
3692 chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3681 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3693 3682
3694 chan->expected_ack_seq = tx_seq; 3683 chan->expected_ack_seq = tx_seq;
3695 l2cap_drop_acked_frames(chan); 3684 l2cap_drop_acked_frames(chan);
3696 3685
3697 if (rx_control & L2CAP_CTRL_FINAL) { 3686 if (rx_control & L2CAP_CTRL_FINAL) {
3698 if (chan->conn_state & L2CAP_CONN_REJ_ACT) 3687 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state))
3699 chan->conn_state &= ~L2CAP_CONN_REJ_ACT;
3700 else
3701 l2cap_retransmit_frames(chan); 3688 l2cap_retransmit_frames(chan);
3702 } else { 3689 } else {
3703 l2cap_retransmit_frames(chan); 3690 l2cap_retransmit_frames(chan);
3704 3691
3705 if (chan->conn_state & L2CAP_CONN_WAIT_F) 3692 if (test_bit(CONN_WAIT_F, &chan->conn_state))
3706 chan->conn_state |= L2CAP_CONN_REJ_ACT; 3693 set_bit(CONN_REJ_ACT, &chan->conn_state);
3707 } 3694 }
3708} 3695}
3709static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u16 rx_control) 3696static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u16 rx_control)
@@ -3712,32 +3699,32 @@ static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u16 rx_
3712 3699
3713 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); 3700 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control);
3714 3701
3715 chan->conn_state &= ~L2CAP_CONN_REMOTE_BUSY; 3702 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3716 3703
3717 if (rx_control & L2CAP_CTRL_POLL) { 3704 if (rx_control & L2CAP_CTRL_POLL) {
3718 chan->expected_ack_seq = tx_seq; 3705 chan->expected_ack_seq = tx_seq;
3719 l2cap_drop_acked_frames(chan); 3706 l2cap_drop_acked_frames(chan);
3720 3707
3721 chan->conn_state |= L2CAP_CONN_SEND_FBIT; 3708 set_bit(CONN_SEND_FBIT, &chan->conn_state);
3722 l2cap_retransmit_one_frame(chan, tx_seq); 3709 l2cap_retransmit_one_frame(chan, tx_seq);
3723 3710
3724 l2cap_ertm_send(chan); 3711 l2cap_ertm_send(chan);
3725 3712
3726 if (chan->conn_state & L2CAP_CONN_WAIT_F) { 3713 if (test_bit(CONN_WAIT_F, &chan->conn_state)) {
3727 chan->srej_save_reqseq = tx_seq; 3714 chan->srej_save_reqseq = tx_seq;
3728 chan->conn_state |= L2CAP_CONN_SREJ_ACT; 3715 set_bit(CONN_SREJ_ACT, &chan->conn_state);
3729 } 3716 }
3730 } else if (rx_control & L2CAP_CTRL_FINAL) { 3717 } else if (rx_control & L2CAP_CTRL_FINAL) {
3731 if ((chan->conn_state & L2CAP_CONN_SREJ_ACT) && 3718 if (test_bit(CONN_SREJ_ACT, &chan->conn_state) &&
3732 chan->srej_save_reqseq == tx_seq) 3719 chan->srej_save_reqseq == tx_seq)
3733 chan->conn_state &= ~L2CAP_CONN_SREJ_ACT; 3720 clear_bit(CONN_SREJ_ACT, &chan->conn_state);
3734 else 3721 else
3735 l2cap_retransmit_one_frame(chan, tx_seq); 3722 l2cap_retransmit_one_frame(chan, tx_seq);
3736 } else { 3723 } else {
3737 l2cap_retransmit_one_frame(chan, tx_seq); 3724 l2cap_retransmit_one_frame(chan, tx_seq);
3738 if (chan->conn_state & L2CAP_CONN_WAIT_F) { 3725 if (test_bit(CONN_WAIT_F, &chan->conn_state)) {
3739 chan->srej_save_reqseq = tx_seq; 3726 chan->srej_save_reqseq = tx_seq;
3740 chan->conn_state |= L2CAP_CONN_SREJ_ACT; 3727 set_bit(CONN_SREJ_ACT, &chan->conn_state);
3741 } 3728 }
3742 } 3729 }
3743} 3730}
@@ -3748,14 +3735,14 @@ static inline void l2cap_data_channel_rnrframe(struct l2cap_chan *chan, u16 rx_c
3748 3735
3749 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control); 3736 BT_DBG("chan %p, req_seq %d ctrl 0x%4.4x", chan, tx_seq, rx_control);
3750 3737
3751 chan->conn_state |= L2CAP_CONN_REMOTE_BUSY; 3738 set_bit(CONN_REMOTE_BUSY, &chan->conn_state);
3752 chan->expected_ack_seq = tx_seq; 3739 chan->expected_ack_seq = tx_seq;
3753 l2cap_drop_acked_frames(chan); 3740 l2cap_drop_acked_frames(chan);
3754 3741
3755 if (rx_control & L2CAP_CTRL_POLL) 3742 if (rx_control & L2CAP_CTRL_POLL)
3756 chan->conn_state |= L2CAP_CONN_SEND_FBIT; 3743 set_bit(CONN_SEND_FBIT, &chan->conn_state);
3757 3744
3758 if (!(chan->conn_state & L2CAP_CONN_SREJ_SENT)) { 3745 if (!test_bit(CONN_SREJ_SENT, &chan->conn_state)) {
3759 __clear_retrans_timer(chan); 3746 __clear_retrans_timer(chan);
3760 if (rx_control & L2CAP_CTRL_POLL) 3747 if (rx_control & L2CAP_CTRL_POLL)
3761 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_FINAL); 3748 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_FINAL);
@@ -3773,11 +3760,11 @@ static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u16 rx_cont
3773 BT_DBG("chan %p rx_control 0x%4.4x len %d", chan, rx_control, skb->len); 3760 BT_DBG("chan %p rx_control 0x%4.4x len %d", chan, rx_control, skb->len);
3774 3761
3775 if (L2CAP_CTRL_FINAL & rx_control && 3762 if (L2CAP_CTRL_FINAL & rx_control &&
3776 chan->conn_state & L2CAP_CONN_WAIT_F) { 3763 test_bit(CONN_WAIT_F, &chan->conn_state)) {
3777 __clear_monitor_timer(chan); 3764 __clear_monitor_timer(chan);
3778 if (chan->unacked_frames > 0) 3765 if (chan->unacked_frames > 0)
3779 __set_retrans_timer(chan); 3766 __set_retrans_timer(chan);
3780 chan->conn_state &= ~L2CAP_CONN_WAIT_F; 3767 clear_bit(CONN_WAIT_F, &chan->conn_state);
3781 } 3768 }
3782 3769
3783 switch (rx_control & L2CAP_CTRL_SUPERVISE) { 3770 switch (rx_control & L2CAP_CTRL_SUPERVISE) {