Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
 
 
 
 
  3 *
  4 * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
  5 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  6 * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
  7 * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
  8 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
  9 * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
 10 * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
 11 */
 12#include <linux/errno.h>
 13#include <linux/types.h>
 14#include <linux/socket.h>
 15#include <linux/in.h>
 16#include <linux/kernel.h>
 17#include <linux/module.h>
 18#include <linux/jiffies.h>
 19#include <linux/timer.h>
 20#include <linux/string.h>
 21#include <linux/sockios.h>
 22#include <linux/net.h>
 23#include <net/ax25.h>
 24#include <linux/inet.h>
 25#include <linux/netdevice.h>
 26#include <linux/skbuff.h>
 27#include <net/sock.h>
 28#include <linux/uaccess.h>
 29#include <linux/fcntl.h>
 30#include <linux/mm.h>
 31#include <linux/interrupt.h>
 32
 33static void ax25_heartbeat_expiry(struct timer_list *);
 34static void ax25_t1timer_expiry(struct timer_list *);
 35static void ax25_t2timer_expiry(struct timer_list *);
 36static void ax25_t3timer_expiry(struct timer_list *);
 37static void ax25_idletimer_expiry(struct timer_list *);
 38
 39void ax25_setup_timers(ax25_cb *ax25)
 40{
 41	timer_setup(&ax25->timer, ax25_heartbeat_expiry, 0);
 42	timer_setup(&ax25->t1timer, ax25_t1timer_expiry, 0);
 43	timer_setup(&ax25->t2timer, ax25_t2timer_expiry, 0);
 44	timer_setup(&ax25->t3timer, ax25_t3timer_expiry, 0);
 45	timer_setup(&ax25->idletimer, ax25_idletimer_expiry, 0);
 
 46}
 47
 48void ax25_start_heartbeat(ax25_cb *ax25)
 49{
 50	mod_timer(&ax25->timer, jiffies + 5 * HZ);
 51}
 52
 53void ax25_start_t1timer(ax25_cb *ax25)
 54{
 55	mod_timer(&ax25->t1timer, jiffies + ax25->t1);
 56}
 57
 58void ax25_start_t2timer(ax25_cb *ax25)
 59{
 60	mod_timer(&ax25->t2timer, jiffies + ax25->t2);
 61}
 62
 63void ax25_start_t3timer(ax25_cb *ax25)
 64{
 65	if (ax25->t3 > 0)
 66		mod_timer(&ax25->t3timer, jiffies + ax25->t3);
 67	else
 68		del_timer(&ax25->t3timer);
 69}
 70
 71void ax25_start_idletimer(ax25_cb *ax25)
 72{
 73	if (ax25->idle > 0)
 74		mod_timer(&ax25->idletimer, jiffies + ax25->idle);
 75	else
 76		del_timer(&ax25->idletimer);
 77}
 78
 79void ax25_stop_heartbeat(ax25_cb *ax25)
 80{
 81	del_timer(&ax25->timer);
 82}
 83
 84void ax25_stop_t1timer(ax25_cb *ax25)
 85{
 86	del_timer(&ax25->t1timer);
 87}
 88
 89void ax25_stop_t2timer(ax25_cb *ax25)
 90{
 91	del_timer(&ax25->t2timer);
 92}
 93
 94void ax25_stop_t3timer(ax25_cb *ax25)
 95{
 96	del_timer(&ax25->t3timer);
 97}
 98
 99void ax25_stop_idletimer(ax25_cb *ax25)
