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);
38 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
40 struct llc_opt *llc = llc_sk(sk);
42 if (llc->remote_busy_flag) {
44 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
46 llc->remote_busy_flag = 0;
47 del_timer(&llc->busy_state_timer.timer);
48 nr = LLC_I_GET_NR(pdu);
49 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
54 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
60 llc_pdu_decode_dsap(skb, &dsap);
61 sap = llc_sap_find(dsap);
63 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
64 struct llc_opt *llc = llc_sk(sk);
66 llc_pdu_decode_sa(skb, llc->daddr.mac);
67 llc_pdu_decode_da(skb, llc->laddr.mac);
69 ev->ind_prim = LLC_CONN_PRIM;
75 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
77 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
79 ev->cfm_prim = LLC_CONN_PRIM;
83 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
85 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
87 ev->cfm_prim = LLC_DATA_PRIM;
91 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
93 llc_conn_rtn_pdu(sk, skb);
97 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
99 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
103 if (ev->type == LLC_CONN_EV_TYPE_PDU) {
104 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
106 if (LLC_PDU_IS_RSP(pdu) &&
107 LLC_PDU_TYPE_IS_U(pdu) &&
108 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
109 reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
110 else if (LLC_PDU_IS_CMD(pdu) &&
111 LLC_PDU_TYPE_IS_U(pdu) &&
112 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
113 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
114 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
115 reason = LLC_DISC_REASON_ACK_TMR_EXP;
122 ev->ind_prim = LLC_DISC_PRIM;
127 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
129 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
131 ev->reason = ev->status;
132 ev->cfm_prim = LLC_DISC_PRIM;
136 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
140 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
141 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
142 struct llc_opt *llc = llc_sk(sk);
145 case LLC_CONN_EV_TYPE_PDU:
146 if (LLC_PDU_IS_RSP(pdu) &&
147 LLC_PDU_TYPE_IS_U(pdu) &&
148 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
149 reason = LLC_RESET_REASON_LOCAL;
151 } else if (LLC_PDU_IS_CMD(pdu) &&
152 LLC_PDU_TYPE_IS_U(pdu) &&
153 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
154 reason = LLC_RESET_REASON_REMOTE;
161 case LLC_CONN_EV_TYPE_ACK_TMR:
162 case LLC_CONN_EV_TYPE_P_TMR:
163 case LLC_CONN_EV_TYPE_REJ_TMR:
164 case LLC_CONN_EV_TYPE_BUSY_TMR:
165 if (llc->retry_count > llc->n2) {
166 reason = LLC_RESET_REASON_LOCAL;
174 ev->ind_prim = LLC_RESET_PRIM;
179 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
181 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
184 ev->cfm_prim = LLC_RESET_PRIM;
188 int llc_conn_ac_report_status(struct sock *sk, struct sk_buff *skb)
193 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
196 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
198 if (LLC_PDU_IS_RSP(pdu) &&
199 LLC_PDU_TYPE_IS_I(pdu) &&
200 LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
201 llc_conn_ac_clear_remote_busy(sk, skb);
205 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
208 struct llc_opt *llc = llc_sk(sk);
210 if (llc->data_flag == 2)
211 del_timer(&llc->rej_sent_timer.timer);
215 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
218 struct sk_buff *nskb = llc_alloc_frame();
221 struct llc_opt *llc = llc_sk(sk);
222 struct llc_sap *sap = llc->sap;
224 nskb->dev = llc->dev;
225 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
226 llc->daddr.lsap, LLC_PDU_CMD);
227 llc_pdu_init_as_disc_cmd(nskb, 1);
228 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
231 llc_conn_send_pdu(sk, nskb);
232 llc_conn_ac_set_p_flag_1(sk, skb);
241 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
244 struct sk_buff *nskb = llc_alloc_frame();
247 struct llc_opt *llc = llc_sk(sk);
248 struct llc_sap *sap = llc->sap;
251 nskb->dev = llc->dev;
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 sk_buff *nskb = llc_alloc_frame();
274 struct llc_opt *llc = llc_sk(sk);
275 struct llc_sap *sap = llc->sap;
278 nskb->dev = llc->dev;
279 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
280 llc->daddr.lsap, LLC_PDU_RSP);
281 llc_pdu_init_as_dm_rsp(nskb, f_bit);
282 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
285 llc_conn_send_pdu(sk, nskb);
294 int llc_conn_ac_send_dm_rsp_f_set_f_flag(struct sock *sk, struct sk_buff *skb)
297 struct sk_buff *nskb = llc_alloc_frame();
300 struct llc_opt *llc = llc_sk(sk);
301 struct llc_sap *sap = llc->sap;
302 u8 f_bit = llc->f_flag;
304 nskb->dev = llc->dev;
305 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
306 llc->daddr.lsap, LLC_PDU_RSP);
307 llc_pdu_init_as_dm_rsp(nskb, f_bit);
308 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
311 llc_conn_send_pdu(sk, nskb);
320 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
324 struct sk_buff *nskb;
325 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
326 struct llc_opt *llc = llc_sk(sk);
328 llc->rx_pdu_hdr = *((u32 *)pdu);
329 if (LLC_PDU_IS_CMD(pdu))
330 llc_pdu_decode_pf_bit(skb, &f_bit);
333 nskb = llc_alloc_frame();
335 struct llc_sap *sap = llc->sap;
337 nskb->dev = llc->dev;
338 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
339 llc->daddr.lsap, LLC_PDU_RSP);
340 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
342 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
345 llc_conn_send_pdu(sk, nskb);
354 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
357 struct sk_buff *nskb = llc_alloc_frame();
361 struct llc_opt *llc = llc_sk(sk);
362 struct llc_sap *sap = llc->sap;
363 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
365 nskb->dev = llc->dev;
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_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
386 struct sk_buff *nskb;
388 llc_pdu_decode_pf_bit(skb, &f_bit);
389 nskb = llc_alloc_frame();
391 struct llc_opt *llc = llc_sk(sk);
392 struct llc_sap *sap = llc->sap;
393 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
395 nskb->dev = llc->dev;
396 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
397 llc->daddr.lsap, LLC_PDU_RSP);
398 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
400 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
403 llc_conn_send_pdu(sk, nskb);
412 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
415 struct llc_opt *llc = llc_sk(sk);
416 struct llc_sap *sap = llc->sap;
418 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
419 llc->daddr.lsap, LLC_PDU_CMD);
420 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
421 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
423 llc_conn_send_pdu(sk, skb);
424 llc_conn_ac_inc_vs_by_1(sk, skb);
429 int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
432 struct llc_opt *llc = llc_sk(sk);
433 struct llc_sap *sap = llc->sap;
435 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
436 llc->daddr.lsap, LLC_PDU_CMD);
437 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
438 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
440 llc_conn_send_pdu(sk, skb);
441 llc_conn_ac_inc_vs_by_1(sk, skb);
446 int llc_conn_ac_resend_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
448 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
449 u8 nr = LLC_I_GET_NR(pdu);
451 llc_conn_resend_i_pdu_as_cmd(sk, nr, 1);
455 int llc_conn_ac_resend_i_cmd_p_set_1_or_send_rr(struct sock *sk,
458 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
459 u8 nr = LLC_I_GET_NR(pdu);
460 int rc = llc_conn_ac_send_rr_cmd_p_set_1(sk, skb);
463 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
467 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
470 struct llc_opt *llc = llc_sk(sk);
471 struct llc_sap *sap = llc->sap;
473 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
474 llc->daddr.lsap, LLC_PDU_CMD);
475 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
476 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
478 llc_conn_send_pdu(sk, skb);
479 llc_conn_ac_inc_vs_by_1(sk, skb);
484 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
486 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
487 u8 nr = LLC_I_GET_NR(pdu);
489 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
493 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
497 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
499 struct sk_buff *nskb = llc_alloc_frame();
502 struct llc_opt *llc = llc_sk(sk);
503 struct llc_sap *sap = llc->sap;
505 nskb->dev = llc->dev;
506 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
507 llc->daddr.lsap, LLC_PDU_RSP);
508 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
509 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
511 llc_conn_send_pdu(sk, nskb);
516 nr = LLC_I_GET_NR(pdu);
518 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
523 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
525 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
526 u8 nr = LLC_I_GET_NR(pdu);
528 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
532 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
535 struct sk_buff *nskb = llc_alloc_frame();
538 struct llc_opt *llc = llc_sk(sk);
539 struct llc_sap *sap = llc->sap;
541 nskb->dev = llc->dev;
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_rej_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_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
560 struct sk_buff *nskb = llc_alloc_frame();
564 struct llc_opt *llc = llc_sk(sk);
565 struct llc_sap *sap = llc->sap;
567 nskb->dev = llc->dev;
568 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
569 llc->daddr.lsap, LLC_PDU_RSP);
570 llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR);
571 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
574 llc_conn_send_pdu(sk, nskb);
583 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
586 struct sk_buff *nskb = llc_alloc_frame();
589 struct llc_opt *llc = llc_sk(sk);
590 struct llc_sap *sap = llc->sap;
593 nskb->dev = llc->dev;
594 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
595 llc->daddr.lsap, LLC_PDU_RSP);
596 llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR);
597 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
600 llc_conn_send_pdu(sk, nskb);
609 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
612 struct sk_buff *nskb = llc_alloc_frame();
615 struct llc_opt *llc = llc_sk(sk);
616 struct llc_sap *sap = llc->sap;
618 nskb->dev = llc->dev;
619 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
620 llc->daddr.lsap, LLC_PDU_CMD);
621 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
622 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
625 llc_conn_send_pdu(sk, nskb);
634 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
637 struct sk_buff *nskb = llc_alloc_frame();
640 struct llc_opt *llc = llc_sk(sk);
641 struct llc_sap *sap = llc->sap;
644 nskb->dev = llc->dev;
645 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
646 llc->daddr.lsap, LLC_PDU_RSP);
647 llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR);
648 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
651 llc_conn_send_pdu(sk, nskb);
660 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
663 struct sk_buff *nskb = llc_alloc_frame();
667 struct llc_opt *llc = llc_sk(sk);
668 struct llc_sap *sap = llc->sap;
670 nskb->dev = llc->dev;
671 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
672 llc->daddr.lsap, LLC_PDU_RSP);
673 llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR);
674 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
677 llc_conn_send_pdu(sk, nskb);
686 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
688 struct llc_opt *llc = llc_sk(sk);
690 if (!llc->remote_busy_flag) {
691 llc->remote_busy_flag = 1;
692 mod_timer(&llc->busy_state_timer.timer,
693 jiffies + llc->busy_state_timer.expire * HZ);
698 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
701 struct sk_buff *nskb = llc_alloc_frame();
704 struct llc_opt *llc = llc_sk(sk);
705 struct llc_sap *sap = llc->sap;
707 nskb->dev = llc->dev;
708 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
709 llc->daddr.lsap, LLC_PDU_RSP);
710 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
711 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
714 llc_conn_send_pdu(sk, nskb);
723 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
726 struct sk_buff *nskb = llc_alloc_frame();
729 struct llc_opt *llc = llc_sk(sk);
730 struct llc_sap *sap = llc->sap;
732 nskb->dev = llc->dev;
733 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
734 llc->daddr.lsap, LLC_PDU_CMD);
735 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
736 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
739 llc_conn_send_pdu(sk, nskb);
748 int llc_conn_ac_send_ack_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
751 struct sk_buff *nskb = llc_alloc_frame();
754 struct llc_opt *llc = llc_sk(sk);
755 struct llc_sap *sap = llc->sap;
757 nskb->dev = llc->dev;
758 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
759 llc->daddr.lsap, LLC_PDU_CMD);
760 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
761 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
764 llc_conn_send_pdu(sk, nskb);
773 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
776 struct sk_buff *nskb = llc_alloc_frame();
779 struct llc_opt *llc = llc_sk(sk);
780 struct llc_sap *sap = llc->sap;
783 nskb->dev = llc->dev;
784 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
785 llc->daddr.lsap, LLC_PDU_RSP);
786 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
787 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
790 llc_conn_send_pdu(sk, nskb);
799 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
802 struct sk_buff *nskb = llc_alloc_frame();
805 struct llc_opt *llc = llc_sk(sk);
806 struct llc_sap *sap = llc->sap;
809 nskb->dev = llc->dev;
810 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
811 llc->daddr.lsap, LLC_PDU_RSP);
812 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
813 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
816 llc_conn_send_pdu(sk, nskb);
825 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
828 struct sk_buff *nskb = llc_alloc_frame();
831 struct llc_opt *llc = llc_sk(sk);
832 struct llc_sap *sap = llc->sap;
834 nskb->dev = llc->dev;
835 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
836 llc->daddr.lsap, LLC_PDU_RSP);
837 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
838 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
841 llc_conn_send_pdu(sk, nskb);
850 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
853 struct sk_buff *nskb = llc_alloc_frame();
856 struct llc_opt *llc = llc_sk(sk);
857 struct llc_sap *sap = llc->sap;
859 nskb->dev = llc->dev;
860 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
861 llc->daddr.lsap, LLC_PDU_RSP);
862 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
863 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
866 llc_conn_send_pdu(sk, nskb);
875 void llc_conn_set_p_flag(struct sock *sk, u8 value)
877 int state_changed = llc_sk(sk)->p_flag && !value;
879 llc_sk(sk)->p_flag = value;
882 sk->sk_state_change(sk);
885 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
888 struct sk_buff *nskb = llc_alloc_frame();
889 struct llc_opt *llc = llc_sk(sk);
892 struct llc_sap *sap = llc->sap;
893 u8 *dmac = llc->daddr.mac;
895 if (llc->dev->flags & IFF_LOOPBACK)
896 dmac = llc->dev->dev_addr;
897 nskb->dev = llc->dev;
898 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
899 llc->daddr.lsap, LLC_PDU_CMD);
900 llc_pdu_init_as_sabme_cmd(nskb, 1);
901 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
904 llc_conn_send_pdu(sk, nskb);
905 llc_conn_set_p_flag(sk, 1);
914 int llc_conn_ac_send_ua_rsp_f_set_f_flag(struct sock *sk, struct sk_buff *skb)
917 struct sk_buff *nskb = llc_alloc_frame();
920 struct llc_opt *llc = llc_sk(sk);
921 struct llc_sap *sap = llc->sap;
923 nskb->dev = llc->dev;
924 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
925 llc->daddr.lsap, LLC_PDU_RSP);
926 llc_pdu_init_as_ua_rsp(nskb, llc->f_flag);
927 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
930 llc_conn_send_pdu(sk, nskb);
939 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
943 struct sk_buff *nskb = llc_alloc_frame();
945 llc_pdu_decode_pf_bit(skb, &f_bit);
947 struct llc_opt *llc = llc_sk(sk);
948 struct llc_sap *sap = llc->sap;
950 nskb->dev = llc->dev;
951 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
952 llc->daddr.lsap, LLC_PDU_RSP);
953 llc_pdu_init_as_ua_rsp(nskb, f_bit);
954 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
957 llc_conn_send_pdu(sk, nskb);
966 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
968 llc_sk(sk)->s_flag = 0;
972 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
974 llc_sk(sk)->s_flag = 1;
978 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
980 struct llc_opt *llc = llc_sk(sk);
982 llc_conn_set_p_flag(sk, 1);
983 mod_timer(&llc->pf_cycle_timer.timer,
984 jiffies + llc->pf_cycle_timer.expire * HZ);
989 * llc_conn_ac_send_ack_if_needed - check if ack is needed
990 * @sk: current connection structure
991 * @skb: current event
993 * Checks number of received PDUs which have not been acknowledged, yet,
994 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
995 * sends an RR response as acknowledgement for them. Returns 0 for
996 * success, 1 otherwise.
998 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
1001 struct llc_opt *llc = llc_sk(sk);
1003 llc_pdu_decode_pf_bit(skb, &pf_bit);
1004 llc->ack_pf |= pf_bit & 1;
1005 if (!llc->ack_must_be_send) {
1006 llc->first_pdu_Ns = llc->vR;
1007 llc->ack_must_be_send = 1;
1008 llc->ack_pf = pf_bit & 1;
1010 if (((llc->vR - llc->first_pdu_Ns + 129) % 128) >= llc->npta) {
1011 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
1012 llc->ack_must_be_send = 0;
1014 llc_conn_ac_inc_npta_value(sk, skb);
1020 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
1021 * @sk: current connection structure
1022 * @skb: current event
1024 * This action resets ack_must_be_send flag of given connection, this flag
1025 * indicates if there is any PDU which has not been acknowledged yet.
1026 * Returns 0 for success, 1 otherwise.
1028 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
1030 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
1035 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
1036 * @sk: current connection structure
1037 * @skb: current event
1039 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
1040 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
1041 * set to one if one PDU with p-bit set to one is received. Returns 0 for
1042 * success, 1 otherwise.
1044 int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk, struct sk_buff *skb)
1047 struct llc_opt *llc = llc_sk(sk);
1048 struct llc_sap *sap = llc->sap;
1050 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
1051 llc->daddr.lsap, LLC_PDU_RSP);
1052 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
1053 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
1055 llc_conn_send_pdu(sk, skb);
1056 llc_conn_ac_inc_vs_by_1(sk, skb);
1062 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
1063 * @sk: current connection structure.
1064 * @skb: current event.
1066 * This action sends an I-format PDU as acknowledge to received PDUs which
1067 * have not been acknowledged, yet, if there is any. By using of this
1068 * action number of acknowledgements decreases, this technic is called
1069 * piggy backing. Returns 0 for success, 1 otherwise.
1071 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
1073 struct llc_opt *llc = llc_sk(sk);
1075 if (llc->ack_must_be_send) {
1076 llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
1077 llc->ack_must_be_send = 0 ;
1080 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
1085 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
1086 * @sk: current connection structure.
1087 * @skb: current event.
1089 * This action sends an RR response with f-bit set to ack_pf flag as
1090 * acknowledge to all received PDUs which have not been acknowledged, yet,
1091 * if there is any. ack_pf flag indicates if a PDU has been received with
1092 * p-bit set to one. Returns 0 for success, 1 otherwise.
1094 int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, struct sk_buff *skb)
1097 struct sk_buff *nskb = llc_alloc_frame();
1100 struct llc_opt *llc = llc_sk(sk);
1101 struct llc_sap *sap = llc->sap;
1103 nskb->dev = llc->dev;
1104 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
1105 llc->daddr.lsap, LLC_PDU_RSP);
1106 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
1107 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
1110 llc_conn_send_pdu(sk, nskb);
1120 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
1121 * @sk: current connection structure.
1122 * @skb: current event.
1124 * After "inc_cntr" times calling of this action, "npta" increase by one.
1125 * this action tries to make vale of "npta" greater as possible; number of
1126 * acknowledgements decreases by increasing of "npta". Returns 0 for
1127 * success, 1 otherwise.
1129 int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
1131 struct llc_opt *llc = llc_sk(sk);
1133 if (!llc->inc_cntr) {
1135 llc->dec_cntr = llc->inc_cntr = 2;
1137 if (llc->npta > 127)
1145 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1146 * @sk: current connection structure.
1147 * @skb: current event.
1149 * After receiving "dec_cntr" times RR command, this action decreases
1150 * "npta" by one. Returns 0 for success, 1 otherwise.
1152 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1154 struct llc_opt *llc = llc_sk(sk);
1156 if (!llc->connect_step && !llc->remote_busy_flag) {
1157 if (!llc->dec_step) {
1158 if (!llc->dec_cntr) {
1159 llc->inc_cntr = llc->dec_cntr = 2;
1161 llc->npta = llc->npta - 1;
1166 llc->connect_step = 0 ;
1171 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1172 * @sk: current connection structure.
1173 * @skb: current event.
1175 * After receiving "dec_cntr" times RNR command, this action decreases
1176 * "npta" by one. Returns 0 for success, 1 otherwise.
1178 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1180 struct llc_opt *llc = llc_sk(sk);
1182 if (llc->remote_busy_flag)
1183 if (!llc->dec_step) {
1184 if (!llc->dec_cntr) {
1185 llc->inc_cntr = llc->dec_cntr = 2;
1195 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1196 * @sk: current connection structure.
1197 * @skb: current event.
1199 * After receiving of a REJ command or response, transmit window size is
1200 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1201 * success, 1 otherwise.
1203 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1205 struct llc_opt *llc = llc_sk(sk);
1206 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1208 llc->k -= unacked_pdu;
1215 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1216 * @sk: current connection structure.
1217 * @skb: current event.
1219 * After receiving an RR response with f-bit set to one, transmit window
1220 * size is increased by one. Returns 0 for success, 1 otherwise.
1222 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1224 struct llc_opt *llc = llc_sk(sk);
1232 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1234 struct llc_opt *llc = llc_sk(sk);
1236 del_timer(&llc->pf_cycle_timer.timer);
1237 del_timer(&llc->ack_timer.timer);
1238 del_timer(&llc->rej_sent_timer.timer);
1239 del_timer(&llc->busy_state_timer.timer);
1240 llc->ack_must_be_send = 0;
1245 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1247 struct llc_opt *llc = llc_sk(sk);
1249 del_timer(&llc->rej_sent_timer.timer);
1250 del_timer(&llc->pf_cycle_timer.timer);
1251 del_timer(&llc->busy_state_timer.timer);
1252 llc->ack_must_be_send = 0;
1257 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1259 struct llc_opt *llc = llc_sk(sk);
1261 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire * HZ);
1265 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1267 struct llc_opt *llc = llc_sk(sk);
1269 mod_timer(&llc->rej_sent_timer.timer,
1270 jiffies + llc->rej_sent_timer.expire * HZ);
1274 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1275 struct sk_buff *skb)
1277 struct llc_opt *llc = llc_sk(sk);
1279 if (!timer_pending(&llc->ack_timer.timer))
1280 mod_timer(&llc->ack_timer.timer,
1281 jiffies + llc->ack_timer.expire * HZ);
1285 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1287 del_timer(&llc_sk(sk)->ack_timer.timer);
1291 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1293 struct llc_opt *llc = llc_sk(sk);
1295 del_timer(&llc->pf_cycle_timer.timer);
1296 llc_conn_set_p_flag(sk, 0);
1300 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1302 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1306 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1310 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1311 struct llc_opt *llc = llc_sk(sk);
1313 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1314 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1315 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1316 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1317 llc->retry_count = 0;
1318 del_timer(&llc->ack_timer.timer);
1319 if (llc->failed_data_req) {
1320 /* already, we did not accept data from upper layer
1321 * (tx_window full or unacceptable state). Now, we
1322 * can send data and must inform to upper layer.
1324 llc->failed_data_req = 0;
1325 llc_conn_ac_data_confirm(sk, skb);
1328 mod_timer(&llc->ack_timer.timer,
1329 jiffies + llc->ack_timer.expire * HZ);
1330 } else if (llc->failed_data_req) {
1333 llc_pdu_decode_pf_bit(skb, &f_bit);
1335 llc->failed_data_req = 0;
1336 llc_conn_ac_data_confirm(sk, skb);
1342 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1344 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1346 if (LLC_PDU_IS_RSP(pdu)) {
1349 llc_pdu_decode_pf_bit(skb, &f_bit);
1351 llc_conn_set_p_flag(sk, 0);
1352 llc_conn_ac_stop_p_timer(sk, skb);
1358 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1360 llc_sk(sk)->data_flag = 2;
1364 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1366 llc_sk(sk)->data_flag = 0;
1370 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1372 llc_sk(sk)->data_flag = 1;
1376 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1377 struct sk_buff *skb)
1379 if (!llc_sk(sk)->data_flag)
1380 llc_sk(sk)->data_flag = 1;
1384 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1386 llc_conn_set_p_flag(sk, 0);
1390 int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1392 llc_conn_set_p_flag(sk, 1);
1396 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1398 llc_sk(sk)->remote_busy_flag = 0;
1402 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1404 llc_sk(sk)->cause_flag = 0;
1408 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1410 llc_sk(sk)->cause_flag = 1;
1414 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1416 llc_sk(sk)->retry_count = 0;
1420 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1422 llc_sk(sk)->retry_count++;
1426 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1432 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1434 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1438 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1444 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1446 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1450 int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1452 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128;
1456 int llc_conn_ac_set_f_flag_p(struct sock *sk, struct sk_buff *skb)
1458 llc_pdu_decode_pf_bit(skb, &llc_sk(sk)->f_flag);
1462 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1464 struct sock *sk = (struct sock *)timeout_data;
1465 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1469 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1472 ev->type = LLC_CONN_EV_TYPE_P_TMR;
1473 llc_process_tmr_ev(sk, skb);
1478 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1480 struct sock *sk = (struct sock *)timeout_data;
1481 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1485 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1488 ev->type = LLC_CONN_EV_TYPE_BUSY_TMR;
1489 llc_process_tmr_ev(sk, skb);
1494 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1496 struct sock* sk = (struct sock *)timeout_data;
1497 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1501 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1504 ev->type = LLC_CONN_EV_TYPE_ACK_TMR;
1505 llc_process_tmr_ev(sk, skb);
1510 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1512 struct sock *sk = (struct sock *)timeout_data;
1513 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1517 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1520 ev->type = LLC_CONN_EV_TYPE_REJ_TMR;
1521 llc_process_tmr_ev(sk, skb);
1526 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1528 llc_sk(sk)->X = llc_sk(sk)->vS;
1529 llc_conn_ac_set_vs_nr(sk, skb);
1533 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1535 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1536 u8 nr = PDU_SUPV_GET_Nr(pdu);
1538 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1539 llc_conn_ac_set_vs_nr(sk, skb);
1544 * Non-standard actions; these not contained in IEEE specification; for
1548 * llc_conn_disc - removes connection from SAP list and frees it
1549 * @sk: closed connection
1550 * @skb: occurred event
1552 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1554 /* FIXME: this thing seems to want to die */
1559 * llc_conn_reset - resets connection
1560 * @sk : reseting connection.
1561 * @skb: occurred event.
1563 * Stop all timers, empty all queues and reset all flags.
1565 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1572 * llc_circular_between - designates that b is between a and c or not
1574 * @b: element to see if is between a and b
1577 * This function designates that b is between a and c or not (for example,
1578 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1581 u8 llc_circular_between(u8 a, u8 b, u8 c)
1589 * llc_process_tmr_ev - timer backend
1590 * @sk: active connection
1591 * @skb: occurred event
1593 * This function is called from timer callback functions. When connection
1594 * is busy (during sending a data frame) timer expiration event must be
1595 * queued. Otherwise this event can be sent to connection state machine.
1596 * Queued events will process by llc_backlog_rcv function after sending
1599 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1601 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1602 printk(KERN_WARNING "%s: timer called on closed connection\n",
1606 if (!sock_owned_by_user(sk))
1607 llc_conn_state_process(sk, skb);
1609 llc_set_backlog_type(skb, LLC_EVENT);
1610 sk_add_backlog(sk, skb);