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
;
83 int llc_conn_ac_conn_confirm(struct sock
*sk
, struct sk_buff
*skb
)
85 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
87 ev
->cfm_prim
= LLC_CONN_PRIM
;
91 static int llc_conn_ac_data_confirm(struct sock
*sk
, struct sk_buff
*skb
)
93 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
95 ev
->cfm_prim
= LLC_DATA_PRIM
;
99 int llc_conn_ac_data_ind(struct sock
*sk
, struct sk_buff
*skb
)
101 llc_conn_rtn_pdu(sk
, skb
);
105 int llc_conn_ac_disc_ind(struct sock
*sk
, struct sk_buff
*skb
)
107 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
111 if (ev
->type
== LLC_CONN_EV_TYPE_PDU
) {
112 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
114 if (LLC_PDU_IS_RSP(pdu
) &&
115 LLC_PDU_TYPE_IS_U(pdu
) &&
116 LLC_U_PDU_RSP(pdu
) == LLC_2_PDU_RSP_DM
)
117 reason
= LLC_DISC_REASON_RX_DM_RSP_PDU
;
118 else if (LLC_PDU_IS_CMD(pdu
) &&
119 LLC_PDU_TYPE_IS_U(pdu
) &&
120 LLC_U_PDU_CMD(pdu
) == LLC_2_PDU_CMD_DISC
)
121 reason
= LLC_DISC_REASON_RX_DISC_CMD_PDU
;
122 } else if (ev
->type
== LLC_CONN_EV_TYPE_ACK_TMR
)
123 reason
= LLC_DISC_REASON_ACK_TMR_EXP
;
128 ev
->ind_prim
= LLC_DISC_PRIM
;
133 int llc_conn_ac_disc_confirm(struct sock
*sk
, struct sk_buff
*skb
)
135 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
137 ev
->reason
= ev
->status
;
138 ev
->cfm_prim
= LLC_DISC_PRIM
;
142 int llc_conn_ac_rst_ind(struct sock
*sk
, struct sk_buff
*skb
)
146 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
147 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
148 struct llc_sock
*llc
= llc_sk(sk
);
151 case LLC_CONN_EV_TYPE_PDU
:
152 if (LLC_PDU_IS_RSP(pdu
) &&
153 LLC_PDU_TYPE_IS_U(pdu
) &&
154 LLC_U_PDU_RSP(pdu
) == LLC_2_PDU_RSP_FRMR
) {
155 reason
= LLC_RESET_REASON_LOCAL
;
157 } else if (LLC_PDU_IS_CMD(pdu
) &&
158 LLC_PDU_TYPE_IS_U(pdu
) &&
159 LLC_U_PDU_CMD(pdu
) == LLC_2_PDU_CMD_SABME
) {
160 reason
= LLC_RESET_REASON_REMOTE
;
164 case LLC_CONN_EV_TYPE_ACK_TMR
:
165 case LLC_CONN_EV_TYPE_P_TMR
:
166 case LLC_CONN_EV_TYPE_REJ_TMR
:
167 case LLC_CONN_EV_TYPE_BUSY_TMR
:
168 if (llc
->retry_count
> llc
->n2
) {
169 reason
= LLC_RESET_REASON_LOCAL
;
176 ev
->ind_prim
= LLC_RESET_PRIM
;
181 int llc_conn_ac_rst_confirm(struct sock
*sk
, struct sk_buff
*skb
)
183 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
186 ev
->cfm_prim
= LLC_RESET_PRIM
;
190 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock
*sk
,
193 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
195 if (LLC_PDU_IS_RSP(pdu
) &&
196 LLC_PDU_TYPE_IS_I(pdu
) &&
197 LLC_I_PF_IS_1(pdu
) && llc_sk(sk
)->ack_pf
)
198 llc_conn_ac_clear_remote_busy(sk
, skb
);
202 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock
*sk
,
205 struct llc_sock
*llc
= llc_sk(sk
);
207 if (llc
->data_flag
== 2)
208 del_timer(&llc
->rej_sent_timer
.timer
);
212 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock
*sk
, struct sk_buff
*skb
)
215 struct llc_sock
*llc
= llc_sk(sk
);
216 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
219 struct llc_sap
*sap
= llc
->sap
;
221 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
222 llc
->daddr
.lsap
, LLC_PDU_CMD
);
223 llc_pdu_init_as_disc_cmd(nskb
, 1);
224 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
227 llc_conn_send_pdu(sk
, nskb
);
228 llc_conn_ac_set_p_flag_1(sk
, skb
);
237 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock
*sk
, struct sk_buff
*skb
)
240 struct llc_sock
*llc
= llc_sk(sk
);
241 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
244 struct llc_sap
*sap
= llc
->sap
;
247 llc_pdu_decode_pf_bit(skb
, &f_bit
);
248 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
249 llc
->daddr
.lsap
, LLC_PDU_RSP
);
250 llc_pdu_init_as_dm_rsp(nskb
, f_bit
);
251 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
254 llc_conn_send_pdu(sk
, nskb
);
263 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
266 struct llc_sock
*llc
= llc_sk(sk
);
267 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
270 struct llc_sap
*sap
= llc
->sap
;
272 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
273 llc
->daddr
.lsap
, LLC_PDU_RSP
);
274 llc_pdu_init_as_dm_rsp(nskb
, 1);
275 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
278 llc_conn_send_pdu(sk
, nskb
);
287 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock
*sk
, struct sk_buff
*skb
)
291 struct sk_buff
*nskb
;
292 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
293 struct llc_sock
*llc
= llc_sk(sk
);
295 llc
->rx_pdu_hdr
= *((u32
*)pdu
);
296 if (LLC_PDU_IS_CMD(pdu
))
297 llc_pdu_decode_pf_bit(skb
, &f_bit
);
300 nskb
= llc_alloc_frame(llc
->dev
);
302 struct llc_sap
*sap
= llc
->sap
;
304 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
305 llc
->daddr
.lsap
, LLC_PDU_RSP
);
306 llc_pdu_init_as_frmr_rsp(nskb
, pdu
, f_bit
, llc
->vS
,
308 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
311 llc_conn_send_pdu(sk
, nskb
);
320 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock
*sk
, struct sk_buff
*skb
)
323 struct llc_sock
*llc
= llc_sk(sk
);
324 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
327 struct llc_sap
*sap
= llc
->sap
;
328 struct llc_pdu_sn
*pdu
= (struct llc_pdu_sn
*)&llc
->rx_pdu_hdr
;
330 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
331 llc
->daddr
.lsap
, LLC_PDU_RSP
);
332 llc_pdu_init_as_frmr_rsp(nskb
, pdu
, 0, llc
->vS
,
334 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
337 llc_conn_send_pdu(sk
, nskb
);
346 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock
*sk
, struct sk_buff
*skb
)
350 struct sk_buff
*nskb
;
351 struct llc_sock
*llc
= llc_sk(sk
);
353 llc_pdu_decode_pf_bit(skb
, &f_bit
);
354 nskb
= llc_alloc_frame(llc
->dev
);
356 struct llc_sap
*sap
= llc
->sap
;
357 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
359 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
360 llc
->daddr
.lsap
, LLC_PDU_RSP
);
361 llc_pdu_init_as_frmr_rsp(nskb
, pdu
, f_bit
, llc
->vS
,
363 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
366 llc_conn_send_pdu(sk
, nskb
);
375 int llc_conn_ac_send_i_cmd_p_set_1(struct sock
*sk
, struct sk_buff
*skb
)
378 struct llc_sock
*llc
= llc_sk(sk
);
379 struct llc_sap
*sap
= llc
->sap
;
381 llc_pdu_header_init(skb
, LLC_PDU_TYPE_I
, sap
->laddr
.lsap
,
382 llc
->daddr
.lsap
, LLC_PDU_CMD
);
383 llc_pdu_init_as_i_cmd(skb
, 1, llc
->vS
, llc
->vR
);
384 rc
= llc_mac_hdr_init(skb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
386 llc_conn_send_pdu(sk
, skb
);
387 llc_conn_ac_inc_vs_by_1(sk
, skb
);
392 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock
*sk
, struct sk_buff
*skb
)
395 struct llc_sock
*llc
= llc_sk(sk
);
396 struct llc_sap
*sap
= llc
->sap
;
398 llc_pdu_header_init(skb
, LLC_PDU_TYPE_I
, sap
->laddr
.lsap
,
399 llc
->daddr
.lsap
, LLC_PDU_CMD
);
400 llc_pdu_init_as_i_cmd(skb
, 0, llc
->vS
, llc
->vR
);
401 rc
= llc_mac_hdr_init(skb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
403 llc_conn_send_pdu(sk
, skb
);
404 llc_conn_ac_inc_vs_by_1(sk
, skb
);
409 int llc_conn_ac_send_i_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
412 struct llc_sock
*llc
= llc_sk(sk
);
413 struct llc_sap
*sap
= llc
->sap
;
415 llc_pdu_header_init(skb
, LLC_PDU_TYPE_I
, sap
->laddr
.lsap
,
416 llc
->daddr
.lsap
, LLC_PDU_CMD
);
417 llc_pdu_init_as_i_cmd(skb
, 0, llc
->vS
, llc
->vR
);
418 rc
= llc_mac_hdr_init(skb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
420 llc_conn_send_pdu(sk
, skb
);
421 llc_conn_ac_inc_vs_by_1(sk
, skb
);
426 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
428 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
429 u8 nr
= LLC_I_GET_NR(pdu
);
431 llc_conn_resend_i_pdu_as_cmd(sk
, nr
, 0);
435 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock
*sk
,
439 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
441 struct llc_sock
*llc
= llc_sk(sk
);
442 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
445 struct llc_sap
*sap
= llc
->sap
;
447 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
448 llc
->daddr
.lsap
, LLC_PDU_RSP
);
449 llc_pdu_init_as_rr_rsp(nskb
, 0, llc
->vR
);
450 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
452 llc_conn_send_pdu(sk
, nskb
);
457 nr
= LLC_I_GET_NR(pdu
);
459 llc_conn_resend_i_pdu_as_cmd(sk
, nr
, 0);
464 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
466 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
467 u8 nr
= LLC_I_GET_NR(pdu
);
469 llc_conn_resend_i_pdu_as_rsp(sk
, nr
, 1);
473 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock
*sk
, struct sk_buff
*skb
)
476 struct llc_sock
*llc
= llc_sk(sk
);
477 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
480 struct llc_sap
*sap
= llc
->sap
;
482 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
483 llc
->daddr
.lsap
, LLC_PDU_CMD
);
484 llc_pdu_init_as_rej_cmd(nskb
, 1, llc
->vR
);
485 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
488 llc_conn_send_pdu(sk
, nskb
);
497 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
500 struct llc_sock
*llc
= llc_sk(sk
);
501 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
504 struct llc_sap
*sap
= llc
->sap
;
506 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
507 llc
->daddr
.lsap
, LLC_PDU_RSP
);
508 llc_pdu_init_as_rej_rsp(nskb
, 1, llc
->vR
);
509 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
512 llc_conn_send_pdu(sk
, nskb
);
521 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
524 struct llc_sock
*llc
= llc_sk(sk
);
525 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
528 struct llc_sap
*sap
= llc
->sap
;
530 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
531 llc
->daddr
.lsap
, LLC_PDU_RSP
);
532 llc_pdu_init_as_rej_rsp(nskb
, 0, llc
->vR
);
533 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
536 llc_conn_send_pdu(sk
, nskb
);
545 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock
*sk
, struct sk_buff
*skb
)
548 struct llc_sock
*llc
= llc_sk(sk
);
549 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
552 struct llc_sap
*sap
= llc
->sap
;
554 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
555 llc
->daddr
.lsap
, LLC_PDU_CMD
);
556 llc_pdu_init_as_rnr_cmd(nskb
, 1, llc
->vR
);
557 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
560 llc_conn_send_pdu(sk
, nskb
);
569 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
572 struct llc_sock
*llc
= llc_sk(sk
);
573 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
576 struct llc_sap
*sap
= llc
->sap
;
578 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
579 llc
->daddr
.lsap
, LLC_PDU_RSP
);
580 llc_pdu_init_as_rnr_rsp(nskb
, 1, llc
->vR
);
581 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
584 llc_conn_send_pdu(sk
, nskb
);
593 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
596 struct llc_sock
*llc
= llc_sk(sk
);
597 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
600 struct llc_sap
*sap
= llc
->sap
;
602 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
603 llc
->daddr
.lsap
, LLC_PDU_RSP
);
604 llc_pdu_init_as_rnr_rsp(nskb
, 0, llc
->vR
);
605 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
608 llc_conn_send_pdu(sk
, nskb
);
617 int llc_conn_ac_set_remote_busy(struct sock
*sk
, struct sk_buff
*skb
)
619 struct llc_sock
*llc
= llc_sk(sk
);
621 if (!llc
->remote_busy_flag
) {
622 llc
->remote_busy_flag
= 1;
623 mod_timer(&llc
->busy_state_timer
.timer
,
624 jiffies
+ llc
->busy_state_timer
.expire
);
629 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
632 struct llc_sock
*llc
= llc_sk(sk
);
633 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
636 struct llc_sap
*sap
= llc
->sap
;
638 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
639 llc
->daddr
.lsap
, LLC_PDU_RSP
);
640 llc_pdu_init_as_rnr_rsp(nskb
, 0, llc
->vR
);
641 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
644 llc_conn_send_pdu(sk
, nskb
);
653 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock
*sk
, struct sk_buff
*skb
)
656 struct llc_sock
*llc
= llc_sk(sk
);
657 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
660 struct llc_sap
*sap
= llc
->sap
;
662 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
663 llc
->daddr
.lsap
, LLC_PDU_CMD
);
664 llc_pdu_init_as_rr_cmd(nskb
, 1, llc
->vR
);
665 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
668 llc_conn_send_pdu(sk
, nskb
);
677 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
680 struct llc_sock
*llc
= llc_sk(sk
);
681 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
684 struct llc_sap
*sap
= llc
->sap
;
687 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
688 llc
->daddr
.lsap
, LLC_PDU_RSP
);
689 llc_pdu_init_as_rr_rsp(nskb
, f_bit
, llc
->vR
);
690 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
693 llc_conn_send_pdu(sk
, nskb
);
702 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock
*sk
, struct sk_buff
*skb
)
705 struct llc_sock
*llc
= llc_sk(sk
);
706 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
709 struct llc_sap
*sap
= llc
->sap
;
711 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
712 llc
->daddr
.lsap
, LLC_PDU_RSP
);
713 llc_pdu_init_as_rr_rsp(nskb
, 1, llc
->vR
);
714 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
717 llc_conn_send_pdu(sk
, nskb
);
726 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
729 struct llc_sock
*llc
= llc_sk(sk
);
730 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
733 struct llc_sap
*sap
= llc
->sap
;
735 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
736 llc
->daddr
.lsap
, LLC_PDU_RSP
);
737 llc_pdu_init_as_rr_rsp(nskb
, 0, llc
->vR
);
738 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
741 llc_conn_send_pdu(sk
, nskb
);
750 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock
*sk
, struct sk_buff
*skb
)
753 struct llc_sock
*llc
= llc_sk(sk
);
754 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
757 struct llc_sap
*sap
= llc
->sap
;
759 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
760 llc
->daddr
.lsap
, LLC_PDU_RSP
);
761 llc_pdu_init_as_rr_rsp(nskb
, 0, llc
->vR
);
762 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
765 llc_conn_send_pdu(sk
, nskb
);
774 void llc_conn_set_p_flag(struct sock
*sk
, u8 value
)
776 int state_changed
= llc_sk(sk
)->p_flag
&& !value
;
778 llc_sk(sk
)->p_flag
= value
;
781 sk
->sk_state_change(sk
);
784 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock
*sk
, struct sk_buff
*skb
)
787 struct llc_sock
*llc
= llc_sk(sk
);
788 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
791 struct llc_sap
*sap
= llc
->sap
;
792 u8
*dmac
= llc
->daddr
.mac
;
794 if (llc
->dev
->flags
& IFF_LOOPBACK
)
795 dmac
= llc
->dev
->dev_addr
;
796 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
797 llc
->daddr
.lsap
, LLC_PDU_CMD
);
798 llc_pdu_init_as_sabme_cmd(nskb
, 1);
799 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, dmac
);
802 llc_conn_send_pdu(sk
, nskb
);
803 llc_conn_set_p_flag(sk
, 1);
812 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock
*sk
, struct sk_buff
*skb
)
816 struct llc_sock
*llc
= llc_sk(sk
);
817 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
819 llc_pdu_decode_pf_bit(skb
, &f_bit
);
821 struct llc_sap
*sap
= llc
->sap
;
823 nskb
->dev
= llc
->dev
;
824 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_U
, sap
->laddr
.lsap
,
825 llc
->daddr
.lsap
, LLC_PDU_RSP
);
826 llc_pdu_init_as_ua_rsp(nskb
, f_bit
);
827 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
830 llc_conn_send_pdu(sk
, nskb
);
839 int llc_conn_ac_set_s_flag_0(struct sock
*sk
, struct sk_buff
*skb
)
841 llc_sk(sk
)->s_flag
= 0;
845 int llc_conn_ac_set_s_flag_1(struct sock
*sk
, struct sk_buff
*skb
)
847 llc_sk(sk
)->s_flag
= 1;
851 int llc_conn_ac_start_p_timer(struct sock
*sk
, struct sk_buff
*skb
)
853 struct llc_sock
*llc
= llc_sk(sk
);
855 llc_conn_set_p_flag(sk
, 1);
856 mod_timer(&llc
->pf_cycle_timer
.timer
,
857 jiffies
+ llc
->pf_cycle_timer
.expire
);
862 * llc_conn_ac_send_ack_if_needed - check if ack is needed
863 * @sk: current connection structure
864 * @skb: current event
866 * Checks number of received PDUs which have not been acknowledged, yet,
867 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
868 * sends an RR response as acknowledgement for them. Returns 0 for
869 * success, 1 otherwise.
871 int llc_conn_ac_send_ack_if_needed(struct sock
*sk
, struct sk_buff
*skb
)
874 struct llc_sock
*llc
= llc_sk(sk
);
876 llc_pdu_decode_pf_bit(skb
, &pf_bit
);
877 llc
->ack_pf
|= pf_bit
& 1;
878 if (!llc
->ack_must_be_send
) {
879 llc
->first_pdu_Ns
= llc
->vR
;
880 llc
->ack_must_be_send
= 1;
881 llc
->ack_pf
= pf_bit
& 1;
883 if (((llc
->vR
- llc
->first_pdu_Ns
+ 129) % 128) >= llc
->npta
) {
884 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk
, skb
);
885 llc
->ack_must_be_send
= 0;
887 llc_conn_ac_inc_npta_value(sk
, skb
);
893 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
894 * @sk: current connection structure
895 * @skb: current event
897 * This action resets ack_must_be_send flag of given connection, this flag
898 * indicates if there is any PDU which has not been acknowledged yet.
899 * Returns 0 for success, 1 otherwise.
901 int llc_conn_ac_rst_sendack_flag(struct sock
*sk
, struct sk_buff
*skb
)
903 llc_sk(sk
)->ack_must_be_send
= llc_sk(sk
)->ack_pf
= 0;
908 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
909 * @sk: current connection structure
910 * @skb: current event
912 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
913 * all received PDUs which have not been acknowledged, yet. ack_pf flag is
914 * set to one if one PDU with p-bit set to one is received. Returns 0 for
915 * success, 1 otherwise.
917 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock
*sk
,
921 struct llc_sock
*llc
= llc_sk(sk
);
922 struct llc_sap
*sap
= llc
->sap
;
924 llc_pdu_header_init(skb
, LLC_PDU_TYPE_I
, sap
->laddr
.lsap
,
925 llc
->daddr
.lsap
, LLC_PDU_RSP
);
926 llc_pdu_init_as_i_cmd(skb
, llc
->ack_pf
, llc
->vS
, llc
->vR
);
927 rc
= llc_mac_hdr_init(skb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
929 llc_conn_send_pdu(sk
, skb
);
930 llc_conn_ac_inc_vs_by_1(sk
, skb
);
936 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
937 * @sk: current connection structure.
938 * @skb: current event.
940 * This action sends an I-format PDU as acknowledge to received PDUs which
941 * have not been acknowledged, yet, if there is any. By using of this
942 * action number of acknowledgements decreases, this technic is called
943 * piggy backing. Returns 0 for success, 1 otherwise.
945 int llc_conn_ac_send_i_as_ack(struct sock
*sk
, struct sk_buff
*skb
)
947 struct llc_sock
*llc
= llc_sk(sk
);
949 if (llc
->ack_must_be_send
) {
950 llc_conn_ac_send_i_rsp_f_set_ackpf(sk
, skb
);
951 llc
->ack_must_be_send
= 0 ;
954 llc_conn_ac_send_i_cmd_p_set_0(sk
, skb
);
959 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
960 * @sk: current connection structure.
961 * @skb: current event.
963 * This action sends an RR response with f-bit set to ack_pf flag as
964 * acknowledge to all received PDUs which have not been acknowledged, yet,
965 * if there is any. ack_pf flag indicates if a PDU has been received with
966 * p-bit set to one. Returns 0 for success, 1 otherwise.
968 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock
*sk
,
972 struct llc_sock
*llc
= llc_sk(sk
);
973 struct sk_buff
*nskb
= llc_alloc_frame(llc
->dev
);
976 struct llc_sap
*sap
= llc
->sap
;
978 llc_pdu_header_init(nskb
, LLC_PDU_TYPE_S
, sap
->laddr
.lsap
,
979 llc
->daddr
.lsap
, LLC_PDU_RSP
);
980 llc_pdu_init_as_rr_rsp(nskb
, llc
->ack_pf
, llc
->vR
);
981 rc
= llc_mac_hdr_init(nskb
, llc
->dev
->dev_addr
, llc
->daddr
.mac
);
984 llc_conn_send_pdu(sk
, nskb
);
994 * llc_conn_ac_inc_npta_value - tries to make value of npta greater
995 * @sk: current connection structure.
996 * @skb: current event.
998 * After "inc_cntr" times calling of this action, "npta" increase by one.
999 * this action tries to make vale of "npta" greater as possible; number of
1000 * acknowledgements decreases by increasing of "npta". Returns 0 for
1001 * success, 1 otherwise.
1003 static int llc_conn_ac_inc_npta_value(struct sock
*sk
, struct sk_buff
*skb
)
1005 struct llc_sock
*llc
= llc_sk(sk
);
1007 if (!llc
->inc_cntr
) {
1009 llc
->dec_cntr
= llc
->inc_cntr
= 2;
1011 if (llc
->npta
> 127)
1019 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1020 * @sk: current connection structure.
1021 * @skb: current event.
1023 * After receiving "dec_cntr" times RR command, this action decreases
1024 * "npta" by one. Returns 0 for success, 1 otherwise.
1026 int llc_conn_ac_adjust_npta_by_rr(struct sock
*sk
, struct sk_buff
*skb
)
1028 struct llc_sock
*llc
= llc_sk(sk
);
1030 if (!llc
->connect_step
&& !llc
->remote_busy_flag
) {
1031 if (!llc
->dec_step
) {
1032 if (!llc
->dec_cntr
) {
1033 llc
->inc_cntr
= llc
->dec_cntr
= 2;
1035 llc
->npta
= llc
->npta
- 1;
1040 llc
->connect_step
= 0 ;
1045 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1046 * @sk: current connection structure.
1047 * @skb: current event.
1049 * After receiving "dec_cntr" times RNR command, this action decreases
1050 * "npta" by one. Returns 0 for success, 1 otherwise.
1052 int llc_conn_ac_adjust_npta_by_rnr(struct sock
*sk
, struct sk_buff
*skb
)
1054 struct llc_sock
*llc
= llc_sk(sk
);
1056 if (llc
->remote_busy_flag
)
1057 if (!llc
->dec_step
) {
1058 if (!llc
->dec_cntr
) {
1059 llc
->inc_cntr
= llc
->dec_cntr
= 2;
1069 * llc_conn_ac_dec_tx_win_size - decreases tx window size
1070 * @sk: current connection structure.
1071 * @skb: current event.
1073 * After receiving of a REJ command or response, transmit window size is
1074 * decreased by number of PDUs which are outstanding yet. Returns 0 for
1075 * success, 1 otherwise.
1077 int llc_conn_ac_dec_tx_win_size(struct sock
*sk
, struct sk_buff
*skb
)
1079 struct llc_sock
*llc
= llc_sk(sk
);
1080 u8 unacked_pdu
= skb_queue_len(&llc
->pdu_unack_q
);
1082 llc
->k
-= unacked_pdu
;
1089 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1090 * @sk: current connection structure.
1091 * @skb: current event.
1093 * After receiving an RR response with f-bit set to one, transmit window
1094 * size is increased by one. Returns 0 for success, 1 otherwise.
1096 int llc_conn_ac_inc_tx_win_size(struct sock
*sk
, struct sk_buff
*skb
)
1098 struct llc_sock
*llc
= llc_sk(sk
);
1106 int llc_conn_ac_stop_all_timers(struct sock
*sk
, struct sk_buff
*skb
)
1108 struct llc_sock
*llc
= llc_sk(sk
);
1110 del_timer(&llc
->pf_cycle_timer
.timer
);
1111 del_timer(&llc
->ack_timer
.timer
);
1112 del_timer(&llc
->rej_sent_timer
.timer
);
1113 del_timer(&llc
->busy_state_timer
.timer
);
1114 llc
->ack_must_be_send
= 0;
1119 int llc_conn_ac_stop_other_timers(struct sock
*sk
, struct sk_buff
*skb
)
1121 struct llc_sock
*llc
= llc_sk(sk
);
1123 del_timer(&llc
->rej_sent_timer
.timer
);
1124 del_timer(&llc
->pf_cycle_timer
.timer
);
1125 del_timer(&llc
->busy_state_timer
.timer
);
1126 llc
->ack_must_be_send
= 0;
1131 int llc_conn_ac_start_ack_timer(struct sock
*sk
, struct sk_buff
*skb
)
1133 struct llc_sock
*llc
= llc_sk(sk
);
1135 mod_timer(&llc
->ack_timer
.timer
, jiffies
+ llc
->ack_timer
.expire
);
1139 int llc_conn_ac_start_rej_timer(struct sock
*sk
, struct sk_buff
*skb
)
1141 struct llc_sock
*llc
= llc_sk(sk
);
1143 mod_timer(&llc
->rej_sent_timer
.timer
,
1144 jiffies
+ llc
->rej_sent_timer
.expire
);
1148 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock
*sk
,
1149 struct sk_buff
*skb
)
1151 struct llc_sock
*llc
= llc_sk(sk
);
1153 if (!timer_pending(&llc
->ack_timer
.timer
))
1154 mod_timer(&llc
->ack_timer
.timer
,
1155 jiffies
+ llc
->ack_timer
.expire
);
1159 int llc_conn_ac_stop_ack_timer(struct sock
*sk
, struct sk_buff
*skb
)
1161 del_timer(&llc_sk(sk
)->ack_timer
.timer
);
1165 int llc_conn_ac_stop_p_timer(struct sock
*sk
, struct sk_buff
*skb
)
1167 struct llc_sock
*llc
= llc_sk(sk
);
1169 del_timer(&llc
->pf_cycle_timer
.timer
);
1170 llc_conn_set_p_flag(sk
, 0);
1174 int llc_conn_ac_stop_rej_timer(struct sock
*sk
, struct sk_buff
*skb
)
1176 del_timer(&llc_sk(sk
)->rej_sent_timer
.timer
);
1180 int llc_conn_ac_upd_nr_received(struct sock
*sk
, struct sk_buff
*skb
)
1184 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
1185 struct llc_sock
*llc
= llc_sk(sk
);
1187 llc
->last_nr
= PDU_SUPV_GET_Nr(pdu
);
1188 acked
= llc_conn_remove_acked_pdus(sk
, llc
->last_nr
, &unacked
);
1189 /* On loopback we don't queue I frames in unack_pdu_q queue. */
1190 if (acked
> 0 || (llc
->dev
->flags
& IFF_LOOPBACK
)) {
1191 llc
->retry_count
= 0;
1192 del_timer(&llc
->ack_timer
.timer
);
1193 if (llc
->failed_data_req
) {
1194 /* already, we did not accept data from upper layer
1195 * (tx_window full or unacceptable state). Now, we
1196 * can send data and must inform to upper layer.
1198 llc
->failed_data_req
= 0;
1199 llc_conn_ac_data_confirm(sk
, skb
);
1202 mod_timer(&llc
->ack_timer
.timer
,
1203 jiffies
+ llc
->ack_timer
.expire
);
1204 } else if (llc
->failed_data_req
) {
1207 llc_pdu_decode_pf_bit(skb
, &f_bit
);
1209 llc
->failed_data_req
= 0;
1210 llc_conn_ac_data_confirm(sk
, skb
);
1216 int llc_conn_ac_upd_p_flag(struct sock
*sk
, struct sk_buff
*skb
)
1218 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
1220 if (LLC_PDU_IS_RSP(pdu
)) {
1223 llc_pdu_decode_pf_bit(skb
, &f_bit
);
1225 llc_conn_set_p_flag(sk
, 0);
1226 llc_conn_ac_stop_p_timer(sk
, skb
);
1232 int llc_conn_ac_set_data_flag_2(struct sock
*sk
, struct sk_buff
*skb
)
1234 llc_sk(sk
)->data_flag
= 2;
1238 int llc_conn_ac_set_data_flag_0(struct sock
*sk
, struct sk_buff
*skb
)
1240 llc_sk(sk
)->data_flag
= 0;
1244 int llc_conn_ac_set_data_flag_1(struct sock
*sk
, struct sk_buff
*skb
)
1246 llc_sk(sk
)->data_flag
= 1;
1250 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock
*sk
,
1251 struct sk_buff
*skb
)
1253 if (!llc_sk(sk
)->data_flag
)
1254 llc_sk(sk
)->data_flag
= 1;
1258 int llc_conn_ac_set_p_flag_0(struct sock
*sk
, struct sk_buff
*skb
)
1260 llc_conn_set_p_flag(sk
, 0);
1264 static int llc_conn_ac_set_p_flag_1(struct sock
*sk
, struct sk_buff
*skb
)
1266 llc_conn_set_p_flag(sk
, 1);
1270 int llc_conn_ac_set_remote_busy_0(struct sock
*sk
, struct sk_buff
*skb
)
1272 llc_sk(sk
)->remote_busy_flag
= 0;
1276 int llc_conn_ac_set_cause_flag_0(struct sock
*sk
, struct sk_buff
*skb
)
1278 llc_sk(sk
)->cause_flag
= 0;
1282 int llc_conn_ac_set_cause_flag_1(struct sock
*sk
, struct sk_buff
*skb
)
1284 llc_sk(sk
)->cause_flag
= 1;
1288 int llc_conn_ac_set_retry_cnt_0(struct sock
*sk
, struct sk_buff
*skb
)
1290 llc_sk(sk
)->retry_count
= 0;
1294 int llc_conn_ac_inc_retry_cnt_by_1(struct sock
*sk
, struct sk_buff
*skb
)
1296 llc_sk(sk
)->retry_count
++;
1300 int llc_conn_ac_set_vr_0(struct sock
*sk
, struct sk_buff
*skb
)
1306 int llc_conn_ac_inc_vr_by_1(struct sock
*sk
, struct sk_buff
*skb
)
1308 llc_sk(sk
)->vR
= PDU_GET_NEXT_Vr(llc_sk(sk
)->vR
);
1312 int llc_conn_ac_set_vs_0(struct sock
*sk
, struct sk_buff
*skb
)
1318 int llc_conn_ac_set_vs_nr(struct sock
*sk
, struct sk_buff
*skb
)
1320 llc_sk(sk
)->vS
= llc_sk(sk
)->last_nr
;
1324 int llc_conn_ac_inc_vs_by_1(struct sock
*sk
, struct sk_buff
*skb
)
1326 llc_sk(sk
)->vS
= (llc_sk(sk
)->vS
+ 1) % 128;
1330 static void llc_conn_tmr_common_cb(unsigned long timeout_data
, u8 type
)
1332 struct sock
*sk
= (struct sock
*)timeout_data
;
1333 struct sk_buff
*skb
= alloc_skb(0, GFP_ATOMIC
);
1337 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
1339 skb_set_owner_r(skb
, sk
);
1341 llc_process_tmr_ev(sk
, skb
);
1346 void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data
)
1348 llc_conn_tmr_common_cb(timeout_data
, LLC_CONN_EV_TYPE_P_TMR
);
1351 void llc_conn_busy_tmr_cb(unsigned long timeout_data
)
1353 llc_conn_tmr_common_cb(timeout_data
, LLC_CONN_EV_TYPE_BUSY_TMR
);
1356 void llc_conn_ack_tmr_cb(unsigned long timeout_data
)
1358 llc_conn_tmr_common_cb(timeout_data
, LLC_CONN_EV_TYPE_ACK_TMR
);
1361 void llc_conn_rej_tmr_cb(unsigned long timeout_data
)
1363 llc_conn_tmr_common_cb(timeout_data
, LLC_CONN_EV_TYPE_REJ_TMR
);
1366 int llc_conn_ac_rst_vs(struct sock
*sk
, struct sk_buff
*skb
)
1368 llc_sk(sk
)->X
= llc_sk(sk
)->vS
;
1369 llc_conn_ac_set_vs_nr(sk
, skb
);
1373 int llc_conn_ac_upd_vs(struct sock
*sk
, struct sk_buff
*skb
)
1375 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
1376 u8 nr
= PDU_SUPV_GET_Nr(pdu
);
1378 if (llc_circular_between(llc_sk(sk
)->vS
, nr
, llc_sk(sk
)->X
))
1379 llc_conn_ac_set_vs_nr(sk
, skb
);
1384 * Non-standard actions; these not contained in IEEE specification; for
1388 * llc_conn_disc - removes connection from SAP list and frees it
1389 * @sk: closed connection
1390 * @skb: occurred event
1392 int llc_conn_disc(struct sock
*sk
, struct sk_buff
*skb
)
1394 /* FIXME: this thing seems to want to die */
1399 * llc_conn_reset - resets connection
1400 * @sk : reseting connection.
1401 * @skb: occurred event.
1403 * Stop all timers, empty all queues and reset all flags.
1405 int llc_conn_reset(struct sock
*sk
, struct sk_buff
*skb
)
1412 * llc_circular_between - designates that b is between a and c or not
1414 * @b: element to see if is between a and b
1417 * This function designates that b is between a and c or not (for example,
1418 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
1421 u8
llc_circular_between(u8 a
, u8 b
, u8 c
)
1429 * llc_process_tmr_ev - timer backend
1430 * @sk: active connection
1431 * @skb: occurred event
1433 * This function is called from timer callback functions. When connection
1434 * is busy (during sending a data frame) timer expiration event must be
1435 * queued. Otherwise this event can be sent to connection state machine.
1436 * Queued events will process by llc_backlog_rcv function after sending
1439 static void llc_process_tmr_ev(struct sock
*sk
, struct sk_buff
*skb
)
1441 if (llc_sk(sk
)->state
== LLC_CONN_OUT_OF_SVC
) {
1442 printk(KERN_WARNING
"%s: timer called on closed connection\n",
1446 if (!sock_owned_by_user(sk
))
1447 llc_conn_state_process(sk
, skb
);
1449 llc_set_backlog_type(skb
, LLC_EVENT
);
1450 sk_add_backlog(sk
, skb
);