wext.c 57 KB

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