wext.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324
  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. u8 *tkip_iv = NULL;
  889. if (!priv->has_wpa ||
  890. (ext->key_len > sizeof(priv->tkip_key[0])))
  891. goto out;
  892. priv->encode_alg = alg;
  893. memset(&priv->tkip_key[idx], 0,
  894. sizeof(priv->tkip_key[idx]));
  895. memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
  896. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  897. tkip_iv = &ext->rx_seq[0];
  898. err = __orinoco_hw_set_tkip_key(priv, idx,
  899. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  900. (u8 *) &priv->tkip_key[idx],
  901. tkip_iv, NULL);
  902. if (err)
  903. printk(KERN_ERR "%s: Error %d setting TKIP key"
  904. "\n", dev->name, err);
  905. goto out;
  906. }
  907. default:
  908. goto out;
  909. }
  910. }
  911. err = -EINPROGRESS;
  912. out:
  913. orinoco_unlock(priv, &flags);
  914. return err;
  915. }
  916. static int orinoco_ioctl_get_encodeext(struct net_device *dev,
  917. struct iw_request_info *info,
  918. union iwreq_data *wrqu,
  919. char *extra)
  920. {
  921. struct orinoco_private *priv = netdev_priv(dev);
  922. struct iw_point *encoding = &wrqu->encoding;
  923. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  924. int idx, max_key_len;
  925. unsigned long flags;
  926. int err;
  927. if (orinoco_lock(priv, &flags) != 0)
  928. return -EBUSY;
  929. err = -EINVAL;
  930. max_key_len = encoding->length - sizeof(*ext);
  931. if (max_key_len < 0)
  932. goto out;
  933. idx = encoding->flags & IW_ENCODE_INDEX;
  934. if (idx) {
  935. if ((idx < 1) || (idx > 4))
  936. goto out;
  937. idx--;
  938. } else
  939. idx = priv->tx_key;
  940. encoding->flags = idx + 1;
  941. memset(ext, 0, sizeof(*ext));
  942. ext->alg = priv->encode_alg;
  943. switch (priv->encode_alg) {
  944. case IW_ENCODE_ALG_NONE:
  945. ext->key_len = 0;
  946. encoding->flags |= IW_ENCODE_DISABLED;
  947. break;
  948. case IW_ENCODE_ALG_WEP:
  949. ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
  950. max_key_len);
  951. memcpy(ext->key, priv->keys[idx].data, ext->key_len);
  952. encoding->flags |= IW_ENCODE_ENABLED;
  953. break;
  954. case IW_ENCODE_ALG_TKIP:
  955. ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
  956. max_key_len);
  957. memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
  958. encoding->flags |= IW_ENCODE_ENABLED;
  959. break;
  960. }
  961. err = 0;
  962. out:
  963. orinoco_unlock(priv, &flags);
  964. return err;
  965. }
  966. static int orinoco_ioctl_set_auth(struct net_device *dev,
  967. struct iw_request_info *info,
  968. union iwreq_data *wrqu, char *extra)
  969. {
  970. struct orinoco_private *priv = netdev_priv(dev);
  971. hermes_t *hw = &priv->hw;
  972. struct iw_param *param = &wrqu->param;
  973. unsigned long flags;
  974. int ret = -EINPROGRESS;
  975. if (orinoco_lock(priv, &flags) != 0)
  976. return -EBUSY;
  977. switch (param->flags & IW_AUTH_INDEX) {
  978. case IW_AUTH_WPA_VERSION:
  979. case IW_AUTH_CIPHER_PAIRWISE:
  980. case IW_AUTH_CIPHER_GROUP:
  981. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  982. case IW_AUTH_PRIVACY_INVOKED:
  983. case IW_AUTH_DROP_UNENCRYPTED:
  984. /*
  985. * orinoco does not use these parameters
  986. */
  987. break;
  988. case IW_AUTH_KEY_MGMT:
  989. /* wl_lkm implies value 2 == PSK for Hermes I
  990. * which ties in with WEXT
  991. * no other hints tho :(
  992. */
  993. priv->key_mgmt = param->value;
  994. break;
  995. case IW_AUTH_TKIP_COUNTERMEASURES:
  996. /* When countermeasures are enabled, shut down the
  997. * card; when disabled, re-enable the card. This must
  998. * take effect immediately.
  999. *
  1000. * TODO: Make sure that the EAPOL message is getting
  1001. * out before card disabled
  1002. */
  1003. if (param->value) {
  1004. priv->tkip_cm_active = 1;
  1005. ret = hermes_enable_port(hw, 0);
  1006. } else {
  1007. priv->tkip_cm_active = 0;
  1008. ret = hermes_disable_port(hw, 0);
  1009. }
  1010. break;
  1011. case IW_AUTH_80211_AUTH_ALG:
  1012. if (param->value & IW_AUTH_ALG_SHARED_KEY)
  1013. priv->wep_restrict = 1;
  1014. else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
  1015. priv->wep_restrict = 0;
  1016. else
  1017. ret = -EINVAL;
  1018. break;
  1019. case IW_AUTH_WPA_ENABLED:
  1020. if (priv->has_wpa) {
  1021. priv->wpa_enabled = param->value ? 1 : 0;
  1022. } else {
  1023. if (param->value)
  1024. ret = -EOPNOTSUPP;
  1025. /* else silently accept disable of WPA */
  1026. priv->wpa_enabled = 0;
  1027. }
  1028. break;
  1029. default:
  1030. ret = -EOPNOTSUPP;
  1031. }
  1032. orinoco_unlock(priv, &flags);
  1033. return ret;
  1034. }
  1035. static int orinoco_ioctl_get_auth(struct net_device *dev,
  1036. struct iw_request_info *info,
  1037. union iwreq_data *wrqu, char *extra)
  1038. {
  1039. struct orinoco_private *priv = netdev_priv(dev);
  1040. struct iw_param *param = &wrqu->param;
  1041. unsigned long flags;
  1042. int ret = 0;
  1043. if (orinoco_lock(priv, &flags) != 0)
  1044. return -EBUSY;
  1045. switch (param->flags & IW_AUTH_INDEX) {
  1046. case IW_AUTH_KEY_MGMT:
  1047. param->value = priv->key_mgmt;
  1048. break;
  1049. case IW_AUTH_TKIP_COUNTERMEASURES:
  1050. param->value = priv->tkip_cm_active;
  1051. break;
  1052. case IW_AUTH_80211_AUTH_ALG:
  1053. if (priv->wep_restrict)
  1054. param->value = IW_AUTH_ALG_SHARED_KEY;
  1055. else
  1056. param->value = IW_AUTH_ALG_OPEN_SYSTEM;
  1057. break;
  1058. case IW_AUTH_WPA_ENABLED:
  1059. param->value = priv->wpa_enabled;
  1060. break;
  1061. default:
  1062. ret = -EOPNOTSUPP;
  1063. }
  1064. orinoco_unlock(priv, &flags);
  1065. return ret;
  1066. }
  1067. static int orinoco_ioctl_set_genie(struct net_device *dev,
  1068. struct iw_request_info *info,
  1069. union iwreq_data *wrqu, char *extra)
  1070. {
  1071. struct orinoco_private *priv = netdev_priv(dev);
  1072. u8 *buf;
  1073. unsigned long flags;
  1074. /* cut off at IEEE80211_MAX_DATA_LEN */
  1075. if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
  1076. (wrqu->data.length && (extra == NULL)))
  1077. return -EINVAL;
  1078. if (wrqu->data.length) {
  1079. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  1080. if (buf == NULL)
  1081. return -ENOMEM;
  1082. memcpy(buf, extra, wrqu->data.length);
  1083. } else
  1084. buf = NULL;
  1085. if (orinoco_lock(priv, &flags) != 0) {
  1086. kfree(buf);
  1087. return -EBUSY;
  1088. }
  1089. kfree(priv->wpa_ie);
  1090. priv->wpa_ie = buf;
  1091. priv->wpa_ie_len = wrqu->data.length;
  1092. if (priv->wpa_ie) {
  1093. /* Looks like wl_lkm wants to check the auth alg, and
  1094. * somehow pass it to the firmware.
  1095. * Instead it just calls the key mgmt rid
  1096. * - we do this in set auth.
  1097. */
  1098. }
  1099. orinoco_unlock(priv, &flags);
  1100. return 0;
  1101. }
  1102. static int orinoco_ioctl_get_genie(struct net_device *dev,
  1103. struct iw_request_info *info,
  1104. union iwreq_data *wrqu, char *extra)
  1105. {
  1106. struct orinoco_private *priv = netdev_priv(dev);
  1107. unsigned long flags;
  1108. int err = 0;
  1109. if (orinoco_lock(priv, &flags) != 0)
  1110. return -EBUSY;
  1111. if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
  1112. wrqu->data.length = 0;
  1113. goto out;
  1114. }
  1115. if (wrqu->data.length < priv->wpa_ie_len) {
  1116. err = -E2BIG;
  1117. goto out;
  1118. }
  1119. wrqu->data.length = priv->wpa_ie_len;
  1120. memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
  1121. out:
  1122. orinoco_unlock(priv, &flags);
  1123. return err;
  1124. }
  1125. static int orinoco_ioctl_set_mlme(struct net_device *dev,
  1126. struct iw_request_info *info,
  1127. union iwreq_data *wrqu, char *extra)
  1128. {
  1129. struct orinoco_private *priv = netdev_priv(dev);
  1130. hermes_t *hw = &priv->hw;
  1131. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  1132. unsigned long flags;
  1133. int ret = 0;
  1134. if (orinoco_lock(priv, &flags) != 0)
  1135. return -EBUSY;
  1136. switch (mlme->cmd) {
  1137. case IW_MLME_DEAUTH:
  1138. /* silently ignore */
  1139. break;
  1140. case IW_MLME_DISASSOC:
  1141. {
  1142. struct {
  1143. u8 addr[ETH_ALEN];
  1144. __le16 reason_code;
  1145. } __attribute__ ((packed)) buf;
  1146. memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
  1147. buf.reason_code = cpu_to_le16(mlme->reason_code);
  1148. ret = HERMES_WRITE_RECORD(hw, USER_BAP,
  1149. HERMES_RID_CNFDISASSOCIATE,
  1150. &buf);
  1151. break;
  1152. }
  1153. default:
  1154. ret = -EOPNOTSUPP;
  1155. }
  1156. orinoco_unlock(priv, &flags);
  1157. return ret;
  1158. }
  1159. static int orinoco_ioctl_getretry(struct net_device *dev,
  1160. struct iw_request_info *info,
  1161. struct iw_param *rrq,
  1162. char *extra)
  1163. {
  1164. struct orinoco_private *priv = netdev_priv(dev);
  1165. hermes_t *hw = &priv->hw;
  1166. int err = 0;
  1167. u16 short_limit, long_limit, lifetime;
  1168. unsigned long flags;
  1169. if (orinoco_lock(priv, &flags) != 0)
  1170. return -EBUSY;
  1171. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
  1172. &short_limit);
  1173. if (err)
  1174. goto out;
  1175. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
  1176. &long_limit);
  1177. if (err)
  1178. goto out;
  1179. err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
  1180. &lifetime);
  1181. if (err)
  1182. goto out;
  1183. rrq->disabled = 0; /* Can't be disabled */
  1184. /* Note : by default, display the retry number */
  1185. if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  1186. rrq->flags = IW_RETRY_LIFETIME;
  1187. rrq->value = lifetime * 1000; /* ??? */
  1188. } else {
  1189. /* By default, display the min number */
  1190. if ((rrq->flags & IW_RETRY_LONG)) {
  1191. rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  1192. rrq->value = long_limit;
  1193. } else {
  1194. rrq->flags = IW_RETRY_LIMIT;
  1195. rrq->value = short_limit;
  1196. if (short_limit != long_limit)
  1197. rrq->flags |= IW_RETRY_SHORT;
  1198. }
  1199. }
  1200. out:
  1201. orinoco_unlock(priv, &flags);
  1202. return err;
  1203. }
  1204. static int orinoco_ioctl_reset(struct net_device *dev,
  1205. struct iw_request_info *info,
  1206. void *wrqu,
  1207. char *extra)
  1208. {
  1209. struct orinoco_private *priv = netdev_priv(dev);
  1210. if (!capable(CAP_NET_ADMIN))
  1211. return -EPERM;
  1212. if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
  1213. printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
  1214. /* Firmware reset */
  1215. orinoco_reset(&priv->reset_work);
  1216. } else {
  1217. printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
  1218. schedule_work(&priv->reset_work);
  1219. }
  1220. return 0;
  1221. }
  1222. static int orinoco_ioctl_setibssport(struct net_device *dev,
  1223. struct iw_request_info *info,
  1224. void *wrqu,
  1225. char *extra)
  1226. {
  1227. struct orinoco_private *priv = netdev_priv(dev);
  1228. int val = *((int *) extra);
  1229. unsigned long flags;
  1230. if (orinoco_lock(priv, &flags) != 0)
  1231. return -EBUSY;
  1232. priv->ibss_port = val ;
  1233. /* Actually update the mode we are using */
  1234. set_port_type(priv);
  1235. orinoco_unlock(priv, &flags);
  1236. return -EINPROGRESS; /* Call commit handler */
  1237. }
  1238. static int orinoco_ioctl_getibssport(struct net_device *dev,
  1239. struct iw_request_info *info,
  1240. void *wrqu,
  1241. char *extra)
  1242. {
  1243. struct orinoco_private *priv = netdev_priv(dev);
  1244. int *val = (int *) extra;
  1245. *val = priv->ibss_port;
  1246. return 0;
  1247. }
  1248. static int orinoco_ioctl_setport3(struct net_device *dev,
  1249. struct iw_request_info *info,
  1250. void *wrqu,
  1251. char *extra)
  1252. {
  1253. struct orinoco_private *priv = netdev_priv(dev);
  1254. int val = *((int *) extra);
  1255. int err = 0;
  1256. unsigned long flags;
  1257. if (orinoco_lock(priv, &flags) != 0)
  1258. return -EBUSY;
  1259. switch (val) {
  1260. case 0: /* Try to do IEEE ad-hoc mode */
  1261. if (!priv->has_ibss) {
  1262. err = -EINVAL;
  1263. break;
  1264. }
  1265. priv->prefer_port3 = 0;
  1266. break;
  1267. case 1: /* Try to do Lucent proprietary ad-hoc mode */
  1268. if (!priv->has_port3) {
  1269. err = -EINVAL;
  1270. break;
  1271. }
  1272. priv->prefer_port3 = 1;
  1273. break;
  1274. default:
  1275. err = -EINVAL;
  1276. }
  1277. if (!err) {
  1278. /* Actually update the mode we are using */
  1279. set_port_type(priv);
  1280. err = -EINPROGRESS;
  1281. }
  1282. orinoco_unlock(priv, &flags);
  1283. return err;
  1284. }
  1285. static int orinoco_ioctl_getport3(struct net_device *dev,
  1286. struct iw_request_info *info,
  1287. void *wrqu,
  1288. char *extra)
  1289. {
  1290. struct orinoco_private *priv = netdev_priv(dev);
  1291. int *val = (int *) extra;
  1292. *val = priv->prefer_port3;
  1293. return 0;
  1294. }
  1295. static int orinoco_ioctl_setpreamble(struct net_device *dev,
  1296. struct iw_request_info *info,
  1297. void *wrqu,
  1298. char *extra)
  1299. {
  1300. struct orinoco_private *priv = netdev_priv(dev);
  1301. unsigned long flags;
  1302. int val;
  1303. if (!priv->has_preamble)
  1304. return -EOPNOTSUPP;
  1305. /* 802.11b has recently defined some short preamble.
  1306. * Basically, the Phy header has been reduced in size.
  1307. * This increase performance, especially at high rates
  1308. * (the preamble is transmitted at 1Mb/s), unfortunately
  1309. * this give compatibility troubles... - Jean II */
  1310. val = *((int *) extra);
  1311. if (orinoco_lock(priv, &flags) != 0)
  1312. return -EBUSY;
  1313. if (val)
  1314. priv->preamble = 1;
  1315. else
  1316. priv->preamble = 0;
  1317. orinoco_unlock(priv, &flags);
  1318. return -EINPROGRESS; /* Call commit handler */
  1319. }
  1320. static int orinoco_ioctl_getpreamble(struct net_device *dev,
  1321. struct iw_request_info *info,
  1322. void *wrqu,
  1323. char *extra)
  1324. {
  1325. struct orinoco_private *priv = netdev_priv(dev);
  1326. int *val = (int *) extra;
  1327. if (!priv->has_preamble)
  1328. return -EOPNOTSUPP;
  1329. *val = priv->preamble;
  1330. return 0;
  1331. }
  1332. /* ioctl interface to hermes_read_ltv()
  1333. * To use with iwpriv, pass the RID as the token argument, e.g.
  1334. * iwpriv get_rid [0xfc00]
  1335. * At least Wireless Tools 25 is required to use iwpriv.
  1336. * For Wireless Tools 25 and 26 append "dummy" are the end. */
  1337. static int orinoco_ioctl_getrid(struct net_device *dev,
  1338. struct iw_request_info *info,
  1339. struct iw_point *data,
  1340. char *extra)
  1341. {
  1342. struct orinoco_private *priv = netdev_priv(dev);
  1343. hermes_t *hw = &priv->hw;
  1344. int rid = data->flags;
  1345. u16 length;
  1346. int err;
  1347. unsigned long flags;
  1348. /* It's a "get" function, but we don't want users to access the
  1349. * WEP key and other raw firmware data */
  1350. if (!capable(CAP_NET_ADMIN))
  1351. return -EPERM;
  1352. if (rid < 0xfc00 || rid > 0xffff)
  1353. return -EINVAL;
  1354. if (orinoco_lock(priv, &flags) != 0)
  1355. return -EBUSY;
  1356. err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
  1357. extra);
  1358. if (err)
  1359. goto out;
  1360. data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
  1361. MAX_RID_LEN);
  1362. out:
  1363. orinoco_unlock(priv, &flags);
  1364. return err;
  1365. }
  1366. /* Trigger a scan (look for other cells in the vicinity) */
  1367. static int orinoco_ioctl_setscan(struct net_device *dev,
  1368. struct iw_request_info *info,
  1369. struct iw_point *srq,
  1370. char *extra)
  1371. {
  1372. struct orinoco_private *priv = netdev_priv(dev);
  1373. hermes_t *hw = &priv->hw;
  1374. struct iw_scan_req *si = (struct iw_scan_req *) extra;
  1375. int err = 0;
  1376. unsigned long flags;
  1377. /* Note : you may have realised that, as this is a SET operation,
  1378. * this is privileged and therefore a normal user can't
  1379. * perform scanning.
  1380. * This is not an error, while the device perform scanning,
  1381. * traffic doesn't flow, so it's a perfect DoS...
  1382. * Jean II */
  1383. if (orinoco_lock(priv, &flags) != 0)
  1384. return -EBUSY;
  1385. /* Scanning with port 0 disabled would fail */
  1386. if (!netif_running(dev)) {
  1387. err = -ENETDOWN;
  1388. goto out;
  1389. }
  1390. /* In monitor mode, the scan results are always empty.
  1391. * Probe responses are passed to the driver as received
  1392. * frames and could be processed in software. */
  1393. if (priv->iw_mode == IW_MODE_MONITOR) {
  1394. err = -EOPNOTSUPP;
  1395. goto out;
  1396. }
  1397. /* Note : because we don't lock out the irq handler, the way
  1398. * we access scan variables in priv is critical.
  1399. * o scan_inprogress : not touched by irq handler
  1400. * o scan_mode : not touched by irq handler
  1401. * Before modifying anything on those variables, please think hard !
  1402. * Jean II */
  1403. /* Save flags */
  1404. priv->scan_mode = srq->flags;
  1405. /* Always trigger scanning, even if it's in progress.
  1406. * This way, if the info frame get lost, we will recover somewhat
  1407. * gracefully - Jean II */
  1408. if (priv->has_hostscan) {
  1409. switch (priv->firmware_type) {
  1410. case FIRMWARE_TYPE_SYMBOL:
  1411. err = hermes_write_wordrec(hw, USER_BAP,
  1412. HERMES_RID_CNFHOSTSCAN_SYMBOL,
  1413. HERMES_HOSTSCAN_SYMBOL_ONCE |
  1414. HERMES_HOSTSCAN_SYMBOL_BCAST);
  1415. break;
  1416. case FIRMWARE_TYPE_INTERSIL: {
  1417. __le16 req[3];
  1418. req[0] = cpu_to_le16(0x3fff); /* All channels */
  1419. req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
  1420. req[2] = 0; /* Any ESSID */
  1421. err = HERMES_WRITE_RECORD(hw, USER_BAP,
  1422. HERMES_RID_CNFHOSTSCAN, &req);
  1423. }
  1424. break;
  1425. case FIRMWARE_TYPE_AGERE:
  1426. if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
  1427. struct hermes_idstring idbuf;
  1428. size_t len = min(sizeof(idbuf.val),
  1429. (size_t) si->essid_len);
  1430. idbuf.len = cpu_to_le16(len);
  1431. memcpy(idbuf.val, si->essid, len);
  1432. err = hermes_write_ltv(hw, USER_BAP,
  1433. HERMES_RID_CNFSCANSSID_AGERE,
  1434. HERMES_BYTES_TO_RECLEN(len + 2),
  1435. &idbuf);
  1436. } else
  1437. err = hermes_write_wordrec(hw, USER_BAP,
  1438. HERMES_RID_CNFSCANSSID_AGERE,
  1439. 0); /* Any ESSID */
  1440. if (err)
  1441. break;
  1442. if (priv->has_ext_scan) {
  1443. /* Clear scan results at the start of
  1444. * an extended scan */
  1445. orinoco_clear_scan_results(priv,
  1446. msecs_to_jiffies(15000));
  1447. /* TODO: Is this available on older firmware?
  1448. * Can we use it to scan specific channels
  1449. * for IW_SCAN_THIS_FREQ? */
  1450. err = hermes_write_wordrec(hw, USER_BAP,
  1451. HERMES_RID_CNFSCANCHANNELS2GHZ,
  1452. 0x7FFF);
  1453. if (err)
  1454. goto out;
  1455. err = hermes_inquire(hw,
  1456. HERMES_INQ_CHANNELINFO);
  1457. } else
  1458. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1459. break;
  1460. }
  1461. } else
  1462. err = hermes_inquire(hw, HERMES_INQ_SCAN);
  1463. /* One more client */
  1464. if (!err)
  1465. priv->scan_inprogress = 1;
  1466. out:
  1467. orinoco_unlock(priv, &flags);
  1468. return err;
  1469. }
  1470. #define MAX_CUSTOM_LEN 64
  1471. /* Translate scan data returned from the card to a card independant
  1472. * format that the Wireless Tools will understand - Jean II */
  1473. static inline char *orinoco_translate_scan(struct net_device *dev,
  1474. struct iw_request_info *info,
  1475. char *current_ev,
  1476. char *end_buf,
  1477. union hermes_scan_info *bss,
  1478. unsigned long last_scanned)
  1479. {
  1480. struct orinoco_private *priv = netdev_priv(dev);
  1481. u16 capabilities;
  1482. u16 channel;
  1483. struct iw_event iwe; /* Temporary buffer */
  1484. char custom[MAX_CUSTOM_LEN];
  1485. memset(&iwe, 0, sizeof(iwe));
  1486. /* First entry *MUST* be the AP MAC address */
  1487. iwe.cmd = SIOCGIWAP;
  1488. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1489. memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
  1490. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1491. &iwe, IW_EV_ADDR_LEN);
  1492. /* Other entries will be displayed in the order we give them */
  1493. /* Add the ESSID */
  1494. iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
  1495. if (iwe.u.data.length > 32)
  1496. iwe.u.data.length = 32;
  1497. iwe.cmd = SIOCGIWESSID;
  1498. iwe.u.data.flags = 1;
  1499. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1500. &iwe, bss->a.essid);
  1501. /* Add mode */
  1502. iwe.cmd = SIOCGIWMODE;
  1503. capabilities = le16_to_cpu(bss->a.capabilities);
  1504. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  1505. if (capabilities & WLAN_CAPABILITY_ESS)
  1506. iwe.u.mode = IW_MODE_MASTER;
  1507. else
  1508. iwe.u.mode = IW_MODE_ADHOC;
  1509. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1510. &iwe, IW_EV_UINT_LEN);
  1511. }
  1512. channel = bss->s.channel;
  1513. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  1514. /* Add channel and frequency */
  1515. iwe.cmd = SIOCGIWFREQ;
  1516. iwe.u.freq.m = channel;
  1517. iwe.u.freq.e = 0;
  1518. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1519. &iwe, IW_EV_FREQ_LEN);
  1520. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  1521. iwe.u.freq.e = 1;
  1522. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1523. &iwe, IW_EV_FREQ_LEN);
  1524. }
  1525. /* Add quality statistics. level and noise in dB. No link quality */
  1526. iwe.cmd = IWEVQUAL;
  1527. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  1528. iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
  1529. iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
  1530. /* Wireless tools prior to 27.pre22 will show link quality
  1531. * anyway, so we provide a reasonable value. */
  1532. if (iwe.u.qual.level > iwe.u.qual.noise)
  1533. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  1534. else
  1535. iwe.u.qual.qual = 0;
  1536. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1537. &iwe, IW_EV_QUAL_LEN);
  1538. /* Add encryption capability */
  1539. iwe.cmd = SIOCGIWENCODE;
  1540. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  1541. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1542. else
  1543. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1544. iwe.u.data.length = 0;
  1545. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1546. &iwe, NULL);
  1547. /* Bit rate is not available in Lucent/Agere firmwares */
  1548. if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
  1549. char *current_val = current_ev + iwe_stream_lcp_len(info);
  1550. int i;
  1551. int step;
  1552. if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
  1553. step = 2;
  1554. else
  1555. step = 1;
  1556. iwe.cmd = SIOCGIWRATE;
  1557. /* Those two flags are ignored... */
  1558. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  1559. /* Max 10 values */
  1560. for (i = 0; i < 10; i += step) {
  1561. /* NULL terminated */
  1562. if (bss->p.rates[i] == 0x0)
  1563. break;
  1564. /* Bit rate given in 500 kb/s units (+ 0x80) */
  1565. iwe.u.bitrate.value =
  1566. ((bss->p.rates[i] & 0x7f) * 500000);
  1567. current_val = iwe_stream_add_value(info, current_ev,
  1568. current_val,
  1569. end_buf, &iwe,
  1570. IW_EV_PARAM_LEN);
  1571. }
  1572. /* Check if we added any event */
  1573. if ((current_val - current_ev) > iwe_stream_lcp_len(info))
  1574. current_ev = current_val;
  1575. }
  1576. /* Beacon interval */
  1577. iwe.cmd = IWEVCUSTOM;
  1578. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1579. "bcn_int=%d",
  1580. le16_to_cpu(bss->a.beacon_interv));
  1581. if (iwe.u.data.length)
  1582. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1583. &iwe, custom);
  1584. /* Capabilites */
  1585. iwe.cmd = IWEVCUSTOM;
  1586. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1587. "capab=0x%04x",
  1588. capabilities);
  1589. if (iwe.u.data.length)
  1590. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1591. &iwe, custom);
  1592. /* Add EXTRA: Age to display seconds since last beacon/probe response
  1593. * for given network. */
  1594. iwe.cmd = IWEVCUSTOM;
  1595. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1596. " Last beacon: %dms ago",
  1597. jiffies_to_msecs(jiffies - last_scanned));
  1598. if (iwe.u.data.length)
  1599. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1600. &iwe, custom);
  1601. return current_ev;
  1602. }
  1603. static inline char *orinoco_translate_ext_scan(struct net_device *dev,
  1604. struct iw_request_info *info,
  1605. char *current_ev,
  1606. char *end_buf,
  1607. struct agere_ext_scan_info *bss,
  1608. unsigned long last_scanned)
  1609. {
  1610. u16 capabilities;
  1611. u16 channel;
  1612. struct iw_event iwe; /* Temporary buffer */
  1613. char custom[MAX_CUSTOM_LEN];
  1614. u8 *ie;
  1615. memset(&iwe, 0, sizeof(iwe));
  1616. /* First entry *MUST* be the AP MAC address */
  1617. iwe.cmd = SIOCGIWAP;
  1618. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1619. memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  1620. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1621. &iwe, IW_EV_ADDR_LEN);
  1622. /* Other entries will be displayed in the order we give them */
  1623. /* Add the ESSID */
  1624. ie = bss->data;
  1625. iwe.u.data.length = ie[1];
  1626. if (iwe.u.data.length) {
  1627. if (iwe.u.data.length > 32)
  1628. iwe.u.data.length = 32;
  1629. iwe.cmd = SIOCGIWESSID;
  1630. iwe.u.data.flags = 1;
  1631. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1632. &iwe, &ie[2]);
  1633. }
  1634. /* Add mode */
  1635. capabilities = le16_to_cpu(bss->capabilities);
  1636. if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
  1637. iwe.cmd = SIOCGIWMODE;
  1638. if (capabilities & WLAN_CAPABILITY_ESS)
  1639. iwe.u.mode = IW_MODE_MASTER;
  1640. else
  1641. iwe.u.mode = IW_MODE_ADHOC;
  1642. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1643. &iwe, IW_EV_UINT_LEN);
  1644. }
  1645. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
  1646. channel = ie ? ie[2] : 0;
  1647. if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
  1648. /* Add channel and frequency */
  1649. iwe.cmd = SIOCGIWFREQ;
  1650. iwe.u.freq.m = channel;
  1651. iwe.u.freq.e = 0;
  1652. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1653. &iwe, IW_EV_FREQ_LEN);
  1654. iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
  1655. iwe.u.freq.e = 1;
  1656. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1657. &iwe, IW_EV_FREQ_LEN);
  1658. }
  1659. /* Add quality statistics. level and noise in dB. No link quality */
  1660. iwe.cmd = IWEVQUAL;
  1661. iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
  1662. iwe.u.qual.level = bss->level - 0x95;
  1663. iwe.u.qual.noise = bss->noise - 0x95;
  1664. /* Wireless tools prior to 27.pre22 will show link quality
  1665. * anyway, so we provide a reasonable value. */
  1666. if (iwe.u.qual.level > iwe.u.qual.noise)
  1667. iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
  1668. else
  1669. iwe.u.qual.qual = 0;
  1670. current_ev = iwe_stream_add_event(info, current_ev, end_buf,
  1671. &iwe, IW_EV_QUAL_LEN);
  1672. /* Add encryption capability */
  1673. iwe.cmd = SIOCGIWENCODE;
  1674. if (capabilities & WLAN_CAPABILITY_PRIVACY)
  1675. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1676. else
  1677. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1678. iwe.u.data.length = 0;
  1679. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1680. &iwe, NULL);
  1681. /* WPA IE */
  1682. ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
  1683. if (ie) {
  1684. iwe.cmd = IWEVGENIE;
  1685. iwe.u.data.length = ie[1] + 2;
  1686. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1687. &iwe, ie);
  1688. }
  1689. /* RSN IE */
  1690. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
  1691. if (ie) {
  1692. iwe.cmd = IWEVGENIE;
  1693. iwe.u.data.length = ie[1] + 2;
  1694. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1695. &iwe, ie);
  1696. }
  1697. ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
  1698. if (ie) {
  1699. char *p = current_ev + iwe_stream_lcp_len(info);
  1700. int i;
  1701. iwe.cmd = SIOCGIWRATE;
  1702. /* Those two flags are ignored... */
  1703. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  1704. for (i = 2; i < (ie[1] + 2); i++) {
  1705. iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
  1706. p = iwe_stream_add_value(info, current_ev, p, end_buf,
  1707. &iwe, IW_EV_PARAM_LEN);
  1708. }
  1709. /* Check if we added any event */
  1710. if (p > (current_ev + iwe_stream_lcp_len(info)))
  1711. current_ev = p;
  1712. }
  1713. /* Timestamp */
  1714. iwe.cmd = IWEVCUSTOM;
  1715. iwe.u.data.length =
  1716. snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
  1717. (unsigned long long) le64_to_cpu(bss->timestamp));
  1718. if (iwe.u.data.length)
  1719. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1720. &iwe, custom);
  1721. /* Beacon interval */
  1722. iwe.cmd = IWEVCUSTOM;
  1723. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1724. "bcn_int=%d",
  1725. le16_to_cpu(bss->beacon_interval));
  1726. if (iwe.u.data.length)
  1727. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1728. &iwe, custom);
  1729. /* Capabilites */
  1730. iwe.cmd = IWEVCUSTOM;
  1731. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1732. "capab=0x%04x",
  1733. capabilities);
  1734. if (iwe.u.data.length)
  1735. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1736. &iwe, custom);
  1737. /* Add EXTRA: Age to display seconds since last beacon/probe response
  1738. * for given network. */
  1739. iwe.cmd = IWEVCUSTOM;
  1740. iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
  1741. " Last beacon: %dms ago",
  1742. jiffies_to_msecs(jiffies - last_scanned));
  1743. if (iwe.u.data.length)
  1744. current_ev = iwe_stream_add_point(info, current_ev, end_buf,
  1745. &iwe, custom);
  1746. return current_ev;
  1747. }
  1748. /* Return results of a scan */
  1749. static int orinoco_ioctl_getscan(struct net_device *dev,
  1750. struct iw_request_info *info,
  1751. struct iw_point *srq,
  1752. char *extra)
  1753. {
  1754. struct orinoco_private *priv = netdev_priv(dev);
  1755. int err = 0;
  1756. unsigned long flags;
  1757. char *current_ev = extra;
  1758. if (orinoco_lock(priv, &flags) != 0)
  1759. return -EBUSY;
  1760. if (priv->scan_inprogress) {
  1761. /* Important note : we don't want to block the caller
  1762. * until results are ready for various reasons.
  1763. * First, managing wait queues is complex and racy.
  1764. * Second, we grab some rtnetlink lock before comming
  1765. * here (in dev_ioctl()).
  1766. * Third, we generate an Wireless Event, so the
  1767. * caller can wait itself on that - Jean II */
  1768. err = -EAGAIN;
  1769. goto out;
  1770. }
  1771. if (priv->has_ext_scan) {
  1772. struct xbss_element *bss;
  1773. list_for_each_entry(bss, &priv->bss_list, list) {
  1774. /* Translate this entry to WE format */
  1775. current_ev =
  1776. orinoco_translate_ext_scan(dev, info,
  1777. current_ev,
  1778. extra + srq->length,
  1779. &bss->bss,
  1780. bss->last_scanned);
  1781. /* Check if there is space for one more entry */
  1782. if ((extra + srq->length - current_ev)
  1783. <= IW_EV_ADDR_LEN) {
  1784. /* Ask user space to try again with a
  1785. * bigger buffer */
  1786. err = -E2BIG;
  1787. goto out;
  1788. }
  1789. }
  1790. } else {
  1791. struct bss_element *bss;
  1792. list_for_each_entry(bss, &priv->bss_list, list) {
  1793. /* Translate this entry to WE format */
  1794. current_ev = orinoco_translate_scan(dev, info,
  1795. current_ev,
  1796. extra + srq->length,
  1797. &bss->bss,
  1798. bss->last_scanned);
  1799. /* Check if there is space for one more entry */
  1800. if ((extra + srq->length - current_ev)
  1801. <= IW_EV_ADDR_LEN) {
  1802. /* Ask user space to try again with a
  1803. * bigger buffer */
  1804. err = -E2BIG;
  1805. goto out;
  1806. }
  1807. }
  1808. }
  1809. srq->length = (current_ev - extra);
  1810. srq->flags = (__u16) priv->scan_mode;
  1811. out:
  1812. orinoco_unlock(priv, &flags);
  1813. return err;
  1814. }
  1815. /* Commit handler, called after set operations */
  1816. static int orinoco_ioctl_commit(struct net_device *dev,
  1817. struct iw_request_info *info,
  1818. void *wrqu,
  1819. char *extra)
  1820. {
  1821. struct orinoco_private *priv = netdev_priv(dev);
  1822. struct hermes *hw = &priv->hw;
  1823. unsigned long flags;
  1824. int err = 0;
  1825. if (!priv->open)
  1826. return 0;
  1827. if (priv->broken_disableport) {
  1828. orinoco_reset(&priv->reset_work);
  1829. return 0;
  1830. }
  1831. if (orinoco_lock(priv, &flags) != 0)
  1832. return err;
  1833. err = hermes_disable_port(hw, 0);
  1834. if (err) {
  1835. printk(KERN_WARNING "%s: Unable to disable port "
  1836. "while reconfiguring card\n", dev->name);
  1837. priv->broken_disableport = 1;
  1838. goto out;
  1839. }
  1840. err = __orinoco_program_rids(dev);
  1841. if (err) {
  1842. printk(KERN_WARNING "%s: Unable to reconfigure card\n",
  1843. dev->name);
  1844. goto out;
  1845. }
  1846. err = hermes_enable_port(hw, 0);
  1847. if (err) {
  1848. printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
  1849. dev->name);
  1850. goto out;
  1851. }
  1852. out:
  1853. if (err) {
  1854. printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
  1855. schedule_work(&priv->reset_work);
  1856. err = 0;
  1857. }
  1858. orinoco_unlock(priv, &flags);
  1859. return err;
  1860. }
  1861. static const struct iw_priv_args orinoco_privtab[] = {
  1862. { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
  1863. { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
  1864. { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1865. 0, "set_port3" },
  1866. { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1867. "get_port3" },
  1868. { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1869. 0, "set_preamble" },
  1870. { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1871. "get_preamble" },
  1872. { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1873. 0, "set_ibssport" },
  1874. { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1875. "get_ibssport" },
  1876. { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
  1877. "get_rid" },
  1878. };
  1879. /*
  1880. * Structures to export the Wireless Handlers
  1881. */
  1882. #define STD_IW_HANDLER(id, func) \
  1883. [IW_IOCTL_IDX(id)] = (iw_handler) func
  1884. static const iw_handler orinoco_handler[] = {
  1885. STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
  1886. STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
  1887. STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
  1888. STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
  1889. STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
  1890. STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
  1891. STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
  1892. STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
  1893. STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
  1894. STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
  1895. STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
  1896. STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
  1897. STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
  1898. STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
  1899. STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
  1900. STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
  1901. STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
  1902. STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
  1903. STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
  1904. STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
  1905. STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
  1906. STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
  1907. STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
  1908. STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
  1909. STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
  1910. STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
  1911. STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
  1912. STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
  1913. STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
  1914. STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
  1915. STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
  1916. STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
  1917. STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
  1918. STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
  1919. STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
  1920. STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
  1921. STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
  1922. STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
  1923. STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
  1924. };
  1925. /*
  1926. Added typecasting since we no longer use iwreq_data -- Moustafa
  1927. */
  1928. static const iw_handler orinoco_private_handler[] = {
  1929. [0] = (iw_handler) orinoco_ioctl_reset,
  1930. [1] = (iw_handler) orinoco_ioctl_reset,
  1931. [2] = (iw_handler) orinoco_ioctl_setport3,
  1932. [3] = (iw_handler) orinoco_ioctl_getport3,
  1933. [4] = (iw_handler) orinoco_ioctl_setpreamble,
  1934. [5] = (iw_handler) orinoco_ioctl_getpreamble,
  1935. [6] = (iw_handler) orinoco_ioctl_setibssport,
  1936. [7] = (iw_handler) orinoco_ioctl_getibssport,
  1937. [9] = (iw_handler) orinoco_ioctl_getrid,
  1938. };
  1939. const struct iw_handler_def orinoco_handler_def = {
  1940. .num_standard = ARRAY_SIZE(orinoco_handler),
  1941. .num_private = ARRAY_SIZE(orinoco_private_handler),
  1942. .num_private_args = ARRAY_SIZE(orinoco_privtab),
  1943. .standard = orinoco_handler,
  1944. .private = orinoco_private_handler,
  1945. .private_args = orinoco_privtab,
  1946. .get_wireless_stats = orinoco_get_wireless_stats,
  1947. };