wext.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  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 "hermes.h"
  11. #include "hermes_rid.h"
  12. #include "orinoco.h"
  13. #include "hw.h"
  14. #include "mic.h"
  15. #include "scan.h"
  16. #include "main.h"
  17. #include "wext.h"
  18. #define MAX_RID_LEN 1024
  19. static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
  20. {
  21. struct orinoco_private *priv = netdev_priv(dev);
  22. hermes_t *hw = &priv->hw;
  23. struct iw_statistics *wstats = &priv->wstats;
  24. int err;
  25. unsigned long flags;
  26. if (!netif_device_present(dev)) {
  27. printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
  28. dev->name);
  29. return NULL; /* FIXME: Can we do better than this? */
  30. }
  31. /* If busy, return the old stats. Returning NULL may cause
  32. * the interface to disappear from /proc/net/wireless */
  33. if (orinoco_lock(priv, &flags) != 0)
  34. return wstats;
  35. /* We can't really wait for the tallies inquiry command to
  36. * complete, so we just use the previous results and trigger
  37. * a new tallies inquiry command for next time - Jean II */
  38. /* FIXME: Really we should wait for the inquiry to come back -
  39. * as it is the stats we give don't make a whole lot of sense.
  40. * Unfortunately, it's not clear how to do that within the
  41. * wireless extensions framework: I think we're in user
  42. * context, but a lock seems to be held by the time we get in
  43. * here so we're not safe to sleep here. */
  44. hermes_inquire(hw, HERMES_INQ_TALLIES);
  45. if (priv->iw_mode == IW_MODE_ADHOC) {
  46. memset(&wstats->qual, 0, sizeof(wstats->qual));
  47. /* If a spy address is defined, we report stats of the
  48. * first spy address - Jean II */
  49. if (SPY_NUMBER(priv)) {
  50. wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
  51. wstats->qual.level = priv->spy_data.spy_stat[0].level;
  52. wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
  53. wstats->qual.updated =
  54. priv->spy_data.spy_stat[0].updated;
  55. }
  56. } else {
  57. struct {
  58. __le16 qual, signal, noise, unused;
  59. } __attribute__ ((packed)) cq;
  60. err = HERMES_READ_RECORD(hw, USER_BAP,
  61. HERMES_RID_COMMSQUALITY, &cq);
  62. if (!err) {
  63. wstats->qual.qual = (int)le16_to_cpu(cq.qual);
  64. wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
  65. wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
  66. wstats->qual.updated =
  67. IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
  68. }
  69. }
  70. orinoco_unlock(priv, &flags);
  71. return wstats;
  72. }
  73. /********************************************************************/
  74. /* Wireless extensions */
  75. /********************************************************************/
  76. static int orinoco_ioctl_getname(struct net_device *dev,
  77. struct iw_request_info *info,
  78. char *name,
  79. char *extra)
  80. {
  81. struct orinoco_private *priv = netdev_priv(dev);
  82. int numrates;
  83. int err;
  84. err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
  85. if (!err && (numrates > 2))
  86. strcpy(name, "IEEE 802.11b");
  87. else
  88. strcpy(name, "IEEE 802.11-DS");
  89. return 0;
  90. }
  91. static int orinoco_ioctl_setwap(struct net_device *dev,
  92. struct iw_request_info *info,
  93. struct sockaddr *ap_addr,
  94. char *extra)
  95. {
  96. struct orinoco_private *priv = netdev_priv(dev);
  97. int err = -EINPROGRESS; /* Call commit handler */
  98. unsigned long flags;
  99. static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  100. static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  101. if (orinoco_lock(priv, &flags) != 0)
  102. return -EBUSY;
  103. /* Enable automatic roaming - no sanity checks are needed */
  104. if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
  105. memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
  106. priv->bssid_fixed = 0;
  107. memset(priv->desired_bssid, 0, ETH_ALEN);
  108. /* "off" means keep existing connection */
  109. if (ap_addr->sa_data[0] == 0) {
  110. __orinoco_hw_set_wap(priv);
  111. err = 0;
  112. }
  113. goto out;
  114. }
  115. if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
  116. printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
  117. "support manual roaming\n",
  118. dev->name);
  119. err = -EOPNOTSUPP;
  120. goto out;
  121. }
  122. if (priv->iw_mode != IW_MODE_INFRA) {
  123. printk(KERN_WARNING "%s: Manual roaming supported only in "
  124. "managed mode\n", dev->name);
  125. err = -EOPNOTSUPP;
  126. goto out;
  127. }
  128. /* Intersil firmware hangs without Desired ESSID */
  129. if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
  130. strlen(priv->desired_essid) == 0) {
  131. printk(KERN_WARNING "%s: Desired ESSID must be set for "
  132. "manual roaming\n", dev->name);
  133. err = -EOPNOTSUPP;
  134. goto out;
  135. }
  136. /* Finally, enable manual roaming */
  137. priv->bssid_fixed = 1;
  138. memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
  139. out:
  140. orinoco_unlock(priv, &flags);
  141. return err;
  142. }
  143. static int orinoco_ioctl_getwap(struct net_device *dev,
  144. struct iw_request_info *info,
  145. struct sockaddr *ap_addr,
  146. char *extra)
  147. {
  148. struct orinoco_private *priv = netdev_priv(dev);
  149. hermes_t *hw = &priv->hw;
  150. int err = 0;
  151. unsigned long flags;
  152. if (orinoco_lock(priv, &flags) != 0)
  153. return -EBUSY;
  154. ap_addr->sa_family = ARPHRD_ETHER;
  155. err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
  156. ETH_ALEN, NULL, ap_addr->sa_data);
  157. orinoco_unlock(priv, &flags);
  158. return err;
  159. }
  160. static int orinoco_ioctl_setmode(struct net_device *dev,
  161. struct iw_request_info *info,
  162. u32 *mode,
  163. char *extra)
  164. {
  165. struct orinoco_private *priv = netdev_priv(dev);
  166. int err = -EINPROGRESS; /* Call commit handler */
  167. unsigned long flags;
  168. if (priv->iw_mode == *mode)
  169. return 0;
  170. if (orinoco_lock(priv, &flags) != 0)
  171. return -EBUSY;
  172. switch (*mode) {
  173. case IW_MODE_ADHOC:
  174. if (!priv->has_ibss && !priv->has_port3)
  175. err = -EOPNOTSUPP;
  176. break;
  177. case IW_MODE_INFRA:
  178. break;
  179. case IW_MODE_MONITOR:
  180. if (priv->broken_monitor && !force_monitor) {
  181. printk(KERN_WARNING "%s: Monitor mode support is "
  182. "buggy in this firmware, not enabling\n",
  183. dev->name);
  184. err = -EOPNOTSUPP;
  185. }
  186. break;
  187. default:
  188. err = -EOPNOTSUPP;
  189. break;
  190. }
  191. if (err == -EINPROGRESS) {
  192. priv->iw_mode = *mode;
  193. set_port_type(priv);
  194. }
  195. orinoco_unlock(priv, &flags);
  196. return err;
  197. }
  198. static int orinoco_ioctl_getmode(struct net_device *dev,
  199. struct iw_request_info *info,
  200. u32 *mode,
  201. char *extra)
  202. {
  203. struct orinoco_private *priv = netdev_priv(dev);
  204. *mode = priv->iw_mode;
  205. return 0;
  206. }
  207. static int orinoco_ioctl_getiwrange(struct net_device *dev,
  208. struct iw_request_info *info,
  209. struct iw_point *rrq,
  210. char *extra)
  211. {
  212. struct orinoco_private *priv = netdev_priv(dev);
  213. int err = 0;
  214. struct iw_range *range = (struct iw_range *) extra;
  215. int numrates;
  216. int i, k;
  217. rrq->length = sizeof(struct iw_range);
  218. memset(range, 0, sizeof(struct iw_range));
  219. range->we_version_compiled = WIRELESS_EXT;
  220. range->we_version_source = 22;
  221. /* Set available channels/frequencies */
  222. range->num_channels = NUM_CHANNELS;
  223. k = 0;
  224. for (i = 0; i < NUM_CHANNELS; i++) {
  225. if (priv->channel_mask & (1 << i)) {
  226. range->freq[k].i = i + 1;
  227. range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
  228. 100000);
  229. range->freq[k].e = 1;
  230. k++;
  231. }
  232. if (k >= IW_MAX_FREQUENCIES)
  233. break;
  234. }
  235. range->num_frequency = k;
  236. range->sensitivity = 3;
  237. if (priv->has_wep) {
  238. range->max_encoding_tokens = ORINOCO_MAX_KEYS;
  239. range->encoding_size[0] = SMALL_KEY_SIZE;
  240. range->num_encoding_sizes = 1;
  241. if (priv->has_big_wep) {
  242. range->encoding_size[1] = LARGE_KEY_SIZE;
  243. range->num_encoding_sizes = 2;
  244. }
  245. }
  246. if (priv->has_wpa)
  247. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
  248. if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
  249. /* Quality stats meaningless in ad-hoc mode */
  250. } else {
  251. range->max_qual.qual = 0x8b - 0x2f;
  252. range->max_qual.level = 0x2f - 0x95 - 1;
  253. range->max_qual.noise = 0x2f - 0x95 - 1;
  254. /* Need to get better values */
  255. range->avg_qual.qual = 0x24;
  256. range->avg_qual.level = 0xC2;
  257. range->avg_qual.noise = 0x9E;
  258. }
  259. err = orinoco_hw_get_bitratelist(priv, &numrates,
  260. range->bitrate, IW_MAX_BITRATES);
  261. if (err)
  262. return err;
  263. range->num_bitrates = numrates;
  264. /* Set an indication of the max TCP throughput in bit/s that we can
  265. * expect using this interface. May be use for QoS stuff...
  266. * Jean II */
  267. if (numrates > 2)
  268. range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
  269. else
  270. range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
  271. range->min_rts = 0;
  272. range->max_rts = 2347;
  273. range->min_frag = 256;
  274. range->max_frag = 2346;
  275. range->min_pmp = 0;
  276. range->max_pmp = 65535000;
  277. range->min_pmt = 0;
  278. range->max_pmt = 65535 * 1000; /* ??? */
  279. range->pmp_flags = IW_POWER_PERIOD;
  280. range->pmt_flags = IW_POWER_TIMEOUT;
  281. range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
  282. IW_POWER_UNICAST_R);
  283. range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
  284. range->retry_flags = IW_RETRY_LIMIT;
  285. range->r_time_flags = IW_RETRY_LIFETIME;
  286. range->min_retry = 0;
  287. range->max_retry = 65535; /* ??? */
  288. range->min_r_time = 0;
  289. range->max_r_time = 65535 * 1000; /* ??? */
  290. if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
  291. range->scan_capa = IW_SCAN_CAPA_ESSID;
  292. else
  293. range->scan_capa = IW_SCAN_CAPA_NONE;
  294. /* Event capability (kernel) */
  295. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  296. /* Event capability (driver) */
  297. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  298. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  299. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  300. IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
  301. return 0;
  302. }
  303. static int orinoco_ioctl_setiwencode(struct net_device *dev,
  304. struct iw_request_info *info,
  305. struct iw_point *erq,
  306. char *keybuf)
  307. {
  308. struct orinoco_private *priv = netdev_priv(dev);
  309. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  310. int setindex = priv->tx_key;
  311. int encode_alg = priv->encode_alg;
  312. int restricted = priv->wep_restrict;
  313. u16 xlen = 0;
  314. int err = -EINPROGRESS; /* Call commit handler */
  315. unsigned long flags;
  316. if (!priv->has_wep)
  317. return -EOPNOTSUPP;
  318. if (erq->pointer) {
  319. /* We actually have a key to set - check its length */
  320. if (erq->length > LARGE_KEY_SIZE)
  321. return -E2BIG;
  322. if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
  323. return -E2BIG;
  324. }
  325. if (orinoco_lock(priv, &flags) != 0)
  326. return -EBUSY;
  327. /* Clear any TKIP key we have */
  328. if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
  329. (void) orinoco_clear_tkip_key(priv, setindex);
  330. if (erq->length > 0) {
  331. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  332. index = priv->tx_key;
  333. /* Adjust key length to a supported value */
  334. if (erq->length > SMALL_KEY_SIZE)
  335. xlen = LARGE_KEY_SIZE;
  336. else if (erq->length > 0)
  337. xlen = SMALL_KEY_SIZE;
  338. else
  339. xlen = 0;
  340. /* Switch on WEP if off */
  341. if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
  342. setindex = index;
  343. encode_alg = IW_ENCODE_ALG_WEP;
  344. }
  345. } else {
  346. /* Important note : if the user do "iwconfig eth0 enc off",
  347. * we will arrive there with an index of -1. This is valid
  348. * but need to be taken care off... Jean II */
  349. if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
  350. if ((index != -1) || (erq->flags == 0)) {
  351. err = -EINVAL;
  352. goto out;
  353. }
  354. } else {
  355. /* Set the index : Check that the key is valid */
  356. if (priv->keys[index].len == 0) {
  357. err = -EINVAL;
  358. goto out;
  359. }
  360. setindex = index;
  361. }
  362. }
  363. if (erq->flags & IW_ENCODE_DISABLED)
  364. encode_alg = IW_ENCODE_ALG_NONE;
  365. if (erq->flags & IW_ENCODE_OPEN)
  366. restricted = 0;
  367. if (erq->flags & IW_ENCODE_RESTRICTED)
  368. restricted = 1;
  369. if (erq->pointer && erq->length > 0) {
  370. priv->keys[index].len = cpu_to_le16(xlen);
  371. memset(priv->keys[index].data, 0,
  372. sizeof(priv->keys[index].data));
  373. memcpy(priv->keys[index].data, keybuf, erq->length);
  374. }
  375. priv->tx_key = setindex;
  376. /* Try fast key change if connected and only keys are changed */
  377. if ((priv->encode_alg == encode_alg) &&
  378. (priv->wep_restrict == restricted) &&
  379. netif_carrier_ok(dev)) {
  380. err = __orinoco_hw_setup_wepkeys(priv);
  381. /* No need to commit if successful */
  382. goto out;
  383. }
  384. priv->encode_alg = encode_alg;
  385. priv->wep_restrict = restricted;
  386. out:
  387. orinoco_unlock(priv, &flags);
  388. return err;
  389. }
  390. static int orinoco_ioctl_getiwencode(struct net_device *dev,
  391. struct iw_request_info *info,
  392. struct iw_point *erq,
  393. char *keybuf)
  394. {
  395. struct orinoco_private *priv = netdev_priv(dev);
  396. int index = (erq->flags & IW_ENCODE_INDEX) - 1;
  397. u16 xlen = 0;
  398. unsigned long flags;
  399. if (!priv->has_wep)
  400. return -EOPNOTSUPP;
  401. if (orinoco_lock(priv, &flags) != 0)
  402. return -EBUSY;
  403. if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
  404. index = priv->tx_key;
  405. erq->flags = 0;
  406. if (!priv->encode_alg)
  407. erq->flags |= IW_ENCODE_DISABLED;
  408. erq->flags |= index + 1;
  409. if (priv->wep_restrict)
  410. erq->flags |= IW_ENCODE_RESTRICTED;
  411. else
  412. erq->flags |= IW_ENCODE_OPEN;
  413. xlen = le16_to_cpu(priv->keys[index].len);
  414. erq->length = xlen;
  415. memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
  416. orinoco_unlock(priv, &flags);
  417. return 0;
  418. }
  419. static int orinoco_ioctl_setessid(struct net_device *dev,
  420. struct iw_request_info *info,
  421. struct iw_point *erq,
  422. char *essidbuf)
  423. {
  424. struct orinoco_private *priv = netdev_priv(dev);
  425. unsigned long flags;
  426. /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
  427. * anyway... - Jean II */
  428. /* Hum... Should not use Wireless Extension constant (may change),
  429. * should use our own... - Jean II */
  430. if (erq->length > IW_ESSID_MAX_SIZE)
  431. return -E2BIG;
  432. if (orinoco_lock(priv, &flags) != 0)
  433. return -EBUSY;
  434. /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
  435. memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
  436. /* If not ANY, get the new ESSID */
  437. if (erq->flags)
  438. memcpy(priv->desired_essid, essidbuf, erq->length);
  439. orinoco_unlock(priv, &flags);
  440. return -EINPROGRESS; /* Call commit handler */
  441. }
  442. static int orinoco_ioctl_getessid(struct net_device *dev,
  443. struct iw_request_info *info,
  444. struct iw_point *erq,
  445. char *essidbuf)
  446. {
  447. struct orinoco_private *priv = netdev_priv(dev);
  448. int active;
  449. int err = 0;
  450. unsigned long flags;
  451. if (netif_running(dev)) {
  452. err = orinoco_hw_get_essid(priv, &active, essidbuf);
  453. if (err < 0)
  454. return err;
  455. erq->length = err;
  456. } else {
  457. if (orinoco_lock(priv, &flags) != 0)
  458. return -EBUSY;
  459. memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
  460. erq->length = strlen(priv->desired_essid);
  461. orinoco_unlock(priv, &flags);
  462. }
  463. erq->flags = 1;
  464. return 0;
  465. }
  466. static int orinoco_ioctl_setnick(struct net_device *dev,
  467. struct iw_request_info *info,
  468. struct iw_point *nrq,
  469. char *nickbuf)
  470. {
  471. struct orinoco_private *priv = netdev_priv(dev);
  472. unsigned long flags;
  473. if (nrq->length > IW_ESSID_MAX_SIZE)
  474. return -E2BIG;
  475. if (orinoco_lock(priv, &flags) != 0)
  476. return -EBUSY;
  477. memset(priv->nick, 0, sizeof(priv->nick));
  478. memcpy(priv->nick, nickbuf, nrq->length);
  479. orinoco_unlock(priv, &flags);
  480. return -EINPROGRESS; /* Call commit handler */
  481. }
  482. static int orinoco_ioctl_getnick(struct net_device *dev,
  483. struct iw_request_info *info,
  484. struct iw_point *nrq,
  485. char *nickbuf)
  486. {
  487. struct orinoco_private *priv = netdev_priv(dev);
  488. unsigned long flags;
  489. if (orinoco_lock(priv, &flags) != 0)
  490. return -EBUSY;
  491. memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
  492. orinoco_unlock(priv, &flags);
  493. nrq->length = strlen(priv->nick);
  494. return 0;
  495. }
  496. static int orinoco_ioctl_setfreq(struct net_device *dev,
  497. struct iw_request_info *info,
  498. struct iw_freq *frq,
  499. char *extra)
  500. {
  501. struct orinoco_private *priv = netdev_priv(dev);
  502. int chan = -1;
  503. unsigned long flags;
  504. int err = -EINPROGRESS; /* Call commit handler */
  505. /* In infrastructure mode the AP sets the channel */
  506. if (priv->iw_mode == IW_MODE_INFRA)
  507. return -EBUSY;
  508. if ((frq->e == 0) && (frq->m <= 1000)) {
  509. /* Setting by channel number */
  510. chan = frq->m;
  511. } else {
  512. /* Setting by frequency */
  513. int denom = 1;
  514. int i;
  515. /* Calculate denominator to rescale to MHz */
  516. for (i = 0; i < (6 - frq->e); i++)
  517. denom *= 10;
  518. chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
  519. }
  520. if ((chan < 1) || (chan > NUM_CHANNELS) ||
  521. !(priv->channel_mask & (1 << (chan-1))))
  522. return -EINVAL;
  523. if (orinoco_lock(priv, &flags) != 0)
  524. return -EBUSY;
  525. priv->channel = chan;
  526. if (priv->iw_mode == IW_MODE_MONITOR) {
  527. /* Fast channel change - no commit if successful */
  528. hermes_t *hw = &priv->hw;
  529. err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
  530. HERMES_TEST_SET_CHANNEL,
  531. chan, NULL);
  532. }
  533. orinoco_unlock(priv, &flags);
  534. return err;
  535. }
  536. static int orinoco_ioctl_getfreq(struct net_device *dev,
  537. struct iw_request_info *info,
  538. struct iw_freq *frq,
  539. char *extra)
  540. {
  541. struct orinoco_private *priv = netdev_priv(dev);
  542. int tmp;
  543. /* Locking done in there */
  544. tmp = orinoco_hw_get_freq(priv);
  545. if (tmp < 0)
  546. return tmp;
  547. frq->m = tmp * 100000;
  548. frq->e = 1;
  549. return 0;
  550. }
  551. static int orinoco_ioctl_getsens(struct net_device *dev,
  552. struct iw_request_info *info,
  553. struct iw_param *srq,
  554. char *extra)
  555. {
  556. struct orinoco_private *priv = netdev_priv(dev);
  557. hermes_t *hw = &priv->hw;
  558. u16 val;
  559. int err;
  560. unsigned long flags;
  561. if (!priv->has_sensitivity)
  562. return -EOPNOTSUPP;
  563. if (orinoco_lock(priv, &flags) != 0)
  564. return -EBUSY;
  565. err = hermes_read_wordrec(hw, USER_BAP,
  566. HERMES_RID_CNFSYSTEMSCALE, &val);
  567. orinoco_unlock(priv, &flags);
  568. if (err)
  569. return err;
  570. srq->value = val;
  571. srq->fixed = 0; /* auto */
  572. return 0;
  573. }
  574. static int orinoco_ioctl_setsens(struct net_device *dev,
  575. struct iw_request_info *info,
  576. struct iw_param *srq,
  577. char *extra)
  578. {
  579. struct orinoco_private *priv = netdev_priv(dev);
  580. int val = srq->value;
  581. unsigned long flags;
  582. if (!priv->has_sensitivity)
  583. return -EOPNOTSUPP;
  584. if ((val < 1) || (val > 3))
  585. return -EINVAL;
  586. if (orinoco_lock(priv, &flags) != 0)
  587. return -EBUSY;
  588. priv->ap_density = val;
  589. orinoco_unlock(priv, &flags);
  590. return -EINPROGRESS; /* Call commit handler */
  591. }
  592. static int orinoco_ioctl_setrts(struct net_device *dev,
  593. struct iw_request_info *info,
  594. struct iw_param *rrq,
  595. char *extra)
  596. {
  597. struct orinoco_private *priv = netdev_priv(dev);
  598. int val = rrq->value;
  599. unsigned long flags;
  600. if (rrq->disabled)
  601. val = 2347;
  602. if ((val < 0) || (val > 2347))
  603. return -EINVAL;
  604. if (orinoco_lock(priv, &flags) != 0)
  605. return -EBUSY;
  606. priv->rts_thresh = val;
  607. orinoco_unlock(priv, &flags);
  608. return -EINPROGRESS; /* Call commit handler */
  609. }
  610. static int orinoco_ioctl_getrts(struct net_device *dev,
  611. struct iw_request_info *info,
  612. struct iw_param *rrq,
  613. char *extra)
  614. {
  615. struct orinoco_private *priv = netdev_priv(dev);
  616. rrq->value = priv->rts_thresh;
  617. rrq->disabled = (rrq->value == 2347);
  618. rrq->fixed = 1;
  619. return 0;
  620. }
  621. static int orinoco_ioctl_setfrag(struct net_device *dev,
  622. struct iw_request_info *info,
  623. struct iw_param *frq,
  624. char *extra)
  625. {
  626. struct orinoco_private *priv = netdev_priv(dev);
  627. int err = -EINPROGRESS; /* Call commit handler */
  628. unsigned long flags;
  629. if (orinoco_lock(priv, &flags) != 0)
  630. return -EBUSY;
  631. if (priv->has_mwo) {
  632. if (frq->disabled)
  633. priv->mwo_robust = 0;
  634. else {
  635. if (frq->fixed)
  636. printk(KERN_WARNING "%s: Fixed fragmentation "
  637. "is not supported on this firmware. "
  638. "Using MWO robust instead.\n",
  639. dev->name);
  640. priv->mwo_robust = 1;
  641. }
  642. } else {
  643. if (frq->disabled)
  644. priv->frag_thresh = 2346;
  645. else {
  646. if ((frq->value < 256) || (frq->value > 2346))
  647. err = -EINVAL;
  648. else
  649. /* must be even */
  650. priv->frag_thresh = frq->value & ~0x1;
  651. }
  652. }
  653. orinoco_unlock(priv, &flags);
  654. return err;
  655. }
  656. static int orinoco_ioctl_getfrag(struct net_device *dev,
  657. struct iw_request_info *info,
  658. struct iw_param *frq,
  659. char *extra)
  660. {
  661. struct orinoco_private *priv = netdev_priv(dev);
  662. hermes_t *hw = &priv->hw;
  663. int err;
  664. u16 val;
  665. unsigned long flags;
  666. if (orinoco_lock(priv, &flags) != 0)
  667. return -EBUSY;
  668. if (priv->has_mwo) {
  669. err = hermes_read_wordrec(hw, USER_BAP,
  670. HERMES_RID_CNFMWOROBUST_AGERE,
  671. &val);
  672. if (err)
  673. val = 0;
  674. frq->value = val ? 2347 : 0;
  675. frq->disabled = !val;
  676. frq->fixed = 0;
  677. } else {
  678. err = hermes_read_wordrec(hw, USER_BAP,
  679. HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
  680. &val);
  681. if (err)
  682. val = 0;
  683. frq->value = val;
  684. frq->disabled = (val >= 2346);
  685. frq->fixed = 1;
  686. }
  687. orinoco_unlock(priv, &flags);
  688. return err;
  689. }
  690. static int orinoco_ioctl_setrate(struct net_device *dev,
  691. struct iw_request_info *info,
  692. struct iw_param *rrq,
  693. char *extra)
  694. {
  695. struct orinoco_private *priv = netdev_priv(dev);
  696. int ratemode;
  697. int bitrate; /* 100s of kilobits */
  698. unsigned long flags;
  699. /* As the user space doesn't know our highest rate, it uses -1
  700. * to ask us to set the highest rate. Test it using "iwconfig
  701. * ethX rate auto" - Jean II */
  702. if (rrq->value == -1)
  703. bitrate = 110;
  704. else {
  705. if (rrq->value % 100000)
  706. return -EINVAL;
  707. bitrate = rrq->value / 100000;
  708. }
  709. ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
  710. if (ratemode == -1)
  711. return -EINVAL;
  712. if (orinoco_lock(priv, &flags) != 0)
  713. return -EBUSY;
  714. priv->bitratemode = ratemode;
  715. orinoco_unlock(priv, &flags);
  716. return -EINPROGRESS;
  717. }
  718. static int orinoco_ioctl_getrate(struct net_device *dev,
  719. struct iw_request_info *info,
  720. struct iw_param *rrq,
  721. char *extra)
  722. {
  723. struct orinoco_private *priv = netdev_priv(dev);
  724. int err = 0;
  725. int bitrate, automatic;
  726. unsigned long flags;
  727. if (orinoco_lock(priv, &flags) != 0)
  728. return -EBUSY;
  729. orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
  730. /* If the interface is running we try to find more about the
  731. current mode */
  732. if (netif_running(dev))
  733. err = orinoco_hw_get_act_bitrate(priv, &bitrate);
  734. orinoco_unlock(priv, &flags);
  735. rrq->value = bitrate;
  736. rrq->fixed = !automatic;
  737. rrq->disabled = 0;
  738. return err;
  739. }
  740. static int orinoco_ioctl_setpower(struct net_device *dev,
  741. struct iw_request_info *info,
  742. struct iw_param *prq,
  743. char *extra)
  744. {
  745. struct orinoco_private *priv = netdev_priv(dev);
  746. int err = -EINPROGRESS; /* Call commit handler */
  747. unsigned long flags;
  748. if (orinoco_lock(priv, &flags) != 0)
  749. return -EBUSY;
  750. if (prq->disabled) {
  751. priv->pm_on = 0;
  752. } else {
  753. switch (prq->flags & IW_POWER_MODE) {
  754. case IW_POWER_UNICAST_R:
  755. priv->pm_mcast = 0;
  756. priv->pm_on = 1;
  757. break;
  758. case IW_POWER_ALL_R:
  759. priv->pm_mcast = 1;
  760. priv->pm_on = 1;
  761. break;
  762. case IW_POWER_ON:
  763. /* No flags : but we may have a value - Jean II */
  764. break;
  765. default:
  766. err = -EINVAL;
  767. goto out;
  768. }
  769. if (prq->flags & IW_POWER_TIMEOUT) {
  770. priv->pm_on = 1;
  771. priv->pm_timeout = prq->value / 1000;
  772. }
  773. if (prq->flags & IW_POWER_PERIOD) {
  774. priv->pm_on = 1;
  775. priv->pm_period = prq->value / 1000;
  776. }
  777. /* It's valid to not have a value if we are just toggling
  778. * the flags... Jean II */
  779. if (!priv->pm_on) {
  780. err = -EINVAL;
  781. goto out;
  782. }
  783. }
  784. out:
  785. orinoco_unlock(priv, &flags);
  786. return err;
  787. }
  788. static int orinoco_ioctl_getpower(struct net_device *dev,
  789. struct iw_request_info *info,
  790. struct iw_param *prq,
  791. char *extra)
  792. {
  793. struct orinoco_private *priv = netdev_priv(dev);
  794. hermes_t *hw = &priv->hw;
  795. int err = 0;
  796. u16 enable, period, timeout, mcast;
  797. unsigned long flags;
  798. if (orinoco_lock(priv, &flags) != 0)
  799. return -EBUSY;
  800. err = hermes_read_wordrec(hw, USER_BAP,
  801. HERMES_RID_CNFPMENABLED, &enable);
  802. if (err)
  803. goto out;
  804. err = hermes_read_wordrec(hw, USER_BAP,
  805. HERMES_RID_CNFMAXSLEEPDURATION, &period);
  806. if (err)
  807. goto out;
  808. err = hermes_read_wordrec(hw, USER_BAP,
  809. HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
  810. if (err)
  811. goto out;
  812. err = hermes_read_wordrec(hw, USER_BAP,
  813. HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
  814. if (err)
  815. goto out;
  816. prq->disabled = !enable;
  817. /* Note : by default, display the period */
  818. if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
  819. prq->flags = IW_POWER_TIMEOUT;
  820. prq->value = timeout * 1000;
  821. } else {
  822. prq->flags = IW_POWER_PERIOD;
  823. prq->value = period * 1000;
  824. }
  825. if (mcast)
  826. prq->flags |= IW_POWER_ALL_R;
  827. else
  828. prq->flags |= IW_POWER_UNICAST_R;
  829. out:
  830. orinoco_unlock(priv, &flags);
  831. return err;
  832. }
  833. static int orinoco_ioctl_set_encodeext(struct net_device *dev,
  834. struct iw_request_info *info,
  835. union iwreq_data *wrqu,
  836. char *extra)
  837. {
  838. struct orinoco_private *priv = netdev_priv(dev);
  839. struct iw_point *encoding = &wrqu->encoding;
  840. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  841. int idx, alg = ext->alg, set_key = 1;
  842. unsigned long flags;
  843. int err = -EINVAL;
  844. u16 key_len;
  845. if (orinoco_lock(priv, &flags) != 0)
  846. return -EBUSY;
  847. /* Determine and validate the key index */
  848. idx = encoding->flags & IW_ENCODE_INDEX;
  849. if (idx) {
  850. if ((idx < 1) || (idx > 4))
  851. goto out;
  852. idx--;
  853. } else
  854. idx = priv->tx_key;
  855. if (encoding->flags & IW_ENCODE_DISABLED)
  856. alg = IW_ENCODE_ALG_NONE;
  857. if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
  858. /* Clear any TKIP TX key we had */
  859. (void) orinoco_clear_tkip_key(priv, priv->tx_key);
  860. }
  861. if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
  862. priv->tx_key = idx;
  863. set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
  864. (ext->key_len > 0)) ? 1 : 0;
  865. }
  866. if (set_key) {
  867. /* Set the requested key first */
  868. switch (alg) {
  869. case IW_ENCODE_ALG_NONE:
  870. priv->encode_alg = alg;
  871. priv->keys[idx].len = 0;
  872. break;
  873. case IW_ENCODE_ALG_WEP:
  874. if (ext->key_len > SMALL_KEY_SIZE)
  875. key_len = LARGE_KEY_SIZE;
  876. else if (ext->key_len > 0)
  877. key_len = SMALL_KEY_SIZE;
  878. else
  879. goto out;
  880. priv->encode_alg = alg;
  881. priv->keys[idx].len = cpu_to_le16(key_len);
  882. key_len = min(ext->key_len, key_len);
  883. memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
  884. memcpy(priv->keys[idx].data, ext->key, key_len);
  885. break;
  886. case IW_ENCODE_ALG_TKIP:
  887. {
  888. hermes_t *hw = &priv->hw;
  889. u8 *tkip_iv = NULL;
  890. if (!priv->has_wpa ||
  891. (ext->key_len > sizeof(priv->tkip_key[0])))
  892. goto out;
  893. priv->encode_alg = alg;
  894. memset(&priv->tkip_key[idx], 0,
  895. sizeof(priv->tkip_key[idx]));
  896. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  897. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  898. tkip_iv = &ext->rx_seq[0];
  899. err = __orinoco_hw_set_tkip_key(hw, idx,
  900. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  901. (u8 *) &priv->tkip_key[idx],
  902. tkip_iv, NULL);
  903. if (err)
  904. printk(KERN_ERR "%s: Error %d setting TKIP key"
  905. "\n", dev->name, err);
  906. goto out;
  907. }
  908. default:
  909. goto out;
  910. }
  911. }
  912. err = -EINPROGRESS;
  913. out:
  914. orinoco_unlock(priv, &flags);
  915. return err;
  916. }
  917. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  918. struct iw_request_info *info,
  919. union iwreq_data *wrqu,
  920. char *extra)
  921. {
  922. struct orinoco_private *priv = netdev_priv(dev);
  923. struct iw_point *encoding = &wrqu->encoding;
  924. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  925. int idx, max_key_len;
  926. unsigned long flags;
  927. int err;
  928. if (orinoco_lock(priv, &flags) != 0)
  929. return -EBUSY;
  930. err = -EINVAL;
  931. max_key_len = encoding->length - sizeof(*ext);
  932. if (max_key_len < 0)
  933. goto out;
  934. idx = encoding->flags & IW_ENCODE_INDEX;
  935. if (idx) {
  936. if ((idx < 1) || (idx > 4))
  937. goto out;
  938. idx--;
  939. } else
  940. idx = priv->tx_key;
  941. encoding->flags = idx + 1;
  942. memset(ext, 0, sizeof(*ext));
  943. ext->alg = priv->encode_alg;
  944. switch (priv->encode_alg) {
  945. case IW_ENCODE_ALG_NONE:
  946. ext->key_len = 0;
  947. encoding->flags |= IW_ENCODE_DISABLED;
  948. break;
  949. case IW_ENCODE_ALG_WEP:
  950. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  951. max_key_len);
  952. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  953. encoding->flags |= IW_ENCODE_ENABLED;
  954. break;
  955. case IW_ENCODE_ALG_TKIP:
  956. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  957. max_key_len);
  958. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  959. encoding->flags |= IW_ENCODE_ENABLED;
  960. break;
  961. }
  962. err = 0;
  963. out:
  964. orinoco_unlock(priv, &flags);
  965. return err;
  966. }
  967. static int orinoco_ioctl_set_auth(struct net_device *dev,
  968. struct iw_request_info *info,
  969. union iwreq_data *wrqu, char *extra)
  970. {
  971. struct orinoco_private *priv = netdev_priv(dev);
  972. hermes_t *hw = &priv->hw;
  973. struct iw_param *param = &wrqu->param;
  974. unsigned long flags;
  975. int ret = -EINPROGRESS;
  976. if (orinoco_lock(priv, &flags) != 0)
  977. return -EBUSY;
  978. switch (param->flags & IW_AUTH_INDEX) {
  979. case IW_AUTH_WPA_VERSION:
  980. case IW_AUTH_CIPHER_PAIRWISE:
  981. case IW_AUTH_CIPHER_GROUP:
  982. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  983. case IW_AUTH_PRIVACY_INVOKED:
  984. case IW_AUTH_DROP_UNENCRYPTED:
  985. /*
  986. * orinoco does not use these parameters
  987. */
  988. break;
  989. case IW_AUTH_KEY_MGMT:
  990. /* wl_lkm implies value 2 == PSK for Hermes I
  991. * which ties in with WEXT
  992. * no other hints tho :(
  993. */
  994. priv->key_mgmt = param->value;
  995. break;
  996. case IW_AUTH_TKIP_COUNTERMEASURES:
  997. /* When countermeasures are enabled, shut down the
  998. * card; when disabled, re-enable the card. This must
  999. * take effect immediately.
  1000. *
  1001. * TODO: Make sure that the EAPOL message is getting
  1002. * out before card disabled
  1003. */
  1004. if (param->value) {
  1005. priv->tkip_cm_active = 1;
  1006. ret = hermes_enable_port(hw, 0);
  1007. } else {
  1008. priv->tkip_cm_active = 0;
  1009. ret = hermes_disable_port(hw, 0);
  1010. }
  1011. break;
  1012. case IW_AUTH_80211_AUTH_ALG:
  1013. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  1014. priv->wep_restrict = 1;
  1015. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  1016. priv->wep_restrict = 0;
  1017. else
  1018. ret = -EINVAL;
  1019. break;
  1020. case IW_AUTH_WPA_ENABLED:
  1021. if (priv->has_wpa) {
  1022. priv->wpa_enabled = param->value ? 1 : 0;
  1023. } else {
  1024. if (param->value)
  1025. ret = -EOPNOTSUPP;
  1026. /* else silently accept disable of WPA */
  1027. priv->wpa_enabled = 0;
  1028. }
  1029. break;
  1030. default:
  1031. ret = -EOPNOTSUPP;
  1032. }
  1033. orinoco_unlock(priv, &flags);
  1034. return ret;
  1035. }
  1036. static int orinoco_ioctl_get_auth(struct net_device *dev,
  1037. struct iw_request_info *info,
  1038. union iwreq_data *wrqu, char *extra)
  1039. {
  1040. struct orinoco_private *priv = netdev_priv(dev);
  1041. struct iw_param *param = &wrqu->param;
  1042. unsigned long flags;
  1043. int ret = 0;
  1044. if (orinoco_lock(priv, &flags) != 0)
  1045. return -EBUSY;
  1046. switch (param->flags & IW_AUTH_INDEX) {
  1047. case IW_AUTH_KEY_MGMT:
  1048. param->value = priv->key_mgmt;
  1049. break;
  1050. case IW_AUTH_TKIP_COUNTERMEASURES:
  1051. param->value = priv->tkip_cm_active;
  1052. break;
  1053. case IW_AUTH_80211_AUTH_ALG:
  1054. if (priv->wep_restrict)
  1055. param->value = IW_AUTH_ALG_SHARED_KEY;
  1056. else
  1057. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  1058. break;
  1059. case IW_AUTH_WPA_ENABLED:
  1060. param->value = priv->wpa_enabled;
  1061. break;
  1062. default:
  1063. ret = -EOPNOTSUPP;
  1064. }
  1065. orinoco_unlock(priv, &flags);
  1066. return ret;
  1067. }
  1068. static int orinoco_ioctl_set_genie(struct net_device *dev,
  1069. struct iw_request_info *info,
  1070. union iwreq_data *wrqu, char *extra)
  1071. {
  1072. struct orinoco_private *priv = netdev_priv(dev);
  1073. u8 *buf;
  1074. unsigned long flags;
  1075. /* cut off at IEEE80211_MAX_DATA_LEN */
  1076. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  1077. (wrqu->data.length && (extra == NULL)))
  1078. return -EINVAL;
  1079. if (wrqu->data.length) {
  1080. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  1081. if (buf == NULL)
  1082. return -ENOMEM;
  1083. memcpy(buf, extra, wrqu->data.length);
  1084. } else
  1085. buf = NULL;
  1086. if (orinoco_lock(priv, &flags) != 0) {
  1087. kfree(buf);
  1088. return -EBUSY;
  1089. }
  1090. kfree(priv->wpa_ie);
  1091. priv->wpa_ie = buf;
  1092. priv->wpa_ie_len = wrqu->data.length;
  1093. if (priv->wpa_ie) {
  1094. /* Looks like wl_lkm wants to check the auth alg, and
  1095. * somehow pass it to the firmware.
  1096. * Instead it just calls the key mgmt rid
  1097. * - we do this in set auth.
  1098. */
  1099. }
  1100. orinoco_unlock(priv, &flags);
  1101. return 0;
  1102. }
  1103. static int orinoco_ioctl_get_genie(struct net_device *dev,
  1104. struct iw_request_info *info,
  1105. union iwreq_data *wrqu, char *extra)
  1106. {
  1107. struct orinoco_private *priv = netdev_priv(dev);
  1108. unsigned long flags;
  1109. int err = 0;
  1110. if (orinoco_lock(priv, &flags) != 0)
  1111. return -EBUSY;
  1112. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  1113. wrqu->data.length = 0;
  1114. goto out;
  1115. }
  1116. if (wrqu->data.length < priv->wpa_ie_len) {
  1117. err = -E2BIG;
  1118. goto out;
  1119. }
  1120. wrqu->data.length = priv->wpa_ie_len;
  1121. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  1122. out:
  1123. orinoco_unlock(priv, &flags);
  1124. return err;
  1125. }
  1126. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  1127. struct iw_request_info *info,
  1128. union iwreq_data *wrqu, char *extra)
  1129. {
  1130. struct orinoco_private *priv = netdev_priv(dev);
  1131. hermes_t *hw = &priv->hw;
  1132. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1133. unsigned long flags;
  1134. int ret = 0;
  1135. if (orinoco_lock(priv, &flags) != 0)
  1136. return -EBUSY;
  1137. switch (mlme->cmd) {
  1138. case IW_MLME_DEAUTH:
  1139. /* silently ignore */
  1140. break;
  1141. case IW_MLME_DISASSOC:
  1142. {
  1143. struct {
  1144. u8 addr[ETH_ALEN];
  1145. __le16 reason_code;
  1146. } __attribute__ ((packed)) buf;
  1147. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  1148. buf.reason_code = cpu_to_le16(mlme->reason_code);
  1149. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  1150. HERMES_RID_CNFDISASSOCIATE,
  1151. &buf);
  1152. break;
  1153. }
  1154. default:
  1155. ret = -EOPNOTSUPP;
  1156. }
  1157. orinoco_unlock(priv, &flags);
  1158. return ret;
  1159. }
  1160. static int orinoco_ioctl_getretry(struct net_device *dev,
  1161. struct iw_request_info *info,
  1162. struct iw_param *rrq,
  1163. char *extra)
  1164. {
  1165. struct orinoco_private *priv = netdev_priv(dev);
  1166. hermes_t *hw = &priv->hw;
  1167. int err = 0;
  1168. u16 short_limit, long_limit, lifetime;
  1169. unsigned long flags;
  1170. if (orinoco_lock(priv, &flags) != 0)
  1171. return -EBUSY;
  1172. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  1173. &short_limit);
  1174. if (err)
  1175. goto out;
  1176. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  1177. &long_limit);
  1178. if (err)
  1179. goto out;
  1180. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  1181. &lifetime);
  1182. if (err)
  1183. goto out;
  1184. rrq->disabled = 0; /* Can't be disabled */
  1185. /* Note : by default, display the retry number */
  1186. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  1187. rrq->flags = IW_RETRY_LIFETIME;
  1188. rrq->value = lifetime * 1000; /* ??? */
  1189. } else {
  1190. /* By default, display the min number */
  1191. if ((rrq->flags & IW_RETRY_LONG)) {
  1192. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  1193. rrq->value = long_limit;
  1194. } else {
  1195. rrq->flags = IW_RETRY_LIMIT;
  1196. rrq->value = short_limit;
  1197. if (short_limit != long_limit)
  1198. rrq->flags |= IW_RETRY_SHORT;
  1199. }
  1200. }
  1201. out:
  1202. orinoco_unlock(priv, &flags);
  1203. return err;
  1204. }
  1205. static int orinoco_ioctl_reset(struct net_device *dev,
  1206. struct iw_request_info *info,
  1207. void *wrqu,
  1208. char *extra)
  1209. {
  1210. struct orinoco_private *priv = netdev_priv(dev);
  1211. if (!capable(CAP_NET_ADMIN))
  1212. return -EPERM;
  1213. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  1214. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  1215. /* Firmware reset */
  1216. orinoco_reset(&priv->reset_work);
  1217. } else {
  1218. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  1219. schedule_work(&priv->reset_work);
  1220. }
  1221. return 0;
  1222. }
  1223. static int orinoco_ioctl_setibssport(struct net_device *dev,
  1224. struct iw_request_info *info,
  1225. void *wrqu,
  1226. char *extra)
  1227. {
  1228. struct orinoco_private *priv = netdev_priv(dev);
  1229. int val = *((int *) extra);
  1230. unsigned long flags;
  1231. if (orinoco_lock(priv, &flags) != 0)
  1232. return -EBUSY;
  1233. priv->ibss_port = val ;
  1234. /* Actually update the mode we are using */
  1235. set_port_type(priv);
  1236. orinoco_unlock(priv, &flags);
  1237. return -EINPROGRESS; /* Call commit handler */
  1238. }
  1239. static int orinoco_ioctl_getibssport(struct net_device *dev,
  1240. struct iw_request_info *info,
  1241. void *wrqu,
  1242. char *extra)
  1243. {
  1244. struct orinoco_private *priv = netdev_priv(dev);
  1245. int *val = (int *) extra;
  1246. *val = priv->ibss_port;
  1247. return 0;
  1248. }
  1249. static int orinoco_ioctl_setport3(struct net_device *dev,
  1250. struct iw_request_info *info,
  1251. void *wrqu,
  1252. char *extra)
  1253. {
  1254. struct orinoco_private *priv = netdev_priv(dev);
  1255. int val = *((int *) extra);
  1256. int err = 0;
  1257. unsigned long flags;
  1258. if (orinoco_lock(priv, &flags) != 0)
  1259. return -EBUSY;
  1260. switch (val) {
  1261. case 0: /* Try to do IEEE ad-hoc mode */
  1262. if (!priv->has_ibss) {
  1263. err = -EINVAL;
  1264. break;
  1265. }
  1266. priv->prefer_port3 = 0;
  1267. break;
  1268. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  1269. if (!priv->has_port3) {
  1270. err = -EINVAL;
  1271. break;
  1272. }
  1273. priv->prefer_port3 = 1;
  1274. break;
  1275. default:
  1276. err = -EINVAL;
  1277. }
  1278. if (!err) {
  1279. /* Actually update the mode we are using */
  1280. set_port_type(priv);
  1281. err = -EINPROGRESS;
  1282. }
  1283. orinoco_unlock(priv, &flags);
  1284. return err;
  1285. }
  1286. static int orinoco_ioctl_getport3(struct net_device *dev,
  1287. struct iw_request_info *info,
  1288. void *wrqu,
  1289. char *extra)
  1290. {
  1291. struct orinoco_private *priv = netdev_priv(dev);
  1292. int *val = (int *) extra;
  1293. *val = priv->prefer_port3;
  1294. return 0;
  1295. }
  1296. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  1297. struct iw_request_info *info,
  1298. void *wrqu,
  1299. char *extra)
  1300. {
  1301. struct orinoco_private *priv = netdev_priv(dev);
  1302. unsigned long flags;
  1303. int val;
  1304. if (!priv->has_preamble)
  1305. return -EOPNOTSUPP;
  1306. /* 802.11b has recently defined some short preamble.
  1307. * Basically, the Phy header has been reduced in size.
  1308. * This increase performance, especially at high rates
  1309. * (the preamble is transmitted at 1Mb/s), unfortunately
  1310. * this give compatibility troubles... - Jean II */
  1311. val = *((int *) extra);
  1312. if (orinoco_lock(priv, &flags) != 0)
  1313. return -EBUSY;
  1314. if (val)
  1315. priv->preamble = 1;
  1316. else
  1317. priv->preamble = 0;
  1318. orinoco_unlock(priv, &flags);
  1319. return -EINPROGRESS; /* Call commit handler */
  1320. }
  1321. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  1322. struct iw_request_info *info,
  1323. void *wrqu,
  1324. char *extra)
  1325. {
  1326. struct orinoco_private *priv = netdev_priv(dev);
  1327. int *val = (int *) extra;
  1328. if (!priv->has_preamble)
  1329. return -EOPNOTSUPP;
  1330. *val = priv->preamble;
  1331. return 0;
  1332. }
  1333. /* ioctl interface to hermes_read_ltv()
  1334. * To use with iwpriv, pass the RID as the token argument, e.g.
  1335. * iwpriv get_rid [0xfc00]
  1336. * At least Wireless Tools 25 is required to use iwpriv.
  1337. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  1338. static int orinoco_ioctl_getrid(struct net_device *dev,
  1339. struct iw_request_info *info,
  1340. struct iw_point *data,
  1341. char *extra)
  1342. {
  1343. struct orinoco_private *priv = netdev_priv(dev);
  1344. hermes_t *hw = &priv->hw;
  1345. int rid = data->flags;
  1346. u16 length;
  1347. int err;
  1348. unsigned long flags;
  1349. /* It's a "get" function, but we don't want users to access the
  1350. * WEP key and other raw firmware data */
  1351. if (!capable(CAP_NET_ADMIN))
  1352. return -EPERM;
  1353. if (rid < 0xfc00 || rid > 0xffff)
  1354. return -EINVAL;
  1355. if (orinoco_lock(priv, &flags) != 0)
  1356. return -EBUSY;
  1357. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  1358. extra);
  1359. if (err)
  1360. goto out;
  1361. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  1362. MAX_RID_LEN);
  1363. out:
  1364. orinoco_unlock(priv, &flags);
  1365. return err;
  1366. }
  1367. /* Trigger a scan (look for other cells in the vicinity) */
  1368. static int orinoco_ioctl_setscan(struct net_device *dev,
  1369. struct iw_request_info *info,
  1370. struct iw_point *srq,
  1371. char *extra)
  1372. {
  1373. struct orinoco_private *priv = netdev_priv(dev);
  1374. hermes_t *hw = &priv->hw;
  1375. struct iw_scan_req *si = (struct iw_scan_req *) extra;
  1376. int err = 0;
  1377. unsigned long flags;
  1378. /* Note : you may have realised that, as this is a SET operation,
  1379. * this is privileged and therefore a normal user can't
  1380. * perform scanning.
  1381. * This is not an error, while the device perform scanning,
  1382. * traffic doesn't flow, so it's a perfect DoS...
  1383. * Jean II */
  1384. if (orinoco_lock(priv, &flags) != 0)
  1385. return -EBUSY;
  1386. /* Scanning with port 0 disabled would fail */
  1387. if (!netif_running(dev)) {
  1388. err = -ENETDOWN;
  1389. goto out;
  1390. }
  1391. /* In monitor mode, the scan results are always empty.
  1392. * Probe responses are passed to the driver as received
  1393. * frames and could be processed in software. */
  1394. if (priv->iw_mode == IW_MODE_MONITOR) {
  1395. err = -EOPNOTSUPP;
  1396. goto out;
  1397. }
  1398. /* Note : because we don't lock out the irq handler, the way
  1399. * we access scan variables in priv is critical.
  1400. * o scan_inprogress : not touched by irq handler
  1401. * o scan_mode : not touched by irq handler
  1402. * Before modifying anything on those variables, please think hard !
  1403. * Jean II */
  1404. /* Save flags */
  1405. priv->scan_mode = srq->flags;
  1406. /* Always trigger scanning, even if it's in progress.
  1407. * This way, if the info frame get lost, we will recover somewhat
  1408. * gracefully - Jean II */
  1409. if (priv->has_hostscan) {
  1410. switch (priv->firmware_type) {
  1411. case FIRMWARE_TYPE_SYMBOL:
  1412. err = hermes_write_wordrec(hw, USER_BAP,
  1413. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  1414. HERMES_HOSTSCAN_SYMBOL_ONCE |
  1415. HERMES_HOSTSCAN_SYMBOL_BCAST);
  1416. break;
  1417. case FIRMWARE_TYPE_INTERSIL: {
  1418. __le16 req[3];
  1419. req[0] = cpu_to_le16(0x3fff); /* All channels */
  1420. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  1421. req[2] = 0; /* Any ESSID */
  1422. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1423. HERMES_RID_CNFHOSTSCAN, &req);
  1424. }
  1425. break;
  1426. case FIRMWARE_TYPE_AGERE:
  1427. if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
  1428. struct hermes_idstring idbuf;
  1429. size_t len = min(sizeof(idbuf.val),
  1430. (size_t) si->essid_len);
  1431. idbuf.len = cpu_to_le16(len);
  1432. memcpy(idbuf.val, si->essid, len);
  1433. err = hermes_write_ltv(hw, USER_BAP,
  1434. HERMES_RID_CNFSCANSSID_AGERE,
  1435. HERMES_BYTES_TO_RECLEN(len + 2),
  1436. &idbuf);
  1437. } else
  1438. err = hermes_write_wordrec(hw, USER_BAP,
  1439. HERMES_RID_CNFSCANSSID_AGERE,
  1440. 0); /* Any ESSID */
  1441. if (err)
  1442. break;
  1443. if (priv->has_ext_scan) {
  1444. /* Clear scan results at the start of
  1445. * an extended scan */
  1446. orinoco_clear_scan_results(priv,
  1447. msecs_to_jiffies(15000));
  1448. /* TODO: Is this available on older firmware?
  1449. * Can we use it to scan specific channels
  1450. * for IW_SCAN_THIS_FREQ? */
  1451. err = hermes_write_wordrec(hw, USER_BAP,
  1452. HERMES_RID_CNFSCANCHANNELS2GHZ,
  1453. 0x7FFF);
  1454. if (err)
  1455. goto out;
  1456. err = hermes_inquire(hw,
  1457. HERMES_INQ_CHANNELINFO);
  1458. } else
  1459. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1460. break;
  1461. }
  1462. } else
  1463. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1464. /* One more client */
  1465. if (!err)
  1466. priv->scan_inprogress = 1;
  1467. out:
  1468. orinoco_unlock(priv, &flags);
  1469. return err;
  1470. }
  1471. #define MAX_CUSTOM_LEN 64
  1472. /* Translate scan data returned from the card to a card independant
  1473. * format that the Wireless Tools will understand - Jean II */
  1474. static inline char *orinoco_translate_scan(struct net_device *dev,
  1475. struct iw_request_info *info,
  1476. char *current_ev,
  1477. char *end_buf,
  1478. union hermes_scan_info *bss,
  1479. unsigned long last_scanned)
  1480. {
  1481. struct orinoco_private *priv = netdev_priv(dev);
  1482. u16 capabilities;
  1483. u16 channel;
  1484. struct iw_event iwe; /* Temporary buffer */
  1485. char custom[MAX_CUSTOM_LEN];
  1486. memset(&iwe, 0, sizeof(iwe));
  1487. /* First entry *MUST* be the AP MAC address */
  1488. iwe.cmd = SIOCGIWAP;
  1489. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1490. memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
  1491. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1492. &iwe, IW_EV_ADDR_LEN);
  1493. /* Other entries will be displayed in the order we give them */
  1494. /* Add the ESSID */
  1495. iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
  1496. if (iwe.u.data.length > 32)
  1497. iwe.u.data.length = 32;
  1498. iwe.cmd = SIOCGIWESSID;
  1499. iwe.u.data.flags = 1;
  1500. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1501. &iwe, bss->a.essid);
  1502. /* Add mode */
  1503. iwe.cmd = SIOCGIWMODE;
  1504. capabilities = le16_to_cpu(bss->a.capabilities);
  1505. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  1506. if (capabilities & WLAN_CAPABILITY_ESS)
  1507. iwe.u.mode = IW_MODE_MASTER;
  1508. else
  1509. iwe.u.mode = IW_MODE_ADHOC;
  1510. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1511. &iwe, IW_EV_UINT_LEN);
  1512. }
  1513. channel = bss->s.channel;
  1514. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  1515. /* Add channel and frequency */
  1516. iwe.cmd = SIOCGIWFREQ;
  1517. iwe.u.freq.m = channel;
  1518. iwe.u.freq.e = 0;
  1519. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1520. &iwe, IW_EV_FREQ_LEN);
  1521. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  1522. iwe.u.freq.e = 1;
  1523. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1524. &iwe, IW_EV_FREQ_LEN);
  1525. }
  1526. /* Add quality statistics. level and noise in dB. No link quality */
  1527. iwe.cmd = IWEVQUAL;
  1528. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  1529. iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
  1530. iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
  1531. /* Wireless tools prior to 27.pre22 will show link quality
  1532. * anyway, so we provide a reasonable value. */
  1533. if (iwe.u.qual.level > iwe.u.qual.noise)
  1534. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  1535. else
  1536. iwe.u.qual.qual = 0;
  1537. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1538. &iwe, IW_EV_QUAL_LEN);
  1539. /* Add encryption capability */
  1540. iwe.cmd = SIOCGIWENCODE;
  1541. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  1542. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1543. else
  1544. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1545. iwe.u.data.length = 0;
  1546. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1547. &iwe, NULL);
  1548. /* Bit rate is not available in Lucent/Agere firmwares */
  1549. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  1550. char *current_val = current_ev + iwe_stream_lcp_len(info);
  1551. int i;
  1552. int step;
  1553. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  1554. step = 2;
  1555. else
  1556. step = 1;
  1557. iwe.cmd = SIOCGIWRATE;
  1558. /* Those two flags are ignored... */
  1559. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  1560. /* Max 10 values */
  1561. for (i = 0; i < 10; i += step) {
  1562. /* NULL terminated */
  1563. if (bss->p.rates[i] == 0x0)
  1564. break;
  1565. /* Bit rate given in 500 kb/s units (+ 0x80) */
  1566. iwe.u.bitrate.value =
  1567. ((bss->p.rates[i] & 0x7f) * 500000);
  1568. current_val = iwe_stream_add_value(info, current_ev,
  1569. current_val,
  1570. end_buf, &iwe,
  1571. IW_EV_PARAM_LEN);
  1572. }
  1573. /* Check if we added any event */
  1574. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  1575. current_ev = current_val;
  1576. }
  1577. /* Beacon interval */
  1578. iwe.cmd = IWEVCUSTOM;
  1579. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1580. "bcn_int=%d",
  1581. le16_to_cpu(bss->a.beacon_interv));
  1582. if (iwe.u.data.length)
  1583. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1584. &iwe, custom);
  1585. /* Capabilites */
  1586. iwe.cmd = IWEVCUSTOM;
  1587. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1588. "capab=0x%04x",
  1589. capabilities);
  1590. if (iwe.u.data.length)
  1591. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1592. &iwe, custom);
  1593. /* Add EXTRA: Age to display seconds since last beacon/probe response
  1594. * for given network. */
  1595. iwe.cmd = IWEVCUSTOM;
  1596. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1597. " Last beacon: %dms ago",
  1598. jiffies_to_msecs(jiffies - last_scanned));
  1599. if (iwe.u.data.length)
  1600. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1601. &iwe, custom);
  1602. return current_ev;
  1603. }
  1604. static inline char *orinoco_translate_ext_scan(struct net_device *dev,
  1605. struct iw_request_info *info,
  1606. char *current_ev,
  1607. char *end_buf,
  1608. struct agere_ext_scan_info *bss,
  1609. unsigned long last_scanned)
  1610. {
  1611. u16 capabilities;
  1612. u16 channel;
  1613. struct iw_event iwe; /* Temporary buffer */
  1614. char custom[MAX_CUSTOM_LEN];
  1615. u8 *ie;
  1616. memset(&iwe, 0, sizeof(iwe));
  1617. /* First entry *MUST* be the AP MAC address */
  1618. iwe.cmd = SIOCGIWAP;
  1619. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1620. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  1621. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1622. &iwe, IW_EV_ADDR_LEN);
  1623. /* Other entries will be displayed in the order we give them */
  1624. /* Add the ESSID */
  1625. ie = bss->data;
  1626. iwe.u.data.length = ie[1];
  1627. if (iwe.u.data.length) {
  1628. if (iwe.u.data.length > 32)
  1629. iwe.u.data.length = 32;
  1630. iwe.cmd = SIOCGIWESSID;
  1631. iwe.u.data.flags = 1;
  1632. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1633. &iwe, &ie[2]);
  1634. }
  1635. /* Add mode */
  1636. capabilities = le16_to_cpu(bss->capabilities);
  1637. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  1638. iwe.cmd = SIOCGIWMODE;
  1639. if (capabilities & WLAN_CAPABILITY_ESS)
  1640. iwe.u.mode = IW_MODE_MASTER;
  1641. else
  1642. iwe.u.mode = IW_MODE_ADHOC;
  1643. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1644. &iwe, IW_EV_UINT_LEN);
  1645. }
  1646. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
  1647. channel = ie ? ie[2] : 0;
  1648. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  1649. /* Add channel and frequency */
  1650. iwe.cmd = SIOCGIWFREQ;
  1651. iwe.u.freq.m = channel;
  1652. iwe.u.freq.e = 0;
  1653. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1654. &iwe, IW_EV_FREQ_LEN);
  1655. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  1656. iwe.u.freq.e = 1;
  1657. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1658. &iwe, IW_EV_FREQ_LEN);
  1659. }
  1660. /* Add quality statistics. level and noise in dB. No link quality */
  1661. iwe.cmd = IWEVQUAL;
  1662. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  1663. iwe.u.qual.level = bss->level - 0x95;
  1664. iwe.u.qual.noise = bss->noise - 0x95;
  1665. /* Wireless tools prior to 27.pre22 will show link quality
  1666. * anyway, so we provide a reasonable value. */
  1667. if (iwe.u.qual.level > iwe.u.qual.noise)
  1668. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  1669. else
  1670. iwe.u.qual.qual = 0;
  1671. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1672. &iwe, IW_EV_QUAL_LEN);
  1673. /* Add encryption capability */
  1674. iwe.cmd = SIOCGIWENCODE;
  1675. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  1676. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1677. else
  1678. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1679. iwe.u.data.length = 0;
  1680. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1681. &iwe, NULL);
  1682. /* WPA IE */
  1683. ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
  1684. if (ie) {
  1685. iwe.cmd = IWEVGENIE;
  1686. iwe.u.data.length = ie[1] + 2;
  1687. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1688. &iwe, ie);
  1689. }
  1690. /* RSN IE */
  1691. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
  1692. if (ie) {
  1693. iwe.cmd = IWEVGENIE;
  1694. iwe.u.data.length = ie[1] + 2;
  1695. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1696. &iwe, ie);
  1697. }
  1698. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
  1699. if (ie) {
  1700. char *p = current_ev + iwe_stream_lcp_len(info);
  1701. int i;
  1702. iwe.cmd = SIOCGIWRATE;
  1703. /* Those two flags are ignored... */
  1704. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  1705. for (i = 2; i < (ie[1] + 2); i++) {
  1706. iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
  1707. p = iwe_stream_add_value(info, current_ev, p, end_buf,
  1708. &iwe, IW_EV_PARAM_LEN);
  1709. }
  1710. /* Check if we added any event */
  1711. if (p > (current_ev + iwe_stream_lcp_len(info)))
  1712. current_ev = p;
  1713. }
  1714. /* Timestamp */
  1715. iwe.cmd = IWEVCUSTOM;
  1716. iwe.u.data.length =
  1717. snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
  1718. (unsigned long long) le64_to_cpu(bss->timestamp));
  1719. if (iwe.u.data.length)
  1720. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1721. &iwe, custom);
  1722. /* Beacon interval */
  1723. iwe.cmd = IWEVCUSTOM;
  1724. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1725. "bcn_int=%d",
  1726. le16_to_cpu(bss->beacon_interval));
  1727. if (iwe.u.data.length)
  1728. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1729. &iwe, custom);
  1730. /* Capabilites */
  1731. iwe.cmd = IWEVCUSTOM;
  1732. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1733. "capab=0x%04x",
  1734. capabilities);
  1735. if (iwe.u.data.length)
  1736. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1737. &iwe, custom);
  1738. /* Add EXTRA: Age to display seconds since last beacon/probe response
  1739. * for given network. */
  1740. iwe.cmd = IWEVCUSTOM;
  1741. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1742. " Last beacon: %dms ago",
  1743. jiffies_to_msecs(jiffies - last_scanned));
  1744. if (iwe.u.data.length)
  1745. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1746. &iwe, custom);
  1747. return current_ev;
  1748. }
  1749. /* Return results of a scan */
  1750. static int orinoco_ioctl_getscan(struct net_device *dev,
  1751. struct iw_request_info *info,
  1752. struct iw_point *srq,
  1753. char *extra)
  1754. {
  1755. struct orinoco_private *priv = netdev_priv(dev);
  1756. int err = 0;
  1757. unsigned long flags;
  1758. char *current_ev = extra;
  1759. if (orinoco_lock(priv, &flags) != 0)
  1760. return -EBUSY;
  1761. if (priv->scan_inprogress) {
  1762. /* Important note : we don't want to block the caller
  1763. * until results are ready for various reasons.
  1764. * First, managing wait queues is complex and racy.
  1765. * Second, we grab some rtnetlink lock before comming
  1766. * here (in dev_ioctl()).
  1767. * Third, we generate an Wireless Event, so the
  1768. * caller can wait itself on that - Jean II */
  1769. err = -EAGAIN;
  1770. goto out;
  1771. }
  1772. if (priv->has_ext_scan) {
  1773. struct xbss_element *bss;
  1774. list_for_each_entry(bss, &priv->bss_list, list) {
  1775. /* Translate this entry to WE format */
  1776. current_ev =
  1777. orinoco_translate_ext_scan(dev, info,
  1778. current_ev,
  1779. extra + srq->length,
  1780. &bss->bss,
  1781. bss->last_scanned);
  1782. /* Check if there is space for one more entry */
  1783. if ((extra + srq->length - current_ev)
  1784. <= IW_EV_ADDR_LEN) {
  1785. /* Ask user space to try again with a
  1786. * bigger buffer */
  1787. err = -E2BIG;
  1788. goto out;
  1789. }
  1790. }
  1791. } else {
  1792. struct bss_element *bss;
  1793. list_for_each_entry(bss, &priv->bss_list, list) {
  1794. /* Translate this entry to WE format */
  1795. current_ev = orinoco_translate_scan(dev, info,
  1796. current_ev,
  1797. extra + srq->length,
  1798. &bss->bss,
  1799. bss->last_scanned);
  1800. /* Check if there is space for one more entry */
  1801. if ((extra + srq->length - current_ev)
  1802. <= IW_EV_ADDR_LEN) {
  1803. /* Ask user space to try again with a
  1804. * bigger buffer */
  1805. err = -E2BIG;
  1806. goto out;
  1807. }
  1808. }
  1809. }
  1810. srq->length = (current_ev - extra);
  1811. srq->flags = (__u16) priv->scan_mode;
  1812. out:
  1813. orinoco_unlock(priv, &flags);
  1814. return err;
  1815. }
  1816. /* Commit handler, called after set operations */
  1817. static int orinoco_ioctl_commit(struct net_device *dev,
  1818. struct iw_request_info *info,
  1819. void *wrqu,
  1820. char *extra)
  1821. {
  1822. struct orinoco_private *priv = netdev_priv(dev);
  1823. struct hermes *hw = &priv->hw;
  1824. unsigned long flags;
  1825. int err = 0;
  1826. if (!priv->open)
  1827. return 0;
  1828. if (priv->broken_disableport) {
  1829. orinoco_reset(&priv->reset_work);
  1830. return 0;
  1831. }
  1832. if (orinoco_lock(priv, &flags) != 0)
  1833. return err;
  1834. err = hermes_disable_port(hw, 0);
  1835. if (err) {
  1836. printk(KERN_WARNING "%s: Unable to disable port "
  1837. "while reconfiguring card\n", dev->name);
  1838. priv->broken_disableport = 1;
  1839. goto out;
  1840. }
  1841. err = __orinoco_program_rids(dev);
  1842. if (err) {
  1843. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  1844. dev->name);
  1845. goto out;
  1846. }
  1847. err = hermes_enable_port(hw, 0);
  1848. if (err) {
  1849. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  1850. dev->name);
  1851. goto out;
  1852. }
  1853. out:
  1854. if (err) {
  1855. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  1856. schedule_work(&priv->reset_work);
  1857. err = 0;
  1858. }
  1859. orinoco_unlock(priv, &flags);
  1860. return err;
  1861. }
  1862. static const struct iw_priv_args orinoco_privtab[] = {
  1863. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  1864. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  1865. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1866. 0, "set_port3" },
  1867. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1868. "get_port3" },
  1869. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1870. 0, "set_preamble" },
  1871. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1872. "get_preamble" },
  1873. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1874. 0, "set_ibssport" },
  1875. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1876. "get_ibssport" },
  1877. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  1878. "get_rid" },
  1879. };
  1880. /*
  1881. * Structures to export the Wireless Handlers
  1882. */
  1883. #define STD_IW_HANDLER(id, func) \
  1884. [IW_IOCTL_IDX(id)] = (iw_handler) func
  1885. static const iw_handler orinoco_handler[] = {
  1886. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  1887. STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
  1888. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  1889. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  1890. STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
  1891. STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
  1892. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  1893. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  1894. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  1895. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  1896. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  1897. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  1898. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  1899. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  1900. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  1901. STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
  1902. STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
  1903. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  1904. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  1905. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  1906. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  1907. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  1908. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  1909. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  1910. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  1911. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  1912. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  1913. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  1914. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  1915. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  1916. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  1917. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  1918. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  1919. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  1920. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  1921. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  1922. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  1923. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  1924. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  1925. };
  1926. /*
  1927. Added typecasting since we no longer use iwreq_data -- Moustafa
  1928. */
  1929. static const iw_handler orinoco_private_handler[] = {
  1930. [0] = (iw_handler) orinoco_ioctl_reset,
  1931. [1] = (iw_handler) orinoco_ioctl_reset,
  1932. [2] = (iw_handler) orinoco_ioctl_setport3,
  1933. [3] = (iw_handler) orinoco_ioctl_getport3,
  1934. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  1935. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  1936. [6] = (iw_handler) orinoco_ioctl_setibssport,
  1937. [7] = (iw_handler) orinoco_ioctl_getibssport,
  1938. [9] = (iw_handler) orinoco_ioctl_getrid,
  1939. };
  1940. const struct iw_handler_def orinoco_handler_def = {
  1941. .num_standard = ARRAY_SIZE(orinoco_handler),
  1942. .num_private = ARRAY_SIZE(orinoco_private_handler),
  1943. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  1944. .standard = orinoco_handler,
  1945. .private = orinoco_private_handler,
  1946. .private_args = orinoco_privtab,
  1947. .get_wireless_stats = orinoco_get_wireless_stats,
  1948. };