Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Most of this code is based on the SDL diagrams published in the 7th ARRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Computer Networking Conference papers. The diagrams have mistakes in them,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * but are mostly correct. Before you modify the code could you read the SDL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * diagrams as the code is not obvious and probably very easy to break.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <net/rose.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * State machine for state 1, Awaiting Call Accepted State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * The handling of the timer(s) is in file rose_timer.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Handling of state 0 and connection release is in af_rose.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int rose_state1_machine(struct sock *sk, struct sk_buff *skb, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	case ROSE_CALL_ACCEPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		rose->state     = ROSE_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		sk->sk_state	= TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		rose_disconnect(sk, ECONNREFUSED, skb->data[3], skb->data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * State machine for state 2, Awaiting Clear Confirmation State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * The handling of the timer(s) is in file rose_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Handling of state 0 and connection release is in af_rose.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static int rose_state2_machine(struct sock *sk, struct sk_buff *skb, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	case ROSE_CLEAR_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		rose_disconnect(sk, 0, -1, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * State machine for state 3, Connected State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * The handling of the timer(s) is in file rose_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * Handling of state 0 and connection release is in af_rose.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int rose_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype, int ns, int nr, int q, int d, int m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	case ROSE_RESET_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		rose_write_internal(sk, ROSE_RESET_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		rose_requeue_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	case ROSE_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	case ROSE_RNR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		if (!rose_validate_nr(sk, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			rose_write_internal(sk, ROSE_RESET_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			rose->state     = ROSE_STATE_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			rose_start_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			rose_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			if (frametype == ROSE_RNR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				rose->condition |= ROSE_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				rose->condition &= ~ROSE_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	case ROSE_DATA:	/* XXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		rose->condition &= ~ROSE_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (!rose_validate_nr(sk, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			rose_write_internal(sk, ROSE_RESET_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			rose->state     = ROSE_STATE_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			rose_start_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		rose_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (ns == rose->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			if (sk_filter_trim_cap(sk, skb, ROSE_MIN_LEN) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			    __sock_queue_rcv_skb(sk, skb) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				rose->vr = (rose->vr + 1) % ROSE_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				/* Should never happen ! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				rose_write_internal(sk, ROSE_RESET_REQUEST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 				rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				rose->state     = ROSE_STATE_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				rose_start_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			if (atomic_read(&sk->sk_rmem_alloc) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			    (sk->sk_rcvbuf >> 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				rose->condition |= ROSE_COND_OWN_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		 * If the window is full, ack the frame, else start the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		 * acknowledge hold back timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (((rose->vl + sysctl_rose_window_size) % ROSE_MODULUS) == rose->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			rose->condition &= ~ROSE_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			rose_enquiry_response(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			rose->condition |= ROSE_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			rose_start_hbtimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		printk(KERN_WARNING "ROSE: unknown %02X in state 3\n", frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * State machine for state 4, Awaiting Reset Confirmation State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * The handling of the timer(s) is in file rose_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * Handling of state 0 and connection release is in af_rose.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int rose_state4_machine(struct sock *sk, struct sk_buff *skb, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	case ROSE_RESET_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		rose_write_internal(sk, ROSE_RESET_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	case ROSE_RESET_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		rose->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		rose->va        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		rose->vr        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		rose->vs        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		rose->vl        = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		rose->state     = ROSE_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		rose_requeue_frames(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		rose->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * State machine for state 5, Awaiting Call Acceptance State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * The handling of the timer(s) is in file rose_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * Handling of state 0 and connection release is in af_rose.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int rose_state5_machine(struct sock *sk, struct sk_buff *skb, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (frametype == ROSE_CLEAR_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		rose_write_internal(sk, ROSE_CLEAR_CONFIRMATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		rose_disconnect(sk, 0, skb->data[3], skb->data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		rose_sk(sk)->neighbour->use--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Higher level upcall for a LAPB frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int rose_process_rx_frame(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	int queued = 0, frametype, ns, nr, q, d, m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (rose->state == ROSE_STATE_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	frametype = rose_decode(skb, &ns, &nr, &q, &d, &m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	switch (rose->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	case ROSE_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		queued = rose_state1_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	case ROSE_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		queued = rose_state2_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	case ROSE_STATE_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		queued = rose_state3_machine(sk, skb, frametype, ns, nr, q, d, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	case ROSE_STATE_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		queued = rose_state4_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	case ROSE_STATE_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		queued = rose_state5_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	rose_kick(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }