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