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, see <http://www.gnu.org/licenses/>.
28 ********************************************************************/
30 #include <linux/init.h>
31 #include <linux/sched.h>
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>
40 #include <net/irda/ircomm_core.h>
41 #include <net/irda/ircomm_param.h>
42 #include <net/irda/ircomm_event.h>
44 #include <net/irda/ircomm_tty.h>
45 #include <net/irda/ircomm_tty_attach.h>
47 static void ircomm_tty_ias_register(struct ircomm_tty_cb
*self
);
48 static void ircomm_tty_discovery_indication(discinfo_t
*discovery
,
51 static void ircomm_tty_getvalue_confirm(int result
, __u16 obj_id
,
52 struct ias_value
*value
, void *priv
);
53 static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb
*self
,
55 static void ircomm_tty_watchdog_timer_expired(void *data
);
57 static int ircomm_tty_state_idle(struct ircomm_tty_cb
*self
,
58 IRCOMM_TTY_EVENT event
,
60 struct ircomm_tty_info
*info
);
61 static int ircomm_tty_state_search(struct ircomm_tty_cb
*self
,
62 IRCOMM_TTY_EVENT event
,
64 struct ircomm_tty_info
*info
);
65 static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb
*self
,
66 IRCOMM_TTY_EVENT event
,
68 struct ircomm_tty_info
*info
);
69 static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb
*self
,
70 IRCOMM_TTY_EVENT event
,
72 struct ircomm_tty_info
*info
);
73 static int ircomm_tty_state_setup(struct ircomm_tty_cb
*self
,
74 IRCOMM_TTY_EVENT event
,
76 struct ircomm_tty_info
*info
);
77 static int ircomm_tty_state_ready(struct ircomm_tty_cb
*self
,
78 IRCOMM_TTY_EVENT event
,
80 struct ircomm_tty_info
*info
);
82 const char *const ircomm_tty_state
[] = {
85 "IRCOMM_TTY_QUERY_PARAMETERS",
86 "IRCOMM_TTY_QUERY_LSAP_SEL",
92 #ifdef CONFIG_IRDA_DEBUG
93 static const char *const 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",
109 #endif /* CONFIG_IRDA_DEBUG */
111 static int (*state
[])(struct ircomm_tty_cb
*self
, IRCOMM_TTY_EVENT event
,
112 struct sk_buff
*skb
, struct ircomm_tty_info
*info
) =
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
,
123 * Function ircomm_tty_attach_cable (driver)
125 * Try to attach cable (IrCOMM link). This function will only return
126 * when the link has been connected, or if an error condition occurs.
127 * If success, the return value is the resulting service type.
129 int ircomm_tty_attach_cable(struct ircomm_tty_cb
*self
)
131 struct tty_struct
*tty
;
133 IRDA_DEBUG(0, "%s()\n", __func__
);
135 IRDA_ASSERT(self
!= NULL
, return -1;);
136 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
138 /* Check if somebody has already connected to us */
139 if (ircomm_is_connected(self
->ircomm
)) {
140 IRDA_DEBUG(0, "%s(), already connected!\n", __func__
);
144 /* Make sure nobody tries to write before the link is up */
145 tty
= tty_port_tty_get(&self
->port
);
151 ircomm_tty_ias_register(self
);
153 ircomm_tty_do_event(self
, IRCOMM_TTY_ATTACH_CABLE
, NULL
, NULL
);
159 * Function ircomm_detach_cable (driver)
161 * Detach cable, or cable has been detached by peer
164 void ircomm_tty_detach_cable(struct ircomm_tty_cb
*self
)
166 IRDA_DEBUG(0, "%s()\n", __func__
);
168 IRDA_ASSERT(self
!= NULL
, return;);
169 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
171 del_timer(&self
->watchdog_timer
);
173 /* Remove discovery handler */
175 irlmp_unregister_client(self
->ckey
);
178 /* Remove IrCOMM hint bits */
180 irlmp_unregister_service(self
->skey
);
185 iriap_close(self
->iriap
);
189 /* Remove LM-IAS object */
191 irias_delete_object(self
->obj
);
195 ircomm_tty_do_event(self
, IRCOMM_TTY_DETACH_CABLE
, NULL
, NULL
);
197 /* Reset some values */
198 self
->daddr
= self
->saddr
= 0;
199 self
->dlsap_sel
= self
->slsap_sel
= 0;
201 memset(&self
->settings
, 0, sizeof(struct ircomm_params
));
205 * Function ircomm_tty_ias_register (self)
207 * Register with LM-IAS depending on which service type we are
210 static void ircomm_tty_ias_register(struct ircomm_tty_cb
*self
)
215 IRDA_DEBUG(0, "%s()\n", __func__
);
217 IRDA_ASSERT(self
!= NULL
, return;);
218 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
220 /* 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
);
225 /* Advertise IrCOMM hint bit in discovery */
227 self
->skey
= irlmp_register_service(hints
);
228 /* Set up a discovery handler */
230 self
->ckey
= irlmp_register_client(hints
,
231 ircomm_tty_discovery_indication
,
232 NULL
, (void *) self
);
234 /* If already done, no need to do it again */
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
);
241 irias_add_integer_attrib(self
->obj
, "IrDA:IrLMP:LsapSel",
242 self
->slsap_sel
, IAS_KERNEL_ATTR
);
244 /* Register IrCOMM with LM-IAS */
245 self
->obj
= irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID
);
246 irias_add_integer_attrib(self
->obj
, "IrDA:TinyTP:LsapSel",
247 self
->slsap_sel
, IAS_KERNEL_ATTR
);
249 /* Code the parameters into the buffer */
250 irda_param_pack(oct_seq
, "bbbbbb",
251 IRCOMM_SERVICE_TYPE
, 1, self
->service_type
,
252 IRCOMM_PORT_TYPE
, 1, IRCOMM_SERIAL
);
254 /* Register parameters with LM-IAS */
255 irias_add_octseq_attrib(self
->obj
, "Parameters", oct_seq
, 6,
258 irias_insert_object(self
->obj
);
262 * Function ircomm_tty_ias_unregister (self)
264 * Remove our IAS object and client hook while connected.
267 static void ircomm_tty_ias_unregister(struct ircomm_tty_cb
*self
)
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.
282 irias_delete_object(self
->obj
);
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 */
292 irlmp_unregister_client(self
->ckey
);
299 * Function ircomm_send_initial_parameters (self)
301 * Send initial parameters to the remote IrCOMM device. These parameters
302 * must be sent before any data.
304 int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb
*self
)
306 IRDA_ASSERT(self
!= NULL
, return -1;);
307 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
309 if (self
->service_type
& IRCOMM_3_WIRE_RAW
)
313 * Set default values, but only if the application for some reason
314 * haven't set them already
316 IRDA_DEBUG(2, "%s(), data-rate = %d\n", __func__
,
317 self
->settings
.data_rate
);
318 if (!self
->settings
.data_rate
)
319 self
->settings
.data_rate
= 9600;
320 IRDA_DEBUG(2, "%s(), data-format = %d\n", __func__
,
321 self
->settings
.data_format
);
322 if (!self
->settings
.data_format
)
323 self
->settings
.data_format
= IRCOMM_WSIZE_8
; /* 8N1 */
325 IRDA_DEBUG(2, "%s(), flow-control = %d\n", __func__
,
326 self
->settings
.flow_control
);
327 /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/
329 /* Do not set delta values for the initial parameters */
330 self
->settings
.dte
= IRCOMM_DTR
| IRCOMM_RTS
;
332 /* Only send service type parameter when we are the 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
);
338 /* 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
);
344 /* Only 9-wire service types continue here */
345 ircomm_param_request(self
, IRCOMM_FLOW_CONTROL
, FALSE
);
347 ircomm_param_request(self
, IRCOMM_XON_XOFF
, FALSE
);
348 ircomm_param_request(self
, IRCOMM_ENQ_ACK
, FALSE
);
350 /* Notify peer that we are ready to receive data */
351 ircomm_param_request(self
, IRCOMM_DTE
, TRUE
);
357 * Function ircomm_tty_discovery_indication (discovery)
359 * Remote device is discovered, try query the remote IAS to see which
360 * device it is, and which services it has.
363 static void ircomm_tty_discovery_indication(discinfo_t
*discovery
,
367 struct ircomm_tty_cb
*self
;
368 struct ircomm_tty_info info
;
370 IRDA_DEBUG(2, "%s()\n", __func__
);
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.
383 if(mode
== DISCOVERY_PASSIVE
)
386 info
.daddr
= discovery
->daddr
;
387 info
.saddr
= discovery
->saddr
;
390 ircomm_tty_do_event(self
, IRCOMM_TTY_DISCOVERY_INDICATION
,
395 * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb)
400 void ircomm_tty_disconnect_indication(void *instance
, void *sap
,
404 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
405 struct tty_struct
*tty
;
407 IRDA_DEBUG(2, "%s()\n", __func__
);
409 IRDA_ASSERT(self
!= NULL
, return;);
410 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
412 tty
= tty_port_tty_get(&self
->port
);
416 /* This will stop control data transfers */
417 self
->flow
= FLOW_STOP
;
419 /* Stop data transfers */
422 ircomm_tty_do_event(self
, IRCOMM_TTY_DISCONNECT_INDICATION
, NULL
,
428 * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv)
430 * Got result from the IAS query we make
433 static void ircomm_tty_getvalue_confirm(int result
, __u16 obj_id
,
434 struct ias_value
*value
,
437 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) priv
;
439 IRDA_DEBUG(2, "%s()\n", __func__
);
441 IRDA_ASSERT(self
!= NULL
, return;);
442 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
444 /* We probably don't need to make any more queries */
445 iriap_close(self
->iriap
);
448 /* Check if request succeeded */
449 if (result
!= IAS_SUCCESS
) {
450 IRDA_DEBUG(4, "%s(), got NULL value!\n", __func__
);
454 switch (value
->type
) {
456 IRDA_DEBUG(2, "%s(), got octet sequence\n", __func__
);
458 irda_param_extract_all(self
, value
->t
.oct_seq
, value
->len
,
461 ircomm_tty_do_event(self
, IRCOMM_TTY_GOT_PARAMETERS
, NULL
,
465 /* Got LSAP selector */
466 IRDA_DEBUG(2, "%s(), got lsapsel = %d\n", __func__
,
469 if (value
->t
.integer
== -1) {
470 IRDA_DEBUG(0, "%s(), invalid value!\n", __func__
);
472 self
->dlsap_sel
= value
->t
.integer
;
474 ircomm_tty_do_event(self
, IRCOMM_TTY_GOT_LSAPSEL
, NULL
, NULL
);
477 IRDA_DEBUG(0, "%s(), got IAS_MISSING\n", __func__
);
480 IRDA_DEBUG(0, "%s(), got unknown type!\n", __func__
);
483 irias_delete_value(value
);
487 * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb)
489 * Connection confirmed
492 void ircomm_tty_connect_confirm(void *instance
, void *sap
,
493 struct qos_info
*qos
,
495 __u8 max_header_size
,
498 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
500 IRDA_DEBUG(2, "%s()\n", __func__
);
502 IRDA_ASSERT(self
!= NULL
, return;);
503 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
506 self
->max_data_size
= max_data_size
;
507 self
->max_header_size
= max_header_size
;
508 self
->flow
= FLOW_START
;
510 ircomm_tty_do_event(self
, IRCOMM_TTY_CONNECT_CONFIRM
, NULL
, NULL
);
512 /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */
516 * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size,
519 * we are discovered and being requested to connect by remote device !
522 void ircomm_tty_connect_indication(void *instance
, void *sap
,
523 struct qos_info
*qos
,
525 __u8 max_header_size
,
528 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
531 IRDA_DEBUG(2, "%s()\n", __func__
);
533 IRDA_ASSERT(self
!= NULL
, return;);
534 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
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
;
543 irda_param_extract_all(self
, skb
->data
+1,
544 IRDA_MIN(skb
->len
, clen
),
547 ircomm_tty_do_event(self
, IRCOMM_TTY_CONNECT_INDICATION
, NULL
, NULL
);
549 /* No need to kfree_skb - see ircomm_ttp_connect_indication() */
553 * Function ircomm_tty_link_established (self)
555 * Called when the IrCOMM link is established
558 void ircomm_tty_link_established(struct ircomm_tty_cb
*self
)
560 struct tty_struct
*tty
;
562 IRDA_DEBUG(2, "%s()\n", __func__
);
564 IRDA_ASSERT(self
!= NULL
, return;);
565 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
567 tty
= tty_port_tty_get(&self
->port
);
571 del_timer(&self
->watchdog_timer
);
574 * 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
579 if (tty_port_cts_enabled(&self
->port
) &&
580 ((self
->settings
.dce
& IRCOMM_CTS
) == 0)) {
581 IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__
);
584 IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__
);
588 /* Wake up processes blocked on open */
589 wake_up_interruptible(&self
->port
.open_wait
);
592 schedule_work(&self
->tqueue
);
598 * Function ircomm_tty_start_watchdog_timer (self, timeout)
600 * 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
604 static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb
*self
,
607 IRDA_ASSERT(self
!= NULL
, return;);
608 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
610 irda_start_timer(&self
->watchdog_timer
, timeout
, (void *) self
,
611 ircomm_tty_watchdog_timer_expired
);
615 * Function ircomm_tty_watchdog_timer_expired (data)
617 * Called when the connect procedure have taken to much time.
620 static void ircomm_tty_watchdog_timer_expired(void *data
)
622 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) data
;
624 IRDA_DEBUG(2, "%s()\n", __func__
);
626 IRDA_ASSERT(self
!= NULL
, return;);
627 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
629 ircomm_tty_do_event(self
, IRCOMM_TTY_WD_TIMER_EXPIRED
, NULL
, NULL
);
634 * Function ircomm_tty_do_event (self, event, skb)
639 int ircomm_tty_do_event(struct ircomm_tty_cb
*self
, IRCOMM_TTY_EVENT event
,
640 struct sk_buff
*skb
, struct ircomm_tty_info
*info
)
642 IRDA_ASSERT(self
!= NULL
, return -1;);
643 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
645 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
646 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
648 return (*state
[self
->state
])(self
, event
, skb
, info
);
652 * Function ircomm_tty_next_state (self, state)
657 static inline void ircomm_tty_next_state(struct ircomm_tty_cb
*self
, IRCOMM_TTY_STATE state
)
660 IRDA_ASSERT(self != NULL, return;);
661 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
663 IRDA_DEBUG(2, "%s: next state=%s, service type=%d\n", __func__ ,
664 ircomm_tty_state[self->state], self->service_type);
670 * Function ircomm_tty_state_idle (self, event, skb, info)
672 * Just hanging around
675 static int ircomm_tty_state_idle(struct ircomm_tty_cb
*self
,
676 IRCOMM_TTY_EVENT event
,
678 struct ircomm_tty_info
*info
)
682 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
683 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
685 case IRCOMM_TTY_ATTACH_CABLE
:
686 /* Try to discover any remote devices */
687 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
688 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
690 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
692 case IRCOMM_TTY_DISCOVERY_INDICATION
:
693 self
->daddr
= info
->daddr
;
694 self
->saddr
= info
->saddr
;
697 IRDA_WARNING("%s(), busy with a previous query\n",
702 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
703 ircomm_tty_getvalue_confirm
);
705 iriap_getvaluebyclass_request(self
->iriap
,
706 self
->saddr
, self
->daddr
,
707 "IrDA:IrCOMM", "Parameters");
709 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
710 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_PARAMETERS
);
712 case IRCOMM_TTY_CONNECT_INDICATION
:
713 del_timer(&self
->watchdog_timer
);
715 /* Accept connection */
716 ircomm_connect_response(self
->ircomm
, NULL
);
717 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
719 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
722 case IRCOMM_TTY_DETACH_CABLE
:
723 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
726 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
727 ircomm_tty_event
[event
]);
734 * Function ircomm_tty_state_search (self, event, skb, info)
736 * Trying to discover an IrCOMM device
739 static int ircomm_tty_state_search(struct ircomm_tty_cb
*self
,
740 IRCOMM_TTY_EVENT event
,
742 struct ircomm_tty_info
*info
)
746 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
747 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
750 case IRCOMM_TTY_DISCOVERY_INDICATION
:
751 self
->daddr
= info
->daddr
;
752 self
->saddr
= info
->saddr
;
755 IRDA_WARNING("%s(), busy with a previous query\n",
760 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
761 ircomm_tty_getvalue_confirm
);
763 if (self
->service_type
== IRCOMM_3_WIRE_RAW
) {
764 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
765 self
->daddr
, "IrLPT",
766 "IrDA:IrLMP:LsapSel");
767 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_LSAP_SEL
);
769 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
774 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_PARAMETERS
);
776 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
778 case IRCOMM_TTY_CONNECT_INDICATION
:
779 del_timer(&self
->watchdog_timer
);
780 ircomm_tty_ias_unregister(self
);
782 /* Accept connection */
783 ircomm_connect_response(self
->ircomm
, NULL
);
784 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
786 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
790 /* Try to discover any remote devices */
791 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
792 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
795 case IRCOMM_TTY_DETACH_CABLE
:
796 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
799 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
800 ircomm_tty_event
[event
]);
807 * Function ircomm_tty_state_query (self, event, skb, info)
809 * Querying the remote LM-IAS for IrCOMM parameters
812 static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb
*self
,
813 IRCOMM_TTY_EVENT event
,
815 struct ircomm_tty_info
*info
)
819 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
820 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
823 case IRCOMM_TTY_GOT_PARAMETERS
:
825 IRDA_WARNING("%s(), busy with a previous query\n",
830 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
831 ircomm_tty_getvalue_confirm
);
833 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
834 self
->daddr
, "IrDA:IrCOMM",
835 "IrDA:TinyTP:LsapSel");
837 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
838 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_LSAP_SEL
);
840 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
841 /* Go back to search mode */
842 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
843 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
845 case IRCOMM_TTY_CONNECT_INDICATION
:
846 del_timer(&self
->watchdog_timer
);
847 ircomm_tty_ias_unregister(self
);
849 /* Accept connection */
850 ircomm_connect_response(self
->ircomm
, NULL
);
851 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
853 case IRCOMM_TTY_DETACH_CABLE
:
854 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
857 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
858 ircomm_tty_event
[event
]);
865 * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info)
867 * Query remote LM-IAS for the LSAP selector which we can connect to
870 static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb
*self
,
871 IRCOMM_TTY_EVENT event
,
873 struct ircomm_tty_info
*info
)
877 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
878 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
881 case IRCOMM_TTY_GOT_LSAPSEL
:
882 /* Connect to remote device */
883 ret
= ircomm_connect_request(self
->ircomm
, self
->dlsap_sel
,
884 self
->saddr
, self
->daddr
,
885 NULL
, self
->service_type
);
886 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
887 ircomm_tty_next_state(self
, IRCOMM_TTY_SETUP
);
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
);
894 case IRCOMM_TTY_CONNECT_INDICATION
:
895 del_timer(&self
->watchdog_timer
);
896 ircomm_tty_ias_unregister(self
);
898 /* Accept connection */
899 ircomm_connect_response(self
->ircomm
, NULL
);
900 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
902 case IRCOMM_TTY_DETACH_CABLE
:
903 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
906 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
907 ircomm_tty_event
[event
]);
914 * Function ircomm_tty_state_setup (self, event, skb, info)
919 static int ircomm_tty_state_setup(struct ircomm_tty_cb
*self
,
920 IRCOMM_TTY_EVENT event
,
922 struct ircomm_tty_info
*info
)
926 IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__
,
927 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
930 case IRCOMM_TTY_CONNECT_CONFIRM
:
931 del_timer(&self
->watchdog_timer
);
932 ircomm_tty_ias_unregister(self
);
935 * Send initial parameters. This will also send out queued
936 * parameters waiting for the connection to come up
938 ircomm_tty_send_initial_parameters(self
);
939 ircomm_tty_link_established(self
);
940 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
942 case IRCOMM_TTY_CONNECT_INDICATION
:
943 del_timer(&self
->watchdog_timer
);
944 ircomm_tty_ias_unregister(self
);
946 /* Accept connection */
947 ircomm_connect_response(self
->ircomm
, NULL
);
948 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
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
);
955 case IRCOMM_TTY_DETACH_CABLE
:
956 /* ircomm_disconnect_request(self->ircomm, NULL); */
957 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
960 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
961 ircomm_tty_event
[event
]);
968 * Function ircomm_tty_state_ready (self, event, skb, info)
970 * IrCOMM is now connected
973 static int ircomm_tty_state_ready(struct ircomm_tty_cb
*self
,
974 IRCOMM_TTY_EVENT event
,
976 struct ircomm_tty_info
*info
)
981 case IRCOMM_TTY_DATA_REQUEST
:
982 ret
= ircomm_data_request(self
->ircomm
, skb
);
984 case IRCOMM_TTY_DETACH_CABLE
:
985 ircomm_disconnect_request(self
->ircomm
, NULL
);
986 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
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
);
993 if (self
->port
.flags
& ASYNC_CHECK_CD
) {
995 self
->settings
.dce
= IRCOMM_DELTA_CD
;
996 ircomm_tty_check_modem_status(self
);
998 IRDA_DEBUG(0, "%s(), hanging up!\n", __func__
);
999 tty_port_tty_hangup(&self
->port
, false);
1003 IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__
,
1004 ircomm_tty_event
[event
]);