hw.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. /* Encapsulate basic setting changes and retrieval on Hermes hardware
  2. *
  3. * See copyright notice in main.c
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/device.h>
  7. #include <linux/if_arp.h>
  8. #include <linux/ieee80211.h>
  9. #include <linux/wireless.h>
  10. #include "hermes.h"
  11. #include "hermes_rid.h"
  12. #include "orinoco.h"
  13. #include "hw.h"
  14. #define SYMBOL_MAX_VER_LEN (14)
  15. /* Symbol firmware has a bug allocating buffers larger than this */
  16. #define TX_NICBUF_SIZE_BUG 1585
  17. /********************************************************************/
  18. /* Data tables */
  19. /********************************************************************/
  20. /* This tables gives the actual meanings of the bitrate IDs returned
  21. * by the firmware. */
  22. static const struct {
  23. int bitrate; /* in 100s of kilobits */
  24. int automatic;
  25. u16 agere_txratectrl;
  26. u16 intersil_txratectrl;
  27. } bitrate_table[] = {
  28. {110, 1, 3, 15}, /* Entry 0 is the default */
  29. {10, 0, 1, 1},
  30. {10, 1, 1, 1},
  31. {20, 0, 2, 2},
  32. {20, 1, 6, 3},
  33. {55, 0, 4, 4},
  34. {55, 1, 7, 7},
  35. {110, 0, 5, 8},
  36. };
  37. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  38. /* Firmware version encoding */
  39. struct comp_id {
  40. u16 id, variant, major, minor;
  41. } __attribute__ ((packed));
  42. static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
  43. {
  44. if (nic_id->id < 0x8000)
  45. return FIRMWARE_TYPE_AGERE;
  46. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  47. return FIRMWARE_TYPE_SYMBOL;
  48. else
  49. return FIRMWARE_TYPE_INTERSIL;
  50. }
  51. /* Set priv->firmware type, determine firmware properties
  52. * This function can be called before we have registerred with netdev,
  53. * so all errors go out with dev_* rather than printk
  54. */
  55. int determine_fw_capabilities(struct orinoco_private *priv)
  56. {
  57. struct device *dev = priv->dev;
  58. hermes_t *hw = &priv->hw;
  59. int err;
  60. struct comp_id nic_id, sta_id;
  61. unsigned int firmver;
  62. char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
  63. /* Get the hardware version */
  64. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  65. if (err) {
  66. dev_err(dev, "Cannot read hardware identity: error %d\n",
  67. err);
  68. return err;
  69. }
  70. le16_to_cpus(&nic_id.id);
  71. le16_to_cpus(&nic_id.variant);
  72. le16_to_cpus(&nic_id.major);
  73. le16_to_cpus(&nic_id.minor);
  74. dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
  75. nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
  76. priv->firmware_type = determine_firmware_type(&nic_id);
  77. /* Get the firmware version */
  78. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  79. if (err) {
  80. dev_err(dev, "Cannot read station identity: error %d\n",
  81. err);
  82. return err;
  83. }
  84. le16_to_cpus(&sta_id.id);
  85. le16_to_cpus(&sta_id.variant);
  86. le16_to_cpus(&sta_id.major);
  87. le16_to_cpus(&sta_id.minor);
  88. dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
  89. sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
  90. switch (sta_id.id) {
  91. case 0x15:
  92. dev_err(dev, "Primary firmware is active\n");
  93. return -ENODEV;
  94. case 0x14b:
  95. dev_err(dev, "Tertiary firmware is active\n");
  96. return -ENODEV;
  97. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  98. case 0x21: /* Symbol Spectrum24 Trilogy */
  99. break;
  100. default:
  101. dev_notice(dev, "Unknown station ID, please report\n");
  102. break;
  103. }
  104. /* Default capabilities */
  105. priv->has_sensitivity = 1;
  106. priv->has_mwo = 0;
  107. priv->has_preamble = 0;
  108. priv->has_port3 = 1;
  109. priv->has_ibss = 1;
  110. priv->has_wep = 0;
  111. priv->has_big_wep = 0;
  112. priv->has_alt_txcntl = 0;
  113. priv->has_ext_scan = 0;
  114. priv->has_wpa = 0;
  115. priv->do_fw_download = 0;
  116. /* Determine capabilities from the firmware version */
  117. switch (priv->firmware_type) {
  118. case FIRMWARE_TYPE_AGERE:
  119. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  120. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  121. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  122. "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
  123. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  124. priv->has_ibss = (firmver >= 0x60006);
  125. priv->has_wep = (firmver >= 0x40020);
  126. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  127. Gold cards from the others? */
  128. priv->has_mwo = (firmver >= 0x60000);
  129. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  130. priv->ibss_port = 1;
  131. priv->has_hostscan = (firmver >= 0x8000a);
  132. priv->do_fw_download = 1;
  133. priv->broken_monitor = (firmver >= 0x80000);
  134. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  135. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  136. priv->has_wpa = (firmver >= 0x9002a);
  137. /* Tested with Agere firmware :
  138. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  139. * Tested CableTron firmware : 4.32 => Anton */
  140. break;
  141. case FIRMWARE_TYPE_SYMBOL:
  142. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  143. /* Intel MAC : 00:02:B3:* */
  144. /* 3Com MAC : 00:50:DA:* */
  145. memset(tmp, 0, sizeof(tmp));
  146. /* Get the Symbol firmware version */
  147. err = hermes_read_ltv(hw, USER_BAP,
  148. HERMES_RID_SECONDARYVERSION_SYMBOL,
  149. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  150. if (err) {
  151. dev_warn(dev, "Error %d reading Symbol firmware info. "
  152. "Wildly guessing capabilities...\n", err);
  153. firmver = 0;
  154. tmp[0] = '\0';
  155. } else {
  156. /* The firmware revision is a string, the format is
  157. * something like : "V2.20-01".
  158. * Quick and dirty parsing... - Jean II
  159. */
  160. firmver = ((tmp[1] - '0') << 16)
  161. | ((tmp[3] - '0') << 12)
  162. | ((tmp[4] - '0') << 8)
  163. | ((tmp[6] - '0') << 4)
  164. | (tmp[7] - '0');
  165. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  166. }
  167. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  168. "Symbol %s", tmp);
  169. priv->has_ibss = (firmver >= 0x20000);
  170. priv->has_wep = (firmver >= 0x15012);
  171. priv->has_big_wep = (firmver >= 0x20000);
  172. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  173. (firmver >= 0x29000 && firmver < 0x30000) ||
  174. firmver >= 0x31000;
  175. priv->has_preamble = (firmver >= 0x20000);
  176. priv->ibss_port = 4;
  177. /* Symbol firmware is found on various cards, but
  178. * there has been no attempt to check firmware
  179. * download on non-spectrum_cs based cards.
  180. *
  181. * Given that the Agere firmware download works
  182. * differently, we should avoid doing a firmware
  183. * download with the Symbol algorithm on non-spectrum
  184. * cards.
  185. *
  186. * For now we can identify a spectrum_cs based card
  187. * because it has a firmware reset function.
  188. */
  189. priv->do_fw_download = (priv->stop_fw != NULL);
  190. priv->broken_disableport = (firmver == 0x25013) ||
  191. (firmver >= 0x30000 && firmver <= 0x31000);
  192. priv->has_hostscan = (firmver >= 0x31001) ||
  193. (firmver >= 0x29057 && firmver < 0x30000);
  194. /* Tested with Intel firmware : 0x20015 => Jean II */
  195. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  196. break;
  197. case FIRMWARE_TYPE_INTERSIL:
  198. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  199. * Samsung, Compaq 100/200 and Proxim are slightly
  200. * different and less well tested */
  201. /* D-Link MAC : 00:40:05:* */
  202. /* Addtron MAC : 00:90:D1:* */
  203. snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
  204. "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
  205. sta_id.variant);
  206. firmver = ((unsigned long)sta_id.major << 16) |
  207. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  208. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  209. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  210. priv->has_pm = (firmver >= 0x000700);
  211. priv->has_hostscan = (firmver >= 0x010301);
  212. if (firmver >= 0x000800)
  213. priv->ibss_port = 0;
  214. else {
  215. dev_notice(dev, "Intersil firmware earlier than v0.8.x"
  216. " - several features not supported\n");
  217. priv->ibss_port = 1;
  218. }
  219. break;
  220. }
  221. dev_info(dev, "Firmware determined as %s\n", priv->fw_name);
  222. return 0;
  223. }
  224. /* Read settings from EEPROM into our private structure.
  225. * MAC address gets dropped into callers buffer
  226. * Can be called before netdev registration.
  227. */
  228. int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
  229. {
  230. struct device *dev = priv->dev;
  231. struct hermes_idstring nickbuf;
  232. hermes_t *hw = &priv->hw;
  233. int len;
  234. int err;
  235. u16 reclen;
  236. /* Get the MAC address */
  237. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  238. ETH_ALEN, NULL, dev_addr);
  239. if (err) {
  240. dev_warn(dev, "Failed to read MAC address!\n");
  241. goto out;
  242. }
  243. dev_dbg(dev, "MAC address %pM\n", dev_addr);
  244. /* Get the station name */
  245. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  246. sizeof(nickbuf), &reclen, &nickbuf);
  247. if (err) {
  248. dev_err(dev, "failed to read station name\n");
  249. goto out;
  250. }
  251. if (nickbuf.len)
  252. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  253. else
  254. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  255. memcpy(priv->nick, &nickbuf.val, len);
  256. priv->nick[len] = '\0';
  257. dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
  258. /* Get allowed channels */
  259. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  260. &priv->channel_mask);
  261. if (err) {
  262. dev_err(dev, "Failed to read channel list!\n");
  263. goto out;
  264. }
  265. /* Get initial AP density */
  266. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  267. &priv->ap_density);
  268. if (err || priv->ap_density < 1 || priv->ap_density > 3)
  269. priv->has_sensitivity = 0;
  270. /* Get initial RTS threshold */
  271. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  272. &priv->rts_thresh);
  273. if (err) {
  274. dev_err(dev, "Failed to read RTS threshold!\n");
  275. goto out;
  276. }
  277. /* Get initial fragmentation settings */
  278. if (priv->has_mwo)
  279. err = hermes_read_wordrec(hw, USER_BAP,
  280. HERMES_RID_CNFMWOROBUST_AGERE,
  281. &priv->mwo_robust);
  282. else
  283. err = hermes_read_wordrec(hw, USER_BAP,
  284. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  285. &priv->frag_thresh);
  286. if (err) {
  287. dev_err(dev, "Failed to read fragmentation settings!\n");
  288. goto out;
  289. }
  290. /* Power management setup */
  291. if (priv->has_pm) {
  292. priv->pm_on = 0;
  293. priv->pm_mcast = 1;
  294. err = hermes_read_wordrec(hw, USER_BAP,
  295. HERMES_RID_CNFMAXSLEEPDURATION,
  296. &priv->pm_period);
  297. if (err) {
  298. dev_err(dev, "Failed to read power management "
  299. "period!\n");
  300. goto out;
  301. }
  302. err = hermes_read_wordrec(hw, USER_BAP,
  303. HERMES_RID_CNFPMHOLDOVERDURATION,
  304. &priv->pm_timeout);
  305. if (err) {
  306. dev_err(dev, "Failed to read power management "
  307. "timeout!\n");
  308. goto out;
  309. }
  310. }
  311. /* Preamble setup */
  312. if (priv->has_preamble) {
  313. err = hermes_read_wordrec(hw, USER_BAP,
  314. HERMES_RID_CNFPREAMBLE_SYMBOL,
  315. &priv->preamble);
  316. }
  317. out:
  318. return err;
  319. }
  320. /* Can be called before netdev registration */
  321. int orinoco_hw_allocate_fid(struct orinoco_private *priv)
  322. {
  323. struct device *dev = priv->dev;
  324. struct hermes *hw = &priv->hw;
  325. int err;
  326. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  327. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  328. /* Try workaround for old Symbol firmware bug */
  329. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  330. err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
  331. dev_warn(dev, "Firmware ALLOC bug detected "
  332. "(old Symbol firmware?). Work around %s\n",
  333. err ? "failed!" : "ok.");
  334. }
  335. return err;
  336. }
  337. int orinoco_get_bitratemode(int bitrate, int automatic)
  338. {
  339. int ratemode = -1;
  340. int i;
  341. if ((bitrate != 10) && (bitrate != 20) &&
  342. (bitrate != 55) && (bitrate != 110))
  343. return ratemode;
  344. for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
  345. if ((bitrate_table[i].bitrate == bitrate) &&
  346. (bitrate_table[i].automatic == automatic)) {
  347. ratemode = i;
  348. break;
  349. }
  350. }
  351. return ratemode;
  352. }
  353. void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
  354. {
  355. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  356. *bitrate = bitrate_table[ratemode].bitrate * 100000;
  357. *automatic = bitrate_table[ratemode].automatic;
  358. }
  359. /* Get tsc from the firmware */
  360. int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
  361. {
  362. hermes_t *hw = &priv->hw;
  363. int err = 0;
  364. u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
  365. if ((key < 0) || (key > 4))
  366. return -EINVAL;
  367. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
  368. sizeof(tsc_arr), NULL, &tsc_arr);
  369. if (!err)
  370. memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
  371. return err;
  372. }
  373. int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  374. {
  375. hermes_t *hw = &priv->hw;
  376. int ratemode = priv->bitratemode;
  377. int err = 0;
  378. if (ratemode >= BITRATE_TABLE_SIZE) {
  379. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  380. priv->ndev->name, ratemode);
  381. return -EINVAL;
  382. }
  383. switch (priv->firmware_type) {
  384. case FIRMWARE_TYPE_AGERE:
  385. err = hermes_write_wordrec(hw, USER_BAP,
  386. HERMES_RID_CNFTXRATECONTROL,
  387. bitrate_table[ratemode].agere_txratectrl);
  388. break;
  389. case FIRMWARE_TYPE_INTERSIL:
  390. case FIRMWARE_TYPE_SYMBOL:
  391. err = hermes_write_wordrec(hw, USER_BAP,
  392. HERMES_RID_CNFTXRATECONTROL,
  393. bitrate_table[ratemode].intersil_txratectrl);
  394. break;
  395. default:
  396. BUG();
  397. }
  398. return err;
  399. }
  400. int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
  401. {
  402. hermes_t *hw = &priv->hw;
  403. int i;
  404. int err = 0;
  405. u16 val;
  406. err = hermes_read_wordrec(hw, USER_BAP,
  407. HERMES_RID_CURRENTTXRATE, &val);
  408. if (err)
  409. return err;
  410. switch (priv->firmware_type) {
  411. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  412. /* Note : in Lucent firmware, the return value of
  413. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  414. * and therefore is totally different from the
  415. * encoding of HERMES_RID_CNFTXRATECONTROL.
  416. * Don't forget that 6Mb/s is really 5.5Mb/s */
  417. if (val == 6)
  418. *bitrate = 5500000;
  419. else
  420. *bitrate = val * 1000000;
  421. break;
  422. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  423. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  424. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  425. if (bitrate_table[i].intersil_txratectrl == val)
  426. break;
  427. if (i >= BITRATE_TABLE_SIZE)
  428. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  429. priv->ndev->name, val);
  430. *bitrate = bitrate_table[i].bitrate * 100000;
  431. break;
  432. default:
  433. BUG();
  434. }
  435. return err;
  436. }
  437. /* Set fixed AP address */
  438. int __orinoco_hw_set_wap(struct orinoco_private *priv)
  439. {
  440. int roaming_flag;
  441. int err = 0;
  442. hermes_t *hw = &priv->hw;
  443. switch (priv->firmware_type) {
  444. case FIRMWARE_TYPE_AGERE:
  445. /* not supported */
  446. break;
  447. case FIRMWARE_TYPE_INTERSIL:
  448. if (priv->bssid_fixed)
  449. roaming_flag = 2;
  450. else
  451. roaming_flag = 1;
  452. err = hermes_write_wordrec(hw, USER_BAP,
  453. HERMES_RID_CNFROAMINGMODE,
  454. roaming_flag);
  455. break;
  456. case FIRMWARE_TYPE_SYMBOL:
  457. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  458. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  459. &priv->desired_bssid);
  460. break;
  461. }
  462. return err;
  463. }
  464. /* Change the WEP keys and/or the current keys. Can be called
  465. * either from __orinoco_hw_setup_enc() or directly from
  466. * orinoco_ioctl_setiwencode(). In the later case the association
  467. * with the AP is not broken (if the firmware can handle it),
  468. * which is needed for 802.1x implementations. */
  469. int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  470. {
  471. hermes_t *hw = &priv->hw;
  472. int err = 0;
  473. switch (priv->firmware_type) {
  474. case FIRMWARE_TYPE_AGERE:
  475. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  476. HERMES_RID_CNFWEPKEYS_AGERE,
  477. &priv->keys);
  478. if (err)
  479. return err;
  480. err = hermes_write_wordrec(hw, USER_BAP,
  481. HERMES_RID_CNFTXKEY_AGERE,
  482. priv->tx_key);
  483. if (err)
  484. return err;
  485. break;
  486. case FIRMWARE_TYPE_INTERSIL:
  487. case FIRMWARE_TYPE_SYMBOL:
  488. {
  489. int keylen;
  490. int i;
  491. /* Force uniform key length to work around
  492. * firmware bugs */
  493. keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
  494. if (keylen > LARGE_KEY_SIZE) {
  495. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  496. priv->ndev->name, priv->tx_key, keylen);
  497. return -E2BIG;
  498. }
  499. /* Write all 4 keys */
  500. for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
  501. err = hermes_write_ltv(hw, USER_BAP,
  502. HERMES_RID_CNFDEFAULTKEY0 + i,
  503. HERMES_BYTES_TO_RECLEN(keylen),
  504. priv->keys[i].data);
  505. if (err)
  506. return err;
  507. }
  508. /* Write the index of the key used in transmission */
  509. err = hermes_write_wordrec(hw, USER_BAP,
  510. HERMES_RID_CNFWEPDEFAULTKEYID,
  511. priv->tx_key);
  512. if (err)
  513. return err;
  514. }
  515. break;
  516. }
  517. return 0;
  518. }
  519. int __orinoco_hw_setup_enc(struct orinoco_private *priv)
  520. {
  521. hermes_t *hw = &priv->hw;
  522. int err = 0;
  523. int master_wep_flag;
  524. int auth_flag;
  525. int enc_flag;
  526. /* Setup WEP keys for WEP and WPA */
  527. if (priv->encode_alg)
  528. __orinoco_hw_setup_wepkeys(priv);
  529. if (priv->wep_restrict)
  530. auth_flag = HERMES_AUTH_SHARED_KEY;
  531. else
  532. auth_flag = HERMES_AUTH_OPEN;
  533. if (priv->wpa_enabled)
  534. enc_flag = 2;
  535. else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
  536. enc_flag = 1;
  537. else
  538. enc_flag = 0;
  539. switch (priv->firmware_type) {
  540. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  541. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  542. /* Enable the shared-key authentication. */
  543. err = hermes_write_wordrec(hw, USER_BAP,
  544. HERMES_RID_CNFAUTHENTICATION_AGERE,
  545. auth_flag);
  546. }
  547. err = hermes_write_wordrec(hw, USER_BAP,
  548. HERMES_RID_CNFWEPENABLED_AGERE,
  549. enc_flag);
  550. if (err)
  551. return err;
  552. if (priv->has_wpa) {
  553. /* Set WPA key management */
  554. err = hermes_write_wordrec(hw, USER_BAP,
  555. HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
  556. priv->key_mgmt);
  557. if (err)
  558. return err;
  559. }
  560. break;
  561. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  562. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  563. if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
  564. if (priv->wep_restrict ||
  565. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  566. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  567. HERMES_WEP_EXCL_UNENCRYPTED;
  568. else
  569. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  570. err = hermes_write_wordrec(hw, USER_BAP,
  571. HERMES_RID_CNFAUTHENTICATION,
  572. auth_flag);
  573. if (err)
  574. return err;
  575. } else
  576. master_wep_flag = 0;
  577. if (priv->iw_mode == IW_MODE_MONITOR)
  578. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  579. /* Master WEP setting : on/off */
  580. err = hermes_write_wordrec(hw, USER_BAP,
  581. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  582. master_wep_flag);
  583. if (err)
  584. return err;
  585. break;
  586. }
  587. return 0;
  588. }
  589. /* key must be 32 bytes, including the tx and rx MIC keys.
  590. * rsc must be 8 bytes
  591. * tsc must be 8 bytes or NULL
  592. */
  593. int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
  594. int set_tx, u8 *key, u8 *rsc, u8 *tsc)
  595. {
  596. struct {
  597. __le16 idx;
  598. u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
  599. u8 key[TKIP_KEYLEN];
  600. u8 tx_mic[MIC_KEYLEN];
  601. u8 rx_mic[MIC_KEYLEN];
  602. u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
  603. } __attribute__ ((packed)) buf;
  604. hermes_t *hw = &priv->hw;
  605. int ret;
  606. int err;
  607. int k;
  608. u16 xmitting;
  609. key_idx &= 0x3;
  610. if (set_tx)
  611. key_idx |= 0x8000;
  612. buf.idx = cpu_to_le16(key_idx);
  613. memcpy(buf.key, key,
  614. sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
  615. if (rsc == NULL)
  616. memset(buf.rsc, 0, sizeof(buf.rsc));
  617. else
  618. memcpy(buf.rsc, rsc, sizeof(buf.rsc));
  619. if (tsc == NULL) {
  620. memset(buf.tsc, 0, sizeof(buf.tsc));
  621. buf.tsc[4] = 0x10;
  622. } else {
  623. memcpy(buf.tsc, tsc, sizeof(buf.tsc));
  624. }
  625. /* Wait upto 100ms for tx queue to empty */
  626. for (k = 100; k > 0; k--) {
  627. udelay(1000);
  628. ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
  629. &xmitting);
  630. if (ret || !xmitting)
  631. break;
  632. }
  633. if (k == 0)
  634. ret = -ETIMEDOUT;
  635. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  636. HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
  637. &buf);
  638. return ret ? ret : err;
  639. }
  640. int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
  641. {
  642. hermes_t *hw = &priv->hw;
  643. int err;
  644. memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
  645. err = hermes_write_wordrec(hw, USER_BAP,
  646. HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
  647. key_idx);
  648. if (err)
  649. printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
  650. priv->ndev->name, err, key_idx);
  651. return err;
  652. }
  653. int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
  654. struct dev_addr_list *mc_list,
  655. int mc_count, int promisc)
  656. {
  657. hermes_t *hw = &priv->hw;
  658. int err = 0;
  659. if (promisc != priv->promiscuous) {
  660. err = hermes_write_wordrec(hw, USER_BAP,
  661. HERMES_RID_CNFPROMISCUOUSMODE,
  662. promisc);
  663. if (err) {
  664. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  665. priv->ndev->name, err);
  666. } else
  667. priv->promiscuous = promisc;
  668. }
  669. /* If we're not in promiscuous mode, then we need to set the
  670. * group address if either we want to multicast, or if we were
  671. * multicasting and want to stop */
  672. if (!promisc && (mc_count || priv->mc_count)) {
  673. struct dev_mc_list *p = mc_list;
  674. struct hermes_multicast mclist;
  675. int i;
  676. for (i = 0; i < mc_count; i++) {
  677. /* paranoia: is list shorter than mc_count? */
  678. BUG_ON(!p);
  679. /* paranoia: bad address size in list? */
  680. BUG_ON(p->dmi_addrlen != ETH_ALEN);
  681. memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
  682. p = p->next;
  683. }
  684. if (p)
  685. printk(KERN_WARNING "%s: Multicast list is "
  686. "longer than mc_count\n", priv->ndev->name);
  687. err = hermes_write_ltv(hw, USER_BAP,
  688. HERMES_RID_CNFGROUPADDRESSES,
  689. HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
  690. &mclist);
  691. if (err)
  692. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  693. priv->ndev->name, err);
  694. else
  695. priv->mc_count = mc_count;
  696. }
  697. return err;
  698. }
  699. /* Return : < 0 -> error code ; >= 0 -> length */
  700. int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  701. char buf[IW_ESSID_MAX_SIZE+1])
  702. {
  703. hermes_t *hw = &priv->hw;
  704. int err = 0;
  705. struct hermes_idstring essidbuf;
  706. char *p = (char *)(&essidbuf.val);
  707. int len;
  708. unsigned long flags;
  709. if (orinoco_lock(priv, &flags) != 0)
  710. return -EBUSY;
  711. if (strlen(priv->desired_essid) > 0) {
  712. /* We read the desired SSID from the hardware rather
  713. than from priv->desired_essid, just in case the
  714. firmware is allowed to change it on us. I'm not
  715. sure about this */
  716. /* My guess is that the OWNSSID should always be whatever
  717. * we set to the card, whereas CURRENT_SSID is the one that
  718. * may change... - Jean II */
  719. u16 rid;
  720. *active = 1;
  721. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  722. HERMES_RID_CNFDESIREDSSID;
  723. err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  724. NULL, &essidbuf);
  725. if (err)
  726. goto fail_unlock;
  727. } else {
  728. *active = 0;
  729. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  730. sizeof(essidbuf), NULL, &essidbuf);
  731. if (err)
  732. goto fail_unlock;
  733. }
  734. len = le16_to_cpu(essidbuf.len);
  735. BUG_ON(len > IW_ESSID_MAX_SIZE);
  736. memset(buf, 0, IW_ESSID_MAX_SIZE);
  737. memcpy(buf, p, len);
  738. err = len;
  739. fail_unlock:
  740. orinoco_unlock(priv, &flags);
  741. return err;
  742. }
  743. int orinoco_hw_get_freq(struct orinoco_private *priv)
  744. {
  745. hermes_t *hw = &priv->hw;
  746. int err = 0;
  747. u16 channel;
  748. int freq = 0;
  749. unsigned long flags;
  750. if (orinoco_lock(priv, &flags) != 0)
  751. return -EBUSY;
  752. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
  753. &channel);
  754. if (err)
  755. goto out;
  756. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  757. if (channel == 0) {
  758. err = -EBUSY;
  759. goto out;
  760. }
  761. if ((channel < 1) || (channel > NUM_CHANNELS)) {
  762. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  763. priv->ndev->name, channel);
  764. err = -EBUSY;
  765. goto out;
  766. }
  767. freq = ieee80211_dsss_chan_to_freq(channel);
  768. out:
  769. orinoco_unlock(priv, &flags);
  770. if (err > 0)
  771. err = -EBUSY;
  772. return err ? err : freq;
  773. }
  774. int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  775. int *numrates, s32 *rates, int max)
  776. {
  777. hermes_t *hw = &priv->hw;
  778. struct hermes_idstring list;
  779. unsigned char *p = (unsigned char *)&list.val;
  780. int err = 0;
  781. int num;
  782. int i;
  783. unsigned long flags;
  784. if (orinoco_lock(priv, &flags) != 0)
  785. return -EBUSY;
  786. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  787. sizeof(list), NULL, &list);
  788. orinoco_unlock(priv, &flags);
  789. if (err)
  790. return err;
  791. num = le16_to_cpu(list.len);
  792. *numrates = num;
  793. num = min(num, max);
  794. for (i = 0; i < num; i++)
  795. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  796. return 0;
  797. }