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>
11 *
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 *
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.
19 *
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.
23 *
24 ********************************************************************/
25
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>
31
32 #include <asm/byteorder.h>
33 #include <asm/unaligned.h>
34
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>
42
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"
56 };
57
58 static hashbin_t *iriap = NULL;
59 static __u32 service_handle;
60
61 extern char *lmp_reasons[];
62
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);
77
78 /*
79 * Function iriap_init (void)
80 *
81 * Initializes the IrIAP layer, called by the module initialization code
82 * in irmod.c
83 */
84 int __init iriap_init(void)
85 {
86 struct ias_object *obj;
87 struct iriap_cb *server;
88 __u8 oct_seq[6];
89 __u16 hints;
90
91 /* Allocate master array */
92 iriap = hashbin_new(HB_LOCAL);
93 if (!iriap)
94 return -ENOMEM;
95
96 objects = hashbin_new(HB_LOCAL);
97 if (!objects) {
98 WARNING(__FUNCTION__ "(), Can't allocate objects hashbin!\n");
99 return -ENOMEM;
100 }
101
102 /*
103 * Register some default services for IrLMP
104 */
105 hints = irlmp_service_to_hint(S_COMPUTER);
106 service_handle = irlmp_register_service(hints);
107
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);
111
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);
121
122 /*
123 * Register server support with IrLMP so we can accept incoming
124 * connections
125 */
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;
130 }
131 iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
132
133 return 0;
134 }
135
136 /*
137 * Function iriap_cleanup (void)
138 *
139 * Initializes the IrIAP layer, called by the module cleanup code in
140 * irmod.c
141 */
142 void iriap_cleanup(void)
143 {
144 irlmp_unregister_service(service_handle);
145
146 hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
147 hashbin_delete(objects, (FREE_FUNC) __irias_delete_object);
148 }
149
150 /*
151 * Function iriap_open (void)
152 *
153 * Opens an instance of the IrIAP layer, and registers with IrLMP
154 */
155 struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
156 CONFIRM_CALLBACK callback)
157 {
158 struct iriap_cb *self;
159
160 IRDA_DEBUG(2, __FUNCTION__ "()\n");
161
162 self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
163 if (!self) {
164 WARNING(__FUNCTION__ "(), Unable to kmalloc!\n");
165 return NULL;
166 }
167
168 /*
169 * Initialize instance
170 */
171 memset(self, 0, sizeof(struct iriap_cb));
172
173 self->magic = IAS_MAGIC;
174 self->mode = mode;
175 if (mode == IAS_CLIENT)
176 iriap_register_lsap(self, slsap_sel, mode);
177
178 self->confirm = callback;
179 self->priv = priv;
180
181 init_timer(&self->watchdog_timer);
182
183 hashbin_insert(iriap, (irda_queue_t *) self, (int) self, NULL);
184
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);
190
191 return self;
192 }
193
194 /*
195 * Function __iriap_close (self)
196 *
197 * Removes (deallocates) the IrIAP instance
198 *
199 */
200 static void __iriap_close(struct iriap_cb *self)
201 {
202 IRDA_DEBUG(4, __FUNCTION__ "()\n");
203
204 ASSERT(self != NULL, return;);
205 ASSERT(self->magic == IAS_MAGIC, return;);
206
207 del_timer(&self->watchdog_timer);
208
209 if (self->skb)
210 dev_kfree_skb(self->skb);
211
212 self->magic = 0;
213
214 kfree(self);
215 }
216
217 /*
218 * Function iriap_close (void)
219 *
220 * Closes IrIAP and deregisters with IrLMP
221 */
222 void iriap_close(struct iriap_cb *self)
223 {
224 struct iriap_cb *entry;
225
226 IRDA_DEBUG(2, __FUNCTION__ "()\n");
227
228 ASSERT(self != NULL, return;);
229 ASSERT(self->magic == IAS_MAGIC, return;);
230
231 if (self->lsap) {
232 irlmp_close_lsap(self->lsap);
233 self->lsap = NULL;
234 }
235
236 entry = (struct iriap_cb *) hashbin_remove(iriap, (int) self, NULL);
237 ASSERT(entry == self, return;);
238
239 __iriap_close(self);
240 }
241
242 static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
243 {
244 notify_t notify;
245
246 IRDA_DEBUG(2, __FUNCTION__ "()\n");
247
248 irda_notify_init(¬ify);
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");
258
259 self->lsap = irlmp_open_lsap(slsap_sel, ¬ify, 0);
260 if (self->lsap == NULL) {
261 ERROR(__FUNCTION__ "(), Unable to allocated LSAP!\n");
262 return -1;
263 }
264 self->slsap_sel = self->lsap->slsap_sel;
265
266 return 0;
267 }
268
269 /*
270 * Function iriap_disconnect_indication (handle, reason)
271 *
272 * Got disconnect, so clean up everything assosiated with this connection
273 *
274 */
275 static void iriap_disconnect_indication(void *instance, void *sap,
276 LM_REASON reason,
277 struct sk_buff *userdata)
278 {
279 struct iriap_cb *self;
280
281 IRDA_DEBUG(4, __FUNCTION__ "(), reason=%s\n", lmp_reasons[reason]);
282
283 self = (struct iriap_cb *) instance;
284
285 ASSERT(self != NULL, return;);
286 ASSERT(self->magic == IAS_MAGIC, return;);
287
288 ASSERT(iriap != NULL, return;);
289
290 del_timer(&self->watchdog_timer);
291
292 if (self->mode == IAS_CLIENT) {
293 IRDA_DEBUG(4, __FUNCTION__ "(), disconnect as client\n");
294
295
296 iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
297 NULL);
298 /*
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
302 */
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);
310 }
311
312 if (userdata)
313 dev_kfree_skb(userdata);
314 }
315
316 /*
317 * Function iriap_disconnect_request (handle)
318 *
319 *
320 *
321 */
322 void iriap_disconnect_request(struct iriap_cb *self)
323 {
324 struct sk_buff *skb;
325
326 IRDA_DEBUG(4, __FUNCTION__ "()\n");
327
328 ASSERT(self != NULL, return;);
329 ASSERT(self->magic == IAS_MAGIC, return;);
330
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;
336 }
337
338 /*
339 * Reserve space for MUX control and LAP header
340 */
341 skb_reserve(skb, LMP_MAX_HEADER);
342
343 irlmp_disconnect_request(self->lsap, skb);
344 }
345
346 void iriap_getinfobasedetails_request(void)
347 {
348 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
349 }
350
351 void iriap_getinfobasedetails_confirm(void)
352 {
353 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
354 }
355
356 void iriap_getobjects_request(void)
357 {
358 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
359 }
360
361 void iriap_getobjects_confirm(void)
362 {
363 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
364 }
365
366 void iriap_getvalue(void)
367 {
368 IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
369 }
370
371 /*
372 * Function iriap_getvaluebyclass (addr, name, attr)
373 *
374 * Retreive all values from attribute in all objects with given class
375 * name
376 */
377 int iriap_getvaluebyclass_request(struct iriap_cb *self,
378 __u32 saddr, __u32 daddr,
379 char *name, char *attr)
380 {
381 struct sk_buff *skb;
382 int name_len, attr_len;
383 __u8 *frame;
384
385 ASSERT(self != NULL, return -1;);
386 ASSERT(self->magic == IAS_MAGIC, return -1;);
387
388 /* Client must supply the destination device address */
389 if (!daddr)
390 return -1;
391
392 self->daddr = daddr;
393 self->saddr = saddr;
394
395 /*
396 * Save operation, so we know what the later indication is about
397 */
398 self->operation = GET_VALUE_BY_CLASS;
399
400 /* Give ourselves 10 secs to finish this operation */
401 iriap_start_watchdog_timer(self, 10*HZ);
402
403 skb = dev_alloc_skb(64);
404 if (!skb)
405 return -ENOMEM;
406
407 name_len = strlen(name);
408 attr_len = strlen(attr);
409
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;
414
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 */
421
422 iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, skb);
423
424 return 0;
425 }
426
427 /*
428 * Function iriap_getvaluebyclass_confirm (self, skb)
429 *
430 * Got result from GetValueByClass command. Parse it and return result
431 * to service user.
432 *
433 */
434 void iriap_getvaluebyclass_confirm(struct iriap_cb *self, struct sk_buff *skb)
435 {
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;
445
446 ASSERT(self != NULL, return;);
447 ASSERT(self->magic == IAS_MAGIC, return;);
448 ASSERT(skb != NULL, return;);
449
450 /* Initialize variables */
451 fp = skb->data;
452 n = 2;
453
454 /* Get length, MSB first */
455 len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
456
457 IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
458
459 /* Get object ID, MSB first */
460 obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
461
462 type = fp[n++];
463 IRDA_DEBUG(4, __FUNCTION__ "(), Value type = %d\n", type);
464
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);
470
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++];
476
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]);
494
495 /* Aborting, close connection! */
496 iriap_disconnect_request(self);
497 dev_kfree_skb(skb);
498 return;
499 /* break; */
500 }
501 value_len = fp[n++];
502 IRDA_DEBUG(4, __FUNCTION__ "(), strlen=%d\n", value_len);
503 ASSERT(value_len < 64, return;);
504
505 /* Make sure the string is null-terminated */
506 fp[n+value_len] = 0x00;
507
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;
514
515 ASSERT(value_len <= 55, return;);
516
517 value = irias_new_octseq_value(fp+n, value_len);
518 break;
519 default:
520 value = irias_new_missing_value();
521 break;
522 }
523
524 /* Finished, close connection! */
525 iriap_disconnect_request(self);
526
527 /* Warning, the client might close us, so remember no to use self
528 * anymore after calling confirm
529 */
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);
535 }
536 dev_kfree_skb(skb);
537 }
538
539 /*
540 * Function iriap_getvaluebyclass_response ()
541 *
542 * Send answer back to remote LM-IAS
543 *
544 */
545 void iriap_getvaluebyclass_response(struct iriap_cb *self, __u16 obj_id,
546 __u8 ret_code, struct ias_value *value)
547 {
548 struct sk_buff *skb;
549 int n;
550 __u32 tmp_be32, tmp_be16;
551 __u8 *fp;
552
553 IRDA_DEBUG(4, __FUNCTION__ "()\n");
554
555 ASSERT(self != NULL, return;);
556 ASSERT(self->magic == IAS_MAGIC, return;);
557 ASSERT(value != NULL, return;);
558 ASSERT(value->len <= 1024, return;);
559
560 /* Initialize variables */
561 n = 0;
562
563 /*
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.
567 */
568 skb = dev_alloc_skb(value->len + self->max_header_size + 32);
569 if (!skb)
570 return;
571
572 /* Reserve space for MUX and LAP header */
573 skb_reserve(skb, self->max_header_size);
574 skb_put(skb, 6);
575
576 fp = skb->data;
577
578 /* Build frame */
579 fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
580 fp[n++] = ret_code;
581
582 /* Insert list length (MSB first) */
583 tmp_be16 = __constant_htons(0x0001);
584 memcpy(fp+n, &tmp_be16, 2); n += 2;
585
586 /* Insert object identifier ( MSB first) */
587 tmp_be16 = cpu_to_be16(obj_id);
588 memcpy(fp+n, &tmp_be16, 2); n += 2;
589
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;
601
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;
608
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;
621 }
622 iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, skb);
623 }
624
625 /*
626 * Function iriap_getvaluebyclass_indication (self, skb)
627 *
628 * getvaluebyclass is requested from peer LM-IAS
629 *
630 */
631 void iriap_getvaluebyclass_indication(struct iriap_cb *self,
632 struct sk_buff *skb)
633 {
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;
642
643 IRDA_DEBUG(4, __FUNCTION__ "()\n");
644
645 ASSERT(self != NULL, return;);
646 ASSERT(self->magic == IAS_MAGIC, return;);
647 ASSERT(skb != NULL, return;);
648
649 fp = skb->data;
650 n = 1;
651
652 name_len = fp[n++];
653 memcpy(name, fp+n, name_len); n+=name_len;
654 name[name_len] = '\0';
655
656 attr_len = fp[n++];
657 memcpy(attr, fp+n, attr_len); n+=attr_len;
658 attr[attr_len] = '\0';
659
660 /* We do not need the buffer anymore */
661 dev_kfree_skb(skb);
662
663 IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
664 obj = irias_find_object(name);
665
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;
671 }
672 IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
673
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;
680 }
681
682 /* We have a match; send the value. */
683 iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
684 attrib->value);
685
686 return;
687 }
688
689 /*
690 * Function iriap_send_ack (void)
691 *
692 * Currently not used
693 *
694 */
695 void iriap_send_ack(struct iriap_cb *self)
696 {
697 struct sk_buff *skb;
698 __u8 *frame;
699
700 IRDA_DEBUG(2, __FUNCTION__ "()\n");
701
702 ASSERT(self != NULL, return;);
703 ASSERT(self->magic == IAS_MAGIC, return;);
704
705 skb = dev_alloc_skb(64);
706 if (!skb)
707 return;
708
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;
713
714 /* Build frame */
715 frame[0] = IAP_LST | IAP_ACK | self->operation;
716
717 irlmp_data_request(self->lsap, skb);
718 }
719
720 void iriap_connect_request(struct iriap_cb *self)
721 {
722 int ret;
723
724 ASSERT(self != NULL, return;);
725 ASSERT(self->magic == IAS_MAGIC, return;);
726
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);
733 }
734 }
735
736 /*
737 * Function iriap_connect_confirm (handle, skb)
738 *
739 * LSAP connection confirmed!
740 *
741 */
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)
746 {
747 struct iriap_cb *self;
748
749 self = (struct iriap_cb *) instance;
750
751 ASSERT(self != NULL, return;);
752 ASSERT(self->magic == IAS_MAGIC, return;);
753 ASSERT(userdata != NULL, return;);
754
755 self->max_data_size = max_seg_size;
756 self->max_header_size = max_header_size;
757
758 del_timer(&self->watchdog_timer);
759
760 iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, userdata);
761 }
762
763 /*
764 * Function iriap_connect_indication ( handle, skb)
765 *
766 * Remote LM-IAS is requesting connection
767 *
768 */
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)
773 {
774 struct iriap_cb *self, *new;
775
776 IRDA_DEBUG(0, __FUNCTION__ "()\n");
777
778 self = (struct iriap_cb *) instance;
779
780 ASSERT(self != NULL, return;);
781 ASSERT(self->magic == IAS_MAGIC, return;);
782
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;
789 }
790
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;
796 }
797
798 new->max_data_size = max_seg_size;
799 new->max_header_size = max_header_size;
800
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 */
805
806 iriap_do_server_event(new, IAP_LM_CONNECT_INDICATION, userdata);
807 }
808
809 /*
810 * Function iriap_data_indication (handle, skb)
811 *
812 * Receives data from connection identified by handle from IrLMP
813 *
814 */
815 static int iriap_data_indication(void *instance, void *sap,
816 struct sk_buff *skb)
817 {
818 struct iriap_cb *self;
819 __u8 *frame;
820 __u8 opcode;
821
822 IRDA_DEBUG(3, __FUNCTION__ "()\n");
823
824 self = (struct iriap_cb *) instance;
825
826 ASSERT(self != NULL, return 0;);
827 ASSERT(self->magic == IAS_MAGIC, return 0;);
828
829 ASSERT(skb != NULL, return 0;);
830
831 frame = skb->data;
832
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);
837
838 return 0;
839 }
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;
846 }
847
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;
853 }
854
855 opcode &= ~IAP_LST; /* Mask away LST bit */
856
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);
864
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);
873
874 /*
875 * Warning, the client might close us, so remember
876 * no to use self anymore after calling confirm
877 */
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);
887
888 /*
889 * Warning, the client might close us, so remember
890 * no to use self anymore after calling confirm
891 */
892 if (self->confirm)
893 self->confirm(IAS_ATTRIB_UNKNOWN, 0, NULL,
894 self->priv);
895 dev_kfree_skb(skb);
896 break;
897 }
898 break;
899 default:
900 IRDA_DEBUG(0, __FUNCTION__ "(), Unknown op-code: %02x\n",
901 opcode);
902 dev_kfree_skb(skb);
903 break;
904 }
905 return 0;
906 }
907
908 /*
909 * Function iriap_call_indication (self, skb)
910 *
911 * Received call to server from peer LM-IAS
912 *
913 */
914 void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
915 {
916 __u8 *fp;
917 __u8 opcode;
918
919 IRDA_DEBUG(4, __FUNCTION__ "()\n");
920
921 ASSERT(self != NULL, return;);
922 ASSERT(self->magic == IAS_MAGIC, return;);
923 ASSERT(skb != NULL, return;);
924
925 fp = skb->data;
926
927 opcode = fp[0];
928 if (~opcode & 0x80) {
929 WARNING(__FUNCTION__ "(), IrIAS multiframe commands or results"
930 "is not implemented yet!\n");
931 return;
932 }
933 opcode &= 0x7f; /* Mask away LST bit */
934
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;
943 }
944 }
945
946 /*
947 * Function iriap_watchdog_timer_expired (data)
948 *
949 * Query has taken to long time, so abort
950 *
951 */
952 void iriap_watchdog_timer_expired(void *data)
953 {
954 struct iriap_cb *self = (struct iriap_cb *) data;
955
956 ASSERT(self != NULL, return;);
957 ASSERT(self->magic == IAS_MAGIC, return;);
958
959 /* iriap_close(self); */
960 }
961
962 #ifdef CONFIG_PROC_FS
963
964 static char *ias_value_types[] = {
965 "IAS_MISSING",
966 "IAS_INTEGER",
967 "IAS_OCT_SEQ",
968 "IAS_STRING"
969 };
970
971 int irias_proc_read(char *buf, char **start, off_t offset, int len)
972 {
973 struct ias_object *obj;
974 struct ias_attrib *attrib;
975 unsigned long flags;
976
977 ASSERT( objects != NULL, return 0;);
978
979 save_flags( flags);
980 cli();
981
982 len = 0;
983
984 len += sprintf(buf+len, "LM-IAS Objects:\n");
985
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;);
990
991 len += sprintf(buf+len, "name: %s, ", obj->name);
992 len += sprintf(buf+len, "id=%d", obj->id);
993 len += sprintf(buf+len, "\n");
994
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;);
1000
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]);
1005
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;
1025 }
1026 len += sprintf(buf+len, "\n");
1027
1028 attrib = (struct ias_attrib *)
1029 hashbin_get_next(obj->attribs);
1030 }
1031 obj = (struct ias_object *) hashbin_get_next(objects);
1032 }
1033 restore_flags(flags);
1034
1035 return len;
1036 }
1037
1038 #endif /* PROC_FS */
1039
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.