- pre3:
[davej-history.git] / net / irda / iriap.c
blob03014ac0d478ec5d436403c5c555830ce1fae19f
1 /*********************************************************************
2 *
3 * Filename: iriap.c
4 * Version: 0.8
5 * Description: Information Access Protocol (IAP)
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Thu Aug 21 00:02:07 1997
9 * Modified at: Sat Dec 25 16:42:42 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * Neither Dag Brattli nor University of Tromsø admit liability nor
21 * provide warranty for any of this software. This material is
22 * provided "AS-IS" and at no charge.
24 ********************************************************************/
26 #include <linux/config.h>
27 #include <linux/types.h>
28 #include <linux/skbuff.h>
29 #include <linux/string.h>
30 #include <linux/init.h>
32 #include <asm/byteorder.h>
33 #include <asm/unaligned.h>
35 #include <net/irda/irda.h>
36 #include <net/irda/irttp.h>
37 #include <net/irda/irmod.h>
38 #include <net/irda/irlmp.h>
39 #include <net/irda/irias_object.h>
40 #include <net/irda/iriap_event.h>
41 #include <net/irda/iriap.h>
43 /* FIXME: This one should go in irlmp.c */
44 static const char *ias_charset_types[] = {
45 "CS_ASCII",
46 "CS_ISO_8859_1",
47 "CS_ISO_8859_2",
48 "CS_ISO_8859_3",
49 "CS_ISO_8859_4",
50 "CS_ISO_8859_5",
51 "CS_ISO_8859_6",
52 "CS_ISO_8859_7",
53 "CS_ISO_8859_8",
54 "CS_ISO_8859_9",
55 "CS_UNICODE"
58 static hashbin_t *iriap = NULL;
59 static __u32 service_handle;
61 extern char *lmp_reasons[];
63 static void __iriap_close(struct iriap_cb *self);
64 static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode);
65 static void iriap_disconnect_indication(void *instance, void *sap,
66 LM_REASON reason, struct sk_buff *skb);
67 static void iriap_connect_indication(void *instance, void *sap,
68 struct qos_info *qos, __u32 max_sdu_size,
69 __u8 max_header_size,
70 struct sk_buff *skb);
71 static void iriap_connect_confirm(void *instance, void *sap,
72 struct qos_info *qos,
73 __u32 max_sdu_size, __u8 max_header_size,
74 struct sk_buff *skb);
75 static int iriap_data_indication(void *instance, void *sap,
76 struct sk_buff *skb);
79 * Function iriap_init (void)
81 * Initializes the IrIAP layer, called by the module initialization code
82 * in irmod.c
84 int __init iriap_init(void)
86 struct ias_object *obj;
87 struct iriap_cb *server;
88 __u8 oct_seq[6];
89 __u16 hints;
91 /* Allocate master array */
92 iriap = hashbin_new(HB_LOCAL);
93 if (!iriap)
94 return -ENOMEM;
96 objects = hashbin_new(HB_LOCAL);
97 if (!objects) {
98 WARNING(__FUNCTION__ "(), Can't allocate objects hashbin!\n");
99 return -ENOMEM;
103 * Register some default services for IrLMP
105 hints = irlmp_service_to_hint(S_COMPUTER);
106 service_handle = irlmp_register_service(hints);
108 /* Register the Device object with LM-IAS */
109 obj = irias_new_object("Device", IAS_DEVICE_ID);
110 irias_add_string_attrib(obj, "DeviceName", "Linux", IAS_KERNEL_ATTR);
112 oct_seq[0] = 0x01; /* Version 1 */
113 oct_seq[1] = 0x00; /* IAS support bits */
114 oct_seq[2] = 0x00; /* LM-MUX support bits */
115 #ifdef CONFIG_IRDA_ULTRA
116 oct_seq[2] |= 0x04; /* Connectionless Data support */
117 #endif
118 irias_add_octseq_attrib(obj, "IrLMPSupport", oct_seq, 3,
119 IAS_KERNEL_ATTR);
120 irias_insert_object(obj);
123 * Register server support with IrLMP so we can accept incoming
124 * connections
126 server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
127 if (!server) {
128 IRDA_DEBUG(0, __FUNCTION__ "(), unable to open server\n");
129 return -1;
131 iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
133 return 0;
137 * Function iriap_cleanup (void)
139 * Initializes the IrIAP layer, called by the module cleanup code in
140 * irmod.c
142 void iriap_cleanup(void)
144 irlmp_unregister_service(service_handle);
146 hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
147 hashbin_delete(objects, (FREE_FUNC) __irias_delete_object);
151 * Function iriap_open (void)
153 * Opens an instance of the IrIAP layer, and registers with IrLMP
155 struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
156 CONFIRM_CALLBACK callback)
158 struct iriap_cb *self;
160 IRDA_DEBUG(2, __FUNCTION__ "()\n");
162 self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
163 if (!self) {
164 WARNING(__FUNCTION__ "(), Unable to kmalloc!\n");
165 return NULL;
169 * Initialize instance
171 memset(self, 0, sizeof(struct iriap_cb));
173 self->magic = IAS_MAGIC;
174 self->mode = mode;
175 if (mode == IAS_CLIENT)
176 iriap_register_lsap(self, slsap_sel, mode);
178 self->confirm = callback;
179 self->priv = priv;
181 init_timer(&self->watchdog_timer);
183 hashbin_insert(iriap, (irda_queue_t *) self, (int) self, NULL);
185 /* Initialize state machines */
186 iriap_next_client_state(self, S_DISCONNECT);
187 iriap_next_call_state(self, S_MAKE_CALL);
188 iriap_next_server_state(self, R_DISCONNECT);
189 iriap_next_r_connect_state(self, R_WAITING);
191 return self;
195 * Function __iriap_close (self)
197 * Removes (deallocates) the IrIAP instance
200 static void __iriap_close(struct iriap_cb *self)
202 IRDA_DEBUG(4, __FUNCTION__ "()\n");
204 ASSERT(self != NULL, return;);
205 ASSERT(self->magic == IAS_MAGIC, return;);
207 del_timer(&self->watchdog_timer);
209 if (self->skb)
210 dev_kfree_skb(self->skb);
212 self->magic = 0;
214 kfree(self);
218 * Function iriap_close (void)
220 * Closes IrIAP and deregisters with IrLMP
222 void iriap_close(struct iriap_cb *self)
224 struct iriap_cb *entry;
226 IRDA_DEBUG(2, __FUNCTION__ "()\n");
228 ASSERT(self != NULL, return;);
229 ASSERT(self->magic == IAS_MAGIC, return;);
231 if (self->lsap) {
232 irlmp_close_lsap(self->lsap);
233 self->lsap = NULL;
236 entry = (struct iriap_cb *) hashbin_remove(iriap, (int) self, NULL);
237 ASSERT(entry == self, return;);
239 __iriap_close(self);
242 static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
244 notify_t notify;
246 IRDA_DEBUG(2, __FUNCTION__ "()\n");
248 irda_notify_init(&notify);
249 notify.connect_confirm = iriap_connect_confirm;
250 notify.connect_indication = iriap_connect_indication;
251 notify.disconnect_indication = iriap_disconnect_indication;
252 notify.data_indication = iriap_data_indication;
253 notify.instance = self;
254 if (mode == IAS_CLIENT)
255 strcpy(notify.name, "IrIAS cli");
256 else
257 strcpy(notify.name, "IrIAS srv");
259 self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
260 if (self->lsap == NULL) {
261 ERROR(__FUNCTION__ "(), Unable to allocated LSAP!\n");
262 return -1;
264 self->slsap_sel = self->lsap->slsap_sel;
266 return 0;
270 * Function iriap_disconnect_indication (handle, reason)
272 * Got disconnect, so clean up everything assosiated with this connection
275 static void iriap_disconnect_indication(void *instance, void *sap,
276 LM_REASON reason,
277 struct sk_buff *userdata)
279 struct iriap_cb *self;
281 IRDA_DEBUG(4, __FUNCTION__ "(), reason=%s\n", lmp_reasons[reason]);
283 self = (struct iriap_cb *) instance;
285 ASSERT(self != NULL, return;);
286 ASSERT(self->magic == IAS_MAGIC, return;);
288 ASSERT(iriap != NULL, return;);
290 del_timer(&self->watchdog_timer);
292 if (self->mode == IAS_CLIENT) {
293 IRDA_DEBUG(4, __FUNCTION__ "(), disconnect as client\n");
296 iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
297 NULL);
299 * Inform service user that the request failed by sending
300 * it a NULL value. Warning, the client might close us, so
301 * remember no to use self anymore after calling confirm
303 if (self->confirm)
304 self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
305 } else {
306 IRDA_DEBUG(4, __FUNCTION__ "(), disconnect as server\n");
307 iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
308 NULL);
309 iriap_close(self);
312 if (userdata)
313 dev_kfree_skb(userdata);
317 * Function iriap_disconnect_request (handle)
322 void iriap_disconnect_request(struct iriap_cb *self)
324 struct sk_buff *skb;
326 IRDA_DEBUG(4, __FUNCTION__ "()\n");
328 ASSERT(self != NULL, return;);
329 ASSERT(self->magic == IAS_MAGIC, return;);
331 skb = dev_alloc_skb(64);
332 if (skb == NULL) {
333 IRDA_DEBUG(0, __FUNCTION__
334 "(), Could not allocate an sk_buff of length %d\n", 64);
335 return;
339 * Reserve space for MUX control and LAP header
341 skb_reserve(skb, LMP_MAX_HEADER);
343 irlmp_disconnect_request(self->lsap, skb);
346 void iriap_getinfobasedetails_request(void)
348 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
351 void iriap_getinfobasedetails_confirm(void)
353 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
356 void iriap_getobjects_request(void)
358 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
361 void iriap_getobjects_confirm(void)
363 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
366 void iriap_getvalue(void)
368 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
372 * Function iriap_getvaluebyclass (addr, name, attr)
374 * Retreive all values from attribute in all objects with given class
375 * name
377 int iriap_getvaluebyclass_request(struct iriap_cb *self,
378 __u32 saddr, __u32 daddr,
379 char *name, char *attr)
381 struct sk_buff *skb;
382 int name_len, attr_len;
383 __u8 *frame;
385 ASSERT(self != NULL, return -1;);
386 ASSERT(self->magic == IAS_MAGIC, return -1;);
388 /* Client must supply the destination device address */
389 if (!daddr)
390 return -1;
392 self->daddr = daddr;
393 self->saddr = saddr;
396 * Save operation, so we know what the later indication is about
398 self->operation = GET_VALUE_BY_CLASS;
400 /* Give ourselves 10 secs to finish this operation */
401 iriap_start_watchdog_timer(self, 10*HZ);
403 skb = dev_alloc_skb(64);
404 if (!skb)
405 return -ENOMEM;
407 name_len = strlen(name);
408 attr_len = strlen(attr);
410 /* Reserve space for MUX and LAP header */
411 skb_reserve(skb, self->max_header_size);
412 skb_put(skb, 3+name_len+attr_len);
413 frame = skb->data;
415 /* Build frame */
416 frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
417 frame[1] = name_len; /* Insert length of name */
418 memcpy(frame+2, name, name_len); /* Insert name */
419 frame[2+name_len] = attr_len; /* Insert length of attr */
420 memcpy(frame+3+name_len, attr, attr_len); /* Insert attr */
422 iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, skb);
424 return 0;
428 * Function iriap_getvaluebyclass_confirm (self, skb)
430 * Got result from GetValueByClass command. Parse it and return result
431 * to service user.
434 void iriap_getvaluebyclass_confirm(struct iriap_cb *self, struct sk_buff *skb)
436 struct ias_value *value;
437 int charset;
438 __u32 value_len;
439 __u32 tmp_cpu32;
440 __u16 obj_id;
441 __u16 len;
442 __u8 type;
443 __u8 *fp;
444 int n;
446 ASSERT(self != NULL, return;);
447 ASSERT(self->magic == IAS_MAGIC, return;);
448 ASSERT(skb != NULL, return;);
450 /* Initialize variables */
451 fp = skb->data;
452 n = 2;
454 /* Get length, MSB first */
455 len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
457 IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
459 /* Get object ID, MSB first */
460 obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
462 type = fp[n++];
463 IRDA_DEBUG(4, __FUNCTION__ "(), Value type = %d\n", type);
465 switch (type) {
466 case IAS_INTEGER:
467 memcpy(&tmp_cpu32, fp+n, 4); n += 4;
468 be32_to_cpus(&tmp_cpu32);
469 value = irias_new_integer_value(tmp_cpu32);
471 /* Legal values restricted to 0x01-0x6f, page 15 irttp */
472 IRDA_DEBUG(4, __FUNCTION__ "(), lsap=%d\n", value->t.integer);
473 break;
474 case IAS_STRING:
475 charset = fp[n++];
477 switch (charset) {
478 case CS_ASCII:
479 break;
480 /* case CS_ISO_8859_1: */
481 /* case CS_ISO_8859_2: */
482 /* case CS_ISO_8859_3: */
483 /* case CS_ISO_8859_4: */
484 /* case CS_ISO_8859_5: */
485 /* case CS_ISO_8859_6: */
486 /* case CS_ISO_8859_7: */
487 /* case CS_ISO_8859_8: */
488 /* case CS_ISO_8859_9: */
489 /* case CS_UNICODE: */
490 default:
491 IRDA_DEBUG(0, __FUNCTION__
492 "(), charset %s, not supported\n",
493 ias_charset_types[charset]);
495 /* Aborting, close connection! */
496 iriap_disconnect_request(self);
497 dev_kfree_skb(skb);
498 return;
499 /* break; */
501 value_len = fp[n++];
502 IRDA_DEBUG(4, __FUNCTION__ "(), strlen=%d\n", value_len);
503 ASSERT(value_len < 64, return;);
505 /* Make sure the string is null-terminated */
506 fp[n+value_len] = 0x00;
508 IRDA_DEBUG(4, "Got string %s\n", fp+n);
509 value = irias_new_string_value(fp+n);
510 break;
511 case IAS_OCT_SEQ:
512 value_len = be16_to_cpu(get_unaligned((__u16 *)(fp+n)));
513 n += 2;
515 ASSERT(value_len <= 55, return;);
517 value = irias_new_octseq_value(fp+n, value_len);
518 break;
519 default:
520 value = irias_new_missing_value();
521 break;
524 /* Finished, close connection! */
525 iriap_disconnect_request(self);
527 /* Warning, the client might close us, so remember no to use self
528 * anymore after calling confirm
530 if (self->confirm)
531 self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
532 else {
533 IRDA_DEBUG(0, __FUNCTION__ "(), missing handler!\n");
534 irias_delete_value(value);
536 dev_kfree_skb(skb);
540 * Function iriap_getvaluebyclass_response ()
542 * Send answer back to remote LM-IAS
545 void iriap_getvaluebyclass_response(struct iriap_cb *self, __u16 obj_id,
546 __u8 ret_code, struct ias_value *value)
548 struct sk_buff *skb;
549 int n;
550 __u32 tmp_be32, tmp_be16;
551 __u8 *fp;
553 IRDA_DEBUG(4, __FUNCTION__ "()\n");
555 ASSERT(self != NULL, return;);
556 ASSERT(self->magic == IAS_MAGIC, return;);
557 ASSERT(value != NULL, return;);
558 ASSERT(value->len <= 1024, return;);
560 /* Initialize variables */
561 n = 0;
564 * We must adjust the size of the response after the length of the
565 * value. We add 32 bytes because of the 6 bytes for the frame and
566 * max 5 bytes for the value coding.
568 skb = dev_alloc_skb(value->len + self->max_header_size + 32);
569 if (!skb)
570 return;
572 /* Reserve space for MUX and LAP header */
573 skb_reserve(skb, self->max_header_size);
574 skb_put(skb, 6);
576 fp = skb->data;
578 /* Build frame */
579 fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
580 fp[n++] = ret_code;
582 /* Insert list length (MSB first) */
583 tmp_be16 = __constant_htons(0x0001);
584 memcpy(fp+n, &tmp_be16, 2); n += 2;
586 /* Insert object identifier ( MSB first) */
587 tmp_be16 = cpu_to_be16(obj_id);
588 memcpy(fp+n, &tmp_be16, 2); n += 2;
590 switch (value->type) {
591 case IAS_STRING:
592 skb_put(skb, 3 + value->len);
593 fp[n++] = value->type;
594 fp[n++] = 0; /* ASCII */
595 fp[n++] = (__u8) value->len;
596 memcpy(fp+n, value->t.string, value->len); n+=value->len;
597 break;
598 case IAS_INTEGER:
599 skb_put(skb, 5);
600 fp[n++] = value->type;
602 tmp_be32 = cpu_to_be32(value->t.integer);
603 memcpy(fp+n, &tmp_be32, 4); n += 4;
604 break;
605 case IAS_OCT_SEQ:
606 skb_put(skb, 3 + value->len);
607 fp[n++] = value->type;
609 tmp_be16 = cpu_to_be16(value->len);
610 memcpy(fp+n, &tmp_be16, 2); n += 2;
611 memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
612 break;
613 case IAS_MISSING:
614 IRDA_DEBUG( 3, __FUNCTION__ ": sending IAS_MISSING\n");
615 skb_put(skb, 1);
616 fp[n++] = value->type;
617 break;
618 default:
619 IRDA_DEBUG(0, __FUNCTION__ "(), type not implemented!\n");
620 break;
622 iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, skb);
626 * Function iriap_getvaluebyclass_indication (self, skb)
628 * getvaluebyclass is requested from peer LM-IAS
631 void iriap_getvaluebyclass_indication(struct iriap_cb *self,
632 struct sk_buff *skb)
634 struct ias_object *obj;
635 struct ias_attrib *attrib;
636 int name_len;
637 int attr_len;
638 char name[64];
639 char attr[64];
640 __u8 *fp;
641 int n;
643 IRDA_DEBUG(4, __FUNCTION__ "()\n");
645 ASSERT(self != NULL, return;);
646 ASSERT(self->magic == IAS_MAGIC, return;);
647 ASSERT(skb != NULL, return;);
649 fp = skb->data;
650 n = 1;
652 name_len = fp[n++];
653 memcpy(name, fp+n, name_len); n+=name_len;
654 name[name_len] = '\0';
656 attr_len = fp[n++];
657 memcpy(attr, fp+n, attr_len); n+=attr_len;
658 attr[attr_len] = '\0';
660 /* We do not need the buffer anymore */
661 dev_kfree_skb(skb);
663 IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
664 obj = irias_find_object(name);
666 if (obj == NULL) {
667 IRDA_DEBUG(2, "LM-IAS: Object %s not found\n", name);
668 iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
669 &missing);
670 return;
672 IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
674 attrib = irias_find_attrib(obj, attr);
675 if (attrib == NULL) {
676 IRDA_DEBUG(2, "LM-IAS: Attribute %s not found\n", attr);
677 iriap_getvaluebyclass_response(self, obj->id,
678 IAS_ATTRIB_UNKNOWN, &missing);
679 return;
682 /* We have a match; send the value. */
683 iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
684 attrib->value);
686 return;
690 * Function iriap_send_ack (void)
692 * Currently not used
695 void iriap_send_ack(struct iriap_cb *self)
697 struct sk_buff *skb;
698 __u8 *frame;
700 IRDA_DEBUG(2, __FUNCTION__ "()\n");
702 ASSERT(self != NULL, return;);
703 ASSERT(self->magic == IAS_MAGIC, return;);
705 skb = dev_alloc_skb(64);
706 if (!skb)
707 return;
709 /* Reserve space for MUX and LAP header */
710 skb_reserve(skb, self->max_header_size);
711 skb_put(skb, 1);
712 frame = skb->data;
714 /* Build frame */
715 frame[0] = IAP_LST | IAP_ACK | self->operation;
717 irlmp_data_request(self->lsap, skb);
720 void iriap_connect_request(struct iriap_cb *self)
722 int ret;
724 ASSERT(self != NULL, return;);
725 ASSERT(self->magic == IAS_MAGIC, return;);
727 ret = irlmp_connect_request(self->lsap, LSAP_IAS,
728 self->saddr, self->daddr,
729 NULL, NULL);
730 if (ret < 0) {
731 IRDA_DEBUG(0, __FUNCTION__ "(), connect failed!\n");
732 self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
737 * Function iriap_connect_confirm (handle, skb)
739 * LSAP connection confirmed!
742 static void iriap_connect_confirm(void *instance, void *sap,
743 struct qos_info *qos, __u32 max_seg_size,
744 __u8 max_header_size,
745 struct sk_buff *userdata)
747 struct iriap_cb *self;
749 self = (struct iriap_cb *) instance;
751 ASSERT(self != NULL, return;);
752 ASSERT(self->magic == IAS_MAGIC, return;);
753 ASSERT(userdata != NULL, return;);
755 self->max_data_size = max_seg_size;
756 self->max_header_size = max_header_size;
758 del_timer(&self->watchdog_timer);
760 iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, userdata);
764 * Function iriap_connect_indication ( handle, skb)
766 * Remote LM-IAS is requesting connection
769 static void iriap_connect_indication(void *instance, void *sap,
770 struct qos_info *qos, __u32 max_seg_size,
771 __u8 max_header_size,
772 struct sk_buff *userdata)
774 struct iriap_cb *self, *new;
776 IRDA_DEBUG(0, __FUNCTION__ "()\n");
778 self = (struct iriap_cb *) instance;
780 ASSERT(self != NULL, return;);
781 ASSERT(self->magic == IAS_MAGIC, return;);
783 /* Start new server */
784 new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
785 if (!new) {
786 IRDA_DEBUG(0, __FUNCTION__ "(), open failed\n");
787 dev_kfree_skb(userdata);
788 return;
791 /* Now attach up the new "socket" */
792 new->lsap = irlmp_dup(self->lsap, new);
793 if (!new->lsap) {
794 IRDA_DEBUG(0, __FUNCTION__ "(), dup failed!\n");
795 return;
798 new->max_data_size = max_seg_size;
799 new->max_header_size = max_header_size;
801 /* Clean up the original one to keep it in listen state */
802 self->lsap->dlsap_sel = LSAP_ANY;
803 self->lsap->lsap_state = LSAP_DISCONNECTED;
804 /* FIXME: refcount in irlmp might get wrong */
806 iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, userdata);
810 * Function iriap_data_indication (handle, skb)
812 * Receives data from connection identified by handle from IrLMP
815 static int iriap_data_indication(void *instance, void *sap,
816 struct sk_buff *skb)
818 struct iriap_cb *self;
819 __u8 *frame;
820 __u8 opcode;
822 IRDA_DEBUG(3, __FUNCTION__ "()\n");
824 self = (struct iriap_cb *) instance;
826 ASSERT(self != NULL, return 0;);
827 ASSERT(self->magic == IAS_MAGIC, return 0;);
829 ASSERT(skb != NULL, return 0;);
831 frame = skb->data;
833 if (self->mode == IAS_SERVER) {
834 /* Call server */
835 IRDA_DEBUG(4, __FUNCTION__ "(), Calling server!\n");
836 iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
838 return 0;
840 opcode = frame[0];
841 if (~opcode & IAP_LST) {
842 WARNING(__FUNCTION__ "(), IrIAS multiframe commands or "
843 "results is not implemented yet!\n");
844 dev_kfree_skb(skb);
845 return 0;
848 /* Check for ack frames since they don't contain any data */
849 if (opcode & IAP_ACK) {
850 IRDA_DEBUG(0, __FUNCTION__ "() Got ack frame!\n");
851 dev_kfree_skb(skb);
852 return 0;
855 opcode &= ~IAP_LST; /* Mask away LST bit */
857 switch (opcode) {
858 case GET_INFO_BASE:
859 IRDA_DEBUG(0, "IrLMP GetInfoBaseDetails not implemented!\n");
860 dev_kfree_skb(skb);
861 break;
862 case GET_VALUE_BY_CLASS:
863 iriap_do_call_event(self, IAP_RECV_F_LST, NULL);
865 switch (frame[1]) {
866 case IAS_SUCCESS:
867 iriap_getvaluebyclass_confirm(self, skb);
868 break;
869 case IAS_CLASS_UNKNOWN:
870 IRDA_DEBUG(1, __FUNCTION__ "(), No such class!\n");
871 /* Finished, close connection! */
872 iriap_disconnect_request(self);
875 * Warning, the client might close us, so remember
876 * no to use self anymore after calling confirm
878 if (self->confirm)
879 self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
880 self->priv);
881 dev_kfree_skb(skb);
882 break;
883 case IAS_ATTRIB_UNKNOWN:
884 IRDA_DEBUG(1, __FUNCTION__ "(), No such attribute!\n");
885 /* Finished, close connection! */
886 iriap_disconnect_request(self);
889 * Warning, the client might close us, so remember
890 * no to use self anymore after calling confirm
892 if (self->confirm)
893 self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
894 self->priv);
895 dev_kfree_skb(skb);
896 break;
898 break;
899 default:
900 IRDA_DEBUG(0, __FUNCTION__ "(), Unknown op-code: %02x\n",
901 opcode);
902 dev_kfree_skb(skb);
903 break;
905 return 0;
909 * Function iriap_call_indication (self, skb)
911 * Received call to server from peer LM-IAS
914 void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
916 __u8 *fp;
917 __u8 opcode;
919 IRDA_DEBUG(4, __FUNCTION__ "()\n");
921 ASSERT(self != NULL, return;);
922 ASSERT(self->magic == IAS_MAGIC, return;);
923 ASSERT(skb != NULL, return;);
925 fp = skb->data;
927 opcode = fp[0];
928 if (~opcode & 0x80) {
929 WARNING(__FUNCTION__ "(), IrIAS multiframe commands or results"
930 "is not implemented yet!\n");
931 return;
933 opcode &= 0x7f; /* Mask away LST bit */
935 switch (opcode) {
936 case GET_INFO_BASE:
937 WARNING(__FUNCTION__
938 "(), GetInfoBaseDetails not implemented yet!\n");
939 break;
940 case GET_VALUE_BY_CLASS:
941 iriap_getvaluebyclass_indication(self, skb);
942 break;
947 * Function iriap_watchdog_timer_expired (data)
949 * Query has taken to long time, so abort
952 void iriap_watchdog_timer_expired(void *data)
954 struct iriap_cb *self = (struct iriap_cb *) data;
956 ASSERT(self != NULL, return;);
957 ASSERT(self->magic == IAS_MAGIC, return;);
959 /* iriap_close(self); */
962 #ifdef CONFIG_PROC_FS
964 static char *ias_value_types[] = {
965 "IAS_MISSING",
966 "IAS_INTEGER",
967 "IAS_OCT_SEQ",
968 "IAS_STRING"
971 int irias_proc_read(char *buf, char **start, off_t offset, int len)
973 struct ias_object *obj;
974 struct ias_attrib *attrib;
975 unsigned long flags;
977 ASSERT( objects != NULL, return 0;);
979 save_flags( flags);
980 cli();
982 len = 0;
984 len += sprintf(buf+len, "LM-IAS Objects:\n");
986 /* List all objects */
987 obj = (struct ias_object *) hashbin_get_first(objects);
988 while ( obj != NULL) {
989 ASSERT(obj->magic == IAS_OBJECT_MAGIC, return 0;);
991 len += sprintf(buf+len, "name: %s, ", obj->name);
992 len += sprintf(buf+len, "id=%d", obj->id);
993 len += sprintf(buf+len, "\n");
995 /* List all attributes for this object */
996 attrib = (struct ias_attrib *)
997 hashbin_get_first(obj->attribs);
998 while (attrib != NULL) {
999 ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return 0;);
1001 len += sprintf(buf+len, " - Attribute name: \"%s\", ",
1002 attrib->name);
1003 len += sprintf(buf+len, "value[%s]: ",
1004 ias_value_types[attrib->value->type]);
1006 switch (attrib->value->type) {
1007 case IAS_INTEGER:
1008 len += sprintf(buf+len, "%d\n",
1009 attrib->value->t.integer);
1010 break;
1011 case IAS_STRING:
1012 len += sprintf(buf+len, "\"%s\"\n",
1013 attrib->value->t.string);
1014 break;
1015 case IAS_OCT_SEQ:
1016 len += sprintf(buf+len, "octet sequence\n");
1017 break;
1018 case IAS_MISSING:
1019 len += sprintf(buf+len, "missing\n");
1020 break;
1021 default:
1022 IRDA_DEBUG(0, __FUNCTION__
1023 "(), Unknown value type!\n");
1024 return -1;
1026 len += sprintf(buf+len, "\n");
1028 attrib = (struct ias_attrib *)
1029 hashbin_get_next(obj->attribs);
1031 obj = (struct ias_object *) hashbin_get_next(objects);
1033 restore_flags(flags);
1035 return len;
1038 #endif /* PROC_FS */