2 * llc_c_ac.c - actions performed during connection state transition.
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>
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>
30 #include "llc_output.h"
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);
36 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
38 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
41 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
45 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
47 struct llc_sock *llc = llc_sk(sk);
49 if (llc->remote_busy_flag) {
51 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
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);
61 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
67 llc_pdu_decode_dsap(skb, &dsap);
68 sap = llc_sap_find(dsap);
70 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
71 struct llc_sock *llc = llc_sk(sk);
73 llc_pdu_decode_sa(skb, llc->daddr.mac);
74 llc_pdu_decode_da(skb, llc->laddr.mac);
76 ev->ind_prim = LLC_CONN_PRIM;
82 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
84 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
86 ev->cfm_prim = LLC_CONN_PRIM;
90 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
92 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
94 ev->cfm_prim = LLC_DATA_PRIM;
98 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
100 llc_conn_rtn_pdu(sk, skb);
104 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
106 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
110 if (ev->type == LLC_CONN_EV_TYPE_PDU) {
111 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
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;
129 ev->ind_prim = LLC_DISC_PRIM;
134 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
136 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
138 ev->reason = ev->status;
139 ev->cfm_prim = LLC_DISC_PRIM;
143 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
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);
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;
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;
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;
181 ev->ind_prim = LLC_RESET_PRIM;
186 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
188 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
191 ev->cfm_prim = LLC_RESET_PRIM;
195 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
198 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
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);
207 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
210 struct llc_sock *llc = llc_sk(sk);
212 if (llc->data_flag == 2)
213 del_timer(&llc->rej_sent_timer.timer);
217 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
220 struct llc_sock *llc = llc_sk(sk);
221 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
224 struct llc_sap *sap = llc->sap;
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);
232 llc_conn_send_pdu(sk, nskb);
233 llc_conn_ac_set_p_flag_1(sk, skb);
242 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
245 struct llc_sock *llc = llc_sk(sk);
246 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
249 struct llc_sap *sap = llc->sap;
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);
259 llc_conn_send_pdu(sk, nskb);
268 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
271 struct llc_sock *llc = llc_sk(sk);
272 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
275 struct llc_sap *sap = llc->sap;
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);
284 llc_conn_send_pdu(sk, nskb);
293 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
297 struct sk_buff *nskb;
298 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
299 struct llc_sock *llc = llc_sk(sk);
301 llc->rx_pdu_hdr = *((u32 *)pdu);
302 if (LLC_PDU_IS_CMD(pdu))
303 llc_pdu_decode_pf_bit(skb, &f_bit);
306 nskb = llc_alloc_frame(llc->dev);
308 struct llc_sap *sap = llc->sap;
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,
314 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
317 llc_conn_send_pdu(sk, nskb);
326 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
329 struct llc_sock *llc = llc_sk(sk);
330 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
334 struct llc_sap *sap = llc->sap;
335 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
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,
341 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
344 llc_conn_send_pdu(sk, nskb);
353 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
357 struct sk_buff *nskb;
358 struct llc_sock *llc = llc_sk(sk);
360 llc_pdu_decode_pf_bit(skb, &f_bit);
361 nskb = llc_alloc_frame(llc->dev);
363 struct llc_sap *sap = llc->sap;
364 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
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,
370 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
373 llc_conn_send_pdu(sk, nskb);
382 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
385 struct llc_sock *llc = llc_sk(sk);
386 struct llc_sap *sap = llc->sap;
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);
393 llc_conn_send_pdu(sk, skb);
394 llc_conn_ac_inc_vs_by_1(sk, skb);
399 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
402 struct llc_sock *llc = llc_sk(sk);
403 struct llc_sap *sap = llc->sap;
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);
410 llc_conn_send_pdu(sk, skb);
411 llc_conn_ac_inc_vs_by_1(sk, skb);
416 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
419 struct llc_sock *llc = llc_sk(sk);
420 struct llc_sap *sap = llc->sap;
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);
427 llc_conn_send_pdu(sk, skb);
428 llc_conn_ac_inc_vs_by_1(sk, skb);
433 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
435 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
436 u8 nr = LLC_I_GET_NR(pdu);
438 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
442 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
446 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
448 struct llc_sock *llc = llc_sk(sk);
449 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
452 struct llc_sap *sap = llc->sap;
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);
459 llc_conn_send_pdu(sk, nskb);
464 nr = LLC_I_GET_NR(pdu);
466 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
471 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
473 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
474 u8 nr = LLC_I_GET_NR(pdu);
476 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
480 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
483 struct llc_sock *llc = llc_sk(sk);
484 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
487 struct llc_sap *sap = llc->sap;
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);
495 llc_conn_send_pdu(sk, nskb);
504 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
507 struct llc_sock *llc = llc_sk(sk);
508 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
512 struct llc_sap *sap = llc->sap;
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);
520 llc_conn_send_pdu(sk, nskb);
529 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
532 struct llc_sock *llc = llc_sk(sk);
533 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
536 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_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);
545 llc_conn_send_pdu(sk, nskb);
554 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
557 struct llc_sock *llc = llc_sk(sk);
558 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
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_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);
569 llc_conn_send_pdu(sk, nskb);
578 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
581 struct llc_sock *llc = llc_sk(sk);
582 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
585 struct llc_sap *sap = llc->sap;
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);
594 llc_conn_send_pdu(sk, nskb);
603 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
606 struct llc_sock *llc = llc_sk(sk);
607 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
611 struct llc_sap *sap = llc->sap;
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);
619 llc_conn_send_pdu(sk, nskb);
628 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
630 struct llc_sock *llc = llc_sk(sk);
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);
640 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
643 struct llc_sock *llc = llc_sk(sk);
644 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
647 struct llc_sap *sap = llc->sap;
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);
655 llc_conn_send_pdu(sk, nskb);
664 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
667 struct llc_sock *llc = llc_sk(sk);
668 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
671 struct llc_sap *sap = llc->sap;
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);
679 llc_conn_send_pdu(sk, nskb);
688 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
691 struct llc_sock *llc = llc_sk(sk);
692 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
695 struct llc_sap *sap = llc->sap;
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);
704 llc_conn_send_pdu(sk, nskb);
713 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
716 struct llc_sock *llc = llc_sk(sk);
717 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
720 struct llc_sap *sap = llc->sap;
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);
729 llc_conn_send_pdu(sk, nskb);
738 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
741 struct llc_sock *llc = llc_sk(sk);
742 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
745 struct llc_sap *sap = llc->sap;
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);
753 llc_conn_send_pdu(sk, nskb);
762 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
765 struct llc_sock *llc = llc_sk(sk);
766 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
769 struct llc_sap *sap = llc->sap;
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);
777 llc_conn_send_pdu(sk, nskb);
786 void llc_conn_set_p_flag(struct sock *sk, u8 value)
788 int state_changed = llc_sk(sk)->p_flag && !value;
790 llc_sk(sk)->p_flag = value;
793 sk->sk_state_change(sk);
796 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
799 struct llc_sock *llc = llc_sk(sk);
800 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
803 struct llc_sap *sap = llc->sap;
804 u8 *dmac = llc->daddr.mac;
806 if (llc->dev->flags & IFF_LOOPBACK)
807 dmac = llc->dev->dev_addr;
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);
814 llc_conn_send_pdu(sk, nskb);
815 llc_conn_set_p_flag(sk, 1);
824 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
828 struct llc_sock *llc = llc_sk(sk);
829 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
831 llc_pdu_decode_pf_bit(skb, &f_bit);
833 struct llc_sap *sap = llc->sap;
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);
842 llc_conn_send_pdu(sk, nskb);
851 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
853 llc_sk(sk)->s_flag = 0;
857 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
859 llc_sk(sk)->s_flag = 1;
863 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
865 struct llc_sock *llc = llc_sk(sk);
867 llc_conn_set_p_flag(sk, 1);
868 mod_timer(&llc->pf_cycle_timer.timer,
869 jiffies + llc->pf_cycle_timer.expire * HZ);
874 * llc_conn_ac_send_ack_if_needed - check if ack is needed
875 * @sk: current connection structure
876 * @skb: current event
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.
883 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
886 struct llc_sock *llc = llc_sk(sk);
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;
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;
899 llc_conn_ac_inc_npta_value(sk, skb);
905 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
906 * @sk: current connection structure
907 * @skb: current event
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.
913 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
915 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
920 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
921 * @sk: current connection structure
922 * @skb: current event
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.
929 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
933 struct llc_sock *llc = llc_sk(sk);
934 struct llc_sap *sap = llc->sap;
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);
941 llc_conn_send_pdu(sk, skb);
942 llc_conn_ac_inc_vs_by_1(sk, skb);
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.
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.
957 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
959 struct llc_sock *llc = llc_sk(sk);
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 ;
966 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
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.
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.
980 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
984 struct llc_sock *llc = llc_sk(sk);
985 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
988 struct llc_sap *sap = llc->sap;
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);
996 llc_conn_send_pdu(sk, nskb);
1006 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
1007 * @sk: current connection structure.
1008 * @skb: current event.
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.
1015 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
1017 struct llc_sock *llc = llc_sk(sk);
1019 if (!llc->inc_cntr) {
1021 llc->dec_cntr = llc->inc_cntr = 2;
1023 if (llc->npta > 127)
1031 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1032 * @sk: current connection structure.
1033 * @skb: current event.
1035 * After receiving "dec_cntr" times RR command, this action decreases
1036 * "npta" by one. Returns 0 for success, 1 otherwise.
1038 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1040 struct llc_sock *llc = llc_sk(sk);
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;
1047 llc->npta = llc->npta - 1;
1052 llc->connect_step = 0 ;
1057 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1058 * @sk: current connection structure.
1059 * @skb: current event.
1061 * After receiving "dec_cntr" times RNR command, this action decreases
1062 * "npta" by one. Returns 0 for success, 1 otherwise.
1064 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1066 struct llc_sock *llc = llc_sk(sk);
1068 if (llc->remote_busy_flag)
1069 if (!llc->dec_step) {
1070 if (!llc->dec_cntr) {
1071 llc->inc_cntr = llc->dec_cntr = 2;
1081 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1082 * @sk: current connection structure.
1083 * @skb: current event.
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.
1089 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1091 struct llc_sock *llc = llc_sk(sk);
1092 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1094 llc->k -= unacked_pdu;
1101 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1102 * @sk: current connection structure.
1103 * @skb: current event.
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.
1108 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1110 struct llc_sock *llc = llc_sk(sk);
1118 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1120 struct llc_sock *llc = llc_sk(sk);
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;
1131 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1133 struct llc_sock *llc = llc_sk(sk);
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;
1143 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1145 struct llc_sock *llc = llc_sk(sk);
1147 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire * HZ);
1151 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1153 struct llc_sock *llc = llc_sk(sk);
1155 mod_timer(&llc->rej_sent_timer.timer,
1156 jiffies + llc->rej_sent_timer.expire * HZ);
1160 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1161 struct sk_buff *skb)
1163 struct llc_sock *llc = llc_sk(sk);
1165 if (!timer_pending(&llc->ack_timer.timer))
1166 mod_timer(&llc->ack_timer.timer,
1167 jiffies + llc->ack_timer.expire * HZ);
1171 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1173 del_timer(&llc_sk(sk)->ack_timer.timer);
1177 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1179 struct llc_sock *llc = llc_sk(sk);
1181 del_timer(&llc->pf_cycle_timer.timer);
1182 llc_conn_set_p_flag(sk, 0);
1186 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1188 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1192 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1196 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1197 struct llc_sock *llc = llc_sk(sk);
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.
1210 llc->failed_data_req = 0;
1211 llc_conn_ac_data_confirm(sk, skb);
1214 mod_timer(&llc->ack_timer.timer,
1215 jiffies + llc->ack_timer.expire * HZ);
1216 } else if (llc->failed_data_req) {
1219 llc_pdu_decode_pf_bit(skb, &f_bit);
1221 llc->failed_data_req = 0;
1222 llc_conn_ac_data_confirm(sk, skb);
1228 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1230 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1232 if (LLC_PDU_IS_RSP(pdu)) {
1235 llc_pdu_decode_pf_bit(skb, &f_bit);
1237 llc_conn_set_p_flag(sk, 0);
1238 llc_conn_ac_stop_p_timer(sk, skb);
1244 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1246 llc_sk(sk)->data_flag = 2;
1250 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1252 llc_sk(sk)->data_flag = 0;
1256 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1258 llc_sk(sk)->data_flag = 1;
1262 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1263 struct sk_buff *skb)
1265 if (!llc_sk(sk)->data_flag)
1266 llc_sk(sk)->data_flag = 1;
1270 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1272 llc_conn_set_p_flag(sk, 0);
1276 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1278 llc_conn_set_p_flag(sk, 1);
1282 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1284 llc_sk(sk)->remote_busy_flag = 0;
1288 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1290 llc_sk(sk)->cause_flag = 0;
1294 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1296 llc_sk(sk)->cause_flag = 1;
1300 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1302 llc_sk(sk)->retry_count = 0;
1306 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1308 llc_sk(sk)->retry_count++;
1312 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1318 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1320 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1324 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1330 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1332 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1336 int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1338 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128;
1342 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1344 struct sock *sk = (struct sock *)timeout_data;
1345 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1349 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1352 ev->type = LLC_CONN_EV_TYPE_P_TMR;
1353 llc_process_tmr_ev(sk, skb);
1358 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1360 struct sock *sk = (struct sock *)timeout_data;
1361 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1365 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1368 ev->type = LLC_CONN_EV_TYPE_BUSY_TMR;
1369 llc_process_tmr_ev(sk, skb);
1374 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1376 struct sock* sk = (struct sock *)timeout_data;
1377 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1381 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1384 ev->type = LLC_CONN_EV_TYPE_ACK_TMR;
1385 llc_process_tmr_ev(sk, skb);
1390 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1392 struct sock *sk = (struct sock *)timeout_data;
1393 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1397 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1400 ev->type = LLC_CONN_EV_TYPE_REJ_TMR;
1401 llc_process_tmr_ev(sk, skb);
1406 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1408 llc_sk(sk)->X = llc_sk(sk)->vS;
1409 llc_conn_ac_set_vs_nr(sk, skb);
1413 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1415 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1416 u8 nr = PDU_SUPV_GET_Nr(pdu);
1418 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1419 llc_conn_ac_set_vs_nr(sk, skb);
1424 * Non-standard actions; these not contained in IEEE specification; for
1428 * llc_conn_disc - removes connection from SAP list and frees it
1429 * @sk: closed connection
1430 * @skb: occurred event
1432 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1434 /* FIXME: this thing seems to want to die */
1439 * llc_conn_reset - resets connection
1440 * @sk : reseting connection.
1441 * @skb: occurred event.
1443 * Stop all timers, empty all queues and reset all flags.
1445 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1452 * llc_circular_between - designates that b is between a and c or not
1454 * @b: element to see if is between a and b
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
1461 u8 llc_circular_between(u8 a, u8 b, u8 c)
1469 * llc_process_tmr_ev - timer backend
1470 * @sk: active connection
1471 * @skb: occurred event
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
1479 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1481 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1482 printk(KERN_WARNING "%s: timer called on closed connection\n",
1486 if (!sock_owned_by_user(sk))
1487 llc_conn_state_process(sk, skb);
1489 llc_set_backlog_type(skb, LLC_EVENT);
1490 sk_add_backlog(sk, skb);