Thomas Gleixner | 0e9facc | 2019-05-29 07:17:55 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * llc_output.c - LLC minimal output path |
| 4 | * |
| 5 | * Copyright (c) 1997 by Procom Technology, Inc. |
| 6 | * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/if_arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/skbuff.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 12 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <net/llc.h> |
| 14 | #include <net/llc_pdu.h> |
| 15 | |
| 16 | /** |
| 17 | * llc_mac_hdr_init - fills MAC header fields |
| 18 | * @skb: Address of the frame to initialize its MAC header |
| 19 | * @sa: The MAC source address |
| 20 | * @da: The MAC destination address |
| 21 | * |
| 22 | * Fills MAC header fields, depending on MAC type. Returns 0, If MAC type |
| 23 | * is a valid type and initialization completes correctly 1, otherwise. |
| 24 | */ |
Stephen Hemminger | f4ad2b1 | 2006-03-20 22:59:36 -0800 | [diff] [blame] | 25 | int llc_mac_hdr_init(struct sk_buff *skb, |
| 26 | const unsigned char *sa, const unsigned char *da) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 28 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | switch (skb->dev->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | case ARPHRD_ETHER: |
Octavian Purdila | bf9ae53 | 2009-12-26 11:50:59 +0000 | [diff] [blame] | 32 | case ARPHRD_LOOPBACK: |
| 33 | rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa, |
| 34 | skb->len); |
| 35 | if (rc > 0) |
| 36 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | default: |
Dave Jones | 0f1a24c | 2014-01-28 16:30:52 -0500 | [diff] [blame] | 39 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | return rc; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * llc_build_and_send_ui_pkt - unitdata request interface for upper layers |
| 46 | * @sap: sap to use |
| 47 | * @skb: packet to send |
| 48 | * @dmac: destination mac address |
| 49 | * @dsap: destination sap |
| 50 | * |
| 51 | * Upper layers calls this function when upper layer wants to send data |
| 52 | * using connection-less mode communication (UI pdu). |
| 53 | * |
| 54 | * Accept data frame from network layer to be sent using connection- |
| 55 | * less mode communication; timeout/retries handled by network layer; |
| 56 | * package primitive as an event and send to SAP event handler |
| 57 | */ |
| 58 | int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, |
| 59 | unsigned char *dmac, unsigned char dsap) |
| 60 | { |
| 61 | int rc; |
| 62 | llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
| 63 | dsap, LLC_PDU_CMD); |
| 64 | llc_pdu_init_as_ui_cmd(skb); |
| 65 | 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] | 66 | if (likely(!rc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | rc = dev_queue_xmit(skb); |
Eric Dumazet | 8fb44d6 | 2019-05-27 17:35:52 -0700 | [diff] [blame] | 68 | else |
| 69 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return rc; |
| 71 | } |
| 72 | |
| 73 | EXPORT_SYMBOL(llc_mac_hdr_init); |
| 74 | EXPORT_SYMBOL(llc_build_and_send_ui_pkt); |