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>
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,
40 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
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) {
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);
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;
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;
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;
84 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
86 llc_conn_rtn_pdu(sk, skb);
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);
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;
113 ev->ind_prim = LLC_DISC_PRIM;
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;
127 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
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);
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;
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;
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;
161 ev->ind_prim = LLC_RESET_PRIM;
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);
171 ev->cfm_prim = LLC_RESET_PRIM;
175 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
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);
187 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
190 struct llc_sock *llc = llc_sk(sk);
192 if (llc->data_flag == 2)
193 del_timer(&llc->rej_sent_timer.timer);
197 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
200 struct llc_sock *llc = llc_sk(sk);
201 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
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);
212 llc_conn_send_pdu(sk, nskb);
213 llc_conn_ac_set_p_flag_1(sk, skb);
222 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
225 struct llc_sock *llc = llc_sk(sk);
226 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
229 struct llc_sap *sap = llc->sap;
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);
239 llc_conn_send_pdu(sk, nskb);
248 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
251 struct llc_sock *llc = llc_sk(sk);
252 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
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);
263 llc_conn_send_pdu(sk, nskb);
272 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
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);
285 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
286 sizeof(struct llc_frmr_info));
288 struct llc_sap *sap = llc->sap;
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,
294 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
297 llc_conn_send_pdu(sk, nskb);
306 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
309 struct llc_sock *llc = llc_sk(sk);
310 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
311 sizeof(struct llc_frmr_info));
314 struct llc_sap *sap = llc->sap;
315 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
317 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
318 llc->daddr.lsap, LLC_PDU_RSP);
319 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
321 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
324 llc_conn_send_pdu(sk, nskb);
333 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
337 struct sk_buff *nskb;
338 struct llc_sock *llc = llc_sk(sk);
340 llc_pdu_decode_pf_bit(skb, &f_bit);
341 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
342 sizeof(struct llc_frmr_info));
344 struct llc_sap *sap = llc->sap;
345 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
347 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
348 llc->daddr.lsap, LLC_PDU_RSP);
349 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
351 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
354 llc_conn_send_pdu(sk, nskb);
363 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
366 struct llc_sock *llc = llc_sk(sk);
367 struct llc_sap *sap = llc->sap;
369 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
370 llc->daddr.lsap, LLC_PDU_CMD);
371 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
372 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
374 llc_conn_send_pdu(sk, skb);
375 llc_conn_ac_inc_vs_by_1(sk, skb);
380 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
383 struct llc_sock *llc = llc_sk(sk);
384 struct llc_sap *sap = llc->sap;
386 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
387 llc->daddr.lsap, LLC_PDU_CMD);
388 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
389 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
391 llc_conn_send_pdu(sk, skb);
392 llc_conn_ac_inc_vs_by_1(sk, skb);
397 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
400 struct llc_sock *llc = llc_sk(sk);
401 struct llc_sap *sap = llc->sap;
403 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
404 llc->daddr.lsap, LLC_PDU_CMD);
405 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
406 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
408 llc_conn_send_pdu(sk, skb);
409 llc_conn_ac_inc_vs_by_1(sk, skb);
414 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
416 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
417 u8 nr = LLC_I_GET_NR(pdu);
419 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
423 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
427 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
429 struct llc_sock *llc = llc_sk(sk);
430 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
433 struct llc_sap *sap = llc->sap;
435 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
436 llc->daddr.lsap, LLC_PDU_RSP);
437 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
438 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
440 llc_conn_send_pdu(sk, nskb);
445 nr = LLC_I_GET_NR(pdu);
447 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
452 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
454 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
455 u8 nr = LLC_I_GET_NR(pdu);
457 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
461 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
464 struct llc_sock *llc = llc_sk(sk);
465 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
468 struct llc_sap *sap = llc->sap;
470 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
471 llc->daddr.lsap, LLC_PDU_CMD);
472 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
473 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
476 llc_conn_send_pdu(sk, nskb);
485 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
488 struct llc_sock *llc = llc_sk(sk);
489 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
492 struct llc_sap *sap = llc->sap;
494 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
495 llc->daddr.lsap, LLC_PDU_RSP);
496 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
497 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
500 llc_conn_send_pdu(sk, nskb);
509 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
512 struct llc_sock *llc = llc_sk(sk);
513 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
516 struct llc_sap *sap = llc->sap;
518 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
519 llc->daddr.lsap, LLC_PDU_RSP);
520 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
521 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
524 llc_conn_send_pdu(sk, nskb);
533 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
536 struct llc_sock *llc = llc_sk(sk);
537 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
540 struct llc_sap *sap = llc->sap;
542 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
543 llc->daddr.lsap, LLC_PDU_CMD);
544 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
545 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
548 llc_conn_send_pdu(sk, nskb);
557 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
560 struct llc_sock *llc = llc_sk(sk);
561 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
564 struct llc_sap *sap = llc->sap;
566 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
567 llc->daddr.lsap, LLC_PDU_RSP);
568 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
569 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
572 llc_conn_send_pdu(sk, nskb);
581 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
584 struct llc_sock *llc = llc_sk(sk);
585 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
588 struct llc_sap *sap = llc->sap;
590 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
591 llc->daddr.lsap, LLC_PDU_RSP);
592 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
593 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
596 llc_conn_send_pdu(sk, nskb);
605 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
607 struct llc_sock *llc = llc_sk(sk);
609 if (!llc->remote_busy_flag) {
610 llc->remote_busy_flag = 1;
611 mod_timer(&llc->busy_state_timer.timer,
612 jiffies + llc->busy_state_timer.expire);
617 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
620 struct llc_sock *llc = llc_sk(sk);
621 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
624 struct llc_sap *sap = llc->sap;
626 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
627 llc->daddr.lsap, LLC_PDU_RSP);
628 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
629 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
632 llc_conn_send_pdu(sk, nskb);
641 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
644 struct llc_sock *llc = llc_sk(sk);
645 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
648 struct llc_sap *sap = llc->sap;
650 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
651 llc->daddr.lsap, LLC_PDU_CMD);
652 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
653 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
656 llc_conn_send_pdu(sk, nskb);
665 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
668 struct llc_sock *llc = llc_sk(sk);
669 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
672 struct llc_sap *sap = llc->sap;
675 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
676 llc->daddr.lsap, LLC_PDU_RSP);
677 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
678 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
681 llc_conn_send_pdu(sk, nskb);
690 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
693 struct llc_sock *llc = llc_sk(sk);
694 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
697 struct llc_sap *sap = llc->sap;
699 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
700 llc->daddr.lsap, LLC_PDU_RSP);
701 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
702 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
705 llc_conn_send_pdu(sk, nskb);
714 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
717 struct llc_sock *llc = llc_sk(sk);
718 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
721 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, 0, 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_ack_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(sk, llc->dev, LLC_PDU_TYPE_S, 0);
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 void llc_conn_set_p_flag(struct sock *sk, u8 value)
764 int state_changed = llc_sk(sk)->p_flag && !value;
766 llc_sk(sk)->p_flag = value;
769 sk->sk_state_change(sk);
772 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
775 struct llc_sock *llc = llc_sk(sk);
776 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
779 struct llc_sap *sap = llc->sap;
780 u8 *dmac = llc->daddr.mac;
782 if (llc->dev->flags & IFF_LOOPBACK)
783 dmac = llc->dev->dev_addr;
784 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
785 llc->daddr.lsap, LLC_PDU_CMD);
786 llc_pdu_init_as_sabme_cmd(nskb, 1);
787 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
790 llc_conn_send_pdu(sk, nskb);
791 llc_conn_set_p_flag(sk, 1);
800 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
804 struct llc_sock *llc = llc_sk(sk);
805 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
807 llc_pdu_decode_pf_bit(skb, &f_bit);
809 struct llc_sap *sap = llc->sap;
811 nskb->dev = llc->dev;
812 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
813 llc->daddr.lsap, LLC_PDU_RSP);
814 llc_pdu_init_as_ua_rsp(nskb, f_bit);
815 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
818 llc_conn_send_pdu(sk, nskb);
827 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
829 llc_sk(sk)->s_flag = 0;
833 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
835 llc_sk(sk)->s_flag = 1;
839 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
841 struct llc_sock *llc = llc_sk(sk);
843 llc_conn_set_p_flag(sk, 1);
844 mod_timer(&llc->pf_cycle_timer.timer,
845 jiffies + llc->pf_cycle_timer.expire);
850 * llc_conn_ac_send_ack_if_needed - check if ack is needed
851 * @sk: current connection structure
852 * @skb: current event
854 * Checks number of received PDUs which have not been acknowledged, yet,
855 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
856 * sends an RR response as acknowledgement for them. Returns 0 for
857 * success, 1 otherwise.
859 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
862 struct llc_sock *llc = llc_sk(sk);
864 llc_pdu_decode_pf_bit(skb, &pf_bit);
865 llc->ack_pf |= pf_bit & 1;
866 if (!llc->ack_must_be_send) {
867 llc->first_pdu_Ns = llc->vR;
868 llc->ack_must_be_send = 1;
869 llc->ack_pf = pf_bit & 1;
871 if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
872 % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
873 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
874 llc->ack_must_be_send = 0;
876 llc_conn_ac_inc_npta_value(sk, skb);
882 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
883 * @sk: current connection structure
884 * @skb: current event
886 * This action resets ack_must_be_send flag of given connection, this flag
887 * indicates if there is any PDU which has not been acknowledged yet.
888 * Returns 0 for success, 1 otherwise.
890 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
892 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
897 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
898 * @sk: current connection structure
899 * @skb: current event
901 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
902 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
903 * set to one if one PDU with p-bit set to one is received. Returns 0 for
904 * success, 1 otherwise.
906 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
910 struct llc_sock *llc = llc_sk(sk);
911 struct llc_sap *sap = llc->sap;
913 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
914 llc->daddr.lsap, LLC_PDU_RSP);
915 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
916 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
918 llc_conn_send_pdu(sk, skb);
919 llc_conn_ac_inc_vs_by_1(sk, skb);
925 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
926 * @sk: current connection structure.
927 * @skb: current event.
929 * This action sends an I-format PDU as acknowledge to received PDUs which
930 * have not been acknowledged, yet, if there is any. By using of this
931 * action number of acknowledgements decreases, this technic is called
932 * piggy backing. Returns 0 for success, 1 otherwise.
934 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
936 struct llc_sock *llc = llc_sk(sk);
938 if (llc->ack_must_be_send) {
939 llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
940 llc->ack_must_be_send = 0 ;
943 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
948 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
949 * @sk: current connection structure.
950 * @skb: current event.
952 * This action sends an RR response with f-bit set to ack_pf flag as
953 * acknowledge to all received PDUs which have not been acknowledged, yet,
954 * if there is any. ack_pf flag indicates if a PDU has been received with
955 * p-bit set to one. Returns 0 for success, 1 otherwise.
957 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
961 struct llc_sock *llc = llc_sk(sk);
962 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
965 struct llc_sap *sap = llc->sap;
967 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
968 llc->daddr.lsap, LLC_PDU_RSP);
969 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
970 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
973 llc_conn_send_pdu(sk, nskb);
983 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
984 * @sk: current connection structure.
985 * @skb: current event.
987 * After "inc_cntr" times calling of this action, "npta" increase by one.
988 * this action tries to make vale of "npta" greater as possible; number of
989 * acknowledgements decreases by increasing of "npta". Returns 0 for
990 * success, 1 otherwise.
992 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
994 struct llc_sock *llc = llc_sk(sk);
996 if (!llc->inc_cntr) {
998 llc->dec_cntr = llc->inc_cntr = 2;
1000 if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
1001 llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
1008 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1009 * @sk: current connection structure.
1010 * @skb: current event.
1012 * After receiving "dec_cntr" times RR command, this action decreases
1013 * "npta" by one. Returns 0 for success, 1 otherwise.
1015 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1017 struct llc_sock *llc = llc_sk(sk);
1019 if (!llc->connect_step && !llc->remote_busy_flag) {
1020 if (!llc->dec_step) {
1021 if (!llc->dec_cntr) {
1022 llc->inc_cntr = llc->dec_cntr = 2;
1024 llc->npta = llc->npta - 1;
1029 llc->connect_step = 0 ;
1034 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1035 * @sk: current connection structure.
1036 * @skb: current event.
1038 * After receiving "dec_cntr" times RNR command, this action decreases
1039 * "npta" by one. Returns 0 for success, 1 otherwise.
1041 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1043 struct llc_sock *llc = llc_sk(sk);
1045 if (llc->remote_busy_flag)
1046 if (!llc->dec_step) {
1047 if (!llc->dec_cntr) {
1048 llc->inc_cntr = llc->dec_cntr = 2;
1058 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1059 * @sk: current connection structure.
1060 * @skb: current event.
1062 * After receiving of a REJ command or response, transmit window size is
1063 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1064 * success, 1 otherwise.
1066 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1068 struct llc_sock *llc = llc_sk(sk);
1069 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1071 if (llc->k - unacked_pdu < 1)
1074 llc->k -= unacked_pdu;
1079 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1080 * @sk: current connection structure.
1081 * @skb: current event.
1083 * After receiving an RR response with f-bit set to one, transmit window
1084 * size is increased by one. Returns 0 for success, 1 otherwise.
1086 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1088 struct llc_sock *llc = llc_sk(sk);
1091 if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1092 llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
1096 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1098 struct llc_sock *llc = llc_sk(sk);
1100 del_timer(&llc->pf_cycle_timer.timer);
1101 del_timer(&llc->ack_timer.timer);
1102 del_timer(&llc->rej_sent_timer.timer);
1103 del_timer(&llc->busy_state_timer.timer);
1104 llc->ack_must_be_send = 0;
1109 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1111 struct llc_sock *llc = llc_sk(sk);
1113 del_timer(&llc->rej_sent_timer.timer);
1114 del_timer(&llc->pf_cycle_timer.timer);
1115 del_timer(&llc->busy_state_timer.timer);
1116 llc->ack_must_be_send = 0;
1121 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1123 struct llc_sock *llc = llc_sk(sk);
1125 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1129 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1131 struct llc_sock *llc = llc_sk(sk);
1133 mod_timer(&llc->rej_sent_timer.timer,
1134 jiffies + llc->rej_sent_timer.expire);
1138 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1139 struct sk_buff *skb)
1141 struct llc_sock *llc = llc_sk(sk);
1143 if (!timer_pending(&llc->ack_timer.timer))
1144 mod_timer(&llc->ack_timer.timer,
1145 jiffies + llc->ack_timer.expire);
1149 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1151 del_timer(&llc_sk(sk)->ack_timer.timer);
1155 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1157 struct llc_sock *llc = llc_sk(sk);
1159 del_timer(&llc->pf_cycle_timer.timer);
1160 llc_conn_set_p_flag(sk, 0);
1164 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1166 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1170 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1174 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1175 struct llc_sock *llc = llc_sk(sk);
1177 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1178 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1179 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1180 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1181 llc->retry_count = 0;
1182 del_timer(&llc->ack_timer.timer);
1183 if (llc->failed_data_req) {
1184 /* already, we did not accept data from upper layer
1185 * (tx_window full or unacceptable state). Now, we
1186 * can send data and must inform to upper layer.
1188 llc->failed_data_req = 0;
1189 llc_conn_ac_data_confirm(sk, skb);
1192 mod_timer(&llc->ack_timer.timer,
1193 jiffies + llc->ack_timer.expire);
1194 } else if (llc->failed_data_req) {
1197 llc_pdu_decode_pf_bit(skb, &f_bit);
1199 llc->failed_data_req = 0;
1200 llc_conn_ac_data_confirm(sk, skb);
1206 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1208 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1210 if (LLC_PDU_IS_RSP(pdu)) {
1213 llc_pdu_decode_pf_bit(skb, &f_bit);
1215 llc_conn_set_p_flag(sk, 0);
1216 llc_conn_ac_stop_p_timer(sk, skb);
1222 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1224 llc_sk(sk)->data_flag = 2;
1228 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1230 llc_sk(sk)->data_flag = 0;
1234 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1236 llc_sk(sk)->data_flag = 1;
1240 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1241 struct sk_buff *skb)
1243 if (!llc_sk(sk)->data_flag)
1244 llc_sk(sk)->data_flag = 1;
1248 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1250 llc_conn_set_p_flag(sk, 0);
1254 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1256 llc_conn_set_p_flag(sk, 1);
1260 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1262 llc_sk(sk)->remote_busy_flag = 0;
1266 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1268 llc_sk(sk)->cause_flag = 0;
1272 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1274 llc_sk(sk)->cause_flag = 1;
1278 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1280 llc_sk(sk)->retry_count = 0;
1284 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1286 llc_sk(sk)->retry_count++;
1290 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1296 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1298 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1302 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1308 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1310 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1314 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1316 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
1320 static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
1322 struct sock *sk = (struct sock *)timeout_data;
1323 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1327 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1329 skb_set_owner_r(skb, sk);
1331 llc_process_tmr_ev(sk, skb);
1336 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1338 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
1341 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1343 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
1346 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1348 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
1351 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1353 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
1356 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1358 llc_sk(sk)->X = llc_sk(sk)->vS;
1359 llc_conn_ac_set_vs_nr(sk, skb);
1363 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1365 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1366 u8 nr = PDU_SUPV_GET_Nr(pdu);
1368 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1369 llc_conn_ac_set_vs_nr(sk, skb);
1374 * Non-standard actions; these not contained in IEEE specification; for
1378 * llc_conn_disc - removes connection from SAP list and frees it
1379 * @sk: closed connection
1380 * @skb: occurred event
1382 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1384 /* FIXME: this thing seems to want to die */
1389 * llc_conn_reset - resets connection
1390 * @sk : reseting connection.
1391 * @skb: occurred event.
1393 * Stop all timers, empty all queues and reset all flags.
1395 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1402 * llc_circular_between - designates that b is between a and c or not
1404 * @b: element to see if is between a and b
1407 * This function designates that b is between a and c or not (for example,
1408 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1411 u8 llc_circular_between(u8 a, u8 b, u8 c)
1419 * llc_process_tmr_ev - timer backend
1420 * @sk: active connection
1421 * @skb: occurred event
1423 * This function is called from timer callback functions. When connection
1424 * is busy (during sending a data frame) timer expiration event must be
1425 * queued. Otherwise this event can be sent to connection state machine.
1426 * Queued events will process by llc_backlog_rcv function after sending
1429 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1431 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1432 printk(KERN_WARNING "%s: timer called on closed connection\n",
1436 if (!sock_owned_by_user(sk))
1437 llc_conn_state_process(sk, skb);
1439 llc_set_backlog_type(skb, LLC_EVENT);
1440 sk_add_backlog(sk, skb);