1 /*********************************************************************
3 * Filename: irlan_common.c
5 * Description: IrDA LAN Access Protocol Implementation
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Aug 31 20:14:37 1997
9 * Modified at: Sun Dec 26 21:53:10 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1997, 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/module.h>
28 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/init.h>
31 #include <linux/errno.h>
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
34 #include <linux/random.h>
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/rtnetlink.h>
38 #include <linux/moduleparam.h>
39 #include <linux/bitops.h>
41 #include <asm/system.h>
42 #include <asm/byteorder.h>
44 #include <net/irda/irda.h>
45 #include <net/irda/irttp.h>
46 #include <net/irda/irlmp.h>
47 #include <net/irda/iriap.h>
48 #include <net/irda/timer.h>
50 #include <net/irda/irlan_common.h>
51 #include <net/irda/irlan_client.h>
52 #include <net/irda/irlan_provider.h>
53 #include <net/irda/irlan_eth.h>
54 #include <net/irda/irlan_filter.h>
58 * Send gratuitous ARP when connected to a new AP or not. May be a clever
59 * thing to do, but for some reason the machine crashes if you use DHCP. So
60 * lets not use it by default.
62 #undef CONFIG_IRLAN_SEND_GRATUITOUS_ARP
64 /* extern char sysctl_devname[]; */
69 static LIST_HEAD(irlans
);
74 /* Module parameters */
75 static int eth
; /* Use "eth" or "irlan" name for devices */
76 static int access
= ACCESS_PEER
; /* PEER, DIRECT or HOSTED */
79 static const char *irlan_access
[] = {
86 static const char *irlan_media
[] = {
92 extern struct proc_dir_entry
*proc_irda
;
94 static int irlan_seq_open(struct inode
*inode
, struct file
*file
);
96 static const struct file_operations irlan_fops
= {
98 .open
= irlan_seq_open
,
101 .release
= seq_release
,
104 extern struct proc_dir_entry
*proc_irda
;
105 #endif /* CONFIG_PROC_FS */
107 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
);
108 static void __irlan_close(struct irlan_cb
*self
);
109 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
110 __u8 value_byte
, __u16 value_short
,
111 __u8
*value_array
, __u16 value_len
);
112 static void irlan_open_unicast_addr(struct irlan_cb
*self
);
113 static void irlan_get_unicast_addr(struct irlan_cb
*self
);
114 void irlan_close_tsaps(struct irlan_cb
*self
);
117 * Function irlan_init (void)
119 * Initialize IrLAN layer
122 static int __init
irlan_init(void)
124 struct irlan_cb
*new;
127 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
129 #ifdef CONFIG_PROC_FS
130 { struct proc_dir_entry
*proc
;
131 <<<<<<< HEAD
:net
/irda
/irlan
/irlan_common
.c
132 proc
= create_proc_entry("irlan", 0, proc_irda
);
134 proc
= proc_create("irlan", 0, proc_irda
, &irlan_fops
);
135 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/irda
/irlan
/irlan_common
.c
137 printk(KERN_ERR
"irlan_init: can't create /proc entry!\n");
140 <<<<<<< HEAD
:net
/irda
/irlan
/irlan_common
.c
142 proc
->proc_fops
= &irlan_fops
;
144 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/irda
/irlan
/irlan_common
.c
146 #endif /* CONFIG_PROC_FS */
148 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
149 hints
= irlmp_service_to_hint(S_LAN
);
151 /* Register with IrLMP as a client */
152 ckey
= irlmp_register_client(hints
, &irlan_client_discovery_indication
,
157 /* Register with IrLMP as a service */
158 skey
= irlmp_register_service(hints
);
162 /* Start the master IrLAN instance (the only one for now) */
163 new = irlan_open(DEV_ADDR_ANY
, DEV_ADDR_ANY
);
167 /* The master will only open its (listen) control TSAP */
168 irlan_provider_open_ctrl_tsap(new);
170 /* Do some fast discovery! */
171 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
176 irlmp_unregister_service(skey
);
178 irlmp_unregister_client(ckey
);
180 #ifdef CONFIG_PROC_FS
181 remove_proc_entry("irlan", proc_irda
);
182 #endif /* CONFIG_PROC_FS */
187 static void __exit
irlan_cleanup(void)
189 struct irlan_cb
*self
, *next
;
191 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
193 irlmp_unregister_client(ckey
);
194 irlmp_unregister_service(skey
);
196 #ifdef CONFIG_PROC_FS
197 remove_proc_entry("irlan", proc_irda
);
198 #endif /* CONFIG_PROC_FS */
200 /* Cleanup any leftover network devices */
202 list_for_each_entry_safe(self
, next
, &irlans
, dev_list
) {
209 * Function irlan_open (void)
211 * Open new instance of a client/provider, we should only register the
212 * network device if this instance is ment for a particular client/provider
214 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
)
216 struct net_device
*dev
;
217 struct irlan_cb
*self
;
219 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
221 /* Create network device with irlan */
222 dev
= alloc_irlandev(eth
? "eth%d" : "irlan%d");
230 * Initialize local device structure
232 self
->magic
= IRLAN_MAGIC
;
236 /* Provider access can only be PEER, DIRECT, or HOSTED */
237 self
->provider
.access_type
= access
;
238 if (access
== ACCESS_DIRECT
) {
240 * Since we are emulating an IrLAN sever we will have to
241 * give ourself an ethernet address!
243 dev
->dev_addr
[0] = 0x40;
244 dev
->dev_addr
[1] = 0x00;
245 dev
->dev_addr
[2] = 0x00;
246 dev
->dev_addr
[3] = 0x00;
247 get_random_bytes(dev
->dev_addr
+4, 1);
248 get_random_bytes(dev
->dev_addr
+5, 1);
251 self
->media
= MEDIA_802_3
;
252 self
->disconnect_reason
= LM_USER_REQUEST
;
253 init_timer(&self
->watchdog_timer
);
254 init_timer(&self
->client
.kick_timer
);
255 init_waitqueue_head(&self
->open_wait
);
257 skb_queue_head_init(&self
->client
.txq
);
259 irlan_next_client_state(self
, IRLAN_IDLE
);
260 irlan_next_provider_state(self
, IRLAN_IDLE
);
262 if (register_netdev(dev
)) {
263 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
269 list_add_rcu(&self
->dev_list
, &irlans
);
276 * Function __irlan_close (self)
278 * This function closes and deallocates the IrLAN client instances. Be
279 * aware that other functions which calls client_close() must
280 * remove self from irlans list first.
282 static void __irlan_close(struct irlan_cb
*self
)
284 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
287 IRDA_ASSERT(self
!= NULL
, return;);
288 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
290 del_timer_sync(&self
->watchdog_timer
);
291 del_timer_sync(&self
->client
.kick_timer
);
293 /* Close all open connections and remove TSAPs */
294 irlan_close_tsaps(self
);
296 if (self
->client
.iriap
)
297 iriap_close(self
->client
.iriap
);
299 /* Remove frames queued on the control channel */
300 skb_queue_purge(&self
->client
.txq
);
302 /* Unregister and free self via destructor */
303 unregister_netdevice(self
->dev
);
306 /* Find any instance of irlan, used for client discovery wakeup */
307 struct irlan_cb
*irlan_get_any(void)
309 struct irlan_cb
*self
;
311 list_for_each_entry_rcu(self
, &irlans
, dev_list
) {
318 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
320 * Here we receive the connect indication for the data channel
323 static void irlan_connect_indication(void *instance
, void *sap
,
324 struct qos_info
*qos
,
326 __u8 max_header_size
,
329 struct irlan_cb
*self
;
330 struct tsap_cb
*tsap
;
332 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
334 self
= (struct irlan_cb
*) instance
;
335 tsap
= (struct tsap_cb
*) sap
;
337 IRDA_ASSERT(self
!= NULL
, return;);
338 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
339 IRDA_ASSERT(tsap
== self
->tsap_data
,return;);
341 self
->max_sdu_size
= max_sdu_size
;
342 self
->max_header_size
= max_header_size
;
344 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__
);
346 del_timer(&self
->watchdog_timer
);
348 /* If you want to pass the skb to *both* state machines, you will
349 * need to skb_clone() it, so that you don't free it twice.
350 * As the state machines don't need it, git rid of it here...
355 irlan_do_provider_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
356 irlan_do_client_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
358 if (self
->provider
.access_type
== ACCESS_PEER
) {
360 * Data channel is open, so we are now allowed to
361 * configure the remote filter
363 irlan_get_unicast_addr(self
);
364 irlan_open_unicast_addr(self
);
366 /* Ready to transfer Ethernet frames (at last) */
367 netif_start_queue(self
->dev
); /* Clear reason */
370 static void irlan_connect_confirm(void *instance
, void *sap
,
371 struct qos_info
*qos
,
373 __u8 max_header_size
,
376 struct irlan_cb
*self
;
378 self
= (struct irlan_cb
*) instance
;
380 IRDA_ASSERT(self
!= NULL
, return;);
381 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
383 self
->max_sdu_size
= max_sdu_size
;
384 self
->max_header_size
= max_header_size
;
386 /* TODO: we could set the MTU depending on the max_sdu_size */
388 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__
);
389 del_timer(&self
->watchdog_timer
);
392 * Data channel is open, so we are now allowed to configure the remote
395 irlan_get_unicast_addr(self
);
396 irlan_open_unicast_addr(self
);
398 /* Open broadcast and multicast filter by default */
399 irlan_set_broadcast_filter(self
, TRUE
);
400 irlan_set_multicast_filter(self
, TRUE
);
402 /* Ready to transfer Ethernet frames */
403 netif_start_queue(self
->dev
);
404 self
->disconnect_reason
= 0; /* Clear reason */
405 #ifdef CONFIG_IRLAN_SEND_GRATUITOUS_ARP
406 irlan_eth_send_gratuitous_arp(&self
->dev
);
408 wake_up_interruptible(&self
->open_wait
);
412 * Function irlan_client_disconnect_indication (handle)
414 * Callback function for the IrTTP layer. Indicates a disconnection of
415 * the specified connection (handle)
417 static void irlan_disconnect_indication(void *instance
,
418 void *sap
, LM_REASON reason
,
419 struct sk_buff
*userdata
)
421 struct irlan_cb
*self
;
422 struct tsap_cb
*tsap
;
424 IRDA_DEBUG(0, "%s(), reason=%d\n", __FUNCTION__
, reason
);
426 self
= (struct irlan_cb
*) instance
;
427 tsap
= (struct tsap_cb
*) sap
;
429 IRDA_ASSERT(self
!= NULL
, return;);
430 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
431 IRDA_ASSERT(tsap
!= NULL
, return;);
432 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
434 IRDA_ASSERT(tsap
== self
->tsap_data
, return;);
436 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
438 /* Save reason so we know if we should try to reconnect or not */
439 self
->disconnect_reason
= reason
;
442 case LM_USER_REQUEST
: /* User request */
443 IRDA_DEBUG(2, "%s(), User requested\n", __FUNCTION__
);
445 case LM_LAP_DISCONNECT
: /* Unexpected IrLAP disconnect */
446 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __FUNCTION__
);
448 case LM_CONNECT_FAILURE
: /* Failed to establish IrLAP connection */
449 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __FUNCTION__
);
451 case LM_LAP_RESET
: /* IrLAP reset */
452 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __FUNCTION__
);
454 case LM_INIT_DISCONNECT
:
455 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __FUNCTION__
);
458 IRDA_ERROR("%s(), Unknown disconnect reason\n", __FUNCTION__
);
462 /* If you want to pass the skb to *both* state machines, you will
463 * need to skb_clone() it, so that you don't free it twice.
464 * As the state machines don't need it, git rid of it here...
467 dev_kfree_skb(userdata
);
469 irlan_do_client_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
470 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
472 wake_up_interruptible(&self
->open_wait
);
475 void irlan_open_data_tsap(struct irlan_cb
*self
)
477 struct tsap_cb
*tsap
;
480 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
482 IRDA_ASSERT(self
!= NULL
, return;);
483 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
485 /* Check if already open */
489 irda_notify_init(¬ify
);
491 notify
.data_indication
= irlan_eth_receive
;
492 notify
.udata_indication
= irlan_eth_receive
;
493 notify
.connect_indication
= irlan_connect_indication
;
494 notify
.connect_confirm
= irlan_connect_confirm
;
495 notify
.flow_indication
= irlan_eth_flow_indication
;
496 notify
.disconnect_indication
= irlan_disconnect_indication
;
497 notify
.instance
= self
;
498 strlcpy(notify
.name
, "IrLAN data", sizeof(notify
.name
));
500 tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
, ¬ify
);
502 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __FUNCTION__
);
505 self
->tsap_data
= tsap
;
508 * This is the data TSAP selector which we will pass to the client
509 * when the client ask for it.
511 self
->stsap_sel_data
= self
->tsap_data
->stsap_sel
;
514 void irlan_close_tsaps(struct irlan_cb
*self
)
516 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
518 IRDA_ASSERT(self
!= NULL
, return;);
519 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
521 /* Disconnect and close all open TSAP connections */
522 if (self
->tsap_data
) {
523 irttp_disconnect_request(self
->tsap_data
, NULL
, P_NORMAL
);
524 irttp_close_tsap(self
->tsap_data
);
525 self
->tsap_data
= NULL
;
527 if (self
->client
.tsap_ctrl
) {
528 irttp_disconnect_request(self
->client
.tsap_ctrl
, NULL
,
530 irttp_close_tsap(self
->client
.tsap_ctrl
);
531 self
->client
.tsap_ctrl
= NULL
;
533 if (self
->provider
.tsap_ctrl
) {
534 irttp_disconnect_request(self
->provider
.tsap_ctrl
, NULL
,
536 irttp_close_tsap(self
->provider
.tsap_ctrl
);
537 self
->provider
.tsap_ctrl
= NULL
;
539 self
->disconnect_reason
= LM_USER_REQUEST
;
543 * Function irlan_ias_register (self, tsap_sel)
545 * Register with LM-IAS
548 void irlan_ias_register(struct irlan_cb
*self
, __u8 tsap_sel
)
550 struct ias_object
*obj
;
551 struct ias_value
*new_value
;
553 IRDA_ASSERT(self
!= NULL
, return;);
554 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
557 * Check if object has already been registered by a previous provider.
558 * If that is the case, we just change the value of the attribute
560 if (!irias_find_object("IrLAN")) {
561 obj
= irias_new_object("IrLAN", IAS_IRLAN_ID
);
562 irias_add_integer_attrib(obj
, "IrDA:TinyTP:LsapSel", tsap_sel
,
564 irias_insert_object(obj
);
566 new_value
= irias_new_integer_value(tsap_sel
);
567 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
571 /* Register PnP object only if not registered before */
572 if (!irias_find_object("PnP")) {
573 obj
= irias_new_object("PnP", IAS_PNP_ID
);
575 irias_add_string_attrib(obj
, "Name", sysctl_devname
,
578 irias_add_string_attrib(obj
, "Name", "Linux", IAS_KERNEL_ATTR
);
580 irias_add_string_attrib(obj
, "DeviceID", "HWP19F0",
582 irias_add_integer_attrib(obj
, "CompCnt", 1, IAS_KERNEL_ATTR
);
583 if (self
->provider
.access_type
== ACCESS_PEER
)
584 irias_add_string_attrib(obj
, "Comp#01", "PNP8389",
587 irias_add_string_attrib(obj
, "Comp#01", "PNP8294",
590 irias_add_string_attrib(obj
, "Manufacturer",
591 "Linux-IrDA Project", IAS_KERNEL_ATTR
);
592 irias_insert_object(obj
);
597 * Function irlan_run_ctrl_tx_queue (self)
599 * Try to send the next command in the control transmit queue
602 int irlan_run_ctrl_tx_queue(struct irlan_cb
*self
)
606 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
608 if (irda_lock(&self
->client
.tx_busy
) == FALSE
)
611 skb
= skb_dequeue(&self
->client
.txq
);
613 self
->client
.tx_busy
= FALSE
;
617 /* Check that it's really possible to send commands */
618 if ((self
->client
.tsap_ctrl
== NULL
) ||
619 (self
->client
.state
== IRLAN_IDLE
))
621 self
->client
.tx_busy
= FALSE
;
625 IRDA_DEBUG(2, "%s(), sending ...\n", __FUNCTION__
);
627 return irttp_data_request(self
->client
.tsap_ctrl
, skb
);
631 * Function irlan_ctrl_data_request (self, skb)
633 * This function makes sure that commands on the control channel is being
634 * sent in a command/response fashion
636 static void irlan_ctrl_data_request(struct irlan_cb
*self
, struct sk_buff
*skb
)
638 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
641 skb_queue_tail(&self
->client
.txq
, skb
);
643 /* Try to send command */
644 irlan_run_ctrl_tx_queue(self
);
648 * Function irlan_get_provider_info (self)
650 * Send Get Provider Information command to peer IrLAN layer
653 void irlan_get_provider_info(struct irlan_cb
*self
)
658 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
660 IRDA_ASSERT(self
!= NULL
, return;);
661 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
663 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
,
668 /* Reserve space for TTP, LMP, and LAP header */
669 skb_reserve(skb
, self
->client
.max_header_size
);
674 frame
[0] = CMD_GET_PROVIDER_INFO
;
675 frame
[1] = 0x00; /* Zero parameters */
677 irlan_ctrl_data_request(self
, skb
);
681 * Function irlan_open_data_channel (self)
683 * Send an Open Data Command to provider
686 void irlan_open_data_channel(struct irlan_cb
*self
)
691 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
693 IRDA_ASSERT(self
!= NULL
, return;);
694 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
696 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
697 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
698 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
703 skb_reserve(skb
, self
->client
.max_header_size
);
709 frame
[0] = CMD_OPEN_DATA_CHANNEL
;
710 frame
[1] = 0x02; /* Two parameters */
712 irlan_insert_string_param(skb
, "MEDIA", "802.3");
713 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
714 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
716 /* self->use_udata = TRUE; */
718 irlan_ctrl_data_request(self
, skb
);
721 void irlan_close_data_channel(struct irlan_cb
*self
)
726 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
728 IRDA_ASSERT(self
!= NULL
, return;);
729 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
731 /* Check if the TSAP is still there */
732 if (self
->client
.tsap_ctrl
== NULL
)
735 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
736 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
741 skb_reserve(skb
, self
->client
.max_header_size
);
747 frame
[0] = CMD_CLOSE_DATA_CHAN
;
748 frame
[1] = 0x01; /* One parameter */
750 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
752 irlan_ctrl_data_request(self
, skb
);
756 * Function irlan_open_unicast_addr (self)
758 * Make IrLAN provider accept ethernet frames addressed to the unicast
762 static void irlan_open_unicast_addr(struct irlan_cb
*self
)
767 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
769 IRDA_ASSERT(self
!= NULL
, return;);
770 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
772 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
773 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
774 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
775 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
780 /* Reserve space for TTP, LMP, and LAP header */
781 skb_reserve(skb
, self
->max_header_size
);
786 frame
[0] = CMD_FILTER_OPERATION
;
787 frame
[1] = 0x03; /* Three parameters */
788 irlan_insert_byte_param(skb
, "DATA_CHAN" , self
->dtsap_sel_data
);
789 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
790 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
792 irlan_ctrl_data_request(self
, skb
);
796 * Function irlan_set_broadcast_filter (self, status)
798 * Make IrLAN provider accept ethernet frames addressed to the broadcast
799 * address. Be careful with the use of this one, since there may be a lot
800 * of broadcast traffic out there. We can still function without this
801 * one but then _we_ have to initiate all communication with other
802 * hosts, since ARP request for this host will not be answered.
804 void irlan_set_broadcast_filter(struct irlan_cb
*self
, int status
)
809 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
811 IRDA_ASSERT(self
!= NULL
, return;);
812 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
814 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
815 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
816 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
817 /* We may waste one byte here...*/
818 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
823 /* Reserve space for TTP, LMP, and LAP header */
824 skb_reserve(skb
, self
->client
.max_header_size
);
829 frame
[0] = CMD_FILTER_OPERATION
;
830 frame
[1] = 0x03; /* Three parameters */
831 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
832 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
834 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
836 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
838 irlan_ctrl_data_request(self
, skb
);
842 * Function irlan_set_multicast_filter (self, status)
844 * Make IrLAN provider accept ethernet frames addressed to the multicast
848 void irlan_set_multicast_filter(struct irlan_cb
*self
, int status
)
853 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
855 IRDA_ASSERT(self
!= NULL
, return;);
856 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
858 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
859 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
860 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
861 /* We may waste one byte here...*/
862 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
867 /* Reserve space for TTP, LMP, and LAP header */
868 skb_reserve(skb
, self
->client
.max_header_size
);
873 frame
[0] = CMD_FILTER_OPERATION
;
874 frame
[1] = 0x03; /* Three parameters */
875 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
876 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
878 irlan_insert_string_param(skb
, "FILTER_MODE", "ALL");
880 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
882 irlan_ctrl_data_request(self
, skb
);
886 * Function irlan_get_unicast_addr (self)
888 * Retrieves the unicast address from the IrLAN provider. This address
889 * will be inserted into the devices structure, so the ethernet layer
890 * can construct its packets.
893 static void irlan_get_unicast_addr(struct irlan_cb
*self
)
898 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
900 IRDA_ASSERT(self
!= NULL
, return;);
901 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
903 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
904 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
905 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
906 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
912 /* Reserve space for TTP, LMP, and LAP header */
913 skb_reserve(skb
, self
->client
.max_header_size
);
918 frame
[0] = CMD_FILTER_OPERATION
;
919 frame
[1] = 0x03; /* Three parameters */
920 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
921 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
922 irlan_insert_string_param(skb
, "FILTER_OPERATION", "DYNAMIC");
924 irlan_ctrl_data_request(self
, skb
);
928 * Function irlan_get_media_char (self)
933 void irlan_get_media_char(struct irlan_cb
*self
)
938 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
940 IRDA_ASSERT(self
!= NULL
, return;);
941 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
943 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
944 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
950 /* Reserve space for TTP, LMP, and LAP header */
951 skb_reserve(skb
, self
->client
.max_header_size
);
957 frame
[0] = CMD_GET_MEDIA_CHAR
;
958 frame
[1] = 0x01; /* One parameter */
960 irlan_insert_string_param(skb
, "MEDIA", "802.3");
961 irlan_ctrl_data_request(self
, skb
);
965 * Function insert_byte_param (skb, param, value)
967 * Insert byte parameter into frame
970 int irlan_insert_byte_param(struct sk_buff
*skb
, char *param
, __u8 value
)
972 return __irlan_insert_param(skb
, param
, IRLAN_BYTE
, value
, 0, NULL
, 0);
975 int irlan_insert_short_param(struct sk_buff
*skb
, char *param
, __u16 value
)
977 return __irlan_insert_param(skb
, param
, IRLAN_SHORT
, 0, value
, NULL
, 0);
981 * Function insert_string (skb, param, value)
983 * Insert string parameter into frame
986 int irlan_insert_string_param(struct sk_buff
*skb
, char *param
, char *string
)
988 int string_len
= strlen(string
);
990 return __irlan_insert_param(skb
, param
, IRLAN_ARRAY
, 0, 0, string
,
995 * Function insert_array_param(skb, param, value, len_value)
997 * Insert array parameter into frame
1000 int irlan_insert_array_param(struct sk_buff
*skb
, char *name
, __u8
*array
,
1003 return __irlan_insert_param(skb
, name
, IRLAN_ARRAY
, 0, 0, array
,
1008 * Function insert_param (skb, param, value, byte)
1010 * Insert parameter at end of buffer, structure of a parameter is:
1012 * -----------------------------------------------------------------------
1013 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
1014 * -----------------------------------------------------------------------
1016 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
1017 __u8 value_byte
, __u16 value_short
,
1018 __u8
*value_array
, __u16 value_len
)
1022 __le16 tmp_le
; /* Temporary value in little endian format */
1026 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __FUNCTION__
);
1030 param_len
= strlen(param
);
1039 IRDA_ASSERT(value_array
!= NULL
, return 0;);
1040 IRDA_ASSERT(value_len
> 0, return 0;);
1043 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __FUNCTION__
);
1048 /* Insert at end of sk-buffer */
1049 frame
= skb_tail_pointer(skb
);
1051 /* Make space for data */
1052 if (skb_tailroom(skb
) < (param_len
+value_len
+3)) {
1053 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __FUNCTION__
);
1056 skb_put(skb
, param_len
+value_len
+3);
1058 /* Insert parameter length */
1059 frame
[n
++] = param_len
;
1061 /* Insert parameter */
1062 memcpy(frame
+n
, param
, param_len
); n
+= param_len
;
1064 /* Insert value length (2 byte little endian format, LSB first) */
1065 tmp_le
= cpu_to_le16(value_len
);
1066 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2; /* To avoid alignment problems */
1071 frame
[n
++] = value_byte
;
1074 tmp_le
= cpu_to_le16(value_short
);
1075 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2;
1078 memcpy(frame
+n
, value_array
, value_len
); n
+=value_len
;
1083 IRDA_ASSERT(n
== (param_len
+value_len
+3), return 0;);
1085 return param_len
+value_len
+3;
1089 * Function irlan_extract_param (buf, name, value, len)
1091 * Extracts a single parameter name/value pair from buffer and updates
1092 * the buffer pointer to point to the next name/value pair.
1094 int irlan_extract_param(__u8
*buf
, char *name
, char *value
, __u16
*len
)
1100 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
1102 /* get length of parameter name (1 byte) */
1103 name_len
= buf
[n
++];
1105 if (name_len
> 254) {
1106 IRDA_DEBUG(2, "%s(), name_len > 254\n", __FUNCTION__
);
1107 return -RSP_INVALID_COMMAND_FORMAT
;
1110 /* get parameter name */
1111 memcpy(name
, buf
+n
, name_len
);
1112 name
[name_len
] = '\0';
1116 * Get length of parameter value (2 bytes in little endian
1119 memcpy(&val_len
, buf
+n
, 2); /* To avoid alignment problems */
1120 le16_to_cpus(&val_len
); n
+=2;
1122 if (val_len
> 1016) {
1123 IRDA_DEBUG(2, "%s(), parameter length to long\n", __FUNCTION__
);
1124 return -RSP_INVALID_COMMAND_FORMAT
;
1128 /* get parameter value */
1129 memcpy(value
, buf
+n
, val_len
);
1130 value
[val_len
] = '\0';
1133 IRDA_DEBUG(4, "Parameter: %s ", name
);
1134 IRDA_DEBUG(4, "Value: %s\n", value
);
1139 #ifdef CONFIG_PROC_FS
1142 * Start of reading /proc entries.
1143 * Return entry at pos,
1144 * or start_token to indicate print header line
1145 * or NULL if end of file
1147 static void *irlan_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1150 struct irlan_cb
*self
;
1154 return SEQ_START_TOKEN
;
1156 list_for_each_entry(self
, &irlans
, dev_list
) {
1164 /* Return entry after v, and increment pos */
1165 static void *irlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1167 struct list_head
*nxt
;
1170 if (v
== SEQ_START_TOKEN
)
1173 nxt
= ((struct irlan_cb
*)v
)->dev_list
.next
;
1175 return (nxt
== &irlans
) ? NULL
1176 : list_entry(nxt
, struct irlan_cb
, dev_list
);
1179 /* End of reading /proc file */
1180 static void irlan_seq_stop(struct seq_file
*seq
, void *v
)
1187 * Show one entry in /proc file.
1189 static int irlan_seq_show(struct seq_file
*seq
, void *v
)
1191 if (v
== SEQ_START_TOKEN
)
1192 seq_puts(seq
, "IrLAN instances:\n");
1194 struct irlan_cb
*self
= v
;
1196 IRDA_ASSERT(self
!= NULL
, return -1;);
1197 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
1199 seq_printf(seq
,"ifname: %s,\n",
1201 seq_printf(seq
,"client state: %s, ",
1202 irlan_state
[ self
->client
.state
]);
1203 seq_printf(seq
,"provider state: %s,\n",
1204 irlan_state
[ self
->provider
.state
]);
1205 seq_printf(seq
,"saddr: %#08x, ",
1207 seq_printf(seq
,"daddr: %#08x\n",
1209 seq_printf(seq
,"version: %d.%d,\n",
1210 self
->version
[1], self
->version
[0]);
1211 seq_printf(seq
,"access type: %s\n",
1212 irlan_access
[self
->client
.access_type
]);
1213 seq_printf(seq
,"media: %s\n",
1214 irlan_media
[self
->media
]);
1216 seq_printf(seq
,"local filter:\n");
1217 seq_printf(seq
,"remote filter: ");
1218 irlan_print_filter(seq
, self
->client
.filter_type
);
1219 seq_printf(seq
,"tx busy: %s\n",
1220 netif_queue_stopped(self
->dev
) ? "TRUE" : "FALSE");
1227 static const struct seq_operations irlan_seq_ops
= {
1228 .start
= irlan_seq_start
,
1229 .next
= irlan_seq_next
,
1230 .stop
= irlan_seq_stop
,
1231 .show
= irlan_seq_show
,
1234 static int irlan_seq_open(struct inode
*inode
, struct file
*file
)
1236 return seq_open(file
, &irlan_seq_ops
);
1240 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1241 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1242 MODULE_LICENSE("GPL");
1244 module_param(eth
, bool, 0);
1245 MODULE_PARM_DESC(eth
, "Name devices ethX (0) or irlanX (1)");
1246 module_param(access
, int, 0);
1247 MODULE_PARM_DESC(access
, "Access type DIRECT=1, PEER=2, HOSTED=3");
1249 module_init(irlan_init
);
1250 module_exit(irlan_cleanup
);