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 | |
Joe Perches | a768851 | 2014-11-12 18:15:47 -0800 | [diff] [blame^] | 92 | static const char *const ircomm_tty_event[] __maybe_unused = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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", |
| 106 | "*** ERROR ****", |
| 107 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 110 | struct sk_buff *skb, struct ircomm_tty_info *info) = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
| 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, |
| 118 | }; |
| 119 | |
| 120 | /* |
| 121 | * Function ircomm_tty_attach_cable (driver) |
| 122 | * |
| 123 | * Try to attach cable (IrCOMM link). This function will only return |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 124 | * when the link has been connected, or if an error condition occurs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * If success, the return value is the resulting service type. |
| 126 | */ |
| 127 | int ircomm_tty_attach_cable(struct ircomm_tty_cb *self) |
| 128 | { |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 129 | struct tty_struct *tty; |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | IRDA_ASSERT(self != NULL, return -1;); |
| 132 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 133 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 134 | /* Check if somebody has already connected to us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | if (ircomm_is_connected(self->ircomm)) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 136 | pr_debug("%s(), already connected!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /* Make sure nobody tries to write before the link is up */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 141 | tty = tty_port_tty_get(&self->port); |
| 142 | if (tty) { |
| 143 | tty->hw_stopped = 1; |
| 144 | tty_kref_put(tty); |
| 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | ircomm_tty_ias_register(self); |
| 148 | |
| 149 | ircomm_tty_do_event(self, IRCOMM_TTY_ATTACH_CABLE, NULL, NULL); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Function ircomm_detach_cable (driver) |
| 156 | * |
| 157 | * Detach cable, or cable has been detached by peer |
| 158 | * |
| 159 | */ |
| 160 | void ircomm_tty_detach_cable(struct ircomm_tty_cb *self) |
| 161 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | IRDA_ASSERT(self != NULL, return;); |
| 163 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 164 | |
| 165 | del_timer(&self->watchdog_timer); |
| 166 | |
| 167 | /* Remove discovery handler */ |
| 168 | if (self->ckey) { |
| 169 | irlmp_unregister_client(self->ckey); |
| 170 | self->ckey = NULL; |
| 171 | } |
| 172 | /* Remove IrCOMM hint bits */ |
| 173 | if (self->skey) { |
| 174 | irlmp_unregister_service(self->skey); |
| 175 | self->skey = NULL; |
| 176 | } |
| 177 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 178 | if (self->iriap) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | iriap_close(self->iriap); |
| 180 | self->iriap = NULL; |
| 181 | } |
| 182 | |
| 183 | /* Remove LM-IAS object */ |
| 184 | if (self->obj) { |
| 185 | irias_delete_object(self->obj); |
| 186 | self->obj = NULL; |
| 187 | } |
| 188 | |
| 189 | ircomm_tty_do_event(self, IRCOMM_TTY_DETACH_CABLE, NULL, NULL); |
| 190 | |
| 191 | /* Reset some values */ |
| 192 | self->daddr = self->saddr = 0; |
| 193 | self->dlsap_sel = self->slsap_sel = 0; |
| 194 | |
| 195 | memset(&self->settings, 0, sizeof(struct ircomm_params)); |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Function ircomm_tty_ias_register (self) |
| 200 | * |
| 201 | * Register with LM-IAS depending on which service type we are |
| 202 | * |
| 203 | */ |
| 204 | static void ircomm_tty_ias_register(struct ircomm_tty_cb *self) |
| 205 | { |
| 206 | __u8 oct_seq[6]; |
| 207 | __u16 hints; |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | IRDA_ASSERT(self != NULL, return;); |
| 210 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 216 | |
| 217 | /* Advertise IrCOMM hint bit in discovery */ |
| 218 | if (!self->skey) |
| 219 | self->skey = irlmp_register_service(hints); |
| 220 | /* Set up a discovery handler */ |
| 221 | if (!self->ckey) |
| 222 | self->ckey = irlmp_register_client(hints, |
| 223 | ircomm_tty_discovery_indication, |
| 224 | NULL, (void *) self); |
| 225 | |
| 226 | /* If already done, no need to do it again */ |
| 227 | if (self->obj) |
| 228 | return; |
| 229 | |
| 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); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 233 | irias_add_integer_attrib(self->obj, "IrDA:IrLMP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | self->slsap_sel, IAS_KERNEL_ATTR); |
| 235 | } else { |
| 236 | /* Register IrCOMM with LM-IAS */ |
| 237 | self->obj = irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 238 | irias_add_integer_attrib(self->obj, "IrDA:TinyTP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | self->slsap_sel, IAS_KERNEL_ATTR); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* Code the parameters into the buffer */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 242 | irda_param_pack(oct_seq, "bbbbbb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | IRCOMM_SERVICE_TYPE, 1, self->service_type, |
| 244 | IRCOMM_PORT_TYPE, 1, IRCOMM_SERIAL); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | /* Register parameters with LM-IAS */ |
| 247 | irias_add_octseq_attrib(self->obj, "Parameters", oct_seq, 6, |
| 248 | IAS_KERNEL_ATTR); |
| 249 | } |
| 250 | irias_insert_object(self->obj); |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * Function ircomm_tty_ias_unregister (self) |
| 255 | * |
| 256 | * Remove our IAS object and client hook while connected. |
| 257 | * |
| 258 | */ |
| 259 | static void ircomm_tty_ias_unregister(struct ircomm_tty_cb *self) |
| 260 | { |
| 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. |
| 272 | * Jean II */ |
| 273 | if (self->obj) { |
| 274 | irias_delete_object(self->obj); |
| 275 | self->obj = NULL; |
| 276 | } |
| 277 | |
| 278 | #if 0 |
| 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 */ |
| 283 | if (self->ckey) { |
| 284 | irlmp_unregister_client(self->ckey); |
| 285 | self->ckey = NULL; |
| 286 | } |
| 287 | #endif |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Function ircomm_send_initial_parameters (self) |
| 292 | * |
| 293 | * Send initial parameters to the remote IrCOMM device. These parameters |
| 294 | * must be sent before any data. |
| 295 | */ |
| 296 | int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb *self) |
| 297 | { |
| 298 | IRDA_ASSERT(self != NULL, return -1;); |
| 299 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 300 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 301 | if (self->service_type & IRCOMM_3_WIRE_RAW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return 0; |
| 303 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 304 | /* |
| 305 | * Set default values, but only if the application for some reason |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | * haven't set them already |
| 307 | */ |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 308 | pr_debug("%s(), data-rate = %d\n", __func__ , |
| 309 | self->settings.data_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (!self->settings.data_rate) |
| 311 | self->settings.data_rate = 9600; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 312 | pr_debug("%s(), data-format = %d\n", __func__ , |
| 313 | self->settings.data_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (!self->settings.data_format) |
| 315 | self->settings.data_format = IRCOMM_WSIZE_8; /* 8N1 */ |
| 316 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 317 | pr_debug("%s(), flow-control = %d\n", __func__ , |
| 318 | self->settings.flow_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/ |
| 320 | |
| 321 | /* Do not set delta values for the initial parameters */ |
| 322 | self->settings.dte = IRCOMM_DTR | IRCOMM_RTS; |
| 323 | |
| 324 | /* Only send service type parameter when we are the client */ |
| 325 | if (self->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); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /* Only 9-wire service types continue here */ |
| 337 | ircomm_param_request(self, IRCOMM_FLOW_CONTROL, FALSE); |
| 338 | #if 0 |
| 339 | ircomm_param_request(self, IRCOMM_XON_XOFF, FALSE); |
| 340 | ircomm_param_request(self, IRCOMM_ENQ_ACK, FALSE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 341 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /* Notify peer that we are ready to receive data */ |
| 343 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | * Function ircomm_tty_discovery_indication (discovery) |
| 350 | * |
| 351 | * Remote device is discovered, try query the remote IAS to see which |
| 352 | * device it is, and which services it has. |
| 353 | * |
| 354 | */ |
| 355 | static void ircomm_tty_discovery_indication(discinfo_t *discovery, |
| 356 | DISCOVERY_MODE mode, |
| 357 | void *priv) |
| 358 | { |
| 359 | struct ircomm_tty_cb *self; |
| 360 | struct ircomm_tty_info info; |
| 361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* Important note : |
| 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. |
| 372 | * Jean II */ |
| 373 | if(mode == DISCOVERY_PASSIVE) |
| 374 | return; |
| 375 | |
| 376 | info.daddr = discovery->daddr; |
| 377 | info.saddr = discovery->saddr; |
| 378 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 379 | self = priv; |
Ryan Reading | c310f09 | 2007-10-17 19:34:11 -0700 | [diff] [blame] | 380 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCOVERY_INDICATION, |
| 381 | NULL, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb) |
| 386 | * |
| 387 | * Link disconnected |
| 388 | * |
| 389 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 390 | void ircomm_tty_disconnect_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | LM_REASON reason, |
| 392 | struct sk_buff *skb) |
| 393 | { |
| 394 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 395 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | IRDA_ASSERT(self != NULL, return;); |
| 398 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 399 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 400 | tty = tty_port_tty_get(&self->port); |
| 401 | if (!tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return; |
| 403 | |
| 404 | /* This will stop control data transfers */ |
| 405 | self->flow = FLOW_STOP; |
| 406 | |
| 407 | /* Stop data transfers */ |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 408 | tty->hw_stopped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 410 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | NULL); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 412 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /* |
| 416 | * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv) |
| 417 | * |
| 418 | * Got result from the IAS query we make |
| 419 | * |
| 420 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 421 | static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id, |
| 422 | struct ias_value *value, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | void *priv) |
| 424 | { |
| 425 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) priv; |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | IRDA_ASSERT(self != NULL, return;); |
| 428 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 429 | |
| 430 | /* We probably don't need to make any more queries */ |
| 431 | iriap_close(self->iriap); |
| 432 | self->iriap = NULL; |
| 433 | |
| 434 | /* Check if request succeeded */ |
| 435 | if (result != IAS_SUCCESS) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 436 | pr_debug("%s(), got NULL value!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | |
| 440 | switch (value->type) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 441 | case IAS_OCT_SEQ: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 442 | pr_debug("%s(), got octet sequence\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | irda_param_extract_all(self, value->t.oct_seq, value->len, |
| 445 | &ircomm_param_info); |
| 446 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 447 | ircomm_tty_do_event(self, IRCOMM_TTY_GOT_PARAMETERS, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | NULL); |
| 449 | break; |
| 450 | case IAS_INTEGER: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 451 | /* Got LSAP selector */ |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 452 | pr_debug("%s(), got lsapsel = %d\n", __func__ , |
| 453 | value->t.integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | if (value->t.integer == -1) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 456 | pr_debug("%s(), invalid value!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } else |
| 458 | self->dlsap_sel = value->t.integer; |
| 459 | |
| 460 | ircomm_tty_do_event(self, IRCOMM_TTY_GOT_LSAPSEL, NULL, NULL); |
| 461 | break; |
| 462 | case IAS_MISSING: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 463 | pr_debug("%s(), got IAS_MISSING\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | break; |
| 465 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 466 | pr_debug("%s(), got unknown type!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | irias_delete_value(value); |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb) |
| 474 | * |
| 475 | * Connection confirmed |
| 476 | * |
| 477 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 478 | void ircomm_tty_connect_confirm(void *instance, void *sap, |
| 479 | struct qos_info *qos, |
| 480 | __u32 max_data_size, |
| 481 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | struct sk_buff *skb) |
| 483 | { |
| 484 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | IRDA_ASSERT(self != NULL, return;); |
| 487 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 488 | |
| 489 | self->client = TRUE; |
| 490 | self->max_data_size = max_data_size; |
| 491 | self->max_header_size = max_header_size; |
| 492 | self->flow = FLOW_START; |
| 493 | |
| 494 | ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_CONFIRM, NULL, NULL); |
| 495 | |
| 496 | /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */ |
| 497 | } |
| 498 | |
| 499 | /* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 500 | * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | * skb) |
| 502 | * |
| 503 | * we are discovered and being requested to connect by remote device ! |
| 504 | * |
| 505 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 506 | void ircomm_tty_connect_indication(void *instance, void *sap, |
| 507 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | __u32 max_data_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 509 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | struct sk_buff *skb) |
| 511 | { |
| 512 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 513 | int clen; |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | IRDA_ASSERT(self != NULL, return;); |
| 516 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 517 | |
| 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; |
| 522 | |
| 523 | clen = skb->data[0]; |
| 524 | if (clen) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 525 | irda_param_extract_all(self, skb->data+1, |
| 526 | IRDA_MIN(skb->len, clen), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | &ircomm_param_info); |
| 528 | |
| 529 | ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_INDICATION, NULL, NULL); |
| 530 | |
| 531 | /* No need to kfree_skb - see ircomm_ttp_connect_indication() */ |
| 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Function ircomm_tty_link_established (self) |
| 536 | * |
| 537 | * Called when the IrCOMM link is established |
| 538 | * |
| 539 | */ |
| 540 | void ircomm_tty_link_established(struct ircomm_tty_cb *self) |
| 541 | { |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 542 | struct tty_struct *tty; |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | IRDA_ASSERT(self != NULL, return;); |
| 545 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 546 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 547 | tty = tty_port_tty_get(&self->port); |
| 548 | if (!tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | return; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | del_timer(&self->watchdog_timer); |
| 552 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 553 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 557 | * line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | */ |
Huang Shijie | f21ec3d | 2012-08-22 22:13:36 -0400 | [diff] [blame] | 559 | if (tty_port_cts_enabled(&self->port) && |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 560 | ((self->settings.dce & IRCOMM_CTS) == 0)) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 561 | pr_debug("%s(), waiting for CTS ...\n", __func__); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 562 | goto put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } else { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 564 | pr_debug("%s(), starting hardware!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 566 | tty->hw_stopped = 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* Wake up processes blocked on open */ |
Jiri Slaby | a3cc9fc | 2012-06-04 13:35:16 +0200 | [diff] [blame] | 569 | wake_up_interruptible(&self->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | schedule_work(&self->tqueue); |
Jiri Slaby | 62f228a | 2012-06-04 13:35:21 +0200 | [diff] [blame] | 573 | put: |
| 574 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* |
| 578 | * Function ircomm_tty_start_watchdog_timer (self, timeout) |
| 579 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | * the timeout |
| 583 | */ |
| 584 | static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, |
| 585 | int timeout) |
| 586 | { |
| 587 | IRDA_ASSERT(self != NULL, return;); |
| 588 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 589 | |
| 590 | irda_start_timer(&self->watchdog_timer, timeout, (void *) self, |
| 591 | ircomm_tty_watchdog_timer_expired); |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Function ircomm_tty_watchdog_timer_expired (data) |
| 596 | * |
| 597 | * Called when the connect procedure have taken to much time. |
| 598 | * |
| 599 | */ |
| 600 | static void ircomm_tty_watchdog_timer_expired(void *data) |
| 601 | { |
| 602 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | IRDA_ASSERT(self != NULL, return;); |
| 605 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 606 | |
| 607 | ircomm_tty_do_event(self, IRCOMM_TTY_WD_TIMER_EXPIRED, NULL, NULL); |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /* |
| 612 | * Function ircomm_tty_do_event (self, event, skb) |
| 613 | * |
| 614 | * Process event |
| 615 | * |
| 616 | */ |
| 617 | 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] | 618 | struct sk_buff *skb, struct ircomm_tty_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | IRDA_ASSERT(self != NULL, return -1;); |
| 621 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 622 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 623 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 624 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return (*state[self->state])(self, event, skb, info); |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Function ircomm_tty_next_state (self, state) |
| 631 | * |
| 632 | * Switch state |
| 633 | * |
| 634 | */ |
| 635 | static inline void ircomm_tty_next_state(struct ircomm_tty_cb *self, IRCOMM_TTY_STATE state) |
| 636 | { |
| 637 | /* |
| 638 | IRDA_ASSERT(self != NULL, return;); |
| 639 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 640 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 641 | pr_debug("%s: next state=%s, service type=%d\n", __func__ , |
| 642 | ircomm_tty_state[self->state], self->service_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | */ |
| 644 | self->state = state; |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * Function ircomm_tty_state_idle (self, event, skb, info) |
| 649 | * |
| 650 | * Just hanging around |
| 651 | * |
| 652 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 653 | static int ircomm_tty_state_idle(struct ircomm_tty_cb *self, |
| 654 | IRCOMM_TTY_EVENT event, |
| 655 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct ircomm_tty_info *info) |
| 657 | { |
| 658 | int ret = 0; |
| 659 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 660 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 661 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | switch (event) { |
| 663 | case IRCOMM_TTY_ATTACH_CABLE: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 664 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 666 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS); |
| 669 | break; |
| 670 | case IRCOMM_TTY_DISCOVERY_INDICATION: |
| 671 | self->daddr = info->daddr; |
| 672 | self->saddr = info->saddr; |
| 673 | |
| 674 | if (self->iriap) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 675 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 676 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return -EBUSY; |
| 678 | } |
| 679 | |
| 680 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 681 | ircomm_tty_getvalue_confirm); |
| 682 | |
| 683 | iriap_getvaluebyclass_request(self->iriap, |
| 684 | self->saddr, self->daddr, |
| 685 | "IrDA:IrCOMM", "Parameters"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 686 | |
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_QUERY_PARAMETERS); |
| 689 | break; |
| 690 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 691 | del_timer(&self->watchdog_timer); |
| 692 | |
| 693 | /* Accept connection */ |
| 694 | ircomm_connect_response(self->ircomm, NULL); |
| 695 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 696 | break; |
| 697 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 698 | /* Just stay idle */ |
| 699 | break; |
| 700 | case IRCOMM_TTY_DETACH_CABLE: |
| 701 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 702 | break; |
| 703 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 704 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 705 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | ret = -EINVAL; |
| 707 | } |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | /* |
| 712 | * Function ircomm_tty_state_search (self, event, skb, info) |
| 713 | * |
| 714 | * Trying to discover an IrCOMM device |
| 715 | * |
| 716 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 717 | static int ircomm_tty_state_search(struct ircomm_tty_cb *self, |
| 718 | IRCOMM_TTY_EVENT event, |
| 719 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | struct ircomm_tty_info *info) |
| 721 | { |
| 722 | int ret = 0; |
| 723 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 724 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 725 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
| 727 | switch (event) { |
| 728 | case IRCOMM_TTY_DISCOVERY_INDICATION: |
| 729 | self->daddr = info->daddr; |
| 730 | self->saddr = info->saddr; |
| 731 | |
| 732 | if (self->iriap) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 733 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 734 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return -EBUSY; |
| 736 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 739 | ircomm_tty_getvalue_confirm); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | if (self->service_type == IRCOMM_3_WIRE_RAW) { |
| 742 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 743 | self->daddr, "IrLPT", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | "IrDA:IrLMP:LsapSel"); |
| 745 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL); |
| 746 | } else { |
| 747 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 748 | self->daddr, |
| 749 | "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | "Parameters"); |
| 751 | |
| 752 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS); |
| 753 | } |
| 754 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 755 | break; |
| 756 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 757 | del_timer(&self->watchdog_timer); |
| 758 | ircomm_tty_ias_unregister(self); |
| 759 | |
| 760 | /* Accept connection */ |
| 761 | ircomm_connect_response(self->ircomm, NULL); |
| 762 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 763 | break; |
| 764 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 765 | #if 1 |
| 766 | /* Give up */ |
| 767 | #else |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 768 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 770 | irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS); |
| 771 | #endif |
| 772 | break; |
| 773 | case IRCOMM_TTY_DETACH_CABLE: |
| 774 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 775 | break; |
| 776 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 777 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 778 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | ret = -EINVAL; |
| 780 | } |
| 781 | return ret; |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * Function ircomm_tty_state_query (self, event, skb, info) |
| 786 | * |
| 787 | * Querying the remote LM-IAS for IrCOMM parameters |
| 788 | * |
| 789 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 790 | static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self, |
| 791 | IRCOMM_TTY_EVENT event, |
| 792 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | struct ircomm_tty_info *info) |
| 794 | { |
| 795 | int ret = 0; |
| 796 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 797 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 798 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
| 800 | switch (event) { |
| 801 | case IRCOMM_TTY_GOT_PARAMETERS: |
| 802 | if (self->iriap) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 803 | net_warn_ratelimited("%s(), busy with a previous query\n", |
| 804 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | return -EBUSY; |
| 806 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 809 | ircomm_tty_getvalue_confirm); |
| 810 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 811 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
| 812 | self->daddr, "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | "IrDA:TinyTP:LsapSel"); |
| 814 | |
| 815 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 816 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL); |
| 817 | break; |
| 818 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 819 | /* Go back to search mode */ |
| 820 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 821 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | break; |
| 823 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 824 | del_timer(&self->watchdog_timer); |
| 825 | ircomm_tty_ias_unregister(self); |
| 826 | |
| 827 | /* Accept connection */ |
| 828 | ircomm_connect_response(self->ircomm, NULL); |
| 829 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 830 | break; |
| 831 | case IRCOMM_TTY_DETACH_CABLE: |
| 832 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 833 | break; |
| 834 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 835 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 836 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | ret = -EINVAL; |
| 838 | } |
| 839 | return ret; |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info) |
| 844 | * |
| 845 | * Query remote LM-IAS for the LSAP selector which we can connect to |
| 846 | * |
| 847 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 848 | static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self, |
| 849 | IRCOMM_TTY_EVENT event, |
| 850 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | struct ircomm_tty_info *info) |
| 852 | { |
| 853 | int ret = 0; |
| 854 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 855 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 856 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
| 858 | switch (event) { |
| 859 | case IRCOMM_TTY_GOT_LSAPSEL: |
| 860 | /* Connect to remote device */ |
| 861 | ret = ircomm_connect_request(self->ircomm, self->dlsap_sel, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 862 | self->saddr, self->daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | NULL, self->service_type); |
| 864 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 865 | ircomm_tty_next_state(self, IRCOMM_TTY_SETUP); |
| 866 | break; |
| 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); |
| 871 | break; |
| 872 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 873 | del_timer(&self->watchdog_timer); |
| 874 | ircomm_tty_ias_unregister(self); |
| 875 | |
| 876 | /* Accept connection */ |
| 877 | ircomm_connect_response(self->ircomm, NULL); |
| 878 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 879 | break; |
| 880 | case IRCOMM_TTY_DETACH_CABLE: |
| 881 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 882 | break; |
| 883 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 884 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 885 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | ret = -EINVAL; |
| 887 | } |
| 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | * Function ircomm_tty_state_setup (self, event, skb, info) |
| 893 | * |
| 894 | * Trying to connect |
| 895 | * |
| 896 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 897 | static int ircomm_tty_state_setup(struct ircomm_tty_cb *self, |
| 898 | IRCOMM_TTY_EVENT event, |
| 899 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | struct ircomm_tty_info *info) |
| 901 | { |
| 902 | int ret = 0; |
| 903 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 904 | pr_debug("%s: state=%s, event=%s\n", __func__ , |
| 905 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | switch (event) { |
| 908 | case IRCOMM_TTY_CONNECT_CONFIRM: |
| 909 | del_timer(&self->watchdog_timer); |
| 910 | ircomm_tty_ias_unregister(self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 911 | |
| 912 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | * Send initial parameters. This will also send out queued |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 914 | * parameters waiting for the connection to come up |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | */ |
| 916 | ircomm_tty_send_initial_parameters(self); |
| 917 | ircomm_tty_link_established(self); |
| 918 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 919 | break; |
| 920 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 921 | del_timer(&self->watchdog_timer); |
| 922 | ircomm_tty_ias_unregister(self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | /* Accept connection */ |
| 925 | ircomm_connect_response(self->ircomm, NULL); |
| 926 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 927 | break; |
| 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); |
| 932 | break; |
| 933 | case IRCOMM_TTY_DETACH_CABLE: |
| 934 | /* ircomm_disconnect_request(self->ircomm, NULL); */ |
| 935 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 936 | break; |
| 937 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 938 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 939 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | ret = -EINVAL; |
| 941 | } |
| 942 | return ret; |
| 943 | } |
| 944 | |
| 945 | /* |
| 946 | * Function ircomm_tty_state_ready (self, event, skb, info) |
| 947 | * |
| 948 | * IrCOMM is now connected |
| 949 | * |
| 950 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 951 | static int ircomm_tty_state_ready(struct ircomm_tty_cb *self, |
| 952 | IRCOMM_TTY_EVENT event, |
| 953 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | struct ircomm_tty_info *info) |
| 955 | { |
| 956 | int ret = 0; |
| 957 | |
| 958 | switch (event) { |
| 959 | case IRCOMM_TTY_DATA_REQUEST: |
| 960 | ret = ircomm_data_request(self->ircomm, skb); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 961 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | case IRCOMM_TTY_DETACH_CABLE: |
| 963 | ircomm_disconnect_request(self->ircomm, NULL); |
| 964 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 965 | break; |
| 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); |
| 970 | |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame] | 971 | if (self->port.flags & ASYNC_CHECK_CD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | /* Drop carrier */ |
| 973 | self->settings.dce = IRCOMM_DELTA_CD; |
| 974 | ircomm_tty_check_modem_status(self); |
| 975 | } else { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 976 | pr_debug("%s(), hanging up!\n", __func__); |
Jiri Slaby | aa27a09 | 2013-03-07 13:12:30 +0100 | [diff] [blame] | 977 | tty_port_tty_hangup(&self->port, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | break; |
| 980 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 981 | pr_debug("%s(), unknown event: %s\n", __func__ , |
| 982 | ircomm_tty_event[event]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | ret = -EINVAL; |
| 984 | } |
| 985 | return ret; |
| 986 | } |
| 987 | |