1 /*********************************************************************
3 * Filename: ircomm_tty_attach.c
5 * 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>
12 * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
13 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
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
18 * the License, or (at your option) any later version.
20 * 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.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 ********************************************************************/
32 #include <linux/sched.h>
33 #include <linux/init.h>
35 #include <net/irda/irda.h>
36 #include <net/irda/irlmp.h>
37 #include <net/irda/iriap.h>
38 #include <net/irda/irttp.h>
39 #include <net/irda/irias_object.h>
40 #include <net/irda/parameters.h>
42 #include <net/irda/ircomm_core.h>
43 #include <net/irda/ircomm_param.h>
44 #include <net/irda/ircomm_event.h>
46 #include <net/irda/ircomm_tty.h>
47 #include <net/irda/ircomm_tty_attach.h>
49 static void ircomm_tty_ias_register(struct ircomm_tty_cb *self);
50 static void ircomm_tty_discovery_indication(discinfo_t *discovery,
53 static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id,
54 struct ias_value *value, void *priv);
55 void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, int timeout);
56 void ircomm_tty_watchdog_timer_expired(void *data);
58 static int ircomm_tty_state_idle(struct ircomm_tty_cb *self,
59 IRCOMM_TTY_EVENT event,
61 struct ircomm_tty_info *info);
62 static int ircomm_tty_state_search(struct ircomm_tty_cb *self,
63 IRCOMM_TTY_EVENT event,
65 struct ircomm_tty_info *info);
66 static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self,
67 IRCOMM_TTY_EVENT event,
69 struct ircomm_tty_info *info);
70 static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self,
71 IRCOMM_TTY_EVENT event,
73 struct ircomm_tty_info *info);
74 static int ircomm_tty_state_setup(struct ircomm_tty_cb *self,
75 IRCOMM_TTY_EVENT event,
77 struct ircomm_tty_info *info);
78 static int ircomm_tty_state_ready(struct ircomm_tty_cb *self,
79 IRCOMM_TTY_EVENT event,
81 struct ircomm_tty_info *info);
83 char *ircomm_tty_state[] = {
86 "IRCOMM_TTY_QUERY_PARAMETERS",
87 "IRCOMM_TTY_QUERY_LSAP_SEL",
93 char *ircomm_tty_event[] = {
94 "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",
110 static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event,
111 struct sk_buff *skb, struct ircomm_tty_info *info) =
113 ircomm_tty_state_idle,
114 ircomm_tty_state_search,
115 ircomm_tty_state_query_parameters,
116 ircomm_tty_state_query_lsap_sel,
117 ircomm_tty_state_setup,
118 ircomm_tty_state_ready,
122 * Function ircomm_tty_attach_cable (driver)
124 * Try to attach cable (IrCOMM link). This function will only return
125 * when the link has been connected, or if an error condition occurs.
126 * If success, the return value is the resulting service type.
128 int ircomm_tty_attach_cable(struct ircomm_tty_cb *self)
130 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
132 ASSERT(self != NULL, return -1;);
133 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
135 /* Check if somebody has already connected to us */
136 if (ircomm_is_connected(self->ircomm)) {
137 IRDA_DEBUG(0, "%s(), already connected!\n", __FUNCTION__ );
141 /* Make sure nobody tries to write before the link is up */
142 self->tty->hw_stopped = 1;
144 ircomm_tty_ias_register(self);
146 ircomm_tty_do_event(self, IRCOMM_TTY_ATTACH_CABLE, NULL, NULL);
152 * Function ircomm_detach_cable (driver)
154 * Detach cable, or cable has been detached by peer
157 void ircomm_tty_detach_cable(struct ircomm_tty_cb *self)
159 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
161 ASSERT(self != NULL, return;);
162 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
164 del_timer(&self->watchdog_timer);
166 /* Remove discovery handler */
168 irlmp_unregister_client(self->ckey);
171 /* Remove IrCOMM hint bits */
173 irlmp_unregister_service(self->skey);
178 iriap_close(self->iriap);
182 /* Remove LM-IAS object */
184 irias_delete_object(self->obj);
188 ircomm_tty_do_event(self, IRCOMM_TTY_DETACH_CABLE, NULL, NULL);
190 /* Reset some values */
191 self->daddr = self->saddr = 0;
192 self->dlsap_sel = self->slsap_sel = 0;
194 memset(&self->settings, 0, sizeof(struct ircomm_params));
198 * Function ircomm_tty_ias_register (self)
200 * Register with LM-IAS depending on which service type we are
203 static void ircomm_tty_ias_register(struct ircomm_tty_cb *self)
208 IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
210 ASSERT(self != NULL, return;);
211 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
213 /* Compute hint bits based on service */
214 hints = irlmp_service_to_hint(S_COMM);
215 if (self->service_type & IRCOMM_3_WIRE_RAW)
216 hints |= irlmp_service_to_hint(S_PRINTER);
218 /* Advertise IrCOMM hint bit in discovery */
220 self->skey = irlmp_register_service(hints);
221 /* Set up a discovery handler */
223 self->ckey = irlmp_register_client(hints,
224 ircomm_tty_discovery_indication,
225 NULL, (void *) self);
227 /* If already done, no need to do it again */
231 if (self->service_type & IRCOMM_3_WIRE_RAW) {
232 /* Register IrLPT with LM-IAS */
233 self->obj = irias_new_object("IrLPT", IAS_IRLPT_ID);
234 irias_add_integer_attrib(self->obj, "IrDA:IrLMP:LsapSel",
235 self->slsap_sel, IAS_KERNEL_ATTR);
237 /* Register IrCOMM with LM-IAS */
238 self->obj = irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID);
239 irias_add_integer_attrib(self->obj, "IrDA:TinyTP:LsapSel",
240 self->slsap_sel, IAS_KERNEL_ATTR);
242 /* Code the parameters into the buffer */
243 irda_param_pack(oct_seq, "bbbbbb",
244 IRCOMM_SERVICE_TYPE, 1, self->service_type,
245 IRCOMM_PORT_TYPE, 1, IRCOMM_SERIAL);
247 /* Register parameters with LM-IAS */
248 irias_add_octseq_attrib(self->obj, "Parameters", oct_seq, 6,
251 irias_insert_object(self->obj);
255 * Function ircomm_tty_ias_unregister (self)
257 * Remove our IAS object and client hook while connected.
260 static void ircomm_tty_ias_unregister(struct ircomm_tty_cb *self)
262 /* Remove LM-IAS object now so it is not reused.
263 * IrCOMM deals very poorly with multiple incoming connections.
264 * It should looks a lot more like IrNET, and "dup" a server TSAP
265 * to the application TSAP (based on various rules).
266 * This is a cheap workaround allowing multiple clients to
267 * connect to us. It will not always work.
268 * Each IrCOMM socket has an IAS entry. Incoming connection will
269 * pick the first one found. So, when we are fully connected,
270 * we remove our IAS entries so that the next IAS entry is used.
271 * We do that for *both* client and server, because a server
272 * can also create client instances.
275 irias_delete_object(self->obj);
280 /* Remove discovery handler.
281 * While we are connected, we no longer need to receive
282 * discovery events. This would be the case if there is
283 * multiple IrLAP interfaces. Jean II */
285 irlmp_unregister_client(self->ckey);
292 * Function ircomm_send_initial_parameters (self)
294 * Send initial parameters to the remote IrCOMM device. These parameters
295 * must be sent before any data.
297 int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb *self)
299 ASSERT(self != NULL, return -1;);
300 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
302 if (self->service_type & IRCOMM_3_WIRE_RAW)
306 * Set default values, but only if the application for some reason
307 * haven't set them already
309 IRDA_DEBUG(2, "%s(), data-rate = %d\n", __FUNCTION__ ,
310 self->settings.data_rate);
311 if (!self->settings.data_rate)
312 self->settings.data_rate = 9600;
313 IRDA_DEBUG(2, "%s(), data-format = %d\n", __FUNCTION__ ,
314 self->settings.data_format);
315 if (!self->settings.data_format)
316 self->settings.data_format = IRCOMM_WSIZE_8; /* 8N1 */
318 IRDA_DEBUG(2, "%s(), flow-control = %d\n", __FUNCTION__ ,
319 self->settings.flow_control);
320 /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/
322 /* Do not set delta values for the initial parameters */
323 self->settings.dte = IRCOMM_DTR | IRCOMM_RTS;
325 /* Only send service type parameter when we are the client */
327 ircomm_param_request(self, IRCOMM_SERVICE_TYPE, FALSE);
328 ircomm_param_request(self, IRCOMM_DATA_RATE, FALSE);
329 ircomm_param_request(self, IRCOMM_DATA_FORMAT, FALSE);
331 /* For a 3 wire service, we just flush the last parameter and return */
332 if (self->settings.service_type == IRCOMM_3_WIRE) {
333 ircomm_param_request(self, IRCOMM_FLOW_CONTROL, TRUE);
337 /* Only 9-wire service types continue here */
338 ircomm_param_request(self, IRCOMM_FLOW_CONTROL, FALSE);
340 ircomm_param_request(self, IRCOMM_XON_XOFF, FALSE);
341 ircomm_param_request(self, IRCOMM_ENQ_ACK, FALSE);
343 /* Notify peer that we are ready to receive data */
344 ircomm_param_request(self, IRCOMM_DTE, TRUE);
350 * Function ircomm_tty_discovery_indication (discovery)
352 * Remote device is discovered, try query the remote IAS to see which
353 * device it is, and which services it has.
356 static void ircomm_tty_discovery_indication(discinfo_t *discovery,
360 struct ircomm_tty_cb *self;
361 struct ircomm_tty_info info;
363 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
366 * We need to drop all passive discoveries.
367 * The LSAP management of IrComm is deficient and doesn't deal
368 * with the case of two instance connecting to each other
369 * simultaneously (it will deadlock in LMP).
370 * The proper fix would be to use the same technique as in IrNET,
371 * to have one server socket and separate instances for the
372 * connecting/connected socket.
373 * The workaround is to drop passive discovery, which drastically
374 * reduce the probability of this happening.
376 if(mode == DISCOVERY_PASSIVE)
379 info.daddr = discovery->daddr;
380 info.saddr = discovery->saddr;
382 /* FIXME. We have a locking problem on the hashbin here.
383 * We probably need to use hashbin_find_next(), but we first
384 * need to ensure that "line" is unique. - Jean II */
385 self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
386 while (self != NULL) {
387 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
389 ircomm_tty_do_event(self, IRCOMM_TTY_DISCOVERY_INDICATION,
392 self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
397 * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb)
402 void ircomm_tty_disconnect_indication(void *instance, void *sap,
406 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
408 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
410 ASSERT(self != NULL, return;);
411 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
416 /* This will stop control data transfers */
417 self->flow = FLOW_STOP;
419 /* Stop data transfers */
420 self->tty->hw_stopped = 1;
422 ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL,
427 * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv)
429 * Got result from the IAS query we make
432 static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id,
433 struct ias_value *value,
436 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) priv;
438 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
440 ASSERT(self != NULL, return;);
441 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
443 /* We probably don't need to make any more queries */
444 iriap_close(self->iriap);
447 /* Check if request succeeded */
448 if (result != IAS_SUCCESS) {
449 IRDA_DEBUG(4, "%s(), got NULL value!\n", __FUNCTION__ );
453 switch (value->type) {
455 IRDA_DEBUG(2, "%s(), got octet sequence\n", __FUNCTION__ );
457 irda_param_extract_all(self, value->t.oct_seq, value->len,
460 ircomm_tty_do_event(self, IRCOMM_TTY_GOT_PARAMETERS, NULL,
464 /* Got LSAP selector */
465 IRDA_DEBUG(2, "%s(), got lsapsel = %d\n", __FUNCTION__ ,
468 if (value->t.integer == -1) {
469 IRDA_DEBUG(0, "%s(), invalid value!\n", __FUNCTION__ );
471 self->dlsap_sel = value->t.integer;
473 ircomm_tty_do_event(self, IRCOMM_TTY_GOT_LSAPSEL, NULL, NULL);
476 IRDA_DEBUG(0, "%s(), got IAS_MISSING\n", __FUNCTION__ );
479 IRDA_DEBUG(0, "%s(), got unknown type!\n", __FUNCTION__ );
482 irias_delete_value(value);
486 * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb)
488 * Connection confirmed
491 void ircomm_tty_connect_confirm(void *instance, void *sap,
492 struct qos_info *qos,
494 __u8 max_header_size,
497 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
499 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
501 ASSERT(self != NULL, return;);
502 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
505 self->max_data_size = max_data_size;
506 self->max_header_size = max_header_size;
507 self->flow = FLOW_START;
509 ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_CONFIRM, NULL, NULL);
511 /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */
515 * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size,
518 * we are discovered and being requested to connect by remote device !
521 void ircomm_tty_connect_indication(void *instance, void *sap,
522 struct qos_info *qos,
524 __u8 max_header_size,
527 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
530 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
532 ASSERT(self != NULL, return;);
533 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
535 self->client = FALSE;
536 self->max_data_size = max_data_size;
537 self->max_header_size = max_header_size;
538 self->flow = FLOW_START;
542 irda_param_extract_all(self, skb->data+1,
543 IRDA_MIN(skb->len, clen),
546 ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_INDICATION, NULL, NULL);
548 /* No need to kfree_skb - see ircomm_ttp_connect_indication() */
552 * Function ircomm_tty_link_established (self)
554 * Called when the IrCOMM link is established
557 void ircomm_tty_link_established(struct ircomm_tty_cb *self)
559 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
561 ASSERT(self != NULL, return;);
562 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
567 del_timer(&self->watchdog_timer);
570 * IrCOMM link is now up, and if we are not using hardware
571 * flow-control, then declare the hardware as running. Otherwise we
572 * will have to wait for the peer device (DCE) to raise the CTS
575 if ((self->flags & ASYNC_CTS_FLOW) && ((self->settings.dce & IRCOMM_CTS) == 0)) {
576 IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __FUNCTION__ );
579 IRDA_DEBUG(1, "%s(), starting hardware!\n", __FUNCTION__ );
581 self->tty->hw_stopped = 0;
583 /* Wake up processes blocked on open */
584 wake_up_interruptible(&self->open_wait);
587 schedule_work(&self->tqueue);
591 * Function ircomm_tty_start_watchdog_timer (self, timeout)
593 * Start the watchdog timer. This timer is used to make sure that any
594 * connection attempt is successful, and if not, we will retry after
597 void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, int timeout)
599 ASSERT(self != NULL, return;);
600 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
602 irda_start_timer(&self->watchdog_timer, timeout, (void *) self,
603 ircomm_tty_watchdog_timer_expired);
607 * Function ircomm_tty_watchdog_timer_expired (data)
609 * Called when the connect procedure have taken to much time.
612 void ircomm_tty_watchdog_timer_expired(void *data)
614 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) data;
616 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
618 ASSERT(self != NULL, return;);
619 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
621 ircomm_tty_do_event(self, IRCOMM_TTY_WD_TIMER_EXPIRED, NULL, NULL);
626 * Function ircomm_tty_do_event (self, event, skb)
631 int ircomm_tty_do_event(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event,
632 struct sk_buff *skb, struct ircomm_tty_info *info)
634 ASSERT(self != NULL, return -1;);
635 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
637 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
638 ircomm_tty_state[self->state], ircomm_tty_event[event]);
640 return (*state[self->state])(self, event, skb, info);
644 * Function ircomm_tty_next_state (self, state)
649 static inline void ircomm_tty_next_state(struct ircomm_tty_cb *self, IRCOMM_TTY_STATE state)
652 ASSERT(self != NULL, return;);
653 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
655 IRDA_DEBUG(2, "%s: next state=%s, service type=%d\n", __FUNCTION__ ,
656 ircomm_tty_state[self->state], self->service_type);
662 * Function ircomm_tty_state_idle (self, event, skb, info)
664 * Just hanging around
667 static int ircomm_tty_state_idle(struct ircomm_tty_cb *self,
668 IRCOMM_TTY_EVENT event,
670 struct ircomm_tty_info *info)
674 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
675 ircomm_tty_state[self->state], ircomm_tty_event[event]);
677 case IRCOMM_TTY_ATTACH_CABLE:
678 /* Try to discover any remote devices */
679 ircomm_tty_start_watchdog_timer(self, 3*HZ);
680 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
682 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
684 case IRCOMM_TTY_DISCOVERY_INDICATION:
685 self->daddr = info->daddr;
686 self->saddr = info->saddr;
689 WARNING("%s(), busy with a previous query\n", __FUNCTION__);
693 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
694 ircomm_tty_getvalue_confirm);
696 iriap_getvaluebyclass_request(self->iriap,
697 self->saddr, self->daddr,
698 "IrDA:IrCOMM", "Parameters");
700 ircomm_tty_start_watchdog_timer(self, 3*HZ);
701 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS);
703 case IRCOMM_TTY_CONNECT_INDICATION:
704 del_timer(&self->watchdog_timer);
706 /* Accept connection */
707 ircomm_connect_response(self->ircomm, NULL);
708 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
710 case IRCOMM_TTY_WD_TIMER_EXPIRED:
713 case IRCOMM_TTY_DETACH_CABLE:
714 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
717 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
718 ircomm_tty_event[event]);
725 * Function ircomm_tty_state_search (self, event, skb, info)
727 * Trying to discover an IrCOMM device
730 static int ircomm_tty_state_search(struct ircomm_tty_cb *self,
731 IRCOMM_TTY_EVENT event,
733 struct ircomm_tty_info *info)
737 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
738 ircomm_tty_state[self->state], ircomm_tty_event[event]);
741 case IRCOMM_TTY_DISCOVERY_INDICATION:
742 self->daddr = info->daddr;
743 self->saddr = info->saddr;
746 WARNING("%s(), busy with a previous query\n", __FUNCTION__);
750 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
751 ircomm_tty_getvalue_confirm);
753 if (self->service_type == IRCOMM_3_WIRE_RAW) {
754 iriap_getvaluebyclass_request(self->iriap, self->saddr,
755 self->daddr, "IrLPT",
756 "IrDA:IrLMP:LsapSel");
757 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL);
759 iriap_getvaluebyclass_request(self->iriap, self->saddr,
764 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS);
766 ircomm_tty_start_watchdog_timer(self, 3*HZ);
768 case IRCOMM_TTY_CONNECT_INDICATION:
769 del_timer(&self->watchdog_timer);
770 ircomm_tty_ias_unregister(self);
772 /* Accept connection */
773 ircomm_connect_response(self->ircomm, NULL);
774 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
776 case IRCOMM_TTY_WD_TIMER_EXPIRED:
780 /* Try to discover any remote devices */
781 ircomm_tty_start_watchdog_timer(self, 3*HZ);
782 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
785 case IRCOMM_TTY_DETACH_CABLE:
786 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
789 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
790 ircomm_tty_event[event]);
797 * Function ircomm_tty_state_query (self, event, skb, info)
799 * Querying the remote LM-IAS for IrCOMM parameters
802 static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self,
803 IRCOMM_TTY_EVENT event,
805 struct ircomm_tty_info *info)
809 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
810 ircomm_tty_state[self->state], ircomm_tty_event[event]);
813 case IRCOMM_TTY_GOT_PARAMETERS:
815 WARNING("%s(), busy with a previous query\n", __FUNCTION__);
819 self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
820 ircomm_tty_getvalue_confirm);
822 iriap_getvaluebyclass_request(self->iriap, self->saddr,
823 self->daddr, "IrDA:IrCOMM",
824 "IrDA:TinyTP:LsapSel");
826 ircomm_tty_start_watchdog_timer(self, 3*HZ);
827 ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL);
829 case IRCOMM_TTY_WD_TIMER_EXPIRED:
830 /* Go back to search mode */
831 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
832 ircomm_tty_start_watchdog_timer(self, 3*HZ);
834 case IRCOMM_TTY_CONNECT_INDICATION:
835 del_timer(&self->watchdog_timer);
836 ircomm_tty_ias_unregister(self);
838 /* Accept connection */
839 ircomm_connect_response(self->ircomm, NULL);
840 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
842 case IRCOMM_TTY_DETACH_CABLE:
843 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
846 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
847 ircomm_tty_event[event]);
854 * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info)
856 * Query remote LM-IAS for the LSAP selector which we can connect to
859 static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self,
860 IRCOMM_TTY_EVENT event,
862 struct ircomm_tty_info *info)
866 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
867 ircomm_tty_state[self->state], ircomm_tty_event[event]);
870 case IRCOMM_TTY_GOT_LSAPSEL:
871 /* Connect to remote device */
872 ret = ircomm_connect_request(self->ircomm, self->dlsap_sel,
873 self->saddr, self->daddr,
874 NULL, self->service_type);
875 ircomm_tty_start_watchdog_timer(self, 3*HZ);
876 ircomm_tty_next_state(self, IRCOMM_TTY_SETUP);
878 case IRCOMM_TTY_WD_TIMER_EXPIRED:
879 /* Go back to search mode */
880 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
881 ircomm_tty_start_watchdog_timer(self, 3*HZ);
883 case IRCOMM_TTY_CONNECT_INDICATION:
884 del_timer(&self->watchdog_timer);
885 ircomm_tty_ias_unregister(self);
887 /* Accept connection */
888 ircomm_connect_response(self->ircomm, NULL);
889 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
891 case IRCOMM_TTY_DETACH_CABLE:
892 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
895 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
896 ircomm_tty_event[event]);
903 * Function ircomm_tty_state_setup (self, event, skb, info)
908 static int ircomm_tty_state_setup(struct ircomm_tty_cb *self,
909 IRCOMM_TTY_EVENT event,
911 struct ircomm_tty_info *info)
915 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __FUNCTION__ ,
916 ircomm_tty_state[self->state], ircomm_tty_event[event]);
919 case IRCOMM_TTY_CONNECT_CONFIRM:
920 del_timer(&self->watchdog_timer);
921 ircomm_tty_ias_unregister(self);
924 * Send initial parameters. This will also send out queued
925 * parameters waiting for the connection to come up
927 ircomm_tty_send_initial_parameters(self);
928 ircomm_tty_link_established(self);
929 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
931 case IRCOMM_TTY_CONNECT_INDICATION:
932 del_timer(&self->watchdog_timer);
933 ircomm_tty_ias_unregister(self);
935 /* Accept connection */
936 ircomm_connect_response(self->ircomm, NULL);
937 ircomm_tty_next_state(self, IRCOMM_TTY_READY);
939 case IRCOMM_TTY_WD_TIMER_EXPIRED:
940 /* Go back to search mode */
941 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
942 ircomm_tty_start_watchdog_timer(self, 3*HZ);
944 case IRCOMM_TTY_DETACH_CABLE:
945 /* ircomm_disconnect_request(self->ircomm, NULL); */
946 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
949 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
950 ircomm_tty_event[event]);
957 * Function ircomm_tty_state_ready (self, event, skb, info)
959 * IrCOMM is now connected
962 static int ircomm_tty_state_ready(struct ircomm_tty_cb *self,
963 IRCOMM_TTY_EVENT event,
965 struct ircomm_tty_info *info)
970 case IRCOMM_TTY_DATA_REQUEST:
971 ret = ircomm_data_request(self->ircomm, skb);
973 case IRCOMM_TTY_DETACH_CABLE:
974 ircomm_disconnect_request(self->ircomm, NULL);
975 ircomm_tty_next_state(self, IRCOMM_TTY_IDLE);
977 case IRCOMM_TTY_DISCONNECT_INDICATION:
978 ircomm_tty_ias_register(self);
979 ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH);
980 ircomm_tty_start_watchdog_timer(self, 3*HZ);
982 if (self->flags & ASYNC_CHECK_CD) {
984 self->settings.dce = IRCOMM_DELTA_CD;
985 ircomm_tty_check_modem_status(self);
987 IRDA_DEBUG(0, "%s(), hanging up!\n", __FUNCTION__ );
989 tty_hangup(self->tty);
993 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __FUNCTION__ ,
994 ircomm_tty_event[event]);