| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 21 | #include <linux/export.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <net/llc.h> | 
 | 23 | #include <net/llc_pdu.h> | 
 | 24 |  | 
 | 25 | /** | 
 | 26 |  *	llc_mac_hdr_init - fills MAC header fields | 
 | 27 |  *	@skb: Address of the frame to initialize its MAC header | 
 | 28 |  *	@sa: The MAC source address | 
 | 29 |  *	@da: The MAC destination address | 
 | 30 |  * | 
 | 31 |  *	Fills MAC header fields, depending on MAC type. Returns 0, If MAC type | 
 | 32 |  *	is a valid type and initialization completes correctly 1, otherwise. | 
 | 33 |  */ | 
| Stephen Hemminger | f4ad2b1 | 2006-03-20 22:59:36 -0800 | [diff] [blame] | 34 | int llc_mac_hdr_init(struct sk_buff *skb, | 
 | 35 | 		     const unsigned char *sa, const unsigned char *da) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { | 
| Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 37 | 	int rc = -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
 | 39 | 	switch (skb->dev->type) { | 
| Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 40 | 	case ARPHRD_IEEE802_TR: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | 	case ARPHRD_ETHER: | 
| Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 42 | 	case ARPHRD_LOOPBACK: | 
 | 43 | 		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa, | 
 | 44 | 				     skb->len); | 
 | 45 | 		if (rc > 0) | 
 | 46 | 			rc = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | 	default: | 
| Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 49 | 		WARN(1, "device type not supported: %d\n", skb->dev->type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | 	} | 
 | 51 | 	return rc; | 
 | 52 | } | 
 | 53 |  | 
 | 54 | /** | 
 | 55 |  *	llc_build_and_send_ui_pkt - unitdata request interface for upper layers | 
 | 56 |  *	@sap: sap to use | 
 | 57 |  *	@skb: packet to send | 
 | 58 |  *	@dmac: destination mac address | 
 | 59 |  *	@dsap: destination sap | 
 | 60 |  * | 
 | 61 |  *	Upper layers calls this function when upper layer wants to send data | 
 | 62 |  *	using connection-less mode communication (UI pdu). | 
 | 63 |  * | 
 | 64 |  *	Accept data frame from network layer to be sent using connection- | 
 | 65 |  *	less mode communication; timeout/retries handled by network layer; | 
 | 66 |  *	package primitive as an event and send to SAP event handler | 
 | 67 |  */ | 
 | 68 | int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, | 
 | 69 | 			      unsigned char *dmac, unsigned char dsap) | 
 | 70 | { | 
 | 71 | 	int rc; | 
 | 72 | 	llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap, | 
 | 73 | 			    dsap, LLC_PDU_CMD); | 
 | 74 | 	llc_pdu_init_as_ui_cmd(skb); | 
 | 75 | 	rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac); | 
| Arnaldo Carvalho de Melo | 249ff1c | 2005-09-22 04:32:10 -0300 | [diff] [blame] | 76 | 	if (likely(!rc)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 		rc = dev_queue_xmit(skb); | 
 | 78 | 	return rc; | 
 | 79 | } | 
 | 80 |  | 
 | 81 | EXPORT_SYMBOL(llc_mac_hdr_init); | 
 | 82 | EXPORT_SYMBOL(llc_build_and_send_ui_pkt); |