wext-compat.c 38 KB

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