Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ax25_timer.c
Go to the documentation of this file.
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 ([email protected])
8  * Copyright (C) Jonathan Naylor G4KLX ([email protected])
9  * Copyright (C) Tomi Manninen OH2BNS ([email protected])
10  * Copyright (C) Darryl Miles G7LED ([email protected])
11  * Copyright (C) Joerg Reuter DL1BKE ([email protected])
12  * Copyright (C) Frederic Rible F1OAT ([email protected])
13  * Copyright (C) 2002 Ralf Baechle DO1GRB ([email protected])
14  */
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>
20 #include <linux/module.h>
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 <linux/fcntl.h>
33 #include <linux/mm.h>
34 #include <linux/interrupt.h>
35 
36 static void ax25_heartbeat_expiry(unsigned long);
37 static void ax25_t1timer_expiry(unsigned long);
38 static void ax25_t2timer_expiry(unsigned long);
39 static void ax25_t3timer_expiry(unsigned long);
40 static void ax25_idletimer_expiry(unsigned long);
41 
43 {
44  setup_timer(&ax25->timer, ax25_heartbeat_expiry, (unsigned long)ax25);
45  setup_timer(&ax25->t1timer, ax25_t1timer_expiry, (unsigned long)ax25);
46  setup_timer(&ax25->t2timer, ax25_t2timer_expiry, (unsigned long)ax25);
47  setup_timer(&ax25->t3timer, ax25_t3timer_expiry, (unsigned long)ax25);
48  setup_timer(&ax25->idletimer, ax25_idletimer_expiry,
49  (unsigned long)ax25);
50 }
51 
53 {
54  mod_timer(&ax25->timer, jiffies + 5 * HZ);
55 }
56 
58 {
59  mod_timer(&ax25->t1timer, jiffies + ax25->t1);
60 }
61 
63 {
64  mod_timer(&ax25->t2timer, jiffies + ax25->t2);
65 }
66 
68 {
69  if (ax25->t3 > 0)
70  mod_timer(&ax25->t3timer, jiffies + ax25->t3);
71  else
72  del_timer(&ax25->t3timer);
73 }
74 
76 {
77  if (ax25->idle > 0)
78  mod_timer(&ax25->idletimer, jiffies + ax25->idle);
79  else
80  del_timer(&ax25->idletimer);
81 }
82 
84 {
85  del_timer(&ax25->timer);
86 }
87 
89 {
90  del_timer(&ax25->t1timer);
91 }
92 
94 {
95  del_timer(&ax25->t2timer);
96 }
97 
99 {
100  del_timer(&ax25->t3timer);
101 }
102 
104 {
105  del_timer(&ax25->idletimer);
106 }
107 
109 {
110  return timer_pending(&ax25->t1timer);
111 }
112 
113 unsigned long ax25_display_timer(struct timer_list *timer)
114 {
115  if (!timer_pending(timer))
116  return 0;
117 
118  return timer->expires - jiffies;
119 }
120 
122 
123 static void ax25_heartbeat_expiry(unsigned long param)
124 {
126  ax25_cb *ax25 = (ax25_cb *)param;
127 
128  if (ax25->ax25_dev)
129  proto = ax25->ax25_dev->values[AX25_VALUES_PROTOCOL];
130 
131  switch (proto) {
135  break;
136 
137 #ifdef CONFIG_AX25_DAMA_SLAVE
138  case AX25_PROTO_DAMA_SLAVE:
139  if (ax25->ax25_dev->dama.slave)
141  else
143  break;
144 #endif
145  }
146 }
147 
148 static void ax25_t1timer_expiry(unsigned long param)
149 {
150  ax25_cb *ax25 = (ax25_cb *)param;
151 
152  switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
156  break;
157 
158 #ifdef CONFIG_AX25_DAMA_SLAVE
159  case AX25_PROTO_DAMA_SLAVE:
160  if (!ax25->ax25_dev->dama.slave)
162  break;
163 #endif
164  }
165 }
166 
167 static void ax25_t2timer_expiry(unsigned long param)
168 {
169  ax25_cb *ax25 = (ax25_cb *)param;
170 
171  switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
175  break;
176 
177 #ifdef CONFIG_AX25_DAMA_SLAVE
178  case AX25_PROTO_DAMA_SLAVE:
179  if (!ax25->ax25_dev->dama.slave)
181  break;
182 #endif
183  }
184 }
185 
186 static void ax25_t3timer_expiry(unsigned long param)
187 {
188  ax25_cb *ax25 = (ax25_cb *)param;
189 
190  switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
194  break;
195 
196 #ifdef CONFIG_AX25_DAMA_SLAVE
197  case AX25_PROTO_DAMA_SLAVE:
198  if (ax25->ax25_dev->dama.slave)
200  else
202  break;
203 #endif
204  }
205 }
206 
207 static void ax25_idletimer_expiry(unsigned long param)
208 {
209  ax25_cb *ax25 = (ax25_cb *)param;
210 
211  switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
215  break;
216 
217 #ifdef CONFIG_AX25_DAMA_SLAVE
218  case AX25_PROTO_DAMA_SLAVE:
219  if (ax25->ax25_dev->dama.slave)
221  else
223  break;
224 #endif
225  }
226 }