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