wext-compat.c 38 KB

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