1 /*********************************************************************
3 * Filename: irlpt_srvr_fsm.c
5 * Sources: irlan_event.c
7 * Copyright (c) 1997, Dag Brattli <dagb@cs.uit.no>, All Rights Reserved.
8 * Copyright (c) 1998, Thomas Davis, <ratbert@radiks.net>, All Rights Reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * I, Thomas Davis, provide no warranty for any of this software. This
16 * material is provided "AS-IS" and at no charge.
18 ********************************************************************/
20 #include <net/irda/iriap.h>
21 #include <net/irda/irlmp.h>
22 #include <net/irda/irttp.h>
23 #include <net/irda/irlpt_common.h>
24 #include <net/irda/irlpt_server.h>
25 #include <net/irda/irlpt_server_fsm.h>
26 #include <net/irda/irda.h>
28 static int irlpt_server_state_idle ( struct irlpt_cb
*self
,
31 struct irlpt_info
*info
);
32 static int irlpt_server_state_conn ( struct irlpt_cb
*self
,
35 struct irlpt_info
*info
);
38 static char *rcsid
= "$Id: irlpt_server_fsm.c,v 1.4 1998/10/05 05:46:45 ratbert Exp $";
41 int irlpt_server_fsm_debug
= 3;
43 static int (*irlpt_server_state
[])( struct irlpt_cb
*self
, IRLPT_EVENT event
,
45 struct irlpt_info
*info
) =
47 irlpt_server_state_idle
,
48 irlpt_server_state_conn
,
51 void irlpt_server_do_event( struct irlpt_cb
*self
, IRLPT_EVENT event
,
52 struct sk_buff
*skb
, struct irlpt_info
*info
)
54 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
": STATE = %s, EVENT = %s\n",
55 irlpt_server_fsm_state
[self
->state
], irlpt_fsm_event
[event
]);
57 ASSERT( self
!= NULL
, return;);
58 ASSERT( self
->magic
== IRLPT_MAGIC
, return;);
60 (*irlpt_server_state
[ self
->state
]) ( self
, event
, skb
, info
);
62 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
" -->\n");
65 void irlpt_server_next_state( struct irlpt_cb
*self
, IRLPT_CLIENT_STATE state
)
68 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
": NEXT STATE = %s\n",
69 irlpt_server_fsm_state
[state
]);
71 ASSERT( self
!= NULL
, return;);
72 ASSERT( self
->magic
== IRLPT_MAGIC
, return;);
76 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
" -->\n");
80 * Function server_state_idle (event, skb, info)
82 * IDLE, We are waiting for an indication that there is a provider
85 static int irlpt_server_state_idle( struct irlpt_cb
*self
, IRLPT_EVENT event
,
87 struct irlpt_info
*info
)
89 struct sk_buff
*r_skb
;
91 DEBUG( irlpt_server_fsm_debug
, "--> " __FUNCTION__
":\n");
93 ASSERT( self
!= NULL
, return -1;);
94 ASSERT( self
->magic
== IRLPT_MAGIC
, return -1;);
98 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
99 ": LM_CONNECT, remote lsap=%d\n",
102 self
->dlsap_sel
= info
->dlsap_sel
;
104 r_skb
= dev_alloc_skb(64);
106 printk( KERN_INFO __FUNCTION__
107 ": can't allocate sk_buff of length 64\n");
110 ALLOC_SKB_MAGIC(r_skb
);
111 skb_reserve( r_skb
, LMP_MAX_HEADER
);
113 irlmp_connect_response( self
->lsap
, r_skb
);
114 irlpt_server_next_state( self
, IRLPT_SERVER_CONN
);
119 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
120 ": Unknown event %d (%s)\n",
121 event
, irlpt_fsm_event
[event
]);
129 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
" -->\n");
135 * Function server_state_conn (event, skb, info)
137 * CONN, We have connected to a provider but has not issued any
141 static int irlpt_server_state_conn( struct irlpt_cb
*self
,
144 struct irlpt_info
*info
)
146 DEBUG( irlpt_server_fsm_debug
, "--> " __FUNCTION__
":\n");
148 ASSERT( self
!= NULL
, return -1;);
149 ASSERT( self
->magic
== IRLPT_MAGIC
, return -1;);
154 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
155 ": LMP_DISCONNECT/LAP_DISCONNECT\n");
156 irlpt_server_next_state( self
, IRLPT_SERVER_IDLE
);
160 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
161 ": Unknown event %d (%s)\n",
162 event
, irlpt_fsm_event
[event
]);
170 DEBUG( irlpt_server_fsm_debug
, __FUNCTION__
" -->\n");
176 static void irlpt_server_print_event( IRLPT_EVENT event
)
178 DEBUG( 0, "IRLPT_EVENT = %s\n", irlpt_fsm_event
[event
]);