hw.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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 <net/cfg80211.h>
  11. #include "hermes.h"
  12. #include "hermes_rid.h"
  13. #include "orinoco.h"
  14. #include "hw.h"
  15. #define SYMBOL_MAX_VER_LEN (14)
  16. /* Symbol firmware has a bug allocating buffers larger than this */
  17. #define TX_NICBUF_SIZE_BUG 1585
  18. /********************************************************************/
  19. /* Data tables */
  20. /********************************************************************/
  21. /* This tables gives the actual meanings of the bitrate IDs returned
  22. * by the firmware. */
  23. static const struct {
  24. int bitrate; /* in 100s of kilobits */
  25. int automatic;
  26. u16 agere_txratectrl;
  27. u16 intersil_txratectrl;
  28. } bitrate_table[] = {
  29. {110, 1, 3, 15}, /* Entry 0 is the default */
  30. {10, 0, 1, 1},
  31. {10, 1, 1, 1},
  32. {20, 0, 2, 2},
  33. {20, 1, 6, 3},
  34. {55, 0, 4, 4},
  35. {55, 1, 7, 7},
  36. {110, 0, 5, 8},
  37. };
  38. #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
  39. /* Firmware version encoding */
  40. struct comp_id {
  41. u16 id, variant, major, minor;
  42. } __packed;
  43. static inline enum fwtype determine_firmware_type(struct comp_id *nic_id)
  44. {
  45. if (nic_id->id < 0x8000)
  46. return FIRMWARE_TYPE_AGERE;
  47. else if (nic_id->id == 0x8000 && nic_id->major == 0)
  48. return FIRMWARE_TYPE_SYMBOL;
  49. else
  50. return FIRMWARE_TYPE_INTERSIL;
  51. }
  52. /* Set priv->firmware type, determine firmware properties
  53. * This function can be called before we have registerred with netdev,
  54. * so all errors go out with dev_* rather than printk
  55. *
  56. * If non-NULL stores a firmware description in fw_name.
  57. * If non-NULL stores a HW version in hw_ver
  58. *
  59. * These are output via generic cfg80211 ethtool support.
  60. */
  61. int determine_fw_capabilities(struct orinoco_private *priv,
  62. char *fw_name, size_t fw_name_len,
  63. u32 *hw_ver)
  64. {
  65. struct device *dev = priv->dev;
  66. struct hermes *hw = &priv->hw;
  67. int err;
  68. struct comp_id nic_id, sta_id;
  69. unsigned int firmver;
  70. char tmp[SYMBOL_MAX_VER_LEN + 1] __attribute__((aligned(2)));
  71. /* Get the hardware version */
  72. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
  73. if (err) {
  74. dev_err(dev, "Cannot read hardware identity: error %d\n",
  75. err);
  76. return err;
  77. }
  78. le16_to_cpus(&nic_id.id);
  79. le16_to_cpus(&nic_id.variant);
  80. le16_to_cpus(&nic_id.major);
  81. le16_to_cpus(&nic_id.minor);
  82. dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
  83. nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
  84. if (hw_ver)
  85. *hw_ver = (((nic_id.id & 0xff) << 24) |
  86. ((nic_id.variant & 0xff) << 16) |
  87. ((nic_id.major & 0xff) << 8) |
  88. (nic_id.minor & 0xff));
  89. priv->firmware_type = determine_firmware_type(&nic_id);
  90. /* Get the firmware version */
  91. err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
  92. if (err) {
  93. dev_err(dev, "Cannot read station identity: error %d\n",
  94. err);
  95. return err;
  96. }
  97. le16_to_cpus(&sta_id.id);
  98. le16_to_cpus(&sta_id.variant);
  99. le16_to_cpus(&sta_id.major);
  100. le16_to_cpus(&sta_id.minor);
  101. dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
  102. sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
  103. switch (sta_id.id) {
  104. case 0x15:
  105. dev_err(dev, "Primary firmware is active\n");
  106. return -ENODEV;
  107. case 0x14b:
  108. dev_err(dev, "Tertiary firmware is active\n");
  109. return -ENODEV;
  110. case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
  111. case 0x21: /* Symbol Spectrum24 Trilogy */
  112. break;
  113. default:
  114. dev_notice(dev, "Unknown station ID, please report\n");
  115. break;
  116. }
  117. /* Default capabilities */
  118. priv->has_sensitivity = 1;
  119. priv->has_mwo = 0;
  120. priv->has_preamble = 0;
  121. priv->has_port3 = 1;
  122. priv->has_ibss = 1;
  123. priv->has_wep = 0;
  124. priv->has_big_wep = 0;
  125. priv->has_alt_txcntl = 0;
  126. priv->has_ext_scan = 0;
  127. priv->has_wpa = 0;
  128. priv->do_fw_download = 0;
  129. /* Determine capabilities from the firmware version */
  130. switch (priv->firmware_type) {
  131. case FIRMWARE_TYPE_AGERE:
  132. /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
  133. ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
  134. if (fw_name)
  135. snprintf(fw_name, fw_name_len, "Lucent/Agere %d.%02d",
  136. sta_id.major, sta_id.minor);
  137. firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
  138. priv->has_ibss = (firmver >= 0x60006);
  139. priv->has_wep = (firmver >= 0x40020);
  140. priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
  141. Gold cards from the others? */
  142. priv->has_mwo = (firmver >= 0x60000);
  143. priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
  144. priv->ibss_port = 1;
  145. priv->has_hostscan = (firmver >= 0x8000a);
  146. priv->do_fw_download = 1;
  147. priv->broken_monitor = (firmver >= 0x80000);
  148. priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
  149. priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
  150. priv->has_wpa = (firmver >= 0x9002a);
  151. /* Tested with Agere firmware :
  152. * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
  153. * Tested CableTron firmware : 4.32 => Anton */
  154. break;
  155. case FIRMWARE_TYPE_SYMBOL:
  156. /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
  157. /* Intel MAC : 00:02:B3:* */
  158. /* 3Com MAC : 00:50:DA:* */
  159. memset(tmp, 0, sizeof(tmp));
  160. /* Get the Symbol firmware version */
  161. err = hw->ops->read_ltv(hw, USER_BAP,
  162. HERMES_RID_SECONDARYVERSION_SYMBOL,
  163. SYMBOL_MAX_VER_LEN, NULL, &tmp);
  164. if (err) {
  165. dev_warn(dev, "Error %d reading Symbol firmware info. "
  166. "Wildly guessing capabilities...\n", err);
  167. firmver = 0;
  168. tmp[0] = '\0';
  169. } else {
  170. /* The firmware revision is a string, the format is
  171. * something like : "V2.20-01".
  172. * Quick and dirty parsing... - Jean II
  173. */
  174. firmver = ((tmp[1] - '0') << 16)
  175. | ((tmp[3] - '0') << 12)
  176. | ((tmp[4] - '0') << 8)
  177. | ((tmp[6] - '0') << 4)
  178. | (tmp[7] - '0');
  179. tmp[SYMBOL_MAX_VER_LEN] = '\0';
  180. }
  181. if (fw_name)
  182. snprintf(fw_name, fw_name_len, "Symbol %s", tmp);
  183. priv->has_ibss = (firmver >= 0x20000);
  184. priv->has_wep = (firmver >= 0x15012);
  185. priv->has_big_wep = (firmver >= 0x20000);
  186. priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
  187. (firmver >= 0x29000 && firmver < 0x30000) ||
  188. firmver >= 0x31000;
  189. priv->has_preamble = (firmver >= 0x20000);
  190. priv->ibss_port = 4;
  191. /* Symbol firmware is found on various cards, but
  192. * there has been no attempt to check firmware
  193. * download on non-spectrum_cs based cards.
  194. *
  195. * Given that the Agere firmware download works
  196. * differently, we should avoid doing a firmware
  197. * download with the Symbol algorithm on non-spectrum
  198. * cards.
  199. *
  200. * For now we can identify a spectrum_cs based card
  201. * because it has a firmware reset function.
  202. */
  203. priv->do_fw_download = (priv->stop_fw != NULL);
  204. priv->broken_disableport = (firmver == 0x25013) ||
  205. (firmver >= 0x30000 && firmver <= 0x31000);
  206. priv->has_hostscan = (firmver >= 0x31001) ||
  207. (firmver >= 0x29057 && firmver < 0x30000);
  208. /* Tested with Intel firmware : 0x20015 => Jean II */
  209. /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
  210. break;
  211. case FIRMWARE_TYPE_INTERSIL:
  212. /* D-Link, Linksys, Adtron, ZoomAir, and many others...
  213. * Samsung, Compaq 100/200 and Proxim are slightly
  214. * different and less well tested */
  215. /* D-Link MAC : 00:40:05:* */
  216. /* Addtron MAC : 00:90:D1:* */
  217. if (fw_name)
  218. snprintf(fw_name, fw_name_len, "Intersil %d.%d.%d",
  219. sta_id.major, sta_id.minor, sta_id.variant);
  220. firmver = ((unsigned long)sta_id.major << 16) |
  221. ((unsigned long)sta_id.minor << 8) | sta_id.variant;
  222. priv->has_ibss = (firmver >= 0x000700); /* FIXME */
  223. priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
  224. priv->has_pm = (firmver >= 0x000700);
  225. priv->has_hostscan = (firmver >= 0x010301);
  226. if (firmver >= 0x000800)
  227. priv->ibss_port = 0;
  228. else {
  229. dev_notice(dev, "Intersil firmware earlier than v0.8.x"
  230. " - several features not supported\n");
  231. priv->ibss_port = 1;
  232. }
  233. break;
  234. }
  235. if (fw_name)
  236. dev_info(dev, "Firmware determined as %s\n", fw_name);
  237. #ifndef CONFIG_HERMES_PRISM
  238. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
  239. dev_err(dev, "Support for Prism chipset is not enabled\n");
  240. return -ENODEV;
  241. }
  242. #endif
  243. return 0;
  244. }
  245. /* Read settings from EEPROM into our private structure.
  246. * MAC address gets dropped into callers buffer
  247. * Can be called before netdev registration.
  248. */
  249. int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
  250. {
  251. struct device *dev = priv->dev;
  252. struct hermes_idstring nickbuf;
  253. struct hermes *hw = &priv->hw;
  254. int len;
  255. int err;
  256. u16 reclen;
  257. /* Get the MAC address */
  258. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  259. ETH_ALEN, NULL, dev_addr);
  260. if (err) {
  261. dev_warn(dev, "Failed to read MAC address!\n");
  262. goto out;
  263. }
  264. dev_dbg(dev, "MAC address %pM\n", dev_addr);
  265. /* Get the station name */
  266. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  267. sizeof(nickbuf), &reclen, &nickbuf);
  268. if (err) {
  269. dev_err(dev, "failed to read station name\n");
  270. goto out;
  271. }
  272. if (nickbuf.len)
  273. len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
  274. else
  275. len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
  276. memcpy(priv->nick, &nickbuf.val, len);
  277. priv->nick[len] = '\0';
  278. dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
  279. /* Get allowed channels */
  280. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
  281. &priv->channel_mask);
  282. if (err) {
  283. dev_err(dev, "Failed to read channel list!\n");
  284. goto out;
  285. }
  286. /* Get initial AP density */
  287. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
  288. &priv->ap_density);
  289. if (err || priv->ap_density < 1 || priv->ap_density > 3)
  290. priv->has_sensitivity = 0;
  291. /* Get initial RTS threshold */
  292. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  293. &priv->rts_thresh);
  294. if (err) {
  295. dev_err(dev, "Failed to read RTS threshold!\n");
  296. goto out;
  297. }
  298. /* Get initial fragmentation settings */
  299. if (priv->has_mwo)
  300. err = hermes_read_wordrec(hw, USER_BAP,
  301. HERMES_RID_CNFMWOROBUST_AGERE,
  302. &priv->mwo_robust);
  303. else
  304. err = hermes_read_wordrec(hw, USER_BAP,
  305. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  306. &priv->frag_thresh);
  307. if (err) {
  308. dev_err(dev, "Failed to read fragmentation settings!\n");
  309. goto out;
  310. }
  311. /* Power management setup */
  312. if (priv->has_pm) {
  313. priv->pm_on = 0;
  314. priv->pm_mcast = 1;
  315. err = hermes_read_wordrec(hw, USER_BAP,
  316. HERMES_RID_CNFMAXSLEEPDURATION,
  317. &priv->pm_period);
  318. if (err) {
  319. dev_err(dev, "Failed to read power management "
  320. "period!\n");
  321. goto out;
  322. }
  323. err = hermes_read_wordrec(hw, USER_BAP,
  324. HERMES_RID_CNFPMHOLDOVERDURATION,
  325. &priv->pm_timeout);
  326. if (err) {
  327. dev_err(dev, "Failed to read power management "
  328. "timeout!\n");
  329. goto out;
  330. }
  331. }
  332. /* Preamble setup */
  333. if (priv->has_preamble) {
  334. err = hermes_read_wordrec(hw, USER_BAP,
  335. HERMES_RID_CNFPREAMBLE_SYMBOL,
  336. &priv->preamble);
  337. if (err) {
  338. dev_err(dev, "Failed to read preamble setup\n");
  339. goto out;
  340. }
  341. }
  342. /* Retry settings */
  343. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  344. &priv->short_retry_limit);
  345. if (err) {
  346. dev_err(dev, "Failed to read short retry limit\n");
  347. goto out;
  348. }
  349. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  350. &priv->long_retry_limit);
  351. if (err) {
  352. dev_err(dev, "Failed to read long retry limit\n");
  353. goto out;
  354. }
  355. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  356. &priv->retry_lifetime);
  357. if (err) {
  358. dev_err(dev, "Failed to read max retry lifetime\n");
  359. goto out;
  360. }
  361. out:
  362. return err;
  363. }
  364. /* Can be called before netdev registration */
  365. int orinoco_hw_allocate_fid(struct orinoco_private *priv)
  366. {
  367. struct device *dev = priv->dev;
  368. struct hermes *hw = &priv->hw;
  369. int err;
  370. err = hw->ops->allocate(hw, priv->nicbuf_size, &priv->txfid);
  371. if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
  372. /* Try workaround for old Symbol firmware bug */
  373. priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
  374. err = hw->ops->allocate(hw, priv->nicbuf_size, &priv->txfid);
  375. dev_warn(dev, "Firmware ALLOC bug detected "
  376. "(old Symbol firmware?). Work around %s\n",
  377. err ? "failed!" : "ok.");
  378. }
  379. return err;
  380. }
  381. int orinoco_get_bitratemode(int bitrate, int automatic)
  382. {
  383. int ratemode = -1;
  384. int i;
  385. if ((bitrate != 10) && (bitrate != 20) &&
  386. (bitrate != 55) && (bitrate != 110))
  387. return ratemode;
  388. for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
  389. if ((bitrate_table[i].bitrate == bitrate) &&
  390. (bitrate_table[i].automatic == automatic)) {
  391. ratemode = i;
  392. break;
  393. }
  394. }
  395. return ratemode;
  396. }
  397. void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
  398. {
  399. BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
  400. *bitrate = bitrate_table[ratemode].bitrate * 100000;
  401. *automatic = bitrate_table[ratemode].automatic;
  402. }
  403. int orinoco_hw_program_rids(struct orinoco_private *priv)
  404. {
  405. struct net_device *dev = priv->ndev;
  406. struct wireless_dev *wdev = netdev_priv(dev);
  407. struct hermes *hw = &priv->hw;
  408. int err;
  409. struct hermes_idstring idbuf;
  410. /* Set the MAC address */
  411. err = hw->ops->write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
  412. HERMES_BYTES_TO_RECLEN(ETH_ALEN),
  413. dev->dev_addr);
  414. if (err) {
  415. printk(KERN_ERR "%s: Error %d setting MAC address\n",
  416. dev->name, err);
  417. return err;
  418. }
  419. /* Set up the link mode */
  420. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
  421. priv->port_type);
  422. if (err) {
  423. printk(KERN_ERR "%s: Error %d setting port type\n",
  424. dev->name, err);
  425. return err;
  426. }
  427. /* Set the channel/frequency */
  428. if (priv->channel != 0 && priv->iw_mode != NL80211_IFTYPE_STATION) {
  429. err = hermes_write_wordrec(hw, USER_BAP,
  430. HERMES_RID_CNFOWNCHANNEL,
  431. priv->channel);
  432. if (err) {
  433. printk(KERN_ERR "%s: Error %d setting channel %d\n",
  434. dev->name, err, priv->channel);
  435. return err;
  436. }
  437. }
  438. if (priv->has_ibss) {
  439. u16 createibss;
  440. if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
  441. printk(KERN_WARNING "%s: This firmware requires an "
  442. "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
  443. /* With wvlan_cs, in this case, we would crash.
  444. * hopefully, this driver will behave better...
  445. * Jean II */
  446. createibss = 0;
  447. } else {
  448. createibss = priv->createibss;
  449. }
  450. err = hermes_write_wordrec(hw, USER_BAP,
  451. HERMES_RID_CNFCREATEIBSS,
  452. createibss);
  453. if (err) {
  454. printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
  455. dev->name, err);
  456. return err;
  457. }
  458. }
  459. /* Set the desired BSSID */
  460. err = __orinoco_hw_set_wap(priv);
  461. if (err) {
  462. printk(KERN_ERR "%s: Error %d setting AP address\n",
  463. dev->name, err);
  464. return err;
  465. }
  466. /* Set the desired ESSID */
  467. idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
  468. memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
  469. /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
  470. err = hw->ops->write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
  471. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid) + 2),
  472. &idbuf);
  473. if (err) {
  474. printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
  475. dev->name, err);
  476. return err;
  477. }
  478. err = hw->ops->write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
  479. HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid) + 2),
  480. &idbuf);
  481. if (err) {
  482. printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
  483. dev->name, err);
  484. return err;
  485. }
  486. /* Set the station name */
  487. idbuf.len = cpu_to_le16(strlen(priv->nick));
  488. memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
  489. err = hw->ops->write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
  490. HERMES_BYTES_TO_RECLEN(strlen(priv->nick) + 2),
  491. &idbuf);
  492. if (err) {
  493. printk(KERN_ERR "%s: Error %d setting nickname\n",
  494. dev->name, err);
  495. return err;
  496. }
  497. /* Set AP density */
  498. if (priv->has_sensitivity) {
  499. err = hermes_write_wordrec(hw, USER_BAP,
  500. HERMES_RID_CNFSYSTEMSCALE,
  501. priv->ap_density);
  502. if (err) {
  503. printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
  504. "Disabling sensitivity control\n",
  505. dev->name, err);
  506. priv->has_sensitivity = 0;
  507. }
  508. }
  509. /* Set RTS threshold */
  510. err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
  511. priv->rts_thresh);
  512. if (err) {
  513. printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
  514. dev->name, err);
  515. return err;
  516. }
  517. /* Set fragmentation threshold or MWO robustness */
  518. if (priv->has_mwo)
  519. err = hermes_write_wordrec(hw, USER_BAP,
  520. HERMES_RID_CNFMWOROBUST_AGERE,
  521. priv->mwo_robust);
  522. else
  523. err = hermes_write_wordrec(hw, USER_BAP,
  524. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  525. priv->frag_thresh);
  526. if (err) {
  527. printk(KERN_ERR "%s: Error %d setting fragmentation\n",
  528. dev->name, err);
  529. return err;
  530. }
  531. /* Set bitrate */
  532. err = __orinoco_hw_set_bitrate(priv);
  533. if (err) {
  534. printk(KERN_ERR "%s: Error %d setting bitrate\n",
  535. dev->name, err);
  536. return err;
  537. }
  538. /* Set power management */
  539. if (priv->has_pm) {
  540. err = hermes_write_wordrec(hw, USER_BAP,
  541. HERMES_RID_CNFPMENABLED,
  542. priv->pm_on);
  543. if (err) {
  544. printk(KERN_ERR "%s: Error %d setting up PM\n",
  545. dev->name, err);
  546. return err;
  547. }
  548. err = hermes_write_wordrec(hw, USER_BAP,
  549. HERMES_RID_CNFMULTICASTRECEIVE,
  550. priv->pm_mcast);
  551. if (err) {
  552. printk(KERN_ERR "%s: Error %d setting up PM\n",
  553. dev->name, err);
  554. return err;
  555. }
  556. err = hermes_write_wordrec(hw, USER_BAP,
  557. HERMES_RID_CNFMAXSLEEPDURATION,
  558. priv->pm_period);
  559. if (err) {
  560. printk(KERN_ERR "%s: Error %d setting up PM\n",
  561. dev->name, err);
  562. return err;
  563. }
  564. err = hermes_write_wordrec(hw, USER_BAP,
  565. HERMES_RID_CNFPMHOLDOVERDURATION,
  566. priv->pm_timeout);
  567. if (err) {
  568. printk(KERN_ERR "%s: Error %d setting up PM\n",
  569. dev->name, err);
  570. return err;
  571. }
  572. }
  573. /* Set preamble - only for Symbol so far... */
  574. if (priv->has_preamble) {
  575. err = hermes_write_wordrec(hw, USER_BAP,
  576. HERMES_RID_CNFPREAMBLE_SYMBOL,
  577. priv->preamble);
  578. if (err) {
  579. printk(KERN_ERR "%s: Error %d setting preamble\n",
  580. dev->name, err);
  581. return err;
  582. }
  583. }
  584. /* Set up encryption */
  585. if (priv->has_wep || priv->has_wpa) {
  586. err = __orinoco_hw_setup_enc(priv);
  587. if (err) {
  588. printk(KERN_ERR "%s: Error %d activating encryption\n",
  589. dev->name, err);
  590. return err;
  591. }
  592. }
  593. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  594. /* Enable monitor mode */
  595. dev->type = ARPHRD_IEEE80211;
  596. err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
  597. HERMES_TEST_MONITOR, 0, NULL);
  598. } else {
  599. /* Disable monitor mode */
  600. dev->type = ARPHRD_ETHER;
  601. err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
  602. HERMES_TEST_STOP, 0, NULL);
  603. }
  604. if (err)
  605. return err;
  606. /* Reset promiscuity / multicast*/
  607. priv->promiscuous = 0;
  608. priv->mc_count = 0;
  609. /* Record mode change */
  610. wdev->iftype = priv->iw_mode;
  611. return 0;
  612. }
  613. /* Get tsc from the firmware */
  614. int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
  615. {
  616. struct hermes *hw = &priv->hw;
  617. int err = 0;
  618. u8 tsc_arr[4][ORINOCO_SEQ_LEN];
  619. if ((key < 0) || (key >= 4))
  620. return -EINVAL;
  621. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
  622. sizeof(tsc_arr), NULL, &tsc_arr);
  623. if (!err)
  624. memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
  625. return err;
  626. }
  627. int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
  628. {
  629. struct hermes *hw = &priv->hw;
  630. int ratemode = priv->bitratemode;
  631. int err = 0;
  632. if (ratemode >= BITRATE_TABLE_SIZE) {
  633. printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
  634. priv->ndev->name, ratemode);
  635. return -EINVAL;
  636. }
  637. switch (priv->firmware_type) {
  638. case FIRMWARE_TYPE_AGERE:
  639. err = hermes_write_wordrec(hw, USER_BAP,
  640. HERMES_RID_CNFTXRATECONTROL,
  641. bitrate_table[ratemode].agere_txratectrl);
  642. break;
  643. case FIRMWARE_TYPE_INTERSIL:
  644. case FIRMWARE_TYPE_SYMBOL:
  645. err = hermes_write_wordrec(hw, USER_BAP,
  646. HERMES_RID_CNFTXRATECONTROL,
  647. bitrate_table[ratemode].intersil_txratectrl);
  648. break;
  649. default:
  650. BUG();
  651. }
  652. return err;
  653. }
  654. int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
  655. {
  656. struct hermes *hw = &priv->hw;
  657. int i;
  658. int err = 0;
  659. u16 val;
  660. err = hermes_read_wordrec(hw, USER_BAP,
  661. HERMES_RID_CURRENTTXRATE, &val);
  662. if (err)
  663. return err;
  664. switch (priv->firmware_type) {
  665. case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
  666. /* Note : in Lucent firmware, the return value of
  667. * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
  668. * and therefore is totally different from the
  669. * encoding of HERMES_RID_CNFTXRATECONTROL.
  670. * Don't forget that 6Mb/s is really 5.5Mb/s */
  671. if (val == 6)
  672. *bitrate = 5500000;
  673. else
  674. *bitrate = val * 1000000;
  675. break;
  676. case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
  677. case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
  678. for (i = 0; i < BITRATE_TABLE_SIZE; i++)
  679. if (bitrate_table[i].intersil_txratectrl == val) {
  680. *bitrate = bitrate_table[i].bitrate * 100000;
  681. break;
  682. }
  683. if (i >= BITRATE_TABLE_SIZE) {
  684. printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
  685. priv->ndev->name, val);
  686. err = -EIO;
  687. }
  688. break;
  689. default:
  690. BUG();
  691. }
  692. return err;
  693. }
  694. /* Set fixed AP address */
  695. int __orinoco_hw_set_wap(struct orinoco_private *priv)
  696. {
  697. int roaming_flag;
  698. int err = 0;
  699. struct hermes *hw = &priv->hw;
  700. switch (priv->firmware_type) {
  701. case FIRMWARE_TYPE_AGERE:
  702. /* not supported */
  703. break;
  704. case FIRMWARE_TYPE_INTERSIL:
  705. if (priv->bssid_fixed)
  706. roaming_flag = 2;
  707. else
  708. roaming_flag = 1;
  709. err = hermes_write_wordrec(hw, USER_BAP,
  710. HERMES_RID_CNFROAMINGMODE,
  711. roaming_flag);
  712. break;
  713. case FIRMWARE_TYPE_SYMBOL:
  714. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  715. HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
  716. &priv->desired_bssid);
  717. break;
  718. }
  719. return err;
  720. }
  721. /* Change the WEP keys and/or the current keys. Can be called
  722. * either from __orinoco_hw_setup_enc() or directly from
  723. * orinoco_ioctl_setiwencode(). In the later case the association
  724. * with the AP is not broken (if the firmware can handle it),
  725. * which is needed for 802.1x implementations. */
  726. int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
  727. {
  728. struct hermes *hw = &priv->hw;
  729. int err = 0;
  730. int i;
  731. switch (priv->firmware_type) {
  732. case FIRMWARE_TYPE_AGERE:
  733. {
  734. struct orinoco_key keys[ORINOCO_MAX_KEYS];
  735. memset(&keys, 0, sizeof(keys));
  736. for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
  737. int len = min(priv->keys[i].key_len,
  738. ORINOCO_MAX_KEY_SIZE);
  739. memcpy(&keys[i].data, priv->keys[i].key, len);
  740. if (len > SMALL_KEY_SIZE)
  741. keys[i].len = cpu_to_le16(LARGE_KEY_SIZE);
  742. else if (len > 0)
  743. keys[i].len = cpu_to_le16(SMALL_KEY_SIZE);
  744. else
  745. keys[i].len = cpu_to_le16(0);
  746. }
  747. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  748. HERMES_RID_CNFWEPKEYS_AGERE,
  749. &keys);
  750. if (err)
  751. return err;
  752. err = hermes_write_wordrec(hw, USER_BAP,
  753. HERMES_RID_CNFTXKEY_AGERE,
  754. priv->tx_key);
  755. if (err)
  756. return err;
  757. break;
  758. }
  759. case FIRMWARE_TYPE_INTERSIL:
  760. case FIRMWARE_TYPE_SYMBOL:
  761. {
  762. int keylen;
  763. /* Force uniform key length to work around
  764. * firmware bugs */
  765. keylen = priv->keys[priv->tx_key].key_len;
  766. if (keylen > LARGE_KEY_SIZE) {
  767. printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
  768. priv->ndev->name, priv->tx_key, keylen);
  769. return -E2BIG;
  770. } else if (keylen > SMALL_KEY_SIZE)
  771. keylen = LARGE_KEY_SIZE;
  772. else if (keylen > 0)
  773. keylen = SMALL_KEY_SIZE;
  774. else
  775. keylen = 0;
  776. /* Write all 4 keys */
  777. for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
  778. u8 key[LARGE_KEY_SIZE] = { 0 };
  779. memcpy(key, priv->keys[i].key,
  780. priv->keys[i].key_len);
  781. err = hw->ops->write_ltv(hw, USER_BAP,
  782. HERMES_RID_CNFDEFAULTKEY0 + i,
  783. HERMES_BYTES_TO_RECLEN(keylen),
  784. key);
  785. if (err)
  786. return err;
  787. }
  788. /* Write the index of the key used in transmission */
  789. err = hermes_write_wordrec(hw, USER_BAP,
  790. HERMES_RID_CNFWEPDEFAULTKEYID,
  791. priv->tx_key);
  792. if (err)
  793. return err;
  794. }
  795. break;
  796. }
  797. return 0;
  798. }
  799. int __orinoco_hw_setup_enc(struct orinoco_private *priv)
  800. {
  801. struct hermes *hw = &priv->hw;
  802. int err = 0;
  803. int master_wep_flag;
  804. int auth_flag;
  805. int enc_flag;
  806. /* Setup WEP keys */
  807. if (priv->encode_alg == ORINOCO_ALG_WEP)
  808. __orinoco_hw_setup_wepkeys(priv);
  809. if (priv->wep_restrict)
  810. auth_flag = HERMES_AUTH_SHARED_KEY;
  811. else
  812. auth_flag = HERMES_AUTH_OPEN;
  813. if (priv->wpa_enabled)
  814. enc_flag = 2;
  815. else if (priv->encode_alg == ORINOCO_ALG_WEP)
  816. enc_flag = 1;
  817. else
  818. enc_flag = 0;
  819. switch (priv->firmware_type) {
  820. case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
  821. if (priv->encode_alg == ORINOCO_ALG_WEP) {
  822. /* Enable the shared-key authentication. */
  823. err = hermes_write_wordrec(hw, USER_BAP,
  824. HERMES_RID_CNFAUTHENTICATION_AGERE,
  825. auth_flag);
  826. }
  827. err = hermes_write_wordrec(hw, USER_BAP,
  828. HERMES_RID_CNFWEPENABLED_AGERE,
  829. enc_flag);
  830. if (err)
  831. return err;
  832. if (priv->has_wpa) {
  833. /* Set WPA key management */
  834. err = hermes_write_wordrec(hw, USER_BAP,
  835. HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
  836. priv->key_mgmt);
  837. if (err)
  838. return err;
  839. }
  840. break;
  841. case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
  842. case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
  843. if (priv->encode_alg == ORINOCO_ALG_WEP) {
  844. if (priv->wep_restrict ||
  845. (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
  846. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
  847. HERMES_WEP_EXCL_UNENCRYPTED;
  848. else
  849. master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
  850. err = hermes_write_wordrec(hw, USER_BAP,
  851. HERMES_RID_CNFAUTHENTICATION,
  852. auth_flag);
  853. if (err)
  854. return err;
  855. } else
  856. master_wep_flag = 0;
  857. if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
  858. master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
  859. /* Master WEP setting : on/off */
  860. err = hermes_write_wordrec(hw, USER_BAP,
  861. HERMES_RID_CNFWEPFLAGS_INTERSIL,
  862. master_wep_flag);
  863. if (err)
  864. return err;
  865. break;
  866. }
  867. return 0;
  868. }
  869. /* key must be 32 bytes, including the tx and rx MIC keys.
  870. * rsc must be NULL or up to 8 bytes
  871. * tsc must be NULL or up to 8 bytes
  872. */
  873. int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
  874. int set_tx, const u8 *key, const u8 *rsc,
  875. size_t rsc_len, const u8 *tsc, size_t tsc_len)
  876. {
  877. struct {
  878. __le16 idx;
  879. u8 rsc[ORINOCO_SEQ_LEN];
  880. u8 key[TKIP_KEYLEN];
  881. u8 tx_mic[MIC_KEYLEN];
  882. u8 rx_mic[MIC_KEYLEN];
  883. u8 tsc[ORINOCO_SEQ_LEN];
  884. } __packed buf;
  885. struct hermes *hw = &priv->hw;
  886. int ret;
  887. int err;
  888. int k;
  889. u16 xmitting;
  890. key_idx &= 0x3;
  891. if (set_tx)
  892. key_idx |= 0x8000;
  893. buf.idx = cpu_to_le16(key_idx);
  894. memcpy(buf.key, key,
  895. sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
  896. if (rsc_len > sizeof(buf.rsc))
  897. rsc_len = sizeof(buf.rsc);
  898. if (tsc_len > sizeof(buf.tsc))
  899. tsc_len = sizeof(buf.tsc);
  900. memset(buf.rsc, 0, sizeof(buf.rsc));
  901. memset(buf.tsc, 0, sizeof(buf.tsc));
  902. if (rsc != NULL)
  903. memcpy(buf.rsc, rsc, rsc_len);
  904. if (tsc != NULL)
  905. memcpy(buf.tsc, tsc, tsc_len);
  906. else
  907. buf.tsc[4] = 0x10;
  908. /* Wait up to 100ms for tx queue to empty */
  909. for (k = 100; k > 0; k--) {
  910. udelay(1000);
  911. ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
  912. &xmitting);
  913. if (ret || !xmitting)
  914. break;
  915. }
  916. if (k == 0)
  917. ret = -ETIMEDOUT;
  918. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  919. HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
  920. &buf);
  921. return ret ? ret : err;
  922. }
  923. int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
  924. {
  925. struct hermes *hw = &priv->hw;
  926. int err;
  927. err = hermes_write_wordrec(hw, USER_BAP,
  928. HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
  929. key_idx);
  930. if (err)
  931. printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
  932. priv->ndev->name, err, key_idx);
  933. return err;
  934. }
  935. int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
  936. struct net_device *dev,
  937. int mc_count, int promisc)
  938. {
  939. struct hermes *hw = &priv->hw;
  940. int err = 0;
  941. if (promisc != priv->promiscuous) {
  942. err = hermes_write_wordrec(hw, USER_BAP,
  943. HERMES_RID_CNFPROMISCUOUSMODE,
  944. promisc);
  945. if (err) {
  946. printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
  947. priv->ndev->name, err);
  948. } else
  949. priv->promiscuous = promisc;
  950. }
  951. /* If we're not in promiscuous mode, then we need to set the
  952. * group address if either we want to multicast, or if we were
  953. * multicasting and want to stop */
  954. if (!promisc && (mc_count || priv->mc_count)) {
  955. struct netdev_hw_addr *ha;
  956. struct hermes_multicast mclist;
  957. int i = 0;
  958. netdev_for_each_mc_addr(ha, dev) {
  959. if (i == mc_count)
  960. break;
  961. memcpy(mclist.addr[i++], ha->addr, ETH_ALEN);
  962. }
  963. err = hw->ops->write_ltv(hw, USER_BAP,
  964. HERMES_RID_CNFGROUPADDRESSES,
  965. HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
  966. &mclist);
  967. if (err)
  968. printk(KERN_ERR "%s: Error %d setting multicast list.\n",
  969. priv->ndev->name, err);
  970. else
  971. priv->mc_count = mc_count;
  972. }
  973. return err;
  974. }
  975. /* Return : < 0 -> error code ; >= 0 -> length */
  976. int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
  977. char buf[IW_ESSID_MAX_SIZE + 1])
  978. {
  979. struct hermes *hw = &priv->hw;
  980. int err = 0;
  981. struct hermes_idstring essidbuf;
  982. char *p = (char *)(&essidbuf.val);
  983. int len;
  984. unsigned long flags;
  985. if (orinoco_lock(priv, &flags) != 0)
  986. return -EBUSY;
  987. if (strlen(priv->desired_essid) > 0) {
  988. /* We read the desired SSID from the hardware rather
  989. than from priv->desired_essid, just in case the
  990. firmware is allowed to change it on us. I'm not
  991. sure about this */
  992. /* My guess is that the OWNSSID should always be whatever
  993. * we set to the card, whereas CURRENT_SSID is the one that
  994. * may change... - Jean II */
  995. u16 rid;
  996. *active = 1;
  997. rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
  998. HERMES_RID_CNFDESIREDSSID;
  999. err = hw->ops->read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
  1000. NULL, &essidbuf);
  1001. if (err)
  1002. goto fail_unlock;
  1003. } else {
  1004. *active = 0;
  1005. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
  1006. sizeof(essidbuf), NULL, &essidbuf);
  1007. if (err)
  1008. goto fail_unlock;
  1009. }
  1010. len = le16_to_cpu(essidbuf.len);
  1011. BUG_ON(len > IW_ESSID_MAX_SIZE);
  1012. memset(buf, 0, IW_ESSID_MAX_SIZE);
  1013. memcpy(buf, p, len);
  1014. err = len;
  1015. fail_unlock:
  1016. orinoco_unlock(priv, &flags);
  1017. return err;
  1018. }
  1019. int orinoco_hw_get_freq(struct orinoco_private *priv)
  1020. {
  1021. struct hermes *hw = &priv->hw;
  1022. int err = 0;
  1023. u16 channel;
  1024. int freq = 0;
  1025. unsigned long flags;
  1026. if (orinoco_lock(priv, &flags) != 0)
  1027. return -EBUSY;
  1028. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
  1029. &channel);
  1030. if (err)
  1031. goto out;
  1032. /* Intersil firmware 1.3.5 returns 0 when the interface is down */
  1033. if (channel == 0) {
  1034. err = -EBUSY;
  1035. goto out;
  1036. }
  1037. if ((channel < 1) || (channel > NUM_CHANNELS)) {
  1038. printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
  1039. priv->ndev->name, channel);
  1040. err = -EBUSY;
  1041. goto out;
  1042. }
  1043. freq = ieee80211_channel_to_frequency(channel, IEEE80211_BAND_2GHZ);
  1044. out:
  1045. orinoco_unlock(priv, &flags);
  1046. if (err > 0)
  1047. err = -EBUSY;
  1048. return err ? err : freq;
  1049. }
  1050. int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
  1051. int *numrates, s32 *rates, int max)
  1052. {
  1053. struct hermes *hw = &priv->hw;
  1054. struct hermes_idstring list;
  1055. unsigned char *p = (unsigned char *)&list.val;
  1056. int err = 0;
  1057. int num;
  1058. int i;
  1059. unsigned long flags;
  1060. if (orinoco_lock(priv, &flags) != 0)
  1061. return -EBUSY;
  1062. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
  1063. sizeof(list), NULL, &list);
  1064. orinoco_unlock(priv, &flags);
  1065. if (err)
  1066. return err;
  1067. num = le16_to_cpu(list.len);
  1068. *numrates = num;
  1069. num = min(num, max);
  1070. for (i = 0; i < num; i++)
  1071. rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
  1072. return 0;
  1073. }
  1074. int orinoco_hw_trigger_scan(struct orinoco_private *priv,
  1075. const struct cfg80211_ssid *ssid)
  1076. {
  1077. struct net_device *dev = priv->ndev;
  1078. struct hermes *hw = &priv->hw;
  1079. unsigned long flags;
  1080. int err = 0;
  1081. if (orinoco_lock(priv, &flags) != 0)
  1082. return -EBUSY;
  1083. /* Scanning with port 0 disabled would fail */
  1084. if (!netif_running(dev)) {
  1085. err = -ENETDOWN;
  1086. goto out;
  1087. }
  1088. /* In monitor mode, the scan results are always empty.
  1089. * Probe responses are passed to the driver as received
  1090. * frames and could be processed in software. */
  1091. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  1092. err = -EOPNOTSUPP;
  1093. goto out;
  1094. }
  1095. if (priv->has_hostscan) {
  1096. switch (priv->firmware_type) {
  1097. case FIRMWARE_TYPE_SYMBOL:
  1098. err = hermes_write_wordrec(hw, USER_BAP,
  1099. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  1100. HERMES_HOSTSCAN_SYMBOL_ONCE |
  1101. HERMES_HOSTSCAN_SYMBOL_BCAST);
  1102. break;
  1103. case FIRMWARE_TYPE_INTERSIL: {
  1104. __le16 req[3];
  1105. req[0] = cpu_to_le16(0x3fff); /* All channels */
  1106. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  1107. req[2] = 0; /* Any ESSID */
  1108. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1109. HERMES_RID_CNFHOSTSCAN, &req);
  1110. break;
  1111. }
  1112. case FIRMWARE_TYPE_AGERE:
  1113. if (ssid->ssid_len > 0) {
  1114. struct hermes_idstring idbuf;
  1115. size_t len = ssid->ssid_len;
  1116. idbuf.len = cpu_to_le16(len);
  1117. memcpy(idbuf.val, ssid->ssid, len);
  1118. err = hw->ops->write_ltv(hw, USER_BAP,
  1119. HERMES_RID_CNFSCANSSID_AGERE,
  1120. HERMES_BYTES_TO_RECLEN(len + 2),
  1121. &idbuf);
  1122. } else
  1123. err = hermes_write_wordrec(hw, USER_BAP,
  1124. HERMES_RID_CNFSCANSSID_AGERE,
  1125. 0); /* Any ESSID */
  1126. if (err)
  1127. break;
  1128. if (priv->has_ext_scan) {
  1129. err = hermes_write_wordrec(hw, USER_BAP,
  1130. HERMES_RID_CNFSCANCHANNELS2GHZ,
  1131. 0x7FFF);
  1132. if (err)
  1133. goto out;
  1134. err = hermes_inquire(hw,
  1135. HERMES_INQ_CHANNELINFO);
  1136. } else
  1137. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1138. break;
  1139. }
  1140. } else
  1141. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1142. out:
  1143. orinoco_unlock(priv, &flags);
  1144. return err;
  1145. }
  1146. /* Disassociate from node with BSSID addr */
  1147. int orinoco_hw_disassociate(struct orinoco_private *priv,
  1148. u8 *addr, u16 reason_code)
  1149. {
  1150. struct hermes *hw = &priv->hw;
  1151. int err;
  1152. struct {
  1153. u8 addr[ETH_ALEN];
  1154. __le16 reason_code;
  1155. } __packed buf;
  1156. /* Currently only supported by WPA enabled Agere fw */
  1157. if (!priv->has_wpa)
  1158. return -EOPNOTSUPP;
  1159. memcpy(buf.addr, addr, ETH_ALEN);
  1160. buf.reason_code = cpu_to_le16(reason_code);
  1161. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1162. HERMES_RID_CNFDISASSOCIATE,
  1163. &buf);
  1164. return err;
  1165. }
  1166. int orinoco_hw_get_current_bssid(struct orinoco_private *priv,
  1167. u8 *addr)
  1168. {
  1169. struct hermes *hw = &priv->hw;
  1170. int err;
  1171. err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  1172. ETH_ALEN, NULL, addr);
  1173. return err;
  1174. }