llc_output.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <linux/if_arp.h>
  16. #include <linux/if_tr.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/trdevice.h>
  19. #include <linux/skbuff.h>
  20. #include <net/llc.h>
  21. #include <net/llc_pdu.h>
  22. /**
  23. * llc_mac_hdr_init - fills MAC header fields
  24. * @skb: Address of the frame to initialize its MAC header
  25. * @sa: The MAC source address
  26. * @da: The MAC destination address
  27. *
  28. * Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
  29. * is a valid type and initialization completes correctly 1, otherwise.
  30. */
  31. int llc_mac_hdr_init(struct sk_buff *skb,
  32. const unsigned char *sa, const unsigned char *da)
  33. {
  34. int rc = -EINVAL;
  35. switch (skb->dev->type) {
  36. case ARPHRD_IEEE802_TR:
  37. case ARPHRD_ETHER:
  38. case ARPHRD_LOOPBACK:
  39. rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
  40. skb->len);
  41. if (rc > 0)
  42. rc = 0;
  43. break;
  44. default:
  45. WARN(1, "device type not supported: %d\n", skb->dev->type);
  46. }
  47. return rc;
  48. }
  49. /**
  50. * llc_build_and_send_ui_pkt - unitdata request interface for upper layers
  51. * @sap: sap to use
  52. * @skb: packet to send
  53. * @dmac: destination mac address
  54. * @dsap: destination sap
  55. *
  56. * Upper layers calls this function when upper layer wants to send data
  57. * using connection-less mode communication (UI pdu).
  58. *
  59. * Accept data frame from network layer to be sent using connection-
  60. * less mode communication; timeout/retries handled by network layer;
  61. * package primitive as an event and send to SAP event handler
  62. */
  63. int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
  64. unsigned char *dmac, unsigned char dsap)
  65. {
  66. int rc;
  67. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  68. dsap, LLC_PDU_CMD);
  69. llc_pdu_init_as_ui_cmd(skb);
  70. rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
  71. if (likely(!rc))
  72. rc = dev_queue_xmit(skb);
  73. return rc;
  74. }
  75. EXPORT_SYMBOL(llc_mac_hdr_init);
  76. EXPORT_SYMBOL(llc_build_and_send_ui_pkt);