1 /*********************************************************************
3 * Filename: irlan_provider_event.c
5 * Description: IrLAN provider state machine)
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Aug 31 20:14:37 1997
9 * Modified at: Sat Oct 30 12:52:41 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, All Rights Reserved.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * Neither Dag Brattli nor University of Tromsø admit liability nor
20 * provide warranty for any of this software. This material is
21 * provided "AS-IS" and at no charge.
23 ********************************************************************/
25 #include <net/irda/irda.h>
26 #include <net/irda/iriap.h>
27 #include <net/irda/irlmp.h>
28 #include <net/irda/irttp.h>
30 #include <net/irda/irlan_provider.h>
31 #include <net/irda/irlan_event.h>
33 static int irlan_provider_state_idle(struct irlan_cb
*self
, IRLAN_EVENT event
,
35 static int irlan_provider_state_info(struct irlan_cb
*self
, IRLAN_EVENT event
,
37 static int irlan_provider_state_open(struct irlan_cb
*self
, IRLAN_EVENT event
,
39 static int irlan_provider_state_data(struct irlan_cb
*self
, IRLAN_EVENT event
,
42 static int (*state
[])(struct irlan_cb
*self
, IRLAN_EVENT event
,
43 struct sk_buff
*skb
) =
45 irlan_provider_state_idle
,
48 irlan_provider_state_info
,
50 irlan_provider_state_open
,
53 irlan_provider_state_data
,
58 void irlan_do_provider_event(struct irlan_cb
*self
, IRLAN_EVENT event
,
61 IRDA_ASSERT(*state
[ self
->provider
.state
] != NULL
, return;);
63 (*state
[self
->provider
.state
]) (self
, event
, skb
);
67 * Function irlan_provider_state_idle (event, skb, info)
69 * IDLE, We are waiting for an indication that there is a provider
72 static int irlan_provider_state_idle(struct irlan_cb
*self
, IRLAN_EVENT event
,
75 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
77 IRDA_ASSERT(self
!= NULL
, return -1;);
80 case IRLAN_CONNECT_INDICATION
:
81 irlan_provider_connect_response( self
, self
->provider
.tsap_ctrl
);
82 irlan_next_provider_state( self
, IRLAN_INFO
);
85 IRDA_DEBUG(4, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
95 * Function irlan_provider_state_info (self, event, skb, info)
97 * INFO, We have issued a GetInfo command and is awaiting a reply.
99 static int irlan_provider_state_info(struct irlan_cb
*self
, IRLAN_EVENT event
,
104 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
106 IRDA_ASSERT(self
!= NULL
, return -1;);
109 case IRLAN_GET_INFO_CMD
:
110 /* Be sure to use 802.3 in case of peer mode */
111 if (self
->provider
.access_type
== ACCESS_PEER
) {
112 self
->media
= MEDIA_802_3
;
114 /* Check if client has started yet */
115 if (self
->client
.state
== IRLAN_IDLE
) {
116 /* This should get the client going */
117 irlmp_discovery_request(8);
121 irlan_provider_send_reply(self
, CMD_GET_PROVIDER_INFO
,
125 case IRLAN_GET_MEDIA_CMD
:
126 irlan_provider_send_reply(self
, CMD_GET_MEDIA_CHAR
,
130 case IRLAN_OPEN_DATA_CMD
:
131 ret
= irlan_parse_open_data_cmd(self
, skb
);
132 if (self
->provider
.access_type
== ACCESS_PEER
) {
133 /* FIXME: make use of random functions! */
134 self
->provider
.send_arb_val
= (jiffies
& 0xffff);
136 irlan_provider_send_reply(self
, CMD_OPEN_DATA_CHANNEL
, ret
);
138 if (ret
== RSP_SUCCESS
) {
139 irlan_next_provider_state(self
, IRLAN_OPEN
);
141 /* Signal client that we are now open */
142 irlan_do_client_event(self
, IRLAN_PROVIDER_SIGNAL
, NULL
);
145 case IRLAN_LMP_DISCONNECT
: /* FALLTHROUGH */
146 case IRLAN_LAP_DISCONNECT
:
147 irlan_next_provider_state(self
, IRLAN_IDLE
);
150 IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
160 * Function irlan_provider_state_open (self, event, skb, info)
162 * OPEN, The client has issued a OpenData command and is awaiting a
166 static int irlan_provider_state_open(struct irlan_cb
*self
, IRLAN_EVENT event
,
169 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
171 IRDA_ASSERT(self
!= NULL
, return -1;);
174 case IRLAN_FILTER_CONFIG_CMD
:
175 irlan_provider_parse_command(self
, CMD_FILTER_OPERATION
, skb
);
176 irlan_provider_send_reply(self
, CMD_FILTER_OPERATION
,
180 case IRLAN_DATA_CONNECT_INDICATION
:
181 irlan_next_provider_state(self
, IRLAN_DATA
);
182 irlan_provider_connect_response(self
, self
->tsap_data
);
184 case IRLAN_LMP_DISCONNECT
: /* FALLTHROUGH */
185 case IRLAN_LAP_DISCONNECT
:
186 irlan_next_provider_state(self
, IRLAN_IDLE
);
189 IRDA_DEBUG(2, "%s(), Unknown event %d\n", __FUNCTION__
, event
);
199 * Function irlan_provider_state_data (self, event, skb, info)
201 * DATA, The data channel is connected, allowing data transfers between
202 * the local and remote machines.
205 static int irlan_provider_state_data(struct irlan_cb
*self
, IRLAN_EVENT event
,
208 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
210 IRDA_ASSERT(self
!= NULL
, return -1;);
211 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
214 case IRLAN_FILTER_CONFIG_CMD
:
215 irlan_provider_parse_command(self
, CMD_FILTER_OPERATION
, skb
);
216 irlan_provider_send_reply(self
, CMD_FILTER_OPERATION
,
219 case IRLAN_LMP_DISCONNECT
: /* FALLTHROUGH */
220 case IRLAN_LAP_DISCONNECT
:
221 irlan_next_provider_state(self
, IRLAN_IDLE
);
224 IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __FUNCTION__
, event
);