^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 Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright Darryl Miles G7LED (dlm@g7led.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/netrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int nr_queue_rx_frame(struct sock *sk, struct sk_buff *skb, int more)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct sk_buff *skbo, *skbn = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) skb_pull(skb, NR_NETWORK_LEN + NR_TRANSPORT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) nr_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (more) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) nr->fraglen += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) skb_queue_tail(&nr->frag_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (!more && nr->fraglen > 0) { /* End of fragment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) nr->fraglen += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) skb_queue_tail(&nr->frag_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if ((skbn = alloc_skb(nr->fraglen, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) skb_reset_transport_header(skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) while ((skbo = skb_dequeue(&nr->frag_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) skb_copy_from_linear_data(skbo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) skb_put(skbn, skbo->len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) skbo->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) kfree_skb(skbo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) nr->fraglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return sock_queue_rcv_skb(sk, skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * State machine for state 1, Awaiting Connection State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * The handling of the timer(s) is in file nr_timer.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * Handling of state 0 and connection release is in netrom.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int nr_state1_machine(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) case NR_CONNACK: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) nr_stop_t1timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) nr_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) nr->your_index = skb->data[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) nr->your_id = skb->data[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) nr->vs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) nr->va = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) nr->vr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) nr->vl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) nr->state = NR_STATE_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) nr->n2count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) nr->window = skb->data[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) sk->sk_state = TCP_ESTABLISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sk->sk_state_change(sk);
^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) case NR_CONNACK | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) nr_disconnect(sk, ECONNREFUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) case NR_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (sysctl_netrom_reset_circuit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nr_disconnect(sk, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * State machine for state 2, Awaiting Release State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * The handling of the timer(s) is in file nr_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Handling of state 0 and connection release is in netrom.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int nr_state2_machine(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) case NR_CONNACK | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) nr_disconnect(sk, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case NR_DISCREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) nr_write_internal(sk, NR_DISCACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) case NR_DISCACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) nr_disconnect(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) case NR_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (sysctl_netrom_reset_circuit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) nr_disconnect(sk, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * State machine for state 3, Connected State.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * The handling of the timer(s) is in file nr_timer.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * Handling of state 0 and connection release is in netrom.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct nr_sock *nrom = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct sk_buff_head temp_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unsigned short save_vr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned short nr, ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) nr = skb->data[18];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ns = skb->data[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case NR_CONNREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) nr_write_internal(sk, NR_CONNACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) case NR_DISCREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) nr_write_internal(sk, NR_DISCACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) nr_disconnect(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case NR_CONNACK | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) case NR_DISCACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) nr_disconnect(sk, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) case NR_INFOACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) case NR_INFOACK | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case NR_INFOACK | NR_NAK_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) case NR_INFOACK | NR_NAK_FLAG | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (frametype & NR_CHOKE_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) nrom->condition |= NR_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) nr_start_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) nrom->condition &= ~NR_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) nr_stop_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!nr_validate_nr(sk, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (frametype & NR_NAK_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) nr_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) nr_send_nak_frame(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (nrom->condition & NR_COND_PEER_RX_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) nr_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) nr_check_iframes_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^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) case NR_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) case NR_INFO | NR_NAK_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) case NR_INFO | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case NR_INFO | NR_MORE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) case NR_INFO | NR_NAK_FLAG | NR_CHOKE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) case NR_INFO | NR_CHOKE_FLAG | NR_MORE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) case NR_INFO | NR_NAK_FLAG | NR_MORE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) case NR_INFO | NR_NAK_FLAG | NR_CHOKE_FLAG | NR_MORE_FLAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (frametype & NR_CHOKE_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) nrom->condition |= NR_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) nr_start_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) nrom->condition &= ~NR_COND_PEER_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) nr_stop_t4timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (nr_validate_nr(sk, nr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (frametype & NR_NAK_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) nr_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) nr_send_nak_frame(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (nrom->condition & NR_COND_PEER_RX_BUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) nr_frames_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) nr_check_iframes_acked(sk, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) skb_queue_head(&nrom->reseq_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (nrom->condition & NR_COND_OWN_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) skb_queue_head_init(&temp_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) save_vr = nrom->vr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) while ((skbn = skb_dequeue(&nrom->reseq_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ns = skbn->data[17];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (ns == nrom->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (nr_queue_rx_frame(sk, skbn, frametype & NR_MORE_FLAG) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) nrom->vr = (nrom->vr + 1) % NR_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) nrom->condition |= NR_COND_OWN_RX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) skb_queue_tail(&temp_queue, skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) } else if (nr_in_rx_window(sk, ns)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) skb_queue_tail(&temp_queue, skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) kfree_skb(skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) while ((skbn = skb_dequeue(&temp_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) skb_queue_tail(&nrom->reseq_queue, skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } while (save_vr != nrom->vr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * Window is full, ack it immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (((nrom->vl + nrom->window) % NR_MODULUS) == nrom->vr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) nr_enquiry_response(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!(nrom->condition & NR_COND_ACK_PENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) nrom->condition |= NR_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) nr_start_t2timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case NR_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (sysctl_netrom_reset_circuit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) nr_disconnect(sk, ECONNRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Higher level upcall for a LAPB frame - called with sk locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int nr_process_rx_frame(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct nr_sock *nr = nr_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int queued = 0, frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (nr->state == NR_STATE_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) frametype = skb->data[19];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) switch (nr->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case NR_STATE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) queued = nr_state1_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) case NR_STATE_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) queued = nr_state2_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) case NR_STATE_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) queued = nr_state3_machine(sk, skb, frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) nr_kick(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }