^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * llc_s_ac.c - actions performed during sap state transition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Description :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Functions in this module are implementation of sap component actions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Details of actions can be found in IEEE-802.2 standard document.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * All functions have one sap and one event as input argument. All of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * them return 0 On success and 1 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 1997 by Procom Technology, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * This program can be redistributed or modified under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * GNU General Public License as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This program is distributed without any warranty or implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * of merchantability or fitness for a particular purpose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * See the GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/llc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/llc_pdu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/llc_s_ac.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/llc_s_ev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <net/llc_sap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * llc_sap_action_unit_data_ind - forward UI PDU to network layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @skb: the event to forward
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Received a UI PDU from MAC layer; forward to network layer as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * UNITDATA INDICATION; verify our event is the kind we expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) llc_sap_rtn_pdu(sap, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * primitive from the network layer. Verifies event is a primitive type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * event. Verify the primitive is a UNITDATA REQUEST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct llc_sap_state_ev *ev = llc_sap_ev(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ev->daddr.lsap, LLC_PDU_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) llc_pdu_init_as_ui_cmd(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (likely(!rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) skb_get(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) rc = dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Send a XID command PDU to MAC layer in response to a XID REQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * primitive from the network layer. Verify event is a primitive type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * event. Verify the primitive is a XID REQUEST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct llc_sap_state_ev *ev = llc_sap_ev(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) llc_pdu_header_init(skb, LLC_PDU_TYPE_U_XID, ev->saddr.lsap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ev->daddr.lsap, LLC_PDU_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (likely(!rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) skb_get(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) rc = dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Send XID response PDU to MAC in response to an earlier received XID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * command PDU. Verify event is a PDU type event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) llc_pdu_decode_sa(skb, mac_da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) llc_pdu_decode_da(skb, mac_sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) llc_pdu_decode_ssap(skb, &dsap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) sizeof(struct llc_xid_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!nskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) LLC_PDU_RSP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (likely(!rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rc = dev_queue_xmit(nskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * primitive from the network layer. Verify event is a primitive type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * event; verify the primitive is a TEST REQUEST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct llc_sap_state_ev *ev = llc_sap_ev(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ev->daddr.lsap, LLC_PDU_CMD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) llc_pdu_init_as_test_cmd(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (likely(!rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) skb_get(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) rc = dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) u32 data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) llc_pdu_decode_sa(skb, mac_da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) llc_pdu_decode_da(skb, mac_sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) llc_pdu_decode_ssap(skb, &dsap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* The test request command is type U (llc_len = 3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!nskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) LLC_PDU_RSP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) llc_pdu_init_as_test_rsp(nskb, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (likely(!rc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) rc = dev_queue_xmit(nskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * llc_sap_action_report_status - report data link status to layer mgmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Report data link status to layer management. Verify our event is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * kind we expect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Send a XID response PDU to the network layer via a XID INDICATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * primitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) llc_sap_rtn_pdu(sap, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * @sap: SAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * @skb: the event to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * Send a TEST response PDU to the network layer via a TEST INDICATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * primitive. Verify our event is a PDU type event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) llc_sap_rtn_pdu(sap, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }