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 <linux/slab.h>
29 #include <net/irda/irda.h>
30 #include <net/irda/irlmp.h>
31 #include <net/irda/iriap.h>
32 #include <net/irda/iriap_event.h>
34 static void state_s_disconnect (struct iriap_cb
*self
, IRIAP_EVENT event
,
36 static void state_s_connecting (struct iriap_cb
*self
, IRIAP_EVENT event
,
38 static void state_s_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
41 static void state_s_make_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
43 static void state_s_calling (struct iriap_cb
*self
, IRIAP_EVENT event
,
45 static void state_s_outstanding (struct iriap_cb
*self
, IRIAP_EVENT event
,
47 static void state_s_replying (struct iriap_cb
*self
, IRIAP_EVENT event
,
49 static void state_s_wait_for_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
51 static void state_s_wait_active (struct iriap_cb
*self
, IRIAP_EVENT event
,
54 static void state_r_disconnect (struct iriap_cb
*self
, IRIAP_EVENT event
,
56 static void state_r_call (struct iriap_cb
*self
, IRIAP_EVENT event
,
58 static void state_r_waiting (struct iriap_cb
*self
, IRIAP_EVENT event
,
60 static void state_r_wait_active (struct iriap_cb
*self
, IRIAP_EVENT event
,
62 static void state_r_receiving (struct iriap_cb
*self
, IRIAP_EVENT event
,
64 static void state_r_execute (struct iriap_cb
*self
, IRIAP_EVENT event
,
66 static void state_r_returning (struct iriap_cb
*self
, IRIAP_EVENT event
,
69 static void (*iriap_state
[])(struct iriap_cb
*self
, IRIAP_EVENT event
,
70 struct sk_buff
*skb
) = {
81 state_s_wait_for_call
,
96 void iriap_next_client_state(struct iriap_cb
*self
, IRIAP_STATE state
)
98 IRDA_ASSERT(self
!= NULL
, return;);
99 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
101 self
->client_state
= state
;
104 void iriap_next_call_state(struct iriap_cb
*self
, IRIAP_STATE state
)
106 IRDA_ASSERT(self
!= NULL
, return;);
107 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
109 self
->call_state
= state
;
112 void iriap_next_server_state(struct iriap_cb
*self
, IRIAP_STATE state
)
114 IRDA_ASSERT(self
!= NULL
, return;);
115 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
117 self
->server_state
= state
;
120 void iriap_next_r_connect_state(struct iriap_cb
*self
, IRIAP_STATE state
)
122 IRDA_ASSERT(self
!= NULL
, return;);
123 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
125 self
->r_connect_state
= state
;
128 void iriap_do_client_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
131 IRDA_ASSERT(self
!= NULL
, return;);
132 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
134 (*iriap_state
[ self
->client_state
]) (self
, event
, skb
);
137 void iriap_do_call_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
140 IRDA_ASSERT(self
!= NULL
, return;);
141 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
143 (*iriap_state
[ self
->call_state
]) (self
, event
, skb
);
146 void iriap_do_server_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
149 IRDA_ASSERT(self
!= NULL
, return;);
150 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
152 (*iriap_state
[ self
->server_state
]) (self
, event
, skb
);
155 void iriap_do_r_connect_event(struct iriap_cb
*self
, IRIAP_EVENT event
,
158 IRDA_ASSERT(self
!= NULL
, return;);
159 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
161 (*iriap_state
[ self
->r_connect_state
]) (self
, event
, skb
);
166 * Function state_s_disconnect (event, skb)
168 * S-Disconnect, The device has no LSAP connection to a particular
171 static void state_s_disconnect(struct iriap_cb
*self
, IRIAP_EVENT event
,
174 IRDA_ASSERT(self
!= NULL
, return;);
175 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
178 case IAP_CALL_REQUEST_GVBC
:
179 iriap_next_client_state(self
, S_CONNECTING
);
180 IRDA_ASSERT(self
->request_skb
== NULL
, return;);
181 /* Don't forget to refcount it -
182 * see iriap_getvaluebyclass_request(). */
184 self
->request_skb
= skb
;
185 iriap_connect_request(self
);
187 case IAP_LM_DISCONNECT_INDICATION
:
190 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __func__
, event
);
196 * Function state_s_connecting (self, event, skb)
201 static void state_s_connecting(struct iriap_cb
*self
, IRIAP_EVENT event
,
204 IRDA_ASSERT(self
!= NULL
, return;);
205 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
208 case IAP_LM_CONNECT_CONFIRM
:
212 iriap_do_call_event(self
, IAP_CALL_REQUEST
, skb
);
213 /* iriap_call_request(self, 0,0,0); */
214 iriap_next_client_state(self
, S_CALL
);
216 case IAP_LM_DISCONNECT_INDICATION
:
218 iriap_next_call_state(self
, S_MAKE_CALL
);
219 iriap_next_client_state(self
, S_DISCONNECT
);
222 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __func__
, event
);
228 * Function state_s_call (self, event, skb)
230 * S-Call, The device can process calls to a specific remote
231 * device. Whenever the LSAP connection is disconnected, this state
232 * catches that event and clears up
234 static void state_s_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
237 IRDA_ASSERT(self
!= NULL
, return;);
240 case IAP_LM_DISCONNECT_INDICATION
:
242 iriap_next_call_state(self
, S_MAKE_CALL
);
243 iriap_next_client_state(self
, S_DISCONNECT
);
246 IRDA_DEBUG(0, "state_s_call: Unknown event %d\n", event
);
252 * Function state_s_make_call (event, skb)
257 static void state_s_make_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
260 struct sk_buff
*tx_skb
;
262 IRDA_ASSERT(self
!= NULL
, return;);
265 case IAP_CALL_REQUEST
:
266 /* Already refcounted - see state_s_disconnect() */
267 tx_skb
= self
->request_skb
;
268 self
->request_skb
= NULL
;
270 irlmp_data_request(self
->lsap
, tx_skb
);
271 iriap_next_call_state(self
, S_OUTSTANDING
);
274 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __func__
, event
);
280 * Function state_s_calling (event, skb)
285 static void state_s_calling(struct iriap_cb
*self
, IRIAP_EVENT event
,
288 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
292 * Function state_s_outstanding (event, skb)
294 * S-Outstanding, The device is waiting for a response to a command
297 static void state_s_outstanding(struct iriap_cb
*self
, IRIAP_EVENT event
,
300 IRDA_ASSERT(self
!= NULL
, return;);
304 /*iriap_send_ack(self);*/
305 /*LM_Idle_request(idle); */
307 iriap_next_call_state(self
, S_WAIT_FOR_CALL
);
310 IRDA_DEBUG(0, "%s(), Unknown event %d\n", __func__
, event
);
316 * Function state_s_replying (event, skb)
318 * S-Replying, The device is collecting a multiple part response
320 static void state_s_replying(struct iriap_cb
*self
, IRIAP_EVENT event
,
323 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
327 * Function state_s_wait_for_call (event, skb)
332 static void state_s_wait_for_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
335 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
340 * Function state_s_wait_active (event, skb)
345 static void state_s_wait_active(struct iriap_cb
*self
, IRIAP_EVENT event
,
348 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
351 /**************************************************************************
355 **************************************************************************/
358 * Function state_r_disconnect (self, event, skb)
360 * LM-IAS server is disconnected (not processing any requests!)
363 static void state_r_disconnect(struct iriap_cb
*self
, IRIAP_EVENT event
,
366 struct sk_buff
*tx_skb
;
369 case IAP_LM_CONNECT_INDICATION
:
370 tx_skb
= alloc_skb(LMP_MAX_HEADER
, GFP_ATOMIC
);
371 if (tx_skb
== NULL
) {
372 IRDA_WARNING("%s: unable to malloc!\n", __func__
);
376 /* Reserve space for MUX_CONTROL and LAP header */
377 skb_reserve(tx_skb
, LMP_MAX_HEADER
);
379 irlmp_connect_response(self
->lsap
, tx_skb
);
380 /*LM_Idle_request(idle); */
382 iriap_next_server_state(self
, R_CALL
);
385 * Jump to R-Connect FSM, we skip R-Waiting since we do not
386 * care about LM_Idle_request()!
388 iriap_next_r_connect_state(self
, R_RECEIVING
);
391 IRDA_DEBUG(0, "%s(), unknown event %d\n", __func__
, event
);
397 * Function state_r_call (self, event, skb)
399 static void state_r_call(struct iriap_cb
*self
, IRIAP_EVENT event
,
402 IRDA_DEBUG(4, "%s()\n", __func__
);
405 case IAP_LM_DISCONNECT_INDICATION
:
407 iriap_next_server_state(self
, R_DISCONNECT
);
408 iriap_next_r_connect_state(self
, R_WAITING
);
411 IRDA_DEBUG(0, "%s(), unknown event!\n", __func__
);
421 * Function state_r_waiting (self, event, skb)
423 static void state_r_waiting(struct iriap_cb
*self
, IRIAP_EVENT event
,
426 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
429 static void state_r_wait_active(struct iriap_cb
*self
, IRIAP_EVENT event
,
432 IRDA_DEBUG(0, "%s(), Not implemented\n", __func__
);
436 * Function state_r_receiving (self, event, skb)
438 * We are receiving a command
441 static void state_r_receiving(struct iriap_cb
*self
, IRIAP_EVENT event
,
444 IRDA_DEBUG(4, "%s()\n", __func__
);
448 iriap_next_r_connect_state(self
, R_EXECUTE
);
450 iriap_call_indication(self
, skb
);
453 IRDA_DEBUG(0, "%s(), unknown event!\n", __func__
);
459 * Function state_r_execute (self, event, skb)
461 * The server is processing the request
464 static void state_r_execute(struct iriap_cb
*self
, IRIAP_EVENT event
,
467 IRDA_DEBUG(4, "%s()\n", __func__
);
469 IRDA_ASSERT(skb
!= NULL
, return;);
470 IRDA_ASSERT(self
!= NULL
, return;);
471 IRDA_ASSERT(self
->magic
== IAS_MAGIC
, return;);
474 case IAP_CALL_RESPONSE
:
476 * Since we don't implement the Waiting state, we return
477 * to state Receiving instead, DB.
479 iriap_next_r_connect_state(self
, R_RECEIVING
);
481 /* Don't forget to refcount it - see
482 * iriap_getvaluebyclass_response(). */
485 irlmp_data_request(self
->lsap
, skb
);
488 IRDA_DEBUG(0, "%s(), unknown event!\n", __func__
);
493 static void state_r_returning(struct iriap_cb
*self
, IRIAP_EVENT event
,
496 IRDA_DEBUG(0, "%s(), event=%d\n", __func__
, event
);