llc_output.c 2.0 KB

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