ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / llc / llc_output.c
1 /*
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  */
33 int llc_mac_hdr_init(struct sk_buff *skb, unsigned char *sa, unsigned char *da)
34 {
35         int rc = 0;
36
37         switch (skb->dev->type) {
38 #ifdef CONFIG_TR
39         case ARPHRD_IEEE802_TR: {
40                 struct net_device *dev = skb->dev;
41                 struct trh_hdr *trh;
42                 
43                 trh = (struct trh_hdr *)skb_push(skb, sizeof(*trh));
44                 trh->ac = AC;
45                 trh->fc = LLC_FRAME;
46                 if (sa)
47                         memcpy(trh->saddr, sa, dev->addr_len);
48                 else
49                         memset(trh->saddr, 0, dev->addr_len);
50                 if (da) {
51                         memcpy(trh->daddr, da, dev->addr_len);
52                         tr_source_route(skb, trh, dev);
53                 }
54                 skb->mac.raw = skb->data;
55                 break;
56         }
57 #endif
58         case ARPHRD_ETHER:
59         case ARPHRD_LOOPBACK: {
60                 unsigned short len = skb->len;
61                 struct ethhdr *eth;
62
63                 skb->mac.raw = skb_push(skb, sizeof(*eth));
64                 eth = (struct ethhdr *)skb->mac.raw;
65                 eth->h_proto = htons(len);
66                 memcpy(eth->h_dest, da, ETH_ALEN);
67                 memcpy(eth->h_source, sa, ETH_ALEN);
68                 break;
69         }
70         default:
71                 printk(KERN_WARNING "device type not supported: %d\n",
72                        skb->dev->type);
73                 rc = -EINVAL;
74         }
75         return rc;
76 }
77
78 /**
79  *      llc_build_and_send_ui_pkt - unitdata request interface for upper layers
80  *      @sap: sap to use
81  *      @skb: packet to send
82  *      @dmac: destination mac address
83  *      @dsap: destination sap
84  *
85  *      Upper layers calls this function when upper layer wants to send data
86  *      using connection-less mode communication (UI pdu).
87  *
88  *      Accept data frame from network layer to be sent using connection-
89  *      less mode communication; timeout/retries handled by network layer;
90  *      package primitive as an event and send to SAP event handler
91  */
92 int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
93                               unsigned char *dmac, unsigned char dsap)
94 {
95         int rc;
96         llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
97                             dsap, LLC_PDU_CMD);
98         llc_pdu_init_as_ui_cmd(skb);
99         rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
100         if (!rc)
101                 rc = dev_queue_xmit(skb);
102         return rc;
103 }
104
105 EXPORT_SYMBOL(llc_mac_hdr_init);
106 EXPORT_SYMBOL(llc_build_and_send_ui_pkt);