^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) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/jiffies.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 <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/rose.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void rose_ftimer_expiry(struct timer_list *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void rose_t0timer_expiry(struct timer_list *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static void rose_transmit_restart_confirmation(struct rose_neigh *neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void rose_transmit_restart_request(struct rose_neigh *neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) void rose_start_ftimer(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) del_timer(&neigh->ftimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) neigh->ftimer.function = rose_ftimer_expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) neigh->ftimer.expires =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) jiffies + msecs_to_jiffies(sysctl_rose_link_fail_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) add_timer(&neigh->ftimer);
^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) static void rose_start_t0timer(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) del_timer(&neigh->t0timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) neigh->t0timer.function = rose_t0timer_expiry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) neigh->t0timer.expires =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) jiffies + msecs_to_jiffies(sysctl_rose_restart_request_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) add_timer(&neigh->t0timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void rose_stop_ftimer(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) del_timer(&neigh->ftimer);
^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) void rose_stop_t0timer(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) del_timer(&neigh->t0timer);
^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) int rose_ftimer_running(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return timer_pending(&neigh->ftimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static int rose_t0timer_running(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return timer_pending(&neigh->t0timer);
^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) static void rose_ftimer_expiry(struct timer_list *t)
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void rose_t0timer_expiry(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct rose_neigh *neigh = from_timer(neigh, t, t0timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) rose_transmit_restart_request(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) neigh->dce_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) rose_start_t0timer(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^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) * Interface to ax25_send_frame. Changes my level 2 callsign depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * on whether we have a global ROSE callsign or use the default port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * callsign.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int rose_send_frame(struct sk_buff *skb, struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ax25_address *rose_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ax25_cb *ax25s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) rose_call = (ax25_address *)neigh->dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rose_call = &rose_callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ax25s = neigh->ax25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) neigh->ax25 = ax25_send_frame(skb, 260, rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ax25s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ax25_cb_put(ax25s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return neigh->ax25 != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * Interface to ax25_link_up. Changes my level 2 callsign depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * on whether we have a global ROSE callsign or use the default port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * callsign.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int rose_link_up(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ax25_address *rose_call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ax25_cb *ax25s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (ax25cmp(&rose_callsign, &null_ax25_address) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) rose_call = (ax25_address *)neigh->dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) rose_call = &rose_callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ax25s = neigh->ax25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) neigh->ax25 = ax25_find_cb(rose_call, &neigh->callsign, neigh->digipeat, neigh->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (ax25s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ax25_cb_put(ax25s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return neigh->ax25 != NULL;
^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) * This handles all restart and diagnostic frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void rose_link_rx_restart(struct sk_buff *skb, struct rose_neigh *neigh, unsigned short frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct sk_buff *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) case ROSE_RESTART_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) rose_stop_t0timer(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) neigh->restarted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) neigh->dce_mode = (skb->data[3] == ROSE_DTE_ORIGINATED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) rose_transmit_restart_confirmation(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) case ROSE_RESTART_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) rose_stop_t0timer(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) neigh->restarted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case ROSE_DIAGNOSTIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pr_warn("ROSE: received diagnostic #%d - %3ph\n", skb->data[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) skb->data + 4);
^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) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) printk(KERN_WARNING "ROSE: received unknown %02X with LCI 000\n", frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (neigh->restarted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) while ((skbn = skb_dequeue(&neigh->queue)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!rose_send_frame(skbn, neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) kfree_skb(skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * This routine is called when a Restart Request is needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void rose_transmit_restart_request(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned char *dptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) dptr = skb_put(skb, ROSE_MIN_LEN + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) *dptr++ = AX25_P_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *dptr++ = ROSE_GFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *dptr++ = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) *dptr++ = ROSE_RESTART_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) *dptr++ = ROSE_DTE_ORIGINATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) *dptr++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!rose_send_frame(skb, neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * This routine is called when a Restart Confirmation is needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void rose_transmit_restart_confirmation(struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) unsigned char *dptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dptr = skb_put(skb, ROSE_MIN_LEN + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *dptr++ = AX25_P_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *dptr++ = ROSE_GFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *dptr++ = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *dptr++ = ROSE_RESTART_CONFIRMATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (!rose_send_frame(skb, neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * This routine is called when a Clear Request is needed outside of the context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * of a connected socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void rose_transmit_clear_request(struct rose_neigh *neigh, unsigned int lci, unsigned char cause, unsigned char diagnostic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned char *dptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) len = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + ROSE_MIN_LEN + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if ((skb = alloc_skb(len, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) skb_reserve(skb, AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) dptr = skb_put(skb, ROSE_MIN_LEN + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *dptr++ = AX25_P_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) *dptr++ = ((lci >> 8) & 0x0F) | ROSE_GFI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *dptr++ = ((lci >> 0) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *dptr++ = ROSE_CLEAR_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *dptr++ = cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *dptr++ = diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!rose_send_frame(skb, neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) void rose_transmit_link(struct sk_buff *skb, struct rose_neigh *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) unsigned char *dptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (neigh->loopback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) rose_loopback_queue(skb, neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return;
^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) if (!rose_link_up(neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) neigh->restarted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) dptr = skb_push(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *dptr++ = AX25_P_ROSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (neigh->restarted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (!rose_send_frame(skb, neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) skb_queue_tail(&neigh->queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!rose_t0timer_running(neigh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) rose_transmit_restart_request(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) neigh->dce_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) rose_start_t0timer(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }