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>
57 /* extern char sysctl_devname[]; */
62 static LIST_HEAD(irlans
);
67 /* Module parameters */
68 static int eth
; /* Use "eth" or "irlan" name for devices */
69 static int access
= ACCESS_PEER
; /* PEER, DIRECT or HOSTED */
72 static const char *const irlan_access
[] = {
79 static const char *const irlan_media
[] = {
85 extern struct proc_dir_entry
*proc_irda
;
87 static int irlan_seq_open(struct inode
*inode
, struct file
*file
);
89 static const struct file_operations irlan_fops
= {
91 .open
= irlan_seq_open
,
94 .release
= seq_release
,
97 extern struct proc_dir_entry
*proc_irda
;
98 #endif /* CONFIG_PROC_FS */
100 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
);
101 static void __irlan_close(struct irlan_cb
*self
);
102 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
103 __u8 value_byte
, __u16 value_short
,
104 __u8
*value_array
, __u16 value_len
);
105 static void irlan_open_unicast_addr(struct irlan_cb
*self
);
106 static void irlan_get_unicast_addr(struct irlan_cb
*self
);
107 void irlan_close_tsaps(struct irlan_cb
*self
);
110 * Function irlan_init (void)
112 * Initialize IrLAN layer
115 static int __init
irlan_init(void)
117 struct irlan_cb
*new;
120 IRDA_DEBUG(2, "%s()\n", __func__
);
122 #ifdef CONFIG_PROC_FS
123 { struct proc_dir_entry
*proc
;
124 proc
= proc_create("irlan", 0, proc_irda
, &irlan_fops
);
126 printk(KERN_ERR
"irlan_init: can't create /proc entry!\n");
130 #endif /* CONFIG_PROC_FS */
132 IRDA_DEBUG(4, "%s()\n", __func__
);
133 hints
= irlmp_service_to_hint(S_LAN
);
135 /* Register with IrLMP as a client */
136 ckey
= irlmp_register_client(hints
, &irlan_client_discovery_indication
,
141 /* Register with IrLMP as a service */
142 skey
= irlmp_register_service(hints
);
146 /* Start the master IrLAN instance (the only one for now) */
147 new = irlan_open(DEV_ADDR_ANY
, DEV_ADDR_ANY
);
151 /* The master will only open its (listen) control TSAP */
152 irlan_provider_open_ctrl_tsap(new);
154 /* Do some fast discovery! */
155 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
160 irlmp_unregister_service(skey
);
162 irlmp_unregister_client(ckey
);
164 #ifdef CONFIG_PROC_FS
165 remove_proc_entry("irlan", proc_irda
);
166 #endif /* CONFIG_PROC_FS */
171 static void __exit
irlan_cleanup(void)
173 struct irlan_cb
*self
, *next
;
175 IRDA_DEBUG(4, "%s()\n", __func__
);
177 irlmp_unregister_client(ckey
);
178 irlmp_unregister_service(skey
);
180 #ifdef CONFIG_PROC_FS
181 remove_proc_entry("irlan", proc_irda
);
182 #endif /* CONFIG_PROC_FS */
184 /* Cleanup any leftover network devices */
186 list_for_each_entry_safe(self
, next
, &irlans
, dev_list
) {
193 * Function irlan_open (void)
195 * Open new instance of a client/provider, we should only register the
196 * network device if this instance is ment for a particular client/provider
198 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
)
200 struct net_device
*dev
;
201 struct irlan_cb
*self
;
203 IRDA_DEBUG(2, "%s()\n", __func__
);
205 /* Create network device with irlan */
206 dev
= alloc_irlandev(eth
? "eth%d" : "irlan%d");
210 self
= netdev_priv(dev
);
214 * Initialize local device structure
216 self
->magic
= IRLAN_MAGIC
;
220 /* Provider access can only be PEER, DIRECT, or HOSTED */
221 self
->provider
.access_type
= access
;
222 if (access
== ACCESS_DIRECT
) {
224 * Since we are emulating an IrLAN sever we will have to
225 * give ourself an ethernet address!
227 dev
->dev_addr
[0] = 0x40;
228 dev
->dev_addr
[1] = 0x00;
229 dev
->dev_addr
[2] = 0x00;
230 dev
->dev_addr
[3] = 0x00;
231 get_random_bytes(dev
->dev_addr
+4, 1);
232 get_random_bytes(dev
->dev_addr
+5, 1);
235 self
->media
= MEDIA_802_3
;
236 self
->disconnect_reason
= LM_USER_REQUEST
;
237 init_timer(&self
->watchdog_timer
);
238 init_timer(&self
->client
.kick_timer
);
239 init_waitqueue_head(&self
->open_wait
);
241 skb_queue_head_init(&self
->client
.txq
);
243 irlan_next_client_state(self
, IRLAN_IDLE
);
244 irlan_next_provider_state(self
, IRLAN_IDLE
);
246 if (register_netdev(dev
)) {
247 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
253 list_add_rcu(&self
->dev_list
, &irlans
);
260 * Function __irlan_close (self)
262 * This function closes and deallocates the IrLAN client instances. Be
263 * aware that other functions which calls client_close() must
264 * remove self from irlans list first.
266 static void __irlan_close(struct irlan_cb
*self
)
268 IRDA_DEBUG(2, "%s()\n", __func__
);
271 IRDA_ASSERT(self
!= NULL
, return;);
272 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
274 del_timer_sync(&self
->watchdog_timer
);
275 del_timer_sync(&self
->client
.kick_timer
);
277 /* Close all open connections and remove TSAPs */
278 irlan_close_tsaps(self
);
280 if (self
->client
.iriap
)
281 iriap_close(self
->client
.iriap
);
283 /* Remove frames queued on the control channel */
284 skb_queue_purge(&self
->client
.txq
);
286 /* Unregister and free self via destructor */
287 unregister_netdevice(self
->dev
);
290 /* Find any instance of irlan, used for client discovery wakeup */
291 struct irlan_cb
*irlan_get_any(void)
293 struct irlan_cb
*self
;
295 list_for_each_entry_rcu(self
, &irlans
, dev_list
) {
302 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
304 * Here we receive the connect indication for the data channel
307 static void irlan_connect_indication(void *instance
, void *sap
,
308 struct qos_info
*qos
,
310 __u8 max_header_size
,
313 struct irlan_cb
*self
;
314 struct tsap_cb
*tsap
;
316 IRDA_DEBUG(2, "%s()\n", __func__
);
318 self
= (struct irlan_cb
*) instance
;
319 tsap
= (struct tsap_cb
*) sap
;
321 IRDA_ASSERT(self
!= NULL
, return;);
322 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
323 IRDA_ASSERT(tsap
== self
->tsap_data
,return;);
325 self
->max_sdu_size
= max_sdu_size
;
326 self
->max_header_size
= max_header_size
;
328 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
330 del_timer(&self
->watchdog_timer
);
332 /* If you want to pass the skb to *both* state machines, you will
333 * need to skb_clone() it, so that you don't free it twice.
334 * As the state machines don't need it, git rid of it here...
339 irlan_do_provider_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
340 irlan_do_client_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
342 if (self
->provider
.access_type
== ACCESS_PEER
) {
344 * Data channel is open, so we are now allowed to
345 * configure the remote filter
347 irlan_get_unicast_addr(self
);
348 irlan_open_unicast_addr(self
);
350 /* Ready to transfer Ethernet frames (at last) */
351 netif_start_queue(self
->dev
); /* Clear reason */
354 static void irlan_connect_confirm(void *instance
, void *sap
,
355 struct qos_info
*qos
,
357 __u8 max_header_size
,
360 struct irlan_cb
*self
;
362 self
= (struct irlan_cb
*) instance
;
364 IRDA_ASSERT(self
!= NULL
, return;);
365 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
367 self
->max_sdu_size
= max_sdu_size
;
368 self
->max_header_size
= max_header_size
;
370 /* TODO: we could set the MTU depending on the max_sdu_size */
372 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
373 del_timer(&self
->watchdog_timer
);
376 * Data channel is open, so we are now allowed to configure the remote
379 irlan_get_unicast_addr(self
);
380 irlan_open_unicast_addr(self
);
382 /* Open broadcast and multicast filter by default */
383 irlan_set_broadcast_filter(self
, TRUE
);
384 irlan_set_multicast_filter(self
, TRUE
);
386 /* Ready to transfer Ethernet frames */
387 netif_start_queue(self
->dev
);
388 self
->disconnect_reason
= 0; /* Clear reason */
389 wake_up_interruptible(&self
->open_wait
);
393 * Function irlan_client_disconnect_indication (handle)
395 * Callback function for the IrTTP layer. Indicates a disconnection of
396 * the specified connection (handle)
398 static void irlan_disconnect_indication(void *instance
,
399 void *sap
, LM_REASON reason
,
400 struct sk_buff
*userdata
)
402 struct irlan_cb
*self
;
403 struct tsap_cb
*tsap
;
405 IRDA_DEBUG(0, "%s(), reason=%d\n", __func__
, reason
);
407 self
= (struct irlan_cb
*) instance
;
408 tsap
= (struct tsap_cb
*) sap
;
410 IRDA_ASSERT(self
!= NULL
, return;);
411 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
412 IRDA_ASSERT(tsap
!= NULL
, return;);
413 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
415 IRDA_ASSERT(tsap
== self
->tsap_data
, return;);
417 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
419 /* Save reason so we know if we should try to reconnect or not */
420 self
->disconnect_reason
= reason
;
423 case LM_USER_REQUEST
: /* User request */
424 IRDA_DEBUG(2, "%s(), User requested\n", __func__
);
426 case LM_LAP_DISCONNECT
: /* Unexpected IrLAP disconnect */
427 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __func__
);
429 case LM_CONNECT_FAILURE
: /* Failed to establish IrLAP connection */
430 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __func__
);
432 case LM_LAP_RESET
: /* IrLAP reset */
433 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __func__
);
435 case LM_INIT_DISCONNECT
:
436 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __func__
);
439 IRDA_ERROR("%s(), Unknown disconnect reason\n", __func__
);
443 /* If you want to pass the skb to *both* state machines, you will
444 * need to skb_clone() it, so that you don't free it twice.
445 * As the state machines don't need it, git rid of it here...
448 dev_kfree_skb(userdata
);
450 irlan_do_client_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
451 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
453 wake_up_interruptible(&self
->open_wait
);
456 void irlan_open_data_tsap(struct irlan_cb
*self
)
458 struct tsap_cb
*tsap
;
461 IRDA_DEBUG(2, "%s()\n", __func__
);
463 IRDA_ASSERT(self
!= NULL
, return;);
464 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
466 /* Check if already open */
470 irda_notify_init(¬ify
);
472 notify
.data_indication
= irlan_eth_receive
;
473 notify
.udata_indication
= irlan_eth_receive
;
474 notify
.connect_indication
= irlan_connect_indication
;
475 notify
.connect_confirm
= irlan_connect_confirm
;
476 notify
.flow_indication
= irlan_eth_flow_indication
;
477 notify
.disconnect_indication
= irlan_disconnect_indication
;
478 notify
.instance
= self
;
479 strlcpy(notify
.name
, "IrLAN data", sizeof(notify
.name
));
481 tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
, ¬ify
);
483 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__
);
486 self
->tsap_data
= tsap
;
489 * This is the data TSAP selector which we will pass to the client
490 * when the client ask for it.
492 self
->stsap_sel_data
= self
->tsap_data
->stsap_sel
;
495 void irlan_close_tsaps(struct irlan_cb
*self
)
497 IRDA_DEBUG(4, "%s()\n", __func__
);
499 IRDA_ASSERT(self
!= NULL
, return;);
500 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
502 /* Disconnect and close all open TSAP connections */
503 if (self
->tsap_data
) {
504 irttp_disconnect_request(self
->tsap_data
, NULL
, P_NORMAL
);
505 irttp_close_tsap(self
->tsap_data
);
506 self
->tsap_data
= NULL
;
508 if (self
->client
.tsap_ctrl
) {
509 irttp_disconnect_request(self
->client
.tsap_ctrl
, NULL
,
511 irttp_close_tsap(self
->client
.tsap_ctrl
);
512 self
->client
.tsap_ctrl
= NULL
;
514 if (self
->provider
.tsap_ctrl
) {
515 irttp_disconnect_request(self
->provider
.tsap_ctrl
, NULL
,
517 irttp_close_tsap(self
->provider
.tsap_ctrl
);
518 self
->provider
.tsap_ctrl
= NULL
;
520 self
->disconnect_reason
= LM_USER_REQUEST
;
524 * Function irlan_ias_register (self, tsap_sel)
526 * Register with LM-IAS
529 void irlan_ias_register(struct irlan_cb
*self
, __u8 tsap_sel
)
531 struct ias_object
*obj
;
532 struct ias_value
*new_value
;
534 IRDA_ASSERT(self
!= NULL
, return;);
535 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
538 * Check if object has already been registered by a previous provider.
539 * If that is the case, we just change the value of the attribute
541 if (!irias_find_object("IrLAN")) {
542 obj
= irias_new_object("IrLAN", IAS_IRLAN_ID
);
543 irias_add_integer_attrib(obj
, "IrDA:TinyTP:LsapSel", tsap_sel
,
545 irias_insert_object(obj
);
547 new_value
= irias_new_integer_value(tsap_sel
);
548 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
552 /* Register PnP object only if not registered before */
553 if (!irias_find_object("PnP")) {
554 obj
= irias_new_object("PnP", IAS_PNP_ID
);
556 irias_add_string_attrib(obj
, "Name", sysctl_devname
,
559 irias_add_string_attrib(obj
, "Name", "Linux", IAS_KERNEL_ATTR
);
561 irias_add_string_attrib(obj
, "DeviceID", "HWP19F0",
563 irias_add_integer_attrib(obj
, "CompCnt", 1, IAS_KERNEL_ATTR
);
564 if (self
->provider
.access_type
== ACCESS_PEER
)
565 irias_add_string_attrib(obj
, "Comp#01", "PNP8389",
568 irias_add_string_attrib(obj
, "Comp#01", "PNP8294",
571 irias_add_string_attrib(obj
, "Manufacturer",
572 "Linux-IrDA Project", IAS_KERNEL_ATTR
);
573 irias_insert_object(obj
);
578 * Function irlan_run_ctrl_tx_queue (self)
580 * Try to send the next command in the control transmit queue
583 int irlan_run_ctrl_tx_queue(struct irlan_cb
*self
)
587 IRDA_DEBUG(2, "%s()\n", __func__
);
589 if (irda_lock(&self
->client
.tx_busy
) == FALSE
)
592 skb
= skb_dequeue(&self
->client
.txq
);
594 self
->client
.tx_busy
= FALSE
;
598 /* Check that it's really possible to send commands */
599 if ((self
->client
.tsap_ctrl
== NULL
) ||
600 (self
->client
.state
== IRLAN_IDLE
))
602 self
->client
.tx_busy
= FALSE
;
606 IRDA_DEBUG(2, "%s(), sending ...\n", __func__
);
608 return irttp_data_request(self
->client
.tsap_ctrl
, skb
);
612 * Function irlan_ctrl_data_request (self, skb)
614 * This function makes sure that commands on the control channel is being
615 * sent in a command/response fashion
617 static void irlan_ctrl_data_request(struct irlan_cb
*self
, struct sk_buff
*skb
)
619 IRDA_DEBUG(2, "%s()\n", __func__
);
622 skb_queue_tail(&self
->client
.txq
, skb
);
624 /* Try to send command */
625 irlan_run_ctrl_tx_queue(self
);
629 * Function irlan_get_provider_info (self)
631 * Send Get Provider Information command to peer IrLAN layer
634 void irlan_get_provider_info(struct irlan_cb
*self
)
639 IRDA_DEBUG(4, "%s()\n", __func__
);
641 IRDA_ASSERT(self
!= NULL
, return;);
642 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
644 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
,
649 /* Reserve space for TTP, LMP, and LAP header */
650 skb_reserve(skb
, self
->client
.max_header_size
);
655 frame
[0] = CMD_GET_PROVIDER_INFO
;
656 frame
[1] = 0x00; /* Zero parameters */
658 irlan_ctrl_data_request(self
, skb
);
662 * Function irlan_open_data_channel (self)
664 * Send an Open Data Command to provider
667 void irlan_open_data_channel(struct irlan_cb
*self
)
672 IRDA_DEBUG(4, "%s()\n", __func__
);
674 IRDA_ASSERT(self
!= NULL
, return;);
675 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
677 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
678 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
679 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
684 skb_reserve(skb
, self
->client
.max_header_size
);
690 frame
[0] = CMD_OPEN_DATA_CHANNEL
;
691 frame
[1] = 0x02; /* Two parameters */
693 irlan_insert_string_param(skb
, "MEDIA", "802.3");
694 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
695 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
697 /* self->use_udata = TRUE; */
699 irlan_ctrl_data_request(self
, skb
);
702 void irlan_close_data_channel(struct irlan_cb
*self
)
707 IRDA_DEBUG(4, "%s()\n", __func__
);
709 IRDA_ASSERT(self
!= NULL
, return;);
710 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
712 /* Check if the TSAP is still there */
713 if (self
->client
.tsap_ctrl
== NULL
)
716 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
717 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
722 skb_reserve(skb
, self
->client
.max_header_size
);
728 frame
[0] = CMD_CLOSE_DATA_CHAN
;
729 frame
[1] = 0x01; /* One parameter */
731 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
733 irlan_ctrl_data_request(self
, skb
);
737 * Function irlan_open_unicast_addr (self)
739 * Make IrLAN provider accept ethernet frames addressed to the unicast
743 static void irlan_open_unicast_addr(struct irlan_cb
*self
)
748 IRDA_DEBUG(4, "%s()\n", __func__
);
750 IRDA_ASSERT(self
!= NULL
, return;);
751 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
753 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
754 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
755 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
756 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
761 /* Reserve space for TTP, LMP, and LAP header */
762 skb_reserve(skb
, self
->max_header_size
);
767 frame
[0] = CMD_FILTER_OPERATION
;
768 frame
[1] = 0x03; /* Three parameters */
769 irlan_insert_byte_param(skb
, "DATA_CHAN" , self
->dtsap_sel_data
);
770 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
771 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
773 irlan_ctrl_data_request(self
, skb
);
777 * Function irlan_set_broadcast_filter (self, status)
779 * Make IrLAN provider accept ethernet frames addressed to the broadcast
780 * address. Be careful with the use of this one, since there may be a lot
781 * of broadcast traffic out there. We can still function without this
782 * one but then _we_ have to initiate all communication with other
783 * hosts, since ARP request for this host will not be answered.
785 void irlan_set_broadcast_filter(struct irlan_cb
*self
, int status
)
790 IRDA_DEBUG(2, "%s()\n", __func__
);
792 IRDA_ASSERT(self
!= NULL
, return;);
793 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
795 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
796 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
797 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
798 /* We may waste one byte here...*/
799 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
804 /* Reserve space for TTP, LMP, and LAP header */
805 skb_reserve(skb
, self
->client
.max_header_size
);
810 frame
[0] = CMD_FILTER_OPERATION
;
811 frame
[1] = 0x03; /* Three parameters */
812 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
813 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
815 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
817 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
819 irlan_ctrl_data_request(self
, skb
);
823 * Function irlan_set_multicast_filter (self, status)
825 * Make IrLAN provider accept ethernet frames addressed to the multicast
829 void irlan_set_multicast_filter(struct irlan_cb
*self
, int status
)
834 IRDA_DEBUG(2, "%s()\n", __func__
);
836 IRDA_ASSERT(self
!= NULL
, return;);
837 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
839 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
840 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
841 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
842 /* We may waste one byte here...*/
843 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
848 /* Reserve space for TTP, LMP, and LAP header */
849 skb_reserve(skb
, self
->client
.max_header_size
);
854 frame
[0] = CMD_FILTER_OPERATION
;
855 frame
[1] = 0x03; /* Three parameters */
856 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
857 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
859 irlan_insert_string_param(skb
, "FILTER_MODE", "ALL");
861 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
863 irlan_ctrl_data_request(self
, skb
);
867 * Function irlan_get_unicast_addr (self)
869 * Retrieves the unicast address from the IrLAN provider. This address
870 * will be inserted into the devices structure, so the ethernet layer
871 * can construct its packets.
874 static void irlan_get_unicast_addr(struct irlan_cb
*self
)
879 IRDA_DEBUG(2, "%s()\n", __func__
);
881 IRDA_ASSERT(self
!= NULL
, return;);
882 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
884 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
885 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
886 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
887 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
893 /* Reserve space for TTP, LMP, and LAP header */
894 skb_reserve(skb
, self
->client
.max_header_size
);
899 frame
[0] = CMD_FILTER_OPERATION
;
900 frame
[1] = 0x03; /* Three parameters */
901 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
902 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
903 irlan_insert_string_param(skb
, "FILTER_OPERATION", "DYNAMIC");
905 irlan_ctrl_data_request(self
, skb
);
909 * Function irlan_get_media_char (self)
914 void irlan_get_media_char(struct irlan_cb
*self
)
919 IRDA_DEBUG(4, "%s()\n", __func__
);
921 IRDA_ASSERT(self
!= NULL
, return;);
922 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
924 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
925 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
931 /* Reserve space for TTP, LMP, and LAP header */
932 skb_reserve(skb
, self
->client
.max_header_size
);
938 frame
[0] = CMD_GET_MEDIA_CHAR
;
939 frame
[1] = 0x01; /* One parameter */
941 irlan_insert_string_param(skb
, "MEDIA", "802.3");
942 irlan_ctrl_data_request(self
, skb
);
946 * Function insert_byte_param (skb, param, value)
948 * Insert byte parameter into frame
951 int irlan_insert_byte_param(struct sk_buff
*skb
, char *param
, __u8 value
)
953 return __irlan_insert_param(skb
, param
, IRLAN_BYTE
, value
, 0, NULL
, 0);
956 int irlan_insert_short_param(struct sk_buff
*skb
, char *param
, __u16 value
)
958 return __irlan_insert_param(skb
, param
, IRLAN_SHORT
, 0, value
, NULL
, 0);
962 * Function insert_string (skb, param, value)
964 * Insert string parameter into frame
967 int irlan_insert_string_param(struct sk_buff
*skb
, char *param
, char *string
)
969 int string_len
= strlen(string
);
971 return __irlan_insert_param(skb
, param
, IRLAN_ARRAY
, 0, 0, string
,
976 * Function insert_array_param(skb, param, value, len_value)
978 * Insert array parameter into frame
981 int irlan_insert_array_param(struct sk_buff
*skb
, char *name
, __u8
*array
,
984 return __irlan_insert_param(skb
, name
, IRLAN_ARRAY
, 0, 0, array
,
989 * Function insert_param (skb, param, value, byte)
991 * Insert parameter at end of buffer, structure of a parameter is:
993 * -----------------------------------------------------------------------
994 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
995 * -----------------------------------------------------------------------
997 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
998 __u8 value_byte
, __u16 value_short
,
999 __u8
*value_array
, __u16 value_len
)
1003 __le16 tmp_le
; /* Temporary value in little endian format */
1007 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __func__
);
1011 param_len
= strlen(param
);
1020 IRDA_ASSERT(value_array
!= NULL
, return 0;);
1021 IRDA_ASSERT(value_len
> 0, return 0;);
1024 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __func__
);
1029 /* Insert at end of sk-buffer */
1030 frame
= skb_tail_pointer(skb
);
1032 /* Make space for data */
1033 if (skb_tailroom(skb
) < (param_len
+value_len
+3)) {
1034 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __func__
);
1037 skb_put(skb
, param_len
+value_len
+3);
1039 /* Insert parameter length */
1040 frame
[n
++] = param_len
;
1042 /* Insert parameter */
1043 memcpy(frame
+n
, param
, param_len
); n
+= param_len
;
1045 /* Insert value length (2 byte little endian format, LSB first) */
1046 tmp_le
= cpu_to_le16(value_len
);
1047 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2; /* To avoid alignment problems */
1052 frame
[n
++] = value_byte
;
1055 tmp_le
= cpu_to_le16(value_short
);
1056 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2;
1059 memcpy(frame
+n
, value_array
, value_len
); n
+=value_len
;
1064 IRDA_ASSERT(n
== (param_len
+value_len
+3), return 0;);
1066 return param_len
+value_len
+3;
1070 * Function irlan_extract_param (buf, name, value, len)
1072 * Extracts a single parameter name/value pair from buffer and updates
1073 * the buffer pointer to point to the next name/value pair.
1075 int irlan_extract_param(__u8
*buf
, char *name
, char *value
, __u16
*len
)
1081 IRDA_DEBUG(4, "%s()\n", __func__
);
1083 /* get length of parameter name (1 byte) */
1084 name_len
= buf
[n
++];
1086 if (name_len
> 254) {
1087 IRDA_DEBUG(2, "%s(), name_len > 254\n", __func__
);
1088 return -RSP_INVALID_COMMAND_FORMAT
;
1091 /* get parameter name */
1092 memcpy(name
, buf
+n
, name_len
);
1093 name
[name_len
] = '\0';
1097 * Get length of parameter value (2 bytes in little endian
1100 memcpy(&val_len
, buf
+n
, 2); /* To avoid alignment problems */
1101 le16_to_cpus(&val_len
); n
+=2;
1103 if (val_len
> 1016) {
1104 IRDA_DEBUG(2, "%s(), parameter length to long\n", __func__
);
1105 return -RSP_INVALID_COMMAND_FORMAT
;
1109 /* get parameter value */
1110 memcpy(value
, buf
+n
, val_len
);
1111 value
[val_len
] = '\0';
1114 IRDA_DEBUG(4, "Parameter: %s ", name
);
1115 IRDA_DEBUG(4, "Value: %s\n", value
);
1120 #ifdef CONFIG_PROC_FS
1123 * Start of reading /proc entries.
1124 * Return entry at pos,
1125 * or start_token to indicate print header line
1126 * or NULL if end of file
1128 static void *irlan_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1131 struct irlan_cb
*self
;
1135 return SEQ_START_TOKEN
;
1137 list_for_each_entry(self
, &irlans
, dev_list
) {
1145 /* Return entry after v, and increment pos */
1146 static void *irlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1148 struct list_head
*nxt
;
1151 if (v
== SEQ_START_TOKEN
)
1154 nxt
= ((struct irlan_cb
*)v
)->dev_list
.next
;
1156 return (nxt
== &irlans
) ? NULL
1157 : list_entry(nxt
, struct irlan_cb
, dev_list
);
1160 /* End of reading /proc file */
1161 static void irlan_seq_stop(struct seq_file
*seq
, void *v
)
1168 * Show one entry in /proc file.
1170 static int irlan_seq_show(struct seq_file
*seq
, void *v
)
1172 if (v
== SEQ_START_TOKEN
)
1173 seq_puts(seq
, "IrLAN instances:\n");
1175 struct irlan_cb
*self
= v
;
1177 IRDA_ASSERT(self
!= NULL
, return -1;);
1178 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
1180 seq_printf(seq
,"ifname: %s,\n",
1182 seq_printf(seq
,"client state: %s, ",
1183 irlan_state
[ self
->client
.state
]);
1184 seq_printf(seq
,"provider state: %s,\n",
1185 irlan_state
[ self
->provider
.state
]);
1186 seq_printf(seq
,"saddr: %#08x, ",
1188 seq_printf(seq
,"daddr: %#08x\n",
1190 seq_printf(seq
,"version: %d.%d,\n",
1191 self
->version
[1], self
->version
[0]);
1192 seq_printf(seq
,"access type: %s\n",
1193 irlan_access
[self
->client
.access_type
]);
1194 seq_printf(seq
,"media: %s\n",
1195 irlan_media
[self
->media
]);
1197 seq_printf(seq
,"local filter:\n");
1198 seq_printf(seq
,"remote filter: ");
1199 irlan_print_filter(seq
, self
->client
.filter_type
);
1200 seq_printf(seq
,"tx busy: %s\n",
1201 netif_queue_stopped(self
->dev
) ? "TRUE" : "FALSE");
1208 static const struct seq_operations irlan_seq_ops
= {
1209 .start
= irlan_seq_start
,
1210 .next
= irlan_seq_next
,
1211 .stop
= irlan_seq_stop
,
1212 .show
= irlan_seq_show
,
1215 static int irlan_seq_open(struct inode
*inode
, struct file
*file
)
1217 return seq_open(file
, &irlan_seq_ops
);
1221 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1222 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1223 MODULE_LICENSE("GPL");
1225 module_param(eth
, bool, 0);
1226 MODULE_PARM_DESC(eth
, "Name devices ethX (0) or irlanX (1)");
1227 module_param(access
, int, 0);
1228 MODULE_PARM_DESC(access
, "Access type DIRECT=1, PEER=2, HOSTED=3");
1230 module_init(irlan_init
);
1231 module_exit(irlan_cleanup
);