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)
67 llc_pdu_decode_dsap(skb, &dsap);
68 sap = llc_sap_find(dsap);
70 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
71 struct llc_sock *llc = llc_sk(sk);
73 llc_pdu_decode_sa(skb, llc->daddr.mac);
74 llc_pdu_decode_da(skb, llc->laddr.mac);
76 ev->ind_prim = LLC_CONN_PRIM;
82 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
84 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
86 ev->cfm_prim = LLC_CONN_PRIM;
90 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
92 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
94 ev->cfm_prim = LLC_DATA_PRIM;
98 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
100 llc_conn_rtn_pdu(sk, skb);
104 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
106 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
110 if (ev->type == LLC_CONN_EV_TYPE_PDU) {
111 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
113 if (LLC_PDU_IS_RSP(pdu) &&
114 LLC_PDU_TYPE_IS_U(pdu) &&
115 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
116 reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
117 else if (LLC_PDU_IS_CMD(pdu) &&
118 LLC_PDU_TYPE_IS_U(pdu) &&
119 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
120 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
121 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
122 reason = LLC_DISC_REASON_ACK_TMR_EXP;
127 ev->ind_prim = LLC_DISC_PRIM;
132 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
134 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
136 ev->reason = ev->status;
137 ev->cfm_prim = LLC_DISC_PRIM;
141 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
145 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
146 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
147 struct llc_sock *llc = llc_sk(sk);
150 case LLC_CONN_EV_TYPE_PDU:
151 if (LLC_PDU_IS_RSP(pdu) &&
152 LLC_PDU_TYPE_IS_U(pdu) &&
153 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
154 reason = LLC_RESET_REASON_LOCAL;
156 } else if (LLC_PDU_IS_CMD(pdu) &&
157 LLC_PDU_TYPE_IS_U(pdu) &&
158 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
159 reason = LLC_RESET_REASON_REMOTE;
163 case LLC_CONN_EV_TYPE_ACK_TMR:
164 case LLC_CONN_EV_TYPE_P_TMR:
165 case LLC_CONN_EV_TYPE_REJ_TMR:
166 case LLC_CONN_EV_TYPE_BUSY_TMR:
167 if (llc->retry_count > llc->n2) {
168 reason = LLC_RESET_REASON_LOCAL;
175 ev->ind_prim = LLC_RESET_PRIM;
180 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
182 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
185 ev->cfm_prim = LLC_RESET_PRIM;
189 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
192 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
194 if (LLC_PDU_IS_RSP(pdu) &&
195 LLC_PDU_TYPE_IS_I(pdu) &&
196 LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
197 llc_conn_ac_clear_remote_busy(sk, skb);
201 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
204 struct llc_sock *llc = llc_sk(sk);
206 if (llc->data_flag == 2)
207 del_timer(&llc->rej_sent_timer.timer);
211 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
214 struct llc_sock *llc = llc_sk(sk);
215 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
218 struct llc_sap *sap = llc->sap;
220 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
221 llc->daddr.lsap, LLC_PDU_CMD);
222 llc_pdu_init_as_disc_cmd(nskb, 1);
223 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
226 llc_conn_send_pdu(sk, nskb);
227 llc_conn_ac_set_p_flag_1(sk, skb);
236 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
239 struct llc_sock *llc = llc_sk(sk);
240 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
243 struct llc_sap *sap = llc->sap;
246 llc_pdu_decode_pf_bit(skb, &f_bit);
247 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
248 llc->daddr.lsap, LLC_PDU_RSP);
249 llc_pdu_init_as_dm_rsp(nskb, f_bit);
250 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
253 llc_conn_send_pdu(sk, nskb);
262 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
265 struct llc_sock *llc = llc_sk(sk);
266 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
269 struct llc_sap *sap = llc->sap;
271 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
272 llc->daddr.lsap, LLC_PDU_RSP);
273 llc_pdu_init_as_dm_rsp(nskb, 1);
274 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
277 llc_conn_send_pdu(sk, nskb);
286 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
290 struct sk_buff *nskb;
291 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
292 struct llc_sock *llc = llc_sk(sk);
294 llc->rx_pdu_hdr = *((u32 *)pdu);
295 if (LLC_PDU_IS_CMD(pdu))
296 llc_pdu_decode_pf_bit(skb, &f_bit);
299 nskb = llc_alloc_frame(llc->dev);
301 struct llc_sap *sap = llc->sap;
303 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
304 llc->daddr.lsap, LLC_PDU_RSP);
305 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
307 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
310 llc_conn_send_pdu(sk, nskb);
319 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
322 struct llc_sock *llc = llc_sk(sk);
323 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
326 struct llc_sap *sap = llc->sap;
327 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
329 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
330 llc->daddr.lsap, LLC_PDU_RSP);
331 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
333 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
336 llc_conn_send_pdu(sk, nskb);
345 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
349 struct sk_buff *nskb;
350 struct llc_sock *llc = llc_sk(sk);
352 llc_pdu_decode_pf_bit(skb, &f_bit);
353 nskb = llc_alloc_frame(llc->dev);
355 struct llc_sap *sap = llc->sap;
356 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
358 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
359 llc->daddr.lsap, LLC_PDU_RSP);
360 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
362 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
365 llc_conn_send_pdu(sk, nskb);
374 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
377 struct llc_sock *llc = llc_sk(sk);
378 struct llc_sap *sap = llc->sap;
380 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
381 llc->daddr.lsap, LLC_PDU_CMD);
382 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
383 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
385 llc_conn_send_pdu(sk, skb);
386 llc_conn_ac_inc_vs_by_1(sk, skb);
391 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
394 struct llc_sock *llc = llc_sk(sk);
395 struct llc_sap *sap = llc->sap;
397 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
398 llc->daddr.lsap, LLC_PDU_CMD);
399 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
400 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
402 llc_conn_send_pdu(sk, skb);
403 llc_conn_ac_inc_vs_by_1(sk, skb);
408 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
411 struct llc_sock *llc = llc_sk(sk);
412 struct llc_sap *sap = llc->sap;
414 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
415 llc->daddr.lsap, LLC_PDU_CMD);
416 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
417 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
419 llc_conn_send_pdu(sk, skb);
420 llc_conn_ac_inc_vs_by_1(sk, skb);
425 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
427 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
428 u8 nr = LLC_I_GET_NR(pdu);
430 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
434 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
438 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
440 struct llc_sock *llc = llc_sk(sk);
441 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
444 struct llc_sap *sap = llc->sap;
446 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
447 llc->daddr.lsap, LLC_PDU_RSP);
448 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
449 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
451 llc_conn_send_pdu(sk, nskb);
456 nr = LLC_I_GET_NR(pdu);
458 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
463 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
465 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
466 u8 nr = LLC_I_GET_NR(pdu);
468 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
472 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
475 struct llc_sock *llc = llc_sk(sk);
476 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
479 struct llc_sap *sap = llc->sap;
481 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
482 llc->daddr.lsap, LLC_PDU_CMD);
483 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
484 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
487 llc_conn_send_pdu(sk, nskb);
496 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
499 struct llc_sock *llc = llc_sk(sk);
500 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
503 struct llc_sap *sap = llc->sap;
505 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
506 llc->daddr.lsap, LLC_PDU_RSP);
507 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
508 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
511 llc_conn_send_pdu(sk, nskb);
520 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
523 struct llc_sock *llc = llc_sk(sk);
524 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
527 struct llc_sap *sap = llc->sap;
529 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
530 llc->daddr.lsap, LLC_PDU_RSP);
531 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
532 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
535 llc_conn_send_pdu(sk, nskb);
544 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
547 struct llc_sock *llc = llc_sk(sk);
548 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
551 struct llc_sap *sap = llc->sap;
553 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
554 llc->daddr.lsap, LLC_PDU_CMD);
555 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
556 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
559 llc_conn_send_pdu(sk, nskb);
568 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
571 struct llc_sock *llc = llc_sk(sk);
572 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
575 struct llc_sap *sap = llc->sap;
577 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
578 llc->daddr.lsap, LLC_PDU_RSP);
579 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
580 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
583 llc_conn_send_pdu(sk, nskb);
592 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
595 struct llc_sock *llc = llc_sk(sk);
596 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
599 struct llc_sap *sap = llc->sap;
601 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
602 llc->daddr.lsap, LLC_PDU_RSP);
603 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
604 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
607 llc_conn_send_pdu(sk, nskb);
616 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
618 struct llc_sock *llc = llc_sk(sk);
620 if (!llc->remote_busy_flag) {
621 llc->remote_busy_flag = 1;
622 mod_timer(&llc->busy_state_timer.timer,
623 jiffies + llc->busy_state_timer.expire);
628 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
631 struct llc_sock *llc = llc_sk(sk);
632 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
635 struct llc_sap *sap = llc->sap;
637 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
638 llc->daddr.lsap, LLC_PDU_RSP);
639 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
640 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
643 llc_conn_send_pdu(sk, nskb);
652 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
655 struct llc_sock *llc = llc_sk(sk);
656 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
659 struct llc_sap *sap = llc->sap;
661 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
662 llc->daddr.lsap, LLC_PDU_CMD);
663 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
664 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
667 llc_conn_send_pdu(sk, nskb);
676 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
679 struct llc_sock *llc = llc_sk(sk);
680 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
683 struct llc_sap *sap = llc->sap;
686 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
687 llc->daddr.lsap, LLC_PDU_RSP);
688 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
689 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
692 llc_conn_send_pdu(sk, nskb);
701 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
704 struct llc_sock *llc = llc_sk(sk);
705 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
708 struct llc_sap *sap = llc->sap;
710 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
711 llc->daddr.lsap, LLC_PDU_RSP);
712 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
713 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
716 llc_conn_send_pdu(sk, nskb);
725 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
728 struct llc_sock *llc = llc_sk(sk);
729 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
732 struct llc_sap *sap = llc->sap;
734 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
735 llc->daddr.lsap, LLC_PDU_RSP);
736 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
737 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
740 llc_conn_send_pdu(sk, nskb);
749 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
752 struct llc_sock *llc = llc_sk(sk);
753 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
756 struct llc_sap *sap = llc->sap;
758 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
759 llc->daddr.lsap, LLC_PDU_RSP);
760 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
761 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
764 llc_conn_send_pdu(sk, nskb);
773 void llc_conn_set_p_flag(struct sock *sk, u8 value)
775 int state_changed = llc_sk(sk)->p_flag && !value;
777 llc_sk(sk)->p_flag = value;
780 sk->sk_state_change(sk);
783 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
786 struct llc_sock *llc = llc_sk(sk);
787 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
790 struct llc_sap *sap = llc->sap;
791 u8 *dmac = llc->daddr.mac;
793 if (llc->dev->flags & IFF_LOOPBACK)
794 dmac = llc->dev->dev_addr;
795 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
796 llc->daddr.lsap, LLC_PDU_CMD);
797 llc_pdu_init_as_sabme_cmd(nskb, 1);
798 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
801 llc_conn_send_pdu(sk, nskb);
802 llc_conn_set_p_flag(sk, 1);
811 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
815 struct llc_sock *llc = llc_sk(sk);
816 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
818 llc_pdu_decode_pf_bit(skb, &f_bit);
820 struct llc_sap *sap = llc->sap;
822 nskb->dev = llc->dev;
823 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
824 llc->daddr.lsap, LLC_PDU_RSP);
825 llc_pdu_init_as_ua_rsp(nskb, f_bit);
826 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
829 llc_conn_send_pdu(sk, nskb);
838 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
840 llc_sk(sk)->s_flag = 0;
844 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
846 llc_sk(sk)->s_flag = 1;
850 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
852 struct llc_sock *llc = llc_sk(sk);
854 llc_conn_set_p_flag(sk, 1);
855 mod_timer(&llc->pf_cycle_timer.timer,
856 jiffies + llc->pf_cycle_timer.expire);
861 * llc_conn_ac_send_ack_if_needed - check if ack is needed
862 * @sk: current connection structure
863 * @skb: current event
865 * Checks number of received PDUs which have not been acknowledged, yet,
866 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
867 * sends an RR response as acknowledgement for them. Returns 0 for
868 * success, 1 otherwise.
870 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
873 struct llc_sock *llc = llc_sk(sk);
875 llc_pdu_decode_pf_bit(skb, &pf_bit);
876 llc->ack_pf |= pf_bit & 1;
877 if (!llc->ack_must_be_send) {
878 llc->first_pdu_Ns = llc->vR;
879 llc->ack_must_be_send = 1;
880 llc->ack_pf = pf_bit & 1;
882 if (((llc->vR - llc->first_pdu_Ns + 129) % 128) >= llc->npta) {
883 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
884 llc->ack_must_be_send = 0;
886 llc_conn_ac_inc_npta_value(sk, skb);
892 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
893 * @sk: current connection structure
894 * @skb: current event
896 * This action resets ack_must_be_send flag of given connection, this flag
897 * indicates if there is any PDU which has not been acknowledged yet.
898 * Returns 0 for success, 1 otherwise.
900 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
902 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
907 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
908 * @sk: current connection structure
909 * @skb: current event
911 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
912 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
913 * set to one if one PDU with p-bit set to one is received. Returns 0 for
914 * success, 1 otherwise.
916 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
920 struct llc_sock *llc = llc_sk(sk);
921 struct llc_sap *sap = llc->sap;
923 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
924 llc->daddr.lsap, LLC_PDU_RSP);
925 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
926 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
928 llc_conn_send_pdu(sk, skb);
929 llc_conn_ac_inc_vs_by_1(sk, skb);
935 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
936 * @sk: current connection structure.
937 * @skb: current event.
939 * This action sends an I-format PDU as acknowledge to received PDUs which
940 * have not been acknowledged, yet, if there is any. By using of this
941 * action number of acknowledgements decreases, this technic is called
942 * piggy backing. Returns 0 for success, 1 otherwise.
944 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
946 struct llc_sock *llc = llc_sk(sk);
948 if (llc->ack_must_be_send) {
949 llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
950 llc->ack_must_be_send = 0 ;
953 llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
958 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
959 * @sk: current connection structure.
960 * @skb: current event.
962 * This action sends an RR response with f-bit set to ack_pf flag as
963 * acknowledge to all received PDUs which have not been acknowledged, yet,
964 * if there is any. ack_pf flag indicates if a PDU has been received with
965 * p-bit set to one. Returns 0 for success, 1 otherwise.
967 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
971 struct llc_sock *llc = llc_sk(sk);
972 struct sk_buff *nskb = llc_alloc_frame(llc->dev);
975 struct llc_sap *sap = llc->sap;
977 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
978 llc->daddr.lsap, LLC_PDU_RSP);
979 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
980 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
983 llc_conn_send_pdu(sk, nskb);
993 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
994 * @sk: current connection structure.
995 * @skb: current event.
997 * After "inc_cntr" times calling of this action, "npta" increase by one.
998 * this action tries to make vale of "npta" greater as possible; number of
999 * acknowledgements decreases by increasing of "npta". Returns 0 for
1000 * success, 1 otherwise.
1002 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
1004 struct llc_sock *llc = llc_sk(sk);
1006 if (!llc->inc_cntr) {
1008 llc->dec_cntr = llc->inc_cntr = 2;
1010 if (llc->npta > 127)
1018 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1019 * @sk: current connection structure.
1020 * @skb: current event.
1022 * After receiving "dec_cntr" times RR command, this action decreases
1023 * "npta" by one. Returns 0 for success, 1 otherwise.
1025 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1027 struct llc_sock *llc = llc_sk(sk);
1029 if (!llc->connect_step && !llc->remote_busy_flag) {
1030 if (!llc->dec_step) {
1031 if (!llc->dec_cntr) {
1032 llc->inc_cntr = llc->dec_cntr = 2;
1034 llc->npta = llc->npta - 1;
1039 llc->connect_step = 0 ;
1044 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1045 * @sk: current connection structure.
1046 * @skb: current event.
1048 * After receiving "dec_cntr" times RNR command, this action decreases
1049 * "npta" by one. Returns 0 for success, 1 otherwise.
1051 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1053 struct llc_sock *llc = llc_sk(sk);
1055 if (llc->remote_busy_flag)
1056 if (!llc->dec_step) {
1057 if (!llc->dec_cntr) {
1058 llc->inc_cntr = llc->dec_cntr = 2;
1068 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1069 * @sk: current connection structure.
1070 * @skb: current event.
1072 * After receiving of a REJ command or response, transmit window size is
1073 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1074 * success, 1 otherwise.
1076 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1078 struct llc_sock *llc = llc_sk(sk);
1079 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1081 llc->k -= unacked_pdu;
1088 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1089 * @sk: current connection structure.
1090 * @skb: current event.
1092 * After receiving an RR response with f-bit set to one, transmit window
1093 * size is increased by one. Returns 0 for success, 1 otherwise.
1095 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1097 struct llc_sock *llc = llc_sk(sk);
1105 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1107 struct llc_sock *llc = llc_sk(sk);
1109 del_timer(&llc->pf_cycle_timer.timer);
1110 del_timer(&llc->ack_timer.timer);
1111 del_timer(&llc->rej_sent_timer.timer);
1112 del_timer(&llc->busy_state_timer.timer);
1113 llc->ack_must_be_send = 0;
1118 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1120 struct llc_sock *llc = llc_sk(sk);
1122 del_timer(&llc->rej_sent_timer.timer);
1123 del_timer(&llc->pf_cycle_timer.timer);
1124 del_timer(&llc->busy_state_timer.timer);
1125 llc->ack_must_be_send = 0;
1130 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1132 struct llc_sock *llc = llc_sk(sk);
1134 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1138 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1140 struct llc_sock *llc = llc_sk(sk);
1142 mod_timer(&llc->rej_sent_timer.timer,
1143 jiffies + llc->rej_sent_timer.expire);
1147 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1148 struct sk_buff *skb)
1150 struct llc_sock *llc = llc_sk(sk);
1152 if (!timer_pending(&llc->ack_timer.timer))
1153 mod_timer(&llc->ack_timer.timer,
1154 jiffies + llc->ack_timer.expire);
1158 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1160 del_timer(&llc_sk(sk)->ack_timer.timer);
1164 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1166 struct llc_sock *llc = llc_sk(sk);
1168 del_timer(&llc->pf_cycle_timer.timer);
1169 llc_conn_set_p_flag(sk, 0);
1173 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1175 del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1179 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1183 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1184 struct llc_sock *llc = llc_sk(sk);
1186 llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1187 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1188 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1189 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1190 llc->retry_count = 0;
1191 del_timer(&llc->ack_timer.timer);
1192 if (llc->failed_data_req) {
1193 /* already, we did not accept data from upper layer
1194 * (tx_window full or unacceptable state). Now, we
1195 * can send data and must inform to upper layer.
1197 llc->failed_data_req = 0;
1198 llc_conn_ac_data_confirm(sk, skb);
1201 mod_timer(&llc->ack_timer.timer,
1202 jiffies + llc->ack_timer.expire);
1203 } else if (llc->failed_data_req) {
1206 llc_pdu_decode_pf_bit(skb, &f_bit);
1208 llc->failed_data_req = 0;
1209 llc_conn_ac_data_confirm(sk, skb);
1215 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1217 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1219 if (LLC_PDU_IS_RSP(pdu)) {
1222 llc_pdu_decode_pf_bit(skb, &f_bit);
1224 llc_conn_set_p_flag(sk, 0);
1225 llc_conn_ac_stop_p_timer(sk, skb);
1231 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1233 llc_sk(sk)->data_flag = 2;
1237 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1239 llc_sk(sk)->data_flag = 0;
1243 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1245 llc_sk(sk)->data_flag = 1;
1249 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1250 struct sk_buff *skb)
1252 if (!llc_sk(sk)->data_flag)
1253 llc_sk(sk)->data_flag = 1;
1257 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1259 llc_conn_set_p_flag(sk, 0);
1263 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1265 llc_conn_set_p_flag(sk, 1);
1269 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1271 llc_sk(sk)->remote_busy_flag = 0;
1275 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1277 llc_sk(sk)->cause_flag = 0;
1281 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1283 llc_sk(sk)->cause_flag = 1;
1287 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1289 llc_sk(sk)->retry_count = 0;
1293 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1295 llc_sk(sk)->retry_count++;
1299 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1305 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1307 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1311 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1317 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1319 llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1323 int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1325 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128;
1329 static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
1331 struct sock *sk = (struct sock *)timeout_data;
1332 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1336 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1338 skb_set_owner_r(skb, sk);
1340 llc_process_tmr_ev(sk, skb);
1345 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1347 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
1350 void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1352 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
1355 void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1357 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
1360 void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1362 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
1365 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1367 llc_sk(sk)->X = llc_sk(sk)->vS;
1368 llc_conn_ac_set_vs_nr(sk, skb);
1372 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1374 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1375 u8 nr = PDU_SUPV_GET_Nr(pdu);
1377 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1378 llc_conn_ac_set_vs_nr(sk, skb);
1383 * Non-standard actions; these not contained in IEEE specification; for
1387 * llc_conn_disc - removes connection from SAP list and frees it
1388 * @sk: closed connection
1389 * @skb: occurred event
1391 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1393 /* FIXME: this thing seems to want to die */
1398 * llc_conn_reset - resets connection
1399 * @sk : reseting connection.
1400 * @skb: occurred event.
1402 * Stop all timers, empty all queues and reset all flags.
1404 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1411 * llc_circular_between - designates that b is between a and c or not
1413 * @b: element to see if is between a and b
1416 * This function designates that b is between a and c or not (for example,
1417 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1420 u8 llc_circular_between(u8 a, u8 b, u8 c)
1428 * llc_process_tmr_ev - timer backend
1429 * @sk: active connection
1430 * @skb: occurred event
1432 * This function is called from timer callback functions. When connection
1433 * is busy (during sending a data frame) timer expiration event must be
1434 * queued. Otherwise this event can be sent to connection state machine.
1435 * Queued events will process by llc_backlog_rcv function after sending
1438 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1440 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1441 printk(KERN_WARNING "%s: timer called on closed connection\n",
1445 if (!sock_owned_by_user(sk))
1446 llc_conn_state_process(sk, skb);
1448 llc_set_backlog_type(skb, LLC_EVENT);
1449 sk_add_backlog(sk, skb);