1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef LLC_PDU_H 3 #define LLC_PDU_H 4 /* 5 * Copyright (c) 1997 by Procom Technology,Inc. 6 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> 7 */ 8 9 #include <linux/skbuff.h> 10 11 /* Command/response PDU indicator in SSAP field */ 12 #define LLC_PDU_CMD 0 13 #define LLC_PDU_RSP 1 14 15 /* Get PDU type from 2 lowest-order bits of control field first byte */ 16 #define LLC_PDU_TYPE_MASK 0x03 17 #define LLC_PDU_TYPE_U 3 /* first two bits */ 18 19 #define LLC_1_PDU_CMD_UI 0x00 /* Type 1 cmds/rsps */ 20 21 /* Un-numbered PDU format (3 bytes in length) */ 22 struct llc_pdu_un { 23 u8 dsap; 24 u8 ssap; 25 u8 ctrl_1; 26 } __packed; 27 28 static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb) 29 { 30 return (struct llc_pdu_un *)skb_network_header(skb); 31 } 32 33 /** 34 * llc_pdu_header_init - initializes pdu header 35 * @skb: input skb that header must be set into it. 36 * @ssap: source sap. 37 * @dsap: destination sap. 38 * @cr: command/response bit (%LLC_PDU_CMD or %LLC_PDU_RSP). 39 * 40 * This function sets DSAP, SSAP and command/Response bit in LLC header. 41 */ 42 static inline void llc_pdu_header_init(struct sk_buff *skb, u8 ssap, u8 dsap, 43 u8 cr) 44 { 45 struct llc_pdu_un *pdu; 46 47 skb_push(skb, sizeof(*pdu)); 48 skb_reset_network_header(skb); 49 pdu = llc_pdu_un_hdr(skb); 50 pdu->dsap = dsap; 51 pdu->ssap = ssap; 52 pdu->ssap |= cr; 53 } 54 55 /** 56 * llc_pdu_init_as_ui_cmd - sets LLC header as UI PDU 57 * @skb: input skb that header must be set into it. 58 * 59 * This function sets third byte of LLC header as a UI PDU. 60 */ 61 static inline void llc_pdu_init_as_ui_cmd(struct sk_buff *skb) 62 { 63 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 64 65 pdu->ctrl_1 = LLC_PDU_TYPE_U; 66 pdu->ctrl_1 |= LLC_1_PDU_CMD_UI; 67 } 68 69 #endif /* LLC_PDU_H */ 70