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> 311da177e4SLinus Torvalds #include <asm/uaccess.h> 321da177e4SLinus Torvalds #include <asm/system.h> 331da177e4SLinus Torvalds #include <linux/fcntl.h> 341da177e4SLinus Torvalds #include <linux/mm.h> 351da177e4SLinus Torvalds #include <linux/interrupt.h> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds static void ax25_heartbeat_expiry(unsigned long); 381da177e4SLinus Torvalds static void ax25_t1timer_expiry(unsigned long); 391da177e4SLinus Torvalds static void ax25_t2timer_expiry(unsigned long); 401da177e4SLinus Torvalds static void ax25_t3timer_expiry(unsigned long); 411da177e4SLinus Torvalds static void ax25_idletimer_expiry(unsigned long); 421da177e4SLinus Torvalds 43*21fab4a8SJarek Poplawski void ax25_setup_timers(ax25_cb *ax25) 44*21fab4a8SJarek Poplawski { 45*21fab4a8SJarek Poplawski setup_timer(&ax25->timer, ax25_heartbeat_expiry, (unsigned long)ax25); 46*21fab4a8SJarek Poplawski setup_timer(&ax25->t1timer, ax25_t1timer_expiry, (unsigned long)ax25); 47*21fab4a8SJarek Poplawski setup_timer(&ax25->t2timer, ax25_t2timer_expiry, (unsigned long)ax25); 48*21fab4a8SJarek Poplawski setup_timer(&ax25->t3timer, ax25_t3timer_expiry, (unsigned long)ax25); 49*21fab4a8SJarek Poplawski setup_timer(&ax25->idletimer, ax25_idletimer_expiry, 50*21fab4a8SJarek Poplawski (unsigned long)ax25); 51*21fab4a8SJarek Poplawski } 52*21fab4a8SJarek Poplawski 531da177e4SLinus Torvalds void ax25_start_heartbeat(ax25_cb *ax25) 541da177e4SLinus Torvalds { 55*21fab4a8SJarek Poplawski mod_timer(&ax25->timer, jiffies + 5 * HZ); 561da177e4SLinus Torvalds } 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds void ax25_start_t1timer(ax25_cb *ax25) 591da177e4SLinus Torvalds { 60*21fab4a8SJarek Poplawski mod_timer(&ax25->t1timer, jiffies + ax25->t1); 611da177e4SLinus Torvalds } 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds void ax25_start_t2timer(ax25_cb *ax25) 641da177e4SLinus Torvalds { 65*21fab4a8SJarek Poplawski mod_timer(&ax25->t2timer, jiffies + ax25->t2); 661da177e4SLinus Torvalds } 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds void ax25_start_t3timer(ax25_cb *ax25) 691da177e4SLinus Torvalds { 70*21fab4a8SJarek Poplawski if (ax25->t3 > 0) 71*21fab4a8SJarek Poplawski mod_timer(&ax25->t3timer, jiffies + ax25->t3); 72*21fab4a8SJarek Poplawski else 731da177e4SLinus Torvalds del_timer(&ax25->t3timer); 741da177e4SLinus Torvalds } 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds void ax25_start_idletimer(ax25_cb *ax25) 771da177e4SLinus Torvalds { 78*21fab4a8SJarek Poplawski if (ax25->idle > 0) 79*21fab4a8SJarek Poplawski mod_timer(&ax25->idletimer, jiffies + ax25->idle); 80*21fab4a8SJarek Poplawski else 811da177e4SLinus Torvalds del_timer(&ax25->idletimer); 821da177e4SLinus Torvalds } 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds void ax25_stop_heartbeat(ax25_cb *ax25) 851da177e4SLinus Torvalds { 861da177e4SLinus Torvalds del_timer(&ax25->timer); 871da177e4SLinus Torvalds } 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds void ax25_stop_t1timer(ax25_cb *ax25) 901da177e4SLinus Torvalds { 911da177e4SLinus Torvalds del_timer(&ax25->t1timer); 921da177e4SLinus Torvalds } 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds void ax25_stop_t2timer(ax25_cb *ax25) 951da177e4SLinus Torvalds { 961da177e4SLinus Torvalds del_timer(&ax25->t2timer); 971da177e4SLinus Torvalds } 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds void ax25_stop_t3timer(ax25_cb *ax25) 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds del_timer(&ax25->t3timer); 1021da177e4SLinus Torvalds } 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds void ax25_stop_idletimer(ax25_cb *ax25) 1051da177e4SLinus Torvalds { 1061da177e4SLinus Torvalds del_timer(&ax25->idletimer); 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds int ax25_t1timer_running(ax25_cb *ax25) 1101da177e4SLinus Torvalds { 1111da177e4SLinus Torvalds return timer_pending(&ax25->t1timer); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds unsigned long ax25_display_timer(struct timer_list *timer) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds if (!timer_pending(timer)) 1171da177e4SLinus Torvalds return 0; 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds return timer->expires - jiffies; 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds 12270868eacSRalf Baechle EXPORT_SYMBOL(ax25_display_timer); 12370868eacSRalf Baechle 1241da177e4SLinus Torvalds static void ax25_heartbeat_expiry(unsigned long param) 1251da177e4SLinus Torvalds { 1261da177e4SLinus Torvalds int proto = AX25_PROTO_STD_SIMPLEX; 1271da177e4SLinus Torvalds ax25_cb *ax25 = (ax25_cb *)param; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds if (ax25->ax25_dev) 1301da177e4SLinus Torvalds proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]; 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds switch (proto) { 1331da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1341da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1351da177e4SLinus Torvalds ax25_std_heartbeat_expiry(ax25); 1361da177e4SLinus Torvalds break; 1371da177e4SLinus Torvalds 1381da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1391da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1401da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 1411da177e4SLinus Torvalds ax25_ds_heartbeat_expiry(ax25); 1421da177e4SLinus Torvalds else 1431da177e4SLinus Torvalds ax25_std_heartbeat_expiry(ax25); 1441da177e4SLinus Torvalds break; 1451da177e4SLinus Torvalds #endif 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds } 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds static void ax25_t1timer_expiry(unsigned long param) 1501da177e4SLinus Torvalds { 1511da177e4SLinus Torvalds ax25_cb *ax25 = (ax25_cb *)param; 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1541da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1551da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1561da177e4SLinus Torvalds ax25_std_t1timer_expiry(ax25); 1571da177e4SLinus Torvalds break; 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1601da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1611da177e4SLinus Torvalds if (!ax25->ax25_dev->dama.slave) 1621da177e4SLinus Torvalds ax25_std_t1timer_expiry(ax25); 1631da177e4SLinus Torvalds break; 1641da177e4SLinus Torvalds #endif 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds static void ax25_t2timer_expiry(unsigned long param) 1691da177e4SLinus Torvalds { 1701da177e4SLinus Torvalds ax25_cb *ax25 = (ax25_cb *)param; 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1731da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1741da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1751da177e4SLinus Torvalds ax25_std_t2timer_expiry(ax25); 1761da177e4SLinus Torvalds break; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1791da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1801da177e4SLinus Torvalds if (!ax25->ax25_dev->dama.slave) 1811da177e4SLinus Torvalds ax25_std_t2timer_expiry(ax25); 1821da177e4SLinus Torvalds break; 1831da177e4SLinus Torvalds #endif 1841da177e4SLinus Torvalds } 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds static void ax25_t3timer_expiry(unsigned long param) 1881da177e4SLinus Torvalds { 1891da177e4SLinus Torvalds ax25_cb *ax25 = (ax25_cb *)param; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 1921da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 1931da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 1941da177e4SLinus Torvalds ax25_std_t3timer_expiry(ax25); 1951da177e4SLinus Torvalds break; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 1981da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 1991da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 2001da177e4SLinus Torvalds ax25_ds_t3timer_expiry(ax25); 2011da177e4SLinus Torvalds else 2021da177e4SLinus Torvalds ax25_std_t3timer_expiry(ax25); 2031da177e4SLinus Torvalds break; 2041da177e4SLinus Torvalds #endif 2051da177e4SLinus Torvalds } 2061da177e4SLinus Torvalds } 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds static void ax25_idletimer_expiry(unsigned long param) 2091da177e4SLinus Torvalds { 2101da177e4SLinus Torvalds ax25_cb *ax25 = (ax25_cb *)param; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) { 2131da177e4SLinus Torvalds case AX25_PROTO_STD_SIMPLEX: 2141da177e4SLinus Torvalds case AX25_PROTO_STD_DUPLEX: 2151da177e4SLinus Torvalds ax25_std_idletimer_expiry(ax25); 2161da177e4SLinus Torvalds break; 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds #ifdef CONFIG_AX25_DAMA_SLAVE 2191da177e4SLinus Torvalds case AX25_PROTO_DAMA_SLAVE: 2201da177e4SLinus Torvalds if (ax25->ax25_dev->dama.slave) 2211da177e4SLinus Torvalds ax25_ds_idletimer_expiry(ax25); 2221da177e4SLinus Torvalds else 2231da177e4SLinus Torvalds ax25_std_idletimer_expiry(ax25); 2241da177e4SLinus Torvalds break; 2251da177e4SLinus Torvalds #endif 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds } 228