~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/net/x25/x25_out.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *      X.25 Packet Layer release 002
  3  *
  4  *      This is ALPHA test software. This code may break your machine, randomly fail to work with new 
  5  *      releases, misbehave and/or generally screw up. It might even work. 
  6  *
  7  *      This code REQUIRES 2.1.15 or higher
  8  *
  9  *      This module:
 10  *              This module is free software; you can redistribute it and/or
 11  *              modify it under the terms of the GNU General Public License
 12  *              as published by the Free Software Foundation; either version
 13  *              2 of the License, or (at your option) any later version.
 14  *
 15  *      History
 16  *      X.25 001        Jonathan Naylor Started coding.
 17  *      X.25 002        Jonathan Naylor New timer architecture.
 18  *      2000-09-04      Henner Eisen    Prevented x25_output() skb leakage.
 19  *      2000-10-27      Henner Eisen    MSG_DONTWAIT for fragment allocation.
 20  *      2000-11-10      Henner Eisen    x25_send_iframe(): re-queued frames
 21  *                                      needed cleaned seq-number fields.
 22  */
 23 
 24 #include <linux/config.h>
 25 #if defined(CONFIG_X25) || defined(CONFIG_X25_MODULE)
 26 #include <linux/errno.h>
 27 #include <linux/types.h>
 28 #include <linux/socket.h>
 29 #include <linux/in.h>
 30 #include <linux/kernel.h>
 31 #include <linux/sched.h>
 32 #include <linux/timer.h>
 33 #include <linux/string.h>
 34 #include <linux/sockios.h>
 35 #include <linux/net.h>
 36 #include <linux/inet.h>
 37 #include <linux/netdevice.h>
 38 #include <linux/skbuff.h>
 39 #include <net/sock.h>
 40 #include <asm/segment.h>
 41 #include <asm/system.h>
 42 #include <linux/fcntl.h>
 43 #include <linux/mm.h>
 44 #include <linux/interrupt.h>
 45 #include <net/x25.h>
 46 
 47 static int x25_pacsize_to_bytes(unsigned int pacsize)
 48 {
 49         int bytes = 1;
 50 
 51         if (pacsize == 0)
 52                 return 128;
 53 
 54         while (pacsize-- > 0)
 55                 bytes *= 2;
 56 
 57         return bytes;
 58 }
 59 
 60 /*
 61  *      This is where all X.25 information frames pass.
 62  *
 63  *      Returns the amount of user data bytes sent on success
 64  *      or a negative error code on failure.
 65  */
 66 int x25_output(struct sock *sk, struct sk_buff *skb)
 67 {
 68         struct sk_buff *skbn;
 69         unsigned char header[X25_EXT_MIN_LEN];
 70         int err, frontlen, len, header_len, max_len;
 71         int sent=0, noblock = X25_SKB_CB(skb)->flags & MSG_DONTWAIT;
 72 
 73         header_len = (sk->protinfo.x25->neighbour->extended) ? X25_EXT_MIN_LEN : X25_STD_MIN_LEN;
 74         max_len    = x25_pacsize_to_bytes(sk->protinfo.x25->facilities.pacsize_out);
 75 
 76         if (skb->len - header_len > max_len) {
 77                 /* Save a copy of the Header */
 78                 memcpy(header, skb->data, header_len);
 79                 skb_pull(skb, header_len);
 80 
 81                 frontlen = skb_headroom(skb);
 82 
 83                 while (skb->len > 0) {
 84                         if ((skbn = sock_alloc_send_skb(sk, frontlen + max_len, 0, noblock, &err)) == NULL){
 85                                 if(err == -EWOULDBLOCK && noblock){
 86                                         kfree_skb(skb);
 87                                         return sent;
 88                                 }
 89                                 SOCK_DEBUG(sk, "x25_output: fragment allocation failed, err=%d, %d bytes sent\n", err, sent);
 90                                 return err;
 91                         }
 92                                 
 93                         skb_reserve(skbn, frontlen);
 94 
 95                         len = (max_len > skb->len) ? skb->len : max_len;
 96 
 97                         /* Copy the user data */
 98                         memcpy(skb_put(skbn, len), skb->data, len);
 99                         skb_pull(skb, len);
100 
101                         /* Duplicate the Header */
102                         skb_push(skbn, header_len);
103                         memcpy(skbn->data, header, header_len);
104 
105                         if (skb->len > 0) {
106                                 if (sk->protinfo.x25->neighbour->extended)
107                                         skbn->data[3] |= X25_EXT_M_BIT;
108                                 else
109                                         skbn->data[2] |= X25_STD_M_BIT;
110                         }
111 
112                         skb_queue_tail(&sk->write_queue, skbn);
113                         sent += len;
114                 }
115                 
116                 kfree_skb(skb);
117         } else {
118                 skb_queue_tail(&sk->write_queue, skb);
119                 sent = skb->len - header_len;
120         }
121         return sent;
122 }
123 
124 /* 
125  *      This procedure is passed a buffer descriptor for an iframe. It builds
126  *      the rest of the control part of the frame and then writes it out.
127  */
128 static void x25_send_iframe(struct sock *sk, struct sk_buff *skb)
129 {
130         if (skb == NULL)
131                 return;
132 
133         if (sk->protinfo.x25->neighbour->extended) {
134                 skb->data[2]  = (sk->protinfo.x25->vs << 1) & 0xFE;
135                 skb->data[3] &= X25_EXT_M_BIT;
136                 skb->data[3] |= (sk->protinfo.x25->vr << 1) & 0xFE;
137         } else {
138                 skb->data[2] &= X25_STD_M_BIT;
139                 skb->data[2] |= (sk->protinfo.x25->vs << 1) & 0x0E;
140                 skb->data[2] |= (sk->protinfo.x25->vr << 5) & 0xE0;
141         }
142 
143         x25_transmit_link(skb, sk->protinfo.x25->neighbour);    
144 }
145 
146 void x25_kick(struct sock *sk)
147 {
148         struct sk_buff *skb, *skbn;
149         unsigned short start, end;
150         int modulus;
151 
152         if (sk->protinfo.x25->state != X25_STATE_3)
153                 return;
154 
155         /*
156          *      Transmit interrupt data.
157          */
158         if (!sk->protinfo.x25->intflag && skb_peek(&sk->protinfo.x25->interrupt_out_queue) != NULL) {
159                 sk->protinfo.x25->intflag = 1;
160                 skb = skb_dequeue(&sk->protinfo.x25->interrupt_out_queue);
161                 x25_transmit_link(skb, sk->protinfo.x25->neighbour);
162         }
163 
164         if (sk->protinfo.x25->condition & X25_COND_PEER_RX_BUSY)
165                 return;
166 
167         if (skb_peek(&sk->write_queue) == NULL)
168                 return;
169 
170         modulus = (sk->protinfo.x25->neighbour->extended) ? X25_EMODULUS : X25_SMODULUS;
171 
172         start   = (skb_peek(&sk->protinfo.x25->ack_queue) == NULL) ? sk->protinfo.x25->va : sk->protinfo.x25->vs;
173         end     = (sk->protinfo.x25->va + sk->protinfo.x25->facilities.winsize_out) % modulus;
174 
175         if (start == end)
176                 return;
177 
178         sk->protinfo.x25->vs = start;
179 
180         /*
181          * Transmit data until either we're out of data to send or
182          * the window is full.
183          */
184 
185         skb = skb_dequeue(&sk->write_queue);
186 
187         do {
188                 if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
189                         skb_queue_head(&sk->write_queue, skb);
190                         break;
191                 }
192 
193                 skb_set_owner_w(skbn, sk);
194 
195                 /*
196                  * Transmit the frame copy.
197                  */
198                 x25_send_iframe(sk, skbn);
199 
200                 sk->protinfo.x25->vs = (sk->protinfo.x25->vs + 1) % modulus;
201 
202                 /*
203                  * Requeue the original data frame.
204                  */
205                 skb_queue_tail(&sk->protinfo.x25->ack_queue, skb);
206 
207         } while (sk->protinfo.x25->vs != end && (skb = skb_dequeue(&sk->write_queue)) != NULL);
208 
209         sk->protinfo.x25->vl         = sk->protinfo.x25->vr;
210         sk->protinfo.x25->condition &= ~X25_COND_ACK_PENDING;
211 
212         x25_stop_timer(sk);
213 }
214 
215 /*
216  * The following routines are taken from page 170 of the 7th ARRL Computer
217  * Networking Conference paper, as is the whole state machine.
218  */
219 
220 void x25_enquiry_response(struct sock *sk)
221 {
222         if (sk->protinfo.x25->condition & X25_COND_OWN_RX_BUSY)
223                 x25_write_internal(sk, X25_RNR);
224         else
225                 x25_write_internal(sk, X25_RR);
226 
227         sk->protinfo.x25->vl         = sk->protinfo.x25->vr;
228         sk->protinfo.x25->condition &= ~X25_COND_ACK_PENDING;
229 
230         x25_stop_timer(sk);
231 }
232 
233 #endif
234 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.