wext-compat.c 39 KB

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