cfg.c 40 KB

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