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 | |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 43 | void ax25_setup_timers(ax25_cb *ax25) |
| 44 | { |
| 45 | setup_timer(&ax25->timer, ax25_heartbeat_expiry, (unsigned long)ax25); |
| 46 | setup_timer(&ax25->t1timer, ax25_t1timer_expiry, (unsigned long)ax25); |
| 47 | setup_timer(&ax25->t2timer, ax25_t2timer_expiry, (unsigned long)ax25); |
| 48 | setup_timer(&ax25->t3timer, ax25_t3timer_expiry, (unsigned long)ax25); |
| 49 | setup_timer(&ax25->idletimer, ax25_idletimer_expiry, |
| 50 | (unsigned long)ax25); |
| 51 | } |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | void ax25_start_heartbeat(ax25_cb *ax25) |
| 54 | { |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 55 | mod_timer(&ax25->timer, jiffies + 5 * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void ax25_start_t1timer(ax25_cb *ax25) |
| 59 | { |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 60 | mod_timer(&ax25->t1timer, jiffies + ax25->t1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void ax25_start_t2timer(ax25_cb *ax25) |
| 64 | { |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 65 | mod_timer(&ax25->t2timer, jiffies + ax25->t2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void ax25_start_t3timer(ax25_cb *ax25) |
| 69 | { |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 70 | if (ax25->t3 > 0) |
| 71 | mod_timer(&ax25->t3timer, jiffies + ax25->t3); |
| 72 | else |
| 73 | del_timer(&ax25->t3timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void ax25_start_idletimer(ax25_cb *ax25) |
| 77 | { |
Jarek Poplawski | 21fab4a | 2008-02-11 21:36:39 -0800 | [diff] [blame] | 78 | if (ax25->idle > 0) |
| 79 | mod_timer(&ax25->idletimer, jiffies + ax25->idle); |
| 80 | else |
| 81 | del_timer(&ax25->idletimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void ax25_stop_heartbeat(ax25_cb *ax25) |
| 85 | { |
| 86 | del_timer(&ax25->timer); |
| 87 | } |
| 88 | |
| 89 | void ax25_stop_t1timer(ax25_cb *ax25) |
| 90 | { |
| 91 | del_timer(&ax25->t1timer); |
| 92 | } |
| 93 | |
| 94 | void ax25_stop_t2timer(ax25_cb *ax25) |
| 95 | { |
| 96 | del_timer(&ax25->t2timer); |
| 97 | } |
| 98 | |
| 99 | void ax25_stop_t3timer(ax25_cb *ax25) |
| 100 | { |
| 101 | del_timer(&ax25->t3timer); |
| 102 | } |
| 103 | |
| 104 | void ax25_stop_idletimer(ax25_cb *ax25) |
| 105 | { |
| 106 | del_timer(&ax25->idletimer); |
| 107 | } |
| 108 | |
| 109 | int ax25_t1timer_running(ax25_cb *ax25) |
| 110 | { |
| 111 | return timer_pending(&ax25->t1timer); |
| 112 | } |
| 113 | |
| 114 | unsigned long ax25_display_timer(struct timer_list *timer) |
| 115 | { |
| 116 | if (!timer_pending(timer)) |
| 117 | return 0; |
| 118 | |
| 119 | return timer->expires - jiffies; |
| 120 | } |
| 121 | |
Ralf Baechle | 70868ea | 2006-05-03 23:25:17 -0700 | [diff] [blame] | 122 | EXPORT_SYMBOL(ax25_display_timer); |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static void ax25_heartbeat_expiry(unsigned long param) |
| 125 | { |
| 126 | int proto = AX25_PROTO_STD_SIMPLEX; |
| 127 | ax25_cb *ax25 = (ax25_cb *)param; |
| 128 | |
| 129 | if (ax25->ax25_dev) |
| 130 | proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]; |
| 131 | |
| 132 | switch (proto) { |
| 133 | case AX25_PROTO_STD_SIMPLEX: |
| 134 | case AX25_PROTO_STD_DUPLEX: |
| 135 | ax25_std_heartbeat_expiry(ax25); |
| 136 | break; |
| 137 | |
| 138 | #ifdef CONFIG_AX25_DAMA_SLAVE |
| 139 | case AX25_PROTO_DAMA_SLAVE: |
| 140 | if (ax25->ax25_dev->dama.slave) |
| 141 | ax25_ds_heartbeat_expiry(ax25); |
| 142 | else |
| 143 | ax25_std_heartbeat_expiry(ax25); |
| 144 | break; |
| 145 | #endif |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static void ax25_t1timer_expiry(unsigned long param) |
| 150 | { |
| 151 | ax25_cb *ax25 = (ax25_cb *)param; |
| 152 | |
| 153 | switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { |
| 154 | case AX25_PROTO_STD_SIMPLEX: |
| 155 | case AX25_PROTO_STD_DUPLEX: |
| 156 | ax25_std_t1timer_expiry(ax25); |
| 157 | break; |
| 158 | |
| 159 | #ifdef CONFIG_AX25_DAMA_SLAVE |
| 160 | case AX25_PROTO_DAMA_SLAVE: |
| 161 | if (!ax25->ax25_dev->dama.slave) |
| 162 | ax25_std_t1timer_expiry(ax25); |
| 163 | break; |
| 164 | #endif |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | static void ax25_t2timer_expiry(unsigned long param) |
| 169 | { |
| 170 | ax25_cb *ax25 = (ax25_cb *)param; |
| 171 | |
| 172 | switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { |
| 173 | case AX25_PROTO_STD_SIMPLEX: |
| 174 | case AX25_PROTO_STD_DUPLEX: |
| 175 | ax25_std_t2timer_expiry(ax25); |
| 176 | break; |
| 177 | |
| 178 | #ifdef CONFIG_AX25_DAMA_SLAVE |
| 179 | case AX25_PROTO_DAMA_SLAVE: |
| 180 | if (!ax25->ax25_dev->dama.slave) |
| 181 | ax25_std_t2timer_expiry(ax25); |
| 182 | break; |
| 183 | #endif |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static void ax25_t3timer_expiry(unsigned long param) |
| 188 | { |
| 189 | ax25_cb *ax25 = (ax25_cb *)param; |
| 190 | |
| 191 | switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { |
| 192 | case AX25_PROTO_STD_SIMPLEX: |
| 193 | case AX25_PROTO_STD_DUPLEX: |
| 194 | ax25_std_t3timer_expiry(ax25); |
| 195 | break; |
| 196 | |
| 197 | #ifdef CONFIG_AX25_DAMA_SLAVE |
| 198 | case AX25_PROTO_DAMA_SLAVE: |
| 199 | if (ax25->ax25_dev->dama.slave) |
| 200 | ax25_ds_t3timer_expiry(ax25); |
| 201 | else |
| 202 | ax25_std_t3timer_expiry(ax25); |
| 203 | break; |
| 204 | #endif |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | static void ax25_idletimer_expiry(unsigned long param) |
| 209 | { |
| 210 | ax25_cb *ax25 = (ax25_cb *)param; |
| 211 | |
| 212 | switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { |
| 213 | case AX25_PROTO_STD_SIMPLEX: |
| 214 | case AX25_PROTO_STD_DUPLEX: |
| 215 | ax25_std_idletimer_expiry(ax25); |
| 216 | break; |
| 217 | |
| 218 | #ifdef CONFIG_AX25_DAMA_SLAVE |
| 219 | case AX25_PROTO_DAMA_SLAVE: |
| 220 | if (ax25->ax25_dev->dama.slave) |
| 221 | ax25_ds_idletimer_expiry(ax25); |
| 222 | else |
| 223 | ax25_std_idletimer_expiry(ax25); |
| 224 | break; |
| 225 | #endif |
| 226 | } |
| 227 | } |