Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 * This program is free software; you can redistribute it and/or modify
  3 * it under the terms of the GNU General Public License as published by
  4 * the Free Software Foundation; either version 2 of the License, or
  5 * (at your option) any later version.
  6 *
  7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  8 * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
  9 */
 10#include <linux/errno.h>
 11#include <linux/types.h>
 12#include <linux/socket.h>
 13#include <linux/in.h>
 14#include <linux/kernel.h>
 15#include <linux/jiffies.h>
 16#include <linux/timer.h>
 17#include <linux/string.h>
 18#include <linux/sockios.h>
 19#include <linux/net.h>
 20#include <net/ax25.h>
 21#include <linux/inet.h>
 22#include <linux/netdevice.h>
 23#include <linux/skbuff.h>
 24#include <net/sock.h>
 25#include <net/tcp_states.h>
 26#include <linux/fcntl.h>
 27#include <linux/mm.h>
 28#include <linux/interrupt.h>
 29#include <net/rose.h>
 30
 31static void rose_heartbeat_expiry(unsigned long);
 32static void rose_timer_expiry(unsigned long);
 33static void rose_idletimer_expiry(unsigned long);
 34
 35void rose_start_heartbeat(struct sock *sk)
 36{
 37	del_timer(&sk->sk_timer);
 38
 39	sk->sk_timer.data     = (unsigned long)sk;
 40	sk->sk_timer.function = &rose_heartbeat_expiry;
 41	sk->sk_timer.expires  = jiffies + 5 * HZ;
 42
 43	add_timer(&sk->sk_timer);
 44}
 45
 46void rose_start_t1timer(struct sock *sk)
 47{
 48	struct rose_sock *rose = rose_sk(sk);
 49
 50	del_timer(&rose->timer);
 51
 52	rose->timer.data     = (unsigned long)sk;
 53	rose->timer.function = &rose_timer_expiry;
 54	rose->timer.expires  = jiffies + rose->t1;
 55
 56	add_timer(&rose->timer);
 57}
 58
 59void rose_start_t2timer(struct sock *sk)
 60{
 61	struct rose_sock *rose = rose_sk(sk);
 62
 63	del_timer(&rose->timer);
 64
 65	rose->timer.data     = (unsigned long)sk;
 66	rose->timer.function = &rose_timer_expiry;
 67	rose->timer.expires  = jiffies + rose->t2;
 68
 69	add_timer(&rose->timer);
 70}
 71
 72void rose_start_t3timer(struct sock *sk)
 73{
 74	struct rose_sock *rose = rose_sk(sk);
 75
 76	del_timer(&rose->timer);
 77
 78	rose->timer.data     = (unsigned long)sk;
 79	rose->timer.function = &rose_timer_expiry;
 80	rose->timer.expires  = jiffies + rose->t3;
 81
 82	add_timer(&rose->timer);
 83}
 84
 85void rose_start_hbtimer(struct sock *sk)
 86{
 87	struct rose_sock *rose = rose_sk(sk);
 88
 89	del_timer(&rose->timer);
 90
 91	rose->timer.data     = (unsigned long)sk;
 92	rose->timer.function = &rose_timer_expiry;
 93	rose->timer.expires  = jiffies + rose->hb;
 94
 95	add_timer(&rose->timer);
 96}
 97
 98void rose_start_idletimer(struct sock *sk)
 99{
100	struct rose_sock *rose = rose_sk(sk);
101
102	del_timer(&rose->idletimer);
103
104	if (rose->idle > 0) {
105		rose->idletimer.data     = (unsigned long)sk;
106		rose->idletimer.function = &rose_idletimer_expiry;
107		rose->idletimer.expires  = jiffies + rose->idle;
108
109		add_timer(&rose->idletimer);
110	}
111}
112
113void rose_stop_heartbeat(struct sock *sk)
114{
115	del_timer(&sk->sk_timer);
116}
117
118void rose_stop_timer(struct sock *sk)
119{
120	del_timer(&rose_sk(sk)->timer);
121}
122
123void rose_stop_idletimer(struct sock *sk)
124{
125	del_timer(&rose_sk(sk)->idletimer);
126}
127
128static void rose_heartbeat_expiry(unsigned long param)
129{
130	struct sock *sk = (struct sock *)param;
131	struct rose_sock *rose = rose_sk(sk);
132
133	bh_lock_sock(sk);
 
 
 
 
134	switch (rose->state) {
135	case ROSE_STATE_0:
136		/* Magic here: If we listen() and a new link dies before it
137		   is accepted() it isn't 'dead' so doesn't get removed. */
138		if (sock_flag(sk, SOCK_DESTROY) ||
139		    (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) {
140			bh_unlock_sock(sk);
141			rose_destroy_socket(sk);
 
142			return;
143		}
144		break;
145
146	case ROSE_STATE_3:
147		/*
148		 * Check for the state of the receive buffer.
149		 */
150		if (atomic_read(&sk->sk_rmem_alloc) < (sk->sk_rcvbuf / 2) &&
151		    (rose->condition & ROSE_COND_OWN_RX_BUSY)) {
152			rose->condition &= ~ROSE_COND_OWN_RX_BUSY;
153			rose->condition &= ~ROSE_COND_ACK_PENDING;
154			rose->vl         = rose->vr;
155			rose_write_internal(sk, ROSE_RR);
156			rose_stop_timer(sk);	/* HB */
157			break;
158		}
159		break;
160	}
161
162	rose_start_heartbeat(sk);
 
163	bh_unlock_sock(sk);
 
164}
165
166static void rose_timer_expiry(unsigned long param)
167{
168	struct sock *sk = (struct sock *)param;
169	struct rose_sock *rose = rose_sk(sk);
170
171	bh_lock_sock(sk);
 
 
 
 
172	switch (rose->state) {
173	case ROSE_STATE_1:	/* T1 */
174	case ROSE_STATE_4:	/* T2 */
175		rose_write_internal(sk, ROSE_CLEAR_REQUEST);
176		rose->state = ROSE_STATE_2;
177		rose_start_t3timer(sk);
178		break;
179
180	case ROSE_STATE_2:	/* T3 */
181		rose->neighbour->use--;
182		rose_disconnect(sk, ETIMEDOUT, -1, -1);
183		break;
184
185	case ROSE_STATE_3:	/* HB */
186		if (rose->condition & ROSE_COND_ACK_PENDING) {
187			rose->condition &= ~ROSE_COND_ACK_PENDING;
188			rose_enquiry_response(sk);
189		}
190		break;
191	}
 
192	bh_unlock_sock(sk);
 
193}
194
195static void rose_idletimer_expiry(unsigned long param)
196{
197	struct sock *sk = (struct sock *)param;
 
198
199	bh_lock_sock(sk);
 
 
 
 
200	rose_clear_queues(sk);
201
202	rose_write_internal(sk, ROSE_CLEAR_REQUEST);
203	rose_sk(sk)->state = ROSE_STATE_2;
204
205	rose_start_t3timer(sk);
206
207	sk->sk_state     = TCP_CLOSE;
208	sk->sk_err       = 0;
209	sk->sk_shutdown |= SEND_SHUTDOWN;
210
211	if (!sock_flag(sk, SOCK_DEAD)) {
212		sk->sk_state_change(sk);
213		sock_set_flag(sk, SOCK_DEAD);
214	}
 
215	bh_unlock_sock(sk);
 
216}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
 
 
 
 
  3 *
  4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  5 * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
  6 */
  7#include <linux/errno.h>
  8#include <linux/types.h>
  9#include <linux/socket.h>
 10#include <linux/in.h>
 11#include <linux/kernel.h>
 12#include <linux/jiffies.h>
 13#include <linux/timer.h>
 14#include <linux/string.h>
 15#include <linux/sockios.h>
 16#include <linux/net.h>
 17#include <net/ax25.h>
 18#include <linux/inet.h>
 19#include <linux/netdevice.h>
 20#include <linux/skbuff.h>
 21#include <net/sock.h>
 22#include <net/tcp_states.h>
 23#include <linux/fcntl.h>
 24#include <linux/mm.h>
 25#include <linux/interrupt.h>
 26#include <net/rose.h>
 27
 28static void rose_heartbeat_expiry(struct timer_list *t);
 29static void rose_timer_expiry(struct timer_list *);
 30static void rose_idletimer_expiry(struct timer_list *);
 31
 32void rose_start_heartbeat(struct sock *sk)
 33{
 34	sk_stop_timer(sk, &sk->sk_timer);
 35
 36	sk->sk_timer.function = rose_heartbeat_expiry;
 
 37	sk->sk_timer.expires  = jiffies + 5 * HZ;
 38
 39	sk_reset_timer(sk, &sk->sk_timer, sk->sk_timer.expires);
 40}
 41
 42void rose_start_t1timer(struct sock *sk)
 43{
 44	struct rose_sock *rose = rose_sk(sk);
 45
 46	sk_stop_timer(sk, &rose->timer);
 47
 48	rose->timer.function = rose_timer_expiry;
 
 49	rose->timer.expires  = jiffies + rose->t1;
 50
 51	sk_reset_timer(sk, &rose->timer, rose->timer.expires);
 52}
 53
 54void rose_start_t2timer(struct sock *sk)
 55{
 56	struct rose_sock *rose = rose_sk(sk);
 57
 58	sk_stop_timer(sk, &rose->timer);
 59
 60	rose->timer.function = rose_timer_expiry;
 
 61	rose->timer.expires  = jiffies + rose->t2;
 62
 63	sk_reset_timer(sk, &rose->timer, rose->timer.expires);
 64}
 65
 66void rose_start_t3timer(struct sock *sk)
 67{
 68	struct rose_sock *rose = rose_sk(sk);
 69
 70	sk_stop_timer(sk, &rose->timer);
 71
 72	rose->timer.function = rose_timer_expiry;
 
 73	rose->timer.expires  = jiffies + rose->t3;
 74
 75	sk_reset_timer(sk, &rose->timer, rose->timer.expires);
 76}
 77
 78void rose_start_hbtimer(struct sock *sk)
 79{
 80	struct rose_sock *rose = rose_sk(sk);
 81
 82	sk_stop_timer(sk, &rose->timer);
 83
 84	rose->timer.function = rose_timer_expiry;
 
 85	rose->timer.expires  = jiffies + rose->hb;
 86
 87	sk_reset_timer(sk, &rose->timer, rose->timer.expires);
 88}
 89
 90void rose_start_idletimer(struct sock *sk)
 91{
 92	struct rose_sock *rose = rose_sk(sk);
 93
 94	sk_stop_timer(sk, &rose->idletimer);
 95
 96	if (rose->idle > 0) {
 97		rose->idletimer.function = rose_idletimer_expiry;
 
 98		rose->idletimer.expires  = jiffies + rose->idle;
 99
100		sk_reset_timer(sk, &rose->idletimer, rose->idletimer.expires);
101	}
102}
103
104void rose_stop_heartbeat(struct sock *sk)
105{
106	sk_stop_timer(sk, &sk->sk_timer);
107}
108
109void rose_stop_timer(struct sock *sk)
110{
111	sk_stop_timer(sk, &rose_sk(sk)->timer);
112}
113
114void rose_stop_idletimer(struct sock *sk)
115{
116	sk_stop_timer(sk, &rose_sk(sk)->idletimer);
117}
118
119static void rose_heartbeat_expiry(struct timer_list *t)
120{
121	struct sock *sk = from_timer(sk, t, sk_timer);
122	struct rose_sock *rose = rose_sk(sk);
123
124	bh_lock_sock(sk);
125	if (sock_owned_by_user(sk)) {
126		sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ/20);
127		goto out;
128	}
129	switch (rose->state) {
130	case ROSE_STATE_0:
131		/* Magic here: If we listen() and a new link dies before it
132		   is accepted() it isn't 'dead' so doesn't get removed. */
133		if (sock_flag(sk, SOCK_DESTROY) ||
134		    (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) {
135			bh_unlock_sock(sk);
136			rose_destroy_socket(sk);
137			sock_put(sk);
138			return;
139		}
140		break;
141
142	case ROSE_STATE_3:
143		/*
144		 * Check for the state of the receive buffer.
145		 */
146		if (atomic_read(&sk->sk_rmem_alloc) < (sk->sk_rcvbuf / 2) &&
147		    (rose->condition & ROSE_COND_OWN_RX_BUSY)) {
148			rose->condition &= ~ROSE_COND_OWN_RX_BUSY;
149			rose->condition &= ~ROSE_COND_ACK_PENDING;
150			rose->vl         = rose->vr;
151			rose_write_internal(sk, ROSE_RR);
152			rose_stop_timer(sk);	/* HB */
153			break;
154		}
155		break;
156	}
157
158	rose_start_heartbeat(sk);
159out:
160	bh_unlock_sock(sk);
161	sock_put(sk);
162}
163
164static void rose_timer_expiry(struct timer_list *t)
165{
166	struct rose_sock *rose = from_timer(rose, t, timer);
167	struct sock *sk = &rose->sock;
168
169	bh_lock_sock(sk);
170	if (sock_owned_by_user(sk)) {
171		sk_reset_timer(sk, &rose->timer, jiffies + HZ/20);
172		goto out;
173	}
174	switch (rose->state) {
175	case ROSE_STATE_1:	/* T1 */
176	case ROSE_STATE_4:	/* T2 */
177		rose_write_internal(sk, ROSE_CLEAR_REQUEST);
178		rose->state = ROSE_STATE_2;
179		rose_start_t3timer(sk);
180		break;
181
182	case ROSE_STATE_2:	/* T3 */
183		rose->neighbour->use--;
184		rose_disconnect(sk, ETIMEDOUT, -1, -1);
185		break;
186
187	case ROSE_STATE_3:	/* HB */
188		if (rose->condition & ROSE_COND_ACK_PENDING) {
189			rose->condition &= ~ROSE_COND_ACK_PENDING;
190			rose_enquiry_response(sk);
191		}
192		break;
193	}
194out:
195	bh_unlock_sock(sk);
196	sock_put(sk);
197}
198
199static void rose_idletimer_expiry(struct timer_list *t)
200{
201	struct rose_sock *rose = from_timer(rose, t, idletimer);
202	struct sock *sk = &rose->sock;
203
204	bh_lock_sock(sk);
205	if (sock_owned_by_user(sk)) {
206		sk_reset_timer(sk, &rose->idletimer, jiffies + HZ/20);
207		goto out;
208	}
209	rose_clear_queues(sk);
210
211	rose_write_internal(sk, ROSE_CLEAR_REQUEST);
212	rose_sk(sk)->state = ROSE_STATE_2;
213
214	rose_start_t3timer(sk);
215
216	sk->sk_state     = TCP_CLOSE;
217	sk->sk_err       = 0;
218	sk->sk_shutdown |= SEND_SHUTDOWN;
219
220	if (!sock_flag(sk, SOCK_DEAD)) {
221		sk->sk_state_change(sk);
222		sock_set_flag(sk, SOCK_DEAD);
223	}
224out:
225	bh_unlock_sock(sk);
226	sock_put(sk);
227}