1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
|
/*********************************************************************
*
* Filename: iriap.c
* 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: Sat Oct 9 17:00:56 1999
* Modified by: Dag Brattli <dagb@cs.uit.no>
*
* Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Neither Dag Brattli nor University of Tromsø admit liability nor
* provide warranty for any of this software. This material is
* provided "AS-IS" and at no charge.
*
********************************************************************/
#include <linux/config.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/string.h>
#include <linux/init.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>
#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"
};
static hashbin_t *iriap = NULL;
static __u32 service_handle;
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_connect_indication(void *instance, void *sap,
struct qos_info *qos, __u32 max_sdu_size,
__u8 max_header_size,
struct sk_buff *skb);
static void iriap_connect_confirm(void *instance, void *sap,
struct qos_info *qos,
__u32 max_sdu_size, __u8 max_header_size,
struct sk_buff *skb);
static int iriap_data_indication(void *instance, void *sap,
struct sk_buff *skb);
/*
* Function iriap_init (void)
*
* Initializes the IrIAP layer, called by the module initialization code
* in irmod.c
*/
int __init iriap_init(void)
{
__u16 hints;
struct ias_object *obj;
/* Allocate master array */
iriap = hashbin_new(HB_LOCAL);
if (!iriap)
return -ENOMEM;
objects = hashbin_new(HB_LOCAL);
if (!objects) {
WARNING(__FUNCTION__ "(), Can't allocate objects hashbin!\n");
return -ENOMEM;
}
/*
* Register some default services for IrLMP
*/
hints = irlmp_service_to_hint(S_COMPUTER);
hints |= irlmp_service_to_hint(S_PNP);
service_handle = irlmp_register_service(hints);
/*
* Register the Device object with LM-IAS
*/
obj = irias_new_object("Device", IAS_DEVICE_ID);
irias_add_string_attrib(obj, "DeviceName", "Linux");
irias_insert_object(obj);
/*
* Register server support with IrLMP so we can accept incoming
* connections
*/
iriap_open(LSAP_IAS, IAS_SERVER);
return 0;
}
/*
* Function iriap_cleanup (void)
*
* Initializes the IrIAP layer, called by the module cleanup code in
* irmod.c
*/
void iriap_cleanup(void)
{
irlmp_unregister_service(service_handle);
hashbin_delete(iriap, (FREE_FUNC) __iriap_close);
hashbin_delete(objects, (FREE_FUNC) __irias_delete_object);
}
/*
* Function iriap_open (void)
*
* Opens an instance of the IrIAP layer, and registers with IrLMP
*/
struct iriap_cb *iriap_open(__u8 slsap_sel, int mode)
{
struct iriap_cb *self;
struct lsap_cb *lsap;
notify_t notify;
IRDA_DEBUG(4, __FUNCTION__ "()\n");
self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
if (!self) {
WARNING(__FUNCTION__ "(), Unable to kmalloc!\n");
return NULL;
}
/*
* Initialize instance
*/
memset(self, 0, sizeof(struct iriap_cb));
irda_notify_init(¬ify);
notify.connect_confirm = iriap_connect_confirm;
notify.connect_indication = iriap_connect_indication;
notify.disconnect_indication = iriap_disconnect_indication;
notify.data_indication = iriap_data_indication;
notify.instance = self;
if (mode == IAS_CLIENT)
strcpy(notify.name, "IrIAS cli");
else
strcpy(notify.name, "IrIAS srv");
lsap = irlmp_open_lsap(slsap_sel, ¬ify);
if (lsap == NULL) {
ERROR(__FUNCTION__ "(), Unable to allocated LSAP!\n");
return NULL;
}
slsap_sel = lsap->slsap_sel;
self->magic = IAS_MAGIC;
self->lsap = lsap;
self->slsap_sel = slsap_sel;
self->mode = mode;
init_timer(&self->watchdog_timer);
hashbin_insert(iriap, (queue_t *) self, slsap_sel, NULL);
/* Initialize state machines */
iriap_next_client_state(self, S_DISCONNECT);
iriap_next_call_state(self, S_MAKE_CALL);
iriap_next_server_state(self, R_DISCONNECT);
iriap_next_r_connect_state(self, R_WAITING);
return self;
}
/*
* Function __iriap_close (self)
*
* Removes (deallocates) the IrIAP instance
*
*/
static void __iriap_close(struct iriap_cb *self)
{
IRDA_DEBUG(4, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
del_timer(&self->watchdog_timer);
self->magic = 0;
kfree(self);
}
/*
* Function iriap_close (void)
*
* Closes IrIAP and deregisters with IrLMP
*/
void iriap_close(struct iriap_cb *self)
{
struct iriap_cb *entry;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
if (self->lsap) {
irlmp_close_lsap(self->lsap);
self->lsap = NULL;
}
entry = (struct iriap_cb *) hashbin_remove(iriap, self->slsap_sel,
NULL);
ASSERT(entry == self, return;);
__iriap_close(self);
}
/*
* Function iriap_disconnect_indication (handle, reason)
*
* Got disconnect, so clean up everything assosiated with this connection
*
*/
static void iriap_disconnect_indication(void *instance, void *sap,
LM_REASON reason,
struct sk_buff *userdata)
{
struct iriap_cb *self;
IRDA_DEBUG(4, __FUNCTION__ "(), reason=%s\n", lmp_reasons[reason]);
self = (struct iriap_cb *) instance;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
ASSERT(iriap != NULL, return;);
del_timer(&self->watchdog_timer);
if (self->mode == IAS_CLIENT) {
IRDA_DEBUG(4, __FUNCTION__ "(), disconnect as client\n");
/*
* Inform service user that the request failed by sending
* it a NULL value.
*/
if (self->confirm)
self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
NULL);
/* Close instance only if client */
iriap_close(self);
} else {
IRDA_DEBUG(4, __FUNCTION__ "(), disconnect as server\n");
iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
NULL);
}
if (userdata)
dev_kfree_skb(userdata);
}
/*
* Function iriap_disconnect_request (handle)
*
*
*
*/
void iriap_disconnect_request(struct iriap_cb *self)
{
struct sk_buff *skb;
IRDA_DEBUG(4, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
skb = dev_alloc_skb(64);
if (skb == NULL) {
IRDA_DEBUG(0, __FUNCTION__
"(), Could not allocate an sk_buff of length %d\n", 64);
return;
}
/*
* Reserve space for MUX control and LAP header
*/
skb_reserve(skb, LMP_MAX_HEADER);
irlmp_disconnect_request(self->lsap, skb);
}
void iriap_getinfobasedetails_request(void)
{
IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
}
void iriap_getinfobasedetails_confirm(void)
{
IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
}
void iriap_getobjects_request(void)
{
IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
}
void iriap_getobjects_confirm(void)
{
IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
}
void iriap_getvalue(void)
{
IRDA_DEBUG(0, __FUNCTION__ "(), Not implemented!\n");
}
/*
* Function iriap_getvaluebyclass (addr, name, attr)
*
* Retreive all values from attribute in all objects with given class
* name
*/
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;
int name_len, attr_len;
__u8 slsap = LSAP_ANY; /* Source LSAP to use */
__u8 *frame;
/* Client must supply the destination device address */
if (!daddr)
return;
self = iriap_open(slsap, IAS_CLIENT);
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
*/
self->operation = GET_VALUE_BY_CLASS;
/* Give ourselves 10 secs to finish this operation */
iriap_start_watchdog_timer(self, 10*HZ);
skb = dev_alloc_skb(64);
if (!skb)
return;
name_len = strlen(name);
attr_len = strlen(attr);
/* Reserve space for MUX and LAP header */
skb_reserve(skb, self->max_header_size);
skb_put(skb, 3+name_len+attr_len);
frame = skb->data;
/* Build frame */
frame[0] = IAP_LST | GET_VALUE_BY_CLASS;
frame[1] = name_len; /* Insert length of name */
memcpy(frame+2, name, name_len); /* Insert name */
frame[2+name_len] = attr_len; /* Insert length of attr */
memcpy(frame+3+name_len, attr, attr_len); /* Insert attr */
iriap_do_client_event(self, IAP_CALL_REQUEST_GVBC, skb);
}
/*
* Function iriap_getvaluebyclass_confirm (self, skb)
*
* Got result from GetValueByClass command. Parse it and return result
* to service user.
*
*/
void iriap_getvaluebyclass_confirm(struct iriap_cb *self, struct sk_buff *skb)
{
struct ias_value *value;
int charset;
__u32 value_len;
__u32 tmp_cpu32;
__u16 obj_id;
__u16 len;
__u8 type;
__u8 *fp;
int n;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
ASSERT(skb != NULL, return;);
/* Initialize variables */
fp = skb->data;
n = 2;
/* Get length, MSB first */
len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
/* Get object ID, MSB first */
obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
type = fp[n++];
IRDA_DEBUG(4, __FUNCTION__ "(), Value type = %d\n", type);
switch (type) {
case IAS_INTEGER:
memcpy(&tmp_cpu32, fp+n, 4); n += 4;
be32_to_cpus(&tmp_cpu32);
value = irias_new_integer_value(tmp_cpu32);
/* Legal values restricted to 0x01-0x6f, page 15 irttp */
IRDA_DEBUG(4, __FUNCTION__ "(), lsap=%d\n", value->t.integer);
break;
case IAS_STRING:
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:
IRDA_DEBUG(0, __FUNCTION__"(), charset %s, not supported\n",
ias_charset_types[charset]);
return;
/* break; */
}
value_len = fp[n++];
IRDA_DEBUG(4, __FUNCTION__ "(), strlen=%d\n", value_len);
ASSERT(value_len < 64, return;);
/* Make sure the string is null-terminated */
fp[n+value_len] = 0x00;
IRDA_DEBUG(4, "Got string %s\n", fp+n);
value = irias_new_string_value(fp+n);
break;
case IAS_OCT_SEQ:
value_len = be16_to_cpu(get_unaligned((__u16 *)(fp+n)));
n += 2;
ASSERT(value_len <= 55, return;);
value = irias_new_octseq_value(fp+n, value_len);
break;
default:
value = &missing;
break;
}
/* Finished, close connection! */
iriap_disconnect_request(self);
if (self->confirm)
self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
}
/*
* Function iriap_getvaluebyclass_response ()
*
* 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)
{
struct sk_buff *skb;
int n;
__u32 tmp_be32, tmp_be16;
__u8 *fp;
IRDA_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;
/*
* 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(value->len + self->max_header_size + 9);
if (!skb)
return;
/* Reserve space for MUX and LAP header */
skb_reserve(skb, self->max_header_size);
skb_put(skb, 6);
fp = skb->data;
/* Build frame */
fp[n++] = GET_VALUE_BY_CLASS | IAP_LST;
fp[n++] = ret_code;
/* Insert list length (MSB first) */
tmp_be16 = __constant_htons(0x0001);
memcpy(fp+n, &tmp_be16, 2); n += 2;
/* Insert object identifier ( MSB first) */
tmp_be16 = cpu_to_be16(obj_id);
memcpy(fp+n, &tmp_be16, 2); n += 2;
switch(value->type) {
case IAS_STRING:
skb_put(skb, 3 + value->len);
fp[n++] = value->type;
fp[n++] = 0; /* ASCII */
fp[n++] = (__u8) value->len;
memcpy(fp+n, value->t.string, value->len); n+=value->len;
break;
case IAS_INTEGER:
skb_put(skb, 5);
fp[n++] = value->type;
tmp_be32 = cpu_to_be32(value->t.integer);
memcpy(fp+n, &tmp_be32, 4); n += 4;
break;
case IAS_OCT_SEQ:
skb_put(skb, 3 + value->len);
fp[n++] = value->type;
tmp_be16 = cpu_to_be16(value->len);
memcpy(fp+n, &tmp_be16, 2); n += 2;
memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
break;
case IAS_MISSING:
IRDA_DEBUG( 3, __FUNCTION__ ": sending IAS_MISSING\n");
skb_put( skb, 1);
fp[n++] = value->type;
break;
default:
IRDA_DEBUG(0, __FUNCTION__ "(), type not implemented!\n");
break;
}
iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, skb);
}
/*
* Function iriap_getvaluebyclass_indication (self, skb)
*
* getvaluebyclass is requested from peer LM-IAS
*
*/
void iriap_getvaluebyclass_indication(struct iriap_cb *self,
struct sk_buff *skb)
{
struct ias_object *obj;
struct ias_attrib *attrib;
int name_len;
int attr_len;
char name[64];
char attr[64];
__u8 *fp;
int n;
IRDA_DEBUG(4, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
ASSERT(skb != NULL, return;);
fp = skb->data;
n = 1;
name_len = fp[n++];
memcpy(name, fp+n, name_len); n+=name_len;
name[name_len] = '\0';
attr_len = fp[n++];
memcpy(attr, fp+n, attr_len); n+=attr_len;
attr[attr_len] = '\0';
dev_kfree_skb(skb);
/*
* Now, do some advanced parsing! :-)
*/
IRDA_DEBUG(4, "LM-IAS: Looking up %s: %s\n", name, attr);
obj = irias_find_object(name);
if (obj == NULL) {
IRDA_DEBUG(0, "LM-IAS: Object not found\n");
iriap_getvaluebyclass_response(self, 0x1235, IAS_CLASS_UNKNOWN,
&missing);
return;
}
IRDA_DEBUG(4, "LM-IAS: found %s, id=%d\n", obj->name, obj->id);
attrib = irias_find_attrib(obj, attr);
if (attrib == NULL) {
IRDA_DEBUG(0, "LM-IAS: Attribute %s not found\n", attr);
iriap_getvaluebyclass_response(self, obj->id,
IAS_ATTRIB_UNKNOWN, &missing);
return;
}
IRDA_DEBUG(4, "LM-IAS: found %s\n", attrib->name);
/*
* We have a match; send the value.
*/
iriap_getvaluebyclass_response(self, obj->id, IAS_SUCCESS,
attrib->value);
return;
}
/*
* Function iriap_send_ack (void)
*
* Currently not used
*
*/
void iriap_send_ack(struct iriap_cb *self)
{
struct sk_buff *skb;
__u8 *frame;
IRDA_DEBUG(6, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
skb = dev_alloc_skb(64);
if (!skb)
return;
/* Reserve space for MUX and LAP header */
skb_reserve(skb, self->max_header_size);
skb_put(skb, 1);
frame = skb->data;
/* Build frame */
frame[0] = IAP_LST | self->operation;
}
/*
* Function iriap_connect_confirm (handle, skb)
*
* LSAP connection confirmed!
*
*/
static void iriap_connect_confirm(void *instance, void *sap,
struct qos_info *qos,
__u32 max_sdu_size, __u8 header_size,
struct sk_buff *userdata)
{
struct iriap_cb *self;
self = (struct iriap_cb *) instance;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
ASSERT(userdata != NULL, return;);
IRDA_DEBUG(4, __FUNCTION__ "()\n");
del_timer(&self->watchdog_timer);
iriap_do_client_event(self, IAP_LM_CONNECT_CONFIRM, userdata);
}
/*
* Function iriap_connect_indication ( handle, skb)
*
* Remote LM-IAS is requesting connection
*
*/
static void iriap_connect_indication(void *instance, void *sap,
struct qos_info *qos, __u32 max_sdu_size,
__u8 header_size,
struct sk_buff *userdata)
{
struct iriap_cb *self;
self = (struct iriap_cb *) instance;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
iriap_do_server_event(self, IAP_LM_CONNECT_INDICATION, userdata);
}
/*
* Function iriap_data_indication (handle, skb)
*
* Receives data from connection identified by handle from IrLMP
*
*/
static int iriap_data_indication(void *instance, void *sap,
struct sk_buff *skb)
{
struct iriap_cb *self;
__u8 *frame;
__u8 opcode;
IRDA_DEBUG( 4, __FUNCTION__ "()\n");
self = (struct iriap_cb *) instance;
ASSERT(self != NULL, return 0;);
ASSERT(self->magic == IAS_MAGIC, return 0;);
ASSERT(skb != NULL, return 0;);
frame = skb->data;
if (self->mode == IAS_SERVER) {
/* Call server */
IRDA_DEBUG(4, __FUNCTION__ "(), Calling server!\n");
iriap_do_r_connect_event( self, IAP_RECV_F_LST, skb);
return 0;
}
opcode = frame[0];
if (~opcode & IAP_LST) {
WARNING(__FUNCTION__ "(), IrIAS multiframe commands or "
"results is not implemented yet!\n");
return 0;
}
/* Check for ack frames since they don't contain any data */
if (opcode & IAP_ACK) {
IRDA_DEBUG(0, __FUNCTION__ "() Got ack frame!\n");
return 0;
}
opcode &= ~IAP_LST; /* Mask away LST bit */
switch (opcode) {
case GET_INFO_BASE:
IRDA_DEBUG(0, "IrLMP GetInfoBaseDetails not implemented!\n");
break;
case GET_VALUE_BY_CLASS:
switch (frame[1]) {
case IAS_SUCCESS:
iriap_getvaluebyclass_confirm(self, skb);
break;
case IAS_CLASS_UNKNOWN:
WARNING(__FUNCTION__ "(), No such class!\n");
/* Finished, close connection! */
iriap_disconnect_request(self);
if (self->confirm)
self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
self->priv);
break;
case IAS_ATTRIB_UNKNOWN:
WARNING(__FUNCTION__ "(), No such attribute!\n");
/* Finished, close connection! */
iriap_disconnect_request(self);
if (self->confirm)
self->confirm(IAS_CLASS_UNKNOWN, 0, NULL,
self->priv);
break;
}
iriap_do_call_event(self, IAP_RECV_F_LST, skb);
/*
* We remove LSAPs used by IrIAS as a client since these
* are more difficult to reuse!
*/
iriap_close(self);
break;
default:
IRDA_DEBUG(0, __FUNCTION__ "(), Unknown op-code: %02x\n", opcode);
break;
}
return 0;
}
/*
* Function iriap_call_indication (self, skb)
*
* Received call to server from peer LM-IAS
*
*/
void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
{
__u8 *fp;
__u8 opcode;
IRDA_DEBUG(4, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
ASSERT(skb != NULL, return;);
fp = skb->data;
opcode = fp[0];
if (~opcode & 0x80) {
WARNING(__FUNCTION__ "(), IrIAS multiframe commands or results"
"is not implemented yet!\n");
return;
}
opcode &= 0x7f; /* Mask away LST bit */
switch (opcode) {
case GET_INFO_BASE:
WARNING(__FUNCTION__
"(), GetInfoBaseDetails not implemented yet!\n");
break;
case GET_VALUE_BY_CLASS:
iriap_getvaluebyclass_indication(self, skb);
break;
}
}
/*
* Function iriap_watchdog_timer_expired (data)
*
* Query has taken to long time, so abort
*
*/
void iriap_watchdog_timer_expired(void *data)
{
struct iriap_cb *self = (struct iriap_cb *) data;
ASSERT(self != NULL, return;);
ASSERT(self->magic == IAS_MAGIC, return;);
iriap_close(self);
}
#ifdef CONFIG_PROC_FS
static char *ias_value_types[] = {
"IAS_MISSING",
"IAS_INTEGER",
"IAS_OCT_SEQ",
"IAS_STRING"
};
int irias_proc_read(char *buf, char **start, off_t offset, int len, int unused)
{
struct ias_object *obj;
struct ias_attrib *attrib;
unsigned long flags;
ASSERT( objects != NULL, return 0;);
save_flags( flags);
cli();
len = 0;
len += sprintf(buf+len, "LM-IAS Objects:\n");
/* List all objects */
obj = (struct ias_object *) hashbin_get_first(objects);
while ( obj != NULL) {
ASSERT(obj->magic == IAS_OBJECT_MAGIC, return 0;);
len += sprintf(buf+len, "name: %s, ", obj->name);
len += sprintf(buf+len, "id=%d", obj->id);
len += sprintf(buf+len, "\n");
/* List all attributes for this object */
attrib = (struct ias_attrib *)
hashbin_get_first(obj->attribs);
while (attrib != NULL) {
ASSERT(attrib->magic == IAS_ATTRIB_MAGIC, return 0;);
len += sprintf(buf+len, " - Attribute name: \"%s\", ",
attrib->name);
len += sprintf(buf+len, "value[%s]: ",
ias_value_types[attrib->value->type]);
switch (attrib->value->type) {
case IAS_INTEGER:
len += sprintf(buf+len, "%d\n",
attrib->value->t.integer);
break;
case IAS_STRING:
len += sprintf(buf+len, "\"%s\"\n",
attrib->value->t.string);
break;
case IAS_OCT_SEQ:
len += sprintf(buf+len, "octet sequence\n");
break;
case IAS_MISSING:
len += sprintf(buf+len, "missing\n");
break;
default:
IRDA_DEBUG(0, __FUNCTION__
"(), Unknown value type!\n");
return -1;
}
len += sprintf(buf+len, "\n");
attrib = (struct ias_attrib *)
hashbin_get_next(obj->attribs);
}
obj = (struct ias_object *) hashbin_get_next(objects);
}
restore_flags(flags);
return len;
}
#endif /* PROC_FS */
|