llc_s_ac.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. skb_get(skb);
  58. rc = dev_queue_xmit(skb);
  59. }
  60. return rc;
  61. }
  62. /**
  63. * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
  64. * @sap: SAP
  65. * @skb: the event to send
  66. *
  67. * Send a XID command PDU to MAC layer in response to a XID REQUEST
  68. * primitive from the network layer. Verify event is a primitive type
  69. * event. Verify the primitive is a XID REQUEST.
  70. */
  71. int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
  72. {
  73. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  74. int rc;
  75. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  76. ev->daddr.lsap, LLC_PDU_CMD);
  77. llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
  78. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  79. if (likely(!rc)) {
  80. skb_get(skb);
  81. rc = dev_queue_xmit(skb);
  82. }
  83. return rc;
  84. }
  85. /**
  86. * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
  87. * @sap: SAP
  88. * @skb: the event to send
  89. *
  90. * Send XID response PDU to MAC in response to an earlier received XID
  91. * command PDU. Verify event is a PDU type event
  92. */
  93. int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
  94. {
  95. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  96. int rc = 1;
  97. struct sk_buff *nskb;
  98. llc_pdu_decode_sa(skb, mac_da);
  99. llc_pdu_decode_da(skb, mac_sa);
  100. llc_pdu_decode_ssap(skb, &dsap);
  101. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
  102. sizeof(struct llc_xid_info));
  103. if (!nskb)
  104. goto out;
  105. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  106. LLC_PDU_RSP);
  107. llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
  108. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  109. if (likely(!rc))
  110. rc = dev_queue_xmit(nskb);
  111. out:
  112. return rc;
  113. }
  114. /**
  115. * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
  116. * @sap: SAP
  117. * @skb: the event to send
  118. *
  119. * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
  120. * primitive from the network layer. Verify event is a primitive type
  121. * event; verify the primitive is a TEST REQUEST.
  122. */
  123. int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
  124. {
  125. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  126. int rc;
  127. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  128. ev->daddr.lsap, LLC_PDU_CMD);
  129. llc_pdu_init_as_test_cmd(skb);
  130. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  131. if (likely(!rc)) {
  132. skb_get(skb);
  133. rc = dev_queue_xmit(skb);
  134. }
  135. return rc;
  136. }
  137. int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
  138. {
  139. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  140. struct sk_buff *nskb;
  141. int rc = 1;
  142. u32 data_size;
  143. llc_pdu_decode_sa(skb, mac_da);
  144. llc_pdu_decode_da(skb, mac_sa);
  145. llc_pdu_decode_ssap(skb, &dsap);
  146. /* The test request command is type U (llc_len = 3) */
  147. data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
  148. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
  149. if (!nskb)
  150. goto out;
  151. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  152. LLC_PDU_RSP);
  153. llc_pdu_init_as_test_rsp(nskb, skb);
  154. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  155. if (likely(!rc))
  156. rc = dev_queue_xmit(nskb);
  157. out:
  158. return rc;
  159. }
  160. /**
  161. * llc_sap_action_report_status - report data link status to layer mgmt
  162. * @sap: SAP
  163. * @skb: the event to send
  164. *
  165. * Report data link status to layer management. Verify our event is the
  166. * kind we expect.
  167. */
  168. int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
  169. {
  170. return 0;
  171. }
  172. /**
  173. * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
  174. * @sap: SAP
  175. * @skb: the event to send
  176. *
  177. * Send a XID response PDU to the network layer via a XID INDICATION
  178. * primitive.
  179. */
  180. int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
  181. {
  182. llc_sap_rtn_pdu(sap, skb);
  183. return 0;
  184. }
  185. /**
  186. * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
  187. * @sap: SAP
  188. * @skb: the event to send
  189. *
  190. * Send a TEST response PDU to the network layer via a TEST INDICATION
  191. * primitive. Verify our event is a PDU type event.
  192. */
  193. int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
  194. {
  195. llc_sap_rtn_pdu(sap, skb);
  196. return 0;
  197. }