| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Ralf Baechle | 70868ea | 2006-05-03 23:25:17 -0700 | [diff] [blame] | 20 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <asm/system.h> | 
 | 33 | #include <linux/fcntl.h> | 
 | 34 | #include <linux/mm.h> | 
 | 35 | #include <linux/interrupt.h> | 
 | 36 |  | 
 | 37 | static void ax25_heartbeat_expiry(unsigned long); | 
 | 38 | static void ax25_t1timer_expiry(unsigned long); | 
 | 39 | static void ax25_t2timer_expiry(unsigned long); | 
 | 40 | static void ax25_t3timer_expiry(unsigned long); | 
 | 41 | static void ax25_idletimer_expiry(unsigned long); | 
 | 42 |  | 
 | 43 | void ax25_start_heartbeat(ax25_cb *ax25) | 
 | 44 | { | 
 | 45 | 	del_timer(&ax25->timer); | 
 | 46 |  | 
 | 47 | 	ax25->timer.data     = (unsigned long)ax25; | 
 | 48 | 	ax25->timer.function = &ax25_heartbeat_expiry; | 
 | 49 | 	ax25->timer.expires  = jiffies + 5 * HZ; | 
 | 50 |  | 
 | 51 | 	add_timer(&ax25->timer); | 
 | 52 | } | 
 | 53 |  | 
 | 54 | void ax25_start_t1timer(ax25_cb *ax25) | 
 | 55 | { | 
 | 56 | 	del_timer(&ax25->t1timer); | 
 | 57 |  | 
 | 58 | 	ax25->t1timer.data     = (unsigned long)ax25; | 
 | 59 | 	ax25->t1timer.function = &ax25_t1timer_expiry; | 
 | 60 | 	ax25->t1timer.expires  = jiffies + ax25->t1; | 
 | 61 |  | 
 | 62 | 	add_timer(&ax25->t1timer); | 
 | 63 | } | 
 | 64 |  | 
 | 65 | void ax25_start_t2timer(ax25_cb *ax25) | 
 | 66 | { | 
 | 67 | 	del_timer(&ax25->t2timer); | 
 | 68 |  | 
 | 69 | 	ax25->t2timer.data     = (unsigned long)ax25; | 
 | 70 | 	ax25->t2timer.function = &ax25_t2timer_expiry; | 
 | 71 | 	ax25->t2timer.expires  = jiffies + ax25->t2; | 
 | 72 |  | 
 | 73 | 	add_timer(&ax25->t2timer); | 
 | 74 | } | 
 | 75 |  | 
 | 76 | void ax25_start_t3timer(ax25_cb *ax25) | 
 | 77 | { | 
 | 78 | 	del_timer(&ax25->t3timer); | 
 | 79 |  | 
 | 80 | 	if (ax25->t3 > 0) { | 
 | 81 | 		ax25->t3timer.data     = (unsigned long)ax25; | 
 | 82 | 		ax25->t3timer.function = &ax25_t3timer_expiry; | 
 | 83 | 		ax25->t3timer.expires  = jiffies + ax25->t3; | 
 | 84 |  | 
 | 85 | 		add_timer(&ax25->t3timer); | 
 | 86 | 	} | 
 | 87 | } | 
 | 88 |  | 
 | 89 | void ax25_start_idletimer(ax25_cb *ax25) | 
 | 90 | { | 
 | 91 | 	del_timer(&ax25->idletimer); | 
 | 92 |  | 
 | 93 | 	if (ax25->idle > 0) { | 
 | 94 | 		ax25->idletimer.data     = (unsigned long)ax25; | 
 | 95 | 		ax25->idletimer.function = &ax25_idletimer_expiry; | 
 | 96 | 		ax25->idletimer.expires  = jiffies + ax25->idle; | 
 | 97 |  | 
 | 98 | 		add_timer(&ax25->idletimer); | 
 | 99 | 	} | 
 | 100 | } | 
 | 101 |  | 
 | 102 | void ax25_stop_heartbeat(ax25_cb *ax25) | 
 | 103 | { | 
 | 104 | 	del_timer(&ax25->timer); | 
 | 105 | } | 
 | 106 |  | 
 | 107 | void ax25_stop_t1timer(ax25_cb *ax25) | 
 | 108 | { | 
 | 109 | 	del_timer(&ax25->t1timer); | 
 | 110 | } | 
 | 111 |  | 
 | 112 | void ax25_stop_t2timer(ax25_cb *ax25) | 
 | 113 | { | 
 | 114 | 	del_timer(&ax25->t2timer); | 
 | 115 | } | 
 | 116 |  | 
 | 117 | void ax25_stop_t3timer(ax25_cb *ax25) | 
 | 118 | { | 
 | 119 | 	del_timer(&ax25->t3timer); | 
 | 120 | } | 
 | 121 |  | 
 | 122 | void ax25_stop_idletimer(ax25_cb *ax25) | 
 | 123 | { | 
 | 124 | 	del_timer(&ax25->idletimer); | 
 | 125 | } | 
 | 126 |  | 
 | 127 | int ax25_t1timer_running(ax25_cb *ax25) | 
 | 128 | { | 
 | 129 | 	return timer_pending(&ax25->t1timer); | 
 | 130 | } | 
 | 131 |  | 
 | 132 | unsigned long ax25_display_timer(struct timer_list *timer) | 
 | 133 | { | 
 | 134 | 	if (!timer_pending(timer)) | 
 | 135 | 		return 0; | 
 | 136 |  | 
 | 137 | 	return timer->expires - jiffies; | 
 | 138 | } | 
 | 139 |  | 
