llc_s_ac.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 (!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 (!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();
  99. if (!nskb)
  100. goto out;
  101. nskb->dev = skb->dev;
  102. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  103. LLC_PDU_RSP);
  104. llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
  105. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  106. if (!rc)
  107. rc = dev_queue_xmit(nskb);
  108. out:
  109. return rc;
  110. }
  111. /**
  112. * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
  113. * @sap: SAP
  114. * @skb: the event to send
  115. *
  116. * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
  117. * primitive from the network layer. Verify event is a primitive type
  118. * event; verify the primitive is a TEST REQUEST.
  119. */
  120. int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
  121. {
  122. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  123. int rc;
  124. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  125. ev->daddr.lsap, LLC_PDU_CMD);
  126. llc_pdu_init_as_test_cmd(skb);
  127. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  128. if (!rc)
  129. rc = dev_queue_xmit(skb);
  130. return rc;
  131. }
  132. int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
  133. {
  134. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  135. struct sk_buff *nskb;
  136. int rc = 1;
  137. llc_pdu_decode_sa(skb, mac_da);
  138. llc_pdu_decode_da(skb, mac_sa);
  139. llc_pdu_decode_ssap(skb, &dsap);
  140. nskb = llc_alloc_frame();
  141. if (!nskb)
  142. goto out;
  143. nskb->dev = skb->dev;
  144. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  145. LLC_PDU_RSP);
  146. llc_pdu_init_as_test_rsp(nskb, skb);
  147. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  148. if (!rc)
  149. rc = dev_queue_xmit(nskb);
  150. out:
  151. return rc;
  152. }
  153. /**
  154. * llc_sap_action_report_status - report data link status to layer mgmt
  155. * @sap: SAP
  156. * @skb: the event to send
  157. *
  158. * Report data link status to layer management. Verify our event is the
  159. * kind we expect.
  160. */
  161. int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
  162. {
  163. return 0;
  164. }
  165. /**
  166. * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
  167. * @sap: SAP
  168. * @skb: the event to send
  169. *
  170. * Send a XID response PDU to the network layer via a XID INDICATION
  171. * primitive.
  172. */
  173. int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
  174. {
  175. llc_sap_rtn_pdu(sap, skb);
  176. return 0;
  177. }
  178. /**
  179. * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
  180. * @sap: SAP
  181. * @skb: the event to send
  182. *
  183. * Send a TEST response PDU to the network layer via a TEST INDICATION
  184. * primitive. Verify our event is a PDU type event.
  185. */
  186. int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
  187. {
  188. llc_sap_rtn_pdu(sap, skb);
  189. return 0;
  190. }