Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Host AP (software wireless LAN access point) driver for |
| 3 | * Intersil Prism2/2.5/3 - hostap.o module, common routines |
| 4 | * |
| 5 | * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen |
Jouni Malinen | 85d32e7 | 2007-03-24 17:15:30 -0700 | [diff] [blame] | 6 | * <j@w1.fi> |
| 7 | * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. See README and COPYING for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/proc_fs.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/random.h> |
| 22 | #include <linux/workqueue.h> |
| 23 | #include <linux/kmod.h> |
| 24 | #include <linux/rtnetlink.h> |
| 25 | #include <linux/wireless.h> |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 26 | #include <linux/etherdevice.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 27 | #include <net/net_namespace.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 28 | #include <net/iw_handler.h> |
Jouni Malinen | ebed67d | 2005-07-30 20:43:19 -0700 | [diff] [blame] | 29 | #include <net/ieee80211.h> |
| 30 | #include <net/ieee80211_crypt.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | |
| 33 | #include "hostap_wlan.h" |
| 34 | #include "hostap_80211.h" |
| 35 | #include "hostap_ap.h" |
| 36 | #include "hostap.h" |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 37 | |
| 38 | MODULE_AUTHOR("Jouni Malinen"); |
| 39 | MODULE_DESCRIPTION("Host AP common routines"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 42 | #define TX_TIMEOUT (2 * HZ) |
| 43 | |
| 44 | #define PRISM2_MAX_FRAME_SIZE 2304 |
| 45 | #define PRISM2_MIN_MTU 256 |
| 46 | /* FIX: */ |
| 47 | #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */)) |
| 48 | |
| 49 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 50 | struct net_device * hostap_add_interface(struct local_info *local, |
| 51 | int type, int rtnl_locked, |
| 52 | const char *prefix, |
| 53 | const char *name) |
| 54 | { |
| 55 | struct net_device *dev, *mdev; |
| 56 | struct hostap_interface *iface; |
| 57 | int ret; |
| 58 | |
| 59 | dev = alloc_etherdev(sizeof(struct hostap_interface)); |
| 60 | if (dev == NULL) |
| 61 | return NULL; |
| 62 | |
| 63 | iface = netdev_priv(dev); |
| 64 | iface->dev = dev; |
| 65 | iface->local = local; |
| 66 | iface->type = type; |
| 67 | list_add(&iface->list, &local->hostap_interfaces); |
| 68 | |
| 69 | mdev = local->dev; |
| 70 | memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN); |
| 71 | dev->base_addr = mdev->base_addr; |
| 72 | dev->irq = mdev->irq; |
| 73 | dev->mem_start = mdev->mem_start; |
| 74 | dev->mem_end = mdev->mem_end; |
| 75 | |
Daniel Drake | 09703f5 | 2007-09-26 21:45:24 +0100 | [diff] [blame] | 76 | hostap_setup_dev(dev, local, type); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 77 | dev->destructor = free_netdev; |
| 78 | |
| 79 | sprintf(dev->name, "%s%s", prefix, name); |
| 80 | if (!rtnl_locked) |
| 81 | rtnl_lock(); |
| 82 | |
| 83 | ret = 0; |
| 84 | if (strchr(dev->name, '%')) |
| 85 | ret = dev_alloc_name(dev, dev->name); |
| 86 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 87 | SET_NETDEV_DEV(dev, mdev->dev.parent); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 88 | if (ret >= 0) |
| 89 | ret = register_netdevice(dev); |
| 90 | |
| 91 | if (!rtnl_locked) |
| 92 | rtnl_unlock(); |
| 93 | |
| 94 | if (ret < 0) { |
| 95 | printk(KERN_WARNING "%s: failed to add new netdevice!\n", |
| 96 | dev->name); |
| 97 | free_netdev(dev); |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | printk(KERN_DEBUG "%s: registered netdevice %s\n", |
| 102 | mdev->name, dev->name); |
| 103 | |
| 104 | return dev; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | void hostap_remove_interface(struct net_device *dev, int rtnl_locked, |
| 109 | int remove_from_list) |
| 110 | { |
| 111 | struct hostap_interface *iface; |
| 112 | |
| 113 | if (!dev) |
| 114 | return; |
| 115 | |
| 116 | iface = netdev_priv(dev); |
| 117 | |
| 118 | if (remove_from_list) { |
| 119 | list_del(&iface->list); |
| 120 | } |
| 121 | |
| 122 | if (dev == iface->local->ddev) |
| 123 | iface->local->ddev = NULL; |
| 124 | else if (dev == iface->local->apdev) |
| 125 | iface->local->apdev = NULL; |
| 126 | else if (dev == iface->local->stadev) |
| 127 | iface->local->stadev = NULL; |
| 128 | |
| 129 | if (rtnl_locked) |
| 130 | unregister_netdevice(dev); |
| 131 | else |
| 132 | unregister_netdev(dev); |
| 133 | |
| 134 | /* dev->destructor = free_netdev() will free the device data, including |
| 135 | * private data, when removing the device */ |
| 136 | } |
| 137 | |
| 138 | |
| 139 | static inline int prism2_wds_special_addr(u8 *addr) |
| 140 | { |
| 141 | if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5]) |
| 142 | return 0; |
| 143 | |
| 144 | return 1; |
| 145 | } |
| 146 | |
| 147 | |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 148 | int prism2_wds_add(local_info_t *local, u8 *remote_addr, |
| 149 | int rtnl_locked) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 150 | { |
| 151 | struct net_device *dev; |
| 152 | struct list_head *ptr; |
| 153 | struct hostap_interface *iface, *empty, *match; |
| 154 | |
| 155 | empty = match = NULL; |
| 156 | read_lock_bh(&local->iface_lock); |
| 157 | list_for_each(ptr, &local->hostap_interfaces) { |
| 158 | iface = list_entry(ptr, struct hostap_interface, list); |
| 159 | if (iface->type != HOSTAP_INTERFACE_WDS) |
| 160 | continue; |
| 161 | |
| 162 | if (prism2_wds_special_addr(iface->u.wds.remote_addr)) |
| 163 | empty = iface; |
| 164 | else if (memcmp(iface->u.wds.remote_addr, remote_addr, |
| 165 | ETH_ALEN) == 0) { |
| 166 | match = iface; |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | if (!match && empty && !prism2_wds_special_addr(remote_addr)) { |
| 171 | /* take pre-allocated entry into use */ |
| 172 | memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN); |
| 173 | read_unlock_bh(&local->iface_lock); |
| 174 | printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n", |
| 175 | local->dev->name, empty->dev->name); |
| 176 | return 0; |
| 177 | } |
| 178 | read_unlock_bh(&local->iface_lock); |
| 179 | |
| 180 | if (!prism2_wds_special_addr(remote_addr)) { |
| 181 | if (match) |
| 182 | return -EEXIST; |
| 183 | hostap_add_sta(local->ap, remote_addr); |
| 184 | } |
| 185 | |
| 186 | if (local->wds_connections >= local->wds_max_connections) |
| 187 | return -ENOBUFS; |
| 188 | |
| 189 | /* verify that there is room for wds# postfix in the interface name */ |
| 190 | if (strlen(local->dev->name) > IFNAMSIZ - 5) { |
| 191 | printk(KERN_DEBUG "'%s' too long base device name\n", |
| 192 | local->dev->name); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked, |
| 197 | local->ddev->name, "wds%d"); |
| 198 | if (dev == NULL) |
| 199 | return -ENOMEM; |
| 200 | |
| 201 | iface = netdev_priv(dev); |
| 202 | memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN); |
| 203 | |
| 204 | local->wds_connections++; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | |
Adrian Bunk | 5fad5a2 | 2006-01-14 03:09:34 +0100 | [diff] [blame] | 210 | int prism2_wds_del(local_info_t *local, u8 *remote_addr, |
| 211 | int rtnl_locked, int do_not_remove) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 212 | { |
| 213 | unsigned long flags; |
| 214 | struct list_head *ptr; |
| 215 | struct hostap_interface *iface, *selected = NULL; |
| 216 | |
| 217 | write_lock_irqsave(&local->iface_lock, flags); |
| 218 | list_for_each(ptr, &local->hostap_interfaces) { |
| 219 | iface = list_entry(ptr, struct hostap_interface, list); |
| 220 | if (iface->type != HOSTAP_INTERFACE_WDS) |
| 221 | continue; |
| 222 | |
| 223 | if (memcmp(iface->u.wds.remote_addr, remote_addr, |
| 224 | ETH_ALEN) == 0) { |
| 225 | selected = iface; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | if (selected && !do_not_remove) |
| 230 | list_del(&selected->list); |
| 231 | write_unlock_irqrestore(&local->iface_lock, flags); |
| 232 | |
| 233 | if (selected) { |
| 234 | if (do_not_remove) |
| 235 | memset(selected->u.wds.remote_addr, 0, ETH_ALEN); |
| 236 | else { |
| 237 | hostap_remove_interface(selected->dev, rtnl_locked, 0); |
| 238 | local->wds_connections--; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | return selected ? 0 : -ENODEV; |
| 243 | } |
| 244 | |
| 245 | |
| 246 | u16 hostap_tx_callback_register(local_info_t *local, |
| 247 | void (*func)(struct sk_buff *, int ok, void *), |
| 248 | void *data) |
| 249 | { |
| 250 | unsigned long flags; |
| 251 | struct hostap_tx_callback_info *entry; |
| 252 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 253 | entry = kmalloc(sizeof(*entry), |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 254 | GFP_ATOMIC); |
| 255 | if (entry == NULL) |
| 256 | return 0; |
| 257 | |
| 258 | entry->func = func; |
| 259 | entry->data = data; |
| 260 | |
| 261 | spin_lock_irqsave(&local->lock, flags); |
| 262 | entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1; |
| 263 | entry->next = local->tx_callback; |
| 264 | local->tx_callback = entry; |
| 265 | spin_unlock_irqrestore(&local->lock, flags); |
| 266 | |
| 267 | return entry->idx; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | int hostap_tx_callback_unregister(local_info_t *local, u16 idx) |
| 272 | { |
| 273 | unsigned long flags; |
| 274 | struct hostap_tx_callback_info *cb, *prev = NULL; |
| 275 | |
| 276 | spin_lock_irqsave(&local->lock, flags); |
| 277 | cb = local->tx_callback; |
| 278 | while (cb != NULL && cb->idx != idx) { |
| 279 | prev = cb; |
| 280 | cb = cb->next; |
| 281 | } |
| 282 | if (cb) { |
| 283 | if (prev == NULL) |
| 284 | local->tx_callback = cb->next; |
| 285 | else |
| 286 | prev->next = cb->next; |
| 287 | kfree(cb); |
| 288 | } |
| 289 | spin_unlock_irqrestore(&local->lock, flags); |
| 290 | |
| 291 | return cb ? 0 : -1; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | /* val is in host byte order */ |
| 296 | int hostap_set_word(struct net_device *dev, int rid, u16 val) |
| 297 | { |
| 298 | struct hostap_interface *iface; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 299 | __le16 tmp = cpu_to_le16(val); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 300 | iface = netdev_priv(dev); |
| 301 | return iface->local->func->set_rid(dev, rid, &tmp, 2); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | int hostap_set_string(struct net_device *dev, int rid, const char *val) |
| 306 | { |
| 307 | struct hostap_interface *iface; |
| 308 | char buf[MAX_SSID_LEN + 2]; |
| 309 | int len; |
| 310 | |
| 311 | iface = netdev_priv(dev); |
| 312 | len = strlen(val); |
| 313 | if (len > MAX_SSID_LEN) |
| 314 | return -1; |
| 315 | memset(buf, 0, sizeof(buf)); |
| 316 | buf[0] = len; /* little endian 16 bit word */ |
| 317 | memcpy(buf + 2, val, len); |
| 318 | |
| 319 | return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | u16 hostap_get_porttype(local_info_t *local) |
| 324 | { |
| 325 | if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc) |
| 326 | return HFA384X_PORTTYPE_PSEUDO_IBSS; |
| 327 | if (local->iw_mode == IW_MODE_ADHOC) |
| 328 | return HFA384X_PORTTYPE_IBSS; |
| 329 | if (local->iw_mode == IW_MODE_INFRA) |
| 330 | return HFA384X_PORTTYPE_BSS; |
| 331 | if (local->iw_mode == IW_MODE_REPEAT) |
| 332 | return HFA384X_PORTTYPE_WDS; |
| 333 | if (local->iw_mode == IW_MODE_MONITOR) |
| 334 | return HFA384X_PORTTYPE_PSEUDO_IBSS; |
| 335 | return HFA384X_PORTTYPE_HOSTAP; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | int hostap_set_encryption(local_info_t *local) |
| 340 | { |
| 341 | u16 val, old_val; |
| 342 | int i, keylen, len, idx; |
| 343 | char keybuf[WEP_KEY_LEN + 1]; |
| 344 | enum { NONE, WEP, OTHER } encrypt_type; |
| 345 | |
| 346 | idx = local->tx_keyidx; |
| 347 | if (local->crypt[idx] == NULL || local->crypt[idx]->ops == NULL) |
| 348 | encrypt_type = NONE; |
| 349 | else if (strcmp(local->crypt[idx]->ops->name, "WEP") == 0) |
| 350 | encrypt_type = WEP; |
| 351 | else |
| 352 | encrypt_type = OTHER; |
| 353 | |
| 354 | if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, |
| 355 | 1) < 0) { |
| 356 | printk(KERN_DEBUG "Could not read current WEP flags.\n"); |
| 357 | goto fail; |
| 358 | } |
| 359 | le16_to_cpus(&val); |
| 360 | old_val = val; |
| 361 | |
| 362 | if (encrypt_type != NONE || local->privacy_invoked) |
| 363 | val |= HFA384X_WEPFLAGS_PRIVACYINVOKED; |
| 364 | else |
| 365 | val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED; |
| 366 | |
| 367 | if (local->open_wep || encrypt_type == NONE || |
| 368 | ((local->ieee_802_1x || local->wpa) && local->host_decrypt)) |
| 369 | val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED; |
| 370 | else |
| 371 | val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED; |
| 372 | |
| 373 | if ((encrypt_type != NONE || local->privacy_invoked) && |
| 374 | (encrypt_type == OTHER || local->host_encrypt)) |
| 375 | val |= HFA384X_WEPFLAGS_HOSTENCRYPT; |
| 376 | else |
| 377 | val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT; |
| 378 | if ((encrypt_type != NONE || local->privacy_invoked) && |
| 379 | (encrypt_type == OTHER || local->host_decrypt)) |
| 380 | val |= HFA384X_WEPFLAGS_HOSTDECRYPT; |
| 381 | else |
| 382 | val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT; |
| 383 | |
| 384 | if (val != old_val && |
| 385 | hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) { |
| 386 | printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n", |
| 387 | val); |
| 388 | goto fail; |
| 389 | } |
| 390 | |
| 391 | if (encrypt_type != WEP) |
| 392 | return 0; |
| 393 | |
| 394 | /* 104-bit support seems to require that all the keys are set to the |
| 395 | * same keylen */ |
| 396 | keylen = 6; /* first 5 octets */ |
| 397 | len = local->crypt[idx]->ops->get_key(keybuf, sizeof(keybuf), |
| 398 | NULL, local->crypt[idx]->priv); |
| 399 | if (idx >= 0 && idx < WEP_KEYS && len > 5) |
| 400 | keylen = WEP_KEY_LEN + 1; /* first 13 octets */ |
| 401 | |
| 402 | for (i = 0; i < WEP_KEYS; i++) { |
| 403 | memset(keybuf, 0, sizeof(keybuf)); |
| 404 | if (local->crypt[i]) { |
| 405 | (void) local->crypt[i]->ops->get_key( |
| 406 | keybuf, sizeof(keybuf), |
| 407 | NULL, local->crypt[i]->priv); |
| 408 | } |
| 409 | if (local->func->set_rid(local->dev, |
| 410 | HFA384X_RID_CNFDEFAULTKEY0 + i, |
| 411 | keybuf, keylen)) { |
| 412 | printk(KERN_DEBUG "Could not set key %d (len=%d)\n", |
| 413 | i, keylen); |
| 414 | goto fail; |
| 415 | } |
| 416 | } |
| 417 | if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) { |
| 418 | printk(KERN_DEBUG "Could not set default keyid %d\n", idx); |
| 419 | goto fail; |
| 420 | } |
| 421 | |
| 422 | return 0; |
| 423 | |
| 424 | fail: |
| 425 | printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name); |
| 426 | return -1; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | int hostap_set_antsel(local_info_t *local) |
| 431 | { |
| 432 | u16 val; |
| 433 | int ret = 0; |
| 434 | |
| 435 | if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH && |
| 436 | local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF, |
| 437 | HFA386X_CR_TX_CONFIGURE, |
| 438 | NULL, &val) == 0) { |
| 439 | val &= ~(BIT(2) | BIT(1)); |
| 440 | switch (local->antsel_tx) { |
| 441 | case HOSTAP_ANTSEL_DIVERSITY: |
| 442 | val |= BIT(1); |
| 443 | break; |
| 444 | case HOSTAP_ANTSEL_LOW: |
| 445 | break; |
| 446 | case HOSTAP_ANTSEL_HIGH: |
| 447 | val |= BIT(2); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF, |
| 452 | HFA386X_CR_TX_CONFIGURE, &val, NULL)) { |
| 453 | printk(KERN_INFO "%s: setting TX AntSel failed\n", |
| 454 | local->dev->name); |
| 455 | ret = -1; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH && |
| 460 | local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF, |
| 461 | HFA386X_CR_RX_CONFIGURE, |
| 462 | NULL, &val) == 0) { |
| 463 | val &= ~(BIT(1) | BIT(0)); |
| 464 | switch (local->antsel_rx) { |
| 465 | case HOSTAP_ANTSEL_DIVERSITY: |
| 466 | break; |
| 467 | case HOSTAP_ANTSEL_LOW: |
| 468 | val |= BIT(0); |
| 469 | break; |
| 470 | case HOSTAP_ANTSEL_HIGH: |
| 471 | val |= BIT(0) | BIT(1); |
| 472 | break; |
| 473 | } |
| 474 | |
| 475 | if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF, |
| 476 | HFA386X_CR_RX_CONFIGURE, &val, NULL)) { |
| 477 | printk(KERN_INFO "%s: setting RX AntSel failed\n", |
| 478 | local->dev->name); |
| 479 | ret = -1; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | return ret; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | int hostap_set_roaming(local_info_t *local) |
| 488 | { |
| 489 | u16 val; |
| 490 | |
| 491 | switch (local->host_roaming) { |
| 492 | case 1: |
| 493 | val = HFA384X_ROAMING_HOST; |
| 494 | break; |
| 495 | case 2: |
| 496 | val = HFA384X_ROAMING_DISABLED; |
| 497 | break; |
| 498 | case 0: |
| 499 | default: |
| 500 | val = HFA384X_ROAMING_FIRMWARE; |
| 501 | break; |
| 502 | } |
| 503 | |
| 504 | return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | int hostap_set_auth_algs(local_info_t *local) |
| 509 | { |
| 510 | int val = local->auth_algs; |
| 511 | /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication |
| 512 | * set to include both Open and Shared Key flags. It tries to use |
| 513 | * Shared Key authentication in that case even if WEP keys are not |
| 514 | * configured.. STA f/w v0.7.6 is able to handle such configuration, |
| 515 | * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */ |
| 516 | if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) && |
| 517 | val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY) |
| 518 | val = PRISM2_AUTH_OPEN; |
| 519 | |
| 520 | if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) { |
| 521 | printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x " |
| 522 | "failed\n", local->dev->name, local->auth_algs); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx) |
| 531 | { |
| 532 | u16 status, fc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 533 | DECLARE_MAC_BUF(mac); |
| 534 | DECLARE_MAC_BUF(mac2); |
| 535 | DECLARE_MAC_BUF(mac3); |
| 536 | DECLARE_MAC_BUF(mac4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 537 | |
| 538 | status = __le16_to_cpu(rx->status); |
| 539 | |
| 540 | printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, " |
| 541 | "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; " |
| 542 | "jiffies=%ld\n", |
| 543 | name, status, (status >> 8) & 0x07, status >> 13, status & 1, |
| 544 | rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies); |
| 545 | |
| 546 | fc = __le16_to_cpu(rx->frame_control); |
| 547 | printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x " |
| 548 | "data_len=%d%s%s\n", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 549 | fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 550 | __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl), |
| 551 | __le16_to_cpu(rx->data_len), |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 552 | fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "", |
| 553 | fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : ""); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 554 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 555 | printk(KERN_DEBUG " A1=%s A2=%s A3=%s A4=%s\n", |
| 556 | print_mac(mac, rx->addr1), print_mac(mac2, rx->addr2), |
| 557 | print_mac(mac3, rx->addr3), print_mac(mac4, rx->addr4)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 558 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 559 | printk(KERN_DEBUG " dst=%s src=%s len=%d\n", |
| 560 | print_mac(mac, rx->dst_addr), print_mac(mac2, rx->src_addr), |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 561 | __be16_to_cpu(rx->len)); |
| 562 | } |
| 563 | |
| 564 | |
| 565 | void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx) |
| 566 | { |
| 567 | u16 fc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 568 | DECLARE_MAC_BUF(mac); |
| 569 | DECLARE_MAC_BUF(mac2); |
| 570 | DECLARE_MAC_BUF(mac3); |
| 571 | DECLARE_MAC_BUF(mac4); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 572 | |
| 573 | printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d " |
| 574 | "tx_control=0x%04x; jiffies=%ld\n", |
| 575 | name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate, |
| 576 | __le16_to_cpu(tx->tx_control), jiffies); |
| 577 | |
| 578 | fc = __le16_to_cpu(tx->frame_control); |
| 579 | printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x " |
| 580 | "data_len=%d%s%s\n", |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 581 | fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 582 | __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl), |
| 583 | __le16_to_cpu(tx->data_len), |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 584 | fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "", |
| 585 | fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : ""); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 586 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 587 | printk(KERN_DEBUG " A1=%s A2=%s A3=%s A4=%s\n", |
| 588 | print_mac(mac, tx->addr1), print_mac(mac2, tx->addr2), |
| 589 | print_mac(mac3, tx->addr3), print_mac(mac4, tx->addr4)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 590 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 591 | printk(KERN_DEBUG " dst=%s src=%s len=%d\n", |
| 592 | print_mac(mac, tx->dst_addr), print_mac(mac2, tx->src_addr), |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 593 | __be16_to_cpu(tx->len)); |
| 594 | } |
| 595 | |
| 596 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 597 | int hostap_80211_header_parse(const struct sk_buff *skb, unsigned char *haddr) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 598 | { |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 599 | struct hostap_interface *iface = netdev_priv(skb->dev); |
| 600 | local_info_t *local = iface->local; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 601 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 602 | if (local->monitor_type == PRISM2_MONITOR_PRISM || |
| 603 | local->monitor_type == PRISM2_MONITOR_CAPHDR) { |
| 604 | const unsigned char *mac = skb_mac_header(skb); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 605 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 606 | if (*(u32 *)mac == LWNG_CAP_DID_BASE) { |
| 607 | memcpy(haddr, |
| 608 | mac + sizeof(struct linux_wlan_ng_prism_hdr) + 10, |
| 609 | ETH_ALEN); /* addr2 */ |
| 610 | } else { /* (*(u32 *)mac == htonl(LWNG_CAPHDR_VERSION)) */ |
| 611 | memcpy(haddr, |
| 612 | mac + sizeof(struct linux_wlan_ng_cap_hdr) + 10, |
| 613 | ETH_ALEN); /* addr2 */ |
| 614 | } |
| 615 | } else |
| 616 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 617 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 618 | return ETH_ALEN; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | int hostap_80211_get_hdrlen(u16 fc) |
| 623 | { |
| 624 | int hdrlen = 24; |
| 625 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 626 | switch (WLAN_FC_GET_TYPE(fc)) { |
| 627 | case IEEE80211_FTYPE_DATA: |
Jouni Malinen | b2f4a2e | 2005-08-14 21:00:01 -0700 | [diff] [blame] | 628 | if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS)) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 629 | hdrlen = 30; /* Addr4 */ |
| 630 | break; |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 631 | case IEEE80211_FTYPE_CTL: |
| 632 | switch (WLAN_FC_GET_STYPE(fc)) { |
| 633 | case IEEE80211_STYPE_CTS: |
| 634 | case IEEE80211_STYPE_ACK: |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 635 | hdrlen = 10; |
| 636 | break; |
| 637 | default: |
| 638 | hdrlen = 16; |
| 639 | break; |
| 640 | } |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | return hdrlen; |
| 645 | } |
| 646 | |
| 647 | |
| 648 | struct net_device_stats *hostap_get_stats(struct net_device *dev) |
| 649 | { |
| 650 | struct hostap_interface *iface; |
| 651 | iface = netdev_priv(dev); |
| 652 | return &iface->stats; |
| 653 | } |
| 654 | |
| 655 | |
| 656 | static int prism2_close(struct net_device *dev) |
| 657 | { |
| 658 | struct hostap_interface *iface; |
| 659 | local_info_t *local; |
| 660 | |
| 661 | PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name); |
| 662 | |
| 663 | iface = netdev_priv(dev); |
| 664 | local = iface->local; |
| 665 | |
| 666 | if (dev == local->ddev) { |
| 667 | prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING); |
| 668 | } |
| 669 | #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT |
| 670 | if (!local->hostapd && dev == local->dev && |
| 671 | (!local->func->card_present || local->func->card_present(local)) && |
| 672 | local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER) |
| 673 | hostap_deauth_all_stas(dev, local->ap, 1); |
| 674 | #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ |
| 675 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 676 | if (dev == local->dev) { |
| 677 | local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL); |
| 678 | } |
| 679 | |
| 680 | if (netif_running(dev)) { |
| 681 | netif_stop_queue(dev); |
| 682 | netif_device_detach(dev); |
| 683 | } |
| 684 | |
David S. Miller | 4bb073c | 2008-06-12 02:22:02 -0700 | [diff] [blame] | 685 | cancel_work_sync(&local->reset_queue); |
| 686 | cancel_work_sync(&local->set_multicast_list_queue); |
| 687 | cancel_work_sync(&local->set_tim_queue); |
| 688 | #ifndef PRISM2_NO_STATION_MODES |
| 689 | cancel_work_sync(&local->info_queue); |
| 690 | #endif |
| 691 | cancel_work_sync(&local->comms_qual_update); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 692 | |
| 693 | module_put(local->hw_module); |
| 694 | |
| 695 | local->num_dev_open--; |
| 696 | |
| 697 | if (dev != local->dev && local->dev->flags & IFF_UP && |
| 698 | local->master_dev_auto_open && local->num_dev_open == 1) { |
| 699 | /* Close master radio interface automatically if it was also |
| 700 | * opened automatically and we are now closing the last |
| 701 | * remaining non-master device. */ |
| 702 | dev_close(local->dev); |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | |
| 709 | static int prism2_open(struct net_device *dev) |
| 710 | { |
| 711 | struct hostap_interface *iface; |
| 712 | local_info_t *local; |
| 713 | |
| 714 | PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name); |
| 715 | |
| 716 | iface = netdev_priv(dev); |
| 717 | local = iface->local; |
| 718 | |
| 719 | if (local->no_pri) { |
| 720 | printk(KERN_DEBUG "%s: could not set interface UP - no PRI " |
| 721 | "f/w\n", dev->name); |
| 722 | return 1; |
| 723 | } |
| 724 | |
| 725 | if ((local->func->card_present && !local->func->card_present(local)) || |
| 726 | local->hw_downloading) |
| 727 | return -ENODEV; |
| 728 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 729 | if (!try_module_get(local->hw_module)) |
| 730 | return -ENODEV; |
| 731 | local->num_dev_open++; |
| 732 | |
| 733 | if (!local->dev_enabled && local->func->hw_enable(dev, 1)) { |
| 734 | printk(KERN_WARNING "%s: could not enable MAC port\n", |
| 735 | dev->name); |
| 736 | prism2_close(dev); |
| 737 | return 1; |
| 738 | } |
| 739 | if (!local->dev_enabled) |
| 740 | prism2_callback(local, PRISM2_CALLBACK_ENABLE); |
| 741 | local->dev_enabled = 1; |
| 742 | |
| 743 | if (dev != local->dev && !(local->dev->flags & IFF_UP)) { |
| 744 | /* Master radio interface is needed for all operation, so open |
| 745 | * it automatically when any virtual net_device is opened. */ |
| 746 | local->master_dev_auto_open = 1; |
| 747 | dev_open(local->dev); |
| 748 | } |
| 749 | |
| 750 | netif_device_attach(dev); |
| 751 | netif_start_queue(dev); |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | |
| 757 | static int prism2_set_mac_address(struct net_device *dev, void *p) |
| 758 | { |
| 759 | struct hostap_interface *iface; |
| 760 | local_info_t *local; |
| 761 | struct list_head *ptr; |
| 762 | struct sockaddr *addr = p; |
| 763 | |
| 764 | iface = netdev_priv(dev); |
| 765 | local = iface->local; |
| 766 | |
| 767 | if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data, |
| 768 | ETH_ALEN) < 0 || local->func->reset_port(dev)) |
| 769 | return -EINVAL; |
| 770 | |
| 771 | read_lock_bh(&local->iface_lock); |
| 772 | list_for_each(ptr, &local->hostap_interfaces) { |
| 773 | iface = list_entry(ptr, struct hostap_interface, list); |
| 774 | memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN); |
| 775 | } |
| 776 | memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN); |
| 777 | read_unlock_bh(&local->iface_lock); |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | |
| 783 | /* TODO: to be further implemented as soon as Prism2 fully supports |
| 784 | * GroupAddresses and correct documentation is available */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 785 | void hostap_set_multicast_list_queue(struct work_struct *work) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 786 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 787 | local_info_t *local = |
| 788 | container_of(work, local_info_t, set_multicast_list_queue); |
| 789 | struct net_device *dev = local->dev; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 790 | struct hostap_interface *iface; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 791 | |
| 792 | iface = netdev_priv(dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 793 | if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE, |
| 794 | local->is_promisc)) { |
| 795 | printk(KERN_INFO "%s: %sabling promiscuous mode failed\n", |
| 796 | dev->name, local->is_promisc ? "en" : "dis"); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
| 801 | static void hostap_set_multicast_list(struct net_device *dev) |
| 802 | { |
| 803 | #if 0 |
| 804 | /* FIX: promiscuous mode seems to be causing a lot of problems with |
| 805 | * some station firmware versions (FCSErr frames, invalid MACPort, etc. |
| 806 | * corrupted incoming frames). This code is now commented out while the |
| 807 | * problems are investigated. */ |
| 808 | struct hostap_interface *iface; |
| 809 | local_info_t *local; |
| 810 | |
| 811 | iface = netdev_priv(dev); |
| 812 | local = iface->local; |
| 813 | if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) { |
| 814 | local->is_promisc = 1; |
| 815 | } else { |
| 816 | local->is_promisc = 0; |
| 817 | } |
| 818 | |
| 819 | schedule_work(&local->set_multicast_list_queue); |
| 820 | #endif |
| 821 | } |
| 822 | |
| 823 | |
| 824 | static int prism2_change_mtu(struct net_device *dev, int new_mtu) |
| 825 | { |
| 826 | if (new_mtu < PRISM2_MIN_MTU || new_mtu > PRISM2_MAX_MTU) |
| 827 | return -EINVAL; |
| 828 | |
| 829 | dev->mtu = new_mtu; |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | |
| 834 | static void prism2_tx_timeout(struct net_device *dev) |
| 835 | { |
| 836 | struct hostap_interface *iface; |
| 837 | local_info_t *local; |
| 838 | struct hfa384x_regs regs; |
| 839 | |
| 840 | iface = netdev_priv(dev); |
| 841 | local = iface->local; |
| 842 | |
| 843 | printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name); |
| 844 | netif_stop_queue(local->dev); |
| 845 | |
| 846 | local->func->read_regs(dev, ®s); |
| 847 | printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x " |
| 848 | "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n", |
| 849 | dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1, |
| 850 | regs.swsupport0); |
| 851 | |
| 852 | local->func->schedule_reset(local); |
| 853 | } |
| 854 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 855 | const struct header_ops hostap_80211_ops = { |
| 856 | .create = eth_header, |
| 857 | .rebuild = eth_rebuild_header, |
| 858 | .cache = eth_header_cache, |
| 859 | .cache_update = eth_header_cache_update, |
| 860 | |
| 861 | .parse = hostap_80211_header_parse, |
| 862 | }; |
| 863 | EXPORT_SYMBOL(hostap_80211_ops); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 864 | |
| 865 | void hostap_setup_dev(struct net_device *dev, local_info_t *local, |
Daniel Drake | 09703f5 | 2007-09-26 21:45:24 +0100 | [diff] [blame] | 866 | int type) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 867 | { |
| 868 | struct hostap_interface *iface; |
| 869 | |
| 870 | iface = netdev_priv(dev); |
| 871 | ether_setup(dev); |
| 872 | |
| 873 | /* kernel callbacks */ |
| 874 | dev->get_stats = hostap_get_stats; |
| 875 | if (iface) { |
| 876 | /* Currently, we point to the proper spy_data only on |
| 877 | * the main_dev. This could be fixed. Jean II */ |
| 878 | iface->wireless_data.spy_data = &iface->spy_data; |
| 879 | dev->wireless_data = &iface->wireless_data; |
| 880 | } |
| 881 | dev->wireless_handlers = |
| 882 | (struct iw_handler_def *) &hostap_iw_handler_def; |
| 883 | dev->do_ioctl = hostap_ioctl; |
| 884 | dev->open = prism2_open; |
| 885 | dev->stop = prism2_close; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 886 | dev->set_mac_address = prism2_set_mac_address; |
| 887 | dev->set_multicast_list = hostap_set_multicast_list; |
| 888 | dev->change_mtu = prism2_change_mtu; |
| 889 | dev->tx_timeout = prism2_tx_timeout; |
| 890 | dev->watchdog_timeo = TX_TIMEOUT; |
| 891 | |
Daniel Drake | 09703f5 | 2007-09-26 21:45:24 +0100 | [diff] [blame] | 892 | if (type == HOSTAP_INTERFACE_AP) { |
| 893 | dev->hard_start_xmit = hostap_mgmt_start_xmit; |
| 894 | dev->type = ARPHRD_IEEE80211; |
| 895 | dev->header_ops = &hostap_80211_ops; |
| 896 | } else { |
| 897 | dev->hard_start_xmit = hostap_data_start_xmit; |
| 898 | } |
| 899 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 900 | dev->mtu = local->mtu; |
Daniel Drake | 09703f5 | 2007-09-26 21:45:24 +0100 | [diff] [blame] | 901 | if (type != HOSTAP_INTERFACE_MASTER) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 902 | /* use main radio device queue */ |
| 903 | dev->tx_queue_len = 0; |
| 904 | } |
| 905 | |
| 906 | SET_ETHTOOL_OPS(dev, &prism2_ethtool_ops); |
| 907 | |
| 908 | netif_stop_queue(dev); |
| 909 | } |
| 910 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 911 | static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked) |
| 912 | { |
| 913 | struct net_device *dev = local->dev; |
| 914 | |
| 915 | if (local->apdev) |
| 916 | return -EEXIST; |
| 917 | |
| 918 | printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name); |
| 919 | |
| 920 | local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP, |
| 921 | rtnl_locked, local->ddev->name, |
| 922 | "ap"); |
| 923 | if (local->apdev == NULL) |
| 924 | return -ENOMEM; |
| 925 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked) |
| 931 | { |
| 932 | struct net_device *dev = local->dev; |
| 933 | |
| 934 | printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name); |
| 935 | |
| 936 | hostap_remove_interface(local->apdev, rtnl_locked, 1); |
| 937 | local->apdev = NULL; |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | |
| 943 | static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked) |
| 944 | { |
| 945 | struct net_device *dev = local->dev; |
| 946 | |
| 947 | if (local->stadev) |
| 948 | return -EEXIST; |
| 949 | |
| 950 | printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name); |
| 951 | |
| 952 | local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA, |
| 953 | rtnl_locked, local->ddev->name, |
| 954 | "sta"); |
| 955 | if (local->stadev == NULL) |
| 956 | return -ENOMEM; |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | |
| 962 | static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked) |
| 963 | { |
| 964 | struct net_device *dev = local->dev; |
| 965 | |
| 966 | printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name); |
| 967 | |
| 968 | hostap_remove_interface(local->stadev, rtnl_locked, 1); |
| 969 | local->stadev = NULL; |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | |
| 975 | int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked) |
| 976 | { |
| 977 | int ret; |
| 978 | |
| 979 | if (val < 0 || val > 1) |
| 980 | return -EINVAL; |
| 981 | |
| 982 | if (local->hostapd == val) |
| 983 | return 0; |
| 984 | |
| 985 | if (val) { |
| 986 | ret = hostap_enable_hostapd(local, rtnl_locked); |
| 987 | if (ret == 0) |
| 988 | local->hostapd = 1; |
| 989 | } else { |
| 990 | local->hostapd = 0; |
| 991 | ret = hostap_disable_hostapd(local, rtnl_locked); |
| 992 | if (ret != 0) |
| 993 | local->hostapd = 1; |
| 994 | } |
| 995 | |
| 996 | return ret; |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked) |
| 1001 | { |
| 1002 | int ret; |
| 1003 | |
| 1004 | if (val < 0 || val > 1) |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | if (local->hostapd_sta == val) |
| 1008 | return 0; |
| 1009 | |
| 1010 | if (val) { |
| 1011 | ret = hostap_enable_hostapd_sta(local, rtnl_locked); |
| 1012 | if (ret == 0) |
| 1013 | local->hostapd_sta = 1; |
| 1014 | } else { |
| 1015 | local->hostapd_sta = 0; |
| 1016 | ret = hostap_disable_hostapd_sta(local, rtnl_locked); |
| 1017 | if (ret != 0) |
| 1018 | local->hostapd_sta = 1; |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | int prism2_update_comms_qual(struct net_device *dev) |
| 1027 | { |
| 1028 | struct hostap_interface *iface; |
| 1029 | local_info_t *local; |
| 1030 | int ret = 0; |
| 1031 | struct hfa384x_comms_quality sq; |
| 1032 | |
| 1033 | iface = netdev_priv(dev); |
| 1034 | local = iface->local; |
| 1035 | if (!local->sta_fw_ver) |
| 1036 | ret = -1; |
| 1037 | else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) { |
| 1038 | if (local->func->get_rid(local->dev, |
| 1039 | HFA384X_RID_DBMCOMMSQUALITY, |
| 1040 | &sq, sizeof(sq), 1) >= 0) { |
| 1041 | local->comms_qual = (s16) le16_to_cpu(sq.comm_qual); |
| 1042 | local->avg_signal = (s16) le16_to_cpu(sq.signal_level); |
| 1043 | local->avg_noise = (s16) le16_to_cpu(sq.noise_level); |
| 1044 | local->last_comms_qual_update = jiffies; |
| 1045 | } else |
| 1046 | ret = -1; |
| 1047 | } else { |
| 1048 | if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY, |
| 1049 | &sq, sizeof(sq), 1) >= 0) { |
| 1050 | local->comms_qual = le16_to_cpu(sq.comm_qual); |
| 1051 | local->avg_signal = HFA384X_LEVEL_TO_dBm( |
| 1052 | le16_to_cpu(sq.signal_level)); |
| 1053 | local->avg_noise = HFA384X_LEVEL_TO_dBm( |
| 1054 | le16_to_cpu(sq.noise_level)); |
| 1055 | local->last_comms_qual_update = jiffies; |
| 1056 | } else |
| 1057 | ret = -1; |
| 1058 | } |
| 1059 | |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
| 1063 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 1064 | int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1065 | u8 *body, size_t bodylen) |
| 1066 | { |
| 1067 | struct sk_buff *skb; |
| 1068 | struct hostap_ieee80211_mgmt *mgmt; |
| 1069 | struct hostap_skb_tx_data *meta; |
| 1070 | struct net_device *dev = local->dev; |
| 1071 | |
| 1072 | skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen); |
| 1073 | if (skb == NULL) |
| 1074 | return -ENOMEM; |
| 1075 | |
| 1076 | mgmt = (struct hostap_ieee80211_mgmt *) |
| 1077 | skb_put(skb, IEEE80211_MGMT_HDR_LEN); |
| 1078 | memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN); |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 1079 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1080 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 1081 | memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN); |
| 1082 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
| 1083 | if (body) |
| 1084 | memcpy(skb_put(skb, bodylen), body, bodylen); |
| 1085 | |
| 1086 | meta = (struct hostap_skb_tx_data *) skb->cb; |
| 1087 | memset(meta, 0, sizeof(*meta)); |
| 1088 | meta->magic = HOSTAP_SKB_TX_DATA_MAGIC; |
| 1089 | meta->iface = netdev_priv(dev); |
| 1090 | |
| 1091 | skb->dev = dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 1092 | skb_reset_mac_header(skb); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 1093 | skb_reset_network_header(skb); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1094 | dev_queue_xmit(skb); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | int prism2_sta_deauth(local_info_t *local, u16 reason) |
| 1101 | { |
| 1102 | union iwreq_data wrqu; |
| 1103 | int ret; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 1104 | __le16 val = cpu_to_le16(reason); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1105 | |
| 1106 | if (local->iw_mode != IW_MODE_INFRA || |
| 1107 | memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 || |
| 1108 | memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0) |
| 1109 | return 0; |
| 1110 | |
Jouni Malinen | 4339d32 | 2005-08-14 19:08:44 -0700 | [diff] [blame] | 1111 | ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH, |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 1112 | (u8 *) &val, 2); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1113 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); |
| 1114 | wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL); |
| 1115 | return ret; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | struct proc_dir_entry *hostap_proc; |
| 1120 | |
| 1121 | static int __init hostap_init(void) |
| 1122 | { |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1123 | if (init_net.proc_net != NULL) { |
| 1124 | hostap_proc = proc_mkdir("hostap", init_net.proc_net); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1125 | if (!hostap_proc) |
| 1126 | printk(KERN_WARNING "Failed to mkdir " |
| 1127 | "/proc/net/hostap\n"); |
| 1128 | } else |
| 1129 | hostap_proc = NULL; |
| 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | static void __exit hostap_exit(void) |
| 1136 | { |
| 1137 | if (hostap_proc != NULL) { |
| 1138 | hostap_proc = NULL; |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 1139 | remove_proc_entry("hostap", init_net.proc_net); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1140 | } |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | EXPORT_SYMBOL(hostap_set_word); |
| 1145 | EXPORT_SYMBOL(hostap_set_string); |
| 1146 | EXPORT_SYMBOL(hostap_get_porttype); |
| 1147 | EXPORT_SYMBOL(hostap_set_encryption); |
| 1148 | EXPORT_SYMBOL(hostap_set_antsel); |
| 1149 | EXPORT_SYMBOL(hostap_set_roaming); |
| 1150 | EXPORT_SYMBOL(hostap_set_auth_algs); |
| 1151 | EXPORT_SYMBOL(hostap_dump_rx_header); |
| 1152 | EXPORT_SYMBOL(hostap_dump_tx_header); |
| 1153 | EXPORT_SYMBOL(hostap_80211_header_parse); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1154 | EXPORT_SYMBOL(hostap_80211_get_hdrlen); |
| 1155 | EXPORT_SYMBOL(hostap_get_stats); |
| 1156 | EXPORT_SYMBOL(hostap_setup_dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1157 | EXPORT_SYMBOL(hostap_set_multicast_list_queue); |
| 1158 | EXPORT_SYMBOL(hostap_set_hostapd); |
| 1159 | EXPORT_SYMBOL(hostap_set_hostapd_sta); |
| 1160 | EXPORT_SYMBOL(hostap_add_interface); |
| 1161 | EXPORT_SYMBOL(hostap_remove_interface); |
| 1162 | EXPORT_SYMBOL(prism2_update_comms_qual); |
| 1163 | |
| 1164 | module_init(hostap_init); |
| 1165 | module_exit(hostap_exit); |