llc_output.c 2.9 KB

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