Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Filename: ircomm_tty_attach.c |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 4 | * Version: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved. |
| 13 | * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 14 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * the License, or (at your option) any later version. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | d377050 | 2013-12-06 09:13:43 -0800 | [diff] [blame] | 26 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 27 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | ********************************************************************/ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/init.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 31 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 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 | |
| 47 | static void ircomm_tty_ias_register(struct ircomm_tty_cb *self); |
| 48 | static void ircomm_tty_discovery_indication(discinfo_t *discovery, |
| 49 | DISCOVERY_MODE mode, |
| 50 | void *priv); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 51 | static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | struct ias_value *value, void *priv); |
| 53 | static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, |
| 54 | int timeout); |
| 55 | static void ircomm_tty_watchdog_timer_expired(void *data); |
| 56 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 57 | static int ircomm_tty_state_idle(struct ircomm_tty_cb *self, |
| 58 | IRCOMM_TTY_EVENT event, |
| 59 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 61 | static int ircomm_tty_state_search(struct ircomm_tty_cb *self, |
| 62 | IRCOMM_TTY_EVENT event, |
| 63 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 65 | static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self, |
| 66 | IRCOMM_TTY_EVENT event, |
| 67 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 69 | static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self, |
| 70 | IRCOMM_TTY_EVENT event, |
| 71 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 73 | static int ircomm_tty_state_setup(struct ircomm_tty_cb *self, |
| 74 | IRCOMM_TTY_EVENT event, |
| 75 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 77 | static int ircomm_tty_state_ready(struct ircomm_tty_cb *self, |
| 78 | IRCOMM_TTY_EVENT event, |
| 79 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | struct ircomm_tty_info *info); |
| 81 | |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 82 | const char *const ircomm_tty_state[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | "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 Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 93 | static const char *const ircomm_tty_event[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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", |
| 107 | "*** ERROR ****", |
| 108 | }; |
| 109 | #endif /* CONFIG_IRDA_DEBUG */ |
| 110 | |
| 111 | static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 112 | struct sk_buff *skb, struct ircomm_tty_info *info) = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 126 | * when the link has been connected, or if an error condition occurs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * If success, the return value is the resulting service type. |
| 128 | */ |
| 129 | int ircomm_tty_attach_cable(struct ircomm_tty_cb *self) |
| 130 | { |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 131 | struct tty_struct *tty; |
| 132 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 133 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | IRDA_ASSERT(self != NULL, return -1;); |
| 136 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 137 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 138 | /* Check if somebody has already connected to us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (ircomm_is_connected(self->ircomm)) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 140 | IRDA_DEBUG(0, "%s(), already connected!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /* Make sure nobody tries to write before the link is up */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 145 | tty = tty_port_tty_get(&self->port); |
| 146 | if (tty) { |
| 147 | tty->hw_stopped = 1; |
| 148 | tty_kref_put(tty); |
| 149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 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 | */ |
| 164 | void ircomm_tty_detach_cable(struct ircomm_tty_cb *self) |
| 165 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 166 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 184 | if (self->iriap) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | 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 | */ |
| 210 | static void ircomm_tty_ias_register(struct ircomm_tty_cb *self) |
| 211 | { |
| 212 | __u8 oct_seq[6]; |
| 213 | __u16 hints; |
| 214 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 215 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | IRDA_ASSERT(self != NULL, return;); |
| 218 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 241 | irias_add_integer_attrib(self->obj, "IrDA:IrLMP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 246 | irias_add_integer_attrib(self->obj, "IrDA:TinyTP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | self->slsap_sel, IAS_KERNEL_ATTR); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | /* Code the parameters into the buffer */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 250 | irda_param_pack(oct_seq, "bbbbbb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | IRCOMM_SERVICE_TYPE, 1, self->service_type, |
| 252 | IRCOMM_PORT_TYPE, 1, IRCOMM_SERIAL); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* 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 | */ |
| 267 | static 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 | */ |
| 304 | int 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 309 | if (self->service_type & IRCOMM_3_WIRE_RAW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return 0; |
| 311 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 312 | /* |
| 313 | * Set default values, but only if the application for some reason |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * haven't set them already |
| 315 | */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 316 | IRDA_DEBUG(2, "%s(), data-rate = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | self->settings.data_rate); |
| 318 | if (!self->settings.data_rate) |
| 319 | self->settings.data_rate = 9600; |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 320 | IRDA_DEBUG(2, "%s(), data-format = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | self->settings.data_format); |
| 322 | if (!self->settings.data_format) |
| 323 | self->settings.data_format = IRCOMM_WSIZE_8; /* 8N1 */ |
| 324 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 325 | IRDA_DEBUG(2, "%s(), flow-control = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 349 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | /* Notify peer that we are ready to receive data */ |
| 351 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | 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 | */ |
| 363 | static 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 370 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 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 Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 389 | self = priv; |
Ryan Reading | c310f09 | 2007-10-17 19:34:11 -0700 | [diff] [blame] | 390 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCOVERY_INDICATION, |
| 391 | NULL, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb) |
| 396 | * |
| 397 | * Link disconnected |
| 398 | * |
| 399 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 400 | void ircomm_tty_disconnect_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | LM_REASON reason, |
| 402 | struct sk_buff *skb) |
| 403 | { |
| 404 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 405 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 407 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | IRDA_ASSERT(self != NULL, return;); |
| 410 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 411 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 412 | tty = tty_port_tty_get(&self->port); |
| 413 | if (!tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | return; |
| 415 | |
| 416 | /* This will stop control data transfers */ |
| 417 | self->flow = FLOW_STOP; |
| 418 | |
| 419 | /* Stop data transfers */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 420 | tty->hw_stopped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 422 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | NULL); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 424 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 433 | static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id, |
| 434 | struct ias_value *value, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | void *priv) |
| 436 | { |
| 437 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) priv; |
| 438 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 439 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 450 | IRDA_DEBUG(4, "%s(), got NULL value!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | switch (value->type) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 455 | case IAS_OCT_SEQ: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 456 | IRDA_DEBUG(2, "%s(), got octet sequence\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | irda_param_extract_all(self, value->t.oct_seq, value->len, |
| 459 | &ircomm_param_info); |
| 460 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 461 | ircomm_tty_do_event(self, IRCOMM_TTY_GOT_PARAMETERS, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | NULL); |
| 463 | break; |
| 464 | case IAS_INTEGER: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 465 | /* Got LSAP selector */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 466 | IRDA_DEBUG(2, "%s(), got lsapsel = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | value->t.integer); |
| 468 | |
| 469 | if (value->t.integer == -1) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 470 | IRDA_DEBUG(0, "%s(), invalid value!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 477 | IRDA_DEBUG(0, "%s(), got IAS_MISSING\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | break; |
| 479 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 480 | IRDA_DEBUG(0, "%s(), got unknown type!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 492 | void ircomm_tty_connect_confirm(void *instance, void *sap, |
| 493 | struct qos_info *qos, |
| 494 | __u32 max_data_size, |
| 495 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | struct sk_buff *skb) |
| 497 | { |
| 498 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 499 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 500 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 516 | * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | * skb) |
| 518 | * |
| 519 | * we are discovered and being requested to connect by remote device ! |
| 520 | * |
| 521 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 522 | void ircomm_tty_connect_indication(void *instance, void *sap, |
| 523 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | __u32 max_data_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 525 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | struct sk_buff *skb) |
| 527 | { |
| 528 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 529 | int clen; |
| 530 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 531 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 543 | irda_param_extract_all(self, skb->data+1, |
| 544 | IRDA_MIN(skb->len, clen), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | &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 | */ |
| 558 | void ircomm_tty_link_established(struct ircomm_tty_cb *self) |
| 559 | { |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 560 | struct tty_struct *tty; |
| 561 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 562 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | IRDA_ASSERT(self != NULL, return;); |
| 565 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 566 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 567 | tty = tty_port_tty_get(&self->port); |
| 568 | if (!tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | return; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | del_timer(&self->watchdog_timer); |
| 572 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 573 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 577 | * line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | */ |
Huang Shijie | f21ec3d | 2012-08-22 22:13:36 -0400 | [diff] [blame] | 579 | if (tty_port_cts_enabled(&self->port) && |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 580 | ((self->settings.dce & IRCOMM_CTS) == 0)) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 581 | IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__ ); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 582 | goto put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } else { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 584 | IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 586 | tty->hw_stopped = 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* Wake up processes blocked on open */ |
Jiri Slaby | a3cc9fc | 2012-06-04 13:35:16 +0200 | [diff] [blame] | 589 | wake_up_interruptible(&self->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | schedule_work(&self->tqueue); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 593 | put: |
| 594 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Function ircomm_tty_start_watchdog_timer (self, timeout) |
| 599 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | * the timeout |
| 603 | */ |
| 604 | static 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 | */ |
| 620 | static void ircomm_tty_watchdog_timer_expired(void *data) |
| 621 | { |
| 622 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 623 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 624 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 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 | */ |
| 639 | int ircomm_tty_do_event(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 640 | struct sk_buff *skb, struct ircomm_tty_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
| 642 | IRDA_ASSERT(self != NULL, return -1;); |
| 643 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 644 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 645 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | 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 | */ |
| 657 | static 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 663 | IRDA_DEBUG(2, "%s: next state=%s, service type=%d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 675 | static int ircomm_tty_state_idle(struct ircomm_tty_cb *self, |
| 676 | IRCOMM_TTY_EVENT event, |
| 677 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | struct ircomm_tty_info *info) |
| 679 | { |
| 680 | int ret = 0; |
| 681 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 682 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 684 | switch (event) { |
| 685 | case IRCOMM_TTY_ATTACH_CABLE: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 686 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 688 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | 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) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame^] | 697 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 698 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 726 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 739 | static int ircomm_tty_state_search(struct ircomm_tty_cb *self, |
| 740 | IRCOMM_TTY_EVENT event, |
| 741 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | struct ircomm_tty_info *info) |
| 743 | { |
| 744 | int ret = 0; |
| 745 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 746 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | 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) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame^] | 755 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 756 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | return -EBUSY; |
| 758 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 761 | ircomm_tty_getvalue_confirm); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | if (self->service_type == IRCOMM_3_WIRE_RAW) { |
| 764 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 765 | self->daddr, "IrLPT", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | "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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 770 | self->daddr, |
| 771 | "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | "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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 790 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 799 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 812 | static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self, |
| 813 | IRCOMM_TTY_EVENT event, |
| 814 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | struct ircomm_tty_info *info) |
| 816 | { |
| 817 | int ret = 0; |
| 818 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 819 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 821 | |
| 822 | switch (event) { |
| 823 | case IRCOMM_TTY_GOT_PARAMETERS: |
| 824 | if (self->iriap) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame^] | 825 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 826 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return -EBUSY; |
| 828 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 831 | ircomm_tty_getvalue_confirm); |
| 832 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 833 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
| 834 | self->daddr, "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | "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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 843 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 857 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 870 | static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self, |
| 871 | IRCOMM_TTY_EVENT event, |
| 872 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | struct ircomm_tty_info *info) |
| 874 | { |
| 875 | int ret = 0; |
| 876 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 877 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 884 | self->saddr, self->daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 906 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 919 | static int ircomm_tty_state_setup(struct ircomm_tty_cb *self, |
| 920 | IRCOMM_TTY_EVENT event, |
| 921 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct ircomm_tty_info *info) |
| 923 | { |
| 924 | int ret = 0; |
| 925 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 926 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 933 | |
| 934 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | * Send initial parameters. This will also send out queued |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 936 | * parameters waiting for the connection to come up |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | */ |
| 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | /* 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 Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 960 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 973 | static int ircomm_tty_state_ready(struct ircomm_tty_cb *self, |
| 974 | IRCOMM_TTY_EVENT event, |
| 975 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | 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 Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 983 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | 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 Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 993 | if (self->port.flags & ASYNC_CHECK_CD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | /* Drop carrier */ |
| 995 | self->settings.dce = IRCOMM_DELTA_CD; |
| 996 | ircomm_tty_check_modem_status(self); |
| 997 | } else { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 998 | IRDA_DEBUG(0, "%s(), hanging up!\n", __func__ ); |
Jiri Slaby | aa27a09 | 2013-03-07 13:12:30 +0100 | [diff] [blame] | 999 | tty_port_tty_hangup(&self->port, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | break; |
| 1002 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1003 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | ircomm_tty_event[event]); |
| 1005 | ret = -EINVAL; |
| 1006 | } |
| 1007 | return ret; |
| 1008 | } |
| 1009 | |