| Ralf Baechle | 70868ea | 2006-05-03 23:25:17 -0700 | [diff] [blame] | 140 | EXPORT_SYMBOL(ax25_display_timer); | 
 | 141 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | static void ax25_heartbeat_expiry(unsigned long param) | 
 | 143 | { | 
 | 144 | 	int proto = AX25_PROTO_STD_SIMPLEX; | 
 | 145 | 	ax25_cb *ax25 = (ax25_cb *)param; | 
 | 146 |  | 
 | 147 | 	if (ax25->ax25_dev) | 
 | 148 | 		proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]; | 
 | 149 |  | 
 | 150 | 	switch (proto) { | 
 | 151 | 	case AX25_PROTO_STD_SIMPLEX: | 
 | 152 | 	case AX25_PROTO_STD_DUPLEX: | 
 | 153 | 		ax25_std_heartbeat_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_ds_heartbeat_expiry(ax25); | 
 | 160 | 		else | 
 | 161 | 			ax25_std_heartbeat_expiry(ax25); | 
 | 162 | 		break; | 
 | 163 | #endif | 
 | 164 | 	} | 
 | 165 | } | 
 | 166 |  | 
 | 167 | static void ax25_t1timer_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_t1timer_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_t1timer_expiry(ax25); | 
 | 181 | 		break; | 
 | 182 | #endif | 
 | 183 | 	} | 
 | 184 | } | 
 | 185 |  | 
 | 186 | static void ax25_t2timer_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_t2timer_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_std_t2timer_expiry(ax25); | 
 | 200 | 		break; | 
 | 201 | #endif | 
 | 202 | 	} | 
 | 203 | } | 
 | 204 |  | 
 | 205 | static void ax25_t3timer_expiry(unsigned long param) | 
 | 206 | { | 
 | 207 | 	ax25_cb *ax25 = (ax25_cb *)param; | 
 | 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_t3timer_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_t3timer_expiry(ax25); | 
 | 219 | 		else | 
 | 220 | 			ax25_std_t3timer_expiry(ax25); | 
 | 221 | 		break; | 
 | 222 | #endif | 
 | 223 | 	} | 
 | 224 | } | 
 | 225 |  | 
 | 226 | static void ax25_idletimer_expiry(unsigned long param) | 
 | 227 | { | 
 | 228 | 	ax25_cb *ax25 = (ax25_cb *)param; | 
 | 229 |  | 
 | 230 | 	switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { | 
 | 231 | 	case AX25_PROTO_STD_SIMPLEX: | 
 | 232 | 	case AX25_PROTO_STD_DUPLEX: | 
 | 233 | 		ax25_std_idletimer_expiry(ax25); | 
 | 234 | 		break; | 
 | 235 |  | 
 | 236 | #ifdef CONFIG_AX25_DAMA_SLAVE | 
 | 237 | 	case AX25_PROTO_DAMA_SLAVE: | 
 | 238 | 		if (ax25->ax25_dev->dama.slave) | 
 | 239 | 			ax25_ds_idletimer_expiry(ax25); | 
 | 240 | 		else | 
 | 241 | 			ax25_std_idletimer_expiry(ax25); | 
 | 242 | 		break; | 
 | 243 | #endif | 
 | 244 | 	} | 
 | 245 | } |