wext-compat.c 38 KB

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