llc_station.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * llc_station.c - station component of LLC
  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 as published by the Free Software Foundation.
  9. * This program is distributed without any warranty or implied warranty
  10. * of merchantability or fitness for a particular purpose.
  11. *
  12. * See the GNU General Public License for more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/slab.h>
  17. #include <net/llc.h>
  18. #include <net/llc_sap.h>
  19. #include <net/llc_conn.h>
  20. #include <net/llc_c_ac.h>
  21. #include <net/llc_s_ac.h>
  22. #include <net/llc_c_ev.h>
  23. #include <net/llc_c_st.h>
  24. #include <net/llc_s_ev.h>
  25. #include <net/llc_s_st.h>
  26. #include <net/llc_pdu.h>
  27. static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb)
  28. {
  29. struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
  30. return LLC_PDU_IS_CMD(pdu) && /* command PDU */
  31. LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
  32. LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID &&
  33. !pdu->dsap; /* NULL DSAP value */
  34. }
  35. static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb)
  36. {
  37. struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
  38. return LLC_PDU_IS_CMD(pdu) && /* command PDU */
  39. LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
  40. LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST &&
  41. !pdu->dsap; /* NULL DSAP */
  42. }
  43. static int llc_station_ac_send_xid_r(struct sk_buff *skb)
  44. {
  45. u8 mac_da[ETH_ALEN], dsap;
  46. int rc = 1;
  47. struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
  48. sizeof(struct llc_xid_info));
  49. if (!nskb)
  50. goto out;
  51. rc = 0;
  52. llc_pdu_decode_sa(skb, mac_da);
  53. llc_pdu_decode_ssap(skb, &dsap);
  54. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
  55. llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
  56. rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da);
  57. if (unlikely(rc))
  58. goto free;
  59. dev_queue_xmit(nskb);
  60. out:
  61. return rc;
  62. free:
  63. kfree_skb(nskb);
  64. goto out;
  65. }
  66. static int llc_station_ac_send_test_r(struct sk_buff *skb)
  67. {
  68. u8 mac_da[ETH_ALEN], dsap;
  69. int rc = 1;
  70. u32 data_size;
  71. struct sk_buff *nskb;
  72. /* The test request command is type U (llc_len = 3) */
  73. data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
  74. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
  75. if (!nskb)
  76. goto out;
  77. rc = 0;
  78. llc_pdu_decode_sa(skb, mac_da);
  79. llc_pdu_decode_ssap(skb, &dsap);
  80. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
  81. llc_pdu_init_as_test_rsp(nskb, skb);
  82. rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da);
  83. if (unlikely(rc))
  84. goto free;
  85. dev_queue_xmit(nskb);
  86. out:
  87. return rc;
  88. free:
  89. kfree_skb(nskb);
  90. goto out;
  91. }
  92. /**
  93. * llc_station_rcv - send received pdu to the station state machine
  94. * @skb: received frame.
  95. *
  96. * Sends data unit to station state machine.
  97. */
  98. static void llc_station_rcv(struct sk_buff *skb)
  99. {
  100. if (llc_stat_ev_rx_null_dsap_xid_c(skb))
  101. llc_station_ac_send_xid_r(skb);
  102. else if (llc_stat_ev_rx_null_dsap_test_c(skb))
  103. llc_station_ac_send_test_r(skb);
  104. kfree_skb(skb);
  105. }
  106. void __init llc_station_init(void)
  107. {
  108. llc_set_station_handler(llc_station_rcv);
  109. }
  110. void llc_station_exit(void)
  111. {
  112. llc_set_station_handler(NULL);
  113. }