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/sched.h>
34 #include <linux/seq_file.h>
35 #include <linux/random.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/rtnetlink.h>
39 #include <linux/moduleparam.h>
40 #include <linux/bitops.h>
42 #include <asm/system.h>
43 #include <asm/byteorder.h>
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>
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>
58 /* extern char sysctl_devname[]; */
63 static LIST_HEAD(irlans
);
68 /* Module parameters */
69 static int eth
; /* Use "eth" or "irlan" name for devices */
70 static int access
= ACCESS_PEER
; /* PEER, DIRECT or HOSTED */
73 static const char *const irlan_access
[] = {
80 static const char *const irlan_media
[] = {
86 extern struct proc_dir_entry
*proc_irda
;
88 static int irlan_seq_open(struct inode
*inode
, struct file
*file
);
90 static const struct file_operations irlan_fops
= {
92 .open
= irlan_seq_open
,
95 .release
= seq_release
,
98 extern struct proc_dir_entry
*proc_irda
;
99 #endif /* CONFIG_PROC_FS */
101 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
);
102 static void __irlan_close(struct irlan_cb
*self
);
103 static 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
);
106 static void irlan_open_unicast_addr(struct irlan_cb
*self
);
107 static void irlan_get_unicast_addr(struct irlan_cb
*self
);
108 void irlan_close_tsaps(struct irlan_cb
*self
);
111 * Function irlan_init (void)
113 * Initialize IrLAN layer
116 static int __init
irlan_init(void)
118 struct irlan_cb
*new;
121 IRDA_DEBUG(2, "%s()\n", __func__
);
123 #ifdef CONFIG_PROC_FS
124 { struct proc_dir_entry
*proc
;
125 proc
= proc_create("irlan", 0, proc_irda
, &irlan_fops
);
127 printk(KERN_ERR
"irlan_init: can't create /proc entry!\n");
131 #endif /* CONFIG_PROC_FS */
133 IRDA_DEBUG(4, "%s()\n", __func__
);
134 hints
= irlmp_service_to_hint(S_LAN
);
136 /* Register with IrLMP as a client */
137 ckey
= irlmp_register_client(hints
, &irlan_client_discovery_indication
,
142 /* Register with IrLMP as a service */
143 skey
= irlmp_register_service(hints
);
147 /* Start the master IrLAN instance (the only one for now) */
148 new = irlan_open(DEV_ADDR_ANY
, DEV_ADDR_ANY
);
152 /* The master will only open its (listen) control TSAP */
153 irlan_provider_open_ctrl_tsap(new);
155 /* Do some fast discovery! */
156 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS
);
161 irlmp_unregister_service(skey
);
163 irlmp_unregister_client(ckey
);
165 #ifdef CONFIG_PROC_FS
166 remove_proc_entry("irlan", proc_irda
);
167 #endif /* CONFIG_PROC_FS */
172 static void __exit
irlan_cleanup(void)
174 struct irlan_cb
*self
, *next
;
176 IRDA_DEBUG(4, "%s()\n", __func__
);
178 irlmp_unregister_client(ckey
);
179 irlmp_unregister_service(skey
);
181 #ifdef CONFIG_PROC_FS
182 remove_proc_entry("irlan", proc_irda
);
183 #endif /* CONFIG_PROC_FS */
185 /* Cleanup any leftover network devices */
187 list_for_each_entry_safe(self
, next
, &irlans
, dev_list
) {
194 * Function irlan_open (void)
196 * Open new instance of a client/provider, we should only register the
197 * network device if this instance is ment for a particular client/provider
199 static struct irlan_cb
*irlan_open(__u32 saddr
, __u32 daddr
)
201 struct net_device
*dev
;
202 struct irlan_cb
*self
;
204 IRDA_DEBUG(2, "%s()\n", __func__
);
206 /* Create network device with irlan */
207 dev
= alloc_irlandev(eth
? "eth%d" : "irlan%d");
211 self
= netdev_priv(dev
);
215 * Initialize local device structure
217 self
->magic
= IRLAN_MAGIC
;
221 /* Provider access can only be PEER, DIRECT, or HOSTED */
222 self
->provider
.access_type
= access
;
223 if (access
== ACCESS_DIRECT
) {
225 * Since we are emulating an IrLAN sever we will have to
226 * give ourself an ethernet address!
228 dev
->dev_addr
[0] = 0x40;
229 dev
->dev_addr
[1] = 0x00;
230 dev
->dev_addr
[2] = 0x00;
231 dev
->dev_addr
[3] = 0x00;
232 get_random_bytes(dev
->dev_addr
+4, 1);
233 get_random_bytes(dev
->dev_addr
+5, 1);
236 self
->media
= MEDIA_802_3
;
237 self
->disconnect_reason
= LM_USER_REQUEST
;
238 init_timer(&self
->watchdog_timer
);
239 init_timer(&self
->client
.kick_timer
);
240 init_waitqueue_head(&self
->open_wait
);
242 skb_queue_head_init(&self
->client
.txq
);
244 irlan_next_client_state(self
, IRLAN_IDLE
);
245 irlan_next_provider_state(self
, IRLAN_IDLE
);
247 if (register_netdev(dev
)) {
248 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
254 list_add_rcu(&self
->dev_list
, &irlans
);
261 * Function __irlan_close (self)
263 * This function closes and deallocates the IrLAN client instances. Be
264 * aware that other functions which calls client_close() must
265 * remove self from irlans list first.
267 static void __irlan_close(struct irlan_cb
*self
)
269 IRDA_DEBUG(2, "%s()\n", __func__
);
272 IRDA_ASSERT(self
!= NULL
, return;);
273 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
275 del_timer_sync(&self
->watchdog_timer
);
276 del_timer_sync(&self
->client
.kick_timer
);
278 /* Close all open connections and remove TSAPs */
279 irlan_close_tsaps(self
);
281 if (self
->client
.iriap
)
282 iriap_close(self
->client
.iriap
);
284 /* Remove frames queued on the control channel */
285 skb_queue_purge(&self
->client
.txq
);
287 /* Unregister and free self via destructor */
288 unregister_netdevice(self
->dev
);
291 /* Find any instance of irlan, used for client discovery wakeup */
292 struct irlan_cb
*irlan_get_any(void)
294 struct irlan_cb
*self
;
296 list_for_each_entry_rcu(self
, &irlans
, dev_list
) {
303 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
305 * Here we receive the connect indication for the data channel
308 static void irlan_connect_indication(void *instance
, void *sap
,
309 struct qos_info
*qos
,
311 __u8 max_header_size
,
314 struct irlan_cb
*self
;
315 struct tsap_cb
*tsap
;
317 IRDA_DEBUG(2, "%s()\n", __func__
);
319 self
= (struct irlan_cb
*) instance
;
320 tsap
= (struct tsap_cb
*) sap
;
322 IRDA_ASSERT(self
!= NULL
, return;);
323 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
324 IRDA_ASSERT(tsap
== self
->tsap_data
,return;);
326 self
->max_sdu_size
= max_sdu_size
;
327 self
->max_header_size
= max_header_size
;
329 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
331 del_timer(&self
->watchdog_timer
);
333 /* If you want to pass the skb to *both* state machines, you will
334 * need to skb_clone() it, so that you don't free it twice.
335 * As the state machines don't need it, git rid of it here...
340 irlan_do_provider_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
341 irlan_do_client_event(self
, IRLAN_DATA_CONNECT_INDICATION
, NULL
);
343 if (self
->provider
.access_type
== ACCESS_PEER
) {
345 * Data channel is open, so we are now allowed to
346 * configure the remote filter
348 irlan_get_unicast_addr(self
);
349 irlan_open_unicast_addr(self
);
351 /* Ready to transfer Ethernet frames (at last) */
352 netif_start_queue(self
->dev
); /* Clear reason */
355 static void irlan_connect_confirm(void *instance
, void *sap
,
356 struct qos_info
*qos
,
358 __u8 max_header_size
,
361 struct irlan_cb
*self
;
363 self
= (struct irlan_cb
*) instance
;
365 IRDA_ASSERT(self
!= NULL
, return;);
366 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
368 self
->max_sdu_size
= max_sdu_size
;
369 self
->max_header_size
= max_header_size
;
371 /* TODO: we could set the MTU depending on the max_sdu_size */
373 IRDA_DEBUG(0, "%s: We are now connected!\n", __func__
);
374 del_timer(&self
->watchdog_timer
);
377 * Data channel is open, so we are now allowed to configure the remote
380 irlan_get_unicast_addr(self
);
381 irlan_open_unicast_addr(self
);
383 /* Open broadcast and multicast filter by default */
384 irlan_set_broadcast_filter(self
, TRUE
);
385 irlan_set_multicast_filter(self
, TRUE
);
387 /* Ready to transfer Ethernet frames */
388 netif_start_queue(self
->dev
);
389 self
->disconnect_reason
= 0; /* Clear reason */
390 wake_up_interruptible(&self
->open_wait
);
394 * Function irlan_client_disconnect_indication (handle)
396 * Callback function for the IrTTP layer. Indicates a disconnection of
397 * the specified connection (handle)
399 static void irlan_disconnect_indication(void *instance
,
400 void *sap
, LM_REASON reason
,
401 struct sk_buff
*userdata
)
403 struct irlan_cb
*self
;
404 struct tsap_cb
*tsap
;
406 IRDA_DEBUG(0, "%s(), reason=%d\n", __func__
, reason
);
408 self
= (struct irlan_cb
*) instance
;
409 tsap
= (struct tsap_cb
*) sap
;
411 IRDA_ASSERT(self
!= NULL
, return;);
412 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
413 IRDA_ASSERT(tsap
!= NULL
, return;);
414 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
416 IRDA_ASSERT(tsap
== self
->tsap_data
, return;);
418 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
420 /* Save reason so we know if we should try to reconnect or not */
421 self
->disconnect_reason
= reason
;
424 case LM_USER_REQUEST
: /* User request */
425 IRDA_DEBUG(2, "%s(), User requested\n", __func__
);
427 case LM_LAP_DISCONNECT
: /* Unexpected IrLAP disconnect */
428 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __func__
);
430 case LM_CONNECT_FAILURE
: /* Failed to establish IrLAP connection */
431 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __func__
);
433 case LM_LAP_RESET
: /* IrLAP reset */
434 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __func__
);
436 case LM_INIT_DISCONNECT
:
437 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __func__
);
440 IRDA_ERROR("%s(), Unknown disconnect reason\n", __func__
);
444 /* If you want to pass the skb to *both* state machines, you will
445 * need to skb_clone() it, so that you don't free it twice.
446 * As the state machines don't need it, git rid of it here...
449 dev_kfree_skb(userdata
);
451 irlan_do_client_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
452 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
454 wake_up_interruptible(&self
->open_wait
);
457 void irlan_open_data_tsap(struct irlan_cb
*self
)
459 struct tsap_cb
*tsap
;
462 IRDA_DEBUG(2, "%s()\n", __func__
);
464 IRDA_ASSERT(self
!= NULL
, return;);
465 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
467 /* Check if already open */
471 irda_notify_init(¬ify
);
473 notify
.data_indication
= irlan_eth_receive
;
474 notify
.udata_indication
= irlan_eth_receive
;
475 notify
.connect_indication
= irlan_connect_indication
;
476 notify
.connect_confirm
= irlan_connect_confirm
;
477 notify
.flow_indication
= irlan_eth_flow_indication
;
478 notify
.disconnect_indication
= irlan_disconnect_indication
;
479 notify
.instance
= self
;
480 strlcpy(notify
.name
, "IrLAN data", sizeof(notify
.name
));
482 tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
, ¬ify
);
484 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__
);
487 self
->tsap_data
= tsap
;
490 * This is the data TSAP selector which we will pass to the client
491 * when the client ask for it.
493 self
->stsap_sel_data
= self
->tsap_data
->stsap_sel
;
496 void irlan_close_tsaps(struct irlan_cb
*self
)
498 IRDA_DEBUG(4, "%s()\n", __func__
);
500 IRDA_ASSERT(self
!= NULL
, return;);
501 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
503 /* Disconnect and close all open TSAP connections */
504 if (self
->tsap_data
) {
505 irttp_disconnect_request(self
->tsap_data
, NULL
, P_NORMAL
);
506 irttp_close_tsap(self
->tsap_data
);
507 self
->tsap_data
= NULL
;
509 if (self
->client
.tsap_ctrl
) {
510 irttp_disconnect_request(self
->client
.tsap_ctrl
, NULL
,
512 irttp_close_tsap(self
->client
.tsap_ctrl
);
513 self
->client
.tsap_ctrl
= NULL
;
515 if (self
->provider
.tsap_ctrl
) {
516 irttp_disconnect_request(self
->provider
.tsap_ctrl
, NULL
,
518 irttp_close_tsap(self
->provider
.tsap_ctrl
);
519 self
->provider
.tsap_ctrl
= NULL
;
521 self
->disconnect_reason
= LM_USER_REQUEST
;
525 * Function irlan_ias_register (self, tsap_sel)
527 * Register with LM-IAS
530 void irlan_ias_register(struct irlan_cb
*self
, __u8 tsap_sel
)
532 struct ias_object
*obj
;
533 struct ias_value
*new_value
;
535 IRDA_ASSERT(self
!= NULL
, return;);
536 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
539 * Check if object has already been registered by a previous provider.
540 * If that is the case, we just change the value of the attribute
542 if (!irias_find_object("IrLAN")) {
543 obj
= irias_new_object("IrLAN", IAS_IRLAN_ID
);
544 irias_add_integer_attrib(obj
, "IrDA:TinyTP:LsapSel", tsap_sel
,
546 irias_insert_object(obj
);
548 new_value
= irias_new_integer_value(tsap_sel
);
549 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
553 /* Register PnP object only if not registered before */
554 if (!irias_find_object("PnP")) {
555 obj
= irias_new_object("PnP", IAS_PNP_ID
);
557 irias_add_string_attrib(obj
, "Name", sysctl_devname
,
560 irias_add_string_attrib(obj
, "Name", "Linux", IAS_KERNEL_ATTR
);
562 irias_add_string_attrib(obj
, "DeviceID", "HWP19F0",
564 irias_add_integer_attrib(obj
, "CompCnt", 1, IAS_KERNEL_ATTR
);
565 if (self
->provider
.access_type
== ACCESS_PEER
)
566 irias_add_string_attrib(obj
, "Comp#01", "PNP8389",
569 irias_add_string_attrib(obj
, "Comp#01", "PNP8294",
572 irias_add_string_attrib(obj
, "Manufacturer",
573 "Linux-IrDA Project", IAS_KERNEL_ATTR
);
574 irias_insert_object(obj
);
579 * Function irlan_run_ctrl_tx_queue (self)
581 * Try to send the next command in the control transmit queue
584 int irlan_run_ctrl_tx_queue(struct irlan_cb
*self
)
588 IRDA_DEBUG(2, "%s()\n", __func__
);
590 if (irda_lock(&self
->client
.tx_busy
) == FALSE
)
593 skb
= skb_dequeue(&self
->client
.txq
);
595 self
->client
.tx_busy
= FALSE
;
599 /* Check that it's really possible to send commands */
600 if ((self
->client
.tsap_ctrl
== NULL
) ||
601 (self
->client
.state
== IRLAN_IDLE
))
603 self
->client
.tx_busy
= FALSE
;
607 IRDA_DEBUG(2, "%s(), sending ...\n", __func__
);
609 return irttp_data_request(self
->client
.tsap_ctrl
, skb
);
613 * Function irlan_ctrl_data_request (self, skb)
615 * This function makes sure that commands on the control channel is being
616 * sent in a command/response fashion
618 static void irlan_ctrl_data_request(struct irlan_cb
*self
, struct sk_buff
*skb
)
620 IRDA_DEBUG(2, "%s()\n", __func__
);
623 skb_queue_tail(&self
->client
.txq
, skb
);
625 /* Try to send command */
626 irlan_run_ctrl_tx_queue(self
);
630 * Function irlan_get_provider_info (self)
632 * Send Get Provider Information command to peer IrLAN layer
635 void irlan_get_provider_info(struct irlan_cb
*self
)
640 IRDA_DEBUG(4, "%s()\n", __func__
);
642 IRDA_ASSERT(self
!= NULL
, return;);
643 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
645 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
,
650 /* Reserve space for TTP, LMP, and LAP header */
651 skb_reserve(skb
, self
->client
.max_header_size
);
656 frame
[0] = CMD_GET_PROVIDER_INFO
;
657 frame
[1] = 0x00; /* Zero parameters */
659 irlan_ctrl_data_request(self
, skb
);
663 * Function irlan_open_data_channel (self)
665 * Send an Open Data Command to provider
668 void irlan_open_data_channel(struct irlan_cb
*self
)
673 IRDA_DEBUG(4, "%s()\n", __func__
);
675 IRDA_ASSERT(self
!= NULL
, return;);
676 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
678 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
679 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
680 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
685 skb_reserve(skb
, self
->client
.max_header_size
);
691 frame
[0] = CMD_OPEN_DATA_CHANNEL
;
692 frame
[1] = 0x02; /* Two parameters */
694 irlan_insert_string_param(skb
, "MEDIA", "802.3");
695 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
696 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
698 /* self->use_udata = TRUE; */
700 irlan_ctrl_data_request(self
, skb
);
703 void irlan_close_data_channel(struct irlan_cb
*self
)
708 IRDA_DEBUG(4, "%s()\n", __func__
);
710 IRDA_ASSERT(self
!= NULL
, return;);
711 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
713 /* Check if the TSAP is still there */
714 if (self
->client
.tsap_ctrl
== NULL
)
717 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
718 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
723 skb_reserve(skb
, self
->client
.max_header_size
);
729 frame
[0] = CMD_CLOSE_DATA_CHAN
;
730 frame
[1] = 0x01; /* One parameter */
732 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
734 irlan_ctrl_data_request(self
, skb
);
738 * Function irlan_open_unicast_addr (self)
740 * Make IrLAN provider accept ethernet frames addressed to the unicast
744 static void irlan_open_unicast_addr(struct irlan_cb
*self
)
749 IRDA_DEBUG(4, "%s()\n", __func__
);
751 IRDA_ASSERT(self
!= NULL
, return;);
752 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
754 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
755 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
756 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
757 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
762 /* Reserve space for TTP, LMP, and LAP header */
763 skb_reserve(skb
, self
->max_header_size
);
768 frame
[0] = CMD_FILTER_OPERATION
;
769 frame
[1] = 0x03; /* Three parameters */
770 irlan_insert_byte_param(skb
, "DATA_CHAN" , self
->dtsap_sel_data
);
771 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
772 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
774 irlan_ctrl_data_request(self
, skb
);
778 * Function irlan_set_broadcast_filter (self, status)
780 * Make IrLAN provider accept ethernet frames addressed to the broadcast
781 * address. Be careful with the use of this one, since there may be a lot
782 * of broadcast traffic out there. We can still function without this
783 * one but then _we_ have to initiate all communication with other
784 * hosts, since ARP request for this host will not be answered.
786 void irlan_set_broadcast_filter(struct irlan_cb
*self
, int status
)
791 IRDA_DEBUG(2, "%s()\n", __func__
);
793 IRDA_ASSERT(self
!= NULL
, return;);
794 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
796 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
797 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
798 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
799 /* We may waste one byte here...*/
800 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
805 /* Reserve space for TTP, LMP, and LAP header */
806 skb_reserve(skb
, self
->client
.max_header_size
);
811 frame
[0] = CMD_FILTER_OPERATION
;
812 frame
[1] = 0x03; /* Three parameters */
813 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
814 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
816 irlan_insert_string_param(skb
, "FILTER_MODE", "FILTER");
818 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
820 irlan_ctrl_data_request(self
, skb
);
824 * Function irlan_set_multicast_filter (self, status)
826 * Make IrLAN provider accept ethernet frames addressed to the multicast
830 void irlan_set_multicast_filter(struct irlan_cb
*self
, int status
)
835 IRDA_DEBUG(2, "%s()\n", __func__
);
837 IRDA_ASSERT(self
!= NULL
, return;);
838 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
840 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
841 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
842 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
843 /* We may waste one byte here...*/
844 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
849 /* Reserve space for TTP, LMP, and LAP header */
850 skb_reserve(skb
, self
->client
.max_header_size
);
855 frame
[0] = CMD_FILTER_OPERATION
;
856 frame
[1] = 0x03; /* Three parameters */
857 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
858 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
860 irlan_insert_string_param(skb
, "FILTER_MODE", "ALL");
862 irlan_insert_string_param(skb
, "FILTER_MODE", "NONE");
864 irlan_ctrl_data_request(self
, skb
);
868 * Function irlan_get_unicast_addr (self)
870 * Retrieves the unicast address from the IrLAN provider. This address
871 * will be inserted into the devices structure, so the ethernet layer
872 * can construct its packets.
875 static void irlan_get_unicast_addr(struct irlan_cb
*self
)
880 IRDA_DEBUG(2, "%s()\n", __func__
);
882 IRDA_ASSERT(self
!= NULL
, return;);
883 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
885 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
886 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
887 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
888 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
894 /* Reserve space for TTP, LMP, and LAP header */
895 skb_reserve(skb
, self
->client
.max_header_size
);
900 frame
[0] = CMD_FILTER_OPERATION
;
901 frame
[1] = 0x03; /* Three parameters */
902 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->dtsap_sel_data
);
903 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
904 irlan_insert_string_param(skb
, "FILTER_OPERATION", "DYNAMIC");
906 irlan_ctrl_data_request(self
, skb
);
910 * Function irlan_get_media_char (self)
915 void irlan_get_media_char(struct irlan_cb
*self
)
920 IRDA_DEBUG(4, "%s()\n", __func__
);
922 IRDA_ASSERT(self
!= NULL
, return;);
923 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
925 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
926 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
932 /* Reserve space for TTP, LMP, and LAP header */
933 skb_reserve(skb
, self
->client
.max_header_size
);
939 frame
[0] = CMD_GET_MEDIA_CHAR
;
940 frame
[1] = 0x01; /* One parameter */
942 irlan_insert_string_param(skb
, "MEDIA", "802.3");
943 irlan_ctrl_data_request(self
, skb
);
947 * Function insert_byte_param (skb, param, value)
949 * Insert byte parameter into frame
952 int irlan_insert_byte_param(struct sk_buff
*skb
, char *param
, __u8 value
)
954 return __irlan_insert_param(skb
, param
, IRLAN_BYTE
, value
, 0, NULL
, 0);
957 int irlan_insert_short_param(struct sk_buff
*skb
, char *param
, __u16 value
)
959 return __irlan_insert_param(skb
, param
, IRLAN_SHORT
, 0, value
, NULL
, 0);
963 * Function insert_string (skb, param, value)
965 * Insert string parameter into frame
968 int irlan_insert_string_param(struct sk_buff
*skb
, char *param
, char *string
)
970 int string_len
= strlen(string
);
972 return __irlan_insert_param(skb
, param
, IRLAN_ARRAY
, 0, 0, string
,
977 * Function insert_array_param(skb, param, value, len_value)
979 * Insert array parameter into frame
982 int irlan_insert_array_param(struct sk_buff
*skb
, char *name
, __u8
*array
,
985 return __irlan_insert_param(skb
, name
, IRLAN_ARRAY
, 0, 0, array
,
990 * Function insert_param (skb, param, value, byte)
992 * Insert parameter at end of buffer, structure of a parameter is:
994 * -----------------------------------------------------------------------
995 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
996 * -----------------------------------------------------------------------
998 static int __irlan_insert_param(struct sk_buff
*skb
, char *param
, int type
,
999 __u8 value_byte
, __u16 value_short
,
1000 __u8
*value_array
, __u16 value_len
)
1004 __le16 tmp_le
; /* Temporary value in little endian format */
1008 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __func__
);
1012 param_len
= strlen(param
);
1021 IRDA_ASSERT(value_array
!= NULL
, return 0;);
1022 IRDA_ASSERT(value_len
> 0, return 0;);
1025 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __func__
);
1030 /* Insert at end of sk-buffer */
1031 frame
= skb_tail_pointer(skb
);
1033 /* Make space for data */
1034 if (skb_tailroom(skb
) < (param_len
+value_len
+3)) {
1035 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __func__
);
1038 skb_put(skb
, param_len
+value_len
+3);
1040 /* Insert parameter length */
1041 frame
[n
++] = param_len
;
1043 /* Insert parameter */
1044 memcpy(frame
+n
, param
, param_len
); n
+= param_len
;
1046 /* Insert value length (2 byte little endian format, LSB first) */
1047 tmp_le
= cpu_to_le16(value_len
);
1048 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2; /* To avoid alignment problems */
1053 frame
[n
++] = value_byte
;
1056 tmp_le
= cpu_to_le16(value_short
);
1057 memcpy(frame
+n
, &tmp_le
, 2); n
+= 2;
1060 memcpy(frame
+n
, value_array
, value_len
); n
+=value_len
;
1065 IRDA_ASSERT(n
== (param_len
+value_len
+3), return 0;);
1067 return param_len
+value_len
+3;
1071 * Function irlan_extract_param (buf, name, value, len)
1073 * Extracts a single parameter name/value pair from buffer and updates
1074 * the buffer pointer to point to the next name/value pair.
1076 int irlan_extract_param(__u8
*buf
, char *name
, char *value
, __u16
*len
)
1082 IRDA_DEBUG(4, "%s()\n", __func__
);
1084 /* get length of parameter name (1 byte) */
1085 name_len
= buf
[n
++];
1087 if (name_len
> 254) {
1088 IRDA_DEBUG(2, "%s(), name_len > 254\n", __func__
);
1089 return -RSP_INVALID_COMMAND_FORMAT
;
1092 /* get parameter name */
1093 memcpy(name
, buf
+n
, name_len
);
1094 name
[name_len
] = '\0';
1098 * Get length of parameter value (2 bytes in little endian
1101 memcpy(&val_len
, buf
+n
, 2); /* To avoid alignment problems */
1102 le16_to_cpus(&val_len
); n
+=2;
1104 if (val_len
> 1016) {
1105 IRDA_DEBUG(2, "%s(), parameter length to long\n", __func__
);
1106 return -RSP_INVALID_COMMAND_FORMAT
;
1110 /* get parameter value */
1111 memcpy(value
, buf
+n
, val_len
);
1112 value
[val_len
] = '\0';
1115 IRDA_DEBUG(4, "Parameter: %s ", name
);
1116 IRDA_DEBUG(4, "Value: %s\n", value
);
1121 #ifdef CONFIG_PROC_FS
1124 * Start of reading /proc entries.
1125 * Return entry at pos,
1126 * or start_token to indicate print header line
1127 * or NULL if end of file
1129 static void *irlan_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1132 struct irlan_cb
*self
;
1136 return SEQ_START_TOKEN
;
1138 list_for_each_entry(self
, &irlans
, dev_list
) {
1146 /* Return entry after v, and increment pos */
1147 static void *irlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1149 struct list_head
*nxt
;
1152 if (v
== SEQ_START_TOKEN
)
1155 nxt
= ((struct irlan_cb
*)v
)->dev_list
.next
;
1157 return (nxt
== &irlans
) ? NULL
1158 : list_entry(nxt
, struct irlan_cb
, dev_list
);
1161 /* End of reading /proc file */
1162 static void irlan_seq_stop(struct seq_file
*seq
, void *v
)
1169 * Show one entry in /proc file.
1171 static int irlan_seq_show(struct seq_file
*seq
, void *v
)
1173 if (v
== SEQ_START_TOKEN
)
1174 seq_puts(seq
, "IrLAN instances:\n");
1176 struct irlan_cb
*self
= v
;
1178 IRDA_ASSERT(self
!= NULL
, return -1;);
1179 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
1181 seq_printf(seq
,"ifname: %s,\n",
1183 seq_printf(seq
,"client state: %s, ",
1184 irlan_state
[ self
->client
.state
]);
1185 seq_printf(seq
,"provider state: %s,\n",
1186 irlan_state
[ self
->provider
.state
]);
1187 seq_printf(seq
,"saddr: %#08x, ",
1189 seq_printf(seq
,"daddr: %#08x\n",
1191 seq_printf(seq
,"version: %d.%d,\n",
1192 self
->version
[1], self
->version
[0]);
1193 seq_printf(seq
,"access type: %s\n",
1194 irlan_access
[self
->client
.access_type
]);
1195 seq_printf(seq
,"media: %s\n",
1196 irlan_media
[self
->media
]);
1198 seq_printf(seq
,"local filter:\n");
1199 seq_printf(seq
,"remote filter: ");
1200 irlan_print_filter(seq
, self
->client
.filter_type
);
1201 seq_printf(seq
,"tx busy: %s\n",
1202 netif_queue_stopped(self
->dev
) ? "TRUE" : "FALSE");
1209 static const struct seq_operations irlan_seq_ops
= {
1210 .start
= irlan_seq_start
,
1211 .next
= irlan_seq_next
,
1212 .stop
= irlan_seq_stop
,
1213 .show
= irlan_seq_show
,
1216 static int irlan_seq_open(struct inode
*inode
, struct file
*file
)
1218 return seq_open(file
, &irlan_seq_ops
);
1222 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1223 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1224 MODULE_LICENSE("GPL");
1226 module_param(eth
, bool, 0);
1227 MODULE_PARM_DESC(eth
, "Name devices ethX (0) or irlanX (1)");
1228 module_param(access
, int, 0);
1229 MODULE_PARM_DESC(access
, "Access type DIRECT=1, PEER=2, HOSTED=3");
1231 module_init(irlan_init
);
1232 module_exit(irlan_cleanup
);