2 * llc_c_ac.c - actions performed during connection state transition.
5 * Functions in this module are implementation of connection component actions
6 * Details of actions can be found in IEEE-802.2 standard document.
7 * All functions have one connection and one event as input argument. All of
8 * them return 0 On success and 1 otherwise.
10 * Copyright (c) 1997 by Procom Technology, Inc.
11 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
13 * This program can be redistributed or modified under the terms of the
14 * GNU General Public License as published by the Free Software Foundation.
15 * This program is distributed without any warranty or implied warranty
16 * of merchantability or fitness for a particular purpose.
18 * See the GNU General Public License for more details.
20 #include <linux/netdevice.h>
21 #include <net/llc_conn.h>
22 #include <net/llc_sap.h>
24 #include <net/llc_c_ev.h>
25 #include <net/llc_c_ac.h>
26 #include <net/llc_c_st.h>
27 #include <net/llc_pdu.h>
30 #include "llc_output.h"
32 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
33 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
34 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev);
36 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
38 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
41 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
45 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
47 struct llc_sock *llc = llc_sk(sk);
49 if (llc->remote_busy_flag) {
51 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
53 llc->remote_busy_flag = 0;
54 del_timer(&llc->busy_state_timer.timer);
55 nr = LLC_I_GET_NR(pdu);
56 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
61 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
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);
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);
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);
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);
288 struct llc_sap *sap = llc->sap;
290 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
291 llc->daddr.lsap, LLC_PDU_RSP);
292 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
294 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
297 llc_conn_send_pdu(sk, nskb);
306 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
309 struct llc_sock *llc = llc_sk(sk);
310 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
313 struct llc_sap *sap = llc->sap;
314 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
316 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
317 llc->daddr.lsap, LLC_PDU_RSP);
318 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
320 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
323 llc_conn_send_pdu(sk, nskb);
332 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
336 struct sk_buff *nskb;
337 struct llc_sock *llc = llc_sk(sk);
339 llc_pdu_decode_pf_bit(skb, &f_bit);
340 nskb = llc_alloc_frame(sk, llc->dev);
342 struct llc_sap *sap = llc->sap;
343 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
345 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
346 llc->daddr.lsap, LLC_PDU_RSP);
347 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
349 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
352 llc_conn_send_pdu(sk, nskb);
361 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
364 struct llc_sock *llc = llc_sk(sk);
365 struct llc_sap *sap = llc->sap;
367 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
368 llc->daddr.lsap, LLC_PDU_CMD);
369 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
370 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
372 llc_conn_send_pdu(sk, skb);
373 llc_conn_ac_inc_vs_by_1(sk, skb);
378 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
381 struct llc_sock *llc = llc_sk(sk);
382 struct llc_sap *sap = llc->sap;
384 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
385 llc->daddr.lsap, LLC_PDU_CMD);
386 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
387 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
389 llc_conn_send_pdu(sk, skb);
390 llc_conn_ac_inc_vs_by_1(sk, skb);
395 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
398 struct llc_sock *llc = llc_sk(sk);
399 struct llc_sap *sap = llc->sap;
401 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
402 llc->daddr.lsap, LLC_PDU_CMD);
403 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
404 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
406 llc_conn_send_pdu(sk, skb);
407 llc_conn_ac_inc_vs_by_1(sk, skb);
412 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
414 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
415 u8 nr = LLC_I_GET_NR(pdu);
417 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
421 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
425 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
427 struct llc_sock *llc = llc_sk(sk);
428 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
431 struct llc_sap *sap = llc->sap;
433 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
434 llc->daddr.lsap, LLC_PDU_RSP);
435 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
436 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
438 llc_conn_send_pdu(sk, nskb);
443 nr = LLC_I_GET_NR(pdu);
445 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
450 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
452 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
453 u8 nr = LLC_I_GET_NR(pdu);
455 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
459 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
462 struct llc_sock *llc = llc_sk(sk);
463 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
466 struct llc_sap *sap = llc->sap;
468 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
469 llc->daddr.lsap, LLC_PDU_CMD);
470 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
471 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
474 llc_conn_send_pdu(sk, nskb);
483 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
486 struct llc_sock *llc = llc_sk(sk);
487 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
490 struct llc_sap *sap = llc->sap;
492 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
493 llc->daddr.lsap, LLC_PDU_RSP);
494 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
495 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
498 llc_conn_send_pdu(sk, nskb);
507 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
510 struct llc_sock *llc = llc_sk(sk);
511 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
514 struct llc_sap *sap = llc->sap;
516 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
517 llc->daddr.lsap, LLC_PDU_RSP);
518 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
519 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
522 llc_conn_send_pdu(sk, nskb);
531 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
534 struct llc_sock *llc = llc_sk(sk);
535 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
538 struct llc_sap *sap = llc->sap;
540 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
541 llc->daddr.lsap, LLC_PDU_CMD);
542 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
543 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
546 llc_conn_send_pdu(sk, nskb);
555 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
558 struct llc_sock *llc = llc_sk(sk);
559 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
562 struct llc_sap *sap = llc->sap;
564 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
565 llc->daddr.lsap, LLC_PDU_RSP);
566 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
567 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
570 llc_conn_send_pdu(sk, nskb);
579 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
582 struct llc_sock *llc = llc_sk(sk);
583 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
586 struct llc_sap *sap = llc->sap;
588 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
589 llc->daddr.lsap, LLC_PDU_RSP);
590 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
591 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
594 llc_conn_send_pdu(sk, nskb);
603 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
605 struct llc_sock *llc = llc_sk(sk);
607 if (!llc->remote_busy_flag) {
608 llc->remote_busy_flag = 1;
609 mod_timer(&llc->busy_state_timer.timer,
610 jiffies + llc->busy_state_timer.expire);
615 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
618 struct llc_sock *llc = llc_sk(sk);
619 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
622 struct llc_sap *sap = llc->sap;
624 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
625 llc->daddr.lsap, LLC_PDU_RSP);
626 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
627 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
630 llc_conn_send_pdu(sk, nskb);
639 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
642 struct llc_sock *llc = llc_sk(sk);
643 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
646 struct llc_sap *sap = llc->sap;
648 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
649 llc->daddr.lsap, LLC_PDU_CMD);
650 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
651 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
654 llc_conn_send_pdu(sk, nskb);
663 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
666 struct llc_sock *llc = llc_sk(sk);
667 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
670 struct llc_sap *sap = llc->sap;
673 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
674 llc->daddr.lsap, LLC_PDU_RSP);
675 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
676 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
679 llc_conn_send_pdu(sk, nskb);
688 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
691 struct llc_sock *llc = llc_sk(sk);
692 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
695 struct llc_sap *sap = llc->sap;
697 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
698 llc->daddr.lsap, LLC_PDU_RSP);
699 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
700 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
703 llc_conn_send_pdu(sk, nskb);
712 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
715 struct llc_sock *llc = llc_sk(sk);
716 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
719 struct llc_sap *sap = llc->sap;
721 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
722 llc->daddr.lsap, LLC_PDU_RSP);
723 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
724 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
727 llc_conn_send_pdu(sk, nskb);
736 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
739 struct llc_sock *llc = llc_sk(sk);
740 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
743 struct llc_sap *sap = llc->sap;
745 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
746 llc->daddr.lsap, LLC_PDU_RSP);
747 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
748 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
751 llc_conn_send_pdu(sk, nskb);
760 void llc_conn_set_p_flag(struct sock *sk, u8 value)
762 int state_changed = llc_sk(sk)->p_flag && !value;
764 llc_sk(sk)->p_flag = value;
767 sk->sk_state_change(sk);
770 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
773 struct llc_sock *llc = llc_sk(sk);
774 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
777 struct llc_sap *sap = llc->sap;
778 u8 *dmac = llc->daddr.mac;
780 if (llc->dev->flags & IFF_LOOPBACK)
781 dmac = llc->dev->dev_addr;
782 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
783 llc->daddr.lsap, LLC_PDU_CMD);
784 llc_pdu_init_as_sabme_cmd(nskb, 1);
785 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
788 llc_conn_send_pdu(sk, nskb);
789 llc_conn_set_p_flag(sk, 1);
798 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
802 struct llc_sock *llc = llc_sk(sk);
803 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
805 llc_pdu_decode_pf_bit(skb, &f_bit);
807 struct llc_sap *sap = llc->sap;
809 nskb->dev = llc->dev;
810 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
811 llc->daddr.lsap, LLC_PDU_RSP);
812 llc_pdu_init_as_ua_rsp(nskb, f_bit);
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_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
827 llc_sk(sk)->s_flag = 0;
831 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
833 llc_sk(sk)->s_flag = 1;
837 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
839 struct llc_sock *llc = llc_sk(sk);
841 llc_conn_set_p_flag(sk, 1);
842 mod_timer(&llc->pf_cycle_timer.timer,
843 jiffies + llc->pf_cycle_timer.expire);
848 * llc_conn_ac_send_ack_if_needed - check if ack is needed
849 * @sk: current connection structure
850 * @skb: current event
852 * Checks number of received PDUs which have not been acknowledged, yet,
853 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
854 * sends an RR response as acknowledgement for them. Returns 0 for
855 * success, 1 otherwise.
857 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
860 struct llc_sock *llc = llc_sk(sk);
862 llc_pdu_decode_pf_bit(skb, &pf_bit);
863 llc->ack_pf |= pf_bit & 1;
864 if (!llc->ack_must_be_send) {
865 llc->first_pdu_Ns = llc->vR;
866 llc->ack_must_be_send = 1;
867 llc->ack_pf = pf_bit & 1;
869 if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
870 % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
871 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
872 llc->ack_must_be_send = 0;
874 llc_conn_ac_inc_npta_value(sk, skb);
880 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
881 * @sk: current connection structure
882 * @skb: current event
884 * This action resets ack_must_be_send flag of given connection, this flag
885 * indicates if there is any PDU which has not been acknowledged yet.
886 * Returns 0 for success, 1 otherwise.
888 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
890 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
895 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
896 * @sk: current connection structure
897 * @skb: current event
899 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
900 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
901 * set to one if one PDU with p-bit set to one is received. Returns 0 for
902 * success, 1 otherwise.
904 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
908 struct llc_sock *llc = llc_sk(sk);
909 struct llc_sap *sap = llc->sap;
911 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
912 llc->daddr.lsap, LLC_PDU_RSP);
913 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
914 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
916 llc_conn_send_pdu(sk, skb);
917 llc_conn_ac_inc_vs_by_1(sk, skb);
923 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
924 * @sk: current connection structure.
925 * @skb: current event.
927 * This action sends an I-format PDU as acknowledge to received PDUs which
928 * have not been acknowledged, yet, if there is any. By using of this
929 * action number of acknowledgements decreases, this technic is called
930 * piggy backing. Returns 0 for success, 1 otherwise.
932 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
934 struct llc_sock *llc = llc_sk(sk);
936 if (llc->ack_must_be_send) {
937 llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
938 llc->ack_must_be_send = 0 ;
941 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
946 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
947 * @sk: current connection structure.
948 * @skb: current event.
950 * This action sends an RR response with f-bit set to ack_pf flag as
951 * acknowledge to all received PDUs which have not been acknowledged, yet,
952 * if there is any. ack_pf flag indicates if a PDU has been received with
953 * p-bit set to one. Returns 0 for success, 1 otherwise.
955 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
959 struct llc_sock *llc = llc_sk(sk);
960 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
963 struct llc_sap *sap = llc->sap;
965 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
966 llc->daddr.lsap, LLC_PDU_RSP);
967 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
968 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
971 llc_conn_send_pdu(sk, nskb);
981 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
982 * @sk: current connection structure.
983 * @skb: current event.
985 * After "inc_cntr" times calling of this action, "npta" increase by one.
986 * this action tries to make vale of "npta" greater as possible; number of
987 * acknowledgements decreases by increasing of "npta". Returns 0 for
988 * success, 1 otherwise.
990 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
992 struct llc_sock *llc = llc_sk(sk);
994 if (!llc->inc_cntr) {
996 llc->dec_cntr = llc->inc_cntr = 2;
998 if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
999 llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
1006 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1007 * @sk: current connection structure.
1008 * @skb: current event.
1010 * After receiving "dec_cntr" times RR command, this action decreases
1011 * "npta" by one. Returns 0 for success, 1 otherwise.
1013 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1015 struct llc_sock *llc = llc_sk(sk);
1017 if (!llc->connect_step && !llc->remote_busy_flag) {
1018 if (!llc->dec_step) {
1019 if (!llc->dec_cntr) {
1020 llc->inc_cntr = llc->dec_cntr = 2;
1022 llc->npta = llc->npta - 1;
1027 llc->connect_step = 0 ;
1032 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1033 * @sk: current connection structure.
1034 * @skb: current event.
1036 * After receiving "dec_cntr" times RNR command, this action decreases
1037 * "npta" by one. Returns 0 for success, 1 otherwise.
1039 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1041 struct llc_sock *llc = llc_sk(sk);
1043 if (llc->remote_busy_flag)
1044 if (!llc->dec_step) {
1045 if (!llc->dec_cntr) {
1046 llc->inc_cntr = llc->dec_cntr = 2;
1056 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1057 * @sk: current connection structure.
1058 * @skb: current event.
1060 * After receiving of a REJ command or response, transmit window size is
1061 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1062 * success, 1 otherwise.
1064 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1066 struct llc_sock *llc = llc_sk(sk);
1067 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1069 if (llc->k - unacked_pdu < 1)
1072 llc->k -= unacked_pdu;
1077 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1078 * @sk: current connection structure.
1079 * @skb: current event.
1081 * After receiving an RR response with f-bit set to one, transmit window
1082 * size is increased by one. Returns 0 for success, 1 otherwise.
1084 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1086 struct llc_sock *llc = llc_sk(sk);
1089 if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1090 llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
1094 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1096 struct llc_sock *llc = llc_sk(sk);
1098 del_timer(&llc->pf_cycle_timer.timer);
1099 del_timer(&llc->ack_timer.timer);
1100 del_timer(&llc->rej_sent_timer.timer);
1101 del_timer(&llc->busy_state_timer.timer);
1102 llc->ack_must_be_send = 0;
1107 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1109 struct llc_sock *llc = llc_sk(sk);
1111 del_timer(&llc->rej_sent_timer.timer);
1112 del_timer(&llc->pf_cycle_timer.timer);
1113 del_timer(&llc->busy_state_timer.timer);
1114 llc->ack_must_be_send = 0;
1119 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1121 struct llc_sock *llc = llc_sk(sk);
1123 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1127 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1129 struct llc_sock *llc = llc_sk(sk);
1131 mod_timer(&llc->rej_sent_timer.timer,
1132 jiffies + llc->rej_sent_timer.expire);
1136 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1137 struct sk_buff *skb)
1139 struct llc_sock *llc = llc_sk(sk);
1141 if (!timer_pending(&llc->ack_timer.timer))
1142 mod_timer(&llc->ack_timer.timer,
1143 jiffies + llc->ack_timer.expire);
1147 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1149 del_timer(&llc_sk(sk)->ack_timer.timer);
1153 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1155 struct llc_sock *llc = llc_sk(sk);
1157 del_timer(&llc->pf_cycle_timer.timer);
1158 llc_conn_set_p_flag(sk, 0);
1162 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1164 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1168 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1172 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1173 struct llc_sock *llc = llc_sk(sk);
1175 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1176 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1177 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1178 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1179 llc->retry_count = 0;
1180 del_timer(&llc->ack_timer.timer);
1181 if (llc->failed_data_req) {
1182 /* already, we did not accept data from upper layer
1183 * (tx_window full or unacceptable state). Now, we
1184 * can send data and must inform to upper layer.
1186 llc->failed_data_req = 0;
1187 llc_conn_ac_data_confirm(sk, skb);
1190 mod_timer(&llc->ack_timer.timer,
1191 jiffies + llc->ack_timer.expire);
1192 } else if (llc->failed_data_req) {
1195 llc_pdu_decode_pf_bit(skb, &f_bit);
1197 llc->failed_data_req = 0;
1198 llc_conn_ac_data_confirm(sk, skb);
1204 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1206 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1208 if (LLC_PDU_IS_RSP(pdu)) {
1211 llc_pdu_decode_pf_bit(skb, &f_bit);
1213 llc_conn_set_p_flag(sk, 0);
1214 llc_conn_ac_stop_p_timer(sk, skb);
1220 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1222 llc_sk(sk)->data_flag = 2;
1226 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1228 llc_sk(sk)->data_flag = 0;
1232 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1234 llc_sk(sk)->data_flag = 1;
1238 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1239 struct sk_buff *skb)
1241 if (!llc_sk(sk)->data_flag)
1242 llc_sk(sk)->data_flag = 1;
1246 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1248 llc_conn_set_p_flag(sk, 0);
1252 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1254 llc_conn_set_p_flag(sk, 1);
1258 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1260 llc_sk(sk)->remote_busy_flag = 0;
1264 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1266 llc_sk(sk)->cause_flag = 0;
1270 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1272 llc_sk(sk)->cause_flag = 1;
1276 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1278 llc_sk(sk)->retry_count = 0;
1282 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1284 llc_sk(sk)->retry_count++;
1288 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1294 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1296 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1300 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1306 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1308 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1312 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1314 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
1318 static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
1320 struct sock *sk = (struct sock *)timeout_data;
1321 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1325 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1327 skb_set_owner_r(skb, sk);
1329 llc_process_tmr_ev(sk, skb);
1334 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1336 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
1339 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1341 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
1344 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1346 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
1349 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1351 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
1354 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1356 llc_sk(sk)->X = llc_sk(sk)->vS;
1357 llc_conn_ac_set_vs_nr(sk, skb);
1361 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1363 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1364 u8 nr = PDU_SUPV_GET_Nr(pdu);
1366 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1367 llc_conn_ac_set_vs_nr(sk, skb);
1372 * Non-standard actions; these not contained in IEEE specification; for
1376 * llc_conn_disc - removes connection from SAP list and frees it
1377 * @sk: closed connection
1378 * @skb: occurred event
1380 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1382 /* FIXME: this thing seems to want to die */
1387 * llc_conn_reset - resets connection
1388 * @sk : reseting connection.
1389 * @skb: occurred event.
1391 * Stop all timers, empty all queues and reset all flags.
1393 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1400 * llc_circular_between - designates that b is between a and c or not
1402 * @b: element to see if is between a and b
1405 * This function designates that b is between a and c or not (for example,
1406 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1409 u8 llc_circular_between(u8 a, u8 b, u8 c)
1417 * llc_process_tmr_ev - timer backend
1418 * @sk: active connection
1419 * @skb: occurred event
1421 * This function is called from timer callback functions. When connection
1422 * is busy (during sending a data frame) timer expiration event must be
1423 * queued. Otherwise this event can be sent to connection state machine.
1424 * Queued events will process by llc_backlog_rcv function after sending
1427 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1429 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1430 printk(KERN_WARNING "%s: timer called on closed connection\n",
1434 if (!sock_owned_by_user(sk))
1435 llc_conn_state_process(sk, skb);
1437 llc_set_backlog_type(skb, LLC_EVENT);
1438 sk_add_backlog(sk, skb);