^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) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Most of this code is based on the SDL diagrams published in the 7th ARRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Computer Networking Conference papers. The diagrams have mistakes in them,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * but are mostly correct. Before you modify the code could you read the SDL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * diagrams as the code is not obvious and probably very easy to break.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * State machine for state 1, Awaiting Connection State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * The handling of the timer(s) is in file ax25_std_timer.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Handling of state 0 and connection release is in ax25.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int ax25_std_state1_machine(ax25_cb *ax25, struct sk_buff *skb, int frametype, int pf, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) case AX25_SABM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ax25->modulus = AX25_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) case AX25_SABME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ax25->modulus = AX25_EMODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ax25->window = ax25->ax25_dev->values[AX25_VALUES_EWINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) case AX25_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ax25_send_control(ax25, AX25_DM, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) case AX25_UA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (pf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ax25_calculate_rtt(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ax25_start_idletimer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ax25->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ax25->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ax25->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ax25->state = AX25_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ax25->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ax25->sk != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) bh_lock_sock(ax25->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ax25->sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* For WAIT_SABM connections we will produce an accept ready socket here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (!sock_flag(ax25->sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ax25->sk->sk_state_change(ax25->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) bh_unlock_sock(ax25->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) case AX25_DM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (pf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (ax25->modulus == AX25_MODULUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ax25_disconnect(ax25, ECONNREFUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ax25->modulus = AX25_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * State machine for state 2, Awaiting Release State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * The handling of the timer(s) is in file ax25_std_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * Handling of state 0 and connection release is in ax25.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int ax25_std_state2_machine(ax25_cb *ax25, struct sk_buff *skb, int frametype, int pf, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) case AX25_SABM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case AX25_SABME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ax25_send_control(ax25, AX25_DM, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case AX25_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ax25_disconnect(ax25, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) case AX25_DM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) case AX25_UA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ax25_disconnect(ax25, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) case AX25_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case AX25_REJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) case AX25_RNR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case AX25_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (pf) ax25_send_control(ax25, AX25_DM, AX25_POLLON, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * State machine for state 3, Connected State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * The handling of the timer(s) is in file ax25_std_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * Handling of state 0 and connection release is in ax25.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int ax25_std_state3_machine(ax25_cb *ax25, struct sk_buff *skb, int frametype, int ns, int nr, int pf, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case AX25_SABM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) case AX25_SABME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (frametype == AX25_SABM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ax25->modulus = AX25_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ax25->modulus = AX25_EMODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ax25->window = ax25->ax25_dev->values[AX25_VALUES_EWINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ax25_stop_t2timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ax25_start_idletimer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ax25->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ax25->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ax25->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ax25->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case AX25_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ax25_disconnect(ax25, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) case AX25_DM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ax25_disconnect(ax25, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) case AX25_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case AX25_RNR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (frametype == AX25_RR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ax25->condition &= ~AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ax25->condition |= AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (type == AX25_COMMAND && pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ax25_check_iframes_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) case AX25_REJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ax25->condition &= ~AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (type == AX25_COMMAND && pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ax25_calculate_rtt(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case AX25_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (ax25->condition & AX25_COND_PEER_RX_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ax25_check_iframes_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (ax25->condition & AX25_COND_OWN_RX_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (pf) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (ns == ax25->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ax25->vr = (ax25->vr + 1) % ax25->modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) queued = ax25_rx_iframe(ax25, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (ax25->condition & AX25_COND_OWN_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ax25->vr = ns; /* ax25->vr - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ax25->condition &= ~AX25_COND_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (pf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!(ax25->condition & AX25_COND_ACK_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ax25->condition |= AX25_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ax25_start_t2timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (ax25->condition & AX25_COND_REJECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (pf) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ax25->condition |= AX25_COND_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ax25_send_control(ax25, AX25_REJ, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ax25->condition &= ~AX25_COND_ACK_PENDING;
^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) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) case AX25_FRMR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case AX25_ILLEGAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ax25_std_establish_data_link(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^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 queued;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * State machine for state 4, Timer Recovery State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * The handling of the timer(s) is in file ax25_std_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * Handling of state 0 and connection release is in ax25.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int ax25_std_state4_machine(ax25_cb *ax25, struct sk_buff *skb, int frametype, int ns, int nr, int pf, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) case AX25_SABM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) case AX25_SABME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (frametype == AX25_SABM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ax25->modulus = AX25_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) ax25->modulus = AX25_EMODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ax25->window = ax25->ax25_dev->values[AX25_VALUES_EWINDOW];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ax25_stop_t2timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ax25_start_idletimer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ax25->condition = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ax25->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ax25->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ax25->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ax25->state = AX25_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ax25->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) case AX25_DISC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) ax25_send_control(ax25, AX25_UA, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ax25_disconnect(ax25, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) case AX25_DM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ax25_disconnect(ax25, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) case AX25_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) case AX25_RNR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (frametype == AX25_RR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) ax25->condition &= ~AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ax25->condition |= AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (type == AX25_RESPONSE && pf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ax25->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (ax25->vs == ax25->va) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) ax25->state = AX25_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (type == AX25_COMMAND && pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) case AX25_REJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ax25->condition &= ~AX25_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (pf && type == AX25_RESPONSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ax25->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (ax25->vs == ax25->va) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ax25->state = AX25_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (type == AX25_COMMAND && pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ax25_requeue_frames(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case AX25_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!ax25_validate_nr(ax25, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ax25_std_nr_error_recovery(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (ax25->condition & AX25_COND_OWN_RX_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (pf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (ns == ax25->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ax25->vr = (ax25->vr + 1) % ax25->modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) queued = ax25_rx_iframe(ax25, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (ax25->condition & AX25_COND_OWN_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ax25->vr = ns; /* ax25->vr - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ax25->condition &= ~AX25_COND_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (pf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (!(ax25->condition & AX25_COND_ACK_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ax25->condition |= AX25_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) ax25_start_t2timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (ax25->condition & AX25_COND_REJECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (pf) ax25_std_enquiry_response(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ax25->condition |= AX25_COND_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ax25_send_control(ax25, AX25_REJ, pf, AX25_RESPONSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ax25->condition &= ~AX25_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) case AX25_FRMR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case AX25_ILLEGAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ax25_std_establish_data_link(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * Higher level upcall for a LAPB frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int ax25_std_frame_in(ax25_cb *ax25, struct sk_buff *skb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int queued = 0, frametype, ns, nr, pf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) frametype = ax25_decode(ax25, skb, &ns, &nr, &pf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) switch (ax25->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) case AX25_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) queued = ax25_std_state1_machine(ax25, skb, frametype, pf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) case AX25_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) queued = ax25_std_state2_machine(ax25, skb, frametype, pf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) case AX25_STATE_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) queued = ax25_std_state3_machine(ax25, skb, frametype, ns, nr, pf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) case AX25_STATE_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) queued = ax25_std_state4_machine(ax25, skb, frametype, ns, nr, pf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ax25_kick(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }