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 * ROSE 001 Jonathan(G4KLX) Cloned from nr_in.c
20 * ROSE 002 Jonathan(G4KLX) Return cause and diagnostic codes from Clear Requests.
21 * ROSE 003 Jonathan(G4KLX) New timer architecture.
22 * Removed M bit processing.
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 <net/ip.h> /* For ip_rcv */
41 #include <asm/segment.h>
42 #include <asm/system.h>
43 #include <linux/fcntl.h>
45 #include <linux/interrupt.h>
49 * State machine for state 1, Awaiting Call Accepted State.
50 * The handling of the timer(s) is in file rose_timer.c.
51 * Handling of state 0 and connection release is in af_rose.c.
53 static int rose_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype)
57 case ROSE_CALL_ACCEPTED:
59 rose_start_idletimer(sk);
60 sk->protinfo.rose->condition = 0x00;
61 sk->protinfo.rose->vs = 0;
62 sk->protinfo.rose->va = 0;
63 sk->protinfo.rose->vr = 0;
64 sk->protinfo.rose->vl = 0;
65 sk->protinfo.rose->state = ROSE_STATE_3;
66 sk->state = TCP_ESTABLISHED;
71 case ROSE_CLEAR_REQUEST:
72 rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
73 rose_disconnect(sk, ECONNREFUSED, skb->data[3], skb->data[4]);
74 sk->protinfo.rose->neighbour->use--;
85 * State machine for state 2, Awaiting Clear Confirmation State.
86 * The handling of the timer(s) is in file rose_timer.c
87 * Handling of state 0 and connection release is in af_rose.c.
89 static int rose_state2_machine(struct sock *sk, struct sk_buff *skb, int frametype)
93 case ROSE_CLEAR_REQUEST:
94 rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
95 rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
96 sk->protinfo.rose->neighbour->use--;
99 case ROSE_CLEAR_CONFIRMATION:
100 rose_disconnect(sk, 0, -1, -1);
101 sk->protinfo.rose->neighbour->use--;
112 * State machine for state 3, Connected State.
113 * The handling of the timer(s) is in file rose_timer.c
114 * Handling of state 0 and connection release is in af_rose.c.
116 static int rose_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype, int ns, int nr, int q, int d, int m)
122 case ROSE_RESET_REQUEST:
124 rose_start_idletimer(sk);
125 rose_write_internal(sk, ROSE_RESET_CONFIRMATION);
126 sk->protinfo.rose->condition = 0x00;
127 sk->protinfo.rose->vs = 0;
128 sk->protinfo.rose->vr = 0;
129 sk->protinfo.rose->va = 0;
130 sk->protinfo.rose->vl = 0;
131 rose_requeue_frames(sk);
134 case ROSE_CLEAR_REQUEST:
135 rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
136 rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
137 sk->protinfo.rose->neighbour->use--;
142 if (!rose_validate_nr(sk, nr)) {
143 rose_write_internal(sk, ROSE_RESET_REQUEST);
144 sk->protinfo.rose->condition = 0x00;
145 sk->protinfo.rose->vs = 0;
146 sk->protinfo.rose->vr = 0;
147 sk->protinfo.rose->va = 0;
148 sk->protinfo.rose->vl = 0;
149 sk->protinfo.rose->state = ROSE_STATE_4;
150 rose_start_t2timer(sk);
151 rose_stop_idletimer(sk);
153 rose_frames_acked(sk, nr);
154 if (frametype == ROSE_RNR) {
155 sk->protinfo.rose->condition |= ROSE_COND_PEER_RX_BUSY;
157 sk->protinfo.rose->condition &= ~ROSE_COND_PEER_RX_BUSY;
162 case ROSE_DATA: /* XXX */
163 sk->protinfo.rose->condition &= ~ROSE_COND_PEER_RX_BUSY;
164 if (!rose_validate_nr(sk, nr)) {
165 rose_write_internal(sk, ROSE_RESET_REQUEST);
166 sk->protinfo.rose->condition = 0x00;
167 sk->protinfo.rose->vs = 0;
168 sk->protinfo.rose->vr = 0;
169 sk->protinfo.rose->va = 0;
170 sk->protinfo.rose->vl = 0;
171 sk->protinfo.rose->state = ROSE_STATE_4;
172 rose_start_t2timer(sk);
173 rose_stop_idletimer(sk);
176 rose_frames_acked(sk, nr);
177 if (ns == sk->protinfo.rose->vr) {
178 rose_start_idletimer(sk);
179 if (sock_queue_rcv_skb(sk, skb) == 0) {
180 sk->protinfo.rose->vr = (sk->protinfo.rose->vr + 1) % ROSE_MODULUS;
183 /* Should never happen ! */
184 rose_write_internal(sk, ROSE_RESET_REQUEST);
185 sk->protinfo.rose->condition = 0x00;
186 sk->protinfo.rose->vs = 0;
187 sk->protinfo.rose->vr = 0;
188 sk->protinfo.rose->va = 0;
189 sk->protinfo.rose->vl = 0;
190 sk->protinfo.rose->state = ROSE_STATE_4;
191 rose_start_t2timer(sk);
192 rose_stop_idletimer(sk);
195 if (atomic_read(&sk->rmem_alloc) > (sk->rcvbuf / 2))
196 sk->protinfo.rose->condition |= ROSE_COND_OWN_RX_BUSY;
199 * If the window is full, ack the frame, else start the
200 * acknowledge hold back timer.
202 if (((sk->protinfo.rose->vl + sysctl_rose_window_size) % ROSE_MODULUS) == sk->protinfo.rose->vr) {
203 sk->protinfo.rose->condition &= ~ROSE_COND_ACK_PENDING;
205 rose_enquiry_response(sk);
207 sk->protinfo.rose->condition |= ROSE_COND_ACK_PENDING;
208 rose_start_hbtimer(sk);
213 printk(KERN_WARNING "ROSE: unknown %02X in state 3\n", frametype);
221 * State machine for state 4, Awaiting Reset Confirmation State.
222 * The handling of the timer(s) is in file rose_timer.c
223 * Handling of state 0 and connection release is in af_rose.c.
225 static int rose_state4_machine(struct sock *sk, struct sk_buff *skb, int frametype)
229 case ROSE_RESET_REQUEST:
230 rose_write_internal(sk, ROSE_RESET_CONFIRMATION);
231 case ROSE_RESET_CONFIRMATION:
233 rose_start_idletimer(sk);
234 sk->protinfo.rose->condition = 0x00;
235 sk->protinfo.rose->va = 0;
236 sk->protinfo.rose->vr = 0;
237 sk->protinfo.rose->vs = 0;
238 sk->protinfo.rose->vl = 0;
239 sk->protinfo.rose->state = ROSE_STATE_3;
240 rose_requeue_frames(sk);
243 case ROSE_CLEAR_REQUEST:
244 rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
245 rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
246 sk->protinfo.rose->neighbour->use--;
257 * State machine for state 5, Awaiting Call Acceptance State.
258 * The handling of the timer(s) is in file rose_timer.c
259 * Handling of state 0 and connection release is in af_rose.c.
261 static int rose_state5_machine(struct sock *sk, struct sk_buff *skb, int frametype)
263 if (frametype == ROSE_CLEAR_REQUEST) {
264 rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
265 rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
266 sk->protinfo.rose->neighbour->use--;
272 /* Higher level upcall for a LAPB frame */
273 int rose_process_rx_frame(struct sock *sk, struct sk_buff *skb)
275 int queued = 0, frametype, ns, nr, q, d, m;
277 if (sk->protinfo.rose->state == ROSE_STATE_0)
280 frametype = rose_decode(skb, &ns, &nr, &q, &d, &m);
282 switch (sk->protinfo.rose->state) {
284 queued = rose_state1_machine(sk, skb, frametype);
287 queued = rose_state2_machine(sk, skb, frametype);
290 queued = rose_state3_machine(sk, skb, frametype, ns, nr, q, d, m);
293 queued = rose_state4_machine(sk, skb, frametype);
296 queued = rose_state5_machine(sk, skb, frametype);