Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Filename: irlan_common.c |
| 4 | * Version: 0.9 |
| 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> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 11 | * |
| 12 | * Copyright (c) 1997, 1999 Dag Brattli <dagb@cs.uit.no>, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * All Rights Reserved. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 14 | * |
| 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * the License, or (at your option) any later version. |
| 19 | * |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 20 | * Neither Dag Brattli nor University of Tromsø admit liability nor |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 21 | * provide warranty for any of this software. This material is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * provided "AS-IS" and at no charge. |
| 23 | * |
| 24 | ********************************************************************/ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | |
| 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> |
| 40 | |
| 41 | #include <asm/system.h> |
| 42 | #include <asm/byteorder.h> |
| 43 | |
| 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> |
| 49 | |
| 50 | #include <net/irda/irlan_common.h> |
| 51 | #include <net/irda/irlan_client.h> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 52 | #include <net/irda/irlan_provider.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <net/irda/irlan_eth.h> |
| 54 | #include <net/irda/irlan_filter.h> |
| 55 | |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* extern char sysctl_devname[]; */ |
| 58 | |
| 59 | /* |
| 60 | * Master structure |
| 61 | */ |
| 62 | static LIST_HEAD(irlans); |
| 63 | |
| 64 | static void *ckey; |
| 65 | static void *skey; |
| 66 | |
| 67 | /* Module parameters */ |
| 68 | static int eth; /* Use "eth" or "irlan" name for devices */ |
| 69 | static int access = ACCESS_PEER; /* PEER, DIRECT or HOSTED */ |
| 70 | |
| 71 | #ifdef CONFIG_PROC_FS |
| 72 | static const char *irlan_access[] = { |
| 73 | "UNKNOWN", |
| 74 | "DIRECT", |
| 75 | "PEER", |
| 76 | "HOSTED" |
| 77 | }; |
| 78 | |
| 79 | static const char *irlan_media[] = { |
| 80 | "UNKNOWN", |
| 81 | "802.3", |
| 82 | "802.5" |
| 83 | }; |
| 84 | |
| 85 | extern struct proc_dir_entry *proc_irda; |
| 86 | |
| 87 | static int irlan_seq_open(struct inode *inode, struct file *file); |
| 88 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 89 | static const struct file_operations irlan_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | .owner = THIS_MODULE, |
| 91 | .open = irlan_seq_open, |
| 92 | .read = seq_read, |
| 93 | .llseek = seq_lseek, |
| 94 | .release = seq_release, |
| 95 | }; |
| 96 | |
| 97 | extern struct proc_dir_entry *proc_irda; |
| 98 | #endif /* CONFIG_PROC_FS */ |
| 99 | |
| 100 | static struct irlan_cb *irlan_open(__u32 saddr, __u32 daddr); |
| 101 | static void __irlan_close(struct irlan_cb *self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 102 | static int __irlan_insert_param(struct sk_buff *skb, char *param, int type, |
| 103 | __u8 value_byte, __u16 value_short, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | __u8 *value_array, __u16 value_len); |
| 105 | static void irlan_open_unicast_addr(struct irlan_cb *self); |
| 106 | static void irlan_get_unicast_addr(struct irlan_cb *self); |
| 107 | void irlan_close_tsaps(struct irlan_cb *self); |
| 108 | |
| 109 | /* |
| 110 | * Function irlan_init (void) |
| 111 | * |
| 112 | * Initialize IrLAN layer |
| 113 | * |
| 114 | */ |
| 115 | static int __init irlan_init(void) |
| 116 | { |
| 117 | struct irlan_cb *new; |
| 118 | __u16 hints; |
| 119 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 120 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | #ifdef CONFIG_PROC_FS |
| 123 | { struct proc_dir_entry *proc; |
Wang Chen | 5e47879 | 2008-02-29 10:34:45 -0800 | [diff] [blame] | 124 | proc = proc_create("irlan", 0, proc_irda, &irlan_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (!proc) { |
| 126 | printk(KERN_ERR "irlan_init: can't create /proc entry!\n"); |
| 127 | return -ENODEV; |
| 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | #endif /* CONFIG_PROC_FS */ |
| 131 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 132 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | hints = irlmp_service_to_hint(S_LAN); |
| 134 | |
| 135 | /* Register with IrLMP as a client */ |
| 136 | ckey = irlmp_register_client(hints, &irlan_client_discovery_indication, |
| 137 | NULL, NULL); |
Akinobu Mita | 719647e | 2007-02-07 00:12:13 -0800 | [diff] [blame] | 138 | if (!ckey) |
| 139 | goto err_ckey; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* Register with IrLMP as a service */ |
Akinobu Mita | 719647e | 2007-02-07 00:12:13 -0800 | [diff] [blame] | 142 | skey = irlmp_register_service(hints); |
| 143 | if (!skey) |
| 144 | goto err_skey; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* Start the master IrLAN instance (the only one for now) */ |
Akinobu Mita | 719647e | 2007-02-07 00:12:13 -0800 | [diff] [blame] | 147 | new = irlan_open(DEV_ADDR_ANY, DEV_ADDR_ANY); |
| 148 | if (!new) |
| 149 | goto err_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | /* The master will only open its (listen) control TSAP */ |
| 152 | irlan_provider_open_ctrl_tsap(new); |
| 153 | |
| 154 | /* Do some fast discovery! */ |
| 155 | irlmp_discovery_request(DISCOVERY_DEFAULT_SLOTS); |
| 156 | |
| 157 | return 0; |
Akinobu Mita | 719647e | 2007-02-07 00:12:13 -0800 | [diff] [blame] | 158 | |
| 159 | err_open: |
| 160 | irlmp_unregister_service(skey); |
| 161 | err_skey: |
| 162 | irlmp_unregister_client(ckey); |
| 163 | err_ckey: |
| 164 | #ifdef CONFIG_PROC_FS |
| 165 | remove_proc_entry("irlan", proc_irda); |
| 166 | #endif /* CONFIG_PROC_FS */ |
| 167 | |
| 168 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 171 | static void __exit irlan_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | struct irlan_cb *self, *next; |
| 174 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 175 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | irlmp_unregister_client(ckey); |
| 178 | irlmp_unregister_service(skey); |
| 179 | |
| 180 | #ifdef CONFIG_PROC_FS |
| 181 | remove_proc_entry("irlan", proc_irda); |
| 182 | #endif /* CONFIG_PROC_FS */ |
| 183 | |
| 184 | /* Cleanup any leftover network devices */ |
| 185 | rtnl_lock(); |
| 186 | list_for_each_entry_safe(self, next, &irlans, dev_list) { |
| 187 | __irlan_close(self); |
| 188 | } |
| 189 | rtnl_unlock(); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Function irlan_open (void) |
| 194 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 195 | * Open new instance of a client/provider, we should only register the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * network device if this instance is ment for a particular client/provider |
| 197 | */ |
| 198 | static struct irlan_cb *irlan_open(__u32 saddr, __u32 daddr) |
| 199 | { |
| 200 | struct net_device *dev; |
| 201 | struct irlan_cb *self; |
| 202 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 203 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | /* Create network device with irlan */ |
| 206 | dev = alloc_irlandev(eth ? "eth%d" : "irlan%d"); |
| 207 | if (!dev) |
| 208 | return NULL; |
| 209 | |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame^] | 210 | self = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | self->dev = dev; |
| 212 | |
| 213 | /* |
| 214 | * Initialize local device structure |
| 215 | */ |
| 216 | self->magic = IRLAN_MAGIC; |
| 217 | self->saddr = saddr; |
| 218 | self->daddr = daddr; |
| 219 | |
| 220 | /* Provider access can only be PEER, DIRECT, or HOSTED */ |
| 221 | self->provider.access_type = access; |
| 222 | if (access == ACCESS_DIRECT) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 223 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | * Since we are emulating an IrLAN sever we will have to |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 225 | * give ourself an ethernet address! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | */ |
| 227 | dev->dev_addr[0] = 0x40; |
| 228 | dev->dev_addr[1] = 0x00; |
| 229 | dev->dev_addr[2] = 0x00; |
| 230 | dev->dev_addr[3] = 0x00; |
| 231 | get_random_bytes(dev->dev_addr+4, 1); |
| 232 | get_random_bytes(dev->dev_addr+5, 1); |
| 233 | } |
| 234 | |
| 235 | self->media = MEDIA_802_3; |
| 236 | self->disconnect_reason = LM_USER_REQUEST; |
| 237 | init_timer(&self->watchdog_timer); |
| 238 | init_timer(&self->client.kick_timer); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 239 | init_waitqueue_head(&self->open_wait); |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | skb_queue_head_init(&self->client.txq); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | irlan_next_client_state(self, IRLAN_IDLE); |
| 244 | irlan_next_provider_state(self, IRLAN_IDLE); |
| 245 | |
| 246 | if (register_netdev(dev)) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 247 | IRDA_DEBUG(2, "%s(), register_netdev() failed!\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 248 | __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | self = NULL; |
| 250 | free_netdev(dev); |
| 251 | } else { |
| 252 | rtnl_lock(); |
| 253 | list_add_rcu(&self->dev_list, &irlans); |
| 254 | rtnl_unlock(); |
| 255 | } |
| 256 | |
| 257 | return self; |
| 258 | } |
| 259 | /* |
| 260 | * Function __irlan_close (self) |
| 261 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 262 | * This function closes and deallocates the IrLAN client instances. Be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | * aware that other functions which calls client_close() must |
| 264 | * remove self from irlans list first. |
| 265 | */ |
| 266 | static void __irlan_close(struct irlan_cb *self) |
| 267 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 268 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | ASSERT_RTNL(); |
| 271 | IRDA_ASSERT(self != NULL, return;); |
| 272 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 273 | |
| 274 | del_timer_sync(&self->watchdog_timer); |
| 275 | del_timer_sync(&self->client.kick_timer); |
| 276 | |
| 277 | /* Close all open connections and remove TSAPs */ |
| 278 | irlan_close_tsaps(self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 279 | |
| 280 | if (self->client.iriap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | iriap_close(self->client.iriap); |
| 282 | |
| 283 | /* Remove frames queued on the control channel */ |
| 284 | skb_queue_purge(&self->client.txq); |
| 285 | |
| 286 | /* Unregister and free self via destructor */ |
| 287 | unregister_netdevice(self->dev); |
| 288 | } |
| 289 | |
| 290 | /* Find any instance of irlan, used for client discovery wakeup */ |
| 291 | struct irlan_cb *irlan_get_any(void) |
| 292 | { |
| 293 | struct irlan_cb *self; |
| 294 | |
| 295 | list_for_each_entry_rcu(self, &irlans, dev_list) { |
| 296 | return self; |
| 297 | } |
| 298 | return NULL; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Function irlan_connect_indication (instance, sap, qos, max_sdu_size, skb) |
| 303 | * |
| 304 | * Here we receive the connect indication for the data channel |
| 305 | * |
| 306 | */ |
| 307 | static void irlan_connect_indication(void *instance, void *sap, |
| 308 | struct qos_info *qos, |
| 309 | __u32 max_sdu_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 310 | __u8 max_header_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | struct sk_buff *skb) |
| 312 | { |
| 313 | struct irlan_cb *self; |
| 314 | struct tsap_cb *tsap; |
| 315 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 316 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | self = (struct irlan_cb *) instance; |
| 319 | tsap = (struct tsap_cb *) sap; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | IRDA_ASSERT(self != NULL, return;); |
| 322 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 323 | IRDA_ASSERT(tsap == self->tsap_data,return;); |
| 324 | |
| 325 | self->max_sdu_size = max_sdu_size; |
| 326 | self->max_header_size = max_header_size; |
| 327 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 328 | IRDA_DEBUG(0, "%s: We are now connected!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | del_timer(&self->watchdog_timer); |
| 331 | |
| 332 | /* If you want to pass the skb to *both* state machines, you will |
| 333 | * need to skb_clone() it, so that you don't free it twice. |
| 334 | * As the state machines don't need it, git rid of it here... |
| 335 | * Jean II */ |
| 336 | if (skb) |
| 337 | dev_kfree_skb(skb); |
| 338 | |
| 339 | irlan_do_provider_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL); |
| 340 | irlan_do_client_event(self, IRLAN_DATA_CONNECT_INDICATION, NULL); |
| 341 | |
| 342 | if (self->provider.access_type == ACCESS_PEER) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 343 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | * Data channel is open, so we are now allowed to |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 345 | * configure the remote filter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | */ |
| 347 | irlan_get_unicast_addr(self); |
| 348 | irlan_open_unicast_addr(self); |
| 349 | } |
| 350 | /* Ready to transfer Ethernet frames (at last) */ |
| 351 | netif_start_queue(self->dev); /* Clear reason */ |
| 352 | } |
| 353 | |
| 354 | static void irlan_connect_confirm(void *instance, void *sap, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 355 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | __u32 max_sdu_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 357 | __u8 max_header_size, |
| 358 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
| 360 | struct irlan_cb *self; |
| 361 | |
| 362 | self = (struct irlan_cb *) instance; |
| 363 | |
| 364 | IRDA_ASSERT(self != NULL, return;); |
| 365 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 366 | |
| 367 | self->max_sdu_size = max_sdu_size; |
| 368 | self->max_header_size = max_header_size; |
| 369 | |
| 370 | /* TODO: we could set the MTU depending on the max_sdu_size */ |
| 371 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 372 | IRDA_DEBUG(0, "%s: We are now connected!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | del_timer(&self->watchdog_timer); |
| 374 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 375 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | * Data channel is open, so we are now allowed to configure the remote |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 377 | * filter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | */ |
| 379 | irlan_get_unicast_addr(self); |
| 380 | irlan_open_unicast_addr(self); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* Open broadcast and multicast filter by default */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 383 | irlan_set_broadcast_filter(self, TRUE); |
| 384 | irlan_set_multicast_filter(self, TRUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* Ready to transfer Ethernet frames */ |
| 387 | netif_start_queue(self->dev); |
| 388 | self->disconnect_reason = 0; /* Clear reason */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | wake_up_interruptible(&self->open_wait); |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Function irlan_client_disconnect_indication (handle) |
| 394 | * |
| 395 | * Callback function for the IrTTP layer. Indicates a disconnection of |
| 396 | * the specified connection (handle) |
| 397 | */ |
| 398 | static void irlan_disconnect_indication(void *instance, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 399 | void *sap, LM_REASON reason, |
| 400 | struct sk_buff *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | struct irlan_cb *self; |
| 403 | struct tsap_cb *tsap; |
| 404 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 405 | IRDA_DEBUG(0, "%s(), reason=%d\n", __func__ , reason); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | self = (struct irlan_cb *) instance; |
| 408 | tsap = (struct tsap_cb *) sap; |
| 409 | |
| 410 | IRDA_ASSERT(self != NULL, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 411 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | IRDA_ASSERT(tsap != NULL, return;); |
| 413 | IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | IRDA_ASSERT(tsap == self->tsap_data, return;); |
| 416 | |
| 417 | IRDA_DEBUG(2, "IrLAN, data channel disconnected by peer!\n"); |
| 418 | |
| 419 | /* Save reason so we know if we should try to reconnect or not */ |
| 420 | self->disconnect_reason = reason; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | switch (reason) { |
| 423 | case LM_USER_REQUEST: /* User request */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 424 | IRDA_DEBUG(2, "%s(), User requested\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | break; |
| 426 | case LM_LAP_DISCONNECT: /* Unexpected IrLAP disconnect */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 427 | IRDA_DEBUG(2, "%s(), Unexpected IrLAP disconnect\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | break; |
| 429 | case LM_CONNECT_FAILURE: /* Failed to establish IrLAP connection */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 430 | IRDA_DEBUG(2, "%s(), IrLAP connect failed\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | break; |
| 432 | case LM_LAP_RESET: /* IrLAP reset */ |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 433 | IRDA_DEBUG(2, "%s(), IrLAP reset\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | break; |
| 435 | case LM_INIT_DISCONNECT: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 436 | IRDA_DEBUG(2, "%s(), IrLMP connect failed\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | break; |
| 438 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 439 | IRDA_ERROR("%s(), Unknown disconnect reason\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | break; |
| 441 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* If you want to pass the skb to *both* state machines, you will |
| 444 | * need to skb_clone() it, so that you don't free it twice. |
| 445 | * As the state machines don't need it, git rid of it here... |
| 446 | * Jean II */ |
| 447 | if (userdata) |
| 448 | dev_kfree_skb(userdata); |
| 449 | |
| 450 | irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL); |
| 451 | irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | wake_up_interruptible(&self->open_wait); |
| 454 | } |
| 455 | |
| 456 | void irlan_open_data_tsap(struct irlan_cb *self) |
| 457 | { |
| 458 | struct tsap_cb *tsap; |
| 459 | notify_t notify; |
| 460 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 461 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | IRDA_ASSERT(self != NULL, return;); |
| 464 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 465 | |
| 466 | /* Check if already open */ |
| 467 | if (self->tsap_data) |
| 468 | return; |
| 469 | |
| 470 | irda_notify_init(¬ify); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | notify.data_indication = irlan_eth_receive; |
| 473 | notify.udata_indication = irlan_eth_receive; |
| 474 | notify.connect_indication = irlan_connect_indication; |
| 475 | notify.connect_confirm = irlan_connect_confirm; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 476 | notify.flow_indication = irlan_eth_flow_indication; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | notify.disconnect_indication = irlan_disconnect_indication; |
| 478 | notify.instance = self; |
| 479 | strlcpy(notify.name, "IrLAN data", sizeof(notify.name)); |
| 480 | |
| 481 | tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify); |
| 482 | if (!tsap) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 483 | IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | self->tsap_data = tsap; |
| 487 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 488 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | * This is the data TSAP selector which we will pass to the client |
| 490 | * when the client ask for it. |
| 491 | */ |
| 492 | self->stsap_sel_data = self->tsap_data->stsap_sel; |
| 493 | } |
| 494 | |
| 495 | void irlan_close_tsaps(struct irlan_cb *self) |
| 496 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 497 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | IRDA_ASSERT(self != NULL, return;); |
| 500 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 501 | |
| 502 | /* Disconnect and close all open TSAP connections */ |
| 503 | if (self->tsap_data) { |
| 504 | irttp_disconnect_request(self->tsap_data, NULL, P_NORMAL); |
| 505 | irttp_close_tsap(self->tsap_data); |
| 506 | self->tsap_data = NULL; |
| 507 | } |
| 508 | if (self->client.tsap_ctrl) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 509 | irttp_disconnect_request(self->client.tsap_ctrl, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | P_NORMAL); |
| 511 | irttp_close_tsap(self->client.tsap_ctrl); |
| 512 | self->client.tsap_ctrl = NULL; |
| 513 | } |
| 514 | if (self->provider.tsap_ctrl) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 515 | irttp_disconnect_request(self->provider.tsap_ctrl, NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | P_NORMAL); |
| 517 | irttp_close_tsap(self->provider.tsap_ctrl); |
| 518 | self->provider.tsap_ctrl = NULL; |
| 519 | } |
| 520 | self->disconnect_reason = LM_USER_REQUEST; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Function irlan_ias_register (self, tsap_sel) |
| 525 | * |
| 526 | * Register with LM-IAS |
| 527 | * |
| 528 | */ |
| 529 | void irlan_ias_register(struct irlan_cb *self, __u8 tsap_sel) |
| 530 | { |
| 531 | struct ias_object *obj; |
| 532 | struct ias_value *new_value; |
| 533 | |
| 534 | IRDA_ASSERT(self != NULL, return;); |
| 535 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 536 | |
| 537 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | * Check if object has already been registered by a previous provider. |
| 539 | * If that is the case, we just change the value of the attribute |
| 540 | */ |
| 541 | if (!irias_find_object("IrLAN")) { |
| 542 | obj = irias_new_object("IrLAN", IAS_IRLAN_ID); |
| 543 | irias_add_integer_attrib(obj, "IrDA:TinyTP:LsapSel", tsap_sel, |
| 544 | IAS_KERNEL_ATTR); |
| 545 | irias_insert_object(obj); |
| 546 | } else { |
| 547 | new_value = irias_new_integer_value(tsap_sel); |
| 548 | irias_object_change_attribute("IrLAN", "IrDA:TinyTP:LsapSel", |
| 549 | new_value); |
| 550 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 551 | |
| 552 | /* Register PnP object only if not registered before */ |
| 553 | if (!irias_find_object("PnP")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | obj = irias_new_object("PnP", IAS_PNP_ID); |
| 555 | #if 0 |
| 556 | irias_add_string_attrib(obj, "Name", sysctl_devname, |
| 557 | IAS_KERNEL_ATTR); |
| 558 | #else |
| 559 | irias_add_string_attrib(obj, "Name", "Linux", IAS_KERNEL_ATTR); |
| 560 | #endif |
| 561 | irias_add_string_attrib(obj, "DeviceID", "HWP19F0", |
| 562 | IAS_KERNEL_ATTR); |
| 563 | irias_add_integer_attrib(obj, "CompCnt", 1, IAS_KERNEL_ATTR); |
| 564 | if (self->provider.access_type == ACCESS_PEER) |
| 565 | irias_add_string_attrib(obj, "Comp#01", "PNP8389", |
| 566 | IAS_KERNEL_ATTR); |
| 567 | else |
| 568 | irias_add_string_attrib(obj, "Comp#01", "PNP8294", |
| 569 | IAS_KERNEL_ATTR); |
| 570 | |
| 571 | irias_add_string_attrib(obj, "Manufacturer", |
| 572 | "Linux-IrDA Project", IAS_KERNEL_ATTR); |
| 573 | irias_insert_object(obj); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /* |
| 578 | * Function irlan_run_ctrl_tx_queue (self) |
| 579 | * |
| 580 | * Try to send the next command in the control transmit queue |
| 581 | * |
| 582 | */ |
| 583 | int irlan_run_ctrl_tx_queue(struct irlan_cb *self) |
| 584 | { |
| 585 | struct sk_buff *skb; |
| 586 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 587 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | if (irda_lock(&self->client.tx_busy) == FALSE) |
| 590 | return -EBUSY; |
| 591 | |
| 592 | skb = skb_dequeue(&self->client.txq); |
| 593 | if (!skb) { |
| 594 | self->client.tx_busy = FALSE; |
| 595 | return 0; |
| 596 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /* Check that it's really possible to send commands */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 599 | if ((self->client.tsap_ctrl == NULL) || |
| 600 | (self->client.state == IRLAN_IDLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
| 602 | self->client.tx_busy = FALSE; |
| 603 | dev_kfree_skb(skb); |
| 604 | return -1; |
| 605 | } |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 606 | IRDA_DEBUG(2, "%s(), sending ...\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | return irttp_data_request(self->client.tsap_ctrl, skb); |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * Function irlan_ctrl_data_request (self, skb) |
| 613 | * |
| 614 | * This function makes sure that commands on the control channel is being |
| 615 | * sent in a command/response fashion |
| 616 | */ |
| 617 | static void irlan_ctrl_data_request(struct irlan_cb *self, struct sk_buff *skb) |
| 618 | { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 619 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | /* Queue command */ |
| 622 | skb_queue_tail(&self->client.txq, skb); |
| 623 | |
| 624 | /* Try to send command */ |
| 625 | irlan_run_ctrl_tx_queue(self); |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | * Function irlan_get_provider_info (self) |
| 630 | * |
| 631 | * Send Get Provider Information command to peer IrLAN layer |
| 632 | * |
| 633 | */ |
| 634 | void irlan_get_provider_info(struct irlan_cb *self) |
| 635 | { |
| 636 | struct sk_buff *skb; |
| 637 | __u8 *frame; |
| 638 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 639 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | IRDA_ASSERT(self != NULL, return;); |
| 642 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 643 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 644 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER, |
| 645 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | if (!skb) |
| 647 | return; |
| 648 | |
| 649 | /* Reserve space for TTP, LMP, and LAP header */ |
| 650 | skb_reserve(skb, self->client.max_header_size); |
| 651 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 654 | |
| 655 | frame[0] = CMD_GET_PROVIDER_INFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | frame[1] = 0x00; /* Zero parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | irlan_ctrl_data_request(self, skb); |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * Function irlan_open_data_channel (self) |
| 663 | * |
| 664 | * Send an Open Data Command to provider |
| 665 | * |
| 666 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 667 | void irlan_open_data_channel(struct irlan_cb *self) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
| 669 | struct sk_buff *skb; |
| 670 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 671 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 672 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | IRDA_ASSERT(self != NULL, return;); |
| 675 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 676 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 677 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 678 | IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3") + |
| 679 | IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "DIRECT"), |
| 680 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | if (!skb) |
| 682 | return; |
| 683 | |
| 684 | skb_reserve(skb, self->client.max_header_size); |
| 685 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | /* Build frame */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 690 | frame[0] = CMD_OPEN_DATA_CHANNEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | frame[1] = 0x02; /* Two parameters */ |
| 692 | |
| 693 | irlan_insert_string_param(skb, "MEDIA", "802.3"); |
| 694 | irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT"); |
| 695 | /* irlan_insert_string_param(skb, "MODE", "UNRELIABLE"); */ |
| 696 | |
| 697 | /* self->use_udata = TRUE; */ |
| 698 | |
| 699 | irlan_ctrl_data_request(self, skb); |
| 700 | } |
| 701 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 702 | void irlan_close_data_channel(struct irlan_cb *self) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
| 704 | struct sk_buff *skb; |
| 705 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 706 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 707 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
| 709 | IRDA_ASSERT(self != NULL, return;); |
| 710 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 711 | |
| 712 | /* Check if the TSAP is still there */ |
| 713 | if (self->client.tsap_ctrl == NULL) |
| 714 | return; |
| 715 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 716 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 717 | IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN"), |
| 718 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | if (!skb) |
| 720 | return; |
| 721 | |
| 722 | skb_reserve(skb, self->client.max_header_size); |
| 723 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /* Build frame */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 728 | frame[0] = CMD_CLOSE_DATA_CHAN; |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 729 | frame[1] = 0x01; /* One parameter */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| 731 | irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data); |
| 732 | |
| 733 | irlan_ctrl_data_request(self, skb); |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * Function irlan_open_unicast_addr (self) |
| 738 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 739 | * Make IrLAN provider accept ethernet frames addressed to the unicast |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | * address. |
| 741 | * |
| 742 | */ |
| 743 | static void irlan_open_unicast_addr(struct irlan_cb *self) |
| 744 | { |
| 745 | struct sk_buff *skb; |
| 746 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 747 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 748 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | IRDA_ASSERT(self != NULL, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 751 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 752 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 753 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 754 | IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") + |
| 755 | IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") + |
| 756 | IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"), |
| 757 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | if (!skb) |
| 759 | return; |
| 760 | |
| 761 | /* Reserve space for TTP, LMP, and LAP header */ |
| 762 | skb_reserve(skb, self->max_header_size); |
| 763 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 766 | |
| 767 | frame[0] = CMD_FILTER_OPERATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | frame[1] = 0x03; /* Three parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 769 | irlan_insert_byte_param(skb, "DATA_CHAN" , self->dtsap_sel_data); |
| 770 | irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED"); |
| 771 | irlan_insert_string_param(skb, "FILTER_MODE", "FILTER"); |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | irlan_ctrl_data_request(self, skb); |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Function irlan_set_broadcast_filter (self, status) |
| 778 | * |
| 779 | * Make IrLAN provider accept ethernet frames addressed to the broadcast |
| 780 | * address. Be careful with the use of this one, since there may be a lot |
| 781 | * of broadcast traffic out there. We can still function without this |
| 782 | * one but then _we_ have to initiate all communication with other |
| 783 | * hosts, since ARP request for this host will not be answered. |
| 784 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 785 | void irlan_set_broadcast_filter(struct irlan_cb *self, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
| 787 | struct sk_buff *skb; |
| 788 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 789 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 790 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | IRDA_ASSERT(self != NULL, return;); |
| 793 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 794 | |
| 795 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 796 | IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") + |
| 797 | IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") + |
| 798 | /* We may waste one byte here...*/ |
| 799 | IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "FILTER"), |
| 800 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if (!skb) |
| 802 | return; |
| 803 | |
| 804 | /* Reserve space for TTP, LMP, and LAP header */ |
| 805 | skb_reserve(skb, self->client.max_header_size); |
| 806 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 809 | |
| 810 | frame[0] = CMD_FILTER_OPERATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | frame[1] = 0x03; /* Three parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 812 | irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data); |
| 813 | irlan_insert_string_param(skb, "FILTER_TYPE", "BROADCAST"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (status) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 815 | irlan_insert_string_param(skb, "FILTER_MODE", "FILTER"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | else |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 817 | irlan_insert_string_param(skb, "FILTER_MODE", "NONE"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | irlan_ctrl_data_request(self, skb); |
| 820 | } |
| 821 | |
| 822 | /* |
| 823 | * Function irlan_set_multicast_filter (self, status) |
| 824 | * |
| 825 | * Make IrLAN provider accept ethernet frames addressed to the multicast |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 826 | * address. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | * |
| 828 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 829 | void irlan_set_multicast_filter(struct irlan_cb *self, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | { |
| 831 | struct sk_buff *skb; |
| 832 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 833 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 834 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | IRDA_ASSERT(self != NULL, return;); |
| 837 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 838 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 839 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 840 | IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") + |
| 841 | IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") + |
| 842 | /* We may waste one byte here...*/ |
| 843 | IRLAN_STRING_PARAMETER_LEN("FILTER_MODE", "NONE"), |
| 844 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | if (!skb) |
| 846 | return; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | /* Reserve space for TTP, LMP, and LAP header */ |
| 849 | skb_reserve(skb, self->client.max_header_size); |
| 850 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 853 | |
| 854 | frame[0] = CMD_FILTER_OPERATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | frame[1] = 0x03; /* Three parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 856 | irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data); |
| 857 | irlan_insert_string_param(skb, "FILTER_TYPE", "MULTICAST"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | if (status) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 859 | irlan_insert_string_param(skb, "FILTER_MODE", "ALL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | else |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 861 | irlan_insert_string_param(skb, "FILTER_MODE", "NONE"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | irlan_ctrl_data_request(self, skb); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * Function irlan_get_unicast_addr (self) |
| 868 | * |
| 869 | * Retrieves the unicast address from the IrLAN provider. This address |
| 870 | * will be inserted into the devices structure, so the ethernet layer |
| 871 | * can construct its packets. |
| 872 | * |
| 873 | */ |
| 874 | static void irlan_get_unicast_addr(struct irlan_cb *self) |
| 875 | { |
| 876 | struct sk_buff *skb; |
| 877 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 878 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 879 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | IRDA_ASSERT(self != NULL, return;); |
| 882 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 883 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 884 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 885 | IRLAN_BYTE_PARAMETER_LEN("DATA_CHAN") + |
| 886 | IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") + |
| 887 | IRLAN_STRING_PARAMETER_LEN("FILTER_OPERATION", |
| 888 | "DYNAMIC"), |
| 889 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | if (!skb) |
| 891 | return; |
| 892 | |
| 893 | /* Reserve space for TTP, LMP, and LAP header */ |
| 894 | skb_reserve(skb, self->client.max_header_size); |
| 895 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 898 | |
| 899 | frame[0] = CMD_FILTER_OPERATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | frame[1] = 0x03; /* Three parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 901 | irlan_insert_byte_param(skb, "DATA_CHAN", self->dtsap_sel_data); |
| 902 | irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED"); |
| 903 | irlan_insert_string_param(skb, "FILTER_OPERATION", "DYNAMIC"); |
| 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | irlan_ctrl_data_request(self, skb); |
| 906 | } |
| 907 | |
| 908 | /* |
| 909 | * Function irlan_get_media_char (self) |
| 910 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 911 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | * |
| 913 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 914 | void irlan_get_media_char(struct irlan_cb *self) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
| 916 | struct sk_buff *skb; |
| 917 | __u8 *frame; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 918 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 919 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | IRDA_ASSERT(self != NULL, return;); |
| 922 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 923 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 924 | skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER + |
| 925 | IRLAN_STRING_PARAMETER_LEN("MEDIA", "802.3"), |
| 926 | GFP_ATOMIC); |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if (!skb) |
| 929 | return; |
| 930 | |
| 931 | /* Reserve space for TTP, LMP, and LAP header */ |
| 932 | skb_reserve(skb, self->client.max_header_size); |
| 933 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | /* Build frame */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 938 | frame[0] = CMD_GET_MEDIA_CHAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | frame[1] = 0x01; /* One parameter */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | irlan_insert_string_param(skb, "MEDIA", "802.3"); |
| 942 | irlan_ctrl_data_request(self, skb); |
| 943 | } |
| 944 | |
| 945 | /* |
| 946 | * Function insert_byte_param (skb, param, value) |
| 947 | * |
| 948 | * Insert byte parameter into frame |
| 949 | * |
| 950 | */ |
| 951 | int irlan_insert_byte_param(struct sk_buff *skb, char *param, __u8 value) |
| 952 | { |
| 953 | return __irlan_insert_param(skb, param, IRLAN_BYTE, value, 0, NULL, 0); |
| 954 | } |
| 955 | |
| 956 | int irlan_insert_short_param(struct sk_buff *skb, char *param, __u16 value) |
| 957 | { |
| 958 | return __irlan_insert_param(skb, param, IRLAN_SHORT, 0, value, NULL, 0); |
| 959 | } |
| 960 | |
| 961 | /* |
| 962 | * Function insert_string (skb, param, value) |
| 963 | * |
| 964 | * Insert string parameter into frame |
| 965 | * |
| 966 | */ |
| 967 | int irlan_insert_string_param(struct sk_buff *skb, char *param, char *string) |
| 968 | { |
| 969 | int string_len = strlen(string); |
| 970 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 971 | return __irlan_insert_param(skb, param, IRLAN_ARRAY, 0, 0, string, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | string_len); |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | * Function insert_array_param(skb, param, value, len_value) |
| 977 | * |
| 978 | * Insert array parameter into frame |
| 979 | * |
| 980 | */ |
| 981 | int irlan_insert_array_param(struct sk_buff *skb, char *name, __u8 *array, |
| 982 | __u16 array_len) |
| 983 | { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 984 | return __irlan_insert_param(skb, name, IRLAN_ARRAY, 0, 0, array, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | array_len); |
| 986 | } |
| 987 | |
| 988 | /* |
| 989 | * Function insert_param (skb, param, value, byte) |
| 990 | * |
| 991 | * Insert parameter at end of buffer, structure of a parameter is: |
| 992 | * |
| 993 | * ----------------------------------------------------------------------- |
| 994 | * | Name Length[1] | Param Name[1..255] | Val Length[2] | Value[0..1016]| |
| 995 | * ----------------------------------------------------------------------- |
| 996 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 997 | static int __irlan_insert_param(struct sk_buff *skb, char *param, int type, |
| 998 | __u8 value_byte, __u16 value_short, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | __u8 *value_array, __u16 value_len) |
| 1000 | { |
| 1001 | __u8 *frame; |
| 1002 | __u8 param_len; |
Al Viro | 448c31a | 2006-11-14 20:47:46 -0800 | [diff] [blame] | 1003 | __le16 tmp_le; /* Temporary value in little endian format */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | int n=0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | if (skb == NULL) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1007 | IRDA_DEBUG(2, "%s(), Got NULL skb\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | return 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
| 1011 | param_len = strlen(param); |
| 1012 | switch (type) { |
| 1013 | case IRLAN_BYTE: |
| 1014 | value_len = 1; |
| 1015 | break; |
| 1016 | case IRLAN_SHORT: |
| 1017 | value_len = 2; |
| 1018 | break; |
| 1019 | case IRLAN_ARRAY: |
| 1020 | IRDA_ASSERT(value_array != NULL, return 0;); |
| 1021 | IRDA_ASSERT(value_len > 0, return 0;); |
| 1022 | break; |
| 1023 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1024 | IRDA_DEBUG(2, "%s(), Unknown parameter type!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | return 0; |
| 1026 | break; |
| 1027 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | /* Insert at end of sk-buffer */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 1030 | frame = skb_tail_pointer(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
| 1032 | /* Make space for data */ |
| 1033 | if (skb_tailroom(skb) < (param_len+value_len+3)) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1034 | IRDA_DEBUG(2, "%s(), No more space at end of skb\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | return 0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | skb_put(skb, param_len+value_len+3); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | /* Insert parameter length */ |
| 1040 | frame[n++] = param_len; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | /* Insert parameter */ |
| 1043 | memcpy(frame+n, param, param_len); n += param_len; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | /* Insert value length (2 byte little endian format, LSB first) */ |
| 1046 | tmp_le = cpu_to_le16(value_len); |
| 1047 | memcpy(frame+n, &tmp_le, 2); n += 2; /* To avoid alignment problems */ |
| 1048 | |
| 1049 | /* Insert value */ |
| 1050 | switch (type) { |
| 1051 | case IRLAN_BYTE: |
| 1052 | frame[n++] = value_byte; |
| 1053 | break; |
| 1054 | case IRLAN_SHORT: |
| 1055 | tmp_le = cpu_to_le16(value_short); |
| 1056 | memcpy(frame+n, &tmp_le, 2); n += 2; |
| 1057 | break; |
| 1058 | case IRLAN_ARRAY: |
| 1059 | memcpy(frame+n, value_array, value_len); n+=value_len; |
| 1060 | break; |
| 1061 | default: |
| 1062 | break; |
| 1063 | } |
| 1064 | IRDA_ASSERT(n == (param_len+value_len+3), return 0;); |
| 1065 | |
| 1066 | return param_len+value_len+3; |
| 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * Function irlan_extract_param (buf, name, value, len) |
| 1071 | * |
| 1072 | * Extracts a single parameter name/value pair from buffer and updates |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1073 | * the buffer pointer to point to the next name/value pair. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | */ |
| 1075 | int irlan_extract_param(__u8 *buf, char *name, char *value, __u16 *len) |
| 1076 | { |
| 1077 | __u8 name_len; |
| 1078 | __u16 val_len; |
| 1079 | int n=0; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1080 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1081 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | /* get length of parameter name (1 byte) */ |
| 1084 | name_len = buf[n++]; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if (name_len > 254) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1087 | IRDA_DEBUG(2, "%s(), name_len > 254\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return -RSP_INVALID_COMMAND_FORMAT; |
| 1089 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | /* get parameter name */ |
| 1092 | memcpy(name, buf+n, name_len); |
| 1093 | name[name_len] = '\0'; |
| 1094 | n+=name_len; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1095 | |
| 1096 | /* |
| 1097 | * Get length of parameter value (2 bytes in little endian |
| 1098 | * format) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | */ |
| 1100 | memcpy(&val_len, buf+n, 2); /* To avoid alignment problems */ |
| 1101 | le16_to_cpus(&val_len); n+=2; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | if (val_len > 1016) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1104 | IRDA_DEBUG(2, "%s(), parameter length to long\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return -RSP_INVALID_COMMAND_FORMAT; |
| 1106 | } |
| 1107 | *len = val_len; |
| 1108 | |
| 1109 | /* get parameter value */ |
| 1110 | memcpy(value, buf+n, val_len); |
| 1111 | value[val_len] = '\0'; |
| 1112 | n+=val_len; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1113 | |
| 1114 | IRDA_DEBUG(4, "Parameter: %s ", name); |
| 1115 | IRDA_DEBUG(4, "Value: %s\n", value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | return n; |
| 1118 | } |
| 1119 | |
| 1120 | #ifdef CONFIG_PROC_FS |
| 1121 | |
| 1122 | /* |
| 1123 | * Start of reading /proc entries. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1124 | * Return entry at pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | * or start_token to indicate print header line |
| 1126 | * or NULL if end of file |
| 1127 | */ |
| 1128 | static void *irlan_seq_start(struct seq_file *seq, loff_t *pos) |
| 1129 | { |
| 1130 | int i = 1; |
| 1131 | struct irlan_cb *self; |
| 1132 | |
| 1133 | rcu_read_lock(); |
| 1134 | if (*pos == 0) |
| 1135 | return SEQ_START_TOKEN; |
| 1136 | |
| 1137 | list_for_each_entry(self, &irlans, dev_list) { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1138 | if (*pos == i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | return self; |
| 1140 | ++i; |
| 1141 | } |
| 1142 | return NULL; |
| 1143 | } |
| 1144 | |
| 1145 | /* Return entry after v, and increment pos */ |
| 1146 | static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1147 | { |
| 1148 | struct list_head *nxt; |
| 1149 | |
| 1150 | ++*pos; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1151 | if (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | nxt = irlans.next; |
| 1153 | else |
| 1154 | nxt = ((struct irlan_cb *)v)->dev_list.next; |
| 1155 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1156 | return (nxt == &irlans) ? NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | : list_entry(nxt, struct irlan_cb, dev_list); |
| 1158 | } |
| 1159 | |
| 1160 | /* End of reading /proc file */ |
| 1161 | static void irlan_seq_stop(struct seq_file *seq, void *v) |
| 1162 | { |
| 1163 | rcu_read_unlock(); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | /* |
| 1168 | * Show one entry in /proc file. |
| 1169 | */ |
| 1170 | static int irlan_seq_show(struct seq_file *seq, void *v) |
| 1171 | { |
| 1172 | if (v == SEQ_START_TOKEN) |
| 1173 | seq_puts(seq, "IrLAN instances:\n"); |
| 1174 | else { |
| 1175 | struct irlan_cb *self = v; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | IRDA_ASSERT(self != NULL, return -1;); |
| 1178 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;); |
| 1179 | |
| 1180 | seq_printf(seq,"ifname: %s,\n", |
| 1181 | self->dev->name); |
| 1182 | seq_printf(seq,"client state: %s, ", |
| 1183 | irlan_state[ self->client.state]); |
| 1184 | seq_printf(seq,"provider state: %s,\n", |
| 1185 | irlan_state[ self->provider.state]); |
| 1186 | seq_printf(seq,"saddr: %#08x, ", |
| 1187 | self->saddr); |
| 1188 | seq_printf(seq,"daddr: %#08x\n", |
| 1189 | self->daddr); |
| 1190 | seq_printf(seq,"version: %d.%d,\n", |
| 1191 | self->version[1], self->version[0]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1192 | seq_printf(seq,"access type: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | irlan_access[self->client.access_type]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1194 | seq_printf(seq,"media: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | irlan_media[self->media]); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | seq_printf(seq,"local filter:\n"); |
| 1198 | seq_printf(seq,"remote filter: "); |
| 1199 | irlan_print_filter(seq, self->client.filter_type); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1200 | seq_printf(seq,"tx busy: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | netif_queue_stopped(self->dev) ? "TRUE" : "FALSE"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | seq_putc(seq,'\n'); |
| 1204 | } |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 1208 | static const struct seq_operations irlan_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | .start = irlan_seq_start, |
| 1210 | .next = irlan_seq_next, |
| 1211 | .stop = irlan_seq_stop, |
| 1212 | .show = irlan_seq_show, |
| 1213 | }; |
| 1214 | |
| 1215 | static int irlan_seq_open(struct inode *inode, struct file *file) |
| 1216 | { |
| 1217 | return seq_open(file, &irlan_seq_ops); |
| 1218 | } |
| 1219 | #endif |
| 1220 | |
| 1221 | MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 1222 | MODULE_DESCRIPTION("The Linux IrDA LAN protocol"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | MODULE_LICENSE("GPL"); |
| 1224 | |
| 1225 | module_param(eth, bool, 0); |
| 1226 | MODULE_PARM_DESC(eth, "Name devices ethX (0) or irlanX (1)"); |
| 1227 | module_param(access, int, 0); |
| 1228 | MODULE_PARM_DESC(access, "Access type DIRECT=1, PEER=2, HOSTED=3"); |
| 1229 | |
| 1230 | module_init(irlan_init); |
| 1231 | module_exit(irlan_cleanup); |
| 1232 | |