patch-2.2.3 linux/net/irda/iriap.c
Next file: linux/net/irda/iriap_event.c
Previous file: linux/net/irda/irda_device.c
Back to the patch index
Back to the overall index
- Lines: 581
- Date:
Sun Mar 7 15:26:44 1999
- Orig file:
v2.2.2/linux/net/irda/iriap.c
- Orig date:
Wed Jan 20 23:14:07 1999
diff -u --recursive --new-file v2.2.2/linux/net/irda/iriap.c linux/net/irda/iriap.c
@@ -1,12 +1,12 @@
/*********************************************************************
*
* Filename: iriap.c
- * Version: 0.1
+ * Version: 0.8
* Description: Information Access Protocol (IAP)
* Status: Experimental.
* Author: Dag Brattli <dagb@cs.uit.no>
* Created at: Thu Aug 21 00:02:07 1997
- * Modified at: Tue Dec 15 16:00:35 1998
+ * Modified at: Thu Feb 11 01:22:44 1999
* Modified by: Dag Brattli <dagb@cs.uit.no>
*
* Copyright (c) 1998 Dag Brattli <dagb@cs.uit.no>,
@@ -33,18 +33,35 @@
#include <net/irda/irda.h>
#include <net/irda/irttp.h>
+#include <net/irda/irmod.h>
#include <net/irda/irlmp.h>
#include <net/irda/irias_object.h>
#include <net/irda/iriap_event.h>
#include <net/irda/iriap.h>
+/* FIXME: This one should go in irlmp.c */
+static const char *ias_charset_types[] = {
+ "CS_ASCII",
+ "CS_ISO_8859_1",
+ "CS_ISO_8859_2",
+ "CS_ISO_8859_3",
+ "CS_ISO_8859_4",
+ "CS_ISO_8859_5",
+ "CS_ISO_8859_6",
+ "CS_ISO_8859_7",
+ "CS_ISO_8859_8",
+ "CS_ISO_8859_9",
+ "CS_UNICODE"
+};
+
hashbin_t *iriap = NULL;
+extern char *lmp_reasons[];
+
static struct iriap_cb *iriap_open( __u8 slsap, int mode);
static void __iriap_close( struct iriap_cb *self);
-static void iriap_disconnect_indication( void *instance, void *sap,
- LM_REASON reason,
- struct sk_buff *skb);
+static void iriap_disconnect_indication(void *instance, void *sap,
+ LM_REASON reason, struct sk_buff *skb);
/*
* Function iriap_init (void)
@@ -56,7 +73,7 @@
{
struct ias_object *obj;
- DEBUG( 4, "--> iriap_init\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
/* Allocate master array */
iriap = hashbin_new( HB_LOCAL);
@@ -91,8 +108,6 @@
*/
iriap_open( LSAP_IAS, IAS_SERVER);
- DEBUG( 4, "iriap_init -->\n");
-
return 0;
}
@@ -151,14 +166,14 @@
DEBUG( 0, "iriap_open: Unable to allocated LSAP!\n");
return NULL;
}
- DEBUG( 4, "iriap_register: source LSAP sel=%02x\n", slsap_sel);
+ DEBUG( 4, __FUNCTION__ "(), source LSAP sel=%02x\n", slsap_sel);
self->magic = IAS_MAGIC;
self->lsap = lsap;
self->slsap_sel = slsap_sel;
self->mode = mode;
- init_timer( &self->watchdog_timer);
+ /* init_timer( &self->watchdog_timer); */
hashbin_insert( iriap, (QUEUE*) self, slsap_sel, NULL);
@@ -178,10 +193,12 @@
*/
static void __iriap_close( struct iriap_cb *self)
{
+ DEBUG( 4, __FUNCTION__ "()\n");
+
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
- del_timer( &self->watchdog_timer);
+ /* del_timer( &self->watchdog_timer); */
self->magic = 0;
@@ -195,7 +212,9 @@
*/
void iriap_close( struct iriap_cb *self)
{
- DEBUG( 4, "iriap_close()\n");
+ struct iriap_cb *entry;
+
+ DEBUG( 4, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
@@ -205,7 +224,9 @@
self->lsap = NULL;
}
- hashbin_remove( iriap, self->slsap_sel, NULL);
+ entry = (struct iriap_cb *) hashbin_remove( iriap, self->slsap_sel,
+ NULL);
+ ASSERT( entry == self, return;);
__iriap_close( self);
}
@@ -221,7 +242,7 @@
{
struct iriap_cb *self;
- DEBUG( 4, __FUNCTION__ "()\n");
+ DEBUG(4, __FUNCTION__ "(), reason=%s\n", lmp_reasons[reason]);
self = (struct iriap_cb *) instance;
@@ -230,20 +251,24 @@
ASSERT( iriap != NULL, return;);
- del_timer( &self->watchdog_timer);
+ /* del_timer( &self->watchdog_timer); */
if ( self->mode == IAS_CLIENT) {
DEBUG( 4, __FUNCTION__ "(), disconnect as client\n");
- /* Inform service user */
+ /*
+ * Inform service user that the request failed by sending
+ * it a NULL value.
+ */
if ( self->confirm)
- self->confirm( 0, NULL, self->priv);
-
+ self->confirm( 0, NULL, self->priv);
+
+
iriap_do_client_event( self, IAP_LM_DISCONNECT_INDICATION,
NULL);
/* Close instance only if client */
iriap_close( self);
-
+
} else {
DEBUG( 4, __FUNCTION__ "(), disconnect as server\n");
iriap_do_server_event( self, IAP_LM_DISCONNECT_INDICATION,
@@ -265,15 +290,15 @@
{
struct sk_buff *skb;
- DEBUG( 4, "iriap_disconnect_request()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
skb = dev_alloc_skb( 64);
if (skb == NULL) {
- DEBUG( 0,"iriap_getvaluebyclass: "
- "Could not allocate an sk_buff of length %d\n", 64);
+ DEBUG( 0, __FUNCTION__
+ "(), Could not allocate an sk_buff of length %d\n", 64);
return;
}
@@ -316,9 +341,9 @@
* Retreive all values from attribute in all objects with given class
* name
*/
-void iriap_getvaluebyclass_request( __u32 daddr, char *name, char *attr,
- CONFIRM_CALLBACK callback,
- void *priv)
+void iriap_getvaluebyclass_request( char *name, char *attr,
+ __u32 saddr, __u32 daddr,
+ CONFIRM_CALLBACK callback, void *priv)
{
struct sk_buff *skb;
struct iriap_cb *self;
@@ -326,16 +351,18 @@
int name_len, attr_len;
__u8 slsap = LSAP_ANY; /* Source LSAP to use */
- DEBUG( 4, "iriap_getvaluebyclass_request()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
self = iriap_open( slsap, IAS_CLIENT);
- if ( self == NULL)
+ if (!self)
return;
self->mode = IAS_CLIENT;
self->confirm = callback;
self->priv = priv;
+
self->daddr = daddr;
+ self->saddr = saddr;
/*
* Save operation, so we know what the later indication is about
@@ -343,14 +370,11 @@
self->operation = GET_VALUE_BY_CLASS;
/* Give ourselves 7 secs to finish this operation */
- iriap_start_watchdog_timer( self, 700);
+ /* iriap_start_watchdog_timer( self, 700); */
skb = dev_alloc_skb( 64);
- if (skb == NULL) {
- DEBUG( 0,"iriap_getvaluebyclass: "
- "Could not allocate an sk_buff of length %d\n", 64);
+ if (!skb)
return;
- }
name_len = strlen( name);
attr_len = strlen( attr);
@@ -377,8 +401,7 @@
* 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;
__u16 obj_id;
@@ -387,6 +410,7 @@
int value_len;
__u8 *fp;
int n;
+ int charset;
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
@@ -399,7 +423,7 @@
/* Get length, MSB first */
len = ntohs( *(__u16 *)( fp+n)); n += 2;
- DEBUG( 4, "iriap_getvaluebyclass_confirm: len=%d\n", len);
+ DEBUG( 4, __FUNCTION__ "(), len=%d\n", len);
/* Get object ID, MSB first */
obj_id = ntohs( *(__u16 *)( fp+n)); n += 2;
@@ -407,39 +431,54 @@
type = fp[n++];
DEBUG( 4, __FUNCTION__ "(), Value type = %d\n", type);
-
switch( type) {
case IAS_INTEGER:
value = irias_new_integer_value( ntohl(*(__u32 *)(fp+n)));
/*
* Legal values restricted to 0x01-0x6f, page 15 irttp
*/
- DEBUG( 4, "iriap_getvaluebyclass_confirm: lsap=%d\n",
- value->t.integer);
+ DEBUG( 4, __FUNCTION__ "(), lsap=%d\n", value->t.integer);
break;
case IAS_STRING:
- /* FIXME: check len of string, and if string is/should be
- * null terminated? */
- ASSERT( fp[n++] == 0, return;); /* ASCII only! */
+ charset = fp[n++];
+
+ switch(charset) {
+ case CS_ASCII:
+ break;
+/* case CS_ISO_8859_1: */
+/* case CS_ISO_8859_2: */
+/* case CS_ISO_8859_3: */
+/* case CS_ISO_8859_4: */
+/* case CS_ISO_8859_5: */
+/* case CS_ISO_8859_6: */
+/* case CS_ISO_8859_7: */
+/* case CS_ISO_8859_8: */
+/* case CS_ISO_8859_9: */
+/* case CS_UNICODE: */
+ default:
+ DEBUG(0, __FUNCTION__"(), charset %s, not supported\n",
+ ias_charset_types[charset]);
+ return;
+ /* break; */
+ }
value_len = fp[n++];
- DEBUG( 0, __FUNCTION__ "(), strlen=%d\n", value_len);
+ DEBUG(4, __FUNCTION__ "(), strlen=%d\n", value_len);
ASSERT( value_len < 64, return;);
- DEBUG( 0, "Got string %s\n", fp+n);
-
+ /* Make sure the string is null-terminated */
+ fp[n+value_len] = 0x00;
+
+ DEBUG(4, "Got string %s\n", fp+n);
value = irias_new_string_value( fp+n);
-
break;
case IAS_OCT_SEQ:
value_len = ntohs( *(__u16 *)( fp+n)); n += 2;
/* FIXME:should be 1024, but.... */
- DEBUG( 0, __FUNCTION__ "():octet sequence:len=%d\n",
- value_len);
+ DEBUG(0, __FUNCTION__ "():octet sequence:len=%d\n", value_len);
ASSERT(value_len <= 55, return;);
value = irias_new_octseq_value( fp+n, value_len);
-
break;
default:
value = &missing;
@@ -458,39 +497,37 @@
/*
* Function iriap_getvaluebyclass_response ()
*
- * Send answer to getvaluebyclass_indication back to peer LM-IAS
+ * Send answer back to remote LM-IAS
*
*/
-void iriap_getvaluebyclass_response( struct iriap_cb *self,
- __u16 obj_id,
- __u8 ret_code,
- struct ias_value *value)
+void iriap_getvaluebyclass_response(struct iriap_cb *self, __u16 obj_id,
+ __u8 ret_code, struct ias_value *value)
{
struct sk_buff *skb;
__u8 *fp;
int n;
- DEBUG( 4, "iriap_getvaluebyclass_response()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
+ ASSERT( value != NULL, return;);
+ ASSERT( value->len <= 1024, return;);
/* Initialize variables */
n = 0;
/*
- * FIXME: adjust the size of the response after the length of the
- * value
+ * We must adjust the size of the response after the length of the
+ * value. We add 9 bytes because of the 6 bytes for the frame and
+ * max 3 bytes for the value coding.
*/
- skb = dev_alloc_skb( 64);
- if (skb == NULL) {
- DEBUG( 0, __FUNCTION__ "(),"
- "Could not allocate an skb of length %d\n", 64);
+ skb = dev_alloc_skb(value->len + LMP_HEADER + LAP_HEADER + 9);
+ if (!skb)
return;
- }
/* Reserve space for MUX and LAP header */
- skb_reserve( skb, LMP_CONTROL_HEADER+LAP_HEADER);
+ skb_reserve( skb, LMP_HEADER+LAP_HEADER);
skb_put( skb, 6);
fp = skb->data;
@@ -520,13 +557,6 @@
*((__u32 *)(fp+n)) = htonl(value->t.integer); n+=4;
break;
case IAS_OCT_SEQ:
-
- /* FIXME:
- * we can send only 55 octets at this time.
- * we should be able to send 1024 octets. TH
- */
-
- ASSERT(value->len <= 55, return ;);
skb_put( skb, 3 + value->len);
fp[n++] = value->type;
*((__u16 *)(fp+n)) = htons(value->len); n+=2;
@@ -540,8 +570,7 @@
break;
default:
- DEBUG( 0, "iriap_getvaluebyclass_response: "
- "type not implemented!\n");
+ DEBUG(0, __FUNCTION__ "(), type not implemented!\n");
break;
}
iriap_do_r_connect_event( self, IAP_CALL_RESPONSE, skb);
@@ -553,8 +582,8 @@
* getvaluebyclass is requested from peer LM-IAS
*
*/
-void iriap_getvaluebyclass_indication( struct iriap_cb *self,
- struct sk_buff *skb)
+void iriap_getvaluebyclass_indication(struct iriap_cb *self,
+ struct sk_buff *skb)
{
__u8 *fp;
int n;
@@ -562,11 +591,10 @@
int attr_len;
char name[64];
char attr[64];
- char both[128];
struct ias_object *obj;
struct ias_attrib *attrib;
- DEBUG( 4, "iriap_getvaluebyclass_indication()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
@@ -588,30 +616,26 @@
/*
* Now, do some advanced parsing! :-)
*/
- DEBUG( 9, "LM-IAS: Looking up %s: %s\n", name, attr);
-
- sprintf( both, "%s:%s", name, attr);
- DEBUG( 0, "LM-IAS: looking for %s\n", both);
-
- obj = irias_find_object( name);
-
+ DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
+ obj = irias_find_object(name);
+
if ( obj == NULL) {
DEBUG( 0, "LM-IAS: Object not found\n");
iriap_getvaluebyclass_response( self, 0x1235,
IAS_CLASS_UNKNOWN, &missing);
return;
}
- DEBUG( 0, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
+ DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
attrib = irias_find_attrib( obj, attr);
if ( attrib == NULL) {
DEBUG( 0, "LM-IAS: Attribute %s not found\n", attr);
- iriap_getvaluebyclass_response( self, obj->id,
- IAS_ATTRIB_UNKNOWN, &missing);
+ iriap_getvaluebyclass_response(self, obj->id,
+ IAS_ATTRIB_UNKNOWN, &missing);
return;
}
- DEBUG( 0, "LM-IAS: found %s\n", attrib->name);
+ DEBUG(4, "LM-IAS: found %s\n", attrib->name);
/*
* We have a match; send the value.
@@ -633,17 +657,14 @@
struct sk_buff *skb;
__u8 *frame;
- DEBUG( 6, "iriap_send_ack()\n");
+ DEBUG( 6, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
- skb = dev_alloc_skb( 64);
- if (skb == NULL) {
- DEBUG( 0, "iriap_send_ack: "
- "Could not allocate an sk_buff of length %d\n", 64);
+ skb = dev_alloc_skb( 64);
+ if (!skb)
return;
- }
/* Reserve space for MUX and LAP header */
skb_reserve( skb, 4);
@@ -671,9 +692,9 @@
ASSERT( self->magic == IAS_MAGIC, return;);
ASSERT( userdata != NULL, return;);
- DEBUG( 4, "iriap_connect_confirm()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
- del_timer( &self->watchdog_timer);
+ /* del_timer( &self->watchdog_timer); */
iriap_do_client_event( self, IAP_LM_CONNECT_CONFIRM, userdata);
}
@@ -684,13 +705,12 @@
* Remote LM-IAS is requesting connection
*
*/
-void iriap_connect_indication( void *instance, void *sap,
- struct qos_info *qos, int max_sdu_size,
- struct sk_buff *userdata)
+void iriap_connect_indication(void *instance, void *sap, struct qos_info *qos,
+ int max_sdu_size, struct sk_buff *userdata)
{
struct iriap_cb *self;
- DEBUG( 4, "iriap_connect_indication()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
self = ( struct iriap_cb *) instance;
@@ -713,7 +733,7 @@
__u8 *frame;
__u8 opcode;
- DEBUG( 4, "iriap_data_indication()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
self = ( struct iriap_cb *) instance;
@@ -769,8 +789,7 @@
iriap_close( self);
break;
default:
- DEBUG( 0, "iriap_data_indication: Unknown op-code: %02x\n",
- opcode);
+ DEBUG(0, __FUNCTION__ "(), Unknown op-code: %02x\n", opcode);
break;
}
}
@@ -786,7 +805,7 @@
__u8 *fp;
__u8 opcode;
- DEBUG( 4, "iriap_call_indication()\n");
+ DEBUG( 4, __FUNCTION__ "()\n");
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
@@ -816,7 +835,9 @@
{
struct iriap_cb *self = ( struct iriap_cb *) data;
- DEBUG( 4, __FUNCTION__ "()\n");
+ DEBUG( 0, __FUNCTION__ "()\n");
+
+ return;
ASSERT( self != NULL, return;);
ASSERT( self->magic == IAS_MAGIC, return;);
@@ -834,23 +855,7 @@
"IAS_STRING"
};
-/* FIXME: This one should go in irlmp.c */
-static char *ias_charset_types[] = {
- "CS_ASCII",
- "CS_ISO_8859_1",
- "CS_ISO_8859_2",
- "CS_ISO_8859_3",
- "CS_ISO_8859_4",
- "CS_ISO_8859_5",
- "CS_ISO_8859_6",
- "CS_ISO_8859_7",
- "CS_ISO_8859_8",
- "CS_ISO_8859_9",
- "CS_UNICODE"
-};
-
-int irias_proc_read( char *buf, char **start, off_t offset, int len,
- int unused)
+int irias_proc_read(char *buf, char **start, off_t offset, int len, int unused)
{
struct ias_object *obj;
struct ias_attrib *attrib;
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)