1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 2 /* 3 * 3 * 4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@ 4 * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk) 5 */ 5 */ 6 #include <linux/errno.h> 6 #include <linux/errno.h> 7 #include <linux/types.h> 7 #include <linux/types.h> 8 #include <linux/socket.h> 8 #include <linux/socket.h> 9 #include <linux/in.h> 9 #include <linux/in.h> 10 #include <linux/kernel.h> 10 #include <linux/kernel.h> 11 #include <linux/timer.h> 11 #include <linux/timer.h> 12 #include <linux/string.h> 12 #include <linux/string.h> 13 #include <linux/sockios.h> 13 #include <linux/sockios.h> 14 #include <linux/net.h> 14 #include <linux/net.h> 15 #include <linux/gfp.h> 15 #include <linux/gfp.h> 16 #include <net/ax25.h> 16 #include <net/ax25.h> 17 #include <linux/inet.h> 17 #include <linux/inet.h> 18 #include <linux/netdevice.h> 18 #include <linux/netdevice.h> 19 #include <linux/skbuff.h> 19 #include <linux/skbuff.h> 20 #include <net/sock.h> 20 #include <net/sock.h> 21 #include <linux/fcntl.h> 21 #include <linux/fcntl.h> 22 #include <linux/mm.h> 22 #include <linux/mm.h> 23 #include <linux/interrupt.h> 23 #include <linux/interrupt.h> 24 #include <net/rose.h> 24 #include <net/rose.h> 25 25 26 /* 26 /* 27 * This procedure is passed a buffer desc 27 * This procedure is passed a buffer descriptor for an iframe. It builds 28 * the rest of the control part of the fr 28 * the rest of the control part of the frame and then writes it out. 29 */ 29 */ 30 static void rose_send_iframe(struct sock *sk, 30 static void rose_send_iframe(struct sock *sk, struct sk_buff *skb) 31 { 31 { 32 struct rose_sock *rose = rose_sk(sk); 32 struct rose_sock *rose = rose_sk(sk); 33 33 34 if (skb == NULL) 34 if (skb == NULL) 35 return; 35 return; 36 36 37 skb->data[2] |= (rose->vr << 5) & 0xE0 37 skb->data[2] |= (rose->vr << 5) & 0xE0; 38 skb->data[2] |= (rose->vs << 1) & 0x0E 38 skb->data[2] |= (rose->vs << 1) & 0x0E; 39 39 40 rose_start_idletimer(sk); 40 rose_start_idletimer(sk); 41 41 42 rose_transmit_link(skb, rose->neighbou 42 rose_transmit_link(skb, rose->neighbour); 43 } 43 } 44 44 45 void rose_kick(struct sock *sk) 45 void rose_kick(struct sock *sk) 46 { 46 { 47 struct rose_sock *rose = rose_sk(sk); 47 struct rose_sock *rose = rose_sk(sk); 48 struct sk_buff *skb, *skbn; 48 struct sk_buff *skb, *skbn; 49 unsigned short start, end; 49 unsigned short start, end; 50 50 51 if (rose->state != ROSE_STATE_3) 51 if (rose->state != ROSE_STATE_3) 52 return; 52 return; 53 53 54 if (rose->condition & ROSE_COND_PEER_R 54 if (rose->condition & ROSE_COND_PEER_RX_BUSY) 55 return; 55 return; 56 56 57 if (!skb_peek(&sk->sk_write_queue)) 57 if (!skb_peek(&sk->sk_write_queue)) 58 return; 58 return; 59 59 60 start = (skb_peek(&rose->ack_queue) == 60 start = (skb_peek(&rose->ack_queue) == NULL) ? rose->va : rose->vs; 61 end = (rose->va + sysctl_rose_window 61 end = (rose->va + sysctl_rose_window_size) % ROSE_MODULUS; 62 62 63 if (start == end) 63 if (start == end) 64 return; 64 return; 65 65 66 rose->vs = start; 66 rose->vs = start; 67 67 68 /* 68 /* 69 * Transmit data until either we're ou 69 * Transmit data until either we're out of data to send or 70 * the window is full. 70 * the window is full. 71 */ 71 */ 72 72 73 skb = skb_dequeue(&sk->sk_write_queue 73 skb = skb_dequeue(&sk->sk_write_queue); 74 74 75 do { 75 do { 76 if ((skbn = skb_clone(skb, GFP 76 if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) { 77 skb_queue_head(&sk->sk 77 skb_queue_head(&sk->sk_write_queue, skb); 78 break; 78 break; 79 } 79 } 80 80 81 skb_set_owner_w(skbn, sk); 81 skb_set_owner_w(skbn, sk); 82 82 83 /* 83 /* 84 * Transmit the frame copy. 84 * Transmit the frame copy. 85 */ 85 */ 86 rose_send_iframe(sk, skbn); 86 rose_send_iframe(sk, skbn); 87 87 88 rose->vs = (rose->vs + 1) % RO 88 rose->vs = (rose->vs + 1) % ROSE_MODULUS; 89 89 90 /* 90 /* 91 * Requeue the original data f 91 * Requeue the original data frame. 92 */ 92 */ 93 skb_queue_tail(&rose->ack_queu 93 skb_queue_tail(&rose->ack_queue, skb); 94 94 95 } while (rose->vs != end && 95 } while (rose->vs != end && 96 (skb = skb_dequeue(&sk->sk_wr 96 (skb = skb_dequeue(&sk->sk_write_queue)) != NULL); 97 97 98 rose->vl = rose->vr; 98 rose->vl = rose->vr; 99 rose->condition &= ~ROSE_COND_ACK_PEND 99 rose->condition &= ~ROSE_COND_ACK_PENDING; 100 100 101 rose_stop_timer(sk); 101 rose_stop_timer(sk); 102 } 102 } 103 103 104 /* 104 /* 105 * The following routines are taken from page 105 * The following routines are taken from page 170 of the 7th ARRL Computer 106 * Networking Conference paper, as is the whol 106 * Networking Conference paper, as is the whole state machine. 107 */ 107 */ 108 108 109 void rose_enquiry_response(struct sock *sk) 109 void rose_enquiry_response(struct sock *sk) 110 { 110 { 111 struct rose_sock *rose = rose_sk(sk); 111 struct rose_sock *rose = rose_sk(sk); 112 112 113 if (rose->condition & ROSE_COND_OWN_RX 113 if (rose->condition & ROSE_COND_OWN_RX_BUSY) 114 rose_write_internal(sk, ROSE_R 114 rose_write_internal(sk, ROSE_RNR); 115 else 115 else 116 rose_write_internal(sk, ROSE_R 116 rose_write_internal(sk, ROSE_RR); 117 117 118 rose->vl = rose->vr; 118 rose->vl = rose->vr; 119 rose->condition &= ~ROSE_COND_ACK_PEND 119 rose->condition &= ~ROSE_COND_ACK_PENDING; 120 120 121 rose_stop_timer(sk); 121 rose_stop_timer(sk); 122 } 122 } 123 123
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.