OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [irda/] [irlmp_event.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/*********************************************************************
/*********************************************************************
 *
 *
 * Filename:      irlmp_event.c
 * Filename:      irlmp_event.c
 * Version:       0.8
 * Version:       0.8
 * Description:   An IrDA LMP event driver for Linux
 * Description:   An IrDA LMP event driver for Linux
 * Status:        Experimental.
 * Status:        Experimental.
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Mon Aug  4 20:40:53 1997
 * Created at:    Mon Aug  4 20:40:53 1997
 * Modified at:   Tue Dec 14 23:04:16 1999
 * Modified at:   Tue Dec 14 23:04:16 1999
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 *
 *
 *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
 *     Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
 *     All Rights Reserved.
 *     All Rights Reserved.
 *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
 *     Copyright (c) 2000-2001 Jean Tourrilhes <jt@hpl.hp.com>
 *
 *
 *     This program is free software; you can redistribute it and/or
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
 *     published by the Free Software Foundation; either version 2 of
 *     the License, or (at your option) any later version.
 *     the License, or (at your option) any later version.
 *
 *
 *     Neither Dag Brattli nor University of Tromsø admit liability nor
 *     Neither Dag Brattli nor University of Tromsø admit liability nor
 *     provide warranty for any of this software. This material is
 *     provide warranty for any of this software. This material is
 *     provided "AS-IS" and at no charge.
 *     provided "AS-IS" and at no charge.
 *
 *
 ********************************************************************/
 ********************************************************************/
 
 
#include <linux/config.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
 
 
#include <net/irda/irda.h>
#include <net/irda/irda.h>
#include <net/irda/timer.h>
#include <net/irda/timer.h>
#include <net/irda/irlap.h>
#include <net/irda/irlap.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp_frame.h>
#include <net/irda/irlmp_frame.h>
#include <net/irda/irlmp_event.h>
#include <net/irda/irlmp_event.h>
 
 
const char *irlmp_state[] = {
const char *irlmp_state[] = {
        "LAP_STANDBY",
        "LAP_STANDBY",
        "LAP_U_CONNECT",
        "LAP_U_CONNECT",
        "LAP_ACTIVE",
        "LAP_ACTIVE",
};
};
 
 
const char *irlsap_state[] = {
const char *irlsap_state[] = {
        "LSAP_DISCONNECTED",
        "LSAP_DISCONNECTED",
        "LSAP_CONNECT",
        "LSAP_CONNECT",
        "LSAP_CONNECT_PEND",
        "LSAP_CONNECT_PEND",
        "LSAP_DATA_TRANSFER_READY",
        "LSAP_DATA_TRANSFER_READY",
        "LSAP_SETUP",
        "LSAP_SETUP",
        "LSAP_SETUP_PEND",
        "LSAP_SETUP_PEND",
};
};
 
 
#ifdef CONFIG_IRDA_DEBUG
#ifdef CONFIG_IRDA_DEBUG
static const char *irlmp_event[] = {
static const char *irlmp_event[] = {
        "LM_CONNECT_REQUEST",
        "LM_CONNECT_REQUEST",
        "LM_CONNECT_CONFIRM",
        "LM_CONNECT_CONFIRM",
        "LM_CONNECT_RESPONSE",
        "LM_CONNECT_RESPONSE",
        "LM_CONNECT_INDICATION",
        "LM_CONNECT_INDICATION",
 
 
        "LM_DISCONNECT_INDICATION",
        "LM_DISCONNECT_INDICATION",
        "LM_DISCONNECT_REQUEST",
        "LM_DISCONNECT_REQUEST",
 
 
        "LM_DATA_REQUEST",
        "LM_DATA_REQUEST",
        "LM_UDATA_REQUEST",
        "LM_UDATA_REQUEST",
        "LM_DATA_INDICATION",
        "LM_DATA_INDICATION",
        "LM_UDATA_INDICATION",
        "LM_UDATA_INDICATION",
 
 
        "LM_WATCHDOG_TIMEOUT",
        "LM_WATCHDOG_TIMEOUT",
 
 
        /* IrLAP events */
        /* IrLAP events */
        "LM_LAP_CONNECT_REQUEST",
        "LM_LAP_CONNECT_REQUEST",
        "LM_LAP_CONNECT_INDICATION",
        "LM_LAP_CONNECT_INDICATION",
        "LM_LAP_CONNECT_CONFIRM",
        "LM_LAP_CONNECT_CONFIRM",
        "LM_LAP_DISCONNECT_INDICATION",
        "LM_LAP_DISCONNECT_INDICATION",
        "LM_LAP_DISCONNECT_REQUEST",
        "LM_LAP_DISCONNECT_REQUEST",
        "LM_LAP_DISCOVERY_REQUEST",
        "LM_LAP_DISCOVERY_REQUEST",
        "LM_LAP_DISCOVERY_CONFIRM",
        "LM_LAP_DISCOVERY_CONFIRM",
        "LM_LAP_IDLE_TIMEOUT",
        "LM_LAP_IDLE_TIMEOUT",
};
};
#endif  /* CONFIG_IRDA_DEBUG */
#endif  /* CONFIG_IRDA_DEBUG */
 
 
/* LAP Connection control proto declarations */
/* LAP Connection control proto declarations */
static void irlmp_state_standby  (struct lap_cb *, IRLMP_EVENT,
static void irlmp_state_standby  (struct lap_cb *, IRLMP_EVENT,
                                  struct sk_buff *);
                                  struct sk_buff *);
static void irlmp_state_u_connect(struct lap_cb *, IRLMP_EVENT,
static void irlmp_state_u_connect(struct lap_cb *, IRLMP_EVENT,
                                  struct sk_buff *);
                                  struct sk_buff *);
static void irlmp_state_active   (struct lap_cb *, IRLMP_EVENT,
static void irlmp_state_active   (struct lap_cb *, IRLMP_EVENT,
                                  struct sk_buff *);
                                  struct sk_buff *);
 
 
/* LSAP Connection control proto declarations */
/* LSAP Connection control proto declarations */
static int irlmp_state_disconnected(struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_disconnected(struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
static int irlmp_state_connect     (struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_connect     (struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
static int irlmp_state_connect_pend(struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_connect_pend(struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
static int irlmp_state_dtr         (struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_dtr         (struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
static int irlmp_state_setup       (struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_setup       (struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
static int irlmp_state_setup_pend  (struct lsap_cb *, IRLMP_EVENT,
static int irlmp_state_setup_pend  (struct lsap_cb *, IRLMP_EVENT,
                                    struct sk_buff *);
                                    struct sk_buff *);
 
 
static void (*lap_state[]) (struct lap_cb *, IRLMP_EVENT, struct sk_buff *) =
static void (*lap_state[]) (struct lap_cb *, IRLMP_EVENT, struct sk_buff *) =
{
{
        irlmp_state_standby,
        irlmp_state_standby,
        irlmp_state_u_connect,
        irlmp_state_u_connect,
        irlmp_state_active,
        irlmp_state_active,
};
};
 
 
static int (*lsap_state[])( struct lsap_cb *, IRLMP_EVENT, struct sk_buff *) =
static int (*lsap_state[])( struct lsap_cb *, IRLMP_EVENT, struct sk_buff *) =
{
{
        irlmp_state_disconnected,
        irlmp_state_disconnected,
        irlmp_state_connect,
        irlmp_state_connect,
        irlmp_state_connect_pend,
        irlmp_state_connect_pend,
        irlmp_state_dtr,
        irlmp_state_dtr,
        irlmp_state_setup,
        irlmp_state_setup,
        irlmp_state_setup_pend
        irlmp_state_setup_pend
};
};
 
 
static inline void irlmp_next_lap_state(struct lap_cb *self,
static inline void irlmp_next_lap_state(struct lap_cb *self,
                                        IRLMP_STATE state)
                                        IRLMP_STATE state)
{
{
        /*
        /*
        IRDA_DEBUG(4, "%s(), LMP LAP = %s\n", __FUNCTION__, irlmp_state[state]);
        IRDA_DEBUG(4, "%s(), LMP LAP = %s\n", __FUNCTION__, irlmp_state[state]);
        */
        */
        self->lap_state = state;
        self->lap_state = state;
}
}
 
 
static inline void irlmp_next_lsap_state(struct lsap_cb *self,
static inline void irlmp_next_lsap_state(struct lsap_cb *self,
                                         LSAP_STATE state)
                                         LSAP_STATE state)
{
{
        /*
        /*
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        IRDA_DEBUG(4, "%s(), LMP LSAP = %s\n", __FUNCTION__, irlsap_state[state]);
        IRDA_DEBUG(4, "%s(), LMP LSAP = %s\n", __FUNCTION__, irlsap_state[state]);
        */
        */
        self->lsap_state = state;
        self->lsap_state = state;
}
}
 
 
/* Do connection control events */
/* Do connection control events */
int irlmp_do_lsap_event(struct lsap_cb *self, IRLMP_EVENT event,
int irlmp_do_lsap_event(struct lsap_cb *self, IRLMP_EVENT event,
                        struct sk_buff *skb)
                        struct sk_buff *skb)
{
{
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
 
 
        IRDA_DEBUG(4, "%s(), EVENT = %s, STATE = %s\n",
        IRDA_DEBUG(4, "%s(), EVENT = %s, STATE = %s\n",
                __FUNCTION__, irlmp_event[event], irlsap_state[ self->lsap_state]);
                __FUNCTION__, irlmp_event[event], irlsap_state[ self->lsap_state]);
 
 
        return (*lsap_state[self->lsap_state]) (self, event, skb);
        return (*lsap_state[self->lsap_state]) (self, event, skb);
}
}
 
 
/*
/*
 * Function do_lap_event (event, skb, info)
 * Function do_lap_event (event, skb, info)
 *
 *
 *    Do IrLAP control events
 *    Do IrLAP control events
 *
 *
 */
 */
void irlmp_do_lap_event(struct lap_cb *self, IRLMP_EVENT event,
void irlmp_do_lap_event(struct lap_cb *self, IRLMP_EVENT event,
                        struct sk_buff *skb)
                        struct sk_buff *skb)
{
{
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == LMP_LAP_MAGIC, return;);
        ASSERT(self->magic == LMP_LAP_MAGIC, return;);
 
 
        IRDA_DEBUG(4, "%s(), EVENT = %s, STATE = %s\n",
        IRDA_DEBUG(4, "%s(), EVENT = %s, STATE = %s\n",
                __FUNCTION__, irlmp_event[event],
                __FUNCTION__, irlmp_event[event],
                irlmp_state[self->lap_state]);
                irlmp_state[self->lap_state]);
 
 
        (*lap_state[self->lap_state]) (self, event, skb);
        (*lap_state[self->lap_state]) (self, event, skb);
}
}
 
 
void irlmp_discovery_timer_expired(void *data)
void irlmp_discovery_timer_expired(void *data)
{
{
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        /* We always cleanup the log (active & passive discovery) */
        /* We always cleanup the log (active & passive discovery) */
        irlmp_do_expiry();
        irlmp_do_expiry();
 
 
        /* Active discovery is conditional */
        /* Active discovery is conditional */
        if (sysctl_discovery)
        if (sysctl_discovery)
                irlmp_do_discovery(sysctl_discovery_slots);
                irlmp_do_discovery(sysctl_discovery_slots);
 
 
        /* Restart timer */
        /* Restart timer */
        irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout * HZ);
        irlmp_start_discovery_timer(irlmp, sysctl_discovery_timeout * HZ);
}
}
 
 
void irlmp_watchdog_timer_expired(void *data)
void irlmp_watchdog_timer_expired(void *data)
{
{
        struct lsap_cb *self = (struct lsap_cb *) data;
        struct lsap_cb *self = (struct lsap_cb *) data;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return;);
 
 
        irlmp_do_lsap_event(self, LM_WATCHDOG_TIMEOUT, NULL);
        irlmp_do_lsap_event(self, LM_WATCHDOG_TIMEOUT, NULL);
}
}
 
 
void irlmp_idle_timer_expired(void *data)
void irlmp_idle_timer_expired(void *data)
{
{
        struct lap_cb *self = (struct lap_cb *) data;
        struct lap_cb *self = (struct lap_cb *) data;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == LMP_LAP_MAGIC, return;);
        ASSERT(self->magic == LMP_LAP_MAGIC, return;);
 
 
        irlmp_do_lap_event(self, LM_LAP_IDLE_TIMEOUT, NULL);
        irlmp_do_lap_event(self, LM_LAP_IDLE_TIMEOUT, NULL);
}
}
 
 
/*********************************************************************
/*********************************************************************
 *
 *
 *    LAP connection control states
 *    LAP connection control states
 *
 *
 ********************************************************************/
 ********************************************************************/
 
 
/*
/*
 * Function irlmp_state_standby (event, skb, info)
 * Function irlmp_state_standby (event, skb, info)
 *
 *
 *    STANDBY, The IrLAP connection does not exist.
 *    STANDBY, The IrLAP connection does not exist.
 *
 *
 */
 */
static void irlmp_state_standby(struct lap_cb *self, IRLMP_EVENT event,
static void irlmp_state_standby(struct lap_cb *self, IRLMP_EVENT event,
                                struct sk_buff *skb)
                                struct sk_buff *skb)
{
{
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        ASSERT(self->irlap != NULL, return;);
        ASSERT(self->irlap != NULL, return;);
 
 
        switch (event) {
        switch (event) {
        case LM_LAP_DISCOVERY_REQUEST:
        case LM_LAP_DISCOVERY_REQUEST:
                /* irlmp_next_station_state( LMP_DISCOVER); */
                /* irlmp_next_station_state( LMP_DISCOVER); */
 
 
                irlap_discovery_request(self->irlap, &irlmp->discovery_cmd);
                irlap_discovery_request(self->irlap, &irlmp->discovery_cmd);
                break;
                break;
        case LM_LAP_CONNECT_INDICATION:
        case LM_LAP_CONNECT_INDICATION:
                /*  It's important to switch state first, to avoid IrLMP to
                /*  It's important to switch state first, to avoid IrLMP to
                 *  think that the link is free since IrLMP may then start
                 *  think that the link is free since IrLMP may then start
                 *  discovery before the connection is properly set up. DB.
                 *  discovery before the connection is properly set up. DB.
                 */
                 */
                irlmp_next_lap_state(self, LAP_ACTIVE);
                irlmp_next_lap_state(self, LAP_ACTIVE);
 
 
                /* Just accept connection TODO, this should be fixed */
                /* Just accept connection TODO, this should be fixed */
                irlap_connect_response(self->irlap, skb);
                irlap_connect_response(self->irlap, skb);
                break;
                break;
        case LM_LAP_CONNECT_REQUEST:
        case LM_LAP_CONNECT_REQUEST:
                IRDA_DEBUG(4, "%s() LS_CONNECT_REQUEST\n", __FUNCTION__);
                IRDA_DEBUG(4, "%s() LS_CONNECT_REQUEST\n", __FUNCTION__);
 
 
                irlmp_next_lap_state(self, LAP_U_CONNECT);
                irlmp_next_lap_state(self, LAP_U_CONNECT);
 
 
                /* FIXME: need to set users requested QoS */
                /* FIXME: need to set users requested QoS */
                irlap_connect_request(self->irlap, self->daddr, NULL, 0);
                irlap_connect_request(self->irlap, self->daddr, NULL, 0);
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION:
        case LM_LAP_DISCONNECT_INDICATION:
                IRDA_DEBUG(4, "%s(), Error LM_LAP_DISCONNECT_INDICATION\n", __FUNCTION__);
                IRDA_DEBUG(4, "%s(), Error LM_LAP_DISCONNECT_INDICATION\n", __FUNCTION__);
 
 
                irlmp_next_lap_state(self, LAP_STANDBY);
                irlmp_next_lap_state(self, LAP_STANDBY);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s\n", __FUNCTION__, irlmp_event[event]);
                IRDA_DEBUG(0, "%s(), Unknown event %s\n", __FUNCTION__, irlmp_event[event]);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
}
}
 
 
/*
/*
 * Function irlmp_state_u_connect (event, skb, info)
 * Function irlmp_state_u_connect (event, skb, info)
 *
 *
 *    U_CONNECT, The layer above has tried to open an LSAP connection but
 *    U_CONNECT, The layer above has tried to open an LSAP connection but
 *    since the IrLAP connection does not exist, we must first start an
 *    since the IrLAP connection does not exist, we must first start an
 *    IrLAP connection. We are now waiting response from IrLAP.
 *    IrLAP connection. We are now waiting response from IrLAP.
 * */
 * */
static void irlmp_state_u_connect(struct lap_cb *self, IRLMP_EVENT event,
static void irlmp_state_u_connect(struct lap_cb *self, IRLMP_EVENT event,
                                  struct sk_buff *skb)
                                  struct sk_buff *skb)
{
{
        struct lsap_cb *lsap;
        struct lsap_cb *lsap;
        struct lsap_cb *lsap_current;
        struct lsap_cb *lsap_current;
 
 
        IRDA_DEBUG(2, "%s(), event=%s\n",  __FUNCTION__, irlmp_event[event]);
        IRDA_DEBUG(2, "%s(), event=%s\n",  __FUNCTION__, irlmp_event[event]);
 
 
        switch (event) {
        switch (event) {
        case LM_LAP_CONNECT_INDICATION:
        case LM_LAP_CONNECT_INDICATION:
                /*  It's important to switch state first, to avoid IrLMP to
                /*  It's important to switch state first, to avoid IrLMP to
                 *  think that the link is free since IrLMP may then start
                 *  think that the link is free since IrLMP may then start
                 *  discovery before the connection is properly set up. DB.
                 *  discovery before the connection is properly set up. DB.
                 */
                 */
                irlmp_next_lap_state(self, LAP_ACTIVE);
                irlmp_next_lap_state(self, LAP_ACTIVE);
 
 
                /* Just accept connection TODO, this should be fixed */
                /* Just accept connection TODO, this should be fixed */
                irlap_connect_response(self->irlap, skb);
                irlap_connect_response(self->irlap, skb);
 
 
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                while (lsap != NULL) {
                while (lsap != NULL) {
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                }
                }
                /* Note : by the time we get there (LAP retries and co),
                /* Note : by the time we get there (LAP retries and co),
                 * the lsaps may already have gone. This avoid getting stuck
                 * the lsaps may already have gone. This avoid getting stuck
                 * forever in LAP_ACTIVE state - Jean II */
                 * forever in LAP_ACTIVE state - Jean II */
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                        IRDA_DEBUG(0, "%s() NO LSAPs !\n",  __FUNCTION__);
                        IRDA_DEBUG(0, "%s() NO LSAPs !\n",  __FUNCTION__);
                        irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
                        irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
                }
                }
                break;
                break;
        case LM_LAP_CONNECT_REQUEST:
        case LM_LAP_CONNECT_REQUEST:
                /* Already trying to connect */
                /* Already trying to connect */
                break;
                break;
        case LM_LAP_CONNECT_CONFIRM:
        case LM_LAP_CONNECT_CONFIRM:
                /* For all lsap_ce E Associated do LS_Connect_confirm */
                /* For all lsap_ce E Associated do LS_Connect_confirm */
                irlmp_next_lap_state(self, LAP_ACTIVE);
                irlmp_next_lap_state(self, LAP_ACTIVE);
 
 
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                while (lsap != NULL) {
                while (lsap != NULL) {
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                }
                }
                /* Note : by the time we get there (LAP retries and co),
                /* Note : by the time we get there (LAP retries and co),
                 * the lsaps may already have gone. This avoid getting stuck
                 * the lsaps may already have gone. This avoid getting stuck
                 * forever in LAP_ACTIVE state - Jean II */
                 * forever in LAP_ACTIVE state - Jean II */
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                        IRDA_DEBUG(0, "%s() NO LSAPs !\n",  __FUNCTION__);
                        IRDA_DEBUG(0, "%s() NO LSAPs !\n",  __FUNCTION__);
                        irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
                        irlmp_start_idle_timer(self, LM_IDLE_TIMEOUT);
                }
                }
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION:
        case LM_LAP_DISCONNECT_INDICATION:
                IRDA_DEBUG(4, "%s(), LM_LAP_DISCONNECT_INDICATION\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), LM_LAP_DISCONNECT_INDICATION\n",  __FUNCTION__);
                irlmp_next_lap_state(self, LAP_STANDBY);
                irlmp_next_lap_state(self, LAP_STANDBY);
 
 
                /* Send disconnect event to all LSAPs using this link */
                /* Send disconnect event to all LSAPs using this link */
                lsap = (struct lsap_cb *) hashbin_get_first( self->lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first( self->lsaps);
                while (lsap != NULL ) {
                while (lsap != NULL ) {
                        ASSERT(lsap->magic == LMP_LSAP_MAGIC, return;);
                        ASSERT(lsap->magic == LMP_LSAP_MAGIC, return;);
 
 
                        lsap_current = lsap;
                        lsap_current = lsap;
 
 
                        /* Be sure to stay one item ahead */
                        /* Be sure to stay one item ahead */
                        lsap = (struct lsap_cb *) hashbin_get_next(self->lsaps);
                        lsap = (struct lsap_cb *) hashbin_get_next(self->lsaps);
                        irlmp_do_lsap_event(lsap_current,
                        irlmp_do_lsap_event(lsap_current,
                                            LM_LAP_DISCONNECT_INDICATION,
                                            LM_LAP_DISCONNECT_INDICATION,
                                            NULL);
                                            NULL);
                }
                }
                break;
                break;
        case LM_LAP_DISCONNECT_REQUEST:
        case LM_LAP_DISCONNECT_REQUEST:
                IRDA_DEBUG(4, "%s(), LM_LAP_DISCONNECT_REQUEST\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), LM_LAP_DISCONNECT_REQUEST\n",  __FUNCTION__);
 
 
                /* One of the LSAP did timeout or was closed, if it was
                /* One of the LSAP did timeout or was closed, if it was
                 * the last one, try to get out of here - Jean II */
                 * the last one, try to get out of here - Jean II */
                if (HASHBIN_GET_SIZE(self->lsaps) <= 1) {
                if (HASHBIN_GET_SIZE(self->lsaps) <= 1) {
                        irlap_disconnect_request(self->irlap);
                        irlap_disconnect_request(self->irlap);
                }
                }
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s\n",
                         __FUNCTION__, irlmp_event[event]);
                         __FUNCTION__, irlmp_event[event]);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
}
}
 
 
/*
/*
 * Function irlmp_state_active (event, skb, info)
 * Function irlmp_state_active (event, skb, info)
 *
 *
 *    ACTIVE, IrLAP connection is active
 *    ACTIVE, IrLAP connection is active
 *
 *
 */
 */
static void irlmp_state_active(struct lap_cb *self, IRLMP_EVENT event,
static void irlmp_state_active(struct lap_cb *self, IRLMP_EVENT event,
                               struct sk_buff *skb)
                               struct sk_buff *skb)
{
{
        struct lsap_cb *lsap;
        struct lsap_cb *lsap;
        struct lsap_cb *lsap_current;
        struct lsap_cb *lsap_current;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        switch (event) {
        switch (event) {
        case LM_LAP_CONNECT_REQUEST:
        case LM_LAP_CONNECT_REQUEST:
                IRDA_DEBUG(4, "%s(), LS_CONNECT_REQUEST\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), LS_CONNECT_REQUEST\n",  __FUNCTION__);
 
 
                /*
                /*
                 *  LAP connection allready active, just bounce back! Since we
                 *  LAP connection allready active, just bounce back! Since we
                 *  don't know which LSAP that tried to do this, we have to
                 *  don't know which LSAP that tried to do this, we have to
                 *  notify all LSAPs using this LAP, but that should be safe to
                 *  notify all LSAPs using this LAP, but that should be safe to
                 *  do anyway.
                 *  do anyway.
                 */
                 */
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                while (lsap != NULL) {
                while (lsap != NULL) {
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        irlmp_do_lsap_event(lsap, LM_LAP_CONNECT_CONFIRM, NULL);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                        lsap = (struct lsap_cb*) hashbin_get_next(self->lsaps);
                }
                }
 
 
                /* Needed by connect indication */
                /* Needed by connect indication */
                lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first(irlmp->unconnected_lsaps);
                while (lsap != NULL) {
                while (lsap != NULL) {
                        lsap_current = lsap;
                        lsap_current = lsap;
 
 
                        /* Be sure to stay one item ahead */
                        /* Be sure to stay one item ahead */
                        lsap = (struct lsap_cb*) hashbin_get_next(irlmp->unconnected_lsaps);
                        lsap = (struct lsap_cb*) hashbin_get_next(irlmp->unconnected_lsaps);
                        irlmp_do_lsap_event(lsap_current,
                        irlmp_do_lsap_event(lsap_current,
                                            LM_LAP_CONNECT_CONFIRM, NULL);
                                            LM_LAP_CONNECT_CONFIRM, NULL);
                }
                }
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_LAP_DISCONNECT_REQUEST:
        case LM_LAP_DISCONNECT_REQUEST:
                /*
                /*
                 *  Need to find out if we should close IrLAP or not. If there
                 *  Need to find out if we should close IrLAP or not. If there
                 *  is only one LSAP connection left on this link, that LSAP
                 *  is only one LSAP connection left on this link, that LSAP
                 *  must be the one that tries to close IrLAP. It will be
                 *  must be the one that tries to close IrLAP. It will be
                 *  removed later and moved to the list of unconnected LSAPs
                 *  removed later and moved to the list of unconnected LSAPs
                 */
                 */
                if (HASHBIN_GET_SIZE(self->lsaps) > 0) {
                if (HASHBIN_GET_SIZE(self->lsaps) > 0) {
                        /* Timer value is checked in irsysctl - Jean II */
                        /* Timer value is checked in irsysctl - Jean II */
                        irlmp_start_idle_timer(self, sysctl_lap_keepalive_time * HZ / 1000);
                        irlmp_start_idle_timer(self, sysctl_lap_keepalive_time * HZ / 1000);
                } else {
                } else {
                        /* No more connections, so close IrLAP */
                        /* No more connections, so close IrLAP */
 
 
                        /* We don't want to change state just yet, because
                        /* We don't want to change state just yet, because
                         * we want to reflect accurately the real state of
                         * we want to reflect accurately the real state of
                         * the LAP, not the state we wish it was in,
                         * the LAP, not the state we wish it was in,
                         * so that we don't loose LM_LAP_CONNECT_REQUEST.
                         * so that we don't loose LM_LAP_CONNECT_REQUEST.
                         * In some cases, IrLAP won't close the LAP
                         * In some cases, IrLAP won't close the LAP
                         * immediately. For example, it might still be
                         * immediately. For example, it might still be
                         * retrying packets or waiting for the pf bit.
                         * retrying packets or waiting for the pf bit.
                         * As the LAP always send a DISCONNECT_INDICATION
                         * As the LAP always send a DISCONNECT_INDICATION
                         * in PCLOSE or SCLOSE, just change state on that.
                         * in PCLOSE or SCLOSE, just change state on that.
                         * Jean II */
                         * Jean II */
                        irlap_disconnect_request(self->irlap);
                        irlap_disconnect_request(self->irlap);
                }
                }
                break;
                break;
        case LM_LAP_IDLE_TIMEOUT:
        case LM_LAP_IDLE_TIMEOUT:
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                if (HASHBIN_GET_SIZE(self->lsaps) == 0) {
                        /* Same reasoning as above - keep state */
                        /* Same reasoning as above - keep state */
                        irlap_disconnect_request(self->irlap);
                        irlap_disconnect_request(self->irlap);
                }
                }
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION:
        case LM_LAP_DISCONNECT_INDICATION:
                irlmp_next_lap_state(self, LAP_STANDBY);
                irlmp_next_lap_state(self, LAP_STANDBY);
 
 
                /* In some case, at this point our side has already closed
                /* In some case, at this point our side has already closed
                 * all lsaps, and we are waiting for the idle_timer to
                 * all lsaps, and we are waiting for the idle_timer to
                 * expire. If another device reconnect immediately, the
                 * expire. If another device reconnect immediately, the
                 * idle timer will expire in the midle of the connection
                 * idle timer will expire in the midle of the connection
                 * initialisation, screwing up things a lot...
                 * initialisation, screwing up things a lot...
                 * Therefore, we must stop the timer... */
                 * Therefore, we must stop the timer... */
                irlmp_stop_idle_timer(self);
                irlmp_stop_idle_timer(self);
 
 
                /*
                /*
                 *  Inform all connected LSAP's using this link
                 *  Inform all connected LSAP's using this link
                 */
                 */
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                lsap = (struct lsap_cb *) hashbin_get_first(self->lsaps);
                while (lsap != NULL ) {
                while (lsap != NULL ) {
                        ASSERT(lsap->magic == LMP_LSAP_MAGIC, return;);
                        ASSERT(lsap->magic == LMP_LSAP_MAGIC, return;);
 
 
                        lsap_current = lsap;
                        lsap_current = lsap;
 
 
                        /* Be sure to stay one item ahead */
                        /* Be sure to stay one item ahead */
                        lsap = (struct lsap_cb *) hashbin_get_next(self->lsaps);
                        lsap = (struct lsap_cb *) hashbin_get_next(self->lsaps);
                        irlmp_do_lsap_event(lsap_current,
                        irlmp_do_lsap_event(lsap_current,
                                            LM_LAP_DISCONNECT_INDICATION,
                                            LM_LAP_DISCONNECT_INDICATION,
                                            NULL);
                                            NULL);
                }
                }
 
 
                /* Force an expiry of the discovery log.
                /* Force an expiry of the discovery log.
                 * Now that the LAP is free, the system may attempt to
                 * Now that the LAP is free, the system may attempt to
                 * connect to another device. Unfortunately, our entries
                 * connect to another device. Unfortunately, our entries
                 * are stale. There is a small window (<3s) before the
                 * are stale. There is a small window (<3s) before the
                 * normal discovery will run and where irlmp_connect_request()
                 * normal discovery will run and where irlmp_connect_request()
                 * can get the wrong info, so make sure things get
                 * can get the wrong info, so make sure things get
                 * cleaned *NOW* ;-) - Jean II */
                 * cleaned *NOW* ;-) - Jean II */
                irlmp_do_expiry();
                irlmp_do_expiry();
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s\n",
                         __FUNCTION__, irlmp_event[event]);
                         __FUNCTION__, irlmp_event[event]);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
}
}
 
 
/*********************************************************************
/*********************************************************************
 *
 *
 *    LSAP connection control states
 *    LSAP connection control states
 *
 *
 ********************************************************************/
 ********************************************************************/
 
 
/*
/*
 * Function irlmp_state_disconnected (event, skb, info)
 * Function irlmp_state_disconnected (event, skb, info)
 *
 *
 *    DISCONNECTED
 *    DISCONNECTED
 *
 *
 */
 */
static int irlmp_state_disconnected(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_disconnected(struct lsap_cb *self, IRLMP_EVENT event,
                                    struct sk_buff *skb)
                                    struct sk_buff *skb)
{
{
        int ret = 0;
        int ret = 0;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
 
 
        switch (event) {
        switch (event) {
#ifdef CONFIG_IRDA_ULTRA
#ifdef CONFIG_IRDA_ULTRA
        case LM_UDATA_INDICATION:
        case LM_UDATA_INDICATION:
                irlmp_connless_data_indication(self, skb);
                irlmp_connless_data_indication(self, skb);
                break;
                break;
#endif /* CONFIG_IRDA_ULTRA */
#endif /* CONFIG_IRDA_ULTRA */
        case LM_CONNECT_REQUEST:
        case LM_CONNECT_REQUEST:
                IRDA_DEBUG(4, "%s(), LM_CONNECT_REQUEST\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), LM_CONNECT_REQUEST\n",  __FUNCTION__);
 
 
                if (self->conn_skb) {
                if (self->conn_skb) {
                        WARNING("%s(), busy with another request!\n",  __FUNCTION__);
                        WARNING("%s(), busy with another request!\n",  __FUNCTION__);
                        return -EBUSY;
                        return -EBUSY;
                }
                }
                self->conn_skb = skb;
                self->conn_skb = skb;
 
 
                irlmp_next_lsap_state(self, LSAP_SETUP_PEND);
                irlmp_next_lsap_state(self, LSAP_SETUP_PEND);
 
 
                /* Start watchdog timer (5 secs for now) */
                /* Start watchdog timer (5 secs for now) */
                irlmp_start_watchdog_timer(self, 5*HZ);
                irlmp_start_watchdog_timer(self, 5*HZ);
 
 
                irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
                break;
                break;
        case LM_CONNECT_INDICATION:
        case LM_CONNECT_INDICATION:
                if (self->conn_skb) {
                if (self->conn_skb) {
                        WARNING("%s(), busy with another request!\n",  __FUNCTION__);
                        WARNING("%s(), busy with another request!\n",  __FUNCTION__);
                        return -EBUSY;
                        return -EBUSY;
                }
                }
                self->conn_skb = skb;
                self->conn_skb = skb;
 
 
                irlmp_next_lsap_state(self, LSAP_CONNECT_PEND);
                irlmp_next_lsap_state(self, LSAP_CONNECT_PEND);
 
 
                /* Start watchdog timer
                /* Start watchdog timer
                 * This is not mentionned in the spec, but there is a rare
                 * This is not mentionned in the spec, but there is a rare
                 * race condition that can get the socket stuck.
                 * race condition that can get the socket stuck.
                 * If we receive this event while our LAP is closing down,
                 * If we receive this event while our LAP is closing down,
                 * the LM_LAP_CONNECT_REQUEST get lost and we get stuck in
                 * the LM_LAP_CONNECT_REQUEST get lost and we get stuck in
                 * CONNECT_PEND state forever.
                 * CONNECT_PEND state forever.
                 * The other cause of getting stuck down there is if the
                 * The other cause of getting stuck down there is if the
                 * higher layer never reply to the CONNECT_INDICATION.
                 * higher layer never reply to the CONNECT_INDICATION.
                 * Anyway, it make sense to make sure that we always have
                 * Anyway, it make sense to make sure that we always have
                 * a backup plan. 1 second is plenty (should be immediate).
                 * a backup plan. 1 second is plenty (should be immediate).
                 * Jean II */
                 * Jean II */
                irlmp_start_watchdog_timer(self, 1*HZ);
                irlmp_start_watchdog_timer(self, 1*HZ);
 
 
                irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_CONNECT_REQUEST, NULL);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(1, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(1, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 
/*
/*
 * Function irlmp_state_connect (self, event, skb)
 * Function irlmp_state_connect (self, event, skb)
 *
 *
 *    CONNECT
 *    CONNECT
 *
 *
 */
 */
static int irlmp_state_connect(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_connect(struct lsap_cb *self, IRLMP_EVENT event,
                                struct sk_buff *skb)
                                struct sk_buff *skb)
{
{
        struct lsap_cb *lsap;
        struct lsap_cb *lsap;
        int ret = 0;
        int ret = 0;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
 
 
        switch (event) {
        switch (event) {
        case LM_CONNECT_RESPONSE:
        case LM_CONNECT_RESPONSE:
                /*
                /*
                 *  Bind this LSAP to the IrLAP link where the connect was
                 *  Bind this LSAP to the IrLAP link where the connect was
                 *  received
                 *  received
                 */
                 */
                lsap = hashbin_remove(irlmp->unconnected_lsaps, (int) self,
                lsap = hashbin_remove(irlmp->unconnected_lsaps, (int) self,
                                      NULL);
                                      NULL);
 
 
                ASSERT(lsap == self, return -1;);
                ASSERT(lsap == self, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap->lsaps != NULL, return -1;);
                ASSERT(self->lap->lsaps != NULL, return -1;);
 
 
                hashbin_insert(self->lap->lsaps, (irda_queue_t *) self, (int) self,
                hashbin_insert(self->lap->lsaps, (irda_queue_t *) self, (int) self,
                               NULL);
                               NULL);
 
 
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
                                   self->slsap_sel, CONNECT_CNF, skb);
                                   self->slsap_sel, CONNECT_CNF, skb);
 
 
                del_timer(&self->watchdog_timer);
                del_timer(&self->watchdog_timer);
 
 
                irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
                irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
                break;
                break;
        case LM_WATCHDOG_TIMEOUT:
        case LM_WATCHDOG_TIMEOUT:
                /* May happen, who knows...
                /* May happen, who knows...
                 * Jean II */
                 * Jean II */
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
 
 
                /* Disconnect, get out... - Jean II */
                /* Disconnect, get out... - Jean II */
                self->dlsap_sel = LSAP_ANY;
                self->dlsap_sel = LSAP_ANY;
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 
/*
/*
 * Function irlmp_state_connect_pend (event, skb, info)
 * Function irlmp_state_connect_pend (event, skb, info)
 *
 *
 *    CONNECT_PEND
 *    CONNECT_PEND
 *
 *
 */
 */
static int irlmp_state_connect_pend(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_connect_pend(struct lsap_cb *self, IRLMP_EVENT event,
                                    struct sk_buff *skb)
                                    struct sk_buff *skb)
{
{
        int ret = 0;
        int ret = 0;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
 
 
        switch (event) {
        switch (event) {
        case LM_CONNECT_REQUEST:
        case LM_CONNECT_REQUEST:
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_CONNECT_RESPONSE:
        case LM_CONNECT_RESPONSE:
                IRDA_DEBUG(0, "%s(), LM_CONNECT_RESPONSE, "
                IRDA_DEBUG(0, "%s(), LM_CONNECT_RESPONSE, "
                           "no indication issued yet\n",  __FUNCTION__);
                           "no indication issued yet\n",  __FUNCTION__);
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_DISCONNECT_REQUEST:
        case LM_DISCONNECT_REQUEST:
                IRDA_DEBUG(0, "%s(), LM_DISCONNECT_REQUEST, "
                IRDA_DEBUG(0, "%s(), LM_DISCONNECT_REQUEST, "
                           "not yet bound to IrLAP connection\n",  __FUNCTION__);
                           "not yet bound to IrLAP connection\n",  __FUNCTION__);
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_LAP_CONNECT_CONFIRM:
        case LM_LAP_CONNECT_CONFIRM:
                IRDA_DEBUG(4, "%s(), LS_CONNECT_CONFIRM\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), LS_CONNECT_CONFIRM\n",  __FUNCTION__);
                irlmp_next_lsap_state(self, LSAP_CONNECT);
                irlmp_next_lsap_state(self, LSAP_CONNECT);
 
 
                skb = self->conn_skb;
                skb = self->conn_skb;
                self->conn_skb = NULL;
                self->conn_skb = NULL;
 
 
                irlmp_connect_indication(self, skb);
                irlmp_connect_indication(self, skb);
                break;
                break;
        case LM_WATCHDOG_TIMEOUT:
        case LM_WATCHDOG_TIMEOUT:
                /* Will happen in some rare cases because of a race condition.
                /* Will happen in some rare cases because of a race condition.
                 * Just make sure we don't stay there forever...
                 * Just make sure we don't stay there forever...
                 * Jean II */
                 * Jean II */
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
 
 
                /* Go back to disconnected mode, keep the socket waiting */
                /* Go back to disconnected mode, keep the socket waiting */
                self->dlsap_sel = LSAP_ANY;
                self->dlsap_sel = LSAP_ANY;
                if(self->conn_skb)
                if(self->conn_skb)
                        dev_kfree_skb(self->conn_skb);
                        dev_kfree_skb(self->conn_skb);
                self->conn_skb = NULL;
                self->conn_skb = NULL;
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 
/*
/*
 * Function irlmp_state_dtr (self, event, skb)
 * Function irlmp_state_dtr (self, event, skb)
 *
 *
 *    DATA_TRANSFER_READY
 *    DATA_TRANSFER_READY
 *
 *
 */
 */
static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_dtr(struct lsap_cb *self, IRLMP_EVENT event,
                           struct sk_buff *skb)
                           struct sk_buff *skb)
{
{
        LM_REASON reason;
        LM_REASON reason;
        int ret = 0;
        int ret = 0;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->lap != NULL, return -1;);
        ASSERT(self->lap != NULL, return -1;);
 
 
        switch (event) {
        switch (event) {
        case LM_DATA_REQUEST: /* Optimize for the common case */
        case LM_DATA_REQUEST: /* Optimize for the common case */
                irlmp_send_data_pdu(self->lap, self->dlsap_sel,
                irlmp_send_data_pdu(self->lap, self->dlsap_sel,
                                    self->slsap_sel, FALSE, skb);
                                    self->slsap_sel, FALSE, skb);
                break;
                break;
        case LM_DATA_INDICATION: /* Optimize for the common case */
        case LM_DATA_INDICATION: /* Optimize for the common case */
                irlmp_data_indication(self, skb);
                irlmp_data_indication(self, skb);
                break;
                break;
        case LM_UDATA_REQUEST:
        case LM_UDATA_REQUEST:
                ASSERT(skb != NULL, return -1;);
                ASSERT(skb != NULL, return -1;);
                irlmp_send_data_pdu(self->lap, self->dlsap_sel,
                irlmp_send_data_pdu(self->lap, self->dlsap_sel,
                                    self->slsap_sel, TRUE, skb);
                                    self->slsap_sel, TRUE, skb);
                break;
                break;
        case LM_UDATA_INDICATION:
        case LM_UDATA_INDICATION:
                irlmp_udata_indication(self, skb);
                irlmp_udata_indication(self, skb);
                break;
                break;
        case LM_CONNECT_REQUEST:
        case LM_CONNECT_REQUEST:
                IRDA_DEBUG(0, "%s(), LM_CONNECT_REQUEST, "
                IRDA_DEBUG(0, "%s(), LM_CONNECT_REQUEST, "
                           "error, LSAP already connected\n",  __FUNCTION__);
                           "error, LSAP already connected\n",  __FUNCTION__);
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_CONNECT_RESPONSE:
        case LM_CONNECT_RESPONSE:
                IRDA_DEBUG(0, "%s(), LM_CONNECT_RESPONSE, "
                IRDA_DEBUG(0, "%s(), LM_CONNECT_RESPONSE, "
                           "error, LSAP allready connected\n",  __FUNCTION__);
                           "error, LSAP allready connected\n",  __FUNCTION__);
                /* Keep state */
                /* Keep state */
                break;
                break;
        case LM_DISCONNECT_REQUEST:
        case LM_DISCONNECT_REQUEST:
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel, self->slsap_sel,
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel, self->slsap_sel,
                                   DISCONNECT, skb);
                                   DISCONNECT, skb);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                /* Try to close the LAP connection if its still there */
                /* Try to close the LAP connection if its still there */
                if (self->lap) {
                if (self->lap) {
                        IRDA_DEBUG(4, "%s(), trying to close IrLAP\n",  __FUNCTION__);
                        IRDA_DEBUG(4, "%s(), trying to close IrLAP\n",  __FUNCTION__);
                        irlmp_do_lap_event(self->lap,
                        irlmp_do_lap_event(self->lap,
                                           LM_LAP_DISCONNECT_REQUEST,
                                           LM_LAP_DISCONNECT_REQUEST,
                                           NULL);
                                           NULL);
                }
                }
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION:
        case LM_LAP_DISCONNECT_INDICATION:
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                reason = irlmp_convert_lap_reason(self->lap->reason);
                reason = irlmp_convert_lap_reason(self->lap->reason);
 
 
                irlmp_disconnect_indication(self, reason, NULL);
                irlmp_disconnect_indication(self, reason, NULL);
                break;
                break;
        case LM_DISCONNECT_INDICATION:
        case LM_DISCONNECT_INDICATION:
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
 
 
                ASSERT(skb != NULL, return -1;);
                ASSERT(skb != NULL, return -1;);
                ASSERT(skb->len > 3, return -1;);
                ASSERT(skb->len > 3, return -1;);
                reason = skb->data[3];
                reason = skb->data[3];
 
 
                 /* Try to close the LAP connection */
                 /* Try to close the LAP connection */
                IRDA_DEBUG(4, "%ss(), trying to close IrLAP\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%ss(), trying to close IrLAP\n",  __FUNCTION__);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
 
 
                irlmp_disconnect_indication(self, reason, skb);
                irlmp_disconnect_indication(self, reason, skb);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 
/*
/*
 * Function irlmp_state_setup (event, skb, info)
 * Function irlmp_state_setup (event, skb, info)
 *
 *
 *    SETUP, Station Control has set up the underlying IrLAP connection.
 *    SETUP, Station Control has set up the underlying IrLAP connection.
 *    An LSAP connection request has been transmitted to the peer
 *    An LSAP connection request has been transmitted to the peer
 *    LSAP-Connection Control FSM and we are awaiting reply.
 *    LSAP-Connection Control FSM and we are awaiting reply.
 */
 */
static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_setup(struct lsap_cb *self, IRLMP_EVENT event,
                             struct sk_buff *skb)
                             struct sk_buff *skb)
{
{
        LM_REASON reason;
        LM_REASON reason;
        int ret = 0;
        int ret = 0;
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
        ASSERT(self->magic == LMP_LSAP_MAGIC, return -1;);
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        switch (event) {
        switch (event) {
        case LM_CONNECT_CONFIRM:
        case LM_CONNECT_CONFIRM:
                irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
                irlmp_next_lsap_state(self, LSAP_DATA_TRANSFER_READY);
 
 
                del_timer(&self->watchdog_timer);
                del_timer(&self->watchdog_timer);
 
 
                irlmp_connect_confirm(self, skb);
                irlmp_connect_confirm(self, skb);
                break;
                break;
        case LM_DISCONNECT_INDICATION:
        case LM_DISCONNECT_INDICATION:
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
 
 
                ASSERT(skb != NULL, return -1;);
                ASSERT(skb != NULL, return -1;);
                ASSERT(skb->len > 3, return -1;);
                ASSERT(skb->len > 3, return -1;);
                reason = skb->data[3];
                reason = skb->data[3];
 
 
                 /* Try to close the LAP connection */
                 /* Try to close the LAP connection */
                IRDA_DEBUG(4, "%s(), trying to close IrLAP\n",  __FUNCTION__);
                IRDA_DEBUG(4, "%s(), trying to close IrLAP\n",  __FUNCTION__);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
 
 
                irlmp_disconnect_indication(self, reason, skb);
                irlmp_disconnect_indication(self, reason, skb);
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION:
        case LM_LAP_DISCONNECT_INDICATION:
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                del_timer(&self->watchdog_timer);
                del_timer(&self->watchdog_timer);
 
 
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
                ASSERT(self->lap->magic == LMP_LAP_MAGIC, return -1;);
 
 
                reason = irlmp_convert_lap_reason(self->lap->reason);
                reason = irlmp_convert_lap_reason(self->lap->reason);
 
 
                irlmp_disconnect_indication(self, reason, skb);
                irlmp_disconnect_indication(self, reason, skb);
                break;
                break;
        case LM_WATCHDOG_TIMEOUT:
        case LM_WATCHDOG_TIMEOUT:
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
                IRDA_DEBUG(0, "%s() WATCHDOG_TIMEOUT!\n",  __FUNCTION__);
 
 
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
                irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 
/*
/*
 * Function irlmp_state_setup_pend (event, skb, info)
 * Function irlmp_state_setup_pend (event, skb, info)
 *
 *
 *    SETUP_PEND, An LM_CONNECT_REQUEST has been received from the service
 *    SETUP_PEND, An LM_CONNECT_REQUEST has been received from the service
 *    user to set up an LSAP connection. A request has been sent to the
 *    user to set up an LSAP connection. A request has been sent to the
 *    LAP FSM to set up the underlying IrLAP connection, and we
 *    LAP FSM to set up the underlying IrLAP connection, and we
 *    are awaiting confirm.
 *    are awaiting confirm.
 */
 */
static int irlmp_state_setup_pend(struct lsap_cb *self, IRLMP_EVENT event,
static int irlmp_state_setup_pend(struct lsap_cb *self, IRLMP_EVENT event,
                                  struct sk_buff *skb)
                                  struct sk_buff *skb)
{
{
        LM_REASON reason;
        LM_REASON reason;
        int ret = 0;
        int ret = 0;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(irlmp != NULL, return -1;);
        ASSERT(irlmp != NULL, return -1;);
 
 
        switch (event) {
        switch (event) {
        case LM_LAP_CONNECT_CONFIRM:
        case LM_LAP_CONNECT_CONFIRM:
                ASSERT(self->conn_skb != NULL, return -1;);
                ASSERT(self->conn_skb != NULL, return -1;);
 
 
                skb = self->conn_skb;
                skb = self->conn_skb;
                self->conn_skb = NULL;
                self->conn_skb = NULL;
 
 
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
                irlmp_send_lcf_pdu(self->lap, self->dlsap_sel,
                                   self->slsap_sel, CONNECT_CMD, skb);
                                   self->slsap_sel, CONNECT_CMD, skb);
 
 
                irlmp_next_lsap_state(self, LSAP_SETUP);
                irlmp_next_lsap_state(self, LSAP_SETUP);
                break;
                break;
        case LM_WATCHDOG_TIMEOUT:
        case LM_WATCHDOG_TIMEOUT:
                IRDA_DEBUG(0, "%s() : WATCHDOG_TIMEOUT !\n",  __FUNCTION__);
                IRDA_DEBUG(0, "%s() : WATCHDOG_TIMEOUT !\n",  __FUNCTION__);
 
 
                ASSERT(self->lap != NULL, return -1;);
                ASSERT(self->lap != NULL, return -1;);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_do_lap_event(self->lap, LM_LAP_DISCONNECT_REQUEST, NULL);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
                irlmp_disconnect_indication(self, LM_CONNECT_FAILURE, NULL);
                break;
                break;
        case LM_LAP_DISCONNECT_INDICATION: /* LS_Disconnect.indication */
        case LM_LAP_DISCONNECT_INDICATION: /* LS_Disconnect.indication */
                del_timer( &self->watchdog_timer);
                del_timer( &self->watchdog_timer);
 
 
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
                irlmp_next_lsap_state(self, LSAP_DISCONNECTED);
 
 
                reason = irlmp_convert_lap_reason(self->lap->reason);
                reason = irlmp_convert_lap_reason(self->lap->reason);
 
 
                irlmp_disconnect_indication(self, reason, NULL);
                irlmp_disconnect_indication(self, reason, NULL);
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                IRDA_DEBUG(0, "%s(), Unknown event %s on LSAP %#02x\n",
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                           __FUNCTION__, irlmp_event[event], self->slsap_sel);
                if (skb)
                if (skb)
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return ret;
        return ret;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.