xref: /linux/include/net/llc.h (revision 0e59523b440c90ed1899476f32ad4e949282f43e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LLC_H
3 #define LLC_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/list.h>
10 #include <linux/refcount.h>
11 
12 struct net_device;
13 struct packet_type;
14 struct sk_buff;
15 
16 /**
17  * struct llc_sap - Defines the SAP component
18  *
19  * @refcnt: reference count
20  * @lsap: SAP number
21  * @rcv_func: handler for the PDUs addressed to this SAP
22  * @node: entry in the SAP list
23  * @rcu: for deferred freeing
24  */
25 struct llc_sap {
26 	refcount_t		 refcnt;
27 	unsigned char	 lsap;
28 	int		 (*rcv_func)(struct sk_buff *skb,
29 				     struct net_device *dev,
30 				     struct packet_type *pt,
31 				     struct net_device *orig_dev);
32 	struct list_head node;
33 	struct rcu_head rcu;
34 };
35 
36 int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
37 	    struct net_device *orig_dev);
38 
39 int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
40 		     const unsigned char *da);
41 
42 struct llc_sap *llc_sap_open(unsigned char lsap,
43 			     int (*rcv)(struct sk_buff *skb,
44 					struct net_device *dev,
45 					struct packet_type *pt,
46 					struct net_device *orig_dev));
47 
48 static inline bool llc_sap_hold_safe(struct llc_sap *sap)
49 {
50 	return refcount_inc_not_zero(&sap->refcnt);
51 }
52 
53 void llc_sap_close(struct llc_sap *sap);
54 
55 static inline void llc_sap_put(struct llc_sap *sap)
56 {
57 	if (refcount_dec_and_test(&sap->refcnt))
58 		llc_sap_close(sap);
59 }
60 
61 struct llc_sap *llc_sap_find(unsigned char sap_value);
62 
63 int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
64 			      const unsigned char *dmac, unsigned char dsap);
65 #endif /* LLC_H */
66