2 * llc_c_ev.c - Connection component state transition event qualifiers
4 * A 'state' consists of a number of possible event matching functions,
5 * the actions associated with each being executed when that event is
6 * matched; a 'state machine' accepts events in a serial fashion from an
7 * event queue. Each event is passed to each successive event matching
8 * function until a match is made (the event matching function returns
9 * success, or '0') or the list of event matching functions is exhausted.
10 * If a match is made, the actions associated with the event are executed
11 * and the state is changed to that event's transition state. Before some
12 * events are recognized, even after a match has been made, a certain
13 * number of 'event qualifier' functions must also be executed. If these
14 * all execute successfully, then the event is finally executed.
16 * These event functions must return 0 for success, to show a matched
17 * event, of 1 if the event does not match. Event qualifier functions
18 * must return a 0 for success or a non-zero for failure. Each function
19 * is simply responsible for verifying one single thing and returning
20 * either a success or failure.
22 * All of followed event functions are described in 802.2 LLC Protocol
23 * standard document except two functions that we added that will explain
24 * in their comments, at below.
26 * Copyright (c) 1997 by Procom Technology, Inc.
27 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
29 * This program can be redistributed or modified under the terms of the
30 * GNU General Public License as published by the Free Software Foundation.
31 * This program is distributed without any warranty or implied warranty
32 * of merchantability or fitness for a particular purpose.
34 * See the GNU General Public License for more details.
36 #include <linux/netdevice.h>
37 #include <net/llc_conn.h>
38 #include <net/llc_sap.h>
40 #include <net/llc_c_ev.h>
41 #include <net/llc_pdu.h>
44 #define dprintk(args...) printk(KERN_DEBUG args)
46 #define dprintk(args...)
49 extern u16
llc_circular_between(u8 a
, u8 b
, u8 c
);
52 * llc_util_ns_inside_rx_window - check if sequence number is in rx window
53 * @ns: sequence number of received pdu.
54 * @vr: sequence number which receiver expects to receive.
55 * @rw: receive window size of receiver.
57 * Checks if sequence number of received PDU is in range of receive
58 * window. Returns 0 for success, 1 otherwise
60 static u16
llc_util_ns_inside_rx_window(u8 ns
, u8 vr
, u8 rw
)
62 return !llc_circular_between(vr
, ns
,
63 (vr
+ rw
- 1) % LLC_2_SEQ_NBR_MODULO
);
67 * llc_util_nr_inside_tx_window - check if sequence number is in tx window
68 * @sk: current connection.
69 * @nr: N(R) of received PDU.
71 * This routine checks if N(R) of received PDU is in range of transmit
72 * window; on the other hand checks if received PDU acknowledges some
73 * outstanding PDUs that are in transmit window. Returns 0 for success, 1
76 static u16
llc_util_nr_inside_tx_window(struct sock
*sk
, u8 nr
)
80 struct llc_pdu_sn
*pdu
;
81 struct llc_sock
*llc
= llc_sk(sk
);
84 if (llc
->dev
->flags
& IFF_LOOPBACK
)
87 if (!skb_queue_len(&llc
->pdu_unack_q
))
89 skb
= skb_peek(&llc
->pdu_unack_q
);
90 pdu
= llc_pdu_sn_hdr(skb
);
91 nr1
= LLC_I_GET_NS(pdu
);
92 skb
= skb_peek_tail(&llc
->pdu_unack_q
);
93 pdu
= llc_pdu_sn_hdr(skb
);
94 nr2
= LLC_I_GET_NS(pdu
);
95 rc
= !llc_circular_between(nr1
, nr
, (nr2
+ 1) % LLC_2_SEQ_NBR_MODULO
);
100 int llc_conn_ev_conn_req(struct sock
*sk
, struct sk_buff
*skb
)
102 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
104 return ev
->prim
== LLC_CONN_PRIM
&&
105 ev
->prim_type
== LLC_PRIM_TYPE_REQ
? 0 : 1;
108 int llc_conn_ev_data_req(struct sock
*sk
, struct sk_buff
*skb
)
110 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
112 return ev
->prim
== LLC_DATA_PRIM
&&
113 ev
->prim_type
== LLC_PRIM_TYPE_REQ
? 0 : 1;
116 int llc_conn_ev_disc_req(struct sock
*sk
, struct sk_buff
*skb
)
118 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
120 return ev
->prim
== LLC_DISC_PRIM
&&
121 ev
->prim_type
== LLC_PRIM_TYPE_REQ
? 0 : 1;
124 int llc_conn_ev_rst_req(struct sock
*sk
, struct sk_buff
*skb
)
126 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
128 return ev
->prim
== LLC_RESET_PRIM
&&
129 ev
->prim_type
== LLC_PRIM_TYPE_REQ
? 0 : 1;
132 int llc_conn_ev_local_busy_detected(struct sock
*sk
, struct sk_buff
*skb
)
134 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
136 return ev
->type
== LLC_CONN_EV_TYPE_SIMPLE
&&
137 ev
->prim_type
== LLC_CONN_EV_LOCAL_BUSY_DETECTED
? 0 : 1;
140 int llc_conn_ev_local_busy_cleared(struct sock
*sk
, struct sk_buff
*skb
)
142 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
144 return ev
->type
== LLC_CONN_EV_TYPE_SIMPLE
&&
145 ev
->prim_type
== LLC_CONN_EV_LOCAL_BUSY_CLEARED
? 0 : 1;
148 int llc_conn_ev_rx_bad_pdu(struct sock
*sk
, struct sk_buff
*skb
)
153 int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
155 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
157 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_U(pdu
) &&
158 LLC_U_PDU_CMD(pdu
) == LLC_2_PDU_CMD_DISC
? 0 : 1;
161 int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
163 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
165 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_U(pdu
) &&
166 LLC_U_PDU_RSP(pdu
) == LLC_2_PDU_RSP_DM
? 0 : 1;
169 int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
171 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
173 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_U(pdu
) &&
174 LLC_U_PDU_RSP(pdu
) == LLC_2_PDU_RSP_FRMR
? 0 : 1;
177 int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
179 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
181 return llc_conn_space(sk
, skb
) &&
182 LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
183 LLC_I_PF_IS_0(pdu
) &&
184 LLC_I_GET_NS(pdu
) == llc_sk(sk
)->vR
? 0 : 1;
187 int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
189 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
191 return llc_conn_space(sk
, skb
) &&
192 LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
193 LLC_I_PF_IS_1(pdu
) &&
194 LLC_I_GET_NS(pdu
) == llc_sk(sk
)->vR
? 0 : 1;
197 int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock
*sk
,
200 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
201 u8 vr
= llc_sk(sk
)->vR
;
202 u8 ns
= LLC_I_GET_NS(pdu
);
204 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
205 LLC_I_PF_IS_0(pdu
) && ns
!= vr
&&
206 !llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
209 int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock
*sk
,
212 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
213 u8 vr
= llc_sk(sk
)->vR
;
214 u8 ns
= LLC_I_GET_NS(pdu
);
216 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
217 LLC_I_PF_IS_1(pdu
) && ns
!= vr
&&
218 !llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
221 int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock
*sk
,
224 struct llc_pdu_sn
* pdu
= llc_pdu_sn_hdr(skb
);
225 u8 vr
= llc_sk(sk
)->vR
;
226 u8 ns
= LLC_I_GET_NS(pdu
);
227 u16 rc
= LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) && ns
!= vr
&&
228 llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
230 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n",
231 __FUNCTION__
, llc_sk(sk
)->state
, ns
, vr
);
235 int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
237 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
239 return llc_conn_space(sk
, skb
) &&
240 LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
241 LLC_I_PF_IS_0(pdu
) &&
242 LLC_I_GET_NS(pdu
) == llc_sk(sk
)->vR
? 0 : 1;
245 int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
247 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
249 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
250 LLC_I_PF_IS_1(pdu
) &&
251 LLC_I_GET_NS(pdu
) == llc_sk(sk
)->vR
? 0 : 1;
254 int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
256 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
258 return llc_conn_space(sk
, skb
) &&
259 LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
260 LLC_I_GET_NS(pdu
) == llc_sk(sk
)->vR
? 0 : 1;
263 int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock
*sk
,
266 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
267 u8 vr
= llc_sk(sk
)->vR
;
268 u8 ns
= LLC_I_GET_NS(pdu
);
270 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
271 LLC_I_PF_IS_0(pdu
) && ns
!= vr
&&
272 !llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
275 int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock
*sk
,
278 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
279 u8 vr
= llc_sk(sk
)->vR
;
280 u8 ns
= LLC_I_GET_NS(pdu
);
282 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) &&
283 LLC_I_PF_IS_1(pdu
) && ns
!= vr
&&
284 !llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
287 int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock
*sk
,
290 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
291 u8 vr
= llc_sk(sk
)->vR
;
292 u8 ns
= LLC_I_GET_NS(pdu
);
294 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) && ns
!= vr
&&
295 !llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
298 int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock
*sk
,
301 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
302 u8 vr
= llc_sk(sk
)->vR
;
303 u8 ns
= LLC_I_GET_NS(pdu
);
304 u16 rc
= LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_I(pdu
) && ns
!= vr
&&
305 llc_util_ns_inside_rx_window(ns
, vr
, llc_sk(sk
)->rw
) ? 0 : 1;
307 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n",
308 __FUNCTION__
, llc_sk(sk
)->state
, ns
, vr
);
312 int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
314 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
316 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
317 LLC_S_PF_IS_0(pdu
) &&
318 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_REJ
? 0 : 1;
321 int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
323 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
325 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
326 LLC_S_PF_IS_1(pdu
) &&
327 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_REJ
? 0 : 1;
330 int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
332 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
334 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
335 LLC_S_PF_IS_0(pdu
) &&
336 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_REJ
? 0 : 1;
339 int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
341 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
343 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
344 LLC_S_PF_IS_1(pdu
) &&
345 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_REJ
? 0 : 1;
348 int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
350 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
352 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
353 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_REJ
? 0 : 1;
356 int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
358 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
360 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
361 LLC_S_PF_IS_0(pdu
) &&
362 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_RNR
? 0 : 1;
365 int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
367 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
369 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
370 LLC_S_PF_IS_1(pdu
) &&
371 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_RNR
? 0 : 1;
374 int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
376 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
378 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
379 LLC_S_PF_IS_0(pdu
) &&
380 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_RNR
? 0 : 1;
383 int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
385 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
387 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
388 LLC_S_PF_IS_1(pdu
) &&
389 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_RNR
? 0 : 1;
392 int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
394 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
396 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
397 LLC_S_PF_IS_0(pdu
) &&
398 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_RR
? 0 : 1;
401 int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
403 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
405 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
406 LLC_S_PF_IS_1(pdu
) &&
407 LLC_S_PDU_CMD(pdu
) == LLC_2_PDU_CMD_RR
? 0 : 1;
410 int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock
*sk
, struct sk_buff
*skb
)
412 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
414 return llc_conn_space(sk
, skb
) &&
415 LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
416 LLC_S_PF_IS_0(pdu
) &&
417 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_RR
? 0 : 1;
420 int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
422 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
424 return llc_conn_space(sk
, skb
) &&
425 LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_S(pdu
) &&
426 LLC_S_PF_IS_1(pdu
) &&
427 LLC_S_PDU_RSP(pdu
) == LLC_2_PDU_RSP_RR
? 0 : 1;
430 int llc_conn_ev_rx_sabme_cmd_pbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
432 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
434 return LLC_PDU_IS_CMD(pdu
) && LLC_PDU_TYPE_IS_U(pdu
) &&
435 LLC_U_PDU_CMD(pdu
) == LLC_2_PDU_CMD_SABME
? 0 : 1;
438 int llc_conn_ev_rx_ua_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
440 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
442 return LLC_PDU_IS_RSP(pdu
) && LLC_PDU_TYPE_IS_U(pdu
) &&
443 LLC_U_PDU_RSP(pdu
) == LLC_2_PDU_RSP_UA
? 0 : 1;
446 int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
449 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
451 if (LLC_PDU_IS_CMD(pdu
)) {
452 if (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
)) {
453 if (LLC_I_PF_IS_1(pdu
))
455 } else if (LLC_PDU_TYPE_IS_U(pdu
) && LLC_U_PF_IS_1(pdu
))
461 int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
464 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
466 if (LLC_PDU_IS_CMD(pdu
)) {
467 if (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
))
469 else if (LLC_PDU_TYPE_IS_U(pdu
))
470 switch (LLC_U_PDU_CMD(pdu
)) {
471 case LLC_2_PDU_CMD_SABME
:
472 case LLC_2_PDU_CMD_DISC
:
480 int llc_conn_ev_rx_xxx_rsp_fbit_set_1(struct sock
*sk
, struct sk_buff
*skb
)
483 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
485 if (LLC_PDU_IS_RSP(pdu
)) {
486 if (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
)) {
487 if (LLC_I_PF_IS_1(pdu
))
489 } else if (LLC_PDU_TYPE_IS_U(pdu
))
490 switch (LLC_U_PDU_RSP(pdu
)) {
491 case LLC_2_PDU_RSP_UA
:
492 case LLC_2_PDU_RSP_DM
:
493 case LLC_2_PDU_RSP_FRMR
:
494 if (LLC_U_PF_IS_1(pdu
))
502 int llc_conn_ev_rx_xxx_rsp_fbit_set_x(struct sock
*sk
, struct sk_buff
*skb
)
505 struct llc_pdu_un
*pdu
= llc_pdu_un_hdr(skb
);
507 if (LLC_PDU_IS_RSP(pdu
)) {
508 if (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
))
510 else if (LLC_PDU_TYPE_IS_U(pdu
))
511 switch (LLC_U_PDU_RSP(pdu
)) {
512 case LLC_2_PDU_RSP_UA
:
513 case LLC_2_PDU_RSP_DM
:
514 case LLC_2_PDU_RSP_FRMR
:
523 int llc_conn_ev_rx_zzz_cmd_pbit_set_x_inval_nr(struct sock
*sk
,
527 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
528 u8 vs
= llc_sk(sk
)->vS
;
529 u8 nr
= LLC_I_GET_NR(pdu
);
531 if (LLC_PDU_IS_CMD(pdu
) &&
532 (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
)) &&
533 nr
!= vs
&& llc_util_nr_inside_tx_window(sk
, nr
)) {
534 dprintk("%s: matched, state=%d, vs=%d, nr=%d\n",
535 __FUNCTION__
, llc_sk(sk
)->state
, vs
, nr
);
541 int llc_conn_ev_rx_zzz_rsp_fbit_set_x_inval_nr(struct sock
*sk
,
545 struct llc_pdu_sn
*pdu
= llc_pdu_sn_hdr(skb
);
546 u8 vs
= llc_sk(sk
)->vS
;
547 u8 nr
= LLC_I_GET_NR(pdu
);
549 if (LLC_PDU_IS_RSP(pdu
) &&
550 (LLC_PDU_TYPE_IS_I(pdu
) || LLC_PDU_TYPE_IS_S(pdu
)) &&
551 nr
!= vs
&& llc_util_nr_inside_tx_window(sk
, nr
)) {
553 dprintk("%s: matched, state=%d, vs=%d, nr=%d\n",
554 __FUNCTION__
, llc_sk(sk
)->state
, vs
, nr
);
559 int llc_conn_ev_rx_any_frame(struct sock
*sk
, struct sk_buff
*skb
)
564 int llc_conn_ev_p_tmr_exp(struct sock
*sk
, struct sk_buff
*skb
)
566 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
568 return ev
->type
!= LLC_CONN_EV_TYPE_P_TMR
;
571 int llc_conn_ev_ack_tmr_exp(struct sock
*sk
, struct sk_buff
*skb
)
573 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
575 return ev
->type
!= LLC_CONN_EV_TYPE_ACK_TMR
;
578 int llc_conn_ev_rej_tmr_exp(struct sock
*sk
, struct sk_buff
*skb
)
580 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
582 return ev
->type
!= LLC_CONN_EV_TYPE_REJ_TMR
;
585 int llc_conn_ev_busy_tmr_exp(struct sock
*sk
, struct sk_buff
*skb
)
587 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
589 return ev
->type
!= LLC_CONN_EV_TYPE_BUSY_TMR
;
592 int llc_conn_ev_init_p_f_cycle(struct sock
*sk
, struct sk_buff
*skb
)
597 int llc_conn_ev_tx_buffer_full(struct sock
*sk
, struct sk_buff
*skb
)
599 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
601 return ev
->type
== LLC_CONN_EV_TYPE_SIMPLE
&&
602 ev
->prim_type
== LLC_CONN_EV_TX_BUFF_FULL
? 0 : 1;
605 /* Event qualifier functions
607 * these functions simply verify the value of a state flag associated with
608 * the connection and return either a 0 for success or a non-zero value
609 * for not-success; verify the event is the type we expect
611 int llc_conn_ev_qlfy_data_flag_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
613 return llc_sk(sk
)->data_flag
!= 1;
616 int llc_conn_ev_qlfy_data_flag_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
618 return llc_sk(sk
)->data_flag
;
621 int llc_conn_ev_qlfy_data_flag_eq_2(struct sock
*sk
, struct sk_buff
*skb
)
623 return llc_sk(sk
)->data_flag
!= 2;
626 int llc_conn_ev_qlfy_p_flag_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
628 return llc_sk(sk
)->p_flag
!= 1;
632 * conn_ev_qlfy_last_frame_eq_1 - checks if frame is last in tx window
633 * @sk: current connection structure.
634 * @skb: current event.
636 * This function determines when frame which is sent, is last frame of
637 * transmit window, if it is then this function return zero else return
638 * one. This function is used for sending last frame of transmit window
639 * as I-format command with p-bit set to one. Returns 0 if frame is last
640 * frame, 1 otherwise.
642 int llc_conn_ev_qlfy_last_frame_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
644 return !(skb_queue_len(&llc_sk(sk
)->pdu_unack_q
) + 1 == llc_sk(sk
)->k
);
648 * conn_ev_qlfy_last_frame_eq_0 - checks if frame isn't last in tx window
649 * @sk: current connection structure.
650 * @skb: current event.
652 * This function determines when frame which is sent, isn't last frame of
653 * transmit window, if it isn't then this function return zero else return
654 * one. Returns 0 if frame isn't last frame, 1 otherwise.
656 int llc_conn_ev_qlfy_last_frame_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
658 return skb_queue_len(&llc_sk(sk
)->pdu_unack_q
) + 1 == llc_sk(sk
)->k
;
661 int llc_conn_ev_qlfy_p_flag_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
663 return llc_sk(sk
)->p_flag
;
666 int llc_conn_ev_qlfy_p_flag_eq_f(struct sock
*sk
, struct sk_buff
*skb
)
670 llc_pdu_decode_pf_bit(skb
, &f_bit
);
671 return llc_sk(sk
)->p_flag
== f_bit
? 0 : 1;
674 int llc_conn_ev_qlfy_remote_busy_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
676 return llc_sk(sk
)->remote_busy_flag
;
679 int llc_conn_ev_qlfy_remote_busy_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
681 return !llc_sk(sk
)->remote_busy_flag
;
684 int llc_conn_ev_qlfy_retry_cnt_lt_n2(struct sock
*sk
, struct sk_buff
*skb
)
686 return !(llc_sk(sk
)->retry_count
< llc_sk(sk
)->n2
);
689 int llc_conn_ev_qlfy_retry_cnt_gte_n2(struct sock
*sk
, struct sk_buff
*skb
)
691 return !(llc_sk(sk
)->retry_count
>= llc_sk(sk
)->n2
);
694 int llc_conn_ev_qlfy_s_flag_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
696 return !llc_sk(sk
)->s_flag
;
699 int llc_conn_ev_qlfy_s_flag_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
701 return llc_sk(sk
)->s_flag
;
704 int llc_conn_ev_qlfy_cause_flag_eq_1(struct sock
*sk
, struct sk_buff
*skb
)
706 return !llc_sk(sk
)->cause_flag
;
709 int llc_conn_ev_qlfy_cause_flag_eq_0(struct sock
*sk
, struct sk_buff
*skb
)
711 return llc_sk(sk
)->cause_flag
;
714 int llc_conn_ev_qlfy_set_status_conn(struct sock
*sk
, struct sk_buff
*skb
)
716 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
718 ev
->status
= LLC_STATUS_CONN
;
722 int llc_conn_ev_qlfy_set_status_disc(struct sock
*sk
, struct sk_buff
*skb
)
724 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
726 ev
->status
= LLC_STATUS_DISC
;
730 int llc_conn_ev_qlfy_set_status_failed(struct sock
*sk
, struct sk_buff
*skb
)
732 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
734 ev
->status
= LLC_STATUS_FAILED
;
738 int llc_conn_ev_qlfy_set_status_remote_busy(struct sock
*sk
,
741 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
743 ev
->status
= LLC_STATUS_REMOTE_BUSY
;
747 int llc_conn_ev_qlfy_set_status_refuse(struct sock
*sk
, struct sk_buff
*skb
)
749 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
751 ev
->status
= LLC_STATUS_REFUSE
;
755 int llc_conn_ev_qlfy_set_status_conflict(struct sock
*sk
, struct sk_buff
*skb
)
757 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
759 ev
->status
= LLC_STATUS_CONFLICT
;
763 int llc_conn_ev_qlfy_set_status_rst_done(struct sock
*sk
, struct sk_buff
*skb
)
765 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
767 ev
->status
= LLC_STATUS_RESET_DONE
;