100{
101	del_timer(&ax25->idletimer);
102}
103
104int ax25_t1timer_running(ax25_cb *ax25)
105{
106	return timer_pending(&ax25->t1timer);
107}
108
109unsigned long ax25_display_timer(struct timer_list *timer)
110{
111	long delta = timer->expires - jiffies;
112
113	if (!timer_pending(timer))
114		return 0;
115
116	return max(0L, delta);
117}
118
119EXPORT_SYMBOL(ax25_display_timer);
120
121static void ax25_heartbeat_expiry(struct timer_list *t)
122{
123	int proto = AX25_PROTO_STD_SIMPLEX;
124	ax25_cb *ax25 = from_timer(ax25, t, timer);
125
126	if (ax25->ax25_dev)
127		proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
128
129	switch (proto) {
130	case AX25_PROTO_STD_SIMPLEX:
131	case AX25_PROTO_STD_DUPLEX:
132		ax25_std_heartbeat_expiry(ax25);
133		break;
134
135#ifdef CONFIG_AX25_DAMA_SLAVE
136	case AX25_PROTO_DAMA_SLAVE:
137		if (ax25->ax25_dev->dama.slave)
138			ax25_ds_heartbeat_expiry(ax25);
139		else
140			ax25_std_heartbeat_expiry(ax25);
141		break;
142#endif
143	}
144}
145
146static void ax25_t1timer_expiry(struct timer_list *t)
147{
148	ax25_cb *ax25 = from_timer(ax25, t, t1timer);
149
150	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
151	case AX25_PROTO_STD_SIMPLEX:
152	case AX25_PROTO_STD_DUPLEX:
153		ax25_std_t1timer_expiry(ax25);
154		break;
155
156#ifdef CONFIG_AX25_DAMA_SLAVE
157	case AX25_PROTO_DAMA_SLAVE:
158		if (!ax25->ax25_dev->dama.slave)
159			ax25_std_t1timer_expiry(ax25);
160		break;
161#endif
162	}
163}
164
165static void ax25_t2timer_expiry(struct timer_list *t)
166{
167	ax25_cb *ax25 = from_timer(ax25, t, t2timer);
168
169	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
170	case AX25_PROTO_STD_SIMPLEX:
171	case AX25_PROTO_STD_DUPLEX:
172		ax25_std_t2timer_expiry(ax25);
173		break;
174
175#ifdef CONFIG_AX25_DAMA_SLAVE
176	case AX25_PROTO_DAMA_SLAVE:
177		if (!ax25->ax25_dev->dama.slave)
178			ax25_std_t2timer_expiry(ax25);
179		break;
180#endif
181	}
182}
183
184static void ax25_t3timer_expiry(struct timer_list *t)
185{
186	ax25_cb *ax25 = from_timer(ax25, t, t3timer);
187
188	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
189	case AX25_PROTO_STD_SIMPLEX:
190	case AX25_PROTO_STD_DUPLEX:
191		ax25_std_t3timer_expiry(ax25);
192		break;
193
194#ifdef CONFIG_AX25_DAMA_SLAVE
195	case AX25_PROTO_DAMA_SLAVE:
196		if (ax25->ax25_dev->dama.slave)
197			ax25_ds_t3timer_expiry(ax25);
198		else
199			ax25_std_t3timer_expiry(ax25);
200		break;
201#endif
202	}
203}
204
205static void ax25_idletimer_expiry(struct timer_list *t)
206{
207	ax25_cb *ax25 = from_timer(ax25, t, idletimer);
208
209	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
210	case AX25_PROTO_STD_SIMPLEX:
211	case AX25_PROTO_STD_DUPLEX:
212		ax25_std_idletimer_expiry(ax25);
213		break;
214
215#ifdef CONFIG_AX25_DAMA_SLAVE
216	case AX25_PROTO_DAMA_SLAVE:
217		if (ax25->ax25_dev->dama.slave)
218			ax25_ds_idletimer_expiry(ax25);
219		else
220			ax25_std_idletimer_expiry(ax25);
221		break;
222#endif
223	}
224}
v3.15
 
  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) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
  8 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
  9 * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi)
 10 * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
 11 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
 12 * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
 13 * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org)
 14 */
 15#include <linux/errno.h>
 16#include <linux/types.h>
 17#include <linux/socket.h>
 18#include <linux/in.h>
 19#include <linux/kernel.h>
 20#include <linux/module.h>
 21#include <linux/jiffies.h>
 22#include <linux/timer.h>
 23#include <linux/string.h>
 24#include <linux/sockios.h>
 25#include <linux/net.h>
 26#include <net/ax25.h>
 27#include <linux/inet.h>
 28#include <linux/netdevice.h>
 29#include <linux/skbuff.h>
 30#include <net/sock.h>
 31#include <asm/uaccess.h>
 32#include <linux/fcntl.h>
 33#include <linux/mm.h>
 34#include <linux/interrupt.h>
 35
 36static void ax25_heartbeat_expiry(unsigned long);
 37static void ax25_t1timer_expiry(unsigned long);
 38static void ax25_t2timer_expiry(unsigned long);
 39static void ax25_t3timer_expiry(unsigned long);
 40static void ax25_idletimer_expiry(unsigned long);
 41
 42void ax25_setup_timers(ax25_cb *ax25)
 43{
 44	setup_timer(&ax25->timer, ax25_heartbeat_expiry, (unsigned long)ax25);
 45	setup_timer(&ax25->t1timer, ax25_t1timer_expiry, (unsigned long)ax25);
 46	setup_timer(&ax25->t2timer, ax25_t2timer_expiry, (unsigned long)ax25);
 47	setup_timer(&ax25->t3timer, ax25_t3timer_expiry, (unsigned long)ax25);
 48	setup_timer(&ax25->idletimer, ax25_idletimer_expiry,
 49		    (unsigned long)ax25);
 50}
 51
 52void ax25_start_heartbeat(ax25_cb *ax25)
 53{
 54	mod_timer(&ax25->timer, jiffies + 5 * HZ);
 55}
 56
 57void ax25_start_t1timer(ax25_cb *ax25)
 58{
 59	mod_timer(&ax25->t1timer, jiffies + ax25->t1);
 60}
 61
 62void ax25_start_t2timer(ax25_cb *ax25)
 63{
 64	mod_timer(&ax25->t2timer, jiffies + ax25->t2);
 65}
 66
 67void ax25_start_t3timer(ax25_cb *ax25)
 68{
 69	if (ax25->t3 > 0)
 70		mod_timer(&ax25->t3timer, jiffies + ax25->t3);
 71	else
 72		del_timer(&ax25->t3timer);
 73}
 74
 75void ax25_start_idletimer(ax25_cb *ax25)
 76{
 77	if (ax25->idle > 0)
 78		mod_timer(&ax25->idletimer, jiffies + ax25->idle);
 79	else
 80		del_timer(&ax25->idletimer);
 81}
 82
 83void ax25_stop_heartbeat(ax25_cb *ax25)
 84{
 85	del_timer(&ax25->timer);
 86}
 87
 88void ax25_stop_t1timer(ax25_cb *ax25)
 89{
 90	del_timer(&ax25->t1timer);
 91}
 92
 93void ax25_stop_t2timer(ax25_cb *ax25)
 94{
 95	del_timer(&ax25->t2timer);
 96}
 97
 98void ax25_stop_t3timer(ax25_cb *ax25)
 99{
100	del_timer(&ax25->t3timer);
101}
102
103void ax25_stop_idletimer(ax25_cb *ax25)
104{
105	del_timer(&ax25->idletimer);
106}
107
108int ax25_t1timer_running(ax25_cb *ax25)
109{
110	return timer_pending(&ax25->t1timer);
111}
112
113unsigned long ax25_display_timer(struct timer_list *timer)
114{
 
 
115	if (!timer_pending(timer))
116		return 0;
117
118	return timer->expires - jiffies;
119}
120
121EXPORT_SYMBOL(ax25_display_timer);
122
123static void ax25_heartbeat_expiry(unsigned long param)
124{
125	int proto = AX25_PROTO_STD_SIMPLEX;
126	ax25_cb *ax25 = (ax25_cb *)param;
127
128	if (ax25->ax25_dev)
129		proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
130
131	switch (proto) {
132	case AX25_PROTO_STD_SIMPLEX:
133	case AX25_PROTO_STD_DUPLEX:
134		ax25_std_heartbeat_expiry(ax25);
135		break;
136
137#ifdef CONFIG_AX25_DAMA_SLAVE
138	case AX25_PROTO_DAMA_SLAVE:
139		if (ax25->ax25_dev->dama.slave)
140			ax25_ds_heartbeat_expiry(ax25);
141		else
142			ax25_std_heartbeat_expiry(ax25);
143		break;
144#endif
145	}
146}
147
148static void ax25_t1timer_expiry(unsigned long param)
149{
150	ax25_cb *ax25 = (ax25_cb *)param;
151
152	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
153	case AX25_PROTO_STD_SIMPLEX:
154	case AX25_PROTO_STD_DUPLEX:
155		ax25_std_t1timer_expiry(ax25);
156		break;
157
158#ifdef CONFIG_AX25_DAMA_SLAVE
159	case AX25_PROTO_DAMA_SLAVE:
160		if (!ax25->ax25_dev->dama.slave)
161			ax25_std_t1timer_expiry(ax25);
162		break;
163#endif
164	}
165}
166
167static void ax25_t2timer_expiry(unsigned long param)
168{
169	ax25_cb *ax25 = (ax25_cb *)param;
170
171	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
172	case AX25_PROTO_STD_SIMPLEX:
173	case AX25_PROTO_STD_DUPLEX:
174		ax25_std_t2timer_expiry(ax25);
175		break;
176
177#ifdef CONFIG_AX25_DAMA_SLAVE
178	case AX25_PROTO_DAMA_SLAVE:
179		if (!ax25->ax25_dev->dama.slave)
180			ax25_std_t2timer_expiry(ax25);
181		break;
182#endif
183	}
184}
185
186static void ax25_t3timer_expiry(unsigned long param)
187{
188	ax25_cb *ax25 = (ax25_cb *)param;
189
190	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
191	case AX25_PROTO_STD_SIMPLEX:
192	case AX25_PROTO_STD_DUPLEX:
193		ax25_std_t3timer_expiry(ax25);
194		break;
195
196#ifdef CONFIG_AX25_DAMA_SLAVE
197	case AX25_PROTO_DAMA_SLAVE:
198		if (ax25->ax25_dev->dama.slave)
199			ax25_ds_t3timer_expiry(ax25);
200		else
201			ax25_std_t3timer_expiry(ax25);
202		break;
203#endif
204	}
205}
206
207static void ax25_idletimer_expiry(unsigned long param)
208{
209	ax25_cb *ax25 = (ax25_cb *)param;
210
211	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
212	case AX25_PROTO_STD_SIMPLEX:
213	case AX25_PROTO_STD_DUPLEX:
214		ax25_std_idletimer_expiry(ax25);
215		break;
216
217#ifdef CONFIG_AX25_DAMA_SLAVE
218	case AX25_PROTO_DAMA_SLAVE:
219		if (ax25->ax25_dev->dama.slave)
220			ax25_ds_idletimer_expiry(ax25);
221		else
222			ax25_std_idletimer_expiry(ax25);
223		break;
224#endif
225	}
226}