xref: /linux/net/llc/llc_s_ev.c (revision 90e63d5354951d37fa2b3b91e6f17b95d2bf9bee)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * llc_s_ev.c - Defines SAP component events
4  *
5  * The followed event functions are SAP component events which are described
6  * in 802.2 LLC protocol standard document.
7  *
8  * Copyright (c) 1997 by Procom Technology, Inc.
9  *		 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10  */
11 #include <linux/socket.h>
12 #include <net/sock.h>
13 #include <net/llc_if.h>
14 #include <net/llc_s_ev.h>
15 #include <net/llc_pdu.h>
16 
17 int llc_sap_ev_activation_req(struct llc_sap *sap, struct sk_buff *skb)
18 {
19 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
20 
21 	return ev->type == LLC_SAP_EV_TYPE_SIMPLE &&
22 	       ev->prim_type == LLC_SAP_EV_ACTIVATION_REQ ? 0 : 1;
23 }
24 
25 int llc_sap_ev_rx_ui(struct llc_sap *sap, struct sk_buff *skb)
26 {
27 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
28 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
29 
30 	return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) &&
31 	       LLC_PDU_TYPE_IS_U(pdu) &&
32 	       LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_UI ? 0 : 1;
33 }
34 
35 int llc_sap_ev_unitdata_req(struct llc_sap *sap, struct sk_buff *skb)
36 {
37 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
38 
39 	return ev->type == LLC_SAP_EV_TYPE_PRIM &&
40 	       ev->prim == LLC_DATAUNIT_PRIM &&
41 	       ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
42 
43 }
44 
45 int llc_sap_ev_xid_req(struct llc_sap *sap, struct sk_buff *skb)
46 {
47 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
48 
49 	return ev->type == LLC_SAP_EV_TYPE_PRIM &&
50 	       ev->prim == LLC_XID_PRIM &&
51 	       ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
52 }
53 
54 int llc_sap_ev_rx_xid_c(struct llc_sap *sap, struct sk_buff *skb)
55 {
56 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
57 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
58 
59 	return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) &&
60 	       LLC_PDU_TYPE_IS_U(pdu) &&
61 	       LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID ? 0 : 1;
62 }
63 
64 int llc_sap_ev_rx_xid_r(struct llc_sap *sap, struct sk_buff *skb)
65 {
66 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
67 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
68 
69 	return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_RSP(pdu) &&
70 	       LLC_PDU_TYPE_IS_U(pdu) &&
71 	       LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID ? 0 : 1;
72 }
73 
74 int llc_sap_ev_test_req(struct llc_sap *sap, struct sk_buff *skb)
75 {
76 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
77 
78 	return ev->type == LLC_SAP_EV_TYPE_PRIM &&
79 	       ev->prim == LLC_TEST_PRIM &&
80 	       ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
81 }
82 
83 int llc_sap_ev_rx_test_c(struct llc_sap *sap, struct sk_buff *skb)
84 {
85 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
86 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
87 
88 	return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_CMD(pdu) &&
89 	       LLC_PDU_TYPE_IS_U(pdu) &&
90 	       LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST ? 0 : 1;
91 }
92 
93 int llc_sap_ev_rx_test_r(struct llc_sap *sap, struct sk_buff *skb)
94 {
95 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
96 	struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
97 
98 	return ev->type == LLC_SAP_EV_TYPE_PDU && LLC_PDU_IS_RSP(pdu) &&
99 	       LLC_PDU_TYPE_IS_U(pdu) &&
100 	       LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_TEST ? 0 : 1;
101 }
102 
103 int llc_sap_ev_deactivation_req(struct llc_sap *sap, struct sk_buff *skb)
104 {
105 	struct llc_sap_state_ev *ev = llc_sap_ev(skb);
106 
107 	return ev->type == LLC_SAP_EV_TYPE_SIMPLE &&
108 	       ev->prim_type == LLC_SAP_EV_DEACTIVATION_REQ ? 0 : 1;
109 }
110