hw.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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. }