xref: /OK3568_Linux_fs/kernel/net/802/p8022.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *	NET3:	Support for 802.2 demultiplexing off Ethernet
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *		Demultiplex 802.2 encoded protocols. We match the entry by the
6*4882a593Smuzhiyun  *		SSAP/DSAP pair and then deliver to the registered datalink that
7*4882a593Smuzhiyun  *		matches. The control byte is ignored and handling of such items
8*4882a593Smuzhiyun  *		is up to the routine passed the frame.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *		Unlike the 802.3 datalink we have a list of 802.2 entries as
11*4882a593Smuzhiyun  *		there are multiple protocols to demux. The list is currently
12*4882a593Smuzhiyun  *		short (3 or 4 entries at most). The current demux assumes this.
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun #include <linux/netdevice.h>
16*4882a593Smuzhiyun #include <linux/skbuff.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <net/datalink.h>
19*4882a593Smuzhiyun #include <linux/mm.h>
20*4882a593Smuzhiyun #include <linux/in.h>
21*4882a593Smuzhiyun #include <linux/init.h>
22*4882a593Smuzhiyun #include <net/llc.h>
23*4882a593Smuzhiyun #include <net/p8022.h>
24*4882a593Smuzhiyun 
p8022_request(struct datalink_proto * dl,struct sk_buff * skb,unsigned char * dest)25*4882a593Smuzhiyun static int p8022_request(struct datalink_proto *dl, struct sk_buff *skb,
26*4882a593Smuzhiyun 			 unsigned char *dest)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun 	llc_build_and_send_ui_pkt(dl->sap, skb, dest, dl->sap->laddr.lsap);
29*4882a593Smuzhiyun 	return 0;
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun 
register_8022_client(unsigned char type,int (* func)(struct sk_buff * skb,struct net_device * dev,struct packet_type * pt,struct net_device * orig_dev))32*4882a593Smuzhiyun struct datalink_proto *register_8022_client(unsigned char type,
33*4882a593Smuzhiyun 					    int (*func)(struct sk_buff *skb,
34*4882a593Smuzhiyun 							struct net_device *dev,
35*4882a593Smuzhiyun 							struct packet_type *pt,
36*4882a593Smuzhiyun 							struct net_device *orig_dev))
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun 	struct datalink_proto *proto;
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 	proto = kmalloc(sizeof(*proto), GFP_ATOMIC);
41*4882a593Smuzhiyun 	if (proto) {
42*4882a593Smuzhiyun 		proto->type[0]		= type;
43*4882a593Smuzhiyun 		proto->header_length	= 3;
44*4882a593Smuzhiyun 		proto->request		= p8022_request;
45*4882a593Smuzhiyun 		proto->sap = llc_sap_open(type, func);
46*4882a593Smuzhiyun 		if (!proto->sap) {
47*4882a593Smuzhiyun 			kfree(proto);
48*4882a593Smuzhiyun 			proto = NULL;
49*4882a593Smuzhiyun 		}
50*4882a593Smuzhiyun 	}
51*4882a593Smuzhiyun 	return proto;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
unregister_8022_client(struct datalink_proto * proto)54*4882a593Smuzhiyun void unregister_8022_client(struct datalink_proto *proto)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun 	llc_sap_put(proto->sap);
57*4882a593Smuzhiyun 	kfree(proto);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun EXPORT_SYMBOL(register_8022_client);
61*4882a593Smuzhiyun EXPORT_SYMBOL(unregister_8022_client);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun MODULE_LICENSE("GPL");
64