1
2
3
4
5
6
7
8
9
10#include <linux/errno.h>
11#include <linux/types.h>
12#include <linux/socket.h>
13#include <linux/in.h>
14#include <linux/kernel.h>
15#include <linux/timer.h>
16#include <linux/string.h>
17#include <linux/sockios.h>
18#include <linux/spinlock.h>
19#include <linux/net.h>
20#include <linux/gfp.h>
21#include <net/ax25.h>
22#include <linux/inet.h>
23#include <linux/netdevice.h>
24#include <linux/skbuff.h>
25#include <net/sock.h>
26#include <asm/uaccess.h>
27#include <linux/fcntl.h>
28#include <linux/mm.h>
29#include <linux/interrupt.h>
30
31void ax25_ds_nr_error_recovery(ax25_cb *ax25)
32{
33 ax25_ds_establish_data_link(ax25);
34}
35
36
37
38
39void ax25_ds_enquiry_response(ax25_cb *ax25)
40{
41 ax25_cb *ax25o;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 ax25_std_enquiry_response(ax25);
67
68 if (!(ax25->condition & AX25_COND_PEER_RX_BUSY)) {
69 ax25_requeue_frames(ax25);
70 ax25_kick(ax25);
71 }
72
73 if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 || skb_peek(&ax25->ack_queue) != NULL)
74 ax25_ds_t1_timeout(ax25);
75 else
76 ax25->n2count = 0;
77
78 ax25_start_t3timer(ax25);
79 ax25_ds_set_timer(ax25->ax25_dev);
80
81 spin_lock(&ax25_list_lock);
82 ax25_for_each(ax25o, &ax25_list) {
83 if (ax25o == ax25)
84 continue;
85
86 if (ax25o->ax25_dev != ax25->ax25_dev)
87 continue;
88
89 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2) {
90 ax25_ds_t1_timeout(ax25o);
91 continue;
92 }
93
94 if (!(ax25o->condition & AX25_COND_PEER_RX_BUSY) && ax25o->state == AX25_STATE_3) {
95 ax25_requeue_frames(ax25o);
96 ax25_kick(ax25o);
97 }
98
99 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 || skb_peek(&ax25o->ack_queue) != NULL)
100 ax25_ds_t1_timeout(ax25o);
101
102
103
104 if (ax25o->state != AX25_STATE_0)
105 ax25_start_t3timer(ax25o);
106 }
107 spin_unlock(&ax25_list_lock);
108}
109
110void ax25_ds_establish_data_link(ax25_cb *ax25)
111{
112 ax25->condition &= AX25_COND_DAMA_MODE;
113 ax25->n2count = 0;
114 ax25_calculate_t1(ax25);
115 ax25_start_t1timer(ax25);
116 ax25_stop_t2timer(ax25);
117 ax25_start_t3timer(ax25);
118}
119
120
121
122
123
124
125
126
127static void ax25_kiss_cmd(ax25_dev *ax25_dev, unsigned char cmd, unsigned char param)
128{
129 struct sk_buff *skb;
130 unsigned char *p;
131
132 if (ax25_dev->dev == NULL)
133 return;
134
135 if ((skb = alloc_skb(2, GFP_ATOMIC)) == NULL)
136 return;
137
138 skb_reset_network_header(skb);
139 p = skb_put(skb, 2);
140
141 *p++ = cmd;
142 *p++ = param;
143
144 skb->protocol = ax25_type_trans(skb, ax25_dev->dev);
145
146 dev_queue_xmit(skb);
147}
148
149
150
151
152
153
154
155
156
157static int ax25_check_dama_slave(ax25_dev *ax25_dev)
158{
159 ax25_cb *ax25;
160 int res = 0;
161
162 spin_lock(&ax25_list_lock);
163 ax25_for_each(ax25, &ax25_list)
164 if (ax25->ax25_dev == ax25_dev && (ax25->condition & AX25_COND_DAMA_MODE) && ax25->state > AX25_STATE_1) {
165 res = 1;
166 break;
167 }
168 spin_unlock(&ax25_list_lock);
169
170 return res;
171}
172
173static void ax25_dev_dama_on(ax25_dev *ax25_dev)
174{
175 if (ax25_dev == NULL)
176 return;
177
178 if (ax25_dev->dama.slave == 0)
179 ax25_kiss_cmd(ax25_dev, 5, 1);
180
181 ax25_dev->dama.slave = 1;
182 ax25_ds_set_timer(ax25_dev);
183}
184
185void ax25_dev_dama_off(ax25_dev *ax25_dev)
186{
187 if (ax25_dev == NULL)
188 return;
189
190 if (ax25_dev->dama.slave && !ax25_check_dama_slave(ax25_dev)) {
191 ax25_kiss_cmd(ax25_dev, 5, 0);
192 ax25_dev->dama.slave = 0;
193 ax25_ds_del_timer(ax25_dev);
194 }
195}
196
197void ax25_dama_on(ax25_cb *ax25)
198{
199 ax25_dev_dama_on(ax25->ax25_dev);
200 ax25->condition |= AX25_COND_DAMA_MODE;
201}
202
203void ax25_dama_off(ax25_cb *ax25)
204{
205 ax25->condition &= ~AX25_COND_DAMA_MODE;
206 ax25_dev_dama_off(ax25->ax25_dev);
207}
208
209