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

Subversion Repositories or1k

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

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

Rev 1275 Rev 1765
/*********************************************************************
/*********************************************************************
 *
 *
 * Filename:      iriap.c
 * Filename:      iriap.c
 * Version:       0.8
 * Version:       0.8
 * Description:   Information Access Protocol (IAP)
 * Description:   Information Access Protocol (IAP)
 * Status:        Experimental.
 * Status:        Experimental.
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Thu Aug 21 00:02:07 1997
 * Created at:    Thu Aug 21 00:02:07 1997
 * Modified at:   Sat Dec 25 16:42:42 1999
 * Modified at:   Sat Dec 25 16:42:42 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/types.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/init.h>
 
 
#include <asm/byteorder.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>
#include <asm/unaligned.h>
 
 
#include <net/irda/irda.h>
#include <net/irda/irda.h>
#include <net/irda/irttp.h>
#include <net/irda/irttp.h>
#include <net/irda/irmod.h>
#include <net/irda/irmod.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp.h>
#include <net/irda/irias_object.h>
#include <net/irda/irias_object.h>
#include <net/irda/iriap_event.h>
#include <net/irda/iriap_event.h>
#include <net/irda/iriap.h>
#include <net/irda/iriap.h>
 
 
#ifdef CONFIG_IRDA_DEBUG
#ifdef CONFIG_IRDA_DEBUG
/* FIXME: This one should go in irlmp.c */
/* FIXME: This one should go in irlmp.c */
static const char *ias_charset_types[] = {
static const char *ias_charset_types[] = {
        "CS_ASCII",
        "CS_ASCII",
        "CS_ISO_8859_1",
        "CS_ISO_8859_1",
        "CS_ISO_8859_2",
        "CS_ISO_8859_2",
        "CS_ISO_8859_3",
        "CS_ISO_8859_3",
        "CS_ISO_8859_4",
        "CS_ISO_8859_4",
        "CS_ISO_8859_5",
        "CS_ISO_8859_5",
        "CS_ISO_8859_6",
        "CS_ISO_8859_6",
        "CS_ISO_8859_7",
        "CS_ISO_8859_7",
        "CS_ISO_8859_8",
        "CS_ISO_8859_8",
        "CS_ISO_8859_9",
        "CS_ISO_8859_9",
        "CS_UNICODE"
        "CS_UNICODE"
};
};
#endif  /* CONFIG_IRDA_DEBUG */
#endif  /* CONFIG_IRDA_DEBUG */
 
 
static hashbin_t *iriap = NULL;
static hashbin_t *iriap = NULL;
static __u32 service_handle;
static __u32 service_handle;
 
 
extern char *lmp_reasons[];
extern char *lmp_reasons[];
 
 
static void __iriap_close(struct iriap_cb *self);
static void __iriap_close(struct iriap_cb *self);
static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode);
static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode);
static void iriap_disconnect_indication(void *instance, void *sap,
static void iriap_disconnect_indication(void *instance, void *sap,
                                        LM_REASON reason, struct sk_buff *skb);
                                        LM_REASON reason, struct sk_buff *skb);
static void iriap_connect_indication(void *instance, void *sap,
static void iriap_connect_indication(void *instance, void *sap,
                                     struct qos_info *qos, __u32 max_sdu_size,
                                     struct qos_info *qos, __u32 max_sdu_size,
                                     __u8 max_header_size,
                                     __u8 max_header_size,
                                     struct sk_buff *skb);
                                     struct sk_buff *skb);
static void iriap_connect_confirm(void *instance, void *sap,
static void iriap_connect_confirm(void *instance, void *sap,
                                  struct qos_info *qos,
                                  struct qos_info *qos,
                                  __u32 max_sdu_size, __u8 max_header_size,
                                  __u32 max_sdu_size, __u8 max_header_size,
                                  struct sk_buff *skb);
                                  struct sk_buff *skb);
static int iriap_data_indication(void *instance, void *sap,
static int iriap_data_indication(void *instance, void *sap,
                                 struct sk_buff *skb);
                                 struct sk_buff *skb);
 
 
/*
/*
 * Function iriap_init (void)
 * Function iriap_init (void)
 *
 *
 *    Initializes the IrIAP layer, called by the module initialization code
 *    Initializes the IrIAP layer, called by the module initialization code
 *    in irmod.c
 *    in irmod.c
 */
 */
