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)
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/socket.h>
13 #include <linux/kernel.h>
14 #include <linux/timer.h>
15 #include <linux/string.h>
16 #include <linux/sockios.h>
17 #include <linux/net.h>
18 #include <linux/gfp.h>
20 #include <linux/inet.h>
21 #include <linux/netdevice.h>
22 #include <linux/skbuff.h>
24 #include <linux/fcntl.h>
26 #include <linux/interrupt.h>
30 * This procedure is passed a buffer descriptor for an iframe. It builds
31 * the rest of the control part of the frame and then writes it out.
33 static void rose_send_iframe(struct sock
*sk
, struct sk_buff
*skb
)
35 struct rose_sock
*rose
= rose_sk(sk
);
40 skb
->data
[2] |= (rose
->vr
<< 5) & 0xE0;
41 skb
->data
[2] |= (rose
->vs
<< 1) & 0x0E;
43 rose_start_idletimer(sk
);
45 rose_transmit_link(skb
, rose
->neighbour
);
48 void rose_kick(struct sock
*sk
)
50 struct rose_sock
*rose
= rose_sk(sk
);
51 struct sk_buff
*skb
, *skbn
;
52 unsigned short start
, end
;
54 if (rose
->state
!= ROSE_STATE_3
)
57 if (rose
->condition
& ROSE_COND_PEER_RX_BUSY
)
60 if (!skb_peek(&sk
->sk_write_queue
))
63 start
= (skb_peek(&rose
->ack_queue
) == NULL
) ? rose
->va
: rose
->vs
;
64 end
= (rose
->va
+ sysctl_rose_window_size
) % ROSE_MODULUS
;
72 * Transmit data until either we're out of data to send or
76 skb
= skb_dequeue(&sk
->sk_write_queue
);
79 if ((skbn
= skb_clone(skb
, GFP_ATOMIC
)) == NULL
) {
80 skb_queue_head(&sk
->sk_write_queue
, skb
);
84 skb_set_owner_w(skbn
, sk
);
87 * Transmit the frame copy.
89 rose_send_iframe(sk
, skbn
);
91 rose
->vs
= (rose
->vs
+ 1) % ROSE_MODULUS
;
94 * Requeue the original data frame.
96 skb_queue_tail(&rose
->ack_queue
, skb
);
98 } while (rose
->vs
!= end
&&
99 (skb
= skb_dequeue(&sk
->sk_write_queue
)) != NULL
);
102 rose
->condition
&= ~ROSE_COND_ACK_PENDING
;
108 * The following routines are taken from page 170 of the 7th ARRL Computer
109 * Networking Conference paper, as is the whole state machine.
112 void rose_enquiry_response(struct sock
*sk
)
114 struct rose_sock
*rose
= rose_sk(sk
);
116 if (rose
->condition
& ROSE_COND_OWN_RX_BUSY
)
117 rose_write_internal(sk
, ROSE_RNR
);
119 rose_write_internal(sk
, ROSE_RR
);
122 rose
->condition
&= ~ROSE_COND_ACK_PENDING
;