]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * llc_c_ac.c - actions performed during connection state transition. | |
3 | * | |
4 | * Description: | |
5 | * Functions in this module are implementation of connection component actions | |
6 | * Details of actions can be found in IEEE-802.2 standard document. | |
7 | * All functions have one connection 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_conn.h> | |
22 | #include <net/llc_sap.h> | |
23 | #include <net/sock.h> | |
24 | #include <net/llc_c_ev.h> | |
25 | #include <net/llc_c_ac.h> | |
26 | #include <net/llc_c_st.h> | |
27 | #include <net/llc_pdu.h> | |
28 | #include <net/llc.h> | |
29 | ||
30 | #include "llc_output.h" | |
31 | ||
32 | static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb); | |
33 | static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb); | |
34 | static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev); | |
35 | ||
36 | static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb); | |
37 | ||
38 | static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, | |
39 | struct sk_buff *skb); | |
40 | ||
41 | static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb); | |
42 | ||
43 | #define INCORRECT 0 | |
44 | ||
45 | int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb) | |
46 | { | |
47 | struct llc_sock *llc = llc_sk(sk); | |
48 | ||
49 | if (llc->remote_busy_flag) { | |
50 | u8 nr; | |
51 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
52 | ||
53 | llc->remote_busy_flag = 0; | |
54 | del_timer(&llc->busy_state_timer.timer); | |
55 | nr = LLC_I_GET_NR(pdu); | |
56 | llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); | |
57 | } | |
58 | return 0; | |
59 | } | |
60 | ||
61 | int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb) | |
62 | { | |
63 | int rc = -ENOTCONN; | |
64 | u8 dsap; | |
65 | struct llc_sap *sap; | |
66 | ||
67 | llc_pdu_decode_dsap(skb, &dsap); | |
68 | sap = llc_sap_find(dsap); | |
69 | if (sap) { | |
70 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
71 | struct llc_sock *llc = llc_sk(sk); | |
72 | ||
73 | llc_pdu_decode_sa(skb, llc->daddr.mac); | |
74 | llc_pdu_decode_da(skb, llc->laddr.mac); | |
75 | llc->dev = skb->dev; | |
76 | ev->ind_prim = LLC_CONN_PRIM; | |
77 | rc = 0; | |
78 | } | |
79 | return rc; | |
80 | } | |
81 | ||
82 | int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb) | |
83 | { | |
84 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
85 | ||
86 | ev->cfm_prim = LLC_CONN_PRIM; | |
87 | return 0; | |
88 | } | |
89 | ||
90 | static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb) | |
91 | { | |
92 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
93 | ||
94 | ev->cfm_prim = LLC_DATA_PRIM; | |
95 | return 0; | |
96 | } | |
97 | ||
98 | int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb) | |
99 | { | |
100 | llc_conn_rtn_pdu(sk, skb); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb) | |
105 | { | |
106 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
107 | u8 reason = 0; | |
108 | int rc = 0; | |
109 | ||
110 | if (ev->type == LLC_CONN_EV_TYPE_PDU) { | |
111 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); | |
112 | ||
113 | if (LLC_PDU_IS_RSP(pdu) && | |
114 | LLC_PDU_TYPE_IS_U(pdu) && | |
115 | LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM) | |
116 | reason = LLC_DISC_REASON_RX_DM_RSP_PDU; | |
117 | else if (LLC_PDU_IS_CMD(pdu) && | |
118 | LLC_PDU_TYPE_IS_U(pdu) && | |
119 | LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC) | |
120 | reason = LLC_DISC_REASON_RX_DISC_CMD_PDU; | |
121 | } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR) | |
122 | reason = LLC_DISC_REASON_ACK_TMR_EXP; | |
123 | else { | |
124 | reason = 0; | |
125 | rc = -EINVAL; | |
126 | } | |
127 | if (!rc) { | |
128 | ev->reason = reason; | |
129 | ev->ind_prim = LLC_DISC_PRIM; | |
130 | } | |
131 | return rc; | |
132 | } | |
133 | ||
134 | int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb) | |
135 | { | |
136 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
137 | ||
138 | ev->reason = ev->status; | |
139 | ev->cfm_prim = LLC_DISC_PRIM; | |
140 | return 0; | |
141 | } | |
142 | ||
143 | int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb) | |
144 | { | |
145 | u8 reason = 0; | |
146 | int rc = 1; | |
147 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
148 | struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); | |
149 | struct llc_sock *llc = llc_sk(sk); | |
150 | ||
151 | switch (ev->type) { | |
152 | case LLC_CONN_EV_TYPE_PDU: | |
153 | if (LLC_PDU_IS_RSP(pdu) && | |
154 | LLC_PDU_TYPE_IS_U(pdu) && | |
155 | LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) { | |
156 | reason = LLC_RESET_REASON_LOCAL; | |
157 | rc = 0; | |
158 | } else if (LLC_PDU_IS_CMD(pdu) && | |
159 | LLC_PDU_TYPE_IS_U(pdu) && | |
160 | LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) { | |
161 | reason = LLC_RESET_REASON_REMOTE; | |
162 | rc = 0; | |
163 | } else { | |
164 | reason = 0; | |
165 | rc = 1; | |
166 | } | |
167 | break; | |
168 | case LLC_CONN_EV_TYPE_ACK_TMR: | |
169 | case LLC_CONN_EV_TYPE_P_TMR: | |
170 | case LLC_CONN_EV_TYPE_REJ_TMR: | |
171 | case LLC_CONN_EV_TYPE_BUSY_TMR: | |
172 | if (llc->retry_count > llc->n2) { | |
173 | reason = LLC_RESET_REASON_LOCAL; | |
174 | rc = 0; | |
175 | } else | |
176 | rc = 1; | |
177 | break; | |
178 | } | |
179 | if (!rc) { | |
180 | ev->reason = reason; | |
181 | ev->ind_prim = LLC_RESET_PRIM; | |
182 | } | |
183 | return rc; | |
184 | } | |
185 | ||
186 | int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb) | |
187 | { | |
188 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
189 | ||
190 | ev->reason = 0; | |
191 | ev->cfm_prim = LLC_RESET_PRIM; | |
192 | return 0; | |
193 | } | |
194 | ||
195 | int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk, | |
196 | struct sk_buff *skb) | |
197 | { | |
198 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
199 | ||
200 | if (LLC_PDU_IS_RSP(pdu) && | |
201 | LLC_PDU_TYPE_IS_I(pdu) && | |
202 | LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf) | |
203 | llc_conn_ac_clear_remote_busy(sk, skb); | |
204 | return 0; | |
205 | } | |
206 | ||
207 | int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk, | |
208 | struct sk_buff *skb) | |
209 | { | |
210 | struct llc_sock *llc = llc_sk(sk); | |
211 | ||
212 | if (llc->data_flag == 2) | |
213 | del_timer(&llc->rej_sent_timer.timer); | |
214 | return 0; | |
215 | } | |
216 | ||
217 | int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) | |
218 | { | |
219 | int rc = -ENOBUFS; | |
1d67e650 ACM |
220 | struct llc_sock *llc = llc_sk(sk); |
221 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
222 | |
223 | if (nskb) { | |
1da177e4 LT |
224 | struct llc_sap *sap = llc->sap; |
225 | ||
1da177e4 LT |
226 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
227 | llc->daddr.lsap, LLC_PDU_CMD); | |
228 | llc_pdu_init_as_disc_cmd(nskb, 1); | |
229 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
230 | if (rc) | |
231 | goto free; | |
232 | llc_conn_send_pdu(sk, nskb); | |
233 | llc_conn_ac_set_p_flag_1(sk, skb); | |
234 | } | |
235 | out: | |
236 | return rc; | |
237 | free: | |
238 | kfree_skb(nskb); | |
239 | goto out; | |
240 | } | |
241 | ||
242 | int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) | |
243 | { | |
244 | int rc = -ENOBUFS; | |
1d67e650 ACM |
245 | struct llc_sock *llc = llc_sk(sk); |
246 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
247 | |
248 | if (nskb) { | |
1da177e4 LT |
249 | struct llc_sap *sap = llc->sap; |
250 | u8 f_bit; | |
251 | ||
1da177e4 LT |
252 | llc_pdu_decode_pf_bit(skb, &f_bit); |
253 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, | |
254 | llc->daddr.lsap, LLC_PDU_RSP); | |
255 | llc_pdu_init_as_dm_rsp(nskb, f_bit); | |
256 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
257 | if (rc) | |
258 | goto free; | |
259 | llc_conn_send_pdu(sk, nskb); | |
260 | } | |
261 | out: | |
262 | return rc; | |
263 | free: | |
264 | kfree_skb(nskb); | |
265 | goto out; | |
266 | } | |
267 | ||
268 | int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
269 | { | |
270 | int rc = -ENOBUFS; | |
1d67e650 ACM |
271 | struct llc_sock *llc = llc_sk(sk); |
272 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
273 | |
274 | if (nskb) { | |
1da177e4 LT |
275 | struct llc_sap *sap = llc->sap; |
276 | u8 f_bit = 1; | |
277 | ||
1da177e4 LT |
278 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
279 | llc->daddr.lsap, LLC_PDU_RSP); | |
280 | llc_pdu_init_as_dm_rsp(nskb, f_bit); | |
281 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
282 | if (rc) | |
283 | goto free; | |
284 | llc_conn_send_pdu(sk, nskb); | |
285 | } | |
286 | out: | |
287 | return rc; | |
288 | free: | |
289 | kfree_skb(nskb); | |
290 | goto out; | |
291 | } | |
292 | ||
293 | int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb) | |
294 | { | |
295 | u8 f_bit; | |
296 | int rc = -ENOBUFS; | |
297 | struct sk_buff *nskb; | |
298 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
299 | struct llc_sock *llc = llc_sk(sk); | |
300 | ||
301 | llc->rx_pdu_hdr = *((u32 *)pdu); | |
302 | if (LLC_PDU_IS_CMD(pdu)) | |
303 | llc_pdu_decode_pf_bit(skb, &f_bit); | |
304 | else | |
305 | f_bit = 0; | |
1d67e650 | 306 | nskb = llc_alloc_frame(llc->dev); |
1da177e4 LT |
307 | if (nskb) { |
308 | struct llc_sap *sap = llc->sap; | |
309 | ||
1da177e4 LT |
310 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
311 | llc->daddr.lsap, LLC_PDU_RSP); | |
312 | llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, | |
313 | llc->vR, INCORRECT); | |
314 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
315 | if (rc) | |
316 | goto free; | |
317 | llc_conn_send_pdu(sk, nskb); | |
318 | } | |
319 | out: | |
320 | return rc; | |
321 | free: | |
322 | kfree_skb(nskb); | |
323 | goto out; | |
324 | } | |
325 | ||
326 | int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb) | |
327 | { | |
328 | int rc = -ENOBUFS; | |
1d67e650 ACM |
329 | struct llc_sock *llc = llc_sk(sk); |
330 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
331 | |
332 | if (nskb) { | |
333 | u8 f_bit = 0; | |
1da177e4 LT |
334 | struct llc_sap *sap = llc->sap; |
335 | struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr; | |
336 | ||
1da177e4 LT |
337 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
338 | llc->daddr.lsap, LLC_PDU_RSP); | |
339 | llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, | |
340 | llc->vR, INCORRECT); | |
341 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
342 | if (rc) | |
343 | goto free; | |
344 | llc_conn_send_pdu(sk, nskb); | |
345 | } | |
346 | out: | |
347 | return rc; | |
348 | free: | |
349 | kfree_skb(nskb); | |
350 | goto out; | |
351 | } | |
352 | ||
353 | int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) | |
354 | { | |
355 | u8 f_bit; | |
356 | int rc = -ENOBUFS; | |
357 | struct sk_buff *nskb; | |
1d67e650 | 358 | struct llc_sock *llc = llc_sk(sk); |
1da177e4 LT |
359 | |
360 | llc_pdu_decode_pf_bit(skb, &f_bit); | |
1d67e650 | 361 | nskb = llc_alloc_frame(llc->dev); |
1da177e4 | 362 | if (nskb) { |
1da177e4 LT |
363 | struct llc_sap *sap = llc->sap; |
364 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
365 | ||
1da177e4 LT |
366 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
367 | llc->daddr.lsap, LLC_PDU_RSP); | |
368 | llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, | |
369 | llc->vR, INCORRECT); | |
370 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
371 | if (rc) | |
372 | goto free; | |
373 | llc_conn_send_pdu(sk, nskb); | |
374 | } | |
375 | out: | |
376 | return rc; | |
377 | free: | |
378 | kfree_skb(nskb); | |
379 | goto out; | |
380 | } | |
381 | ||
382 | int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) | |
383 | { | |
384 | int rc; | |
385 | struct llc_sock *llc = llc_sk(sk); | |
386 | struct llc_sap *sap = llc->sap; | |
387 | ||
388 | llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, | |
389 | llc->daddr.lsap, LLC_PDU_CMD); | |
390 | llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR); | |
391 | rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); | |
392 | if (!rc) { | |
393 | llc_conn_send_pdu(sk, skb); | |
394 | llc_conn_ac_inc_vs_by_1(sk, skb); | |
395 | } | |
396 | return rc; | |
397 | } | |
398 | ||
399 | static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb) | |
400 | { | |
401 | int rc; | |
402 | struct llc_sock *llc = llc_sk(sk); | |
403 | struct llc_sap *sap = llc->sap; | |
404 | ||
405 | llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, | |
406 | llc->daddr.lsap, LLC_PDU_CMD); | |
407 | llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); | |
408 | rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); | |
409 | if (!rc) { | |
410 | llc_conn_send_pdu(sk, skb); | |
411 | llc_conn_ac_inc_vs_by_1(sk, skb); | |
412 | } | |
413 | return rc; | |
414 | } | |
415 | ||
416 | int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
417 | { | |
418 | int rc; | |
419 | struct llc_sock *llc = llc_sk(sk); | |
420 | struct llc_sap *sap = llc->sap; | |
421 | ||
422 | llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, | |
423 | llc->daddr.lsap, LLC_PDU_CMD); | |
424 | llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); | |
425 | rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); | |
426 | if (!rc) { | |
427 | llc_conn_send_pdu(sk, skb); | |
428 | llc_conn_ac_inc_vs_by_1(sk, skb); | |
429 | } | |
430 | return 0; | |
431 | } | |
432 | ||
433 | int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
434 | { | |
435 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
436 | u8 nr = LLC_I_GET_NR(pdu); | |
437 | ||
438 | llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); | |
439 | return 0; | |
440 | } | |
441 | ||
442 | int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk, | |
443 | struct sk_buff *skb) | |
444 | { | |
445 | u8 nr; | |
446 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
447 | int rc = -ENOBUFS; | |
1d67e650 ACM |
448 | struct llc_sock *llc = llc_sk(sk); |
449 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
450 | |
451 | if (nskb) { | |
1da177e4 LT |
452 | struct llc_sap *sap = llc->sap; |
453 | ||
1da177e4 LT |
454 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
455 | llc->daddr.lsap, LLC_PDU_RSP); | |
456 | llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); | |
457 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
458 | if (!rc) | |
459 | llc_conn_send_pdu(sk, nskb); | |
460 | else | |
461 | kfree_skb(skb); | |
462 | } | |
463 | if (rc) { | |
464 | nr = LLC_I_GET_NR(pdu); | |
465 | rc = 0; | |
466 | llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); | |
467 | } | |
468 | return rc; | |
469 | } | |
470 | ||
471 | int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
472 | { | |
473 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
474 | u8 nr = LLC_I_GET_NR(pdu); | |
475 | ||
476 | llc_conn_resend_i_pdu_as_rsp(sk, nr, 1); | |
477 | return 0; | |
478 | } | |
479 | ||
480 | int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) | |
481 | { | |
482 | int rc = -ENOBUFS; | |
1d67e650 ACM |
483 | struct llc_sock *llc = llc_sk(sk); |
484 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
485 | |
486 | if (nskb) { | |
1da177e4 LT |
487 | struct llc_sap *sap = llc->sap; |
488 | ||
1da177e4 LT |
489 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
490 | llc->daddr.lsap, LLC_PDU_CMD); | |
491 | llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR); | |
492 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
493 | if (rc) | |
494 | goto free; | |
495 | llc_conn_send_pdu(sk, nskb); | |
496 | } | |
497 | out: | |
498 | return rc; | |
499 | free: | |
500 | kfree_skb(nskb); | |
501 | goto out; | |
502 | } | |
503 | ||
504 | int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
505 | { | |
506 | int rc = -ENOBUFS; | |
1d67e650 ACM |
507 | struct llc_sock *llc = llc_sk(sk); |
508 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
509 | |
510 | if (nskb) { | |
511 | u8 f_bit = 1; | |
1da177e4 LT |
512 | struct llc_sap *sap = llc->sap; |
513 | ||
1da177e4 LT |
514 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
515 | llc->daddr.lsap, LLC_PDU_RSP); | |
516 | llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR); | |
517 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
518 | if (rc) | |
519 | goto free; | |
520 | llc_conn_send_pdu(sk, nskb); | |
521 | } | |
522 | out: | |
523 | return rc; | |
524 | free: | |
525 | kfree_skb(nskb); | |
526 | goto out; | |
527 | } | |
528 | ||
529 | int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
530 | { | |
531 | int rc = -ENOBUFS; | |
1d67e650 ACM |
532 | struct llc_sock *llc = llc_sk(sk); |
533 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
534 | |
535 | if (nskb) { | |
1da177e4 LT |
536 | struct llc_sap *sap = llc->sap; |
537 | u8 f_bit = 0; | |
538 | ||
1da177e4 LT |
539 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
540 | llc->daddr.lsap, LLC_PDU_RSP); | |
541 | llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR); | |
542 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
543 | if (rc) | |
544 | goto free; | |
545 | llc_conn_send_pdu(sk, nskb); | |
546 | } | |
547 | out: | |
548 | return rc; | |
549 | free: | |
550 | kfree_skb(nskb); | |
551 | goto out; | |
552 | } | |
553 | ||
554 | int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) | |
555 | { | |
556 | int rc = -ENOBUFS; | |
1d67e650 ACM |
557 | struct llc_sock *llc = llc_sk(sk); |
558 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
559 | |
560 | if (nskb) { | |
1da177e4 LT |
561 | struct llc_sap *sap = llc->sap; |
562 | ||
1da177e4 LT |
563 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
564 | llc->daddr.lsap, LLC_PDU_CMD); | |
565 | llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR); | |
566 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
567 | if (rc) | |
568 | goto free; | |
569 | llc_conn_send_pdu(sk, nskb); | |
570 | } | |
571 | out: | |
572 | return rc; | |
573 | free: | |
574 | kfree_skb(nskb); | |
575 | goto out; | |
576 | } | |
577 | ||
578 | int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
579 | { | |
580 | int rc = -ENOBUFS; | |
1d67e650 ACM |
581 | struct llc_sock *llc = llc_sk(sk); |
582 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
583 | |
584 | if (nskb) { | |
1da177e4 LT |
585 | struct llc_sap *sap = llc->sap; |
586 | u8 f_bit = 1; | |
587 | ||
1da177e4 LT |
588 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
589 | llc->daddr.lsap, LLC_PDU_RSP); | |
590 | llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR); | |
591 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
592 | if (rc) | |
593 | goto free; | |
594 | llc_conn_send_pdu(sk, nskb); | |
595 | } | |
596 | out: | |
597 | return rc; | |
598 | free: | |
599 | kfree_skb(nskb); | |
600 | goto out; | |
601 | } | |
602 | ||
603 | int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
604 | { | |
605 | int rc = -ENOBUFS; | |
1d67e650 ACM |
606 | struct llc_sock *llc = llc_sk(sk); |
607 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
608 | |
609 | if (nskb) { | |
610 | u8 f_bit = 0; | |
1da177e4 LT |
611 | struct llc_sap *sap = llc->sap; |
612 | ||
1da177e4 LT |
613 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
614 | llc->daddr.lsap, LLC_PDU_RSP); | |
615 | llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR); | |
616 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
617 | if (rc) | |
618 | goto free; | |
619 | llc_conn_send_pdu(sk, nskb); | |
620 | } | |
621 | out: | |
622 | return rc; | |
623 | free: | |
624 | kfree_skb(nskb); | |
625 | goto out; | |
626 | } | |
627 | ||
628 | int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb) | |
629 | { | |
630 | struct llc_sock *llc = llc_sk(sk); | |
631 | ||
632 | if (!llc->remote_busy_flag) { | |
633 | llc->remote_busy_flag = 1; | |
634 | mod_timer(&llc->busy_state_timer.timer, | |
635 | jiffies + llc->busy_state_timer.expire * HZ); | |
636 | } | |
637 | return 0; | |
638 | } | |
639 | ||
640 | int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
641 | { | |
642 | int rc = -ENOBUFS; | |
1d67e650 ACM |
643 | struct llc_sock *llc = llc_sk(sk); |
644 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
645 | |
646 | if (nskb) { | |
1da177e4 LT |
647 | struct llc_sap *sap = llc->sap; |
648 | ||
1da177e4 LT |
649 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
650 | llc->daddr.lsap, LLC_PDU_RSP); | |
651 | llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); | |
652 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
653 | if (rc) | |
654 | goto free; | |
655 | llc_conn_send_pdu(sk, nskb); | |
656 | } | |
657 | out: | |
658 | return rc; | |
659 | free: | |
660 | kfree_skb(nskb); | |
661 | goto out; | |
662 | } | |
663 | ||
664 | int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) | |
665 | { | |
666 | int rc = -ENOBUFS; | |
1d67e650 ACM |
667 | struct llc_sock *llc = llc_sk(sk); |
668 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
669 | |
670 | if (nskb) { | |
1da177e4 LT |
671 | struct llc_sap *sap = llc->sap; |
672 | ||
1da177e4 LT |
673 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
674 | llc->daddr.lsap, LLC_PDU_CMD); | |
675 | llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR); | |
676 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
677 | if (rc) | |
678 | goto free; | |
679 | llc_conn_send_pdu(sk, nskb); | |
680 | } | |
681 | out: | |
682 | return rc; | |
683 | free: | |
684 | kfree_skb(nskb); | |
685 | goto out; | |
686 | } | |
687 | ||
688 | int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
689 | { | |
690 | int rc = -ENOBUFS; | |
1d67e650 ACM |
691 | struct llc_sock *llc = llc_sk(sk); |
692 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
693 | |
694 | if (nskb) { | |
1da177e4 LT |
695 | struct llc_sap *sap = llc->sap; |
696 | u8 f_bit = 1; | |
697 | ||
1da177e4 LT |
698 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
699 | llc->daddr.lsap, LLC_PDU_RSP); | |
700 | llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); | |
701 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
702 | if (rc) | |
703 | goto free; | |
704 | llc_conn_send_pdu(sk, nskb); | |
705 | } | |
706 | out: | |
707 | return rc; | |
708 | free: | |
709 | kfree_skb(nskb); | |
710 | goto out; | |
711 | } | |
712 | ||
713 | int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) | |
714 | { | |
715 | int rc = -ENOBUFS; | |
1d67e650 ACM |
716 | struct llc_sock *llc = llc_sk(sk); |
717 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
718 | |
719 | if (nskb) { | |
1da177e4 LT |
720 | struct llc_sap *sap = llc->sap; |
721 | u8 f_bit = 1; | |
722 | ||
1da177e4 LT |
723 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
724 | llc->daddr.lsap, LLC_PDU_RSP); | |
725 | llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); | |
726 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
727 | if (rc) | |
728 | goto free; | |
729 | llc_conn_send_pdu(sk, nskb); | |
730 | } | |
731 | out: | |
732 | return rc; | |
733 | free: | |
734 | kfree_skb(nskb); | |
735 | goto out; | |
736 | } | |
737 | ||
738 | int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
739 | { | |
740 | int rc = -ENOBUFS; | |
1d67e650 ACM |
741 | struct llc_sock *llc = llc_sk(sk); |
742 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
743 | |
744 | if (nskb) { | |
1da177e4 LT |
745 | struct llc_sap *sap = llc->sap; |
746 | ||
1da177e4 LT |
747 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
748 | llc->daddr.lsap, LLC_PDU_RSP); | |
749 | llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); | |
750 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
751 | if (rc) | |
752 | goto free; | |
753 | llc_conn_send_pdu(sk, nskb); | |
754 | } | |
755 | out: | |
756 | return rc; | |
757 | free: | |
758 | kfree_skb(nskb); | |
759 | goto out; | |
760 | } | |
761 | ||
762 | int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) | |
763 | { | |
764 | int rc = -ENOBUFS; | |
1d67e650 ACM |
765 | struct llc_sock *llc = llc_sk(sk); |
766 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
767 | |
768 | if (nskb) { | |
1da177e4 LT |
769 | struct llc_sap *sap = llc->sap; |
770 | ||
1da177e4 LT |
771 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
772 | llc->daddr.lsap, LLC_PDU_RSP); | |
773 | llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); | |
774 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
775 | if (rc) | |
776 | goto free; | |
777 | llc_conn_send_pdu(sk, nskb); | |
778 | } | |
779 | out: | |
780 | return rc; | |
781 | free: | |
782 | kfree_skb(nskb); | |
783 | goto out; | |
784 | } | |
785 | ||
786 | void llc_conn_set_p_flag(struct sock *sk, u8 value) | |
787 | { | |
788 | int state_changed = llc_sk(sk)->p_flag && !value; | |
789 | ||
790 | llc_sk(sk)->p_flag = value; | |
791 | ||
792 | if (state_changed) | |
793 | sk->sk_state_change(sk); | |
794 | } | |
795 | ||
796 | int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) | |
797 | { | |
798 | int rc = -ENOBUFS; | |
1da177e4 | 799 | struct llc_sock *llc = llc_sk(sk); |
1d67e650 | 800 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); |
1da177e4 LT |
801 | |
802 | if (nskb) { | |
803 | struct llc_sap *sap = llc->sap; | |
804 | u8 *dmac = llc->daddr.mac; | |
805 | ||
806 | if (llc->dev->flags & IFF_LOOPBACK) | |
807 | dmac = llc->dev->dev_addr; | |
1da177e4 LT |
808 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, |
809 | llc->daddr.lsap, LLC_PDU_CMD); | |
810 | llc_pdu_init_as_sabme_cmd(nskb, 1); | |
811 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac); | |
812 | if (rc) | |
813 | goto free; | |
814 | llc_conn_send_pdu(sk, nskb); | |
815 | llc_conn_set_p_flag(sk, 1); | |
816 | } | |
817 | out: | |
818 | return rc; | |
819 | free: | |
820 | kfree_skb(nskb); | |
821 | goto out; | |
822 | } | |
823 | ||
824 | int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) | |
825 | { | |
826 | u8 f_bit; | |
827 | int rc = -ENOBUFS; | |
1d67e650 ACM |
828 | struct llc_sock *llc = llc_sk(sk); |
829 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
830 | |
831 | llc_pdu_decode_pf_bit(skb, &f_bit); | |
832 | if (nskb) { | |
1da177e4 LT |
833 | struct llc_sap *sap = llc->sap; |
834 | ||
835 | nskb->dev = llc->dev; | |
836 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, | |
837 | llc->daddr.lsap, LLC_PDU_RSP); | |
838 | llc_pdu_init_as_ua_rsp(nskb, f_bit); | |
839 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
840 | if (rc) | |
841 | goto free; | |
842 | llc_conn_send_pdu(sk, nskb); | |
843 | } | |
844 | out: | |
845 | return rc; | |
846 | free: | |
847 | kfree_skb(nskb); | |
848 | goto out; | |
849 | } | |
850 | ||
851 | int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb) | |
852 | { | |
853 | llc_sk(sk)->s_flag = 0; | |
854 | return 0; | |
855 | } | |
856 | ||
857 | int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb) | |
858 | { | |
859 | llc_sk(sk)->s_flag = 1; | |
860 | return 0; | |
861 | } | |
862 | ||
863 | int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb) | |
864 | { | |
865 | struct llc_sock *llc = llc_sk(sk); | |
866 | ||
867 | llc_conn_set_p_flag(sk, 1); | |
868 | mod_timer(&llc->pf_cycle_timer.timer, | |
869 | jiffies + llc->pf_cycle_timer.expire * HZ); | |
870 | return 0; | |
871 | } | |
872 | ||
873 | /** | |
874 | * llc_conn_ac_send_ack_if_needed - check if ack is needed | |
875 | * @sk: current connection structure | |
876 | * @skb: current event | |
877 | * | |
878 | * Checks number of received PDUs which have not been acknowledged, yet, | |
879 | * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then | |
880 | * sends an RR response as acknowledgement for them. Returns 0 for | |
881 | * success, 1 otherwise. | |
882 | */ | |
883 | int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb) | |
884 | { | |
885 | u8 pf_bit; | |
886 | struct llc_sock *llc = llc_sk(sk); | |
887 | ||
888 | llc_pdu_decode_pf_bit(skb, &pf_bit); | |
889 | llc->ack_pf |= pf_bit & 1; | |
890 | if (!llc->ack_must_be_send) { | |
891 | llc->first_pdu_Ns = llc->vR; | |
892 | llc->ack_must_be_send = 1; | |
893 | llc->ack_pf = pf_bit & 1; | |
894 | } | |
895 | if (((llc->vR - llc->first_pdu_Ns + 129) % 128) >= llc->npta) { | |
896 | llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb); | |
897 | llc->ack_must_be_send = 0; | |
898 | llc->ack_pf = 0; | |
899 | llc_conn_ac_inc_npta_value(sk, skb); | |
900 | } | |
901 | return 0; | |
902 | } | |
903 | ||
904 | /** | |
905 | * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag | |
906 | * @sk: current connection structure | |
907 | * @skb: current event | |
908 | * | |
909 | * This action resets ack_must_be_send flag of given connection, this flag | |
910 | * indicates if there is any PDU which has not been acknowledged yet. | |
911 | * Returns 0 for success, 1 otherwise. | |
912 | */ | |
913 | int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb) | |
914 | { | |
915 | llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0; | |
916 | return 0; | |
917 | } | |
918 | ||
919 | /** | |
920 | * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs | |
921 | * @sk: current connection structure | |
922 | * @skb: current event | |
923 | * | |
924 | * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to | |
925 | * all received PDUs which have not been acknowledged, yet. ack_pf flag is | |
926 | * set to one if one PDU with p-bit set to one is received. Returns 0 for | |
927 | * success, 1 otherwise. | |
928 | */ | |
929 | static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk, | |
930 | struct sk_buff *skb) | |
931 | { | |
932 | int rc; | |
933 | struct llc_sock *llc = llc_sk(sk); | |
934 | struct llc_sap *sap = llc->sap; | |
935 | ||
936 | llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, | |
937 | llc->daddr.lsap, LLC_PDU_RSP); | |
938 | llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR); | |
939 | rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); | |
940 | if (!rc) { | |
941 | llc_conn_send_pdu(sk, skb); | |
942 | llc_conn_ac_inc_vs_by_1(sk, skb); | |
943 | } | |
944 | return rc; | |
945 | } | |
946 | ||
947 | /** | |
948 | * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs | |
949 | * @sk: current connection structure. | |
950 | * @skb: current event. | |
951 | * | |
952 | * This action sends an I-format PDU as acknowledge to received PDUs which | |
953 | * have not been acknowledged, yet, if there is any. By using of this | |
954 | * action number of acknowledgements decreases, this technic is called | |
955 | * piggy backing. Returns 0 for success, 1 otherwise. | |
956 | */ | |
957 | int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb) | |
958 | { | |
959 | struct llc_sock *llc = llc_sk(sk); | |
960 | ||
961 | if (llc->ack_must_be_send) { | |
962 | llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb); | |
963 | llc->ack_must_be_send = 0 ; | |
964 | llc->ack_pf = 0; | |
965 | } else | |
966 | llc_conn_ac_send_i_cmd_p_set_0(sk, skb); | |
967 | return 0; | |
968 | } | |
969 | ||
970 | /** | |
971 | * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked | |
972 | * @sk: current connection structure. | |
973 | * @skb: current event. | |
974 | * | |
975 | * This action sends an RR response with f-bit set to ack_pf flag as | |
976 | * acknowledge to all received PDUs which have not been acknowledged, yet, | |
977 | * if there is any. ack_pf flag indicates if a PDU has been received with | |
978 | * p-bit set to one. Returns 0 for success, 1 otherwise. | |
979 | */ | |
980 | static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, | |
981 | struct sk_buff *skb) | |
982 | { | |
983 | int rc = -ENOBUFS; | |
1d67e650 ACM |
984 | struct llc_sock *llc = llc_sk(sk); |
985 | struct sk_buff *nskb = llc_alloc_frame(llc->dev); | |
1da177e4 LT |
986 | |
987 | if (nskb) { | |
1da177e4 LT |
988 | struct llc_sap *sap = llc->sap; |
989 | ||
1da177e4 LT |
990 | llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, |
991 | llc->daddr.lsap, LLC_PDU_RSP); | |
992 | llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR); | |
993 | rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); | |
994 | if (rc) | |
995 | goto free; | |
996 | llc_conn_send_pdu(sk, nskb); | |
997 | } | |
998 | out: | |
999 | return rc; | |
1000 | free: | |
1001 | kfree_skb(nskb); | |
1002 | goto out; | |
1003 | } | |
1004 | ||
1005 | /** | |
1006 | * llc_conn_ac_inc_npta_value - tries to make value of npta greater | |
1007 | * @sk: current connection structure. | |
1008 | * @skb: current event. | |
1009 | * | |
1010 | * After "inc_cntr" times calling of this action, "npta" increase by one. | |
1011 | * this action tries to make vale of "npta" greater as possible; number of | |
1012 | * acknowledgements decreases by increasing of "npta". Returns 0 for | |
1013 | * success, 1 otherwise. | |
1014 | */ | |
1015 | static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb) | |
1016 | { | |
1017 | struct llc_sock *llc = llc_sk(sk); | |
1018 | ||
1019 | if (!llc->inc_cntr) { | |
1020 | llc->dec_step = 0; | |
1021 | llc->dec_cntr = llc->inc_cntr = 2; | |
1022 | ++llc->npta; | |
1023 | if (llc->npta > 127) | |
1024 | llc->npta = 127 ; | |
1025 | } else | |
1026 | --llc->inc_cntr; | |
1027 | return 0; | |
1028 | } | |
1029 | ||
1030 | /** | |
1031 | * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one | |
1032 | * @sk: current connection structure. | |
1033 | * @skb: current event. | |
1034 | * | |
1035 | * After receiving "dec_cntr" times RR command, this action decreases | |
1036 | * "npta" by one. Returns 0 for success, 1 otherwise. | |
1037 | */ | |
1038 | int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb) | |
1039 | { | |
1040 | struct llc_sock *llc = llc_sk(sk); | |
1041 | ||
1042 | if (!llc->connect_step && !llc->remote_busy_flag) { | |
1043 | if (!llc->dec_step) { | |
1044 | if (!llc->dec_cntr) { | |
1045 | llc->inc_cntr = llc->dec_cntr = 2; | |
1046 | if (llc->npta > 0) | |
1047 | llc->npta = llc->npta - 1; | |
1048 | } else | |
1049 | llc->dec_cntr -=1; | |
1050 | } | |
1051 | } else | |
1052 | llc->connect_step = 0 ; | |
1053 | return 0; | |
1054 | } | |
1055 | ||
1056 | /** | |
1057 | * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one | |
1058 | * @sk: current connection structure. | |
1059 | * @skb: current event. | |
1060 | * | |
1061 | * After receiving "dec_cntr" times RNR command, this action decreases | |
1062 | * "npta" by one. Returns 0 for success, 1 otherwise. | |
1063 | */ | |
1064 | int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb) | |
1065 | { | |
1066 | struct llc_sock *llc = llc_sk(sk); | |
1067 | ||
1068 | if (llc->remote_busy_flag) | |
1069 | if (!llc->dec_step) { | |
1070 | if (!llc->dec_cntr) { | |
1071 | llc->inc_cntr = llc->dec_cntr = 2; | |
1072 | if (llc->npta > 0) | |
1073 | --llc->npta; | |
1074 | } else | |
1075 | --llc->dec_cntr; | |
1076 | } | |
1077 | return 0; | |
1078 | } | |
1079 | ||
1080 | /** | |
1081 | * llc_conn_ac_dec_tx_win_size - decreases tx window size | |
1082 | * @sk: current connection structure. | |
1083 | * @skb: current event. | |
1084 | * | |
1085 | * After receiving of a REJ command or response, transmit window size is | |
1086 | * decreased by number of PDUs which are outstanding yet. Returns 0 for | |
1087 | * success, 1 otherwise. | |
1088 | */ | |
1089 | int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb) | |
1090 | { | |
1091 | struct llc_sock *llc = llc_sk(sk); | |
1092 | u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q); | |
1093 | ||
1094 | llc->k -= unacked_pdu; | |
1095 | if (llc->k < 2) | |
1096 | llc->k = 2; | |
1097 | return 0; | |
1098 | } | |
1099 | ||
1100 | /** | |
1101 | * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1 | |
1102 | * @sk: current connection structure. | |
1103 | * @skb: current event. | |
1104 | * | |
1105 | * After receiving an RR response with f-bit set to one, transmit window | |
1106 | * size is increased by one. Returns 0 for success, 1 otherwise. | |
1107 | */ | |
1108 | int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb) | |
1109 | { | |
1110 | struct llc_sock *llc = llc_sk(sk); | |
1111 | ||
1112 | llc->k += 1; | |
1113 | if (llc->k > 128) | |
1114 | llc->k = 128 ; | |
1115 | return 0; | |
1116 | } | |
1117 | ||
1118 | int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb) | |
1119 | { | |
1120 | struct llc_sock *llc = llc_sk(sk); | |
1121 | ||
1122 | del_timer(&llc->pf_cycle_timer.timer); | |
1123 | del_timer(&llc->ack_timer.timer); | |
1124 | del_timer(&llc->rej_sent_timer.timer); | |
1125 | del_timer(&llc->busy_state_timer.timer); | |
1126 | llc->ack_must_be_send = 0; | |
1127 | llc->ack_pf = 0; | |
1128 | return 0; | |
1129 | } | |
1130 | ||
1131 | int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb) | |
1132 | { | |
1133 | struct llc_sock *llc = llc_sk(sk); | |
1134 | ||
1135 | del_timer(&llc->rej_sent_timer.timer); | |
1136 | del_timer(&llc->pf_cycle_timer.timer); | |
1137 | del_timer(&llc->busy_state_timer.timer); | |
1138 | llc->ack_must_be_send = 0; | |
1139 | llc->ack_pf = 0; | |
1140 | return 0; | |
1141 | } | |
1142 | ||
1143 | int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb) | |
1144 | { | |
1145 | struct llc_sock *llc = llc_sk(sk); | |
1146 | ||
1147 | mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire * HZ); | |
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb) | |
1152 | { | |
1153 | struct llc_sock *llc = llc_sk(sk); | |
1154 | ||
1155 | mod_timer(&llc->rej_sent_timer.timer, | |
1156 | jiffies + llc->rej_sent_timer.expire * HZ); | |
1157 | return 0; | |
1158 | } | |
1159 | ||
1160 | int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk, | |
1161 | struct sk_buff *skb) | |
1162 | { | |
1163 | struct llc_sock *llc = llc_sk(sk); | |
1164 | ||
1165 | if (!timer_pending(&llc->ack_timer.timer)) | |
1166 | mod_timer(&llc->ack_timer.timer, | |
1167 | jiffies + llc->ack_timer.expire * HZ); | |
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb) | |
1172 | { | |
1173 | del_timer(&llc_sk(sk)->ack_timer.timer); | |
1174 | return 0; | |
1175 | } | |
1176 | ||
1177 | int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb) | |
1178 | { | |
1179 | struct llc_sock *llc = llc_sk(sk); | |
1180 | ||
1181 | del_timer(&llc->pf_cycle_timer.timer); | |
1182 | llc_conn_set_p_flag(sk, 0); | |
1183 | return 0; | |
1184 | } | |
1185 | ||
1186 | int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb) | |
1187 | { | |
1188 | del_timer(&llc_sk(sk)->rej_sent_timer.timer); | |
1189 | return 0; | |
1190 | } | |
1191 | ||
1192 | int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb) | |
1193 | { | |
1194 | int acked; | |
1195 | u16 unacked = 0; | |
1196 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
1197 | struct llc_sock *llc = llc_sk(sk); | |
1198 | ||
1199 | llc->last_nr = PDU_SUPV_GET_Nr(pdu); | |
1200 | acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked); | |
1201 | /* On loopback we don't queue I frames in unack_pdu_q queue. */ | |
1202 | if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) { | |
1203 | llc->retry_count = 0; | |
1204 | del_timer(&llc->ack_timer.timer); | |
1205 | if (llc->failed_data_req) { | |
1206 | /* already, we did not accept data from upper layer | |
1207 | * (tx_window full or unacceptable state). Now, we | |
1208 | * can send data and must inform to upper layer. | |
1209 | */ | |
1210 | llc->failed_data_req = 0; | |
1211 | llc_conn_ac_data_confirm(sk, skb); | |
1212 | } | |
1213 | if (unacked) | |
1214 | mod_timer(&llc->ack_timer.timer, | |
1215 | jiffies + llc->ack_timer.expire * HZ); | |
1216 | } else if (llc->failed_data_req) { | |
1217 | u8 f_bit; | |
1218 | ||
1219 | llc_pdu_decode_pf_bit(skb, &f_bit); | |
1220 | if (f_bit == 1) { | |
1221 | llc->failed_data_req = 0; | |
1222 | llc_conn_ac_data_confirm(sk, skb); | |
1223 | } | |
1224 | } | |
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb) | |
1229 | { | |
1230 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
1231 | ||
1232 | if (LLC_PDU_IS_RSP(pdu)) { | |
1233 | u8 f_bit; | |
1234 | ||
1235 | llc_pdu_decode_pf_bit(skb, &f_bit); | |
1236 | if (f_bit) { | |
1237 | llc_conn_set_p_flag(sk, 0); | |
1238 | llc_conn_ac_stop_p_timer(sk, skb); | |
1239 | } | |
1240 | } | |
1241 | return 0; | |
1242 | } | |
1243 | ||
1244 | int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb) | |
1245 | { | |
1246 | llc_sk(sk)->data_flag = 2; | |
1247 | return 0; | |
1248 | } | |
1249 | ||
1250 | int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb) | |
1251 | { | |
1252 | llc_sk(sk)->data_flag = 0; | |
1253 | return 0; | |
1254 | } | |
1255 | ||
1256 | int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb) | |
1257 | { | |
1258 | llc_sk(sk)->data_flag = 1; | |
1259 | return 0; | |
1260 | } | |
1261 | ||
1262 | int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk, | |
1263 | struct sk_buff *skb) | |
1264 | { | |
1265 | if (!llc_sk(sk)->data_flag) | |
1266 | llc_sk(sk)->data_flag = 1; | |
1267 | return 0; | |
1268 | } | |
1269 | ||
1270 | int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb) | |
1271 | { | |
1272 | llc_conn_set_p_flag(sk, 0); | |
1273 | return 0; | |
1274 | } | |
1275 | ||
1276 | static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb) | |
1277 | { | |
1278 | llc_conn_set_p_flag(sk, 1); | |
1279 | return 0; | |
1280 | } | |
1281 | ||
1282 | int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb) | |
1283 | { | |
1284 | llc_sk(sk)->remote_busy_flag = 0; | |
1285 | return 0; | |
1286 | } | |
1287 | ||
1288 | int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb) | |
1289 | { | |
1290 | llc_sk(sk)->cause_flag = 0; | |
1291 | return 0; | |
1292 | } | |
1293 | ||
1294 | int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb) | |
1295 | { | |
1296 | llc_sk(sk)->cause_flag = 1; | |
1297 | return 0; | |
1298 | } | |
1299 | ||
1300 | int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb) | |
1301 | { | |
1302 | llc_sk(sk)->retry_count = 0; | |
1303 | return 0; | |
1304 | } | |
1305 | ||
1306 | int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb) | |
1307 | { | |
1308 | llc_sk(sk)->retry_count++; | |
1309 | return 0; | |
1310 | } | |
1311 | ||
1312 | int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb) | |
1313 | { | |
1314 | llc_sk(sk)->vR = 0; | |
1315 | return 0; | |
1316 | } | |
1317 | ||
1318 | int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb) | |
1319 | { | |
1320 | llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR); | |
1321 | return 0; | |
1322 | } | |
1323 | ||
1324 | int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb) | |
1325 | { | |
1326 | llc_sk(sk)->vS = 0; | |
1327 | return 0; | |
1328 | } | |
1329 | ||
1330 | int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb) | |
1331 | { | |
1332 | llc_sk(sk)->vS = llc_sk(sk)->last_nr; | |
1333 | return 0; | |
1334 | } | |
1335 | ||
1336 | int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb) | |
1337 | { | |
1338 | llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128; | |
1339 | return 0; | |
1340 | } | |
1341 | ||
1342 | void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data) | |
1343 | { | |
1344 | struct sock *sk = (struct sock *)timeout_data; | |
1345 | struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); | |
1346 | ||
1347 | bh_lock_sock(sk); | |
1348 | if (skb) { | |
1349 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
1350 | ||
1351 | skb->sk = sk; | |
1352 | ev->type = LLC_CONN_EV_TYPE_P_TMR; | |
1353 | llc_process_tmr_ev(sk, skb); | |
1354 | } | |
1355 | bh_unlock_sock(sk); | |
1356 | } | |
1357 | ||
1358 | void llc_conn_busy_tmr_cb(unsigned long timeout_data) | |
1359 | { | |
1360 | struct sock *sk = (struct sock *)timeout_data; | |
1361 | struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); | |
1362 | ||
1363 | bh_lock_sock(sk); | |
1364 | if (skb) { | |
1365 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
1366 | ||
1367 | skb->sk = sk; | |
1368 | ev->type = LLC_CONN_EV_TYPE_BUSY_TMR; | |
1369 | llc_process_tmr_ev(sk, skb); | |
1370 | } | |
1371 | bh_unlock_sock(sk); | |
1372 | } | |
1373 | ||
1374 | void llc_conn_ack_tmr_cb(unsigned long timeout_data) | |
1375 | { | |
1376 | struct sock* sk = (struct sock *)timeout_data; | |
1377 | struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); | |
1378 | ||
1379 | bh_lock_sock(sk); | |
1380 | if (skb) { | |
1381 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
1382 | ||
1383 | skb->sk = sk; | |
1384 | ev->type = LLC_CONN_EV_TYPE_ACK_TMR; | |
1385 | llc_process_tmr_ev(sk, skb); | |
1386 | } | |
1387 | bh_unlock_sock(sk); | |
1388 | } | |
1389 | ||
1390 | void llc_conn_rej_tmr_cb(unsigned long timeout_data) | |
1391 | { | |
1392 | struct sock *sk = (struct sock *)timeout_data; | |
1393 | struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); | |
1394 | ||
1395 | bh_lock_sock(sk); | |
1396 | if (skb) { | |
1397 | struct llc_conn_state_ev *ev = llc_conn_ev(skb); | |
1398 | ||
1399 | skb->sk = sk; | |
1400 | ev->type = LLC_CONN_EV_TYPE_REJ_TMR; | |
1401 | llc_process_tmr_ev(sk, skb); | |
1402 | } | |
1403 | bh_unlock_sock(sk); | |
1404 | } | |
1405 | ||
1406 | int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb) | |
1407 | { | |
1408 | llc_sk(sk)->X = llc_sk(sk)->vS; | |
1409 | llc_conn_ac_set_vs_nr(sk, skb); | |
1410 | return 0; | |
1411 | } | |
1412 | ||
1413 | int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb) | |
1414 | { | |
1415 | struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); | |
1416 | u8 nr = PDU_SUPV_GET_Nr(pdu); | |
1417 | ||
1418 | if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X)) | |
1419 | llc_conn_ac_set_vs_nr(sk, skb); | |
1420 | return 0; | |
1421 | } | |
1422 | ||
1423 | /* | |
1424 | * Non-standard actions; these not contained in IEEE specification; for | |
1425 | * our own usage | |
1426 | */ | |
1427 | /** | |
1428 | * llc_conn_disc - removes connection from SAP list and frees it | |
1429 | * @sk: closed connection | |
1430 | * @skb: occurred event | |
1431 | */ | |
1432 | int llc_conn_disc(struct sock *sk, struct sk_buff *skb) | |
1433 | { | |
1434 | /* FIXME: this thing seems to want to die */ | |
1435 | return 0; | |
1436 | } | |
1437 | ||
1438 | /** | |
1439 | * llc_conn_reset - resets connection | |
1440 | * @sk : reseting connection. | |
1441 | * @skb: occurred event. | |
1442 | * | |
1443 | * Stop all timers, empty all queues and reset all flags. | |
1444 | */ | |
1445 | int llc_conn_reset(struct sock *sk, struct sk_buff *skb) | |
1446 | { | |
1447 | llc_sk_reset(sk); | |
1448 | return 0; | |
1449 | } | |
1450 | ||
1451 | /** | |
1452 | * llc_circular_between - designates that b is between a and c or not | |
1453 | * @a: lower bound | |
1454 | * @b: element to see if is between a and b | |
1455 | * @c: upper bound | |
1456 | * | |
1457 | * This function designates that b is between a and c or not (for example, | |
1458 | * 0 is between 127 and 1). Returns 1 if b is between a and c, 0 | |
1459 | * otherwise. | |
1460 | */ | |
1461 | u8 llc_circular_between(u8 a, u8 b, u8 c) | |
1462 | { | |
1463 | b = b - a; | |
1464 | c = c - a; | |
1465 | return b <= c; | |
1466 | } | |
1467 | ||
1468 | /** | |
1469 | * llc_process_tmr_ev - timer backend | |
1470 | * @sk: active connection | |
1471 | * @skb: occurred event | |
1472 | * | |
1473 | * This function is called from timer callback functions. When connection | |
1474 | * is busy (during sending a data frame) timer expiration event must be | |
1475 | * queued. Otherwise this event can be sent to connection state machine. | |
1476 | * Queued events will process by llc_backlog_rcv function after sending | |
1477 | * data frame. | |
1478 | */ | |
1479 | static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb) | |
1480 | { | |
1481 | if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) { | |
1482 | printk(KERN_WARNING "%s: timer called on closed connection\n", | |
1483 | __FUNCTION__); | |
1484 | kfree_skb(skb); | |
1485 | } else { | |
1486 | if (!sock_owned_by_user(sk)) | |
1487 | llc_conn_state_process(sk, skb); | |
1488 | else { | |
1489 | llc_set_backlog_type(skb, LLC_EVENT); | |
1490 | sk_add_backlog(sk, skb); | |
1491 | } | |
1492 | } | |
1493 | } |