1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
5 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
7 #include <linux/errno.h>
8 #include <linux/types.h>
9 #include <linux/socket.h>
11 #include <linux/kernel.h>
12 #include <linux/timer.h>
13 #include <linux/string.h>
14 #include <linux/sockios.h>
15 #include <linux/spinlock.h>
16 #include <linux/net.h>
17 #include <linux/gfp.h>
19 #include <linux/inet.h>
20 #include <linux/netdevice.h>
21 #include <linux/skbuff.h>
23 #include <linux/uaccess.h>
24 #include <linux/fcntl.h>
26 #include <linux/interrupt.h>
28 void ax25_ds_nr_error_recovery(ax25_cb *ax25)
30 ax25_ds_establish_data_link(ax25);
34 * dl1bke 960114: transmit I frames on DAMA poll
36 void ax25_ds_enquiry_response(ax25_cb *ax25)
40 /* Please note that neither DK4EG's nor DG2FEF's
41 * DAMA spec mention the following behaviour as seen
44 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
45 * DL1BKE->DB0ACH <I NR=0 NS=0>
46 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
47 * DL1BKE->DB0ACH <RR R F R0>
49 * The Flexnet DAMA Master implementation apparently
50 * insists on the "proper" AX.25 behaviour:
52 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
53 * DL1BKE->DB0ACH <RR R F R0>
54 * DL1BKE->DB0ACH <I NR=0 NS=0>
55 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
57 * Flexnet refuses to send us *any* I frame if we send
58 * a REJ in case AX25_COND_REJECT is set. It is superfluous in
59 * this mode anyway (a RR or RNR invokes the retransmission).
60 * Is this a Flexnet bug?
63 ax25_std_enquiry_response(ax25);
65 if (!(ax25->condition & AX25_COND_PEER_RX_BUSY)) {
66 ax25_requeue_frames(ax25);
70 if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 || skb_peek(&ax25->ack_queue) != NULL)
71 ax25_ds_t1_timeout(ax25);
75 ax25_start_t3timer(ax25);
76 ax25_ds_set_timer(ax25->ax25_dev);
78 spin_lock(&ax25_list_lock);
79 ax25_for_each(ax25o, &ax25_list) {
83 if (ax25o->ax25_dev != ax25->ax25_dev)
86 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2) {
87 ax25_ds_t1_timeout(ax25o);
91 if (!(ax25o->condition & AX25_COND_PEER_RX_BUSY) && ax25o->state == AX25_STATE_3) {
92 ax25_requeue_frames(ax25o);
96 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 || skb_peek(&ax25o->ack_queue) != NULL)
97 ax25_ds_t1_timeout(ax25o);
99 /* do not start T3 for listening sockets (tnx DD8NE) */
101 if (ax25o->state != AX25_STATE_0)
102 ax25_start_t3timer(ax25o);
104 spin_unlock(&ax25_list_lock);
107 void ax25_ds_establish_data_link(ax25_cb *ax25)
109 ax25->condition &= AX25_COND_DAMA_MODE;
111 ax25_calculate_t1(ax25);
112 ax25_start_t1timer(ax25);
113 ax25_stop_t2timer(ax25);
114 ax25_start_t3timer(ax25);
119 * This is a kludge. Not all drivers recognize kiss commands.
120 * We need a driver level request to switch duplex mode, that does
121 * either SCC changing, PI config or KISS as required. Currently
122 * this request isn't reliable.
124 static void ax25_kiss_cmd(ax25_dev *ax25_dev, unsigned char cmd, unsigned char param)
129 if (ax25_dev->dev == NULL)
132 if ((skb = alloc_skb(2, GFP_ATOMIC)) == NULL)
135 skb_reset_network_header(skb);
141 skb->protocol = ax25_type_trans(skb, ax25_dev->dev);
147 * A nasty problem arises if we count the number of DAMA connections
148 * wrong, especially when connections on the device already existed
149 * and our network node (or the sysop) decides to turn on DAMA Master
150 * mode. We thus flag the 'real' slave connections with
151 * ax25->dama_slave=1 and look on every disconnect if still slave
154 static int ax25_check_dama_slave(ax25_dev *ax25_dev)
159 spin_lock(&ax25_list_lock);
160 ax25_for_each(ax25, &ax25_list)
161 if (ax25->ax25_dev == ax25_dev && (ax25->condition & AX25_COND_DAMA_MODE) && ax25->state > AX25_STATE_1) {
165 spin_unlock(&ax25_list_lock);
170 static void ax25_dev_dama_on(ax25_dev *ax25_dev)
172 if (ax25_dev == NULL)
175 if (ax25_dev->dama.slave == 0)
176 ax25_kiss_cmd(ax25_dev, 5, 1);
178 ax25_dev->dama.slave = 1;
179 ax25_ds_set_timer(ax25_dev);
182 void ax25_dev_dama_off(ax25_dev *ax25_dev)
184 if (ax25_dev == NULL)
187 if (ax25_dev->dama.slave && !ax25_check_dama_slave(ax25_dev)) {
188 ax25_kiss_cmd(ax25_dev, 5, 0);
189 ax25_dev->dama.slave = 0;
190 ax25_ds_del_timer(ax25_dev);
194 void ax25_dama_on(ax25_cb *ax25)
196 ax25_dev_dama_on(ax25->ax25_dev);
197 ax25->condition |= AX25_COND_DAMA_MODE;
200 void ax25_dama_off(ax25_cb *ax25)
202 ax25->condition &= ~AX25_COND_DAMA_MODE;
203 ax25_dev_dama_off(ax25->ax25_dev);