1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * llc_c_ac.c - actions performed during connection state transition. 4 * 5 * Description: 6 * Functions in this module are implementation of connection component actions 7 * Details of actions can be found in IEEE-802.2 standard document. 8 * All functions have one connection and one event as input argument. All of 9 * them return 0 On success and 1 otherwise. 10 * 11 * Copyright (c) 1997 by Procom Technology, Inc. 12 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> 13 */ 14 #include <linux/netdevice.h> 15 #include <linux/slab.h> 16 #include <net/llc_conn.h> 17 #include <net/llc_sap.h> 18 #include <net/sock.h> 19 #include <net/llc_c_ev.h> 20 #include <net/llc_c_ac.h> 21 #include <net/llc_c_st.h> 22 #include <net/llc_pdu.h> 23 #include <net/llc.h> 24 25 26 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb); 27 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb); 28 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev); 29 30 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb); 31 32 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, 33 struct sk_buff *skb); 34 35 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb); 36 37 #define INCORRECT 0 38 39 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb) 40 { 41 struct llc_sock *llc = llc_sk(sk); 42 43 if (llc->remote_busy_flag) { 44 u8 nr; 45 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 46 47 llc->remote_busy_flag = 0; 48 timer_delete(&llc->busy_state_timer.timer); 49 nr = LLC_I_GET_NR(pdu); 50 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); 51 } 52 return 0; 53 } 54 55 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb) 56 { 57 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 58 59 ev->ind_prim = LLC_CONN_PRIM; 60 return 0; 61 } 62 63 int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb) 64 { 65 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 66 67 ev->cfm_prim = LLC_CONN_PRIM; 68 return 0; 69 } 70 71 static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb) 72 { 73 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 74 75 ev->cfm_prim = LLC_DATA_PRIM; 76 return 0; 77 } 78 79 int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb) 80 { 81 llc_conn_rtn_pdu(sk, skb); 82 return 0; 83 } 84 85 int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb) 86 { 87 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 88 u8 reason = 0; 89 int rc = 0; 90 91 if (ev->type == LLC_CONN_EV_TYPE_PDU) { 92 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 93 94 if (LLC_PDU_IS_RSP(pdu) && 95 LLC_PDU_TYPE_IS_U(pdu) && 96 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM) 97 reason = LLC_DISC_REASON_RX_DM_RSP_PDU; 98 else if (LLC_PDU_IS_CMD(pdu) && 99 LLC_PDU_TYPE_IS_U(pdu) && 100 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC) 101 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU; 102 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR) 103 reason = LLC_DISC_REASON_ACK_TMR_EXP; 104 else 105 rc = -EINVAL; 106 if (!rc) { 107 ev->reason = reason; 108 ev->ind_prim = LLC_DISC_PRIM; 109 } 110 return rc; 111 } 112 113 int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb) 114 { 115 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 116 117 ev->reason = ev->status; 118 ev->cfm_prim = LLC_DISC_PRIM; 119 return 0; 120 } 121 122 int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb) 123 { 124 u8 reason = 0; 125 int rc = 1; 126 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 127 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 128 struct llc_sock *llc = llc_sk(sk); 129 130 switch (ev->type) { 131 case LLC_CONN_EV_TYPE_PDU: 132 if (LLC_PDU_IS_RSP(pdu) && 133 LLC_PDU_TYPE_IS_U(pdu) && 134 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) { 135 reason = LLC_RESET_REASON_LOCAL; 136 rc = 0; 137 } else if (LLC_PDU_IS_CMD(pdu) && 138 LLC_PDU_TYPE_IS_U(pdu) && 139 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) { 140 reason = LLC_RESET_REASON_REMOTE; 141 rc = 0; 142 } 143 break; 144 case LLC_CONN_EV_TYPE_ACK_TMR: 145 case LLC_CONN_EV_TYPE_P_TMR: 146 case LLC_CONN_EV_TYPE_REJ_TMR: 147 case LLC_CONN_EV_TYPE_BUSY_TMR: 148 if (llc->retry_count > llc->n2) { 149 reason = LLC_RESET_REASON_LOCAL; 150 rc = 0; 151 } 152 break; 153 } 154 if (!rc) { 155 ev->reason = reason; 156 ev->ind_prim = LLC_RESET_PRIM; 157 } 158 return rc; 159 } 160 161 int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb) 162 { 163 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 164 165 ev->reason = 0; 166 ev->cfm_prim = LLC_RESET_PRIM; 167 return 0; 168 } 169 170 int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk, 171 struct sk_buff *skb) 172 { 173 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 174 175 if (LLC_PDU_IS_RSP(pdu) && 176 LLC_PDU_TYPE_IS_I(pdu) && 177 LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf) 178 llc_conn_ac_clear_remote_busy(sk, skb); 179 return 0; 180 } 181 182 int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk, 183 struct sk_buff *skb) 184 { 185 struct llc_sock *llc = llc_sk(sk); 186 187 if (llc->data_flag == 2) 188 timer_delete(&llc->rej_sent_timer.timer); 189 return 0; 190 } 191 192 int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) 193 { 194 int rc = -ENOBUFS; 195 struct llc_sock *llc = llc_sk(sk); 196 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 197 198 if (nskb) { 199 struct llc_sap *sap = llc->sap; 200 201 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 202 llc->daddr.lsap, LLC_PDU_CMD); 203 llc_pdu_init_as_disc_cmd(nskb, 1); 204 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 205 if (unlikely(rc)) 206 goto free; 207 llc_conn_send_pdu(sk, nskb); 208 llc_conn_ac_set_p_flag_1(sk, skb); 209 } 210 out: 211 return rc; 212 free: 213 kfree_skb(nskb); 214 goto out; 215 } 216 217 int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) 218 { 219 int rc = -ENOBUFS; 220 struct llc_sock *llc = llc_sk(sk); 221 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 222 223 if (nskb) { 224 struct llc_sap *sap = llc->sap; 225 u8 f_bit; 226 227 llc_pdu_decode_pf_bit(skb, &f_bit); 228 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 229 llc->daddr.lsap, LLC_PDU_RSP); 230 llc_pdu_init_as_dm_rsp(nskb, f_bit); 231 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 232 if (unlikely(rc)) 233 goto free; 234 llc_conn_send_pdu(sk, nskb); 235 } 236 out: 237 return rc; 238 free: 239 kfree_skb(nskb); 240 goto out; 241 } 242 243 int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 244 { 245 int rc = -ENOBUFS; 246 struct llc_sock *llc = llc_sk(sk); 247 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 248 249 if (nskb) { 250 struct llc_sap *sap = llc->sap; 251 252 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 253 llc->daddr.lsap, LLC_PDU_RSP); 254 llc_pdu_init_as_dm_rsp(nskb, 1); 255 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 256 if (unlikely(rc)) 257 goto free; 258 llc_conn_send_pdu(sk, nskb); 259 } 260 out: 261 return rc; 262 free: 263 kfree_skb(nskb); 264 goto out; 265 } 266 267 int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb) 268 { 269 u8 f_bit; 270 int rc = -ENOBUFS; 271 struct sk_buff *nskb; 272 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 273 struct llc_sock *llc = llc_sk(sk); 274 275 llc->rx_pdu_hdr = *((u32 *)pdu); 276 if (LLC_PDU_IS_CMD(pdu)) 277 llc_pdu_decode_pf_bit(skb, &f_bit); 278 else 279 f_bit = 0; 280 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 281 sizeof(struct llc_frmr_info)); 282 if (nskb) { 283 struct llc_sap *sap = llc->sap; 284 285 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 286 llc->daddr.lsap, LLC_PDU_RSP); 287 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, 288 llc->vR, INCORRECT); 289 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 290 if (unlikely(rc)) 291 goto free; 292 llc_conn_send_pdu(sk, nskb); 293 } 294 out: 295 return rc; 296 free: 297 kfree_skb(nskb); 298 goto out; 299 } 300 301 int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb) 302 { 303 int rc = -ENOBUFS; 304 struct llc_sock *llc = llc_sk(sk); 305 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 306 sizeof(struct llc_frmr_info)); 307 308 if (nskb) { 309 struct llc_sap *sap = llc->sap; 310 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr; 311 312 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 313 llc->daddr.lsap, LLC_PDU_RSP); 314 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS, 315 llc->vR, INCORRECT); 316 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 317 if (unlikely(rc)) 318 goto free; 319 llc_conn_send_pdu(sk, nskb); 320 } 321 out: 322 return rc; 323 free: 324 kfree_skb(nskb); 325 goto out; 326 } 327 328 int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) 329 { 330 u8 f_bit; 331 int rc = -ENOBUFS; 332 struct sk_buff *nskb; 333 struct llc_sock *llc = llc_sk(sk); 334 335 llc_pdu_decode_pf_bit(skb, &f_bit); 336 nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 337 sizeof(struct llc_frmr_info)); 338 if (nskb) { 339 struct llc_sap *sap = llc->sap; 340 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 341 342 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 343 llc->daddr.lsap, LLC_PDU_RSP); 344 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, 345 llc->vR, INCORRECT); 346 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 347 if (unlikely(rc)) 348 goto free; 349 llc_conn_send_pdu(sk, nskb); 350 } 351 out: 352 return rc; 353 free: 354 kfree_skb(nskb); 355 goto out; 356 } 357 358 int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 359 { 360 int rc; 361 struct llc_sock *llc = llc_sk(sk); 362 struct llc_sap *sap = llc->sap; 363 364 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, 365 llc->daddr.lsap, LLC_PDU_CMD); 366 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR); 367 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 368 if (likely(!rc)) { 369 skb_get(skb); 370 llc_conn_send_pdu(sk, skb); 371 llc_conn_ac_inc_vs_by_1(sk, skb); 372 } 373 return rc; 374 } 375 376 static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb) 377 { 378 int rc; 379 struct llc_sock *llc = llc_sk(sk); 380 struct llc_sap *sap = llc->sap; 381 382 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, 383 llc->daddr.lsap, LLC_PDU_CMD); 384 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 385 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 386 if (likely(!rc)) { 387 skb_get(skb); 388 llc_conn_send_pdu(sk, skb); 389 llc_conn_ac_inc_vs_by_1(sk, skb); 390 } 391 return rc; 392 } 393 394 int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 395 { 396 int rc; 397 struct llc_sock *llc = llc_sk(sk); 398 struct llc_sap *sap = llc->sap; 399 400 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, 401 llc->daddr.lsap, LLC_PDU_CMD); 402 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 403 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 404 if (likely(!rc)) { 405 skb_get(skb); 406 llc_conn_send_pdu(sk, skb); 407 llc_conn_ac_inc_vs_by_1(sk, skb); 408 } 409 return 0; 410 } 411 412 int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 413 { 414 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 415 u8 nr = LLC_I_GET_NR(pdu); 416 417 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); 418 return 0; 419 } 420 421 int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk, 422 struct sk_buff *skb) 423 { 424 u8 nr; 425 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 426 int rc = -ENOBUFS; 427 struct llc_sock *llc = llc_sk(sk); 428 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 429 430 if (nskb) { 431 struct llc_sap *sap = llc->sap; 432 433 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 434 llc->daddr.lsap, LLC_PDU_RSP); 435 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 436 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 437 if (likely(!rc)) 438 llc_conn_send_pdu(sk, nskb); 439 else 440 kfree_skb(skb); 441 } 442 if (rc) { 443 nr = LLC_I_GET_NR(pdu); 444 rc = 0; 445 llc_conn_resend_i_pdu_as_cmd(sk, nr, 0); 446 } 447 return rc; 448 } 449 450 int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 451 { 452 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 453 u8 nr = LLC_I_GET_NR(pdu); 454 455 llc_conn_resend_i_pdu_as_rsp(sk, nr, 1); 456 return 0; 457 } 458 459 int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 460 { 461 int rc = -ENOBUFS; 462 struct llc_sock *llc = llc_sk(sk); 463 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 464 465 if (nskb) { 466 struct llc_sap *sap = llc->sap; 467 468 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 469 llc->daddr.lsap, LLC_PDU_CMD); 470 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR); 471 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 472 if (unlikely(rc)) 473 goto free; 474 llc_conn_send_pdu(sk, nskb); 475 } 476 out: 477 return rc; 478 free: 479 kfree_skb(nskb); 480 goto out; 481 } 482 483 int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 484 { 485 int rc = -ENOBUFS; 486 struct llc_sock *llc = llc_sk(sk); 487 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 488 489 if (nskb) { 490 struct llc_sap *sap = llc->sap; 491 492 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 493 llc->daddr.lsap, LLC_PDU_RSP); 494 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR); 495 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 496 if (unlikely(rc)) 497 goto free; 498 llc_conn_send_pdu(sk, nskb); 499 } 500 out: 501 return rc; 502 free: 503 kfree_skb(nskb); 504 goto out; 505 } 506 507 int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 508 { 509 int rc = -ENOBUFS; 510 struct llc_sock *llc = llc_sk(sk); 511 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 512 513 if (nskb) { 514 struct llc_sap *sap = llc->sap; 515 516 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 517 llc->daddr.lsap, LLC_PDU_RSP); 518 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR); 519 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 520 if (unlikely(rc)) 521 goto free; 522 llc_conn_send_pdu(sk, nskb); 523 } 524 out: 525 return rc; 526 free: 527 kfree_skb(nskb); 528 goto out; 529 } 530 531 int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 532 { 533 int rc = -ENOBUFS; 534 struct llc_sock *llc = llc_sk(sk); 535 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 536 537 if (nskb) { 538 struct llc_sap *sap = llc->sap; 539 540 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 541 llc->daddr.lsap, LLC_PDU_CMD); 542 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR); 543 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 544 if (unlikely(rc)) 545 goto free; 546 llc_conn_send_pdu(sk, nskb); 547 } 548 out: 549 return rc; 550 free: 551 kfree_skb(nskb); 552 goto out; 553 } 554 555 int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 556 { 557 int rc = -ENOBUFS; 558 struct llc_sock *llc = llc_sk(sk); 559 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 560 561 if (nskb) { 562 struct llc_sap *sap = llc->sap; 563 564 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 565 llc->daddr.lsap, LLC_PDU_RSP); 566 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR); 567 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 568 if (unlikely(rc)) 569 goto free; 570 llc_conn_send_pdu(sk, nskb); 571 } 572 out: 573 return rc; 574 free: 575 kfree_skb(nskb); 576 goto out; 577 } 578 579 int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 580 { 581 int rc = -ENOBUFS; 582 struct llc_sock *llc = llc_sk(sk); 583 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 584 585 if (nskb) { 586 struct llc_sap *sap = llc->sap; 587 588 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 589 llc->daddr.lsap, LLC_PDU_RSP); 590 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); 591 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 592 if (unlikely(rc)) 593 goto free; 594 llc_conn_send_pdu(sk, nskb); 595 } 596 out: 597 return rc; 598 free: 599 kfree_skb(nskb); 600 goto out; 601 } 602 603 int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb) 604 { 605 struct llc_sock *llc = llc_sk(sk); 606 607 if (!llc->remote_busy_flag) { 608 llc->remote_busy_flag = 1; 609 mod_timer(&llc->busy_state_timer.timer, 610 jiffies + llc->busy_state_timer.expire); 611 } 612 return 0; 613 } 614 615 int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 616 { 617 int rc = -ENOBUFS; 618 struct llc_sock *llc = llc_sk(sk); 619 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 620 621 if (nskb) { 622 struct llc_sap *sap = llc->sap; 623 624 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 625 llc->daddr.lsap, LLC_PDU_RSP); 626 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); 627 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 628 if (unlikely(rc)) 629 goto free; 630 llc_conn_send_pdu(sk, nskb); 631 } 632 out: 633 return rc; 634 free: 635 kfree_skb(nskb); 636 goto out; 637 } 638 639 int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 640 { 641 int rc = -ENOBUFS; 642 struct llc_sock *llc = llc_sk(sk); 643 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 644 645 if (nskb) { 646 struct llc_sap *sap = llc->sap; 647 648 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 649 llc->daddr.lsap, LLC_PDU_CMD); 650 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR); 651 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 652 if (unlikely(rc)) 653 goto free; 654 llc_conn_send_pdu(sk, nskb); 655 } 656 out: 657 return rc; 658 free: 659 kfree_skb(nskb); 660 goto out; 661 } 662 663 int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 664 { 665 int rc = -ENOBUFS; 666 struct llc_sock *llc = llc_sk(sk); 667 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 668 669 if (nskb) { 670 struct llc_sap *sap = llc->sap; 671 u8 f_bit = 1; 672 673 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 674 llc->daddr.lsap, LLC_PDU_RSP); 675 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); 676 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 677 if (unlikely(rc)) 678 goto free; 679 llc_conn_send_pdu(sk, nskb); 680 } 681 out: 682 return rc; 683 free: 684 kfree_skb(nskb); 685 goto out; 686 } 687 688 int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 689 { 690 int rc = -ENOBUFS; 691 struct llc_sock *llc = llc_sk(sk); 692 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 693 694 if (nskb) { 695 struct llc_sap *sap = llc->sap; 696 697 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 698 llc->daddr.lsap, LLC_PDU_RSP); 699 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR); 700 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 701 if (unlikely(rc)) 702 goto free; 703 llc_conn_send_pdu(sk, nskb); 704 } 705 out: 706 return rc; 707 free: 708 kfree_skb(nskb); 709 goto out; 710 } 711 712 int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 713 { 714 int rc = -ENOBUFS; 715 struct llc_sock *llc = llc_sk(sk); 716 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 717 718 if (nskb) { 719 struct llc_sap *sap = llc->sap; 720 721 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 722 llc->daddr.lsap, LLC_PDU_RSP); 723 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 724 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 725 if (unlikely(rc)) 726 goto free; 727 llc_conn_send_pdu(sk, nskb); 728 } 729 out: 730 return rc; 731 free: 732 kfree_skb(nskb); 733 goto out; 734 } 735 736 int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 737 { 738 int rc = -ENOBUFS; 739 struct llc_sock *llc = llc_sk(sk); 740 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 741 742 if (nskb) { 743 struct llc_sap *sap = llc->sap; 744 745 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 746 llc->daddr.lsap, LLC_PDU_RSP); 747 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 748 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 749 if (unlikely(rc)) 750 goto free; 751 llc_conn_send_pdu(sk, nskb); 752 } 753 out: 754 return rc; 755 free: 756 kfree_skb(nskb); 757 goto out; 758 } 759 760 void llc_conn_set_p_flag(struct sock *sk, u8 value) 761 { 762 int state_changed = llc_sk(sk)->p_flag && !value; 763 764 llc_sk(sk)->p_flag = value; 765 766 if (state_changed) 767 sk->sk_state_change(sk); 768 } 769 770 int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) 771 { 772 int rc = -ENOBUFS; 773 struct llc_sock *llc = llc_sk(sk); 774 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 775 776 if (nskb) { 777 struct llc_sap *sap = llc->sap; 778 const u8 *dmac = llc->daddr.mac; 779 780 if (llc->dev->flags & IFF_LOOPBACK) 781 dmac = llc->dev->dev_addr; 782 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 783 llc->daddr.lsap, LLC_PDU_CMD); 784 llc_pdu_init_as_sabme_cmd(nskb, 1); 785 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac); 786 if (unlikely(rc)) 787 goto free; 788 llc_conn_send_pdu(sk, nskb); 789 llc_conn_set_p_flag(sk, 1); 790 } 791 out: 792 return rc; 793 free: 794 kfree_skb(nskb); 795 goto out; 796 } 797 798 int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) 799 { 800 u8 f_bit; 801 int rc = -ENOBUFS; 802 struct llc_sock *llc = llc_sk(sk); 803 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0); 804 805 llc_pdu_decode_pf_bit(skb, &f_bit); 806 if (nskb) { 807 struct llc_sap *sap = llc->sap; 808 809 nskb->dev = llc->dev; 810 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 811 llc->daddr.lsap, LLC_PDU_RSP); 812 llc_pdu_init_as_ua_rsp(nskb, f_bit); 813 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 814 if (unlikely(rc)) 815 goto free; 816 llc_conn_send_pdu(sk, nskb); 817 } 818 out: 819 return rc; 820 free: 821 kfree_skb(nskb); 822 goto out; 823 } 824 825 int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb) 826 { 827 llc_sk(sk)->s_flag = 0; 828 return 0; 829 } 830 831 int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb) 832 { 833 llc_sk(sk)->s_flag = 1; 834 return 0; 835 } 836 837 int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb) 838 { 839 struct llc_sock *llc = llc_sk(sk); 840 841 llc_conn_set_p_flag(sk, 1); 842 mod_timer(&llc->pf_cycle_timer.timer, 843 jiffies + llc->pf_cycle_timer.expire); 844 return 0; 845 } 846 847 /** 848 * llc_conn_ac_send_ack_if_needed - check if ack is needed 849 * @sk: current connection structure 850 * @skb: current event 851 * 852 * Checks number of received PDUs which have not been acknowledged, yet, 853 * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then 854 * sends an RR response as acknowledgement for them. Returns 0 for 855 * success, 1 otherwise. 856 */ 857 int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb) 858 { 859 u8 pf_bit; 860 struct llc_sock *llc = llc_sk(sk); 861 862 llc_pdu_decode_pf_bit(skb, &pf_bit); 863 llc->ack_pf |= pf_bit & 1; 864 if (!llc->ack_must_be_send) { 865 llc->first_pdu_Ns = llc->vR; 866 llc->ack_must_be_send = 1; 867 llc->ack_pf = pf_bit & 1; 868 } 869 if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO) 870 % LLC_2_SEQ_NBR_MODULO) >= llc->npta) { 871 llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb); 872 llc->ack_must_be_send = 0; 873 llc->ack_pf = 0; 874 llc_conn_ac_inc_npta_value(sk, skb); 875 } 876 return 0; 877 } 878 879 /** 880 * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag 881 * @sk: current connection structure 882 * @skb: current event 883 * 884 * This action resets ack_must_be_send flag of given connection, this flag 885 * indicates if there is any PDU which has not been acknowledged yet. 886 * Returns 0 for success, 1 otherwise. 887 */ 888 int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb) 889 { 890 llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0; 891 return 0; 892 } 893 894 /** 895 * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs 896 * @sk: current connection structure 897 * @skb: current event 898 * 899 * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to 900 * all received PDUs which have not been acknowledged, yet. ack_pf flag is 901 * set to one if one PDU with p-bit set to one is received. Returns 0 for 902 * success, 1 otherwise. 903 */ 904 static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk, 905 struct sk_buff *skb) 906 { 907 int rc; 908 struct llc_sock *llc = llc_sk(sk); 909 struct llc_sap *sap = llc->sap; 910 911 llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap, 912 llc->daddr.lsap, LLC_PDU_RSP); 913 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR); 914 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 915 if (likely(!rc)) { 916 skb_get(skb); 917 llc_conn_send_pdu(sk, skb); 918 llc_conn_ac_inc_vs_by_1(sk, skb); 919 } 920 return rc; 921 } 922 923 /** 924 * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs 925 * @sk: current connection structure. 926 * @skb: current event. 927 * 928 * This action sends an I-format PDU as acknowledge to received PDUs which 929 * have not been acknowledged, yet, if there is any. By using of this 930 * action number of acknowledgements decreases, this technic is called 931 * piggy backing. Returns 0 for success, 1 otherwise. 932 */ 933 int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb) 934 { 935 struct llc_sock *llc = llc_sk(sk); 936 int ret; 937 938 if (llc->ack_must_be_send) { 939 ret = llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb); 940 llc->ack_must_be_send = 0 ; 941 llc->ack_pf = 0; 942 } else { 943 ret = llc_conn_ac_send_i_cmd_p_set_0(sk, skb); 944 } 945 946 return ret; 947 } 948 949 /** 950 * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked 951 * @sk: current connection structure. 952 * @skb: current event. 953 * 954 * This action sends an RR response with f-bit set to ack_pf flag as 955 * acknowledge to all received PDUs which have not been acknowledged, yet, 956 * if there is any. ack_pf flag indicates if a PDU has been received with 957 * p-bit set to one. Returns 0 for success, 1 otherwise. 958 */ 959 static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk, 960 struct sk_buff *skb) 961 { 962 int rc = -ENOBUFS; 963 struct llc_sock *llc = llc_sk(sk); 964 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0); 965 966 if (nskb) { 967 struct llc_sap *sap = llc->sap; 968 969 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 970 llc->daddr.lsap, LLC_PDU_RSP); 971 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR); 972 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 973 if (unlikely(rc)) 974 goto free; 975 llc_conn_send_pdu(sk, nskb); 976 } 977 out: 978 return rc; 979 free: 980 kfree_skb(nskb); 981 goto out; 982 } 983 984 /** 985 * llc_conn_ac_inc_npta_value - tries to make value of npta greater 986 * @sk: current connection structure. 987 * @skb: current event. 988 * 989 * After "inc_cntr" times calling of this action, "npta" increase by one. 990 * this action tries to make vale of "npta" greater as possible; number of 991 * acknowledgements decreases by increasing of "npta". Returns 0 for 992 * success, 1 otherwise. 993 */ 994 static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb) 995 { 996 struct llc_sock *llc = llc_sk(sk); 997 998 if (!llc->inc_cntr) { 999 llc->dec_step = 0; 1000 llc->dec_cntr = llc->inc_cntr = 2; 1001 ++llc->npta; 1002 if (llc->npta > LLC_2_SEQ_NBR_MODULO - 1) 1003 llc->npta = LLC_2_SEQ_NBR_MODULO - 1; 1004 } else 1005 --llc->inc_cntr; 1006 return 0; 1007 } 1008 1009 /** 1010 * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one 1011 * @sk: current connection structure. 1012 * @skb: current event. 1013 * 1014 * After receiving "dec_cntr" times RR command, this action decreases 1015 * "npta" by one. Returns 0 for success, 1 otherwise. 1016 */ 1017 int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb) 1018 { 1019 struct llc_sock *llc = llc_sk(sk); 1020 1021 if (!llc->connect_step && !llc->remote_busy_flag) { 1022 if (!llc->dec_step) { 1023 if (!llc->dec_cntr) { 1024 llc->inc_cntr = llc->dec_cntr = 2; 1025 if (llc->npta > 0) 1026 llc->npta = llc->npta - 1; 1027 } else 1028 llc->dec_cntr -=1; 1029 } 1030 } else 1031 llc->connect_step = 0 ; 1032 return 0; 1033 } 1034 1035 /** 1036 * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one 1037 * @sk: current connection structure. 1038 * @skb: current event. 1039 * 1040 * After receiving "dec_cntr" times RNR command, this action decreases 1041 * "npta" by one. Returns 0 for success, 1 otherwise. 1042 */ 1043 int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb) 1044 { 1045 struct llc_sock *llc = llc_sk(sk); 1046 1047 if (llc->remote_busy_flag) 1048 if (!llc->dec_step) { 1049 if (!llc->dec_cntr) { 1050 llc->inc_cntr = llc->dec_cntr = 2; 1051 if (llc->npta > 0) 1052 --llc->npta; 1053 } else 1054 --llc->dec_cntr; 1055 } 1056 return 0; 1057 } 1058 1059 /** 1060 * llc_conn_ac_dec_tx_win_size - decreases tx window size 1061 * @sk: current connection structure. 1062 * @skb: current event. 1063 * 1064 * After receiving of a REJ command or response, transmit window size is 1065 * decreased by number of PDUs which are outstanding yet. Returns 0 for 1066 * success, 1 otherwise. 1067 */ 1068 int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb) 1069 { 1070 struct llc_sock *llc = llc_sk(sk); 1071 u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q); 1072 1073 if (llc->k - unacked_pdu < 1) 1074 llc->k = 1; 1075 else 1076 llc->k -= unacked_pdu; 1077 return 0; 1078 } 1079 1080 /** 1081 * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1 1082 * @sk: current connection structure. 1083 * @skb: current event. 1084 * 1085 * After receiving an RR response with f-bit set to one, transmit window 1086 * size is increased by one. Returns 0 for success, 1 otherwise. 1087 */ 1088 int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb) 1089 { 1090 struct llc_sock *llc = llc_sk(sk); 1091 1092 llc->k += 1; 1093 if (llc->k > LLC_2_SEQ_NBR_MODULO - 1) 1094 llc->k = LLC_2_SEQ_NBR_MODULO - 1; 1095 return 0; 1096 } 1097 1098 int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb) 1099 { 1100 llc_sk_stop_all_timers(sk, false); 1101 return 0; 1102 } 1103 1104 int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb) 1105 { 1106 struct llc_sock *llc = llc_sk(sk); 1107 1108 timer_delete(&llc->rej_sent_timer.timer); 1109 timer_delete(&llc->pf_cycle_timer.timer); 1110 timer_delete(&llc->busy_state_timer.timer); 1111 llc->ack_must_be_send = 0; 1112 llc->ack_pf = 0; 1113 return 0; 1114 } 1115 1116 int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb) 1117 { 1118 struct llc_sock *llc = llc_sk(sk); 1119 1120 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire); 1121 return 0; 1122 } 1123 1124 int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb) 1125 { 1126 struct llc_sock *llc = llc_sk(sk); 1127 1128 mod_timer(&llc->rej_sent_timer.timer, 1129 jiffies + llc->rej_sent_timer.expire); 1130 return 0; 1131 } 1132 1133 int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk, 1134 struct sk_buff *skb) 1135 { 1136 struct llc_sock *llc = llc_sk(sk); 1137 1138 if (!timer_pending(&llc->ack_timer.timer)) 1139 mod_timer(&llc->ack_timer.timer, 1140 jiffies + llc->ack_timer.expire); 1141 return 0; 1142 } 1143 1144 int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb) 1145 { 1146 timer_delete(&llc_sk(sk)->ack_timer.timer); 1147 return 0; 1148 } 1149 1150 int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb) 1151 { 1152 struct llc_sock *llc = llc_sk(sk); 1153 1154 timer_delete(&llc->pf_cycle_timer.timer); 1155 llc_conn_set_p_flag(sk, 0); 1156 return 0; 1157 } 1158 1159 int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb) 1160 { 1161 timer_delete(&llc_sk(sk)->rej_sent_timer.timer); 1162 return 0; 1163 } 1164 1165 int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb) 1166 { 1167 int acked; 1168 u16 unacked = 0; 1169 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 1170 struct llc_sock *llc = llc_sk(sk); 1171 1172 llc->last_nr = PDU_SUPV_GET_Nr(pdu); 1173 acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked); 1174 /* On loopback we don't queue I frames in unack_pdu_q queue. */ 1175 if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) { 1176 llc->retry_count = 0; 1177 timer_delete(&llc->ack_timer.timer); 1178 if (llc->failed_data_req) { 1179 /* already, we did not accept data from upper layer 1180 * (tx_window full or unacceptable state). Now, we 1181 * can send data and must inform to upper layer. 1182 */ 1183 llc->failed_data_req = 0; 1184 llc_conn_ac_data_confirm(sk, skb); 1185 } 1186 if (unacked) 1187 mod_timer(&llc->ack_timer.timer, 1188 jiffies + llc->ack_timer.expire); 1189 } else if (llc->failed_data_req) { 1190 u8 f_bit; 1191 1192 llc_pdu_decode_pf_bit(skb, &f_bit); 1193 if (f_bit == 1) { 1194 llc->failed_data_req = 0; 1195 llc_conn_ac_data_confirm(sk, skb); 1196 } 1197 } 1198 return 0; 1199 } 1200 1201 int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb) 1202 { 1203 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 1204 1205 if (LLC_PDU_IS_RSP(pdu)) { 1206 u8 f_bit; 1207 1208 llc_pdu_decode_pf_bit(skb, &f_bit); 1209 if (f_bit) { 1210 llc_conn_set_p_flag(sk, 0); 1211 llc_conn_ac_stop_p_timer(sk, skb); 1212 } 1213 } 1214 return 0; 1215 } 1216 1217 int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb) 1218 { 1219 llc_sk(sk)->data_flag = 2; 1220 return 0; 1221 } 1222 1223 int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb) 1224 { 1225 llc_sk(sk)->data_flag = 0; 1226 return 0; 1227 } 1228 1229 int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb) 1230 { 1231 llc_sk(sk)->data_flag = 1; 1232 return 0; 1233 } 1234 1235 int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk, 1236 struct sk_buff *skb) 1237 { 1238 if (!llc_sk(sk)->data_flag) 1239 llc_sk(sk)->data_flag = 1; 1240 return 0; 1241 } 1242 1243 int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb) 1244 { 1245 llc_conn_set_p_flag(sk, 0); 1246 return 0; 1247 } 1248 1249 static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb) 1250 { 1251 llc_conn_set_p_flag(sk, 1); 1252 return 0; 1253 } 1254 1255 int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb) 1256 { 1257 llc_sk(sk)->remote_busy_flag = 0; 1258 return 0; 1259 } 1260 1261 int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb) 1262 { 1263 llc_sk(sk)->cause_flag = 0; 1264 return 0; 1265 } 1266 1267 int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb) 1268 { 1269 llc_sk(sk)->cause_flag = 1; 1270 return 0; 1271 } 1272 1273 int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb) 1274 { 1275 llc_sk(sk)->retry_count = 0; 1276 return 0; 1277 } 1278 1279 int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb) 1280 { 1281 llc_sk(sk)->retry_count++; 1282 return 0; 1283 } 1284 1285 int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb) 1286 { 1287 llc_sk(sk)->vR = 0; 1288 return 0; 1289 } 1290 1291 int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb) 1292 { 1293 llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR); 1294 return 0; 1295 } 1296 1297 int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb) 1298 { 1299 llc_sk(sk)->vS = 0; 1300 return 0; 1301 } 1302 1303 int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb) 1304 { 1305 llc_sk(sk)->vS = llc_sk(sk)->last_nr; 1306 return 0; 1307 } 1308 1309 static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb) 1310 { 1311 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO; 1312 return 0; 1313 } 1314 1315 static void llc_conn_tmr_common_cb(struct sock *sk, u8 type) 1316 { 1317 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); 1318 1319 bh_lock_sock(sk); 1320 if (skb) { 1321 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 1322 1323 skb_set_owner_r(skb, sk); 1324 ev->type = type; 1325 llc_process_tmr_ev(sk, skb); 1326 } 1327 bh_unlock_sock(sk); 1328 } 1329 1330 void llc_conn_pf_cycle_tmr_cb(struct timer_list *t) 1331 { 1332 struct llc_sock *llc = timer_container_of(llc, t, 1333 pf_cycle_timer.timer); 1334 1335 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_P_TMR); 1336 } 1337 1338 void llc_conn_busy_tmr_cb(struct timer_list *t) 1339 { 1340 struct llc_sock *llc = timer_container_of(llc, t, 1341 busy_state_timer.timer); 1342 1343 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_BUSY_TMR); 1344 } 1345 1346 void llc_conn_ack_tmr_cb(struct timer_list *t) 1347 { 1348 struct llc_sock *llc = timer_container_of(llc, t, ack_timer.timer); 1349 1350 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_ACK_TMR); 1351 } 1352 1353 void llc_conn_rej_tmr_cb(struct timer_list *t) 1354 { 1355 struct llc_sock *llc = timer_container_of(llc, t, 1356 rej_sent_timer.timer); 1357 1358 llc_conn_tmr_common_cb(&llc->sk, LLC_CONN_EV_TYPE_REJ_TMR); 1359 } 1360 1361 int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb) 1362 { 1363 llc_sk(sk)->X = llc_sk(sk)->vS; 1364 llc_conn_ac_set_vs_nr(sk, skb); 1365 return 0; 1366 } 1367 1368 int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb) 1369 { 1370 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 1371 u8 nr = PDU_SUPV_GET_Nr(pdu); 1372 1373 if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X)) 1374 llc_conn_ac_set_vs_nr(sk, skb); 1375 return 0; 1376 } 1377 1378 /* 1379 * Non-standard actions; these not contained in IEEE specification; for 1380 * our own usage 1381 */ 1382 /** 1383 * llc_conn_disc - removes connection from SAP list and frees it 1384 * @sk: closed connection 1385 * @skb: occurred event 1386 */ 1387 int llc_conn_disc(struct sock *sk, struct sk_buff *skb) 1388 { 1389 /* FIXME: this thing seems to want to die */ 1390 return 0; 1391 } 1392 1393 /** 1394 * llc_conn_reset - resets connection 1395 * @sk : reseting connection. 1396 * @skb: occurred event. 1397 * 1398 * Stop all timers, empty all queues and reset all flags. 1399 */ 1400 int llc_conn_reset(struct sock *sk, struct sk_buff *skb) 1401 { 1402 llc_sk_reset(sk); 1403 return 0; 1404 } 1405 1406 /** 1407 * llc_circular_between - designates that b is between a and c or not 1408 * @a: lower bound 1409 * @b: element to see if is between a and b 1410 * @c: upper bound 1411 * 1412 * This function designates that b is between a and c or not (for example, 1413 * 0 is between 127 and 1). Returns 1 if b is between a and c, 0 1414 * otherwise. 1415 */ 1416 u8 llc_circular_between(u8 a, u8 b, u8 c) 1417 { 1418 b = b - a; 1419 c = c - a; 1420 return b <= c; 1421 } 1422 1423 /** 1424 * llc_process_tmr_ev - timer backend 1425 * @sk: active connection 1426 * @skb: occurred event 1427 * 1428 * This function is called from timer callback functions. When connection 1429 * is busy (during sending a data frame) timer expiration event must be 1430 * queued. Otherwise this event can be sent to connection state machine. 1431 * Queued events will process by llc_backlog_rcv function after sending 1432 * data frame. 1433 */ 1434 static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb) 1435 { 1436 if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) { 1437 printk(KERN_WARNING "%s: timer called on closed connection\n", 1438 __func__); 1439 kfree_skb(skb); 1440 } else { 1441 if (!sock_owned_by_user(sk)) 1442 llc_conn_state_process(sk, skb); 1443 else { 1444 llc_set_backlog_type(skb, LLC_EVENT); 1445 __sk_add_backlog(sk, skb); 1446 } 1447 } 1448 } 1449