Lines Matching refs:sk
23 static void nfc_sock_link(struct nfc_sock_list *l, struct sock *sk) in nfc_sock_link() argument
26 sk_add_node(sk, &l->head); in nfc_sock_link()
30 static void nfc_sock_unlink(struct nfc_sock_list *l, struct sock *sk) in nfc_sock_unlink() argument
33 sk_del_node_init(sk); in nfc_sock_unlink()
37 static void rawsock_write_queue_purge(struct sock *sk) in rawsock_write_queue_purge() argument
39 pr_debug("sk=%p\n", sk); in rawsock_write_queue_purge()
41 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_write_queue_purge()
42 __skb_queue_purge(&sk->sk_write_queue); in rawsock_write_queue_purge()
43 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_write_queue_purge()
44 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_write_queue_purge()
47 static void rawsock_report_error(struct sock *sk, int err) in rawsock_report_error() argument
49 pr_debug("sk=%p err=%d\n", sk, err); in rawsock_report_error()
51 sk->sk_shutdown = SHUTDOWN_MASK; in rawsock_report_error()
52 sk->sk_err = -err; in rawsock_report_error()
53 sk_error_report(sk); in rawsock_report_error()
55 rawsock_write_queue_purge(sk); in rawsock_report_error()
60 struct sock *sk = sock->sk; in rawsock_release() local
62 pr_debug("sock=%p sk=%p\n", sock, sk); in rawsock_release()
64 if (!sk) in rawsock_release()
68 nfc_sock_unlink(&raw_sk_list, sk); in rawsock_release()
70 sock_orphan(sk); in rawsock_release()
71 sock_put(sk); in rawsock_release()
79 struct sock *sk = sock->sk; in rawsock_connect() local
84 pr_debug("sock=%p sk=%p flags=%d\n", sock, sk, flags); in rawsock_connect()
93 lock_sock(sk); in rawsock_connect()
116 nfc_rawsock(sk)->dev = dev; in rawsock_connect()
117 nfc_rawsock(sk)->target_idx = addr->target_idx; in rawsock_connect()
119 sk->sk_state = TCP_ESTABLISHED; in rawsock_connect()
120 sk->sk_state_change(sk); in rawsock_connect()
122 release_sock(sk); in rawsock_connect()
128 release_sock(sk); in rawsock_connect()
142 struct sock *sk = (struct sock *) context; in rawsock_data_exchange_complete() local
146 pr_debug("sk=%p err=%d\n", sk, err); in rawsock_data_exchange_complete()
155 err = sock_queue_rcv_skb(sk, skb); in rawsock_data_exchange_complete()
159 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_data_exchange_complete()
160 if (!skb_queue_empty(&sk->sk_write_queue)) in rawsock_data_exchange_complete()
161 schedule_work(&nfc_rawsock(sk)->tx_work); in rawsock_data_exchange_complete()
163 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_data_exchange_complete()
164 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_data_exchange_complete()
166 sock_put(sk); in rawsock_data_exchange_complete()
173 rawsock_report_error(sk, err); in rawsock_data_exchange_complete()
174 sock_put(sk); in rawsock_data_exchange_complete()
179 struct sock *sk = to_rawsock_sk(work); in rawsock_tx_work() local
180 struct nfc_dev *dev = nfc_rawsock(sk)->dev; in rawsock_tx_work()
181 u32 target_idx = nfc_rawsock(sk)->target_idx; in rawsock_tx_work()
185 pr_debug("sk=%p target_idx=%u\n", sk, target_idx); in rawsock_tx_work()
187 if (sk->sk_shutdown & SEND_SHUTDOWN) { in rawsock_tx_work()
188 rawsock_write_queue_purge(sk); in rawsock_tx_work()
192 skb = skb_dequeue(&sk->sk_write_queue); in rawsock_tx_work()
195 sock_hold(sk); in rawsock_tx_work()
197 rawsock_data_exchange_complete, sk); in rawsock_tx_work()
199 rawsock_report_error(sk, rc); in rawsock_tx_work()
200 sock_put(sk); in rawsock_tx_work()
207 struct sock *sk = sock->sk; in rawsock_sendmsg() local
208 struct nfc_dev *dev = nfc_rawsock(sk)->dev; in rawsock_sendmsg()
212 pr_debug("sock=%p sk=%p len=%zu\n", sock, sk, len); in rawsock_sendmsg()
220 skb = nfc_alloc_send_skb(dev, sk, msg->msg_flags, len, &rc); in rawsock_sendmsg()
230 spin_lock_bh(&sk->sk_write_queue.lock); in rawsock_sendmsg()
231 __skb_queue_tail(&sk->sk_write_queue, skb); in rawsock_sendmsg()
232 if (!nfc_rawsock(sk)->tx_work_scheduled) { in rawsock_sendmsg()
233 schedule_work(&nfc_rawsock(sk)->tx_work); in rawsock_sendmsg()
234 nfc_rawsock(sk)->tx_work_scheduled = true; in rawsock_sendmsg()
236 spin_unlock_bh(&sk->sk_write_queue.lock); in rawsock_sendmsg()
244 struct sock *sk = sock->sk; in rawsock_recvmsg() local
249 pr_debug("sock=%p sk=%p len=%zu flags=%d\n", sock, sk, len, flags); in rawsock_recvmsg()
251 skb = skb_recv_datagram(sk, flags, &rc); in rawsock_recvmsg()
263 skb_free_datagram(sk, skb); in rawsock_recvmsg()
304 static void rawsock_destruct(struct sock *sk) in rawsock_destruct() argument
306 pr_debug("sk=%p\n", sk); in rawsock_destruct()
308 if (sk->sk_state == TCP_ESTABLISHED) { in rawsock_destruct()
309 nfc_deactivate_target(nfc_rawsock(sk)->dev, in rawsock_destruct()
310 nfc_rawsock(sk)->target_idx, in rawsock_destruct()
312 nfc_put_device(nfc_rawsock(sk)->dev); in rawsock_destruct()
315 skb_queue_purge(&sk->sk_receive_queue); in rawsock_destruct()
317 if (!sock_flag(sk, SOCK_DEAD)) { in rawsock_destruct()
318 pr_err("Freeing alive NFC raw socket %p\n", sk); in rawsock_destruct()
326 struct sock *sk; in rawsock_create() local
341 sk = sk_alloc(net, PF_NFC, GFP_ATOMIC, nfc_proto->proto, kern); in rawsock_create()
342 if (!sk) in rawsock_create()
345 sock_init_data(sock, sk); in rawsock_create()
346 sk->sk_protocol = nfc_proto->id; in rawsock_create()
347 sk->sk_destruct = rawsock_destruct; in rawsock_create()
350 nfc_sock_link(&raw_sk_list, sk); in rawsock_create()
352 INIT_WORK(&nfc_rawsock(sk)->tx_work, rawsock_tx_work); in rawsock_create()
353 nfc_rawsock(sk)->tx_work_scheduled = false; in rawsock_create()
363 struct sock *sk; in nfc_send_to_raw_sock() local
368 sk_for_each(sk, &raw_sk_list.head) { in nfc_send_to_raw_sock()
386 if (sock_queue_rcv_skb(sk, nskb)) in nfc_send_to_raw_sock()