wext-compat.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. /*
  2. * cfg80211 - wext compat code
  3. *
  4. * This is temporary code until all wireless functionality is migrated
  5. * into cfg80211, when that happens all the exports here go away and
  6. * we directly assign the wireless handlers of wireless interfaces.
  7. *
  8. * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
  9. */
  10. #include <linux/wireless.h>
  11. #include <linux/nl80211.h>
  12. #include <linux/if_arp.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/slab.h>
  15. #include <net/iw_handler.h>
  16. #include <net/cfg80211.h>
  17. #include "wext-compat.h"
  18. #include "core.h"
  19. int cfg80211_wext_giwname(struct net_device *dev,
  20. struct iw_request_info *info,
  21. char *name, char *extra)
  22. {
  23. struct wireless_dev *wdev = dev->ieee80211_ptr;
  24. struct ieee80211_supported_band *sband;
  25. bool is_ht = false, is_a = false, is_b = false, is_g = false;
  26. if (!wdev)
  27. return -EOPNOTSUPP;
  28. sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
  29. if (sband) {
  30. is_a = true;
  31. is_ht |= sband->ht_cap.ht_supported;
  32. }
  33. sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
  34. if (sband) {
  35. int i;
  36. /* Check for mandatory rates */
  37. for (i = 0; i < sband->n_bitrates; i++) {
  38. if (sband->bitrates[i].bitrate == 10)
  39. is_b = true;
  40. if (sband->bitrates[i].bitrate == 60)
  41. is_g = true;
  42. }
  43. is_ht |= sband->ht_cap.ht_supported;
  44. }
  45. strcpy(name, "IEEE 802.11");
  46. if (is_a)
  47. strcat(name, "a");
  48. if (is_b)
  49. strcat(name, "b");
  50. if (is_g)
  51. strcat(name, "g");
  52. if (is_ht)
  53. strcat(name, "n");
  54. return 0;
  55. }
  56. EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
  57. int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
  58. u32 *mode, char *extra)
  59. {
  60. struct wireless_dev *wdev = dev->ieee80211_ptr;
  61. struct cfg80211_registered_device *rdev;
  62. struct vif_params vifparams;
  63. enum nl80211_iftype type;
  64. int ret;
  65. rdev = wiphy_to_dev(wdev->wiphy);
  66. switch (*mode) {
  67. case IW_MODE_INFRA:
  68. type = NL80211_IFTYPE_STATION;
  69. break;
  70. case IW_MODE_ADHOC:
  71. type = NL80211_IFTYPE_ADHOC;
  72. break;
  73. case IW_MODE_REPEAT:
  74. type = NL80211_IFTYPE_WDS;
  75. break;
  76. case IW_MODE_MONITOR:
  77. type = NL80211_IFTYPE_MONITOR;
  78. break;
  79. default:
  80. return -EINVAL;
  81. }
  82. if (type == wdev->iftype)
  83. return 0;
  84. memset(&vifparams, 0, sizeof(vifparams));
  85. cfg80211_lock_rdev(rdev);
  86. ret = cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
  87. cfg80211_unlock_rdev(rdev);
  88. return ret;
  89. }
  90. EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
  91. int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
  92. u32 *mode, char *extra)
  93. {
  94. struct wireless_dev *wdev = dev->ieee80211_ptr;
  95. if (!wdev)
  96. return -EOPNOTSUPP;
  97. switch (wdev->iftype) {
  98. case NL80211_IFTYPE_AP:
  99. *mode = IW_MODE_MASTER;
  100. break;
  101. case NL80211_IFTYPE_STATION:
  102. *mode = IW_MODE_INFRA;
  103. break;
  104. case NL80211_IFTYPE_ADHOC:
  105. *mode = IW_MODE_ADHOC;
  106. break;
  107. case NL80211_IFTYPE_MONITOR:
  108. *mode = IW_MODE_MONITOR;
  109. break;
  110. case NL80211_IFTYPE_WDS:
  111. *mode = IW_MODE_REPEAT;
  112. break;
  113. case NL80211_IFTYPE_AP_VLAN:
  114. *mode = IW_MODE_SECOND; /* FIXME */
  115. break;
  116. default:
  117. *mode = IW_MODE_AUTO;
  118. break;
  119. }
  120. return 0;
  121. }
  122. EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
  123. int cfg80211_wext_giwrange(struct net_device *dev,
  124. struct iw_request_info *info,
  125. struct iw_point *data, char *extra)
  126. {
  127. struct wireless_dev *wdev = dev->ieee80211_ptr;
  128. struct iw_range *range = (struct iw_range *) extra;
  129. enum ieee80211_band band;
  130. int i, c = 0;
  131. if (!wdev)
  132. return -EOPNOTSUPP;
  133. data->length = sizeof(struct iw_range);
  134. memset(range, 0, sizeof(struct iw_range));
  135. range->we_version_compiled = WIRELESS_EXT;
  136. range->we_version_source = 21;
  137. range->retry_capa = IW_RETRY_LIMIT;
  138. range->retry_flags = IW_RETRY_LIMIT;
  139. range->min_retry = 0;
  140. range->max_retry = 255;
  141. range->min_rts = 0;
  142. range->max_rts = 2347;
  143. range->min_frag = 256;
  144. range->max_frag = 2346;
  145. range->max_encoding_tokens = 4;
  146. range->max_qual.updated = IW_QUAL_NOISE_INVALID;
  147. switch (wdev->wiphy->signal_type) {
  148. case CFG80211_SIGNAL_TYPE_NONE:
  149. break;
  150. case CFG80211_SIGNAL_TYPE_MBM:
  151. range->max_qual.level = -110;
  152. range->max_qual.qual = 70;
  153. range->avg_qual.qual = 35;
  154. range->max_qual.updated |= IW_QUAL_DBM;
  155. range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
  156. range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
  157. break;
  158. case CFG80211_SIGNAL_TYPE_UNSPEC:
  159. range->max_qual.level = 100;
  160. range->max_qual.qual = 100;
  161. range->avg_qual.qual = 50;
  162. range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
  163. range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
  164. break;
  165. }
  166. range->avg_qual.level = range->max_qual.level / 2;
  167. range->avg_qual.noise = range->max_qual.noise / 2;
  168. range->avg_qual.updated = range->max_qual.updated;
  169. for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
  170. switch (wdev->wiphy->cipher_suites[i]) {
  171. case WLAN_CIPHER_SUITE_TKIP:
  172. range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
  173. IW_ENC_CAPA_WPA);
  174. break;
  175. case WLAN_CIPHER_SUITE_CCMP:
  176. range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
  177. IW_ENC_CAPA_WPA2);
  178. break;
  179. case WLAN_CIPHER_SUITE_WEP40:
  180. range->encoding_size[range->num_encoding_sizes++] =
  181. WLAN_KEY_LEN_WEP40;
  182. break;
  183. case WLAN_CIPHER_SUITE_WEP104:
  184. range->encoding_size[range->num_encoding_sizes++] =
  185. WLAN_KEY_LEN_WEP104;
  186. break;
  187. }
  188. }
  189. for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
  190. struct ieee80211_supported_band *sband;
  191. sband = wdev->wiphy->bands[band];
  192. if (!sband)
  193. continue;
  194. for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
  195. struct ieee80211_channel *chan = &sband->channels[i];
  196. if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
  197. range->freq[c].i =
  198. ieee80211_frequency_to_channel(
  199. chan->center_freq);
  200. range->freq[c].m = chan->center_freq;
  201. range->freq[c].e = 6;
  202. c++;
  203. }
  204. }
  205. }
  206. range->num_channels = c;
  207. range->num_frequency = c;
  208. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  209. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  210. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  211. if (wdev->wiphy->max_scan_ssids > 0)
  212. range->scan_capa |= IW_SCAN_CAPA_ESSID;
  213. return 0;
  214. }
  215. EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
  216. /**
  217. * cfg80211_wext_freq - get wext frequency for non-"auto"
  218. * @wiphy: the wiphy
  219. * @freq: the wext freq encoding
  220. *
  221. * Returns a frequency, or a negative error code, or 0 for auto.
  222. */
  223. int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
  224. {
  225. /*
  226. * Parse frequency - return 0 for auto and
  227. * -EINVAL for impossible things.
  228. */
  229. if (freq->e == 0) {
  230. enum ieee80211_band band = IEEE80211_BAND_2GHZ;
  231. if (freq->m < 0)
  232. return 0;
  233. if (freq->m > 14)
  234. band = IEEE80211_BAND_5GHZ;
  235. return ieee80211_channel_to_frequency(freq->m, band);
  236. } else {
  237. int i, div = 1000000;
  238. for (i = 0; i < freq->e; i++)
  239. div /= 10;
  240. if (div <= 0)
  241. return -EINVAL;
  242. return freq->m / div;
  243. }
  244. }
  245. int cfg80211_wext_siwrts(struct net_device *dev,
  246. struct iw_request_info *info,
  247. struct iw_param *rts, char *extra)
  248. {
  249. struct wireless_dev *wdev = dev->ieee80211_ptr;
  250. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  251. u32 orts = wdev->wiphy->rts_threshold;
  252. int err;
  253. if (rts->disabled || !rts->fixed)
  254. wdev->wiphy->rts_threshold = (u32) -1;
  255. else if (rts->value < 0)
  256. return -EINVAL;
  257. else
  258. wdev->wiphy->rts_threshold = rts->value;
  259. err = rdev->ops->set_wiphy_params(wdev->wiphy,
  260. WIPHY_PARAM_RTS_THRESHOLD);
  261. if (err)
  262. wdev->wiphy->rts_threshold = orts;
  263. return err;
  264. }
  265. EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
  266. int cfg80211_wext_giwrts(struct net_device *dev,
  267. struct iw_request_info *info,
  268. struct iw_param *rts, char *extra)
  269. {
  270. struct wireless_dev *wdev = dev->ieee80211_ptr;
  271. rts->value = wdev->wiphy->rts_threshold;
  272. rts->disabled = rts->value == (u32) -1;
  273. rts->fixed = 1;
  274. return 0;
  275. }
  276. EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
  277. int cfg80211_wext_siwfrag(struct net_device *dev,
  278. struct iw_request_info *info,
  279. struct iw_param *frag, char *extra)
  280. {
  281. struct wireless_dev *wdev = dev->ieee80211_ptr;
  282. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  283. u32 ofrag = wdev->wiphy->frag_threshold;
  284. int err;
  285. if (frag->disabled || !frag->fixed)
  286. wdev->wiphy->frag_threshold = (u32) -1;
  287. else if (frag->value < 256)
  288. return -EINVAL;
  289. else {
  290. /* Fragment length must be even, so strip LSB. */
  291. wdev->wiphy->frag_threshold = frag->value & ~0x1;
  292. }
  293. err = rdev->ops->set_wiphy_params(wdev->wiphy,
  294. WIPHY_PARAM_FRAG_THRESHOLD);
  295. if (err)
  296. wdev->wiphy->frag_threshold = ofrag;
  297. return err;
  298. }
  299. EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
  300. int cfg80211_wext_giwfrag(struct net_device *dev,
  301. struct iw_request_info *info,
  302. struct iw_param *frag, char *extra)
  303. {
  304. struct wireless_dev *wdev = dev->ieee80211_ptr;
  305. frag->value = wdev->wiphy->frag_threshold;
  306. frag->disabled = frag->value == (u32) -1;
  307. frag->fixed = 1;
  308. return 0;
  309. }
  310. EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
  311. int cfg80211_wext_siwretry(struct net_device *dev,
  312. struct iw_request_info *info,
  313. struct iw_param *retry, char *extra)
  314. {
  315. struct wireless_dev *wdev = dev->ieee80211_ptr;
  316. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  317. u32 changed = 0;
  318. u8 olong = wdev->wiphy->retry_long;
  319. u8 oshort = wdev->wiphy->retry_short;
  320. int err;
  321. if (retry->disabled ||
  322. (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
  323. return -EINVAL;
  324. if (retry->flags & IW_RETRY_LONG) {
  325. wdev->wiphy->retry_long = retry->value;
  326. changed |= WIPHY_PARAM_RETRY_LONG;
  327. } else if (retry->flags & IW_RETRY_SHORT) {
  328. wdev->wiphy->retry_short = retry->value;
  329. changed |= WIPHY_PARAM_RETRY_SHORT;
  330. } else {
  331. wdev->wiphy->retry_short = retry->value;
  332. wdev->wiphy->retry_long = retry->value;
  333. changed |= WIPHY_PARAM_RETRY_LONG;
  334. changed |= WIPHY_PARAM_RETRY_SHORT;
  335. }
  336. if (!changed)
  337. return 0;
  338. err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
  339. if (err) {
  340. wdev->wiphy->retry_short = oshort;
  341. wdev->wiphy->retry_long = olong;
  342. }
  343. return err;
  344. }
  345. EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
  346. int cfg80211_wext_giwretry(struct net_device *dev,
  347. struct iw_request_info *info,
  348. struct iw_param *retry, char *extra)
  349. {
  350. struct wireless_dev *wdev = dev->ieee80211_ptr;
  351. retry->disabled = 0;
  352. if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
  353. /*
  354. * First return short value, iwconfig will ask long value
  355. * later if needed
  356. */
  357. retry->flags |= IW_RETRY_LIMIT;
  358. retry->value = wdev->wiphy->retry_short;
  359. if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
  360. retry->flags |= IW_RETRY_LONG;
  361. return 0;
  362. }
  363. if (retry->flags & IW_RETRY_LONG) {
  364. retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  365. retry->value = wdev->wiphy->retry_long;
  366. }
  367. return 0;
  368. }
  369. EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
  370. static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
  371. struct net_device *dev, bool pairwise,
  372. const u8 *addr, bool remove, bool tx_key,
  373. int idx, struct key_params *params)
  374. {
  375. struct wireless_dev *wdev = dev->ieee80211_ptr;
  376. int err, i;
  377. bool rejoin = false;
  378. if (pairwise && !addr)
  379. return -EINVAL;
  380. if (!wdev->wext.keys) {
  381. wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
  382. GFP_KERNEL);
  383. if (!wdev->wext.keys)
  384. return -ENOMEM;
  385. for (i = 0; i < 6; i++)
  386. wdev->wext.keys->params[i].key =
  387. wdev->wext.keys->data[i];
  388. }
  389. if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
  390. wdev->iftype != NL80211_IFTYPE_STATION)
  391. return -EOPNOTSUPP;
  392. if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
  393. if (!wdev->current_bss)
  394. return -ENOLINK;
  395. if (!rdev->ops->set_default_mgmt_key)
  396. return -EOPNOTSUPP;
  397. if (idx < 4 || idx > 5)
  398. return -EINVAL;
  399. } else if (idx < 0 || idx > 3)
  400. return -EINVAL;
  401. if (remove) {
  402. err = 0;
  403. if (wdev->current_bss) {
  404. /*
  405. * If removing the current TX key, we will need to
  406. * join a new IBSS without the privacy bit clear.
  407. */
  408. if (idx == wdev->wext.default_key &&
  409. wdev->iftype == NL80211_IFTYPE_ADHOC) {
  410. __cfg80211_leave_ibss(rdev, wdev->netdev, true);
  411. rejoin = true;
  412. }
  413. if (!pairwise && addr &&
  414. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  415. err = -ENOENT;
  416. else
  417. err = rdev->ops->del_key(&rdev->wiphy, dev, idx,
  418. pairwise, addr);
  419. }
  420. wdev->wext.connect.privacy = false;
  421. /*
  422. * Applications using wireless extensions expect to be
  423. * able to delete keys that don't exist, so allow that.
  424. */
  425. if (err == -ENOENT)
  426. err = 0;
  427. if (!err) {
  428. if (!addr) {
  429. wdev->wext.keys->params[idx].key_len = 0;
  430. wdev->wext.keys->params[idx].cipher = 0;
  431. }
  432. if (idx == wdev->wext.default_key)
  433. wdev->wext.default_key = -1;
  434. else if (idx == wdev->wext.default_mgmt_key)
  435. wdev->wext.default_mgmt_key = -1;
  436. }
  437. if (!err && rejoin)
  438. err = cfg80211_ibss_wext_join(rdev, wdev);
  439. return err;
  440. }
  441. if (addr)
  442. tx_key = false;
  443. if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
  444. return -EINVAL;
  445. err = 0;
  446. if (wdev->current_bss)
  447. err = rdev->ops->add_key(&rdev->wiphy, dev, idx,
  448. pairwise, addr, params);
  449. if (err)
  450. return err;
  451. if (!addr) {
  452. wdev->wext.keys->params[idx] = *params;
  453. memcpy(wdev->wext.keys->data[idx],
  454. params->key, params->key_len);
  455. wdev->wext.keys->params[idx].key =
  456. wdev->wext.keys->data[idx];
  457. }
  458. if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  459. params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  460. (tx_key || (!addr && wdev->wext.default_key == -1))) {
  461. if (wdev->current_bss) {
  462. /*
  463. * If we are getting a new TX key from not having
  464. * had one before we need to join a new IBSS with
  465. * the privacy bit set.
  466. */
  467. if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
  468. wdev->wext.default_key == -1) {
  469. __cfg80211_leave_ibss(rdev, wdev->netdev, true);
  470. rejoin = true;
  471. }
  472. err = rdev->ops->set_default_key(&rdev->wiphy, dev,
  473. idx, true, true);
  474. }
  475. if (!err) {
  476. wdev->wext.default_key = idx;
  477. if (rejoin)
  478. err = cfg80211_ibss_wext_join(rdev, wdev);
  479. }
  480. return err;
  481. }
  482. if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
  483. (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
  484. if (wdev->current_bss)
  485. err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
  486. dev, idx);
  487. if (!err)
  488. wdev->wext.default_mgmt_key = idx;
  489. return err;
  490. }
  491. return 0;
  492. }
  493. static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
  494. struct net_device *dev, bool pairwise,
  495. const u8 *addr, bool remove, bool tx_key,
  496. int idx, struct key_params *params)
  497. {
  498. int err;
  499. /* devlist mutex needed for possible IBSS re-join */
  500. mutex_lock(&rdev->devlist_mtx);
  501. wdev_lock(dev->ieee80211_ptr);
  502. err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
  503. remove, tx_key, idx, params);
  504. wdev_unlock(dev->ieee80211_ptr);
  505. mutex_unlock(&rdev->devlist_mtx);
  506. return err;
  507. }
  508. int cfg80211_wext_siwencode(struct net_device *dev,
  509. struct iw_request_info *info,
  510. struct iw_point *erq, char *keybuf)
  511. {
  512. struct wireless_dev *wdev = dev->ieee80211_ptr;
  513. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  514. int idx, err;
  515. bool remove = false;
  516. struct key_params params;
  517. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  518. wdev->iftype != NL80211_IFTYPE_ADHOC)
  519. return -EOPNOTSUPP;
  520. /* no use -- only MFP (set_default_mgmt_key) is optional */
  521. if (!rdev->ops->del_key ||
  522. !rdev->ops->add_key ||
  523. !rdev->ops->set_default_key)
  524. return -EOPNOTSUPP;
  525. idx = erq->flags & IW_ENCODE_INDEX;
  526. if (idx == 0) {
  527. idx = wdev->wext.default_key;
  528. if (idx < 0)
  529. idx = 0;
  530. } else if (idx < 1 || idx > 4)
  531. return -EINVAL;
  532. else
  533. idx--;
  534. if (erq->flags & IW_ENCODE_DISABLED)
  535. remove = true;
  536. else if (erq->length == 0) {
  537. /* No key data - just set the default TX key index */
  538. err = 0;
  539. wdev_lock(wdev);
  540. if (wdev->current_bss)
  541. err = rdev->ops->set_default_key(&rdev->wiphy, dev,
  542. idx, true, true);
  543. if (!err)
  544. wdev->wext.default_key = idx;
  545. wdev_unlock(wdev);
  546. return err;
  547. }
  548. memset(&params, 0, sizeof(params));
  549. params.key = keybuf;
  550. params.key_len = erq->length;
  551. if (erq->length == 5)
  552. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  553. else if (erq->length == 13)
  554. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  555. else if (!remove)
  556. return -EINVAL;
  557. return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
  558. wdev->wext.default_key == -1,
  559. idx, &params);
  560. }
  561. EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
  562. int cfg80211_wext_siwencodeext(struct net_device *dev,
  563. struct iw_request_info *info,
  564. struct iw_point *erq, char *extra)
  565. {
  566. struct wireless_dev *wdev = dev->ieee80211_ptr;
  567. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  568. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  569. const u8 *addr;
  570. int idx;
  571. bool remove = false;
  572. struct key_params params;
  573. u32 cipher;
  574. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  575. wdev->iftype != NL80211_IFTYPE_ADHOC)
  576. return -EOPNOTSUPP;
  577. /* no use -- only MFP (set_default_mgmt_key) is optional */
  578. if (!rdev->ops->del_key ||
  579. !rdev->ops->add_key ||
  580. !rdev->ops->set_default_key)
  581. return -EOPNOTSUPP;
  582. switch (ext->alg) {
  583. case IW_ENCODE_ALG_NONE:
  584. remove = true;
  585. cipher = 0;
  586. break;
  587. case IW_ENCODE_ALG_WEP:
  588. if (ext->key_len == 5)
  589. cipher = WLAN_CIPHER_SUITE_WEP40;
  590. else if (ext->key_len == 13)
  591. cipher = WLAN_CIPHER_SUITE_WEP104;
  592. else
  593. return -EINVAL;
  594. break;
  595. case IW_ENCODE_ALG_TKIP:
  596. cipher = WLAN_CIPHER_SUITE_TKIP;
  597. break;
  598. case IW_ENCODE_ALG_CCMP:
  599. cipher = WLAN_CIPHER_SUITE_CCMP;
  600. break;
  601. case IW_ENCODE_ALG_AES_CMAC:
  602. cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  603. break;
  604. default:
  605. return -EOPNOTSUPP;
  606. }
  607. if (erq->flags & IW_ENCODE_DISABLED)
  608. remove = true;
  609. idx = erq->flags & IW_ENCODE_INDEX;
  610. if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
  611. if (idx < 4 || idx > 5) {
  612. idx = wdev->wext.default_mgmt_key;
  613. if (idx < 0)
  614. return -EINVAL;
  615. } else
  616. idx--;
  617. } else {
  618. if (idx < 1 || idx > 4) {
  619. idx = wdev->wext.default_key;
  620. if (idx < 0)
  621. return -EINVAL;
  622. } else
  623. idx--;
  624. }
  625. addr = ext->addr.sa_data;
  626. if (is_broadcast_ether_addr(addr))
  627. addr = NULL;
  628. memset(&params, 0, sizeof(params));
  629. params.key = ext->key;
  630. params.key_len = ext->key_len;
  631. params.cipher = cipher;
  632. if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  633. params.seq = ext->rx_seq;
  634. params.seq_len = 6;
  635. }
  636. return cfg80211_set_encryption(
  637. rdev, dev,
  638. !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
  639. addr, remove,
  640. ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
  641. idx, &params);
  642. }
  643. EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
  644. int cfg80211_wext_giwencode(struct net_device *dev,
  645. struct iw_request_info *info,
  646. struct iw_point *erq, char *keybuf)
  647. {
  648. struct wireless_dev *wdev = dev->ieee80211_ptr;
  649. int idx;
  650. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  651. wdev->iftype != NL80211_IFTYPE_ADHOC)
  652. return -EOPNOTSUPP;
  653. idx = erq->flags & IW_ENCODE_INDEX;
  654. if (idx == 0) {
  655. idx = wdev->wext.default_key;
  656. if (idx < 0)
  657. idx = 0;
  658. } else if (idx < 1 || idx > 4)
  659. return -EINVAL;
  660. else
  661. idx--;
  662. erq->flags = idx + 1;
  663. if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
  664. erq->flags |= IW_ENCODE_DISABLED;
  665. erq->length = 0;
  666. return 0;
  667. }
  668. erq->length = min_t(size_t, erq->length,
  669. wdev->wext.keys->params[idx].key_len);
  670. memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
  671. erq->flags |= IW_ENCODE_ENABLED;
  672. return 0;
  673. }
  674. EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);
  675. int cfg80211_wext_siwfreq(struct net_device *dev,
  676. struct iw_request_info *info,
  677. struct iw_freq *wextfreq, char *extra)
  678. {
  679. struct wireless_dev *wdev = dev->ieee80211_ptr;
  680. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  681. int freq, err;
  682. switch (wdev->iftype) {
  683. case NL80211_IFTYPE_STATION:
  684. return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
  685. case NL80211_IFTYPE_ADHOC:
  686. return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
  687. case NL80211_IFTYPE_MONITOR:
  688. case NL80211_IFTYPE_WDS:
  689. case NL80211_IFTYPE_MESH_POINT:
  690. freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
  691. if (freq < 0)
  692. return freq;
  693. if (freq == 0)
  694. return -EINVAL;
  695. mutex_lock(&rdev->devlist_mtx);
  696. wdev_lock(wdev);
  697. err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
  698. wdev_unlock(wdev);
  699. mutex_unlock(&rdev->devlist_mtx);
  700. return err;
  701. default:
  702. return -EOPNOTSUPP;
  703. }
  704. }
  705. EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq);
  706. int cfg80211_wext_giwfreq(struct net_device *dev,
  707. struct iw_request_info *info,
  708. struct iw_freq *freq, char *extra)
  709. {
  710. struct wireless_dev *wdev = dev->ieee80211_ptr;
  711. switch (wdev->iftype) {
  712. case NL80211_IFTYPE_STATION:
  713. return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
  714. case NL80211_IFTYPE_ADHOC:
  715. return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
  716. default:
  717. if (!wdev->channel)
  718. return -EINVAL;
  719. freq->m = wdev->channel->center_freq;
  720. freq->e = 6;
  721. return 0;
  722. }
  723. }
  724. EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq);
  725. int cfg80211_wext_siwtxpower(struct net_device *dev,
  726. struct iw_request_info *info,
  727. union iwreq_data *data, char *extra)
  728. {
  729. struct wireless_dev *wdev = dev->ieee80211_ptr;
  730. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  731. enum nl80211_tx_power_setting type;
  732. int dbm = 0;
  733. if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  734. return -EINVAL;
  735. if (data->txpower.flags & IW_TXPOW_RANGE)
  736. return -EINVAL;
  737. if (!rdev->ops->set_tx_power)
  738. return -EOPNOTSUPP;
  739. /* only change when not disabling */
  740. if (!data->txpower.disabled) {
  741. rfkill_set_sw_state(rdev->rfkill, false);
  742. if (data->txpower.fixed) {
  743. /*
  744. * wext doesn't support negative values, see
  745. * below where it's for automatic
  746. */
  747. if (data->txpower.value < 0)
  748. return -EINVAL;
  749. dbm = data->txpower.value;
  750. type = NL80211_TX_POWER_FIXED;
  751. /* TODO: do regulatory check! */
  752. } else {
  753. /*
  754. * Automatic power level setting, max being the value
  755. * passed in from userland.
  756. */
  757. if (data->txpower.value < 0) {
  758. type = NL80211_TX_POWER_AUTOMATIC;
  759. } else {
  760. dbm = data->txpower.value;
  761. type = NL80211_TX_POWER_LIMITED;
  762. }
  763. }
  764. } else {
  765. rfkill_set_sw_state(rdev->rfkill, true);
  766. schedule_work(&rdev->rfkill_sync);
  767. return 0;
  768. }
  769. return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
  770. }
  771. EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
  772. int cfg80211_wext_giwtxpower(struct net_device *dev,
  773. struct iw_request_info *info,
  774. union iwreq_data *data, char *extra)
  775. {
  776. struct wireless_dev *wdev = dev->ieee80211_ptr;
  777. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  778. int err, val;
  779. if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  780. return -EINVAL;
  781. if (data->txpower.flags & IW_TXPOW_RANGE)
  782. return -EINVAL;
  783. if (!rdev->ops->get_tx_power)
  784. return -EOPNOTSUPP;
  785. err = rdev->ops->get_tx_power(wdev->wiphy, &val);
  786. if (err)
  787. return err;
  788. /* well... oh well */
  789. data->txpower.fixed = 1;
  790. data->txpower.disabled = rfkill_blocked(rdev->rfkill);
  791. data->txpower.value = val;
  792. data->txpower.flags = IW_TXPOW_DBM;
  793. return 0;
  794. }
  795. EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
  796. static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
  797. s32 auth_alg)
  798. {
  799. int nr_alg = 0;
  800. if (!auth_alg)
  801. return -EINVAL;
  802. if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
  803. IW_AUTH_ALG_SHARED_KEY |
  804. IW_AUTH_ALG_LEAP))
  805. return -EINVAL;
  806. if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
  807. nr_alg++;
  808. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  809. }
  810. if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
  811. nr_alg++;
  812. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
  813. }
  814. if (auth_alg & IW_AUTH_ALG_LEAP) {
  815. nr_alg++;
  816. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
  817. }
  818. if (nr_alg > 1)
  819. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  820. return 0;
  821. }
  822. static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
  823. {
  824. if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
  825. IW_AUTH_WPA_VERSION_WPA2|
  826. IW_AUTH_WPA_VERSION_DISABLED))
  827. return -EINVAL;
  828. if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
  829. (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
  830. IW_AUTH_WPA_VERSION_WPA2)))
  831. return -EINVAL;
  832. if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
  833. wdev->wext.connect.crypto.wpa_versions &=
  834. ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
  835. if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
  836. wdev->wext.connect.crypto.wpa_versions |=
  837. NL80211_WPA_VERSION_1;
  838. if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
  839. wdev->wext.connect.crypto.wpa_versions |=
  840. NL80211_WPA_VERSION_2;
  841. return 0;
  842. }
  843. static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
  844. {
  845. if (cipher & IW_AUTH_CIPHER_WEP40)
  846. wdev->wext.connect.crypto.cipher_group =
  847. WLAN_CIPHER_SUITE_WEP40;
  848. else if (cipher & IW_AUTH_CIPHER_WEP104)
  849. wdev->wext.connect.crypto.cipher_group =
  850. WLAN_CIPHER_SUITE_WEP104;
  851. else if (cipher & IW_AUTH_CIPHER_TKIP)
  852. wdev->wext.connect.crypto.cipher_group =
  853. WLAN_CIPHER_SUITE_TKIP;
  854. else if (cipher & IW_AUTH_CIPHER_CCMP)
  855. wdev->wext.connect.crypto.cipher_group =
  856. WLAN_CIPHER_SUITE_CCMP;
  857. else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
  858. wdev->wext.connect.crypto.cipher_group =
  859. WLAN_CIPHER_SUITE_AES_CMAC;
  860. else if (cipher & IW_AUTH_CIPHER_NONE)
  861. wdev->wext.connect.crypto.cipher_group = 0;
  862. else
  863. return -EINVAL;
  864. return 0;
  865. }
  866. static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
  867. {
  868. int nr_ciphers = 0;
  869. u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
  870. if (cipher & IW_AUTH_CIPHER_WEP40) {
  871. ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
  872. nr_ciphers++;
  873. }
  874. if (cipher & IW_AUTH_CIPHER_WEP104) {
  875. ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
  876. nr_ciphers++;
  877. }
  878. if (cipher & IW_AUTH_CIPHER_TKIP) {
  879. ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
  880. nr_ciphers++;
  881. }
  882. if (cipher & IW_AUTH_CIPHER_CCMP) {
  883. ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
  884. nr_ciphers++;
  885. }
  886. if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
  887. ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
  888. nr_ciphers++;
  889. }
  890. BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
  891. wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
  892. return 0;
  893. }
  894. static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
  895. {
  896. int nr_akm_suites = 0;
  897. if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
  898. IW_AUTH_KEY_MGMT_PSK))
  899. return -EINVAL;
  900. if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
  901. wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
  902. WLAN_AKM_SUITE_8021X;
  903. nr_akm_suites++;
  904. }
  905. if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
  906. wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
  907. WLAN_AKM_SUITE_PSK;
  908. nr_akm_suites++;
  909. }
  910. wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
  911. return 0;
  912. }
  913. int cfg80211_wext_siwauth(struct net_device *dev,
  914. struct iw_request_info *info,
  915. struct iw_param *data, char *extra)
  916. {
  917. struct wireless_dev *wdev = dev->ieee80211_ptr;
  918. if (wdev->iftype != NL80211_IFTYPE_STATION)
  919. return -EOPNOTSUPP;
  920. switch (data->flags & IW_AUTH_INDEX) {
  921. case IW_AUTH_PRIVACY_INVOKED:
  922. wdev->wext.connect.privacy = data->value;
  923. return 0;
  924. case IW_AUTH_WPA_VERSION:
  925. return cfg80211_set_wpa_version(wdev, data->value);
  926. case IW_AUTH_CIPHER_GROUP:
  927. return cfg80211_set_cipher_group(wdev, data->value);
  928. case IW_AUTH_KEY_MGMT:
  929. return cfg80211_set_key_mgt(wdev, data->value);
  930. case IW_AUTH_CIPHER_PAIRWISE:
  931. return cfg80211_set_cipher_pairwise(wdev, data->value);
  932. case IW_AUTH_80211_AUTH_ALG:
  933. return cfg80211_set_auth_alg(wdev, data->value);
  934. case IW_AUTH_WPA_ENABLED:
  935. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  936. case IW_AUTH_DROP_UNENCRYPTED:
  937. case IW_AUTH_MFP:
  938. return 0;
  939. default:
  940. return -EOPNOTSUPP;
  941. }
  942. }
  943. EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
  944. int cfg80211_wext_giwauth(struct net_device *dev,
  945. struct iw_request_info *info,
  946. struct iw_param *data, char *extra)
  947. {
  948. /* XXX: what do we need? */
  949. return -EOPNOTSUPP;
  950. }
  951. EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
  952. int cfg80211_wext_siwpower(struct net_device *dev,
  953. struct iw_request_info *info,
  954. struct iw_param *wrq, char *extra)
  955. {
  956. struct wireless_dev *wdev = dev->ieee80211_ptr;
  957. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  958. bool ps = wdev->ps;
  959. int timeout = wdev->ps_timeout;
  960. int err;
  961. if (wdev->iftype != NL80211_IFTYPE_STATION)
  962. return -EINVAL;
  963. if (!rdev->ops->set_power_mgmt)
  964. return -EOPNOTSUPP;
  965. if (wrq->disabled) {
  966. ps = false;
  967. } else {
  968. switch (wrq->flags & IW_POWER_MODE) {
  969. case IW_POWER_ON: /* If not specified */
  970. case IW_POWER_MODE: /* If set all mask */
  971. case IW_POWER_ALL_R: /* If explicitely state all */
  972. ps = true;
  973. break;
  974. default: /* Otherwise we ignore */
  975. return -EINVAL;
  976. }
  977. if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
  978. return -EINVAL;
  979. if (wrq->flags & IW_POWER_TIMEOUT)
  980. timeout = wrq->value / 1000;
  981. }
  982. err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
  983. if (err)
  984. return err;
  985. wdev->ps = ps;
  986. wdev->ps_timeout = timeout;
  987. return 0;
  988. }
  989. EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
  990. int cfg80211_wext_giwpower(struct net_device *dev,
  991. struct iw_request_info *info,
  992. struct iw_param *wrq, char *extra)
  993. {
  994. struct wireless_dev *wdev = dev->ieee80211_ptr;
  995. wrq->disabled = !wdev->ps;
  996. return 0;
  997. }
  998. EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
  999. static int cfg80211_wds_wext_siwap(struct net_device *dev,
  1000. struct iw_request_info *info,
  1001. struct sockaddr *addr, char *extra)
  1002. {
  1003. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1004. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  1005. int err;
  1006. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
  1007. return -EINVAL;
  1008. if (addr->sa_family != ARPHRD_ETHER)
  1009. return -EINVAL;
  1010. if (netif_running(dev))
  1011. return -EBUSY;
  1012. if (!rdev->ops->set_wds_peer)
  1013. return -EOPNOTSUPP;
  1014. err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
  1015. if (err)
  1016. return err;
  1017. memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
  1018. return 0;
  1019. }
  1020. static int cfg80211_wds_wext_giwap(struct net_device *dev,
  1021. struct iw_request_info *info,
  1022. struct sockaddr *addr, char *extra)
  1023. {
  1024. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1025. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
  1026. return -EINVAL;
  1027. addr->sa_family = ARPHRD_ETHER;
  1028. memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
  1029. return 0;
  1030. }
  1031. int cfg80211_wext_siwrate(struct net_device *dev,
  1032. struct iw_request_info *info,
  1033. struct iw_param *rate, char *extra)
  1034. {
  1035. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1036. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  1037. struct cfg80211_bitrate_mask mask;
  1038. u32 fixed, maxrate;
  1039. struct ieee80211_supported_band *sband;
  1040. int band, ridx;
  1041. bool match = false;
  1042. if (!rdev->ops->set_bitrate_mask)
  1043. return -EOPNOTSUPP;
  1044. memset(&mask, 0, sizeof(mask));
  1045. fixed = 0;
  1046. maxrate = (u32)-1;
  1047. if (rate->value < 0) {
  1048. /* nothing */
  1049. } else if (rate->fixed) {
  1050. fixed = rate->value / 100000;
  1051. } else {
  1052. maxrate = rate->value / 100000;
  1053. }
  1054. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1055. sband = wdev->wiphy->bands[band];
  1056. if (sband == NULL)
  1057. continue;
  1058. for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
  1059. struct ieee80211_rate *srate = &sband->bitrates[ridx];
  1060. if (fixed == srate->bitrate) {
  1061. mask.control[band].legacy = 1 << ridx;
  1062. match = true;
  1063. break;
  1064. }
  1065. if (srate->bitrate <= maxrate) {
  1066. mask.control[band].legacy |= 1 << ridx;
  1067. match = true;
  1068. }
  1069. }
  1070. }
  1071. if (!match)
  1072. return -EINVAL;
  1073. return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
  1074. }
  1075. EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
  1076. int cfg80211_wext_giwrate(struct net_device *dev,
  1077. struct iw_request_info *info,
  1078. struct iw_param *rate, char *extra)
  1079. {
  1080. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1081. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  1082. /* we are under RTNL - globally locked - so can use a static struct */
  1083. static struct station_info sinfo;
  1084. u8 addr[ETH_ALEN];
  1085. int err;
  1086. if (wdev->iftype != NL80211_IFTYPE_STATION)
  1087. return -EOPNOTSUPP;
  1088. if (!rdev->ops->get_station)
  1089. return -EOPNOTSUPP;
  1090. err = 0;
  1091. wdev_lock(wdev);
  1092. if (wdev->current_bss)
  1093. memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
  1094. else
  1095. err = -EOPNOTSUPP;
  1096. wdev_unlock(wdev);
  1097. if (err)
  1098. return err;
  1099. err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
  1100. if (err)
  1101. return err;
  1102. if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
  1103. return -EOPNOTSUPP;
  1104. rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
  1105. return 0;
  1106. }
  1107. EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
  1108. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  1109. struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
  1110. {
  1111. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1112. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  1113. /* we are under RTNL - globally locked - so can use static structs */
  1114. static struct iw_statistics wstats;
  1115. static struct station_info sinfo;
  1116. u8 bssid[ETH_ALEN];
  1117. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
  1118. return NULL;
  1119. if (!rdev->ops->get_station)
  1120. return NULL;
  1121. /* Grab BSSID of current BSS, if any */
  1122. wdev_lock(wdev);
  1123. if (!wdev->current_bss) {
  1124. wdev_unlock(wdev);
  1125. return NULL;
  1126. }
  1127. memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
  1128. wdev_unlock(wdev);
  1129. if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo))
  1130. return NULL;
  1131. memset(&wstats, 0, sizeof(wstats));
  1132. switch (rdev->wiphy.signal_type) {
  1133. case CFG80211_SIGNAL_TYPE_MBM:
  1134. if (sinfo.filled & STATION_INFO_SIGNAL) {
  1135. int sig = sinfo.signal;
  1136. wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
  1137. wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
  1138. wstats.qual.updated |= IW_QUAL_DBM;
  1139. wstats.qual.level = sig;
  1140. if (sig < -110)
  1141. sig = -110;
  1142. else if (sig > -40)
  1143. sig = -40;
  1144. wstats.qual.qual = sig + 110;
  1145. break;
  1146. }
  1147. case CFG80211_SIGNAL_TYPE_UNSPEC:
  1148. if (sinfo.filled & STATION_INFO_SIGNAL) {
  1149. wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
  1150. wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
  1151. wstats.qual.level = sinfo.signal;
  1152. wstats.qual.qual = sinfo.signal;
  1153. break;
  1154. }
  1155. default:
  1156. wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
  1157. wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
  1158. }
  1159. wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
  1160. if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
  1161. wstats.discard.misc = sinfo.rx_dropped_misc;
  1162. if (sinfo.filled & STATION_INFO_TX_FAILED)
  1163. wstats.discard.retries = sinfo.tx_failed;
  1164. return &wstats;
  1165. }
  1166. EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
  1167. int cfg80211_wext_siwap(struct net_device *dev,
  1168. struct iw_request_info *info,
  1169. struct sockaddr *ap_addr, char *extra)
  1170. {
  1171. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1172. switch (wdev->iftype) {
  1173. case NL80211_IFTYPE_ADHOC:
  1174. return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
  1175. case NL80211_IFTYPE_STATION:
  1176. return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
  1177. case NL80211_IFTYPE_WDS:
  1178. return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
  1179. default:
  1180. return -EOPNOTSUPP;
  1181. }
  1182. }
  1183. EXPORT_SYMBOL_GPL(cfg80211_wext_siwap);
  1184. int cfg80211_wext_giwap(struct net_device *dev,
  1185. struct iw_request_info *info,
  1186. struct sockaddr *ap_addr, char *extra)
  1187. {
  1188. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1189. switch (wdev->iftype) {
  1190. case NL80211_IFTYPE_ADHOC:
  1191. return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
  1192. case NL80211_IFTYPE_STATION:
  1193. return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
  1194. case NL80211_IFTYPE_WDS:
  1195. return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
  1196. default:
  1197. return -EOPNOTSUPP;
  1198. }
  1199. }
  1200. EXPORT_SYMBOL_GPL(cfg80211_wext_giwap);
  1201. int cfg80211_wext_siwessid(struct net_device *dev,
  1202. struct iw_request_info *info,
  1203. struct iw_point *data, char *ssid)
  1204. {
  1205. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1206. switch (wdev->iftype) {
  1207. case NL80211_IFTYPE_ADHOC:
  1208. return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
  1209. case NL80211_IFTYPE_STATION:
  1210. return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
  1211. default:
  1212. return -EOPNOTSUPP;
  1213. }
  1214. }
  1215. EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid);
  1216. int cfg80211_wext_giwessid(struct net_device *dev,
  1217. struct iw_request_info *info,
  1218. struct iw_point *data, char *ssid)
  1219. {
  1220. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1221. data->flags = 0;
  1222. data->length = 0;
  1223. switch (wdev->iftype) {
  1224. case NL80211_IFTYPE_ADHOC:
  1225. return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
  1226. case NL80211_IFTYPE_STATION:
  1227. return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
  1228. default:
  1229. return -EOPNOTSUPP;
  1230. }
  1231. }
  1232. EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid);
  1233. int cfg80211_wext_siwpmksa(struct net_device *dev,
  1234. struct iw_request_info *info,
  1235. struct iw_point *data, char *extra)
  1236. {
  1237. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1238. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  1239. struct cfg80211_pmksa cfg_pmksa;
  1240. struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
  1241. memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
  1242. if (wdev->iftype != NL80211_IFTYPE_STATION)
  1243. return -EINVAL;
  1244. cfg_pmksa.bssid = pmksa->bssid.sa_data;
  1245. cfg_pmksa.pmkid = pmksa->pmkid;
  1246. switch (pmksa->cmd) {
  1247. case IW_PMKSA_ADD:
  1248. if (!rdev->ops->set_pmksa)
  1249. return -EOPNOTSUPP;
  1250. return rdev->ops->set_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
  1251. case IW_PMKSA_REMOVE:
  1252. if (!rdev->ops->del_pmksa)
  1253. return -EOPNOTSUPP;
  1254. return rdev->ops->del_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
  1255. case IW_PMKSA_FLUSH:
  1256. if (!rdev->ops->flush_pmksa)
  1257. return -EOPNOTSUPP;
  1258. return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
  1259. default:
  1260. return -EOPNOTSUPP;
  1261. }
  1262. }
  1263. EXPORT_SYMBOL_GPL(cfg80211_wext_siwpmksa);
  1264. static const iw_handler cfg80211_handlers[] = {
  1265. [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
  1266. [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
  1267. [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
  1268. [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
  1269. [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
  1270. [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
  1271. [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
  1272. [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
  1273. [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
  1274. [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
  1275. [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
  1276. [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
  1277. [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
  1278. [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
  1279. [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
  1280. [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
  1281. [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
  1282. [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
  1283. [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
  1284. [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
  1285. [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
  1286. [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
  1287. [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
  1288. [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
  1289. [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
  1290. [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
  1291. [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
  1292. [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
  1293. [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
  1294. [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
  1295. [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
  1296. [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
  1297. };
  1298. const struct iw_handler_def cfg80211_wext_handler = {
  1299. .num_standard = ARRAY_SIZE(cfg80211_handlers),
  1300. .standard = cfg80211_handlers,
  1301. .get_wireless_stats = cfg80211_wireless_stats,
  1302. };