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