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