Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.35 2938 lines 91 kB view raw
1/*============================================================================= 2 * 3 * A PCMCIA client driver for the Raylink wireless LAN card. 4 * The starting point for this module was the skeleton.c in the 5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net 6 * 7 * 8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com) 9 * 10 * This driver is free software; you can redistribute it and/or modify 11 * it under the terms of version 2 only of the GNU General Public License as 12 * published by the Free Software Foundation. 13 * 14 * It is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 22 * 23 * Changes: 24 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000 25 * - reorganize kmallocs in ray_attach, checking all for failure 26 * and releasing the previous allocations if one fails 27 * 28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003 29 * - Audit copy_to_user in ioctl(SIOCGIWESSID) 30 * 31=============================================================================*/ 32 33#include <linux/module.h> 34#include <linux/kernel.h> 35#include <linux/proc_fs.h> 36#include <linux/ptrace.h> 37#include <linux/seq_file.h> 38#include <linux/string.h> 39#include <linux/timer.h> 40#include <linux/init.h> 41#include <linux/netdevice.h> 42#include <linux/etherdevice.h> 43#include <linux/if_arp.h> 44#include <linux/ioport.h> 45#include <linux/skbuff.h> 46#include <linux/ethtool.h> 47#include <linux/ieee80211.h> 48 49#include <pcmcia/cs_types.h> 50#include <pcmcia/cs.h> 51#include <pcmcia/cistpl.h> 52#include <pcmcia/cisreg.h> 53#include <pcmcia/ds.h> 54 55#include <linux/wireless.h> 56#include <net/iw_handler.h> 57 58#include <asm/io.h> 59#include <asm/system.h> 60#include <asm/byteorder.h> 61#include <asm/uaccess.h> 62 63/* Warning : these stuff will slow down the driver... */ 64#define WIRELESS_SPY /* Enable spying addresses */ 65/* Definitions we need for spy */ 66typedef struct iw_statistics iw_stats; 67typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */ 68 69#include "rayctl.h" 70#include "ray_cs.h" 71 72 73/** Prototypes based on PCMCIA skeleton driver *******************************/ 74static int ray_config(struct pcmcia_device *link); 75static void ray_release(struct pcmcia_device *link); 76static void ray_detach(struct pcmcia_device *p_dev); 77 78/***** Prototypes indicated by device structure ******************************/ 79static int ray_dev_close(struct net_device *dev); 80static int ray_dev_config(struct net_device *dev, struct ifmap *map); 81static struct net_device_stats *ray_get_stats(struct net_device *dev); 82static int ray_dev_init(struct net_device *dev); 83 84static const struct ethtool_ops netdev_ethtool_ops; 85 86static int ray_open(struct net_device *dev); 87static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb, 88 struct net_device *dev); 89static void set_multicast_list(struct net_device *dev); 90static void ray_update_multi_list(struct net_device *dev, int all); 91static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, 92 unsigned char *data, int len); 93static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, 94 UCHAR msg_type, unsigned char *data); 95static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len); 96static iw_stats *ray_get_wireless_stats(struct net_device *dev); 97static const struct iw_handler_def ray_handler_def; 98 99/***** Prototypes for raylink functions **************************************/ 100static int asc_to_int(char a); 101static void authenticate(ray_dev_t *local); 102static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type); 103static void authenticate_timeout(u_long); 104static int get_free_ccs(ray_dev_t *local); 105static int get_free_tx_ccs(ray_dev_t *local); 106static void init_startup_params(ray_dev_t *local); 107static int parse_addr(char *in_str, UCHAR *out); 108static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type); 109static int ray_init(struct net_device *dev); 110static int interrupt_ecf(ray_dev_t *local, int ccs); 111static void ray_reset(struct net_device *dev); 112static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len); 113static void verify_dl_startup(u_long); 114 115/* Prototypes for interrpt time functions **********************************/ 116static irqreturn_t ray_interrupt(int reg, void *dev_id); 117static void clear_interrupt(ray_dev_t *local); 118static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs, 119 unsigned int pkt_addr, int rx_len); 120static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len); 121static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs); 122static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs); 123static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, 124 unsigned int pkt_addr, int rx_len); 125static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, 126 unsigned int pkt_addr, int rx_len); 127static void associate(ray_dev_t *local); 128 129/* Card command functions */ 130static int dl_startup_params(struct net_device *dev); 131static void join_net(u_long local); 132static void start_net(u_long local); 133/* void start_net(ray_dev_t *local); */ 134 135/*===========================================================================*/ 136/* Parameters that can be set with 'insmod' */ 137 138/* ADHOC=0, Infrastructure=1 */ 139static int net_type = ADHOC; 140 141/* Hop dwell time in Kus (1024 us units defined by 802.11) */ 142static int hop_dwell = 128; 143 144/* Beacon period in Kus */ 145static int beacon_period = 256; 146 147/* power save mode (0 = off, 1 = save power) */ 148static int psm; 149 150/* String for network's Extended Service Set ID. 32 Characters max */ 151static char *essid; 152 153/* Default to encapsulation unless translation requested */ 154static int translate = 1; 155 156static int country = USA; 157 158static int sniffer; 159 160static int bc; 161 162/* 48 bit physical card address if overriding card's real physical 163 * address is required. Since IEEE 802.11 addresses are 48 bits 164 * like ethernet, an int can't be used, so a string is used. To 165 * allow use of addresses starting with a decimal digit, the first 166 * character must be a letter and will be ignored. This letter is 167 * followed by up to 12 hex digits which are the address. If less 168 * than 12 digits are used, the address will be left filled with 0's. 169 * Note that bit 0 of the first byte is the broadcast bit, and evil 170 * things will happen if it is not 0 in a card address. 171 */ 172static char *phy_addr = NULL; 173 174 175/* A struct pcmcia_device structure has fields for most things that are needed 176 to keep track of a socket, but there will usually be some device 177 specific information that also needs to be kept track of. The 178 'priv' pointer in a struct pcmcia_device structure can be used to point to 179 a device-specific private data structure, like this. 180*/ 181static unsigned int ray_mem_speed = 500; 182 183/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */ 184static struct pcmcia_device *this_device = NULL; 185 186MODULE_AUTHOR("Corey Thomas <corey@world.std.com>"); 187MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver"); 188MODULE_LICENSE("GPL"); 189 190module_param(net_type, int, 0); 191module_param(hop_dwell, int, 0); 192module_param(beacon_period, int, 0); 193module_param(psm, int, 0); 194module_param(essid, charp, 0); 195module_param(translate, int, 0); 196module_param(country, int, 0); 197module_param(sniffer, int, 0); 198module_param(bc, int, 0); 199module_param(phy_addr, charp, 0); 200module_param(ray_mem_speed, int, 0); 201 202static UCHAR b5_default_startup_parms[] = { 203 0, 0, /* Adhoc station */ 204 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */ 205 0, 0, 0, 0, 0, 0, 0, 0, 206 0, 0, 0, 0, 0, 0, 0, 0, 207 0, 0, 0, 0, 0, 0, 0, 0, 208 1, 0, /* Active scan, CA Mode */ 209 0, 0, 0, 0, 0, 0, /* No default MAC addr */ 210 0x7f, 0xff, /* Frag threshold */ 211 0x00, 0x80, /* Hop time 128 Kus */ 212 0x01, 0x00, /* Beacon period 256 Kus */ 213 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */ 214 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */ 215 0x7f, 0xff, /* RTS threshold */ 216 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */ 217 0x05, /* assoc resp timeout thresh */ 218 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */ 219 0, /* Promiscuous mode */ 220 0x0c, 0x0bd, /* Unique word */ 221 0x32, /* Slot time */ 222 0xff, 0xff, /* roam-low snr, low snr count */ 223 0x05, 0xff, /* Infra, adhoc missed bcn thresh */ 224 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */ 225/* b4 - b5 differences start here */ 226 0x00, 0x3f, /* CW max */ 227 0x00, 0x0f, /* CW min */ 228 0x04, 0x08, /* Noise gain, limit offset */ 229 0x28, 0x28, /* det rssi, med busy offsets */ 230 7, /* det sync thresh */ 231 0, 2, 2, /* test mode, min, max */ 232 0, /* allow broadcast SSID probe resp */ 233 0, 0, /* privacy must start, can join */ 234 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */ 235}; 236 237static UCHAR b4_default_startup_parms[] = { 238 0, 0, /* Adhoc station */ 239 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */ 240 0, 0, 0, 0, 0, 0, 0, 0, 241 0, 0, 0, 0, 0, 0, 0, 0, 242 0, 0, 0, 0, 0, 0, 0, 0, 243 1, 0, /* Active scan, CA Mode */ 244 0, 0, 0, 0, 0, 0, /* No default MAC addr */ 245 0x7f, 0xff, /* Frag threshold */ 246 0x02, 0x00, /* Hop time */ 247 0x00, 0x01, /* Beacon period */ 248 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */ 249 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */ 250 0x7f, 0xff, /* RTS threshold */ 251 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */ 252 0x05, /* assoc resp timeout thresh */ 253 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */ 254 0, /* Promiscuous mode */ 255 0x0c, 0x0bd, /* Unique word */ 256 0x4e, /* Slot time (TBD seems wrong) */ 257 0xff, 0xff, /* roam-low snr, low snr count */ 258 0x05, 0xff, /* Infra, adhoc missed bcn thresh */ 259 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */ 260/* b4 - b5 differences start here */ 261 0x3f, 0x0f, /* CW max, min */ 262 0x04, 0x08, /* Noise gain, limit offset */ 263 0x28, 0x28, /* det rssi, med busy offsets */ 264 7, /* det sync thresh */ 265 0, 2, 2 /* test mode, min, max */ 266}; 267 268/*===========================================================================*/ 269static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 }; 270 271static char hop_pattern_length[] = { 1, 272 USA_HOP_MOD, EUROPE_HOP_MOD, 273 JAPAN_HOP_MOD, KOREA_HOP_MOD, 274 SPAIN_HOP_MOD, FRANCE_HOP_MOD, 275 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD, 276 JAPAN_TEST_HOP_MOD 277}; 278 279static char rcsid[] = 280 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>"; 281 282static const struct net_device_ops ray_netdev_ops = { 283 .ndo_init = ray_dev_init, 284 .ndo_open = ray_open, 285 .ndo_stop = ray_dev_close, 286 .ndo_start_xmit = ray_dev_start_xmit, 287 .ndo_set_config = ray_dev_config, 288 .ndo_get_stats = ray_get_stats, 289 .ndo_set_multicast_list = set_multicast_list, 290 .ndo_change_mtu = eth_change_mtu, 291 .ndo_set_mac_address = eth_mac_addr, 292 .ndo_validate_addr = eth_validate_addr, 293}; 294 295/*============================================================================= 296 ray_attach() creates an "instance" of the driver, allocating 297 local data structures for one device. The device is registered 298 with Card Services. 299 The dev_link structure is initialized, but we don't actually 300 configure the card at this point -- we wait until we receive a 301 card insertion event. 302=============================================================================*/ 303static int ray_probe(struct pcmcia_device *p_dev) 304{ 305 ray_dev_t *local; 306 struct net_device *dev; 307 308 dev_dbg(&p_dev->dev, "ray_attach()\n"); 309 310 /* Allocate space for private device-specific data */ 311 dev = alloc_etherdev(sizeof(ray_dev_t)); 312 if (!dev) 313 goto fail_alloc_dev; 314 315 local = netdev_priv(dev); 316 local->finder = p_dev; 317 318 /* The io structure describes IO port mapping. None used here */ 319 p_dev->io.NumPorts1 = 0; 320 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 321 p_dev->io.IOAddrLines = 5; 322 323 /* General socket configuration */ 324 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 325 p_dev->conf.IntType = INT_MEMORY_AND_IO; 326 p_dev->conf.ConfigIndex = 1; 327 328 p_dev->priv = dev; 329 330 local->finder = p_dev; 331 local->card_status = CARD_INSERTED; 332 local->authentication_state = UNAUTHENTICATED; 333 local->num_multi = 0; 334 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n", 335 p_dev, dev, local, &ray_interrupt); 336 337 /* Raylink entries in the device structure */ 338 dev->netdev_ops = &ray_netdev_ops; 339 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 340 dev->wireless_handlers = &ray_handler_def; 341#ifdef WIRELESS_SPY 342 local->wireless_data.spy_data = &local->spy_data; 343 dev->wireless_data = &local->wireless_data; 344#endif /* WIRELESS_SPY */ 345 346 347 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n"); 348 netif_stop_queue(dev); 349 350 init_timer(&local->timer); 351 352 this_device = p_dev; 353 return ray_config(p_dev); 354 355fail_alloc_dev: 356 return -ENOMEM; 357} /* ray_attach */ 358 359/*============================================================================= 360 This deletes a driver "instance". The device is de-registered 361 with Card Services. If it has been released, all local data 362 structures are freed. Otherwise, the structures will be freed 363 when the device is released. 364=============================================================================*/ 365static void ray_detach(struct pcmcia_device *link) 366{ 367 struct net_device *dev; 368 ray_dev_t *local; 369 370 dev_dbg(&link->dev, "ray_detach\n"); 371 372 this_device = NULL; 373 dev = link->priv; 374 375 ray_release(link); 376 377 local = netdev_priv(dev); 378 del_timer(&local->timer); 379 380 if (link->priv) { 381 unregister_netdev(dev); 382 free_netdev(dev); 383 } 384 dev_dbg(&link->dev, "ray_cs ray_detach ending\n"); 385} /* ray_detach */ 386 387/*============================================================================= 388 ray_config() is run after a CARD_INSERTION event 389 is received, to configure the PCMCIA socket, and to make the 390 ethernet device available to the system. 391=============================================================================*/ 392#define MAX_TUPLE_SIZE 128 393static int ray_config(struct pcmcia_device *link) 394{ 395 int ret = 0; 396 int i; 397 win_req_t req; 398 memreq_t mem; 399 struct net_device *dev = (struct net_device *)link->priv; 400 ray_dev_t *local = netdev_priv(dev); 401 402 dev_dbg(&link->dev, "ray_config\n"); 403 404 /* Determine card type and firmware version */ 405 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n", 406 link->prod_id[0] ? link->prod_id[0] : " ", 407 link->prod_id[1] ? link->prod_id[1] : " ", 408 link->prod_id[2] ? link->prod_id[2] : " ", 409 link->prod_id[3] ? link->prod_id[3] : " "); 410 411 /* Now allocate an interrupt line. Note that this does not 412 actually assign a handler to the interrupt. 413 */ 414 ret = pcmcia_request_irq(link, ray_interrupt); 415 if (ret) 416 goto failed; 417 dev->irq = link->irq; 418 419 /* This actually configures the PCMCIA socket -- setting up 420 the I/O windows and the interrupt mapping. 421 */ 422 ret = pcmcia_request_configuration(link, &link->conf); 423 if (ret) 424 goto failed; 425 426/*** Set up 32k window for shared memory (transmit and control) ************/ 427 req.Attributes = 428 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 429 req.Base = 0; 430 req.Size = 0x8000; 431 req.AccessSpeed = ray_mem_speed; 432 ret = pcmcia_request_window(link, &req, &link->win); 433 if (ret) 434 goto failed; 435 mem.CardOffset = 0x0000; 436 mem.Page = 0; 437 ret = pcmcia_map_mem_page(link, link->win, &mem); 438 if (ret) 439 goto failed; 440 local->sram = ioremap(req.Base, req.Size); 441 442/*** Set up 16k window for shared memory (receive buffer) ***************/ 443 req.Attributes = 444 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 445 req.Base = 0; 446 req.Size = 0x4000; 447 req.AccessSpeed = ray_mem_speed; 448 ret = pcmcia_request_window(link, &req, &local->rmem_handle); 449 if (ret) 450 goto failed; 451 mem.CardOffset = 0x8000; 452 mem.Page = 0; 453 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem); 454 if (ret) 455 goto failed; 456 local->rmem = ioremap(req.Base, req.Size); 457 458/*** Set up window for attribute memory ***********************************/ 459 req.Attributes = 460 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT; 461 req.Base = 0; 462 req.Size = 0x1000; 463 req.AccessSpeed = ray_mem_speed; 464 ret = pcmcia_request_window(link, &req, &local->amem_handle); 465 if (ret) 466 goto failed; 467 mem.CardOffset = 0x0000; 468 mem.Page = 0; 469 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem); 470 if (ret) 471 goto failed; 472 local->amem = ioremap(req.Base, req.Size); 473 474 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram); 475 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem); 476 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem); 477 if (ray_init(dev) < 0) { 478 ray_release(link); 479 return -ENODEV; 480 } 481 482 SET_NETDEV_DEV(dev, &link->dev); 483 i = register_netdev(dev); 484 if (i != 0) { 485 printk("ray_config register_netdev() failed\n"); 486 ray_release(link); 487 return i; 488 } 489 490 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n", 491 dev->name, dev->irq, dev->dev_addr); 492 493 return 0; 494 495failed: 496 ray_release(link); 497 return -ENODEV; 498} /* ray_config */ 499 500static inline struct ccs __iomem *ccs_base(ray_dev_t *dev) 501{ 502 return dev->sram + CCS_BASE; 503} 504 505static inline struct rcs __iomem *rcs_base(ray_dev_t *dev) 506{ 507 /* 508 * This looks nonsensical, since there is a separate 509 * RCS_BASE. But the difference between a "struct rcs" 510 * and a "struct ccs" ends up being in the _index_ off 511 * the base, so the base pointer is the same for both 512 * ccs/rcs. 513 */ 514 return dev->sram + CCS_BASE; 515} 516 517/*===========================================================================*/ 518static int ray_init(struct net_device *dev) 519{ 520 int i; 521 UCHAR *p; 522 struct ccs __iomem *pccs; 523 ray_dev_t *local = netdev_priv(dev); 524 struct pcmcia_device *link = local->finder; 525 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev); 526 if (!(pcmcia_dev_present(link))) { 527 dev_dbg(&link->dev, "ray_init - device not present\n"); 528 return -1; 529 } 530 531 local->net_type = net_type; 532 local->sta_type = TYPE_STA; 533 534 /* Copy the startup results to local memory */ 535 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE, 536 sizeof(struct startup_res_6)); 537 538 /* Check Power up test status and get mac address from card */ 539 if (local->startup_res.startup_word != 0x80) { 540 printk(KERN_INFO "ray_init ERROR card status = %2x\n", 541 local->startup_res.startup_word); 542 local->card_status = CARD_INIT_ERROR; 543 return -1; 544 } 545 546 local->fw_ver = local->startup_res.firmware_version[0]; 547 local->fw_bld = local->startup_res.firmware_version[1]; 548 local->fw_var = local->startup_res.firmware_version[2]; 549 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver, 550 local->fw_bld); 551 552 local->tib_length = 0x20; 553 if ((local->fw_ver == 5) && (local->fw_bld >= 30)) 554 local->tib_length = local->startup_res.tib_length; 555 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length); 556 /* Initialize CCS's to buffer free state */ 557 pccs = ccs_base(local); 558 for (i = 0; i < NUMBER_OF_CCS; i++) { 559 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 560 } 561 init_startup_params(local); 562 563 /* copy mac address to startup parameters */ 564 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) { 565 p = local->sparm.b4.a_mac_addr; 566 } else { 567 memcpy(&local->sparm.b4.a_mac_addr, 568 &local->startup_res.station_addr, ADDRLEN); 569 p = local->sparm.b4.a_mac_addr; 570 } 571 572 clear_interrupt(local); /* Clear any interrupt from the card */ 573 local->card_status = CARD_AWAITING_PARAM; 574 dev_dbg(&link->dev, "ray_init ending\n"); 575 return 0; 576} /* ray_init */ 577 578/*===========================================================================*/ 579/* Download startup parameters to the card and command it to read them */ 580static int dl_startup_params(struct net_device *dev) 581{ 582 int ccsindex; 583 ray_dev_t *local = netdev_priv(dev); 584 struct ccs __iomem *pccs; 585 struct pcmcia_device *link = local->finder; 586 587 dev_dbg(&link->dev, "dl_startup_params entered\n"); 588 if (!(pcmcia_dev_present(link))) { 589 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n"); 590 return -1; 591 } 592 593 /* Copy parameters to host to ECF area */ 594 if (local->fw_ver == 0x55) 595 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4, 596 sizeof(struct b4_startup_params)); 597 else 598 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5, 599 sizeof(struct b5_startup_params)); 600 601 /* Fill in the CCS fields for the ECF */ 602 if ((ccsindex = get_free_ccs(local)) < 0) 603 return -1; 604 local->dl_param_ccs = ccsindex; 605 pccs = ccs_base(local) + ccsindex; 606 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd); 607 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n", 608 local->dl_param_ccs); 609 /* Interrupt the firmware to process the command */ 610 if (interrupt_ecf(local, ccsindex)) { 611 printk(KERN_INFO "ray dl_startup_params failed - " 612 "ECF not ready for intr\n"); 613 local->card_status = CARD_DL_PARAM_ERROR; 614 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 615 return -2; 616 } 617 local->card_status = CARD_DL_PARAM; 618 /* Start kernel timer to wait for dl startup to complete. */ 619 local->timer.expires = jiffies + HZ / 2; 620 local->timer.data = (long)local; 621 local->timer.function = &verify_dl_startup; 622 add_timer(&local->timer); 623 dev_dbg(&link->dev, 624 "ray_cs dl_startup_params started timer for verify_dl_startup\n"); 625 return 0; 626} /* dl_startup_params */ 627 628/*===========================================================================*/ 629static void init_startup_params(ray_dev_t *local) 630{ 631 int i; 632 633 if (country > JAPAN_TEST) 634 country = USA; 635 else if (country < USA) 636 country = USA; 637 /* structure for hop time and beacon period is defined here using 638 * New 802.11D6.1 format. Card firmware is still using old format 639 * until version 6. 640 * Before After 641 * a_hop_time ms byte a_hop_time ms byte 642 * a_hop_time 2s byte a_hop_time ls byte 643 * a_hop_time ls byte a_beacon_period ms byte 644 * a_beacon_period a_beacon_period ls byte 645 * 646 * a_hop_time = uS a_hop_time = KuS 647 * a_beacon_period = hops a_beacon_period = KuS 648 *//* 64ms = 010000 */ 649 if (local->fw_ver == 0x55) { 650 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms, 651 sizeof(struct b4_startup_params)); 652 /* Translate sane kus input values to old build 4/5 format */ 653 /* i = hop time in uS truncated to 3 bytes */ 654 i = (hop_dwell * 1024) & 0xffffff; 655 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff; 656 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff; 657 local->sparm.b4.a_beacon_period[0] = 0; 658 local->sparm.b4.a_beacon_period[1] = 659 ((beacon_period / hop_dwell) - 1) & 0xff; 660 local->sparm.b4.a_curr_country_code = country; 661 local->sparm.b4.a_hop_pattern_length = 662 hop_pattern_length[(int)country] - 1; 663 if (bc) { 664 local->sparm.b4.a_ack_timeout = 0x50; 665 local->sparm.b4.a_sifs = 0x3f; 666 } 667 } else { /* Version 5 uses real kus values */ 668 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms, 669 sizeof(struct b5_startup_params)); 670 671 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff; 672 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff; 673 local->sparm.b5.a_beacon_period[0] = 674 (beacon_period >> 8) & 0xff; 675 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff; 676 if (psm) 677 local->sparm.b5.a_power_mgt_state = 1; 678 local->sparm.b5.a_curr_country_code = country; 679 local->sparm.b5.a_hop_pattern_length = 680 hop_pattern_length[(int)country]; 681 } 682 683 local->sparm.b4.a_network_type = net_type & 0x01; 684 local->sparm.b4.a_acting_as_ap_status = TYPE_STA; 685 686 if (essid != NULL) 687 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE); 688} /* init_startup_params */ 689 690/*===========================================================================*/ 691static void verify_dl_startup(u_long data) 692{ 693 ray_dev_t *local = (ray_dev_t *) data; 694 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs; 695 UCHAR status; 696 struct pcmcia_device *link = local->finder; 697 698 if (!(pcmcia_dev_present(link))) { 699 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n"); 700 return; 701 } 702#if 0 703 { 704 int i; 705 printk(KERN_DEBUG 706 "verify_dl_startup parameters sent via ccs %d:\n", 707 local->dl_param_ccs); 708 for (i = 0; i < sizeof(struct b5_startup_params); i++) { 709 printk(" %2x", 710 (unsigned int)readb(local->sram + 711 HOST_TO_ECF_BASE + i)); 712 } 713 printk("\n"); 714 } 715#endif 716 717 status = readb(&pccs->buffer_status); 718 if (status != CCS_BUFFER_FREE) { 719 printk(KERN_INFO 720 "Download startup params failed. Status = %d\n", 721 status); 722 local->card_status = CARD_DL_PARAM_ERROR; 723 return; 724 } 725 if (local->sparm.b4.a_network_type == ADHOC) 726 start_net((u_long) local); 727 else 728 join_net((u_long) local); 729} /* end verify_dl_startup */ 730 731/*===========================================================================*/ 732/* Command card to start a network */ 733static void start_net(u_long data) 734{ 735 ray_dev_t *local = (ray_dev_t *) data; 736 struct ccs __iomem *pccs; 737 int ccsindex; 738 struct pcmcia_device *link = local->finder; 739 if (!(pcmcia_dev_present(link))) { 740 dev_dbg(&link->dev, "ray_cs start_net - device not present\n"); 741 return; 742 } 743 /* Fill in the CCS fields for the ECF */ 744 if ((ccsindex = get_free_ccs(local)) < 0) 745 return; 746 pccs = ccs_base(local) + ccsindex; 747 writeb(CCS_START_NETWORK, &pccs->cmd); 748 writeb(0, &pccs->var.start_network.update_param); 749 /* Interrupt the firmware to process the command */ 750 if (interrupt_ecf(local, ccsindex)) { 751 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n"); 752 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 753 return; 754 } 755 local->card_status = CARD_DOING_ACQ; 756} /* end start_net */ 757 758/*===========================================================================*/ 759/* Command card to join a network */ 760static void join_net(u_long data) 761{ 762 ray_dev_t *local = (ray_dev_t *) data; 763 764 struct ccs __iomem *pccs; 765 int ccsindex; 766 struct pcmcia_device *link = local->finder; 767 768 if (!(pcmcia_dev_present(link))) { 769 dev_dbg(&link->dev, "ray_cs join_net - device not present\n"); 770 return; 771 } 772 /* Fill in the CCS fields for the ECF */ 773 if ((ccsindex = get_free_ccs(local)) < 0) 774 return; 775 pccs = ccs_base(local) + ccsindex; 776 writeb(CCS_JOIN_NETWORK, &pccs->cmd); 777 writeb(0, &pccs->var.join_network.update_param); 778 writeb(0, &pccs->var.join_network.net_initiated); 779 /* Interrupt the firmware to process the command */ 780 if (interrupt_ecf(local, ccsindex)) { 781 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n"); 782 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 783 return; 784 } 785 local->card_status = CARD_DOING_ACQ; 786} 787 788/*============================================================================ 789 After a card is removed, ray_release() will unregister the net 790 device, and release the PCMCIA configuration. If the device is 791 still open, this will be postponed until it is closed. 792=============================================================================*/ 793static void ray_release(struct pcmcia_device *link) 794{ 795 struct net_device *dev = link->priv; 796 ray_dev_t *local = netdev_priv(dev); 797 int i; 798 799 dev_dbg(&link->dev, "ray_release\n"); 800 801 del_timer(&local->timer); 802 803 iounmap(local->sram); 804 iounmap(local->rmem); 805 iounmap(local->amem); 806 /* Do bother checking to see if these succeed or not */ 807 i = pcmcia_release_window(link, local->amem_handle); 808 if (i != 0) 809 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i); 810 i = pcmcia_release_window(link, local->rmem_handle); 811 if (i != 0) 812 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i); 813 pcmcia_disable_device(link); 814 815 dev_dbg(&link->dev, "ray_release ending\n"); 816} 817 818static int ray_suspend(struct pcmcia_device *link) 819{ 820 struct net_device *dev = link->priv; 821 822 if (link->open) 823 netif_device_detach(dev); 824 825 return 0; 826} 827 828static int ray_resume(struct pcmcia_device *link) 829{ 830 struct net_device *dev = link->priv; 831 832 if (link->open) { 833 ray_reset(dev); 834 netif_device_attach(dev); 835 } 836 837 return 0; 838} 839 840/*===========================================================================*/ 841static int ray_dev_init(struct net_device *dev) 842{ 843#ifdef RAY_IMMEDIATE_INIT 844 int i; 845#endif /* RAY_IMMEDIATE_INIT */ 846 ray_dev_t *local = netdev_priv(dev); 847 struct pcmcia_device *link = local->finder; 848 849 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev); 850 if (!(pcmcia_dev_present(link))) { 851 dev_dbg(&link->dev, "ray_dev_init - device not present\n"); 852 return -1; 853 } 854#ifdef RAY_IMMEDIATE_INIT 855 /* Download startup parameters */ 856 if ((i = dl_startup_params(dev)) < 0) { 857 printk(KERN_INFO "ray_dev_init dl_startup_params failed - " 858 "returns 0x%x\n", i); 859 return -1; 860 } 861#else /* RAY_IMMEDIATE_INIT */ 862 /* Postpone the card init so that we can still configure the card, 863 * for example using the Wireless Extensions. The init will happen 864 * in ray_open() - Jean II */ 865 dev_dbg(&link->dev, 866 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n", 867 local->card_status); 868#endif /* RAY_IMMEDIATE_INIT */ 869 870 /* copy mac and broadcast addresses to linux device */ 871 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN); 872 memset(dev->broadcast, 0xff, ETH_ALEN); 873 874 dev_dbg(&link->dev, "ray_dev_init ending\n"); 875 return 0; 876} 877 878/*===========================================================================*/ 879static int ray_dev_config(struct net_device *dev, struct ifmap *map) 880{ 881 ray_dev_t *local = netdev_priv(dev); 882 struct pcmcia_device *link = local->finder; 883 /* Dummy routine to satisfy device structure */ 884 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map); 885 if (!(pcmcia_dev_present(link))) { 886 dev_dbg(&link->dev, "ray_dev_config - device not present\n"); 887 return -1; 888 } 889 890 return 0; 891} 892 893/*===========================================================================*/ 894static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb, 895 struct net_device *dev) 896{ 897 ray_dev_t *local = netdev_priv(dev); 898 struct pcmcia_device *link = local->finder; 899 short length = skb->len; 900 901 if (!pcmcia_dev_present(link)) { 902 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n"); 903 dev_kfree_skb(skb); 904 return NETDEV_TX_OK; 905 } 906 907 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev); 908 if (local->authentication_state == NEED_TO_AUTH) { 909 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n"); 910 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) { 911 local->authentication_state = AUTHENTICATED; 912 netif_stop_queue(dev); 913 return NETDEV_TX_BUSY; 914 } 915 } 916 917 if (length < ETH_ZLEN) { 918 if (skb_padto(skb, ETH_ZLEN)) 919 return NETDEV_TX_OK; 920 length = ETH_ZLEN; 921 } 922 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) { 923 case XMIT_NO_CCS: 924 case XMIT_NEED_AUTH: 925 netif_stop_queue(dev); 926 return NETDEV_TX_BUSY; 927 case XMIT_NO_INTR: 928 case XMIT_MSG_BAD: 929 case XMIT_OK: 930 default: 931 dev_kfree_skb(skb); 932 } 933 934 return NETDEV_TX_OK; 935} /* ray_dev_start_xmit */ 936 937/*===========================================================================*/ 938static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, 939 UCHAR msg_type) 940{ 941 ray_dev_t *local = netdev_priv(dev); 942 struct ccs __iomem *pccs; 943 int ccsindex; 944 int offset; 945 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */ 946 short int addr; /* Address of xmit buffer in card space */ 947 948 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev); 949 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) { 950 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n", 951 len); 952 return XMIT_MSG_BAD; 953 } 954 switch (ccsindex = get_free_tx_ccs(local)) { 955 case ECCSBUSY: 956 pr_debug("ray_hw_xmit tx_ccs table busy\n"); 957 case ECCSFULL: 958 pr_debug("ray_hw_xmit No free tx ccs\n"); 959 case ECARDGONE: 960 netif_stop_queue(dev); 961 return XMIT_NO_CCS; 962 default: 963 break; 964 } 965 addr = TX_BUF_BASE + (ccsindex << 11); 966 967 if (msg_type == DATA_TYPE) { 968 local->stats.tx_bytes += len; 969 local->stats.tx_packets++; 970 } 971 972 ptx = local->sram + addr; 973 974 ray_build_header(local, ptx, msg_type, data); 975 if (translate) { 976 offset = translate_frame(local, ptx, data, len); 977 } else { /* Encapsulate frame */ 978 /* TBD TIB length will move address of ptx->var */ 979 memcpy_toio(&ptx->var, data, len); 980 offset = 0; 981 } 982 983 /* fill in the CCS */ 984 pccs = ccs_base(local) + ccsindex; 985 len += TX_HEADER_LENGTH + offset; 986 writeb(CCS_TX_REQUEST, &pccs->cmd); 987 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]); 988 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]); 989 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]); 990 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]); 991/* TBD still need psm_cam? */ 992 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode); 993 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate); 994 writeb(0, &pccs->var.tx_request.antenna); 995 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n", 996 local->net_default_tx_rate); 997 998 /* Interrupt the firmware to process the command */ 999 if (interrupt_ecf(local, ccsindex)) { 1000 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n"); 1001/* TBD very inefficient to copy packet to buffer, and then not 1002 send it, but the alternative is to queue the messages and that 1003 won't be done for a while. Maybe set tbusy until a CCS is free? 1004*/ 1005 writeb(CCS_BUFFER_FREE, &pccs->buffer_status); 1006 return XMIT_NO_INTR; 1007 } 1008 return XMIT_OK; 1009} /* end ray_hw_xmit */ 1010 1011/*===========================================================================*/ 1012static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, 1013 unsigned char *data, int len) 1014{ 1015 __be16 proto = ((struct ethhdr *)data)->h_proto; 1016 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */ 1017 pr_debug("ray_cs translate_frame DIX II\n"); 1018 /* Copy LLC header to card buffer */ 1019 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc)); 1020 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc), 1021 (UCHAR *) &proto, 2); 1022 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) { 1023 /* This is the selective translation table, only 2 entries */ 1024 writeb(0xf8, 1025 &((struct snaphdr_t __iomem *)ptx->var)->org[3]); 1026 } 1027 /* Copy body of ethernet packet without ethernet header */ 1028 memcpy_toio((void __iomem *)&ptx->var + 1029 sizeof(struct snaphdr_t), data + ETH_HLEN, 1030 len - ETH_HLEN); 1031 return (int)sizeof(struct snaphdr_t) - ETH_HLEN; 1032 } else { /* already 802 type, and proto is length */ 1033 pr_debug("ray_cs translate_frame 802\n"); 1034 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */ 1035 pr_debug("ray_cs translate_frame evil IPX\n"); 1036 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN); 1037 return 0 - ETH_HLEN; 1038 } 1039 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN); 1040 return 0 - ETH_HLEN; 1041 } 1042 /* TBD do other frame types */ 1043} /* end translate_frame */ 1044 1045/*===========================================================================*/ 1046static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, 1047 UCHAR msg_type, unsigned char *data) 1048{ 1049 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1); 1050/*** IEEE 802.11 Address field assignments ************* 1051 TODS FROMDS addr_1 addr_2 addr_3 addr_4 1052Adhoc 0 0 dest src (terminal) BSSID N/A 1053AP to Terminal 0 1 dest AP(BSSID) source N/A 1054Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A 1055AP to AP 1 1 dest AP src AP dest source 1056*******************************************************/ 1057 if (local->net_type == ADHOC) { 1058 writeb(0, &ptx->mac.frame_ctl_2); 1059 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, 1060 2 * ADDRLEN); 1061 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); 1062 } else { /* infrastructure */ 1063 1064 if (local->sparm.b4.a_acting_as_ap_status) { 1065 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2); 1066 memcpy_toio(ptx->mac.addr_1, 1067 ((struct ethhdr *)data)->h_dest, ADDRLEN); 1068 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6); 1069 memcpy_toio(ptx->mac.addr_3, 1070 ((struct ethhdr *)data)->h_source, ADDRLEN); 1071 } else { /* Terminal */ 1072 1073 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2); 1074 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN); 1075 memcpy_toio(ptx->mac.addr_2, 1076 ((struct ethhdr *)data)->h_source, ADDRLEN); 1077 memcpy_toio(ptx->mac.addr_3, 1078 ((struct ethhdr *)data)->h_dest, ADDRLEN); 1079 } 1080 } 1081} /* end encapsulate_frame */ 1082 1083/*===========================================================================*/ 1084 1085static void netdev_get_drvinfo(struct net_device *dev, 1086 struct ethtool_drvinfo *info) 1087{ 1088 strcpy(info->driver, "ray_cs"); 1089} 1090 1091static const struct ethtool_ops netdev_ethtool_ops = { 1092 .get_drvinfo = netdev_get_drvinfo, 1093}; 1094 1095/*====================================================================*/ 1096 1097/*------------------------------------------------------------------*/ 1098/* 1099 * Wireless Handler : get protocol name 1100 */ 1101static int ray_get_name(struct net_device *dev, struct iw_request_info *info, 1102 union iwreq_data *wrqu, char *extra) 1103{ 1104 strcpy(wrqu->name, "IEEE 802.11-FH"); 1105 return 0; 1106} 1107 1108/*------------------------------------------------------------------*/ 1109/* 1110 * Wireless Handler : set frequency 1111 */ 1112static int ray_set_freq(struct net_device *dev, struct iw_request_info *info, 1113 union iwreq_data *wrqu, char *extra) 1114{ 1115 ray_dev_t *local = netdev_priv(dev); 1116 int err = -EINPROGRESS; /* Call commit handler */ 1117 1118 /* Reject if card is already initialised */ 1119 if (local->card_status != CARD_AWAITING_PARAM) 1120 return -EBUSY; 1121 1122 /* Setting by channel number */ 1123 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0)) 1124 err = -EOPNOTSUPP; 1125 else 1126 local->sparm.b5.a_hop_pattern = wrqu->freq.m; 1127 1128 return err; 1129} 1130 1131/*------------------------------------------------------------------*/ 1132/* 1133 * Wireless Handler : get frequency 1134 */ 1135static int ray_get_freq(struct net_device *dev, struct iw_request_info *info, 1136 union iwreq_data *wrqu, char *extra) 1137{ 1138 ray_dev_t *local = netdev_priv(dev); 1139 1140 wrqu->freq.m = local->sparm.b5.a_hop_pattern; 1141 wrqu->freq.e = 0; 1142 return 0; 1143} 1144 1145/*------------------------------------------------------------------*/ 1146/* 1147 * Wireless Handler : set ESSID 1148 */ 1149static int ray_set_essid(struct net_device *dev, struct iw_request_info *info, 1150 union iwreq_data *wrqu, char *extra) 1151{ 1152 ray_dev_t *local = netdev_priv(dev); 1153 1154 /* Reject if card is already initialised */ 1155 if (local->card_status != CARD_AWAITING_PARAM) 1156 return -EBUSY; 1157 1158 /* Check if we asked for `any' */ 1159 if (wrqu->essid.flags == 0) 1160 /* Corey : can you do that ? */ 1161 return -EOPNOTSUPP; 1162 1163 /* Check the size of the string */ 1164 if (wrqu->essid.length > IW_ESSID_MAX_SIZE) 1165 return -E2BIG; 1166 1167 /* Set the ESSID in the card */ 1168 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE); 1169 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length); 1170 1171 return -EINPROGRESS; /* Call commit handler */ 1172} 1173 1174/*------------------------------------------------------------------*/ 1175/* 1176 * Wireless Handler : get ESSID 1177 */ 1178static int ray_get_essid(struct net_device *dev, struct iw_request_info *info, 1179 union iwreq_data *wrqu, char *extra) 1180{ 1181 ray_dev_t *local = netdev_priv(dev); 1182 1183 /* Get the essid that was set */ 1184 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE); 1185 1186 /* Push it out ! */ 1187 wrqu->essid.length = strlen(extra); 1188 wrqu->essid.flags = 1; /* active */ 1189 1190 return 0; 1191} 1192 1193/*------------------------------------------------------------------*/ 1194/* 1195 * Wireless Handler : get AP address 1196 */ 1197static int ray_get_wap(struct net_device *dev, struct iw_request_info *info, 1198 union iwreq_data *wrqu, char *extra) 1199{ 1200 ray_dev_t *local = netdev_priv(dev); 1201 1202 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN); 1203 wrqu->ap_addr.sa_family = ARPHRD_ETHER; 1204 1205 return 0; 1206} 1207 1208/*------------------------------------------------------------------*/ 1209/* 1210 * Wireless Handler : set Bit-Rate 1211 */ 1212static int ray_set_rate(struct net_device *dev, struct iw_request_info *info, 1213 union iwreq_data *wrqu, char *extra) 1214{ 1215 ray_dev_t *local = netdev_priv(dev); 1216 1217 /* Reject if card is already initialised */ 1218 if (local->card_status != CARD_AWAITING_PARAM) 1219 return -EBUSY; 1220 1221 /* Check if rate is in range */ 1222 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000)) 1223 return -EINVAL; 1224 1225 /* Hack for 1.5 Mb/s instead of 2 Mb/s */ 1226 if ((local->fw_ver == 0x55) && /* Please check */ 1227 (wrqu->bitrate.value == 2000000)) 1228 local->net_default_tx_rate = 3; 1229 else 1230 local->net_default_tx_rate = wrqu->bitrate.value / 500000; 1231 1232 return 0; 1233} 1234 1235/*------------------------------------------------------------------*/ 1236/* 1237 * Wireless Handler : get Bit-Rate 1238 */ 1239static int ray_get_rate(struct net_device *dev, struct iw_request_info *info, 1240 union iwreq_data *wrqu, char *extra) 1241{ 1242 ray_dev_t *local = netdev_priv(dev); 1243 1244 if (local->net_default_tx_rate == 3) 1245 wrqu->bitrate.value = 2000000; /* Hum... */ 1246 else 1247 wrqu->bitrate.value = local->net_default_tx_rate * 500000; 1248 wrqu->bitrate.fixed = 0; /* We are in auto mode */ 1249 1250 return 0; 1251} 1252 1253/*------------------------------------------------------------------*/ 1254/* 1255 * Wireless Handler : set RTS threshold 1256 */ 1257static int ray_set_rts(struct net_device *dev, struct iw_request_info *info, 1258 union iwreq_data *wrqu, char *extra) 1259{ 1260 ray_dev_t *local = netdev_priv(dev); 1261 int rthr = wrqu->rts.value; 1262 1263 /* Reject if card is already initialised */ 1264 if (local->card_status != CARD_AWAITING_PARAM) 1265 return -EBUSY; 1266 1267 /* if(wrq->u.rts.fixed == 0) we should complain */ 1268 if (wrqu->rts.disabled) 1269 rthr = 32767; 1270 else { 1271 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */ 1272 return -EINVAL; 1273 } 1274 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF; 1275 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF; 1276 1277 return -EINPROGRESS; /* Call commit handler */ 1278} 1279 1280/*------------------------------------------------------------------*/ 1281/* 1282 * Wireless Handler : get RTS threshold 1283 */ 1284static int ray_get_rts(struct net_device *dev, struct iw_request_info *info, 1285 union iwreq_data *wrqu, char *extra) 1286{ 1287 ray_dev_t *local = netdev_priv(dev); 1288 1289 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8) 1290 + local->sparm.b5.a_rts_threshold[1]; 1291 wrqu->rts.disabled = (wrqu->rts.value == 32767); 1292 wrqu->rts.fixed = 1; 1293 1294 return 0; 1295} 1296 1297/*------------------------------------------------------------------*/ 1298/* 1299 * Wireless Handler : set Fragmentation threshold 1300 */ 1301static int ray_set_frag(struct net_device *dev, struct iw_request_info *info, 1302 union iwreq_data *wrqu, char *extra) 1303{ 1304 ray_dev_t *local = netdev_priv(dev); 1305 int fthr = wrqu->frag.value; 1306 1307 /* Reject if card is already initialised */ 1308 if (local->card_status != CARD_AWAITING_PARAM) 1309 return -EBUSY; 1310 1311 /* if(wrq->u.frag.fixed == 0) should complain */ 1312 if (wrqu->frag.disabled) 1313 fthr = 32767; 1314 else { 1315 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */ 1316 return -EINVAL; 1317 } 1318 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF; 1319 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF; 1320 1321 return -EINPROGRESS; /* Call commit handler */ 1322} 1323 1324/*------------------------------------------------------------------*/ 1325/* 1326 * Wireless Handler : get Fragmentation threshold 1327 */ 1328static int ray_get_frag(struct net_device *dev, struct iw_request_info *info, 1329 union iwreq_data *wrqu, char *extra) 1330{ 1331 ray_dev_t *local = netdev_priv(dev); 1332 1333 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8) 1334 + local->sparm.b5.a_frag_threshold[1]; 1335 wrqu->frag.disabled = (wrqu->frag.value == 32767); 1336 wrqu->frag.fixed = 1; 1337 1338 return 0; 1339} 1340 1341/*------------------------------------------------------------------*/ 1342/* 1343 * Wireless Handler : set Mode of Operation 1344 */ 1345static int ray_set_mode(struct net_device *dev, struct iw_request_info *info, 1346 union iwreq_data *wrqu, char *extra) 1347{ 1348 ray_dev_t *local = netdev_priv(dev); 1349 int err = -EINPROGRESS; /* Call commit handler */ 1350 char card_mode = 1; 1351 1352 /* Reject if card is already initialised */ 1353 if (local->card_status != CARD_AWAITING_PARAM) 1354 return -EBUSY; 1355 1356 switch (wrqu->mode) { 1357 case IW_MODE_ADHOC: 1358 card_mode = 0; 1359 /* Fall through */ 1360 case IW_MODE_INFRA: 1361 local->sparm.b5.a_network_type = card_mode; 1362 break; 1363 default: 1364 err = -EINVAL; 1365 } 1366 1367 return err; 1368} 1369 1370/*------------------------------------------------------------------*/ 1371/* 1372 * Wireless Handler : get Mode of Operation 1373 */ 1374static int ray_get_mode(struct net_device *dev, struct iw_request_info *info, 1375 union iwreq_data *wrqu, char *extra) 1376{ 1377 ray_dev_t *local = netdev_priv(dev); 1378 1379 if (local->sparm.b5.a_network_type) 1380 wrqu->mode = IW_MODE_INFRA; 1381 else 1382 wrqu->mode = IW_MODE_ADHOC; 1383 1384 return 0; 1385} 1386 1387/*------------------------------------------------------------------*/ 1388/* 1389 * Wireless Handler : get range info 1390 */ 1391static int ray_get_range(struct net_device *dev, struct iw_request_info *info, 1392 union iwreq_data *wrqu, char *extra) 1393{ 1394 struct iw_range *range = (struct iw_range *)extra; 1395 1396 memset(range, 0, sizeof(struct iw_range)); 1397 1398 /* Set the length (very important for backward compatibility) */ 1399 wrqu->data.length = sizeof(struct iw_range); 1400 1401 /* Set the Wireless Extension versions */ 1402 range->we_version_compiled = WIRELESS_EXT; 1403 range->we_version_source = 9; 1404 1405 /* Set information in the range struct */ 1406 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */ 1407 range->num_channels = hop_pattern_length[(int)country]; 1408 range->num_frequency = 0; 1409 range->max_qual.qual = 0; 1410 range->max_qual.level = 255; /* What's the correct value ? */ 1411 range->max_qual.noise = 255; /* Idem */ 1412 range->num_bitrates = 2; 1413 range->bitrate[0] = 1000000; /* 1 Mb/s */ 1414 range->bitrate[1] = 2000000; /* 2 Mb/s */ 1415 return 0; 1416} 1417 1418/*------------------------------------------------------------------*/ 1419/* 1420 * Wireless Private Handler : set framing mode 1421 */ 1422static int ray_set_framing(struct net_device *dev, struct iw_request_info *info, 1423 union iwreq_data *wrqu, char *extra) 1424{ 1425 translate = *(extra); /* Set framing mode */ 1426 1427 return 0; 1428} 1429 1430/*------------------------------------------------------------------*/ 1431/* 1432 * Wireless Private Handler : get framing mode 1433 */ 1434static int ray_get_framing(struct net_device *dev, struct iw_request_info *info, 1435 union iwreq_data *wrqu, char *extra) 1436{ 1437 *(extra) = translate; 1438 1439 return 0; 1440} 1441 1442/*------------------------------------------------------------------*/ 1443/* 1444 * Wireless Private Handler : get country 1445 */ 1446static int ray_get_country(struct net_device *dev, struct iw_request_info *info, 1447 union iwreq_data *wrqu, char *extra) 1448{ 1449 *(extra) = country; 1450 1451 return 0; 1452} 1453 1454/*------------------------------------------------------------------*/ 1455/* 1456 * Commit handler : called after a bunch of SET operations 1457 */ 1458static int ray_commit(struct net_device *dev, struct iw_request_info *info, 1459 union iwreq_data *wrqu, char *extra) 1460{ 1461 return 0; 1462} 1463 1464/*------------------------------------------------------------------*/ 1465/* 1466 * Stats handler : return Wireless Stats 1467 */ 1468static iw_stats *ray_get_wireless_stats(struct net_device *dev) 1469{ 1470 ray_dev_t *local = netdev_priv(dev); 1471 struct pcmcia_device *link = local->finder; 1472 struct status __iomem *p = local->sram + STATUS_BASE; 1473 1474 local->wstats.status = local->card_status; 1475#ifdef WIRELESS_SPY 1476 if ((local->spy_data.spy_number > 0) 1477 && (local->sparm.b5.a_network_type == 0)) { 1478 /* Get it from the first node in spy list */ 1479 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual; 1480 local->wstats.qual.level = local->spy_data.spy_stat[0].level; 1481 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise; 1482 local->wstats.qual.updated = 1483 local->spy_data.spy_stat[0].updated; 1484 } 1485#endif /* WIRELESS_SPY */ 1486 1487 if (pcmcia_dev_present(link)) { 1488 local->wstats.qual.noise = readb(&p->rxnoise); 1489 local->wstats.qual.updated |= 4; 1490 } 1491 1492 return &local->wstats; 1493} /* end ray_get_wireless_stats */ 1494 1495/*------------------------------------------------------------------*/ 1496/* 1497 * Structures to export the Wireless Handlers 1498 */ 1499 1500static const iw_handler ray_handler[] = { 1501 IW_HANDLER(SIOCSIWCOMMIT, ray_commit), 1502 IW_HANDLER(SIOCGIWNAME, ray_get_name), 1503 IW_HANDLER(SIOCSIWFREQ, ray_set_freq), 1504 IW_HANDLER(SIOCGIWFREQ, ray_get_freq), 1505 IW_HANDLER(SIOCSIWMODE, ray_set_mode), 1506 IW_HANDLER(SIOCGIWMODE, ray_get_mode), 1507 IW_HANDLER(SIOCGIWRANGE, ray_get_range), 1508#ifdef WIRELESS_SPY 1509 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), 1510 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), 1511 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), 1512 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), 1513#endif /* WIRELESS_SPY */ 1514 IW_HANDLER(SIOCGIWAP, ray_get_wap), 1515 IW_HANDLER(SIOCSIWESSID, ray_set_essid), 1516 IW_HANDLER(SIOCGIWESSID, ray_get_essid), 1517 IW_HANDLER(SIOCSIWRATE, ray_set_rate), 1518 IW_HANDLER(SIOCGIWRATE, ray_get_rate), 1519 IW_HANDLER(SIOCSIWRTS, ray_set_rts), 1520 IW_HANDLER(SIOCGIWRTS, ray_get_rts), 1521 IW_HANDLER(SIOCSIWFRAG, ray_set_frag), 1522 IW_HANDLER(SIOCGIWFRAG, ray_get_frag), 1523}; 1524 1525#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */ 1526#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */ 1527#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */ 1528 1529static const iw_handler ray_private_handler[] = { 1530 [0] = ray_set_framing, 1531 [1] = ray_get_framing, 1532 [3] = ray_get_country, 1533}; 1534 1535static const struct iw_priv_args ray_private_args[] = { 1536/* cmd, set_args, get_args, name */ 1537 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, 1538 "set_framing"}, 1539 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 1540 "get_framing"}, 1541 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 1542 "get_country"}, 1543}; 1544 1545static const struct iw_handler_def ray_handler_def = { 1546 .num_standard = ARRAY_SIZE(ray_handler), 1547 .num_private = ARRAY_SIZE(ray_private_handler), 1548 .num_private_args = ARRAY_SIZE(ray_private_args), 1549 .standard = ray_handler, 1550 .private = ray_private_handler, 1551 .private_args = ray_private_args, 1552 .get_wireless_stats = ray_get_wireless_stats, 1553}; 1554 1555/*===========================================================================*/ 1556static int ray_open(struct net_device *dev) 1557{ 1558 ray_dev_t *local = netdev_priv(dev); 1559 struct pcmcia_device *link; 1560 link = local->finder; 1561 1562 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name); 1563 1564 if (link->open == 0) 1565 local->num_multi = 0; 1566 link->open++; 1567 1568 /* If the card is not started, time to start it ! - Jean II */ 1569 if (local->card_status == CARD_AWAITING_PARAM) { 1570 int i; 1571 1572 dev_dbg(&link->dev, "ray_open: doing init now !\n"); 1573 1574 /* Download startup parameters */ 1575 if ((i = dl_startup_params(dev)) < 0) { 1576 printk(KERN_INFO 1577 "ray_dev_init dl_startup_params failed - " 1578 "returns 0x%x\n", i); 1579 return -1; 1580 } 1581 } 1582 1583 if (sniffer) 1584 netif_stop_queue(dev); 1585 else 1586 netif_start_queue(dev); 1587 1588 dev_dbg(&link->dev, "ray_open ending\n"); 1589 return 0; 1590} /* end ray_open */ 1591 1592/*===========================================================================*/ 1593static int ray_dev_close(struct net_device *dev) 1594{ 1595 ray_dev_t *local = netdev_priv(dev); 1596 struct pcmcia_device *link; 1597 link = local->finder; 1598 1599 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name); 1600 1601 link->open--; 1602 netif_stop_queue(dev); 1603 1604 /* In here, we should stop the hardware (stop card from beeing active) 1605 * and set local->card_status to CARD_AWAITING_PARAM, so that while the 1606 * card is closed we can chage its configuration. 1607 * Probably also need a COR reset to get sane state - Jean II */ 1608 1609 return 0; 1610} /* end ray_dev_close */ 1611 1612/*===========================================================================*/ 1613static void ray_reset(struct net_device *dev) 1614{ 1615 pr_debug("ray_reset entered\n"); 1616} 1617 1618/*===========================================================================*/ 1619/* Cause a firmware interrupt if it is ready for one */ 1620/* Return nonzero if not ready */ 1621static int interrupt_ecf(ray_dev_t *local, int ccs) 1622{ 1623 int i = 50; 1624 struct pcmcia_device *link = local->finder; 1625 1626 if (!(pcmcia_dev_present(link))) { 1627 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n"); 1628 return -1; 1629 } 1630 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs); 1631 1632 while (i && 1633 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & 1634 ECF_INTR_SET)) 1635 i--; 1636 if (i == 0) { 1637 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n"); 1638 return -1; 1639 } 1640 /* Fill the mailbox, then kick the card */ 1641 writeb(ccs, local->sram + SCB_BASE); 1642 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET); 1643 return 0; 1644} /* interrupt_ecf */ 1645 1646/*===========================================================================*/ 1647/* Get next free transmit CCS */ 1648/* Return - index of current tx ccs */ 1649static int get_free_tx_ccs(ray_dev_t *local) 1650{ 1651 int i; 1652 struct ccs __iomem *pccs = ccs_base(local); 1653 struct pcmcia_device *link = local->finder; 1654 1655 if (!(pcmcia_dev_present(link))) { 1656 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n"); 1657 return ECARDGONE; 1658 } 1659 1660 if (test_and_set_bit(0, &local->tx_ccs_lock)) { 1661 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n"); 1662 return ECCSBUSY; 1663 } 1664 1665 for (i = 0; i < NUMBER_OF_TX_CCS; i++) { 1666 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) { 1667 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status); 1668 writeb(CCS_END_LIST, &(pccs + i)->link); 1669 local->tx_ccs_lock = 0; 1670 return i; 1671 } 1672 } 1673 local->tx_ccs_lock = 0; 1674 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n"); 1675 return ECCSFULL; 1676} /* get_free_tx_ccs */ 1677 1678/*===========================================================================*/ 1679/* Get next free CCS */ 1680/* Return - index of current ccs */ 1681static int get_free_ccs(ray_dev_t *local) 1682{ 1683 int i; 1684 struct ccs __iomem *pccs = ccs_base(local); 1685 struct pcmcia_device *link = local->finder; 1686 1687 if (!(pcmcia_dev_present(link))) { 1688 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n"); 1689 return ECARDGONE; 1690 } 1691 if (test_and_set_bit(0, &local->ccs_lock)) { 1692 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n"); 1693 return ECCSBUSY; 1694 } 1695 1696 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) { 1697 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) { 1698 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status); 1699 writeb(CCS_END_LIST, &(pccs + i)->link); 1700 local->ccs_lock = 0; 1701 return i; 1702 } 1703 } 1704 local->ccs_lock = 0; 1705 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n"); 1706 return ECCSFULL; 1707} /* get_free_ccs */ 1708 1709/*===========================================================================*/ 1710static void authenticate_timeout(u_long data) 1711{ 1712 ray_dev_t *local = (ray_dev_t *) data; 1713 del_timer(&local->timer); 1714 printk(KERN_INFO "ray_cs Authentication with access point failed" 1715 " - timeout\n"); 1716 join_net((u_long) local); 1717} 1718 1719/*===========================================================================*/ 1720static int asc_to_int(char a) 1721{ 1722 if (a < '0') 1723 return -1; 1724 if (a <= '9') 1725 return (a - '0'); 1726 if (a < 'A') 1727 return -1; 1728 if (a <= 'F') 1729 return (10 + a - 'A'); 1730 if (a < 'a') 1731 return -1; 1732 if (a <= 'f') 1733 return (10 + a - 'a'); 1734 return -1; 1735} 1736 1737/*===========================================================================*/ 1738static int parse_addr(char *in_str, UCHAR *out) 1739{ 1740 int len; 1741 int i, j, k; 1742 int status; 1743 1744 if (in_str == NULL) 1745 return 0; 1746 if ((len = strlen(in_str)) < 2) 1747 return 0; 1748 memset(out, 0, ADDRLEN); 1749 1750 status = 1; 1751 j = len - 1; 1752 if (j > 12) 1753 j = 12; 1754 i = 5; 1755 1756 while (j > 0) { 1757 if ((k = asc_to_int(in_str[j--])) != -1) 1758 out[i] = k; 1759 else 1760 return 0; 1761 1762 if (j == 0) 1763 break; 1764 if ((k = asc_to_int(in_str[j--])) != -1) 1765 out[i] += k << 4; 1766 else 1767 return 0; 1768 if (!i--) 1769 break; 1770 } 1771 return status; 1772} 1773 1774/*===========================================================================*/ 1775static struct net_device_stats *ray_get_stats(struct net_device *dev) 1776{ 1777 ray_dev_t *local = netdev_priv(dev); 1778 struct pcmcia_device *link = local->finder; 1779 struct status __iomem *p = local->sram + STATUS_BASE; 1780 if (!(pcmcia_dev_present(link))) { 1781 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n"); 1782 return &local->stats; 1783 } 1784 if (readb(&p->mrx_overflow_for_host)) { 1785 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow)); 1786 writeb(0, &p->mrx_overflow); 1787 writeb(0, &p->mrx_overflow_for_host); 1788 } 1789 if (readb(&p->mrx_checksum_error_for_host)) { 1790 local->stats.rx_crc_errors += 1791 swab16(readw(&p->mrx_checksum_error)); 1792 writeb(0, &p->mrx_checksum_error); 1793 writeb(0, &p->mrx_checksum_error_for_host); 1794 } 1795 if (readb(&p->rx_hec_error_for_host)) { 1796 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error)); 1797 writeb(0, &p->rx_hec_error); 1798 writeb(0, &p->rx_hec_error_for_host); 1799 } 1800 return &local->stats; 1801} 1802 1803/*===========================================================================*/ 1804static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, 1805 int len) 1806{ 1807 ray_dev_t *local = netdev_priv(dev); 1808 struct pcmcia_device *link = local->finder; 1809 int ccsindex; 1810 int i; 1811 struct ccs __iomem *pccs; 1812 1813 if (!(pcmcia_dev_present(link))) { 1814 dev_dbg(&link->dev, "ray_update_parm - device not present\n"); 1815 return; 1816 } 1817 1818 if ((ccsindex = get_free_ccs(local)) < 0) { 1819 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n"); 1820 return; 1821 } 1822 pccs = ccs_base(local) + ccsindex; 1823 writeb(CCS_UPDATE_PARAMS, &pccs->cmd); 1824 writeb(objid, &pccs->var.update_param.object_id); 1825 writeb(1, &pccs->var.update_param.number_objects); 1826 writeb(0, &pccs->var.update_param.failure_cause); 1827 for (i = 0; i < len; i++) { 1828 writeb(value[i], local->sram + HOST_TO_ECF_BASE); 1829 } 1830 /* Interrupt the firmware to process the command */ 1831 if (interrupt_ecf(local, ccsindex)) { 1832 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n"); 1833 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 1834 } 1835} 1836 1837/*===========================================================================*/ 1838static void ray_update_multi_list(struct net_device *dev, int all) 1839{ 1840 int ccsindex; 1841 struct ccs __iomem *pccs; 1842 ray_dev_t *local = netdev_priv(dev); 1843 struct pcmcia_device *link = local->finder; 1844 void __iomem *p = local->sram + HOST_TO_ECF_BASE; 1845 1846 if (!(pcmcia_dev_present(link))) { 1847 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n"); 1848 return; 1849 } else 1850 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev); 1851 if ((ccsindex = get_free_ccs(local)) < 0) { 1852 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n"); 1853 return; 1854 } 1855 pccs = ccs_base(local) + ccsindex; 1856 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd); 1857 1858 if (all) { 1859 writeb(0xff, &pccs->var); 1860 local->num_multi = 0xff; 1861 } else { 1862 struct netdev_hw_addr *ha; 1863 int i = 0; 1864 1865 /* Copy the kernel's list of MC addresses to card */ 1866 netdev_for_each_mc_addr(ha, dev) { 1867 memcpy_toio(p, ha->addr, ETH_ALEN); 1868 dev_dbg(&link->dev, 1869 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n", 1870 ha->addr[0], ha->addr[1], 1871 ha->addr[2], ha->addr[3], 1872 ha->addr[4], ha->addr[5]); 1873 p += ETH_ALEN; 1874 i++; 1875 } 1876 if (i > 256 / ADDRLEN) 1877 i = 256 / ADDRLEN; 1878 writeb((UCHAR) i, &pccs->var); 1879 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i); 1880 /* Interrupt the firmware to process the command */ 1881 local->num_multi = i; 1882 } 1883 if (interrupt_ecf(local, ccsindex)) { 1884 dev_dbg(&link->dev, 1885 "ray_cs update_multi failed - ECF not ready for intr\n"); 1886 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 1887 } 1888} /* end ray_update_multi_list */ 1889 1890/*===========================================================================*/ 1891static void set_multicast_list(struct net_device *dev) 1892{ 1893 ray_dev_t *local = netdev_priv(dev); 1894 UCHAR promisc; 1895 1896 pr_debug("ray_cs set_multicast_list(%p)\n", dev); 1897 1898 if (dev->flags & IFF_PROMISC) { 1899 if (local->sparm.b5.a_promiscuous_mode == 0) { 1900 pr_debug("ray_cs set_multicast_list promisc on\n"); 1901 local->sparm.b5.a_promiscuous_mode = 1; 1902 promisc = 1; 1903 ray_update_parm(dev, OBJID_promiscuous_mode, 1904 &promisc, sizeof(promisc)); 1905 } 1906 } else { 1907 if (local->sparm.b5.a_promiscuous_mode == 1) { 1908 pr_debug("ray_cs set_multicast_list promisc off\n"); 1909 local->sparm.b5.a_promiscuous_mode = 0; 1910 promisc = 0; 1911 ray_update_parm(dev, OBJID_promiscuous_mode, 1912 &promisc, sizeof(promisc)); 1913 } 1914 } 1915 1916 if (dev->flags & IFF_ALLMULTI) 1917 ray_update_multi_list(dev, 1); 1918 else { 1919 if (local->num_multi != netdev_mc_count(dev)) 1920 ray_update_multi_list(dev, 0); 1921 } 1922} /* end set_multicast_list */ 1923 1924/*============================================================================= 1925 * All routines below here are run at interrupt time. 1926=============================================================================*/ 1927static irqreturn_t ray_interrupt(int irq, void *dev_id) 1928{ 1929 struct net_device *dev = (struct net_device *)dev_id; 1930 struct pcmcia_device *link; 1931 ray_dev_t *local; 1932 struct ccs __iomem *pccs; 1933 struct rcs __iomem *prcs; 1934 UCHAR rcsindex; 1935 UCHAR tmp; 1936 UCHAR cmd; 1937 UCHAR status; 1938 1939 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */ 1940 return IRQ_NONE; 1941 1942 pr_debug("ray_cs: interrupt for *dev=%p\n", dev); 1943 1944 local = netdev_priv(dev); 1945 link = (struct pcmcia_device *)local->finder; 1946 if (!pcmcia_dev_present(link)) { 1947 pr_debug( 1948 "ray_cs interrupt from device not present or suspended.\n"); 1949 return IRQ_NONE; 1950 } 1951 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index); 1952 1953 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { 1954 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex); 1955 clear_interrupt(local); 1956 return IRQ_HANDLED; 1957 } 1958 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */ 1959 pccs = ccs_base(local) + rcsindex; 1960 cmd = readb(&pccs->cmd); 1961 status = readb(&pccs->buffer_status); 1962 switch (cmd) { 1963 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */ 1964 del_timer(&local->timer); 1965 if (status == CCS_COMMAND_COMPLETE) { 1966 dev_dbg(&link->dev, 1967 "ray_cs interrupt download_startup_parameters OK\n"); 1968 } else { 1969 dev_dbg(&link->dev, 1970 "ray_cs interrupt download_startup_parameters fail\n"); 1971 } 1972 break; 1973 case CCS_UPDATE_PARAMS: 1974 dev_dbg(&link->dev, "ray_cs interrupt update params done\n"); 1975 if (status != CCS_COMMAND_COMPLETE) { 1976 tmp = 1977 readb(&pccs->var.update_param. 1978 failure_cause); 1979 dev_dbg(&link->dev, 1980 "ray_cs interrupt update params failed - reason %d\n", 1981 tmp); 1982 } 1983 break; 1984 case CCS_REPORT_PARAMS: 1985 dev_dbg(&link->dev, "ray_cs interrupt report params done\n"); 1986 break; 1987 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */ 1988 dev_dbg(&link->dev, 1989 "ray_cs interrupt CCS Update Multicast List done\n"); 1990 break; 1991 case CCS_UPDATE_POWER_SAVINGS_MODE: 1992 dev_dbg(&link->dev, 1993 "ray_cs interrupt update power save mode done\n"); 1994 break; 1995 case CCS_START_NETWORK: 1996 case CCS_JOIN_NETWORK: 1997 if (status == CCS_COMMAND_COMPLETE) { 1998 if (readb 1999 (&pccs->var.start_network.net_initiated) == 2000 1) { 2001 dev_dbg(&link->dev, 2002 "ray_cs interrupt network \"%s\" started\n", 2003 local->sparm.b4.a_current_ess_id); 2004 } else { 2005 dev_dbg(&link->dev, 2006 "ray_cs interrupt network \"%s\" joined\n", 2007 local->sparm.b4.a_current_ess_id); 2008 } 2009 memcpy_fromio(&local->bss_id, 2010 pccs->var.start_network.bssid, 2011 ADDRLEN); 2012 2013 if (local->fw_ver == 0x55) 2014 local->net_default_tx_rate = 3; 2015 else 2016 local->net_default_tx_rate = 2017 readb(&pccs->var.start_network. 2018 net_default_tx_rate); 2019 local->encryption = 2020 readb(&pccs->var.start_network.encryption); 2021 if (!sniffer && (local->net_type == INFRA) 2022 && !(local->sparm.b4.a_acting_as_ap_status)) { 2023 authenticate(local); 2024 } 2025 local->card_status = CARD_ACQ_COMPLETE; 2026 } else { 2027 local->card_status = CARD_ACQ_FAILED; 2028 2029 del_timer(&local->timer); 2030 local->timer.expires = jiffies + HZ * 5; 2031 local->timer.data = (long)local; 2032 if (status == CCS_START_NETWORK) { 2033 dev_dbg(&link->dev, 2034 "ray_cs interrupt network \"%s\" start failed\n", 2035 local->sparm.b4.a_current_ess_id); 2036 local->timer.function = &start_net; 2037 } else { 2038 dev_dbg(&link->dev, 2039 "ray_cs interrupt network \"%s\" join failed\n", 2040 local->sparm.b4.a_current_ess_id); 2041 local->timer.function = &join_net; 2042 } 2043 add_timer(&local->timer); 2044 } 2045 break; 2046 case CCS_START_ASSOCIATION: 2047 if (status == CCS_COMMAND_COMPLETE) { 2048 local->card_status = CARD_ASSOC_COMPLETE; 2049 dev_dbg(&link->dev, "ray_cs association successful\n"); 2050 } else { 2051 dev_dbg(&link->dev, "ray_cs association failed,\n"); 2052 local->card_status = CARD_ASSOC_FAILED; 2053 join_net((u_long) local); 2054 } 2055 break; 2056 case CCS_TX_REQUEST: 2057 if (status == CCS_COMMAND_COMPLETE) { 2058 dev_dbg(&link->dev, 2059 "ray_cs interrupt tx request complete\n"); 2060 } else { 2061 dev_dbg(&link->dev, 2062 "ray_cs interrupt tx request failed\n"); 2063 } 2064 if (!sniffer) 2065 netif_start_queue(dev); 2066 netif_wake_queue(dev); 2067 break; 2068 case CCS_TEST_MEMORY: 2069 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n"); 2070 break; 2071 case CCS_SHUTDOWN: 2072 dev_dbg(&link->dev, 2073 "ray_cs interrupt Unexpected CCS returned - Shutdown\n"); 2074 break; 2075 case CCS_DUMP_MEMORY: 2076 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n"); 2077 break; 2078 case CCS_START_TIMER: 2079 dev_dbg(&link->dev, 2080 "ray_cs interrupt DING - raylink timer expired\n"); 2081 break; 2082 default: 2083 dev_dbg(&link->dev, 2084 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n", 2085 rcsindex, cmd); 2086 } 2087 writeb(CCS_BUFFER_FREE, &pccs->buffer_status); 2088 } else { /* It's an RCS */ 2089 2090 prcs = rcs_base(local) + rcsindex; 2091 2092 switch (readb(&prcs->interrupt_id)) { 2093 case PROCESS_RX_PACKET: 2094 ray_rx(dev, local, prcs); 2095 break; 2096 case REJOIN_NET_COMPLETE: 2097 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n"); 2098 local->card_status = CARD_ACQ_COMPLETE; 2099 /* do we need to clear tx buffers CCS's? */ 2100 if (local->sparm.b4.a_network_type == ADHOC) { 2101 if (!sniffer) 2102 netif_start_queue(dev); 2103 } else { 2104 memcpy_fromio(&local->bss_id, 2105 prcs->var.rejoin_net_complete. 2106 bssid, ADDRLEN); 2107 dev_dbg(&link->dev, 2108 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n", 2109 local->bss_id[0], local->bss_id[1], 2110 local->bss_id[2], local->bss_id[3], 2111 local->bss_id[4], local->bss_id[5]); 2112 if (!sniffer) 2113 authenticate(local); 2114 } 2115 break; 2116 case ROAMING_INITIATED: 2117 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n"); 2118 netif_stop_queue(dev); 2119 local->card_status = CARD_DOING_ACQ; 2120 break; 2121 case JAPAN_CALL_SIGN_RXD: 2122 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n"); 2123 break; 2124 default: 2125 dev_dbg(&link->dev, 2126 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n", 2127 rcsindex, 2128 (unsigned int)readb(&prcs->interrupt_id)); 2129 break; 2130 } 2131 writeb(CCS_BUFFER_FREE, &prcs->buffer_status); 2132 } 2133 clear_interrupt(local); 2134 return IRQ_HANDLED; 2135} /* ray_interrupt */ 2136 2137/*===========================================================================*/ 2138static void ray_rx(struct net_device *dev, ray_dev_t *local, 2139 struct rcs __iomem *prcs) 2140{ 2141 int rx_len; 2142 unsigned int pkt_addr; 2143 void __iomem *pmsg; 2144 pr_debug("ray_rx process rx packet\n"); 2145 2146 /* Calculate address of packet within Rx buffer */ 2147 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8) 2148 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END; 2149 /* Length of first packet fragment */ 2150 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8) 2151 + readb(&prcs->var.rx_packet.rx_data_length[1]); 2152 2153 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev); 2154 pmsg = local->rmem + pkt_addr; 2155 switch (readb(pmsg)) { 2156 case DATA_TYPE: 2157 pr_debug("ray_rx data type\n"); 2158 rx_data(dev, prcs, pkt_addr, rx_len); 2159 break; 2160 case AUTHENTIC_TYPE: 2161 pr_debug("ray_rx authentic type\n"); 2162 if (sniffer) 2163 rx_data(dev, prcs, pkt_addr, rx_len); 2164 else 2165 rx_authenticate(local, prcs, pkt_addr, rx_len); 2166 break; 2167 case DEAUTHENTIC_TYPE: 2168 pr_debug("ray_rx deauth type\n"); 2169 if (sniffer) 2170 rx_data(dev, prcs, pkt_addr, rx_len); 2171 else 2172 rx_deauthenticate(local, prcs, pkt_addr, rx_len); 2173 break; 2174 case NULL_MSG_TYPE: 2175 pr_debug("ray_cs rx NULL msg\n"); 2176 break; 2177 case BEACON_TYPE: 2178 pr_debug("ray_rx beacon type\n"); 2179 if (sniffer) 2180 rx_data(dev, prcs, pkt_addr, rx_len); 2181 2182 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr, 2183 rx_len < sizeof(struct beacon_rx) ? 2184 rx_len : sizeof(struct beacon_rx)); 2185 2186 local->beacon_rxed = 1; 2187 /* Get the statistics so the card counters never overflow */ 2188 ray_get_stats(dev); 2189 break; 2190 default: 2191 pr_debug("ray_cs unknown pkt type %2x\n", 2192 (unsigned int)readb(pmsg)); 2193 break; 2194 } 2195 2196} /* end ray_rx */ 2197 2198/*===========================================================================*/ 2199static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, 2200 unsigned int pkt_addr, int rx_len) 2201{ 2202 struct sk_buff *skb = NULL; 2203 struct rcs __iomem *prcslink = prcs; 2204 ray_dev_t *local = netdev_priv(dev); 2205 UCHAR *rx_ptr; 2206 int total_len; 2207 int tmp; 2208#ifdef WIRELESS_SPY 2209 int siglev = local->last_rsl; 2210 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */ 2211#endif 2212 2213 if (!sniffer) { 2214 if (translate) { 2215/* TBD length needs fixing for translated header */ 2216 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || 2217 rx_len > 2218 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + 2219 FCS_LEN)) { 2220 pr_debug( 2221 "ray_cs invalid packet length %d received\n", 2222 rx_len); 2223 return; 2224 } 2225 } else { /* encapsulated ethernet */ 2226 2227 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || 2228 rx_len > 2229 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + 2230 FCS_LEN)) { 2231 pr_debug( 2232 "ray_cs invalid packet length %d received\n", 2233 rx_len); 2234 return; 2235 } 2236 } 2237 } 2238 pr_debug("ray_cs rx_data packet\n"); 2239 /* If fragmented packet, verify sizes of fragments add up */ 2240 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { 2241 pr_debug("ray_cs rx'ed fragment\n"); 2242 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8) 2243 + readb(&prcs->var.rx_packet.totalpacketlength[1]); 2244 total_len = tmp; 2245 prcslink = prcs; 2246 do { 2247 tmp -= 2248 (readb(&prcslink->var.rx_packet.rx_data_length[0]) 2249 << 8) 2250 + readb(&prcslink->var.rx_packet.rx_data_length[1]); 2251 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) 2252 == 0xFF || tmp < 0) 2253 break; 2254 prcslink = rcs_base(local) 2255 + readb(&prcslink->link_field); 2256 } while (1); 2257 2258 if (tmp < 0) { 2259 pr_debug( 2260 "ray_cs rx_data fragment lengths don't add up\n"); 2261 local->stats.rx_dropped++; 2262 release_frag_chain(local, prcs); 2263 return; 2264 } 2265 } else { /* Single unfragmented packet */ 2266 total_len = rx_len; 2267 } 2268 2269 skb = dev_alloc_skb(total_len + 5); 2270 if (skb == NULL) { 2271 pr_debug("ray_cs rx_data could not allocate skb\n"); 2272 local->stats.rx_dropped++; 2273 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) 2274 release_frag_chain(local, prcs); 2275 return; 2276 } 2277 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */ 2278 2279 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len, 2280 rx_len); 2281 2282/************************/ 2283 /* Reserve enough room for the whole damn packet. */ 2284 rx_ptr = skb_put(skb, total_len); 2285 /* Copy the whole packet to sk_buff */ 2286 rx_ptr += 2287 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len); 2288 /* Get source address */ 2289#ifdef WIRELESS_SPY 2290 skb_copy_from_linear_data_offset(skb, 2291 offsetof(struct mac_header, addr_2), 2292 linksrcaddr, ETH_ALEN); 2293#endif 2294 /* Now, deal with encapsulation/translation/sniffer */ 2295 if (!sniffer) { 2296 if (!translate) { 2297 /* Encapsulated ethernet, so just lop off 802.11 MAC header */ 2298/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */ 2299 skb_pull(skb, RX_MAC_HEADER_LENGTH); 2300 } else { 2301 /* Do translation */ 2302 untranslate(local, skb, total_len); 2303 } 2304 } else { /* sniffer mode, so just pass whole packet */ 2305 }; 2306 2307/************************/ 2308 /* Now pick up the rest of the fragments if any */ 2309 tmp = 17; 2310 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { 2311 prcslink = prcs; 2312 pr_debug("ray_cs rx_data in fragment loop\n"); 2313 do { 2314 prcslink = rcs_base(local) 2315 + 2316 readb(&prcslink->var.rx_packet.next_frag_rcs_index); 2317 rx_len = 2318 ((readb(&prcslink->var.rx_packet.rx_data_length[0]) 2319 << 8) 2320 + 2321 readb(&prcslink->var.rx_packet.rx_data_length[1])) 2322 & RX_BUFF_END; 2323 pkt_addr = 2324 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << 2325 8) 2326 + readb(&prcslink->var.rx_packet.rx_data_ptr[1])) 2327 & RX_BUFF_END; 2328 2329 rx_ptr += 2330 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len); 2331 2332 } while (tmp-- && 2333 readb(&prcslink->var.rx_packet.next_frag_rcs_index) != 2334 0xFF); 2335 release_frag_chain(local, prcs); 2336 } 2337 2338 skb->protocol = eth_type_trans(skb, dev); 2339 netif_rx(skb); 2340 local->stats.rx_packets++; 2341 local->stats.rx_bytes += total_len; 2342 2343 /* Gather signal strength per address */ 2344#ifdef WIRELESS_SPY 2345 /* For the Access Point or the node having started the ad-hoc net 2346 * note : ad-hoc work only in some specific configurations, but we 2347 * kludge in ray_get_wireless_stats... */ 2348 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) { 2349 /* Update statistics */ 2350 /*local->wstats.qual.qual = none ? */ 2351 local->wstats.qual.level = siglev; 2352 /*local->wstats.qual.noise = none ? */ 2353 local->wstats.qual.updated = 0x2; 2354 } 2355 /* Now, update the spy stuff */ 2356 { 2357 struct iw_quality wstats; 2358 wstats.level = siglev; 2359 /* wstats.noise = none ? */ 2360 /* wstats.qual = none ? */ 2361 wstats.updated = 0x2; 2362 /* Update spy records */ 2363 wireless_spy_update(dev, linksrcaddr, &wstats); 2364 } 2365#endif /* WIRELESS_SPY */ 2366} /* end rx_data */ 2367 2368/*===========================================================================*/ 2369static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len) 2370{ 2371 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH); 2372 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data; 2373 __be16 type = *(__be16 *) psnap->ethertype; 2374 int delta; 2375 struct ethhdr *peth; 2376 UCHAR srcaddr[ADDRLEN]; 2377 UCHAR destaddr[ADDRLEN]; 2378 static UCHAR org_bridge[3] = { 0, 0, 0xf8 }; 2379 static UCHAR org_1042[3] = { 0, 0, 0 }; 2380 2381 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN); 2382 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN); 2383 2384#if 0 2385 if { 2386 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ", 2387 DUMP_PREFIX_NONE, 16, 1, 2388 skb->data, 64, true); 2389 printk(KERN_DEBUG 2390 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n", 2391 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl, 2392 psnap->org[0], psnap->org[1], psnap->org[2]); 2393 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data); 2394 } 2395#endif 2396 2397 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) { 2398 /* not a snap type so leave it alone */ 2399 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n", 2400 psnap->dsap, psnap->ssap, psnap->ctrl); 2401 2402 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; 2403 peth = (struct ethhdr *)(skb->data + delta); 2404 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH); 2405 } else { /* Its a SNAP */ 2406 if (memcmp(psnap->org, org_bridge, 3) == 0) { 2407 /* EtherII and nuke the LLC */ 2408 pr_debug("ray_cs untranslate Bridge encap\n"); 2409 delta = RX_MAC_HEADER_LENGTH 2410 + sizeof(struct snaphdr_t) - ETH_HLEN; 2411 peth = (struct ethhdr *)(skb->data + delta); 2412 peth->h_proto = type; 2413 } else if (memcmp(psnap->org, org_1042, 3) == 0) { 2414 switch (ntohs(type)) { 2415 case ETH_P_IPX: 2416 case ETH_P_AARP: 2417 pr_debug("ray_cs untranslate RFC IPX/AARP\n"); 2418 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; 2419 peth = (struct ethhdr *)(skb->data + delta); 2420 peth->h_proto = 2421 htons(len - RX_MAC_HEADER_LENGTH); 2422 break; 2423 default: 2424 pr_debug("ray_cs untranslate RFC default\n"); 2425 delta = RX_MAC_HEADER_LENGTH + 2426 sizeof(struct snaphdr_t) - ETH_HLEN; 2427 peth = (struct ethhdr *)(skb->data + delta); 2428 peth->h_proto = type; 2429 break; 2430 } 2431 } else { 2432 printk("ray_cs untranslate very confused by packet\n"); 2433 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; 2434 peth = (struct ethhdr *)(skb->data + delta); 2435 peth->h_proto = type; 2436 } 2437 } 2438/* TBD reserve skb_reserve(skb, delta); */ 2439 skb_pull(skb, delta); 2440 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta, 2441 skb->data); 2442 memcpy(peth->h_dest, destaddr, ADDRLEN); 2443 memcpy(peth->h_source, srcaddr, ADDRLEN); 2444#if 0 2445 { 2446 int i; 2447 printk(KERN_DEBUG "skb->data after untranslate:"); 2448 for (i = 0; i < 64; i++) 2449 printk("%02x ", skb->data[i]); 2450 printk("\n"); 2451 } 2452#endif 2453} /* end untranslate */ 2454 2455/*===========================================================================*/ 2456/* Copy data from circular receive buffer to PC memory. 2457 * dest = destination address in PC memory 2458 * pkt_addr = source address in receive buffer 2459 * len = length of packet to copy 2460 */ 2461static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, 2462 int length) 2463{ 2464 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1); 2465 if (wrap_bytes <= 0) { 2466 memcpy_fromio(dest, local->rmem + pkt_addr, length); 2467 } else { /* Packet wrapped in circular buffer */ 2468 2469 memcpy_fromio(dest, local->rmem + pkt_addr, 2470 length - wrap_bytes); 2471 memcpy_fromio(dest + length - wrap_bytes, local->rmem, 2472 wrap_bytes); 2473 } 2474 return length; 2475} 2476 2477/*===========================================================================*/ 2478static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs) 2479{ 2480 struct rcs __iomem *prcslink = prcs; 2481 int tmp = 17; 2482 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index); 2483 2484 while (tmp--) { 2485 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); 2486 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { 2487 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n", 2488 rcsindex); 2489 break; 2490 } 2491 prcslink = rcs_base(local) + rcsindex; 2492 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index); 2493 } 2494 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); 2495} 2496 2497/*===========================================================================*/ 2498static void authenticate(ray_dev_t *local) 2499{ 2500 struct pcmcia_device *link = local->finder; 2501 dev_dbg(&link->dev, "ray_cs Starting authentication.\n"); 2502 if (!(pcmcia_dev_present(link))) { 2503 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n"); 2504 return; 2505 } 2506 2507 del_timer(&local->timer); 2508 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) { 2509 local->timer.function = &join_net; 2510 } else { 2511 local->timer.function = &authenticate_timeout; 2512 } 2513 local->timer.expires = jiffies + HZ * 2; 2514 local->timer.data = (long)local; 2515 add_timer(&local->timer); 2516 local->authentication_state = AWAITING_RESPONSE; 2517} /* end authenticate */ 2518 2519/*===========================================================================*/ 2520static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, 2521 unsigned int pkt_addr, int rx_len) 2522{ 2523 UCHAR buff[256]; 2524 struct rx_msg *msg = (struct rx_msg *)buff; 2525 2526 del_timer(&local->timer); 2527 2528 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); 2529 /* if we are trying to get authenticated */ 2530 if (local->sparm.b4.a_network_type == ADHOC) { 2531 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n", 2532 msg->var[0], msg->var[1], msg->var[2], msg->var[3], 2533 msg->var[4], msg->var[5]); 2534 if (msg->var[2] == 1) { 2535 pr_debug("ray_cs Sending authentication response.\n"); 2536 if (!build_auth_frame 2537 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) { 2538 local->authentication_state = NEED_TO_AUTH; 2539 memcpy(local->auth_id, msg->mac.addr_2, 2540 ADDRLEN); 2541 } 2542 } 2543 } else { /* Infrastructure network */ 2544 2545 if (local->authentication_state == AWAITING_RESPONSE) { 2546 /* Verify authentication sequence #2 and success */ 2547 if (msg->var[2] == 2) { 2548 if ((msg->var[3] | msg->var[4]) == 0) { 2549 pr_debug("Authentication successful\n"); 2550 local->card_status = CARD_AUTH_COMPLETE; 2551 associate(local); 2552 local->authentication_state = 2553 AUTHENTICATED; 2554 } else { 2555 pr_debug("Authentication refused\n"); 2556 local->card_status = CARD_AUTH_REFUSED; 2557 join_net((u_long) local); 2558 local->authentication_state = 2559 UNAUTHENTICATED; 2560 } 2561 } 2562 } 2563 } 2564 2565} /* end rx_authenticate */ 2566 2567/*===========================================================================*/ 2568static void associate(ray_dev_t *local) 2569{ 2570 struct ccs __iomem *pccs; 2571 struct pcmcia_device *link = local->finder; 2572 struct net_device *dev = link->priv; 2573 int ccsindex; 2574 if (!(pcmcia_dev_present(link))) { 2575 dev_dbg(&link->dev, "ray_cs associate - device not present\n"); 2576 return; 2577 } 2578 /* If no tx buffers available, return */ 2579 if ((ccsindex = get_free_ccs(local)) < 0) { 2580/* TBD should never be here but... what if we are? */ 2581 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n"); 2582 return; 2583 } 2584 dev_dbg(&link->dev, "ray_cs Starting association with access point\n"); 2585 pccs = ccs_base(local) + ccsindex; 2586 /* fill in the CCS */ 2587 writeb(CCS_START_ASSOCIATION, &pccs->cmd); 2588 /* Interrupt the firmware to process the command */ 2589 if (interrupt_ecf(local, ccsindex)) { 2590 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n"); 2591 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 2592 2593 del_timer(&local->timer); 2594 local->timer.expires = jiffies + HZ * 2; 2595 local->timer.data = (long)local; 2596 local->timer.function = &join_net; 2597 add_timer(&local->timer); 2598 local->card_status = CARD_ASSOC_FAILED; 2599 return; 2600 } 2601 if (!sniffer) 2602 netif_start_queue(dev); 2603 2604} /* end associate */ 2605 2606/*===========================================================================*/ 2607static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs, 2608 unsigned int pkt_addr, int rx_len) 2609{ 2610/* UCHAR buff[256]; 2611 struct rx_msg *msg = (struct rx_msg *)buff; 2612*/ 2613 pr_debug("Deauthentication frame received\n"); 2614 local->authentication_state = UNAUTHENTICATED; 2615 /* Need to reauthenticate or rejoin depending on reason code */ 2616/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); 2617 */ 2618} 2619 2620/*===========================================================================*/ 2621static void clear_interrupt(ray_dev_t *local) 2622{ 2623 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET); 2624} 2625 2626/*===========================================================================*/ 2627#ifdef CONFIG_PROC_FS 2628#define MAXDATA (PAGE_SIZE - 80) 2629 2630static char *card_status[] = { 2631 "Card inserted - uninitialized", /* 0 */ 2632 "Card not downloaded", /* 1 */ 2633 "Waiting for download parameters", /* 2 */ 2634 "Card doing acquisition", /* 3 */ 2635 "Acquisition complete", /* 4 */ 2636 "Authentication complete", /* 5 */ 2637 "Association complete", /* 6 */ 2638 "???", "???", "???", "???", /* 7 8 9 10 undefined */ 2639 "Card init error", /* 11 */ 2640 "Download parameters error", /* 12 */ 2641 "???", /* 13 */ 2642 "Acquisition failed", /* 14 */ 2643 "Authentication refused", /* 15 */ 2644 "Association failed" /* 16 */ 2645}; 2646 2647static char *nettype[] = { "Adhoc", "Infra " }; 2648static char *framing[] = { "Encapsulation", "Translation" } 2649 2650; 2651/*===========================================================================*/ 2652static int ray_cs_proc_show(struct seq_file *m, void *v) 2653{ 2654/* Print current values which are not available via other means 2655 * eg ifconfig 2656 */ 2657 int i; 2658 struct pcmcia_device *link; 2659 struct net_device *dev; 2660 ray_dev_t *local; 2661 UCHAR *p; 2662 struct freq_hop_element *pfh; 2663 UCHAR c[33]; 2664 2665 link = this_device; 2666 if (!link) 2667 return 0; 2668 dev = (struct net_device *)link->priv; 2669 if (!dev) 2670 return 0; 2671 local = netdev_priv(dev); 2672 if (!local) 2673 return 0; 2674 2675 seq_puts(m, "Raylink Wireless LAN driver status\n"); 2676 seq_printf(m, "%s\n", rcsid); 2677 /* build 4 does not report version, and field is 0x55 after memtest */ 2678 seq_puts(m, "Firmware version = "); 2679 if (local->fw_ver == 0x55) 2680 seq_puts(m, "4 - Use dump_cis for more details\n"); 2681 else 2682 seq_printf(m, "%2d.%02d.%02d\n", 2683 local->fw_ver, local->fw_bld, local->fw_var); 2684 2685 for (i = 0; i < 32; i++) 2686 c[i] = local->sparm.b5.a_current_ess_id[i]; 2687 c[32] = 0; 2688 seq_printf(m, "%s network ESSID = \"%s\"\n", 2689 nettype[local->sparm.b5.a_network_type], c); 2690 2691 p = local->bss_id; 2692 seq_printf(m, "BSSID = %pM\n", p); 2693 2694 seq_printf(m, "Country code = %d\n", 2695 local->sparm.b5.a_curr_country_code); 2696 2697 i = local->card_status; 2698 if (i < 0) 2699 i = 10; 2700 if (i > 16) 2701 i = 10; 2702 seq_printf(m, "Card status = %s\n", card_status[i]); 2703 2704 seq_printf(m, "Framing mode = %s\n", framing[translate]); 2705 2706 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl); 2707 2708 if (local->beacon_rxed) { 2709 /* Pull some fields out of last beacon received */ 2710 seq_printf(m, "Beacon Interval = %d Kus\n", 2711 local->last_bcn.beacon_intvl[0] 2712 + 256 * local->last_bcn.beacon_intvl[1]); 2713 2714 p = local->last_bcn.elements; 2715 if (p[0] == C_ESSID_ELEMENT_ID) 2716 p += p[1] + 2; 2717 else { 2718 seq_printf(m, 2719 "Parse beacon failed at essid element id = %d\n", 2720 p[0]); 2721 return 0; 2722 } 2723 2724 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) { 2725 seq_puts(m, "Supported rate codes = "); 2726 for (i = 2; i < p[1] + 2; i++) 2727 seq_printf(m, "0x%02x ", p[i]); 2728 seq_putc(m, '\n'); 2729 p += p[1] + 2; 2730 } else { 2731 seq_puts(m, "Parse beacon failed at rates element\n"); 2732 return 0; 2733 } 2734 2735 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) { 2736 pfh = (struct freq_hop_element *)p; 2737 seq_printf(m, "Hop dwell = %d Kus\n", 2738 pfh->dwell_time[0] + 2739 256 * pfh->dwell_time[1]); 2740 seq_printf(m, "Hop set = %d\n", 2741 pfh->hop_set); 2742 seq_printf(m, "Hop pattern = %d\n", 2743 pfh->hop_pattern); 2744 seq_printf(m, "Hop index = %d\n", 2745 pfh->hop_index); 2746 p += p[1] + 2; 2747 } else { 2748 seq_puts(m, 2749 "Parse beacon failed at FH param element\n"); 2750 return 0; 2751 } 2752 } else { 2753 seq_puts(m, "No beacons received\n"); 2754 } 2755 return 0; 2756} 2757 2758static int ray_cs_proc_open(struct inode *inode, struct file *file) 2759{ 2760 return single_open(file, ray_cs_proc_show, NULL); 2761} 2762 2763static const struct file_operations ray_cs_proc_fops = { 2764 .owner = THIS_MODULE, 2765 .open = ray_cs_proc_open, 2766 .read = seq_read, 2767 .llseek = seq_lseek, 2768 .release = single_release, 2769}; 2770#endif 2771/*===========================================================================*/ 2772static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type) 2773{ 2774 int addr; 2775 struct ccs __iomem *pccs; 2776 struct tx_msg __iomem *ptx; 2777 int ccsindex; 2778 2779 /* If no tx buffers available, return */ 2780 if ((ccsindex = get_free_tx_ccs(local)) < 0) { 2781 pr_debug("ray_cs send authenticate - No free tx ccs\n"); 2782 return -1; 2783 } 2784 2785 pccs = ccs_base(local) + ccsindex; 2786 2787 /* Address in card space */ 2788 addr = TX_BUF_BASE + (ccsindex << 11); 2789 /* fill in the CCS */ 2790 writeb(CCS_TX_REQUEST, &pccs->cmd); 2791 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr); 2792 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1); 2793 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length); 2794 writeb(TX_AUTHENTICATE_LENGTH_LSB, 2795 pccs->var.tx_request.tx_data_length + 1); 2796 writeb(0, &pccs->var.tx_request.pow_sav_mode); 2797 2798 ptx = local->sram + addr; 2799 /* fill in the mac header */ 2800 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1); 2801 writeb(0, &ptx->mac.frame_ctl_2); 2802 2803 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN); 2804 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN); 2805 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); 2806 2807 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */ 2808 memset_io(ptx->var, 0, 6); 2809 writeb(auth_type & 0xff, ptx->var + 2); 2810 2811 /* Interrupt the firmware to process the command */ 2812 if (interrupt_ecf(local, ccsindex)) { 2813 pr_debug( 2814 "ray_cs send authentication request failed - ECF not ready for intr\n"); 2815 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); 2816 return -1; 2817 } 2818 return 0; 2819} /* End build_auth_frame */ 2820 2821/*===========================================================================*/ 2822#ifdef CONFIG_PROC_FS 2823static ssize_t ray_cs_essid_proc_write(struct file *file, 2824 const char __user *buffer, size_t count, loff_t *pos) 2825{ 2826 static char proc_essid[33]; 2827 unsigned int len = count; 2828 2829 if (len > 32) 2830 len = 32; 2831 memset(proc_essid, 0, 33); 2832 if (copy_from_user(proc_essid, buffer, len)) 2833 return -EFAULT; 2834 essid = proc_essid; 2835 return count; 2836} 2837 2838static const struct file_operations ray_cs_essid_proc_fops = { 2839 .owner = THIS_MODULE, 2840 .write = ray_cs_essid_proc_write, 2841}; 2842 2843static ssize_t int_proc_write(struct file *file, const char __user *buffer, 2844 size_t count, loff_t *pos) 2845{ 2846 static char proc_number[10]; 2847 char *p; 2848 int nr, len; 2849 2850 if (!count) 2851 return 0; 2852 2853 if (count > 9) 2854 return -EINVAL; 2855 if (copy_from_user(proc_number, buffer, count)) 2856 return -EFAULT; 2857 p = proc_number; 2858 nr = 0; 2859 len = count; 2860 do { 2861 unsigned int c = *p - '0'; 2862 if (c > 9) 2863 return -EINVAL; 2864 nr = nr * 10 + c; 2865 p++; 2866 } while (--len); 2867 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr; 2868 return count; 2869} 2870 2871static const struct file_operations int_proc_fops = { 2872 .owner = THIS_MODULE, 2873 .write = int_proc_write, 2874}; 2875#endif 2876 2877static struct pcmcia_device_id ray_ids[] = { 2878 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000), 2879 PCMCIA_DEVICE_NULL, 2880}; 2881 2882MODULE_DEVICE_TABLE(pcmcia, ray_ids); 2883 2884static struct pcmcia_driver ray_driver = { 2885 .owner = THIS_MODULE, 2886 .drv = { 2887 .name = "ray_cs", 2888 }, 2889 .probe = ray_probe, 2890 .remove = ray_detach, 2891 .id_table = ray_ids, 2892 .suspend = ray_suspend, 2893 .resume = ray_resume, 2894}; 2895 2896static int __init init_ray_cs(void) 2897{ 2898 int rc; 2899 2900 pr_debug("%s\n", rcsid); 2901 rc = pcmcia_register_driver(&ray_driver); 2902 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n", 2903 rc); 2904 2905#ifdef CONFIG_PROC_FS 2906 proc_mkdir("driver/ray_cs", NULL); 2907 2908 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops); 2909 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops); 2910 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type); 2911 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate); 2912#endif 2913 if (translate != 0) 2914 translate = 1; 2915 return 0; 2916} /* init_ray_cs */ 2917 2918/*===========================================================================*/ 2919 2920static void __exit exit_ray_cs(void) 2921{ 2922 pr_debug("ray_cs: cleanup_module\n"); 2923 2924#ifdef CONFIG_PROC_FS 2925 remove_proc_entry("driver/ray_cs/ray_cs", NULL); 2926 remove_proc_entry("driver/ray_cs/essid", NULL); 2927 remove_proc_entry("driver/ray_cs/net_type", NULL); 2928 remove_proc_entry("driver/ray_cs/translate", NULL); 2929 remove_proc_entry("driver/ray_cs", NULL); 2930#endif 2931 2932 pcmcia_unregister_driver(&ray_driver); 2933} /* exit_ray_cs */ 2934 2935module_init(init_ray_cs); 2936module_exit(exit_ray_cs); 2937 2938/*===========================================================================*/