diff options
author | Andrei Emeltchenko <andrei.emeltchenko@intel.com> | 2012-02-24 09:00:00 -0500 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-02-24 13:35:02 -0500 |
commit | 9b27f350688c9399da10c2b888c4044c2c1bd923 (patch) | |
tree | fbdd090275c27a910e6b56d10f608a5ad2eb0cbf /net/bluetooth | |
parent | 5b4cedaa14bd1fe3ca1d59c684203a6ae7747faa (diff) |
Bluetooth: Remove duplicated code in l2cap conn req
The same sequence sending L2CAP Connection Request was used in several
places. Using subroutine makes those places easy to read.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Reviewed-by: Ulisses Furquim <ulisses@profusion.mobi>
Acked-by: Gustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index db04c9e4e1d9..bdcfbf0f631e 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -667,6 +667,21 @@ static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan) | |||
667 | return !test_bit(CONF_CONNECT_PEND, &chan->conf_state); | 667 | return !test_bit(CONF_CONNECT_PEND, &chan->conf_state); |
668 | } | 668 | } |
669 | 669 | ||
670 | static void l2cap_send_conn_req(struct l2cap_chan *chan) | ||
671 | { | ||
672 | struct l2cap_conn *conn = chan->conn; | ||
673 | struct l2cap_conn_req req; | ||
674 | |||
675 | req.scid = cpu_to_le16(chan->scid); | ||
676 | req.psm = chan->psm; | ||
677 | |||
678 | chan->ident = l2cap_get_ident(conn); | ||
679 | |||
680 | set_bit(CONF_CONNECT_PEND, &chan->conf_state); | ||
681 | |||
682 | l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ, sizeof(req), &req); | ||
683 | } | ||
684 | |||
670 | static void l2cap_do_start(struct l2cap_chan *chan) | 685 | static void l2cap_do_start(struct l2cap_chan *chan) |
671 | { | 686 | { |
672 | struct l2cap_conn *conn = chan->conn; | 687 | struct l2cap_conn *conn = chan->conn; |
@@ -676,17 +691,8 @@ static void l2cap_do_start(struct l2cap_chan *chan) | |||
676 | return; | 691 | return; |
677 | 692 | ||
678 | if (l2cap_chan_check_security(chan) && | 693 | if (l2cap_chan_check_security(chan) && |
679 | __l2cap_no_conn_pending(chan)) { | 694 | __l2cap_no_conn_pending(chan)) |
680 | struct l2cap_conn_req req; | 695 | l2cap_send_conn_req(chan); |
681 | req.scid = cpu_to_le16(chan->scid); | ||
682 | req.psm = chan->psm; | ||
683 | |||
684 | chan->ident = l2cap_get_ident(conn); | ||
685 | set_bit(CONF_CONNECT_PEND, &chan->conf_state); | ||
686 | |||
687 | l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ, | ||
688 | sizeof(req), &req); | ||
689 | } | ||
690 | } else { | 696 | } else { |
691 | struct l2cap_info_req req; | 697 | struct l2cap_info_req req; |
692 | req.type = cpu_to_le16(L2CAP_IT_FEAT_MASK); | 698 | req.type = cpu_to_le16(L2CAP_IT_FEAT_MASK); |
@@ -763,8 +769,6 @@ static void l2cap_conn_start(struct l2cap_conn *conn) | |||
763 | } | 769 | } |
764 | 770 | ||
765 | if (chan->state == BT_CONNECT) { | 771 | if (chan->state == BT_CONNECT) { |
766 | struct l2cap_conn_req req; | ||
767 | |||
768 | if (!l2cap_chan_check_security(chan) || | 772 | if (!l2cap_chan_check_security(chan) || |
769 | !__l2cap_no_conn_pending(chan)) { | 773 | !__l2cap_no_conn_pending(chan)) { |
770 | l2cap_chan_unlock(chan); | 774 | l2cap_chan_unlock(chan); |
@@ -779,14 +783,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn) | |||
779 | continue; | 783 | continue; |
780 | } | 784 | } |
781 | 785 | ||
782 | req.scid = cpu_to_le16(chan->scid); | 786 | l2cap_send_conn_req(chan); |
783 | req.psm = chan->psm; | ||
784 | |||
785 | chan->ident = l2cap_get_ident(conn); | ||
786 | set_bit(CONF_CONNECT_PEND, &chan->conf_state); | ||
787 | |||
788 | l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ, | ||
789 | sizeof(req), &req); | ||
790 | 787 | ||
791 | } else if (chan->state == BT_CONNECT2) { | 788 | } else if (chan->state == BT_CONNECT2) { |
792 | struct l2cap_conn_rsp rsp; | 789 | struct l2cap_conn_rsp rsp; |
@@ -4593,15 +4590,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt) | |||
4593 | 4590 | ||
4594 | if (chan->state == BT_CONNECT) { | 4591 | if (chan->state == BT_CONNECT) { |
4595 | if (!status) { | 4592 | if (!status) { |
4596 | struct l2cap_conn_req req; | 4593 | l2cap_send_conn_req(chan); |
4597 | req.scid = cpu_to_le16(chan->scid); | ||
4598 | req.psm = chan->psm; | ||
4599 | |||
4600 | chan->ident = l2cap_get_ident(conn); | ||
4601 | set_bit(CONF_CONNECT_PEND, &chan->conf_state); | ||
4602 | |||
4603 | l2cap_send_cmd(conn, chan->ident, | ||
4604 | L2CAP_CONN_REQ, sizeof(req), &req); | ||
4605 | } else { | 4594 | } else { |
4606 | __clear_chan_timer(chan); | 4595 | __clear_chan_timer(chan); |
4607 | __set_chan_timer(chan, | 4596 | __set_chan_timer(chan, |