wext.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. /* Wireless extensions support.
  2. *
  3. * See copyright notice in main.c
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/if_arp.h>
  7. #include <linux/wireless.h>
  8. #include <linux/ieee80211.h>
  9. #include <net/iw_handler.h>
  10. #include <net/cfg80211.h>
  11. #include "hermes.h"
  12. #include "hermes_rid.h"
  13. #include "orinoco.h"
  14. #include "hw.h"
  15. #include "mic.h"
  16. #include "scan.h"
  17. #include "main.h"
  18. #include "wext.h"
  19. #define MAX_RID_LEN 1024
  20. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  21. {
  22. struct orinoco_private *priv = ndev_priv(dev);
  23. hermes_t *hw = &priv->hw;
  24. struct iw_statistics *wstats = &priv->wstats;
  25. int err;
  26. unsigned long flags;
  27. if (!netif_device_present(dev)) {
  28. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  29. dev->name);
  30. return NULL; /* FIXME: Can we do better than this? */
  31. }
  32. /* If busy, return the old stats. Returning NULL may cause
  33. * the interface to disappear from /proc/net/wireless */
  34. if (orinoco_lock(priv, &flags) != 0)
  35. return wstats;
  36. /* We can't really wait for the tallies inquiry command to
  37. * complete, so we just use the previous results and trigger
  38. * a new tallies inquiry command for next time - Jean II */
  39. /* FIXME: Really we should wait for the inquiry to come back -
  40. * as it is the stats we give don't make a whole lot of sense.
  41. * Unfortunately, it's not clear how to do that within the
  42. * wireless extensions framework: I think we're in user
  43. * context, but a lock seems to be held by the time we get in
  44. * here so we're not safe to sleep here. */
  45. hermes_inquire(hw, HERMES_INQ_TALLIES);
  46. if (priv->iw_mode == NL80211_IFTYPE_ADHOC) {
  47. memset(&wstats->qual, 0, sizeof(wstats->qual));
  48. /* If a spy address is defined, we report stats of the
  49. * first spy address - Jean II */
  50. if (SPY_NUMBER(priv)) {
  51. wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
  52. wstats->qual.level = priv->spy_data.spy_stat[0].level;
  53. wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
  54. wstats->qual.updated =
  55. priv->spy_data.spy_stat[0].updated;
  56. }
  57. } else {
  58. struct {
  59. __le16 qual, signal, noise, unused;
  60. } __attribute__ ((packed)) cq;
  61. err = HERMES_READ_RECORD(hw, USER_BAP,
  62. HERMES_RID_COMMSQUALITY, &cq);
  63. if (!err) {
  64. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  65. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  66. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  67. wstats->qual.updated =
  68. IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  69. }
  70. }
  71. orinoco_unlock(priv, &flags);
  72. return wstats;
  73. }
  74. /********************************************************************/
  75. /* Wireless extensions */
  76. /********************************************************************/
  77. static int orinoco_ioctl_setwap(struct net_device *dev,
  78. struct iw_request_info *info,
  79. struct sockaddr *ap_addr,
  80. char *extra)
  81. {
  82. struct orinoco_private *priv = ndev_priv(dev);
  83. int err = -EINPROGRESS; /* Call commit handler */
  84. unsigned long flags;
  85. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  86. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  87. if (orinoco_lock(priv, &flags) != 0)
  88. return -EBUSY;
  89. /* Enable automatic roaming - no sanity checks are needed */
  90. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  91. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  92. priv->bssid_fixed = 0;
  93. memset(priv->desired_bssid, 0, ETH_ALEN);
  94. /* "off" means keep existing connection */
  95. if (ap_addr->sa_data[0] == 0) {
  96. __orinoco_hw_set_wap(priv);
  97. err = 0;
  98. }
  99. goto out;
  100. }
  101. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  102. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  103. "support manual roaming\n",
  104. dev->name);
  105. err = -EOPNOTSUPP;
  106. goto out;
  107. }
  108. if (priv->iw_mode != NL80211_IFTYPE_STATION) {
  109. printk(KERN_WARNING "%s: Manual roaming supported only in "
  110. "managed mode\n", dev->name);
  111. err = -EOPNOTSUPP;
  112. goto out;
  113. }
  114. /* Intersil firmware hangs without Desired ESSID */
  115. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  116. strlen(priv->desired_essid) == 0) {
  117. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  118. "manual roaming\n", dev->name);
  119. err = -EOPNOTSUPP;
  120. goto out;
  121. }
  122. /* Finally, enable manual roaming */
  123. priv->bssid_fixed = 1;
  124. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  125. out:
  126. orinoco_unlock(priv, &flags);
  127. return err;
  128. }
  129. static int orinoco_ioctl_getwap(struct net_device *dev,
  130. struct iw_request_info *info,
  131. struct sockaddr *ap_addr,
  132. char *extra)
  133. {
  134. struct orinoco_private *priv = ndev_priv(dev);
  135. hermes_t *hw = &priv->hw;
  136. int err = 0;
  137. unsigned long flags;
  138. if (orinoco_lock(priv, &flags) != 0)
  139. return -EBUSY;
  140. ap_addr->sa_family = ARPHRD_ETHER;
  141. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  142. ETH_ALEN, NULL, ap_addr->sa_data);
  143. orinoco_unlock(priv, &flags);
  144. return err;
  145. }
  146. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  147. struct iw_request_info *info,
  148. struct iw_point *erq,
  149. char *keybuf)
  150. {
  151. struct orinoco_private *priv = ndev_priv(dev);
  152. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  153. int setindex = priv->tx_key;
  154. int encode_alg = priv->encode_alg;
  155. int restricted = priv->wep_restrict;
  156. u16 xlen = 0;
  157. int err = -EINPROGRESS; /* Call commit handler */
  158. unsigned long flags;
  159. if (!priv->has_wep)
  160. return -EOPNOTSUPP;
  161. if (erq->pointer) {
  162. /* We actually have a key to set - check its length */
  163. if (erq->length > LARGE_KEY_SIZE)
  164. return -E2BIG;
  165. if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
  166. return -E2BIG;
  167. }
  168. if (orinoco_lock(priv, &flags) != 0)
  169. return -EBUSY;
  170. /* Clear any TKIP key we have */
  171. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  172. (void) orinoco_clear_tkip_key(priv, setindex);
  173. if (erq->length > 0) {
  174. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  175. index = priv->tx_key;
  176. /* Adjust key length to a supported value */
  177. if (erq->length > SMALL_KEY_SIZE)
  178. xlen = LARGE_KEY_SIZE;
  179. else if (erq->length > 0)
  180. xlen = SMALL_KEY_SIZE;
  181. else
  182. xlen = 0;
  183. /* Switch on WEP if off */
  184. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  185. setindex = index;
  186. encode_alg = IW_ENCODE_ALG_WEP;
  187. }
  188. } else {
  189. /* Important note : if the user do "iwconfig eth0 enc off",
  190. * we will arrive there with an index of -1. This is valid
  191. * but need to be taken care off... Jean II */
  192. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  193. if ((index != -1) || (erq->flags == 0)) {
  194. err = -EINVAL;
  195. goto out;
  196. }
  197. } else {
  198. /* Set the index : Check that the key is valid */
  199. if (priv->keys[index].len == 0) {
  200. err = -EINVAL;
  201. goto out;
  202. }
  203. setindex = index;
  204. }
  205. }
  206. if (erq->flags & IW_ENCODE_DISABLED)
  207. encode_alg = IW_ENCODE_ALG_NONE;
  208. if (erq->flags & IW_ENCODE_OPEN)
  209. restricted = 0;
  210. if (erq->flags & IW_ENCODE_RESTRICTED)
  211. restricted = 1;
  212. if (erq->pointer && erq->length > 0) {
  213. priv->keys[index].len = cpu_to_le16(xlen);
  214. memset(priv->keys[index].data, 0,
  215. sizeof(priv->keys[index].data));
  216. memcpy(priv->keys[index].data, keybuf, erq->length);
  217. }
  218. priv->tx_key = setindex;
  219. /* Try fast key change if connected and only keys are changed */
  220. if ((priv->encode_alg == encode_alg) &&
  221. (priv->wep_restrict == restricted) &&
  222. netif_carrier_ok(dev)) {
  223. err = __orinoco_hw_setup_wepkeys(priv);
  224. /* No need to commit if successful */
  225. goto out;
  226. }
  227. priv->encode_alg = encode_alg;
  228. priv->wep_restrict = restricted;
  229. out:
  230. orinoco_unlock(priv, &flags);
  231. return err;
  232. }
  233. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  234. struct iw_request_info *info,
  235. struct iw_point *erq,
  236. char *keybuf)
  237. {
  238. struct orinoco_private *priv = ndev_priv(dev);
  239. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  240. u16 xlen = 0;
  241. unsigned long flags;
  242. if (!priv->has_wep)
  243. return -EOPNOTSUPP;
  244. if (orinoco_lock(priv, &flags) != 0)
  245. return -EBUSY;
  246. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  247. index = priv->tx_key;
  248. erq->flags = 0;
  249. if (!priv->encode_alg)
  250. erq->flags |= IW_ENCODE_DISABLED;
  251. erq->flags |= index + 1;
  252. if (priv->wep_restrict)
  253. erq->flags |= IW_ENCODE_RESTRICTED;
  254. else
  255. erq->flags |= IW_ENCODE_OPEN;
  256. xlen = le16_to_cpu(priv->keys[index].len);
  257. erq->length = xlen;
  258. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  259. orinoco_unlock(priv, &flags);
  260. return 0;
  261. }
  262. static int orinoco_ioctl_setessid(struct net_device *dev,
  263. struct iw_request_info *info,
  264. struct iw_point *erq,
  265. char *essidbuf)
  266. {
  267. struct orinoco_private *priv = ndev_priv(dev);
  268. unsigned long flags;
  269. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  270. * anyway... - Jean II */
  271. /* Hum... Should not use Wireless Extension constant (may change),
  272. * should use our own... - Jean II */
  273. if (erq->length > IW_ESSID_MAX_SIZE)
  274. return -E2BIG;
  275. if (orinoco_lock(priv, &flags) != 0)
  276. return -EBUSY;
  277. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  278. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  279. /* If not ANY, get the new ESSID */
  280. if (erq->flags)
  281. memcpy(priv->desired_essid, essidbuf, erq->length);
  282. orinoco_unlock(priv, &flags);
  283. return -EINPROGRESS; /* Call commit handler */
  284. }
  285. static int orinoco_ioctl_getessid(struct net_device *dev,
  286. struct iw_request_info *info,
  287. struct iw_point *erq,
  288. char *essidbuf)
  289. {
  290. struct orinoco_private *priv = ndev_priv(dev);
  291. int active;
  292. int err = 0;
  293. unsigned long flags;
  294. if (netif_running(dev)) {
  295. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  296. if (err < 0)
  297. return err;
  298. erq->length = err;
  299. } else {
  300. if (orinoco_lock(priv, &flags) != 0)
  301. return -EBUSY;
  302. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  303. erq->length = strlen(priv->desired_essid);
  304. orinoco_unlock(priv, &flags);
  305. }
  306. erq->flags = 1;
  307. return 0;
  308. }
  309. static int orinoco_ioctl_setfreq(struct net_device *dev,
  310. struct iw_request_info *info,
  311. struct iw_freq *frq,
  312. char *extra)
  313. {
  314. struct orinoco_private *priv = ndev_priv(dev);
  315. int chan = -1;
  316. unsigned long flags;
  317. int err = -EINPROGRESS; /* Call commit handler */
  318. /* In infrastructure mode the AP sets the channel */
  319. if (priv->iw_mode == NL80211_IFTYPE_STATION)
  320. return -EBUSY;
  321. if ((frq->e == 0) && (frq->m <= 1000)) {
  322. /* Setting by channel number */
  323. chan = frq->m;
  324. } else {
  325. /* Setting by frequency */
  326. int denom = 1;
  327. int i;
  328. /* Calculate denominator to rescale to MHz */
  329. for (i = 0; i < (6 - frq->e); i++)
  330. denom *= 10;
  331. chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
  332. }
  333. if ((chan < 1) || (chan > NUM_CHANNELS) ||
  334. !(priv->channel_mask & (1 << (chan-1))))
  335. return -EINVAL;
  336. if (orinoco_lock(priv, &flags) != 0)
  337. return -EBUSY;
  338. priv->channel = chan;
  339. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  340. /* Fast channel change - no commit if successful */
  341. hermes_t *hw = &priv->hw;
  342. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  343. HERMES_TEST_SET_CHANNEL,
  344. chan, NULL);
  345. }
  346. orinoco_unlock(priv, &flags);
  347. return err;
  348. }
  349. static int orinoco_ioctl_getfreq(struct net_device *dev,
  350. struct iw_request_info *info,
  351. struct iw_freq *frq,
  352. char *extra)
  353. {
  354. struct orinoco_private *priv = ndev_priv(dev);
  355. int tmp;
  356. /* Locking done in there */
  357. tmp = orinoco_hw_get_freq(priv);
  358. if (tmp < 0)
  359. return tmp;
  360. frq->m = tmp * 100000;
  361. frq->e = 1;
  362. return 0;
  363. }
  364. static int orinoco_ioctl_getsens(struct net_device *dev,
  365. struct iw_request_info *info,
  366. struct iw_param *srq,
  367. char *extra)
  368. {
  369. struct orinoco_private *priv = ndev_priv(dev);
  370. hermes_t *hw = &priv->hw;
  371. u16 val;
  372. int err;
  373. unsigned long flags;
  374. if (!priv->has_sensitivity)
  375. return -EOPNOTSUPP;
  376. if (orinoco_lock(priv, &flags) != 0)
  377. return -EBUSY;
  378. err = hermes_read_wordrec(hw, USER_BAP,
  379. HERMES_RID_CNFSYSTEMSCALE, &val);
  380. orinoco_unlock(priv, &flags);
  381. if (err)
  382. return err;
  383. srq->value = val;
  384. srq->fixed = 0; /* auto */
  385. return 0;
  386. }
  387. static int orinoco_ioctl_setsens(struct net_device *dev,
  388. struct iw_request_info *info,
  389. struct iw_param *srq,
  390. char *extra)
  391. {
  392. struct orinoco_private *priv = ndev_priv(dev);
  393. int val = srq->value;
  394. unsigned long flags;
  395. if (!priv->has_sensitivity)
  396. return -EOPNOTSUPP;
  397. if ((val < 1) || (val > 3))
  398. return -EINVAL;
  399. if (orinoco_lock(priv, &flags) != 0)
  400. return -EBUSY;
  401. priv->ap_density = val;
  402. orinoco_unlock(priv, &flags);
  403. return -EINPROGRESS; /* Call commit handler */
  404. }
  405. static int orinoco_ioctl_setrts(struct net_device *dev,
  406. struct iw_request_info *info,
  407. struct iw_param *rrq,
  408. char *extra)
  409. {
  410. struct orinoco_private *priv = ndev_priv(dev);
  411. int val = rrq->value;
  412. unsigned long flags;
  413. if (rrq->disabled)
  414. val = 2347;
  415. if ((val < 0) || (val > 2347))
  416. return -EINVAL;
  417. if (orinoco_lock(priv, &flags) != 0)
  418. return -EBUSY;
  419. priv->rts_thresh = val;
  420. orinoco_unlock(priv, &flags);
  421. return -EINPROGRESS; /* Call commit handler */
  422. }
  423. static int orinoco_ioctl_getrts(struct net_device *dev,
  424. struct iw_request_info *info,
  425. struct iw_param *rrq,
  426. char *extra)
  427. {
  428. struct orinoco_private *priv = ndev_priv(dev);
  429. rrq->value = priv->rts_thresh;
  430. rrq->disabled = (rrq->value == 2347);
  431. rrq->fixed = 1;
  432. return 0;
  433. }
  434. static int orinoco_ioctl_setfrag(struct net_device *dev,
  435. struct iw_request_info *info,
  436. struct iw_param *frq,
  437. char *extra)
  438. {
  439. struct orinoco_private *priv = ndev_priv(dev);
  440. int err = -EINPROGRESS; /* Call commit handler */
  441. unsigned long flags;
  442. if (orinoco_lock(priv, &flags) != 0)
  443. return -EBUSY;
  444. if (priv->has_mwo) {
  445. if (frq->disabled)
  446. priv->mwo_robust = 0;
  447. else {
  448. if (frq->fixed)
  449. printk(KERN_WARNING "%s: Fixed fragmentation "
  450. "is not supported on this firmware. "
  451. "Using MWO robust instead.\n",
  452. dev->name);
  453. priv->mwo_robust = 1;
  454. }
  455. } else {
  456. if (frq->disabled)
  457. priv->frag_thresh = 2346;
  458. else {
  459. if ((frq->value < 256) || (frq->value > 2346))
  460. err = -EINVAL;
  461. else
  462. /* must be even */
  463. priv->frag_thresh = frq->value & ~0x1;
  464. }
  465. }
  466. orinoco_unlock(priv, &flags);
  467. return err;
  468. }
  469. static int orinoco_ioctl_getfrag(struct net_device *dev,
  470. struct iw_request_info *info,
  471. struct iw_param *frq,
  472. char *extra)
  473. {
  474. struct orinoco_private *priv = ndev_priv(dev);
  475. hermes_t *hw = &priv->hw;
  476. int err;
  477. u16 val;
  478. unsigned long flags;
  479. if (orinoco_lock(priv, &flags) != 0)
  480. return -EBUSY;
  481. if (priv->has_mwo) {
  482. err = hermes_read_wordrec(hw, USER_BAP,
  483. HERMES_RID_CNFMWOROBUST_AGERE,
  484. &val);
  485. if (err)
  486. val = 0;
  487. frq->value = val ? 2347 : 0;
  488. frq->disabled = !val;
  489. frq->fixed = 0;
  490. } else {
  491. err = hermes_read_wordrec(hw, USER_BAP,
  492. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  493. &val);
  494. if (err)
  495. val = 0;
  496. frq->value = val;
  497. frq->disabled = (val >= 2346);
  498. frq->fixed = 1;
  499. }
  500. orinoco_unlock(priv, &flags);
  501. return err;
  502. }
  503. static int orinoco_ioctl_setrate(struct net_device *dev,
  504. struct iw_request_info *info,
  505. struct iw_param *rrq,
  506. char *extra)
  507. {
  508. struct orinoco_private *priv = ndev_priv(dev);
  509. int ratemode;
  510. int bitrate; /* 100s of kilobits */
  511. unsigned long flags;
  512. /* As the user space doesn't know our highest rate, it uses -1
  513. * to ask us to set the highest rate. Test it using "iwconfig
  514. * ethX rate auto" - Jean II */
  515. if (rrq->value == -1)
  516. bitrate = 110;
  517. else {
  518. if (rrq->value % 100000)
  519. return -EINVAL;
  520. bitrate = rrq->value / 100000;
  521. }
  522. ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
  523. if (ratemode == -1)
  524. return -EINVAL;
  525. if (orinoco_lock(priv, &flags) != 0)
  526. return -EBUSY;
  527. priv->bitratemode = ratemode;
  528. orinoco_unlock(priv, &flags);
  529. return -EINPROGRESS;
  530. }
  531. static int orinoco_ioctl_getrate(struct net_device *dev,
  532. struct iw_request_info *info,
  533. struct iw_param *rrq,
  534. char *extra)
  535. {
  536. struct orinoco_private *priv = ndev_priv(dev);
  537. int err = 0;
  538. int bitrate, automatic;
  539. unsigned long flags;
  540. if (orinoco_lock(priv, &flags) != 0)
  541. return -EBUSY;
  542. orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
  543. /* If the interface is running we try to find more about the
  544. current mode */
  545. if (netif_running(dev))
  546. err = orinoco_hw_get_act_bitrate(priv, &bitrate);
  547. orinoco_unlock(priv, &flags);
  548. rrq->value = bitrate;
  549. rrq->fixed = !automatic;
  550. rrq->disabled = 0;
  551. return err;
  552. }
  553. static int orinoco_ioctl_setpower(struct net_device *dev,
  554. struct iw_request_info *info,
  555. struct iw_param *prq,
  556. char *extra)
  557. {
  558. struct orinoco_private *priv = ndev_priv(dev);
  559. int err = -EINPROGRESS; /* Call commit handler */
  560. unsigned long flags;
  561. if (orinoco_lock(priv, &flags) != 0)
  562. return -EBUSY;
  563. if (prq->disabled) {
  564. priv->pm_on = 0;
  565. } else {
  566. switch (prq->flags & IW_POWER_MODE) {
  567. case IW_POWER_UNICAST_R:
  568. priv->pm_mcast = 0;
  569. priv->pm_on = 1;
  570. break;
  571. case IW_POWER_ALL_R:
  572. priv->pm_mcast = 1;
  573. priv->pm_on = 1;
  574. break;
  575. case IW_POWER_ON:
  576. /* No flags : but we may have a value - Jean II */
  577. break;
  578. default:
  579. err = -EINVAL;
  580. goto out;
  581. }
  582. if (prq->flags & IW_POWER_TIMEOUT) {
  583. priv->pm_on = 1;
  584. priv->pm_timeout = prq->value / 1000;
  585. }
  586. if (prq->flags & IW_POWER_PERIOD) {
  587. priv->pm_on = 1;
  588. priv->pm_period = prq->value / 1000;
  589. }
  590. /* It's valid to not have a value if we are just toggling
  591. * the flags... Jean II */
  592. if (!priv->pm_on) {
  593. err = -EINVAL;
  594. goto out;
  595. }
  596. }
  597. out:
  598. orinoco_unlock(priv, &flags);
  599. return err;
  600. }
  601. static int orinoco_ioctl_getpower(struct net_device *dev,
  602. struct iw_request_info *info,
  603. struct iw_param *prq,
  604. char *extra)
  605. {
  606. struct orinoco_private *priv = ndev_priv(dev);
  607. hermes_t *hw = &priv->hw;
  608. int err = 0;
  609. u16 enable, period, timeout, mcast;
  610. unsigned long flags;
  611. if (orinoco_lock(priv, &flags) != 0)
  612. return -EBUSY;
  613. err = hermes_read_wordrec(hw, USER_BAP,
  614. HERMES_RID_CNFPMENABLED, &enable);
  615. if (err)
  616. goto out;
  617. err = hermes_read_wordrec(hw, USER_BAP,
  618. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  619. if (err)
  620. goto out;
  621. err = hermes_read_wordrec(hw, USER_BAP,
  622. HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  623. if (err)
  624. goto out;
  625. err = hermes_read_wordrec(hw, USER_BAP,
  626. HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  627. if (err)
  628. goto out;
  629. prq->disabled = !enable;
  630. /* Note : by default, display the period */
  631. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  632. prq->flags = IW_POWER_TIMEOUT;
  633. prq->value = timeout * 1000;
  634. } else {
  635. prq->flags = IW_POWER_PERIOD;
  636. prq->value = period * 1000;
  637. }
  638. if (mcast)
  639. prq->flags |= IW_POWER_ALL_R;
  640. else
  641. prq->flags |= IW_POWER_UNICAST_R;
  642. out:
  643. orinoco_unlock(priv, &flags);
  644. return err;
  645. }
  646. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  647. struct iw_request_info *info,
  648. union iwreq_data *wrqu,
  649. char *extra)
  650. {
  651. struct orinoco_private *priv = ndev_priv(dev);
  652. struct iw_point *encoding = &wrqu->encoding;
  653. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  654. int idx, alg = ext->alg, set_key = 1;
  655. unsigned long flags;
  656. int err = -EINVAL;
  657. u16 key_len;
  658. if (orinoco_lock(priv, &flags) != 0)
  659. return -EBUSY;
  660. /* Determine and validate the key index */
  661. idx = encoding->flags & IW_ENCODE_INDEX;
  662. if (idx) {
  663. if ((idx < 1) || (idx > 4))
  664. goto out;
  665. idx--;
  666. } else
  667. idx = priv->tx_key;
  668. if (encoding->flags & IW_ENCODE_DISABLED)
  669. alg = IW_ENCODE_ALG_NONE;
  670. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  671. /* Clear any TKIP TX key we had */
  672. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  673. }
  674. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  675. priv->tx_key = idx;
  676. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  677. (ext->key_len > 0)) ? 1 : 0;
  678. }
  679. if (set_key) {
  680. /* Set the requested key first */
  681. switch (alg) {
  682. case IW_ENCODE_ALG_NONE:
  683. priv->encode_alg = alg;
  684. priv->keys[idx].len = 0;
  685. break;
  686. case IW_ENCODE_ALG_WEP:
  687. if (ext->key_len > SMALL_KEY_SIZE)
  688. key_len = LARGE_KEY_SIZE;
  689. else if (ext->key_len > 0)
  690. key_len = SMALL_KEY_SIZE;
  691. else
  692. goto out;
  693. priv->encode_alg = alg;
  694. priv->keys[idx].len = cpu_to_le16(key_len);
  695. key_len = min(ext->key_len, key_len);
  696. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  697. memcpy(priv->keys[idx].data, ext->key, key_len);
  698. break;
  699. case IW_ENCODE_ALG_TKIP:
  700. {
  701. u8 *tkip_iv = NULL;
  702. if (!priv->has_wpa ||
  703. (ext->key_len > sizeof(priv->tkip_key[0])))
  704. goto out;
  705. priv->encode_alg = alg;
  706. memset(&priv->tkip_key[idx], 0,
  707. sizeof(priv->tkip_key[idx]));
  708. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  709. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  710. tkip_iv = &ext->rx_seq[0];
  711. err = __orinoco_hw_set_tkip_key(priv, idx,
  712. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  713. (u8 *) &priv->tkip_key[idx],
  714. tkip_iv, NULL);
  715. if (err)
  716. printk(KERN_ERR "%s: Error %d setting TKIP key"
  717. "\n", dev->name, err);
  718. goto out;
  719. }
  720. default:
  721. goto out;
  722. }
  723. }
  724. err = -EINPROGRESS;
  725. out:
  726. orinoco_unlock(priv, &flags);
  727. return err;
  728. }
  729. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  730. struct iw_request_info *info,
  731. union iwreq_data *wrqu,
  732. char *extra)
  733. {
  734. struct orinoco_private *priv = ndev_priv(dev);
  735. struct iw_point *encoding = &wrqu->encoding;
  736. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  737. int idx, max_key_len;
  738. unsigned long flags;
  739. int err;
  740. if (orinoco_lock(priv, &flags) != 0)
  741. return -EBUSY;
  742. err = -EINVAL;
  743. max_key_len = encoding->length - sizeof(*ext);
  744. if (max_key_len < 0)
  745. goto out;
  746. idx = encoding->flags & IW_ENCODE_INDEX;
  747. if (idx) {
  748. if ((idx < 1) || (idx > 4))
  749. goto out;
  750. idx--;
  751. } else
  752. idx = priv->tx_key;
  753. encoding->flags = idx + 1;
  754. memset(ext, 0, sizeof(*ext));
  755. ext->alg = priv->encode_alg;
  756. switch (priv->encode_alg) {
  757. case IW_ENCODE_ALG_NONE:
  758. ext->key_len = 0;
  759. encoding->flags |= IW_ENCODE_DISABLED;
  760. break;
  761. case IW_ENCODE_ALG_WEP:
  762. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  763. max_key_len);
  764. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  765. encoding->flags |= IW_ENCODE_ENABLED;
  766. break;
  767. case IW_ENCODE_ALG_TKIP:
  768. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  769. max_key_len);
  770. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  771. encoding->flags |= IW_ENCODE_ENABLED;
  772. break;
  773. }
  774. err = 0;
  775. out:
  776. orinoco_unlock(priv, &flags);
  777. return err;
  778. }
  779. static int orinoco_ioctl_set_auth(struct net_device *dev,
  780. struct iw_request_info *info,
  781. union iwreq_data *wrqu, char *extra)
  782. {
  783. struct orinoco_private *priv = ndev_priv(dev);
  784. hermes_t *hw = &priv->hw;
  785. struct iw_param *param = &wrqu->param;
  786. unsigned long flags;
  787. int ret = -EINPROGRESS;
  788. if (orinoco_lock(priv, &flags) != 0)
  789. return -EBUSY;
  790. switch (param->flags & IW_AUTH_INDEX) {
  791. case IW_AUTH_WPA_VERSION:
  792. case IW_AUTH_CIPHER_PAIRWISE:
  793. case IW_AUTH_CIPHER_GROUP:
  794. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  795. case IW_AUTH_PRIVACY_INVOKED:
  796. case IW_AUTH_DROP_UNENCRYPTED:
  797. /*
  798. * orinoco does not use these parameters
  799. */
  800. break;
  801. case IW_AUTH_KEY_MGMT:
  802. /* wl_lkm implies value 2 == PSK for Hermes I
  803. * which ties in with WEXT
  804. * no other hints tho :(
  805. */
  806. priv->key_mgmt = param->value;
  807. break;
  808. case IW_AUTH_TKIP_COUNTERMEASURES:
  809. /* When countermeasures are enabled, shut down the
  810. * card; when disabled, re-enable the card. This must
  811. * take effect immediately.
  812. *
  813. * TODO: Make sure that the EAPOL message is getting
  814. * out before card disabled
  815. */
  816. if (param->value) {
  817. priv->tkip_cm_active = 1;
  818. ret = hermes_enable_port(hw, 0);
  819. } else {
  820. priv->tkip_cm_active = 0;
  821. ret = hermes_disable_port(hw, 0);
  822. }
  823. break;
  824. case IW_AUTH_80211_AUTH_ALG:
  825. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  826. priv->wep_restrict = 1;
  827. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  828. priv->wep_restrict = 0;
  829. else
  830. ret = -EINVAL;
  831. break;
  832. case IW_AUTH_WPA_ENABLED:
  833. if (priv->has_wpa) {
  834. priv->wpa_enabled = param->value ? 1 : 0;
  835. } else {
  836. if (param->value)
  837. ret = -EOPNOTSUPP;
  838. /* else silently accept disable of WPA */
  839. priv->wpa_enabled = 0;
  840. }
  841. break;
  842. default:
  843. ret = -EOPNOTSUPP;
  844. }
  845. orinoco_unlock(priv, &flags);
  846. return ret;
  847. }
  848. static int orinoco_ioctl_get_auth(struct net_device *dev,
  849. struct iw_request_info *info,
  850. union iwreq_data *wrqu, char *extra)
  851. {
  852. struct orinoco_private *priv = ndev_priv(dev);
  853. struct iw_param *param = &wrqu->param;
  854. unsigned long flags;
  855. int ret = 0;
  856. if (orinoco_lock(priv, &flags) != 0)
  857. return -EBUSY;
  858. switch (param->flags & IW_AUTH_INDEX) {
  859. case IW_AUTH_KEY_MGMT:
  860. param->value = priv->key_mgmt;
  861. break;
  862. case IW_AUTH_TKIP_COUNTERMEASURES:
  863. param->value = priv->tkip_cm_active;
  864. break;
  865. case IW_AUTH_80211_AUTH_ALG:
  866. if (priv->wep_restrict)
  867. param->value = IW_AUTH_ALG_SHARED_KEY;
  868. else
  869. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  870. break;
  871. case IW_AUTH_WPA_ENABLED:
  872. param->value = priv->wpa_enabled;
  873. break;
  874. default:
  875. ret = -EOPNOTSUPP;
  876. }
  877. orinoco_unlock(priv, &flags);
  878. return ret;
  879. }
  880. static int orinoco_ioctl_set_genie(struct net_device *dev,
  881. struct iw_request_info *info,
  882. union iwreq_data *wrqu, char *extra)
  883. {
  884. struct orinoco_private *priv = ndev_priv(dev);
  885. u8 *buf;
  886. unsigned long flags;
  887. /* cut off at IEEE80211_MAX_DATA_LEN */
  888. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  889. (wrqu->data.length && (extra == NULL)))
  890. return -EINVAL;
  891. if (wrqu->data.length) {
  892. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  893. if (buf == NULL)
  894. return -ENOMEM;
  895. memcpy(buf, extra, wrqu->data.length);
  896. } else
  897. buf = NULL;
  898. if (orinoco_lock(priv, &flags) != 0) {
  899. kfree(buf);
  900. return -EBUSY;
  901. }
  902. kfree(priv->wpa_ie);
  903. priv->wpa_ie = buf;
  904. priv->wpa_ie_len = wrqu->data.length;
  905. if (priv->wpa_ie) {
  906. /* Looks like wl_lkm wants to check the auth alg, and
  907. * somehow pass it to the firmware.
  908. * Instead it just calls the key mgmt rid
  909. * - we do this in set auth.
  910. */
  911. }
  912. orinoco_unlock(priv, &flags);
  913. return 0;
  914. }
  915. static int orinoco_ioctl_get_genie(struct net_device *dev,
  916. struct iw_request_info *info,
  917. union iwreq_data *wrqu, char *extra)
  918. {
  919. struct orinoco_private *priv = ndev_priv(dev);
  920. unsigned long flags;
  921. int err = 0;
  922. if (orinoco_lock(priv, &flags) != 0)
  923. return -EBUSY;
  924. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  925. wrqu->data.length = 0;
  926. goto out;
  927. }
  928. if (wrqu->data.length < priv->wpa_ie_len) {
  929. err = -E2BIG;
  930. goto out;
  931. }
  932. wrqu->data.length = priv->wpa_ie_len;
  933. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  934. out:
  935. orinoco_unlock(priv, &flags);
  936. return err;
  937. }
  938. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  939. struct iw_request_info *info,
  940. union iwreq_data *wrqu, char *extra)
  941. {
  942. struct orinoco_private *priv = ndev_priv(dev);
  943. hermes_t *hw = &priv->hw;
  944. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  945. unsigned long flags;
  946. int ret = 0;
  947. if (orinoco_lock(priv, &flags) != 0)
  948. return -EBUSY;
  949. switch (mlme->cmd) {
  950. case IW_MLME_DEAUTH:
  951. /* silently ignore */
  952. break;
  953. case IW_MLME_DISASSOC:
  954. {
  955. struct {
  956. u8 addr[ETH_ALEN];
  957. __le16 reason_code;
  958. } __attribute__ ((packed)) buf;
  959. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  960. buf.reason_code = cpu_to_le16(mlme->reason_code);
  961. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  962. HERMES_RID_CNFDISASSOCIATE,
  963. &buf);
  964. break;
  965. }
  966. default:
  967. ret = -EOPNOTSUPP;
  968. }
  969. orinoco_unlock(priv, &flags);
  970. return ret;
  971. }
  972. static int orinoco_ioctl_getretry(struct net_device *dev,
  973. struct iw_request_info *info,
  974. struct iw_param *rrq,
  975. char *extra)
  976. {
  977. struct orinoco_private *priv = ndev_priv(dev);
  978. hermes_t *hw = &priv->hw;
  979. int err = 0;
  980. u16 short_limit, long_limit, lifetime;
  981. unsigned long flags;
  982. if (orinoco_lock(priv, &flags) != 0)
  983. return -EBUSY;
  984. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  985. &short_limit);
  986. if (err)
  987. goto out;
  988. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  989. &long_limit);
  990. if (err)
  991. goto out;
  992. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  993. &lifetime);
  994. if (err)
  995. goto out;
  996. rrq->disabled = 0; /* Can't be disabled */
  997. /* Note : by default, display the retry number */
  998. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  999. rrq->flags = IW_RETRY_LIFETIME;
  1000. rrq->value = lifetime * 1000; /* ??? */
  1001. } else {
  1002. /* By default, display the min number */
  1003. if ((rrq->flags & IW_RETRY_LONG)) {
  1004. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  1005. rrq->value = long_limit;
  1006. } else {
  1007. rrq->flags = IW_RETRY_LIMIT;
  1008. rrq->value = short_limit;
  1009. if (short_limit != long_limit)
  1010. rrq->flags |= IW_RETRY_SHORT;
  1011. }
  1012. }
  1013. out:
  1014. orinoco_unlock(priv, &flags);
  1015. return err;
  1016. }
  1017. static int orinoco_ioctl_reset(struct net_device *dev,
  1018. struct iw_request_info *info,
  1019. void *wrqu,
  1020. char *extra)
  1021. {
  1022. struct orinoco_private *priv = ndev_priv(dev);
  1023. if (!capable(CAP_NET_ADMIN))
  1024. return -EPERM;
  1025. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  1026. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  1027. /* Firmware reset */
  1028. orinoco_reset(&priv->reset_work);
  1029. } else {
  1030. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  1031. schedule_work(&priv->reset_work);
  1032. }
  1033. return 0;
  1034. }
  1035. static int orinoco_ioctl_setibssport(struct net_device *dev,
  1036. struct iw_request_info *info,
  1037. void *wrqu,
  1038. char *extra)
  1039. {
  1040. struct orinoco_private *priv = ndev_priv(dev);
  1041. int val = *((int *) extra);
  1042. unsigned long flags;
  1043. if (orinoco_lock(priv, &flags) != 0)
  1044. return -EBUSY;
  1045. priv->ibss_port = val ;
  1046. /* Actually update the mode we are using */
  1047. set_port_type(priv);
  1048. orinoco_unlock(priv, &flags);
  1049. return -EINPROGRESS; /* Call commit handler */
  1050. }
  1051. static int orinoco_ioctl_getibssport(struct net_device *dev,
  1052. struct iw_request_info *info,
  1053. void *wrqu,
  1054. char *extra)
  1055. {
  1056. struct orinoco_private *priv = ndev_priv(dev);
  1057. int *val = (int *) extra;
  1058. *val = priv->ibss_port;
  1059. return 0;
  1060. }
  1061. static int orinoco_ioctl_setport3(struct net_device *dev,
  1062. struct iw_request_info *info,
  1063. void *wrqu,
  1064. char *extra)
  1065. {
  1066. struct orinoco_private *priv = ndev_priv(dev);
  1067. int val = *((int *) extra);
  1068. int err = 0;
  1069. unsigned long flags;
  1070. if (orinoco_lock(priv, &flags) != 0)
  1071. return -EBUSY;
  1072. switch (val) {
  1073. case 0: /* Try to do IEEE ad-hoc mode */
  1074. if (!priv->has_ibss) {
  1075. err = -EINVAL;
  1076. break;
  1077. }
  1078. priv->prefer_port3 = 0;
  1079. break;
  1080. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  1081. if (!priv->has_port3) {
  1082. err = -EINVAL;
  1083. break;
  1084. }
  1085. priv->prefer_port3 = 1;
  1086. break;
  1087. default:
  1088. err = -EINVAL;
  1089. }
  1090. if (!err) {
  1091. /* Actually update the mode we are using */
  1092. set_port_type(priv);
  1093. err = -EINPROGRESS;
  1094. }
  1095. orinoco_unlock(priv, &flags);
  1096. return err;
  1097. }
  1098. static int orinoco_ioctl_getport3(struct net_device *dev,
  1099. struct iw_request_info *info,
  1100. void *wrqu,
  1101. char *extra)
  1102. {
  1103. struct orinoco_private *priv = ndev_priv(dev);
  1104. int *val = (int *) extra;
  1105. *val = priv->prefer_port3;
  1106. return 0;
  1107. }
  1108. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  1109. struct iw_request_info *info,
  1110. void *wrqu,
  1111. char *extra)
  1112. {
  1113. struct orinoco_private *priv = ndev_priv(dev);
  1114. unsigned long flags;
  1115. int val;
  1116. if (!priv->has_preamble)
  1117. return -EOPNOTSUPP;
  1118. /* 802.11b has recently defined some short preamble.
  1119. * Basically, the Phy header has been reduced in size.
  1120. * This increase performance, especially at high rates
  1121. * (the preamble is transmitted at 1Mb/s), unfortunately
  1122. * this give compatibility troubles... - Jean II */
  1123. val = *((int *) extra);
  1124. if (orinoco_lock(priv, &flags) != 0)
  1125. return -EBUSY;
  1126. if (val)
  1127. priv->preamble = 1;
  1128. else
  1129. priv->preamble = 0;
  1130. orinoco_unlock(priv, &flags);
  1131. return -EINPROGRESS; /* Call commit handler */
  1132. }
  1133. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  1134. struct iw_request_info *info,
  1135. void *wrqu,
  1136. char *extra)
  1137. {
  1138. struct orinoco_private *priv = ndev_priv(dev);
  1139. int *val = (int *) extra;
  1140. if (!priv->has_preamble)
  1141. return -EOPNOTSUPP;
  1142. *val = priv->preamble;
  1143. return 0;
  1144. }
  1145. /* ioctl interface to hermes_read_ltv()
  1146. * To use with iwpriv, pass the RID as the token argument, e.g.
  1147. * iwpriv get_rid [0xfc00]
  1148. * At least Wireless Tools 25 is required to use iwpriv.
  1149. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  1150. static int orinoco_ioctl_getrid(struct net_device *dev,
  1151. struct iw_request_info *info,
  1152. struct iw_point *data,
  1153. char *extra)
  1154. {
  1155. struct orinoco_private *priv = ndev_priv(dev);
  1156. hermes_t *hw = &priv->hw;
  1157. int rid = data->flags;
  1158. u16 length;
  1159. int err;
  1160. unsigned long flags;
  1161. /* It's a "get" function, but we don't want users to access the
  1162. * WEP key and other raw firmware data */
  1163. if (!capable(CAP_NET_ADMIN))
  1164. return -EPERM;
  1165. if (rid < 0xfc00 || rid > 0xffff)
  1166. return -EINVAL;
  1167. if (orinoco_lock(priv, &flags) != 0)
  1168. return -EBUSY;
  1169. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  1170. extra);
  1171. if (err)
  1172. goto out;
  1173. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  1174. MAX_RID_LEN);
  1175. out:
  1176. orinoco_unlock(priv, &flags);
  1177. return err;
  1178. }
  1179. /* Commit handler, called after set operations */
  1180. static int orinoco_ioctl_commit(struct net_device *dev,
  1181. struct iw_request_info *info,
  1182. void *wrqu,
  1183. char *extra)
  1184. {
  1185. struct orinoco_private *priv = ndev_priv(dev);
  1186. unsigned long flags;
  1187. int err = 0;
  1188. if (!priv->open)
  1189. return 0;
  1190. if (orinoco_lock(priv, &flags) != 0)
  1191. return err;
  1192. err = orinoco_commit(priv);
  1193. orinoco_unlock(priv, &flags);
  1194. return err;
  1195. }
  1196. static const struct iw_priv_args orinoco_privtab[] = {
  1197. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  1198. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  1199. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1200. 0, "set_port3" },
  1201. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1202. "get_port3" },
  1203. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1204. 0, "set_preamble" },
  1205. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1206. "get_preamble" },
  1207. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1208. 0, "set_ibssport" },
  1209. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1210. "get_ibssport" },
  1211. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  1212. "get_rid" },
  1213. };
  1214. /*
  1215. * Structures to export the Wireless Handlers
  1216. */
  1217. #define STD_IW_HANDLER(id, func) \
  1218. [IW_IOCTL_IDX(id)] = (iw_handler) func
  1219. static const iw_handler orinoco_handler[] = {
  1220. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  1221. STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname),
  1222. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  1223. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  1224. STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode),
  1225. STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode),
  1226. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  1227. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  1228. STD_IW_HANDLER(SIOCGIWRANGE, cfg80211_wext_giwrange),
  1229. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  1230. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  1231. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  1232. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  1233. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  1234. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  1235. STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan),
  1236. STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan),
  1237. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  1238. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  1239. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  1240. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  1241. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  1242. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  1243. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  1244. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  1245. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  1246. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  1247. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  1248. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  1249. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  1250. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  1251. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  1252. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  1253. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  1254. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  1255. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  1256. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  1257. };
  1258. /*
  1259. Added typecasting since we no longer use iwreq_data -- Moustafa
  1260. */
  1261. static const iw_handler orinoco_private_handler[] = {
  1262. [0] = (iw_handler) orinoco_ioctl_reset,
  1263. [1] = (iw_handler) orinoco_ioctl_reset,
  1264. [2] = (iw_handler) orinoco_ioctl_setport3,
  1265. [3] = (iw_handler) orinoco_ioctl_getport3,
  1266. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  1267. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  1268. [6] = (iw_handler) orinoco_ioctl_setibssport,
  1269. [7] = (iw_handler) orinoco_ioctl_getibssport,
  1270. [9] = (iw_handler) orinoco_ioctl_getrid,
  1271. };
  1272. const struct iw_handler_def orinoco_handler_def = {
  1273. .num_standard = ARRAY_SIZE(orinoco_handler),
  1274. .num_private = ARRAY_SIZE(orinoco_private_handler),
  1275. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  1276. .standard = orinoco_handler,
  1277. .private = orinoco_private_handler,
  1278. .private_args = orinoco_privtab,
  1279. .get_wireless_stats = orinoco_get_wireless_stats,
  1280. };