int __init iriap_init(void)
int __init iriap_init(void)
{
{
        struct ias_object *obj;
        struct ias_object *obj;
        struct iriap_cb *server;
        struct iriap_cb *server;
        __u8 oct_seq[6];
        __u8 oct_seq[6];
        __u16 hints;
        __u16 hints;
 
 
        /* Allocate master array */
        /* Allocate master array */
        iriap = hashbin_new(HB_LOCAL);
        iriap = hashbin_new(HB_LOCAL);
        if (!iriap)
        if (!iriap)
                return -ENOMEM;
                return -ENOMEM;
 
 
        objects = hashbin_new(HB_LOCAL);
        objects = hashbin_new(HB_LOCAL);
        if (!objects) {
        if (!objects) {
                WARNING("%s(), Can't allocate objects hashbin!\n", __FUNCTION__);
                WARNING("%s(), Can't allocate objects hashbin!\n", __FUNCTION__);
                return -ENOMEM;
                return -ENOMEM;
        }
        }
 
 
        /*
        /*
         *  Register some default services for IrLMP
         *  Register some default services for IrLMP
         */
         */
        hints  = irlmp_service_to_hint(S_COMPUTER);
        hints  = irlmp_service_to_hint(S_COMPUTER);
        service_handle = irlmp_register_service(hints);
        service_handle = irlmp_register_service(hints);
 
 
        /* Register the Device object with LM-IAS */
        /* Register the Device object with LM-IAS */
        obj = irias_new_object("Device", IAS_DEVICE_ID);
        obj = irias_new_object("Device", IAS_DEVICE_ID);
        irias_add_string_attrib(obj, "DeviceName", "Linux", IAS_KERNEL_ATTR);
        irias_add_string_attrib(obj, "DeviceName", "Linux", IAS_KERNEL_ATTR);
 
 
        oct_seq[0] = 0x01;  /* Version 1 */
        oct_seq[0] = 0x01;  /* Version 1 */
        oct_seq[1] = 0x00;  /* IAS support bits */
        oct_seq[1] = 0x00;  /* IAS support bits */
        oct_seq[2] = 0x00;  /* LM-MUX support bits */
        oct_seq[2] = 0x00;  /* LM-MUX support bits */
#ifdef CONFIG_IRDA_ULTRA
#ifdef CONFIG_IRDA_ULTRA
        oct_seq[2] |= 0x04; /* Connectionless Data support */
        oct_seq[2] |= 0x04; /* Connectionless Data support */
#endif
#endif
        irias_add_octseq_attrib(obj, "IrLMPSupport", oct_seq, 3,
        irias_add_octseq_attrib(obj, "IrLMPSupport", oct_seq, 3,
                                IAS_KERNEL_ATTR);
                                IAS_KERNEL_ATTR);
        irias_insert_object(obj);
        irias_insert_object(obj);
 
 
        /*
        /*
         *  Register server support with IrLMP so we can accept incoming
         *  Register server support with IrLMP so we can accept incoming
         *  connections
         *  connections
         */
         */
        server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        if (!server) {
        if (!server) {
                IRDA_DEBUG(0, "%s(), unable to open server\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), unable to open server\n", __FUNCTION__);
                return -1;
                return -1;
        }
        }
        iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
        iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 * Function iriap_cleanup (void)
 * Function iriap_cleanup (void)
 *
 *
 *    Initializes the IrIAP layer, called by the module cleanup code in
 *    Initializes the IrIAP layer, called by the module cleanup code in
 *    irmod.c
 *    irmod.c
 */
 */
void iriap_cleanup(void)
void iriap_cleanup(void)
{
{
        irlmp_unregister_service(service_handle);
        irlmp_unregister_service(service_handle);
 
 
        hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
        hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
        hashbin_delete(objects, (FREE_FUNC) __irias_delete_object);
        hashbin_delete(objects, (FREE_FUNC) __irias_delete_object);
}
}
 
 
/*
/*
 * Function iriap_open (void)
 * Function iriap_open (void)
 *
 *
 *    Opens an instance of the IrIAP layer, and registers with IrLMP
 *    Opens an instance of the IrIAP layer, and registers with IrLMP
 */
 */
struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
                            CONFIRM_CALLBACK callback)
                            CONFIRM_CALLBACK callback)
{
{
        struct iriap_cb *self;
        struct iriap_cb *self;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
        self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
        if (!self) {
        if (!self) {
                WARNING("%s(), Unable to kmalloc!\n", __FUNCTION__);
                WARNING("%s(), Unable to kmalloc!\n", __FUNCTION__);
                return NULL;
                return NULL;
        }
        }
 
 
        /*
        /*
         *  Initialize instance
         *  Initialize instance
         */
         */
        memset(self, 0, sizeof(struct iriap_cb));
        memset(self, 0, sizeof(struct iriap_cb));
 
 
        self->magic = IAS_MAGIC;
        self->magic = IAS_MAGIC;
        self->mode = mode;
        self->mode = mode;
        if (mode == IAS_CLIENT)
        if (mode == IAS_CLIENT)
                iriap_register_lsap(self, slsap_sel, mode);
                iriap_register_lsap(self, slsap_sel, mode);
 
 
        self->confirm = callback;
        self->confirm = callback;
        self->priv = priv;
        self->priv = priv;
 
 
        init_timer(&self->watchdog_timer);
        init_timer(&self->watchdog_timer);
 
 
        hashbin_insert(iriap, (irda_queue_t *) self, (int) self, NULL);
        hashbin_insert(iriap, (irda_queue_t *) self, (int) self, NULL);
 
 
        /* Initialize state machines */
        /* Initialize state machines */
        iriap_next_client_state(self, S_DISCONNECT);
        iriap_next_client_state(self, S_DISCONNECT);
        iriap_next_call_state(self, S_MAKE_CALL);
        iriap_next_call_state(self, S_MAKE_CALL);
        iriap_next_server_state(self, R_DISCONNECT);
        iriap_next_server_state(self, R_DISCONNECT);
        iriap_next_r_connect_state(self, R_WAITING);
        iriap_next_r_connect_state(self, R_WAITING);
 
 
        return self;
        return self;
}
}
 
 
/*
/*
 * Function __iriap_close (self)
 * Function __iriap_close (self)
 *
 *
 *    Removes (deallocates) the IrIAP instance
 *    Removes (deallocates) the IrIAP instance
 *
 *
 */
 */
static void __iriap_close(struct iriap_cb *self)
static void __iriap_close(struct iriap_cb *self)
{
{
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        del_timer(&self->watchdog_timer);
        del_timer(&self->watchdog_timer);
 
 
        if (self->skb)
        if (self->skb)
                dev_kfree_skb(self->skb);
                dev_kfree_skb(self->skb);
 
 
        self->magic = 0;
        self->magic = 0;
 
 
        kfree(self);
        kfree(self);
}
}
 
 
/*
/*
 * Function iriap_close (void)
 * Function iriap_close (void)
 *
 *
 *    Closes IrIAP and deregisters with IrLMP
 *    Closes IrIAP and deregisters with IrLMP
 */
 */
