blob: 24ea4b4d487e4b6e218293c74f96483b3d162a88 [file] [log] [blame]
David Kilroy712a4342009-02-04 23:05:55 +00001/* Encapsulate basic setting changes and retrieval on Hermes hardware
2 *
3 * See copyright notice in main.c
4 */
5#include <linux/kernel.h>
David Kilroya3f47b92009-06-18 23:21:21 +01006#include <linux/device.h>
David Kilroy712a4342009-02-04 23:05:55 +00007#include <linux/if_arp.h>
8#include <linux/ieee80211.h>
9#include <linux/wireless.h>
David Kilroy5217c572009-06-18 23:21:32 +010010#include <net/cfg80211.h>
David Kilroy712a4342009-02-04 23:05:55 +000011#include "hermes.h"
12#include "hermes_rid.h"
13#include "orinoco.h"
14
15#include "hw.h"
16
David Kilroya2d1a422009-06-18 23:21:18 +010017#define SYMBOL_MAX_VER_LEN (14)
18
David Kilroy42a51b92009-06-18 23:21:20 +010019/* Symbol firmware has a bug allocating buffers larger than this */
20#define TX_NICBUF_SIZE_BUG 1585
21
David Kilroy712a4342009-02-04 23:05:55 +000022/********************************************************************/
23/* Data tables */
24/********************************************************************/
25
26/* This tables gives the actual meanings of the bitrate IDs returned
27 * by the firmware. */
28static const struct {
29 int bitrate; /* in 100s of kilobits */
30 int automatic;
31 u16 agere_txratectrl;
32 u16 intersil_txratectrl;
33} bitrate_table[] = {
34 {110, 1, 3, 15}, /* Entry 0 is the default */
35 {10, 0, 1, 1},
36 {10, 1, 1, 1},
37 {20, 0, 2, 2},
38 {20, 1, 6, 3},
39 {55, 0, 4, 4},
40 {55, 1, 7, 7},
41 {110, 0, 5, 8},
42};
43#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
44
David Kilroya2d1a422009-06-18 23:21:18 +010045/* Firmware version encoding */
46struct comp_id {
47 u16 id, variant, major, minor;
48} __attribute__ ((packed));
49
50static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
51{
52 if (nic_id->id < 0x8000)
53 return FIRMWARE_TYPE_AGERE;
54 else if (nic_id->id == 0x8000 && nic_id->major == 0)
55 return FIRMWARE_TYPE_SYMBOL;
56 else
57 return FIRMWARE_TYPE_INTERSIL;
58}
59
David Kilroya3f47b92009-06-18 23:21:21 +010060/* Set priv->firmware type, determine firmware properties
61 * This function can be called before we have registerred with netdev,
62 * so all errors go out with dev_* rather than printk
David Kilroy3414fc32009-10-07 22:23:32 +010063 *
64 * If non-NULL stores a firmware description in fw_name.
65 * If non-NULL stores a HW version in hw_ver
66 *
67 * These are output via generic cfg80211 ethtool support.
David Kilroya3f47b92009-06-18 23:21:21 +010068 */
David Kilroy3414fc32009-10-07 22:23:32 +010069int determine_fw_capabilities(struct orinoco_private *priv,
70 char *fw_name, size_t fw_name_len,
71 u32 *hw_ver)
David Kilroya2d1a422009-06-18 23:21:18 +010072{
David Kilroya3f47b92009-06-18 23:21:21 +010073 struct device *dev = priv->dev;
David Kilroya2d1a422009-06-18 23:21:18 +010074 hermes_t *hw = &priv->hw;
75 int err;
76 struct comp_id nic_id, sta_id;
77 unsigned int firmver;
78 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
79
80 /* Get the hardware version */
81 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
82 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +010083 dev_err(dev, "Cannot read hardware identity: error %d\n",
84 err);
David Kilroya2d1a422009-06-18 23:21:18 +010085 return err;
86 }
87
88 le16_to_cpus(&nic_id.id);
89 le16_to_cpus(&nic_id.variant);
90 le16_to_cpus(&nic_id.major);
91 le16_to_cpus(&nic_id.minor);
David Kilroya3f47b92009-06-18 23:21:21 +010092 dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
93 nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
David Kilroya2d1a422009-06-18 23:21:18 +010094
David Kilroy3414fc32009-10-07 22:23:32 +010095 if (hw_ver)
96 *hw_ver = (((nic_id.id & 0xff) << 24) |
97 ((nic_id.variant & 0xff) << 16) |
98 ((nic_id.major & 0xff) << 8) |
99 (nic_id.minor & 0xff));
100
David Kilroya2d1a422009-06-18 23:21:18 +0100101 priv->firmware_type = determine_firmware_type(&nic_id);
102
103 /* Get the firmware version */
104 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
105 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100106 dev_err(dev, "Cannot read station identity: error %d\n",
107 err);
David Kilroya2d1a422009-06-18 23:21:18 +0100108 return err;
109 }
110
111 le16_to_cpus(&sta_id.id);
112 le16_to_cpus(&sta_id.variant);
113 le16_to_cpus(&sta_id.major);
114 le16_to_cpus(&sta_id.minor);
David Kilroya3f47b92009-06-18 23:21:21 +0100115 dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
116 sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
David Kilroya2d1a422009-06-18 23:21:18 +0100117
118 switch (sta_id.id) {
119 case 0x15:
David Kilroya3f47b92009-06-18 23:21:21 +0100120 dev_err(dev, "Primary firmware is active\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100121 return -ENODEV;
122 case 0x14b:
David Kilroya3f47b92009-06-18 23:21:21 +0100123 dev_err(dev, "Tertiary firmware is active\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100124 return -ENODEV;
125 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
126 case 0x21: /* Symbol Spectrum24 Trilogy */
127 break;
128 default:
David Kilroya3f47b92009-06-18 23:21:21 +0100129 dev_notice(dev, "Unknown station ID, please report\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100130 break;
131 }
132
133 /* Default capabilities */
134 priv->has_sensitivity = 1;
135 priv->has_mwo = 0;
136 priv->has_preamble = 0;
137 priv->has_port3 = 1;
138 priv->has_ibss = 1;
139 priv->has_wep = 0;
140 priv->has_big_wep = 0;
141 priv->has_alt_txcntl = 0;
142 priv->has_ext_scan = 0;
143 priv->has_wpa = 0;
144 priv->do_fw_download = 0;
145
146 /* Determine capabilities from the firmware version */
147 switch (priv->firmware_type) {
148 case FIRMWARE_TYPE_AGERE:
149 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
150 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
David Kilroy3414fc32009-10-07 22:23:32 +0100151 if (fw_name)
152 snprintf(fw_name, fw_name_len, "Lucent/Agere %d.%02d",
153 sta_id.major, sta_id.minor);
David Kilroya2d1a422009-06-18 23:21:18 +0100154
155 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
156
157 priv->has_ibss = (firmver >= 0x60006);
158 priv->has_wep = (firmver >= 0x40020);
159 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
160 Gold cards from the others? */
161 priv->has_mwo = (firmver >= 0x60000);
162 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
163 priv->ibss_port = 1;
164 priv->has_hostscan = (firmver >= 0x8000a);
165 priv->do_fw_download = 1;
166 priv->broken_monitor = (firmver >= 0x80000);
167 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
168 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
169 priv->has_wpa = (firmver >= 0x9002a);
170 /* Tested with Agere firmware :
171 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
172 * Tested CableTron firmware : 4.32 => Anton */
173 break;
174 case FIRMWARE_TYPE_SYMBOL:
175 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
176 /* Intel MAC : 00:02:B3:* */
177 /* 3Com MAC : 00:50:DA:* */
178 memset(tmp, 0, sizeof(tmp));
179 /* Get the Symbol firmware version */
180 err = hermes_read_ltv(hw, USER_BAP,
181 HERMES_RID_SECONDARYVERSION_SYMBOL,
182 SYMBOL_MAX_VER_LEN, NULL, &tmp);
183 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100184 dev_warn(dev, "Error %d reading Symbol firmware info. "
185 "Wildly guessing capabilities...\n", err);
David Kilroya2d1a422009-06-18 23:21:18 +0100186 firmver = 0;
187 tmp[0] = '\0';
188 } else {
189 /* The firmware revision is a string, the format is
190 * something like : "V2.20-01".
191 * Quick and dirty parsing... - Jean II
192 */
193 firmver = ((tmp[1] - '0') << 16)
194 | ((tmp[3] - '0') << 12)
195 | ((tmp[4] - '0') << 8)
196 | ((tmp[6] - '0') << 4)
197 | (tmp[7] - '0');
198
199 tmp[SYMBOL_MAX_VER_LEN] = '\0';
200 }
201
David Kilroy3414fc32009-10-07 22:23:32 +0100202 if (fw_name)
203 snprintf(fw_name, fw_name_len, "Symbol %s", tmp);
David Kilroya2d1a422009-06-18 23:21:18 +0100204
205 priv->has_ibss = (firmver >= 0x20000);
206 priv->has_wep = (firmver >= 0x15012);
207 priv->has_big_wep = (firmver >= 0x20000);
208 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
209 (firmver >= 0x29000 && firmver < 0x30000) ||
210 firmver >= 0x31000;
211 priv->has_preamble = (firmver >= 0x20000);
212 priv->ibss_port = 4;
213
214 /* Symbol firmware is found on various cards, but
215 * there has been no attempt to check firmware
216 * download on non-spectrum_cs based cards.
217 *
218 * Given that the Agere firmware download works
219 * differently, we should avoid doing a firmware
220 * download with the Symbol algorithm on non-spectrum
221 * cards.
222 *
223 * For now we can identify a spectrum_cs based card
224 * because it has a firmware reset function.
225 */
226 priv->do_fw_download = (priv->stop_fw != NULL);
227
228 priv->broken_disableport = (firmver == 0x25013) ||
229 (firmver >= 0x30000 && firmver <= 0x31000);
230 priv->has_hostscan = (firmver >= 0x31001) ||
231 (firmver >= 0x29057 && firmver < 0x30000);
232 /* Tested with Intel firmware : 0x20015 => Jean II */
233 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
234 break;
235 case FIRMWARE_TYPE_INTERSIL:
236 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
237 * Samsung, Compaq 100/200 and Proxim are slightly
238 * different and less well tested */
239 /* D-Link MAC : 00:40:05:* */
240 /* Addtron MAC : 00:90:D1:* */
David Kilroy3414fc32009-10-07 22:23:32 +0100241 if (fw_name)
242 snprintf(fw_name, fw_name_len, "Intersil %d.%d.%d",
243 sta_id.major, sta_id.minor, sta_id.variant);
David Kilroya2d1a422009-06-18 23:21:18 +0100244
245 firmver = ((unsigned long)sta_id.major << 16) |
246 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
247
248 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
249 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
250 priv->has_pm = (firmver >= 0x000700);
251 priv->has_hostscan = (firmver >= 0x010301);
252
253 if (firmver >= 0x000800)
254 priv->ibss_port = 0;
255 else {
David Kilroya3f47b92009-06-18 23:21:21 +0100256 dev_notice(dev, "Intersil firmware earlier than v0.8.x"
257 " - several features not supported\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100258 priv->ibss_port = 1;
259 }
260 break;
261 }
David Kilroy3414fc32009-10-07 22:23:32 +0100262 if (fw_name)
263 dev_info(dev, "Firmware determined as %s\n", fw_name);
David Kilroya2d1a422009-06-18 23:21:18 +0100264
Pavel Roskin484b4dd2010-03-11 23:13:28 -0500265#ifndef CONFIG_HERMES_PRISM
266 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
267 dev_err(dev, "Support for Prism chipset is not enabled\n");
268 return -ENODEV;
269 }
270#endif
271
David Kilroya2d1a422009-06-18 23:21:18 +0100272 return 0;
273}
274
David Kilroye9e3d012009-06-18 23:21:19 +0100275/* Read settings from EEPROM into our private structure.
David Kilroya3f47b92009-06-18 23:21:21 +0100276 * MAC address gets dropped into callers buffer
277 * Can be called before netdev registration.
278 */
David Kilroye9e3d012009-06-18 23:21:19 +0100279int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
280{
David Kilroya3f47b92009-06-18 23:21:21 +0100281 struct device *dev = priv->dev;
David Kilroye9e3d012009-06-18 23:21:19 +0100282 struct hermes_idstring nickbuf;
283 hermes_t *hw = &priv->hw;
284 int len;
285 int err;
286 u16 reclen;
287
288 /* Get the MAC address */
289 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
290 ETH_ALEN, NULL, dev_addr);
291 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100292 dev_warn(dev, "Failed to read MAC address!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100293 goto out;
294 }
295
David Kilroya3f47b92009-06-18 23:21:21 +0100296 dev_dbg(dev, "MAC address %pM\n", dev_addr);
David Kilroye9e3d012009-06-18 23:21:19 +0100297
298 /* Get the station name */
299 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
300 sizeof(nickbuf), &reclen, &nickbuf);
301 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100302 dev_err(dev, "failed to read station name\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100303 goto out;
304 }
305 if (nickbuf.len)
306 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
307 else
308 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
309 memcpy(priv->nick, &nickbuf.val, len);
310 priv->nick[len] = '\0';
311
David Kilroya3f47b92009-06-18 23:21:21 +0100312 dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
David Kilroye9e3d012009-06-18 23:21:19 +0100313
314 /* Get allowed channels */
315 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
316 &priv->channel_mask);
317 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100318 dev_err(dev, "Failed to read channel list!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100319 goto out;
320 }
321
322 /* Get initial AP density */
323 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
324 &priv->ap_density);
325 if (err || priv->ap_density < 1 || priv->ap_density > 3)
326 priv->has_sensitivity = 0;
327
328 /* Get initial RTS threshold */
329 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
330 &priv->rts_thresh);
331 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100332 dev_err(dev, "Failed to read RTS threshold!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100333 goto out;
334 }
335
336 /* Get initial fragmentation settings */
337 if (priv->has_mwo)
338 err = hermes_read_wordrec(hw, USER_BAP,
339 HERMES_RID_CNFMWOROBUST_AGERE,
340 &priv->mwo_robust);
341 else
342 err = hermes_read_wordrec(hw, USER_BAP,
343 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
344 &priv->frag_thresh);
345 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100346 dev_err(dev, "Failed to read fragmentation settings!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100347 goto out;
348 }
349
350 /* Power management setup */
351 if (priv->has_pm) {
352 priv->pm_on = 0;
353 priv->pm_mcast = 1;
354 err = hermes_read_wordrec(hw, USER_BAP,
355 HERMES_RID_CNFMAXSLEEPDURATION,
356 &priv->pm_period);
357 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100358 dev_err(dev, "Failed to read power management "
359 "period!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100360 goto out;
361 }
362 err = hermes_read_wordrec(hw, USER_BAP,
363 HERMES_RID_CNFPMHOLDOVERDURATION,
364 &priv->pm_timeout);
365 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100366 dev_err(dev, "Failed to read power management "
367 "timeout!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100368 goto out;
369 }
370 }
371
372 /* Preamble setup */
373 if (priv->has_preamble) {
374 err = hermes_read_wordrec(hw, USER_BAP,
375 HERMES_RID_CNFPREAMBLE_SYMBOL,
376 &priv->preamble);
David Kilroyc3d41502010-04-19 08:16:21 +0100377 if (err) {
378 dev_err(dev, "Failed to read preamble setup\n");
379 goto out;
380 }
381 }
382
383 /* Retry settings */
384 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
385 &priv->short_retry_limit);
386 if (err) {
387 dev_err(dev, "Failed to read short retry limit\n");
388 goto out;
389 }
390
391 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
392 &priv->long_retry_limit);
393 if (err) {
394 dev_err(dev, "Failed to read long retry limit\n");
395 goto out;
396 }
397
398 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
399 &priv->retry_lifetime);
400 if (err) {
401 dev_err(dev, "Failed to read max retry lifetime\n");
402 goto out;
David Kilroye9e3d012009-06-18 23:21:19 +0100403 }
404
405out:
406 return err;
407}
408
David Kilroya3f47b92009-06-18 23:21:21 +0100409/* Can be called before netdev registration */
David Kilroy42a51b92009-06-18 23:21:20 +0100410int orinoco_hw_allocate_fid(struct orinoco_private *priv)
411{
David Kilroya3f47b92009-06-18 23:21:21 +0100412 struct device *dev = priv->dev;
David Kilroy42a51b92009-06-18 23:21:20 +0100413 struct hermes *hw = &priv->hw;
414 int err;
415
416 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
417 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
418 /* Try workaround for old Symbol firmware bug */
419 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
420 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
421
David Kilroya3f47b92009-06-18 23:21:21 +0100422 dev_warn(dev, "Firmware ALLOC bug detected "
423 "(old Symbol firmware?). Work around %s\n",
424 err ? "failed!" : "ok.");
David Kilroy42a51b92009-06-18 23:21:20 +0100425 }
426
427 return err;
428}
429
David Kilroy712a4342009-02-04 23:05:55 +0000430int orinoco_get_bitratemode(int bitrate, int automatic)
431{
432 int ratemode = -1;
433 int i;
434
435 if ((bitrate != 10) && (bitrate != 20) &&
436 (bitrate != 55) && (bitrate != 110))
437 return ratemode;
438
439 for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
440 if ((bitrate_table[i].bitrate == bitrate) &&
441 (bitrate_table[i].automatic == automatic)) {
442 ratemode = i;
443 break;
444 }
445 }
446 return ratemode;
447}
448
449void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
450{
451 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
452
453 *bitrate = bitrate_table[ratemode].bitrate * 100000;
454 *automatic = bitrate_table[ratemode].automatic;
455}
456
David Kilroy721aa2f2009-06-18 23:21:31 +0100457int orinoco_hw_program_rids(struct orinoco_private *priv)
458{
459 struct net_device *dev = priv->ndev;
David Kilroy5217c572009-06-18 23:21:32 +0100460 struct wireless_dev *wdev = netdev_priv(dev);
David Kilroy721aa2f2009-06-18 23:21:31 +0100461 hermes_t *hw = &priv->hw;
462 int err;
463 struct hermes_idstring idbuf;
464
465 /* Set the MAC address */
466 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
467 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
468 if (err) {
469 printk(KERN_ERR "%s: Error %d setting MAC address\n",
470 dev->name, err);
471 return err;
472 }
473
474 /* Set up the link mode */
475 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
476 priv->port_type);
477 if (err) {
478 printk(KERN_ERR "%s: Error %d setting port type\n",
479 dev->name, err);
480 return err;
481 }
482 /* Set the channel/frequency */
David Kilroy5217c572009-06-18 23:21:32 +0100483 if (priv->channel != 0 && priv->iw_mode != NL80211_IFTYPE_STATION) {
David Kilroy721aa2f2009-06-18 23:21:31 +0100484 err = hermes_write_wordrec(hw, USER_BAP,
485 HERMES_RID_CNFOWNCHANNEL,
486 priv->channel);
487 if (err) {
488 printk(KERN_ERR "%s: Error %d setting channel %d\n",
489 dev->name, err, priv->channel);
490 return err;
491 }
492 }
493
494 if (priv->has_ibss) {
495 u16 createibss;
496
497 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
498 printk(KERN_WARNING "%s: This firmware requires an "
499 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
500 /* With wvlan_cs, in this case, we would crash.
501 * hopefully, this driver will behave better...
502 * Jean II */
503 createibss = 0;
504 } else {
505 createibss = priv->createibss;
506 }
507
508 err = hermes_write_wordrec(hw, USER_BAP,
509 HERMES_RID_CNFCREATEIBSS,
510 createibss);
511 if (err) {
512 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
513 dev->name, err);
514 return err;
515 }
516 }
517
518 /* Set the desired BSSID */
519 err = __orinoco_hw_set_wap(priv);
520 if (err) {
521 printk(KERN_ERR "%s: Error %d setting AP address\n",
522 dev->name, err);
523 return err;
524 }
525
526 /* Set the desired ESSID */
527 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
528 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
529 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
530 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
531 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
532 &idbuf);
533 if (err) {
534 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
535 dev->name, err);
536 return err;
537 }
538 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
539 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
540 &idbuf);
541 if (err) {
542 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
543 dev->name, err);
544 return err;
545 }
546
547 /* Set the station name */
548 idbuf.len = cpu_to_le16(strlen(priv->nick));
549 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
550 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
551 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
552 &idbuf);
553 if (err) {
554 printk(KERN_ERR "%s: Error %d setting nickname\n",
555 dev->name, err);
556 return err;
557 }
558
559 /* Set AP density */
560 if (priv->has_sensitivity) {
561 err = hermes_write_wordrec(hw, USER_BAP,
562 HERMES_RID_CNFSYSTEMSCALE,
563 priv->ap_density);
564 if (err) {
565 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
566 "Disabling sensitivity control\n",
567 dev->name, err);
568
569 priv->has_sensitivity = 0;
570 }
571 }
572
573 /* Set RTS threshold */
574 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
575 priv->rts_thresh);
576 if (err) {
577 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
578 dev->name, err);
579 return err;
580 }
581
582 /* Set fragmentation threshold or MWO robustness */
583 if (priv->has_mwo)
584 err = hermes_write_wordrec(hw, USER_BAP,
585 HERMES_RID_CNFMWOROBUST_AGERE,
586 priv->mwo_robust);
587 else
588 err = hermes_write_wordrec(hw, USER_BAP,
589 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
590 priv->frag_thresh);
591 if (err) {
592 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
593 dev->name, err);
594 return err;
595 }
596
597 /* Set bitrate */
598 err = __orinoco_hw_set_bitrate(priv);
599 if (err) {
600 printk(KERN_ERR "%s: Error %d setting bitrate\n",
601 dev->name, err);
602 return err;
603 }
604
605 /* Set power management */
606 if (priv->has_pm) {
607 err = hermes_write_wordrec(hw, USER_BAP,
608 HERMES_RID_CNFPMENABLED,
609 priv->pm_on);
610 if (err) {
611 printk(KERN_ERR "%s: Error %d setting up PM\n",
612 dev->name, err);
613 return err;
614 }
615
616 err = hermes_write_wordrec(hw, USER_BAP,
617 HERMES_RID_CNFMULTICASTRECEIVE,
618 priv->pm_mcast);
619 if (err) {
620 printk(KERN_ERR "%s: Error %d setting up PM\n",
621 dev->name, err);
622 return err;
623 }
624 err = hermes_write_wordrec(hw, USER_BAP,
625 HERMES_RID_CNFMAXSLEEPDURATION,
626 priv->pm_period);
627 if (err) {
628 printk(KERN_ERR "%s: Error %d setting up PM\n",
629 dev->name, err);
630 return err;
631 }
632 err = hermes_write_wordrec(hw, USER_BAP,
633 HERMES_RID_CNFPMHOLDOVERDURATION,
634 priv->pm_timeout);
635 if (err) {
636 printk(KERN_ERR "%s: Error %d setting up PM\n",
637 dev->name, err);
638 return err;
639 }
640 }
641
642 /* Set preamble - only for Symbol so far... */
643 if (priv->has_preamble) {
644 err = hermes_write_wordrec(hw, USER_BAP,
645 HERMES_RID_CNFPREAMBLE_SYMBOL,
646 priv->preamble);
647 if (err) {
648 printk(KERN_ERR "%s: Error %d setting preamble\n",
649 dev->name, err);
650 return err;
651 }
652 }
653
654 /* Set up encryption */
655 if (priv->has_wep || priv->has_wpa) {
656 err = __orinoco_hw_setup_enc(priv);
657 if (err) {
658 printk(KERN_ERR "%s: Error %d activating encryption\n",
659 dev->name, err);
660 return err;
661 }
662 }
663
David Kilroy5217c572009-06-18 23:21:32 +0100664 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
David Kilroy721aa2f2009-06-18 23:21:31 +0100665 /* Enable monitor mode */
666 dev->type = ARPHRD_IEEE80211;
667 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
668 HERMES_TEST_MONITOR, 0, NULL);
669 } else {
670 /* Disable monitor mode */
671 dev->type = ARPHRD_ETHER;
672 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
673 HERMES_TEST_STOP, 0, NULL);
674 }
675 if (err)
676 return err;
677
678 /* Reset promiscuity / multicast*/
679 priv->promiscuous = 0;
680 priv->mc_count = 0;
681
David Kilroy5217c572009-06-18 23:21:32 +0100682 /* Record mode change */
683 wdev->iftype = priv->iw_mode;
684
David Kilroy721aa2f2009-06-18 23:21:31 +0100685 return 0;
686}
687
David Kilroy712a4342009-02-04 23:05:55 +0000688/* Get tsc from the firmware */
689int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
690{
691 hermes_t *hw = &priv->hw;
692 int err = 0;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100693 u8 tsc_arr[4][ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000694
John W. Linville518ff042009-08-17 12:09:26 -0400695 if ((key < 0) || (key >= 4))
David Kilroy712a4342009-02-04 23:05:55 +0000696 return -EINVAL;
697
698 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
699 sizeof(tsc_arr), NULL, &tsc_arr);
700 if (!err)
701 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
702
703 return err;
704}
705
706int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
707{
708 hermes_t *hw = &priv->hw;
709 int ratemode = priv->bitratemode;
710 int err = 0;
711
712 if (ratemode >= BITRATE_TABLE_SIZE) {
713 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
714 priv->ndev->name, ratemode);
715 return -EINVAL;
716 }
717
718 switch (priv->firmware_type) {
719 case FIRMWARE_TYPE_AGERE:
720 err = hermes_write_wordrec(hw, USER_BAP,
721 HERMES_RID_CNFTXRATECONTROL,
722 bitrate_table[ratemode].agere_txratectrl);
723 break;
724 case FIRMWARE_TYPE_INTERSIL:
725 case FIRMWARE_TYPE_SYMBOL:
726 err = hermes_write_wordrec(hw, USER_BAP,
727 HERMES_RID_CNFTXRATECONTROL,
728 bitrate_table[ratemode].intersil_txratectrl);
729 break;
730 default:
731 BUG();
732 }
733
734 return err;
735}
736
737int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
738{
739 hermes_t *hw = &priv->hw;
740 int i;
741 int err = 0;
742 u16 val;
743
744 err = hermes_read_wordrec(hw, USER_BAP,
745 HERMES_RID_CURRENTTXRATE, &val);
746 if (err)
747 return err;
748
749 switch (priv->firmware_type) {
750 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
751 /* Note : in Lucent firmware, the return value of
752 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
753 * and therefore is totally different from the
754 * encoding of HERMES_RID_CNFTXRATECONTROL.
755 * Don't forget that 6Mb/s is really 5.5Mb/s */
756 if (val == 6)
757 *bitrate = 5500000;
758 else
759 *bitrate = val * 1000000;
760 break;
761 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
762 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
763 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
764 if (bitrate_table[i].intersil_txratectrl == val)
765 break;
766
767 if (i >= BITRATE_TABLE_SIZE)
768 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
769 priv->ndev->name, val);
770
771 *bitrate = bitrate_table[i].bitrate * 100000;
772 break;
773 default:
774 BUG();
775 }
776
777 return err;
778}
779
780/* Set fixed AP address */
781int __orinoco_hw_set_wap(struct orinoco_private *priv)
782{
783 int roaming_flag;
784 int err = 0;
785 hermes_t *hw = &priv->hw;
786
787 switch (priv->firmware_type) {
788 case FIRMWARE_TYPE_AGERE:
789 /* not supported */
790 break;
791 case FIRMWARE_TYPE_INTERSIL:
792 if (priv->bssid_fixed)
793 roaming_flag = 2;
794 else
795 roaming_flag = 1;
796
797 err = hermes_write_wordrec(hw, USER_BAP,
798 HERMES_RID_CNFROAMINGMODE,
799 roaming_flag);
800 break;
801 case FIRMWARE_TYPE_SYMBOL:
802 err = HERMES_WRITE_RECORD(hw, USER_BAP,
803 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
804 &priv->desired_bssid);
805 break;
806 }
807 return err;
808}
809
810/* Change the WEP keys and/or the current keys. Can be called
811 * either from __orinoco_hw_setup_enc() or directly from
812 * orinoco_ioctl_setiwencode(). In the later case the association
813 * with the AP is not broken (if the firmware can handle it),
814 * which is needed for 802.1x implementations. */
815int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
816{
817 hermes_t *hw = &priv->hw;
818 int err = 0;
David Kilroy4af198f2009-08-05 21:23:32 +0100819 int i;
David Kilroy712a4342009-02-04 23:05:55 +0000820
821 switch (priv->firmware_type) {
822 case FIRMWARE_TYPE_AGERE:
David Kilroy4af198f2009-08-05 21:23:32 +0100823 {
824 struct orinoco_key keys[ORINOCO_MAX_KEYS];
825
826 memset(&keys, 0, sizeof(keys));
827 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
828 int len = min(priv->keys[i].key_len,
829 ORINOCO_MAX_KEY_SIZE);
830 memcpy(&keys[i].data, priv->keys[i].key, len);
831 if (len > SMALL_KEY_SIZE)
832 keys[i].len = cpu_to_le16(LARGE_KEY_SIZE);
833 else if (len > 0)
834 keys[i].len = cpu_to_le16(SMALL_KEY_SIZE);
835 else
836 keys[i].len = cpu_to_le16(0);
837 }
838
David Kilroy712a4342009-02-04 23:05:55 +0000839 err = HERMES_WRITE_RECORD(hw, USER_BAP,
840 HERMES_RID_CNFWEPKEYS_AGERE,
David Kilroy4af198f2009-08-05 21:23:32 +0100841 &keys);
David Kilroy712a4342009-02-04 23:05:55 +0000842 if (err)
843 return err;
844 err = hermes_write_wordrec(hw, USER_BAP,
845 HERMES_RID_CNFTXKEY_AGERE,
846 priv->tx_key);
847 if (err)
848 return err;
849 break;
David Kilroy4af198f2009-08-05 21:23:32 +0100850 }
David Kilroy712a4342009-02-04 23:05:55 +0000851 case FIRMWARE_TYPE_INTERSIL:
852 case FIRMWARE_TYPE_SYMBOL:
853 {
854 int keylen;
David Kilroy712a4342009-02-04 23:05:55 +0000855
856 /* Force uniform key length to work around
857 * firmware bugs */
David Kilroy4af198f2009-08-05 21:23:32 +0100858 keylen = priv->keys[priv->tx_key].key_len;
David Kilroy712a4342009-02-04 23:05:55 +0000859
860 if (keylen > LARGE_KEY_SIZE) {
861 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
862 priv->ndev->name, priv->tx_key, keylen);
863 return -E2BIG;
David Kilroy4af198f2009-08-05 21:23:32 +0100864 } else if (keylen > SMALL_KEY_SIZE)
865 keylen = LARGE_KEY_SIZE;
866 else if (keylen > 0)
867 keylen = SMALL_KEY_SIZE;
868 else
869 keylen = 0;
David Kilroy712a4342009-02-04 23:05:55 +0000870
871 /* Write all 4 keys */
872 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
David Kilroy4af198f2009-08-05 21:23:32 +0100873 u8 key[LARGE_KEY_SIZE] = { 0 };
874
875 memcpy(key, priv->keys[i].key,
876 priv->keys[i].key_len);
877
David Kilroy712a4342009-02-04 23:05:55 +0000878 err = hermes_write_ltv(hw, USER_BAP,
879 HERMES_RID_CNFDEFAULTKEY0 + i,
880 HERMES_BYTES_TO_RECLEN(keylen),
David Kilroy4af198f2009-08-05 21:23:32 +0100881 key);
David Kilroy712a4342009-02-04 23:05:55 +0000882 if (err)
883 return err;
884 }
885
886 /* Write the index of the key used in transmission */
887 err = hermes_write_wordrec(hw, USER_BAP,
888 HERMES_RID_CNFWEPDEFAULTKEYID,
889 priv->tx_key);
890 if (err)
891 return err;
892 }
893 break;
894 }
895
896 return 0;
897}
898
899int __orinoco_hw_setup_enc(struct orinoco_private *priv)
900{
901 hermes_t *hw = &priv->hw;
902 int err = 0;
903 int master_wep_flag;
904 int auth_flag;
905 int enc_flag;
906
David Kilroy4af198f2009-08-05 21:23:32 +0100907 /* Setup WEP keys */
908 if (priv->encode_alg == ORINOCO_ALG_WEP)
David Kilroy712a4342009-02-04 23:05:55 +0000909 __orinoco_hw_setup_wepkeys(priv);
910
911 if (priv->wep_restrict)
912 auth_flag = HERMES_AUTH_SHARED_KEY;
913 else
914 auth_flag = HERMES_AUTH_OPEN;
915
916 if (priv->wpa_enabled)
917 enc_flag = 2;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100918 else if (priv->encode_alg == ORINOCO_ALG_WEP)
David Kilroy712a4342009-02-04 23:05:55 +0000919 enc_flag = 1;
920 else
921 enc_flag = 0;
922
923 switch (priv->firmware_type) {
924 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
David Kilroy5c9f41e2009-08-05 21:23:28 +0100925 if (priv->encode_alg == ORINOCO_ALG_WEP) {
David Kilroy712a4342009-02-04 23:05:55 +0000926 /* Enable the shared-key authentication. */
927 err = hermes_write_wordrec(hw, USER_BAP,
928 HERMES_RID_CNFAUTHENTICATION_AGERE,
929 auth_flag);
930 }
931 err = hermes_write_wordrec(hw, USER_BAP,
932 HERMES_RID_CNFWEPENABLED_AGERE,
933 enc_flag);
934 if (err)
935 return err;
936
937 if (priv->has_wpa) {
938 /* Set WPA key management */
939 err = hermes_write_wordrec(hw, USER_BAP,
940 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
941 priv->key_mgmt);
942 if (err)
943 return err;
944 }
945
946 break;
947
948 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
949 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
David Kilroy5c9f41e2009-08-05 21:23:28 +0100950 if (priv->encode_alg == ORINOCO_ALG_WEP) {
David Kilroy712a4342009-02-04 23:05:55 +0000951 if (priv->wep_restrict ||
952 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
953 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
954 HERMES_WEP_EXCL_UNENCRYPTED;
955 else
956 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
957
958 err = hermes_write_wordrec(hw, USER_BAP,
959 HERMES_RID_CNFAUTHENTICATION,
960 auth_flag);
961 if (err)
962 return err;
963 } else
964 master_wep_flag = 0;
965
David Kilroy5217c572009-06-18 23:21:32 +0100966 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
David Kilroy712a4342009-02-04 23:05:55 +0000967 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
968
969 /* Master WEP setting : on/off */
970 err = hermes_write_wordrec(hw, USER_BAP,
971 HERMES_RID_CNFWEPFLAGS_INTERSIL,
972 master_wep_flag);
973 if (err)
974 return err;
975
976 break;
977 }
978
979 return 0;
980}
981
982/* key must be 32 bytes, including the tx and rx MIC keys.
David Kilroy16e15842009-08-05 21:23:29 +0100983 * rsc must be NULL or up to 8 bytes
984 * tsc must be NULL or up to 8 bytes
David Kilroy712a4342009-02-04 23:05:55 +0000985 */
David Kilroy98e5f402009-06-18 23:21:25 +0100986int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
David Kilroy16e15842009-08-05 21:23:29 +0100987 int set_tx, u8 *key, u8 *rsc, size_t rsc_len,
988 u8 *tsc, size_t tsc_len)
David Kilroy712a4342009-02-04 23:05:55 +0000989{
990 struct {
991 __le16 idx;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100992 u8 rsc[ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000993 u8 key[TKIP_KEYLEN];
994 u8 tx_mic[MIC_KEYLEN];
995 u8 rx_mic[MIC_KEYLEN];
David Kilroy5c9f41e2009-08-05 21:23:28 +0100996 u8 tsc[ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000997 } __attribute__ ((packed)) buf;
David Kilroy98e5f402009-06-18 23:21:25 +0100998 hermes_t *hw = &priv->hw;
David Kilroy712a4342009-02-04 23:05:55 +0000999 int ret;
1000 int err;
1001 int k;
1002 u16 xmitting;
1003
1004 key_idx &= 0x3;
1005
1006 if (set_tx)
1007 key_idx |= 0x8000;
1008
1009 buf.idx = cpu_to_le16(key_idx);
1010 memcpy(buf.key, key,
1011 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
1012
David Kilroy16e15842009-08-05 21:23:29 +01001013 if (rsc_len > sizeof(buf.rsc))
1014 rsc_len = sizeof(buf.rsc);
David Kilroy712a4342009-02-04 23:05:55 +00001015
David Kilroy16e15842009-08-05 21:23:29 +01001016 if (tsc_len > sizeof(buf.tsc))
1017 tsc_len = sizeof(buf.tsc);
1018
1019 memset(buf.rsc, 0, sizeof(buf.rsc));
1020 memset(buf.tsc, 0, sizeof(buf.tsc));
1021
1022 if (rsc != NULL)
1023 memcpy(buf.rsc, rsc, rsc_len);
1024
1025 if (tsc != NULL)
1026 memcpy(buf.tsc, tsc, tsc_len);
1027 else
David Kilroy712a4342009-02-04 23:05:55 +00001028 buf.tsc[4] = 0x10;
David Kilroy712a4342009-02-04 23:05:55 +00001029
1030 /* Wait upto 100ms for tx queue to empty */
Pavel Roskin91fe9ca2009-04-09 21:41:05 -04001031 for (k = 100; k > 0; k--) {
David Kilroy712a4342009-02-04 23:05:55 +00001032 udelay(1000);
1033 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
1034 &xmitting);
Pavel Roskin91fe9ca2009-04-09 21:41:05 -04001035 if (ret || !xmitting)
David Kilroy712a4342009-02-04 23:05:55 +00001036 break;
Pavel Roskin91fe9ca2009-04-09 21:41:05 -04001037 }
David Kilroy712a4342009-02-04 23:05:55 +00001038
1039 if (k == 0)
1040 ret = -ETIMEDOUT;
1041
1042 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1043 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
1044 &buf);
1045
1046 return ret ? ret : err;
1047}
1048
1049int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
1050{
1051 hermes_t *hw = &priv->hw;
1052 int err;
1053
David Kilroy712a4342009-02-04 23:05:55 +00001054 err = hermes_write_wordrec(hw, USER_BAP,
1055 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
1056 key_idx);
1057 if (err)
1058 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
1059 priv->ndev->name, err, key_idx);
1060 return err;
1061}
1062
1063int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
Jiri Pirko655ffee2010-02-27 07:35:45 +00001064 struct net_device *dev,
David Kilroy712a4342009-02-04 23:05:55 +00001065 int mc_count, int promisc)
1066{
1067 hermes_t *hw = &priv->hw;
1068 int err = 0;
1069
1070 if (promisc != priv->promiscuous) {
1071 err = hermes_write_wordrec(hw, USER_BAP,
1072 HERMES_RID_CNFPROMISCUOUSMODE,
1073 promisc);
1074 if (err) {
1075 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1076 priv->ndev->name, err);
1077 } else
1078 priv->promiscuous = promisc;
1079 }
1080
1081 /* If we're not in promiscuous mode, then we need to set the
1082 * group address if either we want to multicast, or if we were
1083 * multicasting and want to stop */
1084 if (!promisc && (mc_count || priv->mc_count)) {
Jiri Pirko655ffee2010-02-27 07:35:45 +00001085 struct dev_mc_list *p;
David Kilroy712a4342009-02-04 23:05:55 +00001086 struct hermes_multicast mclist;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001087 int i = 0;
David Kilroy712a4342009-02-04 23:05:55 +00001088
Jiri Pirko655ffee2010-02-27 07:35:45 +00001089 netdev_for_each_mc_addr(p, dev) {
1090 if (i == mc_count)
1091 break;
1092 memcpy(mclist.addr[i++], p->dmi_addr, ETH_ALEN);
David Kilroy712a4342009-02-04 23:05:55 +00001093 }
1094
David Kilroy712a4342009-02-04 23:05:55 +00001095 err = hermes_write_ltv(hw, USER_BAP,
1096 HERMES_RID_CNFGROUPADDRESSES,
1097 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
1098 &mclist);
1099 if (err)
1100 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1101 priv->ndev->name, err);
1102 else
1103 priv->mc_count = mc_count;
1104 }
1105 return err;
1106}
1107
1108/* Return : < 0 -> error code ; >= 0 -> length */
1109int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
1110 char buf[IW_ESSID_MAX_SIZE+1])
1111{
1112 hermes_t *hw = &priv->hw;
1113 int err = 0;
1114 struct hermes_idstring essidbuf;
1115 char *p = (char *)(&essidbuf.val);
1116 int len;
1117 unsigned long flags;
1118
1119 if (orinoco_lock(priv, &flags) != 0)
1120 return -EBUSY;
1121
1122 if (strlen(priv->desired_essid) > 0) {
1123 /* We read the desired SSID from the hardware rather
1124 than from priv->desired_essid, just in case the
1125 firmware is allowed to change it on us. I'm not
1126 sure about this */
1127 /* My guess is that the OWNSSID should always be whatever
1128 * we set to the card, whereas CURRENT_SSID is the one that
1129 * may change... - Jean II */
1130 u16 rid;
1131
1132 *active = 1;
1133
1134 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
1135 HERMES_RID_CNFDESIREDSSID;
1136
1137 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
1138 NULL, &essidbuf);
1139 if (err)
1140 goto fail_unlock;
1141 } else {
1142 *active = 0;
1143
1144 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
1145 sizeof(essidbuf), NULL, &essidbuf);
1146 if (err)
1147 goto fail_unlock;
1148 }
1149
1150 len = le16_to_cpu(essidbuf.len);
1151 BUG_ON(len > IW_ESSID_MAX_SIZE);
1152
1153 memset(buf, 0, IW_ESSID_MAX_SIZE);
1154 memcpy(buf, p, len);
1155 err = len;
1156
1157 fail_unlock:
1158 orinoco_unlock(priv, &flags);
1159
1160 return err;
1161}
1162
1163int orinoco_hw_get_freq(struct orinoco_private *priv)
1164{
1165 hermes_t *hw = &priv->hw;
1166 int err = 0;
1167 u16 channel;
1168 int freq = 0;
1169 unsigned long flags;
1170
1171 if (orinoco_lock(priv, &flags) != 0)
1172 return -EBUSY;
1173
1174 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
1175 &channel);
1176 if (err)
1177 goto out;
1178
1179 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
1180 if (channel == 0) {
1181 err = -EBUSY;
1182 goto out;
1183 }
1184
1185 if ((channel < 1) || (channel > NUM_CHANNELS)) {
1186 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
1187 priv->ndev->name, channel);
1188 err = -EBUSY;
1189 goto out;
1190
1191 }
1192 freq = ieee80211_dsss_chan_to_freq(channel);
1193
1194 out:
1195 orinoco_unlock(priv, &flags);
1196
1197 if (err > 0)
1198 err = -EBUSY;
1199 return err ? err : freq;
1200}
1201
1202int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
1203 int *numrates, s32 *rates, int max)
1204{
1205 hermes_t *hw = &priv->hw;
1206 struct hermes_idstring list;
1207 unsigned char *p = (unsigned char *)&list.val;
1208 int err = 0;
1209 int num;
1210 int i;
1211 unsigned long flags;
1212
1213 if (orinoco_lock(priv, &flags) != 0)
1214 return -EBUSY;
1215
1216 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
1217 sizeof(list), NULL, &list);
1218 orinoco_unlock(priv, &flags);
1219
1220 if (err)
1221 return err;
1222
1223 num = le16_to_cpu(list.len);
1224 *numrates = num;
1225 num = min(num, max);
1226
1227 for (i = 0; i < num; i++)
1228 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
1229
1230 return 0;
1231}
David Kilroyc63cdbe2009-06-18 23:21:33 +01001232
1233int orinoco_hw_trigger_scan(struct orinoco_private *priv,
1234 const struct cfg80211_ssid *ssid)
1235{
1236 struct net_device *dev = priv->ndev;
1237 hermes_t *hw = &priv->hw;
1238 unsigned long flags;
1239 int err = 0;
1240
1241 if (orinoco_lock(priv, &flags) != 0)
1242 return -EBUSY;
1243
1244 /* Scanning with port 0 disabled would fail */
1245 if (!netif_running(dev)) {
1246 err = -ENETDOWN;
1247 goto out;
1248 }
1249
1250 /* In monitor mode, the scan results are always empty.
1251 * Probe responses are passed to the driver as received
1252 * frames and could be processed in software. */
1253 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1254 err = -EOPNOTSUPP;
1255 goto out;
1256 }
1257
1258 if (priv->has_hostscan) {
1259 switch (priv->firmware_type) {
1260 case FIRMWARE_TYPE_SYMBOL:
1261 err = hermes_write_wordrec(hw, USER_BAP,
1262 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1263 HERMES_HOSTSCAN_SYMBOL_ONCE |
1264 HERMES_HOSTSCAN_SYMBOL_BCAST);
1265 break;
1266 case FIRMWARE_TYPE_INTERSIL: {
1267 __le16 req[3];
1268
1269 req[0] = cpu_to_le16(0x3fff); /* All channels */
1270 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1271 req[2] = 0; /* Any ESSID */
1272 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1273 HERMES_RID_CNFHOSTSCAN, &req);
1274 break;
1275 }
1276 case FIRMWARE_TYPE_AGERE:
1277 if (ssid->ssid_len > 0) {
1278 struct hermes_idstring idbuf;
1279 size_t len = ssid->ssid_len;
1280
1281 idbuf.len = cpu_to_le16(len);
1282 memcpy(idbuf.val, ssid->ssid, len);
1283
1284 err = hermes_write_ltv(hw, USER_BAP,
1285 HERMES_RID_CNFSCANSSID_AGERE,
1286 HERMES_BYTES_TO_RECLEN(len + 2),
1287 &idbuf);
1288 } else
1289 err = hermes_write_wordrec(hw, USER_BAP,
1290 HERMES_RID_CNFSCANSSID_AGERE,
1291 0); /* Any ESSID */
1292 if (err)
1293 break;
1294
1295 if (priv->has_ext_scan) {
1296 err = hermes_write_wordrec(hw, USER_BAP,
1297 HERMES_RID_CNFSCANCHANNELS2GHZ,
1298 0x7FFF);
1299 if (err)
1300 goto out;
1301
1302 err = hermes_inquire(hw,
1303 HERMES_INQ_CHANNELINFO);
1304 } else
1305 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1306
1307 break;
1308 }
1309 } else
1310 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1311
1312 out:
1313 orinoco_unlock(priv, &flags);
1314
1315 return err;
1316}
David Kilroy07542d02009-08-05 21:23:30 +01001317
1318/* Disassociate from node with BSSID addr */
1319int orinoco_hw_disassociate(struct orinoco_private *priv,
1320 u8 *addr, u16 reason_code)
1321{
1322 hermes_t *hw = &priv->hw;
1323 int err;
1324
1325 struct {
1326 u8 addr[ETH_ALEN];
1327 __le16 reason_code;
1328 } __attribute__ ((packed)) buf;
1329
1330 /* Currently only supported by WPA enabled Agere fw */
1331 if (!priv->has_wpa)
1332 return -EOPNOTSUPP;
1333
1334 memcpy(buf.addr, addr, ETH_ALEN);
1335 buf.reason_code = cpu_to_le16(reason_code);
1336 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1337 HERMES_RID_CNFDISASSOCIATE,
1338 &buf);
1339 return err;
1340}
David Kilroy2b260352009-08-05 21:23:31 +01001341
1342int orinoco_hw_get_current_bssid(struct orinoco_private *priv,
1343 u8 *addr)
1344{
1345 hermes_t *hw = &priv->hw;
1346 int err;
1347
1348 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1349 ETH_ALEN, NULL, addr);
1350
1351 return err;
1352}