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 |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * MA 02111-1307 USA |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 29 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | ********************************************************************/ |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 33 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include <net/irda/irda.h> |
| 36 | #include <net/irda/irlmp.h> |
| 37 | #include <net/irda/iriap.h> |
| 38 | #include <net/irda/irttp.h> |
| 39 | #include <net/irda/irias_object.h> |
| 40 | #include <net/irda/parameters.h> |
| 41 | |
| 42 | #include <net/irda/ircomm_core.h> |
| 43 | #include <net/irda/ircomm_param.h> |
| 44 | #include <net/irda/ircomm_event.h> |
| 45 | |
| 46 | #include <net/irda/ircomm_tty.h> |
| 47 | #include <net/irda/ircomm_tty_attach.h> |
| 48 | |
| 49 | static void ircomm_tty_ias_register(struct ircomm_tty_cb *self); |
| 50 | static void ircomm_tty_discovery_indication(discinfo_t *discovery, |
| 51 | DISCOVERY_MODE mode, |
| 52 | void *priv); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 53 | static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | struct ias_value *value, void *priv); |
| 55 | static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, |
| 56 | int timeout); |
| 57 | static void ircomm_tty_watchdog_timer_expired(void *data); |
| 58 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 59 | static int ircomm_tty_state_idle(struct ircomm_tty_cb *self, |
| 60 | IRCOMM_TTY_EVENT event, |
| 61 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 63 | static int ircomm_tty_state_search(struct ircomm_tty_cb *self, |
| 64 | IRCOMM_TTY_EVENT event, |
| 65 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 67 | static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self, |
| 68 | IRCOMM_TTY_EVENT event, |
| 69 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 71 | static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self, |
| 72 | IRCOMM_TTY_EVENT event, |
| 73 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 75 | static int ircomm_tty_state_setup(struct ircomm_tty_cb *self, |
| 76 | IRCOMM_TTY_EVENT event, |
| 77 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | struct ircomm_tty_info *info); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 79 | static int ircomm_tty_state_ready(struct ircomm_tty_cb *self, |
| 80 | IRCOMM_TTY_EVENT event, |
| 81 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | struct ircomm_tty_info *info); |
| 83 | |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 84 | const char *const ircomm_tty_state[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | "IRCOMM_TTY_IDLE", |
| 86 | "IRCOMM_TTY_SEARCH", |
| 87 | "IRCOMM_TTY_QUERY_PARAMETERS", |
| 88 | "IRCOMM_TTY_QUERY_LSAP_SEL", |
| 89 | "IRCOMM_TTY_SETUP", |
| 90 | "IRCOMM_TTY_READY", |
| 91 | "*** ERROR *** ", |
| 92 | }; |
| 93 | |
| 94 | #ifdef CONFIG_IRDA_DEBUG |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 95 | static const char *const ircomm_tty_event[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | "IRCOMM_TTY_ATTACH_CABLE", |
| 97 | "IRCOMM_TTY_DETACH_CABLE", |
| 98 | "IRCOMM_TTY_DATA_REQUEST", |
| 99 | "IRCOMM_TTY_DATA_INDICATION", |
| 100 | "IRCOMM_TTY_DISCOVERY_REQUEST", |
| 101 | "IRCOMM_TTY_DISCOVERY_INDICATION", |
| 102 | "IRCOMM_TTY_CONNECT_CONFIRM", |
| 103 | "IRCOMM_TTY_CONNECT_INDICATION", |
| 104 | "IRCOMM_TTY_DISCONNECT_REQUEST", |
| 105 | "IRCOMM_TTY_DISCONNECT_INDICATION", |
| 106 | "IRCOMM_TTY_WD_TIMER_EXPIRED", |
| 107 | "IRCOMM_TTY_GOT_PARAMETERS", |
| 108 | "IRCOMM_TTY_GOT_LSAPSEL", |
| 109 | "*** ERROR ****", |
| 110 | }; |
| 111 | #endif /* CONFIG_IRDA_DEBUG */ |
| 112 | |
| 113 | static int (*state[])(struct ircomm_tty_cb *self, IRCOMM_TTY_EVENT event, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 114 | struct sk_buff *skb, struct ircomm_tty_info *info) = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | ircomm_tty_state_idle, |
| 117 | ircomm_tty_state_search, |
| 118 | ircomm_tty_state_query_parameters, |
| 119 | ircomm_tty_state_query_lsap_sel, |
| 120 | ircomm_tty_state_setup, |
| 121 | ircomm_tty_state_ready, |
| 122 | }; |
| 123 | |
| 124 | /* |
| 125 | * Function ircomm_tty_attach_cable (driver) |
| 126 | * |
| 127 | * Try to attach cable (IrCOMM link). This function will only return |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 128 | * when the link has been connected, or if an error condition occurs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * If success, the return value is the resulting service type. |
| 130 | */ |
| 131 | int ircomm_tty_attach_cable(struct ircomm_tty_cb *self) |
| 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 */ |
| 145 | self->tty->hw_stopped = 1; |
| 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 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 162 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | IRDA_ASSERT(self != NULL, return;); |
| 165 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 166 | |
| 167 | del_timer(&self->watchdog_timer); |
| 168 | |
| 169 | /* Remove discovery handler */ |
| 170 | if (self->ckey) { |
| 171 | irlmp_unregister_client(self->ckey); |
| 172 | self->ckey = NULL; |
| 173 | } |
| 174 | /* Remove IrCOMM hint bits */ |
| 175 | if (self->skey) { |
| 176 | irlmp_unregister_service(self->skey); |
| 177 | self->skey = NULL; |
| 178 | } |
| 179 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 180 | if (self->iriap) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | iriap_close(self->iriap); |
| 182 | self->iriap = NULL; |
| 183 | } |
| 184 | |
| 185 | /* Remove LM-IAS object */ |
| 186 | if (self->obj) { |
| 187 | irias_delete_object(self->obj); |
| 188 | self->obj = NULL; |
| 189 | } |
| 190 | |
| 191 | ircomm_tty_do_event(self, IRCOMM_TTY_DETACH_CABLE, NULL, NULL); |
| 192 | |
| 193 | /* Reset some values */ |
| 194 | self->daddr = self->saddr = 0; |
| 195 | self->dlsap_sel = self->slsap_sel = 0; |
| 196 | |
| 197 | memset(&self->settings, 0, sizeof(struct ircomm_params)); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Function ircomm_tty_ias_register (self) |
| 202 | * |
| 203 | * Register with LM-IAS depending on which service type we are |
| 204 | * |
| 205 | */ |
| 206 | static void ircomm_tty_ias_register(struct ircomm_tty_cb *self) |
| 207 | { |
| 208 | __u8 oct_seq[6]; |
| 209 | __u16 hints; |
| 210 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 211 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | IRDA_ASSERT(self != NULL, return;); |
| 214 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* Compute hint bits based on service */ |
| 217 | hints = irlmp_service_to_hint(S_COMM); |
| 218 | if (self->service_type & IRCOMM_3_WIRE_RAW) |
| 219 | hints |= irlmp_service_to_hint(S_PRINTER); |
| 220 | |
| 221 | /* Advertise IrCOMM hint bit in discovery */ |
| 222 | if (!self->skey) |
| 223 | self->skey = irlmp_register_service(hints); |
| 224 | /* Set up a discovery handler */ |
| 225 | if (!self->ckey) |
| 226 | self->ckey = irlmp_register_client(hints, |
| 227 | ircomm_tty_discovery_indication, |
| 228 | NULL, (void *) self); |
| 229 | |
| 230 | /* If already done, no need to do it again */ |
| 231 | if (self->obj) |
| 232 | return; |
| 233 | |
| 234 | if (self->service_type & IRCOMM_3_WIRE_RAW) { |
| 235 | /* Register IrLPT with LM-IAS */ |
| 236 | self->obj = irias_new_object("IrLPT", IAS_IRLPT_ID); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 237 | irias_add_integer_attrib(self->obj, "IrDA:IrLMP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | self->slsap_sel, IAS_KERNEL_ATTR); |
| 239 | } else { |
| 240 | /* Register IrCOMM with LM-IAS */ |
| 241 | self->obj = irias_new_object("IrDA:IrCOMM", IAS_IRCOMM_ID); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 242 | irias_add_integer_attrib(self->obj, "IrDA:TinyTP:LsapSel", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | self->slsap_sel, IAS_KERNEL_ATTR); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* Code the parameters into the buffer */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 246 | irda_param_pack(oct_seq, "bbbbbb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | IRCOMM_SERVICE_TYPE, 1, self->service_type, |
| 248 | IRCOMM_PORT_TYPE, 1, IRCOMM_SERIAL); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /* Register parameters with LM-IAS */ |
| 251 | irias_add_octseq_attrib(self->obj, "Parameters", oct_seq, 6, |
| 252 | IAS_KERNEL_ATTR); |
| 253 | } |
| 254 | irias_insert_object(self->obj); |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * Function ircomm_tty_ias_unregister (self) |
| 259 | * |
| 260 | * Remove our IAS object and client hook while connected. |
| 261 | * |
| 262 | */ |
| 263 | static void ircomm_tty_ias_unregister(struct ircomm_tty_cb *self) |
| 264 | { |
| 265 | /* Remove LM-IAS object now so it is not reused. |
| 266 | * IrCOMM deals very poorly with multiple incoming connections. |
| 267 | * It should looks a lot more like IrNET, and "dup" a server TSAP |
| 268 | * to the application TSAP (based on various rules). |
| 269 | * This is a cheap workaround allowing multiple clients to |
| 270 | * connect to us. It will not always work. |
| 271 | * Each IrCOMM socket has an IAS entry. Incoming connection will |
| 272 | * pick the first one found. So, when we are fully connected, |
| 273 | * we remove our IAS entries so that the next IAS entry is used. |
| 274 | * We do that for *both* client and server, because a server |
| 275 | * can also create client instances. |
| 276 | * Jean II */ |
| 277 | if (self->obj) { |
| 278 | irias_delete_object(self->obj); |
| 279 | self->obj = NULL; |
| 280 | } |
| 281 | |
| 282 | #if 0 |
| 283 | /* Remove discovery handler. |
| 284 | * While we are connected, we no longer need to receive |
| 285 | * discovery events. This would be the case if there is |
| 286 | * multiple IrLAP interfaces. Jean II */ |
| 287 | if (self->ckey) { |
| 288 | irlmp_unregister_client(self->ckey); |
| 289 | self->ckey = NULL; |
| 290 | } |
| 291 | #endif |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Function ircomm_send_initial_parameters (self) |
| 296 | * |
| 297 | * Send initial parameters to the remote IrCOMM device. These parameters |
| 298 | * must be sent before any data. |
| 299 | */ |
| 300 | int ircomm_tty_send_initial_parameters(struct ircomm_tty_cb *self) |
| 301 | { |
| 302 | IRDA_ASSERT(self != NULL, return -1;); |
| 303 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 304 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 305 | if (self->service_type & IRCOMM_3_WIRE_RAW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return 0; |
| 307 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 308 | /* |
| 309 | * Set default values, but only if the application for some reason |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | * haven't set them already |
| 311 | */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 312 | IRDA_DEBUG(2, "%s(), data-rate = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | self->settings.data_rate); |
| 314 | if (!self->settings.data_rate) |
| 315 | self->settings.data_rate = 9600; |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 316 | IRDA_DEBUG(2, "%s(), data-format = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | self->settings.data_format); |
| 318 | if (!self->settings.data_format) |
| 319 | self->settings.data_format = IRCOMM_WSIZE_8; /* 8N1 */ |
| 320 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 321 | IRDA_DEBUG(2, "%s(), flow-control = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | self->settings.flow_control); |
| 323 | /*self->settings.flow_control = IRCOMM_RTS_CTS_IN|IRCOMM_RTS_CTS_OUT;*/ |
| 324 | |
| 325 | /* Do not set delta values for the initial parameters */ |
| 326 | self->settings.dte = IRCOMM_DTR | IRCOMM_RTS; |
| 327 | |
| 328 | /* Only send service type parameter when we are the client */ |
| 329 | if (self->client) |
| 330 | ircomm_param_request(self, IRCOMM_SERVICE_TYPE, FALSE); |
| 331 | ircomm_param_request(self, IRCOMM_DATA_RATE, FALSE); |
| 332 | ircomm_param_request(self, IRCOMM_DATA_FORMAT, FALSE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* For a 3 wire service, we just flush the last parameter and return */ |
| 335 | if (self->settings.service_type == IRCOMM_3_WIRE) { |
| 336 | ircomm_param_request(self, IRCOMM_FLOW_CONTROL, TRUE); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | /* Only 9-wire service types continue here */ |
| 341 | ircomm_param_request(self, IRCOMM_FLOW_CONTROL, FALSE); |
| 342 | #if 0 |
| 343 | ircomm_param_request(self, IRCOMM_XON_XOFF, FALSE); |
| 344 | ircomm_param_request(self, IRCOMM_ENQ_ACK, FALSE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 345 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | /* Notify peer that we are ready to receive data */ |
| 347 | ircomm_param_request(self, IRCOMM_DTE, TRUE); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * Function ircomm_tty_discovery_indication (discovery) |
| 354 | * |
| 355 | * Remote device is discovered, try query the remote IAS to see which |
| 356 | * device it is, and which services it has. |
| 357 | * |
| 358 | */ |
| 359 | static void ircomm_tty_discovery_indication(discinfo_t *discovery, |
| 360 | DISCOVERY_MODE mode, |
| 361 | void *priv) |
| 362 | { |
| 363 | struct ircomm_tty_cb *self; |
| 364 | struct ircomm_tty_info info; |
| 365 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 366 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | /* Important note : |
| 369 | * We need to drop all passive discoveries. |
| 370 | * The LSAP management of IrComm is deficient and doesn't deal |
| 371 | * with the case of two instance connecting to each other |
| 372 | * simultaneously (it will deadlock in LMP). |
| 373 | * The proper fix would be to use the same technique as in IrNET, |
| 374 | * to have one server socket and separate instances for the |
| 375 | * connecting/connected socket. |
| 376 | * The workaround is to drop passive discovery, which drastically |
| 377 | * reduce the probability of this happening. |
| 378 | * Jean II */ |
| 379 | if(mode == DISCOVERY_PASSIVE) |
| 380 | return; |
| 381 | |
| 382 | info.daddr = discovery->daddr; |
| 383 | info.saddr = discovery->saddr; |
| 384 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 385 | self = priv; |
Ryan Reading | c310f09 | 2007-10-17 19:34:11 -0700 | [diff] [blame] | 386 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCOVERY_INDICATION, |
| 387 | NULL, &info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Function ircomm_tty_disconnect_indication (instance, sap, reason, skb) |
| 392 | * |
| 393 | * Link disconnected |
| 394 | * |
| 395 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 396 | void ircomm_tty_disconnect_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | LM_REASON reason, |
| 398 | struct sk_buff *skb) |
| 399 | { |
| 400 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 401 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 402 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | IRDA_ASSERT(self != NULL, return;); |
| 405 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 406 | |
| 407 | if (!self->tty) |
| 408 | return; |
| 409 | |
| 410 | /* This will stop control data transfers */ |
| 411 | self->flow = FLOW_STOP; |
| 412 | |
| 413 | /* Stop data transfers */ |
| 414 | self->tty->hw_stopped = 1; |
| 415 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 416 | ircomm_tty_do_event(self, IRCOMM_TTY_DISCONNECT_INDICATION, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | NULL); |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Function ircomm_tty_getvalue_confirm (result, obj_id, value, priv) |
| 422 | * |
| 423 | * Got result from the IAS query we make |
| 424 | * |
| 425 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 426 | static void ircomm_tty_getvalue_confirm(int result, __u16 obj_id, |
| 427 | struct ias_value *value, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | void *priv) |
| 429 | { |
| 430 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) priv; |
| 431 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 432 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | IRDA_ASSERT(self != NULL, return;); |
| 435 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 436 | |
| 437 | /* We probably don't need to make any more queries */ |
| 438 | iriap_close(self->iriap); |
| 439 | self->iriap = NULL; |
| 440 | |
| 441 | /* Check if request succeeded */ |
| 442 | if (result != IAS_SUCCESS) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 443 | IRDA_DEBUG(4, "%s(), got NULL value!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | |
| 447 | switch (value->type) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 448 | case IAS_OCT_SEQ: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 449 | IRDA_DEBUG(2, "%s(), got octet sequence\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | irda_param_extract_all(self, value->t.oct_seq, value->len, |
| 452 | &ircomm_param_info); |
| 453 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 454 | ircomm_tty_do_event(self, IRCOMM_TTY_GOT_PARAMETERS, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | NULL); |
| 456 | break; |
| 457 | case IAS_INTEGER: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 458 | /* Got LSAP selector */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 459 | IRDA_DEBUG(2, "%s(), got lsapsel = %d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | value->t.integer); |
| 461 | |
| 462 | if (value->t.integer == -1) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 463 | IRDA_DEBUG(0, "%s(), invalid value!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | } else |
| 465 | self->dlsap_sel = value->t.integer; |
| 466 | |
| 467 | ircomm_tty_do_event(self, IRCOMM_TTY_GOT_LSAPSEL, NULL, NULL); |
| 468 | break; |
| 469 | case IAS_MISSING: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 470 | IRDA_DEBUG(0, "%s(), got IAS_MISSING\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | break; |
| 472 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 473 | IRDA_DEBUG(0, "%s(), got unknown type!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | break; |
| 475 | } |
| 476 | irias_delete_value(value); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Function ircomm_tty_connect_confirm (instance, sap, qos, max_sdu_size, skb) |
| 481 | * |
| 482 | * Connection confirmed |
| 483 | * |
| 484 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 485 | void ircomm_tty_connect_confirm(void *instance, void *sap, |
| 486 | struct qos_info *qos, |
| 487 | __u32 max_data_size, |
| 488 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | struct sk_buff *skb) |
| 490 | { |
| 491 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 492 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 493 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | IRDA_ASSERT(self != NULL, return;); |
| 496 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 497 | |
| 498 | self->client = TRUE; |
| 499 | self->max_data_size = max_data_size; |
| 500 | self->max_header_size = max_header_size; |
| 501 | self->flow = FLOW_START; |
| 502 | |
| 503 | ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_CONFIRM, NULL, NULL); |
| 504 | |
| 505 | /* No need to kfree_skb - see ircomm_ttp_connect_confirm() */ |
| 506 | } |
| 507 | |
| 508 | /* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 509 | * Function ircomm_tty_connect_indication (instance, sap, qos, max_sdu_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | * skb) |
| 511 | * |
| 512 | * we are discovered and being requested to connect by remote device ! |
| 513 | * |
| 514 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 515 | void ircomm_tty_connect_indication(void *instance, void *sap, |
| 516 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | __u32 max_data_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 518 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | struct sk_buff *skb) |
| 520 | { |
| 521 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; |
| 522 | int clen; |
| 523 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 524 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | IRDA_ASSERT(self != NULL, return;); |
| 527 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 528 | |
| 529 | self->client = FALSE; |
| 530 | self->max_data_size = max_data_size; |
| 531 | self->max_header_size = max_header_size; |
| 532 | self->flow = FLOW_START; |
| 533 | |
| 534 | clen = skb->data[0]; |
| 535 | if (clen) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 536 | irda_param_extract_all(self, skb->data+1, |
| 537 | IRDA_MIN(skb->len, clen), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | &ircomm_param_info); |
| 539 | |
| 540 | ircomm_tty_do_event(self, IRCOMM_TTY_CONNECT_INDICATION, NULL, NULL); |
| 541 | |
| 542 | /* No need to kfree_skb - see ircomm_ttp_connect_indication() */ |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Function ircomm_tty_link_established (self) |
| 547 | * |
| 548 | * Called when the IrCOMM link is established |
| 549 | * |
| 550 | */ |
| 551 | void ircomm_tty_link_established(struct ircomm_tty_cb *self) |
| 552 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 553 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | IRDA_ASSERT(self != NULL, return;); |
| 556 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 557 | |
| 558 | if (!self->tty) |
| 559 | return; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | del_timer(&self->watchdog_timer); |
| 562 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 563 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | * IrCOMM link is now up, and if we are not using hardware |
| 565 | * flow-control, then declare the hardware as running. Otherwise we |
| 566 | * 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] | 567 | * line. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | */ |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame^] | 569 | if ((self->port.flags & ASYNC_CTS_FLOW) && |
| 570 | ((self->settings.dce & IRCOMM_CTS) == 0)) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 571 | IRDA_DEBUG(0, "%s(), waiting for CTS ...\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return; |
| 573 | } else { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 574 | IRDA_DEBUG(1, "%s(), starting hardware!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | self->tty->hw_stopped = 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | /* Wake up processes blocked on open */ |
Jiri Slaby | a3cc9fc | 2012-06-04 13:35:16 +0200 | [diff] [blame] | 579 | wake_up_interruptible(&self->port.open_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | schedule_work(&self->tqueue); |
| 583 | } |
| 584 | |
| 585 | /* |
| 586 | * Function ircomm_tty_start_watchdog_timer (self, timeout) |
| 587 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 588 | * Start the watchdog timer. This timer is used to make sure that any |
| 589 | * connection attempt is successful, and if not, we will retry after |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | * the timeout |
| 591 | */ |
| 592 | static void ircomm_tty_start_watchdog_timer(struct ircomm_tty_cb *self, |
| 593 | int timeout) |
| 594 | { |
| 595 | IRDA_ASSERT(self != NULL, return;); |
| 596 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 597 | |
| 598 | irda_start_timer(&self->watchdog_timer, timeout, (void *) self, |
| 599 | ircomm_tty_watchdog_timer_expired); |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * Function ircomm_tty_watchdog_timer_expired (data) |
| 604 | * |
| 605 | * Called when the connect procedure have taken to much time. |
| 606 | * |
| 607 | */ |
| 608 | static void ircomm_tty_watchdog_timer_expired(void *data) |
| 609 | { |
| 610 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 611 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 612 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | IRDA_ASSERT(self != NULL, return;); |
| 615 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 616 | |
| 617 | ircomm_tty_do_event(self, IRCOMM_TTY_WD_TIMER_EXPIRED, NULL, NULL); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | /* |
| 622 | * Function ircomm_tty_do_event (self, event, skb) |
| 623 | * |
| 624 | * Process event |
| 625 | * |
| 626 | */ |
| 627 | 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] | 628 | struct sk_buff *skb, struct ircomm_tty_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
| 630 | IRDA_ASSERT(self != NULL, return -1;); |
| 631 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); |
| 632 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 633 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return (*state[self->state])(self, event, skb, info); |
| 637 | } |
| 638 | |
| 639 | /* |
| 640 | * Function ircomm_tty_next_state (self, state) |
| 641 | * |
| 642 | * Switch state |
| 643 | * |
| 644 | */ |
| 645 | static inline void ircomm_tty_next_state(struct ircomm_tty_cb *self, IRCOMM_TTY_STATE state) |
| 646 | { |
| 647 | /* |
| 648 | IRDA_ASSERT(self != NULL, return;); |
| 649 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;); |
| 650 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 651 | IRDA_DEBUG(2, "%s: next state=%s, service type=%d\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | ircomm_tty_state[self->state], self->service_type); |
| 653 | */ |
| 654 | self->state = state; |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * Function ircomm_tty_state_idle (self, event, skb, info) |
| 659 | * |
| 660 | * Just hanging around |
| 661 | * |
| 662 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 663 | static int ircomm_tty_state_idle(struct ircomm_tty_cb *self, |
| 664 | IRCOMM_TTY_EVENT event, |
| 665 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | struct ircomm_tty_info *info) |
| 667 | { |
| 668 | int ret = 0; |
| 669 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 670 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 672 | switch (event) { |
| 673 | case IRCOMM_TTY_ATTACH_CABLE: |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 674 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 676 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS); |
| 679 | break; |
| 680 | case IRCOMM_TTY_DISCOVERY_INDICATION: |
| 681 | self->daddr = info->daddr; |
| 682 | self->saddr = info->saddr; |
| 683 | |
| 684 | if (self->iriap) { |
| 685 | IRDA_WARNING("%s(), busy with a previous query\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 686 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return -EBUSY; |
| 688 | } |
| 689 | |
| 690 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 691 | ircomm_tty_getvalue_confirm); |
| 692 | |
| 693 | iriap_getvaluebyclass_request(self->iriap, |
| 694 | self->saddr, self->daddr, |
| 695 | "IrDA:IrCOMM", "Parameters"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 698 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS); |
| 699 | break; |
| 700 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 701 | del_timer(&self->watchdog_timer); |
| 702 | |
| 703 | /* Accept connection */ |
| 704 | ircomm_connect_response(self->ircomm, NULL); |
| 705 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 706 | break; |
| 707 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 708 | /* Just stay idle */ |
| 709 | break; |
| 710 | case IRCOMM_TTY_DETACH_CABLE: |
| 711 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 712 | break; |
| 713 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 714 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | ircomm_tty_event[event]); |
| 716 | ret = -EINVAL; |
| 717 | } |
| 718 | return ret; |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Function ircomm_tty_state_search (self, event, skb, info) |
| 723 | * |
| 724 | * Trying to discover an IrCOMM device |
| 725 | * |
| 726 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 727 | static int ircomm_tty_state_search(struct ircomm_tty_cb *self, |
| 728 | IRCOMM_TTY_EVENT event, |
| 729 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | struct ircomm_tty_info *info) |
| 731 | { |
| 732 | int ret = 0; |
| 733 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 734 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 736 | |
| 737 | switch (event) { |
| 738 | case IRCOMM_TTY_DISCOVERY_INDICATION: |
| 739 | self->daddr = info->daddr; |
| 740 | self->saddr = info->saddr; |
| 741 | |
| 742 | if (self->iriap) { |
| 743 | IRDA_WARNING("%s(), busy with a previous query\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 744 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | return -EBUSY; |
| 746 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 749 | ircomm_tty_getvalue_confirm); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (self->service_type == IRCOMM_3_WIRE_RAW) { |
| 752 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 753 | self->daddr, "IrLPT", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | "IrDA:IrLMP:LsapSel"); |
| 755 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL); |
| 756 | } else { |
| 757 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 758 | self->daddr, |
| 759 | "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | "Parameters"); |
| 761 | |
| 762 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_PARAMETERS); |
| 763 | } |
| 764 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 765 | break; |
| 766 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 767 | del_timer(&self->watchdog_timer); |
| 768 | ircomm_tty_ias_unregister(self); |
| 769 | |
| 770 | /* Accept connection */ |
| 771 | ircomm_connect_response(self->ircomm, NULL); |
| 772 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 773 | break; |
| 774 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 775 | #if 1 |
| 776 | /* Give up */ |
| 777 | #else |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 778 | /* Try to discover any remote devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 780 | irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS); |
| 781 | #endif |
| 782 | break; |
| 783 | case IRCOMM_TTY_DETACH_CABLE: |
| 784 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 785 | break; |
| 786 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 787 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | ircomm_tty_event[event]); |
| 789 | ret = -EINVAL; |
| 790 | } |
| 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | /* |
| 795 | * Function ircomm_tty_state_query (self, event, skb, info) |
| 796 | * |
| 797 | * Querying the remote LM-IAS for IrCOMM parameters |
| 798 | * |
| 799 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 800 | static int ircomm_tty_state_query_parameters(struct ircomm_tty_cb *self, |
| 801 | IRCOMM_TTY_EVENT event, |
| 802 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | struct ircomm_tty_info *info) |
| 804 | { |
| 805 | int ret = 0; |
| 806 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 807 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 809 | |
| 810 | switch (event) { |
| 811 | case IRCOMM_TTY_GOT_PARAMETERS: |
| 812 | if (self->iriap) { |
| 813 | IRDA_WARNING("%s(), busy with a previous query\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 814 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | return -EBUSY; |
| 816 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, |
| 819 | ircomm_tty_getvalue_confirm); |
| 820 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 821 | iriap_getvaluebyclass_request(self->iriap, self->saddr, |
| 822 | self->daddr, "IrDA:IrCOMM", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | "IrDA:TinyTP:LsapSel"); |
| 824 | |
| 825 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 826 | ircomm_tty_next_state(self, IRCOMM_TTY_QUERY_LSAP_SEL); |
| 827 | break; |
| 828 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 829 | /* Go back to search mode */ |
| 830 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 831 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | break; |
| 833 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 834 | del_timer(&self->watchdog_timer); |
| 835 | ircomm_tty_ias_unregister(self); |
| 836 | |
| 837 | /* Accept connection */ |
| 838 | ircomm_connect_response(self->ircomm, NULL); |
| 839 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 840 | break; |
| 841 | case IRCOMM_TTY_DETACH_CABLE: |
| 842 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 843 | break; |
| 844 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 845 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | ircomm_tty_event[event]); |
| 847 | ret = -EINVAL; |
| 848 | } |
| 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Function ircomm_tty_state_query_lsap_sel (self, event, skb, info) |
| 854 | * |
| 855 | * Query remote LM-IAS for the LSAP selector which we can connect to |
| 856 | * |
| 857 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 858 | static int ircomm_tty_state_query_lsap_sel(struct ircomm_tty_cb *self, |
| 859 | IRCOMM_TTY_EVENT event, |
| 860 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | struct ircomm_tty_info *info) |
| 862 | { |
| 863 | int ret = 0; |
| 864 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 865 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 867 | |
| 868 | switch (event) { |
| 869 | case IRCOMM_TTY_GOT_LSAPSEL: |
| 870 | /* Connect to remote device */ |
| 871 | ret = ircomm_connect_request(self->ircomm, self->dlsap_sel, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 872 | self->saddr, self->daddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | NULL, self->service_type); |
| 874 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 875 | ircomm_tty_next_state(self, IRCOMM_TTY_SETUP); |
| 876 | break; |
| 877 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 878 | /* Go back to search mode */ |
| 879 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
| 880 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 881 | break; |
| 882 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 883 | del_timer(&self->watchdog_timer); |
| 884 | ircomm_tty_ias_unregister(self); |
| 885 | |
| 886 | /* Accept connection */ |
| 887 | ircomm_connect_response(self->ircomm, NULL); |
| 888 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 889 | break; |
| 890 | case IRCOMM_TTY_DETACH_CABLE: |
| 891 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 892 | break; |
| 893 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 894 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | ircomm_tty_event[event]); |
| 896 | ret = -EINVAL; |
| 897 | } |
| 898 | return ret; |
| 899 | } |
| 900 | |
| 901 | /* |
| 902 | * Function ircomm_tty_state_setup (self, event, skb, info) |
| 903 | * |
| 904 | * Trying to connect |
| 905 | * |
| 906 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 907 | static int ircomm_tty_state_setup(struct ircomm_tty_cb *self, |
| 908 | IRCOMM_TTY_EVENT event, |
| 909 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | struct ircomm_tty_info *info) |
| 911 | { |
| 912 | int ret = 0; |
| 913 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 914 | IRDA_DEBUG(2, "%s: state=%s, event=%s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | ircomm_tty_state[self->state], ircomm_tty_event[event]); |
| 916 | |
| 917 | switch (event) { |
| 918 | case IRCOMM_TTY_CONNECT_CONFIRM: |
| 919 | del_timer(&self->watchdog_timer); |
| 920 | ircomm_tty_ias_unregister(self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 921 | |
| 922 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | * Send initial parameters. This will also send out queued |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 924 | * parameters waiting for the connection to come up |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | */ |
| 926 | ircomm_tty_send_initial_parameters(self); |
| 927 | ircomm_tty_link_established(self); |
| 928 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 929 | break; |
| 930 | case IRCOMM_TTY_CONNECT_INDICATION: |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | /* Accept connection */ |
| 935 | ircomm_connect_response(self->ircomm, NULL); |
| 936 | ircomm_tty_next_state(self, IRCOMM_TTY_READY); |
| 937 | break; |
| 938 | case IRCOMM_TTY_WD_TIMER_EXPIRED: |
| 939 | /* Go back to search mode */ |
| 940 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
| 941 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 942 | break; |
| 943 | case IRCOMM_TTY_DETACH_CABLE: |
| 944 | /* ircomm_disconnect_request(self->ircomm, NULL); */ |
| 945 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 946 | break; |
| 947 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 948 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | ircomm_tty_event[event]); |
| 950 | ret = -EINVAL; |
| 951 | } |
| 952 | return ret; |
| 953 | } |
| 954 | |
| 955 | /* |
| 956 | * Function ircomm_tty_state_ready (self, event, skb, info) |
| 957 | * |
| 958 | * IrCOMM is now connected |
| 959 | * |
| 960 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 961 | static int ircomm_tty_state_ready(struct ircomm_tty_cb *self, |
| 962 | IRCOMM_TTY_EVENT event, |
| 963 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | struct ircomm_tty_info *info) |
| 965 | { |
| 966 | int ret = 0; |
| 967 | |
| 968 | switch (event) { |
| 969 | case IRCOMM_TTY_DATA_REQUEST: |
| 970 | ret = ircomm_data_request(self->ircomm, skb); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 971 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | case IRCOMM_TTY_DETACH_CABLE: |
| 973 | ircomm_disconnect_request(self->ircomm, NULL); |
| 974 | ircomm_tty_next_state(self, IRCOMM_TTY_IDLE); |
| 975 | break; |
| 976 | case IRCOMM_TTY_DISCONNECT_INDICATION: |
| 977 | ircomm_tty_ias_register(self); |
| 978 | ircomm_tty_next_state(self, IRCOMM_TTY_SEARCH); |
| 979 | ircomm_tty_start_watchdog_timer(self, 3*HZ); |
| 980 | |
Jiri Slaby | 849d5a9 | 2012-06-04 13:35:19 +0200 | [diff] [blame^] | 981 | if (self->port.flags & ASYNC_CHECK_CD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | /* Drop carrier */ |
| 983 | self->settings.dce = IRCOMM_DELTA_CD; |
| 984 | ircomm_tty_check_modem_status(self); |
| 985 | } else { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 986 | IRDA_DEBUG(0, "%s(), hanging up!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | if (self->tty) |
| 988 | tty_hangup(self->tty); |
| 989 | } |
| 990 | break; |
| 991 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 992 | IRDA_DEBUG(2, "%s(), unknown event: %s\n", __func__ , |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | ircomm_tty_event[event]); |
| 994 | ret = -EINVAL; |
| 995 | } |
| 996 | return ret; |
| 997 | } |
| 998 | |