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