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);
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);
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);
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);
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,
293 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
296 llc_conn_send_pdu(sk, nskb);
305 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
308 struct llc_sock *llc = llc_sk(sk);
309 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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,
319 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
322 llc_conn_send_pdu(sk, nskb);
331 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
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);
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,
348 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
351 llc_conn_send_pdu(sk, nskb);
360 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
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);
371 llc_conn_send_pdu(sk, skb);
372 llc_conn_ac_inc_vs_by_1(sk, skb);
377 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
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);
388 llc_conn_send_pdu(sk, skb);
389 llc_conn_ac_inc_vs_by_1(sk, skb);
394 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
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);
405 llc_conn_send_pdu(sk, skb);
406 llc_conn_ac_inc_vs_by_1(sk, skb);
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);
420 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
424 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
426 struct llc_sock *llc = llc_sk(sk);
427 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
437 llc_conn_send_pdu(sk, nskb);
442 nr = LLC_I_GET_NR(pdu);
444 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
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);
458 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
461 struct llc_sock *llc = llc_sk(sk);
462 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
473 llc_conn_send_pdu(sk, nskb);
482 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
485 struct llc_sock *llc = llc_sk(sk);
486 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
497 llc_conn_send_pdu(sk, nskb);
506 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
509 struct llc_sock *llc = llc_sk(sk);
510 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
521 llc_conn_send_pdu(sk, nskb);
530 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
533 struct llc_sock *llc = llc_sk(sk);
534 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
545 llc_conn_send_pdu(sk, nskb);
554 int llc_conn_ac_send_rnr_rsp_f_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(sk, 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_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);
569 llc_conn_send_pdu(sk, nskb);
578 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
581 struct llc_sock *llc = llc_sk(sk);
582 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
593 llc_conn_send_pdu(sk, nskb);
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);
614 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
617 struct llc_sock *llc = llc_sk(sk);
618 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
629 llc_conn_send_pdu(sk, nskb);
638 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
641 struct llc_sock *llc = llc_sk(sk);
642 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
653 llc_conn_send_pdu(sk, nskb);
662 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
665 struct llc_sock *llc = llc_sk(sk);
666 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
669 struct llc_sap *sap = llc->sap;
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);
678 llc_conn_send_pdu(sk, nskb);
687 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
690 struct llc_sock *llc = llc_sk(sk);
691 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
702 llc_conn_send_pdu(sk, nskb);
711 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
714 struct llc_sock *llc = llc_sk(sk);
715 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
726 llc_conn_send_pdu(sk, nskb);
735 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
738 struct llc_sock *llc = llc_sk(sk);
739 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
750 llc_conn_send_pdu(sk, nskb);
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;
766 sk->sk_state_change(sk);
769 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
772 struct llc_sock *llc = llc_sk(sk);
773 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
787 llc_conn_send_pdu(sk, nskb);
788 llc_conn_set_p_flag(sk, 1);
797 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
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);
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);
815 llc_conn_send_pdu(sk, nskb);
824 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
826 llc_sk(sk)->s_flag = 0;
830 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
832 llc_sk(sk)->s_flag = 1;
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);
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)
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;
873 llc_conn_ac_inc_npta_value(sk, skb);
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;
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,
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);
915 llc_conn_send_pdu(sk, skb);
916 llc_conn_ac_inc_vs_by_1(sk, skb);
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 ;
940 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
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,
958 struct llc_sock *llc = llc_sk(sk);
959 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
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);
970 llc_conn_send_pdu(sk, nskb);
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) {
995 llc->dec_cntr = llc->inc_cntr = 2;
997 if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
998 llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
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;
1021 llc->npta = llc->npta - 1;
1026 llc->connect_step = 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;
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)
1071 llc->k -= unacked_pdu;
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);
1088 if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1089 llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
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;
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;
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);
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);
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);
1146 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1148 del_timer(&llc_sk(sk)->ack_timer.timer);
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);
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);
1167 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
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);
1189 mod_timer(&llc->ack_timer.timer,
1190 jiffies + llc->ack_timer.expire);
1191 } else if (llc->failed_data_req) {
1194 llc_pdu_decode_pf_bit(skb, &f_bit);
1196 llc->failed_data_req = 0;
1197 llc_conn_ac_data_confirm(sk, skb);
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)) {
1210 llc_pdu_decode_pf_bit(skb, &f_bit);
1212 llc_conn_set_p_flag(sk, 0);
1213 llc_conn_ac_stop_p_timer(sk, skb);
1219 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1221 llc_sk(sk)->data_flag = 2;
1225 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1227 llc_sk(sk)->data_flag = 0;
1231 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1233 llc_sk(sk)->data_flag = 1;
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;
1245 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1247 llc_conn_set_p_flag(sk, 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);
1257 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1259 llc_sk(sk)->remote_busy_flag = 0;
1263 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1265 llc_sk(sk)->cause_flag = 0;
1269 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1271 llc_sk(sk)->cause_flag = 1;
1275 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1277 llc_sk(sk)->retry_count = 0;
1281 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1283 llc_sk(sk)->retry_count++;
1287 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
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);
1299 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
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;
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;
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);
1324 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1326 skb_set_owner_r(skb, sk);
1328 llc_process_tmr_ev(sk, skb);
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);
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);
1371 * Non-standard actions; these not contained in IEEE specification; for
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 */
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)
1399 * llc_circular_between - designates that b is between a and c or not
1401 * @b: element to see if is between a and b
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
1408 u8 llc_circular_between(u8 a, u8 b, u8 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
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",
1433 if (!sock_owned_by_user(sk))
1434 llc_conn_state_process(sk, skb);
1436 llc_set_backlog_type(skb, LLC_EVENT);
1437 sk_add_backlog(sk, skb);