11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 31da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 41da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 51da177e4SLinus Torvalds * (at your option) any later version. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk) 81da177e4SLinus Torvalds * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) 91da177e4SLinus Torvalds * Copyright (C) Tomi Manninen OH2BNS (oh2bns@sral.fi) 101da177e4SLinus Torvalds * Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk) 111da177e4SLinus Torvalds * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de) 121da177e4SLinus Torvalds * Copyright (C) Frederic Rible F1OAT (frible@teaser.fr) 131da177e4SLinus Torvalds * Copyright (C) 2002 Ralf Baechle DO1GRB (ralf@gnu.org) 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds #include <linux/errno.h> 161da177e4SLinus Torvalds #include <linux/types.h> 171da177e4SLinus Torvalds #include <linux/socket.h> 181da177e4SLinus Torvalds #include <linux/in.h> 191da177e4SLinus Torvalds #include <linux/kernel.h> 2070868eacSRalf Baechle #include <linux/module.h> 211da177e4SLinus Torvalds #include <linux/jiffies.h> 221da177e4SLinus Torvalds #include <linux/timer.h> 231da177e4SLinus Torvalds #include <linux/string.h> 241da177e4SLinus Torvalds #include <linux/sockios.h> 251da177e4SLinus Torvalds #include <linux/net.h> 261da177e4SLinus Torvalds #include <net/ax25.h> 271da177e4SLinus Torvalds #include <linux/inet.h> 281da177e4SLinus Torvalds #include <linux/netdevice.h> 291da177e4SLinus Torvalds #include <linux/skbuff.h> 301da177e4SLinus Torvalds #include <net/sock.h> 317c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 321da177e4SLinus Torvalds #include <linux/fcntl.h> 331da177e4SLinus Torvalds #include <linux/mm.h> 341da177e4SLinus Torvalds #include <linux/interrupt.h> 351da177e4SLinus Torvalds 36*8dbd05ffSKees Cook static void ax25_heartbeat_expiry(struct timer_list *); 37*8dbd05ffSKees Cook static void ax25_t1timer_expiry(struct timer_list *); 38*8dbd05ffSKees Cook static void ax25_t2timer_expiry(struct timer_list *); 39*8dbd05ffSKees Cook static void ax25_t3timer_expiry(struct timer_list *); 40*8dbd05ffSKees Cook static void ax25_idletimer_expiry(struct timer_list *); 411da177e4SLinus Torvalds 4221fab4a8SJarek Poplawski void ax25_setup_timers(ax25_cb *ax25) 4321fab4a8SJarek Poplawski { 44*8dbd05ffSKees Cook timer_setup(&ax25->timer, ax25_heartbeat_expiry, 0); 45*8dbd05ffSKees Cook timer_setup(&ax25->t1timer, ax25_t1timer_expiry, 0); 46*8dbd05ffSKees Cook timer_setup(&ax25->t2timer, ax25_t2timer_expiry, 0); 47*8dbd05ffSKees Cook timer_setup(&ax25->t3timer, ax25_t3timer_expiry, 0); 48*8dbd05ffSKees Cook timer_setup(&ax25->idletimer, ax25_idletimer_expiry, 0); 4921fab4a8SJarek Poplawski } 5021fab4a8SJarek Poplawski 511da177e4SLinus Torvalds void ax25_start_heartbeat(ax25_cb *ax25) 521da177e4SLinus Torvalds { 5321fab4a8SJarek Poplawski mod_timer(&ax25->timer, jiffies + 5 * HZ); 541da177e4SLinus Torvalds } 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds void ax25_start_t1timer(ax25_cb *ax25) 571da177e4SLinus Torvalds { 5821fab4a8SJarek Poplawski mod_timer(&ax25->t1timer, jiffies + ax25->t1); 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds void ax25_start_t2timer(ax25_cb *ax25) 621da177e4SLinus Torvalds { 6321fab4a8SJarek Poplawski mod_timer(&ax25->t2timer, jiffies + ax25->t2); 641da177e4SLinus Torvalds } 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds void ax25_start_t3timer(ax25_cb *ax25) 671da177e4SLinus Torvalds { 6821fab4a8SJarek Poplawski if (ax25->t3 > 0) 6921fab4a8SJarek Poplawski mod_timer(&ax25->t3timer, jiffies + ax25->t3); 7021fab4a8SJarek Poplawski else 711da177e4SLinus Torvalds del_timer(&ax25->t3timer); 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds void ax25_start_idletimer(ax25_cb *ax25) 751da177e4SLinus Torvalds { 7621fab4a8SJarek Poplawski if (ax25->idle > 0) 7721fab4a8SJarek Poplawski mod_timer(&ax25->idletimer, jiffies + ax25->idle); 7821fab4a8SJarek Poplawski else 791da177e4SLinus Torvalds del_timer(&ax25->idletimer); 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds void ax25_stop_heartbeat(ax25_cb *ax25) 831da177e4SLinus Torvalds { 841da177e4SLinus Torvalds del_timer(&ax25->timer); 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds void ax25_stop_t1timer(ax25_cb *ax25) 881da177e4SLinus Torvalds { 891da177e4SLinus Torvalds del_timer(&ax25->t1timer); 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds void ax25_stop_t2timer(ax25_cb *ax25) 931da177e4SLinus Torvalds { 941da177e4SLinus Torvalds del_timer(&ax25->t2timer); 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds void ax25_stop_t3timer(ax25_cb *ax25) 981da177e4SLinus Torvalds { 991da177e4SLinus Torvalds del_timer(&ax25->t3timer); 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds void ax25_stop_idletimer(ax25_cb *ax25) 1031da177e4SLinus Torvalds { 1041da177e4SLinus Torvalds del_timer(&ax25->idletimer); 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds int ax25_t1timer_running(ax25_cb *ax25) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds return timer_pending(&ax25->t1timer); 1101da177e4SLinus Torvalds } 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds unsigned long ax25_display_timer(struct timer_list *timer) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds if (!timer_pending(timer)) 1151da177e4SLinus Torvalds return 0; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds return timer->expires - jiffies; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds 12070868eacSRalf Baechle EXPORT_SYMBOL(ax25_display_timer); 12170868eacSRalf Baechle 122*8dbd05ffSKees Cook static void ax25_heartbeat_expiry(struct timer_list *t) 1231da177e4SLinus Torvalds { 1241da177e4SLinus Torvalds int proto = AX25_PROTO_STD_SIMPLEX; 125*8dbd05ffSKees Cook ax25_cb *ax25 = from_timer(ax25, t, timer); 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds if (ax25->ax25_dev) 1281da177e4SLinus Torvalds proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds switch (proto) { 1311da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1321da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1331da177e4SLinus Torvalds ax25_std_heartbeat_expiry(ax25); 1341da177e4SLinus Torvalds break; 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1371da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1381da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 1391da177e4SLinus Torvalds ax25_ds_heartbeat_expiry(ax25); 1401da177e4SLinus Torvalds else 1411da177e4SLinus Torvalds ax25_std_heartbeat_expiry(ax25); 1421da177e4SLinus Torvalds break; 1431da177e4SLinus Torvalds #endif 1441da177e4SLinus Torvalds } 1451da177e4SLinus Torvalds } 1461da177e4SLinus Torvalds 147*8dbd05ffSKees Cook static void ax25_t1timer_expiry(struct timer_list *t) 1481da177e4SLinus Torvalds { 149*8dbd05ffSKees Cook ax25_cb *ax25 = from_timer(ax25, t, t1timer); 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1521da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1531da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1541da177e4SLinus Torvalds ax25_std_t1timer_expiry(ax25); 1551da177e4SLinus Torvalds break; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1581da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1591da177e4SLinus Torvalds if (!ax25->ax25_dev->dama.slave) 1601da177e4SLinus Torvalds ax25_std_t1timer_expiry(ax25); 1611da177e4SLinus Torvalds break; 1621da177e4SLinus Torvalds #endif 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds 166*8dbd05ffSKees Cook static void ax25_t2timer_expiry(struct timer_list *t) 1671da177e4SLinus Torvalds { 168*8dbd05ffSKees Cook ax25_cb *ax25 = from_timer(ax25, t, t2timer); 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1711da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1721da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1731da177e4SLinus Torvalds ax25_std_t2timer_expiry(ax25); 1741da177e4SLinus Torvalds break; 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1771da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1781da177e4SLinus Torvalds if (!ax25->ax25_dev->dama.slave) 1791da177e4SLinus Torvalds ax25_std_t2timer_expiry(ax25); 1801da177e4SLinus Torvalds break; 1811da177e4SLinus Torvalds #endif 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds } 1841da177e4SLinus Torvalds 185*8dbd05ffSKees Cook static void ax25_t3timer_expiry(struct timer_list *t) 1861da177e4SLinus Torvalds { 187*8dbd05ffSKees Cook ax25_cb *ax25 = from_timer(ax25, t, t3timer); 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1901da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1911da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1921da177e4SLinus Torvalds ax25_std_t3timer_expiry(ax25); 1931da177e4SLinus Torvalds break; 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1961da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1971da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 1981da177e4SLinus Torvalds ax25_ds_t3timer_expiry(ax25); 1991da177e4SLinus Torvalds else 2001da177e4SLinus Torvalds ax25_std_t3timer_expiry(ax25); 2011da177e4SLinus Torvalds break; 2021da177e4SLinus Torvalds #endif 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds } 2051da177e4SLinus Torvalds 206*8dbd05ffSKees Cook static void ax25_idletimer_expiry(struct timer_list *t) 2071da177e4SLinus Torvalds { 208*8dbd05ffSKees Cook ax25_cb *ax25 = from_timer(ax25, t, idletimer); 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 2111da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 2121da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 2131da177e4SLinus Torvalds ax25_std_idletimer_expiry(ax25); 2141da177e4SLinus Torvalds break; 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 2171da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 2181da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 2191da177e4SLinus Torvalds ax25_ds_idletimer_expiry(ax25); 2201da177e4SLinus Torvalds else 2211da177e4SLinus Torvalds ax25_std_idletimer_expiry(ax25); 2221da177e4SLinus Torvalds break; 2231da177e4SLinus Torvalds #endif 2241da177e4SLinus Torvalds } 2251da177e4SLinus Torvalds } 226