Lines Matching refs:sk
48 struct sock *sk; member
56 static void sco_sock_close(struct sock *sk);
57 static void sco_sock_kill(struct sock *sk);
60 #define sco_pi(sk) ((struct sco_pinfo *) sk) argument
77 struct sock *sk = (struct sock *)arg; in sco_sock_timeout() local
79 BT_DBG("sock %p state %d", sk, sk->sk_state); in sco_sock_timeout()
81 bh_lock_sock(sk); in sco_sock_timeout()
82 sk->sk_err = ETIMEDOUT; in sco_sock_timeout()
83 sk->sk_state_change(sk); in sco_sock_timeout()
84 bh_unlock_sock(sk); in sco_sock_timeout()
86 sco_sock_kill(sk); in sco_sock_timeout()
87 sock_put(sk); in sco_sock_timeout()
90 static void sco_sock_set_timer(struct sock *sk, long timeout) in sco_sock_set_timer() argument
92 BT_DBG("sock %p state %d timeout %ld", sk, sk->sk_state, timeout); in sco_sock_set_timer()
93 sk_reset_timer(sk, &sk->sk_timer, jiffies + timeout); in sco_sock_set_timer()
96 static void sco_sock_clear_timer(struct sock *sk) in sco_sock_clear_timer() argument
98 BT_DBG("sock %p state %d", sk, sk->sk_state); in sco_sock_clear_timer()
99 sk_stop_timer(sk, &sk->sk_timer); in sco_sock_clear_timer()
132 static void sco_chan_del(struct sock *sk, int err) in sco_chan_del() argument
136 conn = sco_pi(sk)->conn; in sco_chan_del()
138 BT_DBG("sk %p, conn %p, err %d", sk, conn, err); in sco_chan_del()
142 conn->sk = NULL; in sco_chan_del()
143 sco_pi(sk)->conn = NULL; in sco_chan_del()
150 sk->sk_state = BT_CLOSED; in sco_chan_del()
151 sk->sk_err = err; in sco_chan_del()
152 sk->sk_state_change(sk); in sco_chan_del()
154 sock_set_flag(sk, SOCK_ZAPPED); in sco_chan_del()
160 struct sock *sk; in sco_conn_del() local
169 sk = conn->sk; in sco_conn_del()
172 if (sk) { in sco_conn_del()
173 sock_hold(sk); in sco_conn_del()
174 bh_lock_sock(sk); in sco_conn_del()
175 sco_sock_clear_timer(sk); in sco_conn_del()
176 sco_chan_del(sk, err); in sco_conn_del()
177 bh_unlock_sock(sk); in sco_conn_del()
178 sco_sock_kill(sk); in sco_conn_del()
179 sock_put(sk); in sco_conn_del()
186 static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, in __sco_chan_add() argument
191 sco_pi(sk)->conn = conn; in __sco_chan_add()
192 conn->sk = sk; in __sco_chan_add()
195 bt_accept_enqueue(parent, sk); in __sco_chan_add()
198 static int sco_chan_add(struct sco_conn *conn, struct sock *sk, in sco_chan_add() argument
204 if (conn->sk) in sco_chan_add()
207 __sco_chan_add(conn, sk, parent); in sco_chan_add()
213 static int sco_connect(struct sock *sk) in sco_connect() argument
220 BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst); in sco_connect()
222 hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src, BDADDR_BREDR); in sco_connect()
233 if (sco_pi(sk)->setting == BT_VOICE_TRANSPARENT && in sco_connect()
239 hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst, in sco_connect()
240 sco_pi(sk)->setting); in sco_connect()
254 bacpy(&sco_pi(sk)->src, &hcon->src); in sco_connect()
256 err = sco_chan_add(conn, sk, NULL); in sco_connect()
261 sco_sock_clear_timer(sk); in sco_connect()
262 sk->sk_state = BT_CONNECTED; in sco_connect()
264 sk->sk_state = BT_CONNECT; in sco_connect()
265 sco_sock_set_timer(sk, sk->sk_sndtimeo); in sco_connect()
274 static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) in sco_send_frame() argument
276 struct sco_conn *conn = sco_pi(sk)->conn; in sco_send_frame()
284 BT_DBG("sk %p len %d", sk, len); in sco_send_frame()
286 skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err); in sco_send_frame()
302 struct sock *sk; in sco_recv_frame() local
305 sk = conn->sk; in sco_recv_frame()
308 if (!sk) in sco_recv_frame()
311 BT_DBG("sk %p len %d", sk, skb->len); in sco_recv_frame()
313 if (sk->sk_state != BT_CONNECTED) in sco_recv_frame()
316 if (!sock_queue_rcv_skb(sk, skb)) in sco_recv_frame()
326 struct sock *sk; in __sco_get_sock_listen_by_addr() local
328 sk_for_each(sk, &sco_sk_list.head) { in __sco_get_sock_listen_by_addr()
329 if (sk->sk_state != BT_LISTEN) in __sco_get_sock_listen_by_addr()
332 if (!bacmp(&sco_pi(sk)->src, ba)) in __sco_get_sock_listen_by_addr()
333 return sk; in __sco_get_sock_listen_by_addr()
344 struct sock *sk = NULL, *sk1 = NULL; in sco_get_sock_listen() local
348 sk_for_each(sk, &sco_sk_list.head) { in sco_get_sock_listen()
349 if (sk->sk_state != BT_LISTEN) in sco_get_sock_listen()
353 if (!bacmp(&sco_pi(sk)->src, src)) in sco_get_sock_listen()
357 if (!bacmp(&sco_pi(sk)->src, BDADDR_ANY)) in sco_get_sock_listen()
358 sk1 = sk; in sco_get_sock_listen()
363 return sk ? sk : sk1; in sco_get_sock_listen()
366 static void sco_sock_destruct(struct sock *sk) in sco_sock_destruct() argument
368 BT_DBG("sk %p", sk); in sco_sock_destruct()
370 skb_queue_purge(&sk->sk_receive_queue); in sco_sock_destruct()
371 skb_queue_purge(&sk->sk_write_queue); in sco_sock_destruct()
376 struct sock *sk; in sco_sock_cleanup_listen() local
381 while ((sk = bt_accept_dequeue(parent, NULL))) { in sco_sock_cleanup_listen()
382 sco_sock_close(sk); in sco_sock_cleanup_listen()
383 sco_sock_kill(sk); in sco_sock_cleanup_listen()
393 static void sco_sock_kill(struct sock *sk) in sco_sock_kill() argument
395 if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) in sco_sock_kill()
398 BT_DBG("sk %p state %d", sk, sk->sk_state); in sco_sock_kill()
401 bt_sock_unlink(&sco_sk_list, sk); in sco_sock_kill()
402 sock_set_flag(sk, SOCK_DEAD); in sco_sock_kill()
403 sock_put(sk); in sco_sock_kill()
406 static void __sco_sock_close(struct sock *sk) in __sco_sock_close() argument
408 BT_DBG("sk %p state %d socket %p", sk, sk->sk_state, sk->sk_socket); in __sco_sock_close()
410 switch (sk->sk_state) { in __sco_sock_close()
412 sco_sock_cleanup_listen(sk); in __sco_sock_close()
417 if (sco_pi(sk)->conn->hcon) { in __sco_sock_close()
418 sk->sk_state = BT_DISCONN; in __sco_sock_close()
419 sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT); in __sco_sock_close()
420 sco_conn_lock(sco_pi(sk)->conn); in __sco_sock_close()
421 hci_conn_drop(sco_pi(sk)->conn->hcon); in __sco_sock_close()
422 sco_pi(sk)->conn->hcon = NULL; in __sco_sock_close()
423 sco_conn_unlock(sco_pi(sk)->conn); in __sco_sock_close()
425 sco_chan_del(sk, ECONNRESET); in __sco_sock_close()
431 sco_chan_del(sk, ECONNRESET); in __sco_sock_close()
435 sock_set_flag(sk, SOCK_ZAPPED); in __sco_sock_close()
441 static void sco_sock_close(struct sock *sk) in sco_sock_close() argument
443 sco_sock_clear_timer(sk); in sco_sock_close()
444 lock_sock(sk); in sco_sock_close()
445 __sco_sock_close(sk); in sco_sock_close()
446 release_sock(sk); in sco_sock_close()
447 sco_sock_kill(sk); in sco_sock_close()
450 static void sco_sock_init(struct sock *sk, struct sock *parent) in sco_sock_init() argument
452 BT_DBG("sk %p", sk); in sco_sock_init()
455 sk->sk_type = parent->sk_type; in sco_sock_init()
456 bt_sk(sk)->flags = bt_sk(parent)->flags; in sco_sock_init()
457 security_sk_clone(parent, sk); in sco_sock_init()
470 struct sock *sk; in sco_sock_alloc() local
472 sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto, kern); in sco_sock_alloc()
473 if (!sk) in sco_sock_alloc()
476 sock_init_data(sock, sk); in sco_sock_alloc()
477 INIT_LIST_HEAD(&bt_sk(sk)->accept_q); in sco_sock_alloc()
479 sk->sk_destruct = sco_sock_destruct; in sco_sock_alloc()
480 sk->sk_sndtimeo = SCO_CONN_TIMEOUT; in sco_sock_alloc()
482 sock_reset_flag(sk, SOCK_ZAPPED); in sco_sock_alloc()
484 sk->sk_protocol = proto; in sco_sock_alloc()
485 sk->sk_state = BT_OPEN; in sco_sock_alloc()
487 sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT; in sco_sock_alloc()
489 setup_timer(&sk->sk_timer, sco_sock_timeout, (unsigned long)sk); in sco_sock_alloc()
491 bt_sock_link(&sco_sk_list, sk); in sco_sock_alloc()
492 return sk; in sco_sock_alloc()
498 struct sock *sk; in sco_sock_create() local
509 sk = sco_sock_alloc(net, sock, protocol, GFP_ATOMIC, kern); in sco_sock_create()
510 if (!sk) in sco_sock_create()
513 sco_sock_init(sk, NULL); in sco_sock_create()
521 struct sock *sk = sock->sk; in sco_sock_bind() local
524 BT_DBG("sk %p %pMR", sk, &sa->sco_bdaddr); in sco_sock_bind()
532 lock_sock(sk); in sco_sock_bind()
534 if (sk->sk_state != BT_OPEN) { in sco_sock_bind()
539 if (sk->sk_type != SOCK_SEQPACKET) { in sco_sock_bind()
544 bacpy(&sco_pi(sk)->src, &sa->sco_bdaddr); in sco_sock_bind()
546 sk->sk_state = BT_BOUND; in sco_sock_bind()
549 release_sock(sk); in sco_sock_bind()
556 struct sock *sk = sock->sk; in sco_sock_connect() local
559 BT_DBG("sk %p", sk); in sco_sock_connect()
565 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) in sco_sock_connect()
568 if (sk->sk_type != SOCK_SEQPACKET) in sco_sock_connect()
571 lock_sock(sk); in sco_sock_connect()
574 bacpy(&sco_pi(sk)->dst, &sa->sco_bdaddr); in sco_sock_connect()
576 err = sco_connect(sk); in sco_sock_connect()
580 err = bt_sock_wait_state(sk, BT_CONNECTED, in sco_sock_connect()
581 sock_sndtimeo(sk, flags & O_NONBLOCK)); in sco_sock_connect()
584 release_sock(sk); in sco_sock_connect()
590 struct sock *sk = sock->sk; in sco_sock_listen() local
591 bdaddr_t *src = &sco_pi(sk)->src; in sco_sock_listen()
594 BT_DBG("sk %p backlog %d", sk, backlog); in sco_sock_listen()
596 lock_sock(sk); in sco_sock_listen()
598 if (sk->sk_state != BT_BOUND) { in sco_sock_listen()
603 if (sk->sk_type != SOCK_SEQPACKET) { in sco_sock_listen()
615 sk->sk_max_ack_backlog = backlog; in sco_sock_listen()
616 sk->sk_ack_backlog = 0; in sco_sock_listen()
618 sk->sk_state = BT_LISTEN; in sco_sock_listen()
624 release_sock(sk); in sco_sock_listen()
632 struct sock *sk = sock->sk, *ch; in sco_sock_accept() local
636 lock_sock(sk); in sco_sock_accept()
638 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); in sco_sock_accept()
640 BT_DBG("sk %p timeo %ld", sk, timeo); in sco_sock_accept()
643 add_wait_queue_exclusive(sk_sleep(sk), &wait); in sco_sock_accept()
645 if (sk->sk_state != BT_LISTEN) { in sco_sock_accept()
650 ch = bt_accept_dequeue(sk, newsock); in sco_sock_accept()
664 release_sock(sk); in sco_sock_accept()
667 lock_sock(sk); in sco_sock_accept()
669 remove_wait_queue(sk_sleep(sk), &wait); in sco_sock_accept()
679 release_sock(sk); in sco_sock_accept()
687 struct sock *sk = sock->sk; in sco_sock_getname() local
689 BT_DBG("sock %p, sk %p", sock, sk); in sco_sock_getname()
695 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->dst); in sco_sock_getname()
697 bacpy(&sa->sco_bdaddr, &sco_pi(sk)->src); in sco_sock_getname()
705 struct sock *sk = sock->sk; in sco_sock_sendmsg() local
708 BT_DBG("sock %p, sk %p", sock, sk); in sco_sock_sendmsg()
710 err = sock_error(sk); in sco_sock_sendmsg()
717 lock_sock(sk); in sco_sock_sendmsg()
719 if (sk->sk_state == BT_CONNECTED) in sco_sock_sendmsg()
720 err = sco_send_frame(sk, msg, len); in sco_sock_sendmsg()
724 release_sock(sk); in sco_sock_sendmsg()
775 struct sock *sk = sock->sk; in sco_sock_recvmsg() local
776 struct sco_pinfo *pi = sco_pi(sk); in sco_sock_recvmsg()
778 lock_sock(sk); in sco_sock_recvmsg()
780 if (sk->sk_state == BT_CONNECT2 && in sco_sock_recvmsg()
781 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { in sco_sock_recvmsg()
783 sk->sk_state = BT_CONFIG; in sco_sock_recvmsg()
785 release_sock(sk); in sco_sock_recvmsg()
789 release_sock(sk); in sco_sock_recvmsg()
797 struct sock *sk = sock->sk; in sco_sock_setsockopt() local
802 BT_DBG("sk %p", sk); in sco_sock_setsockopt()
804 lock_sock(sk); in sco_sock_setsockopt()
809 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { in sco_sock_setsockopt()
820 set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); in sco_sock_setsockopt()
822 clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags); in sco_sock_setsockopt()
826 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND && in sco_sock_setsockopt()
827 sk->sk_state != BT_CONNECT2) { in sco_sock_setsockopt()
832 voice.setting = sco_pi(sk)->setting; in sco_sock_setsockopt()
847 sco_pi(sk)->setting = voice.setting; in sco_sock_setsockopt()
855 release_sock(sk); in sco_sock_setsockopt()
862 struct sock *sk = sock->sk; in sco_sock_getsockopt_old() local
867 BT_DBG("sk %p", sk); in sco_sock_getsockopt_old()
872 lock_sock(sk); in sco_sock_getsockopt_old()
876 if (sk->sk_state != BT_CONNECTED && in sco_sock_getsockopt_old()
877 !(sk->sk_state == BT_CONNECT2 && in sco_sock_getsockopt_old()
878 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) { in sco_sock_getsockopt_old()
883 opts.mtu = sco_pi(sk)->conn->mtu; in sco_sock_getsockopt_old()
894 if (sk->sk_state != BT_CONNECTED && in sco_sock_getsockopt_old()
895 !(sk->sk_state == BT_CONNECT2 && in sco_sock_getsockopt_old()
896 test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags))) { in sco_sock_getsockopt_old()
902 cinfo.hci_handle = sco_pi(sk)->conn->hcon->handle; in sco_sock_getsockopt_old()
903 memcpy(cinfo.dev_class, sco_pi(sk)->conn->hcon->dev_class, 3); in sco_sock_getsockopt_old()
916 release_sock(sk); in sco_sock_getsockopt_old()
923 struct sock *sk = sock->sk; in sco_sock_getsockopt() local
927 BT_DBG("sk %p", sk); in sco_sock_getsockopt()
935 lock_sock(sk); in sco_sock_getsockopt()
940 if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) { in sco_sock_getsockopt()
945 if (put_user(test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags), in sco_sock_getsockopt()
952 voice.setting = sco_pi(sk)->setting; in sco_sock_getsockopt()
965 release_sock(sk); in sco_sock_getsockopt()
971 struct sock *sk = sock->sk; in sco_sock_shutdown() local
974 BT_DBG("sock %p, sk %p", sock, sk); in sco_sock_shutdown()
976 if (!sk) in sco_sock_shutdown()
979 sock_hold(sk); in sco_sock_shutdown()
980 lock_sock(sk); in sco_sock_shutdown()
982 if (!sk->sk_shutdown) { in sco_sock_shutdown()
983 sk->sk_shutdown = SHUTDOWN_MASK; in sco_sock_shutdown()
984 sco_sock_clear_timer(sk); in sco_sock_shutdown()
985 __sco_sock_close(sk); in sco_sock_shutdown()
987 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && in sco_sock_shutdown()
989 err = bt_sock_wait_state(sk, BT_CLOSED, in sco_sock_shutdown()
990 sk->sk_lingertime); in sco_sock_shutdown()
993 release_sock(sk); in sco_sock_shutdown()
994 sock_put(sk); in sco_sock_shutdown()
1001 struct sock *sk = sock->sk; in sco_sock_release() local
1004 BT_DBG("sock %p, sk %p", sock, sk); in sco_sock_release()
1006 if (!sk) in sco_sock_release()
1009 sco_sock_close(sk); in sco_sock_release()
1011 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && in sco_sock_release()
1013 lock_sock(sk); in sco_sock_release()
1014 err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime); in sco_sock_release()
1015 release_sock(sk); in sco_sock_release()
1018 sock_orphan(sk); in sco_sock_release()
1019 sco_sock_kill(sk); in sco_sock_release()
1026 struct sock *sk = conn->sk; in sco_conn_ready() local
1030 if (sk) { in sco_conn_ready()
1031 sco_sock_clear_timer(sk); in sco_conn_ready()
1032 bh_lock_sock(sk); in sco_conn_ready()
1033 sk->sk_state = BT_CONNECTED; in sco_conn_ready()
1034 sk->sk_state_change(sk); in sco_conn_ready()
1035 bh_unlock_sock(sk); in sco_conn_ready()
1052 sk = sco_sock_alloc(sock_net(parent), NULL, in sco_conn_ready()
1054 if (!sk) { in sco_conn_ready()
1060 sco_sock_init(sk, parent); in sco_conn_ready()
1062 bacpy(&sco_pi(sk)->src, &conn->hcon->src); in sco_conn_ready()
1063 bacpy(&sco_pi(sk)->dst, &conn->hcon->dst); in sco_conn_ready()
1066 __sco_chan_add(conn, sk, parent); in sco_conn_ready()
1069 sk->sk_state = BT_CONNECT2; in sco_conn_ready()
1071 sk->sk_state = BT_CONNECTED; in sco_conn_ready()
1085 struct sock *sk; in sco_connect_ind() local
1092 sk_for_each(sk, &sco_sk_list.head) { in sco_connect_ind()
1093 if (sk->sk_state != BT_LISTEN) in sco_connect_ind()
1096 if (!bacmp(&sco_pi(sk)->src, &hdev->bdaddr) || in sco_connect_ind()
1097 !bacmp(&sco_pi(sk)->src, BDADDR_ANY)) { in sco_connect_ind()
1100 if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) in sco_connect_ind()
1163 struct sock *sk; in sco_debugfs_show() local
1167 sk_for_each(sk, &sco_sk_list.head) { in sco_debugfs_show()
1168 seq_printf(f, "%pMR %pMR %d\n", &sco_pi(sk)->src, in sco_debugfs_show()
1169 &sco_pi(sk)->dst, sk->sk_state); in sco_debugfs_show()