wext-compat.c 39 KB

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