^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) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.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 <linux/uaccess.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static DEFINE_SPINLOCK(ax25_frag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ax25_cb *ax25_send_frame(struct sk_buff *skb, int paclen, ax25_address *src, ax25_address *dest, ax25_digi *digi, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ax25_dev *ax25_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ax25_cb *ax25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Take the default packet length for the device if zero is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (paclen == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) paclen = ax25_dev->values[AX25_VALUES_PACLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Look for an existing connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if ((ax25 = ax25_find_cb(src, dest, digi, dev)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ax25_output(ax25, paclen, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return ax25; /* It already existed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if ((ax25 = ax25_create_cb()) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ax25_fillin_cb(ax25, ax25_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ax25->source_addr = *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ax25->dest_addr = *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (digi != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ax25->digipeat = kmemdup(digi, sizeof(*digi), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (ax25->digipeat == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ax25_cb_put(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) case AX25_PROTO_STD_SIMPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case AX25_PROTO_STD_DUPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ax25_std_establish_data_link(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #ifdef CONFIG_AX25_DAMA_SLAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) case AX25_PROTO_DAMA_SLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (ax25_dev->dama.slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ax25_ds_establish_data_link(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ax25_std_establish_data_link(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * There is one ref for the state machine; a caller needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * one more to put it back, just like with the existing one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ax25_cb_hold(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ax25_cb_add(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ax25->state = AX25_STATE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ax25_start_heartbeat(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ax25_output(ax25, paclen, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return ax25; /* We had to create it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) EXPORT_SYMBOL(ax25_send_frame);
^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) * All outgoing AX.25 I frames pass via this routine. Therefore this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * where the fragmentation of frames takes place. If fragment is set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * zero then we are not allowed to do fragmentation, even if the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * is too large.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void ax25_output(ax25_cb *ax25, int paclen, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int frontlen, len, fragno, ka9qfrag, first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (paclen < 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if ((skb->len - 1) > paclen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (*skb->data == AX25_P_TEXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) skb_pull(skb, 1); /* skip PID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ka9qfrag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) paclen -= 2; /* Allow for fragment control info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ka9qfrag = 1;
^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) fragno = skb->len / paclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (skb->len % paclen == 0) fragno--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) frontlen = skb_headroom(skb); /* Address space + CTRL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) while (skb->len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) spin_lock_bh(&ax25_frag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if ((skbn = alloc_skb(paclen + 2 + frontlen, GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) spin_unlock_bh(&ax25_frag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) printk(KERN_CRIT "AX.25: ax25_output - out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (skb->sk != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) skb_set_owner_w(skbn, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) spin_unlock_bh(&ax25_frag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) len = (paclen > skb->len) ? skb->len : paclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (ka9qfrag == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) skb_reserve(skbn, frontlen + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) skb_set_network_header(skbn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) skb_copy_from_linear_data(skb, skb_put(skbn, len), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) p = skb_push(skbn, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *p++ = AX25_P_SEGMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *p = fragno--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (first) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) *p |= AX25_SEG_FIRST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) skb_reserve(skbn, frontlen + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) skb_set_network_header(skbn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) skb_network_offset(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) skb_copy_from_linear_data(skb, skb_put(skbn, len), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) p = skb_push(skbn, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) *p = AX25_P_TEXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) skb_pull(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) skb_queue_tail(&ax25->write_queue, skbn); /* Throw it on the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) skb_queue_tail(&ax25->write_queue, skb); /* Throw it on the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case AX25_PROTO_STD_SIMPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case AX25_PROTO_STD_DUPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ax25_kick(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #ifdef CONFIG_AX25_DAMA_SLAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * A DAMA slave is _required_ to work as normal AX.25L2V2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * if no DAMA master is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) case AX25_PROTO_DAMA_SLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!ax25->ax25_dev->dama.slave) ax25_kick(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^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) * This procedure is passed a buffer descriptor for an iframe. It builds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * the rest of the control part of the frame and then writes it out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void ax25_send_iframe(ax25_cb *ax25, struct sk_buff *skb, int poll_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) unsigned char *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (ax25->modulus == AX25_MODULUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) frame = skb_push(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *frame = AX25_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) *frame |= (poll_bit) ? AX25_PF : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) *frame |= (ax25->vr << 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) *frame |= (ax25->vs << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) frame = skb_push(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) frame[0] = AX25_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) frame[0] |= (ax25->vs << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) frame[1] = (poll_bit) ? AX25_EPF : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) frame[1] |= (ax25->vr << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ax25_start_idletimer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ax25_transmit_buffer(ax25, skb, AX25_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) void ax25_kick(ax25_cb *ax25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct sk_buff *skb, *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int last = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) unsigned short start, end, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (ax25->state != AX25_STATE_3 && ax25->state != AX25_STATE_4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (ax25->condition & AX25_COND_PEER_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (skb_peek(&ax25->write_queue) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) start = (skb_peek(&ax25->ack_queue) == NULL) ? ax25->va : ax25->vs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) end = (ax25->va + ax25->window) % ax25->modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (start == end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return;
^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) * Transmit data until either we're out of data to send or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * the window is full. Send a poll on the final I frame if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * the window is filled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Dequeue the frame and copy it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Check for race with ax25_clear_queues().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) skb = skb_dequeue(&ax25->write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ax25->vs = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) skb_queue_head(&ax25->write_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (skb->sk != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) skb_set_owner_w(skbn, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) next = (ax25->vs + 1) % ax25->modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) last = (next == end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Transmit the frame copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * bke 960114: do not set the Poll bit on the last frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * in DAMA mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) case AX25_PROTO_STD_SIMPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case AX25_PROTO_STD_DUPLEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ax25_send_iframe(ax25, skbn, (last) ? AX25_POLLON : AX25_POLLOFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #ifdef CONFIG_AX25_DAMA_SLAVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) case AX25_PROTO_DAMA_SLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ax25_send_iframe(ax25, skbn, AX25_POLLOFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ax25->vs = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * Requeue the original data frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) skb_queue_tail(&ax25->ack_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) } while (!last && (skb = skb_dequeue(&ax25->write_queue)) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ax25->condition &= ~AX25_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (!ax25_t1timer_running(ax25)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ax25_stop_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ax25_calculate_t1(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ax25_start_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void ax25_transmit_buffer(ax25_cb *ax25, struct sk_buff *skb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (ax25->ax25_dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ax25_disconnect(ax25, ENETUNREACH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) headroom = ax25_addr_size(ax25->digipeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (skb_headroom(skb) < headroom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if ((skbn = skb_realloc_headroom(skb, headroom)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) printk(KERN_CRIT "AX.25: ax25_transmit_buffer - out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (skb->sk != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) skb_set_owner_w(skbn, skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) skb = skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ptr = skb_push(skb, headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ax25_addr_build(ptr, &ax25->source_addr, &ax25->dest_addr, ax25->digipeat, type, ax25->modulus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ax25_queue_xmit(skb, ax25->ax25_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * A small shim to dev_queue_xmit to add the KISS control byte, and do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * any packet forwarding in operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void ax25_queue_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) skb->protocol = ax25_type_trans(skb, ax25_fwd_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ptr = skb_push(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) *ptr = 0x00; /* KISS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int ax25_check_iframes_acked(ax25_cb *ax25, unsigned short nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (ax25->vs == nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ax25_calculate_rtt(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ax25_stop_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ax25_start_t3timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (ax25->va != nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ax25_frames_acked(ax25, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ax25_calculate_t1(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ax25_start_t1timer(ax25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return 1;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }