irda: Convert IRDA_DEBUG to pr_debug
[deliverable/linux.git] / net / irda / irlmp_event.c
1 /*********************************************************************
2 *
3 * Filename: irlmp_event.c
4 * Version: 0.8
5 * Description: An IrDA LMP event driver for Linux
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Mon Aug 4 20:40:53 1997
9 * Modified at: Tue Dec 14 23:04:16 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * Neither Dag Brattli nor University of Tromsø admit liability nor
22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge.
24 *
25 ********************************************************************/
26
27 #include <linux/kernel.h>
28
29 #include <net/irda/irda.h>
30 #include <net/irda/timer.h>
31 #include <net/irda/irlap.h>
32 #include <net/irda/irlmp.h>
33 #include <net/irda/irlmp_frame.h>
34 #include <net/irda/irlmp_event.h>
35
36 const char *const irlmp_state[] = {
37 "LAP_STANDBY",
38 "LAP_U_CONNECT",
39 "LAP_ACTIVE",
40 };
41
42 const char *const irlsap_state[] = {
43 "LSAP_DISCONNECTED",
44 "LSAP_CONNECT",
45 "LSAP_CONNECT_PEND",
46 "LSAP_DATA_TRANSFER_READY",
47 "LSAP_SETUP",
48 "LSAP_SETUP_PEND",
49 };
50
51 #ifdef CONFIG_IRDA_DEBUG
52 static const char *const irlmp_event[] = {
53 "LM_CONNECT_REQUEST",
54 "LM_CONNECT_CONFIRM",
55 "LM_CONNECT_RESPONSE",
56 "LM_CONNECT_INDICATION",
57
58 "LM_DISCONNECT_INDICATION",
59 "LM_DISCONNECT_REQUEST",
60
61 "LM_DATA_REQUEST",
62 "LM_UDATA_REQUEST",
63 "LM_DATA_INDICATION",
64 "LM_UDATA_INDICATION",
65
66 "LM_WATCHDOG_TIMEOUT",
67
68 /* IrLAP events */
69 "LM_LAP_CONNECT_REQUEST",
70 "LM_LAP_CONNECT_INDICATION",
71 "LM_LAP_CONNECT_CONFIRM",
72 "LM_LAP_DISCONNECT_INDICATION",
73 "LM_LAP_DISCONNECT_REQUEST",
74 "LM_LAP_DISCOVERY_REQUEST",
75 "LM_LAP_DISCOVERY_CONFIRM",
76 "LM_LAP_IDLE_TIMEOUT",
77 };
78 #endif /* CONFIG_IRDA_DEBUG */
79
80 /* LAP Connection control proto declarations */
81 static void irlmp_state_standby (struct lap_cb *, IRLMP_EVENT,
82 struct sk_buff *);
83 static void irlmp_state_u_connect(struct lap_cb *, IRLMP_EVENT,
84 struct sk_buff *);
85 static void irlmp_state_active (struct lap_cb *, IRLMP_EVENT,
86 struct sk_buff *);
87
88 /* LSAP Connection control proto declarations */
89 static int irlmp_state_disconnected(struct lsap_cb *, IRLMP_EVENT,
90 struct sk_buff *);
91 static int irlmp_state_connect (struct lsap_cb *, IRLMP_EVENT,
92 struct sk_buff *);
93 static int irlmp_state_connect_pend(struct lsap_cb *, IRLMP_EVENT,
94 struct sk_buff *);
95 static int irlmp_state_dtr (struct lsap_cb *, IRLMP_EVENT,
96 struct sk_buff *);
97 static int irlmp_state_setup (struct lsap_cb *, IRLMP_EVENT,
98 struct sk_buff *);
99 static int irlmp_state_setup_pend (struct lsap_cb *, IRLMP_EVENT,
100 struct sk_buff *);
101
102 static void (*lap_state[]) (struct lap_cb *, IRLMP_EVENT, struct sk_buff *) =
103 {
104 irlmp_state_standby,
105 irlmp_state_u_connect,
106 irlmp_state_active,
107 };
108
109 static int (*lsap_state[])( struct lsap_cb *, IRLMP_EVENT, struct sk_buff *) =
110 {
111 irlmp_state_disconnected,
112 irlmp_state_connect,
113 irlmp_state_connect_pend,
114 irlmp_state_dtr,
115 irlmp_state_setup,
116 irlmp_state_setup_pend
117 };
118
119 static inline void irlmp_next_lap_state(struct lap_cb *self,
120 IRLMP_STATE state)
121 {
122 /*
123 pr_debug("%s(), LMP LAP = %s\n", __func__, irlmp_state[state]);
124 */
125 self->lap_state = state;
126 }
127
128 static inline void irlmp_next_lsap_state(struct lsap_cb *self,
129 LSAP_STATE state)
130 {
131 /*
132 IRDA_ASSERT(self != NULL, return;);
133 pr_debug("%s(), LMP LSAP = %s\n", __func__, irlsap_state[state]);
134 */
135 self->lsap_state = state;
136 }
137
138 /* Do connection control events */
139 int irlmp_do_lsap_event(struct lsap_cb *self, IRLMP_EVENT event,
140 struct sk_buff *skb)
141 {
142 IRDA_ASSERT(self != NULL, return -1;);
143 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
144
145 pr_debug("%s(), EVENT = %s, STATE = %s\n",
146 __func__, irlmp_event[event], irlsap_state[self->lsap_state]);
147
148 return (*lsap_state[self->lsap_state]) (self, event, skb);
149 }
150
151 /*
152 * Function do_lap_event (event, skb, info)
153 *
154 * Do IrLAP control events
155 *
156 */
157 void irlmp_do_lap_event(struct lap_cb *self, IRLMP_EVENT event,
158 struct sk_buff *skb)
159 {
160 IRDA_ASSERT(self != NULL, return;);
161 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
162
163 pr_debug("%s(), EVENT = %s, STATE = %s\n", __func__,
164 irlmp_event[event],
165 irlmp_state[self->lap_state]);
166
167 (*lap_state[self->lap_state]) (self, event, skb);
168 }
169
170 void irlmp_discovery_timer_expired(void *data)
171 {
172 /* We always cleanup the log (active & passive discovery) */
173 irlmp_do_expiry();
174
175 irlmp_do_discovery(sysctl_discovery_slots);
176
177 /* Restart timer */
178 irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout * HZ);
179 }
180
181 void irlmp_watchdog_timer_expired(void *data)
182 {
183 struct lsap_cb *self = (struct lsap_cb *) data;
184
185 IRDA_ASSERT(self != NULL, return;);
186 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
187
188 irlmp_do_lsap_event(self, LM_WATCHDOG_TIMEOUT, NULL);
189 }
190
191 void irlmp_idle_timer_expired(void *data)
192 {
193 struct lap_cb *self = (struct lap_cb *) data;
194
195 IRDA_ASSERT(self != NULL, return;);
196 IRDA_ASSERT(self->magic == LMP_LAP_MAGIC, return;);
197
198 irlmp_do_lap_event(self, LM_LAP_IDLE_TIMEOUT, NULL);
199 }
200
201 /*
202 * Send an event on all LSAPs attached to this LAP.
203 */
204 static inline void
205 irlmp_do_all_lsap_event(hashbin_t * lsap_hashbin,
206 IRLMP_EVENT event)
207 {
208 struct lsap_cb *lsap;
209 struct lsap_cb *lsap_next;
210
211 /* Note : this function use the new hashbin_find_next()
212 * function, instead of the old hashbin_get_next().
213 * This make sure that we are always pointing one lsap
214 * ahead, so that if the current lsap is removed as the
215 * result of sending the event, we don't care.
216 * Also, as we store the context ourselves, if an enumeration
217 * of the same lsap hashbin happens as the result of sending the
218 * event, we don't care.
219 * The only problem is if the next lsap is removed. In that case,
220 * hashbin_find_next() will return NULL and we will abort the
221 * enumeration. - Jean II */
222
223 /* Also : we don't accept any skb in input. We can *NOT* pass
224 * the same skb to multiple clients safely, we would need to
225 * skb_clone() it. - Jean II */
226
227 lsap = (struct lsap_cb *) hashbin_get_first(lsap_hashbin);
228
229 while (NULL != hashbin_find_next(lsap_hashbin,
230 (long) lsap,
231 NULL,
232 (void *) &lsap_next) ) {
233 irlmp_do_lsap_event(lsap, event, NULL);
234 lsap = lsap_next;
235 }
236 }
237
238 /*********************************************************************
239 *
240 * LAP connection control states
241 *
242 ********************************************************************/
243
244 /*
245 * Function irlmp_state_standby (event, skb, info)
246 *
247 * STANDBY, The IrLAP connection does not exist.
248 *
249 */
250 static void irlmp_state_standby(struct lap_cb *self, IRLMP_EVENT event,
251 struct sk_buff *skb)
252 {
253 IRDA_ASSERT(self->irlap != NULL, return;);
254
255 switch (event) {
256 case LM_LAP_DISCOVERY_REQUEST:
257 /* irlmp_next_station_state( LMP_DISCOVER); */
258
259 irlap_discovery_request(self->irlap, &irlmp->discovery_cmd);
260 break;
261 case LM_LAP_CONNECT_INDICATION:
262 /* It's important to switch state first, to avoid IrLMP to
263 * think that the link is free since IrLMP may then start
264 * discovery before the connection is properly set up. DB.
265 */
266 irlmp_next_lap_state(self, LAP_ACTIVE);
267
268 /* Just accept connection TODO, this should be fixed */
269 irlap_connect_response(self->irlap, skb);
270 break;
271 case LM_LAP_CONNECT_REQUEST:
272 pr_debug("%s() LS_CONNECT_REQUEST\n", __func__);
273
274 irlmp_next_lap_state(self, LAP_U_CONNECT);
275
276 /* FIXME: need to set users requested QoS */
277 irlap_connect_request(self->irlap, self->daddr, NULL, 0);
278 break;
279 case LM_LAP_DISCONNECT_INDICATION:
280 pr_debug("%s(), Error LM_LAP_DISCONNECT_INDICATION\n",
281 __func__);
282
283 irlmp_next_lap_state(self, LAP_STANDBY);
284 break;
285 default:
286 pr_debug("%s(), Unknown event %s\n",
287 __func__, irlmp_event[event]);
288 break;
289 }
290 }
291
292 /*
293 * Function irlmp_state_u_connect (event, skb, info)
294 *
295 * U_CONNECT, The layer above has tried to open an LSAP connection but
296 * since the IrLAP connection does not exist, we must first start an
297 * IrLAP connection. We are now waiting response from IrLAP.
298 * */
299 static void irlmp_state_u_connect(struct lap_cb *self, IRLMP_EVENT event,
300 struct sk_buff *skb)
301 {
302 pr_debug("%s(), event=%s\n", __func__, irlmp_event[event]);
303
304 switch (event) {
305 case LM_LAP_CONNECT_INDICATION:
306 /* It's important to switch state first, to avoid IrLMP to
307 * think that the link is free since IrLMP may then start
308 * discovery before the connection is properly set up. DB.
309 */
310 irlmp_next_lap_state(self, LAP_ACTIVE);
311
312 /* Just accept connection TODO, this should be fixed */
313 irlap_connect_response(self->irlap, skb);
314
315 /* Tell LSAPs that they can start sending data */
316 irlmp_do_all_lsap_event(self->lsaps, LM_LAP_CONNECT_CONFIRM);
317
318 /* Note : by the time we get there (LAP retries and co),
319 * the lsaps may already have gone. This avoid getting stuck
320 * forever in LAP_ACTIVE state - Jean II */
321 if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
322 pr_debug("%s() NO LSAPs !\n", __func__);
323 irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
324 }
325 break;
326 case LM_LAP_CONNECT_REQUEST:
327 /* Already trying to connect */
328 break;
329 case LM_LAP_CONNECT_CONFIRM:
330 /* For all lsap_ce E Associated do LS_Connect_confirm */
331 irlmp_next_lap_state(self, LAP_ACTIVE);
332
333 /* Tell LSAPs that they can start sending data */
334 irlmp_do_all_lsap_event(self->lsaps, LM_LAP_CONNECT_CONFIRM);
335
336 /* Note : by the time we get there (LAP retries and co),
337 * the lsaps may already have gone. This avoid getting stuck
338 * forever in LAP_ACTIVE state - Jean II */
339 if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
340 pr_debug("%s() NO LSAPs !\n", __func__);
341 irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
342 }
343 break;
344 case LM_LAP_DISCONNECT_INDICATION:
345 pr_debug("%s(), LM_LAP_DISCONNECT_INDICATION\n", __func__);
346 irlmp_next_lap_state(self, LAP_STANDBY);
347
348 /* Send disconnect event to all LSAPs using this link */
349 irlmp_do_all_lsap_event(self->lsaps,
350 LM_LAP_DISCONNECT_INDICATION);
351 break;
352 case LM_LAP_DISCONNECT_REQUEST:
353 pr_debug("%s(), LM_LAP_DISCONNECT_REQUEST\n", __func__);
354
355 /* One of the LSAP did timeout or was closed, if it was
356 * the last one, try to get out of here - Jean II */
357 if (HASHBIN_GET_SIZE(self->lsaps) <= 1) {
358 irlap_disconnect_request(self->irlap);
359 }
360 break;
361 default:
362 pr_debug("%s(), Unknown event %s\n",
363 __func__, irlmp_event[event]);
364 break;
365 }
366 }
367
368 /*
369 * Function irlmp_state_active (event, skb, info)
370 *
371 * ACTIVE, IrLAP connection is active
372 *
373 */
374 static void irlmp_state_active(struct lap_cb *self, IRLMP_EVENT event,
375 struct sk_buff *skb)
376 {
377 switch (event) {
378 case LM_LAP_CONNECT_REQUEST:
379 pr_debug("%s(), LS_CONNECT_REQUEST\n", __func__);
380
381 /*
382 * IrLAP may have a pending disconnect. We tried to close
383 * IrLAP, but it was postponed because the link was
384 * busy or we were still sending packets. As we now
385 * need it, make sure it stays on. Jean II
386 */
387 irlap_clear_disconnect(self->irlap);
388
389 /*
390 * LAP connection already active, just bounce back! Since we
391 * don't know which LSAP that tried to do this, we have to
392 * notify all LSAPs using this LAP, but that should be safe to
393 * do anyway.
394 */
395 irlmp_do_all_lsap_event(self->lsaps, LM_LAP_CONNECT_CONFIRM);
396
397 /* Needed by connect indication */
398 irlmp_do_all_lsap_event(irlmp->unconnected_lsaps,
399 LM_LAP_CONNECT_CONFIRM);
400 /* Keep state */
401 break;
402 case LM_LAP_DISCONNECT_REQUEST:
403 /*
404 * Need to find out if we should close IrLAP or not. If there
405 * is only one LSAP connection left on this link, that LSAP
406 * must be the one that tries to close IrLAP. It will be
407 * removed later and moved to the list of unconnected LSAPs
408 */
409 if (HASHBIN_GET_SIZE(self->lsaps) > 0) {
410 /* Timer value is checked in irsysctl - Jean II */
411 irlmp_start_idle_timer(self, sysctl_lap_keepalive_time * HZ / 1000);
412 } else {
413 /* No more connections, so close IrLAP */
414
415 /* We don't want to change state just yet, because
416 * we want to reflect accurately the real state of
417 * the LAP, not the state we wish it was in,
418 * so that we don't lose LM_LAP_CONNECT_REQUEST.
419 * In some cases, IrLAP won't close the LAP
420 * immediately. For example, it might still be
421 * retrying packets or waiting for the pf bit.
422 * As the LAP always send a DISCONNECT_INDICATION
423 * in PCLOSE or SCLOSE, just change state on that.
424 * Jean II */
425 irlap_disconnect_request(self->irlap);
426 }
427 break;
428 case LM_LAP_IDLE_TIMEOUT:
429 if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
430 /* Same reasoning as above - keep state */
431 irlap_disconnect_request(self->irlap);
432 }
433 break;
434 case LM_LAP_DISCONNECT_INDICATION:
435 irlmp_next_lap_state(self, LAP_STANDBY);
436
437 /* In some case, at this point our side has already closed
438 * all lsaps, and we are waiting for the idle_timer to
439 * expire. If another device reconnect immediately, the
440 * idle timer will expire in the midle of the connection
441 * initialisation, screwing up things a lot...
442 * Therefore, we must stop the timer... */
443 irlmp_stop_idle_timer(self);
444
445 /*
446 * Inform all connected LSAP's using this link
447 */
448 irlmp_do_all_lsap_event(self->lsaps,
449 LM_LAP_DISCONNECT_INDICATION);
450
451 /* Force an expiry of the discovery log.
452 * Now that the LAP is free, the system may attempt to
453 * connect to another device. Unfortunately, our entries
454 * are stale. There is a small window (<3s) before the
455 * normal discovery will run and where irlmp_connect_request()
456 * can get the wrong info, so make sure things get
457 * cleaned *NOW* ;-) - Jean II */
458 irlmp_do_expiry();
459 break;
460 default:
461 pr_debug("%s(), Unknown event %s\n",
462 __func__, irlmp_event[event]);
463 break;
464 }
465 }
466
467 /*********************************************************************
468 *
469 * LSAP connection control states
470 *
471 ********************************************************************/
472
473 /*
474 * Function irlmp_state_disconnected (event, skb, info)
475 *
476 * DISCONNECTED
477 *
478 */
479 static int irlmp_state_disconnected(struct lsap_cb *self, IRLMP_EVENT event,
480 struct sk_buff *skb)
481 {
482 int ret = 0;
483
484 IRDA_ASSERT(self != NULL, return -1;);
485 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
486
487 switch (event) {
488 #ifdef CONFIG_IRDA_ULTRA
489 case LM_UDATA_INDICATION:
490 /* This is most bizarre. Those packets are aka unreliable
491 * connected, aka IrLPT or SOCK_DGRAM/IRDAPROTO_UNITDATA.
492 * Why do we pass them as Ultra ??? Jean II */
493 irlmp_connless_data_indication(self, skb);
494 break;
495 #endif /* CONFIG_IRDA_ULTRA */
496 case LM_CONNECT_REQUEST:
497 pr_debug("%s(), LM_CONNECT_REQUEST\n", __func__);
498
499 if (self->conn_skb) {
500 net_warn_ratelimited("%s: busy with another request!\n",
501 __func__);
502 return -EBUSY;
503 }
504 /* Don't forget to refcount it (see irlmp_connect_request()) */
505 skb_get(skb);
506 self->conn_skb = skb;
507
508 irlmp_next_lsap_state(self, LSAP_SETUP_PEND);
509
510 /* Start watchdog timer (5 secs for now) */
511 irlmp_start_watchdog_timer(self, 5*HZ);
512
513 irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
514 break;
515 case LM_CONNECT_INDICATION:
516 if (self->conn_skb) {
517 net_warn_ratelimited("%s: busy with another request!\n",
518 __func__);
519 return -EBUSY;
520 }
521 /* Don't forget to refcount it (see irlap_driver_rcv()) */
522 skb_get(skb);
523 self->conn_skb = skb;
524
525 irlmp_next_lsap_state(self, LSAP_CONNECT_PEND);
526
527 /* Start watchdog timer
528 * This is not mentionned in the spec, but there is a rare
529 * race condition that can get the socket stuck.
530 * If we receive this event while our LAP is closing down,
531 * the LM_LAP_CONNECT_REQUEST get lost and we get stuck in
532 * CONNECT_PEND state forever.
533 * The other cause of getting stuck down there is if the
534 * higher layer never reply to the CONNECT_INDICATION.
535 * Anyway, it make sense to make sure that we always have
536 * a backup plan. 1 second is plenty (should be immediate).
537 * Jean II */
538 irlmp_start_watchdog_timer(self, 1*HZ);
539
540 irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
541 break;
542 default:
543 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
544 __func__, irlmp_event[event], self->slsap_sel);
545 break;
546 }
547 return ret;
548 }
549
550 /*
551 * Function irlmp_state_connect (self, event, skb)
552 *
553 * CONNECT
554 *
555 */
556 static int irlmp_state_connect(struct lsap_cb *self, IRLMP_EVENT event,
557 struct sk_buff *skb)
558 {
559 struct lsap_cb *lsap;
560 int ret = 0;
561
562 IRDA_ASSERT(self != NULL, return -1;);
563 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
564
565 switch (event) {
566 case LM_CONNECT_RESPONSE:
567 /*
568 * Bind this LSAP to the IrLAP link where the connect was
569 * received
570 */
571 lsap = hashbin_remove(irlmp->unconnected_lsaps, (long) self,
572 NULL);
573
574 IRDA_ASSERT(lsap == self, return -1;);
575 IRDA_ASSERT(self->lap != NULL, return -1;);
576 IRDA_ASSERT(self->lap->lsaps != NULL, return -1;);
577
578 hashbin_insert(self->lap->lsaps, (irda_queue_t *) self,
579 (long) self, NULL);
580
581 set_bit(0, &self->connected); /* TRUE */
582
583 irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
584 self->slsap_sel, CONNECT_CNF, skb);
585
586 del_timer(&self->watchdog_timer);
587
588 irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
589 break;
590 case LM_WATCHDOG_TIMEOUT:
591 /* May happen, who knows...
592 * Jean II */
593 pr_debug("%s() WATCHDOG_TIMEOUT!\n", __func__);
594
595 /* Disconnect, get out... - Jean II */
596 self->lap = NULL;
597 self->dlsap_sel = LSAP_ANY;
598 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
599 break;
600 default:
601 /* LM_LAP_DISCONNECT_INDICATION : Should never happen, we
602 * are *not* yet bound to the IrLAP link. Jean II */
603 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
604 __func__, irlmp_event[event], self->slsap_sel);
605 break;
606 }
607 return ret;
608 }
609
610 /*
611 * Function irlmp_state_connect_pend (event, skb, info)
612 *
613 * CONNECT_PEND
614 *
615 */
616 static int irlmp_state_connect_pend(struct lsap_cb *self, IRLMP_EVENT event,
617 struct sk_buff *skb)
618 {
619 struct sk_buff *tx_skb;
620 int ret = 0;
621
622 IRDA_ASSERT(self != NULL, return -1;);
623 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
624
625 switch (event) {
626 case LM_CONNECT_REQUEST:
627 /* Keep state */
628 break;
629 case LM_CONNECT_RESPONSE:
630 pr_debug("%s(), LM_CONNECT_RESPONSE, no indication issued yet\n",
631 __func__);
632 /* Keep state */
633 break;
634 case LM_DISCONNECT_REQUEST:
635 pr_debug("%s(), LM_DISCONNECT_REQUEST, not yet bound to IrLAP connection\n",
636 __func__);
637 /* Keep state */
638 break;
639 case LM_LAP_CONNECT_CONFIRM:
640 pr_debug("%s(), LS_CONNECT_CONFIRM\n", __func__);
641 irlmp_next_lsap_state(self, LSAP_CONNECT);
642
643 tx_skb = self->conn_skb;
644 self->conn_skb = NULL;
645
646 irlmp_connect_indication(self, tx_skb);
647 /* Drop reference count - see irlmp_connect_indication(). */
648 dev_kfree_skb(tx_skb);
649 break;
650 case LM_WATCHDOG_TIMEOUT:
651 /* Will happen in some rare cases because of a race condition.
652 * Just make sure we don't stay there forever...
653 * Jean II */
654 pr_debug("%s() WATCHDOG_TIMEOUT!\n", __func__);
655
656 /* Go back to disconnected mode, keep the socket waiting */
657 self->lap = NULL;
658 self->dlsap_sel = LSAP_ANY;
659 if(self->conn_skb)
660 dev_kfree_skb(self->conn_skb);
661 self->conn_skb = NULL;
662 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
663 break;
664 default:
665 /* LM_LAP_DISCONNECT_INDICATION : Should never happen, we
666 * are *not* yet bound to the IrLAP link. Jean II */
667 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
668 __func__, irlmp_event[event], self->slsap_sel);
669 break;
670 }
671 return ret;
672 }
673
674 /*
675 * Function irlmp_state_dtr (self, event, skb)
676 *
677 * DATA_TRANSFER_READY
678 *
679 */
680 static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
681 struct sk_buff *skb)
682 {
683 LM_REASON reason;
684 int ret = 0;
685
686 IRDA_ASSERT(self != NULL, return -1;);
687 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
688 IRDA_ASSERT(self->lap != NULL, return -1;);
689
690 switch (event) {
691 case LM_DATA_REQUEST: /* Optimize for the common case */
692 irlmp_send_data_pdu(self->lap, self->dlsap_sel,
693 self->slsap_sel, FALSE, skb);
694 break;
695 case LM_DATA_INDICATION: /* Optimize for the common case */
696 irlmp_data_indication(self, skb);
697 break;
698 case LM_UDATA_REQUEST:
699 IRDA_ASSERT(skb != NULL, return -1;);
700 irlmp_send_data_pdu(self->lap, self->dlsap_sel,
701 self->slsap_sel, TRUE, skb);
702 break;
703 case LM_UDATA_INDICATION:
704 irlmp_udata_indication(self, skb);
705 break;
706 case LM_CONNECT_REQUEST:
707 pr_debug("%s(), LM_CONNECT_REQUEST, error, LSAP already connected\n",
708 __func__);
709 /* Keep state */
710 break;
711 case LM_CONNECT_RESPONSE:
712 pr_debug("%s(), LM_CONNECT_RESPONSE, error, LSAP already connected\n",
713 __func__);
714 /* Keep state */
715 break;
716 case LM_DISCONNECT_REQUEST:
717 irlmp_send_lcf_pdu(self->lap, self->dlsap_sel, self->slsap_sel,
718 DISCONNECT, skb);
719 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
720 /* Called only from irlmp_disconnect_request(), will
721 * unbind from LAP over there. Jean II */
722
723 /* Try to close the LAP connection if its still there */
724 if (self->lap) {
725 pr_debug("%s(), trying to close IrLAP\n",
726 __func__);
727 irlmp_do_lap_event(self->lap,
728 LM_LAP_DISCONNECT_REQUEST,
729 NULL);
730 }
731 break;
732 case LM_LAP_DISCONNECT_INDICATION:
733 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
734
735 reason = irlmp_convert_lap_reason(self->lap->reason);
736
737 irlmp_disconnect_indication(self, reason, NULL);
738 break;
739 case LM_DISCONNECT_INDICATION:
740 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
741
742 IRDA_ASSERT(self->lap != NULL, return -1;);
743 IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
744
745 IRDA_ASSERT(skb != NULL, return -1;);
746 IRDA_ASSERT(skb->len > 3, return -1;);
747 reason = skb->data[3];
748
749 /* Try to close the LAP connection */
750 pr_debug("%s(), trying to close IrLAP\n", __func__);
751 irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
752
753 irlmp_disconnect_indication(self, reason, skb);
754 break;
755 default:
756 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
757 __func__, irlmp_event[event], self->slsap_sel);
758 break;
759 }
760 return ret;
761 }
762
763 /*
764 * Function irlmp_state_setup (event, skb, info)
765 *
766 * SETUP, Station Control has set up the underlying IrLAP connection.
767 * An LSAP connection request has been transmitted to the peer
768 * LSAP-Connection Control FSM and we are awaiting reply.
769 */
770 static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
771 struct sk_buff *skb)
772 {
773 LM_REASON reason;
774 int ret = 0;
775
776 IRDA_ASSERT(self != NULL, return -1;);
777 IRDA_ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
778
779 switch (event) {
780 case LM_CONNECT_CONFIRM:
781 irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
782
783 del_timer(&self->watchdog_timer);
784
785 irlmp_connect_confirm(self, skb);
786 break;
787 case LM_DISCONNECT_INDICATION:
788 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
789
790 IRDA_ASSERT(self->lap != NULL, return -1;);
791 IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
792
793 IRDA_ASSERT(skb != NULL, return -1;);
794 IRDA_ASSERT(skb->len > 3, return -1;);
795 reason = skb->data[3];
796
797 /* Try to close the LAP connection */
798 pr_debug("%s(), trying to close IrLAP\n", __func__);
799 irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
800
801 irlmp_disconnect_indication(self, reason, skb);
802 break;
803 case LM_LAP_DISCONNECT_INDICATION:
804 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
805
806 del_timer(&self->watchdog_timer);
807
808 IRDA_ASSERT(self->lap != NULL, return -1;);
809 IRDA_ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
810
811 reason = irlmp_convert_lap_reason(self->lap->reason);
812
813 irlmp_disconnect_indication(self, reason, skb);
814 break;
815 case LM_WATCHDOG_TIMEOUT:
816 pr_debug("%s() WATCHDOG_TIMEOUT!\n", __func__);
817
818 IRDA_ASSERT(self->lap != NULL, return -1;);
819 irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
820 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
821
822 irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
823 break;
824 default:
825 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
826 __func__, irlmp_event[event], self->slsap_sel);
827 break;
828 }
829 return ret;
830 }
831
832 /*
833 * Function irlmp_state_setup_pend (event, skb, info)
834 *
835 * SETUP_PEND, An LM_CONNECT_REQUEST has been received from the service
836 * user to set up an LSAP connection. A request has been sent to the
837 * LAP FSM to set up the underlying IrLAP connection, and we
838 * are awaiting confirm.
839 */
840 static int irlmp_state_setup_pend(struct lsap_cb *self, IRLMP_EVENT event,
841 struct sk_buff *skb)
842 {
843 struct sk_buff *tx_skb;
844 LM_REASON reason;
845 int ret = 0;
846
847 IRDA_ASSERT(self != NULL, return -1;);
848 IRDA_ASSERT(irlmp != NULL, return -1;);
849
850 switch (event) {
851 case LM_LAP_CONNECT_CONFIRM:
852 IRDA_ASSERT(self->conn_skb != NULL, return -1;);
853
854 tx_skb = self->conn_skb;
855 self->conn_skb = NULL;
856
857 irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
858 self->slsap_sel, CONNECT_CMD, tx_skb);
859 /* Drop reference count - see irlap_data_request(). */
860 dev_kfree_skb(tx_skb);
861
862 irlmp_next_lsap_state(self, LSAP_SETUP);
863 break;
864 case LM_WATCHDOG_TIMEOUT:
865 pr_debug("%s() : WATCHDOG_TIMEOUT !\n", __func__);
866
867 IRDA_ASSERT(self->lap != NULL, return -1;);
868 irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
869 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
870
871 irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
872 break;
873 case LM_LAP_DISCONNECT_INDICATION: /* LS_Disconnect.indication */
874 del_timer( &self->watchdog_timer);
875
876 irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
877
878 reason = irlmp_convert_lap_reason(self->lap->reason);
879
880 irlmp_disconnect_indication(self, reason, NULL);
881 break;
882 default:
883 pr_debug("%s(), Unknown event %s on LSAP %#02x\n",
884 __func__, irlmp_event[event], self->slsap_sel);
885 break;
886 }
887 return ret;
888 }
This page took 0.051213 seconds and 5 git commands to generate.