llc_s_ac.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 <net/sock.h>
  27. /**
  28. * llc_sap_action_unitdata_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. static int llc_prepare_and_xmit(struct sk_buff *skb)
  41. {
  42. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  43. struct sk_buff *nskb;
  44. int rc;
  45. rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
  46. if (rc)
  47. return rc;
  48. nskb = skb_clone(skb, GFP_ATOMIC);
  49. if (!nskb)
  50. return -ENOMEM;
  51. if (skb->sk)
  52. skb_set_owner_w(nskb, skb->sk);
  53. return dev_queue_xmit(nskb);
  54. }
  55. /**
  56. * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
  57. * @sap: SAP
  58. * @skb: the event to send
  59. *
  60. * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
  61. * primitive from the network layer. Verifies event is a primitive type of
  62. * event. Verify the primitive is a UNITDATA REQUEST.
  63. */
  64. int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
  65. {
  66. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  67. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  68. ev->daddr.lsap, LLC_PDU_CMD);
  69. llc_pdu_init_as_ui_cmd(skb);
  70. return llc_prepare_and_xmit(skb);
  71. }
  72. /**
  73. * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
  74. * @sap: SAP
  75. * @skb: the event to send
  76. *
  77. * Send a XID command PDU to MAC layer in response to a XID REQUEST
  78. * primitive from the network layer. Verify event is a primitive type
  79. * event. Verify the primitive is a XID REQUEST.
  80. */
  81. int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
  82. {
  83. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  84. llc_pdu_header_init(skb, LLC_PDU_TYPE_U_XID, ev->saddr.lsap,
  85. ev->daddr.lsap, LLC_PDU_CMD);
  86. llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
  87. return llc_prepare_and_xmit(skb);
  88. }
  89. /**
  90. * llc_sap_action_send_xid_r - send XID PDU resp to MAC for received XID
  91. * @sap: SAP
  92. * @skb: the event to send
  93. *
  94. * Send XID response PDU to MAC in response to an earlier received XID
  95. * command PDU. Verify event is a PDU type event
  96. */
  97. int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
  98. {
  99. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  100. int rc = 1;
  101. struct sk_buff *nskb;
  102. llc_pdu_decode_sa(skb, mac_da);
  103. llc_pdu_decode_da(skb, mac_sa);
  104. llc_pdu_decode_ssap(skb, &dsap);
  105. nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
  106. sizeof(struct llc_xid_info));
  107. if (!nskb)
  108. goto out;
  109. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
  110. LLC_PDU_RSP);
  111. llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
  112. rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
  113. if (likely(!rc))
  114. rc = dev_queue_xmit(nskb);
  115. out:
  116. return rc;
  117. }
  118. /**
  119. * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
  120. * @sap: SAP
  121. * @skb: the event to send
  122. *
  123. * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
  124. * primitive from the network layer. Verify event is a primitive type
  125. * event; verify the primitive is a TEST REQUEST.
  126. */
  127. int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
  128. {
  129. struct llc_sap_state_ev *ev = llc_sap_ev(skb);
  130. llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
  131. ev->daddr.lsap, LLC_PDU_CMD);
  132. llc_pdu_init_as_test_cmd(skb);
  133. return llc_prepare_and_xmit(skb);
  134. }
  135. int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
  136. {
  137. u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
  138. struct sk_buff *nskb;
  139. int rc = 1;
  140. u32 data_size;
  141. if (skb->mac_len < ETH_HLEN)
  142. return 1;
  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. }