cfg.c 40 KB

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