blob: 01a9d7c993eee12b5ef4e404f26282917934e455 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Filename: irlan_provider_event.c
4 * Version: 0.9
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>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, All Rights Reserved.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090013 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * the License, or (at your option) any later version.
18 *
Jan Engelhardt96de0e22007-10-19 23:21:04 +020019 * Neither Dag Brattli nor University of Tromsø admit liability nor
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090020 * provide warranty for any of this software. This material is
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * provided "AS-IS" and at no charge.
22 *
23 ********************************************************************/
24
25#include <net/irda/irda.h>
26#include <net/irda/iriap.h>
27#include <net/irda/irlmp.h>
28#include <net/irda/irttp.h>
29
30#include <net/irda/irlan_provider.h>
31#include <net/irda/irlan_event.h>
32
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090033static int irlan_provider_state_idle(struct irlan_cb *self, IRLAN_EVENT event,
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct sk_buff *skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090035static int irlan_provider_state_info(struct irlan_cb *self, IRLAN_EVENT event,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 struct sk_buff *skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090037static int irlan_provider_state_open(struct irlan_cb *self, IRLAN_EVENT event,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 struct sk_buff *skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090039static int irlan_provider_state_data(struct irlan_cb *self, IRLAN_EVENT event,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct sk_buff *skb);
41
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090042static int (*state[])(struct irlan_cb *self, IRLAN_EVENT event,
43 struct sk_buff *skb) =
44{
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 irlan_provider_state_idle,
46 NULL, /* Query */
47 NULL, /* Info */
48 irlan_provider_state_info,
49 NULL, /* Media */
50 irlan_provider_state_open,
51 NULL, /* Wait */
52 NULL, /* Arb */
53 irlan_provider_state_data,
54 NULL, /* Close */
55 NULL, /* Sync */
56};
57
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090058void irlan_do_provider_event(struct irlan_cb *self, IRLAN_EVENT event,
59 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 IRDA_ASSERT(*state[ self->provider.state] != NULL, return;);
62
63 (*state[self->provider.state]) (self, event, skb);
64}
65
66/*
67 * Function irlan_provider_state_idle (event, skb, info)
68 *
69 * IDLE, We are waiting for an indication that there is a provider
70 * available.
71 */
72static int irlan_provider_state_idle(struct irlan_cb *self, IRLAN_EVENT event,
73 struct sk_buff *skb)
74{
Harvey Harrison0dc47872008-03-05 20:47:47 -080075 IRDA_DEBUG(4, "%s()\n", __func__ );
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 IRDA_ASSERT(self != NULL, return -1;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 switch(event) {
80 case IRLAN_CONNECT_INDICATION:
81 irlan_provider_connect_response( self, self->provider.tsap_ctrl);
82 irlan_next_provider_state( self, IRLAN_INFO);
83 break;
84 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -080085 IRDA_DEBUG(4, "%s(), Unknown event %d\n", __func__ , event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 break;
87 }
88 if (skb)
89 dev_kfree_skb(skb);
90
91 return 0;
92}
93
94/*
95 * Function irlan_provider_state_info (self, event, skb, info)
96 *
97 * INFO, We have issued a GetInfo command and is awaiting a reply.
98 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090099static int irlan_provider_state_info(struct irlan_cb *self, IRLAN_EVENT event,
100 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 int ret;
103
Harvey Harrison0dc47872008-03-05 20:47:47 -0800104 IRDA_DEBUG(4, "%s()\n", __func__ );
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 IRDA_ASSERT(self != NULL, return -1;);
107
108 switch(event) {
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;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* 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);
118 }
119 }
120
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900121 irlan_provider_send_reply(self, CMD_GET_PROVIDER_INFO,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 RSP_SUCCESS);
123 /* Keep state */
124 break;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900125 case IRLAN_GET_MEDIA_CMD:
126 irlan_provider_send_reply(self, CMD_GET_MEDIA_CHAR,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 RSP_SUCCESS);
128 /* Keep state */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900129 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 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);
135 }
136 irlan_provider_send_reply(self, CMD_OPEN_DATA_CHANNEL, ret);
137
138 if (ret == RSP_SUCCESS) {
139 irlan_next_provider_state(self, IRLAN_OPEN);
140
141 /* Signal client that we are now open */
142 irlan_do_client_event(self, IRLAN_PROVIDER_SIGNAL, NULL);
143 }
144 break;
145 case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
146 case IRLAN_LAP_DISCONNECT:
147 irlan_next_provider_state(self, IRLAN_IDLE);
148 break;
149 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800150 IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __func__ , event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 break;
152 }
153 if (skb)
154 dev_kfree_skb(skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return 0;
157}
158
159/*
160 * Function irlan_provider_state_open (self, event, skb, info)
161 *
162 * OPEN, The client has issued a OpenData command and is awaiting a
163 * reply
164 *
165 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900166static int irlan_provider_state_open(struct irlan_cb *self, IRLAN_EVENT event,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 struct sk_buff *skb)
168{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800169 IRDA_DEBUG(4, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 IRDA_ASSERT(self != NULL, return -1;);
172
173 switch(event) {
174 case IRLAN_FILTER_CONFIG_CMD:
175 irlan_provider_parse_command(self, CMD_FILTER_OPERATION, skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900176 irlan_provider_send_reply(self, CMD_FILTER_OPERATION,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 RSP_SUCCESS);
178 /* Keep state */
179 break;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900180 case IRLAN_DATA_CONNECT_INDICATION:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 irlan_next_provider_state(self, IRLAN_DATA);
182 irlan_provider_connect_response(self, self->tsap_data);
183 break;
184 case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
185 case IRLAN_LAP_DISCONNECT:
186 irlan_next_provider_state(self, IRLAN_IDLE);
187 break;
188 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800189 IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 break;
191 }
192 if (skb)
193 dev_kfree_skb(skb);
194
195 return 0;
196}
197
198/*
199 * Function irlan_provider_state_data (self, event, skb, info)
200 *
201 * DATA, The data channel is connected, allowing data transfers between
202 * the local and remote machines.
203 *
204 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900205static int irlan_provider_state_data(struct irlan_cb *self, IRLAN_EVENT event,
206 struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800208 IRDA_DEBUG(4, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 IRDA_ASSERT(self != NULL, return -1;);
211 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
212
213 switch(event) {
214 case IRLAN_FILTER_CONFIG_CMD:
215 irlan_provider_parse_command(self, CMD_FILTER_OPERATION, skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900216 irlan_provider_send_reply(self, CMD_FILTER_OPERATION,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 RSP_SUCCESS);
218 break;
219 case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
220 case IRLAN_LAP_DISCONNECT:
221 irlan_next_provider_state(self, IRLAN_IDLE);
222 break;
223 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800224 IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __func__ , event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 break;
226 }
227 if (skb)
228 dev_kfree_skb(skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return 0;
231}
232
233
234
235
236
237
238
239
240
241