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#include <linux/module.h>
27
28#include <linux/kernel.h>
29#include <linux/string.h>
30#include <linux/gfp.h>
31#include <linux/init.h>
32#include <linux/errno.h>
33#include <linux/proc_fs.h>
34#include <linux/sched.h>
35#include <linux/seq_file.h>
36#include <linux/random.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
39#include <linux/rtnetlink.h>
40#include <linux/moduleparam.h>
41#include <linux/bitops.h>
42
43#include <asm/byteorder.h>
44
45#include <net/irda/irda.h>
46#include <net/irda/irttp.h>
47#include <net/irda/irlmp.h>
48#include <net/irda/iriap.h>
49#include <net/irda/timer.h>
50
51#include <net/irda/irlan_common.h>
52#include <net/irda/irlan_client.h>
53#include <net/irda/irlan_provider.h>
54#include <net/irda/irlan_eth.h>
55#include <net/irda/irlan_filter.h>
56
57
58
59
60
61
62
63static LIST_HEAD(irlans);
64
65static void *ckey;
66static void *skey;
67
68
69static bool eth;
70static int access = ACCESS_PEER;
71
72#ifdef CONFIG_PROC_FS
73static const char *const irlan_access[] = {
74 "UNKNOWN",
75 "DIRECT",
76 "PEER",
77 "HOSTED"
78};
79
80static const char *const irlan_media[] = {
81 "UNKNOWN",
82 "802.3",
83 "802.5"
84};
85
86extern struct proc_dir_entry *proc_irda;
87
88static int irlan_seq_open(struct inode *inode, struct file *file);
89
90static const struct file_operations irlan_fops = {
91 .owner = THIS_MODULE,
92 .open = irlan_seq_open,
93 .read = seq_read,
94 .llseek = seq_lseek,
95 .release = seq_release,
96};
97
98extern struct proc_dir_entry *proc_irda;
99#endif
100
101static struct irlan_cb __init *irlan_open(__u32 saddr, __u32 daddr);
102static void __irlan_close(struct irlan_cb *self);
103static int __irlan_insert_param(struct sk_buff *skb, char *param, int type,
104 __u8 value_byte, __u16 value_short,
105 __u8 *value_array, __u16 value_len);
106static void irlan_open_unicast_addr(struct irlan_cb *self);
107static void irlan_get_unicast_addr(struct irlan_cb *self);
108void irlan_close_tsaps(struct irlan_cb *self);
109
110
111
112
113
114
115
116static int __init irlan_init(void)
117{
118 struct irlan_cb *new;
119 __u16 hints;
120
121#ifdef CONFIG_PROC_FS
122 { struct proc_dir_entry *proc;
123 proc = proc_create("irlan", 0, proc_irda, &irlan_fops);
124 if (!proc) {
125 printk(KERN_ERR "irlan_init: can't create /proc entry!\n");
126 return -ENODEV;
127 }
128 }
129#endif
130
131 hints = irlmp_service_to_hint(S_LAN);
132
133
134 ckey = irlmp_register_client(hints, &irlan_client_discovery_indication,
135 NULL, NULL);
136 if (!ckey)
137 goto err_ckey;
138
139
140 skey = irlmp_register_service(hints);
141 if (!skey)
142 goto err_skey;
143
144
145 new = irlan_open(DEV_ADDR_ANY, DEV_ADDR_ANY);
146 if (!new)
147 goto err_open;
148
149
150 irlan_provider_open_ctrl_tsap(new);
151
152
153 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
154
155 return 0;
156
157err_open:
158 irlmp_unregister_service(skey);
159err_skey:
160 irlmp_unregister_client(ckey);
161err_ckey:
162#ifdef CONFIG_PROC_FS
163 remove_proc_entry("irlan", proc_irda);
164#endif
165
166 return -ENOMEM;
167}
168
169static void __exit irlan_cleanup(void)
170{
171 struct irlan_cb *self, *next;
172
173 irlmp_unregister_client(ckey);
174 irlmp_unregister_service(skey);
175
176#ifdef CONFIG_PROC_FS
177 remove_proc_entry("irlan", proc_irda);
178#endif
179
180
181 rtnl_lock();
182 list_for_each_entry_safe(self, next, &irlans, dev_list) {
183 __irlan_close(self);
184 }
185 rtnl_unlock();
186}
187
188
189
190
191
192
193
194static struct irlan_cb __init *irlan_open(__u32 saddr, __u32 daddr)
195{
196 struct net_device *dev;
197 struct irlan_cb *self;
198
199
200 dev = alloc_irlandev(eth ? "eth%d" : "irlan%d");
201 if (!dev)
202 return NULL;
203
204 self = netdev_priv(dev);
205 self->dev = dev;
206
207
208
209
210 self->magic = IRLAN_MAGIC;
211 self->saddr = saddr;
212 self->daddr = daddr;
213
214
215 self->provider.access_type = access;
216 if (access == ACCESS_DIRECT) {
217
218
219
220
221 dev->dev_addr[0] = 0x40;
222 dev->dev_addr[1] = 0x00;
223 dev->dev_addr[2] = 0x00;
224 dev->dev_addr[3] = 0x00;
225 get_random_bytes(dev->dev_addr+4, 1);
226 get_random_bytes(dev->dev_addr+5, 1);
227 }
228
229 self->media = MEDIA_802_3;
230 self->disconnect_reason = LM_USER_REQUEST;
231 init_timer(&self->watchdog_timer);
232 init_timer(&self->client.kick_timer);
233 init_waitqueue_head(&self->open_wait);
234
235 skb_queue_head_init(&self->client.txq);
236
237 irlan_next_client_state(self, IRLAN_IDLE);
238 irlan_next_provider_state(self, IRLAN_IDLE);
239
240 if (register_netdev(dev)) {
241 pr_debug("%s(), register_netdev() failed!\n",
242 __func__);
243 self = NULL;
244 free_netdev(dev);
245 } else {
246 rtnl_lock();
247 list_add_rcu(&self->dev_list, &irlans);
248 rtnl_unlock();
249 }
250
251 return self;
252}
253
254
255
256
257
258
259
260static void __irlan_close(struct irlan_cb *self)
261{
262 ASSERT_RTNL();
263 IRDA_ASSERT(self != NULL, return;);
264 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
265
266 del_timer_sync(&self->watchdog_timer);
267 del_timer_sync(&self->client.kick_timer);
268
269
270 irlan_close_tsaps(self);
271
272 if (self->client.iriap)
273 iriap_close(self->client.iriap);
274
275
276 skb_queue_purge(&self->client.txq);
277
278
279 unregister_netdevice(self->dev);
280}
281
282
283struct irlan_cb *irlan_get_any(void)
284{
285 struct irlan_cb *self;
286
287 list_for_each_entry_rcu(self, &irlans, dev_list) {
288 return self;
289 }
290 return NULL;
291}
292
293
294
295
296
297
298
299static void irlan_connect_indication(void *instance, void *sap,
300 struct qos_info *qos,
301 __u32 max_sdu_size,
302 __u8 max_header_size,
303 struct sk_buff *skb)
304{
305 struct irlan_cb *self;
306 struct tsap_cb *tsap;
307
308 self = instance;
309 tsap = sap;
310
311 IRDA_ASSERT(self != NULL, return;);
312 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
313 IRDA_ASSERT(tsap == self->tsap_data,return;);
314
315 self->max_sdu_size = max_sdu_size;
316 self->max_header_size = max_header_size;
317
318 pr_debug("%s: We are now connected!\n", __func__);
319
320 del_timer(&self->watchdog_timer);
321
322
323
324
325
326 if (skb)
327 dev_kfree_skb(skb);
328
329 irlan_do_provider_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
330 irlan_do_client_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
331
332 if (self->provider.access_type == ACCESS_PEER) {
333
334
335
336
337 irlan_get_unicast_addr(self);
338 irlan_open_unicast_addr(self);
339 }
340
341 netif_start_queue(self->dev);
342}
343
344static void irlan_connect_confirm(void *instance, void *sap,
345 struct qos_info *qos,
346 __u32 max_sdu_size,
347 __u8 max_header_size,
348 struct sk_buff *skb)
349{
350 struct irlan_cb *self;
351
352 self = instance;
353
354 IRDA_ASSERT(self != NULL, return;);
355 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
356
357 self->max_sdu_size = max_sdu_size;
358 self->max_header_size = max_header_size;
359
360
361
362 pr_debug("%s: We are now connected!\n", __func__);
363 del_timer(&self->watchdog_timer);
364
365
366
367
368
369 irlan_get_unicast_addr(self);
370 irlan_open_unicast_addr(self);
371
372
373 irlan_set_broadcast_filter(self, TRUE);
374 irlan_set_multicast_filter(self, TRUE);
375
376
377 netif_start_queue(self->dev);
378 self->disconnect_reason = 0;
379 wake_up_interruptible(&self->open_wait);
380}
381
382
383
384
385
386
387
388static void irlan_disconnect_indication(void *instance,
389 void *sap, LM_REASON reason,
390 struct sk_buff *userdata)
391{
392 struct irlan_cb *self;
393 struct tsap_cb *tsap;
394
395 pr_debug("%s(), reason=%d\n", __func__ , reason);
396
397 self = instance;
398 tsap = sap;
399
400 IRDA_ASSERT(self != NULL, return;);
401 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
402 IRDA_ASSERT(tsap != NULL, return;);
403 IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;);
404
405 IRDA_ASSERT(tsap == self->tsap_data, return;);
406
407 pr_debug("IrLAN, data channel disconnected by peer!\n");
408
409
410 self->disconnect_reason = reason;
411
412 switch (reason) {
413 case LM_USER_REQUEST:
414 pr_debug("%s(), User requested\n", __func__);
415 break;
416 case LM_LAP_DISCONNECT:
417 pr_debug("%s(), Unexpected IrLAP disconnect\n", __func__);
418 break;
419 case LM_CONNECT_FAILURE:
420 pr_debug("%s(), IrLAP connect failed\n", __func__);
421 break;
422 case LM_LAP_RESET:
423 pr_debug("%s(), IrLAP reset\n", __func__);
424 break;
425 case LM_INIT_DISCONNECT:
426 pr_debug("%s(), IrLMP connect failed\n", __func__);
427 break;
428 default:
429 net_err_ratelimited("%s(), Unknown disconnect reason\n",
430 __func__);
431 break;
432 }
433
434
435
436
437
438 if (userdata)
439 dev_kfree_skb(userdata);
440
441 irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
442 irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
443
444 wake_up_interruptible(&self->open_wait);
445}
446
447void irlan_open_data_tsap(struct irlan_cb *self)
448{
449 struct tsap_cb *tsap;
450 notify_t notify;
451
452 IRDA_ASSERT(self != NULL, return;);
453 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
454
455
456 if (self->tsap_data)
457 return;
458
459 irda_notify_init(¬ify);
460
461 notify.data_indication = irlan_eth_receive;
462 notify.udata_indication = irlan_eth_receive;
463 notify.connect_indication = irlan_connect_indication;
464 notify.connect_confirm = irlan_connect_confirm;
465 notify.flow_indication = irlan_eth_flow_indication;
466 notify.disconnect_indication = irlan_disconnect_indication;
467 notify.instance = self;
468 strlcpy(notify.name, "IrLAN data", sizeof(notify.name));
469
470 tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify);
471 if (!tsap) {
472 pr_debug("%s(), Got no tsap!\n", __func__);
473 return;
474 }
475 self->tsap_data = tsap;
476
477
478
479
480
481 self->stsap_sel_data = self->tsap_data->stsap_sel;
482}
483
484void irlan_close_tsaps(struct irlan_cb *self)
485{
486 IRDA_ASSERT(self != NULL, return;);
487 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
488
489
490 if (self->tsap_data) {
491 irttp_disconnect_request(self->tsap_data, NULL, P_NORMAL);
492 irttp_close_tsap(self->tsap_data);
493 self->tsap_data = NULL;
494 }
495 if (self->client.tsap_ctrl) {
496 irttp_disconnect_request(self->client.tsap_ctrl, NULL,
497 P_NORMAL);
498 irttp_close_tsap(self->client.tsap_ctrl);
499 self->client.tsap_ctrl = NULL;
500 }
501 if (self->provider.tsap_ctrl) {
502 irttp_disconnect_request(self->provider.tsap_ctrl, NULL,
503 P_NORMAL);
504 irttp_close_tsap(self->provider.tsap_ctrl);
505 self->provider.tsap_ctrl = NULL;
506 }
507 self->disconnect_reason = LM_USER_REQUEST;
508}
509
510
511
512
513
514
515
516void irlan_ias_register(struct irlan_cb *self, __u8 tsap_sel)
517{
518 struct ias_object *obj;
519 struct ias_value *new_value;
520
521 IRDA_ASSERT(self != NULL, return;);
522 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
523
524
525
526
527
528 if (!irias_find_object("IrLAN")) {
529 obj = irias_new_object("IrLAN", IAS_IRLAN_ID);
530 irias_add_integer_attrib(obj, "IrDA:TinyTP:LsapSel", tsap_sel,
531 IAS_KERNEL_ATTR);
532 irias_insert_object(obj);
533 } else {
534 new_value = irias_new_integer_value(tsap_sel);
535 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
536 new_value);
537 }
538
539
540 if (!irias_find_object("PnP")) {
541 obj = irias_new_object("PnP", IAS_PNP_ID);
542#if 0
543 irias_add_string_attrib(obj, "Name", sysctl_devname,
544 IAS_KERNEL_ATTR);
545#else
546 irias_add_string_attrib(obj, "Name", "Linux", IAS_KERNEL_ATTR);
547#endif
548 irias_add_string_attrib(obj, "DeviceID", "HWP19F0",
549 IAS_KERNEL_ATTR);
550 irias_add_integer_attrib(obj, "CompCnt", 1, IAS_KERNEL_ATTR);
551 if (self->provider.access_type == ACCESS_PEER)
552 irias_add_string_attrib(obj, "Comp#01", "PNP8389",
553 IAS_KERNEL_ATTR);
554 else
555 irias_add_string_attrib(obj, "Comp#01", "PNP8294",
556 IAS_KERNEL_ATTR);
557
558 irias_add_string_attrib(obj, "Manufacturer",
559 "Linux-IrDA Project", IAS_KERNEL_ATTR);
560 irias_insert_object(obj);
561 }
562}
563
564
565
566
567
568
569
570int irlan_run_ctrl_tx_queue(struct irlan_cb *self)
571{
572 struct sk_buff *skb;
573
574 if (irda_lock(&self->client.tx_busy) == FALSE)
575 return -EBUSY;
576
577 skb = skb_dequeue(&self->client.txq);
578 if (!skb) {
579 self->client.tx_busy = FALSE;
580 return 0;
581 }
582
583
584 if ((self->client.tsap_ctrl == NULL) ||
585 (self->client.state == IRLAN_IDLE))
586 {
587 self->client.tx_busy = FALSE;
588 dev_kfree_skb(skb);
589 return -1;
590 }
591 pr_debug("%s(), sending ...\n", __func__);
592
593 return irttp_data_request(self->client.tsap_ctrl, skb);
594}
595
596
597
598
599
600
601
602static void irlan_ctrl_data_request(struct irlan_cb *self, struct sk_buff *skb)
603{
604
605 skb_queue_tail(&self->client.txq, skb);
606
607
608 irlan_run_ctrl_tx_queue(self);
609}
610
611
612
613
614
615
616
617void irlan_get_provider_info(struct irlan_cb *self)
618{
619 struct sk_buff *skb;
620 __u8 *frame;
621
622 IRDA_ASSERT(self != NULL, return;);
623 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
624
625 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER,
626 GFP_ATOMIC);
627 if (!skb)
628 return;
629
630
631 skb_reserve(skb, self->client.max_header_size);
632 skb_put(skb, 2);
633
634 frame = skb->data;
635
636 frame[0] = CMD_GET_PROVIDER_INFO;
637 frame[1] = 0x00;
638
639 irlan_ctrl_data_request(self, skb);
640}
641
642
643
644
645
646
647
648void irlan_open_data_channel(struct irlan_cb *self)
649{
650 struct sk_buff *skb;
651 __u8 *frame;
652
653 IRDA_ASSERT(self != NULL, return;);
654 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
655
656 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
657 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
658 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
659 GFP_ATOMIC);
660 if (!skb)
661 return;
662
663 skb_reserve(skb, self->client.max_header_size);
664 skb_put(skb, 2);
665
666 frame = skb->data;
667
668
669 frame[0] = CMD_OPEN_DATA_CHANNEL;
670 frame[1] = 0x02;
671
672 irlan_insert_string_param(skb, "MEDIA", "802.3");
673 irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT");
674
675
676
677
678 irlan_ctrl_data_request(self, skb);
679}
680
681void irlan_close_data_channel(struct irlan_cb *self)
682{
683 struct sk_buff *skb;
684 __u8 *frame;
685
686 IRDA_ASSERT(self != NULL, return;);
687 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
688
689
690 if (self->client.tsap_ctrl == NULL)
691 return;
692
693 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
694 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
695 GFP_ATOMIC);
696 if (!skb)
697 return;
698
699 skb_reserve(skb, self->client.max_header_size);
700 skb_put(skb, 2);
701
702 frame = skb->data;
703
704
705 frame[0] = CMD_CLOSE_DATA_CHAN;
706 frame[1] = 0x01;
707
708 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
709
710 irlan_ctrl_data_request(self, skb);
711}
712
713
714
715
716
717
718
719
720static void irlan_open_unicast_addr(struct irlan_cb *self)
721{
722 struct sk_buff *skb;
723 __u8 *frame;
724
725 IRDA_ASSERT(self != NULL, return;);
726 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
727
728 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
729 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
730 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
731 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
732 GFP_ATOMIC);
733 if (!skb)
734 return;
735
736
737 skb_reserve(skb, self->max_header_size);
738 skb_put(skb, 2);
739
740 frame = skb->data;
741
742 frame[0] = CMD_FILTER_OPERATION;
743 frame[1] = 0x03;
744 irlan_insert_byte_param(skb, "DATA_CHAN" , self->dtsap_sel_data);
745 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
746 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
747
748 irlan_ctrl_data_request(self, skb);
749}
750
751
752
753
754
755
756
757
758
759
760void irlan_set_broadcast_filter(struct irlan_cb *self, int status)
761{
762 struct sk_buff *skb;
763 __u8 *frame;
764
765 IRDA_ASSERT(self != NULL, return;);
766 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
767
768 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
769 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
770 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
771
772 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
773 GFP_ATOMIC);
774 if (!skb)
775 return;
776
777
778 skb_reserve(skb, self->client.max_header_size);
779 skb_put(skb, 2);
780
781 frame = skb->data;
782
783 frame[0] = CMD_FILTER_OPERATION;
784 frame[1] = 0x03;
785 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
786 irlan_insert_string_param(skb, "FILTER_TYPE", "BROADCAST");
787 if (status)
788 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
789 else
790 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
791
792 irlan_ctrl_data_request(self, skb);
793}
794
795
796
797
798
799
800
801
802void irlan_set_multicast_filter(struct irlan_cb *self, int status)
803{
804 struct sk_buff *skb;
805 __u8 *frame;
806
807 IRDA_ASSERT(self != NULL, return;);
808 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
809
810 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
811 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
812 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
813
814 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
815 GFP_ATOMIC);
816 if (!skb)
817 return;
818
819
820 skb_reserve(skb, self->client.max_header_size);
821 skb_put(skb, 2);
822
823 frame = skb->data;
824
825 frame[0] = CMD_FILTER_OPERATION;
826 frame[1] = 0x03;
827 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
828 irlan_insert_string_param(skb, "FILTER_TYPE", "MULTICAST");
829 if (status)
830 irlan_insert_string_param(skb, "FILTER_MODE", "ALL");
831 else
832 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
833
834 irlan_ctrl_data_request(self, skb);
835}
836
837
838
839
840
841
842
843
844
845static void irlan_get_unicast_addr(struct irlan_cb *self)
846{
847 struct sk_buff *skb;
848 __u8 *frame;
849
850 IRDA_ASSERT(self != NULL, return;);
851 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
852
853 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
854 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
855 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
856 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
857 "DYNAMIC"),
858 GFP_ATOMIC);
859 if (!skb)
860 return;
861
862
863 skb_reserve(skb, self->client.max_header_size);
864 skb_put(skb, 2);
865
866 frame = skb->data;
867
868 frame[0] = CMD_FILTER_OPERATION;
869 frame[1] = 0x03;
870 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
871 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
872 irlan_insert_string_param(skb, "FILTER_OPERATION", "DYNAMIC");
873
874 irlan_ctrl_data_request(self, skb);
875}
876
877
878
879
880
881
882
883void irlan_get_media_char(struct irlan_cb *self)
884{
885 struct sk_buff *skb;
886 __u8 *frame;
887
888 IRDA_ASSERT(self != NULL, return;);
889 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
890
891 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
892 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
893 GFP_ATOMIC);
894
895 if (!skb)
896 return;
897
898
899 skb_reserve(skb, self->client.max_header_size);
900 skb_put(skb, 2);
901
902 frame = skb->data;
903
904
905 frame[0] = CMD_GET_MEDIA_CHAR;
906 frame[1] = 0x01;
907
908 irlan_insert_string_param(skb, "MEDIA", "802.3");
909 irlan_ctrl_data_request(self, skb);
910}
911
912
913
914
915
916
917
918int irlan_insert_byte_param(struct sk_buff *skb, char *param, __u8 value)
919{
920 return __irlan_insert_param(skb, param, IRLAN_BYTE, value, 0, NULL, 0);
921}
922
923int irlan_insert_short_param(struct sk_buff *skb, char *param, __u16 value)
924{
925 return __irlan_insert_param(skb, param, IRLAN_SHORT, 0, value, NULL, 0);
926}
927
928
929
930
931
932
933
934int irlan_insert_string_param(struct sk_buff *skb, char *param, char *string)
935{
936 int string_len = strlen(string);
937
938 return __irlan_insert_param(skb, param, IRLAN_ARRAY, 0, 0, string,
939 string_len);
940}
941
942
943
944
945
946
947
948int irlan_insert_array_param(struct sk_buff *skb, char *name, __u8 *array,
949 __u16 array_len)
950{
951 return __irlan_insert_param(skb, name, IRLAN_ARRAY, 0, 0, array,
952 array_len);
953}
954
955
956
957
958
959
960
961
962
963
964static int __irlan_insert_param(struct sk_buff *skb, char *param, int type,
965 __u8 value_byte, __u16 value_short,
966 __u8 *value_array, __u16 value_len)
967{
968 __u8 *frame;
969 __u8 param_len;
970 __le16 tmp_le;
971 int n=0;
972
973 if (skb == NULL) {
974 pr_debug("%s(), Got NULL skb\n", __func__);
975 return 0;
976 }
977
978 param_len = strlen(param);
979 switch (type) {
980 case IRLAN_BYTE:
981 value_len = 1;
982 break;
983 case IRLAN_SHORT:
984 value_len = 2;
985 break;
986 case IRLAN_ARRAY:
987 IRDA_ASSERT(value_array != NULL, return 0;);
988 IRDA_ASSERT(value_len > 0, return 0;);
989 break;
990 default:
991 pr_debug("%s(), Unknown parameter type!\n", __func__);
992 return 0;
993 }
994
995
996 frame = skb_tail_pointer(skb);
997
998
999 if (skb_tailroom(skb) < (param_len+value_len+3)) {
1000 pr_debug("%s(), No more space at end of skb\n", __func__);
1001 return 0;
1002 }
1003 skb_put(skb, param_len+value_len+3);
1004
1005
1006 frame[n++] = param_len;
1007
1008
1009 memcpy(frame+n, param, param_len); n += param_len;
1010
1011
1012 tmp_le = cpu_to_le16(value_len);
1013 memcpy(frame+n, &tmp_le, 2); n += 2;
1014
1015
1016 switch (type) {
1017 case IRLAN_BYTE:
1018 frame[n++] = value_byte;
1019 break;
1020 case IRLAN_SHORT:
1021 tmp_le = cpu_to_le16(value_short);
1022 memcpy(frame+n, &tmp_le, 2); n += 2;
1023 break;
1024 case IRLAN_ARRAY:
1025 memcpy(frame+n, value_array, value_len); n+=value_len;
1026 break;
1027 default:
1028 break;
1029 }
1030 IRDA_ASSERT(n == (param_len+value_len+3), return 0;);
1031
1032 return param_len+value_len+3;
1033}
1034
1035
1036
1037
1038
1039
1040
1041int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len)
1042{
1043 __u8 name_len;
1044 __u16 val_len;
1045 int n=0;
1046
1047
1048 name_len = buf[n++];
1049
1050 if (name_len > 254) {
1051 pr_debug("%s(), name_len > 254\n", __func__);
1052 return -RSP_INVALID_COMMAND_FORMAT;
1053 }
1054
1055
1056 memcpy(name, buf+n, name_len);
1057 name[name_len] = '\0';
1058 n+=name_len;
1059
1060
1061
1062
1063
1064 memcpy(&val_len, buf+n, 2);
1065 le16_to_cpus(&val_len); n+=2;
1066
1067 if (val_len >= 1016) {
1068 pr_debug("%s(), parameter length to long\n", __func__);
1069 return -RSP_INVALID_COMMAND_FORMAT;
1070 }
1071 *len = val_len;
1072
1073
1074 memcpy(value, buf+n, val_len);
1075 value[val_len] = '\0';
1076 n+=val_len;
1077
1078 pr_debug("Parameter: %s ", name);
1079 pr_debug("Value: %s\n", value);
1080
1081 return n;
1082}
1083
1084#ifdef CONFIG_PROC_FS
1085
1086
1087
1088
1089
1090
1091
1092static void *irlan_seq_start(struct seq_file *seq, loff_t *pos)
1093{
1094 rcu_read_lock();
1095 return seq_list_start_head(&irlans, *pos);
1096}
1097
1098
1099static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1100{
1101 return seq_list_next(v, &irlans, pos);
1102}
1103
1104
1105static void irlan_seq_stop(struct seq_file *seq, void *v)
1106{
1107 rcu_read_unlock();
1108}
1109
1110
1111
1112
1113
1114static int irlan_seq_show(struct seq_file *seq, void *v)
1115{
1116 if (v == &irlans)
1117 seq_puts(seq, "IrLAN instances:\n");
1118 else {
1119 struct irlan_cb *self = list_entry(v, struct irlan_cb, dev_list);
1120
1121 IRDA_ASSERT(self != NULL, return -1;);
1122 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
1123
1124 seq_printf(seq,"ifname: %s,\n",
1125 self->dev->name);
1126 seq_printf(seq,"client state: %s, ",
1127 irlan_state[ self->client.state]);
1128 seq_printf(seq,"provider state: %s,\n",
1129 irlan_state[ self->provider.state]);
1130 seq_printf(seq,"saddr: %#08x, ",
1131 self->saddr);
1132 seq_printf(seq,"daddr: %#08x\n",
1133 self->daddr);
1134 seq_printf(seq,"version: %d.%d,\n",
1135 self->version[1], self->version[0]);
1136 seq_printf(seq,"access type: %s\n",
1137 irlan_access[self->client.access_type]);
1138 seq_printf(seq,"media: %s\n",
1139 irlan_media[self->media]);
1140
1141 seq_printf(seq,"local filter:\n");
1142 seq_printf(seq,"remote filter: ");
1143 irlan_print_filter(seq, self->client.filter_type);
1144 seq_printf(seq,"tx busy: %s\n",
1145 netif_queue_stopped(self->dev) ? "TRUE" : "FALSE");
1146
1147 seq_putc(seq,'\n');
1148 }
1149 return 0;
1150}
1151
1152static const struct seq_operations irlan_seq_ops = {
1153 .start = irlan_seq_start,
1154 .next = irlan_seq_next,
1155 .stop = irlan_seq_stop,
1156 .show = irlan_seq_show,
1157};
1158
1159static int irlan_seq_open(struct inode *inode, struct file *file)
1160{
1161 return seq_open(file, &irlan_seq_ops);
1162}
1163#endif
1164
1165MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1166MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1167MODULE_LICENSE("GPL");
1168
1169module_param(eth, bool, 0);
1170MODULE_PARM_DESC(eth, "Name devices ethX (0) or irlanX (1)");
1171module_param(access, int, 0);
1172MODULE_PARM_DESC(access, "Access type DIRECT=1, PEER=2, HOSTED=3");
1173
1174module_init(irlan_init);
1175module_exit(irlan_cleanup);
1176
1177