void iriap_close(struct iriap_cb *self)
void iriap_close(struct iriap_cb *self)
{
{
        struct iriap_cb *entry;
        struct iriap_cb *entry;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        if (self->lsap) {
        if (self->lsap) {
                irlmp_close_lsap(self->lsap);
                irlmp_close_lsap(self->lsap);
                self->lsap = NULL;
                self->lsap = NULL;
        }
        }
 
 
        entry = (struct iriap_cb *) hashbin_remove(iriap, (int) self, NULL);
        entry = (struct iriap_cb *) hashbin_remove(iriap, (int) self, NULL);
        ASSERT(entry == self, return;);
        ASSERT(entry == self, return;);
 
 
        __iriap_close(self);
        __iriap_close(self);
}
}
 
 
static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
{
{
        notify_t notify;
        notify_t notify;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        irda_notify_init(&notify);
        irda_notify_init(&notify);
        notify.connect_confirm       = iriap_connect_confirm;
        notify.connect_confirm       = iriap_connect_confirm;
        notify.connect_indication    = iriap_connect_indication;
        notify.connect_indication    = iriap_connect_indication;
        notify.disconnect_indication = iriap_disconnect_indication;
        notify.disconnect_indication = iriap_disconnect_indication;
        notify.data_indication       = iriap_data_indication;
        notify.data_indication       = iriap_data_indication;
        notify.instance = self;
        notify.instance = self;
        if (mode == IAS_CLIENT)
        if (mode == IAS_CLIENT)
                strcpy(notify.name, "IrIAS cli");
                strcpy(notify.name, "IrIAS cli");
        else
        else
                strcpy(notify.name, "IrIAS srv");
                strcpy(notify.name, "IrIAS srv");
 
 
        self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
        self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
        if (self->lsap == NULL) {
        if (self->lsap == NULL) {
                ERROR("%s(), Unable to allocated LSAP!\n", __FUNCTION__);
                ERROR("%s(), Unable to allocated LSAP!\n", __FUNCTION__);
                return -1;
                return -1;
        }
        }
        self->slsap_sel = self->lsap->slsap_sel;
        self->slsap_sel = self->lsap->slsap_sel;
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 * Function iriap_disconnect_indication (handle, reason)
 * Function iriap_disconnect_indication (handle, reason)
 *
 *
 *    Got disconnect, so clean up everything assosiated with this connection
 *    Got disconnect, so clean up everything assosiated with this connection
 *
 *
 */
 */
static void iriap_disconnect_indication(void *instance, void *sap,
static void iriap_disconnect_indication(void *instance, void *sap,
                                        LM_REASON reason,
                                        LM_REASON reason,
                                        struct sk_buff *userdata)
                                        struct sk_buff *userdata)
{
{
        struct iriap_cb *self;
        struct iriap_cb *self;
 
 
        IRDA_DEBUG(4, "%s(), reason=%s\n", __FUNCTION__, lmp_reasons[reason]);
        IRDA_DEBUG(4, "%s(), reason=%s\n", __FUNCTION__, lmp_reasons[reason]);
 
 
        self = (struct iriap_cb *) instance;
        self = (struct iriap_cb *) instance;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        ASSERT(iriap != NULL, return;);
        ASSERT(iriap != NULL, return;);
 
 
        del_timer(&self->watchdog_timer);
        del_timer(&self->watchdog_timer);
 
 
        if (self->mode == IAS_CLIENT) {
        if (self->mode == IAS_CLIENT) {
                IRDA_DEBUG(4, "%s(), disconnect as client\n", __FUNCTION__);
                IRDA_DEBUG(4, "%s(), disconnect as client\n", __FUNCTION__);
 
 
 
 
                iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
                iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
                                      NULL);
                                      NULL);
                /*
                /*
                 * Inform service user that the request failed by sending
                 * Inform service user that the request failed by sending
                 * it a NULL value. Warning, the client might close us, so
                 * it a NULL value. Warning, the client might close us, so
                 * remember no to use self anymore after calling confirm
                 * remember no to use self anymore after calling confirm
                 */
                 */
                if (self->confirm)
                if (self->confirm)
                        self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
                        self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
        } else {
        } else {
                IRDA_DEBUG(4, "%s(), disconnect as server\n", __FUNCTION__);
                IRDA_DEBUG(4, "%s(), disconnect as server\n", __FUNCTION__);
                iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
                iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
                                      NULL);
                                      NULL);
                iriap_close(self);
                iriap_close(self);
        }
        }
 
 
        if (userdata)
        if (userdata)
                dev_kfree_skb(userdata);
                dev_kfree_skb(userdata);
}
}
 
 
/*
/*
 * Function iriap_disconnect_request (handle)
 * Function iriap_disconnect_request (handle)
 *
 *
 *
 *
 *
 *
 */
 */
void iriap_disconnect_request(struct iriap_cb *self)
void iriap_disconnect_request(struct iriap_cb *self)
{
{
        struct sk_buff *skb;
        struct sk_buff *skb;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        skb = dev_alloc_skb(64);
        skb = dev_alloc_skb(64);
        if (skb == NULL) {
        if (skb == NULL) {
                IRDA_DEBUG(0, "%s(), Could not allocate an sk_buff of length %d\n",
                IRDA_DEBUG(0, "%s(), Could not allocate an sk_buff of length %d\n",
                        __FUNCTION__, 64);
                        __FUNCTION__, 64);
                return;
                return;
        }
        }
 
 
        /*
        /*
         *  Reserve space for MUX control and LAP header
         *  Reserve space for MUX control and LAP header
         */
         */
        skb_reserve(skb, LMP_MAX_HEADER);
        skb_reserve(skb, LMP_MAX_HEADER);
 
 
        irlmp_disconnect_request(self->lsap, skb);
        irlmp_disconnect_request(self->lsap, skb);
}
}
 
 
void iriap_getinfobasedetails_request(void)
void iriap_getinfobasedetails_request(void)
{
{
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
}
}
 
 
void iriap_getinfobasedetails_confirm(void)
void iriap_getinfobasedetails_confirm(void)
{
{
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
}
}
 
 
void iriap_getobjects_request(void)
void iriap_getobjects_request(void)
{
{
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
}
}
 
 
void iriap_getobjects_confirm(void)
void iriap_getobjects_confirm(void)
{
{
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
}
}
 
 
void iriap_getvalue(void)
void iriap_getvalue(void)
{
{
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
        IRDA_DEBUG(0, "%s(), Not implemented!\n", __FUNCTION__);
}
}
 
 
/*
/*
 * Function iriap_getvaluebyclass (addr, name, attr)
 * Function iriap_getvaluebyclass (addr, name, attr)
 *
 *
 *    Retreive all values from attribute in all objects with given class
 *    Retreive all values from attribute in all objects with given class
 *    name
 *    name
 */
 */
int iriap_getvaluebyclass_request(struct iriap_cb *self,
int iriap_getvaluebyclass_request(struct iriap_cb *self,
                                  __u32 saddr, __u32 daddr,
                                  __u32 saddr, __u32 daddr,
                                  char *name, char *attr)
                                  char *name, char *attr)
{
{
        struct sk_buff *skb;
        struct sk_buff *skb;
        int name_len, attr_len, skb_len;
        int name_len, attr_len, skb_len;
        __u8 *frame;
        __u8 *frame;
 
 
        ASSERT(self != NULL, return -1;);
        ASSERT(self != NULL, return -1;);
        ASSERT(self->magic == IAS_MAGIC, return -1;);
        ASSERT(self->magic == IAS_MAGIC, return -1;);
 
 
        /* Client must supply the destination device address */
        /* Client must supply the destination device address */
        if (!daddr)
        if (!daddr)
                return -1;
                return -1;
 
 
        self->daddr = daddr;
        self->daddr = daddr;
        self->saddr = saddr;
        self->saddr = saddr;
 
 
        /*
        /*
         *  Save operation, so we know what the later indication is about
         *  Save operation, so we know what the later indication is about
         */
         */
        self->operation = GET_VALUE_BY_CLASS;
        self->operation = GET_VALUE_BY_CLASS;
 
 
        /* Give ourselves 10 secs to finish this operation */
        /* Give ourselves 10 secs to finish this operation */
        iriap_start_watchdog_timer(self, 10*HZ);
        iriap_start_watchdog_timer(self, 10*HZ);
 
 
        name_len = strlen(name);        /* Up to IAS_MAX_CLASSNAME = 60 */
        name_len = strlen(name);        /* Up to IAS_MAX_CLASSNAME = 60 */
        attr_len = strlen(attr);        /* Up to IAS_MAX_ATTRIBNAME = 60 */
        attr_len = strlen(attr);        /* Up to IAS_MAX_ATTRIBNAME = 60 */
 
 
        skb_len = self->max_header_size+2+name_len+1+attr_len+4;
        skb_len = self->max_header_size+2+name_len+1+attr_len+4;
        skb = dev_alloc_skb(skb_len);
        skb = dev_alloc_skb(skb_len);
        if (!skb)
        if (!skb)
                return -ENOMEM;
                return -ENOMEM;
 
 
        /* Reserve space for MUX and LAP header */
        /* Reserve space for MUX and LAP header */
        skb_reserve(skb, self->max_header_size);
        skb_reserve(skb, self->max_header_size);
        skb_put(skb, 3+name_len+attr_len);
        skb_put(skb, 3+name_len+attr_len);
        frame = skb->data;
        frame = skb->data;
 
 
        /* Build frame */
        /* Build frame */
        frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
        frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
        frame[1] = name_len;                       /* Insert length of name */
        frame[1] = name_len;                       /* Insert length of name */
        memcpy(frame+2, name, name_len);           /* Insert name */
        memcpy(frame+2, name, name_len);           /* Insert name */
        frame[2+name_len] = attr_len;              /* Insert length of attr */
        frame[2+name_len] = attr_len;              /* Insert length of attr */
        memcpy(frame+3+name_len, attr, attr_len);  /* Insert attr */
        memcpy(frame+3+name_len, attr, attr_len);  /* Insert attr */
 
 
        iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, skb);
        iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, skb);
 
 
        return 0;
        return 0;
}
}
 
 
/*
/*
 * Function iriap_getvaluebyclass_confirm (self, skb)
 * Function iriap_getvaluebyclass_confirm (self, skb)
 *
 *
 *    Got result from GetValueByClass command. Parse it and return result
 *    Got result from GetValueByClass command. Parse it and return result
 *    to service user.
 *    to service user.
 *
 *
 */
 */
void iriap_getvaluebyclass_confirm(struct iriap_cb *self, struct sk_buff *skb)
void iriap_getvaluebyclass_confirm(struct iriap_cb *self, struct sk_buff *skb)
{
{
        struct ias_value *value;
        struct ias_value *value;
        int charset;
        int charset;
        __u32 value_len;
        __u32 value_len;
        __u32 tmp_cpu32;
        __u32 tmp_cpu32;
        __u16 obj_id;
        __u16 obj_id;
        __u16 len;
        __u16 len;
        __u8  type;
        __u8  type;
        __u8 *fp;
        __u8 *fp;
        int n;
        int n;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(skb != NULL, return;);
        ASSERT(skb != NULL, return;);
 
 
        /* Initialize variables */
        /* Initialize variables */
        fp = skb->data;
        fp = skb->data;
        n = 2;
        n = 2;
 
 
        /* Get length, MSB first */
        /* Get length, MSB first */
        len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
        len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
 
 
        IRDA_DEBUG(4, "%s(), len=%d\n", __FUNCTION__, len);
        IRDA_DEBUG(4, "%s(), len=%d\n", __FUNCTION__, len);
 
 
        /* Get object ID, MSB first */
        /* Get object ID, MSB first */
        obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
        obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
 
 
        type = fp[n++];
        type = fp[n++];
        IRDA_DEBUG(4, "%s(), Value type = %d\n", __FUNCTION__, type);
        IRDA_DEBUG(4, "%s(), Value type = %d\n", __FUNCTION__, type);
 
 
        switch (type) {
        switch (type) {
        case IAS_INTEGER:
        case IAS_INTEGER:
                memcpy(&tmp_cpu32, fp+n, 4); n += 4;
                memcpy(&tmp_cpu32, fp+n, 4); n += 4;
                be32_to_cpus(&tmp_cpu32);
                be32_to_cpus(&tmp_cpu32);
                value = irias_new_integer_value(tmp_cpu32);
                value = irias_new_integer_value(tmp_cpu32);
 
 
                /*  Legal values restricted to 0x01-0x6f, page 15 irttp */
                /*  Legal values restricted to 0x01-0x6f, page 15 irttp */
                IRDA_DEBUG(4, "%s(), lsap=%d\n", __FUNCTION__, value->t.integer);
                IRDA_DEBUG(4, "%s(), lsap=%d\n", __FUNCTION__, value->t.integer);
                break;
                break;
        case IAS_STRING:
        case IAS_STRING:
                charset = fp[n++];
                charset = fp[n++];
 
 
                switch (charset) {
                switch (charset) {
                case CS_ASCII:
                case CS_ASCII:
                        break;
                        break;
/*              case CS_ISO_8859_1: */
/*              case CS_ISO_8859_1: */
/*              case CS_ISO_8859_2: */
/*              case CS_ISO_8859_2: */
/*              case CS_ISO_8859_3: */
/*              case CS_ISO_8859_3: */
/*              case CS_ISO_8859_4: */
/*              case CS_ISO_8859_4: */
/*              case CS_ISO_8859_5: */
/*              case CS_ISO_8859_5: */
/*              case CS_ISO_8859_6: */
/*              case CS_ISO_8859_6: */
/*              case CS_ISO_8859_7: */
/*              case CS_ISO_8859_7: */
/*              case CS_ISO_8859_8: */
/*              case CS_ISO_8859_8: */
/*              case CS_ISO_8859_9: */
/*              case CS_ISO_8859_9: */
/*              case CS_UNICODE: */
/*              case CS_UNICODE: */
                default:
                default:
                        IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
                        IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
                                   __FUNCTION__, ias_charset_types[charset]);
                                   __FUNCTION__, ias_charset_types[charset]);
 
 
                        /* Aborting, close connection! */
                        /* Aborting, close connection! */
                        iriap_disconnect_request(self);
                        iriap_disconnect_request(self);
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                        return;
                        return;
                        /* break; */
                        /* break; */
                }
                }
                value_len = fp[n++];
                value_len = fp[n++];
                IRDA_DEBUG(4, "%s(), strlen=%d\n", __FUNCTION__, value_len);
                IRDA_DEBUG(4, "%s(), strlen=%d\n", __FUNCTION__, value_len);
 
 
                /* Make sure the string is null-terminated */
                /* Make sure the string is null-terminated */
                fp[n+value_len] = 0x00;
                fp[n+value_len] = 0x00;
                IRDA_DEBUG(4, "Got string %s\n", fp+n);
                IRDA_DEBUG(4, "Got string %s\n", fp+n);
 
 
                /* Will truncate to IAS_MAX_STRING bytes */
                /* Will truncate to IAS_MAX_STRING bytes */
                value = irias_new_string_value(fp+n);
                value = irias_new_string_value(fp+n);
                break;
                break;
        case IAS_OCT_SEQ:
        case IAS_OCT_SEQ:
                value_len = be16_to_cpu(get_unaligned((__u16 *)(fp+n)));
                value_len = be16_to_cpu(get_unaligned((__u16 *)(fp+n)));
                n += 2;
                n += 2;
 
 
                /* Will truncate to IAS_MAX_OCTET_STRING bytes */
                /* Will truncate to IAS_MAX_OCTET_STRING bytes */
                value = irias_new_octseq_value(fp+n, value_len);
                value = irias_new_octseq_value(fp+n, value_len);
                break;
                break;
        default:
        default:
                value = irias_new_missing_value();
                value = irias_new_missing_value();
                break;
                break;
        }
        }
 
 
        /* Finished, close connection! */
        /* Finished, close connection! */
        iriap_disconnect_request(self);
        iriap_disconnect_request(self);
 
 
        /* Warning, the client might close us, so remember no to use self
        /* Warning, the client might close us, so remember no to use self
         * anymore after calling confirm
         * anymore after calling confirm
         */
         */
        if (self->confirm)
        if (self->confirm)
                self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
                self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
        else {
        else {
                IRDA_DEBUG(0, "%s(), missing handler!\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), missing handler!\n", __FUNCTION__);
                irias_delete_value(value);
                irias_delete_value(value);
        }
        }
        dev_kfree_skb(skb);
        dev_kfree_skb(skb);
}
}
 
 
/*
/*
 * Function iriap_getvaluebyclass_response ()
 * Function iriap_getvaluebyclass_response ()
 *
 *
 *    Send answer back to remote LM-IAS
 *    Send answer back to remote LM-IAS
 *
 *
 */
 */
