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