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/config.h>
27 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/string.h>
31 #include <linux/init.h>
32 #include <linux/errno.h>
33 #include <linux/proc_fs.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>
40 #include <asm/system.h>
41 #include <asm/bitops.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 void __irlan_close(struct irlan_cb *self);
108 static int __irlan_insert_param(struct sk_buff *skb, char *param, int type,
109 __u8 value_byte, __u16 value_short,
110 __u8 *value_array, __u16 value_len);
111 void irlan_close_tsaps(struct irlan_cb *self);
114 * Function irlan_init (void)
116 * Initialize IrLAN layer
119 static int __init irlan_init(void)
121 struct irlan_cb *new;
124 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
126 #ifdef CONFIG_PROC_FS
127 { struct proc_dir_entry *proc;
128 proc = create_proc_entry("irlan", 0, proc_irda);
130 printk(KERN_ERR "irlan_init: can't create /proc entry!\n");
134 proc->proc_fops = &irlan_fops;
136 #endif /* CONFIG_PROC_FS */
138 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
139 hints = irlmp_service_to_hint(S_LAN);
141 /* Register with IrLMP as a client */
142 ckey = irlmp_register_client(hints, &irlan_client_discovery_indication,
145 /* Register with IrLMP as a service */
146 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);
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 static void __exit irlan_cleanup(void)
162 struct irlan_cb *self, *next;
164 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
166 irlmp_unregister_client(ckey);
167 irlmp_unregister_service(skey);
169 #ifdef CONFIG_PROC_FS
170 remove_proc_entry("irlan", proc_irda);
171 #endif /* CONFIG_PROC_FS */
173 /* Cleanup any leftover network devices */
175 list_for_each_entry_safe(self, next, &irlans, dev_list) {
182 * Function irlan_open (void)
184 * Open new instance of a client/provider, we should only register the
185 * network device if this instance is ment for a particular client/provider
187 struct irlan_cb *irlan_open(__u32 saddr, __u32 daddr)
189 struct net_device *dev;
190 struct irlan_cb *self;
192 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
194 /* Create network device with irlan */
195 dev = alloc_irlandev(eth ? "eth%d" : "irlan%d");
203 * Initialize local device structure
205 self->magic = IRLAN_MAGIC;
209 /* Provider access can only be PEER, DIRECT, or HOSTED */
210 self->provider.access_type = access;
211 if (access == ACCESS_DIRECT) {
213 * Since we are emulating an IrLAN sever we will have to
214 * give ourself an ethernet address!
216 dev->dev_addr[0] = 0x40;
217 dev->dev_addr[1] = 0x00;
218 dev->dev_addr[2] = 0x00;
219 dev->dev_addr[3] = 0x00;
220 get_random_bytes(dev->dev_addr+4, 1);
221 get_random_bytes(dev->dev_addr+5, 1);
224 self->media = MEDIA_802_3;
225 self->disconnect_reason = LM_USER_REQUEST;
226 init_timer(&self->watchdog_timer);
227 init_timer(&self->client.kick_timer);
228 init_waitqueue_head(&self->open_wait);
230 skb_queue_head_init(&self->client.txq);
232 irlan_next_client_state(self, IRLAN_IDLE);
233 irlan_next_provider_state(self, IRLAN_IDLE);
235 if (register_netdev(dev)) {
236 IRDA_DEBUG(2, "%s(), register_netdev() failed!\n",
242 list_add_rcu(&self->dev_list, &irlans);
249 * Function __irlan_close (self)
251 * This function closes and deallocates the IrLAN client instances. Be
252 * aware that other functions which calls client_close() must
253 * remove self from irlans list first.
255 static void __irlan_close(struct irlan_cb *self)
257 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
260 ASSERT(self != NULL, return;);
261 ASSERT(self->magic == IRLAN_MAGIC, return;);
263 del_timer_sync(&self->watchdog_timer);
264 del_timer_sync(&self->client.kick_timer);
266 /* Close all open connections and remove TSAPs */
267 irlan_close_tsaps(self);
269 if (self->client.iriap)
270 iriap_close(self->client.iriap);
272 /* Remove frames queued on the control channel */
273 skb_queue_purge(&self->client.txq);
275 /* Unregister and free self via destructor */
276 unregister_netdevice(self->dev);
279 /* Find any instance of irlan, used for client discovery wakeup */
280 struct irlan_cb *irlan_get_any(void)
282 struct irlan_cb *self;
284 list_for_each_entry_rcu(self, &irlans, dev_list) {
291 * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb)
293 * Here we receive the connect indication for the data channel
296 void irlan_connect_indication(void *instance, void *sap, struct qos_info *qos,
297 __u32 max_sdu_size, __u8 max_header_size,
300 struct irlan_cb *self;
301 struct tsap_cb *tsap;
303 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
305 self = (struct irlan_cb *) instance;
306 tsap = (struct tsap_cb *) sap;
308 ASSERT(self != NULL, return;);
309 ASSERT(self->magic == IRLAN_MAGIC, return;);
310 ASSERT(tsap == self->tsap_data,return;);
312 self->max_sdu_size = max_sdu_size;
313 self->max_header_size = max_header_size;
315 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__);
317 del_timer(&self->watchdog_timer);
319 /* If you want to pass the skb to *both* state machines, you will
320 * need to skb_clone() it, so that you don't free it twice.
321 * As the state machines don't need it, git rid of it here...
326 irlan_do_provider_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
327 irlan_do_client_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL);
329 if (self->provider.access_type == ACCESS_PEER) {
331 * Data channel is open, so we are now allowed to
332 * configure the remote filter
334 irlan_get_unicast_addr(self);
335 irlan_open_unicast_addr(self);
337 /* Ready to transfer Ethernet frames (at last) */
338 netif_start_queue(self->dev); /* Clear reason */
341 void irlan_connect_confirm(void *instance, void *sap, struct qos_info *qos,
342 __u32 max_sdu_size, __u8 max_header_size,
345 struct irlan_cb *self;
347 self = (struct irlan_cb *) instance;
349 ASSERT(self != NULL, return;);
350 ASSERT(self->magic == IRLAN_MAGIC, return;);
352 self->max_sdu_size = max_sdu_size;
353 self->max_header_size = max_header_size;
355 /* TODO: we could set the MTU depending on the max_sdu_size */
357 IRDA_DEBUG(0, "%s: We are now connected!\n", __FUNCTION__);
358 del_timer(&self->watchdog_timer);
361 * Data channel is open, so we are now allowed to configure the remote
364 irlan_get_unicast_addr(self);
365 irlan_open_unicast_addr(self);
367 /* Open broadcast and multicast filter by default */
368 irlan_set_broadcast_filter(self, TRUE);
369 irlan_set_multicast_filter(self, TRUE);
371 /* Ready to transfer Ethernet frames */
372 netif_start_queue(self->dev);
373 self->disconnect_reason = 0; /* Clear reason */
374 #ifdef CONFIG_IRLAN_SEND_GRATUITOUS_ARP
375 irlan_eth_send_gratuitous_arp(&self->dev);
377 wake_up_interruptible(&self->open_wait);
381 * Function irlan_client_disconnect_indication (handle)
383 * Callback function for the IrTTP layer. Indicates a disconnection of
384 * the specified connection (handle)
386 void irlan_disconnect_indication(void *instance, void *sap, LM_REASON reason,
387 struct sk_buff *userdata)
389 struct irlan_cb *self;
390 struct tsap_cb *tsap;
392 IRDA_DEBUG(0, "%s(), reason=%d\n", __FUNCTION__ , reason);
394 self = (struct irlan_cb *) instance;
395 tsap = (struct tsap_cb *) sap;
397 ASSERT(self != NULL, return;);
398 ASSERT(self->magic == IRLAN_MAGIC, return;);
399 ASSERT(tsap != NULL, return;);
400 ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;);
402 ASSERT(tsap == self->tsap_data, return;);
404 IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n");
406 /* Save reason so we know if we should try to reconnect or not */
407 self->disconnect_reason = reason;
410 case LM_USER_REQUEST: /* User request */
411 IRDA_DEBUG(2, "%s(), User requested\n", __FUNCTION__ );
413 case LM_LAP_DISCONNECT: /* Unexpected IrLAP disconnect */
414 IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __FUNCTION__ );
416 case LM_CONNECT_FAILURE: /* Failed to establish IrLAP connection */
417 IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __FUNCTION__ );
419 case LM_LAP_RESET: /* IrLAP reset */
420 IRDA_DEBUG(2, "%s(), IrLAP reset\n", __FUNCTION__ );
422 case LM_INIT_DISCONNECT:
423 IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __FUNCTION__ );
426 ERROR("%s(), Unknown disconnect reason\n", __FUNCTION__);
430 /* If you want to pass the skb to *both* state machines, you will
431 * need to skb_clone() it, so that you don't free it twice.
432 * As the state machines don't need it, git rid of it here...
435 dev_kfree_skb(userdata);
437 irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
438 irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
440 wake_up_interruptible(&self->open_wait);
443 void irlan_open_data_tsap(struct irlan_cb *self)
445 struct tsap_cb *tsap;
448 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
450 ASSERT(self != NULL, return;);
451 ASSERT(self->magic == IRLAN_MAGIC, return;);
453 /* Check if already open */
457 irda_notify_init(¬ify);
459 notify.data_indication = irlan_eth_receive;
460 notify.udata_indication = irlan_eth_receive;
461 notify.connect_indication = irlan_connect_indication;
462 notify.connect_confirm = irlan_connect_confirm;
463 notify.flow_indication = irlan_eth_flow_indication;
464 notify.disconnect_indication = irlan_disconnect_indication;
465 notify.instance = self;
466 strlcpy(notify.name, "IrLAN data", sizeof(notify.name));
468 tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify);
470 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __FUNCTION__ );
473 self->tsap_data = tsap;
476 * This is the data TSAP selector which we will pass to the client
477 * when the client ask for it.
479 self->stsap_sel_data = self->tsap_data->stsap_sel;
482 void irlan_close_tsaps(struct irlan_cb *self)
484 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
486 ASSERT(self != NULL, return;);
487 ASSERT(self->magic == IRLAN_MAGIC, return;);
489 /* Disconnect and close all open TSAP connections */
490 if (self->tsap_data) {
491 irttp_disconnect_request(self->tsap_data, NULL, P_NORMAL);
492 irttp_close_tsap(self->tsap_data);
493 self->tsap_data = NULL;
495 if (self->client.tsap_ctrl) {
496 irttp_disconnect_request(self->client.tsap_ctrl, NULL,
498 irttp_close_tsap(self->client.tsap_ctrl);
499 self->client.tsap_ctrl = NULL;
501 if (self->provider.tsap_ctrl) {
502 irttp_disconnect_request(self->provider.tsap_ctrl, NULL,
504 irttp_close_tsap(self->provider.tsap_ctrl);
505 self->provider.tsap_ctrl = NULL;
507 self->disconnect_reason = LM_USER_REQUEST;
511 * Function irlan_ias_register (self, tsap_sel)
513 * Register with LM-IAS
516 void irlan_ias_register(struct irlan_cb *self, __u8 tsap_sel)
518 struct ias_object *obj;
519 struct ias_value *new_value;
521 ASSERT(self != NULL, return;);
522 ASSERT(self->magic == IRLAN_MAGIC, return;);
525 * Check if object has already been registered by a previous provider.
526 * If that is the case, we just change the value of the attribute
528 if (!irias_find_object("IrLAN")) {
529 obj = irias_new_object("IrLAN", IAS_IRLAN_ID);
530 irias_add_integer_attrib(obj, "IrDA:TinyTP:LsapSel", tsap_sel,
532 irias_insert_object(obj);
534 new_value = irias_new_integer_value(tsap_sel);
535 irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel",
539 /* Register PnP object only if not registered before */
540 if (!irias_find_object("PnP")) {
541 obj = irias_new_object("PnP", IAS_PNP_ID);
543 irias_add_string_attrib(obj, "Name", sysctl_devname,
546 irias_add_string_attrib(obj, "Name", "Linux", IAS_KERNEL_ATTR);
548 irias_add_string_attrib(obj, "DeviceID", "HWP19F0",
550 irias_add_integer_attrib(obj, "CompCnt", 1, IAS_KERNEL_ATTR);
551 if (self->provider.access_type == ACCESS_PEER)
552 irias_add_string_attrib(obj, "Comp#01", "PNP8389",
555 irias_add_string_attrib(obj, "Comp#01", "PNP8294",
558 irias_add_string_attrib(obj, "Manufacturer",
559 "Linux-IrDA Project", IAS_KERNEL_ATTR);
560 irias_insert_object(obj);
565 * Function irlan_run_ctrl_tx_queue (self)
567 * Try to send the next command in the control transmit queue
570 int irlan_run_ctrl_tx_queue(struct irlan_cb *self)
574 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
576 if (irda_lock(&self->client.tx_busy) == FALSE)
579 skb = skb_dequeue(&self->client.txq);
581 self->client.tx_busy = FALSE;
585 /* Check that it's really possible to send commands */
586 if ((self->client.tsap_ctrl == NULL) ||
587 (self->client.state == IRLAN_IDLE))
589 self->client.tx_busy = FALSE;
593 IRDA_DEBUG(2, "%s(), sending ...\n", __FUNCTION__ );
595 return irttp_data_request(self->client.tsap_ctrl, skb);
599 * Function irlan_ctrl_data_request (self, skb)
601 * This function makes sure that commands on the control channel is being
602 * sent in a command/response fashion
604 void irlan_ctrl_data_request(struct irlan_cb *self, struct sk_buff *skb)
606 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
609 skb_queue_tail(&self->client.txq, skb);
611 /* Try to send command */
612 irlan_run_ctrl_tx_queue(self);
616 * Function irlan_get_provider_info (self)
618 * Send Get Provider Information command to peer IrLAN layer
621 void irlan_get_provider_info(struct irlan_cb *self)
626 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
628 ASSERT(self != NULL, return;);
629 ASSERT(self->magic == IRLAN_MAGIC, return;);
631 skb = dev_alloc_skb(64);
635 /* Reserve space for TTP, LMP, and LAP header */
636 skb_reserve(skb, self->client.max_header_size);
641 frame[0] = CMD_GET_PROVIDER_INFO;
642 frame[1] = 0x00; /* Zero parameters */
644 irlan_ctrl_data_request(self, skb);
648 * Function irlan_open_data_channel (self)
650 * Send an Open Data Command to provider
653 void irlan_open_data_channel(struct irlan_cb *self)
658 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
660 ASSERT(self != NULL, return;);
661 ASSERT(self->magic == IRLAN_MAGIC, return;);
663 skb = dev_alloc_skb(64);
667 skb_reserve(skb, self->client.max_header_size);
673 frame[0] = CMD_OPEN_DATA_CHANNEL;
674 frame[1] = 0x02; /* Two parameters */
676 irlan_insert_string_param(skb, "MEDIA", "802.3");
677 irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT");
678 /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */
680 /* self->use_udata = TRUE; */
682 irlan_ctrl_data_request(self, skb);
685 void irlan_close_data_channel(struct irlan_cb *self)
690 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
692 ASSERT(self != NULL, return;);
693 ASSERT(self->magic == IRLAN_MAGIC, return;);
695 /* Check if the TSAP is still there */
696 if (self->client.tsap_ctrl == NULL)
699 skb = dev_alloc_skb(64);
703 skb_reserve(skb, self->client.max_header_size);
709 frame[0] = CMD_CLOSE_DATA_CHAN;
710 frame[1] = 0x01; /* Two parameters */
712 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
714 irlan_ctrl_data_request(self, skb);
718 * Function irlan_open_unicast_addr (self)
720 * Make IrLAN provider accept ethernet frames addressed to the unicast
724 void irlan_open_unicast_addr(struct irlan_cb *self)
729 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
731 ASSERT(self != NULL, return;);
732 ASSERT(self->magic == IRLAN_MAGIC, return;);
734 skb = dev_alloc_skb(128);
738 /* Reserve space for TTP, LMP, and LAP header */
739 skb_reserve(skb, self->max_header_size);
744 frame[0] = CMD_FILTER_OPERATION;
745 frame[1] = 0x03; /* Three parameters */
746 irlan_insert_byte_param(skb, "DATA_CHAN" , self->dtsap_sel_data);
747 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
748 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
750 irlan_ctrl_data_request(self, skb);
754 * Function irlan_set_broadcast_filter (self, status)
756 * Make IrLAN provider accept ethernet frames addressed to the broadcast
757 * address. Be careful with the use of this one, since there may be a lot
758 * of broadcast traffic out there. We can still function without this
759 * one but then _we_ have to initiate all communication with other
760 * hosts, since ARP request for this host will not be answered.
762 void irlan_set_broadcast_filter(struct irlan_cb *self, int status)
767 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
769 ASSERT(self != NULL, return;);
770 ASSERT(self->magic == IRLAN_MAGIC, return;);
772 skb = dev_alloc_skb(128);
776 /* Reserve space for TTP, LMP, and LAP header */
777 skb_reserve(skb, self->client.max_header_size);
782 frame[0] = CMD_FILTER_OPERATION;
783 frame[1] = 0x03; /* Three parameters */
784 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
785 irlan_insert_string_param(skb, "FILTER_TYPE", "BROADCAST");
787 irlan_insert_string_param(skb, "FILTER_MODE", "FILTER");
789 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
791 irlan_ctrl_data_request(self, skb);
795 * Function irlan_set_multicast_filter (self, status)
797 * Make IrLAN provider accept ethernet frames addressed to the multicast
801 void irlan_set_multicast_filter(struct irlan_cb *self, int status)
806 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
808 ASSERT(self != NULL, return;);
809 ASSERT(self->magic == IRLAN_MAGIC, return;);
811 skb = dev_alloc_skb(128);
815 /* Reserve space for TTP, LMP, and LAP header */
816 skb_reserve(skb, self->client.max_header_size);
821 frame[0] = CMD_FILTER_OPERATION;
822 frame[1] = 0x03; /* Three parameters */
823 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
824 irlan_insert_string_param(skb, "FILTER_TYPE", "MULTICAST");
826 irlan_insert_string_param(skb, "FILTER_MODE", "ALL");
828 irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
830 irlan_ctrl_data_request(self, skb);
834 * Function irlan_get_unicast_addr (self)
836 * Retrieves the unicast address from the IrLAN provider. This address
837 * will be inserted into the devices structure, so the ethernet layer
838 * can construct its packets.
841 void irlan_get_unicast_addr(struct irlan_cb *self)
846 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
848 ASSERT(self != NULL, return;);
849 ASSERT(self->magic == IRLAN_MAGIC, return;);
851 skb = dev_alloc_skb(128);
855 /* Reserve space for TTP, LMP, and LAP header */
856 skb_reserve(skb, self->client.max_header_size);
861 frame[0] = CMD_FILTER_OPERATION;
862 frame[1] = 0x03; /* Three parameters */
863 irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data);
864 irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
865 irlan_insert_string_param(skb, "FILTER_OPERATION", "DYNAMIC");
867 irlan_ctrl_data_request(self, skb);
871 * Function irlan_get_media_char (self)
876 void irlan_get_media_char(struct irlan_cb *self)
881 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
883 ASSERT(self != NULL, return;);
884 ASSERT(self->magic == IRLAN_MAGIC, return;);
886 skb = dev_alloc_skb(64);
890 /* Reserve space for TTP, LMP, and LAP header */
891 skb_reserve(skb, self->client.max_header_size);
897 frame[0] = CMD_GET_MEDIA_CHAR;
898 frame[1] = 0x01; /* One parameter */
900 irlan_insert_string_param(skb, "MEDIA", "802.3");
901 irlan_ctrl_data_request(self, skb);
905 * Function insert_byte_param (skb, param, value)
907 * Insert byte parameter into frame
910 int irlan_insert_byte_param(struct sk_buff *skb, char *param, __u8 value)
912 return __irlan_insert_param(skb, param, IRLAN_BYTE, value, 0, NULL, 0);
915 int irlan_insert_short_param(struct sk_buff *skb, char *param, __u16 value)
917 return __irlan_insert_param(skb, param, IRLAN_SHORT, 0, value, NULL, 0);
921 * Function insert_string (skb, param, value)
923 * Insert string parameter into frame
926 int irlan_insert_string_param(struct sk_buff *skb, char *param, char *string)
928 int string_len = strlen(string);
930 return __irlan_insert_param(skb, param, IRLAN_ARRAY, 0, 0, string,
935 * Function insert_array_param(skb, param, value, len_value)
937 * Insert array parameter into frame
940 int irlan_insert_array_param(struct sk_buff *skb, char *name, __u8 *array,
943 return __irlan_insert_param(skb, name, IRLAN_ARRAY, 0, 0, array,
948 * Function insert_param (skb, param, value, byte)
950 * Insert parameter at end of buffer, structure of a parameter is:
952 * -----------------------------------------------------------------------
953 * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]|
954 * -----------------------------------------------------------------------
956 static int __irlan_insert_param(struct sk_buff *skb, char *param, int type,
957 __u8 value_byte, __u16 value_short,
958 __u8 *value_array, __u16 value_len)
962 __u16 tmp_le; /* Temporary value in little endian format */
966 IRDA_DEBUG(2, "%s(), Got NULL skb\n", __FUNCTION__ );
970 param_len = strlen(param);
979 ASSERT(value_array != NULL, return 0;);
980 ASSERT(value_len > 0, return 0;);
983 IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __FUNCTION__ );
988 /* Insert at end of sk-buffer */
991 /* Make space for data */
992 if (skb_tailroom(skb) < (param_len+value_len+3)) {
993 IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __FUNCTION__ );
996 skb_put(skb, param_len+value_len+3);
998 /* Insert parameter length */
999 frame[n++] = param_len;
1001 /* Insert parameter */
1002 memcpy(frame+n, param, param_len); n += param_len;
1004 /* Insert value length (2 byte little endian format, LSB first) */
1005 tmp_le = cpu_to_le16(value_len);
1006 memcpy(frame+n, &tmp_le, 2); n += 2; /* To avoid alignment problems */
1011 frame[n++] = value_byte;
1014 tmp_le = cpu_to_le16(value_short);
1015 memcpy(frame+n, &tmp_le, 2); n += 2;
1018 memcpy(frame+n, value_array, value_len); n+=value_len;
1023 ASSERT(n == (param_len+value_len+3), return 0;);
1025 return param_len+value_len+3;
1029 * Function irlan_extract_param (buf, name, value, len)
1031 * Extracts a single parameter name/value pair from buffer and updates
1032 * the buffer pointer to point to the next name/value pair.
1034 int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len)
1040 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
1042 /* get length of parameter name (1 byte) */
1043 name_len = buf[n++];
1045 if (name_len > 254) {
1046 IRDA_DEBUG(2, "%s(), name_len > 254\n", __FUNCTION__ );
1047 return -RSP_INVALID_COMMAND_FORMAT;
1050 /* get parameter name */
1051 memcpy(name, buf+n, name_len);
1052 name[name_len] = '\0';
1056 * Get length of parameter value (2 bytes in little endian
1059 memcpy(&val_len, buf+n, 2); /* To avoid alignment problems */
1060 le16_to_cpus(&val_len); n+=2;
1062 if (val_len > 1016) {
1063 IRDA_DEBUG(2, "%s(), parameter length to long\n", __FUNCTION__ );
1064 return -RSP_INVALID_COMMAND_FORMAT;
1068 /* get parameter value */
1069 memcpy(value, buf+n, val_len);
1070 value[val_len] = '\0';
1073 IRDA_DEBUG(4, "Parameter: %s ", name);
1074 IRDA_DEBUG(4, "Value: %s\n", value);
1079 #ifdef CONFIG_PROC_FS
1082 * Start of reading /proc entries.
1083 * Return entry at pos,
1084 * or start_token to indicate print header line
1085 * or NULL if end of file
1087 static void *irlan_seq_start(struct seq_file *seq, loff_t *pos)
1090 struct irlan_cb *self;
1094 return SEQ_START_TOKEN;
1096 list_for_each_entry(self, &irlans, dev_list) {
1104 /* Return entry after v, and increment pos */
1105 static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1107 struct list_head *nxt;
1110 if (v == SEQ_START_TOKEN)
1113 nxt = ((struct irlan_cb *)v)->dev_list.next;
1115 return (nxt == &irlans) ? NULL
1116 : list_entry(nxt, struct irlan_cb, dev_list);
1119 /* End of reading /proc file */
1120 static void irlan_seq_stop(struct seq_file *seq, void *v)
1127 * Show one entry in /proc file.
1129 static int irlan_seq_show(struct seq_file *seq, void *v)
1131 if (v == SEQ_START_TOKEN)
1132 seq_puts(seq, "IrLAN instances:\n");
1134 struct irlan_cb *self = v;
1136 ASSERT(self != NULL, return -1;);
1137 ASSERT(self->magic == IRLAN_MAGIC, return -1;);
1139 seq_printf(seq,"ifname: %s,\n",
1141 seq_printf(seq,"client state: %s, ",
1142 irlan_state[ self->client.state]);
1143 seq_printf(seq,"provider state: %s,\n",
1144 irlan_state[ self->provider.state]);
1145 seq_printf(seq,"saddr: %#08x, ",
1147 seq_printf(seq,"daddr: %#08x\n",
1149 seq_printf(seq,"version: %d.%d,\n",
1150 self->version[1], self->version[0]);
1151 seq_printf(seq,"access type: %s\n",
1152 irlan_access[self->client.access_type]);
1153 seq_printf(seq,"media: %s\n",
1154 irlan_media[self->media]);
1156 seq_printf(seq,"local filter:\n");
1157 seq_printf(seq,"remote filter: ");
1158 irlan_print_filter(seq, self->client.filter_type);
1159 seq_printf(seq,"tx busy: %s\n",
1160 netif_queue_stopped(self->dev) ? "TRUE" : "FALSE");
1167 static struct seq_operations irlan_seq_ops = {
1168 .start = irlan_seq_start,
1169 .next = irlan_seq_next,
1170 .stop = irlan_seq_stop,
1171 .show = irlan_seq_show,
1174 static int irlan_seq_open(struct inode *inode, struct file *file)
1176 return seq_open(file, &irlan_seq_ops);
1180 MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
1181 MODULE_DESCRIPTION("The Linux IrDA LAN protocol");
1182 MODULE_LICENSE("GPL");
1184 MODULE_PARM(eth, "i");
1185 MODULE_PARM_DESC(eth, "Name devices ethX (0) or irlanX (1)");
1186 MODULE_PARM(access, "i");
1187 MODULE_PARM_DESC(access, "Access type DIRECT=1, PEER=2, HOSTED=3");
1189 module_init(irlan_init);
1190 module_exit(irlan_cleanup);