1 /*********************************************************************
3 * Filename: iriap_event.c
5 * Description: IAP Finite State Machine
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Thu Aug 21 00:02:07 1997
9 * Modified at: Wed Mar 1 11:28:34 2000
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1997, 1999-2000 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * Neither Dag Brattli nor University of Tromsø admit liability nor
22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge.
25 ********************************************************************/
27 #include <net/irda/irda.h>
28 #include <net/irda/irlmp.h>
29 #include <net/irda/iriap.h>
30 #include <net/irda/iriap_event.h>
32 static void state_s_disconnect (struct iriap_cb
*self
, IRIAP_EVENT event
,
34 static void state_s_connecting (struct iriap_cb
*self
, IRIAP_EVENT event
,
36 static void state_s_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
39 static void state_s_make_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
41 static void state_s_calling (struct iriap_cb
*self
, IRIAP_EVENT event
,
43 static void state_s_outstanding (struct iriap_cb
*self
, IRIAP_EVENT event
,
45 static void state_s_replying (struct iriap_cb
*self
, IRIAP_EVENT event
,
47 static void state_s_wait_for_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
49 static void state_s_wait_active (struct iriap_cb
*self
, IRIAP_EVENT event
,
52 static void state_r_disconnect (struct iriap_cb
*self
, IRIAP_EVENT event
,
54 static void state_r_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
56 static void state_r_waiting (struct iriap_cb
*self
, IRIAP_EVENT event
,
58 static void state_r_wait_active (struct iriap_cb
*self
, IRIAP_EVENT event
,
60 static void state_r_receiving (struct iriap_cb
*self
, IRIAP_EVENT event
,
62 static void state_r_execute (struct iriap_cb
*self
, IRIAP_EVENT event
,
64 static void state_r_returning (struct iriap_cb
*self
, IRIAP_EVENT event
,
67 static void (*iriap_state
[])(struct iriap_cb
*self
, IRIAP_EVENT event
,
68 struct sk_buff
*skb
) = {
79 state_s_wait_for_call
,
94 void iriap_next_client_state(struct iriap_cb
*self
, IRIAP_STATE state
)
96 IRDA_ASSERT(self
!= NULL
, return;);
97 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
99 self
->client_state
= state
;
102 void iriap_next_call_state(struct iriap_cb
*self
, IRIAP_STATE state
)
104 IRDA_ASSERT(self
!= NULL
, return;);
105 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
107 self
->call_state
= state
;
110 void iriap_next_server_state(struct iriap_cb
*self
, IRIAP_STATE state
)
112 IRDA_ASSERT(self
!= NULL
, return;);
113 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
115 self
->server_state
= state
;
118 void iriap_next_r_connect_state(struct iriap_cb
*self
, IRIAP_STATE state
)
120 IRDA_ASSERT(self
!= NULL
, return;);
121 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
123 self
->r_connect_state
= state
;
126 void iriap_do_client_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
129 IRDA_ASSERT(self
!= NULL
, return;);
130 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
132 (*iriap_state
[ self
->client_state
]) (self
, event
, skb
);
135 void iriap_do_call_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
138 IRDA_ASSERT(self
!= NULL
, return;);
139 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
141 (*iriap_state
[ self
->call_state
]) (self
, event
, skb
);
144 void iriap_do_server_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
147 IRDA_ASSERT(self
!= NULL
, return;);
148 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
150 (*iriap_state
[ self
->server_state
]) (self
, event
, skb
);
153 void iriap_do_r_connect_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
156 IRDA_ASSERT(self
!= NULL
, return;);
157 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
159 (*iriap_state
[ self
->r_connect_state
]) (self
, event
, skb
);
164 * Function state_s_disconnect (event, skb)
166 * S-Disconnect, The device has no LSAP connection to a particular
169 static void state_s_disconnect(struct iriap_cb
*self
, IRIAP_EVENT event
,
172 IRDA_ASSERT(self
!= NULL
, return;);
173 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
176 case IAP_CALL_REQUEST_GVBC
:
177 iriap_next_client_state(self
, S_CONNECTING
);
178 IRDA_ASSERT(self
->request_skb
== NULL
, return;);
179 /* Don't forget to refcount it -
180 * see iriap_getvaluebyclass_request(). */
182 self
->request_skb
= skb
;
183 iriap_connect_request(self
);
185 case IAP_LM_DISCONNECT_INDICATION
:
188 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
194 * Function state_s_connecting (self, event, skb)
199 static void state_s_connecting(struct iriap_cb
*self
, IRIAP_EVENT event
,
202 IRDA_ASSERT(self
!= NULL
, return;);
203 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
206 case IAP_LM_CONNECT_CONFIRM
:
210 iriap_do_call_event(self
, IAP_CALL_REQUEST
, skb
);
211 /* iriap_call_request(self, 0,0,0); */
212 iriap_next_client_state(self
, S_CALL
);
214 case IAP_LM_DISCONNECT_INDICATION
:
216 iriap_next_call_state(self
, S_MAKE_CALL
);
217 iriap_next_client_state(self
, S_DISCONNECT
);
220 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
226 * Function state_s_call (self, event, skb)
228 * S-Call, The device can process calls to a specific remote
229 * device. Whenever the LSAP connection is disconnected, this state
230 * catches that event and clears up
232 static void state_s_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
235 IRDA_ASSERT(self
!= NULL
, return;);
238 case IAP_LM_DISCONNECT_INDICATION
:
240 iriap_next_call_state(self
, S_MAKE_CALL
);
241 iriap_next_client_state(self
, S_DISCONNECT
);
244 IRDA_DEBUG(0, "state_s_call: Unknown event %d\n", event
);
250 * Function state_s_make_call (event, skb)
255 static void state_s_make_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
258 struct sk_buff
*tx_skb
;
260 IRDA_ASSERT(self
!= NULL
, return;);
263 case IAP_CALL_REQUEST
:
264 /* Already refcounted - see state_s_disconnect() */
265 tx_skb
= self
->request_skb
;
266 self
->request_skb
= NULL
;
268 irlmp_data_request(self
->lsap
, tx_skb
);
269 iriap_next_call_state(self
, S_OUTSTANDING
);
272 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
278 * Function state_s_calling (event, skb)
283 static void state_s_calling(struct iriap_cb
*self
, IRIAP_EVENT event
,
286 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
290 * Function state_s_outstanding (event, skb)
292 * S-Outstanding, The device is waiting for a response to a command
295 static void state_s_outstanding(struct iriap_cb
*self
, IRIAP_EVENT event
,
298 IRDA_ASSERT(self
!= NULL
, return;);
302 /*iriap_send_ack(self);*/
303 /*LM_Idle_request(idle); */
305 iriap_next_call_state(self
, S_WAIT_FOR_CALL
);
308 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
314 * Function state_s_replying (event, skb)
316 * S-Replying, The device is collecting a multiple part response
318 static void state_s_replying(struct iriap_cb
*self
, IRIAP_EVENT event
,
321 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
325 * Function state_s_wait_for_call (event, skb)
330 static void state_s_wait_for_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
333 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
338 * Function state_s_wait_active (event, skb)
343 static void state_s_wait_active(struct iriap_cb
*self
, IRIAP_EVENT event
,
346 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
349 /**************************************************************************
353 **************************************************************************/
356 * Function state_r_disconnect (self, event, skb)
358 * LM-IAS server is disconnected (not processing any requests!)
361 static void state_r_disconnect(struct iriap_cb
*self
, IRIAP_EVENT event
,
364 struct sk_buff
*tx_skb
;
367 case IAP_LM_CONNECT_INDICATION
:
368 tx_skb
= dev_alloc_skb(64);
369 if (tx_skb
== NULL
) {
370 IRDA_WARNING("%s: unable to malloc!\n", __FUNCTION__
);
374 /* Reserve space for MUX_CONTROL and LAP header */
375 skb_reserve(tx_skb
, LMP_MAX_HEADER
);
377 irlmp_connect_response(self
->lsap
, tx_skb
);
378 /*LM_Idle_request(idle); */
380 iriap_next_server_state(self
, R_CALL
);
383 * Jump to R-Connect FSM, we skip R-Waiting since we do not
384 * care about LM_Idle_request()!
386 iriap_next_r_connect_state(self
, R_RECEIVING
);
389 IRDA_DEBUG(0, "%s(), unknown event %d\n", __FUNCTION__
, event
);
395 * Function state_r_call (self, event, skb)
397 static void state_r_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
400 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
403 case IAP_LM_DISCONNECT_INDICATION
:
405 iriap_next_server_state(self
, R_DISCONNECT
);
406 iriap_next_r_connect_state(self
, R_WAITING
);
409 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__
);
419 * Function state_r_waiting (self, event, skb)
421 static void state_r_waiting(struct iriap_cb
*self
, IRIAP_EVENT event
,
424 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
427 static void state_r_wait_active(struct iriap_cb
*self
, IRIAP_EVENT event
,
430 IRDA_DEBUG(0, "%s(), Not implemented\n", __FUNCTION__
);
434 * Function state_r_receiving (self, event, skb)
436 * We are receiving a command
439 static void state_r_receiving(struct iriap_cb
*self
, IRIAP_EVENT event
,
442 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
446 iriap_next_r_connect_state(self
, R_EXECUTE
);
448 iriap_call_indication(self
, skb
);
451 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__
);
457 * Function state_r_execute (self, event, skb)
459 * The server is processing the request
462 static void state_r_execute(struct iriap_cb
*self
, IRIAP_EVENT event
,
465 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
467 IRDA_ASSERT(skb
!= NULL
, return;);
468 IRDA_ASSERT(self
!= NULL
, return;);
469 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
472 case IAP_CALL_RESPONSE
:
474 * Since we don't implement the Waiting state, we return
475 * to state Receiving instead, DB.
477 iriap_next_r_connect_state(self
, R_RECEIVING
);
479 /* Don't forget to refcount it - see
480 * iriap_getvaluebyclass_response(). */
483 irlmp_data_request(self
->lsap
, skb
);
486 IRDA_DEBUG(0, "%s(), unknown event!\n", __FUNCTION__
);
491 static void state_r_returning(struct iriap_cb
*self
, IRIAP_EVENT event
,
494 IRDA_DEBUG(0, "%s(), event=%d\n", __FUNCTION__
, event
);