Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * llc_c_ac.c - actions performed during connection state transition.
0003  *
0004  * Description:
0005  *   Functions in this module are implementation of connection component actions
0006  *   Details of actions can be found in IEEE-802.2 standard document.
0007  *   All functions have one connection and one event as input argument. All of
0008  *   them return 0 On success and 1 otherwise.
0009  *
0010  * Copyright (c) 1997 by Procom Technology, Inc.
0011  *       2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
0012  *
0013  * This program can be redistributed or modified under the terms of the
0014  * GNU General Public License as published by the Free Software Foundation.
0015  * This program is distributed without any warranty or implied warranty
0016  * of merchantability or fitness for a particular purpose.
0017  *
0018  * See the GNU General Public License for more details.
0019  */
0020 #include <linux/netdevice.h>
0021 #include <linux/slab.h>
0022 #include <net/llc_conn.h>
0023 #include <net/llc_sap.h>
0024 #include <net/sock.h>
0025 #include <net/llc_c_ev.h>
0026 #include <net/llc_c_ac.h>
0027 #include <net/llc_c_st.h>
0028 #include <net/llc_pdu.h>
0029 #include <net/llc.h>
0030 
0031 
0032 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
0033 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
0034 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev);
0035 
0036 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
0037 
0038 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
0039                            struct sk_buff *skb);
0040 
0041 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
0042 
0043 #define INCORRECT 0
0044 
0045 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
0046 {
0047     struct llc_sock *llc = llc_sk(sk);
0048 
0049     if (llc->remote_busy_flag) {
0050         u8 nr;
0051         struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0052 
0053         llc->remote_busy_flag = 0;
0054         del_timer(&llc->busy_state_timer.timer);
0055         nr = LLC_I_GET_NR(pdu);
0056         llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
0057     }
0058     return 0;
0059 }
0060 
0061 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
0062 {
0063     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0064 
0065     ev->ind_prim = LLC_CONN_PRIM;
0066     return 0;
0067 }
0068 
0069 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
0070 {
0071     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0072 
0073     ev->cfm_prim = LLC_CONN_PRIM;
0074     return 0;
0075 }
0076 
0077 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
0078 {
0079     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0080 
0081     ev->cfm_prim = LLC_DATA_PRIM;
0082     return 0;
0083 }
0084 
0085 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
0086 {
0087     llc_conn_rtn_pdu(sk, skb);
0088     return 0;
0089 }
0090 
0091 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
0092 {
0093     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0094     u8 reason = 0;
0095     int rc = 0;
0096 
0097     if (ev->type == LLC_CONN_EV_TYPE_PDU) {
0098         struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
0099 
0100         if (LLC_PDU_IS_RSP(pdu) &&
0101             LLC_PDU_TYPE_IS_U(pdu) &&
0102             LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
0103             reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
0104         else if (LLC_PDU_IS_CMD(pdu) &&
0105                LLC_PDU_TYPE_IS_U(pdu) &&
0106                LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
0107             reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
0108     } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
0109         reason = LLC_DISC_REASON_ACK_TMR_EXP;
0110     else
0111         rc = -EINVAL;
0112     if (!rc) {
0113         ev->reason   = reason;
0114         ev->ind_prim = LLC_DISC_PRIM;
0115     }
0116     return rc;
0117 }
0118 
0119 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
0120 {
0121     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0122 
0123     ev->reason   = ev->status;
0124     ev->cfm_prim = LLC_DISC_PRIM;
0125     return 0;
0126 }
0127 
0128 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
0129 {
0130     u8 reason = 0;
0131     int rc = 1;
0132     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0133     struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
0134     struct llc_sock *llc = llc_sk(sk);
0135 
0136     switch (ev->type) {
0137     case LLC_CONN_EV_TYPE_PDU:
0138         if (LLC_PDU_IS_RSP(pdu) &&
0139             LLC_PDU_TYPE_IS_U(pdu) &&
0140             LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
0141             reason = LLC_RESET_REASON_LOCAL;
0142             rc = 0;
0143         } else if (LLC_PDU_IS_CMD(pdu) &&
0144                LLC_PDU_TYPE_IS_U(pdu) &&
0145                LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
0146             reason = LLC_RESET_REASON_REMOTE;
0147             rc = 0;
0148         }
0149         break;
0150     case LLC_CONN_EV_TYPE_ACK_TMR:
0151     case LLC_CONN_EV_TYPE_P_TMR:
0152     case LLC_CONN_EV_TYPE_REJ_TMR:
0153     case LLC_CONN_EV_TYPE_BUSY_TMR:
0154         if (llc->retry_count > llc->n2) {
0155             reason = LLC_RESET_REASON_LOCAL;
0156             rc = 0;
0157         }
0158         break;
0159     }
0160     if (!rc) {
0161         ev->reason   = reason;
0162         ev->ind_prim = LLC_RESET_PRIM;
0163     }
0164     return rc;
0165 }
0166 
0167 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
0168 {
0169     struct llc_conn_state_ev *ev = llc_conn_ev(skb);
0170 
0171     ev->reason   = 0;
0172     ev->cfm_prim = LLC_RESET_PRIM;
0173     return 0;
0174 }
0175 
0176 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
0177                         struct sk_buff *skb)
0178 {
0179     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0180 
0181     if (LLC_PDU_IS_RSP(pdu) &&
0182         LLC_PDU_TYPE_IS_I(pdu) &&
0183         LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
0184         llc_conn_ac_clear_remote_busy(sk, skb);
0185     return 0;
0186 }
0187 
0188 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
0189                            struct sk_buff *skb)
0190 {
0191     struct llc_sock *llc = llc_sk(sk);
0192 
0193     if (llc->data_flag == 2)
0194         del_timer(&llc->rej_sent_timer.timer);
0195     return 0;
0196 }
0197 
0198 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
0199 {
0200     int rc = -ENOBUFS;
0201     struct llc_sock *llc = llc_sk(sk);
0202     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0203 
0204     if (nskb) {
0205         struct llc_sap *sap = llc->sap;
0206 
0207         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0208                     llc->daddr.lsap, LLC_PDU_CMD);
0209         llc_pdu_init_as_disc_cmd(nskb, 1);
0210         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0211         if (unlikely(rc))
0212             goto free;
0213         llc_conn_send_pdu(sk, nskb);
0214         llc_conn_ac_set_p_flag_1(sk, skb);
0215     }
0216 out:
0217     return rc;
0218 free:
0219     kfree_skb(nskb);
0220     goto out;
0221 }
0222 
0223 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
0224 {
0225     int rc = -ENOBUFS;
0226     struct llc_sock *llc = llc_sk(sk);
0227     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0228 
0229     if (nskb) {
0230         struct llc_sap *sap = llc->sap;
0231         u8 f_bit;
0232 
0233         llc_pdu_decode_pf_bit(skb, &f_bit);
0234         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0235                     llc->daddr.lsap, LLC_PDU_RSP);
0236         llc_pdu_init_as_dm_rsp(nskb, f_bit);
0237         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0238         if (unlikely(rc))
0239             goto free;
0240         llc_conn_send_pdu(sk, nskb);
0241     }
0242 out:
0243     return rc;
0244 free:
0245     kfree_skb(nskb);
0246     goto out;
0247 }
0248 
0249 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0250 {
0251     int rc = -ENOBUFS;
0252     struct llc_sock *llc = llc_sk(sk);
0253     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0254 
0255     if (nskb) {
0256         struct llc_sap *sap = llc->sap;
0257 
0258         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0259                     llc->daddr.lsap, LLC_PDU_RSP);
0260         llc_pdu_init_as_dm_rsp(nskb, 1);
0261         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0262         if (unlikely(rc))
0263             goto free;
0264         llc_conn_send_pdu(sk, nskb);
0265     }
0266 out:
0267     return rc;
0268 free:
0269     kfree_skb(nskb);
0270     goto out;
0271 }
0272 
0273 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
0274 {
0275     u8 f_bit;
0276     int rc = -ENOBUFS;
0277     struct sk_buff *nskb;
0278     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0279     struct llc_sock *llc = llc_sk(sk);
0280 
0281     llc->rx_pdu_hdr = *((u32 *)pdu);
0282     if (LLC_PDU_IS_CMD(pdu))
0283         llc_pdu_decode_pf_bit(skb, &f_bit);
0284     else
0285         f_bit = 0;
0286     nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
0287                    sizeof(struct llc_frmr_info));
0288     if (nskb) {
0289         struct llc_sap *sap = llc->sap;
0290 
0291         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0292                     llc->daddr.lsap, LLC_PDU_RSP);
0293         llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
0294                      llc->vR, INCORRECT);
0295         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0296         if (unlikely(rc))
0297             goto free;
0298         llc_conn_send_pdu(sk, nskb);
0299     }
0300 out:
0301     return rc;
0302 free:
0303     kfree_skb(nskb);
0304     goto out;
0305 }
0306 
0307 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
0308 {
0309     int rc = -ENOBUFS;
0310     struct llc_sock *llc = llc_sk(sk);
0311     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
0312                            sizeof(struct llc_frmr_info));
0313 
0314     if (nskb) {
0315         struct llc_sap *sap = llc->sap;
0316         struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
0317 
0318         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0319                     llc->daddr.lsap, LLC_PDU_RSP);
0320         llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
0321                      llc->vR, INCORRECT);
0322         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0323         if (unlikely(rc))
0324             goto free;
0325         llc_conn_send_pdu(sk, nskb);
0326     }
0327 out:
0328     return rc;
0329 free:
0330     kfree_skb(nskb);
0331     goto out;
0332 }
0333 
0334 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
0335 {
0336     u8 f_bit;
0337     int rc = -ENOBUFS;
0338     struct sk_buff *nskb;
0339     struct llc_sock *llc = llc_sk(sk);
0340 
0341     llc_pdu_decode_pf_bit(skb, &f_bit);
0342     nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U,
0343                    sizeof(struct llc_frmr_info));
0344     if (nskb) {
0345         struct llc_sap *sap = llc->sap;
0346         struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0347 
0348         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0349                     llc->daddr.lsap, LLC_PDU_RSP);
0350         llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
0351                      llc->vR, INCORRECT);
0352         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0353         if (unlikely(rc))
0354             goto free;
0355         llc_conn_send_pdu(sk, nskb);
0356     }
0357 out:
0358     return rc;
0359 free:
0360     kfree_skb(nskb);
0361     goto out;
0362 }
0363 
0364 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
0365 {
0366     int rc;
0367     struct llc_sock *llc = llc_sk(sk);
0368     struct llc_sap *sap = llc->sap;
0369 
0370     llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
0371                 llc->daddr.lsap, LLC_PDU_CMD);
0372     llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
0373     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
0374     if (likely(!rc)) {
0375         skb_get(skb);
0376         llc_conn_send_pdu(sk, skb);
0377         llc_conn_ac_inc_vs_by_1(sk, skb);
0378     }
0379     return rc;
0380 }
0381 
0382 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
0383 {
0384     int rc;
0385     struct llc_sock *llc = llc_sk(sk);
0386     struct llc_sap *sap = llc->sap;
0387 
0388     llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
0389                 llc->daddr.lsap, LLC_PDU_CMD);
0390     llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
0391     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
0392     if (likely(!rc)) {
0393         skb_get(skb);
0394         llc_conn_send_pdu(sk, skb);
0395         llc_conn_ac_inc_vs_by_1(sk, skb);
0396     }
0397     return rc;
0398 }
0399 
0400 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0401 {
0402     int rc;
0403     struct llc_sock *llc = llc_sk(sk);
0404     struct llc_sap *sap = llc->sap;
0405 
0406     llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
0407                 llc->daddr.lsap, LLC_PDU_CMD);
0408     llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
0409     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
0410     if (likely(!rc)) {
0411         skb_get(skb);
0412         llc_conn_send_pdu(sk, skb);
0413         llc_conn_ac_inc_vs_by_1(sk, skb);
0414     }
0415     return 0;
0416 }
0417 
0418 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0419 {
0420     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0421     u8 nr = LLC_I_GET_NR(pdu);
0422 
0423     llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
0424     return 0;
0425 }
0426 
0427 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
0428                         struct sk_buff *skb)
0429 {
0430     u8 nr;
0431     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0432     int rc = -ENOBUFS;
0433     struct llc_sock *llc = llc_sk(sk);
0434     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0435 
0436     if (nskb) {
0437         struct llc_sap *sap = llc->sap;
0438 
0439         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0440                     llc->daddr.lsap, LLC_PDU_RSP);
0441         llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
0442         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0443         if (likely(!rc))
0444             llc_conn_send_pdu(sk, nskb);
0445         else
0446             kfree_skb(skb);
0447     }
0448     if (rc) {
0449         nr = LLC_I_GET_NR(pdu);
0450         rc = 0;
0451         llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
0452     }
0453     return rc;
0454 }
0455 
0456 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0457 {
0458     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
0459     u8 nr = LLC_I_GET_NR(pdu);
0460 
0461     llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
0462     return 0;
0463 }
0464 
0465 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
0466 {
0467     int rc = -ENOBUFS;
0468     struct llc_sock *llc = llc_sk(sk);
0469     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0470 
0471     if (nskb) {
0472         struct llc_sap *sap = llc->sap;
0473 
0474         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0475                     llc->daddr.lsap, LLC_PDU_CMD);
0476         llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
0477         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0478         if (unlikely(rc))
0479             goto free;
0480         llc_conn_send_pdu(sk, nskb);
0481     }
0482 out:
0483     return rc;
0484 free:
0485     kfree_skb(nskb);
0486     goto out;
0487 }
0488 
0489 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0490 {
0491     int rc = -ENOBUFS;
0492     struct llc_sock *llc = llc_sk(sk);
0493     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0494 
0495     if (nskb) {
0496         struct llc_sap *sap = llc->sap;
0497 
0498         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0499                     llc->daddr.lsap, LLC_PDU_RSP);
0500         llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
0501         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0502         if (unlikely(rc))
0503             goto free;
0504         llc_conn_send_pdu(sk, nskb);
0505     }
0506 out:
0507     return rc;
0508 free:
0509     kfree_skb(nskb);
0510     goto out;
0511 }
0512 
0513 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0514 {
0515     int rc = -ENOBUFS;
0516     struct llc_sock *llc = llc_sk(sk);
0517     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0518 
0519     if (nskb) {
0520         struct llc_sap *sap = llc->sap;
0521 
0522         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0523                     llc->daddr.lsap, LLC_PDU_RSP);
0524         llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
0525         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0526         if (unlikely(rc))
0527             goto free;
0528         llc_conn_send_pdu(sk, nskb);
0529     }
0530 out:
0531     return rc;
0532 free:
0533     kfree_skb(nskb);
0534     goto out;
0535 }
0536 
0537 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
0538 {
0539     int rc = -ENOBUFS;
0540     struct llc_sock *llc = llc_sk(sk);
0541     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0542 
0543     if (nskb) {
0544         struct llc_sap *sap = llc->sap;
0545 
0546         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0547                     llc->daddr.lsap, LLC_PDU_CMD);
0548         llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
0549         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0550         if (unlikely(rc))
0551             goto free;
0552         llc_conn_send_pdu(sk, nskb);
0553     }
0554 out:
0555     return rc;
0556 free:
0557     kfree_skb(nskb);
0558     goto out;
0559 }
0560 
0561 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0562 {
0563     int rc = -ENOBUFS;
0564     struct llc_sock *llc = llc_sk(sk);
0565     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0566 
0567     if (nskb) {
0568         struct llc_sap *sap = llc->sap;
0569 
0570         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0571                     llc->daddr.lsap, LLC_PDU_RSP);
0572         llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
0573         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0574         if (unlikely(rc))
0575             goto free;
0576         llc_conn_send_pdu(sk, nskb);
0577     }
0578 out:
0579     return rc;
0580 free:
0581     kfree_skb(nskb);
0582     goto out;
0583 }
0584 
0585 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0586 {
0587     int rc = -ENOBUFS;
0588     struct llc_sock *llc = llc_sk(sk);
0589     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0590 
0591     if (nskb) {
0592         struct llc_sap *sap = llc->sap;
0593 
0594         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0595                     llc->daddr.lsap, LLC_PDU_RSP);
0596         llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
0597         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0598         if (unlikely(rc))
0599             goto free;
0600         llc_conn_send_pdu(sk, nskb);
0601     }
0602 out:
0603     return rc;
0604 free:
0605     kfree_skb(nskb);
0606     goto out;
0607 }
0608 
0609 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
0610 {
0611     struct llc_sock *llc = llc_sk(sk);
0612 
0613     if (!llc->remote_busy_flag) {
0614         llc->remote_busy_flag = 1;
0615         mod_timer(&llc->busy_state_timer.timer,
0616              jiffies + llc->busy_state_timer.expire);
0617     }
0618     return 0;
0619 }
0620 
0621 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0622 {
0623     int rc = -ENOBUFS;
0624     struct llc_sock *llc = llc_sk(sk);
0625     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0626 
0627     if (nskb) {
0628         struct llc_sap *sap = llc->sap;
0629 
0630         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0631                     llc->daddr.lsap, LLC_PDU_RSP);
0632         llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
0633         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0634         if (unlikely(rc))
0635             goto free;
0636         llc_conn_send_pdu(sk, nskb);
0637     }
0638 out:
0639     return rc;
0640 free:
0641     kfree_skb(nskb);
0642     goto out;
0643 }
0644 
0645 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
0646 {
0647     int rc = -ENOBUFS;
0648     struct llc_sock *llc = llc_sk(sk);
0649     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0650 
0651     if (nskb) {
0652         struct llc_sap *sap = llc->sap;
0653 
0654         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0655                     llc->daddr.lsap, LLC_PDU_CMD);
0656         llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
0657         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0658         if (unlikely(rc))
0659             goto free;
0660         llc_conn_send_pdu(sk, nskb);
0661     }
0662 out:
0663     return rc;
0664 free:
0665     kfree_skb(nskb);
0666     goto out;
0667 }
0668 
0669 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0670 {
0671     int rc = -ENOBUFS;
0672     struct llc_sock *llc = llc_sk(sk);
0673     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0674 
0675     if (nskb) {
0676         struct llc_sap *sap = llc->sap;
0677         u8 f_bit = 1;
0678 
0679         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0680                     llc->daddr.lsap, LLC_PDU_RSP);
0681         llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
0682         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0683         if (unlikely(rc))
0684             goto free;
0685         llc_conn_send_pdu(sk, nskb);
0686     }
0687 out:
0688     return rc;
0689 free:
0690     kfree_skb(nskb);
0691     goto out;
0692 }
0693 
0694 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
0695 {
0696     int rc = -ENOBUFS;
0697     struct llc_sock *llc = llc_sk(sk);
0698     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0699 
0700     if (nskb) {
0701         struct llc_sap *sap = llc->sap;
0702 
0703         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0704                     llc->daddr.lsap, LLC_PDU_RSP);
0705         llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
0706         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0707         if (unlikely(rc))
0708             goto free;
0709         llc_conn_send_pdu(sk, nskb);
0710     }
0711 out:
0712     return rc;
0713 free:
0714     kfree_skb(nskb);
0715     goto out;
0716 }
0717 
0718 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0719 {
0720     int rc = -ENOBUFS;
0721     struct llc_sock *llc = llc_sk(sk);
0722     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0723 
0724     if (nskb) {
0725         struct llc_sap *sap = llc->sap;
0726 
0727         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0728                     llc->daddr.lsap, LLC_PDU_RSP);
0729         llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
0730         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0731         if (unlikely(rc))
0732             goto free;
0733         llc_conn_send_pdu(sk, nskb);
0734     }
0735 out:
0736     return rc;
0737 free:
0738     kfree_skb(nskb);
0739     goto out;
0740 }
0741 
0742 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
0743 {
0744     int rc = -ENOBUFS;
0745     struct llc_sock *llc = llc_sk(sk);
0746     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0747 
0748     if (nskb) {
0749         struct llc_sap *sap = llc->sap;
0750 
0751         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0752                     llc->daddr.lsap, LLC_PDU_RSP);
0753         llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
0754         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0755         if (unlikely(rc))
0756             goto free;
0757         llc_conn_send_pdu(sk, nskb);
0758     }
0759 out:
0760     return rc;
0761 free:
0762     kfree_skb(nskb);
0763     goto out;
0764 }
0765 
0766 void llc_conn_set_p_flag(struct sock *sk, u8 value)
0767 {
0768     int state_changed = llc_sk(sk)->p_flag && !value;
0769 
0770     llc_sk(sk)->p_flag = value;
0771 
0772     if (state_changed)
0773         sk->sk_state_change(sk);
0774 }
0775 
0776 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
0777 {
0778     int rc = -ENOBUFS;
0779     struct llc_sock *llc = llc_sk(sk);
0780     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0781 
0782     if (nskb) {
0783         struct llc_sap *sap = llc->sap;
0784         const u8 *dmac = llc->daddr.mac;
0785 
0786         if (llc->dev->flags & IFF_LOOPBACK)
0787             dmac = llc->dev->dev_addr;
0788         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0789                     llc->daddr.lsap, LLC_PDU_CMD);
0790         llc_pdu_init_as_sabme_cmd(nskb, 1);
0791         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
0792         if (unlikely(rc))
0793             goto free;
0794         llc_conn_send_pdu(sk, nskb);
0795         llc_conn_set_p_flag(sk, 1);
0796     }
0797 out:
0798     return rc;
0799 free:
0800     kfree_skb(nskb);
0801     goto out;
0802 }
0803 
0804 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
0805 {
0806     u8 f_bit;
0807     int rc = -ENOBUFS;
0808     struct llc_sock *llc = llc_sk(sk);
0809     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
0810 
0811     llc_pdu_decode_pf_bit(skb, &f_bit);
0812     if (nskb) {
0813         struct llc_sap *sap = llc->sap;
0814 
0815         nskb->dev = llc->dev;
0816         llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
0817                     llc->daddr.lsap, LLC_PDU_RSP);
0818         llc_pdu_init_as_ua_rsp(nskb, f_bit);
0819         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0820         if (unlikely(rc))
0821             goto free;
0822         llc_conn_send_pdu(sk, nskb);
0823     }
0824 out:
0825     return rc;
0826 free:
0827     kfree_skb(nskb);
0828     goto out;
0829 }
0830 
0831 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
0832 {
0833     llc_sk(sk)->s_flag = 0;
0834     return 0;
0835 }
0836 
0837 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
0838 {
0839     llc_sk(sk)->s_flag = 1;
0840     return 0;
0841 }
0842 
0843 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
0844 {
0845     struct llc_sock *llc = llc_sk(sk);
0846 
0847     llc_conn_set_p_flag(sk, 1);
0848     mod_timer(&llc->pf_cycle_timer.timer,
0849           jiffies + llc->pf_cycle_timer.expire);
0850     return 0;
0851 }
0852 
0853 /**
0854  *  llc_conn_ac_send_ack_if_needed - check if ack is needed
0855  *  @sk: current connection structure
0856  *  @skb: current event
0857  *
0858  *  Checks number of received PDUs which have not been acknowledged, yet,
0859  *  If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
0860  *  sends an RR response as acknowledgement for them.  Returns 0 for
0861  *  success, 1 otherwise.
0862  */
0863 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
0864 {
0865     u8 pf_bit;
0866     struct llc_sock *llc = llc_sk(sk);
0867 
0868     llc_pdu_decode_pf_bit(skb, &pf_bit);
0869     llc->ack_pf |= pf_bit & 1;
0870     if (!llc->ack_must_be_send) {
0871         llc->first_pdu_Ns = llc->vR;
0872         llc->ack_must_be_send = 1;
0873         llc->ack_pf = pf_bit & 1;
0874     }
0875     if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
0876             % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
0877         llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
0878         llc->ack_must_be_send   = 0;
0879         llc->ack_pf     = 0;
0880         llc_conn_ac_inc_npta_value(sk, skb);
0881     }
0882     return 0;
0883 }
0884 
0885 /**
0886  *  llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
0887  *  @sk: current connection structure
0888  *  @skb: current event
0889  *
0890  *  This action resets ack_must_be_send flag of given connection, this flag
0891  *  indicates if there is any PDU which has not been acknowledged yet.
0892  *  Returns 0 for success, 1 otherwise.
0893  */
0894 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
0895 {
0896     llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
0897     return 0;
0898 }
0899 
0900 /**
0901  *  llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
0902  *  @sk: current connection structure
0903  *  @skb: current event
0904  *
0905  *  Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
0906  *  all received PDUs which have not been acknowledged, yet. ack_pf flag is
0907  *  set to one if one PDU with p-bit set to one is received.  Returns 0 for
0908  *  success, 1 otherwise.
0909  */
0910 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
0911                           struct sk_buff *skb)
0912 {
0913     int rc;
0914     struct llc_sock *llc = llc_sk(sk);
0915     struct llc_sap *sap = llc->sap;
0916 
0917     llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
0918                 llc->daddr.lsap, LLC_PDU_RSP);
0919     llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
0920     rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
0921     if (likely(!rc)) {
0922         skb_get(skb);
0923         llc_conn_send_pdu(sk, skb);
0924         llc_conn_ac_inc_vs_by_1(sk, skb);
0925     }
0926     return rc;
0927 }
0928 
0929 /**
0930  *  llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
0931  *  @sk: current connection structure.
0932  *  @skb: current event.
0933  *
0934  *  This action sends an I-format PDU as acknowledge to received PDUs which
0935  *  have not been acknowledged, yet, if there is any. By using of this
0936  *  action number of acknowledgements decreases, this technic is called
0937  *  piggy backing. Returns 0 for success, 1 otherwise.
0938  */
0939 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
0940 {
0941     struct llc_sock *llc = llc_sk(sk);
0942     int ret;
0943 
0944     if (llc->ack_must_be_send) {
0945         ret = llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
0946         llc->ack_must_be_send = 0 ;
0947         llc->ack_pf = 0;
0948     } else {
0949         ret = llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
0950     }
0951 
0952     return ret;
0953 }
0954 
0955 /**
0956  *  llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
0957  *  @sk: current connection structure.
0958  *  @skb: current event.
0959  *
0960  *  This action sends an RR response with f-bit set to ack_pf flag as
0961  *  acknowledge to all received PDUs which have not been acknowledged, yet,
0962  *  if there is any. ack_pf flag indicates if a PDU has been received with
0963  *  p-bit set to one. Returns 0 for success, 1 otherwise.
0964  */
0965 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
0966                            struct sk_buff *skb)
0967 {
0968     int rc = -ENOBUFS;
0969     struct llc_sock *llc = llc_sk(sk);
0970     struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
0971 
0972     if (nskb) {
0973         struct llc_sap *sap = llc->sap;
0974 
0975         llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
0976                     llc->daddr.lsap, LLC_PDU_RSP);
0977         llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
0978         rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
0979         if (unlikely(rc))
0980             goto free;
0981         llc_conn_send_pdu(sk, nskb);
0982     }
0983 out:
0984     return rc;
0985 free:
0986     kfree_skb(nskb);
0987     goto out;
0988 }
0989 
0990 /**
0991  *  llc_conn_ac_inc_npta_value - tries to make value of npta greater
0992  *  @sk: current connection structure.
0993  *  @skb: current event.
0994  *
0995  *  After "inc_cntr" times calling of this action, "npta" increase by one.
0996  *  this action tries to make vale of "npta" greater as possible; number of
0997  *  acknowledgements decreases by increasing of "npta". Returns 0 for
0998  *  success, 1 otherwise.
0999  */
1000 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
1001 {
1002     struct llc_sock *llc = llc_sk(sk);
1003 
1004     if (!llc->inc_cntr) {
1005         llc->dec_step = 0;
1006         llc->dec_cntr = llc->inc_cntr = 2;
1007         ++llc->npta;
1008         if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
1009             llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
1010     } else
1011         --llc->inc_cntr;
1012     return 0;
1013 }
1014 
1015 /**
1016  *  llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
1017  *  @sk: current connection structure.
1018  *  @skb: current event.
1019  *
1020  *  After receiving "dec_cntr" times RR command, this action decreases
1021  *  "npta" by one. Returns 0 for success, 1 otherwise.
1022  */
1023 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
1024 {
1025     struct llc_sock *llc = llc_sk(sk);
1026 
1027     if (!llc->connect_step && !llc->remote_busy_flag) {
1028         if (!llc->dec_step) {
1029             if (!llc->dec_cntr) {
1030                 llc->inc_cntr = llc->dec_cntr = 2;
1031                 if (llc->npta > 0)
1032                     llc->npta = llc->npta - 1;
1033             } else
1034                 llc->dec_cntr -=1;
1035         }
1036     } else
1037         llc->connect_step = 0 ;
1038     return 0;
1039 }
1040 
1041 /**
1042  *  llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
1043  *  @sk: current connection structure.
1044  *  @skb: current event.
1045  *
1046  *  After receiving "dec_cntr" times RNR command, this action decreases
1047  *  "npta" by one. Returns 0 for success, 1 otherwise.
1048  */
1049 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
1050 {
1051     struct llc_sock *llc = llc_sk(sk);
1052 
1053     if (llc->remote_busy_flag)
1054         if (!llc->dec_step) {
1055             if (!llc->dec_cntr) {
1056                 llc->inc_cntr = llc->dec_cntr = 2;
1057                 if (llc->npta > 0)
1058                     --llc->npta;
1059             } else
1060                 --llc->dec_cntr;
1061         }
1062     return 0;
1063 }
1064 
1065 /**
1066  *  llc_conn_ac_dec_tx_win_size - decreases tx window size
1067  *  @sk: current connection structure.
1068  *  @skb: current event.
1069  *
1070  *  After receiving of a REJ command or response, transmit window size is
1071  *  decreased by number of PDUs which are outstanding yet. Returns 0 for
1072  *  success, 1 otherwise.
1073  */
1074 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
1075 {
1076     struct llc_sock *llc = llc_sk(sk);
1077     u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
1078 
1079     if (llc->k - unacked_pdu < 1)
1080         llc->k = 1;
1081     else
1082         llc->k -= unacked_pdu;
1083     return 0;
1084 }
1085 
1086 /**
1087  *  llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
1088  *  @sk: current connection structure.
1089  *  @skb: current event.
1090  *
1091  *  After receiving an RR response with f-bit set to one, transmit window
1092  *  size is increased by one. Returns 0 for success, 1 otherwise.
1093  */
1094 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
1095 {
1096     struct llc_sock *llc = llc_sk(sk);
1097 
1098     llc->k += 1;
1099     if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
1100         llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
1101     return 0;
1102 }
1103 
1104 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
1105 {
1106     llc_sk_stop_all_timers(sk, false);
1107     return 0;
1108 }
1109 
1110 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
1111 {
1112     struct llc_sock *llc = llc_sk(sk);
1113 
1114     del_timer(&llc->rej_sent_timer.timer);
1115     del_timer(&llc->pf_cycle_timer.timer);
1116     del_timer(&llc->busy_state_timer.timer);
1117     llc->ack_must_be_send = 0;
1118     llc->ack_pf = 0;
1119     return 0;
1120 }
1121 
1122 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1123 {
1124     struct llc_sock *llc = llc_sk(sk);
1125 
1126     mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1127     return 0;
1128 }
1129 
1130 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1131 {
1132     struct llc_sock *llc = llc_sk(sk);
1133 
1134     mod_timer(&llc->rej_sent_timer.timer,
1135           jiffies + llc->rej_sent_timer.expire);
1136     return 0;
1137 }
1138 
1139 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1140                          struct sk_buff *skb)
1141 {
1142     struct llc_sock *llc = llc_sk(sk);
1143 
1144     if (!timer_pending(&llc->ack_timer.timer))
1145         mod_timer(&llc->ack_timer.timer,
1146               jiffies + llc->ack_timer.expire);
1147     return 0;
1148 }
1149 
1150 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
1151 {
1152     del_timer(&llc_sk(sk)->ack_timer.timer);
1153     return 0;
1154 }
1155 
1156 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
1157 {
1158     struct llc_sock *llc = llc_sk(sk);
1159 
1160     del_timer(&llc->pf_cycle_timer.timer);
1161     llc_conn_set_p_flag(sk, 0);
1162     return 0;
1163 }
1164 
1165 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
1166 {
1167     del_timer(&llc_sk(sk)->rej_sent_timer.timer);
1168     return 0;
1169 }
1170 
1171 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1172 {
1173     int acked;
1174     u16 unacked = 0;
1175     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1176     struct llc_sock *llc = llc_sk(sk);
1177 
1178     llc->last_nr = PDU_SUPV_GET_Nr(pdu);
1179     acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
1180     /* On loopback we don't queue I frames in unack_pdu_q queue. */
1181     if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
1182         llc->retry_count = 0;
1183         del_timer(&llc->ack_timer.timer);
1184         if (llc->failed_data_req) {
1185             /* already, we did not accept data from upper layer
1186              * (tx_window full or unacceptable state). Now, we
1187              * can send data and must inform to upper layer.
1188              */
1189             llc->failed_data_req = 0;
1190             llc_conn_ac_data_confirm(sk, skb);
1191         }
1192         if (unacked)
1193             mod_timer(&llc->ack_timer.timer,
1194                   jiffies + llc->ack_timer.expire);
1195     } else if (llc->failed_data_req) {
1196         u8 f_bit;
1197 
1198         llc_pdu_decode_pf_bit(skb, &f_bit);
1199         if (f_bit == 1) {
1200             llc->failed_data_req = 0;
1201             llc_conn_ac_data_confirm(sk, skb);
1202         }
1203     }
1204     return 0;
1205 }
1206 
1207 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
1208 {
1209     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1210 
1211     if (LLC_PDU_IS_RSP(pdu)) {
1212         u8 f_bit;
1213 
1214         llc_pdu_decode_pf_bit(skb, &f_bit);
1215         if (f_bit) {
1216             llc_conn_set_p_flag(sk, 0);
1217             llc_conn_ac_stop_p_timer(sk, skb);
1218         }
1219     }
1220     return 0;
1221 }
1222 
1223 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
1224 {
1225     llc_sk(sk)->data_flag = 2;
1226     return 0;
1227 }
1228 
1229 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
1230 {
1231     llc_sk(sk)->data_flag = 0;
1232     return 0;
1233 }
1234 
1235 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
1236 {
1237     llc_sk(sk)->data_flag = 1;
1238     return 0;
1239 }
1240 
1241 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
1242                           struct sk_buff *skb)
1243 {
1244     if (!llc_sk(sk)->data_flag)
1245         llc_sk(sk)->data_flag = 1;
1246     return 0;
1247 }
1248 
1249 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
1250 {
1251     llc_conn_set_p_flag(sk, 0);
1252     return 0;
1253 }
1254 
1255 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
1256 {
1257     llc_conn_set_p_flag(sk, 1);
1258     return 0;
1259 }
1260 
1261 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
1262 {
1263     llc_sk(sk)->remote_busy_flag = 0;
1264     return 0;
1265 }
1266 
1267 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
1268 {
1269     llc_sk(sk)->cause_flag = 0;
1270     return 0;
1271 }
1272 
1273 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
1274 {
1275     llc_sk(sk)->cause_flag = 1;
1276     return 0;
1277 }
1278 
1279 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
1280 {
1281     llc_sk(sk)->retry_count = 0;
1282     return 0;
1283 }
1284 
1285 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
1286 {
1287     llc_sk(sk)->retry_count++;
1288     return 0;
1289 }
1290 
1291 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
1292 {
1293     llc_sk(sk)->vR = 0;
1294     return 0;
1295 }
1296 
1297 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
1298 {
1299     llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
1300     return 0;
1301 }
1302 
1303 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
1304 {
1305     llc_sk(sk)->vS = 0;
1306     return 0;
1307 }
1308 
1309 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1310 {
1311     llc_sk(sk)->vS = llc_sk(sk)->last_nr;
1312     return 0;
1313 }
1314 
1315 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1316 {
1317     llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
1318     return 0;
1319 }
1320 
1321 static void llc_conn_tmr_common_cb(struct sock *sk, u8 type)
1322 {
1323     struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1324 
1325     bh_lock_sock(sk);
1326     if (skb) {
1327         struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1328 
1329         skb_set_owner_r(skb, sk);
1330         ev->type = type;
1331         llc_process_tmr_ev(sk, skb);
1332     }
1333     bh_unlock_sock(sk);
1334 }
1335 
1336 void llc_conn_pf_cycle_tmr_cb(struct timer_list *t)
1337 {
1338     struct llc_sock *llc = from_timer(llc, t, pf_cycle_timer.timer);
1339 
1340     llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_P_TMR);
1341 }
1342 
1343 void llc_conn_busy_tmr_cb(struct timer_list *t)
1344 {
1345     struct llc_sock *llc = from_timer(llc, t, busy_state_timer.timer);
1346 
1347     llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_BUSY_TMR);
1348 }
1349 
1350 void llc_conn_ack_tmr_cb(struct timer_list *t)
1351 {
1352     struct llc_sock *llc = from_timer(llc, t, ack_timer.timer);
1353 
1354     llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_ACK_TMR);
1355 }
1356 
1357 void llc_conn_rej_tmr_cb(struct timer_list *t)
1358 {
1359     struct llc_sock *llc = from_timer(llc, t, rej_sent_timer.timer);
1360 
1361     llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_REJ_TMR);
1362 }
1363 
1364 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
1365 {
1366     llc_sk(sk)->X = llc_sk(sk)->vS;
1367     llc_conn_ac_set_vs_nr(sk, skb);
1368     return 0;
1369 }
1370 
1371 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
1372 {
1373     struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
1374     u8 nr = PDU_SUPV_GET_Nr(pdu);
1375 
1376     if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
1377         llc_conn_ac_set_vs_nr(sk, skb);
1378     return 0;
1379 }
1380 
1381 /*
1382  * Non-standard actions; these not contained in IEEE specification; for
1383  * our own usage
1384  */
1385 /**
1386  *  llc_conn_disc - removes connection from SAP list and frees it
1387  *  @sk: closed connection
1388  *  @skb: occurred event
1389  */
1390 int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
1391 {
1392     /* FIXME: this thing seems to want to die */
1393     return 0;
1394 }
1395 
1396 /**
1397  *  llc_conn_reset - resets connection
1398  *  @sk : reseting connection.
1399  *  @skb: occurred event.
1400  *
1401  *  Stop all timers, empty all queues and reset all flags.
1402  */
1403 int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
1404 {
1405     llc_sk_reset(sk);
1406     return 0;
1407 }
1408 
1409 /**
1410  *  llc_circular_between - designates that b is between a and c or not
1411  *  @a: lower bound
1412  *  @b: element to see if is between a and b
1413  *  @c: upper bound
1414  *
1415  *  This function designates that b is between a and c or not (for example,
1416  *  0 is between 127 and 1). Returns 1 if b is between a and c, 0
1417  *  otherwise.
1418  */
1419 u8 llc_circular_between(u8 a, u8 b, u8 c)
1420 {
1421     b = b - a;
1422     c = c - a;
1423     return b <= c;
1424 }
1425 
1426 /**
1427  *  llc_process_tmr_ev - timer backend
1428  *  @sk: active connection
1429  *  @skb: occurred event
1430  *
1431  *  This function is called from timer callback functions. When connection
1432  *  is busy (during sending a data frame) timer expiration event must be
1433  *  queued. Otherwise this event can be sent to connection state machine.
1434  *  Queued events will process by llc_backlog_rcv function after sending
1435  *  data frame.
1436  */
1437 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
1438 {
1439     if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
1440         printk(KERN_WARNING "%s: timer called on closed connection\n",
1441                __func__);
1442         kfree_skb(skb);
1443     } else {
1444         if (!sock_owned_by_user(sk))
1445             llc_conn_state_process(sk, skb);
1446         else {
1447             llc_set_backlog_type(skb, LLC_EVENT);
1448             __sk_add_backlog(sk, skb);
1449         }
1450     }
1451 }