diff options
author | Mat Martineau <mathewm@codeaurora.org> | 2012-04-25 19:36:15 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo@padovan.org> | 2012-05-09 00:40:47 -0400 |
commit | b5c6aaed183d6300b2cc5a107e5798aef427e5d9 (patch) | |
tree | 163656722550424d86f5dc0591ad74a024cfc56f /net/bluetooth | |
parent | 3ce3514f5d0f90c7d856e8b0f26c6da393bbeba0 (diff) |
Bluetooth: Move recently-added ERTM header packing functions
Moving these functions simplifies future patches by eliminating
forward declarations, makes future patches easier to review, and
better preserves 'git blame' information.
Signed-off-by: Mat Martineau <mathewm@codeaurora.org>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo@padovan.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 62ef7c335163..3b5238d1dfaa 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -724,87 +724,6 @@ static void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb) | |||
724 | hci_send_acl(chan->conn->hchan, skb, flags); | 724 | hci_send_acl(chan->conn->hchan, skb, flags); |
725 | } | 725 | } |
726 | 726 | ||
727 | static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) | ||
728 | { | ||
729 | struct sk_buff *skb; | ||
730 | struct l2cap_hdr *lh; | ||
731 | struct l2cap_conn *conn = chan->conn; | ||
732 | int count, hlen; | ||
733 | |||
734 | if (chan->state != BT_CONNECTED) | ||
735 | return; | ||
736 | |||
737 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | ||
738 | hlen = L2CAP_EXT_HDR_SIZE; | ||
739 | else | ||
740 | hlen = L2CAP_ENH_HDR_SIZE; | ||
741 | |||
742 | if (chan->fcs == L2CAP_FCS_CRC16) | ||
743 | hlen += L2CAP_FCS_SIZE; | ||
744 | |||
745 | BT_DBG("chan %p, control 0x%8.8x", chan, control); | ||
746 | |||
747 | count = min_t(unsigned int, conn->mtu, hlen); | ||
748 | |||
749 | control |= __set_sframe(chan); | ||
750 | |||
751 | if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state)) | ||
752 | control |= __set_ctrl_final(chan); | ||
753 | |||
754 | if (test_and_clear_bit(CONN_SEND_PBIT, &chan->conn_state)) | ||
755 | control |= __set_ctrl_poll(chan); | ||
756 | |||
757 | skb = bt_skb_alloc(count, GFP_ATOMIC); | ||
758 | if (!skb) | ||
759 | return; | ||
760 | |||
761 | lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); | ||
762 | lh->len = cpu_to_le16(hlen - L2CAP_HDR_SIZE); | ||
763 | lh->cid = cpu_to_le16(chan->dcid); | ||
764 | |||
765 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); | ||
766 | |||
767 | if (chan->fcs == L2CAP_FCS_CRC16) { | ||
768 | u16 fcs = crc16(0, (u8 *)lh, count - L2CAP_FCS_SIZE); | ||
769 | put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE)); | ||
770 | } | ||
771 | |||
772 | skb->priority = HCI_PRIO_MAX; | ||
773 | l2cap_do_send(chan, skb); | ||
774 | } | ||
775 | |||
776 | static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u32 control) | ||
777 | { | ||
778 | if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { | ||
779 | control |= __set_ctrl_super(chan, L2CAP_SUPER_RNR); | ||
780 | set_bit(CONN_RNR_SENT, &chan->conn_state); | ||
781 | } else | ||
782 | control |= __set_ctrl_super(chan, L2CAP_SUPER_RR); | ||
783 | |||
784 | control |= __set_reqseq(chan, chan->buffer_seq); | ||
785 | |||
786 | l2cap_send_sframe(chan, control); | ||
787 | } | ||
788 | |||
789 | static u16 __pack_enhanced_control(struct l2cap_ctrl *control) | ||
790 | { | ||
791 | u16 packed; | ||
792 | |||
793 | packed = control->reqseq << L2CAP_CTRL_REQSEQ_SHIFT; | ||
794 | packed |= control->final << L2CAP_CTRL_FINAL_SHIFT; | ||
795 | |||
796 | if (control->sframe) { | ||
797 | packed |= control->poll << L2CAP_CTRL_POLL_SHIFT; | ||
798 | packed |= control->super << L2CAP_CTRL_SUPER_SHIFT; | ||
799 | packed |= L2CAP_CTRL_FRAME_TYPE; | ||
800 | } else { | ||
801 | packed |= control->sar << L2CAP_CTRL_SAR_SHIFT; | ||
802 | packed |= control->txseq << L2CAP_CTRL_TXSEQ_SHIFT; | ||
803 | } | ||
804 | |||
805 | return packed; | ||
806 | } | ||
807 | |||
808 | static void __unpack_enhanced_control(u16 enh, struct l2cap_ctrl *control) | 727 | static void __unpack_enhanced_control(u16 enh, struct l2cap_ctrl *control) |
809 | { | 728 | { |
810 | control->reqseq = (enh & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; | 729 | control->reqseq = (enh & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; |
@@ -829,25 +748,6 @@ static void __unpack_enhanced_control(u16 enh, struct l2cap_ctrl *control) | |||
829 | } | 748 | } |
830 | } | 749 | } |
831 | 750 | ||
832 | static u32 __pack_extended_control(struct l2cap_ctrl *control) | ||
833 | { | ||
834 | u32 packed; | ||
835 | |||
836 | packed = control->reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT; | ||
837 | packed |= control->final << L2CAP_EXT_CTRL_FINAL_SHIFT; | ||
838 | |||
839 | if (control->sframe) { | ||
840 | packed |= control->poll << L2CAP_EXT_CTRL_POLL_SHIFT; | ||
841 | packed |= control->super << L2CAP_EXT_CTRL_SUPER_SHIFT; | ||
842 | packed |= L2CAP_EXT_CTRL_FRAME_TYPE; | ||
843 | } else { | ||
844 | packed |= control->sar << L2CAP_EXT_CTRL_SAR_SHIFT; | ||
845 | packed |= control->txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT; | ||
846 | } | ||
847 | |||
848 | return packed; | ||
849 | } | ||
850 | |||
851 | static void __unpack_extended_control(u32 ext, struct l2cap_ctrl *control) | 751 | static void __unpack_extended_control(u32 ext, struct l2cap_ctrl *control) |
852 | { | 752 | { |
853 | control->reqseq = (ext & L2CAP_EXT_CTRL_REQSEQ) >> L2CAP_EXT_CTRL_REQSEQ_SHIFT; | 753 | control->reqseq = (ext & L2CAP_EXT_CTRL_REQSEQ) >> L2CAP_EXT_CTRL_REQSEQ_SHIFT; |
@@ -884,6 +784,44 @@ static inline void __unpack_control(struct l2cap_chan *chan, | |||
884 | } | 784 | } |
885 | } | 785 | } |
886 | 786 | ||
787 | static u32 __pack_extended_control(struct l2cap_ctrl *control) | ||
788 | { | ||
789 | u32 packed; | ||
790 | |||
791 | packed = control->reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT; | ||
792 | packed |= control->final << L2CAP_EXT_CTRL_FINAL_SHIFT; | ||
793 | |||
794 | if (control->sframe) { | ||
795 | packed |= control->poll << L2CAP_EXT_CTRL_POLL_SHIFT; | ||
796 | packed |= control->super << L2CAP_EXT_CTRL_SUPER_SHIFT; | ||
797 | packed |= L2CAP_EXT_CTRL_FRAME_TYPE; | ||
798 | } else { | ||
799 | packed |= control->sar << L2CAP_EXT_CTRL_SAR_SHIFT; | ||
800 | packed |= control->txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT; | ||
801 | } | ||
802 | |||
803 | return packed; | ||
804 | } | ||
805 | |||
806 | static u16 __pack_enhanced_control(struct l2cap_ctrl *control) | ||
807 | { | ||
808 | u16 packed; | ||
809 | |||
810 | packed = control->reqseq << L2CAP_CTRL_REQSEQ_SHIFT; | ||
811 | packed |= control->final << L2CAP_CTRL_FINAL_SHIFT; | ||
812 | |||
813 | if (control->sframe) { | ||
814 | packed |= control->poll << L2CAP_CTRL_POLL_SHIFT; | ||
815 | packed |= control->super << L2CAP_CTRL_SUPER_SHIFT; | ||
816 | packed |= L2CAP_CTRL_FRAME_TYPE; | ||
817 | } else { | ||
818 | packed |= control->sar << L2CAP_CTRL_SAR_SHIFT; | ||
819 | packed |= control->txseq << L2CAP_CTRL_TXSEQ_SHIFT; | ||
820 | } | ||
821 | |||
822 | return packed; | ||
823 | } | ||
824 | |||
887 | static inline void __pack_control(struct l2cap_chan *chan, | 825 | static inline void __pack_control(struct l2cap_chan *chan, |
888 | struct l2cap_ctrl *control, | 826 | struct l2cap_ctrl *control, |
889 | struct sk_buff *skb) | 827 | struct sk_buff *skb) |
@@ -897,6 +835,68 @@ static inline void __pack_control(struct l2cap_chan *chan, | |||
897 | } | 835 | } |
898 | } | 836 | } |
899 | 837 | ||
838 | static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) | ||
839 | { | ||
840 | struct sk_buff *skb; | ||
841 | struct l2cap_hdr *lh; | ||
842 | struct l2cap_conn *conn = chan->conn; | ||
843 | int count, hlen; | ||
844 | |||
845 | if (chan->state != BT_CONNECTED) | ||
846 | return; | ||
847 | |||
848 | if (test_bit(FLAG_EXT_CTRL, &chan->flags)) | ||
849 | hlen = L2CAP_EXT_HDR_SIZE; | ||
850 | else | ||
851 | hlen = L2CAP_ENH_HDR_SIZE; | ||
852 | |||
853 | if (chan->fcs == L2CAP_FCS_CRC16) | ||
854 | hlen += L2CAP_FCS_SIZE; | ||
855 | |||
856 | BT_DBG("chan %p, control 0x%8.8x", chan, control); | ||
857 | |||
858 | count = min_t(unsigned int, conn->mtu, hlen); | ||
859 | |||
860 | control |= __set_sframe(chan); | ||
861 | |||
862 | if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state)) | ||
863 | control |= __set_ctrl_final(chan); | ||
864 | |||
865 | if (test_and_clear_bit(CONN_SEND_PBIT, &chan->conn_state)) | ||
866 | control |= __set_ctrl_poll(chan); | ||
867 | |||
868 | skb = bt_skb_alloc(count, GFP_ATOMIC); | ||
869 | if (!skb) | ||
870 | return; | ||
871 | |||
872 | lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); | ||
873 | lh->len = cpu_to_le16(hlen - L2CAP_HDR_SIZE); | ||
874 | lh->cid = cpu_to_le16(chan->dcid); | ||
875 | |||
876 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); | ||
877 | |||
878 | if (chan->fcs == L2CAP_FCS_CRC16) { | ||
879 | u16 fcs = crc16(0, (u8 *)lh, count - L2CAP_FCS_SIZE); | ||
880 | put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE)); | ||
881 | } | ||
882 | |||
883 | skb->priority = HCI_PRIO_MAX; | ||
884 | l2cap_do_send(chan, skb); | ||
885 | } | ||
886 | |||
887 | static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u32 control) | ||
888 | { | ||
889 | if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { | ||
890 | control |= __set_ctrl_super(chan, L2CAP_SUPER_RNR); | ||
891 | set_bit(CONN_RNR_SENT, &chan->conn_state); | ||
892 | } else | ||
893 | control |= __set_ctrl_super(chan, L2CAP_SUPER_RR); | ||
894 | |||
895 | control |= __set_reqseq(chan, chan->buffer_seq); | ||
896 | |||
897 | l2cap_send_sframe(chan, control); | ||
898 | } | ||
899 | |||
900 | static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan) | 900 | static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan) |
901 | { | 901 | { |
902 | return !test_bit(CONF_CONNECT_PEND, &chan->conf_state); | 902 | return !test_bit(CONF_CONNECT_PEND, &chan->conf_state); |