Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * llc_s_ac.c - actions performed during sap state transition.
0003  *
0004  * Description :
0005  *   Functions in this module are implementation of sap component actions.
0006  *   Details of actions can be found in IEEE-802.2 standard document.
0007  *   All functions have one sap and one event as input argument. All of
0008  *   them return 0 On success and 1 otherwise.
0009  *
0010  * Copyright (c) 1997 by Procom Technology, Inc.
0011  *       2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
0012  *
0013  * This program can be redistributed or modified under the terms of the
0014  * GNU General Public License as published by the Free Software Foundation.
0015  * This program is distributed without any warranty or implied warranty
0016  * of merchantability or fitness for a particular purpose.
0017  *
0018  * See the GNU General Public License for more details.
0019  */
0020 
0021 #include <linux/netdevice.h>
0022 #include <net/llc.h>
0023 #include <net/llc_pdu.h>
0024 #include <net/llc_s_ac.h>
0025 #include <net/llc_s_ev.h>
0026 #include <net/llc_sap.h>
0027 
0028 
0029 /**
0030  *  llc_sap_action_unitdata_ind - forward UI PDU to network layer
0031  *  @sap: SAP
0032  *  @skb: the event to forward
0033  *
0034  *  Received a UI PDU from MAC layer; forward to network layer as a
0035  *  UNITDATA INDICATION; verify our event is the kind we expect
0036  */
0037 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)
0038 {
0039     llc_sap_rtn_pdu(sap, skb);
0040     return 0;
0041 }
0042 
0043 /**
0044  *  llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
0045  *  @sap: SAP
0046  *  @skb: the event to send
0047  *
0048  *  Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
0049  *  primitive from the network layer. Verifies event is a primitive type of
0050  *  event. Verify the primitive is a UNITDATA REQUEST.
0051  */
0052 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
0053 {
0054     struct llc_sap_state_ev *ev = llc_sap_ev(skb);
0055     int rc;
0056 
0057     llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
0058                 ev->daddr.lsap, LLC_PDU_CMD);
0059     llc_pdu_init_as_ui_cmd(skb);
0060     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
0061     if (likely(!rc)) {
0062         skb_get(skb);
0063         rc = dev_queue_xmit(skb);
0064     }
0065     return rc;
0066 }
0067 
0068 /**
0069  *  llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
0070  *  @sap: SAP
0071  *  @skb: the event to send
0072  *
0073  *  Send a XID command PDU to MAC layer in response to a XID REQUEST
0074  *  primitive from the network layer. Verify event is a primitive type
0075  *  event. Verify the primitive is a XID REQUEST.
0076  */
0077 int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
0078 {
0079     struct llc_sap_state_ev *ev = llc_sap_ev(skb);
0080     int rc;
0081 
0082     llc_pdu_header_init(skb, LLC_PDU_TYPE_U_XID, ev->saddr.lsap,
0083                 ev->daddr.lsap, LLC_PDU_CMD);
0084     llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
0085     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
0086     if (likely(!rc)) {
0087         skb_get(skb);
0088         rc = dev_queue_xmit(skb);
0089     }
0090     return rc;
0091 }
0092 
0093 /**
0094  *  llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
0095  *  @sap: SAP
0096  *  @skb: the event to send
0097  *
0098  *  Send XID response PDU to MAC in response to an earlier received XID
0099  *  command PDU. Verify event is a PDU type event
0100  */
0101 int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
0102 {
0103     u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
0104     int rc = 1;
0105     struct sk_buff *nskb;
0106 
0107     llc_pdu_decode_sa(skb, mac_da);
0108     llc_pdu_decode_da(skb, mac_sa);
0109     llc_pdu_decode_ssap(skb, &dsap);
0110     nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
0111                    sizeof(struct llc_xid_info));
0112     if (!nskb)
0113         goto out;
0114     llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
0115                 LLC_PDU_RSP);
0116     llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
0117     rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
0118     if (likely(!rc))
0119         rc = dev_queue_xmit(nskb);
0120 out:
0121     return rc;
0122 }
0123 
0124 /**
0125  *  llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
0126  *  @sap: SAP
0127  *  @skb: the event to send
0128  *
0129  *  Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
0130  *  primitive from the network layer. Verify event is a primitive type
0131  *  event; verify the primitive is a TEST REQUEST.
0132  */
0133 int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
0134 {
0135     struct llc_sap_state_ev *ev = llc_sap_ev(skb);
0136     int rc;
0137 
0138     llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
0139                 ev->daddr.lsap, LLC_PDU_CMD);
0140     llc_pdu_init_as_test_cmd(skb);
0141     rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
0142     if (likely(!rc)) {
0143         skb_get(skb);
0144         rc = dev_queue_xmit(skb);
0145     }
0146     return rc;
0147 }
0148 
0149 int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
0150 {
0151     u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
0152     struct sk_buff *nskb;
0153     int rc = 1;
0154     u32 data_size;
0155 
0156     llc_pdu_decode_sa(skb, mac_da);
0157     llc_pdu_decode_da(skb, mac_sa);
0158     llc_pdu_decode_ssap(skb, &dsap);
0159 
0160     /* The test request command is type U (llc_len = 3) */
0161     data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
0162     nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
0163     if (!nskb)
0164         goto out;
0165     llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
0166                 LLC_PDU_RSP);
0167     llc_pdu_init_as_test_rsp(nskb, skb);
0168     rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
0169     if (likely(!rc))
0170         rc = dev_queue_xmit(nskb);
0171 out:
0172     return rc;
0173 }
0174 
0175 /**
0176  *  llc_sap_action_report_status - report data link status to layer mgmt
0177  *  @sap: SAP
0178  *  @skb: the event to send
0179  *
0180  *  Report data link status to layer management. Verify our event is the
0181  *  kind we expect.
0182  */
0183 int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
0184 {
0185     return 0;
0186 }
0187 
0188 /**
0189  *  llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
0190  *  @sap: SAP
0191  *  @skb: the event to send
0192  *
0193  *  Send a XID response PDU to the network layer via a XID INDICATION
0194  *  primitive.
0195  */
0196 int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
0197 {
0198     llc_sap_rtn_pdu(sap, skb);
0199     return 0;
0200 }
0201 
0202 /**
0203  *  llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
0204  *  @sap: SAP
0205  *  @skb: the event to send
0206  *
0207  *  Send a TEST response PDU to the network layer via a TEST INDICATION
0208  *  primitive. Verify our event is a PDU type event.
0209  */
0210 int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
0211 {
0212     llc_sap_rtn_pdu(sap, skb);
0213     return 0;
0214 }