2424 SOFTWARE IS DISCLAIMED.
2525*/
2626
27- /* Bluetooth L2CAP core and sockets . */
27+ /* Bluetooth L2CAP core. */
2828
2929#include <linux/module.h>
3030
5757
5858#define VERSION "2.15"
5959
60- static int disable_ertm ;
60+ int disable_ertm ;
6161
6262static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN ;
6363static u8 l2cap_fixed_chan [8 ] = { 0x02 , };
6464
65- static const struct proto_ops l2cap_sock_ops ;
66-
6765static struct workqueue_struct * _busy_wq ;
6866
69- static struct bt_sock_list l2cap_sk_list = {
67+ struct bt_sock_list l2cap_sk_list = {
7068 .lock = __RW_LOCK_UNLOCKED (l2cap_sk_list .lock )
7169};
7270
7371static void l2cap_busy_work (struct work_struct * work );
7472
75- static void __l2cap_sock_close (struct sock * sk , int reason );
7673static void l2cap_sock_close (struct sock * sk );
77- static void l2cap_sock_kill (struct sock * sk );
7874
7975static int l2cap_build_conf_req (struct sock * sk , void * data );
8076static struct sk_buff * l2cap_build_cmd (struct l2cap_conn * conn ,
@@ -83,7 +79,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
8379static int l2cap_ertm_data_rcv (struct sock * sk , struct sk_buff * skb );
8480
8581/* ---- L2CAP timers ---- */
86- static void l2cap_sock_set_timer (struct sock * sk , long timeout )
82+ void l2cap_sock_set_timer (struct sock * sk , long timeout )
8783{
8884 BT_DBG ("sk %p state %d timeout %ld" , sk , sk -> sk_state , timeout );
8985 sk_reset_timer (sk , & sk -> sk_timer , jiffies + timeout );
@@ -95,39 +91,6 @@ static void l2cap_sock_clear_timer(struct sock *sk)
9591 sk_stop_timer (sk , & sk -> sk_timer );
9692}
9793
98- static void l2cap_sock_timeout (unsigned long arg )
99- {
100- struct sock * sk = (struct sock * ) arg ;
101- int reason ;
102-
103- BT_DBG ("sock %p state %d" , sk , sk -> sk_state );
104-
105- bh_lock_sock (sk );
106-
107- if (sock_owned_by_user (sk )) {
108- /* sk is owned by user. Try again later */
109- l2cap_sock_set_timer (sk , HZ / 5 );
110- bh_unlock_sock (sk );
111- sock_put (sk );
112- return ;
113- }
114-
115- if (sk -> sk_state == BT_CONNECTED || sk -> sk_state == BT_CONFIG )
116- reason = ECONNREFUSED ;
117- else if (sk -> sk_state == BT_CONNECT &&
118- l2cap_pi (sk )-> sec_level != BT_SECURITY_SDP )
119- reason = ECONNREFUSED ;
120- else
121- reason = ETIMEDOUT ;
122-
123- __l2cap_sock_close (sk , reason );
124-
125- bh_unlock_sock (sk );
126-
127- l2cap_sock_kill (sk );
128- sock_put (sk );
129- }
130-
13194/* ---- L2CAP channels ---- */
13295static struct sock * __l2cap_get_chan_by_dcid (struct l2cap_chan_list * l , u16 cid )
13396{
@@ -801,14 +764,6 @@ static struct sock *l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src)
801764 return node ? sk : sk1 ;
802765}
803766
804- static void l2cap_sock_destruct (struct sock * sk )
805- {
806- BT_DBG ("sk %p" , sk );
807-
808- skb_queue_purge (& sk -> sk_receive_queue );
809- skb_queue_purge (& sk -> sk_write_queue );
810- }
811-
812767static void l2cap_sock_cleanup_listen (struct sock * parent )
813768{
814769 struct sock * sk ;
@@ -826,7 +781,7 @@ static void l2cap_sock_cleanup_listen(struct sock *parent)
826781/* Kill socket (only if zapped and orphan)
827782 * Must be called on unlocked socket.
828783 */
829- static void l2cap_sock_kill (struct sock * sk )
784+ void l2cap_sock_kill (struct sock * sk )
830785{
831786 if (!sock_flag (sk , SOCK_ZAPPED ) || sk -> sk_socket )
832787 return ;
@@ -839,7 +794,7 @@ static void l2cap_sock_kill(struct sock *sk)
839794 sock_put (sk );
840795}
841796
842- static void __l2cap_sock_close (struct sock * sk , int reason )
797+ void __l2cap_sock_close (struct sock * sk , int reason )
843798{
844799 BT_DBG ("sk %p state %d socket %p" , sk , sk -> sk_state , sk -> sk_socket );
845800
@@ -904,111 +859,6 @@ static void l2cap_sock_close(struct sock *sk)
904859 l2cap_sock_kill (sk );
905860}
906861
907- static void l2cap_sock_init (struct sock * sk , struct sock * parent )
908- {
909- struct l2cap_pinfo * pi = l2cap_pi (sk );
910-
911- BT_DBG ("sk %p" , sk );
912-
913- if (parent ) {
914- sk -> sk_type = parent -> sk_type ;
915- bt_sk (sk )-> defer_setup = bt_sk (parent )-> defer_setup ;
916-
917- pi -> imtu = l2cap_pi (parent )-> imtu ;
918- pi -> omtu = l2cap_pi (parent )-> omtu ;
919- pi -> conf_state = l2cap_pi (parent )-> conf_state ;
920- pi -> mode = l2cap_pi (parent )-> mode ;
921- pi -> fcs = l2cap_pi (parent )-> fcs ;
922- pi -> max_tx = l2cap_pi (parent )-> max_tx ;
923- pi -> tx_win = l2cap_pi (parent )-> tx_win ;
924- pi -> sec_level = l2cap_pi (parent )-> sec_level ;
925- pi -> role_switch = l2cap_pi (parent )-> role_switch ;
926- pi -> force_reliable = l2cap_pi (parent )-> force_reliable ;
927- pi -> flushable = l2cap_pi (parent )-> flushable ;
928- } else {
929- pi -> imtu = L2CAP_DEFAULT_MTU ;
930- pi -> omtu = 0 ;
931- if (!disable_ertm && sk -> sk_type == SOCK_STREAM ) {
932- pi -> mode = L2CAP_MODE_ERTM ;
933- pi -> conf_state |= L2CAP_CONF_STATE2_DEVICE ;
934- } else {
935- pi -> mode = L2CAP_MODE_BASIC ;
936- }
937- pi -> max_tx = L2CAP_DEFAULT_MAX_TX ;
938- pi -> fcs = L2CAP_FCS_CRC16 ;
939- pi -> tx_win = L2CAP_DEFAULT_TX_WINDOW ;
940- pi -> sec_level = BT_SECURITY_LOW ;
941- pi -> role_switch = 0 ;
942- pi -> force_reliable = 0 ;
943- pi -> flushable = BT_FLUSHABLE_OFF ;
944- }
945-
946- /* Default config options */
947- pi -> conf_len = 0 ;
948- pi -> flush_to = L2CAP_DEFAULT_FLUSH_TO ;
949- skb_queue_head_init (TX_QUEUE (sk ));
950- skb_queue_head_init (SREJ_QUEUE (sk ));
951- skb_queue_head_init (BUSY_QUEUE (sk ));
952- INIT_LIST_HEAD (SREJ_LIST (sk ));
953- }
954-
955- static struct proto l2cap_proto = {
956- .name = "L2CAP" ,
957- .owner = THIS_MODULE ,
958- .obj_size = sizeof (struct l2cap_pinfo )
959- };
960-
961- static struct sock * l2cap_sock_alloc (struct net * net , struct socket * sock , int proto , gfp_t prio )
962- {
963- struct sock * sk ;
964-
965- sk = sk_alloc (net , PF_BLUETOOTH , prio , & l2cap_proto );
966- if (!sk )
967- return NULL ;
968-
969- sock_init_data (sock , sk );
970- INIT_LIST_HEAD (& bt_sk (sk )-> accept_q );
971-
972- sk -> sk_destruct = l2cap_sock_destruct ;
973- sk -> sk_sndtimeo = msecs_to_jiffies (L2CAP_CONN_TIMEOUT );
974-
975- sock_reset_flag (sk , SOCK_ZAPPED );
976-
977- sk -> sk_protocol = proto ;
978- sk -> sk_state = BT_OPEN ;
979-
980- setup_timer (& sk -> sk_timer , l2cap_sock_timeout , (unsigned long ) sk );
981-
982- bt_sock_link (& l2cap_sk_list , sk );
983- return sk ;
984- }
985-
986- static int l2cap_sock_create (struct net * net , struct socket * sock , int protocol ,
987- int kern )
988- {
989- struct sock * sk ;
990-
991- BT_DBG ("sock %p" , sock );
992-
993- sock -> state = SS_UNCONNECTED ;
994-
995- if (sock -> type != SOCK_SEQPACKET && sock -> type != SOCK_STREAM &&
996- sock -> type != SOCK_DGRAM && sock -> type != SOCK_RAW )
997- return - ESOCKTNOSUPPORT ;
998-
999- if (sock -> type == SOCK_RAW && !kern && !capable (CAP_NET_RAW ))
1000- return - EPERM ;
1001-
1002- sock -> ops = & l2cap_sock_ops ;
1003-
1004- sk = l2cap_sock_alloc (net , sock , protocol , GFP_ATOMIC );
1005- if (!sk )
1006- return - ENOMEM ;
1007-
1008- l2cap_sock_init (sk , NULL );
1009- return 0 ;
1010- }
1011-
1012862static int l2cap_sock_bind (struct socket * sock , struct sockaddr * addr , int alen )
1013863{
1014864 struct sock * sk = sock -> sk ;
@@ -4865,7 +4715,7 @@ static const struct file_operations l2cap_debugfs_fops = {
48654715
48664716static struct dentry * l2cap_debugfs ;
48674717
4868- static const struct proto_ops l2cap_sock_ops = {
4718+ const struct proto_ops l2cap_sock_ops = {
48694719 .family = PF_BLUETOOTH ,
48704720 .owner = THIS_MODULE ,
48714721 .release = l2cap_sock_release ,
@@ -4885,12 +4735,6 @@ static const struct proto_ops l2cap_sock_ops = {
48854735 .getsockopt = l2cap_sock_getsockopt
48864736};
48874737
4888- static const struct net_proto_family l2cap_sock_family_ops = {
4889- .family = PF_BLUETOOTH ,
4890- .owner = THIS_MODULE ,
4891- .create = l2cap_sock_create ,
4892- };
4893-
48944738static struct hci_proto l2cap_hci_proto = {
48954739 .name = "L2CAP" ,
48964740 .id = HCI_PROTO_L2CAP ,
@@ -4906,19 +4750,13 @@ static int __init l2cap_init(void)
49064750{
49074751 int err ;
49084752
4909- err = proto_register ( & l2cap_proto , 0 );
4753+ err = l2cap_init_sockets ( );
49104754 if (err < 0 )
49114755 return err ;
49124756
49134757 _busy_wq = create_singlethread_workqueue ("l2cap" );
49144758 if (!_busy_wq ) {
4915- proto_unregister (& l2cap_proto );
4916- return - ENOMEM ;
4917- }
4918-
4919- err = bt_sock_register (BTPROTO_L2CAP , & l2cap_sock_family_ops );
4920- if (err < 0 ) {
4921- BT_ERR ("L2CAP socket registration failed" );
4759+ err = - ENOMEM ;
49224760 goto error ;
49234761 }
49244762
@@ -4943,7 +4781,7 @@ static int __init l2cap_init(void)
49434781
49444782error :
49454783 destroy_workqueue (_busy_wq );
4946- proto_unregister ( & l2cap_proto );
4784+ l2cap_cleanup_sockets ( );
49474785 return err ;
49484786}
49494787
@@ -4954,13 +4792,10 @@ static void __exit l2cap_exit(void)
49544792 flush_workqueue (_busy_wq );
49554793 destroy_workqueue (_busy_wq );
49564794
4957- if (bt_sock_unregister (BTPROTO_L2CAP ) < 0 )
4958- BT_ERR ("L2CAP socket unregistration failed" );
4959-
49604795 if (hci_unregister_proto (& l2cap_hci_proto ) < 0 )
49614796 BT_ERR ("L2CAP protocol unregistration failed" );
49624797
4963- proto_unregister ( & l2cap_proto );
4798+ l2cap_cleanup_sockets ( );
49644799}
49654800
49664801void l2cap_load (void )
0 commit comments