0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/errno.h>
0013 #include <linux/types.h>
0014 #include <linux/socket.h>
0015 #include <linux/in.h>
0016 #include <linux/kernel.h>
0017 #include <linux/module.h>
0018 #include <linux/jiffies.h>
0019 #include <linux/timer.h>
0020 #include <linux/string.h>
0021 #include <linux/sockios.h>
0022 #include <linux/net.h>
0023 #include <net/ax25.h>
0024 #include <linux/inet.h>
0025 #include <linux/netdevice.h>
0026 #include <linux/skbuff.h>
0027 #include <net/sock.h>
0028 #include <linux/uaccess.h>
0029 #include <linux/fcntl.h>
0030 #include <linux/mm.h>
0031 #include <linux/interrupt.h>
0032
0033 static void ax25_heartbeat_expiry(struct timer_list *);
0034 static void ax25_t1timer_expiry(struct timer_list *);
0035 static void ax25_t2timer_expiry(struct timer_list *);
0036 static void ax25_t3timer_expiry(struct timer_list *);
0037 static void ax25_idletimer_expiry(struct timer_list *);
0038
0039 void ax25_setup_timers(ax25_cb *ax25)
0040 {
0041 timer_setup(&ax25->timer, ax25_heartbeat_expiry, 0);
0042 timer_setup(&ax25->t1timer, ax25_t1timer_expiry, 0);
0043 timer_setup(&ax25->t2timer, ax25_t2timer_expiry, 0);
0044 timer_setup(&ax25->t3timer, ax25_t3timer_expiry, 0);
0045 timer_setup(&ax25->idletimer, ax25_idletimer_expiry, 0);
0046 }
0047
0048 void ax25_start_heartbeat(ax25_cb *ax25)
0049 {
0050 mod_timer(&ax25->timer, jiffies + 5 * HZ);
0051 }
0052
0053 void ax25_start_t1timer(ax25_cb *ax25)
0054 {
0055 mod_timer(&ax25->t1timer, jiffies + ax25->t1);
0056 }
0057
0058 void ax25_start_t2timer(ax25_cb *ax25)
0059 {
0060 mod_timer(&ax25->t2timer, jiffies + ax25->t2);
0061 }
0062
0063 void ax25_start_t3timer(ax25_cb *ax25)
0064 {
0065 if (ax25->t3 > 0)
0066 mod_timer(&ax25->t3timer, jiffies + ax25->t3);
0067 else
0068 del_timer(&ax25->t3timer);
0069 }
0070
0071 void ax25_start_idletimer(ax25_cb *ax25)
0072 {
0073 if (ax25->idle > 0)
0074 mod_timer(&ax25->idletimer, jiffies + ax25->idle);
0075 else
0076 del_timer(&ax25->idletimer);
0077 }
0078
0079 void ax25_stop_heartbeat(ax25_cb *ax25)
0080 {
0081 del_timer(&ax25->timer);
0082 }
0083
0084 void ax25_stop_t1timer(ax25_cb *ax25)
0085 {
0086 del_timer(&ax25->t1timer);
0087 }
0088
0089 void ax25_stop_t2timer(ax25_cb *ax25)
0090 {
0091 del_timer(&ax25->t2timer);
0092 }
0093
0094 void ax25_stop_t3timer(ax25_cb *ax25)
0095 {
0096 del_timer(&ax25->t3timer);
0097 }
0098
0099 void ax25_stop_idletimer(ax25_cb *ax25)
0100 {
0101 del_timer(&ax25->idletimer);
0102 }
0103
0104 int ax25_t1timer_running(ax25_cb *ax25)
0105 {
0106 return timer_pending(&ax25->t1timer);
0107 }
0108
0109 unsigned long ax25_display_timer(struct timer_list *timer)
0110 {
0111 long delta = timer->expires - jiffies;
0112
0113 if (!timer_pending(timer))
0114 return 0;
0115
0116 return max(0L, delta);
0117 }
0118
0119 EXPORT_SYMBOL(ax25_display_timer);
0120
0121 static void ax25_heartbeat_expiry(struct timer_list *t)
0122 {
0123 int proto = AX25_PROTO_STD_SIMPLEX;
0124 ax25_cb *ax25 = from_timer(ax25, t, timer);
0125
0126 if (ax25->ax25_dev)
0127 proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
0128
0129 switch (proto) {
0130 case AX25_PROTO_STD_SIMPLEX:
0131 case AX25_PROTO_STD_DUPLEX:
0132 ax25_std_heartbeat_expiry(ax25);
0133 break;
0134
0135 #ifdef CONFIG_AX25_DAMA_SLAVE
0136 case AX25_PROTO_DAMA_SLAVE:
0137 if (ax25->ax25_dev->dama.slave)
0138 ax25_ds_heartbeat_expiry(ax25);
0139 else
0140 ax25_std_heartbeat_expiry(ax25);
0141 break;
0142 #endif
0143 }
0144 }
0145
0146 static void ax25_t1timer_expiry(struct timer_list *t)
0147 {
0148 ax25_cb *ax25 = from_timer(ax25, t, t1timer);
0149
0150 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
0151 case AX25_PROTO_STD_SIMPLEX:
0152 case AX25_PROTO_STD_DUPLEX:
0153 ax25_std_t1timer_expiry(ax25);
0154 break;
0155
0156 #ifdef CONFIG_AX25_DAMA_SLAVE
0157 case AX25_PROTO_DAMA_SLAVE:
0158 if (!ax25->ax25_dev->dama.slave)
0159 ax25_std_t1timer_expiry(ax25);
0160 break;
0161 #endif
0162 }
0163 }
0164
0165 static void ax25_t2timer_expiry(struct timer_list *t)
0166 {
0167 ax25_cb *ax25 = from_timer(ax25, t, t2timer);
0168
0169 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
0170 case AX25_PROTO_STD_SIMPLEX:
0171 case AX25_PROTO_STD_DUPLEX:
0172 ax25_std_t2timer_expiry(ax25);
0173 break;
0174
0175 #ifdef CONFIG_AX25_DAMA_SLAVE
0176 case AX25_PROTO_DAMA_SLAVE:
0177 if (!ax25->ax25_dev->dama.slave)
0178 ax25_std_t2timer_expiry(ax25);
0179 break;
0180 #endif
0181 }
0182 }
0183
0184 static void ax25_t3timer_expiry(struct timer_list *t)
0185 {
0186 ax25_cb *ax25 = from_timer(ax25, t, t3timer);
0187
0188 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
0189 case AX25_PROTO_STD_SIMPLEX:
0190 case AX25_PROTO_STD_DUPLEX:
0191 ax25_std_t3timer_expiry(ax25);
0192 break;
0193
0194 #ifdef CONFIG_AX25_DAMA_SLAVE
0195 case AX25_PROTO_DAMA_SLAVE:
0196 if (ax25->ax25_dev->dama.slave)
0197 ax25_ds_t3timer_expiry(ax25);
0198 else
0199 ax25_std_t3timer_expiry(ax25);
0200 break;
0201 #endif
0202 }
0203 }
0204
0205 static void ax25_idletimer_expiry(struct timer_list *t)
0206 {
0207 ax25_cb *ax25 = from_timer(ax25, t, idletimer);
0208
0209 switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
0210 case AX25_PROTO_STD_SIMPLEX:
0211 case AX25_PROTO_STD_DUPLEX:
0212 ax25_std_idletimer_expiry(ax25);
0213 break;
0214
0215 #ifdef CONFIG_AX25_DAMA_SLAVE
0216 case AX25_PROTO_DAMA_SLAVE:
0217 if (ax25->ax25_dev->dama.slave)
0218 ax25_ds_idletimer_expiry(ax25);
0219 else
0220 ax25_std_idletimer_expiry(ax25);
0221 break;
0222 #endif
0223 }
0224 }