wext.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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_getiwrange(struct net_device *dev,
  147. struct iw_request_info *info,
  148. struct iw_point *rrq,
  149. char *extra)
  150. {
  151. struct orinoco_private *priv = ndev_priv(dev);
  152. int err = 0;
  153. struct iw_range *range = (struct iw_range *) extra;
  154. int numrates;
  155. int i, k;
  156. rrq->length = sizeof(struct iw_range);
  157. memset(range, 0, sizeof(struct iw_range));
  158. range->we_version_compiled = WIRELESS_EXT;
  159. range->we_version_source = 22;
  160. /* Set available channels/frequencies */
  161. range->num_channels = NUM_CHANNELS;
  162. k = 0;
  163. for (i = 0; i < NUM_CHANNELS; i++) {
  164. if (priv->channel_mask & (1 << i)) {
  165. range->freq[k].i = i + 1;
  166. range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
  167. 100000);
  168. range->freq[k].e = 1;
  169. k++;
  170. }
  171. if (k >= IW_MAX_FREQUENCIES)
  172. break;
  173. }
  174. range->num_frequency = k;
  175. range->sensitivity = 3;
  176. if (priv->has_wep) {
  177. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  178. range->encoding_size[0] = SMALL_KEY_SIZE;
  179. range->num_encoding_sizes = 1;
  180. if (priv->has_big_wep) {
  181. range->encoding_size[1] = LARGE_KEY_SIZE;
  182. range->num_encoding_sizes = 2;
  183. }
  184. }
  185. if (priv->has_wpa)
  186. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
  187. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && (!SPY_NUMBER(priv))) {
  188. /* Quality stats meaningless in ad-hoc mode */
  189. } else {
  190. range->max_qual.qual = 0x8b - 0x2f;
  191. range->max_qual.level = 0x2f - 0x95 - 1;
  192. range->max_qual.noise = 0x2f - 0x95 - 1;
  193. /* Need to get better values */
  194. range->avg_qual.qual = 0x24;
  195. range->avg_qual.level = 0xC2;
  196. range->avg_qual.noise = 0x9E;
  197. }
  198. err = orinoco_hw_get_bitratelist(priv, &numrates,
  199. range->bitrate, IW_MAX_BITRATES);
  200. if (err)
  201. return err;
  202. range->num_bitrates = numrates;
  203. /* Set an indication of the max TCP throughput in bit/s that we can
  204. * expect using this interface. May be use for QoS stuff...
  205. * Jean II */
  206. if (numrates > 2)
  207. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  208. else
  209. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  210. range->min_rts = 0;
  211. range->max_rts = 2347;
  212. range->min_frag = 256;
  213. range->max_frag = 2346;
  214. range->min_pmp = 0;
  215. range->max_pmp = 65535000;
  216. range->min_pmt = 0;
  217. range->max_pmt = 65535 * 1000; /* ??? */
  218. range->pmp_flags = IW_POWER_PERIOD;
  219. range->pmt_flags = IW_POWER_TIMEOUT;
  220. range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
  221. IW_POWER_UNICAST_R);
  222. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  223. range->retry_flags = IW_RETRY_LIMIT;
  224. range->r_time_flags = IW_RETRY_LIFETIME;
  225. range->min_retry = 0;
  226. range->max_retry = 65535; /* ??? */
  227. range->min_r_time = 0;
  228. range->max_r_time = 65535 * 1000; /* ??? */
  229. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  230. range->scan_capa = IW_SCAN_CAPA_ESSID;
  231. else
  232. range->scan_capa = IW_SCAN_CAPA_NONE;
  233. /* Event capability (kernel) */
  234. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  235. /* Event capability (driver) */
  236. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  237. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  238. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  239. IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
  240. return 0;
  241. }
  242. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  243. struct iw_request_info *info,
  244. struct iw_point *erq,
  245. char *keybuf)
  246. {
  247. struct orinoco_private *priv = ndev_priv(dev);
  248. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  249. int setindex = priv->tx_key;
  250. int encode_alg = priv->encode_alg;
  251. int restricted = priv->wep_restrict;
  252. u16 xlen = 0;
  253. int err = -EINPROGRESS; /* Call commit handler */
  254. unsigned long flags;
  255. if (!priv->has_wep)
  256. return -EOPNOTSUPP;
  257. if (erq->pointer) {
  258. /* We actually have a key to set - check its length */
  259. if (erq->length > LARGE_KEY_SIZE)
  260. return -E2BIG;
  261. if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
  262. return -E2BIG;
  263. }
  264. if (orinoco_lock(priv, &flags) != 0)
  265. return -EBUSY;
  266. /* Clear any TKIP key we have */
  267. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  268. (void) orinoco_clear_tkip_key(priv, setindex);
  269. if (erq->length > 0) {
  270. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  271. index = priv->tx_key;
  272. /* Adjust key length to a supported value */
  273. if (erq->length > SMALL_KEY_SIZE)
  274. xlen = LARGE_KEY_SIZE;
  275. else if (erq->length > 0)
  276. xlen = SMALL_KEY_SIZE;
  277. else
  278. xlen = 0;
  279. /* Switch on WEP if off */
  280. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  281. setindex = index;
  282. encode_alg = IW_ENCODE_ALG_WEP;
  283. }
  284. } else {
  285. /* Important note : if the user do "iwconfig eth0 enc off",
  286. * we will arrive there with an index of -1. This is valid
  287. * but need to be taken care off... Jean II */
  288. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  289. if ((index != -1) || (erq->flags == 0)) {
  290. err = -EINVAL;
  291. goto out;
  292. }
  293. } else {
  294. /* Set the index : Check that the key is valid */
  295. if (priv->keys[index].len == 0) {
  296. err = -EINVAL;
  297. goto out;
  298. }
  299. setindex = index;
  300. }
  301. }
  302. if (erq->flags & IW_ENCODE_DISABLED)
  303. encode_alg = IW_ENCODE_ALG_NONE;
  304. if (erq->flags & IW_ENCODE_OPEN)
  305. restricted = 0;
  306. if (erq->flags & IW_ENCODE_RESTRICTED)
  307. restricted = 1;
  308. if (erq->pointer && erq->length > 0) {
  309. priv->keys[index].len = cpu_to_le16(xlen);
  310. memset(priv->keys[index].data, 0,
  311. sizeof(priv->keys[index].data));
  312. memcpy(priv->keys[index].data, keybuf, erq->length);
  313. }
  314. priv->tx_key = setindex;
  315. /* Try fast key change if connected and only keys are changed */
  316. if ((priv->encode_alg == encode_alg) &&
  317. (priv->wep_restrict == restricted) &&
  318. netif_carrier_ok(dev)) {
  319. err = __orinoco_hw_setup_wepkeys(priv);
  320. /* No need to commit if successful */
  321. goto out;
  322. }
  323. priv->encode_alg = encode_alg;
  324. priv->wep_restrict = restricted;
  325. out:
  326. orinoco_unlock(priv, &flags);
  327. return err;
  328. }
  329. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  330. struct iw_request_info *info,
  331. struct iw_point *erq,
  332. char *keybuf)
  333. {
  334. struct orinoco_private *priv = ndev_priv(dev);
  335. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  336. u16 xlen = 0;
  337. unsigned long flags;
  338. if (!priv->has_wep)
  339. return -EOPNOTSUPP;
  340. if (orinoco_lock(priv, &flags) != 0)
  341. return -EBUSY;
  342. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  343. index = priv->tx_key;
  344. erq->flags = 0;
  345. if (!priv->encode_alg)
  346. erq->flags |= IW_ENCODE_DISABLED;
  347. erq->flags |= index + 1;
  348. if (priv->wep_restrict)
  349. erq->flags |= IW_ENCODE_RESTRICTED;
  350. else
  351. erq->flags |= IW_ENCODE_OPEN;
  352. xlen = le16_to_cpu(priv->keys[index].len);
  353. erq->length = xlen;
  354. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  355. orinoco_unlock(priv, &flags);
  356. return 0;
  357. }
  358. static int orinoco_ioctl_setessid(struct net_device *dev,
  359. struct iw_request_info *info,
  360. struct iw_point *erq,
  361. char *essidbuf)
  362. {
  363. struct orinoco_private *priv = ndev_priv(dev);
  364. unsigned long flags;
  365. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  366. * anyway... - Jean II */
  367. /* Hum... Should not use Wireless Extension constant (may change),
  368. * should use our own... - Jean II */
  369. if (erq->length > IW_ESSID_MAX_SIZE)
  370. return -E2BIG;
  371. if (orinoco_lock(priv, &flags) != 0)
  372. return -EBUSY;
  373. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  374. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  375. /* If not ANY, get the new ESSID */
  376. if (erq->flags)
  377. memcpy(priv->desired_essid, essidbuf, erq->length);
  378. orinoco_unlock(priv, &flags);
  379. return -EINPROGRESS; /* Call commit handler */
  380. }
  381. static int orinoco_ioctl_getessid(struct net_device *dev,
  382. struct iw_request_info *info,
  383. struct iw_point *erq,
  384. char *essidbuf)
  385. {
  386. struct orinoco_private *priv = ndev_priv(dev);
  387. int active;
  388. int err = 0;
  389. unsigned long flags;
  390. if (netif_running(dev)) {
  391. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  392. if (err < 0)
  393. return err;
  394. erq->length = err;
  395. } else {
  396. if (orinoco_lock(priv, &flags) != 0)
  397. return -EBUSY;
  398. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  399. erq->length = strlen(priv->desired_essid);
  400. orinoco_unlock(priv, &flags);
  401. }
  402. erq->flags = 1;
  403. return 0;
  404. }
  405. static int orinoco_ioctl_setnick(struct net_device *dev,
  406. struct iw_request_info *info,
  407. struct iw_point *nrq,
  408. char *nickbuf)
  409. {
  410. struct orinoco_private *priv = ndev_priv(dev);
  411. unsigned long flags;
  412. if (nrq->length > IW_ESSID_MAX_SIZE)
  413. return -E2BIG;
  414. if (orinoco_lock(priv, &flags) != 0)
  415. return -EBUSY;
  416. memset(priv->nick, 0, sizeof(priv->nick));
  417. memcpy(priv->nick, nickbuf, nrq->length);
  418. orinoco_unlock(priv, &flags);
  419. return -EINPROGRESS; /* Call commit handler */
  420. }
  421. static int orinoco_ioctl_getnick(struct net_device *dev,
  422. struct iw_request_info *info,
  423. struct iw_point *nrq,
  424. char *nickbuf)
  425. {
  426. struct orinoco_private *priv = ndev_priv(dev);
  427. unsigned long flags;
  428. if (orinoco_lock(priv, &flags) != 0)
  429. return -EBUSY;
  430. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
  431. orinoco_unlock(priv, &flags);
  432. nrq->length = strlen(priv->nick);
  433. return 0;
  434. }
  435. static int orinoco_ioctl_setfreq(struct net_device *dev,
  436. struct iw_request_info *info,
  437. struct iw_freq *frq,
  438. char *extra)
  439. {
  440. struct orinoco_private *priv = ndev_priv(dev);
  441. int chan = -1;
  442. unsigned long flags;
  443. int err = -EINPROGRESS; /* Call commit handler */
  444. /* In infrastructure mode the AP sets the channel */
  445. if (priv->iw_mode == NL80211_IFTYPE_STATION)
  446. return -EBUSY;
  447. if ((frq->e == 0) && (frq->m <= 1000)) {
  448. /* Setting by channel number */
  449. chan = frq->m;
  450. } else {
  451. /* Setting by frequency */
  452. int denom = 1;
  453. int i;
  454. /* Calculate denominator to rescale to MHz */
  455. for (i = 0; i < (6 - frq->e); i++)
  456. denom *= 10;
  457. chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
  458. }
  459. if ((chan < 1) || (chan > NUM_CHANNELS) ||
  460. !(priv->channel_mask & (1 << (chan-1))))
  461. return -EINVAL;
  462. if (orinoco_lock(priv, &flags) != 0)
  463. return -EBUSY;
  464. priv->channel = chan;
  465. if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
  466. /* Fast channel change - no commit if successful */
  467. hermes_t *hw = &priv->hw;
  468. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  469. HERMES_TEST_SET_CHANNEL,
  470. chan, NULL);
  471. }
  472. orinoco_unlock(priv, &flags);
  473. return err;
  474. }
  475. static int orinoco_ioctl_getfreq(struct net_device *dev,
  476. struct iw_request_info *info,
  477. struct iw_freq *frq,
  478. char *extra)
  479. {
  480. struct orinoco_private *priv = ndev_priv(dev);
  481. int tmp;
  482. /* Locking done in there */
  483. tmp = orinoco_hw_get_freq(priv);
  484. if (tmp < 0)
  485. return tmp;
  486. frq->m = tmp * 100000;
  487. frq->e = 1;
  488. return 0;
  489. }
  490. static int orinoco_ioctl_getsens(struct net_device *dev,
  491. struct iw_request_info *info,
  492. struct iw_param *srq,
  493. char *extra)
  494. {
  495. struct orinoco_private *priv = ndev_priv(dev);
  496. hermes_t *hw = &priv->hw;
  497. u16 val;
  498. int err;
  499. unsigned long flags;
  500. if (!priv->has_sensitivity)
  501. return -EOPNOTSUPP;
  502. if (orinoco_lock(priv, &flags) != 0)
  503. return -EBUSY;
  504. err = hermes_read_wordrec(hw, USER_BAP,
  505. HERMES_RID_CNFSYSTEMSCALE, &val);
  506. orinoco_unlock(priv, &flags);
  507. if (err)
  508. return err;
  509. srq->value = val;
  510. srq->fixed = 0; /* auto */
  511. return 0;
  512. }
  513. static int orinoco_ioctl_setsens(struct net_device *dev,
  514. struct iw_request_info *info,
  515. struct iw_param *srq,
  516. char *extra)
  517. {
  518. struct orinoco_private *priv = ndev_priv(dev);
  519. int val = srq->value;
  520. unsigned long flags;
  521. if (!priv->has_sensitivity)
  522. return -EOPNOTSUPP;
  523. if ((val < 1) || (val > 3))
  524. return -EINVAL;
  525. if (orinoco_lock(priv, &flags) != 0)
  526. return -EBUSY;
  527. priv->ap_density = val;
  528. orinoco_unlock(priv, &flags);
  529. return -EINPROGRESS; /* Call commit handler */
  530. }
  531. static int orinoco_ioctl_setrts(struct net_device *dev,
  532. struct iw_request_info *info,
  533. struct iw_param *rrq,
  534. char *extra)
  535. {
  536. struct orinoco_private *priv = ndev_priv(dev);
  537. int val = rrq->value;
  538. unsigned long flags;
  539. if (rrq->disabled)
  540. val = 2347;
  541. if ((val < 0) || (val > 2347))
  542. return -EINVAL;
  543. if (orinoco_lock(priv, &flags) != 0)
  544. return -EBUSY;
  545. priv->rts_thresh = val;
  546. orinoco_unlock(priv, &flags);
  547. return -EINPROGRESS; /* Call commit handler */
  548. }
  549. static int orinoco_ioctl_getrts(struct net_device *dev,
  550. struct iw_request_info *info,
  551. struct iw_param *rrq,
  552. char *extra)
  553. {
  554. struct orinoco_private *priv = ndev_priv(dev);
  555. rrq->value = priv->rts_thresh;
  556. rrq->disabled = (rrq->value == 2347);
  557. rrq->fixed = 1;
  558. return 0;
  559. }
  560. static int orinoco_ioctl_setfrag(struct net_device *dev,
  561. struct iw_request_info *info,
  562. struct iw_param *frq,
  563. char *extra)
  564. {
  565. struct orinoco_private *priv = ndev_priv(dev);
  566. int err = -EINPROGRESS; /* Call commit handler */
  567. unsigned long flags;
  568. if (orinoco_lock(priv, &flags) != 0)
  569. return -EBUSY;
  570. if (priv->has_mwo) {
  571. if (frq->disabled)
  572. priv->mwo_robust = 0;
  573. else {
  574. if (frq->fixed)
  575. printk(KERN_WARNING "%s: Fixed fragmentation "
  576. "is not supported on this firmware. "
  577. "Using MWO robust instead.\n",
  578. dev->name);
  579. priv->mwo_robust = 1;
  580. }
  581. } else {
  582. if (frq->disabled)
  583. priv->frag_thresh = 2346;
  584. else {
  585. if ((frq->value < 256) || (frq->value > 2346))
  586. err = -EINVAL;
  587. else
  588. /* must be even */
  589. priv->frag_thresh = frq->value & ~0x1;
  590. }
  591. }
  592. orinoco_unlock(priv, &flags);
  593. return err;
  594. }
  595. static int orinoco_ioctl_getfrag(struct net_device *dev,
  596. struct iw_request_info *info,
  597. struct iw_param *frq,
  598. char *extra)
  599. {
  600. struct orinoco_private *priv = ndev_priv(dev);
  601. hermes_t *hw = &priv->hw;
  602. int err;
  603. u16 val;
  604. unsigned long flags;
  605. if (orinoco_lock(priv, &flags) != 0)
  606. return -EBUSY;
  607. if (priv->has_mwo) {
  608. err = hermes_read_wordrec(hw, USER_BAP,
  609. HERMES_RID_CNFMWOROBUST_AGERE,
  610. &val);
  611. if (err)
  612. val = 0;
  613. frq->value = val ? 2347 : 0;
  614. frq->disabled = !val;
  615. frq->fixed = 0;
  616. } else {
  617. err = hermes_read_wordrec(hw, USER_BAP,
  618. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  619. &val);
  620. if (err)
  621. val = 0;
  622. frq->value = val;
  623. frq->disabled = (val >= 2346);
  624. frq->fixed = 1;
  625. }
  626. orinoco_unlock(priv, &flags);
  627. return err;
  628. }
  629. static int orinoco_ioctl_setrate(struct net_device *dev,
  630. struct iw_request_info *info,
  631. struct iw_param *rrq,
  632. char *extra)
  633. {
  634. struct orinoco_private *priv = ndev_priv(dev);
  635. int ratemode;
  636. int bitrate; /* 100s of kilobits */
  637. unsigned long flags;
  638. /* As the user space doesn't know our highest rate, it uses -1
  639. * to ask us to set the highest rate. Test it using "iwconfig
  640. * ethX rate auto" - Jean II */
  641. if (rrq->value == -1)
  642. bitrate = 110;
  643. else {
  644. if (rrq->value % 100000)
  645. return -EINVAL;
  646. bitrate = rrq->value / 100000;
  647. }
  648. ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
  649. if (ratemode == -1)
  650. return -EINVAL;
  651. if (orinoco_lock(priv, &flags) != 0)
  652. return -EBUSY;
  653. priv->bitratemode = ratemode;
  654. orinoco_unlock(priv, &flags);
  655. return -EINPROGRESS;
  656. }
  657. static int orinoco_ioctl_getrate(struct net_device *dev,
  658. struct iw_request_info *info,
  659. struct iw_param *rrq,
  660. char *extra)
  661. {
  662. struct orinoco_private *priv = ndev_priv(dev);
  663. int err = 0;
  664. int bitrate, automatic;
  665. unsigned long flags;
  666. if (orinoco_lock(priv, &flags) != 0)
  667. return -EBUSY;
  668. orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
  669. /* If the interface is running we try to find more about the
  670. current mode */
  671. if (netif_running(dev))
  672. err = orinoco_hw_get_act_bitrate(priv, &bitrate);
  673. orinoco_unlock(priv, &flags);
  674. rrq->value = bitrate;
  675. rrq->fixed = !automatic;
  676. rrq->disabled = 0;
  677. return err;
  678. }
  679. static int orinoco_ioctl_setpower(struct net_device *dev,
  680. struct iw_request_info *info,
  681. struct iw_param *prq,
  682. char *extra)
  683. {
  684. struct orinoco_private *priv = ndev_priv(dev);
  685. int err = -EINPROGRESS; /* Call commit handler */
  686. unsigned long flags;
  687. if (orinoco_lock(priv, &flags) != 0)
  688. return -EBUSY;
  689. if (prq->disabled) {
  690. priv->pm_on = 0;
  691. } else {
  692. switch (prq->flags & IW_POWER_MODE) {
  693. case IW_POWER_UNICAST_R:
  694. priv->pm_mcast = 0;
  695. priv->pm_on = 1;
  696. break;
  697. case IW_POWER_ALL_R:
  698. priv->pm_mcast = 1;
  699. priv->pm_on = 1;
  700. break;
  701. case IW_POWER_ON:
  702. /* No flags : but we may have a value - Jean II */
  703. break;
  704. default:
  705. err = -EINVAL;
  706. goto out;
  707. }
  708. if (prq->flags & IW_POWER_TIMEOUT) {
  709. priv->pm_on = 1;
  710. priv->pm_timeout = prq->value / 1000;
  711. }
  712. if (prq->flags & IW_POWER_PERIOD) {
  713. priv->pm_on = 1;
  714. priv->pm_period = prq->value / 1000;
  715. }
  716. /* It's valid to not have a value if we are just toggling
  717. * the flags... Jean II */
  718. if (!priv->pm_on) {
  719. err = -EINVAL;
  720. goto out;
  721. }
  722. }
  723. out:
  724. orinoco_unlock(priv, &flags);
  725. return err;
  726. }
  727. static int orinoco_ioctl_getpower(struct net_device *dev,
  728. struct iw_request_info *info,
  729. struct iw_param *prq,
  730. char *extra)
  731. {
  732. struct orinoco_private *priv = ndev_priv(dev);
  733. hermes_t *hw = &priv->hw;
  734. int err = 0;
  735. u16 enable, period, timeout, mcast;
  736. unsigned long flags;
  737. if (orinoco_lock(priv, &flags) != 0)
  738. return -EBUSY;
  739. err = hermes_read_wordrec(hw, USER_BAP,
  740. HERMES_RID_CNFPMENABLED, &enable);
  741. if (err)
  742. goto out;
  743. err = hermes_read_wordrec(hw, USER_BAP,
  744. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  745. if (err)
  746. goto out;
  747. err = hermes_read_wordrec(hw, USER_BAP,
  748. HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  749. if (err)
  750. goto out;
  751. err = hermes_read_wordrec(hw, USER_BAP,
  752. HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  753. if (err)
  754. goto out;
  755. prq->disabled = !enable;
  756. /* Note : by default, display the period */
  757. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  758. prq->flags = IW_POWER_TIMEOUT;
  759. prq->value = timeout * 1000;
  760. } else {
  761. prq->flags = IW_POWER_PERIOD;
  762. prq->value = period * 1000;
  763. }
  764. if (mcast)
  765. prq->flags |= IW_POWER_ALL_R;
  766. else
  767. prq->flags |= IW_POWER_UNICAST_R;
  768. out:
  769. orinoco_unlock(priv, &flags);
  770. return err;
  771. }
  772. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  773. struct iw_request_info *info,
  774. union iwreq_data *wrqu,
  775. char *extra)
  776. {
  777. struct orinoco_private *priv = ndev_priv(dev);
  778. struct iw_point *encoding = &wrqu->encoding;
  779. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  780. int idx, alg = ext->alg, set_key = 1;
  781. unsigned long flags;
  782. int err = -EINVAL;
  783. u16 key_len;
  784. if (orinoco_lock(priv, &flags) != 0)
  785. return -EBUSY;
  786. /* Determine and validate the key index */
  787. idx = encoding->flags & IW_ENCODE_INDEX;
  788. if (idx) {
  789. if ((idx < 1) || (idx > 4))
  790. goto out;
  791. idx--;
  792. } else
  793. idx = priv->tx_key;
  794. if (encoding->flags & IW_ENCODE_DISABLED)
  795. alg = IW_ENCODE_ALG_NONE;
  796. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  797. /* Clear any TKIP TX key we had */
  798. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  799. }
  800. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  801. priv->tx_key = idx;
  802. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  803. (ext->key_len > 0)) ? 1 : 0;
  804. }
  805. if (set_key) {
  806. /* Set the requested key first */
  807. switch (alg) {
  808. case IW_ENCODE_ALG_NONE:
  809. priv->encode_alg = alg;
  810. priv->keys[idx].len = 0;
  811. break;
  812. case IW_ENCODE_ALG_WEP:
  813. if (ext->key_len > SMALL_KEY_SIZE)
  814. key_len = LARGE_KEY_SIZE;
  815. else if (ext->key_len > 0)
  816. key_len = SMALL_KEY_SIZE;
  817. else
  818. goto out;
  819. priv->encode_alg = alg;
  820. priv->keys[idx].len = cpu_to_le16(key_len);
  821. key_len = min(ext->key_len, key_len);
  822. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  823. memcpy(priv->keys[idx].data, ext->key, key_len);
  824. break;
  825. case IW_ENCODE_ALG_TKIP:
  826. {
  827. u8 *tkip_iv = NULL;
  828. if (!priv->has_wpa ||
  829. (ext->key_len > sizeof(priv->tkip_key[0])))
  830. goto out;
  831. priv->encode_alg = alg;
  832. memset(&priv->tkip_key[idx], 0,
  833. sizeof(priv->tkip_key[idx]));
  834. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  835. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  836. tkip_iv = &ext->rx_seq[0];
  837. err = __orinoco_hw_set_tkip_key(priv, idx,
  838. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  839. (u8 *) &priv->tkip_key[idx],
  840. tkip_iv, NULL);
  841. if (err)
  842. printk(KERN_ERR "%s: Error %d setting TKIP key"
  843. "\n", dev->name, err);
  844. goto out;
  845. }
  846. default:
  847. goto out;
  848. }
  849. }
  850. err = -EINPROGRESS;
  851. out:
  852. orinoco_unlock(priv, &flags);
  853. return err;
  854. }
  855. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  856. struct iw_request_info *info,
  857. union iwreq_data *wrqu,
  858. char *extra)
  859. {
  860. struct orinoco_private *priv = ndev_priv(dev);
  861. struct iw_point *encoding = &wrqu->encoding;
  862. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  863. int idx, max_key_len;
  864. unsigned long flags;
  865. int err;
  866. if (orinoco_lock(priv, &flags) != 0)
  867. return -EBUSY;
  868. err = -EINVAL;
  869. max_key_len = encoding->length - sizeof(*ext);
  870. if (max_key_len < 0)
  871. goto out;
  872. idx = encoding->flags & IW_ENCODE_INDEX;
  873. if (idx) {
  874. if ((idx < 1) || (idx > 4))
  875. goto out;
  876. idx--;
  877. } else
  878. idx = priv->tx_key;
  879. encoding->flags = idx + 1;
  880. memset(ext, 0, sizeof(*ext));
  881. ext->alg = priv->encode_alg;
  882. switch (priv->encode_alg) {
  883. case IW_ENCODE_ALG_NONE:
  884. ext->key_len = 0;
  885. encoding->flags |= IW_ENCODE_DISABLED;
  886. break;
  887. case IW_ENCODE_ALG_WEP:
  888. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  889. max_key_len);
  890. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  891. encoding->flags |= IW_ENCODE_ENABLED;
  892. break;
  893. case IW_ENCODE_ALG_TKIP:
  894. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  895. max_key_len);
  896. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  897. encoding->flags |= IW_ENCODE_ENABLED;
  898. break;
  899. }
  900. err = 0;
  901. out:
  902. orinoco_unlock(priv, &flags);
  903. return err;
  904. }
  905. static int orinoco_ioctl_set_auth(struct net_device *dev,
  906. struct iw_request_info *info,
  907. union iwreq_data *wrqu, char *extra)
  908. {
  909. struct orinoco_private *priv = ndev_priv(dev);
  910. hermes_t *hw = &priv->hw;
  911. struct iw_param *param = &wrqu->param;
  912. unsigned long flags;
  913. int ret = -EINPROGRESS;
  914. if (orinoco_lock(priv, &flags) != 0)
  915. return -EBUSY;
  916. switch (param->flags & IW_AUTH_INDEX) {
  917. case IW_AUTH_WPA_VERSION:
  918. case IW_AUTH_CIPHER_PAIRWISE:
  919. case IW_AUTH_CIPHER_GROUP:
  920. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  921. case IW_AUTH_PRIVACY_INVOKED:
  922. case IW_AUTH_DROP_UNENCRYPTED:
  923. /*
  924. * orinoco does not use these parameters
  925. */
  926. break;
  927. case IW_AUTH_KEY_MGMT:
  928. /* wl_lkm implies value 2 == PSK for Hermes I
  929. * which ties in with WEXT
  930. * no other hints tho :(
  931. */
  932. priv->key_mgmt = param->value;
  933. break;
  934. case IW_AUTH_TKIP_COUNTERMEASURES:
  935. /* When countermeasures are enabled, shut down the
  936. * card; when disabled, re-enable the card. This must
  937. * take effect immediately.
  938. *
  939. * TODO: Make sure that the EAPOL message is getting
  940. * out before card disabled
  941. */
  942. if (param->value) {
  943. priv->tkip_cm_active = 1;
  944. ret = hermes_enable_port(hw, 0);
  945. } else {
  946. priv->tkip_cm_active = 0;
  947. ret = hermes_disable_port(hw, 0);
  948. }
  949. break;
  950. case IW_AUTH_80211_AUTH_ALG:
  951. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  952. priv->wep_restrict = 1;
  953. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  954. priv->wep_restrict = 0;
  955. else
  956. ret = -EINVAL;
  957. break;
  958. case IW_AUTH_WPA_ENABLED:
  959. if (priv->has_wpa) {
  960. priv->wpa_enabled = param->value ? 1 : 0;
  961. } else {
  962. if (param->value)
  963. ret = -EOPNOTSUPP;
  964. /* else silently accept disable of WPA */
  965. priv->wpa_enabled = 0;
  966. }
  967. break;
  968. default:
  969. ret = -EOPNOTSUPP;
  970. }
  971. orinoco_unlock(priv, &flags);
  972. return ret;
  973. }
  974. static int orinoco_ioctl_get_auth(struct net_device *dev,
  975. struct iw_request_info *info,
  976. union iwreq_data *wrqu, char *extra)
  977. {
  978. struct orinoco_private *priv = ndev_priv(dev);
  979. struct iw_param *param = &wrqu->param;
  980. unsigned long flags;
  981. int ret = 0;
  982. if (orinoco_lock(priv, &flags) != 0)
  983. return -EBUSY;
  984. switch (param->flags & IW_AUTH_INDEX) {
  985. case IW_AUTH_KEY_MGMT:
  986. param->value = priv->key_mgmt;
  987. break;
  988. case IW_AUTH_TKIP_COUNTERMEASURES:
  989. param->value = priv->tkip_cm_active;
  990. break;
  991. case IW_AUTH_80211_AUTH_ALG:
  992. if (priv->wep_restrict)
  993. param->value = IW_AUTH_ALG_SHARED_KEY;
  994. else
  995. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  996. break;
  997. case IW_AUTH_WPA_ENABLED:
  998. param->value = priv->wpa_enabled;
  999. break;
  1000. default:
  1001. ret = -EOPNOTSUPP;
  1002. }
  1003. orinoco_unlock(priv, &flags);
  1004. return ret;
  1005. }
  1006. static int orinoco_ioctl_set_genie(struct net_device *dev,
  1007. struct iw_request_info *info,
  1008. union iwreq_data *wrqu, char *extra)
  1009. {
  1010. struct orinoco_private *priv = ndev_priv(dev);
  1011. u8 *buf;
  1012. unsigned long flags;
  1013. /* cut off at IEEE80211_MAX_DATA_LEN */
  1014. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  1015. (wrqu->data.length && (extra == NULL)))
  1016. return -EINVAL;
  1017. if (wrqu->data.length) {
  1018. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  1019. if (buf == NULL)
  1020. return -ENOMEM;
  1021. memcpy(buf, extra, wrqu->data.length);
  1022. } else
  1023. buf = NULL;
  1024. if (orinoco_lock(priv, &flags) != 0) {
  1025. kfree(buf);
  1026. return -EBUSY;
  1027. }
  1028. kfree(priv->wpa_ie);
  1029. priv->wpa_ie = buf;
  1030. priv->wpa_ie_len = wrqu->data.length;
  1031. if (priv->wpa_ie) {
  1032. /* Looks like wl_lkm wants to check the auth alg, and
  1033. * somehow pass it to the firmware.
  1034. * Instead it just calls the key mgmt rid
  1035. * - we do this in set auth.
  1036. */
  1037. }
  1038. orinoco_unlock(priv, &flags);
  1039. return 0;
  1040. }
  1041. static int orinoco_ioctl_get_genie(struct net_device *dev,
  1042. struct iw_request_info *info,
  1043. union iwreq_data *wrqu, char *extra)
  1044. {
  1045. struct orinoco_private *priv = ndev_priv(dev);
  1046. unsigned long flags;
  1047. int err = 0;
  1048. if (orinoco_lock(priv, &flags) != 0)
  1049. return -EBUSY;
  1050. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  1051. wrqu->data.length = 0;
  1052. goto out;
  1053. }
  1054. if (wrqu->data.length < priv->wpa_ie_len) {
  1055. err = -E2BIG;
  1056. goto out;
  1057. }
  1058. wrqu->data.length = priv->wpa_ie_len;
  1059. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  1060. out:
  1061. orinoco_unlock(priv, &flags);
  1062. return err;
  1063. }
  1064. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  1065. struct iw_request_info *info,
  1066. union iwreq_data *wrqu, char *extra)
  1067. {
  1068. struct orinoco_private *priv = ndev_priv(dev);
  1069. hermes_t *hw = &priv->hw;
  1070. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1071. unsigned long flags;
  1072. int ret = 0;
  1073. if (orinoco_lock(priv, &flags) != 0)
  1074. return -EBUSY;
  1075. switch (mlme->cmd) {
  1076. case IW_MLME_DEAUTH:
  1077. /* silently ignore */
  1078. break;
  1079. case IW_MLME_DISASSOC:
  1080. {
  1081. struct {
  1082. u8 addr[ETH_ALEN];
  1083. __le16 reason_code;
  1084. } __attribute__ ((packed)) buf;
  1085. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  1086. buf.reason_code = cpu_to_le16(mlme->reason_code);
  1087. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  1088. HERMES_RID_CNFDISASSOCIATE,
  1089. &buf);
  1090. break;
  1091. }
  1092. default:
  1093. ret = -EOPNOTSUPP;
  1094. }
  1095. orinoco_unlock(priv, &flags);
  1096. return ret;
  1097. }
  1098. static int orinoco_ioctl_getretry(struct net_device *dev,
  1099. struct iw_request_info *info,
  1100. struct iw_param *rrq,
  1101. char *extra)
  1102. {
  1103. struct orinoco_private *priv = ndev_priv(dev);
  1104. hermes_t *hw = &priv->hw;
  1105. int err = 0;
  1106. u16 short_limit, long_limit, lifetime;
  1107. unsigned long flags;
  1108. if (orinoco_lock(priv, &flags) != 0)
  1109. return -EBUSY;
  1110. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  1111. &short_limit);
  1112. if (err)
  1113. goto out;
  1114. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  1115. &long_limit);
  1116. if (err)
  1117. goto out;
  1118. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  1119. &lifetime);
  1120. if (err)
  1121. goto out;
  1122. rrq->disabled = 0; /* Can't be disabled */
  1123. /* Note : by default, display the retry number */
  1124. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  1125. rrq->flags = IW_RETRY_LIFETIME;
  1126. rrq->value = lifetime * 1000; /* ??? */
  1127. } else {
  1128. /* By default, display the min number */
  1129. if ((rrq->flags & IW_RETRY_LONG)) {
  1130. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  1131. rrq->value = long_limit;
  1132. } else {
  1133. rrq->flags = IW_RETRY_LIMIT;
  1134. rrq->value = short_limit;
  1135. if (short_limit != long_limit)
  1136. rrq->flags |= IW_RETRY_SHORT;
  1137. }
  1138. }
  1139. out:
  1140. orinoco_unlock(priv, &flags);
  1141. return err;
  1142. }
  1143. static int orinoco_ioctl_reset(struct net_device *dev,
  1144. struct iw_request_info *info,
  1145. void *wrqu,
  1146. char *extra)
  1147. {
  1148. struct orinoco_private *priv = ndev_priv(dev);
  1149. if (!capable(CAP_NET_ADMIN))
  1150. return -EPERM;
  1151. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  1152. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  1153. /* Firmware reset */
  1154. orinoco_reset(&priv->reset_work);
  1155. } else {
  1156. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  1157. schedule_work(&priv->reset_work);
  1158. }
  1159. return 0;
  1160. }
  1161. static int orinoco_ioctl_setibssport(struct net_device *dev,
  1162. struct iw_request_info *info,
  1163. void *wrqu,
  1164. char *extra)
  1165. {
  1166. struct orinoco_private *priv = ndev_priv(dev);
  1167. int val = *((int *) extra);
  1168. unsigned long flags;
  1169. if (orinoco_lock(priv, &flags) != 0)
  1170. return -EBUSY;
  1171. priv->ibss_port = val ;
  1172. /* Actually update the mode we are using */
  1173. set_port_type(priv);
  1174. orinoco_unlock(priv, &flags);
  1175. return -EINPROGRESS; /* Call commit handler */
  1176. }
  1177. static int orinoco_ioctl_getibssport(struct net_device *dev,
  1178. struct iw_request_info *info,
  1179. void *wrqu,
  1180. char *extra)
  1181. {
  1182. struct orinoco_private *priv = ndev_priv(dev);
  1183. int *val = (int *) extra;
  1184. *val = priv->ibss_port;
  1185. return 0;
  1186. }
  1187. static int orinoco_ioctl_setport3(struct net_device *dev,
  1188. struct iw_request_info *info,
  1189. void *wrqu,
  1190. char *extra)
  1191. {
  1192. struct orinoco_private *priv = ndev_priv(dev);
  1193. int val = *((int *) extra);
  1194. int err = 0;
  1195. unsigned long flags;
  1196. if (orinoco_lock(priv, &flags) != 0)
  1197. return -EBUSY;
  1198. switch (val) {
  1199. case 0: /* Try to do IEEE ad-hoc mode */
  1200. if (!priv->has_ibss) {
  1201. err = -EINVAL;
  1202. break;
  1203. }
  1204. priv->prefer_port3 = 0;
  1205. break;
  1206. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  1207. if (!priv->has_port3) {
  1208. err = -EINVAL;
  1209. break;
  1210. }
  1211. priv->prefer_port3 = 1;
  1212. break;
  1213. default:
  1214. err = -EINVAL;
  1215. }
  1216. if (!err) {
  1217. /* Actually update the mode we are using */
  1218. set_port_type(priv);
  1219. err = -EINPROGRESS;
  1220. }
  1221. orinoco_unlock(priv, &flags);
  1222. return err;
  1223. }
  1224. static int orinoco_ioctl_getport3(struct net_device *dev,
  1225. struct iw_request_info *info,
  1226. void *wrqu,
  1227. char *extra)
  1228. {
  1229. struct orinoco_private *priv = ndev_priv(dev);
  1230. int *val = (int *) extra;
  1231. *val = priv->prefer_port3;
  1232. return 0;
  1233. }
  1234. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  1235. struct iw_request_info *info,
  1236. void *wrqu,
  1237. char *extra)
  1238. {
  1239. struct orinoco_private *priv = ndev_priv(dev);
  1240. unsigned long flags;
  1241. int val;
  1242. if (!priv->has_preamble)
  1243. return -EOPNOTSUPP;
  1244. /* 802.11b has recently defined some short preamble.
  1245. * Basically, the Phy header has been reduced in size.
  1246. * This increase performance, especially at high rates
  1247. * (the preamble is transmitted at 1Mb/s), unfortunately
  1248. * this give compatibility troubles... - Jean II */
  1249. val = *((int *) extra);
  1250. if (orinoco_lock(priv, &flags) != 0)
  1251. return -EBUSY;
  1252. if (val)
  1253. priv->preamble = 1;
  1254. else
  1255. priv->preamble = 0;
  1256. orinoco_unlock(priv, &flags);
  1257. return -EINPROGRESS; /* Call commit handler */
  1258. }
  1259. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  1260. struct iw_request_info *info,
  1261. void *wrqu,
  1262. char *extra)
  1263. {
  1264. struct orinoco_private *priv = ndev_priv(dev);
  1265. int *val = (int *) extra;
  1266. if (!priv->has_preamble)
  1267. return -EOPNOTSUPP;
  1268. *val = priv->preamble;
  1269. return 0;
  1270. }
  1271. /* ioctl interface to hermes_read_ltv()
  1272. * To use with iwpriv, pass the RID as the token argument, e.g.
  1273. * iwpriv get_rid [0xfc00]
  1274. * At least Wireless Tools 25 is required to use iwpriv.
  1275. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  1276. static int orinoco_ioctl_getrid(struct net_device *dev,
  1277. struct iw_request_info *info,
  1278. struct iw_point *data,
  1279. char *extra)
  1280. {
  1281. struct orinoco_private *priv = ndev_priv(dev);
  1282. hermes_t *hw = &priv->hw;
  1283. int rid = data->flags;
  1284. u16 length;
  1285. int err;
  1286. unsigned long flags;
  1287. /* It's a "get" function, but we don't want users to access the
  1288. * WEP key and other raw firmware data */
  1289. if (!capable(CAP_NET_ADMIN))
  1290. return -EPERM;
  1291. if (rid < 0xfc00 || rid > 0xffff)
  1292. return -EINVAL;
  1293. if (orinoco_lock(priv, &flags) != 0)
  1294. return -EBUSY;
  1295. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  1296. extra);
  1297. if (err)
  1298. goto out;
  1299. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  1300. MAX_RID_LEN);
  1301. out:
  1302. orinoco_unlock(priv, &flags);
  1303. return err;
  1304. }
  1305. /* Commit handler, called after set operations */
  1306. static int orinoco_ioctl_commit(struct net_device *dev,
  1307. struct iw_request_info *info,
  1308. void *wrqu,
  1309. char *extra)
  1310. {
  1311. struct orinoco_private *priv = ndev_priv(dev);
  1312. unsigned long flags;
  1313. int err = 0;
  1314. if (!priv->open)
  1315. return 0;
  1316. if (orinoco_lock(priv, &flags) != 0)
  1317. return err;
  1318. err = orinoco_commit(priv);
  1319. orinoco_unlock(priv, &flags);
  1320. return err;
  1321. }
  1322. static const struct iw_priv_args orinoco_privtab[] = {
  1323. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  1324. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  1325. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1326. 0, "set_port3" },
  1327. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1328. "get_port3" },
  1329. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1330. 0, "set_preamble" },
  1331. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1332. "get_preamble" },
  1333. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1334. 0, "set_ibssport" },
  1335. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1336. "get_ibssport" },
  1337. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  1338. "get_rid" },
  1339. };
  1340. /*
  1341. * Structures to export the Wireless Handlers
  1342. */
  1343. #define STD_IW_HANDLER(id, func) \
  1344. [IW_IOCTL_IDX(id)] = (iw_handler) func
  1345. static const iw_handler orinoco_handler[] = {
  1346. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  1347. STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname),
  1348. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  1349. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  1350. STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode),
  1351. STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode),
  1352. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  1353. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  1354. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  1355. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  1356. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  1357. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  1358. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  1359. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  1360. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  1361. STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan),
  1362. STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan),
  1363. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  1364. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  1365. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  1366. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  1367. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  1368. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  1369. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  1370. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  1371. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  1372. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  1373. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  1374. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  1375. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  1376. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  1377. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  1378. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  1379. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  1380. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  1381. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  1382. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  1383. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  1384. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  1385. };
  1386. /*
  1387. Added typecasting since we no longer use iwreq_data -- Moustafa
  1388. */
  1389. static const iw_handler orinoco_private_handler[] = {
  1390. [0] = (iw_handler) orinoco_ioctl_reset,
  1391. [1] = (iw_handler) orinoco_ioctl_reset,
  1392. [2] = (iw_handler) orinoco_ioctl_setport3,
  1393. [3] = (iw_handler) orinoco_ioctl_getport3,
  1394. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  1395. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  1396. [6] = (iw_handler) orinoco_ioctl_setibssport,
  1397. [7] = (iw_handler) orinoco_ioctl_getibssport,
  1398. [9] = (iw_handler) orinoco_ioctl_getrid,
  1399. };
  1400. const struct iw_handler_def orinoco_handler_def = {
  1401. .num_standard = ARRAY_SIZE(orinoco_handler),
  1402. .num_private = ARRAY_SIZE(orinoco_private_handler),
  1403. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  1404. .standard = orinoco_handler,
  1405. .private = orinoco_private_handler,
  1406. .private_args = orinoco_privtab,
  1407. .get_wireless_stats = orinoco_get_wireless_stats,
  1408. };