Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #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/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/tcp_states.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 int rose_create_facilities(unsigned char *buffer, struct rose_sock *rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *	This routine purges all of the queues of frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) void rose_clear_queues(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	skb_queue_purge(&sk->sk_write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	skb_queue_purge(&rose_sk(sk)->ack_queue);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * This routine purges the input queue of those frames that have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * acknowledged. This replaces the boxes labelled "V(a) <- N(r)" on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * SDL diagram.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) void rose_frames_acked(struct sock *sk, unsigned short nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct rose_sock *rose = rose_sk(sk);
^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) 	 * Remove all the ack-ed frames from the ack queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (rose->va != nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		while (skb_peek(&rose->ack_queue) != NULL && rose->va != nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			skb = skb_dequeue(&rose->ack_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			rose->va = (rose->va + 1) % ROSE_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^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_requeue_frames(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct sk_buff *skb, *skb_prev = NULL;
^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) 	 * Requeue all the un-ack-ed frames on the output queue to be picked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 * up by rose_kick. This arrangement handles the possibility of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * empty output queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	while ((skb = skb_dequeue(&rose_sk(sk)->ack_queue)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (skb_prev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			skb_queue_head(&sk->sk_write_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			skb_append(skb_prev, skb, &sk->sk_write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		skb_prev = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^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)  *	Validate that the value of nr is between va and vs. Return true or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *	false for testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) int rose_validate_nr(struct sock *sk, unsigned short nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	unsigned short vc = rose->va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	while (vc != rose->vs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (nr == vc) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		vc = (vc + 1) % ROSE_MODULUS;
^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) 	return nr == rose->vs;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *  This routine is called when the packet layer internally generates a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *  control frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) void rose_write_internal(struct sock *sk, int frametype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	unsigned char  *dptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	unsigned char  lci1, lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int maxfaclen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int len, faclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int reserve;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	reserve = AX25_BPQ_HEADER_LEN + AX25_MAX_HEADER_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	len = ROSE_MIN_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	case ROSE_CALL_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		len   += 1 + ROSE_ADDR_LEN + ROSE_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		maxfaclen = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case ROSE_CALL_ACCEPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case ROSE_RESET_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		len   += 2;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	skb = alloc_skb(reserve + len + maxfaclen, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 *	Space for AX.25 header and PID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	skb_reserve(skb, reserve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	dptr = skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	lci1 = (rose->lci >> 8) & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	lci2 = (rose->lci >> 0) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	switch (frametype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	case ROSE_CALL_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		*dptr++ = frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		*dptr++ = ROSE_CALL_REQ_ADDR_LEN_VAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		memcpy(dptr, &rose->dest_addr,  ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		dptr   += ROSE_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		memcpy(dptr, &rose->source_addr, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		dptr   += ROSE_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		faclen = rose_create_facilities(dptr, rose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		skb_put(skb, faclen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		dptr   += faclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	case ROSE_CALL_ACCEPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		*dptr++ = frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		*dptr++ = 0x00;		/* Address length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		*dptr++ = 0;		/* Facilities length */
^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) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		*dptr++ = frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		*dptr++ = rose->cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		*dptr++ = rose->diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	case ROSE_RESET_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		*dptr++ = frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		*dptr++ = ROSE_DTE_ORIGINATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		*dptr++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	case ROSE_RR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	case ROSE_RNR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		*dptr   = frametype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		*dptr++ |= (rose->vr << 5) & 0xE0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	case ROSE_CLEAR_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	case ROSE_RESET_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		*dptr++ = ROSE_GFI | lci1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		*dptr++ = lci2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		*dptr++  = frametype;
^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) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		printk(KERN_ERR "ROSE: rose_write_internal - invalid frametype %02X\n", frametype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	rose_transmit_link(skb, rose->neighbour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int rose_decode(struct sk_buff *skb, int *ns, int *nr, int *q, int *d, int *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	unsigned char *frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	frame = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	*ns = *nr = *q = *d = *m = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	switch (frame[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	case ROSE_CALL_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	case ROSE_CALL_ACCEPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	case ROSE_CLEAR_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	case ROSE_CLEAR_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	case ROSE_RESET_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	case ROSE_RESET_CONFIRMATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return frame[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if ((frame[2] & 0x1F) == ROSE_RR  ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	    (frame[2] & 0x1F) == ROSE_RNR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		*nr = (frame[2] >> 5) & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return frame[2] & 0x1F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if ((frame[2] & 0x01) == ROSE_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		*q  = (frame[0] & ROSE_Q_BIT) == ROSE_Q_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		*d  = (frame[0] & ROSE_D_BIT) == ROSE_D_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		*m  = (frame[2] & ROSE_M_BIT) == ROSE_M_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		*nr = (frame[2] >> 5) & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		*ns = (frame[2] >> 1) & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return ROSE_DATA;
^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) 	return ROSE_ILLEGAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int rose_parse_national(unsigned char *p, struct rose_facilities_struct *facilities, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned char *pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	unsigned char l, lg, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	int fac_national_digis_received = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		switch (*p & 0xC0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			if (len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			p   += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			n   += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			len -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			if (len < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			if (*p == FAC_NATIONAL_RAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				facilities->rand = ((p[1] << 8) & 0xFF00) + ((p[2] << 0) & 0x00FF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			p   += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			n   += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			len -= 3;
^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 0x80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			if (len < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			p   += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			n   += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			len -= 4;
^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) 		case 0xC0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			if (len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			l = p[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			if (len < 2 + l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			if (*p == FAC_NATIONAL_DEST_DIGI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				if (!fac_national_digis_received) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					if (l < AX25_ADDR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 						return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 					memcpy(&facilities->source_digis[0], p + 2, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 					facilities->source_ndigis = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			else if (*p == FAC_NATIONAL_SRC_DIGI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				if (!fac_national_digis_received) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 					if (l < AX25_ADDR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 						return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 					memcpy(&facilities->dest_digis[0], p + 2, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 					facilities->dest_ndigis = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			else if (*p == FAC_NATIONAL_FAIL_CALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				if (l < AX25_ADDR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 					return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				memcpy(&facilities->fail_call, p + 2, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			else if (*p == FAC_NATIONAL_FAIL_ADD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 				if (l < 1 + ROSE_ADDR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 					return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				memcpy(&facilities->fail_addr, p + 3, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			else if (*p == FAC_NATIONAL_DIGIS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				if (l % AX25_ADDR_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 					return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				fac_national_digis_received = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 				facilities->source_ndigis = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 				facilities->dest_ndigis   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 				for (pt = p + 2, lg = 0 ; lg < l ; pt += AX25_ADDR_LEN, lg += AX25_ADDR_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 					if (pt[6] & AX25_HBIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 						if (facilities->dest_ndigis >= ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 							return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 						memcpy(&facilities->dest_digis[facilities->dest_ndigis++], pt, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 						if (facilities->source_ndigis >= ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 							return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 						memcpy(&facilities->source_digis[facilities->source_ndigis++], pt, AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			p   += l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			n   += l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			len -= l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	} while (*p != 0x00 && len > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int rose_parse_ccitt(unsigned char *p, struct rose_facilities_struct *facilities, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	unsigned char l, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	char callsign[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		switch (*p & 0xC0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			if (len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			p   += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			n   += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			len -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			if (len < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			p   += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			n   += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			len -= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		case 0x80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			if (len < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			p   += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			n   += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			len -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		case 0xC0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			if (len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			l = p[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			/* Prevent overflows*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			if (l < 10 || l > 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			if (*p == FAC_CCITT_DEST_NSAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				memcpy(&facilities->source_addr, p + 7, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				memcpy(callsign, p + 12,   l - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 				callsign[l - 10] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 				asc2ax(&facilities->source_call, callsign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			if (*p == FAC_CCITT_SRC_NSAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 				memcpy(&facilities->dest_addr, p + 7, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				memcpy(callsign, p + 12, l - 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				callsign[l - 10] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				asc2ax(&facilities->dest_call, callsign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			p   += l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			n   += l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			len -= l + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	} while (*p != 0x00 && len > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int rose_parse_facilities(unsigned char *p, unsigned packet_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct rose_facilities_struct *facilities)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	int facilities_len, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	facilities_len = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (facilities_len == 0 || (unsigned int)facilities_len > packet_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	while (facilities_len >= 3 && *p == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		facilities_len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		switch (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		case FAC_NATIONAL:		/* National */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			len = rose_parse_national(p + 1, facilities, facilities_len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		case FAC_CCITT:		/* CCITT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			len = rose_parse_ccitt(p + 1, facilities, facilities_len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			printk(KERN_DEBUG "ROSE: rose_parse_facilities - unknown facilities family %02X\n", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		if (WARN_ON(len >= facilities_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		facilities_len -= len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		p += len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return facilities_len == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int rose_create_facilities(unsigned char *buffer, struct rose_sock *rose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	unsigned char *p = buffer + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	char *callsign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	char buf[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	int len, nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/* National Facilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (rose->rand != 0 || rose->source_ndigis == 1 || rose->dest_ndigis == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		*p++ = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		*p++ = FAC_NATIONAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		if (rose->rand != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			*p++ = FAC_NATIONAL_RAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			*p++ = (rose->rand >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			*p++ = (rose->rand >> 0) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		/* Sent before older facilities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		if ((rose->source_ndigis > 0) || (rose->dest_ndigis > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			int maxdigi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			*p++ = FAC_NATIONAL_DIGIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			*p++ = AX25_ADDR_LEN * (rose->source_ndigis + rose->dest_ndigis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			for (nb = 0 ; nb < rose->source_ndigis ; nb++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				if (++maxdigi >= ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 				memcpy(p, &rose->source_digis[nb], AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 				p[6] |= AX25_HBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 				p += AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			for (nb = 0 ; nb < rose->dest_ndigis ; nb++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 				if (++maxdigi >= ROSE_MAX_DIGIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				memcpy(p, &rose->dest_digis[nb], AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				p[6] &= ~AX25_HBIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 				p += AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		/* For compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		if (rose->source_ndigis > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			*p++ = FAC_NATIONAL_SRC_DIGI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			*p++ = AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			memcpy(p, &rose->source_digis[0], AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			p   += AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		/* For compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		if (rose->dest_ndigis > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			*p++ = FAC_NATIONAL_DEST_DIGI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			*p++ = AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			memcpy(p, &rose->dest_digis[0], AX25_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			p   += AX25_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	*p++ = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	*p++ = FAC_CCITT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	*p++ = FAC_CCITT_DEST_NSAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	callsign = ax2asc(buf, &rose->dest_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	*p++ = strlen(callsign) + 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	*p++ = (strlen(callsign) + 9) * 2;		/* ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	*p++ = 0x47; *p++ = 0x00; *p++ = 0x11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	*p++ = ROSE_ADDR_LEN * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	memcpy(p, &rose->dest_addr, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	p   += ROSE_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	memcpy(p, callsign, strlen(callsign));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	p   += strlen(callsign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	*p++ = FAC_CCITT_SRC_NSAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	callsign = ax2asc(buf, &rose->source_call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	*p++ = strlen(callsign) + 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	*p++ = (strlen(callsign) + 9) * 2;		/* ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	*p++ = 0x47; *p++ = 0x00; *p++ = 0x11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	*p++ = ROSE_ADDR_LEN * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	memcpy(p, &rose->source_addr, ROSE_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	p   += ROSE_ADDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	memcpy(p, callsign, strlen(callsign));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	p   += strlen(callsign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	len       = p - buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	buffer[0] = len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) void rose_disconnect(struct sock *sk, int reason, int cause, int diagnostic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	rose_stop_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	rose_clear_queues(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	rose->lci   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	rose->state = ROSE_STATE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (cause != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		rose->cause = cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (diagnostic != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		rose->diagnostic = diagnostic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	sk->sk_state     = TCP_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	sk->sk_err       = reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	sk->sk_shutdown |= SEND_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	if (!sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		sock_set_flag(sk, SOCK_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }