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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * llc_pdu.c - access to PDU internals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 1997 by Procom Technology, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *		 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This program can be redistributed or modified under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * GNU General Public License as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This program is distributed without any warranty or implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * of merchantability or fitness for a particular purpose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * See the GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/llc_pdu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 pdu_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	llc_pdu_un_hdr(skb)->ssap |= pdu_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	pdu_set_pf_bit - sets poll/final bit in LLC header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *	@skb: Frame to set bit in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *	@bit_value: poll/final bit (0 or 1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *	This function sets poll/final bit in LLC header (based on type of PDU).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *	in I or S pdus, p/f bit is right bit of fourth byte in header. in U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *	pdus p/f bit is fifth bit of third byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u8 pdu_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct llc_pdu_sn *pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	llc_pdu_decode_pdu_type(skb, &pdu_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	switch (pdu_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	case LLC_PDU_TYPE_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	case LLC_PDU_TYPE_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		pdu->ctrl_2 = (pdu->ctrl_2 & 0xFE) | bit_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	case LLC_PDU_TYPE_U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		pdu->ctrl_1 |= (pdu->ctrl_1 & 0xEF) | (bit_value << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^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)  *	llc_pdu_decode_pf_bit - extracs poll/final bit from LLC header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *	@skb: input skb that p/f bit must be extracted from it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *	@pf_bit: poll/final bit (0 or 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *	This function extracts poll/final bit from LLC header (based on type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *	PDU). In I or S pdus, p/f bit is right bit of fourth byte in header. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *	U pdus p/f bit is fifth bit of third byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) void llc_pdu_decode_pf_bit(struct sk_buff *skb, u8 *pf_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u8 pdu_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct llc_pdu_sn *pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	llc_pdu_decode_pdu_type(skb, &pdu_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	switch (pdu_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	case LLC_PDU_TYPE_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case LLC_PDU_TYPE_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		*pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	case LLC_PDU_TYPE_U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		*pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *	llc_pdu_init_as_disc_cmd - Builds DISC PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	Builds a pdu frame as a DISC command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) void llc_pdu_init_as_disc_cmd(struct sk_buff *skb, u8 p_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	pdu->ctrl_1  = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	pdu->ctrl_1 |= LLC_2_PDU_CMD_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *	llc_pdu_init_as_i_cmd - builds I pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *	@ns: The sequence number of the data PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  *	@nr: The seq. number of the expected I PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *	Builds a pdu frame as an I command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) void llc_pdu_init_as_i_cmd(struct sk_buff *skb, u8 p_bit, u8 ns, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	pdu->ctrl_1  = LLC_PDU_TYPE_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	pdu->ctrl_2 |= (p_bit & LLC_I_PF_BIT_MASK); /* p/f bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pdu->ctrl_1 |= (ns << 1) & 0xFE;   /* set N(S) in bits 2..8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	pdu->ctrl_2 |= (nr << 1) & 0xFE;   /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *	llc_pdu_init_as_rej_cmd - builds REJ PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *	@nr: The seq. number of the expected I PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *	Builds a pdu frame as a REJ command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void llc_pdu_init_as_rej_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	pdu->ctrl_1 |= LLC_2_PDU_CMD_REJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *	llc_pdu_init_as_rnr_cmd - builds RNR pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  *	@nr: The seq. number of the expected I PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  *	Builds a pdu frame as an RNR command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void llc_pdu_init_as_rnr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	pdu->ctrl_1 |= LLC_2_PDU_CMD_RNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	pdu->ctrl_2 |= p_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *	llc_pdu_init_as_rr_cmd - Builds RR pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *	@nr: The seq. number of the expected I PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *	Builds a pdu frame as an RR command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void llc_pdu_init_as_rr_cmd(struct sk_buff *skb, u8 p_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	pdu->ctrl_1 |= LLC_2_PDU_CMD_RR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	pdu->ctrl_2  = p_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	pdu->ctrl_2 |= (nr << 1) & 0xFE; /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *	llc_pdu_init_as_sabme_cmd - builds SABME pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *	@p_bit: The P bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *	Builds a pdu frame as an SABME command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) void llc_pdu_init_as_sabme_cmd(struct sk_buff *skb, u8 p_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	pdu->ctrl_1  = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	pdu->ctrl_1 |= LLC_2_PDU_CMD_SABME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	pdu->ctrl_1 |= ((p_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *	llc_pdu_init_as_dm_rsp - builds DM response pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *	Builds a pdu frame as a DM response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) void llc_pdu_init_as_dm_rsp(struct sk_buff *skb, u8 f_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	pdu->ctrl_1  = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_DM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  *	llc_pdu_init_as_frmr_rsp - builds FRMR response PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  *	@skb: Address of the frame to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  *	@prev_pdu: The rejected PDU frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *	@vs: tx state vari value for the data link conn at the rejecting LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  *	@vr: rx state var value for the data link conn at the rejecting LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  *	@vzyxw: completely described in the IEEE Std 802.2 document (Pg 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *	Builds a pdu frame as a FRMR response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void llc_pdu_init_as_frmr_rsp(struct sk_buff *skb, struct llc_pdu_sn *prev_pdu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			      u8 f_bit, u8 vs, u8 vr, u8 vzyxw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct llc_frmr_info *frmr_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	u8 prev_pf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	u8 *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	pdu->ctrl_1  = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_FRMR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	frmr_info = (struct llc_frmr_info *)&pdu->ctrl_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	ctrl = (u8 *)&prev_pdu->ctrl_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	FRMR_INFO_SET_REJ_CNTRL(frmr_info,ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	FRMR_INFO_SET_Vs(frmr_info, vs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	FRMR_INFO_SET_Vr(frmr_info, vr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	prev_pf = llc_pdu_get_pf_bit(prev_pdu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	FRMR_INFO_SET_C_R_BIT(frmr_info, prev_pf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	FRMR_INFO_SET_INVALID_PDU_CTRL_IND(frmr_info, vzyxw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	FRMR_INFO_SET_INVALID_PDU_INFO_IND(frmr_info, vzyxw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	FRMR_INFO_SET_PDU_INFO_2LONG_IND(frmr_info, vzyxw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	FRMR_INFO_SET_PDU_INVALID_Nr_IND(frmr_info, vzyxw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	FRMR_INFO_SET_PDU_INVALID_Ns_IND(frmr_info, vzyxw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	skb_put(skb, sizeof(struct llc_frmr_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^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)  *	llc_pdu_init_as_rr_rsp - builds RR response pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  *	@nr: The seq. number of the expected data PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *	Builds a pdu frame as an RR response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void llc_pdu_init_as_rr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_RR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	pdu->ctrl_2 |= (nr << 1) & 0xFE;  /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^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)  *	llc_pdu_init_as_rej_rsp - builds REJ response pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *	@skb: Address of the skb to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  *	@nr: The seq. number of the expected data PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  *	Builds a pdu frame as a REJ response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void llc_pdu_init_as_rej_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_REJ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	pdu->ctrl_2 |= (nr << 1) & 0xFE;  /* set N(R) in bits 10..16 */
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  *	llc_pdu_init_as_rnr_rsp - builds RNR response pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  *	@skb: Address of the frame to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  *	@nr: The seq. number of the expected data PDU from the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  *	Builds a pdu frame as an RNR response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) void llc_pdu_init_as_rnr_rsp(struct sk_buff *skb, u8 f_bit, u8 nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	pdu->ctrl_1  = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_RNR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	pdu->ctrl_2  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	pdu->ctrl_2 |= f_bit & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	pdu->ctrl_1 &= 0x0F;    /* setting bits 5..8 to zero(reserved) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	pdu->ctrl_2 |= (nr << 1) & 0xFE;  /* set N(R) in bits 10..16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^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)  *	llc_pdu_init_as_ua_rsp - builds UA response pdu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *	@skb: Address of the frame to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  *	@f_bit: The F bit to set in the PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *	Builds a pdu frame as a UA response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) void llc_pdu_init_as_ua_rsp(struct sk_buff *skb, u8 f_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	pdu->ctrl_1  = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	pdu->ctrl_1 |= LLC_2_PDU_RSP_UA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	pdu->ctrl_1 |= ((f_bit & 1) << 4) & LLC_U_PF_BIT_MASK;
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  *	llc_pdu_decode_pdu_type - designates PDU type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  *	@skb: input skb that type of it must be designated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  *	@type: type of PDU (output argument).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *	This function designates type of PDU (I, S or U).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static void llc_pdu_decode_pdu_type(struct sk_buff *skb, u8 *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (pdu->ctrl_1 & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			*type = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			*type = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		*type = LLC_PDU_TYPE_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)  *	llc_pdu_get_pf_bit - extracts p/f bit of input PDU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  *	@pdu: pointer to LLC header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  *	This function extracts p/f bit of input PDU. at first examines type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  *	PDU and then extracts p/f bit. Returns the p/f bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static u8 llc_pdu_get_pf_bit(struct llc_pdu_sn *pdu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	u8 pdu_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	u8 pf_bit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (pdu->ctrl_1 & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if ((pdu->ctrl_1 & LLC_PDU_TYPE_U) == LLC_PDU_TYPE_U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			pdu_type = LLC_PDU_TYPE_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			pdu_type = LLC_PDU_TYPE_S;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		pdu_type = LLC_PDU_TYPE_I;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	switch (pdu_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	case LLC_PDU_TYPE_I:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	case LLC_PDU_TYPE_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		pf_bit = pdu->ctrl_2 & LLC_S_PF_BIT_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	case LLC_PDU_TYPE_U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		pf_bit = (pdu->ctrl_1 & LLC_U_PF_BIT_MASK) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return pf_bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }