llc_output.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = 0;
  35. switch (skb->dev->type) {
  36. #ifdef CONFIG_TR
  37. case ARPHRD_IEEE802_TR: {
  38. struct net_device *dev = skb->dev;
  39. struct trh_hdr *trh;
  40. skb_push(skb, sizeof(*trh));
  41. skb_reset_mac_header(skb);
  42. trh = tr_hdr(skb);
  43. trh->ac = AC;
  44. trh->fc = LLC_FRAME;
  45. if (sa)
  46. memcpy(trh->saddr, sa, dev->addr_len);
  47. else
  48. memset(trh->saddr, 0, dev->addr_len);
  49. if (da) {
  50. memcpy(trh->daddr, da, dev->addr_len);
  51. tr_source_route(skb, trh, dev);
  52. skb_reset_mac_header(skb);
  53. }
  54. break;
  55. }
  56. #endif
  57. case ARPHRD_ETHER:
  58. case ARPHRD_LOOPBACK: {
  59. unsigned short len = skb->len;
  60. struct ethhdr *eth;
  61. skb_push(skb, sizeof(*eth));
  62. skb_reset_mac_header(skb);
  63. eth = eth_hdr(skb);
  64. eth->h_proto = htons(len);
  65. memcpy(eth->h_dest, da, ETH_ALEN);
  66. memcpy(eth->h_source, sa, ETH_ALEN);
  67. break;
  68. }
  69. default:
  70. printk(KERN_WARNING "device type not supported: %d\n",
  71. skb->dev->type);
  72. rc = -EINVAL;
  73. }
  74. return rc;
  75. }
  76. /**
  77. * llc_build_and_send_ui_pkt - unitdata request interface for upper layers
  78. * @sap: sap to use
  79. * @skb: packet to send
  80. * @dmac: destination mac address
  81. * @dsap: destination sap
  82. *
  83. * Upper layers calls this function when upper layer wants to send data
  84. * using connection-less mode communication (UI pdu).
  85. *
  86. * Accept data frame from network layer to be sent using connection-
  87. * less mode communication; timeout/retries handled by network layer;
  88. * package primitive as an event and send to SAP event handler
  89. */
  90. int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
  91. unsigned char *dmac, unsigned char dsap)
  92. {
  93. int rc;
  94. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  95. dsap, LLC_PDU_CMD);
  96. llc_pdu_init_as_ui_cmd(skb);
  97. rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
  98. if (likely(!rc))
  99. rc = dev_queue_xmit(skb);
  100. return rc;
  101. }
  102. EXPORT_SYMBOL(llc_mac_hdr_init);
  103. EXPORT_SYMBOL(llc_build_and_send_ui_pkt);