wext.c 37 KB

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