Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ax25 / ax25_ds_subr.c
blob10ffd2beba3f861a4ca8800f1e61faa9f3a983d4
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.
7 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
8 * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
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/sched.h>
16 #include <linux/timer.h>
17 #include <linux/string.h>
18 #include <linux/sockios.h>
19 #include <linux/spinlock.h>
20 #include <linux/net.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 <asm/system.h>
28 #include <linux/fcntl.h>
29 #include <linux/mm.h>
30 #include <linux/interrupt.h>
32 void ax25_ds_nr_error_recovery(ax25_cb *ax25)
34 ax25_ds_establish_data_link(ax25);
38 * dl1bke 960114: transmit I frames on DAMA poll
40 void ax25_ds_enquiry_response(ax25_cb *ax25)
42 ax25_cb *ax25o;
43 struct hlist_node *node;
45 /* Please note that neither DK4EG´s nor DG2FEF´s
46 * DAMA spec mention the following behaviour as seen
47 * with TheFirmware:
49 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
50 * DL1BKE->DB0ACH <I NR=0 NS=0>
51 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
52 * DL1BKE->DB0ACH <RR R F R0>
54 * The Flexnet DAMA Master implementation apparently
55 * insists on the "proper" AX.25 behaviour:
57 * DB0ACH->DL1BKE <RR C P R0> [DAMA]
58 * DL1BKE->DB0ACH <RR R F R0>
59 * DL1BKE->DB0ACH <I NR=0 NS=0>
60 * DL1BKE-7->DB0PRA-6 DB0ACH <I C S3 R5>
62 * Flexnet refuses to send us *any* I frame if we send
63 * a REJ in case AX25_COND_REJECT is set. It is superfluous in
64 * this mode anyway (a RR or RNR invokes the retransmission).
65 * Is this a Flexnet bug?
68 ax25_std_enquiry_response(ax25);
70 if (!(ax25->condition & AX25_COND_PEER_RX_BUSY)) {
71 ax25_requeue_frames(ax25);
72 ax25_kick(ax25);
75 if (ax25->state == AX25_STATE_1 || ax25->state == AX25_STATE_2 || skb_peek(&ax25->ack_queue) != NULL)
76 ax25_ds_t1_timeout(ax25);
77 else
78 ax25->n2count = 0;
80 ax25_start_t3timer(ax25);
81 ax25_ds_set_timer(ax25->ax25_dev);
83 spin_lock_bh(&ax25_list_lock);
84 ax25_for_each(ax25o, node, &ax25_list) {
85 if (ax25o == ax25)
86 continue;
88 if (ax25o->ax25_dev != ax25->ax25_dev)
89 continue;
91 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2) {
92 ax25_ds_t1_timeout(ax25o);
93 continue;
96 if (!(ax25o->condition & AX25_COND_PEER_RX_BUSY) && ax25o->state == AX25_STATE_3) {
97 ax25_requeue_frames(ax25o);
98 ax25_kick(ax25o);
101 if (ax25o->state == AX25_STATE_1 || ax25o->state == AX25_STATE_2 || skb_peek(&ax25o->ack_queue) != NULL)
102 ax25_ds_t1_timeout(ax25o);
104 /* do not start T3 for listening sockets (tnx DD8NE) */
106 if (ax25o->state != AX25_STATE_0)
107 ax25_start_t3timer(ax25o);
109 spin_unlock_bh(&ax25_list_lock);
112 void ax25_ds_establish_data_link(ax25_cb *ax25)
114 ax25->condition &= AX25_COND_DAMA_MODE;
115 ax25->n2count = 0;
116 ax25_calculate_t1(ax25);
117 ax25_start_t1timer(ax25);
118 ax25_stop_t2timer(ax25);
119 ax25_start_t3timer(ax25);
123 * :::FIXME:::
124 * This is a kludge. Not all drivers recognize kiss commands.
125 * We need a driver level request to switch duplex mode, that does
126 * either SCC changing, PI config or KISS as required. Currently
127 * this request isn't reliable.
129 static void ax25_kiss_cmd(ax25_dev *ax25_dev, unsigned char cmd, unsigned char param)
131 struct sk_buff *skb;
132 unsigned char *p;
134 if (ax25_dev->dev == NULL)
135 return;
137 if ((skb = alloc_skb(2, GFP_ATOMIC)) == NULL)
138 return;
140 skb->nh.raw = skb->data;
141 p = skb_put(skb, 2);
143 *p++ = cmd;
144 *p++ = param;
146 skb->dev = ax25_dev->dev;
147 skb->protocol = htons(ETH_P_AX25);
149 dev_queue_xmit(skb);
153 * A nasty problem arises if we count the number of DAMA connections
154 * wrong, especially when connections on the device already existed
155 * and our network node (or the sysop) decides to turn on DAMA Master
156 * mode. We thus flag the 'real' slave connections with
157 * ax25->dama_slave=1 and look on every disconnect if still slave
158 * connections exist.
160 static int ax25_check_dama_slave(ax25_dev *ax25_dev)
162 ax25_cb *ax25;
163 int res = 0;
164 struct hlist_node *node;
166 spin_lock_bh(&ax25_list_lock);
167 ax25_for_each(ax25, node, &ax25_list)
168 if (ax25->ax25_dev == ax25_dev && (ax25->condition & AX25_COND_DAMA_MODE) && ax25->state > AX25_STATE_1) {
169 res = 1;
170 break;
172 spin_unlock_bh(&ax25_list_lock);
174 return res;
177 static void ax25_dev_dama_on(ax25_dev *ax25_dev)
179 if (ax25_dev == NULL)
180 return;
182 if (ax25_dev->dama.slave == 0)
183 ax25_kiss_cmd(ax25_dev, 5, 1);
185 ax25_dev->dama.slave = 1;
186 ax25_ds_set_timer(ax25_dev);
189 void ax25_dev_dama_off(ax25_dev *ax25_dev)
191 if (ax25_dev == NULL)
192 return;
194 if (ax25_dev->dama.slave && !ax25_check_dama_slave(ax25_dev)) {
195 ax25_kiss_cmd(ax25_dev, 5, 0);
196 ax25_dev->dama.slave = 0;
197 ax25_ds_del_timer(ax25_dev);
201 void ax25_dama_on(ax25_cb *ax25)
203 ax25_dev_dama_on(ax25->ax25_dev);
204 ax25->condition |= AX25_COND_DAMA_MODE;
207 void ax25_dama_off(ax25_cb *ax25)
209 ax25->condition &= ~AX25_COND_DAMA_MODE;
210 ax25_dev_dama_off(ax25->ax25_dev);