1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
6 #include <linux/errno.h>
7 #include <linux/types.h>
8 #include <linux/socket.h>
10 #include <linux/kernel.h>
11 #include <linux/timer.h>
12 #include <linux/string.h>
13 #include <linux/sockios.h>
14 #include <linux/net.h>
15 #include <linux/gfp.h>
17 #include <linux/inet.h>
18 #include <linux/netdevice.h>
19 #include <linux/skbuff.h>
21 #include <linux/fcntl.h>
23 #include <linux/interrupt.h>
27 * This procedure is passed a buffer descriptor for an iframe. It builds
28 * the rest of the control part of the frame and then writes it out.
30 static void rose_send_iframe(struct sock *sk, struct sk_buff *skb)
32 struct rose_sock *rose = rose_sk(sk);
37 skb->data[2] |= (rose->vr << 5) & 0xE0;
38 skb->data[2] |= (rose->vs << 1) & 0x0E;
40 rose_start_idletimer(sk);
42 rose_transmit_link(skb, rose->neighbour);
45 void rose_kick(struct sock *sk)
47 struct rose_sock *rose = rose_sk(sk);
48 struct sk_buff *skb, *skbn;
49 unsigned short start, end;
51 if (rose->state != ROSE_STATE_3)
54 if (rose->condition & ROSE_COND_PEER_RX_BUSY)
57 if (!skb_peek(&sk->sk_write_queue))
60 start = (skb_peek(&rose->ack_queue) == NULL) ? rose->va : rose->vs;
61 end = (rose->va + sysctl_rose_window_size) % ROSE_MODULUS;
69 * Transmit data until either we're out of data to send or
73 skb = skb_dequeue(&sk->sk_write_queue);
76 if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
77 skb_queue_head(&sk->sk_write_queue, skb);
81 skb_set_owner_w(skbn, sk);
84 * Transmit the frame copy.
86 rose_send_iframe(sk, skbn);
88 rose->vs = (rose->vs + 1) % ROSE_MODULUS;
91 * Requeue the original data frame.
93 skb_queue_tail(&rose->ack_queue, skb);
95 } while (rose->vs != end &&
96 (skb = skb_dequeue(&sk->sk_write_queue)) != NULL);
99 rose->condition &= ~ROSE_COND_ACK_PENDING;
105 * The following routines are taken from page 170 of the 7th ARRL Computer
106 * Networking Conference paper, as is the whole state machine.
109 void rose_enquiry_response(struct sock *sk)
111 struct rose_sock *rose = rose_sk(sk);
113 if (rose->condition & ROSE_COND_OWN_RX_BUSY)
114 rose_write_internal(sk, ROSE_RNR);
116 rose_write_internal(sk, ROSE_RR);
119 rose->condition &= ~ROSE_COND_ACK_PENDING;