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