blob: b38a1079a98eac59dd1737b6f5bb7e7bf5437a54 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * llc_output.c - LLC minimal output path
3 *
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 *
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License version 2 as published by the Free Software
9 * Foundation.
10 * This program is distributed without any warranty or implied warranty
11 * of merchantability or fitness for a particular purpose.
12 *
13 * See the GNU General Public License version 2 for more details.
14 */
15
16#include <linux/if_arp.h>
17#include <linux/if_tr.h>
18#include <linux/netdevice.h>
19#include <linux/trdevice.h>
20#include <linux/skbuff.h>
21#include <net/llc.h>
22#include <net/llc_pdu.h>
23
24/**
25 * llc_mac_hdr_init - fills MAC header fields
26 * @skb: Address of the frame to initialize its MAC header
27 * @sa: The MAC source address
28 * @da: The MAC destination address
29 *
30 * Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
31 * is a valid type and initialization completes correctly 1, otherwise.
32 */
Stephen Hemmingerf4ad2b12006-03-20 22:59:36 -080033int llc_mac_hdr_init(struct sk_buff *skb,
34 const unsigned char *sa, const unsigned char *da)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Octavian Purdilabf9ae532009-12-26 11:50:59 +000036 int rc = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 switch (skb->dev->type) {
Octavian Purdilabf9ae532009-12-26 11:50:59 +000039 case ARPHRD_IEEE802_TR:
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 case ARPHRD_ETHER:
Octavian Purdilabf9ae532009-12-26 11:50:59 +000041 case ARPHRD_LOOPBACK:
42 rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
43 skb->len);
44 if (rc > 0)
45 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 default:
Octavian Purdilabf9ae532009-12-26 11:50:59 +000048 WARN(1, "device type not supported: %d\n", skb->dev->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 }
50 return rc;
51}
52
53/**
54 * llc_build_and_send_ui_pkt - unitdata request interface for upper layers
55 * @sap: sap to use
56 * @skb: packet to send
57 * @dmac: destination mac address
58 * @dsap: destination sap
59 *
60 * Upper layers calls this function when upper layer wants to send data
61 * using connection-less mode communication (UI pdu).
62 *
63 * Accept data frame from network layer to be sent using connection-
64 * less mode communication; timeout/retries handled by network layer;
65 * package primitive as an event and send to SAP event handler
66 */
67int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
68 unsigned char *dmac, unsigned char dsap)
69{
70 int rc;
71 llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
72 dsap, LLC_PDU_CMD);
73 llc_pdu_init_as_ui_cmd(skb);
74 rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -030075 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 rc = dev_queue_xmit(skb);
77 return rc;
78}
79
80EXPORT_SYMBOL(llc_mac_hdr_init);
81EXPORT_SYMBOL(llc_build_and_send_ui_pkt);