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/config.h>
26 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
31 #include <linux/kernel.h>
32 #include <linux/sched.h>
33 #include <linux/timer.h>
34 #include <linux/string.h>
35 #include <linux/sockios.h>
36 #include <linux/net.h>
38 #include <linux/inet.h>
39 #include <linux/netdevice.h>
40 #include <linux/skbuff.h>
42 #include <net/ip.h> /* For ip_rcv */
43 #include <asm/segment.h>
44 #include <asm/system.h>
45 #include <linux/fcntl.h>
47 #include <linux/interrupt.h>
51 * State machine for state 1, Awaiting Call Accepted State.
52 * The handling of the timer(s) is in file rose_timer.c.
53 * Handling of state 0 and connection release is in af_rose.c.
55 static int rose_state1_machine(struct sock
*sk
, struct sk_buff
*skb
, int frametype
)
59 case ROSE_CALL_ACCEPTED
:
61 rose_start_idletimer(sk
);
62 sk
->protinfo
.rose
->condition
= 0x00;
63 sk
->protinfo
.rose
->vs
= 0;
64 sk
->protinfo
.rose
->va
= 0;
65 sk
->protinfo
.rose
->vr
= 0;
66 sk
->protinfo
.rose
->vl
= 0;
67 sk
->protinfo
.rose
->state
= ROSE_STATE_3
;
68 sk
->state
= TCP_ESTABLISHED
;
73 case ROSE_CLEAR_REQUEST
:
74 rose_write_internal(sk
, ROSE_CLEAR_CONFIRMATION
);
75 rose_disconnect(sk
, ECONNREFUSED
, skb
->data
[3], skb
->data
[4]);
76 sk
->protinfo
.rose
->neighbour
->use
--;
87 * State machine for state 2, Awaiting Clear Confirmation State.
88 * The handling of the timer(s) is in file rose_timer.c
89 * Handling of state 0 and connection release is in af_rose.c.
91 static int rose_state2_machine(struct sock
*sk
, struct sk_buff
*skb
, int frametype
)
95 case ROSE_CLEAR_REQUEST
:
96 rose_write_internal(sk
, ROSE_CLEAR_CONFIRMATION
);
97 rose_disconnect(sk
, 0, skb
->data
[3], skb
->data
[4]);
98 sk
->protinfo
.rose
->neighbour
->use
--;
101 case ROSE_CLEAR_CONFIRMATION
:
102 rose_disconnect(sk
, 0, -1, -1);
103 sk
->protinfo
.rose
->neighbour
->use
--;
114 * State machine for state 3, Connected State.
115 * The handling of the timer(s) is in file rose_timer.c
116 * Handling of state 0 and connection release is in af_rose.c.
118 static int rose_state3_machine(struct sock
*sk
, struct sk_buff
*skb
, int frametype
, int ns
, int nr
, int q
, int d
, int m
)
124 case ROSE_RESET_REQUEST
:
126 rose_start_idletimer(sk
);
127 rose_write_internal(sk
, ROSE_RESET_CONFIRMATION
);
128 sk
->protinfo
.rose
->condition
= 0x00;
129 sk
->protinfo
.rose
->vs
= 0;
130 sk
->protinfo
.rose
->vr
= 0;
131 sk
->protinfo
.rose
->va
= 0;
132 sk
->protinfo
.rose
->vl
= 0;
133 rose_requeue_frames(sk
);
136 case ROSE_CLEAR_REQUEST
:
137 rose_write_internal(sk
, ROSE_CLEAR_CONFIRMATION
);
138 rose_disconnect(sk
, 0, skb
->data
[3], skb
->data
[4]);
139 sk
->protinfo
.rose
->neighbour
->use
--;
144 if (!rose_validate_nr(sk
, nr
)) {
145 rose_write_internal(sk
, ROSE_RESET_REQUEST
);
146 sk
->protinfo
.rose
->condition
= 0x00;
147 sk
->protinfo
.rose
->vs
= 0;
148 sk
->protinfo
.rose
->vr
= 0;
149 sk
->protinfo
.rose
->va
= 0;
150 sk
->protinfo
.rose
->vl
= 0;
151 sk
->protinfo
.rose
->state
= ROSE_STATE_4
;
152 rose_start_t2timer(sk
);
153 rose_stop_idletimer(sk
);
155 rose_frames_acked(sk
, nr
);
156 if (frametype
== ROSE_RNR
) {
157 sk
->protinfo
.rose
->condition
|= ROSE_COND_PEER_RX_BUSY
;
159 sk
->protinfo
.rose
->condition
&= ~ROSE_COND_PEER_RX_BUSY
;
164 case ROSE_DATA
: /* XXX */
165 sk
->protinfo
.rose
->condition
&= ~ROSE_COND_PEER_RX_BUSY
;
166 if (!rose_validate_nr(sk
, nr
)) {
167 rose_write_internal(sk
, ROSE_RESET_REQUEST
);
168 sk
->protinfo
.rose
->condition
= 0x00;
169 sk
->protinfo
.rose
->vs
= 0;
170 sk
->protinfo
.rose
->vr
= 0;
171 sk
->protinfo
.rose
->va
= 0;
172 sk
->protinfo
.rose
->vl
= 0;
173 sk
->protinfo
.rose
->state
= ROSE_STATE_4
;
174 rose_start_t2timer(sk
);
175 rose_stop_idletimer(sk
);
178 rose_frames_acked(sk
, nr
);
179 if (ns
== sk
->protinfo
.rose
->vr
) {
180 rose_start_idletimer(sk
);
181 if (sock_queue_rcv_skb(sk
, skb
) == 0) {
182 sk
->protinfo
.rose
->vr
= (sk
->protinfo
.rose
->vr
+ 1) % ROSE_MODULUS
;
185 /* Should never happen ! */
186 rose_write_internal(sk
, ROSE_RESET_REQUEST
);
187 sk
->protinfo
.rose
->condition
= 0x00;
188 sk
->protinfo
.rose
->vs
= 0;
189 sk
->protinfo
.rose
->vr
= 0;
190 sk
->protinfo
.rose
->va
= 0;
191 sk
->protinfo
.rose
->vl
= 0;
192 sk
->protinfo
.rose
->state
= ROSE_STATE_4
;
193 rose_start_t2timer(sk
);
194 rose_stop_idletimer(sk
);
197 if (atomic_read(&sk
->rmem_alloc
) > (sk
->rcvbuf
/ 2))
198 sk
->protinfo
.rose
->condition
|= ROSE_COND_OWN_RX_BUSY
;
201 * If the window is full, ack the frame, else start the
202 * acknowledge hold back timer.
204 if (((sk
->protinfo
.rose
->vl
+ sysctl_rose_window_size
) % ROSE_MODULUS
) == sk
->protinfo
.rose
->vr
) {
205 sk
->protinfo
.rose
->condition
&= ~ROSE_COND_ACK_PENDING
;
207 rose_enquiry_response(sk
);
209 sk
->protinfo
.rose
->condition
|= ROSE_COND_ACK_PENDING
;
210 rose_start_hbtimer(sk
);
215 printk(KERN_WARNING
"ROSE: unknown %02X in state 3\n", frametype
);
223 * State machine for state 4, Awaiting Reset Confirmation State.
224 * The handling of the timer(s) is in file rose_timer.c
225 * Handling of state 0 and connection release is in af_rose.c.
227 static int rose_state4_machine(struct sock
*sk
, struct sk_buff
*skb
, int frametype
)
231 case ROSE_RESET_REQUEST
:
232 rose_write_internal(sk
, ROSE_RESET_CONFIRMATION
);
233 case ROSE_RESET_CONFIRMATION
:
235 rose_start_idletimer(sk
);
236 sk
->protinfo
.rose
->condition
= 0x00;
237 sk
->protinfo
.rose
->va
= 0;
238 sk
->protinfo
.rose
->vr
= 0;
239 sk
->protinfo
.rose
->vs
= 0;
240 sk
->protinfo
.rose
->vl
= 0;
241 sk
->protinfo
.rose
->state
= ROSE_STATE_3
;
242 rose_requeue_frames(sk
);
245 case ROSE_CLEAR_REQUEST
:
246 rose_write_internal(sk
, ROSE_CLEAR_CONFIRMATION
);
247 rose_disconnect(sk
, 0, skb
->data
[3], skb
->data
[4]);
248 sk
->protinfo
.rose
->neighbour
->use
--;
259 * State machine for state 5, Awaiting Call Acceptance State.
260 * The handling of the timer(s) is in file rose_timer.c
261 * Handling of state 0 and connection release is in af_rose.c.
263 static int rose_state5_machine(struct sock
*sk
, struct sk_buff
*skb
, int frametype
)
265 if (frametype
== ROSE_CLEAR_REQUEST
) {
266 rose_write_internal(sk
, ROSE_CLEAR_CONFIRMATION
);
267 rose_disconnect(sk
, 0, skb
->data
[3], skb
->data
[4]);
268 sk
->protinfo
.rose
->neighbour
->use
--;
274 /* Higher level upcall for a LAPB frame */
275 int rose_process_rx_frame(struct sock
*sk
, struct sk_buff
*skb
)
277 int queued
= 0, frametype
, ns
, nr
, q
, d
, m
;
279 if (sk
->protinfo
.rose
->state
== ROSE_STATE_0
)
282 frametype
= rose_decode(skb
, &ns
, &nr
, &q
, &d
, &m
);
284 switch (sk
->protinfo
.rose
->state
) {
286 queued
= rose_state1_machine(sk
, skb
, frametype
);
289 queued
= rose_state2_machine(sk
, skb
, frametype
);
292 queued
= rose_state3_machine(sk
, skb
, frametype
, ns
, nr
, q
, d
, m
);
295 queued
= rose_state4_machine(sk
, skb
, frametype
);
298 queued
= rose_state5_machine(sk
, skb
, frametype
);