llc_s_ac.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. /**
  27. * llc_sap_action_unit_data_ind - forward UI PDU to network layer
  28. * @sap: SAP
  29. * @skb: the event to forward
  30. *
  31. * Received a UI PDU from MAC layer; forward to network layer as a
  32. * UNITDATA INDICATION; verify our event is the kind we expect
  33. */
  34. int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)
  35. {
  36. llc_sap_rtn_pdu(sap, skb);
  37. return 0;
  38. }
  39. /**
  40. * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
  41. * @sap: SAP
  42. * @skb: the event to send
  43. *
  44. * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
  45. * primitive from the network layer. Verifies event is a primitive type of
  46. * event. Verify the primitive is a UNITDATA REQUEST.
  47. */
  48. int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
  49. {
  50. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  51. int rc;
  52. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  53. ev->daddr.lsap, LLC_PDU_CMD);
  54. llc_pdu_init_as_ui_cmd(skb);
  55. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  56. if (likely(!rc))
  57. rc = dev_queue_xmit(skb);
  58. return rc;
  59. }
  60. /**
  61. * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
  62. * @sap: SAP
  63. * @skb: the event to send
  64. *
  65. * Send a XID command PDU to MAC layer in response to a XID REQUEST
  66. * primitive from the network layer. Verify event is a primitive type
  67. * event. Verify the primitive is a XID REQUEST.
  68. */
  69. int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
  70. {
  71. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  72. int rc;
  73. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  74. ev->daddr.lsap, LLC_PDU_CMD);
  75. llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
  76. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  77. if (likely(!rc))
  78. rc = dev_queue_xmit(skb);
  79. return rc;
  80. }
  81. /**
  82. * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
  83. * @sap: SAP
  84. * @skb: the event to send
  85. *
  86. * Send XID response PDU to MAC in response to an earlier received XID
  87. * command PDU. Verify event is a PDU type event
  88. */
  89. int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
  90. {
  91. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  92. int rc = 1;
  93. struct sk_buff *nskb;
  94. llc_pdu_decode_sa(skb, mac_da);
  95. llc_pdu_decode_da(skb, mac_sa);
  96. llc_pdu_decode_ssap(skb, &dsap);
  97. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
  98. sizeof(struct llc_xid_info));
  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. u32 data_size;
  137. llc_pdu_decode_sa(skb, mac_da);
  138. llc_pdu_decode_da(skb, mac_sa);
  139. llc_pdu_decode_ssap(skb, &dsap);
  140. /* The test request command is type U (llc_len = 3) */
  141. data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
  142. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
  143. if (!nskb)
  144. goto out;
  145. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  146. LLC_PDU_RSP);
  147. llc_pdu_init_as_test_rsp(nskb, skb);
  148. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  149. if (likely(!rc))
  150. rc = dev_queue_xmit(nskb);
  151. out:
  152. return rc;
  153. }
  154. /**
  155. * llc_sap_action_report_status - report data link status to layer mgmt
  156. * @sap: SAP
  157. * @skb: the event to send
  158. *
  159. * Report data link status to layer management. Verify our event is the
  160. * kind we expect.
  161. */
  162. int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
  163. {
  164. return 0;
  165. }
  166. /**
  167. * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
  168. * @sap: SAP
  169. * @skb: the event to send
  170. *
  171. * Send a XID response PDU to the network layer via a XID INDICATION
  172. * primitive.
  173. */
  174. int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
  175. {
  176. llc_sap_rtn_pdu(sap, skb);
  177. return 0;
  178. }
  179. /**
  180. * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
  181. * @sap: SAP
  182. * @skb: the event to send
  183. *
  184. * Send a TEST response PDU to the network layer via a TEST INDICATION
  185. * primitive. Verify our event is a PDU type event.
  186. */
  187. int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
  188. {
  189. llc_sap_rtn_pdu(sap, skb);
  190. return 0;
  191. }