llc_s_ac.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * llc_s_ac.c - actions performed during sap state transition.
  3. *
  4. * Description :
  5. * Functions in this module are implementation of sap component actions.
  6. * Details of actions can be found in IEEE-802.2 standard document.
  7. * All functions have one sap and one event as input argument. All of
  8. * them return 0 On success and 1 otherwise.
  9. *
  10. * Copyright (c) 1997 by Procom Technology, Inc.
  11. * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  12. *
  13. * This program can be redistributed or modified under the terms of the
  14. * GNU General Public License as published by the Free Software Foundation.
  15. * This program is distributed without any warranty or implied warranty
  16. * of merchantability or fitness for a particular purpose.
  17. *
  18. * See the GNU General Public License for more details.
  19. */
  20. #include <linux/netdevice.h>
  21. #include <net/llc.h>
  22. #include <net/llc_pdu.h>
  23. #include <net/llc_s_ac.h>
  24. #include <net/llc_s_ev.h>
  25. #include <net/llc_sap.h>
  26. #include "llc_output.h"
  27. /**
  28. * llc_sap_action_unit_data_ind - forward UI PDU to network layer
  29. * @sap: SAP
  30. * @skb: the event to forward
  31. *
  32. * Received a UI PDU from MAC layer; forward to network layer as a
  33. * UNITDATA INDICATION; verify our event is the kind we expect
  34. */
  35. int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)
  36. {
  37. llc_sap_rtn_pdu(sap, skb);
  38. return 0;
  39. }
  40. /**
  41. * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
  42. * @sap: SAP
  43. * @skb: the event to send
  44. *
  45. * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
  46. * primitive from the network layer. Verifies event is a primitive type of
  47. * event. Verify the primitive is a UNITDATA REQUEST.
  48. */
  49. int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
  50. {
  51. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  52. int rc;
  53. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  54. ev->daddr.lsap, LLC_PDU_CMD);
  55. llc_pdu_init_as_ui_cmd(skb);
  56. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  57. if (likely(!rc))
  58. rc = dev_queue_xmit(skb);
  59. return rc;
  60. }
  61. /**
  62. * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
  63. * @sap: SAP
  64. * @skb: the event to send
  65. *
  66. * Send a XID command PDU to MAC layer in response to a XID REQUEST
  67. * primitive from the network layer. Verify event is a primitive type
  68. * event. Verify the primitive is a XID REQUEST.
  69. */
  70. int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
  71. {
  72. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  73. int rc;
  74. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  75. ev->daddr.lsap, LLC_PDU_CMD);
  76. llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
  77. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  78. if (likely(!rc))
  79. rc = dev_queue_xmit(skb);
  80. return rc;
  81. }
  82. /**
  83. * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
  84. * @sap: SAP
  85. * @skb: the event to send
  86. *
  87. * Send XID response PDU to MAC in response to an earlier received XID
  88. * command PDU. Verify event is a PDU type event
  89. */
  90. int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
  91. {
  92. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  93. int rc = 1;
  94. struct sk_buff *nskb;
  95. llc_pdu_decode_sa(skb, mac_da);
  96. llc_pdu_decode_da(skb, mac_sa);
  97. llc_pdu_decode_ssap(skb, &dsap);
  98. nskb = llc_alloc_frame(NULL, skb->dev);
  99. if (!nskb)
  100. goto out;
  101. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  102. LLC_PDU_RSP);
  103. llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
  104. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  105. if (likely(!rc))
  106. rc = dev_queue_xmit(nskb);
  107. out:
  108. return rc;
  109. }
  110. /**
  111. * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
  112. * @sap: SAP
  113. * @skb: the event to send
  114. *
  115. * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
  116. * primitive from the network layer. Verify event is a primitive type
  117. * event; verify the primitive is a TEST REQUEST.
  118. */
  119. int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
  120. {
  121. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  122. int rc;
  123. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  124. ev->daddr.lsap, LLC_PDU_CMD);
  125. llc_pdu_init_as_test_cmd(skb);
  126. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  127. if (likely(!rc))
  128. rc = dev_queue_xmit(skb);
  129. return rc;
  130. }
  131. int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
  132. {
  133. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  134. struct sk_buff *nskb;
  135. int rc = 1;
  136. llc_pdu_decode_sa(skb, mac_da);
  137. llc_pdu_decode_da(skb, mac_sa);
  138. llc_pdu_decode_ssap(skb, &dsap);
  139. nskb = llc_alloc_frame(NULL, skb->dev);
  140. if (!nskb)
  141. goto out;
  142. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  143. LLC_PDU_RSP);
  144. llc_pdu_init_as_test_rsp(nskb, skb);
  145. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  146. if (likely(!rc))
  147. rc = dev_queue_xmit(nskb);
  148. out:
  149. return rc;
  150. }
  151. /**
  152. * llc_sap_action_report_status - report data link status to layer mgmt
  153. * @sap: SAP
  154. * @skb: the event to send
  155. *
  156. * Report data link status to layer management. Verify our event is the
  157. * kind we expect.
  158. */
  159. int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
  160. {
  161. return 0;
  162. }
  163. /**
  164. * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
  165. * @sap: SAP
  166. * @skb: the event to send
  167. *
  168. * Send a XID response PDU to the network layer via a XID INDICATION
  169. * primitive.
  170. */
  171. int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
  172. {
  173. llc_sap_rtn_pdu(sap, skb);
  174. return 0;
  175. }
  176. /**
  177. * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
  178. * @sap: SAP
  179. * @skb: the event to send
  180. *
  181. * Send a TEST response PDU to the network layer via a TEST INDICATION
  182. * primitive. Verify our event is a PDU type event.
  183. */
  184. int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
  185. {
  186. llc_sap_rtn_pdu(sap, skb);
  187. return 0;
  188. }