void iriap_getvaluebyclass_response(struct iriap_cb *self, __u16 obj_id,
void iriap_getvaluebyclass_response(struct iriap_cb *self, __u16 obj_id,
                                    __u8 ret_code, struct ias_value *value)
                                    __u8 ret_code, struct ias_value *value)
{
{
        struct sk_buff *skb;
        struct sk_buff *skb;
        int n;
        int n;
        __u32 tmp_be32, tmp_be16;
        __u32 tmp_be32, tmp_be16;
        __u8 *fp;
        __u8 *fp;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(value != NULL, return;);
        ASSERT(value != NULL, return;);
        ASSERT(value->len <= 1024, return;);
        ASSERT(value->len <= 1024, return;);
 
 
        /* Initialize variables */
        /* Initialize variables */
        n = 0;
        n = 0;
 
 
        /*
        /*
         *  We must adjust the size of the response after the length of the
         *  We must adjust the size of the response after the length of the
         *  value. We add 32 bytes because of the 6 bytes for the frame and
         *  value. We add 32 bytes because of the 6 bytes for the frame and
         *  max 5 bytes for the value coding.
         *  max 5 bytes for the value coding.
         */
         */
        skb = dev_alloc_skb(value->len + self->max_header_size + 32);
        skb = dev_alloc_skb(value->len + self->max_header_size + 32);
        if (!skb)
        if (!skb)
                return;
                return;
 
 
        /* Reserve space for MUX and LAP header */
        /* Reserve space for MUX and LAP header */
        skb_reserve(skb, self->max_header_size);
        skb_reserve(skb, self->max_header_size);
        skb_put(skb, 6);
        skb_put(skb, 6);
 
 
        fp = skb->data;
        fp = skb->data;
 
 
        /* Build frame */
        /* Build frame */
        fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
        fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
        fp[n++] = ret_code;
        fp[n++] = ret_code;
 
 
        /* Insert list length (MSB first) */
        /* Insert list length (MSB first) */
        tmp_be16 = __constant_htons(0x0001);
        tmp_be16 = __constant_htons(0x0001);
        memcpy(fp+n, &tmp_be16, 2);  n += 2;
        memcpy(fp+n, &tmp_be16, 2);  n += 2;
 
 
        /* Insert object identifier ( MSB first) */
        /* Insert object identifier ( MSB first) */
        tmp_be16 = cpu_to_be16(obj_id);
        tmp_be16 = cpu_to_be16(obj_id);
        memcpy(fp+n, &tmp_be16, 2); n += 2;
        memcpy(fp+n, &tmp_be16, 2); n += 2;
 
 
        switch (value->type) {
        switch (value->type) {
        case IAS_STRING:
        case IAS_STRING:
                skb_put(skb, 3 + value->len);
                skb_put(skb, 3 + value->len);
                fp[n++] = value->type;
                fp[n++] = value->type;
                fp[n++] = 0; /* ASCII */
                fp[n++] = 0; /* ASCII */
                fp[n++] = (__u8) value->len;
                fp[n++] = (__u8) value->len;
                memcpy(fp+n, value->t.string, value->len); n+=value->len;
                memcpy(fp+n, value->t.string, value->len); n+=value->len;
                break;
                break;
        case IAS_INTEGER:
        case IAS_INTEGER:
                skb_put(skb, 5);
                skb_put(skb, 5);
                fp[n++] = value->type;
                fp[n++] = value->type;
 
 
                tmp_be32 = cpu_to_be32(value->t.integer);
                tmp_be32 = cpu_to_be32(value->t.integer);
                memcpy(fp+n, &tmp_be32, 4); n += 4;
                memcpy(fp+n, &tmp_be32, 4); n += 4;
                break;
                break;
        case IAS_OCT_SEQ:
        case IAS_OCT_SEQ:
                skb_put(skb, 3 + value->len);
                skb_put(skb, 3 + value->len);
                fp[n++] = value->type;
                fp[n++] = value->type;
 
 
                tmp_be16 = cpu_to_be16(value->len);
                tmp_be16 = cpu_to_be16(value->len);
                memcpy(fp+n, &tmp_be16, 2); n += 2;
                memcpy(fp+n, &tmp_be16, 2); n += 2;
                memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
                memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
                break;
                break;
        case IAS_MISSING:
        case IAS_MISSING:
                IRDA_DEBUG( 3, "%s: sending IAS_MISSING\n", __FUNCTION__);
                IRDA_DEBUG( 3, "%s: sending IAS_MISSING\n", __FUNCTION__);
                skb_put(skb, 1);
                skb_put(skb, 1);
                fp[n++] = value->type;
                fp[n++] = value->type;
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), type not implemented!\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), type not implemented!\n", __FUNCTION__);
                break;
                break;
        }
        }
        iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, skb);
        iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, skb);
}
}
 
 
/*
/*
 * Function iriap_getvaluebyclass_indication (self, skb)
 * Function iriap_getvaluebyclass_indication (self, skb)
 *
 *
 *    getvaluebyclass is requested from peer LM-IAS
 *    getvaluebyclass is requested from peer LM-IAS
 *
 *
 */
 */
