blob: 2ee87bf387cc191147ce9bb3809b6fd1e3096cc4 [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: ircomm_tty_attach.c
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +09004 * Version:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Description: Code for attaching the serial driver to IrCOMM
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sat Jun 5 17:42:00 1999
9 * Modified at: Tue Jan 4 14:20:49 2000
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) 1999-2000 Dag Brattli, All Rights Reserved.
13 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090014 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * the License, or (at your option) any later version.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090019 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090024 *
25 * You should have received a copy of the GNU General Public License
Jeff Kirsherd3770502013-12-06 09:13:43 -080026 * along with this program; if not, see <http://www.gnu.org/licenses/>.
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090027 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 ********************************************************************/
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/init.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040031#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <net/irda/irda.h>
34#include <net/irda/irlmp.h>
35#include <net/irda/iriap.h>
36#include <net/irda/irttp.h>
37#include <net/irda/irias_object.h>
38#include <net/irda/parameters.h>
39
40#include <net/irda/ircomm_core.h>
41#include <net/irda/ircomm_param.h>
42#include <net/irda/ircomm_event.h>
43
44#include <net/irda/ircomm_tty.h>
45#include <net/irda/ircomm_tty_attach.h>
46
47static void ircomm_tty_ias_register(struct ircomm_tty_cb *self);
48static void ircomm_tty_discovery_indication(discinfo_t *discovery,
49 DISCOVERY_MODE mode,
50 void *priv);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090051static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct ias_value *value, void *priv);
53static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self,
54 int timeout);
55static void ircomm_tty_watchdog_timer_expired(void *data);
56
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090057static int ircomm_tty_state_idle(struct ircomm_tty_cb *self,
58 IRCOMM_TTY_EVENT event,
59 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct ircomm_tty_info *info);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090061static int ircomm_tty_state_search(struct ircomm_tty_cb *self,
62 IRCOMM_TTY_EVENT event,
63 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 struct ircomm_tty_info *info);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090065static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self,
66 IRCOMM_TTY_EVENT event,
67 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct ircomm_tty_info *info);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090069static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self,
70 IRCOMM_TTY_EVENT event,
71 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct ircomm_tty_info *info);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090073static int ircomm_tty_state_setup(struct ircomm_tty_cb *self,
74 IRCOMM_TTY_EVENT event,
75 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 struct ircomm_tty_info *info);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +090077static int ircomm_tty_state_ready(struct ircomm_tty_cb *self,
78 IRCOMM_TTY_EVENT event,
79 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 struct ircomm_tty_info *info);
81
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -070082const char *const ircomm_tty_state[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 "IRCOMM_TTY_IDLE",
84 "IRCOMM_TTY_SEARCH",
85 "IRCOMM_TTY_QUERY_PARAMETERS",
86 "IRCOMM_TTY_QUERY_LSAP_SEL",
87 "IRCOMM_TTY_SETUP",
88 "IRCOMM_TTY_READY",
89 "*** ERROR *** ",
90};
91
92#ifdef CONFIG_IRDA_DEBUG
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -070093static const char *const ircomm_tty_event[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 "IRCOMM_TTY_ATTACH_CABLE",
95 "IRCOMM_TTY_DETACH_CABLE",
96 "IRCOMM_TTY_DATA_REQUEST",
97 "IRCOMM_TTY_DATA_INDICATION",
98 "IRCOMM_TTY_DISCOVERY_REQUEST",
99 "IRCOMM_TTY_DISCOVERY_INDICATION",
100 "IRCOMM_TTY_CONNECT_CONFIRM",
101 "IRCOMM_TTY_CONNECT_INDICATION",
102 "IRCOMM_TTY_DISCONNECT_REQUEST",
103 "IRCOMM_TTY_DISCONNECT_INDICATION",
104 "IRCOMM_TTY_WD_TIMER_EXPIRED",
105 "IRCOMM_TTY_GOT_PARAMETERS",
106 "IRCOMM_TTY_GOT_LSAPSEL",
107 "*** ERROR ****",
108};
109#endif /* CONFIG_IRDA_DEBUG */
110
111static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900112 struct sk_buff *skb, struct ircomm_tty_info *info) =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
114 ircomm_tty_state_idle,
115 ircomm_tty_state_search,
116 ircomm_tty_state_query_parameters,
117 ircomm_tty_state_query_lsap_sel,
118 ircomm_tty_state_setup,
119 ircomm_tty_state_ready,
120};
121
122/*
123 * Function ircomm_tty_attach_cable (driver)
124 *
125 * Try to attach cable (IrCOMM link). This function will only return
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900126 * when the link has been connected, or if an error condition occurs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 * If success, the return value is the resulting service type.
128 */
129int ircomm_tty_attach_cable(struct ircomm_tty_cb *self)
130{
Jiri Slaby62f228a2012-06-04 13:35:21 +0200131 struct tty_struct *tty;
132
Harvey Harrison0dc47872008-03-05 20:47:47 -0800133 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 IRDA_ASSERT(self != NULL, return -1;);
136 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
137
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900138 /* Check if somebody has already connected to us */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (ircomm_is_connected(self->ircomm)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800140 IRDA_DEBUG(0, "%s(), already connected!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return 0;
142 }
143
144 /* Make sure nobody tries to write before the link is up */
Jiri Slaby62f228a2012-06-04 13:35:21 +0200145 tty = tty_port_tty_get(&self->port);
146 if (tty) {
147 tty->hw_stopped = 1;
148 tty_kref_put(tty);
149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 ircomm_tty_ias_register(self);
152
153 ircomm_tty_do_event(self, IRCOMM_TTY_ATTACH_CABLE, NULL, NULL);
154
155 return 0;
156}
157
158/*
159 * Function ircomm_detach_cable (driver)
160 *
161 * Detach cable, or cable has been detached by peer
162 *
163 */
164void ircomm_tty_detach_cable(struct ircomm_tty_cb *self)
165{
Harvey Harrison0dc47872008-03-05 20:47:47 -0800166 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 IRDA_ASSERT(self != NULL, return;);
169 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
170
171 del_timer(&self->watchdog_timer);
172
173 /* Remove discovery handler */
174 if (self->ckey) {
175 irlmp_unregister_client(self->ckey);
176 self->ckey = NULL;
177 }
178 /* Remove IrCOMM hint bits */
179 if (self->skey) {
180 irlmp_unregister_service(self->skey);
181 self->skey = NULL;
182 }
183
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900184 if (self->iriap) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 iriap_close(self->iriap);
186 self->iriap = NULL;
187 }
188
189 /* Remove LM-IAS object */
190 if (self->obj) {
191 irias_delete_object(self->obj);
192 self->obj = NULL;
193 }
194
195 ircomm_tty_do_event(self, IRCOMM_TTY_DETACH_CABLE, NULL, NULL);
196
197 /* Reset some values */
198 self->daddr = self->saddr = 0;
199 self->dlsap_sel = self->slsap_sel = 0;
200
201 memset(&self->settings, 0, sizeof(struct ircomm_params));
202}
203
204/*
205 * Function ircomm_tty_ias_register (self)
206 *
207 * Register with LM-IAS depending on which service type we are
208 *
209 */
210static void ircomm_tty_ias_register(struct ircomm_tty_cb *self)
211{
212 __u8 oct_seq[6];
213 __u16 hints;
214
Harvey Harrison0dc47872008-03-05 20:47:47 -0800215 IRDA_DEBUG(0, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 IRDA_ASSERT(self != NULL, return;);
218 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 /* Compute hint bits based on service */
221 hints = irlmp_service_to_hint(S_COMM);
222 if (self->service_type & IRCOMM_3_WIRE_RAW)
223 hints |= irlmp_service_to_hint(S_PRINTER);
224
225 /* Advertise IrCOMM hint bit in discovery */
226 if (!self->skey)
227 self->skey = irlmp_register_service(hints);
228 /* Set up a discovery handler */
229 if (!self->ckey)
230 self->ckey = irlmp_register_client(hints,
231 ircomm_tty_discovery_indication,
232 NULL, (void *) self);
233
234 /* If already done, no need to do it again */
235 if (self->obj)
236 return;
237
238 if (self->service_type & IRCOMM_3_WIRE_RAW) {
239 /* Register IrLPT with LM-IAS */
240 self->obj = irias_new_object("IrLPT", IAS_IRLPT_ID);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900241 irias_add_integer_attrib(self->obj, "IrDA:IrLMP:LsapSel",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 self->slsap_sel, IAS_KERNEL_ATTR);
243 } else {
244 /* Register IrCOMM with LM-IAS */
245 self->obj = irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900246 irias_add_integer_attrib(self->obj, "IrDA:TinyTP:LsapSel",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 self->slsap_sel, IAS_KERNEL_ATTR);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 /* Code the parameters into the buffer */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900250 irda_param_pack(oct_seq, "bbbbbb",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 IRCOMM_SERVICE_TYPE, 1, self->service_type,
252 IRCOMM_PORT_TYPE, 1, IRCOMM_SERIAL);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 /* Register parameters with LM-IAS */
255 irias_add_octseq_attrib(self->obj, "Parameters", oct_seq, 6,
256 IAS_KERNEL_ATTR);
257 }
258 irias_insert_object(self->obj);
259}
260
261/*
262 * Function ircomm_tty_ias_unregister (self)
263 *
264 * Remove our IAS object and client hook while connected.
265 *
266 */
267static void ircomm_tty_ias_unregister(struct ircomm_tty_cb *self)
268{
269 /* Remove LM-IAS object now so it is not reused.
270 * IrCOMM deals very poorly with multiple incoming connections.
271 * It should looks a lot more like IrNET, and "dup" a server TSAP
272 * to the application TSAP (based on various rules).
273 * This is a cheap workaround allowing multiple clients to
274 * connect to us. It will not always work.
275 * Each IrCOMM socket has an IAS entry. Incoming connection will
276 * pick the first one found. So, when we are fully connected,
277 * we remove our IAS entries so that the next IAS entry is used.
278 * We do that for *both* client and server, because a server
279 * can also create client instances.
280 * Jean II */
281 if (self->obj) {
282 irias_delete_object(self->obj);
283 self->obj = NULL;
284 }
285
286#if 0
287 /* Remove discovery handler.
288 * While we are connected, we no longer need to receive
289 * discovery events. This would be the case if there is
290 * multiple IrLAP interfaces. Jean II */
291 if (self->ckey) {
292 irlmp_unregister_client(self->ckey);
293 self->ckey = NULL;
294 }
295#endif
296}
297
298/*
299 * Function ircomm_send_initial_parameters (self)
300 *
301 * Send initial parameters to the remote IrCOMM device. These parameters
302 * must be sent before any data.
303 */
304int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb *self)
305{
306 IRDA_ASSERT(self != NULL, return -1;);
307 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
308
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900309 if (self->service_type & IRCOMM_3_WIRE_RAW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return 0;
311
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900312 /*
313 * Set default values, but only if the application for some reason
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * haven't set them already
315 */
Harvey Harrison0dc47872008-03-05 20:47:47 -0800316 IRDA_DEBUG(2, "%s(), data-rate = %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 self->settings.data_rate);
318 if (!self->settings.data_rate)
319 self->settings.data_rate = 9600;
Harvey Harrison0dc47872008-03-05 20:47:47 -0800320 IRDA_DEBUG(2, "%s(), data-format = %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 self->settings.data_format);
322 if (!self->settings.data_format)
323 self->settings.data_format = IRCOMM_WSIZE_8; /* 8N1 */
324
Harvey Harrison0dc47872008-03-05 20:47:47 -0800325 IRDA_DEBUG(2, "%s(), flow-control = %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 self->settings.flow_control);
327 /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/
328
329 /* Do not set delta values for the initial parameters */
330 self->settings.dte = IRCOMM_DTR | IRCOMM_RTS;
331
332 /* Only send service type parameter when we are the client */
333 if (self->client)
334 ircomm_param_request(self, IRCOMM_SERVICE_TYPE, FALSE);
335 ircomm_param_request(self, IRCOMM_DATA_RATE, FALSE);
336 ircomm_param_request(self, IRCOMM_DATA_FORMAT, FALSE);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /* For a 3 wire service, we just flush the last parameter and return */
339 if (self->settings.service_type == IRCOMM_3_WIRE) {
340 ircomm_param_request(self, IRCOMM_FLOW_CONTROL, TRUE);
341 return 0;
342 }
343
344 /* Only 9-wire service types continue here */
345 ircomm_param_request(self, IRCOMM_FLOW_CONTROL, FALSE);
346#if 0
347 ircomm_param_request(self, IRCOMM_XON_XOFF, FALSE);
348 ircomm_param_request(self, IRCOMM_ENQ_ACK, FALSE);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900349#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /* Notify peer that we are ready to receive data */
351 ircomm_param_request(self, IRCOMM_DTE, TRUE);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return 0;
354}
355
356/*
357 * Function ircomm_tty_discovery_indication (discovery)
358 *
359 * Remote device is discovered, try query the remote IAS to see which
360 * device it is, and which services it has.
361 *
362 */
363static void ircomm_tty_discovery_indication(discinfo_t *discovery,
364 DISCOVERY_MODE mode,
365 void *priv)
366{
367 struct ircomm_tty_cb *self;
368 struct ircomm_tty_info info;
369
Harvey Harrison0dc47872008-03-05 20:47:47 -0800370 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 /* Important note :
373 * We need to drop all passive discoveries.
374 * The LSAP management of IrComm is deficient and doesn't deal
375 * with the case of two instance connecting to each other
376 * simultaneously (it will deadlock in LMP).
377 * The proper fix would be to use the same technique as in IrNET,
378 * to have one server socket and separate instances for the
379 * connecting/connected socket.
380 * The workaround is to drop passive discovery, which drastically
381 * reduce the probability of this happening.
382 * Jean II */
383 if(mode == DISCOVERY_PASSIVE)
384 return;
385
386 info.daddr = discovery->daddr;
387 info.saddr = discovery->saddr;
388
Joe Perchesea110732011-06-13 16:21:26 +0000389 self = priv;
Ryan Readingc310f092007-10-17 19:34:11 -0700390 ircomm_tty_do_event(self, IRCOMM_TTY_DISCOVERY_INDICATION,
391 NULL, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
394/*
395 * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb)
396 *
397 * Link disconnected
398 *
399 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900400void ircomm_tty_disconnect_indication(void *instance, void *sap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 LM_REASON reason,
402 struct sk_buff *skb)
403{
404 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
Jiri Slaby62f228a2012-06-04 13:35:21 +0200405 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Harvey Harrison0dc47872008-03-05 20:47:47 -0800407 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 IRDA_ASSERT(self != NULL, return;);
410 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
411
Jiri Slaby62f228a2012-06-04 13:35:21 +0200412 tty = tty_port_tty_get(&self->port);
413 if (!tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 return;
415
416 /* This will stop control data transfers */
417 self->flow = FLOW_STOP;
418
419 /* Stop data transfers */
Jiri Slaby62f228a2012-06-04 13:35:21 +0200420 tty->hw_stopped = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900422 ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 NULL);
Jiri Slaby62f228a2012-06-04 13:35:21 +0200424 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427/*
428 * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv)
429 *
430 * Got result from the IAS query we make
431 *
432 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900433static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id,
434 struct ias_value *value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 void *priv)
436{
437 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) priv;
438
Harvey Harrison0dc47872008-03-05 20:47:47 -0800439 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 IRDA_ASSERT(self != NULL, return;);
442 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
443
444 /* We probably don't need to make any more queries */
445 iriap_close(self->iriap);
446 self->iriap = NULL;
447
448 /* Check if request succeeded */
449 if (result != IAS_SUCCESS) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800450 IRDA_DEBUG(4, "%s(), got NULL value!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return;
452 }
453
454 switch (value->type) {
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900455 case IAS_OCT_SEQ:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800456 IRDA_DEBUG(2, "%s(), got octet sequence\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 irda_param_extract_all(self, value->t.oct_seq, value->len,
459 &ircomm_param_info);
460
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900461 ircomm_tty_do_event(self, IRCOMM_TTY_GOT_PARAMETERS, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 NULL);
463 break;
464 case IAS_INTEGER:
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900465 /* Got LSAP selector */
Harvey Harrison0dc47872008-03-05 20:47:47 -0800466 IRDA_DEBUG(2, "%s(), got lsapsel = %d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 value->t.integer);
468
469 if (value->t.integer == -1) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800470 IRDA_DEBUG(0, "%s(), invalid value!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 } else
472 self->dlsap_sel = value->t.integer;
473
474 ircomm_tty_do_event(self, IRCOMM_TTY_GOT_LSAPSEL, NULL, NULL);
475 break;
476 case IAS_MISSING:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800477 IRDA_DEBUG(0, "%s(), got IAS_MISSING\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 break;
479 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800480 IRDA_DEBUG(0, "%s(), got unknown type!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 break;
482 }
483 irias_delete_value(value);
484}
485
486/*
487 * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb)
488 *
489 * Connection confirmed
490 *
491 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900492void ircomm_tty_connect_confirm(void *instance, void *sap,
493 struct qos_info *qos,
494 __u32 max_data_size,
495 __u8 max_header_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 struct sk_buff *skb)
497{
498 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
499
Harvey Harrison0dc47872008-03-05 20:47:47 -0800500 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 IRDA_ASSERT(self != NULL, return;);
503 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
504
505 self->client = TRUE;
506 self->max_data_size = max_data_size;
507 self->max_header_size = max_header_size;
508 self->flow = FLOW_START;
509
510 ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_CONFIRM, NULL, NULL);
511
512 /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */
513}
514
515/*
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900516 * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 * skb)
518 *
519 * we are discovered and being requested to connect by remote device !
520 *
521 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900522void ircomm_tty_connect_indication(void *instance, void *sap,
523 struct qos_info *qos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 __u32 max_data_size,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900525 __u8 max_header_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct sk_buff *skb)
527{
528 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
529 int clen;
530
Harvey Harrison0dc47872008-03-05 20:47:47 -0800531 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 IRDA_ASSERT(self != NULL, return;);
534 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
535
536 self->client = FALSE;
537 self->max_data_size = max_data_size;
538 self->max_header_size = max_header_size;
539 self->flow = FLOW_START;
540
541 clen = skb->data[0];
542 if (clen)
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900543 irda_param_extract_all(self, skb->data+1,
544 IRDA_MIN(skb->len, clen),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 &ircomm_param_info);
546
547 ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_INDICATION, NULL, NULL);
548
549 /* No need to kfree_skb - see ircomm_ttp_connect_indication() */
550}
551
552/*
553 * Function ircomm_tty_link_established (self)
554 *
555 * Called when the IrCOMM link is established
556 *
557 */
558void ircomm_tty_link_established(struct ircomm_tty_cb *self)
559{
Jiri Slaby62f228a2012-06-04 13:35:21 +0200560 struct tty_struct *tty;
561
Harvey Harrison0dc47872008-03-05 20:47:47 -0800562 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 IRDA_ASSERT(self != NULL, return;);
565 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
566
Jiri Slaby62f228a2012-06-04 13:35:21 +0200567 tty = tty_port_tty_get(&self->port);
568 if (!tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 del_timer(&self->watchdog_timer);
572
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900573 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 * IrCOMM link is now up, and if we are not using hardware
575 * flow-control, then declare the hardware as running. Otherwise we
576 * will have to wait for the peer device (DCE) to raise the CTS
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900577 * line.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
Huang Shijief21ec3d2012-08-22 22:13:36 -0400579 if (tty_port_cts_enabled(&self->port) &&
Jiri Slaby849d5a92012-06-04 13:35:19 +0200580 ((self->settings.dce & IRCOMM_CTS) == 0)) {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800581 IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__ );
Jiri Slaby62f228a2012-06-04 13:35:21 +0200582 goto put;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 } else {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800584 IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Jiri Slaby62f228a2012-06-04 13:35:21 +0200586 tty->hw_stopped = 0;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /* Wake up processes blocked on open */
Jiri Slabya3cc9fc2012-06-04 13:35:16 +0200589 wake_up_interruptible(&self->port.open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591
592 schedule_work(&self->tqueue);
Jiri Slaby62f228a2012-06-04 13:35:21 +0200593put:
594 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597/*
598 * Function ircomm_tty_start_watchdog_timer (self, timeout)
599 *
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900600 * Start the watchdog timer. This timer is used to make sure that any
601 * connection attempt is successful, and if not, we will retry after
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 * the timeout
603 */
604static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self,
605 int timeout)
606{
607 IRDA_ASSERT(self != NULL, return;);
608 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
609
610 irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
611 ircomm_tty_watchdog_timer_expired);
612}
613
614/*
615 * Function ircomm_tty_watchdog_timer_expired (data)
616 *
617 * Called when the connect procedure have taken to much time.
618 *
619 */
620static void ircomm_tty_watchdog_timer_expired(void *data)
621{
622 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) data;
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900623
Harvey Harrison0dc47872008-03-05 20:47:47 -0800624 IRDA_DEBUG(2, "%s()\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 IRDA_ASSERT(self != NULL, return;);
627 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
628
629 ircomm_tty_do_event(self, IRCOMM_TTY_WD_TIMER_EXPIRED, NULL, NULL);
630}
631
632
633/*
634 * Function ircomm_tty_do_event (self, event, skb)
635 *
636 * Process event
637 *
638 */
639int ircomm_tty_do_event(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900640 struct sk_buff *skb, struct ircomm_tty_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
642 IRDA_ASSERT(self != NULL, return -1;);
643 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
644
Harvey Harrison0dc47872008-03-05 20:47:47 -0800645 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 ircomm_tty_state[self->state], ircomm_tty_event[event]);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return (*state[self->state])(self, event, skb, info);
649}
650
651/*
652 * Function ircomm_tty_next_state (self, state)
653 *
654 * Switch state
655 *
656 */
657static inline void ircomm_tty_next_state(struct ircomm_tty_cb *self, IRCOMM_TTY_STATE state)
658{
659 /*
660 IRDA_ASSERT(self != NULL, return;);
661 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
662
Harvey Harrison0dc47872008-03-05 20:47:47 -0800663 IRDA_DEBUG(2, "%s: next state=%s, service type=%d\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 ircomm_tty_state[self->state], self->service_type);
665 */
666 self->state = state;
667}
668
669/*
670 * Function ircomm_tty_state_idle (self, event, skb, info)
671 *
672 * Just hanging around
673 *
674 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900675static int ircomm_tty_state_idle(struct ircomm_tty_cb *self,
676 IRCOMM_TTY_EVENT event,
677 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 struct ircomm_tty_info *info)
679{
680 int ret = 0;
681
Harvey Harrison0dc47872008-03-05 20:47:47 -0800682 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 ircomm_tty_state[self->state], ircomm_tty_event[event]);
684 switch (event) {
685 case IRCOMM_TTY_ATTACH_CABLE:
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900686 /* Try to discover any remote devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 ircomm_tty_start_watchdog_timer(self, 3*HZ);
688 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
691 break;
692 case IRCOMM_TTY_DISCOVERY_INDICATION:
693 self->daddr = info->daddr;
694 self->saddr = info->saddr;
695
696 if (self->iriap) {
697 IRDA_WARNING("%s(), busy with a previous query\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800698 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return -EBUSY;
700 }
701
702 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
703 ircomm_tty_getvalue_confirm);
704
705 iriap_getvaluebyclass_request(self->iriap,
706 self->saddr, self->daddr,
707 "IrDA:IrCOMM", "Parameters");
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 ircomm_tty_start_watchdog_timer(self, 3*HZ);
710 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS);
711 break;
712 case IRCOMM_TTY_CONNECT_INDICATION:
713 del_timer(&self->watchdog_timer);
714
715 /* Accept connection */
716 ircomm_connect_response(self->ircomm, NULL);
717 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
718 break;
719 case IRCOMM_TTY_WD_TIMER_EXPIRED:
720 /* Just stay idle */
721 break;
722 case IRCOMM_TTY_DETACH_CABLE:
723 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
724 break;
725 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800726 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 ircomm_tty_event[event]);
728 ret = -EINVAL;
729 }
730 return ret;
731}
732
733/*
734 * Function ircomm_tty_state_search (self, event, skb, info)
735 *
736 * Trying to discover an IrCOMM device
737 *
738 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900739static int ircomm_tty_state_search(struct ircomm_tty_cb *self,
740 IRCOMM_TTY_EVENT event,
741 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 struct ircomm_tty_info *info)
743{
744 int ret = 0;
745
Harvey Harrison0dc47872008-03-05 20:47:47 -0800746 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 ircomm_tty_state[self->state], ircomm_tty_event[event]);
748
749 switch (event) {
750 case IRCOMM_TTY_DISCOVERY_INDICATION:
751 self->daddr = info->daddr;
752 self->saddr = info->saddr;
753
754 if (self->iriap) {
755 IRDA_WARNING("%s(), busy with a previous query\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800756 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return -EBUSY;
758 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
761 ircomm_tty_getvalue_confirm);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (self->service_type == IRCOMM_3_WIRE_RAW) {
764 iriap_getvaluebyclass_request(self->iriap, self->saddr,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900765 self->daddr, "IrLPT",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 "IrDA:IrLMP:LsapSel");
767 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL);
768 } else {
769 iriap_getvaluebyclass_request(self->iriap, self->saddr,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900770 self->daddr,
771 "IrDA:IrCOMM",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 "Parameters");
773
774 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS);
775 }
776 ircomm_tty_start_watchdog_timer(self, 3*HZ);
777 break;
778 case IRCOMM_TTY_CONNECT_INDICATION:
779 del_timer(&self->watchdog_timer);
780 ircomm_tty_ias_unregister(self);
781
782 /* Accept connection */
783 ircomm_connect_response(self->ircomm, NULL);
784 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
785 break;
786 case IRCOMM_TTY_WD_TIMER_EXPIRED:
787#if 1
788 /* Give up */
789#else
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900790 /* Try to discover any remote devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 ircomm_tty_start_watchdog_timer(self, 3*HZ);
792 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
793#endif
794 break;
795 case IRCOMM_TTY_DETACH_CABLE:
796 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
797 break;
798 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800799 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 ircomm_tty_event[event]);
801 ret = -EINVAL;
802 }
803 return ret;
804}
805
806/*
807 * Function ircomm_tty_state_query (self, event, skb, info)
808 *
809 * Querying the remote LM-IAS for IrCOMM parameters
810 *
811 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900812static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self,
813 IRCOMM_TTY_EVENT event,
814 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 struct ircomm_tty_info *info)
816{
817 int ret = 0;
818
Harvey Harrison0dc47872008-03-05 20:47:47 -0800819 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 ircomm_tty_state[self->state], ircomm_tty_event[event]);
821
822 switch (event) {
823 case IRCOMM_TTY_GOT_PARAMETERS:
824 if (self->iriap) {
825 IRDA_WARNING("%s(), busy with a previous query\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800826 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return -EBUSY;
828 }
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
831 ircomm_tty_getvalue_confirm);
832
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900833 iriap_getvaluebyclass_request(self->iriap, self->saddr,
834 self->daddr, "IrDA:IrCOMM",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 "IrDA:TinyTP:LsapSel");
836
837 ircomm_tty_start_watchdog_timer(self, 3*HZ);
838 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL);
839 break;
840 case IRCOMM_TTY_WD_TIMER_EXPIRED:
841 /* Go back to search mode */
842 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900843 ircomm_tty_start_watchdog_timer(self, 3*HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 break;
845 case IRCOMM_TTY_CONNECT_INDICATION:
846 del_timer(&self->watchdog_timer);
847 ircomm_tty_ias_unregister(self);
848
849 /* Accept connection */
850 ircomm_connect_response(self->ircomm, NULL);
851 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
852 break;
853 case IRCOMM_TTY_DETACH_CABLE:
854 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
855 break;
856 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800857 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 ircomm_tty_event[event]);
859 ret = -EINVAL;
860 }
861 return ret;
862}
863
864/*
865 * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info)
866 *
867 * Query remote LM-IAS for the LSAP selector which we can connect to
868 *
869 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900870static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self,
871 IRCOMM_TTY_EVENT event,
872 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 struct ircomm_tty_info *info)
874{
875 int ret = 0;
876
Harvey Harrison0dc47872008-03-05 20:47:47 -0800877 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 ircomm_tty_state[self->state], ircomm_tty_event[event]);
879
880 switch (event) {
881 case IRCOMM_TTY_GOT_LSAPSEL:
882 /* Connect to remote device */
883 ret = ircomm_connect_request(self->ircomm, self->dlsap_sel,
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900884 self->saddr, self->daddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 NULL, self->service_type);
886 ircomm_tty_start_watchdog_timer(self, 3*HZ);
887 ircomm_tty_next_state(self, IRCOMM_TTY_SETUP);
888 break;
889 case IRCOMM_TTY_WD_TIMER_EXPIRED:
890 /* Go back to search mode */
891 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
892 ircomm_tty_start_watchdog_timer(self, 3*HZ);
893 break;
894 case IRCOMM_TTY_CONNECT_INDICATION:
895 del_timer(&self->watchdog_timer);
896 ircomm_tty_ias_unregister(self);
897
898 /* Accept connection */
899 ircomm_connect_response(self->ircomm, NULL);
900 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
901 break;
902 case IRCOMM_TTY_DETACH_CABLE:
903 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
904 break;
905 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800906 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 ircomm_tty_event[event]);
908 ret = -EINVAL;
909 }
910 return ret;
911}
912
913/*
914 * Function ircomm_tty_state_setup (self, event, skb, info)
915 *
916 * Trying to connect
917 *
918 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900919static int ircomm_tty_state_setup(struct ircomm_tty_cb *self,
920 IRCOMM_TTY_EVENT event,
921 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 struct ircomm_tty_info *info)
923{
924 int ret = 0;
925
Harvey Harrison0dc47872008-03-05 20:47:47 -0800926 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 ircomm_tty_state[self->state], ircomm_tty_event[event]);
928
929 switch (event) {
930 case IRCOMM_TTY_CONNECT_CONFIRM:
931 del_timer(&self->watchdog_timer);
932 ircomm_tty_ias_unregister(self);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900933
934 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 * Send initial parameters. This will also send out queued
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900936 * parameters waiting for the connection to come up
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 */
938 ircomm_tty_send_initial_parameters(self);
939 ircomm_tty_link_established(self);
940 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
941 break;
942 case IRCOMM_TTY_CONNECT_INDICATION:
943 del_timer(&self->watchdog_timer);
944 ircomm_tty_ias_unregister(self);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 /* Accept connection */
947 ircomm_connect_response(self->ircomm, NULL);
948 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
949 break;
950 case IRCOMM_TTY_WD_TIMER_EXPIRED:
951 /* Go back to search mode */
952 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
953 ircomm_tty_start_watchdog_timer(self, 3*HZ);
954 break;
955 case IRCOMM_TTY_DETACH_CABLE:
956 /* ircomm_disconnect_request(self->ircomm, NULL); */
957 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
958 break;
959 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -0800960 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 ircomm_tty_event[event]);
962 ret = -EINVAL;
963 }
964 return ret;
965}
966
967/*
968 * Function ircomm_tty_state_ready (self, event, skb, info)
969 *
970 * IrCOMM is now connected
971 *
972 */
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900973static int ircomm_tty_state_ready(struct ircomm_tty_cb *self,
974 IRCOMM_TTY_EVENT event,
975 struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 struct ircomm_tty_info *info)
977{
978 int ret = 0;
979
980 switch (event) {
981 case IRCOMM_TTY_DATA_REQUEST:
982 ret = ircomm_data_request(self->ircomm, skb);
YOSHIFUJI Hideaki6819bc22007-02-09 23:24:53 +0900983 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 case IRCOMM_TTY_DETACH_CABLE:
985 ircomm_disconnect_request(self->ircomm, NULL);
986 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
987 break;
988 case IRCOMM_TTY_DISCONNECT_INDICATION:
989 ircomm_tty_ias_register(self);
990 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
991 ircomm_tty_start_watchdog_timer(self, 3*HZ);
992
Jiri Slaby849d5a92012-06-04 13:35:19 +0200993 if (self->port.flags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 /* Drop carrier */
995 self->settings.dce = IRCOMM_DELTA_CD;
996 ircomm_tty_check_modem_status(self);
997 } else {
Harvey Harrison0dc47872008-03-05 20:47:47 -0800998 IRDA_DEBUG(0, "%s(), hanging up!\n", __func__ );
Jiri Slabyaa27a092013-03-07 13:12:30 +0100999 tty_port_tty_hangup(&self->port, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001 break;
1002 default:
Harvey Harrison0dc47872008-03-05 20:47:47 -08001003 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 ircomm_tty_event[event]);
1005 ret = -EINVAL;
1006 }
1007 return ret;
1008}
1009