Lines Matching refs:sk

22 static void nfc_sock_link(struct nfc_sock_list *l, struct sock *sk)  in nfc_sock_link()  argument
25 sk_add_node(sk, &l->head); in nfc_sock_link()
29 static void nfc_sock_unlink(struct nfc_sock_list *l, struct sock *sk) in nfc_sock_unlink() argument
32 sk_del_node_init(sk); in nfc_sock_unlink()
36 static void rawsock_write_queue_purge(struct sock *sk) in rawsock_write_queue_purge() argument
38 pr_debug("sk=%p\n", sk); in rawsock_write_queue_purge()
40 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_write_queue_purge()
41 __skb_queue_purge(&sk->sk_write_queue); in rawsock_write_queue_purge()
42 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_write_queue_purge()
43 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_write_queue_purge()
46 static void rawsock_report_error(struct sock *sk, int err) in rawsock_report_error() argument
48 pr_debug("sk=%p err=%d\n", sk, err); in rawsock_report_error()
50 sk->sk_shutdown = SHUTDOWN_MASK; in rawsock_report_error()
51 sk->sk_err = -err; in rawsock_report_error()
52 sk_error_report(sk); in rawsock_report_error()
54 rawsock_write_queue_purge(sk); in rawsock_report_error()
59 struct sock *sk = sock->sk; in rawsock_release() local
61 pr_debug("sock=%p sk=%p\n", sock, sk); in rawsock_release()
63 if (!sk) in rawsock_release()
67 nfc_sock_unlink(&raw_sk_list, sk); in rawsock_release()
69 sock_orphan(sk); in rawsock_release()
70 sock_put(sk); in rawsock_release()
78 struct sock *sk = sock->sk; in rawsock_connect() local
83 pr_debug("sock=%p sk=%p flags=%d\n", sock, sk, flags); in rawsock_connect()
92 lock_sock(sk); in rawsock_connect()
115 nfc_rawsock(sk)->dev = dev; in rawsock_connect()
116 nfc_rawsock(sk)->target_idx = addr->target_idx; in rawsock_connect()
118 sk->sk_state = TCP_ESTABLISHED; in rawsock_connect()
119 sk->sk_state_change(sk); in rawsock_connect()
121 release_sock(sk); in rawsock_connect()
127 release_sock(sk); in rawsock_connect()
141 struct sock *sk = (struct sock *) context; in rawsock_data_exchange_complete() local
145 pr_debug("sk=%p err=%d\n", sk, err); in rawsock_data_exchange_complete()
154 err = sock_queue_rcv_skb(sk, skb); in rawsock_data_exchange_complete()
158 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_data_exchange_complete()
159 if (!skb_queue_empty(&sk->sk_write_queue)) in rawsock_data_exchange_complete()
160 schedule_work(&nfc_rawsock(sk)->tx_work); in rawsock_data_exchange_complete()
162 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_data_exchange_complete()
163 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_data_exchange_complete()
165 sock_put(sk); in rawsock_data_exchange_complete()
172 rawsock_report_error(sk, err); in rawsock_data_exchange_complete()
173 sock_put(sk); in rawsock_data_exchange_complete()
178 struct sock *sk = to_rawsock_sk(work); in rawsock_tx_work() local
179 struct nfc_dev *dev = nfc_rawsock(sk)->dev; in rawsock_tx_work()
180 u32 target_idx = nfc_rawsock(sk)->target_idx; in rawsock_tx_work()
184 pr_debug("sk=%p target_idx=%u\n", sk, target_idx); in rawsock_tx_work()
186 if (sk->sk_shutdown & SEND_SHUTDOWN) { in rawsock_tx_work()
187 rawsock_write_queue_purge(sk); in rawsock_tx_work()
191 skb = skb_dequeue(&sk->sk_write_queue); in rawsock_tx_work()
193 sock_hold(sk); in rawsock_tx_work()
195 rawsock_data_exchange_complete, sk); in rawsock_tx_work()
197 rawsock_report_error(sk, rc); in rawsock_tx_work()
198 sock_put(sk); in rawsock_tx_work()
204 struct sock *sk = sock->sk; in rawsock_sendmsg() local
205 struct nfc_dev *dev = nfc_rawsock(sk)->dev; in rawsock_sendmsg()
209 pr_debug("sock=%p sk=%p len=%zu\n", sock, sk, len); in rawsock_sendmsg()
217 skb = nfc_alloc_send_skb(dev, sk, msg->msg_flags, len, &rc); in rawsock_sendmsg()
227 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_sendmsg()
228 __skb_queue_tail(&sk->sk_write_queue, skb); in rawsock_sendmsg()
229 if (!nfc_rawsock(sk)->tx_work_scheduled) { in rawsock_sendmsg()
230 schedule_work(&nfc_rawsock(sk)->tx_work); in rawsock_sendmsg()
231 nfc_rawsock(sk)->tx_work_scheduled = true; in rawsock_sendmsg()
233 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_sendmsg()
241 struct sock *sk = sock->sk; in rawsock_recvmsg() local
246 pr_debug("sock=%p sk=%p len=%zu flags=%d\n", sock, sk, len, flags); in rawsock_recvmsg()
248 skb = skb_recv_datagram(sk, flags, &rc); in rawsock_recvmsg()
260 skb_free_datagram(sk, skb); in rawsock_recvmsg()
301 static void rawsock_destruct(struct sock *sk) in rawsock_destruct() argument
303 pr_debug("sk=%p\n", sk); in rawsock_destruct()
305 if (sk->sk_state == TCP_ESTABLISHED) { in rawsock_destruct()
306 nfc_deactivate_target(nfc_rawsock(sk)->dev, in rawsock_destruct()
307 nfc_rawsock(sk)->target_idx, in rawsock_destruct()
309 nfc_put_device(nfc_rawsock(sk)->dev); in rawsock_destruct()
312 skb_queue_purge(&sk->sk_receive_queue); in rawsock_destruct()
314 if (!sock_flag(sk, SOCK_DEAD)) { in rawsock_destruct()
315 pr_err("Freeing alive NFC raw socket %p\n", sk); in rawsock_destruct()
323 struct sock *sk; in rawsock_create() local
338 sk = sk_alloc(net, PF_NFC, GFP_ATOMIC, nfc_proto->proto, kern); in rawsock_create()
339 if (!sk) in rawsock_create()
342 sock_init_data(sock, sk); in rawsock_create()
343 sk->sk_protocol = nfc_proto->id; in rawsock_create()
344 sk->sk_destruct = rawsock_destruct; in rawsock_create()
347 nfc_sock_link(&raw_sk_list, sk); in rawsock_create()
349 INIT_WORK(&nfc_rawsock(sk)->tx_work, rawsock_tx_work); in rawsock_create()
350 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_create()
360 struct sock *sk; in nfc_send_to_raw_sock() local
365 sk_for_each(sk, &raw_sk_list.head) { in nfc_send_to_raw_sock()
383 if (sock_queue_rcv_skb(sk, nskb)) in nfc_send_to_raw_sock()