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 static const char *const ircomm_tty_event
[] __maybe_unused
= {
93 "IRCOMM_TTY_ATTACH_CABLE",
94 "IRCOMM_TTY_DETACH_CABLE",
95 "IRCOMM_TTY_DATA_REQUEST",
96 "IRCOMM_TTY_DATA_INDICATION",
97 "IRCOMM_TTY_DISCOVERY_REQUEST",
98 "IRCOMM_TTY_DISCOVERY_INDICATION",
99 "IRCOMM_TTY_CONNECT_CONFIRM",
100 "IRCOMM_TTY_CONNECT_INDICATION",
101 "IRCOMM_TTY_DISCONNECT_REQUEST",
102 "IRCOMM_TTY_DISCONNECT_INDICATION",
103 "IRCOMM_TTY_WD_TIMER_EXPIRED",
104 "IRCOMM_TTY_GOT_PARAMETERS",
105 "IRCOMM_TTY_GOT_LSAPSEL",
109 static int (*state
[])(struct ircomm_tty_cb
*self
, IRCOMM_TTY_EVENT event
,
110 struct sk_buff
*skb
, struct ircomm_tty_info
*info
) =
112 ircomm_tty_state_idle
,
113 ircomm_tty_state_search
,
114 ircomm_tty_state_query_parameters
,
115 ircomm_tty_state_query_lsap_sel
,
116 ircomm_tty_state_setup
,
117 ircomm_tty_state_ready
,
121 * Function ircomm_tty_attach_cable (driver)
123 * Try to attach cable (IrCOMM link). This function will only return
124 * when the link has been connected, or if an error condition occurs.
125 * If success, the return value is the resulting service type.
127 int ircomm_tty_attach_cable(struct ircomm_tty_cb
*self
)
129 struct tty_struct
*tty
;
131 IRDA_ASSERT(self
!= NULL
, return -1;);
132 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
134 /* Check if somebody has already connected to us */
135 if (ircomm_is_connected(self
->ircomm
)) {
136 pr_debug("%s(), already connected!\n", __func__
);
140 /* Make sure nobody tries to write before the link is up */
141 tty
= tty_port_tty_get(&self
->port
);
147 ircomm_tty_ias_register(self
);
149 ircomm_tty_do_event(self
, IRCOMM_TTY_ATTACH_CABLE
, NULL
, NULL
);
155 * Function ircomm_detach_cable (driver)
157 * Detach cable, or cable has been detached by peer
160 void ircomm_tty_detach_cable(struct ircomm_tty_cb
*self
)
162 IRDA_ASSERT(self
!= NULL
, return;);
163 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
165 del_timer(&self
->watchdog_timer
);
167 /* Remove discovery handler */
169 irlmp_unregister_client(self
->ckey
);
172 /* Remove IrCOMM hint bits */
174 irlmp_unregister_service(self
->skey
);
179 iriap_close(self
->iriap
);
183 /* Remove LM-IAS object */
185 irias_delete_object(self
->obj
);
189 ircomm_tty_do_event(self
, IRCOMM_TTY_DETACH_CABLE
, NULL
, NULL
);
191 /* Reset some values */
192 self
->daddr
= self
->saddr
= 0;
193 self
->dlsap_sel
= self
->slsap_sel
= 0;
195 memset(&self
->settings
, 0, sizeof(struct ircomm_params
));
199 * Function ircomm_tty_ias_register (self)
201 * Register with LM-IAS depending on which service type we are
204 static void ircomm_tty_ias_register(struct ircomm_tty_cb
*self
)
209 IRDA_ASSERT(self
!= NULL
, return;);
210 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
212 /* Compute hint bits based on service */
213 hints
= irlmp_service_to_hint(S_COMM
);
214 if (self
->service_type
& IRCOMM_3_WIRE_RAW
)
215 hints
|= irlmp_service_to_hint(S_PRINTER
);
217 /* Advertise IrCOMM hint bit in discovery */
219 self
->skey
= irlmp_register_service(hints
);
220 /* Set up a discovery handler */
222 self
->ckey
= irlmp_register_client(hints
,
223 ircomm_tty_discovery_indication
,
224 NULL
, (void *) self
);
226 /* If already done, no need to do it again */
230 if (self
->service_type
& IRCOMM_3_WIRE_RAW
) {
231 /* Register IrLPT with LM-IAS */
232 self
->obj
= irias_new_object("IrLPT", IAS_IRLPT_ID
);
233 irias_add_integer_attrib(self
->obj
, "IrDA:IrLMP:LsapSel",
234 self
->slsap_sel
, IAS_KERNEL_ATTR
);
236 /* Register IrCOMM with LM-IAS */
237 self
->obj
= irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID
);
238 irias_add_integer_attrib(self
->obj
, "IrDA:TinyTP:LsapSel",
239 self
->slsap_sel
, IAS_KERNEL_ATTR
);
241 /* Code the parameters into the buffer */
242 irda_param_pack(oct_seq
, "bbbbbb",
243 IRCOMM_SERVICE_TYPE
, 1, self
->service_type
,
244 IRCOMM_PORT_TYPE
, 1, IRCOMM_SERIAL
);
246 /* Register parameters with LM-IAS */
247 irias_add_octseq_attrib(self
->obj
, "Parameters", oct_seq
, 6,
250 irias_insert_object(self
->obj
);
254 * Function ircomm_tty_ias_unregister (self)
256 * Remove our IAS object and client hook while connected.
259 static void ircomm_tty_ias_unregister(struct ircomm_tty_cb
*self
)
261 /* Remove LM-IAS object now so it is not reused.
262 * IrCOMM deals very poorly with multiple incoming connections.
263 * It should looks a lot more like IrNET, and "dup" a server TSAP
264 * to the application TSAP (based on various rules).
265 * This is a cheap workaround allowing multiple clients to
266 * connect to us. It will not always work.
267 * Each IrCOMM socket has an IAS entry. Incoming connection will
268 * pick the first one found. So, when we are fully connected,
269 * we remove our IAS entries so that the next IAS entry is used.
270 * We do that for *both* client and server, because a server
271 * can also create client instances.
274 irias_delete_object(self
->obj
);
279 /* Remove discovery handler.
280 * While we are connected, we no longer need to receive
281 * discovery events. This would be the case if there is
282 * multiple IrLAP interfaces. Jean II */
284 irlmp_unregister_client(self
->ckey
);
291 * Function ircomm_send_initial_parameters (self)
293 * Send initial parameters to the remote IrCOMM device. These parameters
294 * must be sent before any data.
296 int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb
*self
)
298 IRDA_ASSERT(self
!= NULL
, return -1;);
299 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
301 if (self
->service_type
& IRCOMM_3_WIRE_RAW
)
305 * Set default values, but only if the application for some reason
306 * haven't set them already
308 pr_debug("%s(), data-rate = %d\n", __func__
,
309 self
->settings
.data_rate
);
310 if (!self
->settings
.data_rate
)
311 self
->settings
.data_rate
= 9600;
312 pr_debug("%s(), data-format = %d\n", __func__
,
313 self
->settings
.data_format
);
314 if (!self
->settings
.data_format
)
315 self
->settings
.data_format
= IRCOMM_WSIZE_8
; /* 8N1 */
317 pr_debug("%s(), flow-control = %d\n", __func__
,
318 self
->settings
.flow_control
);
319 /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/
321 /* Do not set delta values for the initial parameters */
322 self
->settings
.dte
= IRCOMM_DTR
| IRCOMM_RTS
;
324 /* Only send service type parameter when we are the client */
326 ircomm_param_request(self
, IRCOMM_SERVICE_TYPE
, FALSE
);
327 ircomm_param_request(self
, IRCOMM_DATA_RATE
, FALSE
);
328 ircomm_param_request(self
, IRCOMM_DATA_FORMAT
, FALSE
);
330 /* For a 3 wire service, we just flush the last parameter and return */
331 if (self
->settings
.service_type
== IRCOMM_3_WIRE
) {
332 ircomm_param_request(self
, IRCOMM_FLOW_CONTROL
, TRUE
);
336 /* Only 9-wire service types continue here */
337 ircomm_param_request(self
, IRCOMM_FLOW_CONTROL
, FALSE
);
339 ircomm_param_request(self
, IRCOMM_XON_XOFF
, FALSE
);
340 ircomm_param_request(self
, IRCOMM_ENQ_ACK
, FALSE
);
342 /* Notify peer that we are ready to receive data */
343 ircomm_param_request(self
, IRCOMM_DTE
, TRUE
);
349 * Function ircomm_tty_discovery_indication (discovery)
351 * Remote device is discovered, try query the remote IAS to see which
352 * device it is, and which services it has.
355 static void ircomm_tty_discovery_indication(discinfo_t
*discovery
,
359 struct ircomm_tty_cb
*self
;
360 struct ircomm_tty_info info
;
363 * We need to drop all passive discoveries.
364 * The LSAP management of IrComm is deficient and doesn't deal
365 * with the case of two instance connecting to each other
366 * simultaneously (it will deadlock in LMP).
367 * The proper fix would be to use the same technique as in IrNET,
368 * to have one server socket and separate instances for the
369 * connecting/connected socket.
370 * The workaround is to drop passive discovery, which drastically
371 * reduce the probability of this happening.
373 if(mode
== DISCOVERY_PASSIVE
)
376 info
.daddr
= discovery
->daddr
;
377 info
.saddr
= discovery
->saddr
;
380 ircomm_tty_do_event(self
, IRCOMM_TTY_DISCOVERY_INDICATION
,
385 * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb)
390 void ircomm_tty_disconnect_indication(void *instance
, void *sap
,
394 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
395 struct tty_struct
*tty
;
397 IRDA_ASSERT(self
!= NULL
, return;);
398 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
400 tty
= tty_port_tty_get(&self
->port
);
404 /* This will stop control data transfers */
405 self
->flow
= FLOW_STOP
;
407 /* Stop data transfers */
410 ircomm_tty_do_event(self
, IRCOMM_TTY_DISCONNECT_INDICATION
, NULL
,
416 * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv)
418 * Got result from the IAS query we make
421 static void ircomm_tty_getvalue_confirm(int result
, __u16 obj_id
,
422 struct ias_value
*value
,
425 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) priv
;
427 IRDA_ASSERT(self
!= NULL
, return;);
428 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
430 /* We probably don't need to make any more queries */
431 iriap_close(self
->iriap
);
434 /* Check if request succeeded */
435 if (result
!= IAS_SUCCESS
) {
436 pr_debug("%s(), got NULL value!\n", __func__
);
440 switch (value
->type
) {
442 pr_debug("%s(), got octet sequence\n", __func__
);
444 irda_param_extract_all(self
, value
->t
.oct_seq
, value
->len
,
447 ircomm_tty_do_event(self
, IRCOMM_TTY_GOT_PARAMETERS
, NULL
,
451 /* Got LSAP selector */
452 pr_debug("%s(), got lsapsel = %d\n", __func__
,
455 if (value
->t
.integer
== -1) {
456 pr_debug("%s(), invalid value!\n", __func__
);
458 self
->dlsap_sel
= value
->t
.integer
;
460 ircomm_tty_do_event(self
, IRCOMM_TTY_GOT_LSAPSEL
, NULL
, NULL
);
463 pr_debug("%s(), got IAS_MISSING\n", __func__
);
466 pr_debug("%s(), got unknown type!\n", __func__
);
469 irias_delete_value(value
);
473 * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb)
475 * Connection confirmed
478 void ircomm_tty_connect_confirm(void *instance
, void *sap
,
479 struct qos_info
*qos
,
481 __u8 max_header_size
,
484 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
486 IRDA_ASSERT(self
!= NULL
, return;);
487 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
490 self
->max_data_size
= max_data_size
;
491 self
->max_header_size
= max_header_size
;
492 self
->flow
= FLOW_START
;
494 ircomm_tty_do_event(self
, IRCOMM_TTY_CONNECT_CONFIRM
, NULL
, NULL
);
496 /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */
500 * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size,
503 * we are discovered and being requested to connect by remote device !
506 void ircomm_tty_connect_indication(void *instance
, void *sap
,
507 struct qos_info
*qos
,
509 __u8 max_header_size
,
512 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
515 IRDA_ASSERT(self
!= NULL
, return;);
516 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
518 self
->client
= FALSE
;
519 self
->max_data_size
= max_data_size
;
520 self
->max_header_size
= max_header_size
;
521 self
->flow
= FLOW_START
;
525 irda_param_extract_all(self
, skb
->data
+1,
526 IRDA_MIN(skb
->len
, clen
),
529 ircomm_tty_do_event(self
, IRCOMM_TTY_CONNECT_INDICATION
, NULL
, NULL
);
531 /* No need to kfree_skb - see ircomm_ttp_connect_indication() */
535 * Function ircomm_tty_link_established (self)
537 * Called when the IrCOMM link is established
540 void ircomm_tty_link_established(struct ircomm_tty_cb
*self
)
542 struct tty_struct
*tty
;
544 IRDA_ASSERT(self
!= NULL
, return;);
545 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
547 tty
= tty_port_tty_get(&self
->port
);
551 del_timer(&self
->watchdog_timer
);
554 * IrCOMM link is now up, and if we are not using hardware
555 * flow-control, then declare the hardware as running. Otherwise we
556 * will have to wait for the peer device (DCE) to raise the CTS
559 if (tty_port_cts_enabled(&self
->port
) &&
560 ((self
->settings
.dce
& IRCOMM_CTS
) == 0)) {
561 pr_debug("%s(), waiting for CTS ...\n", __func__
);
564 pr_debug("%s(), starting hardware!\n", __func__
);
568 /* Wake up processes blocked on open */
569 wake_up_interruptible(&self
->port
.open_wait
);
572 schedule_work(&self
->tqueue
);
578 * Function ircomm_tty_start_watchdog_timer (self, timeout)
580 * Start the watchdog timer. This timer is used to make sure that any
581 * connection attempt is successful, and if not, we will retry after
584 static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb
*self
,
587 IRDA_ASSERT(self
!= NULL
, return;);
588 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
590 irda_start_timer(&self
->watchdog_timer
, timeout
, (void *) self
,
591 ircomm_tty_watchdog_timer_expired
);
595 * Function ircomm_tty_watchdog_timer_expired (data)
597 * Called when the connect procedure have taken to much time.
600 static void ircomm_tty_watchdog_timer_expired(void *data
)
602 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) data
;
604 IRDA_ASSERT(self
!= NULL
, return;);
605 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return;);
607 ircomm_tty_do_event(self
, IRCOMM_TTY_WD_TIMER_EXPIRED
, NULL
, NULL
);
612 * Function ircomm_tty_do_event (self, event, skb)
617 int ircomm_tty_do_event(struct ircomm_tty_cb
*self
, IRCOMM_TTY_EVENT event
,
618 struct sk_buff
*skb
, struct ircomm_tty_info
*info
)
620 IRDA_ASSERT(self
!= NULL
, return -1;);
621 IRDA_ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
623 pr_debug("%s: state=%s, event=%s\n", __func__
,
624 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
626 return (*state
[self
->state
])(self
, event
, skb
, info
);
630 * Function ircomm_tty_next_state (self, state)
635 static inline void ircomm_tty_next_state(struct ircomm_tty_cb
*self
, IRCOMM_TTY_STATE state
)
638 IRDA_ASSERT(self != NULL, return;);
639 IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
641 pr_debug("%s: next state=%s, service type=%d\n", __func__ ,
642 ircomm_tty_state[self->state], self->service_type);
648 * Function ircomm_tty_state_idle (self, event, skb, info)
650 * Just hanging around
653 static int ircomm_tty_state_idle(struct ircomm_tty_cb
*self
,
654 IRCOMM_TTY_EVENT event
,
656 struct ircomm_tty_info
*info
)
660 pr_debug("%s: state=%s, event=%s\n", __func__
,
661 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
663 case IRCOMM_TTY_ATTACH_CABLE
:
664 /* Try to discover any remote devices */
665 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
666 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
668 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
670 case IRCOMM_TTY_DISCOVERY_INDICATION
:
671 self
->daddr
= info
->daddr
;
672 self
->saddr
= info
->saddr
;
675 net_warn_ratelimited("%s(), busy with a previous query\n",
680 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
681 ircomm_tty_getvalue_confirm
);
683 iriap_getvaluebyclass_request(self
->iriap
,
684 self
->saddr
, self
->daddr
,
685 "IrDA:IrCOMM", "Parameters");
687 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
688 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_PARAMETERS
);
690 case IRCOMM_TTY_CONNECT_INDICATION
:
691 del_timer(&self
->watchdog_timer
);
693 /* Accept connection */
694 ircomm_connect_response(self
->ircomm
, NULL
);
695 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
697 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
700 case IRCOMM_TTY_DETACH_CABLE
:
701 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
704 pr_debug("%s(), unknown event: %s\n", __func__
,
705 ircomm_tty_event
[event
]);
712 * Function ircomm_tty_state_search (self, event, skb, info)
714 * Trying to discover an IrCOMM device
717 static int ircomm_tty_state_search(struct ircomm_tty_cb
*self
,
718 IRCOMM_TTY_EVENT event
,
720 struct ircomm_tty_info
*info
)
724 pr_debug("%s: state=%s, event=%s\n", __func__
,
725 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
728 case IRCOMM_TTY_DISCOVERY_INDICATION
:
729 self
->daddr
= info
->daddr
;
730 self
->saddr
= info
->saddr
;
733 net_warn_ratelimited("%s(), busy with a previous query\n",
738 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
739 ircomm_tty_getvalue_confirm
);
741 if (self
->service_type
== IRCOMM_3_WIRE_RAW
) {
742 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
743 self
->daddr
, "IrLPT",
744 "IrDA:IrLMP:LsapSel");
745 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_LSAP_SEL
);
747 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
752 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_PARAMETERS
);
754 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
756 case IRCOMM_TTY_CONNECT_INDICATION
:
757 del_timer(&self
->watchdog_timer
);
758 ircomm_tty_ias_unregister(self
);
760 /* Accept connection */
761 ircomm_connect_response(self
->ircomm
, NULL
);
762 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
764 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
768 /* Try to discover any remote devices */
769 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
770 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
773 case IRCOMM_TTY_DETACH_CABLE
:
774 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
777 pr_debug("%s(), unknown event: %s\n", __func__
,
778 ircomm_tty_event
[event
]);
785 * Function ircomm_tty_state_query (self, event, skb, info)
787 * Querying the remote LM-IAS for IrCOMM parameters
790 static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb
*self
,
791 IRCOMM_TTY_EVENT event
,
793 struct ircomm_tty_info
*info
)
797 pr_debug("%s: state=%s, event=%s\n", __func__
,
798 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
801 case IRCOMM_TTY_GOT_PARAMETERS
:
803 net_warn_ratelimited("%s(), busy with a previous query\n",
808 self
->iriap
= iriap_open(LSAP_ANY
, IAS_CLIENT
, self
,
809 ircomm_tty_getvalue_confirm
);
811 iriap_getvaluebyclass_request(self
->iriap
, self
->saddr
,
812 self
->daddr
, "IrDA:IrCOMM",
813 "IrDA:TinyTP:LsapSel");
815 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
816 ircomm_tty_next_state(self
, IRCOMM_TTY_QUERY_LSAP_SEL
);
818 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
819 /* Go back to search mode */
820 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
821 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
823 case IRCOMM_TTY_CONNECT_INDICATION
:
824 del_timer(&self
->watchdog_timer
);
825 ircomm_tty_ias_unregister(self
);
827 /* Accept connection */
828 ircomm_connect_response(self
->ircomm
, NULL
);
829 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
831 case IRCOMM_TTY_DETACH_CABLE
:
832 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
835 pr_debug("%s(), unknown event: %s\n", __func__
,
836 ircomm_tty_event
[event
]);
843 * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info)
845 * Query remote LM-IAS for the LSAP selector which we can connect to
848 static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb
*self
,
849 IRCOMM_TTY_EVENT event
,
851 struct ircomm_tty_info
*info
)
855 pr_debug("%s: state=%s, event=%s\n", __func__
,
856 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
859 case IRCOMM_TTY_GOT_LSAPSEL
:
860 /* Connect to remote device */
861 ret
= ircomm_connect_request(self
->ircomm
, self
->dlsap_sel
,
862 self
->saddr
, self
->daddr
,
863 NULL
, self
->service_type
);
864 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
865 ircomm_tty_next_state(self
, IRCOMM_TTY_SETUP
);
867 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
868 /* Go back to search mode */
869 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
870 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
872 case IRCOMM_TTY_CONNECT_INDICATION
:
873 del_timer(&self
->watchdog_timer
);
874 ircomm_tty_ias_unregister(self
);
876 /* Accept connection */
877 ircomm_connect_response(self
->ircomm
, NULL
);
878 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
880 case IRCOMM_TTY_DETACH_CABLE
:
881 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
884 pr_debug("%s(), unknown event: %s\n", __func__
,
885 ircomm_tty_event
[event
]);
892 * Function ircomm_tty_state_setup (self, event, skb, info)
897 static int ircomm_tty_state_setup(struct ircomm_tty_cb
*self
,
898 IRCOMM_TTY_EVENT event
,
900 struct ircomm_tty_info
*info
)
904 pr_debug("%s: state=%s, event=%s\n", __func__
,
905 ircomm_tty_state
[self
->state
], ircomm_tty_event
[event
]);
908 case IRCOMM_TTY_CONNECT_CONFIRM
:
909 del_timer(&self
->watchdog_timer
);
910 ircomm_tty_ias_unregister(self
);
913 * Send initial parameters. This will also send out queued
914 * parameters waiting for the connection to come up
916 ircomm_tty_send_initial_parameters(self
);
917 ircomm_tty_link_established(self
);
918 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
920 case IRCOMM_TTY_CONNECT_INDICATION
:
921 del_timer(&self
->watchdog_timer
);
922 ircomm_tty_ias_unregister(self
);
924 /* Accept connection */
925 ircomm_connect_response(self
->ircomm
, NULL
);
926 ircomm_tty_next_state(self
, IRCOMM_TTY_READY
);
928 case IRCOMM_TTY_WD_TIMER_EXPIRED
:
929 /* Go back to search mode */
930 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
931 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
933 case IRCOMM_TTY_DETACH_CABLE
:
934 /* ircomm_disconnect_request(self->ircomm, NULL); */
935 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
938 pr_debug("%s(), unknown event: %s\n", __func__
,
939 ircomm_tty_event
[event
]);
946 * Function ircomm_tty_state_ready (self, event, skb, info)
948 * IrCOMM is now connected
951 static int ircomm_tty_state_ready(struct ircomm_tty_cb
*self
,
952 IRCOMM_TTY_EVENT event
,
954 struct ircomm_tty_info
*info
)
959 case IRCOMM_TTY_DATA_REQUEST
:
960 ret
= ircomm_data_request(self
->ircomm
, skb
);
962 case IRCOMM_TTY_DETACH_CABLE
:
963 ircomm_disconnect_request(self
->ircomm
, NULL
);
964 ircomm_tty_next_state(self
, IRCOMM_TTY_IDLE
);
966 case IRCOMM_TTY_DISCONNECT_INDICATION
:
967 ircomm_tty_ias_register(self
);
968 ircomm_tty_next_state(self
, IRCOMM_TTY_SEARCH
);
969 ircomm_tty_start_watchdog_timer(self
, 3*HZ
);
971 if (self
->port
.flags
& ASYNC_CHECK_CD
) {
973 self
->settings
.dce
= IRCOMM_DELTA_CD
;
974 ircomm_tty_check_modem_status(self
);
976 pr_debug("%s(), hanging up!\n", __func__
);
977 tty_port_tty_hangup(&self
->port
, false);
981 pr_debug("%s(), unknown event: %s\n", __func__
,
982 ircomm_tty_event
[event
]);