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/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>
43 #include <asm/system.h>
44 #include <asm/byteorder.h>
46 #include <net/irda/irda.h>
47 #include <net/irda/irttp.h>
48 #include <net/irda/irlmp.h>
49 #include <net/irda/iriap.h>
50 #include <net/irda/timer.h>
52 #include <net/irda/irlan_common.h>
53 #include <net/irda/irlan_client.h>
54 #include <net/irda/irlan_provider.h>
55 #include <net/irda/irlan_eth.h>
56 #include <net/irda/irlan_filter.h>
59 /* extern char sysctl_devname[]; */
64 static LIST_HEAD(irlans
);
69 /* Module parameters */
70 static int eth
; /* Use "eth" or "irlan" name for devices */
71 static int access
= ACCESS_PEER
; /* PEER, DIRECT or HOSTED */
74 static const char *const irlan_access
[] = {
81 static const char *const irlan_media
[] = {
87 extern struct proc_dir_entry
*proc_irda
;
89 static int irlan_seq_open(struct inode
*inode
, struct file
*file
);
91 static const struct file_operations irlan_fops
= {
93 .open
= irlan_seq_open
,
96 .release
= seq_release
,
99 extern struct proc_dir_entry
*proc_irda
;
100 #endif /* CONFIG_PROC_FS */
102 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
);
103 static void __irlan_close(struct irlan_cb
*self
);
104 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
105 __u8 value_byte
, __u16 value_short
,
106 __u8
*value_array
, __u16 value_len
);
107 static void irlan_open_unicast_addr(struct irlan_cb
*self
);
108 static void irlan_get_unicast_addr(struct irlan_cb
*self
);
109 void irlan_close_tsaps(struct irlan_cb
*self
);
112 * Function irlan_init (void)
114 * Initialize IrLAN layer
117 static int __init
irlan_init(void)
119 struct irlan_cb
*new;
122 IRDA_DEBUG(2, "%s()\n", __func__
);
124 #ifdef CONFIG_PROC_FS
125 { struct proc_dir_entry
*proc
;
126 proc
= proc_create("irlan", 0, proc_irda
, &irlan_fops
);
128 printk(KERN_ERR
"irlan_init: can't create /proc entry!\n");
132 #endif /* CONFIG_PROC_FS */
134 IRDA_DEBUG(4, "%s()\n", __func__
);
135 hints
= irlmp_service_to_hint(S_LAN
);
137 /* Register with IrLMP as a client */
138 ckey
= irlmp_register_client(hints
, &irlan_client_discovery_indication
,
143 /* Register with IrLMP as a service */
144 skey
= irlmp_register_service(hints
);
148 /* Start the master IrLAN instance (the only one for now) */
149 new = irlan_open(DEV_ADDR_ANY
, DEV_ADDR_ANY
);
153 /* The master will only open its (listen) control TSAP */
154 irlan_provider_open_ctrl_tsap(new);
156 /* Do some fast discovery! */
157 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
162 irlmp_unregister_service(skey
);
164 irlmp_unregister_client(ckey
);
166 #ifdef CONFIG_PROC_FS
167 remove_proc_entry("irlan", proc_irda
);
168 #endif /* CONFIG_PROC_FS */
173 static void __exit
irlan_cleanup(void)
175 struct irlan_cb
*self
, *next
;
177 IRDA_DEBUG(4, "%s()\n", __func__
);
179 irlmp_unregister_client(ckey
);
180 irlmp_unregister_service(skey
);
182 #ifdef CONFIG_PROC_FS
183 remove_proc_entry("irlan", proc_irda
);
184 #endif /* CONFIG_PROC_FS */
186 /* Cleanup any leftover network devices */
188 list_for_each_entry_safe(self
, next
, &irlans
, dev_list
) {
195 * Function irlan_open (void)
197 * Open new instance of a client/provider, we should only register the
198 * network device if this instance is ment for a particular client/provider
200 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
)
202 struct net_device
*dev
;
203 struct irlan_cb
*self
;
205 IRDA_DEBUG(2, "%s()\n", __func__
);
207 /* Create network device with irlan */
208 dev
= alloc_irlandev(eth
? "eth%d" : "irlan%d");
212 self
= netdev_priv(dev
);
216 * Initialize local device structure
218 self
->magic
= IRLAN_MAGIC
;
222 /* Provider access can only be PEER, DIRECT, or HOSTED */
223 self
->provider
.access_type
= access
;
224 if (access
== ACCESS_DIRECT
) {
226 * Since we are emulating an IrLAN sever we will have to
227 * give ourself an ethernet address!
229 dev
->dev_addr
[0] = 0x40;
230 dev
->dev_addr
[1] = 0x00;
231 dev
->dev_addr
[2] = 0x00;
232 dev
->dev_addr
[3] = 0x00;
233 get_random_bytes(dev
->dev_addr
+4, 1);
234 get_random_bytes(dev
->dev_addr
+5, 1);
237 self
->media
= MEDIA_802_3
;
238 self
->disconnect_reason
= LM_USER_REQUEST
;
239 init_timer(&self
->watchdog_timer
);
240 init_timer(&self
->client
.kick_timer
);
241 init_waitqueue_head(&self
->open_wait
);
243 skb_queue_head_init(&self
->client
.txq
);
245 irlan_next_client_state(self
, IRLAN_IDLE
);
246 irlan_next_provider_state(self
, IRLAN_IDLE
);
248 if (register_netdev(dev
)) {
249 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
255 list_add_rcu(&self
->dev_list
, &irlans
);
262 * Function __irlan_close (self)
264 * This function closes and deallocates the IrLAN client instances. Be
265 * aware that other functions which calls client_close() must
266 * remove self from irlans list first.
268 static void __irlan_close(struct irlan_cb
*self
)
270 IRDA_DEBUG(2, "%s()\n", __func__
);
273 IRDA_ASSERT(self
!= NULL
, return;);
274 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
276 del_timer_sync(&self
->watchdog_timer
);
277 del_timer_sync(&self
->client
.kick_timer
);
279 /* Close all open connections and remove TSAPs */
280 irlan_close_tsaps(self
);
282 if (self
->client
.iriap
)
283 iriap_close(self
->client
.iriap
);
285 /* Remove frames queued on the control channel */
286 skb_queue_purge(&self
->client
.txq
);
288 /* Unregister and free self via destructor */
289 unregister_netdevice(self
->dev
);
292 /* Find any instance of irlan, used for client discovery wakeup */
293 struct irlan_cb
*irlan_get_any(void)
295 struct irlan_cb
*self
;
297 list_for_each_entry_rcu(self
, &irlans
, dev_list
) {
304 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
306 * Here we receive the connect indication for the data channel
309 static void irlan_connect_indication(void *instance
, void *sap
,
310 struct qos_info
*qos
,
312 __u8 max_header_size
,
315 struct irlan_cb
*self
;
316 struct tsap_cb
*tsap
;
318 IRDA_DEBUG(2, "%s()\n", __func__
);
320 self
= (struct irlan_cb
*) instance
;
321 tsap
= (struct tsap_cb
*) sap
;
323 IRDA_ASSERT(self
!= NULL
, return;);
324 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
325 IRDA_ASSERT(tsap
== self
->tsap_data
,return;);
327 self
->max_sdu_size
= max_sdu_size
;
328 self
->max_header_size
= max_header_size
;
330 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
332 del_timer(&self
->watchdog_timer
);
334 /* If you want to pass the skb to *both* state machines, you will
335 * need to skb_clone() it, so that you don't free it twice.
336 * As the state machines don't need it, git rid of it here...
341 irlan_do_provider_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
342 irlan_do_client_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
344 if (self
->provider
.access_type
== ACCESS_PEER
) {
346 * Data channel is open, so we are now allowed to
347 * configure the remote filter
349 irlan_get_unicast_addr(self
);
350 irlan_open_unicast_addr(self
);
352 /* Ready to transfer Ethernet frames (at last) */
353 netif_start_queue(self
->dev
); /* Clear reason */
356 static void irlan_connect_confirm(void *instance
, void *sap
,
357 struct qos_info
*qos
,
359 __u8 max_header_size
,
362 struct irlan_cb
*self
;
364 self
= (struct irlan_cb
*) instance
;
366 IRDA_ASSERT(self
!= NULL
, return;);
367 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
369 self
->max_sdu_size
= max_sdu_size
;
370 self
->max_header_size
= max_header_size
;
372 /* TODO: we could set the MTU depending on the max_sdu_size */
374 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
375 del_timer(&self
->watchdog_timer
);
378 * Data channel is open, so we are now allowed to configure the remote
381 irlan_get_unicast_addr(self
);
382 irlan_open_unicast_addr(self
);
384 /* Open broadcast and multicast filter by default */
385 irlan_set_broadcast_filter(self
, TRUE
);
386 irlan_set_multicast_filter(self
, TRUE
);
388 /* Ready to transfer Ethernet frames */
389 netif_start_queue(self
->dev
);
390 self
->disconnect_reason
= 0; /* Clear reason */
391 wake_up_interruptible(&self
->open_wait
);
395 * Function irlan_client_disconnect_indication (handle)
397 * Callback function for the IrTTP layer. Indicates a disconnection of
398 * the specified connection (handle)
400 static void irlan_disconnect_indication(void *instance
,
401 void *sap
, LM_REASON reason
,
402 struct sk_buff
*userdata
)
404 struct irlan_cb
*self
;
405 struct tsap_cb
*tsap
;
407 IRDA_DEBUG(0, "%s(), reason=%d\n", __func__
, reason
);
409 self
= (struct irlan_cb
*) instance
;
410 tsap
= (struct tsap_cb
*) sap
;
412 IRDA_ASSERT(self
!= NULL
, return;);
413 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
414 IRDA_ASSERT(tsap
!= NULL
, return;);
415 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
417 IRDA_ASSERT(tsap
== self
->tsap_data
, return;);
419 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
421 /* Save reason so we know if we should try to reconnect or not */
422 self
->disconnect_reason
= reason
;
425 case LM_USER_REQUEST
: /* User request */
426 IRDA_DEBUG(2, "%s(), User requested\n", __func__
);
428 case LM_LAP_DISCONNECT
: /* Unexpected IrLAP disconnect */
429 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __func__
);
431 case LM_CONNECT_FAILURE
: /* Failed to establish IrLAP connection */
432 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __func__
);
434 case LM_LAP_RESET
: /* IrLAP reset */
435 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __func__
);
437 case LM_INIT_DISCONNECT
:
438 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __func__
);
441 IRDA_ERROR("%s(), Unknown disconnect reason\n", __func__
);
445 /* If you want to pass the skb to *both* state machines, you will
446 * need to skb_clone() it, so that you don't free it twice.
447 * As the state machines don't need it, git rid of it here...
450 dev_kfree_skb(userdata
);
452 irlan_do_client_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
453 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
455 wake_up_interruptible(&self
->open_wait
);
458 void irlan_open_data_tsap(struct irlan_cb
*self
)
460 struct tsap_cb
*tsap
;
463 IRDA_DEBUG(2, "%s()\n", __func__
);
465 IRDA_ASSERT(self
!= NULL
, return;);
466 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
468 /* Check if already open */
472 irda_notify_init(¬ify
);
474 notify
.data_indication
= irlan_eth_receive
;
475 notify
.udata_indication
= irlan_eth_receive
;
476 notify
.connect_indication
= irlan_connect_indication
;
477 notify
.connect_confirm
= irlan_connect_confirm
;
478 notify
.flow_indication
= irlan_eth_flow_indication
;
479 notify
.disconnect_indication
= irlan_disconnect_indication
;
480 notify
.instance
= self
;
481 strlcpy(notify
.name
, "IrLAN data", sizeof(notify
.name
));
483 tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
, ¬ify
);
485 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__
);
488 self
->tsap_data
= tsap
;
491 * This is the data TSAP selector which we will pass to the client
492 * when the client ask for it.
494 self
->stsap_sel_data
= self
->tsap_data
->stsap_sel
;
497 void irlan_close_tsaps(struct irlan_cb
*self
)
499 IRDA_DEBUG(4, "%s()\n", __func__
);
501 IRDA_ASSERT(self
!= NULL
, return;);
502 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
504 /* Disconnect and close all open TSAP connections */
505 if (self
->tsap_data
) {
506 irttp_disconnect_request(self
->tsap_data
, NULL
, P_NORMAL
);
507 irttp_close_tsap(self
->tsap_data
);
508 self
->tsap_data
= NULL
;
510 if (self
->client
.tsap_ctrl
) {
511 irttp_disconnect_request(self
->client
.tsap_ctrl
, NULL
,
513 irttp_close_tsap(self
->client
.tsap_ctrl
);
514 self
->client
.tsap_ctrl
= NULL
;
516 if (self
->provider
.tsap_ctrl
) {
517 irttp_disconnect_request(self
->provider
.tsap_ctrl
, NULL
,
519 irttp_close_tsap(self
->provider
.tsap_ctrl
);
520 self
->provider
.tsap_ctrl
= NULL
;
522 self
->disconnect_reason
= LM_USER_REQUEST
;
526 * Function irlan_ias_register (self, tsap_sel)
528 * Register with LM-IAS
531 void irlan_ias_register(struct irlan_cb
*self
, __u8 tsap_sel
)
533 struct ias_object
*obj
;
534 struct ias_value
*new_value
;
536 IRDA_ASSERT(self
!= NULL
, return;);
537 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
540 * Check if object has already been registered by a previous provider.
541 * If that is the case, we just change the value of the attribute
543 if (!irias_find_object("IrLAN")) {
544 obj
= irias_new_object("IrLAN", IAS_IRLAN_ID
);
545 irias_add_integer_attrib(obj
, "IrDA:TinyTP:LsapSel", tsap_sel
,
547 irias_insert_object(obj
);
549 new_value
= irias_new_integer_value(tsap_sel
);
550 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
554 /* Register PnP object only if not registered before */
555 if (!irias_find_object("PnP")) {
556 obj
= irias_new_object("PnP", IAS_PNP_ID
);
557 irias_add_string_attrib(obj
, "Name", "Linux", IAS_KERNEL_ATTR
);
558 irias_add_string_attrib(obj
, "DeviceID", "HWP19F0",
560 irias_add_integer_attrib(obj
, "CompCnt", 1, IAS_KERNEL_ATTR
);
561 if (self
->provider
.access_type
== ACCESS_PEER
)
562 irias_add_string_attrib(obj
, "Comp#01", "PNP8389",
565 irias_add_string_attrib(obj
, "Comp#01", "PNP8294",
568 irias_add_string_attrib(obj
, "Manufacturer",
569 "Linux-IrDA Project", IAS_KERNEL_ATTR
);
570 irias_insert_object(obj
);
575 * Function irlan_run_ctrl_tx_queue (self)
577 * Try to send the next command in the control transmit queue
580 int irlan_run_ctrl_tx_queue(struct irlan_cb
*self
)
584 IRDA_DEBUG(2, "%s()\n", __func__
);
586 if (irda_lock(&self
->client
.tx_busy
) == FALSE
)
589 skb
= skb_dequeue(&self
->client
.txq
);
591 self
->client
.tx_busy
= FALSE
;
595 /* Check that it's really possible to send commands */
596 if ((self
->client
.tsap_ctrl
== NULL
) ||
597 (self
->client
.state
== IRLAN_IDLE
))
599 self
->client
.tx_busy
= FALSE
;
603 IRDA_DEBUG(2, "%s(), sending ...\n", __func__
);
605 return irttp_data_request(self
->client
.tsap_ctrl
, skb
);
609 * Function irlan_ctrl_data_request (self, skb)
611 * This function makes sure that commands on the control channel is being
612 * sent in a command/response fashion
614 static void irlan_ctrl_data_request(struct irlan_cb
*self
, struct sk_buff
*skb
)
616 IRDA_DEBUG(2, "%s()\n", __func__
);
619 skb_queue_tail(&self
->client
.txq
, skb
);
621 /* Try to send command */
622 irlan_run_ctrl_tx_queue(self
);
626 * Function irlan_get_provider_info (self)
628 * Send Get Provider Information command to peer IrLAN layer
631 void irlan_get_provider_info(struct irlan_cb
*self
)
636 IRDA_DEBUG(4, "%s()\n", __func__
);
638 IRDA_ASSERT(self
!= NULL
, return;);
639 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
641 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
,
646 /* Reserve space for TTP, LMP, and LAP header */
647 skb_reserve(skb
, self
->client
.max_header_size
);
652 frame
[0] = CMD_GET_PROVIDER_INFO
;
653 frame
[1] = 0x00; /* Zero parameters */
655 irlan_ctrl_data_request(self
, skb
);
659 * Function irlan_open_data_channel (self)
661 * Send an Open Data Command to provider
664 void irlan_open_data_channel(struct irlan_cb
*self
)
669 IRDA_DEBUG(4, "%s()\n", __func__
);
671 IRDA_ASSERT(self
!= NULL
, return;);
672 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
674 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
675 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
676 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
681 skb_reserve(skb
, self
->client
.max_header_size
);
687 frame
[0] = CMD_OPEN_DATA_CHANNEL
;
688 frame
[1] = 0x02; /* Two parameters */
690 irlan_insert_string_param(skb
, "MEDIA", "802.3");
691 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
692 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
694 /* self->use_udata = TRUE; */
696 irlan_ctrl_data_request(self
, skb
);
699 void irlan_close_data_channel(struct irlan_cb
*self
)
704 IRDA_DEBUG(4, "%s()\n", __func__
);
706 IRDA_ASSERT(self
!= NULL
, return;);
707 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
709 /* Check if the TSAP is still there */
710 if (self
->client
.tsap_ctrl
== NULL
)
713 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
714 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
719 skb_reserve(skb
, self
->client
.max_header_size
);
725 frame
[0] = CMD_CLOSE_DATA_CHAN
;
726 frame
[1] = 0x01; /* One parameter */
728 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
730 irlan_ctrl_data_request(self
, skb
);
734 * Function irlan_open_unicast_addr (self)
736 * Make IrLAN provider accept ethernet frames addressed to the unicast
740 static void irlan_open_unicast_addr(struct irlan_cb
*self
)
745 IRDA_DEBUG(4, "%s()\n", __func__
);
747 IRDA_ASSERT(self
!= NULL
, return;);
748 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
750 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
751 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
752 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
753 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
758 /* Reserve space for TTP, LMP, and LAP header */
759 skb_reserve(skb
, self
->max_header_size
);
764 frame
[0] = CMD_FILTER_OPERATION
;
765 frame
[1] = 0x03; /* Three parameters */
766 irlan_insert_byte_param(skb
, "DATA_CHAN" , self
->dtsap_sel_data
);
767 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
768 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
770 irlan_ctrl_data_request(self
, skb
);
774 * Function irlan_set_broadcast_filter (self, status)
776 * Make IrLAN provider accept ethernet frames addressed to the broadcast
777 * address. Be careful with the use of this one, since there may be a lot
778 * of broadcast traffic out there. We can still function without this
779 * one but then _we_ have to initiate all communication with other
780 * hosts, since ARP request for this host will not be answered.
782 void irlan_set_broadcast_filter(struct irlan_cb
*self
, int status
)
787 IRDA_DEBUG(2, "%s()\n", __func__
);
789 IRDA_ASSERT(self
!= NULL
, return;);
790 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
792 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
793 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
794 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
795 /* We may waste one byte here...*/
796 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
801 /* Reserve space for TTP, LMP, and LAP header */
802 skb_reserve(skb
, self
->client
.max_header_size
);
807 frame
[0] = CMD_FILTER_OPERATION
;
808 frame
[1] = 0x03; /* Three parameters */
809 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
810 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
812 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
814 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
816 irlan_ctrl_data_request(self
, skb
);
820 * Function irlan_set_multicast_filter (self, status)
822 * Make IrLAN provider accept ethernet frames addressed to the multicast
826 void irlan_set_multicast_filter(struct irlan_cb
*self
, int status
)
831 IRDA_DEBUG(2, "%s()\n", __func__
);
833 IRDA_ASSERT(self
!= NULL
, return;);
834 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
836 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
837 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
838 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
839 /* We may waste one byte here...*/
840 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
845 /* Reserve space for TTP, LMP, and LAP header */
846 skb_reserve(skb
, self
->client
.max_header_size
);
851 frame
[0] = CMD_FILTER_OPERATION
;
852 frame
[1] = 0x03; /* Three parameters */
853 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
854 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
856 irlan_insert_string_param(skb
, "FILTER_MODE", "ALL");
858 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
860 irlan_ctrl_data_request(self
, skb
);
864 * Function irlan_get_unicast_addr (self)
866 * Retrieves the unicast address from the IrLAN provider. This address
867 * will be inserted into the devices structure, so the ethernet layer
868 * can construct its packets.
871 static void irlan_get_unicast_addr(struct irlan_cb
*self
)
876 IRDA_DEBUG(2, "%s()\n", __func__
);
878 IRDA_ASSERT(self
!= NULL
, return;);
879 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
881 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
882 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
883 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
884 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
890 /* Reserve space for TTP, LMP, and LAP header */
891 skb_reserve(skb
, self
->client
.max_header_size
);
896 frame
[0] = CMD_FILTER_OPERATION
;
897 frame
[1] = 0x03; /* Three parameters */
898 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
899 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
900 irlan_insert_string_param(skb
, "FILTER_OPERATION", "DYNAMIC");
902 irlan_ctrl_data_request(self
, skb
);
906 * Function irlan_get_media_char (self)
911 void irlan_get_media_char(struct irlan_cb
*self
)
916 IRDA_DEBUG(4, "%s()\n", __func__
);
918 IRDA_ASSERT(self
!= NULL
, return;);
919 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
921 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
922 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
928 /* Reserve space for TTP, LMP, and LAP header */
929 skb_reserve(skb
, self
->client
.max_header_size
);
935 frame
[0] = CMD_GET_MEDIA_CHAR
;
936 frame
[1] = 0x01; /* One parameter */
938 irlan_insert_string_param(skb
, "MEDIA", "802.3");
939 irlan_ctrl_data_request(self
, skb
);
943 * Function insert_byte_param (skb, param, value)
945 * Insert byte parameter into frame
948 int irlan_insert_byte_param(struct sk_buff
*skb
, char *param
, __u8 value
)
950 return __irlan_insert_param(skb
, param
, IRLAN_BYTE
, value
, 0, NULL
, 0);
953 int irlan_insert_short_param(struct sk_buff
*skb
, char *param
, __u16 value
)
955 return __irlan_insert_param(skb
, param
, IRLAN_SHORT
, 0, value
, NULL
, 0);
959 * Function insert_string (skb, param, value)
961 * Insert string parameter into frame
964 int irlan_insert_string_param(struct sk_buff
*skb
, char *param
, char *string
)
966 int string_len
= strlen(string
);
968 return __irlan_insert_param(skb
, param
, IRLAN_ARRAY
, 0, 0, string
,
973 * Function insert_array_param(skb, param, value, len_value)
975 * Insert array parameter into frame
978 int irlan_insert_array_param(struct sk_buff
*skb
, char *name
, __u8
*array
,
981 return __irlan_insert_param(skb
, name
, IRLAN_ARRAY
, 0, 0, array
,
986 * Function insert_param (skb, param, value, byte)
988 * Insert parameter at end of buffer, structure of a parameter is:
990 * -----------------------------------------------------------------------
991 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
992 * -----------------------------------------------------------------------
994 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
995 __u8 value_byte
, __u16 value_short
,
996 __u8
*value_array
, __u16 value_len
)
1000 __le16 tmp_le
; /* Temporary value in little endian format */
1004 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __func__
);
1008 param_len
= strlen(param
);
1017 IRDA_ASSERT(value_array
!= NULL
, return 0;);
1018 IRDA_ASSERT(value_len
> 0, return 0;);
1021 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __func__
);
1026 /* Insert at end of sk-buffer */
1027 frame
= skb_tail_pointer(skb
);
1029 /* Make space for data */
1030 if (skb_tailroom(skb
) < (param_len
+value_len
+3)) {
1031 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __func__
);
1034 skb_put(skb
, param_len
+value_len
+3);
1036 /* Insert parameter length */
1037 frame
[n
++] = param_len
;
1039 /* Insert parameter */
1040 memcpy(frame
+n
, param
, param_len
); n
+= param_len
;
1042 /* Insert value length (2 byte little endian format, LSB first) */
1043 tmp_le
= cpu_to_le16(value_len
);
1044 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2; /* To avoid alignment problems */
1049 frame
[n
++] = value_byte
;
1052 tmp_le
= cpu_to_le16(value_short
);
1053 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2;
1056 memcpy(frame
+n
, value_array
, value_len
); n
+=value_len
;
1061 IRDA_ASSERT(n
== (param_len
+value_len
+3), return 0;);
1063 return param_len
+value_len
+3;
1067 * Function irlan_extract_param (buf, name, value, len)
1069 * Extracts a single parameter name/value pair from buffer and updates
1070 * the buffer pointer to point to the next name/value pair.
1072 int irlan_extract_param(__u8
*buf
, char *name
, char *value
, __u16
*len
)
1078 IRDA_DEBUG(4, "%s()\n", __func__
);
1080 /* get length of parameter name (1 byte) */
1081 name_len
= buf
[n
++];
1083 if (name_len
> 254) {
1084 IRDA_DEBUG(2, "%s(), name_len > 254\n", __func__
);
1085 return -RSP_INVALID_COMMAND_FORMAT
;
1088 /* get parameter name */
1089 memcpy(name
, buf
+n
, name_len
);
1090 name
[name_len
] = '\0';
1094 * Get length of parameter value (2 bytes in little endian
1097 memcpy(&val_len
, buf
+n
, 2); /* To avoid alignment problems */
1098 le16_to_cpus(&val_len
); n
+=2;
1100 if (val_len
>= 1016) {
1101 IRDA_DEBUG(2, "%s(), parameter length to long\n", __func__
);
1102 return -RSP_INVALID_COMMAND_FORMAT
;
1106 /* get parameter value */
1107 memcpy(value
, buf
+n
, val_len
);
1108 value
[val_len
] = '\0';
1111 IRDA_DEBUG(4, "Parameter: %s ", name
);
1112 IRDA_DEBUG(4, "Value: %s\n", value
);
1117 #ifdef CONFIG_PROC_FS
1120 * Start of reading /proc entries.
1121 * Return entry at pos,
1122 * or start_token to indicate print header line
1123 * or NULL if end of file
1125 static void *irlan_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1128 return seq_list_start_head(&irlans
, *pos
);
1131 /* Return entry after v, and increment pos */
1132 static void *irlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1134 return seq_list_next(v
, &irlans
, pos
);
1137 /* End of reading /proc file */
1138 static void irlan_seq_stop(struct seq_file
*seq
, void *v
)
1145 * Show one entry in /proc file.
1147 static int irlan_seq_show(struct seq_file
*seq
, void *v
)
1150 seq_puts(seq
, "IrLAN instances:\n");
1152 struct irlan_cb
*self
= list_entry(v
, struct irlan_cb
, dev_list
);
1154 IRDA_ASSERT(self
!= NULL
, return -1;);
1155 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
1157 seq_printf(seq
,"ifname: %s,\n",
1159 seq_printf(seq
,"client state: %s, ",
1160 irlan_state
[ self
->client
.state
]);
1161 seq_printf(seq
,"provider state: %s,\n",
1162 irlan_state
[ self
->provider
.state
]);
1163 seq_printf(seq
,"saddr: %#08x, ",
1165 seq_printf(seq
,"daddr: %#08x\n",
1167 seq_printf(seq
,"version: %d.%d,\n",
1168 self
->version
[1], self
->version
[0]);
1169 seq_printf(seq
,"access type: %s\n",
1170 irlan_access
[self
->client
.access_type
]);
1171 seq_printf(seq
,"media: %s\n",
1172 irlan_media
[self
->media
]);
1174 seq_printf(seq
,"local filter:\n");
1175 seq_printf(seq
,"remote filter: ");
1176 irlan_print_filter(seq
, self
->client
.filter_type
);
1177 seq_printf(seq
,"tx busy: %s\n",
1178 netif_queue_stopped(self
->dev
) ? "TRUE" : "FALSE");
1185 static const struct seq_operations irlan_seq_ops
= {
1186 .start
= irlan_seq_start
,
1187 .next
= irlan_seq_next
,
1188 .stop
= irlan_seq_stop
,
1189 .show
= irlan_seq_show
,
1192 static int irlan_seq_open(struct inode
*inode
, struct file
*file
)
1194 return seq_open(file
, &irlan_seq_ops
);
1198 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1199 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1200 MODULE_LICENSE("GPL");
1202 module_param(eth
, bool, 0);
1203 MODULE_PARM_DESC(eth
, "Name devices ethX (0) or irlanX (1)");
1204 module_param(access
, int, 0);
1205 MODULE_PARM_DESC(access
, "Access type DIRECT=1, PEER=2, HOSTED=3");
1207 module_init(irlan_init
);
1208 module_exit(irlan_cleanup
);