cfg.c 40 KB

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