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. enum orinoco_alg 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 == ORINOCO_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 /* (erq->length > 0) */
  180. xlen = SMALL_KEY_SIZE;
  181. /* Switch on WEP if off */
  182. if (encode_alg != ORINOCO_ALG_WEP) {
  183. setindex = index;
  184. encode_alg = ORINOCO_ALG_WEP;
  185. }
  186. } else {
  187. /* Important note : if the user do "iwconfig eth0 enc off",
  188. * we will arrive there with an index of -1. This is valid
  189. * but need to be taken care off... Jean II */
  190. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  191. if ((index != -1) || (erq->flags == 0)) {
  192. err = -EINVAL;
  193. goto out;
  194. }
  195. } else {
  196. /* Set the index : Check that the key is valid */
  197. if (priv->keys[index].len == 0) {
  198. err = -EINVAL;
  199. goto out;
  200. }
  201. setindex = index;
  202. }
  203. }
  204. if (erq->flags & IW_ENCODE_DISABLED)
  205. encode_alg = ORINOCO_ALG_NONE;
  206. if (erq->flags & IW_ENCODE_OPEN)
  207. restricted = 0;
  208. if (erq->flags & IW_ENCODE_RESTRICTED)
  209. restricted = 1;
  210. if (erq->pointer && erq->length > 0) {
  211. priv->keys[index].len = cpu_to_le16(xlen);
  212. memset(priv->keys[index].data, 0,
  213. sizeof(priv->keys[index].data));
  214. memcpy(priv->keys[index].data, keybuf, erq->length);
  215. }
  216. priv->tx_key = setindex;
  217. /* Try fast key change if connected and only keys are changed */
  218. if ((priv->encode_alg == encode_alg) &&
  219. (priv->wep_restrict == restricted) &&
  220. netif_carrier_ok(dev)) {
  221. err = __orinoco_hw_setup_wepkeys(priv);
  222. /* No need to commit if successful */
  223. goto out;
  224. }
  225. priv->encode_alg = encode_alg;
  226. priv->wep_restrict = restricted;
  227. out:
  228. orinoco_unlock(priv, &flags);
  229. return err;
  230. }
  231. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  232. struct iw_request_info *info,
  233. struct iw_point *erq,
  234. char *keybuf)
  235. {
  236. struct orinoco_private *priv = ndev_priv(dev);
  237. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  238. u16 xlen = 0;
  239. unsigned long flags;
  240. if (!priv->has_wep)
  241. return -EOPNOTSUPP;
  242. if (orinoco_lock(priv, &flags) != 0)
  243. return -EBUSY;
  244. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  245. index = priv->tx_key;
  246. erq->flags = 0;
  247. if (!priv->encode_alg)
  248. erq->flags |= IW_ENCODE_DISABLED;
  249. erq->flags |= index + 1;
  250. if (priv->wep_restrict)
  251. erq->flags |= IW_ENCODE_RESTRICTED;
  252. else
  253. erq->flags |= IW_ENCODE_OPEN;
  254. xlen = le16_to_cpu(priv->keys[index].len);
  255. erq->length = xlen;
  256. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  257. orinoco_unlock(priv, &flags);
  258. return 0;
  259. }
  260. static int orinoco_ioctl_setessid(struct net_device *dev,
  261. struct iw_request_info *info,
  262. struct iw_point *erq,
  263. char *essidbuf)
  264. {
  265. struct orinoco_private *priv = ndev_priv(dev);
  266. unsigned long flags;
  267. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  268. * anyway... - Jean II */
  269. /* Hum... Should not use Wireless Extension constant (may change),
  270. * should use our own... - Jean II */
  271. if (erq->length > IW_ESSID_MAX_SIZE)
  272. return -E2BIG;
  273. if (orinoco_lock(priv, &flags) != 0)
  274. return -EBUSY;
  275. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  276. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  277. /* If not ANY, get the new ESSID */
  278. if (erq->flags)
  279. memcpy(priv->desired_essid, essidbuf, erq->length);
  280. orinoco_unlock(priv, &flags);
  281. return -EINPROGRESS; /* Call commit handler */
  282. }
  283. static int orinoco_ioctl_getessid(struct net_device *dev,
  284. struct iw_request_info *info,
  285. struct iw_point *erq,
  286. char *essidbuf)
  287. {
  288. struct orinoco_private *priv = ndev_priv(dev);
  289. int active;
  290. int err = 0;
  291. unsigned long flags;
  292. if (netif_running(dev)) {
  293. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  294. if (err < 0)
  295. return err;
  296. erq->length = err;
  297. } else {
  298. if (orinoco_lock(priv, &flags) != 0)
  299. return -EBUSY;
  300. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  301. erq->length = strlen(priv->desired_essid);
  302. orinoco_unlock(priv, &flags);
  303. }
  304. erq->flags = 1;
  305. return 0;
  306. }
  307. static int orinoco_ioctl_setfreq(struct net_device *dev,
  308. struct iw_request_info *info,
  309. struct iw_freq *frq,
  310. char *extra)
  311. {
  312. struct orinoco_private *priv = ndev_priv(dev);
  313. int chan = -1;
  314. unsigned long flags;
  315. int err = -EINPROGRESS; /* Call commit handler */
  316. /* In infrastructure mode the AP sets the channel */
  317. if (priv->iw_mode == NL80211_IFTYPE_STATION)
  318. return -EBUSY;
  319. if ((frq->e == 0) && (frq->m <= 1000)) {
  320. /* Setting by channel number */
  321. chan = frq->m;
  322. } else {
  323. /* Setting by frequency */
  324. int denom = 1;
  325. int i;
  326. /* Calculate denominator to rescale to MHz */
  327. for (i = 0; i < (6 - frq->e); i++)
  328. denom *= 10;
  329. chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
  330. }
  331. if ((chan < 1) || (chan > NUM_CHANNELS) ||
  332. !(priv->channel_mask & (1 << (chan-1))))
  333. return -EINVAL;
  334. if (orinoco_lock(priv, &flags) != 0)
  335. return -EBUSY;
  336. priv->channel = chan;
  337. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  338. /* Fast channel change - no commit if successful */
  339. hermes_t *hw = &priv->hw;
  340. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  341. HERMES_TEST_SET_CHANNEL,
  342. chan, NULL);
  343. }
  344. orinoco_unlock(priv, &flags);
  345. return err;
  346. }
  347. static int orinoco_ioctl_getfreq(struct net_device *dev,
  348. struct iw_request_info *info,
  349. struct iw_freq *frq,
  350. char *extra)
  351. {
  352. struct orinoco_private *priv = ndev_priv(dev);
  353. int tmp;
  354. /* Locking done in there */
  355. tmp = orinoco_hw_get_freq(priv);
  356. if (tmp < 0)
  357. return tmp;
  358. frq->m = tmp * 100000;
  359. frq->e = 1;
  360. return 0;
  361. }
  362. static int orinoco_ioctl_getsens(struct net_device *dev,
  363. struct iw_request_info *info,
  364. struct iw_param *srq,
  365. char *extra)
  366. {
  367. struct orinoco_private *priv = ndev_priv(dev);
  368. hermes_t *hw = &priv->hw;
  369. u16 val;
  370. int err;
  371. unsigned long flags;
  372. if (!priv->has_sensitivity)
  373. return -EOPNOTSUPP;
  374. if (orinoco_lock(priv, &flags) != 0)
  375. return -EBUSY;
  376. err = hermes_read_wordrec(hw, USER_BAP,
  377. HERMES_RID_CNFSYSTEMSCALE, &val);
  378. orinoco_unlock(priv, &flags);
  379. if (err)
  380. return err;
  381. srq->value = val;
  382. srq->fixed = 0; /* auto */
  383. return 0;
  384. }
  385. static int orinoco_ioctl_setsens(struct net_device *dev,
  386. struct iw_request_info *info,
  387. struct iw_param *srq,
  388. char *extra)
  389. {
  390. struct orinoco_private *priv = ndev_priv(dev);
  391. int val = srq->value;
  392. unsigned long flags;
  393. if (!priv->has_sensitivity)
  394. return -EOPNOTSUPP;
  395. if ((val < 1) || (val > 3))
  396. return -EINVAL;
  397. if (orinoco_lock(priv, &flags) != 0)
  398. return -EBUSY;
  399. priv->ap_density = val;
  400. orinoco_unlock(priv, &flags);
  401. return -EINPROGRESS; /* Call commit handler */
  402. }
  403. static int orinoco_ioctl_setrts(struct net_device *dev,
  404. struct iw_request_info *info,
  405. struct iw_param *rrq,
  406. char *extra)
  407. {
  408. struct orinoco_private *priv = ndev_priv(dev);
  409. int val = rrq->value;
  410. unsigned long flags;
  411. if (rrq->disabled)
  412. val = 2347;
  413. if ((val < 0) || (val > 2347))
  414. return -EINVAL;
  415. if (orinoco_lock(priv, &flags) != 0)
  416. return -EBUSY;
  417. priv->rts_thresh = val;
  418. orinoco_unlock(priv, &flags);
  419. return -EINPROGRESS; /* Call commit handler */
  420. }
  421. static int orinoco_ioctl_getrts(struct net_device *dev,
  422. struct iw_request_info *info,
  423. struct iw_param *rrq,
  424. char *extra)
  425. {
  426. struct orinoco_private *priv = ndev_priv(dev);
  427. rrq->value = priv->rts_thresh;
  428. rrq->disabled = (rrq->value == 2347);
  429. rrq->fixed = 1;
  430. return 0;
  431. }
  432. static int orinoco_ioctl_setfrag(struct net_device *dev,
  433. struct iw_request_info *info,
  434. struct iw_param *frq,
  435. char *extra)
  436. {
  437. struct orinoco_private *priv = ndev_priv(dev);
  438. int err = -EINPROGRESS; /* Call commit handler */
  439. unsigned long flags;
  440. if (orinoco_lock(priv, &flags) != 0)
  441. return -EBUSY;
  442. if (priv->has_mwo) {
  443. if (frq->disabled)
  444. priv->mwo_robust = 0;
  445. else {
  446. if (frq->fixed)
  447. printk(KERN_WARNING "%s: Fixed fragmentation "
  448. "is not supported on this firmware. "
  449. "Using MWO robust instead.\n",
  450. dev->name);
  451. priv->mwo_robust = 1;
  452. }
  453. } else {
  454. if (frq->disabled)
  455. priv->frag_thresh = 2346;
  456. else {
  457. if ((frq->value < 256) || (frq->value > 2346))
  458. err = -EINVAL;
  459. else
  460. /* must be even */
  461. priv->frag_thresh = frq->value & ~0x1;
  462. }
  463. }
  464. orinoco_unlock(priv, &flags);
  465. return err;
  466. }
  467. static int orinoco_ioctl_getfrag(struct net_device *dev,
  468. struct iw_request_info *info,
  469. struct iw_param *frq,
  470. char *extra)
  471. {
  472. struct orinoco_private *priv = ndev_priv(dev);
  473. hermes_t *hw = &priv->hw;
  474. int err;
  475. u16 val;
  476. unsigned long flags;
  477. if (orinoco_lock(priv, &flags) != 0)
  478. return -EBUSY;
  479. if (priv->has_mwo) {
  480. err = hermes_read_wordrec(hw, USER_BAP,
  481. HERMES_RID_CNFMWOROBUST_AGERE,
  482. &val);
  483. if (err)
  484. val = 0;
  485. frq->value = val ? 2347 : 0;
  486. frq->disabled = !val;
  487. frq->fixed = 0;
  488. } else {
  489. err = hermes_read_wordrec(hw, USER_BAP,
  490. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  491. &val);
  492. if (err)
  493. val = 0;
  494. frq->value = val;
  495. frq->disabled = (val >= 2346);
  496. frq->fixed = 1;
  497. }
  498. orinoco_unlock(priv, &flags);
  499. return err;
  500. }
  501. static int orinoco_ioctl_setrate(struct net_device *dev,
  502. struct iw_request_info *info,
  503. struct iw_param *rrq,
  504. char *extra)
  505. {
  506. struct orinoco_private *priv = ndev_priv(dev);
  507. int ratemode;
  508. int bitrate; /* 100s of kilobits */
  509. unsigned long flags;
  510. /* As the user space doesn't know our highest rate, it uses -1
  511. * to ask us to set the highest rate. Test it using "iwconfig
  512. * ethX rate auto" - Jean II */
  513. if (rrq->value == -1)
  514. bitrate = 110;
  515. else {
  516. if (rrq->value % 100000)
  517. return -EINVAL;
  518. bitrate = rrq->value / 100000;
  519. }
  520. ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
  521. if (ratemode == -1)
  522. return -EINVAL;
  523. if (orinoco_lock(priv, &flags) != 0)
  524. return -EBUSY;
  525. priv->bitratemode = ratemode;
  526. orinoco_unlock(priv, &flags);
  527. return -EINPROGRESS;
  528. }
  529. static int orinoco_ioctl_getrate(struct net_device *dev,
  530. struct iw_request_info *info,
  531. struct iw_param *rrq,
  532. char *extra)
  533. {
  534. struct orinoco_private *priv = ndev_priv(dev);
  535. int err = 0;
  536. int bitrate, automatic;
  537. unsigned long flags;
  538. if (orinoco_lock(priv, &flags) != 0)
  539. return -EBUSY;
  540. orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
  541. /* If the interface is running we try to find more about the
  542. current mode */
  543. if (netif_running(dev))
  544. err = orinoco_hw_get_act_bitrate(priv, &bitrate);
  545. orinoco_unlock(priv, &flags);
  546. rrq->value = bitrate;
  547. rrq->fixed = !automatic;
  548. rrq->disabled = 0;
  549. return err;
  550. }
  551. static int orinoco_ioctl_setpower(struct net_device *dev,
  552. struct iw_request_info *info,
  553. struct iw_param *prq,
  554. char *extra)
  555. {
  556. struct orinoco_private *priv = ndev_priv(dev);
  557. int err = -EINPROGRESS; /* Call commit handler */
  558. unsigned long flags;
  559. if (orinoco_lock(priv, &flags) != 0)
  560. return -EBUSY;
  561. if (prq->disabled) {
  562. priv->pm_on = 0;
  563. } else {
  564. switch (prq->flags & IW_POWER_MODE) {
  565. case IW_POWER_UNICAST_R:
  566. priv->pm_mcast = 0;
  567. priv->pm_on = 1;
  568. break;
  569. case IW_POWER_ALL_R:
  570. priv->pm_mcast = 1;
  571. priv->pm_on = 1;
  572. break;
  573. case IW_POWER_ON:
  574. /* No flags : but we may have a value - Jean II */
  575. break;
  576. default:
  577. err = -EINVAL;
  578. goto out;
  579. }
  580. if (prq->flags & IW_POWER_TIMEOUT) {
  581. priv->pm_on = 1;
  582. priv->pm_timeout = prq->value / 1000;
  583. }
  584. if (prq->flags & IW_POWER_PERIOD) {
  585. priv->pm_on = 1;
  586. priv->pm_period = prq->value / 1000;
  587. }
  588. /* It's valid to not have a value if we are just toggling
  589. * the flags... Jean II */
  590. if (!priv->pm_on) {
  591. err = -EINVAL;
  592. goto out;
  593. }
  594. }
  595. out:
  596. orinoco_unlock(priv, &flags);
  597. return err;
  598. }
  599. static int orinoco_ioctl_getpower(struct net_device *dev,
  600. struct iw_request_info *info,
  601. struct iw_param *prq,
  602. char *extra)
  603. {
  604. struct orinoco_private *priv = ndev_priv(dev);
  605. hermes_t *hw = &priv->hw;
  606. int err = 0;
  607. u16 enable, period, timeout, mcast;
  608. unsigned long flags;
  609. if (orinoco_lock(priv, &flags) != 0)
  610. return -EBUSY;
  611. err = hermes_read_wordrec(hw, USER_BAP,
  612. HERMES_RID_CNFPMENABLED, &enable);
  613. if (err)
  614. goto out;
  615. err = hermes_read_wordrec(hw, USER_BAP,
  616. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  617. if (err)
  618. goto out;
  619. err = hermes_read_wordrec(hw, USER_BAP,
  620. HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  621. if (err)
  622. goto out;
  623. err = hermes_read_wordrec(hw, USER_BAP,
  624. HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  625. if (err)
  626. goto out;
  627. prq->disabled = !enable;
  628. /* Note : by default, display the period */
  629. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  630. prq->flags = IW_POWER_TIMEOUT;
  631. prq->value = timeout * 1000;
  632. } else {
  633. prq->flags = IW_POWER_PERIOD;
  634. prq->value = period * 1000;
  635. }
  636. if (mcast)
  637. prq->flags |= IW_POWER_ALL_R;
  638. else
  639. prq->flags |= IW_POWER_UNICAST_R;
  640. out:
  641. orinoco_unlock(priv, &flags);
  642. return err;
  643. }
  644. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  645. struct iw_request_info *info,
  646. union iwreq_data *wrqu,
  647. char *extra)
  648. {
  649. struct orinoco_private *priv = ndev_priv(dev);
  650. struct iw_point *encoding = &wrqu->encoding;
  651. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  652. int idx, alg = ext->alg, set_key = 1;
  653. unsigned long flags;
  654. int err = -EINVAL;
  655. u16 key_len;
  656. if (orinoco_lock(priv, &flags) != 0)
  657. return -EBUSY;
  658. /* Determine and validate the key index */
  659. idx = encoding->flags & IW_ENCODE_INDEX;
  660. if (idx) {
  661. if ((idx < 1) || (idx > 4))
  662. goto out;
  663. idx--;
  664. } else
  665. idx = priv->tx_key;
  666. if (encoding->flags & IW_ENCODE_DISABLED)
  667. alg = IW_ENCODE_ALG_NONE;
  668. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  669. /* Clear any TKIP TX key we had */
  670. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  671. }
  672. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  673. priv->tx_key = idx;
  674. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  675. (ext->key_len > 0)) ? 1 : 0;
  676. }
  677. if (set_key) {
  678. /* Set the requested key first */
  679. switch (alg) {
  680. case IW_ENCODE_ALG_NONE:
  681. priv->encode_alg = ORINOCO_ALG_NONE;
  682. priv->keys[idx].len = 0;
  683. break;
  684. case IW_ENCODE_ALG_WEP:
  685. if (ext->key_len > SMALL_KEY_SIZE)
  686. key_len = LARGE_KEY_SIZE;
  687. else if (ext->key_len > 0)
  688. key_len = SMALL_KEY_SIZE;
  689. else
  690. goto out;
  691. priv->encode_alg = ORINOCO_ALG_WEP;
  692. priv->keys[idx].len = cpu_to_le16(key_len);
  693. key_len = min(ext->key_len, key_len);
  694. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  695. memcpy(priv->keys[idx].data, ext->key, key_len);
  696. break;
  697. case IW_ENCODE_ALG_TKIP:
  698. {
  699. u8 *tkip_iv = NULL;
  700. if (!priv->has_wpa ||
  701. (ext->key_len > sizeof(priv->tkip_key[0])))
  702. goto out;
  703. priv->encode_alg = ORINOCO_ALG_TKIP;
  704. memset(&priv->tkip_key[idx], 0,
  705. sizeof(priv->tkip_key[idx]));
  706. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  707. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  708. tkip_iv = &ext->rx_seq[0];
  709. err = __orinoco_hw_set_tkip_key(priv, idx,
  710. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  711. (u8 *) &priv->tkip_key[idx],
  712. tkip_iv, NULL);
  713. if (err)
  714. printk(KERN_ERR "%s: Error %d setting TKIP key"
  715. "\n", dev->name, err);
  716. goto out;
  717. }
  718. default:
  719. goto out;
  720. }
  721. }
  722. err = -EINPROGRESS;
  723. out:
  724. orinoco_unlock(priv, &flags);
  725. return err;
  726. }
  727. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  728. struct iw_request_info *info,
  729. union iwreq_data *wrqu,
  730. char *extra)
  731. {
  732. struct orinoco_private *priv = ndev_priv(dev);
  733. struct iw_point *encoding = &wrqu->encoding;
  734. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  735. int idx, max_key_len;
  736. unsigned long flags;
  737. int err;
  738. if (orinoco_lock(priv, &flags) != 0)
  739. return -EBUSY;
  740. err = -EINVAL;
  741. max_key_len = encoding->length - sizeof(*ext);
  742. if (max_key_len < 0)
  743. goto out;
  744. idx = encoding->flags & IW_ENCODE_INDEX;
  745. if (idx) {
  746. if ((idx < 1) || (idx > 4))
  747. goto out;
  748. idx--;
  749. } else
  750. idx = priv->tx_key;
  751. encoding->flags = idx + 1;
  752. memset(ext, 0, sizeof(*ext));
  753. switch (priv->encode_alg) {
  754. case ORINOCO_ALG_NONE:
  755. ext->alg = IW_ENCODE_ALG_NONE;
  756. ext->key_len = 0;
  757. encoding->flags |= IW_ENCODE_DISABLED;
  758. break;
  759. case ORINOCO_ALG_WEP:
  760. ext->alg = IW_ENCODE_ALG_WEP;
  761. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  762. max_key_len);
  763. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  764. encoding->flags |= IW_ENCODE_ENABLED;
  765. break;
  766. case ORINOCO_ALG_TKIP:
  767. ext->alg = 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. };