aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo F. Padovan <padovan@profusion.mobi>2011-02-04 00:35:20 -0500
committerGustavo F. Padovan <padovan@profusion.mobi>2011-02-07 22:46:02 -0500
commit6de0702b5b93da0ef097aa092b4597fbc024ebba (patch)
tree601d1ac548d2c5e83be23c9a81472665378e0503
parent05fc1576dabb1defae3c8c0371fb9d21f7db997a (diff)
Bluetooth: move __l2cap_sock_close() to l2cap_sock.c
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r--include/net/bluetooth/l2cap.h2
-rw-r--r--net/bluetooth/l2cap_core.c85
-rw-r--r--net/bluetooth/l2cap_sock.c78
3 files changed, 82 insertions, 83 deletions
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index d4c93eded727..75ef0b2948f9 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -451,6 +451,8 @@ void l2cap_sock_kill(struct sock *sk);
451void l2cap_sock_init(struct sock *sk, struct sock *parent); 451void l2cap_sock_init(struct sock *sk, struct sock *parent);
452struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, 452struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
453 int proto, gfp_t prio); 453 int proto, gfp_t prio);
454void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err);
455void l2cap_chan_del(struct sock *sk, int err);
454int l2cap_do_connect(struct sock *sk); 456int l2cap_do_connect(struct sock *sk);
455 457
456void l2cap_load(void); 458void l2cap_load(void);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 9d51af300d9c..ba7f9da68998 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -70,8 +70,6 @@ struct bt_sock_list l2cap_sk_list = {
70 70
71static void l2cap_busy_work(struct work_struct *work); 71static void l2cap_busy_work(struct work_struct *work);
72 72
73static void l2cap_sock_close(struct sock *sk);
74
75static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, 73static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
76 u8 code, u8 ident, u16 dlen, void *data); 74 u8 code, u8 ident, u16 dlen, void *data);
77 75
@@ -207,7 +205,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct sock *sk, struct so
207 205
208/* Delete channel. 206/* Delete channel.
209 * Must be called on the locked socket. */ 207 * Must be called on the locked socket. */
210static void l2cap_chan_del(struct sock *sk, int err) 208void l2cap_chan_del(struct sock *sk, int err)
211{ 209{
212 struct l2cap_conn *conn = l2cap_pi(sk)->conn; 210 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
213 struct sock *parent = bt_sk(sk)->parent; 211 struct sock *parent = bt_sk(sk)->parent;
@@ -457,7 +455,7 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
457 } 455 }
458} 456}
459 457
460static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err) 458void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err)
461{ 459{
462 struct l2cap_disconn_req req; 460 struct l2cap_disconn_req req;
463 461
@@ -739,85 +737,6 @@ static struct sock *l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src)
739 return node ? sk : sk1; 737 return node ? sk : sk1;
740} 738}
741 739
742static void l2cap_sock_cleanup_listen(struct sock *parent)
743{
744 struct sock *sk;
745
746 BT_DBG("parent %p", parent);
747
748 /* Close not yet accepted channels */
749 while ((sk = bt_accept_dequeue(parent, NULL)))
750 l2cap_sock_close(sk);
751
752 parent->sk_state = BT_CLOSED;
753 sock_set_flag(parent, SOCK_ZAPPED);
754}
755
756void __l2cap_sock_close(struct sock *sk, int reason)
757{
758 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
759
760 switch (sk->sk_state) {
761 case BT_LISTEN:
762 l2cap_sock_cleanup_listen(sk);
763 break;
764
765 case BT_CONNECTED:
766 case BT_CONFIG:
767 if (sk->sk_type == SOCK_SEQPACKET ||
768 sk->sk_type == SOCK_STREAM) {
769 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
770
771 l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
772 l2cap_send_disconn_req(conn, sk, reason);
773 } else
774 l2cap_chan_del(sk, reason);
775 break;
776
777 case BT_CONNECT2:
778 if (sk->sk_type == SOCK_SEQPACKET ||
779 sk->sk_type == SOCK_STREAM) {
780 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
781 struct l2cap_conn_rsp rsp;
782 __u16 result;
783
784 if (bt_sk(sk)->defer_setup)
785 result = L2CAP_CR_SEC_BLOCK;
786 else
787 result = L2CAP_CR_BAD_PSM;
788 sk->sk_state = BT_DISCONN;
789
790 rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid);
791 rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid);
792 rsp.result = cpu_to_le16(result);
793 rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO);
794 l2cap_send_cmd(conn, l2cap_pi(sk)->ident,
795 L2CAP_CONN_RSP, sizeof(rsp), &rsp);
796 } else
797 l2cap_chan_del(sk, reason);
798 break;
799
800 case BT_CONNECT:
801 case BT_DISCONN:
802 l2cap_chan_del(sk, reason);
803 break;
804
805 default:
806 sock_set_flag(sk, SOCK_ZAPPED);
807 break;
808 }
809}
810
811/* Must be called on unlocked socket. */
812static void l2cap_sock_close(struct sock *sk)
813{
814 l2cap_sock_clear_timer(sk);
815 lock_sock(sk);
816 __l2cap_sock_close(sk, ECONNRESET);
817 release_sock(sk);
818 l2cap_sock_kill(sk);
819}
820
821int l2cap_do_connect(struct sock *sk) 740int l2cap_do_connect(struct sock *sk)
822{ 741{
823 bdaddr_t *src = &bt_sk(sk)->src; 742 bdaddr_t *src = &bt_sk(sk)->src;
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 4b4e0201ebbe..adf41692daf3 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -854,6 +854,84 @@ void l2cap_sock_kill(struct sock *sk)
854 sock_put(sk); 854 sock_put(sk);
855} 855}
856 856
857/* Must be called on unlocked socket. */
858static void l2cap_sock_close(struct sock *sk)
859{
860 l2cap_sock_clear_timer(sk);
861 lock_sock(sk);
862 __l2cap_sock_close(sk, ECONNRESET);
863 release_sock(sk);
864 l2cap_sock_kill(sk);
865}
866
867static void l2cap_sock_cleanup_listen(struct sock *parent)
868{
869 struct sock *sk;
870
871 BT_DBG("parent %p", parent);
872
873 /* Close not yet accepted channels */
874 while ((sk = bt_accept_dequeue(parent, NULL)))
875 l2cap_sock_close(sk);
876
877 parent->sk_state = BT_CLOSED;
878 sock_set_flag(parent, SOCK_ZAPPED);
879}
880
881void __l2cap_sock_close(struct sock *sk, int reason)
882{
883 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket);
884
885 switch (sk->sk_state) {
886 case BT_LISTEN:
887 l2cap_sock_cleanup_listen(sk);
888 break;
889
890 case BT_CONNECTED:
891 case BT_CONFIG:
892 if (sk->sk_type == SOCK_SEQPACKET ||
893 sk->sk_type == SOCK_STREAM) {
894 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
895
896 l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
897 l2cap_send_disconn_req(conn, sk, reason);
898 } else
899 l2cap_chan_del(sk, reason);
900 break;
901
902 case BT_CONNECT2:
903 if (sk->sk_type == SOCK_SEQPACKET ||
904 sk->sk_type == SOCK_STREAM) {
905 struct l2cap_conn *conn = l2cap_pi(sk)->conn;
906 struct l2cap_conn_rsp rsp;
907 __u16 result;
908
909 if (bt_sk(sk)->defer_setup)
910 result = L2CAP_CR_SEC_BLOCK;
911 else
912 result = L2CAP_CR_BAD_PSM;
913
914 rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid);
915 rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid);
916 rsp.result = cpu_to_le16(result);
917 rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO);
918 l2cap_send_cmd(conn, l2cap_pi(sk)->ident,
919 L2CAP_CONN_RSP, sizeof(rsp), &rsp);
920 } else
921 l2cap_chan_del(sk, reason);
922 break;
923
924 case BT_CONNECT:
925 case BT_DISCONN:
926 l2cap_chan_del(sk, reason);
927 break;
928
929 default:
930 sock_set_flag(sk, SOCK_ZAPPED);
931 break;
932 }
933}
934
857static int l2cap_sock_shutdown(struct socket *sock, int how) 935static int l2cap_sock_shutdown(struct socket *sock, int how)
858{ 936{
859 struct sock *sk = sock->sk; 937 struct sock *sk = sock->sk;