* better
[mascara-docs.git] / i386 / linux-2.3.21 / net / rose / rose_out.c
blobaea1d9f68efab971d4a51d7c97c859ddfcf9412b
1 /*
2 * ROSE release 003
4 * This code REQUIRES 2.1.15 or higher/ NET3.038
6 * This module:
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 * History
13 * ROSE 001 Jonathan(G4KLX) Cloned from nr_out.c
14 * ROSE 003 Jonathan(G4KLX) New timer architecture.
15 * Removed M bit processing.
18 #include <linux/config.h>
19 #if defined(CONFIG_ROSE) || defined(CONFIG_ROSE_MODULE)
20 #include <linux/errno.h>
21 #include <linux/types.h>
22 #include <linux/socket.h>
23 #include <linux/in.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/string.h>
28 #include <linux/sockios.h>
29 #include <linux/net.h>
30 #include <net/ax25.h>
31 #include <linux/inet.h>
32 #include <linux/netdevice.h>
33 #include <linux/skbuff.h>
34 #include <net/sock.h>
35 #include <asm/segment.h>
36 #include <asm/system.h>
37 #include <linux/fcntl.h>
38 #include <linux/mm.h>
39 #include <linux/interrupt.h>
40 #include <net/rose.h>
42 /*
43 * This procedure is passed a buffer descriptor for an iframe. It builds
44 * the rest of the control part of the frame and then writes it out.
46 static void rose_send_iframe(struct sock *sk, struct sk_buff *skb)
48 if (skb == NULL)
49 return;
51 skb->data[2] |= (sk->protinfo.rose->vr << 5) & 0xE0;
52 skb->data[2] |= (sk->protinfo.rose->vs << 1) & 0x0E;
54 rose_start_idletimer(sk);
56 rose_transmit_link(skb, sk->protinfo.rose->neighbour);
59 void rose_kick(struct sock *sk)
61 struct sk_buff *skb, *skbn;
62 unsigned short start, end;
64 if (sk->protinfo.rose->state != ROSE_STATE_3)
65 return;
67 if (sk->protinfo.rose->condition & ROSE_COND_PEER_RX_BUSY)
68 return;
70 if (skb_peek(&sk->write_queue) == NULL)
71 return;
73 start = (skb_peek(&sk->protinfo.rose->ack_queue) == NULL) ? sk->protinfo.rose->va : sk->protinfo.rose->vs;
74 end = (sk->protinfo.rose->va + sysctl_rose_window_size) % ROSE_MODULUS;
76 if (start == end)
77 return;
79 sk->protinfo.rose->vs = start;
82 * Transmit data until either we're out of data to send or
83 * the window is full.
86 skb = skb_dequeue(&sk->write_queue);
88 do {
89 if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
90 skb_queue_head(&sk->write_queue, skb);
91 break;
94 skb_set_owner_w(skbn, sk);
97 * Transmit the frame copy.
99 rose_send_iframe(sk, skbn);
101 sk->protinfo.rose->vs = (sk->protinfo.rose->vs + 1) % ROSE_MODULUS;
104 * Requeue the original data frame.
106 skb_queue_tail(&sk->protinfo.rose->ack_queue, skb);
108 } while (sk->protinfo.rose->vs != end && (skb = skb_dequeue(&sk->write_queue)) != NULL);
110 sk->protinfo.rose->vl = sk->protinfo.rose->vr;
111 sk->protinfo.rose->condition &= ~ROSE_COND_ACK_PENDING;
113 rose_stop_timer(sk);
117 * The following routines are taken from page 170 of the 7th ARRL Computer
118 * Networking Conference paper, as is the whole state machine.
121 void rose_enquiry_response(struct sock *sk)
123 if (sk->protinfo.rose->condition & ROSE_COND_OWN_RX_BUSY)
124 rose_write_internal(sk, ROSE_RNR);
125 else
126 rose_write_internal(sk, ROSE_RR);
128 sk->protinfo.rose->vl = sk->protinfo.rose->vr;
129 sk->protinfo.rose->condition &= ~ROSE_COND_ACK_PENDING;
131 rose_stop_timer(sk);
134 #endif