Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * llc_output.c - LLC minimal output path
0004  *
0005  * Copyright (c) 1997 by Procom Technology, Inc.
0006  *       2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
0007  */
0008 
0009 #include <linux/if_arp.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/skbuff.h>
0012 #include <linux/export.h>
0013 #include <net/llc.h>
0014 #include <net/llc_pdu.h>
0015 
0016 /**
0017  *  llc_mac_hdr_init - fills MAC header fields
0018  *  @skb: Address of the frame to initialize its MAC header
0019  *  @sa: The MAC source address
0020  *  @da: The MAC destination address
0021  *
0022  *  Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
0023  *  is a valid type and initialization completes correctly 1, otherwise.
0024  */
0025 int llc_mac_hdr_init(struct sk_buff *skb,
0026              const unsigned char *sa, const unsigned char *da)
0027 {
0028     int rc = -EINVAL;
0029 
0030     switch (skb->dev->type) {
0031     case ARPHRD_ETHER:
0032     case ARPHRD_LOOPBACK:
0033         rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
0034                      skb->len);
0035         if (rc > 0)
0036             rc = 0;
0037         break;
0038     default:
0039         break;
0040     }
0041     return rc;
0042 }
0043 
0044 /**
0045  *  llc_build_and_send_ui_pkt - unitdata request interface for upper layers
0046  *  @sap: sap to use
0047  *  @skb: packet to send
0048  *  @dmac: destination mac address
0049  *  @dsap: destination sap
0050  *
0051  *  Upper layers calls this function when upper layer wants to send data
0052  *  using connection-less mode communication (UI pdu).
0053  *
0054  *  Accept data frame from network layer to be sent using connection-
0055  *  less mode communication; timeout/retries handled by network layer;
0056  *  package primitive as an event and send to SAP event handler
0057  */
0058 int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
0059                   const unsigned char *dmac, unsigned char dsap)
0060 {
0061     int rc;
0062     llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0063                 dsap, LLC_PDU_CMD);
0064     llc_pdu_init_as_ui_cmd(skb);
0065     rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
0066     if (likely(!rc))
0067         rc = dev_queue_xmit(skb);
0068     else
0069         kfree_skb(skb);
0070     return rc;
0071 }
0072 
0073 EXPORT_SYMBOL(llc_mac_hdr_init);
0074 EXPORT_SYMBOL(llc_build_and_send_ui_pkt);