void iriap_getvaluebyclass_indication(struct iriap_cb *self,
void iriap_getvaluebyclass_indication(struct iriap_cb *self,
                                      struct sk_buff *skb)
                                      struct sk_buff *skb)
{
{
        struct ias_object *obj;
        struct ias_object *obj;
        struct ias_attrib *attrib;
        struct ias_attrib *attrib;
        int name_len;
        int name_len;
        int attr_len;
        int attr_len;
        char name[IAS_MAX_CLASSNAME + 1];       /* 60 bytes */
        char name[IAS_MAX_CLASSNAME + 1];       /* 60 bytes */
        char attr[IAS_MAX_ATTRIBNAME + 1];      /* 60 bytes */
        char attr[IAS_MAX_ATTRIBNAME + 1];      /* 60 bytes */
        __u8 *fp;
        __u8 *fp;
        int n;
        int n;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(skb != NULL, return;);
        ASSERT(skb != NULL, return;);
 
 
        fp = skb->data;
        fp = skb->data;
        n = 1;
        n = 1;
 
 
        name_len = fp[n++];
        name_len = fp[n++];
        memcpy(name, fp+n, name_len); n+=name_len;
        memcpy(name, fp+n, name_len); n+=name_len;
        name[name_len] = '\0';
        name[name_len] = '\0';
 
 
        attr_len = fp[n++];
        attr_len = fp[n++];
        memcpy(attr, fp+n, attr_len); n+=attr_len;
        memcpy(attr, fp+n, attr_len); n+=attr_len;
        attr[attr_len] = '\0';
        attr[attr_len] = '\0';
 
 
        /* We do not need the buffer anymore */
        /* We do not need the buffer anymore */
        dev_kfree_skb(skb);
        dev_kfree_skb(skb);
 
 
        IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
        IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
        obj = irias_find_object(name);
        obj = irias_find_object(name);
 
 
        if (obj == NULL) {
        if (obj == NULL) {
                IRDA_DEBUG(2, "LM-IAS: Object %s not found\n", name);
                IRDA_DEBUG(2, "LM-IAS: Object %s not found\n", name);
                iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
                iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
                                               &missing);
                                               &missing);
                return;
                return;
        }
        }
        IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
        IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
 
 
        attrib = irias_find_attrib(obj, attr);
        attrib = irias_find_attrib(obj, attr);
        if (attrib == NULL) {
        if (attrib == NULL) {
                IRDA_DEBUG(2, "LM-IAS: Attribute %s not found\n", attr);
                IRDA_DEBUG(2, "LM-IAS: Attribute %s not found\n", attr);
                iriap_getvaluebyclass_response(self, obj->id,
                iriap_getvaluebyclass_response(self, obj->id,
                                               IAS_ATTRIB_UNKNOWN, &missing);
                                               IAS_ATTRIB_UNKNOWN, &missing);
                return;
                return;
        }
        }
 
 
        /* We have a match; send the value.  */
        /* We have a match; send the value.  */
        iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
        iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
                                       attrib->value);
                                       attrib->value);
 
 
        return;
        return;
}
}
 
 
/*
/*
 * Function iriap_send_ack (void)
 * Function iriap_send_ack (void)
 *
 *
 *    Currently not used
 *    Currently not used
 *
 *
 */
 */
void iriap_send_ack(struct iriap_cb *self)
void iriap_send_ack(struct iriap_cb *self)
{
{
        struct sk_buff *skb;
        struct sk_buff *skb;
        __u8 *frame;
        __u8 *frame;
 
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        skb = dev_alloc_skb(64);
        skb = dev_alloc_skb(64);
        if (!skb)
        if (!skb)
                return;
                return;
 
 
        /* Reserve space for MUX and LAP header */
        /* Reserve space for MUX and LAP header */
        skb_reserve(skb, self->max_header_size);
        skb_reserve(skb, self->max_header_size);
        skb_put(skb, 1);
        skb_put(skb, 1);
        frame = skb->data;
        frame = skb->data;
 
 
        /* Build frame */
        /* Build frame */
        frame[0] = IAP_LST | IAP_ACK | self->operation;
        frame[0] = IAP_LST | IAP_ACK | self->operation;
 
 
        irlmp_data_request(self->lsap, skb);
        irlmp_data_request(self->lsap, skb);
}
}
 
 
void iriap_connect_request(struct iriap_cb *self)
void iriap_connect_request(struct iriap_cb *self)
{
{
        int ret;
        int ret;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        ret = irlmp_connect_request(self->lsap, LSAP_IAS,
        ret = irlmp_connect_request(self->lsap, LSAP_IAS,
                                    self->saddr, self->daddr,
                                    self->saddr, self->daddr,
                                    NULL, NULL);
                                    NULL, NULL);
        if (ret < 0) {
        if (ret < 0) {
                IRDA_DEBUG(0, "%s(), connect failed!\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), connect failed!\n", __FUNCTION__);
                self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
                self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
        }
        }
}
}
 
 
/*
/*
 * Function iriap_connect_confirm (handle, skb)
 * Function iriap_connect_confirm (handle, skb)
 *
 *
 *    LSAP connection confirmed!
 *    LSAP connection confirmed!
 *
 *
 */
 */
static void iriap_connect_confirm(void *instance, void *sap,
static void iriap_connect_confirm(void *instance, void *sap,
                                  struct qos_info *qos, __u32 max_seg_size,
                                  struct qos_info *qos, __u32 max_seg_size,
                                  __u8 max_header_size,
                                  __u8 max_header_size,
                                  struct sk_buff *userdata)
                                  struct sk_buff *userdata)
{
{
        struct iriap_cb *self;
        struct iriap_cb *self;
 
 
        self = (struct iriap_cb *) instance;
        self = (struct iriap_cb *) instance;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(userdata != NULL, return;);
        ASSERT(userdata != NULL, return;);
 
 
        self->max_data_size = max_seg_size;
        self->max_data_size = max_seg_size;
        self->max_header_size = max_header_size;
        self->max_header_size = max_header_size;
 
 
        del_timer(&self->watchdog_timer);
        del_timer(&self->watchdog_timer);
 
 
        iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, userdata);
        iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, userdata);
}
}
 
 
/*
/*
 * Function iriap_connect_indication ( handle, skb)
 * Function iriap_connect_indication ( handle, skb)
 *
 *
 *    Remote LM-IAS is requesting connection
 *    Remote LM-IAS is requesting connection
 *
 *
 */
 */
static void iriap_connect_indication(void *instance, void *sap,
static void iriap_connect_indication(void *instance, void *sap,
                                     struct qos_info *qos, __u32 max_seg_size,
                                     struct qos_info *qos, __u32 max_seg_size,
                                     __u8 max_header_size,
                                     __u8 max_header_size,
                                     struct sk_buff *userdata)
                                     struct sk_buff *userdata)
{
{
        struct iriap_cb *self, *new;
        struct iriap_cb *self, *new;
 
 
        IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
 
 
        self = (struct iriap_cb *) instance;
        self = (struct iriap_cb *) instance;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        /* Start new server */
        /* Start new server */
        new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        if (!new) {
        if (!new) {
                IRDA_DEBUG(0, "%s(), open failed\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), open failed\n", __FUNCTION__);
                dev_kfree_skb(userdata);
                dev_kfree_skb(userdata);
                return;
                return;
        }
        }
 
 
        /* Now attach up the new "socket" */
        /* Now attach up the new "socket" */
        new->lsap = irlmp_dup(self->lsap, new);
        new->lsap = irlmp_dup(self->lsap, new);
        if (!new->lsap) {
        if (!new->lsap) {
                IRDA_DEBUG(0, "%s(), dup failed!\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s(), dup failed!\n", __FUNCTION__);
                return;
                return;
        }
        }
 
 
        new->max_data_size = max_seg_size;
        new->max_data_size = max_seg_size;
        new->max_header_size = max_header_size;
        new->max_header_size = max_header_size;
 
 
        /* Clean up the original one to keep it in listen state */
        /* Clean up the original one to keep it in listen state */
        irlmp_listen(self->lsap);
        irlmp_listen(self->lsap);
 
 
        iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, userdata);
        iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, userdata);
}
}
 
 
/*
/*
 * Function iriap_data_indication (handle, skb)
 * Function iriap_data_indication (handle, skb)
 *
 *
 *    Receives data from connection identified by handle from IrLMP
 *    Receives data from connection identified by handle from IrLMP
 *
 *
 */
 */
