cfg.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * This file is GPLv2 as found in COPYING.
  7. */
  8. #include <linux/ieee80211.h>
  9. #include <linux/nl80211.h>
  10. #include <linux/rtnetlink.h>
  11. #include <linux/slab.h>
  12. #include <net/net_namespace.h>
  13. #include <linux/rcupdate.h>
  14. #include <net/cfg80211.h>
  15. #include "ieee80211_i.h"
  16. #include "driver-ops.h"
  17. #include "cfg.h"
  18. #include "rate.h"
  19. #include "mesh.h"
  20. static bool nl80211_type_check(enum nl80211_iftype type)
  21. {
  22. switch (type) {
  23. case NL80211_IFTYPE_ADHOC:
  24. case NL80211_IFTYPE_STATION:
  25. case NL80211_IFTYPE_MONITOR:
  26. #ifdef CONFIG_MAC80211_MESH
  27. case NL80211_IFTYPE_MESH_POINT:
  28. #endif
  29. case NL80211_IFTYPE_AP:
  30. case NL80211_IFTYPE_AP_VLAN:
  31. case NL80211_IFTYPE_WDS:
  32. return true;
  33. default:
  34. return false;
  35. }
  36. }
  37. static bool nl80211_params_check(enum nl80211_iftype type,
  38. struct vif_params *params)
  39. {
  40. if (!nl80211_type_check(type))
  41. return false;
  42. return true;
  43. }
  44. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_local *local = wiphy_priv(wiphy);
  49. struct net_device *dev;
  50. struct ieee80211_sub_if_data *sdata;
  51. int err;
  52. if (!nl80211_params_check(type, params))
  53. return -EINVAL;
  54. err = ieee80211_if_add(local, name, &dev, type, params);
  55. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  56. return err;
  57. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  58. sdata->u.mntr_flags = *flags;
  59. return 0;
  60. }
  61. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  62. {
  63. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  64. return 0;
  65. }
  66. static int ieee80211_change_iface(struct wiphy *wiphy,
  67. struct net_device *dev,
  68. enum nl80211_iftype type, u32 *flags,
  69. struct vif_params *params)
  70. {
  71. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  72. int ret;
  73. if (ieee80211_sdata_running(sdata))
  74. return -EBUSY;
  75. if (!nl80211_params_check(type, params))
  76. return -EINVAL;
  77. ret = ieee80211_if_change_type(sdata, type);
  78. if (ret)
  79. return ret;
  80. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  81. ieee80211_sdata_set_mesh_id(sdata,
  82. params->mesh_id_len,
  83. params->mesh_id);
  84. if (type == NL80211_IFTYPE_AP_VLAN &&
  85. params && params->use_4addr == 0)
  86. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  87. else if (type == NL80211_IFTYPE_STATION &&
  88. params && params->use_4addr >= 0)
  89. sdata->u.mgd.use_4addr = params->use_4addr;
  90. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
  91. sdata->u.mntr_flags = *flags;
  92. return 0;
  93. }
  94. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  95. u8 key_idx, const u8 *mac_addr,
  96. struct key_params *params)
  97. {
  98. struct ieee80211_sub_if_data *sdata;
  99. struct sta_info *sta = NULL;
  100. enum ieee80211_key_alg alg;
  101. struct ieee80211_key *key;
  102. int err;
  103. if (!netif_running(dev))
  104. return -ENETDOWN;
  105. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  106. switch (params->cipher) {
  107. case WLAN_CIPHER_SUITE_WEP40:
  108. case WLAN_CIPHER_SUITE_WEP104:
  109. alg = ALG_WEP;
  110. break;
  111. case WLAN_CIPHER_SUITE_TKIP:
  112. alg = ALG_TKIP;
  113. break;
  114. case WLAN_CIPHER_SUITE_CCMP:
  115. alg = ALG_CCMP;
  116. break;
  117. case WLAN_CIPHER_SUITE_AES_CMAC:
  118. alg = ALG_AES_CMAC;
  119. break;
  120. default:
  121. return -EINVAL;
  122. }
  123. /* reject WEP and TKIP keys if WEP failed to initialize */
  124. if ((alg == ALG_WEP || alg == ALG_TKIP) &&
  125. IS_ERR(sdata->local->wep_tx_tfm))
  126. return -EINVAL;
  127. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
  128. params->seq_len, params->seq);
  129. if (!key)
  130. return -ENOMEM;
  131. mutex_lock(&sdata->local->sta_mtx);
  132. if (mac_addr) {
  133. sta = sta_info_get_bss(sdata, mac_addr);
  134. if (!sta) {
  135. ieee80211_key_free(sdata->local, key);
  136. err = -ENOENT;
  137. goto out_unlock;
  138. }
  139. }
  140. ieee80211_key_link(key, sdata, sta);
  141. err = 0;
  142. out_unlock:
  143. mutex_unlock(&sdata->local->sta_mtx);
  144. return err;
  145. }
  146. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  147. u8 key_idx, const u8 *mac_addr)
  148. {
  149. struct ieee80211_sub_if_data *sdata;
  150. struct sta_info *sta;
  151. int ret;
  152. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  153. mutex_lock(&sdata->local->sta_mtx);
  154. if (mac_addr) {
  155. ret = -ENOENT;
  156. sta = sta_info_get_bss(sdata, mac_addr);
  157. if (!sta)
  158. goto out_unlock;
  159. if (sta->key) {
  160. ieee80211_key_free(sdata->local, sta->key);
  161. WARN_ON(sta->key);
  162. ret = 0;
  163. }
  164. goto out_unlock;
  165. }
  166. if (!sdata->keys[key_idx]) {
  167. ret = -ENOENT;
  168. goto out_unlock;
  169. }
  170. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  171. WARN_ON(sdata->keys[key_idx]);
  172. ret = 0;
  173. out_unlock:
  174. mutex_unlock(&sdata->local->sta_mtx);
  175. return ret;
  176. }
  177. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  178. u8 key_idx, const u8 *mac_addr, void *cookie,
  179. void (*callback)(void *cookie,
  180. struct key_params *params))
  181. {
  182. struct ieee80211_sub_if_data *sdata;
  183. struct sta_info *sta = NULL;
  184. u8 seq[6] = {0};
  185. struct key_params params;
  186. struct ieee80211_key *key;
  187. u32 iv32;
  188. u16 iv16;
  189. int err = -ENOENT;
  190. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  191. rcu_read_lock();
  192. if (mac_addr) {
  193. sta = sta_info_get_bss(sdata, mac_addr);
  194. if (!sta)
  195. goto out;
  196. key = sta->key;
  197. } else
  198. key = sdata->keys[key_idx];
  199. if (!key)
  200. goto out;
  201. memset(&params, 0, sizeof(params));
  202. switch (key->conf.alg) {
  203. case ALG_TKIP:
  204. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  205. iv32 = key->u.tkip.tx.iv32;
  206. iv16 = key->u.tkip.tx.iv16;
  207. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  208. drv_get_tkip_seq(sdata->local,
  209. key->conf.hw_key_idx,
  210. &iv32, &iv16);
  211. seq[0] = iv16 & 0xff;
  212. seq[1] = (iv16 >> 8) & 0xff;
  213. seq[2] = iv32 & 0xff;
  214. seq[3] = (iv32 >> 8) & 0xff;
  215. seq[4] = (iv32 >> 16) & 0xff;
  216. seq[5] = (iv32 >> 24) & 0xff;
  217. params.seq = seq;
  218. params.seq_len = 6;
  219. break;
  220. case ALG_CCMP:
  221. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  222. seq[0] = key->u.ccmp.tx_pn[5];
  223. seq[1] = key->u.ccmp.tx_pn[4];
  224. seq[2] = key->u.ccmp.tx_pn[3];
  225. seq[3] = key->u.ccmp.tx_pn[2];
  226. seq[4] = key->u.ccmp.tx_pn[1];
  227. seq[5] = key->u.ccmp.tx_pn[0];
  228. params.seq = seq;
  229. params.seq_len = 6;
  230. break;
  231. case ALG_WEP:
  232. if (key->conf.keylen == 5)
  233. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  234. else
  235. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  236. break;
  237. case ALG_AES_CMAC:
  238. params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  239. seq[0] = key->u.aes_cmac.tx_pn[5];
  240. seq[1] = key->u.aes_cmac.tx_pn[4];
  241. seq[2] = key->u.aes_cmac.tx_pn[3];
  242. seq[3] = key->u.aes_cmac.tx_pn[2];
  243. seq[4] = key->u.aes_cmac.tx_pn[1];
  244. seq[5] = key->u.aes_cmac.tx_pn[0];
  245. params.seq = seq;
  246. params.seq_len = 6;
  247. break;
  248. }
  249. params.key = key->conf.key;
  250. params.key_len = key->conf.keylen;
  251. callback(cookie, &params);
  252. err = 0;
  253. out:
  254. rcu_read_unlock();
  255. return err;
  256. }
  257. static int ieee80211_config_default_key(struct wiphy *wiphy,
  258. struct net_device *dev,
  259. u8 key_idx)
  260. {
  261. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  262. ieee80211_set_default_key(sdata, key_idx);
  263. return 0;
  264. }
  265. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  266. struct net_device *dev,
  267. u8 key_idx)
  268. {
  269. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  270. ieee80211_set_default_mgmt_key(sdata, key_idx);
  271. return 0;
  272. }
  273. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  274. {
  275. struct ieee80211_sub_if_data *sdata = sta->sdata;
  276. sinfo->generation = sdata->local->sta_generation;
  277. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  278. STATION_INFO_RX_BYTES |
  279. STATION_INFO_TX_BYTES |
  280. STATION_INFO_RX_PACKETS |
  281. STATION_INFO_TX_PACKETS |
  282. STATION_INFO_TX_BITRATE;
  283. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  284. sinfo->rx_bytes = sta->rx_bytes;
  285. sinfo->tx_bytes = sta->tx_bytes;
  286. sinfo->rx_packets = sta->rx_packets;
  287. sinfo->tx_packets = sta->tx_packets;
  288. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  289. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  290. sinfo->filled |= STATION_INFO_SIGNAL;
  291. sinfo->signal = (s8)sta->last_signal;
  292. }
  293. sinfo->txrate.flags = 0;
  294. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  295. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  296. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  297. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  298. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  299. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  300. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  301. struct ieee80211_supported_band *sband;
  302. sband = sta->local->hw.wiphy->bands[
  303. sta->local->hw.conf.channel->band];
  304. sinfo->txrate.legacy =
  305. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  306. } else
  307. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  308. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  309. #ifdef CONFIG_MAC80211_MESH
  310. sinfo->filled |= STATION_INFO_LLID |
  311. STATION_INFO_PLID |
  312. STATION_INFO_PLINK_STATE;
  313. sinfo->llid = le16_to_cpu(sta->llid);
  314. sinfo->plid = le16_to_cpu(sta->plid);
  315. sinfo->plink_state = sta->plink_state;
  316. #endif
  317. }
  318. }
  319. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  320. int idx, u8 *mac, struct station_info *sinfo)
  321. {
  322. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  323. struct sta_info *sta;
  324. int ret = -ENOENT;
  325. rcu_read_lock();
  326. sta = sta_info_get_by_idx(sdata, idx);
  327. if (sta) {
  328. ret = 0;
  329. memcpy(mac, sta->sta.addr, ETH_ALEN);
  330. sta_set_sinfo(sta, sinfo);
  331. }
  332. rcu_read_unlock();
  333. return ret;
  334. }
  335. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  336. int idx, struct survey_info *survey)
  337. {
  338. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  339. return drv_get_survey(local, idx, survey);
  340. }
  341. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  342. u8 *mac, struct station_info *sinfo)
  343. {
  344. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  345. struct sta_info *sta;
  346. int ret = -ENOENT;
  347. rcu_read_lock();
  348. sta = sta_info_get_bss(sdata, mac);
  349. if (sta) {
  350. ret = 0;
  351. sta_set_sinfo(sta, sinfo);
  352. }
  353. rcu_read_unlock();
  354. return ret;
  355. }
  356. /*
  357. * This handles both adding a beacon and setting new beacon info
  358. */
  359. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  360. struct beacon_parameters *params)
  361. {
  362. struct beacon_data *new, *old;
  363. int new_head_len, new_tail_len;
  364. int size;
  365. int err = -EINVAL;
  366. old = sdata->u.ap.beacon;
  367. /* head must not be zero-length */
  368. if (params->head && !params->head_len)
  369. return -EINVAL;
  370. /*
  371. * This is a kludge. beacon interval should really be part
  372. * of the beacon information.
  373. */
  374. if (params->interval &&
  375. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  376. sdata->vif.bss_conf.beacon_int = params->interval;
  377. ieee80211_bss_info_change_notify(sdata,
  378. BSS_CHANGED_BEACON_INT);
  379. }
  380. /* Need to have a beacon head if we don't have one yet */
  381. if (!params->head && !old)
  382. return err;
  383. /* sorry, no way to start beaconing without dtim period */
  384. if (!params->dtim_period && !old)
  385. return err;
  386. /* new or old head? */
  387. if (params->head)
  388. new_head_len = params->head_len;
  389. else
  390. new_head_len = old->head_len;
  391. /* new or old tail? */
  392. if (params->tail || !old)
  393. /* params->tail_len will be zero for !params->tail */
  394. new_tail_len = params->tail_len;
  395. else
  396. new_tail_len = old->tail_len;
  397. size = sizeof(*new) + new_head_len + new_tail_len;
  398. new = kzalloc(size, GFP_KERNEL);
  399. if (!new)
  400. return -ENOMEM;
  401. /* start filling the new info now */
  402. /* new or old dtim period? */
  403. if (params->dtim_period)
  404. new->dtim_period = params->dtim_period;
  405. else
  406. new->dtim_period = old->dtim_period;
  407. /*
  408. * pointers go into the block we allocated,
  409. * memory is | beacon_data | head | tail |
  410. */
  411. new->head = ((u8 *) new) + sizeof(*new);
  412. new->tail = new->head + new_head_len;
  413. new->head_len = new_head_len;
  414. new->tail_len = new_tail_len;
  415. /* copy in head */
  416. if (params->head)
  417. memcpy(new->head, params->head, new_head_len);
  418. else
  419. memcpy(new->head, old->head, new_head_len);
  420. /* copy in optional tail */
  421. if (params->tail)
  422. memcpy(new->tail, params->tail, new_tail_len);
  423. else
  424. if (old)
  425. memcpy(new->tail, old->tail, new_tail_len);
  426. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  427. rcu_assign_pointer(sdata->u.ap.beacon, new);
  428. synchronize_rcu();
  429. kfree(old);
  430. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  431. BSS_CHANGED_BEACON);
  432. return 0;
  433. }
  434. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  435. struct beacon_parameters *params)
  436. {
  437. struct ieee80211_sub_if_data *sdata;
  438. struct beacon_data *old;
  439. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  440. old = sdata->u.ap.beacon;
  441. if (old)
  442. return -EALREADY;
  443. return ieee80211_config_beacon(sdata, params);
  444. }
  445. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  446. struct beacon_parameters *params)
  447. {
  448. struct ieee80211_sub_if_data *sdata;
  449. struct beacon_data *old;
  450. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  451. old = sdata->u.ap.beacon;
  452. if (!old)
  453. return -ENOENT;
  454. return ieee80211_config_beacon(sdata, params);
  455. }
  456. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  457. {
  458. struct ieee80211_sub_if_data *sdata;
  459. struct beacon_data *old;
  460. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  461. old = sdata->u.ap.beacon;
  462. if (!old)
  463. return -ENOENT;
  464. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  465. synchronize_rcu();
  466. kfree(old);
  467. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  468. return 0;
  469. }
  470. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  471. struct iapp_layer2_update {
  472. u8 da[ETH_ALEN]; /* broadcast */
  473. u8 sa[ETH_ALEN]; /* STA addr */
  474. __be16 len; /* 6 */
  475. u8 dsap; /* 0 */
  476. u8 ssap; /* 0 */
  477. u8 control;
  478. u8 xid_info[3];
  479. } __packed;
  480. static void ieee80211_send_layer2_update(struct sta_info *sta)
  481. {
  482. struct iapp_layer2_update *msg;
  483. struct sk_buff *skb;
  484. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  485. * bridge devices */
  486. skb = dev_alloc_skb(sizeof(*msg));
  487. if (!skb)
  488. return;
  489. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  490. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  491. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  492. memset(msg->da, 0xff, ETH_ALEN);
  493. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  494. msg->len = htons(6);
  495. msg->dsap = 0;
  496. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  497. msg->control = 0xaf; /* XID response lsb.1111F101.
  498. * F=0 (no poll command; unsolicited frame) */
  499. msg->xid_info[0] = 0x81; /* XID format identifier */
  500. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  501. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  502. skb->dev = sta->sdata->dev;
  503. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  504. memset(skb->cb, 0, sizeof(skb->cb));
  505. netif_rx_ni(skb);
  506. }
  507. static void sta_apply_parameters(struct ieee80211_local *local,
  508. struct sta_info *sta,
  509. struct station_parameters *params)
  510. {
  511. u32 rates;
  512. int i, j;
  513. struct ieee80211_supported_band *sband;
  514. struct ieee80211_sub_if_data *sdata = sta->sdata;
  515. u32 mask, set;
  516. sband = local->hw.wiphy->bands[local->oper_channel->band];
  517. spin_lock_bh(&sta->lock);
  518. mask = params->sta_flags_mask;
  519. set = params->sta_flags_set;
  520. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  521. sta->flags &= ~WLAN_STA_AUTHORIZED;
  522. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  523. sta->flags |= WLAN_STA_AUTHORIZED;
  524. }
  525. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  526. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  527. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  528. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  529. }
  530. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  531. sta->flags &= ~WLAN_STA_WME;
  532. if (set & BIT(NL80211_STA_FLAG_WME))
  533. sta->flags |= WLAN_STA_WME;
  534. }
  535. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  536. sta->flags &= ~WLAN_STA_MFP;
  537. if (set & BIT(NL80211_STA_FLAG_MFP))
  538. sta->flags |= WLAN_STA_MFP;
  539. }
  540. spin_unlock_bh(&sta->lock);
  541. /*
  542. * cfg80211 validates this (1-2007) and allows setting the AID
  543. * only when creating a new station entry
  544. */
  545. if (params->aid)
  546. sta->sta.aid = params->aid;
  547. /*
  548. * FIXME: updating the following information is racy when this
  549. * function is called from ieee80211_change_station().
  550. * However, all this information should be static so
  551. * maybe we should just reject attemps to change it.
  552. */
  553. if (params->listen_interval >= 0)
  554. sta->listen_interval = params->listen_interval;
  555. if (params->supported_rates) {
  556. rates = 0;
  557. for (i = 0; i < params->supported_rates_len; i++) {
  558. int rate = (params->supported_rates[i] & 0x7f) * 5;
  559. for (j = 0; j < sband->n_bitrates; j++) {
  560. if (sband->bitrates[j].bitrate == rate)
  561. rates |= BIT(j);
  562. }
  563. }
  564. sta->sta.supp_rates[local->oper_channel->band] = rates;
  565. }
  566. if (params->ht_capa)
  567. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  568. params->ht_capa,
  569. &sta->sta.ht_cap);
  570. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  571. switch (params->plink_action) {
  572. case PLINK_ACTION_OPEN:
  573. mesh_plink_open(sta);
  574. break;
  575. case PLINK_ACTION_BLOCK:
  576. mesh_plink_block(sta);
  577. break;
  578. }
  579. }
  580. }
  581. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  582. u8 *mac, struct station_parameters *params)
  583. {
  584. struct ieee80211_local *local = wiphy_priv(wiphy);
  585. struct sta_info *sta;
  586. struct ieee80211_sub_if_data *sdata;
  587. int err;
  588. int layer2_update;
  589. if (params->vlan) {
  590. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  591. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  592. sdata->vif.type != NL80211_IFTYPE_AP)
  593. return -EINVAL;
  594. } else
  595. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  596. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  597. return -EINVAL;
  598. if (is_multicast_ether_addr(mac))
  599. return -EINVAL;
  600. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  601. if (!sta)
  602. return -ENOMEM;
  603. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  604. sta_apply_parameters(local, sta, params);
  605. rate_control_rate_init(sta);
  606. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  607. sdata->vif.type == NL80211_IFTYPE_AP;
  608. err = sta_info_insert_rcu(sta);
  609. if (err) {
  610. rcu_read_unlock();
  611. return err;
  612. }
  613. if (layer2_update)
  614. ieee80211_send_layer2_update(sta);
  615. rcu_read_unlock();
  616. return 0;
  617. }
  618. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  619. u8 *mac)
  620. {
  621. struct ieee80211_local *local = wiphy_priv(wiphy);
  622. struct ieee80211_sub_if_data *sdata;
  623. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  624. if (mac)
  625. return sta_info_destroy_addr_bss(sdata, mac);
  626. sta_info_flush(local, sdata);
  627. return 0;
  628. }
  629. static int ieee80211_change_station(struct wiphy *wiphy,
  630. struct net_device *dev,
  631. u8 *mac,
  632. struct station_parameters *params)
  633. {
  634. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  635. struct ieee80211_local *local = wiphy_priv(wiphy);
  636. struct sta_info *sta;
  637. struct ieee80211_sub_if_data *vlansdata;
  638. rcu_read_lock();
  639. sta = sta_info_get_bss(sdata, mac);
  640. if (!sta) {
  641. rcu_read_unlock();
  642. return -ENOENT;
  643. }
  644. if (params->vlan && params->vlan != sta->sdata->dev) {
  645. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  646. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  647. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  648. rcu_read_unlock();
  649. return -EINVAL;
  650. }
  651. if (params->vlan->ieee80211_ptr->use_4addr) {
  652. if (vlansdata->u.vlan.sta) {
  653. rcu_read_unlock();
  654. return -EBUSY;
  655. }
  656. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  657. }
  658. sta->sdata = vlansdata;
  659. ieee80211_send_layer2_update(sta);
  660. }
  661. sta_apply_parameters(local, sta, params);
  662. rcu_read_unlock();
  663. return 0;
  664. }
  665. #ifdef CONFIG_MAC80211_MESH
  666. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  667. u8 *dst, u8 *next_hop)
  668. {
  669. struct ieee80211_sub_if_data *sdata;
  670. struct mesh_path *mpath;
  671. struct sta_info *sta;
  672. int err;
  673. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  674. rcu_read_lock();
  675. sta = sta_info_get(sdata, next_hop);
  676. if (!sta) {
  677. rcu_read_unlock();
  678. return -ENOENT;
  679. }
  680. err = mesh_path_add(dst, sdata);
  681. if (err) {
  682. rcu_read_unlock();
  683. return err;
  684. }
  685. mpath = mesh_path_lookup(dst, sdata);
  686. if (!mpath) {
  687. rcu_read_unlock();
  688. return -ENXIO;
  689. }
  690. mesh_path_fix_nexthop(mpath, sta);
  691. rcu_read_unlock();
  692. return 0;
  693. }
  694. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  695. u8 *dst)
  696. {
  697. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  698. if (dst)
  699. return mesh_path_del(dst, sdata);
  700. mesh_path_flush(sdata);
  701. return 0;
  702. }
  703. static int ieee80211_change_mpath(struct wiphy *wiphy,
  704. struct net_device *dev,
  705. u8 *dst, u8 *next_hop)
  706. {
  707. struct ieee80211_sub_if_data *sdata;
  708. struct mesh_path *mpath;
  709. struct sta_info *sta;
  710. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  711. rcu_read_lock();
  712. sta = sta_info_get(sdata, next_hop);
  713. if (!sta) {
  714. rcu_read_unlock();
  715. return -ENOENT;
  716. }
  717. mpath = mesh_path_lookup(dst, sdata);
  718. if (!mpath) {
  719. rcu_read_unlock();
  720. return -ENOENT;
  721. }
  722. mesh_path_fix_nexthop(mpath, sta);
  723. rcu_read_unlock();
  724. return 0;
  725. }
  726. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  727. struct mpath_info *pinfo)
  728. {
  729. if (mpath->next_hop)
  730. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  731. else
  732. memset(next_hop, 0, ETH_ALEN);
  733. pinfo->generation = mesh_paths_generation;
  734. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  735. MPATH_INFO_SN |
  736. MPATH_INFO_METRIC |
  737. MPATH_INFO_EXPTIME |
  738. MPATH_INFO_DISCOVERY_TIMEOUT |
  739. MPATH_INFO_DISCOVERY_RETRIES |
  740. MPATH_INFO_FLAGS;
  741. pinfo->frame_qlen = mpath->frame_queue.qlen;
  742. pinfo->sn = mpath->sn;
  743. pinfo->metric = mpath->metric;
  744. if (time_before(jiffies, mpath->exp_time))
  745. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  746. pinfo->discovery_timeout =
  747. jiffies_to_msecs(mpath->discovery_timeout);
  748. pinfo->discovery_retries = mpath->discovery_retries;
  749. pinfo->flags = 0;
  750. if (mpath->flags & MESH_PATH_ACTIVE)
  751. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  752. if (mpath->flags & MESH_PATH_RESOLVING)
  753. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  754. if (mpath->flags & MESH_PATH_SN_VALID)
  755. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  756. if (mpath->flags & MESH_PATH_FIXED)
  757. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  758. if (mpath->flags & MESH_PATH_RESOLVING)
  759. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  760. pinfo->flags = mpath->flags;
  761. }
  762. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  763. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  764. {
  765. struct ieee80211_sub_if_data *sdata;
  766. struct mesh_path *mpath;
  767. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  768. rcu_read_lock();
  769. mpath = mesh_path_lookup(dst, sdata);
  770. if (!mpath) {
  771. rcu_read_unlock();
  772. return -ENOENT;
  773. }
  774. memcpy(dst, mpath->dst, ETH_ALEN);
  775. mpath_set_pinfo(mpath, next_hop, pinfo);
  776. rcu_read_unlock();
  777. return 0;
  778. }
  779. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  780. int idx, u8 *dst, u8 *next_hop,
  781. struct mpath_info *pinfo)
  782. {
  783. struct ieee80211_sub_if_data *sdata;
  784. struct mesh_path *mpath;
  785. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  786. rcu_read_lock();
  787. mpath = mesh_path_lookup_by_idx(idx, sdata);
  788. if (!mpath) {
  789. rcu_read_unlock();
  790. return -ENOENT;
  791. }
  792. memcpy(dst, mpath->dst, ETH_ALEN);
  793. mpath_set_pinfo(mpath, next_hop, pinfo);
  794. rcu_read_unlock();
  795. return 0;
  796. }
  797. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  798. struct net_device *dev,
  799. struct mesh_config *conf)
  800. {
  801. struct ieee80211_sub_if_data *sdata;
  802. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  803. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  804. return 0;
  805. }
  806. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  807. {
  808. return (mask >> (parm-1)) & 0x1;
  809. }
  810. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  811. struct net_device *dev,
  812. const struct mesh_config *nconf, u32 mask)
  813. {
  814. struct mesh_config *conf;
  815. struct ieee80211_sub_if_data *sdata;
  816. struct ieee80211_if_mesh *ifmsh;
  817. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  818. ifmsh = &sdata->u.mesh;
  819. /* Set the config options which we are interested in setting */
  820. conf = &(sdata->u.mesh.mshcfg);
  821. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  822. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  823. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  824. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  825. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  826. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  828. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  829. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  830. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  831. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  832. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  834. conf->auto_open_plinks = nconf->auto_open_plinks;
  835. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  836. conf->dot11MeshHWMPmaxPREQretries =
  837. nconf->dot11MeshHWMPmaxPREQretries;
  838. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  839. conf->path_refresh_time = nconf->path_refresh_time;
  840. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  841. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  842. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  843. conf->dot11MeshHWMPactivePathTimeout =
  844. nconf->dot11MeshHWMPactivePathTimeout;
  845. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  846. conf->dot11MeshHWMPpreqMinInterval =
  847. nconf->dot11MeshHWMPpreqMinInterval;
  848. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  849. mask))
  850. conf->dot11MeshHWMPnetDiameterTraversalTime =
  851. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  852. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  853. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  854. ieee80211_mesh_root_setup(ifmsh);
  855. }
  856. return 0;
  857. }
  858. #endif
  859. static int ieee80211_change_bss(struct wiphy *wiphy,
  860. struct net_device *dev,
  861. struct bss_parameters *params)
  862. {
  863. struct ieee80211_sub_if_data *sdata;
  864. u32 changed = 0;
  865. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  866. if (params->use_cts_prot >= 0) {
  867. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  868. changed |= BSS_CHANGED_ERP_CTS_PROT;
  869. }
  870. if (params->use_short_preamble >= 0) {
  871. sdata->vif.bss_conf.use_short_preamble =
  872. params->use_short_preamble;
  873. changed |= BSS_CHANGED_ERP_PREAMBLE;
  874. }
  875. if (!sdata->vif.bss_conf.use_short_slot &&
  876. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  877. sdata->vif.bss_conf.use_short_slot = true;
  878. changed |= BSS_CHANGED_ERP_SLOT;
  879. }
  880. if (params->use_short_slot_time >= 0) {
  881. sdata->vif.bss_conf.use_short_slot =
  882. params->use_short_slot_time;
  883. changed |= BSS_CHANGED_ERP_SLOT;
  884. }
  885. if (params->basic_rates) {
  886. int i, j;
  887. u32 rates = 0;
  888. struct ieee80211_local *local = wiphy_priv(wiphy);
  889. struct ieee80211_supported_band *sband =
  890. wiphy->bands[local->oper_channel->band];
  891. for (i = 0; i < params->basic_rates_len; i++) {
  892. int rate = (params->basic_rates[i] & 0x7f) * 5;
  893. for (j = 0; j < sband->n_bitrates; j++) {
  894. if (sband->bitrates[j].bitrate == rate)
  895. rates |= BIT(j);
  896. }
  897. }
  898. sdata->vif.bss_conf.basic_rates = rates;
  899. changed |= BSS_CHANGED_BASIC_RATES;
  900. }
  901. if (params->ap_isolate >= 0) {
  902. if (params->ap_isolate)
  903. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  904. else
  905. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  906. }
  907. ieee80211_bss_info_change_notify(sdata, changed);
  908. return 0;
  909. }
  910. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  911. struct ieee80211_txq_params *params)
  912. {
  913. struct ieee80211_local *local = wiphy_priv(wiphy);
  914. struct ieee80211_tx_queue_params p;
  915. if (!local->ops->conf_tx)
  916. return -EOPNOTSUPP;
  917. memset(&p, 0, sizeof(p));
  918. p.aifs = params->aifs;
  919. p.cw_max = params->cwmax;
  920. p.cw_min = params->cwmin;
  921. p.txop = params->txop;
  922. /*
  923. * Setting tx queue params disables u-apsd because it's only
  924. * called in master mode.
  925. */
  926. p.uapsd = false;
  927. if (drv_conf_tx(local, params->queue, &p)) {
  928. printk(KERN_DEBUG "%s: failed to set TX queue "
  929. "parameters for queue %d\n",
  930. wiphy_name(local->hw.wiphy), params->queue);
  931. return -EINVAL;
  932. }
  933. return 0;
  934. }
  935. static int ieee80211_set_channel(struct wiphy *wiphy,
  936. struct net_device *netdev,
  937. struct ieee80211_channel *chan,
  938. enum nl80211_channel_type channel_type)
  939. {
  940. struct ieee80211_local *local = wiphy_priv(wiphy);
  941. struct ieee80211_sub_if_data *sdata = NULL;
  942. if (netdev)
  943. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  944. switch (ieee80211_get_channel_mode(local, NULL)) {
  945. case CHAN_MODE_HOPPING:
  946. return -EBUSY;
  947. case CHAN_MODE_FIXED:
  948. if (local->oper_channel != chan)
  949. return -EBUSY;
  950. if (!sdata && local->_oper_channel_type == channel_type)
  951. return 0;
  952. break;
  953. case CHAN_MODE_UNDEFINED:
  954. break;
  955. }
  956. local->oper_channel = chan;
  957. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  958. return -EBUSY;
  959. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  960. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
  961. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  962. return 0;
  963. }
  964. #ifdef CONFIG_PM
  965. static int ieee80211_suspend(struct wiphy *wiphy)
  966. {
  967. return __ieee80211_suspend(wiphy_priv(wiphy));
  968. }
  969. static int ieee80211_resume(struct wiphy *wiphy)
  970. {
  971. return __ieee80211_resume(wiphy_priv(wiphy));
  972. }
  973. #else
  974. #define ieee80211_suspend NULL
  975. #define ieee80211_resume NULL
  976. #endif
  977. static int ieee80211_scan(struct wiphy *wiphy,
  978. struct net_device *dev,
  979. struct cfg80211_scan_request *req)
  980. {
  981. struct ieee80211_sub_if_data *sdata;
  982. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  983. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  984. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  985. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  986. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  987. return -EOPNOTSUPP;
  988. return ieee80211_request_scan(sdata, req);
  989. }
  990. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  991. struct cfg80211_auth_request *req)
  992. {
  993. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  994. }
  995. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  996. struct cfg80211_assoc_request *req)
  997. {
  998. struct ieee80211_local *local = wiphy_priv(wiphy);
  999. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1000. switch (ieee80211_get_channel_mode(local, sdata)) {
  1001. case CHAN_MODE_HOPPING:
  1002. return -EBUSY;
  1003. case CHAN_MODE_FIXED:
  1004. if (local->oper_channel == req->bss->channel)
  1005. break;
  1006. return -EBUSY;
  1007. case CHAN_MODE_UNDEFINED:
  1008. break;
  1009. }
  1010. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1011. }
  1012. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1013. struct cfg80211_deauth_request *req,
  1014. void *cookie)
  1015. {
  1016. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1017. req, cookie);
  1018. }
  1019. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1020. struct cfg80211_disassoc_request *req,
  1021. void *cookie)
  1022. {
  1023. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1024. req, cookie);
  1025. }
  1026. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1027. struct cfg80211_ibss_params *params)
  1028. {
  1029. struct ieee80211_local *local = wiphy_priv(wiphy);
  1030. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1031. switch (ieee80211_get_channel_mode(local, sdata)) {
  1032. case CHAN_MODE_HOPPING:
  1033. return -EBUSY;
  1034. case CHAN_MODE_FIXED:
  1035. if (!params->channel_fixed)
  1036. return -EBUSY;
  1037. if (local->oper_channel == params->channel)
  1038. break;
  1039. return -EBUSY;
  1040. case CHAN_MODE_UNDEFINED:
  1041. break;
  1042. }
  1043. return ieee80211_ibss_join(sdata, params);
  1044. }
  1045. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1046. {
  1047. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1048. return ieee80211_ibss_leave(sdata);
  1049. }
  1050. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1051. {
  1052. struct ieee80211_local *local = wiphy_priv(wiphy);
  1053. int err;
  1054. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1055. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1056. if (err)
  1057. return err;
  1058. }
  1059. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1060. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1061. if (err)
  1062. return err;
  1063. }
  1064. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1065. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1066. if (changed & WIPHY_PARAM_RETRY_LONG)
  1067. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1068. if (changed &
  1069. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1070. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1071. return 0;
  1072. }
  1073. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1074. enum nl80211_tx_power_setting type, int mbm)
  1075. {
  1076. struct ieee80211_local *local = wiphy_priv(wiphy);
  1077. struct ieee80211_channel *chan = local->hw.conf.channel;
  1078. u32 changes = 0;
  1079. switch (type) {
  1080. case NL80211_TX_POWER_AUTOMATIC:
  1081. local->user_power_level = -1;
  1082. break;
  1083. case NL80211_TX_POWER_LIMITED:
  1084. if (mbm < 0 || (mbm % 100))
  1085. return -EOPNOTSUPP;
  1086. local->user_power_level = MBM_TO_DBM(mbm);
  1087. break;
  1088. case NL80211_TX_POWER_FIXED:
  1089. if (mbm < 0 || (mbm % 100))
  1090. return -EOPNOTSUPP;
  1091. /* TODO: move to cfg80211 when it knows the channel */
  1092. if (MBM_TO_DBM(mbm) > chan->max_power)
  1093. return -EINVAL;
  1094. local->user_power_level = MBM_TO_DBM(mbm);
  1095. break;
  1096. }
  1097. ieee80211_hw_config(local, changes);
  1098. return 0;
  1099. }
  1100. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1101. {
  1102. struct ieee80211_local *local = wiphy_priv(wiphy);
  1103. *dbm = local->hw.conf.power_level;
  1104. return 0;
  1105. }
  1106. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1107. u8 *addr)
  1108. {
  1109. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1110. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1111. return 0;
  1112. }
  1113. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1114. {
  1115. struct ieee80211_local *local = wiphy_priv(wiphy);
  1116. drv_rfkill_poll(local);
  1117. }
  1118. #ifdef CONFIG_NL80211_TESTMODE
  1119. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1120. {
  1121. struct ieee80211_local *local = wiphy_priv(wiphy);
  1122. if (!local->ops->testmode_cmd)
  1123. return -EOPNOTSUPP;
  1124. return local->ops->testmode_cmd(&local->hw, data, len);
  1125. }
  1126. #endif
  1127. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1128. enum ieee80211_smps_mode smps_mode)
  1129. {
  1130. const u8 *ap;
  1131. enum ieee80211_smps_mode old_req;
  1132. int err;
  1133. old_req = sdata->u.mgd.req_smps;
  1134. sdata->u.mgd.req_smps = smps_mode;
  1135. if (old_req == smps_mode &&
  1136. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1137. return 0;
  1138. /*
  1139. * If not associated, or current association is not an HT
  1140. * association, there's no need to send an action frame.
  1141. */
  1142. if (!sdata->u.mgd.associated ||
  1143. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1144. mutex_lock(&sdata->local->iflist_mtx);
  1145. ieee80211_recalc_smps(sdata->local, sdata);
  1146. mutex_unlock(&sdata->local->iflist_mtx);
  1147. return 0;
  1148. }
  1149. ap = sdata->u.mgd.associated->bssid;
  1150. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1151. if (sdata->u.mgd.powersave)
  1152. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1153. else
  1154. smps_mode = IEEE80211_SMPS_OFF;
  1155. }
  1156. /* send SM PS frame to AP */
  1157. err = ieee80211_send_smps_action(sdata, smps_mode,
  1158. ap, ap);
  1159. if (err)
  1160. sdata->u.mgd.req_smps = old_req;
  1161. return err;
  1162. }
  1163. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1164. bool enabled, int timeout)
  1165. {
  1166. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1167. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1168. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1169. return -EOPNOTSUPP;
  1170. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1171. return -EOPNOTSUPP;
  1172. if (enabled == sdata->u.mgd.powersave &&
  1173. timeout == local->dynamic_ps_forced_timeout)
  1174. return 0;
  1175. sdata->u.mgd.powersave = enabled;
  1176. local->dynamic_ps_forced_timeout = timeout;
  1177. /* no change, but if automatic follow powersave */
  1178. mutex_lock(&sdata->u.mgd.mtx);
  1179. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1180. mutex_unlock(&sdata->u.mgd.mtx);
  1181. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1182. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1183. ieee80211_recalc_ps(local, -1);
  1184. return 0;
  1185. }
  1186. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1187. struct net_device *dev,
  1188. s32 rssi_thold, u32 rssi_hyst)
  1189. {
  1190. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1191. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1192. struct ieee80211_vif *vif = &sdata->vif;
  1193. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1194. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1195. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1196. return 0;
  1197. bss_conf->cqm_rssi_thold = rssi_thold;
  1198. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1199. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1200. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1201. return -EOPNOTSUPP;
  1202. return 0;
  1203. }
  1204. /* tell the driver upon association, unless already associated */
  1205. if (sdata->u.mgd.associated)
  1206. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1207. return 0;
  1208. }
  1209. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1210. struct net_device *dev,
  1211. const u8 *addr,
  1212. const struct cfg80211_bitrate_mask *mask)
  1213. {
  1214. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1215. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1216. int i;
  1217. /*
  1218. * This _could_ be supported by providing a hook for
  1219. * drivers for this function, but at this point it
  1220. * doesn't seem worth bothering.
  1221. */
  1222. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1223. return -EOPNOTSUPP;
  1224. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1225. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1226. return 0;
  1227. }
  1228. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1229. struct net_device *dev,
  1230. struct ieee80211_channel *chan,
  1231. enum nl80211_channel_type channel_type,
  1232. unsigned int duration,
  1233. u64 *cookie)
  1234. {
  1235. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1236. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1237. duration, cookie);
  1238. }
  1239. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1240. struct net_device *dev,
  1241. u64 cookie)
  1242. {
  1243. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1244. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1245. }
  1246. static int ieee80211_action(struct wiphy *wiphy, struct net_device *dev,
  1247. struct ieee80211_channel *chan,
  1248. enum nl80211_channel_type channel_type,
  1249. bool channel_type_valid,
  1250. const u8 *buf, size_t len, u64 *cookie)
  1251. {
  1252. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1253. struct ieee80211_local *local = sdata->local;
  1254. struct sk_buff *skb;
  1255. struct sta_info *sta;
  1256. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1257. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1258. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1259. /* Check that we are on the requested channel for transmission */
  1260. if (chan != local->tmp_channel &&
  1261. chan != local->oper_channel)
  1262. return -EBUSY;
  1263. if (channel_type_valid &&
  1264. (channel_type != local->tmp_channel_type &&
  1265. channel_type != local->_oper_channel_type))
  1266. return -EBUSY;
  1267. switch (sdata->vif.type) {
  1268. case NL80211_IFTYPE_ADHOC:
  1269. if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1270. break;
  1271. rcu_read_lock();
  1272. sta = sta_info_get(sdata, mgmt->da);
  1273. rcu_read_unlock();
  1274. if (!sta)
  1275. return -ENOLINK;
  1276. break;
  1277. case NL80211_IFTYPE_STATION:
  1278. if (!(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
  1279. flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1280. break;
  1281. default:
  1282. return -EOPNOTSUPP;
  1283. }
  1284. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1285. if (!skb)
  1286. return -ENOMEM;
  1287. skb_reserve(skb, local->hw.extra_tx_headroom);
  1288. memcpy(skb_put(skb, len), buf, len);
  1289. IEEE80211_SKB_CB(skb)->flags = flags;
  1290. skb->dev = sdata->dev;
  1291. ieee80211_tx_skb(sdata, skb);
  1292. *cookie = (unsigned long) skb;
  1293. return 0;
  1294. }
  1295. struct cfg80211_ops mac80211_config_ops = {
  1296. .add_virtual_intf = ieee80211_add_iface,
  1297. .del_virtual_intf = ieee80211_del_iface,
  1298. .change_virtual_intf = ieee80211_change_iface,
  1299. .add_key = ieee80211_add_key,
  1300. .del_key = ieee80211_del_key,
  1301. .get_key = ieee80211_get_key,
  1302. .set_default_key = ieee80211_config_default_key,
  1303. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1304. .add_beacon = ieee80211_add_beacon,
  1305. .set_beacon = ieee80211_set_beacon,
  1306. .del_beacon = ieee80211_del_beacon,
  1307. .add_station = ieee80211_add_station,
  1308. .del_station = ieee80211_del_station,
  1309. .change_station = ieee80211_change_station,
  1310. .get_station = ieee80211_get_station,
  1311. .dump_station = ieee80211_dump_station,
  1312. .dump_survey = ieee80211_dump_survey,
  1313. #ifdef CONFIG_MAC80211_MESH
  1314. .add_mpath = ieee80211_add_mpath,
  1315. .del_mpath = ieee80211_del_mpath,
  1316. .change_mpath = ieee80211_change_mpath,
  1317. .get_mpath = ieee80211_get_mpath,
  1318. .dump_mpath = ieee80211_dump_mpath,
  1319. .set_mesh_params = ieee80211_set_mesh_params,
  1320. .get_mesh_params = ieee80211_get_mesh_params,
  1321. #endif
  1322. .change_bss = ieee80211_change_bss,
  1323. .set_txq_params = ieee80211_set_txq_params,
  1324. .set_channel = ieee80211_set_channel,
  1325. .suspend = ieee80211_suspend,
  1326. .resume = ieee80211_resume,
  1327. .scan = ieee80211_scan,
  1328. .auth = ieee80211_auth,
  1329. .assoc = ieee80211_assoc,
  1330. .deauth = ieee80211_deauth,
  1331. .disassoc = ieee80211_disassoc,
  1332. .join_ibss = ieee80211_join_ibss,
  1333. .leave_ibss = ieee80211_leave_ibss,
  1334. .set_wiphy_params = ieee80211_set_wiphy_params,
  1335. .set_tx_power = ieee80211_set_tx_power,
  1336. .get_tx_power = ieee80211_get_tx_power,
  1337. .set_wds_peer = ieee80211_set_wds_peer,
  1338. .rfkill_poll = ieee80211_rfkill_poll,
  1339. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1340. .set_power_mgmt = ieee80211_set_power_mgmt,
  1341. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1342. .remain_on_channel = ieee80211_remain_on_channel,
  1343. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1344. .action = ieee80211_action,
  1345. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1346. };