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