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 <linux/slab.h>
22 #include <net/llc_conn.h>
23 #include <net/llc_sap.h>
25 #include <net/llc_c_ev.h>
26 #include <net/llc_c_ac.h>
27 #include <net/llc_c_st.h>
28 #include <net/llc_pdu.h>
32 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
33 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
34 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev);
36 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
38 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
41 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
45 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
47 struct llc_sock *llc = llc_sk(sk);
49 if (llc->remote_busy_flag) {
51 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
53 llc->remote_busy_flag = 0;
54 del_timer(&llc->busy_state_timer.timer);
55 nr = LLC_I_GET_NR(pdu);
56 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
61 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
63 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
65 ev->ind_prim = LLC_CONN_PRIM;
69 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
71 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
73 ev->cfm_prim = LLC_CONN_PRIM;
77 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
79 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
81 ev->cfm_prim = LLC_DATA_PRIM;
85 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
87 llc_conn_rtn_pdu(sk, skb);
91 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
93 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
97 if (ev->type == LLC_CONN_EV_TYPE_PDU) {
98 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
100 if (LLC_PDU_IS_RSP(pdu) &&
101 LLC_PDU_TYPE_IS_U(pdu) &&
102 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
103 reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
104 else if (LLC_PDU_IS_CMD(pdu) &&
105 LLC_PDU_TYPE_IS_U(pdu) &&
106 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
107 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
108 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
109 reason = LLC_DISC_REASON_ACK_TMR_EXP;
114 ev->ind_prim = LLC_DISC_PRIM;
119 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
121 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
123 ev->reason = ev->status;
124 ev->cfm_prim = LLC_DISC_PRIM;
128 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
132 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
133 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
134 struct llc_sock *llc = llc_sk(sk);
137 case LLC_CONN_EV_TYPE_PDU:
138 if (LLC_PDU_IS_RSP(pdu) &&
139 LLC_PDU_TYPE_IS_U(pdu) &&
140 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
141 reason = LLC_RESET_REASON_LOCAL;
143 } else if (LLC_PDU_IS_CMD(pdu) &&
144 LLC_PDU_TYPE_IS_U(pdu) &&
145 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
146 reason = LLC_RESET_REASON_REMOTE;
150 case LLC_CONN_EV_TYPE_ACK_TMR:
151 case LLC_CONN_EV_TYPE_P_TMR:
152 case LLC_CONN_EV_TYPE_REJ_TMR:
153 case LLC_CONN_EV_TYPE_BUSY_TMR:
154 if (llc->retry_count > llc->n2) {
155 reason = LLC_RESET_REASON_LOCAL;
162 ev->ind_prim = LLC_RESET_PRIM;
167 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
169 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
172 ev->cfm_prim = LLC_RESET_PRIM;
176 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
179 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
181 if (LLC_PDU_IS_RSP(pdu) &&
182 LLC_PDU_TYPE_IS_I(pdu) &&
183 LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
184 llc_conn_ac_clear_remote_busy(sk, skb);
188 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
191 struct llc_sock *llc = llc_sk(sk);
193 if (llc->data_flag == 2)
194 del_timer(&llc->rej_sent_timer.timer);
198 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
201 struct llc_sock *llc = llc_sk(sk);
202 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
205 struct llc_sap *sap = llc->sap;
207 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
208 llc->daddr.lsap, LLC_PDU_CMD);
209 llc_pdu_init_as_disc_cmd(nskb, 1);
210 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
213 llc_conn_send_pdu(sk, nskb);
214 llc_conn_ac_set_p_flag_1(sk, skb);
223 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
226 struct llc_sock *llc = llc_sk(sk);
227 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
230 struct llc_sap *sap = llc->sap;
233 llc_pdu_decode_pf_bit(skb, &f_bit);
234 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
235 llc->daddr.lsap, LLC_PDU_RSP);
236 llc_pdu_init_as_dm_rsp(nskb, f_bit);
237 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
240 llc_conn_send_pdu(sk, nskb);
249 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
252 struct llc_sock *llc = llc_sk(sk);
253 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
256 struct llc_sap *sap = llc->sap;
258 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
259 llc->daddr.lsap, LLC_PDU_RSP);
260 llc_pdu_init_as_dm_rsp(nskb, 1);
261 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
264 llc_conn_send_pdu(sk, nskb);
273 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
277 struct sk_buff *nskb;
278 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
279 struct llc_sock *llc = llc_sk(sk);
281 llc->rx_pdu_hdr = *((u32 *)pdu);
282 if (LLC_PDU_IS_CMD(pdu))
283 llc_pdu_decode_pf_bit(skb, &f_bit);
286 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
287 sizeof(struct llc_frmr_info));
289 struct llc_sap *sap = llc->sap;
291 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
292 llc->daddr.lsap, LLC_PDU_RSP);
293 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
295 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
298 llc_conn_send_pdu(sk, nskb);
307 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
310 struct llc_sock *llc = llc_sk(sk);
311 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
312 sizeof(struct llc_frmr_info));
315 struct llc_sap *sap = llc->sap;
316 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
318 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
319 llc->daddr.lsap, LLC_PDU_RSP);
320 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
322 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
325 llc_conn_send_pdu(sk, nskb);
334 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
338 struct sk_buff *nskb;
339 struct llc_sock *llc = llc_sk(sk);
341 llc_pdu_decode_pf_bit(skb, &f_bit);
342 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
343 sizeof(struct llc_frmr_info));
345 struct llc_sap *sap = llc->sap;
346 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
348 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
349 llc->daddr.lsap, LLC_PDU_RSP);
350 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
352 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
355 llc_conn_send_pdu(sk, nskb);
364 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
367 struct llc_sock *llc = llc_sk(sk);
368 struct llc_sap *sap = llc->sap;
370 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
371 llc->daddr.lsap, LLC_PDU_CMD);
372 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
373 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
376 llc_conn_send_pdu(sk, skb);
377 llc_conn_ac_inc_vs_by_1(sk, skb);
382 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
385 struct llc_sock *llc = llc_sk(sk);
386 struct llc_sap *sap = llc->sap;
388 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
389 llc->daddr.lsap, LLC_PDU_CMD);
390 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
391 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
394 llc_conn_send_pdu(sk, skb);
395 llc_conn_ac_inc_vs_by_1(sk, skb);
400 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
403 struct llc_sock *llc = llc_sk(sk);
404 struct llc_sap *sap = llc->sap;
406 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
407 llc->daddr.lsap, LLC_PDU_CMD);
408 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
409 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
412 llc_conn_send_pdu(sk, skb);
413 llc_conn_ac_inc_vs_by_1(sk, skb);
418 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
420 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
421 u8 nr = LLC_I_GET_NR(pdu);
423 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
427 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
431 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
433 struct llc_sock *llc = llc_sk(sk);
434 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
437 struct llc_sap *sap = llc->sap;
439 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
440 llc->daddr.lsap, LLC_PDU_RSP);
441 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
442 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
444 llc_conn_send_pdu(sk, nskb);
449 nr = LLC_I_GET_NR(pdu);
451 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
456 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
458 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
459 u8 nr = LLC_I_GET_NR(pdu);
461 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
465 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
468 struct llc_sock *llc = llc_sk(sk);
469 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
472 struct llc_sap *sap = llc->sap;
474 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
475 llc->daddr.lsap, LLC_PDU_CMD);
476 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
477 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
480 llc_conn_send_pdu(sk, nskb);
489 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
492 struct llc_sock *llc = llc_sk(sk);
493 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
496 struct llc_sap *sap = llc->sap;
498 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
499 llc->daddr.lsap, LLC_PDU_RSP);
500 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
501 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
504 llc_conn_send_pdu(sk, nskb);
513 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
516 struct llc_sock *llc = llc_sk(sk);
517 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
520 struct llc_sap *sap = llc->sap;
522 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
523 llc->daddr.lsap, LLC_PDU_RSP);
524 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
525 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
528 llc_conn_send_pdu(sk, nskb);
537 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
540 struct llc_sock *llc = llc_sk(sk);
541 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
544 struct llc_sap *sap = llc->sap;
546 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
547 llc->daddr.lsap, LLC_PDU_CMD);
548 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
549 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
552 llc_conn_send_pdu(sk, nskb);
561 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
564 struct llc_sock *llc = llc_sk(sk);
565 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
568 struct llc_sap *sap = llc->sap;
570 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
571 llc->daddr.lsap, LLC_PDU_RSP);
572 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
573 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
576 llc_conn_send_pdu(sk, nskb);
585 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
588 struct llc_sock *llc = llc_sk(sk);
589 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
592 struct llc_sap *sap = llc->sap;
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_rnr_rsp(nskb, 0, 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_set_remote_busy(struct sock *sk, struct sk_buff *skb)
611 struct llc_sock *llc = llc_sk(sk);
613 if (!llc->remote_busy_flag) {
614 llc->remote_busy_flag = 1;
615 mod_timer(&llc->busy_state_timer.timer,
616 jiffies + llc->busy_state_timer.expire);
621 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
624 struct llc_sock *llc = llc_sk(sk);
625 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
628 struct llc_sap *sap = llc->sap;
630 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
631 llc->daddr.lsap, LLC_PDU_RSP);
632 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
633 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
636 llc_conn_send_pdu(sk, nskb);
645 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
648 struct llc_sock *llc = llc_sk(sk);
649 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
652 struct llc_sap *sap = llc->sap;
654 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
655 llc->daddr.lsap, LLC_PDU_CMD);
656 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
657 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
660 llc_conn_send_pdu(sk, nskb);
669 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
672 struct llc_sock *llc = llc_sk(sk);
673 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
676 struct llc_sap *sap = llc->sap;
679 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
680 llc->daddr.lsap, LLC_PDU_RSP);
681 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
682 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
685 llc_conn_send_pdu(sk, nskb);
694 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
697 struct llc_sock *llc = llc_sk(sk);
698 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
701 struct llc_sap *sap = llc->sap;
703 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
704 llc->daddr.lsap, LLC_PDU_RSP);
705 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
706 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
709 llc_conn_send_pdu(sk, nskb);
718 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
721 struct llc_sock *llc = llc_sk(sk);
722 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
725 struct llc_sap *sap = llc->sap;
727 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
728 llc->daddr.lsap, LLC_PDU_RSP);
729 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
730 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
733 llc_conn_send_pdu(sk, nskb);
742 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
745 struct llc_sock *llc = llc_sk(sk);
746 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
749 struct llc_sap *sap = llc->sap;
751 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
752 llc->daddr.lsap, LLC_PDU_RSP);
753 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
754 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
757 llc_conn_send_pdu(sk, nskb);
766 void llc_conn_set_p_flag(struct sock *sk, u8 value)
768 int state_changed = llc_sk(sk)->p_flag && !value;
770 llc_sk(sk)->p_flag = value;
773 sk->sk_state_change(sk);
776 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
779 struct llc_sock *llc = llc_sk(sk);
780 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
783 struct llc_sap *sap = llc->sap;
784 u8 *dmac = llc->daddr.mac;
786 if (llc->dev->flags & IFF_LOOPBACK)
787 dmac = llc->dev->dev_addr;
788 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
789 llc->daddr.lsap, LLC_PDU_CMD);
790 llc_pdu_init_as_sabme_cmd(nskb, 1);
791 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
794 llc_conn_send_pdu(sk, nskb);
795 llc_conn_set_p_flag(sk, 1);
804 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
808 struct llc_sock *llc = llc_sk(sk);
809 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
811 llc_pdu_decode_pf_bit(skb, &f_bit);
813 struct llc_sap *sap = llc->sap;
815 nskb->dev = llc->dev;
816 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
817 llc->daddr.lsap, LLC_PDU_RSP);
818 llc_pdu_init_as_ua_rsp(nskb, f_bit);
819 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
822 llc_conn_send_pdu(sk, nskb);
831 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
833 llc_sk(sk)->s_flag = 0;
837 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
839 llc_sk(sk)->s_flag = 1;
843 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
845 struct llc_sock *llc = llc_sk(sk);
847 llc_conn_set_p_flag(sk, 1);
848 mod_timer(&llc->pf_cycle_timer.timer,
849 jiffies + llc->pf_cycle_timer.expire);
854 * llc_conn_ac_send_ack_if_needed - check if ack is needed
855 * @sk: current connection structure
856 * @skb: current event
858 * Checks number of received PDUs which have not been acknowledged, yet,
859 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
860 * sends an RR response as acknowledgement for them. Returns 0 for
861 * success, 1 otherwise.
863 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
866 struct llc_sock *llc = llc_sk(sk);
868 llc_pdu_decode_pf_bit(skb, &pf_bit);
869 llc->ack_pf |= pf_bit & 1;
870 if (!llc->ack_must_be_send) {
871 llc->first_pdu_Ns = llc->vR;
872 llc->ack_must_be_send = 1;
873 llc->ack_pf = pf_bit & 1;
875 if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
876 % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
877 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
878 llc->ack_must_be_send = 0;
880 llc_conn_ac_inc_npta_value(sk, skb);
886 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
887 * @sk: current connection structure
888 * @skb: current event
890 * This action resets ack_must_be_send flag of given connection, this flag
891 * indicates if there is any PDU which has not been acknowledged yet.
892 * Returns 0 for success, 1 otherwise.
894 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
896 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
901 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
902 * @sk: current connection structure
903 * @skb: current event
905 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
906 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
907 * set to one if one PDU with p-bit set to one is received. Returns 0 for
908 * success, 1 otherwise.
910 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
914 struct llc_sock *llc = llc_sk(sk);
915 struct llc_sap *sap = llc->sap;
917 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
918 llc->daddr.lsap, LLC_PDU_RSP);
919 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
920 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
923 llc_conn_send_pdu(sk, skb);
924 llc_conn_ac_inc_vs_by_1(sk, skb);
930 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
931 * @sk: current connection structure.
932 * @skb: current event.
934 * This action sends an I-format PDU as acknowledge to received PDUs which
935 * have not been acknowledged, yet, if there is any. By using of this
936 * action number of acknowledgements decreases, this technic is called
937 * piggy backing. Returns 0 for success, 1 otherwise.
939 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
941 struct llc_sock *llc = llc_sk(sk);
944 if (llc->ack_must_be_send) {
945 ret = llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
946 llc->ack_must_be_send = 0 ;
949 ret = llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
956 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
957 * @sk: current connection structure.
958 * @skb: current event.
960 * This action sends an RR response with f-bit set to ack_pf flag as
961 * acknowledge to all received PDUs which have not been acknowledged, yet,
962 * if there is any. ack_pf flag indicates if a PDU has been received with
963 * p-bit set to one. Returns 0 for success, 1 otherwise.
965 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
969 struct llc_sock *llc = llc_sk(sk);
970 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
973 struct llc_sap *sap = llc->sap;
975 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
976 llc->daddr.lsap, LLC_PDU_RSP);
977 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
978 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
981 llc_conn_send_pdu(sk, nskb);
991 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
992 * @sk: current connection structure.
993 * @skb: current event.
995 * After "inc_cntr" times calling of this action, "npta" increase by one.
996 * this action tries to make vale of "npta" greater as possible; number of
997 * acknowledgements decreases by increasing of "npta". Returns 0 for
998 * success, 1 otherwise.
1000 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
1002 struct llc_sock *llc = llc_sk(sk);
1004 if (!llc->inc_cntr) {
1006 llc->dec_cntr = llc->inc_cntr = 2;
1008 if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
1009 llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
1016 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1017 * @sk: current connection structure.
1018 * @skb: current event.
1020 * After receiving "dec_cntr" times RR command, this action decreases
1021 * "npta" by one. Returns 0 for success, 1 otherwise.
1023 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1025 struct llc_sock *llc = llc_sk(sk);
1027 if (!llc->connect_step && !llc->remote_busy_flag) {
1028 if (!llc->dec_step) {
1029 if (!llc->dec_cntr) {
1030 llc->inc_cntr = llc->dec_cntr = 2;
1032 llc->npta = llc->npta - 1;
1037 llc->connect_step = 0 ;
1042 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1043 * @sk: current connection structure.
1044 * @skb: current event.
1046 * After receiving "dec_cntr" times RNR command, this action decreases
1047 * "npta" by one. Returns 0 for success, 1 otherwise.
1049 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1051 struct llc_sock *llc = llc_sk(sk);
1053 if (llc->remote_busy_flag)
1054 if (!llc->dec_step) {
1055 if (!llc->dec_cntr) {
1056 llc->inc_cntr = llc->dec_cntr = 2;
1066 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1067 * @sk: current connection structure.
1068 * @skb: current event.
1070 * After receiving of a REJ command or response, transmit window size is
1071 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1072 * success, 1 otherwise.
1074 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1076 struct llc_sock *llc = llc_sk(sk);
1077 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1079 if (llc->k - unacked_pdu < 1)
1082 llc->k -= unacked_pdu;
1087 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1088 * @sk: current connection structure.
1089 * @skb: current event.
1091 * After receiving an RR response with f-bit set to one, transmit window
1092 * size is increased by one. Returns 0 for success, 1 otherwise.
1094 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1096 struct llc_sock *llc = llc_sk(sk);
1099 if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1100 llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
1104 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1106 llc_sk_stop_all_timers(sk, false);
1110 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1112 struct llc_sock *llc = llc_sk(sk);
1114 del_timer(&llc->rej_sent_timer.timer);
1115 del_timer(&llc->pf_cycle_timer.timer);
1116 del_timer(&llc->busy_state_timer.timer);
1117 llc->ack_must_be_send = 0;
1122 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1124 struct llc_sock *llc = llc_sk(sk);
1126 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1130 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1132 struct llc_sock *llc = llc_sk(sk);
1134 mod_timer(&llc->rej_sent_timer.timer,
1135 jiffies + llc->rej_sent_timer.expire);
1139 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1140 struct sk_buff *skb)
1142 struct llc_sock *llc = llc_sk(sk);
1144 if (!timer_pending(&llc->ack_timer.timer))
1145 mod_timer(&llc->ack_timer.timer,
1146 jiffies + llc->ack_timer.expire);
1150 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1152 del_timer(&llc_sk(sk)->ack_timer.timer);
1156 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1158 struct llc_sock *llc = llc_sk(sk);
1160 del_timer(&llc->pf_cycle_timer.timer);
1161 llc_conn_set_p_flag(sk, 0);
1165 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1167 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1171 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1175 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1176 struct llc_sock *llc = llc_sk(sk);
1178 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1179 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1180 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1181 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1182 llc->retry_count = 0;
1183 del_timer(&llc->ack_timer.timer);
1184 if (llc->failed_data_req) {
1185 /* already, we did not accept data from upper layer
1186 * (tx_window full or unacceptable state). Now, we
1187 * can send data and must inform to upper layer.
1189 llc->failed_data_req = 0;
1190 llc_conn_ac_data_confirm(sk, skb);
1193 mod_timer(&llc->ack_timer.timer,
1194 jiffies + llc->ack_timer.expire);
1195 } else if (llc->failed_data_req) {
1198 llc_pdu_decode_pf_bit(skb, &f_bit);
1200 llc->failed_data_req = 0;
1201 llc_conn_ac_data_confirm(sk, skb);
1207 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1209 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1211 if (LLC_PDU_IS_RSP(pdu)) {
1214 llc_pdu_decode_pf_bit(skb, &f_bit);
1216 llc_conn_set_p_flag(sk, 0);
1217 llc_conn_ac_stop_p_timer(sk, skb);
1223 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1225 llc_sk(sk)->data_flag = 2;
1229 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1231 llc_sk(sk)->data_flag = 0;
1235 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1237 llc_sk(sk)->data_flag = 1;
1241 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1242 struct sk_buff *skb)
1244 if (!llc_sk(sk)->data_flag)
1245 llc_sk(sk)->data_flag = 1;
1249 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1251 llc_conn_set_p_flag(sk, 0);
1255 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1257 llc_conn_set_p_flag(sk, 1);
1261 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1263 llc_sk(sk)->remote_busy_flag = 0;
1267 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1269 llc_sk(sk)->cause_flag = 0;
1273 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1275 llc_sk(sk)->cause_flag = 1;
1279 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1281 llc_sk(sk)->retry_count = 0;
1285 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1287 llc_sk(sk)->retry_count++;
1291 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1297 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1299 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1303 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1309 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1311 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1315 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1317 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
1321 static void llc_conn_tmr_common_cb(struct sock *sk, u8 type)
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(struct timer_list *t)
1338 struct llc_sock *llc = from_timer(llc, t, pf_cycle_timer.timer);
1340 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_P_TMR);
1343 void llc_conn_busy_tmr_cb(struct timer_list *t)
1345 struct llc_sock *llc = from_timer(llc, t, busy_state_timer.timer);
1347 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_BUSY_TMR);
1350 void llc_conn_ack_tmr_cb(struct timer_list *t)
1352 struct llc_sock *llc = from_timer(llc, t, ack_timer.timer);
1354 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_ACK_TMR);
1357 void llc_conn_rej_tmr_cb(struct timer_list *t)
1359 struct llc_sock *llc = from_timer(llc, t, rej_sent_timer.timer);
1361 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_REJ_TMR);
1364 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1366 llc_sk(sk)->X = llc_sk(sk)->vS;
1367 llc_conn_ac_set_vs_nr(sk, skb);
1371 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1373 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1374 u8 nr = PDU_SUPV_GET_Nr(pdu);
1376 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1377 llc_conn_ac_set_vs_nr(sk, skb);
1382 * Non-standard actions; these not contained in IEEE specification; for
1386 * llc_conn_disc - removes connection from SAP list and frees it
1387 * @sk: closed connection
1388 * @skb: occurred event
1390 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1392 /* FIXME: this thing seems to want to die */
1397 * llc_conn_reset - resets connection
1398 * @sk : reseting connection.
1399 * @skb: occurred event.
1401 * Stop all timers, empty all queues and reset all flags.
1403 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1410 * llc_circular_between - designates that b is between a and c or not
1412 * @b: element to see if is between a and b
1415 * This function designates that b is between a and c or not (for example,
1416 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1419 u8 llc_circular_between(u8 a, u8 b, u8 c)
1427 * llc_process_tmr_ev - timer backend
1428 * @sk: active connection
1429 * @skb: occurred event
1431 * This function is called from timer callback functions. When connection
1432 * is busy (during sending a data frame) timer expiration event must be
1433 * queued. Otherwise this event can be sent to connection state machine.
1434 * Queued events will process by llc_backlog_rcv function after sending
1437 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1439 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1440 printk(KERN_WARNING "%s: timer called on closed connection\n",
1444 if (!sock_owned_by_user(sk))
1445 llc_conn_state_process(sk, skb);
1447 llc_set_backlog_type(skb, LLC_EVENT);
1448 __sk_add_backlog(sk, skb);