4 * This code REQUIRES 2.1.15 or higher/ NET3.038
7 * This module is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Most of this code is based on the SDL diagrams published in the 7th
13 * ARRL Computer Networking Conference papers. The diagrams have mistakes
14 * in them, but are mostly correct. Before you modify the code could you
15 * read the SDL diagrams as the code is not obvious and probably very
19 * AX.25 036 Jonathan(G4KLX) Cloned from ax25_out.c and ax25_subr.c.
20 * Joerg(DL1BKE) Changed ax25_ds_enquiry_response(),
21 * fixed ax25_dama_on() and ax25_dama_off().
22 * AX.25 037 Jonathan(G4KLX) New timer architecture.
25 #include <linux/errno.h>
26 #include <linux/types.h>
27 #include <linux/socket.h>
29 #include <linux/kernel.h>
30 #include <linux/sched.h>
31 #include <linux/timer.h>
32 #include <linux/string.h>
33 #include <linux/sockios.h>
34 #include <linux/net.h>
36 #include <linux/inet.h>
37 #include <linux/netdevice.h>
38 #include <linux/skbuff.h>
40 #include <asm/uaccess.h>
41 #include <asm/system.h>
42 #include <linux/fcntl.h>
44 #include <linux/interrupt.h>
46 void ax25_ds_nr_error_recovery(ax25_cb *ax25)
48 ax25_ds_establish_data_link(ax25);
52 * dl1bke 960114: transmit I frames on DAMA poll
54 void ax25_ds_enquiry_response(ax25_cb *ax25)
58 /* Please note that neither DK4EG´s nor DG2FEF´s
59 * DAMA spec mention the following behaviour as seen
62 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
63 * DL1BKE->DB0ACH <I NR=0 NS=0>
64 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
65 * DL1BKE->DB0ACH <RR R F R0>
67 * The Flexnet DAMA Master implementation apparently
68 * insists on the "proper" AX.25 behaviour:
70 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
71 * DL1BKE->DB0ACH <RR R F R0>
72 * DL1BKE->DB0ACH <I NR=0 NS=0>
73 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
75 * Flexnet refuses to send us *any* I frame if we send
76 * a REJ in case AX25_COND_REJECT is set. It is superfluous in
77 * this mode anyway (a RR or RNR invokes the retransmission).
78 * Is this a Flexnet bug?
81 ax25_std_enquiry_response(ax25);
83 if (!(ax25->condition & AX25_COND_PEER_RX_BUSY)) {
84 ax25_requeue_frames(ax25);
88 if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 || skb_peek(&ax25->ack_queue) != NULL)
89 ax25_ds_t1_timeout(ax25);
93 ax25_start_t3timer(ax25);
94 ax25_ds_set_timer(ax25->ax25_dev);
96 for (ax25o = ax25_list; ax25o != NULL; ax25o = ax25o->next) {
100 if (ax25o->ax25_dev != ax25->ax25_dev)
103 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2) {
104 ax25_ds_t1_timeout(ax25o);
108 if (!(ax25o->condition & AX25_COND_PEER_RX_BUSY) && ax25o->state == AX25_STATE_3) {
109 ax25_requeue_frames(ax25o);
113 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 || skb_peek(&ax25o->ack_queue) != NULL)
114 ax25_ds_t1_timeout(ax25o);
116 /* do not start T3 for listening sockets (tnx DD8NE) */
118 if (ax25o->state != AX25_STATE_0)
119 ax25_start_t3timer(ax25o);
123 void ax25_ds_establish_data_link(ax25_cb *ax25)
125 ax25->condition &= AX25_COND_DAMA_MODE;
127 ax25_calculate_t1(ax25);
128 ax25_start_t1timer(ax25);
129 ax25_stop_t2timer(ax25);
130 ax25_start_t3timer(ax25);
135 * This is a kludge. Not all drivers recognize kiss commands.
136 * We need a driver level request to switch duplex mode, that does
137 * either SCC changing, PI config or KISS as required. Currently
138 * this request isn't reliable.
140 static void ax25_kiss_cmd(ax25_dev *ax25_dev, unsigned char cmd, unsigned char param)
145 if (ax25_dev->dev == NULL)
148 if ((skb = alloc_skb(2, GFP_ATOMIC)) == NULL)
151 skb->nh.raw = skb->data;
157 skb->dev = ax25_dev->dev;
158 skb->protocol = htons(ETH_P_AX25);
164 * A nasty problem arises if we count the number of DAMA connections
165 * wrong, especially when connections on the device already existed
166 * and our network node (or the sysop) decides to turn on DAMA Master
167 * mode. We thus flag the 'real' slave connections with
168 * ax25->dama_slave=1 and look on every disconnect if still slave
171 static int ax25_check_dama_slave(ax25_dev *ax25_dev)
175 for (ax25 = ax25_list; ax25 != NULL ; ax25 = ax25->next)
176 if (ax25->ax25_dev == ax25_dev && (ax25->condition & AX25_COND_DAMA_MODE) && ax25->state > AX25_STATE_1)
182 void ax25_dev_dama_on(ax25_dev *ax25_dev)
184 if (ax25_dev == NULL)
187 if (ax25_dev->dama.slave == 0)
188 ax25_kiss_cmd(ax25_dev, 5, 1);
190 ax25_dev->dama.slave = 1;
191 ax25_ds_set_timer(ax25_dev);
194 void ax25_dev_dama_off(ax25_dev *ax25_dev)
196 if (ax25_dev == NULL)
199 if (ax25_dev->dama.slave && !ax25_check_dama_slave(ax25_dev)) {
200 ax25_kiss_cmd(ax25_dev, 5, 0);
201 ax25_dev->dama.slave = 0;
202 ax25_ds_del_timer(ax25_dev);
206 void ax25_dama_on(ax25_cb *ax25)
208 ax25_dev_dama_on(ax25->ax25_dev);
209 ax25->condition |= AX25_COND_DAMA_MODE;
212 void ax25_dama_off(ax25_cb *ax25)
214 ax25->condition &= ~AX25_COND_DAMA_MODE;
215 ax25_dev_dama_off(ax25->ax25_dev);