Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / llc / llc_station.c
blob8fe48a24bad5f1606826f57e5e018432fa00881a
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/config.h>
15 #include <linux/init.h>
16 #include <linux/module.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 /* Types of events (possible values in 'ev->type') */
54 #define LLC_STATION_EV_TYPE_SIMPLE 1
55 #define LLC_STATION_EV_TYPE_CONDITION 2
56 #define LLC_STATION_EV_TYPE_PRIM 3
57 #define LLC_STATION_EV_TYPE_PDU 4 /* command/response PDU */
58 #define LLC_STATION_EV_TYPE_ACK_TMR 5
59 #define LLC_STATION_EV_TYPE_RPT_STATUS 6
61 /* Events */
62 #define LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK 1
63 #define LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK 2
64 #define LLC_STATION_EV_ACK_TMR_EXP_LT_RETRY_CNT_MAX_RETRY 3
65 #define LLC_STATION_EV_ACK_TMR_EXP_EQ_RETRY_CNT_MAX_RETRY 4
66 #define LLC_STATION_EV_RX_NULL_DSAP_XID_C 5
67 #define LLC_STATION_EV_RX_NULL_DSAP_0_XID_R_XID_R_CNT_EQ 6
68 #define LLC_STATION_EV_RX_NULL_DSAP_1_XID_R_XID_R_CNT_EQ 7
69 #define LLC_STATION_EV_RX_NULL_DSAP_TEST_C 8
70 #define LLC_STATION_EV_DISABLE_REQ 9
72 struct llc_station_state_ev {
73 u8 type;
74 u8 prim;
75 u8 prim_type;
76 u8 reason;
77 struct list_head node; /* node in station->ev_q.list */
80 static __inline__ struct llc_station_state_ev *
81 llc_station_ev(struct sk_buff *skb)
83 return (struct llc_station_state_ev *)skb->cb;
86 typedef int (*llc_station_ev_t)(struct sk_buff *skb);
88 #define LLC_STATION_STATE_DOWN 1 /* initial state */
89 #define LLC_STATION_STATE_DUP_ADDR_CHK 2
90 #define LLC_STATION_STATE_UP 3
92 #define LLC_NBR_STATION_STATES 3 /* size of state table */
94 typedef int (*llc_station_action_t)(struct sk_buff *skb);
96 /* Station component state table structure */
97 struct llc_station_state_trans {
98 llc_station_ev_t ev;
99 u8 next_state;
100 llc_station_action_t *ev_actions;
103 struct llc_station_state {
104 u8 curr_state;
105 struct llc_station_state_trans **transitions;
108 static struct llc_station llc_main_station;
110 static int llc_stat_ev_enable_with_dup_addr_check(struct sk_buff *skb)
112 struct llc_station_state_ev *ev = llc_station_ev(skb);
114 return ev->type == LLC_STATION_EV_TYPE_SIMPLE &&
115 ev->prim_type ==
116 LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK ? 0 : 1;
119 static int llc_stat_ev_enable_without_dup_addr_check(struct sk_buff *skb)
121 struct llc_station_state_ev *ev = llc_station_ev(skb);
123 return ev->type == LLC_STATION_EV_TYPE_SIMPLE &&
124 ev->prim_type ==
125 LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK ? 0 : 1;
128 static int llc_stat_ev_ack_tmr_exp_lt_retry_cnt_max_retry(struct sk_buff *skb)
130 struct llc_station_state_ev *ev = llc_station_ev(skb);
132 return ev->type == LLC_STATION_EV_TYPE_ACK_TMR &&
133 llc_main_station.retry_count <
134 llc_main_station.maximum_retry ? 0 : 1;
137 static int llc_stat_ev_ack_tmr_exp_eq_retry_cnt_max_retry(struct sk_buff *skb)
139 struct llc_station_state_ev *ev = llc_station_ev(skb);
141 return ev->type == LLC_STATION_EV_TYPE_ACK_TMR &&
142 llc_main_station.retry_count ==
143 llc_main_station.maximum_retry ? 0 : 1;
146 static int llc_stat_ev_rx_null_dsap_xid_c(struct sk_buff *skb)
148 struct llc_station_state_ev *ev = llc_station_ev(skb);
149 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
151 return ev->type == LLC_STATION_EV_TYPE_PDU &&
152 LLC_PDU_IS_CMD(pdu) && /* command PDU */
153 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
154 LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_XID &&
155 !pdu->dsap ? 0 : 1; /* NULL DSAP value */
158 static int llc_stat_ev_rx_null_dsap_0_xid_r_xid_r_cnt_eq(struct sk_buff *skb)
160 struct llc_station_state_ev *ev = llc_station_ev(skb);
161 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
163 return ev->type == LLC_STATION_EV_TYPE_PDU &&
164 LLC_PDU_IS_RSP(pdu) && /* response PDU */
165 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
166 LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID &&
167 !pdu->dsap && /* NULL DSAP value */
168 !llc_main_station.xid_r_count ? 0 : 1;
171 static int llc_stat_ev_rx_null_dsap_1_xid_r_xid_r_cnt_eq(struct sk_buff *skb)
173 struct llc_station_state_ev *ev = llc_station_ev(skb);
174 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
176 return ev->type == LLC_STATION_EV_TYPE_PDU &&
177 LLC_PDU_IS_RSP(pdu) && /* response PDU */
178 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
179 LLC_U_PDU_RSP(pdu) == LLC_1_PDU_CMD_XID &&
180 !pdu->dsap && /* NULL DSAP value */
181 llc_main_station.xid_r_count == 1 ? 0 : 1;
184 static int llc_stat_ev_rx_null_dsap_test_c(struct sk_buff *skb)
186 struct llc_station_state_ev *ev = llc_station_ev(skb);
187 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
189 return ev->type == LLC_STATION_EV_TYPE_PDU &&
190 LLC_PDU_IS_CMD(pdu) && /* command PDU */
191 LLC_PDU_TYPE_IS_U(pdu) && /* U type PDU */
192 LLC_U_PDU_CMD(pdu) == LLC_1_PDU_CMD_TEST &&
193 !pdu->dsap ? 0 : 1; /* NULL DSAP */
196 static int llc_stat_ev_disable_req(struct sk_buff *skb)
198 struct llc_station_state_ev *ev = llc_station_ev(skb);
200 return ev->type == LLC_STATION_EV_TYPE_PRIM &&
201 ev->prim == LLC_DISABLE_PRIM &&
202 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
206 * llc_station_send_pdu - queues PDU to send
207 * @skb: Address of the PDU
209 * Queues a PDU to send to the MAC layer.
211 static void llc_station_send_pdu(struct sk_buff *skb)
213 skb_queue_tail(&llc_main_station.mac_pdu_q, skb);
214 while ((skb = skb_dequeue(&llc_main_station.mac_pdu_q)) != NULL)
215 if (dev_queue_xmit(skb))
216 break;
219 static int llc_station_ac_start_ack_timer(struct sk_buff *skb)
221 mod_timer(&llc_main_station.ack_timer, jiffies + LLC_ACK_TIME * HZ);
222 return 0;
225 static int llc_station_ac_set_retry_cnt_0(struct sk_buff *skb)
227 llc_main_station.retry_count = 0;
228 return 0;
231 static int llc_station_ac_inc_retry_cnt_by_1(struct sk_buff *skb)
233 llc_main_station.retry_count++;
234 return 0;
237 static int llc_station_ac_set_xid_r_cnt_0(struct sk_buff *skb)
239 llc_main_station.xid_r_count = 0;
240 return 0;
243 static int llc_station_ac_inc_xid_r_cnt_by_1(struct sk_buff *skb)
245 llc_main_station.xid_r_count++;
246 return 0;
249 static int llc_station_ac_send_null_dsap_xid_c(struct sk_buff *skb)
251 int rc = 1;
252 struct sk_buff *nskb = llc_alloc_frame();
254 if (!nskb)
255 goto out;
256 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD);
257 llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127);
258 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, llc_station_mac_sa);
259 if (rc)
260 goto free;
261 llc_station_send_pdu(nskb);
262 out:
263 return rc;
264 free:
265 kfree_skb(skb);
266 goto out;
269 static int llc_station_ac_send_xid_r(struct sk_buff *skb)
271 u8 mac_da[ETH_ALEN], dsap;
272 int rc = 1;
273 struct sk_buff* nskb = llc_alloc_frame();
275 if (!nskb)
276 goto out;
277 rc = 0;
278 nskb->dev = skb->dev;
279 llc_pdu_decode_sa(skb, mac_da);
280 llc_pdu_decode_ssap(skb, &dsap);
281 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
282 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
283 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da);
284 if (rc)
285 goto free;
286 llc_station_send_pdu(nskb);
287 out:
288 return rc;
289 free:
290 kfree_skb(skb);
291 goto out;
294 static int llc_station_ac_send_test_r(struct sk_buff *skb)
296 u8 mac_da[ETH_ALEN], dsap;
297 int rc = 1;
298 struct sk_buff *nskb = llc_alloc_frame();
300 if (!nskb)
301 goto out;
302 rc = 0;
303 nskb->dev = skb->dev;
304 llc_pdu_decode_sa(skb, mac_da);
305 llc_pdu_decode_ssap(skb, &dsap);
306 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
307 llc_pdu_init_as_test_rsp(nskb, skb);
308 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da);
309 if (rc)
310 goto free;
311 llc_station_send_pdu(nskb);
312 out:
313 return rc;
314 free:
315 kfree_skb(skb);
316 goto out;
319 static int llc_station_ac_report_status(struct sk_buff *skb)
321 return 0;
324 /* COMMON STATION STATE transitions */
326 /* dummy last-transition indicator; common to all state transition groups
327 * last entry for this state
328 * all members are zeros, .bss zeroes it
330 static struct llc_station_state_trans llc_stat_state_trans_end;
332 /* DOWN STATE transitions */
334 /* state transition for LLC_STATION_EV_ENABLE_WITH_DUP_ADDR_CHECK event */
335 static llc_station_action_t llc_stat_down_state_actions_1[] = {
336 [0] = llc_station_ac_start_ack_timer,
337 [1] = llc_station_ac_set_retry_cnt_0,
338 [2] = llc_station_ac_set_xid_r_cnt_0,
339 [3] = llc_station_ac_send_null_dsap_xid_c,
340 [4] = NULL,
343 static struct llc_station_state_trans llc_stat_down_state_trans_1 = {
344 .ev = llc_stat_ev_enable_with_dup_addr_check,
345 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
346 .ev_actions = llc_stat_down_state_actions_1,
349 /* state transition for LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK event */
350 static llc_station_action_t llc_stat_down_state_actions_2[] = {
351 [0] = llc_station_ac_report_status, /* STATION UP */
352 [1] = NULL,
355 static struct llc_station_state_trans llc_stat_down_state_trans_2 = {
356 .ev = llc_stat_ev_enable_without_dup_addr_check,
357 .next_state = LLC_STATION_STATE_UP,
358 .ev_actions = llc_stat_down_state_actions_2,
361 /* array of pointers; one to each transition */
362 static struct llc_station_state_trans *llc_stat_dwn_state_trans[] = {
363 [0] = &llc_stat_down_state_trans_1,
364 [1] = &llc_stat_down_state_trans_2,
365 [2] = &llc_stat_state_trans_end,
368 /* UP STATE transitions */
369 /* state transition for LLC_STATION_EV_DISABLE_REQ event */
370 static llc_station_action_t llc_stat_up_state_actions_1[] = {
371 [0] = llc_station_ac_report_status, /* STATION DOWN */
372 [1] = NULL,
375 static struct llc_station_state_trans llc_stat_up_state_trans_1 = {
376 .ev = llc_stat_ev_disable_req,
377 .next_state = LLC_STATION_STATE_DOWN,
378 .ev_actions = llc_stat_up_state_actions_1,
381 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
382 static llc_station_action_t llc_stat_up_state_actions_2[] = {
383 [0] = llc_station_ac_send_xid_r,
384 [1] = NULL,
387 static struct llc_station_state_trans llc_stat_up_state_trans_2 = {
388 .ev = llc_stat_ev_rx_null_dsap_xid_c,
389 .next_state = LLC_STATION_STATE_UP,
390 .ev_actions = llc_stat_up_state_actions_2,
393 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_TEST_C event */
394 static llc_station_action_t llc_stat_up_state_actions_3[] = {
395 [0] = llc_station_ac_send_test_r,
396 [1] = NULL,
399 static struct llc_station_state_trans llc_stat_up_state_trans_3 = {
400 .ev = llc_stat_ev_rx_null_dsap_test_c,
401 .next_state = LLC_STATION_STATE_UP,
402 .ev_actions = llc_stat_up_state_actions_3,
405 /* array of pointers; one to each transition */
406 static struct llc_station_state_trans *llc_stat_up_state_trans [] = {
407 [0] = &llc_stat_up_state_trans_1,
408 [1] = &llc_stat_up_state_trans_2,
409 [2] = &llc_stat_up_state_trans_3,
410 [3] = &llc_stat_state_trans_end,
413 /* DUP ADDR CHK STATE transitions */
414 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_0_XID_R_XID_R_CNT_EQ
415 * event
417 static llc_station_action_t llc_stat_dupaddr_state_actions_1[] = {
418 [0] = llc_station_ac_inc_xid_r_cnt_by_1,
419 [1] = NULL,
422 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_1 = {
423 .ev = llc_stat_ev_rx_null_dsap_0_xid_r_xid_r_cnt_eq,
424 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
425 .ev_actions = llc_stat_dupaddr_state_actions_1,
428 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_1_XID_R_XID_R_CNT_EQ
429 * event
431 static llc_station_action_t llc_stat_dupaddr_state_actions_2[] = {
432 [0] = llc_station_ac_report_status, /* DUPLICATE ADDRESS FOUND */
433 [1] = NULL,
436 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_2 = {
437 .ev = llc_stat_ev_rx_null_dsap_1_xid_r_xid_r_cnt_eq,
438 .next_state = LLC_STATION_STATE_DOWN,
439 .ev_actions = llc_stat_dupaddr_state_actions_2,
442 /* state transition for LLC_STATION_EV_RX_NULL_DSAP_XID_C event */
443 static llc_station_action_t llc_stat_dupaddr_state_actions_3[] = {
444 [0] = llc_station_ac_send_xid_r,
445 [1] = NULL,
448 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_3 = {
449 .ev = llc_stat_ev_rx_null_dsap_xid_c,
450 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
451 .ev_actions = llc_stat_dupaddr_state_actions_3,
454 /* state transition for LLC_STATION_EV_ACK_TMR_EXP_LT_RETRY_CNT_MAX_RETRY
455 * event
457 static llc_station_action_t llc_stat_dupaddr_state_actions_4[] = {
458 [0] = llc_station_ac_start_ack_timer,
459 [1] = llc_station_ac_inc_retry_cnt_by_1,
460 [2] = llc_station_ac_set_xid_r_cnt_0,
461 [3] = llc_station_ac_send_null_dsap_xid_c,
462 [4] = NULL,
465 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_4 = {
466 .ev = llc_stat_ev_ack_tmr_exp_lt_retry_cnt_max_retry,
467 .next_state = LLC_STATION_STATE_DUP_ADDR_CHK,
468 .ev_actions = llc_stat_dupaddr_state_actions_4,
471 /* state transition for LLC_STATION_EV_ACK_TMR_EXP_EQ_RETRY_CNT_MAX_RETRY
472 * event
474 static llc_station_action_t llc_stat_dupaddr_state_actions_5[] = {
475 [0] = llc_station_ac_report_status, /* STATION UP */
476 [1] = NULL,
479 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_5 = {
480 .ev = llc_stat_ev_ack_tmr_exp_eq_retry_cnt_max_retry,
481 .next_state = LLC_STATION_STATE_UP,
482 .ev_actions = llc_stat_dupaddr_state_actions_5,
485 /* state transition for LLC_STATION_EV_DISABLE_REQ event */
486 static llc_station_action_t llc_stat_dupaddr_state_actions_6[] = {
487 [0] = llc_station_ac_report_status, /* STATION DOWN */
488 [1] = NULL,
491 static struct llc_station_state_trans llc_stat_dupaddr_state_trans_6 = {
492 .ev = llc_stat_ev_disable_req,
493 .next_state = LLC_STATION_STATE_DOWN,
494 .ev_actions = llc_stat_dupaddr_state_actions_6,
497 /* array of pointers; one to each transition */
498 static struct llc_station_state_trans *llc_stat_dupaddr_state_trans[] = {
499 [0] = &llc_stat_dupaddr_state_trans_6, /* Request */
500 [1] = &llc_stat_dupaddr_state_trans_4, /* Timer */
501 [2] = &llc_stat_dupaddr_state_trans_5,
502 [3] = &llc_stat_dupaddr_state_trans_1, /* Receive frame */
503 [4] = &llc_stat_dupaddr_state_trans_2,
504 [5] = &llc_stat_dupaddr_state_trans_3,
505 [6] = &llc_stat_state_trans_end,
508 static struct llc_station_state
509 llc_station_state_table[LLC_NBR_STATION_STATES] = {
510 [LLC_STATION_STATE_DOWN - 1] = {
511 .curr_state = LLC_STATION_STATE_DOWN,
512 .transitions = llc_stat_dwn_state_trans,
514 [LLC_STATION_STATE_DUP_ADDR_CHK - 1] = {
515 .curr_state = LLC_STATION_STATE_DUP_ADDR_CHK,
516 .transitions = llc_stat_dupaddr_state_trans,
518 [LLC_STATION_STATE_UP - 1] = {
519 .curr_state = LLC_STATION_STATE_UP,
520 .transitions = llc_stat_up_state_trans,
525 * llc_exec_station_trans_actions - executes actions for transition
526 * @trans: Address of the transition
527 * @skb: Address of the event that caused the transition
529 * Executes actions of a transition of the station state machine. Returns
530 * 0 if all actions complete successfully, nonzero otherwise.
532 static u16 llc_exec_station_trans_actions(struct llc_station_state_trans *trans,
533 struct sk_buff *skb)
535 u16 rc = 0;
536 llc_station_action_t *next_action = trans->ev_actions;
538 for (; next_action && *next_action; next_action++)
539 if ((*next_action)(skb))
540 rc = 1;
541 return rc;
545 * llc_find_station_trans - finds transition for this event
546 * @skb: Address of the event
548 * Search thru events of the current state of the station until list
549 * exhausted or it's obvious that the event is not valid for the current
550 * state. Returns the address of the transition if cound, %NULL otherwise.
552 static struct llc_station_state_trans *
553 llc_find_station_trans(struct sk_buff *skb)
555 int i = 0;
556 struct llc_station_state_trans *rc = NULL;
557 struct llc_station_state_trans **next_trans;
558 struct llc_station_state *curr_state =
559 &llc_station_state_table[llc_main_station.state - 1];
561 for (next_trans = curr_state->transitions; next_trans[i]->ev; i++)
562 if (!next_trans[i]->ev(skb)) {
563 rc = next_trans[i];
564 break;
566 return rc;
570 * llc_station_free_ev - frees an event
571 * @skb: Address of the event
573 * Frees an event.
575 static void llc_station_free_ev(struct sk_buff *skb)
577 struct llc_station_state_ev *ev = llc_station_ev(skb);
579 if (ev->type == LLC_STATION_EV_TYPE_PDU)
580 kfree_skb(skb);
584 * llc_station_next_state - processes event and goes to the next state
585 * @skb: Address of the event
587 * Processes an event, executes any transitions related to that event and
588 * updates the state of the station.
590 static u16 llc_station_next_state(struct sk_buff *skb)
592 u16 rc = 1;
593 struct llc_station_state_trans *trans;
595 if (llc_main_station.state > LLC_NBR_STATION_STATES)
596 goto out;
597 trans = llc_find_station_trans(skb);
598 if (trans) {
599 /* got the state to which we next transition; perform the
600 * actions associated with this transition before actually
601 * transitioning to the next state
603 rc = llc_exec_station_trans_actions(trans, skb);
604 if (!rc)
605 /* transition station to next state if all actions
606 * execute successfully; done; wait for next event
608 llc_main_station.state = trans->next_state;
609 } else
610 /* event not recognized in current state; re-queue it for
611 * processing again at a later time; return failure
613 rc = 0;
614 out:
615 llc_station_free_ev(skb);
616 return rc;
620 * llc_station_service_events - service events in the queue
622 * Get an event from the station event queue (if any); attempt to service
623 * the event; if event serviced, get the next event (if any) on the event
624 * queue; if event not service, re-queue the event on the event queue and
625 * attempt to service the next event; when serviced all events in queue,
626 * finished; if don't transition to different state, just service all
627 * events once; if transition to new state, service all events again.
628 * Caller must hold llc_main_station.ev_q.lock.
630 static void llc_station_service_events(void)
632 struct sk_buff *skb;
634 while ((skb = skb_dequeue(&llc_main_station.ev_q.list)) != NULL)
635 llc_station_next_state(skb);
639 * llc_station_state_process: queue event and try to process queue.
640 * @skb: Address of the event
642 * Queues an event (on the station event queue) for handling by the
643 * station state machine and attempts to process any queued-up events.
645 static void llc_station_state_process(struct sk_buff *skb)
647 spin_lock_bh(&llc_main_station.ev_q.lock);
648 skb_queue_tail(&llc_main_station.ev_q.list, skb);
649 llc_station_service_events();
650 spin_unlock_bh(&llc_main_station.ev_q.lock);
653 static void llc_station_ack_tmr_cb(unsigned long timeout_data)
655 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
657 if (skb) {
658 struct llc_station_state_ev *ev = llc_station_ev(skb);
660 ev->type = LLC_STATION_EV_TYPE_ACK_TMR;
661 llc_station_state_process(skb);
666 * llc_station_rcv - send received pdu to the station state machine
667 * @skb: received frame.
669 * Sends data unit to station state machine.
671 static void llc_station_rcv(struct sk_buff *skb)
673 struct llc_station_state_ev *ev = llc_station_ev(skb);
675 ev->type = LLC_STATION_EV_TYPE_PDU;
676 ev->reason = 0;
677 llc_station_state_process(skb);
680 int __init llc_station_init(void)
682 u16 rc = -ENOBUFS;
683 struct sk_buff *skb;
684 struct llc_station_state_ev *ev;
686 skb_queue_head_init(&llc_main_station.mac_pdu_q);
687 skb_queue_head_init(&llc_main_station.ev_q.list);
688 spin_lock_init(&llc_main_station.ev_q.lock);
689 init_timer(&llc_main_station.ack_timer);
690 llc_main_station.ack_timer.data = (unsigned long)&llc_main_station;
691 llc_main_station.ack_timer.function = llc_station_ack_tmr_cb;
693 skb = alloc_skb(0, GFP_ATOMIC);
694 if (!skb)
695 goto out;
696 rc = 0;
697 llc_set_station_handler(llc_station_rcv);
698 ev = llc_station_ev(skb);
699 memset(ev, 0, sizeof(*ev));
700 llc_main_station.ack_timer.expires = jiffies + 3 * HZ;
701 llc_main_station.maximum_retry = 1;
702 llc_main_station.state = LLC_STATION_STATE_DOWN;
703 ev->type = LLC_STATION_EV_TYPE_SIMPLE;
704 ev->prim_type = LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK;
705 rc = llc_station_next_state(skb);
706 out:
707 return rc;
710 void __exit llc_station_exit(void)
712 llc_set_station_handler(NULL);