wext.c 37 KB

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