wext-compat.c 37 KB

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