/*1* llc_s_ac.c - actions performed during sap state transition.2*3* Description :4* Functions in this module are implementation of sap component actions.5* Details of actions can be found in IEEE-802.2 standard document.6* All functions have one sap and one event as input argument. All of7* them return 0 On success and 1 otherwise.8*9* Copyright (c) 1997 by Procom Technology, Inc.10* 2001-2003 by Arnaldo Carvalho de Melo <[email protected]>11*12* This program can be redistributed or modified under the terms of the13* GNU General Public License as published by the Free Software Foundation.14* This program is distributed without any warranty or implied warranty15* of merchantability or fitness for a particular purpose.16*17* See the GNU General Public License for more details.18*/1920#include <linux/netdevice.h>21#include <net/llc.h>22#include <net/llc_pdu.h>23#include <net/llc_s_ac.h>24#include <net/llc_s_ev.h>25#include <net/llc_sap.h>262728/**29* llc_sap_action_unit_data_ind - forward UI PDU to network layer30* @sap: SAP31* @skb: the event to forward32*33* Received a UI PDU from MAC layer; forward to network layer as a34* UNITDATA INDICATION; verify our event is the kind we expect35*/36int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)37{38llc_sap_rtn_pdu(sap, skb);39return 0;40}4142/**43* llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer44* @sap: SAP45* @skb: the event to send46*47* Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST48* primitive from the network layer. Verifies event is a primitive type of49* event. Verify the primitive is a UNITDATA REQUEST.50*/51int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)52{53struct llc_sap_state_ev *ev = llc_sap_ev(skb);54int rc;5556llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,57ev->daddr.lsap, LLC_PDU_CMD);58llc_pdu_init_as_ui_cmd(skb);59rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);60if (likely(!rc))61rc = dev_queue_xmit(skb);62return rc;63}6465/**66* llc_sap_action_send_xid_c - send XID PDU as response to XID REQ67* @sap: SAP68* @skb: the event to send69*70* Send a XID command PDU to MAC layer in response to a XID REQUEST71* primitive from the network layer. Verify event is a primitive type72* event. Verify the primitive is a XID REQUEST.73*/74int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)75{76struct llc_sap_state_ev *ev = llc_sap_ev(skb);77int rc;7879llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,80ev->daddr.lsap, LLC_PDU_CMD);81llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);82rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);83if (likely(!rc))84rc = dev_queue_xmit(skb);85return rc;86}8788/**89* llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID90* @sap: SAP91* @skb: the event to send92*93* Send XID response PDU to MAC in response to an earlier received XID94* command PDU. Verify event is a PDU type event95*/96int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)97{98u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;99int rc = 1;100struct sk_buff *nskb;101102llc_pdu_decode_sa(skb, mac_da);103llc_pdu_decode_da(skb, mac_sa);104llc_pdu_decode_ssap(skb, &dsap);105nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,106sizeof(struct llc_xid_info));107if (!nskb)108goto out;109llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,110LLC_PDU_RSP);111llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);112rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);113if (likely(!rc))114rc = dev_queue_xmit(nskb);115out:116return rc;117}118119/**120* llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ121* @sap: SAP122* @skb: the event to send123*124* Send a TEST command PDU to the MAC layer in response to a TEST REQUEST125* primitive from the network layer. Verify event is a primitive type126* event; verify the primitive is a TEST REQUEST.127*/128int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)129{130struct llc_sap_state_ev *ev = llc_sap_ev(skb);131int rc;132133llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,134ev->daddr.lsap, LLC_PDU_CMD);135llc_pdu_init_as_test_cmd(skb);136rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);137if (likely(!rc))138rc = dev_queue_xmit(skb);139return rc;140}141142int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)143{144u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;145struct sk_buff *nskb;146int rc = 1;147u32 data_size;148149llc_pdu_decode_sa(skb, mac_da);150llc_pdu_decode_da(skb, mac_sa);151llc_pdu_decode_ssap(skb, &dsap);152153/* The test request command is type U (llc_len = 3) */154data_size = ntohs(eth_hdr(skb)->h_proto) - 3;155nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);156if (!nskb)157goto out;158llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,159LLC_PDU_RSP);160llc_pdu_init_as_test_rsp(nskb, skb);161rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);162if (likely(!rc))163rc = dev_queue_xmit(nskb);164out:165return rc;166}167168/**169* llc_sap_action_report_status - report data link status to layer mgmt170* @sap: SAP171* @skb: the event to send172*173* Report data link status to layer management. Verify our event is the174* kind we expect.175*/176int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)177{178return 0;179}180181/**182* llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND183* @sap: SAP184* @skb: the event to send185*186* Send a XID response PDU to the network layer via a XID INDICATION187* primitive.188*/189int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)190{191llc_sap_rtn_pdu(sap, skb);192return 0;193}194195/**196* llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND197* @sap: SAP198* @skb: the event to send199*200* Send a TEST response PDU to the network layer via a TEST INDICATION201* primitive. Verify our event is a PDU type event.202*/203int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)204{205llc_sap_rtn_pdu(sap, skb);206return 0;207}208209210