blob: 6acdebf03b2b84c45bdf9baef5d59ede61122112 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
21#include <linux/netdevice.h>
22#include <net/llc.h>
23#include <net/llc_pdu.h>
24#include <net/llc_s_ac.h>
25#include <net/llc_s_ev.h>
26#include <net/llc_sap.h>
27#include "llc_output.h"
28
29/**
30 * llc_sap_action_unit_data_ind - forward UI PDU to network layer
31 * @sap: SAP
32 * @skb: the event to forward
33 *
34 * Received a UI PDU from MAC layer; forward to network layer as a
35 * UNITDATA INDICATION; verify our event is the kind we expect
36 */
37int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb)
38{
39 llc_sap_rtn_pdu(sap, skb);
40 return 0;
41}
42
43/**
44 * llc_sap_action_send_ui - sends UI PDU resp to UNITDATA REQ to MAC layer
45 * @sap: SAP
46 * @skb: the event to send
47 *
48 * Sends a UI PDU to the MAC layer in response to a UNITDATA REQUEST
49 * primitive from the network layer. Verifies event is a primitive type of
50 * event. Verify the primitive is a UNITDATA REQUEST.
51 */
52int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
53{
54 struct llc_sap_state_ev *ev = llc_sap_ev(skb);
55 int rc;
56
57 llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
58 ev->daddr.lsap, LLC_PDU_CMD);
59 llc_pdu_init_as_ui_cmd(skb);
60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -030061 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 rc = dev_queue_xmit(skb);
63 return rc;
64}
65
66/**
67 * llc_sap_action_send_xid_c - send XID PDU as response to XID REQ
68 * @sap: SAP
69 * @skb: the event to send
70 *
71 * Send a XID command PDU to MAC layer in response to a XID REQUEST
72 * primitive from the network layer. Verify event is a primitive type
73 * event. Verify the primitive is a XID REQUEST.
74 */
75int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
76{
77 struct llc_sap_state_ev *ev = llc_sap_ev(skb);
78 int rc;
79
80 llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
81 ev->daddr.lsap, LLC_PDU_CMD);
82 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
83 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -030084 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 rc = dev_queue_xmit(skb);
86 return rc;
87}
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 */
97int 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
103 llc_pdu_decode_sa(skb, mac_da);
104 llc_pdu_decode_da(skb, mac_sa);
105 llc_pdu_decode_ssap(skb, &dsap);
Arnaldo Carvalho de Melo1d67e652005-09-22 03:27:56 -0300106 nskb = llc_alloc_frame(skb->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (!nskb)
108 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 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);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -0300113 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 rc = dev_queue_xmit(nskb);
115out:
116 return rc;
117}
118
119/**
120 * llc_sap_action_send_test_c - send TEST PDU to MAC in resp to TEST REQ
121 * @sap: SAP
122 * @skb: the event to send
123 *
124 * Send a TEST command PDU to the MAC layer in response to a TEST REQUEST
125 * primitive from the network layer. Verify event is a primitive type
126 * event; verify the primitive is a TEST REQUEST.
127 */
128int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
129{
130 struct llc_sap_state_ev *ev = llc_sap_ev(skb);
131 int rc;
132
133 llc_pdu_header_init(skb, LLC_PDU_TYPE_U, ev->saddr.lsap,
134 ev->daddr.lsap, LLC_PDU_CMD);
135 llc_pdu_init_as_test_cmd(skb);
136 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -0300137 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 rc = dev_queue_xmit(skb);
139 return rc;
140}
141
142int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
143{
144 u8 mac_da[ETH_ALEN], mac_sa[ETH_ALEN], dsap;
145 struct sk_buff *nskb;
146 int rc = 1;
147
148 llc_pdu_decode_sa(skb, mac_da);
149 llc_pdu_decode_da(skb, mac_sa);
150 llc_pdu_decode_ssap(skb, &dsap);
Arnaldo Carvalho de Melo1d67e652005-09-22 03:27:56 -0300151 nskb = llc_alloc_frame(skb->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (!nskb)
153 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
155 LLC_PDU_RSP);
156 llc_pdu_init_as_test_rsp(nskb, skb);
157 rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
Arnaldo Carvalho de Melo249ff1c2005-09-22 04:32:10 -0300158 if (likely(!rc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 rc = dev_queue_xmit(nskb);
160out:
161 return rc;
162}
163
164/**
165 * llc_sap_action_report_status - report data link status to layer mgmt
166 * @sap: SAP
167 * @skb: the event to send
168 *
169 * Report data link status to layer management. Verify our event is the
170 * kind we expect.
171 */
172int llc_sap_action_report_status(struct llc_sap *sap, struct sk_buff *skb)
173{
174 return 0;
175}
176
177/**
178 * llc_sap_action_xid_ind - send XID PDU resp to net layer via XID IND
179 * @sap: SAP
180 * @skb: the event to send
181 *
182 * Send a XID response PDU to the network layer via a XID INDICATION
183 * primitive.
184 */
185int llc_sap_action_xid_ind(struct llc_sap *sap, struct sk_buff *skb)
186{
187 llc_sap_rtn_pdu(sap, skb);
188 return 0;
189}
190
191/**
192 * llc_sap_action_test_ind - send TEST PDU to net layer via TEST IND
193 * @sap: SAP
194 * @skb: the event to send
195 *
196 * Send a TEST response PDU to the network layer via a TEST INDICATION
197 * primitive. Verify our event is a PDU type event.
198 */
199int llc_sap_action_test_ind(struct llc_sap *sap, struct sk_buff *skb)
200{
201 llc_sap_rtn_pdu(sap, skb);
202 return 0;
203}