ACPI: Delete the IRQ operation in throttling controll via PTC
[linux-2.6/mini2440.git] / net / llc / llc_c_ac.c
blob860140caa6e0ea9aa0a2b61114456e6d74a0db6b
1 /*
2 * llc_c_ac.c - actions performed during connection state transition.
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.
10 * Copyright (c) 1997 by Procom Technology, Inc.
11 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
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.
18 * See the GNU General Public License for more details.
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>
31 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
32 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
33 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev);
35 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
37 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
38 struct sk_buff *skb);
40 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
42 #define INCORRECT 0
44 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
46 struct llc_sock *llc = llc_sk(sk);
48 if (llc->remote_busy_flag) {
49 u8 nr;
50 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
52 llc->remote_busy_flag = 0;
53 del_timer(&llc->busy_state_timer.timer);
54 nr = LLC_I_GET_NR(pdu);
55 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
57 return 0;
60 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
62 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
64 ev->ind_prim = LLC_CONN_PRIM;
65 return 0;
68 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
70 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
72 ev->cfm_prim = LLC_CONN_PRIM;
73 return 0;
76 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
78 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
80 ev->cfm_prim = LLC_DATA_PRIM;
81 return 0;
84 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
86 llc_conn_rtn_pdu(sk, skb);
87 return 0;
90 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
92 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
93 u8 reason = 0;
94 int rc = 0;
96 if (ev->type == LLC_CONN_EV_TYPE_PDU) {
97 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
99 if (LLC_PDU_IS_RSP(pdu) &&
100 LLC_PDU_TYPE_IS_U(pdu) &&
101 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
102 reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
103 else if (LLC_PDU_IS_CMD(pdu) &&
104 LLC_PDU_TYPE_IS_U(pdu) &&
105 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
106 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
107 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
108 reason = LLC_DISC_REASON_ACK_TMR_EXP;
109 else
110 rc = -EINVAL;
111 if (!rc) {
112 ev->reason = reason;
113 ev->ind_prim = LLC_DISC_PRIM;
115 return rc;
118 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
120 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
122 ev->reason = ev->status;
123 ev->cfm_prim = LLC_DISC_PRIM;
124 return 0;
127 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
129 u8 reason = 0;
130 int rc = 1;
131 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
132 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
133 struct llc_sock *llc = llc_sk(sk);
135 switch (ev->type) {
136 case LLC_CONN_EV_TYPE_PDU:
137 if (LLC_PDU_IS_RSP(pdu) &&
138 LLC_PDU_TYPE_IS_U(pdu) &&
139 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
140 reason = LLC_RESET_REASON_LOCAL;
141 rc = 0;
142 } else if (LLC_PDU_IS_CMD(pdu) &&
143 LLC_PDU_TYPE_IS_U(pdu) &&
144 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
145 reason = LLC_RESET_REASON_REMOTE;
146 rc = 0;
148 break;
149 case LLC_CONN_EV_TYPE_ACK_TMR:
150 case LLC_CONN_EV_TYPE_P_TMR:
151 case LLC_CONN_EV_TYPE_REJ_TMR:
152 case LLC_CONN_EV_TYPE_BUSY_TMR:
153 if (llc->retry_count > llc->n2) {
154 reason = LLC_RESET_REASON_LOCAL;
155 rc = 0;
157 break;
159 if (!rc) {
160 ev->reason = reason;
161 ev->ind_prim = LLC_RESET_PRIM;
163 return rc;
166 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
168 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
170 ev->reason = 0;
171 ev->cfm_prim = LLC_RESET_PRIM;
172 return 0;
175 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
176 struct sk_buff *skb)
178 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
180 if (LLC_PDU_IS_RSP(pdu) &&
181 LLC_PDU_TYPE_IS_I(pdu) &&
182 LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
183 llc_conn_ac_clear_remote_busy(sk, skb);
184 return 0;
187 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
188 struct sk_buff *skb)
190 struct llc_sock *llc = llc_sk(sk);
192 if (llc->data_flag == 2)
193 del_timer(&llc->rej_sent_timer.timer);
194 return 0;
197 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
199 int rc = -ENOBUFS;
200 struct llc_sock *llc = llc_sk(sk);
201 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
203 if (nskb) {
204 struct llc_sap *sap = llc->sap;
206 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
207 llc->daddr.lsap, LLC_PDU_CMD);
208 llc_pdu_init_as_disc_cmd(nskb, 1);
209 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
210 if (unlikely(rc))
211 goto free;
212 llc_conn_send_pdu(sk, nskb);
213 llc_conn_ac_set_p_flag_1(sk, skb);
215 out:
216 return rc;
217 free:
218 kfree_skb(nskb);
219 goto out;
222 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
224 int rc = -ENOBUFS;
225 struct llc_sock *llc = llc_sk(sk);
226 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
228 if (nskb) {
229 struct llc_sap *sap = llc->sap;
230 u8 f_bit;
232 llc_pdu_decode_pf_bit(skb, &f_bit);
233 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
234 llc->daddr.lsap, LLC_PDU_RSP);
235 llc_pdu_init_as_dm_rsp(nskb, f_bit);
236 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
237 if (unlikely(rc))
238 goto free;
239 llc_conn_send_pdu(sk, nskb);
241 out:
242 return rc;
243 free:
244 kfree_skb(nskb);
245 goto out;
248 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
250 int rc = -ENOBUFS;
251 struct llc_sock *llc = llc_sk(sk);
252 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
254 if (nskb) {
255 struct llc_sap *sap = llc->sap;
257 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
258 llc->daddr.lsap, LLC_PDU_RSP);
259 llc_pdu_init_as_dm_rsp(nskb, 1);
260 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
261 if (unlikely(rc))
262 goto free;
263 llc_conn_send_pdu(sk, nskb);
265 out:
266 return rc;
267 free:
268 kfree_skb(nskb);
269 goto out;
272 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
274 u8 f_bit;
275 int rc = -ENOBUFS;
276 struct sk_buff *nskb;
277 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
278 struct llc_sock *llc = llc_sk(sk);
280 llc->rx_pdu_hdr = *((u32 *)pdu);
281 if (LLC_PDU_IS_CMD(pdu))
282 llc_pdu_decode_pf_bit(skb, &f_bit);
283 else
284 f_bit = 0;
285 nskb = llc_alloc_frame(sk, llc->dev);
286 if (nskb) {
287 struct llc_sap *sap = llc->sap;
289 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
290 llc->daddr.lsap, LLC_PDU_RSP);
291 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
292 llc->vR, INCORRECT);
293 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
294 if (unlikely(rc))
295 goto free;
296 llc_conn_send_pdu(sk, nskb);
298 out:
299 return rc;
300 free:
301 kfree_skb(nskb);
302 goto out;
305 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
307 int rc = -ENOBUFS;
308 struct llc_sock *llc = llc_sk(sk);
309 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
311 if (nskb) {
312 struct llc_sap *sap = llc->sap;
313 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
315 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
316 llc->daddr.lsap, LLC_PDU_RSP);
317 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
318 llc->vR, INCORRECT);
319 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
320 if (unlikely(rc))
321 goto free;
322 llc_conn_send_pdu(sk, nskb);
324 out:
325 return rc;
326 free:
327 kfree_skb(nskb);
328 goto out;
331 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
333 u8 f_bit;
334 int rc = -ENOBUFS;
335 struct sk_buff *nskb;
336 struct llc_sock *llc = llc_sk(sk);
338 llc_pdu_decode_pf_bit(skb, &f_bit);
339 nskb = llc_alloc_frame(sk, llc->dev);
340 if (nskb) {
341 struct llc_sap *sap = llc->sap;
342 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
344 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
345 llc->daddr.lsap, LLC_PDU_RSP);
346 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
347 llc->vR, INCORRECT);
348 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
349 if (unlikely(rc))
350 goto free;
351 llc_conn_send_pdu(sk, nskb);
353 out:
354 return rc;
355 free:
356 kfree_skb(nskb);
357 goto out;
360 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
362 int rc;
363 struct llc_sock *llc = llc_sk(sk);
364 struct llc_sap *sap = llc->sap;
366 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
367 llc->daddr.lsap, LLC_PDU_CMD);
368 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
369 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
370 if (likely(!rc)) {
371 llc_conn_send_pdu(sk, skb);
372 llc_conn_ac_inc_vs_by_1(sk, skb);
374 return rc;
377 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
379 int rc;
380 struct llc_sock *llc = llc_sk(sk);
381 struct llc_sap *sap = llc->sap;
383 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
384 llc->daddr.lsap, LLC_PDU_CMD);
385 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
386 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
387 if (likely(!rc)) {
388 llc_conn_send_pdu(sk, skb);
389 llc_conn_ac_inc_vs_by_1(sk, skb);
391 return rc;
394 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
396 int rc;
397 struct llc_sock *llc = llc_sk(sk);
398 struct llc_sap *sap = llc->sap;
400 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
401 llc->daddr.lsap, LLC_PDU_CMD);
402 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
403 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
404 if (likely(!rc)) {
405 llc_conn_send_pdu(sk, skb);
406 llc_conn_ac_inc_vs_by_1(sk, skb);
408 return 0;
411 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
413 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
414 u8 nr = LLC_I_GET_NR(pdu);
416 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
417 return 0;
420 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
421 struct sk_buff *skb)
423 u8 nr;
424 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
425 int rc = -ENOBUFS;
426 struct llc_sock *llc = llc_sk(sk);
427 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
429 if (nskb) {
430 struct llc_sap *sap = llc->sap;
432 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
433 llc->daddr.lsap, LLC_PDU_RSP);
434 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
435 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
436 if (likely(!rc))
437 llc_conn_send_pdu(sk, nskb);
438 else
439 kfree_skb(skb);
441 if (rc) {
442 nr = LLC_I_GET_NR(pdu);
443 rc = 0;
444 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
446 return rc;
449 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
451 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
452 u8 nr = LLC_I_GET_NR(pdu);
454 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
455 return 0;
458 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
460 int rc = -ENOBUFS;
461 struct llc_sock *llc = llc_sk(sk);
462 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
464 if (nskb) {
465 struct llc_sap *sap = llc->sap;
467 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
468 llc->daddr.lsap, LLC_PDU_CMD);
469 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
470 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
471 if (unlikely(rc))
472 goto free;
473 llc_conn_send_pdu(sk, nskb);
475 out:
476 return rc;
477 free:
478 kfree_skb(nskb);
479 goto out;
482 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
484 int rc = -ENOBUFS;
485 struct llc_sock *llc = llc_sk(sk);
486 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
488 if (nskb) {
489 struct llc_sap *sap = llc->sap;
491 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
492 llc->daddr.lsap, LLC_PDU_RSP);
493 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
494 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
495 if (unlikely(rc))
496 goto free;
497 llc_conn_send_pdu(sk, nskb);
499 out:
500 return rc;
501 free:
502 kfree_skb(nskb);
503 goto out;
506 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
508 int rc = -ENOBUFS;
509 struct llc_sock *llc = llc_sk(sk);
510 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
512 if (nskb) {
513 struct llc_sap *sap = llc->sap;
515 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
516 llc->daddr.lsap, LLC_PDU_RSP);
517 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
518 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
519 if (unlikely(rc))
520 goto free;
521 llc_conn_send_pdu(sk, nskb);
523 out:
524 return rc;
525 free:
526 kfree_skb(nskb);
527 goto out;
530 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
532 int rc = -ENOBUFS;
533 struct llc_sock *llc = llc_sk(sk);
534 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
536 if (nskb) {
537 struct llc_sap *sap = llc->sap;
539 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
540 llc->daddr.lsap, LLC_PDU_CMD);
541 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
542 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
543 if (unlikely(rc))
544 goto free;
545 llc_conn_send_pdu(sk, nskb);
547 out:
548 return rc;
549 free:
550 kfree_skb(nskb);
551 goto out;
554 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
556 int rc = -ENOBUFS;
557 struct llc_sock *llc = llc_sk(sk);
558 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
560 if (nskb) {
561 struct llc_sap *sap = llc->sap;
563 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
564 llc->daddr.lsap, LLC_PDU_RSP);
565 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
566 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
567 if (unlikely(rc))
568 goto free;
569 llc_conn_send_pdu(sk, nskb);
571 out:
572 return rc;
573 free:
574 kfree_skb(nskb);
575 goto out;
578 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
580 int rc = -ENOBUFS;
581 struct llc_sock *llc = llc_sk(sk);
582 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
584 if (nskb) {
585 struct llc_sap *sap = llc->sap;
587 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
588 llc->daddr.lsap, LLC_PDU_RSP);
589 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
590 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
591 if (unlikely(rc))
592 goto free;
593 llc_conn_send_pdu(sk, nskb);
595 out:
596 return rc;
597 free:
598 kfree_skb(nskb);
599 goto out;
602 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
604 struct llc_sock *llc = llc_sk(sk);
606 if (!llc->remote_busy_flag) {
607 llc->remote_busy_flag = 1;
608 mod_timer(&llc->busy_state_timer.timer,
609 jiffies + llc->busy_state_timer.expire);
611 return 0;
614 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
616 int rc = -ENOBUFS;
617 struct llc_sock *llc = llc_sk(sk);
618 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
620 if (nskb) {
621 struct llc_sap *sap = llc->sap;
623 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
624 llc->daddr.lsap, LLC_PDU_RSP);
625 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
626 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
627 if (unlikely(rc))
628 goto free;
629 llc_conn_send_pdu(sk, nskb);
631 out:
632 return rc;
633 free:
634 kfree_skb(nskb);
635 goto out;
638 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
640 int rc = -ENOBUFS;
641 struct llc_sock *llc = llc_sk(sk);
642 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
644 if (nskb) {
645 struct llc_sap *sap = llc->sap;
647 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
648 llc->daddr.lsap, LLC_PDU_CMD);
649 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
650 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
651 if (unlikely(rc))
652 goto free;
653 llc_conn_send_pdu(sk, nskb);
655 out:
656 return rc;
657 free:
658 kfree_skb(nskb);
659 goto out;
662 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
664 int rc = -ENOBUFS;
665 struct llc_sock *llc = llc_sk(sk);
666 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
668 if (nskb) {
669 struct llc_sap *sap = llc->sap;
670 u8 f_bit = 1;
672 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
673 llc->daddr.lsap, LLC_PDU_RSP);
674 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
675 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
676 if (unlikely(rc))
677 goto free;
678 llc_conn_send_pdu(sk, nskb);
680 out:
681 return rc;
682 free:
683 kfree_skb(nskb);
684 goto out;
687 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
689 int rc = -ENOBUFS;
690 struct llc_sock *llc = llc_sk(sk);
691 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
693 if (nskb) {
694 struct llc_sap *sap = llc->sap;
696 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
697 llc->daddr.lsap, LLC_PDU_RSP);
698 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
699 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
700 if (unlikely(rc))
701 goto free;
702 llc_conn_send_pdu(sk, nskb);
704 out:
705 return rc;
706 free:
707 kfree_skb(nskb);
708 goto out;
711 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
713 int rc = -ENOBUFS;
714 struct llc_sock *llc = llc_sk(sk);
715 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
717 if (nskb) {
718 struct llc_sap *sap = llc->sap;
720 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
721 llc->daddr.lsap, LLC_PDU_RSP);
722 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
723 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
724 if (unlikely(rc))
725 goto free;
726 llc_conn_send_pdu(sk, nskb);
728 out:
729 return rc;
730 free:
731 kfree_skb(nskb);
732 goto out;
735 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
737 int rc = -ENOBUFS;
738 struct llc_sock *llc = llc_sk(sk);
739 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
741 if (nskb) {
742 struct llc_sap *sap = llc->sap;
744 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
745 llc->daddr.lsap, LLC_PDU_RSP);
746 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
747 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
748 if (unlikely(rc))
749 goto free;
750 llc_conn_send_pdu(sk, nskb);
752 out:
753 return rc;
754 free:
755 kfree_skb(nskb);
756 goto out;
759 void llc_conn_set_p_flag(struct sock *sk, u8 value)
761 int state_changed = llc_sk(sk)->p_flag && !value;
763 llc_sk(sk)->p_flag = value;
765 if (state_changed)
766 sk->sk_state_change(sk);
769 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
771 int rc = -ENOBUFS;
772 struct llc_sock *llc = llc_sk(sk);
773 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
775 if (nskb) {
776 struct llc_sap *sap = llc->sap;
777 u8 *dmac = llc->daddr.mac;
779 if (llc->dev->flags & IFF_LOOPBACK)
780 dmac = llc->dev->dev_addr;
781 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
782 llc->daddr.lsap, LLC_PDU_CMD);
783 llc_pdu_init_as_sabme_cmd(nskb, 1);
784 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
785 if (unlikely(rc))
786 goto free;
787 llc_conn_send_pdu(sk, nskb);
788 llc_conn_set_p_flag(sk, 1);
790 out:
791 return rc;
792 free:
793 kfree_skb(nskb);
794 goto out;
797 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
799 u8 f_bit;
800 int rc = -ENOBUFS;
801 struct llc_sock *llc = llc_sk(sk);
802 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
804 llc_pdu_decode_pf_bit(skb, &f_bit);
805 if (nskb) {
806 struct llc_sap *sap = llc->sap;
808 nskb->dev = llc->dev;
809 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
810 llc->daddr.lsap, LLC_PDU_RSP);
811 llc_pdu_init_as_ua_rsp(nskb, f_bit);
812 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
813 if (unlikely(rc))
814 goto free;
815 llc_conn_send_pdu(sk, nskb);
817 out:
818 return rc;
819 free:
820 kfree_skb(nskb);
821 goto out;
824 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
826 llc_sk(sk)->s_flag = 0;
827 return 0;
830 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
832 llc_sk(sk)->s_flag = 1;
833 return 0;
836 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
838 struct llc_sock *llc = llc_sk(sk);
840 llc_conn_set_p_flag(sk, 1);
841 mod_timer(&llc->pf_cycle_timer.timer,
842 jiffies + llc->pf_cycle_timer.expire);
843 return 0;
847 * llc_conn_ac_send_ack_if_needed - check if ack is needed
848 * @sk: current connection structure
849 * @skb: current event
851 * Checks number of received PDUs which have not been acknowledged, yet,
852 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
853 * sends an RR response as acknowledgement for them. Returns 0 for
854 * success, 1 otherwise.
856 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
858 u8 pf_bit;
859 struct llc_sock *llc = llc_sk(sk);
861 llc_pdu_decode_pf_bit(skb, &pf_bit);
862 llc->ack_pf |= pf_bit & 1;
863 if (!llc->ack_must_be_send) {
864 llc->first_pdu_Ns = llc->vR;
865 llc->ack_must_be_send = 1;
866 llc->ack_pf = pf_bit & 1;
868 if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
869 % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
870 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
871 llc->ack_must_be_send = 0;
872 llc->ack_pf = 0;
873 llc_conn_ac_inc_npta_value(sk, skb);
875 return 0;
879 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
880 * @sk: current connection structure
881 * @skb: current event
883 * This action resets ack_must_be_send flag of given connection, this flag
884 * indicates if there is any PDU which has not been acknowledged yet.
885 * Returns 0 for success, 1 otherwise.
887 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
889 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
890 return 0;
894 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
895 * @sk: current connection structure
896 * @skb: current event
898 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
899 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
900 * set to one if one PDU with p-bit set to one is received. Returns 0 for
901 * success, 1 otherwise.
903 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
904 struct sk_buff *skb)
906 int rc;
907 struct llc_sock *llc = llc_sk(sk);
908 struct llc_sap *sap = llc->sap;
910 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
911 llc->daddr.lsap, LLC_PDU_RSP);
912 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
913 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
914 if (likely(!rc)) {
915 llc_conn_send_pdu(sk, skb);
916 llc_conn_ac_inc_vs_by_1(sk, skb);
918 return rc;
922 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
923 * @sk: current connection structure.
924 * @skb: current event.
926 * This action sends an I-format PDU as acknowledge to received PDUs which
927 * have not been acknowledged, yet, if there is any. By using of this
928 * action number of acknowledgements decreases, this technic is called
929 * piggy backing. Returns 0 for success, 1 otherwise.
931 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
933 struct llc_sock *llc = llc_sk(sk);
935 if (llc->ack_must_be_send) {
936 llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
937 llc->ack_must_be_send = 0 ;
938 llc->ack_pf = 0;
939 } else
940 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
941 return 0;
945 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
946 * @sk: current connection structure.
947 * @skb: current event.
949 * This action sends an RR response with f-bit set to ack_pf flag as
950 * acknowledge to all received PDUs which have not been acknowledged, yet,
951 * if there is any. ack_pf flag indicates if a PDU has been received with
952 * p-bit set to one. Returns 0 for success, 1 otherwise.
954 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
955 struct sk_buff *skb)
957 int rc = -ENOBUFS;
958 struct llc_sock *llc = llc_sk(sk);
959 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
961 if (nskb) {
962 struct llc_sap *sap = llc->sap;
964 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
965 llc->daddr.lsap, LLC_PDU_RSP);
966 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
967 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
968 if (unlikely(rc))
969 goto free;
970 llc_conn_send_pdu(sk, nskb);
972 out:
973 return rc;
974 free:
975 kfree_skb(nskb);
976 goto out;
980 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
981 * @sk: current connection structure.
982 * @skb: current event.
984 * After "inc_cntr" times calling of this action, "npta" increase by one.
985 * this action tries to make vale of "npta" greater as possible; number of
986 * acknowledgements decreases by increasing of "npta". Returns 0 for
987 * success, 1 otherwise.
989 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
991 struct llc_sock *llc = llc_sk(sk);
993 if (!llc->inc_cntr) {
994 llc->dec_step = 0;
995 llc->dec_cntr = llc->inc_cntr = 2;
996 ++llc->npta;
997 if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
998 llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
999 } else
1000 --llc->inc_cntr;
1001 return 0;
1005 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1006 * @sk: current connection structure.
1007 * @skb: current event.
1009 * After receiving "dec_cntr" times RR command, this action decreases
1010 * "npta" by one. Returns 0 for success, 1 otherwise.
1012 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1014 struct llc_sock *llc = llc_sk(sk);
1016 if (!llc->connect_step && !llc->remote_busy_flag) {
1017 if (!llc->dec_step) {
1018 if (!llc->dec_cntr) {
1019 llc->inc_cntr = llc->dec_cntr = 2;
1020 if (llc->npta > 0)
1021 llc->npta = llc->npta - 1;
1022 } else
1023 llc->dec_cntr -=1;
1025 } else
1026 llc->connect_step = 0 ;
1027 return 0;
1031 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1032 * @sk: current connection structure.
1033 * @skb: current event.
1035 * After receiving "dec_cntr" times RNR command, this action decreases
1036 * "npta" by one. Returns 0 for success, 1 otherwise.
1038 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1040 struct llc_sock *llc = llc_sk(sk);
1042 if (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;
1048 } else
1049 --llc->dec_cntr;
1051 return 0;
1055 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1056 * @sk: current connection structure.
1057 * @skb: current event.
1059 * After receiving of a REJ command or response, transmit window size is
1060 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1061 * success, 1 otherwise.
1063 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1065 struct llc_sock *llc = llc_sk(sk);
1066 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1068 if (llc->k - unacked_pdu < 1)
1069 llc->k = 1;
1070 else
1071 llc->k -= unacked_pdu;
1072 return 0;
1076 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1077 * @sk: current connection structure.
1078 * @skb: current event.
1080 * After receiving an RR response with f-bit set to one, transmit window
1081 * size is increased by one. Returns 0 for success, 1 otherwise.
1083 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1085 struct llc_sock *llc = llc_sk(sk);
1087 llc->k += 1;
1088 if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1089 llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
1090 return 0;
1093 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1095 struct llc_sock *llc = llc_sk(sk);
1097 del_timer(&llc->pf_cycle_timer.timer);
1098 del_timer(&llc->ack_timer.timer);
1099 del_timer(&llc->rej_sent_timer.timer);
1100 del_timer(&llc->busy_state_timer.timer);
1101 llc->ack_must_be_send = 0;
1102 llc->ack_pf = 0;
1103 return 0;
1106 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1108 struct llc_sock *llc = llc_sk(sk);
1110 del_timer(&llc->rej_sent_timer.timer);
1111 del_timer(&llc->pf_cycle_timer.timer);
1112 del_timer(&llc->busy_state_timer.timer);
1113 llc->ack_must_be_send = 0;
1114 llc->ack_pf = 0;
1115 return 0;
1118 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1120 struct llc_sock *llc = llc_sk(sk);
1122 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1123 return 0;
1126 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1128 struct llc_sock *llc = llc_sk(sk);
1130 mod_timer(&llc->rej_sent_timer.timer,
1131 jiffies + llc->rej_sent_timer.expire);
1132 return 0;
1135 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1136 struct sk_buff *skb)
1138 struct llc_sock *llc = llc_sk(sk);
1140 if (!timer_pending(&llc->ack_timer.timer))
1141 mod_timer(&llc->ack_timer.timer,
1142 jiffies + llc->ack_timer.expire);
1143 return 0;
1146 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1148 del_timer(&llc_sk(sk)->ack_timer.timer);
1149 return 0;
1152 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1154 struct llc_sock *llc = llc_sk(sk);
1156 del_timer(&llc->pf_cycle_timer.timer);
1157 llc_conn_set_p_flag(sk, 0);
1158 return 0;
1161 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1163 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1164 return 0;
1167 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1169 int acked;
1170 u16 unacked = 0;
1171 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1172 struct llc_sock *llc = llc_sk(sk);
1174 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1175 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1176 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1177 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1178 llc->retry_count = 0;
1179 del_timer(&llc->ack_timer.timer);
1180 if (llc->failed_data_req) {
1181 /* already, we did not accept data from upper layer
1182 * (tx_window full or unacceptable state). Now, we
1183 * can send data and must inform to upper layer.
1185 llc->failed_data_req = 0;
1186 llc_conn_ac_data_confirm(sk, skb);
1188 if (unacked)
1189 mod_timer(&llc->ack_timer.timer,
1190 jiffies + llc->ack_timer.expire);
1191 } else if (llc->failed_data_req) {
1192 u8 f_bit;
1194 llc_pdu_decode_pf_bit(skb, &f_bit);
1195 if (f_bit == 1) {
1196 llc->failed_data_req = 0;
1197 llc_conn_ac_data_confirm(sk, skb);
1200 return 0;
1203 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1205 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1207 if (LLC_PDU_IS_RSP(pdu)) {
1208 u8 f_bit;
1210 llc_pdu_decode_pf_bit(skb, &f_bit);
1211 if (f_bit) {
1212 llc_conn_set_p_flag(sk, 0);
1213 llc_conn_ac_stop_p_timer(sk, skb);
1216 return 0;
1219 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1221 llc_sk(sk)->data_flag = 2;
1222 return 0;
1225 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1227 llc_sk(sk)->data_flag = 0;
1228 return 0;
1231 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1233 llc_sk(sk)->data_flag = 1;
1234 return 0;
1237 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1238 struct sk_buff *skb)
1240 if (!llc_sk(sk)->data_flag)
1241 llc_sk(sk)->data_flag = 1;
1242 return 0;
1245 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1247 llc_conn_set_p_flag(sk, 0);
1248 return 0;
1251 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1253 llc_conn_set_p_flag(sk, 1);
1254 return 0;
1257 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1259 llc_sk(sk)->remote_busy_flag = 0;
1260 return 0;
1263 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1265 llc_sk(sk)->cause_flag = 0;
1266 return 0;
1269 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1271 llc_sk(sk)->cause_flag = 1;
1272 return 0;
1275 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1277 llc_sk(sk)->retry_count = 0;
1278 return 0;
1281 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1283 llc_sk(sk)->retry_count++;
1284 return 0;
1287 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1289 llc_sk(sk)->vR = 0;
1290 return 0;
1293 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1295 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1296 return 0;
1299 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1301 llc_sk(sk)->vS = 0;
1302 return 0;
1305 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1307 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1308 return 0;
1311 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1313 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
1314 return 0;
1317 static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
1319 struct sock *sk = (struct sock *)timeout_data;
1320 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1322 bh_lock_sock(sk);
1323 if (skb) {
1324 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1326 skb_set_owner_r(skb, sk);
1327 ev->type = type;
1328 llc_process_tmr_ev(sk, skb);
1330 bh_unlock_sock(sk);
1333 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1335 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
1338 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1340 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
1343 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1345 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
1348 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1350 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
1353 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1355 llc_sk(sk)->X = llc_sk(sk)->vS;
1356 llc_conn_ac_set_vs_nr(sk, skb);
1357 return 0;
1360 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1362 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1363 u8 nr = PDU_SUPV_GET_Nr(pdu);
1365 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1366 llc_conn_ac_set_vs_nr(sk, skb);
1367 return 0;
1371 * Non-standard actions; these not contained in IEEE specification; for
1372 * our own usage
1375 * llc_conn_disc - removes connection from SAP list and frees it
1376 * @sk: closed connection
1377 * @skb: occurred event
1379 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1381 /* FIXME: this thing seems to want to die */
1382 return 0;
1386 * llc_conn_reset - resets connection
1387 * @sk : reseting connection.
1388 * @skb: occurred event.
1390 * Stop all timers, empty all queues and reset all flags.
1392 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1394 llc_sk_reset(sk);
1395 return 0;
1399 * llc_circular_between - designates that b is between a and c or not
1400 * @a: lower bound
1401 * @b: element to see if is between a and b
1402 * @c: upper bound
1404 * This function designates that b is between a and c or not (for example,
1405 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1406 * otherwise.
1408 u8 llc_circular_between(u8 a, u8 b, u8 c)
1410 b = b - a;
1411 c = c - a;
1412 return b <= c;
1416 * llc_process_tmr_ev - timer backend
1417 * @sk: active connection
1418 * @skb: occurred event
1420 * This function is called from timer callback functions. When connection
1421 * is busy (during sending a data frame) timer expiration event must be
1422 * queued. Otherwise this event can be sent to connection state machine.
1423 * Queued events will process by llc_backlog_rcv function after sending
1424 * data frame.
1426 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1428 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1429 printk(KERN_WARNING "%s: timer called on closed connection\n",
1430 __FUNCTION__);
1431 kfree_skb(skb);
1432 } else {
1433 if (!sock_owned_by_user(sk))
1434 llc_conn_state_process(sk, skb);
1435 else {
1436 llc_set_backlog_type(skb, LLC_EVENT);
1437 sk_add_backlog(sk, skb);