llc_output.c 2.3 KB

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