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