diff options
Diffstat (limited to 'net/bluetooth/l2cap_core.c')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 492 |
1 files changed, 0 insertions, 492 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 0a195ab4a385..d795d15cadf9 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -534,8 +534,6 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err) | |||
534 | skb_queue_purge(&chan->tx_q); | 534 | skb_queue_purge(&chan->tx_q); |
535 | 535 | ||
536 | if (chan->mode == L2CAP_MODE_ERTM) { | 536 | if (chan->mode == L2CAP_MODE_ERTM) { |
537 | struct srej_list *l, *tmp; | ||
538 | |||
539 | __clear_retrans_timer(chan); | 537 | __clear_retrans_timer(chan); |
540 | __clear_monitor_timer(chan); | 538 | __clear_monitor_timer(chan); |
541 | __clear_ack_timer(chan); | 539 | __clear_ack_timer(chan); |
@@ -544,10 +542,6 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err) | |||
544 | 542 | ||
545 | l2cap_seq_list_free(&chan->srej_list); | 543 | l2cap_seq_list_free(&chan->srej_list); |
546 | l2cap_seq_list_free(&chan->retrans_list); | 544 | l2cap_seq_list_free(&chan->retrans_list); |
547 | list_for_each_entry_safe(l, tmp, &chan->srej_l, list) { | ||
548 | list_del(&l->list); | ||
549 | kfree(l); | ||
550 | } | ||
551 | } | 545 | } |
552 | } | 546 | } |
553 | 547 | ||
@@ -1658,25 +1652,6 @@ static void l2cap_retrans_timeout(struct work_struct *work) | |||
1658 | l2cap_chan_put(chan); | 1652 | l2cap_chan_put(chan); |
1659 | } | 1653 | } |
1660 | 1654 | ||
1661 | static void l2cap_drop_acked_frames(struct l2cap_chan *chan) | ||
1662 | { | ||
1663 | struct sk_buff *skb; | ||
1664 | |||
1665 | while ((skb = skb_peek(&chan->tx_q)) && | ||
1666 | chan->unacked_frames) { | ||
1667 | if (bt_cb(skb)->control.txseq == chan->expected_ack_seq) | ||
1668 | break; | ||
1669 | |||
1670 | skb = skb_dequeue(&chan->tx_q); | ||
1671 | kfree_skb(skb); | ||
1672 | |||
1673 | chan->unacked_frames--; | ||
1674 | } | ||
1675 | |||
1676 | if (!chan->unacked_frames) | ||
1677 | __clear_retrans_timer(chan); | ||
1678 | } | ||
1679 | |||
1680 | static int l2cap_streaming_send(struct l2cap_chan *chan, | 1655 | static int l2cap_streaming_send(struct l2cap_chan *chan, |
1681 | struct sk_buff_head *skbs) | 1656 | struct sk_buff_head *skbs) |
1682 | { | 1657 | { |
@@ -1718,53 +1693,6 @@ static int l2cap_streaming_send(struct l2cap_chan *chan, | |||
1718 | return 0; | 1693 | return 0; |
1719 | } | 1694 | } |
1720 | 1695 | ||
1721 | static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq) | ||
1722 | { | ||
1723 | struct sk_buff *skb, *tx_skb; | ||
1724 | u16 fcs; | ||
1725 | u32 control; | ||
1726 | |||
1727 | skb = skb_peek(&chan->tx_q); | ||
1728 | if (!skb) | ||
1729 | return; | ||
1730 | |||
1731 | while (bt_cb(skb)->control.txseq != tx_seq) { | ||
1732 | if (skb_queue_is_last(&chan->tx_q, skb)) | ||
1733 | return; | ||
1734 | |||
1735 | skb = skb_queue_next(&chan->tx_q, skb); | ||
1736 | } | ||
1737 | |||
1738 | if (bt_cb(skb)->control.retries == chan->remote_max_tx && | ||
1739 | chan->remote_max_tx) { | ||
1740 | l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED); | ||
1741 | return; | ||
1742 | } | ||
1743 | |||
1744 | tx_skb = skb_clone(skb, GFP_ATOMIC); | ||
1745 | bt_cb(skb)->control.retries++; | ||
1746 | |||
1747 | control = __get_control(chan, tx_skb->data + L2CAP_HDR_SIZE); | ||
1748 | control &= __get_sar_mask(chan); | ||
1749 | |||
1750 | if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state)) | ||
1751 | control |= __set_ctrl_final(chan); | ||
1752 | |||
1753 | control |= __set_reqseq(chan, chan->buffer_seq); | ||
1754 | control |= __set_txseq(chan, tx_seq); | ||
1755 | |||
1756 | __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); | ||
1757 | |||
1758 | if (chan->fcs == L2CAP_FCS_CRC16) { | ||
1759 | fcs = crc16(0, (u8 *)tx_skb->data, | ||
1760 | tx_skb->len - L2CAP_FCS_SIZE); | ||
1761 | put_unaligned_le16(fcs, | ||
1762 | tx_skb->data + tx_skb->len - L2CAP_FCS_SIZE); | ||
1763 | } | ||
1764 | |||
1765 | l2cap_do_send(chan, tx_skb); | ||
1766 | } | ||
1767 | |||
1768 | static int l2cap_ertm_send(struct l2cap_chan *chan) | 1696 | static int l2cap_ertm_send(struct l2cap_chan *chan) |
1769 | { | 1697 | { |
1770 | struct sk_buff *skb, *tx_skb; | 1698 | struct sk_buff *skb, *tx_skb; |
@@ -1868,18 +1796,6 @@ static void l2cap_send_ack(struct l2cap_chan *chan) | |||
1868 | __l2cap_send_ack(chan); | 1796 | __l2cap_send_ack(chan); |
1869 | } | 1797 | } |
1870 | 1798 | ||
1871 | static void l2cap_send_srejtail(struct l2cap_chan *chan) | ||
1872 | { | ||
1873 | struct srej_list *tail; | ||
1874 | u32 control; | ||
1875 | |||
1876 | control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ); | ||
1877 | control |= __set_ctrl_final(chan); | ||
1878 | |||
1879 | tail = list_entry((&chan->srej_l)->prev, struct srej_list, list); | ||
1880 | control |= __set_reqseq(chan, tail->tx_seq); | ||
1881 | } | ||
1882 | |||
1883 | static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan, | 1799 | static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan, |
1884 | struct msghdr *msg, int len, | 1800 | struct msghdr *msg, int len, |
1885 | int count, struct sk_buff *skb) | 1801 | int count, struct sk_buff *skb) |
@@ -2639,7 +2555,6 @@ static inline int l2cap_ertm_init(struct l2cap_chan *chan) | |||
2639 | chan->expected_ack_seq = 0; | 2555 | chan->expected_ack_seq = 0; |
2640 | chan->unacked_frames = 0; | 2556 | chan->unacked_frames = 0; |
2641 | chan->buffer_seq = 0; | 2557 | chan->buffer_seq = 0; |
2642 | chan->num_acked = 0; | ||
2643 | chan->frames_sent = 0; | 2558 | chan->frames_sent = 0; |
2644 | chan->last_acked_seq = 0; | 2559 | chan->last_acked_seq = 0; |
2645 | chan->sdu = NULL; | 2560 | chan->sdu = NULL; |
@@ -2660,7 +2575,6 @@ static inline int l2cap_ertm_init(struct l2cap_chan *chan) | |||
2660 | 2575 | ||
2661 | skb_queue_head_init(&chan->srej_q); | 2576 | skb_queue_head_init(&chan->srej_q); |
2662 | 2577 | ||
2663 | INIT_LIST_HEAD(&chan->srej_l); | ||
2664 | err = l2cap_seq_list_init(&chan->srej_list, chan->tx_win); | 2578 | err = l2cap_seq_list_init(&chan->srej_list, chan->tx_win); |
2665 | if (err < 0) | 2579 | if (err < 0) |
2666 | return err; | 2580 | return err; |
@@ -4277,41 +4191,6 @@ static inline void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan) | |||
4277 | } | 4191 | } |
4278 | } | 4192 | } |
4279 | 4193 | ||
4280 | static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb, u16 tx_seq, u8 sar) | ||
4281 | { | ||
4282 | struct sk_buff *next_skb; | ||
4283 | int tx_seq_offset, next_tx_seq_offset; | ||
4284 | |||
4285 | bt_cb(skb)->control.txseq = tx_seq; | ||
4286 | bt_cb(skb)->control.sar = sar; | ||
4287 | |||
4288 | next_skb = skb_peek(&chan->srej_q); | ||
4289 | |||
4290 | tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq); | ||
4291 | |||
4292 | while (next_skb) { | ||
4293 | if (bt_cb(next_skb)->control.txseq == tx_seq) | ||
4294 | return -EINVAL; | ||
4295 | |||
4296 | next_tx_seq_offset = __seq_offset(chan, | ||
4297 | bt_cb(next_skb)->control.txseq, chan->buffer_seq); | ||
4298 | |||
4299 | if (next_tx_seq_offset > tx_seq_offset) { | ||
4300 | __skb_queue_before(&chan->srej_q, next_skb, skb); | ||
4301 | return 0; | ||
4302 | } | ||
4303 | |||
4304 | if (skb_queue_is_last(&chan->srej_q, next_skb)) | ||
4305 | next_skb = NULL; | ||
4306 | else | ||
4307 | next_skb = skb_queue_next(&chan->srej_q, next_skb); | ||
4308 | } | ||
4309 | |||
4310 | __skb_queue_tail(&chan->srej_q, skb); | ||
4311 | |||
4312 | return 0; | ||
4313 | } | ||
4314 | |||
4315 | static void append_skb_frag(struct sk_buff *skb, | 4194 | static void append_skb_frag(struct sk_buff *skb, |
4316 | struct sk_buff *new_frag, struct sk_buff **last_frag) | 4195 | struct sk_buff *new_frag, struct sk_buff **last_frag) |
4317 | { | 4196 | { |
@@ -4457,377 +4336,6 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy) | |||
4457 | } | 4336 | } |
4458 | } | 4337 | } |
4459 | 4338 | ||
4460 | static void l2cap_check_srej_gap(struct l2cap_chan *chan, u16 tx_seq) | ||
4461 | { | ||
4462 | struct sk_buff *skb; | ||
4463 | u32 control; | ||
4464 | |||
4465 | while ((skb = skb_peek(&chan->srej_q)) && | ||
4466 | !test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { | ||
4467 | int err; | ||
4468 | |||
4469 | if (bt_cb(skb)->control.txseq != tx_seq) | ||
4470 | break; | ||
4471 | |||
4472 | skb = skb_dequeue(&chan->srej_q); | ||
4473 | control = __set_ctrl_sar(chan, bt_cb(skb)->control.sar); | ||
4474 | |||
4475 | if (err < 0) { | ||
4476 | l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); | ||
4477 | break; | ||
4478 | } | ||
4479 | |||
4480 | chan->buffer_seq_srej = __next_seq(chan, chan->buffer_seq_srej); | ||
4481 | tx_seq = __next_seq(chan, tx_seq); | ||
4482 | } | ||
4483 | } | ||
4484 | |||
4485 | static void l2cap_resend_srejframe(struct l2cap_chan *chan, u16 tx_seq) | ||
4486 | { | ||
4487 | struct srej_list *l, *tmp; | ||
4488 | u32 control; | ||
4489 | |||
4490 | list_for_each_entry_safe(l, tmp, &chan->srej_l, list) { | ||
4491 | if (l->tx_seq == tx_seq) { | ||
4492 | list_del(&l->list); | ||
4493 | kfree(l); | ||
4494 | return; | ||
4495 | } | ||
4496 | control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ); | ||
4497 | control |= __set_reqseq(chan, l->tx_seq); | ||
4498 | list_del(&l->list); | ||
4499 | list_add_tail(&l->list, &chan->srej_l); | ||
4500 | } | ||
4501 | } | ||
4502 | |||
4503 | static int l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq) | ||
4504 | { | ||
4505 | struct srej_list *new; | ||
4506 | u32 control; | ||
4507 | |||
4508 | while (tx_seq != chan->expected_tx_seq) { | ||
4509 | control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ); | ||
4510 | control |= __set_reqseq(chan, chan->expected_tx_seq); | ||
4511 | l2cap_seq_list_append(&chan->srej_list, chan->expected_tx_seq); | ||
4512 | |||
4513 | new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC); | ||
4514 | if (!new) | ||
4515 | return -ENOMEM; | ||
4516 | |||
4517 | new->tx_seq = chan->expected_tx_seq; | ||
4518 | |||
4519 | chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); | ||
4520 | |||
4521 | list_add_tail(&new->list, &chan->srej_l); | ||
4522 | } | ||
4523 | |||
4524 | chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); | ||
4525 | |||
4526 | return 0; | ||
4527 | } | ||
4528 | |||
4529 | static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb) | ||
4530 | { | ||
4531 | u16 tx_seq = __get_txseq(chan, rx_control); | ||
4532 | u16 req_seq = __get_reqseq(chan, rx_control); | ||
4533 | u8 sar = __get_ctrl_sar(chan, rx_control); | ||
4534 | int tx_seq_offset, expected_tx_seq_offset; | ||
4535 | int num_to_ack = (chan->tx_win/6) + 1; | ||
4536 | int err = 0; | ||
4537 | |||
4538 | BT_DBG("chan %p len %d tx_seq %d rx_control 0x%8.8x", chan, skb->len, | ||
4539 | tx_seq, rx_control); | ||
4540 | |||
4541 | if (__is_ctrl_final(chan, rx_control) && | ||
4542 | test_bit(CONN_WAIT_F, &chan->conn_state)) { | ||
4543 | __clear_monitor_timer(chan); | ||
4544 | if (chan->unacked_frames > 0) | ||
4545 | __set_retrans_timer(chan); | ||
4546 | clear_bit(CONN_WAIT_F, &chan->conn_state); | ||
4547 | } | ||
4548 | |||
4549 | chan->expected_ack_seq = req_seq; | ||
4550 | l2cap_drop_acked_frames(chan); | ||
4551 | |||
4552 | tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq); | ||
4553 | |||
4554 | /* invalid tx_seq */ | ||
4555 | if (tx_seq_offset >= chan->tx_win) { | ||
4556 | l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); | ||
4557 | goto drop; | ||
4558 | } | ||
4559 | |||
4560 | if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { | ||
4561 | if (!test_bit(CONN_RNR_SENT, &chan->conn_state)) | ||
4562 | l2cap_send_ack(chan); | ||
4563 | goto drop; | ||
4564 | } | ||
4565 | |||
4566 | if (tx_seq == chan->expected_tx_seq) | ||
4567 | goto expected; | ||
4568 | |||
4569 | if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) { | ||
4570 | struct srej_list *first; | ||
4571 | |||
4572 | first = list_first_entry(&chan->srej_l, | ||
4573 | struct srej_list, list); | ||
4574 | if (tx_seq == first->tx_seq) { | ||
4575 | l2cap_add_to_srej_queue(chan, skb, tx_seq, sar); | ||
4576 | l2cap_check_srej_gap(chan, tx_seq); | ||
4577 | |||
4578 | list_del(&first->list); | ||
4579 | kfree(first); | ||
4580 | |||
4581 | if (list_empty(&chan->srej_l)) { | ||
4582 | chan->buffer_seq = chan->buffer_seq_srej; | ||
4583 | clear_bit(CONN_SREJ_SENT, &chan->conn_state); | ||
4584 | l2cap_send_ack(chan); | ||
4585 | BT_DBG("chan %p, Exit SREJ_SENT", chan); | ||
4586 | } | ||
4587 | } else { | ||
4588 | struct srej_list *l; | ||
4589 | |||
4590 | /* duplicated tx_seq */ | ||
4591 | if (l2cap_add_to_srej_queue(chan, skb, tx_seq, sar) < 0) | ||
4592 | goto drop; | ||
4593 | |||
4594 | list_for_each_entry(l, &chan->srej_l, list) { | ||
4595 | if (l->tx_seq == tx_seq) { | ||
4596 | l2cap_resend_srejframe(chan, tx_seq); | ||
4597 | return 0; | ||
4598 | } | ||
4599 | } | ||
4600 | |||
4601 | err = l2cap_send_srejframe(chan, tx_seq); | ||
4602 | if (err < 0) { | ||
4603 | l2cap_send_disconn_req(chan->conn, chan, -err); | ||
4604 | return err; | ||
4605 | } | ||
4606 | } | ||
4607 | } else { | ||
4608 | expected_tx_seq_offset = __seq_offset(chan, | ||
4609 | chan->expected_tx_seq, chan->buffer_seq); | ||
4610 | |||
4611 | /* duplicated tx_seq */ | ||
4612 | if (tx_seq_offset < expected_tx_seq_offset) | ||
4613 | goto drop; | ||
4614 | |||
4615 | set_bit(CONN_SREJ_SENT, &chan->conn_state); | ||
4616 | |||
4617 | BT_DBG("chan %p, Enter SREJ", chan); | ||
4618 | |||
4619 | INIT_LIST_HEAD(&chan->srej_l); | ||
4620 | chan->buffer_seq_srej = chan->buffer_seq; | ||
4621 | |||
4622 | __skb_queue_head_init(&chan->srej_q); | ||
4623 | l2cap_add_to_srej_queue(chan, skb, tx_seq, sar); | ||
4624 | |||
4625 | /* Set P-bit only if there are some I-frames to ack. */ | ||
4626 | if (__clear_ack_timer(chan)) | ||
4627 | set_bit(CONN_SEND_PBIT, &chan->conn_state); | ||
4628 | |||
4629 | err = l2cap_send_srejframe(chan, tx_seq); | ||
4630 | if (err < 0) { | ||
4631 | l2cap_send_disconn_req(chan->conn, chan, -err); | ||
4632 | return err; | ||
4633 | } | ||
4634 | } | ||
4635 | return 0; | ||
4636 | |||
4637 | expected: | ||
4638 | chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); | ||
4639 | |||
4640 | if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) { | ||
4641 | bt_cb(skb)->control.txseq = tx_seq; | ||
4642 | bt_cb(skb)->control.sar = sar; | ||
4643 | __skb_queue_tail(&chan->srej_q, skb); | ||
4644 | return 0; | ||
4645 | } | ||
4646 | |||
4647 | chan->buffer_seq = __next_seq(chan, chan->buffer_seq); | ||
4648 | |||
4649 | if (err < 0) { | ||
4650 | l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); | ||
4651 | return err; | ||
4652 | } | ||
4653 | |||
4654 | if (__is_ctrl_final(chan, rx_control)) { | ||
4655 | if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state)) | ||
4656 | l2cap_retransmit_frames(chan); | ||
4657 | } | ||
4658 | |||
4659 | |||
4660 | chan->num_acked = (chan->num_acked + 1) % num_to_ack; | ||
4661 | if (chan->num_acked == num_to_ack - 1) | ||
4662 | l2cap_send_ack(chan); | ||
4663 | else | ||
4664 | __set_ack_timer(chan); | ||
4665 | |||
4666 | return 0; | ||
4667 | |||
4668 | drop: | ||
4669 | kfree_skb(skb); | ||
4670 | return 0; | ||
4671 | } | ||
4672 | |||
4673 | static inline void l2cap_data_channel_rrframe(struct l2cap_chan *chan, u32 rx_control) | ||
4674 | { | ||
4675 | BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, | ||
4676 | __get_reqseq(chan, rx_control), rx_control); | ||
4677 | |||
4678 | chan->expected_ack_seq = __get_reqseq(chan, rx_control); | ||
4679 | l2cap_drop_acked_frames(chan); | ||
4680 | |||
4681 | if (__is_ctrl_poll(chan, rx_control)) { | ||
4682 | set_bit(CONN_SEND_FBIT, &chan->conn_state); | ||
4683 | if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) { | ||
4684 | if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) && | ||
4685 | (chan->unacked_frames > 0)) | ||
4686 | __set_retrans_timer(chan); | ||
4687 | |||
4688 | clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4689 | l2cap_send_srejtail(chan); | ||
4690 | } else { | ||
4691 | l2cap_send_i_or_rr_or_rnr(chan); | ||
4692 | } | ||
4693 | |||
4694 | } else if (__is_ctrl_final(chan, rx_control)) { | ||
4695 | clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4696 | |||
4697 | if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state)) | ||
4698 | l2cap_retransmit_frames(chan); | ||
4699 | |||
4700 | } else { | ||
4701 | if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) && | ||
4702 | (chan->unacked_frames > 0)) | ||
4703 | __set_retrans_timer(chan); | ||
4704 | |||
4705 | clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4706 | if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) | ||
4707 | l2cap_send_ack(chan); | ||
4708 | else | ||
4709 | l2cap_ertm_send(chan); | ||
4710 | } | ||
4711 | } | ||
4712 | |||
4713 | static inline void l2cap_data_channel_rejframe(struct l2cap_chan *chan, u32 rx_control) | ||
4714 | { | ||
4715 | u16 tx_seq = __get_reqseq(chan, rx_control); | ||
4716 | |||
4717 | BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control); | ||
4718 | |||
4719 | clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4720 | |||
4721 | chan->expected_ack_seq = tx_seq; | ||
4722 | l2cap_drop_acked_frames(chan); | ||
4723 | |||
4724 | if (__is_ctrl_final(chan, rx_control)) { | ||
4725 | if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state)) | ||
4726 | l2cap_retransmit_frames(chan); | ||
4727 | } else { | ||
4728 | l2cap_retransmit_frames(chan); | ||
4729 | |||
4730 | if (test_bit(CONN_WAIT_F, &chan->conn_state)) | ||
4731 | set_bit(CONN_REJ_ACT, &chan->conn_state); | ||
4732 | } | ||
4733 | } | ||
4734 | static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u32 rx_control) | ||
4735 | { | ||
4736 | u16 tx_seq = __get_reqseq(chan, rx_control); | ||
4737 | |||
4738 | BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control); | ||
4739 | |||
4740 | clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4741 | |||
4742 | if (__is_ctrl_poll(chan, rx_control)) { | ||
4743 | chan->expected_ack_seq = tx_seq; | ||
4744 | l2cap_drop_acked_frames(chan); | ||
4745 | |||
4746 | set_bit(CONN_SEND_FBIT, &chan->conn_state); | ||
4747 | l2cap_retransmit_one_frame(chan, tx_seq); | ||
4748 | |||
4749 | l2cap_ertm_send(chan); | ||
4750 | |||
4751 | if (test_bit(CONN_WAIT_F, &chan->conn_state)) { | ||
4752 | chan->srej_save_reqseq = tx_seq; | ||
4753 | set_bit(CONN_SREJ_ACT, &chan->conn_state); | ||
4754 | } | ||
4755 | } else if (__is_ctrl_final(chan, rx_control)) { | ||
4756 | if (test_bit(CONN_SREJ_ACT, &chan->conn_state) && | ||
4757 | chan->srej_save_reqseq == tx_seq) | ||
4758 | clear_bit(CONN_SREJ_ACT, &chan->conn_state); | ||
4759 | else | ||
4760 | l2cap_retransmit_one_frame(chan, tx_seq); | ||
4761 | } else { | ||
4762 | l2cap_retransmit_one_frame(chan, tx_seq); | ||
4763 | if (test_bit(CONN_WAIT_F, &chan->conn_state)) { | ||
4764 | chan->srej_save_reqseq = tx_seq; | ||
4765 | set_bit(CONN_SREJ_ACT, &chan->conn_state); | ||
4766 | } | ||
4767 | } | ||
4768 | } | ||
4769 | |||
4770 | static inline void l2cap_data_channel_rnrframe(struct l2cap_chan *chan, u32 rx_control) | ||
4771 | { | ||
4772 | u16 tx_seq = __get_reqseq(chan, rx_control); | ||
4773 | |||
4774 | BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control); | ||
4775 | |||
4776 | set_bit(CONN_REMOTE_BUSY, &chan->conn_state); | ||
4777 | chan->expected_ack_seq = tx_seq; | ||
4778 | l2cap_drop_acked_frames(chan); | ||
4779 | |||
4780 | if (__is_ctrl_poll(chan, rx_control)) | ||
4781 | set_bit(CONN_SEND_FBIT, &chan->conn_state); | ||
4782 | |||
4783 | if (!test_bit(CONN_SREJ_SENT, &chan->conn_state)) { | ||
4784 | __clear_retrans_timer(chan); | ||
4785 | if (__is_ctrl_poll(chan, rx_control)) | ||
4786 | l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_FINAL); | ||
4787 | return; | ||
4788 | } | ||
4789 | |||
4790 | if (__is_ctrl_poll(chan, rx_control)) { | ||
4791 | l2cap_send_srejtail(chan); | ||
4792 | } else { | ||
4793 | rx_control = __set_ctrl_super(chan, L2CAP_SUPER_RR); | ||
4794 | } | ||
4795 | } | ||
4796 | |||
4797 | static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb) | ||
4798 | { | ||
4799 | BT_DBG("chan %p rx_control 0x%8.8x len %d", chan, rx_control, skb->len); | ||
4800 | |||
4801 | if (__is_ctrl_final(chan, rx_control) && | ||
4802 | test_bit(CONN_WAIT_F, &chan->conn_state)) { | ||
4803 | __clear_monitor_timer(chan); | ||
4804 | if (chan->unacked_frames > 0) | ||
4805 | __set_retrans_timer(chan); | ||
4806 | clear_bit(CONN_WAIT_F, &chan->conn_state); | ||
4807 | } | ||
4808 | |||
4809 | switch (__get_ctrl_super(chan, rx_control)) { | ||
4810 | case L2CAP_SUPER_RR: | ||
4811 | l2cap_data_channel_rrframe(chan, rx_control); | ||
4812 | break; | ||
4813 | |||
4814 | case L2CAP_SUPER_REJ: | ||
4815 | l2cap_data_channel_rejframe(chan, rx_control); | ||
4816 | break; | ||
4817 | |||
4818 | case L2CAP_SUPER_SREJ: | ||
4819 | l2cap_data_channel_srejframe(chan, rx_control); | ||
4820 | break; | ||
4821 | |||
4822 | case L2CAP_SUPER_RNR: | ||
4823 | l2cap_data_channel_rnrframe(chan, rx_control); | ||
4824 | break; | ||
4825 | } | ||
4826 | |||
4827 | kfree_skb(skb); | ||
4828 | return 0; | ||
4829 | } | ||
4830 | |||
4831 | static u8 l2cap_classify_txseq(struct l2cap_chan *chan, u16 txseq) | 4339 | static u8 l2cap_classify_txseq(struct l2cap_chan *chan, u16 txseq) |
4832 | { | 4340 | { |
4833 | BT_DBG("chan %p, txseq %d", chan, txseq); | 4341 | BT_DBG("chan %p, txseq %d", chan, txseq); |