static int iriap_data_indication(void *instance, void *sap,
static int iriap_data_indication(void *instance, void *sap,
                                 struct sk_buff *skb)
                                 struct sk_buff *skb)
{
{
        struct iriap_cb *self;
        struct iriap_cb *self;
        __u8  *frame;
        __u8  *frame;
        __u8  opcode;
        __u8  opcode;
 
 
        IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
 
        self = (struct iriap_cb *) instance;
        self = (struct iriap_cb *) instance;
 
 
        ASSERT(self != NULL, return 0;);
        ASSERT(self != NULL, return 0;);
        ASSERT(self->magic == IAS_MAGIC, return 0;);
        ASSERT(self->magic == IAS_MAGIC, return 0;);
 
 
        ASSERT(skb != NULL, return 0;);
        ASSERT(skb != NULL, return 0;);
 
 
        frame = skb->data;
        frame = skb->data;
 
 
        if (self->mode == IAS_SERVER) {
        if (self->mode == IAS_SERVER) {
                /* Call server */
                /* Call server */
                IRDA_DEBUG(4, "%s(), Calling server!\n", __FUNCTION__);
                IRDA_DEBUG(4, "%s(), Calling server!\n", __FUNCTION__);
                iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
                iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
 
 
                return 0;
                return 0;
        }
        }
        opcode = frame[0];
        opcode = frame[0];
        if (~opcode & IAP_LST) {
        if (~opcode & IAP_LST) {
                WARNING("%s(), IrIAS multiframe commands or "
                WARNING("%s(), IrIAS multiframe commands or "
                        "results is not implemented yet!\n", __FUNCTION__);
                        "results is not implemented yet!\n", __FUNCTION__);
                dev_kfree_skb(skb);
                dev_kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        /* Check for ack frames since they don't contain any data */
        /* Check for ack frames since they don't contain any data */
        if (opcode & IAP_ACK) {
        if (opcode & IAP_ACK) {
                IRDA_DEBUG(0, "%s() Got ack frame!\n", __FUNCTION__);
                IRDA_DEBUG(0, "%s() Got ack frame!\n", __FUNCTION__);
                dev_kfree_skb(skb);
                dev_kfree_skb(skb);
                return 0;
                return 0;
        }
        }
 
 
        opcode &= ~IAP_LST; /* Mask away LST bit */
        opcode &= ~IAP_LST; /* Mask away LST bit */
 
 
        switch (opcode) {
        switch (opcode) {
        case GET_INFO_BASE:
        case GET_INFO_BASE:
                IRDA_DEBUG(0, "IrLMP GetInfoBaseDetails not implemented!\n");
                IRDA_DEBUG(0, "IrLMP GetInfoBaseDetails not implemented!\n");
                dev_kfree_skb(skb);
                dev_kfree_skb(skb);
                break;
                break;
        case GET_VALUE_BY_CLASS:
        case GET_VALUE_BY_CLASS:
                iriap_do_call_event(self, IAP_RECV_F_LST, NULL);
                iriap_do_call_event(self, IAP_RECV_F_LST, NULL);
 
 
                switch (frame[1]) {
                switch (frame[1]) {
                case IAS_SUCCESS:
                case IAS_SUCCESS:
                        iriap_getvaluebyclass_confirm(self, skb);
                        iriap_getvaluebyclass_confirm(self, skb);
                        break;
                        break;
                case IAS_CLASS_UNKNOWN:
                case IAS_CLASS_UNKNOWN:
                        IRDA_DEBUG(1, "%s(), No such class!\n", __FUNCTION__);
                        IRDA_DEBUG(1, "%s(), No such class!\n", __FUNCTION__);
                        /* Finished, close connection! */
                        /* Finished, close connection! */
                        iriap_disconnect_request(self);
                        iriap_disconnect_request(self);
 
 
                        /*
                        /*
                         * Warning, the client might close us, so remember
                         * Warning, the client might close us, so remember
                         * no to use self anymore after calling confirm
                         * no to use self anymore after calling confirm
                         */
                         */
                        if (self->confirm)
                        if (self->confirm)
                                self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
                                self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
                                              self->priv);
                                              self->priv);
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                        break;
                        break;
                case IAS_ATTRIB_UNKNOWN:
                case IAS_ATTRIB_UNKNOWN:
                        IRDA_DEBUG(1, "%s(), No such attribute!\n", __FUNCTION__);
                        IRDA_DEBUG(1, "%s(), No such attribute!\n", __FUNCTION__);
                        /* Finished, close connection! */
                        /* Finished, close connection! */
                        iriap_disconnect_request(self);
                        iriap_disconnect_request(self);
 
 
                        /*
                        /*
                         * Warning, the client might close us, so remember
                         * Warning, the client might close us, so remember
                         * no to use self anymore after calling confirm
                         * no to use self anymore after calling confirm
                         */
                         */
                        if (self->confirm)
                        if (self->confirm)
                                self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
                                self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
                                              self->priv);
                                              self->priv);
                        dev_kfree_skb(skb);
                        dev_kfree_skb(skb);
                        break;
                        break;
                }
                }
                break;
                break;
        default:
        default:
                IRDA_DEBUG(0, "%s(), Unknown op-code: %02x\n", __FUNCTION__, opcode);
                IRDA_DEBUG(0, "%s(), Unknown op-code: %02x\n", __FUNCTION__, opcode);
                dev_kfree_skb(skb);
                dev_kfree_skb(skb);
                break;
                break;
        }
        }
        return 0;
        return 0;
}
}
 
 
/*
/*
 * Function iriap_call_indication (self, skb)
 * Function iriap_call_indication (self, skb)
 *
 *
 *    Received call to server from peer LM-IAS
 *    Received call to server from peer LM-IAS
 *
 *
 */
 */
