cfg.c 40 KB

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