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