void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
{
{
        __u8 *fp;
        __u8 *fp;
        __u8 opcode;
        __u8 opcode;
 
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(skb != NULL, return;);
        ASSERT(skb != NULL, return;);
 
 
        fp = skb->data;
        fp = skb->data;
 
 
        opcode = fp[0];
        opcode = fp[0];
        if (~opcode & 0x80) {
        if (~opcode & 0x80) {
                WARNING("%s(), IrIAS multiframe commands or results"
                WARNING("%s(), IrIAS multiframe commands or results"
                        "is not implemented yet!\n", __FUNCTION__);
                        "is not implemented yet!\n", __FUNCTION__);
                return;
                return;
        }
        }
        opcode &= 0x7f; /* Mask away LST bit */
        opcode &= 0x7f; /* Mask away LST bit */
 
 
        switch (opcode) {
        switch (opcode) {
        case GET_INFO_BASE:
        case GET_INFO_BASE:
                WARNING("%s(), GetInfoBaseDetails not implemented yet!\n",
                WARNING("%s(), GetInfoBaseDetails not implemented yet!\n",
                        __FUNCTION__);
                        __FUNCTION__);
                break;
                break;
        case GET_VALUE_BY_CLASS:
        case GET_VALUE_BY_CLASS:
                iriap_getvaluebyclass_indication(self, skb);
                iriap_getvaluebyclass_indication(self, skb);
                break;
                break;
        }
        }
}
}
 
 
/*
/*
 * Function iriap_watchdog_timer_expired (data)
 * Function iriap_watchdog_timer_expired (data)
 *
 *
 *    Query has taken to long time, so abort
 *    Query has taken to long time, so abort
 *
 *
 */
 */
void iriap_watchdog_timer_expired(void *data)
void iriap_watchdog_timer_expired(void *data)
{
{
        struct iriap_cb *self = (struct iriap_cb *) data;
        struct iriap_cb *self = (struct iriap_cb *) data;
 
 
        ASSERT(self != NULL, return;);
        ASSERT(self != NULL, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
        ASSERT(self->magic == IAS_MAGIC, return;);
 
 
        /* iriap_close(self); */
        /* iriap_close(self); */
}
}
 
 
#ifdef CONFIG_PROC_FS
#ifdef CONFIG_PROC_FS
 
 
static char *ias_value_types[] = {
static char *ias_value_types[] = {
        "IAS_MISSING",
        "IAS_MISSING",
        "IAS_INTEGER",
        "IAS_INTEGER",
        "IAS_OCT_SEQ",
        "IAS_OCT_SEQ",
        "IAS_STRING"
        "IAS_STRING"
};
};
 
 
int irias_proc_read(char *buf, char **start, off_t offset, int len)
int irias_proc_read(char *buf, char **start, off_t offset, int len)
{
{
        struct ias_object *obj;
        struct ias_object *obj;
        struct ias_attrib *attrib;
        struct ias_attrib *attrib;
        unsigned long flags;
        unsigned long flags;
 
 
        ASSERT( objects != NULL, return 0;);
        ASSERT( objects != NULL, return 0;);
 
 
        save_flags( flags);
        save_flags( flags);
        cli();
        cli();
 
 
        len = 0;
        len = 0;
 
 
        len += sprintf(buf+len, "LM-IAS Objects:\n");
        len += sprintf(buf+len, "LM-IAS Objects:\n");
 
 
        /* List all objects */
        /* List all objects */
        obj = (struct ias_object *) hashbin_get_first(objects);
        obj = (struct ias_object *) hashbin_get_first(objects);
        while ( obj != NULL) {
        while ( obj != NULL) {
                ASSERT(obj->magic == IAS_OBJECT_MAGIC, return 0;);
                ASSERT(obj->magic == IAS_OBJECT_MAGIC, return 0;);
 
 
                len += sprintf(buf+len, "name: %s, ", obj->name);
                len += sprintf(buf+len, "name: %s, ", obj->name);
                len += sprintf(buf+len, "id=%d", obj->id);
                len += sprintf(buf+len, "id=%d", obj->id);
                len += sprintf(buf+len, "\n");
                len += sprintf(buf+len, "\n");
 
 
                /* List all attributes for this object */
                /* List all attributes for this object */
                attrib = (struct ias_attrib *)
                attrib = (struct ias_attrib *)
                        hashbin_get_first(obj->attribs);
                        hashbin_get_first(obj->attribs);
                while (attrib != NULL) {
                while (attrib != NULL) {
                        ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return 0;);
                        ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return 0;);
 
 
                        len += sprintf(buf+len, " - Attribute name: \"%s\", ",
                        len += sprintf(buf+len, " - Attribute name: \"%s\", ",
                                       attrib->name);
                                       attrib->name);
                        len += sprintf(buf+len, "value[%s]: ",
                        len += sprintf(buf+len, "value[%s]: ",
                                       ias_value_types[attrib->value->type]);
                                       ias_value_types[attrib->value->type]);
 
 
                        switch (attrib->value->type) {
                        switch (attrib->value->type) {
                        case IAS_INTEGER:
                        case IAS_INTEGER:
                                len += sprintf(buf+len, "%d\n",
                                len += sprintf(buf+len, "%d\n",
                                               attrib->value->t.integer);
                                               attrib->value->t.integer);
                                break;
                                break;
                        case IAS_STRING:
                        case IAS_STRING:
                                len += sprintf(buf+len, "\"%s\"\n",
                                len += sprintf(buf+len, "\"%s\"\n",
                                               attrib->value->t.string);
                                               attrib->value->t.string);
                                break;
                                break;
                        case IAS_OCT_SEQ:
                        case IAS_OCT_SEQ:
                                len += sprintf(buf+len, "octet sequence (%d bytes)\n", attrib->value->len);
                                len += sprintf(buf+len, "octet sequence (%d bytes)\n", attrib->value->len);
                                break;
                                break;
                        case IAS_MISSING:
                        case IAS_MISSING:
                                len += sprintf(buf+len, "missing\n");
                                len += sprintf(buf+len, "missing\n");
                                break;
                                break;
                        default:
                        default:
                                IRDA_DEBUG(0, "%s(), Unknown value type!\n", __FUNCTION__);
                                IRDA_DEBUG(0, "%s(), Unknown value type!\n", __FUNCTION__);
                                return -1;
                                return -1;
                        }
                        }
                        len += sprintf(buf+len, "\n");
                        len += sprintf(buf+len, "\n");
 
 
                        attrib = (struct ias_attrib *)
                        attrib = (struct ias_attrib *)
                                hashbin_get_next(obj->attribs);
                                hashbin_get_next(obj->attribs);
                }
                }
                obj = (struct ias_object *) hashbin_get_next(objects);
                obj = (struct ias_object *) hashbin_get_next(objects);
        }
        }
        restore_flags(flags);
        restore_flags(flags);
 
 
        return len;
        return len;
}
}
 
 
#endif /* PROC_FS */
#endif /* PROC_FS */
 
 

powered by: WebSVN 2.1.0

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