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 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 proc = create_proc_entry("irlan", 0, proc_irda);
133 printk(KERN_ERR "irlan_init: can't create /proc entry!\n");
137 proc->proc_fops = &irlan_fops;
139 #endif /* CONFIG_PROC_FS */
141 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
142 hints = irlmp_service_to_hint(S_LAN);
144 /* Register with IrLMP as a client */
145 ckey = irlmp_register_client(hints, &irlan_client_discovery_indication,
148 /* Register with IrLMP as a service */
149 skey = irlmp_register_service(hints);
151 /* Start the master IrLAN instance (the only one for now) */
152 new = irlan_open(DEV_ADDR_ANY, DEV_ADDR_ANY);
154 /* The master will only open its (listen) control TSAP */
155 irlan_provider_open_ctrl_tsap(new);
157 /* Do some fast discovery! */
158 irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS);
163 static void __exit irlan_cleanup(void)
165 struct irlan_cb *self, *next;
167 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
169 irlmp_unregister_client(ckey);
170 irlmp_unregister_service(skey);
172 #ifdef CONFIG_PROC_FS
173 remove_proc_entry("irlan", proc_irda);
174 #endif /* CONFIG_PROC_FS */
176 /* Cleanup any leftover network devices */
178 list_for_each_entry_safe(self, next, &irlans, dev_list) {
185 * Function irlan_open (void)
187 * Open new instance of a client/provider, we should only register the
188 * network device if this instance is ment for a particular client/provider
190 static struct irlan_cb *irlan_open(__u32 saddr, __u32 daddr)
192 struct net_device *dev;
193 struct irlan_cb *self;
195 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
197 /* Create network device with irlan */
198 dev = alloc_irlandev(eth ? "eth%d" : "irlan%d");
206 * Initialize local device structure
208 self->magic = IRLAN_MAGIC;
212 /* Provider access can only be PEER, DIRECT, or HOSTED */
213 self->provider.access_type = access;
214 if (access == ACCESS_DIRECT) {
216 * Since we are emulating an IrLAN sever we will have to
217 * give ourself an ethernet address!
219 dev->dev_addr[0] = 0x40;
220 dev->dev_addr[1] = 0x00;
221 dev->dev_addr[2] = 0x00;
222 dev->dev_addr[3] = 0x00;
223 get_random_bytes(dev->dev_addr+4, 1);
224 get_random_bytes(dev->dev_addr+5, 1);
227 self->media = MEDIA_802_3;
228 self->disconnect_reason = LM_USER_REQUEST;
229 init_timer(&self->watchdog_timer);
230 init_timer(&self->client.kick_timer);
231 init_waitqueue_head(&self->open_wait);
233 skb_queue_head_init(&self->client.txq);
235 irlan_next_client_state(self, IRLAN_IDLE);
236 irlan_next_provider_state(self, IRLAN_IDLE);
238 if (register_netdev(dev)) {
239 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
245 list_add_rcu(&self->dev_list, &irlans);
252 * Function __irlan_close (self)
254 * This function closes and deallocates the IrLAN client instances. Be
255 * aware that other functions which calls client_close() must
256 * remove self from irlans list first.
258 static void __irlan_close(struct irlan_cb *self)
260 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
263 IRDA_ASSERT(self != NULL, return;);
264 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
266 del_timer_sync(&self->watchdog_timer);
267 del_timer_sync(&self->client.kick_timer);
269 /* Close all open connections and remove TSAPs */
270 irlan_close_tsaps(self);
272 if (self->client.iriap)
273 iriap_close(self->client.iriap);
275 /* Remove frames queued on the control channel */
276 skb_queue_purge(&self->client.txq);
278 /* Unregister and free self via destructor */
279 unregister_netdevice(self->dev);
282 /* Find any instance of irlan, used for client discovery wakeup */
283 struct irlan_cb *irlan_get_any(void)
285 struct irlan_cb *self;
287 list_for_each_entry_rcu(self, &irlans, dev_list) {
294 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
296 * Here we receive the connect indication for the data channel
299 static void irlan_connect_indication(void *instance, void *sap,
300 struct qos_info *qos,
302 __u8 max_header_size,
305 struct irlan_cb *self;
306 struct tsap_cb *tsap;
308 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
310 self = (struct irlan_cb *) instance;
311 tsap = (struct tsap_cb *) sap;
313 IRDA_ASSERT(self != NULL, return;);
314 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
315 IRDA_ASSERT(tsap == self->tsap_data,return;);
317 self->max_sdu_size = max_sdu_size;
318 self->max_header_size = max_header_size;
320 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__);
322 del_timer(&self->watchdog_timer);
324 /* If you want to pass the skb to *both* state machines, you will
325 * need to skb_clone() it, so that you don't free it twice.
326 * As the state machines don't need it, git rid of it here...
331 irlan_do_provider_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
332 irlan_do_client_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
334 if (self->provider.access_type == ACCESS_PEER) {
336 * Data channel is open, so we are now allowed to
337 * configure the remote filter
339 irlan_get_unicast_addr(self);
340 irlan_open_unicast_addr(self);
342 /* Ready to transfer Ethernet frames (at last) */
343 netif_start_queue(self->dev); /* Clear reason */
346 static void irlan_connect_confirm(void *instance, void *sap,
347 struct qos_info *qos,
349 __u8 max_header_size,
352 struct irlan_cb *self;
354 self = (struct irlan_cb *) instance;
356 IRDA_ASSERT(self != NULL, return;);
357 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
359 self->max_sdu_size = max_sdu_size;
360 self->max_header_size = max_header_size;
362 /* TODO: we could set the MTU depending on the max_sdu_size */
364 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__);
365 del_timer(&self->watchdog_timer);
368 * Data channel is open, so we are now allowed to configure the remote
371 irlan_get_unicast_addr(self);
372 irlan_open_unicast_addr(self);
374 /* Open broadcast and multicast filter by default */
375 irlan_set_broadcast_filter(self, TRUE);
376 irlan_set_multicast_filter(self, TRUE);
378 /* Ready to transfer Ethernet frames */
379 netif_start_queue(self->dev);
380 self->disconnect_reason = 0; /* Clear reason */
381 #ifdef CONFIG_IRLAN_SEND_GRATUITOUS_ARP
382 irlan_eth_send_gratuitous_arp(&self->dev);
384 wake_up_interruptible(&self->open_wait);
388 * Function irlan_client_disconnect_indication (handle)
390 * Callback function for the IrTTP layer. Indicates a disconnection of
391 * the specified connection (handle)
393 static void irlan_disconnect_indication(void *instance,
394 void *sap, LM_REASON reason,
395 struct sk_buff *userdata)
397 struct irlan_cb *self;
398 struct tsap_cb *tsap;
400 IRDA_DEBUG(0, "%s(), reason=%d\n", __FUNCTION__ , reason);
402 self = (struct irlan_cb *) instance;
403 tsap = (struct tsap_cb *) sap;
405 IRDA_ASSERT(self != NULL, return;);
406 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
407 IRDA_ASSERT(tsap != NULL, return;);
408 IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;);
410 IRDA_ASSERT(tsap == self->tsap_data, return;);
412 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
414 /* Save reason so we know if we should try to reconnect or not */
415 self->disconnect_reason = reason;
418 case LM_USER_REQUEST: /* User request */
419 IRDA_DEBUG(2, "%s(), User requested\n", __FUNCTION__ );
421 case LM_LAP_DISCONNECT: /* Unexpected IrLAP disconnect */
422 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __FUNCTION__ );
424 case LM_CONNECT_FAILURE: /* Failed to establish IrLAP connection */
425 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __FUNCTION__ );
427 case LM_LAP_RESET: /* IrLAP reset */
428 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __FUNCTION__ );
430 case LM_INIT_DISCONNECT:
431 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __FUNCTION__ );
434 IRDA_ERROR("%s(), Unknown disconnect reason\n", __FUNCTION__);
438 /* If you want to pass the skb to *both* state machines, you will
439 * need to skb_clone() it, so that you don't free it twice.
440 * As the state machines don't need it, git rid of it here...
443 dev_kfree_skb(userdata);
445 irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
446 irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
448 wake_up_interruptible(&self->open_wait);
451 void irlan_open_data_tsap(struct irlan_cb *self)
453 struct tsap_cb *tsap;
456 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
458 IRDA_ASSERT(self != NULL, return;);
459 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
461 /* Check if already open */
465 irda_notify_init(¬ify);
467 notify.data_indication = irlan_eth_receive;
468 notify.udata_indication = irlan_eth_receive;
469 notify.connect_indication = irlan_connect_indication;
470 notify.connect_confirm = irlan_connect_confirm;
471 notify.flow_indication = irlan_eth_flow_indication;
472 notify.disconnect_indication = irlan_disconnect_indication;
473 notify.instance = self;
474 strlcpy(notify.name, "IrLAN data", sizeof(notify.name));
476 tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify);
478 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __FUNCTION__ );
481 self->tsap_data = tsap;
484 * This is the data TSAP selector which we will pass to the client
485 * when the client ask for it.
487 self->stsap_sel_data = self->tsap_data->stsap_sel;
490 void irlan_close_tsaps(struct irlan_cb *self)
492 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
494 IRDA_ASSERT(self != NULL, return;);
495 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
497 /* Disconnect and close all open TSAP connections */
498 if (self->tsap_data) {
499 irttp_disconnect_request(self->tsap_data, NULL, P_NORMAL);
500 irttp_close_tsap(self->tsap_data);
501 self->tsap_data = NULL;
503 if (self->client.tsap_ctrl) {
504 irttp_disconnect_request(self->client.tsap_ctrl, NULL,
506 irttp_close_tsap(self->client.tsap_ctrl);
507 self->client.tsap_ctrl = NULL;
509 if (self->provider.tsap_ctrl) {
510 irttp_disconnect_request(self->provider.tsap_ctrl, NULL,
512 irttp_close_tsap(self->provider.tsap_ctrl);
513 self->provider.tsap_ctrl = NULL;
515 self->disconnect_reason = LM_USER_REQUEST;
519 * Function irlan_ias_register (self, tsap_sel)
521 * Register with LM-IAS
524 void irlan_ias_register(struct irlan_cb *self, __u8 tsap_sel)
526 struct ias_object *obj;
527 struct ias_value *new_value;
529 IRDA_ASSERT(self != NULL, return;);
530 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
533 * Check if object has already been registered by a previous provider.
534 * If that is the case, we just change the value of the attribute
536 if (!irias_find_object("IrLAN")) {
537 obj = irias_new_object("IrLAN", IAS_IRLAN_ID);
538 irias_add_integer_attrib(obj, "IrDA:TinyTP:LsapSel", tsap_sel,
540 irias_insert_object(obj);
542 new_value = irias_new_integer_value(tsap_sel);
543 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
547 /* Register PnP object only if not registered before */
548 if (!irias_find_object("PnP")) {
549 obj = irias_new_object("PnP", IAS_PNP_ID);
551 irias_add_string_attrib(obj, "Name", sysctl_devname,
554 irias_add_string_attrib(obj, "Name", "Linux", IAS_KERNEL_ATTR);
556 irias_add_string_attrib(obj, "DeviceID", "HWP19F0",
558 irias_add_integer_attrib(obj, "CompCnt", 1, IAS_KERNEL_ATTR);
559 if (self->provider.access_type == ACCESS_PEER)
560 irias_add_string_attrib(obj, "Comp#01", "PNP8389",
563 irias_add_string_attrib(obj, "Comp#01", "PNP8294",
566 irias_add_string_attrib(obj, "Manufacturer",
567 "Linux-IrDA Project", IAS_KERNEL_ATTR);
568 irias_insert_object(obj);
573 * Function irlan_run_ctrl_tx_queue (self)
575 * Try to send the next command in the control transmit queue
578 int irlan_run_ctrl_tx_queue(struct irlan_cb *self)
582 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
584 if (irda_lock(&self->client.tx_busy) == FALSE)
587 skb = skb_dequeue(&self->client.txq);
589 self->client.tx_busy = FALSE;
593 /* Check that it's really possible to send commands */
594 if ((self->client.tsap_ctrl == NULL) ||
595 (self->client.state == IRLAN_IDLE))
597 self->client.tx_busy = FALSE;
601 IRDA_DEBUG(2, "%s(), sending ...\n", __FUNCTION__ );
603 return irttp_data_request(self->client.tsap_ctrl, skb);
607 * Function irlan_ctrl_data_request (self, skb)
609 * This function makes sure that commands on the control channel is being
610 * sent in a command/response fashion
612 static void irlan_ctrl_data_request(struct irlan_cb *self, struct sk_buff *skb)
614 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
617 skb_queue_tail(&self->client.txq, skb);
619 /* Try to send command */
620 irlan_run_ctrl_tx_queue(self);
624 * Function irlan_get_provider_info (self)
626 * Send Get Provider Information command to peer IrLAN layer
629 void irlan_get_provider_info(struct irlan_cb *self)
634 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
636 IRDA_ASSERT(self != NULL, return;);
637 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
639 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER,
644 /* Reserve space for TTP, LMP, and LAP header */
645 skb_reserve(skb, self->client.max_header_size);
650 frame[0] = CMD_GET_PROVIDER_INFO;
651 frame[1] = 0x00; /* Zero parameters */
653 irlan_ctrl_data_request(self, skb);
657 * Function irlan_open_data_channel (self)
659 * Send an Open Data Command to provider
662 void irlan_open_data_channel(struct irlan_cb *self)
667 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
669 IRDA_ASSERT(self != NULL, return;);
670 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
672 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
673 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") +
674 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"),
679 skb_reserve(skb, self->client.max_header_size);
685 frame[0] = CMD_OPEN_DATA_CHANNEL;
686 frame[1] = 0x02; /* Two parameters */
688 irlan_insert_string_param(skb, "MEDIA", "802.3");
689 irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT");
690 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
692 /* self->use_udata = TRUE; */
694 irlan_ctrl_data_request(self, skb);
697 void irlan_close_data_channel(struct irlan_cb *self)
702 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
704 IRDA_ASSERT(self != NULL, return;);
705 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
707 /* Check if the TSAP is still there */
708 if (self->client.tsap_ctrl == NULL)
711 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
712 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"),
717 skb_reserve(skb, self->client.max_header_size);
723 frame[0] = CMD_CLOSE_DATA_CHAN;
724 frame[1] = 0x01; /* One parameter */
726 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
728 irlan_ctrl_data_request(self, skb);
732 * Function irlan_open_unicast_addr (self)
734 * Make IrLAN provider accept ethernet frames addressed to the unicast
738 static void irlan_open_unicast_addr(struct irlan_cb *self)
743 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
745 IRDA_ASSERT(self != NULL, return;);
746 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
748 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
749 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
750 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
751 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
756 /* Reserve space for TTP, LMP, and LAP header */
757 skb_reserve(skb, self->max_header_size);
762 frame[0] = CMD_FILTER_OPERATION;
763 frame[1] = 0x03; /* Three parameters */
764 irlan_insert_byte_param(skb, "DATA_CHAN" , self->dtsap_sel_data);
765 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
766 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
768 irlan_ctrl_data_request(self, skb);
772 * Function irlan_set_broadcast_filter (self, status)
774 * Make IrLAN provider accept ethernet frames addressed to the broadcast
775 * address. Be careful with the use of this one, since there may be a lot
776 * of broadcast traffic out there. We can still function without this
777 * one but then _we_ have to initiate all communication with other
778 * hosts, since ARP request for this host will not be answered.
780 void irlan_set_broadcast_filter(struct irlan_cb *self, int status)
785 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
787 IRDA_ASSERT(self != NULL, return;);
788 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
790 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
791 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
792 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
793 /* We may waste one byte here...*/
794 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"),
799 /* Reserve space for TTP, LMP, and LAP header */
800 skb_reserve(skb, self->client.max_header_size);
805 frame[0] = CMD_FILTER_OPERATION;
806 frame[1] = 0x03; /* Three parameters */
807 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
808 irlan_insert_string_param(skb, "FILTER_TYPE", "BROADCAST");
810 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
812 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
814 irlan_ctrl_data_request(self, skb);
818 * Function irlan_set_multicast_filter (self, status)
820 * Make IrLAN provider accept ethernet frames addressed to the multicast
824 void irlan_set_multicast_filter(struct irlan_cb *self, int status)
829 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
831 IRDA_ASSERT(self != NULL, return;);
832 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
834 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
835 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
836 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
837 /* We may waste one byte here...*/
838 IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"),
843 /* Reserve space for TTP, LMP, and LAP header */
844 skb_reserve(skb, self->client.max_header_size);
849 frame[0] = CMD_FILTER_OPERATION;
850 frame[1] = 0x03; /* Three parameters */
851 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
852 irlan_insert_string_param(skb, "FILTER_TYPE", "MULTICAST");
854 irlan_insert_string_param(skb, "FILTER_MODE", "ALL");
856 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
858 irlan_ctrl_data_request(self, skb);
862 * Function irlan_get_unicast_addr (self)
864 * Retrieves the unicast address from the IrLAN provider. This address
865 * will be inserted into the devices structure, so the ethernet layer
866 * can construct its packets.
869 static void irlan_get_unicast_addr(struct irlan_cb *self)
874 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
876 IRDA_ASSERT(self != NULL, return;);
877 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
879 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
880 IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") +
881 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
882 IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION",
888 /* Reserve space for TTP, LMP, and LAP header */
889 skb_reserve(skb, self->client.max_header_size);
894 frame[0] = CMD_FILTER_OPERATION;
895 frame[1] = 0x03; /* Three parameters */
896 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
897 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
898 irlan_insert_string_param(skb, "FILTER_OPERATION", "DYNAMIC");
900 irlan_ctrl_data_request(self, skb);
904 * Function irlan_get_media_char (self)
909 void irlan_get_media_char(struct irlan_cb *self)
914 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
916 IRDA_ASSERT(self != NULL, return;);
917 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
919 skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
920 IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"),
926 /* Reserve space for TTP, LMP, and LAP header */
927 skb_reserve(skb, self->client.max_header_size);
933 frame[0] = CMD_GET_MEDIA_CHAR;
934 frame[1] = 0x01; /* One parameter */
936 irlan_insert_string_param(skb, "MEDIA", "802.3");
937 irlan_ctrl_data_request(self, skb);
941 * Function insert_byte_param (skb, param, value)
943 * Insert byte parameter into frame
946 int irlan_insert_byte_param(struct sk_buff *skb, char *param, __u8 value)
948 return __irlan_insert_param(skb, param, IRLAN_BYTE, value, 0, NULL, 0);
951 int irlan_insert_short_param(struct sk_buff *skb, char *param, __u16 value)
953 return __irlan_insert_param(skb, param, IRLAN_SHORT, 0, value, NULL, 0);
957 * Function insert_string (skb, param, value)
959 * Insert string parameter into frame
962 int irlan_insert_string_param(struct sk_buff *skb, char *param, char *string)
964 int string_len = strlen(string);
966 return __irlan_insert_param(skb, param, IRLAN_ARRAY, 0, 0, string,
971 * Function insert_array_param(skb, param, value, len_value)
973 * Insert array parameter into frame
976 int irlan_insert_array_param(struct sk_buff *skb, char *name, __u8 *array,
979 return __irlan_insert_param(skb, name, IRLAN_ARRAY, 0, 0, array,
984 * Function insert_param (skb, param, value, byte)
986 * Insert parameter at end of buffer, structure of a parameter is:
988 * -----------------------------------------------------------------------
989 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
990 * -----------------------------------------------------------------------
992 static int __irlan_insert_param(struct sk_buff *skb, char *param, int type,
993 __u8 value_byte, __u16 value_short,
994 __u8 *value_array, __u16 value_len)
998 __le16 tmp_le; /* Temporary value in little endian format */
1002 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __FUNCTION__ );
1006 param_len = strlen(param);
1015 IRDA_ASSERT(value_array != NULL, return 0;);
1016 IRDA_ASSERT(value_len > 0, return 0;);
1019 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __FUNCTION__ );
1024 /* Insert at end of sk-buffer */
1027 /* Make space for data */
1028 if (skb_tailroom(skb) < (param_len+value_len+3)) {
1029 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __FUNCTION__ );
1032 skb_put(skb, param_len+value_len+3);
1034 /* Insert parameter length */
1035 frame[n++] = param_len;
1037 /* Insert parameter */
1038 memcpy(frame+n, param, param_len); n += param_len;
1040 /* Insert value length (2 byte little endian format, LSB first) */
1041 tmp_le = cpu_to_le16(value_len);
1042 memcpy(frame+n, &tmp_le, 2); n += 2; /* To avoid alignment problems */
1047 frame[n++] = value_byte;
1050 tmp_le = cpu_to_le16(value_short);
1051 memcpy(frame+n, &tmp_le, 2); n += 2;
1054 memcpy(frame+n, value_array, value_len); n+=value_len;
1059 IRDA_ASSERT(n == (param_len+value_len+3), return 0;);
1061 return param_len+value_len+3;
1065 * Function irlan_extract_param (buf, name, value, len)
1067 * Extracts a single parameter name/value pair from buffer and updates
1068 * the buffer pointer to point to the next name/value pair.
1070 int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len)
1076 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
1078 /* get length of parameter name (1 byte) */
1079 name_len = buf[n++];
1081 if (name_len > 254) {
1082 IRDA_DEBUG(2, "%s(), name_len > 254\n", __FUNCTION__ );
1083 return -RSP_INVALID_COMMAND_FORMAT;
1086 /* get parameter name */
1087 memcpy(name, buf+n, name_len);
1088 name[name_len] = '\0';
1092 * Get length of parameter value (2 bytes in little endian
1095 memcpy(&val_len, buf+n, 2); /* To avoid alignment problems */
1096 le16_to_cpus(&val_len); n+=2;
1098 if (val_len > 1016) {
1099 IRDA_DEBUG(2, "%s(), parameter length to long\n", __FUNCTION__ );
1100 return -RSP_INVALID_COMMAND_FORMAT;
1104 /* get parameter value */
1105 memcpy(value, buf+n, val_len);
1106 value[val_len] = '\0';
1109 IRDA_DEBUG(4, "Parameter: %s ", name);
1110 IRDA_DEBUG(4, "Value: %s\n", value);
1115 #ifdef CONFIG_PROC_FS
1118 * Start of reading /proc entries.
1119 * Return entry at pos,
1120 * or start_token to indicate print header line
1121 * or NULL if end of file
1123 static void *irlan_seq_start(struct seq_file *seq, loff_t *pos)
1126 struct irlan_cb *self;
1130 return SEQ_START_TOKEN;
1132 list_for_each_entry(self, &irlans, dev_list) {
1140 /* Return entry after v, and increment pos */
1141 static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1143 struct list_head *nxt;
1146 if (v == SEQ_START_TOKEN)
1149 nxt = ((struct irlan_cb *)v)->dev_list.next;
1151 return (nxt == &irlans) ? NULL
1152 : list_entry(nxt, struct irlan_cb, dev_list);
1155 /* End of reading /proc file */
1156 static void irlan_seq_stop(struct seq_file *seq, void *v)
1163 * Show one entry in /proc file.
1165 static int irlan_seq_show(struct seq_file *seq, void *v)
1167 if (v == SEQ_START_TOKEN)
1168 seq_puts(seq, "IrLAN instances:\n");
1170 struct irlan_cb *self = v;
1172 IRDA_ASSERT(self != NULL, return -1;);
1173 IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
1175 seq_printf(seq,"ifname: %s,\n",
1177 seq_printf(seq,"client state: %s, ",
1178 irlan_state[ self->client.state]);
1179 seq_printf(seq,"provider state: %s,\n",
1180 irlan_state[ self->provider.state]);
1181 seq_printf(seq,"saddr: %#08x, ",
1183 seq_printf(seq,"daddr: %#08x\n",
1185 seq_printf(seq,"version: %d.%d,\n",
1186 self->version[1], self->version[0]);
1187 seq_printf(seq,"access type: %s\n",
1188 irlan_access[self->client.access_type]);
1189 seq_printf(seq,"media: %s\n",
1190 irlan_media[self->media]);
1192 seq_printf(seq,"local filter:\n");
1193 seq_printf(seq,"remote filter: ");
1194 irlan_print_filter(seq, self->client.filter_type);
1195 seq_printf(seq,"tx busy: %s\n",
1196 netif_queue_stopped(self->dev) ? "TRUE" : "FALSE");
1203 static struct seq_operations irlan_seq_ops = {
1204 .start = irlan_seq_start,
1205 .next = irlan_seq_next,
1206 .stop = irlan_seq_stop,
1207 .show = irlan_seq_show,
1210 static int irlan_seq_open(struct inode *inode, struct file *file)
1212 return seq_open(file, &irlan_seq_ops);
1216 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1217 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1218 MODULE_LICENSE("GPL");
1220 module_param(eth, bool, 0);
1221 MODULE_PARM_DESC(eth, "Name devices ethX (0) or irlanX (1)");
1222 module_param(access, int, 0);
1223 MODULE_PARM_DESC(access, "Access type DIRECT=1, PEER=2, HOSTED=3");
1225 module_init(irlan_init);
1226 module_exit(irlan_cleanup);