llc2: Remove pointless indirection through llc_stat_state_trans_end
[linux-2.6.git] / net / llc / llc_station.c
blobe16c1b96e527ed1429f0b88f6109fba72074d88d
1 /*
2 * llc_station.c - station component of LLC
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License as published by the Free Software Foundation.
9 * This program is distributed without any warranty or implied warranty
10 * of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 #include <linux/init.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <net/llc.h>
18 #include <net/llc_sap.h>
19 #include <net/llc_conn.h>
20 #include <net/llc_c_ac.h>
21 #include <net/llc_s_ac.h>
22 #include <net/llc_c_ev.h>
23 #include <net/llc_c_st.h>
24 #include <net/llc_s_ev.h>
25 #include <net/llc_s_st.h>
26 #include <net/llc_pdu.h>
28 /**
29 * struct llc_station - LLC station component
31 * SAP and connection resource manager, one per adapter.
33 * @state: state of station
34 * @xid_r_count: XID response PDU counter
35 * @mac_sa: MAC source address
36 * @sap_list: list of related SAPs
37 * @ev_q: events entering state mach.
38 * @mac_pdu_q: PDUs ready to send to MAC
40 struct llc_station {
41 u8 state;
42 u8 xid_r_count;
43 struct timer_list ack_timer;
44 u8 retry_count;
45 u8 maximum_retry;
46 struct {
47 struct sk_buff_head list;
48 spinlock_t lock;
49 } ev_q;
50 struct sk_buff_head mac_pdu_q;
53 #define LLC_STATION_ACK_TIME (3 * HZ)
55 int sysctl_llc_station_ack_timeout = LLC_STATION_ACK_TIME;
57 /* Types of events (possible values in 'ev->type') */
58 #define LLC_STATION_EV_TYPE_SIMPLE 1
59 #define LLC_STATION_EV_TYPE_CONDITION 2
60 #define LLC_STATION_EV_TYPE_PRIM 3
61 #define LLC_STATION_EV_TYPE_PDU 4 /* command/response PDU */
62 #define LLC_STATION_EV_TYPE_ACK_TMR 5
63 #define LLC_STATION_EV_TYPE_RPT_STATUS 6
65 /* Events */
66 #define LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK 1
67 #define LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK 2
68 #define LLC_STATION_EV_ACK_TMR_EXP_LT_RETRY_CNT_MAX_RETRY 3
69 #define LLC_STATION_EV_ACK_TMR_EXP_EQ_RETRY_CNT_MAX_RETRY 4
70 #define LLC_STATION_EV_RX_NULL_DSAP_XID_C 5
71 #define LLC_STATION_EV_RX_NULL_DSAP_0_XID_R_XID_R_CNT_EQ 6
72 #define LLC_STATION_EV_RX_NULL_DSAP_1_XID_R_XID_R_CNT_EQ 7
73 #define LLC_STATION_EV_RX_NULL_DSAP_TEST_C 8
74 #define LLC_STATION_EV_DISABLE_REQ 9
76 struct llc_station_state_ev {
77 u8 type;
78 u8 prim;
79 u8 prim_type;
80 u8 reason;
81 struct list_head node; /* node in station->ev_q.list */
84 static __inline__ struct llc_station_state_ev *
85 llc_station_ev(struct sk_buff *skb)
87 return (struct llc_station_state_ev *)skb->cb;
90 typedef int (*llc_station_ev_t)(struct sk_buff *skb);
92 #define LLC_STATION_STATE_DOWN 1 /* initial state */
93 #define LLC_STATION_STATE_DUP_ADDR_CHK 2
94 #define LLC_STATION_STATE_UP 3
96 #define LLC_NBR_STATION_STATES 3 /* size of state table */
98 typedef int (*llc_station_action_t)(struct sk_buff *skb);
100 /* Station component state table structure */
101 struct llc_station_state_trans {
102 llc_station_ev_t ev;
103 u8 next_state;
104 llc_station_action_t *ev_actions;
107 struct llc_station_state {
108 u8 curr_state;
109 struct llc_station_state_trans **transitions;
112 static struct llc_station llc_main_station;
114 static int llc_stat_ev_enable_with_dup_addr_check(struct sk_buff *skb)
116 struct llc_station_state_ev *ev = llc_station_ev(skb);
118 return ev->type == LLC_STATION_EV_TYPE_SIMPLE &&
119 ev->prim_type ==
120 LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK ? 0 : 1;
123 static int llc_stat_ev_enable_without_dup_addr_check(struct sk_buff *skb)
125 struct llc_station_state_ev *ev = llc_station_ev(skb);
127 return ev->type == LLC_STATION_EV_TYPE_SIMPLE &&
128 ev->prim_type ==
129 LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK ? 0 : 1;
132 static int llc_stat_ev_ack_tmr_exp_lt_retry_cnt_max_retry(struct sk_buff *skb)
134 struct llc_station_state_ev *ev = llc_station_ev(skb);
136 return ev->type == LLC_STATION_EV_TYPE_ACK_TMR &&
137 llc_main_station.retry_count <
138 llc_main_station.maximum_retry ? 0 : 1;
141 static int llc_stat_ev_ack_tmr_exp_eq_retry_cnt_max_retry(struct sk_buff *skb)
143 struct llc_station_state_ev *ev = llc_station_ev(skb);
145 return ev->type == LLC_STATION_EV_TYPE_ACK_TMR &&
146 llc_main_station.retry_count ==
147 llc_main_station.maximum_retry ? 0 : 1;
150 static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb)
152 struct llc_station_state_ev *ev = llc_station_ev(skb);
153 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
155 return ev->type == LLC_STATION_EV_TYPE_PDU &&
156 LLC_PDU_IS_CMD(pdu) && /* command PDU */
157 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
158 LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID &&
159 !pdu->dsap ? 0 : 1; /* NULL DSAP value */
162 static int llc_stat_ev_rx_null_dsap_0_xid_r_xid_r_cnt_eq(struct sk_buff *skb)
164 struct llc_station_state_ev *ev = llc_station_ev(skb);
165 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
167 return ev->type == LLC_STATION_EV_TYPE_PDU &&
168 LLC_PDU_IS_RSP(pdu) && /* response PDU */
169 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
170 LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID &&
171 !pdu->dsap && /* NULL DSAP value */
172 !llc_main_station.xid_r_count ? 0 : 1;
175 static int llc_stat_ev_rx_null_dsap_1_xid_r_xid_r_cnt_eq(struct sk_buff *skb)
177 struct llc_station_state_ev *ev = llc_station_ev(skb);
178 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
180 return ev->type == LLC_STATION_EV_TYPE_PDU &&
181 LLC_PDU_IS_RSP(pdu) && /* response PDU */
182 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
183 LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID &&
184 !pdu->dsap && /* NULL DSAP value */
185 llc_main_station.xid_r_count == 1 ? 0 : 1;
188 static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb)
190 struct llc_station_state_ev *ev = llc_station_ev(skb);
191 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
193 return ev->type == LLC_STATION_EV_TYPE_PDU &&
194 LLC_PDU_IS_CMD(pdu) && /* command PDU */
195 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
196 LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST &&
197 !pdu->dsap ? 0 : 1; /* NULL DSAP */
200 static int llc_stat_ev_disable_req(struct sk_buff *skb)
202 struct llc_station_state_ev *ev = llc_station_ev(skb);
204 return ev->type == LLC_STATION_EV_TYPE_PRIM &&
205 ev->prim == LLC_DISABLE_PRIM &&
206 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
210 * llc_station_send_pdu - queues PDU to send
211 * @skb: Address of the PDU
213 * Queues a PDU to send to the MAC layer.
215 static void llc_station_send_pdu(struct sk_buff *skb)
217 skb_queue_tail(&llc_main_station.mac_pdu_q, skb);
218 while ((skb = skb_dequeue(&llc_main_station.mac_pdu_q)) != NULL)
219 if (dev_queue_xmit(skb))
220 break;
223 static int llc_station_ac_start_ack_timer(struct sk_buff *skb)
225 mod_timer(&llc_main_station.ack_timer,
226 jiffies + sysctl_llc_station_ack_timeout);
227 return 0;
230 static int llc_station_ac_set_retry_cnt_0(struct sk_buff *skb)
232 llc_main_station.retry_count = 0;
233 return 0;
236 static int llc_station_ac_inc_retry_cnt_by_1(struct sk_buff *skb)
238 llc_main_station.retry_count++;
239 return 0;
242 static int llc_station_ac_set_xid_r_cnt_0(struct sk_buff *skb)
244 llc_main_station.xid_r_count = 0;
245 return 0;
248 static int llc_station_ac_inc_xid_r_cnt_by_1(struct sk_buff *skb)
250 llc_main_station.xid_r_count++;
251 return 0;
254 static int llc_station_ac_send_null_dsap_xid_c(struct sk_buff *skb)
256 int rc = 1;
257 struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
258 sizeof(struct llc_xid_info));
260 if (!nskb)
261 goto out;
262 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD);
263 llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127);
264 rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, skb->dev->dev_addr);
265 if (unlikely(rc))
266 goto free;
267 llc_station_send_pdu(nskb);
268 out:
269 return rc;
270 free:
271 kfree_skb(nskb);
272 goto out;
275 static int llc_station_ac_send_xid_r(struct sk_buff *skb)
277 u8 mac_da[ETH_ALEN], dsap;
278 int rc = 1;
279 struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U,
280 sizeof(struct llc_xid_info));
282 if (!nskb)
283 goto out;
284 rc = 0;
285 llc_pdu_decode_sa(skb, mac_da);
286 llc_pdu_decode_ssap(skb, &dsap);
287 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
288 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
289 rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da);
290 if (unlikely(rc))
291 goto free;
292 llc_station_send_pdu(nskb);
293 out:
294 return rc;
295 free:
296 kfree_skb(nskb);
297 goto out;
300 static int llc_station_ac_send_test_r(struct sk_buff *skb)
302 u8 mac_da[ETH_ALEN], dsap;
303 int rc = 1;
304 u32 data_size;
305 struct sk_buff *nskb;
307 /* The test request command is type U (llc_len = 3) */
308 data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
309 nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);
311 if (!nskb)
312 goto out;
313 rc = 0;
314 llc_pdu_decode_sa(skb, mac_da);
315 llc_pdu_decode_ssap(skb, &dsap);
316 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
317 llc_pdu_init_as_test_rsp(nskb, skb);
318 rc = llc_mac_hdr_init(nskb, skb->dev->dev_addr, mac_da);
319 if (unlikely(rc))
320 goto free;
321 llc_station_send_pdu(nskb);
322 out:
323 return rc;
324 free:
325 kfree_skb(nskb);
326 goto out;
329 static int llc_station_ac_report_status(struct sk_buff *skb)
331 return 0;
334 /* DOWN STATE transitions */
336 /* state transition for LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK event */
337 static llc_station_action_t llc_stat_down_state_actions_1[] = {
338 [0] = llc_station_ac_start_ack_timer,
339 [1] = llc_station_ac_set_retry_cnt_0,
340 [2] = llc_station_ac_set_xid_r_cnt_0,
341 [3] = llc_station_ac_send_null_dsap_xid_c,
342 [4] = NULL,
345 static struct llc_station_state_trans llc_stat_down_state_trans_1 = {
346 .ev = llc_stat_ev_enable_with_dup_addr_check,
347 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
348 .ev_actions = llc_stat_down_state_actions_1,
351 /* state transition for LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK event */
352 static llc_station_action_t llc_stat_down_state_actions_2[] = {
353 [0] = llc_station_ac_report_status, /* STATION UP */
354 [1] = NULL,
357 static struct llc_station_state_trans llc_stat_down_state_trans_2 = {
358 .ev = llc_stat_ev_enable_without_dup_addr_check,
359 .next_state = LLC_STATION_STATE_UP,
360 .ev_actions = llc_stat_down_state_actions_2,
363 /* array of pointers; one to each transition */
364 static struct llc_station_state_trans *llc_stat_dwn_state_trans[] = {
365 [0] = &llc_stat_down_state_trans_1,
366 [1] = &llc_stat_down_state_trans_2,
367 [2] = NULL,
370 /* UP STATE transitions */
371 /* state transition for LLC_STATION_EV_DISABLE_REQ event */
372 static llc_station_action_t llc_stat_up_state_actions_1[] = {
373 [0] = llc_station_ac_report_status, /* STATION DOWN */
374 [1] = NULL,
377 static struct llc_station_state_trans llc_stat_up_state_trans_1 = {
378 .ev = llc_stat_ev_disable_req,
379 .next_state = LLC_STATION_STATE_DOWN,
380 .ev_actions = llc_stat_up_state_actions_1,
383 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
384 static llc_station_action_t llc_stat_up_state_actions_2[] = {
385 [0] = llc_station_ac_send_xid_r,
386 [1] = NULL,
389 static struct llc_station_state_trans llc_stat_up_state_trans_2 = {
390 .ev = llc_stat_ev_rx_null_dsap_xid_c,
391 .next_state = LLC_STATION_STATE_UP,
392 .ev_actions = llc_stat_up_state_actions_2,
395 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_TEST_C event */
396 static llc_station_action_t llc_stat_up_state_actions_3[] = {
397 [0] = llc_station_ac_send_test_r,
398 [1] = NULL,
401 static struct llc_station_state_trans llc_stat_up_state_trans_3 = {
402 .ev = llc_stat_ev_rx_null_dsap_test_c,
403 .next_state = LLC_STATION_STATE_UP,
404 .ev_actions = llc_stat_up_state_actions_3,
407 /* array of pointers; one to each transition */
408 static struct llc_station_state_trans *llc_stat_up_state_trans [] = {
409 [0] = &llc_stat_up_state_trans_1,
410 [1] = &llc_stat_up_state_trans_2,
411 [2] = &llc_stat_up_state_trans_3,
412 [3] = NULL,
415 /* DUP ADDR CHK STATE transitions */
416 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_0_XID_R_XID_R_CNT_EQ
417 * event
419 static llc_station_action_t llc_stat_dupaddr_state_actions_1[] = {
420 [0] = llc_station_ac_inc_xid_r_cnt_by_1,
421 [1] = NULL,
424 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_1 = {
425 .ev = llc_stat_ev_rx_null_dsap_0_xid_r_xid_r_cnt_eq,
426 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
427 .ev_actions = llc_stat_dupaddr_state_actions_1,
430 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_1_XID_R_XID_R_CNT_EQ
431 * event
433 static llc_station_action_t llc_stat_dupaddr_state_actions_2[] = {
434 [0] = llc_station_ac_report_status, /* DUPLICATE ADDRESS FOUND */
435 [1] = NULL,
438 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_2 = {
439 .ev = llc_stat_ev_rx_null_dsap_1_xid_r_xid_r_cnt_eq,
440 .next_state = LLC_STATION_STATE_DOWN,
441 .ev_actions = llc_stat_dupaddr_state_actions_2,
444 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
445 static llc_station_action_t llc_stat_dupaddr_state_actions_3[] = {
446 [0] = llc_station_ac_send_xid_r,
447 [1] = NULL,
450 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_3 = {
451 .ev = llc_stat_ev_rx_null_dsap_xid_c,
452 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
453 .ev_actions = llc_stat_dupaddr_state_actions_3,
456 /* state transition for LLC_STATION_EV_ACK_TMR_EXP_LT_RETRY_CNT_MAX_RETRY
457 * event
459 static llc_station_action_t llc_stat_dupaddr_state_actions_4[] = {
460 [0] = llc_station_ac_start_ack_timer,
461 [1] = llc_station_ac_inc_retry_cnt_by_1,
462 [2] = llc_station_ac_set_xid_r_cnt_0,
463 [3] = llc_station_ac_send_null_dsap_xid_c,
464 [4] = NULL,
467 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_4 = {
468 .ev = llc_stat_ev_ack_tmr_exp_lt_retry_cnt_max_retry,
469 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
470 .ev_actions = llc_stat_dupaddr_state_actions_4,
473 /* state transition for LLC_STATION_EV_ACK_TMR_EXP_EQ_RETRY_CNT_MAX_RETRY
474 * event
476 static llc_station_action_t llc_stat_dupaddr_state_actions_5[] = {
477 [0] = llc_station_ac_report_status, /* STATION UP */
478 [1] = NULL,
481 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_5 = {
482 .ev = llc_stat_ev_ack_tmr_exp_eq_retry_cnt_max_retry,
483 .next_state = LLC_STATION_STATE_UP,
484 .ev_actions = llc_stat_dupaddr_state_actions_5,
487 /* state transition for LLC_STATION_EV_DISABLE_REQ event */
488 static llc_station_action_t llc_stat_dupaddr_state_actions_6[] = {
489 [0] = llc_station_ac_report_status, /* STATION DOWN */
490 [1] = NULL,
493 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_6 = {
494 .ev = llc_stat_ev_disable_req,
495 .next_state = LLC_STATION_STATE_DOWN,
496 .ev_actions = llc_stat_dupaddr_state_actions_6,
499 /* array of pointers; one to each transition */
500 static struct llc_station_state_trans *llc_stat_dupaddr_state_trans[] = {
501 [0] = &llc_stat_dupaddr_state_trans_6, /* Request */
502 [1] = &llc_stat_dupaddr_state_trans_4, /* Timer */
503 [2] = &llc_stat_dupaddr_state_trans_5,
504 [3] = &llc_stat_dupaddr_state_trans_1, /* Receive frame */
505 [4] = &llc_stat_dupaddr_state_trans_2,
506 [5] = &llc_stat_dupaddr_state_trans_3,
507 [6] = NULL,
510 static struct llc_station_state
511 llc_station_state_table[LLC_NBR_STATION_STATES] = {
512 [LLC_STATION_STATE_DOWN - 1] = {
513 .curr_state = LLC_STATION_STATE_DOWN,
514 .transitions = llc_stat_dwn_state_trans,
516 [LLC_STATION_STATE_DUP_ADDR_CHK - 1] = {
517 .curr_state = LLC_STATION_STATE_DUP_ADDR_CHK,
518 .transitions = llc_stat_dupaddr_state_trans,
520 [LLC_STATION_STATE_UP - 1] = {
521 .curr_state = LLC_STATION_STATE_UP,
522 .transitions = llc_stat_up_state_trans,
527 * llc_exec_station_trans_actions - executes actions for transition
528 * @trans: Address of the transition
529 * @skb: Address of the event that caused the transition
531 * Executes actions of a transition of the station state machine. Returns
532 * 0 if all actions complete successfully, nonzero otherwise.
534 static u16 llc_exec_station_trans_actions(struct llc_station_state_trans *trans,
535 struct sk_buff *skb)
537 u16 rc = 0;
538 llc_station_action_t *next_action = trans->ev_actions;
540 for (; next_action && *next_action; next_action++)
541 if ((*next_action)(skb))
542 rc = 1;
543 return rc;
547 * llc_find_station_trans - finds transition for this event
548 * @skb: Address of the event
550 * Search thru events of the current state of the station until list
551 * exhausted or it's obvious that the event is not valid for the current
552 * state. Returns the address of the transition if cound, %NULL otherwise.
554 static struct llc_station_state_trans *
555 llc_find_station_trans(struct sk_buff *skb)
557 int i = 0;
558 struct llc_station_state_trans *rc = NULL;
559 struct llc_station_state_trans **next_trans;
560 struct llc_station_state *curr_state =
561 &llc_station_state_table[llc_main_station.state - 1];
563 for (next_trans = curr_state->transitions; next_trans[i]; i++)
564 if (!next_trans[i]->ev(skb)) {
565 rc = next_trans[i];
566 break;
568 return rc;
572 * llc_station_free_ev - frees an event
573 * @skb: Address of the event
575 * Frees an event.
577 static void llc_station_free_ev(struct sk_buff *skb)
579 struct llc_station_state_ev *ev = llc_station_ev(skb);
581 if (ev->type == LLC_STATION_EV_TYPE_PDU)
582 kfree_skb(skb);
586 * llc_station_next_state - processes event and goes to the next state
587 * @skb: Address of the event
589 * Processes an event, executes any transitions related to that event and
590 * updates the state of the station.
592 static u16 llc_station_next_state(struct sk_buff *skb)
594 u16 rc = 1;
595 struct llc_station_state_trans *trans;
597 if (llc_main_station.state > LLC_NBR_STATION_STATES)
598 goto out;
599 trans = llc_find_station_trans(skb);
600 if (trans) {
601 /* got the state to which we next transition; perform the
602 * actions associated with this transition before actually
603 * transitioning to the next state
605 rc = llc_exec_station_trans_actions(trans, skb);
606 if (!rc)
607 /* transition station to next state if all actions
608 * execute successfully; done; wait for next event
610 llc_main_station.state = trans->next_state;
611 } else
612 /* event not recognized in current state; re-queue it for
613 * processing again at a later time; return failure
615 rc = 0;
616 out:
617 llc_station_free_ev(skb);
618 return rc;
622 * llc_station_service_events - service events in the queue
624 * Get an event from the station event queue (if any); attempt to service
625 * the event; if event serviced, get the next event (if any) on the event
626 * queue; if event not service, re-queue the event on the event queue and
627 * attempt to service the next event; when serviced all events in queue,
628 * finished; if don't transition to different state, just service all
629 * events once; if transition to new state, service all events again.
630 * Caller must hold llc_main_station.ev_q.lock.
632 static void llc_station_service_events(void)
634 struct sk_buff *skb;
636 while ((skb = skb_dequeue(&llc_main_station.ev_q.list)) != NULL)
637 llc_station_next_state(skb);
641 * llc_station_state_process - queue event and try to process queue.
642 * @skb: Address of the event
644 * Queues an event (on the station event queue) for handling by the
645 * station state machine and attempts to process any queued-up events.
647 static void llc_station_state_process(struct sk_buff *skb)
649 spin_lock_bh(&llc_main_station.ev_q.lock);
650 skb_queue_tail(&llc_main_station.ev_q.list, skb);
651 llc_station_service_events();
652 spin_unlock_bh(&llc_main_station.ev_q.lock);
655 static void llc_station_ack_tmr_cb(unsigned long timeout_data)
657 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
659 if (skb) {
660 struct llc_station_state_ev *ev = llc_station_ev(skb);
662 ev->type = LLC_STATION_EV_TYPE_ACK_TMR;
663 llc_station_state_process(skb);
668 * llc_station_rcv - send received pdu to the station state machine
669 * @skb: received frame.
671 * Sends data unit to station state machine.
673 static void llc_station_rcv(struct sk_buff *skb)
675 struct llc_station_state_ev *ev = llc_station_ev(skb);
677 ev->type = LLC_STATION_EV_TYPE_PDU;
678 ev->reason = 0;
679 llc_station_state_process(skb);
682 void __init llc_station_init(void)
684 skb_queue_head_init(&llc_main_station.mac_pdu_q);
685 skb_queue_head_init(&llc_main_station.ev_q.list);
686 spin_lock_init(&llc_main_station.ev_q.lock);
687 setup_timer(&llc_main_station.ack_timer, llc_station_ack_tmr_cb,
688 (unsigned long)&llc_main_station);
689 llc_main_station.ack_timer.expires = jiffies +
690 sysctl_llc_station_ack_timeout;
691 llc_main_station.maximum_retry = 1;
692 llc_main_station.state = LLC_STATION_STATE_UP;
693 llc_set_station_handler(llc_station_rcv);
696 void llc_station_exit(void)
698 llc_set_station_handler(NULL);